From 3595239f08f2bc1df32ef22ed6de9bde10ca3384 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 4 Jun 2007 01:35:20 +0000 Subject: Style cleanup, minor Matrix fixes, duplication validations, Pokemod methods git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@19 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/MapWildList.cpp | 91 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 15 deletions(-) (limited to 'pokemod/MapWildList.cpp') diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp index d7dab5f5..6ffdcf28 100644 --- a/pokemod/MapWildList.cpp +++ b/pokemod/MapWildList.cpp @@ -26,9 +26,9 @@ extern PokeGen::PokeMod::Pokemod curPokeMod; PokeGen::PokeMod::MapWildList::MapWildList(const unsigned _id) : - control(UINT_MAX), - value(INT_MAX), - scope(INT_MAX) + control(UINT_MAX), + value(INT_MAX), + scope(INT_MAX) { LogCtor("MapWildList", _id); id = _id; @@ -54,15 +54,35 @@ void PokeGen::PokeMod::MapWildList::Validate() #endif { LogValidateStart("MapWildList", id); + unsigned i = 0; + unsigned j = 0; + bool temp = false; if (CTRL_END <= control) { LogVarNotValid("MapWildList", id, "control"); - isValid = true; + isValid = false; } else if (control == CTRL_FISHING) { - // TODO (Ben#1#): Value validation + if (const Item *item = curPokeMod.GetItem(value)) + { + while ((i < item->GetItemEffectCount()) || !temp) + { + if (const ItemEffect *e = item->GetItemEffect(j++)) + { + ++i; + if (e->GetEffect() == IE_FISH) + temp = true; + } + } + } + if (!temp) + { + LogVarNotValid("ItemEffect", id, "value"); + isValid = false; + } } + std::map idChecker; for (std::vector::const_iterator i = times.begin(); i != times.end(); ++i) { if (!curPokeMod.GetTime(*i)) @@ -70,8 +90,42 @@ void PokeGen::PokeMod::MapWildList::Validate() LogVarNotValid("MapWildList", id, "times"); isValid = false; } + ++idChecker[*i]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("MapWildList", id, "times", i->first); + isValid = false; + } + } + if (scope != UINT_MAX) + { + temp = false; + if (const Item *item = curPokeMod.GetItem(scope)) + { + i = 0; + j = 0; + while (i < item->GetItemEffectCount()) + { + if (const ItemEffect *e = item->GetItemEffect(j++)) + { + ++i; + if (e->GetEffect() == IE_SCOPE) + { + temp = true; + break; + } + } + } + } + if (!temp) + { + LogVarNotValid("ItemEffect", id, "value"); + isValid = false; + } } - // TODO (Ben#1#): Scope validation LogValidateOver("MapWildList", id, isValid); } @@ -81,7 +135,6 @@ void PokeGen::PokeMod::MapWildList::ImportIni(Ini &ini, const unsigned _id) if (_id == UINT_MAX) { ini.GetValue("id", id); - // Was there an id associated with the element? if (id == UINT_MAX) LogIdNotFound("MapWildList"); } @@ -106,7 +159,6 @@ void PokeGen::PokeMod::MapWildList::ImportIni(Ini &ini, const unsigned _id) 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); @@ -130,11 +182,11 @@ void PokeGen::PokeMod::MapWildList::SetControl(const unsigned c) void PokeGen::PokeMod::MapWildList::SetValue(const unsigned v) { - unsigned i = 0; - unsigned j = 0; LogSetVar("MapWildList", id, "value", v); if (const Item *item = curPokeMod.GetItem(v)) { + unsigned i = 0; + unsigned j = 0; while (i < item->GetItemEffectCount()) { if (const ItemEffect *effect = item->GetItemEffect(j++)) @@ -142,7 +194,7 @@ void PokeGen::PokeMod::MapWildList::SetValue(const unsigned v) ++i; if (effect->GetEffect() == IE_FISH) { - value = effect->GetVal1(); + value = v; break; } } @@ -187,17 +239,22 @@ void PokeGen::PokeMod::MapWildList::SetTime(const String &ts, const bool t) void PokeGen::PokeMod::MapWildList::SetScope(const unsigned s) { LogSetVar("MapWildList", id, "scope", s); - unsigned i = 0; - unsigned j = 0; + if (s == UINT_MAX) + { + scope = UINT_MAX; + return; + } if (const Item *item = curPokeMod.GetItem(s)) { + unsigned i = 0; + unsigned j = 0; while (i < item->GetItemEffectCount()) { if (const ItemEffect *effect = item->GetItemEffect(j++)) { ++i; if (effect->GetEffect() == IE_SCOPE) - scope = effect->GetVal1(); + scope = s; } } } @@ -206,6 +263,11 @@ void PokeGen::PokeMod::MapWildList::SetScope(const unsigned s) void PokeGen::PokeMod::MapWildList::SetScope(const String &s) { LogSetVar("MapWildList", id, "scope string", s); + if (s == "None") + { + scope = UINT_MAX; + return; + } if (const Item *i = curPokeMod.GetItem(s)) SetScope(i->GetId()); } @@ -280,7 +342,6 @@ unsigned PokeGen::PokeMod::MapWildList::GetMapWildPokemonCount() const 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)) -- cgit