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 @@ -2258,9 +2258,9 @@ { // Check that we can gather from the resource we're supposed to gather from. // Will only be added if we're not already in. - var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); - var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); - if (!cmpSupply || !cmpSupply.AddGatherer(cmpOwnership.GetOwner(), this.entity)) + let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + let cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); + if (!cmpOwnership || !cmpSupply || !cmpSupply.AddGatherer(cmpOwnership.GetOwner(), this.entity)) { this.gatheringTarget = INVALID_ENTITY; this.StartTimer(0); @@ -2275,8 +2275,8 @@ // Calculate timing based on gather rates // This allows the gather rate to control how often we gather, instead of how much. - var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); - var rate = cmpResourceGatherer.GetTargetGatherRate(this.gatheringTarget); + let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); + let rate = cmpResourceGatherer.GetTargetGatherRate(this.gatheringTarget); if (!rate) { @@ -2295,9 +2295,8 @@ // Scale timing interval based on rate, and start timer // The offset should be at least as long as the repeat time so we use the same value for both. - var offset = 1000/rate; - var repeat = offset; - this.StartTimer(offset, repeat); + let offset = 1000 / rate; + this.StartTimer(offset, offset); // We want to start the gather animation as soon as possible, // but only if we're actually at the target and it's still alive @@ -2308,7 +2307,7 @@ { this.StopMoving(); this.SetDefaultAnimationVariant(); - var typename = "gather_" + this.order.data.type.specific; + let typename = "gather_" + this.order.data.type.specific; this.SelectAnimation(typename); } return false; @@ -2317,9 +2316,9 @@ "leave": function() { this.StopTimer(); - // don't use ownership because this is called after a conversion/resignation + // Don't use ownership because this is called after a conversion/resignation // and the ownership would be invalid then. - var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); + let cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); if (cmpSupply) cmpSupply.RemoveGatherer(this.entity); delete this.gatheringTarget; @@ -2329,22 +2328,21 @@ }, "Timer": function(msg) { - var resourceTemplate = this.order.data.template; - var resourceType = this.order.data.type; - - var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); if (!cmpOwnership) return; - var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); + let resourceTemplate = this.order.data.template; + let resourceType = this.order.data.type; + + let cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); if (cmpSupply && cmpSupply.IsAvailable(cmpOwnership.GetOwner(), this.entity)) { // Check we can still reach and gather from the target - if (this.CheckTargetRange(this.gatheringTarget, IID_ResourceGatherer) && this.CanGather(this.gatheringTarget)) + if (this.CanGather(this.gatheringTarget) && this.CheckTargetRange(this.gatheringTarget, IID_ResourceGatherer)) { // Gather the resources: - - var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); + let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); // Try to gather treasure if (cmpResourceGatherer.TryInstantGather(this.gatheringTarget)) @@ -2356,18 +2354,18 @@ cmpResourceGatherer.DropResources(); // Collect from the target - var status = cmpResourceGatherer.PerformGather(this.gatheringTarget); + let status = cmpResourceGatherer.PerformGather(this.gatheringTarget); // If we've collected as many resources as possible, // return to the nearest dropsite if (status.filled) { - var nearby = this.FindNearestDropsite(resourceType.generic); - if (nearby) + let nearestDropsite = this.FindNearestDropsite(resourceType.generic); + if (nearestDropsite) { // (Keep this Gather order on the stack so we'll // continue gathering after returning) - this.PushOrderFront("ReturnResource", { "target": nearby, "force": false }); + this.PushOrderFront("ReturnResource", { "target": nearestDropsite, "force": false }); return; } @@ -2395,9 +2393,8 @@ // the old one. So try to get close to the old resource's // last known position - var maxRange = 8; // get close but not too close if (this.order.data.lastPos && - this.MoveToPointRange(this.order.data.lastPos.x, this.order.data.lastPos.z, 0, maxRange)) + this.MoveToPointRange(this.order.data.lastPos.x, this.order.data.lastPos.z, 0, 8)) { this.SetNextState("APPROACHING"); return; @@ -2407,18 +2404,18 @@ // We're already in range, can't get anywhere near it or the target is exhausted. - var herdPos = this.order.data.initPos; + let herdPos = this.order.data.initPos; // Give up on this order and try our next queued order // but first check what is our next order and, if needed, insert a returnResource order - var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); + let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); if (cmpResourceGatherer.IsCarrying(resourceType.generic) && this.orderQueue.length > 1 && this.orderQueue[1] !== "ReturnResource" && (this.orderQueue[1].type !== "Gather" || this.orderQueue[1].data.type.generic !== resourceType.generic)) { - let nearby = this.FindNearestDropsite(resourceType.generic); - if (nearby) - this.orderQueue.splice(1, 0, { "type": "ReturnResource", "data": { "target": nearby, "force": false } }); + let nearestDropsite = this.FindNearestDropsite(resourceType.generic); + if (nearestDropsite) + this.orderQueue.splice(1, 0, { "type": "ReturnResource", "data": { "target": nearestDropsite, "force": false } }); } if (this.FinishOrder()) return; @@ -2427,16 +2424,16 @@ // Try to find a new resource of the same specific type near our current position: // Also don't switch to a different type of huntable animal - var nearby = this.FindNearbyResource(function(ent, type, template) { + let nearbyResource = this.FindNearbyResource(function(ent, type, template) { return ( (type.generic == "treasure" && resourceType.generic == "treasure") || (type.specific == resourceType.specific && (type.specific != "meat" || resourceTemplate == template)) ); }); - if (nearby) + if (nearbyResource) { - this.PerformGather(nearby, false, false); + this.PerformGather(nearbyResource, false, false); return; } @@ -2451,10 +2448,10 @@ // drop it off, and if not then we might as well head to the dropsite // anyway because that's a nice enough place to congregate and idle - var nearby = this.FindNearestDropsite(resourceType.generic); - if (nearby) + let nearestDropsite = this.FindNearestDropsite(resourceType.generic); + if (nearestDropsite) { - this.PushOrderFront("ReturnResource", { "target": nearby, "force": false }); + this.PushOrderFront("ReturnResource", { "target": nearestDropsite, "force": false }); return; } @@ -5751,7 +5748,7 @@ if (this.IsTurret()) return false; // The target must be a valid resource supply, or the mirage of one. - var cmpResourceSupply = QueryMiragedInterface(target, IID_ResourceSupply); + let cmpResourceSupply = QueryMiragedInterface(target, IID_ResourceSupply); if (!cmpResourceSupply) return false; @@ -5761,7 +5758,7 @@ return true; // Verify that we're able to respond to Gather commands - var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); + let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); if (!cmpResourceGatherer) return false;