signs_sl.cpp

Go to the documentation of this file.
00001 /* $Id: signs_sl.cpp 17248 2009-08-21 20:21:05Z rubidium $ */
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 "../company_func.h"
00014 #include "../signs_base.h"
00015 
00016 #include "saveload.h"
00017 
00018 static const SaveLoad _sign_desc[] = {
00019   SLE_CONDVAR(Sign, name,  SLE_NAME,                   0, 83),
00020   SLE_CONDSTR(Sign, name,  SLE_STR, 0,                84, SL_MAX_VERSION),
00021   SLE_CONDVAR(Sign, x,     SLE_FILE_I16 | SLE_VAR_I32, 0, 4),
00022   SLE_CONDVAR(Sign, y,     SLE_FILE_I16 | SLE_VAR_I32, 0, 4),
00023   SLE_CONDVAR(Sign, x,     SLE_INT32,                  5, SL_MAX_VERSION),
00024   SLE_CONDVAR(Sign, y,     SLE_INT32,                  5, SL_MAX_VERSION),
00025   SLE_CONDVAR(Sign, owner, SLE_UINT8,                  6, SL_MAX_VERSION),
00026       SLE_VAR(Sign, z,     SLE_UINT8),
00027   SLE_END()
00028 };
00029 
00031 static void Save_SIGN()
00032 {
00033   Sign *si;
00034 
00035   FOR_ALL_SIGNS(si) {
00036     SlSetArrayIndex(si->index);
00037     SlObject(si, _sign_desc);
00038   }
00039 }
00040 
00042 static void Load_SIGN()
00043 {
00044   int index;
00045   while ((index = SlIterateArray()) != -1) {
00046     Sign *si = new (index) Sign();
00047     SlObject(si, _sign_desc);
00048     /* Before version 6.1, signs didn't have owner.
00049      * Before version 83, invalid signs were determined by si->str == 0.
00050      * Before version 103, owner could be a bankrupted company.
00051      *  - we can't use IsValidCompany() now, so this is fixed in AfterLoadGame()
00052      * All signs that were saved are valid (including those with just 'Sign' and INVALID_OWNER).
00053      *  - so set owner to OWNER_NONE if needed (signs from pre-version 6.1 would be lost) */
00054     if (CheckSavegameVersionOldStyle(6, 1) || (CheckSavegameVersion(83) && si->owner == INVALID_OWNER)) {
00055       si->owner = OWNER_NONE;
00056     }
00057   }
00058 }
00059 
00060 extern const ChunkHandler _sign_chunk_handlers[] = {
00061   { 'SIGN', Save_SIGN, Load_SIGN, NULL, CH_ARRAY | CH_LAST},
00062 };

Generated on Tue Jan 5 21:02:58 2010 for OpenTTD by  doxygen 1.5.6