From e858d98977a09b3c8faf4df87ada4abc1399e8e5 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 22 May 2007 03:51:45 +0000 Subject: Added a lot of minor PokéMod modules 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@12 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/CoinList.cpp | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 pokemod/CoinList.cpp (limited to 'pokemod/CoinList.cpp') diff --git a/pokemod/CoinList.cpp b/pokemod/CoinList.cpp new file mode 100644 index 00000000..83748355 --- /dev/null +++ b/pokemod/CoinList.cpp @@ -0,0 +1,208 @@ +///////////////////////////////////////////////////////////////////////////// +// 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" + +extern PokeGen::PokeMod::Pokemod curPokeMod; + +PokeGen::PokeMod::CoinList::CoinList(unsigned _id) +{ + LogCtor("CoinList", _id); + name = ""; + value = 0; + items.clear(); + id = _id; +} + +PokeGen::PokeMod::CoinList::CoinList(Ini &ini, unsigned _id) +{ + LogCtorIni("CoinList", _id); + ImportIni(ini); + if(_id == UINT_MAX) + LogIdError("CoinList"); +} + +PokeGen::PokeMod::CoinList::~CoinList() +{ + LogDtor("CoinList", id, name); +} + +void PokeGen::PokeMod::CoinList::Validate() +{ + isValid = true; + LogValidateStart("CoinList", id, name); + if (name == "") + { + LogVarEmpty("CoinList", id, "name", name); + isValid = false; + } + if (GetCoinItemCount()) + { + for (unsigned i = 0; i < GetCoinItemCount(); ++i) + { + LogSubmoduleIterate("CoinList", id, "item", i, name); + if (!items[i].IsValid()) + 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) +{ + isValid = true; + LogValidateStart("CoinList", id, name); + if (name == "") + { + LogVarEmpty("CoinList", id, "name", name); + output.Append(ConsoleLogVarEmpty("CoinList", id, "name", name)); + isValid = false; + } + if (GetCoinItemCount()) + { + for (unsigned i = 0; i < GetCoinItemCount(); ++i) + { + LogSubmoduleIterate("CoinList", id, "item", i, name); + if (!items[i].IsValid()) + 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, unsigned _id) +{ + LogImportStart("CoinList"); + if (_id == UINT_MAX) + { + ini.GetValue("id", id, UINT_MAX); + // Was there an id associated with the element? + if (id == UINT_MAX) + LogIdNotFound("CoinList"); + } + else + id = _id; + ini.GetValue("name", name, ""); + ini.GetValue("value", value, 0); + LogImportOver("CoinList", id, name); +} + +void PokeGen::PokeMod::CoinList::ExportIni(std::ofstream &fout) const +{ + LogExportStart("CoinList", id, name); + // Make elements + Ini exCoinList("coinList"); + exCoinList.AddField("id", id); + exCoinList.AddField("name", name); + exCoinList.AddField("value", value); + exCoinList.Export(fout); + for (std::vector::iterator i = effects.begin(); i != effects.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(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; +} + +PokeGen::PokeMod::CoinItem *PokeGen::PokeMod::CoinList::GetCoinItem(unsigned _id) +{ + LogSubmoduleFetch("CoinList", id, "item", _id, name); + for (unsigned i = 0; i < GetAbilityEffectCount(); ++i) + { + if (items[i].GetId() == _id) + return &items[i]; + } + LogSubmoduleFetch("CoinList", id, "item", _id, 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; + // Find the first unused ID in the vector + for (; i < GetCoinItemCount(); ++i) + { + if (!GetCoinItem(i)) + break; + } + CoinItem newCoinItem(i); + if (ini) + newCoinItem.ImportIni(*ini); + LogSubmoduleNew("CoinList", id, "item", i, name); + items.push_back(newCoinItem); +} + +void PokeGen::PokeMod::CoinList::DeleteCoinItem(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); + effects.erase(i); + } + } + LogSubmoduleRemoveFail("CoinList", id, "item", _id, name); +} -- cgit