0ad/binaries/data/mods/public/simulation/components/tests/test_BuildRestrictions.js
Stan 167020c05c
Fix broken build restrictions
In f3ac9e9669 the fail condition was broken causing it to allow building on restricted areas.

Add a test to ensure correct behavior for this case.

Reported by: @wowgetoffyourcellphone
Pull Request: #8021
2025-05-31 10:58:14 +02:00

30 lines
795 B
JavaScript

Engine.LoadComponentScript("interfaces/BuildRestrictions.js");
Engine.LoadComponentScript("BuildRestrictions.js");
{
const entity = 10;
const QueryOwnerInterface = () => ({
"GetPlayerID": () => 1,
"IsAI": () => false
});
Engine.RegisterGlobal("QueryOwnerInterface", QueryOwnerInterface);
const cmpBuildRestrictions = ConstructComponent(entity, "BuildRestrictions", {
"PlacementType": "land"
});
AddMock(SYSTEM_ENTITY, IID_RangeManager, {
"GetLosVisibility": (_, __) => "visible",
"GetEntitiesByPlayer": () => []
});
AddMock(entity, IID_Ownership, {
"GetOwner": () => 1
});
AddMock(entity, IID_Obstruction, {
"CheckFoundation": () => "fail_obstructs_foundation"
});
const result = cmpBuildRestrictions.CheckPlacement();
TS_ASSERT_EQUALS(result.success, false);
}