Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | "OrderTargetRenamed": function() { | ||||
// so that state preconditions are checked against the new entity | // so that state preconditions are checked against the new entity | ||||
// (there is no reason to assume the target is still valid). | // (there is no reason to assume the target is still valid). | ||||
this.SetNextState(this.GetCurrentState()); | this.SetNextState(this.GetCurrentState()); | ||||
}, | }, | ||||
// Formation handlers: | // Formation handlers: | ||||
"FormationLeave": function(msg) { | "FormationLeave": function(msg) { | ||||
// ignore when we're not in FORMATIONMEMBER | // Overloaded by FORMATIONMEMBER | ||||
// We end up here if LeaveFormation was called when the entity | |||||
// was executing an order in an individual state, so we must | |||||
// discard the order now that it has been executed. | |||||
if (this.order.type === "LeaveFormation") | |||||
Stan: What other orders can it be ? | |||||
FreagarachUnsubmitted Not Done Inline ActionsIs it guaranteed to have an order? (Perhaps check for this.order first.) Freagarach: Is it guaranteed to have an order? (Perhaps check for `this.order` first.) | |||||
wraitiiAuthorUnsubmitted Done Inline ActionsAlmost any order wraitii: Almost any order | |||||
this.FinishOrder(); | |||||
}, | }, | ||||
// Called when being told to walk as part of a formation | // Called when being told to walk as part of a formation | ||||
"Order.FormationWalk": function(msg) { | "Order.FormationWalk": function(msg) { | ||||
if (!this.AbleToMove()) | if (!this.AbleToMove()) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
Show All 29 Lines | if (!this.IsFormationMember()) | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); | let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); | ||||
if (cmpFormation) | if (cmpFormation) | ||||
{ | { | ||||
cmpFormation.SetRearrange(false); | cmpFormation.SetRearrange(false); | ||||
// Calls FinishOrder(); | // Triggers FormationLeave, which ultimately will FinishOrder, | ||||
// discarding this order. | |||||
cmpFormation.RemoveMembers([this.entity]); | cmpFormation.RemoveMembers([this.entity]); | ||||
cmpFormation.SetRearrange(true); | cmpFormation.SetRearrange(true); | ||||
} | } | ||||
}, | }, | ||||
"Order.Stop": function(msg) { | "Order.Stop": function(msg) { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | if (this.CanPack()) | ||||
return; | return; | ||||
} | } | ||||
if (this.CheckRange(this.order.data)) | if (this.CheckRange(this.order.data)) | ||||
{ | { | ||||
// We are already at the target, or can't move at all | // We are already at the target, or can't move at all | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
Lint: ESLintBear (consistent-return) Method 'Order.WalkToTarget' expected no return value. Lint: ESLintBear (consistent-return): `Method 'Order.WalkToTarget' expected no return value.` | |||||
} | } | ||||
this.order.data.relaxed = true; | this.order.data.relaxed = true; | ||||
if (this.IsAnimal()) | if (this.IsAnimal()) | ||||
this.SetNextState("ANIMAL.WALKING"); | this.SetNextState("ANIMAL.WALKING"); | ||||
else | else | ||||
this.SetNextState("INDIVIDUAL.WALKING"); | this.SetNextState("INDIVIDUAL.WALKING"); | ||||
▲ Show 20 Lines • Show All 425 Lines • ▼ Show 20 Lines | "Order.Garrison": function(msg) { | ||||
if (!this.CheckGarrisonRange(msg.data.target)) | if (!this.CheckGarrisonRange(msg.data.target)) | ||||
{ | { | ||||
if (!this.CheckTargetVisible(msg.data.target)) | if (!this.CheckTargetVisible(msg.data.target)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
Lint: ESLintBear (no-else-return) Unnecessary 'else' after 'return'. Lint: ESLintBear (no-else-return): `Unnecessary 'else' after 'return'.` | |||||
this.SetNextState("GARRISON.APPROACHING"); | this.SetNextState("GARRISON.APPROACHING"); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
this.SetNextState("GARRISON.GARRISONING"); | this.SetNextState("GARRISON.GARRISONING"); | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 1,352 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
this.SetNextState("FINDINGNEWTARGET"); | this.SetNextState("FINDINGNEWTARGET"); | ||||
}, | }, | ||||
// TODO: respond to target deaths immediately, rather than waiting | // TODO: respond to target deaths immediately, rather than waiting | ||||
// until the next Timer event | // until the next Timer event | ||||
"Attacked": function(msg) { | "Attacked": function(msg) { | ||||
if (this.order.data.attackType == "Capture" && (this.GetStance().targetAttackersAlways || !this.order.data.force) | if (this.order.data.attackType == "Capture" && (this.GetStance().targetAttackersAlways || !this.order.data.force) | ||||
&& this.order.data.target != msg.data.attacker && this.GetBestAttackAgainst(msg.data.attacker, true) != "Capture") | && this.order.data.target != msg.data.attacker && this.GetBestAttackAgainst(msg.data.attacker, true) != "Capture") | ||||
Lint: ESLintBear (operator-linebreak) '&&' should be placed at the end of the line. Lint: ESLintBear (operator-linebreak): `'&&' should be placed at the end of the line.` | |||||
this.RespondToTargetedEntities([msg.data.attacker]); | this.RespondToTargetedEntities([msg.data.attacker]); | ||||
}, | }, | ||||
}, | }, | ||||
"FINDINGNEWTARGET": { | "FINDINGNEWTARGET": { | ||||
"Order.Cheer": function() { | "Order.Cheer": function() { | ||||
if (!this.cheeringTime) | if (!this.cheeringTime) | ||||
return { "discardOrder": true }; | return { "discardOrder": true }; | ||||
▲ Show 20 Lines • Show All 4,409 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
What other orders can it be ?