/* * Copyright 2007-2008 Ben Boeckel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ // Header include #include "AbilityEffect.h" // Pokemod includes #include "Ability.h" #include "Type.h" #include "Pokemod.h" #include "Rules.h" const QStringList AbilityEffect::EffectStr = QStringList() << "Damage to HP" << "Prevent Damage" << "Auto Heal" << "Deal Damage" << "Wilds" << "Stat" << "Status" << "Ability" << "Accuracy/Power Trade" << "Bullseye" << "Item Effect" << "Type" << "Fast Hatch" << "Weather"; const QStringList AbilityEffect::TriggerStr = QStringList() << "Anything" << "Contact" << "Weather" << "Damage" << "Type" << "HP Boundary" << "Stat Change" << "Status"; const QStringList AbilityEffect::InteractStr = QStringList() << "Trade" << "Shadow" << "Block"; const QStringList AbilityEffect::PowerAccuracyStr = QStringList() << "Boost Power" << "Boost Accuracy"; const QStringList AbilityEffect::ItemStr = QStringList() << "Stat Modifier" << "Type Booster" << "Flinch" << "Go First"; const QStringList AbilityEffect::CauseStr = QStringList() << "Prevent" << "Inflict"; const QStringList AbilityEffect::BoostStr = QStringList() << "Boost" << "Hinder"; const QStringList AbilityEffect::SideStr = QStringList() << "Above" << "Below"; AbilityEffect::AbilityEffect(const AbilityEffect& effect) : Object("AbilityEffect", effect.parent(), effect.id()) { *this = effect; } AbilityEffect::AbilityEffect(const Ability* parent, const int id) : Object("AbilityEffect", parent, id), m_chance(1, 1), m_effect(INT_MAX), m_value1(INT_MAX), m_value2(INT_MAX), m_value3(INT_MAX), m_trigger(INT_MAX), m_triggerValue1(INT_MAX), m_triggerValue2(1, 1) { } AbilityEffect::AbilityEffect(const AbilityEffect& effect, const Ability* parent, const int id) : Object("AbilityEffect", parent, id) { *this = effect; } AbilityEffect::AbilityEffect(const QDomElement& xml, const Ability* parent, const int id) : Object("AbilityEffect", parent, id) { load(xml, id); } void AbilityEffect::validate() { 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) { LOAD_ID(); LOAD(Fraction, chance); LOAD(int, effect); LOAD(int, value1); LOAD(int, value2); LOAD(int, value3); LOAD(int, trigger); LOAD(int, triggerValue1); LOAD(Fraction, triggerValue2); } QDomElement AbilityEffect::save() const { SAVE_CREATE(); SAVE(Fraction, chance); SAVE(int, effect); SAVE(int, value1); SAVE(int, value2); SAVE(int, value3); SAVE(int, trigger); SAVE(int, triggerValue1); SAVE(Fraction, triggerValue2); return xml; } void AbilityEffect::setChance(const Fraction& chance) { if (1 < chance) { emit(error(bounds("chance"))); return; } m_chance = chance; emit(changed()); } void AbilityEffect::setEffect(const int effect) { if (E_End <= effect) { emit(error(bounds("effect"))); return; } m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; m_value3 = 0; emit(changed()); } void AbilityEffect::setValue1(const int value1) { switch (m_effect) { case E_Stats: if ((value1 < Pokemod::ST_No_HP_Start) || (Pokemod::ST_End_Battle <= value1) || ((Pokemod::ST_SpecialDefense == value1) && !static_cast(pokemod())->rules()->specialSplit())) { emit(error(bounds("value1"))); return; } break; case E_Status: if (Pokemod::STS_End <= value1) { emit(error(bounds("value1"))); return; } break; case E_Ability: if (static_cast(pokemod())->abilityIndex(value1) == INT_MAX) { emit(error(bounds("value1"))); return; } break; case E_AccuracyPowerTrade: if (PA_End <= value1) { emit(error(bounds("value1"))); return; } break; case E_ItemEffect: if (IT_End <= value1) { emit(error(bounds("value1"))); return; } break; case E_Type: if (static_cast(pokemod())->typeIndex(value1) == INT_MAX) { emit(error(bounds("value1"))); return; } break; case E_Weather: if (Pokemod::W_End_All <= value1) { emit(error(bounds("value1"))); return; } break; default: emit(warning(unused("value1"))); return; } m_value1 = value1; emit(changed()); } void AbilityEffect::setValue2(const int value2) { switch (m_effect) { case E_Stats: if (Pokemod::BM_End <= value2) { emit(error(bounds("value2"))); return; } break; case E_Status: case E_Weather: if (C_End <= value2) { emit(error(bounds("value2"))); return; } break; case E_Ability: if (I_End <= value2) { emit(error(bounds("value2"))); return; } break; case E_Type: if (B_End <= value2) { emit(error(bounds("value2"))); return; } break; default: emit(warning(unused("value2"))); return; } m_value2 = value2; emit(changed()); } void AbilityEffect::setValue3(const int value3) { 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 ((value3 < 0) || (100 < value3)) { emit(error(bounds("value3"))); return; } break; case E_Stats: if ((value3 < -12) || (12 < value3)) { emit(error(bounds("value3"))); return; } break; default: emit(warning(unused("value3"))); return; } m_value3 = value3; emit(changed()); } void AbilityEffect::setTrigger(const int trigger) { if (T_End <= trigger) { emit(error(bounds("trigger"))); return; } m_trigger = trigger; m_triggerValue1 = INT_MAX; m_triggerValue2.set(1, 1); emit(changed()); } void AbilityEffect::setTriggerValue1(const int triggerValue1) { switch (m_trigger) { case T_Weather: if (Pokemod::W_End_All <= triggerValue1) { emit(error(bounds("triggerValue1"))); return; } break; case T_Type: if (static_cast(pokemod())->typeIndex(triggerValue1) == INT_MAX) { emit(error(bounds("triggerValue1"))); return; } break; case T_HPBoundary: if (S_End <= triggerValue1) { emit(error(bounds("triggerValue1"))); return; } break; case T_StatChange: if ((triggerValue1 < Pokemod::ST_No_HP_Start) || (Pokemod::ST_End_Battle <= triggerValue1) || ((Pokemod::ST_SpecialDefense == triggerValue1) && !static_cast(pokemod())->rules()->specialSplit())) { emit(error(bounds("triggerValue1"))); return; } break; case T_Status: if (Pokemod::STS_End <= triggerValue1) { emit(error(bounds("triggerValue1"))); return; } break; default: emit(warning(unused("triggerValue1"))); return; } m_triggerValue1 = triggerValue1; emit(changed()); } void AbilityEffect::setTriggerValue2(const Fraction& triggerValue2) { if (m_trigger != T_HPBoundary) { emit(warning(unused("triggerValue2"))); return; } m_triggerValue2 = triggerValue2; emit(changed()); } Fraction AbilityEffect::chance() const { return m_chance; } int AbilityEffect::effect() const { return m_effect; } int AbilityEffect::value1() const { return m_value1; } int AbilityEffect::value2() const { return m_value2; } int AbilityEffect::value3() const { return m_value3; } int AbilityEffect::trigger() const { return m_trigger; } int AbilityEffect::triggerValue1() const { return m_triggerValue1; } Fraction AbilityEffect::triggerValue2() const { return m_triggerValue2; } AbilityEffect& AbilityEffect::operator=(const AbilityEffect& rhs) { if (this == &rhs) return *this; COPY(chance); COPY(effect); COPY(value1); COPY(value2); COPY(value3); COPY(trigger); COPY(triggerValue1); COPY(triggerValue2); return *this; }