OpenTTD Source  20240917-master-g9ab0a47812
story_base.h
Go to the documentation of this file.
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 
10 #ifndef STORY_BASE_H
11 #define STORY_BASE_H
12 
13 #include "company_type.h"
14 #include "story_type.h"
16 #include "gfx_type.h"
17 #include "vehicle_type.h"
18 #include "core/pool_type.hpp"
19 
22 extern StoryPageElementPool _story_page_element_pool;
23 extern StoryPagePool _story_page_pool;
24 extern uint32_t _story_page_element_next_sort_value;
25 extern uint32_t _story_page_next_sort_value;
26 
27 /*
28  * Each story page element is one of these types.
29  */
30 enum StoryPageElementType : uint8_t {
31  SPET_TEXT = 0,
37  SPET_END,
38  INVALID_SPET = 0xFF,
39 };
40 
42 enum StoryPageButtonFlags : uint8_t {
43  SPBF_NONE = 0,
44  SPBF_FLOAT_LEFT = 1 << 0,
45  SPBF_FLOAT_RIGHT = 1 << 1,
46 };
48 
49 
50 enum StoryPageButtonCursor : uint8_t {
51  SPBC_MOUSE,
52  SPBC_ZZZ,
53  SPBC_BUOY,
54  SPBC_QUERY,
55  SPBC_HQ,
56  SPBC_SHIP_DEPOT,
57  SPBC_SIGN,
58  SPBC_TREE,
59  SPBC_BUY_LAND,
60  SPBC_LEVEL_LAND,
61  SPBC_TOWN,
62  SPBC_INDUSTRY,
63  SPBC_ROCKY_AREA,
64  SPBC_DESERT,
65  SPBC_TRANSMITTER,
66  SPBC_AIRPORT,
67  SPBC_DOCK,
68  SPBC_CANAL,
69  SPBC_LOCK,
70  SPBC_RIVER,
71  SPBC_AQUEDUCT,
72  SPBC_BRIDGE,
73  SPBC_RAIL_STATION,
74  SPBC_TUNNEL_RAIL,
75  SPBC_TUNNEL_ELRAIL,
76  SPBC_TUNNEL_MONO,
77  SPBC_TUNNEL_MAGLEV,
78  SPBC_AUTORAIL,
79  SPBC_AUTOELRAIL,
80  SPBC_AUTOMONO,
81  SPBC_AUTOMAGLEV,
82  SPBC_WAYPOINT,
83  SPBC_RAIL_DEPOT,
84  SPBC_ELRAIL_DEPOT,
85  SPBC_MONO_DEPOT,
86  SPBC_MAGLEV_DEPOT,
87  SPBC_CONVERT_RAIL,
88  SPBC_CONVERT_ELRAIL,
89  SPBC_CONVERT_MONO,
90  SPBC_CONVERT_MAGLEV,
91  SPBC_AUTOROAD,
92  SPBC_AUTOTRAM,
93  SPBC_ROAD_DEPOT,
94  SPBC_BUS_STATION,
95  SPBC_TRUCK_STATION,
96  SPBC_ROAD_TUNNEL,
97  SPBC_CLONE_TRAIN,
98  SPBC_CLONE_ROADVEH,
99  SPBC_CLONE_SHIP,
100  SPBC_CLONE_AIRPLANE,
101  SPBC_DEMOLISH,
102  SPBC_LOWERLAND,
103  SPBC_RAISELAND,
104  SPBC_PICKSTATION,
105  SPBC_BUILDSIGNALS,
106  SPBC_END,
107  INVALID_SPBC = 0xFF
108 };
109 
117 {
118  return cursor < SPBC_END;
119 }
120 
123  uint32_t referenced_id;
124 
125  void SetColour(Colours button_colour);
126  void SetFlags(StoryPageButtonFlags flags);
127  void SetCursor(StoryPageButtonCursor cursor);
128  void SetVehicleType(VehicleType vehtype);
129  Colours GetColour() const;
130  StoryPageButtonFlags GetFlags() const;
132  VehicleType GetVehicleType() const;
133  bool ValidateColour() const;
134  bool ValidateFlags() const;
135  bool ValidateCursor() const;
136  bool ValidateVehicleType() const;
137 };
138 
144 struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
145  uint32_t sort_value;
148 
149  uint32_t referenced_id;
150  std::string text;
151 
155  inline StoryPageElement() { }
156 
160  inline ~StoryPageElement() { }
161 };
162 
164 struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
165  uint32_t sort_value;
168 
169  std::string title;
170 
174  inline StoryPage() { }
175 
179  inline ~StoryPage()
180  {
181  if (!this->CleaningPool()) {
183  if (spe->page == this->index) delete spe;
184  }
185  }
186  }
187 };
188 
189 #endif /* STORY_BASE_H */
190 
StoryPageButtonCursor
StoryPageButtonCursor
Mouse cursors usable by story page buttons.
Definition: story_base.h:50
StoryPage::title
std::string title
Title of story page.
Definition: story_base.h:169
StoryPage::date
TimerGameCalendar::Date date
Date when the page was created.
Definition: story_base.h:166
StoryPageButtonData::GetCursor
StoryPageButtonCursor GetCursor() const
Get the mouse cursor used while waiting for input for the button.
Definition: story.cpp:160
timer_game_calendar.h
StoryPageButtonData::SetCursor
void SetCursor(StoryPageButtonCursor cursor)
Set the mouse cursor used while waiting for input for the button.
Definition: story.cpp:133
StoryPageElement::StoryPageElement
StoryPageElement()
We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
Definition: story_base.h:155
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition: strong_typedef_type.hpp:150
StoryPageButtonData::SetColour
void SetColour(Colours button_colour)
Set the button background colour.
Definition: story.cpp:121
SPET_BUTTON_PUSH
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
Definition: story_base.h:34
StoryPageButtonData::ValidateVehicleType
bool ValidateVehicleType() const
Verity that the data stored a valid VehicleType value.
Definition: story.cpp:196
SPET_BUTTON_TILE
@ SPET_BUTTON_TILE
A button that allows the player to select a tile, and triggers an event with the tile.
Definition: story_base.h:35
StoryPageButtonData::ValidateCursor
bool ValidateCursor() const
Verify that the data stores a valid StoryPageButtonCursor value.
Definition: story.cpp:190
story_type.h
SPET_BUTTON_VEHICLE
@ SPET_BUTTON_VEHICLE
A button that allows the player to select a vehicle, and triggers an event wih the vehicle.
Definition: story_base.h:36
StoryPageElement::type
StoryPageElementType type
Type of page element.
Definition: story_base.h:147
StoryPageButtonData::GetVehicleType
VehicleType GetVehicleType() const
Get the type of vehicles that are accepted by the button.
Definition: story.cpp:168
SPET_LOCATION
@ SPET_LOCATION
An element that references a tile along with a one-line text.
Definition: story_base.h:32
IsValidStoryPageButtonCursor
bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
Checks if a StoryPageButtonCursor value is valid.
Definition: story_base.h:116
StoryPage
Struct about stories, current and completed.
Definition: story_base.h:164
StoryPage::StoryPage
StoryPage()
We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
Definition: story_base.h:174
StoryPage::~StoryPage
~StoryPage()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter
Definition: story_base.h:179
StoryPageButtonData::SetVehicleType
void SetVehicleType(VehicleType vehtype)
Set the type of vehicles that are accepted by the button.
Definition: story.cpp:140
SPET_TEXT
@ SPET_TEXT
A text element.
Definition: story_base.h:31
vehicle_type.h
Pool::PoolItem<&_story_page_element_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
Pool
Base class for all pools.
Definition: pool_type.hpp:80
SPET_GOAL
@ SPET_GOAL
An element that references a goal.
Definition: story_base.h:33
StoryPageElement::referenced_id
uint32_t referenced_id
Id of referenced object (location, goal etc.)
Definition: story_base.h:149
StoryPage::sort_value
uint32_t sort_value
A number that increases for every created story page. Used for sorting. The id of a story page is the...
Definition: story_base.h:165
Pool::PoolItem<&_story_page_pool >::CleaningPool
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition: pool_type.hpp:318
StoryPageButtonData::GetColour
Colours GetColour() const
Get the button background colour.
Definition: story.cpp:147
StoryPageElement::text
std::string text
Static content text of page element.
Definition: story_base.h:150
StoryPageElement
Struct about story page elements.
Definition: story_base.h:144
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
StoryPageButtonData
Helper to construct packed "id" values for button-type StoryPageElement.
Definition: story_base.h:122
pool_type.hpp
StoryPageElementType
StoryPageElementType
Definition: story_base.h:30
StoryPageButtonData::ValidateColour
bool ValidateColour() const
Verify that the data stored a valid Colour value.
Definition: story.cpp:174
StoryPageID
uint16_t StoryPageID
ID of a story page.
Definition: story_type.h:16
gfx_type.h
StoryPageElement::sort_value
uint32_t sort_value
A number that increases for every created story page element. Used for sorting. The id of a story pag...
Definition: story_base.h:145
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:237
StoryPage::company
CompanyID company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
Definition: story_base.h:167
company_type.h
StoryPageElement::page
StoryPageID page
Id of the page which the page element belongs to.
Definition: story_base.h:146
StoryPageButtonFlags
StoryPageButtonFlags
Flags available for buttons.
Definition: story_base.h:42
StoryPageElement::~StoryPageElement
~StoryPageElement()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter
Definition: story_base.h:160