Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 1,604 Lines • ▼ Show 20 Lines | "IDLE": { | ||||
if (this.losAttackRangeQuery) | if (this.losAttackRangeQuery) | ||||
cmpRangeManager.DisableActiveQuery(this.losAttackRangeQuery); | cmpRangeManager.DisableActiveQuery(this.losAttackRangeQuery); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
if (this.isIdle) | if (this.isIdle) | ||||
{ | { | ||||
this.isIdle = false; | this.isIdle = false; | ||||
Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); | Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle, "entity": this.entity }); | ||||
} | } | ||||
}, | }, | ||||
"Attacked": function(msg) { | "Attacked": function(msg) { | ||||
if (this.isIdle && (this.GetStance().targetAttackersAlways || !this.order || !this.order.data || !this.order.data.force)) | if (this.isIdle && (this.GetStance().targetAttackersAlways || !this.order || !this.order.data || !this.order.data.force)) | ||||
this.RespondToTargetedEntities([msg.data.attacker]); | this.RespondToTargetedEntities([msg.data.attacker]); | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | "IDLE": { | ||||
if (this.IsFormationMember()) | if (this.IsFormationMember()) | ||||
{ | { | ||||
let cmpFormationAI = Engine.QueryInterface(this.formationController, IID_UnitAI); | let cmpFormationAI = Engine.QueryInterface(this.formationController, IID_UnitAI); | ||||
if (!cmpFormationAI || !cmpFormationAI.IsIdle()) | if (!cmpFormationAI || !cmpFormationAI.IsIdle()) | ||||
return; | 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, "entity": this.entity }); | ||||
} | } | ||||
// Go linger first to prevent all roaming entities | // Go linger first to prevent all roaming entities | ||||
// to move all at the same time on map init. | // to move all at the same time on map init. | ||||
if (this.template.RoamDistance) | if (this.template.RoamDistance) | ||||
this.SetNextState("LINGERING"); | this.SetNextState("LINGERING"); | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 1,804 Lines • ▼ Show 20 Lines | |||||
* Used by formation controllers to toggle the idleness of their members. | * Used by formation controllers to toggle the idleness of their members. | ||||
*/ | */ | ||||
UnitAI.prototype.ResetIdle = function() | UnitAI.prototype.ResetIdle = function() | ||||
{ | { | ||||
let shouldBeIdle = this.GetCurrentState().endsWith(".IDLE"); | let shouldBeIdle = this.GetCurrentState().endsWith(".IDLE"); | ||||
if (this.isIdle == shouldBeIdle) | if (this.isIdle == shouldBeIdle) | ||||
return; | return; | ||||
this.isIdle = shouldBeIdle; | this.isIdle = shouldBeIdle; | ||||
Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); | Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle, "entity": this.entity }); | ||||
}; | }; | ||||
UnitAI.prototype.SetGarrisoned = function() | UnitAI.prototype.SetGarrisoned = function() | ||||
{ | { | ||||
// UnitAI caches its own garrisoned state for performance. | // UnitAI caches its own garrisoned state for performance. | ||||
this.isGarrisoned = true; | this.isGarrisoned = true; | ||||
this.SetImmobile(); | this.SetImmobile(); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 2,997 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator