Index: ps/trunk/binaries/data/mods/public/maps/scenarios/unit_pushing_test.js =================================================================== --- ps/trunk/binaries/data/mods/public/maps/scenarios/unit_pushing_test.js +++ ps/trunk/binaries/data/mods/public/maps/scenarios/unit_pushing_test.js @@ -117,7 +117,7 @@ Do("repair", { "target": target }, QuickSpawn(gx + i, gy, REG_UNIT_TEMPLATE)); let cmpFoundation = Engine.QueryInterface(target, IID_Foundation); - cmpFoundation.InitialiseConstruction(1, "structures/athen/storehouse"); + cmpFoundation.InitialiseConstruction("structures/athen/storehouse"); } }; Index: ps/trunk/binaries/data/mods/public/simulation/components/Cost.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/Cost.js +++ ps/trunk/binaries/data/mods/public/simulation/components/Cost.js @@ -38,21 +38,20 @@ return ApplyValueModificationsToEntity("Cost/BuildTime", +this.template.BuildTime, this.entity); }; -Cost.prototype.GetResourceCosts = function(owner) +Cost.prototype.GetResourceCosts = function() { - if (!owner) + let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + if (!cmpOwnership) { - let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); - if (!cmpOwnership) - error("GetResourceCosts called without valid ownership"); - else - owner = cmpOwnership.GetOwner(); + error("GetResourceCosts called without valid ownership on " + this.entity + "."); + return {}; } let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); let entityTemplateName = cmpTemplateManager.GetCurrentTemplateName(this.entity); let entityTemplate = cmpTemplateManager.GetTemplate(entityTemplateName); + let owner = cmpOwnership.GetOwner(); let costs = {}; for (let res in this.template.Resources) costs[res] = ApplyValueModificationsToTemplate("Cost/Resources/"+res, +this.template.Resources[res], owner, entityTemplate); Index: ps/trunk/binaries/data/mods/public/simulation/components/Foundation.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/Foundation.js +++ ps/trunk/binaries/data/mods/public/simulation/components/Foundation.js @@ -38,21 +38,17 @@ this.CreateConstructionPreview(); }; -Foundation.prototype.InitialiseConstruction = function(owner, template) +Foundation.prototype.InitialiseConstruction = function(template) { this.finalTemplateName = template; - // We need to know the owner in OnDestroy, but at that point the entity has already been - // decoupled from its owner, so we need to remember it in here (and assume it won't change) - this.owner = owner; - // Remember the cost here, so if it changes after construction begins (from auras or technologies) - // we will use the correct values to refund partial construction costs + // we will use the correct values to refund partial construction costs. let cmpCost = Engine.QueryInterface(this.entity, IID_Cost); if (!cmpCost) - error("A foundation must have a cost component to know the build time"); + error("A foundation, from " + template + ", must have a cost component to know the build time"); - this.costs = cmpCost.GetResourceCosts(owner); + this.costs = cmpCost.GetResourceCosts(); this.maxProgress = 0; @@ -140,7 +136,9 @@ if (this.IsFinished()) return; - let cmpPlayer = QueryPlayerIDInterface(this.owner); + let cmpPlayer = QueryPlayerIDInterface(msg.from); + if (!cmpPlayer) + return; for (var r in this.costs) { @@ -148,7 +146,7 @@ if (scaled) { cmpPlayer.AddResource(r, scaled); - var cmpStatisticsTracker = QueryPlayerIDInterface(this.owner, IID_StatisticsTracker); + var cmpStatisticsTracker = QueryPlayerIDInterface(msg.from, IID_StatisticsTracker); if (cmpStatisticsTracker) cmpStatisticsTracker.IncreaseResourceUsedCounter(r, -scaled); } Index: ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Foundation.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Foundation.js +++ ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Foundation.js @@ -128,9 +128,8 @@ return previewEnt; }; cmpFoundation = ConstructComponent(foundationEnt, "Foundation", {}); - cmpFoundation.InitialiseConstruction(player, finalTemplate); + cmpFoundation.InitialiseConstruction(finalTemplate); - TS_ASSERT_EQUALS(cmpFoundation.owner, player); TS_ASSERT_EQUALS(cmpFoundation.finalTemplateName, finalTemplate); TS_ASSERT_EQUALS(cmpFoundation.maxProgress, 0); TS_ASSERT_EQUALS(cmpFoundation.initialised, true); @@ -243,7 +242,7 @@ "Rate": "1.0" }); -cmpAutoBuildingFoundation.InitialiseConstruction(player, finalTemplate); +cmpAutoBuildingFoundation.InitialiseConstruction(finalTemplate); // We start at 3 cause there is no delay on the first run. cmpTimer.OnUpdate({ "turnLength": turnLength }); Index: ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js +++ ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js @@ -1181,10 +1181,9 @@ Engine.DestroyEntity(ent); } - // We need the cost after tech and aura modifications - // To calculate this with an entity requires ownership, so use the template instead + // We need the cost after tech and aura modifications. let cmpCost = Engine.QueryInterface(ent, IID_Cost); - let costs = cmpCost.GetResourceCosts(player); + let costs = cmpCost.GetResourceCosts(); if (!cmpPlayer.TrySubtractResources(costs)) { @@ -1202,7 +1201,7 @@ // Initialise the foundation var cmpFoundation = Engine.QueryInterface(ent, IID_Foundation); - cmpFoundation.InitialiseConstruction(player, cmd.template); + cmpFoundation.InitialiseConstruction(cmd.template); // send Metadata info if any if (cmd.metadata)