signs_sl.cpp

Go to the documentation of this file.
00001 /* $Id: signs_sl.cpp 23636 2011-12-19 21:06:06Z truebrain $ */
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 
00018 static const SaveLoad _sign_desc[] = {
00019   SLE_CONDVAR(Sign, name,  SLE_NAME,                   0, 83),
00020   SLE_CONDSTR(Sign, name,  SLE_STR | SLF_ALLOW_CONTROL, 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_CONDVAR(Sign, z,     SLE_FILE_U8  | SLE_VAR_I32, 0, 163),
00027   SLE_CONDVAR(Sign, z,     SLE_INT32,                164, SL_MAX_VERSION),
00028   SLE_END()
00029 };
00030 
00032 static void Save_SIGN()
00033 {
00034   Sign *si;
00035 
00036   FOR_ALL_SIGNS(si) {
00037     SlSetArrayIndex(si->index);
00038     SlObject(si, _sign_desc);
00039   }
00040 }
00041 
00043 static void Load_SIGN()
00044 {
00045   int index;
00046   while ((index = SlIterateArray()) != -1) {
00047     Sign *si = new (index) Sign();
00048     SlObject(si, _sign_desc);
00049     /* Before version 6.1, signs didn't have owner.
00050      * Before version 83, invalid signs were determined by si->str == 0.
00051      * Before version 103, owner could be a bankrupted company.
00052      *  - we can't use IsValidCompany() now, so this is fixed in AfterLoadGame()
00053      * All signs that were saved are valid (including those with just 'Sign' and INVALID_OWNER).
00054      *  - so set owner to OWNER_NONE if needed (signs from pre-version 6.1 would be lost) */
00055     if (IsSavegameVersionBefore(6, 1) || (IsSavegameVersionBefore(83) && si->owner == INVALID_OWNER)) {
00056       si->owner = OWNER_NONE;
00057     }
00058   }
00059 }
00060 
00062 extern const ChunkHandler _sign_chunk_handlers[] = {
00063   { 'SIGN', Save_SIGN, Load_SIGN, NULL, NULL, CH_ARRAY | CH_LAST},
00064 };