From 807071d35159de0660f9df31c48d5bf895ca3622 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 27 Apr 2008 15:15:17 +0000 Subject: [FIX] Pokemod objects now know about parents [FIX] Project includes are now relative [FIX] Headers included for better detection of invalid headers [FIX] Validation code commented out so it can be done better git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@111 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/Move.cpp | 135 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 68 insertions(+), 67 deletions(-) (limited to 'pokemod/Move.cpp') diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index d1d17641..10c8affe 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -15,27 +15,27 @@ * with this program. If not, see . */ -// Qt includes -#include +// Header include +#include "Move.h" // Pokemod includes -#include "Pokemod.h" #include "MoveEffect.h" +#include "Pokemod.h" -// Header include -#include "Move.h" +// Qt includes +#include const QStringList Move::TargetStr = QStringList() << "Player" << "Enemy" << "All" << "Random"; const QStringList Move::ChoiceStr = QStringList() << "Player" << "Enemy" << "Random"; Move::Move(const Move& move) : - Object("Move", move.pokemod(), move.id()) + Object("Move", move.parent(), move.id()) { *this = move; } -Move::Move(const Pokemod* pokemod, const int id) : - Object("Move", pokemod, id), +Move::Move(const Object* parent, const int id) : + Object("Move", parent, id), m_name(""), m_accuracy(1, 1), m_power(0), @@ -54,14 +54,14 @@ Move::Move(const Pokemod* pokemod, const int id) : { } -Move::Move(const Move& move, const Pokemod* pokemod, const int id) : - Object("Move", pokemod, id) +Move::Move(const Move& move, const Object* parent, const int id) : + Object("Move", parent, id) { *this = move; } -Move::Move(const QDomElement& xml, const Pokemod* pokemod, const int id) : - Object("Move", pokemod, id) +Move::Move(const QDomElement& xml, const Object* parent, const int id) : + Object("Move", parent, id) { load(xml, id); } @@ -73,56 +73,57 @@ Move::~Move() bool Move::validate() const { - bool valid = true; - 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"); - valid = ""; - } - if (pokemod()->typeIndex(m_type) == INT_MAX) - { - pokemod()->validationMsg("Invalid type"); - valid = false; - } - if (!m_powerPoints) - { - pokemod()->validationMsg("Invalid number of power points"); - valid = false; - } - if (T_End <= m_target) - { - pokemod()->validationMsg("Invalid target"); - valid = false; - } - if (!m_target || (pokemod()->rules()->maxFight() * ((m_target == T_All) ? pokemod()->rules()->maxPlayers() : 1)) < m_numTargets) - { - pokemod()->validationMsg("Invalid number of targets"); - valid = false; - } - if (C_End <= m_targetChoice) - { - pokemod()->validationMsg("Invalid target choice"); - valid = false; - } - if (effectCount()) - { - QMap idChecker; - foreach (MoveEffect* effect, m_effects) - { - 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"); - valid = false; - } - return valid; + // TODO: validate +// bool valid = true; +// static_cast(pokemod())->validationMsg(QString("---Move \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); +// if (m_name == "") +// { +// static_cast(pokemod())->validationMsg("Name is not defined"); +// valid = ""; +// } +// if (static_cast(pokemod())->typeIndex(m_type) == INT_MAX) +// { +// static_cast(pokemod())->validationMsg("Invalid type"); +// valid = false; +// } +// if (!m_powerPoints) +// { +// static_cast(pokemod())->validationMsg("Invalid number of power points"); +// valid = false; +// } +// if (T_End <= m_target) +// { +// static_cast(pokemod())->validationMsg("Invalid target"); +// valid = false; +// } +// if (!m_target || (static_cast(pokemod())->rules()->maxFight() * ((m_target == T_All) ? static_cast(pokemod())->rules()->maxPlayers() : 1)) < m_numTargets) +// { +// static_cast(pokemod())->validationMsg("Invalid number of targets"); +// valid = false; +// } +// if (C_End <= m_targetChoice) +// { +// static_cast(pokemod())->validationMsg("Invalid target choice"); +// valid = false; +// } +// if (effectCount()) +// { +// QMap idChecker; +// foreach (MoveEffect* effect, m_effects) +// { +// if (!effect->isValid()) +// valid = false; +// if (idChecker[effect->id()]) +// static_cast(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); +// idChecker[effect->id()] = true; +// } +// } +// else +// { +// static_cast(pokemod())->validationMsg("There are no effects"); +// valid = false; +// } +// return valid; } void Move::load(const QDomElement& xml, int id) @@ -186,7 +187,7 @@ void Move::setPower(const int power) void Move::setType(const int type) throw(BoundsException) { - if (pokemod()->typeIndex(type) == INT_MAX) + if (static_cast(pokemod())->typeIndex(type) == INT_MAX) error("type"); m_type = type; } @@ -212,7 +213,7 @@ void Move::setTarget(const int target) throw(BoundsException) void Move::setNumTargets(const int numTargets) throw(BoundsException) { - if (!numTargets || ((pokemod()->rules()->maxFight() * ((m_target == T_All) ? pokemod()->rules()->maxPlayers() : 1)) < numTargets)) + if (!numTargets || ((static_cast(pokemod())->rules()->maxFight() * ((m_target == T_All) ? static_cast(pokemod())->rules()->maxPlayers() : 1)) < numTargets)) error("numTargets"); m_numTargets = numTargets; } @@ -370,19 +371,19 @@ int Move::effectCount() const MoveEffect* Move::newEffect() { - m_effects.append(new MoveEffect(pokemod(), newEffectId())); + m_effects.append(new MoveEffect(this, newEffectId())); return m_effects[effectCount() - 1]; } MoveEffect* Move::newEffect(const QDomElement& xml) { - m_effects.append(new MoveEffect(xml, pokemod(), newEffectId())); + m_effects.append(new MoveEffect(xml, this, newEffectId())); return m_effects[effectCount() - 1]; } MoveEffect* Move::newEffect(const MoveEffect& effect) { - m_effects.append(new MoveEffect(effect, pokemod(), newEffectId())); + m_effects.append(new MoveEffect(effect, this, newEffectId())); return m_effects[effectCount() - 1]; } -- cgit