/* * 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" // Pokemod includes #include "Macros.h" #include "Pokemod.h" const QStringList Pokemod::Rules::DVStr = QStringList() << "16" << "32"; Pokemod::Rules::Rules(const Rules& rules) : Object("Rules", rules.parent(), 0) { *this = rules; } Pokemod::Rules::Rules(const Pokemod* parent) : Object("Rules", parent, 0), m_genderAllowed(false), m_breedingAllowed(false), m_criticalDomains(false), m_useTurns(true), 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_hardCash(false), m_allowSwitchStyle(false), m_specialSplit(false), m_specialDVSplit(false), 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) { } Pokemod::Rules::Rules(const Rules& rules, const Pokemod* parent) : Object("Rules", parent, 0) { *this = rules; } Pokemod::Rules::Rules(const QDomElement& xml, const Pokemod* parent) : Object("Rules", parent, 0) { load(xml); } void Pokemod::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); if (!m_maxMoney) emit(warning("Player cannot carry any money")); if (m_effortValuesAllowed) { TEST(setMaxEVPerStat, maxEVPerStat); } TEST(setPokerusChance, pokerusChance); if (.005 < m_pokerusChance) emit(warning("Pokerus chance is high")); TEST_END(); } void Pokemod::Rules::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(bool, genderAllowed); LOAD(bool, breedingAllowed); LOAD(bool, criticalDomains); LOAD(bool, useTurns); LOAD(int, numBoxes); LOAD(int, boxSize); LOAD(int, maxParty); LOAD(int, maxFight); LOAD(int, maxPlayers); LOAD(int, maxHeldItems); LOAD(int, maxAbilities); LOAD(int, maxNatures); LOAD(int, maxMoves); LOAD(int, maxLevel); LOAD(int, maxStages); LOAD(int, maxMoney); LOAD(bool, hardCash); LOAD(bool, allowSwitchStyle); LOAD(bool, specialSplit); LOAD(bool, specialDVSplit); 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 Pokemod::Rules::save() const { QDomElement xml = QDomDocument().createElement(className()); SAVE(bool, genderAllowed); SAVE(bool, breedingAllowed); SAVE(bool, criticalDomains); SAVE(bool, useTurns); SAVE(int, numBoxes); SAVE(int, boxSize); SAVE(int, maxParty); SAVE(int, maxFight); SAVE(int, maxPlayers); SAVE(int, maxHeldItems); SAVE(int, maxAbilities); SAVE(int, maxNatures); SAVE(int, maxMoves); SAVE(int, maxLevel); SAVE(int, maxStages); SAVE(int, maxMoney); SAVE(bool, hardCash); SAVE(bool, allowSwitchStyle); SAVE(bool, specialSplit); SAVE(bool, specialDVSplit); 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 Pokemod::Rules::setGenderAllowed(const bool genderAllowed) { CHECK(genderAllowed); } void Pokemod::Rules::setBreedingAllowed(const bool breedingAllowed) { if (!m_genderAllowed && breedingAllowed) { emit(error(bounds("breedingAllowed"))); return; } CHECK(breedingAllowed); } void Pokemod::Rules::setCriticalDomains(const bool criticalDomains) { CHECK(criticalDomains); } void Pokemod::Rules::setUseTurns(const bool useTurns) { CHECK(useTurns); } void Pokemod::Rules::setNumBoxes(const int numBoxes) { CHECK(numBoxes); } void Pokemod::Rules::setBoxSize(const int boxSize) { if (m_numBoxes && !boxSize) { emit(error(bounds("boxSize"))); return; } CHECK(boxSize); } void Pokemod::Rules::setMaxParty(const int maxParty) { if (!maxParty) { emit(error(bounds("maxParty"))); return; } CHECK(maxParty); } void Pokemod::Rules::setMaxFight(const int maxFight) { if (m_maxParty < maxFight) { emit(error(bounds("maxFight"))); return; } CHECK(maxFight); } void Pokemod::Rules::setMaxPlayers(const int maxPlayers) { if (maxPlayers < 2) { emit(error(bounds("maxPlayers"))); return; } CHECK(maxPlayers); } void Pokemod::Rules::setMaxHeldItems(const int maxHeldItems) { CHECK(maxHeldItems); } void Pokemod::Rules::setMaxAbilities(const int maxAbilities) { CHECK(maxAbilities); } void Pokemod::Rules::setMaxNatures(const int maxNatures) { CHECK(maxNatures); } void Pokemod::Rules::setMaxMoves(const int maxMoves) { if (!maxMoves) { emit(error(bounds("maxMoves"))); return; } CHECK(maxMoves); } void Pokemod::Rules::setMaxLevel(const int maxLevel) { if (!maxLevel) { emit(error(bounds("maxLevel"))); return; } CHECK(maxLevel); } void Pokemod::Rules::setMaxStages(const int maxStages) { CHECK(maxStages); } void Pokemod::Rules::setMaxMoney(const int maxMoney) { CHECK(maxMoney); } void Pokemod::Rules::setHardCash(const bool hardCash) { CHECK(hardCash); } void Pokemod::Rules::setAllowSwitchStyle(const bool allowSwitchStyle) { CHECK(allowSwitchStyle); } void Pokemod::Rules::setSpecialSplit(const bool specialSplit) { CHECK(specialSplit); } void Pokemod::Rules::setSpecialDVSplit(const bool specialDVSplit) { if (!specialDVSplit && m_specialSplit) { emit(error(bounds("specialDVSplit"))); return; } CHECK(specialDVSplit); } void Pokemod::Rules::setHappiness(const bool happiness) { CHECK(happiness); } void Pokemod::Rules::setHappyFaintLoss(const int happyFaintLoss) { CHECK(happyFaintLoss); } void Pokemod::Rules::setHappyLevelGain(const int happyLevelGain) { CHECK(happyLevelGain); } void Pokemod::Rules::setHappySteps(const int happySteps) { CHECK(happySteps); } void Pokemod::Rules::setEffortValuesAllowed(const bool effortValuesAllowed) { CHECK(effortValuesAllowed); } void Pokemod::Rules::setMaxTotalEV(const int maxTotalEV) { if (!maxTotalEV) { emit(error(bounds("maxTotalEV"))); return; } CHECK(maxTotalEV); } void Pokemod::Rules::setMaxEVPerStat(const int maxEVPerStat) { if ((!maxEVPerStat && m_maxTotalEV) || (m_maxTotalEV < maxEVPerStat)) { emit(error(bounds("maxEVPerStat"))); return; } CHECK(maxEVPerStat); } void Pokemod::Rules::setPokerusChance(const Fraction& pokerusChance) { if (1 < pokerusChance) { emit(error(bounds("pokerusChance"))); return; } CHECK(pokerusChance); } bool Pokemod::Rules::genderAllowed() const { return m_genderAllowed; } bool Pokemod::Rules::breedingAllowed() const { return m_breedingAllowed; } bool Pokemod::Rules::criticalDomains() const { return m_criticalDomains; } bool Pokemod::Rules::useTurns() const { return m_useTurns; } int Pokemod::Rules::numBoxes() const { return m_numBoxes; } int Pokemod::Rules::boxSize() const { return m_boxSize; } int Pokemod::Rules::maxParty() const { return m_maxParty; } int Pokemod::Rules::maxFight() const { return m_maxFight; } int Pokemod::Rules::maxPlayers() const { return m_maxPlayers; } int Pokemod::Rules::maxHeldItems() const { return m_maxHeldItems; } int Pokemod::Rules::maxAbilities() const { return m_maxAbilities; } int Pokemod::Rules::maxNatures() const { return m_maxNatures; } int Pokemod::Rules::maxMoves() const { return m_maxMoves; } int Pokemod::Rules::maxLevel() const { return m_maxLevel; } int Pokemod::Rules::maxStages() const { return m_maxStages; } int Pokemod::Rules::maxMoney() const { return m_maxMoney; } bool Pokemod::Rules::hardCash() const { return m_hardCash; } bool Pokemod::Rules::allowSwitchStyle() const { return m_allowSwitchStyle; } bool Pokemod::Rules::specialSplit() const { return m_specialSplit; } bool Pokemod::Rules::specialDVSplit() const { return m_specialDVSplit; } bool Pokemod::Rules::happiness() const { return m_happiness; } int Pokemod::Rules::happyFaintLoss() const { return m_happyFaintLoss; } int Pokemod::Rules::happyLevelGain() const { return m_happyLevelGain; } int Pokemod::Rules::happySteps() const { return m_happySteps; } bool Pokemod::Rules::effortValuesAllowed() const { return m_effortValuesAllowed; } int Pokemod::Rules::maxTotalEV() const { return m_maxTotalEV; } int Pokemod::Rules::maxEVPerStat() const { return m_maxEVPerStat; } Pokemod::Fraction Pokemod::Rules::pokerusChance() const { return m_pokerusChance; } Pokemod::Rules& Pokemod::Rules::operator=(const Rules& rhs) { if (this == &rhs) return *this; COPY(genderAllowed); COPY(breedingAllowed); COPY(criticalDomains); COPY(useTurns); 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(hardCash); COPY(allowSwitchStyle); COPY(specialSplit); COPY(specialDVSplit); COPY(happiness); COPY(happyFaintLoss); COPY(happyLevelGain); COPY(happySteps); COPY(effortValuesAllowed); COPY(maxTotalEV); COPY(maxEVPerStat); COPY(pokerusChance); return *this; }