summaryrefslogtreecommitdiffstats
path: root/pokemod/Rules.cpp
blob: dfc940c9c9ea24070cefc1a3fb0ae1e51e8e5311 (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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
/*
 * 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/>.
 */

// Pokemod includes
#include "Pokemod.h"

// Header include
#include "Rules.h"

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

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

Rules::Rules(const Pokemod* pokemod) :
        Object("Rules", pokemod, 0),
        m_genderAllowed(false),
        m_breedingAllowed(false),
        m_holdItems(0),
        m_criticalDomains(false),
        m_abilityAllowed(false),
        m_natureAllowed(false),
        m_numBoxes(0),
        m_boxSize(1),
        m_maxParty(1),
        m_maxFight(1),
        m_maxPlayers(2),
        m_maxMoves(1),
        m_maxLevel(1),
        m_maxMoney(0),
        m_hardCash(false),
        m_specialSplit(false),
        m_specialDVSplit(false),
        m_maxDVValue(0),
        m_happiness(false),
        m_happyFaintLoss(0),
        m_happyLevelGain(0),
        m_happySteps(0),
        m_effortValuesAllowed(false),
        m_maxTotalEV(0),
        m_maxEVPerStat(0),
        m_pokerusChance(1, 1)
{
}

Rules::Rules(const Rules& rules, const Pokemod* pokemod) :
        Object("Rules", pokemod, 0)
{
    *this = rules;
}

Rules::Rules(const QDomElement& xml, const Pokemod* pokemod) :
        Object("Rules", pokemod, 0)
{
    load(xml);
}

bool Rules::validate() const
{
    bool valid = true;
    pokemod()->validationMsg("---Rules", Pokemod::V_Msg);
    if (!m_numBoxes)
        pokemod()->validationMsg("No box storage", Pokemod::V_Warn);
    else if (!m_boxSize)
    {
        pokemod()->validationMsg("Invalid box size");
        valid = false;
    }
    if (!m_maxParty)
    {
        pokemod()->validationMsg("Invalid party size");
        valid = false;
    }
    if (!m_maxParty || (m_maxParty < m_maxFight))
    {
        pokemod()->validationMsg("Larger active than party");
        valid = false;
    }
    if (m_maxPlayers < 2)
    {
        pokemod()->validationMsg("Cannot have battles without at least two players");
        valid = false;
    }
    if (!m_maxMoves)
    {
        pokemod()->validationMsg("No moves can be learned");
        valid = false;
    }
    if (!m_maxMoney)
        pokemod()->validationMsg("Player cannot carry any money", Pokemod::V_Warn);
    if (1 < m_maxDVValue)
    {
        pokemod()->validationMsg("Invalid maximum DV value");
        valid = false;
    }
    if (m_effortValuesAllowed)
    {
        if (m_maxTotalEV < m_maxEVPerStat)
        {
            pokemod()->validationMsg("More EV points are allowed on a stat than allowed overall");
            valid = false;
        }
    }
    if (.005 < m_pokerusChance)
        pokemod()->validationMsg("Pokérus chance is unusually high", Pokemod::V_Warn);
    return valid;
}

void Rules::load(const QDomElement& xml, const int) throw(Exception)
{
    clear();
    LOAD(bool, genderAllowed);
    LOAD(bool, breedingAllowed);
    LOAD(int, holdItems);
    LOAD(bool, criticalDomains);
    LOAD(bool, abilityAllowed);
    LOAD(bool, natureAllowed);
    LOAD(int, numBoxes);
    LOAD(int, boxSize);
    LOAD(int, maxParty);
    LOAD(int, maxFight);
    LOAD(int, maxPlayers);
    LOAD(int, maxMoves);
    LOAD(int, maxLevel);
    LOAD(int, maxMoney);
    LOAD(bool, hardCash);
    LOAD(bool, specialSplit);
    LOAD(bool, specialDVSplit);
    LOAD(int, maxDVValue);
    LOAD(bool, happiness);
    LOAD(int, happyFaintLoss);
    LOAD(int, happyLevelGain);
    LOAD(int, happySteps);
    LOAD(bool, effortValuesAllowed);
    LOAD(int, maxTotalEV);
    LOAD(int, maxEVPerStat);
    LOAD(Fraction, pokerusChance);
}

QDomElement Rules::save() const
{
    QDomElement xml;
    xml.setTagName(className());
    SAVE(bool, genderAllowed);
    SAVE(bool, breedingAllowed);
    SAVE(int, holdItems);
    SAVE(bool, criticalDomains);
    SAVE(bool, abilityAllowed);
    SAVE(bool, natureAllowed);
    SAVE(int, numBoxes);
    SAVE(int, boxSize);
    SAVE(int, maxParty);
    SAVE(int, maxFight);
    SAVE(int, maxPlayers);
    SAVE(int, maxMoves);
    SAVE(int, maxLevel);
    SAVE(int, maxMoney);
    SAVE(bool, hardCash);
    SAVE(bool, specialSplit);
    SAVE(bool, specialDVSplit);
    SAVE(int, maxDVValue);
    SAVE(bool, happiness);
    SAVE(int, happyFaintLoss);
    SAVE(int, happyLevelGain);
    SAVE(int, happySteps);
    SAVE(bool, effortValuesAllowed);
    SAVE(int, maxTotalEV);
    SAVE(int, maxEVPerStat);
    SAVE(Fraction, pokerusChance);
    return xml;
}

void Rules::setGenderAllowed(const bool genderAllowed)
{
    m_genderAllowed = genderAllowed;
}

void Rules::setBreedingAllowed(const bool breedingAllowed)
{
    m_breedingAllowed = breedingAllowed;
}

void Rules::setHoldItems(const int holdItems)
{
    m_holdItems = holdItems;
}

void Rules::setCriticalDomains(const bool criticalDomains)
{
    m_criticalDomains = criticalDomains;
}

void Rules::setAbilityAllowed(const bool abilityAllowed)
{
    m_abilityAllowed = abilityAllowed;
}

void Rules::setNatureAllowed(const bool natureAllowed)
{
    m_natureAllowed = natureAllowed;
}

void Rules::setNumBoxes(const int numBoxes)
{
    m_numBoxes = numBoxes;
}

void Rules::setBoxSize(const int boxSize)
{
    m_boxSize = boxSize;
}

void Rules::setMaxParty(const int maxParty) throw(BoundsException)
{
    if (!maxParty)
        throw(BoundsException(className(), "maxParty"));
    m_maxParty = maxParty;
    if (maxParty < m_maxFight)
        setMaxFight(maxParty);
}

void Rules::setMaxFight(const int maxFight) throw(BoundsException)
{
    if (m_maxParty < maxFight)
        throw(BoundsException(className(), "maxFight"));
    m_maxFight = maxFight;
}

void Rules::setMaxPlayers(const int maxPlayers) throw(BoundsException)
{
    if (!maxPlayers)
        throw(BoundsException(className(), "maxPlayers"));
    m_maxPlayers = maxPlayers;
}

void Rules::setMaxMoves(const int maxMoves) throw(BoundsException)
{
    if (!maxMoves)
        throw(BoundsException(className(), "maxMoves"));
    m_maxMoves = maxMoves;
}

void Rules::setMaxLevel(const int maxLevel) throw(BoundsException)
{
    if (!maxLevel)
        throw(BoundsException(className(), "maxLevel"));
    m_maxLevel = maxLevel;
}

void Rules::setMaxMoney(const int maxMoney)
{
    m_maxMoney = maxMoney;
}

void Rules::setHardCash(const bool hardCash)
{
    m_hardCash = hardCash;
}

void Rules::setSpecialSplit(const bool specialSplit)
{
    m_specialSplit = specialSplit;
    if (!specialSplit)
        setSpecialDVSplit(false);
}

void Rules::setSpecialDVSplit(const bool specialDVSplit)
{
    m_specialDVSplit = specialDVSplit;
}

void Rules::setMaxDVValue(const unsigned char maxDVValue) throw(BoundsException)
{
    if (1 < maxDVValue)
        throw(BoundsException(className(), "maxDVValue"));
    m_maxDVValue = maxDVValue;
}

void Rules::setHappiness(const bool happiness)
{
    m_happiness = happiness;
}

void Rules::setHappyFaintLoss(const int happyFaintLoss)
{
    m_happyFaintLoss = happyFaintLoss;
}

void Rules::setHappyLevelGain(const int happyLevelGain)
{
    m_happyLevelGain = happyLevelGain;
}

void Rules::setHappySteps(const int happySteps)
{
    m_happySteps = happySteps;
}

void Rules::setEffortValuesAllowed(const bool effortValuesAllowed)
{
    m_effortValuesAllowed = effortValuesAllowed;
}

void Rules::setMaxTotalEV(const int maxTotalEV) throw(BoundsException)
{
    if (!maxTotalEV)
        throw(BoundsException(className(), "maxTotalEV"));
    m_maxTotalEV = maxTotalEV;
    if (maxTotalEV < m_maxEVPerStat)
        setMaxEVPerStat(maxTotalEV);
}

void Rules::setMaxEVPerStat(const int maxEVPerStat) throw(BoundsException)
{
    if (!maxEVPerStat || (m_maxTotalEV < maxEVPerStat))
        throw(BoundsException(className(), "maxEVPerStat"));
    m_maxEVPerStat = maxEVPerStat;
}

void Rules::setPokerusChance(const Fraction& pokerusChance) throw(Exception)
{
    m_pokerusChance = pokerusChance;
}

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

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

int Rules::holdItems() const
{
    return m_holdItems;
}

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

bool Rules::abilityAllowed() const
{
    return m_abilityAllowed;
}

bool Rules::natureAllowed() const
{
    return m_natureAllowed;
}

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

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

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

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

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

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

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

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

bool Rules::hardCash() const
{
    return m_hardCash;
}

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

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

unsigned char Rules::maxDVValue() const
{
    return m_maxDVValue;
}

bool Rules::happiness() const
{
    return m_happiness;
}

int Rules::happyFaintLoss() const
{
    return m_happyFaintLoss;
}

int Rules::happyLevelGain() const
{
    return m_happyLevelGain;
}

int Rules::happySteps() const
{
    return m_happySteps;
}

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

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

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

Fraction Rules::pokerusChance() const
{
    return m_pokerusChance;
}

Rules& Rules::operator=(const Rules& rhs)
{
    if (this == &rhs)
        return *this;
    COPY(genderAllowed);
    COPY(breedingAllowed);
    COPY(holdItems);
    COPY(criticalDomains);
    COPY(abilityAllowed);
    COPY(natureAllowed);
    COPY(numBoxes);
    COPY(boxSize);
    COPY(maxParty);
    COPY(maxFight);
    COPY(maxPlayers);
    COPY(maxMoves);
    COPY(maxLevel);
    COPY(maxMoney);
    COPY(hardCash);
    COPY(specialSplit);
    COPY(specialDVSplit);
    COPY(maxDVValue);
    COPY(happiness);
    COPY(happyFaintLoss);
    COPY(happyLevelGain);
    COPY(happySteps);
    COPY(effortValuesAllowed);
    COPY(maxTotalEV);
    COPY(maxEVPerStat);
    COPY(pokerusChance);
    return *this;
}