diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-06-02 01:50:47 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-06-02 01:50:47 +0000 |
| commit | 87bc8b43600937a3d83cbdf8345e23a484755e3a (patch) | |
| tree | 661131614ed841f68ab8cc23ea372983d49fbe20 /pokemod/MapTrainerTeamMember.cpp | |
| parent | f3e081acd87439efadd5ff4181916e06cc07f051 (diff) | |
| download | sigen-87bc8b43600937a3d83cbdf8345e23a484755e3a.tar.gz sigen-87bc8b43600937a3d83cbdf8345e23a484755e3a.tar.xz sigen-87bc8b43600937a3d83cbdf8345e23a484755e3a.zip | |
[FIX] Modified Rules a bit
[FIX] Updated Rules widget to match up with Rules
[FIX] Reorganized the Rules widget
[FIX] Using KStandardDirs rather than hardcoded ones
[FIX] Cleaned up some minor things with KListWidgets
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@188 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/MapTrainerTeamMember.cpp')
| -rw-r--r-- | pokemod/MapTrainerTeamMember.cpp | 145 |
1 files changed, 116 insertions, 29 deletions
diff --git a/pokemod/MapTrainerTeamMember.cpp b/pokemod/MapTrainerTeamMember.cpp index e82072eb..da8c962f 100644 --- a/pokemod/MapTrainerTeamMember.cpp +++ b/pokemod/MapTrainerTeamMember.cpp @@ -24,6 +24,7 @@ #include "Pokemod.h" #include "Rules.h" #include "Species.h" +#include "SpeciesMove.h" // Qt includes #include <QSet> @@ -37,8 +38,7 @@ MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMembe MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainer* parent, const int id) : Object("MapTrainerTeamMember", parent, id), m_species(INT_MAX), - m_level(INT_MAX), - m_nature(INT_MAX) + m_level(INT_MAX) { } @@ -58,16 +58,18 @@ void MapTrainerTeamMember::validate() { TEST(setSpecies, species); TEST(setLevel, level); - if (m_item.size() <= static_cast<const Pokemod*>(pokemod())->rules()->holdItems()) - { - TEST_LIST(setItem, item); - } - else + if (static_cast<const Pokemod*>(pokemod())->rules()->maxAbilities() < m_ability.size()) + emit(error("Too many abilities")); + TEST_LIST(setAbility, ability); + if (static_cast<const Pokemod*>(pokemod())->rules()->maxHeldItems() < m_item.size()) emit(error("Too many held items")); - if (static_cast<const Pokemod*>(pokemod())->rules()->natureAllowed()) - { - TEST(setNature, nature); - } + TEST_LIST(setItem, item); + if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoves() < m_move.size()) + emit(error("Too many moves")); + TEST_LIST(setMove, move); + if (static_cast<const Pokemod*>(pokemod())->rules()->maxNatures() < m_nature.size()) + emit(error("Too many natures")); + TEST_LIST(setNature, nature); } void MapTrainerTeamMember::load(const QDomElement& xml, int id) @@ -75,8 +77,10 @@ void MapTrainerTeamMember::load(const QDomElement& xml, int id) LOAD_ID(); LOAD(int, species); LOAD(int, level); - LOAD(int, nature); - LOAD_LIST(int, item) + LOAD_LIST(int, ability); + LOAD_LIST(int, item); + LOAD_LIST(int, move); + LOAD_LIST(int, nature); } QDomElement MapTrainerTeamMember::save() const @@ -84,8 +88,10 @@ QDomElement MapTrainerTeamMember::save() const SAVE_CREATE(); SAVE(int, species); SAVE(int, level); - SAVE(int, nature); + SAVE_LIST(int, ability); SAVE_LIST(int, item); + SAVE_LIST(int, move); + SAVE_LIST(int, nature); return xml; } @@ -109,6 +115,30 @@ void MapTrainerTeamMember::setLevel(const int level) CHECK(level); } +void MapTrainerTeamMember::setAbility(const int ability, const bool state) +{ + if (static_cast<const Pokemod*>(pokemod())->abilityIndex(ability) == INT_MAX) + { + emit(error(bounds("ability"))); + return; + } + if (state && !m_ability.contains(ability)) + { + if (m_ability.size() < static_cast<const Pokemod*>(pokemod())->rules()->maxAbilities()) + { + m_ability.append(ability); + emit(changed()); + } + else + emit(error("Cannot have any more abilities")); + } + else if (m_ability.contains(ability)) + { + m_ability.removeAll(ability); + emit(changed()); + } +} + void MapTrainerTeamMember::setItem(const int item, const bool state) { if (static_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) @@ -116,34 +146,79 @@ void MapTrainerTeamMember::setItem(const int item, const bool state) emit(error(bounds("item"))); return; } - if (state) + if (state && !m_item.contains(item)) { - if (!m_item.contains(item)) + if (m_item.size() < static_cast<const Pokemod*>(pokemod())->rules()->maxHeldItems()) { - if (m_item.size() < static_cast<const Pokemod*>(pokemod())->rules()->holdItems()) + m_item.append(item); + emit(changed()); + } + else + emit(error("Cannot hold any more items")); + } + else if (m_item.contains(item)) + { + m_item.removeAll(item); + emit(changed()); + } +} + +void MapTrainerTeamMember::setMove(const int move, const bool state) +{ + if (static_cast<const Pokemod*>(pokemod())->moveIndex(move) == INT_MAX) + { + emit(error(bounds("move"))); + return; + } + if (state && !m_move.contains(move)) + { + const Species* species = static_cast<const Pokemod*>(pokemod())->speciesById(move); + for (int i = 0; i < species->moveCount(); ++i) + { + const SpeciesMove* speciesMove = species->move(i); + if (speciesMove->move() == move) { - m_item.append(item); - emit(changed()); + if (m_move.size() < static_cast<const Pokemod*>(pokemod())->rules()->maxMoves()) + { + m_move.append(move); + emit(changed()); + return; + } + else + emit(error("Cannot know any more moves")); } - else - emit(error("Cannot hold any more items")); } + emit(error("Cannot learn the move")); } - else + else if (m_move.contains(move)) { - m_item.removeAll(item); + m_move.removeAll(move); emit(changed()); } } -void MapTrainerTeamMember::setNature(const int nature) +void MapTrainerTeamMember::setNature(const int nature, const bool state) { - if (!static_cast<const Pokemod*>(pokemod())->rules()->natureAllowed() || (static_cast<const Pokemod*>(pokemod())->natureIndex(nature) == INT_MAX)) + if (static_cast<const Pokemod*>(pokemod())->natureIndex(nature) == INT_MAX) { emit(error(bounds("nature"))); return; } - CHECK(nature); + if (state && !m_nature.contains(nature)) + { + if (m_nature.size() < static_cast<const Pokemod*>(pokemod())->rules()->maxNatures()) + { + m_nature.append(nature); + emit(changed()); + } + else + emit(error("Cannot have any more natures")); + } + else if (m_nature.contains(nature)) + { + m_nature.removeAll(nature); + emit(changed()); + } } int MapTrainerTeamMember::species() const @@ -156,9 +231,9 @@ int MapTrainerTeamMember::level() const return m_level; } -int MapTrainerTeamMember::nature() const +bool MapTrainerTeamMember::ability(const int ability) const { - return m_nature; + return m_ability.contains(ability); } bool MapTrainerTeamMember::item(const int item) const @@ -166,13 +241,25 @@ bool MapTrainerTeamMember::item(const int item) const return m_item.contains(item); } +bool MapTrainerTeamMember::move(const int move) const +{ + return m_move.contains(move); +} + +bool MapTrainerTeamMember::nature(const int nature) const +{ + return m_nature.contains(nature); +} + MapTrainerTeamMember& MapTrainerTeamMember::operator=(const MapTrainerTeamMember& rhs) { if (this == &rhs) return *this; COPY(species); COPY(level); - COPY(nature); + COPY(ability); COPY(item); + COPY(move); + COPY(nature); return *this; } |
