Ticket #3412: ships.diff

File ships.diff, 3.5 KB (added by smitec, 8 years ago)
  • binaries/data/mods/public/gui/session/unit_actions.js

    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 =  
    367367        {
    368368            if (!hasClass(entState, "Unit") || !targetState.garrisonHolder)
    369369                return false;
     370            if (!entState.unitAI || !entState.unitAI.canGarrison)
     371                return false;
    370372            if (!playerCheck(entState, targetState, ["Player", "Ally"]))
    371373                return false;
    372374            var tooltip = sprintf(translate("Current garrison: %(garrisoned)s/%(capacity)s"), {
    var g_EntityCommands =  
    749751     "garrison": {
    750752        "getInfo": function(entState)
    751753        {
    752             if (!entState.unitAI || entState.turretParent)
     754            if (!entState.unitAI || !entState.unitAI.canGarrison || entState.turretParent)
    753755                return false;
    754756            return {
    755757                "tooltip": translate("Garrison"),
  • binaries/data/mods/public/simulation/components/GuiInterface.js

    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)  
    351351            "orders": cmpUnitAI.GetOrders(),
    352352            "hasWorkOrders": cmpUnitAI.HasWorkOrders(),
    353353            "canGuard": cmpUnitAI.CanGuard(),
     354            "canGarrison": cmpUnitAI.CanGarrison(),
    354355            "isGuarding": cmpUnitAI.IsGuardOf(),
    355356            "possibleStances": cmpUnitAI.GetPossibleStances(),
    356357            "isIdle":cmpUnitAI.IsIdle(),
  • binaries/data/mods/public/simulation/components/UnitAI.js

    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)  
    56325632    if (this.IsFormationController())
    56335633        return true;
    56345634
    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    }
    56435646
    56445647    // Don't let animals garrison for now
    56455648    // (If we want to support that, we'll need to change Order.Garrison so it
    UnitAI.prototype.CanGarrison = function(target)  
    56475650    if (this.IsAnimal())
    56485651        return false;
    56495652
     5653    // Don't let ships garrison
     5654    var isShip = Engine.QueryInterface(this.entity, IID_Identity).HasClass("Ship");
     5655    if (isShip)
     5656        return false;
     5657
    56505658    return true;
    56515659};
    56525660