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/Move.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/Move.cpp')
| -rw-r--r-- | pokemod/Move.cpp | 494 |
1 files changed, 240 insertions, 254 deletions
diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index 6f8ad323..aaf6af7b 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -1,451 +1,437 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Move.cpp -// Purpose: Define a move that can be learned -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sat May 26 2007 22:51:21 -// 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 <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "MoveEffect.h" + +// Header include #include "Move.h" -const QStringList Move::TargetStr = QStringList() << "Player" << "Enemy" << "Both" << "Random"; +const QStringList Move::TargetStr = QStringList() << "Player" << "Enemy" << "All" << "Random"; const QStringList Move::ChoiceStr = QStringList() << "Player" << "Enemy" << "Random"; -Move::Move(const Pokemod* par, const int _id) : - Object("Move", par, _id), - name(""), - accuracy(1, 1), - power(0), - type(-1), - special(false), - powerPoints(0), - target(-1), - targetChoice(-1), - ignoreAccuracy(false), - canFlinch(false), - canRandom(false), - canSnatch(false), - sound(false), - description("") +Move::Move(const Pokemod* pokemod, const int id) : + Object("Move", pokemod, id), + m_name(""), + m_accuracy(1, 1), + m_power(0), + m_type(INT_MAX), + m_special(false), + m_powerPoints(0), + m_target(INT_MAX), + m_targetChoice(INT_MAX), + m_ignoreAccuracy(false), + m_canFlinch(false), + m_canRandom(false), + m_canSnatch(false), + m_sound(false), + m_priority(1), + m_description("") { } -Move::Move(const Pokemod* par, const Move& m, const int _id) : - Object("Move", par, _id) +Move::Move(const Pokemod* pokemod, const Move& move, const int id) : + Object("Move", pokemod, id) { - *this = m; + *this = move; } -Move::Move(const Pokemod* par, const QString& fname, const int _id) : - Object("Move", par, _id) +Move::Move(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Move", pokemod, id) { - load(fname, _id); + load(fileName, id); } Move::~Move() { - for (QListIterator<MoveEffect*> i(effects); i.hasNext(); ) - delete i.next(); + foreach (MoveEffect* effect, m_effects) + delete effect; } bool Move::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Move \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Move \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = ""; } - if (pokemod->getTypeIndex(type) == -1) + if (pokemod()->typeIndex(m_type) == INT_MAX) { - pokemod->validationMsg("Invalid type"); + pokemod()->validationMsg("Invalid type"); valid = false; } - if (!powerPoints) + if (!m_powerPoints) { - pokemod->validationMsg("Invalid number of power points"); + pokemod()->validationMsg("Invalid number of power points"); valid = false; } - if (T_End <= target) + if (T_End <= m_target) { - pokemod->validationMsg("Invalid target"); + pokemod()->validationMsg("Invalid target"); valid = false; } - if (!target || (pokemod->getRules()->getMaxFight() << (target == T_Both)) < numTargets) + if (!m_target || (pokemod()->rules()->maxFight() * ((m_target == T_All) ? pokemod()->rules()->maxPlayers() : 1)) < m_numTargets) { - pokemod->validationMsg("Invalid number of targets"); + pokemod()->validationMsg("Invalid number of targets"); valid = false; } - if (C_End <= targetChoice) + if (C_End <= m_targetChoice) { - pokemod->validationMsg("Invalid target choice"); + pokemod()->validationMsg("Invalid target choice"); valid = false; } - if (getEffectCount()) + if (effectCount()) { - QMap<int, int> idChecker; - for (QListIterator<MoveEffect*> 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 (MoveEffect* effect, m_effects) { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 effects with id %2").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("There are no effects"); + pokemod()->validationMsg("There are no effects"); valid = false; } return valid; } -int Move::getNewId() const +void Move::load(const QString& fileName, int id) throw(Exception) { - int i = 0; - for (; (i < getEffectCount()) && (getEffectIndex(i) != -1); ++i) - ; - return i; -} - -void Move::load(const QString& fname, const 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; - ini.getValue("name", name); + ini.getValue("name", m_name); ini.getValue("accuracy-n", i, 1); ini.getValue("accuracy-d", j, 1); - accuracy.set(i, j); - ini.getValue("power", power, 0); - ini.getValue("type", type); - ini.getValue("special", special, false); - ini.getValue("powerPoints", powerPoints, 1); - ini.getValue("target", target); - ini.getValue("numTargets", numTargets, 0); - ini.getValue("targetChoice", targetChoice); - ini.getValue("ignoreAccuracy", ignoreAccuracy, false); - ini.getValue("canFlinch", canFlinch, false); - ini.getValue("canRandom", canRandom, false); - ini.getValue("canSnatch", canSnatch, false); - ini.getValue("sound", sound, false); - ini.getValue("description", description, ""); - QStringList path = pokemod->getPath().split('/'); + m_accuracy.set(i, j); + ini.getValue("power", m_power, 0); + ini.getValue("type", m_type); + ini.getValue("special", m_special, false); + ini.getValue("powerPoints", m_powerPoints, 1); + ini.getValue("target", m_target); + ini.getValue("numTargets", m_numTargets, 0); + ini.getValue("targetChoice", m_targetChoice); + ini.getValue("ignoreAccuracy", m_ignoreAccuracy, false); + ini.getValue("canFlinch", m_canFlinch, false); + ini.getValue("canRandom", m_canRandom, false); + ini.getValue("canSnatch", m_canSnatch, false); + ini.getValue("sound", m_sound, false); + ini.getValue("description", m_description, ""); + 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 Move::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("accuracy-n", accuracy.getNum()); - ini.addField("accuracy-d", accuracy.getDenom()); - ini.addField("power", power); - ini.addField("type", type); - ini.addField("special", special); - ini.addField("powerPoints", powerPoints); - ini.addField("target", target); - ini.addField("numTargets", numTargets); - ini.addField("targetChoice", targetChoice); - ini.addField("ignoreAccuracy", ignoreAccuracy); - ini.addField("canFlinch", canFlinch); - ini.addField("canRandom", canRandom); - ini.addField("canSnatch", canSnatch); - ini.addField("sound", sound); - ini.addField("description", description); - ini.save(QString("%1/move/%2/data.pini").arg(pokemod->getPath()).arg(name)); - for (QListIterator<MoveEffect*> i(effects); i.hasNext(); ) - i.next()->save(name); -} - -void Move::setName(const QString& n) -{ - name = n; + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("accuracy-n", m_accuracy.numerator()); + ini.addField("accuracy-d", m_accuracy.denominator()); + ini.addField("power", m_power); + ini.addField("type", m_type); + ini.addField("special", m_special); + ini.addField("powerPoints", m_powerPoints); + ini.addField("target", m_target); + ini.addField("numTargets", m_numTargets); + ini.addField("targetChoice", m_targetChoice); + ini.addField("ignoreAccuracy", m_ignoreAccuracy); + ini.addField("canFlinch", m_canFlinch); + ini.addField("canRandom", m_canRandom); + ini.addField("canSnatch", m_canSnatch); + ini.addField("sound", m_sound); + ini.addField("description", m_description); + ini.save(QString("%1/move/%2/data.pini").arg(pokemod()->path()).arg(m_name)); + foreach (MoveEffect* effect, m_effects) + effect->save(m_name); +} + +void Move::setName(const QString& name) +{ + m_name = name; } void Move::setAccuracy(const int n, const int d) throw(Exception) { - accuracy.set(n, d); + m_accuracy.set(n, d); } -void Move::setAccuracyNum(const int n) throw(Exception) +void Move::setType(const int type) throw(BoundsException) { - accuracy.setNum(n); + if (pokemod()->typeIndex(type) == INT_MAX) + throw(BoundsException(className(), "type")); + m_type = type; } -void Move::setAccuracyDenom(const int d) throw(Exception) +void Move::setSpecial(const bool special) { - accuracy.setDenom(d); + m_special = special; } -void Move::setType(const int t) throw(BoundsException) +void Move::setPowerPoints(const int powerPoints) throw(BoundsException) { - if (pokemod->getTypeIndex(t) == -1) - throw(BoundsException(className, "type")); - type = t; + if (!powerPoints) + throw(BoundsException(className(), "powerPoints")); + m_powerPoints = powerPoints; } -void Move::setSpecial(const bool s) +void Move::setTarget(const int target) throw(BoundsException) { - special = s; + if (T_End <= target) + throw(BoundsException(className(), "target")); + m_target = target; } -void Move::setPowerPoints(const int p) throw(BoundsException) +void Move::setNumTargets(const int numTargets) throw(BoundsException) { - if (!p) - throw(BoundsException(className, "powerPoints")); - powerPoints = p; + if (!numTargets || ((pokemod()->rules()->maxFight() * ((m_target == T_All) ? pokemod()->rules()->maxPlayers() : 1)) < numTargets)) + throw(BoundsException(className(), "numTargets")); + m_numTargets = numTargets; } -void Move::setTarget(const int t) throw(BoundsException) +void Move::setTargetChoice(const int targetChoice) throw(BoundsException) { - if (T_End <= t) - throw(BoundsException(className, "target")); - target = t; + if (C_End <= targetChoice) + throw(BoundsException(className(), "targetChoice")); + m_targetChoice = targetChoice; } -void Move::setNumTargets(const int n) throw(BoundsException) +void Move::setIgnoreAccuracy(const bool ignoreAccuracy) { - if (!n || ((pokemod->getRules()->getMaxFight() << 1) < n)) - throw(BoundsException(className, "numTargets")); - numTargets = n; + m_ignoreAccuracy = ignoreAccuracy; } -void Move::setTargetChoice(const int t) throw(BoundsException) +void Move::setCanFlinch(const bool canFlinch) { - if (C_End <= t) - throw(BoundsException(className, "targetChoice")); - targetChoice = t; + m_canFlinch = canFlinch; } -void Move::setIgnoreAccuracy(const bool i) +void Move::setCanRandom(const bool canRandom) { - ignoreAccuracy = i; + m_canRandom = canRandom; } -void Move::setCanFlinch(const bool c) +void Move::setCanSnatch(const bool canSnatch) { - canFlinch = c; + m_canSnatch = canSnatch; } -void Move::setCanRandom(const bool c) +void Move::setSound(const bool sound) { - canRandom = c; + m_sound = sound; } -void Move::setCanSnatch(const bool c) +void Move::setDescription(const QString& description) { - canSnatch = c; + m_description = description; } -void Move::setSound(const bool s) +QString Move::name() const { - sound = s; + return m_name; } -void Move::setDescription(const QString& d) +Frac Move::accuracy() const { - description = d; + return m_accuracy; } -QString Move::getName() const +int Move::type() const { - return name; + return m_type; } -Frac Move::getAccuracy() const +bool Move::special() const { - return accuracy; + return m_special; } -int Move::getType() const +int Move::powerPoints() const { - return type; + return m_powerPoints; } -bool Move::getSpecial() const +int Move::target() const { - return special; + return m_target; } -int Move::getPowerPoints() const +int Move::numTargets() const { - return powerPoints; + return m_numTargets; } -int Move::getTarget() const +int Move::targetChoice() const { - return target; + return m_targetChoice; } -int Move::getNumTargets() const +bool Move::ignoreAccuracy() const { - return numTargets; + return m_ignoreAccuracy; } -int Move::getTargetChoice() const +bool Move::canFlinch() const { - return targetChoice; + return m_canFlinch; } -bool Move::getIgnoreAccuracy() const +bool Move::canRandom() const { - return ignoreAccuracy; + return m_canRandom; } -bool Move::getCanFlinch() const +bool Move::canSnatch() const { - return canFlinch; + return m_canSnatch; } -bool Move::getCanRandom() const +bool Move::sound() const { - return canRandom; + return m_sound; } -bool Move::getCanSnatch() const +QString Move::description() const { - return canSnatch; + return m_description; } -bool Move::getSound() const +const MoveEffect* Move::effect(const int index) const throw(IndexException) { - return sound; + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects.at(index); } -QString Move::getDescription() const +MoveEffect* Move::effect(const int index) throw(IndexException) { - return description; + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects[index]; } -const MoveEffect* Move::getEffect(const int i) const throw(IndexException) +const MoveEffect* Move::effectById(const int id) const throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects.at(i); + return effect(effectIndex(id)); } -MoveEffect* Move::getEffect(const int i) throw(IndexException) +MoveEffect* Move::effectById(const int id) throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects[i]; + return effect(effectIndex(id)); } -const MoveEffect* Move::getEffectByID(const int i) const throw(IndexException) +int Move::effectIndex(const int id) const { - return getEffect(getEffectIndex(i)); + for (int i = 0; i < effectCount(); ++i) + { + if (m_effects[i]->id() == id) + return i; + } + return INT_MAX; } -MoveEffect* Move::getEffectByID(const int i) throw(IndexException) +int Move::effectCount() const { - return getEffect(getEffectIndex(i)); + return m_effects.size(); } -int Move::getEffectIndex(const int _id) const +MoveEffect* Move::newEffect() { - for (int i = 0; i < getEffectCount(); ++i) - { - if (effects[i]->getId() == _id) - return i; - } - return -1; + m_effects.append(new MoveEffect(pokemod(), newEffectId())); + return m_effects[effectCount() - 1]; } -int Move::getEffectCount() const +MoveEffect* Move::newEffect(const QString& fileName) { - return effects.size(); + m_effects.append(new MoveEffect(pokemod(), fileName, newEffectId())); + return m_effects[effectCount() - 1]; } -MoveEffect* Move::newEffect() +MoveEffect* Move::newEffect(const MoveEffect& effect) { - effects.append(new MoveEffect(pokemod, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new MoveEffect(pokemod(), effect, newEffectId())); + return m_effects[effectCount() - 1]; } -MoveEffect* Move::newEffect(const QString& fname) +void Move::deleteEffect(const int index) throw(IndexException) { - effects.append(new MoveEffect(pokemod, fname, getNewId())); - return effects[getEffectCount() - 1]; + if (effectCount() <= index) + throw(IndexException(className())); + delete m_effects[index]; + m_effects.removeAt(index); } -MoveEffect* Move::newEffect(const MoveEffect& e) +void Move::deleteEffectById(const int id) throw(IndexException) { - effects.append(new MoveEffect(pokemod, e, getNewId())); - return effects[getEffectCount() - 1]; + deleteEffect(effectIndex(id)); } -void Move::deleteEffect(const int i) throw(IndexException) +int Move::newEffectId() const { - if (getEffectCount() <= i) - throw(IndexException(className)); - delete effects[i]; - effects.removeAt(i); + int i = 0; + while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) + ++i; + return i; } Move& Move::operator=(const Move& rhs) { if (this == &rhs) return *this; - name = rhs.name; - accuracy = rhs.accuracy; - power = rhs.power; - type = rhs.type; - special = rhs.special; - powerPoints = rhs.powerPoints; - target = rhs.target; - numTargets = rhs.numTargets; - targetChoice = rhs.targetChoice; - ignoreAccuracy = rhs.ignoreAccuracy; - canFlinch = rhs.canFlinch; - canRandom = rhs.canRandom; - canSnatch = rhs.canSnatch; - sound = rhs.sound; - description = rhs.description; - effects.clear(); - for (int i = 0; i < rhs.getEffectCount(); ++i) - effects.append(new MoveEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId())); + m_name = rhs.m_name; + m_accuracy = rhs.m_accuracy; + m_power = rhs.m_power; + m_type = rhs.m_type; + m_special = rhs.m_special; + m_powerPoints = rhs.m_powerPoints; + m_target = rhs.m_target; + m_numTargets = rhs.m_numTargets; + m_targetChoice = rhs.m_targetChoice; + m_ignoreAccuracy = rhs.m_ignoreAccuracy; + m_canFlinch = rhs.m_canFlinch; + m_canRandom = rhs.m_canRandom; + m_canSnatch = rhs.m_canSnatch; + m_sound = rhs.m_sound; + m_description = rhs.m_description; + m_effects.clear(); + foreach (MoveEffect* effect, rhs.m_effects) + m_effects.append(new MoveEffect(pokemod(), *effect, effect->id())); return *this; } |
