OpenTTD

story_base.h
Go to the documentation of this file.
1 /* $Id: story_base.h 25621 2013-07-21 15:21:55Z zuu $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef STORY_BASE_H
13 #define STORY_BASE_H
14
15 #include "company_type.h"
16 #include "story_type.h"
17 #include "date_type.h"
18 #include "core/pool_type.hpp"
19
20 typedef Pool<StoryPageElement, StoryPageElementID, 64, 64000> StoryPageElementPool;
21 typedef Pool<StoryPage, StoryPageID, 64, 64000> StoryPagePool;
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 {
31 SPET_TEXT = 0,
32 SPET_LOCATION,
33 SPET_GOAL,
34 SPET_END,
35 INVALID_SPET = 0xFF,
36 };
37
39 template <> struct EnumPropsT<StoryPageElementType> : MakeEnumPropsT<StoryPageElementType, byte, SPET_TEXT, SPET_END, INVALID_SPET, 8> {};
40 typedef TinyEnumT<StoryPageElementType> StoryPageElementTypeByte;
41
47 struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
48 uint32 sort_value;
49 StoryPageID page;
50 StoryPageElementTypeByte type;
51
52 uint32 referenced_id;
53 char *text;
54
58 inline StoryPageElement() { }
59
63 inline ~StoryPageElement() { free(this->text); }
64 };
65
66 #define FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPageElement, story_page_element_index, var, start)
67 #define FOR_ALL_STORY_PAGE_ELEMENTS(var) FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, 0)
68
70 struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
71 uint32 sort_value;
72 Date date;
73 CompanyByte company;
74
75 char *title;
76
80 inline StoryPage() { }
81
85 inline ~StoryPage()
86 {
87 if (!this->CleaningPool()) {
88 StoryPageElement *spe;
89 FOR_ALL_STORY_PAGE_ELEMENTS(spe) {
90 if (spe->page == this->index) delete spe;
91 }
92 }
93 free(this->title);
94 }
95 };
96
97 #define FOR_ALL_STORY_PAGES_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPage, story_page_index, var, start)
98 #define FOR_ALL_STORY_PAGES(var) FOR_ALL_STORY_PAGES_FROM(var, 0)
99
100 #endif /* STORY_BASE_H */
101
StoryPageElement::StoryPageElement
StoryPageElement()
We need an (empty) constructor so struct isn&#39;t zeroed (as C++ standard states)
Definition: story_base.h:58
MakeEnumPropsT
Helper template class that makes basic properties of given enumeration type visible from outsize...
Definition: enum_type.hpp:66
StoryPageElementType
StoryPageElementType
Definition: story_base.h:30
StoryPageElement::page
StoryPageID page
Id of the page which the page element belongs to.
Definition: story_base.h:49
StoryPageElement::~StoryPageElement
~StoryPageElement()
(Empty) destructor has to be defined else operator delete might be called with NULL parameter ...
Definition: story_base.h:63
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:48
StoryPage::date
Date date
Date when the page was created.
Definition: story_base.h:72
StoryPage::~StoryPage
~StoryPage()
(Empty) destructor has to be defined else operator delete might be called with NULL parameter ...
Definition: story_base.h:85
StoryPage::title
char * title
Title of story page.
Definition: story_base.h:75
pool_type.hpp
Defintion of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
story_type.h
basic types related to story pages
StoryPageElement
Struct about story page elements.
Definition: story_base.h:47
StoryPageElement::referenced_id
uint32 referenced_id
Id of referenced object (location, goal etc.)
Definition: story_base.h:52
StoryPage
Struct about stories, current and completed.
Definition: story_base.h:70
EnumPropsT
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:52
TinyEnumT< StoryPageElementType >
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:71
StoryPage::company
CompanyByte company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
Definition: story_base.h:73
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:146
Pool
Base class for all pools.
Definition: pool_type.hpp:83
SPET_TEXT
A text element.
Definition: story_base.h:31
StoryPageElementTypeByte
TinyEnumT< StoryPageElementType > StoryPageElementTypeByte
typedefing-enumification of Direction
Definition: story_base.h:40
SPET_GOAL
An element that references a goal.
Definition: story_base.h:33
company_type.h
Types related to companies.
date_type.h
Types related to the dates in OpenTTD.
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:16
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
SPET_LOCATION
An element that references a tile along with a one-line text.
Definition: story_base.h:32
StoryPageElement::text
char * text
Static content text of page element.
Definition: story_base.h:53
StoryPageElement::type
StoryPageElementTypeByte type
Type of page element.
Definition: story_base.h:50
StoryPage::StoryPage
StoryPage()
We need an (empty) constructor so struct isn&#39;t zeroed (as C++ standard states)
Definition: story_base.h:80
StoryPageID
uint16 StoryPageID
ID of a story page.
Definition: story_type.h:18