///////////////////////////////////////////////////////////////////////////// // Name: pokemod/CoinListObject.cpp // Purpose: Define an object that can be bought with gambling winnings // Author: Ben Boeckel // Modified by: Ben Boeckel // Created: Wed Feb 28 21:21:23 2007 // Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions // Licence: // 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 Pokemod* par, const int _id) : Object("CoinListObject", par, _id), type(Item), object(-1), amount(1), cost(0) { } CoinListObject::CoinListObject(const Pokemod* par, const CoinListObject& o, const int _id) : Object("CoinListObject", par, _id) { *this = o; } CoinListObject::CoinListObject(const Pokemod* par, const QString& fname, const int _id) : Object("CoinListObject", par, _id) { load(fname, _id); } bool CoinListObject::validate() const { bool valid = true; pokemod->validationMsg(QString("------Object with id %1---").arg(id), Pokemod::V_Msg); if (type == Item) { if (pokemod->getItemIndex(object) == -1) { pokemod->validationMsg("Invalid item"); valid = false; } } else if (type == Species) { if (pokemod->getSpeciesIndex(object) == -1) { pokemod->validationMsg("Invalid Species"); valid = false; } } else { pokemod->validationMsg("Invalid type"); valid = false; } if (!amount || ((1 < amount) && (type == Species))) { pokemod->validationMsg("Invalid amount"); valid = false; } return valid; } void CoinListObject::load(const QString& fname, const int _id) throw(Exception) { Ini ini(fname); if (_id == -1) ini.getValue("id", id); else id = _id; ini.getValue("type", type, Item); ini.getValue("object", object); ini.getValue("amount", amount, 1); ini.getValue("cost", cost, 0); } void CoinListObject::save(const QString& coinList) const throw(Exception) { Ini ini; ini.addField("id", id); ini.addField("type", type); ini.addField("object", object); ini.addField("amount", amount); ini.addField("cost", cost); ini.save(QString("%1/coinlist/%2/item/%3.pini").arg(pokemod->getPath()).arg(coinList).arg(id)); } void CoinListObject::setType(const int t) throw(BoundsException) { if (End <= t) throw(BoundsException(className, "type")); type = t; object = -1; } void CoinListObject::setObject(const int o) throw(BoundsException) { if (((type == Item) && (pokemod->getItemIndex(o) == -1)) || ((type == Species) && (pokemod->getSpeciesIndex(o) == -1))) throw(BoundsException(className, "object")); object = o; } void CoinListObject::setAmount(const int a) throw(BoundsException) { if (!a) throw(BoundsException(className, "amount")); amount = a; } void CoinListObject::setCost(const int c) { cost = c; } int CoinListObject::getType() const { return type; } int CoinListObject::getObject() const { return object; } int CoinListObject::getAmount() const { return amount; } int CoinListObject::getCost() const { return cost; } CoinListObject& CoinListObject::operator=(const CoinListObject& rhs) { if (this == &rhs) return *this; type = rhs.type; object = rhs.object; amount = rhs.amount; cost = rhs.cost; return *this; }