diff --git a/binaries/data/mods/public/gui/session/unit_actions.js b/binaries/data/mods/public/gui/session/unit_actions.js
index 45cb732..21ea868 100644
a
|
b
|
var unitActions =
|
367 | 367 | { |
368 | 368 | if (!hasClass(entState, "Unit") || !targetState.garrisonHolder) |
369 | 369 | return false; |
| 370 | if (!entState.unitAI || !entState.unitAI.canGarrison) |
| 371 | return false; |
370 | 372 | if (!playerCheck(entState, targetState, ["Player", "Ally"])) |
371 | 373 | return false; |
372 | 374 | var tooltip = sprintf(translate("Current garrison: %(garrisoned)s/%(capacity)s"), { |
… |
… |
var g_EntityCommands =
|
749 | 751 | "garrison": { |
750 | 752 | "getInfo": function(entState) |
751 | 753 | { |
752 | | if (!entState.unitAI || entState.turretParent) |
| 754 | if (!entState.unitAI || !entState.unitAI.canGarrison || entState.turretParent) |
753 | 755 | return false; |
754 | 756 | return { |
755 | 757 | "tooltip": translate("Garrison"), |
diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js
index d55ffae..55eefa2 100644
a
|
b
|
GuiInterface.prototype.GetEntityState = function(player, ent)
|
351 | 351 | "orders": cmpUnitAI.GetOrders(), |
352 | 352 | "hasWorkOrders": cmpUnitAI.HasWorkOrders(), |
353 | 353 | "canGuard": cmpUnitAI.CanGuard(), |
| 354 | "canGarrison": cmpUnitAI.IsGarrisonable(), |
354 | 355 | "isGuarding": cmpUnitAI.IsGuardOf(), |
355 | 356 | "possibleStances": cmpUnitAI.GetPossibleStances(), |
356 | 357 | "isIdle":cmpUnitAI.IsIdle(), |
diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js
index 5d88429..5c4686e 100644
a
|
b
|
UnitAI.prototype.Schema =
|
24 | 24 | "<element name='CanGuard'>" + |
25 | 25 | "<data type='boolean'/>" + |
26 | 26 | "</element>" + |
| 27 | "<element name='CanGarrison'>" + |
| 28 | "<data type='boolean'/>" + |
| 29 | "</element>" + |
27 | 30 | "<optional>" + |
28 | 31 | "<interleave>" + |
29 | 32 | "<element name='NaturalBehaviour' a:help='Behaviour of the unit in the absence of player commands (intended for animals)'>" + |
… |
… |
UnitAI.prototype.CanAttack = function(target, forceResponse)
|
5625 | 5628 | return false; |
5626 | 5629 | }; |
5627 | 5630 | |
| 5631 | UnitAI.prototype.IsGarrisonable = function() { |
| 5632 | return (this.template.CanGarrison == "true"); |
| 5633 | } |
| 5634 | |
5628 | 5635 | UnitAI.prototype.CanGarrison = function(target) |
5629 | 5636 | { |
5630 | 5637 | // Formation controllers should always respond to commands |
5631 | 5638 | // (then the individual units can make up their own minds) |
5632 | 5639 | if (this.IsFormationController()) |
5633 | 5640 | return true; |
5634 | | |
5635 | | var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder); |
5636 | | if (!cmpGarrisonHolder) |
5637 | | return false; |
5638 | | |
5639 | | // Verify that the target is owned by this entity's player or a mutual ally of this player |
5640 | | var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); |
5641 | | if (!cmpOwnership || !(IsOwnedByPlayer(cmpOwnership.GetOwner(), target) || IsOwnedByMutualAllyOfPlayer(cmpOwnership.GetOwner(), target))) |
5642 | | return false; |
5643 | | |
5644 | | // Don't let animals garrison for now |
5645 | | // (If we want to support that, we'll need to change Order.Garrison so it |
5646 | | // doesn't move the animal into an INVIDIDUAL.* state) |
5647 | | if (this.IsAnimal()) |
5648 | | return false; |
| 5641 | |
| 5642 | // Check if the unit is able to Garrison based on their template |
| 5643 | if (!this.isGarrisonable()) |
| 5644 | return false; |
| 5645 | |
| 5646 | var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder); |
| 5647 | if (!cmpGarrisonHolder) |
| 5648 | return false; |
| 5649 | |
| 5650 | // Verify that the target is owned by this entity's player or a mutual ally of this player |
| 5651 | var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); |
| 5652 | if (!cmpOwnership || !(IsOwnedByPlayer(cmpOwnership.GetOwner(), target) || IsOwnedByMutualAllyOfPlayer(cmpOwnership.GetOwner(), target))) |
| 5653 | return false; |
5649 | 5654 | |
5650 | 5655 | return true; |
5651 | 5656 | }; |
diff --git a/binaries/data/mods/public/simulation/templates/template_formation.xml b/binaries/data/mods/public/simulation/templates/template_formation.xml
index c310825..655ecf8 100644
a
|
b
|
|
34 | 34 | <FleeDistance>12.0</FleeDistance> |
35 | 35 | <FormationController>true</FormationController> |
36 | 36 | <CanGuard>true</CanGuard> |
| 37 | <CanGarrison>true</CanGarrison> |
37 | 38 | </UnitAI> |
38 | 39 | <UnitMotion> |
39 | 40 | <FormationController>true</FormationController> |
diff --git a/binaries/data/mods/public/simulation/templates/template_unit.xml b/binaries/data/mods/public/simulation/templates/template_unit.xml
index 3654f4b..23d8d58 100644
a
|
b
|
|
101 | 101 | <FleeDistance>12.0</FleeDistance> |
102 | 102 | <FormationController>false</FormationController> |
103 | 103 | <CanGuard>true</CanGuard> |
| 104 | <CanGarrison>true</CanGarrison> |
104 | 105 | </UnitAI> |
105 | 106 | <Guard/> |
106 | 107 | <UnitMotion> |
diff --git a/binaries/data/mods/public/simulation/templates/template_unit_fauna.xml b/binaries/data/mods/public/simulation/templates/template_unit_fauna.xml
index b15d93a..873cc64 100644
a
|
b
|
|
28 | 28 | <RoamTimeMax>8000</RoamTimeMax> |
29 | 29 | <FeedTimeMin>15000</FeedTimeMin> |
30 | 30 | <FeedTimeMax>60000</FeedTimeMax> |
| 31 | <CanGarrison>false</CanGarrison> |
31 | 32 | </UnitAI> |
32 | 33 | <Guard disable=""/> |
33 | 34 | <UnitMotion> |
diff --git a/binaries/data/mods/public/simulation/templates/template_unit_fauna_decorative.xml b/binaries/data/mods/public/simulation/templates/template_unit_fauna_decorative.xml
index 9ede543..ecd13dd 100644
a
|
b
|
|
31 | 31 | <RoamTimeMax>100000</RoamTimeMax> |
32 | 32 | <FeedTimeMin>1</FeedTimeMin> |
33 | 33 | <FeedTimeMax>2</FeedTimeMax> |
| 34 | <CanGarrison>false</CanGarrison> |
34 | 35 | </UnitAI> |
35 | 36 | <UnitMotion> |
36 | 37 | <FormationController>false</FormationController> |
diff --git a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship.xml b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship.xml
index 32379af..7c61cd1 100644
a
|
b
|
|
70 | 70 | <Vision> |
71 | 71 | <Range>90</Range> |
72 | 72 | </Vision> |
| 73 | <UnitAI> |
| 74 | <CanGarrison>false</CanGarrison> |
| 75 | </UnitAI> |
73 | 76 | </Entity> |