2015-04-05 21:28:12 +00:00
|
|
|
/*
|
|
|
|
Author: Pabst Mirror
|
|
|
|
|
|
|
|
Description:
|
2015-04-05 22:07:55 +00:00
|
|
|
Builds a rangeTable line for a certian range, given muzzle velocity and air friction, returns [] if out of range.
|
2015-04-05 21:28:12 +00:00
|
|
|
|
|
|
|
Parameters:
|
2015-04-05 22:07:55 +00:00
|
|
|
0: NUMBER - Muzzle Velocity
|
|
|
|
1: NUMBER - Air Friction
|
|
|
|
2: NUMBER - Range To Hit
|
2015-04-05 21:28:12 +00:00
|
|
|
|
|
|
|
Returns:
|
2015-04-05 22:07:55 +00:00
|
|
|
ARRAY - Range Table Line Data (see return line)
|
2015-04-05 21:28:12 +00:00
|
|
|
|
|
|
|
Example:
|
2015-04-24 18:26:09 +00:00
|
|
|
[300, -0.0001, 3000] call ace_mk6mortar_fnc_simulateCalcRangeTableLine
|
2015-04-05 22:07:55 +00:00
|
|
|
*/
|
2015-04-05 21:28:12 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
#define TIME_STEP (1/50)
|
|
|
|
|
2015-04-24 18:26:09 +00:00
|
|
|
private ["_startTime", "_muzzleVelocity", "_rangeToHit", "_airFriction", "_vacElevation", "_radicand", "_maxElev", "_minElev", "_error", "_solutionElevation", "_lastTestResult", "_numberOfAttempts", "_lineElevation", "_lineTimeOfFlight", "_lineHeightElevation", "_lineHeightTimeDelta", "_lineCrosswindDeg", "_lineHeadwindMeters", "_lineTailWindMeters", "_result"];
|
2015-04-05 21:28:12 +00:00
|
|
|
|
2015-05-21 16:42:44 +00:00
|
|
|
_startTime = ACE_diagTime;
|
2015-04-05 21:28:12 +00:00
|
|
|
|
|
|
|
_muzzleVelocity = _this select 0;
|
|
|
|
_rangeToHit = _this select 1;
|
|
|
|
_airFriction = _this select 2;
|
|
|
|
|
|
|
|
//Run Binary search for correct elevation
|
|
|
|
_solution = [_rangeToHit, 0, _muzzleVelocity, _airFriction, TIME_STEP] call FUNC(dev_simulateFindSolution);
|
|
|
|
if (_solution isEqualTo []) exitWith {[]};
|
|
|
|
|
|
|
|
//Real Elevation
|
|
|
|
_lineElevation = _solution select 0;
|
|
|
|
|
|
|
|
//Time Of Flight:
|
|
|
|
_lineTimeOfFlight = _solution select 1;
|
|
|
|
|
|
|
|
//Height Adjustment for -100m (another binary search)
|
|
|
|
_solution = [_rangeToHit, -100, _muzzleVelocity, _airFriction, TIME_STEP] call FUNC(dev_simulateFindSolution);
|
|
|
|
if (_solution isEqualTo []) exitWith {[]};//should never be triggered (lower elevation easier to hit)
|
|
|
|
|
|
|
|
_lineHeightElevation = ((_solution select 0) - _lineElevation);
|
2015-04-24 18:26:09 +00:00
|
|
|
_lineHeightTimeDelta = (_solution select 1) - _lineTimeOfFlight;
|
2015-04-05 21:28:12 +00:00
|
|
|
|
|
|
|
//Compute for 10x and divide to minimize rounding errors
|
|
|
|
|
|
|
|
//Crosswind
|
|
|
|
_lastTestResult = [_lineElevation, _muzzleVelocity, _airFriction, 15, 1, 0, 10, 0, TIME_STEP] call FUNC(dev_simulateShot);
|
|
|
|
_lineCrosswindDeg = (_lastTestResult select 2) / 10;
|
|
|
|
|
|
|
|
//Headwind:
|
|
|
|
_lastTestResult = [_lineElevation, _muzzleVelocity, _airFriction, 15, 1, -10, 0, 0, TIME_STEP] call FUNC(dev_simulateShot);
|
|
|
|
_lineHeadwindMeters = (_rangeToHit - (_lastTestResult select 0)) / 10;
|
|
|
|
|
|
|
|
//TailWind:
|
|
|
|
_lastTestResult = [_lineElevation, _muzzleVelocity, _airFriction, 15, 1, 10, 0, 0, TIME_STEP] call FUNC(dev_simulateShot);
|
|
|
|
_lineTailWindMeters = (_rangeToHit - (_lastTestResult select 0)) / 10;
|
|
|
|
|
|
|
|
//Air Temp Dec
|
|
|
|
_lastTestResult = [_lineElevation, _muzzleVelocity, _airFriction, (15 - 10), 1, 0, 0, 0, TIME_STEP] call FUNC(dev_simulateShot);
|
|
|
|
_lineTempDec = (_rangeToHit - (_lastTestResult select 0)) / 10;
|
|
|
|
|
|
|
|
//Air Temp Inc
|
|
|
|
_lastTestResult = [_lineElevation, _muzzleVelocity, _airFriction, (15 + 10), 1, 0, 0, 0, TIME_STEP] call FUNC(dev_simulateShot);
|
|
|
|
_lineTempInc = (_rangeToHit - (_lastTestResult select 0)) / 10;
|
|
|
|
|
|
|
|
//Air Density Dec
|
|
|
|
_lastTestResult = [_lineElevation, _muzzleVelocity, _airFriction, 15, 0.9, 0, 0, 0, TIME_STEP] call FUNC(dev_simulateShot);
|
|
|
|
_lineAirDensDec = (_rangeToHit - (_lastTestResult select 0)) / 10;
|
|
|
|
|
|
|
|
//Air Density Inc
|
|
|
|
_lastTestResult = [_lineElevation, _muzzleVelocity, _airFriction, 15, 1.1, 0, 0, 0, TIME_STEP] call FUNC(dev_simulateShot);
|
|
|
|
_lineAirDensInc = (_rangeToHit - (_lastTestResult select 0)) / 10;
|
|
|
|
|
2015-05-21 16:42:44 +00:00
|
|
|
// systemChat format ["debug: Range %1 - in %2 sec", _rangeToHit, (ACE_diagTime - _startTime)];
|
2015-04-05 21:28:12 +00:00
|
|
|
|
2015-04-24 18:26:09 +00:00
|
|
|
[_rangeToHit, _lineElevation, _lineHeightElevation, _lineHeightTimeDelta, _lineTimeOfFlight, _lineCrosswindDeg, _lineHeadwindMeters, _lineTailWindMeters, _lineTempDec, _lineTempInc, _lineAirDensDec, _lineAirDensInc]
|