Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 783 Lines • ▼ Show 20 Lines | "Order.Gather": function(msg) { | ||||
// TODO: on what should we base this range? | // TODO: on what should we base this range? | ||||
if (!this.CheckTargetRangeExplicit(msg.data.target, 0, 10)) | if (!this.CheckTargetRangeExplicit(msg.data.target, 0, 10)) | ||||
{ | { | ||||
if (!this.CanGather(msg.data.target) || !this.CheckTargetVisible(msg.data.target)) | if (!this.CanGather(msg.data.target) || !this.CheckTargetVisible(msg.data.target)) | ||||
return REJECT_ORDER; | return REJECT_ORDER; | ||||
// TODO: Should we issue a gather-near-position order | // TODO: Should we issue a gather-near-position order | ||||
// if the target isn't gatherable/doesn't exist anymore? | // if the target isn't gatherable/doesn't exist anymore? | ||||
if (!msg.data.secondTry) | |||||
{ | |||||
msg.data.secondTry = true; | |||||
this.PushOrderFront("WalkToTargetRange", { "target": msg.data.target, "min": 0, "max": 10 }); | this.PushOrderFront("WalkToTargetRange", { "target": msg.data.target, "min": 0, "max": 10 }); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
} | } | ||||
return REJECT_ORDER; | |||||
} | |||||
this.CallMemberFunction("Gather", [msg.data.target, false]); | this.CallMemberFunction("Gather", [msg.data.target, false]); | ||||
this.SetNextState("MEMBER"); | this.SetNextState("MEMBER"); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
}, | }, | ||||
"Order.GatherNearPosition": function(msg) { | "Order.GatherNearPosition": function(msg) { | ||||
Show All 13 Lines | "FORMATIONCONTROLLER": { | ||||
"Order.Heal": function(msg) { | "Order.Heal": function(msg) { | ||||
// TODO: on what should we base this range? | // TODO: on what should we base this range? | ||||
if (!this.CheckTargetRangeExplicit(msg.data.target, 0, 10)) | if (!this.CheckTargetRangeExplicit(msg.data.target, 0, 10)) | ||||
{ | { | ||||
if (!this.TargetIsAlive(msg.data.target) || !this.CheckTargetVisible(msg.data.target)) | if (!this.TargetIsAlive(msg.data.target) || !this.CheckTargetVisible(msg.data.target)) | ||||
return REJECT_ORDER; | return REJECT_ORDER; | ||||
// Out of range; move there in formation. | if (!msg.data.secondTry) | ||||
{ | |||||
msg.data.secondTry = true; | |||||
this.PushOrderFront("WalkToTargetRange", { "target": msg.data.target, "min": 0, "max": 10 }); | this.PushOrderFront("WalkToTargetRange", { "target": msg.data.target, "min": 0, "max": 10 }); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
} | } | ||||
return REJECT_ORDER; | |||||
} | |||||
this.CallMemberFunction("Heal", [msg.data.target, false]); | this.CallMemberFunction("Heal", [msg.data.target, false]); | ||||
this.SetNextState("MEMBER"); | this.SetNextState("MEMBER"); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
}, | }, | ||||
"Order.Repair": function(msg) { | "Order.Repair": function(msg) { | ||||
// TODO: on what should we base this range? | // TODO: on what should we base this range? | ||||
if (!this.CheckTargetRangeExplicit(msg.data.target, 0, 10)) | if (!this.CheckTargetRangeExplicit(msg.data.target, 0, 10)) | ||||
{ | { | ||||
if (!this.TargetIsAlive(msg.data.target) || !this.CheckTargetVisible(msg.data.target)) | if (!this.TargetIsAlive(msg.data.target) || !this.CheckTargetVisible(msg.data.target)) | ||||
return REJECT_ORDER; | return REJECT_ORDER; | ||||
// Out of range move there in formation. | if (!msg.data.secondTry) | ||||
{ | |||||
msg.data.secondTry = true; | |||||
this.PushOrderFront("WalkToTargetRange", { "target": msg.data.target, "min": 0, "max": 10 }); | this.PushOrderFront("WalkToTargetRange", { "target": msg.data.target, "min": 0, "max": 10 }); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
} | } | ||||
return REJECT_ORDER; | |||||
} | |||||
this.CallMemberFunction("Repair", [msg.data.target, msg.data.autocontinue, false]); | this.CallMemberFunction("Repair", [msg.data.target, msg.data.autocontinue, false]); | ||||
this.SetNextState("MEMBER"); | this.SetNextState("MEMBER"); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
}, | }, | ||||
"Order.ReturnResource": function(msg) { | "Order.ReturnResource": function(msg) { | ||||
// TODO: on what should we base this range? | // TODO: on what should we base this range? | ||||
if (!this.CheckTargetRangeExplicit(msg.data.target, 0, 10)) | if (!this.CheckTargetRangeExplicit(msg.data.target, 0, 10)) | ||||
{ | { | ||||
if (!this.CheckTargetVisible(msg.data.target)) | if (!this.CheckTargetVisible(msg.data.target)) | ||||
return REJECT_ORDER; | return REJECT_ORDER; | ||||
// Out of range; move there in formation. | if (!msg.data.secondTry) | ||||
{ | |||||
msg.data.secondTry = true; | |||||
this.PushOrderFront("WalkToTargetRange", { "target": msg.data.target, "min": 0, "max": 10 }); | this.PushOrderFront("WalkToTargetRange", { "target": msg.data.target, "min": 0, "max": 10 }); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
} | } | ||||
return REJECT_ORDER; | |||||
} | |||||
this.CallMemberFunction("ReturnResource", [msg.data.target, false]); | this.CallMemberFunction("ReturnResource", [msg.data.target, false]); | ||||
this.SetNextState("MEMBER"); | this.SetNextState("MEMBER"); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
}, | }, | ||||
"Order.Pack": function(msg) { | "Order.Pack": function(msg) { | ||||
Show All 38 Lines | "IDLE": { | ||||
if (this.TestAllMemberFunction("IsIdle")) | if (this.TestAllMemberFunction("IsIdle")) | ||||
cmpFormation.MoveMembersIntoFormation(false, false); | cmpFormation.MoveMembersIntoFormation(false, false); | ||||
}, | }, | ||||
}, | }, | ||||
"WALKING": { | "WALKING": { | ||||
"enter": function() { | "enter": function() { | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true); | |||||
if (!this.MoveTo(this.order.data)) | if (!this.MoveTo(this.order.data)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true); | |||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopTimer(); | this.StopTimer(); | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
Show All 16 Lines | "WALKING": { | ||||
"Timer": function() { | "Timer": function() { | ||||
// Reenter to reset the pathfinder state. | // Reenter to reset the pathfinder state. | ||||
this.SetNextState("WALKING"); | this.SetNextState("WALKING"); | ||||
} | } | ||||
}, | }, | ||||
"WALKINGANDFIGHTING": { | "WALKINGANDFIGHTING": { | ||||
"enter": function(msg) { | "enter": function(msg) { | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true, "combat"); | |||||
if (!this.MoveTo(this.order.data)) | if (!this.MoveTo(this.order.data)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.StartTimer(0, 1000); | this.StartTimer(0, 1000); | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true, "combat"); | |||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
}, | }, | ||||
Show All 30 Lines | "PATROL": { | ||||
"leave": function() { | "leave": function() { | ||||
delete this.patrolStartPosOrder; | delete this.patrolStartPosOrder; | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
}, | }, | ||||
"PATROLLING": { | "PATROLLING": { | ||||
"enter": function() { | "enter": function() { | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true, "combat"); | |||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
if (!cmpPosition || !cmpPosition.IsInWorld() || | if (!cmpPosition || !cmpPosition.IsInWorld() || | ||||
!this.MoveTo(this.order.data)) | !this.MoveTo(this.order.data)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true, "combat"); | |||||
this.StartTimer(0, 1000); | this.StartTimer(0, 1000); | ||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
}, | }, | ||||
Show All 37 Lines | "PATROL": { | ||||
++this.stopSurveying; | ++this.stopSurveying; | ||||
} | } | ||||
} | } | ||||
}, | }, | ||||
"GARRISON": { | "GARRISON": { | ||||
"APPROACHING": { | "APPROACHING": { | ||||
"enter": function() { | "enter": function() { | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true); | |||||
if (!this.MoveToGarrisonRange(this.order.data.target)) | if (!this.MoveToGarrisonRange(this.order.data.target)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true); | |||||
// If the garrisonholder should pickup, warn it so it can take needed action. | // If the garrisonholder should pickup, warn it so it can take needed action. | ||||
let cmpGarrisonHolder = Engine.QueryInterface(this.order.data.target, IID_GarrisonHolder); | let cmpGarrisonHolder = Engine.QueryInterface(this.order.data.target, IID_GarrisonHolder); | ||||
if (cmpGarrisonHolder && cmpGarrisonHolder.CanPickup(this.entity)) | if (cmpGarrisonHolder && cmpGarrisonHolder.CanPickup(this.entity)) | ||||
{ | { | ||||
this.pickup = this.order.data.target; // temporary, deleted in "leave" | this.pickup = this.order.data.target; // temporary, deleted in "leave" | ||||
Engine.PostMessage(this.pickup, MT_PickupRequested, { "entity": this.entity }); | Engine.PostMessage(this.pickup, MT_PickupRequested, { "entity": this.entity }); | ||||
} | } | ||||
Show All 23 Lines | "GARRISON": { | ||||
this.SetNextState("MEMBER"); | this.SetNextState("MEMBER"); | ||||
return true; | return true; | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
"FORMING": { | "FORMING": { | ||||
"enter": function() { | "enter": function() { | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true); | |||||
if (!this.MoveTo(this.order.data)) | if (!this.MoveTo(this.order.data)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true); | |||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (!msg.likelyFailure && !this.CheckRange(this.order.data)) | if (!msg.likelyFailure && !this.CheckRange(this.order.data)) | ||||
return; | return; | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
} | } | ||||
}, | }, | ||||
"COMBAT": { | "COMBAT": { | ||||
"APPROACHING": { | "APPROACHING": { | ||||
"enter": function() { | "enter": function() { | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true, "combat"); | |||||
if (!this.MoveFormationToTargetAttackRange(this.order.data.target)) | if (!this.MoveFormationToTargetAttackRange(this.order.data.target)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||
cmpFormation.SetRearrange(true); | |||||
cmpFormation.MoveMembersIntoFormation(true, true, "combat"); | |||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
▲ Show 20 Lines • Show All 5,341 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator