summaryrefslogtreecommitdiffstats
path: root/pokemod/Item.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2007-09-21 15:36:22 +0000
committerBen Boeckel <MathStuf@gmail.com>2007-09-21 15:36:22 +0000
commit5b55d13ead7e352ee1feaae72009e8abf5bd071a (patch)
tree6c2838312dd7f42769280e24e8abc16b53c165cb /pokemod/Item.cpp
parente94d9893b8753e72adb92b2c5eb203830ddf641c (diff)
[FIX] Neural Network methods complete
[FIX] Wrapped Node up into the layer [FIX] Wrapped NatureEffect into Nature [FIX] Getting around to fixing up the design of the PokéMod stuff [FIX] Creating new subclasses now returns pointer to new subclass [FIX] Simplified interfaces [FIX] Minor style issues [FIX] Renamed CoinItem to CoinListObject [FIX] Renamed MapTrainerTeam to MapTrainerPokemon [FIX] Renamed MapWildPokemon to MapWildListPokemon [FIX] Moved global enums to relevant classes [FIX] Removed general logging features [DEL] pokemod/Debug.{h, cpp} [DEL] pokemod/Path.{h, cpp} [FIX] Using QFile rather than custom Path class for checking for files [FIX] Set* methods now return a bool to let the caller know if anything actually changed (if it can fail, otherwise it is void) [ADD] Compliation without errors is required for pokemod from now on before commits git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@24 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Item.cpp')
-rw-r--r--pokemod/Item.cpp467
1 files changed, 208 insertions, 259 deletions
diff --git a/pokemod/Item.cpp b/pokemod/Item.cpp
index ff732d2c..b0892600 100644
--- a/pokemod/Item.cpp
+++ b/pokemod/Item.cpp
@@ -1,259 +1,208 @@
-/////////////////////////////////////////////////////////////////////////////
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-/////////////////////////////////////////////////////////////////////////////
-
-#include "Item.h"
-
-PokeGen::PokeMod::Item::Item(const Pokemod *par, const unsigned _id) :
- name(""),
- sellable(false),
- type(UINT_MAX),
- price(0),
- description("")
-{
- LogCtor("Item", _id);
- id = _id;
- pokemod = par;
-}
-
-PokeGen::PokeMod::Item::Item(const Pokemod *par, Ini &ini, const unsigned _id)
-{
- LogCtorIni("Item", _id);
- pokemod = par;
- ImportIni(ini, _id);
- if (id == UINT_MAX)
- LogIdError("Item");
-}
-
-PokeGen::PokeMod::Item::~Item()
-{
- LogDtor("Item", id, name);
-}
-
-void PokeGen::PokeMod::Item::Validate()
-{
- LogValidateStart("Item", id, name);
- if (name == "")
- {
- LogVarNotSet("Item", id, "name");
- isValid = false;
- }
- if (!pokemod->GetItemStorage(type))
- {
- LogVarNotValid("Item", id, "type", name);
- isValid = false;
- }
- if (GetItemEffectCount())
- {
- QMap<unsigned, unsigned> idChecker;
- QMap<QString, unsigned> effectChecker;
- for (QList<ItemEffect>::Iterator i = effects.begin(); i != effects.end(); ++i)
- {
- LogSubmoduleIterate("Item", id, "effect", i->GetId(), name);
- if (!i->IsValid())
- isValid = false;
- ++idChecker[i->GetId()];
- ++effectChecker[i->GetEffectString()];
- }
- for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateId("Item", id, "effect", i.key(), name);
- isValid = false;
- }
- }
- for (QMap<QString, unsigned>::ConstIterator i = effectChecker.begin(); i != effectChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateSubmodule("Item", id, "effect", i.key(), name);
- isValid = false;
- }
- }
- }
- else
- {
- LogSubmoduleEmpty("Item", id, "effect", name);
- isValid = false;
- }
- LogValidateOver("Item", id, isValid, name);
-}
-
-void PokeGen::PokeMod::Item::ImportIni(Ini &ini, const unsigned _id)
-{
- LogImportStart("Item");
- if (_id == UINT_MAX)
- {
- ini.GetValue("id", id);
- if (id == UINT_MAX)
- LogIdNotFound("Item");
- }
- else
- id = _id;
- ini.GetValue("name", name);
- ini.GetValue("sellable", sellable, false);
- ini.GetValue("type", type);
- ini.GetValue("price", price, 0);
- ini.GetValue("description", description);
- effects.clear();
- LogImportOver("Item", id, name);
-}
-
-void PokeGen::PokeMod::Item::ExportIni(QFile &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 (QList<ItemEffect>::ConstIterator i = effects.begin(); i != effects.end(); ++i)
- i->ExportIni(fout, name);
- LogExportOver("Item", id, name);
-}
-
-void PokeGen::PokeMod::Item::SetName(const QString &n)
-{
- LogSetVar("Item", id, "name", n);
- name = n;
-}
-
-void PokeGen::PokeMod::Item::SetSellable(const bool s)
-{
- LogSetVar("Item", id, "sellable", s, name);
- sellable = s;
-}
-
-void PokeGen::PokeMod::Item::SetType(const unsigned t)
-{
- LogSetVar("Item", id, "type", t, name);
- if (pokemod->GetItemStorage(t))
- type = t;
-}
-
-void PokeGen::PokeMod::Item::SetType(const QString &t)
-{
- LogSetVar("Item", id, "type string", t, name);
- if (const ItemStorage *i = pokemod->GetItemStorage(t))
- type = i->GetId();
-}
-
-void PokeGen::PokeMod::Item::SetPrice(const unsigned p)
-{
- LogSetVar("Item", id, "price", p, name);
- price = p;
-}
-
-void PokeGen::PokeMod::Item::SetDescription(const QString &d)
-{
- LogSetVar("Item", id, "description", d, name);
- description = d;
-}
-
-QString 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;
-}
-
-unsigned PokeGen::PokeMod::Item::GetType() const
-{
- LogFetchVar("Item", id, "type", type, name);
- return type;
-}
-
-QString PokeGen::PokeMod::Item::GetTypeString() const
-{
- LogFetchVar("Item", id, "type string", type, name);
- if (const ItemStorage *i = pokemod->GetItemStorage(type))
- return i->GetName();
- return "";
-}
-
-unsigned PokeGen::PokeMod::Item::GetPrice() const
-{
- LogFetchVar("Item", id, "price", price, name);
- return price;
-}
-
-QString PokeGen::PokeMod::Item::GetDescription() const
-{
- LogFetchVar("Item", id, "description", description, name);
- return description;
-}
-
-const PokeGen::PokeMod::ItemEffect *PokeGen::PokeMod::Item::GetItemEffect(const unsigned _id) const
-{
- 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(Ini *const ini)
-{
- unsigned i = 0;
- for (; i < GetItemEffectCount(); ++i)
- {
- if (!GetItemEffect(i))
- break;
- }
- ItemEffect newItemEffect(pokemod, i);
- if (ini)
- newItemEffect.ImportIni(*ini);
- LogSubmoduleNew("Item", id, "effect", i, name);
- effects.append(newItemEffect);
-}
-
-void PokeGen::PokeMod::Item::DeleteItemEffect(const unsigned _id)
-{
- LogSubmoduleRemoveStart("Item", id, "effect", _id, name);
- for (QList<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);
-}
+/////////////////////////////////////////////////////////////////////////////
+// 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 3 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, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Item.h"
+
+PokeGen::PokeMod::Item::Item(const Pokemod* par, const unsigned _id) :
+ Object(_id, par),
+ name(""),
+ sellable(false),
+ type(UINT_MAX),
+ price(0),
+ description("")
+{
+}
+
+PokeGen::PokeMod::Item::Item(const Pokemod* par, Ini& ini, const unsigned _id) :
+ Object(_id, par)
+{
+ ImportIni(ini, _id);
+}
+
+bool PokeGen::PokeMod::Item::Validate()
+{
+ pokemod->ValidationMsg(QString("---Item \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg);
+ if (name == "")
+ {
+ pokemod->ValidationMsg("Name is not defined");
+ isValid = false;
+ }
+ if (pokemod->GetItemTypeByID(type) == UINT_MAX)
+ {
+ pokemod->ValidationMsg("Invalid item type");
+ isValid = false;
+ }
+ if (GetEffectCount())
+ {
+ QMap<unsigned, unsigned> idChecker;
+ for (QList<ItemEffect>::Iterator i = effects.begin(); i != effects.end(); ++i)
+ {
+ if (!i->IsValid())
+ isValid = false;
+ ++idChecker[i->GetId()];
+ }
+ for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i)
+ {
+ if (1 < i.value())
+ {
+ pokemod->ValidationMsg(QString("There are %1 effects with id %2").arg(i.value()).arg(i.key()));
+ isValid = false;
+ }
+ }
+ }
+ else
+ {
+ pokemod->ValidationMsg("There are no effects");
+ isValid = false;
+ }
+ return isValid;
+}
+
+void PokeGen::PokeMod::Item::ImportIni(Ini& ini, const unsigned _id)
+{
+ if (_id == UINT_MAX)
+ ini.GetValue("id", id);
+ else
+ id = _id;
+ ini.GetValue("name", name);
+ ini.GetValue("sellable", sellable, false);
+ ini.GetValue("type", type);
+ ini.GetValue("price", price, 0);
+ ini.GetValue("description", description);
+ effects.clear();
+}
+
+void PokeGen::PokeMod::Item::ExportIni(QFile& fout) const
+{
+ 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 (QList<ItemEffect>::ConstIterator i = effects.begin(); i != effects.end(); ++i)
+ i->ExportIni(fout, name);
+}
+
+void PokeGen::PokeMod::Item::SetName(const QString& n)
+{
+ name = n;
+}
+
+void PokeGen::PokeMod::Item::SetSellable(const bool s)
+{
+ sellable = s;
+}
+
+bool PokeGen::PokeMod::Item::SetType(const unsigned t)
+{
+ if (pokemod->GetItemTypeByID(t) != UINT_MAX)
+ {
+ type = t;
+ return true;
+ }
+ return false;
+}
+
+void PokeGen::PokeMod::Item::SetPrice(const unsigned p)
+{
+ price = p;
+}
+
+void PokeGen::PokeMod::Item::SetDescription(const QString& d)
+{
+ description = d;
+}
+
+QString PokeGen::PokeMod::Item::GetName() const
+{
+ return name;
+}
+
+bool PokeGen::PokeMod::Item::GetSellable() const
+{
+ return sellable;
+}
+
+unsigned PokeGen::PokeMod::Item::GetType() const
+{
+ return type;
+}
+
+unsigned PokeGen::PokeMod::Item::GetPrice() const
+{
+ return price;
+}
+
+QString PokeGen::PokeMod::Item::GetDescription() const
+{
+ return description;
+}
+
+const PokeGen::PokeMod::ItemEffect* PokeGen::PokeMod::Item::GetEffect(const unsigned i) const
+{
+ if (i < GetEffectCount())
+ return &effects[i];
+ return NULL;
+}
+
+unsigned PokeGen::PokeMod::Item::GetEffectByID(const unsigned _id) const
+{
+ for (unsigned i = 0; i < GetEffectCount(); ++i)
+ {
+ if (effects[i].GetId() == _id)
+ return i;
+ }
+ return UINT_MAX;
+}
+
+unsigned PokeGen::PokeMod::Item::GetEffectCount() const
+{
+ return effects.size();
+}
+
+const PokeGen::PokeMod::ItemEffect* PokeGen::PokeMod::Item::NewEffect(Ini* const ini)
+{
+ unsigned i = 0;
+ for (; i < GetEffectCount(); ++i)
+ {
+ if (GetEffectByID(i) == UINT_MAX)
+ break;
+ }
+ ItemEffect newEffect(pokemod, i);
+ if (ini)
+ newEffect.ImportIni(*ini);
+ effects.append(newEffect);
+ return &effects[GetEffectCount() - 1];
+}
+
+bool PokeGen::PokeMod::Item::DeleteEffect(const unsigned i)
+{
+ if (i < GetEffectCount())
+ {
+ effects.erase(effects.begin() + i);
+ return true;
+ }
+ return false;
+}