Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 919 Lines • ▼ Show 20 Lines | "IDLE": { | ||||
"enter": function(msg) { | "enter": function(msg) { | ||||
// Turn rearrange off. Otherwise, if the formation is idle, | // Turn rearrange off. Otherwise, if the formation is idle, | ||||
// but individual units go off to fight, any death | // but individual units go off to fight, any death | ||||
// will rearrange the formation, looking odd. | // will rearrange the formation, looking odd. | ||||
// Instead, move idle units in formation on a timer. | // Instead, move idle units in formation on a timer. | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | ||||
cmpFormation.SetRearrange(false); | cmpFormation.SetRearrange(false); | ||||
this.StartTimer(0, 2000); | this.StartTimer(0, 2000); | ||||
this.isIdle = true; | |||||
this.CallMemberFunction("ResetIdle"); | |||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.isIdle = false; | |||||
this.StopTimer(); | this.StopTimer(); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | ||||
if (!cmpFormation) | if (!cmpFormation) | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 666 Lines • ▼ Show 20 Lines | "IDLE": { | ||||
// Move back to the held position if we drifted away. | // Move back to the held position if we drifted away. | ||||
// (only if not a formation member). | // (only if not a formation member). | ||||
if (!this.IsFormationMember() && | if (!this.IsFormationMember() && | ||||
this.GetStance().respondHoldGround && this.heldPosition && | this.GetStance().respondHoldGround && this.heldPosition && | ||||
!this.CheckPointRangeExplicit(this.heldPosition.x, this.heldPosition.z, 0, 10) && | !this.CheckPointRangeExplicit(this.heldPosition.x, this.heldPosition.z, 0, 10) && | ||||
this.WalkToHeldPosition()) | this.WalkToHeldPosition()) | ||||
return; | return; | ||||
if (this.IsFormationMember()) | |||||
{ | |||||
let cmpFormationAI = Engine.QueryInterface(this.formationController, IID_UnitAI); | |||||
if (!cmpFormationAI || !cmpFormationAI.IsIdle()) | |||||
return; | |||||
} | |||||
this.isIdle = true; | this.isIdle = true; | ||||
Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); | Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); | ||||
} | } | ||||
}, | }, | ||||
}, | }, | ||||
"WALKING": { | "WALKING": { | ||||
"enter": function() { | "enter": function() { | ||||
▲ Show 20 Lines • Show All 1,904 Lines • ▼ Show 20 Lines | UnitAI.prototype.IsHealer = function() | ||||
return Engine.QueryInterface(this.entity, IID_Heal); | return Engine.QueryInterface(this.entity, IID_Heal); | ||||
}; | }; | ||||
UnitAI.prototype.IsIdle = function() | UnitAI.prototype.IsIdle = function() | ||||
{ | { | ||||
return this.isIdle; | return this.isIdle; | ||||
}; | }; | ||||
/** | |||||
* Used by formation controllers to toggle the idleness of their members. | |||||
*/ | |||||
UnitAI.prototype.ResetIdle = function() | |||||
{ | |||||
let shouldBeIdle = this.GetCurrentState().endsWith(".IDLE"); | |||||
if (this.isIdle == shouldBeIdle) | |||||
return; | |||||
this.isIdle = shouldBeIdle; | |||||
Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); | |||||
}; | |||||
UnitAI.prototype.IsGarrisoned = function() | UnitAI.prototype.IsGarrisoned = function() | ||||
{ | { | ||||
return this.isGarrisoned; | return this.isGarrisoned; | ||||
}; | }; | ||||
UnitAI.prototype.SetGarrisoned = function() | UnitAI.prototype.SetGarrisoned = function() | ||||
{ | { | ||||
this.isGarrisoned = true; | this.isGarrisoned = true; | ||||
▲ Show 20 Lines • Show All 3,013 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator