Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 2,789 Lines • ▼ Show 20 Lines | "GARRISON": { | ||||
"MovementUpdate": function() { | "MovementUpdate": function() { | ||||
this.SetNextState("GARRISONED"); | this.SetNextState("GARRISONED"); | ||||
}, | }, | ||||
}, | }, | ||||
"GARRISONED": { | "GARRISONED": { | ||||
"enter": function() { | "enter": function() { | ||||
if (this.order.data.target) | let target = this.order.data.target; | ||||
var target = this.order.data.target; | if (!target) | ||||
else | |||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
if (this.IsGarrisoned()) | if (this.IsGarrisoned()) | ||||
return false; | return false; | ||||
// Check that we can garrison here | // Check that we can garrison here | ||||
if (this.CanGarrison(target)) | if (this.CanGarrison(target)) | ||||
{ | |||||
// Check that we're in range of the garrison target | // Check that we're in range of the garrison target | ||||
if (this.CheckGarrisonRange(target)) | if (this.CheckGarrisonRange(target)) | ||||
{ | { | ||||
var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder); | var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder); | ||||
// Check that garrisoning succeeds | // Check that garrisoning succeeds | ||||
if (cmpGarrisonHolder.Garrison(this.entity)) | if (cmpGarrisonHolder.Garrison(this.entity)) | ||||
{ | { | ||||
this.isGarrisoned = true; | this.isGarrisoned = true; | ||||
Show All 34 Lines | "GARRISON": { | ||||
var cmpHolderUnitAI = Engine.QueryInterface(target, IID_UnitAI); | var cmpHolderUnitAI = Engine.QueryInterface(target, IID_UnitAI); | ||||
if (cmpHolderUnitAI && cmpHolderPosition) | if (cmpHolderUnitAI && cmpHolderPosition) | ||||
cmpHolderUnitAI.lastShorelinePosition = cmpHolderPosition.GetPosition(); | cmpHolderUnitAI.lastShorelinePosition = cmpHolderPosition.GetPosition(); | ||||
Engine.PostMessage(this.pickup, MT_PickupCanceled, { "entity": this.entity }); | Engine.PostMessage(this.pickup, MT_PickupCanceled, { "entity": this.entity }); | ||||
delete this.pickup; | delete this.pickup; | ||||
} | } | ||||
if (this.IsTurret()) | if (this.IsTurret()) | ||||
{ | |||||
this.SetNextState("IDLE"); | this.SetNextState("IDLE"); | ||||
return true; | |||||
} | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// Unable to reach the target, try again (or follow if it is a moving target) | // Unable to reach the target, try again (or follow if it is a moving target) | ||||
// except if the does not exits anymore or its orders have changed | // except if the does not exits anymore or its orders have changed | ||||
if (this.pickup) | if (this.pickup) | ||||
{ | { | ||||
var cmpUnitAI = Engine.QueryInterface(this.pickup, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(this.pickup, IID_UnitAI); | ||||
if (!cmpUnitAI || !cmpUnitAI.HasPickupOrder(this.entity)) | if (!cmpUnitAI || !cmpUnitAI.HasPickupOrder(this.entity)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
if (!this.CheckTargetRangeExplicit(target, 0, 0) && this.MoveToTarget(target)) | |||||
{ | |||||
this.SetNextState("APPROACHING"); | this.SetNextState("APPROACHING"); | ||||
return false; | return true; | ||||
} | |||||
} | |||||
} | } | ||||
// Garrisoning failed for some reason, so finish the order | // Garrisoning failed for some reason, so finish the order | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
} | } | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | "IDLE": { | ||||
this.SetNextState("FEEDING"); | this.SetNextState("FEEDING"); | ||||
return true; | return true; | ||||
}, | }, | ||||
}, | }, | ||||
"ROAMING": { | "ROAMING": { | ||||
"enter": function() { | "enter": function() { | ||||
// Walk in a random direction | // Walk in a random direction | ||||
this.SelectAnimation("walk", false, 1); | this.SelectAnimation("move", false, 1); | ||||
this.SetFacePointAfterMove(false); | this.SetFacePointAfterMove(false); | ||||
this.MoveRandomly(+this.template.RoamDistance); | this.MoveRandomly(+this.template.RoamDistance); | ||||
// Set a random timer to switch to feeding state | // Set a random timer to switch to feeding state | ||||
this.StartTimer(randIntInclusive(+this.template.RoamTimeMin, +this.template.RoamTimeMax)); | this.StartTimer(randIntInclusive(+this.template.RoamTimeMin, +this.template.RoamTimeMax)); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
▲ Show 20 Lines • Show All 2,137 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
if (this.waypoints && this.waypoints.length > 1) | if (this.waypoints && this.waypoints.length > 1) | ||||
{ | { | ||||
let point = this.waypoints.pop(); | let point = this.waypoints.pop(); | ||||
return this.MoveToPoint(point.x, point.z) || this.MoveToMarket(targetMarket); | return this.MoveToPoint(point.x, point.z) || this.MoveToMarket(targetMarket); | ||||
} | } | ||||
this.waypoints = undefined; | this.waypoints = undefined; | ||||
return this.MoveToTarget(targetMarket); | return this.MoveToTargetRange(targetMarket, IID_Trader); | ||||
}; | }; | ||||
UnitAI.prototype.PerformTradeAndMoveToNextMarket = function(currentMarket) | UnitAI.prototype.PerformTradeAndMoveToNextMarket = function(currentMarket) | ||||
{ | { | ||||
if (!this.CanTrade(currentMarket)) | if (!this.CanTrade(currentMarket)) | ||||
{ | { | ||||
this.StopTrading(); | this.StopTrading(); | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 749 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator