/////////////////////////////////////////////////////////////////////////////
// Name: pokemod/MapWildList.cpp
// Purpose: Define a list of species 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 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 "MapWildList.h"
const char* PokeGen::PokeMod::MapWildList::ControlStr[PokeGen::PokeMod::MapWildList::End] = {"Grass", "Surfing", "Fishing", "Dive", "Headbutt", "Rock Smash"};
PokeGen::PokeMod::MapWildList::MapWildList(const Pokemod* par, const unsigned _id) :
Object(_id, par),
control(UINT_MAX),
value(INT_MAX),
scope(INT_MAX)
{
}
PokeGen::PokeMod::MapWildList::MapWildList(const Pokemod* par, Ini& ini, const unsigned _id) :
Object(_id, par)
{
ImportIni(ini, _id);
}
bool PokeGen::PokeMod::MapWildList::Validate()
{
pokemod->ValidationMsg(QString("------Wild List with id %1---").arg(id), Pokemod::V_Msg);
if (End <= control)
{
pokemod->ValidationMsg("Invalid control");
isValid = false;
}
else if (control == Fishing)
{
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_Fish)
temp = true;
}
}
}
if (!temp)
{
pokemod->ValidationMsg("Invalid fishing value");
isValid = false;
}
}
QMap idChecker;
for (QList::ConstIterator i = times.begin(); i != times.end(); ++i)
{
if (!pokemod->GetTime(*i))
{
pokemod->ValidationMsg("Invalid times");
isValid = false;
}
++idChecker[*i];
}
for (QMap::ConstIterator i = idChecker.begin(); i != idChecker.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;
}
}
if (scope != UINT_MAX)
{
bool temp = false;
if (const Item* item = pokemod->GetItem(scope))
{
for (unsigned i = 0; (i < item->GetEffectCount()) && !temp; ++i)
{
if (const ItemEffect* e = item->GetEffect(i))
{
if (e->GetEffect() == ItemEffect::E_Scope)
temp = true;
}
}
}
if (!temp)
{
pokemod->ValidationMsg("Invalid scope");
isValid = false;
}
}
return isValid;
}
void PokeGen::PokeMod::MapWildList::ImportIni(Ini& ini, const unsigned _id)
{
if (_id == UINT_MAX)
ini.GetValue("id", id);
else
id = _id;
unsigned i;
unsigned j;
times.clear();
ini.GetValue("control", control);
ini.GetValue("value", value);
ini.GetValue("numTimes", i, 0);
for (unsigned k = 0; k < i; ++k)
{
ini.GetValue(QString("time-%1").arg(k), j, UINT_MAX);
if (k != UINT_MAX)
times.append(j);
}
ini.GetValue("scope", scope);
}
void PokeGen::PokeMod::MapWildList::ExportIni(QFile& fout, const QString& map) const
{
Ini exMapWildList(map + " mapWildList");
exMapWildList.AddField("id", id);
exMapWildList.AddField("control", control);
exMapWildList.AddField("value", value);
exMapWildList.AddField("numTimes", times.size());
for (int i = 0; i < times.size(); ++i)
exMapWildList.AddField(QString("time-%1").arg(i), times[i]);
exMapWildList.AddField("scope", scope);
exMapWildList.Export(fout);
for (QList::ConstIterator i = pokemon.begin(); i != pokemon.end(); ++i)
i->ExportIni(fout, map, id);
}
bool PokeGen::PokeMod::MapWildList::SetControl(const unsigned c)
{
if (c < End)
control = c;
return (control == c);
}
bool PokeGen::PokeMod::MapWildList::SetValue(const unsigned v)
{
if (v == UINT_MAX)
{
value = UINT_MAX;
return true;
}
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_Fish)
{
value = v;
return true;
}
}
}
}
return false;
}
bool PokeGen::PokeMod::MapWildList::SetTime(const unsigned ts, const bool t)
{
for (QList::Iterator i = times.begin(); i != times.end(); ++i)
{
if (*i == ts)
{
if (!t)
{
times.erase(i);
return true;
}
return false;
}
}
if (t)
{
times.append(ts);
return true;
}
return false;
}
bool PokeGen::PokeMod::MapWildList::SetScope(const unsigned s)
{
if (s == UINT_MAX)
{
scope = UINT_MAX;
return true;
}
if (const Item* item = pokemod->GetItem(s))
{
for (unsigned i = 0; i < item->GetEffectCount(); ++i)
{
if (const ItemEffect* effect = item->GetEffect(i))
{
if (effect->GetEffect() == ItemEffect::E_Scope)
{
scope = s;
return true;
}
}
}
}
return false;
}
unsigned PokeGen::PokeMod::MapWildList::GetControl() const
{
return control;
}
int PokeGen::PokeMod::MapWildList::GetValue() const
{
return value;
}
bool PokeGen::PokeMod::MapWildList::GetTime(const unsigned ts) const
{
for (QList::ConstIterator i = times.begin(); i != times.end(); ++i)
{
if (*i == ts)
return true;
}
return false;
}
int PokeGen::PokeMod::MapWildList::GetScope() const
{
return scope;
}
const PokeGen::PokeMod::MapWildListPokemon* PokeGen::PokeMod::MapWildList::GetPokemon(const unsigned i) const
{
if (i < GetPokemonCount())
return &pokemon[i];
return NULL;
}
unsigned PokeGen::PokeMod::MapWildList::GetPokemonByID(const unsigned _id) const
{
for (unsigned i = 0; i < GetPokemonCount(); ++i)
{
if (pokemon[i].GetId() == _id)
return i;
}
return UINT_MAX;
}
unsigned PokeGen::PokeMod::MapWildList::GetPokemonCount() const
{
return pokemon.size();
}
const PokeGen::PokeMod::MapWildListPokemon* PokeGen::PokeMod::MapWildList::NewPokemon(Ini* const ini)
{
unsigned i = 0;
for (; (i < GetPokemonCount()) && (GetPokemonByID(i) != UINT_MAX); ++i)
;
MapWildListPokemon newPokemon(pokemod, i);
if (ini)
newPokemon.ImportIni(*ini);
pokemon.append(newPokemon);
return &pokemon[GetPokemonCount() - 1];
}
bool PokeGen::PokeMod::MapWildList::DeletePokemon(const unsigned i)
{
if (i < GetPokemonCount())
{
pokemon.erase(pokemon.begin() + i);
return true;
}
return false;
}