OpenTTD Source 20260108-master-g8ba1860eaa
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"
17#include "gfx_type.h"
18#include "vehicle_type.h"
19#include "core/pool_type.hpp"
20
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 */
41
43enum StoryPageButtonFlags : uint8_t {
44 SPBF_NONE = 0,
45 SPBF_FLOAT_LEFT = 1 << 0,
46 SPBF_FLOAT_RIGHT = 1 << 1,
47};
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
118{
119 return cursor < SPBC_END;
120}
121
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;
134 bool ValidateColour() const;
135 bool ValidateFlags() const;
136 bool ValidateCursor() const;
137 bool ValidateVehicleType() const;
138};
139
162
164struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
165 uint32_t sort_value = 0;
167 CompanyID company = CompanyID::Invalid();
168
170
171 StoryPage(StoryPageID index) : StoryPagePool::PoolItem<&_story_page_pool>(index) {}
172 StoryPage(StoryPageID index, uint32_t sort_value, TimerGameCalendar::Date date, CompanyID company, const EncodedString &title) :
174
175 ~StoryPage();
176};
177
178#endif /* STORY_BASE_H */
179
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:43
StoryPageElementType
Definition story_base.h:31
@ SPET_LOCATION
An element that references a tile along with a one-line text.
Definition story_base.h:33
@ SPET_GOAL
An element that references a goal.
Definition story_base.h:34
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
Definition story_base.h:35
@ 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
A text element.
Definition story_base.h:32
@ 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
Mouse cursors usable by story page buttons.
Definition story_base.h:51
bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
Checks if a StoryPageButtonCursor value is valid.
Definition story_base.h:117
Basic types related to story pages.
Types related to strings.
Base class for all PoolItems.
PoolItem(Tindex index)
Construct the item.
const Tindex index
Index of this pool item.
Base class for all pools.
Helper to construct packed "id" values for button-type StoryPageElement.
Definition story_base.h:123
Colours GetColour() const
Get the button background colour.
Definition story.cpp:156
VehicleType GetVehicleType() const
Get the type of vehicles that are accepted by the button.
Definition story.cpp:177
void SetColour(Colours button_colour)
Set the button background colour.
Definition story.cpp:130
bool ValidateVehicleType() const
Verity that the data stored a valid VehicleType value.
Definition story.cpp:205
bool ValidateColour() const
Verify that the data stored a valid Colour value.
Definition story.cpp:183
void SetVehicleType(VehicleType vehtype)
Set the type of vehicles that are accepted by the button.
Definition story.cpp:149
StoryPageButtonCursor GetCursor() const
Get the mouse cursor used while waiting for input for the button.
Definition story.cpp:169
bool ValidateCursor() const
Verify that the data stores a valid StoryPageButtonCursor value.
Definition story.cpp:199
void SetCursor(StoryPageButtonCursor cursor)
Set the mouse cursor used while waiting for input for the button.
Definition story.cpp:142
Struct about story page elements.
Definition story_base.h:145
uint32_t referenced_id
Id of referenced object (location, goal etc.)
Definition story_base.h:150
EncodedString text
Static content text of page element.
Definition story_base.h:151
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
StoryPageElementType type
Type of page element.
Definition story_base.h:148
~StoryPageElement()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter
Definition story_base.h:160
StoryPageID page
Id of the page which the page element belongs to.
Definition story_base.h:147
Struct about stories, current and completed.
Definition story_base.h:164
EncodedString title
Title of story page.
Definition story_base.h:169
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
CompanyID company
StoryPage is for a specific company; CompanyID::Invalid() if it is global.
Definition story_base.h:167
TimerGameCalendar::Date date
Date when the page was created.
Definition story_base.h:166
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition of the game-calendar-timer.
Types related to vehicles.
VehicleType
Available vehicle types.