Index: binaries/data/mods/public/simulation/components/Builder.js =================================================================== --- binaries/data/mods/public/simulation/components/Builder.js +++ binaries/data/mods/public/simulation/components/Builder.js @@ -73,12 +73,16 @@ */ Builder.prototype.CanRepair = function(target) { - let cmpFoundation = QueryMiragedInterface(target, IID_Foundation); - let cmpRepairable = QueryMiragedInterface(target, IID_Repairable); + const cmpFoundation = QueryMiragedInterface(target, IID_Foundation); + const cmpRepairable = QueryMiragedInterface(target, IID_Repairable); if (!cmpFoundation && (!cmpRepairable || !cmpRepairable.IsRepairable())) return false; - let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + const targetTemplateName = cmpFoundation ? cmpFoundation.FinalTemplateName() : Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager).GetCurrentTemplateName(target); + if (!this.GetEntitiesList().some(buildable => targetTemplateName === buildable)) + return false; + + const cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); return cmpOwnership && IsOwnedByAllyOfPlayer(cmpOwnership.GetOwner(), target); }; Index: binaries/data/mods/public/simulation/components/Foundation.js =================================================================== --- binaries/data/mods/public/simulation/components/Foundation.js +++ binaries/data/mods/public/simulation/components/Foundation.js @@ -58,6 +58,11 @@ this.initialised = true; }; +Foundation.prototype.FinalTemplateName = function() +{ + return this.finalTemplateName; +}; + /** * Moving the revelation logic from Build to here makes the building sink if * it is attacked. Index: binaries/data/mods/public/simulation/components/tests/test_Builder.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_Builder.js +++ binaries/data/mods/public/simulation/components/tests/test_Builder.js @@ -107,10 +107,12 @@ { let cmpBuilder = ConstructComponent(builderId, "Builder", { "Rate": "1.0", - "Entities": { "_string": "" } + "Entities": { "_string": "structure" } }); AddMock(playerEntityID, IID_Player, { + "GetCiv": () => "gaia", + "GetDisabledTemplates": () => { return {}; }, "IsAlly": (p) => p == playerId }); @@ -124,7 +126,8 @@ increased = true; TS_ASSERT_EQUALS(amount, 1); }, - "AddBuilder": () => {} + "AddBuilder": () => {}, + "FinalTemplateName": () => "structure" }); let cmpTimer = ConstructComponent(SYSTEM_ENTITY, "Timer"); @@ -141,12 +144,19 @@ function testRepairing() { AddMock(playerEntityID, IID_Player, { + "GetCiv": () => "gaia", + "GetDisabledTemplates": () => { return {}; }, "IsAlly": (p) => p == playerId }); + AddMock(SYSTEM_ENTITY, IID_TemplateManager, { + "GetCurrentTemplateName": () => "structure", + "TemplateExists": () => true + }); + let cmpBuilder = ConstructComponent(builderId, "Builder", { "Rate": "1.0", - "Entities": { "_string": "" } + "Entities": { "_string": "structure" } }); AddMock(target, IID_Ownership, {