summaryrefslogtreecommitdiffstats
path: root/pokemod/Store.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2007-05-21 04:18:48 +0000
committerBen Boeckel <MathStuf@gmail.com>2007-05-21 04:18:48 +0000
commit0fec318eac634e5465c30eb73d47ec82aaed9db8 (patch)
tree1851831cbcfce296aeabe7ad553ca936343d4a33 /pokemod/Store.cpp
parent42375a0129fdd57355764c58ed27fa3a0a3c5465 (diff)
downloadsigen-0fec318eac634e5465c30eb73d47ec82aaed9db8.tar.gz
sigen-0fec318eac634e5465c30eb73d47ec82aaed9db8.tar.xz
sigen-0fec318eac634e5465c30eb73d47ec82aaed9db8.zip
Added Time, Store, and PokemonItem
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@11 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Store.cpp')
-rw-r--r--pokemod/Store.cpp207
1 files changed, 207 insertions, 0 deletions
diff --git a/pokemod/Store.cpp b/pokemod/Store.cpp
new file mode 100644
index 00000000..acb40d0d
--- /dev/null
+++ b/pokemod/Store.cpp
@@ -0,0 +1,207 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: Store.cpp
+// Purpose: Define a store that the player can shop at
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Tue Mar 20 18:31:50 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 "Store.h"
+
+extern PokeGen::PokeMod::PokeMod curPokeMod;
+
+PokeGen::PokeMod::Store::Store(unsigned _id)
+{
+ LogCtor("Store", _id);
+ name = "";
+ items.clear();
+ id = _id;
+}
+
+PokeGen::PokeMod::Store::Store(Ini &ini, unsigned _id)
+{
+ LogCtorIni("Store", _id);
+ ImportIni(ini);
+ if(_id == UINT_MAX)
+ LogIdError("Store");
+}
+
+PokeGen::PokeMod::Store::~Store()
+{
+ LogDtor("Store", id, name);
+}
+
+void PokeGen::PokeMod::Store::Validate()
+{
+ isValid = true;
+ LogValidateStart("Store", id, name);
+ if (name == "")
+ {
+ LogVarNotSet("Store", id, "name", name);
+ isValid = false;
+ }
+ for (unsigned i = 0; i < GetItemCount(); ++i)
+ {
+ if (!curPokeMod.GetItem(items[i]))
+ {
+ LogSubmoduleEmpty("Store", id, "item", name);
+ isValid = false;
+ }
+ }
+ LogValidateOver("Store", id, isValid, name);
+}
+
+#ifdef PG_DEBUG_WINDOW
+void PokeGen::PokeMod::Store::Validate(wxListBox &output)
+{
+ isValid = true;
+ LogValidateStart("Store", id, name);
+ if (name == "")
+ {
+ LogVarNotSet("Store", id, "name", name);
+ output.Append(ConsoleLogVarNotSet("Store", id, "name", name));
+ isValid = false;
+ }
+ for (unsigned i = 0; i < GetItemCount(); ++i)
+ {
+ if (!curPokeGen::PokeMod.GetItem(items[i]))
+ {
+ LogSubmoduleEmpty("Store", id, "item", name);
+ output.Append(ConsoleLogVarNotSet("Store", id, "item", name));
+ isValid = false;
+ }
+ }
+ LogValidateOver("Store", id, isValid, name);
+}
+#endif
+
+void PokeGen::PokeMod::Store::ImportIni(Ini &ini, unsigned _id)
+{
+ LogImportStart("Store");
+ if (_id == UINT_MAX)
+ {
+ ini.GetValue("id", id, UINT_MAX);
+ // Was there an id associated with the element?
+ if (id == UINT_MAX)
+ LogIdNotFound("Store");
+ }
+ else
+ id = _id;
+ items.clear();
+ unsigned i;
+ unsigned j;
+ ini.GetValue("name", name, "");
+ ini.GetValue("numItems", i, 0);
+ for (unsigned k = 0; k < i; ++k)
+ {
+ ini.GetValue(String("item-%u", k), j, UINT_MAX);
+ if (j != UINT_MAX)
+ items.push_back(j);
+ }
+ LogImportOver("Store", id, name);
+}
+
+void PokeGen::PokeMod::Store::ExportIni(std::ofstream &fout) const
+{
+ LogExportStart("Store", id, name);
+ // Make elements
+ Ini exStore("store");
+ exStore.AddField("id", id);
+ exStore.AddField("name", name);
+ exStore.AddField("numItems", items.size());
+ for (unsigned i = 0; i < items.size(); ++i)
+ exStore.AddField(String("items-%u", i), items[i]);
+ exStore.Export(fout);
+ LogExportOver("Store", id, name);
+}
+
+void PokeGen::PokeMod::Store::SetName(const String &n)
+{
+ LogSetVar("Store", id, "name", n, name);
+ name = n;
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Store::GetName()
+{
+ LogFetchVar("Store", id, "name", name, name);
+ return name;
+}
+
+int PokeGen::PokeMod::Store::GetItem(unsigned i) const
+{
+ LogSubmoduleFetch("Store", id, "item", i, name);
+ if (GetItemCount() <= i)
+ {
+ LogSubmoduleFetchFail("Store", id, "item", i, name);
+ return -1;
+ }
+ return items[i];
+}
+
+bool PokeGen::PokeMod::Store::HasItem(unsigned _id) const
+{
+ LogSubmoduleFetch("Store", id, "item", _id, name);
+ return (GetItem(_id) != -1);
+}
+
+bool PokeGen::PokeMod::Store::HasItem(const String &n) const
+{
+ LogSubmoduleFetch("Store", id, "item", UINT_MAX, name);
+ for (unsigned i = 0; i < GetItemCount(); ++i)
+ {
+ if (curPokeMod.GetItem(items[i])->GetName() == n)
+ return true;
+ }
+ LogSubmoduleFetchFail("Store", id, "item", UINT_MAX, name);
+ return false;
+}
+
+unsigned PokeGen::PokeMod::Store::GetItemCount() const
+{
+ LogSubmoduleCount("Store", id, "item", name);
+ return items.size();
+}
+
+void PokeGen::PokeMod::Store::NewItem(unsigned i)
+{
+ LogSubmoduleNew("Store", id, "item", items.size());
+ items.push_back(i);
+}
+
+void PokeGen::PokeMod::Store::DeleteItem(unsigned i)
+{
+ LogSubmoduleRemoveStart("Store", id, "item", i, name);
+ if (GetItemCount() <= i)
+ LogSubmoduleRemoveFail("Store", id, "item", i, name);
+ else
+ DeleteItemByID(items[i]);
+}
+
+void PokeGen::PokeMod::Store::DeleteItemByID(unsigned _id)
+{
+ LogSubmoduleRemoveStart("Store", id, "item", _id, name);
+ for (std::vector<unsigned>::iterator i = items.begin(); i != items.end(); ++i)
+ {
+ if (*i == _id)
+ {
+ LogSubmoduleRemoved("Store", id, "item", _id, name);
+ items.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Store", id, "item", _id, name);
+}