diff options
Diffstat (limited to 'pokemod/ItemEffect.cpp')
| -rw-r--r-- | pokemod/ItemEffect.cpp | 455 |
1 files changed, 166 insertions, 289 deletions
diff --git a/pokemod/ItemEffect.cpp b/pokemod/ItemEffect.cpp index d7b98023..98ca941a 100644 --- a/pokemod/ItemEffect.cpp +++ b/pokemod/ItemEffect.cpp @@ -62,244 +62,15 @@ ItemEffect::ItemEffect(const QDomElement& xml, const Object* parent, const int i load(xml, id); } -bool ItemEffect::validate() const +void ItemEffect::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Effect with id %1---").arg(id()), Pokemod::V_Msg); -// switch (m_effect) -// { -// case E_Revive: -// case E_LevelBoost: -// case E_StatBoost: -// case E_PPBoost: -// case E_Fish: -// case E_Repel: -// case E_Escape: -// case E_TM: -// case E_HM: -// case E_Map: -// case E_Itemfinder: -// case E_Bike: -// case E_Scope: -// case E_Coin: -// case E_CoinCase: -// case E_Acorn: -// case E_Evolution: -// if (!m_overworld) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Effect only works in the overworld"); -// valid = false; -// } -// break; -// case E_Flinch: -// case E_First: -// case E_KeepAlive: -// case E_ModifyStatBattle: -// case E_ShieldBattle: -// case E_RunBattle: -// case E_TypeBoost: -// case E_ExpShare: -// case E_Ball: -// case E_Berry: -// if (m_overworld) -// { -// valid = false; -// static_cast<const Pokemod*>(pokemod())->validationMsg("Effect cannot work in the overworld"); -// } -// break; -// } -// if (m_effect < E_End) -// { -// bool ok = true; -// switch (m_effect) -// { -// case E_HPCure: -// case E_Revive: -// if ((m_value4 != R_Absolute) || !m_value1) -// ok = false; -// break; -// case E_LevelBoost: -// case E_ShieldBattle: -// case E_PPBoost: -// case E_Repel: -// if (!m_value1) -// ok = false; -// break; -// case E_StatBoost: -// case E_Acorn: -// if ((m_value1 < 0) || (65536 <= m_value1)) -// ok = false; -// break; -// case E_ModifyStatBattle: -// if ((m_value1 < -12) || (12 < m_value1)) -// ok = false; -// break; -// case E_Ball: -// switch (m_value2) -// { -// case B_Regular: -// if (256 <= m_value1) -// ok = false; -// break; -// case B_Level: -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < m_value1) -// ok = false; -// break; -// case B_Master: -// case B_Love: -// case B_Area: -// case B_Time: -// case B_Battle: -// case B_Friend: -// case B_Stat: -// case B_Type: -// case B_Weight: -// break; -// default: -// ok = false; -// break; -// } -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 1"); -// valid = false; -// ok = true; -// } -// switch (m_effect) -// { -// case E_HPCure: -// case E_Revive: -// if (R_End <= m_value2) -// ok = false; -// break; -// case E_CureStatus: -// if (Pokemod::STS_End <= m_value2) -// ok = false; -// break; -// case E_StatBoost: -// if ((m_value2 <= 0) || (65536 <= m_value2)) -// ok = false; -// break; -// case E_ModifyStatBattle: -// if (Pokemod::ST_End_Battle <= m_value2) -// ok = false; -// break; -// case E_ShieldBattle: -// if (SP_End <= m_value2) -// ok = false; -// break; -// case E_TypeBoost: -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(m_value2) == INT_MAX) -// ok = false; -// break; -// case E_PPRestore: -// if (A_End <= m_value2) -// ok = false; -// break; -// case E_Repel: -// if (RP_End <= m_value2) -// ok = false; -// break; -// case E_Escape: -// if (ES_End <= m_value2) -// ok = false; -// break; -// case E_TM: -// case E_HM: -// if (static_cast<const Pokemod*>(pokemod())->moveIndex(m_value2) == INT_MAX) -// ok = false; -// break; -// case E_Ball: -// if (B_End <= m_value2) -// ok = false; -// break; -// case E_Berry: -// if (B2_End <= m_value2) -// ok = false; -// break; -// case E_Coin: -// case E_CoinCase: -// if (m_value2 <= 0) -// ok = false; -// break; -// case E_Acorn: -// if (static_cast<const Pokemod*>(pokemod())->itemIndex(m_value2) == INT_MAX) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 2"); -// valid = false; -// ok = true; -// } -// switch (m_effect) -// { -// case E_StatBoost: -// if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= m_value3) -// ok = false; -// break; -// case E_Ball: -// switch (m_value2) -// { -// case B_Regular: -// case B_Master: -// case B_Level: -// case B_Love: -// case B_Battle: -// case B_Friend: -// case B_Weight: -// break; -// case B_Area: -// if (MapWildList::End <= m_value3) -// ok = false; -// break; -// case B_Time: -// if (static_cast<const Pokemod*>(pokemod())->timeIndex(m_value3) == INT_MAX) -// ok = false; -// break; -// case B_Stat: -// if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= m_value3) -// ok = false; -// break; -// case B_Type: -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(m_value3) == INT_MAX) -// ok = false; -// break; -// } -// break; -// case E_Berry: -// switch (m_value2) -// { -// case B2_HPCure: -// if (Pokemod::REL_End <= m_value3) -// ok = false; -// break; -// case B2_StatusCure: -// if (Pokemod::STS_End <= m_value3) -// ok = false; -// break; -// default: -// ok = false; -// break; -// } -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 3"); -// valid = false; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid effect"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setOverworld, overworld); + TEST(setEffect, effect); + TEST(setValue1, value1); + TEST(setValue2, value2); + TEST(setValue3, value3); + TEST(setValue4, value4); } void ItemEffect::load(const QDomElement& xml, int id) @@ -329,7 +100,7 @@ QDomElement ItemEffect::save() const return xml; } -void ItemEffect::setOverworld(const bool overworld) throw(Exception) +void ItemEffect::setOverworld(const bool overworld) { switch (m_effect) { @@ -351,7 +122,10 @@ void ItemEffect::setOverworld(const bool overworld) throw(Exception) case E_Acorn: case E_Evolution: if (!overworld) - throw(Exception(className(), "overworld mismatch")); + { + error("Overworld mismatch"); + return; + } break; case E_Flinch: case E_First: @@ -364,7 +138,10 @@ void ItemEffect::setOverworld(const bool overworld) throw(Exception) case E_Ball: case E_Berry: if (overworld) - throw(Exception(className(), "overworld mismatch")); + { + error("Overworld mismatch"); + return; + } break; } m_overworld = overworld; @@ -380,10 +157,13 @@ void ItemEffect::setHeld(const bool held) m_held = held; } -void ItemEffect::setEffect(const int effect) throw(Exception) +void ItemEffect::setEffect(const int effect) { if (E_End <= effect) - throw(BoundsException(className(), "effect out-of-bounds")); + { + boundsError("effect"); + return; + } switch (effect) { case E_Revive: @@ -425,30 +205,42 @@ void ItemEffect::setEffect(const int effect) throw(Exception) m_value4.set(1, 1); } -void ItemEffect::setValue1(const int value1) throw(Exception) +void ItemEffect::setValue1(const int value1) { switch (m_effect) { case E_HPCure: case E_Revive: if ((m_value4 != R_Absolute) || !value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_LevelBoost: case E_ShieldBattle: case E_PPBoost: case E_Repel: if (!value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_StatBoost: case E_Acorn: if ((value1 < 0) || (65536 <= value1)) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_ModifyStatBattle: if ((value1 < -12) || (12 < value1)) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Fish: case E_Coin: @@ -459,11 +251,17 @@ void ItemEffect::setValue1(const int value1) throw(Exception) { case B_Regular: if (256 <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case B_Level: if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case B_Master: case B_Love: @@ -476,95 +274,141 @@ void ItemEffect::setValue1(const int value1) throw(Exception) case B_Weight: break; default: - error<BoundsException>("value1"); + boundsError("value1"); + return; } break; default: - error<UnusedException>("value1"); - break; + unusedError("value1"); + return; } m_value1 = value1; } -void ItemEffect::setValue2(const int value2) throw(Exception) +void ItemEffect::setValue2(const int value2) { switch (m_effect) { case E_HPCure: case E_Revive: if (R_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_CureStatus: if (Pokemod::STS_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_StatBoost: if ((value2 <= 0) || (65536 <= value2)) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_ModifyStatBattle: if (Pokemod::ST_End_Battle <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_ShieldBattle: if (SP_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_TypeBoost: if (static_cast<const Pokemod*>(pokemod())->typeIndex(value2) == INT_MAX) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_PPRestore: if (A_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Repel: if (RP_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Escape: if (ES_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_TM: case E_HM: if (static_cast<const Pokemod*>(pokemod())->moveIndex(value2) == INT_MAX) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Ball: if (B_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Scope: break; case E_Berry: if (B2_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Coin: case E_CoinCase: if (value2 <= 0) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Acorn: if (static_cast<const Pokemod*>(pokemod())->itemIndex(value2) == INT_MAX) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; default: - error<UnusedException>("value2"); - break; + unusedError("value2"); + return; } m_value2 = value2; } -void ItemEffect::setValue3(const int value3) throw(Exception) +void ItemEffect::setValue3(const int value3) { switch (m_effect) { case E_StatBoost: if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case E_Ball: switch (m_value2) @@ -575,26 +419,38 @@ void ItemEffect::setValue3(const int value3) throw(Exception) break; case B_Area: if (MapWildList::End <= value3) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case B_Time: if (static_cast<const Pokemod*>(pokemod())->timeIndex(value3) == INT_MAX) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case B_Stat: if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case B_Type: if (static_cast<const Pokemod*>(pokemod())->typeIndex(value3) == INT_MAX) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case B_Regular: case B_Master: case B_Love: case B_Battle: - error<UnusedException>("value3"); - break; + unusedError("value3"); + return; } break; case E_Berry: @@ -602,33 +458,45 @@ void ItemEffect::setValue3(const int value3) throw(Exception) { case B2_HPCure: if (Pokemod::REL_End <= value3) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case B2_StatusCure: if (Pokemod::STS_End <= value3) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; default: - error<UnusedException>("value3"); - break; + unusedError("value3"); + return; } break; default: - error<UnusedException>("value3"); - break; + unusedError("value3"); + return; } m_value3 = value3; } -void ItemEffect::setValue4(const Fraction& value4) throw(Exception) +void ItemEffect::setValue4(const Fraction& value4) { if ((E_TypeBoost == m_effect) || (E_PPBoost == m_effect)) { if (value4 < 1) - error<BoundsException>("value4"); + { + boundsError("value4"); + return; + } } else if (1 < value4) - error<BoundsException>("value4"); + { + boundsError("value4"); + return; + } switch (m_effect) { case E_CureStatus: @@ -647,14 +515,23 @@ void ItemEffect::setValue4(const Fraction& value4) throw(Exception) case E_CoinCase: case E_Acorn: case E_Evolution: - error<UnusedException>("value4"); + { + unusedError("value4"); + return; + } case E_Ball: if (m_value2 == B_Master) - error<UnusedException>("value4"); + { + unusedError("value4"); + return; + } break; case E_Berry: if (m_value2 != B2_HPCure) - error<UnusedException>("value4"); + { + unusedError("value4"); + return; + } break; } m_value4 = value4; |
