src/cheat.cpp
author rubidium
Fri, 04 Jul 2008 19:00:11 +0000
changeset 11118 f66e0a4ce878
parent 10751 ebd94f2d6385
permissions -rw-r--r--
(svn r13676) -Fix [FS#2126]: inactive companies from old (TTD) saves could be marked active in some cases, which then loads garbage in their statistics and such.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10225
diff changeset
     3
/** @file cheat.cpp Handling (loading/saving/initializing) of cheats. */
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6417
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "saveload.h"
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
     7
#include "cheat_type.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
     9
Cheats _cheats;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    11
void InitializeCheats()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
{
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 179
diff changeset
    13
	memset(&_cheats, 0, sizeof(Cheats));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
    16
static void Save_CHTS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
{
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    18
	/* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    19
	byte count = sizeof(_cheats) / sizeof(Cheat);
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    20
	Cheat *cht = (Cheat*) &_cheats;
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    21
	Cheat *cht_last = &cht[count];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2861
diff changeset
    23
	SlSetLength(count * 2);
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2861
diff changeset
    24
	for (; cht != cht_last; cht++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
		SlWriteByte(cht->been_used);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
		SlWriteByte(cht->value);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
    30
static void Load_CHTS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
{
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    32
	Cheat *cht = (Cheat*)&_cheats;
10751
ebd94f2d6385 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 10429
diff changeset
    33
	size_t count = SlGetFieldLength() / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
9315
336e6518acb3 (svn r12565) -Cleanup: variable scope in misc\*.cpp
smatz
parents: 9282
diff changeset
    35
	for (uint i = 0; i < count; i++) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    36
		cht[i].been_used = (SlReadByte() != 0);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    37
		cht[i].value     = (SlReadByte() != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    41
bool CheatHasBeenUsed()
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    42
{
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    43
	/* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    44
	const Cheat* cht = (Cheat*)&_cheats;
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    45
	const Cheat* cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    47
	for (; cht != cht_last; cht++) {
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    48
		if (cht->been_used) return true;
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    49
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    51
	return false;
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    52
}
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    53
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    54
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10164
diff changeset
    55
extern const ChunkHandler _cheat_chunk_handlers[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    56
	{ 'CHTS', Save_CHTS,     Load_CHTS,     CH_RIFF | CH_LAST}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
};