///////////////////////////////////////////////////////////////////////////// // 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 "../general/Ref.h" #include "Pokemod.h" #include "MoveEffect.h" const char* PokeMod::MoveEffect::EffectStr[PokeMod::MoveEffect::E_End_Overworld] = {"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"}; PokeMod::MoveEffect::MoveEffect(const Pokemod& par, const unsigned _id) : Object(par, _id), chance(1, 1), effect(UINT_MAX), val1(UINT_MAX), val2(UINT_MAX), val3(INT_MIN), val4(1, 1) { } PokeMod::MoveEffect::MoveEffect(const Pokemod& par, const MoveEffect& e, const unsigned _id) : Object(par, _id) { *this = e; } PokeMod::MoveEffect::MoveEffect(const Pokemod& par, const QString& fname, const unsigned _id) : Object(par, _id) { load(fname, _id); } bool PokeMod::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 PokeMod::MoveEffect::load(const QString& fname, const unsigned _id) throw(Exception) { Ini ini(fname); if (_id == UINT_MAX) ini.getValue("id", id); else id = _id; unsigned i; unsigned j; unsigned 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 PokeMod::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 PokeMod::MoveEffect::setChance(const unsigned n, const unsigned d) throw(Exception) { chance.set(n, d); } void PokeMod::MoveEffect::setChanceNum(const unsigned n) throw(Exception) { chance.setNum(n); } void PokeMod::MoveEffect::setChanceDenom(const unsigned d) throw(Exception) { chance.setDenom(d); } void PokeMod::MoveEffect::setEffect(const unsigned e) throw(BoundsException) { if (E_End <= e) throw(BoundsException("MoveEffect", "effect")); effect = e; val1 = UINT_MAX; val2 = UINT_MAX; val3 = INT_MIN; 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 PokeMod::MoveEffect::setVal1(const unsigned v1) throw(Exception) { switch (effect) { case E_Damage: if (D_End <= v1) throw(BoundsException("MoveEffect", "val1")); break; case E_Status: case E_NeedStatus: if (STS_End <= v1) throw(BoundsException("MoveEffect", "val1")); throw; case E_Stat: if (ST_End_Battle <= v1) throw(BoundsException("MoveEffect", "val1")); break; case E_Counter: case E_Shield: if (MT_End <= v1) throw(BoundsException("MoveEffect", "val1")); break; case E_Recoil: if (R_End <= v1) throw(BoundsException("MoveEffect", "val1")); break; default: throw(BoundsException("MoveEffect", "val1")); break; } val1 = v1; } void PokeMod::MoveEffect::setVal2(const unsigned v2) throw(Exception) { switch (effect) { case E_Damage: if ((D_Level <= val1) || !v2) throw(BoundsException("MoveEffect", "val2")); break; default: throw(BoundsException("MoveEffect", "val2")); break; } val2 = v2; } void PokeMod::MoveEffect::setVal3(const int v3) { switch (effect) { case E_Damage: //if () break; } val3 = v3; } void PokeMod::MoveEffect::setVal4(const unsigned n, const unsigned d) throw(Exception) { val4.set(n, d); } void PokeMod::MoveEffect::setVal4Num(const unsigned n) throw(Exception) { val4.setNum(n); } void PokeMod::MoveEffect::setVal4Denom(const unsigned d) throw(Exception) { val4.setDenom(d); } Frac PokeMod::MoveEffect::getChance() const { return chance; } unsigned PokeMod::MoveEffect::getEffect() const { return effect; } unsigned PokeMod::MoveEffect::getVal1() const { return val1; } unsigned PokeMod::MoveEffect::getVal2() const { return val2; } int PokeMod::MoveEffect::getVal3() const { return val3; } Frac PokeMod::MoveEffect::getVal4() const { return val4; } PokeMod::MoveEffect& PokeMod::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; }