diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-07-23 13:31:51 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-07-23 14:54:10 +0300 |
commit | 554a73e59eb49ae282b5fea1adfab0efd5b633fb (patch) | |
tree | 933365cb2a69d56dd584e36fc61e61f2f15bef01 /src/gamemodifiers.cpp | |
parent | f365abac5cf10d6535e587964a840ca878fa07d3 (diff) | |
download | plus-554a73e59eb49ae282b5fea1adfab0efd5b633fb.tar.gz plus-554a73e59eb49ae282b5fea1adfab0efd5b633fb.tar.bz2 plus-554a73e59eb49ae282b5fea1adfab0efd5b633fb.tar.xz plus-554a73e59eb49ae282b5fea1adfab0efd5b633fb.zip |
Simplify gamemodifiers with macro addModifier.
Diffstat (limited to 'src/gamemodifiers.cpp')
-rw-r--r-- | src/gamemodifiers.cpp | 200 |
1 files changed, 89 insertions, 111 deletions
diff --git a/src/gamemodifiers.cpp b/src/gamemodifiers.cpp index dc4fc8c14..ea03b2e8b 100644 --- a/src/gamemodifiers.cpp +++ b/src/gamemodifiers.cpp @@ -42,6 +42,10 @@ #include "debug.h" +#define addModifier(name, sz) \ + static const unsigned m##name##Size = sz; \ + static const char *const m##name##Strings[] = + GameModifiers *modifiers = nullptr; GameModifiers::GameModifiers() @@ -106,16 +110,7 @@ const char *GameModifiers::getVarItem(const char *const *const arr, return arr[sz]; } -static const unsigned mMoveTypeSize = 5; - -void GameModifiers::changeMoveType(const bool forward) -{ - player_node->setMoveState(0); - changeMode(&settings.moveType, mMoveTypeSize, "invertMoveDirection", - &GameModifiers::getMoveTypeString, 0, false, forward); -} - -static const char *const mMoveTypeStrings[] = +addModifier(MoveType, 5) { // TRANSLATORS: move type in status bar N_("(D) default moves"), @@ -131,6 +126,13 @@ static const char *const mMoveTypeStrings[] = N_("(?) unknown move") }; +void GameModifiers::changeMoveType(const bool forward) +{ + player_node->setMoveState(0); + changeMode(&settings.moveType, mMoveTypeSize, "invertMoveDirection", + &GameModifiers::getMoveTypeString, 0, false, forward); +} + std::string GameModifiers::getMoveTypeString() { return gettext(getVarItem(&mMoveTypeStrings[0], @@ -167,16 +169,7 @@ std::string GameModifiers::getCrazyMoveTypeString() } } -static const unsigned mMoveToTargetTypeSize = 13; - -void GameModifiers::changeMoveToTargetType(const bool forward) -{ - changeMode(&settings.moveToTargetType, mMoveToTargetTypeSize, - "moveToTargetType", - &GameModifiers::getMoveToTargetTypeString, 0, true, forward); -} - -static const char *const mMoveToTargetTypeStrings[] = +addModifier(MoveToTargetType, 13) { // TRANSLATORS: move to target type in status bar N_("(0) default moves to target"), @@ -208,21 +201,20 @@ static const char *const mMoveToTargetTypeStrings[] = N_("(?) move to target") }; -std::string GameModifiers::getMoveToTargetTypeString() +void GameModifiers::changeMoveToTargetType(const bool forward) { - return gettext(getVarItem(&mMoveToTargetTypeStrings[0], - settings.moveToTargetType, mMoveToTargetTypeSize)); + changeMode(&settings.moveToTargetType, mMoveToTargetTypeSize, + "moveToTargetType", + &GameModifiers::getMoveToTargetTypeString, 0, true, forward); } -static const unsigned mFollowModeSize = 4; - -void GameModifiers::changeFollowMode(const bool forward) +std::string GameModifiers::getMoveToTargetTypeString() { - changeMode(&settings.followMode, mFollowModeSize, "followMode", - &GameModifiers::getFollowModeString, 0, true, forward); + return gettext(getVarItem(&mMoveToTargetTypeStrings[0], + settings.moveToTargetType, mMoveToTargetTypeSize)); } -static const char *const mFollowModeStrings[] = +addModifier(FollowMode, 4) { // TRANSLATORS: folow mode in status bar N_("(D) default follow"), @@ -236,22 +228,19 @@ static const char *const mFollowModeStrings[] = N_("(?) unknown follow") }; -std::string GameModifiers::getFollowModeString() +void GameModifiers::changeFollowMode(const bool forward) { - return gettext(getVarItem(&mFollowModeStrings[0], - settings.followMode, mFollowModeSize)); + changeMode(&settings.followMode, mFollowModeSize, "followMode", + &GameModifiers::getFollowModeString, 0, true, forward); } -const unsigned mAttackWeaponTypeSize = 4; - -void GameModifiers::changeAttackWeaponType(const bool forward) +std::string GameModifiers::getFollowModeString() { - changeMode(&settings.attackWeaponType, mAttackWeaponTypeSize, - "attackWeaponType", - &GameModifiers::getAttackWeaponTypeString, 1, true, forward); + return gettext(getVarItem(&mFollowModeStrings[0], + settings.followMode, mFollowModeSize)); } -static const char *const mAttackWeaponTypeStrings[] = +addModifier(AttackWeaponType, 4) { // TRANSLATORS: switch attack type in status bar N_("(?) attack"), @@ -265,21 +254,20 @@ static const char *const mAttackWeaponTypeStrings[] = N_("(?) attack") }; -std::string GameModifiers::getAttackWeaponTypeString() +void GameModifiers::changeAttackWeaponType(const bool forward) { - return gettext(getVarItem(&mAttackWeaponTypeStrings[0], - settings.attackWeaponType, mAttackWeaponTypeSize)); + changeMode(&settings.attackWeaponType, mAttackWeaponTypeSize, + "attackWeaponType", + &GameModifiers::getAttackWeaponTypeString, 1, true, forward); } -const unsigned mAttackTypeSize = 4; - -void GameModifiers::changeAttackType(const bool forward) +std::string GameModifiers::getAttackWeaponTypeString() { - changeMode(&settings.attackType, mAttackTypeSize, "attackType", - &GameModifiers::getAttackTypeString, 0, true, forward); + return gettext(getVarItem(&mAttackWeaponTypeStrings[0], + settings.attackWeaponType, mAttackWeaponTypeSize)); } -static const char *const mAttackTypeStrings[] = +addModifier(AttackType, 4) { // TRANSLATORS: attack type in status bar N_("(D) default attack"), @@ -293,6 +281,12 @@ static const char *const mAttackTypeStrings[] = N_("(?) attack") }; +void GameModifiers::changeAttackType(const bool forward) +{ + changeMode(&settings.attackType, mAttackTypeSize, "attackType", + &GameModifiers::getAttackTypeString, 0, true, forward); +} + std::string GameModifiers::getAttackTypeString() { return gettext(getVarItem(&mAttackTypeStrings[0], @@ -331,15 +325,7 @@ void GameModifiers::setQuickDropCounter(const int n) UpdateStatusListener::distributeEvent(); } -const unsigned mPickUpTypeSize = 7; - -void GameModifiers::changePickUpType(const bool forward) -{ - changeMode(&settings.pickUpType, mPickUpTypeSize, "pickUpType", - &GameModifiers::getPickUpTypeString, 0, true, forward); -} - -static const char *const mPickUpTypeStrings[] = +addModifier(PickUpType, 7) { // TRANSLATORS: pickup size in status bar N_("(S) small pick up 1x1 cells"), @@ -359,21 +345,19 @@ static const char *const mPickUpTypeStrings[] = N_("(?) pick up") }; -std::string GameModifiers::getPickUpTypeString() +void GameModifiers::changePickUpType(const bool forward) { - return gettext(getVarItem(&mPickUpTypeStrings[0], - settings.pickUpType, mPickUpTypeSize)); + changeMode(&settings.pickUpType, mPickUpTypeSize, "pickUpType", + &GameModifiers::getPickUpTypeString, 0, true, forward); } -const unsigned mMagicAttackSize = 5; - -void GameModifiers::changeMagicAttackType(const bool forward) +std::string GameModifiers::getPickUpTypeString() { - changeMode(&settings.magicAttackType, mMagicAttackSize, "magicAttackType", - &GameModifiers::getMagicAttackString, 0, true, forward); + return gettext(getVarItem(&mPickUpTypeStrings[0], + settings.pickUpType, mPickUpTypeSize)); } -static const char *const mMagicAttackStrings[] = +addModifier(MagicAttack, 5) { // TRANSLATORS: magic attack in status bar N_("(f) use #flar for magic attack"), @@ -389,21 +373,19 @@ static const char *const mMagicAttackStrings[] = N_("(?) magic attack") }; -std::string GameModifiers::getMagicAttackString() +void GameModifiers::changeMagicAttackType(const bool forward) { - return gettext(getVarItem(&mMagicAttackStrings[0], - settings.magicAttackType, mMagicAttackSize)); + changeMode(&settings.magicAttackType, mMagicAttackSize, "magicAttackType", + &GameModifiers::getMagicAttackString, 0, true, forward); } -const unsigned mPvpAttackTypeSize = 4; - -void GameModifiers::changePvpAttackType(const bool forward) +std::string GameModifiers::getMagicAttackString() { - changeMode(&settings.pvpAttackType, mPvpAttackTypeSize, "pvpAttackType", - &GameModifiers::getPvpAttackTypeString, 0, true, forward); + return gettext(getVarItem(&mMagicAttackStrings[0], + settings.magicAttackType, mMagicAttackSize)); } -static const char *const mPvpAttackTypeStrings[] = +addModifier(PvpAttackType, 4) { // TRANSLATORS: player attack type in status bar N_("(a) attack all players"), @@ -417,21 +399,19 @@ static const char *const mPvpAttackTypeStrings[] = N_("(?) pvp attack") }; -std::string GameModifiers::getPvpAttackTypeString() +void GameModifiers::changePvpAttackType(const bool forward) { - return gettext(getVarItem(&mPvpAttackTypeStrings[0], - settings.pvpAttackType, mPvpAttackTypeSize)); + changeMode(&settings.pvpAttackType, mPvpAttackTypeSize, "pvpAttackType", + &GameModifiers::getPvpAttackTypeString, 0, true, forward); } -const unsigned mImitationModeSize = 2; - -void GameModifiers::changeImitationMode(const bool forward) +std::string GameModifiers::getPvpAttackTypeString() { - changeMode(&settings.imitationMode, mImitationModeSize, "imitationMode", - &GameModifiers::getImitationModeString, 0, true, forward); + return gettext(getVarItem(&mPvpAttackTypeStrings[0], + settings.pvpAttackType, mPvpAttackTypeSize)); } -static const char *const mImitationModeStrings[] = +addModifier(ImitationMode, 2) { // TRANSLATORS: imitation type in status bar N_("(D) default imitation"), @@ -441,22 +421,19 @@ static const char *const mImitationModeStrings[] = N_("(?) imitation") }; -std::string GameModifiers::getImitationModeString() +void GameModifiers::changeImitationMode(const bool forward) { - return gettext(getVarItem(&mImitationModeStrings[0], - settings.imitationMode, mImitationModeSize)); + changeMode(&settings.imitationMode, mImitationModeSize, "imitationMode", + &GameModifiers::getImitationModeString, 0, true, forward); } -const unsigned mGameModifiersSize = 2; - -void GameModifiers::changeGameModifiers() +std::string GameModifiers::getImitationModeString() { - settings.disableGameModifiers = !settings.disableGameModifiers; - config.setValue("disableGameModifiers", settings.disableGameModifiers); - UpdateStatusListener::distributeEvent(); + return gettext(getVarItem(&mImitationModeStrings[0], + settings.imitationMode, mImitationModeSize)); } -static const char *const mGameModifiersStrings[] = +addModifier(GameModifiers, 2) { // TRANSLATORS: game modifiers state in status bar N_("Game modifiers are enabled"), @@ -466,15 +443,20 @@ static const char *const mGameModifiersStrings[] = N_("Game modifiers are unknown") }; +void GameModifiers::changeGameModifiers() +{ + settings.disableGameModifiers = !settings.disableGameModifiers; + config.setValue("disableGameModifiers", settings.disableGameModifiers); + UpdateStatusListener::distributeEvent(); +} + std::string GameModifiers::getGameModifiersString() { return gettext(getVarItem(&mGameModifiersStrings[0], settings.disableGameModifiers, mGameModifiersSize)); } -const unsigned mMapDrawTypeSize = 7; - -static const char *const mMapDrawTypeStrings[] = +addModifier(MapDrawType, 7) { // TRANSLATORS: map view type in status bar N_("(N) normal map view"), @@ -500,7 +482,15 @@ std::string GameModifiers::getMapDrawTypeString() settings.mapDrawType, mMapDrawTypeSize)); } -const unsigned mAwayModeSize = 2; +addModifier(AwayMode, 2) +{ + // TRANSLATORS: away type in status bar + N_("(O) on keyboard"), + // TRANSLATORS: away type in status bar + N_("(A) away"), + // TRANSLATORS: away type in status bar + N_("(?) away") +}; void GameModifiers::changeAwayMode() { @@ -543,25 +533,13 @@ void GameModifiers::changeAwayMode() } } -static const char *const mAwayModeStrings[] = -{ - // TRANSLATORS: away type in status bar - N_("(O) on keyboard"), - // TRANSLATORS: away type in status bar - N_("(A) away"), - // TRANSLATORS: away type in status bar - N_("(?) away") -}; - std::string GameModifiers::getAwayModeString() { return gettext(getVarItem(&mAwayModeStrings[0], settings.awayMode, mAwayModeSize)); } -const unsigned mCameraModeSize = 2; - -static const char *const mCameraModeStrings[] = +addModifier(CameraMode, 2) { // TRANSLATORS: camera mode in status bar N_("(G) game camera mode"), |