diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-02 08:42:08 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-02 08:42:08 +0000 |
| commit | 822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd (patch) | |
| tree | 40dc605213eff20f62b16e5f54e5e5e03d744d63 /pokemod/MapWildList.cpp | |
| parent | 696414f1dc8bc419427efb6c1abe1bbae0a68a56 (diff) | |
| download | sigen-822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd.tar.gz sigen-822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd.tar.xz sigen-822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd.zip | |
[FIX] Exceptions no longer used in pokemod
[DEL] Exception and BugCatcher are no longer needed
[ADD] Object.cpp added
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@119 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/MapWildList.cpp')
| -rw-r--r-- | pokemod/MapWildList.cpp | 182 |
1 files changed, 70 insertions, 112 deletions
diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp index 5c866aef..ff092db2 100644 --- a/pokemod/MapWildList.cpp +++ b/pokemod/MapWildList.cpp @@ -24,6 +24,9 @@ #include "MapWildListEncounter.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + const QStringList MapWildList::ControlStr = QStringList() << "Grass" << "Surfing" << "Fishing" << "Dive" << "Headbutt" << "Rock Smash"; MapWildList::MapWildList(const MapWildList& wildList) : @@ -57,82 +60,24 @@ MapWildList::~MapWildList() clear(); } -bool MapWildList::validate() const +void MapWildList::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Wild List with id %1---").arg(id()), Pokemod::V_Msg); -// if (End <= m_control) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid control"); -// valid = false; -// } -// else if (m_control == Fishing) -// { -// bool ok = false; -// for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()) && !ok; ++i) -// { -// const Item* item = static_cast<const Pokemod*>(pokemod())->item(i); -// for (int j = 0; (j < item->effectCount()) && !ok; ++j) -// { -// const ItemEffect* effect = item->effect(j); -// ok = ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == m_value)); -// } -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid fishing value"); -// valid = false; -// } -// } -// QMap<int, bool> idChecker; -// foreach (int time, m_times) -// { -// if (static_cast<const Pokemod*>(pokemod())->timeIndex(time) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid time"); -// valid = false; -// } -// if (idChecker[time]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate of time %1").arg(time)); -// idChecker[time] = true; -// } -// idChecker.clear(); -// if (m_scope != INT_MAX) -// { -// bool ok = false; -// for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()) && !ok; ++i) -// { -// const Item* item = static_cast<const Pokemod*>(pokemod())->item(i); -// for (int j = 0; (j < item->effectCount()) && !ok; ++j) -// { -// const ItemEffect* effect = item->effect(j); -// ok = ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == m_scope)); -// } -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid scope"); -// valid = false; -// } -// } -// if (encounterCount()) -// { -// foreach (MapWildListEncounter* encounter, m_encounters) -// { -// if (!encounter->isValid()) -// valid = false; -// if (idChecker[encounter->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate encounter with id %1").arg(encounter->id())); -// idChecker[encounter->id()] = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("No effects")); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setControl, control); + TEST(setValue, value); + TEST_LIST(setTime, time); + TEST(setScope, scope); + if (!encounterCount()) + error(stream, "There are no encounters"); + QSet<int> idChecker; + foreach (MapWildListEncounter* encounter, m_encounters) + { + if (!encounter->isValid(stream)) + setValid(false); + if (idChecker.contains(encounter->id())) + subclassError(stream, "encounter", encounter->id()); + idChecker.insert(encounter->id()); + } } void MapWildList::load(const QDomElement& xml, int id) @@ -140,7 +85,7 @@ void MapWildList::load(const QDomElement& xml, int id) LOAD_ID(); LOAD(int, control); LOAD(int, value); - LOAD_LIST(int, times); + LOAD_LIST(int, time); LOAD(int, scope); LOAD_SUB(newEncounter, MapWildListEncounter); } @@ -150,70 +95,83 @@ QDomElement MapWildList::save() const SAVE_CREATE(); SAVE(int, control); SAVE(int, value); - SAVE_LIST(int, times); + SAVE_LIST(int, time); SAVE(int, scope); SAVE_SUB(MapWildListEncounter, encounters); return xml; } -void MapWildList::setControl(const int control) throw(BoundsException) +void MapWildList::setControl(const int control) { if (End <= control) - error<BoundsException>("control"); + { + boundsError("control"); + return; + } m_control = control; m_value = INT_MAX; } -void MapWildList::setValue(const int value) throw(Exception) +void MapWildList::setValue(const int value) { if (m_control != Fishing) - error<UnusedException>("value"); - bool ok = false; - for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()) && !ok; ++i) + { + unusedError("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()) && !ok; ++j) + for (int j = 0; (j < item->effectCount()); ++j) { const ItemEffect* effect = item->effect(j); - ok = ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == value)); + if ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == value)) + { + m_value = value; + return; + } } } - if (!ok) - error<BoundsException>("value"); - m_value = value; + boundsError("value"); } -void MapWildList::setTime(const int time, const bool state) throw(BoundsException) +void MapWildList::setTime(const int time, const bool state) { if (static_cast<const Pokemod*>(pokemod())->timeIndex(time) == INT_MAX) - error<BoundsException>("time"); + { + boundsError("time"); + return; + } if (state) { - if (!m_times.contains(time)) - m_times.append(time); + if (!m_time.contains(time)) + m_time.append(time); } else - m_times.removeAll(time); + m_time.removeAll(time); } -void MapWildList::setScope(const int scope) throw(BoundsException) +void MapWildList::setScope(const int scope) { if (scope != INT_MAX) { - bool ok = false; - for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()) && !ok; ++i) + 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()) && !ok; ++j) + for (int j = 0; (j < item->effectCount()); ++j) { const ItemEffect* effect = item->effect(j); - ok = ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == scope)); + if ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == scope)) + { + m_scope = scope; + return; + } } } - if (!ok) - error<BoundsException>("scope"); + boundsError("value"); } - m_scope = scope; + else + m_scope = scope; } int MapWildList::control() const @@ -228,7 +186,7 @@ int MapWildList::value() const bool MapWildList::time(const int time) const { - return m_times.contains(time); + return m_time.contains(time); } int MapWildList::scope() const @@ -236,26 +194,26 @@ int MapWildList::scope() const return m_scope; } -const MapWildListEncounter* MapWildList::encounter(const int index) const throw(IndexException) +const MapWildListEncounter* MapWildList::encounter(const int index) const { if (encounterCount() <= index) - warning<IndexException>("encounter"); + return NULL; return m_encounters.at(index); } -MapWildListEncounter* MapWildList::encounter(const int index) throw(IndexException) +MapWildListEncounter* MapWildList::encounter(const int index) { if (encounterCount() <= index) - error<IndexException>("encounter"); + return NULL; return m_encounters[index]; } -const MapWildListEncounter* MapWildList::encounterById(const int id) const throw(IndexException) +const MapWildListEncounter* MapWildList::encounterById(const int id) const { return encounter(encounterIndex(id)); } -MapWildListEncounter* MapWildList::encounterById(const int id) throw(IndexException) +MapWildListEncounter* MapWildList::encounterById(const int id) { return encounter(encounterIndex(id)); } @@ -296,15 +254,15 @@ MapWildListEncounter* MapWildList::newEncounter(MapWildListEncounter* encounter) return encounter; } -void MapWildList::deleteEncounter(const int index) throw(IndexException) +void MapWildList::deleteEncounter(const int index) { if (encounterCount() <= index) - error<IndexException>("encounter"); + return; delete m_encounters[index]; m_encounters.removeAt(index); } -void MapWildList::deleteEncounterById(const int id) throw(IndexException) +void MapWildList::deleteEncounterById(const int id) { deleteEncounter(encounterIndex(id)); } @@ -324,7 +282,7 @@ MapWildList& MapWildList::operator=(const MapWildList& rhs) clear(); COPY(control); COPY(value); - COPY(times); + COPY(time); COPY(scope); COPY_SUB(MapWildListEncounter, encounters); return *this; |
