/* * 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 "Pokemod.h" const QStringList Rules::DVStr = QStringList() << "16" << "32"; Rules::Rules(const Rules& rules) : Object("Rules", rules.parent(), 0) { *this = rules; } Rules::Rules(const Pokemod* parent) : Object("Rules", parent, 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_allowSwitchStyle(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* parent) : Object("Rules", parent, 0) { *this = rules; } Rules::Rules(const QDomElement& xml, const Pokemod* parent) : Object("Rules", parent, 0) { load(xml); } void Rules::validate() { 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")); TEST(setMaxDVValue, maxDVValue); if (m_effortValuesAllowed) { TEST(setMaxEVPerStat, maxEVPerStat); } TEST(setPokerusChance, pokerusChance); if (.005 < m_pokerusChance) emit(warning("Pokerus chance is high")); } void Rules::load(const QDomElement& xml, const int) { 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, allowSwitchStyle); 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 = QDomDocument().createElement(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, allowSwitchStyle); 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; emit(changed()); } void Rules::setBreedingAllowed(const bool breedingAllowed) { if (!m_genderAllowed && breedingAllowed) { emit(error(bounds("breedingAllowed"))); return; } m_breedingAllowed = breedingAllowed; emit(changed()); } void Rules::setHoldItems(const int holdItems) { m_holdItems = holdItems; emit(changed()); } void Rules::setCriticalDomains(const bool criticalDomains) { m_criticalDomains = criticalDomains; emit(changed()); } void Rules::setAbilityAllowed(const bool abilityAllowed) { m_abilityAllowed = abilityAllowed; emit(changed()); } void Rules::setNatureAllowed(const bool natureAllowed) { m_natureAllowed = natureAllowed; emit(changed()); } void Rules::setNumBoxes(const int numBoxes) { m_numBoxes = numBoxes; emit(changed()); } void Rules::setBoxSize(const int boxSize) { if (m_numBoxes && !boxSize) { emit(error(bounds("boxSize"))); return; } m_boxSize = boxSize; emit(changed()); } void Rules::setMaxParty(const int maxParty) { if (!maxParty) { emit(error(bounds("maxParty"))); return; } m_maxParty = maxParty; emit(changed()); } void Rules::setMaxFight(const int maxFight) { if (m_maxParty < maxFight) { emit(error(bounds("maxFight"))); return; } m_maxFight = maxFight; emit(changed()); } void Rules::setMaxPlayers(const int maxPlayers) { if (!maxPlayers) { emit(error(bounds("maxPlayers"))); return; } m_maxPlayers = maxPlayers; emit(changed()); } void Rules::setMaxMoves(const int maxMoves) { if (!maxMoves) { emit(error(bounds("maxMoves"))); return; } m_maxMoves = maxMoves; emit(changed()); } void Rules::setMaxLevel(const int maxLevel) { if (!maxLevel) { emit(error(bounds("maxLevel"))); return; } m_maxLevel = maxLevel; emit(changed()); } void Rules::setMaxMoney(const int maxMoney) { m_maxMoney = maxMoney; emit(changed()); } void Rules::setHardCash(const bool hardCash) { m_hardCash = hardCash; emit(changed()); } void Rules::setAllowSwitchStyle(const bool allowSwitchStyle) { m_allowSwitchStyle = allowSwitchStyle; emit(changed()); } void Rules::setSpecialSplit(const bool specialSplit) { m_specialSplit = specialSplit; emit(changed()); } void Rules::setSpecialDVSplit(const bool specialDVSplit) { if (!specialDVSplit && m_specialSplit) { emit(error(bounds("specialDVSplit"))); return; } m_specialDVSplit = specialDVSplit; emit(changed()); } void Rules::setMaxDVValue(const unsigned char maxDVValue) { if (1 < maxDVValue) { emit(error(bounds("maxDVValue"))); return; } m_maxDVValue = maxDVValue; emit(changed()); } void Rules::setHappiness(const bool happiness) { m_happiness = happiness; emit(changed()); } void Rules::setHappyFaintLoss(const int happyFaintLoss) { m_happyFaintLoss = happyFaintLoss; emit(changed()); } void Rules::setHappyLevelGain(const int happyLevelGain) { m_happyLevelGain = happyLevelGain; emit(changed()); } void Rules::setHappySteps(const int happySteps) { m_happySteps = happySteps; emit(changed()); } void Rules::setEffortValuesAllowed(const bool effortValuesAllowed) { m_effortValuesAllowed = effortValuesAllowed; emit(changed()); } void Rules::setMaxTotalEV(const int maxTotalEV) { if (!maxTotalEV) { emit(error(bounds("maxTotalEV"))); return; } m_maxTotalEV = maxTotalEV; emit(changed()); } void Rules::setMaxEVPerStat(const int maxEVPerStat) { if ((!maxEVPerStat && m_maxTotalEV) || (m_maxTotalEV < maxEVPerStat)) { emit(error(bounds("maxEVPerStat"))); return; } m_maxEVPerStat = maxEVPerStat; emit(changed()); } void Rules::setPokerusChance(const Fraction& pokerusChance) { if (1 < pokerusChance) { emit(error(bounds("pokerusChance"))); return; } m_pokerusChance = pokerusChance; emit(changed()); } 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::allowSwitchStyle() const { return m_allowSwitchStyle; } 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(allowSwitchStyle); COPY(specialSplit); COPY(specialDVSplit); COPY(maxDVValue); COPY(happiness); COPY(happyFaintLoss); COPY(happyLevelGain); COPY(happySteps); COPY(effortValuesAllowed); COPY(maxTotalEV); COPY(maxEVPerStat); COPY(pokerusChance); return *this; }