From 7a0a1ead6ee8e143303ac4f1cd6f0e564dc0bbf4 Mon Sep 17 00:00:00 2001 From: jokoho48 Date: Wed, 5 Aug 2015 00:32:48 +0200 Subject: [PATCH] Updated parameterization in Advanced Ballistics module. --- addons/advanced_ballistics/ACE_Settings.hpp | 40 +++++++++---------- ..._calculateAmmoTemperatureVelocityShift.sqf | 5 +-- .../fnc_calculateAtmosphericCorrection.sqf | 9 ++--- ...fnc_calculateBarrelLengthVelocityShift.sqf | 7 +--- .../functions/fnc_calculateRetardation.sqf | 25 +++++------- .../fnc_calculateStabilityFactor.sqf | 10 +---- .../functions/fnc_displayProtractor.sqf | 17 ++++---- .../functions/fnc_handleFired.sqf | 30 +++++--------- .../functions/fnc_initModuleSettings.sqf | 5 +-- .../fnc_initializeTerrainExtension.sqf | 15 +++---- 10 files changed, 63 insertions(+), 100 deletions(-) diff --git a/addons/advanced_ballistics/ACE_Settings.hpp b/addons/advanced_ballistics/ACE_Settings.hpp index d88a9b1148..757385deb3 100644 --- a/addons/advanced_ballistics/ACE_Settings.hpp +++ b/addons/advanced_ballistics/ACE_Settings.hpp @@ -1,31 +1,31 @@ class ACE_Settings { class GVAR(enabled) { - displayName = CSTRING(enabled_DisplayName); - description = CSTRING(enabled_Description); + displayName = "Advanced Ballistics"; + description = "Enables advanced ballistics"; typeName = "BOOL"; value = 0; }; class GVAR(simulateForSnipers) { - displayName = CSTRING(simulateForSnipers_DisplayName); - description = CSTRING(simulateForSnipers_Description); + displayName = "Enabled For Snipers"; + description = "Enables advanced ballistics for non local snipers (when using high power optics)"; typeName = "BOOL"; value = 1; }; class GVAR(simulateForGroupMembers) { - displayName = CSTRING(simulateForGroupMembers_DisplayName); - description = CSTRING(simulateForGroupMembers_Description); + displayName = "Enabled For Group Members"; + description = "Enables advanced ballistics for non local group members"; typeName = "BOOL"; value = 0; }; class GVAR(simulateForEveryone) { - displayName = CSTRING(simulateForEveryone_DisplayName); - description = CSTRING(simulateForEveryone_Description); + displayName = "Enabled For Everyone"; + description = "Enables advanced ballistics for all non local players (enabling this may degrade performance during heavy firefights in multiplayer)"; typeName = "BOOL"; value = 0; }; class GVAR(disabledInFullAutoMode) { - displayName = CSTRING(disabledInFullAutoMod_DisplayName); - description = CSTRING(disabledInFullAutoMod_Description); + displayName = "Disabled In FullAuto Mode"; + description = "Disables advanced ballistics during full auto fire"; typeName = "BOOL"; value = 0; }; @@ -38,32 +38,32 @@ class ACE_Settings { }; */ class GVAR(ammoTemperatureEnabled) { - displayName = CSTRING(ammoTemperatureEnabled_DisplayName); - description = CSTRING(ammoTemperatureEnabled_Description); + displayName = "Enable Ammo Temperature Simulation"; + description = "Muzzle velocity varies with ammo temperature"; typeName = "BOOL"; value = 1; }; class GVAR(barrelLengthInfluenceEnabled) { - displayName = CSTRING(barrelLengthInfluenceEnabled_DisplayName); - description = CSTRING(barrelLengthInfluenceEnabled_Description); + displayName = "Enable Barrel Length Simulation"; + description = "Muzzle velocity varies with barrel length"; typeName = "BOOL"; value = 1; }; class GVAR(bulletTraceEnabled) { - displayName = CSTRING(bulletTraceEnabled_DisplayName); - description = CSTRING(bulletTraceEnabled_Description); + displayName = "Enable Bullet Trace Effect"; + description = "Enables a bullet trace effect to high caliber bullets (only visible when looking through high power optics)"; typeName = "BOOL"; value = 1; }; class GVAR(simulationInterval) { - displayName = CSTRING(simulationInterval_DisplayName); - description = CSTRING(simulationInterval_Description); + displayName = "Simulation Interval"; + description = "Defines the interval between every calculation step"; typeName = "SCALAR"; value = 0.0; }; class GVAR(simulationRadius) { - displayName = CSTRING(simulationRadius_DisplayName); - description = CSTRING(simulationRadius_Description); + displayName = "Simulation Radius"; + description = "Defines the radius around the player (in meters) at which advanced ballistics are applied to projectiles"; typeName = "SCALAR"; value = 3000; }; diff --git a/addons/advanced_ballistics/functions/fnc_calculateAmmoTemperatureVelocityShift.sqf b/addons/advanced_ballistics/functions/fnc_calculateAmmoTemperatureVelocityShift.sqf index 28df9d1d97..16b094b462 100644 --- a/addons/advanced_ballistics/functions/fnc_calculateAmmoTemperatureVelocityShift.sqf +++ b/addons/advanced_ballistics/functions/fnc_calculateAmmoTemperatureVelocityShift.sqf @@ -15,9 +15,8 @@ */ #include "script_component.hpp" -private ["_muzzleVelocityShiftTable", "_temperature", "_muzzleVelocityShift", "_temperatureIndexA", "_temperatureIndexB", "_temperatureRatio"]; -_muzzleVelocityShiftTable = _this select 0; -_temperature = _this select 1; +private ["_muzzleVelocityShift", "_temperatureIndexA", "_temperatureIndexB", "_temperatureRatio"]; +params["_muzzleVelocityShiftTable", "_temperature"]; if (count _muzzleVelocityShiftTable != 11) exitWith { 0 }; diff --git a/addons/advanced_ballistics/functions/fnc_calculateAtmosphericCorrection.sqf b/addons/advanced_ballistics/functions/fnc_calculateAtmosphericCorrection.sqf index b0166109f5..fac048c061 100644 --- a/addons/advanced_ballistics/functions/fnc_calculateAtmosphericCorrection.sqf +++ b/addons/advanced_ballistics/functions/fnc_calculateAtmosphericCorrection.sqf @@ -17,12 +17,9 @@ */ #include "script_component.hpp" -private ["_ballisticCoefficient", "_temperature", "_pressure", "_relativeHumidity", "_atmosphereModel", "_airDensity"]; -_ballisticCoefficient = _this select 0; -_temperature = _this select 1; // in C -_pressure = _this select 2; // in hPa -_relativeHumidity = _this select 3; // as ratio 0-1 -_atmosphereModel = _this select 4; // "ICAO" or "ASM" +private "_airDensity"; + +params ["_ballisticCoefficient", "_temperature"/*in C*/, "_pressure"/*in hPa*/, "_relativeHumidity"/*as ratio 0-1*/, "_atmosphereModel"/*"ICAO" or "ASM"*/]; _airDensity = [_temperature, _pressure, _relativeHumidity] call EFUNC(weather,calculateAirDensity); diff --git a/addons/advanced_ballistics/functions/fnc_calculateBarrelLengthVelocityShift.sqf b/addons/advanced_ballistics/functions/fnc_calculateBarrelLengthVelocityShift.sqf index de037f49bc..1896ef816b 100644 --- a/addons/advanced_ballistics/functions/fnc_calculateBarrelLengthVelocityShift.sqf +++ b/addons/advanced_ballistics/functions/fnc_calculateBarrelLengthVelocityShift.sqf @@ -17,11 +17,8 @@ */ #include "script_component.hpp" -private ["_barrelLength", "_muzzleVelocityTable", "_barrelLengthTable", "_muzzleVelocity", "_lowerIndex", "_upperIndex", "_barrelLengthRatio", "_muzzleVelocityNew"]; -_barrelLength = _this select 0; -_muzzleVelocityTable = _this select 1; -_barrelLengthTable = _this select 2; -_muzzleVelocity = _this select 3; +private ["_lowerIndex", "_upperIndex", "_barrelLengthRatio", "_muzzleVelocityNew"]; +params ["_barrelLength", "_muzzleVelocityTable", "_barrelLengthTable", "_muzzleVelocity"]; if (_barrelLength == 0) exitWith { 0 }; if (count _muzzleVelocityTable != count _barrelLengthTable) exitWith { 0 }; diff --git a/addons/advanced_ballistics/functions/fnc_calculateRetardation.sqf b/addons/advanced_ballistics/functions/fnc_calculateRetardation.sqf index 433dafbe10..507410276e 100644 --- a/addons/advanced_ballistics/functions/fnc_calculateRetardation.sqf +++ b/addons/advanced_ballistics/functions/fnc_calculateRetardation.sqf @@ -18,18 +18,16 @@ // Source: GNU Exterior Ballistics -private ["_dragModel", "_dragCoefficient", "_velocity", "_A", "_M", "_result"]; -_dragModel = _this select 0; -_dragCoefficient = _this select 1; -_velocity = (_this select 2) * 3.2808399; +private ["_A", "_M", "_result"]; +params ["_dragModel", "_dragCoefficient", "_velocity"]; +_velocity = _velocity * 3.2808399; _A = -1; _M = -1; _result = 0; switch _dragModel do { - case 1: - { + case 1: { switch true do { case (_velocity > 4230) : { _A = 0.0001477404177730177; _M = 1.9565; }; case (_velocity > 3680) : { _A = 0.0001920339268755614; _M = 1.925 ; }; @@ -74,8 +72,7 @@ switch _dragModel do { case (_velocity > 0) : { _A = 0.00005206214107320588; _M = 2.000 ; }; }; }; - case 2: - { + case 2: { switch true do { case (_velocity > 1674) : { _A = 0.0079470052136733; _M = 1.36999902851493; }; case (_velocity > 1172) : { _A = 0.00100419763721974; _M = 1.65392237010294; }; @@ -86,8 +83,7 @@ switch _dragModel do { case (_velocity > 0) : { _A = 0.0000518033561289704; _M = 1.98160270524632; }; }; }; - case 5: - { + case 5: { switch true do { case (_velocity > 1730) : { _A = 0.00724854775171929; _M = 1.41538574492812; }; case (_velocity > 1228) : { _A = 0.0000350563361516117; _M = 2.13077307854948; }; @@ -98,8 +94,7 @@ switch _dragModel do { case (_velocity > 0) : { _A = 0.0000351963178524273; _M = 2.00477856801111; }; }; }; - case 6: - { + case 6: { switch true do { case (_velocity > 3236) : { _A = 0.0455384883480781; _M = 1.15997674041274; }; case (_velocity > 2065) : { _A = 0.07167261849653769; _M = 1.10704436538885; }; @@ -110,8 +105,7 @@ switch _dragModel do { case (_velocity > 0) : { _A = 0.0000750912466084823; _M = 1.92031057847052; }; }; }; - case 7: - { + case 7: { switch true do { case (_velocity > 4200) : { _A = 0.00000000129081656775919; _M = 3.24121295355962; }; case (_velocity > 3000) : { _A = 0.0171422231434847; _M = 1.27907168025204; }; @@ -124,8 +118,7 @@ switch _dragModel do { case (_velocity > 0) : { _A = 0.0000134504843776525; _M = 2.08702306738884; }; }; }; - case 8: - { + case 8: { switch true do { case (_velocity > 3571) : { _A = 0.0112263766252305; _M = 1.33207346655961; }; case (_velocity > 1841) : { _A = 0.0167252613732636; _M = 1.28662041261785; }; diff --git a/addons/advanced_ballistics/functions/fnc_calculateStabilityFactor.sqf b/addons/advanced_ballistics/functions/fnc_calculateStabilityFactor.sqf index 9b205c3ec2..d09e292138 100644 --- a/addons/advanced_ballistics/functions/fnc_calculateStabilityFactor.sqf +++ b/addons/advanced_ballistics/functions/fnc_calculateStabilityFactor.sqf @@ -19,14 +19,8 @@ */ #include "script_component.hpp" -private ["_caliber", "_bulletLength", "_bulletMass", "_barrelTwist", "_muzzleVelocity", "_temperature", "_barometricPressure", "_l", "_t", "_stabilityFactor"]; -_caliber = _this select 0; -_bulletLength = _this select 1; -_bulletMass = _this select 2; -_barrelTwist = _this select 3; -_muzzleVelocity = _this select 4; -_temperature = _this select 5; -_barometricPressure = _this select 6; +private ["_l", "_t", "_stabilityFactor"]; +params ["_caliber", "_bulletLength", "_bulletMass", "_barrelTwist", "_muzzleVelocity", "_temperature", "_barometricPressure"]; // Source: http://www.jbmballistics.com/ballistics/bibliography/articles/miller_stability_1.pdf _t = _barrelTwist / _caliber; diff --git a/addons/advanced_ballistics/functions/fnc_displayProtractor.sqf b/addons/advanced_ballistics/functions/fnc_displayProtractor.sqf index 1a4c344b2e..3acefff54e 100644 --- a/addons/advanced_ballistics/functions/fnc_displayProtractor.sqf +++ b/addons/advanced_ballistics/functions/fnc_displayProtractor.sqf @@ -32,30 +32,29 @@ EGVAR(weather,WindInfo) = false; GVAR(Protractor) = true; [{ + params ["","_idPFH"]; if !(GVAR(Protractor) && !(weaponLowered ACE_player) && currentWeapon ACE_player == primaryWeapon ACE_player) exitWith { GVAR(Protractor) = false; 1 cutText ["", "PLAIN"]; - [_this select 1] call cba_fnc_removePerFrameHandler; + [_idPFH] call cba_fnc_removePerFrameHandler; }; - - _refPosition = [SafeZoneX + 0.001, SafeZoneY + 0.001, 0.2, 0.2 * 4/3]; - + _inclinationAngle = asin((ACE_player weaponDirection currentWeapon ACE_player) select 2); _inclinationAngle = -58 max _inclinationAngle min 58; - + 1 cutRsc ["RscProtractor", "PLAIN", 1, false]; - + __ctrl1 ctrlSetScale 1; __ctrl1 ctrlCommit 0; __ctrl1 ctrlSetText QUOTE(PATHTOF(UI\protractor.paa)); __ctrl1 ctrlSetTextColor [1, 1, 1, 1]; - + __ctrl2 ctrlSetScale 1; - __ctrl2 ctrlSetPosition [(_refPosition select 0), (_refPosition select 1) - 0.0012 * _inclinationAngle, (_refPosition select 2), (_refPosition select 3)]; + __ctrl2 ctrlSetPosition [SafeZoneX + 0.001, SafeZoneY + 0.001 - 0.0012 * _inclinationAngle, 0.2, 0.2 * 4/3]; __ctrl2 ctrlCommit 0; __ctrl2 ctrlSetText QUOTE(PATHTOF(UI\protractor_marker.paa)); __ctrl2 ctrlSetTextColor [1, 1, 1, 1]; - + }, 0.1, []] call CBA_fnc_addPerFrameHandler; true diff --git a/addons/advanced_ballistics/functions/fnc_handleFired.sqf b/addons/advanced_ballistics/functions/fnc_handleFired.sqf index 7c01bd9f23..8285eb49cb 100644 --- a/addons/advanced_ballistics/functions/fnc_handleFired.sqf +++ b/addons/advanced_ballistics/functions/fnc_handleFired.sqf @@ -19,13 +19,8 @@ */ #include "script_component.hpp" -private ["_unit", "_weapon", "_mode", "_ammo", "_magazine", "_caliber", "_bullet", "_abort", "_AmmoCacheEntry", "_WeaponCacheEntry", "_opticsName", "_opticType", "_bulletTraceVisible", "_temperature", "_barometricPressure", "_bulletMass", "_bulletLength", "_muzzleVelocity", "_muzzleVelocityShift", "_bulletVelocity", "_bulletSpeed", "_bulletLength", "_barrelTwist", "_stabilityFactor"]; -_unit = _this select 0; -_weapon = _this select 1; -_mode = _this select 3; -_ammo = _this select 4; -_magazine = _this select 5; -_bullet = _this select 6; +private ["_abort", "_AmmoCacheEntry", "_WeaponCacheEntry", "_opticsName", "_opticType", "_bulletTraceVisible", "_temperature", "_barometricPressure", "_bulletMass", "_bulletLength", "_muzzleVelocity", "_muzzleVelocityShift", "_bulletVelocity", "_bulletSpeed", "_bulletLength", "_barrelTwist", "_stabilityFactor"]; +params ["_unit", "_weapon", "_mode", "_ammo", "_magazine", "_caliber", "_bullet"]; _abort = false; if (!hasInterface) exitWith {}; @@ -53,9 +48,7 @@ if (!GVAR(simulateForEveryone) && !(local _unit)) then { if (GVAR(disabledInFullAutoMode) && getNumber(configFile >> "CfgWeapons" >> _weapon >> _mode >> "autoFire") == 1) then { _abort = true; }; if (_abort || !(GVAR(extensionAvailable))) exitWith { - if (missionNamespace getVariable [QEGVAR(windDeflection,enabled), false]) then { - EGVAR(windDeflection,trackedBullets) pushBack [_bullet, getNumber(configFile >> "cfgAmmo" >> _ammo >> "airFriction")]; - }; + [_bullet, getNumber(configFile >> "CfgAmmo" >> _ammo >> "airFriction")] call EFUNC(winddeflection,updateTrajectoryPFH); }; _AmmoCacheEntry = uiNamespace getVariable format[QGVAR(%1), _ammo]; @@ -120,21 +113,18 @@ GVAR(currentbulletID) = (GVAR(currentbulletID) + 1) % 10000; [{ private ["_args", "_index", "_bullet", "_caliber", "_bulletTraceVisible", "_bulletVelocity", "_bulletPosition"]; - _args = _this select 0; - _bullet = _args select 0; - _caliber = _args select 1; - _bulletTraceVisible = _args select 2; - _index = _args select 3; - + params ["_args","_idPFH"]; + _args params["_bullet","_caliber","_bulletTraceVisible","_index"]; + _bulletVelocity = velocity _bullet; _bulletPosition = getPosASL _bullet; - + _bulletSpeed = vectorMagnitude _bulletVelocity; - + if (!alive _bullet || _bulletSpeed < 100) exitWith { - [_this select 1] call cba_fnc_removePerFrameHandler; + [_idPFH] call cba_fnc_removePerFrameHandler; }; - + if (_bulletTraceVisible && _bulletSpeed > 500) then { drop ["\A3\data_f\ParticleEffects\Universal\Refract","","Billboard",1,0.1,getPos _bullet,[0,0,0],0,1.275,1,0,[0.02*_caliber,0.01*_caliber],[[0,0,0,0.65],[0,0,0,0.2]],[1,0],0,0,"","",""]; }; diff --git a/addons/advanced_ballistics/functions/fnc_initModuleSettings.sqf b/addons/advanced_ballistics/functions/fnc_initModuleSettings.sqf index 186c0d0649..7cfa50b7df 100644 --- a/addons/advanced_ballistics/functions/fnc_initModuleSettings.sqf +++ b/addons/advanced_ballistics/functions/fnc_initModuleSettings.sqf @@ -15,10 +15,7 @@ #include "script_component.hpp" -private ["_logic", "_units", "_activated"]; -_logic = _this select 0; -_units = _this select 1; -_activated = _this select 2; +params ["_logic","_units", "_activated"] if !(_activated) exitWith {}; diff --git a/addons/advanced_ballistics/functions/fnc_initializeTerrainExtension.sqf b/addons/advanced_ballistics/functions/fnc_initializeTerrainExtension.sqf index b2fc7ba084..7587285963 100644 --- a/addons/advanced_ballistics/functions/fnc_initializeTerrainExtension.sqf +++ b/addons/advanced_ballistics/functions/fnc_initializeTerrainExtension.sqf @@ -33,19 +33,16 @@ _gridCells = _mapGrids * _mapGrids; GVAR(currentGrid) = 0; [{ - private ["_args", "_mapGrids", "_gridCells", "_initStartTime"]; - _args = _this select 0; - _mapGrids = _args select 0; - _gridCells = _args select 1; - _initStartTime = _args select 2; - + params ["_args","_idPFH"]; + _args params ["_mapGrids", "_gridCells", "_initStartTime"]; + if (GVAR(currentGrid) >= _gridCells) exitWith { if (GVAR(initMessageEnabled)) then { systemChat format["AdvancedBallistics: Finished terrain initialization in %1 seconds", ceil(ACE_time - _initStartTime)]; }; - [_this select 1] call cba_fnc_removePerFrameHandler; + [_idPFH] call cba_fnc_removePerFrameHandler; }; - + for "_i" from 1 to 50 do { _x = floor(GVAR(currentGrid) / _mapGrids) * 50; _y = (GVAR(currentGrid) - floor(GVAR(currentGrid) / _mapGrids) * _mapGrids) * 50; @@ -57,5 +54,5 @@ GVAR(currentGrid) = 0; GVAR(currentGrid) = GVAR(currentGrid) + 1; if (GVAR(currentGrid) >= _gridCells) exitWith {}; }; - + }, 0, [_mapGrids, _gridCells, _initStartTime]] call CBA_fnc_addPerFrameHandler