diff options
Diffstat (limited to 'src/gamemodifiers.cpp')
-rw-r--r-- | src/gamemodifiers.cpp | 129 |
1 files changed, 65 insertions, 64 deletions
diff --git a/src/gamemodifiers.cpp b/src/gamemodifiers.cpp index 01d54b212..b0c893ab9 100644 --- a/src/gamemodifiers.cpp +++ b/src/gamemodifiers.cpp @@ -1,9 +1,9 @@ /* - * The ManaPlus Client + * The ManaVerse Client * Copyright (C) 2011-2020 The ManaPlus Developers - * Copyright (C) 2020-2023 The ManaVerse Developers + * Copyright (C) 2020-2025 The ManaVerse Developers * - * This file is part of The ManaPlus Client. + * This file is part of The ManaVerse Client. * * 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 @@ -49,36 +49,36 @@ #include "debug.h" -#define addModifier(name1, name2, sz, ...) \ - const unsigned GameModifiers::m##name1##Size = sz; \ - const char *const GameModifiers::m##name1##Strings[] = \ - __VA_ARGS__; \ - std::string GameModifiers::get##name1##String() \ +#define addModifier(typeName, varName, size, ...) \ + const unsigned GameModifiers::m##typeName##Size = size; \ + const char *const GameModifiers::m##typeName##Strings[] = __VA_ARGS__; \ + std::string GameModifiers::get##typeName##String() \ { \ - return gettext(getVarItem(&m##name1##Strings[0], \ - CAST_U32(settings.name2), m##name1##Size)); \ + return gettext(getHumanString(&m##typeName##Strings[0], \ + CAST_U32(settings.varName), \ + m##typeName##Size)); \ } -#define addModifier2(name1, name2, str, sz, ...) \ - const unsigned GameModifiers::m##name1##Size = sz; \ - const char *const GameModifiers::m##name1##Strings[] = \ - __VA_ARGS__; \ - void GameModifiers::change##name1(const bool forward) \ +#define addModifier2(typeName, varName, str, size, ...) \ + const unsigned GameModifiers::m##typeName##Size = size; \ + const char *const GameModifiers::m##typeName##Strings[] = __VA_ARGS__; \ + void GameModifiers::change##typeName(const bool forward) \ { \ - changeMode(&settings.name2, m##name1##Size, str, \ - &GameModifiers::get##name1##String, 0, true, forward); \ + changeMode(&settings.varName, 0, m##typeName##Size, str, \ + &GameModifiers::get##typeName##String, true, forward); \ } \ - std::string GameModifiers::get##name1##String() \ + std::string GameModifiers::get##typeName##String() \ { \ - return gettext(getVarItem(&m##name1##Strings[0], \ - settings.name2, m##name1##Size)); \ + return gettext(getHumanString(&m##typeName##Strings[0], \ + settings.varName, \ + m##typeName##Size)); \ } -#define changeMethod(name1, name2, str) \ - void GameModifiers::change##name1(const bool forward) \ +#define changeMethod(typeName, varName, str) \ + void GameModifiers::change##typeName(const bool forward) \ { \ - changeMode(&settings.name2, m##name1##Size, str, \ - &GameModifiers::get##name1##String, 0, true, forward); \ + changeMode(&settings.varName, 0, m##typeName##Size, str, \ + &GameModifiers::get##typeName##String, true, forward); \ } void GameModifiers::init() @@ -94,18 +94,18 @@ void GameModifiers::init() settings.magicAttackType = config.getIntValue("magicAttackType"); settings.pvpAttackType = config.getIntValue("pvpAttackType"); settings.imitationMode = config.getIntValue("imitationMode"); - settings.disableGameModifiers = config.getBoolValue( - "disableGameModifiers"); + settings.disableGameModifiers = + config.getBoolValue("disableGameModifiers"); settings.awayMode = false; settings.mapDrawType = MapType::NORMAL; // UpdateStatusListener::distributeEvent(); } void GameModifiers::changeMode(unsigned *restrict const var, + const unsigned first, const unsigned limit, - const char *restrict const conf, - std::string (*const func)(), - const unsigned def, + const char *restrict const configKey, + std::string (*const toHumanString)(), const bool save, const bool forward) { @@ -116,7 +116,7 @@ void GameModifiers::changeMode(unsigned *restrict const var, { (*var) ++; if (*var >= limit) - *var = def; + *var = first; } else { @@ -127,21 +127,23 @@ void GameModifiers::changeMode(unsigned *restrict const var, } if (save) - config.setValue(conf, *var); + config.setValue(configKey, *var); UpdateStatusListener::distributeEvent(); GameModifierListener::distributeEvent(); - const std::string str = (*func)(); + // Announce new setting to user's chat. + const std::string str = (*toHumanString)(); if (str.size() > 4) debugMsg(str.substr(4)) } -const char *GameModifiers::getVarItem(const char *const *const arr, - const unsigned index, - const unsigned sz) +const char *GameModifiers::getHumanString(const char *const *const lut, + const unsigned index, + const unsigned size) { - if (index < sz) - return arr[index]; - return arr[sz]; + if (index < size) + return lut[index]; + else + return lut[size]; } addModifier(MoveType, moveType, 5, @@ -163,8 +165,8 @@ addModifier(MoveType, moveType, 5, void GameModifiers::changeMoveType(const bool forward) { localPlayer->setMoveState(0); - changeMode(&settings.moveType, mMoveTypeSize, "invertMoveDirection", - &GameModifiers::getMoveTypeString, 0, false, forward); + changeMode(&settings.moveType, 0, mMoveTypeSize, "invertMoveDirection", + &GameModifiers::getMoveTypeString, false, forward); } const unsigned GameModifiers::mCrazyMoveTypeSize = 11; @@ -172,8 +174,8 @@ const unsigned GameModifiers::mCrazyMoveTypeSize = 11; void GameModifiers::changeCrazyMoveType(const bool forward) { settings.crazyMoveState = 0U; - changeMode(&settings.crazyMoveType, mCrazyMoveTypeSize, "crazyMoveType", - &GameModifiers::getCrazyMoveTypeString, 1, true, forward); + changeMode(&settings.crazyMoveType, 1, mCrazyMoveTypeSize, "crazyMoveType", + &GameModifiers::getCrazyMoveTypeString, true, forward); } std::string GameModifiers::getCrazyMoveTypeString() @@ -183,7 +185,7 @@ std::string GameModifiers::getCrazyMoveTypeString() { // TRANSLATORS: crazy move type in status bar return strprintf(_("(%u) crazy move number %u"), - crazyMoveType, crazyMoveType); + crazyMoveType, crazyMoveType); } else if (crazyMoveType == mCrazyMoveTypeSize - 1) { @@ -200,33 +202,33 @@ std::string GameModifiers::getCrazyMoveTypeString() addModifier2(MoveToTargetType, moveToTargetType, "moveToTargetType", 13, { // TRANSLATORS: move to target type in status bar - N_("(0) default moves to target"), + N_("(0) default moves to target"), // 0 // TRANSLATORS: move to target type in status bar - N_("(1) moves to target in distance 1"), + N_("(1) moves to target in distance 1"), // 1 // TRANSLATORS: move to target type in status bar - N_("(2) moves to target in distance 2"), + N_("(2) moves to target in distance 2"), // 2 // TRANSLATORS: move to target type in status bar - N_("(3) moves to target in distance 3"), + N_("(3) moves to target in distance 3"), // 3 // TRANSLATORS: move to target type in status bar - N_("(4) moves to target in distance 4"), + N_("(4) moves to target in distance 4"), // 4 // TRANSLATORS: move to target type in status bar - N_("(5) moves to target in distance 5"), + N_("(5) moves to target in distance 5"), // 5 // TRANSLATORS: move to target type in status bar - N_("(6) moves to target in distance 6"), + N_("(6) moves to target in distance 6"), // 6 // TRANSLATORS: move to target type in status bar - N_("(7) moves to target in distance 7"), + N_("(7) moves to target in distance 7"), // 7 // TRANSLATORS: move to target type in status bar - N_("(8) moves to target in distance 8"), + N_("(8) moves to target in distance 8"), // 8 // TRANSLATORS: move to target type in status bar - N_("(9) moves to target in distance 9"), + N_("(9) moves to target in distance 9"), // 9 // TRANSLATORS: move to target type in status bar - N_("(A) moves to target in attack range"), + N_("(A) moves to target in attack range"), // 10 // TRANSLATORS: move to target type in status bar - N_("(a) archer attack range"), + N_("(a) archer attack range"), // 11 // TRANSLATORS: move to target type in status bar - N_("(B) moves to target in attack range - 1"), + N_("(B) moves to target in attack range - 1"), // 12 // TRANSLATORS: move to target type in status bar - N_("(?) move to target") + N_("(?) move to target") // 13 }) addModifier2(FollowMode, followMode, "followMode", 4, @@ -289,11 +291,10 @@ std::string GameModifiers::getQuickDropCounterString() { const unsigned int cnt = settings.quickDropCounter; if (cnt > 9) - { - return strprintf("(%c) drop counter %u", CAST_S8( - 'a' + cnt - 10), cnt); - } - return strprintf("(%u) drop counter %u", cnt, cnt); + return strprintf("(%c) drop counter %u", + CAST_S8('a' + cnt - 10), cnt); + else + return strprintf("(%u) drop counter %u", cnt, cnt); } void GameModifiers::setQuickDropCounter(const int n) @@ -510,8 +511,8 @@ void GameModifiers::resetModifiers() map->setDrawLayersFlags(MapType::NORMAL); } settings.imitationMode = config.resetIntValue("imitationMode"); - settings.disableGameModifiers = config.resetBoolValue( - "disableGameModifiers"); + settings.disableGameModifiers = + config.resetBoolValue("disableGameModifiers"); UpdateStatusListener::distributeEvent(); GameModifierListener::distributeEvent(); |