diff options
Diffstat (limited to 'pokemod/Nature.cpp')
| -rw-r--r-- | pokemod/Nature.cpp | 155 |
1 files changed, 69 insertions, 86 deletions
diff --git a/pokemod/Nature.cpp b/pokemod/Nature.cpp index fa52ef43..c1b0f834 100644 --- a/pokemod/Nature.cpp +++ b/pokemod/Nature.cpp @@ -1,155 +1,138 @@ -///////////////////////////////////////////////////////////////////////////// -// 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 <http://www.gnu.org/licenses/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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/>. + */ + +// Pokemod includes #include "Pokemod.h" + +// Header include #include "Nature.h" -Nature::Nature(const Pokemod* par, const int _id) : - Object("Nature", par, _id), - name(""), - weight(1) +Nature::Nature(const Pokemod* pokemod, const int id) : + Object("Nature", pokemod, id), + m_name(""), + m_weight(1) { for (int i = 0; i < Pokemod::ST_End_GSC; ++i) - stats[i].set(1, 1, Frac::Improper); + m_stats[i].set(1, 1, Frac::Improper); } -Nature::Nature(const Pokemod* par, const Nature& n, const int _id) : - Object("Nature", par, _id) +Nature::Nature(const Pokemod* pokemod, const Nature& nature, const int id) : + Object("Nature", pokemod, id) { - *this = n; + *this = nature; } -Nature::Nature(const Pokemod* par, const QString& fname, const int _id) : - Object("Nature", par, _id) +Nature::Nature(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Nature", pokemod, id) { - load(fname, _id); + load(fileName, 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(QString("---Nature \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } - if (!weight) + if (!m_weight) { - pokemod->validationMsg("Weight is not valid"); + pokemod()->validationMsg("Weight is not valid"); valid = false; } return valid; } -void Nature::load(const QString& fname, const int _id) throw(Exception) +void Nature::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name); + ini.getValue("name", m_name); for (int k = 0; k < Pokemod::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); + m_stats[k].set(1, 1, true); } - ini.getValue("weight", weight); + ini.getValue("weight", m_weight); } void Nature::save() const throw(Exception) { Ini ini; - ini.addField("name", name); + ini.addField("name", m_name); for (int i = 0; i < Pokemod::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(QString("stat-%1-n").arg(i), m_stats[i].numerator()); + ini.addField(QString("stat-%1-d").arg(i), m_stats[i].denominator()); } - ini.addField("weight", weight); - ini.save(QString("%1/nature/%2.pini").arg(pokemod->getPath()).arg(name)); -} - -void Nature::setName(const QString& n) -{ - name = n; + ini.addField("weight", m_weight); + ini.save(QString("%1/nature/%2.pini").arg(pokemod()->path()).arg(m_name)); } -void Nature::setStat(const int s, const int n, const int d) throw(Exception) +void Nature::setName(const QString& name) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - stats[s].set(n, d); + m_name = name; } -void Nature::setStatNum(const int s, const int n) throw(Exception) +void Nature::setStat(const int stat, const int numerator, const int denominator) throw(Exception) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - stats[s].setNum(n); + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) + throw(BoundsException(className(), "stat")); + m_stats[stat].set(numerator, denominator); } -void Nature::setStatDenom(const int s, const int d) throw(Exception) +void Nature::setWeight(const int weight) throw(BoundsException) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::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; + if (!weight) + throw(BoundsException(className(), "weight")); + m_weight = weight; } -QString Nature::getName() const +QString Nature::name() const { - return name; + return m_name; } -Frac Nature::getStat(const int s) const throw(BoundsException) +Frac Nature::stat(const int stat) const throw(BoundsException) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - return stats[s]; + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) + throw(BoundsException(className(), "stat")); + return m_stats[stat]; } -int Nature::getWeight() const +int Nature::weight() const { - return weight; + return m_weight; } Nature& Nature::operator=(const Nature& rhs) { if (this == &rhs) return *this; - name = rhs.name; + m_name = rhs.m_name; for (int i = 0; i < Pokemod::ST_End_GSC; ++i) - stats[i] = rhs.stats[i]; - weight = rhs.weight; + m_stats[i] = rhs.m_stats[i]; + m_weight = rhs.m_weight; return *this; } |
