diff --git a/binaries/data/mods/public/simulation/components/Attack.js b/binaries/data/mods/public/simulation/components/Attack.js index a771c08df3..8240bea57a 100644 --- a/binaries/data/mods/public/simulation/components/Attack.js +++ b/binaries/data/mods/public/simulation/components/Attack.js @@ -196,7 +196,7 @@ Attack.prototype.GetRange = function(type) var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager); var max = cmpTechMan.ApplyModifications("Attack/" + type + "/MaxRange", +this.template[type].MaxRange, this.entity); - var min = cmpTechMan.ApplyModifications("Attack/" + type + "/MinRange", +this.template[type].MinRange, this.entity); + var min = cmpTechMan.ApplyModifications("Attack/" + type + "/MinRange", +(this.template[type].MinRange || 0), this.entity); this.attackCache.Range[type] = { "max": max, "min": min }; } diff --git a/binaries/data/mods/public/simulation/components/ResourceGatherer.js b/binaries/data/mods/public/simulation/components/ResourceGatherer.js index 57af88cc04..12343bec29 100644 --- a/binaries/data/mods/public/simulation/components/ResourceGatherer.js +++ b/binaries/data/mods/public/simulation/components/ResourceGatherer.js @@ -79,7 +79,7 @@ ResourceGatherer.prototype.GetCarryingStatus = function() ret.push({ "type": type, "amount": this.carrying[type], - "max": +this.template.Capacities[type] + "max": +this.GetCapacities()[type] }); } return ret; @@ -135,13 +135,17 @@ ResourceGatherer.prototype.OnTechnologyModificationChange = function(msg) var player = cmpOwnership.GetOwner(); if (msg.component === "ResourceGatherer" && msg.player === player) + { delete this.gatherRatesCache; + delete this.capacitiesCache; + } }; // Remove any cached template data which is based on technology data ResourceGatherer.prototype.OnOwnershipChanged = function(msg) { delete this.gatherRatesCache; + delete this.capacitiesCache; }; ResourceGatherer.prototype.GetGatherRates = function() @@ -161,6 +165,22 @@ ResourceGatherer.prototype.GetGatherRates = function() return this.gatherRatesCache; }; +ResourceGatherer.prototype.GetCapacities = function() +{ + if (!this.capacitiesCache) + { + this.capacitiesCache = {}; + var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager); + + for (var r in this.template.Capacities) + { + this.capacitiesCache[r] = cmpTechMan.ApplyModifications("ResourceGatherer/Capacities/" + r, this.template.Capacities[r], this.entity); + } + } + + return this.capacitiesCache; +}; + ResourceGatherer.prototype.GetRange = function() { return { "max": +this.template.MaxDistance, "min": 0 }; @@ -209,7 +229,7 @@ ResourceGatherer.prototype.PerformGather = function(target) this.carrying[type.generic] = 0; // Find the maximum so we won't exceed our capacity - var maxGathered = this.template.Capacities[type.generic] - this.carrying[type.generic]; + var maxGathered = this.GetCapacities()[type.generic] - this.carrying[type.generic]; var status = cmpResourceSupply.TakeResources(Math.min(rate, maxGathered)); @@ -233,7 +253,7 @@ ResourceGatherer.prototype.PerformGather = function(target) return { "amount": status.amount, "exhausted": status.exhausted, - "filled": (this.carrying[type.generic] >= this.template.Capacities[type.generic]) + "filled": (this.carrying[type.generic] >= this.GetCapacities()[type.generic]) }; }; @@ -267,7 +287,7 @@ ResourceGatherer.prototype.GetTargetGatherRate = function(target) ResourceGatherer.prototype.CanCarryMore = function(type) { var amount = (this.carrying[type] || 0); - return (amount < this.template.Capacities[type]); + return (amount < this.GetCapacities()[type]); }; /**