diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-03-31 01:17:59 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-03-31 01:17:59 +0000 |
| commit | 9a65bc6bb7c8da1dfa5b101579e52845c75848ef (patch) | |
| tree | 258900f882a6998ac6fa525bd247e302028a8911 /pokemod/AbilityEffect.cpp | |
| parent | 8e1ec2aec50999bae30625303f2c96e5b3b7f318 (diff) | |
| download | sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.tar.gz sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.tar.xz sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.zip | |
[FIX] Member variables now use m_ prefix
[FIX] Lots of minor fixes
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@95 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/AbilityEffect.cpp')
| -rw-r--r-- | pokemod/AbilityEffect.cpp | 403 |
1 files changed, 188 insertions, 215 deletions
diff --git a/pokemod/AbilityEffect.cpp b/pokemod/AbilityEffect.cpp index c4f5c470..e9ae084e 100644 --- a/pokemod/AbilityEffect.cpp +++ b/pokemod/AbilityEffect.cpp @@ -1,28 +1,26 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/AbilityEffect.cpp -// Purpose: Define an effect of an ability -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Thu Mar 22 19:06:58 2007 -// Copyright: ©2007-2008 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/>. + */ -#include "Pokemod.h" +// Pokemod includes #include "Ability.h" +#include "Pokemod.h" #include "Type.h" + +// Header include #include "AbilityEffect.h" const QStringList AbilityEffect::EffectStr = QStringList() << "Damage to HP" << "Prevent Damage" << "Auto Heal" << "Deal Damage" << "Wilds" << "Stat" << "Status" << "Ability" << "Accuracy/Power Trade" << "Bullseye" << "Item Effect" << "Type" << "Fast Hatch" << "Weather"; @@ -35,102 +33,102 @@ const QStringList AbilityEffect::BoostStr = QStringList() << "Boost" << "Hinder" const QStringList AbilityEffect::SideStr = QStringList() << "Above" << "Below"; -AbilityEffect::AbilityEffect(const Pokemod* par, const int _id) : - Object("AbilityEffect", par, _id), - chance(1, 1), - effect(-1), - val1(-1), - val2(-1), - val3(-1), - trigger(-1), - tval1(-1), - tval2(-1) +AbilityEffect::AbilityEffect(const Pokemod* pokemod, const int id) : + Object("AbilityEffect", pokemod, id), + m_chance(1, 1), + m_effect(INT_MAX), + m_value1(INT_MAX), + m_value2(INT_MAX), + m_value3(INT_MAX), + m_trigger(INT_MAX), + m_triggerValue1(INT_MAX), + m_triggerValue2(INT_MAX) { } -AbilityEffect::AbilityEffect(const Pokemod* par, const AbilityEffect& e, const int _id) : - Object("AbilityEffect", par, _id) +AbilityEffect::AbilityEffect(const Pokemod* pokemod, const AbilityEffect& effect, const int id) : + Object("AbilityEffect", pokemod, id) { - *this = e; + *this = effect; } -AbilityEffect::AbilityEffect(const Pokemod* par, const QString& fname, const int _id) : - Object("AbilityEffect", par, _id) +AbilityEffect::AbilityEffect(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("AbilityEffect", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool AbilityEffect::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Effect with id %1---").arg(id), Pokemod::V_Msg); - if (effect < E_End) + pokemod()->validationMsg(QString("------Effect with id %1---").arg(id()), Pokemod::V_Msg); + if (m_effect < E_End) { bool ok = true; - switch (effect) + switch (m_effect) { case E_Stats: - if ((Pokemod::ST_HP == val1) || (Pokemod::ST_End_Battle <= val1) || ((val1 == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) + if ((Pokemod::ST_HP == m_value1) || (Pokemod::ST_End_Battle <= m_value1) || ((Pokemod::ST_SpecialDefense == m_value1) && !pokemod()->rules()->specialSplit())) ok = false; break; case E_Status: - if (Pokemod::STS_End <= val1) + if (Pokemod::STS_End <= m_value1) ok = false; break; case E_Ability: - if (pokemod->getAbilityIndex(val1) == -1) + if (pokemod()->abilityIndex(m_value1) == INT_MAX) ok = false; break; case E_AccuracyPowerTrade: - if (PA_End <= val1) + if (PA_End <= m_value1) ok = false; break; case E_ItemEffect: - if (IT_End <= val1) + if (IT_End <= m_value1) ok = false; break; case E_Type: - if (pokemod->getTypeIndex(val1) == -1) + if (pokemod()->typeIndex(m_value1) == INT_MAX) ok = false; break; case E_Weather: - if (Pokemod::W_End_All <= val1) + if (Pokemod::W_End_All <= m_value1) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid value1"); + pokemod()->validationMsg("Invalid value 1"); valid = false; ok = true; } - switch (effect) + switch (m_effect) { case E_Stats: - if (Pokemod::BM_End <= val2) + if (Pokemod::BM_End <= m_value2) ok = false; break; case E_Status: case E_Weather: - if (C_End <= val2) + if (C_End <= m_value2) ok = false; break; case E_Ability: - if (I_End <= val2) + if (I_End <= m_value2) ok = false; break; case E_Type: - if (B_End <= val2) + if (B_End <= m_value2) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid value2"); + pokemod()->validationMsg("Invalid value 2"); valid = false; ok = true; } - switch (effect) + switch (m_effect) { case E_DamageToHP: case E_PreventDamage: @@ -140,201 +138,190 @@ bool AbilityEffect::validate() const case E_AccuracyPowerTrade: case E_Type: case E_FastHatch: - if ((val3 < 0) || (100 < val3)) + if ((m_value3 < 0) || (100 < m_value3)) ok = false; break; case E_Stats: - if ((val3 < -12) || (12 < val3)) + if ((m_value3 < -12) || (12 < m_value3)) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid value3"); + pokemod()->validationMsg("Invalid value 3"); valid = false; ok = true; } } else { - pokemod->validationMsg("Invalid effect"); + pokemod()->validationMsg("Invalid effect"); valid = false; } - if (trigger < T_End) + if (m_trigger < T_End) { bool ok = true; - switch (trigger) + switch (m_trigger) { case T_Weather: - if (Pokemod::W_End_All <= tval1) + if (Pokemod::W_End_All <= m_triggerValue1) ok = false; break; case T_Type: - if (pokemod->getTypeIndex(tval1) == -1) + if (pokemod()->typeIndex(m_triggerValue1) == INT_MAX) ok = false; break; case T_HPBoundary: - if (S_End <= tval1) + if (S_End <= m_triggerValue1) ok = false; break; case T_StatChange: - if ((Pokemod::ST_HP == tval1) || (Pokemod::ST_End_Battle <= tval1) || ((tval1 == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) + if ((Pokemod::ST_HP == m_triggerValue1) || (Pokemod::ST_End_Battle <= m_triggerValue1) || ((Pokemod::ST_SpecialDefense == m_triggerValue1) && !pokemod()->rules()->specialSplit())) ok = false; break; case T_Status: - if (Pokemod::STS_End <= tval1) + if (Pokemod::STS_End <= m_triggerValue1) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid trigger value1"); + pokemod()->validationMsg("Invalid trigger value 1"); valid = false; } } else { - pokemod->validationMsg("Invalid trigger"); + pokemod()->validationMsg("Invalid trigger"); valid = false; } return valid; } -void AbilityEffect::load(const QString& fname, const int _id) throw(Exception) +void AbilityEffect::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; 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("trigger", trigger); - ini.getValue("tval1", tval1); - ini.getValue("tval2-n", i, 1); - ini.getValue("tval2-d", j, 1); - tval2.set(i, j); + 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("trigger", m_trigger); + ini.getValue("triggerValue1", m_triggerValue1); + ini.getValue("triggerValue2-n", i, 1); + ini.getValue("triggerValue2-d", j, 1); + m_triggerValue2.set(i, j); } void AbilityEffect::save(const QString& ability) 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("trigger", trigger); - ini.addField("tval1", tval1); - ini.addField("tval2-n", tval2.getNum()); - ini.addField("tval2-d", tval2.getDenom()); - ini.save(QString("%1/ability/%2/effect/%3.pini").arg(pokemod->getPath()).arg(ability).arg(id)); -} - -void AbilityEffect::setChance(const int n, const int d) throw(Exception) -{ - chance.set(n, d); -} - -void AbilityEffect::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("trigger", m_trigger); + ini.addField("triggerValue1", m_triggerValue1); + ini.addField("triggerValue2-n", m_triggerValue2.numerator()); + ini.addField("triggerValue2-d", m_triggerValue2.denominator()); + ini.save(QString("%1/ability/%2/effect/%3.pini").arg(pokemod()->path()).arg(ability).arg(id())); } -void AbilityEffect::setChanceDenom(const int d) throw(Exception) +void AbilityEffect::setChance(const int numerator, const int denominator) throw(Exception) { - chance.setDenom(d); + m_chance.set(numerator, denominator); } -void AbilityEffect::setEffect(const int e) throw(BoundsException) +void AbilityEffect::setEffect(const int effect) throw(BoundsException) { - if (E_End <= e) - throw(BoundsException(className, "effect")); - effect = e; - val1 = -1; - val2 = -1; - val3 = 0; + if (E_End <= effect) + throw(BoundsException(className(), "effect")); + m_effect = effect; + m_value1 = INT_MAX; + m_value2 = INT_MAX; + m_value3 = 0; } -void AbilityEffect::setVal1(const int v1) throw(Exception) +void AbilityEffect::setValue1(const int value1) throw(Exception) { - switch (effect) + switch (m_effect) { case E_Stats: - if ((Pokemod::ST_HP == val1) || (Pokemod::ST_End_Battle <= val1) || ((val1 == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) - throw(BoundsException(className, "val1")); + if ((Pokemod::ST_HP == value1) || (Pokemod::ST_End_Battle <= value1) || ((Pokemod::ST_SpecialDefense == value1) && !pokemod()->rules()->specialSplit())) + throw(BoundsException(className(), "value1")); break; case E_Status: - if (Pokemod::STS_End <= v1) - throw(BoundsException(className, "val1")); + if (Pokemod::STS_End <= value1) + throw(BoundsException(className(), "value1")); break; case E_Ability: - if (pokemod->getAbilityIndex(v1) == -1) - throw(BoundsException(className, "val1")); + if (pokemod()->abilityIndex(value1) == INT_MAX) + throw(BoundsException(className(), "value1")); break; case E_AccuracyPowerTrade: - if (PA_End <= v1) - throw(BoundsException(className, "val1")); + if (PA_End <= value1) + throw(BoundsException(className(), "value1")); break; case E_ItemEffect: - if (IT_End <= v1) - throw(BoundsException(className, "val1")); + if (IT_End <= value1) + throw(BoundsException(className(), "value1")); break; case E_Type: - if (pokemod->getTypeIndex(v1) == -1) - throw(BoundsException(className, "val1")); + if (pokemod()->typeIndex(value1) == INT_MAX) + throw(BoundsException(className(), "value1")); break; case E_Weather: - if (Pokemod::W_End_All <= v1) - throw(BoundsException(className, "val1")); + if (Pokemod::W_End_All <= value1) + throw(BoundsException(className(), "value1")); break; default: - throw(UnusedException(className, "val1")); + throw(UnusedException(className(), "value1")); break; } - val1 = v1; + m_value1 = value1; } -void AbilityEffect::setVal2(const int v2) throw(Exception) +void AbilityEffect::setValue2(const int value2) throw(Exception) { - switch (effect) + switch (m_effect) { case E_Stats: - if (Pokemod::BM_End <= v2) - throw(BoundsException(className, "val2")); + if (Pokemod::BM_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_Status: case E_Weather: - if (C_End <= v2) - throw(BoundsException(className, "val2")); + if (C_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_Ability: - if (I_End <= v2) - throw(BoundsException(className, "val2")); + if (I_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_Type: - if (B_End <= v2) - throw(BoundsException(className, "val2")); + if (B_End <= value2) + throw(BoundsException(className(), "value2")); break; default: - throw(UnusedException(className, "val2")); + throw(UnusedException(className(), "value2")); break; } - val2 = v2; + m_value2 = value2; } -void AbilityEffect::setVal3(const int v3) throw(Exception) +void AbilityEffect::setValue3(const int value3) throw(Exception) { - switch (effect) + switch (m_effect) { case E_DamageToHP: case E_PreventDamage: @@ -344,132 +331,118 @@ void AbilityEffect::setVal3(const int v3) throw(Exception) case E_AccuracyPowerTrade: case E_Type: case E_FastHatch: - if ((v3 < 0) || (100 < v3)) - throw(BoundsException(className, "val3")); + if ((value3 < 0) || (100 < value3)) + throw(BoundsException(className(), "value3")); break; case E_Stats: - if ((v3 < -12) || (12 < v3)) - throw(BoundsException(className, "val3")); + if ((value3 < -12) || (12 < value3)) + throw(BoundsException(className(), "value3")); break; default: - throw(UnusedException(className, "val3")); + throw(UnusedException(className(), "value3")); break; } - val3 = v3; + m_value3 = value3; } -void AbilityEffect::setTrigger(const int t) throw(BoundsException) +void AbilityEffect::setTrigger(const int trigger) throw(BoundsException) { - if (T_End <= t) - throw(BoundsException(className, "trigger")); - trigger = t; - tval1 = -1; - tval2.set(1, 1); + if (T_End <= trigger) + throw(BoundsException(className(), "trigger")); + m_trigger = trigger; + m_triggerValue1 = INT_MAX; + m_triggerValue2.set(1, 1); } -void AbilityEffect::setTval1(const int tv1) throw(Exception) +void AbilityEffect::setTriggerValue1(const int triggerValue1) throw(Exception) { - switch (trigger) + switch (m_trigger) { case T_Weather: - if (Pokemod::W_End_All <= tv1) - throw(BoundsException(className, "tval1")); + if (Pokemod::W_End_All <= triggerValue1) + throw(BoundsException(className(), "triggerValue1")); break; case T_Type: - if (pokemod->getTypeIndex(tv1) == -1) - throw(BoundsException(className, "tval1")); + if (pokemod()->typeIndex(triggerValue1) == INT_MAX) + throw(BoundsException(className(), "triggerValue1")); break; case T_HPBoundary: - if (S_End <= tv1) - throw(BoundsException(className, "tval1")); + if (S_End <= triggerValue1) + throw(BoundsException(className(), "triggerValue1")); break; case T_StatChange: - if ((Pokemod::ST_HP == tval1) || (Pokemod::ST_End_Battle <= tval1) || ((tval1 == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) - throw(BoundsException(className, "tval1")); + if ((Pokemod::ST_HP == triggerValue1) || (Pokemod::ST_End_Battle <= triggerValue1) || ((Pokemod::ST_SpecialDefense == triggerValue1) && !pokemod()->rules()->specialSplit())) + throw(BoundsException(className(), "triggerValue1")); break; case T_Status: - if (Pokemod::STS_End <= tv1) - throw(BoundsException(className, "tval1")); + if (Pokemod::STS_End <= triggerValue1) + throw(BoundsException(className(), "triggerValue1")); break; default: - throw(UnusedException(className, "tval1")); + throw(UnusedException(className(), "triggerValue1")); break; } - tval1 = tv1; -} - -void AbilityEffect::setTval2(const int n, const int d) throw(Exception) -{ - if (trigger != T_HPBoundary) - throw(UnusedException(className, "tval2")); - tval2.set(n, d); -} - -void AbilityEffect::setTval2Num(const int n) throw(Exception) -{ - if (trigger != T_HPBoundary) - throw(UnusedException(className, "tval2")); - tval2.setNum(n); + m_triggerValue1 = triggerValue1; } -void AbilityEffect::setTval2Denom(const int d) throw(Exception) +void AbilityEffect::setTriggerValue2(const int numerator, const int denominator) throw(Exception) { - if (trigger != T_HPBoundary) - throw(UnusedException(className, "tval2")); - tval2.setDenom(d); + if (m_trigger != T_HPBoundary) + throw(UnusedException(className(), "triggerValue2")); + m_triggerValue2.set(numerator, denominator); } -Frac AbilityEffect::getChance() const +Frac AbilityEffect::chance() const { - return chance; + return m_chance; } -int AbilityEffect::getEffect() const +int AbilityEffect::effect() const { - return effect; + return m_effect; } -int AbilityEffect::getVal1() const +int AbilityEffect::value1() const { - return val1; + return m_value1; } -int AbilityEffect::getVal2() const +int AbilityEffect::value2() const { - return val2; + return m_value2; } -int AbilityEffect::getVal3() const +int AbilityEffect::value3() const { - return val3; + return m_value3; } -int AbilityEffect::getTrigger() const +int AbilityEffect::trigger() const { - return trigger; + return m_trigger; } -int AbilityEffect::getTval1() const +int AbilityEffect::triggerValue1() const { - return tval1; + return m_triggerValue1; } -Frac AbilityEffect::getTval2() const +Frac AbilityEffect::triggerValue2() const { - return tval2; + return m_triggerValue2; } AbilityEffect& AbilityEffect::operator=(const AbilityEffect& rhs) { if (this == &rhs) return *this; - chance = rhs.chance; - effect = rhs.effect; - val1 = rhs.val1; - val2 = rhs.val2; - val3 = rhs.val3; - trigger = rhs.trigger; - tval1 = rhs.tval1; - tval2 = rhs.tval2; + 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_trigger = rhs.m_trigger; + m_triggerValue1 = rhs.m_triggerValue1; + m_triggerValue2 = rhs.m_triggerValue2; return *this; } |
