Ticket #2353: fix.2.patch

File fix.2.patch, 3.6 KB (added by Itms, 10 years ago)
  • binaries/data/mods/public/simulation/components/AlertRaiser.js

     
    3737    PlaySound(alertString, this.entity);
    3838};
    3939
    40 AlertRaiser.prototype.UpdateUnits = function()
     40AlertRaiser.prototype.UpdateUnits = function(units)
    4141{
    42     // Find units owned by this unit's player
    43     var players = [];
    44     var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
    45     if (cmpOwnership)
    46         players = [cmpOwnership.GetOwner()];
    47 
    48     // Select units to put under alert, ignoring domestic animals (NB : war dogs are not domestic)
    49     var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    50     var level = this.GetLevel();
    51     var units = rangeMan.ExecuteQuery(this.entity, 0, this.template.Range, players, IID_UnitAI).filter( function(e){
    52         var cmpUnitAI = Engine.QueryInterface(e, IID_UnitAI);
    53         return (!cmpUnitAI.IsUnderAlert() && cmpUnitAI.ReactsToAlert(level) && !cmpUnitAI.IsDomestic());
    54         });
    55    
    5642    for each (var unit in units)
    5743    {
    5844        var cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI);
     45        if(!cmpUnitAI)
     46            continue;
     47       
    5948        cmpUnitAI.ReplaceOrder("Alert", {"raiser": this.entity, "force": true});
    6049        this.walkingUnits.push(unit);
    6150    }
     
    6958    this.level++;
    7059    this.SoundAlert();
    7160
    72     // Find buildings owned by this unit's player
     61    // Find buildings / units owned by this unit's player
    7362    var players = [];
    7463    var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
    7564    if (cmpOwnership)
     
    8978        cmpProductionQueue.PutUnderAlert(this.entity);
    9079        this.prodBuildings.push(building);
    9180    }
     81
     82    // Select units to put under alert, ignoring domestic animals (NB : war dogs are not domestic)
     83    var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     84    var level = this.GetLevel();
     85    var units = rangeMan.ExecuteQuery(this.entity, 0, this.template.Range, players, IID_UnitAI).filter( function(e){
     86        var cmpUnitAI = Engine.QueryInterface(e, IID_UnitAI);
     87        return (!cmpUnitAI.IsUnderAlert() && cmpUnitAI.ReactsToAlert(level) && !cmpUnitAI.IsDomestic());
     88        });
    9289   
    93     // Put units under alert
    94     this.UpdateUnits();
     90    for each (var unit in units)
     91    {
     92        var cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI);
     93        cmpUnitAI.ReplaceOrder("Alert", {"raiser": this.entity, "force": true});
     94        this.walkingUnits.push(unit);
     95    }
    9596   
    9697    return true;
    9798};
     
    131132    {
    132133        var cmpGarrisonHolder = Engine.QueryInterface(slot.holder, IID_GarrisonHolder);
    133134        var cmpUnitAI = Engine.QueryInterface(slot.unit, IID_UnitAI);
    134         if (!cmpUnitAI || !cmpGarrisonHolder)
     135        if (!cmpUnitAI)
    135136            continue;
    136137       
    137         if(cmpGarrisonHolder && cmpGarrisonHolder.PerformEject([slot.unit], true))
     138        // If the garrison building was destroyed, the unit is already ejected
     139        if (!cmpGarrisonHolder || cmpGarrisonHolder.PerformEject([slot.unit], true))
    138140        {
    139141            cmpUnitAI.ResetAlert();             
    140142            if (cmpUnitAI.HasWorkOrders())
  • binaries/data/mods/public/simulation/components/ProductionQueue.js

     
    609609        {
    610610            var cmpAlertRaiser = Engine.QueryInterface(this.alertRaiser, IID_AlertRaiser);
    611611            if(cmpAlertRaiser)
    612                 cmpAlertRaiser.UpdateUnits();
     612                cmpAlertRaiser.UpdateUnits(createdEnts);
    613613        }
    614614    }
    615615