Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 609 Lines • ▼ Show 20 Lines | UnitAI.prototype.UnitFsmSpec = { | ||||
"Order.Garrison": function(msg) { | "Order.Garrison": function(msg) { | ||||
if (this.IsTurret()) | if (this.IsTurret()) | ||||
{ | { | ||||
this.SetNextState("IDLE"); | this.SetNextState("IDLE"); | ||||
return; | return; | ||||
} | } | ||||
else if (this.IsGarrisoned()) | else if (this.IsGarrisoned()) | ||||
{ | { | ||||
this.SetNextState("INDIVIDUAL.GARRISON.GARRISONED"); | this.SetNextState("INDIVIDUAL.GARRISON.GARRISONED"); | ||||
Silier: missed | |||||
return; | return; | ||||
} | } | ||||
// For packable units: | // For packable units: | ||||
// 1. If packed, we can move to the garrison target. | // 1. If packed, we can move to the garrison target. | ||||
// 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; | ||||
} | } | ||||
if (this.IsAnimal()) | |||||
this.SetNextState("ANIMAL.GARRISON.APPROACHING"); | |||||
else | |||||
this.SetNextState("INDIVIDUAL.GARRISON.APPROACHING"); | this.SetNextState("INDIVIDUAL.GARRISON.APPROACHING"); | ||||
}, | }, | ||||
"Order.Ungarrison": function() { | "Order.Ungarrison": function() { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
this.isGarrisoned = false; | this.isGarrisoned = false; | ||||
}, | }, | ||||
"Order.Cheering": function(msg) { | "Order.Cheering": function(msg) { | ||||
▲ Show 20 Lines • Show All 2,240 Lines • ▼ Show 20 Lines | "GARRISON": { | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (msg.likelyFailure || msg.likelySuccess) | if (msg.likelyFailure || msg.likelySuccess) | ||||
{ | |||||
if (this.IsAnimal()) | |||||
SilierUnsubmitted Done Inline Actionsthis should not be needed, if animal, "ANIMAL.GARRISON." should be kept and not switched to "INDIVIDUAL.GARRISON" Silier: this should not be needed, if animal, "ANIMAL.GARRISON." should be kept and not switched to… | |||||
this.SetNextState("ANIMAL.GARRISON.GARRISONED"); | |||||
else | |||||
this.SetNextState("GARRISONED"); | this.SetNextState("GARRISONED"); | ||||
} | |||||
}, | }, | ||||
}, | }, | ||||
"GARRISONED": { | "GARRISONED": { | ||||
"enter": function() { | "enter": function() { | ||||
let target = this.order.data.target; | let target = this.order.data.target; | ||||
if (!target) | if (!target) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | "GARRISON": { | ||||
var cmpUnitAI = Engine.QueryInterface(this.pickup, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(this.pickup, IID_UnitAI); | ||||
if (!cmpUnitAI || !cmpUnitAI.HasPickupOrder(this.entity)) | if (!cmpUnitAI || !cmpUnitAI.HasPickupOrder(this.entity)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
this.SetNextState("APPROACHING"); | this.SetNextState("APPROACHING"); | ||||
Done Inline Actionscould you keep names of states consistant with units? thank you Silier: could you keep names of states consistant with units? thank you | |||||
return true; | return true; | ||||
} | } | ||||
// Garrisoning failed for some reason, so finish the order | // Garrisoning failed for some reason, so finish the order | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | "ANIMAL": { | ||||
}, | }, | ||||
"FLEEING": "INDIVIDUAL.FLEEING", // reuse the same fleeing behaviour for animals | "FLEEING": "INDIVIDUAL.FLEEING", // reuse the same fleeing behaviour for animals | ||||
"COMBAT": "INDIVIDUAL.COMBAT", // reuse the same combat behaviour for animals | "COMBAT": "INDIVIDUAL.COMBAT", // reuse the same combat behaviour for animals | ||||
"WALKING": "INDIVIDUAL.WALKING", // reuse the same walking behaviour for animals | "WALKING": "INDIVIDUAL.WALKING", // reuse the same walking behaviour for animals | ||||
// only used for domestic animals | // only used for domestic animals | ||||
"GARRISON": { | |||||
SilierUnsubmitted Done Inline ActionsYou need to reuse whole Garrison state, no just approaching and garrisoned Silier: You need to reuse whole Garrison state, no just approaching and garrisoned | |||||
// Reuse the same garrison behaviour for animals. | |||||
"APPROACHING": "INDIVIDUAL.GARRISON.APPROACHING", | |||||
Done Inline ActionsI should have changed comments... Freagarach: I should have changed comments... | |||||
"GARRISONED": "INDIVIDUAL.GARRISON.GARRISONED", | |||||
}, | |||||
}, | }, | ||||
}; | }; | ||||
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 | ||||
▲ Show 20 Lines • Show All 2,524 Lines • ▼ Show 20 Lines | |||||
UnitAI.prototype.CanGarrison = function(target) | UnitAI.prototype.CanGarrison = function(target) | ||||
{ | { | ||||
// Formation controllers should always respond to commands | // Formation controllers should always respond to commands | ||||
// (then the individual units can make up their own minds) | // (then the individual units can make up their own minds) | ||||
if (this.IsFormationController()) | if (this.IsFormationController()) | ||||
return true; | return true; | ||||
var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder); | let cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder); | ||||
if (!cmpGarrisonHolder) | if (!cmpGarrisonHolder) | ||||
return false; | return false; | ||||
// Verify that the target is owned by this entity's player or a mutual ally of this player | // Verify that the target is owned by this entity's player or a mutual ally of this player | ||||
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | ||||
if (!cmpOwnership || !(IsOwnedByPlayer(cmpOwnership.GetOwner(), target) || IsOwnedByMutualAllyOfPlayer(cmpOwnership.GetOwner(), target))) | if (!cmpOwnership || !(IsOwnedByPlayer(cmpOwnership.GetOwner(), target) || IsOwnedByMutualAllyOfPlayer(cmpOwnership.GetOwner(), target))) | ||||
return false; | return false; | ||||
// Don't let animals garrison for now | |||||
// (If we want to support that, we'll need to change Order.Garrison so it | |||||
// doesn't move the animal into an INVIDIDUAL.* state) | |||||
if (this.IsAnimal()) | |||||
return false; | |||||
return true; | return true; | ||||
}; | }; | ||||
UnitAI.prototype.CanGather = function(target) | UnitAI.prototype.CanGather = function(target) | ||||
{ | { | ||||
if (this.IsTurret()) | if (this.IsTurret()) | ||||
return false; | return false; | ||||
// The target must be a valid resource supply, or the mirage of one. | // The target must be a valid resource supply, or the mirage of one. | ||||
▲ Show 20 Lines • Show All 298 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
missed