Ticket #4291: unitAI_isGarrisoned_broken_v1.patch

File unitAI_isGarrisoned_broken_v1.patch, 5.3 KB (added by elexis, 8 years ago)

Saving the garrison holder entity ID in UnitAI.isGarrisoned this way doesn't affect the outcome at all, it still saves the wrong ID.

  • binaries/data/mods/public/gui/session/utility_functions.js

    function getTradingTooltip(gain)  
    110110 * Returns the entity itself except when garrisoned where it returns its garrisonHolder
    111111 */
    112112function getEntityOrHolder(ent)
    113113{
    114114    var entState = GetEntityState(ent);
    115     if (entState && !entState.position && entState.unitAI && entState.unitAI.orders.length &&
    116             (entState.unitAI.orders[0].type == "Garrison" || entState.unitAI.orders[0].type == "Autogarrison"))
    117         return entState.unitAI.orders[0].data.target;
     115    if (entState && !entState.position && entState.unitAI)
     116        return entState.unitAI.isGarrisoned;
    118117
    119118    return ent;
    120119}
    121120
    122121/**
  • binaries/data/mods/public/simulation/components/GarrisonHolder.js

    GarrisonHolder.prototype.OnGlobalInitGam  
    736736
    737737    for (let ent of this.initGarrison)
    738738    {
    739739        let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
    740740        if (cmpUnitAI && cmpUnitAI.CanGarrison(this.entity) && this.Garrison(ent))
    741             cmpUnitAI.SetGarrisoned();
     741            cmpUnitAI.SetGarrisoned(this.entity);
    742742    }
    743743    this.initGarrison = undefined;
    744744};
    745745
    746746Engine.RegisterComponentType(IID_GarrisonHolder, "GarrisonHolder", GarrisonHolder);
  • binaries/data/mods/public/simulation/components/GuiInterface.js

    GuiInterface.prototype.GetEntityState =  
    372372            "hasWorkOrders": cmpUnitAI.HasWorkOrders(),
    373373            "canGuard": cmpUnitAI.CanGuard(),
    374374            "isGuarding": cmpUnitAI.IsGuardOf(),
    375375            "possibleStances": cmpUnitAI.GetPossibleStances(),
    376376            "isIdle":cmpUnitAI.IsIdle(),
     377            "isGarrisoned": cmpUnitAI.IsGarrisoned()
    377378        };
    378379        // Add some information needed for ungarrisoning
    379380        if (cmpUnitAI.IsGarrisoned() && ret.player !== undefined)
    380381            ret.template = "p" + ret.player + "&" + ret.template;
    381382    }
  • binaries/data/mods/public/simulation/components/Promotion.js

    Promotion.prototype.Promote = function(p  
    8181        cmpPromotedUnitAI.SetHeldPosition(pos.x, pos.z);
    8282    if (cmpCurrentUnitAI.GetStanceName())
    8383        cmpPromotedUnitAI.SwitchToStance(cmpCurrentUnitAI.GetStanceName());
    8484
    8585    var orders = cmpCurrentUnitAI.GetOrders();
    86     if (cmpCurrentUnitAI.IsGarrisoned())
    87         cmpPromotedUnitAI.SetGarrisoned();
     86    cmpPromotedUnitAI.SetGarrisoned(cmpCurrentUnitAI.IsGarrisoned());
     87
    8888    if (cmpCurrentUnitPosition.IsInWorld()) // do not cheer if not visibly garrisoned
    8989        cmpPromotedUnitAI.Cheer(); 
    9090    cmpPromotedUnitAI.AddOrders(orders);
    9191
    9292    var workOrders = cmpCurrentUnitAI.GetWorkOrders();
  • binaries/data/mods/public/simulation/components/UnitAI.js

    UnitAI.prototype.UnitFsmSpec = {  
    708708            this.SetNextState("IDLE");
    709709            return;
    710710        }
    711711        else if (this.IsGarrisoned())
    712712        {
     713            // TODO: when is this called?
     714            this.isGarrisoned = msg.data.target;
    713715            this.SetNextState("INDIVIDUAL.AUTOGARRISON");
    714716            return;
    715717        }
    716718
    717719        // For packable units:
    UnitAI.prototype.UnitFsmSpec = {  
    741743        {
    742744            this.SetNextState("IDLE");
    743745            return;
    744746        }
    745747
     748        // TODO: when is this called?
     749        this.isGarrisoned = msg.data.target;
     750
    746751        this.SetNextState("INDIVIDUAL.AUTOGARRISON");
    747752    },
    748753
    749754    "Order.Ungarrison": function() {
    750755        this.FinishOrder();
    UnitAI.prototype.UnitFsmSpec = {  
    29973002                        {
    29983003                            var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder);
    29993004                            // Check that garrisoning succeeds
    30003005                            if (cmpGarrisonHolder.Garrison(this.entity))
    30013006                            {
    3002                                 this.isGarrisoned = true;
     3007                                this.isGarrisoned = target;
    30033008
    30043009                                if (this.formationController)
    30053010                                {
    30063011                                    var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation);
    30073012                                    if (cmpFormation)
    UnitAI.prototype.UnitFsmSpec = {  
    30783083            },
    30793084        },
    30803085
    30813086        "AUTOGARRISON": {
    30823087            "enter": function() {
    3083                 this.isGarrisoned = true;
    30843088                return false;
    30853089            },
    30863090
    30873091            "leave": function() {
    30883092            }
    UnitAI.prototype.IsIdle = function()  
    34223426UnitAI.prototype.IsGarrisoned = function()
    34233427{
    34243428    return this.isGarrisoned;
    34253429};
    34263430
    3427 UnitAI.prototype.SetGarrisoned = function()
     3431UnitAI.prototype.SetGarrisoned = function(target)
    34283432{
    3429     this.isGarrisoned = true;
     3433    this.isGarrisoned = target;
    34303434};
    34313435
    34323436UnitAI.prototype.IsFleeing = function()
    34333437{
    34343438    var state = this.GetCurrentState().split(".").pop();