Ticket #2093: distance_spread.diff

File distance_spread.diff, 2.2 KB (added by sanderd17, 11 years ago)
  • binaries/data/mods/public/simulation/components/Attack.js

     
    138138                "<element name='ProjectileSpeed' a:help='Speed of projectiles (in metres per second). If unspecified, then it is a melee attack instead'>" +
    139139                    "<ref name='nonNegativeDecimal'/>" +
    140140                "</element>" +
    141                 "<element name='Spread' a:help='Radius over which missiles will tend to land. Roughly 2/3 will land inside this radius (in metres)'><ref name='nonNegativeDecimal'/></element>" +
     141                "<element name='Spread' a:help='Radius over which missiles will tend to land when shooting of the maximum range. Roughly 2/3 will land inside this radius (in metres). When the target is closer to this unit, the spread is naturally diminised.'><ref name='nonNegativeDecimal'/></element>" +
    142142                bonusesSchema +
    143143                preferredClassesSchema +
    144144                restrictedClassesSchema +
     
    469469        // Predict where the unit is when the missile lands.
    470470        var predictedPosition = {"x": targetPosition.x + targetVelocity.x * timeToTarget,
    471471                                 "z": targetPosition.z + targetVelocity.z * timeToTarget};
    472        
     472
    473473        // Compute the real target point (based on spread and target speed)
     474        var range = this.GetRange(type);
     475        var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     476        var elevationAdaptedMaxRange = cmpRangeManager.GetElevationAdaptedRange(selfPosition, cmpPosition.GetRotation(), range.max, range.elevationBonus, 0);
     477        var distanceModifiedSpread = spread * Math.sqrt(horizDistance/elevationAdaptedMaxRange);
    474478        var randNorm = this.GetNormalDistribution();
    475         var offsetX = randNorm[0] * spread * (1 + this.VectorLength(targetVelocity) / 20);
    476         var offsetZ = randNorm[1] * spread * (1 + this.VectorLength(targetVelocity) / 20);
     479        var offsetX = randNorm[0] * distanceModifiedSpread;
     480        var offsetZ = randNorm[1] * distanceModifiedSpread;
    477481
    478482        var realTargetPosition = { "x": predictedPosition.x + offsetX, "y": targetPosition.y, "z": predictedPosition.z + offsetZ };
    479483