summaryrefslogtreecommitdiffstats
path: root/sigmod/Rules.cpp
blob: 3de6fe1af392b0b085bb93253e5741a08220d4c0 (plain)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
/*
 * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
 * 
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

// Header include
#include "Rules.h"

// Sigmod includes
#include "Macros.h"
#include "Sigmod.h"

const QStringList Sigmod::Rules::DVStr = QStringList() << "16" << "32";

Sigmod::Rules::Rules(const Rules& rules) :
        Object(rules.parent(), 0)
{
    *this = rules;
}

Sigmod::Rules::Rules(const Sigmod* parent) :
        Object(parent, 0),
        m_genderAllowed(false),
        m_breedingAllowed(false),
        m_criticalDomains(false),
        m_useTurns(true),
        m_pausedATB(false),
        m_numBoxes(0),
        m_boxSize(1),
        m_maxParty(1),
        m_maxFight(1),
        m_maxPlayers(2),
        m_maxHeldItems(0),
        m_maxAbilities(0),
        m_maxNatures(0),
        m_maxMoves(1),
        m_maxLevel(1),
        m_maxStages(6),
        m_maxMoney(0),
        m_maxTotalWeight(0),
        m_allowSwitchStyle(false),
        m_specialSplit(false),
        m_specialDVSplit(false),
        m_effortValuesAllowed(false),
        m_maxTotalEV(0),
        m_maxEVPerStat(0)
{
}

Sigmod::Rules::Rules(const Rules& rules, const Sigmod* parent) :
        Object(parent, 0)
{
    *this = rules;
}

Sigmod::Rules::Rules(const QDomElement& xml, const Sigmod* parent) :
        Object(parent, 0)
{
    load(xml);
}

void Sigmod::Rules::validate()
{
    TEST_BEGIN();
    TEST(setBreedingAllowed, breedingAllowed);
    TEST(setNumBoxes, numBoxes);
    TEST(setBoxSize, boxSize);
    TEST(setMaxParty, maxParty);
    TEST(setMaxFight, maxFight);
    TEST(setMaxPlayers, maxPlayers);
    TEST(setMaxMoves, maxMoves);
    TEST(setMaxLevel, maxLevel);
    TEST(setMaxStages, maxStages);
    if (!m_maxMoney)
        emit(warning("Player cannot carry any money"));
    else
        TEST(setMaxMoney, maxMoney);
    TEST(setMaxTotalWeight, maxTotalWeight);
    if (m_effortValuesAllowed)
    {
        TEST(setMaxEVPerStat, maxEVPerStat);
    }
    TEST_END();
}

void Sigmod::Rules::load(const QDomElement& xml)
{
    LOAD_BEGIN();
    LOAD(genderAllowed);
    LOAD(breedingAllowed);
    LOAD(criticalDomains);
    LOAD(useTurns);
    LOAD(pausedATB);
    LOAD(numBoxes);
    LOAD(boxSize);
    LOAD(maxParty);
    LOAD(maxFight);
    LOAD(maxPlayers);
    LOAD(maxHeldItems);
    LOAD(maxAbilities);
    LOAD(maxNatures);
    LOAD(maxMoves);
    LOAD(maxLevel);
    LOAD(maxStages);
    LOAD(maxMoney);
    LOAD(maxTotalWeight);
    LOAD(allowSwitchStyle);
    LOAD(specialSplit);
    LOAD(specialDVSplit);
    LOAD(effortValuesAllowed);
    LOAD(maxTotalEV);
    LOAD(maxEVPerStat);
}

QDomElement Sigmod::Rules::save() const
{
    QDomElement xml = QDomDocument().createElement(className());
    SAVE(genderAllowed);
    SAVE(breedingAllowed);
    SAVE(criticalDomains);
    SAVE(useTurns);
    SAVE(pausedATB);
    SAVE(numBoxes);
    SAVE(boxSize);
    SAVE(maxParty);
    SAVE(maxFight);
    SAVE(maxPlayers);
    SAVE(maxHeldItems);
    SAVE(maxAbilities);
    SAVE(maxNatures);
    SAVE(maxMoves);
    SAVE(maxLevel);
    SAVE(maxStages);
    SAVE(maxMoney);
    SAVE(maxTotalWeight);
    SAVE(allowSwitchStyle);
    SAVE(specialSplit);
    SAVE(specialDVSplit);
    SAVE(effortValuesAllowed);
    SAVE(maxTotalEV);
    SAVE(maxEVPerStat);
    return xml;
}

void Sigmod::Rules::setGenderAllowed(const bool genderAllowed)
{
    CHECK(genderAllowed);
}

void Sigmod::Rules::setBreedingAllowed(const bool breedingAllowed)
{
    if (!m_genderAllowed && breedingAllowed)
        emit(error(bounds("breedingAllowed", breedingAllowed)));
    else
        CHECK(breedingAllowed);
}

void Sigmod::Rules::setCriticalDomains(const bool criticalDomains)
{
    CHECK(criticalDomains);
}

void Sigmod::Rules::setUseTurns(const bool useTurns)
{
    CHECK(useTurns);
}

void Sigmod::Rules::setPausedATB(const bool pausedATB)
{
    if (m_useTurns && pausedATB)
        emit(error(bounds("pausedATB", pausedATB)));
    else
        CHECK(pausedATB);
}

void Sigmod::Rules::setNumBoxes(const int numBoxes)
{
    CHECK(numBoxes);
}

void Sigmod::Rules::setBoxSize(const int boxSize)
{
    if (m_numBoxes && (boxSize <= 0))
        emit(error(bounds("boxSize", 1, INT_MAX, boxSize)));
    else
        CHECK(boxSize);
}

void Sigmod::Rules::setMaxParty(const int maxParty)
{
    if (maxParty <= 0)
        emit(error(bounds("maxParty", 1, INT_MAX, maxParty)));
    else
        CHECK(maxParty);
}

void Sigmod::Rules::setMaxFight(const int maxFight)
{
    if ((maxFight <= 0) || (m_maxParty < maxFight))
        emit(error(bounds("maxFight", 1, m_maxParty, maxFight)));
    else
        CHECK(maxFight);
}

void Sigmod::Rules::setMaxPlayers(const int maxPlayers)
{
    if (maxPlayers < 2)
        emit(error(bounds("maxPlayers", 2, INT_MAX, maxPlayers)));
    else
        CHECK(maxPlayers);
}

void Sigmod::Rules::setMaxHeldItems(const int maxHeldItems)
{
    CHECK(maxHeldItems);
}

void Sigmod::Rules::setMaxAbilities(const int maxAbilities)
{
    CHECK(maxAbilities);
}

void Sigmod::Rules::setMaxNatures(const int maxNatures)
{
    CHECK(maxNatures);
}

void Sigmod::Rules::setMaxMoves(const int maxMoves)
{
    if (maxMoves <= 0)
        emit(error(bounds("maxMoves", 1, INT_MAX, maxMoves)));
    else
        CHECK(maxMoves);
}

void Sigmod::Rules::setMaxLevel(const int maxLevel)
{
    if (maxLevel <= 0)
        emit(error(bounds("maxLevel", 1, INT_MAX, maxLevel)));
    else
        CHECK(maxLevel);
}

void Sigmod::Rules::setMaxStages(const int maxStages)
{
    if (maxStages < 0)
        emit(error(bounds("maxStages", 0, INT_MAX, maxStages)));
    else
        CHECK(maxStages);
}

void Sigmod::Rules::setMaxMoney(const int maxMoney)
{
    if (maxMoney < 0)
        emit(error(bounds("maxMoney", 0, INT_MAX, maxMoney)));
    else
        CHECK(maxMoney);
}

void Sigmod::Rules::setMaxTotalWeight(const int maxTotalWeight)
{
    if (maxTotalWeight < -1)
        emit(error(bounds("maxTotalWeight", -1, INT_MAX, maxTotalWeight)));
    else
        CHECK(maxTotalWeight);
}

void Sigmod::Rules::setAllowSwitchStyle(const bool allowSwitchStyle)
{
    CHECK(allowSwitchStyle);
}

void Sigmod::Rules::setSpecialSplit(const bool specialSplit)
{
    CHECK(specialSplit);
}

void Sigmod::Rules::setSpecialDVSplit(const bool specialDVSplit)
{
    if (!specialDVSplit && m_specialSplit)
        emit(error(bounds("specialDVSplit", specialDVSplit)));
    else
        CHECK(specialDVSplit);
}

void Sigmod::Rules::setEffortValuesAllowed(const bool effortValuesAllowed)
{
    CHECK(effortValuesAllowed);
}

void Sigmod::Rules::setMaxTotalEV(const int maxTotalEV)
{
    if (maxTotalEV <= 0)
        emit(error(bounds("maxTotalEV", maxTotalEV)));
    else
        CHECK(maxTotalEV);
}

void Sigmod::Rules::setMaxEVPerStat(const int maxEVPerStat)
{
    if ((m_maxTotalEV && (maxEVPerStat <= 0)) || (m_maxTotalEV < maxEVPerStat))
        emit(error(bounds("maxEVPerStat", 1, m_maxTotalEV, maxEVPerStat)));
    else
        CHECK(maxEVPerStat);
}

bool Sigmod::Rules::genderAllowed() const
{
    return m_genderAllowed;
}

bool Sigmod::Rules::breedingAllowed() const
{
    return m_breedingAllowed;
}

bool Sigmod::Rules::criticalDomains() const
{
    return m_criticalDomains;
}

bool Sigmod::Rules::useTurns() const
{
    return m_useTurns;
}

bool Sigmod::Rules::pausedATB() const
{
    return m_pausedATB;
}

int Sigmod::Rules::numBoxes() const
{
    return m_numBoxes;
}

int Sigmod::Rules::boxSize() const
{
    return m_boxSize;
}

int Sigmod::Rules::maxParty() const
{
    return m_maxParty;
}

int Sigmod::Rules::maxFight() const
{
    return m_maxFight;
}

int Sigmod::Rules::maxPlayers() const
{
    return m_maxPlayers;
}

int Sigmod::Rules::maxHeldItems() const
{
    return m_maxHeldItems;
}

int Sigmod::Rules::maxAbilities() const
{
    return m_maxAbilities;
}

int Sigmod::Rules::maxNatures() const
{
    return m_maxNatures;
}

int Sigmod::Rules::maxMoves() const
{
    return m_maxMoves;
}

int Sigmod::Rules::maxLevel() const
{
    return m_maxLevel;
}

int Sigmod::Rules::maxStages() const
{
    return m_maxStages;
}

int Sigmod::Rules::maxMoney() const
{
    return m_maxMoney;
}

int Sigmod::Rules::maxTotalWeight() const
{
    return m_maxTotalWeight;
}

bool Sigmod::Rules::allowSwitchStyle() const
{
    return m_allowSwitchStyle;
}

bool Sigmod::Rules::specialSplit() const
{
    return m_specialSplit;
}

bool Sigmod::Rules::specialDVSplit() const
{
    return m_specialDVSplit;
}

bool Sigmod::Rules::effortValuesAllowed() const
{
    return m_effortValuesAllowed;
}

int Sigmod::Rules::maxTotalEV() const
{
    return m_maxTotalEV;
}

int Sigmod::Rules::maxEVPerStat() const
{
    return m_maxEVPerStat;
}

Sigmod::Rules& Sigmod::Rules::operator=(const Rules& rhs)
{
    if (this == &rhs)
        return *this;
    COPY(genderAllowed);
    COPY(breedingAllowed);
    COPY(criticalDomains);
    COPY(useTurns);
    COPY(pausedATB);
    COPY(numBoxes);
    COPY(boxSize);
    COPY(maxParty);
    COPY(maxFight);
    COPY(maxPlayers);
    COPY(maxHeldItems);
    COPY(maxAbilities);
    COPY(maxNatures);
    COPY(maxMoves);
    COPY(maxLevel);
    COPY(maxStages);
    COPY(maxMoney);
    COPY(maxTotalWeight);
    COPY(allowSwitchStyle);
    COPY(specialSplit);
    COPY(specialDVSplit);
    COPY(effortValuesAllowed);
    COPY(maxTotalEV);
    COPY(maxEVPerStat);
    return *this;
}