Changeset 25000
- Timestamp:
- Mar 3, 2021, 7:24:16 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
r24999 r25000 2628 2628 // No remaining orders - pick a useful default behaviour 2629 2629 2630 // Give up if we're not in the world right now.2631 2630 let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); 2632 2631 if (!cmpPosition || !cmpPosition.IsInWorld()) 2633 2632 return true; 2634 2633 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. 2637 2649 if (!initPos) 2638 {2639 let pos = cmpPosition.GetPosition();2640 2650 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); 2653 2653 2654 2654 if (nearbyResource)
Note:
See TracChangeset
for help on using the changeset viewer.