Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/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)) | ||||
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)) | ||||
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 480 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)) | ||||
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() { | "MovementUpdate": function(msg) { | ||||
if (this.CheckTargetRangeExplicit(this.isGuardOf, 0, this.guardRange)) | if (msg.error || this.CheckTargetRangeExplicit(this.isGuardOf, 0, this.guardRange)) | ||||
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": { | ||||
this.SetSpeedMultiplier(this.GetRunMultiplier()); | this.SetSpeedMultiplier(this.GetRunMultiplier()); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.ResetSpeedMultiplier(); | this.ResetSpeedMultiplier(); | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function() { | "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)) | ||||
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 764 Lines • ▼ Show 20 Lines | "TRADE": { | ||||
} | } | ||||
this.SelectAnimation("move"); | this.SelectAnimation("move"); | ||||
}, | }, | ||||
"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)) | ||||
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 23 Lines | "REPAIR": { | ||||
this.SelectAnimation("move"); | this.SelectAnimation("move"); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function() { | ||||
if (this.CheckRange(this.order.data, IID_Builder)) | |||||
this.SetNextState("REPAIRING"); | this.SetNextState("REPAIRING"); | ||||
}, | }, | ||||
}, | }, | ||||
"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": { | ||||
this.SelectAnimation("move"); | this.SelectAnimation("move"); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function() { | ||||
if (this.CheckGarrisonRange(this.order.data.target)) | |||||
this.SetNextState("GARRISONED"); | this.SetNextState("GARRISONED"); | ||||
}, | }, | ||||
}, | }, | ||||
"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": { | ||||
this.SelectAnimation("move"); | this.SelectAnimation("move"); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function() { | ||||
if (this.CheckRange(this.order.data)) | |||||
this.SetNextState("LOADING"); | this.SetNextState("LOADING"); | ||||
}, | }, | ||||
"PickupCanceled": function() { | "PickupCanceled": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 2,956 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator