summaryrefslogtreecommitdiffstats
path: root/pokemod/Nature.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2007-05-03 00:32:44 +0000
committerBen Boeckel <MathStuf@gmail.com>2007-05-03 00:32:44 +0000
commit0c6eac6b8ca7d363288890eda1a98ce167987d48 (patch)
treef37b5458200fe570d98d5052c44efa3237bffd5a /pokemod/Nature.cpp
Initial import
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@1 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Nature.cpp')
-rw-r--r--pokemod/Nature.cpp181
1 files changed, 181 insertions, 0 deletions
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);
+}