summaryrefslogtreecommitdiffstats
path: root/pokemod
diff options
context:
space:
mode:
Diffstat (limited to 'pokemod')
-rw-r--r--pokemod/Ability.cpp187
-rw-r--r--pokemod/Ability.h67
-rw-r--r--pokemod/Author.cpp252
-rw-r--r--pokemod/Author.h71
-rw-r--r--pokemod/Badge.cpp285
-rw-r--r--pokemod/Badge.h78
-rw-r--r--pokemod/Debug.cpp87
-rw-r--r--pokemod/Debug.h279
-rw-r--r--pokemod/Flag.cpp97
-rw-r--r--pokemod/Flag.h52
-rw-r--r--pokemod/Frac.cpp172
-rw-r--r--pokemod/Frac.h62
-rw-r--r--pokemod/Matrix.cpp235
-rw-r--r--pokemod/Matrix.h67
-rw-r--r--pokemod/Nature.cpp181
-rw-r--r--pokemod/Nature.h66
-rw-r--r--pokemod/Object.cpp45
-rw-r--r--pokemod/Object.h59
-rw-r--r--pokemod/Path.cpp91
-rw-r--r--pokemod/Path.h49
-rw-r--r--pokemod/Point.cpp56
-rw-r--r--pokemod/Point.h69
-rw-r--r--pokemod/Ref.cpp36
-rw-r--r--pokemod/Ref.h384
-rw-r--r--pokemod/String.cpp133
-rw-r--r--pokemod/String.h60
-rw-r--r--pokemod/Xml.cpp492
-rw-r--r--pokemod/Xml.h88
-rw-r--r--pokemod/pokemod_inc.h56
29 files changed, 3856 insertions, 0 deletions
diff --git a/pokemod/Ability.cpp b/pokemod/Ability.cpp
new file mode 100644
index 00000000..4b5766a3
--- /dev/null
+++ b/pokemod/Ability.cpp
@@ -0,0 +1,187 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Ability.cpp
+// Purpose: Define an ability that Pokémon can possess to add extra
+// dynamics to the battle system
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Wed Feb 28 21:41:10 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Ability.h"
+
+PokeMod::Ability::Ability(unsigned _id)
+{
+ LogCtor("Ability", id);
+ name = "";
+ effects.clear();
+ id = _id;
+}
+
+PokeMod::Ability::Ability(XmlElement &xml, unsigned _id)
+{
+ LogCtorXml("Ability", id);
+ ImportXml(xml, _id);
+ if (id == UINT_MAX)
+ LogIdError("Ability");
+}
+
+PokeMod::Ability::~Ability()
+{
+ LogDtor("Ability", id, name));
+}
+
+#ifdef POKEMODR
+void PokeMod::Ability::Validate(wxListBox &output)
+#else
+void PokeMod::Ability::Validate()
+#endif
+{
+ isValid = true;
+ LogValidateStart("Ability", id, name);
+ // Make sure the name is set to something
+ if (name == "")
+ {
+ LogVarNotSet("Ability", "Name", id, name);
+# ifdef POKEMODR
+ output.Append(ConsoleLogVarNotSet("Ability", "Name", id, name));
+# endif
+ isValid = false;
+ }
+ // Check if there are any effects defined
+ if (GetAbilityEffectCount())
+ {
+ // Validate each effect
+ for (std::vector<AbilityEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
+ {
+ LogSubmoduleIterate("Ability", "effect", i->GetId(), id, name);
+ // If an effect isn't valid, neither is the ability
+ if (!i->IsValid())
+ isValid = false;
+ }
+ }
+ else
+ {
+ LogSubmoduleEmpty("Ability", "effect", id, name);
+# ifdef POKEMODR
+ output.Append(ConsoleLogSubmoduleEmpty("Ability", "effect", id, name));
+# endif
+ isValid = false;
+ }
+ LogValidationOver("Ability", isValid, id, name);
+}
+
+void PokeMod::Ability::ImportXml(XmlElement &xml, unsigned _id)
+{
+ LogImportStart("Ability");
+ String curName;
+ if (_id == UINT_MAX)
+ {
+ xml.GetValue(id);
+ // Was there an id associated with the element?
+ if (id == UINT_MAX)
+ LogIdNotFound("Ability");
+ }
+ else
+ id = _id;
+ name = "";
+ effects.clear();
+ xml.ClearCounter();
+ for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ {
+ curName = child->GetName();
+ if (curName == "name")
+ child->GetValue(name);
+ else if (curName == "effect")
+ effects.push_back(AbilityEffect(*child));
+ else
+ LogUnknownXml("Ability", curName);
+ }
+ LogImportOver("Ability", id, name);
+}
+
+XmlElement PokeMod::Ability::ExportXml()
+{
+ LogExportStart("Ability", id, name);
+ // Make elements
+ XmlElement exAbility("ability");
+ exAbility.AddElement("name", name);
+ for (std::vector<AbilityEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
+ exAbility.AddElement(i->ExportXml());
+ LogExportOver("Ability", id, name);
+ return exAbility;
+}
+
+void PokeMod::Ability::SetName(const String &n)
+{
+ LogSetVar("Ability", "name", id, INT_MIN, n);
+ name = n;
+}
+
+PokeMod::String PokeMod::Ability::GetName()
+{
+ LogFetchVar("Ability", "name", id, INT_MIN, name);
+ return name;
+}
+
+PokeMod::AbilityEffect *PokeMod::Ability::GetAbilityEffect(unsigned _id)
+{
+ LogSubmoduleFetch("Ability", "effect", _id, id, name);
+ for (unsigned i = 0; i < GetAbilityEffectCount(); ++i)
+ {
+ if (effects[i].GetId() == _id)
+ return &effects[i];
+ }
+ LogSubmodule("Ability", "effect", _id, id, name);
+ return NULL;
+}
+
+unsigned PokeMod::Ability::GetAbilityEffectCount()
+{
+ LogSubmoduleCount("Ability", "effects", id, name);
+ return effects.size();
+}
+
+void PokeMod::Ability::NewAbilityEffect(XmlElement *xml)
+{
+ unsigned i = 0;
+ // Find the first unused ID in the vector
+ for (; i < GetAbilityEffectCount(); ++i)
+ {
+ if (!GetAbilityEffect(i))
+ break;
+ }
+ AbilityEffect newAbilityEffect(i);
+ if (xml)
+ newAbilityEffect.ImportXml(*xml);
+ LogSubmoduleNew("Ability", "effect", i, id, name);
+ effects.push_back(newAbilityEffect);
+}
+
+void PokeMod::Ability::DeleteAbilityEffect(unsigned _id)
+{
+ LogSubmoduleRemoveStart("Ability", "effect", _id, id, name);
+ for (std::vector<AbilityEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
+ {
+ if (i->GetId() == _id)
+ {
+ LogSubmoduleRemoved("Ability", "effect", _id, id, name);
+ effects.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Ability", "effect", _id, id, name);
+}
diff --git a/pokemod/Ability.h b/pokemod/Ability.h
new file mode 100644
index 00000000..fe1814fb
--- /dev/null
+++ b/pokemod/Ability.h
@@ -0,0 +1,67 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Ability.h
+// Purpose: Define an ability that Pokémon can possess to add extra
+// dynamics to the battle system
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Wed Feb 28 21:41:10 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_ABILITY__
+#define __POKEMOD_ABILITY__
+
+#include <vector>
+#include <list>
+#include "Object.h"
+#include "String.h"
+#include "AbilityEffect.h"
+
+namespace PokeMod
+{
+ class Ability: public Object
+ {
+ public:
+ Ability(unsigned _id);
+ Ability(XmlElement &xml, unsigned _id = UINT_MAX);
+ ~Ability();
+
+ void ImportXml(XmlElement &xml, unsigned _id = UINT_MAX);
+ XmlElement ExportXml();
+
+ void SetName(const String &n);
+
+ String GetName();
+
+ AbilityEffect *GetAbilityEffect(unsigned _id);
+ unsigned GetAbilityEffectCount();
+ void NewAbilityEffect(XmlElement *xml = NULL);
+ void DeleteAbilityEffect(unsigned _id);
+ private:
+# ifdef POKEMODR
+ void Validate(wxListBox &output);
+# else
+ void Validate();
+# endif
+
+ String name;
+
+ std::vector<AbilityEffect> effects;
+ };
+}
+
+#endif
diff --git a/pokemod/Author.cpp b/pokemod/Author.cpp
new file mode 100644
index 00000000..aad2b60e
--- /dev/null
+++ b/pokemod/Author.cpp
@@ -0,0 +1,252 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Author.cpp
+// Purpose: Define an author of a PokéMod
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Wed Feb 28 20:42:17 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Author.h"
+
+PokeMod::Author::Author(unsigned _id)
+{
+ LogCtor("Author", id);
+ name = "";
+ email = "";
+ role = "";
+ id = _id;
+}
+
+PokeMod::Author::Author(XmlElement &xml, unsigned _id)
+{
+ LogCtorXml("Author", id);
+ ImportXml(xml, _id);
+ // Big problems
+ if (id == UINT_MAX)
+ LogIdError("Author");
+}
+
+PokeMod::Author::~Author()
+{
+ LogDtor("Author", id, name);
+}
+
+#ifdef POKEMODR
+void PokeMod::Author::Validate(wxListBox &output)
+#else
+void PokeMod::Author::Validate()
+#endif
+{
+ isValid = true;
+ LogValidateStart("Author", id, name);
+ if (name == "")
+ {
+ LogVarNotSet("Author", "name", id);
+# ifdef POKEMODR
+ output.Append(ConsoleLogVarNotSet("Author", "name", id)));
+# endif
+ isValid = false;
+ }
+ if (email == "")
+ {
+ LogVarNotSet("Author", "email", id, name);
+# ifdef POKEMODR
+ output.Append(ConsoleLogVarNotSetW("Author", "email", id)));
+# endif
+ }
+ else if (!IsValidEmail())
+ {
+ LogVarNotValid("Author", "email", id, name);
+# ifdef POKEMODR
+ output.Append(ConsoleLogVarNotValid("Author", "email", id, name));
+# endif
+ isValid = false;
+ }
+ if (role == "")
+ {
+ LogValNotSet("Author", "role", id, name);
+# ifdef POKEMODR
+ output.Append(ConsoleLogValNotSet("Author", "role", id, name)));
+# endif
+ isValid = false;
+ }
+ LogValidateOver("Author", isValid, id, name);
+}
+
+void PokeMod::Author::ImportXml(XmlElement &xml, unsigned _id)
+{
+ LogImportStart("Author");
+ String curName;
+ if (_id == UINT_MAX)
+ {
+ xml.GetValue(id);
+ if (id == UINT_MAX)
+ LogIdNotFound("Author");
+ }
+ else
+ id = _id;
+ name = "";
+ email = "";
+ role = "";
+ xml.ClearCounter();
+ for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ {
+ curName = child->GetName();
+ if (curName == "name")
+ child->GetValue(name);
+ else if (curName == "email")
+ child->GetValue(email);
+ else if (curName == "role")
+ child->GetValue(role);
+ else
+ LogUnknownXml("Author", curName);
+ }
+ LogImportOver("Author", id, name);
+}
+
+PokeMod::XmlElement PokeMod::Author::ExportXml()
+{
+ LogExportStart("Author", id, name);
+ // Declare the elements
+ XmlElement exAuthor("author", id, true);
+ exAuthor.AddElement("name", name);
+ exAuthor.AddElement("email", email);
+ exAuthor.AddElement("role", role);
+ LogExportOver("Author", id, name);
+ return exAuthor;
+}
+
+void PokeMod::Author::SetName(const String &n)
+{
+ LogSetVar("Author", "name", id, INT_MIN, n, name);
+ name = n;
+}
+
+void PokeMod::Author::SetEmail(const String &e)
+{
+ LogSetVar("Author", "email", id, INT_MIN, e, name);
+ email = e;
+}
+
+void PokeMod::Author::SetRole(const String &r)
+{
+ LogSetVar("Author", "role", id, INT_MIN, r, name);
+ role = r;
+}
+
+PokeMod::String PokeMod::Author::GetName()
+{
+ LogFetchVar("Author", "name", id, INT_MIN, name);
+ return name;
+}
+
+PokeMod::String PokeMod::Author::GetEmail()
+{
+ LogFetchVar("Author", "email", id, INT_MIN, email, name);
+ return email;
+}
+
+PokeMod::String PokeMod::Author::GetRole()
+{
+ LogFetchVar("Author", "role", id, INT_MIN, role, name);
+ return role;
+}
+
+bool PokeMod::Author::IsValidEmail()
+{
+ bool valid = true;
+ Log(String("Author: Validating email of %d (%s)", id, name), PM_DEBUG_DEBUG);
+ EmailCheck stage = EM_NAME;
+ int count = 0;
+ for (unsigned i = 0; (i < email.length()) && valid; ++i)
+ {
+ switch (stage)
+ {
+ case EM_NAME:
+ switch (email[i])
+ {
+ // Only allow alphanumerics and '%-_.' in the name
+ case 'a' ... 'z':
+ case 'A' ... 'Z':
+ case '0' ... '9':
+ case '%':
+ case '-':
+ case '_':
+ case '.':
+ ++count;
+ break;
+ // Move to the next part if '@' is encountered
+ case '@':
+ if (!count)
+ valid = false;
+ count = 0;
+ stage = EM_HOST;
+ break;
+ // Not valid if anything else is encountered
+ default:
+ valid = false;
+ }
+ break;
+ case EM_HOST:
+ switch (email[i])
+ {
+ // Only allow alphanumerics and '%-_.' in the host
+ case 'a' ... 'z':
+ case 'A' ... 'Z':
+ case '0' ... '9':
+ case '-':
+ ++count;
+ break;
+ // Move to the next part if '.' is encountered
+ case '.':
+ if (!count)
+ valid = false;
+ count = 0;
+ stage = EM_DOMAIN;
+ break;
+ // Not valid if anything else is encountered
+ default:
+ valid = false;
+ }
+ break;
+ case EM_DOMAIN:
+ switch (email[i])
+ {
+ // Only allow alphanumerics and '%-_.' in the host
+ case 'a' ... 'z':
+ case 'A' ... 'Z':
+ ++count;
+ break;
+ // Move to the next domain extension if '.' is encountered
+ case '.':
+ if (!count)
+ valid = false;
+ count = 0;
+ break;
+ // Not valid if anything else is encountered
+ default:
+ valid = false;
+ }
+ }
+ }
+ // Make sure the domain was entered and the extension is in the valid range
+ if ((stage != EM_DOMAIN) || (count < 2) || (4 < count))
+ valid = false;
+ Log(String("Author: Validated email of %d (%s) as %s", id, name, valid ? "valid" : "invalid"), PM_DEBUG_DEBUG);
+ return valid;
+}
diff --git a/pokemod/Author.h b/pokemod/Author.h
new file mode 100644
index 00000000..c81bf3c8
--- /dev/null
+++ b/pokemod/Author.h
@@ -0,0 +1,71 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Author.h
+// Purpose: Define an author of a PokéMod
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Wed Feb 28 20:42:17 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_AUTHOR__
+#define __POKEMOD_AUTHOR__
+
+#include "Object.h"
+#include "String.h"
+
+namespace PokeMod
+{
+ class Author: public Object
+ {
+ public:
+ Author(unsigned _id);
+ Author(XmlElement &xml, unsigned _id = UINT_MAX);
+ ~Author();
+
+ void ImportXml(XmlElement &xml, unsigned _id = UINT_MAX);
+ XmlElement ExportXml();
+
+ void SetName(const String &n);
+ void SetEmail(const String &e);
+ void SetRole(const String &r);
+
+ String GetName();
+ String GetEmail();
+ String GetRole();
+ private:
+# ifdef POKEMODR
+ void Validate(wxListBox &output);
+# else
+ void Validate();
+# endif
+
+ enum EmailCheck
+ {
+ EM_NAME = 0,
+ EM_HOST = 1,
+ EM_DOMAIN = 2
+ };
+
+ bool IsValidEmail();
+
+ String name;
+ String email;
+ String role;
+ };
+}
+
+#endif
diff --git a/pokemod/Badge.cpp b/pokemod/Badge.cpp
new file mode 100644
index 00000000..b6895f14
--- /dev/null
+++ b/pokemod/Badge.cpp
@@ -0,0 +1,285 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Badge.cpp
+// Purpose: Define a badge which can boost some stats and can allow the
+// use of special techniques in the overworld
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Wed Feb 28 21:27:53 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Badge.h"
+
+extern PokeMod::Pokemod curPokeMod;
+
+PokeMod::Badge::Badge(unsigned _id)
+{
+ LogCtor("Badge", _id);
+ name = "";
+ face = "";
+ badge = "";
+ obey = 0;
+ for (unsigned i = 0; i < STH_END_GSC; ++i)
+ stats[i].Set(1, 1);
+ for (unsigned i = 0; i < HM_END; ++i)
+ hm[i] = false;
+ id = _id;
+}
+
+PokeMod::Badge::Badge(XmlElement &xml, unsigned _id)
+{
+ LogCtorXml("Badge", _id);
+ ImportXml(xml);
+ if (id == UINT_MAX)
+ LogIdError("Badge");
+}
+
+PokeMod::Badge::~Badge()
+{
+ LogDtor("Badge", id, name);
+}
+
+#ifdef POKEMODR
+void PokeMod::Badge::Validate(wxListBox &output)
+#else
+void PokeMod::Badge::Validate()
+#endif
+{
+ isValid = true;
+ LogValidateStart("Badge", id, name);
+ if (name == "")
+ {
+ LogVarNotSet("Badge", "name", id);
+# ifdef POKEMODR
+ output.Append(ConsoleLogVarNotSet("Badge", "name", id));
+# endif
+ isValid = false;
+ }
+ if (!face.DoesExist())
+ {
+ if (face == "")
+ {
+ LogVarNotSet("Badge", "face sprite", id, name);
+# ifdef POKEMODR
+ output.Append(ConsoleLogVarNotSet("Badge", "face sprite", id, name));
+# endif
+ }
+ else
+ {
+ LogVarNotValid("Badge", "face sprite", id, name);
+# ifdef POKEMODR
+ output.Append(ConsoleLogVarNotValid("Badge", "face sprite", id, name));
+# endif
+ }
+ isValid = false;
+ }
+ if (!badge.DoesExist())
+ {
+ if (badge == "")
+ {
+ LogVarNotSet("Badge", "badge sprite", id, name);
+# ifdef POKEMODR
+ output.Append(ConsoleLogVarNotSet("Badge", "badge sprite", id, name));
+# endif
+ }
+ else
+ {
+ LogVarNotValid("Badge", "badge sprite", id, name);
+# ifdef POKEMODR
+ output.Append(ConsoleLogVarNotValid("Badge", "badge sprite", id, name));
+# endif
+ }
+ isValid = false;
+ }
+ LogValidationOver("Badge", isValid, is, name);
+}
+
+void PokeMod::Badge::ImportXml(XmlElement &xml, unsigned _id)
+{
+ LogImport("Badge");
+ String curName;
+ if (_id == UINT_MAX)
+ {
+ xml.GetValue(id);
+ // Was there an id associated with the element?
+ if (id == UINT_MAX)
+ LogIdNotFound("Badge");
+ }
+ else
+ id = _id;
+ name = "";
+ face = "";
+ badge = "";
+ obey = 0;
+ for (unsigned i = 0; i < STH_END_GSC; ++i)
+ stats[i].Set(1, 1);
+ for (unsigned i = 0; i < HM_END; ++i)
+ hm[i] = false;
+ xml.ClearCounter();
+ for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ {
+ curName = child->Value();
+ if (curName == "name")
+ name = child->GetTextOrDefault("");
+ else if (curName == "face")
+ face = child->GetTextOrDefault("");
+ else if (curName == "badge")
+ badge = child->GetTextOrDefault("");
+ else if (curName == "obey")
+ child->GetTextOrDefault(&obey, 0);
+ else if (curName == "stats")
+ {
+ for (ticpp::Element *subChild = child->FirstChildElement(); subChild; subChild = subChild->NextSiblingElement())
+ {
+ curName = subChild->Value();
+ int i = FindIn(STH_END_GSC, curName, StatHPGSCStr);
+ if (i < STH_END_GSC)
+ stats[i].ImportXml(*subChild);
+ else if (curName == "Special")
+ stats[STH_SPECIAL].ImportXml(*subChild);
+ else
+ PMLog(PMString("Badge Import: Unknown Stat XML Element \"%s\"", curName.c_str()), PM_DEBUG_ERROR);
+ }
+ }
+ else if (curName == "hms")
+ {
+ for (ticpp::Element *subChild = child->FirstChildElement(); subChild; subChild = subChild->NextSiblingElement())
+ {
+ curName = subChild->Value();
+ int i = FindIn(PokeMod::HM_END, curName, HMStr);
+ if (i < HM_END)
+ subChild->GetTextOrDefault(&hm[i], false);
+ else
+ PMLog(PMString("Badge Import: Unknown HM XML Element \"%s\"", curName.c_str()), PM_DEBUG_ERROR);
+ }
+ }
+ else
+ PMLog(PMString("Badge Import: Unknown XML element \"%s\"", curName.c_str()), PM_DEBUG_ERROR);
+ }
+ LogImportOver("Badge", id, name);
+}
+
+PokeMod::XmlElement PokeMod::Badge::ExportXml()
+{
+ LogExportStart("Badge", id, name);
+ XmlElement exBadge("badge", id, true);
+ XmlElement exStats("stats", 0, true);
+ XmlElement exHm("hm", 0, true);
+ exBadge.AddElement("name", name);
+ exBadge.AddElement("face", face);
+ exBadge.AddElement("badge", badge);
+ exBadge.AddElement("obey", obey);
+ for (unsigned i = 0; i < (curPokeMod.IsSpecialSplit() ? STH_END_GSC : STH_END_RBY); ++i)
+ exStats.AddElement(stats[i].ExportXml((curPokeMod.IsSpecialSplit() ? StatHPGSCStr : StatHPRBYStr)[i]));
+ exBadge.AddElement(exStats);
+ for (unsigned i = 0; i < HM_END; ++i)
+ exHm.AddElement(HMStr[i], hm[i]);
+ exBadge.AddElement(exHm);
+ LogExportOver("Badge", id, name);
+ return exBadge;
+}
+
+void PokeMod::Badge::SetName(const String &n)
+{
+ LogSetVar("Badge", "name", id, INT_MIN, n);
+ name = n;
+}
+
+void PokeMod::Badge::SetFace(const Path &f)
+{
+ LogSetVar("Badge", "face", id, INT_MIN, f);
+ face = f;
+}
+
+void PokeMod::Badge::SetBadge(const Path &b)
+{
+ LogSetVar("Badge", "badge", id, INT_MIN, b);
+ badge = b;
+}
+
+void PokeMod::Badge::SetObey(unsigned o)
+{
+ LogSetVar("Badge", "obey", id, INT_MIN, o);
+ obey = o;
+}
+
+void PokeMod::Badge::SetStat(unsigned s, unsigned n, unsigned d)
+{
+ LogSetVar("Badge", String("stats[%u]", s), Frac(n, d, true), id, INT_MIN);
+ stats[s].Set(n, d);
+}
+
+void PokeMod::Badge::SetStatNum(unsigned s, unsigned n)
+{
+ LogSetVar("Badge", String("stat[%u] numerator", s), id, INT_MIN, n);
+ stats[s].SetNum(n);
+}
+
+void PokeMod::Badge::SetStatDenom(unsigned s, unsigned d)
+{
+ LogSetVar("Badge", String("stat[%u] denominator", s), id, INT_MIN, d);
+ stats[s].SetDenom(d);
+}
+
+void PokeMod::Badge::SetHm(unsigned h, bool hb)
+{
+ LogSetVar("Badge", String("hm[%u]", s), id, INT_MIN, hb);
+ if (HM_END <= h)
+ PMLog(PMString("Badge: Index of hm out-of-bounds (%d)", h), PM_DEBUG_ERROR);
+ else
+ hm[h] = hb;
+}
+
+PokeMod::String PokeMod::Badge::GetName()
+{
+ LogFetchVar("Badge", "name", id, INT_MIN, name);
+ return name;
+}
+
+PokeMod::Path PokeMod::Badge::GetFace()
+{
+ LogFetchVar("Badge", "face", id, INT_MIN, face);
+ return face;
+}
+
+PokeMod::Path PokeMod::Badge::GetBadge()
+{
+ LogFetchVar("Badge", "badge", id, INT_MIN, badge);
+ return badge;
+}
+
+unsigned PokeMod::Badge::GetObey()
+{
+ LogFetchVar("Badge", "obey", id, INT_MIN, obey);
+ return obey;
+}
+
+PokeMod::Frac PokeMod::Badge::GetStat(unsigned s)
+{
+ LogFetchVar("Badge", String("stats[%u]", s), id, INT_MIN, stats[s]);
+ if ((curPokeMod.IsSpecialSplit() ? STH_END_RBY : STH_END_GSC) <= s)
+ PMLog(PMString("Badge: Index of stats out-of-bounds (%d)", s), PM_DEBUG_ERROR);
+ return stats[s];
+}
+
+bool PokeMod::Badge::GetHm(unsigned h)
+{
+ LogFetchVar("Badge", String("hm[%u]", h), id, INT_MIN, hm[h]);
+ if (HM_END <= h)
+ PMLog(PMString("Badge: Index of hm out-of-bounds (%d)", h), PM_DEBUG_ERROR);
+ return hm[h];
+}
diff --git a/pokemod/Badge.h b/pokemod/Badge.h
new file mode 100644
index 00000000..97499ff2
--- /dev/null
+++ b/pokemod/Badge.h
@@ -0,0 +1,78 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Badge.h
+// Purpose: Define a badge which can boost some stats and can allow the
+// use of special techniques in the overworld
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Wed Feb 28 21:27:53 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_BADGE__
+#define __POKEMOD_BADGE__
+
+#include "Object.h"
+#include "String.h"
+#include "Ref.h"
+#include "Path.h"
+#include "Frac.h"
+#include "Pokemod.h"
+
+namespace PokeMod
+{
+ class Badge: public Object
+ {
+ public:
+ Badge(unsigned _id);
+ Badge(XmlElement &xml, unsigned _id = UINT_MAX);
+ ~Badge();
+
+ void ImportXml(XmlElement &xml);
+ XmlElement ExportXml();
+
+ void SetName(const String &n);
+ void SetFace(const Path &f);
+ void SetBadge(const Path &b);
+ void SetObey(unsigned o);
+ void SetStat(unsigned s, unsigned n, unsigned d);
+ void SetStatNum(unsigned s, unsigned n);
+ void SetStatDenom(unsigned s, unsigned d);
+ void SetHm(unsigned h, bool hb);
+
+ String GetName();
+ Path GetFace();
+ Path GetBadge();
+ unsigned GetObey();
+ Frac GetStat(unsigned s);
+ bool GetHm(unsigned h);
+ private:
+# ifdef POKEMODR
+ void Validate(wxListBox &output);
+# else
+ void Validate();
+# endif
+
+ String name;
+ Path face;
+ Path badge;
+ unsigned obey;
+ Frac stats[STH_END_GSC];
+ bool hm[HM_END];
+ };
+}
+
+#endif
diff --git a/pokemod/Debug.cpp b/pokemod/Debug.cpp
new file mode 100644
index 00000000..9790ea20
--- /dev/null
+++ b/pokemod/Debug.cpp
@@ -0,0 +1,87 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Debug.cpp
+// Purpose: Define logging abilities for a PokéMod
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Wed Feb 14 23:44:39 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Debug.h"
+
+#ifdef PM_DEBUG
+
+// Declare an instance of the debug window
+#ifdef PM_DEBUG_OUTPUT_DEBUG
+debugWindow debug = new debugWindow();
+#endif
+
+extern int PMdebugLevel;
+
+void PokeMod::Log(const char *msg, int level)
+{
+ // Actual strings of the debugging levels
+ const char *PokeModDebugStr[8] = {"Emergency", "Alert", "Critical Error", "Error", "Warning", "Notice", "Info", "Debug"};
+ // Only log if wanted
+ if (level <= PMdebugLevel)
+ {
+ // Get the current time
+ time_t curTimeSec = time(NULL);
+ PMString curTime = asctime(localtime(&curTimeSec));
+ curTime.erase(curTime.find('\n'));
+ // Get the actual output message
+ PMString output("%s (%s): %s", PokeModDebugStr[level], curTime.c_str(), msg);
+ // Output to the command window
+# ifdef PM_DEBUG_OUTPUT_CONSOLE
+ std::cout << output << std::endl;
+# endif
+ // Output to the debugging console
+# ifdef PM_DEBUG_OUTPUT_DEBUG
+ if (debug.m_Show[level].IsChecked())
+ debug.m_Debug.Append(output);
+# endif
+ // Output to the debugging log
+# ifdef PM_DEBUG_OUTPUT_FILE
+ std::ofstream flog("PokeMod.log", std::ios::app);
+ // Output erros if the file fails
+ if (!flog)
+ {
+# ifdef PM_DEBUG_OUTPUT_CONSOLE
+ std::cout << "Alert (" << curTime << "): Unable to open log file!\n";
+# endif
+# ifdef PM_DEBUG_OUTPUT_DEBUG
+ debug.m_Debug.Append(String("Alert (%s): Unable to open log file!", curTime));
+# endif
+ }
+ else
+ {
+ flog << output << '\n';
+ flog.close();
+ }
+# endif
+ }
+}
+
+#else
+
+// Empty function if debugging isn't wanted
+void PokeMod::Log(const PokeMod::String &msg, int level)
+{
+ return;
+}
+
+#endif
diff --git a/pokemod/Debug.h b/pokemod/Debug.h
new file mode 100644
index 00000000..8c7db489
--- /dev/null
+++ b/pokemod/Debug.h
@@ -0,0 +1,279 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Debug.h
+// Purpose: Define logging abilities for PokéMods
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Thu Feb 15 8:52:20 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_DEBUG__
+#define __POKEMOD_DEBUG__
+
+// TODO (Ben#1#): Comment logging functions
+
+#ifdef PM_DEBUG
+
+# include <ctime>
+# ifdef PM_DEBUG_OUTPUT_FILE
+# include <fstream>
+# endif
+# ifdef PM_DEBUG_OUTPUT_CONSOLE
+# include <cstdio>
+# endif
+# ifdef PM_DEBUG_OUTPUT_DEBUG
+# include "../gui/debugWindow.h"
+# endif
+
+# if !defined(PM_DEBUG_OUTPUT_FILE) && !defined(PM_DEBUG_OUTPUT_CONSOLE) && !defined(PM_DEBUG_OUTPUT_DEBUG)
+# error "Debugging turned on, but no output specified!"
+# endif
+
+#include "String.h"
+
+namespace PokeMod
+{
+ enum PokeModDebug
+ {
+ PM_DEBUG_EMERGENCY = 0,
+ PM_DEBUG_ALERT = 1,
+ PM_DEBUG_CRITICAL_ERROR = 2,
+ PM_DEBUG_ERROR = 3,
+ PM_DEBUG_WARNING = 4,
+ PM_DEBUG_NOTICE = 5,
+ PM_DEBUG_INFO = 6,
+ PM_DEBUG_DEBUG = 7
+ };
+
+ void Log(const char *msg, int level);
+
+ inline void LogCtor(const char *module, unsigned id)
+ {
+ Log(String("%s: Initializing %u", module, id), PM_DEBUG_DEBUG);
+ }
+
+ inline void LogCtorXml(const char *module, unsigned id)
+ {
+ Log(String("%s: Initializing by XML (%u)", module, id), PM_DEBUG_DEBUG);
+ }
+
+ inline void LogIdError(const char *module)
+ {
+ Log(String("%s: id not set", module), PM_DEBUG_ALERT);
+ }
+
+ // Destruction
+ inline void LogDtor(const char *module, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Destroying %u%s", module, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_DEBUG);
+ }
+
+ // Validation
+ inline void LogValidateStart(const char *module, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s Validation: Starting to validate %u%s", module, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_INFO);
+ }
+
+ inline void LogVarNotSet(const char *module, const char *var, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s Validation: %s of %u%s isn\'t set", module, var, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_ALERT);
+ }
+
+ inline String ConsoleLogVarNotSet(const char *module, const char *var, unsigned id, const char *name = NULL)
+ {
+ return String("Error (%s): %s of %u%s isn\'t set", module, var, id, name ? String(" (%s)", name).c_str() : "");
+ }
+
+ inline String ConsoleLogVarNotSetW(const char *module, const char *var, unsigned id, const char *name = NULL)
+ {
+ return String("Warning (%s): %s of %u%s isn\'t set", module, var, id, name ? String(" (%s)", name).c_str() : "");
+ }
+
+ inline void LogVarNotValid(const char *module, const char *var, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s Validation: %s of %u%s isn\'t valid", module, var, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_ALERT);
+ }
+
+ inline String ConsoleLogVarNotValid(const char *module, const char *var, unsigned id, const char *name = NULL)
+ {
+ return String("Error (%s): %s of %u%s isn\'t valid", module, var, id, name ? String(" (%s)", name).c_str() : "");
+ }
+
+ inline void LogSubmoduleIterate(const char *module, const char *subName, unsigned subId, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s Validation: Validating %s %u of %u%s", module, subName, subId, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_DEBUG);
+ }
+
+ inline void LogSubmoduleEmpty(const char *module, const char *subName, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s Validation: No %s of %u%s defined", module, subName, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_ALERT);
+ }
+
+ inline String ConsoleLogSubmoduleEmpty(const char *module, const char *subName, unsigned id, const char *name = NULL)
+ {
+ return String("Error (%s): No %s of %u%s defined", module, subName, id, name ? String(" (%s)", name).c_str() : "");
+ }
+
+ inline void LogValidationOver(const char *module, bool valid, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s Validation: %u%s %s", module, id, name ? String(" (%s)", name).c_str() : "", valid ? "Passed" : "Failed"), PM_DEBUG_INFO);
+ }
+
+ // Importing
+ inline void LogImport(const char *module)
+ {
+ Log(String("%s Import: Starting", module), PM_DEBUG_INFO);
+ }
+
+ inline void LogIdNotFound(const char *module)
+ {
+ Log(String("%s Import: id not found", module), PM_DEBUG_ALERT);
+ }
+
+ inline void LogUnknownXml(const char *module, const char *element)
+ {
+ Log(String("%s Import: Unknown XML element (%s)", module, element), PM_DEBUG_NOTICE);
+ }
+
+ inline void LogImportOver(const char *module, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s Import: Imported %u%s", module, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_INFO);
+ }
+
+ // Exporting
+ inline void LogExportStart(const char *module, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s Export: Starting %u%s", module, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_INFO);
+ }
+
+ inline void LogExportOver(const char *module, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s Export: Finished %u%s", module, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_INFO);
+ }
+
+ // Setting Variable Values
+ inline void LogSetVar(const char *module, const char *var, unsigned id, int valInt = INT_MIN, const char *valStr = NULL, const char *name = NULL)
+ {
+ Log(String("%s: Setting %s of %u%s to %s", module, var, id, name ? String(" (%s)", name).c_str() : "", (valInt == INT_MIN) ? String("%d%s", valInt, valStr ? String(" (%s)", valStr).c_str()).c_str() : (valStr ? valStr : String("%d", valInt).c_str())), PM_DEBUG_DEBUG);
+ }
+
+ inline void LogSetVar(const char *module, const char *var, unsigned id, unsigned valInt = UINT_MAX, const char *valStr = NULL, const char *name = NULL)
+ {
+ Log(String("%s: Setting %s of %u%s to %s", module, var, id, name ? String(" (%s)", name).c_str() : "", (valInt == INT_MIN) ? String("%u%s", valInt, valStr ? String(" (%s)", valStr).c_str()).c_str() : (valStr ? valStr : String("%u", valInt).c_str())), PM_DEBUG_DEBUG);
+ }
+
+ inline void LogSetVar(const char *module, const char *var, const Frac &val, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Setting %s of %u%s to %u/%u", module, var, id, name ? String(" (%s)", name).c_str() : "", val.GetNum(), val.GetDenom()), PM_DEBUG_);
+ }
+
+ inline void LogSetVar(const char *module, const char *var, unsigned n, unsigned d, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Setting %s of %u%s to %u/%u", module, var, id, name ? String(" (%s)", name).c_str() : "", n, d), PM_DEBUG_);
+ }
+
+ inline void LogSetVar(const char *module, const char *var, unsigned n, bool isNum, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Setting %s of %s of %u%s to %u", module, isNum ? "numerator" : "denominator", var, id, name ? String(" (%s)", name).c_str() : "", n), PM_DEBUG_);
+ }
+
+ inline void LogOutOfRange(const char *module, const char *var, int valInt, const char *regVal, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Attempting to set %s to %d of %u%s out-of-range (%s)", module, var, valInt, id, name ? String(" (%s)", name).c_str() : "", regVal), PM_DEBUG_);
+ }
+
+ inline void LogNotSet(const char *module, const char *var, const char *reg, unsigned id, int valInt = INT_MIN, const char *valStr = NULL, const char *name = NULL)
+ {
+ Log(String("%s: Attempting to set %s to %s of %u%s without %s being set", module, var, (valInt == INT_MIN) ? String("%d%s", valInt, valStr ? String(" (%s)", valStr).c_str()).c_str() : (valStr ? valStr : String("%d", valInt).c_str()), id, name ? String(" (%s)", name).c_str() : "", reg), PM_DEBUG_);
+ }
+
+ inline void LogNotSet(const char *module, const char *var, const char *reg, unsigned id, unsigned valInt = UINT_MAX, const char *valStr = NULL, const char *name = NULL)
+ {
+ Log(String("%s: Attempting to set %s to %s of %u%s without %s being set", module, var, (valInt == UINT_MAX) ? String("%u%s", valInt, valStr ? String(" (%s)", valStr).c_str()).c_str() : (valStr ? valStr : String("%u", valInt).c_str()), id, name ? String(" (%s)", name).c_str() : "", reg), PM_DEBUG_);
+ }
+
+ inline void LogNoUse(const char *module, const char *var, const char *reg, const char *regVal, unsigned id, int valInt = INT_MIN, const char *valStr = NULL, const char *name = NULL)
+ {
+ Log(String("%s: Attempting to set %s to %s of %u%s without %s needing it (%s)", module, var, (valInt == INT_MIN) ? String("%d%s", valInt, valStr ? String(" (%s)", valStr).c_str()).c_str() : (valStr ? valStr : String("%d", valInt).c_str()), id, name ? String(" (%s)", name).c_str() : "", reg, regVal), PM_DEBUG_);
+ }
+
+ inline void LogNoUse(const char *module, const char *var, const char *reg, const char *regVal, unsigned id, unsigned valInt = UINT_MAX, const char *valStr = NULL, const char *name = NULL)
+ {
+ Log(String("%s: Attempting to set %s to %s of %u%s without %s needing it (%s)", module, var, (valInt == UINT_MAX) ? String("%u%s", valInt, valStr ? String(" (%s)", valStr).c_str()).c_str() : (valStr ? valStr : String("%u", valInt).c_str()), id, name ? String(" (%s)", name).c_str() : "", reg, regVal), PM_DEBUG_);
+ }
+
+ // Fetching variable values
+ inline void LogFetchVar(const char *module, const char *var, int valInt, const char *regVal, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Fetching %s from %u%s (%d%s)", module, var, id, name ? String(" (%s)", name).c_str() : "", valInt, regVal ? String(", %s", regVal).c_str() : ""), PM_DEBUG_);
+ }
+
+ inline void LogFetchVar(const char *module, const char *var, const char *valStr, const char *regVal, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Fetching %s from %u%s (%s%s)", module, var, id, name ? String(" (%s)", name).c_str() : "", valStr, regVal ? String(", %s", regVal).c_str() : ""), PM_DEBUG_);
+ }
+
+ // Submodule logging
+ inline void LogSubmoduleFetch(const char *module, const char *subName, unsigned subId, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Fetching %s %u from %u%s", module, subName, subId, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_);
+ }
+
+ inline void LogSubmoduleFetch(const char *module, const char *subName, const char *subStr, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Fetching %s %s from %u%s", module, subName, subStr, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_);
+ }
+
+ inline void LogSubmoduleFetchFail(const char *module, const char *subName, unsigned subId, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Fetching %s %u from %u%s", module, subName, subId, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_);
+ }
+
+ inline void LogSubmoduleCount(const char *module, const char *subName, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Fetching %s count of %u%s", module, subName, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_);
+ }
+
+ inline void LogSubmoduleNew(const char *module, const char *subName, unsigned subId, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Creating a new %s (%u) in %u%s", module, subName, subId, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_);
+ }
+
+ inline void LogSubmoduleRemoveStart(const char *module, const char *subName, unsigned subId, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Attempting to remove %s %u from %u%s", module, subName, subId, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_);
+ }
+
+ inline void LogSubmoduleRemoved(const char *module, const char *subName, unsigned subId, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Removed %s %u from %u%s", module, subName, subId, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_);
+ }
+
+ inline void LogSubmoduleRemoveFail(const char *module, const char *subName, unsigned subId, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: Failed to remove %s %u from %u%s", module, subName, subId, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_);
+ }
+
+ /* inline void Log(const char *module, unsigned id, const char *name = NULL)
+ {
+ Log(String("%s: ", module, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_);
+ }*/
+}
+
+#endif
+
+#endif
diff --git a/pokemod/Flag.cpp b/pokemod/Flag.cpp
new file mode 100644
index 00000000..23b2188a
--- /dev/null
+++ b/pokemod/Flag.cpp
@@ -0,0 +1,97 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Flag.cpp
+// Purpose: A class that handles flags
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Sun Mar 18 15:25:16 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Flag.h"
+
+PokeMod::Flag::Flag(unsigned f, int s)
+{
+ Log("Flag: Initializing", PM_DEBUG_DEBUG);
+ flag = f;
+ SetStatus(s);
+}
+
+void PokeMod::Flag::ImportXml(XmlElement &xml)
+{
+ LogImportStart("Flag");
+ String curName;
+ xml.ClearCounter();
+ for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ {
+ curName = child->GetName();
+ if (curName == "flag")
+ child->GetValue(flag);
+ else if (curName == "state")
+ child->GetValue(status);
+ else
+ LogUnknownXml("Flag", curName);
+ }
+ LogImportOver("Flag", id, name);
+}
+
+PokeMod::XmlElement PokeMod::Flag::ExportXml(const String &val)
+{
+ Log(String("Flag Export: Starting %s", val.c_str()), PM_DEBUG_INFO);
+ // Declare the elements
+ XmlElement exFlag(val, 0, true);
+ exFlag.AddElement("flag", flag);
+ exFlag.AddElement("state", status);
+ Log(String("Flag Export: Finished %s", val.c_str()), PM_DEBUG_INFO);
+ return exFlag;
+}
+
+void PokeMod::Flag::SetFlag(unsigned f)
+{
+ Log(String("Flag: Setting the flag to (%u)", f), PM_DEBUG_DEBUG);
+ flag = f;
+}
+
+void PokeMod::Flag::SetStatus(int s)
+{
+ Log(String("Flag: Setting the status to (%d)", s), PM_DEBUG_DEBUG);
+ // Avoid errors
+ status = (s ? ((s > FV_UNSET) ? FV_SET : FV_IGNORE) : FV_UNSET);
+}
+
+void PokeMod::Flag::SetStatus(const String &s)
+{
+ Log(String("Flag: Setting the status to (%s)", s.c_str()), PM_DEBUG_DEBUG);
+ SetStatus(FindIn(FV_END, s, FlagValueStr));
+}
+
+unsigned PokeMod::Flag::GetFlag()
+{
+ Log(String("Flag: Fetching the flag (%u)", flag), PM_DEBUG_DEBUG);
+ return flag;
+}
+
+FlagValue PokeMod::Flag::GetStatus()
+{
+ Log(String("Flag: Fetching the status (%d, %s)", status, FlagValueStr[status]), PM_DEBUG_DEBUG);
+ return status;
+}
+
+PokeMod::String PokeMod::Flag::GetStatusString()
+{
+ Log(String("Flag: Fetching the status string (%d, %s)", status, FlagValueStr[status]), PM_DEBUG_DEBUG);
+ return FlagValueStr[status];
+}
diff --git a/pokemod/Flag.h b/pokemod/Flag.h
new file mode 100644
index 00000000..0efe74cb
--- /dev/null
+++ b/pokemod/Flag.h
@@ -0,0 +1,52 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Flag.h
+// Purpose: A class that handles flags
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Tue Mar 20 19:22 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_FLAG__
+#define __POKEMOD_FLAG__
+
+#include "Debug.h"
+#include "Xml.h"
+
+namespace PokeMod
+{
+ class Flag
+ {
+ public:
+ Flag(unsigned f, int s);
+ void ImportXml(XmlElement &xml);
+ XmlElement ExportXml(const String &val);
+
+ void SetFlag(unsigned f);
+ void SetStatus(int s);
+ void SetStatus(const String &s);
+
+ unsigned GetFlag();
+ FlagValue GetStatus();
+ String GetStatusString();
+ private:
+ unsigned flag;
+ FlagValue status;
+ };
+}
+
+#endif
diff --git a/pokemod/Frac.cpp b/pokemod/Frac.cpp
new file mode 100644
index 00000000..7a3ddbb1
--- /dev/null
+++ b/pokemod/Frac.cpp
@@ -0,0 +1,172 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Frac.cpp
+// Purpose: A class to make handling fractions easier
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Sun Mar 18 15:25:16 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Frac.h"
+
+PokeMod::Frac::Frac(bool i)
+{
+ Log("Frac: Initializing", PM_DEBUG_DEBUG);
+ num = 1;
+ denom = 1;
+ improper = i;
+}
+
+PokeMod::Frac::Frac(unsigned n, unsigned d, bool i)
+{
+ Log(String("Frac: Initializing as %u/%u (%u)", n, d, i), PM_DEBUG_DEBUG);
+ Set(n, d, i);
+}
+
+void PokeMod::Frac::ImportXml(XmlElement &xml)
+{
+ LogImportStart("Frac");
+ String curName;
+ num = 1;
+ denom = 1;
+ improper = false;
+ Reduce();
+ xml.ClearCounter();
+ for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ {
+ curName = child->GetName();
+ if (curName == "num")
+ child->GetValue(num, 1);
+ else if (curName == "denom")
+ child->GetValue(denom, 1);
+ else if (curName == "improper")
+ child->GetValue(improper, false);
+ else
+ LogUnknownXml("Frac", curName);
+ }
+ Log(String("Frac Import: Imported %u/%u", num, denom), PM_DEBUG_INFO);
+}
+
+PokeMod::XmlElement PokeMod::Frac::ExportXml(const String &val)
+{
+ Log(String("Frac Export: Starting %u/%u as %s", num, denom, val.c_str()), PM_DEBUG_INFO);
+ // Reduce fraction before storing
+ Reduce();
+ // Declare the elements
+ XmlElement exFrac(val, 0, true);
+ exFrac.AddElement("num", num);
+ exFrac.AddElement("denom", denom);
+ exFrac.AddElement("improper", improper);
+ Log(String("Frac Export: Finished %u/%u as %s", num, denom, val.c_str()), PM_DEBUG_INFO);
+ return exFrac;
+}
+
+void PokeMod::Frac::Set(unsigned n, unsigned d)
+{
+ Log(String("Frac: Setting to %u/%u", n, d), PM_DEBUG_DEBUG);
+ SetDenom(d);
+ SetNum(n);
+ Reduce();
+}
+
+void PokeMod::Frac::Set(unsigned n, unsigned d, bool i)
+{
+ SetImproper(i);
+ Set(n, d);
+}
+
+void PokeMod::Frac::SetNum(unsigned n)
+{
+ // Make sure the numerator is less than the denominator if proper
+ if ((n <= denom) || improper)
+ {
+ Log(String("Frac: Setting numerator to %u (%u/%u)", n, n, denom), PM_DEBUG_DEBUG);
+ num = n;
+ }
+ else
+ Log(String("Frac: Setting tried to set numerator to %u when denominator is %u", n, denom), PM_DEBUG_DEBUG);
+}
+
+void PokeMod::Frac::SetDenom(unsigned d)
+{
+ // Make sure the denominator isn't 0
+ if (d)
+ {
+ Log(String("Frac: Setting denominator to %u", d), PM_DEBUG_DEBUG);
+ denom = d;
+ }
+ else
+ Log("Frac: Attempting to set denominator to 0", PM_DEBUG_DEBUG);
+ // Set the numerator to less than the denominator if proper
+ if ((num <= denom) && !improper)
+ {
+ Log(String("Frac: Setting numerator to 1 after denominator reset to (%u)", d), PM_DEBUG_DEBUG);
+ num = denom % num;
+ }
+}
+
+void PokeMod::Frac::SetImproper(bool i)
+{
+ Log(String("Frac: Setting as %s", i ? "improper" : "proper"), PM_DEBUG_DEBUG);
+ improper = i;
+ Set(num, denom);
+}
+
+unsigned PokeMod::Frac::GetNum()
+{
+ Log(String("Frac: Fetching the numerator (%u)", num), PM_DEBUG_DEBUG);
+ return num;
+}
+
+unsigned PokeMod::Frac::GetDenom()
+{
+ Log(String("Frac: Fetching the denominator (%u)", denom), PM_DEBUG_DEBUG);
+ return denom;
+}
+
+bool PokeMod::Frac::GetImproper()
+{
+ Log(String("Frac: Fetching improper (%u)", improper), PM_DEBUG_DEBUG);
+ return improper;
+}
+
+float PokeMod::Frac::GetValue()
+{
+ Log(String("Frac: Fetching the value (%f)", num / denom), PM_DEBUG_DEBUG);
+ return (num / denom);
+}
+
+PokeMod::Frac::operator float()
+{
+ return GetValue();
+}
+
+void PokeMod::Frac::Reduce()
+{
+ Log(String("Frac: Reducing %u/%u", num, denom), PM_DEBUG_DEBUG);
+ // Iterate until i is greater than the square root on num
+ for (unsigned i = 2; i * i <= num; ++i)
+ {
+ // Keep iterating while i is a factor of both
+ while (!((num % i) || (denom % i)))
+ {
+ num /= i;
+ denom /= i;
+ }
+ }
+ Log(String("Frac: Reduced to %u/%u", num, denom), PM_DEBUG_DEBUG);
+}
diff --git a/pokemod/Frac.h b/pokemod/Frac.h
new file mode 100644
index 00000000..90821ab5
--- /dev/null
+++ b/pokemod/Frac.h
@@ -0,0 +1,62 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Frac.h
+// Purpose: A class to make handling fractions easier
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Sun Mar 18 15:25:16 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_FRAC__
+#define __POKEMOD_FRAC__
+
+#include "Debug.h"
+#include "Xml.h"
+
+namespace PokeMod
+{
+ class Frac
+ {
+ public:
+ Frac(bool i = false);
+ Frac(unsigned n, unsigned d, bool i = false);
+
+ void ImportXml(XmlElement &xml);
+ XmlElement ExportXml(const String &val);
+
+ void Set(unsigned n, unsigned d);
+ void Set(unsigned n, unsigned d, bool i);
+ void SetNum(unsigned n);
+ void SetDenom(unsigned d);
+ void SetImproper(bool i);
+
+ unsigned GetNum();
+ unsigned GetDenom();
+ bool GetImproper();
+ float GetValue();
+
+ operator float();
+ private:
+ void Reduce();
+
+ unsigned num;
+ unsigned denom;
+ bool improper;
+ };
+}
+
+#endif
diff --git a/pokemod/Matrix.cpp b/pokemod/Matrix.cpp
new file mode 100644
index 00000000..96550a25
--- /dev/null
+++ b/pokemod/Matrix.cpp
@@ -0,0 +1,235 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Matrix.cpp
+// Purpose: A 2D vector class
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Sun Apr 8 12:51:20 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Matrix.h"
+
+template<class T>
+PokeMod::Matrix<T>::Matrix(unsigned w, unsigned h, T &d)
+{
+ matrix.resize(w, std::vector<T>(h, d));
+ width = w;
+ height = h;
+}
+
+template<class T>
+PokeMod::Matrix<T>::Matrix(XmlElement &x)
+{
+ ImportXml(xml);
+}
+
+template<class T>
+void PokeMod::Matrix<T>::AddRow(T &d)
+{
+ for (std::vector<T> *i = matrix.begin(); i != matrix.end(); ++i)
+ i->push_back(d);
+ ++height;
+}
+
+template<class T>
+void PokeMod::Matrix<T>::ImportXml(XmlElement &xml)
+{
+ LogImportStart("Matrix");
+ String curName;
+ width = 0;
+ height = 0;
+ bool haveHeight = false;
+ bool haveWidth = false;
+ xml.ClearCounter();
+ for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ {
+ curName = child->GetName();
+ if (curName == "height")
+ {
+ child->GetValue(height);
+ if (height)
+ haveHeight = true;
+ }
+ else if (curName == "width")
+ {
+ if (haveHeight)
+ {
+ child->GetValue(width);
+ if (width)
+ haveWidth = true;
+ matrix.resize(w, std::vector<T>(h, T()));
+ }
+ else
+ Log("Matrix Import: Elements out of order", PM_DEBUG_ERROR);
+ }
+ else if (curName == "col")
+ {
+ if (height && width)
+ {
+ unsigned colNum;
+ unsigned rowNum;
+ child->GetValue(colNum);
+ if (colNum < width)
+ {
+ child->ClearCounter();
+ for (XmlElement *item = child->NextElement(); item; item = child->NextElement())
+ {
+ item->GetValue(rowNum);
+ if ((item->GetName() == "item") && (rowNum < height))
+ matrix[colNum][rowNum].ImportXml(*item);
+ else
+ Log("Matrix Import: Item out of bounds", PM_DEBUG_ERROR);
+ }
+ }
+ else
+ Log("Matrix Import: Column out of bounds", PM_DEBUG_ERROR);
+ }
+ else
+ Log("Matrix Import: Elements out of order", PM_DEBUG_ERROR);
+ }
+ else
+ LogUnknownXml("Matrix", curName);
+ }
+ LogImportOver("Matrix", id, name);
+}
+
+template<class T>
+PokeMod::XmlElement PokeMod::Matrix<T>::ExportXml(const String &val)
+{
+ Log(String("Matrix Export: Starting %s", val.c_str()), PM_DEBUG_INFO);
+ // Declare the elements
+ XmlElement exMatrix(val, 0, true);
+ exMatrix.AddElement("height", height);
+ exMatrix.AddElement("width", width);
+ for (int i = 0; i < width; ++i)
+ {
+ XmlElement col("column", i, true);
+ for (int j = 0; j < height; ++j)
+ {
+ XmlElement item("item", j, true);
+ item.AddElement(matrix[i][j].ExportXml());
+ }
+ exMatrix.AddElement(col);
+ }
+ Log(String("Matrix Export: Finished %s", val.c_str()), PM_DEBUG_INFO);
+ return exMatrix;
+}
+
+template<class T>
+void PokeMod::Matrix<T>::AddCol(T &d)
+{
+ matrix.push_back(std::vector<T>(GetHeight(), d));
+ ++width;
+}
+
+template<class T>
+bool PokeMod::Matrix<T>::InsertRow(unsigned pos, T &d)
+{
+ if (height < pos)
+ return false;
+ for (std::vector<T> *i = matrix.begin(); i != matrix.end(); ++i)
+ i->insert(pos, d);
+ ++height;
+ return true;
+}
+
+template<class T>
+bool PokeMod::Matrix<T>::InsertCol(unsigned pos, T &d)
+{
+ if (width < pos)
+ return false;
+ matrix.insert(pos, std::vector<T>(GetHeight(), d));
+ ++width;
+ return true;
+}
+
+template<class T>
+bool PokeMod::Matrix<T>::DeleteRow(unsigned pos)
+{
+ if (height <= pos)
+ return false;
+ for (std::vector<T> *i = matrix.begin(); i != matrix.end(); ++i)
+ i->erase(i->begin() + pos);
+ --height;
+ return true;
+}
+
+template<class T>
+bool PokeMod::Matrix<T>::DeleteCol(unsigned pos)
+{
+ if (width <= pos)
+ return false;
+ matrix.erase(matrix.begin() + pos);
+ --width;
+ return true;
+}
+
+template<class T>
+bool PokeMod::Matrix<T>::Set(unsigned row, unsigned col, T &s)
+{
+ if ((width <= col) || (height <= col))
+ return false;
+ (matrix.begin() + col)->assign(row, s);
+ return true;
+}
+
+template<class T>
+T PokeMod::Matrix<T>::Get(unsigned row, unsigned col)
+{
+ if ((width <= col) || (height <= col))
+ return T();
+ return matrix[col][row];
+}
+
+template<class T>
+std::vector<T> PokeMod::Matrix<T>::GetRow(unsigned row)
+{
+ std::vector<T> r;
+ for (std::vector<T> *i = matrix.begin(); i != matrix.end(); ++i)
+ r.push_back(i->at(row));
+ return r;
+}
+
+template<class T>
+std::vector<T> PokeMod::Matrix<T>::GetCol(unsigned col)
+{
+ return matrix[col];
+}
+
+template<class T>
+unsigned PokeMod::Matrix<T>::GetHeight()
+{
+ return height;
+}
+
+template<class T>
+unsigned PokeMod::Matrix<T>::GetWidth()
+{
+ return width;
+}
+
+template<class T>
+T PokeMod::Matrix<T>::operator[](Point &p)
+{
+ return matrix[p.GetY()][p.GetX()];
+}
+
+template<class T>
+std::vector<T> PokeMod::Matrix<T>::operator[](int col)
+{
+ return matrix[col];
+}
diff --git a/pokemod/Matrix.h b/pokemod/Matrix.h
new file mode 100644
index 00000000..3bdd806f
--- /dev/null
+++ b/pokemod/Matrix.h
@@ -0,0 +1,67 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Matrix.h
+// Purpose: A 2D vector class
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Sun Apr 8 12:51:20 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_MATRIX__
+#define __POKEMOD_MATRIX__
+
+#include <vector>
+#include "Point.h"
+#include "Xml.h"
+
+namespace PokeMod
+{
+ template<class T> class Matrix
+ {
+ public:
+ Matrix();
+ Matrix(unsigned w, unsigned h, T &d = T());
+ Matrix(XmlElement &xml);
+
+ void ImportXml(XmlElement &xml);
+ XmlElement ExportXml(const String &val);
+
+ void AddRow(T &d = T());
+ void AddCol(T &d = T());
+ bool InsertRow(unsigned pos, T &d = T());
+ bool InsertCol(unsigned pos, T &d = T());
+ bool DeleteRow(unsigned pos);
+ bool DeleteCol(unsigned pos);
+
+ bool Set(unsigned row, unsigned col, T &s);
+
+ T Get(unsigned row, unsigned col);
+ std::vector<T> GetRow(unsigned row);
+ std::vector<T> GetCol(unsigned col);
+ unsigned GetHeight();
+ unsigned GetWidth();
+
+ T operator[](Point &p);
+ std::vector<T> operator[](int col);
+ private:
+ std::vector< std::vector<T> > matrix;
+ unsigned height;
+ unsigned width;
+ };
+}
+
+#endif
diff --git a/pokemod/Nature.cpp b/pokemod/Nature.cpp
new file mode 100644
index 00000000..857ff427
--- /dev/null
+++ b/pokemod/Nature.cpp
@@ -0,0 +1,181 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: 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 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Nature.h"
+
+PokeMod::Nature::Nature(unsigned _id)
+{
+ LogCtor("Nature", _id);
+ name = "";
+ effects.clear();
+ id = _id;
+}
+
+PokeMod::Nature::Nature(XmlElement &xml, unsigned _id)
+{
+ LogCtorXml("Nature", _id);
+ ImportXml(xml, _id);
+ if (id == UINT_MAX)
+ LogIdError("Nature");
+}
+
+PokeMod::Nature::~Nature()
+{
+ LogDtor("Nature", id, name);
+}
+
+#ifdef POKEMODR
+void PokeMod::Nature::Validate(wxListBox &output)
+#else
+void PokeMod::Nature::Validate()
+#endif
+{
+ isValid = true;
+ LogValidateStart("Nature", id, name);
+ if (name == "")
+ {
+ LogVarNotSet("Nature", "name", id);
+# ifdef POKEMODR
+ output.Append(ConsoleLogVarNotSet("Nature", "name", id);
+# endif
+ isValid = false;
+ }
+ if (GetNatureEffectCount())
+ {
+ for (unsigned i = 0; i < GetNatureEffectCount(); ++i)
+ {
+ LogSubmoduleIterate("Nature", "effect", i, id, name);
+ if (!effects[i].IsValid())
+ isValid = false;
+ }
+ }
+ else
+ {
+ LogSubmoduleEmpty("Nature", "effects", id, name);
+# ifdef POKEMODR
+ output.Append(ConsoleLogSubmoduleEmpty("Nature", "effects", id, name));
+# endif
+ isValid = false;
+ }
+ LogValidationOver("Nature", isValid, id, name);
+}
+
+void PokeMod::Nature::ImportXml(XmlElement &xml, unsigned _id)
+{
+ LogImport("Nature");
+ String curName;
+ if (_id == UINT_MAX)
+ {
+ xml.GetValue(id);
+ // Was there an id associated with the element?
+ if (id == UINT_MAX)
+ LogIdNotFound("Nature");
+ }
+ else
+ id = _id;
+ name = "";
+ effects.clear();
+ xml.ClearCounter();
+ for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ {
+ curName = child->GetName();
+ if (curName == "name")
+ child->GetValue(name);
+ else if (curName == "effect")
+ effects.push_back(NatureEffect(*child));
+ else
+ LogUnknownXml("Nature", curName);
+ }
+ LogImportOver("Nature");
+}
+
+PokeMod::XmlElement PokeMod::Nature::ExportXml()
+{
+ LogExportStart("Nature");
+ XmlElement exNature("nature", id, true);
+ exNature.AddElement("name", name);
+ for (std::vector<NatureEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
+ exNature.AddElement(i->ExportXml());
+ LogExportOver("Nature");
+ return exNature;
+}
+
+void PokeMod::Nature::SetName(const String &n)
+{
+ LogSetVar("Nature", "name", id, INT_MIN, n);
+ name = n;
+}
+
+PokeMod::String PokeMod::Nature::GetName()
+{
+ LogFetchVar("Nature", "name", id, INT_MIN, name);
+ return name;
+}
+
+PokeMod::NatureEffect *PokeMod::Nature::GetNatureEffect(unsigned _id)
+{
+ LogSubmoduleFetch("Nature", "effect", _id, id, name);
+ for (unsigned i = 0; i < GetNatureEffectCount(); ++i)
+ {
+ if (effects[i].GetId() == _id)
+ return &effects[i];
+ }
+ LogSubmodule("Nature", "effect", _id, id, name);
+ return NULL;
+}
+
+unsigned PokeMod::Nature::GetNatureEffectCount()
+{
+ LogSubmoduleCount("Nature", "effects", id, name);
+ return effects.size();
+}
+
+void PokeMod::Nature::NewNatureEffect()
+{
+ unsigned i = 0;
+ // Find the first unused ID in the vector
+ for (; i < GetNatureEffectCount(); ++i)
+ {
+ if (!GetNatureEffect(i))
+ break;
+ }
+ NatureEffect newNatureEffect(i);
+ if (xml)
+ newNatureEffect.ImportXml(*xml);
+ LogSubmoduleNew("Nature", "effect", i, id, name);
+ effects.push_back(newNatureEffect);
+}
+
+void PokeMod::Nature::DeleteNatureEffect(unsigned _id)
+{
+ LogSubmoduleRemoveStart("Nature", "effect", _id, id, name);
+ for (std::vector<NatureEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
+ {
+ if (i->GetId() == _id)
+ {
+ LogSubmoduleRemoved("Nature", "effect", _id, id, name);
+ effects.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Nature", "effect", _id, id, name);
+}
diff --git a/pokemod/Nature.h b/pokemod/Nature.h
new file mode 100644
index 00000000..10c7251b
--- /dev/null
+++ b/pokemod/Nature.h
@@ -0,0 +1,66 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Nature.h
+// 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 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_NATURE__
+#define __POKEMOD_NATURE__
+
+#include <vector>
+#include <list>
+#include "Object.h"
+#include "String.h"
+#include "NatureEffect.h"
+
+namespace PokeMod
+{
+ class Nature: public Object
+ {
+ public:
+ Nature(unsigned _id);
+ Nature(XmlElement &xml, unsigned _id = UINT_MAX);
+ ~Nature();
+
+ void ImportXml(XmlElement &xml, unsigned _id = UINT_MAX);
+ XmlElement ExportXml();
+
+ void SetName(const String &n);
+
+ String GetName();
+
+ NatureEffect *GetNatureEffect(unsigned _id);
+ unsigned GetNatureEffectCount();
+ void NewNatureEffect(XmlElement *xml = NULL);
+ void DeleteNatureEffect(unsigned _id);
+ private:
+# ifdef POKEMODR
+ void Validate(wxListBox &output);
+# else
+ void Validate();
+# endif
+
+ String name;
+
+ std::vector<NatureEffect> effects;
+ };
+}
+
+#endif
diff --git a/pokemod/Object.cpp b/pokemod/Object.cpp
new file mode 100644
index 00000000..c5d2af54
--- /dev/null
+++ b/pokemod/Object.cpp
@@ -0,0 +1,45 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Object.cpp
+// Purpose: Define the base members for all objects in a PokéMod
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Fri Feb 17 12:14:26 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Object.h"
+
+unsigned PokeMod::Object::GetId()
+{
+ LogFetchVar("Object", "ID", id);
+ return id;
+}
+
+bool PokeMod::Object::IsValid()
+{
+ Validate();
+ return isValid;
+}
+
+#ifdef POKEMODR
+bool PokeMod::Object::IsValid(const wxListBox &output)
+{
+ // Validate with debugging console output
+ Validate(output);
+ return isValid;
+}
+#endif
diff --git a/pokemod/Object.h b/pokemod/Object.h
new file mode 100644
index 00000000..11305ed4
--- /dev/null
+++ b/pokemod/Object.h
@@ -0,0 +1,59 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Object.h
+// Purpose: Define the base members for all objects in a PokéMod
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Wed Feb 14 23:44:39 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_OBJECT__
+#define __POKEMOD_OBJECT__
+
+#ifdef POKEMODR
+# include <wx/listbox.h>
+#endif
+
+#include "Debug.h"
+#include "Xml.h"
+
+namespace PokeMod
+{
+ class Object
+ {
+ public:
+ virtual ~Object();
+ virtual XmlElement ExportXml();
+
+ unsigned GetId();
+ bool IsValid();
+# ifdef POKEMODR
+ bool IsValid(wxListBox &output);
+# endif
+ protected:
+# ifdef POKEMODR
+ virtual void Validate(wxListBox &output = NULL);
+# else
+ virtual void Validate();
+# endif
+
+ bool isValid;
+ unsigned id;
+ };
+}
+
+#endif
diff --git a/pokemod/Path.cpp b/pokemod/Path.cpp
new file mode 100644
index 00000000..e93fcd52
--- /dev/null
+++ b/pokemod/Path.cpp
@@ -0,0 +1,91 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Path.cpp
+// Purpose: Define a derived class from the std::string for path extensions
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Tue Feb 20 10:15:43 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Path.h"
+
+PokeMod::Path::Path()
+{
+ assign("");
+}
+
+PokeMod::Path::Path(const char *s)
+{
+ assign(s);
+ Update();
+}
+
+PokeMod::Path::Path(const std::string &s)
+{
+ assign(s);
+ Update();
+}
+
+void PokeMod::Path::Update()
+{
+ if (!DoesExist())
+ assign("");
+}
+
+bool PokeMod::Path::DoesExist()
+{
+ if (*this == "")
+ return false;
+ // Try to open the file
+ std::ifstream test(c_str(), std::ios::in);
+ test.close();
+ if (test.fail())
+ return false;
+ return true;
+}
+
+bool PokeMod::Path::HasExtension(const String &ext)
+{
+ unsigned pos = rfind('.');
+ bool ret = true;
+ String fileExt(substr(pos + 1));
+ if ((pos == npos) || (pos + 1 == length()) || (fileExt.length() != ext.length()))
+ return false;
+ // Loop while the two are equal
+ for (unsigned i = 0; ret && (i < ext.length()); ++i)
+ ret = (tolower(ext[i]) == tolower(fileExt[i]));
+ return ret;
+}
+
+bool PokeMod::Path::CopyTo(const PMString &dest)
+{
+ if (!DoesExist())
+ return false;
+ std::ifstream fcur(c_str(), std::ios::in | std::ios::binary);
+ std::ofstream fcopy(dest.c_str(), std::ios::out | std::ios::binary);
+ if (fcur.bad() || fcopy.bad())
+ {
+ fcur.close();
+ fcopy.close();
+ return false;
+ }
+ while (!fcur.eof())
+ fcopy.put((char)fcur.get());
+ fcopy.close();
+ fcur.close();
+ return true;
+}
diff --git a/pokemod/Path.h b/pokemod/Path.h
new file mode 100644
index 00000000..441e280f
--- /dev/null
+++ b/pokemod/Path.h
@@ -0,0 +1,49 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Path.h
+// Purpose: Define a derived class from the std::string for path extensions
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Tue Feb 20 10:05:30 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_PATH__
+#define __POKEMOD_PATH__
+
+#include <string>
+#include <fstream>
+#include "String.h"
+
+namespace PokeMod
+{
+ class Path: public std::string
+ {
+ public:
+ Path();
+ Path(const char *s);
+ Path(const std::string &s);
+
+ void Update();
+ bool DoesExist();
+ bool HasExtension(const String &ext);
+ bool CopyTo(const String &dest);
+
+ Path &operator=(const char *path_);
+ };
+}
+
+#endif
diff --git a/pokemod/Point.cpp b/pokemod/Point.cpp
new file mode 100644
index 00000000..f92a2de7
--- /dev/null
+++ b/pokemod/Point.cpp
@@ -0,0 +1,56 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Point.cpp
+// Purpose: Define a coordinate point for use in a PokéMod
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Sun Apr 8 13:46:11 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Point.h"
+
+void PokeMod::Point::ImportXml(XmlElement &xml)
+{
+ String curName;
+ LogImportStart("Point");
+ x = 0;
+ y = 0;
+ xml.ClearCounter();
+ for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ {
+ curName = child->GetName();
+ if (curName == "x")
+ child->GetValue(x, 0);
+ else if (curName == "y")
+ child->GetValue(y, 0);
+ else
+ LogUnknownXml("Point", curName);
+ }
+ Log(String("Point Import: Imported (%d, %d)", x, y), PM_DEBUG_INFO);
+
+}
+
+PokeMod::XmlElement PokeMod::Point::ExportXml(const String &val)
+{
+ Log(String("Point Export: Starting (%d, %d) as %s", x, y, val.c_str()), PM_DEBUG_INFO);
+ // Declare the elements
+ XmlElement exPoint(val, 0, true);
+ exPoint.AddElement("x", x);
+ exPoint.AddElement("y", y);
+ Log(String("Point Export: Finished (%d, %d) as %s", x, y, val.c_str()), PM_DEBUG_INFO);
+ return exPoint;
+}
diff --git a/pokemod/Point.h b/pokemod/Point.h
new file mode 100644
index 00000000..9b220ca5
--- /dev/null
+++ b/pokemod/Point.h
@@ -0,0 +1,69 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Point.h
+// Purpose: Define a coordinate point for use in a PokéMod
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Sun Apr 8 12:53:15 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_POINT__
+#define __POKEMOD_POINT__
+
+#include "Debug.h"
+#include "Xml.h"
+
+namespace PokeMod
+{
+ class Point
+ {
+ public:
+ inline Point(): x(0), y(0) {}
+ inline Point(int _x, int _y): x(_x), y(_y) {}
+
+ void ImportXml(XmlElement &xml);
+ XmlElement ExportXml(const String &val);
+
+ inline void Set(int _x, int _y)
+ {
+ x = _x;
+ y = _y;
+ }
+ inline void SetX(int _x)
+ {
+ x = _x;
+ }
+ inline void SetY(int _y)
+ {
+ y = _y;
+ }
+
+ inline int GetX()
+ {
+ return x;
+ }
+ inline int GetY()
+ {
+ return y;
+ }
+ private:
+ int x;
+ int y;
+ };
+}
+
+#endif
diff --git a/pokemod/Ref.cpp b/pokemod/Ref.cpp
new file mode 100644
index 00000000..202481e4
--- /dev/null
+++ b/pokemod/Ref.cpp
@@ -0,0 +1,36 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Ref.h
+// Purpose: Define searching functions
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Thu Feb 15 10:21:05 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Ref.h"
+
+int PokeMod::FindIn(int end, const String &str, const char *array[])
+{
+ int i = 0;
+ // Loop through looking for where the string is in the array
+ for (; i < end; ++i)
+ {
+ if (str == array[i])
+ break;
+ }
+ return i;
+}
diff --git a/pokemod/Ref.h b/pokemod/Ref.h
new file mode 100644
index 00000000..c52ab151
--- /dev/null
+++ b/pokemod/Ref.h
@@ -0,0 +1,384 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Ref.h
+// Purpose: Define references for Objects
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Thu Feb 15 8:42:45 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_REF__
+#define __POKEMOD_REF__
+
+#include <vector>
+#include "String.h"
+
+// TODO (Comment#1#): Comment Ref
+
+namespace PokeMod
+{
+ int FindIn(int end, const String &str, const char *array[]);
+
+ enum AbilityEffect
+ {
+ AE_NONE = -1,
+ AE_DMG_TO_HP = 0,
+ AE_PRV_DMG = 1,
+ AE_AUTO_HEAL = 2,
+ AE_DEAL_DMG = 3,
+ AE_WILDS = 4,
+ AE_STATS = 5,
+ AE_STATUS = 6,
+ AE_ABILITY = 7,
+ AE_ACC_POWER = 8,
+ AE_BULLSEYE = 9,
+ AE_ITEM_EFFECT = 10,
+ AE_TYPE = 11,
+ AE_FAST_HATCH = 12,
+ AE_WEATHER = 13,
+ AE_END = 14
+ };
+ const char *AbilityEffectStr[AE_END] = {"Damage to HP", "Prevent Damage", "Auto Heal", "Deal Damage", "Wilds", "Stat", "Status", "Ability", "Accuracy/Power Trade", "Bullseye", "Item Effect", "Type", "Fast Hatch", "Weather"};
+
+ enum AbilityTrigger
+ {
+ AT_NONE = -1,
+ AT_ANYTHING = 0,
+ AT_CONTACT = 1,
+ AT_WEATHER = 2,
+ AT_DMG = 3,
+ AT_TYPE = 4,
+ AT_HP_BOUND = 5,
+ AT_STAT_CHANGE = 6,
+ AT_STATUS = 7,
+ AT_END = 8
+ };
+ const char *AbilityTriggerStr[AT_END] = {"Anything", "Contact", "Weather", "Damage", "Type", "HP Boundary", "Stat Change", "Status"};
+
+ enum Stat
+ {
+ ST_NONE = -1,
+ ST_ATTACK = 0,
+ ST_DEFENSE = 1,
+ ST_SPEED = 2,
+ ST_SPECIAL = 3,
+ ST_END_RBY = 4,
+ ST_SPECIAL_ATTACK = 3,
+ ST_SPECIAL_DEFENSE = 4,
+ ST_END_GSC = 5
+ };
+ const char *StatRBYStr[ST_END_RBY] = {"Attack", "Defense", "Speed", "Special"};
+ const char *StatGSCStr[ST_END_GSC] = {"Attack", "Defense", "Speed", "Special Attack", "Special Defense"};
+
+ enum StatHP
+ {
+ STH_NONE = -1,
+ STH_HP = 0,
+ STH_ATTACK = 1,
+ STH_DEFENSE = 2,
+ STH_SPEED = 3,
+ STH_SPECIAL = 4,
+ STH_END_RBY = 5,
+ STH_SPECIAL_ATTACK = 4,
+ STH_SPECIAL_DEFENSE = 5,
+ STH_END_GSC = 6,
+ };
+ const char *StatHPRBYStr[STH_END_RBY] = {"HP", "Attack", "Defense", "Speed", "Special"};
+ const char *StatHPGSCStr[STH_END_GSC] = {"HP", "Attack", "Defense", "Speed", "Special Attack", "Special Defense"};
+
+ enum BattleStat
+ {
+ BST_NONE = -1,
+ BST_ATTACK = 0,
+ BST_DEFENSE = 1,
+ BST_SPEED = 2,
+ BST_SPECIAL = 3,
+ BST_SPECIAL_ATTACK = 3,
+ BST_SPECIAL_DEFENSE = 4,
+ BST_ACCURACY = 5,
+ BST_EVASION = 6,
+ BST_END = 7,
+ };
+ const char *BattleStatRBYStr[BST_END] = {"Attack", "Defense", "Speed", "Special", "Special", "Accuracy", "Evasion"};
+ const char *BattleStatGSCStr[BST_END] = {"Attack", "Defense", "Speed", "Special Attack", "Special Defense", "Accuracy", "Evasion"};
+
+ enum BattleStatHP
+ {
+ BSTH_NONE = -1,
+ BSTH_HP = 0,
+ BSTH_ATTACK = 1,
+ BSTH_DEFENSE = 2,
+ BSTH_SPEED = 3,
+ BSTH_SPECIAL = 4,
+ BSTH_SPECIAL_ATTACK = 4,
+ BSTH_SPECIAL_DEFENSE = 5,
+ BSTH_ACCURACY = 6,
+ BSTH_EVASION = 7,
+ BSTH_END = 8,
+ };
+ const char *BattleStatHPRBYStr[BSTH_END] = {"HP", "Attack", "Defense", "Speed", "Special", "Special", "Accuracy", "Evasion"};
+ const char *BattleStatHPGSCStr[BSTH_END] = {"HP", "Attack", "Defense", "Speed", "Special Attack", "Special Defense", "Accuracy", "Evasion"};
+
+ enum BattleMember
+ {
+ BM_NONE = -1,
+ BM_PLAYER = 0,
+ BM_ENEMY = 1,
+ BM_END = 2
+ };
+ const char *BattleMemberStr[BM_END] = {"Player", "Enemy"};
+
+ enum Status
+ {
+ STS_NONE = -1,
+ STS_FREEZE = 0,
+ STS_PARALYZE = 1,
+ STS_SLEEP = 2,
+ STS_POISON = 3,
+ STS_TOXIC_POISON = 4,
+ STS_BURN = 5,
+ STS_END_SHOW = 6,
+ STS_ANY_SHOW = 6,
+ STS_END_SHOW_ANY = 7,
+ STS_CONFUSED = 6,
+ STS_END_CNF = 7,
+ STS_ANY = 7,
+ STS_END_ANY = 8,
+ };
+ const char *StatusShowStr[STS_END_SHOW_ANY] = {"Freeze", "Paralyze", "Sleep", "Poison", "Toxic Poison", "Burn", "Any"};
+ const char *StatusStr[STS_END_ANY] = {"Freeze", "Paralyze", "Sleep", "Poison", "Toxic Poison", "Burn", "Confuse", "Any"};
+ const char *StatusAbbrStr[STS_END_SHOW] = {"FRZ", "PRZ", "SLP", "PSN", "PSN", "BRN"};
+
+ enum Cause
+ {
+ CA_NONE = -1,
+ CA_PREVENT = 0,
+ CA_INFLICT = 1,
+ CA_END = 2
+ };
+ const char *CauseStr[CA_END] = {"Prevent", "Inflict"};
+
+ enum AbilityInteract
+ {
+ ABI_NONE = -1,
+ ABI_TRADE = 0,
+ ABI_SHADOW = 1,
+ ABI_BLOCK = 2,
+ ABI_END = 3
+ };
+ const char *AbilityInteractStr[ABI_END] = {"Trade", "Shadow", "Block"};
+
+ enum PowerAcc
+ {
+ PA_NONE = -1,
+ PA_POWER = 0,
+ PA_ACC = 1,
+ PA_END = 2
+ };
+ const char *PowerAccStr[PA_END] = {"Boost Power", "Boost Accuracy"};
+
+ enum AbilityItem
+ {
+ ABIT_NONE = -1,
+ ABIT_STAT = 0,
+ ABIT_TYPE_BOOST = 1,
+ ABIT_FLINCH = 2,
+ ABIT_QUICK = 3,
+ ABIT_END = 4
+ };
+ const char *AbilityItemStr[ABIT_END] = {"Stat Modifier", "Type Booster", "Flinch", "Go First"};
+
+ enum Weather
+ {
+ W_NONE = -1,
+ W_ICE = 0,
+ W_RAIN = 1,
+ W_SUN = 2,
+ W_SAND = 3,
+ W_END_REAL = 4,
+ W_ALL = 4,
+ W_END_ALL = 5
+ };
+ const char *WeatherStr[W_END_ALL] = {"Ice", "Rain", "Sun", "Sand", "All"};
+
+ enum Boost
+ {
+ BO_NONE = -1,
+ BO_BOOST = 0,
+ BO_HINDER = 1,
+ BO_END = 2
+ };
+ const char *BoostStr[BO_END] = {"Boost", "Hinder"};
+
+ enum Side
+ {
+ SI_NONE = -1,
+ SI_ABOVE = 0,
+ SI_BELOW = 1,
+ SI_END = 2
+ };
+ const char *SideStr[SI_END] = {"Above", "Below"};
+
+ enum HMMove
+ {
+ HM_NONE = -1,
+ HM_CUT = 0,
+ HM_FLY = 1,
+ HM_SURF = 2,
+ HM_STRENGTH = 3,
+ HM_FLASH = 4,
+ HM_WHIRLPOOL = 5,
+ HM_WATERFALL = 6,
+ HM_DIVE = 7,
+ HM_HEADBUTT = 8,
+ HM_ROCK_SMASH = 9,
+ HM_END = 10
+ };
+ const char *HMStr[HM_END] = {"Cut", "Fly", "Surf", "Strength", "Flash", "Whirlpool", "Waterfall", "Dive", "Headbutt", "Rock Smash"};
+
+ enum StatVersion
+ {
+ STV_NONE = -1,
+ STV_RBY = 0,
+ STV_GSC = 1,
+ STV_END = 2
+ };
+
+ enum FlagValue
+ {
+ FV_NONE = -1,
+ FV_SET = 0,
+ FV_UNSET = 1,
+ FV_IGNORE = 2,
+ FV_END = 3
+ };
+ const char *FlagValueStr[FV_END] = {"Set", "Unset", "Ignore"};
+
+
+ enum CoinItemType
+ {
+ CIT_NONE = -1,
+ CIT_ITEM = 0,
+ CIT_POKEMON = 1,
+ CIT_END = 2
+ };
+ const char *CoinItemTypeStr[CIT_END] = {"Item", "Pokémon"};
+
+ enum ItemEffect
+ {
+ IE_NONE = -1,
+ IE_HP_CURE = 0,
+ IE_REVIVE = 1,
+ IE_CURE_STATUS = 2,
+ IE_LEVEL_BOOST = 3,
+ IE_STAT_BOOST = 4,
+ IE_FLINCH = 5,
+ IE_FIRST = 6,
+ IE_KEEP_ALIVE = 7,
+ IE_MODIFY_STAT_BAT = 8,
+ IE_SHIELD_BAT = 9,
+ IE_RUN_BAT = 10,
+ IE_PP_BOOST = 11,
+ IE_TYPE_BOOST = 12,
+ IE_PP_RESTORE = 13,
+ IE_EXP_SHARE = 14,
+ IE_FISH = 15,
+ IE_REPEL = 16,
+ IE_ESCAPE = 17,
+ IE_TM = 18,
+ IE_HM = 19,
+ IE_MAP = 20,
+ IE_BALL = 21,
+ IE_ITEMFINDER = 22,
+ IE_BIKE = 23,
+ IE_SCOPE = 24,
+ IE_COIN = 25,
+ IE_COIN_CASE = 26,
+ IE_BERRY = 27,
+ IE_ACORN = 28,
+ IE_END = 29
+ };
+ const char *ItemEffectStr[IE_END] = {"HP Cure", "Revive", "Cure Status", "Level Boost", "Stat Boost", "Flinch", "Go First", "Keep Alive", "Modify Stat (Battle Only)", "Shield (Battle Only)", "Run (Battle Only)", "PP Boost", "Type Boost", "PP Restore", "Experience Share", "Fishing Rod", "Repel", "Escape", "TM", "HM", "Map", "Ball", "Itemfinder", "Bike", "Scope", "Coin", "Coin Case", "Berry", "Acorn"};
+
+ enum Relative
+ {
+ REL_NONE = -1,
+ REL_ABSOLUTE = 0,
+ REL_RELATIVE = 1,
+ REL_END = 2
+ };
+ const char *RelativeStr[REL_END] = {"Absolute", "Relative"};
+
+ enum Escape
+ {
+ ESC_NONE = -1,
+ ESC_ANYWHERE = 0,
+ ESC_DUNGEON = 1,
+ ESC_END = 2
+ };
+ const char *EscapeStr[ESC_END] = {"Anywhere", "Dungeon"};
+
+ enum Repel
+ {
+ REP_NONE = -1,
+ REP_FIRST = 0,
+ REP_MAX = 1,
+ REP_ALL = 2,
+ REP_END = 3
+ };
+ const char *RepelStr[REP_END] = {"First", "Max", "All"};
+
+ enum Amount
+ {
+ AMT_NONE = -1,
+ AMT_ALL = 0,
+ AMT_ONE = 1,
+ AMT_END = 2
+ };
+ const char *AmountStr[AMT_END] = {"All", "One"};
+
+ // TODO (Ben#1#): More BallType(?)
+ enum BallType
+ {
+ BLT_NONE = -1,
+ BLT_REGULAR = 0,
+ BLT_MASTER = 1,
+ BLT_LEVEL = 2,
+ BLT_LOVE = 3,
+ BLT_AREA = 4,
+ BLT_TIME = 5,
+ BLT_BATTLE = 6,
+ BLT_FRIEND = 7,
+ BLT_STAT = 8,
+ BLT_END = 9
+ };
+ const char *BallTypeStr[BLT_END] = {"Regular", "Master", "Level", "Love", "Area", "Time", "Battle", "Friend", "Stat"};
+
+ // TODO (Ben#1#): More BerryType(?)
+ enum BerryType
+ {
+ BRT_NONE = -1,
+ BRT_HP_CURE = 0,
+ BRT_STATUS_CURE = 1,
+ BRT_END = 2
+ };
+ const char *BerryTypeStr[BRT_END] = {"HP Cure", "Status Cure"};
+
+// PMenum
+}
+
+#endif
diff --git a/pokemod/String.cpp b/pokemod/String.cpp
new file mode 100644
index 00000000..fa7d4536
--- /dev/null
+++ b/pokemod/String.cpp
@@ -0,0 +1,133 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: String.cpp
+// Purpose: A custom string class derived from the C++ standard string
+// to accomodate simple format functionality
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Mon Feb 19 22:03:45 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "String.h"
+
+PokeMod::String::String(const std::string &str)
+{
+ assign(str);
+}
+
+PokeMod::String::String(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ printf(fmt, args);
+ va_end(args);
+}
+
+void PokeMod::String::printf(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ printf(fmt, args);
+ va_end(args);
+}
+
+void PokeMod::String::printf(const char *fmt, va_list &args)
+{
+ Format unit;
+ std::stringstream ss;
+ const char *p = fmt;
+ while (*p)
+ {
+ if (*p == '%')
+ {
+ if (*++p)
+ {
+ switch (*p)
+ {
+ // C-strings
+ case 's':
+ unit.s = va_arg(args, const char *);
+ append(unit.s);
+ break;
+ // Integers
+ case 'i':
+ case 'd':
+ unit.i = va_arg(args, int);
+ ss.str("");
+ ss << unit.i;
+ append(ss.str());
+ break;
+ // Unsigned integers
+ case 'u':
+ unit.u = va_arg(args, unsigned);
+ ss.str("");
+ ss << unit.u;
+ append(ss.str());
+ break;
+ // Longs
+ case 'I':
+ case 'D':
+ unit.l = va_arg(args, long);
+ ss.str("");
+ ss << unit.l;
+ append(ss.str());
+ break;
+ // Unsigned longs
+ case 'U':
+ unit.ul = va_arg(args, unsigned long);
+ ss.str("");
+ ss << unit.ul;
+ append(ss.str());
+ break;
+ // Characters
+ case 'c':
+ unit.c = (char)va_arg(args, int);
+ append(1, unit.c);
+ break;
+ // Floats
+ case 'f':
+ unit.f = va_arg(args, double);
+ ss.str("");
+ ss << unit.f;
+ append(ss.str());
+ break;
+ // Percent character
+ case '%':
+ append(1, '%');
+ break;
+ // Unknown sequence
+ default:
+ append(1, '%');
+ append(1, *p);
+ }
+ }
+ else
+ {
+ append(1, '%');
+ break;
+ }
+ }
+ else
+ append(1, *p);
+ ++p;
+ }
+}
+
+PokeMod::String::operator const char *()
+{
+ return c_str();
+}
diff --git a/pokemod/String.h b/pokemod/String.h
new file mode 100644
index 00000000..df80e42c
--- /dev/null
+++ b/pokemod/String.h
@@ -0,0 +1,60 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: String.h
+// Purpose: A custom string class derived from the C++ standard string
+// to accomodate simple format functionality
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Mon Feb 19 22:07:02 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_STRING__
+#define __POKEMOD_STRING__
+
+#include <cstdarg>
+#include <string>
+#include <sstream>
+#include <iostream>
+
+namespace PokeMod
+{
+ class String: public std::string
+ {
+ public:
+ String(const std::string &str);
+ String(const char *fmt = "", ...);
+
+ void printf(const char *fmt, ...);
+
+ operator const char *();
+ private:
+ typedef union
+ {
+ const char *s;
+ char c;
+ double f;
+ int i;
+ unsigned u;
+ long l;
+ unsigned long ul;
+ }Format;
+
+ void printf(const char *fmt, va_list &args);
+ };
+}
+
+#endif
diff --git a/pokemod/Xml.cpp b/pokemod/Xml.cpp
new file mode 100644
index 00000000..47d574e1
--- /dev/null
+++ b/pokemod/Xml.cpp
@@ -0,0 +1,492 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Xml.cpp
+// Purpose: An XML container for importing and exporting Pokémod files
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Sun Apr 8 16:07:46 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Xml.h"
+
+PokeMod::XmlElement::XmlElement(const String &p)
+{
+ std::ifstream f(p.c_str(), std::ios::in | std::ios::binary);
+ if (!f)
+ isValid = false;
+ else
+ {
+ isValid = Load(f);
+ f.close();
+ }
+ isTag = true;
+ pos = 0;
+}
+
+PokeMod::XmlElement::XmlElement(const String &n, int v)
+{
+ std::cout << "Making int value Element: " << v << "\n";
+ name = n;
+ value.printf("%d", v);
+ isTag = false;
+}
+
+PokeMod::XmlElement::XmlElement(const String &n, unsigned v, bool isId)
+{
+ std::cout << "Making unsigned value Element: " << v << "\n";
+ name = n;
+ isTag = isId;
+ pos = 0;
+ value.printf("%u", v);
+}
+
+PokeMod::XmlElement::XmlElement(const String &n, const String &v)
+{
+ std::cout << "Making string value Element: " << v << "\n";
+ name = n;
+ value = v;
+ isTag = false;
+}
+
+PokeMod::XmlElement::XmlElement(const String &n, bool v)
+{
+ std::cout << "Making bool value Element: " << v << "\n";
+ name = n;
+ value = v ? "true" : "false";
+ isTag = false;
+}
+
+PokeMod::XmlElement::~XmlElement()
+{
+ std::cout << "Destroying " << name << "\n";
+}
+
+void PokeMod::XmlElement::Export(std::ofstream &file, unsigned depth)
+{
+ file << std::string(depth, ' ');
+ if (isTag)
+ {
+ file << '<' << name << " " << value << ">\n";
+ for (std::vector<XmlElement>::iterator i = elements.begin(); i != elements.end(); ++i)
+ i->Export(file, depth + 3);
+ file << std::string(depth, ' ');
+ file << "</" << name << ">\n";
+ }
+ else
+ {
+ unsigned pos;
+ String v = value;
+ while ((pos = v.find("&")) != std::string::npos)
+ v.replace(pos, 1, "&amp;");
+ while ((pos = v.find("<")) != std::string::npos)
+ v.replace(pos, 1, "&lt;");
+ while ((pos = v.find(">")) != std::string::npos)
+ v.replace(pos, 1, "&gt;");
+ while ((pos = v.find("\"")) != std::string::npos)
+ v.replace(pos, 1, "&quot;");
+ while ((pos = v.find("\'")) != std::string::npos)
+ v.replace(pos, 1, "&apos;");
+ file << '<' << name << '>' << v << "</" << name << ">\n";
+ }
+}
+
+PokeMod::XmlElement *PokeMod::XmlElement::AddElement(const XmlElement &xml)
+{
+ if (!isTag)
+ return NULL;
+ elements.push_back(xml);
+ std::cout << "Adding an element...\n";
+ return &elements.back();
+}
+
+PokeMod::XmlElement *PokeMod::XmlElement::AddElement(const String &n, int v)
+{
+ if (!isTag)
+ return NULL;
+ elements.push_back(xml);
+ XmlElement add(n, v);
+ elements.push_back(add);
+ return &elements.back();
+}
+
+PokeMod::XmlElement *PokeMod::XmlElement::AddElement(const String &n, unsigned v, bool isId)
+{
+ if (!isTag)
+ return NULL;
+ elements.push_back(xml);
+ XmlElement add(n, v, isId);
+ elements.push_back(add);
+ return &elements.back();
+}
+
+PokeMod::XmlElement *PokeMod::XmlElement::AddElement(const String &n, const String &v)
+{
+ if (!isTag)
+ return NULL;
+ elements.push_back(xml);
+ XmlElement add(n, v);
+ elements.push_back(add);
+ return &elements.back();
+}
+
+PokeMod::XmlElement *PokeMod::XmlElement::AddElement(const String &n, bool v)
+{
+ if (!isTag)
+ return NULL;
+ elements.push_back(xml);
+ XmlElement add(n, v);
+ elements.push_back(add);
+ return &elements.back();
+}
+
+PokeMod::XmlElement *PokeMod::XmlElement::NextElement()
+{
+ if ((elements.size() <= pos) || !isTag)
+ return NULL;
+ std::cout << '\n' << &elements[pos] << '\n';
+ return &elements[pos++];
+}
+
+void PokeMod::XmlElement::ClearCounter()
+{
+ pos = 0;
+}
+
+PokeMod::String PokeMod::XmlElement::GetName()
+{
+ return name;
+}
+
+void PokeMod::XmlElement::GetValue(int &val, int def)
+{
+ if (!ExtractInt(val, value))
+ val = def;
+}
+
+void PokeMod::XmlElement::GetValue(unsigned &val, unsigned def)
+{
+ if (!ExtractUnsigned(val, value))
+ val = def;
+}
+
+void PokeMod::XmlElement::GetValue(String &val, const String &def)
+{
+ val = isTag ? def : value;
+}
+
+void PokeMod::XmlElement::GetValue(bool &val, bool def)
+{
+ val = isTag ? def : (value == "true");
+}
+
+bool PokeMod::XmlElement::IsValid()
+{
+ return isValid;
+}
+
+bool PokeMod::XmlElement::Save(const String &p)
+{
+ std::ofstream f(p.c_str(), std::ios::out | std::ios::binary);
+ if (!f)
+ return false;
+ else
+ {
+ f << "<?xml version=\"PokéGen\" encoding=\"UTF-8\" ?>\n";
+ Export(f);
+ f.close();
+ }
+ return true;
+}
+
+bool PokeMod::XmlElement::Load(std::ifstream &file)
+{
+ String curLine;
+ String curName;
+ String curValue;
+ std::stack<String> openElements;
+ std::stack<XmlElement *> prevElements;
+ XmlElement *curElement = this;
+ prevElements.push(this);
+ unsigned count = 0;
+ bool isClosing;
+ LinePos pos;
+ bool isId = false;
+ isValid = true;
+ // First line checks
+ std::getline(file, curLine);
+ if (curLine != "<?xml version=\"PokéGen\" encoding=\"UTF-8\" ?>")
+ return (isValid = false);
+ std::getline(file, curLine);
+ if (curLine[count] != '<')
+ isValid = false;
+ std::cout << (isValid ? "Valid\n" : "Not valid\n");
+ if (isValid)
+ {
+ ++count;
+ isValid = ReadValue(name, curLine, count, true);
+ openElements.push(name);
+ if ((curLine[count] != ' '))
+ isValid = false;
+ else
+ {
+ ++count;
+ isValid = ReadValue(curValue, curLine, count);
+ }
+ std::cout << (isValid ? "Valid\n" : "Not valid\n");
+ }
+ std::getline(file, curLine);
+ std::cout << (isValid ? "Valid\n" : "Not valid\n");
+ while (file.good() && isValid)
+ {
+ std::cout << "\nParsing line: \"" << curLine << '\"';
+ count = 0;
+ pos = POS_INDENT;
+ while ((count < curLine.size()) && isValid)
+ {
+ std::cout << "\nParsing char: \'" << curLine[count] << "\'\n";
+ switch (curLine[count])
+ {
+ case ' ':
+ case '\"':
+ break;
+ case '<':
+ if (pos == POS_INDENT)
+ {
+ if (curLine[++count] == '/')
+ {
+ isClosing = true;
+ ++count;
+ }
+ else
+ {
+ std::cout << "Finished indent...\n";
+ isClosing = false;
+ }
+ isValid = ReadValue(curName, curLine, count);
+ std::cout << "Found name: " << curName << '\n';
+ if (isClosing)
+ {
+ std::cout << "Found close of tag...\n";
+ if (curName == openElements.top())
+ {
+ curElement = prevElements.top();
+ prevElements.pop();
+ openElements.pop();
+ }
+ else
+ isValid = false;
+ }
+ else
+ {
+ std::cout << "Reading name...\n";
+ openElements.push(curName);
+ std::cout << "Next char: \'" << curLine[count] << "\'\n";
+ std::cout << "Reading type...\n";
+ pos = POS_VALUE;
+ if (curLine[count] == ' ')
+ {
+ isId = true;
+ ++count;
+ isValid = ReadValue(curValue, curLine, count);
+ }
+ }
+ }
+ else if (pos == POS_VALUE)
+ {
+ std::cout << "Found closing tag...\n";
+ pos = POS_END;
+ if (curLine[++count] != '/')
+ {
+ std::cout << "No slash!...\n";
+ isValid = false;
+ break;
+ }
+ isValid = ReadValue(curName, curLine, ++count);
+ std::cout << "Top element is: \"" << openElements.top() << "\"\n";
+ if (curName == openElements.top())
+ openElements.pop();
+ else
+ isValid = false;
+ }
+ else
+ isValid = false;
+ break;
+ case '>':
+ std::cout << "Closing bracket...\n";
+ if (pos == POS_VALUE)
+ {
+ ++count;
+ std::cout << "Reading value (\'" << curLine[count] << "\')...\n";
+ if (!isId)
+ isValid = ReadValue(curValue, curLine, count);
+ }
+ }
+ std::cout << (isValid ? "valid\n" : "not valid\n");
+ ++count;
+ }
+ if (isValid)
+ {
+ if (isId)
+ {
+ prevElements.push(curElement);
+ unsigned temp;
+ isValid = ExtractUnsigned(temp, curValue);
+ curElement = curElement->AddElement(curName, temp, true);
+ }
+ else
+ curElement->AddElement(curName, curValue);
+ }
+ else
+ break;
+ std::getline(file, curLine);
+ }
+ std::cout << (isValid ? "valid\n" : "not valid\n");
+ if (!openElements.size())
+ isValid = false;
+ return isValid;
+}
+
+bool PokeMod::XmlElement::ReadValue(String &v, const String &line, unsigned &pos, bool isId)
+{
+ unsigned start = pos;
+ bool notDone = true;
+ v.assign("");
+ while (notDone && (pos < line.length()))
+ {
+ std::cout << "parsing: " << line[pos] << '\n';
+ switch (line[pos])
+ {
+ case 'a' ... 'z':
+ case 'A' ... 'Z':
+ case '0' ... '9':
+ break;
+ case ' ':
+ if (isId)
+ {
+ --pos;
+ notDone = false;
+ }
+ break;
+ case '\n':
+ case '\r':
+ return false;
+ case '>':
+ if (isId)
+ {
+ --pos;
+ notDone = false;
+ }
+ else
+ isValid = false;
+ break;
+ case '&':
+ if (isId)
+ return false;
+ v.append(line.substr(start, pos - start));
+ if (line.substr(pos, 4) == "&amp;")
+ {
+ v += '&';
+ pos += 4;
+ }
+ else if (line.substr(pos, 4) == "&lt;")
+ {
+ v += '<';
+ pos += 3;
+ }
+ else if (line.substr(pos, 4) == "&gt;")
+ {
+ v += '>';
+ pos += 3;
+ }
+ else if (line.substr(pos, 6) == "&quot;")
+ {
+ v += '\"';
+ pos += 5;
+ }
+ else if (line.substr(pos, 6) == "&apos;")
+ {
+ v += '\'';
+ pos += 5;
+ }
+ start = pos + 1;
+ break;
+ default:
+ if (isId)
+ return false;
+ }
+ ++pos;
+ }
+ v.append(line.substr(start, pos - start));
+ std::cout << "Read string as " << v << '\n';
+ return true;
+}
+
+bool PokeMod::XmlElement::ExtractInt(int &v, const String &str)
+{
+ bool notDone = true;
+ unsigned pos = 0;
+ bool isNegative = (str[pos] == '-');
+ if (isNegative)
+ ++pos;
+ v = 0;
+ while (notDone && (pos < str.length()))
+ {
+ switch (str[pos])
+ {
+ case '0' ... '9':
+ v = 10 * v + (str[pos] - '0');
+ break;
+ case '<':
+ --pos;
+ notDone = false;
+ break;
+ default:
+ return false;
+ }
+ ++pos;
+ }
+ if (isNegative)
+ v = -v;
+ std::cout << "Read int as " << v << '\n';
+ return true;
+}
+
+bool PokeMod::XmlElement::ExtractUnsigned(unsigned &v, const String &str)
+{
+ bool notDone = true;
+ unsigned pos = 0;
+ v = 0;
+ while (notDone && (pos < str.length()))
+ {
+ switch (str[pos])
+ {
+ case '0' ... '9':
+ v = 10 * v + (str[pos] - '0');
+ break;
+ case '\"':
+ case '<':
+ --pos;
+ notDone = false;
+ break;
+ default:
+ return false;
+ }
+ ++pos;
+ }
+ std::cout << "Read unsigned as " << v << '\n';
+ return true;
+}
diff --git a/pokemod/Xml.h b/pokemod/Xml.h
new file mode 100644
index 00000000..ac2e5df4
--- /dev/null
+++ b/pokemod/Xml.h
@@ -0,0 +1,88 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Xml.h
+// Purpose: An XML container for importing and exporting PokéMod files
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Sun Apr 8 13:57:37 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_ELEMENT__
+#define __POKEMOD_ELEMENT__
+
+#include <fstream>
+#include <vector>
+#include <stack>
+#include <sstream>
+//#include "Debug.h"
+#include "String.h"
+
+namespace PokeMod
+{
+ class XmlElement
+ {
+ public:
+ XmlElement(const String &p);
+ XmlElement(const String &n, int v);
+ XmlElement(const String &n, unsigned v, bool isId = false);
+ XmlElement(const String &n, const String &v);
+ XmlElement(const String &n, bool v);
+ ~XmlElement();
+
+ void Export(std::ofstream &file, unsigned depth = 0);
+
+ XmlElement *AddElement(const XmlElement &xml);
+ XmlElement *AddElement(const String &n, int v);
+ XmlElement *AddElement(const String &n, unsigned v, bool isId = false);
+ XmlElement *AddElement(const String &n, const String &v);
+ XmlElement *AddElement(const String &n, bool v);
+ XmlElement *NextElement();
+ void ClearCounter();
+
+ String GetName();
+ void GetValue(int &val, int def = -1);
+ void GetValue(unsigned &val, unsigned def = UINT_MAX);
+ void GetValue(String &val, const String &def = "");
+ void GetValue(bool &val, bool def = true);
+
+ bool Save(const String &p);
+
+ bool IsValid();
+ private:
+ enum LinePos
+ {
+ POS_INDENT = 0,
+ POS_VALUE = 1,
+ POS_END = 2
+ };
+
+ bool Load(std::ifstream &file);
+
+ bool ReadValue(String &v, const String &line, unsigned &pos, bool ignoreSpace = true);
+ bool ExtractInt(int &v, const String &str);
+ bool ExtractUnsigned(unsigned &v, const String &str);
+
+ String name;
+ String value;
+ bool isTag;
+ std::vector<XmlElement> elements;
+ unsigned pos;
+ bool isValid;
+ };
+}
+
+#endif
diff --git a/pokemod/pokemod_inc.h b/pokemod/pokemod_inc.h
new file mode 100644
index 00000000..999188cb
--- /dev/null
+++ b/pokemod/pokemod_inc.h
@@ -0,0 +1,56 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: pokemod_inc.h
+// Purpose: Include header for a PokéMod
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Thu Mar 22 20:53:22 2007
+// Copyright: ©2007 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 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
+// 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, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __POKEMOD_H__
+#define __POKEMOD_H__
+
+namespace PokeMod
+{
+ class PMAbility;
+ class PMAbilityEffect;
+ class PMAuthor;
+ class PMBadge;
+ class PMCoinItem;
+ class PMCoinList;
+ class PMDialog;
+ class PMItem;
+ class PMItemEffect;
+ class PMItemStorage;
+ class PMMapTrainerTeam;
+ class PMMapWildList;
+ class PMMapWildPokemon;
+ class PMMoveEffect;
+ class PMPokemod;
+ class PMPokemonAbility;
+ class PMPokemonEvolution;
+ class PMPokemonItem;
+ class PMPokemonMove;
+ class PMPokemonNature;
+ class PMStore;
+ class PMTime;
+ class PMType;
+}
+
+#include "Pokemod.h"
+
+#endif