From 5b55d13ead7e352ee1feaae72009e8abf5bd071a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 21 Sep 2007 15:36:22 +0000 Subject: [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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@24 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/CoinList.cpp | 444 ++++++++++++++++++++++++--------------------------- 1 file changed, 213 insertions(+), 231 deletions(-) (limited to 'pokemod/CoinList.cpp') 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 . -///////////////////////////////////////////////////////////////////////////// - -#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 idChecker; - QMap itemChecker; - QMap pokemonChecker; - for (QList::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::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i) - { - if (1 < i.value()) - { - LogDuplicateId("CoinList", id, "coin item", i.key(), name); - isValid = false; - } - } - for (QMap::ConstIterator i = itemChecker.begin(); i != itemChecker.end(); ++i) - { - if (1 < i.value()) - { - LogDuplicateSubmodule("CoinList", id, "item", i.key(), name); - isValid = false; - } - } - for (QMap::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::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::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::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 . +///////////////////////////////////////////////////////////////////////////// + +#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 idChecker; + QMap itemChecker; + QMap pokemonChecker; + for (QList::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::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::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::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::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; +} -- cgit