diff options
Diffstat (limited to 'pokemod/Move.cpp')
| -rw-r--r-- | pokemod/Move.cpp | 137 |
1 files changed, 63 insertions, 74 deletions
diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index 1c676eac..2e98ad65 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -22,6 +22,9 @@ #include "MoveEffect.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + const QStringList Move::TargetStr = QStringList() << "Player" << "Enemy" << "All" << "Random"; const QStringList Move::ChoiceStr = QStringList() << "Player" << "Enemy" << "Random"; @@ -68,59 +71,27 @@ Move::~Move() clear(); } -bool Move::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Move \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = ""; -// } -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(m_type) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid type"); -// valid = false; -// } -// if (!m_powerPoints) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid number of power points"); -// valid = false; -// } -// if (T_End <= m_target) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid target"); -// valid = false; -// } -// if (!m_target || (static_cast<const Pokemod*>(pokemod())->rules()->maxFight() * ((m_target == T_All) ? static_cast<const Pokemod*>(pokemod())->rules()->maxPlayers() : 1)) < m_numTargets) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid number of targets"); -// valid = false; -// } -// if (C_End <= m_targetChoice) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid target choice"); -// valid = false; -// } -// if (effectCount()) -// { -// QMap<int, bool> idChecker; -// foreach (MoveEffect* effect, m_effects) -// { -// if (!effect->isValid()) -// valid = false; -// if (idChecker[effect->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); -// idChecker[effect->id()] = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no effects"); -// valid = false; -// } -// return valid; +void Move::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setType, type); + TEST(setPowerPoints, powerPoints); + TEST(setTarget, target); + TEST(setNumTargets, numTargets); + TEST(setTargetChoice, targetChoice); + if (!effectCount()) + warning(stream, "There are no effects"); + QSet<int> idChecker; + foreach (MoveEffect* effect, m_effects) + { + if (!effect->isValid(stream)) + setValid(false); + if (idChecker.contains(effect->id())) + subclassError(stream, "effect", effect->id()); + idChecker.insert(effect->id()); + } } void Move::load(const QDomElement& xml, int id) @@ -170,10 +141,13 @@ void Move::setName(const QString& name) m_name = name; } -void Move::setAccuracy(const Fraction& accuracy) throw(BoundsException) +void Move::setAccuracy(const Fraction& accuracy) { if (1 < accuracy) - error<BoundsException>("accuracy"); + { + boundsError("accuracy"); + return; + } m_accuracy = accuracy; } @@ -182,10 +156,13 @@ void Move::setPower(const int power) m_power = power; } -void Move::setType(const int type) throw(BoundsException) +void Move::setType(const int type) { if (static_cast<const Pokemod*>(pokemod())->typeIndex(type) == INT_MAX) - error<BoundsException>("type"); + { + boundsError("type"); + return; + } m_type = type; } @@ -194,31 +171,43 @@ void Move::setSpecial(const bool special) m_special = special; } -void Move::setPowerPoints(const int powerPoints) throw(BoundsException) +void Move::setPowerPoints(const int powerPoints) { if (!powerPoints) - error<BoundsException>("powerPoints"); + { + boundsError("powerPoints"); + return; + } m_powerPoints = powerPoints; } -void Move::setTarget(const int target) throw(BoundsException) +void Move::setTarget(const int target) { if (T_End <= target) - error<BoundsException>("target"); + { + boundsError("target"); + return; + } m_target = target; } -void Move::setNumTargets(const int numTargets) throw(BoundsException) +void Move::setNumTargets(const int numTargets) { if (!numTargets || ((static_cast<const Pokemod*>(pokemod())->rules()->maxFight() * ((m_target == T_All) ? static_cast<const Pokemod*>(pokemod())->rules()->maxPlayers() : 1)) < numTargets)) - error<BoundsException>("numTargets"); + { + boundsError("numTargets"); + return; + } m_numTargets = numTargets; } -void Move::setTargetChoice(const int targetChoice) throw(BoundsException) +void Move::setTargetChoice(const int targetChoice) { if (C_End <= targetChoice) - error<BoundsException>("targetChoice"); + { + boundsError("targetChoice"); + return; + } m_targetChoice = targetChoice; } @@ -327,26 +316,26 @@ QString Move::description() const return m_description; } -const MoveEffect* Move::effect(const int index) const throw(IndexException) +const MoveEffect* Move::effect(const int index) const { if (effectCount() <= index) - warning<IndexException>("effect"); + return NULL; return m_effects.at(index); } -MoveEffect* Move::effect(const int index) throw(IndexException) +MoveEffect* Move::effect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return NULL; return m_effects[index]; } -const MoveEffect* Move::effectById(const int id) const throw(IndexException) +const MoveEffect* Move::effectById(const int id) const { return effect(effectIndex(id)); } -MoveEffect* Move::effectById(const int id) throw(IndexException) +MoveEffect* Move::effectById(const int id) { return effect(effectIndex(id)); } @@ -387,15 +376,15 @@ MoveEffect* Move::newEffect(MoveEffect* effect) return effect; } -void Move::deleteEffect(const int index) throw(IndexException) +void Move::deleteEffect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return; delete m_effects[index]; m_effects.removeAt(index); } -void Move::deleteEffectById(const int id) throw(IndexException) +void Move::deleteEffectById(const int id) { deleteEffect(effectIndex(id)); } |
