///////////////////////////////////////////////////////////////////////////// // 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 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 "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()) { std::map idChecker; std::map itemChecker; std::map pokemonChecker; for (std::vector::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 (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) { if (1 < i->second) { LogDuplicateId("CoinList", id, "coin item", i->first, name); isValid = false; } } for (std::map::const_iterator i = itemChecker.begin(); i != itemChecker.end(); ++i) { if (1 < i->second) { LogDuplicateSubmodule("CoinList", id, "item", i->first, name); isValid = false; } } for (std::map::const_iterator i = pokemonChecker.begin(); i != pokemonChecker.end(); ++i) { if (1 < i->second) { LogDuplicateSubmodule("CoinList", id, "Pokémon", i->first, name); isValid = false; } } } else { LogSubmoduleEmpty("CoinList", id, "items", name); isValid = false; } LogValidateOver("CoinList", id, isValid, name); } #ifdef PG_DEBUG_WINDOW void PokeGen::PokeMod::CoinList::Validate(const wxListBox &output) { LogValidateStart("CoinList", id, name); if (name == "") { LogVarEmpty("CoinList", id, "name", name); output.Append(ConsoleLogVarEmpty("CoinList", id, "name", name)); isValid = false; } if (GetCoinItemCount()) { std::map idChecker; std::map itemChecker; std::map pokemonChecker; for (std::vector::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 (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) { if (1 < i->second) { LogDuplicateId("CoinList", id, "coin item", i->first, name); output.Append(ConsoleLogDuplicateId("CoinList", id, "coin item", i->first, name)); isValid = false; } } for (std::map::const_iterator i = itemChecker.begin(); i != itemChecker.end(); ++i) { if (1 < i->second) { LogDuplicateSubmodule("CoinList", id, "item", i->first, name); output.Append(ConsoleLogDuplicateSubmodule("CoinList", id, "item", i->first, name)); isValid = false; } } for (std::map::const_iterator i = pokemonChecker.begin(); i != pokemonChecker.end(); ++i) { if (1 < i->second) { LogDuplicateSubmodule("CoinList", id, "Pokémon", i->first, name); output.Append(ConsoleLogDuplicateSubmodule("CoinList", id, "Pokémon", i->first, name)); isValid = false; } } } else { LogSubmoduleEmpty("CoinList", id, "items", name); output.Append(ConsoleLogSubmoduleEmpty("CoinList", id, "items", name)); isValid = false; } LogValidateOver("CoinList", id, isValid, name); } #endif 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(std::ofstream &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 (std::vector::const_iterator i = items.begin(); i != items.end(); ++i) i->ExportIni(fout, name); LogExportOver("CoinList", id, name); } void PokeGen::PokeMod::CoinList::SetName(const String &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; } PokeGen::PokeMod::String 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 String &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.push_back(newCoinItem); } void PokeGen::PokeMod::CoinList::DeleteCoinItem(const unsigned _id) { LogSubmoduleRemoveStart("CoinList", id, "item", _id, name); for (std::vector::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 String &n) { LogSubmoduleRemoveStart("CoinList", id, "item", n, name); for (std::vector::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); }