diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2008-03-31 01:17:59 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2008-03-31 01:17:59 +0000 |
commit | 9a65bc6bb7c8da1dfa5b101579e52845c75848ef (patch) | |
tree | 258900f882a6998ac6fa525bd247e302028a8911 /pokemod/Ability.cpp | |
parent | 8e1ec2aec50999bae30625303f2c96e5b3b7f318 (diff) | |
download | sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.tar.gz sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.tar.xz sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.zip |
[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
Diffstat (limited to 'pokemod/Ability.cpp')
-rw-r--r-- | pokemod/Ability.cpp | 228 |
1 files changed, 111 insertions, 117 deletions
diff --git a/pokemod/Ability.cpp b/pokemod/Ability.cpp index 8cc1a319..ee2feeea 100644 --- a/pokemod/Ability.cpp +++ b/pokemod/Ability.cpp @@ -1,215 +1,209 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Ability.cpp -// Purpose: Define an ability that species can possess to add extra -// dynamics to the battle system -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:41:10 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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/>. + */ + +// Qt includes #include <QDir> -#include <QListIterator> #include <QMap> -#include <QMapIterator> #include <QStringList> -#include <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "AbilityEffect.h" + +// Header include #include "Ability.h" -Ability::Ability(const Pokemod* par, const int _id) : - Object("Ability", par, _id), - name("") +Ability::Ability(const Pokemod* pokemod, const int id) : + Object("Ability", pokemod, id), + m_name("") { } -Ability::Ability(const Pokemod* par, const Ability& a, const int _id) : - Object("Ability", par, _id) +Ability::Ability(const Pokemod* pokemod, const Ability& ability, const int id) : + Object("Ability", pokemod, id) { - *this = a; + *this = ability; } -Ability::Ability(const Pokemod* par, const QString& fname, const int _id) : - Object("Ability", par, _id) +Ability::Ability(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Ability", pokemod, id) { - load(fname, _id); + load(fileName, id); } Ability::~Ability() { - for (QListIterator<AbilityEffect*> i(effects); i.hasNext(); ) - delete i.next(); + foreach (AbilityEffect* effect, m_effects) + delete effect; } bool Ability::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Ability \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Ability \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("No Name"); + pokemod()->validationMsg("No Name"); valid = false; } - if (getEffectCount()) + if (effectCount()) { - QMap<int, int> idChecker; - for (QListIterator<AbilityEffect*> i(effects); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) + QMap<int, bool> idChecker; + foreach (AbilityEffect* effect, m_effects) { - if (1 < i.value()) - { - pokemod->validationMsg(QString("%2 effects with id %3").arg(name).arg(i.value()).arg(i.key())); + if (!effect->isValid()) valid = false; - } + if (idChecker[effect->id()]) + pokemod()->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); + idChecker[effect->id()] = true; } } else { - pokemod->validationMsg(QString("No effects").arg(name)); + pokemod()->validationMsg(QString("No effects")); valid = false; } return valid; } -int Ability::getNewId() const -{ - int i = 0; - for (; (i < getEffectCount()) && (getEffectIndex(i) != -1); ++i) - ; - return i; -} - -void Ability::load(const QString& fname, const int _id) throw(Exception) +void Ability::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) - ini.getValue("id", id); - else - id = _id; - ini.getValue("name", name); - QStringList path = pokemod->getPath().split('/'); + Ini ini(fileName); + if (id == INT_MAX) + ini.getValue("id", id, INT_MAX); + setId(id); + ini.getValue("name", m_name); + QStringList path = pokemod()->path().split('/'); path.removeLast(); QDir fdir(path.join("/")); - effects.clear(); + m_effects.clear(); if (fdir.cd("effect")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newEffect(i.next()); + QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); + foreach (QString file, files) + newEffect(file); } } void Ability::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.save(QString("%1/ability/%2/data.pini").arg(pokemod->getPath()).arg(name)); - for (QListIterator<AbilityEffect*> i(effects); i.hasNext(); ) - i.next()->save(name); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.save(QString("%1/ability/%2/data.pini").arg(pokemod()->path()).arg(m_name)); + foreach (AbilityEffect* effect, m_effects) + effect->save(m_name); } -void Ability::setName(const QString& n) +void Ability::setName(const QString& name) { - name = n; + m_name = name; } -QString Ability::getName() const +QString Ability::name() const { - return name; + return m_name; } -const AbilityEffect* Ability::getEffect(const int i) const throw(IndexException) +const AbilityEffect* Ability::effect(const int index) const throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects.at(i); + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects.at(index); } -AbilityEffect* Ability::getEffect(const int i) throw(IndexException) +AbilityEffect* Ability::effect(const int index) throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects[i]; + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects[index]; } -const AbilityEffect* Ability::getEffectByID(const int i) const throw(IndexException) +const AbilityEffect* Ability::effectById(const int id) const throw(IndexException) { - return getEffect(getEffectIndex(i)); + return effect(effectIndex(id)); } -AbilityEffect* Ability::getEffectByID(const int i) throw(IndexException) +AbilityEffect* Ability::effectById(const int id) throw(IndexException) { - return getEffect(getEffectIndex(i)); + return effect(effectIndex(id)); } -int Ability::getEffectIndex(const int _id) const +int Ability::effectIndex(const int id) const { - for (int i = 0; i < getEffectCount(); ++i) + for (int i = 0; i < effectCount(); ++i) { - if (effects[i]->getId() == _id) + if (m_effects[id]->id() == id) return i; } - return -1; + return INT_MAX; } -int Ability::getEffectCount() const +int Ability::effectCount() const { - return effects.size(); + return m_effects.size(); } AbilityEffect* Ability::newEffect() { - effects.append(new AbilityEffect(pokemod, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new AbilityEffect(pokemod(), effectId())); + return m_effects[effectCount() - 1]; } -AbilityEffect* Ability::newEffect(const QString& fname) +AbilityEffect* Ability::newEffect(const QString& fileName) { - effects.append(new AbilityEffect(pokemod, fname, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new AbilityEffect(pokemod(), fileName, effectId())); + return m_effects[effectCount() - 1]; } -AbilityEffect* Ability::newEffect(const AbilityEffect& e) +AbilityEffect* Ability::newEffect(const AbilityEffect& effect) { - effects.append(new AbilityEffect(pokemod, e, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new AbilityEffect(pokemod(), effect, effectId())); + return m_effects[effectCount() - 1]; } -void Ability::deleteEffect(const int i) throw(IndexException) +void Ability::deleteEffect(const int index) throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - delete effects[i]; - effects.removeAt(i); + if (effectCount() <= index) + throw(IndexException(className())); + delete m_effects[index]; + m_effects.removeAt(index); +} + +void Ability::deleteEffectById(const int id) throw(IndexException) +{ + deleteEffect(effectIndex(id)); +} + +int Ability::effectId() const +{ + int i = 0; + while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) + ++i; + return i; } Ability& Ability::operator=(const Ability& rhs) { if (this == &rhs) return *this; - name = rhs.name; - effects.clear(); - for (int i = 0; i < rhs.getEffectCount(); ++i) - effects.append(new AbilityEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId())); + m_name = rhs.m_name; + m_effects.clear(); + foreach (AbilityEffect* effect, rhs.m_effects) + m_effects.append(new AbilityEffect(pokemod(), *effect, effect->id())); return *this; } |