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,571 Lines • ▼ Show 20 Lines | if (this.orderQueue.length && (this.IsGarrisoned() || cmpPosition && cmpPosition.IsInWorld())) | ||||
// and process the remaining queue | // and process the remaining queue | ||||
if (ret && ret.discardOrder) | if (ret && ret.discardOrder) | ||||
return this.FinishOrder(); | return this.FinishOrder(); | ||||
// Otherwise we've successfully processed a new order | // Otherwise we've successfully processed a new order | ||||
return true; | return true; | ||||
} | } | ||||
this.orderQueue = []; | |||||
this.order = undefined; | |||||
this.SetNextState("IDLE"); | this.SetNextState("IDLE"); | ||||
Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() }); | Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() }); | ||||
// Check if there are queued formation orders | // Check if there are queued formation orders | ||||
if (this.IsFormationMember()) | if (this.IsFormationMember()) | ||||
{ | { | ||||
let cmpUnitAI = Engine.QueryInterface(this.formationController, IID_UnitAI); | let cmpUnitAI = Engine.QueryInterface(this.formationController, IID_UnitAI); | ||||
Show All 19 Lines | UnitAI.prototype.PushOrder = function(type, data) | ||||
var order = { "type": type, "data": data }; | var order = { "type": type, "data": data }; | ||||
this.orderQueue.push(order); | this.orderQueue.push(order); | ||||
// If we didn't already have an order, then process this new one | // If we didn't already have an order, then process this new one | ||||
if (this.orderQueue.length == 1) | if (this.orderQueue.length == 1) | ||||
{ | { | ||||
this.order = order; | this.order = order; | ||||
let ret = this.UnitFsm.ProcessMessage(this, | let ret = this.UnitFsm.ProcessMessage(this, | ||||
{"type": "Order."+this.order.type, "data": this.order.data} | { "type": "Order."+this.order.type, "data": this.order.data } | ||||
); | ); | ||||
// If the order was rejected then immediately take it off | // If the order was rejected then immediately take it off | ||||
// and process the remaining queue | // and process the remaining queue | ||||
if (ret && ret.discardOrder) | if (ret && ret.discardOrder) | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
} | } | ||||
Show All 19 Lines | else if (this.order && this.IsPacking()) | ||||
var packingOrder = this.orderQueue.shift(); | var packingOrder = this.orderQueue.shift(); | ||||
this.orderQueue.unshift(packingOrder, order); | this.orderQueue.unshift(packingOrder, order); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
this.orderQueue.unshift(order); | this.orderQueue.unshift(order); | ||||
this.order = order; | this.order = order; | ||||
let ret = this.UnitFsm.ProcessMessage(this, | let ret = this.UnitFsm.ProcessMessage(this, | ||||
{"type": "Order."+this.order.type, "data": this.order.data} | { "type": "Order."+this.order.type, "data": this.order.data } | ||||
); | ); | ||||
// If the order was rejected then immediately take it off again; | // If the order was rejected then immediately take it off again; | ||||
// assume the previous active order is still valid (the short-lived | // assume the previous active order is still valid (the short-lived | ||||
// new order hasn't changed state or anything) so we can carry on | // new order hasn't changed state or anything) so we can carry on | ||||
// as if nothing had happened | // as if nothing had happened | ||||
if (ret && ret.discardOrder) | if (ret && ret.discardOrder) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,198 Lines • ▼ Show 20 Lines | if (cmpGuard) | ||||
cmpGuard.RemoveGuard(this.entity); | cmpGuard.RemoveGuard(this.entity); | ||||
this.guardRange = undefined; | this.guardRange = undefined; | ||||
this.isGuardOf = undefined; | this.isGuardOf = undefined; | ||||
if (!this.order) | if (!this.order) | ||||
return; | return; | ||||
if (this.order.type == "Guard") | if (this.order.type == "Guard") | ||||
this.UnitFsm.ProcessMessage(this, {"type": "RemoveGuard"}); | this.UnitFsm.ProcessMessage(this, { "type": "RemoveGuard" }); | ||||
else | else | ||||
for (let i = 1; i < this.orderQueue.length; ++i) | for (let i = 1; i < this.orderQueue.length; ++i) | ||||
if (this.orderQueue[i].type == "Guard") | if (this.orderQueue[i].type == "Guard") | ||||
this.orderQueue.splice(i, 1); | this.orderQueue.splice(i, 1); | ||||
Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() }); | Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() }); | ||||
}; | }; | ||||
UnitAI.prototype.IsGuardOf = function() | UnitAI.prototype.IsGuardOf = function() | ||||
▲ Show 20 Lines • Show All 1,080 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator