diff options
Diffstat (limited to 'pokemod/Move.cpp')
-rw-r--r-- | pokemod/Move.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index f79f5c3c..6f8ad323 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -27,6 +27,7 @@ #include <QStringListIterator> #include "Pokemod.h" +#include "MoveEffect.h" #include "Move.h" const QStringList Move::TargetStr = QStringList() << "Player" << "Enemy" << "Both" << "Random"; @@ -63,6 +64,12 @@ Move::Move(const Pokemod* par, const QString& fname, const int _id) : load(fname, _id); } +Move::~Move() +{ + for (QListIterator<MoveEffect*> i(effects); i.hasNext(); ) + delete i.next(); +} + bool Move::validate() const { bool valid = true; @@ -100,11 +107,11 @@ bool Move::validate() const if (getEffectCount()) { QMap<int, int> idChecker; - for (QListIterator<MoveEffect> i(effects); i.hasNext(); i.next()) + for (QListIterator<MoveEffect*> i(effects); i.hasNext(); i.next()) { - if (!i.peekNext().isValid()) + if (!i.peekNext()->isValid()) valid = false; - ++idChecker[i.peekNext().getId()]; + ++idChecker[i.peekNext()->getId()]; } for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) { @@ -189,8 +196,8 @@ void Move::save() const throw(Exception) 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); + for (QListIterator<MoveEffect*> i(effects); i.hasNext(); ) + i.next()->save(name); } void Move::setName(const QString& n) @@ -357,14 +364,14 @@ const MoveEffect* Move::getEffect(const int i) const throw(IndexException) { if (getEffectCount() <= i) throw(IndexException(className)); - return &effects.at(i); + return effects.at(i); } MoveEffect* Move::getEffect(const int i) throw(IndexException) { if (getEffectCount() <= i) throw(IndexException(className)); - return &effects[i]; + return effects[i]; } const MoveEffect* Move::getEffectByID(const int i) const throw(IndexException) @@ -381,7 +388,7 @@ int Move::getEffectIndex(const int _id) const { for (int i = 0; i < getEffectCount(); ++i) { - if (effects[i].getId() == _id) + if (effects[i]->getId() == _id) return i; } return -1; @@ -394,26 +401,27 @@ int Move::getEffectCount() const MoveEffect* Move::newEffect() { - effects.append(MoveEffect(pokemod, getNewId())); - return &effects[getEffectCount() - 1]; + effects.append(new MoveEffect(pokemod, getNewId())); + return effects[getEffectCount() - 1]; } MoveEffect* Move::newEffect(const QString& fname) { - effects.append(MoveEffect(pokemod, fname, getNewId())); - return &effects[getEffectCount() - 1]; + effects.append(new MoveEffect(pokemod, fname, getNewId())); + return effects[getEffectCount() - 1]; } MoveEffect* Move::newEffect(const MoveEffect& e) { - effects.append(MoveEffect(pokemod, e, getNewId())); - return &effects[getEffectCount() - 1]; + effects.append(new MoveEffect(pokemod, e, getNewId())); + return effects[getEffectCount() - 1]; } void Move::deleteEffect(const int i) throw(IndexException) { if (getEffectCount() <= i) throw(IndexException(className)); + delete effects[i]; effects.removeAt(i); } @@ -438,6 +446,6 @@ Move& Move::operator=(const Move& rhs) description = rhs.description; effects.clear(); for (int i = 0; i < rhs.getEffectCount(); ++i) - newEffect(*rhs.getEffect(i)); + effects.append(new MoveEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId())); return *this; } |