author | truebrain |
Fri, 13 Jun 2008 19:57:25 +0000 | |
branch | noai |
changeset 10957 | 7a140b4cd91d |
parent 10776 | 07203fc29812 |
permissions | -rw-r--r-- |
10249 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10249
diff
changeset
|
3 |
/** @file cheat.cpp Handling (loading/saving/initializing) of cheats. */ |
10249 | 4 |
|
5 |
#include "stdafx.h" |
|
6 |
#include "saveload.h" |
|
7 |
#include "cheat_type.h" |
|
8 |
||
9 |
Cheats _cheats; |
|
10 |
||
11 |
void InitializeCheats() |
|
12 |
{ |
|
13 |
memset(&_cheats, 0, sizeof(Cheats)); |
|
14 |
} |
|
15 |
||
16 |
static void Save_CHTS() |
|
17 |
{ |
|
18 |
/* Cannot use lengthof because _cheats is of type Cheats, not Cheat */ |
|
19 |
byte count = sizeof(_cheats) / sizeof(Cheat); |
|
20 |
Cheat *cht = (Cheat*) &_cheats; |
|
21 |
Cheat *cht_last = &cht[count]; |
|
22 |
||
23 |
SlSetLength(count * 2); |
|
24 |
for (; cht != cht_last; cht++) { |
|
25 |
SlWriteByte(cht->been_used); |
|
26 |
SlWriteByte(cht->value); |
|
27 |
} |
|
28 |
} |
|
29 |
||
30 |
static void Load_CHTS() |
|
31 |
{ |
|
32 |
Cheat *cht = (Cheat*)&_cheats; |
|
10776 | 33 |
size_t count = SlGetFieldLength() / 2; |
10249 | 34 |
|
35 |
for (uint i = 0; i < count; i++) { |
|
36 |
cht[i].been_used = (SlReadByte() != 0); |
|
37 |
cht[i].value = (SlReadByte() != 0); |
|
38 |
} |
|
39 |
} |
|
40 |
||
41 |
bool CheatHasBeenUsed() |
|
42 |
{ |
|
43 |
/* Cannot use lengthof because _cheats is of type Cheats, not Cheat */ |
|
44 |
const Cheat* cht = (Cheat*)&_cheats; |
|
45 |
const Cheat* cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)]; |
|
46 |
||
47 |
for (; cht != cht_last; cht++) { |
|
48 |
if (cht->been_used) return true; |
|
49 |
} |
|
50 |
||
51 |
return false; |
|
52 |
} |
|
53 |
||
54 |
||
55 |
extern const ChunkHandler _cheat_chunk_handlers[] = { |
|
56 |
{ 'CHTS', Save_CHTS, Load_CHTS, CH_RIFF | CH_LAST} |
|
57 |
}; |