summaryrefslogtreecommitdiffstats
path: root/sigmod/Map.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-11-08 06:15:08 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-11-08 06:15:08 +0000
commit8bad37e82371bd41864903ac0d6f49808ad119bf (patch)
tree77f0cb46059654cefb357d6eb4064c5740edf3d4 /sigmod/Map.cpp
parentc127c0dae65a7600e0ab30b634f25d4915c61d16 (diff)
downloadsigen-8bad37e82371bd41864903ac0d6f49808ad119bf.tar.gz
sigen-8bad37e82371bd41864903ac0d6f49808ad119bf.tar.xz
sigen-8bad37e82371bd41864903ac0d6f49808ad119bf.zip
[FIX] No more asserts in sigmod
[FIX] Moved to using *ById instead of *Index methods in sigmod [FIX] Tilemaps are now collaged (not completely done on the editing side yet) [FIX] Removed the resource files (drawn natively instead) [FIX] ATBTimer now uses the built-in QTimer in a QObject [FIX] Coordinates are now edited on the map for warps, trainers, and effects [FIX] Tiles are now completely scripted [FIX] Config is now thread-safe git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@308 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'sigmod/Map.cpp')
-rw-r--r--sigmod/Map.cpp253
1 files changed, 167 insertions, 86 deletions
diff --git a/sigmod/Map.cpp b/sigmod/Map.cpp
index 1aaa5e36..bea4f227 100644
--- a/sigmod/Map.cpp
+++ b/sigmod/Map.cpp
@@ -21,6 +21,7 @@
// Sigmod includes
#include "Macros.h"
#include "MapEffect.h"
+#include "MapTile.h"
#include "MapTrainer.h"
#include "MapWarp.h"
#include "MapWildList.h"
@@ -41,7 +42,9 @@ Sigmod::Map::Map(const Sigmod* parent, const int id) :
Object(parent, id),
m_name(""),
m_flyWarp(-1),
- m_type(Outdoor)
+ m_type(Outdoor),
+ m_width(0),
+ m_height(0)
{
}
@@ -70,7 +73,10 @@ void Sigmod::Map::validate()
emit(error("Name is empty"));
TEST(setFlyWarp, flyWarp);
TEST(setType, type);
- TEST_MATRIX(setTile, map);
+ if (!m_width)
+ emit(error("Map has no width"));
+ if (!m_height)
+ emit(error("Map has no height"));
QSet<int> idChecker;
QSet<QString> nameChecker;
if (!effectCount())
@@ -81,6 +87,12 @@ void Sigmod::Map::validate()
TEST_SUB_END();
idChecker.clear();
nameChecker.clear();
+ if (!tileCount())
+ emit(warning("There are no tiles"));
+ TEST_SUB_BEGIN(MapTile, tiles);
+ TEST_SUB("tile", id);
+ TEST_SUB_END();
+ idChecker.clear();
if (!trainerCount())
emit(warning("There are no trainers"));
TEST_SUB_BEGIN(MapTrainer, trainers);
@@ -110,8 +122,10 @@ void Sigmod::Map::load(const QDomElement& xml)
LOAD(name);
LOAD(flyWarp);
LOAD(type);
- LOAD_MATRIX(map);
+ LOAD(width);
+ LOAD(height);
LOAD_SUB(newEffect, MapEffect);
+ LOAD_SUB(newTile, MapTile);
LOAD_SUB(newTrainer, MapTrainer);
LOAD_SUB(newWarp, MapWarp);
LOAD_SUB(newWildList, MapWildList);
@@ -123,8 +137,10 @@ QDomElement Sigmod::Map::save() const
SAVE(name);
SAVE(flyWarp);
SAVE(type);
- SAVE_MATRIX(map);
+ SAVE(width);
+ SAVE(height);
SAVE_SUB(MapEffect, effects);
+ SAVE_SUB(MapTile, tiles);
SAVE_SUB(MapTrainer, trainers);
SAVE_SUB(MapWarp, warps);
SAVE_SUB(MapWildList, wildLists);
@@ -138,7 +154,7 @@ void Sigmod::Map::setName(const QString& name)
void Sigmod::Map::setFlyWarp(const int flyWarp)
{
- if ((flyWarp != -1) && (warpIndex(flyWarp) == INT_MAX))
+ if ((flyWarp != -1) && !warpById(flyWarp))
emit(error(bounds("flyWarp")));
else
CHECK(flyWarp);
@@ -149,6 +165,22 @@ void Sigmod::Map::setType(const Type type)
CHECK(type);
}
+void Sigmod::Map::setWidth(const int width)
+{
+ if (width <= 0)
+ emit(error(bounds("width")));
+ else
+ CHECK(width);
+}
+
+void Sigmod::Map::setHeight(const int height)
+{
+ if (height <= 0)
+ emit(error(bounds("height")));
+ else
+ CHECK(height);
+}
+
QString Sigmod::Map::name() const
{
return m_name;
@@ -164,157 +196,192 @@ Sigmod::Map::Type Sigmod::Map::type() const
return m_type;
}
-void Sigmod::Map::setTile(const int row, const int column, const int tile)
+int Sigmod::Map::width() const
{
- if (qobject_cast<const Sigmod*>(sigmod())->tileIndex(tile) == INT_MAX)
- emit(error(bounds("tile")));
- else
- m_map(row, column) = tile;
+ return m_width;
}
-void Sigmod::Map::insertColumn(const int column)
+int Sigmod::Map::height() const
{
- m_map.insertColumn(column, 0);
+ return m_height;
}
-void Sigmod::Map::insertRow(const int row)
+const Sigmod::MapEffect* Sigmod::Map::effect(const int index) const
{
- m_map.insertRow(row, 0);
+ if (index < effectCount())
+ return m_effects.at(index);
+ return NULL;
}
-void Sigmod::Map::addColumn()
+Sigmod::MapEffect* Sigmod::Map::effect(const int index)
{
- m_map.addColumn(0);
+ if (index < effectCount())
+ return m_effects[index];
+ return NULL;
}
-void Sigmod::Map::addRow()
+const Sigmod::MapEffect* Sigmod::Map::effectById(const int index) const
{
- m_map.addRow(0);
+ return effect(effectIndex(index));
}
-void Sigmod::Map::deleteColumn(const int column)
+Sigmod::MapEffect* Sigmod::Map::effectById(const int index)
{
- m_map.deleteColumn(column);
+ return effect(effectIndex(index));
}
-void Sigmod::Map::deleteRow(const int row)
+int Sigmod::Map::effectIndex(const int id) const
{
- m_map.deleteRow(row);
+ for (int i = 0; i < effectCount(); ++i)
+ {
+ if (m_effects[i]->id() == id)
+ return i;
+ }
+ return INT_MAX;
}
-const Sigcore::Matrix<int>* Sigmod::Map::map() const
+int Sigmod::Map::effectCount() const
{
- return &m_map;
+ return m_effects.size();
}
-Sigcore::Matrix<int>* Sigmod::Map::map()
+Sigmod::MapEffect* Sigmod::Map::newEffect()
{
- return &m_map;
+ return newEffect(new MapEffect(this, newEffectId()));
}
-int Sigmod::Map::tile(const int row, const int column) const
+Sigmod::MapEffect* Sigmod::Map::newEffect(const QDomElement& xml)
{
- return m_map(row, column);
+ return newEffect(new MapEffect(xml, this, newEffectId()));
}
-int Sigmod::Map::width() const
+Sigmod::MapEffect* Sigmod::Map::newEffect(const MapEffect& effect)
{
- return m_map.width();
+ return newEffect(new MapEffect(effect, this, newEffectId()));
}
-int Sigmod::Map::height() const
+Sigmod::MapEffect* Sigmod::Map::newEffect(MapEffect* effect)
{
- return m_map.height();
+ m_effects.append(effect);
+ return effect;
}
-const Sigmod::MapEffect* Sigmod::Map::effect(const int index) const
+void Sigmod::Map::deleteEffect(const int index)
{
- Q_ASSERT(index < effectCount());
- return m_effects.at(index);
+ if (index < effectCount())
+ {
+ delete m_effects[index];
+ m_effects.removeAt(index);
+ }
}
-Sigmod::MapEffect* Sigmod::Map::effect(const int index)
+void Sigmod::Map::deleteEffectById(const int id)
{
- Q_ASSERT(index < effectCount());
- return m_effects[index];
+ deleteEffect(effectIndex(id));
}
-const Sigmod::MapEffect* Sigmod::Map::effectById(const int index) const
+int Sigmod::Map::newEffectId() const
{
- return effect(effectIndex(index));
+ int i = 0;
+ while ((i < effectCount()) && (effectIndex(i) != INT_MAX))
+ ++i;
+ return i;
}
-Sigmod::MapEffect* Sigmod::Map::effectById(const int index)
+const Sigmod::MapTile* Sigmod::Map::tile(const int index) const
{
- return effect(effectIndex(index));
+ if (index < tileCount())
+ return m_tiles.at(index);
+ return NULL;
}
-int Sigmod::Map::effectIndex(const int id) const
+Sigmod::MapTile* Sigmod::Map::tile(const int index)
{
- for (int i = 0; i < effectCount(); ++i)
+ 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_effects[i]->id() == id)
+ if (m_tiles[i]->id() == id)
return i;
}
return INT_MAX;
}
-int Sigmod::Map::effectCount() const
+int Sigmod::Map::tileCount() const
{
- return m_effects.size();
+ return m_tiles.size();
}
-Sigmod::MapEffect* Sigmod::Map::newEffect()
+Sigmod::MapTile* Sigmod::Map::newTile()
{
- return newEffect(new MapEffect(this, newEffectId()));
+ return newTile(new MapTile(this, newTileId()));
}
-Sigmod::MapEffect* Sigmod::Map::newEffect(const QDomElement& xml)
+Sigmod::MapTile* Sigmod::Map::newTile(const QDomElement& xml)
{
- return newEffect(new MapEffect(xml, this, newEffectId()));
+ return newTile(new MapTile(xml, this, newTileId()));
}
-Sigmod::MapEffect* Sigmod::Map::newEffect(const MapEffect& effect)
+Sigmod::MapTile* Sigmod::Map::newTile(const MapTile& tile)
{
- return newEffect(new MapEffect(effect, this, newEffectId()));
+ return newTile(new MapTile(tile, this, newTileId()));
}
-Sigmod::MapEffect* Sigmod::Map::newEffect(MapEffect* effect)
+Sigmod::MapTile* Sigmod::Map::newTile(MapTile* tile)
{
- m_effects.append(effect);
- return effect;
+ m_tiles.append(tile);
+ return tile;
}
-void Sigmod::Map::deleteEffect(const int index)
+void Sigmod::Map::deleteTile(const int index)
{
- Q_ASSERT(index < effectCount());
- delete m_effects[index];
- m_effects.removeAt(index);
+ if (index < tileCount())
+ {
+ delete m_tiles[index];
+ m_tiles.removeAt(index);
+ }
}
-void Sigmod::Map::deleteEffectById(const int id)
+void Sigmod::Map::deleteTileById(const int id)
{
- deleteEffect(effectIndex(id));
+ deleteTile(tileIndex(id));
}
-int Sigmod::Map::newEffectId() const
+int Sigmod::Map::newTileId() const
{
int i = 0;
- while ((i < effectCount()) && (effectIndex(i) != INT_MAX))
+ while ((i < tileCount()) && (tileIndex(i) != INT_MAX))
++i;
return i;
}
const Sigmod::MapTrainer* Sigmod::Map::trainer(const int index) const
{
- Q_ASSERT(index < trainerCount());
- return m_trainers.at(index);
+ if (index < trainerCount())
+ return m_trainers.at(index);
+ return NULL;
}
Sigmod::MapTrainer* Sigmod::Map::trainer(const int index)
{
- Q_ASSERT(index < trainerCount());
- return m_trainers[index];
+ if (index < trainerCount())
+ return m_trainers[index];
+ return NULL;
}
const Sigmod::MapTrainer* Sigmod::Map::trainerById(const int id) const
@@ -365,9 +432,11 @@ Sigmod::MapTrainer* Sigmod::Map::newTrainer(MapTrainer* trainer)
void Sigmod::Map::deleteTrainer(const int index)
{
- Q_ASSERT(index < trainerCount());
- delete m_trainers[index];
- m_trainers.removeAt(index);
+ if (index < trainerCount())
+ {
+ delete m_trainers[index];
+ m_trainers.removeAt(index);
+ }
}
void Sigmod::Map::deleteTrainerById(const int id)
@@ -385,14 +454,16 @@ int Sigmod::Map::newTrainerId() const
const Sigmod::MapWarp* Sigmod::Map::warp(const int index) const
{
- Q_ASSERT(index < warpCount());
- return m_warps.at(index);
+ if (index < warpCount())
+ return m_warps.at(index);
+ return NULL;
}
Sigmod::MapWarp* Sigmod::Map::warp(const int index)
{
- Q_ASSERT(index < warpCount());
- return m_warps[index];
+ if (index < warpCount())
+ return m_warps[index];
+ return NULL;
}
const Sigmod::MapWarp* Sigmod::Map::warpById(const int id) const
@@ -443,9 +514,11 @@ Sigmod::MapWarp* Sigmod::Map::newWarp(MapWarp* warp)
void Sigmod::Map::deleteWarp(const int index)
{
- Q_ASSERT(index < warpCount());
- delete m_warps[index];
- m_warps.removeAt(index);
+ if (index < warpCount())
+ {
+ delete m_warps[index];
+ m_warps.removeAt(index);
+ }
}
void Sigmod::Map::deleteWarpById(const int id)
@@ -463,14 +536,16 @@ int Sigmod::Map::newWarpId() const
const Sigmod::MapWildList* Sigmod::Map::wildList(const int index) const
{
- Q_ASSERT(index < wildListCount());
- return m_wildLists.at(index);
+ if (index < wildListCount())
+ return m_wildLists.at(index);
+ return NULL;
}
Sigmod::MapWildList* Sigmod::Map::wildList(const int index)
{
- Q_ASSERT(index < wildListCount());
- return m_wildLists[index];
+ if (index < wildListCount())
+ return m_wildLists[index];
+ return NULL;
}
const Sigmod::MapWildList* Sigmod::Map::wildListById(const int id) const
@@ -521,9 +596,11 @@ Sigmod::MapWildList* Sigmod::Map::newWildList(MapWildList* wildList)
void Sigmod::Map::deleteWildList(const int index)
{
- Q_ASSERT(index < wildListCount());
- delete m_wildLists[index];
- m_wildLists.removeAt(index);
+ if (index < wildListCount())
+ {
+ delete m_wildLists[index];
+ m_wildLists.removeAt(index);
+ }
}
void Sigmod::Map::deleteWildListById(const int id)
@@ -547,8 +624,10 @@ Sigmod::Map& Sigmod::Map::operator=(const Map& rhs)
COPY(name);
COPY(flyWarp);
COPY(type);
- COPY(map);
+ COPY(width);
+ COPY(height);
COPY_SUB(MapEffect, effects);
+ COPY_SUB(MapTile, tiles);
COPY_SUB(MapTrainer, trainers);
COPY_SUB(MapWarp, warps);
COPY_SUB(MapWildList, wildLists);
@@ -559,6 +638,8 @@ 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);