From 9a65bc6bb7c8da1dfa5b101579e52845c75848ef Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 31 Mar 2008 01:17:59 +0000 Subject: [FIX] Member variables now use m_ prefix [FIX] Lots of minor fixes git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@95 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/MapTrainerTeamMember.cpp | 221 ++++++++++++++++++--------------------- 1 file changed, 100 insertions(+), 121 deletions(-) (limited to 'pokemod/MapTrainerTeamMember.cpp') diff --git a/pokemod/MapTrainerTeamMember.cpp b/pokemod/MapTrainerTeamMember.cpp index 1a14abf2..c733ada0 100644 --- a/pokemod/MapTrainerTeamMember.cpp +++ b/pokemod/MapTrainerTeamMember.cpp @@ -1,213 +1,192 @@ -///////////////////////////////////////////////////////////////////////////// -// 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 . -///////////////////////////////////////////////////////////////////////////// - -#include +/* + * Copyright 2007-2008 Ben Boeckel + * + * 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 . + */ + +// Qt includes +#include #include +// Pokemod includes #include "Pokemod.h" #include "Item.h" #include "Species.h" + +// Header include #include "MapTrainerTeamMember.h" -MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* par, const int _id) : - Object("MapTrainerTeamMember", par, _id), - species(-1), - level(-1), - nature(-1) +MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* pokemod, const int id) : + Object("MapTrainerTeamMember", pokemod, id), + m_species(INT_MAX), + m_level(INT_MAX), + m_nature(INT_MAX) { } -MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* par, const MapTrainerTeamMember& t, const int _id) : - Object("MapTrainerTeamMember", par, _id) +MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* pokemod, const MapTrainerTeamMember& teamMember, const int id) : + Object("MapTrainerTeamMember", pokemod, id) { - *this = t; + *this = teamMember; } -MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* par, const QString& fname, const int _id) : - Object("MapTrainerTeamMember", par, _id) +MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MapTrainerTeamMember", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool MapTrainerTeamMember::validate() const { bool valid = true; - pokemod->validationMsg(QString("---------Team Member with id %1---").arg(id), Pokemod::V_Msg); - if (pokemod->getSpeciesIndex(species) == -1) + pokemod()->validationMsg(QString("---------Team Member with id %1---").arg(id()), Pokemod::V_Msg); + if (pokemod()->speciesIndex(m_species) == INT_MAX) { - pokemod->validationMsg("Invalid species"); + pokemod()->validationMsg("Invalid species"); valid = false; } - if (pokemod->getRules()->getMaxLevel() <= level) + if (pokemod()->rules()->maxLevel() <= m_level) { - pokemod->validationMsg("Invalid level"); + pokemod()->validationMsg("Invalid level"); valid = false; } - if (items.size() <= pokemod->getRules()->getHoldItems()) + if (m_items.size() <= pokemod()->rules()->holdItems()) { - QMap idChecker; - for (QListIterator i(items); i.hasNext(); i.next()) - { - if (pokemod->getItemIndex(i.peekNext()) == -1) - { - pokemod->validationMsg("Invalid item"); - valid = false; - } - ++idChecker[i.peekNext()]; - } - for (QMapIterator i(idChecker); i.hasNext(); i.next()) + QMap itemChecker; + foreach (int item, m_items) { - if (1 < i.value()) + if (pokemod()->itemIndex(item) == INT_MAX) { - pokemod->validationMsg(QString("There are %1 items with id %2").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Invalid item"); valid = false; } + if (itemChecker[item]) + pokemod()->validationMsg(QString("Duplicate of item %1").arg(item)); + itemChecker[item] = true; } } else { - pokemod->validationMsg("Too many held items"); + pokemod()->validationMsg("Too many held items"); valid = false; } - if (pokemod->getRules()->getNatureAllowed()) + if (pokemod()->rules()->natureAllowed()) { - if (pokemod->getNatureIndex(nature) == -1) + if (pokemod()->natureIndex(m_nature) == INT_MAX) { - pokemod->validationMsg("Invalid nature"); + pokemod()->validationMsg("Invalid nature"); valid = false; } } return valid; } -void MapTrainerTeamMember::load(const QString& fname, const int _id) throw(Exception) +void MapTrainerTeamMember::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - items.clear(); - ini.getValue("species", species); - ini.getValue("level", level); - ini.getValue("nature", nature); + m_items.clear(); + ini.getValue("species", m_species); + ini.getValue("level", m_level); + ini.getValue("nature", m_nature); ini.getValue("numItems", i, 0); for (int k = 0; k < i; ++k) { ini.getValue(QString("item-%1").arg(k), j); - if (k != -1) - items.append(j); + if (!m_items.contains(j)) + m_items.append(j); } } void 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", items.size()); - for (int i = 0; i < 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)); + ini.addField("id", id()); + ini.addField("species", m_species); + ini.addField("level", m_level); + ini.addField("nature", m_nature); + ini.addField("numItems", m_items.size()); + for (int i = 0; i < m_items.size(); ++i) + ini.addField(QString("item-%1").arg(i), m_items[i]); + ini.save(QString("%1/map/%2/trainer/%3/team/%4.pini").arg(pokemod()->path()).arg(map).arg(trainer).arg(id())); } -void MapTrainerTeamMember::setSpecies(const int s) throw(BoundsException) +void MapTrainerTeamMember::setSpecies(const int species) throw(BoundsException) { - if (pokemod->getSpeciesIndex(s) == -1) - throw(BoundsException(className, "species")); - species = s; + if (pokemod()->speciesIndex(species) == INT_MAX) + throw(BoundsException(className(), "species")); + m_species = species; } -void MapTrainerTeamMember::setLevel(const int l) throw(BoundsException) +void MapTrainerTeamMember::setLevel(const int level) throw(BoundsException) { - if (pokemod->getRules()->getMaxLevel() < l) - throw(BoundsException(className, "level")); - level = l; + if (pokemod()->rules()->maxLevel() < level) + throw(BoundsException(className(), "level")); + m_level = level; } -void MapTrainerTeamMember::setItem(const int itm, const bool it) throw(Exception) +void MapTrainerTeamMember::setItem(const int item, const bool state) throw(BoundsException) { - if (pokemod->getItemIndex(itm) == -1) - throw(BoundsException(className, "item")); - for (QMutableListIterator i(items); i.hasNext(); ) + if (pokemod()->itemIndex(item) == INT_MAX) + throw(BoundsException(className(), "item")); + if (state) { - if (i.next() == itm) - { - if (it) - throw(Exception(className, "item already used")); - else - i.remove(); - } + if (!m_items.contains(item)) + m_items.append(item); } - if (!it) - throw(Exception(className, "item wasn\'t being used anyway")); - if (pokemod->getRules()->getHoldItems() <= items.size()) - throw(Exception(className, "too many items")); - items.append(itm); + else + m_items.removeAll(item); } -void MapTrainerTeamMember::setNature(const int n) throw(BoundsException) +void MapTrainerTeamMember::setNature(const int nature) throw(BoundsException) { - if (!pokemod->getRules()->getNatureAllowed() || (pokemod->getNatureIndex(n) == -1)) - throw(BoundsException(className, "nature")); - nature = n; + if (!pokemod()->rules()->natureAllowed() || (pokemod()->natureIndex(nature) == INT_MAX)) + throw(BoundsException(className(), "nature")); + m_nature = nature; } -int MapTrainerTeamMember::getSpecies() const +int MapTrainerTeamMember::species() const { - return species; + return m_species; } -int MapTrainerTeamMember::getLevel() const +int MapTrainerTeamMember::level() const { - return level; + return m_level; } -int MapTrainerTeamMember::getNature() const +int MapTrainerTeamMember::nature() const { - return nature; + return m_nature; } -bool MapTrainerTeamMember::getItem(const int itm) const +bool MapTrainerTeamMember::item(const int item) const { - for (QListIterator i(items); i.hasNext(); ) - { - if (i.next() == itm) - return true; - } - return false; + return m_items.contains(item); } MapTrainerTeamMember& MapTrainerTeamMember::operator=(const MapTrainerTeamMember& rhs) { if (this == &rhs) return *this; - species = rhs.species; - level = rhs.level; - nature = rhs.nature; - items = rhs.items; + m_species = rhs.m_species; + m_level = rhs.m_level; + m_nature = rhs.m_nature; + m_items = rhs.m_items; return *this; } -- cgit