summaryrefslogtreecommitdiffstats
path: root/pokemod/Pokemod.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-03-09 22:20:15 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-03-09 22:20:15 +0000
commit0191933210bd20a59527fcf2732a4f3c846fb2a9 (patch)
tree4779040481aabbe121cf50286a0ad2f5a316c70e /pokemod/Pokemod.cpp
parent68447b2a21c928526b2a7e614a1d56484f379bc6 (diff)
downloadsigen-0191933210bd20a59527fcf2732a4f3c846fb2a9.tar.gz
sigen-0191933210bd20a59527fcf2732a4f3c846fb2a9.tar.xz
sigen-0191933210bd20a59527fcf2732a4f3c846fb2a9.zip
[ADD] ItemType now has a count descriptor
[ADD] Species now has a flee chance [FIX] Empty fields removed from .ui files [FIX] Fixed compile errors in pokemodr [ADD] Trainer now helps to simplify MapTrainers [ADD] Trainer UI file [FIX] MapTrainer dialogs condensed [FIX] Home direcotry now gotten by QDir::homePath() rather than ~ git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@93 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Pokemod.cpp')
-rw-r--r--pokemod/Pokemod.cpp131
1 files changed, 126 insertions, 5 deletions
diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp
index cc5b44b2..6add7b59 100644
--- a/pokemod/Pokemod.cpp
+++ b/pokemod/Pokemod.cpp
@@ -43,6 +43,7 @@
#include "Store.h"
#include "Tile.h"
#include "Time.h"
+#include "Trainer.h"
#include "Type.h"
#include "Pokemod.h"
@@ -68,7 +69,7 @@ Pokemod::Pokemod() :
superPCPasswd(""),
typeChart(1, 1, Frac(1, 1, Frac::Improper)),
rules(this),
- path("~/.kde/share/apps/pokegen/mods")
+ path(QString("%1/.kde/share/apps/pokegen/mods").arg(QDir::homePath()))
{
}
@@ -125,6 +126,8 @@ Pokemod::~Pokemod()
delete i.next();
for (QListIterator<Time*> i(times); i.hasNext(); )
delete i.next();
+ for (QListIterator<Trainer*> i(trainers); i.hasNext(); )
+ delete i.next();
for (QListIterator<Type*> i(types); i.hasNext(); )
delete i.next();
}
@@ -613,6 +616,35 @@ bool Pokemod::validate() const
validationMsg("There are no tiles");
valid = false;
}
+ if (!getTrainerCount())
+ {
+ validationMsg("There are no times", Pokemod::V_Warn);
+ }
+ for (QListIterator<Trainer*> i(trainers); i.hasNext(); i.next())
+ {
+ if (!i.peekNext()->isValid())
+ valid = false;
+ ++idChecker[i.peekNext()->getId()];
+ ++nameChecker[i.peekNext()->getName()];
+ }
+ for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next())
+ {
+ if (1 < i.value())
+ {
+ validationMsg(QString("There are %1 trainers with id %2").arg(i.value()).arg(i.key()));
+ valid = false;
+ }
+ }
+ for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next())
+ {
+ if (1 < i.value())
+ {
+ validationMsg(QString("There are %1 trianers with the name \"%2\"").arg(i.value()).arg(i.key()));
+ valid = false;
+ }
+ }
+ idChecker.clear();
+ nameChecker.clear();
if (!getTimeCount())
{
validationMsg("There are no times");
@@ -786,6 +818,7 @@ int Pokemod::getNewStoreId() const
;
return i;
}
+
int Pokemod::getNewTileId() const
{
int i = 0;
@@ -793,6 +826,7 @@ int Pokemod::getNewTileId() const
;
return i;
}
+
int Pokemod::getNewTimeId() const
{
int i = 0;
@@ -800,6 +834,15 @@ int Pokemod::getNewTimeId() const
;
return i;
}
+
+int Pokemod::getNewTrainerId() const
+{
+ int i = 0;
+ for (; (i < getTrainerCount()) && (getTrainerIndex(i) != -1); ++i)
+ ;
+ return i;
+}
+
int Pokemod::getNewTypeId() const
{
int i = 0;
@@ -807,6 +850,7 @@ int Pokemod::getNewTypeId() const
;
return i;
}
+
void Pokemod::load(const QString& fname, const int) throw(Exception)
{
Ini ini(fname);
@@ -919,7 +963,14 @@ void Pokemod::load(const QString& fname, const int) throw(Exception)
newTile(i.next());
fdir.cdUp();
}
- times.clear();
+ trainers.clear();
+ if (fdir.cd("trainer"))
+ {
+ for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); )
+ newTrainer(i.next());
+ fdir.cdUp();
+ }
+ trainers.clear();
if (fdir.cd("time"))
{
for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); )
@@ -995,6 +1046,8 @@ void Pokemod::save() const throw(Exception)
i.next()->save();
for (QListIterator<Time*> i(times); i.hasNext(); )
i.next()->save();
+ for (QListIterator<Trainer*> i(trainers); i.hasNext(); )
+ i.next()->save();
for (QListIterator<Type*> i(types); i.hasNext(); )
i.next()->save();
}
@@ -1012,10 +1065,10 @@ void Pokemod::setPath(const QString& p)
void Pokemod::copyDir(const QString& src, const QString& dest) const
{
- QStringList list(QDir(src).entryList(QDir:Dirs));
+ QStringList list(QDir(src).entryList(QDir::Dirs));
for (int i = 0; i < list.size(); ++i)
copyDir(QString("%1/%2").arg(src).arg(list[i]), QString("%1/%2").arg(dest).arg(list[i]));
- list = QDir(src).entryList(QDir:Dirs);
+ list = QDir(src).entryList(QDir::Dirs);
for (int i = 0; i < list.size(); ++i)
QFile::copy(QString("%1/%2").arg(src).arg(list[i]), QString("%1/%2").arg(dest).arg(list[i]));
}
@@ -2229,6 +2282,71 @@ void Pokemod::deleteTime(const int i) throw(IndexException)
times.removeAt(i);
}
+const Trainer* Pokemod::getTrainer(const int i) const throw(IndexException)
+{
+ if (getTrainerCount() <= i)
+ throw(IndexException(className));
+ return trainers.at(i);
+}
+
+Trainer* Pokemod::getTrainer(const int i) throw(IndexException)
+{
+ if (getTrainerCount() <= i)
+ throw(IndexException(className));
+ return trainers[i];
+}
+
+const Trainer* Pokemod::getTrainerByID(const int i) const throw(IndexException)
+{
+ return getTrainer(getTrainerIndex(i));
+}
+
+Trainer* Pokemod::getTrainerByID(const int i) throw(IndexException)
+{
+ return getTrainer(getTrainerIndex(i));
+}
+
+int Pokemod::getTrainerIndex(const int _id) const
+{
+ for (int i = 0; i < getTrainerCount(); ++i)
+ {
+ if (trainers[i]->getId() == _id)
+ return i;
+ }
+ return -1;
+}
+
+int Pokemod::getTrainerCount() const
+{
+ return trainers.size();
+}
+
+Trainer* Pokemod::newTrainer()
+{
+ trainers.append(new Trainer(this, getNewTrainerId()));
+ return trainers[getTrainerCount() - 1];
+}
+
+Trainer* Pokemod::newTrainer(const QString& fname)
+{
+ trainers.append(new Trainer(this, fname, getNewTrainerId()));
+ return trainers[getTrainerCount() - 1];
+}
+
+Trainer* Pokemod::newTrainer(const Trainer& t)
+{
+ trainers.append(new Trainer(this, t, getNewTrainerId()));
+ return trainers[getTrainerCount() - 1];
+}
+
+void Pokemod::deleteTrainer(const int i) throw(IndexException)
+{
+ if (getTrainerCount() <= i)
+ throw(IndexException(className));
+ delete trainers[i];
+ trainers.removeAt(i);
+}
+
const Type* Pokemod::getType(const int i) const throw(IndexException)
{
if (getTypeCount() <= i)
@@ -2360,7 +2478,10 @@ Pokemod& Pokemod::operator=(const Pokemod& rhs)
tiles.clear();
for (int i = 0; i < rhs.getTileCount(); ++i)
tiles.append(new Tile(this, *rhs.getTile(i), rhs.getTile(i)->getId()));
- times.clear();
+ trainers.clear();
+ for (int i = 0; i < rhs.getTrainerCount(); ++i)
+ trainers.append(new Trainer(this, *rhs.getTrainer(i), rhs.getTrainer(i)->getId()));
+ types.clear();
for (int i = 0; i < rhs.getTimeCount(); ++i)
times.append(new Time(this, *rhs.getTime(i), rhs.getTime(i)->getId()));
types.clear();