Skip to content

Commit

Permalink
Cleanup - partly merged #4658
Browse files Browse the repository at this point in the history
* Removed getVariable QGVAR(Adjustment) boilerplate
* Less calls to setVariablePublic
* Removed vanilla zeroing element hiding (fixes warning in log file)
* Moved settings evaluation into ace_settingsInitialized event handler
  • Loading branch information
ulteq committed Nov 15, 2016
1 parent 10cc0ba commit 7fa7374
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 136 deletions.
188 changes: 99 additions & 89 deletions addons/scopes/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,122 +16,132 @@ GVAR(canAdjustWindage) = [false, false, false];
GVAR(boreHeight) = [0, 0, 0];
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;
["ace_settingsInitialized", {

// Instantly hide knobs when scoping in
["cameraView", {
params ["_player", "_newCameraView"];
if (!GVAR(enabled)) exitWith {};

if (GVAR(deduceBarometricPressureFromTerrainAltitude)) then {
GVAR(zeroReferenceBarometricPressure) = 1013.25 * (1 - (0.0065 * EGVAR(common,mapAltitude)) / 288.15) ^ 5.255754495;
};

// Check inventory when it changes
["loadout", FUNC(inventoryCheck), true] call CBA_fnc_addPlayerEventHandler;

if (_newCameraView == "GUNNER") then {
private _layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer;
_layer cutText ["", "PLAIN", 0];
// Instantly hide knobs when scoping in
["cameraView", {
params ["_player", "_newCameraView"];

if !(isNil QGVAR(fadePFH)) then {
[GVAR(fadePFH)] call CBA_fnc_removePerFrameHandler;
GVAR(fadePFH) = nil;
if (_newCameraView == "GUNNER") then {
private _layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer;
_layer cutText ["", "PLAIN", 0];

if !(isNil QGVAR(fadePFH)) then {
[GVAR(fadePFH)] call CBA_fnc_removePerFrameHandler;
GVAR(fadePFH) = nil;
};
};
};
}] call CBA_fnc_addPlayerEventHandler;
}] call CBA_fnc_addPlayerEventHandler;

// Add keybinds
["ACE3 Scope Adjustment", QGVAR(AdjustUpMinor), localize LSTRING(AdjustUpMinor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};
// Add keybinds
["ACE3 Scope Adjustment", QGVAR(AdjustUpMinor), localize LSTRING(AdjustUpMinor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};

[ACE_player] call FUNC(inventoryCheck);
[ACE_player] call FUNC(inventoryCheck);

// Statement
[ACE_player, ELEVATION_UP, MINOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [201, [false, false, false]], true] call CBA_fnc_addKeybind;
// Statement
[ACE_player, ELEVATION_UP, MINOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [201, [false, false, false]], true] call CBA_fnc_addKeybind;

["ACE3 Scope Adjustment", QGVAR(AdjustDownMinor), localize LSTRING(AdjustDownMinor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};
["ACE3 Scope Adjustment", QGVAR(AdjustDownMinor), localize LSTRING(AdjustDownMinor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};

[ACE_player] call FUNC(inventoryCheck);
[ACE_player] call FUNC(inventoryCheck);

// Statement
[ACE_player, ELEVATION_DOWN, MINOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [209, [false, false, false]], true] call CBA_fnc_addKeybind;
// Statement
[ACE_player, ELEVATION_DOWN, MINOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [209, [false, false, false]], true] call CBA_fnc_addKeybind;

["ACE3 Scope Adjustment", QGVAR(AdjustLeftMinor), localize LSTRING(AdjustLeftMinor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};
["ACE3 Scope Adjustment", QGVAR(AdjustLeftMinor), localize LSTRING(AdjustLeftMinor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};

[ACE_player] call FUNC(inventoryCheck);
[ACE_player] call FUNC(inventoryCheck);

// Statement
[ACE_player, WINDAGE_LEFT, MINOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [209, [false, true, false]], true] call CBA_fnc_addKeybind;
// Statement
[ACE_player, WINDAGE_LEFT, MINOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [209, [false, true, false]], true] call CBA_fnc_addKeybind;

["ACE3 Scope Adjustment", QGVAR(AdjustRightMinor), localize LSTRING(AdjustRightMinor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};
["ACE3 Scope Adjustment", QGVAR(AdjustRightMinor), localize LSTRING(AdjustRightMinor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};

[ACE_player] call FUNC(inventoryCheck);
[ACE_player] call FUNC(inventoryCheck);

// Statement
[ACE_player, WINDAGE_RIGHT, MINOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [201, [false, true, false]], true] call CBA_fnc_addKeybind;
// Statement
[ACE_player, WINDAGE_RIGHT, MINOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [201, [false, true, false]], true] call CBA_fnc_addKeybind;

["ACE3 Scope Adjustment", QGVAR(AdjustUpMajor), localize LSTRING(AdjustUpMajor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};
["ACE3 Scope Adjustment", QGVAR(AdjustUpMajor), localize LSTRING(AdjustUpMajor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};

[ACE_player] call FUNC(inventoryCheck);
[ACE_player] call FUNC(inventoryCheck);

// Statement
[ACE_player, ELEVATION_UP, MAJOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [201, [true, false, false]], true] call CBA_fnc_addKeybind;
// Statement
[ACE_player, ELEVATION_UP, MAJOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [201, [true, false, false]], true] call CBA_fnc_addKeybind;

["ACE3 Scope Adjustment", QGVAR(AdjustDownMajor), localize LSTRING(AdjustDownMajor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};
["ACE3 Scope Adjustment", QGVAR(AdjustDownMajor), localize LSTRING(AdjustDownMajor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};

[ACE_player] call FUNC(inventoryCheck);
[ACE_player] call FUNC(inventoryCheck);

// Statement
[ACE_player, ELEVATION_DOWN, MAJOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [209, [true, false, false]], true] call CBA_fnc_addKeybind;
// Statement
[ACE_player, ELEVATION_DOWN, MAJOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [209, [true, false, false]], true] call CBA_fnc_addKeybind;

["ACE3 Scope Adjustment", QGVAR(AdjustLeftMajor), localize LSTRING(AdjustLeftMajor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};
["ACE3 Scope Adjustment", QGVAR(AdjustLeftMajor), localize LSTRING(AdjustLeftMajor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};

[ACE_player] call FUNC(inventoryCheck);
[ACE_player] call FUNC(inventoryCheck);

// Statement
[ACE_player, WINDAGE_LEFT, MAJOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [209, [true, true, false]], true] call CBA_fnc_addKeybind;
// Statement
[ACE_player, WINDAGE_LEFT, MAJOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [209, [true, true, false]], true] call CBA_fnc_addKeybind;

["ACE3 Scope Adjustment", QGVAR(AdjustRightMajor), localize LSTRING(AdjustRightMajor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};
["ACE3 Scope Adjustment", QGVAR(AdjustRightMajor), localize LSTRING(AdjustRightMajor), {
// Conditions: canInteract
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if (!([ACE_player] call CBA_fnc_canUseWeapon)) exitWith {false};

[ACE_player] call FUNC(inventoryCheck);
[ACE_player] call FUNC(inventoryCheck);

// Statement
[ACE_player, WINDAGE_RIGHT, MAJOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [201, [true, true, false]], true] call CBA_fnc_addKeybind;
// Statement
[ACE_player, WINDAGE_RIGHT, MAJOR_INCREMENT] call FUNC(adjustScope);
}, {false}, [201, [true, true, false]], true] call CBA_fnc_addKeybind;


// Register fire event handler
["ace_firedPlayer", DFUNC(firedEH)] call CBA_fnc_addEventHandler;
["ace_firedPlayerNonLocal", DFUNC(firedEH)] call CBA_fnc_addEventHandler;
// Register fire event handler
["ace_firedPlayer", DFUNC(firedEH)] call CBA_fnc_addEventHandler;
["ace_firedPlayerNonLocal", DFUNC(firedEH)] call CBA_fnc_addEventHandler;

}] call CBA_fnc_addEventHandler;
5 changes: 1 addition & 4 deletions addons/scopes/functions/fnc_adjustScope.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ if (!GVAR(enabled)) exitWith {false};
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {false};

_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
_adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]; // [Windage, Elevation, Zero]
};
_adjustment = _unit getVariable [QGVAR(Adjustment), [[0, 0, 0], [0, 0, 0], [0, 0, 0]]];

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};
Expand Down
7 changes: 1 addition & 6 deletions addons/scopes/functions/fnc_adjustZero.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ if (vehicle _unit != _unit) exitWith {false};
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {false};

_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
// [Windage, Elevation, Zero]
_adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
};

_adjustment = _unit getVariable [QGVAR(Adjustment), [[0, 0, 0], [0, 0, 0], [0, 0, 0]]];
_zeroing = _adjustment select _weaponIndex;
_zeroing params ["_elevation", "_windage", "_zero"];

Expand Down
8 changes: 1 addition & 7 deletions addons/scopes/functions/fnc_applyScopeAdjustment.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ params ["_unit", "_elevation", "_windage", "_zero"];

_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);

_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
// [Windage, Elevation, Zero]
_adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
_unit setVariable [QGVAR(Adjustment), _adjustment];
};

_adjustment = _unit getVariable [QGVAR(Adjustment), [[0, 0, 0], [0, 0, 0], [0, 0, 0]]];
_adjustmentDifference = (_adjustment select _weaponIndex) vectorDiff [_elevation, _windage, _zero];
if (_adjustmentDifference isEqualTo [0,0,0]) exitWith {false}; // Don't coninue if no adjustment is made

Expand Down
7 changes: 1 addition & 6 deletions addons/scopes/functions/fnc_canAdjustZero.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ if (!(missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false])
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {false};

_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
// [Windage, Elevation, Zero]
_adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
};

_adjustment = _unit getVariable [QGVAR(Adjustment), [[0, 0, 0], [0, 0, 0], [0, 0, 0]]];
_elevation = (_adjustment select _weaponIndex) select 0;

// You can only adjust your zero reference, if your relative elevation setting is not 0
Expand Down
4 changes: 1 addition & 3 deletions addons/scopes/functions/fnc_firedEH.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
//IGNORE_PRIVATE_WARNING ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle", "_gunner", "_turret"];
TRACE_10("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectile, _vehicle, _gunner, _turret);

private _adjustment = _unit getVariable [QGVAR(Adjustment), []];
if (_adjustment isEqualTo []) exitWith {};

private _weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {};

private _adjustment = ACE_player getVariable [QGVAR(Adjustment), [[0, 0, 0], [0, 0, 0], [0, 0, 0]]];
private _zeroing = +(_adjustment select _weaponIndex);
TRACE_1("Adjusting With",_zeroing);

Expand Down
4 changes: 0 additions & 4 deletions addons/scopes/functions/fnc_initModuleSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,3 @@ 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;
};
19 changes: 7 additions & 12 deletions addons/scopes/functions/fnc_inventoryCheck.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@

params ["_player"];

private _adjustment = ACE_player getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
// [Windage, Elevation, Zero]
_adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
ACE_player setVariable [QGVAR(Adjustment), _adjustment];
[ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
};
private _adjustment = ACE_player getVariable [QGVAR(Adjustment), [[0, 0, 0], [0, 0, 0], [0, 0, 0]]];
private _updateAdjustment = false;

private _newOptics = [_player] call FUNC(getOptics);
private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapon _player];
Expand All @@ -33,7 +28,7 @@ private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapo
// The optic for this weapon changed, set adjustment to zero
if (!((_adjustment select _forEachIndex) isEqualTo [0, 0, 0])) then {
_adjustment set [_forEachIndex, [0, 0, 0]];
[ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
_updateAdjustment;
};
private _opticConfig = configFile >> "CfgWeapons" >> (_newOptics select _forEachIndex);
private _verticalIncrement = -1;
Expand Down Expand Up @@ -69,8 +64,6 @@ private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapo
(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])];
private _hideVanillaZeroing = (GVAR(enabled) && getNumber(_opticConfig >> "ItemInfo" >> "opticType") == 2 && {GVAR(canAdjustElevation) select _forEachIndex}) || {isNumber (_opticConfig >> "ACE_ScopeZeroRange")};
["ace_scopes", true, "zeroing", !_hideVanillaZeroing] call EFUNC(ui,setElementVisibility);
};
} forEach GVAR(Optics);

Expand Down Expand Up @@ -134,7 +127,9 @@ private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapo
}
} forEach [0, 1, 2];

_adjustment = ACE_player getVariable QGVAR(Adjustment);
if (_updateAdjustment) then {
[ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
};

GVAR(Optics) = _newOptics;
GVAR(Guns) = _newGuns;

6 changes: 1 addition & 5 deletions addons/scopes/functions/fnc_showZeroing.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ disableSerialization;
private _weaponIndex = [ACE_player, currentWeapon ACE_player] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {};

private _adjustment = ACE_player getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
// [Windage, Elevation, Zero]
_adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
};
private _adjustment = ACE_player getVariable [QGVAR(Adjustment), [[0, 0, 0], [0, 0, 0], [0, 0, 0]]];

// Display the adjustment knobs
private _layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer;
Expand Down

0 comments on commit 7fa7374

Please sign in to comment.