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/MapWarp.cpp | 117 +++++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 57 deletions(-) (limited to 'pokemod/MapWarp.cpp') diff --git a/pokemod/MapWarp.cpp b/pokemod/MapWarp.cpp index 0dc045e9..15e6ee38 100644 --- a/pokemod/MapWarp.cpp +++ b/pokemod/MapWarp.cpp @@ -15,24 +15,24 @@ * with this program. If not, see . */ +// Header include +#include "MapWarp.h" + // Pokemod includes -#include "Pokemod.h" #include "Dialog.h" #include "Map.h" - -// Header include -#include "MapWarp.h" +#include "Pokemod.h" const QStringList MapWarp::TypeStr = QStringList() << "Door/Stair" << "Warp Pad" << "Hole" << "Boundary"; MapWarp::MapWarp(const MapWarp& warp) : - Object("MapWarp", warp.pokemod(), warp.id()) + Object("MapWarp", warp.parent(), warp.id()) { *this = warp; } -MapWarp::MapWarp(const Pokemod* pokemod, const int id) : - Object("MapWarp", pokemod, id), +MapWarp::MapWarp(const Object* parent, const int id) : + Object("MapWarp", parent, id), m_name(""), m_coordinate(0, 0), m_directionOut(INT_MAX), @@ -49,61 +49,62 @@ MapWarp::MapWarp(const Pokemod* pokemod, const int id) : m_from[i] = false; } -MapWarp::MapWarp(const MapWarp& warp, const Pokemod* pokemod, const int id) : - Object("MapWarp", pokemod, id) +MapWarp::MapWarp(const MapWarp& warp, const Object* parent, const int id) : + Object("MapWarp", parent, id) { *this = warp; } -MapWarp::MapWarp(const QDomElement& xml, const Pokemod* pokemod, const int id) : - Object("MapWarp", pokemod, id) +MapWarp::MapWarp(const QDomElement& xml, const Object* parent, const int id) : + Object("MapWarp", parent, id) { load(xml, id); } bool MapWarp::validate() const { - bool valid = true; - pokemod()->validationMsg(QString("------Warp \"%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_from[Pokemod::D_Up] && !m_from[Pokemod::D_Down] && !m_from[Pokemod::D_Left] && !m_from[Pokemod::D_Right]) - { - pokemod()->validationMsg("No access from any direction"); - valid = false; - } - if (Pokemod::D_End_None <= m_directionOut) - { - pokemod()->validationMsg("Invalid direction out"); - valid = false; - } - if (End <= m_warpType) - { - pokemod()->validationMsg("Invalid type"); - valid = false; - } - if (pokemod()->mapIndex(m_toMap) != INT_MAX) - { - if (pokemod()->mapById(m_toMap)->warpIndex(m_toWarp) == INT_MAX) - { - pokemod()->validationMsg("Invalid destination warp"); - valid = false; - } - } - else - { - pokemod()->validationMsg("Invalid destination map"); - valid = false; - } - if (pokemod()->dialogIndex(m_dialog) == INT_MAX) - { - pokemod()->validationMsg("Invalid dialog"); - valid = false; - } - return valid; + // TODO: validate +// bool valid = true; +// static_cast(pokemod())->validationMsg(QString("------Warp \"%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_from[Pokemod::D_Up] && !m_from[Pokemod::D_Down] && !m_from[Pokemod::D_Left] && !m_from[Pokemod::D_Right]) +// { +// static_cast(pokemod())->validationMsg("No access from any direction"); +// valid = false; +// } +// if (Pokemod::D_End_None <= m_directionOut) +// { +// static_cast(pokemod())->validationMsg("Invalid direction out"); +// valid = false; +// } +// if (End <= m_warpType) +// { +// static_cast(pokemod())->validationMsg("Invalid type"); +// valid = false; +// } +// if (static_cast(pokemod())->mapIndex(m_toMap) != INT_MAX) +// { +// if (static_cast(pokemod())->mapById(m_toMap)->warpIndex(m_toWarp) == INT_MAX) +// { +// static_cast(pokemod())->validationMsg("Invalid destination warp"); +// valid = false; +// } +// } +// else +// { +// static_cast(pokemod())->validationMsg("Invalid destination map"); +// valid = false; +// } +// if (static_cast(pokemod())->dialogIndex(m_dialog) == INT_MAX) +// { +// static_cast(pokemod())->validationMsg("Invalid dialog"); +// valid = false; +// } +// return valid; } void MapWarp::load(const QDomElement& xml, int id) @@ -146,8 +147,10 @@ void MapWarp::setName(const QString& name) m_name = name; } -void MapWarp::setCoordinate(const Point& coordinate) +void MapWarp::setCoordinate(const Point& coordinate) throw(BoundsException) { + if ((static_cast(parent())->width() <= coordinate.x()) || (static_cast(parent())->height() <= coordinate.y())) + error("coordinate"); m_coordinate = coordinate; } @@ -195,7 +198,7 @@ void MapWarp::setIsFoggy(const int isFoggy) throw(BoundsException) void MapWarp::setToMap(const int toMap) throw(BoundsException) { - if (pokemod()->mapIndex(toMap) == INT_MAX) + if (static_cast(pokemod())->mapIndex(toMap) == INT_MAX) error("toMap"); m_toMap = toMap; m_toWarp = INT_MAX; @@ -203,9 +206,9 @@ void MapWarp::setToMap(const int toMap) throw(BoundsException) void MapWarp::setToWarp(const int toWarp) throw(BoundsException) { - if (pokemod()->mapIndex(m_toMap) == INT_MAX) + if (static_cast(pokemod())->mapIndex(m_toMap) == INT_MAX) error("toMap"); - if (pokemod()->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) + if (static_cast(pokemod())->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) error("toWarp"); m_toWarp = toWarp; } @@ -217,7 +220,7 @@ void MapWarp::setWorkingFlag(const Flag& workingFlag) void MapWarp::setDialog(const int dialog) throw(BoundsException) { - if (pokemod()->dialogIndex(dialog) == INT_MAX) + if (static_cast(pokemod())->dialogIndex(dialog) == INT_MAX) error("dialog"); m_dialog = dialog; } -- cgit