diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-04-27 15:15:17 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-04-27 15:15:17 +0000 |
| commit | 807071d35159de0660f9df31c48d5bf895ca3622 (patch) | |
| tree | a1e9dbdc1e58b91cd2e4a5e472597b0204ccb41d /pokemod/Item.cpp | |
| parent | f444f5a45e9325644a360f656176d47d7f540f52 (diff) | |
[FIX] Pokemod objects now know about parents
[FIX] Project includes are now relative
[FIX] Headers included for better detection of invalid headers
[FIX] Validation code commented out so it can be done better
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@111 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Item.cpp')
| -rw-r--r-- | pokemod/Item.cpp | 95 |
1 files changed, 48 insertions, 47 deletions
diff --git a/pokemod/Item.cpp b/pokemod/Item.cpp index a33d3012..cf38506d 100644 --- a/pokemod/Item.cpp +++ b/pokemod/Item.cpp @@ -26,13 +26,13 @@ #include "Item.h" Item::Item(const Item& item) : - Object("Item", item.pokemod(), item.id()) + Object("Item", item.parent(), item.id()) { *this = item; } -Item::Item(const Pokemod* pokemod, const int id) : - Object("Item", pokemod, id), +Item::Item(const Object* parent, const int id) : + Object("Item", parent, id), m_name(""), m_sellable(false), m_type(INT_MAX), @@ -41,14 +41,14 @@ Item::Item(const Pokemod* pokemod, const int id) : { } -Item::Item(const Item& item, const Pokemod* pokemod, const int id) : - Object("Item", pokemod, id) +Item::Item(const Item& item, const Object* parent, const int id) : + Object("Item", parent, id) { *this = item; } -Item::Item(const QDomElement& xml, const Pokemod* pokemod, const int id) : - Object("Item", pokemod, id) +Item::Item(const QDomElement& xml, const Object* parent, const int id) : + Object("Item", parent, id) { load(xml, id); } @@ -60,41 +60,42 @@ Item::~Item() bool Item::validate() const { - bool valid = true; - pokemod()->validationMsg(QString("---Item \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); - if (m_name == "") - { - pokemod()->validationMsg("Name is not defined"); - valid = false; - } - if (pokemod()->itemTypeIndex(m_type) == INT_MAX) - { - pokemod()->validationMsg("Invalid item type"); - valid = false; - } - if (pokemod()->rules()->maxMoney() < m_price) - { - pokemod()->validationMsg("Invalid price"); - valid = false; - } - if (effectCount()) - { - QMap<int, bool> idChecker; - foreach (ItemEffect* effect, m_effects) - { - if (!effect->isValid()) - valid = false; - if (idChecker[effect->id()]) - pokemod()->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); - idChecker[effect->id()] = true; - } - } - else - { - pokemod()->validationMsg("There are no effects"); - valid = false; - } - return valid; + // TODO: validate +// bool valid = true; +// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Item \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); +// if (m_name == "") +// { +// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); +// valid = false; +// } +// if (static_cast<const Pokemod*>(pokemod())->itemTypeIndex(m_type) == INT_MAX) +// { +// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid item type"); +// valid = false; +// } +// if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < m_price) +// { +// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid price"); +// valid = false; +// } +// if (effectCount()) +// { +// QMap<int, bool> idChecker; +// foreach (ItemEffect* effect, m_effects) +// { +// if (!effect->isValid()) +// valid = false; +// if (idChecker[effect->id()]) +// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); +// idChecker[effect->id()] = true; +// } +// } +// else +// { +// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no effects"); +// valid = false; +// } +// return valid; } void Item::load(const QDomElement& xml, int id) @@ -132,14 +133,14 @@ void Item::setSellable(const bool sellable) void Item::setType(const int type) throw(BoundsException) { - if (pokemod()->itemTypeIndex(type) == INT_MAX) + if (static_cast<const Pokemod*>(pokemod())->itemTypeIndex(type) == INT_MAX) error<BoundsException>("type"); m_type = type; } void Item::setPrice(const int price) throw(BoundsException) { - if (pokemod()->rules()->maxMoney() < price) + if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < price) error<BoundsException>("price"); m_price = price; } @@ -215,19 +216,19 @@ int Item::effectCount() const ItemEffect* Item::newEffect() { - m_effects.append(new ItemEffect(pokemod(), effectId())); + m_effects.append(new ItemEffect(this, effectId())); return m_effects[effectCount() - 1]; } ItemEffect* Item::newEffect(const QDomElement& xml) { - m_effects.append(new ItemEffect(xml, pokemod(), effectId())); + m_effects.append(new ItemEffect(xml, this, effectId())); return m_effects[effectCount() - 1]; } ItemEffect* Item::newEffect(const ItemEffect& effect) { - m_effects.append(new ItemEffect(effect, pokemod(), effectId())); + m_effects.append(new ItemEffect(effect, this, effectId())); return m_effects[effectCount() - 1]; } |
