/* * Copyright 2007-2009 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 "Game.h" #include "Macros.h" using namespace Sigmod; const QStringList Rules::DVStr = QStringList() << "16" << "32"; Rules::Rules(const Rules& rules) : Object(rules.parent(), 0) { *this = rules; } Rules::Rules(const Game* parent) : Object(parent, 0), m_genderAllowed(false), m_breedingAllowed(false), m_criticalDomains(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_specialSplit(false), m_specialDVSplit(false), m_maxTotalEV(0), m_maxEVPerStat(0) { } Rules::Rules(const Rules& rules, const Game* parent) : Object(parent, 0) { *this = rules; } Rules::Rules(const QDomElement& xml, const Game* parent) : Object(parent, 0) { load(xml); } void Rules::validate() { testBegin(); 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(maxMoney); TEST(maxTotalWeight); TEST(maxTotalEV); TEST(maxEVPerStat); testEnd(); } void Rules::load(const QDomElement& xml) { clear(); loadValue(xml.firstChildElement("genderAllowed"), &m_genderAllowed); loadValue(xml.firstChildElement("breedingAllowed"), &m_breedingAllowed); loadValue(xml.firstChildElement("criticalDomains"), &m_criticalDomains); loadValue(xml.firstChildElement("numBoxes"), &m_numBoxes); loadValue(xml.firstChildElement("boxSize"), &m_boxSize); loadValue(xml.firstChildElement("maxParty"), &m_maxParty); loadValue(xml.firstChildElement("maxFight"), &m_maxFight); loadValue(xml.firstChildElement("maxPlayers"), &m_maxPlayers); loadValue(xml.firstChildElement("maxHeldItems"), &m_maxHeldItems); loadValue(xml.firstChildElement("maxAbilities"), &m_maxAbilities); loadValue(xml.firstChildElement("maxNatures"), &m_maxNatures); loadValue(xml.firstChildElement("maxMoves"), &m_maxMoves); loadValue(xml.firstChildElement("maxLevel"), &m_maxLevel); loadValue(xml.firstChildElement("maxStages"), &m_maxStages); loadValue(xml.firstChildElement("maxMoney"), &m_maxMoney); loadValue(xml.firstChildElement("maxTotalWeight"), &m_maxTotalWeight); loadValue(xml.firstChildElement("specialSplit"), &m_specialSplit); loadValue(xml.firstChildElement("specialDVSplit"), &m_specialDVSplit); loadValue(xml.firstChildElement("maxTotalEV"), &m_maxTotalEV); loadValue(xml.firstChildElement("maxEVPerStat"), &m_maxEVPerStat); } QDomElement Rules::save() const { QDomElement xml = initXmlExport(); xml.removeAttribute("id"); xml.appendChild(saveValue("genderAllowed", m_genderAllowed)); xml.appendChild(saveValue("breedingAllowed", m_breedingAllowed)); xml.appendChild(saveValue("criticalDomains", m_criticalDomains)); xml.appendChild(saveValue("numBoxes", m_numBoxes)); xml.appendChild(saveValue("boxSize", m_boxSize)); xml.appendChild(saveValue("maxParty", m_maxParty)); xml.appendChild(saveValue("maxFight", m_maxFight)); xml.appendChild(saveValue("maxPlayers", m_maxPlayers)); xml.appendChild(saveValue("maxHeldItems", m_maxHeldItems)); xml.appendChild(saveValue("maxAbilities", m_maxAbilities)); xml.appendChild(saveValue("maxNatures", m_maxNatures)); xml.appendChild(saveValue("maxMoves", m_maxMoves)); xml.appendChild(saveValue("maxLevel", m_maxLevel)); xml.appendChild(saveValue("maxStages", m_maxStages)); xml.appendChild(saveValue("maxMoney", m_maxMoney)); xml.appendChild(saveValue("maxTotalWeight", m_maxTotalWeight)); xml.appendChild(saveValue("specialSplit", m_specialSplit)); xml.appendChild(saveValue("specialDVSplit", m_specialDVSplit)); xml.appendChild(saveValue("maxTotalEV", m_maxTotalEV)); xml.appendChild(saveValue("maxEVPerStat", m_maxEVPerStat)); return xml; } SETTER(Rules, bool, GenderAllowed, genderAllowed) SETTER(Rules, bool, BreedingAllowed, breedingAllowed) SETTER(Rules, bool, CriticalDomains, criticalDomains) 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, SpecialSplit, specialSplit) SETTER(Rules, bool, SpecialDVSplit, specialDVSplit) SETTER(Rules, int, MaxTotalEV, maxTotalEV) SETTER(Rules, int, MaxEVPerStat, maxEVPerStat) GETTER(Rules, bool, genderAllowed) GETTER(Rules, bool, breedingAllowed) GETTER(Rules, bool, criticalDomains) 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, specialSplit) GETTER(Rules, bool, specialDVSplit) GETTER(Rules, int, maxTotalEV) GETTER(Rules, int, maxEVPerStat) CHECK(Rules, bool, genderAllowed) CHECK_BEGIN(Rules, bool, breedingAllowed) if (!m_genderAllowed && breedingAllowed) { ERROR("Cannot breed when genders are not allowed"); return false; } CHECK_END() CHECK(Rules, bool, criticalDomains) CHECK_BOUNDS(Rules, int, numBoxes, 0, INT_MAX) CHECK_BEGIN(Rules, int, boxSize) if (m_numBoxes) TBOUNDS(boxSize, 1, INT_MAX); 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, -1, INT_MAX) CHECK_BOUNDS(Rules, int, maxMoney, 0, INT_MAX) CHECK_BOUNDS(Rules, int, maxTotalWeight, -1, INT_MAX) 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_BEGIN(Rules, int, maxTotalEV) TBOUNDS(maxTotalEV, 0, INT_MAX); CHECK_END() CHECK_BEGIN(Rules, int, maxEVPerStat) if (m_maxTotalEV) TBOUNDS(maxEVPerStat, 1, m_maxTotalEV); CHECK_END() Rules& Rules::operator=(const Rules& rhs) { if (this == &rhs) return *this; m_genderAllowed = rhs.m_genderAllowed; m_breedingAllowed = rhs.m_breedingAllowed; m_criticalDomains = rhs.m_criticalDomains; m_numBoxes = rhs.m_numBoxes; m_boxSize = rhs.m_boxSize; m_maxParty = rhs.m_maxParty; m_maxFight = rhs.m_maxFight; m_maxPlayers = rhs.m_maxPlayers; m_maxHeldItems = rhs.m_maxHeldItems; m_maxAbilities = rhs.m_maxAbilities; m_maxNatures = rhs.m_maxNatures; m_maxMoves = rhs.m_maxMoves; m_maxLevel = rhs.m_maxLevel; m_maxStages = rhs.m_maxStages; m_maxMoney = rhs.m_maxMoney; m_maxTotalWeight = rhs.m_maxTotalWeight; m_specialSplit = rhs.m_specialSplit; m_specialDVSplit = rhs.m_specialDVSplit; m_maxTotalEV = rhs.m_maxTotalEV; m_maxEVPerStat = rhs.m_maxEVPerStat; return *this; }