OpenTTD Source  1.11.2
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"
15 #include "date_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 _story_page_element_next_sort_value;
25 extern uint32 _story_page_next_sort_value;
26 
27 /*
28  * Each story page element is one of these types.
29  */
30 enum StoryPageElementType : byte {
31  SPET_TEXT = 0,
37  SPET_END,
38  INVALID_SPET = 0xFF,
39 };
40 
42 template <> struct EnumPropsT<StoryPageElementType> : MakeEnumPropsT<StoryPageElementType, byte, SPET_TEXT, SPET_END, INVALID_SPET, 8> {};
43 
45 enum StoryPageButtonFlags : byte {
46  SPBF_NONE = 0,
47  SPBF_FLOAT_LEFT = 1 << 0,
48  SPBF_FLOAT_RIGHT = 1 << 1,
49 };
51 
52 
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
111 };
112 
114 template <> struct EnumPropsT<StoryPageButtonCursor> : MakeEnumPropsT<StoryPageButtonCursor, byte, SPBC_MOUSE, SPBC_END, INVALID_SPBC, 8> {};
115 
118  uint32 referenced_id;
119 
120  void SetColour(Colours button_colour);
121  void SetFlags(StoryPageButtonFlags flags);
122  void SetCursor(StoryPageButtonCursor cursor);
123  void SetVehicleType(VehicleType vehtype);
124  Colours GetColour() const;
125  StoryPageButtonFlags GetFlags() const;
127  VehicleType GetVehicleType() const;
128  bool ValidateColour() const;
129  bool ValidateFlags() const;
130  bool ValidateCursor() const;
131  bool ValidateVehicleType() const;
132 };
133 
139 struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
140  uint32 sort_value;
143 
144  uint32 referenced_id;
145  char *text;
146 
150  inline StoryPageElement() { }
151 
155  inline ~StoryPageElement() { free(this->text); }
156 };
157 
159 struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
160  uint32 sort_value;
163 
164  char *title;
165 
169  inline StoryPage() { }
170 
174  inline ~StoryPage()
175  {
176  if (!this->CleaningPool()) {
178  if (spe->page == this->index) delete spe;
179  }
180  }
181  free(this->title);
182  }
183 };
184 
185 #endif /* STORY_BASE_H */
186 
StoryPageElement::sort_value
uint32 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:140
SPET_TEXT
@ SPET_TEXT
A text element.
Definition: story_base.h:31
StoryPageButtonData::GetCursor
StoryPageButtonCursor GetCursor() const
Get the mouse cursor used while waiting for input for the button.
Definition: story.cpp:157
StoryPageButtonFlags
StoryPageButtonFlags
Flags available for buttons.
Definition: story_base.h:45
StoryPageElementType
StoryPageElementType
Definition: story_base.h:30
StoryPageButtonData::SetCursor
void SetCursor(StoryPageButtonCursor cursor)
Set the mouse cursor used while waiting for input for the button.
Definition: story.cpp:132
StoryPageElement::StoryPageElement
StoryPageElement()
We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
Definition: story_base.h:150
SPET_BUTTON_PUSH
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
Definition: story_base.h:34
SPET_GOAL
@ SPET_GOAL
An element that references a goal.
Definition: story_base.h:33
StoryPage::sort_value
uint32 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:160
StoryPageButtonData::SetColour
void SetColour(Colours button_colour)
Set the button background colour.
Definition: story.cpp:120
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
StoryPageElement::referenced_id
uint32 referenced_id
Id of referenced object (location, goal etc.)
Definition: story_base.h:144
StoryPageButtonData::ValidateVehicleType
bool ValidateVehicleType() const
Verity that the data stored a valid VehicleType value.
Definition: story.cpp:191
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
StoryPageButtonData::ValidateCursor
bool ValidateCursor() const
Verify that the data stores a valid StoryPageButtonCursor value.
Definition: story.cpp:185
story_type.h
EnumPropsT
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:48
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
StoryPageElement::type
StoryPageElementType type
Type of page element.
Definition: story_base.h:142
StoryPageID
uint16 StoryPageID
ID of a story page.
Definition: story_type.h:16
StoryPageButtonData::GetVehicleType
VehicleType GetVehicleType() const
Get the type of vehicles that are accepted by the button.
Definition: story.cpp:163
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
StoryPage
Struct about stories, current and completed.
Definition: story_base.h:159
SPET_LOCATION
@ SPET_LOCATION
An element that references a tile along with a one-line text.
Definition: story_base.h:32
StoryPage::StoryPage
StoryPage()
We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
Definition: story_base.h:169
StoryPageButtonCursor
StoryPageButtonCursor
Mouse cursors usable by story page buttons.
Definition: story_base.h:53
StoryPage::~StoryPage
~StoryPage()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter
Definition: story_base.h:174
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
StoryPage::title
char * title
Title of story page.
Definition: story_base.h:164
StoryPageButtonData::SetVehicleType
void SetVehicleType(VehicleType vehtype)
Set the type of vehicles that are accepted by the button.
Definition: story.cpp:139
date_type.h
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:378
Pool
Base class for all pools.
Definition: pool_type.hpp:81
Pool::PoolItem<&_story_page_pool >::CleaningPool
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition: pool_type.hpp:308
StoryPageButtonData::GetColour
Colours GetColour() const
Get the button background colour.
Definition: story.cpp:146
StoryPageElement
Struct about story page elements.
Definition: story_base.h:139
MakeEnumPropsT
Helper template class that makes basic properties of given enumeration type visible from outsize.
Definition: enum_type.hpp:62
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
StoryPageElement::text
char * text
Static content text of page element.
Definition: story_base.h:145
StoryPageButtonData
Helper to construct packed "id" values for button-type StoryPageElement.
Definition: story_base.h:117
pool_type.hpp
StoryPageButtonData::ValidateColour
bool ValidateColour() const
Verify that the data stored a valid Colour value.
Definition: story.cpp:169
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:456
gfx_type.h
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:226
StoryPage::date
Date date
Date when the page was created.
Definition: story_base.h:161
StoryPage::company
CompanyID company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
Definition: story_base.h:162
company_type.h
StoryPageElement::page
StoryPageID page
Id of the page which the page element belongs to.
Definition: story_base.h:141
StoryPageElement::~StoryPageElement
~StoryPageElement()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter
Definition: story_base.h:155