summaryrefslogtreecommitdiffstats
path: root/sigmod/MapWildList.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sigmod/MapWildList.cpp')
-rw-r--r--sigmod/MapWildList.cpp190
1 files changed, 190 insertions, 0 deletions
diff --git a/sigmod/MapWildList.cpp b/sigmod/MapWildList.cpp
new file mode 100644
index 00000000..30a7f56d
--- /dev/null
+++ b/sigmod/MapWildList.cpp
@@ -0,0 +1,190 @@
+/*
+ * 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/>.
+ */
+
+// Header include
+#include "MapWildList.h"
+
+// Pokemod includes
+#include "Macros.h"
+#include "Map.h"
+#include "MapWildListEncounter.h"
+
+// Qt includes
+#include <QtCore/QSet>
+
+Pokemod::MapWildList::MapWildList(const MapWildList& wildList) :
+ Object(wildList.parent(), wildList.id())
+{
+ *this = wildList;
+}
+
+Pokemod::MapWildList::MapWildList(const Map* parent, const int id) :
+ Object(parent, id),
+ m_name("")
+{
+}
+
+Pokemod::MapWildList::MapWildList(const MapWildList& wildList, const Map* parent, const int id) :
+ Object(parent, id)
+{
+ *this = wildList;
+}
+
+Pokemod::MapWildList::MapWildList(const QDomElement& xml, const Map* parent, const int id) :
+ Object(parent, id)
+{
+ LOAD_ID();
+ load(xml);
+}
+
+Pokemod::MapWildList::~MapWildList()
+{
+ clear();
+}
+
+void Pokemod::MapWildList::validate()
+{
+ TEST_BEGIN();
+ if (m_name.isEmpty())
+ emit(error("Name is empty"));
+ if (!encounterCount())
+ emit(error("There are no encounters"));
+ QSet<int> idChecker;
+ TEST_SUB_BEGIN(MapWildListEncounter, encounters);
+ TEST_SUB("encounter", id);
+ TEST_SUB_END();
+ TEST_END();
+}
+
+void Pokemod::MapWildList::load(const QDomElement& xml)
+{
+ LOAD_BEGIN();
+ LOAD(name);
+ LOAD_SUB(newEncounter, MapWildListEncounter);
+}
+
+QDomElement Pokemod::MapWildList::save() const
+{
+ SAVE_CREATE();
+ SAVE(name);
+ SAVE_SUB(MapWildListEncounter, encounters);
+ return xml;
+}
+
+void Pokemod::MapWildList::setName(const QString& name)
+{
+ CHECK(name);
+}
+
+QString Pokemod::MapWildList::name() const
+{
+ return m_name;
+}
+
+const Pokemod::MapWildListEncounter* Pokemod::MapWildList::encounter(const int index) const
+{
+ Q_ASSERT(index < encounterCount());
+ return m_encounters.at(index);
+}
+
+Pokemod::MapWildListEncounter* Pokemod::MapWildList::encounter(const int index)
+{
+ Q_ASSERT(index < encounterCount());
+ return m_encounters[index];
+}
+
+const Pokemod::MapWildListEncounter* Pokemod::MapWildList::encounterById(const int id) const
+{
+ return encounter(encounterIndex(id));
+}
+
+Pokemod::MapWildListEncounter* Pokemod::MapWildList::encounterById(const int id)
+{
+ return encounter(encounterIndex(id));
+}
+
+int Pokemod::MapWildList::encounterIndex(const int id) const
+{
+ for (int i = 0; i < encounterCount(); ++i)
+ {
+ if (m_encounters[i]->id() == id)
+ return i;
+ }
+ return INT_MAX;
+}
+
+int Pokemod::MapWildList::encounterCount() const
+{
+ return m_encounters.size();
+}
+
+Pokemod::MapWildListEncounter* Pokemod::MapWildList::newEncounter()
+{
+ return newEncounter(new MapWildListEncounter(this, newEncounterId()));
+}
+
+Pokemod::MapWildListEncounter* Pokemod::MapWildList::newEncounter(const QDomElement& xml)
+{
+ return newEncounter(new MapWildListEncounter(xml, this, newEncounterId()));
+}
+
+Pokemod::MapWildListEncounter* Pokemod::MapWildList::newEncounter(const MapWildListEncounter& encounter)
+{
+ return newEncounter(new MapWildListEncounter(encounter, this, newEncounterId()));
+}
+
+Pokemod::MapWildListEncounter* Pokemod::MapWildList::newEncounter(MapWildListEncounter* encounter)
+{
+ m_encounters.append(encounter);
+ return encounter;
+}
+
+void Pokemod::MapWildList::deleteEncounter(const int index)
+{
+ Q_ASSERT(index < encounterCount());
+ delete m_encounters[index];
+ m_encounters.removeAt(index);
+}
+
+void Pokemod::MapWildList::deleteEncounterById(const int id)
+{
+ deleteEncounter(encounterIndex(id));
+}
+
+int Pokemod::MapWildList::newEncounterId() const
+{
+ int i = 0;
+ while ((i < encounterCount()) && (encounterIndex(i) != INT_MAX))
+ ++i;
+ return i;
+}
+
+Pokemod::MapWildList& Pokemod::MapWildList::operator=(const MapWildList& rhs)
+{
+ if (this == &rhs)
+ return *this;
+ clear();
+ COPY(name);
+ COPY_SUB(MapWildListEncounter, encounters);
+ return *this;
+}
+
+void Pokemod::MapWildList::clear()
+{
+ while (encounterCount())
+ deleteEncounter(0);
+}