Ticket #4102: 4102.diff

File 4102.diff, 7.0 KB (added by Stan, 8 years ago)

Proposal

  • binaries/data/mods/public/simulation/components/GarrisonHolder.js

     
    6666    this.visibleGarrisonPoints = [];
    6767    if (this.template.VisibleGarrisonPoints)
    6868    {
    69         for each (var offset in this.template.VisibleGarrisonPoints)
     69        for (let offset in this.template.VisibleGarrisonPoints)
    7070        {
    71             var o = {};
     71            let o = {};
    7272            o.x = +offset.X;
    7373            o.y = +offset.Y;
    7474            o.z = +offset.Z;
    75             this.visibleGarrisonPoints.push({"offset":o, "entity": null});
     75            this.visibleGarrisonPoints.push({ "offset": o, "entity": null });
    7676        }
    7777    }
    7878};
     
    163163 */
    164164GarrisonHolder.prototype.IsGarrisoningAllowed = function()
    165165{
    166     for each (var allow in this.allowGarrisoning)
    167     {
     166    for (let allow in this.allowGarrisoning)
    168167        if (!allow)
    169168            return false;
    170     }
     169
    171170    return true;
    172171};
    173172
     
    177176GarrisonHolder.prototype.GetGarrisonedEntitiesCount = function()
    178177{
    179178    var count = 0;
    180     for each (var ent in this.entities)
     179    for (let ent of this.entities)
    181180    {
    182         count++;
    183         var cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder);
     181        ++count;
     182        let cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder);
    184183        if (cmpGarrisonHolder)
    185184            count += cmpGarrisonHolder.GetGarrisonedEntitiesCount();
    186185    }
     
    305304    var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
    306305    // If the garrisonHolder is a sinking ship, restrict the location to the intersection of both passabilities
    307306    // TODO: should use passability classes to be more generic
    308     if ((!cmpHealth || cmpHealth.GetHitpoints() == 0) && cmpIdentity && cmpIdentity.HasClass("Ship"))
    309         var pos = cmpFootprint.PickSpawnPointBothPass(entity);
    310     else
    311         var pos = cmpFootprint.PickSpawnPoint(entity);
     307    var pos = (!cmpHealth || cmpHealth.GetHitpoints() === 0) && cmpIdentity && cmpIdentity.HasClass("Ship") ?
     308        cmpFootprint.PickSpawnPointBothPass(entity) :
     309        cmpFootprint.PickSpawnPoint(entity);
    312310
    313311    if (pos.y < 0)
    314312    {
     
    332330        if (vgp.entity != entity)
    333331            continue;
    334332        cmpNewPosition.SetTurretParent(INVALID_ENTITY, new Vector3D());
    335         var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
     333        let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
    336334        if (cmpUnitAI)
    337335            cmpUnitAI.ResetTurretStance();
    338336        vgp.entity = null;
     
    377375            // ignore the rally point if it is autogarrison
    378376            if (commands[0].type == "garrison" && commands[0].target == this.entity)
    379377                return;
    380             for each (var com in commands)
     378            for (let command of commands)
    381379            {
    382                 ProcessCommand(cmpOwnership.GetOwner(), com);
     380                ProcessCommand(cmpOwnership.GetOwner(), command);
    383381            }
    384382        }
    385383    }
     
    403401    {
    404402        if (failedRadius !== undefined)
    405403        {
    406             var cmpObstruction = Engine.QueryInterface(entity, IID_Obstruction);
    407             var radius = cmpObstruction ? cmpObstruction.GetUnitRadius() : 0;
     404            let cmpObstruction = Engine.QueryInterface(entity, IID_Obstruction);
     405            let radius = cmpObstruction ? cmpObstruction.GetUnitRadius() : 0;
    408406            if (radius >= failedRadius)
    409407                continue;
    410408        }
     
    411409
    412410        if (this.Eject(entity, forced))
    413411        {
    414             var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
    415             var cmpEntOwnership = Engine.QueryInterface(entity, IID_Ownership);
     412            let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
     413            let cmpEntOwnership = Engine.QueryInterface(entity, IID_Ownership);
    416414            if (cmpOwnership && cmpEntOwnership && cmpOwnership.GetOwner() == cmpEntOwnership.GetOwner())
    417415                ejectedEntities.push(entity);
    418416        }
     
    423421                failedRadius = Math.min(failedRadius, radius);
    424422            else
    425423            {
    426                 var cmpObstruction = Engine.QueryInterface(entity, IID_Obstruction);
     424                let cmpObstruction = Engine.QueryInterface(entity, IID_Obstruction);
    427425                failedRadius = cmpObstruction ? cmpObstruction.GetUnitRadius() : 0;
    428426            }
    429427        }
     
    463461
    464462    var entities = [];
    465463    var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
    466     for each (var entity in this.entities)
     464    for (let entity of this.entities)
    467465    {
    468466        var cmpIdentity = Engine.QueryInterface(entity, IID_Identity);
    469467
    470468        // Units with multiple ranks are grouped together.
    471         var name = cmpIdentity.GetSelectionGroupName()
    472                    || cmpTemplateManager.GetCurrentTemplateName(entity);
     469        var name = cmpIdentity.GetSelectionGroupName() || cmpTemplateManager.GetCurrentTemplateName(entity);
    473470
    474471        if (name != template)
    475472            continue;
     
    541538 */
    542539GarrisonHolder.prototype.HealTimeout = function(data)
    543540{
    544     if (this.entities.length == 0)
     541    var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
     542    if (this.entities.length)
    545543    {
    546         var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
    547544        cmpTimer.CancelTimer(this.timer);
    548545        this.timer = undefined;
    549546    }
    550547    else
    551548    {
    552         for each (var entity in this.entities)
     549        for (let entity of this.entities)
    553550        {
    554551            var cmpHealth = Engine.QueryInterface(entity, IID_Health);
    555552            if (cmpHealth)
     
    559556                    cmpHealth.Increase(this.GetHealRate());
    560557            }
    561558        }
    562         var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
     559        cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
    563560        this.timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {});
    564561    }
    565562};
     
    596593    if (this.entity == msg.entity)
    597594    {
    598595        var entities = [];
    599         for each (var entity in this.entities)
     596        for (let entity of this.entities)
    600597        {
    601598            if (msg.to == -1 || !IsOwnedByMutualAllyOfEntity(this.entity, entity))
    602599                entities.push(entity);
     
    612609    {
    613610        // If the entity is dead, remove it directly instead of ejecting the corpse
    614611        var cmpHealth = Engine.QueryInterface(msg.entity, IID_Health);
    615         if (cmpHealth && cmpHealth.GetHitpoints() == 0)
     612        if (cmpHealth && cmpHealth.GetHitpoints() === 0)
    616613        {
    617614            this.entities.splice(entityIndex, 1);
    618615            Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [], "removed": [msg.entity] });
     
    694691
    695692    // And destroy all remaining entities
    696693    var killedEntities = [];
    697     for each (var entity in entities)
     694    for (let entity of entities)
    698695    {
    699696        var entityIndex = this.entities.indexOf(entity);
    700697        if (entityIndex == -1)
     
    719716    var ejectableClasses = this.template.EjectClassesOnDestroy._string;
    720717    ejectableClasses = ejectableClasses ? ejectableClasses.split(/\s+/) : [];
    721718    var entityClasses = (Engine.QueryInterface(entity, IID_Identity)).GetClassesList();
    722     for each (var ejectableClass in ejectableClasses)
    723         if (entityClasses.indexOf(ejectableClass) != -1)
    724             return true;
    725 
     719    if (ejectableClasses.some(ejectableClass => entityClasses.indexOf(ejectableClass) != -1))
     720        return true;
    726721    return false;
    727722};