diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-09-21 15:36:22 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-09-21 15:36:22 +0000 |
| commit | 5b55d13ead7e352ee1feaae72009e8abf5bd071a (patch) | |
| tree | 6c2838312dd7f42769280e24e8abc16b53c165cb /pokemod/MapTrainerPokemon.cpp | |
| parent | e94d9893b8753e72adb92b2c5eb203830ddf641c (diff) | |
[FIX] Neural Network methods complete
[FIX] Wrapped Node up into the layer
[FIX] Wrapped NatureEffect into Nature
[FIX] Getting around to fixing up the design of the PokéMod stuff
[FIX] Creating new subclasses now returns pointer to new subclass
[FIX] Simplified interfaces
[FIX] Minor style issues
[FIX] Renamed CoinItem to CoinListObject
[FIX] Renamed MapTrainerTeam to MapTrainerPokemon
[FIX] Renamed MapWildPokemon to MapWildListPokemon
[FIX] Moved global enums to relevant classes
[FIX] Removed general logging features
[DEL] pokemod/Debug.{h, cpp}
[DEL] pokemod/Path.{h, cpp}
[FIX] Using QFile rather than custom Path class for checking for files
[FIX] Set* methods now return a bool to let the caller know if anything actually changed (if it can fail, otherwise it is void)
[ADD] Compliation without errors is required for pokemod from now on before commits
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@24 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/MapTrainerPokemon.cpp')
| -rw-r--r-- | pokemod/MapTrainerPokemon.cpp | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/pokemod/MapTrainerPokemon.cpp b/pokemod/MapTrainerPokemon.cpp new file mode 100644 index 00000000..1acb6dcd --- /dev/null +++ b/pokemod/MapTrainerPokemon.cpp @@ -0,0 +1,184 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: pokemod/MapTrainerPokemon.cpp +// Purpose: Define a Pokémon on a trainer's team +// Author: Ben Boeckel +// Modified by: Ben Boeckel +// Created: Tue Mar 20 19:20:21 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 <http://www.gnu.org/licenses/>. +///////////////////////////////////////////////////////////////////////////// + +#include "MapTrainerPokemon.h" + +PokeGen::PokeMod::MapTrainerPokemon::MapTrainerPokemon(const Pokemod* par, const unsigned _id) : + Object(_id, par), + species(UINT_MAX), + level(1) +{ +} + +PokeGen::PokeMod::MapTrainerPokemon::MapTrainerPokemon(const Pokemod* par, Ini& ini, const unsigned _id) : + Object(_id, par) +{ + ImportIni(ini, _id); +} + +bool PokeGen::PokeMod::MapTrainerPokemon::Validate() +{ + pokemod->ValidationMsg(QString("---------Pokémon with id %1---").arg(id), Pokemod::V_Msg); + if (pokemod->GetPokemonByID(species) == UINT_MAX) + { + pokemod->ValidationMsg("Invalid species"); + isValid = false; + } + if (pokemod->GetMaxLevel() <= level) + { + pokemod->ValidationMsg("Invalid level"); + isValid = false; + } + if (GetItemCount() <= pokemod->GetHoldItems()) + { + QMap<unsigned, unsigned> idChecker; + QMap<QString, unsigned> itemChecker; + for (QList<unsigned>::ConstIterator i = items.begin(); i != items.end(); ++i) + { + if (pokemod->GetItemByID(*i) == UINT_MAX) + { + pokemod->ValidationMsg("Invalid item"); + isValid = false; + } + ++idChecker[*i]; + ++itemChecker[pokemod->GetItem(*i)->GetName()]; + } + for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 items with id %2").arg(i.value()).arg(i.key())); + isValid = false; + } + } + for (QMap<QString, unsigned>::ConstIterator i = itemChecker.begin(); i != itemChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 items with the name \"%2\"").arg(i.value()).arg(i.key())); + isValid = false; + } + } + } + else if (GetItemCount()) + { + pokemod->ValidationMsg("Too many held items"); + isValid = false; + } + else + pokemod->ValidationMsg("There are no items", Pokemod::V_Warn); + return isValid; +} + +void PokeGen::PokeMod::MapTrainerPokemon::ImportIni(Ini& ini, const unsigned _id) +{ + if (_id == UINT_MAX) + ini.GetValue("id", id); + else + id = _id; + unsigned i; + unsigned j; + items.clear(); + ini.GetValue("species", species); + ini.GetValue("level", level, 1); + ini.GetValue("numItems", i, 0); + for (unsigned k = 0; k < i; ++k) + { + ini.GetValue(QString("item-%1").arg(k), j); + if (k != UINT_MAX) + items.append(j); + } +} + +void PokeGen::PokeMod::MapTrainerPokemon::ExportIni(QFile& fout, const QString& map, const unsigned trainerId) const +{ + Ini exMapTrainerPokemon(QString("mapTrainerPokemon %1 ").arg(trainerId) + map); + exMapTrainerPokemon.AddField("id", id); + exMapTrainerPokemon.AddField("species", species); + exMapTrainerPokemon.AddField("level", level); + exMapTrainerPokemon.AddField("numItems", GetItemCount()); + for (unsigned i = 0; i < GetItemCount(); ++i) + exMapTrainerPokemon.AddField(QString("item-%1").arg(i), items[i]); + exMapTrainerPokemon.Export(fout); +} + +bool PokeGen::PokeMod::MapTrainerPokemon::SetSpecies(const unsigned s) +{ + if (pokemod->GetPokemonByID(s) != UINT_MAX) + species = s; + return (species == s); +} + +bool PokeGen::PokeMod::MapTrainerPokemon::SetLevel(const unsigned l) +{ + if (l <= pokemod->GetMaxLevel()) + level = l; + return (level == l); +} + +unsigned PokeGen::PokeMod::MapTrainerPokemon::GetSpecies() const +{ + return species; +} + +unsigned PokeGen::PokeMod::MapTrainerPokemon::GetLevel() const +{ + return level; +} + +unsigned PokeGen::PokeMod::MapTrainerPokemon::GetItem(const unsigned i) const +{ + if (i < GetItemCount()) + return items[i]; + return UINT_MAX; +} + +unsigned PokeGen::PokeMod::MapTrainerPokemon::GetItemByID(const unsigned _id) const +{ + for (unsigned i = 0; i < GetItemCount(); ++i) + { + if (items[i] == _id) + return i; + } + return UINT_MAX; +} + +unsigned PokeGen::PokeMod::MapTrainerPokemon::GetItemCount() const +{ + return items.size(); +} + +void PokeGen::PokeMod::MapTrainerPokemon::NewItem(const unsigned i) +{ + if ((GetItemCount() < pokemod->GetHoldItems()) && pokemod->GetItem(i)) + items.append(i); +} + +bool PokeGen::PokeMod::MapTrainerPokemon::DeleteItem(const unsigned i) +{ + if (i < GetItemCount()) + { + items.erase(items.begin() + i); + return true; + } + return false; +} |
