Skip to content

Event Based Geoscape AI

karvanit edited this page Nov 17, 2012 · 3 revisions

Basic idea

Everything that happens in the game while in Geoscape mode will generate events, which will be send to a handler. This handler can do whatever it likes with the information contained in the events. The whole think must happen in a way that is easy to extend, both by adding new events and by changing the resultant behaviour. The idea is to have many handler objects, each responsible for one kind of functionality (eg movement, scoring, alien mission generation). This should eventually clean up GeoscapeState and move all the behaviour code to other objects, which can then be easily replaced by mods. (eg AlienMission generator, GameScoring)

Top level design

Events are objects, with their class specific to the event and all relevant data contained in fields. As new events happen they are immediately send to handlers. The handlers can only read the information recorded in the events, but can't change them in any way.

Implementation

The rest of the system only sees an abstract interface that can receive events, through the post() method. The actual abstract class GeoEventHandler has a set of overloaded virtual functions (handle(const X &)), for all the possible event types X. I am using double dispatch to match the events with the appropriate handling methods on the handler. Through the use of the CRTP the event classes don't need to care about how this works, they just have to directly and publicly inherit from the GeoEvent template, passing themselves as the template argument. For example (actually used in the current version):

class GeoEvent30Minutes: public GeoEvent<GeoEvent30Minutes> {
	/* That's All */
};

The default handlers simply ignore the events. The current AI code in GeoscapeAI only keeps track of 30 minute intervals, to randomly spawn UFOs and Terror sites.

Clone this wiki locally