///////////////////////////////////////////////////////////////////////////// // 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 char* PokeMod::CoinListObject::TypeStr[PokeMod::CoinListObject::End] = {"Item", "Pokémon"}; PokeMod::CoinListObject::CoinListObject(const Pokemod& par, const unsigned _id) : Object(par, _id), type(Item), object(UINT_MAX), amount(1), cost(0) { } PokeMod::CoinListObject::CoinListObject(const Pokemod& par, const CoinListObject& o, const unsigned _id) : Object(par, _id) { *this = o; } PokeMod::CoinListObject::CoinListObject(const Pokemod& par, const QString& fname, const unsigned _id) : Object(par, _id) { load(fname, _id); } bool PokeMod::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) == UINT_MAX) { pokemod.validationMsg("Invalid item"); valid = false; } } else if (type == Pokemon) { if (pokemod.getSpeciesIndex(object) == UINT_MAX) { pokemod.validationMsg("Invalid Species"); valid = false; } } else { pokemod.validationMsg("Invalid type"); valid = false; } if (!amount || ((1 < amount) && (type == Pokemon))) { pokemod.validationMsg("Invalid amount"); valid = false; } return valid; } void PokeMod::CoinListObject::load(const QString& fname, const unsigned _id) throw(Exception) { Ini ini(fname); if (_id == UINT_MAX) 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 PokeMod::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 PokeMod::CoinListObject::setType(const unsigned t) throw(BoundsException) { if (End <= t) throw(BoundsException("CoinListObject", "type")); type = t; object = UINT_MAX; } void PokeMod::CoinListObject::setObject(const unsigned o) throw(BoundsException) { if (((type == Item) && (pokemod.getItemIndex(object) == UINT_MAX)) || ((type == Pokemon) && (pokemod.getSpeciesIndex(object) == UINT_MAX))) throw(BoundsException("CoinListObject", "object")); object = o; } void PokeMod::CoinListObject::setAmount(const unsigned a) throw(BoundsException) { if (!a) throw(BoundsException("CoinListObject", "amount")); amount = a; } void PokeMod::CoinListObject::setCost(const unsigned c) { cost = c; } unsigned PokeMod::CoinListObject::getType() const { return type; } unsigned PokeMod::CoinListObject::getObject() const { return object; } unsigned PokeMod::CoinListObject::getAmount() const { return amount; } unsigned PokeMod::CoinListObject::getCost() const { return cost; } PokeMod::CoinListObject& PokeMod::CoinListObject::operator=(const CoinListObject& rhs) { if (this == &rhs) return *this; type = rhs.type; object = rhs.object; amount = rhs.amount; cost = rhs.cost; return *this; }