diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-03-31 01:17:59 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-03-31 01:17:59 +0000 |
| commit | 9a65bc6bb7c8da1dfa5b101579e52845c75848ef (patch) | |
| tree | 258900f882a6998ac6fa525bd247e302028a8911 /pokemod/CoinListObject.cpp | |
| parent | 8e1ec2aec50999bae30625303f2c96e5b3b7f318 (diff) | |
| download | sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.tar.gz sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.tar.xz sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.zip | |
[FIX] Member variables now use m_ prefix
[FIX] Lots of minor fixes
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@95 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/CoinListObject.cpp')
| -rw-r--r-- | pokemod/CoinListObject.cpp | 164 |
1 files changed, 79 insertions, 85 deletions
diff --git a/pokemod/CoinListObject.cpp b/pokemod/CoinListObject.cpp index 143c3db1..4e91136c 100644 --- a/pokemod/CoinListObject.cpp +++ b/pokemod/CoinListObject.cpp @@ -1,162 +1,156 @@ -///////////////////////////////////////////////////////////////////////////// -// 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 <http://www.gnu.org/licenses/>. -///////////////////////////////////////////////////////////////////////////// +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ #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* pokemod, const int id) : + Object("CoinListObject", pokemod, id), + m_type(Item), + m_object(INT_MAX), + m_amount(1), + m_cost(0) { } -CoinListObject::CoinListObject(const Pokemod* par, const CoinListObject& o, const int _id) : - Object("CoinListObject", par, _id) +CoinListObject::CoinListObject(const Pokemod* pokemod, const CoinListObject& object, const int id) : + Object("CoinListObject", pokemod, id) { - *this = o; + *this = object; } -CoinListObject::CoinListObject(const Pokemod* par, const QString& fname, const int _id) : - Object("CoinListObject", par, _id) +CoinListObject::CoinListObject(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("CoinListObject", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool CoinListObject::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Object with id %1---").arg(id), Pokemod::V_Msg); - if (type == Item) + pokemod()->validationMsg(QString("------Object with id %1---").arg(id()), Pokemod::V_Msg); + if (Item == m_type) { - if (pokemod->getItemIndex(object) == -1) + if (pokemod()->itemIndex(m_object) == INT_MAX) { - pokemod->validationMsg("Invalid item"); + pokemod()->validationMsg("Invalid item"); valid = false; } } - else if (type == Species) + else if (Species == m_type) { - if (pokemod->getSpeciesIndex(object) == -1) + if (pokemod()->speciesIndex(m_object) == INT_MAX) { - pokemod->validationMsg("Invalid Species"); + pokemod()->validationMsg("Invalid Species"); valid = false; } } else { - pokemod->validationMsg("Invalid type"); + pokemod()->validationMsg("Invalid type"); valid = false; } - if (!amount || ((1 < amount) && (type == Species))) + if (!m_amount || ((1 < m_amount) && (Species == m_type))) { - pokemod->validationMsg("Invalid amount"); + pokemod()->validationMsg("Invalid amount"); valid = false; } return valid; } -void CoinListObject::load(const QString& fname, const int _id) throw(Exception) +void CoinListObject::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_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); + setId(id); + ini.getValue("type", m_type, Item); + ini.getValue("object", m_object); + ini.getValue("amount", m_amount, 1); + ini.getValue("cost", m_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)); + ini.addField("id", id()); + ini.addField("type", m_type); + ini.addField("object", m_object); + ini.addField("amount", m_amount); + ini.addField("cost", m_cost); + ini.save(QString("%1/coinlist/%2/item/%3.pini").arg(pokemod()->path()).arg(coinList).arg(id())); } -void CoinListObject::setType(const int t) throw(BoundsException) +void CoinListObject::setType(const int type) throw(BoundsException) { - if (End <= t) - throw(BoundsException(className, "type")); - type = t; - object = -1; + if (End <= type) + throw(BoundsException(className(), "type")); + m_type = type; + m_object = INT_MAX; } -void CoinListObject::setObject(const int o) throw(BoundsException) +void CoinListObject::setObject(const int object) throw(BoundsException) { - if (((type == Item) && (pokemod->getItemIndex(o) == -1)) || ((type == Species) && (pokemod->getSpeciesIndex(o) == -1))) - throw(BoundsException(className, "object")); - object = o; + if (((Item == m_type) && (pokemod()->itemIndex(object) == INT_MAX)) || ((Species == m_type) && (pokemod()->speciesIndex(object) == INT_MAX))) + throw(BoundsException(className(), "object")); + m_object = object; } -void CoinListObject::setAmount(const int a) throw(BoundsException) +void CoinListObject::setAmount(const int amount) throw(BoundsException) { - if (!a) - throw(BoundsException(className, "amount")); - amount = a; + if (!amount || ((Species == m_type) && (1 < amount))) + throw(BoundsException(className(), "amount")); + m_amount = amount; } -void CoinListObject::setCost(const int c) +void CoinListObject::setCost(const int cost) { - cost = c; + m_cost = cost; } -int CoinListObject::getType() const +int CoinListObject::type() const { - return type; + return m_type; } -int CoinListObject::getObject() const +int CoinListObject::object() const { - return object; + return m_object; } -int CoinListObject::getAmount() const +int CoinListObject::amount() const { - return amount; + return m_amount; } -int CoinListObject::getCost() const +int CoinListObject::cost() const { - return cost; + return m_cost; } CoinListObject& CoinListObject::operator=(const CoinListObject& rhs) { if (this == &rhs) return *this; - type = rhs.type; - object = rhs.object; - amount = rhs.amount; - cost = rhs.cost; + m_type = rhs.m_type; + m_object = rhs.m_object; + m_amount = rhs.m_amount; + m_cost = rhs.m_cost; return *this; } |
