From 0d0d3d8c80946fb3442a4fe0e3009f67391de183 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 14 Jan 2024 17:14:36 +0200 Subject: [PATCH] Renamed speed -> getMovementRange, remove misleading default parameter --- AI/BattleAI/BattleEvaluator.cpp | 4 ++-- AI/BattleAI/BattleExchangeVariant.cpp | 8 ++++---- AI/Nullkiller/Analyzers/ArmyManager.cpp | 2 +- AI/VCAI/ArmyManager.cpp | 2 +- client/battle/BattleActionsController.cpp | 2 +- client/battle/BattleAnimationClasses.cpp | 2 +- client/battle/BattleInterface.cpp | 2 +- client/battle/CreatureAnimation.cpp | 2 +- client/battle/CreatureAnimation.h | 2 +- client/windows/CCreatureWindow.cpp | 4 ++-- include/vcmi/Creature.h | 2 +- lib/BasicTypes.cpp | 5 ++--- lib/battle/CBattleInfoCallback.cpp | 12 ++++++------ lib/battle/CBattleInfoCallback.h | 2 +- server/battles/BattleActionProcessor.cpp | 2 +- 15 files changed, 26 insertions(+), 27 deletions(-) diff --git a/AI/BattleAI/BattleEvaluator.cpp b/AI/BattleAI/BattleEvaluator.cpp index 1e7234b37..d062f22bb 100644 --- a/AI/BattleAI/BattleEvaluator.cpp +++ b/AI/BattleAI/BattleEvaluator.cpp @@ -147,7 +147,7 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack) (int)bestAttack.from, (int)bestAttack.attack.attacker->getPosition().hex, bestAttack.attack.chargeDistance, - bestAttack.attack.attacker->speed(0, true), + bestAttack.attack.attacker->getMovementRange(0), bestAttack.defenderDamageReduce, bestAttack.attackerDamageReduce, score @@ -553,7 +553,7 @@ bool BattleEvaluator::attemptCastingSpell(const CStack * activeStack) auto needFullEval = vstd::contains_if(allUnits, [&](const battle::Unit * u) -> bool { auto original = cb->getBattle(battleID)->battleGetUnitByID(u->unitId()); - return !original || u->speed() != original->speed(); + return !original || u->getMovementRange() != original->getMovementRange(); }); DamageCache safeCopy = damageCache; diff --git a/AI/BattleAI/BattleExchangeVariant.cpp b/AI/BattleAI/BattleExchangeVariant.cpp index 8e3d5764b..ae090fdb8 100644 --- a/AI/BattleAI/BattleExchangeVariant.cpp +++ b/AI/BattleAI/BattleExchangeVariant.cpp @@ -297,7 +297,7 @@ MoveTarget BattleExchangeEvaluator::findMoveTowardsUnreachable( if(targets.unreachableEnemies.empty()) return result; - auto speed = activeStack->speed(); + auto speed = activeStack->getMovementRange(); if(speed == 0) return result; @@ -324,7 +324,7 @@ MoveTarget BattleExchangeEvaluator::findMoveTowardsUnreachable( auto turnsToRich = (distance - 1) / speed + 1; auto hexes = closestStack->getSurroundingHexes(); - auto enemySpeed = closestStack->speed(); + auto enemySpeed = closestStack->getMovementRange(); auto speedRatio = speed / static_cast(enemySpeed); auto multiplier = speedRatio > 1 ? 1 : speedRatio; @@ -821,7 +821,7 @@ std::vector BattleExchangeEvaluator::getOneTurnReachableUn continue; } - auto unitSpeed = unit->speed(turn); + auto unitSpeed = unit->getMovementRange(turn); auto radius = unitSpeed * (turn + 1); ReachabilityInfo unitReachability = vstd::getOrCompute( @@ -887,7 +887,7 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb float ratio = blockedUnitDamage / (float)(blockedUnitDamage + activeUnitDamage + 0.01); auto unitReachability = turnBattle.getReachability(unit); - auto unitSpeed = unit->speed(turn); // Cached value, to avoid performance hit + auto unitSpeed = unit->getMovementRange(turn); // Cached value, to avoid performance hit for(BattleHex hex = BattleHex::TOP_LEFT; hex.isValid(); hex = hex + 1) { diff --git a/AI/Nullkiller/Analyzers/ArmyManager.cpp b/AI/Nullkiller/Analyzers/ArmyManager.cpp index e0eb6333b..527471b08 100644 --- a/AI/Nullkiller/Analyzers/ArmyManager.cpp +++ b/AI/Nullkiller/Analyzers/ArmyManager.cpp @@ -117,7 +117,7 @@ std::vector::iterator ArmyManager::getWeakestCreature(std::vectorgetLevel() != right.creature->getLevel()) return left.creature->getLevel() < right.creature->getLevel(); - return left.creature->speed() > right.creature->speed(); + return left.creature->getMovementRange() > right.creature->getMovementRange(); }); return weakest; diff --git a/AI/VCAI/ArmyManager.cpp b/AI/VCAI/ArmyManager.cpp index d639c125e..72ab24d6b 100644 --- a/AI/VCAI/ArmyManager.cpp +++ b/AI/VCAI/ArmyManager.cpp @@ -63,7 +63,7 @@ std::vector::iterator ArmyManager::getWeakestCreature(std::vectorgetLevel() != right.creature->getLevel()) return left.creature->getLevel() < right.creature->getLevel(); - return left.creature->speed() > right.creature->speed(); + return left.creature->getMovementRange() > right.creature->getMovementRange(); }); return weakest; diff --git a/client/battle/BattleActionsController.cpp b/client/battle/BattleActionsController.cpp index b058bd263..a6e4f5784 100644 --- a/client/battle/BattleActionsController.cpp +++ b/client/battle/BattleActionsController.cpp @@ -568,7 +568,7 @@ bool BattleActionsController::actionIsLegal(PossiblePlayerBattleAction action, B switch (action.get()) { case PossiblePlayerBattleAction::CHOOSE_TACTICS_STACK: - return (targetStack && targetStackOwned && targetStack->speed() > 0); + return (targetStack && targetStackOwned && targetStack->getMovementRange() > 0); case PossiblePlayerBattleAction::CREATURE_INFO: return (targetStack && targetStackOwned && targetStack->alive()); diff --git a/client/battle/BattleAnimationClasses.cpp b/client/battle/BattleAnimationClasses.cpp index f56298930..2bff6e8ce 100644 --- a/client/battle/BattleAnimationClasses.cpp +++ b/client/battle/BattleAnimationClasses.cpp @@ -363,7 +363,7 @@ bool MovementAnimation::init() Point begPosition = owner.stacksController->getStackPositionAtHex(prevHex, stack); Point endPosition = owner.stacksController->getStackPositionAtHex(nextHex, stack); - progressPerSecond = AnimationControls::getMovementDistance(stack->unitType()); + progressPerSecond = AnimationControls::getMovementRange(stack->unitType()); begX = begPosition.x; begY = begPosition.y; diff --git a/client/battle/BattleInterface.cpp b/client/battle/BattleInterface.cpp index 99920ab2a..c2255b6f5 100644 --- a/client/battle/BattleInterface.cpp +++ b/client/battle/BattleInterface.cpp @@ -640,7 +640,7 @@ void BattleInterface::tacticPhaseEnd() static bool immobile(const CStack *s) { - return !s->speed(0, true); //should bound stacks be immobile? + return s->getMovementRange() == 0; //should bound stacks be immobile? } void BattleInterface::tacticNextStack(const CStack * current) diff --git a/client/battle/CreatureAnimation.cpp b/client/battle/CreatureAnimation.cpp index d3c6f7632..2addb4c3d 100644 --- a/client/battle/CreatureAnimation.cpp +++ b/client/battle/CreatureAnimation.cpp @@ -148,7 +148,7 @@ float AnimationControls::getSpellEffectSpeed() return static_cast(getAnimationSpeedFactor() * 10); } -float AnimationControls::getMovementDistance(const CCreature * creature) +float AnimationControls::getMovementRange(const CCreature * creature) { // H3 speed: 2/4/6 tiles per second return static_cast( 2.0 * getAnimationSpeedFactor() / creature->animation.walkAnimationTime); diff --git a/client/battle/CreatureAnimation.h b/client/battle/CreatureAnimation.h index 9029f7437..686e941b5 100644 --- a/client/battle/CreatureAnimation.h +++ b/client/battle/CreatureAnimation.h @@ -50,7 +50,7 @@ namespace AnimationControls float getSpellEffectSpeed(); /// returns speed of movement animation across the screen, in tiles per second - float getMovementDistance(const CCreature * creature); + float getMovementRange(const CCreature * creature); /// returns speed of movement animation across the screen, in pixels per seconds float getFlightDistance(const CCreature * creature); diff --git a/client/windows/CCreatureWindow.cpp b/client/windows/CCreatureWindow.cpp index 1202febfb..41b0c5137 100644 --- a/client/windows/CCreatureWindow.cpp +++ b/client/windows/CCreatureWindow.cpp @@ -543,7 +543,7 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s addStatLabel(EStat::DEFENCE, parent->info->creature->getDefense(battleStack->isShooter()), battleStack->getDefense(battleStack->isShooter())); addStatLabel(EStat::DAMAGE, parent->info->stackNode->getMinDamage(battleStack->isShooter()) * dmgMultiply, battleStack->getMaxDamage(battleStack->isShooter()) * dmgMultiply); addStatLabel(EStat::HEALTH, parent->info->creature->getMaxHealth(), battleStack->getMaxHealth()); - addStatLabel(EStat::SPEED, parent->info->creature->speed(), battleStack->speed()); + addStatLabel(EStat::SPEED, parent->info->creature->getMovementRange(), battleStack->getMovementRange()); if(battleStack->isShooter()) addStatLabel(EStat::SHOTS, battleStack->shots.total(), battleStack->shots.available()); @@ -563,7 +563,7 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s addStatLabel(EStat::DEFENCE, parent->info->creature->getDefense(shooter), parent->info->stackNode->getDefense(shooter)); addStatLabel(EStat::DAMAGE, parent->info->stackNode->getMinDamage(shooter) * dmgMultiply, parent->info->stackNode->getMaxDamage(shooter) * dmgMultiply); addStatLabel(EStat::HEALTH, parent->info->creature->getMaxHealth(), parent->info->stackNode->getMaxHealth()); - addStatLabel(EStat::SPEED, parent->info->creature->speed(), parent->info->stackNode->speed()); + addStatLabel(EStat::SPEED, parent->info->creature->getMovementRange(), parent->info->stackNode->getMovementRange()); if(shooter) addStatLabel(EStat::SHOTS, parent->info->stackNode->valOfBonuses(BonusType::SHOTS)); diff --git a/include/vcmi/Creature.h b/include/vcmi/Creature.h index 645d144ab..8bff40f86 100644 --- a/include/vcmi/Creature.h +++ b/include/vcmi/Creature.h @@ -23,7 +23,7 @@ class DLL_LINKAGE ACreature: public AFactionMember { public: bool isLiving() const; //non-undead, non-non living or alive - ui32 speed(int turn = 0, bool useBind = false) const; //get speed (in moving tiles) of creature with all modificators + ui32 getMovementRange(int turn = 0) const; //get speed (in moving tiles) of creature with all modificators virtual ui32 getMaxHealth() const; //get max HP of stack with all modifiers }; diff --git a/lib/BasicTypes.cpp b/lib/BasicTypes.cpp index d9f662a96..5ff9a1fe0 100644 --- a/lib/BasicTypes.cpp +++ b/lib/BasicTypes.cpp @@ -168,15 +168,14 @@ ui32 ACreature::getMaxHealth() const return std::max(1, value); //never 0 } -ui32 ACreature::speed(int turn, bool useBind) const +ui32 ACreature::getMovementRange(int turn) const { //war machines cannot move if(getBonusBearer()->hasBonus(Selector::type()(BonusType::SIEGE_WEAPON).And(Selector::turns(turn)))) { return 0; } - //bind effect check - doesn't influence stack initiative - if(useBind && getBonusBearer()->hasBonus(Selector::type()(BonusType::BIND_EFFECT).And(Selector::turns(turn)))) + if(getBonusBearer()->hasBonus(Selector::type()(BonusType::BIND_EFFECT).And(Selector::turns(turn)))) { return 0; } diff --git a/lib/battle/CBattleInfoCallback.cpp b/lib/battle/CBattleInfoCallback.cpp index 340dca2b1..7db5cc7aa 100644 --- a/lib/battle/CBattleInfoCallback.cpp +++ b/lib/battle/CBattleInfoCallback.cpp @@ -267,7 +267,7 @@ std::vector CBattleInfoCallback::getClientActionsFor allowedActionList.push_back(PossiblePlayerBattleAction::ATTACK); //all active stacks can attack allowedActionList.push_back(PossiblePlayerBattleAction::WALK_AND_ATTACK); //not all stacks can always walk, but we will check this elsewhere - if(stack->canMove() && stack->speed(0, true)) //probably no reason to try move war machines or bound stacks + if(stack->canMove() && stack->getMovementRange(0)) //probably no reason to try move war machines or bound stacks allowedActionList.push_back(PossiblePlayerBattleAction::MOVE_STACK); const auto * siegedTown = battleGetDefendedTown(); @@ -570,7 +570,7 @@ std::vector CBattleInfoCallback::battleGetAvailableHexes(const Reacha if(!unit->getPosition().isValid()) //turrets return ret; - auto unitSpeed = unit->speed(0, true); + auto unitSpeed = unit->getMovementRange(0); const bool tacticsPhase = battleTacticDist() && battleGetTacticsSide() == unit->unitSide(); @@ -741,15 +741,15 @@ DamageEstimation CBattleInfoCallback::battleEstimateDamage(const battle::Unit * { RETURN_IF_NOT_BATTLE({}); auto reachability = battleGetDistances(attacker, attacker->getPosition()); - int movementDistance = reachability[attackerPosition]; - return battleEstimateDamage(attacker, defender, movementDistance, retaliationDmg); + int getMovementRange = reachability[attackerPosition]; + return battleEstimateDamage(attacker, defender, getMovementRange, retaliationDmg); } -DamageEstimation CBattleInfoCallback::battleEstimateDamage(const battle::Unit * attacker, const battle::Unit * defender, int movementDistance, DamageEstimation * retaliationDmg) const +DamageEstimation CBattleInfoCallback::battleEstimateDamage(const battle::Unit * attacker, const battle::Unit * defender, int getMovementRange, DamageEstimation * retaliationDmg) const { RETURN_IF_NOT_BATTLE({}); const bool shooting = battleCanShoot(attacker, defender->getPosition()); - const BattleAttackInfo bai(attacker, defender, movementDistance, shooting); + const BattleAttackInfo bai(attacker, defender, getMovementRange, shooting); return battleEstimateDamage(bai, retaliationDmg); } diff --git a/lib/battle/CBattleInfoCallback.h b/lib/battle/CBattleInfoCallback.h index ed5c8a0d8..1ace49408 100644 --- a/lib/battle/CBattleInfoCallback.h +++ b/lib/battle/CBattleInfoCallback.h @@ -98,7 +98,7 @@ public: /// returns pair DamageEstimation battleEstimateDamage(const BattleAttackInfo & bai, DamageEstimation * retaliationDmg = nullptr) const; DamageEstimation battleEstimateDamage(const battle::Unit * attacker, const battle::Unit * defender, BattleHex attackerPosition, DamageEstimation * retaliationDmg = nullptr) const; - DamageEstimation battleEstimateDamage(const battle::Unit * attacker, const battle::Unit * defender, int movementDistance, DamageEstimation * retaliationDmg = nullptr) const; + DamageEstimation battleEstimateDamage(const battle::Unit * attacker, const battle::Unit * defender, int getMovementRange, DamageEstimation * retaliationDmg = nullptr) const; bool battleHasPenaltyOnLine(BattleHex from, BattleHex dest, bool checkWall, bool checkMoat) const; bool battleHasDistancePenalty(const IBonusBearer * shooter, BattleHex shooterPosition, BattleHex destHex) const; diff --git a/server/battles/BattleActionProcessor.cpp b/server/battles/BattleActionProcessor.cpp index 1f35189a3..285ecce15 100644 --- a/server/battles/BattleActionProcessor.cpp +++ b/server/battles/BattleActionProcessor.cpp @@ -659,7 +659,7 @@ int BattleActionProcessor::moveStack(const CBattleInfoCallback & battle, int sta ret = path.second; - int creSpeed = curStack->speed(0, true); + int creSpeed = curStack->getMovementRange(0); if (battle.battleGetTacticDist() > 0 && creSpeed > 0) creSpeed = GameConstants::BFIELD_SIZE;