The easiest way to do it, would be via reflection, and a good usage of OOP.
Create a base 'GameEvent' class that has all the important info you need.
Eg;
ChanceToExecute (double/float/w.e)
Priority (whatever datatype you want here)
CanExecute (bool, to see if the event is allowed [good for checking for certain conditions])
Execute()
Pretty much; a randomized FSM implementation.
Excuse the C# code (just run it through a converter or something)
After loading all your 'GameEvent's, you can use something similar to this:
Code:
public abstract class GameEvent
{
public abstract float ChanceToExecute { get; }
public abstract int Priority { get; }
public abstract bool CanExecute { get; }
public abstract void Execute();
}
public class GameEventEngine
{
List<GameEvent> _events = new List<GameEvent>();
Random _rand = new Random();
public GameEvent GetNextEvent()
{
double randPct = _rand.NextDouble();
int randPriority = _rand.Next(0, 101);
foreach (GameEvent e in _events)
{
if (e.Priority > randPriority && e.ChanceToExecute > randPct && e.CanExecute)
{
return e;
}
}
// If percent based event grabbing fails, just randomize selection until we get something we can execute.
GameEvent ev = _events[_rand.Next(0, _events.Count)];
while (!ev.CanExecute)
ev = _events[_rand.Next(0, _events.Count)];
return ev;
}
Obviously, none of the code to load/prioritize things properly is there. (I have a thread about it in the C# section [it's for an FSM engine])
Just derive new events from the GameEvent class, and there ya go.