Ticket #4291: unitAI_isGarrisoned_v2.patch

File unitAI_isGarrisoned_v2.patch, 5.9 KB (added by elexis, 8 years ago)

Seems to fix the issue. Saves the correct garrison holder ID in GarrisonHolder.PerformGarrison to UnitAI.isGarrisoned.

  • 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.PerformGarrison  
    251251
    252252    // Check if the unit is allowed to be garrisoned inside the building
    253253    if(!this.AllowedToGarrison(entity))
    254254        return false;
    255255
    256     // check the capacity
     256    // Check the capacity
    257257    var extraCount = 0;
    258258    var cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder);
    259259    if (cmpGarrisonHolder)
    260260        extraCount += cmpGarrisonHolder.GetGarrisonedEntitiesCount();
    261261    if (this.GetGarrisonedEntitiesCount() + extraCount >= this.GetCapacity())
    GarrisonHolder.prototype.PerformGarrison  
    276276
    277277    var cmpAura = Engine.QueryInterface(entity, IID_Auras);
    278278    if (cmpAura && cmpAura.HasGarrisonAura())
    279279        cmpAura.ApplyGarrisonBonus(this.entity);
    280280
     281    // Let entities recall their garrison holder
     282    var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
     283    if (cmpUnitAI)
     284        cmpUnitAI.SetGarrisoned(this.entity);
     285
    281286    Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [entity], "removed": [] });
    282287
    283     var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
    284288    if (cmpUnitAI && cmpUnitAI.IsUnderAlert())
    285289        Engine.PostMessage(cmpUnitAI.GetAlertRaiser(), MT_UnitGarrisonedAfterAlert, {"holder": this.entity, "unit": entity});
    286290
    287291    return true;
    288292};
    GarrisonHolder.prototype.OnGlobalInitGam  
    735739        return;
    736740
    737741    for (let ent of this.initGarrison)
    738742    {
    739743        let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
    740         if (cmpUnitAI && cmpUnitAI.CanGarrison(this.entity) && this.Garrison(ent))
    741             cmpUnitAI.SetGarrisoned();
     744        if (cmpUnitAI && cmpUnitAI.CanGarrison(this.entity))
     745            this.Garrison(ent);
    742746    }
    743747    this.initGarrison = undefined;
    744748};
    745749
    746750Engine.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 = {  
    29972997                        {
    29982998                            var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder);
    29992999                            // Check that garrisoning succeeds
    30003000                            if (cmpGarrisonHolder.Garrison(this.entity))
    30013001                            {
    3002                                 this.isGarrisoned = true;
    3003 
    30043002                                if (this.formationController)
    30053003                                {
    30063004                                    var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation);
    30073005                                    if (cmpFormation)
    30083006                                    {
    UnitAI.prototype.UnitFsmSpec = {  
    30783076            },
    30793077        },
    30803078
    30813079        "AUTOGARRISON": {
    30823080            "enter": function() {
    3083                 this.isGarrisoned = true;
    30843081                return false;
    30853082            },
    30863083
    30873084            "leave": function() {
    30883085            }
    UnitAI.prototype.IsIdle = function()  
    34223419UnitAI.prototype.IsGarrisoned = function()
    34233420{
    34243421    return this.isGarrisoned;
    34253422};
    34263423
    3427 UnitAI.prototype.SetGarrisoned = function()
     3424UnitAI.prototype.SetGarrisoned = function(target)
    34283425{
    3429     this.isGarrisoned = true;
     3426    this.isGarrisoned = target;
    34303427};
    34313428
    34323429UnitAI.prototype.IsFleeing = function()
    34333430{
    34343431    var state = this.GetCurrentState().split(".").pop();