summaryrefslogtreecommitdiffstats
path: root/pokemod/Status.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2007-09-21 15:36:22 +0000
committerBen Boeckel <MathStuf@gmail.com>2007-09-21 15:36:22 +0000
commit5b55d13ead7e352ee1feaae72009e8abf5bd071a (patch)
tree6c2838312dd7f42769280e24e8abc16b53c165cb /pokemod/Status.cpp
parente94d9893b8753e72adb92b2c5eb203830ddf641c (diff)
downloadsigen-5b55d13ead7e352ee1feaae72009e8abf5bd071a.tar.gz
sigen-5b55d13ead7e352ee1feaae72009e8abf5bd071a.tar.xz
sigen-5b55d13ead7e352ee1feaae72009e8abf5bd071a.zip
[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/Status.cpp')
-rw-r--r--pokemod/Status.cpp592
1 files changed, 259 insertions, 333 deletions
diff --git a/pokemod/Status.cpp b/pokemod/Status.cpp
index 75059ca7..7ea407e8 100644
--- a/pokemod/Status.cpp
+++ b/pokemod/Status.cpp
@@ -1,333 +1,259 @@
-/////////////////////////////////////////////////////////////////////////////
-// Name: pokemod/Status.cpp
-// Purpose: Define an Status that Pokémon can possess to add extra
-// dynamics to the battle system
-// Author: Ben Boeckel
-// Modified by: Ben Boeckel
-// Created: Sat June 2 2007 12:00:45
-// 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
-// MERCHANTStatus 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 "Status.h"
-
-PokeGen::PokeMod::Status::Status(const Pokemod *par, const unsigned _id) :
- name(""),
- abbreviation(""),
- verb(""),
- afterSwitch(UINT_MAX),
- afterBattle(UINT_MAX),
- maxTurns(0),
- catchBonus(0)
-{
- LogCtor("Status", id);
- id = _id;
- pokemod = par;
-}
-
-PokeGen::PokeMod::Status::Status(const Pokemod *par, Ini &ini, const unsigned _id)
-{
- LogCtorIni("Status", id);
- pokemod = par;
- ImportIni(ini, _id);
- if (id == UINT_MAX)
- LogIdError("Status");
-}
-
-PokeGen::PokeMod::Status::~Status()
-{
- LogDtor("Status", id, name);
-}
-
-void PokeGen::PokeMod::Status::Validate()
-{
- LogValidateStart("Status", id, name);
- if (name == "")
- {
- LogVarNotSet("Status", id, "name");
- isValid = false;
- }
- else if ((name == "Clear") || (name == "Any"))
- {
- LogVarNotValid("Status", id, "name", name);
- isValid = false;
- }
- if (abbreviation == "")
- LogVarNotSet("Status", id, "abbreviation", name);
- else if (4 <= abbreviation.length())
- {
- LogVarNotValid("Status", id, "abbreviation", name);
- isValid = false;
- }
- if (verb == "")
- LogVarNotSet("Status", id, "verb", name);
- if (afterSwitch == UINT_MAX)
- LogVarNotSet("Status", id, "afterSwitch", name);
- else if (!pokemod->GetStatus(afterSwitch))
- {
- LogVarNotValid("Status", id, "afterSwitch", name);
- isValid = false;
- }
- if (afterBattle == UINT_MAX)
- LogVarNotSet("Status", id, "afterBattle", name);
- else if (!pokemod->GetStatus(afterBattle))
- {
- LogVarNotValid("Status", id, "afterBattle", name);
- isValid = false;
- }
- if (GetStatusEffectCount())
- {
- QMap<unsigned, unsigned> idChecker;
- QMap<QString, unsigned> effectChecker;
- for (QList<StatusEffect>::Iterator i = effects.begin(); i != effects.end(); ++i)
- {
- LogSubmoduleIterate("Status", id, "effect", i->GetId(), name);
- if (!i->IsValid())
- isValid = false;
- ++idChecker[i->GetId()];
- ++effectChecker[i->GetEffectString()];
- }
- for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateId("Status", id, "effect", i.key(), name);
- isValid = false;
- }
- }
- for (QMap<QString, unsigned>::ConstIterator i = effectChecker.begin(); i != effectChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateSubmodule("Status", id, "effect", i.key(), name);
- isValid = false;
- }
- }
- }
- else
- {
- LogSubmoduleEmpty("Status", id, "effect", name);
- isValid = false;
- }
- LogValidateOver("Status", id, isValid, name);
-}
-
-void PokeGen::PokeMod::Status::ImportIni(Ini &ini, const unsigned _id)
-{
- LogImportStart("Status");
- if (_id == UINT_MAX)
- {
- ini.GetValue("id", id);
- if (id == UINT_MAX)
- LogIdNotFound("Status");
- }
- else
- id = _id;
- ini.GetValue("name", name);
- ini.GetValue("abbreviation", abbreviation);
- ini.GetValue("verb", verb);
- ini.GetValue("afterSwitch", afterSwitch);
- ini.GetValue("afterBattle", afterBattle);
- ini.GetValue("maxTurns", maxTurns, 0);
- ini.GetValue("catchBonus", catchBonus, 0);
- effects.clear();
- LogImportOver("Status", id, name);
-}
-
-void PokeGen::PokeMod::Status::ExportIni(QFile &fout) const
-{
- LogExportStart("Status", id, name);
- Ini exStatus("Status");
- exStatus.AddField("id", id);
- exStatus.AddField("name", name);
- exStatus.AddField("abbreviation", abbreviation);
- exStatus.AddField("verb", verb);
- exStatus.AddField("afterSwitch", afterSwitch);
- exStatus.AddField("afterBattle", afterBattle);
- exStatus.AddField("maxTurns", maxTurns);
- exStatus.AddField("catchBonus", catchBonus);
- exStatus.Export(fout);
- for (QList<StatusEffect>::ConstIterator i = effects.begin(); i != effects.end(); ++i)
- i->ExportIni(fout, name);
- LogExportOver("Status", id, name);
-}
-
-void PokeGen::PokeMod::Status::SetName(const QString &n)
-{
- LogSetVar("Status", id, "name", n);
- name = n;
-}
-
-void PokeGen::PokeMod::Status::SetAbbreviation(const QString &a)
-{
- LogSetVar("Status", id, "abbreviation", a, name);
- if (a.length() < 4)
- abbreviation = a;
-}
-
-void PokeGen::PokeMod::Status::SetVerb(const QString &v)
-{
- LogSetVar("Status", id, "verb", v, name);
- verb = v;
-}
-
-void PokeGen::PokeMod::Status::SetAfterSwitch(const unsigned a)
-{
- LogSetVar("Status", id, "afterSwitch", a, name);
- if ((a == UINT_MAX) || pokemod->GetStatus(a))
- afterSwitch = a;
-}
-
-void PokeGen::PokeMod::Status::SetAfterSwitch(const QString &a)
-{
- LogSetVar("Status", id, "afterSwitch string", a, name);
- if (a == "Clear")
- afterSwitch = UINT_MAX;
- else if (const Status *s = pokemod->GetStatus(a))
- afterSwitch = s->GetId();
-}
-
-void PokeGen::PokeMod::Status::SetAfterBattle(const unsigned a)
-{
- LogSetVar("Status", id, "afterBattle", a, name);
- if ((a == UINT_MAX) || pokemod->GetStatus(a))
- afterBattle = a;
-}
-
-void PokeGen::PokeMod::Status::SetAfterBattle(const QString &a)
-{
- LogSetVar("Status", id, "afterBattle string", a, name);
- if (a == "Clear")
- afterSwitch = UINT_MAX;
- else if (const Status *s = pokemod->GetStatus(a))
- afterBattle = s->GetId();
-}
-
-void PokeGen::PokeMod::Status::SetMaxTurns(const unsigned m)
-{
- LogSetVar("Status", id, "maxTurns", m, name);
- maxTurns = m;
-}
-
-void PokeGen::PokeMod::Status::SetCatchBonus(const unsigned c)
-{
- LogSetVar("Status", id, "catchBonus", c, name);
- catchBonus = c;
-}
-
-QString PokeGen::PokeMod::Status::GetName() const
-{
- LogFetchVar("Status", id, "name", name);
- return name;
-}
-
-QString PokeGen::PokeMod::Status::GetAbbreviation() const
-{
- LogFetchVar("Status", id, "abbreviation", abbreviation, name);
- return abbreviation;
-}
-
-QString PokeGen::PokeMod::Status::GetVerb() const
-{
- LogFetchVar("Status", id, "verb", verb, name);
- return verb;
-}
-
-unsigned PokeGen::PokeMod::Status::GetAfterSwitch() const
-{
- LogFetchVar("Status", id, "afterSwitch", afterSwitch, name);
- return afterSwitch;
-}
-
-QString PokeGen::PokeMod::Status::GetAfterSwitchString() const
-{
- LogFetchVar("Status", id, "afterSwitch string", afterSwitch, name);
- if (const Status *s = pokemod->GetStatus(afterSwitch))
- return s->GetName();
- return "";
-}
-
-unsigned PokeGen::PokeMod::Status::GetAfterBattle() const
-{
- LogFetchVar("Status", id, "afterBattle", afterBattle, name);
- return afterBattle;
-}
-
-QString PokeGen::PokeMod::Status::GetAfterBattleString() const
-{
- LogFetchVar("Status", id, "afterBattle string", afterBattle, name);
- if (const Status *s = pokemod->GetStatus(afterBattle))
- return s->GetName();
- return "";
-}
-
-unsigned PokeGen::PokeMod::Status::GetMaxTurns() const
-{
- LogFetchVar("Status", id, "maxTurns", maxTurns, name);
- return maxTurns;
-}
-
-unsigned PokeGen::PokeMod::Status::GetCatchBonus() const
-{
- LogFetchVar("Status", id, "catchBonus", catchBonus, name);
- return catchBonus;
-}
-
-const PokeGen::PokeMod::StatusEffect *PokeGen::PokeMod::Status::GetStatusEffect(const unsigned _id) const
-{
- LogSubmoduleFetch("Status", id, "effect", _id, name);
- for (unsigned i = 0; i < GetStatusEffectCount(); ++i)
- {
- if (effects[i].GetId() == _id)
- return &effects[i];
- }
- LogSubmoduleFetchFail("Status", id, "effect", _id, name);
- return NULL;
-}
-
-unsigned PokeGen::PokeMod::Status::GetStatusEffectCount() const
-{
- LogSubmoduleCount("Status", id, "effects", name);
- return effects.size();
-}
-
-void PokeGen::PokeMod::Status::NewStatusEffect(Ini *const ini)
-{
- unsigned i = 0;
- for (; i < GetStatusEffectCount(); ++i)
- {
- if (!GetStatusEffect(i))
- break;
- }
- StatusEffect newStatusEffect(i);
- if (ini)
- newStatusEffect.ImportIni(*ini);
- LogSubmoduleNew("Status", id, "effect", i, name);
- effects.append(newStatusEffect);
-}
-
-void PokeGen::PokeMod::Status::DeleteStatusEffect(const unsigned _id)
-{
- LogSubmoduleRemoveStart("Status", id, "effect", _id, name);
- for (QList<StatusEffect>::Iterator i = effects.begin(); i != effects.end(); ++i)
- {
- if (i->GetId() == _id)
- {
- LogSubmoduleRemoved("Status", id, "effect", _id, name);
- effects.erase(i);
- }
- }
- LogSubmoduleRemoveFail("Status", id, "effect", _id, name);
-}
+/////////////////////////////////////////////////////////////////////////////
+// Name: pokemod/Status.cpp
+// Purpose: Define an Status that Pokémon can possess to add extra
+// dynamics to the battle system
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Sat June 2 2007 12:00:45
+// 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
+// MERCHANTStatus 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 "Status.h"
+
+PokeGen::PokeMod::Status::Status(const Pokemod* par, const unsigned _id) :
+ Object(_id, par),
+ name(""),
+ abbreviation(""),
+ verb(""),
+ afterSwitch(UINT_MAX),
+ afterBattle(UINT_MAX),
+ maxTurns(0),
+ catchBonus(0)
+{
+}
+
+PokeGen::PokeMod::Status::Status(const Pokemod* par, Ini& ini, const unsigned _id) :
+ Object(_id, par)
+{
+ ImportIni(ini, _id);
+}
+
+bool PokeGen::PokeMod::Status::Validate()
+{
+ pokemod->ValidationMsg(QString("---Status \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg);
+ if (name == "")
+ {
+ pokemod->ValidationMsg("Name is not defined");
+ isValid = false;
+ }
+ else if ((name == "Clear") || (name == "Any"))
+ {
+ pokemod->ValidationMsg("Invalid name");
+ isValid = false;
+ }
+ if (abbreviation == "")
+ pokemod->ValidationMsg("Abbreviation is not defined");
+ else if (4 <= abbreviation.length())
+ {
+ pokemod->ValidationMsg("Abbreviation too long");
+ isValid = false;
+ }
+ if (verb == "")
+ pokemod->ValidationMsg("Verb is not defined", Pokemod::V_Warn);
+ if (afterSwitch == UINT_MAX)
+ pokemod->ValidationMsg("After switch status is not defined", Pokemod::V_Warn);
+ else if (pokemod->GetStatusByID(afterSwitch) == UINT_MAX)
+ {
+ pokemod->ValidationMsg("Invalid after switch status");
+ isValid = false;
+ }
+ if (afterBattle == UINT_MAX)
+ pokemod->ValidationMsg("After battle status is not defined", Pokemod::V_Warn);
+ else if (pokemod->GetStatusByID(afterBattle) == UINT_MAX)
+ {
+ pokemod->ValidationMsg("Invalid after battle abbreviation");
+ isValid = false;
+ }
+ if (GetEffectCount())
+ {
+ QMap<unsigned, unsigned> idChecker;
+ for (QList<StatusEffect>::Iterator i = effects.begin(); i != effects.end(); ++i)
+ {
+ if (!i->IsValid())
+ isValid = false;
+ ++idChecker[i->GetId()];
+ }
+ for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i)
+ {
+ if (1 < i.value())
+ {
+ pokemod->ValidationMsg(QString("There are %1 effects with id %2").arg(i.value()).arg(i.key()));
+ isValid = false;
+ }
+ }
+ }
+ else
+ {
+ pokemod->ValidationMsg("There are no effects");
+ isValid = false;
+ }
+ return isValid;
+}
+
+void PokeGen::PokeMod::Status::ImportIni(Ini& ini, const unsigned _id)
+{
+ if (_id == UINT_MAX)
+ ini.GetValue("id", id);
+ else
+ id = _id;
+ ini.GetValue("name", name);
+ ini.GetValue("abbreviation", abbreviation);
+ ini.GetValue("verb", verb);
+ ini.GetValue("afterSwitch", afterSwitch);
+ ini.GetValue("afterBattle", afterBattle);
+ ini.GetValue("maxTurns", maxTurns, 0);
+ ini.GetValue("catchBonus", catchBonus, 0);
+ effects.clear();
+}
+
+void PokeGen::PokeMod::Status::ExportIni(QFile& fout) const
+{
+ Ini exStatus("Status");
+ exStatus.AddField("id", id);
+ exStatus.AddField("name", name);
+ exStatus.AddField("abbreviation", abbreviation);
+ exStatus.AddField("verb", verb);
+ exStatus.AddField("afterSwitch", afterSwitch);
+ exStatus.AddField("afterBattle", afterBattle);
+ exStatus.AddField("maxTurns", maxTurns);
+ exStatus.AddField("catchBonus", catchBonus);
+ exStatus.Export(fout);
+ for (QList<StatusEffect>::ConstIterator i = effects.begin(); i != effects.end(); ++i)
+ i->ExportIni(fout, name);
+}
+
+void PokeGen::PokeMod::Status::SetName(const QString& n)
+{
+ name = n;
+}
+
+bool PokeGen::PokeMod::Status::SetAbbreviation(const QString& a)
+{
+ if (a.length() < 4)
+ abbreviation = a;
+ return (abbreviation == a);
+}
+
+void PokeGen::PokeMod::Status::SetVerb(const QString& v)
+{
+ verb = v;
+}
+
+bool PokeGen::PokeMod::Status::SetAfterSwitch(const unsigned a)
+{
+ if ((a == UINT_MAX) || (pokemod->GetStatusByID(a) != UINT_MAX))
+ afterSwitch = a;
+ return (afterSwitch == a);
+}
+
+bool PokeGen::PokeMod::Status::SetAfterBattle(const unsigned a)
+{
+ if ((a == UINT_MAX) || (pokemod->GetStatusByID(a) != UINT_MAX))
+ afterBattle = a;
+ return (afterBattle == a);
+}
+
+void PokeGen::PokeMod::Status::SetMaxTurns(const unsigned m)
+{
+ maxTurns = m;
+}
+
+void PokeGen::PokeMod::Status::SetCatchBonus(const unsigned c)
+{
+ catchBonus = c;
+}
+
+QString PokeGen::PokeMod::Status::GetName() const
+{
+ return name;
+}
+
+QString PokeGen::PokeMod::Status::GetAbbreviation() const
+{
+ return abbreviation;
+}
+
+QString PokeGen::PokeMod::Status::GetVerb() const
+{
+ return verb;
+}
+
+unsigned PokeGen::PokeMod::Status::GetAfterSwitch() const
+{
+ return afterSwitch;
+}
+
+unsigned PokeGen::PokeMod::Status::GetAfterBattle() const
+{
+ return afterBattle;
+}
+
+unsigned PokeGen::PokeMod::Status::GetMaxTurns() const
+{
+ return maxTurns;
+}
+
+unsigned PokeGen::PokeMod::Status::GetCatchBonus() const
+{
+ return catchBonus;
+}
+
+const PokeGen::PokeMod::StatusEffect* PokeGen::PokeMod::Status::GetEffect(const unsigned i) const
+{
+ if (i < GetEffectCount())
+ return &effects[i];
+ return NULL;
+}
+
+unsigned PokeGen::PokeMod::Status::GetEffectByID(const unsigned _id) const
+{
+ for (unsigned i = 0; i < GetEffectCount(); ++i)
+ {
+ if (effects[i].GetId() == _id)
+ return i;
+ }
+ return UINT_MAX;
+}
+
+unsigned PokeGen::PokeMod::Status::GetEffectCount() const
+{
+ return effects.size();
+}
+
+const PokeGen::PokeMod::StatusEffect* PokeGen::PokeMod::Status::NewEffect(Ini* const ini)
+{
+ unsigned i = 0;
+ for (; i < GetEffectCount(); ++i)
+ {
+ if (GetEffectByID(i) != UINT_MAX)
+ break;
+ }
+ StatusEffect newEffect(pokemod, i);
+ if (ini)
+ newEffect.ImportIni(*ini);
+ effects.append(newEffect);
+ return &effects[GetEffectCount() - 1];
+}
+
+bool PokeGen::PokeMod::Status::DeleteEffect(const unsigned i)
+{
+ if (i < GetEffectCount())
+ {
+ effects.erase(effects.begin() + i);
+ return true;
+ }
+ return false;
+}