1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
8 /** @file script_event.hpp Everything to handle events from the game. */
9 
10 #ifndef SCRIPT_EVENT_HPP
11 #define SCRIPT_EVENT_HPP
12 
13 #include "script_object.hpp"
14 
15 /**
16  * Class that handles all event related functions.
17  * You can lookup the type, and than convert it to the real event-class.
18  * That way you can request more detailed information about the event.
19  * @api ai game
20  */
21 class ScriptEvent : public ScriptObject {
22 public:
23 	/**
24 	 * The type of event. Needed to lookup the detailed class.
25 	 */
26 	enum ScriptEventType {
27 		ET_INVALID = 0,
28 		ET_TEST,
29 		ET_SUBSIDY_OFFER,
30 		ET_SUBSIDY_OFFER_EXPIRED,
31 		ET_SUBSIDY_AWARDED,
32 		ET_SUBSIDY_EXPIRED,
33 		ET_ENGINE_PREVIEW,
34 		ET_COMPANY_NEW,
35 		ET_COMPANY_IN_TROUBLE,
36 		ET_COMPANY_ASK_MERGER,
37 		ET_COMPANY_MERGER,
38 		ET_COMPANY_BANKRUPT,
39 		ET_VEHICLE_CRASHED,
40 		ET_VEHICLE_LOST,
41 		ET_VEHICLE_WAITING_IN_DEPOT,
42 		ET_VEHICLE_UNPROFITABLE,
43 		ET_INDUSTRY_OPEN,
44 		ET_INDUSTRY_CLOSE,
45 		ET_ENGINE_AVAILABLE,
46 		ET_STATION_FIRST_VEHICLE,
47 		ET_DISASTER_ZEPPELINER_CRASHED,
48 		ET_DISASTER_ZEPPELINER_CLEARED,
49 		ET_TOWN_FOUNDED,
50 		ET_AIRCRAFT_DEST_TOO_FAR,
51 		ET_ADMIN_PORT,
52 		ET_WINDOW_WIDGET_CLICK,
53 		ET_GOAL_QUESTION_ANSWER,
54 		ET_EXCLUSIVE_TRANSPORT_RIGHTS,
55 		ET_ROAD_RECONSTRUCTION,
56 		ET_VEHICLE_AUTOREPLACED,
57 		ET_STORYPAGE_BUTTON_CLICK,
58 		ET_STORYPAGE_TILE_SELECT,
59 		ET_STORYPAGE_VEHICLE_SELECT,
60 	};
61 
62 	/**
63 	 * Constructor of ScriptEvent, to get the type of event.
64 	 */
ScriptEvent(ScriptEvent::ScriptEventType type)65 	ScriptEvent(ScriptEvent::ScriptEventType type) :
66 		type(type)
67 	{}
68 
69 	/**
70 	 * Get the event-type.
71 	 * @return The @c ScriptEventType.
72 	 */
GetEventType()73 	ScriptEventType GetEventType() { return this->type; }
74 
75 protected:
76 	/**
77 	 * The type of this event.
78 	 */
79 	ScriptEventType type;
80 };
81 
82 /**
83  * Class that handles all event related functions.
84  * @api ai game
85  * @note it is not needed to create an instance of ScriptEvent to access it, as
86  *  all members are static, and all data is stored script instance-wide.
87  */
88 class ScriptEventController : public ScriptObject {
89 public:
90 	/**
91 	 * Check if there is an event waiting.
92 	 * @return true if there is an event on the stack.
93 	 */
94 	static bool IsEventWaiting();
95 
96 	/**
97 	 * Get the next event.
98 	 * @return a class of the event-child issues.
99 	 */
100 	static ScriptEvent *GetNextEvent();
101 
102 	/**
103 	 * Insert an event to the queue for the company.
104 	 * @param event The event to insert.
105 	 * @api -all
106 	 */
107 	static void InsertEvent(ScriptEvent *event);
108 
109 	/**
110 	 * Free the event pointer.
111 	 * @api -all
112 	 */
113 	static void FreeEventPointer();
114 
115 private:
116 	/**
117 	 * Create the event pointer.
118 	 */
119 	static void CreateEventPointer();
120 };
121 
122 #endif /* SCRIPT_EVENT_HPP */
123