Ticket #3481: visibleGarrison.diff

File visibleGarrison.diff, 5.8 KB (added by mimo, 9 years ago)
  • binaries/data/mods/public/simulation/components/GarrisonHolder.js

     
    224224 * Garrison a unit inside.
    225225 * Returns true if successful, false if not
    226226 * The timer for AutoHeal is started here
     227 * if vgpEntity is given, this visualGarrisonPoint will be used for the entity
    227228 */
    228 GarrisonHolder.prototype.Garrison = function(entity)
     229GarrisonHolder.prototype.Garrison = function(entity, vgpEntity)
    229230{
    230231    var cmpPosition = Engine.QueryInterface(entity, IID_Position);
    231232    if (!cmpPosition)
     
    234235    if (!this.PerformGarrison(entity))
    235236        return false;
    236237
    237     var visiblyGarrisoned = false;
    238     for (var vgp of this.visibleGarrisonPoints)
     238    let visibleGarrisonPoint = vgpEntity;
     239    if (!visibleGarrisonPoint)
    239240    {
    240         if (vgp.entity)
    241             continue;
    242         vgp.entity = entity;
    243         cmpPosition.SetTurretParent(this.entity, vgp.offset);
    244         visiblyGarrisoned = true;
    245         var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
     241        for (let vgp of this.visibleGarrisonPoints)
     242        {
     243            if (vgp.entity)
     244                continue;
     245            visibleGarrisonPoint = vgp;
     246            break;
     247        }
     248    }
     249
     250    if (visibleGarrisonPoint)
     251    {
     252        visibleGarrisonPoint.entity = entity;
     253        cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset);
     254        let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
    246255        if (cmpUnitAI)
    247256            cmpUnitAI.SetTurretStance();
    248         break;
    249257    }
    250     if (!visiblyGarrisoned)
     258    else
    251259        cmpPosition.MoveOutOfWorld();
     260
    252261    return true;
    253262};
    254263
     
    674683    var entityIndex = this.entities.indexOf(msg.entity);
    675684    if (entityIndex != -1)
    676685    {
     686        let vgpRenamed;
     687        for (let vgp of this.visibleGarrisonPoints)
     688        {
     689            if (vgp.entity != msg.entity)
     690                continue;
     691            vgpRenamed = vgp;
     692            break;
     693        }
    677694        this.Eject(msg.entity);
    678         this.Garrison(msg.newentity);
     695        this.Garrison(msg.newentity, vgpRenamed);
    679696    }
    680697
    681698    if (!this.initGarrison)
  • binaries/data/mods/public/simulation/components/Promotion.js

     
    8080
    8181    var orders = cmpCurrentUnitAI.GetOrders();
    8282    if (cmpCurrentUnitAI.IsGarrisoned())
    83     {
    84         if (orders.length > 0 && (orders[0].type == "Garrison" || orders[0].type == "Autogarrison"))
    85         {
    86             // Replace the garrison order by an autogarrison order,
    87             // as we are already garrisoned and do not need to do
    88             // any further checks (or else we should do them here).
    89             var garrisonHolder = orders[0].data.target;
    90             orders.shift();
    91             cmpPromotedUnitAI.Autogarrison(garrisonHolder);
    92         }
    93         else
    94             warn("Promoted garrisoned entity with empty order queue.");
    95     }
    96     else
    97         cmpPromotedUnitAI.Cheer();
    98 
     83        cmpPromotedUnitAI.isGarrisoned = true;
     84    if (cmpCurrentUnitPosition.IsInWorld()) // do not cheer if not visibly garrisoned
     85        cmpPromotedUnitAI.Cheer(); 
    9986    cmpPromotedUnitAI.AddOrders(orders);
    10087
    10188    var workOrders = cmpCurrentUnitAI.GetWorkOrders();
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    687687    "Order.Garrison": function(msg) {
    688688        if (this.IsTurret())
    689689        {
    690             this.FinishOrder();
     690            this.SetNextState("IDLE");
    691691            return;
    692692        }
     693        else if (this.IsGarrisoned())
     694        {
     695            this.SetNextState("INDIVIDUAL.AUTOGARRISON");
     696            return;
     697        }
     698
    693699        // For packable units:
    694700        // 1. If packed, we can move to the garrison target.
    695701        // 2. If unpacked, we first need to pack, then follow case 1.
     
    713719    },
    714720
    715721    "Order.Autogarrison": function(msg) {
     722        if (this.IsTurret())
     723        {
     724            this.SetNextState("IDLE");
     725            return;
     726        }
     727
    716728        this.SetNextState("INDIVIDUAL.AUTOGARRISON");
    717729    },
    718730
     
    14381450                // from FinishOrder (SetNextState("IDLE") is only executed when we get
    14391451                // a ProcessMessage), and thus we should not start an attack which could
    14401452                // put us in a weird state
    1441                 if (this.orderQueue.length > 0)
     1453                if (this.orderQueue.length > 0 && !this.IsGarrisoned())
    14421454                    return false;
    14431455
    14441456                // If a unit can heal and attack we first want to heal wounded units,
     
    15011513                    Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle });
    15021514                }
    15031515            },
     1516
     1517            "Order.Ungarrison": function() {    // Needed for turrets
     1518                this.FinishOrder();
     1519                this.isGarrisoned = false;
     1520            },
    15041521        },
    15051522
    15061523        "WALKING": {
     
    29182935                },
    29192936
    29202937                "Order.Ungarrison": function() {
    2921                     if (this.FinishOrder())
    2922                         return;
     2938                    this.FinishOrder();
     2939                    this.isGarrisoned = false;
    29232940                },
    29242941
    29252942                "leave": function() {
    2926                     this.isGarrisoned = false;
    29272943                }
    29282944            },
    29292945        },
     
    29352951            },
    29362952
    29372953            "Order.Ungarrison": function() {
    2938                 if (this.FinishOrder())
    2939                     return;
     2954                this.FinishOrder();
     2955                this.isGarrisoned = false;
    29402956            },
    29412957
    29422958            "leave": function() {
    2943                 this.isGarrisoned = false;
    29442959            }
    29452960        },
    29462961
     
    33183333{
    33193334    var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
    33203335    if (cmpOwnership && cmpOwnership.GetOwner() == msg.player)
    3321         this.SetupRangeQuery();
     3336        this.SetupRangeQueries();
    33223337};
    33233338
    33243339UnitAI.prototype.OnOwnershipChanged = function(msg)
     
    49764991UnitAI.prototype.Ungarrison = function()
    49774992{
    49784993    if (this.IsGarrisoned())
     4994    {
     4995        // Turret may be attacking, so we must finish all orders except the last one
     4996        // which must be Garrison or Autogarrison
     4997        while (this.orderQueue.length > 1)
     4998            this.FinishOrder();
    49794999        this.AddOrder("Ungarrison", null, false);
     5000    }
    49805001};
    49815002
    49825003/**