Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 3,680 Lines • ▼ Show 20 Lines | for (let order of this.orderQueue) | ||||
if (order.data) | if (order.data) | ||||
orders.push(clone(order.data)); | orders.push(clone(order.data)); | ||||
return orders; | return orders; | ||||
}; | }; | ||||
UnitAI.prototype.UpdateWorkOrders = function(type) | UnitAI.prototype.UpdateWorkOrders = function(type) | ||||
{ | { | ||||
var isWorkType = type => type == "Gather" || type == "Trade" || type == "Repair" || type == "ReturnResource"; | var isWorkType = type => type == "Gather" || type == "Trade" || type == "Repair";// || type == "ReturnResource"; | ||||
// If we are being re-affected to a work order, forget the previous ones | // If we are being re-affected to a work order, forget the previous ones | ||||
if (isWorkType(type)) | if (isWorkType(type)) | ||||
{ | { | ||||
this.workOrders = []; | this.workOrders = []; | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,188 Lines • ▼ Show 20 Lines | |||||
* Adds stop order to queue, forced by the player. | * Adds stop order to queue, forced by the player. | ||||
*/ | */ | ||||
UnitAI.prototype.Stop = function(queued) | UnitAI.prototype.Stop = function(queued) | ||||
{ | { | ||||
this.AddOrder("Stop", { "force": true }, queued); | this.AddOrder("Stop", { "force": true }, queued); | ||||
}; | }; | ||||
/** | /** | ||||
* Adds CallToArms order to queue, forced by the player, | |||||
* targeting the nearest dropsite. | |||||
* | |||||
* @param {float[]} target.x, target.y, target.z - the x,y,z-values to where the units need to walk (after dropping resources) | |||||
* @param {string[]} targetClasses | |||||
* @param {boolean} allowCapture | |||||
Stan: I guess that function is duplicated elsewhere, would be nice to unify the calls. | |||||
* @param {boolean} queued - Whether the order is queued or not | |||||
*/ | |||||
UnitAI.prototype.CallToArms = function(target, targetClasses, allowCapture, queued) | |||||
{ | |||||
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | |||||
let resourceType; | |||||
if (cmpResourceGatherer) | |||||
resourceType = cmpResourceGatherer.GetMainCarryingType(); | |||||
Done Inline Actionsif forced by player you should pass "force": true Silier: if forced by player you should pass "force": true | |||||
let nearby = this.FindNearestDropsite(resourceType); | |||||
SilierUnsubmitted Done Inline Actionsdont bother if !cmpResourceGatherer Silier: dont bother if !cmpResourceGatherer | |||||
if (nearby) | |||||
this.AddOrder("ReturnResource", { "target": nearby, "force": true }, queued); | |||||
else | |||||
this.AddOrder("Stop", { "force": true }, queued); | |||||
this.AddOrder("WalkAndFight", { "x": target.x, "z": target.z, "targetClasses": targetClasses, "allowCapture": allowCapture, "force": true }, true); | |||||
}; | |||||
/** | |||||
* Adds walk-to-target order to queue, this only occurs in response | * Adds walk-to-target order to queue, this only occurs in response | ||||
* to a player order, and so is forced. | * to a player order, and so is forced. | ||||
*/ | */ | ||||
UnitAI.prototype.WalkToTarget = function(target, queued) | UnitAI.prototype.WalkToTarget = function(target, queued) | ||||
{ | { | ||||
this.AddOrder("WalkToTarget", { "target": target, "force": true }, queued); | this.AddOrder("WalkToTarget", { "target": target, "force": true }, queued); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 1,021 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I guess that function is duplicated elsewhere, would be nice to unify the calls.