2023-09-12 18:58:10 +00:00
#include "..\script_component.hpp"
2015-05-08 16:43:26 +00:00
/*
* Author: Ruthberg
*
* Reads the ammo class config and updates the config cache
*
* Arguments:
2015-08-05 04:01:38 +00:00
* ammo - classname <STRING>
2015-05-08 16:43:26 +00:00
*
* Return Value:
2017-06-08 13:31:51 +00:00
* 0: _airFriction <NUMBER>
* 1: _caliber <NUMBER>
* 2: _bulletLength <NUMBER>
* 3: _bulletMass <NUMBER>
* 4: _transonicStabilityCoef <NUMBER>
* 5: _dragModel <NUMBER>
* 6: _ballisticCoefficients <NUMBER>
* 7: _velocityBoundaries <NUMBER>
* 8: _atmosphereModel <NUMBER>
* 9: _ammoTempMuzzleVelocityShifts <NUMBER>
* 10: _muzzleVelocityTable <NUMBER>
* 11: _barrelLengthTable <NUMBER>
*
* Example:
* ["ammo"] call ace_advanced_ballistics_fnc_readAmmoDataFromConfig
2015-08-05 02:38:04 +00:00
*
* Public: No
2015-05-08 16:43:26 +00:00
*/
2016-01-07 20:54:28 +00:00
TRACE_1("Reading Ammo Config",_this);
2017-10-10 14:39:59 +00:00
2017-05-14 19:48:05 +00:00
private _ammoConfig = configFile >> "CfgAmmo" >> _this;
2015-05-08 16:43:26 +00:00
2017-10-10 14:39:59 +00:00
private _airFriction = getNumber(_ammoConfig >> "airFriction");
2017-11-22 22:16:17 +00:00
private _caliber = 0 max getNumber(_ammoConfig >> "ACE_caliber");
private _bulletLength = 0 max getNumber(_ammoConfig >> "ACE_bulletLength");
private _bulletMass = 0 max getNumber(_ammoConfig >> "ACE_bulletMass");
private _transonicStabilityCoef = 0 max getNumber(_ammoConfig >> "ACE_transonicStabilityCoef") min 1;
2015-08-05 04:01:38 +00:00
if (_transonicStabilityCoef == 0) then {
_transonicStabilityCoef = 0.5;
};
2017-10-10 14:39:59 +00:00
private _dragModel = getNumber(_ammoConfig >> "ACE_dragModel");
2024-06-18 14:08:03 +00:00
if !(_dragModel in [1, 2, 5, 6, 7, 8]) then {
2015-08-05 04:01:38 +00:00
_dragModel = 1;
};
2017-10-10 14:39:59 +00:00
private _ballisticCoefficients = getArray(_ammoConfig >> "ACE_ballisticCoefficients");
2024-03-24 16:32:28 +00:00
if (_ballisticCoefficients isEqualTo []) then {
_ballisticCoefficients = [0.5];
};
2017-10-10 14:39:59 +00:00
private _velocityBoundaries = getArray(_ammoConfig >> "ACE_velocityBoundaries");
private _atmosphereModel = getText(_ammoConfig >> "ACE_standardAtmosphere");
2015-08-05 04:01:38 +00:00
if (_atmosphereModel isEqualTo "") then {
_atmosphereModel = "ICAO";
};
2017-11-19 17:48:26 +00:00
private _muzzleVelocityVariationSD = DEFAULT_MUZZLE_VELOCITY_VARIATION_SD;
if (isNumber (_ammoConfig >> "ACE_muzzleVelocityVariationSD")) then {
_muzzleVelocityVariationSD = getNumber(_ammoConfig >> "ACE_muzzleVelocityVariationSD") / 100;
};
2017-10-10 14:39:59 +00:00
private _ammoTempMuzzleVelocityShifts = getArray(_ammoConfig >> "ACE_ammoTempMuzzleVelocityShifts");
private _muzzleVelocityTable = getArray(_ammoConfig >> "ACE_muzzleVelocities");
private _barrelLengthTable = getArray(_ammoConfig >> "ACE_barrelLengths");
2015-05-08 16:43:26 +00:00
2016-01-07 20:54:28 +00:00
//Handle subsonic ammo that would have a huge muzzle velocity shift (when ballistic configs not explicitly defined)
private _typicalSpeed = getNumber (_ammoConfig >> "typicalSpeed");
if ((_typicalSpeed > 0) && {_typicalSpeed < 360}) then {
2021-02-27 17:05:05 +00:00
private _inheritedBarrelConfig = (_muzzleVelocityTable isNotEqualTo []) && {(configProperties [_ammoConfig, "(configName _x) == 'ACE_muzzleVelocities'", false]) isEqualTo []};
private _inheritedTempConfig = (_ammoTempMuzzleVelocityShifts isNotEqualTo []) && {(configProperties [_ammoConfig, "(configName _x) == 'ACE_ammoTempMuzzleVelocityShifts'", false]) isEqualTo []};
2016-01-07 20:54:28 +00:00
TRACE_3("subsonic",_typicalSpeed,_inheritedBarrelConfig,_inheritedTempConfig);
if (_inheritedBarrelConfig || _inheritedTempConfig) then {
private _parentConfig = inheritsFrom _ammoConfig;
private _parentSpeed = getNumber (_parentConfig >> "typicalSpeed");
2024-02-05 17:04:24 +00:00
WARNING_4("Subsonic Ammo %1 (%2 m/s) missing `ACE_muzzleVelocities` or `ACE_ammoTempMuzzleVelocityShifts` configs, attempting to use parent %3 (%4m/s)",_this,_typicalSpeed,configName _parentConfig,_parentSpeed);
2016-01-07 20:54:28 +00:00
if (_parentSpeed <= 0) exitWith {//Handle weird or null parent
_muzzleVelocityTable = [];
_ammoTempMuzzleVelocityShifts = [];
};
private _linearMuliplier = _typicalSpeed / _parentSpeed;
if (_inheritedBarrelConfig) then {
2021-02-27 17:05:05 +00:00
if ((configProperties [_parentConfig, "(configName _x) == 'ACE_muzzleVelocities'", false]) isNotEqualTo []) then {
2016-01-07 20:54:28 +00:00
TRACE_2("Parent Has Defined Barrel MV",_linearMuliplier,_muzzleVelocityTable);
{ _muzzleVelocityTable set [_forEachIndex, (_x * _linearMuliplier)]; } forEach _muzzleVelocityTable;
} else {
TRACE_2("Parent DOES NOT Have Defined Barrel MV",_linearMuliplier,_muzzleVelocityTable);
_muzzleVelocityTable = [];
};
};
if (_inheritedTempConfig) then {
2021-02-27 17:05:05 +00:00
if ((configProperties [_parentConfig, "(configName _x) == 'ACE_ammoTempMuzzleVelocityShifts'", false]) isNotEqualTo []) then {
2016-01-07 20:54:28 +00:00
TRACE_2("Parent Has Defined Ammo Temp Shifts",_linearMuliplier,_muzzleVelocityTable);
{ _ammoTempMuzzleVelocityShifts set [_forEachIndex, (_x * _linearMuliplier)]; } forEach _ammoTempMuzzleVelocityShifts;
} else {
TRACE_2("Parent DOES NOT Have Defined Ammo Temp Shifts",_linearMuliplier,_muzzleVelocityTable);
_ammoTempMuzzleVelocityShifts = [];
};
};
};
};
2017-11-19 17:48:26 +00:00
private _result = [_airFriction, _caliber, _bulletLength, _bulletMass, _transonicStabilityCoef, _dragModel, _ballisticCoefficients, _velocityBoundaries, _atmosphereModel, _ammoTempMuzzleVelocityShifts, _muzzleVelocityTable, _barrelLengthTable, _muzzleVelocityVariationSD];
2015-05-08 16:43:26 +00:00
2015-08-05 04:01:38 +00:00
uiNamespace setVariable [format[QGVAR(%1), _this], _result];
2015-05-08 16:43:26 +00:00
_result