diff options
Diffstat (limited to 'pokemod/MoveEffect.cpp')
| -rw-r--r-- | pokemod/MoveEffect.cpp | 247 |
1 files changed, 112 insertions, 135 deletions
diff --git a/pokemod/MoveEffect.cpp b/pokemod/MoveEffect.cpp index 7db04244..afdb3dcb 100644 --- a/pokemod/MoveEffect.cpp +++ b/pokemod/MoveEffect.cpp @@ -1,239 +1,216 @@ -///////////////////////////////////////////////////////////////////////////// -// 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 <http://www.gnu.org/licenses/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// 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* 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* 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* par, const MoveEffect& e, const int _id) : - Object("MoveEffect", par, _id) +MoveEffect::MoveEffect(const Pokemod* pokemod, const MoveEffect& effect, const int id) : + Object("MoveEffect", pokemod, id) { - *this = e; + *this = effect; } -MoveEffect::MoveEffect(const Pokemod* par, const QString& fname, const int _id) : - Object("MoveEffect", par, _id) +MoveEffect::MoveEffect(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MoveEffect", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool MoveEffect::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Effect with id %1---").arg(id), Pokemod::V_Msg); + 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) +void MoveEffect::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(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); + 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", 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); + 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::setChanceDenom(const int d) throw(Exception) +void MoveEffect::setChance(const int numerator, const int denominator) throw(Exception) { - chance.setDenom(d); + m_chance.set(numerator, denominator); } -void MoveEffect::setEffect(const int e) throw(BoundsException) +void MoveEffect::setEffect(const int effect) 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); + 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::setVal1(const int v1) throw(Exception) +void MoveEffect::setValue1(const int value1) throw(Exception) { - switch (effect) + switch (m_effect) { case E_Damage: - if (D_End <= v1) - throw(BoundsException(className, "val1")); + if (D_End <= value1) + throw(BoundsException(className(), "value1")); break; case E_Status: case E_NeedStatus: - if (Pokemod::STS_End <= v1) - throw(BoundsException(className, "val1")); + if (Pokemod::STS_End <= value1) + throw(BoundsException(className(), "value1")); throw; case E_Stat: - if (Pokemod::ST_End_Battle <= v1) - throw(BoundsException(className, "val1")); + if (Pokemod::ST_End_Battle <= value1) + throw(BoundsException(className(), "value1")); break; case E_Counter: case E_Shield: - if (MT_End <= v1) - throw(BoundsException(className, "val1")); + if (MT_End <= value1) + throw(BoundsException(className(), "value1")); break; case E_Recoil: - if (R_End <= v1) - throw(BoundsException(className, "val1")); + if (R_End <= value1) + throw(BoundsException(className(), "value1")); break; default: - throw(BoundsException(className, "val1")); + throw(BoundsException(className(), "value1")); break; } - val1 = v1; + m_value1 = value1; } -void MoveEffect::setVal2(const int v2) throw(Exception) +void MoveEffect::setValue2(const int value2) throw(Exception) { - switch (effect) + switch (m_effect) { case E_Damage: - if ((D_Level <= val1) || !v2) - throw(BoundsException(className, "val2")); + if ((D_Level <= m_value1) || !value2) + throw(BoundsException(className(), "value2")); break; default: - throw(BoundsException(className, "val2")); + throw(BoundsException(className(), "value2")); break; } - val2 = v2; + m_value2 = value2; } -void MoveEffect::setVal3(const int v3) +void MoveEffect::setValue3(const int value3) { - switch (effect) + switch (m_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); + m_value3 = value3; } -void MoveEffect::setVal4Denom(const int d) throw(Exception) +void MoveEffect::setValue4(const int numerator, const int denominator) throw(Exception) { - val4.setDenom(d); + m_value4.set(numerator, denominator); } -Frac MoveEffect::getChance() const +Frac MoveEffect::chance() const { - return chance; + return m_chance; } -int MoveEffect::getEffect() const +int MoveEffect::effect() const { - return effect; + return m_effect; } -int MoveEffect::getVal1() const +int MoveEffect::value1() const { - return val1; + return m_value1; } -int MoveEffect::getVal2() const +int MoveEffect::value2() const { - return val2; + return m_value2; } -int MoveEffect::getVal3() const +int MoveEffect::value3() const { - return val3; + return m_value3; } -Frac MoveEffect::getVal4() const +Frac MoveEffect::value4() const { - return val4; + return m_value4; } 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; + 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; } |
