summaryrefslogtreecommitdiffstats
path: root/pokemod/Map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemod/Map.cpp')
-rw-r--r--pokemod/Map.cpp158
1 files changed, 89 insertions, 69 deletions
diff --git a/pokemod/Map.cpp b/pokemod/Map.cpp
index 7a575271..e3adeff5 100644
--- a/pokemod/Map.cpp
+++ b/pokemod/Map.cpp
@@ -26,6 +26,10 @@
#include <QStringListIterator>
#include "Pokemod.h"
+#include "MapEffect.h"
+#include "MapTrainer.h"
+#include "MapWarp.h"
+#include "MapWildList.h"
#include "Map.h"
const QStringList Map::TypeStr = QStringList() << "Outdoor" << "Dungeon" << "Building";
@@ -50,6 +54,18 @@ Map::Map(const Pokemod* par, const QString& fname, const int _id) :
load(fname, _id);
}
+Map::~Map()
+{
+ for (QListIterator<MapEffect*> i(effects); i.hasNext(); )
+ delete i.next();
+ for (QListIterator<MapTrainer*> i(trainers); i.hasNext(); )
+ delete i.next();
+ for (QListIterator<MapWarp*> i(warps); i.hasNext(); )
+ delete i.next();
+ for (QListIterator<MapWildList*> i(wildLists); i.hasNext(); )
+ delete i.next();
+}
+
bool Map::validate() const
{
bool valid = true;
@@ -73,22 +89,22 @@ bool Map::validate() const
QMap<QString, int> nameChecker;
if (getEffectCount())
{
- for (QListIterator<MapEffect> i(effects); i.hasNext(); i.next())
+ for (QListIterator<MapEffect*> i(effects); i.hasNext(); i.next())
{
- if (!i.peekNext().isValid())
+ if (!i.peekNext()->isValid())
valid = false;
- if (getWidth() <= i.peekNext().getCoordinate().getX())
+ if (getWidth() <= i.peekNext()->getCoordinate().getX())
{
pokemod->validationMsg("Invalid x coordinate");
valid = false;
}
- if (getHeight() <= i.peekNext().getCoordinate().getY())
+ if (getHeight() <= i.peekNext()->getCoordinate().getY())
{
pokemod->validationMsg("Invalid y coordinate");
valid = false;
}
- ++idChecker[i.peekNext().getId()];
- ++nameChecker[i.peekNext().getName()];
+ ++idChecker[i.peekNext()->getId()];
+ ++nameChecker[i.peekNext()->getName()];
}
for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next())
{
@@ -113,22 +129,22 @@ bool Map::validate() const
pokemod->validationMsg("There are no effects", Pokemod::V_Warn);
if (getTrainerCount())
{
- for (QListIterator<MapTrainer> i(trainers); i.hasNext(); i.next())
+ for (QListIterator<MapTrainer*> i(trainers); i.hasNext(); i.next())
{
- if (!i.peekNext().isValid())
+ if (!i.peekNext()->isValid())
valid = false;
- if (getWidth() <= i.peekNext().getCoordinate().getX())
+ if (getWidth() <= i.peekNext()->getCoordinate().getX())
{
pokemod->validationMsg("Invalid x coordinate");
valid = false;
}
- if (getHeight() <= i.peekNext().getCoordinate().getY())
+ if (getHeight() <= i.peekNext()->getCoordinate().getY())
{
pokemod->validationMsg("Invalid y coordinate");
valid = false;
}
- ++idChecker[i.peekNext().getId()];
- ++nameChecker[i.peekNext().getName()];
+ ++idChecker[i.peekNext()->getId()];
+ ++nameChecker[i.peekNext()->getName()];
}
for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next())
{
@@ -153,22 +169,22 @@ bool Map::validate() const
pokemod->validationMsg("There are no trainers", Pokemod::V_Warn);
if (getWarpCount())
{
- for (QListIterator<MapWarp> i(warps); i.hasNext(); i.next())
+ for (QListIterator<MapWarp*> i(warps); i.hasNext(); i.next())
{
- if (!i.peekNext().isValid())
+ if (!i.peekNext()->isValid())
valid = false;
- if (getWidth() <= i.peekNext().getCoordinate().getX())
+ if (getWidth() <= i.peekNext()->getCoordinate().getX())
{
pokemod->validationMsg("Invalid x coordinate");
valid = false;
}
- if (getHeight() <= i.peekNext().getCoordinate().getY())
+ if (getHeight() <= i.peekNext()->getCoordinate().getY())
{
pokemod->validationMsg("Invalid y coordinate");
valid = false;
}
- ++idChecker[i.peekNext().getId()];
- ++nameChecker[i.peekNext().getName()];
+ ++idChecker[i.peekNext()->getId()];
+ ++nameChecker[i.peekNext()->getName()];
}
for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next())
{
@@ -196,11 +212,11 @@ bool Map::validate() const
}
if (getWildListCount())
{
- for (QListIterator<MapWildList> i(wildLists); i.hasNext(); i.next())
+ for (QListIterator<MapWildList*> i(wildLists); i.hasNext(); i.next())
{
- if (!i.peekNext().isValid())
+ if (!i.peekNext()->isValid())
valid = false;
- ++idChecker[i.peekNext().getId()];
+ ++idChecker[i.peekNext()->getId()];
}
for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next())
{
@@ -327,14 +343,14 @@ void Map::save() const throw(Exception)
ini.addField(QString("tiles-%1-%2").arg(i).arg(j), tiles(i, j));
}
ini.save(QString("%1/map/%2/data.pini").arg(pokemod->getPath()).arg(name));
- for (QListIterator<MapEffect> i(effects); i.hasNext(); )
- i.next().save(name);
- for (QListIterator<MapTrainer> i(trainers); i.hasNext(); )
- i.next().save(name);
- for (QListIterator<MapWarp> i(warps); i.hasNext(); )
- i.next().save(name);
- for (QListIterator<MapWildList> i(wildLists); i.hasNext(); )
- i.next().save(name);
+ for (QListIterator<MapEffect*> i(effects); i.hasNext(); )
+ i.next()->save(name);
+ for (QListIterator<MapTrainer*> i(trainers); i.hasNext(); )
+ i.next()->save(name);
+ for (QListIterator<MapWarp*> i(warps); i.hasNext(); )
+ i.next()->save(name);
+ for (QListIterator<MapWildList*> i(wildLists); i.hasNext(); )
+ i.next()->save(name);
}
void Map::setName(const QString& n)
@@ -437,14 +453,14 @@ const MapEffect* Map::getEffect(const int i) const throw(IndexException)
{
if (getEffectCount() <= i)
throw(IndexException(className));
- return &effects.at(i);
+ return effects.at(i);
}
MapEffect* Map::getEffect(const int i) throw(IndexException)
{
if (getEffectCount() <= i)
throw(IndexException(className));
- return &effects[i];
+ return effects[i];
}
const MapEffect* Map::getEffectByID(const int i) const throw(IndexException)
@@ -461,7 +477,7 @@ int Map::getEffectIndex(const int _id) const
{
for (int i = 0; i < getEffectCount(); ++i)
{
- if (effects[i].getId() == _id)
+ if (effects[i]->getId() == _id)
return i;
}
return -1;
@@ -474,26 +490,27 @@ int Map::getEffectCount() const
MapEffect* Map::newEffect()
{
- effects.append(MapEffect(pokemod, getNewEffectId()));
- return &effects[getEffectCount() - 1];
+ effects.append(new MapEffect(pokemod, getNewEffectId()));
+ return effects[getEffectCount() - 1];
}
MapEffect* Map::newEffect(const QString& fname)
{
- effects.append(MapEffect(pokemod, fname, getNewEffectId()));
- return &effects[getEffectCount() - 1];
+ effects.append(new MapEffect(pokemod, fname, getNewEffectId()));
+ return effects[getEffectCount() - 1];
}
MapEffect* Map::newEffect(const MapEffect& e)
{
- effects.append(MapEffect(pokemod, e, getNewEffectId()));
- return &effects[getEffectCount() - 1];
+ effects.append(new MapEffect(pokemod, e, getNewEffectId()));
+ return effects[getEffectCount() - 1];
}
void Map::deleteEffect(const int i) throw(IndexException)
{
if (getEffectCount() <= i)
throw(IndexException(className));
+ delete effects[i];
effects.removeAt(i);
}
@@ -501,14 +518,14 @@ const MapTrainer* Map::getTrainer(const int i) const throw(IndexException)
{
if (getTrainerCount() <= i)
throw(IndexException(className));
- return &trainers.at(i);
+ return trainers.at(i);
}
MapTrainer* Map::getTrainer(const int i) throw(IndexException)
{
if (getTrainerCount() <= i)
throw(IndexException(className));
- return &trainers[i];
+ return trainers[i];
}
const MapTrainer* Map::getTrainerByID(const int i) const throw(IndexException)
@@ -525,7 +542,7 @@ int Map::getTrainerIndex(const int _id) const
{
for (int i = 0; i < getTrainerCount(); ++i)
{
- if (trainers[i].getId() == _id)
+ if (trainers[i]->getId() == _id)
return i;
}
return -1;
@@ -538,26 +555,27 @@ int Map::getTrainerCount() const
MapTrainer* Map::newTrainer()
{
- trainers.append(MapTrainer(pokemod, getNewTrainerId()));
- return &trainers[getTrainerCount() - 1];
+ trainers.append(new MapTrainer(pokemod, getNewTrainerId()));
+ return trainers[getTrainerCount() - 1];
}
MapTrainer* Map::newTrainer(const QString& fname)
{
- trainers.append(MapTrainer(pokemod, fname, getNewTrainerId()));
- return &trainers[getTrainerCount() - 1];
+ trainers.append(new MapTrainer(pokemod, fname, getNewTrainerId()));
+ return trainers[getTrainerCount() - 1];
}
MapTrainer* Map::newTrainer(const MapTrainer& t)
{
- trainers.append(MapTrainer(pokemod, t, getNewTrainerId()));
- return &trainers[getTrainerCount() - 1];
+ trainers.append(new MapTrainer(pokemod, t, getNewTrainerId()));
+ return trainers[getTrainerCount() - 1];
}
void Map::deleteTrainer(const int i) throw(IndexException)
{
if (getTrainerCount() <= i)
throw(IndexException(className));
+ delete trainers[i];
trainers.removeAt(i);
}
@@ -565,14 +583,14 @@ const MapWarp* Map::getWarp(const int i) const throw(IndexException)
{
if (getWarpCount() <= i)
throw(IndexException(className));
- return &warps.at(i);
+ return warps.at(i);
}
MapWarp* Map::getWarp(const int i) throw(IndexException)
{
if (getWarpCount() <= i)
throw(IndexException(className));
- return &warps[i];
+ return warps[i];
}
const MapWarp* Map::getWarpByID(const int i) const throw(IndexException)
@@ -589,7 +607,7 @@ int Map::getWarpIndex(const int _id) const
{
for (int i = 0; i < getWarpCount(); ++i)
{
- if (warps[i].getId() == _id)
+ if (warps[i]->getId() == _id)
return i;
}
return -1;
@@ -602,26 +620,27 @@ int Map::getWarpCount() const
MapWarp* Map::newWarp()
{
- warps.append(MapWarp(pokemod, getNewWarpId()));
- return &warps[getWarpCount() - 1];
+ warps.append(new MapWarp(pokemod, getNewWarpId()));
+ return warps[getWarpCount() - 1];
}
MapWarp* Map::newWarp(const QString& fname)
{
- warps.append(MapWarp(pokemod, fname, getNewWarpId()));
- return &warps[getWarpCount() - 1];
+ warps.append(new MapWarp(pokemod, fname, getNewWarpId()));
+ return warps[getWarpCount() - 1];
}
MapWarp* Map::newWarp(const MapWarp& w)
{
- warps.append(MapWarp(pokemod, w, getNewWarpId()));
- return &warps[getWarpCount() - 1];
+ warps.append(new MapWarp(pokemod, w, getNewWarpId()));
+ return warps[getWarpCount() - 1];
}
void Map::deleteWarp(const int i) throw(IndexException)
{
if (getWarpCount() <= i)
throw(IndexException(className));
+ delete warps[i];
warps.removeAt(i);
}
@@ -629,14 +648,14 @@ const MapWildList* Map::getWildList(const int i) const throw(IndexException)
{
if (getWildListCount() <= i)
throw(IndexException(className));
- return &wildLists.at(i);
+ return wildLists.at(i);
}
MapWildList* Map::getWildList(const int i) throw(IndexException)
{
if (getWildListCount() <= i)
throw(IndexException(className));
- return &wildLists[i];
+ return wildLists[i];
}
const MapWildList* Map::getWildListByID(const int i) const throw(IndexException)
@@ -653,7 +672,7 @@ int Map::getWildListIndex(const int _id) const
{
for (int i = 0; i < getWildListCount(); ++i)
{
- if (wildLists[i].getId() == _id)
+ if (wildLists[i]->getId() == _id)
return i;
}
return -1;
@@ -666,26 +685,27 @@ int Map::getWildListCount() const
MapWildList* Map::newWildList()
{
- wildLists.append(MapWildList(pokemod, getNewWildListId()));
- return &wildLists[getWildListCount() - 1];
+ wildLists.append(new MapWildList(pokemod, getNewWildListId()));
+ return wildLists[getWildListCount() - 1];
}
MapWildList* Map::newWildList(const QString& fname)
{
- wildLists.append(MapWildList(pokemod, fname, getNewWildListId()));
- return &wildLists[getWildListCount() - 1];
+ wildLists.append(new MapWildList(pokemod, fname, getNewWildListId()));
+ return wildLists[getWildListCount() - 1];
}
MapWildList* Map::newWildList(const MapWildList& w)
{
- wildLists.append(MapWildList(pokemod, w, getNewWildListId()));
- return &wildLists[getWildListCount() - 1];
+ wildLists.append(new MapWildList(pokemod, w, getNewWildListId()));
+ return wildLists[getWildListCount() - 1];
}
void Map::deleteWildList(const int i) throw(IndexException)
{
if (getWildListCount() <= i)
throw(IndexException(className));
+ delete wildLists[i];
wildLists.removeAt(i);
}
@@ -699,15 +719,15 @@ Map& Map::operator=(const Map& rhs)
tiles = rhs.tiles;
effects.clear();
for (int i = 0; i < rhs.getEffectCount(); ++i)
- effects.append(MapEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId()));
+ effects.append(new MapEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId()));
trainers.clear();
for (int i = 0; i < rhs.getTrainerCount(); ++i)
- trainers.append(MapTrainer(pokemod, *rhs.getTrainer(i), rhs.getTrainer(i)->getId()));
+ trainers.append(new MapTrainer(pokemod, *rhs.getTrainer(i), rhs.getTrainer(i)->getId()));
warps.clear();
for (int i = 0; i < rhs.getWarpCount(); ++i)
- warps.append(MapWarp(pokemod, *rhs.getWarp(i), rhs.getWarp(i)->getId()));
+ warps.append(new MapWarp(pokemod, *rhs.getWarp(i), rhs.getWarp(i)->getId()));
wildLists.clear();
for (int i = 0; i < rhs.getWildListCount(); ++i)
- wildLists.append(MapWildList(pokemod, *rhs.getWildList(i), rhs.getWildList(i)->getId()));
+ wildLists.append(new MapWildList(pokemod, *rhs.getWildList(i), rhs.getWildList(i)->getId()));
return *this;
}