summaryrefslogtreecommitdiffstats
path: root/pokemod/Status.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2007-06-02 18:12:48 +0000
committerBen Boeckel <MathStuf@gmail.com>2007-06-02 18:12:48 +0000
commitc9afda3ab74614fb36986f96b7972c082f275eca (patch)
tree1b7c0b31950597d6ed562d94158dd3f8701496da /pokemod/Status.cpp
parentf71140fae5218ee9839ffcd4ec83abfded5124f4 (diff)
downloadsigen-c9afda3ab74614fb36986f96b7972c082f275eca.tar.gz
sigen-c9afda3ab74614fb36986f96b7972c082f275eca.tar.xz
sigen-c9afda3ab74614fb36986f96b7972c082f275eca.zip
Finished off all PokeMod classes, added move validations, fixed up some GUI, various other fixes
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@18 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Status.cpp')
-rw-r--r--pokemod/Status.cpp381
1 files changed, 381 insertions, 0 deletions
diff --git a/pokemod/Status.cpp b/pokemod/Status.cpp
new file mode 100644
index 00000000..d867a436
--- /dev/null
+++ b/pokemod/Status.cpp
@@ -0,0 +1,381 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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 2 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Status.h"
+
+extern PokeGen::PokeMod::Pokemod curPokeMod;
+
+PokeGen::PokeMod::Status::Status(const unsigned _id) :
+ name(""),
+ abbreviation(""),
+ verb(""),
+ afterSwitch(UINT_MAX),
+ afterBattle(UINT_MAX),
+ maxTurns(0),
+ catchBonus(0)
+{
+ LogCtor("Status", id);
+ id = _id;
+}
+
+PokeGen::PokeMod::Status::Status(Ini &ini, const unsigned _id)
+{
+ LogCtorIni("Status", id);
+ 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", name);
+ isValid = false;
+ }
+ if (abbreviation == "")
+ LogVarNotSet("Status", id, "abbreviation", name);
+ else if (4 <= abbreviation.length())
+ LogVarNotValid("Status", id, "abbreviation", name);
+ if (verb == "")
+ LogVarNotSet("Status", id, "verb", name);
+ if (afterSwitch == UINT_MAX)
+ LogVarNotSet("Status", id, "afterSwitch", name);
+ else if (!curPokeMod.GetStatus(afterSwitch))
+ {
+ LogVarNotValid("Status", id, "afterSwitch", name);
+ isValid = false;
+ }
+ if (afterBattle == UINT_MAX)
+ LogVarNotSet("Status", id, "afterBattle", name);
+ else if (!curPokeMod.GetStatus(afterBattle))
+ {
+ LogVarNotValid("Status", id, "afterBattle", name);
+ isValid = false;
+ }
+ // Check if there are any effects defined
+ if (GetStatusEffectCount())
+ {
+ // Validate each effect
+ for (std::vector<StatusEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
+ {
+ LogSubmoduleIterate("Status", id, "effect", i->GetId(), name);
+ // If an effect isn't valid, neither is the Status
+ if (!i->IsValid())
+ isValid = false;
+ }
+ }
+ else
+ {
+ LogSubmoduleEmpty("Status", id, "effect", name);
+ isValid = false;
+ }
+ LogValidateOver("Status", id, isValid, name);
+}
+
+#ifdef PG_DEBUG_WINDOW
+void PokeGen::PokeMod::Status::Validate(const wxListBox &output)
+{
+ LogValidateStart("Status", id, name);
+ if (name == "")
+ {
+ LogVarNotSet("Status", id, "Name", name);
+ output.Append(ConsoleLogVarNotSet("Status", id, "Name", name));
+ isValid = false;
+ }
+ if (abbreviation == "")
+ {
+ LogVarNotSet("Status", id, "abbreviation", name);
+ output.Append(ConsoleLogVarNotSetW("Status", id, "abbreviation", name));
+ }
+ else if (4 <= abbreviation.length())
+ {
+ LogVarNotValid("Status", id, "abbreviation", name);
+ output.Append(ConsoleLogVarNotValidW("Status", id, "abbreviation", name));
+ }
+ if (verb == "")
+ {
+ LogVarNotSet("Status", id, "verb", name);
+ output.Append(ConsoleLogVarNotSetW("Status", id, "verb", name));
+ }
+ if (afterSwitch == UINT_MAX)
+ {
+ LogVarNotSet("Status", id, "afterSwitch", name);
+ output.Append(ConsoleLogVarNotSetW("Status", id, "afterSwitch", name));
+ }
+ else if (!curPokeMod.GetStatus(afterSwitch))
+ {
+ LogVarNotValid("Status", id, "afterSwitch", name);
+ output.Append(ConsoleLogVarNotValid("Status", id, "afterSwitch", name));
+ isValid = false;
+ }
+ if (afterBattle == UINT_MAX)
+ {
+ LogVarNotSet("Status", id, "afterBattle", name);
+ output.Append(ConsoleLogVarNotSetW("Status", id, "afterBattle", name));
+ }
+ else if (!curPokeMod.GetStatus(afterBattle))
+ {
+ LogVarNotValid("Status", id, "afterBattle", name);
+ output.Append(ConsoleLogVarNotValid("Status", id, "afterBattle", name));
+ isValid = false;
+ }
+ // Check if there are any effects defined
+ if (GetStatusEffectCount())
+ {
+ // Validate each effect
+ for (std::vector<StatusEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
+ {
+ LogSubmoduleIterate("Status", id, "effect", i->GetId(), name);
+ // If an effect isn't valid, neither is the Status
+ if (!i->IsValid())
+ isValid = false;
+ }
+ }
+ else
+ {
+ LogSubmoduleEmpty("Status", id, "effect", id, name);
+ output.Append(ConsoleLogSubmoduleEmpty("Status", id, "effect", name));
+ isValid = false;
+ }
+ LogValidateOver("Status", id, isValid, name);
+}
+#endif
+
+void PokeGen::PokeMod::Status::ImportIni(Ini &ini, const unsigned _id)
+{
+ LogImportStart("Status");
+ if (_id == UINT_MAX)
+ {
+ ini.GetValue("id", id);
+ // Was there an id associated with the element?
+ 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(std::ofstream &fout) const
+{
+ LogExportStart("Status", id, name);
+ // Make elements
+ 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 (std::vector<StatusEffect>::const_iterator i = effects.begin(); i != effects.end(); ++i)
+ i->ExportIni(fout, name);
+ LogExportOver("Status", id, name);
+}
+
+void PokeGen::PokeMod::Status::SetName(const String &n)
+{
+ LogSetVar("Status", id, "name", n);
+ name = n;
+}
+
+void PokeGen::PokeMod::Status::SetAbbreviation(const String &a)
+{
+ LogSetVar("Status", id, "abbreviation", a, name);
+ if (a.length() < 4)
+ abbreviation = a;
+}
+
+void PokeGen::PokeMod::Status::SetVerb(const String &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) || curPokeMod.GetStatus(a))
+ afterSwitch = a;
+}
+
+void PokeGen::PokeMod::Status::SetAfterSwitch(const String &a)
+{
+ LogSetVar("Status", id, "afterSwitch string", a, name);
+ if (a == "Clear")
+ afterSwitch = UINT_MAX;
+ else if (const Status *s = curPokeMod.GetStatus(a))
+ afterSwitch = s->GetId();
+}
+
+void PokeGen::PokeMod::Status::SetAfterBattle(const unsigned a)
+{
+ LogSetVar("Status", id, "afterBattle", a, name);
+ if ((a == UINT_MAX) || curPokeMod.GetStatus(a))
+ afterBattle = a;
+}
+
+void PokeGen::PokeMod::Status::SetAfterBattle(const String &a)
+{
+ LogSetVar("Status", id, "afterBattle string", a, name);
+ if (a == "Clear")
+ afterSwitch = UINT_MAX;
+ else if (const Status *s = curPokeMod.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;
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Status::GetName() const
+{
+ LogFetchVar("Status", id, "name", name);
+ return name;
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Status::GetAbbreviation() const
+{
+ LogFetchVar("Status", id, "abbreviation", abbreviation, name);
+ return abbreviation;
+}
+
+PokeGen::PokeMod::String 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;
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Status::GetAfterSwitchString() const
+{
+ LogFetchVar("Status", id, "afterSwitch string", afterSwitch, name);
+ if (const Status *s = curPokeMod.GetStatus(afterSwitch))
+ return s->GetName();
+ return "";
+}
+
+unsigned PokeGen::PokeMod::Status::GetAfterBattle() const
+{
+ LogFetchVar("Status", id, "afterBattle", afterBattle, name);
+ return afterBattle;
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Status::GetAfterBattleString() const
+{
+ LogFetchVar("Status", id, "afterBattle string", afterBattle, name);
+ if (const Status *s = curPokeMod.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;
+ // Find the first unused ID in the vector
+ for (; i < GetStatusEffectCount(); ++i)
+ {
+ if (!GetStatusEffect(i))
+ break;
+ }
+ StatusEffect newStatusEffect(i);
+ if (ini)
+ newStatusEffect.ImportIni(*ini);
+ LogSubmoduleNew("Status", id, "effect", i, name);
+ effects.push_back(newStatusEffect);
+}
+
+void PokeGen::PokeMod::Status::DeleteStatusEffect(const unsigned _id)
+{
+ LogSubmoduleRemoveStart("Status", id, "effect", _id, name);
+ for (std::vector<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);
+}