Changeset 25000

Timestamp:
Mar 3, 2021, 7:24:16 PM (3 years ago)
Author:
Freagarach
Message:

[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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js

    r24999 r25000  
    26282628                    // No remaining orders - pick a useful default behaviour
    26292629
    2630                     // Give up if we're not in the world right now.
    26312630                    let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
    26322631                    if (!cmpPosition || !cmpPosition.IsInWorld())
    26332632                        return true;
    26342633
    2635                     // If we have no known initial position of our target, look around our own position
    2636                     // as a fallback.
     2634                    let filter = (ent, type, template) => {
     2635                        if (previousTarget == ent)
     2636                            return false;
     2637
     2638                        // Don't switch to a different type of huntable animal.
     2639                        return type.specific == resourceType.specific &&
     2640                            (type.specific != "meat" || resourceTemplate == template);
     2641                    };
     2642
     2643                    // Current position is often next to a dropsite.
     2644                    let pos = cmpPosition.GetPosition();
     2645                    let nearbyResource = this.FindNearbyResource(Vector2D.from3D(pos), filter);
     2646
     2647                    // If there is an initPos, search there as well when we haven't found anything.
     2648                    // Otherwise set initPos to our current pos.
    26372649                    if (!initPos)
    2638                     {
    2639                         let pos = cmpPosition.GetPosition();
    26402650                        initPos = { 'x': pos.X, 'z': pos.Z };
    2641                     }
    2642 
    2643                     // Try to find a new resource of the same specific type near the initial resource position:
    2644                     // Also don't switch to a different type of huntable animal
    2645                     let nearbyResource = this.FindNearbyResource(new Vector2D(initPos.x, initPos.z),
    2646                         (ent, type, template) => {
    2647                             if (previousTarget == ent)
    2648                                 return false;
    2649 
    2650                             return type.specific == resourceType.specific &&
    2651                                 (type.specific != "meat" || resourceTemplate == template);
    2652                         });
     2651                    else if (!nearbyResource)
     2652                        nearbyResource = this.FindNearbyResource(new Vector2D(initPos.X, initPos.Z), filter);
    26532653
    26542654                    if (nearbyResource)
Note: See TracChangeset for help on using the changeset viewer.