OpenTTD Source 20260311-master-g511d3794ce
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
9
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"
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
39
41enum StoryPageButtonFlags : uint8_t {
42 SPBF_NONE = 0,
43 SPBF_FLOAT_LEFT = 1 << 0,
44 SPBF_FLOAT_RIGHT = 1 << 1,
45};
47
48
49enum StoryPageButtonCursor : uint8_t {
50 SPBC_MOUSE,
51 SPBC_ZZZ,
52 SPBC_BUOY,
53 SPBC_QUERY,
54 SPBC_HQ,
55 SPBC_SHIP_DEPOT,
56 SPBC_SIGN,
57 SPBC_TREE,
58 SPBC_BUY_LAND,
59 SPBC_LEVEL_LAND,
60 SPBC_TOWN,
61 SPBC_INDUSTRY,
62 SPBC_ROCKY_AREA,
63 SPBC_DESERT,
64 SPBC_TRANSMITTER,
65 SPBC_AIRPORT,
66 SPBC_DOCK,
67 SPBC_CANAL,
68 SPBC_LOCK,
69 SPBC_RIVER,
70 SPBC_AQUEDUCT,
71 SPBC_BRIDGE,
72 SPBC_RAIL_STATION,
73 SPBC_TUNNEL_RAIL,
74 SPBC_TUNNEL_ELRAIL,
75 SPBC_TUNNEL_MONO,
76 SPBC_TUNNEL_MAGLEV,
77 SPBC_AUTORAIL,
78 SPBC_AUTOELRAIL,
79 SPBC_AUTOMONO,
80 SPBC_AUTOMAGLEV,
81 SPBC_WAYPOINT,
82 SPBC_RAIL_DEPOT,
83 SPBC_ELRAIL_DEPOT,
84 SPBC_MONO_DEPOT,
85 SPBC_MAGLEV_DEPOT,
86 SPBC_CONVERT_RAIL,
87 SPBC_CONVERT_ELRAIL,
88 SPBC_CONVERT_MONO,
89 SPBC_CONVERT_MAGLEV,
90 SPBC_AUTOROAD,
91 SPBC_AUTOTRAM,
92 SPBC_ROAD_DEPOT,
93 SPBC_BUS_STATION,
94 SPBC_TRUCK_STATION,
95 SPBC_ROAD_TUNNEL,
96 SPBC_CLONE_TRAIN,
97 SPBC_CLONE_ROADVEH,
98 SPBC_CLONE_SHIP,
99 SPBC_CLONE_AIRPLANE,
100 SPBC_DEMOLISH,
101 SPBC_LOWERLAND,
102 SPBC_RAISELAND,
103 SPBC_PICKSTATION,
104 SPBC_BUILDSIGNALS,
105 SPBC_END,
106 INVALID_SPBC = 0xFF
107};
108
116{
117 return cursor < SPBC_END;
118}
119
122 uint32_t referenced_id = 0;
123
124 void SetColour(Colours button_colour);
125 void SetFlags(StoryPageButtonFlags flags);
126 void SetCursor(StoryPageButtonCursor cursor);
127 void SetVehicleType(VehicleType vehtype);
128 Colours GetColour() const;
132 bool ValidateColour() const;
133 bool ValidateFlags() const;
134 bool ValidateCursor() const;
135 bool ValidateVehicleType() const;
136};
137
143struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
144 uint32_t sort_value = 0;
147
148 uint32_t referenced_id = 0;
150
151 StoryPageElement(StoryPageElementID index) : StoryPageElementPool::PoolItem<&_story_page_element_pool>(index) {}
153 StoryPageElementPool::PoolItem<&_story_page_element_pool>(index), sort_value(sort_value), page(page), type(type) {}
154
159};
160
162struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
163 uint32_t sort_value = 0;
164 TimerGameCalendar::Date date{};
165 CompanyID company = CompanyID::Invalid();
166
168
169 StoryPage(StoryPageID index) : StoryPagePool::PoolItem<&_story_page_pool>(index) {}
170 StoryPage(StoryPageID index, uint32_t sort_value, TimerGameCalendar::Date date, CompanyID company, const EncodedString &title) :
171 StoryPagePool::PoolItem<&_story_page_pool>(index), sort_value(sort_value), date(date), company(company), title(title) {}
172
173 ~StoryPage();
174};
175
176#endif /* STORY_BASE_H */
177
Container for an encoded string, created by GetEncodedString.
Types related to companies.
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Types related to the graphics and/or input devices.
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
StoryPageButtonFlags
Flags available for buttons.
Definition story_base.h:41
StoryPageElementType
Each story page element is one of these types.
Definition story_base.h:29
@ SPET_LOCATION
An element that references a tile along with a one-line text.
Definition story_base.h:31
@ SPET_GOAL
An element that references a goal.
Definition story_base.h:32
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
Definition story_base.h:33
@ SPET_BUTTON_TILE
A button that allows the player to select a tile, and triggers an event with the tile.
Definition story_base.h:34
@ SPET_TEXT
A text element.
Definition story_base.h:30
@ SPET_BUTTON_VEHICLE
A button that allows the player to select a vehicle, and triggers an event with the vehicle.
Definition story_base.h:35
StoryPageButtonCursor
Mouse cursors usable by story page buttons.
Definition story_base.h:49
bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
Checks if a StoryPageButtonCursor value is valid.
Definition story_base.h:115
Basic types related to story pages.
PoolID< uint16_t, struct StoryPageIDTag, 64000, 0xFFFF > StoryPageID
ID of a story page.
Definition story_type.h:16
PoolID< uint16_t, struct StoryPageElementIDTag, 64000, 0xFFFF > StoryPageElementID
ID of a story page element.
Definition story_type.h:15
Types related to strings.
Base class for all pools.
Helper to construct packed "id" values for button-type StoryPageElement.
Definition story_base.h:121
Colours GetColour() const
Get the button background colour.
Definition story.cpp:173
VehicleType GetVehicleType() const
Get the type of vehicles that are accepted by the button.
Definition story.cpp:204
void SetColour(Colours button_colour)
Set the button background colour.
Definition story.cpp:134
bool ValidateVehicleType() const
Verity that the data stored a valid VehicleType value.
Definition story.cpp:246
StoryPageButtonFlags GetFlags() const
Get the button flags.
Definition story.cpp:184
bool ValidateFlags() const
Verify that valid flags were set.
Definition story.cpp:223
bool ValidateColour() const
Verify that the data stored a valid Colour value.
Definition story.cpp:213
void SetVehicleType(VehicleType vehtype)
Set the type of vehicles that are accepted by the button.
Definition story.cpp:163
StoryPageButtonCursor GetCursor() const
Get the mouse cursor used while waiting for input for the button.
Definition story.cpp:193
bool ValidateCursor() const
Verify that the data stores a valid StoryPageButtonCursor value.
Definition story.cpp:237
void SetCursor(StoryPageButtonCursor cursor)
Set the mouse cursor used while waiting for input for the button.
Definition story.cpp:153
void SetFlags(StoryPageButtonFlags flags)
Set the button flags.
Definition story.cpp:144
Struct about story page elements.
Definition story_base.h:143
uint32_t referenced_id
Id of referenced object (location, goal etc.).
Definition story_base.h:148
EncodedString text
Static content text of page element.
Definition story_base.h:149
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:144
StoryPageElementType type
Type of page element.
Definition story_base.h:146
~StoryPageElement()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter
Definition story_base.h:158
StoryPageID page
Id of the page which the page element belongs to.
Definition story_base.h:145
Struct about stories, current and completed.
Definition story_base.h:162
EncodedString title
Title of story page.
Definition story_base.h:167
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:163
CompanyID company
StoryPage is for a specific company; CompanyID::Invalid() if it is global.
Definition story_base.h:165
~StoryPage()
Delete all of our StoryPageElements.
Definition story.cpp:41
TimerGameCalendar::Date date
Date when the page was created.
Definition story_base.h:164
Definition of the game-calendar-timer.
Types related to vehicles.
VehicleType
Available vehicle types.