1
0
forked from 0ad/0ad

[Gameplay] - Search for resources near a current location before the init-pos.

This should bring the behaviour back to pre-A24 and means entities will
stray a lot less when gathering.
The entity will search close to the current position, which is mostly
next to a dropsite.
When there is nothing found there, the entity searches nigh the initPos.

Differential revision: D3607
Comments by: @wraitii
Tested by: @Nescio
This was SVN commit r25000.
This commit is contained in:
Freagarach 2021-03-03 18:24:16 +00:00
parent 97addf2aa7
commit 5e6b775d1a

View File

@ -2627,29 +2627,29 @@ UnitAI.prototype.UnitFsmSpec = {
// No remaining orders - pick a useful default behaviour
// Give up if we're not in the world right now.
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
if (!cmpPosition || !cmpPosition.IsInWorld())
return true;
// If we have no known initial position of our target, look around our own position
// as a fallback.
let filter = (ent, type, template) => {
if (previousTarget == ent)
return false;
// Don't switch to a different type of huntable animal.
return type.specific == resourceType.specific &&
(type.specific != "meat" || resourceTemplate == template);
};
// Current position is often next to a dropsite.
let pos = cmpPosition.GetPosition();
let nearbyResource = this.FindNearbyResource(Vector2D.from3D(pos), filter);
// If there is an initPos, search there as well when we haven't found anything.
// Otherwise set initPos to our current pos.
if (!initPos)
{
let pos = cmpPosition.GetPosition();
initPos = { 'x': pos.X, 'z': pos.Z };
}
// Try to find a new resource of the same specific type near the initial resource position:
// Also don't switch to a different type of huntable animal
let nearbyResource = this.FindNearbyResource(new Vector2D(initPos.x, initPos.z),
(ent, type, template) => {
if (previousTarget == ent)
return false;
return type.specific == resourceType.specific &&
(type.specific != "meat" || resourceTemplate == template);
});
else if (!nearbyResource)
nearbyResource = this.FindNearbyResource(new Vector2D(initPos.X, initPos.Z), filter);
if (nearbyResource)
{