mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:29:50 +00:00
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
This commit is contained in:
@@ -151,23 +151,25 @@ BuildRestrictions.prototype.CheckPlacement = function()
|
||||
var ret = cmpObstruction.CheckFoundation(passClassName, false);
|
||||
}
|
||||
|
||||
if (ret != "success")
|
||||
if (ret !== "success")
|
||||
{
|
||||
switch (ret)
|
||||
{
|
||||
case "fail_error":
|
||||
case "fail_no_obstruction":
|
||||
error("CheckPlacement: Error returned from CheckFoundation");
|
||||
break;
|
||||
case "fail_obstructs_foundation":
|
||||
result.message = markForTranslation("%(name)s cannot be built on another building or resource");
|
||||
break;
|
||||
case "fail_terrain_class":
|
||||
// TODO: be more specific and/or list valid terrain?
|
||||
result.message = markForTranslation("%(name)s cannot be built on invalid terrain");
|
||||
break;
|
||||
case "fail_error":
|
||||
case "fail_no_obstruction":
|
||||
default:
|
||||
return result; // Fail
|
||||
error(`CheckPlacement: Error returned from CheckFoundation. Got reason: '${ret}'`);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check territory restrictions
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user