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)
|
||||
{
|
||||
auto destructible = destructibleEnemyTurns.find(tile);
|
||||
if(!destructibleEnemyTurns)
|
||||
return false;
|
||||
|
||||
return destructible != destructibleEnemyTurns.end();
|
||||
return destructibleEnemyTurns->at(tile.hex) >= 0;
|
||||
}
|
||||
|
||||
if(accessibility != EAccessibility::ACCESSIBLE)
|
||||
|
@@ -27,7 +27,7 @@ enum class EAccessibility
|
||||
DESTRUCTIBLE_WALL,
|
||||
GATE, //sieges -> gate opens only for defender stacks
|
||||
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
|
||||
{
|
||||
std::map<BattleHex, ui8> destructibleEnemyTurns;
|
||||
const std::array<int8_t, GameConstants::BFIELD_SIZE> * destructibleEnemyTurns = nullptr;
|
||||
|
||||
public:
|
||||
bool accessible(BattleHex tile, const battle::Unit * stack) const; //checks for both tiles if stack is double wide
|
||||
|
@@ -1082,18 +1082,16 @@ ReachabilityInfo CBattleInfoCallback::makeBFS(const AccessibilityInfo &accessibi
|
||||
const int costToNeighbour = ret.distances.at(curHex.hex) + 1;
|
||||
|
||||
for(BattleHex neighbour : BattleHexArray::neighbouringTilesCache[curHex.hex])
|
||||
{
|
||||
if(neighbour.isValid())
|
||||
{
|
||||
auto additionalCost = 0;
|
||||
|
||||
if(params.bypassEnemyStacks)
|
||||
{
|
||||
auto enemyToBypass = params.destructibleEnemyTurns.find(neighbour);
|
||||
auto enemyToBypass = params.destructibleEnemyTurns.at(neighbour);
|
||||
|
||||
if(enemyToBypass != params.destructibleEnemyTurns.end())
|
||||
if(enemyToBypass >= 0)
|
||||
{
|
||||
additionalCost = enemyToBypass->second;
|
||||
additionalCost = enemyToBypass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1107,7 +1105,6 @@ ReachabilityInfo CBattleInfoCallback::makeBFS(const AccessibilityInfo &accessibi
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1280,7 +1277,7 @@ ReachabilityInfo CBattleInfoCallback::getReachability(const ReachabilityInfo::Pa
|
||||
{
|
||||
auto accessibility = getAccessibility(params.knownAccessible);
|
||||
|
||||
accessibility.destructibleEnemyTurns = params.destructibleEnemyTurns;
|
||||
accessibility.destructibleEnemyTurns = & params.destructibleEnemyTurns;
|
||||
|
||||
return makeBFS(accessibility, params);
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ ReachabilityInfo::Parameters::Parameters(const battle::Unit * Stack, BattleHex S
|
||||
flying(Stack->hasBonusOfType(BonusType::FLYING))
|
||||
{
|
||||
knownAccessible = battle::Unit::getHexes(startPosition, doubleWide, side);
|
||||
destructibleEnemyTurns.fill(-1);
|
||||
}
|
||||
|
||||
ReachabilityInfo::ReachabilityInfo()
|
||||
|
@@ -33,12 +33,15 @@ struct DLL_LINKAGE ReachabilityInfo
|
||||
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
|
||||
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
|
||||
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);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user