diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-05-23 02:24:14 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-05-23 02:24:14 +0000 |
| commit | 1a4b623c8ecb9d0c7d991312c12d78be4a68eff2 (patch) | |
| tree | 97e260380c334f8f55ac6d82f174ce8604d7dd6c /pokemod/Item.cpp | |
| parent | e858d98977a09b3c8faf4df87ada4abc1399e8e5 (diff) | |
| download | sigen-1a4b623c8ecb9d0c7d991312c12d78be4a68eff2.tar.gz sigen-1a4b623c8ecb9d0c7d991312c12d78be4a68eff2.tar.xz sigen-1a4b623c8ecb9d0c7d991312c12d78be4a68eff2.zip | |
Added more PokéMod modules
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@13 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Item.cpp')
| -rw-r--r-- | pokemod/Item.cpp | 283 |
1 files changed, 283 insertions, 0 deletions
diff --git a/pokemod/Item.cpp b/pokemod/Item.cpp new file mode 100644 index 00000000..70207def --- /dev/null +++ b/pokemod/Item.cpp @@ -0,0 +1,283 @@ +/////////////////////////////////////////////////////////////////////////////
+// Name: pokemod/Item.cpp
+// Purpose: Define an item
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Tue Mar 20 18:16:29 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 "Item.h"
+
+extern PokeGen::PokeMod::Pokemod curPokeMod;
+
+PokeGen::PokeMod::Item::Item(unsigned _id)
+{
+ LogCtor("Item", _id);
+ name = "";
+ sellable = false;
+ type = -1;
+ price = 0;
+ description = "";
+ effects.clear();
+ id = _id;
+}
+
+PokeGen::PokeMod::Item::Item(Ini &ini, unsigned _id)
+{
+ LogCtorIni("Item", _id);
+ ImportIni(ini);
+ if (id == UINT_MAX)
+ LogIdError();
+}
+
+PokeGen::PokeMod::Item::~Item()
+{
+ LogDtor("Item", id, name);
+}
+
+void PokeGen::PokeMod::Item::Validate()
+{
+ isValid = true;
+ LogValidateStart("Item", id, name);
+ if (name == "")
+ {
+ LogVarEmpty("Item", id, "name");
+ output.Append(ConsoleLogVarEmpty("Item", id, "name"));
+ isValid = false;
+ }
+ if (!curPokeMod.GetItemStorage(type))
+ {
+ LogVarNotValid("Item", id, "type", type, name);
+ output.Append(ConsoleLogVarNotValid("Item", id, "type", type, name));
+ isValid = false;
+ }
+ if (GetItemEffectCount())
+ {
+ for (unsigned i = 0; i < GetItemEffectCount(); ++i)
+ {
+ LogSubmoduleIterate("Item", id, "effect", i, name);
+ if (!effects[i].IsValid())
+ isValid = false;
+ }
+ }
+ else
+ {
+ LogSubmoduleEmpty("Item", id, "effect", name);
+ output.Append(ConsoleLogSubmoduleEmpty("Item", id, "effect", name));
+ isValid = false;
+ }
+ LogValidateOver("Item", id, isValid, name);
+}
+
+#ifdef PG_DEBUG_WINDOW
+void PokeGen::PokeMod::Item::Validate(const wxListBox &output)
+{
+ isValid = true;
+ LogValidateStart("Item", id, name);
+ if (name == "")
+ {
+ LogVarEmpty("Item", id, "name");
+ output.Append(ConsoleLogVarEmpty("Item", id, "name"));
+ isValid = false;
+ }
+ if (!curPokeMod.GetItemStorage(type))
+ {
+ LogVarNotValid("Item", id, "type", type, name);
+ output.Append(ConsoleLogVarNotValid("Item", id, "type", type, name));
+ isValid = false;
+ }
+ if (GetItemEffectCount())
+ {
+ for (unsigned i = 0; i < GetItemEffectCount(); ++i)
+ {
+ LogSubmoduleIterate("Item", id, "effect", i, name);
+ if (!effects[i].IsValid())
+ isValid = false;
+ }
+ }
+ else
+ {
+ LogSubmoduleEmpty("Item", id, "effect", name);
+ output.Append(ConsoleLogSubmoduleEmpty("Item", id, "effect", name));
+ isValid = false;
+ }
+ LogValidateOver("Item", id, isValid, name);
+}
+#endif
+
+void PokeGen::PokeMod::Item::ImportIni(Ini &ini, unsigned _id)
+{
+ LogImportStart("Item");
+ if (_id == UINT_MAX)
+ {
+ ini.GetValue("id", id, UINT_MAX);
+ // Was there an id associated with the element?
+ if (id == UINT_MAX)
+ LogIdNotFound("Item");
+ }
+ else
+ id = _id;
+ ini.GetValue("name", name, "");
+ ini.GetValue("sellable", sellable, false);
+ ini.GetValue("type", type, -1);
+ ini.GetValue("price", price, 0);
+ ini.GetValue("description", description, "");
+ effects.clear();
+ LogImportOver("Item", id, name);
+}
+
+void PokeGen::PokeMod::Item::ExportIni(std::ofstream &fout) const
+{
+ LogExportStart("Item", id, name);
+ // Make elements
+ Ini exItem("item");
+ exItem.AddField("id", id);
+ exItem.AddField("name", name);
+ exItem.AddField("sellable", sellable);
+ exItem.AddField("type", type);
+ exItem.AddField("price", price);
+ exItem.AddField("description", description);
+ exItem.Export(fout);
+ for (std::vector<ItemEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
+ i->ExportIni(fout, name);
+ LogExportOver("Item", id, name);
+}
+
+void PokeGen::PokeMod::Item::SetName(const String &n)
+{
+ LogSetVar("Item", id, "name", n);
+ name = n;
+}
+
+void PokeGen::PokeMod::Item::SetSellable(bool s)
+{
+ LogSetVar("Item", id, "sellable", s, name);
+ sellable = s;
+}
+
+void PokeGen::PokeMod::Item::SetType(int t)
+{
+ LogSetVar("Item", id, "type", t, name);
+ if (curPokeMod.GetItemStorage(t))
+ type = t;
+}
+
+void PokeGen::PokeMod::Item::SetType(const String &t)
+{
+ LogSetVar("Item", id, "type string", t, name);
+ if (ItemStorage *i = curPokeMod.GetItemStorage(t))
+ type = i->GetId();
+}
+
+void PokeGen::PokeMod::Item::SetPrice(unsigned p)
+{
+ LogSetVar("Item", id, "price", p, name);
+ price = p;
+}
+
+void PokeGen::PokeMod::Item::SetDescription(const String &d)
+{
+ LogSetVar("Item", id, "description", d, name);
+ description = d;
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Item::GetName() const
+{
+ LogFetchVar("Item", id, "name", name);
+ return name;
+}
+
+bool PokeGen::PokeMod::Item::GetSellable() const
+{
+ LogFetchVar("Item", id, "sellable", sellable, name);
+ return sellable;
+}
+
+int PokeGen::PokeMod::Item::GetType() const
+{
+ LogFetchVar("Item", id, "type", type, name);
+ return type;
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Item::GetType() const
+{
+ LogFetchVar("Item", id, "type string", type, name);
+ if (ItemStorage *i = curPokeMod.GetItemStorage(type))
+ return i->GetName();
+ return "";
+}
+
+unsigned PokeGen::PokeMod::Item::GetPrice() const
+{
+ LogFetchVar("Item", id, "price", price, name);
+ return price;
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Item::GetDescription() const
+{
+ LogFetchVar("Item", id, "description", description, name);
+ return description;
+}
+
+PokeGen::PokeMod::ItemEffect *PokeGen::PokeMod::Item::GetItemEffect(unsigned _id)
+{
+ LogSubmoduleFetch("Item", id, "effect", _id, name);
+ for (unsigned i = 0; i < GetItemEffectCount(); ++i)
+ {
+ if (effects[i].GetId() == _id)
+ return &effects[i];
+ }
+ LogSubmoduleFetchFail("Item", id, "effect", _id, name);
+ return NULL;
+}
+
+unsigned PokeGen::PokeMod::Item::GetItemEffectCount() const
+{
+ LogSubmoduleCount("Item", id, "effect", name);
+ return effects.size();
+}
+
+void PokeGen::PokeMod::Item::NewItemEffect()
+{
+ unsigned i = 0;
+ // Find the first unused ID in the vector
+ for (; i < GetItemEffectCount(); ++i)
+ {
+ if (!GetItemEffect(i))
+ break;
+ }
+ ItemEffect newItemEffect(i);
+ if (ini)
+ newItemEffect.ImportIni(*ini);
+ LogSubmoduleNew("Item", id, "effect", i, name);
+ effects.push_back(newItemEffect);
+}
+
+void PokeGen::PokeMod::Item::DeleteItemEffect(unsigned _id)
+{
+ LogSubmoduleRemoveStart("Item", id, "effect", _id, name);
+ for (std::vector<ItemEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
+ {
+ if (i->GetId() == _id)
+ {
+ LogSubmoduleRemoved("Item", id, "effect", _id, name);
+ effects.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Item", id, "effect", _id, name);
+}
|
