From dcd4137491cbb03aa88689108c759f1383908545 Mon Sep 17 00:00:00 2001 From: ulteq Date: Wed, 16 Nov 2016 16:27:56 +0100 Subject: [PATCH] Fixed several bugs in the unit conversion code * Proper min, max capping for both metric and imperial units * Fixed unit conversion issues on the interpolation table input fields --- addons/atragmx/functions/fnc_parse_input.sqf | 121 ++++++++++++------ ...fnc_show_c1_ballistic_coefficient_data.sqf | 5 + ...c_update_c1_ballistic_coefficient_data.sqf | 2 +- .../functions/fnc_update_gun_ammo_data.sqf | 2 +- .../functions/fnc_update_unit_selection.sqf | 2 + .../functions/fnc_update_zero_range.sqf | 4 - 6 files changed, 92 insertions(+), 44 deletions(-) diff --git a/addons/atragmx/functions/fnc_parse_input.sqf b/addons/atragmx/functions/fnc_parse_input.sqf index 2f73ecebba..38310edfae 100644 --- a/addons/atragmx/functions/fnc_parse_input.sqf +++ b/addons/atragmx/functions/fnc_parse_input.sqf @@ -17,49 +17,96 @@ // Muzzle velocity vs. temperature interpolation data { - private _temperature = -50 max parseNumber(ctrlText _x) min 160; - if (GVAR(currentUnit) == 1) then { + private _temperature = parseNumber(ctrlText _x); + if (GVAR(currentUnit) != 2) then { + _temperature = -50 max _temperature min 160; _temperature = (_temperature - 32) / 1.8; + } else { + _temperature = -50 max _temperature min 71; }; ((GVAR(workingMemory) select 18) select _forEachIndex) set [0, _temperature]; } forEach [160021, 160022, 160023, 160024, 160025, 160026, 160027]; { - private _muzzleVelocity = parseNumber(ctrlText _x); - if (GVAR(currentUnit) == 1) then { - _muzzleVelocity = _muzzleVelocity / 3.2808399; + private _muzzleVelocity = abs(parseNumber(ctrlText _x)); + if (_muzzleVelocity > 0) then { + if (GVAR(currentUnit) != 2) then { + _muzzleVelocity = 300 max _muzzleVelocity min 4500; + _muzzleVelocity = _muzzleVelocity * 0.3048; + } else { + _muzzleVelocity = 100 max _muzzleVelocity min 1400; + }; }; - ((GVAR(workingMemory) select 18) select _forEachIndex) set [1, 0 max _muzzleVelocity min 1400]; + ((GVAR(workingMemory) select 18) select _forEachIndex) set [1, _muzzleVelocity]; } forEach [160031, 160032, 160033, 160034, 160035, 160036, 160037]; // C1 coefficient vs. distance interpolation data { - private _distance = 0 max parseNumber(ctrlText _x) min 4000; - if (GVAR(currentUnit) != 2) then { - _distance = _distance * 0.9144; + private _distance = abs(parseNumber(ctrlText _x)); + if (_distance > 0) then { + if (GVAR(currentUnit) == 1) then { + _distance = 25 max _distance min 4000; + _distance = _distance * 0.9144; + } else { + _distance = 25 max _distance min 3700; + }; }; ((GVAR(workingMemory) select 19) select _forEachIndex) set [0, _distance]; } forEach [170021, 170022, 170023, 170024, 170025, 170026, 170027]; { - private _c1 = 0 max parseNumber(ctrlText _x) min 2.0; + private _c1 = abs(parseNumber(ctrlText _x)); + if (_c1 > 0) then { + _c1 = 0.1 max _c1 min 2.0; + }; ((GVAR(workingMemory) select 19) select _forEachIndex) set [1, _c1]; } forEach [170031, 170032, 170033, 170034, 170035, 170036, 170037]; -GVAR(altitude) = -1000 max parseNumber(ctrlText 130030) min 20000; -GVAR(temperature) = -50 max parseNumber(ctrlText 130040) min 160; -GVAR(barometricPressure) = 10 max parseNumber(ctrlText 130050) min 1350; -GVAR(relativeHumidity) = (0 max parseNumber(ctrlText 130060) min 100) / 100; +GVAR(altitude) = parseNumber(ctrlText 130030); +GVAR(temperature) = parseNumber(ctrlText 130040); +GVAR(barometricPressure) = parseNumber(ctrlText 130050); +GVAR(relativeHumidity) = parseNumber(ctrlText 130060) / 100; if (GVAR(currentUnit) != 2) then { + GVAR(altitude) = -1000 max GVAR(altitude) min 20000; + GVAR(temperature) = -50 max GVAR(temperature) min 160; + GVAR(barometricPressure) = 10 max GVAR(barometricPressure) min 40; GVAR(altitude) = GVAR(altitude) * 0.3048; GVAR(temperature) = (GVAR(temperature) - 32) / 1.8; GVAR(barometricPressure) = GVAR(barometricPressure) * 33.86389; +} else { + GVAR(altitude) = -300 max GVAR(altitude) min 6100; + GVAR(temperature) = -50 max GVAR(temperature) min 71; + GVAR(barometricPressure) = 340 max GVAR(barometricPressure) min 1350; }; -private ["_inclinationAngleCosine", "_inclinationAngleDegree"]; +private ["_windSpeed1", "_windSpeed2", "_targetSpeed", "_targetRange", "_inclinationAngleCosine", "_inclinationAngleDegree"]; +_windSpeed1 = parseNumber(ctrlText 140020); +_windSpeed2 = parseNumber(ctrlText 140021); +_targetSpeed = parseNumber(ctrlText 140050); +_targetRange = parseNumber(ctrlText 140060); +if (GVAR(currentUnit) != 2) then { + _windSpeed1 = 0 max _windSpeed1 min 50; + _windSpeed2 = 0 max _windSpeed2 min 50; + _targetSpeed = 0 max _targetSpeed min 50; + _windSpeed1 = _windSpeed1 * 0.44704; + _windSpeed2 = _windSpeed2 * 0.44704; + _targetSpeed = _targetSpeed * 0.44704; +} else { + _windSpeed1 = 0 max _windSpeed1 min 25; + _windSpeed2 = 0 max _windSpeed2 min 25; + _targetSpeed = 0 max _targetSpeed min 25; +}; +if (GVAR(currentUnit) == 1) then { + _targetRange = 25 max _targetRange min 4000; + _targetRange = _targetRange * 0.9144; +} else { + _targetRange = 25 max _targetRange min 3700; +}; GVAR(latitude) set [GVAR(currentTarget), -90 max Round(parseNumber(ctrlText 140000)) min 90]; GVAR(directionOfFire) set [GVAR(currentTarget), 0 max abs(Round(parseNumber(ctrlText 140010))) min 359]; -GVAR(windSpeed1) set [GVAR(currentTarget), 0 max abs(parseNumber(ctrlText 140020)) min 50]; -GVAR(windSpeed2) set [GVAR(currentTarget), 0 max abs(parseNumber(ctrlText 140021)) min 50]; +GVAR(windSpeed1) set [GVAR(currentTarget), _windSpeed1]; +GVAR(windSpeed2) set [GVAR(currentTarget), _windSpeed2]; GVAR(windDirection) set [GVAR(currentTarget), 1 max Round(parseNumber(ctrlText 140030)) min 12]; +GVAR(targetSpeed) set [GVAR(currentTarget), _targetSpeed]; +GVAR(targetRange) set [GVAR(currentTarget), _targetRange]; _inclinationAngleCosine = 0.5 max parseNumber(ctrlText 140041) min 1; _inclinationAngleDegree = -60 max round(parseNumber(ctrlText 140040)) min 60; if (_inclinationAngleDegree != GVAR(inclinationAngle) select GVAR(currentTarget)) then { @@ -69,52 +116,50 @@ if (_inclinationAngleDegree != GVAR(inclinationAngle) select GVAR(currentTarget) GVAR(inclinationAngle) set [GVAR(currentTarget), round(acos(_inclinationAngleCosine))]; }; }; -GVAR(targetSpeed) set [GVAR(currentTarget), 0 max abs(parseNumber(ctrlText 140050)) min 50]; if ((ctrlText 140051) == ">") then { GVAR(targetSpeedDirection) set [GVAR(currentTarget), +1]; } else { GVAR(targetSpeedDirection) set [GVAR(currentTarget), -1]; }; -GVAR(targetRange) set [GVAR(currentTarget), 0 max abs(parseNumber(ctrlText 140060)) min 4000]; -if (GVAR(currentUnit) != 2) then { - GVAR(windSpeed1) set [GVAR(currentTarget), (GVAR(windSpeed1) select GVAR(currentTarget)) * 0.44704]; - GVAR(windSpeed2) set [GVAR(currentTarget), (GVAR(windSpeed2) select GVAR(currentTarget)) * 0.44704]; - GVAR(targetSpeed) set [GVAR(currentTarget), (GVAR(targetSpeed) select GVAR(currentTarget)) * 0.44704]; -}; -if (GVAR(currentUnit) == 1) then { - GVAR(targetRange) set [GVAR(currentTarget), (GVAR(targetRange) select GVAR(currentTarget)) * 0.9144]; -}; private ["_boreHeight", "_bulletMass", "_bulletDiameter", "_airFriction", "_rifleTwist", "_muzzleVelocity", "_zeroRange"]; _boreHeight = parseNumber(ctrlText 120000); _bulletMass = parseNumber(ctrlText 120010); -_bulletDiameter = parseNumber(ctrlText 120020) * 10; +_bulletDiameter = parseNumber(ctrlText 120020); +_airFriction = parseNumber(ctrlText 120030); if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { - _airFriction = 0.1 max parseNumber(ctrlText 120030) min 2; + _airFriction = 0.1 max _airFriction min 2; } else { - _airFriction = parseNumber(ctrlText 120030) / -1000; + _airFriction = _airFriction / -1000; }; _rifleTwist = parseNumber(ctrlText 120040); _muzzleVelocity = parseNumber(ctrlText 120050); _zeroRange = parseNumber(ctrlText 120060); if (GVAR(currentUnit) != 2) then { + _boreHeight = 0.1 max _boreHeight min 5; + _bulletMass = 1 max _bulletMass min 1500; + _bulletDiameter = 0.1 max _bulletDiameter min 1.0; + _rifleTwist = 1 max _rifleTwist min 36; + _muzzleVelocity = 300 max _muzzleVelocity min 4500; _boreHeight = _boreHeight * 2.54; _bulletMass = _bulletMass * 0.06479891; _bulletDiameter = _bulletDiameter * 2.54; _rifleTwist = _rifleTwist * 2.54; - _muzzleVelocity = _muzzleVelocity / 3.2808399; + _muzzleVelocity = _muzzleVelocity * 0.3048; +} else { + _boreHeight = 0.1 max _boreHeight min 10; + _bulletMass = 1 max _bulletMass min 100; + _bulletDiameter = 0.1 max _bulletDiameter min 2.5; + _rifleTwist = 1 max _rifleTwist min 75; + _muzzleVelocity = 100 max _muzzleVelocity min 1400; }; +_zeroRange = 25 max _zeroRange min 1000; if (GVAR(currentUnit) == 1) then { - _zeroRange = _zeroRange / 1.0936133; + _zeroRange = _zeroRange * 0.9144; }; -_boreHeight = 0.1 max _boreHeight min 10; -_bulletMass = 1 max _bulletMass min 100; -_bulletDiameter = 1 max _bulletDiameter min 25; -_muzzleVelocity = 100 max _muzzleVelocity min 1400; -_zeroRange = 0 max _zeroRange min 1000; GVAR(workingMemory) set [5, _boreHeight]; GVAR(workingMemory) set [12, _bulletMass]; -GVAR(workingMemory) set [13, _bulletDiameter]; +GVAR(workingMemory) set [13, _bulletDiameter * 10]; GVAR(workingMemory) set [14, _rifleTwist]; if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { if (_airFriction != GVAR(workingMemory) select 15) then { diff --git a/addons/atragmx/functions/fnc_show_c1_ballistic_coefficient_data.sqf b/addons/atragmx/functions/fnc_show_c1_ballistic_coefficient_data.sqf index b96902f5fa..9ac13aef86 100644 --- a/addons/atragmx/functions/fnc_show_c1_ballistic_coefficient_data.sqf +++ b/addons/atragmx/functions/fnc_show_c1_ballistic_coefficient_data.sqf @@ -20,6 +20,11 @@ GVAR(showC1BallisticCoefficientData) = _this; {ctrlShow [_x, _this]} forEach [17000, 17001, 170021, 170022, 170023, 170024, 170025, 170026, 170027, 170031, 170032, 170033, 170034, 170035, 170036, 170037, 17004, 17005, 17006, 17007, 17008, 17009]; if (_this) then { + if (GVAR(currentUnit) != 1) then { + ctrlSetText [17000, "Meters"]; + } else { + ctrlSetText [17000, "Yards"]; + }; ctrlSetFocus ((uiNamespace getVariable "ATragMX_Display") displayCtrl 170031); [] call FUNC(update_c1_ballistic_coefficient_data); }; diff --git a/addons/atragmx/functions/fnc_update_c1_ballistic_coefficient_data.sqf b/addons/atragmx/functions/fnc_update_c1_ballistic_coefficient_data.sqf index 09148fd156..d63d9768da 100644 --- a/addons/atragmx/functions/fnc_update_c1_ballistic_coefficient_data.sqf +++ b/addons/atragmx/functions/fnc_update_c1_ballistic_coefficient_data.sqf @@ -16,7 +16,7 @@ #include "script_component.hpp" // Distances -if (GVAR(currentUnit) == 2) then { +if (GVAR(currentUnit) != 1) then { {ctrlSetText [_x, Str(Round(((GVAR(workingMemory) select 19) select _forEachIndex) select 0))]} forEach [170021, 170022, 170023, 170024, 170025, 170026, 170027]; } else { {ctrlSetText [_x, Str(Round((((GVAR(workingMemory) select 19) select _forEachIndex) select 0) * 1.0936133))]} forEach [170021, 170022, 170023, 170024, 170025, 170026, 170027]; diff --git a/addons/atragmx/functions/fnc_update_gun_ammo_data.sqf b/addons/atragmx/functions/fnc_update_gun_ammo_data.sqf index 6332506006..abdb401454 100644 --- a/addons/atragmx/functions/fnc_update_gun_ammo_data.sqf +++ b/addons/atragmx/functions/fnc_update_gun_ammo_data.sqf @@ -68,7 +68,7 @@ if (GVAR(currentUnit) == 2) then { ctrlSetText [12000, "Bore (inches)"]; ctrlSetText [12001, "Bullet Weight (grains)"]; ctrlSetText [12002, "Bullet Diam (inches)"]; - ctrlSetText [12004, "Rifle Twist (inches/trn)"]; + ctrlSetText [12004, "Rifle Twist (in/trn)"]; ctrlSetText [12005, "Muzzle Velocity (feet/sec)"]; }; diff --git a/addons/atragmx/functions/fnc_update_unit_selection.sqf b/addons/atragmx/functions/fnc_update_unit_selection.sqf index 77d96bfdd6..f054857078 100644 --- a/addons/atragmx/functions/fnc_update_unit_selection.sqf +++ b/addons/atragmx/functions/fnc_update_unit_selection.sqf @@ -27,5 +27,7 @@ [] call FUNC(update_atmo_env_data); [] call FUNC(update_target); [] call FUNC(update_target_data); +[] call FUNC(update_muzzle_velocity_data); +[] call FUNC(update_c1_ballistic_coefficient_data); [] call FUNC(update_result); diff --git a/addons/atragmx/functions/fnc_update_zero_range.sqf b/addons/atragmx/functions/fnc_update_zero_range.sqf index 5cf175faf7..e4b3d0da8c 100644 --- a/addons/atragmx/functions/fnc_update_zero_range.sqf +++ b/addons/atragmx/functions/fnc_update_zero_range.sqf @@ -28,10 +28,6 @@ _atmosphereModel = GVAR(workingMemory) select 17; private ["_zeroRange"]; _zeroRange = GVAR(workingMemory) select 2; -if (_zeroRange < 10) exitWith { - GVAR(workingMemory) set [2, _zeroRange]; - GVAR(workingMemory) set [3, 0]; -}; private ["_altitude", "_temperature", "_barometricPressure", "_relativeHumidity"]; _altitude = GVAR(altitude);