summaryrefslogtreecommitdiffstats
path: root/pokemod/MapTrainerTeamMember.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-01-21 00:44:23 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-01-21 00:44:23 +0000
commit2b653821cc31f18adb5d50bb0bc19048939670dc (patch)
treed333bbf0d1dde8fe0c1633bea60785b20ac07841 /pokemod/MapTrainerTeamMember.cpp
parente27ba66952a1e851bb417611e0ed7df1fbf5f945 (diff)
downloadsigen-2b653821cc31f18adb5d50bb0bc19048939670dc.tar.gz
sigen-2b653821cc31f18adb5d50bb0bc19048939670dc.tar.xz
sigen-2b653821cc31f18adb5d50bb0bc19048939670dc.zip
[ADD] More GUI classes (only MoveEffect left)
[FIX] Polished up GUI classes [FIX] renamed methods get*ByID -> get*Index instead for more logical get*ByID [FIX] Renaming in pokemod to remove mention of Pokémon [FIX] minor .pro fixes (aesthetic mainly) git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@35 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/MapTrainerTeamMember.cpp')
-rw-r--r--pokemod/MapTrainerTeamMember.cpp201
1 files changed, 201 insertions, 0 deletions
diff --git a/pokemod/MapTrainerTeamMember.cpp b/pokemod/MapTrainerTeamMember.cpp
new file mode 100644
index 00000000..eb7fa0d1
--- /dev/null
+++ b/pokemod/MapTrainerTeamMember.cpp
@@ -0,0 +1,201 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: pokemod/MapTrainerTeamMember.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-2008 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 "MapTrainerTeamMember.h"
+
+PokeMod::MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod& par, const unsigned _id) :
+ Object(par, _id),
+ species(UINT_MAX),
+ level(UINT_MAX),
+ nature(UINT_MAX)
+{
+}
+
+PokeMod::MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod& par, const QString& fname, const unsigned _id) :
+ Object(par, _id)
+{
+ load(fname, _id);
+}
+
+bool PokeMod::MapTrainerTeamMember::validate() const
+{
+ bool valid = true;
+ pokemod.validationMsg(QString("---------Team Member with id %1---").arg(id), Pokemod::V_Msg);
+ if (pokemod.getSpeciesIndex(species) == UINT_MAX)
+ {
+ pokemod.validationMsg("Invalid species");
+ valid = false;
+ }
+ if (pokemod.getRules().getMaxLevel() <= level)
+ {
+ pokemod.validationMsg("Invalid level");
+ valid = false;
+ }
+ if (unsigned(items.size()) <= pokemod.getRules().getHoldItems())
+ {
+ QMap<unsigned, unsigned> idChecker;
+ for (QListIterator<unsigned> i(items); i.hasNext(); i.next())
+ {
+ if (pokemod.getItemIndex(i.peekNext()) == UINT_MAX)
+ {
+ pokemod.validationMsg("Invalid item");
+ valid = false;
+ }
+ ++idChecker[i.peekNext()];
+ }
+ for (QMapIterator<unsigned, unsigned> i(idChecker); i.hasNext(); i.next())
+ {
+ if (1 < i.value())
+ {
+ pokemod.validationMsg(QString("There are %1 items with id %2").arg(i.value()).arg(i.key()));
+ valid = false;
+ }
+ }
+ }
+ else
+ {
+ pokemod.validationMsg("Too many held items");
+ valid = false;
+ }
+ if (pokemod.getRules().getNatureAllowed())
+ {
+ if (pokemod.getNatureIndex(nature) == UINT_MAX)
+ {
+ pokemod.validationMsg("Invalid nature");
+ valid = false;
+ }
+ }
+ return valid;
+}
+
+void PokeMod::MapTrainerTeamMember::load(const QString& fname, const unsigned _id) throw(Exception)
+{
+ Ini ini(fname);
+ 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);
+ ini.getValue("nature", nature);
+ 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 PokeMod::MapTrainerTeamMember::save(const QString& map, const QString& trainer) const throw(Exception)
+{
+ Ini ini;
+ ini.addField("id", id);
+ ini.addField("species", species);
+ ini.addField("level", level);
+ ini.addField("nature", nature);
+ ini.addField("numItems", unsigned(items.size()));
+ for (unsigned i = 0; i < unsigned(items.size()); ++i)
+ ini.addField(QString("item-%1").arg(i), items[i]);
+ ini.save(QString("%1/map/%2/trainer/%3/team/%4.pini").arg(pokemod.getPath()).arg(map).arg(trainer).arg(id));
+}
+
+void PokeMod::MapTrainerTeamMember::setSpecies(const unsigned s) throw(BoundsException)
+{
+ if (pokemod.getSpeciesIndex(s) == UINT_MAX)
+ throw(BoundsException("MapTrainerTeamMember", "species"));
+ species = s;
+}
+
+void PokeMod::MapTrainerTeamMember::setLevel(const unsigned l) throw(BoundsException)
+{
+ if (pokemod.getRules().getMaxLevel() < l)
+ throw(BoundsException("MapTrainerTeamMember", "level"));
+ level = l;
+}
+
+void PokeMod::MapTrainerTeamMember::setItem(const unsigned itm, const bool it) throw(Exception)
+{
+ if (pokemod.getItemIndex(itm) == UINT_MAX)
+ throw(BoundsException("MpTrainerPokemon", "item"));
+ for (QMutableListIterator<unsigned> i(items); i.hasNext(); )
+ {
+ if (i.next() == itm)
+ {
+ if (it)
+ throw(Exception("MapTrainerTeamMember", "item already used"));
+ else
+ i.remove();
+ }
+ }
+ if (!it)
+ throw(Exception("MapTrainerTeamMember", "item wasn\'t being used anyway"));
+ if (pokemod.getRules().getHoldItems() <= unsigned(items.size()))
+ throw(Exception("MapTrainerTeamMember", "too many items"));
+ items.append(itm);
+}
+
+void PokeMod::MapTrainerTeamMember::setNature(const unsigned n) throw(BoundsException)
+{
+ if (!pokemod.getRules().getNatureAllowed() || (pokemod.getNatureIndex(n) == UINT_MAX))
+ throw(BoundsException("MapTrainerTeamMember", "nature"));
+ nature = n;
+}
+
+unsigned PokeMod::MapTrainerTeamMember::getSpecies() const
+{
+ return species;
+}
+
+unsigned PokeMod::MapTrainerTeamMember::getLevel() const
+{
+ return level;
+}
+
+unsigned PokeMod::MapTrainerTeamMember::getNature() const
+{
+ return nature;
+}
+
+bool PokeMod::MapTrainerTeamMember::getItem(const unsigned itm) const
+{
+ for (QListIterator<unsigned> i(items); i.hasNext(); )
+ {
+ if (i.next() == itm)
+ return true;
+ }
+ return false;
+}
+
+PokeMod::MapTrainerTeamMember& PokeMod::MapTrainerTeamMember::operator=(const MapTrainerTeamMember& rhs)
+{
+ if (this == &rhs)
+ return *this;
+ species = rhs.species;
+ level = rhs.level;
+ nature = rhs.nature;
+ items = rhs.items;
+ return *this;
+}