summaryrefslogtreecommitdiffstats
path: root/pokemod/CoinList.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemod/CoinList.cpp')
-rw-r--r--pokemod/CoinList.cpp444
1 files changed, 213 insertions, 231 deletions
diff --git a/pokemod/CoinList.cpp b/pokemod/CoinList.cpp
index 15c61169..f54dcf6a 100644
--- a/pokemod/CoinList.cpp
+++ b/pokemod/CoinList.cpp
@@ -1,231 +1,213 @@
-/////////////////////////////////////////////////////////////////////////////
-// Name: pokemod/CoinList.cpp
-// Purpose: A specialty store where Pokémon and items can be gotten for
-// coins won through gambling
-// Author: Ben Boeckel
-// Modified by: Ben Boeckel
-// Created: Wed Feb 28 21: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 "CoinList.h"
-
-PokeGen::PokeMod::CoinList::CoinList(const Pokemod *par, const unsigned _id) :
- name(""),
- value(0)
-{
- LogCtor("CoinList", _id);
- id = _id;
- pokemod = par;
-}
-
-PokeGen::PokeMod::CoinList::CoinList(const Pokemod *par, Ini &ini, const unsigned _id)
-{
- LogCtorIni("CoinList", _id);
- pokemod = par;
- ImportIni(ini, _id);
- if (id == UINT_MAX)
- LogIdError("CoinList");
-}
-
-PokeGen::PokeMod::CoinList::~CoinList()
-{
- LogDtor("CoinList", id, name);
-}
-
-void PokeGen::PokeMod::CoinList::Validate()
-{
- LogValidateStart("CoinList", id, name);
- if (name == "")
- {
- LogVarNotSet("CoinList", id, "name");
- isValid = false;
- }
- if (GetCoinItemCount())
- {
- QMap<unsigned, unsigned> idChecker;
- QMap<QString, unsigned> itemChecker;
- QMap<QString, unsigned> pokemonChecker;
- for (QList<CoinItem>::Iterator i = items.begin(); i != items.end(); ++i)
- {
- LogSubmoduleIterate("CoinList", id, "item", i->GetId(), name);
- if (!i->IsValid())
- isValid = false;
- ++idChecker[i->GetId()];
- if (i->GetType() == CIT_ITEM)
- ++itemChecker[i->GetObjectString()];
- else if (i->GetType() == CIT_POKEMON)
- ++pokemonChecker[i->GetObjectString()];
- }
- for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateId("CoinList", id, "coin item", i.key(), name);
- isValid = false;
- }
- }
- for (QMap<QString, unsigned>::ConstIterator i = itemChecker.begin(); i != itemChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateSubmodule("CoinList", id, "item", i.key(), name);
- isValid = false;
- }
- }
- for (QMap<QString, unsigned>::ConstIterator i = pokemonChecker.begin(); i != pokemonChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateSubmodule("CoinList", id, "Pokémon", i.key(), name);
- isValid = false;
- }
- }
- }
- else
- {
- LogSubmoduleEmpty("CoinList", id, "items", name);
- isValid = false;
- }
- LogValidateOver("CoinList", id, isValid, name);
-}
-
-void PokeGen::PokeMod::CoinList::ImportIni(Ini &ini, const unsigned _id)
-{
- LogImportStart("CoinList");
- if (_id == UINT_MAX)
- {
- ini.GetValue("id", id);
- if (id == UINT_MAX)
- LogIdNotFound("CoinList");
- }
- else
- id = _id;
- ini.GetValue("name", name);
- ini.GetValue("value", value, 0);
- items.clear();
- LogImportOver("CoinList", id, name);
-}
-
-void PokeGen::PokeMod::CoinList::ExportIni(QFile &fout) const
-{
- LogExportStart("CoinList", id, name);
- Ini exCoinList("coinList");
- exCoinList.AddField("id", id);
- exCoinList.AddField("name", name);
- exCoinList.AddField("value", value);
- exCoinList.Export(fout);
- for (QList<CoinItem>::ConstIterator i = items.begin(); i != items.end(); ++i)
- i->ExportIni(fout, name);
- LogExportOver("CoinList", id, name);
-}
-
-void PokeGen::PokeMod::CoinList::SetName(const QString &n)
-{
- LogSetVar("CoinList", id, "name", n, name);
- name = n;
-}
-
-void PokeGen::PokeMod::CoinList::SetValue(const unsigned v)
-{
- LogSetVar("CoinList", id, "value", value, name);
- value = v;
-}
-
-QString PokeGen::PokeMod::CoinList::GetName() const
-{
- LogFetchVar("CoinList", id, "name", name, name);
- return name;
-}
-
-unsigned PokeGen::PokeMod::CoinList::GetValue() const
-{
- LogFetchVar("CoinList", id, "value", value, name);
- return value;
-}
-
-const PokeGen::PokeMod::CoinItem *PokeGen::PokeMod::CoinList::GetCoinItem(const unsigned _id) const
-{
- LogSubmoduleFetch("CoinList", id, "item", _id, name);
- for (unsigned i = 0; i < GetCoinItemCount(); ++i)
- {
- if (items[i].GetId() == _id)
- return &items[i];
- }
- LogSubmoduleFetchFail("CoinList", id, "item", _id, name);
- return NULL;
-}
-
-const PokeGen::PokeMod::CoinItem *PokeGen::PokeMod::CoinList::GetCoinItem(const QString &n) const
-{
- LogSubmoduleFetch("CoinList", id, "item", n, name);
- for (unsigned i = 0; i < GetCoinItemCount(); ++i)
- {
- if (items[i].GetObjectString() == n)
- return &items[i];
- }
- LogSubmoduleFetchFail("CoinList", id, "item", n, name);
- return NULL;
-}
-
-unsigned PokeGen::PokeMod::CoinList::GetCoinItemCount() const
-{
- LogSubmoduleCount("CoinList", id, "items", name);
- return items.size();
-}
-
-void PokeGen::PokeMod::CoinList::NewCoinItem(Ini *const ini)
-{
- unsigned i = 0;
- for (; i < GetCoinItemCount(); ++i)
- {
- if (!GetCoinItem(i))
- break;
- }
- CoinItem newCoinItem(pokemod, i);
- if (ini)
- newCoinItem.ImportIni(*ini);
- LogSubmoduleNew("CoinList", id, "item", i, name);
- items.append(newCoinItem);
-}
-
-void PokeGen::PokeMod::CoinList::DeleteCoinItem(const unsigned _id)
-{
- LogSubmoduleRemoveStart("CoinList", id, "item", _id, name);
- for (QList<CoinItem>::Iterator i = items.begin(); i != items.end(); ++i)
- {
- if (i->GetId() == _id)
- {
- LogSubmoduleRemoved("CoinList", id, "item", _id, name);
- items.erase(i);
- }
- }
- LogSubmoduleRemoveFail("CoinList", id, "item", _id, name);
-}
-
-void PokeGen::PokeMod::CoinList::DeleteCoinItem(const QString &n)
-{
- LogSubmoduleRemoveStart("CoinList", id, "item", n, name);
- for (QList<CoinItem>::Iterator i = items.begin(); i != items.end(); ++i)
- {
- if (i->GetObjectString() == n)
- {
- LogSubmoduleRemoved("CoinList", id, "item", n, name);
- items.erase(i);
- }
- }
- LogSubmoduleRemoveFail("CoinList", id, "item", n, name);
-}
+/////////////////////////////////////////////////////////////////////////////
+// Name: pokemod/CoinList.cpp
+// Purpose: A specialty store where Pokémon and items can be gotten for
+// coins won through gambling
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Wed Feb 28 21: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 "CoinList.h"
+
+PokeGen::PokeMod::CoinList::CoinList(const Pokemod* par, const unsigned _id) :
+ Object(_id, par),
+ name(""),
+ value(0)
+{
+}
+
+PokeGen::PokeMod::CoinList::CoinList(const Pokemod* par, Ini& ini, const unsigned _id) :
+ Object(_id, par)
+{
+ ImportIni(ini, _id);
+}
+
+bool PokeGen::PokeMod::CoinList::Validate()
+{
+ pokemod->ValidationMsg(QString("---Coin List \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg);
+ if (name == "")
+ {
+ pokemod->ValidationMsg("Name not defined");
+ isValid = false;
+ }
+ if (GetItemCount())
+ {
+ QMap<unsigned, unsigned> idChecker;
+ QMap<unsigned, unsigned> itemChecker;
+ QMap<unsigned, unsigned> pokemonChecker;
+ for (QList<CoinListObject>::Iterator i = items.begin(); i != items.end(); ++i)
+ {
+ if (!i->IsValid())
+ isValid = false;
+ ++idChecker[i->GetId()];
+ if (i->GetType() == CoinListObject::Item)
+ ++itemChecker[i->GetObject()];
+ else if (i->GetType() == CoinListObject::Pokemon)
+ ++pokemonChecker[i->GetObject()];
+ }
+ for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i)
+ {
+ if (1 < i.value())
+ {
+ pokemod->ValidationMsg(QString("There are %1 objects with id %2").arg(i.value()).arg(i.key()));
+ isValid = false;
+ }
+ }
+ for (QMap<unsigned, unsigned>::ConstIterator i = itemChecker.begin(); i != itemChecker.end(); ++i)
+ {
+ if (1 < i.value())
+ {
+ pokemod->ValidationMsg(QString("There are %1 items with the id %2").arg(i.value()).arg(i.key()));
+ isValid = false;
+ }
+ }
+ for (QMap<unsigned, unsigned>::ConstIterator i = pokemonChecker.begin(); i != pokemonChecker.end(); ++i)
+ {
+ if (1 < i.value())
+ {
+ pokemod->ValidationMsg(QString("There are %1 Pokémon with the id %2").arg(i.value()).arg(i.key()));
+ isValid = false;
+ }
+ }
+ }
+ else
+ {
+ pokemod->ValidationMsg("There are no objects");
+ isValid = false;
+ }
+ bool temp = false;
+ if (const Item* item = pokemod->GetItem(pokemod->GetItemByID(value)))
+ {
+ for (unsigned i = 0; (i < item->GetEffectCount()) && !temp; ++i)
+ {
+ if (const ItemEffect* e = item->GetEffect(i))
+ {
+ if (e->GetEffect() == ItemEffect::E_CoinCase)
+ temp = true;
+ }
+ }
+ }
+ if (!temp)
+ {
+ pokemod->ValidationMsg("Invalid fishing value");
+ isValid = false;
+ }
+ return isValid;
+}
+
+void PokeGen::PokeMod::CoinList::ImportIni(Ini& ini, const unsigned _id)
+{
+ if (_id == UINT_MAX)
+ ini.GetValue("id", id);
+ else
+ id = _id;
+ ini.GetValue("name", name);
+ ini.GetValue("value", value, 0);
+ items.clear();
+}
+
+void PokeGen::PokeMod::CoinList::ExportIni(QFile& fout) const
+{
+ Ini exCoinList("coinList");
+ exCoinList.AddField("id", id);
+ exCoinList.AddField("name", name);
+ exCoinList.AddField("value", value);
+ exCoinList.Export(fout);
+ for (QList<CoinListObject>::ConstIterator i = items.begin(); i != items.end(); ++i)
+ i->ExportIni(fout, name);
+}
+
+void PokeGen::PokeMod::CoinList::SetName(const QString& n)
+{
+ name = n;
+}
+
+bool PokeGen::PokeMod::CoinList::SetValue(const unsigned v)
+{
+ if (const Item* item = pokemod->GetItem(v))
+ {
+ for (unsigned i = 0; i < item->GetEffectCount(); ++i)
+ {
+ if (const ItemEffect* effect = item->GetEffect(i))
+ {
+ if (effect->GetEffect() == ItemEffect::E_CoinCase)
+ {
+ value = v;
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+QString PokeGen::PokeMod::CoinList::GetName() const
+{
+ return name;
+}
+
+unsigned PokeGen::PokeMod::CoinList::GetValue() const
+{
+ return value;
+}
+
+const PokeGen::PokeMod::CoinListObject* PokeGen::PokeMod::CoinList::GetItem(const unsigned i) const
+{
+ if (i < GetItemCount())
+ return &items[i];
+ return NULL;
+}
+
+unsigned PokeGen::PokeMod::CoinList::GetItemByID(const unsigned _id) const
+{
+ for (unsigned i = 0; i < GetItemCount(); ++i)
+ {
+ if (items[i].GetId() == _id)
+ return i;
+ }
+ return UINT_MAX;
+}
+
+unsigned PokeGen::PokeMod::CoinList::GetItemCount() const
+{
+ return items.size();
+}
+
+const PokeGen::PokeMod::CoinListObject* PokeGen::PokeMod::CoinList::NewItem(Ini* const ini)
+{
+ unsigned i = 0;
+ for (; i < GetItemCount(); ++i)
+ {
+ if (GetItemByID(i) == UINT_MAX)
+ break;
+ }
+ CoinListObject newItem(pokemod, i);
+ if (ini)
+ newItem.ImportIni(*ini);
+ items.append(newItem);
+ return &items[GetItemCount() - 1];
+}
+
+bool PokeGen::PokeMod::CoinList::DeleteItem(const unsigned i)
+{
+ if (i < GetItemCount())
+ {
+ items.erase(items.begin() + i);
+ return true;
+ }
+ return false;
+}