Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 951 Lines • ▼ Show 20 Lines | "WALKING": { | ||||
} | } | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | ||||
cmpFormation.SetRearrange(true); | cmpFormation.SetRearrange(true); | ||||
cmpFormation.MoveMembersIntoFormation(true, true); | cmpFormation.MoveMembersIntoFormation(true, true); | ||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopTimer(); | |||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (msg.veryObstructed && !this.timer) | |||||
{ | |||||
// It's possible that the controller (with large clearance) | |||||
// is stuck, but not the individual units. | |||||
// Ask them to move individually for a little while. | |||||
this.CallMemberFunction("MoveTo", [this.order.data]); | |||||
this.StartTimer(3000); | |||||
return; | |||||
} | |||||
else if (this.timer) | |||||
return; | |||||
if (msg.likelyFailure || this.CheckRange(this.order.data)) | if (msg.likelyFailure || this.CheckRange(this.order.data)) | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
"Timer": function() { | |||||
// Reenter to reset the pathfinder state. | |||||
this.SetNextState("WALKING"); | |||||
} | |||||
}, | }, | ||||
"WALKINGANDFIGHTING": { | "WALKINGANDFIGHTING": { | ||||
"enter": function(msg) { | "enter": function(msg) { | ||||
if (!this.MoveTo(this.order.data)) | if (!this.MoveTo(this.order.data)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
// Wait for individual members to finish | // Wait for individual members to finish | ||||
"MEMBER": { | "MEMBER": { | ||||
"OrderTargetRenamed": function(msg) { | "OrderTargetRenamed": function(msg) { | ||||
// In general, don't react - we don't want to send spurious messages to members. | // In general, don't react - we don't want to send spurious messages to members. | ||||
// This looks odd for hunting hwoever because we wait for all | // This looks odd for hunting however because we wait for all | ||||
// entities to ahve clumped around the dead resource before proceeding | // entities to have clumped around the dead resource before proceeding | ||||
// so explicitly handle this case. | // so explicitly handle this case. | ||||
if (this.order && this.order.data && this.order.data.hunting && | if (this.order && this.order.data && this.order.data.hunting && | ||||
this.order.data.target == msg.data.newentity && | this.order.data.target == msg.data.newentity && | ||||
this.orderQueue.length > 1) | this.orderQueue.length > 1) | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
"enter": function(msg) { | "enter": function(msg) { | ||||
▲ Show 20 Lines • Show All 2,964 Lines • ▼ Show 20 Lines | UnitAI.prototype.StopTimer = function() | ||||
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
cmpTimer.CancelTimer(this.timer); | cmpTimer.CancelTimer(this.timer); | ||||
this.timer = undefined; | this.timer = undefined; | ||||
}; | }; | ||||
UnitAI.prototype.OnMotionUpdate = function(msg) | UnitAI.prototype.OnMotionUpdate = function(msg) | ||||
{ | { | ||||
if (msg.veryObstructed) | |||||
msg.obstructed = true; | |||||
this.UnitFsm.ProcessMessage(this, Object.assign({ "type": "MovementUpdate" }, msg)); | this.UnitFsm.ProcessMessage(this, Object.assign({ "type": "MovementUpdate" }, msg)); | ||||
}; | }; | ||||
/** | /** | ||||
* Called directly by cmpFoundation and cmpRepairable to | * Called directly by cmpFoundation and cmpRepairable to | ||||
* inform builders that repairing has finished. | * inform builders that repairing has finished. | ||||
* This not done by listening to a global message due to performance. | * This not done by listening to a global message due to performance. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 2,294 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator