Feature - Vanilla zeroing fix

This commit is contained in:
ulteq 2016-11-07 12:01:36 +01:00 committed by ulteq
parent 21502d7b7b
commit 36c14c5dc4
9 changed files with 284 additions and 18 deletions

View File

@ -20,7 +20,7 @@
disableSerialization;
#define __dsp (uiNamespace getVariable "RangleCard_Display")
private ["_airFriction", "_ammoConfig", "_atmosphereModel", "_barometricPressure", "_barrelLength", "_barrelTwist", "_bc", "_bulletMass", "_boreHeight", "_cacheEntry", "_column", "_control", "_dragModel", "_i", "_muzzleVelocity", "_mv", "_mvShift", "_offset", "_relativeHumidity", "_result", "_row", "_scopeBaseAngle", "_weaponConfig", "_zeroRange", "_initSpeed", "_initSpeedCoef", "_useABConfig"];
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]);
PARAMS_3(_ammoClass,_magazineClass,_weaponClass);
@ -163,17 +163,21 @@ if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) t
_cacheEntry = missionNamespace getVariable format[QGVAR(%1_%2_%3), _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]];
if (isNil {_cacheEntry}) then {
_result = [0, 0, _boreHeight, _airFriction, _muzzleVelocity, 15, 1013.25, 0.5, 1000, [0, 0], 0, 0, 0, _zeroRange, _bc, _dragModel, _atmosphereModel, false, 1.5, 0, 0, 0, 0, _useABConfig] call FUNC(calculateSolution);
_scopeBaseAngle = (_result select 0) / 60;
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) 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);
_scopeBaseAngle = _scopeBaseAngle + _offset;
if (_offset < 0.01) exitWith {};
} forEach [1, 2, 3];
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false] && missionNamespace getVariable [QEGVAR(advanced_ballistics,ammoTemperatureEnabled), false]) then {
{
_mvShift = [_ammoConfig select 9, _x] call EFUNC(advanced_ballistics,calculateAmmoTemperatureVelocityShift);
_mv = _muzzleVelocity + _mvShift;
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);
} 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,3,_useABConfig] call FUNC(calculateSolution);
[_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);
};
for "_i" from 0 to 9 do {

View File

@ -1,8 +1,69 @@
class CfgWeapons {
class ItemCore;
class InventoryOpticsItem_Base_F;
class optic_Yorris : ItemCore {
ACE_ScopeHeightAboveRail = 0.4;
};
class optic_MRD : ItemCore {
ACE_ScopeHeightAboveRail = 0.6;
};
class optic_Aco : ItemCore {
ACE_ScopeHeightAboveRail = 1.8;
};
class optic_ACO_grn : ItemCore {
ACE_ScopeHeightAboveRail = 1.8;
};
class optic_ACO_grn_smg : ItemCore {
ACE_ScopeHeightAboveRail = 1.8;
};
class optic_ACO_smg : ItemCore {
ACE_ScopeHeightAboveRail = 1.8;
};
class optic_Holosight : ItemCore {
ACE_ScopeHeightAboveRail = 2.4;
};
class optic_Holosight_smg : ItemCore {
ACE_ScopeHeightAboveRail = 2.4;
};
class optic_Arco : ItemCore {
ACE_ScopeHeightAboveRail = 3.0;
};
class optic_ERCO_blk_F : optic_Arco {
ACE_ScopeHeightAboveRail = 2.6;
};
class optic_Hamr : ItemCore {
ACE_ScopeHeightAboveRail = 3.2;
};
class optic_MRCO : ItemCore {
ACE_ScopeHeightAboveRail = 2.5;
};
class optic_Nightstalker : ItemCore {
ACE_ScopeHeightAboveRail = 4.2;
};
class optic_NVS : ItemCore {
ACE_ScopeHeightAboveRail = 4.2;
};
class optic_TWS : ItemCore {
ACE_ScopeHeightAboveRail = 4.2;
};
class optic_LRPS : ItemCore {
ACE_ScopeHeightAboveRail = 4.0;
ACE_ScopeAdjust_Vertical[] = {-4, 30};
ACE_ScopeAdjust_Horizontal[] = {-6, 6};
ACE_ScopeAdjust_VerticalIncrement = 0.1;
@ -22,6 +83,7 @@ class CfgWeapons {
};
class optic_SOS : ItemCore {
ACE_ScopeHeightAboveRail = 3.8;
ACE_ScopeAdjust_Vertical[] = {-4, 30};
ACE_ScopeAdjust_Horizontal[] = {-6, 6};
ACE_ScopeAdjust_VerticalIncrement = 0.1;
@ -37,6 +99,7 @@ class CfgWeapons {
};
class optic_DMS : ItemCore {
ACE_ScopeHeightAboveRail = 3.6;
ACE_ScopeAdjust_Vertical[] = {-4, 20};
ACE_ScopeAdjust_Horizontal[] = {-6, 6};
ACE_ScopeAdjust_VerticalIncrement = 0.1;
@ -52,6 +115,7 @@ class CfgWeapons {
};
class optic_AMS_base : ItemCore {
ACE_ScopeHeightAboveRail = 3.6;
ACE_ScopeAdjust_Vertical[] = {-4, 30};
ACE_ScopeAdjust_Horizontal[] = {-6, 6};
ACE_ScopeAdjust_VerticalIncrement = 0.1;
@ -71,6 +135,7 @@ class CfgWeapons {
};
class optic_KHS_base : ItemCore {
ACE_ScopeHeightAboveRail = 4.0;
ACE_ScopeAdjust_Vertical[] = {-4, 30};
ACE_ScopeAdjust_Horizontal[] = {-6, 6};
ACE_ScopeAdjust_VerticalIncrement = 0.1;
@ -90,6 +155,7 @@ class CfgWeapons {
};
class optic_KHS_old : ItemCore {
ACE_ScopeHeightAboveRail = 4.0;
ACE_ScopeAdjust_Vertical[] = {-4, 30};
ACE_ScopeAdjust_Horizontal[] = {-6, 6};
ACE_ScopeAdjust_VerticalIncrement = 0.1;

View File

@ -2,6 +2,8 @@
PREP(adjustScope);
PREP(adjustZero);
PREP(applyScopeAdjustment);
PREP(calculateZeroAngle);
PREP(calculateZeroAngleCorrection);
PREP(canAdjustZero);
PREP(firedEH);
PREP(getOptics);

View File

@ -9,6 +9,8 @@
if (!hasInterface) exitWith {};
GVAR(Optics) = ["", "", ""];
// Check inventory when it changes
["loadout", FUNC(inventoryCheck)] call CBA_fnc_addPlayerEventHandler;

View File

@ -32,10 +32,6 @@ if (isNil "_adjustment") then {
_adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]; // [Windage, Elevation, Zero]
};
if (isNil QGVAR(Optics)) then {
GVAR(Optics) = ["", "", ""];
};
_optic = GVAR(Optics) select _weaponIndex;
_opticConfig = configFile >> "CfgWeapons" >> _optic;
_verticalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_VerticalIncrement");

View File

@ -0,0 +1,84 @@
/*
* Author: Ruthberg
* Calculates zero angle
*
* Arguments:
* 0: zero angle <NUMBER>
* 1: zero range <NUMBER>
* 2: muzzle velocity <NUMBER>
* 3: air friction <NUMBER>
* 4: simulation steps <NUMBER>
* 5: bore height <NUMBER>
* 6: temperature <NUMBER>
* 7: barometric pressure <NUMBER>
* 8: relative humidity <NUMBER>
* 9: ballistic coefficient <NUMBER>
* 10: drag model <NUMBER>
* 11: atmosphere model <STRING>
* 12: advanced_ballistics <BOOL>
*
* Return Value:
* 0: zero angle (Degrees) <NUMBER>
*
* Example:
* call ace_scopes_fnc_calculateZeroAngle
*
* Public: No
*/
#include "script_component.hpp"
params [
"_zeroAngle", "_zeroRange", "_muzzleVelocity", "_airFriction", "_simSteps", "_boreHeight",
"_temperature", "_barometricPressure", "_relativeHumidity", "_bc", "_dragModel", "_atmosphereModel",
"_advancedBallistics"
];
private ["_bulletPos", "_bulletVelocity", "_bulletAccel", "_bulletSpeed", "_gravity", "_deltaT"];
_bulletPos = [0, 0, 0];
_bulletVelocity = [0, 0, 0];
_bulletAccel = [0, 0, 0];
_bulletSpeed = 0;
_gravity = [0, sin(_zeroAngle) * -9.80665, cos(_zeroAngle) * -9.80665];
_deltaT = 1 / _simSteps;
private ["_TOF"];
_TOF = 0;
if (_advancedBallistics) then {
_bc = [_bc, _temperature, _barometricPressure, _relativeHumidity, _atmosphereModel] call EFUNC(advanced_ballistics,calculateAtmosphericCorrection);
};
_bulletPos set [0, 0];
_bulletPos set [1, 0];
_bulletPos set [2, -(_boreHeight / 100)];
_bulletVelocity set [0, 0];
_bulletVelocity set [1, Cos(_zeroAngle) * _muzzleVelocity];
_bulletVelocity set [2, Sin(_zeroAngle) * _muzzleVelocity];
while {_TOF < 15 && (_bulletPos select 1) < _zeroRange} do {
_bulletSpeed = vectorMagnitude _bulletVelocity;
if (_advancedBallistics) then {
private _drag = if (missionNamespace getVariable [QEGVAR(advanced_ballistics,extensionAvailable), false]) then {
parseNumber(("ace_advanced_ballistics" callExtension format["retard:%1:%2:%3", _dragModel, _bc, _bulletSpeed]))
} else {
([_dragModel, _bc, _bulletSpeed] call EFUNC(advanced_ballistics,calculateRetardation))
};
_bulletAccel = (vectorNormalized _bulletVelocity) vectorMultiply (-1 * _drag);
} else {
_bulletAccel = _bulletVelocity vectorMultiply (_bulletSpeed * _airFriction);
};
_bulletAccel = _bulletAccel vectorAdd _gravity;
_bulletVelocity = _bulletVelocity vectorAdd (_bulletAccel vectorMultiply _deltaT);
_bulletPos = _bulletPos vectorAdd (_bulletVelocity vectorMultiply _deltaT);
_TOF = _TOF + _deltaT;
};
if ((_bulletPos select 1) > 0) then {
_zeroAngle = - atan((_bulletPos select 2) / (_bulletPos select 1));
};
_zeroAngle

View File

@ -0,0 +1,73 @@
/*
* Author: Ruthberg
* Calculates the zero angle correction for the new zero range based on current zero range and bore height (distance between bore- and sight axis)
*
* Arguments:
* 0: Zero range <NUMBER>
* 1: Bore height <NUMBER>
* 2: Weapon <OBJECT>
* 3: Ammo <CLASS>
* 4: Magazine <CLASS>
* 5: Advanced Ballistics enabled? <BOOL>
*
* Return Value:
* zeroAngleCorrection
*
* Public: No
*/
#include "script_component.hpp"
params ["_oldZeroRange", "_newZeroRange", "_boreHeight"/*in cm*/, "_weapon", "_ammo", "_magazine", "_advancedBallistics"];
// Get Weapon and Ammo Configurations
private _AmmoCacheEntry = uiNamespace getVariable format[QEGVAR(advanced_ballistics,%1), _ammo];
if (isNil "_AmmoCacheEntry") then {
_AmmoCacheEntry = _ammo call EFUNC(advanced_ballistics,readAmmoDataFromConfig);
};
private _WeaponCacheEntry = uiNamespace getVariable format[QEGVAR(advanced_ballistics,%1), _weapon];
if (isNil "_WeaponCacheEntry") then {
_WeaponCacheEntry = _weapon call EFUNC(advanced_ballistics,readWeaponDataFromConfig);
};
_AmmoCacheEntry params ["_airFriction", "_caliber", "_bulletLength", "_bulletMass", "_transonicStabilityCoef", "_dragModel", "_ballisticCoefficients", "_velocityBoundaries", "_atmosphereModel", "_ammoTempMuzzleVelocityShifts", "_muzzleVelocityTable", "_barrelLengthTable"];
_WeaponCacheEntry params ["_barrelTwist", "_twistDirection", "_barrelLength"];
_initSpeed = getNumber(configFile >> "CfgMagazines" >> _magazine >> "initSpeed");
_initSpeedCoef = getNumber(configFile >> "CfgWeapons" >> _weapon >> "initSpeed");
if (_initSpeedCoef > 0) then {
_initSpeed = _initSpeedCoef;
};
if (_initSpeedCoef < 0) then {
_initSpeed = _initSpeed * (-1 * _initSpeedCoef);
};
private _vanillaZero = 0; // in degrees
{
private _offset = [_vanillaZero, _oldZeroRange, _initSpeed, _airFriction, 1000, 0, 0, 0, 0, 0, 0, "", false] call FUNC(calculateZeroAngle);
_vanillaZero = _vanillaZero + _offset;
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);
_initSpeed = _initSpeed + _barrelVelocityShift;
};
};
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);
_zeroAngle = _zeroAngle + _offset;
if (_offset < 0.01) exitWith {};
} forEach [1, 2, 3];
private _zeroAngleCorrection = _zeroAngle - _vanillaZero;
missionNamespace setVariable [format[QGVAR(%1_%2_%3_%4_%5_%6_%7), _oldZeroRange, _newZeroRange, _boreHeight, _weapon, _ammo, _magazine, _advancedBallistics], _zeroAngleCorrection];
_zeroAngleCorrection

View File

@ -21,13 +21,55 @@ if (_adjustment isEqualTo []) exitWith {};
private _weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {};
private _zeroing = _adjustment select _weaponIndex;
private _zeroing = +(_adjustment select _weaponIndex);
TRACE_1("Adjusting With",_zeroing);
if (_zeroing isEqualTo [0, 0, 0]) exitWith {};
// Convert zeroing from mils to degrees
_zeroing = _zeroing vectorMultiply 0.05625;
if (_ammo isKindOf "BulletBase") then {
private _railHeightAboveBore = 0;
private _scopeHeightAboveRail = 0;
// Determine rail height above bore
private _weaponConfig = configFile >> "CfgWeapons" >> _weapon;
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 _optic = GVAR(Optics) select _weaponIndex;
private _opticConfig = configFile >> "CfgWeapons" >> _optic;
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
};
};
};
};
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 _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);
};
_zeroing = _zeroing vectorAdd [0, 0, _zeroCorrection];
};
if (_zeroing isEqualTo [0, 0, 0]) exitWith {};
_zeroing params ["_elevation", "_windage", "_zero"];
[_projectile, _windage, _elevation + _zero, 0] call EFUNC(common,changeProjectileDirection);

View File

@ -25,9 +25,6 @@ if (isNil "_adjustment") then {
[ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
};
if (isNil QGVAR(Optics)) then {
GVAR(Optics) = ["", "", ""];
};
private _newOptics = [_player] call FUNC(getOptics);
{