Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 550 Lines • ▼ Show 20 Lines | "Order.GatherNearPosition": function(msg) { | |||||||||||||||||||
if (!this.AbleToMove()) | if (!this.AbleToMove()) | |||||||||||||||||||
return this.FinishOrder(); | return this.FinishOrder(); | |||||||||||||||||||
this.SetNextState("INDIVIDUAL.GATHER.WALKING"); | this.SetNextState("INDIVIDUAL.GATHER.WALKING"); | |||||||||||||||||||
msg.data.initPos = { 'x': msg.data.x, 'z': msg.data.z }; | msg.data.initPos = { 'x': msg.data.x, 'z': msg.data.z }; | |||||||||||||||||||
msg.data.relaxed = true; | msg.data.relaxed = true; | |||||||||||||||||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | |||||||||||||||||||
}, | }, | |||||||||||||||||||
"Order.DropAtNearestDropSite": function(msg) { | ||||||||||||||||||||
const cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | ||||||||||||||||||||
if (!cmpResourceGatherer) | ||||||||||||||||||||
return this.FinishOrder(); | ||||||||||||||||||||
const nearby = this.FindNearestDropsite(cmpResourceGatherer.GetMainCarryingType()); | ||||||||||||||||||||
if (!nearby) | ||||||||||||||||||||
return this.FinishOrder(); | ||||||||||||||||||||
this.ReturnResource(nearby, false, true); | ||||||||||||||||||||
return ACCEPT_ORDER; | ||||||||||||||||||||
}, | ||||||||||||||||||||
"Order.ReturnResource": function(msg) { | "Order.ReturnResource": function(msg) { | |||||||||||||||||||
if (this.CheckTargetRange(msg.data.target, IID_ResourceGatherer)) | if (this.CheckTargetRange(msg.data.target, IID_ResourceGatherer)) | |||||||||||||||||||
this.SetNextState("INDIVIDUAL.RETURNRESOURCE.DROPPINGRESOURCES"); | this.SetNextState("INDIVIDUAL.RETURNRESOURCE.DROPPINGRESOURCES"); | |||||||||||||||||||
else if (this.AbleToMove()) | else if (this.AbleToMove()) | |||||||||||||||||||
this.SetNextState("INDIVIDUAL.RETURNRESOURCE.APPROACHING"); | this.SetNextState("INDIVIDUAL.RETURNRESOURCE.APPROACHING"); | |||||||||||||||||||
else | else | |||||||||||||||||||
return this.FinishOrder(); | return this.FinishOrder(); | |||||||||||||||||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | |||||||||||||||||||
▲ Show 20 Lines • Show All 388 Lines • ▼ Show 20 Lines | "FORMATIONCONTROLLER": { | |||||||||||||||||||
"Order.Unpack": function(msg) { | "Order.Unpack": function(msg) { | |||||||||||||||||||
this.CallMemberFunction("Unpack", [false]); | this.CallMemberFunction("Unpack", [false]); | |||||||||||||||||||
this.SetNextState("MEMBER"); | this.SetNextState("MEMBER"); | |||||||||||||||||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | |||||||||||||||||||
}, | }, | |||||||||||||||||||
"Order.DropAtNearestDropSite": function(msg) { | ||||||||||||||||||||
this.CallMemberFunction("DropAtNearestDropSite", [false, false]); | ||||||||||||||||||||
this.SetNextState("MEMBER"); | ||||||||||||||||||||
return ACCEPT_ORDER; | ||||||||||||||||||||
}, | ||||||||||||||||||||
"IDLE": { | "IDLE": { | |||||||||||||||||||
"enter": function(msg) { | "enter": function(msg) { | |||||||||||||||||||
// Turn rearrange off. Otherwise, if the formation is idle | // Turn rearrange off. Otherwise, if the formation is idle | |||||||||||||||||||
// but individual units go off to fight, | // but individual units go off to fight, | |||||||||||||||||||
// any death will rearrange the formation, which looks odd. | // any death will rearrange the formation, which looks odd. | |||||||||||||||||||
// Instead, move idle units in formation on a timer. | // Instead, move idle units in formation on a timer. | |||||||||||||||||||
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); | |||||||||||||||||||
cmpFormation.SetRearrange(false); | cmpFormation.SetRearrange(false); | |||||||||||||||||||
▲ Show 20 Lines • Show All 3,118 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"; | const isWorkType = t => t == "Gather" || t == "Trade" || t == "Repair" || t == "ReturnResource"; | |||||||||||||||||||
Freagarach: Do notice this is a small change in behaviour. Entities tasked to return resources no longer… | ||||||||||||||||||||
Done Inline ActionsI didn't say it was bad, especially since now one can't order your units back to work after such an attack. Perhaps more people are opinionated about this. Freagarach: I didn't say it was bad, especially since now one can't order your units back to work after… | ||||||||||||||||||||
if (isWorkType(type)) | if (isWorkType(type)) | |||||||||||||||||||
{ | { | |||||||||||||||||||
this.workOrders = []; | this.workOrders = []; | |||||||||||||||||||
return; | return; | |||||||||||||||||||
} | } | |||||||||||||||||||
if (this.workOrders.length) | if (this.workOrders.length) | |||||||||||||||||||
return; | return; | |||||||||||||||||||
▲ Show 20 Lines • Show All 1,122 Lines • ▼ Show 20 Lines | case "CollectTreasure": | |||||||||||||||||||
if (!cmpTargetPosition || !cmpTargetPosition.IsInWorld()) | if (!cmpTargetPosition || !cmpTargetPosition.IsInWorld()) | |||||||||||||||||||
return targetPositions; | return targetPositions; | |||||||||||||||||||
targetPositions.push(cmpTargetPosition.GetPosition2D()); | targetPositions.push(cmpTargetPosition.GetPosition2D()); | |||||||||||||||||||
return targetPositions; | return targetPositions; | |||||||||||||||||||
case "Stop": | case "Stop": | |||||||||||||||||||
return []; | return []; | |||||||||||||||||||
case "DropAtNearestDropSite": | ||||||||||||||||||||
break; | ||||||||||||||||||||
default: | default: | |||||||||||||||||||
error("GetTargetPositions: Unrecognised order type '"+order.type+"'"); | error("GetTargetPositions: Unrecognised order type '"+order.type+"'"); | |||||||||||||||||||
return []; | return []; | |||||||||||||||||||
} | } | |||||||||||||||||||
} | } | |||||||||||||||||||
return targetPositions; | return targetPositions; | |||||||||||||||||||
}; | }; | |||||||||||||||||||
▲ Show 20 Lines • Show All 160 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, pushFront) | UnitAI.prototype.Stop = function(queued, pushFront) | |||||||||||||||||||
{ | { | |||||||||||||||||||
this.AddOrder("Stop", { "force": true }, queued, pushFront); | this.AddOrder("Stop", { "force": true }, queued, pushFront); | |||||||||||||||||||
}; | }; | |||||||||||||||||||
/** | /** | |||||||||||||||||||
* The unit will drop all resources at the closest dropsite. If this unit is no gatherer or | ||||||||||||||||||||
Done Inline Actions
Freagarach: | ||||||||||||||||||||
* no dropsite is available, it will do nothing. | ||||||||||||||||||||
*/ | ||||||||||||||||||||
UnitAI.prototype.DropAtNearestDropSite = function(queued, pushFront) | ||||||||||||||||||||
{ | ||||||||||||||||||||
this.AddOrder("DropAtNearestDropSite", { "force": true }, queued, pushFront); | ||||||||||||||||||||
Done Inline Actions
Freagarach: | ||||||||||||||||||||
}; | ||||||||||||||||||||
/** | ||||||||||||||||||||
Done Inline Actions
Freagarach: | ||||||||||||||||||||
* 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. | |||||||||||||||||||
Done Inline Actions
You can early return when no resource gatherer. Freagarach: You can early return when no resource gatherer. | ||||||||||||||||||||
*/ | */ | |||||||||||||||||||
UnitAI.prototype.WalkToTarget = function(target, queued, pushFront) | UnitAI.prototype.WalkToTarget = function(target, queued, pushFront) | |||||||||||||||||||
{ | { | |||||||||||||||||||
this.AddOrder("WalkToTarget", { "target": target, "force": true }, queued, pushFront); | this.AddOrder("WalkToTarget", { "target": target, "force": true }, queued, pushFront); | |||||||||||||||||||
Done Inline Actions
Freagarach: | ||||||||||||||||||||
}; | }; | |||||||||||||||||||
Done Inline Actions
(Same about early return.) Freagarach: (Same about early return.) | ||||||||||||||||||||
/** | /** | |||||||||||||||||||
* Adds walk-and-fight order to queue, this only occurs in response | * Adds walk-and-fight order to queue, this only occurs in response | |||||||||||||||||||
* to a player order, and so is forced. | * to a player order, and so is forced. | |||||||||||||||||||
* If targetClasses is given, only entities matching the targetClasses can be attacked. | * If targetClasses is given, only entities matching the targetClasses can be attacked. | |||||||||||||||||||
*/ | */ | |||||||||||||||||||
UnitAI.prototype.WalkAndFight = function(x, z, targetClasses, allowCapture = true, queued = false, pushFront = false) | UnitAI.prototype.WalkAndFight = function(x, z, targetClasses, allowCapture = true, queued = false, pushFront = false) | |||||||||||||||||||
{ | { | |||||||||||||||||||
this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "allowCapture": allowCapture, "force": true }, queued, pushFront); | this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "allowCapture": allowCapture, "force": true }, queued, pushFront); | |||||||||||||||||||
▲ Show 20 Lines • Show All 1,052 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Do notice this is a small change in behaviour. Entities tasked to return resources no longer clear the workOrders. I think that means one cannot get rid of that pesky command button easily anymore?