summaryrefslogtreecommitdiffstats
path: root/sigmod/Map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sigmod/Map.cpp')
-rw-r--r--sigmod/Map.cpp512
1 files changed, 33 insertions, 479 deletions
diff --git a/sigmod/Map.cpp b/sigmod/Map.cpp
index 667b5524..af58d36f 100644
--- a/sigmod/Map.cpp
+++ b/sigmod/Map.cpp
@@ -71,12 +71,10 @@ void Sigmod::Map::validate()
TEST_BEGIN();
if (m_name.isEmpty())
emit(error("Name is empty"));
- TEST(setFlyWarp, flyWarp);
- TEST(setType, type);
- if (!m_width)
- emit(error("Map has no width"));
- if (!m_height)
- emit(error("Map has no height"));
+ TEST(flyWarp);
+ TEST(type);
+ TEST(width);
+ TEST(height);
QSet<int> idChecker;
QSet<QString> nameChecker;
if (!effectCount())
@@ -147,474 +145,35 @@ QDomElement Sigmod::Map::save() const
return xml;
}
-void Sigmod::Map::setName(const QString& name)
-{
- CHECK(name);
-}
-
-void Sigmod::Map::setFlyWarp(const int flyWarp)
-{
- if ((flyWarp != -1) && !warpById(flyWarp))
- emit(error(bounds("flyWarp", flyWarp)));
- else
- CHECK(flyWarp);
-}
-
-void Sigmod::Map::setType(const Type type)
-{
- CHECK(type);
-}
-
-void Sigmod::Map::setWidth(const int width)
-{
- if (width <= 0)
- emit(error(bounds("width", 1, INT_MAX, width)));
- else
- CHECK(width);
-}
+SETTER(Map, QString&, Name, name)
+SETTER(Map, int, FlyWarp, flyWarp)
+SETTER(Map, Type, Type, type)
+SETTER(Map, int, Width, width)
+SETTER(Map, int, Height, height)
-void Sigmod::Map::setHeight(const int height)
-{
- if (height <= 0)
- emit(error(bounds("height", 1, INT_MAX, height)));
- else
- CHECK(height);
-}
-
-QString Sigmod::Map::name() const
-{
- return m_name;
-}
-
-int Sigmod::Map::flyWarp() const
-{
- return m_flyWarp;
-}
-
-Sigmod::Map::Type Sigmod::Map::type() const
-{
- return m_type;
-}
-
-int Sigmod::Map::width() const
-{
- return m_width;
-}
-
-int Sigmod::Map::height() const
-{
- return m_height;
-}
-
-const Sigmod::MapEffect* Sigmod::Map::effect(const int index) const
-{
- if (index < effectCount())
- return m_effects.at(index);
- return NULL;
-}
-
-Sigmod::MapEffect* Sigmod::Map::effect(const int index)
-{
- if (index < effectCount())
- return m_effects[index];
- return NULL;
-}
-
-const Sigmod::MapEffect* Sigmod::Map::effectById(const int index) const
-{
- return effect(effectIndex(index));
-}
-
-Sigmod::MapEffect* Sigmod::Map::effectById(const int index)
-{
- return effect(effectIndex(index));
-}
-
-int Sigmod::Map::effectIndex(const int id) const
-{
- for (int i = 0; i < effectCount(); ++i)
- {
- if (m_effects[i]->id() == id)
- return i;
- }
- return INT_MAX;
-}
-
-int Sigmod::Map::effectCount() const
-{
- return m_effects.size();
-}
-
-Sigmod::MapEffect* Sigmod::Map::newEffect()
-{
- return newEffect(new MapEffect(this, newEffectId()));
-}
-
-Sigmod::MapEffect* Sigmod::Map::newEffect(const QDomElement& xml)
-{
- return newEffect(new MapEffect(xml, this, newEffectId()));
-}
-
-Sigmod::MapEffect* Sigmod::Map::newEffect(const MapEffect& effect)
-{
- return newEffect(new MapEffect(effect, this, newEffectId()));
-}
-
-Sigmod::MapEffect* Sigmod::Map::newEffect(MapEffect* effect)
-{
- m_effects.append(effect);
- return effect;
-}
-
-void Sigmod::Map::deleteEffect(const int index)
-{
- if (index < effectCount())
- {
- delete m_effects[index];
- m_effects.removeAt(index);
- }
-}
-
-void Sigmod::Map::deleteEffectById(const int id)
-{
- deleteEffect(effectIndex(id));
-}
-
-int Sigmod::Map::newEffectId() const
-{
- int i = 0;
- while ((i < effectCount()) && (effectIndex(i) != INT_MAX))
- ++i;
- return i;
-}
-
-const Sigmod::MapTile* Sigmod::Map::tile(const int index) const
-{
- if (index < tileCount())
- return m_tiles.at(index);
- return NULL;
-}
-
-Sigmod::MapTile* Sigmod::Map::tile(const int index)
-{
- if (index < tileCount())
- return m_tiles[index];
- return NULL;
-}
-
-const Sigmod::MapTile* Sigmod::Map::tileById(const int index) const
-{
- return tile(tileIndex(index));
-}
-
-Sigmod::MapTile* Sigmod::Map::tileById(const int index)
-{
- return tile(tileIndex(index));
-}
-
-int Sigmod::Map::tileIndex(const int id) const
-{
- for (int i = 0; i < tileCount(); ++i)
- {
- if (m_tiles[i]->id() == id)
- return i;
- }
- return INT_MAX;
-}
-
-int Sigmod::Map::tileCount() const
-{
- return m_tiles.size();
-}
-
-Sigmod::MapTile* Sigmod::Map::newTile()
-{
- return newTile(new MapTile(this, newTileId()));
-}
-
-Sigmod::MapTile* Sigmod::Map::newTile(const QDomElement& xml)
-{
- return newTile(new MapTile(xml, this, newTileId()));
-}
-
-Sigmod::MapTile* Sigmod::Map::newTile(const MapTile& tile)
-{
- return newTile(new MapTile(tile, this, newTileId()));
-}
-
-Sigmod::MapTile* Sigmod::Map::newTile(MapTile* tile)
-{
- m_tiles.append(tile);
- return tile;
-}
-
-void Sigmod::Map::deleteTile(const int index)
-{
- if (index < tileCount())
- {
- delete m_tiles[index];
- m_tiles.removeAt(index);
- }
-}
-
-void Sigmod::Map::deleteTileById(const int id)
-{
- deleteTile(tileIndex(id));
-}
-
-int Sigmod::Map::newTileId() const
-{
- int i = 0;
- while ((i < tileCount()) && (tileIndex(i) != INT_MAX))
- ++i;
- return i;
-}
-
-const Sigmod::MapTrainer* Sigmod::Map::trainer(const int index) const
-{
- if (index < trainerCount())
- return m_trainers.at(index);
- return NULL;
-}
-
-Sigmod::MapTrainer* Sigmod::Map::trainer(const int index)
-{
- if (index < trainerCount())
- return m_trainers[index];
- return NULL;
-}
+GETTER(Map, QString, name)
+GETTER(Map, int, flyWarp)
+GETTER(Map, Sigmod::Map::Type, type)
+GETTER(Map, int, width)
+GETTER(Map, int, height)
-const Sigmod::MapTrainer* Sigmod::Map::trainerById(const int id) const
-{
- return trainer(trainerIndex(id));
-}
-
-Sigmod::MapTrainer* Sigmod::Map::trainerById(const int id)
-{
- return trainer(trainerIndex(id));
-}
-
-int Sigmod::Map::trainerIndex(const int id) const
-{
- for (int i = 0; i < trainerCount(); ++i)
- {
- if (m_trainers[i]->id() == id)
- return i;
- }
- return INT_MAX;
-}
-
-int Sigmod::Map::trainerCount() const
-{
- return m_trainers.size();
-}
-
-Sigmod::MapTrainer* Sigmod::Map::newTrainer()
-{
- return newTrainer(new MapTrainer(this, newTrainerId()));
-}
-
-Sigmod::MapTrainer* Sigmod::Map::newTrainer(const QDomElement& xml)
-{
- return newTrainer(new MapTrainer(xml, this, newTrainerId()));
-}
-
-Sigmod::MapTrainer* Sigmod::Map::newTrainer(const MapTrainer& trainer)
-{
- return newTrainer(new MapTrainer(trainer, this, newTrainerId()));
-}
-
-Sigmod::MapTrainer* Sigmod::Map::newTrainer(MapTrainer* trainer)
-{
- m_trainers.append(trainer);
- return trainer;
-}
-
-void Sigmod::Map::deleteTrainer(const int index)
-{
- if (index < trainerCount())
- {
- delete m_trainers[index];
- m_trainers.removeAt(index);
- }
-}
-
-void Sigmod::Map::deleteTrainerById(const int id)
-{
- deleteTrainer(trainerIndex(id));
-}
-
-int Sigmod::Map::newTrainerId() const
-{
- int i = 0;
- while ((i < trainerCount()) && (trainerIndex(i) != INT_MAX))
- ++i;
- return i;
-}
-
-const Sigmod::MapWarp* Sigmod::Map::warp(const int index) const
-{
- if (index < warpCount())
- return m_warps.at(index);
- return NULL;
-}
-
-Sigmod::MapWarp* Sigmod::Map::warp(const int index)
-{
- if (index < warpCount())
- return m_warps[index];
- return NULL;
-}
-
-const Sigmod::MapWarp* Sigmod::Map::warpById(const int id) const
-{
- return warp(warpIndex(id));
-}
-
-Sigmod::MapWarp* Sigmod::Map::warpById(const int id)
-{
- return warp(warpIndex(id));
-}
-
-int Sigmod::Map::warpIndex(const int id) const
-{
- for (int i = 0; i < warpCount(); ++i)
- {
- if (m_warps[i]->id() == id)
- return i;
- }
- return INT_MAX;
-}
-
-int Sigmod::Map::warpCount() const
-{
- return m_warps.size();
-}
-
-Sigmod::MapWarp* Sigmod::Map::newWarp()
-{
- return newWarp(new MapWarp(this, newWarpId()));
-}
-
-Sigmod::MapWarp* Sigmod::Map::newWarp(const QDomElement& xml)
-{
- return newWarp(new MapWarp(xml, this, newWarpId()));
-}
-
-Sigmod::MapWarp* Sigmod::Map::newWarp(const MapWarp& warp)
-{
- return newWarp(new MapWarp(warp, this, newWarpId()));
-}
-
-Sigmod::MapWarp* Sigmod::Map::newWarp(MapWarp* warp)
-{
- m_warps.append(warp);
- return warp;
-}
-
-void Sigmod::Map::deleteWarp(const int index)
-{
- if (index < warpCount())
- {
- delete m_warps[index];
- m_warps.removeAt(index);
- }
-}
-
-void Sigmod::Map::deleteWarpById(const int id)
-{
- deleteWarp(warpIndex(id));
-}
-
-int Sigmod::Map::newWarpId() const
-{
- int i = 0;
- while ((i < warpCount()) && (warpIndex(i) != INT_MAX))
- ++i;
- return i;
-}
-
-const Sigmod::MapWildList* Sigmod::Map::wildList(const int index) const
-{
- if (index < wildListCount())
- return m_wildLists.at(index);
- return NULL;
-}
-
-Sigmod::MapWildList* Sigmod::Map::wildList(const int index)
-{
- if (index < wildListCount())
- return m_wildLists[index];
- return NULL;
-}
-
-const Sigmod::MapWildList* Sigmod::Map::wildListById(const int id) const
-{
- return wildList(wildListIndex(id));
-}
-
-Sigmod::MapWildList* Sigmod::Map::wildListById(const int id)
-{
- return wildList(wildListIndex(id));
-}
-
-int Sigmod::Map::wildListIndex(const int id) const
-{
- for (int i = 0; i < wildListCount(); ++i)
- {
- if (m_wildLists[i]->id() == id)
- return i;
- }
- return INT_MAX;
-}
-
-int Sigmod::Map::wildListCount() const
-{
- return m_wildLists.size();
-}
-
-Sigmod::MapWildList* Sigmod::Map::newWildList()
-{
- return newWildList(new MapWildList(this, newWildListId()));
-}
-
-Sigmod::MapWildList* Sigmod::Map::newWildList(const QDomElement& xml)
-{
- return newWildList(new MapWildList(xml, this, newWildListId()));
-}
-
-Sigmod::MapWildList* Sigmod::Map::newWildList(const MapWildList& wildList)
-{
- return newWildList(new MapWildList(wildList, this, newWildListId()));
-}
-
-Sigmod::MapWildList* Sigmod::Map::newWildList(MapWildList* wildList)
-{
- m_wildLists.append(wildList);
- return wildList;
-}
-
-void Sigmod::Map::deleteWildList(const int index)
-{
- if (index < wildListCount())
+CHECK(Map, QString&, name)
+CHECK_BEGIN(Map, int, flyWarp)
+ if ((flyWarp != -1) && !warpById(flyWarp))
{
- delete m_wildLists[index];
- m_wildLists.removeAt(index);
+ EBOUNDS_IDX(flyWarp);
+ return false;
}
-}
+CHECK_END()
+CHECK(Map, Type, type)
+CHECK_BOUNDS(Map, int, width, 1, INT_MAX)
+CHECK_BOUNDS(Map, int, height, 1, INT_MAX)
-void Sigmod::Map::deleteWildListById(const int id)
-{
- deleteWildList(wildListIndex(id));
-}
-
-int Sigmod::Map::newWildListId() const
-{
- int i = 0;
- while ((i < warpCount()) && (warpIndex(i) != INT_MAX))
- ++i;
- return i;
-}
+SUBCLASS(Map, Effect, effect, effects)
+SUBCLASS(Map, Tile, tile, tiles)
+SUBCLASS(Map, Trainer, trainer, trainers)
+SUBCLASS(Map, Warp, warp, warps)
+SUBCLASS(Map, WildList, wildList, wildLists)
Sigmod::Map& Sigmod::Map::operator=(const Map& rhs)
{
@@ -636,14 +195,9 @@ Sigmod::Map& Sigmod::Map::operator=(const Map& rhs)
void Sigmod::Map::clear()
{
- qDeleteAll(m_effects);
- m_effects.clear();
- qDeleteAll(m_tiles);
- m_tiles.clear();
- qDeleteAll(m_trainers);
- m_trainers.clear();
- qDeleteAll(m_warps);
- m_warps.clear();
- qDeleteAll(m_wildLists);
- m_wildLists.clear();
+ SUBCLASS_CLEAR(effects);
+ SUBCLASS_CLEAR(tiles);
+ SUBCLASS_CLEAR(trainers);
+ SUBCLASS_CLEAR(warps);
+ SUBCLASS_CLEAR(wildLists);
}