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..672388f 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.CanGarrison(), |
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..4a624ce 100644
a
|
b
|
UnitAI.prototype.CanGarrison = function(target)
|
5632 | 5632 | if (this.IsFormationController()) |
5633 | 5633 | return true; |
5634 | 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; |
| 5635 | // Because this checks if the unit can garrision at all, it may not have a target any more |
| 5636 | if (target) { |
| 5637 | var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder); |
| 5638 | if (!cmpGarrisonHolder) |
| 5639 | return false; |
| 5640 | |
| 5641 | // Verify that the target is owned by this entity's player or a mutual ally of this player |
| 5642 | var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); |
| 5643 | if (!cmpOwnership || !(IsOwnedByPlayer(cmpOwnership.GetOwner(), target) || IsOwnedByMutualAllyOfPlayer(cmpOwnership.GetOwner(), target))) |
| 5644 | return false; |
| 5645 | } |
5643 | 5646 | |
5644 | 5647 | // Don't let animals garrison for now |
5645 | 5648 | // (If we want to support that, we'll need to change Order.Garrison so it |
… |
… |
UnitAI.prototype.CanGarrison = function(target)
|
5647 | 5650 | if (this.IsAnimal()) |
5648 | 5651 | return false; |
5649 | 5652 | |
| 5653 | // Don't let ships garrison |
| 5654 | var isShip = Engine.QueryInterface(this.entity, IID_Identity).HasClass("Ship"); |
| 5655 | if (isShip) |
| 5656 | return false; |
| 5657 | |
5650 | 5658 | return true; |
5651 | 5659 | }; |
5652 | 5660 | |