/* * 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 "MoveEffect.h" // Pokemod includes #include "Move.h" #include "Pokemod.h" const QStringList MoveEffect::EffectStr = QStringList() << "Damage" << "Status" << "Confuse" << "Stat" << "StealHP" << "Counter" << "Selfdestruct" << "Need Status" << "Mirror" << "GetMoney" << "Never Miss" << "Steal Types" << "Clear Effects" << "Wait And Return" << "Self Confuse" << "Force Switch" << "Hit Multiple" << "Hit Multiple Turns" << "Flinch" << "One Hit K.O." << "Recoil" << "Recover" << "Rest" << "Sheild" << "Substitute" << "Recharge" << "Rage" << "Mimic" << "Random Move" << "Seed" << "Disable" << "Cut HM" << "Fly HM" << "Surf HM" << "Strength HM" << "Flash HM" << "Rock Smash HM" << "Rock Climb HM" << "Whirlpool HM" << "Waterfall HM" << "Share HP HM " << "Escape HM"; MoveEffect::MoveEffect(const MoveEffect& effect) : Object("MoveEffect", effect.parent(), effect.id()) { *this = effect; } MoveEffect::MoveEffect(const Move* parent, const int id) : Object("MoveEffect", parent, id), m_chance(1, 1), m_effect(INT_MAX), m_value1(INT_MAX), m_value2(INT_MAX), m_value3(0), m_value4(1, 1) { } MoveEffect::MoveEffect(const MoveEffect& effect, const Move* parent, const int id) : Object("MoveEffect", parent, id) { *this = effect; } MoveEffect::MoveEffect(const QDomElement& xml, const Move* parent, const int id) : Object("MoveEffect", parent, id) { load(xml, id); } void MoveEffect::validate() { TEST(setChance, chance); TEST(setEffect, effect); TEST(setValue1, value1); TEST(setValue2, value2); TEST(setValue3, value3); TEST(setValue4, value4); } void MoveEffect::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(Fraction, chance); LOAD(int, effect); LOAD(int, value1); LOAD(int, value2); LOAD(int, value3); LOAD(Fraction, value4); } QDomElement MoveEffect::save() const { SAVE_CREATE(); SAVE(Fraction, chance); SAVE(int, effect); SAVE(int, value1); SAVE(int, value2); SAVE(int, value3); SAVE(Fraction, value4); return xml; } void MoveEffect::setChance(const Fraction& chance) { if (1 < chance) { emit(error(bounds("chance"))); return; } m_chance = chance; emit(changed()); } void MoveEffect::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; m_value4.set(1, 1); emit(changed()); } void MoveEffect::setValue1(const int value1) { switch (m_effect) { case E_Damage: if (D_End <= value1) { emit(error(bounds("value1"))); return; } break; case E_Status: case E_NeedStatus: if (Pokemod::STS_End <= value1) { emit(error(bounds("value1"))); return; } throw; case E_Stat: if (Pokemod::ST_End_Battle <= value1) { emit(error(bounds("value1"))); return; } break; case E_Counter: case E_Shield: if (MT_End <= value1) { emit(error(bounds("value1"))); return; } break; case E_Recoil: if (R_End <= value1) { emit(error(bounds("value1"))); return; } break; default: emit(warning(unused("value1"))); return; } m_value1 = value1; emit(changed()); } void MoveEffect::setValue2(const int value2) { switch (m_effect) { case E_Damage: if ((D_Level <= m_value1) || !value2) { emit(error(bounds("value2"))); return; } break; default: emit(warning(unused("value2"))); return; } m_value2 = value2; emit(changed()); } void MoveEffect::setValue3(const int value3) { switch (m_effect) { case E_Damage: //if () break; } m_value3 = value3; emit(changed()); } void MoveEffect::setValue4(const Fraction& value4) { if ((m_effect != E_StealHP) && (m_effect != E_Counter) && (m_effect != E_Selfdestruct) && (m_effect != E_Mirror) && (m_effect != E_GetMoney) && (m_effect != E_WaitAndReturn) && (m_effect != E_Recoil) && (1 < value4)) { emit(error(bounds("value4"))); return; } m_value4 = value4; emit(changed()); } Fraction MoveEffect::chance() const { return m_chance; } int MoveEffect::effect() const { return m_effect; } int MoveEffect::value1() const { return m_value1; } int MoveEffect::value2() const { return m_value2; } int MoveEffect::value3() const { return m_value3; } Fraction MoveEffect::value4() const { return m_value4; } MoveEffect& MoveEffect::operator=(const MoveEffect& rhs) { if (this == &rhs) return *this; COPY(chance); COPY(effect); COPY(value1); COPY(value2); COPY(value3); COPY(value4); return *this; }