Codechange: Use cached town, station, industry names for list window sorting
[openttd-github.git] / src / story_base.h
blobe82b9d69647f47df16c76544acb8b7f25cba4e0f
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 */
8 /** @file story_base.h %StoryPage base class. */
10 #ifndef STORY_BASE_H
11 #define STORY_BASE_H
13 #include "company_type.h"
14 #include "story_type.h"
15 #include "date_type.h"
16 #include "core/pool_type.hpp"
18 typedef Pool<StoryPageElement, StoryPageElementID, 64, 64000> StoryPageElementPool;
19 typedef Pool<StoryPage, StoryPageID, 64, 64000> StoryPagePool;
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;
26 * Each story page element is one of these types.
28 enum StoryPageElementType : byte {
29 SPET_TEXT = 0, ///< A text element.
30 SPET_LOCATION, ///< An element that references a tile along with a one-line text.
31 SPET_GOAL, ///< An element that references a goal.
32 SPET_END,
33 INVALID_SPET = 0xFF,
36 /** Define basic enum properties */
37 template <> struct EnumPropsT<StoryPageElementType> : MakeEnumPropsT<StoryPageElementType, byte, SPET_TEXT, SPET_END, INVALID_SPET, 8> {};
39 /**
40 * Struct about story page elements.
41 * Each StoryPage is composed of one or more page elements that provide
42 * page content. Each element only contain one type of content.
43 **/
44 struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
45 uint32 sort_value; ///< A number that increases for every created story page element. Used for sorting. The id of a story page element is the pool index.
46 StoryPageID page; ///< Id of the page which the page element belongs to
47 StoryPageElementType type; ///< Type of page element
49 uint32 referenced_id; ///< Id of referenced object (location, goal etc.)
50 char *text; ///< Static content text of page element
52 /**
53 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
55 inline StoryPageElement() { }
57 /**
58 * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
60 inline ~StoryPageElement() { free(this->text); }
63 /** Struct about stories, current and completed */
64 struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
65 uint32 sort_value; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index.
66 Date date; ///< Date when the page was created.
67 CompanyID company; ///< StoryPage is for a specific company; INVALID_COMPANY if it is global
69 char *title; ///< Title of story page
71 /**
72 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
74 inline StoryPage() { }
76 /**
77 * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
79 inline ~StoryPage()
81 if (!this->CleaningPool()) {
82 for (StoryPageElement *spe : StoryPageElement::Iterate()) {
83 if (spe->page == this->index) delete spe;
86 free(this->title);
90 #endif /* STORY_BASE_H */