Recompute fire-cleared map hash (#8768)

This commit is contained in:
2026-07-24 07:38:38 -07:00
committed by GitHub
parent a148a8a2a3
commit 6a91935a1f
2 changed files with 32 additions and 1 deletions
@@ -55,7 +55,7 @@ auto UnitIdsRequiringWaterCrossing(
.mutate_present(false);
}
const auto mapId = ActionPointDistancesCache::GetMapId(mapCopy);
const auto mapId = RecomputeModifierHash(mapCopy.Get());
vector<UnitId> unitIdsToReturn{};
@@ -19,6 +19,7 @@ class AIWaterCrossingCalculatorTest : public ::testing::Test {
InitializeGameSettings();
apdCache = std::make_shared<ActionPointDistancesCache>();
ActionPointDistancesCache::ClearThreadLocalCache();
heavyCavalry = GetGameSettingsGetter().GetBattalionType(
net::eagle0::shardok::storage::fb::BattalionTypeId_HEAVY_CAVALRY);
@@ -148,6 +149,36 @@ TEST_F(AIWaterCrossingCalculatorTest, UnitsRequiringWaterCrossing_oneOtherSide_r
}));
}
TEST_F(AIWaterCrossingCalculatorTest,
UnitsRequiringWaterCrossing_fireChanges_reusesFireClearedDistances) {
CoordsSet destinations(hexMap);
destinations.Add(acrossDestination);
const auto battalionTypeGetter = [](BattalionTypeId typeId) {
return GetGameSettings()->GetGetter().GetBattalionType(typeId);
};
const auto beforeFire = UnitIdsRequiringWaterCrossing(
gameState,
0,
destinations,
apdCache,
battalionTypeGetter);
EXPECT_EQ(1, ActionPointDistancesCache::GetThreadLocalCacheSize());
MutableTerrain(hexMap, Coords(0, 0))->mutable_modifier().mutable_fire().mutate_present(true);
hexMap->mutate_modifier_hash(0);
hexMap->mutate_modifier_hash(ActionPointDistancesCache::GetMapId(hexMap).modifierId);
const auto afterFire = UnitIdsRequiringWaterCrossing(
gameState,
0,
destinations,
apdCache,
battalionTypeGetter);
EXPECT_EQ(beforeFire, afterFire);
EXPECT_EQ(1, ActionPointDistancesCache::GetThreadLocalCacheSize());
}
TEST_F(AIWaterCrossingCalculatorTest, CanReach_sameSide_returnsTrue) {
EXPECT_TRUE(CanReach(origin, sameSideDestination, hexMap, mapId, apdCache, heavyCavalry));
}