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>" + | ||||
"<element name='Controllable'>" + | |||||
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… | |||||
"<data type='boolean'/>" + | |||||
"</element>" + | |||||
"<optional>" + | "<optional>" + | ||||
"<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>" + | ||||
▲ Show 20 Lines • Show All 147 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. | ||||
StanUnsubmitted Done Inline Actionsmove maybe ? else walk everywhere (No biggie) Stan: move maybe ? else walk everywhere (No biggie) | |||||
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); | ||||
// It's not too bad if we don't arrive at exactly the right position. | // It's not too bad if we don't arrive at exactly the right position. | ||||
this.order.data.relaxed = true; | this.order.data.relaxed = true; | ||||
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. | ||||
Show All 9 Lines | "Order.WalkAndFight": function(msg) { | ||||
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 130 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,760 Lines • ▼ Show 20 Lines | |||||
UnitAI.prototype.Init = function() | UnitAI.prototype.Init = function() | ||||
{ | { | ||||
this.orderQueue = []; // current order is at the front of the list | this.orderQueue = []; // current order is at the front of the list | ||||
this.order = undefined; // always == this.orderQueue[0] | this.order = undefined; // always == this.orderQueue[0] | ||||
this.formationController = INVALID_ENTITY; // entity with IID_Formation that we belong to | this.formationController = INVALID_ENTITY; // entity with IID_Formation that we belong to | ||||
this.isGarrisoned = false; | this.isGarrisoned = false; | ||||
this.isIdle = false; | this.isIdle = false; | ||||
this.finishedOrder = false; // used to find if all formation members finished the order | this.finishedOrder = false; // used to find if all formation members finished the order | ||||
this.isControllable = this.template.Controllable == "true"; | |||||
this.heldPosition = undefined; | this.heldPosition = undefined; | ||||
// Queue of remembered works | // Queue of remembered works | ||||
this.workOrders = []; | this.workOrders = []; | ||||
this.isGuardOf = undefined; | this.isGuardOf = undefined; | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
UnitAI.prototype.IsWalking = function() | UnitAI.prototype.IsWalking = function() | ||||
{ | { | ||||
var state = this.GetCurrentState().split(".").pop(); | var state = this.GetCurrentState().split(".").pop(); | ||||
return (state == "WALKING"); | return (state == "WALKING"); | ||||
}; | }; | ||||
UnitAI.prototype.IsControllable = function() | |||||
{ | |||||
return this.isControllable; | |||||
}; | |||||
/** | |||||
* Set whether the entity is controllable. | |||||
* @param {boolean} bool - Q.e.d. | |||||
*/ | |||||
UnitAI.prototype.SetControllable = function(bool) | |||||
{ | |||||
this.isControllable = bool; | |||||
}; | |||||
/** | /** | ||||
* Return true if the current order is WalkAndFight or Patrol. | * Return true if the current order is WalkAndFight or Patrol. | ||||
*/ | */ | ||||
UnitAI.prototype.IsWalkingAndFighting = function() | UnitAI.prototype.IsWalkingAndFighting = function() | ||||
{ | { | ||||
if (this.IsFormationMember()) | if (this.IsFormationMember()) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 2,734 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/>