OpenTTD
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 "core/pool_type.hpp"
17 
20 extern StoryPageElementPool _story_page_element_pool;
21 extern StoryPagePool _story_page_pool;
22 extern uint32 _story_page_element_next_sort_value;
23 extern uint32 _story_page_next_sort_value;
24 
25 /*
26  * Each story page element is one of these types.
27  */
28 enum StoryPageElementType : byte {
29  SPET_TEXT = 0,
32  SPET_END,
33  INVALID_SPET = 0xFF,
34 };
35 
37 template <> struct EnumPropsT<StoryPageElementType> : MakeEnumPropsT<StoryPageElementType, byte, SPET_TEXT, SPET_END, INVALID_SPET, 8> {};
38 
44 struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
45  uint32 sort_value;
47  StoryPageElementType type;
48 
49  uint32 referenced_id;
50  char *text;
51 
55  inline StoryPageElement() { }
56 
60  inline ~StoryPageElement() { free(this->text); }
61 };
62 
64 struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
65  uint32 sort_value;
68 
69  char *title;
70 
74  inline StoryPage() { }
75 
79  inline ~StoryPage()
80  {
81  if (!this->CleaningPool()) {
83  if (spe->page == this->index) delete spe;
84  }
85  }
86  free(this->title);
87  }
88 };
89 
90 #endif /* STORY_BASE_H */
91 
StoryPageElement()
We need an (empty) constructor so struct isn&#39;t zeroed (as C++ standard states)
Definition: story_base.h:55
Helper template class that makes basic properties of given enumeration type visible from outsize...
Definition: enum_type.hpp:62
Owner
Enum for all companies/owners.
Definition: company_type.h:18
An element that references a tile along with a one-line text.
Definition: story_base.h:30
StoryPageID page
Id of the page which the page element belongs to.
Definition: story_base.h:46
~StoryPageElement()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter ...
Definition: story_base.h:60
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:45
Date date
Date when the page was created.
Definition: story_base.h:66
~StoryPage()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter ...
Definition: story_base.h:79
char * title
Title of story page.
Definition: story_base.h:69
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
basic types related to story pages
Struct about story page elements.
Definition: story_base.h:44
uint32 referenced_id
Id of referenced object (location, goal etc.)
Definition: story_base.h:49
Struct about stories, current and completed.
Definition: story_base.h:64
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:48
StoryPageElementType type
Type of page element.
Definition: story_base.h:47
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:65
Base class for all PoolItems.
Definition: pool_type.hpp:188
Base class for all pools.
Definition: pool_type.hpp:82
An element that references a goal.
Definition: story_base.h:31
A text element.
Definition: story_base.h:29
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:340
Types related to companies.
Types related to the dates in OpenTTD.
int32 Date
The type to store our dates in.
Definition: date_type.h:14
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
char * text
Static content text of page element.
Definition: story_base.h:50
StoryPage()
We need an (empty) constructor so struct isn&#39;t zeroed (as C++ standard states)
Definition: story_base.h:74
uint16 StoryPageID
ID of a story page.
Definition: story_type.h:16
CompanyID company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
Definition: story_base.h:67
StoryPageElementType
Definition: story_base.h:28