From 1a4b623c8ecb9d0c7d991312c12d78be4a68eff2 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 23 May 2007 02:24:14 +0000 Subject: Added more 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@13 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/MapWildList.cpp | 300 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+) create mode 100644 pokemod/MapWildList.cpp (limited to 'pokemod/MapWildList.cpp') diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp new file mode 100644 index 00000000..053aebc1 --- /dev/null +++ b/pokemod/MapWildList.cpp @@ -0,0 +1,300 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: pokemod/MapWildList.cpp +// Purpose: Define a list of Pokémon that can be found on the map +// Author: Ben Boeckel +// Modified by: Ben Boeckel +// Created: Tue Mar 20 19:18:23 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 "MapWildList.h" + +extern PokeGen::PokeMod::Pokemod curPokeMod; + +PokeGen::PokeMod::MapWildList::MapWildList(unsigned _id) +{ + LogCtor("MapWildList", _id); + control = 0; + value = 0; + times = false; + scope = -1; + pokemon.clear(); + id = _id; +} + +PokeGen::PokeMod::MapWildList::MapWildList(Ini &ini, unsigned _id) +{ + LogCtorIni("MapWildList", _id); + ImportIni(ini); + if (id == UINT_MAX) + LogIdError("MapWildList"); +} + +PokeGen::PokeMod::MapWildList::~MapWildList() +{ + LogDtor("MapWildList", id); +} + +#ifdef PG_DEBUG_WINDOW +void PokeGen::PokeMod::MapWildList::Validate(wxListBox &output) +#else +void PokeGen::PokeMod::MapWildList::Validate() +#endif +{ + isValid = true; + PMLog("MapWildList Validation: Starting", PM_DEBUG_INFO); + // TODO (Validation#1#): MapWildList Validation + if (isValid) + PMLog("MapWildList Validation: Passed", PM_DEBUG_INFO); + else + PMLog("MapWildList Validation: Failed", PM_DEBUG_INFO); +} + +void PokeGen::PokeMod::MapWildList::ImportIni(Ini &ini, unsigned _id) +{ + LogImportStart("MapWildList"); + if (_id == UINT_MAX) + { + ini.GetValue("id", id, UINT_MAX); + // Was there an id associated with the element? + if (id == UINT_MAX) + LogIdNotFound("MapWildList"); + } + else + id = _id; + unsigned i; + unsigned j; + times.clear(); + ini.GetValue("control", , 0); + ini.GetValue("value", , 0); + ini.GetValue("numTimes", i, 0); + for (unsigned k = 0; k < i; ++k) + { + ini.GetValue(String("time-%u", k), j, UINT_MAX); + if (k != UINT_MAX) + times.push_back(j); + } + ini.GetValue("scope", scope, -1); + LogImportOver("MapWildList", id, name); +} + +void PokeGen::PokeMod::MapWildList::ExportIni(std::ofstream &fout, const String &map) const +{ + LogExportStart("MapWildList", id); + // Make elements + Ini exMapWildList(map + " mapWildList"); + exMapWildList.AddField("id", id); + exMapWildList.AddField("control", control); + exMapWildList.AddField("value", value); + exMapWildList.AddField("numTimes", times.size()); + for (unsigned i = 0; i < times.size(); ++i) + exMapWildList.AddField(String("time-%u", i), times[i]); + exMapWildList.AddField("scope", scope); + exMapWildList.Export(fout); + for (std::vector::iterator i = effects.begin(); i != effects.end(); ++i) + i->ExportIni(fout, map, id); + LogExportOver("MapWildList", id); +} + +void PokeGen::PokeMod::MapWildList::SetControl(unsigned c) +{ + LogSetVar("MapWildList", id, "control", c); + if ((CON_NONE < c) && (c < CON_END)) + control = c; +} + +void PokeGen::PokeMod::MapWildList::SetValue(unsigned v) +{ + unsigned i = 0; + unsigned j = 0; + LogSetVar("MapWildList", id, "value", v); + if (Item *item = curPokeMod.GetItem(v)) + { + while (i < item->GetEffectCount()) + { + if (ItemEffect *effect = curPokeMod.GetItem(j++)) + { + ++i; + if (effect->GetEffect() == IE_FISH) + { + value = effect->GetVal1(); + break; + } + } + } + } +} + +void PokeGen::PokeMod::MapWildList::SetValue(const String &v) +{ + LogSetVar("MapWildList", id, "value string", v); + if (Item *i = curPokeMod.GetItem(v)) + SetValue(i->GetId()); +} + +void PokeGen::PokeMod::MapWildList::SetTime(unsigned ts, bool t) +{ + for (std::vector::iterator i = times.begin(); i != times.end(); ++i) + { + if (*i == ts) + { + if (t) + return; + else + { + times.erase(i); + LogSetVar("MapWildList", id, String("time[%u]", ts), false); + return; + } + } + } + if (t) + { + times.push_back(ts); + LogSetVar("MapWildList", id, String("time[%u]", ts), true); + } +} + +void PokeGen::PokeMod::MapWildList::SetTime(const String &ts, bool t) +{ + LogSetVar("MapWildList", id, String("time[%u] string", ts), t); + SetTime(curPokeMod.GetTime(ts)->GetId(), t); +} + +void PokeGen::PokeMod::MapWildList::SetScope(unsigned s) +{ + LogSetVar("MapWildList", id, "scope", s); + unsigned i = 0; + unsigned j = 0; + if (Item *item = curPokeMod.GetItem(s)) + { + while (i < item->GetEffectCount()) + { + ItemEffect *effect = curPokeMod.GetItem(j++); + if (effect) + { + ++i; + if (effect->GetEffect() == IE_SCOPE) + scope = effect->GetVal1(); + } + } + } +} + +void PokeGen::PokeMod::MapWildList::SetScope(const String &s) +{ + LogSetVar("MapWildList", id, "scope string", s); + if (Item *i = curPokeMod.GetItem(s)) + SetScope(i->GetId()); +} + +unsigned PokeGen::PokeMod::MapWildList::GetControl() const +{ + LogFetchVar("MapWildList", id, "control", control); + return control; +} + +unsigned PokeGen::PokeMod::MapWildList::GetValue() const +{ + LogFetchVar("MapWildList", id, "value", value); + return value; +} + +bool PokeGen::PokeMod::MapWildList::GetTime(unsigned ts) const +{ + LogFetchVar("MapWildList", id, String("time[%u]", ts), "???"); + for (std::vector::iterator i = times.begin(); i != times.end(); ++i) + { + if (*i == ts) + return true; + } + return false; +} + +bool PokeGen::PokeMod::MapWildList::GetTime(const String &ts) const +{ + LogFetchVar("MapWildList", id, String("time[%u] string", ts), "???"); + if (Time *t = curPokeMod.GetTime(ts)) + return GetTime(t->GetId()); + return false; +} + +int PokeGen::PokeMod::MapWildList::GetScope() const +{ + LogFetchVar("MapWildList", id, "scope", scope); + return scope; +} + +PokeGen::PokeMod::MapWildPokemon *PokeGen::PokeMod::MapWildList::GetMapWildPokemon(unsigned _id) +{ + LogSubmoduleFetch("MapWildList", id, "Pokémon", _id); + for (unsigned i = 0; i < GetMapWildPokemonCount(); ++i) + { + if (pokemon[i].GetId() == _id) + return &pokemon[i]; + } + LogSubmoduleFetch("MapWildList", id, "Pokémon", _id); + return NULL; +} + +PokeGen::PokeMod::MapWildPokemon *PokeGen::PokeMod::MapWildList::GetMapWildPokemon(const String &n) +{ + LogSubmoduleFetch("MapWildList", id, "Pokémon string", n); + for (unsigned i = 0; i < GetMapWildPokemonCount(); ++i) + { + if (pokemon[i].GetPokemonString() == n) + return &pokemon[i]; + } + LogSubmoduleFetch("MapWildList", id, "Pokémon", _id); + return NULL; +} + +unsigned PokeGen::PokeMod::MapWildList::GetMapWildPokemonCount() const +{ + LogSubmoduleCount("MapWildList", id, "Pokémon"); + return pokemon.size(); +} + +void PokeGen::PokeMod::MapWildList::NewMapWildPokemon(Ini *const ini) +{ + unsigned i = 0; + // Find the first unused ID in the vector + for (; i < GetMapWildPokemonCount(); ++i) + { + if (!GetMapWildPokemon(i)) + break; + } + MapWildPokemon newMapWildPokemon(i); + if (ini) + newMapWildPokemon.ImportIni(*ini); + LogSubmoduleNew("MapWildList", id, "effect", i, name); + pokemon.push_back(newMapWildPokemon); +} + +void PokeGen::PokeMod::MapWildList::DeleteMapWildPokemon(unsigned _id) +{ + LogSubmoduleRemoveStart("MapWildList", id, "Pokémon", _id, name); + for (std::vector::iterator i = effects.begin(); i != effects.end(); ++i) + { + if (i->GetId() == _id) + { + LogSubmoduleRemoved("MapWildList", id, "Pokémon", _id, name); + effects.erase(i); + } + } + LogSubmoduleRemoveFail("MapWildList", id, "Pokémon", _id, name); +} -- cgit