diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-27 00:47:02 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-27 00:47:02 +0000 |
| commit | 00fecef0aebaa379dfc176ddc5d6488fae0e8272 (patch) | |
| tree | 2b77cc9c4a31f012bcddbf1fe8efa3f3ca1f6139 /pokemod/Pokemod.cpp | |
| parent | c4a3724a2b981e8dbc20f5d319a80bf364f2c7b7 (diff) | |
| download | sigen-00fecef0aebaa379dfc176ddc5d6488fae0e8272.tar.gz sigen-00fecef0aebaa379dfc176ddc5d6488fae0e8272.tar.xz sigen-00fecef0aebaa379dfc176ddc5d6488fae0e8272.zip | |
[FIX] Status and Weather classes in pokemod instead of hardcoded
[FIX] Added a Sprite class to allow for animations and whatnot
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@178 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Pokemod.cpp')
| -rw-r--r-- | pokemod/Pokemod.cpp | 293 |
1 files changed, 289 insertions, 4 deletions
diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp index 895366e1..6a76b081 100644 --- a/pokemod/Pokemod.cpp +++ b/pokemod/Pokemod.cpp @@ -33,11 +33,14 @@ #include "Rules.h" #include "Sound.h" #include "Species.h" +#include "Sprite.h" +#include "Status.h" #include "Store.h" #include "Tile.h" #include "Time.h" #include "Trainer.h" #include "Type.h" +#include "Weather.h" // Qt includes #include <QBuffer> @@ -45,12 +48,8 @@ const QStringList Pokemod::StatRBYStr = QStringList() << "HP" << "Attack" << "Defense" << "Speed" << "Special" << "Special" << "Accuracy" << "Evasion"; const QStringList Pokemod::StatGSCStr = QStringList() << "HP" << "Attack" << "Defense" << "Speed" << "Special Attack" << "Special Defense" << "Accuracy" << "Evasion"; -const QStringList Pokemod::BattleMemberStr = QStringList() << "Player" << "Enemy"; -const QStringList Pokemod::WeatherStr = QStringList() << "Ice" << "Rain" << "Sun" << "Sand" << "All"; const QStringList Pokemod::DirectionStr = QStringList() << "Up" << "Down" << "Left" << "Right" << "None"; const QStringList Pokemod::RelativeStr = QStringList() << "Less" << "Less or Equal" << "Greater or Equal" << "Greater" << "Equal" << "Not Equal"; -const QStringList Pokemod::StatusStr = QStringList() << "Freeze" << "Paralyze" << "Sleep" << "Poison" << "Toxic Poison" << "Burn" << "Any"; -const QStringList Pokemod::HMStr = QStringList() << "Cut" << "Fly" << "Surf" << "Strength" << "Flash" << "Whirlpool" << "Waterfall" << "Dive" << "Headbutt" << "Rock Smash" << "Defog" << "Rock Climb" << "Heal" << "Escape"; Pokemod::Pokemod() : Object("Pokemod", NULL, 0), @@ -302,6 +301,20 @@ void Pokemod::validate() } idChecker.clear(); nameChecker.clear(); + if (!statusCount()) + emit(error("There are no status effects")); + foreach (Status* status, m_status) + { + status->validate(); + if (idChecker.contains(status->id())) + emit(error(subclass("status effect", status->id()))); + idChecker.insert(status->id()); + if (nameChecker.contains(status->name())) + emit(error(subclass("status effect", status->name()))); + nameChecker.insert(status->name()); + } + idChecker.clear(); + nameChecker.clear(); if (!storeCount()) emit(warning("There are no stores")); foreach (Store* store, m_stores) @@ -373,6 +386,20 @@ void Pokemod::validate() emit(error(subclass("type", type->name()))); nameChecker.insert(type->name()); } + idChecker.clear(); + nameChecker.clear(); + if (!weatherCount()) + emit(error("There are no weathers")); + foreach (Weather* weather, m_weathers) + { + weather->validate(); + if (idChecker.contains(weather->id())) + emit(error(subclass("weather", weather->id()))); + idChecker.insert(weather->id()); + if (nameChecker.contains(weather->name())) + emit(error(subclass("weather", weather->name()))); + nameChecker.insert(weather->name()); + } } void Pokemod::load(const QDomElement& xml, const int) @@ -403,11 +430,14 @@ void Pokemod::load(const QDomElement& xml, const int) LOAD_SUB(newNature, Nature); LOAD_SUB(newSound, Sound); LOAD_SUB(newSpecies, Species); + LOAD_SUB(newSprite, Sprite); + LOAD_SUB(newStatus, Status); LOAD_SUB(newStore, Store); LOAD_SUB(newTile, Tile); LOAD_SUB(newTime, Time); LOAD_SUB(newTrainer, Trainer); LOAD_SUB(newType, Type); + LOAD_SUB(newWeather, Weather); LOAD_MATRIX(setTypeChart, Fraction, typeChart); } @@ -440,11 +470,14 @@ QDomElement Pokemod::save() const SAVE_SUB(Nature, natures); SAVE_SUB(Sound, sounds); SAVE_SUB(Species, species); + SAVE_SUB(Sprite, sprites); + SAVE_SUB(Status, status); SAVE_SUB(Store, stores); SAVE_SUB(Tile, tiles); SAVE_SUB(Time, times); SAVE_SUB(Trainer, trainers); SAVE_SUB(Type, types); + SAVE_SUB(Weather, weathers); return xml; } @@ -1707,6 +1740,168 @@ int Pokemod::newSpeciesId() const return i; } +const Sprite* Pokemod::sprite(const int index) const +{ + if (spriteCount() <= index) + return NULL; + return m_sprites.at(index); +} + +Sprite* Pokemod::sprite(const int index) +{ + if (spriteCount() <= index) + return NULL; + return m_sprites[index]; +} + +const Sprite* Pokemod::spriteById(const int id) const +{ + return sprite(spriteIndex(id)); +} + +Sprite* Pokemod::spriteById(const int id) +{ + return sprite(spriteIndex(id)); +} + +int Pokemod::spriteIndex(const int id) const +{ + for (int i = 0; i < spriteCount(); ++i) + { + if (m_sprites[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::spriteCount() const +{ + return m_sprites.size(); +} + +Sprite* Pokemod::newSprite() +{ + return newSprite(new Sprite(this, newSpriteId())); +} + +Sprite* Pokemod::newSprite(const QDomElement& xml) +{ + return newSprite(new Sprite(xml, this, newSpriteId())); +} + +Sprite* Pokemod::newSprite(const Sprite& sprite) +{ + return newSprite(new Sprite(sprite, this, newSpriteId())); +} + +Sprite* Pokemod::newSprite(Sprite* sprite) +{ + m_sprites.append(sprite); + return sprite; +} + +void Pokemod::deleteSprite(const int index) +{ + if (spriteCount() <= index) + return; + delete m_sprites[index]; + m_sprites.removeAt(index); +} + +void Pokemod::deleteSpriteById(const int id) +{ + deleteSprite(spriteIndex(id)); +} + +int Pokemod::newSpriteId() const +{ + int i = 0; + while ((i < spriteCount()) && (spriteIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Status* Pokemod::status(const int index) const +{ + if (statusCount() <= index) + return NULL; + return m_status.at(index); +} + +Status* Pokemod::status(const int index) +{ + if (statusCount() <= index) + return NULL; + return m_status[index]; +} + +const Status* Pokemod::statusById(const int id) const +{ + return status(statusIndex(id)); +} + +Status* Pokemod::statusById(const int id) +{ + return status(statusIndex(id)); +} + +int Pokemod::statusIndex(const int id) const +{ + for (int i = 0; i < statusCount(); ++i) + { + if (m_status[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::statusCount() const +{ + return m_status.size(); +} + +Status* Pokemod::newStatus() +{ + return newStatus(new Status(this, newStatusId())); +} + +Status* Pokemod::newStatus(const QDomElement& xml) +{ + return newStatus(new Status(xml, this, newStatusId())); +} + +Status* Pokemod::newStatus(const Status& status) +{ + return newStatus(new Status(status, this, newStatusId())); +} + +Status* Pokemod::newStatus(Status* status) +{ + m_status.append(status); + return status; +} + +void Pokemod::deleteStatus(const int index) +{ + if (statusCount() <= index) + return; + delete m_status[index]; + m_status.removeAt(index); +} + +void Pokemod::deleteStatusById(const int id) +{ + deleteStatus(statusIndex(id)); +} + +int Pokemod::newStatusId() const +{ + int i = 0; + while ((i < statusCount()) && (statusIndex(i) != INT_MAX)) + ++i; + return i; +} + const Store* Pokemod::store(const int index) const { if (storeCount() <= index) @@ -2126,6 +2321,87 @@ int Pokemod::newTypeId() const return i; } +const Weather* Pokemod::weather(const int index) const +{ + if (weatherCount() <= index) + return NULL; + return m_weathers.at(index); +} + +Weather* Pokemod::weather(const int index) +{ + if (weatherCount() <= index) + return NULL; + return m_weathers[index]; +} + +const Weather* Pokemod::weatherById(const int id) const +{ + return weather(weatherIndex(id)); +} + +Weather* Pokemod::weatherById(const int id) +{ + return weather(weatherIndex(id)); +} + +int Pokemod::weatherIndex(const int id) const +{ + for (int i = 0; i < weatherCount(); ++i) + { + if (m_weathers[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::weatherCount() const +{ + return m_weathers.size(); +} + +Weather* Pokemod::newWeather() +{ + return newWeather(new Weather(this, newWeatherId())); +} + +Weather* Pokemod::newWeather(const QDomElement& xml) +{ + return newWeather(new Weather(xml, this, newWeatherId())); +} + +Weather* Pokemod::newWeather(const Weather& weather) +{ + return newWeather(new Weather(weather, this, newWeatherId())); +} + +Weather* Pokemod::newWeather(Weather* weather) +{ + m_weathers.append(weather); + return weather; +} + +void Pokemod::deleteWeather(const int index) +{ + if (weatherCount() <= index) + return; + delete m_weathers[index]; + m_weathers.removeAt(index); +} + +void Pokemod::deleteWeatherById(const int id) +{ + deleteWeather(weatherIndex(id)); +} + +int Pokemod::newWeatherId() const +{ + int i = 0; + while ((i < weatherCount()) && (weatherIndex(i) != INT_MAX)) + ++i; + return i; +} + Pokemod& Pokemod::operator=(const Pokemod& rhs) { if (this == &rhs) @@ -2151,11 +2427,14 @@ Pokemod& Pokemod::operator=(const Pokemod& rhs) COPY_SUB(Nature, natures); COPY_SUB(Sound, sounds); COPY_SUB(Species, species); + COPY_SUB(Sprite, sprites); + COPY_SUB(Status, status); COPY_SUB(Store, stores); COPY_SUB(Tile, tiles); COPY_SUB(Time, times); COPY_SUB(Trainer, trainers); COPY_SUB(Type, types); + COPY_SUB(Weather, weathers); return *this; } @@ -2188,6 +2467,10 @@ void Pokemod::clear() deleteSound(0); while (speciesCount()) deleteSpecies(0); + while (spriteCount()) + deleteSprite(0); + while (statusCount()) + deleteStatus(0); while (storeCount()) deleteStore(0); while (tileCount()) @@ -2198,4 +2481,6 @@ void Pokemod::clear() deleteTrainer(0); while (typeCount()) deleteType(0); + while (weatherCount()) + deleteWeather(0); } |
