From 807071d35159de0660f9df31c48d5bf895ca3622 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 27 Apr 2008 15:15:17 +0000 Subject: [FIX] Pokemod objects now know about parents [FIX] Project includes are now relative [FIX] Headers included for better detection of invalid headers [FIX] Validation code commented out so it can be done better git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@111 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/MapWildList.cpp | 187 ++++++++++++++++++++++++------------------------ 1 file changed, 94 insertions(+), 93 deletions(-) (limited to 'pokemod/MapWildList.cpp') diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp index 1b239e8b..3bc04a18 100644 --- a/pokemod/MapWildList.cpp +++ b/pokemod/MapWildList.cpp @@ -15,42 +15,42 @@ * with this program. If not, see . */ -// Qt includes -#include +// Header include +#include "MapWildList.h" // Pokemod includes -#include "Pokemod.h" #include "Item.h" #include "ItemEffect.h" #include "MapWildListEncounter.h" +#include "Pokemod.h" -// Header include -#include "MapWildList.h" +// Qt includes +#include const QStringList MapWildList::ControlStr = QStringList() << "Grass" << "Surfing" << "Fishing" << "Dive" << "Headbutt" << "Rock Smash"; MapWildList::MapWildList(const MapWildList& wildList) : - Object("MapWildList", wildList.pokemod(), wildList.id()) + Object("MapWildList", wildList.parent(), wildList.id()) { *this = wildList; } -MapWildList::MapWildList(const Pokemod* pokemod, const int id) : - Object("MapWildList", pokemod, id), +MapWildList::MapWildList(const Object* parent, const int id) : + Object("MapWildList", parent, id), m_control(INT_MAX), m_value(INT_MAX), m_scope(INT_MAX) { } -MapWildList::MapWildList(const MapWildList& wildList, const Pokemod* pokemod, const int id) : - Object("MapWildList", pokemod, id) +MapWildList::MapWildList(const MapWildList& wildList, const Object* parent, const int id) : + Object("MapWildList", parent, id) { *this = wildList; } -MapWildList::MapWildList(const QDomElement& xml, const Pokemod* pokemod, const int id) : - Object("MapWildList", pokemod, id) +MapWildList::MapWildList(const QDomElement& xml, const Object* parent, const int id) : + Object("MapWildList", parent, id) { load(xml, id); } @@ -62,79 +62,80 @@ MapWildList::~MapWildList() bool MapWildList::validate() const { - bool valid = true; - pokemod()->validationMsg(QString("------Wild List with id %1---").arg(id()), Pokemod::V_Msg); - if (End <= m_control) - { - pokemod()->validationMsg("Invalid control"); - valid = false; - } - else if (m_control == Fishing) - { - bool ok = false; - for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) - { - const Item* item = 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) - { - pokemod()->validationMsg("Invalid fishing value"); - valid = false; - } - } - QMap idChecker; - foreach (int time, m_times) - { - if (pokemod()->timeIndex(time) == INT_MAX) - { - pokemod()->validationMsg("Invalid time"); - valid = false; - } - if (idChecker[time]) - 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 < pokemod()->itemCount()) && !ok; ++i) - { - const Item* item = 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) - { - pokemod()->validationMsg("Invalid scope"); - valid = false; - } - } - if (encounterCount()) - { - foreach (MapWildListEncounter* encounter, m_encounters) - { - if (!encounter->isValid()) - valid = false; - if (idChecker[encounter->id()]) - pokemod()->validationMsg(QString("Duplicate encounter with id %1").arg(encounter->id())); - idChecker[encounter->id()] = true; - } - } - else - { - pokemod()->validationMsg(QString("No effects")); - valid = false; - } - return valid; + // TODO: validate +// bool valid = true; +// static_cast(pokemod())->validationMsg(QString("------Wild List with id %1---").arg(id()), Pokemod::V_Msg); +// if (End <= m_control) +// { +// static_cast(pokemod())->validationMsg("Invalid control"); +// valid = false; +// } +// else if (m_control == Fishing) +// { +// bool ok = false; +// for (int i = 0; (i < static_cast(pokemod())->itemCount()) && !ok; ++i) +// { +// const Item* item = static_cast(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(pokemod())->validationMsg("Invalid fishing value"); +// valid = false; +// } +// } +// QMap idChecker; +// foreach (int time, m_times) +// { +// if (static_cast(pokemod())->timeIndex(time) == INT_MAX) +// { +// static_cast(pokemod())->validationMsg("Invalid time"); +// valid = false; +// } +// if (idChecker[time]) +// static_cast(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(pokemod())->itemCount()) && !ok; ++i) +// { +// const Item* item = static_cast(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(pokemod())->validationMsg("Invalid scope"); +// valid = false; +// } +// } +// if (encounterCount()) +// { +// foreach (MapWildListEncounter* encounter, m_encounters) +// { +// if (!encounter->isValid()) +// valid = false; +// if (idChecker[encounter->id()]) +// static_cast(pokemod())->validationMsg(QString("Duplicate encounter with id %1").arg(encounter->id())); +// idChecker[encounter->id()] = true; +// } +// } +// else +// { +// static_cast(pokemod())->validationMsg(QString("No effects")); +// valid = false; +// } +// return valid; } void MapWildList::load(const QDomElement& xml, int id) @@ -171,9 +172,9 @@ void MapWildList::setValue(const int value) throw(Exception) if (m_control != Fishing) error("value"); bool ok = false; - for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) + for (int i = 0; (i < static_cast(pokemod())->itemCount()) && !ok; ++i) { - const Item* item = pokemod()->item(i); + const Item* item = static_cast(pokemod())->item(i); for (int j = 0; (j < item->effectCount()) && !ok; ++j) { const ItemEffect* effect = item->effect(j); @@ -187,7 +188,7 @@ void MapWildList::setValue(const int value) throw(Exception) void MapWildList::setTime(const int time, const bool state) throw(BoundsException) { - if (pokemod()->timeIndex(time) == INT_MAX) + if (static_cast(pokemod())->timeIndex(time) == INT_MAX) error("time"); if (state) { @@ -203,9 +204,9 @@ void MapWildList::setScope(const int scope) throw(BoundsException) if (scope != INT_MAX) { bool ok = false; - for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) + for (int i = 0; (i < static_cast(pokemod())->itemCount()) && !ok; ++i) { - const Item* item = pokemod()->item(i); + const Item* item = static_cast(pokemod())->item(i); for (int j = 0; (j < item->effectCount()) && !ok; ++j) { const ItemEffect* effect = item->effect(j); @@ -279,19 +280,19 @@ int MapWildList::encounterCount() const MapWildListEncounter* MapWildList::newEncounter() { - m_encounters.append(new MapWildListEncounter(pokemod(), newEncounterId())); + m_encounters.append(new MapWildListEncounter(this, newEncounterId())); return m_encounters[encounterCount() - 1]; } MapWildListEncounter* MapWildList::newEncounter(const QDomElement& xml) { - m_encounters.append(new MapWildListEncounter(xml, pokemod(), newEncounterId())); + m_encounters.append(new MapWildListEncounter(xml, this, newEncounterId())); return m_encounters[encounterCount() - 1]; } MapWildListEncounter* MapWildList::newEncounter(const MapWildListEncounter& encounter) { - m_encounters.append(new MapWildListEncounter(encounter, pokemod(), newEncounterId())); + m_encounters.append(new MapWildListEncounter(encounter, this, newEncounterId())); return m_encounters[encounterCount() - 1]; } -- cgit