forked from 0ad/0ad
Save initial herd position and update the last known position of the hunted animal when hunting. Patch by mimo. Fixes #2047.
This was SVN commit r13803.
This commit is contained in:
parent
16c9724c24
commit
819a1e7823
@ -1432,6 +1432,21 @@ var UnitFsmSpec = {
|
|||||||
// Check we can still reach the target
|
// Check we can still reach the target
|
||||||
if (this.CheckTargetAttackRange(target, IID_Attack, this.order.data.attackType))
|
if (this.CheckTargetAttackRange(target, IID_Attack, this.order.data.attackType))
|
||||||
{
|
{
|
||||||
|
// If we are hunting, first update the target position of the gather order so we know where will be the killed animal
|
||||||
|
if (this.order.data.hunting && this.orderQueue[1] && this.orderQueue[1].data.lastPos)
|
||||||
|
{
|
||||||
|
var cmpPosition = Engine.QueryInterface(this.order.data.target, IID_Position);
|
||||||
|
if (cmpPosition && cmpPosition.IsInWorld())
|
||||||
|
{
|
||||||
|
// Store the initial position, so that we can find the rest of the herd later
|
||||||
|
if (!this.orderQueue[1].data.initPos)
|
||||||
|
this.orderQueue[1].data.initPos = this.orderQueue[1].data.lastPos;
|
||||||
|
this.orderQueue[1].data.lastPos = cmpPosition.GetPosition();
|
||||||
|
// We still know where the animal is, so we shouldn't give up before going there
|
||||||
|
this.orderQueue[1].data.secondTry = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
||||||
this.lastAttacked = cmpTimer.GetTime() - msg.lateness;
|
this.lastAttacked = cmpTimer.GetTime() - msg.lateness;
|
||||||
|
|
||||||
@ -1679,7 +1694,18 @@ var UnitFsmSpec = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Couldn't find nearby resources, so give up
|
// Couldn't find nearby resources, so give up
|
||||||
this.FinishOrder();
|
if (this.FinishOrder())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Nothing better to do: go back to dropsite
|
||||||
|
var nearby = this.FindNearestDropsite(resourceType.generic);
|
||||||
|
if (nearby)
|
||||||
|
{
|
||||||
|
this.PushOrderFront("ReturnResource", { "target": nearby, "force": false });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No dropsites, just give up
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1834,6 +1860,8 @@ var UnitFsmSpec = {
|
|||||||
|
|
||||||
// We're already in range, can't get anywhere near it or the target is exhausted.
|
// We're already in range, can't get anywhere near it or the target is exhausted.
|
||||||
|
|
||||||
|
var herdPos = this.order.data.initPos;
|
||||||
|
|
||||||
// Give up on this order and try our next queued order
|
// Give up on this order and try our next queued order
|
||||||
if (this.FinishOrder())
|
if (this.FinishOrder())
|
||||||
return;
|
return;
|
||||||
@ -1855,6 +1883,10 @@ var UnitFsmSpec = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If hunting, try to go to the initial herd position to see if we are more lucky
|
||||||
|
if (herdPos)
|
||||||
|
this.GatherNearPosition(herdPos.x, herdPos.z, resourceType, resourceTemplate);
|
||||||
|
|
||||||
// Nothing else to gather - if we're carrying anything then we should
|
// Nothing else to gather - if we're carrying anything then we should
|
||||||
// drop it off, and if not then we might as well head to the dropsite
|
// 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
|
// anyway because that's a nice enough place to congregate and idle
|
||||||
@ -3945,8 +3977,6 @@ UnitAI.prototype.PerformGather = function(target, queued, force)
|
|||||||
|
|
||||||
// Remember the position of our target, if any, in case it disappears
|
// Remember the position of our target, if any, in case it disappears
|
||||||
// later and we want to head to its last known position
|
// later and we want to head to its last known position
|
||||||
// (TODO: if the target moves a lot (e.g. it's an animal), maybe we
|
|
||||||
// need to update this lastPos regularly rather than just here?)
|
|
||||||
var lastPos = undefined;
|
var lastPos = undefined;
|
||||||
var cmpPosition = Engine.QueryInterface(target, IID_Position);
|
var cmpPosition = Engine.QueryInterface(target, IID_Position);
|
||||||
if (cmpPosition && cmpPosition.IsInWorld())
|
if (cmpPosition && cmpPosition.IsInWorld())
|
||||||
|
Loading…
Reference in New Issue
Block a user