Ticket #252: t252_cleanupattack.diff

File t252_cleanupattack.diff, 3.2 KB (added by bb, 8 years ago)

Some quick trivial pre- cleanup

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

     
    218218
    219219Attack.prototype.GetPreferredClasses = function(type)
    220220{
    221     if (this.template[type] && this.template[type].PreferredClasses &&
    222         this.template[type].PreferredClasses._string)
    223     {
     221    if (this.template[type] && this.template[type].PreferredClasses && this.template[type].PreferredClasses._string)
    224222        return this.template[type].PreferredClasses._string.split(/\s+/);
    225     }
    226223    return [];
    227224};
    228225
    229226Attack.prototype.GetRestrictedClasses = function(type)
    230227{
    231     if (this.template[type] && this.template[type].RestrictedClasses &&
    232         this.template[type].RestrictedClasses._string)
    233     {
     228    if (this.template[type] && this.template[type].RestrictedClasses && this.template[type].RestrictedClasses._string)
    234229        return this.template[type].RestrictedClasses._string.split(/\s+/);
    235     }
    236230    return [];
    237231};
    238232
     
    281275            canAttack = false;
    282276            break;
    283277        }
    284         if (canAttack)
     278        if (canAttack == "true")
    285279            return true;
    286280    }
    287281
     
    327321        if (type == "Slaughter")
    328322            continue;
    329323        let range = this.GetRange(type);
    330         if (range.min < ret.min)
    331             ret.min = range.min;
    332         if (range.max > ret.max)
    333             ret.max = range.max;
     324        ret.min = Math.min(ret.min, Range.min)
     325        ret.max = Math.max(ret.max, Range.max)
    334326    }
    335327    return ret;
    336328};
     
    486478    let a = Math.random();
    487479    let b = Math.random();
    488480
    489     let c = Math.sqrt(-2*Math.log(a)) * Math.cos(2*Math.PI*b);
    490     let d = Math.sqrt(-2*Math.log(a)) * Math.sin(2*Math.PI*b);
     481    let c = Math.sqrt(-2 * Math.log(a)) * Math.cos(2 * Math.PI * b);
     482    let d = Math.sqrt(-2 * Math.log(a)) * Math.sin(2 * Math.PI * b);
    491483
    492484    return [c, d];
    493485};
     
    503495    if (type == "Ranged")
    504496    {
    505497        let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
    506         let turnLength = cmpTimer.GetLatestTurnLength()/1000;
     498        let turnLength = cmpTimer.GetLatestTurnLength() / 1000;
    507499        // In the future this could be extended:
    508500        //  * Obstacles like trees could reduce the probability of the target being hit
    509501        //  * Obstacles like walls should block projectiles entirely
     
    620612Attack.prototype.InterpolatedLocation = function(ent, lateness)
    621613{
    622614    let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
    623     let turnLength = cmpTimer.GetLatestTurnLength()/1000;
     615    let turnLength = cmpTimer.GetLatestTurnLength() / 1000;
    624616    let cmpTargetPosition = Engine.QueryInterface(ent, IID_Position);
    625617    if (!cmpTargetPosition || !cmpTargetPosition.IsInWorld()) // TODO: handle dead target properly
    626618        return undefined;
     
    658650        let d = Vector3D.sub(point, targetPosition);
    659651        d = Vector2D.from3D(d).rotate(-angle);
    660652
    661         return d.x < Math.abs(targetShape.width/2) && d.y < Math.abs(targetShape.depth/2);
     653        return d.x < Math.abs(targetShape.width / 2) && d.y < Math.abs(targetShape.depth / 2);
    662654    }
    663655};
    664656
     
    740732        return;
    741733
    742734    for (let type of this.GetAttackTypes())
    743         if (msg.valueNames.indexOf("Attack/"+type+"/MaxRange") !== -1)
     735        if (msg.valueNames.indexOf("Attack/" + type + "/MaxRange") !== -1)
    744736        {
    745737            cmpUnitAI.UpdateRangeQueries();
    746738            return;