signs_sl.cpp

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

Generated on Wed Feb 17 23:06:51 2010 for OpenTTD by  doxygen 1.6.1