///////////////////////////////////////////////////////////////////////////// // Name: pokemod/Nature.cpp // Purpose: Define a nature that species can possess // Author: Ben Boeckel // Modified by: Ben Boeckel // Created: Sun Mar 18 22:58:48 2007 // 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 // 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 . ///////////////////////////////////////////////////////////////////////////// #include "Pokemod.h" #include "Nature.h" Nature::Nature(const Pokemod* par, const int _id) : Object("Nature", par, _id), name(""), weight(1) { for (int i = 0; i < ST_End_GSC; ++i) stats[i].set(1, 1, Frac::Improper); } Nature::Nature(const Pokemod* par, const Nature& n, const int _id) : Object("Nature", par, _id) { *this = n; } Nature::Nature(const Pokemod* par, const QString& fname, const int _id) : Object("Nature", par, _id) { load(fname, _id); } bool Nature::validate() const { bool valid = true; pokemod->validationMsg(QString("---Nature \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); if (name == "") { pokemod->validationMsg("Name is not defined"); valid = false; } if (!weight) { pokemod->validationMsg("Weight is not valid"); valid = false; } return valid; } void Nature::load(const QString& fname, const int _id) throw(Exception) { Ini ini(fname); if (_id == -1) ini.getValue("id", id); else id = _id; int i; int j; ini.getValue("name", name); for (int k = 0; k < ST_End_GSC; ++k) { ini.getValue(QString("stat-%1-n").arg(k), i, 1); ini.getValue(QString("stat-%1-n").arg(k), j, 1); stats[k].set(1, 1, true); } ini.getValue("weight", weight); } void Nature::save() const throw(Exception) { Ini ini; ini.addField("name", name); for (int i = 0; i < ST_End_GSC; ++i) { ini.addField(QString("stat-%1-n").arg(i), stats[i].getNum()); ini.addField(QString("stat-%1-d").arg(i), stats[i].getNum()); } ini.addField("weight", weight); ini.save(QString("%1/nature/%2.pini").arg(pokemod->getPath()).arg(name)); } void Nature::setName(const QString& n) { name = n; } void Nature::setStat(const int s, const int n, const int d) throw(Exception) { if ((pokemod->getRules()->getSpecialSplit() ? ST_End_GSC : ST_End_RBY) <= s) throw(BoundsException(className, "stat")); stats[s].set(n, d); } void Nature::setStatNum(const int s, const int n) throw(Exception) { if ((pokemod->getRules()->getSpecialSplit() ? ST_End_GSC : ST_End_RBY) <= s) throw(BoundsException(className, "stat")); stats[s].setNum(n); } void Nature::setStatDenom(const int s, const int d) throw(Exception) { if ((pokemod->getRules()->getSpecialSplit() ? ST_End_GSC : ST_End_RBY) <= s) throw(BoundsException(className, "stat")); stats[s].setDenom(d); } void Nature::setWeight(const int w) throw(BoundsException) { if (!w) throw(BoundsException(className, "weight")); weight = w; } QString Nature::getName() const { return name; } Frac Nature::getStat(const int s) const throw(BoundsException) { if ((pokemod->getRules()->getSpecialSplit() ? ST_End_GSC : ST_End_RBY) <= s) throw(BoundsException(className, "stat")); return stats[s]; } int Nature::getWeight() const { return weight; } Nature& Nature::operator=(const Nature& rhs) { if (this == &rhs) return *this; name = rhs.name; for (int i = 0; i < ST_End_GSC; ++i) stats[i] = rhs.stats[i]; weight = rhs.weight; return *this; }