mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
While they often look alike, their behaviour is totally different. This split has some implications: - There are now separate auras for garrisoning and turrets. - Entities can now have both turret points and garrison slots, independent of eachother. In general previous behaviour is maintained as much as possible. Differential revision: D3150 Comments by: @Nescio, @wraitii Tested by: @v32itas This was SVN commit r25123.
58 lines
2 KiB
JavaScript
58 lines
2 KiB
JavaScript
Engine.LoadHelperScript("Position.js");
|
|
Engine.LoadComponentScript("interfaces/Garrisonable.js");
|
|
Engine.LoadComponentScript("interfaces/GarrisonHolder.js");
|
|
Engine.LoadComponentScript("interfaces/Health.js");
|
|
Engine.LoadComponentScript("interfaces/UnitAI.js");
|
|
Engine.LoadComponentScript("Garrisonable.js");
|
|
|
|
Engine.RegisterGlobal("ApplyValueModificationsToEntity", (prop, oVal, ent) => oVal);
|
|
|
|
const garrisonHolderID = 1;
|
|
const garrisonableID = 2;
|
|
AddMock(garrisonHolderID, IID_GarrisonHolder, {
|
|
"Garrison": () => true,
|
|
"IsAllowedToGarrison": () => true,
|
|
"Eject": () => true
|
|
});
|
|
|
|
AddMock(garrisonHolderID, IID_Footprint, {
|
|
"PickSpawnPointBothPass": entity => new Vector3D(4, 3, 30),
|
|
"PickSpawnPoint": entity => new Vector3D(4, 3, 30)
|
|
});
|
|
|
|
let size = 1;
|
|
let cmpGarrisonable = ConstructComponent(garrisonableID, "Garrisonable", {
|
|
"Size": size
|
|
});
|
|
|
|
TS_ASSERT_EQUALS(cmpGarrisonable.UnitSize(), size);
|
|
TS_ASSERT_EQUALS(cmpGarrisonable.TotalSize(), size);
|
|
|
|
let extraSize = 2;
|
|
AddMock(garrisonableID, IID_GarrisonHolder, {
|
|
"OccupiedSlots": () => extraSize
|
|
});
|
|
|
|
TS_ASSERT_EQUALS(cmpGarrisonable.UnitSize(), size);
|
|
TS_ASSERT_EQUALS(cmpGarrisonable.TotalSize(), size + extraSize);
|
|
|
|
// Test garrisoning.
|
|
|
|
TS_ASSERT(cmpGarrisonable.Garrison(garrisonHolderID));
|
|
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), garrisonHolderID);
|
|
|
|
TS_ASSERT(!cmpGarrisonable.Garrison(garrisonHolderID));
|
|
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), garrisonHolderID);
|
|
|
|
TS_ASSERT(cmpGarrisonable.UnGarrison());
|
|
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), INVALID_ENTITY);
|
|
|
|
// Test renaming.
|
|
const newGarrisonableID = 3;
|
|
let cmpGarrisonableNew = ConstructComponent(newGarrisonableID, "Garrisonable", {
|
|
"Size": 1
|
|
});
|
|
TS_ASSERT(cmpGarrisonable.Garrison(garrisonHolderID));
|
|
cmpGarrisonable.OnEntityRenamed({ "entity": garrisonableID, "newentity": newGarrisonableID });
|
|
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), INVALID_ENTITY);
|
|
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonableNew.HolderID(), garrisonHolderID);
|