diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2008-04-19 18:12:17 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2008-04-19 18:12:17 +0000 |
commit | fe31331e2807634ae659e372358bac5781de9130 (patch) | |
tree | 6b208974e3f141e9b22152526e2d42e967bfd4ec | |
parent | 6679f5cffa9d35a23b76605ddfbf3257f882b6ee (diff) | |
download | sigen-fe31331e2807634ae659e372358bac5781de9130.tar.gz sigen-fe31331e2807634ae659e372358bac5781de9130.tar.xz sigen-fe31331e2807634ae659e372358bac5781de9130.zip |
[FIX] IndexException is more explicit
[FIX] Added SizeException for image validation
[FIX] QPixmaps are now verified
[FIX] Classes now use error and warning rather than throwing
[FIX] Deleted Object.cpp
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@100 6ecfd1a5-f3ed-3746-8530-beee90d26b22
42 files changed, 359 insertions, 330 deletions
@@ -1,4 +1,15 @@ ----------------- +Rev: 100 +Date: 19 April 2008 +User: MathStuf +----------------- +[FIX] IndexException is more explicit +[FIX] Added SizeException for image validation +[FIX] QPixmaps are now verified +[FIX] Classes now use error and warning rather than throwing +[FIX] Deleted Object.cpp + +----------------- Rev: 99 Date: 17 April 2008 User: MathStuf diff --git a/general/Exception.h b/general/Exception.h index 96788567..b52fc4b6 100644 --- a/general/Exception.h +++ b/general/Exception.h @@ -60,8 +60,8 @@ class BoundsException : public Exception class IndexException : public BoundsException { public: - IndexException(const QString& className) : - BoundsException(className, "index") + IndexException(const QString& className, const QString& variable) : + BoundsException(className, QString("%1 index").arg(variable)) { } }; @@ -120,4 +120,13 @@ class RemoveException : public Exception } }; +class SizeException : public Exception +{ + public: + SizeException(const QString& className, const QString& variable) : + Exception(className, QString("wrong size for %1").arg(variable)) + { + } +}; + #endif diff --git a/general/general.pro b/general/general.pro index bb7256ce..d13849b4 100644 --- a/general/general.pro +++ b/general/general.pro @@ -4,6 +4,7 @@ UI_DIR = .ui MOC_DIR = .moc DESTDIR = ../../bin LIBS += -lphonon -lkdeui -lkdecore +QMAKE_CXXFLAGS += -pg -O0 CONFIG += qt warn_on dll exceptions debug CONFIG -= release diff --git a/pokemod/Ability.cpp b/pokemod/Ability.cpp index 59574a9e..ba2a7cb7 100644 --- a/pokemod/Ability.cpp +++ b/pokemod/Ability.cpp @@ -111,7 +111,7 @@ QString Ability::name() const const AbilityEffect* Ability::effect(const int index) const throw(IndexException) { if (effectCount() <= index) - error<IndexException>("effect"); + warning<IndexException>("effect"); return m_effects.at(index); } diff --git a/pokemod/AbilityEffect.cpp b/pokemod/AbilityEffect.cpp index 40f3368a..382ccf39 100644 --- a/pokemod/AbilityEffect.cpp +++ b/pokemod/AbilityEffect.cpp @@ -239,7 +239,7 @@ void AbilityEffect::setChance(const Fraction& chance) throw(Exception) void AbilityEffect::setEffect(const int effect) throw(BoundsException) { if (E_End <= effect) - throw(BoundsException(className(), "effect")); + error<BoundsException>("effect"); m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; @@ -252,34 +252,34 @@ void AbilityEffect::setValue1(const int value1) throw(Exception) { case E_Stats: if ((Pokemod::ST_HP == value1) || (Pokemod::ST_End_Battle <= value1) || ((Pokemod::ST_SpecialDefense == value1) && !pokemod()->rules()->specialSplit())) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_Status: if (Pokemod::STS_End <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_Ability: if (pokemod()->abilityIndex(value1) == INT_MAX) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_AccuracyPowerTrade: if (PA_End <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_ItemEffect: if (IT_End <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_Type: if (pokemod()->typeIndex(value1) == INT_MAX) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_Weather: if (Pokemod::W_End_All <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; default: - throw(UnusedException(className(), "value1")); + error<UnusedException>("value1"); break; } m_value1 = value1; @@ -291,23 +291,23 @@ void AbilityEffect::setValue2(const int value2) throw(Exception) { case E_Stats: if (Pokemod::BM_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_Status: case E_Weather: if (C_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_Ability: if (I_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_Type: if (B_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; default: - throw(UnusedException(className(), "value2")); + error<UnusedException>("value2"); break; } m_value2 = value2; @@ -326,14 +326,14 @@ void AbilityEffect::setValue3(const int value3) throw(Exception) case E_Type: case E_FastHatch: if ((value3 < 0) || (100 < value3)) - throw(BoundsException(className(), "value3")); + error<BoundsException>("value3"); break; case E_Stats: if ((value3 < -12) || (12 < value3)) - throw(BoundsException(className(), "value3")); + error<BoundsException>("value3"); break; default: - throw(UnusedException(className(), "value3")); + error<UnusedException>("value3"); break; } m_value3 = value3; @@ -342,7 +342,7 @@ void AbilityEffect::setValue3(const int value3) throw(Exception) void AbilityEffect::setTrigger(const int trigger) throw(BoundsException) { if (T_End <= trigger) - throw(BoundsException(className(), "trigger")); + error<BoundsException>("trigger"); m_trigger = trigger; m_triggerValue1 = INT_MAX; m_triggerValue2.set(1, 1); @@ -354,26 +354,26 @@ void AbilityEffect::setTriggerValue1(const int triggerValue1) throw(Exception) { case T_Weather: if (Pokemod::W_End_All <= triggerValue1) - throw(BoundsException(className(), "triggerValue1")); + error<BoundsException>("triggerValue1"); break; case T_Type: if (pokemod()->typeIndex(triggerValue1) == INT_MAX) - throw(BoundsException(className(), "triggerValue1")); + error<BoundsException>("triggerValue1"); break; case T_HPBoundary: if (S_End <= triggerValue1) - throw(BoundsException(className(), "triggerValue1")); + error<BoundsException>("triggerValue1"); break; case T_StatChange: if ((Pokemod::ST_HP == triggerValue1) || (Pokemod::ST_End_Battle <= triggerValue1) || ((Pokemod::ST_SpecialDefense == triggerValue1) && !pokemod()->rules()->specialSplit())) - throw(BoundsException(className(), "triggerValue1")); + error<BoundsException>("triggerValue1"); break; case T_Status: if (Pokemod::STS_End <= triggerValue1) - throw(BoundsException(className(), "triggerValue1")); + error<BoundsException>("triggerValue1"); break; default: - throw(UnusedException(className(), "triggerValue1")); + error<UnusedException>("triggerValue1"); break; } m_triggerValue1 = triggerValue1; @@ -382,7 +382,7 @@ void AbilityEffect::setTriggerValue1(const int triggerValue1) throw(Exception) void AbilityEffect::setTriggerValue2(const Fraction& triggerValue2) throw(Exception) { if (m_trigger != T_HPBoundary) - throw(UnusedException(className(), "triggerValue2")); + error<UnusedException>("triggerValue2"); m_triggerValue2 = triggerValue2; } diff --git a/pokemod/Badge.cpp b/pokemod/Badge.cpp index 8c5088a9..b167c264 100644 --- a/pokemod/Badge.cpp +++ b/pokemod/Badge.cpp @@ -15,6 +15,9 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +// Qt includes +#include <QBuffer> + // Header include #include "Badge.h" @@ -27,6 +30,8 @@ Badge::Badge(const Badge& badge) : Badge::Badge(const Pokemod* pokemod, const int id) : Object("Badge", pokemod, id), m_name(""), + m_face(64, 64), + m_badge(64, 64), m_obey(0) { for (int i = 0; i < Pokemod::ST_End_GSC; ++i) @@ -68,8 +73,10 @@ void Badge::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(QString, name); + LOAD(QPixmap, face); + LOAD(QPixmap, badge); LOAD(int, obey); - LOAD_ARRAY(Fraction, stat, Pokemod::ST_End_GSC); + LOAD_ARRAY(Fraction, stat, (pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY)); LOAD_ARRAY(bool, hm, Pokemod::HM_End_All); } @@ -77,8 +84,10 @@ QDomElement Badge::save() const { SAVE_CREATE(); SAVE(QString, name); + SAVE(QPixmap, face); + SAVE(QPixmap, badge); SAVE(int, obey); - SAVE_ARRAY(Fraction, stat, Pokemod::ST_End_GSC); + SAVE_ARRAY(Fraction, stat, (pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY)); SAVE_ARRAY(bool, hm, Pokemod::HM_End_All); return xml; } @@ -88,36 +97,38 @@ void Badge::setName(const QString& name) m_name = name; } -void Badge::setFace(const QPixmap& face) throw(Exception) +void Badge::setFace(const QPixmap& face) throw(SizeException) { - // TODO: Check dimensions + if (face.size() != QSize(64, 64)) + error<SizeException>("face"); m_face = face; } -void Badge::setBadge(const QPixmap& badge) throw(Exception) +void Badge::setBadge(const QPixmap& badge) throw(SizeException) { - // TODO: Check dimensions + if (badge.size() != QSize(64, 64)) + error<SizeException>("badge"); m_badge = badge; } void Badge::setObey(const int obey) throw(BoundsException) { if (pokemod()->rules()->maxLevel() < obey) - throw(BoundsException(className(), "obey")); + error<BoundsException>("obey"); m_obey = obey; } void Badge::setStat(const int stat, const Fraction& multiplier) throw(Exception) { if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) - throw(BoundsException(className(), "stat")); + error<BoundsException>("stat"); m_stat[stat] = multiplier; } void Badge::setHm(const int hm, const bool hmAllowed) throw(BoundsException) { if (Pokemod::HM_End_All <= hm) - throw(BoundsException(className(), "hm")); + error<BoundsException>("hm"); m_hm[hm] = hmAllowed; } @@ -144,14 +155,14 @@ int Badge::obey() const Fraction Badge::stat(const int stat) const throw(BoundsException) { if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) - throw(BoundsException(className(), "stat")); + warning<BoundsException>("stat"); return m_stat[stat]; } bool Badge::hm(const int hm) const throw(BoundsException) { if (Pokemod::HM_End_All <= hm) - throw(BoundsException(className(), "hm")); + warning<BoundsException>("hm"); return m_hm[hm]; } diff --git a/pokemod/Badge.h b/pokemod/Badge.h index 2e394aac..2267a29f 100644 --- a/pokemod/Badge.h +++ b/pokemod/Badge.h @@ -42,8 +42,8 @@ class Badge : public Object QDomElement save() const; void setName(const QString& name); - void setFace(const QPixmap& face) throw(Exception); - void setBadge(const QPixmap& badge) throw(Exception); + void setFace(const QPixmap& face) throw(SizeException); + void setBadge(const QPixmap& badge) throw(SizeException); void setObey(const int obey) throw(BoundsException); void setStat(const int stat, const Fraction& multiplier) throw(Exception); void setHm(const int hm, const bool hmAllowed) throw(BoundsException); diff --git a/pokemod/CoinList.cpp b/pokemod/CoinList.cpp index e0b9f2fb..8c40db89 100644 --- a/pokemod/CoinList.cpp +++ b/pokemod/CoinList.cpp @@ -169,7 +169,7 @@ int CoinList::value() const const CoinListObject* CoinList::object(const int index) const throw(IndexException) { if (objectCount() <= index) - error<IndexException>("object"); + warning<IndexException>("object"); return m_objects.at(index); } diff --git a/pokemod/CoinListObject.cpp b/pokemod/CoinListObject.cpp index cc110a8e..bdc170fa 100644 --- a/pokemod/CoinListObject.cpp +++ b/pokemod/CoinListObject.cpp @@ -102,7 +102,7 @@ QDomElement CoinListObject::save() const void CoinListObject::setType(const int type) throw(BoundsException) { if (End <= type) - throw(BoundsException(className(), "type")); + error<BoundsException>("type"); m_type = type; m_object = INT_MAX; } @@ -110,14 +110,14 @@ void CoinListObject::setType(const int type) throw(BoundsException) void CoinListObject::setObject(const int object) throw(BoundsException) { if (((Item == m_type) && (pokemod()->itemIndex(object) == INT_MAX)) || ((Species == m_type) && (pokemod()->speciesIndex(object) == INT_MAX))) - throw(BoundsException(className(), "object")); + error<BoundsException>("object"); m_object = object; } void CoinListObject::setAmount(const int amount) throw(BoundsException) { if (!amount || ((Species == m_type) && (1 < amount))) - throw(BoundsException(className(), "amount")); + error<BoundsException>("amount"); m_amount = amount; } diff --git a/pokemod/Dialog.cpp b/pokemod/Dialog.cpp index 58252431..a24b88bb 100644 --- a/pokemod/Dialog.cpp +++ b/pokemod/Dialog.cpp @@ -691,7 +691,7 @@ QString Dialog::dialog() const void Dialog::insertCommand(const int position, const QString& command) throw(BoundsException) { if (m_dialog.length() < position) - throw(BoundsException(className(), "command")); + error<BoundsException>("command"); m_dialog.insert(position, command); } diff --git a/pokemod/Item.cpp b/pokemod/Item.cpp index afd4bd67..e49e9b17 100644 --- a/pokemod/Item.cpp +++ b/pokemod/Item.cpp @@ -133,14 +133,14 @@ void Item::setSellable(const bool sellable) void Item::setType(const int type) throw(BoundsException) { if (pokemod()->itemTypeIndex(type) == INT_MAX) - throw(BoundsException(className(), "type")); + error<BoundsException>("type"); m_type = type; } void Item::setPrice(const int price) throw(BoundsException) { if (pokemod()->rules()->maxMoney() < price) - throw(BoundsException(className(), "price")); + error<BoundsException>("price"); m_price = price; } @@ -177,7 +177,7 @@ QString Item::description() const const ItemEffect* Item::effect(const int index) const throw(IndexException) { if (effectCount() <= index) - error<IndexException>("effect"); + warning<IndexException>("effect"); return m_effects.at(index); } diff --git a/pokemod/ItemEffect.cpp b/pokemod/ItemEffect.cpp index 9d223475..0a4927c1 100644 --- a/pokemod/ItemEffect.cpp +++ b/pokemod/ItemEffect.cpp @@ -432,23 +432,23 @@ void ItemEffect::setValue1(const int value1) throw(Exception) case E_HPCure: case E_Revive: if ((m_value4 != R_Absolute) || !value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_LevelBoost: case E_ShieldBattle: case E_PPBoost: case E_Repel: if (!value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_StatBoost: case E_Acorn: if ((value1 < 0) || (65536 <= value1)) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_ModifyStatBattle: if ((value1 < -12) || (12 < value1)) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_Fish: case E_Coin: @@ -459,11 +459,11 @@ void ItemEffect::setValue1(const int value1) throw(Exception) { case B_Regular: if (256 <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case B_Level: if (pokemod()->rules()->maxLevel() < value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case B_Master: case B_Love: @@ -476,11 +476,11 @@ void ItemEffect::setValue1(const int value1) throw(Exception) case B_Weight: break; default: - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); } break; default: - throw(UnusedException(className(), "value1")); + error<UnusedException>("value1"); break; } m_value1 = value1; @@ -493,66 +493,66 @@ void ItemEffect::setValue2(const int value2) throw(Exception) case E_HPCure: case E_Revive: if (R_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_CureStatus: if (Pokemod::STS_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_StatBoost: if ((value2 <= 0) || (65536 <= value2)) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_ModifyStatBattle: if (Pokemod::ST_End_Battle <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_ShieldBattle: if (SP_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_TypeBoost: if (pokemod()->typeIndex(value2) == INT_MAX) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_PPRestore: if (A_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_Repel: if (RP_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_Escape: if (ES_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_TM: case E_HM: if (pokemod()->moveIndex(value2) == INT_MAX) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_Ball: if (B_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_Scope: break; case E_Berry: if (B2_End <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_Coin: case E_CoinCase: if (value2 <= 0) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; case E_Acorn: if (pokemod()->itemIndex(value2) == INT_MAX) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; default: - throw(UnusedException(className(), "value2")); + error<UnusedException>("value2"); break; } m_value2 = value2; @@ -564,7 +564,7 @@ void ItemEffect::setValue3(const int value3) throw(Exception) { case E_StatBoost: if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3) - throw(BoundsException(className(), "value3")); + error<BoundsException>("value3"); break; case E_Ball: switch (m_value2) @@ -575,25 +575,25 @@ void ItemEffect::setValue3(const int value3) throw(Exception) break; case B_Area: if (MapWildList::End <= value3) - throw(BoundsException(className(), "value3")); + error<BoundsException>("value3"); break; case B_Time: if (pokemod()->timeIndex(value3) == INT_MAX) - throw(BoundsException(className(), "value3")); + error<BoundsException>("value3"); break; case B_Stat: if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3) - throw(BoundsException(className(), "value3")); + error<BoundsException>("value3"); break; case B_Type: if (pokemod()->typeIndex(value3) == INT_MAX) - throw(BoundsException(className(), "value3")); + error<BoundsException>("value3"); break; case B_Regular: case B_Master: case B_Love: case B_Battle: - throw(UnusedException(className(), "value3")); + error<UnusedException>("value3"); break; } break; @@ -602,19 +602,19 @@ void ItemEffect::setValue3(const int value3) throw(Exception) { case B2_HPCure: if (Pokemod::REL_End <= value3) - throw(BoundsException(className(), "value3")); + error<BoundsException>("value3"); break; case B2_StatusCure: if (Pokemod::STS_End <= value3) - throw(BoundsException(className(), "value3")); + error<BoundsException>("value3"); break; default: - throw(UnusedException(className(), "value3")); + error<UnusedException>("value3"); break; } break; default: - throw(UnusedException(className(), "value3")); + error<UnusedException>("value3"); break; } m_value3 = value3; @@ -640,14 +640,14 @@ void ItemEffect::setValue4(const Fraction& value4) throw(Exception) case E_CoinCase: case E_Acorn: case E_Evolution: - throw(UnusedException(className(), "value4")); + error<UnusedException>("value4"); case E_Ball: if (m_value2 == B_Master) - throw(UnusedException(className(), "value4")); + error<UnusedException>("value4"); break; case E_Berry: if (m_value2 != B2_HPCure) - throw(UnusedException(className(), "value4")); + error<UnusedException>("value4"); break; } m_value4 = value4; diff --git a/pokemod/Map.cpp b/pokemod/Map.cpp index 7b577e14..5f1a0fd0 100644 --- a/pokemod/Map.cpp +++ b/pokemod/Map.cpp @@ -218,14 +218,14 @@ void Map::setName(const QString& name) void Map::setFlyWarp(const int warp) throw(BoundsException) { if ((warp != INT_MAX) && (warpIndex(warp) == INT_MAX)) - throw(BoundsException(className(), "warp")); + error<BoundsException>("warp"); m_flyWarp = warp; } void Map::setType(const int type) throw(BoundsException) { if (End <= type) - throw(BoundsException(className(), "type")); + error<BoundsException>("type"); m_type = type; } @@ -247,7 +247,7 @@ int Map::type() const void Map::setTile(int x, int y, int id) throw(BoundsException) { if (pokemod()->tileIndex(id) == INT_MAX) - throw(BoundsException(className(), "tile")); + error<BoundsException>("tile"); m_tile(x, y) = id; } @@ -309,7 +309,7 @@ int Map::height() const const MapEffect* Map::effect(const int index) const throw(IndexException) { if (effectCount() <= index) - error<IndexException>("effect"); + warning<IndexException>("effect"); return m_effects.at(index); } @@ -387,7 +387,7 @@ int Map::newEffectId() const const MapTrainer* Map::trainer(const int index) const throw(IndexException) { if (trainerCount() <= index) - error<IndexException>("trainer"); + warning<IndexException>("trainer"); return m_trainers.at(index); } @@ -465,7 +465,7 @@ int Map::newTrainerId() const const MapWarp* Map::warp(const int index) const throw(IndexException) { if (warpCount() <= index) - error<IndexException>("warp"); + warning<IndexException>("warp"); return m_warps.at(index); } @@ -543,7 +543,7 @@ int Map::newWarpId() const const MapWildList* Map::wildList(const int index) const throw(IndexException) { if (wildListCount() <= index) - error<IndexException>("wild list"); + warning<IndexException>("wild list"); return m_wildLists.at(index); } diff --git a/pokemod/MapEffect.cpp b/pokemod/MapEffect.cpp index f9f39a24..d17c0df2 100644 --- a/pokemod/MapEffect.cpp +++ b/pokemod/MapEffect.cpp @@ -39,7 +39,7 @@ MapEffect::MapEffect(const Pokemod* pokemod, const int id) : m_name(""), m_coordinate(0, 0), m_existFlag(0, 0), - m_skin(""), + m_skin(192, 128), m_effect(INT_MAX), m_value1(INT_MAX), m_value2(INT_MAX), @@ -168,16 +168,17 @@ void MapEffect::setExistFlag(const Flag& existFlag) m_existFlag = existFlag; } -void MapEffect::setSkin(const QPixmap& skin) throw(Exception) +void MapEffect::setSkin(const QPixmap& skin) throw(SizeException) { - // TODO: check size is 128x128 + if (skin.size() != QSize(192, 128)) + error<SizeException>("skin"); m_skin = skin; } void MapEffect::setEffect(const int effect) throw(BoundsException) { if (E_End <= effect) - throw(BoundsException(className(), "effect")); + error<BoundsException>("effect"); m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; @@ -186,7 +187,7 @@ void MapEffect::setEffect(const int effect) throw(BoundsException) void MapEffect::setValue1(const int value1) throw(UnusedException) { if ((m_effect != E_StrengthBlock) && (m_effect != E_Button)) - throw(UnusedException(className(), "val1")); + error<UnusedException>("val1"); m_value1 = value1; } @@ -196,19 +197,19 @@ void MapEffect::setValue2(const int value2) throw(Exception) { case E_Item: if (pokemod()->itemIndex(value2) == INT_MAX) - throw(BoundsException(className(), "val2")); + error<BoundsException>("val2"); break; case E_PC: if (PC_End <= value2) - throw(BoundsException(className(), "val2")); + error<BoundsException>("val2"); break; case E_StrengthBlock: case E_Button: if (Flag::End <= value2) - throw(BoundsException(className(), "val2")); + error<BoundsException>("val2"); break; default: - throw(UnusedException(className(), "val2")); + error<UnusedException>("val2"); break; } m_value2 = value2; @@ -217,7 +218,7 @@ void MapEffect::setValue2(const int value2) throw(Exception) void MapEffect::setDirection(const int direction) throw(BoundsException) { if (Pokemod::D_End_None <= direction) - throw(BoundsException(className(), "direction")); + error<BoundsException>("direction"); m_direction = direction; } @@ -234,7 +235,7 @@ void MapEffect::setCanMove(const bool canMove) void MapEffect::setDialog(const int dialog) throw(BoundsException) { if (pokemod()->dialogIndex(dialog) == INT_MAX) - throw(BoundsException(className(), "dialog")); + error<BoundsException>("dialog"); m_dialog = dialog; } diff --git a/pokemod/MapEffect.h b/pokemod/MapEffect.h index acbbbf55..e177dac3 100644 --- a/pokemod/MapEffect.h +++ b/pokemod/MapEffect.h @@ -71,7 +71,7 @@ class MapEffect : public Object void setName(const QString& name); void setCoordinate(const Point& coordinate); void setExistFlag(const Flag& existFlag); - void setSkin(const QPixmap& skin) throw(Exception); + void setSkin(const QPixmap& skin) throw(SizeException); void setEffect(const int effect) throw(BoundsException); void setValue1(const int value1) throw(UnusedException); void setValue2(const int value2) throw(Exception); diff --git a/pokemod/MapTrainer.cpp b/pokemod/MapTrainer.cpp index e64d6c16..217b8d2d 100644 --- a/pokemod/MapTrainer.cpp +++ b/pokemod/MapTrainer.cpp @@ -155,7 +155,7 @@ void MapTrainer::setName(const QString& name) void MapTrainer::setTrainerClass(const int trainerClass) throw(BoundsException) { if (pokemod()->trainerIndex(trainerClass) == INT_MAX) - throw(BoundsException(className(), "trainerClass")); + error<BoundsException>("trainerClass"); m_trainerClass = trainerClass; } @@ -172,14 +172,14 @@ void MapTrainer::setSight(const int sight) void MapTrainer::setDirection(const int direction) throw(BoundsException) { if (Pokemod::D_End_None <= direction) - throw(BoundsException(className(), "direction")); + error<BoundsException>("direction"); m_direction = direction; } void MapTrainer::setNumFight(const int numFight) throw(BoundsException) { if (!numFight || (pokemod()->rules()->maxFight() < numFight)) - throw(BoundsException(className(), "numFight")); + error<BoundsException>("numFight"); m_numFight = numFight; } @@ -191,14 +191,14 @@ void MapTrainer::setAppearFlag(const Flag& appearFlag) void MapTrainer::setDialog(const int dialog) throw(BoundsException) { if (pokemod()->dialogIndex(dialog) == INT_MAX) - throw(BoundsException(className(), "dialog")); + error<BoundsException>("dialog"); m_dialog = dialog; } void MapTrainer::setLeadTeamMember(const int leadMember) throw(BoundsException) { if (teamMemberCount() <= leadMember) - throw(BoundsException(className(), "leadTeamMember")); + error<BoundsException>("leadTeamMember"); m_leadTeamMember = leadMember; } @@ -250,7 +250,7 @@ int MapTrainer::leadTeamMember() const const MapTrainerTeamMember* MapTrainer::teamMember(const int index) const throw(IndexException) { if (teamMemberCount() <= index) - error<IndexException>("team member"); + warning<IndexException>("team member"); return m_teamMember.at(index); } diff --git a/pokemod/MapTrainerTeamMember.cpp b/pokemod/MapTrainerTeamMember.cpp index 2948faa7..1338f7b8 100644 --- a/pokemod/MapTrainerTeamMember.cpp +++ b/pokemod/MapTrainerTeamMember.cpp @@ -121,21 +121,21 @@ QDomElement MapTrainerTeamMember::save() const void MapTrainerTeamMember::setSpecies(const int species) throw(BoundsException) { if (pokemod()->speciesIndex(species) == INT_MAX) - throw(BoundsException(className(), "species")); + error<BoundsException>("species"); m_species = species; } void MapTrainerTeamMember::setLevel(const int level) throw(BoundsException) { if (pokemod()->rules()->maxLevel() < level) - throw(BoundsException(className(), "level")); + error<BoundsException>("level"); m_level = level; } void MapTrainerTeamMember::setItem(const int item, const bool state) throw(BoundsException) { if (pokemod()->itemIndex(item) == INT_MAX) - throw(BoundsException(className(), "item")); + error<BoundsException>("item"); if (state) { if (!m_items.contains(item)) @@ -148,7 +148,7 @@ void MapTrainerTeamMember::setItem(const int item, const bool state) throw(Bound void MapTrainerTeamMember::setNature(const int nature) throw(BoundsException) { if (!pokemod()->rules()->natureAllowed() || (pokemod()->natureIndex(nature) == INT_MAX)) - throw(BoundsException(className(), "nature")); + error<BoundsException>("nature"); m_nature = nature; } diff --git a/pokemod/MapWarp.cpp b/pokemod/MapWarp.cpp index 546984ff..0dc045e9 100644 --- a/pokemod/MapWarp.cpp +++ b/pokemod/MapWarp.cpp @@ -154,49 +154,49 @@ void MapWarp::setCoordinate(const Point& coordinate) void MapWarp::setFrom(const int direction, const bool can) throw(BoundsException) { if (Pokemod::D_End <= direction) - throw(BoundsException(className(), "direction")); + error<BoundsException>("direction"); m_from[direction] = can; } void MapWarp::setDirectionOut(const int directionOut) throw(BoundsException) { if (Pokemod::D_End <= directionOut) - throw(BoundsException(className(), "direction")); + error<BoundsException>("direction"); m_directionOut = directionOut; } void MapWarp::setWarpType(const int warpType) throw(BoundsException) { if (End <= warpType) - throw(BoundsException(className(), "warpType")); + error<BoundsException>("warpType"); m_warpType = warpType; } void MapWarp::setIsBiking(const int isBiking) throw(BoundsException) { if (Flag::End <= isBiking) - throw(BoundsException(className(), "isBiking")); + error<BoundsException>("isBiking"); m_isBiking = isBiking; } void MapWarp::setIsFlash(const int isFlash) throw(BoundsException) { if (Flag::End <= isFlash) - throw(BoundsException(className(), "isFlash")); + error<BoundsException>("isFlash"); m_isFlash = isFlash; } void MapWarp::setIsFoggy(const int isFoggy) throw(BoundsException) { if (Flag::End <= isFoggy) - throw(BoundsException(className(), "isFoggy")); + error<BoundsException>("isFoggy"); m_isFoggy = isFoggy; } void MapWarp::setToMap(const int toMap) throw(BoundsException) { if (pokemod()->mapIndex(toMap) == INT_MAX) - throw(BoundsException(className(), "toMap")); + error<BoundsException>("toMap"); m_toMap = toMap; m_toWarp = INT_MAX; } @@ -204,9 +204,9 @@ void MapWarp::setToMap(const int toMap) throw(BoundsException) void MapWarp::setToWarp(const int toWarp) throw(BoundsException) { if (pokemod()->mapIndex(m_toMap) == INT_MAX) - throw(BoundsException(className(), "toMap")); + error<BoundsException>("toMap"); if (pokemod()->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) - throw(BoundsException(className(), "toWarp")); + error<BoundsException>("toWarp"); m_toWarp = toWarp; } @@ -218,7 +218,7 @@ void MapWarp::setWorkingFlag(const Flag& workingFlag) void MapWarp::setDialog(const int dialog) throw(BoundsException) { if (pokemod()->dialogIndex(dialog) == INT_MAX) - throw(BoundsException(className(), "dialog")); + error<BoundsException>("dialog"); m_dialog = dialog; } @@ -235,7 +235,7 @@ Point MapWarp::coordinate() const bool MapWarp::from(const int direction) const throw(BoundsException) { if (Pokemod::D_End <= direction) - throw(BoundsException(className(), "direction")); + warning<BoundsException>("direction"); return m_from[direction]; } diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp index 07cd46ec..8679410f 100644 --- a/pokemod/MapWildList.cpp +++ b/pokemod/MapWildList.cpp @@ -161,7 +161,7 @@ QDomElement MapWildList::save() const void MapWildList::setControl(const int control) throw(BoundsException) { if (End <= control) - throw(BoundsException(className(), "control")); + error<BoundsException>("control"); m_control = control; m_value = INT_MAX; } @@ -169,7 +169,7 @@ void MapWildList::setControl(const int control) throw(BoundsException) void MapWildList::setValue(const int value) throw(Exception) { if (m_control != Fishing) - throw(UnusedException(className(), "value")); + error<UnusedException>("value"); bool ok = false; for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) { @@ -181,14 +181,14 @@ void MapWildList::setValue(const int value) throw(Exception) } } if (!ok) - throw(BoundsException(className(), "value")); + error<BoundsException>("value"); m_value = value; } void MapWildList::setTime(const int time, const bool state) throw(BoundsException) { if (pokemod()->timeIndex(time) == INT_MAX) - throw(BoundsException(className(), "time")); + error<BoundsException>("time"); if (state) { if (!m_times.contains(time)) @@ -213,7 +213,7 @@ void MapWildList::setScope(const int scope) throw(BoundsException) } } if (!ok) - throw(BoundsException(className(), "scope")); + error<BoundsException>("scope"); } m_scope = scope; } @@ -241,7 +241,7 @@ int MapWildList::scope() const const MapWildListEncounter* MapWildList::encounter(const int index) const throw(IndexException) { if (encounterCount() <= index) - error<IndexException>("encounter"); + warning<IndexException>("encounter"); return m_encounters.at(index); } diff --git a/pokemod/MapWildListEncounter.cpp b/pokemod/MapWildListEncounter.cpp index a90b6515..1fde361c 100644 --- a/pokemod/MapWildListEncounter.cpp +++ b/pokemod/MapWildListEncounter.cpp @@ -90,21 +90,21 @@ QDomElement MapWildListEncounter::save() const void MapWildListEncounter::setSpecies(const int species) throw(BoundsException) { if (pokemod()->speciesIndex(species) == INT_MAX) - throw(BoundsException(className(), "species")); + error<BoundsException>("species"); m_species = species; } void MapWildListEncounter::setLevel(const int level) throw(BoundsException) { if (!level || (pokemod()->rules()->maxLevel() <= level)) - throw(BoundsException(className(), "level")); + error<BoundsException>("level"); m_level = level; } void MapWildListEncounter::setWeight(const int weight) throw(BoundsException) { if (!weight) - throw(BoundsException(className(), "weight")); + error<BoundsException>("weight"); m_weight = weight; } diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index 21611be8..0ea33bc3 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -185,7 +185,7 @@ void Move::setPower(const int power) void Move::setType(const int type) throw(BoundsException) { if (pokemod()->typeIndex(type) == INT_MAX) - throw(BoundsException(className(), "type")); + error<BoundsException>("type"); m_type = type; } @@ -197,28 +197,28 @@ void Move::setSpecial(const bool special) void Move::setPowerPoints(const int powerPoints) throw(BoundsException) { if (!powerPoints) - throw(BoundsException(className(), "powerPoints")); + error<BoundsException>("powerPoints"); m_powerPoints = powerPoints; } void Move::setTarget(const int target) throw(BoundsException) { if (T_End <= target) - throw(BoundsException(className(), "target")); + error<BoundsException>("target"); m_target = target; } void Move::setNumTargets(const int numTargets) throw(BoundsException) { if (!numTargets || ((pokemod()->rules()->maxFight() * ((m_target == T_All) ? pokemod()->rules()->maxPlayers() : 1)) < numTargets)) - throw(BoundsException(className(), "numTargets")); + error<BoundsException>("numTargets"); m_numTargets = numTargets; } void Move::setTargetChoice(const int targetChoice) throw(BoundsException) { if (C_End <= targetChoice) - throw(BoundsException(className(), "targetChoice")); + error<BoundsException>("targetChoice"); m_targetChoice = targetChoice; } @@ -330,7 +330,7 @@ QString Move::description() const const MoveEffect* Move::effect(const int index) const throw(IndexException) { if (effectCount() <= index) - error<IndexException>("effect"); + warning<IndexException>("effect"); return m_effects.at(index); } diff --git a/pokemod/MoveEffect.cpp b/pokemod/MoveEffect.cpp index e267337b..8633b549 100644 --- a/pokemod/MoveEffect.cpp +++ b/pokemod/MoveEffect.cpp @@ -91,7 +91,7 @@ void MoveEffect::setChance(const Fraction& chance) throw(Exception) void MoveEffect::setEffect(const int effect) throw(BoundsException) { if (E_End <= effect) - throw(BoundsException(className(), "effect")); + error<BoundsException>("effect"); m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; @@ -105,28 +105,28 @@ void MoveEffect::setValue1(const int value1) throw(Exception) { case E_Damage: if (D_End <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_Status: case E_NeedStatus: if (Pokemod::STS_End <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); throw; case E_Stat: if (Pokemod::ST_End_Battle <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_Counter: case E_Shield: if (MT_End <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case E_Recoil: if (R_End <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; default: - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; } m_value1 = value1; @@ -138,10 +138,10 @@ void MoveEffect::setValue2(const int value2) throw(Exception) { case E_Damage: if ((D_Level <= m_value1) || !value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; default: - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; } m_value2 = value2; diff --git a/pokemod/Nature.cpp b/pokemod/Nature.cpp index 7f84286e..85fd45ea 100644 --- a/pokemod/Nature.cpp +++ b/pokemod/Nature.cpp @@ -90,14 +90,14 @@ void Nature::setName(const QString& name) void Nature::setStat(const int stat, const Fraction& multiplier) throw(Exception) { if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) - throw(BoundsException(className(), "stat")); + error<BoundsException>("stat"); m_stat[stat] = multiplier; } void Nature::setWeight(const int weight) throw(BoundsException) { if (!weight) - throw(BoundsException(className(), "weight")); + error<BoundsException>("weight"); m_weight = weight; } @@ -109,7 +109,7 @@ QString Nature::name() const Fraction Nature::stat(const int stat) const throw(BoundsException) { if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) - throw(BoundsException(className(), "stat")); + warning<BoundsException>("stat"); return m_stat[stat]; } diff --git a/pokemod/Object.cpp b/pokemod/Object.cpp deleted file mode 100644 index 2460b072..00000000 --- a/pokemod/Object.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -// Pokemod includes -#include "Pokemod.h" - -// Header include -#include "Object.h" - -template<class T> void Object::warning(const QString& msg) const throw(Exception) -{ - throw(T(m_className, msg)); -} - -template<class T> void Object::error(const QString& msg) const throw(Exception) -{ - m_valid = false; - warning<T>(msg); -} diff --git a/pokemod/Object.h b/pokemod/Object.h index 8dd29da9..c3234dc8 100644 --- a/pokemod/Object.h +++ b/pokemod/Object.h @@ -19,6 +19,7 @@ #define __POKEMOD_OBJECT__ // Qt includes +#include <QDomDocument> #include <QDomElement> // General includes @@ -30,13 +31,13 @@ class Pokemod; class Object { public: - Object(const Object& object) : + inline Object(const Object& object) : m_id(object.id()), m_className(object.className()), m_pokemod(object.pokemod()) { } - Object(const QString& className, const Pokemod* pokemod, const int id) : + inline Object(const QString& className, const Pokemod* pokemod, const int id) : m_id(id), m_className(className), m_pokemod(pokemod) @@ -46,7 +47,7 @@ class Object { } virtual void load(const QDomElement& xml, int id = INT_MAX) = 0; - virtual QDomElement save() const; + virtual QDomElement save() const = 0; inline const Pokemod* pokemod() const { @@ -78,8 +79,15 @@ class Object m_id = id; } virtual bool validate() const = 0; - template<class T> void warning(const QString& msg) const throw(Exception); - template<class T> void error(const QString& msg) const throw(Exception); + template<class T> inline void warning(const QString& message) const throw(T) + { + throw(T(m_className, message)); + } + template<class T> inline void error(const QString& message) throw(T) + { + m_valid = false; + warning<T>(message); + } virtual void clear() = 0; private: int m_id; @@ -89,7 +97,7 @@ class Object }; #define LOAD_NODE(variable) xml.firstChildElement(variable) -#define LOAD_DATA(node) node.nodeValue() +#define LOAD_DATA(node) node.firstChild().toText().data() #define LOAD_ID() \ if (id == INT_MAX) \ id = xml.attribute("id", "-1").toInt(); \ @@ -147,17 +155,16 @@ class Object } #define SAVE_CREATE() \ - QDomElement xml; \ - xml.setTagName(className()); \ + QDomElement xml = QDomDocument().createElement(className()); \ xml.setAttribute("id", id()) +#define SAVE_VALUE(element, value) element.appendChild(QDomDocument().createTextNode(value)) #define SAVE(type, variable) \ - QDomElement xml_##variable; \ - xml_##variable.setTagName(#variable); \ + QDomElement xml_##variable = QDomDocument().createElement(#variable); \ SAVE_##type(variable, variable()); \ xml.appendChild(xml_##variable) -#define SAVE_bool(variable, value) xml_##variable.setNodeValue(value ? "true" : "false") -#define SAVE_int(variable, value) xml_##variable.setNodeValue(QString::number(value)) -#define SAVE_QString(variable, value) xml_##variable.setNodeValue(value) +#define SAVE_bool(variable, value) SAVE_VALUE(xml_##variable, value ? "true" : "false") +#define SAVE_int(variable, value) SAVE_VALUE(xml_##variable, QString::number(value)) +#define SAVE_QString(variable, value) SAVE_VALUE(xml_##variable, value) #define SAVE_Fraction(variable, value) \ Fraction frac_##variable = value; \ xml_##variable.setAttribute("numerator", frac_##variable.numerator()); \ @@ -171,46 +178,40 @@ class Object xml_##variable.setAttribute("x", point_##variable.x()); \ xml_##variable.setAttribute("y", point_##variable.y()) #define SAVE_QPixmap(variable, value) \ - QPixmap pixmap_##variable; \ QByteArray bytes_##variable; \ QBuffer buffer_##variable(&bytes_##variable); \ buffer_##variable.open(QIODevice::WriteOnly); \ - value.save(&buffer_##variable, "PNG") + value.save(&buffer_##variable, "PNG"); \ + SAVE_VALUE(xml_##variable, bytes_##variable.toBase64()) #define SAVE_ARRAY(type, variable, size) \ - QDomElement xml_array_##variable; \ - xml_array_##variable.setTagName(#variable); \ + QDomElement xml_array_##variable = QDomDocument().createElement(#variable); \ for (int i = 0; i < size; ++i) \ { \ - QDomElement xml_##variable; \ - xml_##variable.setTagName("element"); \ + QDomElement xml_##variable = QDomDocument().createElement("element"); \ xml_##variable.setAttribute("index", QString::number(i)); \ SAVE_##type(variable, variable(i)); \ xml_array_##variable.appendChild(xml_##variable); \ } \ xml.appendChild(xml_array_##variable) #define SAVE_LIST(type, variable) \ - QDomElement xml_list_##variable; \ - xml_list_##variable.setTagName(#variable); \ + QDomElement xml_list_##variable = QDomDocument().createElement(#variable); \ xml_list_##variable.setAttribute("size", m_##variable.size()); \ for (int i = 0; i < m_##variable.size(); ++i) \ { \ - QDomElement xml_##variable; \ - xml_##variable.setTagName("element"); \ + QDomElement xml_##variable = QDomDocument().createElement("element"); \ SAVE_##type(variable, m_##variable[i]); \ xml_list_##variable.appendChild(xml_##variable); \ } \ xml.appendChild(xml_list_##variable) #define SAVE_MATRIX(type, variable) \ - QDomElement xml_matrix_##variable; \ - xml_matrix_##variable.setTagName(#variable); \ + QDomElement xml_matrix_##variable = QDomDocument().createElement(#variable); \ xml_matrix_##variable.setAttribute("height", m_##variable.height()); \ xml_matrix_##variable.setAttribute("width", m_##variable.width()); \ for (int i = 0; i < m_##variable.height(); ++i) \ { \ for (int j = 0; j < m_##variable.width(); ++j) \ { \ - QDomElement xml_##variable; \ - xml_##variable.setTagName("element"); \ + QDomElement xml_##variable = QDomDocument().createElement("element"); \ xml_##variable.setAttribute("row", QString::number(i)); \ xml_##variable.setAttribute("column", QString::number(j)); \ SAVE_##type(variable, variable(i, j)); \ diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp index b5cc1cc5..bed4f017 100644 --- a/pokemod/Pokemod.cpp +++ b/pokemod/Pokemod.cpp @@ -61,6 +61,12 @@ Pokemod::Pokemod() : m_description(""), m_startMap(INT_MAX), m_startWarp(INT_MAX), + m_walkSkin(192, 128), + m_bikeSkin(192, 128), + m_surfSkin(192, 128), + m_flySkin(192, 128), + m_fishSkin(192, 128), + m_surfFishSkin(), m_superPCUname(""), m_superPCPasswd(""), m_typeChart(0, 0),//, Fraction(1, 1, Fraction::Improper)), @@ -409,8 +415,7 @@ void Pokemod::load(const QDomElement& xml, const int) throw(Exception) QDomElement Pokemod::save() const { - QDomElement xml; - xml.setTagName(className()); + QDomElement xml = QDomDocument().createElement(className()); SAVE(QString, title); SAVE(QString, version); SAVE(QString, description); @@ -451,13 +456,13 @@ int Pokemod::maxCompatability(const Pokemod& pokemod) const // TODO: MaxCompatability between two versions } -void Pokemod::validationMsg(const QString& msg, Validation val) const throw(Exception) +void Pokemod::validationMsg(const QString& message, const Validation level) const throw(Exception) { if (!valOutput) throw(Exception(className(), "valOutput isn\'t set")); - if (V_End < val) - throw(BoundsException(className(), "val")); - (*valOutput) << ValidationStr[val] << QDateTime::currentDateTime().toString(" (yyyyMMdd hh:mm:ss.zzz ddd): ") << msg; + if (V_End < level) + warning<BoundsException>("level"); + (*valOutput) << ValidationStr[level] << QDateTime::currentDateTime().toString(" (yyyyMMdd hh:mm:ss.zzz ddd): ") << message; } void Pokemod::setValOutput(QStringList& s) @@ -488,52 +493,58 @@ void Pokemod::setDescription(const QString& description) void Pokemod::setStartMap(const int startMap) throw(BoundsException) { if (mapIndex(startMap) == INT_MAX) - throw(BoundsException(className(), "startMap")); + error<BoundsException>("startMap"); m_startMap = startMap; } void Pokemod::setStartWarp(const int startWarp) throw(BoundsException) { if (mapIndex(m_startMap) == INT_MAX) - throw(BoundsException(className(), "startMap")); + error<BoundsException>("startMap"); if (mapById(m_startMap)->warpIndex(startWarp) == INT_MAX) - throw(BoundsException(className(), "startWarp")); + error<BoundsException>("startWarp"); m_startWarp = startWarp; } -void Pokemod::setWalkSkin(const QPixmap& walkSkin) throw(Exception) +void Pokemod::setWalkSkin(const QPixmap& walkSkin) throw(SizeException) { - // TODO: check dimensions + if (walkSkin.size() != QSize(192, 128)) + error<SizeException>("walkSkin"); m_walkSkin = walkSkin; } -void Pokemod::setBikeSkin(const QPixmap& bikeSkin) throw(Exception) +void Pokemod::setBikeSkin(const QPixmap& bikeSkin) throw(SizeException) { - // TODO: check dimensions + if (bikeSkin.size() != QSize(192, 128)) + error<SizeException>("bikeSkin"); m_bikeSkin = bikeSkin; } -void Pokemod::setSurfSkin(const QPixmap& surfSkin) throw(Exception) +void Pokemod::setSurfSkin(const QPixmap& surfSkin) throw(SizeException) { - // TODO: check dimensions + if (surfSkin.size() != QSize(192, 128)) + error<SizeException>("surfSkin"); m_surfSkin = surfSkin; } -void Pokemod::setFlySkin(const QPixmap& flySkin) throw(Exception) +void Pokemod::setFlySkin(const QPixmap& flySkin) throw(SizeException) { - // TODO: check dimensions + if (flySkin.size() != QSize(192, 128)) + error<SizeException>("flySkin"); m_flySkin = flySkin; } -void Pokemod::setFishSkin(const QPixmap& fishSkin) throw(Exception) +void Pokemod::setFishSkin(const QPixmap& fishSkin) throw(SizeException) { - // TODO: check dimensions + if (fishSkin.size() != QSize(192, 128)) + error<SizeException>("fishSkin"); m_fishSkin = fishSkin; } -void Pokemod::setSurfFishSkin(const QPixmap& surfFishSkin) throw(Exception) +void Pokemod::setSurfFishSkin(const QPixmap& surfFishSkin) throw(SizeException) { - // TODO: check dimensions + if (surfFishSkin.size() != QSize(192, 128)) + error<SizeException>("surfFishSkin"); m_surfFishSkin = surfFishSkin; } @@ -655,7 +666,7 @@ Rules* Pokemod::rules() const Ability* Pokemod::ability(const int index) const throw(IndexException) { if (abilityCount() <= index) - error<IndexException>("ability"); + warning<IndexException>("ability"); return m_abilities.at(index); } @@ -733,7 +744,7 @@ int Pokemod::newAbilityId() const const Author* Pokemod::author(const int index) const throw(IndexException) { if (authorCount() <= index) - error<IndexException>("author"); + warning<IndexException>("author"); return m_authors.at(index); } @@ -811,7 +822,7 @@ int Pokemod::newAuthorId() const const Badge* Pokemod::badge(const int index) const throw(IndexException) { if (badgeCount() <= index) - error<IndexException>("badge"); + warning<IndexException>("badge"); return m_badges.at(index); } @@ -889,7 +900,7 @@ int Pokemod::newBadgeId() const const CoinList* Pokemod::coinList(const int index) const throw(IndexException) { if (coinListCount() <= index) - error<IndexException>("coin list"); + warning<IndexException>("coin list"); return m_coinLists.at(index); } @@ -967,7 +978,7 @@ int Pokemod::newCoinListId() const const Dialog* Pokemod::dialog(const int index) const throw(IndexException) { if (dialogCount() <= index) - error<IndexException>("dialog"); + warning<IndexException>("dialog"); return m_dialogs.at(index); } @@ -1045,7 +1056,7 @@ int Pokemod::newDialogId() const const EggGroup* Pokemod::eggGroup(const int index) const throw(IndexException) { if (eggGroupCount() <= index) - error<IndexException>("egg group"); + warning<IndexException>("egg group"); return m_eggGroups.at(index); } @@ -1123,7 +1134,7 @@ int Pokemod::newEggGroupId() const const Item* Pokemod::item(const int index) const throw(IndexException) { if (itemCount() <= index) - error<IndexException>("item"); + warning<IndexException>("item"); return m_items.at(index); } @@ -1201,7 +1212,7 @@ int Pokemod::newItemId() const const ItemType* Pokemod::itemType(const int index) const throw(IndexException) { if (itemTypeCount() <= index) - error<IndexException>("item type"); + warning<IndexException>("item type"); return m_itemTypes.at(index); } @@ -1279,7 +1290,7 @@ int Pokemod::newItemTypeId() const const Map* Pokemod::map(const int index) const throw(IndexException) { if (mapCount() <= index) - error<IndexException>("map"); + warning<IndexException>("map"); return m_maps.at(index); } @@ -1357,7 +1368,7 @@ int Pokemod::newMapId() const const Move* Pokemod::move(const int index) const throw(IndexException) { if (moveCount() <= index) - error<IndexException>("move"); + warning<IndexException>("move"); return m_moves.at(index); } @@ -1435,7 +1446,7 @@ int Pokemod::newMoveId() const const Nature* Pokemod::nature(const int index) const throw(IndexException) { if (natureCount() <= index) - error<IndexException>("nature"); + warning<IndexException>("nature"); return m_natures.at(index); } @@ -1513,7 +1524,7 @@ int Pokemod::newNatureId() const const Species* Pokemod::species(const int index) const throw(IndexException) { if (speciesCount() <= index) - error<IndexException>("species"); + warning<IndexException>("species"); return m_species.at(index); } @@ -1591,7 +1602,7 @@ int Pokemod::newSpeciesId() const const Store* Pokemod::store(const int index) const throw(IndexException) { if (storeCount() <= index) - error<IndexException>("store"); + warning<IndexException>("store"); return m_stores.at(index); } @@ -1669,7 +1680,7 @@ int Pokemod::newStoreId() const const Tile* Pokemod::tile(const int index) const throw(IndexException) { if (tileCount() <= index) - error<IndexException>("tile"); + warning<IndexException>("tile"); return m_tiles.at(index); } @@ -1747,7 +1758,7 @@ int Pokemod::newTileId() const const Time* Pokemod::time(const int index) const throw(IndexException) { if (timeCount() <= index) - error<IndexException>("time"); + warning<IndexException>("time"); return m_times.at(index); } @@ -1825,7 +1836,7 @@ int Pokemod::newTimeId() const const Trainer* Pokemod::trainer(const int index) const throw(IndexException) { if (trainerCount() <= index) - error<IndexException>("trainer"); + warning<IndexException>("trainer"); return m_trainers.at(index); } @@ -1903,7 +1914,7 @@ int Pokemod::newTrainerId() const const Type* Pokemod::type(const int index) const throw(IndexException) { if (typeCount() <= index) - error<IndexException>("type"); + warning<IndexException>("type"); return m_types.at(index); } diff --git a/pokemod/Pokemod.h b/pokemod/Pokemod.h index ff771269..45aa1fdd 100644 --- a/pokemod/Pokemod.h +++ b/pokemod/Pokemod.h @@ -180,12 +180,12 @@ class Pokemod : public Object void setDescription(const QString& description); void setStartMap(const int startMap) throw(BoundsException); void setStartWarp(const int startWarp) throw(BoundsException); - void setWalkSkin(const QPixmap& walkSkin) throw(Exception); - void setBikeSkin(const QPixmap& bikeSkin) throw(Exception); - void setSurfSkin(const QPixmap& surfSkin) throw(Exception); - void setFlySkin(const QPixmap& slySkin) throw(Exception); - void setFishSkin(const QPixmap& fishSkin) throw(Exception); - void setSurfFishSkin(const QPixmap& surfFishSkin) throw(Exception); + void setWalkSkin(const QPixmap& walkSkin) throw(SizeException); + void setBikeSkin(const QPixmap& bikeSkin) throw(SizeException); + void setSurfSkin(const QPixmap& surfSkin) throw(SizeException); + void setFlySkin(const QPixmap& slySkin) throw(SizeException); + void setFishSkin(const QPixmap& fishSkin) throw(SizeException); + void setSurfFishSkin(const QPixmap& surfFishSkin) throw(SizeException); void setSuperPCUname(const QString& username); void setSuperPCPasswd(const QString& password); void setTypeChart(const int attack, const int defense, const Fraction& multiplier) throw(Exception); diff --git a/pokemod/Rules.cpp b/pokemod/Rules.cpp index dfc940c9..ab4b465e 100644 --- a/pokemod/Rules.cpp +++ b/pokemod/Rules.cpp @@ -156,8 +156,7 @@ void Rules::load(const QDomElement& xml, const int) throw(Exception) QDomElement Rules::save() const { - QDomElement xml; - xml.setTagName(className()); + QDomElement xml = QDomDocument().createElement(className()); SAVE(bool, genderAllowed); SAVE(bool, breedingAllowed); SAVE(int, holdItems); @@ -230,7 +229,7 @@ void Rules::setBoxSize(const int boxSize) void Rules::setMaxParty(const int maxParty) throw(BoundsException) { if (!maxParty) - throw(BoundsException(className(), "maxParty")); + error<BoundsException>("maxParty"); m_maxParty = maxParty; if (maxParty < m_maxFight) setMaxFight(maxParty); @@ -239,28 +238,28 @@ void Rules::setMaxParty(const int maxParty) throw(BoundsException) void Rules::setMaxFight(const int maxFight) throw(BoundsException) { if (m_maxParty < maxFight) - throw(BoundsException(className(), "maxFight")); + error<BoundsException>("maxFight"); m_maxFight = maxFight; } void Rules::setMaxPlayers(const int maxPlayers) throw(BoundsException) { if (!maxPlayers) - throw(BoundsException(className(), "maxPlayers")); + error<BoundsException>("maxPlayers"); m_maxPlayers = maxPlayers; } void Rules::setMaxMoves(const int maxMoves) throw(BoundsException) { if (!maxMoves) - throw(BoundsException(className(), "maxMoves")); + error<BoundsException>("maxMoves"); m_maxMoves = maxMoves; } void Rules::setMaxLevel(const int maxLevel) throw(BoundsException) { if (!maxLevel) - throw(BoundsException(className(), "maxLevel")); + error<BoundsException>("maxLevel"); m_maxLevel = maxLevel; } @@ -289,7 +288,7 @@ void Rules::setSpecialDVSplit(const bool specialDVSplit) void Rules::setMaxDVValue(const unsigned char maxDVValue) throw(BoundsException) { if (1 < maxDVValue) - throw(BoundsException(className(), "maxDVValue")); + error<BoundsException>("maxDVValue"); m_maxDVValue = maxDVValue; } @@ -321,7 +320,7 @@ void Rules::setEffortValuesAllowed(const bool effortValuesAllowed) void Rules::setMaxTotalEV(const int maxTotalEV) throw(BoundsException) { if (!maxTotalEV) - throw(BoundsException(className(), "maxTotalEV")); + error<BoundsException>("maxTotalEV"); m_maxTotalEV = maxTotalEV; if (maxTotalEV < m_maxEVPerStat) setMaxEVPerStat(maxTotalEV); @@ -330,7 +329,7 @@ void Rules::setMaxTotalEV(const int maxTotalEV) throw(BoundsException) void Rules::setMaxEVPerStat(const int maxEVPerStat) throw(BoundsException) { if (!maxEVPerStat || (m_maxTotalEV < maxEVPerStat)) - throw(BoundsException(className(), "maxEVPerStat")); + error<BoundsException>("maxEVPerStat"); m_maxEVPerStat = maxEVPerStat; } diff --git a/pokemod/Species.cpp b/pokemod/Species.cpp index 34141db4..6156148b 100644 --- a/pokemod/Species.cpp +++ b/pokemod/Species.cpp @@ -49,6 +49,11 @@ Species::Species(const Pokemod* pokemod, const int id) : m_weight(0), m_heightFeet(0), m_heightInches(0), + m_frontMaleSprite(128, 128), + m_backMaleSprite(128, 128), + m_frontFemaleSprite(128, 128), + m_backFemaleSprite(128, 128), + m_listSprite(64, 128), m_pokedexEntry(""), m_genderFactor(1, 1), m_eggSpecies(INT_MAX), @@ -289,7 +294,7 @@ void Species::setName(const QString& name) void Species::setBaseStat(const int stat, const int baseStat) throw(BoundsException) { if ((Pokemod::ST_End_RBY <= stat) || ((stat == Pokemod::ST_SpecialDefense) && !pokemod()->rules()->specialSplit())) - throw(BoundsException(className(), "stat")); + error<BoundsException>("stat"); m_baseStat[stat] = baseStat; } @@ -298,16 +303,16 @@ void Species::setEffortValue(const int stat, const int effortValue) throw(Except if (!pokemod()->rules()->effortValuesAllowed()) throw(Exception(className(), "effortValues not allowed")); if (pokemod()->rules()->maxEVPerStat() < effortValue) - throw(BoundsException(className(), "effortValue")); + error<BoundsException>("effortValue"); if ((Pokemod::ST_End_RBY <= stat) || ((stat == Pokemod::ST_SpecialDefense) && !pokemod()->rules()->specialSplit())) - throw(BoundsException(className(), "stat")); + error<BoundsException>("stat"); m_effortValue[stat] = effortValue; } void Species::setGrowth(const int growth) throw(BoundsException) { if (End <= growth) - throw(BoundsException(className(), "growth")); + error<BoundsException>("growth"); m_growth = growth; } @@ -356,7 +361,7 @@ void Species::setHeightFeet(const int feet) void Species::setHeightInches(const int inches) throw(BoundsException) { if (12 <= inches) - throw(BoundsException(className(), "heightInches")); + error<BoundsException>("heightInches"); m_heightInches = inches; } @@ -367,15 +372,19 @@ void Species::setPokedexEntry(const QString& pokedexEntry) void Species::setFrontMaleSprite(const QPixmap& frontMaleSprite) throw(Exception) { - // TODO: gender chance check - // TODO: dimension check + if (m_genderFactor.numerator() == m_genderFactor.denominator()) + error<Exception>("cannot be male"); + if (frontMaleSprite.size() != QSize(128, 128)) + error<SizeException>("frontMaleSprite"); m_frontMaleSprite = frontMaleSprite; } void Species::setBackMaleSprite(const QPixmap& backMaleSprite) throw(Exception) { - // TODO: gender chance check - // TODO: dimension check + if (m_genderFactor.numerator() == m_genderFactor.denominator()) + error<Exception>("cannot be male"); + if (backMaleSprite.size() != QSize(128, 128)) + error<SizeException>("backMaleSprite"); m_backMaleSprite = backMaleSprite; } @@ -383,8 +392,10 @@ void Species::setFrontFemaleSprite(const QPixmap& frontFemaleSprite) throw(Excep { if (!pokemod()->rules()->genderAllowed()) throw(Exception(className(), "gender is not allowed")); - // TODO: gender chance check - // TODO: dimension check + if (!m_genderFactor.numerator()) + error<Exception>("cannot be female"); + if (frontFemaleSprite.size() != QSize(128, 128)) + error<SizeException>("frontFemaleSprite"); m_frontFemaleSprite = frontFemaleSprite; } @@ -392,14 +403,17 @@ void Species::setBackFemaleSprite(const QPixmap& backFemaleSprite) throw(Excepti { if (!pokemod()->rules()->genderAllowed()) throw(Exception(className(), "gender is not allowed")); - // TODO: gender chance check - // TODO: dimension check + if (!m_genderFactor.numerator()) + error<Exception>("cannot be female"); + if (backFemaleSprite.size() != QSize(128, 128)) + error<SizeException>("backFemaleSprite"); m_backFemaleSprite = backFemaleSprite; } -void Species::setListSprite(const QPixmap& listSprite) throw(Exception) +void Species::setListSprite(const QPixmap& listSprite) throw(SizeException) { - // TODO: dimension check + if (listSprite.size() != QSize(64, 128)) + error<SizeException>("listSprite"); m_listSprite = listSprite; } @@ -411,7 +425,7 @@ void Species::setGenderFactor(const Fraction& genderFactor) throw(Exception) void Species::setEggSpecies(const int eggSpecies) throw(BoundsException) { if (pokemod()->speciesIndex(eggSpecies) == INT_MAX) - throw(BoundsException(className(), "eggSpecies")); + error<BoundsException>("eggSpecies"); m_eggSpecies = eggSpecies; } @@ -428,7 +442,7 @@ void Species::setNidoranGroup(const int nidoranGroup) void Species::setType(const int type, const bool state) throw(Exception) { if (pokemod()->typeIndex(type) == INT_MAX) - throw(BoundsException(className(), "type")); + error<BoundsException>("type"); if (state) { if (!m_types.contains(type)) @@ -441,7 +455,7 @@ void Species::setType(const int type, const bool state) throw(Exception) void Species::setEggGroup(const int eggGroup, const bool state) throw(Exception) { if (pokemod()->eggGroupIndex(eggGroup) == INT_MAX) - throw(BoundsException(className(), "eggGroup")); + error<BoundsException>("eggGroup"); if (state) { if (!m_types.contains(eggGroup)) @@ -459,14 +473,14 @@ QString Species::name() const int Species::baseStat(const int stat) const throw(BoundsException) { if ((Pokemod::ST_End_RBY <= stat) || ((stat == Pokemod::ST_SpecialDefense) && !pokemod()->rules()->specialSplit())) - throw(BoundsException(className(), "stat")); + warning<BoundsException>("stat"); return m_baseStat[stat]; } int Species::effortValue(const int stat) const throw(BoundsException) { if ((Pokemod::ST_End_RBY <= stat) || ((stat == Pokemod::ST_SpecialDefense) && !pokemod()->rules()->specialSplit())) - throw(BoundsException(className(), "stat")); + warning<BoundsException>("stat"); return m_effortValue[stat]; } @@ -583,7 +597,7 @@ bool Species::eggGroup(const int eggGroup) const const SpeciesAbility* Species::ability(const int index) const throw(IndexException) { if (abilityCount() <= index) - error<IndexException>("ability"); + warning<IndexException>("ability"); return m_abilities.at(index); } @@ -661,7 +675,7 @@ int Species::newAbilityId() const const SpeciesEvolution* Species::evolution(const int index) const throw(IndexException) { if (evolutionCount() <= index) - error<IndexException>("evolution"); + warning<IndexException>("evolution"); return m_evolutions.at(index); } @@ -739,7 +753,7 @@ int Species::newEvolutionId() const const SpeciesItem* Species::item(const int index) const throw(IndexException) { if (itemCount() <= index) - error<IndexException>("item"); + warning<IndexException>("item"); return m_items.at(index); } @@ -817,7 +831,7 @@ int Species::newItemId() const const SpeciesMove* Species::move(const int index) const throw(IndexException) { if (moveCount() <= index) - error<IndexException>("move"); + warning<IndexException>("move"); return m_moves.at(index); } diff --git a/pokemod/Species.h b/pokemod/Species.h index 58e082dd..3bddf08d 100644 --- a/pokemod/Species.h +++ b/pokemod/Species.h @@ -79,7 +79,7 @@ class Species : public Object void setBackMaleSprite(const QPixmap& backMaleSprite) throw(Exception); void setFrontFemaleSprite(const QPixmap& frontFemaleSprite) throw(Exception); void setBackFemaleSprite(const QPixmap& backFemaleSprite) throw(Exception); - void setListSprite(const QPixmap& listSprite) throw(Exception); + void setListSprite(const QPixmap& listSprite) throw(SizeException); void setGenderFactor(const Fraction& genderFactor) throw(Exception); void setEggSpecies(const int eggSpecies) throw(BoundsException); void setEggSteps(const int eggSteps); diff --git a/pokemod/SpeciesAbility.cpp b/pokemod/SpeciesAbility.cpp index 0dda3ccf..488c2d62 100644 --- a/pokemod/SpeciesAbility.cpp +++ b/pokemod/SpeciesAbility.cpp @@ -81,14 +81,14 @@ QDomElement SpeciesAbility::save() const void SpeciesAbility::setAbility(const int ability) throw(BoundsException) { if (pokemod()->abilityIndex(ability) == INT_MAX) - throw(BoundsException(className(), "ability")); + error<BoundsException>("ability"); m_ability = ability; } void SpeciesAbility::setWeight(const int weight) throw(BoundsException) { if (!weight) - throw(BoundsException(className(), "weight")); + error<BoundsException>("weight"); m_weight = weight; } diff --git a/pokemod/SpeciesEvolution.cpp b/pokemod/SpeciesEvolution.cpp index 62df543b..77ab032e 100644 --- a/pokemod/SpeciesEvolution.cpp +++ b/pokemod/SpeciesEvolution.cpp @@ -148,14 +148,14 @@ QDomElement SpeciesEvolution::save() const void SpeciesEvolution::setSpecies(const int species) throw(BoundsException) { if (pokemod()->speciesIndex(species) == INT_MAX) - throw(BoundsException(className(), "species")); + error<BoundsException>("species"); m_species = species; } void SpeciesEvolution::setStyle(const int style) throw(BoundsException) { if (S_End <= style) - throw(BoundsException(className(), "style")); + error<BoundsException>("style"); m_style = style; } @@ -168,19 +168,19 @@ void SpeciesEvolution::setValue1(const int value1) throw(Exception) case S_Stat: case S_Personality: if (Pokemod::REL_End <= value1) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; case S_Item: case S_TradeItem: if (pokemod()->itemIndex(value1) == INT_MAX) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); for (int i = 0; (i < pokemod()->itemById(value1)->effectCount()) && !ok; ++i) ok = (pokemod()->itemById(value1)->effect(i)->effect() == ItemEffect::E_Evolution); if (!ok) - throw(BoundsException(className(), "value1")); + error<BoundsException>("value1"); break; default: - throw(UnusedException(className(), "value1")); + error<UnusedException>("value1"); break; } m_value1 = value1; @@ -192,13 +192,13 @@ void SpeciesEvolution::setValue2(const int value2) throw(Exception) { case S_Stat: if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value2) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); case S_Item: if ((G_End <= value2) || ((value2 == G_Hold) && !pokemod()->rules()->holdItems())) - throw(BoundsException(className(), "value2")); + error<BoundsException>("value2"); break; default: - throw(UnusedException(className(), "value2")); + error<UnusedException>("value2"); break; } m_value2 = value2; @@ -213,7 +213,7 @@ void SpeciesEvolution::setValue3(const int value3) throw(UnusedException) case S_Personality: break; default: - throw(UnusedException(className(), "value3")); + error<UnusedException>("value3"); break; } m_value3 = value3; @@ -222,7 +222,7 @@ void SpeciesEvolution::setValue3(const int value3) throw(UnusedException) void SpeciesEvolution::setLevel(const int level) throw(BoundsException) { if (pokemod()->rules()->maxLevel() < level) - throw(BoundsException(className(), "level")); + error<BoundsException>("level"); m_level = level; } diff --git a/pokemod/SpeciesItem.cpp b/pokemod/SpeciesItem.cpp index 1a015df0..fc263ca0 100644 --- a/pokemod/SpeciesItem.cpp +++ b/pokemod/SpeciesItem.cpp @@ -81,14 +81,14 @@ QDomElement SpeciesItem::save() const void SpeciesItem::setItem(const int item) throw(BoundsException) { if (pokemod()->itemIndex(item) == INT_MAX) - throw(BoundsException(className(), "item")); + error<BoundsException>("item"); m_item = item; } void SpeciesItem::setWeight(const int weight) throw(BoundsException) { if (!weight) - throw(BoundsException(className(), "weight")); + error<BoundsException>("weight"); m_weight = weight; } diff --git a/pokemod/SpeciesMove.cpp b/pokemod/SpeciesMove.cpp index 287474eb..65d952e5 100644 --- a/pokemod/SpeciesMove.cpp +++ b/pokemod/SpeciesMove.cpp @@ -89,21 +89,21 @@ QDomElement SpeciesMove::save() const void SpeciesMove::setMove(const int move) throw(BoundsException) { if (pokemod()->moveIndex(move) == INT_MAX) - throw(BoundsException(className(), "move")); + error<BoundsException>("move"); m_move = move; } void SpeciesMove::setLevel(const int level) throw(BoundsException) { if (pokemod()->rules()->maxLevel() <= level) - throw(BoundsException(className(), "level")); + error<BoundsException>("level"); m_level = level; } void SpeciesMove::setWild(const int wild) throw(BoundsException) { if (pokemod()->rules()->maxLevel() <= wild) - throw(BoundsException(className(), "wild")); + error<BoundsException>("wild"); m_wild = wild; } diff --git a/pokemod/Store.cpp b/pokemod/Store.cpp index a3f6e37a..1edbca32 100644 --- a/pokemod/Store.cpp +++ b/pokemod/Store.cpp @@ -98,7 +98,7 @@ void Store::setName(const QString& name) void Store::setItem(const int item, const bool state) throw(BoundsException) { if (pokemod()->itemIndex(item) == INT_MAX) - throw(BoundsException(className(), "item")); + error<BoundsException>("item"); if (state) { if (!m_items.contains(item)) diff --git a/pokemod/Tile.cpp b/pokemod/Tile.cpp index ba6bb9ab..80f7d7b4 100644 --- a/pokemod/Tile.cpp +++ b/pokemod/Tile.cpp @@ -35,6 +35,7 @@ Tile::Tile(const Tile& tile) : Tile::Tile(const Pokemod* pokemod, const int id) : Object("Tile", pokemod, id), m_name(""), + m_sprite(64, 64), m_wildChance(1, 1), m_hmType(INT_MAX), m_under(INT_MAX), @@ -134,16 +135,17 @@ void Tile::setName(const QString& name) m_name = name; } -void Tile::setSprite(const QPixmap& sprite) throw(Exception) +void Tile::setSprite(const QPixmap& sprite) throw(SizeException) { - // TODO: check dimension + if (sprite.size() != QSize(64, 64)) + error<SizeException>("sprte"); m_sprite = sprite; } void Tile::setFrom(const int direction, const bool state) throw(BoundsException) { if (Pokemod::D_End <= direction) - throw(BoundsException(className(), "direction")); + error<BoundsException>("direction"); m_from[direction] = state; } @@ -155,7 +157,7 @@ void Tile::setWildChance(const Fraction& wildChance) throw(Exception) void Tile::setHMType(const int hmType) throw(BoundsException) { if (Pokemod::HM_End <= hmType) - throw(BoundsException(className(), "hmType")); + error<BoundsException>("hmType"); m_hmType = hmType; m_under = INT_MAX; } @@ -165,9 +167,9 @@ void Tile::setUnder(const int under) throw(Exception) if (m_hmType != INT_MAX) { if ((m_hmType != Pokemod::HM_Whirlpool) || (m_hmType != Pokemod::HM_Cut) || (m_hmType != Pokemod::HM_RockSmash)) - throw(UnusedException(className(), "under")); + error<UnusedException>("under"); if ((under == id()) || (pokemod()->tileIndex(under) == INT_MAX)) - throw(BoundsException(className(), "under")); + error<BoundsException>("under"); } m_under = under; } @@ -175,7 +177,7 @@ void Tile::setUnder(const int under) throw(Exception) void Tile::setForceType(const int forceType) throw(BoundsException) { if (End <= forceType) - throw(BoundsException(className(), "forceType")); + error<BoundsException>("forceType"); m_forceType = forceType; } @@ -184,9 +186,9 @@ void Tile::setForceDirection(const int forceDirection) throw(Exception) if (m_forceType != INT_MAX) { if (m_forceType == Stop) - throw(UnusedException(className(), "forceDirection")); + error<UnusedException>("forceDirection"); if (Pokemod::D_End <= forceDirection) - throw(BoundsException(className(), "forceDirection")); + error<BoundsException>("forceDirection"); } m_forceDirection = forceDirection; } @@ -204,7 +206,7 @@ QPixmap Tile::sprite() const bool Tile::from(const int direction) const throw(BoundsException) { if (Pokemod::D_End <= direction) - throw(BoundsException(className(), "direction")); + warning<BoundsException>("direction"); return m_from[direction]; } diff --git a/pokemod/Tile.h b/pokemod/Tile.h index 4bb398cd..ed82dce2 100644 --- a/pokemod/Tile.h +++ b/pokemod/Tile.h @@ -52,7 +52,7 @@ class Tile : public Object QDomElement save() const; void setName(const QString& name); - void setSprite(const QPixmap& sprite) throw(Exception); + void setSprite(const QPixmap& sprite) throw(SizeException); void setFrom(const int direction, const bool state) throw(BoundsException); void setWildChance(const Fraction& wildChance) throw(Exception); void setHMType(const int hmType) throw(BoundsException); diff --git a/pokemod/Time.cpp b/pokemod/Time.cpp index c308801c..ba9d3f46 100644 --- a/pokemod/Time.cpp +++ b/pokemod/Time.cpp @@ -94,14 +94,14 @@ void Time::setName(const QString& name) void Time::setHour(const int hour) throw(BoundsException) { if (24 <= hour) - throw(BoundsException(className(), "hour")); + error<BoundsException>("hour"); m_hour = hour; } void Time::setMinute(const int minute) throw(BoundsException) { if (60 <= minute) - throw(BoundsException(className(), "minute")); + error<BoundsException>("minute"); m_minute = minute; } diff --git a/pokemod/Trainer.cpp b/pokemod/Trainer.cpp index a4a86578..94a989fd 100644 --- a/pokemod/Trainer.cpp +++ b/pokemod/Trainer.cpp @@ -33,7 +33,8 @@ Trainer::Trainer(const Trainer& trainer) : Trainer::Trainer(const Pokemod* pokemod, const int id) : Object("Trainer", pokemod, id), m_name(""), - m_moneyFactor(0) + m_moneyFactor(0), + m_skin(192, 128) { } @@ -91,13 +92,14 @@ void Trainer::setName(const QString& name) void Trainer::setMoneyFactor(const int moneyFactor) throw(BoundsException) { if (moneyFactor < 0) - throw(BoundsException(className(), "moneyFactor")); + error<BoundsException>("moneyFactor"); m_moneyFactor = moneyFactor; } -void Trainer::setSkin(const QPixmap& skin) throw(Exception) +void Trainer::setSkin(const QPixmap& skin) throw(SizeException) { - // TODO: check dimensions + if (skin.size() != QSize(192, 128)) + error<SizeException>("skin"); m_skin = skin; } diff --git a/pokemod/Trainer.h b/pokemod/Trainer.h index bc845e35..22d9a6fb 100644 --- a/pokemod/Trainer.h +++ b/pokemod/Trainer.h @@ -43,7 +43,7 @@ class Trainer : public Object void setName(const QString& name); void setMoneyFactor(const int moneyFactor) throw(BoundsException); - void setSkin(const QPixmap& skin) throw(Exception); + void setSkin(const QPixmap& skin) throw(SizeException); // void setAi(const QString& fileName) throw(Exception); QString name() const; diff --git a/pokemod/Type.cpp b/pokemod/Type.cpp index eca0673c..0905ba92 100644 --- a/pokemod/Type.cpp +++ b/pokemod/Type.cpp @@ -107,7 +107,7 @@ Fraction Type::stab() const bool Type::immunity(const int status) const throw(BoundsException) { if (Pokemod::STS_End <= status) - error<BoundsException>("immunnity"); + warning<BoundsException>("immunnity"); return m_immunity[status]; } diff --git a/pokemod/pokemod.pro b/pokemod/pokemod.pro index fcba6191..0b87494b 100644 --- a/pokemod/pokemod.pro +++ b/pokemod/pokemod.pro @@ -3,6 +3,7 @@ OBJECTS_DIR = .obj DESTDIR = ../../bin LIBS += -L../../bin \ -lgeneral +QMAKE_CXXFLAGS += -pg -O0 CONFIG += qt warn_on dll exceptions debug CONFIG -= release @@ -38,7 +39,6 @@ SOURCES += Ability.cpp \ Move.cpp \ MoveEffect.cpp \ Nature.cpp \ - Object.cpp \ Pokemod.cpp \ Rules.cpp \ SpeciesAbility.cpp \ |