///////////////////////////////////////////////////////////////////////////// // 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 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 "CoinListObject.h" const char* PokeGen::PokeMod::CoinListObject::TypeStr[PokeGen::PokeMod::CoinListObject::End] = {"Item", "Pokémon"}; PokeGen::PokeMod::CoinListObject::CoinListObject(const Pokemod* par, const unsigned _id) : Object(_id, par), type(Item), object(UINT_MAX), amount(1), cost(0) { } PokeGen::PokeMod::CoinListObject::CoinListObject(const Pokemod* par, Ini& ini, const unsigned _id) : Object(_id, par) { ImportIni(ini, _id); } bool PokeGen::PokeMod::CoinListObject::Validate() { pokemod->ValidationMsg(QString("------Object with id %1---").arg(id), Pokemod::V_Msg); if (type == Item) { if (pokemod->GetItemByID(object) == UINT_MAX) { pokemod->ValidationMsg("Invalid item"); isValid = false; } } else if (type == Pokemon) { if (pokemod->GetSpeciesByID(object) == UINT_MAX) { pokemod->ValidationMsg("Invalid Species"); isValid = false; } } else { pokemod->ValidationMsg("Invalid type"); isValid = false; } if (!amount || ((1 < amount) && (type == Pokemon))) { pokemod->ValidationMsg("Invalid amount"); isValid = false; } return isValid; } void PokeGen::PokeMod::CoinListObject::ImportIni(Ini& ini, const unsigned _id) { 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 PokeGen::PokeMod::CoinListObject::ExportIni(QFile& fout, const QString& coinList) const { Ini exCoinListObject("CoinListObject " + coinList); exCoinListObject.AddField("id", id); exCoinListObject.AddField("type", type); exCoinListObject.AddField("object", object); exCoinListObject.AddField("amount", amount); exCoinListObject.AddField("cost", cost); exCoinListObject.Export(fout); } bool PokeGen::PokeMod::CoinListObject::SetType(const unsigned t) { if (t < End) { type = t; object = UINT_MAX; } return (type == t); } bool PokeGen::PokeMod::CoinListObject::SetObject(const unsigned o) { if (((type == Item) && (pokemod->GetItemByID(o) != UINT_MAX)) || ((type == Pokemon) && (pokemod->GetSpeciesByID(o) != UINT_MAX))) object = o; return (object == o); } bool PokeGen::PokeMod::CoinListObject::SetAmount(const unsigned a) { if (a) amount = a; return (amount == a); } void PokeGen::PokeMod::CoinListObject::SetCost(const unsigned c) { cost = c; } unsigned PokeGen::PokeMod::CoinListObject::GetType() const { return type; } unsigned PokeGen::PokeMod::CoinListObject::GetObject() const { return object; } unsigned PokeGen::PokeMod::CoinListObject::GetAmount() const { return amount; } unsigned PokeGen::PokeMod::CoinListObject::GetCost() const { return cost; }