diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-04-15 18:57:00 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-04-15 18:57:00 +0000 |
| commit | e1b5d7bc705810ac15ed36924617af52abdc8e81 (patch) | |
| tree | 0dae5af4e2737372ec479bb9ccdd2201edf684a8 /pokemod/Rules.cpp | |
| parent | 12d5161318a4d8d781f896812f5a95fa7b46d8a8 (diff) | |
[FIX] Object::mid -> m_id
[FIX] XML is now used
[FIX] Images are stored in the XML file and classes rather than relying on external images
[FIX] Frac no longer keeps track of its type; the class should do it
[ADD] pokemod/Object.cpp
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@97 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Rules.cpp')
| -rw-r--r-- | pokemod/Rules.cpp | 184 |
1 files changed, 90 insertions, 94 deletions
diff --git a/pokemod/Rules.cpp b/pokemod/Rules.cpp index 3d2f2ca8..89288b5c 100644 --- a/pokemod/Rules.cpp +++ b/pokemod/Rules.cpp @@ -60,10 +60,10 @@ Rules::Rules(const Pokemod* pokemod, const Rules& rules) : *this = rules; } -Rules::Rules(const Pokemod* pokemod, const QString& fileName) : +Rules::Rules(const Pokemod* pokemod, const QDomElement& xml) : Object("Rules", pokemod, 0) { - load(fileName); + load(xml); } bool Rules::validate() const @@ -117,72 +117,68 @@ bool Rules::validate() const return valid; } -void Rules::load(const QString& fileName, const int) throw(Exception) -{ - Ini ini(fileName); - int i; - int j; - ini.getValue("genderAllowed", m_genderAllowed, false); - ini.getValue("breedingAllowed", m_breedingAllowed, false); - ini.getValue("holdItems", m_holdItems, 0); - ini.getValue("criticalDomains", m_criticalDomains, false); - ini.getValue("abilityAllowed", m_abilityAllowed, false); - ini.getValue("natureAllowed", m_natureAllowed, false); - ini.getValue("numBoxes", m_numBoxes, 0); - ini.getValue("boxSize", m_boxSize, 1); - ini.getValue("maxParty", m_maxParty, 1); - ini.getValue("maxFight", m_maxFight, 1); - ini.getValue("maxPlayers", m_maxPlayers, 2); - ini.getValue("maxMoves", m_maxMoves, 1); - ini.getValue("maxLevel", m_maxLevel, 0); - ini.getValue("maxMoney", m_maxMoney, 0); - ini.getValue("hardCash", m_hardCash, false); - ini.getValue("specialSplit", m_specialSplit, false); - ini.getValue("specialDVSplit", m_specialDVSplit, false); - ini.getValue("maxDVValue", m_maxDVValue, 16); - ini.getValue("happiness", m_happiness, false); - ini.getValue("happyFaintLoss", m_happyFaintLoss, 0); - ini.getValue("happyLevelGain", m_happyLevelGain, 0); - ini.getValue("happySteps", m_happySteps, 0); - ini.getValue("effortValuesAllowed", m_effortValuesAllowed, false); - ini.getValue("maxTotalEV", m_maxTotalEV, 0); - ini.getValue("maxEVPerStat", m_maxEVPerStat, 0); - ini.getValue("pokerusChance-n", i, 1); - ini.getValue("pokerusChance-d", j, 1); - m_pokerusChance.set(i, j); -} - -void Rules::save() const throw(Exception) -{ - Ini ini; - ini.addField("genderAllowed", m_genderAllowed); - ini.addField("breedingAllowed", m_breedingAllowed); - ini.addField("holdItems", m_holdItems); - ini.addField("criticalDomains", m_criticalDomains); - ini.addField("abilityAllowed", m_abilityAllowed); - ini.addField("natureAllowed", m_natureAllowed); - ini.addField("numBoxes", m_numBoxes); - ini.addField("boxSize", m_boxSize); - ini.addField("maxParty", m_maxParty); - ini.addField("maxFight", m_maxFight); - ini.addField("maxPlayers", m_maxPlayers); - ini.addField("maxMoves", m_maxMoves); - ini.addField("maxLevel", m_maxLevel); - ini.addField("maxMoney", m_maxMoney); - ini.addField("hardCash", m_hardCash); - ini.addField("specialSplit", m_specialSplit); - ini.addField("specialDVSplit", m_specialDVSplit); - ini.addField("maxDVValue", m_maxDVValue); - ini.addField("happiness", m_happiness); - ini.addField("happyFaintLoss", m_happyFaintLoss); - ini.addField("happyLevelGain", m_happyLevelGain); - ini.addField("happySteps", m_happySteps); - ini.addField("effortValuesAllowed", m_effortValuesAllowed); - ini.addField("maxTotalEV", m_maxTotalEV); - ini.addField("maxEVPerStat", m_maxEVPerStat); - ini.addField("pokerusChance-n", m_pokerusChance.numerator()); - ini.addField("pokerusChance-d", m_pokerusChance.denominator()); - ini.save(QString("%1/rules.pini").arg(pokemod()->path())); +void Rules::load(const QDomElement& xml, const int) throw(Exception) +{ + 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, 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(Frac, pokerusChance); +} + +QDomElement Rules::save() const +{ + QDomElement xml; + xml.setTagName(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, 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(Frac, pokerusChance); + return xml; } void Rules::setGenderAllowed(const bool genderAllowed) @@ -471,31 +467,31 @@ Rules& Rules::operator=(const Rules& rhs) { if (this == &rhs) return *this; - m_genderAllowed = rhs.m_genderAllowed; - m_breedingAllowed = rhs.m_breedingAllowed; - m_holdItems = rhs.m_holdItems; - m_criticalDomains = rhs.m_criticalDomains; - m_abilityAllowed = rhs.m_abilityAllowed; - m_natureAllowed = rhs.m_natureAllowed; - 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_maxMoves = rhs.m_maxMoves; - m_maxLevel = rhs.m_maxLevel; - m_maxMoney = rhs.m_maxMoney; - m_hardCash = rhs.m_hardCash; - m_specialSplit = rhs.m_specialSplit; - m_specialDVSplit = rhs.m_specialDVSplit; - m_maxDVValue = rhs.m_maxDVValue; - m_happiness = rhs.m_happiness; - m_happyFaintLoss = rhs.m_happyFaintLoss; - m_happyLevelGain = rhs.m_happyLevelGain; - m_happySteps = rhs.m_happySteps; - m_effortValuesAllowed = rhs.m_effortValuesAllowed; - m_maxTotalEV = rhs.m_maxTotalEV; - m_maxEVPerStat = rhs.m_maxEVPerStat; - m_pokerusChance = rhs.m_pokerusChance; + 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(specialSplit); + COPY(specialDVSplit); + COPY(maxDVValue); + COPY(happiness); + COPY(happyFaintLoss); + COPY(happyLevelGain); + COPY(happySteps); + COPY(effortValuesAllowed); + COPY(maxTotalEV); + COPY(maxEVPerStat); + COPY(pokerusChance); return *this; } |
