diff options
Diffstat (limited to 'pokemod/Rules.cpp')
| -rw-r--r-- | pokemod/Rules.cpp | 163 |
1 files changed, 85 insertions, 78 deletions
diff --git a/pokemod/Rules.cpp b/pokemod/Rules.cpp index 6c113e88..600bfdd5 100644 --- a/pokemod/Rules.cpp +++ b/pokemod/Rules.cpp @@ -72,59 +72,30 @@ Rules::Rules(const QDomElement& xml, const Object* parent) : load(xml); } -bool Rules::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg("---Rules", Pokemod::V_Msg); -// if (!m_numBoxes) -// static_cast<const Pokemod*>(pokemod())->validationMsg("No box storage", Pokemod::V_Warn); -// else if (!m_boxSize) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid box size"); -// valid = false; -// } -// if (!m_maxParty) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid party size"); -// valid = false; -// } -// if (!m_maxParty || (m_maxParty < m_maxFight)) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Larger active than party"); -// valid = false; -// } -// if (m_maxPlayers < 2) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Cannot have battles without at least two players"); -// valid = false; -// } -// if (!m_maxMoves) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("No moves can be learned"); -// valid = false; -// } -// if (!m_maxMoney) -// static_cast<const Pokemod*>(pokemod())->validationMsg("Player cannot carry any money", Pokemod::V_Warn); -// if (1 < m_maxDVValue) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid maximum DV value"); -// valid = false; -// } -// if (m_effortValuesAllowed) -// { -// if (m_maxTotalEV < m_maxEVPerStat) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("More EV points are allowed on a stat than allowed overall"); -// valid = false; -// } -// } -// if (.005 < m_pokerusChance) -// static_cast<const Pokemod*>(pokemod())->validationMsg("Pokérus chance is unusually high", Pokemod::V_Warn); -// return valid; -} - -void Rules::load(const QDomElement& xml, const int) throw(Exception) +void Rules::validate(QTextStream& stream) +{ + TEST_SETUP(); + TEST(setBreedingAllowed, breedingAllowed); + TEST(setNumBoxes, numBoxes); + TEST(setBoxSize, boxSize); + TEST(setMaxParty, maxParty); + TEST(setMaxFight, maxFight); + TEST(setMaxPlayers, maxPlayers); + TEST(setMaxMoves, maxMoves); + TEST(setMaxLevel, maxLevel); + if (!m_maxMoney) + warning(stream, "Player cannot carry any money"); + TEST(setMaxDVValue, maxDVValue); + if (m_effortValuesAllowed) + { + TEST(setMaxEVPerStat, maxEVPerStat); + } + TEST(setPokerusChance, pokerusChance); + if (.005 < m_pokerusChance) + warning(stream, "Pokerus chance is high"); +} + +void Rules::load(const QDomElement& xml, const int) { clear(); LOAD(bool, genderAllowed); @@ -194,6 +165,11 @@ void Rules::setGenderAllowed(const bool genderAllowed) void Rules::setBreedingAllowed(const bool breedingAllowed) { + if (!m_genderAllowed && breedingAllowed) + { + boundsError("breedingAllowed"); + return; + } m_breedingAllowed = breedingAllowed; } @@ -224,43 +200,61 @@ void Rules::setNumBoxes(const int numBoxes) void Rules::setBoxSize(const int boxSize) { + if (m_numBoxes && !boxSize) + { + boundsError("boxSize"); + return; + } m_boxSize = boxSize; } -void Rules::setMaxParty(const int maxParty) throw(BoundsException) +void Rules::setMaxParty(const int maxParty) { if (!maxParty) - error<BoundsException>("maxParty"); + { + boundsError("maxParty"); + return; + } m_maxParty = maxParty; - if (maxParty < m_maxFight) - setMaxFight(maxParty); } -void Rules::setMaxFight(const int maxFight) throw(BoundsException) +void Rules::setMaxFight(const int maxFight) { if (m_maxParty < maxFight) - error<BoundsException>("maxFight"); + { + boundsError("maxFight"); + return; + } m_maxFight = maxFight; } -void Rules::setMaxPlayers(const int maxPlayers) throw(BoundsException) +void Rules::setMaxPlayers(const int maxPlayers) { if (!maxPlayers) - error<BoundsException>("maxPlayers"); + { + boundsError("maxPlayers"); + return; + } m_maxPlayers = maxPlayers; } -void Rules::setMaxMoves(const int maxMoves) throw(BoundsException) +void Rules::setMaxMoves(const int maxMoves) { if (!maxMoves) - error<BoundsException>("maxMoves"); + { + boundsError("maxMoves"); + return; + } m_maxMoves = maxMoves; } -void Rules::setMaxLevel(const int maxLevel) throw(BoundsException) +void Rules::setMaxLevel(const int maxLevel) { if (!maxLevel) - error<BoundsException>("maxLevel"); + { + boundsError("maxLevel"); + return; + } m_maxLevel = maxLevel; } @@ -277,19 +271,25 @@ void Rules::setHardCash(const bool hardCash) void Rules::setSpecialSplit(const bool specialSplit) { m_specialSplit = specialSplit; - if (!specialSplit) - setSpecialDVSplit(false); } void Rules::setSpecialDVSplit(const bool specialDVSplit) { + if (specialDVSplit && m_specialSplit) + { + boundsError("specialDVSplit"); + return; + } m_specialDVSplit = specialDVSplit; } -void Rules::setMaxDVValue(const unsigned char maxDVValue) throw(BoundsException) +void Rules::setMaxDVValue(const unsigned char maxDVValue) { if (1 < maxDVValue) - error<BoundsException>("maxDVValue"); + { + boundsError("maxDVValue"); + return; + } m_maxDVValue = maxDVValue; } @@ -318,26 +318,33 @@ void Rules::setEffortValuesAllowed(const bool effortValuesAllowed) m_effortValuesAllowed = effortValuesAllowed; } -void Rules::setMaxTotalEV(const int maxTotalEV) throw(BoundsException) +void Rules::setMaxTotalEV(const int maxTotalEV) { if (!maxTotalEV) - error<BoundsException>("maxTotalEV"); + { + boundsError("maxTotalEV"); + return; + } m_maxTotalEV = maxTotalEV; - if (maxTotalEV < m_maxEVPerStat) - setMaxEVPerStat(maxTotalEV); } -void Rules::setMaxEVPerStat(const int maxEVPerStat) throw(BoundsException) +void Rules::setMaxEVPerStat(const int maxEVPerStat) { - if (!maxEVPerStat || (m_maxTotalEV < maxEVPerStat)) - error<BoundsException>("maxEVPerStat"); + if ((!maxEVPerStat && m_maxTotalEV) || (m_maxTotalEV < maxEVPerStat)) + { + boundsError("maxEVPerStat"); + return; + } m_maxEVPerStat = maxEVPerStat; } -void Rules::setPokerusChance(const Fraction& pokerusChance) throw(BoundsException) +void Rules::setPokerusChance(const Fraction& pokerusChance) { if (1 < pokerusChance) - error<BoundsException>("pokerusChance"); + { + boundsError("pokerusChance"); + return; + } m_pokerusChance = pokerusChance; } |
