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/MapWildList.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/MapWildList.cpp')
| -rw-r--r-- | pokemod/MapWildList.cpp | 379 |
1 files changed, 190 insertions, 189 deletions
diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp index 737f506d..59ccec3f 100644 --- a/pokemod/MapWildList.cpp +++ b/pokemod/MapWildList.cpp @@ -1,351 +1,352 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapWildList.cpp -// Purpose: Define a list of species that can be found on the map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 19:18: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/>. + */ +// Qt includes #include <QDir> -#include <QListIterator> #include <QMap> -#include <QMapIterator> -#include <QMutableListIterator> -#include <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "Item.h" #include "ItemEffect.h" #include "MapWildListEncounter.h" + +// Header include #include "MapWildList.h" const QStringList MapWildList::ControlStr = QStringList() << "Grass" << "Surfing" << "Fishing" << "Dive" << "Headbutt" << "Rock Smash"; -MapWildList::MapWildList(const Pokemod* par, const int _id) : - Object("MapWildList", par, _id), - control(-1), - value(-1), - scope(-1) +MapWildList::MapWildList(const Pokemod* pokemod, const int id) : + Object("MapWildList", pokemod, id), + m_control(INT_MAX), + m_value(INT_MAX), + m_scope(INT_MAX) { } -MapWildList::MapWildList(const Pokemod* par, const MapWildList& w, const int _id) : - Object("MapWildList", par, _id) +MapWildList::MapWildList(const Pokemod* pokemod, const MapWildList& wildList, const int id) : + Object("MapWildList", pokemod, id) { - *this = w; + *this = wildList; } -MapWildList::MapWildList(const Pokemod* par, const QString& fname, const int _id) : - Object("MapWildList", par, _id) +MapWildList::MapWildList(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MapWildList", pokemod, id) { - load(fname, _id); + load(fileName, id); } MapWildList::~MapWildList() { - for (QListIterator<MapWildListEncounter*> i(encounters); i.hasNext(); ) - delete i.next(); + foreach (MapWildListEncounter* encounter, m_encounters) + delete encounter; } bool MapWildList::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Wild List with id %1---").arg(id), Pokemod::V_Msg); - if (End <= control) + pokemod()->validationMsg(QString("------Wild List with id %1---").arg(id()), Pokemod::V_Msg); + if (End <= m_control) { - pokemod->validationMsg("Invalid control"); + pokemod()->validationMsg("Invalid control"); valid = false; } - else if (control == Fishing) + else if (m_control == Fishing) { bool ok = false; - for (int i = 0; (i < pokemod->getItemCount()) && !ok; ++i) + for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) { - const Item* it = pokemod->getItem(i); - for (int j = 0; (j < it->getEffectCount()) && !ok; ++j) + const Item* item = pokemod()->item(i); + for (int j = 0; (j < item->effectCount()) && !ok; ++j) { - const ItemEffect* e = it->getEffect(j); - ok = ((e->getEffect() == ItemEffect::E_Fish) && (e->getVal2() == value)); + const ItemEffect* effect = item->effect(j); + ok = ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == m_value)); } } if (!ok) { - pokemod->validationMsg("Invalid fishing value"); + pokemod()->validationMsg("Invalid fishing value"); valid = false; } } - QMap<int, int> idChecker; - for (QListIterator<int> i(times); i.hasNext(); i.next()) + QMap<int, bool> idChecker; + foreach (int time, m_times) { - if (pokemod->getTimeIndex(i.peekNext()) == -1) + if (pokemod()->timeIndex(time) == INT_MAX) { - pokemod->validationMsg("Invalid time"); + pokemod()->validationMsg("Invalid time"); valid = false; } - ++idChecker[i.peekNext()]; + if (idChecker[time]) + pokemod()->validationMsg(QString("Duplicate of time %1").arg(time)); + idChecker[time] = true; } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 of time %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - if (scope != -1) + idChecker.clear(); + if (m_scope != INT_MAX) { bool ok = false; - for (int i = 0; (i < pokemod->getItemCount()) && !ok; ++i) + for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) { - const Item* it = pokemod->getItem(i); - for (int j = 0; (j < it->getEffectCount()) && !ok; ++j) + const Item* item = pokemod()->item(i); + for (int j = 0; (j < item->effectCount()) && !ok; ++j) { - const ItemEffect* e = it->getEffect(j); - ok = ((e->getEffect() == ItemEffect::E_Scope) && (e->getVal2() == scope)); + const ItemEffect* effect = item->effect(j); + ok = ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == m_scope)); } } if (!ok) { - pokemod->validationMsg("Invalid scope"); + pokemod()->validationMsg("Invalid scope"); valid = false; } } - // TODO: MapWildList Encounter validation + if (encounterCount()) + { + foreach (MapWildListEncounter* encounter, m_encounters) + { + if (!encounter->isValid()) + valid = false; + if (idChecker[encounter->id()]) + pokemod()->validationMsg(QString("Duplicate encounter with id %1").arg(encounter->id())); + idChecker[encounter->id()] = true; + } + } + else + { + pokemod()->validationMsg(QString("No effects")); + valid = false; + } return valid; } -int MapWildList::getNewId() const +void MapWildList::load(const QString& fileName, int id) throw(Exception) { - int i = 0; - for (; (i < getEncounterCount()) && (getEncounterIndex(i) != -1); ++i) - ; - return i; -} - -void MapWildList::load(const QString& fname, const int _id) throw(Exception) -{ - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - times.clear(); - ini.getValue("control", control); - ini.getValue("value", value); + m_times.clear(); + ini.getValue("control", m_control); + ini.getValue("value", m_value); ini.getValue("numTimes", i, 0); for (int k = 0; k < i; ++k) { ini.getValue(QString("time-%1").arg(k), j); - if (k != -1) - times.append(j); + if (m_times.contains(j)) + m_times.append(j); } - ini.getValue("scope", scope); - QStringList path = pokemod->getPath().split('/'); + ini.getValue("scope", m_scope); + QStringList path = pokemod()->path().split('/'); path.removeLast(); QDir fdir(path.join("/")); - encounters.clear(); + m_encounters.clear(); if (fdir.cd("encounter")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newEncounter(i.next()); + QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); + foreach (QString file, files) + newEncounter(file); } } void MapWildList::save(const QString& map) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("control", control); - ini.addField("value", value); - ini.addField("numTimes", times.size()); - for (int i = 0; i < times.size(); ++i) - ini.addField(QString("time-%1").arg(i), times[i]); - ini.addField("scope", scope); - ini.save(QString("%1/map/%2/wildlist/%3/data.pini").arg(pokemod->getPath()).arg(map).arg(id)); - for (QListIterator<MapWildListEncounter*> i(encounters); i.hasNext(); ) - i.next()->save(map, id); + ini.addField("id", id()); + ini.addField("control", m_control); + ini.addField("value", m_value); + ini.addField("numTimes", m_times.size()); + for (int i = 0; i < m_times.size(); ++i) + ini.addField(QString("time-%1").arg(i), m_times[i]); + ini.addField("scope", m_scope); + ini.save(QString("%1/map/%2/wildlist/%3/data.pini").arg(pokemod()->path()).arg(map).arg(id())); + foreach (MapWildListEncounter* encounter, m_encounters) + encounter->save(map, id()); } -void MapWildList::setControl(const int c) throw(BoundsException) +void MapWildList::setControl(const int control) throw(BoundsException) { - if (End <= c) - throw(BoundsException(className, "control")); - control = c; - value = -1; + if (End <= control) + throw(BoundsException(className(), "control")); + m_control = control; + m_value = INT_MAX; } -void MapWildList::setValue(const int v) throw(Exception) +void MapWildList::setValue(const int value) throw(Exception) { - if (control != Fishing) - throw(UnusedException(className, "value")); + if (m_control != Fishing) + throw(UnusedException(className(), "value")); bool ok = false; - for (int i = 0; (i < pokemod->getItemCount()) && !ok; ++i) + for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) { - const Item* it = pokemod->getItem(i); - for (int j = 0; (j < it->getEffectCount()) && !ok; ++j) + const Item* item = pokemod()->item(i); + for (int j = 0; (j < item->effectCount()) && !ok; ++j) { - const ItemEffect* e = it->getEffect(j); - ok = ((e->getEffect() == ItemEffect::E_Fish) && (e->getVal2() == value)); + const ItemEffect* effect = item->effect(j); + ok = ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == value)); } } if (!ok) - throw(BoundsException(className, "value")); - value = v; + throw(BoundsException(className(), "value")); + m_value = value; } -void MapWildList::setTime(const int ts, const bool t) throw(Exception) +void MapWildList::setTime(const int time, const bool state) throw(BoundsException) { - for (QMutableListIterator<int> i(times); i.hasNext(); ) + if (pokemod()->timeIndex(time) == INT_MAX) + throw(BoundsException(className(), "time")); + if (state) { - if (i.next() == ts) - { - if (t) - throw(Exception(className, "time already used")); - else - i.remove(); - } + if (!m_times.contains(time)) + m_times.append(time); } - if (!t) - throw(Exception(className, "time wasn\'t being used anyway")); - times.append(ts); + else + m_times.removeAll(time); } -void MapWildList::setScope(const int s) throw(BoundsException) +void MapWildList::setScope(const int scope) throw(BoundsException) { - if (s != -1) + if (scope != INT_MAX) { bool ok = false; - for (int i = 0; (i < pokemod->getItemCount()) && !ok; ++i) + for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) { - const Item* it = pokemod->getItem(i); - for (int j = 0; (j < it->getEffectCount()) && !ok; ++j) + const Item* item = pokemod()->item(i); + for (int j = 0; (j < item->effectCount()) && !ok; ++j) { - const ItemEffect* e = it->getEffect(j); - ok = ((e->getEffect() == ItemEffect::E_Scope) && (e->getVal2() == s)); + const ItemEffect* effect = item->effect(j); + ok = ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == scope)); } } if (!ok) - throw(BoundsException(className, "scope")); + throw(BoundsException(className(), "scope")); } - scope = s; + m_scope = scope; } -int MapWildList::getControl() const +int MapWildList::control() const { - return control; + return m_control; } -int MapWildList::getValue() const +int MapWildList::value() const { - return value; + return m_value; } -bool MapWildList::getTime(const int ts) const +bool MapWildList::time(const int time) const { - for (QListIterator<int> i(times); i.hasNext(); ) - { - if (i.next() == ts) - return true; - } - return false; + return m_times.contains(time); } -int MapWildList::getScope() const +int MapWildList::scope() const { - return scope; + return m_scope; } -const MapWildListEncounter* MapWildList::getEncounter(const int i) const throw(IndexException) +const MapWildListEncounter* MapWildList::encounter(const int index) const throw(IndexException) { - if (getEncounterCount() <= i) - throw(IndexException(className)); - return encounters.at(i); + if (encounterCount() <= index) + throw(IndexException(className())); + return m_encounters.at(index); } -MapWildListEncounter* MapWildList::getEncounter(const int i) throw(IndexException) +MapWildListEncounter* MapWildList::encounter(const int index) throw(IndexException) { - if (getEncounterCount() <= i) - throw(IndexException(className)); - return encounters[i]; + if (encounterCount() <= index) + throw(IndexException(className())); + return m_encounters[index]; } -const MapWildListEncounter* MapWildList::getEncounterByID(const int i) const throw(IndexException) +const MapWildListEncounter* MapWildList::encounterById(const int id) const throw(IndexException) { - return getEncounter(getEncounterIndex(i)); + return encounter(encounterIndex(id)); } -MapWildListEncounter* MapWildList::getEncounterByID(const int i) throw(IndexException) +MapWildListEncounter* MapWildList::encounterById(const int id) throw(IndexException) { - return getEncounter(getEncounterIndex(i)); + return encounter(encounterIndex(id)); } -int MapWildList::getEncounterIndex(const int _id) const +int MapWildList::encounterIndex(const int id) const { - for (int i = 0; i < getEncounterCount(); ++i) + for (int i = 0; i < encounterCount(); ++i) { - if (encounters[i]->getId() == _id) + if (m_encounters[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int MapWildList::getEncounterCount() const +int MapWildList::encounterCount() const { - return encounters.size(); + return m_encounters.size(); } MapWildListEncounter* MapWildList::newEncounter() { - encounters.append(new MapWildListEncounter(pokemod, getNewId())); - return encounters[getEncounterCount() - 1]; + m_encounters.append(new MapWildListEncounter(pokemod(), newEncounterId())); + return m_encounters[encounterCount() - 1]; } -MapWildListEncounter* MapWildList::newEncounter(const QString& fname) +MapWildListEncounter* MapWildList::newEncounter(const QString& fileName) { - encounters.append(new MapWildListEncounter(pokemod, fname, getNewId())); - return encounters[getEncounterCount() - 1]; + m_encounters.append(new MapWildListEncounter(pokemod(), fileName, newEncounterId())); + return m_encounters[encounterCount() - 1]; } -MapWildListEncounter* MapWildList::newEncounter(const MapWildListEncounter& p) +MapWildListEncounter* MapWildList::newEncounter(const MapWildListEncounter& encounter) { - encounters.append(new MapWildListEncounter(pokemod, p, getNewId())); - return encounters[getEncounterCount() - 1]; + m_encounters.append(new MapWildListEncounter(pokemod(), encounter, newEncounterId())); + return m_encounters[encounterCount() - 1]; } -void MapWildList::deleteEncounter(const int i) throw(IndexException) +void MapWildList::deleteEncounter(const int index) throw(IndexException) { - if (getEncounterCount() <= i) - throw(IndexException(className)); - delete encounters[i]; - encounters.removeAt(i); + if (encounterCount() <= index) + throw(IndexException(className())); + delete m_encounters[index]; + m_encounters.removeAt(index); +} + +void MapWildList::deleteEncounterById(const int id) throw(IndexException) +{ + deleteEncounter(encounterIndex(id)); +} + +int MapWildList::newEncounterId() const +{ + int i = 0; + while ((i < encounterCount()) && (encounterIndex(i) != INT_MAX)) + ++i; + return i; } MapWildList& MapWildList::operator=(const MapWildList& rhs) { if (this == &rhs) return *this; - control = rhs.control; - value = rhs.value; - times = rhs.times; - scope = rhs.scope; - encounters.clear(); - for (int i = 0; i < rhs.getEncounterCount(); ++i) - encounters.append(new MapWildListEncounter(pokemod, *rhs.getEncounter(i), rhs.getEncounter(i)->getId())); + m_control = rhs.m_control; + m_value = rhs.m_value; + m_times = rhs.m_times; + m_scope = rhs.m_scope; + m_encounters.clear(); + foreach (MapWildListEncounter* encounter, rhs.m_encounters) + m_encounters.append(new MapWildListEncounter(pokemod(), *encounter, encounter->id())); return *this; } |
