1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Now unit range is shown in Tactics phase as well

A new parameter: isActiveStack was needed in battleGetAvailableHexes, so that we show the propper Tactics range.
This commit is contained in:
krs 2023-03-23 23:03:18 +02:00
parent e1c388465a
commit dab07bdef9
7 changed files with 25 additions and 28 deletions

View File

@ -271,7 +271,7 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
BattleAction CBattleAI::goTowardsNearest(const CStack * stack, std::vector<BattleHex> hexes) const
{
auto reachability = cb->getReachability(stack);
auto avHexes = cb->battleGetAvailableHexes(reachability, stack);
auto avHexes = cb->battleGetAvailableHexes(reachability, stack, true);
if(!avHexes.size() || !hexes.size()) //we are blocked or dest is blocked
{

View File

@ -15,7 +15,7 @@ PotentialTargets::PotentialTargets(const battle::Unit * attacker, const Hypothet
{
auto attackerInfo = state.battleGetUnitByID(attacker->unitId());
auto reachability = state.getReachability(attackerInfo);
auto avHexes = state.battleGetAvailableHexes(reachability, attackerInfo);
auto avHexes = state.battleGetAvailableHexes(reachability, attackerInfo, true);
//FIXME: this should part of battleGetAvailableHexes
bool forceTarget = false;

View File

@ -120,7 +120,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack )
}
else
{
std::vector<BattleHex> avHexes = cb->battleGetAvailableHexes(stack);
std::vector<BattleHex> avHexes = cb->battleGetAvailableHexes(stack, true);
for (BattleHex hex : avHexes)
{
@ -238,7 +238,7 @@ void CStupidAI::print(const std::string &text) const
BattleAction CStupidAI::goTowards(const CStack * stack, std::vector<BattleHex> hexes) const
{
auto reachability = cb->getReachability(stack);
auto avHexes = cb->battleGetAvailableHexes(reachability, stack);
auto avHexes = cb->battleGetAvailableHexes(reachability, stack, false);
if(!avHexes.size() || !hexes.size()) //we are blocked or dest is blocked
{

View File

@ -623,7 +623,7 @@ void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, B
{
if(owner.stacksController->getActiveStack()->doubleWide())
{
std::vector<BattleHex> acc = owner.curInt->cb->battleGetAvailableHexes(owner.stacksController->getActiveStack());
std::vector<BattleHex> acc = owner.curInt->cb->battleGetAvailableHexes(owner.stacksController->getActiveStack(), true);
BattleHex shiftedDest = targetHex.cloneInDirection(owner.stacksController->getActiveStack()->destShiftDir(), false);
if(vstd::contains(acc, targetHex))
owner.giveCommand(EActionType::WALK, targetHex);
@ -926,7 +926,7 @@ bool BattleActionsController::isCastingPossibleHere(const CSpell * currentSpell,
bool BattleActionsController::canStackMoveHere(const CStack * stackToMove, BattleHex myNumber) const
{
std::vector<BattleHex> acc = owner.curInt->cb->battleGetAvailableHexes(stackToMove);
std::vector<BattleHex> acc = owner.curInt->cb->battleGetAvailableHexes(stackToMove, false);
BattleHex shiftedDest = myNumber.cloneInDirection(stackToMove->destShiftDir(), false);
if (vstd::contains(acc, myNumber))

View File

@ -173,7 +173,7 @@ void BattleFieldController::redrawBackgroundWithHexes()
const CStack *activeStack = owner.stacksController->getActiveStack();
std::vector<BattleHex> attackableHexes;
if(activeStack)
occupyableHexes = owner.curInt->cb->battleGetAvailableHexes(activeStack, true, &attackableHexes);
occupyableHexes = owner.curInt->cb->battleGetAvailableHexes(activeStack, true, true, &attackableHexes);
auto accessibility = owner.curInt->cb->getAccesibility();
@ -263,9 +263,9 @@ std::set<BattleHex> BattleFieldController::getMovementRangeForHoveredStack()
// add possible movement hexes for stack under mouse
const CStack * const hoveredStack = owner.curInt->cb->battleGetStackByPos(hoveredHex, true);
if(hoveredStack && hoveredStack != owner.stacksController->getActiveStack())
if(hoveredStack)
{
std::vector<BattleHex> v = owner.curInt->cb->battleGetAvailableHexes(hoveredStack, true, nullptr);
std::vector<BattleHex> v = owner.curInt->cb->battleGetAvailableHexes(hoveredStack, false, true, nullptr);
for(BattleHex hex : v)
result.insert(hex);
}
@ -310,7 +310,7 @@ std::set<BattleHex> BattleFieldController::getHighlightedHexesMovementTarget()
if(!stack)
return {};
std::vector<BattleHex> availableHexes = owner.curInt->cb->battleGetAvailableHexes(stack, false, nullptr);
std::vector<BattleHex> availableHexes = owner.curInt->cb->battleGetAvailableHexes(stack, true, false, nullptr);
auto hoveredStack = owner.curInt->cb->battleGetStackByPos(hoveredHex, true);
if(owner.curInt->cb->battleCanAttack(stack, hoveredStack, hoveredHex))

View File

@ -538,7 +538,7 @@ void CBattleInfoCallback::battleGetTurnOrder(std::vector<battle::Units> & turns,
battleGetTurnOrder(turns, maxUnits, maxTurns, actualTurn + 1, sideThatLastMoved);
}
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle::Unit * unit) const
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle::Unit * unit, bool isActiveStack) const
{
RETURN_IF_NOT_BATTLE(std::vector<BattleHex>());
@ -547,10 +547,10 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle
auto reachability = getReachability(unit);
return battleGetAvailableHexes(reachability, unit);
return battleGetAvailableHexes(reachability, unit, isActiveStack);
}
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const ReachabilityInfo & cache, const battle::Unit * unit) const
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const ReachabilityInfo & cache, const battle::Unit * unit, bool isActiveStack) const
{
std::vector<BattleHex> ret;
@ -560,7 +560,7 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const Reacha
auto unitSpeed = unit->Speed(0, true);
const bool tacticPhase = battleTacticDist() && battleGetTacticsSide() == unit->unitSide();
const bool showTacticsRange = battleTacticDist() && battleGetTacticsSide() == unit->unitSide() && isActiveStack;
for(int i = 0; i < GameConstants::BFIELD_SIZE; ++i)
{
@ -568,7 +568,7 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const Reacha
if(!cache.isReachable(i))
continue;
if(tacticPhase)
if(showTacticsRange)
{
// Stack has to perform tactic-phase movement -> can enter any reachable tile within given range
if(!isInTacticRange(i))
@ -587,10 +587,9 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const Reacha
return ret;
}
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle::Unit * unit, bool addOccupiable, std::vector<BattleHex> * attackable) const
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle::Unit * unit, bool isActiveStack, bool addOccupiable, std::vector<BattleHex> * attackable) const
{
std::vector<BattleHex> ret = battleGetAvailableHexes(unit);
std::vector<BattleHex> ret = battleGetAvailableHexes(unit, isActiveStack);
if(ret.empty())
return ret;
@ -976,7 +975,6 @@ ReachabilityInfo CBattleInfoCallback::makeBFS(const AccessibilityInfo &accessibi
return ret;
}
bool CBattleInfoCallback::isInObstacle(
BattleHex hex,
const std::set<BattleHex> & obstacles,
@ -1030,7 +1028,7 @@ std::set<BattleHex> CBattleInfoCallback::getStoppers(BattlePerspective::BattlePe
std::pair<const battle::Unit *, BattleHex> CBattleInfoCallback::getNearestStack(const battle::Unit * closest) const
{
auto reachability = getReachability(closest);
auto avHexes = battleGetAvailableHexes(reachability, closest);
auto avHexes = battleGetAvailableHexes(reachability, closest, false);
// I hate std::pairs with their undescriptive member names first / second
struct DistStack
@ -1097,7 +1095,6 @@ BattleHex CBattleInfoCallback::getAvaliableHex(const CreatureID & creID, ui8 sid
return BattleHex::getClosestTile(side, pos, occupyable);
}
si8 CBattleInfoCallback::battleGetTacticDist() const
{
RETURN_IF_NOT_BATTLE(0);

View File

@ -74,12 +74,12 @@ public:
void battleGetTurnOrder(std::vector<battle::Units> & out, const size_t maxUnits, const int maxTurns, const int turn = 0, int8_t lastMoved = -1) const;
///returns reachable hexes (valid movement destinations), DOES contain stack current position
std::vector<BattleHex> battleGetAvailableHexes(const battle::Unit * unit, bool addOccupiable, std::vector<BattleHex> * attackable) const;
std::vector<BattleHex> battleGetAvailableHexes(const battle::Unit * unit, bool isActiveStack, bool addOccupiable, std::vector<BattleHex> * attackable) const;
///returns reachable hexes (valid movement destinations), DOES contain stack current position (lite version)
std::vector<BattleHex> battleGetAvailableHexes(const battle::Unit * unit) const;
std::vector<BattleHex> battleGetAvailableHexes(const battle::Unit * unit, bool isActiveStack) const;
std::vector<BattleHex> battleGetAvailableHexes(const ReachabilityInfo & cache, const battle::Unit * unit) const;
std::vector<BattleHex> battleGetAvailableHexes(const ReachabilityInfo & cache, const battle::Unit * unit, bool isActiveStack) const;
int battleGetSurrenderCost(const PlayerColor & Player) const; //returns cost of surrendering battle, -1 if surrendering is not possible
ReachabilityInfo::TDistances battleGetDistances(const battle::Unit * unit, BattleHex assumedPosition) const;