Ticket #2946: NonworkerDistance_PATCHv2.patch

File NonworkerDistance_PATCHv2.patch, 2.7 KB (added by Jason, 9 years ago)

Incorporates size of target into calculations.

  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    324324            return;
    325325        }
    326326
    327         var ok = this.MoveToTarget(this.order.data.target);
     327        var ok = this.MoveToTargetRangeExplicit(this.order.data.target, this.order.data.min, this.order.data.max);
    328328        if (ok)
    329329        {
    330330            // We've started walking to the given point
     
    49144914 */
    49154915UnitAI.prototype.WalkToTarget = function(target, queued)
    49164916{
    4917     this.AddOrder("WalkToTarget", { "target": target, "force": true }, queued);
     4917    this.AddOrder("WalkToTarget", { "min":0, "max":0, "target": target, "force": true }, queued);
    49184918};
    49194919
    49204920/**
     4921 * Adds walk to target order with explicit range to queue.
     4922 * Used when a unit which cannot build/repair is told to do so - they should walk to
     4923 * the structure but not get so close to interfere with other workers.
     4924 */
     4925UnitAI.prototype.WalkToTargetRangeExplicit = function(rangeMin, rangeMax, target, queued)
     4926{
     4927    this.AddOrder("WalkToTarget", { "min":rangeMin, "max":rangeMax, "target": target, "force": true }, queued);
     4928};
     4929
     4930/**
    49214931 * Adds walk-and-fight order to queue, this only occurs in response
    49224932 * to a player order, and so is forced.
    49234933 * If targetClasses is given, only entities matching the targetClasses can be attacked.
     
    50125022{
    50135023    if (!this.CanGather(target))
    50145024    {
    5015         this.WalkToTarget(target, queued);
     5025        var cmpObstruction = Engine.QueryInterface(this.entity, IID_Obstruction);
     5026        var distance = 10 * cmpObstruction.GetUnitRadius();
     5027        this.WalkToTargetRangeExplicit(10, 10, target, queued);
    50165028        return;
    50175029    }
    50185030
     
    50715083{
    50725084    if (!this.CanHeal(target))
    50735085    {
    5074         this.WalkToTarget(target, queued);
     5086        this.WalkToTargetRangeExplicit(10, 10, target, queued);
    50755087        return;
    50765088    }
    50775089   
     
    50855097{
    50865098    if (!this.CanReturnResource(target, true))
    50875099    {
    5088         this.WalkToTarget(target, queued);
     5100        var cmpObstruction = Engine.QueryInterface(this.entity, IID_Obstruction);
     5101        var distance = 10 * cmpObstruction.GetUnitRadius();
     5102        this.WalkToTargetRangeExplicit(distance, distance, target, queued);
    50895103        return;
    50905104    }
    50915105
     
    51025116{
    51035117    if (!this.CanTrade(target))
    51045118    {
    5105         this.WalkToTarget(target, queued);
     5119        this.WalkToTargetRangeExplicit(10, 10, target, queued);
    51065120        return;
    51075121    }
    51085122
     
    52275241{
    52285242    if (!this.CanRepair(target))
    52295243    {
    5230         this.WalkToTarget(target, queued);
     5244        var cmpObstruction = Engine.QueryInterface(this.entity, IID_Obstruction);
     5245        var distance = 10 * cmpObstruction.GetUnitRadius();
     5246        this.WalkToTargetRangeExplicit(distance, distance, target, queued);
    52315247        return;
    52325248    }
    52335249