cheat_sl.cpp

Go to the documentation of this file.
00001 /* $Id: cheat_sl.cpp 22737 2011-08-12 18:36:47Z 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 "../cheat_type.h"
00014 
00015 #include "saveload.h"
00016 
00020 static void Save_CHTS()
00021 {
00022   /* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
00023   byte count = sizeof(_cheats) / sizeof(Cheat);
00024   Cheat *cht = (Cheat*) &_cheats;
00025   Cheat *cht_last = &cht[count];
00026 
00027   SlSetLength(count * 2);
00028   for (; cht != cht_last; cht++) {
00029     SlWriteByte(cht->been_used);
00030     SlWriteByte(cht->value);
00031   }
00032 }
00033 
00037 static void Load_CHTS()
00038 {
00039   Cheat *cht = (Cheat*)&_cheats;
00040   size_t count = SlGetFieldLength() / 2;
00041   /* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
00042   if (count > sizeof(_cheats) / sizeof(Cheat)) SlErrorCorrupt("Too many cheat values");
00043 
00044   for (uint i = 0; i < count; i++) {
00045     cht[i].been_used = (SlReadByte() != 0);
00046     cht[i].value     = (SlReadByte() != 0);
00047   }
00048 }
00049 
00051 extern const ChunkHandler _cheat_chunk_handlers[] = {
00052   { 'CHTS', Save_CHTS, Load_CHTS, NULL, NULL, CH_RIFF | CH_LAST},
00053 };