diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-23 19:05:08 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-23 19:05:08 +0000 |
commit | c07a81f2656d1168e7124f0b7281a4e38128926b (patch) | |
tree | cf0c4d044bc20683c54631862e07ee166b4c0b7f /pokemod | |
parent | d8973a8ed86925ea5611520c3b7b989ccc238bb4 (diff) | |
download | sigen-c07a81f2656d1168e7124f0b7281a4e38128926b.tar.gz sigen-c07a81f2656d1168e7124f0b7281a4e38128926b.tar.xz sigen-c07a81f2656d1168e7124f0b7281a4e38128926b.zip |
[FIX] Scrapped effects and such for scripts (going to use Kross) in pokemod
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@166 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod')
40 files changed, 586 insertions, 3987 deletions
diff --git a/pokemod/Ability.cpp b/pokemod/Ability.cpp index 1ddef95f..279cb5bf 100644 --- a/pokemod/Ability.cpp +++ b/pokemod/Ability.cpp @@ -19,11 +19,8 @@ #include "Ability.h" // Pokemod includes -#include "AbilityEffect.h" #include "Pokemod.h" - -// Qt includes -#include <QSet> +#include "Script.h" Ability::Ability(const Ability& ability) : Object("Ability", ability.parent(), ability.id()) @@ -33,7 +30,8 @@ Ability::Ability(const Ability& ability) : Ability::Ability(const Pokemod* parent, const int id) : Object("Ability", parent, id), - m_name("") + m_name(""), + m_script("", "") { } @@ -51,37 +49,26 @@ Ability::Ability(const QDomElement& xml, const Pokemod* parent, const int id) : Ability::~Ability() { - clear(); } void Ability::validate() { if (m_name.isEmpty()) emit(error("Name is empty")); - if (!effectCount()) - emit(error("No effects")); - QSet<int> idChecker; - foreach (AbilityEffect* effect, m_effects) - { - effect->validate(); - if (idChecker.contains(effect->id())) - emit(error(subclass("effect", effect->id()))); - idChecker.insert(effect->id()); - } } void Ability::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(QString, name); - LOAD_SUB(newEffect, AbilityEffect); + LOAD(Script, script); } QDomElement Ability::save() const { SAVE_CREATE(); SAVE(QString, name); - SAVE_SUB(AbilityEffect, effects); + SAVE(Script, script); return xml; } @@ -90,104 +77,26 @@ void Ability::setName(const QString& name) CHECK(name); } -QString Ability::name() const -{ - return m_name; -} - -const AbilityEffect* Ability::effect(const int index) const -{ - if (effectCount() <= index) - return NULL; - return m_effects.at(index); -} - -AbilityEffect* Ability::effect(const int index) -{ - if (effectCount() <= index) - return NULL; - return m_effects[index]; -} - -const AbilityEffect* Ability::effectById(const int id) const -{ - return effect(effectIndex(id)); -} - -AbilityEffect* Ability::effectById(const int id) -{ - return effect(effectIndex(id)); -} - -int Ability::effectIndex(const int id) const -{ - for (int i = 0; i < effectCount(); ++i) - { - if (m_effects[id]->id() == id) - return i; - } - return INT_MAX; -} - -int Ability::effectCount() const +void Ability::setScript(const Script& script) { - return m_effects.size(); + CHECK(script); } -AbilityEffect* Ability::newEffect() -{ - return newEffect(new AbilityEffect(this, effectId())); -} - -AbilityEffect* Ability::newEffect(const QDomElement& xml) -{ - return newEffect(new AbilityEffect(xml, this, effectId())); -} - -AbilityEffect* Ability::newEffect(const AbilityEffect& effect) -{ - return newEffect(new AbilityEffect(effect, this, effectId())); -} - -AbilityEffect* Ability::newEffect(AbilityEffect* effect) -{ - m_effects.append(effect); - return effect; -} - -void Ability::deleteEffect(const int index) -{ - if (effectCount() <= index) - return; - delete m_effects[index]; - m_effects.removeAt(index); -} - -void Ability::deleteEffectById(const int id) +QString Ability::name() const { - deleteEffect(effectIndex(id)); + return m_name; } -int Ability::effectId() const +Script Ability::script() const { - int i = 0; - while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) - ++i; - return i; + return m_script; } Ability& Ability::operator=(const Ability& rhs) { if (this == &rhs) return *this; - clear(); COPY(name); - COPY_SUB(AbilityEffect, effects); + COPY(script); return *this; } - -void Ability::clear() -{ - while (effectCount()) - deleteEffect(0); -} diff --git a/pokemod/Ability.h b/pokemod/Ability.h index 2b02d13d..edadc074 100644 --- a/pokemod/Ability.h +++ b/pokemod/Ability.h @@ -20,12 +20,9 @@ // Pokemod includes #include "Object.h" - -// Qt includes -#include <QList> +#include "Script.h" // Forward declarations -class AbilityEffect; class Pokemod; class Ability : public Object @@ -45,30 +42,15 @@ class Ability : public Object QDomElement save() const; void setName(const QString& name); + void setScript(const Script& script); QString name() const; - - const AbilityEffect* effect(const int index) const; - AbilityEffect* effect(const int index); - const AbilityEffect* effectById(const int id) const; - AbilityEffect* effectById(const int id); - int effectIndex(const int id) const; - int effectCount() const; - AbilityEffect* newEffect(); - AbilityEffect* newEffect(const QDomElement& xml); - AbilityEffect* newEffect(const AbilityEffect& effect); - void deleteEffect(const int index); - void deleteEffectById(const int id); + Script script() const; Ability& operator=(const Ability& rhs); private: - int effectId() const; - AbilityEffect* newEffect(AbilityEffect* effect); - - void clear(); - QString m_name; - QList<AbilityEffect*> m_effects; + Script m_script; }; #endif diff --git a/pokemod/AbilityEffect.cpp b/pokemod/AbilityEffect.cpp deleted file mode 100644 index d2c044a1..00000000 --- a/pokemod/AbilityEffect.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/* - * 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/>. - */ - -// Header include -#include "AbilityEffect.h" - -// Pokemod includes -#include "Ability.h" -#include "Type.h" -#include "Pokemod.h" -#include "Rules.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"; -const QStringList AbilityEffect::TriggerStr = QStringList() << "Anything" << "Contact" << "Weather" << "Damage" << "Type" << "HP Boundary" << "Stat Change" << "Status"; -const QStringList AbilityEffect::InteractStr = QStringList() << "Trade" << "Shadow" << "Block"; -const QStringList AbilityEffect::PowerAccuracyStr = QStringList() << "Boost Power" << "Boost Accuracy"; -const QStringList AbilityEffect::ItemStr = QStringList() << "Stat Modifier" << "Type Booster" << "Flinch" << "Go First"; -const QStringList AbilityEffect::CauseStr = QStringList() << "Prevent" << "Inflict"; -const QStringList AbilityEffect::BoostStr = QStringList() << "Boost" << "Hinder"; -const QStringList AbilityEffect::SideStr = QStringList() << "Above" << "Below"; - - -AbilityEffect::AbilityEffect(const AbilityEffect& effect) : - Object("AbilityEffect", effect.parent(), effect.id()) -{ - *this = effect; -} - -AbilityEffect::AbilityEffect(const Ability* parent, const int id) : - Object("AbilityEffect", parent, 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(1, 1) -{ -} - -AbilityEffect::AbilityEffect(const AbilityEffect& effect, const Ability* parent, const int id) : - Object("AbilityEffect", parent, id) -{ - *this = effect; -} - -AbilityEffect::AbilityEffect(const QDomElement& xml, const Ability* parent, const int id) : - Object("AbilityEffect", parent, id) -{ - load(xml, id); -} - -void AbilityEffect::validate() -{ - TEST(setChance, chance); - TEST(setEffect, effect); - TEST(setValue1, value1); - TEST(setValue2, value2); - TEST(setValue3, value3); - TEST(setTrigger, trigger); - TEST(setTriggerValue1, triggerValue1); - TEST(setTriggerValue2, triggerValue2); -} - -void AbilityEffect::load(const QDomElement& xml, int id) -{ - LOAD_ID(); - LOAD(Fraction, chance); - LOAD(int, effect); - LOAD(int, value1); - LOAD(int, value2); - LOAD(int, value3); - LOAD(int, trigger); - LOAD(int, triggerValue1); - LOAD(Fraction, triggerValue2); -} - -QDomElement AbilityEffect::save() const -{ - SAVE_CREATE(); - SAVE(Fraction, chance); - SAVE(int, effect); - SAVE(int, value1); - SAVE(int, value2); - SAVE(int, value3); - SAVE(int, trigger); - SAVE(int, triggerValue1); - SAVE(Fraction, triggerValue2); - return xml; -} - -void AbilityEffect::setChance(const Fraction& chance) -{ - if (1 < chance) - { - emit(error(bounds("chance"))); - return; - } - CHECK(chance); -} - -void AbilityEffect::setEffect(const int effect) -{ - if (E_End <= effect) - { - emit(error(bounds("effect"))); - return; - } - CHECK(effect); -} - -void AbilityEffect::setValue1(const int value1) -{ - switch (m_effect) - { - case E_Stats: - if ((value1 < Pokemod::ST_No_HP_Start) || (Pokemod::ST_End_Battle <= value1) || ((Pokemod::ST_SpecialDefense == value1) && !static_cast<const Pokemod*>(pokemod())->rules()->specialSplit())) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_Status: - if (Pokemod::STS_End <= value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_Ability: - if (static_cast<const Pokemod*>(pokemod())->abilityIndex(value1) == INT_MAX) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_AccuracyPowerTrade: - if (PA_End <= value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_ItemEffect: - if (IT_End <= value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_Type: - if (static_cast<const Pokemod*>(pokemod())->typeIndex(value1) == INT_MAX) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_Weather: - if (Pokemod::W_End_All <= value1) - { - emit(error(bounds("value1"))); - return; - } - break; - default: - emit(warning(unused("value1"))); - return; - } - CHECK(value1); -} - -void AbilityEffect::setValue2(const int value2) -{ - switch (m_effect) - { - case E_Stats: - if (Pokemod::BM_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_Status: - case E_Weather: - if (C_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_Ability: - if (I_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_Type: - if (B_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - default: - emit(warning(unused("value2"))); - return; - } - CHECK(value2); -} - -void AbilityEffect::setValue3(const int value3) -{ - switch (m_effect) - { - case E_DamageToHP: - case E_PreventDamage: - case E_AutoHeal: - case E_DealDamage: - case E_Wilds: - case E_AccuracyPowerTrade: - case E_Type: - case E_FastHatch: - if ((value3 < 0) || (100 < value3)) - { - emit(error(bounds("value3"))); - return; - } - break; - case E_Stats: - if ((value3 < -12) || (12 < value3)) - { - emit(error(bounds("value3"))); - return; - } - break; - default: - emit(warning(unused("value3"))); - return; - } - CHECK(value3); -} - -void AbilityEffect::setTrigger(const int trigger) -{ - if (T_End <= trigger) - { - emit(error(bounds("trigger"))); - return; - } - CHECK(trigger); -} - -void AbilityEffect::setTriggerValue1(const int triggerValue1) -{ - switch (m_trigger) - { - case T_Weather: - if (Pokemod::W_End_All <= triggerValue1) - { - emit(error(bounds("triggerValue1"))); - return; - } - break; - case T_Type: - if (static_cast<const Pokemod*>(pokemod())->typeIndex(triggerValue1) == INT_MAX) - { - emit(error(bounds("triggerValue1"))); - return; - } - break; - case T_HPBoundary: - if (S_End <= triggerValue1) - { - emit(error(bounds("triggerValue1"))); - return; - } - break; - case T_StatChange: - if ((triggerValue1 < Pokemod::ST_No_HP_Start) || (Pokemod::ST_End_Battle <= triggerValue1) || ((Pokemod::ST_SpecialDefense == triggerValue1) && !static_cast<const Pokemod*>(pokemod())->rules()->specialSplit())) - { - emit(error(bounds("triggerValue1"))); - return; - } - break; - case T_Status: - if (Pokemod::STS_End <= triggerValue1) - { - emit(error(bounds("triggerValue1"))); - return; - } - break; - default: - emit(warning(unused("triggerValue1"))); - return; - } - CHECK(triggerValue1); -} - -void AbilityEffect::setTriggerValue2(const Fraction& triggerValue2) -{ - if (m_trigger != T_HPBoundary) - { - emit(warning(unused("triggerValue2"))); - return; - } - CHECK(triggerValue2); -} - -Fraction AbilityEffect::chance() const -{ - return m_chance; -} - -int AbilityEffect::effect() const -{ - return m_effect; -} - -int AbilityEffect::value1() const -{ - return m_value1; -} - -int AbilityEffect::value2() const -{ - return m_value2; -} - -int AbilityEffect::value3() const -{ - return m_value3; -} - -int AbilityEffect::trigger() const -{ - return m_trigger; -} - -int AbilityEffect::triggerValue1() const -{ - return m_triggerValue1; -} - -Fraction AbilityEffect::triggerValue2() const -{ - return m_triggerValue2; -} - -AbilityEffect& AbilityEffect::operator=(const AbilityEffect& rhs) -{ - if (this == &rhs) - return *this; - COPY(chance); - COPY(effect); - COPY(value1); - COPY(value2); - COPY(value3); - COPY(trigger); - COPY(triggerValue1); - COPY(triggerValue2); - return *this; -} diff --git a/pokemod/AbilityEffect.h b/pokemod/AbilityEffect.h deleted file mode 100644 index d855cdc8..00000000 --- a/pokemod/AbilityEffect.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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/>. - */ - -#ifndef __POKEMOD_ABILITYEFFECT__ -#define __POKEMOD_ABILITYEFFECT__ - -// Pokemod includes -#include "Fraction.h" -#include "Object.h" - -// Qt includes -#include <QStringList> - -// Forward declarations -class Ability; - -class AbilityEffect : public Object -{ - Q_OBJECT - - public: - enum Effect - { - E_DamageToHP = 0, - E_PreventDamage = 1, - E_AutoHeal = 2, - E_DealDamage = 3, - E_Wilds = 4, - E_Stats = 5, - E_Status = 6, - E_Ability = 7, - E_AccuracyPowerTrade = 8, - E_Bullseye = 9, - E_ItemEffect = 10, - E_Type = 11, - E_FastHatch = 12, - E_Weather = 13, - E_End = 14 - }; - static const QStringList EffectStr; - - enum Trigger - { - T_Anything = 0, - T_Contact = 1, - T_Weather = 2, - T_Damage = 3, - T_Type = 4, - T_HPBoundary = 5, - T_StatChange = 6, - T_Status = 7, - T_End = 8 - }; - static const QStringList TriggerStr; - - enum Interact - { - I_Trade = 0, - I_Shadow = 1, - I_Block = 2, - I_End = 3 - }; - static const QStringList InteractStr; - - enum PowerAccuracy - { - PA_Power = 0, - PA_Accuracy = 1, - PA_End = 2 - }; - static const QStringList PowerAccuracyStr; - - enum Item - { - IT_Stat = 0, - IT_TypeBoost = 1, - IT_Flinch = 2, - IT_Quick = 3, - IT_End = 4 - }; - static const QStringList ItemStr; - - enum Cause - { - C_Prevent = 0, - C_Inflict = 1, - C_End = 2 - }; - static const QStringList CauseStr; - - enum Boost - { - B_Boost = 0, - B_Hinder = 1, - B_End = 2 - }; - static const QStringList BoostStr; - - enum Side - { - S_Above = 0, - S_Below = 1, - S_End = 2 - }; - static const QStringList SideStr; - - AbilityEffect(const AbilityEffect& effect); - AbilityEffect(const Ability* parent, const int id); - AbilityEffect(const AbilityEffect& effect, const Ability* parent, const int id); - AbilityEffect(const QDomElement& xml, const Ability* parent, const int id = INT_MAX); - - void validate(); - - void load(const QDomElement& xml, int id = INT_MAX); - QDomElement save() const; - - void setChance(const Fraction& chance); - void setEffect(const int effect); - void setValue1(const int value1); - void setValue2(const int value2); - void setValue3(const int value3); - void setTrigger(const int trigger); - void setTriggerValue1(const int triggerValue1); - void setTriggerValue2(const Fraction& triggerValue2); - - Fraction chance() const; - int effect() const; - int value1() const; - int value2() const; - int value3() const; - int trigger() const; - int triggerValue1() const; - Fraction triggerValue2() const; - - AbilityEffect& operator=(const AbilityEffect& rhs); - private: - Fraction m_chance; - int m_effect; - int m_value1; - int m_value2; - int m_value3; - int m_trigger; - int m_triggerValue1; - Fraction m_triggerValue2; -}; - -#endif diff --git a/pokemod/CoinList.cpp b/pokemod/CoinList.cpp index cf94e407..8e76362c 100644 --- a/pokemod/CoinList.cpp +++ b/pokemod/CoinList.cpp @@ -20,9 +20,8 @@ // Pokemod includes #include "CoinListObject.h" -#include "Item.h" -#include "ItemEffect.h" #include "Pokemod.h" +#include "Script.h" // Qt includes #include <QSet> @@ -36,7 +35,7 @@ CoinList::CoinList(const CoinList& coinList) : CoinList::CoinList(const Pokemod* parent, const int id) : Object("CoinList", parent, id), m_name(""), - m_value(0) + m_script("", "") { } @@ -61,7 +60,6 @@ void CoinList::validate() { if (m_name.isEmpty()) emit(error("Name is empty")); - TEST(setValue, value); if (!objectCount()) emit(error("There are no objects")); QSet<int> idChecker; @@ -92,7 +90,7 @@ void CoinList::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(QString, name); - LOAD(int, value); + LOAD(Script, script); LOAD_SUB(newObject, CoinListObject); } @@ -100,7 +98,7 @@ QDomElement CoinList::save() const { SAVE_CREATE(); SAVE(QString, name); - SAVE(int, value); + SAVE(Script, script); SAVE_SUB(CoinListObject, objects); return xml; } @@ -110,22 +108,9 @@ void CoinList::setName(const QString& name) CHECK(name); } -void CoinList::setValue(const int value) +void CoinList::setScript(const Script& script) { - for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()); ++i) - { - const Item* item = static_cast<const Pokemod*>(pokemod())->item(i); - for (int j = 0; (j < item->effectCount()); ++j) - { - const ItemEffect* effect = item->effect(j); - if ((effect->effect() == ItemEffect::E_CoinCase) && (effect->value1() == value)) - { - CHECK(value); - return; - } - } - } - emit(error(bounds("value"))); + CHECK(script) } QString CoinList::name() const @@ -133,9 +118,9 @@ QString CoinList::name() const return m_name; } -int CoinList::value() const +Script CoinList::script() const { - return m_value; + return m_script; } const CoinListObject* CoinList::object(const int index) const @@ -225,6 +210,7 @@ CoinList& CoinList::operator=(const CoinList& rhs) return *this; clear(); COPY(name); + COPY(script); COPY_SUB(CoinListObject, objects); return *this; } diff --git a/pokemod/CoinList.h b/pokemod/CoinList.h index 74d50695..d3e1df36 100644 --- a/pokemod/CoinList.h +++ b/pokemod/CoinList.h @@ -20,6 +20,7 @@ // Pokemod includes #include "Object.h" +#include "Script.h" // Qt includes #include <QList> @@ -45,10 +46,10 @@ class CoinList : public Object QDomElement save() const; void setName(const QString& name); - void setValue(const int value); + void setScript(const Script& script); QString name() const; - int value() const; + Script script() const; const CoinListObject* object(const int index) const; CoinListObject* object(const int index); @@ -70,7 +71,7 @@ class CoinList : public Object void clear(); QString m_name; - int m_value; + Script m_script; QList<CoinListObject*> m_objects; }; diff --git a/pokemod/Dialog.cpp b/pokemod/Dialog.cpp deleted file mode 100644 index a812ab16..00000000 --- a/pokemod/Dialog.cpp +++ /dev/null @@ -1,665 +0,0 @@ -/* - * 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/>. - */ - -// Header include -#include "Dialog.h" - -// Pokemod includes -#include "Item.h" -#include "ItemEffect.h" -#include "Map.h" -#include "MapEffect.h" -#include "MapTrainer.h" -#include "MapWarp.h" -#include "Move.h" -#include "Pokemod.h" -#include "Rules.h" -#include "Species.h" - -const QStringList Dialog::CommandStr = QStringList() << "Flip Flag" << "Set Flag" << "Unset Flag" << "Randomize Flag" << "Test Flag" << "Jump" << "Yes/No" << "Item Shop" << "Give Item" << "Take Item" << "Check Item" << "Coin List" << "Teach Move" << "Delete Move" << "Give Species" << "Take Species" << "Show Species" << "View Species" << "Give Money" << "Take Money" << "Move Effect" << "Turn Effect" << "Check Direction" << "Check Roster" << "Check Levels" << "Check Species" << "Check Held Items" << "Check Money" << "Trade" << "Daycare" << "Battle" << "Badge" << "Warp" << "Name" << "Music" << "Sound Effect" << "Timer" << "Map Sign" << "Wild Scope" << "Safari" << "Heal Party" << "Refresh" << "Clear" << "Pause" << "New Line" << "Exit" << "Menu"; -const QStringList Dialog::CommandAbbrStr = QStringList() << "FF" << "SF" << "UF" << "RF" << "TF" << "J" << "YN" << "ItS" << "GIt" << "TIt" << "CIt" << "CL" << "TMv" << "DMv" << "GSp" << "TSp" << "SSp" << "VSp" << "G$" << "T$" << "MvEf" << "TEf" << "CD" << "CR" << "CLv" << "CS" << "CHIt" << "C$" << "T" << "Dc" << "Bat" << "Bdg" << "W" << "N" << "Ms" << "SFX" << "Tmr" << "MS" << "WS" << "S" << "HP" << "R" << "C" << "P" << "NL" << "X" << "M"; -const QList<int> Dialog::CommandNumArgs = QList<int>() << 1 << 1 << 1 << 1 << 3 << 2 << 2 << 1 << 4 << 4 << 4 << 1 << 5 << 3 << 7 << 4 << 1 << 4 << 1 << 4 << 6 << 3 << 6 << 5 << 5 << 4 << 4 << 5 << 6 << 1 << 2 << 1 << 2 << 1 << 2 << 1 << 3 << 1 << 1 << 3 << 0 << 0 << 0 << 0 << 0 << 0; - -Dialog::Dialog(const Dialog& dialog) : - Object("Dialog", dialog.parent(), dialog.id()) -{ - *this = dialog; -} - -Dialog::Dialog(const Pokemod* parent, const int id) : - Object("Dialog", parent, id), - m_dialog("") -{ -} - -Dialog::Dialog(const Dialog& dialog, const Pokemod* parent, const int id) : - Object("Dialog", parent, id) -{ - *this = dialog; -} - -Dialog::Dialog(const QDomElement& xml, const Pokemod* parent, const int id) : - Object("Dialog", parent, id) -{ - load(xml, id); -} - -void Dialog::validate() -{ - if (m_dialog.isEmpty()) - emit(error("Dialog is empty")); - if (m_dialog.count('@') & 1) - emit(error("Command delimiter mismatch")); - else - { - int curCmd = End; - int numArgs = 0; - for (int i = 0; i < m_dialog.length(); ++i) - { - switch (m_dialog.at(i).toAscii()) - { - case '@': - switch (curCmd) - { - case FlipFlag ... Exit: - if (numArgs != CommandNumArgs[curCmd]) - emit(error(QString("Invalid number of arguments for \"%1\". %2 given when %3 needed").arg(CommandStr[curCmd], numArgs, CommandNumArgs[curCmd]))); - break; - case Menu: - if (!(numArgs & 1)) - emit(error("Invalid number of arguments for Menu")); - break; - case End: - QString curCmdStr; - for (; (m_dialog.at(i) != '@') && (m_dialog.at(i) != '#'); ++i) - curCmdStr += m_dialog.at(i); - if (((curCmd = CommandAbbrStr.indexOf(curCmdStr))) == INT_MAX) - { - if (!curCmdStr.isEmpty()) - emit(error(QString("Invalid command \"%1\"").arg(curCmdStr))); - curCmd = End; - } - numArgs = 0; - break; - } - break; - case '#': - if (curCmd != End) - { - QString arg; - for (; (m_dialog.at(i) != '@') && (m_dialog.at(i) != '#'); ++i) - arg += m_dialog.at(i); - bool ok; - int temp = arg.toInt(&ok); - int invError = 0; - const Map* map = NULL; - ++numArgs; - switch (curCmd) - { - case FlipFlag: - case SetFlag: - case UnsetFlag: - case RandomizeFlag: - if (numArgs == 1) - { - if (!ok) - emit(error(QString("Bad flag in \"%1\"").arg(CommandStr[curCmd]))); - } - break; - case TestFlag: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!ok) - emit(error("Bad flag in \"Test Flag\"")); - break; - case 3: - case 4: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - } - break; - case Jump: - if (numArgs == 1) - { - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - } - else if (numArgs == 2) - { - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = 2; - } - break; - case YesNo: - case DeleteMove: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - case 3: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - } - break; - case ItemShop: - if (numArgs == 1) - { - if (!ok || (static_cast<const Pokemod*>(pokemod())->storeIndex(temp) == INT_MAX)) - invError = 1; - } - break; - case GiveItem: - case TakeItem: - case CheckItem: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!ok || (static_cast<const Pokemod*>(pokemod())->itemIndex(temp) == INT_MAX)) - invError = 2; - break; - case 3: - case 4: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - break; - } - break; - case CoinList: - if (numArgs == 1) - { - if (!ok || (static_cast<const Pokemod*>(pokemod())->coinListIndex(temp) == INT_MAX)) - invError = 1; - } - break; - case TeachMove: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!ok || (static_cast<const Pokemod*>(pokemod())->moveIndex(temp) == INT_MAX)) - invError = 2; - break; - case 3: - case 4: - case 5: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - break; - } - break; - case CheckMove: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if ((arg != "Lead") && (arg != "All") && (arg != "0") && (arg != "1")) - invError = 2; - break; - case 3: - if (!ok || (static_cast<const Pokemod*>(pokemod())->moveIndex(temp) == INT_MAX)) - invError = 3; - break; - case 4: - case 5: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - break; - } - break; - case GiveSpecies: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) ==INT_MAX)) - invError = 2; - break; - case 3: - if ((arg != "false") && (arg != "true") && (arg != "0") && (arg != "1")) - invError = 3; - break; - case 4: - if (ok) - { - if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < temp) - emit(error("Higher level than allowed in \"Give Pokémon\"")); - } - else - invError = 4; - break; - case 5: - if (!ok) - invError = 5; - break; - case 6: - case 7: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - break; - } - break; - case TakeSpecies: - case ViewSpecies: - case CheckSpecies: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) == INT_MAX)) - invError = 2; - break; - case 3: - case 4: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - break; - } - break; - case ShowSpecies: - if (numArgs == 1) - { - if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) == INT_MAX)) - invError = 1; - } - break; - case GiveMoney: - if (numArgs == 1) - { - if (ok) - { - if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < temp) - emit(warning("More money given than can be held in \"Give Money\"")); - } - else - invError = 1; - } - break; - case TakeMoney: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (ok) - { - if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < temp) - emit(error("More money taken than can be held in \"Take Money\"")); - } - else - invError = 2; - break; - case 3: - case 4: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - break; - } - break; - case MoveEffect: - case CheckDirection: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) - invError = 2; - else - map = static_cast<const Pokemod*>(pokemod())->mapById(temp); - break; - case 3: - if (map) - { - if (!ok || (map->effectIndex(temp) == INT_MAX)) - invError = 3; - } - else if ((arg != "Player") && (arg != "INT_MAX")) - emit(error(QString("Unable to validate argument #3 in \"%1\"").arg(CommandStr[curCmd]))); - break; - case 4: - if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && ((arg != "Random") || (curCmd == CheckDirection)) && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && ((arg != "4") || (curCmd == CheckDirection))) - invError = 4; - break; - case 5: - case 6: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - break; - } - break; - case TurnEffect: - switch (numArgs) - { - case 1: - if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) - invError = 1; - else - map = static_cast<const Pokemod*>(pokemod())->mapById(temp); - break; - case 2: - if (map) - { - if (!ok || (map->effectIndex(temp) == INT_MAX)) - invError = 2; - } - else if ((arg != "Player") && (arg != "INT_MAX")) - emit(error("Unable to validate argument #2 in \"Turn Effect\"")); - map = NULL; - break; - case 3: - if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && (arg != "Random") && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && (arg != "4")) - invError = 3; - break; - } - break; - case CheckRoster: - case CheckLevels: - case CheckMoney: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if ((arg != "<") && (arg != ">") && (arg != "=")) - invError = 2; - break; - case 3: - if (ok) - { - if (((curCmd == CheckRoster) ? static_cast<const Pokemod*>(pokemod())->rules()->maxParty() : ((curCmd == CheckLevels) ? static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() : static_cast<const Pokemod*>(pokemod())->rules()->maxMoney())) < temp) - emit(error(QString("More %1 than can be carried in \"%2\"").arg((curCmd == CheckRoster) ? "party members" : ((curCmd == CheckLevels) ? "level" : "money"), CommandStr[curCmd]))); - } - else - invError = 3; - break; - case 4: - case 5: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - break; - } - break; - case CheckHeldItems: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - case 3: - case 4: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - } - break; - case Trade: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - case 3: - if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) == INT_MAX)) - invError = numArgs; - case 4: - if (!ok) - invError = 4; - break; - case 5: - case 6: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = numArgs; - break; - } - break; - case Daycare: - if (numArgs == 1) - { - if (!ok) - invError = 1; - } - break; - case Battle: - if (numArgs == 1) - { - if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) - invError = 1; - else - map = static_cast<const Pokemod*>(pokemod())->mapById(temp); - } - else if (numArgs == 2) - { - if (map) - { - if (!ok || (map->trainerIndex(temp) == INT_MAX)) - invError = 2; - } - else - emit(error("Unable to validate argument #2 in \"Battle\"")); - map = NULL; - } - break; - case Badge: - if (numArgs == 1) - { - if (!ok || (static_cast<const Pokemod*>(pokemod())->badgeIndex(temp) == INT_MAX)) - invError = 1; - } - break; - case Warp: - if (numArgs == 1) - { - if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) - invError = 1; - else - map = static_cast<const Pokemod*>(pokemod())->mapById(temp); - } - else if (numArgs == 2) - { - if (map) - { - if (!ok || (map->warpIndex(temp) == INT_MAX)) - invError = 2; - } - else - emit(error("Unable to validate argument #2 in \"Warp\"")); - map = NULL; - } - break; - case Name: - case MapSign: - if (numArgs == 1) - { - if (arg == "") - invError = 1; - } - break; - case Music: - if (numArgs == 1) - { - if (!ok || (static_cast<const Pokemod*>(pokemod())->soundIndex(temp) == INT_MAX)) - invError = 1; - } - break; - case SoundEffect: - if (numArgs == 1) - { - if (!ok || (static_cast<const Pokemod*>(pokemod())->soundIndex(temp) == INT_MAX)) - invError = 1; - } - else if (numArgs == 2) - { - if (!ok) - invError = 2; - } - break; - case Timer: - switch (numArgs) - { - case 1: - if ((arg != "Time") && (arg != "Step") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!ok) - invError = 2; - break; - case 3: - if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) - invError = 3; - break; - } - break; - case WildScope: - if (numArgs == 1) - { - if (!ok) - invError = 1; - } - break; - case Safari: - switch (numArgs) - { - case 1: - if (ok && (static_cast<const Pokemod*>(pokemod())->itemIndex(temp) != INT_MAX)) - { - const Item* item = static_cast<const Pokemod*>(pokemod())->itemById(temp); - bool temp = false; - for (int i = 0; (i < item->effectCount()) || !temp; ++i) - { - if (item->effect(i)->effect() == ItemEffect::E_Ball) - temp = true; - } - if (!temp) - emit(error("Item in argument #1 in \"Safari\" isn\'t a PokéBall")); - } - else - invError = 1; - break; - case 2: - if (!ok) - invError = 2; - break; - case 3: - if (!ok || (static_cast<const Pokemod*>(pokemod())->rules()->maxParty() < temp)) - invError = 3; - break; - } - break; - case Menu: - if (numArgs == 1) - { - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - } - else if (numArgs & 1) - { - if (ok) - { - if (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX) - invError = numArgs; - } - else - invError = numArgs; - } - else if (arg == "") - invError = numArgs; - break; - } - if (invError) - emit(error(QString("Invalid argument #%1 in \"%2\"").arg(invError).arg(CommandStr[curCmd]))); - } - break; - } - } - } -} - -void Dialog::load(const QDomElement& xml, int id) -{ - LOAD_ID(); - LOAD(QString, dialog); -} - -QDomElement Dialog::save() const -{ - SAVE_CREATE(); - SAVE(QString, dialog); - return xml; -} - -void Dialog::setDialog(const QString& dialog) -{ - CHECK(dialog); -} - -QString Dialog::dialog() const -{ - return m_dialog; -} - -void Dialog::insertCommand(const int position, const QString& command) -{ - if (m_dialog.length() < position) - { - emit(error(bounds("command"))); - return; - } - m_dialog.insert(position, command); - emit(changed()); -} - -Dialog& Dialog::operator=(const Dialog& rhs) -{ - if (this == &rhs) - return *this; - COPY(dialog); - return *this; -} diff --git a/pokemod/Dialog.h b/pokemod/Dialog.h deleted file mode 100644 index f282c90a..00000000 --- a/pokemod/Dialog.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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/>. - */ - -#ifndef __POKEMOD_DIALOG__ -#define __POKEMOD_DIALOG__ - -// Pokemod includes -#include "Object.h" - -// Qt includes -#include <QList> - -// Forward declarations -class Pokemod; - -class Dialog : public Object -{ - Q_OBJECT - - public: - enum - { - FlipFlag = 0, - SetFlag = 1, - UnsetFlag = 2, - RandomizeFlag = 3, - TestFlag = 4, - Jump = 5, - YesNo = 6, - ItemShop = 7, - GiveItem = 8, - TakeItem = 9, - CheckItem = 10, - CoinList = 11, - TeachMove = 12, - CheckMove = 13, - DeleteMove = 14, - GiveSpecies = 15, - TakeSpecies = 16, - ShowSpecies = 17, - ViewSpecies = 18, - GiveMoney = 19, - TakeMoney = 20, - MoveEffect = 21, - TurnEffect = 22, - CheckDirection = 23, - CheckRoster = 24, - CheckLevels = 25, - CheckSpecies = 26, - CheckHeldItems = 27, - CheckMoney = 28, - Trade = 29, - Daycare = 30, - Battle = 31, - Badge = 32, - Warp = 33, - Name = 34, - Music = 35, - SoundEffect = 36, - Timer = 37, - MapSign = 38, - WildScope = 39, - Safari = 40, - HealParty = 41, - Refresh = 42, - Clear = 43, - Pause = 44, - NewLine = 45, - Exit = 46, - Menu = 47, - End = 48 - }; - static const QStringList CommandStr; - static const QStringList CommandAbbrStr; - static const QList<int> CommandNumArgs; - - Dialog(const Dialog& dialog); - Dialog(const Pokemod* parent, const int id); - Dialog(const Dialog& dialog, const Pokemod* parent, const int id); - Dialog(const QDomElement& xml, const Pokemod* parent, const int id = INT_MAX); - - void validate(); - - void load(const QDomElement& xml, int id = INT_MAX); - QDomElement save() const; - - void setDialog(const QString& dialog); - - QString dialog() const; - - void insertCommand(const int position, const QString& command); - - Dialog& operator=(const Dialog& rhs); - private: - QString m_dialog; -}; - -#endif diff --git a/pokemod/Flag.cpp b/pokemod/Flag.cpp deleted file mode 100644 index e08ba9f0..00000000 --- a/pokemod/Flag.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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/>. - */ - -// Header include -#include "Flag.h" - -const QStringList Flag::ValueStr = QStringList() << "Off" << "On" << "Ignore"; - -Flag::Flag(const int flag, const int status) : - m_flag(flag) -{ - setStatus(status); -} - -void Flag::set(const int flag, const int status) -{ - setFlag(flag); - setStatus(status); -} - -void Flag::setFlag(const int flag) -{ - m_flag = flag; -} - -void Flag::setStatus(const int status) -{ - if (End <= status) - { - m_status = Ignore; - return; - } - m_status = status; -} - -int Flag::flag() const -{ - return m_flag; -} - -int Flag::status() const -{ - return m_status; -} diff --git a/pokemod/Flag.h b/pokemod/Flag.h deleted file mode 100644 index 20cb404e..00000000 --- a/pokemod/Flag.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/>. - */ - -#ifndef __POKEMOD_FLAG__ -#define __POKEMOD_FLAG__ - -// Qt includes -#include <QStringList> - -class Flag -{ - public: - enum - { - Off, - On, - Ignore, - End - }; - static const QStringList ValueStr; - - Flag(const int flag = 0, const int status = Off); - - void set(const int flag, const int status); - void setFlag(const int flag); - void setStatus(const int status); - - int flag() const; - int status() const; - - inline Flag& operator=(const Flag& rhs) - { - if (this == &rhs) - return *this; - m_flag = rhs.m_flag; - m_status = rhs.m_status; - return *this; - } - inline bool operator==(const Flag& rhs) const - { - return ((m_flag == rhs.m_flag) && (m_status == rhs.m_status)); - } - inline bool operator!=(const Flag& rhs) const - { - return !(*this == rhs); - } - private: - int m_flag; - int m_status; -}; - -#endif diff --git a/pokemod/GlobalScript.cpp b/pokemod/GlobalScript.cpp new file mode 100644 index 00000000..770ea269 --- /dev/null +++ b/pokemod/GlobalScript.cpp @@ -0,0 +1,102 @@ +/* + * 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/>. + */ + +// Header include +#include "GlobalScript.h" + +// Pokemod includes +#include "Pokemod.h" +#include "Script.h" + +GlobalScript::GlobalScript(const GlobalScript& globalScript) : + Object("GlobalScript", globalScript.parent(), globalScript.id()) +{ + *this = globalScript; +} + +GlobalScript::GlobalScript(const Pokemod* parent, const int id) : + Object("GlobalScript", parent, id), + m_name(""), + m_script("", "") +{ +} + +GlobalScript::GlobalScript(const GlobalScript& globalScript, const Pokemod* parent, const int id) : + Object("GlobalScript", parent, id) +{ + *this = globalScript; +} + +GlobalScript::GlobalScript(const QDomElement& xml, const Pokemod* parent, const int id) : + Object("GlobalScript", parent, id) +{ + load(xml, id); +} + +GlobalScript::~GlobalScript() +{ +} + +void GlobalScript::validate() +{ + if (m_name.isEmpty()) + emit(error("Name is empty")); +} + +void GlobalScript::load(const QDomElement& xml, int id) +{ + LOAD_ID(); + LOAD(QString, name); + LOAD(Script, script); +} + +QDomElement GlobalScript::save() const +{ + SAVE_CREATE(); + SAVE(QString, name); + SAVE(Script, script); + return xml; +} + +void GlobalScript::setName(const QString& name) +{ + CHECK(name); +} + +void GlobalScript::setScript(const Script& script) +{ + CHECK(script); +} + +QString GlobalScript::name() const +{ + return m_name; +} + +Script GlobalScript::script() const +{ + return m_script; +} + +GlobalScript& GlobalScript::operator=(const GlobalScript& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(script); + return *this; +} diff --git a/pokemod/GlobalScript.h b/pokemod/GlobalScript.h new file mode 100644 index 00000000..ae45a141 --- /dev/null +++ b/pokemod/GlobalScript.h @@ -0,0 +1,56 @@ +/* + * 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/>. + */ + +#ifndef __POKEMOD_GLOBALSCRIPT__ +#define __POKEMOD_GLOBALSCRIPT__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +// Forward declarations +class Pokemod; + +class GlobalScript : public Object +{ + Q_OBJECT + + public: + GlobalScript(const GlobalScript& globalScript); + GlobalScript(const Pokemod* parent, const int id); + GlobalScript(const GlobalScript& globalScript, const Pokemod* parent, const int id); + GlobalScript(const QDomElement& xml, const Pokemod* parent, const int id = INT_MAX); + ~GlobalScript(); + + void validate(); + + void load(const QDomElement& xml, int id = INT_MAX); + QDomElement save() const; + + void setName(const QString& name); + void setScript(const Script& script); + + QString name() const; + Script script() const; + + GlobalScript& operator=(const GlobalScript& rhs); + private: + QString m_name; + Script m_script; +}; + +#endif diff --git a/pokemod/Item.cpp b/pokemod/Item.cpp index 22ee013a..ddba2d68 100644 --- a/pokemod/Item.cpp +++ b/pokemod/Item.cpp @@ -19,7 +19,6 @@ #include "Item.h" // Pokemod includes -#include "ItemEffect.h" #include "Pokemod.h" #include "Rules.h" @@ -38,7 +37,8 @@ Item::Item(const Pokemod* parent, const int id) : m_sellable(false), m_type(INT_MAX), m_price(0), - m_description("") + m_description(""), + m_script("", "") { } @@ -56,7 +56,6 @@ Item::Item(const QDomElement& xml, const Pokemod* parent, const int id) : Item::~Item() { - clear(); } void Item::validate() @@ -65,16 +64,6 @@ void Item::validate() emit(error("Name is empty")); TEST(setType, type); TEST(setPrice, price); - if (!effectCount()) - emit(error("There are no effects")); - QSet<int> idChecker; - foreach (ItemEffect* effect, m_effects) - { - effect->validate(); - if (idChecker.contains(effect->id())) - emit(error(subclass("effect", effect->id()))); - idChecker.insert(effect->id()); - } } void Item::load(const QDomElement& xml, int id) @@ -85,7 +74,7 @@ void Item::load(const QDomElement& xml, int id) LOAD(int, type); LOAD(int, price); LOAD(QString, description); - LOAD_SUB(newEffect, ItemEffect); + LOAD(Script, script); } QDomElement Item::save() const @@ -96,7 +85,7 @@ QDomElement Item::save() const SAVE(int, type); SAVE(int, price); SAVE(QString, description); - SAVE_SUB(ItemEffect, effects); + SAVE(Script, script); return xml; } @@ -135,6 +124,11 @@ void Item::setDescription(const QString& description) CHECK(description); } +void Item::setScript(const Script& script) +{ + CHECK(script); +} + QString Item::name() const { return m_name; @@ -160,103 +154,20 @@ QString Item::description() const return m_description; } -const ItemEffect* Item::effect(const int index) const -{ - if (effectCount() <= index) - return NULL; - return m_effects.at(index); -} - -ItemEffect* Item::effect(const int index) -{ - if (effectCount() <= index) - return NULL; - return m_effects[index]; -} - -const ItemEffect* Item::effectById(const int id) const -{ - return effect(effectIndex(id)); -} - -ItemEffect* Item::effectById(const int id) -{ - return effect(effectIndex(id)); -} - -int Item::effectIndex(const int id) const -{ - for (int i = 0; i < effectCount(); ++i) - { - if (m_effects[i]->id() == id) - return i; - } - return INT_MAX; -} - -int Item::effectCount() const +Script Item::script() const { - return m_effects.size(); -} - -ItemEffect* Item::newEffect() -{ - return newEffect(new ItemEffect(this, effectId())); -} - -ItemEffect* Item::newEffect(const QDomElement& xml) -{ - return newEffect(new ItemEffect(xml, this, effectId())); -} - -ItemEffect* Item::newEffect(const ItemEffect& effect) -{ - return newEffect(new ItemEffect(effect, this, effectId())); -} - -ItemEffect* Item::newEffect(ItemEffect* effect) -{ - m_effects.append(effect); - return effect; -} - -void Item::deleteEffect(const int index) -{ - if (effectCount() <= index) - return; - delete m_effects[index]; - m_effects.removeAt(index); -} - -void Item::deleteEffectById(const int id) -{ - deleteEffect(effectIndex(id)); -} - -int Item::effectId() const -{ - int i = 0; - while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) - ++i; - return i; + return m_script; } Item& Item::operator=(const Item& rhs) { if (this == &rhs) return *this; - clear(); COPY(name); COPY(sellable); COPY(type); COPY(price); COPY(description); - COPY_SUB(ItemEffect, effects); + COPY(script); return *this; } - -void Item::clear() -{ - while (effectCount()) - deleteEffect(0); -} diff --git a/pokemod/Item.h b/pokemod/Item.h index c70e3ae7..6d91cba9 100644 --- a/pokemod/Item.h +++ b/pokemod/Item.h @@ -20,12 +20,9 @@ // Pokemod includes #include "Object.h" - -// Qt includes -#include <QList> +#include "Script.h" // Forward declarations -class ItemEffect; class Pokemod; class Item : public Object @@ -49,38 +46,23 @@ class Item : public Object void setType(const int type); void setPrice(const int price); void setDescription(const QString& description); + void setScript(const Script& script); QString name() const; bool sellable() const; int type() const; int price() const; QString description() const; - - const ItemEffect* effect(const int index) const; - ItemEffect* effect(const int index); - const ItemEffect* effectById(const int id) const; - ItemEffect* effectById(const int id); - int effectIndex(const int id) const; - int effectCount() const; - ItemEffect* newEffect(); - ItemEffect* newEffect(const QDomElement& xml); - ItemEffect* newEffect(const ItemEffect& effect); - void deleteEffect(const int index); - void deleteEffectById(const int index); + Script script() const; Item& operator=(const Item& rhs); private: - int effectId() const; - ItemEffect* newEffect(ItemEffect* effect); - - void clear(); - QString m_name; bool m_sellable; int m_type; int m_price; QString m_description; - QList<ItemEffect*> m_effects; + Script m_script; }; #endif diff --git a/pokemod/ItemEffect.cpp b/pokemod/ItemEffect.cpp deleted file mode 100644 index 91353f3a..00000000 --- a/pokemod/ItemEffect.cpp +++ /dev/null @@ -1,610 +0,0 @@ -/* - * 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/>. - */ - -// Header include -#include "ItemEffect.h" - -// Pokemod includes -#include "Item.h" -#include "MapWildList.h" -#include "Pokemod.h" -#include "Rules.h" - -const QStringList ItemEffect::EffectStr = QStringList() << "HP Cure" << "Revive" << "Cure Status" << "Level Boost" << "Stat Boost" << "Flinch" << "Go First" << "Keep Alive" << "Modify Stat (Battle Only)" << "Shield (Battle Only)" << "Run (Battle Only)" << "PP Boost" << "Type Boost" << "PP Restore" << "Experience Share" << "Fishing Rod" << "Repel" << "Escape" << "TM" << "HM" << "Map" << "Ball" << "Itemfinder" << "Bike" << "Scope" << "Coin" << "Coin Case" << "Berry" << "Acorn"; -const QStringList ItemEffect::RelativeStr = QStringList() << "Absolute" << "Relative"; -const QStringList ItemEffect::EscapeStr = QStringList() << "Anywhere" << "Dungeon"; -const QStringList ItemEffect::RepelStr = QStringList() << "First" << "Max" << "All"; -const QStringList ItemEffect::AmountStr = QStringList() << "All" << "One"; -const QStringList ItemEffect::SpecialPhysicalStr = QStringList() << "Special" << "Physical"; -const QStringList ItemEffect::BallTypeStr = QStringList() << "Regular" << "Master" << "Level" << "Love" << "Area" << "Time" << "Battle" << "Friend" << "Stat" << "Type" << "Weight"; -const QStringList ItemEffect::BerryTypeStr = QStringList() << "HP Cure" << "Status Cure"; - -ItemEffect::ItemEffect(const ItemEffect& effect) : - Object("ItemEffect", effect.parent(), effect.id()) -{ - *this = effect; -} - -ItemEffect::ItemEffect(const Item* parent, const int id) : - Object("ItemEffect", parent, id), - m_overworld(false), - m_battle(false), - m_held(false), - m_effect(INT_MAX), - m_value1(INT_MAX), - m_value2(INT_MAX), - m_value3(INT_MAX), - m_value4(1, 1), - m_value5(INT_MAX) -{ -} - -ItemEffect::ItemEffect(const ItemEffect& effect, const Item* parent, const int id) : - Object("ItemEffect", parent, id) -{ - *this = effect; -} - -ItemEffect::ItemEffect(const QDomElement& xml, const Item* parent, const int id) : - Object("ItemEffect", parent, id) -{ - load(xml, id); -} - -void ItemEffect::validate() -{ - TEST(setOverworld, overworld); - TEST(setEffect, effect); - TEST(setValue1, value1); - TEST(setValue2, value2); - TEST(setValue3, value3); - TEST(setValue4, value4); - TEST(setValue5, value5); -} - -void ItemEffect::load(const QDomElement& xml, int id) -{ - LOAD_ID(); - LOAD(bool, overworld); - LOAD(bool, battle); - LOAD(bool, held); - LOAD(int, effect); - LOAD(int, value1); - LOAD(int, value2); - LOAD(int, value3); - LOAD(Fraction, value4); - LOAD(int, value5); -} - -QDomElement ItemEffect::save() const -{ - SAVE_CREATE(); - SAVE(bool, overworld); - SAVE(bool, battle); - SAVE(bool, held); - SAVE(int, effect); - SAVE(int, value1); - SAVE(int, value2); - SAVE(int, value3); - SAVE(Fraction, value4); - SAVE(int, value5); - return xml; -} - -void ItemEffect::setOverworld(const bool overworld) -{ - switch (m_effect) - { - case E_Revive: - case E_LevelBoost: - case E_StatBoost: - case E_PPBoost: - case E_Fish: - case E_Repel: - case E_Escape: - case E_TM: - case E_HM: - case E_Map: - case E_Itemfinder: - case E_Bike: - case E_Scope: - case E_Coin: - case E_CoinCase: - case E_Acorn: - case E_Evolution: - if (!overworld) - { - emit(error("Overworld mismatch")); - return; - } - break; - case E_Flinch: - case E_First: - case E_KeepAlive: - case E_ModifyStatBattle: - case E_ShieldBattle: - case E_RunBattle: - case E_TypeBoost: - case E_ExpShare: - case E_Ball: - case E_Berry: - if (overworld) - { - emit(error("Overworld mismatch")); - return; - } - break; - } - CHECK(overworld); -} - -void ItemEffect::setBattle(const bool battle) -{ - CHECK(battle); -} - -void ItemEffect::setHeld(const bool held) -{ - CHECK(held); -} - -void ItemEffect::setEffect(const int effect) -{ - if (E_End <= effect) - { - emit(error(bounds("effect"))); - return; - } - CHECK(effect); - switch (effect) - { - case E_Revive: - case E_LevelBoost: - case E_StatBoost: - case E_PPBoost: - case E_Fish: - case E_Repel: - case E_Escape: - case E_TM: - case E_HM: - case E_Map: - case E_Itemfinder: - case E_Bike: - case E_Scope: - case E_Coin: - case E_CoinCase: - case E_Acorn: - case E_Evolution: - setOverworld(true); - break; - case E_Flinch: - case E_First: - case E_KeepAlive: - case E_ModifyStatBattle: - case E_ShieldBattle: - case E_RunBattle: - case E_TypeBoost: - case E_ExpShare: - case E_Ball: - case E_Berry: - setOverworld(false); - break; - } -} - -void ItemEffect::setValue1(const int value1) -{ - switch (m_effect) - { - case E_HPCure: - case E_Revive: - if ((m_value4 != R_Absolute) || !value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_LevelBoost: - case E_ShieldBattle: - case E_PPBoost: - case E_Repel: - if (!value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_StatBoost: - case E_Acorn: - if ((value1 < 0) || (65536 <= value1)) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_ModifyStatBattle: - if ((value1 < -12) || (12 < value1)) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_Fish: - case E_Coin: - case E_CoinCase: - break; - case E_Ball: - switch (m_value2) - { - case B_Regular: - if (256 <= value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case B_Level: - if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case B_Master: - case B_Love: - case B_Area: - case B_Time: - case B_Battle: - case B_Friend: - case B_Stat: - case B_Type: - case B_Weight: - break; - default: - emit(error(bounds("value1"))); - return; - } - break; - default: - emit(warning(unused("value1"))); - return; - } - CHECK(value1); -} - -void ItemEffect::setValue2(const int value2) -{ - switch (m_effect) - { - case E_HPCure: - case E_Revive: - if (R_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_CureStatus: - if (Pokemod::STS_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_ModifyStatBattle: - if (Pokemod::ST_End_Battle <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_ShieldBattle: - if (SP_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_TypeBoost: - if (static_cast<const Pokemod*>(pokemod())->typeIndex(value2) == INT_MAX) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_PPRestore: - if (A_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_Repel: - if (RP_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_Escape: - if (ES_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_TM: - case E_HM: - if (static_cast<const Pokemod*>(pokemod())->moveIndex(value2) == INT_MAX) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_Ball: - if (B_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_Berry: - if (B2_End <= value2) - { - emit(error(bounds("value2"))); - return; - } - break; - case E_Acorn: - if (static_cast<const Pokemod*>(pokemod())->itemIndex(value2) == INT_MAX) - { - emit(error(bounds("value2"))); - return; - } - break; - default: - emit(warning(unused("value2"))); - return; - } - CHECK(value2); -} - -void ItemEffect::setValue3(const int value3) -{ - switch (m_effect) - { - case E_StatBoost: - if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3) - { - emit(error(bounds("value3"))); - return; - } - break; - case E_Ball: - switch (m_value2) - { - case B_Level: - case B_Friend: - case B_Weight: - // TODO: ??? - break; - case B_Area: - if (MapWildList::End <= value3) - { - emit(error(bounds("value3"))); - return; - } - break; - case B_Time: - if (static_cast<const Pokemod*>(pokemod())->timeIndex(value3) == INT_MAX) - { - emit(error(bounds("value3"))); - return; - } - break; - case B_Stat: - if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3) - { - emit(error(bounds("value3"))); - return; - } - break; - case B_Type: - if (static_cast<const Pokemod*>(pokemod())->typeIndex(value3) == INT_MAX) - { - emit(error(bounds("value3"))); - return; - } - break; - case B_Regular: - case B_Master: - case B_Love: - case B_Battle: - emit(warning(unused("value3"))); - return; - } - break; - case E_Berry: - switch (m_value2) - { - case B2_HPCure: - if (Pokemod::REL_End <= value3) - { - emit(error(bounds("value3"))); - return; - } - break; - case B2_StatusCure: - if (Pokemod::STS_End <= value3) - { - emit(error(bounds("value3"))); - return; - } - break; - default: - emit(warning(unused("value3"))); - return; - } - break; - default: - emit(warning(unused("value3"))); - return; - } - CHECK(value3); -} - -void ItemEffect::setValue4(const Fraction& value4) -{ - if ((E_TypeBoost == m_effect) || (E_PPBoost == m_effect)) - { - if (value4 < 1) - { - emit(error(bounds("value4"))); - return; - } - } - else if (1 < value4) - { - emit(error(bounds("value4"))); - return; - } - switch (m_effect) - { - case E_CureStatus: - case E_LevelBoost: - case E_StatBoost: - case E_ModifyStatBattle: - case E_Fish: - case E_Escape: - case E_TM: - case E_HM: - case E_Map: - case E_Itemfinder: - case E_Bike: - case E_Scope: - case E_Coin: - case E_CoinCase: - case E_Acorn: - case E_Evolution: - emit(warning(unused("value4"))); - return; - case E_Ball: - if (m_value2 == B_Master) - { - emit(warning(unused("value4"))); - return; - } - break; - case E_Berry: - if (m_value2 != B2_HPCure) - { - emit(warning(unused("value4"))); - return; - } - break; - } - CHECK(value4); -} - -void ItemEffect::setValue5(const int value5) -{ - switch (m_effect) - { - case E_StatBoost: - if ((value5 <= 5) || (65536 <= value5)) - { - emit(error(bounds("value5"))); - return; - } - break; - case E_Scope: - break; - case E_Coin: - case E_CoinCase: - if (value5 <= 0) - { - emit(error(bounds("value5"))); - return; - } - break; - default: - emit(error(unused("value5"))); - return; - } - CHECK(value5); -} - -bool ItemEffect::overworld() const -{ - return m_overworld; -} - -bool ItemEffect::battle() const -{ - return m_battle; -} - -bool ItemEffect::held() const -{ - return m_held; -} - -int ItemEffect::effect() const -{ - return m_effect; -} - -int ItemEffect::value1() const -{ - return m_value1; -} - -int ItemEffect::value2() const -{ - return m_value2; -} - -int ItemEffect::value3() const -{ - return m_value3; -} - -Fraction ItemEffect::value4() const -{ - return m_value4; -} - -int ItemEffect::value5() const -{ - return m_value5; -} - -ItemEffect& ItemEffect::operator=(const ItemEffect& rhs) -{ - if (this == &rhs) - return *this; - COPY(overworld); - COPY(battle); - COPY(held); - COPY(effect); - COPY(value1); - COPY(value2); - COPY(value3); - COPY(value4); - COPY(value5); - return *this; -} diff --git a/pokemod/ItemEffect.h b/pokemod/ItemEffect.h deleted file mode 100644 index b1799609..00000000 --- a/pokemod/ItemEffect.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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/>. - */ - -#ifndef __POKEMOD_ITEMEFFECT__ -#define __POKEMOD_ITEMEFFECT__ - -// Pokemod include -#include "Fraction.h" -#include "Object.h" - -// Qt includes -#include <QStringList> - -// Forward declarations -class Item; - -class ItemEffect : public Object -{ - Q_OBJECT - - public: - enum Effect - { - E_HPCure = 0, - E_Revive = 1, - E_CureStatus = 2, - E_LevelBoost = 3, - E_StatBoost = 4, - E_Flinch = 5, - E_First = 6, - E_KeepAlive = 7, - E_ModifyStatBattle = 8, - E_ShieldBattle = 9, - E_RunBattle = 10, - E_PPBoost = 11, - E_TypeBoost = 12, - E_PPRestore = 13, - E_ExpShare = 14, - E_Fish = 15, - E_Repel = 16, - E_Escape = 17, - E_TM = 18, - E_HM = 19, - E_Map = 20, - E_Ball = 21, - E_Itemfinder = 22, - E_Bike = 23, - E_Scope = 24, - E_Coin = 25, - E_CoinCase = 26, - E_Berry = 27, - E_Acorn = 28, - E_Evolution = 29, - E_End = 30 - }; - static const QStringList EffectStr; - - enum Relative - { - R_Absolute = 0, - R_Relative = 1, - R_End = 2 - }; - static const QStringList RelativeStr; - - enum Escape - { - ES_Anywhere = 0, - ES_Dungeon = 1, - ES_End = 2 - }; - static const QStringList EscapeStr; - - enum Repel - { - RP_First = 0, - RP_Max = 1, - RP_All = 2, - RP_End = 3 - }; - static const QStringList RepelStr; - - enum Amount - { - A_All = 0, - A_One = 1, - A_End = 2 - }; - static const QStringList AmountStr; - - enum SpecialPhysical - { - SP_Special = 0, - SP_Physical = 1, - SP_End = 2 - }; - static const QStringList SpecialPhysicalStr; - - enum BallType - { - B_Regular = 0, - B_Master = 1, - B_Level = 2, - B_Love = 3, - B_Area = 4, - B_Time = 5, - B_Battle = 6, - B_Friend = 7, - B_Stat = 8, - B_Type = 9, - B_Weight = 10, - B_End = 11 - }; - static const QStringList BallTypeStr; - - enum BerryType - { - B2_HPCure = 0, - B2_StatusCure = 1, - B2_End = 2 - }; - static const QStringList BerryTypeStr; - - ItemEffect(const ItemEffect& effect); - ItemEffect(const Item* parent, const int id); - ItemEffect(const ItemEffect& effect, const Item* parent, const int id); - ItemEffect(const QDomElement& xml, const Item* parent, const int id = INT_MAX); - - void validate(); - - void load(const QDomElement& xml, int id = INT_MAX); - QDomElement save() const; - - void setOverworld(const bool overworld); - void setBattle(const bool battle); - void setHeld(const bool held); - void setEffect(const int effect); - void setValue1(const int value1); - void setValue2(const int value2); - void setValue3(const int value3); - void setValue4(const Fraction& value4); - void setValue5(const int value5); - - bool overworld() const; - bool battle() const; - bool held() const; - int effect() const; - int value1() const; - int value2() const; - int value3() const; - Fraction value4() const; - int value5() const; - - ItemEffect& operator=(const ItemEffect& rhs); - private: - bool m_overworld; - bool m_battle; - bool m_held; - int m_effect; - int m_value1; - int m_value2; - int m_value3; - Fraction m_value4; - int m_value5; -}; - -#endif diff --git a/pokemod/MapEffect.cpp b/pokemod/MapEffect.cpp index ea4acd1b..73593d22 100644 --- a/pokemod/MapEffect.cpp +++ b/pokemod/MapEffect.cpp @@ -19,16 +19,12 @@ #include "MapEffect.h" // Pokemod includes -#include "Dialog.h" #include "Map.h" #include "Pokemod.h" // Qt includes #include <QBuffer> -const QStringList MapEffect::EffectStr = QStringList() << "Item" << "PC" << "Strength Block" << "Button" << "Slot Machine" << "Card Flip Game"; -const QStringList MapEffect::PCTypeStr = QStringList() << "Item" << "Pokémon" << "PokéDex" << "Hall of Fame" << "All"; - MapEffect::MapEffect(const MapEffect& effect) : Object("MapEffect", effect.parent(), effect.id()) { @@ -39,15 +35,9 @@ MapEffect::MapEffect(const Map* parent, const int id) : Object("MapEffect", parent, id), m_name(""), m_coordinate(0, 0), - m_existFlag(0, 0), m_skin(192, 128), - m_effect(INT_MAX), - m_value1(INT_MAX), - m_value2(INT_MAX), - m_direction(INT_MAX), m_isGhost(false), - m_canMove(false), - m_dialog(INT_MAX) + m_script("", "") { } @@ -69,11 +59,6 @@ void MapEffect::validate() emit(error("Name is empty")); TEST(setCoordinate, coordinate); TEST(setSkin, skin); - TEST(setEffect, effect); - TEST(setValue1, value1); - TEST(setValue2, value2); - TEST(setDirection, direction); - TEST(setDialog, dialog); } void MapEffect::load(const QDomElement& xml, int id) @@ -81,15 +66,9 @@ void MapEffect::load(const QDomElement& xml, int id) LOAD_ID(); LOAD(QString, name); LOAD(Point, coordinate); - LOAD(Flag, existFlag); LOAD(QPixmap, skin); - LOAD(int, effect); - LOAD(int, value1); - LOAD(int, value2); - LOAD(int, direction); LOAD(bool, isGhost); - LOAD(bool, canMove); - LOAD(int, dialog); + LOAD(Script, script); } QDomElement MapEffect::save() const @@ -97,15 +76,9 @@ QDomElement MapEffect::save() const SAVE_CREATE(); SAVE(QString, name); SAVE(Point, coordinate); - SAVE(Flag, existFlag); SAVE(QPixmap, skin); - SAVE(int, effect); - SAVE(int, value1); - SAVE(int, value2); - SAVE(int, direction); SAVE(bool, isGhost); - SAVE(bool, canMove); - SAVE(int, dialog); + SAVE(Script, script); return xml; } @@ -124,11 +97,6 @@ void MapEffect::setCoordinate(const Point& coordinate) CHECK(coordinate); } -void MapEffect::setExistFlag(const Flag& existFlag) -{ - CHECK(existFlag); -} - void MapEffect::setSkin(const QPixmap& skin) { if (skin.size() != QSize(192, 128)) @@ -140,87 +108,14 @@ void MapEffect::setSkin(const QPixmap& skin) emit(changed()); } -void MapEffect::setEffect(const int effect) -{ - if (E_End <= effect) - { - emit(error(bounds("effect"))); - return; - } - CHECK(effect); -} - -void MapEffect::setValue1(const int value1) -{ - if ((m_effect != E_Button) && (m_effect != E_StrengthBlock)) - { - emit(warning(unused("val1"))); - return; - } - CHECK(value1); -} - -void MapEffect::setValue2(const int value2) -{ - switch (m_effect) - { - case E_Item: - if (static_cast<const Pokemod*>(pokemod())->itemIndex(value2) == INT_MAX) - { - emit(error(bounds("val2"))); - return; - } - break; - case E_PC: - if (PC_End <= value2) - { - emit(error(bounds("val2"))); - return; - } - break; - case E_StrengthBlock: - case E_Button: - if (Flag::End <= value2) - { - emit(error(bounds("val2"))); - return; - } - break; - default: - emit(warning(unused("val2"))); - return; - } - CHECK(value2); -} - -void MapEffect::setDirection(const int direction) -{ - if (Pokemod::D_End_None <= direction) - { - emit(error(bounds("direction"))); - return; - } - CHECK(direction); -} - void MapEffect::setIsGhost(const bool isGhost) { CHECK(isGhost); } -void MapEffect::setCanMove(const bool canMove) -{ - CHECK(canMove); -} - -void MapEffect::setDialog(const int dialog) +void MapEffect::setScript(const Script& script) { - if (static_cast<const Pokemod*>(pokemod())->dialogIndex(dialog) == INT_MAX) - { - emit(error(bounds("dialog"))); - return; - } - CHECK(dialog); + CHECK(script); } QString MapEffect::name() const @@ -233,49 +128,19 @@ Point MapEffect::coordinate() const return m_coordinate; } -Flag MapEffect::existFlag() const -{ - return m_existFlag; -} - QPixmap MapEffect::skin() const { return m_skin; } -int MapEffect::effect() const -{ - return m_effect; -} - -int MapEffect::value1() const -{ - return m_value1; -} - -int MapEffect::value2() const -{ - return m_value2; -} - -int MapEffect::direction() const -{ - return m_direction; -} - bool MapEffect::isGhost() const { return m_isGhost; } -bool MapEffect::canMove() const -{ - return m_canMove; -} - -int MapEffect::dialog() const +Script MapEffect::script() const { - return m_dialog; + return m_script; } MapEffect& MapEffect::operator=(const MapEffect& rhs) @@ -284,14 +149,8 @@ MapEffect& MapEffect::operator=(const MapEffect& rhs) return *this; COPY(name); COPY(coordinate); - COPY(existFlag); COPY(skin); - COPY(effect); - COPY(value1); - COPY(value2); - COPY(direction); COPY(isGhost); - COPY(canMove); - COPY(dialog); + COPY(script); return *this; } diff --git a/pokemod/MapEffect.h b/pokemod/MapEffect.h index 1d84d09e..4e956add 100644 --- a/pokemod/MapEffect.h +++ b/pokemod/MapEffect.h @@ -19,9 +19,9 @@ #define __POKEMOD_MAPEFFECT__ // Pokemod includes -#include "Flag.h" #include "Object.h" #include "Point.h" +#include "Script.h" // Qt includes #include <QPixmap> @@ -34,29 +34,6 @@ class MapEffect : public Object Q_OBJECT public: - enum Effect - { - E_Item = 0, - E_PC = 1, - E_StrengthBlock = 2, - E_Button = 3, - E_SlotMachine = 4, - E_CardFlipGame = 5, - E_End = 6 - }; - static const QStringList EffectStr; - - enum PC - { - PC_Item = 0, - PC_Pokemon = 1, - PC_Pokedex = 2, - PC_HallOfFame = 3, - PC_All = 4, - PC_End = 5, - }; - static const QStringList PCTypeStr; - MapEffect(const MapEffect& effect); MapEffect(const Map* parent, const int id); MapEffect(const MapEffect& effect, const Map* parent, const int id); @@ -69,41 +46,23 @@ class MapEffect : public Object void setName(const QString& name); void setCoordinate(const Point& coordinate); - void setExistFlag(const Flag& existFlag); void setSkin(const QPixmap& skin); - void setEffect(const int effect); - void setValue1(const int value1); - void setValue2(const int value2); - void setDirection(const int direction); void setIsGhost(const bool isGhost); - void setCanMove(const bool canMove); - void setDialog(const int dialog); + void setScript(const Script& script); QString name() const; Point coordinate() const; - Flag existFlag() const; QPixmap skin() const; - int effect() const; - int value1() const; - int value2() const; - int direction() const; bool isGhost() const; - bool canMove() const; - int dialog() const; + Script script() const; MapEffect& operator=(const MapEffect& rhs); private: QString m_name; Point m_coordinate; - Flag m_existFlag; QPixmap m_skin; - int m_effect; - int m_value1; - int m_value2; - int m_direction; bool m_isGhost; - bool m_canMove; - int m_dialog; + Script m_script; }; #endif diff --git a/pokemod/MapTrainer.cpp b/pokemod/MapTrainer.cpp index 3bba2093..8b679960 100644 --- a/pokemod/MapTrainer.cpp +++ b/pokemod/MapTrainer.cpp @@ -19,7 +19,6 @@ #include "MapTrainer.h" // Pokemod includes -#include "Dialog.h" #include "Map.h" #include "MapTrainerTeamMember.h" #include "Pokemod.h" @@ -39,11 +38,8 @@ MapTrainer::MapTrainer(const Map* parent, const int id) : m_name(""), m_trainerClass(INT_MAX), m_coordinate(0, 0), - m_sight(0), - m_direction(INT_MAX), m_numberFight(1), - m_appearFlag(0, 0), - m_dialog(INT_MAX), + m_script("", ""), m_leadTeamMember(INT_MAX) { } @@ -71,9 +67,7 @@ void MapTrainer::validate() emit(error("Name is empty")); TEST(setTrainerClass, trainerClass); TEST(setCoordinate, coordinate); - TEST(setDirection, direction); TEST(setNumberFight, numberFight); - TEST(setDialog, dialog); TEST(setLeadTeamMember, leadTeamMember); if (!teamMemberCount()) emit(error("There are no team members")); @@ -93,11 +87,8 @@ void MapTrainer::load(const QDomElement& xml, int id) LOAD(QString, name); LOAD(int, trainerClass); LOAD(Point, coordinate); - LOAD(int, sight); - LOAD(int, direction); LOAD(int, numberFight); - LOAD(Flag, appearFlag); - LOAD(int, dialog); + LOAD(Script, script); LOAD_SUB(newTeamMember, MapTrainerTeamMember); LOAD(int, leadTeamMember); } @@ -108,11 +99,8 @@ QDomElement MapTrainer::save() const SAVE(QString, name); SAVE(int, trainerClass); SAVE(Point, coordinate); - SAVE(int, sight); - SAVE(int, direction); SAVE(int, numberFight); - SAVE(Flag, appearFlag); - SAVE(int, dialog); + SAVE(Script, script); SAVE_SUB(MapTrainerTeamMember, teamMember); return xml; } @@ -142,21 +130,6 @@ void MapTrainer::setCoordinate(const Point& coordinate) CHECK(coordinate); } -void MapTrainer::setSight(const int sight) -{ - CHECK(sight); -} - -void MapTrainer::setDirection(const int direction) -{ - if (Pokemod::D_End_None <= direction) - { - emit(error(bounds("direction"))); - return; - } - CHECK(direction); -} - void MapTrainer::setNumberFight(const int numberFight) { if (!numberFight || (static_cast<const Pokemod*>(pokemod())->rules()->maxFight() < numberFight)) @@ -167,19 +140,9 @@ void MapTrainer::setNumberFight(const int numberFight) CHECK(numberFight); } -void MapTrainer::setAppearFlag(const Flag& appearFlag) -{ - CHECK(appearFlag); -} - -void MapTrainer::setDialog(const int dialog) +void MapTrainer::setScript(const Script& script) { - if (static_cast<const Pokemod*>(pokemod())->dialogIndex(dialog) == INT_MAX) - { - emit(error(bounds("dialog"))); - return; - } - CHECK(dialog); + CHECK(script); } void MapTrainer::setLeadTeamMember(const int leadTeamMember) @@ -207,29 +170,14 @@ Point MapTrainer::coordinate() const return m_coordinate; } -int MapTrainer::sight() const -{ - return m_sight; -} - -int MapTrainer::direction() const -{ - return m_direction; -} - int MapTrainer::numberFight() const { return m_numberFight; } -Flag MapTrainer::appearFlag() const -{ - return m_appearFlag; -} - -int MapTrainer::dialog() const +Script MapTrainer::script() const { - return m_dialog; + return m_script; } int MapTrainer::leadTeamMember() const @@ -326,11 +274,8 @@ MapTrainer& MapTrainer::operator=(const MapTrainer& rhs) COPY(name); COPY(trainerClass); COPY(coordinate); - COPY(sight); - COPY(direction); COPY(numberFight); - COPY(appearFlag); - COPY(dialog); + COPY(script); COPY(leadTeamMember); COPY_SUB(MapTrainerTeamMember, teamMember); return *this; diff --git a/pokemod/MapTrainer.h b/pokemod/MapTrainer.h index fc36e9b5..0b25ae7f 100644 --- a/pokemod/MapTrainer.h +++ b/pokemod/MapTrainer.h @@ -19,9 +19,9 @@ #define __POKEMOD_MAPTRAINER__ // Pokemod includes -#include "Flag.h" #include "Object.h" #include "Point.h" +#include "Script.h" // Qt includes #include <QList> @@ -49,21 +49,15 @@ class MapTrainer : public Object void setName(const QString& name); void setTrainerClass(const int trainerClass); void setCoordinate(const Point& coordinate); - void setSight(const int sight); - void setDirection(const int direction); void setNumberFight(const int numberFight); - void setAppearFlag(const Flag& appearFlag); - void setDialog(const int dialog); + void setScript(const Script& script); void setLeadTeamMember(const int leadTeamMember); QString name() const; int trainerClass() const; Point coordinate() const; - int sight() const; - int direction() const; int numberFight() const; - Flag appearFlag() const; - int dialog() const; + Script script() const; int leadTeamMember() const; const MapTrainerTeamMember* teamMember(const int index) const; @@ -88,11 +82,8 @@ class MapTrainer : public Object QString m_name; int m_trainerClass; Point m_coordinate; - int m_sight; - int m_direction; int m_numberFight; - Flag m_appearFlag; - int m_dialog; + Script m_script; int m_leadTeamMember; QList<MapTrainerTeamMember*> m_teamMember; }; diff --git a/pokemod/MapWarp.cpp b/pokemod/MapWarp.cpp index aca804da..e206bc15 100644 --- a/pokemod/MapWarp.cpp +++ b/pokemod/MapWarp.cpp @@ -19,7 +19,6 @@ #include "MapWarp.h" // Pokemod includes -#include "Dialog.h" #include "Map.h" #include "Pokemod.h" @@ -35,18 +34,11 @@ MapWarp::MapWarp(const Map* parent, const int id) : Object("MapWarp", parent, id), m_name(""), m_coordinate(0, 0), - m_directionOut(INT_MAX), m_type(INT_MAX), - m_isBiking(Flag::Ignore), - m_isFlash(Flag::Ignore), - m_isFoggy(Flag::Ignore), m_toMap(INT_MAX), m_toWarp(INT_MAX), - m_workingFlag(0, 0), - m_dialog(INT_MAX) + m_script("", "") { - for (int i = 0; i < Pokemod::D_End; ++i) - m_from[i] = false; } MapWarp::MapWarp(const MapWarp& warp, const Map* parent, const int id) : @@ -65,13 +57,9 @@ void MapWarp::validate() { if (m_name.isEmpty()) emit(error("Name is empty")); - if (!m_from[Pokemod::D_Up] && !m_from[Pokemod::D_Down] && !m_from[Pokemod::D_Left] && !m_from[Pokemod::D_Right]) - emit(error("No access from any direction")); - TEST(setDirectionOut, directionOut); TEST(setType, type); TEST(setToMap, toMap); TEST(setToWarp, toWarp); - TEST(setDialog, dialog); } void MapWarp::load(const QDomElement& xml, int id) @@ -79,16 +67,10 @@ void MapWarp::load(const QDomElement& xml, int id) LOAD_ID(); LOAD(QString, name); LOAD(Point, coordinate); - LOAD_ARRAY(bool, from, Pokemod::D_End); - LOAD(int, directionOut); LOAD(int, type); - LOAD(bool, isBiking); - LOAD(bool, isFlash); - LOAD(bool, isFoggy); LOAD(int, toMap); LOAD(int, toWarp); - LOAD(Flag, workingFlag); - LOAD(int, dialog); + LOAD(Script, script); } QDomElement MapWarp::save() const @@ -96,16 +78,10 @@ QDomElement MapWarp::save() const SAVE_CREATE(); SAVE(QString, name); SAVE(Point, coordinate); - SAVE_ARRAY(bool, from, Pokemod::D_End); - SAVE(int, directionOut); SAVE(int, type); - SAVE(bool, isBiking); - SAVE(bool, isFlash); - SAVE(bool, isFoggy); SAVE(int, toMap); SAVE(int, toWarp); - SAVE(Flag, workingFlag); - SAVE(int, dialog); + SAVE(Script, script); return xml; } @@ -124,26 +100,6 @@ void MapWarp::setCoordinate(const Point& coordinate) CHECK(coordinate); } -void MapWarp::setFrom(const int direction, const bool can) -{ - if (Pokemod::D_End <= direction) - { - emit(error(bounds("direction"))); - return; - } - CHECK_ARRAY(from[direction], can); -} - -void MapWarp::setDirectionOut(const int directionOut) -{ - if (Pokemod::D_End <= directionOut) - { - emit(error(bounds("direction"))); - return; - } - CHECK(directionOut); -} - void MapWarp::setType(const int type) { if (End <= type) @@ -154,36 +110,6 @@ void MapWarp::setType(const int type) CHECK(type); } -void MapWarp::setIsBiking(const int isBiking) -{ - if (Flag::End <= isBiking) - { - emit(error(bounds("isBiking"))); - return; - } - CHECK(isBiking); -} - -void MapWarp::setIsFlash(const int isFlash) -{ - if (Flag::End <= isFlash) - { - emit(error(bounds("isFlash"))); - return; - } - CHECK(isFlash); -} - -void MapWarp::setIsFoggy(const int isFoggy) -{ - if (Flag::End <= isFoggy) - { - emit(error(bounds("isFoggy"))); - return; - } - CHECK(isFoggy); -} - void MapWarp::setToMap(const int toMap) { if (static_cast<const Pokemod*>(pokemod())->mapIndex(toMap) == INT_MAX) @@ -209,19 +135,9 @@ void MapWarp::setToWarp(const int toWarp) CHECK(toWarp); } -void MapWarp::setWorkingFlag(const Flag& workingFlag) +void MapWarp::setScript(const Script& script) { - CHECK(workingFlag); -} - -void MapWarp::setDialog(const int dialog) -{ - if (static_cast<const Pokemod*>(pokemod())->dialogIndex(dialog) == INT_MAX) - { - emit(error(bounds("dialog"))); - return; - } - CHECK(dialog); + CHECK(script); } QString MapWarp::name() const @@ -234,41 +150,11 @@ Point MapWarp::coordinate() const return m_coordinate; } -bool MapWarp::from(const int direction) const -{ - if (Pokemod::D_End <= direction) - { - emit(warning(bounds("direction"))); - return false; - } - return m_from[direction]; -} - -int MapWarp::directionOut() const -{ - return m_directionOut; -} - int MapWarp::type() const { return m_type; } -int MapWarp::isBiking() const -{ - return m_isBiking; -} - -int MapWarp::isFlash() const -{ - return m_isFlash; -} - -int MapWarp::isFoggy() const -{ - return m_isFoggy; -} - int MapWarp::toMap() const { return m_toMap; @@ -279,14 +165,9 @@ int MapWarp::toWarp() const return m_toWarp; } -Flag MapWarp::workingFlag() const -{ - return m_workingFlag; -} - -int MapWarp::dialog() const +Script MapWarp::script() const { - return m_dialog; + return m_script; } MapWarp& MapWarp::operator=(const MapWarp& rhs) @@ -295,15 +176,9 @@ MapWarp& MapWarp::operator=(const MapWarp& rhs) return *this; COPY(name); COPY(coordinate); - COPY_ARRAY(from, Pokemod::D_End); - COPY(directionOut); COPY(type); - COPY(isBiking); - COPY(isFlash); - COPY(isFoggy); COPY(toMap); COPY(toWarp); - COPY(workingFlag); - COPY(dialog); + COPY(script); return *this; } diff --git a/pokemod/MapWarp.h b/pokemod/MapWarp.h index 6395e3ef..2187fb0e 100644 --- a/pokemod/MapWarp.h +++ b/pokemod/MapWarp.h @@ -19,10 +19,10 @@ #define __POKEMOD_MAPWARP__ // Pokemod includes -#include "Flag.h" #include "Object.h" #include "Point.h" #include "Pokemod.h" +#include "Script.h" class MapWarp : public Object { @@ -51,44 +51,26 @@ class MapWarp : public Object void setName(const QString& name); void setCoordinate(const Point& coordinate); - void setFrom(const int direction, const bool can); - void setDirectionOut(const int directionOut); void setType(const int type); - void setIsBiking(const int isBiking); - void setIsFlash(const int isFlash); - void setIsFoggy(const int isFoggy); void setToMap(const int toMap); void setToWarp(const int toWarp); - void setWorkingFlag(const Flag& workingFlag); - void setDialog(const int dialog); + void setScript(const Script& script); QString name() const; Point coordinate() const; - bool from(const int d) const; - int directionOut() const; int type() const; - int isBiking() const; - int isFlash() const; - int isFoggy() const; int toMap() const; int toWarp() const; - Flag workingFlag() const; - int dialog() const; + Script script() const; MapWarp& operator=(const MapWarp& rhs); private: QString m_name; Point m_coordinate; - bool m_from[Pokemod::D_End]; - int m_directionOut; int m_type; - int m_isBiking; - int m_isFlash; - int m_isFoggy; int m_toMap; int m_toWarp; - Flag m_workingFlag; - int m_dialog; + Script m_script; }; #endif diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp index df47e517..b9fec1f1 100644 --- a/pokemod/MapWildList.cpp +++ b/pokemod/MapWildList.cpp @@ -20,7 +20,6 @@ // Pokemod includes #include "Item.h" -#include "ItemEffect.h" #include "Map.h" #include "MapWildListEncounter.h" #include "Pokemod.h" @@ -39,8 +38,7 @@ MapWildList::MapWildList(const MapWildList& wildList) : MapWildList::MapWildList(const Map* parent, const int id) : Object("MapWildList", parent, id), m_control(INT_MAX), - m_value(INT_MAX), - m_scope(INT_MAX) + m_script("", "") { } @@ -64,9 +62,7 @@ MapWildList::~MapWildList() void MapWildList::validate() { TEST(setControl, control); - TEST(setValue, value); TEST_LIST(setTime, time); - TEST(setScope, scope); if (!encounterCount()) emit(error("There are no encounters")); QSet<int> idChecker; @@ -83,9 +79,8 @@ void MapWildList::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(int, control); - LOAD(int, value); + LOAD(Script, script); LOAD_LIST(int, time); - LOAD(int, scope); LOAD_SUB(newEncounter, MapWildListEncounter); } @@ -93,9 +88,8 @@ QDomElement MapWildList::save() const { SAVE_CREATE(); SAVE(int, control); - SAVE(int, value); + SAVE(Script, script); SAVE_LIST(int, time); - SAVE(int, scope); SAVE_SUB(MapWildListEncounter, encounters); return xml; } @@ -110,27 +104,9 @@ void MapWildList::setControl(const int control) CHECK(control); } -void MapWildList::setValue(const int value) +void MapWildList::setScript(const Script& script) { - if (m_control != Fishing) - { - emit(warning(unused("value"))); - return; - } - for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()); ++i) - { - const Item* item = static_cast<const Pokemod*>(pokemod())->item(i); - for (int j = 0; (j < item->effectCount()); ++j) - { - const ItemEffect* effect = item->effect(j); - if ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == value)) - { - CHECK(value); - return; - } - } - } - emit(error(bounds("value"))); + CHECK(script); } void MapWildList::setTime(const int time, const bool state) @@ -155,37 +131,14 @@ void MapWildList::setTime(const int time, const bool state) } } -void MapWildList::setScope(const int scope) -{ - if (scope != INT_MAX) - { - for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()); ++i) - { - const Item* item = static_cast<const Pokemod*>(pokemod())->item(i); - for (int j = 0; (j < item->effectCount()); ++j) - { - const ItemEffect* effect = item->effect(j); - if ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == scope)) - { - CHECK(scope); - return; - } - } - } - emit(error(bounds("value"))); - } - else - CHECK(scope); -} - int MapWildList::control() const { return m_control; } -int MapWildList::value() const +Script MapWildList::script() const { - return m_value; + return m_script; } bool MapWildList::time(const int time) const @@ -193,11 +146,6 @@ bool MapWildList::time(const int time) const return m_time.contains(time); } -int MapWildList::scope() const -{ - return m_scope; -} - const MapWildListEncounter* MapWildList::encounter(const int index) const { if (encounterCount() <= index) @@ -285,9 +233,8 @@ MapWildList& MapWildList::operator=(const MapWildList& rhs) return *this; clear(); COPY(control); - COPY(value); + COPY(script); COPY(time); - COPY(scope); COPY_SUB(MapWildListEncounter, encounters); return *this; } diff --git a/pokemod/MapWildList.h b/pokemod/MapWildList.h index 6a62e2e3..cfc06fc3 100644 --- a/pokemod/MapWildList.h +++ b/pokemod/MapWildList.h @@ -20,6 +20,7 @@ // Pokemod includes #include "Object.h" +#include "Script.h" // Qt includes #include <QList> @@ -57,14 +58,12 @@ class MapWildList : public Object QDomElement save() const; void setControl(const int control); - void setValue(const int value); + void setScript(const Script& script); void setTime(const int time, const bool state); - void setScope(const int scope); int control() const; - int value() const; + Script script() const; bool time(const int time) const; - int scope() const; const MapWildListEncounter* encounter(const int index) const; MapWildListEncounter* encounter(const int index); @@ -86,9 +85,8 @@ class MapWildList : public Object void clear(); int m_control; - int m_value; + Script m_script; QList<int> m_time; - int m_scope; QList<MapWildListEncounter*> m_encounters; }; diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index 1efccf55..3d544a6c 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -19,7 +19,6 @@ #include "Move.h" // Pokemod includes -#include "MoveEffect.h" #include "Pokemod.h" #include "Rules.h" @@ -45,13 +44,9 @@ Move::Move(const Pokemod* parent, const int id) : m_powerPoints(0), m_target(INT_MAX), m_targetChoice(INT_MAX), - m_ignoreAccuracy(false), - m_canFlinch(false), - m_canRandom(false), - m_canSnatch(false), - m_sound(false), m_priority(1), - m_description("") + m_description(""), + m_script("", "") { } @@ -81,16 +76,6 @@ void Move::validate() TEST(setTarget, target); TEST(setNumTargets, numTargets); TEST(setTargetChoice, targetChoice); - if (!effectCount()) - emit(warning("There are no effects")); - QSet<int> idChecker; - foreach (MoveEffect* effect, m_effects) - { - effect->validate(); - if (idChecker.contains(effect->id())) - emit(error(subclass("effect", effect->id()))); - idChecker.insert(effect->id()); - } } void Move::load(const QDomElement& xml, int id) @@ -104,13 +89,8 @@ void Move::load(const QDomElement& xml, int id) LOAD(int, powerPoints); LOAD(int, target); LOAD(int, targetChoice); - LOAD(bool, ignoreAccuracy); - LOAD(bool, canFlinch); - LOAD(bool, canRandom); - LOAD(bool, canSnatch); - LOAD(bool, sound); LOAD(QString, description); - LOAD_SUB(newEffect, MoveEffect); + LOAD(Script, script); } QDomElement Move::save() const @@ -125,13 +105,8 @@ QDomElement Move::save() const SAVE(int, target); SAVE(int, numTargets); SAVE(int, targetChoice); - SAVE(bool, ignoreAccuracy); - SAVE(bool, canFlinch); - SAVE(bool, canRandom); - SAVE(bool, canSnatch); - SAVE(bool, sound); SAVE(QString, description); - SAVE_SUB(MoveEffect, effects); + SAVE(Script, script); return xml; } @@ -210,34 +185,14 @@ void Move::setTargetChoice(const int targetChoice) CHECK(targetChoice); } -void Move::setIgnoreAccuracy(const bool ignoreAccuracy) -{ - CHECK(ignoreAccuracy); -} - -void Move::setCanFlinch(const bool canFlinch) -{ - CHECK(canFlinch); -} - -void Move::setCanRandom(const bool canRandom) -{ - CHECK(canRandom); -} - -void Move::setCanSnatch(const bool canSnatch) -{ - CHECK(canSnatch); -} - -void Move::setSound(const bool sound) +void Move::setDescription(const QString& description) { - CHECK(sound); + CHECK(description); } -void Move::setDescription(const QString& description) +void Move::setScript(const Script& script) { - CHECK(description); + CHECK(script); } QString Move::name() const @@ -285,122 +240,20 @@ int Move::targetChoice() const return m_targetChoice; } -bool Move::ignoreAccuracy() const -{ - return m_ignoreAccuracy; -} - -bool Move::canFlinch() const -{ - return m_canFlinch; -} - -bool Move::canRandom() const -{ - return m_canRandom; -} - -bool Move::canSnatch() const -{ - return m_canSnatch; -} - -bool Move::sound() const -{ - return m_sound; -} - QString Move::description() const { return m_description; } -const MoveEffect* Move::effect(const int index) const -{ - if (effectCount() <= index) - return NULL; - return m_effects.at(index); -} - -MoveEffect* Move::effect(const int index) -{ - if (effectCount() <= index) - return NULL; - return m_effects[index]; -} - -const MoveEffect* Move::effectById(const int id) const -{ - return effect(effectIndex(id)); -} - -MoveEffect* Move::effectById(const int id) -{ - return effect(effectIndex(id)); -} - -int Move::effectIndex(const int id) const -{ - for (int i = 0; i < effectCount(); ++i) - { - if (m_effects[i]->id() == id) - return i; - } - return INT_MAX; -} - -int Move::effectCount() const -{ - return m_effects.size(); -} - -MoveEffect* Move::newEffect() -{ - return newEffect(new MoveEffect(this, newEffectId())); -} - -MoveEffect* Move::newEffect(const QDomElement& xml) -{ - return newEffect(new MoveEffect(xml, this, newEffectId())); -} - -MoveEffect* Move::newEffect(const MoveEffect& effect) -{ - return newEffect(new MoveEffect(effect, this, newEffectId())); -} - -MoveEffect* Move::newEffect(MoveEffect* effect) +Script Move::script() const { - m_effects.append(effect); - return effect; -} - -void Move::deleteEffect(const int index) -{ - if (effectCount() <= index) - return; - delete m_effects[index]; - m_effects.removeAt(index); -} - -void Move::deleteEffectById(const int id) -{ - deleteEffect(effectIndex(id)); -} - -int Move::newEffectId() const -{ - int i = 0; - while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) - ++i; - return i; + return m_script; } Move& Move::operator=(const Move& rhs) { if (this == &rhs) return *this; - clear(); COPY(name); COPY(accuracy); COPY(power); @@ -409,19 +262,7 @@ Move& Move::operator=(const Move& rhs) COPY(powerPoints); COPY(target); COPY(numTargets); - COPY(targetChoice); - COPY(ignoreAccuracy); - COPY(canFlinch); - COPY(canRandom); - COPY(canSnatch); - COPY(sound); COPY(description); - COPY_SUB(MoveEffect, effects); + COPY(script); return *this; } - -void Move::clear() -{ - while (effectCount()) - deleteEffect(0); -} diff --git a/pokemod/Move.h b/pokemod/Move.h index c2080b7e..171c4b07 100644 --- a/pokemod/Move.h +++ b/pokemod/Move.h @@ -21,12 +21,9 @@ // Pokemod includes #include "Fraction.h" #include "Object.h" - -// Qt includes -#include <QList> +#include "Script.h" // Forward declarations -class MoveEffect; class Pokemod; class Move : public Object @@ -73,13 +70,8 @@ class Move : public Object void setTarget(const int target); void setNumTargets(const int numTargets); void setTargetChoice(const int targetChoice); - void setIgnoreAccuracy(const bool ignoreAccuracy); - void setCanFlinch(const bool canFlinch); - void setCanRandom(const bool canRandom); - void setCanSnatch(const bool canSnatch); - void setSound(const bool sound); - void setPriority(const int priority); void setDescription(const QString& description); + void setScript(const Script& script); QString name() const; Fraction accuracy() const; @@ -90,33 +82,12 @@ class Move : public Object int target() const; int numTargets() const; int targetChoice() const; - bool ignoreAccuracy() const; - bool canFlinch() const; - bool canRandom() const; - bool canSnatch() const; - bool sound() const; int priority() const; QString description() const; - - const MoveEffect* effect(const int index) const; - MoveEffect* effect(const int index); - const MoveEffect* effectById(const int id) const; - MoveEffect* effectById(const int id); - int effectIndex(const int id) const; - int effectCount() const; - MoveEffect* newEffect(); - MoveEffect* newEffect(const QDomElement& xml); - MoveEffect* newEffect(const MoveEffect& effect); - void deleteEffect(const int index); - void deleteEffectById(const int id); + Script script() const; Move& operator=(const Move& rhs); private: - int newEffectId() const; - MoveEffect* newEffect(MoveEffect* effect); - - void clear(); - QString m_name; Fraction m_accuracy; int m_power; @@ -126,14 +97,9 @@ class Move : public Object int m_target; int m_numTargets; int m_targetChoice; - bool m_ignoreAccuracy; - bool m_canFlinch; - bool m_canRandom; - bool m_canSnatch; - bool m_sound; int m_priority; QString m_description; - QList<MoveEffect*> m_effects; + Script m_script; }; #endif diff --git a/pokemod/MoveEffect.cpp b/pokemod/MoveEffect.cpp deleted file mode 100644 index 84e0e04d..00000000 --- a/pokemod/MoveEffect.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - * 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/>. - */ - -// Header include -#include "MoveEffect.h" - -// Pokemod includes -#include "Move.h" -#include "Pokemod.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 MoveEffect& effect) : - Object("MoveEffect", effect.parent(), effect.id()) -{ - *this = effect; -} - -MoveEffect::MoveEffect(const Move* parent, const int id) : - Object("MoveEffect", parent, 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 MoveEffect& effect, const Move* parent, const int id) : - Object("MoveEffect", parent, id) -{ - *this = effect; -} - -MoveEffect::MoveEffect(const QDomElement& xml, const Move* parent, const int id) : - Object("MoveEffect", parent, id) -{ - load(xml, id); -} - -void MoveEffect::validate() -{ - TEST(setChance, chance); - TEST(setEffect, effect); - TEST(setValue1, value1); - TEST(setValue2, value2); - TEST(setValue3, value3); - TEST(setValue4, value4); -} - -void MoveEffect::load(const QDomElement& xml, int id) -{ - LOAD_ID(); - LOAD(Fraction, chance); - LOAD(int, effect); - LOAD(int, value1); - LOAD(int, value2); - LOAD(int, value3); - LOAD(Fraction, value4); -} - -QDomElement MoveEffect::save() const -{ - SAVE_CREATE(); - SAVE(Fraction, chance); - SAVE(int, effect); - SAVE(int, value1); - SAVE(int, value2); - SAVE(int, value3); - SAVE(Fraction, value4); - return xml; -} - -void MoveEffect::setChance(const Fraction& chance) -{ - if (1 < chance) - { - emit(error(bounds("chance"))); - return; - } - CHECK(chance); -} - -void MoveEffect::setEffect(const int effect) -{ - if (E_End <= effect) - { - emit(error(bounds("effect"))); - return; - } - CHECK(effect); -} - -void MoveEffect::setValue1(const int value1) -{ - switch (m_effect) - { - case E_Damage: - if (D_End <= value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_Status: - case E_NeedStatus: - if (Pokemod::STS_End <= value1) - { - emit(error(bounds("value1"))); - return; - } - throw; - case E_Stat: - if (Pokemod::ST_End_Battle <= value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_Counter: - case E_Shield: - if (MT_End <= value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case E_Recoil: - if (R_End <= value1) - { - emit(error(bounds("value1"))); - return; - } - break; - default: - emit(warning(unused("value1"))); - return; - } - CHECK(value1); -} - -void MoveEffect::setValue2(const int value2) -{ - switch (m_effect) - { - case E_Damage: - if ((D_Level <= m_value1) || !value2) - { - emit(error(bounds("value2"))); - return; - } - break; - default: - emit(warning(unused("value2"))); - return; - } - CHECK(value2); -} - -void MoveEffect::setValue3(const int value3) -{ - switch (m_effect) - { - case E_Damage: - //if () - break; - } - CHECK(value3); -} - -void MoveEffect::setValue4(const Fraction& value4) -{ - if ((m_effect != E_StealHP) && (m_effect != E_Counter) && (m_effect != E_Selfdestruct) && (m_effect != E_Mirror) && (m_effect != E_GetMoney) && (m_effect != E_WaitAndReturn) && (m_effect != E_Recoil) && (1 < value4)) - { - emit(error(bounds("value4"))); - return; - } - CHECK(value4); -} - -Fraction 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; -} - -Fraction MoveEffect::value4() const -{ - return m_value4; -} - -MoveEffect& MoveEffect::operator=(const MoveEffect& rhs) -{ - if (this == &rhs) - return *this; - COPY(chance); - COPY(effect); - COPY(value1); - COPY(value2); - COPY(value3); - COPY(value4); - return *this; -} diff --git a/pokemod/MoveEffect.h b/pokemod/MoveEffect.h deleted file mode 100644 index adadaeb5..00000000 --- a/pokemod/MoveEffect.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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/>. - */ - -#ifndef __POKEMOD_MOVEEFFECT__ -#define __POKEMOD_MOVEEFFECT__ - -// Pokemod includes -#include "Fraction.h" -#include "Object.h" - -// Qt includes -#include <QStringList> - -// Forward declarations -class Move; - -class MoveEffect : public Object -{ - Q_OBJECT - - public: - enum Effect - { - E_Damage = 0, - E_Status = 1, - E_Confuse = 2, - E_Stat = 3, - E_StealHP = 4, - E_Counter = 5, - E_Selfdestruct = 6, - E_NeedStatus = 7, - E_Mirror = 8, - E_GetMoney = 9, - E_NeverMiss = 10, - E_StealTypes = 11, - E_ClearEffects = 12, - E_WaitAndReturn = 13, - E_SelfConfuse = 14, - E_ForceSwitch = 15, - E_HitMultiple = 16, - E_HitMultipleTurns = 17, - E_Flinch = 18, - E_OneHitKO = 19, - E_Recoil = 20, - E_Recover = 21, - E_Rest = 22, - E_Shield = 23, - E_Substitute = 24, - E_Recharge = 25, - E_Rage = 26, - E_Mimic = 27, - E_RandomMove = 28, - E_Seed = 29, - E_Disable = 30, - // TODO: GSC, RSEFrLg, DP effects - E_End,// = , - E_CutHM = E_End, - E_FlyHM,// = , - E_SurfHM,// = , - E_StrengthHM,// = , - E_FlashHM,// = , - E_RockSmashHM,// = , - E_RockClimbHM,// = , - E_WhirlpoolHM,// = , - E_WaterfallHM,// = , - E_ShareHPHM,// = , - E_EscapeHM,// = , - E_End_Overworld// = - }; - static const QStringList EffectStr; - - enum Damage - { - D_Fixed = 0, - D_FixedRange = 1, - D_Relative = 2, - D_RelativeRange = 3, - D_Level = 4, - D_End = 5 - }; - static const QStringList DamageStr; - - enum MoveType - { - MT_Physical = 0, - MT_Special = 1, - MT_End = 2 - }; - static const QStringList MoveTypeStr; - - enum Recoil - { - R_Hit = 0, - R_Miss = 1, - R_End = 2 - }; - static const QStringList RecoilStr; - - MoveEffect(const MoveEffect& effect); - MoveEffect(const Move* parent, const int id); - MoveEffect(const MoveEffect& effect, const Move* parent, const int id); - MoveEffect(const QDomElement& xml, const Move* parent, const int id = INT_MAX); - - void validate(); - - void load(const QDomElement& xml, int id = INT_MAX); - QDomElement save() const; - - void setChance(const Fraction& chance); - void setEffect(const int effect); - void setValue1(const int value1); - void setValue2(const int value2); - void setValue3(const int value3); - void setValue4(const Fraction& value4); - - Fraction chance() const; - int effect() const; - int value1() const; - int value2() const; - int value3() const; - Fraction value4() const; - - MoveEffect& operator=(const MoveEffect& rhs); - private: - Fraction m_chance; - int m_effect; - int m_value1; - int m_value2; - int m_value3; - Fraction m_value4; -}; - -#endif diff --git a/pokemod/Object.h b/pokemod/Object.h index de235ec8..796ba857 100644 --- a/pokemod/Object.h +++ b/pokemod/Object.h @@ -87,12 +87,12 @@ class Object : public QObject #define LOAD_int(node) LOAD_DATA(node).toInt() #define LOAD_QString LOAD_DATA #define LOAD_Fraction(node) Fraction(node.attribute("numerator", "1").toInt(), node.attribute("denominator", "1").toInt()) -#define LOAD_Flag(node) Flag(node.attribute("flag", "0").toInt(), node.attribute("status", "1").toInt()) #define LOAD_Point(node) Point(node.attribute("x", "0").toInt(), node.attribute("y", "0").toInt()) // FIXME: QPixmap::fromData static member would be nice #define LOAD_QPixmap(node) QPixmap::fromImage(QImage::fromData(QByteArray::fromBase64(LOAD_DATA(node).toUtf8()))) #define LOAD_QByteArray(node) QByteArray::fromBase64(LOAD_DATA(node).toUtf8()) #define LOAD_Rules(node) new Rules(node, this) +#define LOAD_Script(node) Script(node.attribute("interpreter", ""), LOAD_DATA(node)) #define LOAD_ARRAY(type, variable, size) \ QDomElement xml_##variable = LOAD_NODE(#variable).firstChildElement("element"); \ while (!xml_##variable.isNull()) \ @@ -149,10 +149,6 @@ class Object : public QObject Fraction frac_##variable = value; \ xml_##variable.setAttribute("numerator", frac_##variable.numerator()); \ xml_##variable.setAttribute("denominator", frac_##variable.denominator()) -#define SAVE_Flag(variable, value) \ - Flag flag_##variable = value; \ - xml_##variable.setAttribute("flag", flag_##variable.flag()); \ - xml_##variable.setAttribute("status", flag_##variable.status()) #define SAVE_Point(variable, value) \ Point point_##variable = value; \ xml_##variable.setAttribute("x", point_##variable.x()); \ @@ -165,6 +161,11 @@ class Object : public QObject SAVE_VALUE(xml_##variable, bytes_##variable.toBase64()); \ delete buffer_##variable #define SAVE_QByteArray(variable, value) SAVE_VALUE(xml_##variable, value.toBase64()) +#define SAVE_Rules(variable) xml.appendChild(m_##variable->save()) +#define SAVE_Script(variable, value) \ + Script script_##variable = value; \ + xml_##variable.setAttribute("interpreter", script_##variable.interpreter()); \ + SAVE_VALUE(xml_##variable, script_##variable.script()) #define SAVE_ARRAY(type, variable, size) \ QDomElement xml_array_##variable = QDomDocument().createElement(#variable); \ for (int i = 0; i < size; ++i) \ @@ -206,7 +207,7 @@ class Object : public QObject xml.appendChild(sub->save()) #define COPY(variable) m_##variable = rhs.m_##variable -#define COPY_RULES() *m_rules= *rhs.m_rules +#define COPY_Rules(variable) *m_##variable= *rhs.m_##variable #define COPY_ARRAY(variable, size) \ for (int i = 0; i < size; ++i) \ COPY(variable[i]) diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp index 230dae46..0f52af1f 100644 --- a/pokemod/Pokemod.cpp +++ b/pokemod/Pokemod.cpp @@ -23,8 +23,8 @@ #include "Author.h" #include "Badge.h" #include "CoinList.h" -#include "Dialog.h" #include "EggGroup.h" +#include "GlobalScript.h" #include "Item.h" #include "ItemType.h" #include "Map.h" @@ -176,16 +176,6 @@ void Pokemod::validate() } idChecker.clear(); nameChecker.clear(); - if (!dialogCount()) - emit(error("There are no dialogs")); - foreach (Dialog* dialog, m_dialogs) - { - dialog->validate(); - if (idChecker.contains(dialog->id())) - emit(error(subclass("dialog", dialog->id()))); - idChecker.insert(dialog->id()); - } - idChecker.clear(); if (m_rules->breedingAllowed()) { if (!eggGroupCount()) @@ -203,6 +193,20 @@ void Pokemod::validate() idChecker.clear(); nameChecker.clear(); } + if (!globalScriptCount()) + emit(warning("There are no global scripts")); + foreach (GlobalScript* globalScript, m_globalScripts) + { + globalScript->validate(); + if (idChecker.contains(globalScript->id())) + emit(error(subclass("global script", globalScript->id()))); + idChecker.insert(globalScript->id()); + if (nameChecker.contains(globalScript->name())) + emit(error(subclass("global script", globalScript->name()))); + nameChecker.insert(globalScript->name()); + } + idChecker.clear(); + nameChecker.clear(); if (!itemCount()) emit(warning("There are no items")); foreach (Item* item, m_items) @@ -269,6 +273,9 @@ void Pokemod::validate() if (idChecker.contains(nature->id())) emit(error(subclass("ability", nature->id()))); idChecker.insert(nature->id()); + if (nameChecker.contains(nature->name())) + emit(error(subclass("nature", nature->name()))); + nameChecker.insert(nature->name()); } idChecker.clear(); nameChecker.clear(); @@ -395,8 +402,8 @@ void Pokemod::load(const QDomElement& xml, const int) LOAD_SUB(newAuthor, Author); LOAD_SUB(newBadge, Badge); LOAD_SUB(newCoinList, CoinList); - LOAD_SUB(newDialog, Dialog); LOAD_SUB(newEggGroup, EggGroup); + LOAD_SUB(newGlobalScript, GlobalScript); LOAD_SUB(newItem, Item); LOAD_SUB(newItemType, ItemType); LOAD_SUB(newMap, Map); @@ -428,14 +435,14 @@ QDomElement Pokemod::save() const SAVE(QPixmap, surfFishSkin); SAVE(QString, superPCUname); SAVE(QString, superPCPasswd); - xml.appendChild(m_rules->save()); + SAVE_Rules(rules); SAVE_MATRIX(Fraction, typeChart); SAVE_SUB(Ability, abilities); SAVE_SUB(Author, authors); SAVE_SUB(Badge, badges); SAVE_SUB(CoinList, coinLists); - SAVE_SUB(Dialog, dialogs); SAVE_SUB(EggGroup, eggGroups); + SAVE_SUB(GlobalScript, globalScripts); SAVE_SUB(Item, items); SAVE_SUB(ItemType, itemTypes); SAVE_SUB(Map, maps); @@ -1001,164 +1008,164 @@ int Pokemod::newCoinListId() const return i; } -const Dialog* Pokemod::dialog(const int index) const +const EggGroup* Pokemod::eggGroup(const int index) const { - if (dialogCount() <= index) + if (eggGroupCount() <= index) return NULL; - return m_dialogs.at(index); + return m_eggGroups.at(index); } -Dialog* Pokemod::dialog(const int index) +EggGroup* Pokemod::eggGroup(const int index) { - if (dialogCount() <= index) + if (eggGroupCount() <= index) return NULL; - return m_dialogs[index]; + return m_eggGroups[index]; } -const Dialog* Pokemod::dialogById(const int id) const +const EggGroup* Pokemod::eggGroupById(const int id) const { - return dialog(dialogIndex(id)); + return eggGroup(eggGroupIndex(id)); } -Dialog* Pokemod::dialogById(const int id) +EggGroup* Pokemod::eggGroupById(const int id) { - return dialog(dialogIndex(id)); + return eggGroup(eggGroupIndex(id)); } -int Pokemod::dialogIndex(const int id) const +int Pokemod::eggGroupIndex(const int id) const { - for (int i = 0; i < dialogCount(); ++i) + for (int i = 0; i < eggGroupCount(); ++i) { - if (m_dialogs[i]->id() == id) + if (m_eggGroups[i]->id() == id) return i; } return INT_MAX; } -int Pokemod::dialogCount() const +int Pokemod::eggGroupCount() const { - return m_dialogs.size(); + return m_eggGroups.size(); } -Dialog* Pokemod::newDialog() +EggGroup* Pokemod::newEggGroup() { - return newDialog(new Dialog(this, newDialogId())); + return newEggGroup(new EggGroup(this, newEggGroupId())); } -Dialog* Pokemod::newDialog(const QDomElement& xml) +EggGroup* Pokemod::newEggGroup(const QDomElement& xml) { - return newDialog(new Dialog(xml, this, newDialogId())); + return newEggGroup(new EggGroup(xml, this, newEggGroupId())); } -Dialog* Pokemod::newDialog(const Dialog& dialog) +EggGroup* Pokemod::newEggGroup(const EggGroup& eggGroup) { - return newDialog(new Dialog(dialog, this, newDialogId())); + return newEggGroup(new EggGroup(eggGroup, this, newEggGroupId())); } -Dialog* Pokemod::newDialog(Dialog* dialog) +EggGroup* Pokemod::newEggGroup(EggGroup* eggGroup) { - m_dialogs.append(dialog); - return dialog; + m_eggGroups.append(eggGroup); + return eggGroup; } -void Pokemod::deleteDialog(const int index) +void Pokemod::deleteEggGroup(const int index) { - if (dialogCount() <= index) + if (eggGroupCount() <= index) return; - delete m_dialogs[index]; - m_dialogs.removeAt(index); + delete m_eggGroups[index]; + m_eggGroups.removeAt(index); } -void Pokemod::deleteDialogById(const int id) +void Pokemod::deleteEggGroupById(const int id) { - deleteDialog(dialogIndex(id)); + deleteEggGroup(eggGroupIndex(id)); } -int Pokemod::newDialogId() const +int Pokemod::newEggGroupId() const { int i = 0; - while ((i < dialogCount()) && (dialogIndex(i) != INT_MAX)) + while ((i < eggGroupCount()) && (eggGroupIndex(i) != INT_MAX)) ++i; return i; } -const EggGroup* Pokemod::eggGroup(const int index) const +const GlobalScript* Pokemod::globalScript(const int index) const { - if (eggGroupCount() <= index) + if (globalScriptCount() <= index) return NULL; - return m_eggGroups.at(index); + return m_globalScripts.at(index); } -EggGroup* Pokemod::eggGroup(const int index) +GlobalScript* Pokemod::globalScript(const int index) { - if (eggGroupCount() <= index) + if (globalScriptCount() <= index) return NULL; - return m_eggGroups[index]; + return m_globalScripts[index]; } -const EggGroup* Pokemod::eggGroupById(const int id) const +const GlobalScript* Pokemod::globalScriptById(const int id) const { - return eggGroup(eggGroupIndex(id)); + return globalScript(globalScriptIndex(id)); } -EggGroup* Pokemod::eggGroupById(const int id) +GlobalScript* Pokemod::globalScriptById(const int id) { - return eggGroup(eggGroupIndex(id)); + return globalScript(globalScriptIndex(id)); } -int Pokemod::eggGroupIndex(const int id) const +int Pokemod::globalScriptIndex(const int id) const { - for (int i = 0; i < eggGroupCount(); ++i) + for (int i = 0; i < globalScriptCount(); ++i) { - if (m_eggGroups[i]->id() == id) + if (m_globalScripts[i]->id() == id) return i; } return INT_MAX; } -int Pokemod::eggGroupCount() const +int Pokemod::globalScriptCount() const { - return m_eggGroups.size(); + return m_globalScripts.size(); } -EggGroup* Pokemod::newEggGroup() +GlobalScript* Pokemod::newGlobalScript() { - return newEggGroup(new EggGroup(this, newEggGroupId())); + return newGlobalScript(new GlobalScript(this, newGlobalScriptId())); } -EggGroup* Pokemod::newEggGroup(const QDomElement& xml) +GlobalScript* Pokemod::newGlobalScript(const QDomElement& xml) { - return newEggGroup(new EggGroup(xml, this, newEggGroupId())); + return newGlobalScript(new GlobalScript(xml, this, newGlobalScriptId())); } -EggGroup* Pokemod::newEggGroup(const EggGroup& eggGroup) +GlobalScript* Pokemod::newGlobalScript(const GlobalScript& globalScript) { - return newEggGroup(new EggGroup(eggGroup, this, newEggGroupId())); + return newGlobalScript(new GlobalScript(globalScript, this, newGlobalScriptId())); } -EggGroup* Pokemod::newEggGroup(EggGroup* eggGroup) +GlobalScript* Pokemod::newGlobalScript(GlobalScript* globalScript) { - m_eggGroups.append(eggGroup); - return eggGroup; + m_globalScripts.append(globalScript); + return globalScript; } -void Pokemod::deleteEggGroup(const int index) +void Pokemod::deleteGlobalScript(const int index) { - if (eggGroupCount() <= index) + if (globalScriptCount() <= index) return; - delete m_eggGroups[index]; - m_eggGroups.removeAt(index); + delete m_globalScripts[index]; + m_globalScripts.removeAt(index); } -void Pokemod::deleteEggGroupById(const int id) +void Pokemod::deleteGlobalScriptById(const int id) { - deleteEggGroup(eggGroupIndex(id)); + deleteGlobalScript(globalScriptIndex(id)); } -int Pokemod::newEggGroupId() const +int Pokemod::newGlobalScriptId() const { int i = 0; - while ((i < eggGroupCount()) && (eggGroupIndex(i) != INT_MAX)) + while ((i < globalScriptCount()) && (globalScriptIndex(i) != INT_MAX)) ++i; return i; } @@ -2162,13 +2169,13 @@ Pokemod& Pokemod::operator=(const Pokemod& rhs) COPY(superPCUname); COPY(superPCPasswd); COPY(typeChart); - COPY_RULES(); + COPY_Rules(rules); COPY_SUB(Ability, abilities); COPY_SUB(Author, authors); COPY_SUB(Badge, badges); COPY_SUB(CoinList, coinLists); - COPY_SUB(Dialog, dialogs); COPY_SUB(EggGroup, eggGroups); + COPY_SUB(GlobalScript, globalScripts); COPY_SUB(Item, items); COPY_SUB(ItemType, itemTypes); COPY_SUB(Map, maps); @@ -2194,10 +2201,10 @@ void Pokemod::clear() deleteBadge(0); while (coinListCount()) deleteCoinList(0); - while (dialogCount()) - deleteDialog(0); while (eggGroupCount()) deleteEggGroup(0); + while (globalScriptCount()) + deleteGlobalScript(0); while (itemCount()) deleteItem(0); while (itemTypeCount()) diff --git a/pokemod/Pokemod.h b/pokemod/Pokemod.h index a0d09446..1509e342 100644 --- a/pokemod/Pokemod.h +++ b/pokemod/Pokemod.h @@ -35,8 +35,8 @@ class Ability; class Author; class Badge; class CoinList; -class Dialog; class EggGroup; +class GlobalScript; class Item; class ItemType; class Map; @@ -247,18 +247,6 @@ class Pokemod : public Object void deleteCoinList(const int index); void deleteCoinListById(const int id); - const Dialog* dialog(const int index) const; - Dialog* dialog(const int index); - const Dialog* dialogById(const int id) const; - Dialog* dialogById(const int id); - int dialogIndex(const int id) const; - int dialogCount() const; - Dialog* newDialog(); - Dialog* newDialog(const QDomElement& xml); - Dialog* newDialog(const Dialog& dialog); - void deleteDialog(const int index); - void deleteDialogById(const int id); - const EggGroup* eggGroup(const int index) const; EggGroup* eggGroup(const int index); const EggGroup* eggGroupById(const int id) const; @@ -271,6 +259,18 @@ class Pokemod : public Object void deleteEggGroup(const int index); void deleteEggGroupById(const int id); + const GlobalScript* globalScript(const int index) const; + GlobalScript* globalScript(const int index); + const GlobalScript* globalScriptById(const int id) const; + GlobalScript* globalScriptById(const int id); + int globalScriptIndex(const int id) const; + int globalScriptCount() const; + GlobalScript* newGlobalScript(); + GlobalScript* newGlobalScript(const QDomElement& xml); + GlobalScript* newGlobalScript(const GlobalScript& globalScript); + void deleteGlobalScript(const int index); + void deleteGlobalScriptById(const int id); + const Item* item(const int index) const; Item* item(const int index); const Item* itemById(const int id) const; @@ -431,9 +431,6 @@ class Pokemod : public Object int newCoinListId() const; CoinList* newCoinList(CoinList* coinList); - int newDialogId() const; - Dialog* newDialog(Dialog* dialog); - int newEggGroupId() const; EggGroup* newEggGroup(EggGroup* eggGroup); @@ -452,6 +449,9 @@ class Pokemod : public Object int newNatureId() const; Nature* newNature(Nature* nature); + int newGlobalScriptId() const; + GlobalScript* newGlobalScript(GlobalScript* globalScript); + int newSoundId() const; Sound* newSound(Sound* sound); @@ -496,8 +496,8 @@ class Pokemod : public Object QList<Author*> m_authors; QList<Badge*> m_badges; QList<CoinList*> m_coinLists; - QList<Dialog*> m_dialogs; QList<EggGroup*> m_eggGroups; + QList<GlobalScript*> m_globalScripts; QList<Item*> m_items; QList<ItemType*> m_itemTypes; QList<Map*> m_maps; diff --git a/pokemod/Rules.cpp b/pokemod/Rules.cpp index d60a0bb4..22988f40 100644 --- a/pokemod/Rules.cpp +++ b/pokemod/Rules.cpp @@ -95,9 +95,8 @@ void Rules::validate() emit(warning("Pokerus chance is high")); } -void Rules::load(const QDomElement& xml, const int) +void Rules::load(const QDomElement& xml, const int /*id*/) { - clear(); LOAD(bool, genderAllowed); LOAD(bool, breedingAllowed); LOAD(int, holdItems); diff --git a/pokemod/Rules.h b/pokemod/Rules.h index 64866c81..8dabc683 100644 --- a/pokemod/Rules.h +++ b/pokemod/Rules.h @@ -39,7 +39,7 @@ class Rules : public Object void validate(); - void load(const QDomElement& xml, const int = 0); + void load(const QDomElement& xml, const int /*id*/ = 0); QDomElement save() const; void setGenderAllowed(const bool genderAllowed); diff --git a/pokemod/Script.cpp b/pokemod/Script.cpp new file mode 100644 index 00000000..075f3dcc --- /dev/null +++ b/pokemod/Script.cpp @@ -0,0 +1,95 @@ +/* + * 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/>. + */ + +// Header include +#include "Script.h" + +Script::Script(const Script& script) : + Object("Script", script.parent(), 0) +{ + *this = script; +} + +Script::Script(const Object* parent) : + Object("Script", parent, 0), + m_interpreter(""), + m_script("") +{ +} + +Script::Script(const Script& script, const Object* parent) : + Object("Script", parent, 0) +{ + *this = script; +} + +Script::Script(const QDomElement& xml, const Object* parent) : + Object("Script", parent, 0) +{ + load(xml, id); +} + +void Script::validate() +{ + if (m_interpreter.isEmpty()) + emit(error("Interpreter is empty")); + if (m_script.isEmpty()) + emit(error("Script is empty")); +} + +void Script::load(const QDomElement& xml, const int /*id*/) +{ + LOAD(QString, interpreter); + LOAD(QString, script); +} + +QDomElement Script::save() const +{ + QDomElement xml = QDomDocument().createElement(className()); + SAVE(QString, interpreter); + SAVE(QString, script); + return xml; +} + +void Script::setInterpreter(const QString& interpreter) +{ + CHECK(interpreter); +} + +void Script::setScript(const QString& script) +{ + CHECK(script); +} + +QString Script::interpreter() const +{ + return m_interpreter; +} + +QString Script::script() const +{ + return m_script; +} + +Script& Script::operator=(const Script& rhs) +{ + if (this == &rhs) + return *this; + COPY(interpreter); + COPY(script); + return *this; +} diff --git a/pokemod/Script.h b/pokemod/Script.h new file mode 100644 index 00000000..5e66f578 --- /dev/null +++ b/pokemod/Script.h @@ -0,0 +1,72 @@ +/* + * Copyright 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/>. + */ + +#ifndef __POKEMOD_SCRIPT__ +#define __POKEMOD_SCRIPT__ + +// Qt includes +#include <QString> + +class Script +{ + public: + inline Script(const QString& interpreter = "", const QString& script = "") : + m_interpreter(interpreter), + m_script(script) + { + } + + inline void setInterpreter(const QString& interpreter) + { + m_interpreter = interpreter; + } + inline void setScript(const QString& script) + { + m_script = script; + } + + inline QString interpreter() const + { + return m_interpreter; + } + inline QString script() const + { + return m_script; + } + + inline Script& operator=(const Script& rhs) + { + if (this == &rhs) + return *this; + m_interpreter = rhs.m_interpreter; + m_script = rhs.m_script; + return *this; + } + inline bool operator==(const Script& rhs) const + { + return ((m_interpreter == rhs.m_interpreter) && (m_script == rhs.m_script)); + } + inline bool operator!=(const Script& rhs) const + { + return !(*this == rhs); + } + private: + QString m_interpreter; + QString m_script; +}; + +#endif diff --git a/pokemod/Species.cpp b/pokemod/Species.cpp index 6c6fd278..d3b91b5c 100644 --- a/pokemod/Species.cpp +++ b/pokemod/Species.cpp @@ -22,7 +22,6 @@ #include "Pokemod.h" #include "Rules.h" #include "SpeciesAbility.h" -#include "SpeciesEvolution.h" #include "SpeciesItem.h" #include "SpeciesMove.h" @@ -59,7 +58,8 @@ Species::Species(const Pokemod* parent, const int id) : m_genderFactor(1, 1), m_eggSpecies(INT_MAX), m_eggSteps(0), - m_nidoranGroup(INT_MAX) + m_nidoranGroup(INT_MAX), + m_evolution("", "") { for (int i = 0; i < Pokemod::ST_End_GSC; ++i) { @@ -136,20 +136,6 @@ void Species::validate() idChecker.clear(); valueChecker.clear(); } - if (!evolutionCount()) - emit(warning("There are no evolutions")); - foreach (SpeciesEvolution* evolution, m_evolutions) - { - evolution->validate(); - if (evolution->species() == id()) - emit(error("Evolution into self")); - if (static_cast<const Pokemod*>(pokemod())->species(evolution->species())->growth() != m_growth) - emit(error("Growth mismatch")); - if (idChecker.contains(evolution->id())) - emit(error(subclass("evolution", evolution->id()))); - idChecker.insert(evolution->id()); - } - idChecker.clear(); if (static_cast<const Pokemod*>(pokemod())->rules()->holdItems()) { if (!itemCount()) @@ -201,8 +187,8 @@ void Species::load(const QDomElement& xml, int id) LOAD(int, nidoranGroup); LOAD_LIST(int, type); LOAD_LIST(int, eggGroup); + LOAD(Script, evolution); LOAD_SUB(newAbility, SpeciesAbility); - LOAD_SUB(newEvolution, SpeciesEvolution); LOAD_SUB(newItem, SpeciesItem); LOAD_SUB(newMove, SpeciesMove); } @@ -230,8 +216,8 @@ QDomElement Species::save() const SAVE(int, nidoranGroup); SAVE_LIST(int, type); SAVE_LIST(int, eggGroup); + SAVE(Script, evolution); SAVE_SUB(SpeciesAbility, abilities); - SAVE_SUB(SpeciesEvolution, evolutions); SAVE_SUB(SpeciesItem, items); SAVE_SUB(SpeciesMove, moves); return xml; @@ -516,6 +502,11 @@ void Species::setEggGroup(const int eggGroup, const bool state) } } +void Species::setEvolution(const Script& evolution) +{ + CHECK(evolution); +} + QString Species::name() const { return m_name; @@ -651,6 +642,11 @@ bool Species::eggGroup(const int eggGroup) const return m_eggGroup.contains(eggGroup); } +Script Species::evolution() const +{ + return m_evolution; +} + const SpeciesAbility* Species::ability(const int index) const { if (abilityCount() <= index) @@ -732,87 +728,6 @@ int Species::newAbilityId() const return i; } -const SpeciesEvolution* Species::evolution(const int index) const -{ - if (evolutionCount() <= index) - return NULL; - return m_evolutions.at(index); -} - -SpeciesEvolution* Species::evolution(const int index) -{ - if (evolutionCount() <= index) - return NULL; - return m_evolutions[index]; -} - -const SpeciesEvolution* Species::evolutionById(const int id) const -{ - return evolution(evolutionIndex(id)); -} - -SpeciesEvolution* Species::evolutionById(const int id) -{ - return evolution(evolutionIndex(id)); -} - -int Species::evolutionIndex(const int id) const -{ - for (int i = 0; i < evolutionCount(); ++i) - { - if (m_evolutions[i]->id() == id) - return i; - } - return INT_MAX; -} - -int Species::evolutionCount() const -{ - return m_evolutions.size(); -} - -SpeciesEvolution* Species::newEvolution() -{ - return newEvolution(new SpeciesEvolution(this, newEvolutionId())); -} - -SpeciesEvolution* Species::newEvolution(const QDomElement& xml) -{ - return newEvolution(new SpeciesEvolution(xml, this, newEvolutionId())); -} - -SpeciesEvolution* Species::newEvolution(const SpeciesEvolution& evolution) -{ - return newEvolution(new SpeciesEvolution(evolution, this, newEvolutionId())); -} - -SpeciesEvolution* Species::newEvolution(SpeciesEvolution* evolution) -{ - m_evolutions.append(evolution); - return evolution; -} - -void Species::deleteEvolution(const int index) -{ - if (evolutionCount() <= index) - return; - delete m_evolutions[index]; - m_evolutions.removeAt(index); -} - -void Species::deleteEvolutionById(const int id) -{ - deleteEvolution(evolutionIndex(id)); -} - -int Species::newEvolutionId() const -{ - int i = 0; - while ((i < evolutionCount()) && (evolutionIndex(i) != INT_MAX)) - ++i; - return i; -} - const SpeciesItem* Species::item(const int index) const { if (itemCount() <= index) @@ -1000,8 +915,8 @@ Species& Species::operator=(const Species& rhs) COPY(nidoranGroup); COPY(type); COPY(eggGroup); + COPY(evolution); COPY_SUB(SpeciesAbility, abilities); - COPY_SUB(SpeciesEvolution, evolutions); COPY_SUB(SpeciesItem, items); COPY_SUB(SpeciesMove, moves); return *this; @@ -1011,8 +926,6 @@ void Species::clear() { while (abilityCount()) deleteAbility(0); - while (evolutionCount()) - deleteEvolution(0); while (itemCount()) deleteItem(0); while (moveCount()) diff --git a/pokemod/Species.h b/pokemod/Species.h index f6c65d64..5c808117 100644 --- a/pokemod/Species.h +++ b/pokemod/Species.h @@ -22,13 +22,13 @@ #include "Fraction.h" #include "Object.h" #include "Pokemod.h" +#include "Script.h" // Qt includes #include <QList> // Forward declarations class SpeciesAbility; -class SpeciesEvolution; class SpeciesItem; class SpeciesMove; @@ -85,6 +85,7 @@ class Species : public Object void setNidoranGroup(const int nidoranGroup); void setType(const int type, const bool state); void setEggGroup(const int eggGroup, const bool state); + void setEvolution(const Script& evolution); QString name() const; int baseStat(const int stat) const; @@ -111,6 +112,7 @@ class Species : public Object int nidoranGroup() const; bool type(const int type) const; bool eggGroup(const int eggGroup) const; + Script evolution() const; const SpeciesAbility* ability(const int index) const; SpeciesAbility* ability(const int index); @@ -124,18 +126,6 @@ class Species : public Object void deleteAbility(const int index); void deleteAbilityById(const int id); - const SpeciesEvolution* evolution(const int index) const; - SpeciesEvolution* evolution(const int index); - const SpeciesEvolution* evolutionById(const int id) const; - SpeciesEvolution* evolutionById(const int id); - int evolutionIndex(const int id) const; - int evolutionCount() const; - SpeciesEvolution* newEvolution(); - SpeciesEvolution* newEvolution(const QDomElement& xml); - SpeciesEvolution* newEvolution(const SpeciesEvolution& evolution); - void deleteEvolution(const int index); - void deleteEvolutionById(const int id); - const SpeciesItem* item(const int index) const; SpeciesItem* item(const int index); const SpeciesItem* itemById(const int i) const; @@ -165,9 +155,6 @@ class Species : public Object int newAbilityId() const; SpeciesAbility* newAbility(SpeciesAbility* ability); - int newEvolutionId() const; - SpeciesEvolution* newEvolution(SpeciesEvolution* evolution); - int newItemId() const; SpeciesItem* newItem(SpeciesItem* item); @@ -201,8 +188,8 @@ class Species : public Object int m_nidoranGroup; QList<int> m_type; QList<int> m_eggGroup; + Script m_evolution; QList<SpeciesAbility*> m_abilities; - QList<SpeciesEvolution*> m_evolutions; QList<SpeciesItem*> m_items; QList<SpeciesMove*> m_moves; }; diff --git a/pokemod/SpeciesEvolution.cpp b/pokemod/SpeciesEvolution.cpp index 7e35ccba..4c2c5c8e 100644 --- a/pokemod/SpeciesEvolution.cpp +++ b/pokemod/SpeciesEvolution.cpp @@ -20,14 +20,10 @@ // Pokemod includes #include "Item.h" -#include "ItemEffect.h" #include "Pokemod.h" #include "Rules.h" #include "Species.h" -const QStringList SpeciesEvolution::StyleStr = QStringList() << "Level" << "Happiness" << "Stat" << "Item" << "Trade" << "TradeItem" << "Personality" << "Spare Slot"; -const QStringList SpeciesEvolution::GiveHoldStr = QStringList() <<"Give" << "Hold"; - SpeciesEvolution::SpeciesEvolution(const SpeciesEvolution& evolution) : Object("SpeciesEvolution", evolution.parent(), evolution.id()) { @@ -37,10 +33,7 @@ SpeciesEvolution::SpeciesEvolution(const SpeciesEvolution& evolution) : SpeciesEvolution::SpeciesEvolution(const Species* parent, const int id) : Object("SpeciesEvolution", parent, id), m_species(INT_MAX), - m_style(INT_MAX), - m_value1(INT_MAX), - m_value2(INT_MAX), - m_value3(INT_MAX), + m_script(""), m_level(0) { } @@ -60,10 +53,8 @@ SpeciesEvolution::SpeciesEvolution(const QDomElement& xml, const Species* parent void SpeciesEvolution::validate() { TEST(setSpecies, species); - TEST(setStyle, style); - TEST(setValue1, value1); - TEST(setValue2, value2); - TEST(setValue3, value3); + if (m_script.isEmpty()) + emit(warning("Script is empty")); TEST(setLevel, level); } @@ -71,10 +62,7 @@ void SpeciesEvolution::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(int, species); - LOAD(int, style); - LOAD(int, value1); - LOAD(int, value2); - LOAD(int, value3); + LOAD(QString, script); LOAD(int, level); } @@ -82,10 +70,7 @@ QDomElement SpeciesEvolution::save() const { SAVE_CREATE(); SAVE(int, species); - SAVE(int, style); - SAVE(int, value1); - SAVE(int, value2); - SAVE(int, value3); + SAVE(QString, script); SAVE(int, level); return xml; } @@ -100,89 +85,9 @@ void SpeciesEvolution::setSpecies(const int species) CHECK(species); } -void SpeciesEvolution::setStyle(const int style) -{ - if (S_End <= style) - { - emit(error(bounds("style"))); - return; - } - CHECK(style); -} - -void SpeciesEvolution::setValue1(const int value1) -{ - bool ok = false; - switch (m_style) - { - case S_Happiness: - case S_Stat: - case S_Personality: - if (Pokemod::REL_End <= value1) - { - emit(error(bounds("value1"))); - return; - } - break; - case S_Item: - case S_TradeItem: - if (static_cast<const Pokemod*>(pokemod())->itemIndex(value1) == INT_MAX) - { - emit(error(bounds("value1"))); - return; - } - for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemById(value1)->effectCount()) && !ok; ++i) - ok = (static_cast<const Pokemod*>(pokemod())->itemById(value1)->effect(i)->effect() == ItemEffect::E_Evolution); - if (!ok) - { - emit(error(bounds("value1"))); - return; - } - break; - default: - emit(warning(unused("value1"))); - return; - } - CHECK(value1); -} - -void SpeciesEvolution::setValue2(const int value2) -{ - switch (m_style) - { - case S_Stat: - if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value2) - { - emit(error(bounds("value2"))); - return; - } - case S_Item: - if ((G_End <= value2) || ((value2 == G_Hold) && !static_cast<const Pokemod*>(pokemod())->rules()->holdItems())) - { - emit(error(bounds("value2"))); - return; - } - break; - default: - emit(warning(unused("value2"))); - return; - } - CHECK(value2); -} - -void SpeciesEvolution::setValue3(const int value3) +void SpeciesEvolution::setScript(const QString& script) { - switch (m_style) - { - case S_Happiness: - case S_Stat: - case S_Personality: - break; - default: - emit(warning(unused("value3"))); - return; - } - CHECK(value3); + CHECK(script); } void SpeciesEvolution::setLevel(const int level) @@ -200,24 +105,9 @@ int SpeciesEvolution::species() const return m_species; } -int SpeciesEvolution::style() const -{ - return m_style; -} - -int SpeciesEvolution::value1() const -{ - return m_value1; -} - -int SpeciesEvolution::value2() const -{ - return m_value2; -} - -int SpeciesEvolution::value3() const +QString SpeciesEvolution::script() const { - return m_value3; + return m_script; } int SpeciesEvolution::level() const @@ -230,9 +120,7 @@ SpeciesEvolution& SpeciesEvolution::operator=(const SpeciesEvolution& rhs) if (this == &rhs) return *this; COPY(species); - COPY(style); - COPY(value1); - COPY(value2); + COPY(script); COPY(level); return *this; } diff --git a/pokemod/SpeciesEvolution.h b/pokemod/SpeciesEvolution.h index e0ba988d..126649b8 100644 --- a/pokemod/SpeciesEvolution.h +++ b/pokemod/SpeciesEvolution.h @@ -29,28 +29,6 @@ class SpeciesEvolution : public Object Q_OBJECT public: - enum Style - { - S_Level = 0, - S_Happiness = 1, - S_Stat = 2, - S_Item = 3, - S_Trade = 4, - S_TradeItem = 5, - S_Personality = 6, - S_SpareSlot = 7, - S_End = 8 - }; - static const QStringList StyleStr; - - enum GiveHold - { - G_Give = 0, - G_Hold = 1, - G_End = 2 - }; - static const QStringList GiveHoldStr; - SpeciesEvolution(const SpeciesEvolution& evolution); SpeciesEvolution(const Species* parent, const int id); SpeciesEvolution(const SpeciesEvolution& evolution, const Species* parent, const int id); @@ -62,26 +40,17 @@ class SpeciesEvolution : public Object QDomElement save() const; void setSpecies(const int species); - void setStyle(const int style); - void setValue1(const int value1); - void setValue2(const int value2); - void setValue3(const int value3); + void setScript(const QString& script); void setLevel(const int level); int species() const; - int style() const; - int value1() const; - int value2() const; - int value3() const; + QString script() const; int level() const; SpeciesEvolution& operator=(const SpeciesEvolution& rhs); private: int m_species; - int m_style; - int m_value1; - int m_value2; - int m_value3; + QString m_script; int m_level; }; diff --git a/pokemod/pokemod.pro b/pokemod/pokemod.pro index 158233b9..f366afe7 100644 --- a/pokemod/pokemod.pro +++ b/pokemod/pokemod.pro @@ -13,17 +13,14 @@ QT += xml } SOURCES += Ability.cpp \ - AbilityEffect.cpp \ Author.cpp \ Badge.cpp \ CoinList.cpp \ CoinListObject.cpp \ - Dialog.cpp \ EggGroup.cpp \ - Flag.cpp \ Fraction.cpp \ + GlobalScript.cpp \ Item.cpp \ - ItemEffect.cpp \ ItemType.cpp \ Map.cpp \ MapEffect.cpp \ @@ -33,15 +30,13 @@ SOURCES += Ability.cpp \ MapWildList.cpp \ MapWildListEncounter.cpp \ Move.cpp \ - MoveEffect.cpp \ Nature.cpp \ Object.cpp \ Pokemod.cpp \ Rules.cpp \ Sound.cpp \ - SpeciesAbility.cpp \ Species.cpp \ - SpeciesEvolution.cpp \ + SpeciesAbility.cpp \ SpeciesItem.cpp \ SpeciesMove.cpp \ Store.cpp \ @@ -50,18 +45,15 @@ SOURCES += Ability.cpp \ Trainer.cpp \ Type.cpp -HEADERS += AbilityEffect.h \ - Ability.h \ +HEADERS += Ability.h \ Author.h \ Badge.h \ CoinList.h \ CoinListObject.h \ - Dialog.h \ EggGroup.h \ - Flag.h \ Fraction.h \ + GlobalScript.h \ Hat.h \ - ItemEffect.h \ Item.h \ ItemType.h \ MapEffect.h \ @@ -72,17 +64,16 @@ HEADERS += AbilityEffect.h \ MapWildListEncounter.h \ MapWildList.h \ Matrix.h \ - MoveEffect.h \ Move.h \ Nature.h \ Object.h \ Point.h \ Pokemod.h \ Rules.h \ + Script.h \ Sound.h \ - SpeciesAbility.h \ - SpeciesEvolution.h \ Species.h \ + SpeciesAbility.h \ SpeciesItem.h \ SpeciesMove.h \ Store.h \ |