« first day (76 days earlier)      last day (2782 days later) » 

10:06 AM
Could anyone help with the best way to implement random events in my text based game
I was thinking an array of pointers to different functions
where each function is an event
there are regions in the game and each region can do stuff like form an alliance
so a function might look like:

    void formAlliance(Region first, Region second) {}
or

    void launchNuclearStrike(Region aggressor, Region target) {}
there may also be functions with only one parameter like:

void callMartialLaw(Region region) {}
because I want at every given second in the game, there to be a chance of calling one random function from maybe an array of function pointers if one isn't already happening
 
nwp
10:30 AM
there are various ways to do that
if you use function pointers the functions have to have the same parameters
 
Ah might need to do something else then because would be better if they were all in the same array
 
nwp
one way to solve that is to make all functions take no arguments and then randomly decide the parameters
 
that's a good idea actually
 
nwp
another way would be to have a function fire_random_event() that rolls for the event to happen and then calls the appropriate function directly, without the arrays, with the right parameters
 
there will be a lot of possible events so that might require a lot of repetition
@milleniumbug suggested something to do with std::function but I didn't really understand that
 
nwp
10:34 AM
yeah, I was about to say that
arrays of function pointers have insane syntax
 
I didn't know how to define the arguments with std::function
 
nwp
std::function is essentially a function pointer with some additional perks without the crazy syntax
you write std::function<void()> for the one taking no parameters, or std::function<void(Region, Region)> for the other one
 
and I create an array of std::function s and call a random element of that array? @nwp
 
nwp
yeah, you could do that
 
Alright thanks for you help
will probably be back later anyway
 
nwp
11:31 AM
@sehe wrong tab?
 
Indeed it is :)
2 messages moved to Lounge<C++>
 
 
10 hours later…
9:58 PM
how to make a array splitted by a charachter in a string
?
@nwp
 
10:55 PM
@exitcode hey how is the text based game going? ;)
 

« first day (76 days earlier)      last day (2782 days later) »