Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 965 Lines • ▼ Show 20 Lines | "PATROL": { | ||||
}, | }, | ||||
"leave": function(msg) { | "leave": function(msg) { | ||||
this.StopTimer(); | this.StopTimer(); | ||||
this.StopMoving(); | this.StopMoving(); | ||||
delete this.patrolStartPosOrder; | delete this.patrolStartPosOrder; | ||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function(msg) { | ||||
if (!this.CheckRange(this.order.data)) | if (!msg.error && !this.CheckRange(this.order.data)) | ||||
wraitii: OK - if the movement is failing, probably good to try and patrol to the other waypoint. | |||||
return; | return; | ||||
/** | /** | ||||
* A-B-A-B-..: | * A-B-A-B-..: | ||||
* if the user only commands one patrol order, the patrol will be between | * if the user only commands one patrol order, the patrol will be between | ||||
* the last position and the defined waypoint | * the last position and the defined waypoint | ||||
* A-B-C-..-A-B-..: | * A-B-C-..-A-B-..: | ||||
* otherwise, the patrol is only between the given patrol commands and the | * otherwise, the patrol is only between the given patrol commands and the | ||||
* last position is not included (last position = the position where the unit | * last position is not included (last position = the position where the unit | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | "FORMING": { | ||||
cmpFormation.MoveMembersIntoFormation(true, true); | cmpFormation.MoveMembersIntoFormation(true, true); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (!this.CheckRange(this.order.data)) | if (!msg.error && !this.CheckRange(this.order.data)) | ||||
wraitiiAuthorUnsubmitted Done Inline ActionsOK, no obvious better behaviour. wraitii: OK, no obvious better behaviour. | |||||
return; | return; | ||||
if (this.FinishOrder()) | if (this.FinishOrder()) | ||||
{ | { | ||||
this.CallMemberFunction("ResetFinishOrder", []); | this.CallMemberFunction("ResetFinishOrder", []); | ||||
return; | return; | ||||
} | } | ||||
var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | ||||
▲ Show 20 Lines • Show All 471 Lines • ▼ Show 20 Lines | "PATROL": { | ||||
delete this.patrolStartPosOrder; | delete this.patrolStartPosOrder; | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
this.FindWalkAndFightTargets(); | this.FindWalkAndFightTargets(); | ||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function(msg) { | ||||
if (!this.CheckRange(this.order.data)) | if (!msg.error && !this.CheckRange(this.order.data)) | ||||
wraitiiAuthorUnsubmitted Done Inline ActionsLikewise, patrolling to the other waypoint is sane on error. wraitii: Likewise, patrolling to the other waypoint is sane on error. | |||||
return; | return; | ||||
if (this.orderQueue.length == 1) | if (this.orderQueue.length == 1) | ||||
this.PushOrder("Patrol", this.patrolStartPosOrder); | this.PushOrder("Patrol", this.patrolStartPosOrder); | ||||
this.PushOrder(this.order.type, this.order.data); | this.PushOrder(this.order.type, this.order.data); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | "GUARD": { | ||||
"leave": function(msg) { | "leave": function(msg) { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.ResetSpeedMultiplier(); | this.ResetSpeedMultiplier(); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (this.CheckTargetRangeExplicit(this.isGuardOf, 0, this.guardRange)) | if (msg.error || this.CheckTargetRangeExplicit(this.isGuardOf, 0, this.guardRange)) | ||||
wraitiiAuthorUnsubmitted Done Inline ActionsGuarding has logic to handle real failures, and might call APPROACHING again, so this is OK. wraitii: Guarding has logic to handle real failures, and might call APPROACHING again, so this is OK. | |||||
this.SetNextState("GUARDING"); | this.SetNextState("GUARDING"); | ||||
}, | }, | ||||
}, | }, | ||||
"GUARDING": { | "GUARDING": { | ||||
"enter": function() { | "enter": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.StartTimer(1000, 1000); | this.StartTimer(1000, 1000); | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | "FLEEING": { | ||||
"leave": function() { | "leave": function() { | ||||
this.ResetSpeedMultiplier(); | this.ResetSpeedMultiplier(); | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
// When we've run far enough, stop fleeing | // When we've run far enough, stop fleeing | ||||
if (this.CheckTargetRangeExplicit(this.order.data.target, this.order.data.distanceToFlee, -1)) | if (msg.error || this.CheckTargetRangeExplicit(this.order.data.target, this.order.data.distanceToFlee, -1)) | ||||
wraitiiAuthorUnsubmitted Done Inline ActionsIf we fail to move when fleeing, probably good to stop fleeing and see what happens. wraitii: If we fail to move when fleeing, probably good to stop fleeing and see what happens. | |||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
// TODO: what if we run into more enemies while fleeing? | // TODO: what if we run into more enemies while fleeing? | ||||
}, | }, | ||||
"COMBAT": { | "COMBAT": { | ||||
"Order.LeaveFoundation": function(msg) { | "Order.LeaveFoundation": function(msg) { | ||||
▲ Show 20 Lines • Show All 758 Lines • ▼ Show 20 Lines | "TRADE": { | ||||
return true; | return true; | ||||
} | } | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function(msg) { | ||||
if (!this.CheckTargetRange(this.order.data.target, IID_Trader)) | if (!msg.error && !this.CheckTargetRange(this.order.data.target, IID_Trader)) | ||||
wraitiiAuthorUnsubmitted Done Inline ActionsOK - in case of errors, we probably want to stop trading or go to the next market. wraitii: OK - in case of errors, we probably want to stop trading or go to the next market. | |||||
return; | return; | ||||
if (this.waypoints && this.waypoints.length) | if (this.waypoints && this.waypoints.length) | ||||
{ | { | ||||
if (!this.MoveToMarket(this.order.data.target)) | if (!this.MoveToMarket(this.order.data.target)) | ||||
this.StopTrading(); | this.StopTrading(); | ||||
} | } | ||||
else | else | ||||
Show All 22 Lines | "REPAIR": { | ||||
} | } | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (this.CheckRange(this.order.data, IID_Builder)) | |||||
this.SetNextState("REPAIRING"); | this.SetNextState("REPAIRING"); | ||||
wraitiiAuthorUnsubmitted Done Inline ActionsREPAIRING has logic to handle not being in range and more, so the check is not positive here. wraitii: REPAIRING has logic to handle not being in range and more, so the check is not positive here. | |||||
}, | }, | ||||
}, | }, | ||||
"REPAIRING": { | "REPAIRING": { | ||||
"enter": function() { | "enter": function() { | ||||
// If this order was forced, the player probably gave it, but now we've reached the target | // If this order was forced, the player probably gave it, but now we've reached the target | ||||
// switch to an unforced order (can be interrupted by attacks) | // switch to an unforced order (can be interrupted by attacks) | ||||
if (this.order.data.force) | if (this.order.data.force) | ||||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | "GARRISON": { | ||||
} | } | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (this.CheckGarrisonRange(this.order.data.target)) | |||||
this.SetNextState("GARRISONED"); | this.SetNextState("GARRISONED"); | ||||
wraitiiAuthorUnsubmitted Done Inline ActionsLikewise, Garrisoned has logic to handle actual errors and success more than here. wraitii: Likewise, Garrisoned has logic to handle actual errors and success more than here. | |||||
}, | }, | ||||
}, | }, | ||||
"GARRISONED": { | "GARRISONED": { | ||||
"enter": function() { | "enter": function() { | ||||
if (this.order.data.target) | if (this.order.data.target) | ||||
var target = this.order.data.target; | var target = this.order.data.target; | ||||
else | else | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | "PICKUP": { | ||||
} | } | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (this.CheckRange(this.order.data)) | |||||
this.SetNextState("LOADING"); | this.SetNextState("LOADING"); | ||||
wraitiiAuthorUnsubmitted Done Inline ActionsLikewise, LOADING has logic to handle errors (and success) more than this here. wraitii: Likewise, LOADING has logic to handle errors (and success) more than this here. | |||||
}, | }, | ||||
"PickupCanceled": function() { | "PickupCanceled": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 2,953 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
OK - if the movement is failing, probably good to try and patrol to the other waypoint.