diff options
Diffstat (limited to 'pokemod/AbilityEffect.cpp')
| -rw-r--r-- | pokemod/AbilityEffect.cpp | 290 |
1 files changed, 114 insertions, 176 deletions
diff --git a/pokemod/AbilityEffect.cpp b/pokemod/AbilityEffect.cpp index dba7a5e2..427fdb44 100644 --- a/pokemod/AbilityEffect.cpp +++ b/pokemod/AbilityEffect.cpp @@ -64,145 +64,17 @@ AbilityEffect::AbilityEffect(const QDomElement& xml, const Object* parent, const load(xml, id); } -bool AbilityEffect::validate() const +void AbilityEffect::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Effect with id %1---").arg(id()), Pokemod::V_Msg); -// if (m_effect < E_End) -// { -// bool ok = true; -// switch (m_effect) -// { -// case E_Stats: -// if ((Pokemod::ST_HP == m_value1) || (Pokemod::ST_End_Battle <= m_value1) || ((Pokemod::ST_SpecialDefense == m_value1) && !static_cast<const Pokemod*>(pokemod())->rules()->specialSplit())) -// ok = false; -// break; -// case E_Status: -// if (Pokemod::STS_End <= m_value1) -// ok = false; -// break; -// case E_Ability: -// if (static_cast<const Pokemod*>(pokemod())->abilityIndex(m_value1) == INT_MAX) -// ok = false; -// break; -// case E_AccuracyPowerTrade: -// if (PA_End <= m_value1) -// ok = false; -// break; -// case E_ItemEffect: -// if (IT_End <= m_value1) -// ok = false; -// break; -// case E_Type: -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(m_value1) == INT_MAX) -// ok = false; -// break; -// case E_Weather: -// if (Pokemod::W_End_All <= m_value1) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 1"); -// valid = false; -// ok = true; -// } -// switch (m_effect) -// { -// case E_Stats: -// if (Pokemod::BM_End <= m_value2) -// ok = false; -// break; -// case E_Status: -// case E_Weather: -// if (C_End <= m_value2) -// ok = false; -// break; -// case E_Ability: -// if (I_End <= m_value2) -// ok = false; -// break; -// case E_Type: -// if (B_End <= m_value2) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 2"); -// valid = false; -// ok = true; -// } -// switch (m_effect) -// { -// case E_DamageToHP: -// case E_PreventDamage: -// case E_AutoHeal: -// case E_DealDamage: -// case E_Wilds: -// case E_AccuracyPowerTrade: -// case E_Type: -// case E_FastHatch: -// if ((m_value3 < 0) || (100 < m_value3)) -// ok = false; -// break; -// case E_Stats: -// if ((m_value3 < -12) || (12 < m_value3)) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 3"); -// valid = false; -// ok = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid effect"); -// valid = false; -// } -// if (m_trigger < T_End) -// { -// bool ok = true; -// switch (m_trigger) -// { -// case T_Weather: -// if (Pokemod::W_End_All <= m_triggerValue1) -// ok = false; -// break; -// case T_Type: -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(m_triggerValue1) == INT_MAX) -// ok = false; -// break; -// case T_HPBoundary: -// if (S_End <= m_triggerValue1) -// ok = false; -// break; -// case T_StatChange: -// if ((Pokemod::ST_HP == m_triggerValue1) || (Pokemod::ST_End_Battle <= m_triggerValue1) || ((Pokemod::ST_SpecialDefense == m_triggerValue1) && !static_cast<const Pokemod*>(pokemod())->rules()->specialSplit())) -// ok = false; -// break; -// case T_Status: -// if (Pokemod::STS_End <= m_triggerValue1) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid trigger value 1"); -// valid = false; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid trigger"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setChance, chance); + TEST(setEffect, effect); + TEST(setValue1, value1); + TEST(setValue2, value2); + TEST(setValue3, value3); + TEST(setTrigger, trigger); + TEST(setTriggerValue1, triggerValue1); + TEST(setTriggerValue2, triggerValue2); } void AbilityEffect::load(const QDomElement& xml, int id) @@ -232,91 +104,130 @@ QDomElement AbilityEffect::save() const return xml; } -void AbilityEffect::setChance(const Fraction& chance) throw(BoundsException) +void AbilityEffect::setChance(const Fraction& chance) { if (1 < chance) - error<BoundsException>("chance"); + { + boundsError("chance"); + return; + } m_chance = chance; } -void AbilityEffect::setEffect(const int effect) throw(BoundsException) +void AbilityEffect::setEffect(const int effect) { if (E_End <= effect) - error<BoundsException>("effect"); + { + boundsError("effect"); + return; + } m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; m_value3 = 0; } -void AbilityEffect::setValue1(const int value1) throw(Exception) +void AbilityEffect::setValue1(const int value1) { switch (m_effect) { case E_Stats: if ((Pokemod::ST_HP == value1) || (Pokemod::ST_End_Battle <= value1) || ((Pokemod::ST_SpecialDefense == value1) && !static_cast<const Pokemod*>(pokemod())->rules()->specialSplit())) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Status: if (Pokemod::STS_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Ability: if (static_cast<const Pokemod*>(pokemod())->abilityIndex(value1) == INT_MAX) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_AccuracyPowerTrade: if (PA_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_ItemEffect: if (IT_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Type: if (static_cast<const Pokemod*>(pokemod())->typeIndex(value1) == INT_MAX) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Weather: if (Pokemod::W_End_All <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; default: - error<UnusedException>("value1"); - break; + unusedError("value1"); + return; } m_value1 = value1; } -void AbilityEffect::setValue2(const int value2) throw(Exception) +void AbilityEffect::setValue2(const int value2) { switch (m_effect) { case E_Stats: if (Pokemod::BM_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Status: case E_Weather: if (C_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Ability: if (I_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Type: if (B_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; default: - error<UnusedException>("value2"); - break; + unusedError("value2"); + return; } m_value2 = value2; } -void AbilityEffect::setValue3(const int value3) throw(Exception) +void AbilityEffect::setValue3(const int value3) { switch (m_effect) { @@ -329,63 +240,90 @@ void AbilityEffect::setValue3(const int value3) throw(Exception) case E_Type: case E_FastHatch: if ((value3 < 0) || (100 < value3)) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case E_Stats: if ((value3 < -12) || (12 < value3)) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; default: - error<UnusedException>("value3"); - break; + unusedError("value3"); + return; } m_value3 = value3; } -void AbilityEffect::setTrigger(const int trigger) throw(BoundsException) +void AbilityEffect::setTrigger(const int trigger) { if (T_End <= trigger) - error<BoundsException>("trigger"); + { + boundsError("trigger"); + return; + } m_trigger = trigger; m_triggerValue1 = INT_MAX; m_triggerValue2.set(1, 1); } -void AbilityEffect::setTriggerValue1(const int triggerValue1) throw(Exception) +void AbilityEffect::setTriggerValue1(const int triggerValue1) { switch (m_trigger) { case T_Weather: if (Pokemod::W_End_All <= triggerValue1) - error<BoundsException>("triggerValue1"); + { + boundsError("triggerValue1"); + return; + } break; case T_Type: if (static_cast<const Pokemod*>(pokemod())->typeIndex(triggerValue1) == INT_MAX) - error<BoundsException>("triggerValue1"); + { + boundsError("triggerValue1"); + return; + } break; case T_HPBoundary: if (S_End <= triggerValue1) - error<BoundsException>("triggerValue1"); + { + boundsError("triggerValue1"); + return; + } break; case T_StatChange: if ((Pokemod::ST_HP == triggerValue1) || (Pokemod::ST_End_Battle <= triggerValue1) || ((Pokemod::ST_SpecialDefense == triggerValue1) && !static_cast<const Pokemod*>(pokemod())->rules()->specialSplit())) - error<BoundsException>("triggerValue1"); + { + boundsError("triggerValue1"); + return; + } break; case T_Status: if (Pokemod::STS_End <= triggerValue1) - error<BoundsException>("triggerValue1"); + { + boundsError("triggerValue1"); + return; + } break; default: - error<UnusedException>("triggerValue1"); - break; + unusedError("triggerValue1"); + return; } m_triggerValue1 = triggerValue1; } -void AbilityEffect::setTriggerValue2(const Fraction& triggerValue2) throw(UnusedException) +void AbilityEffect::setTriggerValue2(const Fraction& triggerValue2) { if (m_trigger != T_HPBoundary) - error<UnusedException>("triggerValue2"); + { + unusedError("triggerValue2"); + return; + } m_triggerValue2 = triggerValue2; } |
