/* * Copyright 2007-2008 Ben Boeckel * * 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 . */ // 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; }