Ticket #2047: hunt.diff

File hunt.diff, 2.9 KB (added by mimo, 11 years ago)
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    14051405                        // Check we can still reach the target
    14061406                        if (this.CheckTargetRange(target, IID_Attack, this.order.data.attackType))
    14071407                        {
     1408                            // If we are hunting, first update the target position of the gather order so we know where will be the killed animal
     1409                            if (this.order.data.hunting && this.orderQueue[1] && this.orderQueue[1].data.lastPos)
     1410                            {
     1411                                var cmpPosition = Engine.QueryInterface(this.order.data.target, IID_Position);
     1412                                if (cmpPosition && cmpPosition.IsInWorld())
     1413                                {
     1414                                    // keep in memory the initial position which usually is the herd position
     1415                                    if (!this.orderQueue[1].data.initPos)
     1416                                        this.orderQueue[1].data.initPos = this.orderQueue[1].data.lastPos;
     1417                                    this.orderQueue[1].data.lastPos = cmpPosition.GetPosition();
     1418                                    this.orderQueue[1].data.secondTry = undefined;
     1419                                }
     1420                            }
     1421
    14081422                            var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
    14091423                            this.lastAttacked = cmpTimer.GetTime() - msg.lateness;
    14101424
     
    16501664                    }
    16511665
    16521666                    // Couldn't find nearby resources, so give up
    1653                     this.FinishOrder();
     1667                    if( this.FinishOrder())
     1668                        return;
     1669
     1670                    // Nothing better to do : go back to dropsite
     1671                    var nearby = this.FindNearestDropsite(resourceType.generic);
     1672                    if (nearby)
     1673                        this.PushOrderFront("ReturnResource", { "target": nearby, "force": false });
    16541674                },
    16551675            },
    16561676
     
    18051825
    18061826                    // We're already in range, can't get anywhere near it or the target is exhausted.
    18071827
     1828                    // If hunting, keep in memory the position of the herd in case we do not find any more animals here
     1829                    var herdPos = this.order.data.initPos;
     1830
    18081831                    // Give up on this order and try our next queued order
    18091832                    if (this.FinishOrder())
    18101833                        return;
     
    18261849                        return;
    18271850                    }
    18281851
     1852                    // If hunting, try to go to the initial herd position to see if we are more lucky
     1853                    if (herdPos)
     1854                        this.GatherNearPosition(herdPos.x, herdPos.z, resourceType, resourceTemplate);
     1855
    18291856                    // Nothing else to gather - if we're carrying anything then we should
    18301857                    // drop it off, and if not then we might as well head to the dropsite
    18311858                    // anyway because that's a nice enough place to congregate and idle
     
    38323859
    38333860    // Remember the position of our target, if any, in case it disappears
    38343861    // later and we want to head to its last known position
    3835     // (TODO: if the target moves a lot (e.g. it's an animal), maybe we
    3836     // need to update this lastPos regularly rather than just here?)
    38373862    var lastPos = undefined;
    38383863    var cmpPosition = Engine.QueryInterface(target, IID_Position);
    38393864    if (cmpPosition && cmpPosition.IsInWorld())