diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-12-28 20:57:26 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-12-28 20:57:26 -0500 |
| commit | 471658adb0a2df73eef065cce4e7550d6dd14b1e (patch) | |
| tree | 40fdc45294ea22f863d13dc804e8369cf868ece3 | |
| parent | a5d04bdc0b7e572c01c9cc0a49387b95ad23594c (diff) | |
| download | sigen-471658adb0a2df73eef065cce4e7550d6dd14b1e.tar.gz sigen-471658adb0a2df73eef065cce4e7550d6dd14b1e.tar.xz sigen-471658adb0a2df73eef065cce4e7550d6dd14b1e.zip | |
Rules now uses check macros and fixed bound checks
| -rw-r--r-- | sigmod/Rules.cpp | 408 | ||||
| -rw-r--r-- | sigmod/Rules.h | 25 | ||||
| -rw-r--r-- | sigmodr/gui/rules.ui | 4 |
3 files changed, 144 insertions, 293 deletions
diff --git a/sigmod/Rules.cpp b/sigmod/Rules.cpp index 3de6fe1a..9f9394a4 100644 --- a/sigmod/Rules.cpp +++ b/sigmod/Rules.cpp @@ -74,23 +74,26 @@ Sigmod::Rules::Rules(const QDomElement& xml, const Sigmod* parent) : 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); + TEST(breedingAllowed); + TEST(numBoxes); + TEST(boxSize); + TEST(maxParty); + TEST(maxFight); + TEST(maxPlayers); + TEST(maxHeldItems); + TEST(maxAbilities); + TEST(maxNatures); + TEST(maxMoves); + TEST(maxLevel); + TEST(maxStages); if (!m_maxMoney) emit(warning("Player cannot carry any money")); else - TEST(setMaxMoney, maxMoney); - TEST(setMaxTotalWeight, maxTotalWeight); + TEST(maxMoney); + TEST(maxTotalWeight); if (m_effortValuesAllowed) { - TEST(setMaxEVPerStat, maxEVPerStat); + TEST(maxEVPerStat); } TEST_END(); } @@ -154,287 +157,110 @@ QDomElement Sigmod::Rules::save() const return xml; } -void Sigmod::Rules::setGenderAllowed(const bool genderAllowed) -{ - CHECK(genderAllowed); -} - -void Sigmod::Rules::setBreedingAllowed(const bool breedingAllowed) -{ +SETTER(Rules, bool, GenderAllowed, genderAllowed) +SETTER(Rules, bool, BreedingAllowed, breedingAllowed) +SETTER(Rules, bool, CriticalDomains, criticalDomains) +SETTER(Rules, bool, UseTurns, useTurns) +SETTER(Rules, bool, PausedATB, pausedATB) +SETTER(Rules, int, NumBoxes, numBoxes) +SETTER(Rules, int, BoxSize, boxSize) +SETTER(Rules, int, MaxParty, maxParty) +SETTER(Rules, int, MaxFight, maxFight) +SETTER(Rules, int, MaxPlayers, maxPlayers) +SETTER(Rules, int, MaxHeldItems, maxHeldItems) +SETTER(Rules, int, MaxAbilities, maxAbilities) +SETTER(Rules, int, MaxNatures, maxNatures) +SETTER(Rules, int, MaxMoves, maxMoves) +SETTER(Rules, int, MaxLevel, maxLevel) +SETTER(Rules, int, MaxStages, maxStages) +SETTER(Rules, int, MaxMoney, maxMoney) +SETTER(Rules, int, MaxTotalWeight, maxTotalWeight) +SETTER(Rules, bool, AllowSwitchStyle, allowSwitchStyle) +SETTER(Rules, bool, SpecialSplit, specialSplit) +SETTER(Rules, bool, SpecialDVSplit, specialDVSplit) +SETTER(Rules, bool, EffortValuesAllowed, effortValuesAllowed) +SETTER(Rules, int, MaxTotalEV, maxTotalEV) +SETTER(Rules, int, MaxEVPerStat, maxEVPerStat) + +GETTER(Rules, bool, genderAllowed) +GETTER(Rules, bool, breedingAllowed) +GETTER(Rules, bool, criticalDomains) +GETTER(Rules, bool, useTurns) +GETTER(Rules, bool, pausedATB) +GETTER(Rules, int, numBoxes) +GETTER(Rules, int, boxSize) +GETTER(Rules, int, maxParty) +GETTER(Rules, int, maxFight) +GETTER(Rules, int, maxPlayers) +GETTER(Rules, int, maxHeldItems) +GETTER(Rules, int, maxAbilities) +GETTER(Rules, int, maxNatures) +GETTER(Rules, int, maxMoves) +GETTER(Rules, int, maxLevel) +GETTER(Rules, int, maxStages) +GETTER(Rules, int, maxMoney) +GETTER(Rules, int, maxTotalWeight) +GETTER(Rules, bool, allowSwitchStyle) +GETTER(Rules, bool, specialSplit) +GETTER(Rules, bool, specialDVSplit) +GETTER(Rules, bool, effortValuesAllowed) +GETTER(Rules, int, maxTotalEV) +GETTER(Rules, int, maxEVPerStat) + +CHECK(Rules, bool, genderAllowed) +CHECK_BEGIN(Rules, 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) -{ + { + ERROR("Cannot breed when genders are not allowed"); + return false; + } +CHECK_END() +CHECK(Rules, bool, criticalDomains) +CHECK(Rules, bool, useTurns) +CHECK_BEGIN(Rules, 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; -} + { + ERROR("Cannot pause ATB when turns are used"); + return false; + } +CHECK_END() +CHECK(Rules, int, numBoxes) +CHECK_BEGIN(Rules, int, boxSize) + if (m_numBoxes) + { + TBOUNDS(boxSize, 1, INT_MAX); + return false; + } +CHECK_END() +CHECK_BOUNDS(Rules, int, maxParty, 1, INT_MAX) +CHECK_BOUNDS(Rules, int, maxFight, 1, m_maxParty) +CHECK_BOUNDS(Rules, int, maxPlayers, 2, INT_MAX) +CHECK_BOUNDS(Rules, int, maxHeldItems, 0, INT_MAX) +CHECK_BOUNDS(Rules, int, maxAbilities, 0, INT_MAX) +CHECK_BOUNDS(Rules, int, maxNatures, 0, INT_MAX) +CHECK_BOUNDS(Rules, int, maxMoves, 1, INT_MAX) +CHECK_BOUNDS(Rules, int, maxLevel, 1, INT_MAX) +CHECK_BOUNDS(Rules, int, maxStages, 0, INT_MAX) +CHECK_BOUNDS(Rules, int, maxMoney, 0, INT_MAX) +CHECK_BOUNDS(Rules, int, maxTotalWeight, -1, INT_MAX) +CHECK(Rules, bool, allowSwitchStyle) +CHECK(Rules, bool, specialSplit) +CHECK_BEGIN(Rules, bool, specialDVSplit) + if (!m_specialSplit && specialDVSplit) + { + ERROR("Cannot split special DV when special is not split"); + return false; + } +CHECK_END() +CHECK(Rules, bool, effortValuesAllowed) +CHECK_BOUNDS(Rules, int, maxTotalEV, 0, INT_MAX) +CHECK_BEGIN(Rules, int, maxEVPerStat) + if (m_maxTotalEV) + { + TBOUNDS(maxEVPerStat, 0, m_maxTotalEV); + return false; + } +CHECK_END() Sigmod::Rules& Sigmod::Rules::operator=(const Rules& rhs) { diff --git a/sigmod/Rules.h b/sigmod/Rules.h index 7a9f621c..aaa574f0 100644 --- a/sigmod/Rules.h +++ b/sigmod/Rules.h @@ -93,6 +93,31 @@ class SIGMOD_EXPORT Rules : public Object int maxTotalEV() const; int maxEVPerStat() const; + bool genderAllowedCheck(const bool genderAllowed) const; + bool breedingAllowedCheck(const bool breedingAllowed) const; + bool criticalDomainsCheck(const bool criticalDomains) const; + bool useTurnsCheck(const bool useTurns) const; + bool pausedATBCheck(const bool pausedATB) const; + bool numBoxesCheck(const int numBoxes) const; + bool boxSizeCheck(const int boxSize) const; + bool maxPartyCheck(const int maxParty) const; + bool maxFightCheck(const int maxFight) const; + bool maxPlayersCheck(const int maxPlayers) const; + bool maxHeldItemsCheck(const int maxHeldItems) const; + bool maxAbilitiesCheck(const int maxAbilities) const; + bool maxNaturesCheck(const int maxNatures) const; + bool maxMovesCheck(const int maxMoves) const; + bool maxLevelCheck(const int maxLevel) const; + bool maxStagesCheck(const int maxStage) const; + bool maxMoneyCheck(const int maxMoney) const; + bool maxTotalWeightCheck(const int maxTotalWeight) const; + bool allowSwitchStyleCheck(const bool allowSwitchStyle) const; + bool specialSplitCheck(const bool specialSplit) const; + bool specialDVSplitCheck(const bool specialDVSplit) const; + bool effortValuesAllowedCheck(const bool effortValues) const; + bool maxTotalEVCheck(const int maxTotalEV) const; + bool maxEVPerStatCheck(const int maxEVPerStat) const; + Rules& operator=(const Rules& rhs); private: bool m_genderAllowed; diff --git a/sigmodr/gui/rules.ui b/sigmodr/gui/rules.ui index 614d46a2..85c3af0f 100644 --- a/sigmodr/gui/rules.ui +++ b/sigmodr/gui/rules.ui @@ -182,7 +182,7 @@ <string>The maximum amount of effort values allowed</string> </property> <property name="minimum" > - <number>1</number> + <number>0</number> </property> </widget> </item> @@ -201,7 +201,7 @@ <string>The maximum amount of effort values allowed for a single stat</string> </property> <property name="minimum" > - <number>1</number> + <number>0</number> </property> </widget> </item> |
