diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-09-21 15:36:22 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-09-21 15:36:22 +0000 |
| commit | 5b55d13ead7e352ee1feaae72009e8abf5bd071a (patch) | |
| tree | 6c2838312dd7f42769280e24e8abc16b53c165cb /pokemod/Nature.cpp | |
| parent | e94d9893b8753e72adb92b2c5eb203830ddf641c (diff) | |
[FIX] Neural Network methods complete
[FIX] Wrapped Node up into the layer
[FIX] Wrapped NatureEffect into Nature
[FIX] Getting around to fixing up the design of the PokéMod stuff
[FIX] Creating new subclasses now returns pointer to new subclass
[FIX] Simplified interfaces
[FIX] Minor style issues
[FIX] Renamed CoinItem to CoinListObject
[FIX] Renamed MapTrainerTeam to MapTrainerPokemon
[FIX] Renamed MapWildPokemon to MapWildListPokemon
[FIX] Moved global enums to relevant classes
[FIX] Removed general logging features
[DEL] pokemod/Debug.{h, cpp}
[DEL] pokemod/Path.{h, cpp}
[FIX] Using QFile rather than custom Path class for checking for files
[FIX] Set* methods now return a bool to let the caller know if anything actually changed (if it can fail, otherwise it is void)
[ADD] Compliation without errors is required for pokemod from now on before commits
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@24 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Nature.cpp')
| -rw-r--r-- | pokemod/Nature.cpp | 284 |
1 files changed, 125 insertions, 159 deletions
diff --git a/pokemod/Nature.cpp b/pokemod/Nature.cpp index 86a874ca..816d005d 100644 --- a/pokemod/Nature.cpp +++ b/pokemod/Nature.cpp @@ -1,159 +1,125 @@ -/////////////////////////////////////////////////////////////////////////////
-// Name: pokemod/Nature.cpp
-// Purpose: Define a nature that Pokémon can possess
-// Author: Ben Boeckel
-// Modified by: Ben Boeckel
-// Created: Sun Mar 18 22:58:48 2007
-// Copyright: ©2007 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 "Nature.h"
-
-PokeGen::PokeMod::Nature::Nature(const Pokemod *par, const unsigned _id) :
- name("")
-{
- LogCtor("Nature", _id);
- for (unsigned i = 0; i < STH_END_GSC; ++i)
- stats[i].Set(1, 1, true);
- id = _id;
- pokemod = par;
-}
-
-PokeGen::PokeMod::Nature::Nature(const Pokemod *par, Ini &ini, const unsigned _id)
-{
- LogCtorIni("Nature", _id);
- pokemod = par;
- ImportIni(ini, _id);
- if (id == UINT_MAX)
- LogIdError("Nature");
-}
-
-PokeGen::PokeMod::Nature::~Nature()
-{
- LogDtor("Nature", id, name);
-}
-
-void PokeGen::PokeMod::Nature::Validate()
-{
- LogValidateStart("Nature", id, name);
- if (name == "")
- {
- LogVarNotSet("Nature", id, "name");
- isValid = false;
- }
- LogValidateOver("Nature", id, isValid, name);
-}
-
-void PokeGen::PokeMod::Nature::ImportIni(Ini &ini, const unsigned _id)
-{
- LogImportStart("Nature");
- if (_id == UINT_MAX)
- {
- ini.GetValue("id", id);
- if (id == UINT_MAX)
- LogIdNotFound("Nature");
- }
- else
- id = _id;
- unsigned i;
- unsigned j;
- ini.GetValue("name", name);
- for (unsigned k = 0; k < STH_END_GSC; ++k)
- {
- ini.GetValue(QString("stat-%u-n", k), i, 1);
- ini.GetValue(QString("stat-%u-n", k), j, 1);
- stats[k].Set(1, 1, true);
- }
- LogImportOver("Nature");
-}
-
-void PokeGen::PokeMod::Nature::ExportIni(QFile &fout) const
-{
- LogExportStart("Nature", id, name);
- Ini exNature("nature");
- exNature.AddField("name", name);
- for (unsigned i = 0; i < STH_END_GSC; ++i)
- {
- exNature.AddField(QString("stat-%u-n", i), stats[i].GetNum());
- exNature.AddField(QString("stat-%u-d", i), stats[i].GetNum());
- }
- exNature.Export(fout);
- LogExportOver("Nature", id, name);
-}
-
-void PokeGen::PokeMod::Nature::SetName(const QString &n)
-{
- LogSetVar("Nature", id, "name", n);
- name = n;
-}
-
-void PokeGen::PokeMod::Nature::SetStat(const unsigned s, const Frac &m)
-{
- LogSetVar("Nature", id, QString("stat[%u]", s), m.GetNum(), m.GetDenom(), name);
- if (s < (pokemod->IsSpecialSplit() ? STH_END_GSC : STH_END_RBY))
- stats[s] = m;
-}
-
-void PokeGen::PokeMod::Nature::SetStat(const unsigned s, const unsigned n, const unsigned d)
-{
- LogSetVar("Nature", id, QString("stat[%u]", s), n, d, name);
- if (s < (pokemod->IsSpecialSplit() ? STH_END_GSC : STH_END_RBY))
- stats[s].Set(n, d);
-}
-
-void PokeGen::PokeMod::Nature::SetStatNum(const unsigned s, const unsigned n)
-{
- LogSetVar("Nature", id, QString("stat[%u] numerator", s), n, name);
- if (s < (pokemod->IsSpecialSplit() ? STH_END_GSC : STH_END_RBY))
- stats[s].SetNum(n);
-}
-
-void PokeGen::PokeMod::Nature::SetStatDenom(const unsigned s, const unsigned d)
-{
- LogSetVar("Nature", id, QString("stat[%u] denominator", s), d, name);
- if (s < (pokemod->IsSpecialSplit() ? STH_END_GSC : STH_END_RBY))
- stats[s].SetDenom(d);
-}
-
-QString PokeGen::PokeMod::Nature::GetName() const
-{
- LogFetchVar("Nature", id, "name", name);
- return name;
-}
-
-PokeGen::PokeMod::Frac PokeGen::PokeMod::Nature::GetStat(const unsigned s) const
-{
- LogFetchVar("Nature", id, QString("stat[%u]", s), 0, name);
- if (s < (pokemod->IsSpecialSplit() ? STH_END_GSC : STH_END_RBY))
- return stats[s];
- return Frac(1, 1, true);
-}
-
-unsigned PokeGen::PokeMod::Nature::GetStatNum(const unsigned s) const
-{
- LogFetchVar("Nature", id, QString("stat[%u] numerator", s), 0, name);
- if (s < (pokemod->IsSpecialSplit() ? STH_END_GSC : STH_END_RBY))
- return stats[s].GetNum();
- return 1;
-}
-
-unsigned PokeGen::PokeMod::Nature::GetStatDenom(const unsigned s) const
-{
- LogFetchVar("Nature", id, QString("stat[%u] denominator", s), 0, name);
- if (s < (pokemod->IsSpecialSplit() ? STH_END_GSC : STH_END_RBY))
- return stats[s].GetDenom();
- return 1;
-}
+///////////////////////////////////////////////////////////////////////////// +// Name: pokemod/Nature.cpp +// Purpose: Define a nature that Pokémon can possess +// Author: Ben Boeckel +// Modified by: Ben Boeckel +// Created: Sun Mar 18 22:58:48 2007 +// Copyright: ©2007 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 "Nature.h" + +PokeGen::PokeMod::Nature::Nature(const Pokemod* par, const unsigned _id) : + Object(_id, par), + name("") +{ + for (unsigned i = 0; i < ST_End_GSC; ++i) + stats[i].Set(1, 1, true); +} + +PokeGen::PokeMod::Nature::Nature(const Pokemod* par, Ini& ini, const unsigned _id) : + Object(_id, par) +{ + ImportIni(ini, _id); +} + +bool PokeGen::PokeMod::Nature::Validate() +{ + pokemod->ValidationMsg(QString("---Nature \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); + if (name == "") + { + pokemod->ValidationMsg("Name is not defined"); + isValid = false; + } + return isValid; +} + +void PokeGen::PokeMod::Nature::ImportIni(Ini& ini, const unsigned _id) +{ + if (_id == UINT_MAX) + ini.GetValue("id", id); + else + id = _id; + unsigned i; + unsigned j; + ini.GetValue("name", name); + for (unsigned 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); + } +} + +void PokeGen::PokeMod::Nature::ExportIni(QFile& fout) const +{ + Ini exNature("nature"); + exNature.AddField("name", name); + for (unsigned i = 0; i < ST_End_GSC; ++i) + { + exNature.AddField(QString("stat-%1-n").arg(i), stats[i].GetNum()); + exNature.AddField(QString("stat-%1-d").arg(i), stats[i].GetNum()); + } + exNature.Export(fout); +} + +void PokeGen::PokeMod::Nature::SetName(const QString& n) +{ + name = n; +} + +bool PokeGen::PokeMod::Nature::SetStat(const unsigned s, const unsigned n, const unsigned d) +{ + if (s < (pokemod->IsSpecialSplit() ? ST_End_GSC : ST_End_RBY)) + return stats[s].Set(n, d); + return false; +} + +bool PokeGen::PokeMod::Nature::SetStatNum(const unsigned s, const unsigned n) +{ + if (s < (pokemod->IsSpecialSplit() ? ST_End_GSC : ST_End_RBY)) + return stats[s].SetNum(n); + return false; +} + +bool PokeGen::PokeMod::Nature::SetStatDenom(const unsigned s, const unsigned d) +{ + if (s < (pokemod->IsSpecialSplit() ? ST_End_GSC : ST_End_RBY)) + return stats[s].SetDenom(d); + return false; +} + +QString PokeGen::PokeMod::Nature::GetName() const +{ + return name; +} + +PokeGen::PokeMod::Frac PokeGen::PokeMod::Nature::GetStat(const unsigned s) const +{ + if (s < (pokemod->IsSpecialSplit() ? ST_End_GSC : ST_End_RBY)) + return stats[s]; + return Frac(1, 1, true); +} + +unsigned PokeGen::PokeMod::Nature::GetStatNum(const unsigned s) const +{ + return GetStat(s).GetNum(); +} + +unsigned PokeGen::PokeMod::Nature::GetStatDenom(const unsigned s) const +{ + return GetStat(s).GetDenom(); +} |
