diff options
Diffstat (limited to 'pokemod/Rules.cpp')
| -rw-r--r-- | pokemod/Rules.cpp | 577 |
1 files changed, 577 insertions, 0 deletions
diff --git a/pokemod/Rules.cpp b/pokemod/Rules.cpp new file mode 100644 index 00000000..0daede2a --- /dev/null +++ b/pokemod/Rules.cpp @@ -0,0 +1,577 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: pokemod/Rules.h +// Purpose: Rules for a PokéMod +// Author: Ben Boeckel +// Modified by: Ben Boeckel +// Created: Mon Nov 19 14:54:12 2007 +// Copyright: ©2007 Ben Boeckel and Nerdy Productions +// Licence: +// 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 <http://www.gnu.org/licenses/>. +///////////////////////////////////////////////////////////////////////////// + +#include "Rules.h" + +PokeGen::PokeMod::Rules::Rules(const Pokemod& par) : + Object(par, 0), + genderAllowed(false), + breedingAllowed(false), + eggSpecies(UINT_MAX), + holdItems(0), + criticalDomains(false), + abilityAllowed(false), + natureAllowed(false), + numPokemonBoxes(0), + numPokemonPerBox(1), + maxParty(1), + maxFight(1), + maxMoves(1), + maxLevel(1), + maxMoney(0), + hardCash(false), + specialSplit(false), + specialDVSplit(false), + maxDVValue(16), + happiness(false), + happyFaintLoss(0), + happyLevelGain(0), + happySteps(0), + effortValuesAllowed(false), + maxTotalEV(0), + maxEVPerStat(0), + pokerusChance(1, 1), + typeChart(1, 1, Frac(1, 1, Frac::Improper)) +{ +} + +PokeGen::PokeMod::Rules::Rules(const Pokemod& par, const QString& fname) : + Object(par, 0) +{ + load(fname); +} + +bool PokeGen::PokeMod::Rules::validate() const +{ + bool valid = true; + pokemod.validationMsg("---Rules", Pokemod::V_Msg); + if (genderAllowed && breedingAllowed || (pokemod.getSpeciesByID(eggSpecies) == UINT_MAX)) + { + pokemod.validationMsg("Invalid egg species"); + valid = false; + } + if (!numPokemonBoxes) + pokemod.validationMsg("Invalid number of Pokémon boxes", Pokemod::V_Warn); + else if (!numPokemonPerBox) + { + pokemod.validationMsg("Invalid number of Pokémon per box"); + valid = false; + } + if (!maxParty) + { + pokemod.validationMsg("Invalid number of Pokémon for max party"); + valid = false; + } + if (!maxParty || (maxParty < maxFight)) + { + pokemod.validationMsg("More Pokémon can fight than are allowed in the party"); + valid = false; + } + if (!maxMoves) + { + pokemod.validationMsg("Pokémon cannot learn any moves"); + valid = false; + } + if (!maxMoney) + pokemod.validationMsg("Player cannot carry any money", Pokemod::V_Warn); + if ((maxDVValue != 16) && (maxDVValue != 32)) + { + pokemod.validationMsg("Invalid maximum DV value"); + valid = false; + } + if (effortValuesAllowed) + { + if (maxTotalEV < maxEVPerStat) + { + pokemod.validationMsg("More EV points are allowed on a stat than allowed overall"); + valid = false; + } + } + if (.05 < pokerusChance) + pokemod.validationMsg("Pokérus chance is unusually high", Pokemod::V_Warn); + return valid; +} + +void PokeGen::PokeMod::Rules::load(const QString& fname) +{ + Ini ini(fname); + unsigned i; + unsigned j; + ini.getValue("genderAllowed", genderAllowed, false); + ini.getValue("breedingAllowed", breedingAllowed, false); + ini.getValue("eggSpecies", eggSpecies); + ini.getValue("holdItems", holdItems, 0); + ini.getValue("criticalDomains", criticalDomains, false); + ini.getValue("abilityAllowed", abilityAllowed, false); + ini.getValue("natureAllowed", natureAllowed, false); + ini.getValue("numPokemonBoxes", numPokemonBoxes, 0); + ini.getValue("numPokemonPerBox", numPokemonPerBox, 1); + ini.getValue("maxParty", maxParty, 1); + ini.getValue("maxFight", maxFight, 1); + ini.getValue("maxMoves", maxMoves, 1); + ini.getValue("maxLevel", maxLevel, 0); + ini.getValue("maxMoney", maxMoney, 0); + ini.getValue("hardCash", hardCash, false); + ini.getValue("specialSplit", specialSplit, false); + ini.getValue("specialDVSplit", specialDVSplit, false); + ini.getValue("maxDVValue", maxDVValue, 16); + ini.getValue("happiness", happiness, false); + ini.getValue("happyFaintLoss", happyFaintLoss, 0); + ini.getValue("happyLevelGain", happyLevelGain, 0); + ini.getValue("happySteps", happySteps, 0); + ini.getValue("effortValuesAllowed", effortValuesAllowed, false); + ini.getValue("maxTotalEV", maxTotalEV, 0); + ini.getValue("maxEVPerStat", maxEVPerStat, 0); + ini.getValue("pokerusChance-n", i, 1); + ini.getValue("pokerusChance-d", j, 1); + pokerusChance.set(i, j); + for (unsigned i = 0; i < pokemod.getTypeCount(); ++i) + { + for (unsigned j = 0; j < pokemod.getTypeCount(); ++j) + { + unsigned k; + unsigned l; + ini.getValue(QString("typeChart-%1-%2-n").arg(i).arg(j), k, 1); + ini.getValue(QString("typeChart-%1-%2-d").arg(i).arg(j), l, 1); + setTypeChart(i, j, k, l); + } + } +} + +void PokeGen::PokeMod::Rules::save() const +{ + Ini ini; + ini.addField("genderAllowed", genderAllowed); + ini.addField("breedingAllowed", breedingAllowed); + ini.addField("eggSpecies", eggSpecies); + ini.addField("holdItems", holdItems); + ini.addField("criticalDomains", criticalDomains); + ini.addField("abilityAllowed", abilityAllowed); + ini.addField("natureAllowed", natureAllowed); + ini.addField("numPokemonBoxes", numPokemonBoxes); + ini.addField("numPokemonPerBox", numPokemonPerBox); + ini.addField("maxParty", maxParty); + ini.addField("maxFight", maxFight); + ini.addField("maxMoves", maxMoves); + ini.addField("maxLevel", maxLevel); + ini.addField("maxMoney", maxMoney); + ini.addField("hardCash", hardCash); + ini.addField("specialSplit", specialSplit); + ini.addField("specialDVSplit", specialDVSplit); + ini.addField("maxDVValue", maxDVValue); + ini.addField("happiness", happiness); + ini.addField("happyFaintLoss", happyFaintLoss); + ini.addField("happyLevelGain", happyLevelGain); + ini.addField("happySteps", happySteps); + ini.addField("effortValuesAllowed", effortValuesAllowed); + ini.addField("maxTotalEV", maxTotalEV); + ini.addField("maxEVPerStat", maxEVPerStat); + ini.addField("pokerusChance-n", pokerusChance.getNum()); + ini.addField("pokerusChance-d", pokerusChance.getDenom()); + for (unsigned i = 1; i < typeChart.getWidth(); ++i) + { + for (unsigned j = 1; j < typeChart.getHeight(); ++j) + { + ini.addField(QString("typeChart-%1-%2-n").arg(typeChart(i, 0).getNum()).arg(typeChart(0, j).getNum()), typeChart(i, j).getNum()); + ini.addField(QString("typeChart-%1-%2-d").arg(typeChart(i, 0).getNum()).arg(typeChart(0, j).getNum()), typeChart(i, j).getDenom()); + } + } + ini.save(QString("%1/rules.pini").arg(pokemod.getPath())); +} + +void PokeGen::PokeMod::Rules::setGenderAllowed(const bool g) +{ + genderAllowed = g; + if (!genderAllowed) + breedingAllowed = false; +} + +void PokeGen::PokeMod::Rules::setBreedingAllowed(const bool b) +{ + if (!genderAllowed) + throw("Rules: cannot breed without genders"); + breedingAllowed = b; +} + +void PokeGen::PokeMod::Rules::setEggSpecies(const unsigned e) +{ + if (!breedingAllowed) + throw("Rules: ne eggs without breeding"); + if (pokemod.getSpeciesByID(e) == UINT_MAX) + throw("Rules: eggSpecies out-of-bounds"); + eggSpecies = e; +} + +void PokeGen::PokeMod::Rules::setHoldItems(const unsigned h) +{ + holdItems = h; +} + +void PokeGen::PokeMod::Rules::setCriticalDomains(const bool c) +{ + criticalDomains = c; +} + +void PokeGen::PokeMod::Rules::setAbilityAllowed(const bool a) +{ + abilityAllowed = a; +} + +void PokeGen::PokeMod::Rules::setNatureAllowed(const bool n) +{ + natureAllowed = n; +} + +void PokeGen::PokeMod::Rules::setNumPokemonBoxes(const unsigned n) +{ + numPokemonBoxes = n; +} + +void PokeGen::PokeMod::Rules::setNumPokemonPerBox(const unsigned n) +{ + numPokemonPerBox = n; +} + +void PokeGen::PokeMod::Rules::setMaxParty(const unsigned m) +{ + if (!m) + throw("Rules: maxParty out-of-bounds"); + maxParty = m; +} + +void PokeGen::PokeMod::Rules::setMaxFight(const unsigned m) +{ + if (maxParty < m) + throw("Rules: maxFight out-of-bounds"); + maxFight = m; +} + +void PokeGen::PokeMod::Rules::setMaxMoves(const unsigned m) +{ + if (!m) + throw("Rules: maxMoves out-of-bounds"); + maxMoves = m; +} + +void PokeGen::PokeMod::Rules::setMaxLevel(const unsigned m) +{ + if (!m) + throw("Rules: maxLevel out-of-bounds"); + maxLevel = m; +} + +void PokeGen::PokeMod::Rules::setMaxMoney(const unsigned m) +{ + maxMoney = m; +} + +void PokeGen::PokeMod::Rules::setHardCash(const bool h) +{ + hardCash = h; +} + +void PokeGen::PokeMod::Rules::setSpecialSplit(const bool s) +{ + specialSplit = s; +} + +void PokeGen::PokeMod::Rules::setSpecialDVSplit(const bool s) +{ + specialDVSplit = s; +} + +void PokeGen::PokeMod::Rules::setMaxDVValue(const unsigned char m) +{ + if ((m != 16) && (m != 32)) + throw("Rules: maxDVValue out-of-bounds"); + maxDVValue = m; +} + +void PokeGen::PokeMod::Rules::setHappiness(const bool h) +{ + happiness = h; +} + +void PokeGen::PokeMod::Rules::setHappyFaintLoss(const unsigned h) +{ + happyFaintLoss = h; +} + +void PokeGen::PokeMod::Rules::setHappyLevelGain(const unsigned h) +{ + happyLevelGain = h; +} + +void PokeGen::PokeMod::Rules::setHappySteps(const unsigned h) +{ + happySteps = h; +} + +void PokeGen::PokeMod::Rules::setEffortValuesAllowed(const bool e) +{ + effortValuesAllowed = e; +} + +void PokeGen::PokeMod::Rules::setMaxTotalEV(const unsigned m) +{ + if (!effortValuesAllowed) + throw("Rules: no effort values"); + maxTotalEV = m; +} + +void PokeGen::PokeMod::Rules::setMaxEVPerStat(const unsigned m) +{ + if (!effortValuesAllowed) + throw("Rules: no effort values"); + if (maxTotalEV < m) + throw("Rules: maxEVPerStat out-of-bounds"); + maxEVPerStat = m; +} + +void PokeGen::PokeMod::Rules::setPokerusChance(const unsigned n, const unsigned d) +{ + pokerusChance.set(n, d); +} + +void PokeGen::PokeMod::Rules::setPokerusChanceNum(const unsigned n) +{ + pokerusChance.setNum(n); +} + +void PokeGen::PokeMod::Rules::setPokerusChanceDenom(const unsigned d) +{ + pokerusChance.setDenom(d); +} + +bool PokeGen::PokeMod::Rules::getGenderAllowed() const +{ + return genderAllowed; +} + +bool PokeGen::PokeMod::Rules::getBreedingAllowed() const +{ + return breedingAllowed; +} + +unsigned PokeGen::PokeMod::Rules::getEggSpecies() const +{ + return eggSpecies; +} + +unsigned PokeGen::PokeMod::Rules::getHoldItems() const +{ + return holdItems; +} + +bool PokeGen::PokeMod::Rules::getCriticalDomains() const +{ + return criticalDomains; +} + +bool PokeGen::PokeMod::Rules::getAbilityAllowed() const +{ + return abilityAllowed; +} + +bool PokeGen::PokeMod::Rules::getNatureAllowed() const +{ + return natureAllowed; +} + +unsigned PokeGen::PokeMod::Rules::getNumPokemonBoxes() const +{ + return numPokemonBoxes; +} + +unsigned PokeGen::PokeMod::Rules::getNumPokemonPerBox() const +{ + return numPokemonPerBox; +} + +unsigned PokeGen::PokeMod::Rules::getMaxParty() const +{ + return maxParty; +} + +unsigned PokeGen::PokeMod::Rules::getMaxFight() const +{ + return maxFight; +} + +unsigned PokeGen::PokeMod::Rules::getMaxMoves() const +{ + return maxMoves; +} + +unsigned PokeGen::PokeMod::Rules::getMaxLevel() const +{ + return maxLevel; +} + +unsigned PokeGen::PokeMod::Rules::getMaxMoney() const +{ + return maxMoney; +} + +bool PokeGen::PokeMod::Rules::getHardCash() const +{ + return hardCash; +} + +bool PokeGen::PokeMod::Rules::getSpecialSplit() const +{ + return specialSplit; +} + +bool PokeGen::PokeMod::Rules::getSpecialDVSplit() const +{ + return specialDVSplit; +} + +unsigned char PokeGen::PokeMod::Rules::getMaxDVValue() const +{ + return maxDVValue; +} + +bool PokeGen::PokeMod::Rules::getHappiness() const +{ + return happiness; +} + +unsigned PokeGen::PokeMod::Rules::getHappyFaintLoss() const +{ + return happyFaintLoss; +} + +unsigned PokeGen::PokeMod::Rules::getHappyLevelGain() const +{ + return happyLevelGain; +} + +unsigned PokeGen::PokeMod::Rules::getHappySteps() const +{ + return happySteps; +} + +bool PokeGen::PokeMod::Rules::getEffortValuesAllowed() const +{ + return effortValuesAllowed; +} + +unsigned PokeGen::PokeMod::Rules::getMaxTotalEV() const +{ + return maxTotalEV; +} + +unsigned PokeGen::PokeMod::Rules::getMaxEVPerStat() const +{ + return maxEVPerStat; +} + +PokeGen::Frac PokeGen::PokeMod::Rules::getPokerusChance() const +{ + return pokerusChance; +} + +unsigned PokeGen::PokeMod::Rules::getPokerusChanceNum() const +{ + return pokerusChance.getNum(); +} + +unsigned PokeGen::PokeMod::Rules::getPokerusChanceDenom() const +{ + return pokerusChance.getDenom(); +} + +void PokeGen::PokeMod::Rules::setTypeChart(const unsigned att, const unsigned def, const unsigned n, const unsigned d) +{ + typeChart(att, def).set(n, d); +} + +void PokeGen::PokeMod::Rules::setTypeChartNum(const unsigned att, const unsigned def, const unsigned n) +{ + typeChart(att, def).setNum(n); +} + +void PokeGen::PokeMod::Rules::setTypeChartDenom(const unsigned att, const unsigned def, const unsigned d) +{ + typeChart(att, def).setDenom(d); +} + +const PokeGen::FracMatrix& PokeGen::PokeMod::Rules::getTypeChart() const +{ + return typeChart; +} + +PokeGen::FracMatrix& PokeGen::PokeMod::Rules::getTypeChart() +{ + return typeChart; +} + +PokeGen::Frac PokeGen::PokeMod::Rules::getTypeChart(const unsigned att, const unsigned def) const +{ + return typeChart(att, def); +} + +unsigned PokeGen::PokeMod::Rules::getTypeChartNum(const unsigned att, const unsigned def) const +{ + return getTypeChart(att, def).getNum(); +} + +unsigned PokeGen::PokeMod::Rules::getTypeChartDenom(const unsigned att, const unsigned def) const +{ + return getTypeChart(att, def).getDenom(); +} + +PokeGen::PokeMod::Rules& PokeGen::PokeMod::Rules::operator=(const Rules& rhs) +{ + if (this == &rhs) + return *this; + genderAllowed = rhs.genderAllowed; + breedingAllowed = rhs.breedingAllowed; + eggSpecies = rhs.eggSpecies; + holdItems = rhs.holdItems; + criticalDomains = rhs.criticalDomains; + abilityAllowed = rhs.abilityAllowed; + natureAllowed = rhs.natureAllowed; + numPokemonBoxes = rhs.numPokemonBoxes; + numPokemonPerBox = rhs.numPokemonPerBox; + maxParty = rhs.maxParty; + maxFight = rhs.maxFight; + maxMoves = rhs.maxMoves; + maxLevel = rhs.maxLevel; + maxMoney = rhs.maxMoney; + hardCash = rhs.hardCash; + specialSplit = rhs.specialSplit; + specialDVSplit = rhs.specialDVSplit; + maxDVValue = rhs.maxDVValue; + happiness = rhs.happiness; + happyFaintLoss = rhs.happyFaintLoss; + happyLevelGain = rhs.happyLevelGain; + happySteps = rhs.happySteps; + effortValuesAllowed = rhs.effortValuesAllowed; + maxTotalEV = rhs.maxTotalEV; + maxEVPerStat = rhs.maxEVPerStat; + pokerusChance = rhs.pokerusChance; + typeChart = rhs.typeChart; + return *this; +} |
