summaryrefslogtreecommitdiffstats
path: root/pokemod/Item.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemod/Item.cpp')
-rw-r--r--pokemod/Item.cpp38
1 files changed, 23 insertions, 15 deletions
diff --git a/pokemod/Item.cpp b/pokemod/Item.cpp
index f6293cf7..f2a594d6 100644
--- a/pokemod/Item.cpp
+++ b/pokemod/Item.cpp
@@ -28,6 +28,7 @@
#include <QStringListIterator>
#include "Pokemod.h"
+#include "ItemEffect.h"
#include "Item.h"
Item::Item(const Pokemod* par, const int _id) :
@@ -52,6 +53,12 @@ Item::Item(const Pokemod* par, const QString& fname, const int _id) :
load(fname, _id);
}
+Item::~Item()
+{
+ for (QListIterator<ItemEffect*> i(effects); i.hasNext(); )
+ delete i.next();
+}
+
bool Item::validate() const
{
bool valid = true;
@@ -74,11 +81,11 @@ bool Item::validate() const
if (getEffectCount())
{
QMap<int, int> idChecker;
- for (QListIterator<ItemEffect> i(effects); i.hasNext(); i.next())
+ for (QListIterator<ItemEffect*> i(effects); 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())
{
@@ -138,8 +145,8 @@ void Item::save() const throw(Exception)
ini.addField("price", price);
ini.addField("description", description);
ini.save(QString("%1/item/%2/data.pini").arg(pokemod->getPath()).arg(name));
- for (QListIterator<ItemEffect> i(effects); i.hasNext(); )
- i.next().save(name);
+ for (QListIterator<ItemEffect*> i(effects); i.hasNext(); )
+ i.next()->save(name);
}
void Item::setName(const QString& n)
@@ -200,14 +207,14 @@ const ItemEffect* Item::getEffect(const int i) const throw(IndexException)
{
if (getEffectCount() <= i)
throw(IndexException(className));
- return &effects.at(i);
+ return effects.at(i);
}
ItemEffect* Item::getEffectByID(const int i) throw(IndexException)
{
if (getEffectCount() <= i)
throw(IndexException(className));
- return &effects[i];
+ return effects[i];
}
const ItemEffect* Item::getEffectByID(const int i) const throw(IndexException)
@@ -224,7 +231,7 @@ int Item::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;
@@ -237,26 +244,27 @@ int Item::getEffectCount() const
ItemEffect* Item::newEffect()
{
- effects.append(ItemEffect(pokemod, getNewId()));
- return &effects[getEffectCount() - 1];
+ effects.append(new ItemEffect(pokemod, getNewId()));
+ return effects[getEffectCount() - 1];
}
ItemEffect* Item::newEffect(const QString& fname)
{
- effects.append(ItemEffect(pokemod, fname, getNewId()));
- return &effects[getEffectCount() - 1];
+ effects.append(new ItemEffect(pokemod, fname, getNewId()));
+ return effects[getEffectCount() - 1];
}
ItemEffect* Item::newEffect(const ItemEffect& e)
{
- effects.append(ItemEffect(pokemod, e, getNewId()));
- return &effects[getEffectCount() - 1];
+ effects.append(new ItemEffect(pokemod, e, getNewId()));
+ return effects[getEffectCount() - 1];
}
void Item::deleteEffect(const int i) throw(IndexException)
{
if (getEffectCount() <= i)
throw(IndexException(className));
+ delete effects[i];
effects.removeAt(i);
}
@@ -271,6 +279,6 @@ Item& Item::operator=(const Item& rhs)
description = rhs.description;
effects.clear();
for (int i = 0; i < rhs.getEffectCount(); ++i)
- effects.append(ItemEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId()));
+ effects.append(new ItemEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId()));
return *this;
}