Ticket #2047: hunt.diff
File hunt.diff, 2.9 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/UnitAI.js
1405 1405 // Check we can still reach the target 1406 1406 if (this.CheckTargetRange(target, IID_Attack, this.order.data.attackType)) 1407 1407 { 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 1408 1422 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 1409 1423 this.lastAttacked = cmpTimer.GetTime() - msg.lateness; 1410 1424 … … 1650 1664 } 1651 1665 1652 1666 // 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 }); 1654 1674 }, 1655 1675 }, 1656 1676 … … 1805 1825 1806 1826 // We're already in range, can't get anywhere near it or the target is exhausted. 1807 1827 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 1808 1831 // Give up on this order and try our next queued order 1809 1832 if (this.FinishOrder()) 1810 1833 return; … … 1826 1849 return; 1827 1850 } 1828 1851 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 1829 1856 // Nothing else to gather - if we're carrying anything then we should 1830 1857 // drop it off, and if not then we might as well head to the dropsite 1831 1858 // anyway because that's a nice enough place to congregate and idle … … 3832 3859 3833 3860 // Remember the position of our target, if any, in case it disappears 3834 3861 // 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 we3836 // need to update this lastPos regularly rather than just here?)3837 3862 var lastPos = undefined; 3838 3863 var cmpPosition = Engine.QueryInterface(target, IID_Position); 3839 3864 if (cmpPosition && cmpPosition.IsInWorld())