diff options
Diffstat (limited to 'sigmod/Item.cpp')
| -rw-r--r-- | sigmod/Item.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/sigmod/Item.cpp b/sigmod/Item.cpp index 1f1fdca6..d0eb9a91 100644 --- a/sigmod/Item.cpp +++ b/sigmod/Item.cpp @@ -19,6 +19,7 @@ #include "Item.h" // Sigmod includes +#include "ItemType.h" #include "Macros.h" #include "Rules.h" #include "Sigmod.h" @@ -38,6 +39,8 @@ Sigmod::Item::Item(const Sigmod* parent, const int id) : m_sellable(false), m_type(INT_MAX), m_price(0), + m_sellPrice(0), + m_weight(0), m_description(""), m_script("", "") { @@ -67,6 +70,8 @@ void Sigmod::Item::validate() emit(error("Name is empty")); TEST(setType, type); TEST(setPrice, price); + TEST(setSellPrice, sellPrice); + TEST(setWeight, weight); TEST_END(); } @@ -77,6 +82,8 @@ void Sigmod::Item::load(const QDomElement& xml) LOAD(sellable); LOAD(type); LOAD(price); + LOAD(sellPrice); + LOAD(weight); LOAD(description); LOAD(script); } @@ -88,6 +95,8 @@ QDomElement Sigmod::Item::save() const SAVE(sellable); SAVE(type); SAVE(price); + SAVE(sellPrice); + SAVE(weight); SAVE(description); SAVE(script); return xml; @@ -113,12 +122,34 @@ void Sigmod::Item::setType(const int type) void Sigmod::Item::setPrice(const int price) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxMoney() < price) + if ((price < 0) || (qobject_cast<const Sigmod*>(sigmod())->rules()->maxMoney() < price)) emit(error(bounds("price"))); else CHECK(price); } +void Sigmod::Item::setSellPrice(const int sellPrice) +{ + if ((sellPrice < 0) || (m_price < sellPrice)) + emit(error(bounds("sellPrice"))); + else + CHECK(sellPrice); +} + +void Sigmod::Item::setWeight(const int weight) +{ + const int typeIndex = qobject_cast<const Sigmod*>(sigmod())->itemTypeIndex(m_type); + if (typeIndex != INT_MAX) + { + if (qobject_cast<const Sigmod*>(sigmod())->itemType(typeIndex)->maxWeight() < weight) + emit(error(bounds("weight"))); + else if (weight < 0) + emit(error(bounds("weight"))); + else + CHECK(weight); + } +} + void Sigmod::Item::setDescription(const QString& description) { CHECK(description); @@ -149,6 +180,16 @@ int Sigmod::Item::price() const return m_price; } +int Sigmod::Item::sellPrice() const +{ + return m_sellPrice; +} + +int Sigmod::Item::weight() const +{ + return m_weight; +} + QString Sigmod::Item::description() const { return m_description; @@ -167,6 +208,7 @@ Sigmod::Item& Sigmod::Item::operator=(const Item& rhs) COPY(sellable); COPY(type); COPY(price); + COPY(weight); COPY(description); COPY(script); return *this; |
