Changeset View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show All 18 Lines | "<element name='FleeDistance'>" + | ||||
"<ref name='positiveDecimal'/>" + | "<ref name='positiveDecimal'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='CanGuard'>" + | "<element name='CanGuard'>" + | ||||
"<data type='boolean'/>" + | "<data type='boolean'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='CanPatrol'>" + | "<element name='CanPatrol'>" + | ||||
"<data type='boolean'/>" + | "<data type='boolean'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<optional>" + | "<optional>" + | ||||
Stan: It's consistent with the rest but it could be nice to make it a lone tag instead of a true… | |||||
Done Inline ActionsBut we want to be able to change it in simulation. (E.g. demoralised units.) Freagarach: But we want to be able to change it in simulation. (E.g. demoralised units.) | |||||
Done Inline ActionsCan't you delete the key in that case ? Stan: Can't you delete the key in that case ? | |||||
Done Inline ActionsIt can be a lone tag (I like tags), but I remember that a boolean is preferred. Freagarach: It can be a lone tag (I like tags), but I remember that a boolean is preferred. | |||||
Done Inline ActionsIIRC @wraitii likes tags too. Actually the boolean could be a tristate yes no not present ^^ Maybe it should be in coding conventions Stan: IIRC @wraitii likes tags too.
Actually the boolean could be a tristate yes no not present ^^… | |||||
Done Inline ActionsTemplate structure and the actual variable state are de-correlated. TBH I do like better the <controllable/> or <uncontrollable/> over the boolean, since it's much shorter. But to delete it one has to do <controllable disable=""/> which is a bit odd... So maybe we should go with boolean arguments all the time. wraitii: Template structure and the actual variable state are de-correlated.
TBH I do like better the… | |||||
"<interleave>" + | "<interleave>" + | ||||
"<element name='NaturalBehaviour' a:help='Behaviour of the unit in the absence of player commands (intended for animals)'>" + | "<element name='NaturalBehaviour' a:help='Behaviour of the unit in the absence of player commands (intended for animals)'>" + | ||||
"<choice>" + | "<choice>" + | ||||
"<value a:help='Will actively attack any unit it encounters, even if not threatened'>violent</value>" + | "<value a:help='Will actively attack any unit it encounters, even if not threatened'>violent</value>" + | ||||
"<value a:help='Will attack nearby units if it feels threatened (if they linger within LOS for too long)'>aggressive</value>" + | "<value a:help='Will attack nearby units if it feels threatened (if they linger within LOS for too long)'>aggressive</value>" + | ||||
"<value a:help='Will attack nearby units if attacked'>defensive</value>" + | "<value a:help='Will attack nearby units if attacked'>defensive</value>" + | ||||
"<value a:help='Will never attack units but will attempt to flee when attacked'>passive</value>" + | "<value a:help='Will never attack units but will attempt to flee when attacked'>passive</value>" + | ||||
"<value a:help='Will never attack units. Will typically attempt to flee for short distances when units approach'>skittish</value>" + | "<value a:help='Will never attack units. Will typically attempt to flee for short distances when units approach'>skittish</value>" + | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | UnitAI.prototype.UnitFsmSpec = { | ||||
// Formation handlers: | // Formation handlers: | ||||
"FormationLeave": function(msg) { | "FormationLeave": function(msg) { | ||||
// ignore when we're not in FORMATIONMEMBER | // ignore when we're not in FORMATIONMEMBER | ||||
}, | }, | ||||
// Called when being told to walk as part of a formation | // Called when being told to walk as part of a formation | ||||
"Order.FormationWalk": function(msg) { | "Order.FormationWalk": function(msg) { | ||||
// Let players move captured domestic animals around | // Turrets can't move around. | ||||
if (this.IsAnimal() && !this.IsDomestic() || this.IsTurret()) | if (this.IsTurret()) | ||||
Done Inline ActionscmpUnitAI.IsDomestic looks like unused after this patch bb: cmpUnitAI.IsDomestic looks like unused after this patch | |||||
Done Inline ActionsEven more accurately 'turrets can't be ordered to walk' wraitii: Even more accurately 'turrets can't be ordered to walk' | |||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
// For packable units: | // For packable units: | ||||
// 1. If packed, we can move. | // 1. If packed, we can move. | ||||
// 2. If unpacked, we first need to pack, then follow case 1. | // 2. If unpacked, we first need to pack, then follow case 1. | ||||
Show All 29 Lines | else | ||||
this.SetNextState("INDIVIDUAL.WALKING"); | this.SetNextState("INDIVIDUAL.WALKING"); | ||||
} | } | ||||
}, | }, | ||||
// Individual orders: | // Individual orders: | ||||
// (these will switch the unit out of formation mode) | // (these will switch the unit out of formation mode) | ||||
"Order.Stop": function(msg) { | "Order.Stop": function(msg) { | ||||
// We have no control over non-domestic animals. | |||||
if (this.IsAnimal() && !this.IsDomestic()) | |||||
Done Inline ActionsWe don't need to check anymore? Stan: We don't need to check anymore? | |||||
Done Inline ActionsNope, since orders are caught higher up in the chain now. Freagarach: Nope, since orders are caught higher up in the chain now. | |||||
Done Inline ActionsIt's arguably the "feature" here, making it possible for triggers to give animals orders. wraitii: It's arguably the "feature" here, making it possible for triggers to give animals orders. | |||||
{ | |||||
this.FinishOrder(); | |||||
return; | |||||
} | |||||
// Stop moving immediately. | // Stop moving immediately. | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
// No orders left, we're an individual now | // No orders left, we're an individual now | ||||
if (this.IsAnimal()) | if (this.IsAnimal()) | ||||
this.SetNextState("ANIMAL.IDLE"); | this.SetNextState("ANIMAL.IDLE"); | ||||
else | else | ||||
this.SetNextState("INDIVIDUAL.IDLE"); | this.SetNextState("INDIVIDUAL.IDLE"); | ||||
}, | }, | ||||
"Order.Walk": function(msg) { | "Order.Walk": function(msg) { | ||||
// Let players move captured domestic animals around | // Turrets can't walk. | ||||
if (this.IsAnimal() && !this.IsDomestic() || this.IsTurret()) | if (this.IsTurret()) | ||||
Done Inline Actionsmove maybe ? else walk everywhere (No biggie) Stan: move maybe ? else walk everywhere (No biggie) | |||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
// For packable units: | // For packable units: | ||||
// 1. If packed, we can move. | // 1. If packed, we can move. | ||||
// 2. If unpacked, we first need to pack, then follow case 1. | // 2. If unpacked, we first need to pack, then follow case 1. | ||||
if (this.CanPack()) | if (this.CanPack()) | ||||
{ | { | ||||
this.PushOrderFront("Pack", { "force": true }); | this.PushOrderFront("Pack", { "force": true }); | ||||
return; | return; | ||||
} | } | ||||
this.SetHeldPosition(this.order.data.x, this.order.data.z); | this.SetHeldPosition(this.order.data.x, this.order.data.z); | ||||
if (this.IsAnimal()) | if (this.IsAnimal()) | ||||
this.SetNextState("ANIMAL.WALKING"); | this.SetNextState("ANIMAL.WALKING"); | ||||
else | else | ||||
this.SetNextState("INDIVIDUAL.WALKING"); | this.SetNextState("INDIVIDUAL.WALKING"); | ||||
}, | }, | ||||
"Order.WalkAndFight": function(msg) { | "Order.WalkAndFight": function(msg) { | ||||
// Let players move captured domestic animals around | // Turrets can't move. | ||||
if (this.IsAnimal() && !this.IsDomestic() || this.IsTurret()) | if (this.IsTurret()) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
// For packable units: | // For packable units: | ||||
// 1. If packed, we can move. | // 1. If packed, we can move. | ||||
// 2. If unpacked, we first need to pack, then follow case 1. | // 2. If unpacked, we first need to pack, then follow case 1. | ||||
if (this.CanPack()) | if (this.CanPack()) | ||||
{ | { | ||||
this.PushOrderFront("Pack", { "force": true }); | this.PushOrderFront("Pack", { "force": true }); | ||||
return; | return; | ||||
} | } | ||||
this.SetHeldPosition(this.order.data.x, this.order.data.z); | this.SetHeldPosition(this.order.data.x, this.order.data.z); | ||||
if (this.IsAnimal()) | if (this.IsAnimal()) | ||||
this.SetNextState("ANIMAL.WALKING"); // WalkAndFight not applicable for animals | this.SetNextState("ANIMAL.WALKING"); // WalkAndFight not applicable for animals | ||||
else | else | ||||
this.SetNextState("INDIVIDUAL.WALKINGANDFIGHTING"); | this.SetNextState("INDIVIDUAL.WALKINGANDFIGHTING"); | ||||
}, | }, | ||||
"Order.WalkToTarget": function(msg) { | "Order.WalkToTarget": function(msg) { | ||||
// Let players move captured domestic animals around | // Turrets can't move. | ||||
if (this.IsAnimal() && !this.IsDomestic() || this.IsTurret()) | if (this.IsTurret()) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
// For packable units: | // For packable units: | ||||
// 1. If packed, we can move. | // 1. If packed, we can move. | ||||
// 2. If unpacked, we first need to pack, then follow case 1. | // 2. If unpacked, we first need to pack, then follow case 1. | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | "Order.Attack": function(msg) { | ||||
if (this.IsAnimal()) | if (this.IsAnimal()) | ||||
this.SetNextState("ANIMAL.COMBAT.APPROACHING"); | this.SetNextState("ANIMAL.COMBAT.APPROACHING"); | ||||
else | else | ||||
this.SetNextState("INDIVIDUAL.COMBAT.APPROACHING"); | this.SetNextState("INDIVIDUAL.COMBAT.APPROACHING"); | ||||
}, | }, | ||||
"Order.Patrol": function(msg) { | "Order.Patrol": function(msg) { | ||||
if (this.IsAnimal() || this.IsTurret()) | if (this.IsTurret()) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
if (this.CanPack()) | if (this.CanPack()) | ||||
{ | { | ||||
this.PushOrderFront("Pack", { "force": true }); | this.PushOrderFront("Pack", { "force": true }); | ||||
▲ Show 20 Lines • Show All 2,681 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
UnitAI.prototype.IsDomestic = function() | UnitAI.prototype.IsDomestic = function() | ||||
{ | { | ||||
var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | ||||
return cmpIdentity && cmpIdentity.HasClass("Domestic"); | return cmpIdentity && cmpIdentity.HasClass("Domestic"); | ||||
}; | }; | ||||
UnitAI.prototype.IsUncontrollable = function() | |||||
{ | |||||
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | |||||
return cmpIdentity && cmpIdentity.HasClass("Uncontrollable"); | |||||
}; | |||||
UnitAI.prototype.IsHealer = function() | UnitAI.prototype.IsHealer = function() | ||||
{ | { | ||||
return Engine.QueryInterface(this.entity, IID_Heal); | return Engine.QueryInterface(this.entity, IID_Heal); | ||||
}; | }; | ||||
UnitAI.prototype.IsIdle = function() | UnitAI.prototype.IsIdle = function() | ||||
{ | { | ||||
return this.isIdle; | return this.isIdle; | ||||
▲ Show 20 Lines • Show All 2,725 Lines • Show Last 20 Lines |
It's consistent with the rest but it could be nice to make it a lone tag instead of a true false string
<controllable/>