/
gamerules.cpp
150 lines (134 loc) · 3.7 KB
/
gamerules.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/** @file gamerules.cpp Game rule set.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program 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; either version 2 of the License, or (at your
* option) any later version. This program 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. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#include "common.h"
#include "gamerules.h"
GameRuleset::GameRuleset()
: skill(skillmode_t(0))
#if !__JHEXEN__
, fast(0)
#endif
, deathmatch(0)
, noMonsters(0)
#if __JHEXEN__
, randomClasses(0)
#else
, respawnMonsters(0)
#endif
{}
GameRuleset::GameRuleset(GameRuleset const &other)
: skill (other.skill)
#if !__JHEXEN__
, fast (other.fast)
#endif
, deathmatch (other.deathmatch)
, noMonsters (other.noMonsters)
#if __JHEXEN__
, randomClasses (other.randomClasses)
#else
, respawnMonsters(other.respawnMonsters)
#endif
{}
GameRuleset &GameRuleset::operator = (GameRuleset const &other)
{
skill = other.skill;
#if !__JHEXEN__
fast = other.fast;
#endif
deathmatch = other.deathmatch;
noMonsters = other.noMonsters;
#if __JHEXEN__
randomClasses = other.randomClasses;
#else
respawnMonsters = other.respawnMonsters;
#endif
return *this;
}
void GameRuleset::write(Writer *writer) const
{
DENG2_ASSERT(writer != 0);
Writer_WriteByte(writer, skill);
Writer_WriteByte(writer, deathmatch);
#if !__JHEXEN__
Writer_WriteByte(writer, fast);
#endif
Writer_WriteByte(writer, noMonsters);
#if __JHEXEN__
Writer_WriteByte(writer, randomClasses);
#else
Writer_WriteByte(writer, respawnMonsters);
#endif
}
void GameRuleset::read(Reader *reader)
{
DENG2_ASSERT(reader != 0);
skill = (skillmode_t) Reader_ReadByte(reader);
// Interpret skill modes outside the normal range as "spawn no things".
if(skill < SM_BABY || skill >= NUM_SKILL_MODES)
{
skill = SM_NOTHINGS;
}
deathmatch = Reader_ReadByte(reader);
#if !__JHEXEN__
fast = Reader_ReadByte(reader);
#endif
noMonsters = Reader_ReadByte(reader);
#if __JHEXEN__
randomClasses = Reader_ReadByte(reader);
#else
respawnMonsters = Reader_ReadByte(reader);
#endif
}
// C wrapper API ---------------------------------------------------------------
skillmode_t GameRuleset_Skill(GameRuleset const *rules)
{
DENG2_ASSERT(rules != 0);
return rules->skill;
}
#if !__JHEXEN__
byte GameRuleset_Fast(GameRuleset const *rules)
{
DENG2_ASSERT(rules != 0);
return rules->fast;
}
#endif
byte GameRuleset_Deathmatch(GameRuleset const *rules)
{
DENG2_ASSERT(rules != 0);
return rules->deathmatch;
}
byte GameRuleset_NoMonsters(GameRuleset const *rules)
{
DENG2_ASSERT(rules != 0);
return rules->noMonsters;
}
#if __JHEXEN__
byte GameRuleset_RandomClasses(GameRuleset const *rules)
{
DENG2_ASSERT(rules != 0);
return rules->randomClasses;
}
#endif
#if !__JHEXEN__
byte GameRuleset_RespawnMonsters(GameRuleset const *rules)
{
DENG2_ASSERT(rules != 0);
return rules->respawnMonsters;
}
#endif