(svn r27770) -Fix [FS#6540]: Initialize variables in station_sl.cpp (JGR)
[openttd.git] / src / saveload / cheat_sl.cpp
blob4616b7e8527abace22a2d5e079ef22f0c9b23e08
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file cheat_sl.cpp Code handling saving and loading of cheats */
12 #include "../stdafx.h"
13 #include "../cheat_type.h"
15 #include "saveload.h"
17 #include "../safeguards.h"
19 /**
20 * Save the cheat values.
22 static void Save_CHTS()
24 /* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
25 byte count = sizeof(_cheats) / sizeof(Cheat);
26 Cheat *cht = (Cheat*) &_cheats;
27 Cheat *cht_last = &cht[count];
29 SlSetLength(count * 2);
30 for (; cht != cht_last; cht++) {
31 SlWriteByte(cht->been_used);
32 SlWriteByte(cht->value);
36 /**
37 * Load the cheat values.
39 static void Load_CHTS()
41 Cheat *cht = (Cheat*)&_cheats;
42 size_t count = SlGetFieldLength() / 2;
43 /* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
44 if (count > sizeof(_cheats) / sizeof(Cheat)) SlErrorCorrupt("Too many cheat values");
46 for (uint i = 0; i < count; i++) {
47 cht[i].been_used = (SlReadByte() != 0);
48 cht[i].value = (SlReadByte() != 0);
52 /** Chunk handlers related to cheats. */
53 extern const ChunkHandler _cheat_chunk_handlers[] = {
54 { 'CHTS', Save_CHTS, Load_CHTS, NULL, NULL, CH_RIFF | CH_LAST},