Index: binaries/data/mods/public/simulation/components/ResourceGatherer.js =================================================================== --- binaries/data/mods/public/simulation/components/ResourceGatherer.js +++ binaries/data/mods/public/simulation/components/ResourceGatherer.js @@ -294,22 +294,32 @@ /** * Transfer our carried resources to our owner immediately. - * Only resources of the given types will be transferred. - * (This should typically be called after reaching a dropsite). + * Only resources of the appropriate types will be transferred. + * (This should typically be called after reaching a dropsite.) + * + * @param {number} target - The target entity ID to drop resources at. */ -ResourceGatherer.prototype.CommitResources = function(types) +ResourceGatherer.prototype.CommitResources = function(target) { + let cmpResourceDropsite = Engine.QueryInterface(target, IID_ResourceDropsite); + if (!cmpResourceDropsite) + return; + let cmpPlayer = QueryOwnerInterface(this.entity); + if (!cmpPlayer) + return; - if (cmpPlayer) - for (let type of types) - if (type in this.carrying) - { - cmpPlayer.AddResource(type, this.carrying[type]); - delete this.carrying[type]; - } + let changed = false; + for (let type in this.carrying) + if (cmpResourceDropsite.AcceptsType(type)) + { + cmpPlayer.AddResource(type, this.carrying[type]); + delete this.carrying[type]; + changed = true; + } - Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); + if (changed) + Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); }; /** Index: binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/UnitAI.js +++ binaries/data/mods/public/simulation/components/UnitAI.js @@ -581,18 +581,16 @@ // Check if the dropsite is already in range if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && this.CanReturnResource(this.order.data.target, true)) { - var cmpResourceDropsite = Engine.QueryInterface(this.order.data.target, IID_ResourceDropsite); - if (cmpResourceDropsite) + let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); + if (cmpResourceGatherer) { - // Dump any resources we can - var dropsiteTypes = cmpResourceDropsite.GetTypes(); + cmpResourceGatherer.CommitResources(this.order.data.target); - Engine.QueryInterface(this.entity, IID_ResourceGatherer).CommitResources(dropsiteTypes); // Stop showing the carried resource animation. this.SetDefaultAnimationVariant(); // Our next order should always be a Gather, - // so just switch back to that order + // so just switch back to that order. this.FinishOrder(); return; } @@ -2704,20 +2702,16 @@ // (we didn't get stopped before reaching it) if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && this.CanReturnResource(this.order.data.target, true)) { - let cmpResourceDropsite = Engine.QueryInterface(this.order.data.target, IID_ResourceDropsite); - if (cmpResourceDropsite) + let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); + if (cmpResourceGatherer) { - // Dump any resources we can - let dropsiteTypes = cmpResourceDropsite.GetTypes(); - - let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); - cmpResourceGatherer.CommitResources(dropsiteTypes); + cmpResourceGatherer.CommitResources(this.order.data.target); // Stop showing the carried resource animation. this.SetDefaultAnimationVariant(); // Our next order should always be a Gather, - // so just switch back to that order + // so just switch back to that order. this.FinishOrder(); return; } @@ -2906,12 +2900,10 @@ // Drop any resource we can if we are in range when the construction finishes let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); - let cmpResourceDropsite = Engine.QueryInterface(msg.data.newentity, IID_ResourceDropsite); - if (cmpResourceGatherer && cmpResourceDropsite && this.CheckTargetRange(msg.data.newentity, IID_Builder) && + if (cmpResourceGatherer && this.CheckTargetRange(msg.data.newentity, IID_Builder) && this.CanReturnResource(msg.data.newentity, true)) { - let dropsiteTypes = cmpResourceDropsite.GetTypes(); - cmpResourceGatherer.CommitResources(dropsiteTypes); + cmpResourceGatherer.CommitResources(msg.data.newentity); this.SetDefaultAnimationVariant(); } @@ -2951,6 +2943,7 @@ // the build command should look for nearby resources to gather if ((oldData.force || oldData.autoharvest) && this.CanReturnResource(msg.data.newentity, false)) { + let cmpResourceDropsite = Engine.QueryInterface(msg.data.newentity, IID_ResourceDropsite); let types = cmpResourceDropsite.GetTypes(); let pos; let cmpPosition = Engine.QueryInterface(msg.data.newentity, IID_Position); @@ -3066,18 +3059,12 @@ } } - // Check if we are garrisoned in a dropsite - var cmpResourceDropsite = Engine.QueryInterface(target, IID_ResourceDropsite); - if (cmpResourceDropsite && this.CanReturnResource(target, true)) + // Check if we are garrisoned in a dropsite. + let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); + if (cmpResourceGatherer && this.CanReturnResource(target, true)) { - // Dump any resources we can - var dropsiteTypes = cmpResourceDropsite.GetTypes(); - var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); - if (cmpResourceGatherer) - { - cmpResourceGatherer.CommitResources(dropsiteTypes); - this.SetDefaultAnimationVariant(); - } + cmpResourceGatherer.CommitResources(target); + this.SetDefaultAnimationVariant(); } // If a pickup has been requested, remove it