serverstructs.cpp
1 //------------------------------------------------------------------------------
2 // serverstructs.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "serverstructs.h"
24 
25 #include <QVector>
26 
27 DClass<DMFlag>
28 {
29  public:
30  QString name;
31  unsigned value;
32 };
33 
34 DPointered(DMFlag)
35 
36 DMFlag::DMFlag()
37 {
38  d->value = 0;
39 }
40 
41 DMFlag::DMFlag(QString name, unsigned value)
42 {
43  d->name = name;
44  d->value = value;
45 }
46 
47 DMFlag::~DMFlag()
48 {
49 }
50 
51 bool DMFlag::isValid() const
52 {
53  return value() > 0;
54 }
55 
56 const QString& DMFlag::name() const
57 {
58  return d->name;
59 }
60 
61 unsigned DMFlag::value() const
62 {
63  return d->value;
64 }
65 
67 
68 DClass<DMFlagsSection>
69 {
70  public:
71  QString name;
72  QVector<DMFlag> flags;
73 };
74 
75 DPointered(DMFlagsSection)
76 
78 {
79 }
80 
81 DMFlagsSection::DMFlagsSection(const QString& name)
82 {
83  d->name = name;
84 }
85 
86 DMFlagsSection::~DMFlagsSection()
87 {
88 }
89 
90 void DMFlagsSection::add(const DMFlag& flag)
91 {
92  d->flags << flag;
93 }
94 
96 {
97  unsigned result = 0;
98  foreach (const DMFlag& flag, d->flags)
99  {
100  result |= flag.value();
101  }
102  return result;
103 }
104 
106 {
107  return d->flags.count();
108 }
109 
110 bool DMFlagsSection::isEmpty() const
111 {
112  return count() == 0;
113 }
114 
115 const QString& DMFlagsSection::name() const
116 {
117  return d->name;
118 }
119 
120 const DMFlag& DMFlagsSection::operator[](int index) const
121 {
122  return d->flags[index];
123 }
124 
126 {
127  return d->flags[index];
128 }
129 
131 
132 DClass<GameCVar>
133 {
134  public:
135  QString command;
136  QString name;
137  QVariant value;
138 };
139 
140 DPointered(GameCVar)
141 
143 {
144 }
145 
146 GameCVar::GameCVar(const QString &name, const QString &command)
147 {
148  d->name = name;
149  d->command = command;
150 }
151 
152 GameCVar::~GameCVar()
153 {
154 }
155 
156 const QString &GameCVar::command() const
157 {
158  return d->command;
159 }
160 
161 bool GameCVar::hasValue() const
162 {
163  return value().isValid();
164 }
165 
166 bool GameCVar::isValid() const
167 {
168  return !command().isEmpty();
169 }
170 
171 const QString &GameCVar::name() const
172 {
173  return d->name;
174 }
175 
176 void GameCVar::setValue(const QVariant& value)
177 {
178  d->value = value;
179 }
180 
181 const QVariant &GameCVar::value() const
182 {
183  return d->value;
184 }
185 
187 
188 DClass<GameMode>
189 {
190  public:
191  int index;
192  QString name;
193  bool teamgame;
194 };
195 
196 DPointered(GameMode)
197 
199 {
200  d->index = -1;
201  d->teamgame = false;
202 }
203 
204 GameMode::GameMode(int index, const QString &name)
205 {
206  d->index = index;
207  d->name = name;
208  d->teamgame = false;
209 }
210 
211 GameMode::~GameMode()
212 {
213 }
214 
215 GameMode GameMode::ffaGame(int index, const QString &name)
216 {
217  GameMode result(index, name);
218  result.setTeamGame(false);
219  return result;
220 }
221 
222 int GameMode::index() const
223 {
224  return d->index;
225 }
226 
227 GameMode GameMode::mkCooperative()
228 {
229  return ffaGame(SGM_Cooperative, QObject::tr("Cooperative"));
230 }
231 
232 GameMode GameMode::mkDeathmatch()
233 {
234  return ffaGame(SGM_Deathmatch, QObject::tr("Deathmatch"));
235 }
236 
237 GameMode GameMode::mkTeamDeathmatch()
238 {
239  return teamGame(SGM_TeamDeathmatch, QObject::tr("Team DM"));
240 }
241 
242 GameMode GameMode::mkCaptureTheFlag()
243 {
244  return teamGame(SGM_CTF, QObject::tr("CTF"));
245 }
246 
247 GameMode GameMode::mkUnknown()
248 {
249  return ffaGame(SGM_Unknown, QObject::tr("Unknown"));
250 }
251 
252 const QString &GameMode::name() const
253 {
254  return d->name;
255 }
256 
258 {
259  return d->teamgame;
260 }
261 
262 bool GameMode::isValid() const
263 {
264  return !d->name.isEmpty();
265 }
266 
267 void GameMode::setTeamGame(bool b)
268 {
269  d->teamgame = b;
270 }
271 
272 GameMode GameMode::teamGame(int index, const QString &name)
273 {
274  GameMode result(index, name);
275  result.setTeamGame(true);
276  return result;
277 }
278 
280 
281 DClass<PWad>
282 {
283  public:
284  QString name;
285  bool optional;
286 };
287 
288 DPointered(PWad)
289 
290 PWad::PWad(const QString &name, bool optional)
291 {
292  d->name = name;
293  d->optional = optional;
294 }
295 
296 PWad::~PWad()
297 {
298 }
299 
300 bool PWad::isOptional() const
301 {
302  return d->optional;
303 }
304 
305 const QString& PWad::name() const
306 {
307  return d->name;
308 }
309 
void add(const DMFlag &flag)
Append a new DMFlag to this section.
const QString & name() const
Nice name to display to user in Create Game dialog and in other widgets.
const QString & name() const
User-friendly name to display for game mode.
Impossible to determine the game mode.
static GameMode ffaGame(int index, const QString &name)
Construct a custom FFA game where players don't belong to any teams.
GameMode()
Constructs an invalid GameMode object.
void setValue(const QVariant &value)
Assign value() to this GameCVar.
PWAD hosted on a server.
bool isValid() const
'Null' objects are invalid.
A group of DMFlag objects that can be safely OR'ed together to form a meaningful value.
Definition: serverstructs.h:86
A game setting that is a part of a group of settings that can be OR'ed logically as a single integer...
Definition: serverstructs.h:52
const QVariant & value() const
Passed as the second argument, following command().
int count() const
Number of DMFlag objects inside the collection.
bool isTeamGame() const
Is this GameMode based on rivaling teams?
bool hasValue() const
Is any value assigned to this GameCVar.
bool isValid() const
'Null' objects are invalid.
const DMFlag & operator[](int index) const
Access DMFlag at specific index with '[]' operator.
const QString & name() const
Server's name.
Definition: server.cpp:421
Game mode representation.
unsigned combineValues() const
Logical OR of all DMFlag::value() results in this collection.
unsigned value() const
Bits that represent this flag (usually just a single '1' bit).
int index() const
Index, either a StandardGameMode or custom defined by plugin.
const QString & name() const
User-displayable name of this section, ex. "Compatibility flags".
bool isValid() const
Valid objects have value() greater than zero.
bool isOptional() const
Is this WAD required to join the server?
static GameMode teamGame(int index, const QString &name)
Game mode based on rivaling teams.
const QString & name() const
User-displayable name of the DMFlag, ex. "Jump is allowed".
A general game setting or variable (like fraglimit).
const QString & command() const
Command-line argument that sets this GameCVar.
const QString & name() const
File name of the WAD.