Add a method in NewGRFInspectWindow to resolve FeatureIndex
[openttd/fttd.git] / src / story_base.h
blob3db1ba4a86d3c3690bdc46a26a36ecaabfffc783
1 /* $Id$ */
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 */
10 /** @file story_base.h %StoryPage base class. */
12 #ifndef STORY_BASE_H
13 #define STORY_BASE_H
15 #include "company_type.h"
16 #include "story_type.h"
17 #include "date_type.h"
18 #include "core/pool_type.hpp"
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;
28 * Each story page element is one of these types.
30 enum StoryPageElementType {
31 SPET_TEXT = 0, ///< A text element.
32 SPET_LOCATION, ///< An element that references a tile along with a one-line text.
33 SPET_GOAL, ///< An element that references a goal.
34 SPET_END,
35 INVALID_SPET = 0xFF,
38 /** Define basic enum properties */
39 template <> struct EnumPropsT<StoryPageElementType> : MakeEnumPropsT<StoryPageElementType, byte, SPET_TEXT, SPET_END, INVALID_SPET, 8> {};
40 typedef TinyEnumT<StoryPageElementType> StoryPageElementTypeByte; ///< typedefing-enumification of Direction
42 /**
43 * Struct about story page elements.
44 * Each StoryPage is composed of one or more page elements that provide
45 * page content. Each element only contain one type of content.
46 **/
47 struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
48 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.
49 StoryPageID page; ///< Id of the page which the page element belongs to
50 StoryPageElementTypeByte type; ///< Type of page element
52 uint32 referenced_id; ///< Id of referenced object (location, goal etc.)
53 char *text; ///< Static content text of page element
55 /**
56 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
58 inline StoryPageElement() { }
60 /**
61 * (Empty) destructor has to be defined else operator delete might be called with NULL parameter
63 inline ~StoryPageElement() { free(this->text); }
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)
69 /** Struct about stories, current and completed */
70 struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
71 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.
72 Date date; ///< Date when the page was created.
73 CompanyByte company; ///< StoryPage is for a specific company; INVALID_COMPANY if it is global
75 char *title; ///< Title of story page
77 /**
78 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
80 inline StoryPage() { }
82 /**
83 * (Empty) destructor has to be defined else operator delete might be called with NULL parameter
85 inline ~StoryPage()
87 if (!this->CleaningPool()) {
88 StoryPageElement *spe;
89 FOR_ALL_STORY_PAGE_ELEMENTS(spe) {
90 if (spe->page == this->index) delete spe;
93 free(this->title);
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)
100 #endif /* STORY_BASE_H */