Fix 03cc0d6: Mark level crossings dirty when removing road from them, not from bridge...
[openttd-github.git] / src / story_base.h
blob09a8291fb6c6becb99a0bc121ecd67cf1eb5363e
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 */
8 /** @file story_base.h %StoryPage base class. */
10 #ifndef STORY_BASE_H
11 #define STORY_BASE_H
13 #include "company_type.h"
14 #include "story_type.h"
15 #include "date_type.h"
16 #include "gfx_type.h"
17 #include "vehicle_type.h"
18 #include "core/pool_type.hpp"
20 typedef Pool<StoryPageElement, StoryPageElementID, 64, 64000> StoryPageElementPool;
21 typedef Pool<StoryPage, StoryPageID, 64, 64000> StoryPagePool;
22 extern StoryPageElementPool _story_page_element_pool;
23 extern StoryPagePool _story_page_pool;
24 extern uint32 _story_page_element_next_sort_value;
25 extern uint32 _story_page_next_sort_value;
28 * Each story page element is one of these types.
30 enum StoryPageElementType : byte {
31 SPET_TEXT = 0, ///< A text element.
32 SPET_LOCATION, ///< An element that references a tile along with a one-line text.
33 SPET_GOAL, ///< An element that references a goal.
34 SPET_BUTTON_PUSH, ///< A push button that triggers an immediate event.
35 SPET_BUTTON_TILE, ///< A button that allows the player to select a tile, and triggers an event with the tile.
36 SPET_BUTTON_VEHICLE, ///< A button that allows the player to select a vehicle, and triggers an event wih the vehicle.
37 SPET_END,
38 INVALID_SPET = 0xFF,
41 /** Define basic enum properties */
42 template <> struct EnumPropsT<StoryPageElementType> : MakeEnumPropsT<StoryPageElementType, byte, SPET_TEXT, SPET_END, INVALID_SPET, 8> {};
44 /** Flags available for buttons */
45 enum StoryPageButtonFlags : byte {
46 SPBF_NONE = 0,
47 SPBF_FLOAT_LEFT = 1 << 0,
48 SPBF_FLOAT_RIGHT = 1 << 1,
50 DECLARE_ENUM_AS_BIT_SET(StoryPageButtonFlags)
52 /** Mouse cursors usable by story page buttons. */
53 enum StoryPageButtonCursor : byte {
54 SPBC_MOUSE,
55 SPBC_ZZZ,
56 SPBC_BUOY,
57 SPBC_QUERY,
58 SPBC_HQ,
59 SPBC_SHIP_DEPOT,
60 SPBC_SIGN,
61 SPBC_TREE,
62 SPBC_BUY_LAND,
63 SPBC_LEVEL_LAND,
64 SPBC_TOWN,
65 SPBC_INDUSTRY,
66 SPBC_ROCKY_AREA,
67 SPBC_DESERT,
68 SPBC_TRANSMITTER,
69 SPBC_AIRPORT,
70 SPBC_DOCK,
71 SPBC_CANAL,
72 SPBC_LOCK,
73 SPBC_RIVER,
74 SPBC_AQUEDUCT,
75 SPBC_BRIDGE,
76 SPBC_RAIL_STATION,
77 SPBC_TUNNEL_RAIL,
78 SPBC_TUNNEL_ELRAIL,
79 SPBC_TUNNEL_MONO,
80 SPBC_TUNNEL_MAGLEV,
81 SPBC_AUTORAIL,
82 SPBC_AUTOELRAIL,
83 SPBC_AUTOMONO,
84 SPBC_AUTOMAGLEV,
85 SPBC_WAYPOINT,
86 SPBC_RAIL_DEPOT,
87 SPBC_ELRAIL_DEPOT,
88 SPBC_MONO_DEPOT,
89 SPBC_MAGLEV_DEPOT,
90 SPBC_CONVERT_RAIL,
91 SPBC_CONVERT_ELRAIL,
92 SPBC_CONVERT_MONO,
93 SPBC_CONVERT_MAGLEV,
94 SPBC_AUTOROAD,
95 SPBC_AUTOTRAM,
96 SPBC_ROAD_DEPOT,
97 SPBC_BUS_STATION,
98 SPBC_TRUCK_STATION,
99 SPBC_ROAD_TUNNEL,
100 SPBC_CLONE_TRAIN,
101 SPBC_CLONE_ROADVEH,
102 SPBC_CLONE_SHIP,
103 SPBC_CLONE_AIRPLANE,
104 SPBC_DEMOLISH,
105 SPBC_LOWERLAND,
106 SPBC_RAISELAND,
107 SPBC_PICKSTATION,
108 SPBC_BUILDSIGNALS,
109 SPBC_END,
110 INVALID_SPBC = 0xFF
113 /** Define basic enum properties */
114 template <> struct EnumPropsT<StoryPageButtonCursor> : MakeEnumPropsT<StoryPageButtonCursor, byte, SPBC_MOUSE, SPBC_END, INVALID_SPBC, 8> {};
117 * Checks if a StoryPageButtonCursor value is valid.
119 * @param wc The value to check
120 * @return true if the given value is a valid StoryPageButtonCursor.
122 static inline bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
124 return cursor < SPBC_END;
127 /** Helper to construct packed "id" values for button-type StoryPageElement */
128 struct StoryPageButtonData {
129 uint32 referenced_id;
131 void SetColour(Colours button_colour);
132 void SetFlags(StoryPageButtonFlags flags);
133 void SetCursor(StoryPageButtonCursor cursor);
134 void SetVehicleType(VehicleType vehtype);
135 Colours GetColour() const;
136 StoryPageButtonFlags GetFlags() const;
137 StoryPageButtonCursor GetCursor() const;
138 VehicleType GetVehicleType() const;
139 bool ValidateColour() const;
140 bool ValidateFlags() const;
141 bool ValidateCursor() const;
142 bool ValidateVehicleType() const;
146 * Struct about story page elements.
147 * Each StoryPage is composed of one or more page elements that provide
148 * page content. Each element only contain one type of content.
150 struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
151 uint32 sort_value; ///< A number that increases for every created story page element. Used for sorting. The id of a story page element is the pool index.
152 StoryPageID page; ///< Id of the page which the page element belongs to
153 StoryPageElementType type; ///< Type of page element
155 uint32 referenced_id; ///< Id of referenced object (location, goal etc.)
156 char *text; ///< Static content text of page element
159 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
161 inline StoryPageElement() { }
164 * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
166 inline ~StoryPageElement() { free(this->text); }
169 /** Struct about stories, current and completed */
170 struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
171 uint32 sort_value; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index.
172 Date date; ///< Date when the page was created.
173 CompanyID company; ///< StoryPage is for a specific company; INVALID_COMPANY if it is global
175 char *title; ///< Title of story page
178 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
180 inline StoryPage() { }
183 * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
185 inline ~StoryPage()
187 if (!this->CleaningPool()) {
188 for (StoryPageElement *spe : StoryPageElement::Iterate()) {
189 if (spe->page == this->index) delete spe;
192 free(this->title);
196 #endif /* STORY_BASE_H */