mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
Refactor destructibleEnemyTurns
This commit is contained in:
@@ -22,9 +22,10 @@ bool AccessibilityInfo::tileAccessibleWithGate(BattleHex tile, BattleSide side)
|
|||||||
|
|
||||||
if(accessibility == EAccessibility::ALIVE_STACK)
|
if(accessibility == EAccessibility::ALIVE_STACK)
|
||||||
{
|
{
|
||||||
auto destructible = destructibleEnemyTurns.find(tile);
|
if(!destructibleEnemyTurns)
|
||||||
|
return false;
|
||||||
|
|
||||||
return destructible != destructibleEnemyTurns.end();
|
return destructibleEnemyTurns->at(tile.hex) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(accessibility != EAccessibility::ACCESSIBLE)
|
if(accessibility != EAccessibility::ACCESSIBLE)
|
||||||
|
@@ -27,7 +27,7 @@ enum class EAccessibility
|
|||||||
DESTRUCTIBLE_WALL,
|
DESTRUCTIBLE_WALL,
|
||||||
GATE, //sieges -> gate opens only for defender stacks
|
GATE, //sieges -> gate opens only for defender stacks
|
||||||
UNAVAILABLE, //indestructible wall parts, special battlefields (like boat-to-boat)
|
UNAVAILABLE, //indestructible wall parts, special battlefields (like boat-to-boat)
|
||||||
SIDE_COLUMN //used for first and last columns of hexes that are unavailable but wat machines can stand there
|
SIDE_COLUMN //used for first and last columns of hexes that are unavailable but war machines can stand there
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ using TAccessibilityArray = std::array<EAccessibility, GameConstants::BFIELD_SIZ
|
|||||||
|
|
||||||
struct DLL_LINKAGE AccessibilityInfo : TAccessibilityArray
|
struct DLL_LINKAGE AccessibilityInfo : TAccessibilityArray
|
||||||
{
|
{
|
||||||
std::map<BattleHex, ui8> destructibleEnemyTurns;
|
const std::array<int8_t, GameConstants::BFIELD_SIZE> * destructibleEnemyTurns = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool accessible(BattleHex tile, const battle::Unit * stack) const; //checks for both tiles if stack is double wide
|
bool accessible(BattleHex tile, const battle::Unit * stack) const; //checks for both tiles if stack is double wide
|
||||||
|
@@ -1083,28 +1083,25 @@ ReachabilityInfo CBattleInfoCallback::makeBFS(const AccessibilityInfo &accessibi
|
|||||||
|
|
||||||
for(BattleHex neighbour : BattleHexArray::neighbouringTilesCache[curHex.hex])
|
for(BattleHex neighbour : BattleHexArray::neighbouringTilesCache[curHex.hex])
|
||||||
{
|
{
|
||||||
if(neighbour.isValid())
|
auto additionalCost = 0;
|
||||||
|
|
||||||
|
if(params.bypassEnemyStacks)
|
||||||
{
|
{
|
||||||
auto additionalCost = 0;
|
auto enemyToBypass = params.destructibleEnemyTurns.at(neighbour);
|
||||||
|
|
||||||
if(params.bypassEnemyStacks)
|
if(enemyToBypass >= 0)
|
||||||
{
|
{
|
||||||
auto enemyToBypass = params.destructibleEnemyTurns.find(neighbour);
|
additionalCost = enemyToBypass;
|
||||||
|
|
||||||
if(enemyToBypass != params.destructibleEnemyTurns.end())
|
|
||||||
{
|
|
||||||
additionalCost = enemyToBypass->second;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const int costFoundSoFar = ret.distances[neighbour.hex];
|
const int costFoundSoFar = ret.distances[neighbour.hex];
|
||||||
|
|
||||||
if(accessibleCache[neighbour.hex] && costToNeighbour + additionalCost < costFoundSoFar)
|
if(accessibleCache[neighbour.hex] && costToNeighbour + additionalCost < costFoundSoFar)
|
||||||
{
|
{
|
||||||
hexq.push(neighbour);
|
hexq.push(neighbour);
|
||||||
ret.distances[neighbour.hex] = costToNeighbour + additionalCost;
|
ret.distances[neighbour.hex] = costToNeighbour + additionalCost;
|
||||||
ret.predecessors[neighbour.hex] = curHex;
|
ret.predecessors[neighbour.hex] = curHex;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1280,7 +1277,7 @@ ReachabilityInfo CBattleInfoCallback::getReachability(const ReachabilityInfo::Pa
|
|||||||
{
|
{
|
||||||
auto accessibility = getAccessibility(params.knownAccessible);
|
auto accessibility = getAccessibility(params.knownAccessible);
|
||||||
|
|
||||||
accessibility.destructibleEnemyTurns = params.destructibleEnemyTurns;
|
accessibility.destructibleEnemyTurns = & params.destructibleEnemyTurns;
|
||||||
|
|
||||||
return makeBFS(accessibility, params);
|
return makeBFS(accessibility, params);
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ ReachabilityInfo::Parameters::Parameters(const battle::Unit * Stack, BattleHex S
|
|||||||
flying(Stack->hasBonusOfType(BonusType::FLYING))
|
flying(Stack->hasBonusOfType(BonusType::FLYING))
|
||||||
{
|
{
|
||||||
knownAccessible = battle::Unit::getHexes(startPosition, doubleWide, side);
|
knownAccessible = battle::Unit::getHexes(startPosition, doubleWide, side);
|
||||||
|
destructibleEnemyTurns.fill(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReachabilityInfo::ReachabilityInfo()
|
ReachabilityInfo::ReachabilityInfo()
|
||||||
|
@@ -33,12 +33,15 @@ struct DLL_LINKAGE ReachabilityInfo
|
|||||||
bool ignoreKnownAccessible = false; //Ignore obstacles if it is in accessible hexes
|
bool ignoreKnownAccessible = false; //Ignore obstacles if it is in accessible hexes
|
||||||
bool bypassEnemyStacks = false; // in case of true will count amount of turns needed to kill enemy and thus move forward
|
bool bypassEnemyStacks = false; // in case of true will count amount of turns needed to kill enemy and thus move forward
|
||||||
BattleHexArray knownAccessible; //hexes that will be treated as accessible, even if they're occupied by stack (by default - tiles occupied by stack we do reachability for, so it doesn't block itself)
|
BattleHexArray knownAccessible; //hexes that will be treated as accessible, even if they're occupied by stack (by default - tiles occupied by stack we do reachability for, so it doesn't block itself)
|
||||||
std::map<BattleHex, ui8> destructibleEnemyTurns; // hom many turns it is needed to kill enemy on specific hex
|
std::array<int8_t, GameConstants::BFIELD_SIZE> destructibleEnemyTurns; // how many turns it is needed to kill enemy on specific hex (index <=> hex)
|
||||||
|
|
||||||
BattleHex startPosition; //assumed position of stack
|
BattleHex startPosition; //assumed position of stack
|
||||||
BattleSide perspective = BattleSide::ALL_KNOWING; //some obstacles (eg. quicksands) may be invisible for some side
|
BattleSide perspective = BattleSide::ALL_KNOWING; //some obstacles (eg. quicksands) may be invisible for some side
|
||||||
|
|
||||||
Parameters() = default;
|
Parameters()
|
||||||
|
{
|
||||||
|
destructibleEnemyTurns.fill(-1);
|
||||||
|
}
|
||||||
Parameters(const battle::Unit * Stack, BattleHex StartPosition);
|
Parameters(const battle::Unit * Stack, BattleHex StartPosition);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user