Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 2,491 Lines • ▼ Show 20 Lines | "GATHER": { | ||||
"TargetInvalidated": function(msg) { | "TargetInvalidated": function(msg) { | ||||
this.SetNextState("FINDINGNEWTARGET"); | this.SetNextState("FINDINGNEWTARGET"); | ||||
}, | }, | ||||
}, | }, | ||||
"FINDINGNEWTARGET": { | "FINDINGNEWTARGET": { | ||||
"enter": function() { | "enter": function() { | ||||
const previousForced = this.order.data.force; | |||||
let previousTarget = this.order.data.target; | let previousTarget = this.order.data.target; | ||||
let resourceTemplate = this.order.data.template; | let resourceTemplate = this.order.data.template; | ||||
let resourceType = this.order.data.type; | let resourceType = this.order.data.type; | ||||
// Give up on this order and try our next queued order | // Give up on this order and try our next queued order | ||||
// but first check what is our next order and, if needed, insert a returnResource order | // but first check what is our next order and, if needed, insert a returnResource order | ||||
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | ||||
if (cmpResourceGatherer.IsCarrying(resourceType.generic) && | if (cmpResourceGatherer.IsCarrying(resourceType.generic) && | ||||
Show All 22 Lines | "GATHER": { | ||||
return false; | return false; | ||||
// Don't switch to a different type of huntable animal. | // Don't switch to a different type of huntable animal. | ||||
return type.specific == resourceType.specific && | return type.specific == resourceType.specific && | ||||
(type.specific != "meat" || resourceTemplate == template); | (type.specific != "meat" || resourceTemplate == template); | ||||
}; | }; | ||||
// Current position is often next to a dropsite. | // Current position is often next to a dropsite. | ||||
// But don't use that on forced orders, as the order may want us to go | |||||
// to the other side of the map on purpose. | |||||
let pos = cmpPosition.GetPosition(); | let pos = cmpPosition.GetPosition(); | ||||
let nearbyResource = this.FindNearbyResource(Vector2D.from3D(pos), filter); | let nearbyResource; | ||||
if (!previousForced) | |||||
nearbyResource = this.FindNearbyResource(Vector2D.from3D(pos), filter); | |||||
// If there is an initPos, search there as well when we haven't found anything. | // If there is an initPos, search there as well when we haven't found anything. | ||||
// Otherwise set initPos to our current pos. | // Otherwise set initPos to our current pos. | ||||
if (!initPos) | if (!initPos) | ||||
initPos = { 'x': pos.X, 'z': pos.Z }; | initPos = { 'x': pos.X, 'z': pos.Z }; | ||||
else if (!nearbyResource) | else if (!nearbyResource || previousForced) | ||||
nearbyResource = this.FindNearbyResource(new Vector2D(initPos.x, initPos.z), filter); | nearbyResource = this.FindNearbyResource(new Vector2D(initPos.x, initPos.z), filter); | ||||
if (nearbyResource) | if (nearbyResource) | ||||
{ | { | ||||
this.PerformGather(nearbyResource, false, false); | this.PerformGather(nearbyResource, false, false); | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 3,887 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator