summaryrefslogtreecommitdiffstats
path: root/pokemod/MapWildList.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-04-15 18:57:00 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-04-15 18:57:00 +0000
commite1b5d7bc705810ac15ed36924617af52abdc8e81 (patch)
tree0dae5af4e2737372ec479bb9ccdd2201edf684a8 /pokemod/MapWildList.cpp
parent12d5161318a4d8d781f896812f5a95fa7b46d8a8 (diff)
downloadsigen-e1b5d7bc705810ac15ed36924617af52abdc8e81.tar.gz
sigen-e1b5d7bc705810ac15ed36924617af52abdc8e81.tar.xz
sigen-e1b5d7bc705810ac15ed36924617af52abdc8e81.zip
[FIX] Object::mid -> m_id
[FIX] XML is now used [FIX] Images are stored in the XML file and classes rather than relying on external images [FIX] Frac no longer keeps track of its type; the class should do it [ADD] pokemod/Object.cpp git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@97 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/MapWildList.cpp')
-rw-r--r--pokemod/MapWildList.cpp87
1 files changed, 29 insertions, 58 deletions
diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp
index 0f6730e7..52a1dc78 100644
--- a/pokemod/MapWildList.cpp
+++ b/pokemod/MapWildList.cpp
@@ -44,16 +44,15 @@ MapWildList::MapWildList(const Pokemod* pokemod, const MapWildList& wildList, co
*this = wildList;
}
-MapWildList::MapWildList(const Pokemod* pokemod, const QString& fileName, const int id) :
+MapWildList::MapWildList(const Pokemod* pokemod, const QDomElement& xml, const int id) :
Object("MapWildList", pokemod, id)
{
- load(fileName, id);
+ load(xml, id);
}
MapWildList::~MapWildList()
{
- while (encounterCount())
- deleteEncounter(0);
+ clear();
}
bool MapWildList::validate() const
@@ -133,51 +132,25 @@ bool MapWildList::validate() const
return valid;
}
-void MapWildList::load(const QString& fileName, int id) throw(Exception)
+void MapWildList::load(const QDomElement& xml, int id)
{
- Ini ini(fileName);
- if (id == INT_MAX)
- ini.getValue("id", id);
- setId(id);
- int i;
- int j;
- 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 (m_times.contains(j))
- m_times.append(j);
- }
- ini.getValue("scope", m_scope);
- QStringList path = pokemod()->path().split('/');
- path.removeLast();
- QDir fdir(path.join("/"));
- while (encounterCount())
- deleteEncounter(0);
- if (fdir.cd("encounter"))
- {
- QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name));
- foreach (QString file, files)
- newEncounter(file);
- }
+ LOAD_ID();
+ LOAD(int, control);
+ LOAD(int, value);
+ LOAD_LIST(int, times);
+ LOAD(int, scope);
+ LOAD_SUB(newEncounter, encounters);
}
-void MapWildList::save(const QString& map) const throw(Exception)
+QDomElement MapWildList::save() const
{
- Ini ini;
- 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());
+ SAVE_CREATE();
+ SAVE(int, control);
+ SAVE(int, value);
+ SAVE_LIST(int, times);
+ SAVE(int, scope);
+ SAVE_SUB(MapWildListEncounter, encounters);
+ return xml;
}
void MapWildList::setControl(const int control) throw(BoundsException)
@@ -263,14 +236,14 @@ int MapWildList::scope() const
const MapWildListEncounter* MapWildList::encounter(const int index) const throw(IndexException)
{
if (encounterCount() <= index)
- throw(IndexException(className()));
+ error<IndexException>("encounter");
return m_encounters.at(index);
}
MapWildListEncounter* MapWildList::encounter(const int index) throw(IndexException)
{
if (encounterCount() <= index)
- throw(IndexException(className()));
+ error<IndexException>("encounter");
return m_encounters[index];
}
@@ -305,9 +278,9 @@ MapWildListEncounter* MapWildList::newEncounter()
return m_encounters[encounterCount() - 1];
}
-MapWildListEncounter* MapWildList::newEncounter(const QString& fileName)
+MapWildListEncounter* MapWildList::newEncounter(const QDomElement& xml)
{
- m_encounters.append(new MapWildListEncounter(pokemod(), fileName, newEncounterId()));
+ m_encounters.append(new MapWildListEncounter(pokemod(), xml, newEncounterId()));
return m_encounters[encounterCount() - 1];
}
@@ -320,7 +293,7 @@ MapWildListEncounter* MapWildList::newEncounter(const MapWildListEncounter& enco
void MapWildList::deleteEncounter(const int index) throw(IndexException)
{
if (encounterCount() <= index)
- throw(IndexException(className()));
+ error<IndexException>("encounter");
delete m_encounters[index];
m_encounters.removeAt(index);
}
@@ -342,13 +315,11 @@ MapWildList& MapWildList::operator=(const MapWildList& rhs)
{
if (this == &rhs)
return *this;
- m_control = rhs.m_control;
- m_value = rhs.m_value;
- m_times = rhs.m_times;
- m_scope = rhs.m_scope;
- while (encounterCount())
- deleteEncounter(0);
- foreach (MapWildListEncounter* encounter, rhs.m_encounters)
- m_encounters.append(new MapWildListEncounter(pokemod(), *encounter, encounter->id()));
+ clear();
+ COPY(control);
+ COPY(value);
+ COPY(times);
+ COPY(scope);
+ COPY_SUB(MapWildListEncounter, encounters);
return *this;
}