# story_sl.cpp

Go to the documentation of this file.

    00001 /* $Id: story_sl.cpp 25620 2013-07-21 13:18:45Z 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 #include "../stdafx.h"
    00013 #include "../story_base.h"
    00014
    00015 #include "saveload.h"
    00016
    00018 void AfterLoadStoryBook()
    00019 {
    00020   if (IsSavegameVersionBefore(185)) {
    00021     /* Trash all story pages and page elements because
    00022      * they were saved with wrong data types.
    00023      */
    00024     _story_page_element_pool.CleanPool();
    00025     _story_page_pool.CleanPool();
    00026   }
    00027 }
    00028
    00029 static const SaveLoad _story_page_elements_desc[] = {
    00030   SLE_CONDVAR(StoryPageElement, sort_value,    SLE_FILE_U16 | SLE_VAR_U32, 0,   184),
    00031   SLE_CONDVAR(StoryPageElement, sort_value,    SLE_UINT32,                 185, SL_MAX_VERSION),
    00032       SLE_VAR(StoryPageElement, page,          SLE_UINT16),
    00033   SLE_CONDVAR(StoryPageElement, type,          SLE_FILE_U16 | SLE_VAR_U8,  0,   184),
    00034   SLE_CONDVAR(StoryPageElement, type,          SLE_UINT8,                  185, SL_MAX_VERSION),
    00035       SLE_VAR(StoryPageElement, referenced_id, SLE_UINT32),
    00036       SLE_STR(StoryPageElement, text,          SLE_STR | SLF_ALLOW_CONTROL, 0),
    00037       SLE_END()
    00038 };
    00039
    00040 static void Save_STORY_PAGE_ELEMENT()
    00041 {
    00042   StoryPageElement *s;
    00043   FOR_ALL_STORY_PAGE_ELEMENTS(s) {
    00044     SlSetArrayIndex(s->index);
    00045     SlObject(s, _story_page_elements_desc);
    00046   }
    00047 }
    00048
    00049 static void Load_STORY_PAGE_ELEMENT()
    00050 {
    00051   int index;
    00052   uint32 max_sort_value = 0;
    00053   while ((index = SlIterateArray()) != -1) {
    00054     StoryPageElement *s = new (index) StoryPageElement();
    00055     SlObject(s, _story_page_elements_desc);
    00056     if (s->sort_value > max_sort_value) {
    00057       max_sort_value = s->sort_value;
    00058     }
    00059   }
    00060   /* Update the next sort value, so that the next
    00061    * created page is shown after all existing pages.
    00062    */
    00063   _story_page_element_next_sort_value = max_sort_value + 1;
    00064 }
    00065
    00066 static const SaveLoad _story_pages_desc[] = {
    00067   SLE_CONDVAR(StoryPage, sort_value, SLE_FILE_U16 | SLE_VAR_U32, 0,   184),
    00068   SLE_CONDVAR(StoryPage, sort_value, SLE_UINT32,                 185, SL_MAX_VERSION),
    00069       SLE_VAR(StoryPage, date,       SLE_UINT32),
    00070   SLE_CONDVAR(StoryPage, company,    SLE_FILE_U16 | SLE_VAR_U8,  0,   184),
    00071   SLE_CONDVAR(StoryPage, company,    SLE_UINT8,                  185, SL_MAX_VERSION),
    00072       SLE_STR(StoryPage, title,      SLE_STR | SLF_ALLOW_CONTROL, 0),
    00073       SLE_END()
    00074 };
    00075
    00076 static void Save_STORY_PAGE()
    00077 {
    00078   StoryPage *s;
    00079   FOR_ALL_STORY_PAGES(s) {
    00080     SlSetArrayIndex(s->index);
    00081     SlObject(s, _story_pages_desc);
    00082   }
    00083 }
    00084
    00085 static void Load_STORY_PAGE()
    00086 {
    00087   int index;
    00088   uint32 max_sort_value = 0;
    00089   while ((index = SlIterateArray()) != -1) {
    00090     StoryPage *s = new (index) StoryPage();
    00091     SlObject(s, _story_pages_desc);
    00092     if (s->sort_value > max_sort_value) {
    00093       max_sort_value = s->sort_value;
    00094     }
    00095   }
    00096   /* Update the next sort value, so that the next
    00097    * created page is shown after all existing pages.
    00098    */
    00099   _story_page_next_sort_value = max_sort_value + 1;
    00100 }
    00101
    00102 extern const ChunkHandler _story_page_chunk_handlers[] = {
    00103   { 'STPE', Save_STORY_PAGE_ELEMENT, Load_STORY_PAGE_ELEMENT, NULL, NULL, CH_ARRAY},
    00104   { 'STPA', Save_STORY_PAGE, Load_STORY_PAGE, NULL, NULL, CH_ARRAY | CH_LAST},
    00105 };