# signs_sl.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    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 #include "../fios.h"
    00015
    00016 #include "saveload.h"
    00017
    00019 static const SaveLoad _sign_desc[] = {
    00020   SLE_CONDVAR(Sign, name,  SLE_NAME,                   0, 83),
    00021   SLE_CONDSTR(Sign, name,  SLE_STR | SLF_ALLOW_CONTROL, 0, 84, SL_MAX_VERSION),
    00022   SLE_CONDVAR(Sign, x,     SLE_FILE_I16 | SLE_VAR_I32, 0, 4),
    00023   SLE_CONDVAR(Sign, y,     SLE_FILE_I16 | SLE_VAR_I32, 0, 4),
    00024   SLE_CONDVAR(Sign, x,     SLE_INT32,                  5, SL_MAX_VERSION),
    00025   SLE_CONDVAR(Sign, y,     SLE_INT32,                  5, SL_MAX_VERSION),
    00026   SLE_CONDVAR(Sign, owner, SLE_UINT8,                  6, SL_MAX_VERSION),
    00027   SLE_CONDVAR(Sign, z,     SLE_FILE_U8  | SLE_VAR_I32, 0, 163),
    00028   SLE_CONDVAR(Sign, z,     SLE_INT32,                164, SL_MAX_VERSION),
    00029   SLE_END()
    00030 };
    00031
    00033 static void Save_SIGN()
    00034 {
    00035   Sign *si;
    00036
    00037   FOR_ALL_SIGNS(si) {
    00038     SlSetArrayIndex(si->index);
    00039     SlObject(si, _sign_desc);
    00040   }
    00041 }
    00042
    00044 static void Load_SIGN()
    00045 {
    00046   int index;
    00047   while ((index = SlIterateArray()) != -1) {
    00048     Sign *si = new (index) Sign();
    00049     SlObject(si, _sign_desc);
    00050     /* Before version 6.1, signs didn't have owner.
    00051      * Before version 83, invalid signs were determined by si->str == 0.
    00052      * Before version 103, owner could be a bankrupted company.
    00053      *  - we can't use IsValidCompany() now, so this is fixed in AfterLoadGame()
    00054      * All signs that were saved are valid (including those with just 'Sign' and INVALID_OWNER).
    00055      *  - so set owner to OWNER_NONE if needed (signs from pre-version 6.1 would be lost) */
    00056     if (IsSavegameVersionBefore(6, 1) || (IsSavegameVersionBefore(83) && si->owner == INVALID_OWNER)) {
    00057       si->owner = OWNER_NONE;
    00058     }
    00059
    00060     /* Signs placed in scenario editor shall now be OWNER_DEITY */
    00061     if (IsSavegameVersionBefore(171) && si->owner == OWNER_NONE && _saveload_mode == SLD_LOAD_SCENARIO) {
    00062       si->owner = OWNER_DEITY;
    00063     }
    00064   }
    00065 }
    00066
    00068 extern const ChunkHandler _sign_chunk_handlers[] = {
    00069   { 'SIGN', Save_SIGN, Load_SIGN, NULL, NULL, CH_ARRAY | CH_LAST},
    00070 };