RangeCard - Take bore height into account (#4715)

This commit is contained in:
ulteq 2016-12-01 21:20:51 +01:00 committed by GitHub
parent 3566e6e7f5
commit 3e0f85b4f1
9 changed files with 78 additions and 43 deletions

View File

@ -34,7 +34,7 @@ class CfgVehicles {
class GVAR(makeCopy) {
displayName = CSTRING(CopyRangeCard);
condition = QUOTE(call FUNC(canShow) && !GVAR(RangeCardOpened));
statement = QUOTE(GVAR(ammoClassCopy) = GVAR(ammoClass); GVAR(magazineClassCopy) = GVAR(magazineClass); GVAR(weaponClassCopy) = GVAR(ammoClass););
statement = QUOTE(GVAR(zeroRangeCopy)=GVAR(zeroRange); GVAR(boreHeightCopy)=GVAR(boreHeight); GVAR(ammoClassCopy)=GVAR(ammoClass); GVAR(magazineClassCopy)=GVAR(magazineClass); GVAR(weaponClassCopy)=GVAR(weaponClass););
showDisabled = 0;
priority = 0.1;
icon = QPATHTOF(UI\RangeCard_Icon.paa);

View File

@ -7,11 +7,13 @@ GVAR(RangeCardOpened) = false;
GVAR(controls) = [];
GVAR(zeroRange) = 100;
GVAR(boreHeight) = 3.81;
GVAR(ammoClass) = "B_65x39_Caseless";
GVAR(magazineClass) = "30Rnd_65x39_caseless_mag";
GVAR(weaponClass) = "arifle_MXM_F";
GVAR(zeroRangeCopy) = 100;
GVAR(boreHeightCopy) = 3.81;
GVAR(ammoClassCopy) = "";//"ACE_762x51_Ball_M118LR";
GVAR(magazineClassCopy) = "";//"ACE_20Rnd_762x51_M118LR_Mag";
GVAR(weaponClassCopy) = "";//srifle_DMR_06_olive_F";

View File

@ -23,7 +23,7 @@ if (_this) then {
createDialog "ACE_RangeCard_Dialog";
[GVAR(zeroRangeCopy), GVAR(ammoClassCopy), GVAR(magazineClassCopy), GVAR(weaponClassCopy)] call FUNC(updateRangeCard);
[GVAR(zeroRangeCopy), GVAR(boreHeightCopy), 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(zeroRange), GVAR(ammoClass), GVAR(magazineClass), GVAR(weaponClass)] call FUNC(updateRangeCard);
[GVAR(zeroRange), GVAR(boreHeight), GVAR(ammoClass), GVAR(magazineClass), GVAR(weaponClass)] call FUNC(updateRangeCard);
};
};

View File

@ -38,11 +38,13 @@ if (_ammoClass == "") exitWith { (GVAR(ammoClass) != "" && GVAR(magazineClass) !
if (_unit == ACE_player) then {
GVAR(zeroRange) = [_unit] call EFUNC(scopes,getCurrentZeroRange);
GVAR(boreHeight) = [_unit, 0] call EFUNC(scopes,getBoreHeight);
GVAR(ammoClass) = _ammoClass;
GVAR(magazineClass) = _magazineClass;
GVAR(weaponClass) = _weaponClass;
} else {
GVAR(zeroRangeCopy) = [_unit] call EFUNC(scopes,getCurrentZeroRange);
GVAR(boreHeightCopy) = [_unit, 0] call EFUNC(scopes,getBoreHeight);
GVAR(ammoClassCopy) = _ammoClass;
GVAR(magazineClassCopy) = _magazineClass;
GVAR(weaponClassCopy) = _weaponClass;

View File

@ -4,9 +4,10 @@
*
* Arguments:
* 0: zero range <NUMBER>
* 1: ammo class <STRING>
* 2: magazine class <STRING>
* 3: weapon class <STRING>
* 1: bore height <NUMBER>
* 2: ammo class <STRING>
* 3: magazine class <STRING>
* 4: weapon class <STRING>
*
* Return Value:
* Nothing
@ -21,9 +22,9 @@
disableSerialization;
#define __dsp (uiNamespace getVariable "RangleCard_Display")
private ["_airFriction", "_ammoConfig", "_atmosphereModel", "_transonicStabilityCoef", "_barrelLength", "_barrelTwist", "_bc", "_boreHeight", "_cacheEntry", "_column", "_control", "_dragModel", "_i", "_muzzleVelocity", "_offset", "_row", "_weaponConfig", "_initSpeed", "_initSpeedCoef"];
private ["_airFriction", "_ammoConfig", "_atmosphereModel", "_transonicStabilityCoef", "_barrelLength", "_barrelTwist", "_bc", "_cacheEntry", "_column", "_control", "_dragModel", "_i", "_muzzleVelocity", "_offset", "_row", "_weaponConfig", "_initSpeed", "_initSpeedCoef"];
params ["_zeroRange", "_ammoClass", "_magazineClass", "_weaponClass"];
params ["_zeroRange", "_boreHeight", "_ammoClass", "_magazineClass", "_weaponClass"];
if (_ammoClass == "" || _magazineClass == "" || _weaponClass == "") exitWith {};
@ -106,7 +107,6 @@ if (count (_ammoConfig select 6) > 0) then {
_transonicStabilityCoef = _ammoConfig select 4;
_dragModel = _ammoConfig select 5;
_atmosphereModel = _ammoConfig select 8;
_boreHeight = 3.81;
private _useABConfig = (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]);
if (_bc == 0) then {
@ -157,7 +157,7 @@ if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) t
ctrlSetText [77004 , ""];
};
_cacheEntry = missionNamespace getVariable format[QGVAR(%1_%2_%3_%4), _zeroRange, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]];
_cacheEntry = missionNamespace getVariable format[QGVAR(%1_%2_%3_%4_%5), _zeroRange, _boreHeight, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]];
if (isNil {_cacheEntry}) then {
private _scopeBaseAngle = if (!_useABConfig) then {
private _zeroAngle = "ace_advanced_ballistics" callExtension format ["zeroAngleVanilla:%1:%2:%3:%4", _zeroRange, _muzzleVelocity, _airFriction, _boreHeight];
@ -192,7 +192,7 @@ if (isNil {_cacheEntry}) then {
};
};
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)]];
missionNamespace setVariable [format[QGVAR(%1_%2_%3_%4_%5), _zeroRange, _boreHeight, _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;
@ -243,7 +243,7 @@ for "_column" from 0 to 8 do {
if (_useABConfig) then {
ctrlSetText [770020, "For best results keep ammunition at ambient air temperature. Tables calculated for the above listed barrel"];
ctrlSetText [770021, "and load with optic mounted 1.5'' above line of bore."];
ctrlSetText [770021, format["and load with optic mounted %1'' above line of bore.", round((_boreHeight / 2.54) * 10) / 10]];
} else {
ctrlSetText [770020, ""];
ctrlSetText [770021, ""];

View File

@ -5,6 +5,7 @@ PREP(applyScopeAdjustment);
PREP(calculateZeroAngleCorrection);
PREP(canAdjustZero);
PREP(firedEH);
PREP(getBoreHeight);
PREP(getCurrentZeroRange);
PREP(getOptics);
PREP(initModuleSettings);

View File

@ -0,0 +1,57 @@
/*
* Author: Ruthberg
* Gets the bore height of the weapon & optic combination with the given weapon index
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon index <NUMBER>
*
* Return Value:
* bore height <NUMBER>
*
* Example:
* [player] call ace_scopes_fnc_getBoreHeight
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_player", "_weaponIndex"];
if (_weaponIndex < 0 || {_weaponIndex > 2}) exitWith { 0 };
private _weaponClass = [primaryWeapon _player, secondaryWeapon _player, handgunWeapon _player] select _weaponIndex;
private _opticsClass = ([_player] call FUNC(getOptics)) select _weaponIndex;
if (_opticsClass == "") then { _opticsClass = _weaponClass; };
// Determine rail height above bore
private _railHeightAboveBore = 0;
private _weaponConfig = configFile >> "CfgWeapons" >> _weaponClass;
if (isNumber (_weaponConfig >> "ACE_RailHeightAboveBore")) then {
_railHeightAboveBore = getNumber(_weaponConfig >> "ACE_RailHeightAboveBore");
} else {
switch (_weaponIndex) do {
case 0: { _railHeightAboveBore = 2.0; }; // Rifle
case 2: { _railHeightAboveBore = 0.7; }; // Pistol
};
};
// Determine scope height above rail
private _scopeHeightAboveRail = 0;
private _opticConfig = configFile >> "CfgWeapons" >> _opticsClass;
if (isNumber (_opticConfig >> "ACE_ScopeHeightAboveRail")) then {
_scopeHeightAboveRail = getNumber(_opticConfig >> "ACE_ScopeHeightAboveRail");
} else {
switch (getNumber(_opticConfig >> "ItemInfo" >> "opticType")) do {
case 1: { _scopeHeightAboveRail = 3.0; }; // RCO or similar
case 2: { _scopeHeightAboveRail = 4.0; }; // High power scope
default {
switch (_weaponIndex) do {
case 0: { _scopeHeightAboveRail = 0.5; }; // Rifle iron sights
case 2: { _scopeHeightAboveRail = 0.3; }; // Pistol iron sights
};
};
};
};
(_railHeightAboveBore + _scopeHeightAboveRail)

View File

@ -6,10 +6,10 @@
* 0: Unit <OBJECT>
*
* Return Value:
* current zero range
* current zero range <NUMBER>
*
* Example:
* _unit call ace_scopes_fnc_getCurrentZeroRange
* [player] call ace_scopes_fnc_getCurrentZeroRange
*
* Public: No
*/

View File

@ -69,35 +69,8 @@ private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapo
_adjustment set [_forEachIndex, [0, 0, 0]];
_updateAdjustment = true;
};
// Determine rail height above bore
private _railHeightAboveBore = 0;
private _weaponConfig = configFile >> "CfgWeapons" >> (_newGuns select _x);
if (isNumber (_weaponConfig >> "ACE_RailHeightAboveBore")) then {
_railHeightAboveBore = getNumber(_weaponConfig >> "ACE_RailHeightAboveBore");
} else {
switch (_x) do {
case 0: { _railHeightAboveBore = 2.0; }; // Rifle
case 2: { _railHeightAboveBore = 0.7; }; // Pistol
};
};
// Determine scope height above rail
private _scopeHeightAboveRail = 0;
private _opticConfig = configFile >> "CfgWeapons" >> (_newOptics select _x);
if (isNumber (_opticConfig >> "ACE_ScopeHeightAboveRail")) then {
_scopeHeightAboveRail = getNumber(_opticConfig >> "ACE_ScopeHeightAboveRail");
} else {
switch (getNumber(_opticConfig >> "ItemInfo" >> "opticType")) do {
case 1: { _scopeHeightAboveRail = 3.0; }; // RCO or similar
case 2: { _scopeHeightAboveRail = 4.0; }; // High power scope
default {
switch (_x) do {
case 0: { _scopeHeightAboveRail = 0.5; }; // Rifle iron sights
case 2: { _scopeHeightAboveRail = 0.3; }; // Pistol iron sights
};
};
};
};
GVAR(boreHeight) set [_x, _railHeightAboveBore + _scopeHeightAboveRail];
GVAR(boreHeight) set [_x, [_player, _x] call FUNC(getBoreHeight)];
if ((_newOptics select _x) == "") then {
// Check if the weapon comes with an integrated optic