Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 3,425 Lines • ▼ Show 20 Lines | UnitAI.prototype.IsGarrisoned = function() | ||||
return this.isGarrisoned; | return this.isGarrisoned; | ||||
}; | }; | ||||
UnitAI.prototype.SetGarrisoned = function() | UnitAI.prototype.SetGarrisoned = function() | ||||
{ | { | ||||
this.isGarrisoned = true; | this.isGarrisoned = true; | ||||
}; | }; | ||||
UnitAI.prototype.GetGarrisonHolder = function() | |||||
{ | |||||
if (this.IsGarrisoned()) | |||||
{ | |||||
for (let order of this.orderQueue) | |||||
if (order.type == "Garrison" || order.type == "Autogarrison") | |||||
return order.data.target; | |||||
} | |||||
return INVALID_ENTITY; | |||||
}; | |||||
UnitAI.prototype.IsFleeing = function() | UnitAI.prototype.IsFleeing = function() | ||||
{ | { | ||||
var state = this.GetCurrentState().split(".").pop(); | var state = this.GetCurrentState().split(".").pop(); | ||||
return (state == "FLEEING"); | return (state == "FLEEING"); | ||||
}; | }; | ||||
UnitAI.prototype.IsWalking = function() | UnitAI.prototype.IsWalking = function() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 387 Lines • ▼ Show 20 Lines | UnitAI.prototype.ReplaceOrder = function(type, data) | ||||
if (data && data.force) | if (data && data.force) | ||||
{ | { | ||||
if (this.IsFormationController()) | if (this.IsFormationController()) | ||||
this.CallMemberFunction("UpdateWorkOrders", [type]); | this.CallMemberFunction("UpdateWorkOrders", [type]); | ||||
else | else | ||||
this.UpdateWorkOrders(type); | this.UpdateWorkOrders(type); | ||||
} | } | ||||
let garrisonHolder = this.IsGarrisoned() && type != "Ungarrison" ? this.GetGarrisonHolder() : null; | |||||
// Special cases of orders that shouldn't be replaced: | // Special cases of orders that shouldn't be replaced: | ||||
// 1. Cheering - we're invulnerable, add order after we finish | // 1. Cheering - we're invulnerable, add order after we finish | ||||
// 2. Packing/unpacking - we're immobile, add order after we finish (unless it's cancel) | // 2. Packing/unpacking - we're immobile, add order after we finish (unless it's cancel) | ||||
// TODO: maybe a better way of doing this would be to use priority levels | // TODO: maybe a better way of doing this would be to use priority levels | ||||
if (this.order && this.order.type == "Cheering") | if (this.order && this.order.type == "Cheering") | ||||
{ | { | ||||
var order = { "type": type, "data": data }; | var order = { "type": type, "data": data }; | ||||
var cheeringOrder = this.orderQueue.shift(); | var cheeringOrder = this.orderQueue.shift(); | ||||
this.orderQueue = [cheeringOrder, order]; | this.orderQueue = [cheeringOrder, order]; | ||||
} | } | ||||
else if (this.IsPacking() && type != "CancelPack" && type != "CancelUnpack") | else if (this.IsPacking() && type != "CancelPack" && type != "CancelUnpack") | ||||
{ | { | ||||
var order = { "type": type, "data": data }; | var order = { "type": type, "data": data }; | ||||
var packingOrder = this.orderQueue.shift(); | var packingOrder = this.orderQueue.shift(); | ||||
this.orderQueue = [packingOrder, order]; | this.orderQueue = [packingOrder, order]; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
this.orderQueue = []; | this.orderQueue = []; | ||||
this.PushOrder(type, data); | this.PushOrder(type, data); | ||||
} | } | ||||
if (garrisonHolder) | |||||
this.PushOrder("Garrison", { "target": garrisonHolder }); | |||||
Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() }); | Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() }); | ||||
}; | }; | ||||
UnitAI.prototype.GetOrders = function() | UnitAI.prototype.GetOrders = function() | ||||
{ | { | ||||
return this.orderQueue.slice(); | return this.orderQueue.slice(); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | UnitAI.prototype.UpdateWorkOrders = function(type) | ||||
} | } | ||||
}; | }; | ||||
UnitAI.prototype.BackToWork = function() | UnitAI.prototype.BackToWork = function() | ||||
{ | { | ||||
if (this.workOrders.length == 0) | if (this.workOrders.length == 0) | ||||
return false; | return false; | ||||
if (this.IsGarrisoned()) | |||||
{ | |||||
let cmpGarrisonHolder = Engine.QueryInterface(this.GetGarrisonHolder(), IID_GarrisonHolder); | |||||
if (!cmpGarrisonHolder || !cmpGarrisonHolder.PerformEject([this.entity], false)) | |||||
return false; | |||||
} | |||||
// Clear the order queue considering special orders not to avoid | // Clear the order queue considering special orders not to avoid | ||||
if (this.order && this.order.type == "Cheering") | if (this.order && this.order.type == "Cheering") | ||||
{ | { | ||||
var cheeringOrder = this.orderQueue.shift(); | var cheeringOrder = this.orderQueue.shift(); | ||||
this.orderQueue = [cheeringOrder]; | this.orderQueue = [cheeringOrder]; | ||||
} | } | ||||
else | else | ||||
this.orderQueue = []; | this.orderQueue = []; | ||||
▲ Show 20 Lines • Show All 2,169 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator