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/Map.cpp | 287 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 144 insertions(+), 143 deletions(-) (limited to 'pokemod/Map.cpp') diff --git a/pokemod/Map.cpp b/pokemod/Map.cpp index 6e00dc6b..cd364a55 100644 --- a/pokemod/Map.cpp +++ b/pokemod/Map.cpp @@ -15,43 +15,43 @@ * with this program. If not, see . */ -// Qt includes -#include +// Header include +#include "Map.h" // Pokemod includes -#include "Pokemod.h" #include "MapEffect.h" #include "MapTrainer.h" #include "MapWarp.h" #include "MapWildList.h" +#include "Pokemod.h" -// Header include -#include "Map.h" +// Qt includes +#include const QStringList Map::TypeStr = QStringList() << "Outdoor" << "Dungeon" << "Building"; Map::Map(const Map& map) : - Object("Map", map.pokemod(), map.id()) + Object("Map", map.parent(), map.id()) { *this = map; } -Map::Map(const Pokemod* pokemod, const int id) : - Object("Map", pokemod, id), +Map::Map(const Object* parent, const int id) : + Object("Map", parent, id), m_name(""), m_flyWarp(INT_MAX), m_type(INT_MAX) { } -Map::Map(const Map& map, const Pokemod* pokemod, const int id) : - Object("Map", pokemod, id) +Map::Map(const Map& map, const Object* parent, const int id) : + Object("Map", parent, id) { *this = map; } -Map::Map(const QDomElement& xml, const Pokemod* pokemod, const int id) : - Object("Map", pokemod, id) +Map::Map(const QDomElement& xml, const Object* parent, const int id) : + Object("Map", parent, id) { load(xml, id); } @@ -63,124 +63,125 @@ Map::~Map() bool Map::validate() const { - bool valid = true; - pokemod()->validationMsg(QString("---Map \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); - if (m_name == "") - { - pokemod()->validationMsg("name is not defined"); - valid = false; - } - if ((m_flyWarp != INT_MAX) && (warpIndex(m_flyWarp) == INT_MAX)) - { - pokemod()->validationMsg("Invalid fly destination warp"); - valid = false; - } - if (m_type < End) - { - pokemod()->validationMsg("Invalid type"); - valid = false; - } - QMap idChecker; - if (effectCount()) - { - foreach (MapEffect* effect, m_effects) - { - if (!effect->isValid()) - valid = false; - if (idChecker[effect->id()]) - pokemod()->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); - idChecker[effect->id()] = true; - if (width() <= effect->coordinate().x()) - { - pokemod()->validationMsg("Invalid x coordinate"); - valid = false; - } - if (height() <= effect->coordinate().y()) - { - pokemod()->validationMsg("Invalid y coordinate"); - valid = false; - } - } - idChecker.clear(); - } - else - pokemod()->validationMsg("There are no effects", Pokemod::V_Warn); - if (trainerCount()) - { - foreach (MapTrainer* trainer, m_trainers) - { - if (!trainer->isValid()) - valid = false; - if (idChecker[trainer->id()]) - pokemod()->validationMsg(QString("Duplicate trainer with id %1").arg(trainer->id())); - idChecker[trainer->id()] = true; - if (width() <= trainer->coordinate().x()) - { - pokemod()->validationMsg("Invalid x coordinate"); - valid = false; - } - if (height() <= trainer->coordinate().y()) - { - pokemod()->validationMsg("Invalid y coordinate"); - valid = false; - } - } - idChecker.clear(); - } - else - pokemod()->validationMsg("There are no trainers", Pokemod::V_Warn); - if (warpCount()) - { - foreach (MapWarp* warp, m_warps) - { - if (!warp->isValid()) - valid = false; - if (idChecker[warp->id()]) - pokemod()->validationMsg(QString("Duplicate warp with id %1").arg(warp->id())); - idChecker[warp->id()] = true; - if (width() <= warp->coordinate().x()) - { - pokemod()->validationMsg("Invalid x coordinate"); - valid = false; - } - if (height() <= warp->coordinate().y()) - { - pokemod()->validationMsg("Invalid y coordinate"); - valid = false; - } - } - idChecker.clear(); - } - else - { - pokemod()->validationMsg("There are no warps"); - valid = false; - } - if (wildListCount()) - { - foreach (MapWildList* wildList, m_wildLists) - { - if (!wildList->isValid()) - valid = false; - if (idChecker[wildList->id()]) - pokemod()->validationMsg(QString("Duplicate effect with id %1").arg(wildList->id())); - idChecker[wildList->id()] = true; - } - } - else - pokemod()->validationMsg("There are no effects", Pokemod::V_Warn); - for (int i = 0; i < width(); ++i) - { - for (int j = 0; j < height(); ++j) - { - if (pokemod()->tileIndex(m_tile(i, j)) == INT_MAX) - { - pokemod()->validationMsg(QString("Invalid tile at (%1, %2)").arg(i).arg(j)); - valid = false; - } - } - } - return valid; + // TODO: validate +// bool valid = true; +// static_cast(pokemod())->validationMsg(QString("---Map \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); +// if (m_name == "") +// { +// static_cast(pokemod())->validationMsg("name is not defined"); +// valid = false; +// } +// if ((m_flyWarp != INT_MAX) && (warpIndex(m_flyWarp) == INT_MAX)) +// { +// static_cast(pokemod())->validationMsg("Invalid fly destination warp"); +// valid = false; +// } +// if (m_type < End) +// { +// static_cast(pokemod())->validationMsg("Invalid type"); +// valid = false; +// } +// QMap idChecker; +// if (effectCount()) +// { +// foreach (MapEffect* effect, m_effects) +// { +// if (!effect->isValid()) +// valid = false; +// if (idChecker[effect->id()]) +// static_cast(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); +// idChecker[effect->id()] = true; +// if (width() <= effect->coordinate().x()) +// { +// static_cast(pokemod())->validationMsg("Invalid x coordinate"); +// valid = false; +// } +// if (height() <= effect->coordinate().y()) +// { +// static_cast(pokemod())->validationMsg("Invalid y coordinate"); +// valid = false; +// } +// } +// idChecker.clear(); +// } +// else +// static_cast(pokemod())->validationMsg("There are no effects", Pokemod::V_Warn); +// if (trainerCount()) +// { +// foreach (MapTrainer* trainer, m_trainers) +// { +// if (!trainer->isValid()) +// valid = false; +// if (idChecker[trainer->id()]) +// static_cast(pokemod())->validationMsg(QString("Duplicate trainer with id %1").arg(trainer->id())); +// idChecker[trainer->id()] = true; +// if (width() <= trainer->coordinate().x()) +// { +// static_cast(pokemod())->validationMsg("Invalid x coordinate"); +// valid = false; +// } +// if (height() <= trainer->coordinate().y()) +// { +// static_cast(pokemod())->validationMsg("Invalid y coordinate"); +// valid = false; +// } +// } +// idChecker.clear(); +// } +// else +// static_cast(pokemod())->validationMsg("There are no trainers", Pokemod::V_Warn); +// if (warpCount()) +// { +// foreach (MapWarp* warp, m_warps) +// { +// if (!warp->isValid()) +// valid = false; +// if (idChecker[warp->id()]) +// static_cast(pokemod())->validationMsg(QString("Duplicate warp with id %1").arg(warp->id())); +// idChecker[warp->id()] = true; +// if (width() <= warp->coordinate().x()) +// { +// static_cast(pokemod())->validationMsg("Invalid x coordinate"); +// valid = false; +// } +// if (height() <= warp->coordinate().y()) +// { +// static_cast(pokemod())->validationMsg("Invalid y coordinate"); +// valid = false; +// } +// } +// idChecker.clear(); +// } +// else +// { +// static_cast(pokemod())->validationMsg("There are no warps"); +// valid = false; +// } +// if (wildListCount()) +// { +// foreach (MapWildList* wildList, m_wildLists) +// { +// if (!wildList->isValid()) +// valid = false; +// if (idChecker[wildList->id()]) +// static_cast(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(wildList->id())); +// idChecker[wildList->id()] = true; +// } +// } +// else +// static_cast(pokemod())->validationMsg("There are no effects", Pokemod::V_Warn); +// for (int i = 0; i < width(); ++i) +// { +// for (int j = 0; j < height(); ++j) +// { +// if (static_cast(pokemod())->tileIndex(m_tile(i, j)) == INT_MAX) +// { +// static_cast(pokemod())->validationMsg(QString("Invalid tile at (%1, %2)").arg(i).arg(j)); +// valid = false; +// } +// } +// } +// return valid; } void Map::load(const QDomElement& xml, int id) @@ -246,7 +247,7 @@ int Map::type() const void Map::setTile(int x, int y, int id) throw(BoundsException) { - if (pokemod()->tileIndex(id) == INT_MAX) + if (static_cast(pokemod())->tileIndex(id) == INT_MAX) error("tile"); m_tile(x, y) = id; } @@ -347,19 +348,19 @@ int Map::effectCount() const MapEffect* Map::newEffect() { - m_effects.append(new MapEffect(pokemod(), newEffectId())); + m_effects.append(new MapEffect(this, newEffectId())); return m_effects[effectCount() - 1]; } MapEffect* Map::newEffect(const QDomElement& xml) { - m_effects.append(new MapEffect(xml, pokemod(), newEffectId())); + m_effects.append(new MapEffect(xml, this, newEffectId())); return m_effects[effectCount() - 1]; } MapEffect* Map::newEffect(const MapEffect& effect) { - m_effects.append(new MapEffect(effect, pokemod(), newEffectId())); + m_effects.append(new MapEffect(effect, this, newEffectId())); return m_effects[effectCount() - 1]; } @@ -425,19 +426,19 @@ int Map::trainerCount() const MapTrainer* Map::newTrainer() { - m_trainers.append(new MapTrainer(pokemod(), newTrainerId())); + m_trainers.append(new MapTrainer(this, newTrainerId())); return m_trainers[trainerCount() - 1]; } MapTrainer* Map::newTrainer(const QDomElement& xml) { - m_trainers.append(new MapTrainer(xml, pokemod(), newTrainerId())); + m_trainers.append(new MapTrainer(xml, this, newTrainerId())); return m_trainers[trainerCount() - 1]; } MapTrainer* Map::newTrainer(const MapTrainer& trainer) { - m_trainers.append(new MapTrainer(trainer, pokemod(), newTrainerId())); + m_trainers.append(new MapTrainer(trainer, this, newTrainerId())); return m_trainers[trainerCount() - 1]; } @@ -503,19 +504,19 @@ int Map::warpCount() const MapWarp* Map::newWarp() { - m_warps.append(new MapWarp(pokemod(), newWarpId())); + m_warps.append(new MapWarp(this, newWarpId())); return m_warps[warpCount() - 1]; } MapWarp* Map::newWarp(const QDomElement& xml) { - m_warps.append(new MapWarp(xml, pokemod(), newWarpId())); + m_warps.append(new MapWarp(xml, this, newWarpId())); return m_warps[warpCount() - 1]; } MapWarp* Map::newWarp(const MapWarp& warp) { - m_warps.append(new MapWarp(warp, pokemod(), newWarpId())); + m_warps.append(new MapWarp(warp, this, newWarpId())); return m_warps[warpCount() - 1]; } @@ -581,19 +582,19 @@ int Map::wildListCount() const MapWildList* Map::newWildList() { - m_wildLists.append(new MapWildList(pokemod(), newWildListId())); + m_wildLists.append(new MapWildList(this, newWildListId())); return m_wildLists[wildListCount() - 1]; } MapWildList* Map::newWildList(const QDomElement& xml) { - m_wildLists.append(new MapWildList(xml, pokemod(), newWildListId())); + m_wildLists.append(new MapWildList(xml, this, newWildListId())); return m_wildLists[wildListCount() - 1]; } MapWildList* Map::newWildList(const MapWildList& wildList) { - m_wildLists.append(new MapWildList(wildList, pokemod(), newWildListId())); + m_wildLists.append(new MapWildList(wildList, this, newWildListId())); return m_wildLists[wildListCount() - 1]; } -- cgit