///////////////////////////////////////////////////////////////////////////// // Name: pokemod/MoveEffect.cpp // Purpose: Define an effect of a move // Author: Ben Boeckel // Modified by: Ben Boeckel // Created: Tue Mar 20 18:29:40 2007 // Copyright: ©2007 Ben Boeckel and Nerdy Productions // Licence: // 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 . ///////////////////////////////////////////////////////////////////////////// #include "Pokemod.h" #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* par, const int _id) : Object("MoveEffect", par, _id), chance(1, 1), effect(-1), val1(-1), val2(-1), val3(0), val4(1, 1) { } MoveEffect::MoveEffect(const Pokemod* par, const MoveEffect& e, const int _id) : Object("MoveEffect", par, _id) { *this = e; } MoveEffect::MoveEffect(const Pokemod* par, const QString& fname, const int _id) : Object("MoveEffect", par, _id) { load(fname, _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& fname, const int _id) throw(Exception) { Ini ini(fname); if (_id == -1) ini.getValue("id", id); else id = _id; int i; int j; int k; ini.getValue("chance-n", i, 1); ini.getValue("chance-d", j, 1); chance.set(i, j); ini.getValue("effect", effect); ini.getValue("val1", val1); ini.getValue("val2", val2); ini.getValue("val3", val3); ini.getValue("val4-n", i); ini.getValue("val4-d", j); ini.getValue("val4-t", k); val4.set(i, j, k); } void MoveEffect::save(const QString& move) const throw(Exception) { Ini ini; ini.addField("id", id); ini.addField("chance-n", chance.getNum()); ini.addField("chance-d", chance.getDenom()); ini.addField("effect", effect); ini.addField("val1", val1); ini.addField("val2", val2); ini.addField("val3", val3); ini.addField("val4-n", val4.getNum()); ini.addField("val4-d", val4.getDenom()); ini.addField("val4-t", val4.getType()); ini.save(QString("%1/move/%2/effect/%3.pini").arg(pokemod->getPath()).arg(move).arg(id)); } void MoveEffect::setChance(const int n, const int d) throw(Exception) { chance.set(n, d); } void MoveEffect::setChanceNum(const int n) throw(Exception) { chance.setNum(n); } void MoveEffect::setChanceDenom(const int d) throw(Exception) { chance.setDenom(d); } void MoveEffect::setEffect(const int e) throw(BoundsException) { if (E_End <= e) throw(BoundsException(className, "effect")); effect = e; val1 = -1; val2 = -1; val3 = 0; val4.set(1, 1, ((e == E_StealHP) || (e == E_Counter) || (e == E_Selfdestruct) || (e == E_Mirror) || (e == E_GetMoney) || (e == E_WaitAndReturn) || (e == E_Recoil)) ? Frac::Improper : Frac::Proper); } void MoveEffect::setVal1(const int v1) throw(Exception) { switch (effect) { case E_Damage: if (D_End <= v1) throw(BoundsException(className, "val1")); break; case E_Status: case E_NeedStatus: if (Pokemod::STS_End <= v1) throw(BoundsException(className, "val1")); throw; case E_Stat: if (Pokemod::ST_End_Battle <= v1) throw(BoundsException(className, "val1")); break; case E_Counter: case E_Shield: if (MT_End <= v1) throw(BoundsException(className, "val1")); break; case E_Recoil: if (R_End <= v1) throw(BoundsException(className, "val1")); break; default: throw(BoundsException(className, "val1")); break; } val1 = v1; } void MoveEffect::setVal2(const int v2) throw(Exception) { switch (effect) { case E_Damage: if ((D_Level <= val1) || !v2) throw(BoundsException(className, "val2")); break; default: throw(BoundsException(className, "val2")); break; } val2 = v2; } void MoveEffect::setVal3(const int v3) { switch (effect) { case E_Damage: //if () break; } val3 = v3; } void MoveEffect::setVal4(const int n, const int d) throw(Exception) { val4.set(n, d); } void MoveEffect::setVal4Num(const int n) throw(Exception) { val4.setNum(n); } void MoveEffect::setVal4Denom(const int d) throw(Exception) { val4.setDenom(d); } Frac MoveEffect::getChance() const { return chance; } int MoveEffect::getEffect() const { return effect; } int MoveEffect::getVal1() const { return val1; } int MoveEffect::getVal2() const { return val2; } int MoveEffect::getVal3() const { return val3; } Frac MoveEffect::getVal4() const { return val4; } MoveEffect& MoveEffect::operator=(const MoveEffect& rhs) { if (this == &rhs) return *this; chance = rhs.chance; effect = rhs.effect; val1 = rhs.val1; val2 = rhs.val2; val3 = rhs.val3; val4 = rhs.val4; return *this; }