# story_base.h

Go to the documentation of this file.

    00001 /* $Id: story_base.h 25621 2013-07-21 15:21:55Z zuu $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef STORY_BASE_H
    00013 #define STORY_BASE_H
    00014
    00015 #include "company_type.h"
    00016 #include "story_type.h"
    00017 #include "date_type.h"
    00018 #include "core/pool_type.hpp"
    00019
    00020 typedef Pool<StoryPageElement, StoryPageElementID, 64, 64000> StoryPageElementPool;
    00021 typedef Pool<StoryPage, StoryPageID, 64, 64000> StoryPagePool;
    00022 extern StoryPageElementPool _story_page_element_pool;
    00023 extern StoryPagePool _story_page_pool;
    00024 extern uint32 _story_page_element_next_sort_value;
    00025 extern uint32 _story_page_next_sort_value;
    00026
    00027 /*
    00028  * Each story page element is one of these types.
    00029  */
    00030 enum StoryPageElementType {
    00031   SPET_TEXT = 0,
    00032   SPET_LOCATION,
    00033   SPET_GOAL,
    00034   SPET_END,
    00035   INVALID_SPET = 0xFF,
    00036 };
    00037
    00039 template <> struct EnumPropsT<StoryPageElementType> : MakeEnumPropsT<StoryPageElementType, byte, SPET_TEXT, SPET_END, INVALID_SPET, 8> {};
    00040 typedef TinyEnumT<StoryPageElementType> StoryPageElementTypeByte;
    00041
    00047 struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
    00048   uint32 sort_value;
    00049   StoryPageID page;
    00050   StoryPageElementTypeByte type;
    00051
    00052   uint32 referenced_id;
    00053   char *text;
    00054
    00058   inline StoryPageElement() { }
    00059
    00063   inline ~StoryPageElement() { free(this->text); }
    00064 };
    00065
    00066 #define FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPageElement, story_page_element_index, var, start)
    00067 #define FOR_ALL_STORY_PAGE_ELEMENTS(var) FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, 0)
    00068
    00070 struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
    00071   uint32 sort_value;
    00072   Date date;
    00073   CompanyByte company;
    00074
    00075   char *title;
    00076
    00080   inline StoryPage() { }
    00081
    00085   inline ~StoryPage()
    00086   {
    00087     if (!this->CleaningPool()) {
    00088       StoryPageElement *spe;
    00089       FOR_ALL_STORY_PAGE_ELEMENTS(spe) {
    00090         if (spe->page == this->index) delete spe;
    00091       }
    00092     }
    00093     free(this->title);
    00094   }
    00095 };
    00096
    00097 #define FOR_ALL_STORY_PAGES_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPage, story_page_index, var, start)
    00098 #define FOR_ALL_STORY_PAGES(var) FOR_ALL_STORY_PAGES_FROM(var, 0)
    00099
    00100 #endif /* STORY_BASE_H */
    00101