summaryrefslogtreecommitdiffstats
path: root/pokemod/Map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemod/Map.cpp')
-rw-r--r--pokemod/Map.cpp306
1 files changed, 131 insertions, 175 deletions
diff --git a/pokemod/Map.cpp b/pokemod/Map.cpp
index d1aece20..429b3d0f 100644
--- a/pokemod/Map.cpp
+++ b/pokemod/Map.cpp
@@ -25,6 +25,9 @@
#include "MapWildList.h"
#include "Pokemod.h"
+// Qt includes
+#include <QSet>
+
const QStringList Map::TypeStr = QStringList() << "Outdoor" << "Dungeon" << "Building";
Map::Map(const Map& map) :
@@ -58,127 +61,71 @@ Map::~Map()
clear();
}
-bool Map::validate() const
-{
- // TODO: validate
-// bool valid = true;
-// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Map \"%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_flyWarp != INT_MAX) && (warpIndex(m_flyWarp) == INT_MAX))
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid fly destination warp");
-// valid = false;
-// }
-// if (m_type < End)
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid type");
-// valid = false;
-// }
-// QMap<int, bool> idChecker;
-// if (effectCount())
-// {
-// foreach (MapEffect* effect, m_effects)
-// {
-// if (!effect->isValid())
-// valid = false;
-// if (idChecker[effect->id()])
-// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(effect->id()));
-// idChecker[effect->id()] = true;
-// if (width() <= effect->coordinate().x())
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid x coordinate");
-// valid = false;
-// }
-// if (height() <= effect->coordinate().y())
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid y coordinate");
-// valid = false;
-// }
-// }
-// idChecker.clear();
-// }
-// else
-// static_cast<const Pokemod*>(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<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate trainer with id %1").arg(trainer->id()));
-// idChecker[trainer->id()] = true;
-// if (width() <= trainer->coordinate().x())
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid x coordinate");
-// valid = false;
-// }
-// if (height() <= trainer->coordinate().y())
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid y coordinate");
-// valid = false;
-// }
-// }
-// idChecker.clear();
-// }
-// else
-// static_cast<const Pokemod*>(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<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate warp with id %1").arg(warp->id()));
-// idChecker[warp->id()] = true;
-// if (width() <= warp->coordinate().x())
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid x coordinate");
-// valid = false;
-// }
-// if (height() <= warp->coordinate().y())
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid y coordinate");
-// valid = false;
-// }
-// }
-// idChecker.clear();
-// }
-// else
-// {
-// static_cast<const Pokemod*>(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<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(wildList->id()));
-// idChecker[wildList->id()] = true;
-// }
-// }
-// else
-// static_cast<const Pokemod*>(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<const Pokemod*>(pokemod())->tileIndex(m_tile(i, j)) == INT_MAX)
-// {
-// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Invalid tile at (%1, %2)").arg(i).arg(j));
-// valid = false;
-// }
-// }
-// }
-// return valid;
+void Map::validate(QTextStream& stream)
+{
+ // TODO: validate that every tile that can have a wild encounter has a list to go along with it
+ TEST_SETUP();
+ if (m_name.isEmpty())
+ error(stream, "Name is empty");
+ TEST(setFlyWarp, flyWarp);
+ TEST(setType, type);
+ TEST_MATRIX(setTile, tile);
+ QSet<int> idChecker;
+ QSet<QString> nameChecker;
+ if (!effectCount())
+ warning(stream, "There are no effects");
+ foreach (MapEffect* effect, m_effects)
+ {
+ if (!effect->isValid(stream))
+ setValid(false);
+ if (idChecker.contains(effect->id()))
+ subclassError(stream, "effect", effect->id());
+ idChecker.insert(effect->id());
+ if (nameChecker.contains(effect->name()))
+ subclassError(stream, "effect", effect->name());
+ nameChecker.insert(effect->name());
+ }
+ idChecker.clear();
+ nameChecker.clear();
+ if (!trainerCount())
+ warning(stream, "There are no trainers");
+ foreach (MapTrainer* trainer, m_trainers)
+ {
+ if (!trainer->isValid(stream))
+ setValid(false);
+ if (idChecker.contains(trainer->id()))
+ subclassError(stream, "trainer", trainer->id());
+ idChecker.insert(trainer->id());
+ if (nameChecker.contains(trainer->name()))
+ subclassError(stream, "trainer", trainer->name());
+ nameChecker.insert(trainer->name());
+ }
+ idChecker.clear();
+ nameChecker.clear();
+ if (!warpCount())
+ error(stream, "There are no warps");
+ foreach (MapWarp* warp, m_warps)
+ {
+ if (!warp->isValid(stream))
+ setValid(false);
+ if (idChecker.contains(warp->id()))
+ subclassError(stream, "warp", warp->id());
+ idChecker.insert(warp->id());
+ if (nameChecker.contains(warp->name()))
+ subclassError(stream, "warp", warp->name());
+ nameChecker.insert(warp->name());
+ }
+ idChecker.clear();
+ if (!wildListCount())
+ error(stream, "There are no wild lists");
+ foreach (MapWildList* wildList, m_wildLists)
+ {
+ if (!wildList->isValid(stream))
+ setValid(false);
+ if (idChecker.contains(wildList->id()))
+ subclassError(stream, "effect", wildList->id());
+ idChecker.insert(wildList->id());
+ }
}
void Map::load(const QDomElement& xml, int id)
@@ -213,17 +160,23 @@ void Map::setName(const QString& name)
m_name = name;
}
-void Map::setFlyWarp(const int warp) throw(BoundsException)
+void Map::setFlyWarp(const int warp)
{
if ((warp != INT_MAX) && (warpIndex(warp) == INT_MAX))
- error<BoundsException>("warp");
+ {
+ boundsError("warp");
+ return;
+ }
m_flyWarp = warp;
}
-void Map::setType(const int type) throw(BoundsException)
+void Map::setType(const int type)
{
if (End <= type)
- error<BoundsException>("type");
+ {
+ boundsError("type");
+ return;
+ }
m_type = type;
}
@@ -242,21 +195,24 @@ int Map::type() const
return m_type;
}
-void Map::setTile(int x, int y, int id) throw(BoundsException)
+void Map::setTile(const int row, const int column, const int tile)
{
- if (static_cast<const Pokemod*>(pokemod())->tileIndex(id) == INT_MAX)
- error<BoundsException>("tile");
- m_tile(x, y) = id;
+ if (static_cast<const Pokemod*>(pokemod())->tileIndex(tile) == INT_MAX)
+ {
+ boundsError("tile");
+ return;
+ }
+ m_tile.set(row, column, tile);
}
-void Map::insertColumn(int x)
+void Map::insertColumn(const int column)
{
- m_tile.insertColumn(x, 0);
+ m_tile.insertColumn(column, 0);
}
-void Map::insertRow(int y)
+void Map::insertRow(const int row)
{
- m_tile.insertRow(y, 0);
+ m_tile.insertRow(row, 0);
}
void Map::addColumn()
@@ -269,14 +225,14 @@ void Map::addRow()
m_tile.addRow(0);
}
-void Map::deleteColumn(int x)
+void Map::deleteColumn(const int column)
{
- m_tile.deleteColumn(x);
+ m_tile.deleteColumn(column);
}
-void Map::deleteRow(int y)
+void Map::deleteRow(const int row)
{
- m_tile.deleteRow(y);
+ m_tile.deleteRow(row);
}
const Matrix<int>* Map::map() const
@@ -289,9 +245,9 @@ Matrix<int>* Map::map()
return &m_tile;
}
-int Map::tile(int x, int y) const
+int Map::tile(const int row, const int column) const
{
- return m_tile(x, y);
+ return m_tile.at(row, column);
}
int Map::width() const
@@ -304,26 +260,26 @@ int Map::height() const
return m_tile.height();
}
-const MapEffect* Map::effect(const int index) const throw(IndexException)
+const MapEffect* Map::effect(const int index) const
{
if (effectCount() <= index)
- warning<IndexException>("effect");
+ return NULL;
return m_effects.at(index);
}
-MapEffect* Map::effect(const int index) throw(IndexException)
+MapEffect* Map::effect(const int index)
{
if (effectCount() <= index)
- error<IndexException>("effect");
+ return NULL;
return m_effects[index];
}
-const MapEffect* Map::effectById(const int index) const throw(IndexException)
+const MapEffect* Map::effectById(const int index) const
{
return effect(effectIndex(index));
}
-MapEffect* Map::effectById(const int index) throw(IndexException)
+MapEffect* Map::effectById(const int index)
{
return effect(effectIndex(index));
}
@@ -364,15 +320,15 @@ MapEffect* Map::newEffect(MapEffect* effect)
return effect;
}
-void Map::deleteEffect(const int index) throw(IndexException)
+void Map::deleteEffect(const int index)
{
if (effectCount() <= index)
- error<IndexException>("effect");
+ return;
delete m_effects[index];
m_effects.removeAt(index);
}
-void Map::deleteEffectById(const int id) throw(IndexException)
+void Map::deleteEffectById(const int id)
{
deleteEffect(effectIndex(id));
}
@@ -385,26 +341,26 @@ int Map::newEffectId() const
return i;
}
-const MapTrainer* Map::trainer(const int index) const throw(IndexException)
+const MapTrainer* Map::trainer(const int index) const
{
if (trainerCount() <= index)
- warning<IndexException>("trainer");
+ return NULL;
return m_trainers.at(index);
}
-MapTrainer* Map::trainer(const int index) throw(IndexException)
+MapTrainer* Map::trainer(const int index)
{
if (trainerCount() <= index)
- error<IndexException>("trainer");
+ return NULL;
return m_trainers[index];
}
-const MapTrainer* Map::trainerById(const int id) const throw(IndexException)
+const MapTrainer* Map::trainerById(const int id) const
{
return trainer(trainerIndex(id));
}
-MapTrainer* Map::trainerById(const int id) throw(IndexException)
+MapTrainer* Map::trainerById(const int id)
{
return trainer(trainerIndex(id));
}
@@ -445,15 +401,15 @@ MapTrainer* Map::newTrainer(MapTrainer* trainer)
return trainer;
}
-void Map::deleteTrainer(const int index) throw(IndexException)
+void Map::deleteTrainer(const int index)
{
if (trainerCount() <= index)
- error<IndexException>("trainer");
+ return;
delete m_trainers[index];
m_trainers.removeAt(index);
}
-void Map::deleteTrainerById(const int id) throw(IndexException)
+void Map::deleteTrainerById(const int id)
{
deleteTrainer(trainerIndex(id));
}
@@ -466,26 +422,26 @@ int Map::newTrainerId() const
return i;
}
-const MapWarp* Map::warp(const int index) const throw(IndexException)
+const MapWarp* Map::warp(const int index) const
{
if (warpCount() <= index)
- warning<IndexException>("warp");
+ return NULL;
return m_warps.at(index);
}
-MapWarp* Map::warp(const int index) throw(IndexException)
+MapWarp* Map::warp(const int index)
{
if (warpCount() <= index)
- error<IndexException>("warp");
+ return NULL;
return m_warps[index];
}
-const MapWarp* Map::warpById(const int id) const throw(IndexException)
+const MapWarp* Map::warpById(const int id) const
{
return warp(warpIndex(id));
}
-MapWarp* Map::warpById(const int id) throw(IndexException)
+MapWarp* Map::warpById(const int id)
{
return warp(warpIndex(id));
}
@@ -526,15 +482,15 @@ MapWarp* Map::newWarp(MapWarp* warp)
return warp;
}
-void Map::deleteWarp(const int index) throw(IndexException)
+void Map::deleteWarp(const int index)
{
if (warpCount() <= index)
- error<IndexException>("warp");
+ return;
delete m_warps[index];
m_warps.removeAt(index);
}
-void Map::deleteWarpById(const int id) throw(IndexException)
+void Map::deleteWarpById(const int id)
{
deleteWarp(warpIndex(id));
}
@@ -547,26 +503,26 @@ int Map::newWarpId() const
return i;
}
-const MapWildList* Map::wildList(const int index) const throw(IndexException)
+const MapWildList* Map::wildList(const int index) const
{
if (wildListCount() <= index)
- warning<IndexException>("wild list");
+ return NULL;
return m_wildLists.at(index);
}
-MapWildList* Map::wildList(const int index) throw(IndexException)
+MapWildList* Map::wildList(const int index)
{
if (wildListCount() <= index)
- error<IndexException>("wild list");
+ return NULL;
return m_wildLists[index];
}
-const MapWildList* Map::wildListById(const int id) const throw(IndexException)
+const MapWildList* Map::wildListById(const int id) const
{
return wildList(wildListIndex(id));
}
-MapWildList* Map::wildListById(const int id) throw(IndexException)
+MapWildList* Map::wildListById(const int id)
{
return wildList(wildListIndex(id));
}
@@ -607,15 +563,15 @@ MapWildList* Map::newWildList(MapWildList* wildList)
return wildList;
}
-void Map::deleteWildList(const int index) throw(IndexException)
+void Map::deleteWildList(const int index)
{
if (wildListCount() <= index)
- error<IndexException>("wild list");
+ return;
delete m_wildLists[index];
m_wildLists.removeAt(index);
}
-void Map::deleteWildListById(const int id) throw(IndexException)
+void Map::deleteWildListById(const int id)
{
deleteWildList(wildListIndex(id));
}