Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 1,308 Lines • ▼ Show 20 Lines | "FORMATIONMEMBER": { | ||||
"IDLE": "INDIVIDUAL.IDLE", | "IDLE": "INDIVIDUAL.IDLE", | ||||
"CHEERING": "INDIVIDUAL.CHEERING", | "CHEERING": "INDIVIDUAL.CHEERING", | ||||
"WALKING": { | "WALKING": { | ||||
"enter": function() { | "enter": function() { | ||||
this.formationOffset = { "x": this.order.data.x, "z": this.order.data.z }; | this.formationOffset = { "x": this.order.data.x, "z": this.order.data.z }; | ||||
let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | ||||
// Prevent unit to turn when stopmoving is called. | |||||
cmpUnitMotion.SetFacePointAfterMove(false); | |||||
cmpUnitMotion.MoveToFormationOffset(this.order.data.target, this.order.data.x, this.order.data.z); | cmpUnitMotion.MoveToFormationOffset(this.order.data.target, this.order.data.x, this.order.data.z); | ||||
if (this.order.data.offsetsChanged) | if (this.order.data.offsetsChanged) | ||||
{ | { | ||||
let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); | let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); | ||||
if (cmpFormation) | if (cmpFormation) | ||||
this.SetAnimationVariant(cmpFormation.GetFormationAnimation(this.entity)); | this.SetAnimationVariant(cmpFormation.GetFormationAnimation(this.entity)); | ||||
} | } | ||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.SetFacePointAfterMove(true); | |||||
}, | }, | ||||
// Occurs when the unit has reached its destination and the controller | // Occurs when the unit has reached its destination and the controller | ||||
// is done moving. The controller is notified. | // is done moving. The controller is notified. | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
// We can only finish this order if the move was really completed. | // We can only finish this order if the move was really completed. | ||||
let cmpPosition = Engine.QueryInterface(this.formationController, IID_Position); | let cmpPosition = Engine.QueryInterface(this.formationController, IID_Position); | ||||
let atDestination = cmpPosition && cmpPosition.IsInWorld(); | let atDestination = cmpPosition && cmpPosition.IsInWorld(); | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | "IDLE": { | ||||
if (this.FindNewTargets()) | if (this.FindNewTargets()) | ||||
return; | return; | ||||
if (this.formationOffset && this.formationController) | if (this.formationOffset && this.formationController) | ||||
{ | { | ||||
this.PushOrder("FormationWalk", { | this.PushOrder("FormationWalk", { | ||||
"target": this.formationController, | "target": this.formationController, | ||||
"x": this.formationOffset.x, | "x": this.formationOffset.x, | ||||
"z": this.formationOffset.z, | "z": this.formationOffset.z | ||||
}); | }); | ||||
return; | return; | ||||
} | } | ||||
if (!this.isIdle) | if (!this.isIdle) | ||||
{ | { | ||||
if (this.formationController) | |||||
{ | |||||
let cmpFormationPosition = Engine.QueryInterface(this.formationController, IID_Position); | |||||
if (cmpFormationPosition && cmpFormationPosition.IsInWorld()) | |||||
{ | |||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | |||||
if (cmpPosition && cmpPosition.IsInWorld()) | |||||
cmpPosition.TurnTo(cmpFormationPosition.GetRotation().y); | |||||
} | |||||
} | |||||
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 4,669 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator