/* * 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 . */ // Pokemod includes #include "Pokemod.h" // Header include #include "MoveEffect.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 Pokemod* pokemod, const int id) : Object("MoveEffect", pokemod, 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 Pokemod* pokemod, const MoveEffect& effect, const int id) : Object("MoveEffect", pokemod, id) { *this = effect; } MoveEffect::MoveEffect(const Pokemod* pokemod, const QString& fileName, const int id) : Object("MoveEffect", pokemod, id) { load(fileName, id); } bool MoveEffect::validate() const { bool valid = true; pokemod()->validationMsg(QString("------Effect with id %1---").arg(id()), Pokemod::V_Msg); // TODO (Ben#1#): Move Effect validation return valid; } void MoveEffect::load(const QString& fileName, int id) throw(Exception) { Ini ini(fileName); if (id == INT_MAX) ini.getValue("id", id); setId(id); int i; int j; int k; ini.getValue("chance-n", i, 1); ini.getValue("chance-d", j, 1); m_chance.set(i, j); ini.getValue("effect", m_effect); ini.getValue("value1", m_value1); ini.getValue("value2", m_value2); ini.getValue("value3", m_value3); ini.getValue("value4-n", i); ini.getValue("value4-d", j); ini.getValue("value4-t", k); m_value4.set(i, j, k); } void MoveEffect::save(const QString& move) const throw(Exception) { Ini ini; ini.addField("id", id()); ini.addField("chance-n", m_chance.numerator()); ini.addField("chance-d", m_chance.denominator()); ini.addField("effect", m_effect); ini.addField("value1", m_value1); ini.addField("value2", m_value2); ini.addField("value3", m_value3); ini.addField("value4-n", m_value4.numerator()); ini.addField("value4-d", m_value4.denominator()); ini.addField("value4-t", m_value4.type()); ini.save(QString("%1/move/%2/effect/%3.pini").arg(pokemod()->path()).arg(move).arg(id())); } void MoveEffect::setChance(const int numerator, const int denominator) throw(Exception) { m_chance.set(numerator, denominator); } void MoveEffect::setEffect(const int effect) throw(BoundsException) { if (E_End <= effect) throw(BoundsException(className(), "effect")); m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; m_value3 = 0; m_value4.set(1, 1, ((effect == E_StealHP) || (effect == E_Counter) || (effect == E_Selfdestruct) || (effect == E_Mirror) || (effect == E_GetMoney) || (effect == E_WaitAndReturn) || (effect == E_Recoil)) ? Frac::Improper : Frac::Proper); } void MoveEffect::setValue1(const int value1) throw(Exception) { switch (m_effect) { case E_Damage: if (D_End <= value1) throw(BoundsException(className(), "value1")); break; case E_Status: case E_NeedStatus: if (Pokemod::STS_End <= value1) throw(BoundsException(className(), "value1")); throw; case E_Stat: if (Pokemod::ST_End_Battle <= value1) throw(BoundsException(className(), "value1")); break; case E_Counter: case E_Shield: if (MT_End <= value1) throw(BoundsException(className(), "value1")); break; case E_Recoil: if (R_End <= value1) throw(BoundsException(className(), "value1")); break; default: throw(BoundsException(className(), "value1")); break; } m_value1 = value1; } void MoveEffect::setValue2(const int value2) throw(Exception) { switch (m_effect) { case E_Damage: if ((D_Level <= m_value1) || !value2) throw(BoundsException(className(), "value2")); break; default: throw(BoundsException(className(), "value2")); break; } m_value2 = value2; } void MoveEffect::setValue3(const int value3) { switch (m_effect) { case E_Damage: //if () break; } m_value3 = value3; } void MoveEffect::setValue4(const int numerator, const int denominator) throw(Exception) { m_value4.set(numerator, denominator); } Frac 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; } Frac MoveEffect::value4() const { return m_value4; } MoveEffect& MoveEffect::operator=(const MoveEffect& rhs) { if (this == &rhs) return *this; m_chance = rhs.m_chance; m_effect = rhs.m_effect; m_value1 = rhs.m_value1; m_value2 = rhs.m_value2; m_value3 = rhs.m_value3; m_value4 = rhs.m_value4; return *this; }