From a687c49d2a5653e5c3430630887f302a415d57c3 Mon Sep 17 00:00:00 2001 From: ulteq Date: Tue, 8 Nov 2016 14:47:12 +0100 Subject: [PATCH] Adds settings module for ace_scopes * Interconnects the rangecard and scopes modules * Hides the zeroing text when the vanilla zeroing is overwritten * Makes the scopes module fully compatible with any 3rd party weapon pack without the need for addition compat pbos (though their use is still recommended) --- addons/rangecard/XEH_postInit.sqf | 2 + addons/rangecard/config.cpp | 2 +- .../rangecard/functions/fnc_openRangeCard.sqf | 4 +- .../functions/fnc_updateClassNames.sqf | 2 + .../functions/fnc_updateRangeCard.sqf | 35 +++++------ addons/scopes/ACE_Settings.hpp | 48 +++++++++++++++ addons/scopes/CfgVehicles.hpp | 59 +++++++++++++++++++ addons/scopes/CfgWeapons.hpp | 2 + addons/scopes/XEH_PREP.hpp | 2 + addons/scopes/XEH_postInit.sqf | 3 + addons/scopes/config.cpp | 3 +- addons/scopes/functions/fnc_adjustScope.sqf | 15 ++--- .../fnc_calculateZeroAngleCorrection.sqf | 9 +-- addons/scopes/functions/fnc_firedEH.sqf | 4 +- .../functions/fnc_getCurrentZeroRange.sqf | 35 +++++++++++ .../functions/fnc_initModuleSettings.sqf | 36 +++++++++++ .../scopes/functions/fnc_inventoryCheck.sqf | 39 +++++++++++- addons/scopes/stringtable.xml | 48 +++++++++++++++ 18 files changed, 304 insertions(+), 44 deletions(-) create mode 100644 addons/scopes/ACE_Settings.hpp create mode 100644 addons/scopes/functions/fnc_getCurrentZeroRange.sqf create mode 100644 addons/scopes/functions/fnc_initModuleSettings.sqf diff --git a/addons/rangecard/XEH_postInit.sqf b/addons/rangecard/XEH_postInit.sqf index 8396d76b39..55005fd0a8 100644 --- a/addons/rangecard/XEH_postInit.sqf +++ b/addons/rangecard/XEH_postInit.sqf @@ -6,10 +6,12 @@ GVAR(RangeCardOpened) = false; GVAR(controls) = []; +GVAR(zeroRange) = 100; GVAR(ammoClass) = "B_65x39_Caseless"; GVAR(magazineClass) = "30Rnd_65x39_caseless_mag"; GVAR(weaponClass) = "arifle_MXM_F"; +GVAR(zeroRangeCopy) = 100; GVAR(ammoClassCopy) = "";//"ACE_762x51_Ball_M118LR"; GVAR(magazineClassCopy) = "";//"ACE_20Rnd_762x51_M118LR_Mag"; GVAR(weaponClassCopy) = "";//srifle_DMR_06_olive_F"; diff --git a/addons/rangecard/config.cpp b/addons/rangecard/config.cpp index 9017583606..f300fb1a30 100644 --- a/addons/rangecard/config.cpp +++ b/addons/rangecard/config.cpp @@ -6,7 +6,7 @@ class CfgPatches { units[] = {"ACE_Item_RangeCard"}; weapons[] = {"ACE_RangeCard"}; requiredVersion = REQUIRED_VERSION; - requiredAddons[] = {"ACE_Advanced_Ballistics"}; + requiredAddons[] = {"ACE_Advanced_Ballistics","ace_scopes"}; author = ECSTRING(common,ACETeam); authors[] = {"Ruthberg"}; url = ECSTRING(main,URL); diff --git a/addons/rangecard/functions/fnc_openRangeCard.sqf b/addons/rangecard/functions/fnc_openRangeCard.sqf index ea085ed5b1..e73cdebd2a 100644 --- a/addons/rangecard/functions/fnc_openRangeCard.sqf +++ b/addons/rangecard/functions/fnc_openRangeCard.sqf @@ -23,7 +23,7 @@ if (_this) then { createDialog "ACE_RangeCard_Dialog"; - [GVAR(ammoClassCopy), GVAR(magazineClassCopy), GVAR(weaponClassCopy)] call FUNC(updateRangeCard); + [GVAR(zeroRangeCopy), GVAR(ammoClassCopy), GVAR(magazineClassCopy), GVAR(weaponClassCopy)] call FUNC(updateRangeCard); }; } else { if (ACE_player call FUNC(updateClassNames)) then { @@ -31,6 +31,6 @@ if (_this) then { createDialog "ACE_RangeCard_Dialog"; - [GVAR(ammoClass), GVAR(magazineClass), GVAR(weaponClass)] call FUNC(updateRangeCard); + [GVAR(zeroRange), GVAR(ammoClass), GVAR(magazineClass), GVAR(weaponClass)] call FUNC(updateRangeCard); }; }; diff --git a/addons/rangecard/functions/fnc_updateClassNames.sqf b/addons/rangecard/functions/fnc_updateClassNames.sqf index 70cf25825e..be9256650a 100644 --- a/addons/rangecard/functions/fnc_updateClassNames.sqf +++ b/addons/rangecard/functions/fnc_updateClassNames.sqf @@ -37,10 +37,12 @@ if (_weaponClass == "") exitWith { (GVAR(ammoClass) != "" && GVAR(magazineClass) if (_ammoClass == "") exitWith { (GVAR(ammoClass) != "" && GVAR(magazineClass) != "" && GVAR(weaponClass) != "") }; if (_unit == ACE_player) then { + GVAR(zeroRange) = [_unit] call EFUNC(scopes,getCurrentZeroRange); GVAR(ammoClass) = _ammoClass; GVAR(magazineClass) = _magazineClass; GVAR(weaponClass) = _weaponClass; } else { + GVAR(zeroRangeCopy) = [_unit] call EFUNC(scopes,getCurrentZeroRange); GVAR(ammoClassCopy) = _ammoClass; GVAR(magazineClassCopy) = _magazineClass; GVAR(weaponClassCopy) = _weaponClass; diff --git a/addons/rangecard/functions/fnc_updateRangeCard.sqf b/addons/rangecard/functions/fnc_updateRangeCard.sqf index 2febb7b8ff..37d738648d 100644 --- a/addons/rangecard/functions/fnc_updateRangeCard.sqf +++ b/addons/rangecard/functions/fnc_updateRangeCard.sqf @@ -3,9 +3,10 @@ * Updates the range card data * * Arguments: - * 0: ammo class - * 1: magazine class - * 2: weapon class + * 0: zero range + * 1: ammo class + * 2: magazine class + * 3: weapon class * * Return Value: * Nothing @@ -20,10 +21,9 @@ disableSerialization; #define __dsp (uiNamespace getVariable "RangleCard_Display") -private ["_airFriction", "_ammoConfig", "_atmosphereModel", "_barometricPressure", "_barrelLength", "_barrelTwist", "_bc", "_bulletMass", "_boreHeight", "_cacheEntry", "_column", "_control", "_dragModel", "_i", "_muzzleVelocity", "_offset", "_relativeHumidity", "_result", "_row", "_weaponConfig", "_zeroRange", "_initSpeed", "_initSpeedCoef", "_useABConfig"]; -_useABConfig = (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]); +private ["_airFriction", "_ammoConfig", "_atmosphereModel", "_barrelLength", "_barrelTwist", "_bc", "_boreHeight", "_cacheEntry", "_column", "_control", "_dragModel", "_i", "_muzzleVelocity", "_offset", "_row", "_weaponConfig", "_initSpeed", "_initSpeedCoef"]; -PARAMS_3(_ammoClass,_magazineClass,_weaponClass); +params ["_zeroRange", "_ammoClass", "_magazineClass", "_weaponClass"]; if (_ammoClass == "" || _magazineClass == "" || _weaponClass == "") exitWith {}; @@ -105,10 +105,9 @@ if (count (_ammoConfig select 6) > 0) then { }; _dragModel = _ammoConfig select 5; _atmosphereModel = _ammoConfig select 8; -_bulletMass = 5; _boreHeight = 3.81; -_zeroRange = 100; +private _useABConfig = (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]); if (_bc == 0) then { _useABConfig = false; }; @@ -147,25 +146,21 @@ if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) t lnbAddRow [770300, ["-15°C", " 10°C", " 35°C", "-15°C", " 10°C", " 35°C"]]; }; -_barometricPressure = 1013.25; -if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { - _barometricPressure = 1013.25 * (1 - (0.0065 * EGVAR(common,mapAltitude)) / 288.15) ^ 5.255754495; -}; -_relativeHumidity = 0.5; +ctrlSetText [77003, format["%1m ZERO", round(_zeroRange)]]; if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { - ctrlSetText [770001, format["Drop Tables for B.P.: %1mb; Corrected for MVV at Air/Ammo Temperatures -15-35 °C", round(_barometricPressure * 100) / 100]]; - ctrlSetText [77004 , format["B.P.: %1mb", round(_barometricPressure * 100) / 100]]; + ctrlSetText [770001, format["Drop Tables for B.P.: %1mb; Corrected for MVV at Air/Ammo Temperatures -15-35 °C", round(EGVAR(scopes,zeroReferenceBarometricPressure) * 100) / 100]]; + ctrlSetText [77004 , format["B.P.: %1mb", round(EGVAR(scopes,zeroReferenceBarometricPressure) * 100) / 100]]; } else { ctrlSetText [770001, ""]; ctrlSetText [77004 , ""]; }; -_cacheEntry = missionNamespace getVariable format[QGVAR(%1_%2_%3), _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]]; +_cacheEntry = missionNamespace getVariable format[QGVAR(%1_%2_%3_%4), _zeroRange, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]]; if (isNil {_cacheEntry}) then { private _scopeBaseAngle = 0; { - private _offset = [_scopeBaseAngle, 100, _muzzleVelocity, _airFriction, 1000, _boreHeight, 15, 1013.25, 0.5, _bc, _dragModel, _atmosphereModel, _useABConfig] call EFUNC(scopes,calculateZeroAngle); + private _offset = [_scopeBaseAngle, _zeroRange, _muzzleVelocity, _airFriction, 1000, _boreHeight, EGVAR(scopes,zeroReferenceTemperature), EGVAR(scopes,zeroReferenceBarometricPressure), EGVAR(scopes,zeroReferenceHumidity), _bc, _dragModel, _atmosphereModel, _useABConfig] call EFUNC(scopes,calculateZeroAngle); _scopeBaseAngle = _scopeBaseAngle + _offset; if (_offset < 0.01) exitWith {}; } forEach [1, 2, 3]; @@ -174,10 +169,10 @@ if (isNil {_cacheEntry}) then { private _mvShift = [_ammoConfig select 9, _x] call EFUNC(advanced_ballistics,calculateAmmoTemperatureVelocityShift); private _mv = _muzzleVelocity + _mvShift; - [_scopeBaseAngle,_bulletMass,_boreHeight,_airFriction,_mv,_x,_barometricPressure,_relativeHumidity,1000,[4,0],3,0,1,GVAR(rangeCardEndRange),_bc,_dragModel,_atmosphereModel,true,1.5,1,46,23,_forEachIndex,_useABConfig] call FUNC(calculateSolution); + [_scopeBaseAngle,0,_boreHeight,_airFriction,_mv,_x,EGVAR(scopes,zeroReferenceBarometricPressure),EGVAR(scopes,zeroReferenceHumidity),1000,[4,0],3,0,1,GVAR(rangeCardEndRange),_bc,_dragModel,_atmosphereModel,true,1.5,1,46,23,_forEachIndex,_useABConfig] call FUNC(calculateSolution); } forEach [-15, -5, 5, 10, 15, 20, 25, 30, 35]; } else { - [_scopeBaseAngle,_bulletMass,_boreHeight,_airFriction,_muzzleVelocity,15,_barometricPressure,_relativeHumidity,1000,[4,0],3,0,1,GVAR(rangeCardEndRange),_bc,_dragModel,_atmosphereModel,true,1.5,1,46,23,4,_useABConfig] call FUNC(calculateSolution); + [_scopeBaseAngle,0,_boreHeight,_airFriction,_muzzleVelocity,15,EGVAR(scopes,zeroReferenceBarometricPressure),EGVAR(scopes,zeroReferenceHumidity),1000,[4,0],3,0,1,GVAR(rangeCardEndRange),_bc,_dragModel,_atmosphereModel,true,1.5,1,46,23,4,_useABConfig] call FUNC(calculateSolution); }; for "_i" from 0 to 9 do { @@ -195,7 +190,7 @@ if (isNil {_cacheEntry}) then { }; }; - missionNamespace setVariable [format[QGVAR(%1_%2_%3), _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]], [GVAR(rangeCardDataElevation), GVAR(rangeCardDataWindage), GVAR(rangeCardDataLead), GVAR(rangeCardDataMVs), GVAR(lastValidRow)]]; + missionNamespace setVariable [format[QGVAR(%1_%2_%3_%4), _zeroRange, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]], [GVAR(rangeCardDataElevation), GVAR(rangeCardDataWindage), GVAR(rangeCardDataLead), GVAR(rangeCardDataMVs), GVAR(lastValidRow)]]; } else { GVAR(rangeCardDataElevation) = _cacheEntry select 0; GVAR(rangeCardDataWindage) = _cacheEntry select 1; diff --git a/addons/scopes/ACE_Settings.hpp b/addons/scopes/ACE_Settings.hpp new file mode 100644 index 0000000000..faf3f25836 --- /dev/null +++ b/addons/scopes/ACE_Settings.hpp @@ -0,0 +1,48 @@ +class ACE_Settings { + class GVAR(enabled) { + typeName = "BOOL"; + value = 1; + displayName = CSTRING(enabled_displayName); + description = CSTRING(enabled_description); + }; + // ACE_ScopeAdjust_Vertical and ACE_ScopeAdjust_Horizontal will be populated with default values instead of [0,0] + class GVAR(forceUseOfAdjustmentTurrets) { + typeName = "BOOL"; + value = 0; + displayName = CSTRING(forceUseOfAdjustmentTurrets_displayName); + description = CSTRING(forceUseOfAdjustmentTurrets_description); + }; + // Only affects scopes with elevation adjustment turrets (ACE_ScopeAdjust_Vertical != [0,0]) + class GVAR(defaultZeroRange) { + typeName = "SCALAR"; + value = 100; + displayName = CSTRING(defaultZeroRange_displayName); + description = CSTRING(defaultZeroRange_description); + }; + + // Only relevant when advanced ballistics is enabled + class GVAR(zeroReferenceTemperature) { + typeName = "SCALAR"; + value = 15; + displayName = CSTRING(zeroReferenceTemperature_displayName); + description = CSTRING(zeroReferenceTemperature_description); + }; + class GVAR(zeroReferenceBarometricPressure) { + typeName = "SCALAR"; + value = 1013.25; + displayName = CSTRING(zeroReferenceBarometricPressure_displayName); + description = CSTRING(zeroReferenceBarometricPressure_description); + }; + class GVAR(zeroReferenceHumidity) { + typeName = "SCALAR"; + value = 0.5; + displayName = CSTRING(zeroReferenceHumidity_displayName); + description = CSTRING(zeroReferenceHumidity_description); + }; + class GVAR(deduceBarometricPressureFromTerrainAltitude) { + typeName = "BOOL"; + value = 0; + displayName = CSTRING(deduceBarometricPressureFromTerrainAltitude_displayName); + description = CSTRING(deduceBarometricPressureFromTerrainAltitude_description); + }; +}; diff --git a/addons/scopes/CfgVehicles.hpp b/addons/scopes/CfgVehicles.hpp index 8a17384933..6cb40dd59e 100644 --- a/addons/scopes/CfgVehicles.hpp +++ b/addons/scopes/CfgVehicles.hpp @@ -16,4 +16,63 @@ class CfgVehicles { }; }; }; + class ACE_Module; + class GVAR(ModuleSettings): ACE_Module { + scope = 2; + displayName = CSTRING(DisplayName); + //icon = ""; // needs an icon + category = "ACE"; + function = QUOTE(DFUNC(initModuleSettings)); + functionPriority = 1; + isGlobal = 1; + isTriggerActivated = 0; + author = ECSTRING(common,ACETeam); + class Arguments { + class enabled { + displayName = CSTRING(enabled_DisplayName); + description = CSTRING(enabled_Description); + typeName = "BOOL"; + defaultValue = 1; + }; + class forceUseOfAdjustmentTurrets { + displayName = CSTRING(forceUseOfAdjustmentTurrets_DisplayName); + description = CSTRING(forceUseOfAdjustmentTurrets_Description); + typeName = "BOOL"; + defaultValue = 0; + }; + class defaultZeroRange { + displayName = CSTRING(defaultZeroRange_DisplayName); + description = CSTRING(defaultZeroRange_Description); + typeName = "NUMBER"; + defaultValue = 100; + }; + class zeroReferenceTemperature { + displayName = CSTRING(zeroReferenceTemperature_DisplayName); + description = CSTRING(zeroReferenceTemperature_Description); + typeName = "NUMBER"; + defaultValue = 15; + }; + class zeroReferenceBarometricPressure { + displayName = CSTRING(zeroReferenceBarometricPressure_DisplayName); + description = CSTRING(zeroReferenceBarometricPressure_Description); + typeName = "NUMBER"; + defaultValue = 1013.25; + }; + class zeroReferenceHumidity { + displayName = CSTRING(zeroReferenceHumidity_DisplayName); + description = CSTRING(zeroReferenceHumidity_Description); + typeName = "NUMBER"; + defaultValue = 0.5; + }; + class deduceBarometricPressureFromTerrainAltitude { + displayName = CSTRING(deduceBarometricPressureFromTerrainAltitude_DisplayName); + description = CSTRING(deduceBarometricPressureFromTerrainAltitude_Description); + typeName = "BOOL"; + defaultValue = 0; + }; + }; + class ModuleDescription { + description = CSTRING(Description); + }; + }; }; diff --git a/addons/scopes/CfgWeapons.hpp b/addons/scopes/CfgWeapons.hpp index 5698398ade..72ce987f4c 100644 --- a/addons/scopes/CfgWeapons.hpp +++ b/addons/scopes/CfgWeapons.hpp @@ -56,6 +56,8 @@ class CfgWeapons { class optic_NVS : ItemCore { ACE_ScopeHeightAboveRail = 4.2; + ACE_ScopeAdjust_Vertical[] = {0, 0}; + ACE_ScopeAdjust_Horizontal[] = {0, 0}; }; class optic_TWS : ItemCore { diff --git a/addons/scopes/XEH_PREP.hpp b/addons/scopes/XEH_PREP.hpp index 80ef9b5b5e..7bfcf34268 100644 --- a/addons/scopes/XEH_PREP.hpp +++ b/addons/scopes/XEH_PREP.hpp @@ -6,6 +6,8 @@ PREP(calculateZeroAngle); PREP(calculateZeroAngleCorrection); PREP(canAdjustZero); PREP(firedEH); +PREP(getCurrentZeroRange); PREP(getOptics); +PREP(initModuleSettings); PREP(inventoryCheck); PREP(showZeroing); diff --git a/addons/scopes/XEH_postInit.sqf b/addons/scopes/XEH_postInit.sqf index 7b36617a18..5e04faefba 100644 --- a/addons/scopes/XEH_postInit.sqf +++ b/addons/scopes/XEH_postInit.sqf @@ -10,6 +10,9 @@ if (!hasInterface) exitWith {}; GVAR(Optics) = ["", "", ""]; +GVAR(canAdjustElevation) = [false, false, false]; +GVAR(canAdjustWindage) = [false, false, false]; +GVAR(scopeAdjust) = [[[0,0],0,[0,0],0], [[0,0],0,[0,0],0], [[0,0],0,[0,0],0]]; // Check inventory when it changes ["loadout", FUNC(inventoryCheck)] call CBA_fnc_addPlayerEventHandler; diff --git a/addons/scopes/config.cpp b/addons/scopes/config.cpp index 8388b2d04b..85c870b97c 100644 --- a/addons/scopes/config.cpp +++ b/addons/scopes/config.cpp @@ -8,7 +8,7 @@ class CfgPatches { requiredVersion = REQUIRED_VERSION; requiredAddons[] = { "ace_common" }; author = ECSTRING(common,ACETeam); - authors[] = {"KoffeinFlummi", "esteldunedain"}; + authors[] = {"KoffeinFlummi", "esteldunedain", "Ruthberg"}; url = ECSTRING(main,URL); VERSION_CONFIG; }; @@ -19,3 +19,4 @@ class CfgPatches { #include "CfgVehicles.hpp" #include "CfgWeapons.hpp" #include "RscTitles.hpp" +#include "ACE_Settings.hpp" diff --git a/addons/scopes/functions/fnc_adjustScope.sqf b/addons/scopes/functions/fnc_adjustScope.sqf index 825b68805b..c0a9fb3fdc 100644 --- a/addons/scopes/functions/fnc_adjustScope.sqf +++ b/addons/scopes/functions/fnc_adjustScope.sqf @@ -23,6 +23,7 @@ params ["_unit", "_turretAndDirection", "_majorStep"]; if (!(_unit isKindOf "Man")) exitWith {false}; if (currentMuzzle _unit != currentWeapon _unit) exitWith {false}; +if (!GVAR(enabled)) exitWith {false}; _weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex); if (_weaponIndex < 0) exitWith {false}; @@ -32,20 +33,14 @@ if (isNil "_adjustment") then { _adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]; // [Windage, Elevation, Zero] }; -_optic = GVAR(Optics) select _weaponIndex; -_opticConfig = configFile >> "CfgWeapons" >> _optic; -_verticalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_VerticalIncrement"); -_horizontalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_HorizontalIncrement"); -_maxVertical = getArray (_opticConfig >> "ACE_ScopeAdjust_Vertical"); -_maxHorizontal = getArray (_opticConfig >> "ACE_ScopeAdjust_Horizontal"); - -if ((count _maxHorizontal < 2) || (count _maxVertical < 2)) exitWith {false}; -if ((_verticalIncrement == 0) && (_turretAndDirection in [ELEVATION_UP, ELEVATION_DOWN])) exitWith {false}; -if ((_horizontalIncrement == 0) && (_turretAndDirection in [WINDAGE_UP, WINDAGE_DOWN])) exitWith {false}; +if (!(GVAR(canAdjustElevation) select _weaponIndex) && (_turretAndDirection in [ELEVATION_UP, ELEVATION_DOWN])) exitWith {false}; +if (!(GVAR(canAdjustWindage) select _weaponIndex) && (_turretAndDirection in [WINDAGE_UP, WINDAGE_DOWN])) exitWith {false}; _zeroing = _adjustment select _weaponIndex; _zeroing params ["_elevation", "_windage", "_zero"]; +(GVAR(scopeAdjust) select _weaponIndex) params ["_maxVertical", "_verticalIncrement", "_maxHorizontal", "_horizontalIncrement"]; + switch (_turretAndDirection) do { case ELEVATION_UP: { _elevation = _elevation + _verticalIncrement }; case ELEVATION_DOWN: { _elevation = _elevation - _verticalIncrement }; diff --git a/addons/scopes/functions/fnc_calculateZeroAngleCorrection.sqf b/addons/scopes/functions/fnc_calculateZeroAngleCorrection.sqf index d9229e9301..59984a57ae 100644 --- a/addons/scopes/functions/fnc_calculateZeroAngleCorrection.sqf +++ b/addons/scopes/functions/fnc_calculateZeroAngleCorrection.sqf @@ -47,11 +47,6 @@ private _vanillaZero = 0; // in degrees if (_offset < 0.01) exitWith {}; } forEach [1, 2, 3]; -// Standard atmosphere (optionally overwrite with ace setting) -private _temperature = 15; -private _barometricPressure = 1013.25; -private _relativeHumidity = 0.5; - if (_advancedBallistics) then { if (missionNamespace getVariable [QEGVAR(advanced_ballistics,barrelLengthInfluenceEnabled), false]) then { private _barrelVelocityShift = [_barrelLength, _muzzleVelocityTable, _barrelLengthTable, _initSpeed] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift); @@ -60,8 +55,8 @@ if (_advancedBallistics) then { }; private _zeroAngle = 0; // in degrees -{ - private _offset = [_zeroAngle, _newZeroRange, _initSpeed, _airFriction, 1000, _boreHeight, _temperature, _barometricPressure, _relativeHumidity, _ballisticCoefficients select 0, _dragModel, _atmosphereModel, _advancedBallistics] call FUNC(calculateZeroAngle); +{ + private _offset = [_zeroAngle, _newZeroRange, _initSpeed, _airFriction, 1000, _boreHeight, GVAR(zeroReferenceTemperature), GVAR(zeroReferenceBarometricPressure), GVAR(zeroReferenceHumidity), _ballisticCoefficients select 0, _dragModel, _atmosphereModel, _advancedBallistics] call FUNC(calculateZeroAngle); _zeroAngle = _zeroAngle + _offset; if (_offset < 0.01) exitWith {}; } forEach [1, 2, 3]; diff --git a/addons/scopes/functions/fnc_firedEH.sqf b/addons/scopes/functions/fnc_firedEH.sqf index 9553668946..7baf19c948 100644 --- a/addons/scopes/functions/fnc_firedEH.sqf +++ b/addons/scopes/functions/fnc_firedEH.sqf @@ -1,5 +1,5 @@ /* - * Author: KoffeinFlummi, esteldunedain + * Author: KoffeinFlummi, esteldunedain, Ruthberg * Adjusts the flight path of the bullet according to the zeroing. Called from the unified fired EH only for local and non-local players on foot. * * Arguments: @@ -60,7 +60,7 @@ if (_ammo isKindOf "BulletBase") then { private _advancedBallistics = missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]; private _boreHeight = _railHeightAboveBore + _scopeHeightAboveRail; private _oldZeroRange = currentZeroing _unit; - private _newZeroRange = _oldZeroRange; // Change this if you want to overwrite the discreteDistance[] setting + private _newZeroRange = [_unit] call FUNC(getCurrentZeroRange); private _zeroCorrection = missionNamespace getVariable format[QGVAR(%1_%2_%3_%4_%5_%6_%7), _oldZeroRange, _newZeroRange, _boreHeight, _weapon, _ammo, _magazine, _advancedBallistics]; if (isNil "_zeroCorrection") then { _zeroCorrection = [_oldZeroRange, _newZeroRange, _boreHeight, _weapon, _ammo, _magazine, _advancedBallistics] call FUNC(calculateZeroAngleCorrection); diff --git a/addons/scopes/functions/fnc_getCurrentZeroRange.sqf b/addons/scopes/functions/fnc_getCurrentZeroRange.sqf new file mode 100644 index 0000000000..9c51bc26cf --- /dev/null +++ b/addons/scopes/functions/fnc_getCurrentZeroRange.sqf @@ -0,0 +1,35 @@ +/* + * Author: Ruthberg + * Gets the zero range of the currently used optic + * + * Arguments: + * 0: Unit + * + * Return Value: + * current zero range + * + * Example: + * _unit call ace_scopes_fnc_getCurrentZeroRange + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; + +private _weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex); +if (_weaponIndex < 0) exitWith { 0 }; + +private _optic = GVAR(Optics) select _weaponIndex; +private _opticConfig = configFile >> "CfgWeapons" >> _optic; +private _opticType = getNumber(_opticConfig >> "ItemInfo" >> "opticType"); + +private _zeroRange = currentZeroing _unit; +if (_opticType == 2 && {(GVAR(canAdjustElevation) select _weaponIndex) || GVAR(forceUseOfAdjustmentTurrets)}) then { + _zeroRange = GVAR(defaultZeroRange); +}; +if (isNumber (_opticConfig >> "ACE_ScopeZeroRange")) then { + _zeroRange = getNumber(_opticConfig >> "ACE_ScopeZeroRange"); +}; + +_zeroRange diff --git a/addons/scopes/functions/fnc_initModuleSettings.sqf b/addons/scopes/functions/fnc_initModuleSettings.sqf new file mode 100644 index 0000000000..5435e1f0d2 --- /dev/null +++ b/addons/scopes/functions/fnc_initModuleSettings.sqf @@ -0,0 +1,36 @@ +/* + * Author: Glowbal, Ruthberg + * Module for adjusting the scopes settings + * + * Arguments: + * 0: The module logic + * 1: units + * 2: activated + * + * Return Value: + * None + * + * Public: No + */ +#include "script_component.hpp" + +params ["_logic","_units", "_activated"]; + +if !(_activated) exitWith {}; + +[_logic, QGVAR(enabled), "enabled"] call EFUNC(common,readSettingFromModule); +[_logic, QGVAR(forceUseOfAdjustmentTurrets), "forceUseOfAdjustmentTurrets"] call EFUNC(common,readSettingFromModule); +[_logic, QGVAR(defaultZeroRange), "defaultZeroRange"] call EFUNC(common,readSettingFromModule); +[_logic, QGVAR(zeroReferenceTemperature), "zeroReferenceTemperature"] call EFUNC(common,readSettingFromModule); +[_logic, QGVAR(zeroReferenceBarometricPressure), "zeroReferenceBarometricPressure"] call EFUNC(common,readSettingFromModule); +[_logic, QGVAR(zeroReferenceHumidity), "zeroReferenceHumidity"] call EFUNC(common,readSettingFromModule); +[_logic, QGVAR(deduceBarometricPressureFromTerrainAltitude), "deduceBarometricPressureFromTerrainAltitude"] call EFUNC(common,readSettingFromModule); + +GVAR(defaultZeroRange) = 0 max GVAR(defaultZeroRange) min 1000; +GVAR(zeroReferenceTemperature) = -55 max GVAR(zeroReferenceTemperature) max 55; +GVAR(zeroReferenceBarometricPressure) = 0 max GVAR(zeroReferenceBarometricPressure) min 1013.25; +GVAR(zeroReferenceHumidity) = 0 max GVAR(zeroReferenceHumidity) min 1.0; + +if (GVAR(deduceBarometricPressureFromTerrainAltitude)) then { + GVAR(zeroReferenceBarometricPressure) = 1013.25 * (1 - (0.0065 * EGVAR(common,mapAltitude)) / 288.15) ^ 5.255754495; +}; diff --git a/addons/scopes/functions/fnc_inventoryCheck.sqf b/addons/scopes/functions/fnc_inventoryCheck.sqf index 674a7a7f42..8ec8e50123 100644 --- a/addons/scopes/functions/fnc_inventoryCheck.sqf +++ b/addons/scopes/functions/fnc_inventoryCheck.sqf @@ -1,5 +1,5 @@ /* - * Author: KoffeinFlummi, Commy2 + * Author: KoffeinFlummi, Commy2, Ruthberg * Check if weapon optics changed and reset zeroing if needed * * Arguments: @@ -34,6 +34,43 @@ private _newOptics = [_player] call FUNC(getOptics); _adjustment set [_forEachIndex, [0, 0, 0]]; [ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic); }; + private _opticConfig = configFile >> "CfgWeapons" >> (_newOptics select _forEachIndex); + private _verticalIncrement = -1; + if (isNumber (_opticConfig >> "ACE_ScopeAdjust_VerticalIncrement")) then { + _verticalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_VerticalIncrement"); + }; + private _horizontalIncrement = -1; + if (isNumber (_opticConfig >> "ACE_ScopeAdjust_HorizontalIncrement")) then { + _horizontalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_HorizontalIncrement"); + }; + private _maxVertical = []; + if (isArray (_opticConfig >> "ACE_ScopeAdjust_Vertical")) then { + _maxVertical = getArray (_opticConfig >> "ACE_ScopeAdjust_Vertical"); + }; + private _maxHorizontal = []; + if (isArray (_opticConfig >> "ACE_ScopeAdjust_Horizontal")) then { + _maxHorizontal = getArray (_opticConfig >> "ACE_ScopeAdjust_Horizontal"); + }; + if (GVAR(forceUseOfAdjustmentTurrets)) then { + if (_maxVertical isEqualTo []) then { _maxVertical = [-4, 30]; }; + if (_maxHorizontal isEqualTo []) then { _maxHorizontal = [-6, 6]; }; + if (_verticalIncrement == -1) then { _verticalIncrement = 0.1; }; + if (_horizontalIncrement == -1) then { _horizontalIncrement = 0.1; }; + } else { + if (_maxVertical isEqualTo []) then { _maxVertical = [0, 0]; }; + if (_maxHorizontal isEqualTo []) then { _maxHorizontal = [0, 0]; }; + if (_verticalIncrement == -1) then { _verticalIncrement = 0; }; + if (_horizontalIncrement == -1) then { _horizontalIncrement = 0; }; + }; + (GVAR(scopeAdjust) select _forEachIndex) set [0, _maxVertical]; + (GVAR(scopeAdjust) select _forEachIndex) set [1, _verticalIncrement]; + (GVAR(scopeAdjust) select _forEachIndex) set [2, _maxHorizontal]; + (GVAR(scopeAdjust) select _forEachIndex) set [3, _horizontalIncrement]; + GVAR(canAdjustElevation) set [_forEachIndex, (_verticalIncrement > 0) && !(_maxVertical isEqualTo [0, 0])]; + GVAR(canAdjustWindage) set [_forEachIndex, (_horizontalIncrement > 0) && !(_maxHorizontal isEqualTo [0, 0])]; + // Does not work reliably + //private _hideVanillaZeroing = (getNumber(_opticConfig >> "ItemInfo" >> "opticType") == 2 && (GVAR(canAdjustElevation) select _forEachIndex)) || {isNumber (_opticConfig >> "ACE_ScopeZeroRange")}; + //private _result = ["zeroing", !_hideVanillaZeroing, false] call EFUNC(ui,setAdvancedElement); }; } forEach GVAR(Optics); diff --git a/addons/scopes/stringtable.xml b/addons/scopes/stringtable.xml index 33a9e8beef..7da8c971a0 100644 --- a/addons/scopes/stringtable.xml +++ b/addons/scopes/stringtable.xml @@ -1,6 +1,51 @@  + + Scopes + + + Enable ACE Scope adjustment + + + Enable adjustmet turrets on high powered scopes + + + Force adjustment turrets + + + Force usage of adjustmet turrets on high powered scopes + + + Default zero distance + + + High power scopes will be zeroed at this distance + + + Reference temperature + + + Temperature at which the scope was zeroed + + + Reference barometric pressure + + + Barometric pressure at which the scope was zeroed + + + Reference humidity + + + Humidity at which the scope was zeroed + + + Deduce pressure from altitude + + + Deduce the barometric pressure from the terrain altitude + Minor adjustment up Zerowanie powoli w górę @@ -118,5 +163,8 @@ Vynulovat korekci ゼロインを調節 + + This module adds windage and elevation adjustment turrets on high power rifle scopes. + \ No newline at end of file