OpenTTD: src/saveload/cheat_sl.cpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

cheat_sl.cpp
Go to the documentation of this file.
1 /* $Id: cheat_sl.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2
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 */
9
12 #include "../stdafx.h"
13 #include "../cheat_type.h"
14
15 #include "saveload.h"
16
17 #include "../safeguards.h"
18
22 static void Save_CHTS()
23 {
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];
28
29 SlSetLength(count * 2);
30 for (; cht != cht_last; cht++) {
31 SlWriteByte(cht->been_used);
32 SlWriteByte(cht->value);
33 }
34 }
35
39 static void Load_CHTS()
40 {
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");
45
46 for (uint i = 0; i < count; i++) {
47 cht[i].been_used = (SlReadByte() != 0);
48 cht[i].value = (SlReadByte() != 0);
49 }
50 }
51
53 extern const ChunkHandler _cheat_chunk_handlers[] = {
54 { 'CHTS', Save_CHTS, Load_CHTS, NULL, NULL, CH_RIFF | CH_LAST},
55 };