summaryrefslogtreecommitdiffstats
path: root/pokemod/MapWarp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemod/MapWarp.cpp')
-rw-r--r--pokemod/MapWarp.cpp152
1 files changed, 77 insertions, 75 deletions
diff --git a/pokemod/MapWarp.cpp b/pokemod/MapWarp.cpp
index 15e6ee38..3cf1e0b0 100644
--- a/pokemod/MapWarp.cpp
+++ b/pokemod/MapWarp.cpp
@@ -36,7 +36,7 @@ MapWarp::MapWarp(const Object* parent, const int id) :
m_name(""),
m_coordinate(0, 0),
m_directionOut(INT_MAX),
- m_warpType(INT_MAX),
+ m_type(INT_MAX),
m_isBiking(Flag::Ignore),
m_isFlash(Flag::Ignore),
m_isFoggy(Flag::Ignore),
@@ -61,50 +61,18 @@ MapWarp::MapWarp(const QDomElement& xml, const Object* parent, const int id) :
load(xml, id);
}
-bool MapWarp::validate() const
-{
- // TODO: validate
-// bool valid = true;
-// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Warp \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg);
-// if (m_name == "")
-// {
-// static_cast<const Pokemod*>(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<const Pokemod*>(pokemod())->validationMsg("No access from any direction");
-// valid = false;
-// }
-// if (Pokemod::D_End_None <= m_directionOut)
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid direction out");
-// valid = false;
-// }
-// if (End <= m_warpType)
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid type");
-// valid = false;
-// }
-// if (static_cast<const Pokemod*>(pokemod())->mapIndex(m_toMap) != INT_MAX)
-// {
-// if (static_cast<const Pokemod*>(pokemod())->mapById(m_toMap)->warpIndex(m_toWarp) == INT_MAX)
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid destination warp");
-// valid = false;
-// }
-// }
-// else
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid destination map");
-// valid = false;
-// }
-// if (static_cast<const Pokemod*>(pokemod())->dialogIndex(m_dialog) == INT_MAX)
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid dialog");
-// valid = false;
-// }
-// return valid;
+void MapWarp::validate(QTextStream& stream)
+{
+ TEST_SETUP();
+ if (m_name.isEmpty())
+ error(stream, "Name is empty");
+ if (!m_from[Pokemod::D_Up] && !m_from[Pokemod::D_Down] && !m_from[Pokemod::D_Left] && !m_from[Pokemod::D_Right])
+ error(stream, "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)
@@ -114,7 +82,7 @@ void MapWarp::load(const QDomElement& xml, int id)
LOAD(Point, coordinate);
LOAD_ARRAY(bool, from, Pokemod::D_End);
LOAD(int, directionOut);
- LOAD(int, warpType);
+ LOAD(int, type);
LOAD(bool, isBiking);
LOAD(bool, isFlash);
LOAD(bool, isFoggy);
@@ -131,7 +99,7 @@ QDomElement MapWarp::save() const
SAVE(Point, coordinate);
SAVE_ARRAY(bool, from, Pokemod::D_End);
SAVE(int, directionOut);
- SAVE(int, warpType);
+ SAVE(int, type);
SAVE(bool, isBiking);
SAVE(bool, isFlash);
SAVE(bool, isFoggy);
@@ -147,69 +115,99 @@ void MapWarp::setName(const QString& name)
m_name = name;
}
-void MapWarp::setCoordinate(const Point& coordinate) throw(BoundsException)
+void MapWarp::setCoordinate(const Point& coordinate)
{
if ((static_cast<const Map*>(parent())->width() <= coordinate.x()) || (static_cast<const Map*>(parent())->height() <= coordinate.y()))
- error<BoundsException>("coordinate");
+ {
+ boundsError("coordinate");
+ return;
+ }
m_coordinate = coordinate;
}
-void MapWarp::setFrom(const int direction, const bool can) throw(BoundsException)
+void MapWarp::setFrom(const int direction, const bool can)
{
if (Pokemod::D_End <= direction)
- error<BoundsException>("direction");
+ {
+ boundsError("direction");
+ return;
+ }
m_from[direction] = can;
}
-void MapWarp::setDirectionOut(const int directionOut) throw(BoundsException)
+void MapWarp::setDirectionOut(const int directionOut)
{
if (Pokemod::D_End <= directionOut)
- error<BoundsException>("direction");
+ {
+ boundsError("direction");
+ return;
+ }
m_directionOut = directionOut;
}
-void MapWarp::setWarpType(const int warpType) throw(BoundsException)
+void MapWarp::setType(const int type)
{
- if (End <= warpType)
- error<BoundsException>("warpType");
- m_warpType = warpType;
+ if (End <= type)
+ {
+ boundsError("type");
+ return;
+ }
+ m_type = type;
}
-void MapWarp::setIsBiking(const int isBiking) throw(BoundsException)
+void MapWarp::setIsBiking(const int isBiking)
{
if (Flag::End <= isBiking)
- error<BoundsException>("isBiking");
+ {
+ boundsError("isBiking");
+ return;
+ }
m_isBiking = isBiking;
}
-void MapWarp::setIsFlash(const int isFlash) throw(BoundsException)
+void MapWarp::setIsFlash(const int isFlash)
{
if (Flag::End <= isFlash)
- error<BoundsException>("isFlash");
+ {
+ boundsError("isFlash");
+ return;
+ }
m_isFlash = isFlash;
}
-void MapWarp::setIsFoggy(const int isFoggy) throw(BoundsException)
+void MapWarp::setIsFoggy(const int isFoggy)
{
if (Flag::End <= isFoggy)
- error<BoundsException>("isFoggy");
+ {
+ boundsError("isFoggy");
+ return;
+ }
m_isFoggy = isFoggy;
}
-void MapWarp::setToMap(const int toMap) throw(BoundsException)
+void MapWarp::setToMap(const int toMap)
{
if (static_cast<const Pokemod*>(pokemod())->mapIndex(toMap) == INT_MAX)
- error<BoundsException>("toMap");
+ {
+ boundsError("toMap");
+ return;
+ }
m_toMap = toMap;
m_toWarp = INT_MAX;
}
-void MapWarp::setToWarp(const int toWarp) throw(BoundsException)
+void MapWarp::setToWarp(const int toWarp)
{
if (static_cast<const Pokemod*>(pokemod())->mapIndex(m_toMap) == INT_MAX)
- error<BoundsException>("toMap");
+ {
+ boundsError("toMap");
+ return;
+ }
if (static_cast<const Pokemod*>(pokemod())->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX)
- error<BoundsException>("toWarp");
+ {
+ boundsError("toWarp");
+ return;
+ }
m_toWarp = toWarp;
}
@@ -218,10 +216,13 @@ void MapWarp::setWorkingFlag(const Flag& workingFlag)
m_workingFlag = workingFlag;
}
-void MapWarp::setDialog(const int dialog) throw(BoundsException)
+void MapWarp::setDialog(const int dialog)
{
if (static_cast<const Pokemod*>(pokemod())->dialogIndex(dialog) == INT_MAX)
- error<BoundsException>("dialog");
+ {
+ boundsError("dialog");
+ return;
+ }
m_dialog = dialog;
}
@@ -235,10 +236,11 @@ Point MapWarp::coordinate() const
return m_coordinate;
}
-bool MapWarp::from(const int direction) const throw(BoundsException)
+bool MapWarp::from(const int direction) const
{
+ // TODO: Message about fetching out-of-bounds
if (Pokemod::D_End <= direction)
- warning<BoundsException>("direction");
+ return false;
return m_from[direction];
}
@@ -247,9 +249,9 @@ int MapWarp::directionOut() const
return m_directionOut;
}
-int MapWarp::warpType() const
+int MapWarp::type() const
{
- return m_warpType;
+ return m_type;
}
int MapWarp::isBiking() const
@@ -295,7 +297,7 @@ MapWarp& MapWarp::operator=(const MapWarp& rhs)
COPY(coordinate);
COPY_ARRAY(from, Pokemod::D_End);
COPY(directionOut);
- COPY(warpType);
+ COPY(type);
COPY(isBiking);
COPY(isFlash);
COPY(isFoggy);