///////////////////////////////////////////////////////////////////////////// // Name: pokemod/Species.cpp // Purpose: Define a species // Author: Ben Boeckel // Modified by: Ben Boeckel // Created: Fri June 1 2007 12:10:40 // Copyright: ©2007-2008 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 // MERCHANTSpecies 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 . ///////////////////////////////////////////////////////////////////////////// #include "Species.h" const char* PokeMod::Species::StyleStr[PokeMod::Species::End] = {"Fluctuating", "Fading", "Slow", "Normal", "Fast", "Erratic"}; PokeMod::Species::Species(const Pokemod& par, const unsigned _id) : Object(par, _id), name(""), growth(UINT_MAX), catchValue(0), runChance(1, 1), itemChance(1, 1), pokedexNumber(UINT_MAX), weight(0), heightFeet(0), heightInches(0), pokedexEntry(""), genderFactor(1, 1, true), eggSpecies(UINT_MAX), eggSteps(0), nidoranGroup(UINT_MAX) { for (unsigned i = 0; i < ST_End_GSC; ++i) { baseStats[i] = 0; effortValues[i] = 0; } } PokeMod::Species::Species(const Pokemod& par, const Species& s, const unsigned _id) : Object(par, _id) { *this = s; } PokeMod::Species::Species(const Pokemod& par, const QString& fname, const unsigned _id) : Object(par, _id) { load(fname, _id); } bool PokeMod::Species::validate() const { bool valid = true; pokemod.validationMsg(QString("---Species \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); if (name == "") { pokemod.validationMsg("Name is not defined"); valid = false; } for (unsigned i = 0; i < (pokemod.getRules().getSpecialSplit() ? ST_End_GSC : ST_End_RBY); ++i) { if (!baseStats[i]) { pokemod.validationMsg(QString("Invalid baseStats[%1]").arg(i)); valid = false; } } if (End <= growth) { pokemod.validationMsg("Invalid growth style"); valid = false; } if (pokemod.getSpeciesCount() <= pokedexNumber) { pokemod.validationMsg("Invalid PokéDex number"); valid = false; } if (!weight) pokemod.validationMsg("Species weighs nothing", Pokemod::V_Warn); if (12 <= heightInches) { pokemod.validationMsg("Invalid height inches"); valid = false; } if (!QFile::exists(QString("%1/species/%2/front%3.png").arg(pokemod.getPath()).arg(name).arg(pokemod.getRules().getGenderAllowed() ? "-male" : ""))) { pokemod.validationMsg(QString("Cannot find the front%1 image").arg(pokemod.getRules().getGenderAllowed() ? " male" : "")); valid = false; } if (!QFile::exists(QString("%1/species/%2/back%3.png").arg(pokemod.getPath()).arg(name).arg(pokemod.getRules().getGenderAllowed() ? "-male" : ""))) { pokemod.validationMsg(QString("Cannot find the back%1 image").arg(pokemod.getRules().getGenderAllowed() ? " male" : "")); valid = false; } if (pokemod.getRules().getGenderAllowed()) { if (!QFile::exists(QString("%1/species/%2/front-female.png").arg(pokemod.getPath()).arg(name))) { pokemod.validationMsg("Cannot find the front female image"); valid = false; } if (!QFile::exists(QString("%1/species/%2/back-female.png").arg(pokemod.getPath()).arg(name))) { pokemod.validationMsg("Cannot find the back female image"); valid = false; } } if (!QFile::exists(QString("%1/species/%2/list.png").arg(pokemod.getPath()).arg(name))) { pokemod.validationMsg("Cannot find the list sprite"); valid = false; } if (pokemod.getSpeciesIndex(eggSpecies) == UINT_MAX) pokemod.validationMsg("Invalid egg species", Pokemod::V_Warn); else if (!eggSteps) { pokemod.validationMsg("Invalid egg steps"); valid = false; } QMap idChecker; QMap nameChecker; for (QListIterator i(types); i.hasNext(); i.next()) { if (pokemod.getTypeIndex(i.peekNext()) == UINT_MAX) { pokemod.validationMsg("Invalid type"); valid = false; } ++nameChecker[i.peekNext()]; } for (QMapIterator i(nameChecker); i.hasNext(); i.next()) { if (1 < i.value()) { pokemod.validationMsg(QString("There are %1 of type %2").arg(i.value()).arg(i.key())); valid = false; } } nameChecker.clear(); for (QListIterator i(eggGroups); i.hasNext(); i.next()) { if (pokemod.getEggGroupIndex(i.peekNext()) == UINT_MAX) { pokemod.validationMsg("Invalid egg group"); valid = false; } ++nameChecker[i.peekNext()]; } for (QMapIterator i(nameChecker); i.hasNext(); i.next()) { if (1 < i.value()) { pokemod.validationMsg(QString("There are %1 of egg group %2").arg(i.value()).arg(i.key())); valid = false; } } nameChecker.clear(); if (pokemod.getRules().getAbilityAllowed()) { if (!getAbilityCount()) pokemod.validationMsg("There are no abilities", Pokemod::V_Warn); for (QListIterator i(abilities); i.hasNext(); i.next()) { if (!i.peekNext().isValid()) valid = false; ++idChecker[i.peekNext().getId()]; ++nameChecker[i.peekNext().getAbility()]; } for (QMapIterator i(idChecker); i.hasNext(); i.next()) { if (1 < i.value()) { pokemod.validationMsg(QString("There are %1 abilities with id %2").arg(i.value()).arg(i.key())); valid = false; } } for (QMapIterator i(nameChecker); i.hasNext(); i.next()) { if (1 < i.value()) { pokemod.validationMsg(QString("There are %1 abilities with the ability %2").arg(i.value()).arg(i.key())); valid = false; } } idChecker.clear(); nameChecker.clear(); } if (!getEvolutionCount()) pokemod.validationMsg("There are no evolutions", Pokemod::V_Warn); for (QListIterator i(evolutions); i.hasNext(); i.next()) { if (!i.peekNext().isValid()) valid = false; if (i.peekNext().getSpecies() == id) { pokemod.validationMsg("Evolution is of the same species"); valid = false; } ++idChecker[i.peekNext().getId()]; ++nameChecker[i.peekNext().getSpecies()]; } for (QMapIterator i(idChecker); i.hasNext(); i.next()) { if (1 < i.value()) { pokemod.validationMsg(QString("There are %1 evolutions with id %2").arg(i.value()).arg(i.key())); valid = false; } } for (QMapIterator i(nameChecker); i.hasNext(); i.next()) { if (1 < i.value()) { pokemod.validationMsg(QString("There are %1 evoltions with the speices %2").arg(i.value()).arg(i.key())); valid = false; } } idChecker.clear(); nameChecker.clear(); if (pokemod.getRules().getHoldItems()) { if (!getItemCount()) pokemod.validationMsg("There are no items", Pokemod::V_Warn); for (QListIterator i(items); i.hasNext(); i.next()) { if (!i.peekNext().isValid()) valid = false; ++idChecker[i.peekNext().getId()]; ++nameChecker[i.peekNext().getItem()]; } for (QMapIterator i(idChecker); i.hasNext(); i.next()) { if (1 < i.value()) { pokemod.validationMsg(QString("There are %1 items with id %2").arg(i.value()).arg(i.key())); valid = false; } } for (QMapIterator i(nameChecker); i.hasNext(); i.next()) { if (1 < i.value()) { pokemod.validationMsg(QString("There are %1 items with the item %2").arg(i.value()).arg(i.key())); valid = false; } } idChecker.clear(); nameChecker.clear(); } if (!getMoveCount()) { pokemod.validationMsg("There are no moves"); valid = false; } for (QListIterator i(moves); i.hasNext(); i.next()) { if (!i.peekNext().isValid()) valid = false; ++idChecker[i.peekNext().getId()]; ++nameChecker[i.peekNext().getMove()]; } for (QMapIterator i(idChecker); i.hasNext(); i.next()) { if (1 < i.value()) { pokemod.validationMsg(QString("There are %1 moves with id %2").arg(i.value()).arg(i.key())); valid = false; } } for (QMapIterator i(nameChecker); i.hasNext(); i.next()) { if (1 < i.value()) { pokemod.validationMsg(QString("There are %1 moves with the move %2").arg(i.value()).arg(i.key())); valid = false; } } idChecker.clear(); nameChecker.clear(); return valid; } unsigned PokeMod::Species::getNewAbilityId() const { unsigned i = 0; for (; (i < getAbilityCount()) && (getAbilityIndex(i) != UINT_MAX); ++i) ; return i; } unsigned PokeMod::Species::getNewEvolutionId() const { unsigned i = 0; for (; (i < getEvolutionCount()) && (getEvolutionIndex(i) != UINT_MAX); ++i) ; return i; } unsigned PokeMod::Species::getNewItemId() const { unsigned i = 0; for (; (i < getItemCount()) && (getItemIndex(i) != UINT_MAX); ++i) ; return i; } unsigned PokeMod::Species::getNewMoveId() const { unsigned i = 0; for (; (i < getMoveCount()) && (getMoveIndex(i) != UINT_MAX); ++i) ; return i; } void PokeMod::Species::load(const QString& fname, const unsigned _id) throw(Exception) { Ini ini(fname); if (_id == UINT_MAX) ini.getValue("id", id); else id = _id; unsigned i; unsigned j; ini.getValue("name", name); for (unsigned i = 0; i < ST_End_GSC; ++i) ini.getValue(QString("baseStats-%d").arg(i), baseStats[i], 0); for (unsigned i = 0; i < ST_End_GSC; ++i) ini.getValue(QString("effortValues-%1").arg(i), effortValues[i], 0); ini.getValue("growth", growth); ini.getValue("experienceValue", experienceValue, 0); ini.getValue("catchValue", catchValue, 0); ini.getValue("runChance-n", i, 1); ini.getValue("runChance-d", j, 1); runChance.set(i, j); ini.getValue("itemChance-i", i, 1); ini.getValue("itemChance-j", j, 1); itemChance.set(i, j); ini.getValue("pokedexNumber", pokedexNumber); ini.getValue("weight", weight, 0); ini.getValue("heightFeet", heightFeet, 0); ini.getValue("heightInches", heightInches, 0); ini.getValue("pokedexEntry", pokedexEntry); ini.getValue("genderFactor-n", i, 1); ini.getValue("genderFactor-d", j, 1); genderFactor.set(i, j, true); ini.getValue("eggSpecies", eggSpecies); ini.getValue("eggSteps", eggSteps, 0); ini.getValue("nidoranGroup", nidoranGroup); ini.getValue("numTypes", i); for (unsigned k = 0; k < i; ++k) { ini.getValue(QString("type-%1").arg(i), j); if (j != UINT_MAX) types.append(j); } ini.getValue("numEggGroups", i); for (unsigned k = 0; k < i; ++k) { ini.getValue(QString("eggGroup-%1").arg(i), j); if (j != UINT_MAX) types.append(j); } QStringList path = pokemod.getPath().split('/'); path.removeLast(); QDir fdir(path.join("/")); abilities.clear(); if (fdir.cd("ability")) { for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) newAbility(i.next()); fdir.cdUp(); } evolutions.clear(); if (fdir.cd("evolution")) { for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) newEvolution(i.next()); fdir.cdUp(); } items.clear(); if (fdir.cd("item")) { for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) newItem(i.next()); fdir.cdUp(); } moves.clear(); if (fdir.cd("move")) { for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) newMove(i.next()); } } void PokeMod::Species::save() const throw(Exception) { Ini ini; ini.addField("id", id); ini.addField("name", name); for (unsigned i = 0; i < ST_End_GSC; ++i) ini.addField(QString("baseStats-%1").arg(i), baseStats[i]); for (unsigned i = 0; i < ST_End_GSC; ++i) ini.addField(QString("effortValues-%1").arg(i), effortValues[i]); ini.addField("growth", growth); ini.addField("experienceValue", experienceValue); ini.addField("catchValue", catchValue); ini.addField("runChance-n", runChance.getNum()); ini.addField("runChance-d", runChance.getDenom()); ini.addField("itemChance-n", itemChance.getNum()); ini.addField("itemChance-d", itemChance.getDenom()); ini.addField("pokedexNumber", pokedexNumber); ini.addField("weight", weight); ini.addField("heightFeet", heightFeet); ini.addField("heightInches", heightInches); ini.addField("pokedexEntry", pokedexEntry); ini.addField("genderFactor-n", genderFactor.getNum()); ini.addField("genderFactor-d", genderFactor.getDenom()); ini.addField("eggSpecies", eggSpecies); ini.addField("eggSteps", eggSteps); ini.addField("nidoranGroup", nidoranGroup); ini.addField("numTypes", types.size()); for (unsigned i = 0; i < unsigned(types.size()); ++i) ini.addField(QString("type-%1").arg(i), types[i]); ini.addField("numEggGroups", eggGroups.size()); for (unsigned i = 0; i < unsigned(eggGroups.size()); ++i) ini.addField(QString("eggGroup-%1").arg(i), eggGroups[i]); ini.save(QString("%1/species/%2/data.pini").arg(pokemod.getPath()).arg(name)); for (QListIterator i(abilities); i.hasNext(); ) i.next().save(name); for (QListIterator i(evolutions); i.hasNext(); ) i.next().save(name); for (QListIterator i(items); i.hasNext(); ) i.next().save(name); for (QListIterator i(moves); i.hasNext(); ) i.next().save(name); } void PokeMod::Species::setName(const QString& n) { name = n; } void PokeMod::Species::setBaseStat(const unsigned s, const unsigned b) throw(BoundsException) { if ((ST_End_RBY <= s) || ((s == ST_SpecialDefense) && !pokemod.getRules().getSpecialSplit())) throw(BoundsException("Species", "stat")); baseStats[s] = b; } void PokeMod::Species::setEffortValue(const unsigned s, const unsigned e) throw(Exception) { if (!pokemod.getRules().getEffortValuesAllowed()) throw(Exception("Species", "effortValues not allowed")); if (pokemod.getRules().getMaxEVPerStat() < e) throw(BoundsException("Species", "effortValue")); if ((ST_End_RBY <= s) || ((s == ST_SpecialDefense) && !pokemod.getRules().getSpecialSplit())) throw(BoundsException("Species", "stat")); effortValues[s] = e; } void PokeMod::Species::setGrowth(const unsigned g) throw(BoundsException) { if (End <= g) throw(BoundsException("Species", "growth")); growth = g; } void PokeMod::Species::setExperienceValue(const unsigned e) { experienceValue = e; } void PokeMod::Species::setCatchValue(const unsigned char c) { catchValue = c; } void PokeMod::Species::setRunChance(const unsigned n, const unsigned d) throw(Exception) { runChance.set(n, d); } void PokeMod::Species::setRunChanceNumerator(const unsigned n) throw(Exception) { runChance.setNum(n); } void PokeMod::Species::setRunChanceDenominator(const unsigned d) throw(Exception) { runChance.setDenom(d); } void PokeMod::Species::setItemChance(const unsigned n, const unsigned d) throw(Exception) { itemChance.set(n, d); } void PokeMod::Species::setItemChanceNumerator(const unsigned n) throw(Exception) { itemChance.setNum(n); } void PokeMod::Species::setItemChanceDenominator(const unsigned d) throw(Exception) { itemChance.setDenom(d); } void PokeMod::Species::setPokedexNumber(const unsigned p) { pokedexNumber = p; } void PokeMod::Species::setWeight(const unsigned w) { weight = w; } void PokeMod::Species::setHeightFeet(const unsigned f) { heightFeet = f; } void PokeMod::Species::setHeightInches(const unsigned char i) throw(BoundsException) { if (12 <= i) throw(BoundsException("Species", "heightInches")); heightInches = i; } void PokeMod::Species::setPokedexEntry(const QString& p) { pokedexEntry = p; } void PokeMod::Species::setFrontMaleSprite(const QString& fname) throw(Exception) { QFile file(QString("%1/species/%2/front%3.png").arg(pokemod.getPath()).arg(name).arg(pokemod.getRules().getGenderAllowed() ? "-male" : "")); if (file.exists() && !file.remove()) throw(RemoveException("Species", file.fileName())); if (!QFile::copy(fname, QString("%1/species/%2/front%3.png").arg(pokemod.getPath()).arg(name).arg(pokemod.getRules().getGenderAllowed() ? "-male" : ""))) throw(SaveException("Species", file.fileName())); } void PokeMod::Species::setBackMaleSprite(const QString& fname) throw(Exception) { QFile file(QString("%1/species/%2/back%3.png").arg(pokemod.getPath()).arg(name).arg(pokemod.getRules().getGenderAllowed() ? "-male" : "")); if (file.exists() && !file.remove()) throw(RemoveException("Species", file.fileName())); if (!QFile::copy(fname, QString("%1/species/%2/back%3.png").arg(pokemod.getPath()).arg(name).arg(pokemod.getRules().getGenderAllowed() ? "-male" : ""))) throw(SaveException("Species", file.fileName())); } void PokeMod::Species::setFrontFemaleSprite(const QString& fname) throw(Exception) { if (!pokemod.getRules().getGenderAllowed()) throw(Exception("Species", "gender is not allowed")); QFile file(QString("%1/species/%2/front-female.png").arg(pokemod.getPath()).arg(name)); if (file.exists() && !file.remove()) throw(RemoveException("Species", file.fileName())); if (!QFile::copy(fname, QString("%1/species/%2/front-female.png").arg(pokemod.getPath()).arg(name))) throw(SaveException("Species", file.fileName())); } void PokeMod::Species::setBackFemaleSprite(const QString& fname) throw(Exception) { if (!pokemod.getRules().getGenderAllowed()) throw(Exception("Species", "gender is not allowed")); QFile file(QString("%1/species/%2/back-female.png").arg(pokemod.getPath()).arg(name)); if (file.exists() && !file.remove()) throw(RemoveException("Species", file.fileName())); if (!QFile::copy(fname, QString("%1/species/%2/back-female.png").arg(pokemod.getPath()).arg(name))) throw(SaveException("Species", file.fileName())); } void PokeMod::Species::setListSprite(const QString& fname) throw(Exception) { QFile file(QString("%1/species/%2/list.png").arg(pokemod.getPath()).arg(name)); if (file.exists() && !file.remove()) throw(RemoveException("Species", file.fileName())); if (!QFile::copy(fname, QString("%1/species/%2/list.png").arg(pokemod.getPath()).arg(name))) throw(SaveException("Species", file.fileName())); } void PokeMod::Species::setGenderFactor(const unsigned n, const unsigned d) throw(Exception) { genderFactor.set(n, d); } void PokeMod::Species::setGenderFactorNum(const unsigned n) throw(Exception) { genderFactor.setNum(n); } void PokeMod::Species::setGenderFactorDenom(const unsigned d) throw(Exception) { genderFactor.setDenom(d); } void PokeMod::Species::setEggSpecies(const unsigned e) throw(BoundsException) { if (pokemod.getSpeciesIndex(e) == UINT_MAX) throw(BoundsException("Species", "eggSpecies")); eggSpecies = e; } void PokeMod::Species::setEggSteps(const unsigned e) { eggSteps = e; } void PokeMod::Species::setNidoranGroup(const unsigned n) { nidoranGroup = n; } void PokeMod::Species::setType(const unsigned ty, const bool t) throw(Exception) { if (pokemod.getTypeIndex(ty) == UINT_MAX) throw(BoundsException("Species", "type")); for (QMutableListIterator i(types); i.hasNext(); ) { if (i.next() == ty) { if (t) throw(Exception("Species", "type already used")); else i.remove(); } } if (!t) throw(Exception("Species", "type wasn\'t being used anyway")); types.append(ty); } void PokeMod::Species::setEggGroup(const unsigned eg, const bool e) throw(Exception) { if (pokemod.getEggGroupIndex(eg) == UINT_MAX) throw(BoundsException("Species", "eggGroup")); for (QMutableListIterator i(eggGroups); i.hasNext(); ) { if (i.next() == eg) { if (e) throw(Exception("Species", "egg group already used")); else i.remove(); } } if (!e) throw(Exception("Species", "egg group wasn\'t being used anyway")); eggGroups.append(eg); } QString PokeMod::Species::getName() const { return name; } unsigned PokeMod::Species::getBaseStat(const unsigned s) const throw(BoundsException) { if ((ST_End_RBY <= s) || ((s == ST_SpecialDefense) && !pokemod.getRules().getSpecialSplit())) throw(BoundsException("Species", "stat")); return baseStats[s]; } unsigned PokeMod::Species::getEffortValue(const unsigned s) const throw(BoundsException) { if ((ST_End_RBY <= s) || ((s == ST_SpecialDefense) && !pokemod.getRules().getSpecialSplit())) throw(BoundsException("Species", "stat")); return effortValues[s]; } unsigned PokeMod::Species::getGrowth() const { return growth; } unsigned PokeMod::Species::getExperienceValue() const { return experienceValue; } unsigned char PokeMod::Species::getCatchValue() const { return catchValue; } Frac PokeMod::Species::getRunChance() const { return runChance; } Frac PokeMod::Species::getItemChance() const { return itemChance; } unsigned PokeMod::Species::getPokedexNumber() const { return pokedexNumber; } unsigned PokeMod::Species::getWeight() const { return weight; } unsigned PokeMod::Species::getHeightFeet() const { return heightFeet; } unsigned PokeMod::Species::getHeightInches() const { return heightInches; } QString PokeMod::Species::getPokedexEntry() const { return pokedexEntry; } Frac PokeMod::Species::getGenderFactor() const { return genderFactor; } unsigned PokeMod::Species::getEggSpecies() const { return eggSpecies; } unsigned PokeMod::Species::getEggSteps() const { return eggSteps; } unsigned PokeMod::Species::getNidoranGroup() const { return nidoranGroup; } bool PokeMod::Species::getType(const unsigned ty) const { for (QListIterator i(types); i.hasNext(); ) { if (i.next() == ty) return true; } return false; } bool PokeMod::Species::getEggGroup(const unsigned eg) const { for (QListIterator i(eggGroups); i.hasNext(); ) { if (i.next() == eg) return true; } return false; } const PokeMod::SpeciesAbility& PokeMod::Species::getAbility(const unsigned i) const throw(IndexException) { if (getAbilityCount() <= i) throw(IndexException("Species")); return abilities.at(i); } PokeMod::SpeciesAbility& PokeMod::Species::getAbility(const unsigned i) throw(IndexException) { if (getAbilityCount() <= i) throw(IndexException("Species")); return abilities[i]; } const PokeMod::SpeciesAbility& PokeMod::Species::getAbilityByID(const unsigned i) const throw(IndexException) { return getAbility(getAbilityIndex(i)); } PokeMod::SpeciesAbility& PokeMod::Species::getAbilityByID(const unsigned i) throw(IndexException) { return getAbility(getAbilityIndex(i)); } unsigned PokeMod::Species::getAbilityIndex(const unsigned _id) const { for (unsigned i = 0; i < getAbilityCount(); ++i) { if (abilities[i].getId() == _id) return i; } return UINT_MAX; } unsigned PokeMod::Species::getAbilityCount() const { return abilities.size(); } PokeMod::SpeciesAbility& PokeMod::Species::newAbility() { abilities.append(SpeciesAbility(pokemod, getNewAbilityId())); return abilities[getAbilityCount() - 1]; } PokeMod::SpeciesAbility& PokeMod::Species::newAbility(const QString& fname) { abilities.append(SpeciesAbility(pokemod, fname, getNewAbilityId())); return abilities[getAbilityCount() - 1]; } PokeMod::SpeciesAbility& PokeMod::Species::newAbility(const SpeciesAbility& a) { abilities.append(SpeciesAbility(pokemod, a, getNewAbilityId())); return abilities[getAbilityCount() - 1]; } void PokeMod::Species::deleteAbility(const unsigned i) throw(IndexException) { if (getAbilityCount() <= i) throw(IndexException("Species")); abilities.removeAt(i); } const PokeMod::SpeciesEvolution& PokeMod::Species::getEvolution(const unsigned i) const throw(IndexException) { if (getEvolutionCount() <= i) throw(IndexException("Species")); return evolutions.at(i); } PokeMod::SpeciesEvolution& PokeMod::Species::getEvolution(const unsigned i) throw(IndexException) { if (getEvolutionCount() <= i) throw(IndexException("Species")); return evolutions[i]; } const PokeMod::SpeciesEvolution& PokeMod::Species::getEvolutionByID(const unsigned i) const throw(IndexException) { return getEvolution(getEvolutionIndex(i)); } PokeMod::SpeciesEvolution& PokeMod::Species::getEvolutionByID(const unsigned i) throw(IndexException) { return getEvolution(getEvolutionIndex(i)); } unsigned PokeMod::Species::getEvolutionIndex(const unsigned _id) const { for (unsigned i = 0; i < getEvolutionCount(); ++i) { if (evolutions[i].getId() == _id) return i; } return UINT_MAX; } unsigned PokeMod::Species::getEvolutionCount() const { return evolutions.size(); } PokeMod::SpeciesEvolution& PokeMod::Species::newEvolution() { evolutions.append(SpeciesEvolution(pokemod, getNewEvolutionId())); return evolutions[getEvolutionCount() - 1]; } PokeMod::SpeciesEvolution& PokeMod::Species::newEvolution(const QString& fname) { evolutions.append(SpeciesEvolution(pokemod, fname, getNewEvolutionId())); return evolutions[getEvolutionCount() - 1]; } PokeMod::SpeciesEvolution& PokeMod::Species::newEvolution(const SpeciesEvolution& e) { evolutions.append(SpeciesEvolution(pokemod, e, getNewEvolutionId())); return evolutions[getEvolutionCount() - 1]; } void PokeMod::Species::deleteEvolution(const unsigned i) throw(IndexException) { if (getEvolutionCount() <= i) throw(IndexException("Species")); evolutions.removeAt(i); } const PokeMod::SpeciesItem& PokeMod::Species::getItem(const unsigned i) const throw(IndexException) { if (getItemCount() <= i) throw(IndexException("Species")); return items.at(i); } PokeMod::SpeciesItem& PokeMod::Species::getItem(const unsigned i) throw(IndexException) { if (getItemCount() <= i) throw(IndexException("Species")); return items[i]; } const PokeMod::SpeciesItem& PokeMod::Species::getItemByID(const unsigned i) const throw(IndexException) { return getItem(getItemIndex(i)); } PokeMod::SpeciesItem& PokeMod::Species::getItemByID(const unsigned i) throw(IndexException) { return getItem(getItemIndex(i)); } unsigned PokeMod::Species::getItemIndex(const unsigned _id) const { for (unsigned i = 0; i < getItemCount(); ++i) { if (items[i].getId() == _id) return i; } return UINT_MAX; } unsigned PokeMod::Species::getItemCount() const { return items.size(); } PokeMod::SpeciesItem& PokeMod::Species::newItem() { items.append(SpeciesItem(pokemod, getNewItemId())); return items[getItemCount() - 1]; } PokeMod::SpeciesItem& PokeMod::Species::newItem(const QString& fname) { items.append(SpeciesItem(pokemod, fname, getNewItemId())); return items[getItemCount() - 1]; } PokeMod::SpeciesItem& PokeMod::Species::newItem(const SpeciesItem& i) { items.append(SpeciesItem(pokemod, i, getNewItemId())); return items[getItemCount() - 1]; } void PokeMod::Species::deleteItem(const unsigned i) throw(IndexException) { if (getItemCount() <= i) throw(IndexException("Species")); items.removeAt(i); } const PokeMod::SpeciesMove& PokeMod::Species::getMove(const unsigned i) const throw(IndexException) { if (getMoveCount() <= i) throw(IndexException("Species")); return moves.at(i); } PokeMod::SpeciesMove& PokeMod::Species::getMove(const unsigned i) throw(IndexException) { if (getMoveCount() <= i) throw(IndexException("Species")); return moves[i]; } const PokeMod::SpeciesMove& PokeMod::Species::getMoveByID(const unsigned i) const throw(IndexException) { return getMove(getMoveIndex(i)); } PokeMod::SpeciesMove& PokeMod::Species::getMoveByID(const unsigned i) throw(IndexException) { return getMove(getMoveIndex(i)); } unsigned PokeMod::Species::getMoveIndex(const unsigned _id) const { for (unsigned i = 0; i < getMoveCount(); ++i) { if (moves[i].getId() == _id) return i; } return UINT_MAX; } unsigned PokeMod::Species::getMoveCount() const { return moves.size(); } PokeMod::SpeciesMove& PokeMod::Species::newMove() { moves.append(SpeciesMove(pokemod, getNewMoveId())); return moves[getMoveCount() - 1]; } PokeMod::SpeciesMove& PokeMod::Species::newMove(const QString& fname) { moves.append(SpeciesMove(pokemod, fname, getNewMoveId())); return moves[getMoveCount() - 1]; } PokeMod::SpeciesMove& PokeMod::Species::newMove(const SpeciesMove& m) { moves.append(SpeciesMove(pokemod, m, getNewMoveId())); return moves[getMoveCount() - 1]; } void PokeMod::Species::deleteMove(const unsigned i) throw(IndexException) { if (getMoveCount() <= i) throw(IndexException("Species")); moves.removeAt(i); } PokeMod::Species& PokeMod::Species::operator=(const Species& rhs) { if (this == &rhs) return *this; name = rhs.name; for (unsigned i = 0; i < ST_End_GSC; ++i) { baseStats[i] = rhs.baseStats[i]; effortValues[i] = rhs.effortValues[i]; } growth = rhs.growth; experienceValue = rhs.experienceValue; catchValue = rhs.catchValue; runChance = rhs.runChance; itemChance = rhs.itemChance; pokedexNumber = rhs.pokedexNumber; weight = rhs.weight; heightFeet = rhs.heightFeet; heightInches = rhs.heightInches; pokedexEntry = rhs.pokedexEntry; genderFactor = rhs.genderFactor; eggSpecies = rhs.eggSpecies; eggSteps = rhs.eggSteps; nidoranGroup = rhs.nidoranGroup; types = rhs.types; eggGroups = rhs.eggGroups; for (unsigned i = 0; i < rhs.getAbilityCount(); ++i) newAbility(rhs.getAbility(i)); for (unsigned i = 0; i < rhs.getEvolutionCount(); ++i) newEvolution(rhs.getEvolution(i)); for (unsigned i = 0; i < rhs.getItemCount(); ++i) newItem(rhs.getItem(i)); for (unsigned i = 0; i < rhs.getMoveCount(); ++i) newMove(rhs.getMove(i)); return *this; }