diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2008-11-08 06:15:08 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2008-11-08 06:15:08 +0000 |
commit | 8bad37e82371bd41864903ac0d6f49808ad119bf (patch) | |
tree | 77f0cb46059654cefb357d6eb4064c5740edf3d4 /sigmod | |
parent | c127c0dae65a7600e0ab30b634f25d4915c61d16 (diff) | |
download | sigen-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')
-rw-r--r-- | sigmod/Badge.cpp | 10 | ||||
-rw-r--r-- | sigmod/CMakeLists.txt | 3 | ||||
-rw-r--r-- | sigmod/CoinList.cpp | 18 | ||||
-rw-r--r-- | sigmod/CoinListObject.cpp | 2 | ||||
-rw-r--r-- | sigmod/Item.cpp | 10 | ||||
-rw-r--r-- | sigmod/ItemType.cpp | 2 | ||||
-rw-r--r-- | sigmod/Map.cpp | 253 | ||||
-rw-r--r-- | sigmod/Map.h | 34 | ||||
-rw-r--r-- | sigmod/MapEffect.cpp | 2 | ||||
-rw-r--r-- | sigmod/MapTile.cpp | 128 | ||||
-rw-r--r-- | sigmod/MapTile.h | 58 | ||||
-rw-r--r-- | sigmod/MapTrainer.cpp | 27 | ||||
-rw-r--r-- | sigmod/MapTrainerTeamMember.cpp | 46 | ||||
-rw-r--r-- | sigmod/MapWarp.cpp | 31 | ||||
-rw-r--r-- | sigmod/MapWarp.h | 8 | ||||
-rw-r--r-- | sigmod/MapWildList.cpp | 18 | ||||
-rw-r--r-- | sigmod/MapWildListEncounter.cpp | 4 | ||||
-rw-r--r-- | sigmod/Move.cpp | 2 | ||||
-rw-r--r-- | sigmod/Nature.cpp | 4 | ||||
-rw-r--r-- | sigmod/Sigmod.cpp | 414 | ||||
-rw-r--r-- | sigmod/Species.cpp | 99 | ||||
-rw-r--r-- | sigmod/SpeciesAbility.cpp | 2 | ||||
-rw-r--r-- | sigmod/SpeciesItem.cpp | 2 | ||||
-rw-r--r-- | sigmod/SpeciesMove.cpp | 6 | ||||
-rw-r--r-- | sigmod/Store.cpp | 2 | ||||
-rw-r--r-- | sigmod/Tile.cpp | 41 | ||||
-rw-r--r-- | sigmod/Tile.h | 6 | ||||
-rw-r--r-- | sigmod/Trainer.cpp | 2 |
28 files changed, 795 insertions, 439 deletions
diff --git a/sigmod/Badge.cpp b/sigmod/Badge.cpp index d70833ca..92d60090 100644 --- a/sigmod/Badge.cpp +++ b/sigmod/Badge.cpp @@ -102,7 +102,7 @@ void Sigmod::Badge::setName(const QString& name) void Sigmod::Badge::setFace(const int face) { - if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(face) == INT_MAX) + if (!sigmod()->spriteById(face)) emit(error(bounds("face"))); else CHECK(face); @@ -110,7 +110,7 @@ void Sigmod::Badge::setFace(const int face) void Sigmod::Badge::setBadge(const int badge) { - if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(badge) == INT_MAX) + if (!sigmod()->spriteById(badge)) emit(error(bounds("badge"))); else CHECK(badge); @@ -118,7 +118,7 @@ void Sigmod::Badge::setBadge(const int badge) void Sigmod::Badge::setObey(const int obey) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxLevel() < obey) + if (sigmod()->rules()->maxLevel() < obey) { emit(error(bounds("obey"))); return; @@ -136,7 +136,7 @@ void Sigmod::Badge::setStat(const Stat stat, const Sigcore::Fraction& multiplier switch (stat) { case ST_SpecialDefense - ST_Attack + 1: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_Attack ... ST_Special: break; default: @@ -177,7 +177,7 @@ Sigcore::Fraction Sigmod::Badge::stat(const Stat stat) const switch (stat) { case ST_SpecialDefense - ST_Attack + 1: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_Attack ... ST_Special: return m_stat[stat - ST_Attack]; default: diff --git a/sigmod/CMakeLists.txt b/sigmod/CMakeLists.txt index 1f60289d..ffd6f5c8 100644 --- a/sigmod/CMakeLists.txt +++ b/sigmod/CMakeLists.txt @@ -18,6 +18,7 @@ SET(sigmod_HEADERS Macros.h MapEffect.h Map.h + MapTile.h MapTrainer.h MapTrainerTeamMember.h MapWarp.h @@ -54,6 +55,7 @@ SET(sigmod_SRCS Item.cpp ItemType.cpp Map.cpp + MapTile.cpp MapEffect.cpp MapTrainer.cpp MapTrainerTeamMember.cpp @@ -93,6 +95,7 @@ SET_TARGET_PROPERTIES(sigmod ) TARGET_LINK_LIBRARIES(sigmod ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY} ${QT_QTXML_LIBRARY} sigcore ) diff --git a/sigmod/CoinList.cpp b/sigmod/CoinList.cpp index a36ebeb6..aeeceb46 100644 --- a/sigmod/CoinList.cpp +++ b/sigmod/CoinList.cpp @@ -139,14 +139,16 @@ Sigcore::Script Sigmod::CoinList::script() const const Sigmod::CoinListObject* Sigmod::CoinList::object(const int index) const { - Q_ASSERT(index < objectCount()); - return m_objects.at(index); + if (index < objectCount()) + return m_objects.at(index); + return NULL; } Sigmod::CoinListObject* Sigmod::CoinList::object(const int index) { - Q_ASSERT(index < objectCount()); - return m_objects[index]; + if (index < objectCount()) + return m_objects[index]; + return NULL; } const Sigmod::CoinListObject* Sigmod::CoinList::objectById(const int id) const @@ -197,9 +199,11 @@ Sigmod::CoinListObject* Sigmod::CoinList::newObject(CoinListObject* object) void Sigmod::CoinList::deleteObject(const int index) { - Q_ASSERT(index < objectCount()); - delete m_objects[index]; - m_objects.removeAt(index); + if (index < objectCount()) + { + delete m_objects[index]; + m_objects.removeAt(index); + } } void Sigmod::CoinList::deleteObjectById(const int id) diff --git a/sigmod/CoinListObject.cpp b/sigmod/CoinListObject.cpp index a82c3b2a..e380e016 100644 --- a/sigmod/CoinListObject.cpp +++ b/sigmod/CoinListObject.cpp @@ -87,7 +87,7 @@ void Sigmod::CoinListObject::setType(const Type type) void Sigmod::CoinListObject::setObject(const int object) { - if (((Item == m_type) && (qobject_cast<const Sigmod*>(sigmod())->itemIndex(object) == INT_MAX)) || ((Species == m_type) && (qobject_cast<const Sigmod*>(sigmod())->speciesIndex(object) == INT_MAX))) + if (((Item == m_type) && !sigmod()->itemById(object)) || ((Species == m_type) && !sigmod()->speciesById(object))) emit(error(bounds("object"))); else CHECK(object); diff --git a/sigmod/Item.cpp b/sigmod/Item.cpp index 5cb9d29e..ff74f736 100644 --- a/sigmod/Item.cpp +++ b/sigmod/Item.cpp @@ -114,7 +114,7 @@ void Sigmod::Item::setSellable(const bool sellable) void Sigmod::Item::setType(const int type) { - if (qobject_cast<const Sigmod*>(sigmod())->itemTypeIndex(type) == INT_MAX) + if (!sigmod()->itemTypeById(type)) emit(error(bounds("type"))); else CHECK(type); @@ -122,7 +122,7 @@ void Sigmod::Item::setType(const int type) void Sigmod::Item::setPrice(const int price) { - if ((price < 0) || (qobject_cast<const Sigmod*>(sigmod())->rules()->maxMoney() < price)) + if ((price < 0) || (sigmod()->rules()->maxMoney() < price)) emit(error(bounds("price"))); else CHECK(price); @@ -138,10 +138,10 @@ void Sigmod::Item::setSellPrice(const int sellPrice) void Sigmod::Item::setWeight(const int weight) { - const int typeIndex = qobject_cast<const Sigmod*>(sigmod())->itemTypeIndex(m_type); - if (typeIndex != INT_MAX) + const ItemType* type = sigmod()->itemTypeById(m_type); + if (type) { - if (qobject_cast<const Sigmod*>(sigmod())->itemType(typeIndex)->maxWeight() < weight) + if (type->maxWeight() < weight) emit(error(bounds("weight"))); else if (weight < 0) emit(error(bounds("weight"))); diff --git a/sigmod/ItemType.cpp b/sigmod/ItemType.cpp index 80e1b40d..d9d0d754 100644 --- a/sigmod/ItemType.cpp +++ b/sigmod/ItemType.cpp @@ -105,7 +105,7 @@ void Sigmod::ItemType::setPlayer(const int player) void Sigmod::ItemType::setMaxWeight(const int maxWeight) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxTotalWeight() < maxWeight) + if (sigmod()->rules()->maxTotalWeight() < maxWeight) emit(error(bounds("maxWeight"))); else if (maxWeight < 0) emit(error(bounds("maxWeight"))); 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); diff --git a/sigmod/Map.h b/sigmod/Map.h index 490287c6..8a62e2ba 100644 --- a/sigmod/Map.h +++ b/sigmod/Map.h @@ -31,6 +31,7 @@ namespace Sigmod { // Forward declarations class MapEffect; +class MapTile; class MapTrainer; class MapWarp; class MapWildList; @@ -64,22 +65,12 @@ class SIGMOD_EXPORT Map : public Object void setName(const QString& name); void setFlyWarp(const int flyWarp); void setType(const Type type); + void setWidth(const int width); + void setHeight(const int height); QString name() const; int flyWarp() const; Type type() const; - - void setTile(const int row, const int column, const int tile); - void insertColumn(const int column); - void insertRow(const int row); - void addColumn(); - void addRow(); - void deleteColumn(const int column); - void deleteRow(const int row); - - const Sigcore::Matrix<int>* map() const; - Sigcore::Matrix<int>* map(); - int tile(const int row, const int column) const; int width() const; int height() const; @@ -95,6 +86,18 @@ class SIGMOD_EXPORT Map : public Object void deleteEffect(const int index); void deleteEffectById(const int id); + const MapTile* tile(const int index) const; + MapTile* tile(const int index); + const MapTile* tileById(const int id) const; + MapTile* tileById(const int id); + int tileIndex(const int id) const; + int tileCount() const; + MapTile* newTile(); + MapTile* newTile(const QDomElement& xml); + MapTile* newTile(const MapTile& tile); + void deleteTile(const int index); + void deleteTileById(const int id); + const MapTrainer* trainer(const int index) const; MapTrainer* trainer(const int index); const MapTrainer* trainerById(const int id) const; @@ -136,6 +139,9 @@ class SIGMOD_EXPORT Map : public Object int newEffectId() const; MapEffect* newEffect(MapEffect* effect); + int newTileId() const; + MapTile* newTile(MapTile* tile); + int newTrainerId() const; MapTrainer* newTrainer(MapTrainer* trainer); @@ -150,8 +156,10 @@ class SIGMOD_EXPORT Map : public Object QString m_name; int m_flyWarp; Type m_type; - Sigcore::Matrix<int> m_map; + int m_width; + int m_height; QList<MapEffect*> m_effects; + QList<MapTile*> m_tiles; QList<MapTrainer*> m_trainers; QList<MapWarp*> m_warps; QList<MapWildList*> m_wildLists; diff --git a/sigmod/MapEffect.cpp b/sigmod/MapEffect.cpp index 6d5c2734..2d9cfd71 100644 --- a/sigmod/MapEffect.cpp +++ b/sigmod/MapEffect.cpp @@ -98,7 +98,7 @@ void Sigmod::MapEffect::setCoordinate(const QPoint& coordinate) void Sigmod::MapEffect::setSkin(const int skin) { - if (qobject_cast<const Sigmod*>(sigmod())->skinIndex(skin) == INT_MAX) + if (!sigmod()->skinById(skin)) emit(error(bounds("skin"))); else CHECK(skin); diff --git a/sigmod/MapTile.cpp b/sigmod/MapTile.cpp new file mode 100644 index 00000000..c6471969 --- /dev/null +++ b/sigmod/MapTile.cpp @@ -0,0 +1,128 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapTile.h" + +// Sigmod includes +#include "Macros.h" +#include "Map.h" +#include "Sigmod.h" +#include "Tile.h" + +Sigmod::MapTile::MapTile(const MapTile& tile) : + Object(tile.parent(), tile.id()) +{ + *this = tile; +} + +Sigmod::MapTile::MapTile(const Map* parent, const int id) : + Object(parent, id), + m_tile(-1), + m_position(0, 0), + m_zIndex(-1) +{ +} + +Sigmod::MapTile::MapTile(const MapTile& tile, const Map* parent, const int id) : + Object(parent, id) +{ + *this = tile; +} + +Sigmod::MapTile::MapTile(const QDomElement& xml, const Map* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Sigmod::MapTile::~MapTile() +{ +} + +void Sigmod::MapTile::validate() +{ + TEST_BEGIN(); + TEST(setTile, tile); + TEST(setPosition, position); + TEST_END(); +} + +void Sigmod::MapTile::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(tile); + LOAD(position); + LOAD(zIndex); +} + +QDomElement Sigmod::MapTile::save() const +{ + SAVE_CREATE(); + SAVE(tile); + SAVE(position); + SAVE(zIndex); + return xml; +} + +void Sigmod::MapTile::setTile(const int tile) +{ + if (!sigmod()->tileById(tile)) + emit(error(bounds("tile"))); + else + CHECK(tile); +} + +void Sigmod::MapTile::setPosition(const QPoint& position) +{ + if ((qobject_cast<const Map*>(parent())->width() <= position.x()) || (qobject_cast<const Map*>(parent())->height() <= position.y())) + emit(error(bounds("coordinate"))); + else + CHECK(position); +} + +void Sigmod::MapTile::setZIndex(const int zIndex) +{ + CHECK(zIndex); +} + +int Sigmod::MapTile::tile() const +{ + return m_tile; +} + +QPoint Sigmod::MapTile::position() const +{ + return m_position; +} + +int Sigmod::MapTile::zIndex() const +{ + return m_zIndex; +} + +Sigmod::MapTile& Sigmod::MapTile::operator=(const MapTile& rhs) +{ + if (this == &rhs) + return *this; + clear(); + COPY(tile); + COPY(position); + COPY(zIndex); + return *this; +} diff --git a/sigmod/MapTile.h b/sigmod/MapTile.h new file mode 100644 index 00000000..d7d51e93 --- /dev/null +++ b/sigmod/MapTile.h @@ -0,0 +1,58 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGMOD_MAPTILE +#define SIGMOD_MAPTILE + +// Sigmod includes +#include "Object.h" + +namespace Sigmod +{ +class SIGMOD_EXPORT MapTile : public Object +{ + Q_OBJECT + + public: + MapTile(const MapTile& tile); + MapTile(const Map* parent, const int id); + MapTile(const MapTile& tile, const Map* parent, const int id); + MapTile(const QDomElement& xml, const Map* parent, const int id = -1); + ~MapTile(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setTile(const int tile); + void setPosition(const QPoint& position); + void setZIndex(const int zIndex); + + int tile() const; + QPoint position() const; + int zIndex() const; + + MapTile& operator=(const MapTile& rhs); + private: + int m_tile; + QPoint m_position; + int m_zIndex; +}; +} + +#endif diff --git a/sigmod/MapTrainer.cpp b/sigmod/MapTrainer.cpp index 2c9307c9..1722df8d 100644 --- a/sigmod/MapTrainer.cpp +++ b/sigmod/MapTrainer.cpp @@ -112,7 +112,7 @@ void Sigmod::MapTrainer::setName(const QString& name) void Sigmod::MapTrainer::setTrainerClass(const int trainerClass) { - if (qobject_cast<const Sigmod*>(sigmod())->trainerIndex(trainerClass) == INT_MAX) + if (!sigmod()->trainerById(trainerClass)) emit(error(bounds("trainerClass"))); else CHECK(trainerClass); @@ -120,7 +120,8 @@ void Sigmod::MapTrainer::setTrainerClass(const int trainerClass) void Sigmod::MapTrainer::setCoordinate(const QPoint& coordinate) { - if ((qobject_cast<const Map*>(parent())->width() <= coordinate.x()) || (qobject_cast<const Map*>(parent())->height() <= coordinate.y())) + const Map* map = qobject_cast<const Map*>(parent()); + if ((map->width() <= coordinate.x()) || (map->height() <= coordinate.y())) emit(error(bounds("coordinate"))); else CHECK(coordinate); @@ -128,7 +129,7 @@ void Sigmod::MapTrainer::setCoordinate(const QPoint& coordinate) void Sigmod::MapTrainer::setNumberFight(const int numberFight) { - if (!numberFight || (qobject_cast<const Sigmod*>(sigmod())->rules()->maxFight() < numberFight)) + if (!numberFight || (sigmod()->rules()->maxFight() < numberFight)) emit(error(bounds("numberFight"))); else CHECK(numberFight); @@ -141,7 +142,7 @@ void Sigmod::MapTrainer::setScript(const Sigcore::Script& script) void Sigmod::MapTrainer::setLeadTeamMember(const int leadTeamMember) { - if (teamMemberIndex(leadTeamMember) == INT_MAX) + if (!teamMemberById(leadTeamMember)) emit(error(bounds("leadTeamMember"))); else CHECK(leadTeamMember); @@ -179,14 +180,16 @@ int Sigmod::MapTrainer::leadTeamMember() const const Sigmod::MapTrainerTeamMember* Sigmod::MapTrainer::teamMember(const int index) const { - Q_ASSERT(index < teamMemberCount()); - return m_teamMembers.at(index); + if (index < teamMemberCount()) + return m_teamMembers.at(index); + return NULL; } Sigmod::MapTrainerTeamMember* Sigmod::MapTrainer::teamMember(const int index) { - Q_ASSERT(index < teamMemberCount()); - return m_teamMembers[index]; + if (index < teamMemberCount()) + return m_teamMembers[index]; + return NULL; } const Sigmod::MapTrainerTeamMember* Sigmod::MapTrainer::teamMemberById(const int id) const @@ -237,9 +240,11 @@ Sigmod::MapTrainerTeamMember* Sigmod::MapTrainer::newTeamMember(MapTrainerTeamMe void Sigmod::MapTrainer::deleteTeamMember(const int index) { - Q_ASSERT(index < teamMemberCount()); - delete m_teamMembers[index]; - m_teamMembers.removeAt(index); + if (index < teamMemberCount()) + { + delete m_teamMembers[index]; + m_teamMembers.removeAt(index); + } } void Sigmod::MapTrainer::deleteTeamMemberById(const int id) diff --git a/sigmod/MapTrainerTeamMember.cpp b/sigmod/MapTrainerTeamMember.cpp index 595277df..3a72811e 100644 --- a/sigmod/MapTrainerTeamMember.cpp +++ b/sigmod/MapTrainerTeamMember.cpp @@ -61,16 +61,16 @@ void Sigmod::MapTrainerTeamMember::validate() TEST_BEGIN(); TEST(setSpecies, species); TEST(setLevel, level); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxAbilities() < m_ability.size()) + if (sigmod()->rules()->maxAbilities() < m_ability.size()) emit(error("Too many abilities")); TEST_LIST(setAbility, ability); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxHeldItems() < m_item.size()) + if (sigmod()->rules()->maxHeldItems() < m_item.size()) emit(error("Too many held items")); TEST_LIST(setItem, item); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxMoves() < m_move.size()) + if (sigmod()->rules()->maxMoves() < m_move.size()) emit(error("Too many moves")); TEST_LIST(setMove, move); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxNatures() < m_nature.size()) + if (sigmod()->rules()->maxNatures() < m_nature.size()) emit(error("Too many natures")); TEST_LIST(setNature, nature); TEST_END(); @@ -101,7 +101,7 @@ QDomElement Sigmod::MapTrainerTeamMember::save() const void Sigmod::MapTrainerTeamMember::setSpecies(const int species) { - if (qobject_cast<const Sigmod*>(sigmod())->speciesIndex(species) == INT_MAX) + if (!sigmod()->speciesById(species)) emit(error(bounds("species"))); else CHECK(species); @@ -109,7 +109,7 @@ void Sigmod::MapTrainerTeamMember::setSpecies(const int species) void Sigmod::MapTrainerTeamMember::setLevel(const int level) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxLevel() < level) + if (sigmod()->rules()->maxLevel() < level) emit(error(bounds("level"))); else CHECK(level); @@ -117,11 +117,11 @@ void Sigmod::MapTrainerTeamMember::setLevel(const int level) void Sigmod::MapTrainerTeamMember::setAbility(const int ability, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->abilityIndex(ability) == INT_MAX) + if (!sigmod()->abilityById(ability)) emit(error(bounds("ability"))); else if (state && !m_ability.contains(ability)) { - if (m_ability.size() < qobject_cast<const Sigmod*>(sigmod())->rules()->maxAbilities()) + if (m_ability.size() < sigmod()->rules()->maxAbilities()) { m_ability.append(ability); emit(changed()); @@ -138,11 +138,11 @@ void Sigmod::MapTrainerTeamMember::setAbility(const int ability, const bool stat void Sigmod::MapTrainerTeamMember::setItem(const int item, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->itemIndex(item) == INT_MAX) + if (!sigmod()->itemById(item)) emit(error(bounds("item"))); else if (state && !m_item.contains(item)) { - if (m_item.size() < qobject_cast<const Sigmod*>(sigmod())->rules()->maxHeldItems()) + if (m_item.size() < sigmod()->rules()->maxHeldItems()) { if (checkWeight(item)) { @@ -164,17 +164,17 @@ void Sigmod::MapTrainerTeamMember::setItem(const int item, const bool state) void Sigmod::MapTrainerTeamMember::setMove(const int move, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->moveIndex(move) == INT_MAX) + if (!sigmod()->moveById(move)) emit(error(bounds("move"))); else if (state && !m_move.contains(move)) { - const Species* species = qobject_cast<const Sigmod*>(sigmod())->speciesById(move); + const Species* species = sigmod()->speciesById(move); for (int i = 0; i < species->moveCount(); ++i) { const SpeciesMove* speciesMove = species->move(i); if (speciesMove->move() == move) { - if (m_move.size() < qobject_cast<const Sigmod*>(sigmod())->rules()->maxMoves()) + if (m_move.size() < sigmod()->rules()->maxMoves()) { m_move.append(move); emit(changed()); @@ -195,11 +195,11 @@ void Sigmod::MapTrainerTeamMember::setMove(const int move, const bool state) void Sigmod::MapTrainerTeamMember::setNature(const int nature, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->natureIndex(nature) == INT_MAX) + if (!sigmod()->natureById(nature)) emit(error(bounds("nature"))); else if (state && !m_nature.contains(nature)) { - if (m_nature.size() < qobject_cast<const Sigmod*>(sigmod())->rules()->maxNatures()) + if (m_nature.size() < sigmod()->rules()->maxNatures()) { m_nature.append(nature); emit(changed()); @@ -279,15 +279,15 @@ Sigmod::MapTrainerTeamMember& Sigmod::MapTrainerTeamMember::operator=(const MapT bool Sigmod::MapTrainerTeamMember::checkWeight(const int item) { - const int speciesIndex = qobject_cast<const Sigmod*>(sigmod())->speciesIndex(m_species); - if (speciesIndex == INT_MAX) + const Species* species = sigmod()->speciesById(m_species); + if (!species) return true; - int totalWeight = qobject_cast<const Sigmod*>(sigmod())->itemById(item)->weight(); - foreach (int item, m_item) + int totalWeight = sigmod()->itemById(item)->weight(); + foreach (int itemId, m_item) { - const int itemIndex = qobject_cast<const Sigmod*>(sigmod())->itemIndex(item); - if (itemIndex != INT_MAX) - totalWeight += qobject_cast<const Sigmod*>(sigmod())->item(itemIndex)->weight(); + const Item* item = sigmod()->itemById(itemId); + if (!item) + totalWeight += item->weight(); } - return (totalWeight <= qobject_cast<const Sigmod*>(sigmod())->species(speciesIndex)->maxHoldWeight()); + return (totalWeight <= species->maxHoldWeight()); } diff --git a/sigmod/MapWarp.cpp b/sigmod/MapWarp.cpp index bd4934b6..e0482f14 100644 --- a/sigmod/MapWarp.cpp +++ b/sigmod/MapWarp.cpp @@ -34,7 +34,7 @@ Sigmod::MapWarp::MapWarp(const MapWarp& warp) : Sigmod::MapWarp::MapWarp(const Map* parent, const int id) : Object(parent, id), m_name(""), - m_coordinate(0, 0), + m_area(0, 0, 32, 32), m_type(Door), m_toMap(INT_MAX), m_toWarp(INT_MAX), @@ -60,6 +60,7 @@ void Sigmod::MapWarp::validate() TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); + TEST(setArea, area); TEST(setToMap, toMap); TEST(setToWarp, toWarp); TEST_END(); @@ -69,7 +70,7 @@ void Sigmod::MapWarp::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(name); - LOAD(coordinate); + LOAD(area); LOAD(type); LOAD(toMap); LOAD(toWarp); @@ -80,7 +81,7 @@ QDomElement Sigmod::MapWarp::save() const { SAVE_CREATE(); SAVE(name); - SAVE(coordinate); + SAVE(area); SAVE(type); SAVE(toMap); SAVE(toWarp); @@ -93,12 +94,15 @@ void Sigmod::MapWarp::setName(const QString& name) CHECK(name); } -void Sigmod::MapWarp::setCoordinate(const QPoint& coordinate) +void Sigmod::MapWarp::setArea(const QRect& area) { - if ((qobject_cast<const Map*>(parent())->width() <= coordinate.x()) || (qobject_cast<const Map*>(parent())->height() <= coordinate.y())) - emit(error(bounds("coordinate"))); + const Map* map = qobject_cast<const Map*>(parent()); + if ((map->width() <= area.x()) || (map->height() <= area.y())) + emit(error(bounds("area"))); + else if ((area.width() <= 0) || (area.height() <= 0)) + emit(error(bounds("area"))); else - CHECK(coordinate); + CHECK(area); } void Sigmod::MapWarp::setType(const Type type) @@ -108,7 +112,7 @@ void Sigmod::MapWarp::setType(const Type type) void Sigmod::MapWarp::setToMap(const int toMap) { - if (qobject_cast<const Sigmod*>(sigmod())->mapIndex(toMap) == INT_MAX) + if (!sigmod()->mapById(toMap)) emit(error(bounds("toMap"))); else CHECK(toMap); @@ -116,9 +120,10 @@ void Sigmod::MapWarp::setToMap(const int toMap) void Sigmod::MapWarp::setToWarp(const int toWarp) { - if (qobject_cast<const Sigmod*>(sigmod())->mapIndex(m_toMap) == INT_MAX) + const Map* map = sigmod()->mapById(m_toMap); + if (!map) emit(error(bounds("toMap"))); - else if (qobject_cast<const Sigmod*>(sigmod())->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) + else if (!map->warpById(toWarp)) emit(error(bounds("toWarp"))); else CHECK(toWarp); @@ -134,9 +139,9 @@ QString Sigmod::MapWarp::name() const return m_name; } -QPoint Sigmod::MapWarp::coordinate() const +QRect Sigmod::MapWarp::area() const { - return m_coordinate; + return m_area; } Sigmod::MapWarp::Type Sigmod::MapWarp::type() const @@ -164,7 +169,7 @@ Sigmod::MapWarp& Sigmod::MapWarp::operator=(const MapWarp& rhs) if (this == &rhs) return *this; COPY(name); - COPY(coordinate); + COPY(area); COPY(type); COPY(toMap); COPY(toWarp); diff --git a/sigmod/MapWarp.h b/sigmod/MapWarp.h index f99afdf3..dfdef6c3 100644 --- a/sigmod/MapWarp.h +++ b/sigmod/MapWarp.h @@ -25,7 +25,7 @@ #include "Object.h" // Qt includes -#include <QtCore/QPoint> +#include <QtCore/QRect> namespace Sigmod { @@ -58,14 +58,14 @@ class SIGMOD_EXPORT MapWarp : public Object QDomElement save() const; void setName(const QString& name); - void setCoordinate(const QPoint& coordinate); + void setArea(const QRect& area); void setType(const Type type); void setToMap(const int toMap); void setToWarp(const int toWarp); void setScript(const Sigcore::Script& script); QString name() const; - QPoint coordinate() const; + QRect area() const; Type type() const; int toMap() const; int toWarp() const; @@ -74,7 +74,7 @@ class SIGMOD_EXPORT MapWarp : public Object MapWarp& operator=(const MapWarp& rhs); private: QString m_name; - QPoint m_coordinate; + QRect m_area; Type m_type; int m_toMap; int m_toWarp; diff --git a/sigmod/MapWildList.cpp b/sigmod/MapWildList.cpp index 1f8b9c17..1a385632 100644 --- a/sigmod/MapWildList.cpp +++ b/sigmod/MapWildList.cpp @@ -97,14 +97,16 @@ QString Sigmod::MapWildList::name() const const Sigmod::MapWildListEncounter* Sigmod::MapWildList::encounter(const int index) const { - Q_ASSERT(index < encounterCount()); - return m_encounters.at(index); + if (index < encounterCount()) + return m_encounters.at(index); + return NULL; } Sigmod::MapWildListEncounter* Sigmod::MapWildList::encounter(const int index) { - Q_ASSERT(index < encounterCount()); - return m_encounters[index]; + if (index < encounterCount()) + return m_encounters[index]; + return NULL; } const Sigmod::MapWildListEncounter* Sigmod::MapWildList::encounterById(const int id) const @@ -155,9 +157,11 @@ Sigmod::MapWildListEncounter* Sigmod::MapWildList::newEncounter(MapWildListEncou void Sigmod::MapWildList::deleteEncounter(const int index) { - Q_ASSERT(index < encounterCount()); - delete m_encounters[index]; - m_encounters.removeAt(index); + if (index < encounterCount()) + { + delete m_encounters[index]; + m_encounters.removeAt(index); + } } void Sigmod::MapWildList::deleteEncounterById(const int id) diff --git a/sigmod/MapWildListEncounter.cpp b/sigmod/MapWildListEncounter.cpp index 17482f4f..0fb44e02 100644 --- a/sigmod/MapWildListEncounter.cpp +++ b/sigmod/MapWildListEncounter.cpp @@ -80,7 +80,7 @@ QDomElement Sigmod::MapWildListEncounter::save() const void Sigmod::MapWildListEncounter::setSpecies(const int species) { - if (qobject_cast<const Sigmod*>(sigmod())->speciesIndex(species) == INT_MAX) + if (!sigmod()->speciesById(species)) emit(error(bounds("species"))); else CHECK(species); @@ -88,7 +88,7 @@ void Sigmod::MapWildListEncounter::setSpecies(const int species) void Sigmod::MapWildListEncounter::setLevel(const int level) { - if (!level || (qobject_cast<const Sigmod*>(sigmod())->rules()->maxLevel() <= level)) + if (!level || (sigmod()->rules()->maxLevel() <= level)) emit(error(bounds("level"))); else CHECK(level); diff --git a/sigmod/Move.cpp b/sigmod/Move.cpp index 6f309eb4..6d7a3aa0 100644 --- a/sigmod/Move.cpp +++ b/sigmod/Move.cpp @@ -129,7 +129,7 @@ void Sigmod::Move::setPower(const int power) void Sigmod::Move::setType(const int type) { - if (qobject_cast<const Sigmod*>(sigmod())->typeIndex(type) == INT_MAX) + if (!sigmod()->typeById(type)) emit(error(bounds("type"))); else CHECK(type); diff --git a/sigmod/Nature.cpp b/sigmod/Nature.cpp index 5df36bc3..3238ba9d 100644 --- a/sigmod/Nature.cpp +++ b/sigmod/Nature.cpp @@ -91,7 +91,7 @@ void Sigmod::Nature::setStat(const Stat stat, const Sigcore::Fraction& multiplie switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_Attack ... ST_Special: break; default: @@ -119,7 +119,7 @@ Sigcore::Fraction Sigmod::Nature::stat(const Stat stat) const switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_Attack ... ST_Special: return m_stat[stat - ST_Attack]; default: diff --git a/sigmod/Sigmod.cpp b/sigmod/Sigmod.cpp index 11915177..26895d08 100644 --- a/sigmod/Sigmod.cpp +++ b/sigmod/Sigmod.cpp @@ -91,9 +91,10 @@ void Sigmod::Sigmod::validate() emit(warning("Description is empty")); if (m_singlePlayer) { - if (mapIndex(m_startMap) == INT_MAX) + const Map* map = mapById(m_startMap); + if (!map) emit(error("Invalid starting map")); - else if (mapById(m_startMap)->warpIndex(m_startWarp) == INT_MAX) + else if (!map->warpById(m_startWarp)) emit(error("Invalid starting warp")); } if ((m_typechart.width() != typeCount()) || (m_typechart.height() != typeCount())) @@ -371,7 +372,7 @@ void Sigmod::Sigmod::setStartMap(const int startMap) { if (!m_singlePlayer) emit(error(unused("startMap"))); - if (mapIndex(startMap) == INT_MAX) + if (!mapById(startMap)) emit(error(bounds("startMap"))); else CHECK(startMap); @@ -381,9 +382,10 @@ void Sigmod::Sigmod::setStartWarp(const int startWarp) { if (!m_singlePlayer) emit(error(unused("startWarp"))); - if (mapIndex(m_startMap) == INT_MAX) + const Map* map = mapById(m_startMap); + if (!map) emit(error(bounds("startMap"))); - else if (mapById(m_startMap)->warpIndex(startWarp) == INT_MAX) + else if (!map->warpById(startWarp)) emit(error(bounds("startWarp"))); else CHECK(startWarp); @@ -461,14 +463,16 @@ Sigmod::Rules* Sigmod::Sigmod::rules() const Sigmod::Ability* Sigmod::Sigmod::ability(const int index) const { - Q_ASSERT(index < abilityCount()); - return m_abilities.at(index); + if (index < abilityCount()) + return m_abilities.at(index); + return NULL; } Sigmod::Ability* Sigmod::Sigmod::ability(const int index) { - Q_ASSERT(index < abilityCount()); - return m_abilities[index]; + if (index < abilityCount()) + return m_abilities[index]; + return NULL; } const Sigmod::Ability* Sigmod::Sigmod::abilityById(const int id) const @@ -519,9 +523,11 @@ Sigmod::Ability* Sigmod::Sigmod::newAbility(Ability* ability) void Sigmod::Sigmod::deleteAbility(const int index) { - Q_ASSERT(index < abilityCount()); - delete m_abilities[index]; - m_abilities.removeAt(index); + if (index < abilityCount()) + { + delete m_abilities[index]; + m_abilities.removeAt(index); + } } void Sigmod::Sigmod::deleteAbilityById(const int id) @@ -539,14 +545,16 @@ int Sigmod::Sigmod::newAbilityId() const const Sigmod::Author* Sigmod::Sigmod::author(const int index) const { - Q_ASSERT(index < authorCount()); - return m_authors.at(index); + if (index < authorCount()) + return m_authors.at(index); + return NULL; } Sigmod::Author* Sigmod::Sigmod::author(const int index) { - Q_ASSERT(index < authorCount()); - return m_authors[index]; + if (index < authorCount()) + return m_authors[index]; + return NULL; } const Sigmod::Author* Sigmod::Sigmod::authorById(const int id) const @@ -597,9 +605,11 @@ Sigmod::Author* Sigmod::Sigmod::newAuthor(Author* author) void Sigmod::Sigmod::deleteAuthor(const int index) { - Q_ASSERT(index < authorCount()); - delete m_authors[index]; - m_authors.removeAt(index); + if (index < authorCount()) + { + delete m_authors[index]; + m_authors.removeAt(index); + } } void Sigmod::Sigmod::deleteAuthorById(const int id) @@ -617,14 +627,16 @@ int Sigmod::Sigmod::newAuthorId() const const Sigmod::Badge* Sigmod::Sigmod::badge(const int index) const { - Q_ASSERT(index < badgeCount()); - return m_badges.at(index); + if (index < badgeCount()) + return m_badges.at(index); + return NULL; } Sigmod::Badge* Sigmod::Sigmod::badge(const int index) { - Q_ASSERT(index < badgeCount()); - return m_badges[index]; + if (index < badgeCount()) + return m_badges[index]; + return NULL; } const Sigmod::Badge* Sigmod::Sigmod::badgeById(const int id) const @@ -675,9 +687,11 @@ Sigmod::Badge* Sigmod::Sigmod::newBadge(Badge* badge) void Sigmod::Sigmod::deleteBadge(const int index) { - Q_ASSERT(index < badgeCount()); - delete m_badges[index]; - m_badges.removeAt(index); + if (index < badgeCount()) + { + delete m_badges[index]; + m_badges.removeAt(index); + } } void Sigmod::Sigmod::deleteBadgeById(const int id) @@ -695,14 +709,16 @@ int Sigmod::Sigmod::newBadgeId() const const Sigmod::CoinList* Sigmod::Sigmod::coinList(const int index) const { - Q_ASSERT(index < coinListCount()); - return m_coinLists.at(index); + if (index < coinListCount()) + return m_coinLists.at(index); + return NULL; } Sigmod::CoinList* Sigmod::Sigmod::coinList(const int index) { - Q_ASSERT(index < coinListCount()); - return m_coinLists[index]; + if (index < coinListCount()) + return m_coinLists[index]; + return NULL; } const Sigmod::CoinList* Sigmod::Sigmod::coinListById(const int id) const @@ -753,9 +769,11 @@ Sigmod::CoinList* Sigmod::Sigmod::newCoinList(CoinList* coinList) void Sigmod::Sigmod::deleteCoinList(const int index) { - Q_ASSERT(index < coinListCount()); - delete m_coinLists[index]; - m_coinLists.removeAt(index); + if (index < coinListCount()) + { + delete m_coinLists[index]; + m_coinLists.removeAt(index); + } } void Sigmod::Sigmod::deleteCoinListById(const int id) @@ -773,14 +791,16 @@ int Sigmod::Sigmod::newCoinListId() const const Sigmod::EggGroup* Sigmod::Sigmod::eggGroup(const int index) const { - Q_ASSERT(index < eggGroupCount()); - return m_eggGroups.at(index); + if (index < eggGroupCount()) + return m_eggGroups.at(index); + return NULL; } Sigmod::EggGroup* Sigmod::Sigmod::eggGroup(const int index) { - Q_ASSERT(index < eggGroupCount()); - return m_eggGroups[index]; + if (index < eggGroupCount()) + return m_eggGroups[index]; + return NULL; } const Sigmod::EggGroup* Sigmod::Sigmod::eggGroupById(const int id) const @@ -831,9 +851,11 @@ Sigmod::EggGroup* Sigmod::Sigmod::newEggGroup(EggGroup* eggGroup) void Sigmod::Sigmod::deleteEggGroup(const int index) { - Q_ASSERT(index < eggGroupCount()); - delete m_eggGroups[index]; - m_eggGroups.removeAt(index); + if (index < eggGroupCount()) + { + delete m_eggGroups[index]; + m_eggGroups.removeAt(index); + } } void Sigmod::Sigmod::deleteEggGroupById(const int id) @@ -851,14 +873,16 @@ int Sigmod::Sigmod::newEggGroupId() const const Sigmod::GlobalScript* Sigmod::Sigmod::globalScript(const int index) const { - Q_ASSERT(index < globalScriptCount()); - return m_globalScripts.at(index); + if (index < globalScriptCount()) + return m_globalScripts.at(index); + return NULL; } Sigmod::GlobalScript* Sigmod::Sigmod::globalScript(const int index) { - Q_ASSERT(index < globalScriptCount()); - return m_globalScripts[index]; + if (index < globalScriptCount()) + return m_globalScripts[index]; + return NULL; } const Sigmod::GlobalScript* Sigmod::Sigmod::globalScriptById(const int id) const @@ -909,9 +933,11 @@ Sigmod::GlobalScript* Sigmod::Sigmod::newGlobalScript(GlobalScript* globalScript void Sigmod::Sigmod::deleteGlobalScript(const int index) { - Q_ASSERT(index < globalScriptCount()); - delete m_globalScripts[index]; - m_globalScripts.removeAt(index); + if (index < globalScriptCount()) + { + delete m_globalScripts[index]; + m_globalScripts.removeAt(index); + } } void Sigmod::Sigmod::deleteGlobalScriptById(const int id) @@ -929,14 +955,16 @@ int Sigmod::Sigmod::newGlobalScriptId() const const Sigmod::Item* Sigmod::Sigmod::item(const int index) const { - Q_ASSERT(index < itemCount()); - return m_items.at(index); + if (index < itemCount()) + return m_items.at(index); + return NULL; } Sigmod::Item* Sigmod::Sigmod::item(const int index) { - Q_ASSERT(index < itemCount()); - return m_items[index]; + if (index < itemCount()) + return m_items[index]; + return NULL; } const Sigmod::Item* Sigmod::Sigmod::itemById(const int id) const @@ -987,9 +1015,11 @@ Sigmod::Item* Sigmod::Sigmod::newItem(Item* item) void Sigmod::Sigmod::deleteItem(const int index) { - Q_ASSERT(index < itemCount()); - delete m_items[index]; - m_items.removeAt(index); + if (index < itemCount()) + { + delete m_items[index]; + m_items.removeAt(index); + } } void Sigmod::Sigmod::deleteItemById(const int id) @@ -1000,21 +1030,23 @@ void Sigmod::Sigmod::deleteItemById(const int id) int Sigmod::Sigmod::newItemId() const { int i = 0; - for (; (i < itemCount()) && (itemIndex(i) != INT_MAX); ++i) - ; + while ((i < itemCount()) && (itemIndex(i) != INT_MAX)) + ++i; return i; } const Sigmod::ItemType* Sigmod::Sigmod::itemType(const int index) const { - Q_ASSERT(index < itemTypeCount()); - return m_itemTypes.at(index); + if (index < itemTypeCount()) + return m_itemTypes.at(index); + return NULL; } Sigmod::ItemType* Sigmod::Sigmod::itemType(const int index) { - Q_ASSERT(index < itemTypeCount()); - return m_itemTypes[index]; + if (index < itemTypeCount()) + return m_itemTypes[index]; + return NULL; } const Sigmod::ItemType* Sigmod::Sigmod::itemTypeById(const int id) const @@ -1065,9 +1097,11 @@ Sigmod::ItemType* Sigmod::Sigmod::newItemType(ItemType* itemType) void Sigmod::Sigmod::deleteItemType(const int index) { - Q_ASSERT(index < itemTypeCount()); - delete m_itemTypes[index]; - m_itemTypes.removeAt(index); + if (index < itemTypeCount()) + { + delete m_itemTypes[index]; + m_itemTypes.removeAt(index); + } } void Sigmod::Sigmod::deleteItemTypeById(const int id) @@ -1085,14 +1119,16 @@ int Sigmod::Sigmod::newItemTypeId() const const Sigmod::Map* Sigmod::Sigmod::map(const int index) const { - Q_ASSERT(index < mapCount()); - return m_maps.at(index); + if (index < mapCount()) + return m_maps.at(index); + return NULL; } Sigmod::Map* Sigmod::Sigmod::map(const int index) { - Q_ASSERT(index < mapCount()); - return m_maps[index]; + if (index < mapCount()) + return m_maps[index]; + return NULL; } const Sigmod::Map* Sigmod::Sigmod::mapById(const int id) const @@ -1143,9 +1179,11 @@ Sigmod::Map* Sigmod::Sigmod::newMap(Map* map) void Sigmod::Sigmod::deleteMap(const int index) { - Q_ASSERT(index < mapCount()); - delete m_maps[index]; - m_maps.removeAt(index); + if (index < mapCount()) + { + delete m_maps[index]; + m_maps.removeAt(index); + } } void Sigmod::Sigmod::deleteMapById(const int id) @@ -1163,14 +1201,16 @@ int Sigmod::Sigmod::newMapId() const const Sigmod::Move* Sigmod::Sigmod::move(const int index) const { - Q_ASSERT(index < moveCount()); - return m_moves.at(index); + if (index < moveCount()) + return m_moves.at(index); + return NULL; } Sigmod::Move* Sigmod::Sigmod::move(const int index) { - Q_ASSERT(index < moveCount()); - return m_moves[index]; + if (index < moveCount()) + return m_moves[index]; + return NULL; } const Sigmod::Move* Sigmod::Sigmod::moveById(const int id) const @@ -1221,9 +1261,11 @@ Sigmod::Move* Sigmod::Sigmod::newMove(Move* move) void Sigmod::Sigmod::deleteMove(const int index) { - Q_ASSERT(index < moveCount()); - delete m_moves[index]; - m_moves.removeAt(index); + if (index < moveCount()) + { + delete m_moves[index]; + m_moves.removeAt(index); + } } void Sigmod::Sigmod::deleteMoveById(const int id) @@ -1241,14 +1283,16 @@ int Sigmod::Sigmod::newMoveId() const const Sigmod::Nature* Sigmod::Sigmod::nature(const int index) const { - Q_ASSERT(index < natureCount()); - return m_natures.at(index); + if (index < natureCount()) + return m_natures.at(index); + return NULL; } Sigmod::Nature* Sigmod::Sigmod::nature(const int index) { - Q_ASSERT(index < natureCount()); - return m_natures[index]; + if (index < natureCount()) + return m_natures[index]; + return NULL; } const Sigmod::Nature* Sigmod::Sigmod::natureById(const int id) const @@ -1299,9 +1343,11 @@ Sigmod::Nature* Sigmod::Sigmod::newNature(Nature* nature) void Sigmod::Sigmod::deleteNature(const int index) { - Q_ASSERT(index < natureCount()); - delete m_natures[index]; - m_natures.removeAt(index); + if (index < natureCount()) + { + delete m_natures[index]; + m_natures.removeAt(index); + } } void Sigmod::Sigmod::deleteNatureById(const int id) @@ -1319,14 +1365,16 @@ int Sigmod::Sigmod::newNatureId() const const Sigmod::Skin* Sigmod::Sigmod::skin(const int index) const { - Q_ASSERT(index < skinCount()); - return m_skins.at(index); + if (index < skinCount()) + return m_skins.at(index); + return NULL; } Sigmod::Skin* Sigmod::Sigmod::skin(const int index) { - Q_ASSERT(index < skinCount()); - return m_skins[index]; + if (index < skinCount()) + return m_skins[index]; + return NULL; } const Sigmod::Skin* Sigmod::Sigmod::skinById(const int id) const @@ -1377,9 +1425,11 @@ Sigmod::Skin* Sigmod::Sigmod::newSkin(Skin* skin) void Sigmod::Sigmod::deleteSkin(const int index) { - Q_ASSERT(index < skinCount()); - delete m_skins[index]; - m_skins.removeAt(index); + if (index < skinCount()) + { + delete m_skins[index]; + m_skins.removeAt(index); + } } void Sigmod::Sigmod::deleteSkinById(const int id) @@ -1397,14 +1447,16 @@ int Sigmod::Sigmod::newSkinId() const const Sigmod::Sound* Sigmod::Sigmod::sound(const int index) const { - Q_ASSERT(index < soundCount()); - return m_sounds.at(index); + if (index < soundCount()) + return m_sounds.at(index); + return NULL; } Sigmod::Sound* Sigmod::Sigmod::sound(const int index) { - Q_ASSERT(index < soundCount()); - return m_sounds[index]; + if (index < soundCount()) + return m_sounds[index]; + return NULL; } const Sigmod::Sound* Sigmod::Sigmod::soundById(const int id) const @@ -1455,9 +1507,11 @@ Sigmod::Sound* Sigmod::Sigmod::newSound(Sound* sound) void Sigmod::Sigmod::deleteSound(const int index) { - Q_ASSERT(index < soundCount()); - delete m_sounds[index]; - m_sounds.removeAt(index); + if (index < soundCount()) + { + delete m_sounds[index]; + m_sounds.removeAt(index); + } } void Sigmod::Sigmod::deleteSoundById(const int id) @@ -1475,14 +1529,16 @@ int Sigmod::Sigmod::newSoundId() const const Sigmod::Species* Sigmod::Sigmod::species(const int index) const { - Q_ASSERT(index < speciesCount()); - return m_species.at(index); + if (index < speciesCount()) + return m_species.at(index); + return NULL; } Sigmod::Species* Sigmod::Sigmod::species(const int index) { - Q_ASSERT(index < speciesCount()); - return m_species[index]; + if (index < speciesCount()) + return m_species[index]; + return NULL; } const Sigmod::Species* Sigmod::Sigmod::speciesById(const int id) const @@ -1533,9 +1589,11 @@ Sigmod::Species* Sigmod::Sigmod::newSpecies(Species* species) void Sigmod::Sigmod::deleteSpecies(const int index) { - Q_ASSERT(index < speciesCount()); - delete m_species[index]; - m_species.removeAt(index); + if (index < speciesCount()) + { + delete m_species[index]; + m_species.removeAt(index); + } } void Sigmod::Sigmod::deleteSpeciesById(const int id) @@ -1553,14 +1611,16 @@ int Sigmod::Sigmod::newSpeciesId() const const Sigmod::Sprite* Sigmod::Sigmod::sprite(const int index) const { - Q_ASSERT(index < spriteCount()); - return m_sprites.at(index); + if (index < spriteCount()) + return m_sprites.at(index); + return NULL; } Sigmod::Sprite* Sigmod::Sigmod::sprite(const int index) { - Q_ASSERT(index < spriteCount()); - return m_sprites[index]; + if (index < spriteCount()) + return m_sprites[index]; + return NULL; } const Sigmod::Sprite* Sigmod::Sigmod::spriteById(const int id) const @@ -1611,9 +1671,11 @@ Sigmod::Sprite* Sigmod::Sigmod::newSprite(Sprite* sprite) void Sigmod::Sigmod::deleteSprite(const int index) { - Q_ASSERT(index < spriteCount()); - delete m_sprites[index]; - m_sprites.removeAt(index); + if (index < spriteCount()) + { + delete m_sprites[index]; + m_sprites.removeAt(index); + } } void Sigmod::Sigmod::deleteSpriteById(const int id) @@ -1631,14 +1693,16 @@ int Sigmod::Sigmod::newSpriteId() const const Sigmod::Status* Sigmod::Sigmod::status(const int index) const { - Q_ASSERT(index < statusCount()); - return m_status.at(index); + if (index < statusCount()) + return m_status.at(index); + return NULL; } Sigmod::Status* Sigmod::Sigmod::status(const int index) { - Q_ASSERT(index < statusCount()); - return m_status[index]; + if (index < statusCount()) + return m_status[index]; + return NULL; } const Sigmod::Status* Sigmod::Sigmod::statusById(const int id) const @@ -1689,9 +1753,11 @@ Sigmod::Status* Sigmod::Sigmod::newStatus(Status* status) void Sigmod::Sigmod::deleteStatus(const int index) { - Q_ASSERT(index < statusCount()); - delete m_status[index]; - m_status.removeAt(index); + if (index < statusCount()) + { + delete m_status[index]; + m_status.removeAt(index); + } } void Sigmod::Sigmod::deleteStatusById(const int id) @@ -1709,14 +1775,16 @@ int Sigmod::Sigmod::newStatusId() const const Sigmod::Store* Sigmod::Sigmod::store(const int index) const { - Q_ASSERT(index < storeCount()); - return m_stores.at(index); + if (index < storeCount()) + return m_stores.at(index); + return NULL; } Sigmod::Store* Sigmod::Sigmod::store(const int index) { - Q_ASSERT(index < storeCount()); - return m_stores[index]; + if (index < storeCount()) + return m_stores[index]; + return NULL; } const Sigmod::Store* Sigmod::Sigmod::storeById(const int id) const @@ -1767,9 +1835,11 @@ Sigmod::Store* Sigmod::Sigmod::newStore(Store* store) void Sigmod::Sigmod::deleteStore(const int index) { - Q_ASSERT(index < storeCount()); - delete m_stores[index]; - m_stores.removeAt(index); + if (index < storeCount()) + { + delete m_stores[index]; + m_stores.removeAt(index); + } } void Sigmod::Sigmod::deleteStoreById(const int id) @@ -1787,14 +1857,16 @@ int Sigmod::Sigmod::newStoreId() const const Sigmod::Tile* Sigmod::Sigmod::tile(const int index) const { - Q_ASSERT(index < tileCount()); - return m_tiles.at(index); + if (index < tileCount()) + return m_tiles.at(index); + return NULL; } Sigmod::Tile* Sigmod::Sigmod::tile(const int index) { - Q_ASSERT(index < tileCount()); - return m_tiles[index]; + if (index < tileCount()) + return m_tiles[index]; + return NULL; } const Sigmod::Tile* Sigmod::Sigmod::tileById(const int id) const @@ -1845,9 +1917,11 @@ Sigmod::Tile* Sigmod::Sigmod::newTile(Tile* tile) void Sigmod::Sigmod::deleteTile(const int index) { - Q_ASSERT(index < tileCount()); - delete m_tiles[index]; - m_tiles.removeAt(index); + if (index < tileCount()) + { + delete m_tiles[index]; + m_tiles.removeAt(index); + } } void Sigmod::Sigmod::deleteTileById(const int id) @@ -1865,14 +1939,16 @@ int Sigmod::Sigmod::newTileId() const const Sigmod::Time* Sigmod::Sigmod::time(const int index) const { - Q_ASSERT(index < timeCount()); - return m_times.at(index); + if (index < timeCount()) + return m_times.at(index); + return NULL; } Sigmod::Time* Sigmod::Sigmod::time(const int index) { - Q_ASSERT(index < timeCount()); - return m_times[index]; + if (index < timeCount()) + return m_times[index]; + return NULL; } const Sigmod::Time* Sigmod::Sigmod::timeById(const int id) const @@ -1923,9 +1999,11 @@ Sigmod::Time* Sigmod::Sigmod::newTime(Time* time) void Sigmod::Sigmod::deleteTime(const int index) { - Q_ASSERT(index < timeCount()); - delete m_times[index]; - m_times.removeAt(index); + if (index < timeCount()) + { + delete m_times[index]; + m_times.removeAt(index); + } } void Sigmod::Sigmod::deleteTimeById(const int id) @@ -1943,14 +2021,16 @@ int Sigmod::Sigmod::newTimeId() const const Sigmod::Trainer* Sigmod::Sigmod::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::Trainer* Sigmod::Sigmod::trainer(const int index) { - Q_ASSERT(index < trainerCount()); - return m_trainers[index]; + if (index < trainerCount()) + return m_trainers[index]; + return NULL; } const Sigmod::Trainer* Sigmod::Sigmod::trainerById(const int id) const @@ -2001,9 +2081,11 @@ Sigmod::Trainer* Sigmod::Sigmod::newTrainer(Trainer* trainer) void Sigmod::Sigmod::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::Sigmod::deleteTrainerById(const int id) @@ -2021,14 +2103,16 @@ int Sigmod::Sigmod::newTrainerId() const const Sigmod::Type* Sigmod::Sigmod::type(const int index) const { - Q_ASSERT(index < typeCount()); - return m_types.at(index); + if (index < typeCount()) + return m_types.at(index); + return NULL; } Sigmod::Type* Sigmod::Sigmod::type(const int index) { - Q_ASSERT(index < typeCount()); - return m_types[index]; + if (index < typeCount()) + return m_types[index]; + return NULL; } const Sigmod::Type* Sigmod::Sigmod::typeById(const int id) const @@ -2080,10 +2164,12 @@ Sigmod::Type* Sigmod::Sigmod::newType(Type* type) void Sigmod::Sigmod::deleteType(const int index) { - Q_ASSERT(index < typeCount()); - delete m_types[index]; - m_types.removeAt(index); - m_typechart.resize(typeCount(), typeCount(), Sigcore::Fraction(1, 1)); + if (index < typeCount()) + { + delete m_types[index]; + m_types.removeAt(index); + m_typechart.resize(typeCount(), typeCount(), Sigcore::Fraction(1, 1)); + } } void Sigmod::Sigmod::deleteTypeById(const int id) @@ -2101,14 +2187,16 @@ int Sigmod::Sigmod::newTypeId() const const Sigmod::Weather* Sigmod::Sigmod::weather(const int index) const { - Q_ASSERT(index < weatherCount()); - return m_weathers.at(index); + if (index < weatherCount()) + return m_weathers.at(index); + return NULL; } Sigmod::Weather* Sigmod::Sigmod::weather(const int index) { - Q_ASSERT(index < weatherCount()); - return m_weathers[index]; + if (index < weatherCount()) + return m_weathers[index]; + return NULL; } const Sigmod::Weather* Sigmod::Sigmod::weatherById(const int id) const @@ -2159,9 +2247,11 @@ Sigmod::Weather* Sigmod::Sigmod::newWeather(Weather* weather) void Sigmod::Sigmod::deleteWeather(const int index) { - Q_ASSERT(index < weatherCount()); - delete m_weathers[index]; - m_weathers.removeAt(index); + if (index < weatherCount()) + { + delete m_weathers[index]; + m_weathers.removeAt(index); + } } void Sigmod::Sigmod::deleteWeatherById(const int id) diff --git a/sigmod/Species.cpp b/sigmod/Species.cpp index 0340abd0..f7884170 100644 --- a/sigmod/Species.cpp +++ b/sigmod/Species.cpp @@ -111,13 +111,14 @@ void Sigmod::Species::validate() if ((m_encyclopediaNumber != INT_MAX) && m_encyclopediaEntry.isEmpty()) emit(error("Encyclopedia entry is empty")); TEST(setGenderFactor, genderFactor); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->breedingAllowed()) + if (sigmod()->rules()->breedingAllowed()) { - if (qobject_cast<const Sigmod*>(sigmod())->speciesIndex(m_eggSpecies) == INT_MAX) + const Species* eggSpecies = sigmod()->speciesById(m_eggSpecies); + if (!eggSpecies) emit(error(bounds("egg species"))); else { - if (qobject_cast<const Sigmod*>(sigmod())->species(m_eggSpecies)->growth() != m_growth) + if (eggSpecies->growth() != m_growth) emit(error("Growth mismatch with egg species")); TEST(setEggSteps, eggSteps); } @@ -126,7 +127,7 @@ void Sigmod::Species::validate() TEST_LIST(setEggGroup, eggGroup); QSet<int> idChecker; QSet<int> valueChecker; - if (abilityCount() < qobject_cast<const Sigmod*>(sigmod())->rules()->maxAbilities()) + if (abilityCount() < sigmod()->rules()->maxAbilities()) emit(warning("There are too few abilities")); TEST_SUB_BEGIN(SpeciesAbility, abilities); TEST_SUB("ability", id); @@ -134,7 +135,7 @@ void Sigmod::Species::validate() TEST_SUB_END(); idChecker.clear(); valueChecker.clear(); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxHeldItems() && !itemCount()) + if (sigmod()->rules()->maxHeldItems() && !itemCount()) emit(warning("There are no items")); TEST_SUB_BEGIN(SpeciesItem, items); TEST_SUB("item", id); @@ -228,7 +229,7 @@ void Sigmod::Species::setBaseStat(const Stat stat, const int baseStat) switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_HP ... ST_Special: break; default: @@ -240,14 +241,14 @@ void Sigmod::Species::setBaseStat(const Stat stat, const int baseStat) void Sigmod::Species::setEffortValue(const Stat stat, const int effortValue) { - if (!qobject_cast<const Sigmod*>(sigmod())->rules()->effortValuesAllowed()) + if (!sigmod()->rules()->effortValuesAllowed()) emit(error("Effort Values not allowed")); - else if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxEVPerStat() < effortValue) + else if (sigmod()->rules()->maxEVPerStat() < effortValue) emit(error(bounds("effortValue"))); switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_HP ... ST_Special: break; default: @@ -259,7 +260,7 @@ void Sigmod::Species::setEffortValue(const Stat stat, const int effortValue) void Sigmod::Species::setEffortValue(const int effortValue) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->effortValuesAllowed() && qobject_cast<const Sigmod*>(sigmod())->rules()->maxEVPerStat() < effortValue) + if (sigmod()->rules()->effortValuesAllowed() && sigmod()->rules()->maxEVPerStat() < effortValue) emit(error(bounds("effortValue"))); } @@ -334,7 +335,7 @@ void Sigmod::Species::setFrontMaleSprite(const int frontMaleSprite) { if (m_genderFactor.numerator() == m_genderFactor.denominator()) emit(error("Cannot be male")); - else if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(frontMaleSprite) == INT_MAX) + else if (!sigmod()->spriteById(frontMaleSprite)) emit(error(bounds("frontMaleSprite"))); else CHECK(frontMaleSprite); @@ -344,7 +345,7 @@ void Sigmod::Species::setBackMaleSprite(const int backMaleSprite) { if (m_genderFactor.numerator() == m_genderFactor.denominator()) emit(error("Cannot be male")); - else if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(backMaleSprite) == INT_MAX) + else if (!sigmod()->spriteById(backMaleSprite)) emit(error(bounds("backMaleSprite"))); else CHECK(backMaleSprite); @@ -352,13 +353,13 @@ void Sigmod::Species::setBackMaleSprite(const int backMaleSprite) void Sigmod::Species::setFrontFemaleSprite(const int frontFemaleSprite) { - if (!qobject_cast<const Sigmod*>(sigmod())->rules()->genderAllowed()) + if (!sigmod()->rules()->genderAllowed()) emit(error("Gender is not allowed")); else if (!m_genderFactor.numerator()) emit(error("Cannot be female")); else if (1 < m_genderFactor) emit(error("Genderless uses male sprites")); - else if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(frontFemaleSprite) == INT_MAX) + else if (!sigmod()->spriteById(frontFemaleSprite)) emit(error(bounds("frontFemaleSprite"))); else CHECK(frontFemaleSprite); @@ -366,13 +367,13 @@ void Sigmod::Species::setFrontFemaleSprite(const int frontFemaleSprite) void Sigmod::Species::setBackFemaleSprite(const int backFemaleSprite) { - if (!qobject_cast<const Sigmod*>(sigmod())->rules()->genderAllowed()) + if (!sigmod()->rules()->genderAllowed()) emit(error("Gender is not allowed")); else if (!m_genderFactor.numerator()) emit(error("Cannot be female")); else if (1 < m_genderFactor) emit(error("Genderless uses male sprites")); - else if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(backFemaleSprite) == INT_MAX) + else if (!sigmod()->spriteById(backFemaleSprite)) emit(error(bounds("backFemaleSprite"))); else CHECK(backFemaleSprite); @@ -380,7 +381,7 @@ void Sigmod::Species::setBackFemaleSprite(const int backFemaleSprite) void Sigmod::Species::setSkin(const int skin) { - if (qobject_cast<const Sigmod*>(sigmod())->skinIndex(skin) == INT_MAX) + if (!sigmod()->skinById(skin)) emit(error(bounds("skin"))); else CHECK(skin); @@ -393,7 +394,7 @@ void Sigmod::Species::setGenderFactor(const Sigcore::Fraction& genderFactor) void Sigmod::Species::setEggSpecies(const int eggSpecies) { - if (qobject_cast<const Sigmod*>(sigmod())->speciesIndex(eggSpecies) == INT_MAX) + if (!sigmod()->speciesById(eggSpecies)) emit(error(bounds("eggSpecies"))); else CHECK(eggSpecies); @@ -406,7 +407,7 @@ void Sigmod::Species::setEggSteps(const int eggSteps) void Sigmod::Species::setType(const int type, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->typeIndex(type) == INT_MAX) + if (!sigmod()->typeById(type)) emit(error(bounds("type"))); else if (state && !m_type.contains(type)) { @@ -422,7 +423,7 @@ void Sigmod::Species::setType(const int type, const bool state) void Sigmod::Species::setEggGroup(const int eggGroup, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->eggGroupIndex(eggGroup) == INT_MAX) + if (!sigmod()->eggGroupById(eggGroup)) emit(error(bounds("egg group"))); else if (state && !m_eggGroup.contains(eggGroup)) { @@ -451,7 +452,7 @@ int Sigmod::Species::baseStat(const Stat stat) const switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_HP ... ST_Special: return m_effortValue[stat]; default: @@ -465,7 +466,7 @@ int Sigmod::Species::effortValue(const Stat stat) const switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_HP ... ST_Special: return m_effortValue[stat]; default: @@ -596,14 +597,16 @@ Sigcore::Script Sigmod::Species::evolution() const const Sigmod::SpeciesAbility* Sigmod::Species::ability(const int index) const { - Q_ASSERT(index < abilityCount()); - return m_abilities.at(index); + if (index < abilityCount()) + return m_abilities.at(index); + return NULL; } Sigmod::SpeciesAbility* Sigmod::Species::ability(const int index) { - Q_ASSERT(index < abilityCount()); - return m_abilities[index]; + if (index < abilityCount()) + return m_abilities[index]; + return NULL; } const Sigmod::SpeciesAbility* Sigmod::Species::abilityById(const int id) const @@ -654,9 +657,11 @@ Sigmod::SpeciesAbility* Sigmod::Species::newAbility(SpeciesAbility* ability) void Sigmod::Species::deleteAbility(const int index) { - Q_ASSERT(index < abilityCount()); - delete m_abilities[index]; - m_abilities.removeAt(index); + if (index < abilityCount()) + { + delete m_abilities[index]; + m_abilities.removeAt(index); + } } void Sigmod::Species::deleteAbilityById(const int id) @@ -674,14 +679,16 @@ int Sigmod::Species::newAbilityId() const const Sigmod::SpeciesItem* Sigmod::Species::item(const int index) const { - Q_ASSERT(index < itemCount()); - return m_items.at(index); + if (index < itemCount()) + return m_items.at(index); + return NULL; } Sigmod::SpeciesItem* Sigmod::Species::item(const int index) { - Q_ASSERT(index < itemCount()); - return m_items[index]; + if (index < itemCount()) + return m_items[index]; + return NULL; } const Sigmod::SpeciesItem* Sigmod::Species::itemById(const int id) const @@ -732,9 +739,11 @@ Sigmod::SpeciesItem* Sigmod::Species::newItem(SpeciesItem* item) void Sigmod::Species::deleteItem(const int index) { - Q_ASSERT(index < itemCount()); - delete m_items[index]; - m_items.removeAt(index); + if (index < itemCount()) + { + delete m_items[index]; + m_items.removeAt(index); + } } void Sigmod::Species::deleteItemById(const int id) @@ -752,14 +761,16 @@ int Sigmod::Species::newItemId() const const Sigmod::SpeciesMove* Sigmod::Species::move(const int index) const { - Q_ASSERT(index < moveCount()); - return m_moves.at(index); + if (index < moveCount()) + return m_moves.at(index); + return NULL; } Sigmod::SpeciesMove* Sigmod::Species::move(const int index) { - Q_ASSERT(index < moveCount()); - return m_moves[index]; + if (index < moveCount()) + return m_moves[index]; + return NULL; } const Sigmod::SpeciesMove* Sigmod::Species::moveById(const int id) const @@ -810,9 +821,11 @@ Sigmod::SpeciesMove* Sigmod::Species::newMove(SpeciesMove* move) void Sigmod::Species::deleteMove(const int index) { - Q_ASSERT(index < moveCount()); - delete m_moves[index]; - m_moves.removeAt(index); + if (index < moveCount()) + { + delete m_moves[index]; + m_moves.removeAt(index); + } } void Sigmod::Species::deleteMoveById(const int id) diff --git a/sigmod/SpeciesAbility.cpp b/sigmod/SpeciesAbility.cpp index 4afc6785..355394ed 100644 --- a/sigmod/SpeciesAbility.cpp +++ b/sigmod/SpeciesAbility.cpp @@ -74,7 +74,7 @@ QDomElement Sigmod::SpeciesAbility::save() const void Sigmod::SpeciesAbility::setAbility(const int ability) { - if (qobject_cast<const Sigmod*>(sigmod())->abilityIndex(ability) == INT_MAX) + if (!sigmod()->abilityById(ability)) emit(error(bounds("ability"))); else CHECK(ability); diff --git a/sigmod/SpeciesItem.cpp b/sigmod/SpeciesItem.cpp index ba7733f2..db832470 100644 --- a/sigmod/SpeciesItem.cpp +++ b/sigmod/SpeciesItem.cpp @@ -74,7 +74,7 @@ QDomElement Sigmod::SpeciesItem::save() const void Sigmod::SpeciesItem::setItem(const int item) { - if (qobject_cast<const Sigmod*>(sigmod())->itemIndex(item) == INT_MAX) + if (!sigmod()->itemById(item)) emit(error(bounds("item"))); else CHECK(item); diff --git a/sigmod/SpeciesMove.cpp b/sigmod/SpeciesMove.cpp index 1764ba99..f2b81dcf 100644 --- a/sigmod/SpeciesMove.cpp +++ b/sigmod/SpeciesMove.cpp @@ -79,7 +79,7 @@ QDomElement Sigmod::SpeciesMove::save() const void Sigmod::SpeciesMove::setMove(const int move) { - if (qobject_cast<const Sigmod*>(sigmod())->moveIndex(move) == INT_MAX) + if (!sigmod()->moveById(move)) emit(error(bounds("move"))); else CHECK(move); @@ -87,7 +87,7 @@ void Sigmod::SpeciesMove::setMove(const int move) void Sigmod::SpeciesMove::setLevel(const int level) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxLevel() <= level) + if (sigmod()->rules()->maxLevel() <= level) emit(error(bounds("level"))); else CHECK(level); @@ -95,7 +95,7 @@ void Sigmod::SpeciesMove::setLevel(const int level) void Sigmod::SpeciesMove::setWild(const int wild) { - if (!wild || (qobject_cast<const Sigmod*>(sigmod())->rules()->maxLevel() <= wild)) + if (!wild || (sigmod()->rules()->maxLevel() <= wild)) emit(error(bounds("wild"))); else CHECK(wild); diff --git a/sigmod/Store.cpp b/sigmod/Store.cpp index bee0cd36..96558cc0 100644 --- a/sigmod/Store.cpp +++ b/sigmod/Store.cpp @@ -79,7 +79,7 @@ void Sigmod::Store::setName(const QString& name) void Sigmod::Store::setItem(const int item, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->itemIndex(item) == INT_MAX) + if (!sigmod()->itemById(item)) emit(error(bounds("item"))); else if (state && !m_item.contains(item)) { diff --git a/sigmod/Tile.cpp b/sigmod/Tile.cpp index 56215332..3646dbd3 100644 --- a/sigmod/Tile.cpp +++ b/sigmod/Tile.cpp @@ -21,7 +21,6 @@ // Sigmod includes #include "Macros.h" #include "Sigmod.h" -#include "Sprite.h" Sigmod::Tile::Tile(const Tile& tile) : Object(tile.parent(), tile.id()) @@ -32,24 +31,18 @@ Sigmod::Tile::Tile(const Tile& tile) : Sigmod::Tile::Tile(const Sigmod* parent, const int id) : Object(parent, id), m_name(""), - m_sprite(-1), - m_from(D_Right - D_Up + 1), m_script("", "") { - for (int i = 0; i < m_from.size(); ++i) - m_from[i] = false; } Sigmod::Tile::Tile(const Tile& tile, const Sigmod* parent, const int id) : - Object(parent, id), - m_from(D_Right - D_Up + 1) + Object(parent, id) { *this = tile; } Sigmod::Tile::Tile(const QDomElement& xml, const Sigmod* parent, const int id) : - Object(parent, id), - m_from(D_Right - D_Up + 1) + Object(parent, id) { LOAD_ID(); load(xml); @@ -60,7 +53,6 @@ void Sigmod::Tile::validate() TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); - TEST(setSprite, sprite); TEST_END(); } @@ -68,8 +60,6 @@ void Sigmod::Tile::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(name); - LOAD(sprite); - LOAD_ARRAY(from); LOAD(script); } @@ -77,8 +67,6 @@ QDomElement Sigmod::Tile::save() const { SAVE_CREATE(); SAVE(name); - SAVE(sprite); - SAVE_ARRAY(from); SAVE(script); return xml; } @@ -88,19 +76,6 @@ void Sigmod::Tile::setName(const QString& name) CHECK(name); } -void Sigmod::Tile::setSprite(const int sprite) -{ - if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(sprite) == INT_MAX) - emit(error(bounds("sprite"))); - else - CHECK(sprite); -} - -void Sigmod::Tile::setFrom(const Direction direction, const bool state) -{ - CHECK_ARRAY(from[direction], state); -} - void Sigmod::Tile::setScript(const Sigcore::Script& script) { CHECK(script); @@ -111,16 +86,6 @@ QString Sigmod::Tile::name() const return m_name; } -int Sigmod::Tile::sprite() const -{ - return m_sprite; -} - -bool Sigmod::Tile::from(const Direction direction) const -{ - return m_from[direction]; -} - Sigcore::Script Sigmod::Tile::script() const { return m_script; @@ -131,8 +96,6 @@ Sigmod::Tile& Sigmod::Tile::operator=(const Tile& rhs) if (this == &rhs) return *this; COPY(name); - COPY(sprite); - COPY(from); COPY(script); return *this; } diff --git a/sigmod/Tile.h b/sigmod/Tile.h index 47ccb161..c873f785 100644 --- a/sigmod/Tile.h +++ b/sigmod/Tile.h @@ -45,20 +45,14 @@ class SIGMOD_EXPORT Tile : public Object QDomElement save() const; void setName(const QString& name); - void setSprite(const int sprite); - void setFrom(const Direction direction, const bool state); void setScript(const Sigcore::Script& script); QString name() const; - int sprite() const; - bool from(const Direction direction) const; Sigcore::Script script() const; Tile& operator=(const Tile& rhs); private: QString m_name; - int m_sprite; - QVarLengthArray<bool, D_Right - D_Up + 1> m_from; Sigcore::Script m_script; }; } diff --git a/sigmod/Trainer.cpp b/sigmod/Trainer.cpp index d169d2d6..b67a932b 100644 --- a/sigmod/Trainer.cpp +++ b/sigmod/Trainer.cpp @@ -111,7 +111,7 @@ void Sigmod::Trainer::setMoneyFactor(const int moneyFactor) void Sigmod::Trainer::setSkin(const int skin) { - if (qobject_cast<const Sigmod*>(sigmod())->skinIndex(skin) == INT_MAX) + if (!sigmod()->skinById(skin)) emit(error(bounds("skin"))); else CHECK(skin); |