Ticket #4098: 4098.2.diff

File 4098.2.diff, 21.1 KB (added by Stan, 8 years ago)

Fix the above

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

     
    356356        // Check if we need to move     TODO implement a better way to know if we are on the shoreline
    357357        var needToMove = true;
    358358        var cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
    359         if (this.lastShorelinePosition && cmpPosition && (this.lastShorelinePosition.x == cmpPosition.GetPosition().x)
    360             && (this.lastShorelinePosition.z == cmpPosition.GetPosition().z))
     359        if (this.lastShorelinePosition && cmpPosition &&
     360            this.lastShorelinePosition.x == cmpPosition.GetPosition().x &&
     361            this.lastShorelinePosition.z == cmpPosition.GetPosition().z)
    361362        {
    362363            // we were already on the shoreline, and have not moved since
    363364            if (DistanceBetweenEntities(this.entity, this.order.data.target) < 50)
     
    13761377
    13771378        "GuardedAttacked": function(msg) {
    13781379            // do nothing if we have a forced order in queue before the guard order
    1379             for (var i = 0; i < this.orderQueue.length; ++i)
     1380            for (let i = 0; i < this.orderQueue.length; ++i)
    13801381            {
    13811382                if (this.orderQueue[i].type == "Guard")
    13821383                    break;
     
    18311832                    var animationName = "attack_" + this.order.data.attackType.toLowerCase();
    18321833                    if (this.IsFormationMember())
    18331834                    {
    1834                         var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation);
     1835                        let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation);
    18351836                        if (cmpFormation)
    18361837                            animationName = cmpFormation.GetFormationAnimation(this.entity, animationName);
    18371838                    }
     
    20542055
    20552056                        // Try to find another nearby target of the same specific type
    20562057                        // Also don't switch to a different type of huntable animal
    2057                         var nearby = this.FindNearbyResource(function (ent, type, template) {
    2058                             return (
    2059                                 ent != oldTarget
    2060                                  && ((type.generic == "treasure" && oldType.generic == "treasure")
    2061                                  || (type.specific == oldType.specific
    2062                                  && (type.specific != "meat" || oldTemplate == template)))
    2063                             );
    2064                         }, oldTarget);
     2058                        let nearby = this.FindNearbyResource((ent, type, template) =>
     2059                                ent != oldTarget &&
     2060                                (type.generic == "treasure" && oldType.generic == "treasure" ||
     2061                                (type.specific == oldType.specific &&
     2062                                (type.specific != "meat" || oldTemplate == template))),
     2063                                oldTarget);
    20652064                        if (nearby)
    20662065                        {
    20672066                            this.PerformGather(nearby, false, false);
     
    20822081                            else
    20832082                            {
    20842083                                // we're kind of stuck here. Return resource.
    2085                                 var nearby = this.FindNearestDropsite(oldType.generic);
     2084                                nearby = this.FindNearestDropsite(oldType.generic);
    20862085                                if (nearby)
    20872086                                {
    20882087                                    this.PushOrderFront("ReturnResource", { "target": nearby, "force": false });
     
    21192118
    21202119                        // Try to find another nearby target of the same specific type
    21212120                        // Also don't switch to a different type of huntable animal
    2122                         var nearby = this.FindNearbyResource(function (ent, type, template) {
    2123                             return (
    2124                                 ent != oldTarget
    2125                                 && ((type.generic == "treasure" && oldType.generic == "treasure")
    2126                                 || (type.specific == oldType.specific
    2127                                 && (type.specific != "meat" || oldTemplate == template)))
    2128                             );
    2129                         });
     2121                        let nearby = this.FindNearbyResource((ent, type, template) =>
     2122                            ent != oldTarget &&
     2123                            (type.generic == "treasure" && oldType.generic == "treasure" ||
     2124                            (type.specific == oldType.specific &&
     2125                            (type.specific != "meat" || oldTemplate == template))));
    21302126                        if (nearby)
    21312127                        {
    21322128                            this.PerformGather(nearby, false, false);
     
    21652161
    21662162                    // Try to find another nearby target of the same specific type
    21672163                    // Also don't switch to a different type of huntable animal
    2168                     var nearby = this.FindNearbyResource(function (ent, type, template) {
    2169                         return (
    2170                             (type.generic == "treasure" && resourceType.generic == "treasure")
    2171                             || (type.specific == resourceType.specific
    2172                             && (type.specific != "meat" || resourceTemplate == template))
    2173                         );
    2174                     });
     2164                    let nearby = this.FindNearbyResource((ent, type, template) =>
     2165                        (type.generic == "treasure" && resourceType.generic == "treasure") ||
     2166                        (type.specific == resourceType.specific &&
     2167                        (type.specific != "meat" || resourceTemplate == template)));
    21752168
    21762169                    // If there is a nearby resource start gathering
    21772170                    if (nearby)
     
    21852178                        return;
    21862179
    21872180                    // Nothing better to do: go back to dropsite
    2188                     var nearby = this.FindNearestDropsite(resourceType.generic);
     2181                    nearby = this.FindNearestDropsite(resourceType.generic);
    21892182                    if (nearby)
    21902183                    {
    21912184                        this.PushOrderFront("ReturnResource", { "target": nearby, "force": false });
     
    22882281                        if (this.CheckTargetRange(this.gatheringTarget, IID_ResourceGatherer) && this.CanGather(this.gatheringTarget))
    22892282                        {
    22902283                            // Gather the resources:
     2284                            let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
    22912285
    2292                             var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
    2293 
    22942286                            // Try to gather treasure
    22952287                            if (cmpResourceGatherer.TryInstantGather(this.gatheringTarget))
    22962288                                return;
     
    23072299                            // return to the nearest dropsite
    23082300                            if (status.filled)
    23092301                            {
    2310                                 var nearby = this.FindNearestDropsite(resourceType.generic);
     2302                                let nearby = this.FindNearestDropsite(resourceType.generic);
    23112303                                if (nearby)
    23122304                                {
    23132305                                    // (Keep this Gather order on the stack so we'll
     
    23572349
    23582350                    // Give up on this order and try our next queued order
    23592351                    // but first check what is our next order and, if needed, insert a returnResource order
    2360                     var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
     2352                    let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
    23612353                    if (cmpResourceGatherer.IsCarrying(resourceType.generic) &&
    23622354                        this.orderQueue.length > 1 && this.orderQueue[1] !== "ReturnResource" &&
    23632355                        (this.orderQueue[1].type !== "Gather" || this.orderQueue[1].data.type.generic !== resourceType.generic))
     
    23732365
    23742366                    // Try to find a new resource of the same specific type near our current position:
    23752367                    // Also don't switch to a different type of huntable animal
    2376                     var nearby = this.FindNearbyResource(function (ent, type, template) {
    2377                         return (
    2378                             (type.generic == "treasure" && resourceType.generic == "treasure")
    2379                             || (type.specific == resourceType.specific
    2380                             && (type.specific != "meat" || resourceTemplate == template))
    2381                         );
    2382                     });
     2368                    let nearby = this.FindNearbyResource((ent, type, template) =>
     2369                        (type.generic == "treasure" && resourceType.generic == "treasure") ||
     2370                        (type.specific == resourceType.specific &&
     2371                        (type.specific != "meat" || resourceTemplate == template)));
    23832372                    if (nearby)
    23842373                    {
    23852374                        this.PerformGather(nearby, false, false);
     
    23972386                    // drop it off, and if not then we might as well head to the dropsite
    23982387                    // anyway because that's a nice enough place to congregate and idle
    23992388
    2400                     var nearby = this.FindNearestDropsite(resourceType.generic);
     2389                    nearby = this.FindNearestDropsite(resourceType.generic);
    24012390                    if (nearby)
    24022391                    {
    24032392                        this.PushOrderFront("ReturnResource", { "target": nearby, "force": false });
     
    25652554                            // Dump any resources we can
    25662555                            var dropsiteTypes = cmpResourceDropsite.GetTypes();
    25672556
    2568                             var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
     2557                            let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
    25692558                            cmpResourceGatherer.CommitResources(dropsiteTypes);
    25702559
    25712560                            // Stop showing the carried resource animation.
     
    25812570                    // The dropsite was destroyed, or we couldn't reach it, or ownership changed
    25822571                    // Look for a new one.
    25832572
    2584                     var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
     2573                    let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
    25852574                    var genericType = cmpResourceGatherer.GetMainCarryingType();
    25862575                    var nearby = this.FindNearestDropsite(genericType);
    25872576                    if (nearby)
     
    27762765                // the build command should look for nearby resources to gather
    27772766                if ((oldData.force || oldData.autoharvest) && this.CanReturnResource(msg.data.newentity, false))
    27782767                {
    2779                     var cmpResourceDropsite = Engine.QueryInterface(msg.data.newentity, IID_ResourceDropsite);
    2780                     var types = cmpResourceDropsite.GetTypes();
     2768                    cmpResourceDropsite = Engine.QueryInterface(msg.data.newentity, IID_ResourceDropsite);
     2769                    let types = cmpResourceDropsite.GetTypes();
    27812770                    // TODO: Slightly undefined behavior here, we don't know what type of resource will be collected,
    27822771                    //   may cause problems for AIs (especially hunting fast animals), but avoid ugly hacks to fix that!
    2783                     var nearby = this.FindNearbyResource(function (ent, type, template) {
    2784                         return (types.indexOf(type.generic) != -1);
    2785                     });
     2772                    let nearby = this.FindNearbyResource((ent, type, template) => types.indexOf(type.generic) != -1);
    27862773                    if (nearby)
    27872774                    {
    27882775                        this.PerformGather(nearby, true, false);
     
    28612848            "GARRISONED": {
    28622849                "enter": function() {
    28632850                    // Target is not handled the same way with Alert and direct garrisoning
    2864                     if (this.order.data.target)
    2865                         var target = this.order.data.target;
    2866                     else
     2851                    let target = this.order.data.target;
     2852                    if (!target)
    28672853                    {
    28682854                        if (!this.alertGarrisoningTarget)
    28692855                        {
     
    28712857                            this.FinishOrder();
    28722858                            return true;
    28732859                        }
    2874                         var target = this.alertGarrisoningTarget;
     2860                        target = this.alertGarrisoningTarget;
    28752861                    }
    28762862
    28772863                    // Check that we can garrison here
     
    32433229
    32443230UnitAI.prototype.IsUnderAlert = function()
    32453231{
    3246     return this.alertRaiser != undefined;
     3232    return this.alertRaiser !== undefined;
    32473233};
    32483234
    32493235UnitAI.prototype.ResetAlert = function()
     
    33673353    {
    33683354        // Switch to a virgin state to let states execute their leave handlers.
    33693355        // except if garrisoned or cheering or (un)packing, in which case we only clear the order queue
    3370         if (this.isGarrisoned || (this.orderQueue[0] && (this.orderQueue[0].type == "Cheering"
    3371             || this.orderQueue[0].type == "Pack" || this.orderQueue[0].type == "Unpack")))
     3356        if (this.isGarrisoned || (this.orderQueue[0] && (this.orderQueue[0].type == "Cheering" ||
     3357            this.orderQueue[0].type == "Pack" || this.orderQueue[0].type == "Unpack")))
    33723358        {
    33733359            this.orderQueue.length = Math.min(this.orderQueue.length, 1);
    33743360            Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });
     
    34273413    {
    34283414        if (this.orderQueue[i].type != "PickupUnit" || this.orderQueue[i].data.target != msg.entity)
    34293415            continue;
    3430         if (i == 0)
     3416        if (i === 0)
    34313417            this.UnitFsm.ProcessMessage(this, {"type": "PickupCanceled", "data": msg});
    34323418        else
    34333419            this.orderQueue.splice(i, 1);
     
    37293715    // TODO: maybe a better way of doing this would be to use priority levels
    37303716    if (this.order && this.order.type == "Cheering")
    37313717    {
    3732         var order = { "type": type, "data": data };
     3718        let order = { "type": type, "data": data };
    37333719        var cheeringOrder = this.orderQueue.shift();
    37343720        this.orderQueue = [cheeringOrder, order];
    37353721    }
    37363722    else if (this.IsPacking() && type != "CancelPack" && type != "CancelUnpack")
    37373723    {
    3738         var order = { "type": type, "data": data };
     3724        let order = { "type": type, "data": data };
    37393725        var packingOrder = this.orderQueue.shift();
    37403726        this.orderQueue = [packingOrder, order];
    37413727    }
     
    37923778        var cmpUnitAI = Engine.QueryInterface(this.formationController, IID_UnitAI);
    37933779        if (cmpUnitAI)
    37943780        {
    3795             for (var i = 0; i < cmpUnitAI.orderQueue.length; ++i)
     3781            for (let i = 0; i < cmpUnitAI.orderQueue.length; ++i)
    37963782            {
    37973783                if (isWorkType(cmpUnitAI.orderQueue[i].type))
    37983784                {
     
    38043790    }
    38053791
    38063792    // If nothing found, take the unit orders
    3807     for (var i = 0; i < this.orderQueue.length; ++i)
     3793    for (let i = 0; i < this.orderQueue.length; ++i)
    38083794    {
    38093795        if (isWorkType(this.orderQueue[i].type))
    38103796        {
     
    38163802
    38173803UnitAI.prototype.BackToWork = function()
    38183804{
    3819     if (this.workOrders.length == 0)
     3805    if (!this.workOrders.length)
    38203806        return false;
    38213807
    38223808    // Clear the order queue considering special orders not to avoid
     
    39983984        return true;
    39993985
    40003986    var cmpHealth = QueryMiragedInterface(ent, IID_Health);
    4001     return cmpHealth && cmpHealth.GetHitpoints() != 0;
     3987    return cmpHealth && cmpHealth.GetHitpoints() !== 0;
    40023988};
    40033989
    40043990/**
     
    43364322    var t = targetCmpPosition.GetPosition();
    43374323    // h is positive when I'm higher than the target
    43384324    var h = s.y-t.y+range.elevationBonus;
    4339 
     4325    let parabolicMaxRange = 0;
    43404326    // No negative roots please
    4341     if (h>-range.max/2)
    4342         var parabolicMaxRange = Math.sqrt(range.max*range.max+2*range.max*h);
    4343     else
    4344         // return false? Or hope you come close enough?
    4345         var parabolicMaxRange = 0;
    4346         //return false;
     4327    if (h > -range.max / 2)
     4328        parabolicMaxRange = Math.sqrt(range.max * range.max + 2 * range.max * h);
    43474329
    43484330    // the parabole changes while walking, take something in the middle
    4349     var guessedMaxRange = (range.max + parabolicMaxRange)/2;
     4331    var guessedMaxRange = (range.max + parabolicMaxRange) / 2;
    43504332
    43514333    var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
    43524334    if (cmpUnitMotion.MoveToTargetRange(target, range.min, guessedMaxRange))
     
    44084390    if (this.IsFormationMember())
    44094391    {
    44104392        var cmpFormationUnitAI = Engine.QueryInterface(this.formationController, IID_UnitAI);
    4411         if (cmpFormationUnitAI && cmpFormationUnitAI.IsAttackingAsFormation()
    4412             && cmpFormationUnitAI.order.data.target == target)
     4393        if (cmpFormationUnitAI && cmpFormationUnitAI.IsAttackingAsFormation() && cmpFormationUnitAI.order.data.target == target)
    44134394            return true;
    44144395    }
    44154396
     
    45884569UnitAI.prototype.AttackEntityInZone = function(ents, forceResponse)
    45894570{
    45904571    var target = ents.find(target =>
    4591         this.CanAttack(target, forceResponse)
    4592         && this.CheckTargetDistanceFromHeldPosition(target, IID_Attack, this.GetBestAttackAgainst(target, true))
    4593         && (this.GetStance().respondChaseBeyondVision || this.CheckTargetIsInVisionRange(target))
     4572        this.CanAttack(target, forceResponse) &&
     4573        this.CheckTargetDistanceFromHeldPosition(target, IID_Attack, this.GetBestAttackAgainst(target, true)) &&
     4574        (this.GetStance().respondChaseBeyondVision || this.CheckTargetIsInVisionRange(target))
    45944575    );
    45954576    if (!target)
    45964577        return false;
     
    50985079
    50995080    // Remember the position of our target, if any, in case it disappears
    51005081    // later and we want to head to its last known position
    5101     var lastPos = undefined;
     5082    var lastPos;
    51025083    var cmpPosition = Engine.QueryInterface(target, IID_Position);
    51035084    if (cmpPosition && cmpPosition.IsInWorld())
    51045085        lastPos = cmpPosition.GetPosition();
     
    52255206
    52265207UnitAI.prototype.MoveToMarket = function(targetMarket)
    52275208{
    5228     if (this.waypoints && this.waypoints.length > 1)
    5229     {
    5230         var point = this.waypoints.pop();
    5231         var ok = this.MoveToPoint(point.x, point.z);
    5232         if (!ok)
    5233             ok = this.MoveToMarket(targetMarket);
    5234     }
    5235     else
    5236     {
    5237         this.waypoints = undefined;
    5238         var ok = this.MoveToTarget(targetMarket);
    5239     }
    5240 
    5241     return ok;
     5209    if (this.waypoints && this.waypoints.length > 1)
     5210    {
     5211        var point = this.waypoints.pop();
     5212        return this.MoveToPoint(point.x, point.z) || this.MoveToMarket(targetMarket);
     5213    }
     5214   
     5215    this.waypoints = undefined;
     5216    return this.MoveToTarget(targetMarket);
    52425217};
    52435218
    52445219UnitAI.prototype.PerformTradeAndMoveToNextMarket = function(currentMarket)
     
    54275402    {
    54285403        var cmpUnitAI;
    54295404        var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
    5430         for each (var ent in cmpFormation.members)
     5405        for (let ent of cmpFormation.members)
    54315406        {
    54325407            if (!(cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI)))
    54335408                continue;
    5434             var targets = cmpUnitAI.GetTargetsFromUnit();
    5435             for (var targ of targets)
     5409            let targets = cmpUnitAI.GetTargetsFromUnit();
     5410            for (let target of targets)
    54365411            {
    5437                 if (!cmpUnitAI.CanAttack(targ))
     5412                if (!cmpUnitAI.CanAttack(target))
    54385413                    continue;
    54395414                if (this.order.data.targetClasses)
    54405415                {
    5441                     var cmpIdentity = Engine.QueryInterface(targ, IID_Identity);
    5442                     var targetClasses = this.order.data.targetClasses;
    5443                     if (targetClasses.attack && cmpIdentity
    5444                         && !MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.attack))
     5416                    let cmpIdentity = Engine.QueryInterface(target, IID_Identity);
     5417                    let targetClasses = this.order.data.targetClasses;
     5418                    if (targetClasses.attack && cmpIdentity && !MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.attack))
    54455419                        continue;
    5446                     if (targetClasses.avoid && cmpIdentity
    5447                         && MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid))
     5420                    if (targetClasses.avoid && cmpIdentity && MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid))
    54485421                        continue;
    54495422                    // Only used by the AIs to prevent some choices of targets
    5450                     if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ])
     5423                    if (targetClasses.vetoEntities && targetClasses.vetoEntities[target])
    54515424                        continue;
    54525425                }
    5453                 this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": true });
     5426                this.PushOrderFront("Attack", { "target": target, "force": true, "allowCapture": true });
    54545427                return true;
    54555428            }
    54565429        }
     
    54585431    }
    54595432
    54605433    var targets = this.GetTargetsFromUnit();
    5461     for (var targ of targets)
     5434    for (let target of targets)
    54625435    {
    5463         if (!this.CanAttack(targ))
     5436        if (!this.CanAttack(target))
    54645437            continue;
    54655438        if (this.order.data.targetClasses)
    54665439        {
    5467             var cmpIdentity = Engine.QueryInterface(targ, IID_Identity);
    5468             var targetClasses = this.order.data.targetClasses;
    5469             if (cmpIdentity && targetClasses.attack
    5470                 && !MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.attack))
     5440            let cmpIdentity = Engine.QueryInterface(target, IID_Identity);
     5441            let targetClasses = this.order.data.targetClasses;
     5442            if (cmpIdentity && targetClasses.attack && !MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.attack))
    54715443                continue;
    5472             if (cmpIdentity && targetClasses.avoid
    5473                 && MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid))
     5444            if (cmpIdentity && targetClasses.avoid && MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid))
    54745445                continue;
    54755446            // Only used by the AIs to prevent some choices of targets
    5476             if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ])
     5447            if (targetClasses.vetoEntities && targetClasses.vetoEntities[target])
    54775448                continue;
    54785449        }
    5479         this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": true });
     5450        this.PushOrderFront("Attack", { "target": target, "force": true, "allowCapture": true });
    54805451        return true;
    54815452    }
    54825453
     
    55335504    var ret = { "min": 0, "max": 0 };
    55345505    if (this.GetStance().respondStandGround)
    55355506    {
    5536         var cmpRanged = Engine.QueryInterface(this.entity, iid);
     5507        let cmpRanged = Engine.QueryInterface(this.entity, iid);
    55375508        if (!cmpRanged)
    55385509            return ret;
    5539         var range = iid !== IID_Attack ? cmpRanged.GetRange() : cmpRanged.GetFullAttackRange();
     5510        let range = iid !== IID_Attack ? cmpRanged.GetRange() : cmpRanged.GetFullAttackRange();
    55405511        ret.min = range.min;
    55415512        ret.max = range.max;
    55425513    }
    55435514    else if (this.GetStance().respondChase)
    55445515    {
    5545         var cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
     5516        let cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
    55465517        if (!cmpVision)
    55475518            return ret;
    5548         var range = cmpVision.GetRange();
    5549         ret.max = range;
     5519        ret.max = cmpVision.GetRange();
    55505520    }
    55515521    else if (this.GetStance().respondHoldGround)
    55525522    {
    5553         var cmpRanged = Engine.QueryInterface(this.entity, iid);
     5523        let cmpRanged = Engine.QueryInterface(this.entity, iid);
    55545524        if (!cmpRanged)
    55555525            return ret;
    5556         var range = iid !== IID_Attack ? cmpRanged.GetRange() : cmpRanged.GetFullAttackRange();
    5557         var cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
     5526        let range = iid !== IID_Attack ? cmpRanged.GetRange() : cmpRanged.GetFullAttackRange();
     5527        let cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
    55585528        if (!cmpVision)
    55595529            return ret;
    55605530        var halfvision = cmpVision.GetRange() / 2;
     
    55645534    // but as it is the default for healers we need to set it to something sane.
    55655535    else if (iid === IID_Heal)
    55665536    {
    5567         var cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
     5537        let cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
    55685538        if (!cmpVision)
    55695539            return ret;
    5570         var range = cmpVision.GetRange();
    5571         ret.max = range;
     5540       
     5541        ret.max = cmpVision.GetRange();
    55725542    }
    55735543    return ret;
    55745544};
     
    58655835UnitAI.prototype.IsAttackingAsFormation = function()
    58665836{
    58675837    var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
    5868     return cmpAttack && cmpAttack.CanAttackAsFormation()
    5869         && this.GetCurrentState() == "FORMATIONCONTROLLER.COMBAT.ATTACKING";
     5838    return cmpAttack && cmpAttack.CanAttackAsFormation() && this.GetCurrentState() == "FORMATIONCONTROLLER.COMBAT.ATTACKING";
    58705839};
    58715840
    58725841//// Animal specific functions ////