summaryrefslogtreecommitdiff
path: root/src/script/api/script_event.hpp
blob: eb15ded2ee6fd0a334a5a13f22e90ba6f0b91cc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* $Id$ */

/*
 * This file is part of OpenTTD.
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 */

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

#ifndef SCRIPT_EVENT_HPP
#define SCRIPT_EVENT_HPP

#include "script_object.hpp"

/**
 * Class that handles all event related functions.
 * 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 ScriptEvent : public ScriptObject {
public:
	/**
	 * The type of event. Needed to lookup the detailed class.
	 */
	enum ScriptEventType {
		AI_ET_INVALID = 0,
		AI_ET_TEST,
		AI_ET_SUBSIDY_OFFER,
		AI_ET_SUBSIDY_OFFER_EXPIRED,
		AI_ET_SUBSIDY_AWARDED,
		AI_ET_SUBSIDY_EXPIRED,
		AI_ET_ENGINE_PREVIEW,
		AI_ET_COMPANY_NEW,
		AI_ET_COMPANY_IN_TROUBLE,
		AI_ET_COMPANY_ASK_MERGER,
		AI_ET_COMPANY_MERGER,
		AI_ET_COMPANY_BANKRUPT,
		AI_ET_VEHICLE_CRASHED,
		AI_ET_VEHICLE_LOST,
		AI_ET_VEHICLE_WAITING_IN_DEPOT,
		AI_ET_VEHICLE_UNPROFITABLE,
		AI_ET_INDUSTRY_OPEN,
		AI_ET_INDUSTRY_CLOSE,
		AI_ET_ENGINE_AVAILABLE,
		AI_ET_STATION_FIRST_VEHICLE,
		AI_ET_DISASTER_ZEPPELINER_CRASHED,
		AI_ET_DISASTER_ZEPPELINER_CLEARED,
		AI_ET_TOWN_FOUNDED,
	};

	/**
	 * Constructor of ScriptEvent, to get the type of event.
	 */
	ScriptEvent(ScriptEvent::ScriptEventType type) :
		type(type)
	{}

	/**
	 * Get the event-type.
	 * @return The @c ScriptEventType.
	 */
	ScriptEventType GetEventType() { return this->type; }

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

/**
 * Class that handles all event related functions.
 * @note it is not needed to create an instance of ScriptEvent to access it, as
 *  all members are static, and all data is stored AI-wide.
 */
class ScriptEventController : public ScriptObject {
public:
	/**
	 * 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 ScriptEvent *GetNextEvent();

#ifndef EXPORT_SKIP
	/**
	 * Insert an event to the queue for the company.
	 * @param event The event to insert.
	 * @note DO NOT CALL YOURSELF; leave it to the internal AI programming.
	 */
	static void InsertEvent(ScriptEvent *event);

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

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

#endif /* SCRIPT_EVENT_HPP */