diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-02 08:42:08 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-02 08:42:08 +0000 |
| commit | 822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd (patch) | |
| tree | 40dc605213eff20f62b16e5f54e5e5e03d744d63 /pokemod/MapTrainerTeamMember.cpp | |
| parent | 696414f1dc8bc419427efb6c1abe1bbae0a68a56 (diff) | |
| download | sigen-822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd.tar.gz sigen-822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd.tar.xz sigen-822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd.zip | |
[FIX] Exceptions no longer used in pokemod
[DEL] Exception and BugCatcher are no longer needed
[ADD] Object.cpp added
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@119 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/MapTrainerTeamMember.cpp')
| -rw-r--r-- | pokemod/MapTrainerTeamMember.cpp | 104 |
1 files changed, 45 insertions, 59 deletions
diff --git a/pokemod/MapTrainerTeamMember.cpp b/pokemod/MapTrainerTeamMember.cpp index 94e44357..1a6759ba 100644 --- a/pokemod/MapTrainerTeamMember.cpp +++ b/pokemod/MapTrainerTeamMember.cpp @@ -23,6 +23,9 @@ #include "Species.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMember) : Object("MapTrainerTeamMember", teamMember.parent(), teamMember.id()) { @@ -49,50 +52,21 @@ MapTrainerTeamMember::MapTrainerTeamMember(const QDomElement& xml, const Object* load(xml, id); } -bool MapTrainerTeamMember::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---------Team Member with id %1---").arg(id()), Pokemod::V_Msg); -// if (static_cast<const Pokemod*>(pokemod())->speciesIndex(m_species) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid species"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= m_level) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid level"); -// valid = false; -// } -// if (m_items.size() <= static_cast<const Pokemod*>(pokemod())->rules()->holdItems()) -// { -// QMap<int, bool> itemChecker; -// foreach (int item, m_items) -// { -// if (static_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid item"); -// valid = false; -// } -// if (itemChecker[item]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate of item %1").arg(item)); -// itemChecker[item] = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Too many held items"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->rules()->natureAllowed()) -// { -// if (static_cast<const Pokemod*>(pokemod())->natureIndex(m_nature) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid nature"); -// valid = false; -// } -// } -// return valid; +void MapTrainerTeamMember::validate(QTextStream& stream) +{ + TEST_SETUP(); + TEST(setSpecies, species); + TEST(setLevel, level); + if (m_item.size() <= static_cast<const Pokemod*>(pokemod())->rules()->holdItems()) + { + TEST_LIST(setItem, item); + } + else + error(stream, "Too many held items"); + if (static_cast<const Pokemod*>(pokemod())->rules()->natureAllowed()) + { + TEST(setNature, nature); + } } void MapTrainerTeamMember::load(const QDomElement& xml, int id) @@ -101,7 +75,7 @@ void MapTrainerTeamMember::load(const QDomElement& xml, int id) LOAD(int, species); LOAD(int, level); LOAD(int, nature); - LOAD_LIST(int, items) + LOAD_LIST(int, item) } QDomElement MapTrainerTeamMember::save() const @@ -110,41 +84,53 @@ QDomElement MapTrainerTeamMember::save() const SAVE(int, species); SAVE(int, level); SAVE(int, nature); - SAVE_LIST(int, items); + SAVE_LIST(int, item); return xml; } -void MapTrainerTeamMember::setSpecies(const int species) throw(BoundsException) +void MapTrainerTeamMember::setSpecies(const int species) { if (static_cast<const Pokemod*>(pokemod())->speciesIndex(species) == INT_MAX) - error<BoundsException>("species"); + { + boundsError("species"); + return; + } m_species = species; } -void MapTrainerTeamMember::setLevel(const int level) throw(BoundsException) +void MapTrainerTeamMember::setLevel(const int level) { if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < level) - error<BoundsException>("level"); + { + boundsError("level"); + return; + } m_level = level; } -void MapTrainerTeamMember::setItem(const int item, const bool state) throw(BoundsException) +void MapTrainerTeamMember::setItem(const int item, const bool state) { if (static_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) - error<BoundsException>("item"); + { + boundsError("item"); + return; + } if (state) { - if (!m_items.contains(item)) - m_items.append(item); + if (!m_item.contains(item)) + m_item.append(item); } else - m_items.removeAll(item); + m_item.removeAll(item); } -void MapTrainerTeamMember::setNature(const int nature) throw(BoundsException) +void MapTrainerTeamMember::setNature(const int nature) { if (!static_cast<const Pokemod*>(pokemod())->rules()->natureAllowed() || (static_cast<const Pokemod*>(pokemod())->natureIndex(nature) == INT_MAX)) - error<BoundsException>("nature"); + { + boundsError("nature"); + return; + } m_nature = nature; } @@ -165,7 +151,7 @@ int MapTrainerTeamMember::nature() const bool MapTrainerTeamMember::item(const int item) const { - return m_items.contains(item); + return m_item.contains(item); } MapTrainerTeamMember& MapTrainerTeamMember::operator=(const MapTrainerTeamMember& rhs) @@ -175,6 +161,6 @@ MapTrainerTeamMember& MapTrainerTeamMember::operator=(const MapTrainerTeamMember COPY(species); COPY(level); COPY(nature); - COPY(items); + COPY(item); return *this; } |
