/* * Copyright 2007-2008 Ben Boeckel * * 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 . */ #include "Pokemod.h" #include "CoinListObject.h" const QStringList CoinListObject::TypeStr = QStringList() << "Item" << "Pokémon"; CoinListObject::CoinListObject(const CoinListObject& object) : Object("CoinListObject", object.pokemod(), object.id()) { *this = object; } CoinListObject::CoinListObject(const Pokemod* pokemod, const int id) : Object("CoinListObject", pokemod, id), m_type(Item), m_object(INT_MAX), m_amount(1), m_cost(0) { } CoinListObject::CoinListObject(const CoinListObject& object, const Pokemod* pokemod, const int id) : Object("CoinListObject", pokemod, id) { *this = object; } CoinListObject::CoinListObject(const QDomElement& xml, const Pokemod* pokemod, const int id) : Object("CoinListObject", pokemod, id) { load(xml, id); } bool CoinListObject::validate() const { bool valid = true; pokemod()->validationMsg(QString("------Object with id %1---").arg(id()), Pokemod::V_Msg); if (Item == m_type) { if (pokemod()->itemIndex(m_object) == INT_MAX) { pokemod()->validationMsg("Invalid item"); valid = false; } } else if (Species == m_type) { if (pokemod()->speciesIndex(m_object) == INT_MAX) { pokemod()->validationMsg("Invalid Species"); valid = false; } } else { pokemod()->validationMsg("Invalid type"); valid = false; } if (!m_amount || ((1 < m_amount) && (Species == m_type))) { pokemod()->validationMsg("Invalid amount"); valid = false; } return valid; } void CoinListObject::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(int, type); LOAD(int, object); LOAD(int, amount); LOAD(int, cost); } QDomElement CoinListObject::save() const { SAVE_CREATE(); SAVE(int, type); SAVE(int, object); SAVE(int, amount); SAVE(int, cost); return xml; } void CoinListObject::setType(const int type) throw(BoundsException) { if (End <= type) error("type"); m_type = type; m_object = INT_MAX; } void CoinListObject::setObject(const int object) throw(BoundsException) { if (((Item == m_type) && (pokemod()->itemIndex(object) == INT_MAX)) || ((Species == m_type) && (pokemod()->speciesIndex(object) == INT_MAX))) error("object"); m_object = object; } void CoinListObject::setAmount(const int amount) throw(BoundsException) { if (!amount || ((Species == m_type) && (1 < amount))) error("amount"); m_amount = amount; } void CoinListObject::setCost(const int cost) { m_cost = cost; } int CoinListObject::type() const { return m_type; } int CoinListObject::object() const { return m_object; } int CoinListObject::amount() const { return m_amount; } int CoinListObject::cost() const { return m_cost; } CoinListObject& CoinListObject::operator=(const CoinListObject& rhs) { if (this == &rhs) return *this; COPY(type); COPY(object); COPY(amount); COPY(cost); return *this; }