OpenTTD Source: src/story_base.h Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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 "strings_type.h"
16#include "timer/timer_game_calendar.h"
17#include "gfx_type.h"
18#include "vehicle_type.h"
19#include "core/pool_type.hpp"
20
21using StoryPageElementPool = Pool<StoryPageElement, StoryPageElementID, 64>;
22using StoryPagePool = Pool<StoryPage, StoryPageID, 64>;
23extern StoryPageElementPool _story_page_element_pool;
24extern StoryPagePool _story_page_pool;
25extern uint32_t _story_page_element_next_sort_value;
26extern uint32_t _story_page_next_sort_value;
27
28/*
29 * Each story page element is one of these types.
30 */
31 enum StoryPageElementType : uint8_t {
32 SPET_TEXT = 0,
33 SPET_LOCATION,
34 SPET_GOAL,
35 SPET_BUTTON_PUSH,
36 SPET_BUTTON_TILE,
37 SPET_BUTTON_VEHICLE,
38 SPET_END,
39 INVALID_SPET = 0xFF,
40};
41
43 enum StoryPageButtonFlags : uint8_t {
44 SPBF_NONE = 0,
45 SPBF_FLOAT_LEFT = 1 << 0,
46 SPBF_FLOAT_RIGHT = 1 << 1,
47};
48 DECLARE_ENUM_AS_BIT_SET(StoryPageButtonFlags)
49
50
51enum StoryPageButtonCursor : uint8_t {
52 SPBC_MOUSE,
53 SPBC_ZZZ,
54 SPBC_BUOY,
55 SPBC_QUERY,
56 SPBC_HQ,
57 SPBC_SHIP_DEPOT,
58 SPBC_SIGN,
59 SPBC_TREE,
60 SPBC_BUY_LAND,
61 SPBC_LEVEL_LAND,
62 SPBC_TOWN,
63 SPBC_INDUSTRY,
64 SPBC_ROCKY_AREA,
65 SPBC_DESERT,
66 SPBC_TRANSMITTER,
67 SPBC_AIRPORT,
68 SPBC_DOCK,
69 SPBC_CANAL,
70 SPBC_LOCK,
71 SPBC_RIVER,
72 SPBC_AQUEDUCT,
73 SPBC_BRIDGE,
74 SPBC_RAIL_STATION,
75 SPBC_TUNNEL_RAIL,
76 SPBC_TUNNEL_ELRAIL,
77 SPBC_TUNNEL_MONO,
78 SPBC_TUNNEL_MAGLEV,
79 SPBC_AUTORAIL,
80 SPBC_AUTOELRAIL,
81 SPBC_AUTOMONO,
82 SPBC_AUTOMAGLEV,
83 SPBC_WAYPOINT,
84 SPBC_RAIL_DEPOT,
85 SPBC_ELRAIL_DEPOT,
86 SPBC_MONO_DEPOT,
87 SPBC_MAGLEV_DEPOT,
88 SPBC_CONVERT_RAIL,
89 SPBC_CONVERT_ELRAIL,
90 SPBC_CONVERT_MONO,
91 SPBC_CONVERT_MAGLEV,
92 SPBC_AUTOROAD,
93 SPBC_AUTOTRAM,
94 SPBC_ROAD_DEPOT,
95 SPBC_BUS_STATION,
96 SPBC_TRUCK_STATION,
97 SPBC_ROAD_TUNNEL,
98 SPBC_CLONE_TRAIN,
99 SPBC_CLONE_ROADVEH,
100 SPBC_CLONE_SHIP,
101 SPBC_CLONE_AIRPLANE,
102 SPBC_DEMOLISH,
103 SPBC_LOWERLAND,
104 SPBC_RAISELAND,
105 SPBC_PICKSTATION,
106 SPBC_BUILDSIGNALS,
107 SPBC_END,
108 INVALID_SPBC = 0xFF
109};
110
117 inline bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
118{
119 return cursor < SPBC_END;
120}
121
123 struct StoryPageButtonData {
124 uint32_t referenced_id = 0;
125
126 void SetColour(Colours button_colour);
127 void SetFlags(StoryPageButtonFlags flags);
128 void SetCursor(StoryPageButtonCursor cursor);
129 void SetVehicleType(VehicleType vehtype);
130 Colours GetColour() const;
131 StoryPageButtonFlags GetFlags() const;
132 StoryPageButtonCursor GetCursor() const;
133 VehicleType GetVehicleType() const;
134 bool ValidateColour() const;
135 bool ValidateFlags() const;
136 bool ValidateCursor() const;
137 bool ValidateVehicleType() const;
138};
139
145 struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
146 uint32_t sort_value = 0;
147 StoryPageID page{};
148 StoryPageElementType type{};
149
150 uint32_t referenced_id = 0;
151 EncodedString text{};
152
156 StoryPageElement() { }
157 StoryPageElement(uint32_t sort_value, StoryPageElementType type, StoryPageID page) :
158 sort_value(sort_value), page(page), type(type) { }
159
163 ~StoryPageElement() { }
164};
165
167 struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
168 uint32_t sort_value = 0;
169 TimerGameCalendar::Date date{};
170 CompanyID company = CompanyID::Invalid();
171
172 EncodedString title;
173
177 StoryPage() { }
178 StoryPage(uint32_t sort_value, TimerGameCalendar::Date date, CompanyID company, const EncodedString &title) :
179 sort_value(sort_value), date(date), company(company), title(title) {}
180
181 ~StoryPage();
182};
183
184#endif /* STORY_BASE_H */
185
EncodedString
Container for an encoded string, created by GetEncodedString.
Definition strings_type.h:98
company_type.h
Types related to companies.
DECLARE_ENUM_AS_BIT_SET
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:119
gfx_type.h
Types related to the graphics and/or input devices.
pool_type.hpp
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
StoryPageButtonFlags
StoryPageButtonFlags
Flags available for buttons.
Definition story_base.h:43
StoryPageElementType
StoryPageElementType
Definition story_base.h:31
SPET_LOCATION
@ SPET_LOCATION
An element that references a tile along with a one-line text.
Definition story_base.h:33
SPET_GOAL
@ SPET_GOAL
An element that references a goal.
Definition story_base.h:34
SPET_BUTTON_PUSH
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
Definition story_base.h:35
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:36
SPET_TEXT
@ SPET_TEXT
A text element.
Definition story_base.h:32
SPET_BUTTON_VEHICLE
@ SPET_BUTTON_VEHICLE
A button that allows the player to select a vehicle, and triggers an event with the vehicle.
Definition story_base.h:37
StoryPageButtonCursor
StoryPageButtonCursor
Mouse cursors usable by story page buttons.
Definition story_base.h:51
IsValidStoryPageButtonCursor
bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
Checks if a StoryPageButtonCursor value is valid.
Definition story_base.h:117
story_type.h
basic types related to story pages
strings_type.h
Types related to strings.
PoolID< uint16_t, struct StoryPageIDTag, 64000, 0xFFFF >
Pool::PoolItem
Base class for all PoolItems.
Definition pool_type.hpp:285
Pool
Base class for all pools.
Definition pool_type.hpp:133
StoryPageButtonData
Helper to construct packed "id" values for button-type StoryPageElement.
Definition story_base.h:123
StoryPageButtonData::GetColour
Colours GetColour() const
Get the button background colour.
Definition story.cpp:156
StoryPageButtonData::GetVehicleType
VehicleType GetVehicleType() const
Get the type of vehicles that are accepted by the button.
Definition story.cpp:177
StoryPageButtonData::SetColour
void SetColour(Colours button_colour)
Set the button background colour.
Definition story.cpp:130
StoryPageButtonData::ValidateVehicleType
bool ValidateVehicleType() const
Verity that the data stored a valid VehicleType value.
Definition story.cpp:205
StoryPageButtonData::ValidateColour
bool ValidateColour() const
Verify that the data stored a valid Colour value.
Definition story.cpp:183
StoryPageButtonData::SetVehicleType
void SetVehicleType(VehicleType vehtype)
Set the type of vehicles that are accepted by the button.
Definition story.cpp:149
StoryPageButtonData::GetCursor
StoryPageButtonCursor GetCursor() const
Get the mouse cursor used while waiting for input for the button.
Definition story.cpp:169
StoryPageButtonData::ValidateCursor
bool ValidateCursor() const
Verify that the data stores a valid StoryPageButtonCursor value.
Definition story.cpp:199
StoryPageButtonData::SetCursor
void SetCursor(StoryPageButtonCursor cursor)
Set the mouse cursor used while waiting for input for the button.
Definition story.cpp:142
StoryPageElement
Struct about story page elements.
Definition story_base.h:145
StoryPageElement::referenced_id
uint32_t referenced_id
Id of referenced object (location, goal etc.)
Definition story_base.h:150
StoryPageElement::text
EncodedString text
Static content text of page element.
Definition story_base.h:151
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:146
StoryPageElement::type
StoryPageElementType type
Type of page element.
Definition story_base.h:148
StoryPageElement::~StoryPageElement
~StoryPageElement()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter
Definition story_base.h:163
StoryPageElement::StoryPageElement
StoryPageElement()
We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
Definition story_base.h:156
StoryPageElement::page
StoryPageID page
Id of the page which the page element belongs to.
Definition story_base.h:147
StoryPage
Struct about stories, current and completed.
Definition story_base.h:167
StoryPage::title
EncodedString title
Title of story page.
Definition story_base.h:172
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:168
StoryPage::StoryPage
StoryPage()
We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
Definition story_base.h:177
StoryPage::company
CompanyID company
StoryPage is for a specific company; CompanyID::Invalid() if it is global.
Definition story_base.h:170
StoryPage::date
TimerGameCalendar::Date date
Date when the page was created.
Definition story_base.h:169
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
timer_game_calendar.h
Definition of the game-calendar-timer.
vehicle_type.h
Types related to vehicles.
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22