mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Tactics movement is limited to movement range
This commit is contained in:
parent
c899956e71
commit
e348193f7e
@ -282,7 +282,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, true);
|
||||
auto avHexes = cb->battleGetAvailableHexes(reachability, stack, false);
|
||||
|
||||
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 reachability = state.getReachability(attackerInfo);
|
||||
auto avHexes = state.battleGetAvailableHexes(reachability, attackerInfo, true);
|
||||
auto avHexes = state.battleGetAvailableHexes(reachability, attackerInfo, false);
|
||||
|
||||
//FIXME: this should part of battleGetAvailableHexes
|
||||
bool forceTarget = false;
|
||||
|
@ -120,7 +120,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack )
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<BattleHex> avHexes = cb->battleGetAvailableHexes(stack, true);
|
||||
std::vector<BattleHex> avHexes = cb->battleGetAvailableHexes(stack, false);
|
||||
|
||||
for (BattleHex hex : avHexes)
|
||||
{
|
||||
|
@ -620,7 +620,7 @@ void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, B
|
||||
{
|
||||
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);
|
||||
if(vstd::contains(acc, targetHex))
|
||||
owner.giveCommand(EActionType::WALK, targetHex);
|
||||
|
@ -174,7 +174,7 @@ void BattleFieldController::redrawBackgroundWithHexes()
|
||||
const CStack *activeStack = owner.stacksController->getActiveStack();
|
||||
std::vector<BattleHex> attackableHexes;
|
||||
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
|
||||
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);
|
||||
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)
|
||||
result.insert(hex);
|
||||
}
|
||||
@ -289,7 +289,7 @@ std::set<BattleHex> BattleFieldController::getHighlightedHexesForSpellRange()
|
||||
return result;
|
||||
}
|
||||
|
||||
std::set<BattleHex> BattleFieldController::getHighlightedHexesMovementTarget()
|
||||
std::set<BattleHex> BattleFieldController::getHighlightedHexesForMovementTarget()
|
||||
{
|
||||
const CStack * stack = owner.stacksController->getActiveStack();
|
||||
auto hoveredHex = getHoveredHex();
|
||||
@ -297,7 +297,7 @@ std::set<BattleHex> BattleFieldController::getHighlightedHexesMovementTarget()
|
||||
if(!stack)
|
||||
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);
|
||||
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> hoveredSpellHexes = getHighlightedHexesForSpellRange();
|
||||
std::set<BattleHex> hoveredMoveHexes = getHighlightedHexesMovementTarget();
|
||||
std::set<BattleHex> hoveredMoveHexes = getHighlightedHexesForMovementTarget();
|
||||
|
||||
if(getHoveredHex() == BattleHex::INVALID)
|
||||
return;
|
||||
|
@ -53,7 +53,7 @@ class BattleFieldController : public CIntObject
|
||||
std::set<BattleHex> getHighlightedHexesForActiveStack();
|
||||
std::set<BattleHex> getMovementRangeForHoveredStack();
|
||||
std::set<BattleHex> getHighlightedHexesForSpellRange();
|
||||
std::set<BattleHex> getHighlightedHexesMovementTarget();
|
||||
std::set<BattleHex> getHighlightedHexesForMovementTarget();
|
||||
|
||||
void showBackground(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);
|
||||
}
|
||||
|
||||
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>());
|
||||
@ -555,10 +555,10 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle
|
||||
|
||||
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;
|
||||
|
||||
@ -568,7 +568,7 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const Reacha
|
||||
|
||||
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)
|
||||
{
|
||||
@ -576,7 +576,7 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const Reacha
|
||||
if(!cache.isReachable(i))
|
||||
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
|
||||
if(!isInTacticRange(i))
|
||||
@ -595,9 +595,9 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const Reacha
|
||||
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())
|
||||
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;
|
||||
|
||||
///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)
|
||||
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
|
||||
ReachabilityInfo::TDistances battleGetDistances(const battle::Unit * unit, BattleHex assumedPosition) const;
|
||||
|
Loading…
Reference in New Issue
Block a user