src/ai/api/ai_event.hpp
author truelight
Thu, 19 Jul 2007 22:39:43 +0000
branchnoai
changeset 9682 d031eb183733
child 9683 a4683b021073
permissions -rw-r--r--
(svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
/* $Id$ */

/** @file ai_event.hpp Everything to handle events from the game */

#ifndef AI_EVENT_HPP
#define AI_EVENT_HPP

#include "ai_object.hpp"

/**
 * A single event that can be triggered by the game.
 * You can lookup the type, and than convert it to the real event-class.
 * That way you can request more detailed information about the event.
 */
class AIEvent : public AIObject {
public:
	/**
	 * The type of event. Needed to lookup the detailed class.
	 */
	enum AIEventType {
		AI_ET_INVALID = 0,
		AI_ET_TEST,
		AI_ET_CRASHED_VEHICLE,
	};

	AIEvent(AIEvent::AIEventType type) :
		type(type)
	{}

	/**
	 * Get the event-type.
	 */
	AIEventType GetEventType() { return this->type; }

	/**
	 * The name of the class, needed by several sub-processes.
	 */
	static const char *GetClassName() { return "AIEvent"; }

protected:
	/**
	 * The type of this event.
	 */
	AIEventType type;
};

/**
 * Class that handles all event related functions.
 * @note it is not needed to create an instance of AIEvent to access it, as
 *  all members are static, and all data is stored AI-wide.
 */
class AIEventController : public AIObject {
public:
	/**
	 * The name of the class, needed by several sub-processes.
	 */
	static const char *GetClassName() { return "AIEventController"; }

	/**
	 * Check if there is an event waiting.
	 * @return true if there is an event on the stack.
	 */
	static bool IsEventWaiting();

	/**
	 * Get the next event.
	 * @return a class of the event-child issues.
	 */
	static AIEvent *GetNextEvent();

	/**
	 * No longer report an event of this type.
	 * @param event the event to no longer report.
	 */
	static void DisableEvent(AIEvent::AIEventType event);

	/**
	 * Report events of this type.
	 * @param event the event to report again.
	 */
	static void EnableEvent(AIEvent::AIEventType event);

	/**
	 * Disable all events.
	 */
	static void DisableAllEvents();

	/**
	 * Enable all events.
	 */
	static void EnableAllEvents();

	/**
	 * Insert an event to the queue for the player.
	 */
	static void InsertEvent(AIEvent *event);

	/**
	 * Give a test event to the system.
	 */
	static void Test();

	/**
	 * Free the event pointer.
	 * @note DO NOT CALL YOURSELF; leave it to the internal AI programming.
	 */
	static void FreeEventPointer();

private:
	/**
	 * Create the event pointer.
	 */
	static void CreateEventPointer();
};

#endif /* AI_EVENT_HPP */