mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Tactics movement is limited to movement range
This commit is contained in:
@@ -282,7 +282,7 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
|
|||||||
BattleAction CBattleAI::goTowardsNearest(const CStack * stack, std::vector<BattleHex> hexes) const
|
BattleAction CBattleAI::goTowardsNearest(const CStack * stack, std::vector<BattleHex> hexes) const
|
||||||
{
|
{
|
||||||
auto reachability = cb->getReachability(stack);
|
auto reachability = cb->getReachability(stack);
|
||||||
auto avHexes = cb->battleGetAvailableHexes(reachability, stack, true);
|
auto avHexes = cb->battleGetAvailableHexes(reachability, stack, false);
|
||||||
|
|
||||||
if(!avHexes.size() || !hexes.size()) //we are blocked or dest is blocked
|
if(!avHexes.size() || !hexes.size()) //we are blocked or dest is blocked
|
||||||
{
|
{
|
||||||
|
@@ -15,7 +15,7 @@ PotentialTargets::PotentialTargets(const battle::Unit * attacker, const Hypothet
|
|||||||
{
|
{
|
||||||
auto attackerInfo = state.battleGetUnitByID(attacker->unitId());
|
auto attackerInfo = state.battleGetUnitByID(attacker->unitId());
|
||||||
auto reachability = state.getReachability(attackerInfo);
|
auto reachability = state.getReachability(attackerInfo);
|
||||||
auto avHexes = state.battleGetAvailableHexes(reachability, attackerInfo, true);
|
auto avHexes = state.battleGetAvailableHexes(reachability, attackerInfo, false);
|
||||||
|
|
||||||
//FIXME: this should part of battleGetAvailableHexes
|
//FIXME: this should part of battleGetAvailableHexes
|
||||||
bool forceTarget = false;
|
bool forceTarget = false;
|
||||||
|
@@ -120,7 +120,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::vector<BattleHex> avHexes = cb->battleGetAvailableHexes(stack, true);
|
std::vector<BattleHex> avHexes = cb->battleGetAvailableHexes(stack, false);
|
||||||
|
|
||||||
for (BattleHex hex : avHexes)
|
for (BattleHex hex : avHexes)
|
||||||
{
|
{
|
||||||
|
@@ -620,7 +620,7 @@ void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, B
|
|||||||
{
|
{
|
||||||
if(owner.stacksController->getActiveStack()->doubleWide())
|
if(owner.stacksController->getActiveStack()->doubleWide())
|
||||||
{
|
{
|
||||||
std::vector<BattleHex> acc = owner.curInt->cb->battleGetAvailableHexes(owner.stacksController->getActiveStack(), true);
|
std::vector<BattleHex> acc = owner.curInt->cb->battleGetAvailableHexes(owner.stacksController->getActiveStack(), false);
|
||||||
BattleHex shiftedDest = targetHex.cloneInDirection(owner.stacksController->getActiveStack()->destShiftDir(), false);
|
BattleHex shiftedDest = targetHex.cloneInDirection(owner.stacksController->getActiveStack()->destShiftDir(), false);
|
||||||
if(vstd::contains(acc, targetHex))
|
if(vstd::contains(acc, targetHex))
|
||||||
owner.giveCommand(EActionType::WALK, targetHex);
|
owner.giveCommand(EActionType::WALK, targetHex);
|
||||||
|
@@ -174,7 +174,7 @@ void BattleFieldController::redrawBackgroundWithHexes()
|
|||||||
const CStack *activeStack = owner.stacksController->getActiveStack();
|
const CStack *activeStack = owner.stacksController->getActiveStack();
|
||||||
std::vector<BattleHex> attackableHexes;
|
std::vector<BattleHex> attackableHexes;
|
||||||
if(activeStack)
|
if(activeStack)
|
||||||
occupiableHexes = owner.curInt->cb->battleGetAvailableHexes(activeStack, true, true, &attackableHexes);
|
occupiableHexes = owner.curInt->cb->battleGetAvailableHexes(activeStack, false, true, &attackableHexes);
|
||||||
|
|
||||||
// prepare background graphic with hexes and shaded hexes
|
// prepare background graphic with hexes and shaded hexes
|
||||||
backgroundWithHexes->draw(background, Point(0,0));
|
backgroundWithHexes->draw(background, Point(0,0));
|
||||||
@@ -252,7 +252,7 @@ std::set<BattleHex> BattleFieldController::getMovementRangeForHoveredStack()
|
|||||||
const CStack * const hoveredStack = owner.curInt->cb->battleGetStackByPos(hoveredHex, true);
|
const CStack * const hoveredStack = owner.curInt->cb->battleGetStackByPos(hoveredHex, true);
|
||||||
if(hoveredStack)
|
if(hoveredStack)
|
||||||
{
|
{
|
||||||
std::vector<BattleHex> v = owner.curInt->cb->battleGetAvailableHexes(hoveredStack, false, true, nullptr);
|
std::vector<BattleHex> v = owner.curInt->cb->battleGetAvailableHexes(hoveredStack, true, true, nullptr);
|
||||||
for(BattleHex hex : v)
|
for(BattleHex hex : v)
|
||||||
result.insert(hex);
|
result.insert(hex);
|
||||||
}
|
}
|
||||||
@@ -289,7 +289,7 @@ std::set<BattleHex> BattleFieldController::getHighlightedHexesForSpellRange()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<BattleHex> BattleFieldController::getHighlightedHexesMovementTarget()
|
std::set<BattleHex> BattleFieldController::getHighlightedHexesForMovementTarget()
|
||||||
{
|
{
|
||||||
const CStack * stack = owner.stacksController->getActiveStack();
|
const CStack * stack = owner.stacksController->getActiveStack();
|
||||||
auto hoveredHex = getHoveredHex();
|
auto hoveredHex = getHoveredHex();
|
||||||
@@ -297,7 +297,7 @@ std::set<BattleHex> BattleFieldController::getHighlightedHexesMovementTarget()
|
|||||||
if(!stack)
|
if(!stack)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
std::vector<BattleHex> availableHexes = owner.curInt->cb->battleGetAvailableHexes(stack, true, false, nullptr);
|
std::vector<BattleHex> availableHexes = owner.curInt->cb->battleGetAvailableHexes(stack, false, false, nullptr);
|
||||||
|
|
||||||
auto hoveredStack = owner.curInt->cb->battleGetStackByPos(hoveredHex, true);
|
auto hoveredStack = owner.curInt->cb->battleGetStackByPos(hoveredHex, true);
|
||||||
if(owner.curInt->cb->battleCanAttack(stack, hoveredStack, hoveredHex))
|
if(owner.curInt->cb->battleCanAttack(stack, hoveredStack, hoveredHex))
|
||||||
@@ -337,7 +337,7 @@ void BattleFieldController::showHighlightedHexes(Canvas & canvas)
|
|||||||
{
|
{
|
||||||
std::set<BattleHex> hoveredStackMovementRangeHexes = getMovementRangeForHoveredStack();
|
std::set<BattleHex> hoveredStackMovementRangeHexes = getMovementRangeForHoveredStack();
|
||||||
std::set<BattleHex> hoveredSpellHexes = getHighlightedHexesForSpellRange();
|
std::set<BattleHex> hoveredSpellHexes = getHighlightedHexesForSpellRange();
|
||||||
std::set<BattleHex> hoveredMoveHexes = getHighlightedHexesMovementTarget();
|
std::set<BattleHex> hoveredMoveHexes = getHighlightedHexesForMovementTarget();
|
||||||
|
|
||||||
if(getHoveredHex() == BattleHex::INVALID)
|
if(getHoveredHex() == BattleHex::INVALID)
|
||||||
return;
|
return;
|
||||||
|
@@ -53,7 +53,7 @@ class BattleFieldController : public CIntObject
|
|||||||
std::set<BattleHex> getHighlightedHexesForActiveStack();
|
std::set<BattleHex> getHighlightedHexesForActiveStack();
|
||||||
std::set<BattleHex> getMovementRangeForHoveredStack();
|
std::set<BattleHex> getMovementRangeForHoveredStack();
|
||||||
std::set<BattleHex> getHighlightedHexesForSpellRange();
|
std::set<BattleHex> getHighlightedHexesForSpellRange();
|
||||||
std::set<BattleHex> getHighlightedHexesMovementTarget();
|
std::set<BattleHex> getHighlightedHexesForMovementTarget();
|
||||||
|
|
||||||
void showBackground(Canvas & canvas);
|
void showBackground(Canvas & canvas);
|
||||||
void showBackgroundImage(Canvas & canvas);
|
void showBackgroundImage(Canvas & canvas);
|
||||||
|
@@ -546,7 +546,7 @@ void CBattleInfoCallback::battleGetTurnOrder(std::vector<battle::Units> & turns,
|
|||||||
battleGetTurnOrder(turns, maxUnits, maxTurns, actualTurn + 1, sideThatLastMoved);
|
battleGetTurnOrder(turns, maxUnits, maxTurns, actualTurn + 1, sideThatLastMoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle::Unit * unit, bool isActiveStack) const
|
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle::Unit * unit, bool getMovementRange) const
|
||||||
{
|
{
|
||||||
|
|
||||||
RETURN_IF_NOT_BATTLE(std::vector<BattleHex>());
|
RETURN_IF_NOT_BATTLE(std::vector<BattleHex>());
|
||||||
@@ -555,10 +555,10 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle
|
|||||||
|
|
||||||
auto reachability = getReachability(unit);
|
auto reachability = getReachability(unit);
|
||||||
|
|
||||||
return battleGetAvailableHexes(reachability, unit, isActiveStack);
|
return battleGetAvailableHexes(reachability, unit, getMovementRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const ReachabilityInfo & cache, const battle::Unit * unit, bool isActiveStack) const
|
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const ReachabilityInfo & cache, const battle::Unit * unit, bool getMovementRange) const
|
||||||
{
|
{
|
||||||
std::vector<BattleHex> ret;
|
std::vector<BattleHex> ret;
|
||||||
|
|
||||||
@@ -568,7 +568,7 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const Reacha
|
|||||||
|
|
||||||
auto unitSpeed = unit->Speed(0, true);
|
auto unitSpeed = unit->Speed(0, true);
|
||||||
|
|
||||||
const bool showTacticsRange = battleTacticDist() && battleGetTacticsSide() == unit->unitSide() && isActiveStack;
|
const bool tacticsPhase = battleTacticDist() && battleGetTacticsSide() == unit->unitSide();
|
||||||
|
|
||||||
for(int i = 0; i < GameConstants::BFIELD_SIZE; ++i)
|
for(int i = 0; i < GameConstants::BFIELD_SIZE; ++i)
|
||||||
{
|
{
|
||||||
@@ -576,7 +576,7 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const Reacha
|
|||||||
if(!cache.isReachable(i))
|
if(!cache.isReachable(i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(showTacticsRange)
|
if(tacticsPhase && !getMovementRange) // if getMovementRange requested do not return tactics range
|
||||||
{
|
{
|
||||||
// Stack has to perform tactic-phase movement -> can enter any reachable tile within given range
|
// Stack has to perform tactic-phase movement -> can enter any reachable tile within given range
|
||||||
if(!isInTacticRange(i))
|
if(!isInTacticRange(i))
|
||||||
@@ -595,9 +595,9 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const Reacha
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle::Unit * unit, bool isActiveStack, bool addOccupiable, std::vector<BattleHex> * attackable) const
|
std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle::Unit * unit, bool getMovementRange, bool addOccupiable, std::vector<BattleHex> * attackable) const
|
||||||
{
|
{
|
||||||
std::vector<BattleHex> ret = battleGetAvailableHexes(unit, isActiveStack);
|
std::vector<BattleHex> ret = battleGetAvailableHexes(unit, getMovementRange);
|
||||||
|
|
||||||
if(ret.empty())
|
if(ret.empty())
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -77,12 +77,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;
|
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
|
///returns reachable hexes (valid movement destinations), DOES contain stack current position
|
||||||
std::vector<BattleHex> battleGetAvailableHexes(const battle::Unit * unit, bool isActiveStack, bool addOccupiable, std::vector<BattleHex> * attackable) const;
|
std::vector<BattleHex> battleGetAvailableHexes(const battle::Unit * unit, bool getMovementRange, bool addOccupiable, std::vector<BattleHex> * attackable) const;
|
||||||
|
|
||||||
///returns reachable hexes (valid movement destinations), DOES contain stack current position (lite version)
|
///returns reachable hexes (valid movement destinations), DOES contain stack current position (lite version)
|
||||||
std::vector<BattleHex> battleGetAvailableHexes(const battle::Unit * unit, bool isActiveStack) const;
|
std::vector<BattleHex> battleGetAvailableHexes(const battle::Unit * unit, bool getMovementRange) const;
|
||||||
|
|
||||||
std::vector<BattleHex> battleGetAvailableHexes(const ReachabilityInfo & cache, const battle::Unit * unit, bool isActiveStack) const;
|
std::vector<BattleHex> battleGetAvailableHexes(const ReachabilityInfo & cache, const battle::Unit * unit, bool getMovementRange) const;
|
||||||
|
|
||||||
int battleGetSurrenderCost(const PlayerColor & Player) const; //returns cost of surrendering battle, -1 if surrendering is not possible
|
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;
|
ReachabilityInfo::TDistances battleGetDistances(const battle::Unit * unit, BattleHex assumedPosition) const;
|
||||||
|
Reference in New Issue
Block a user