Code cleanup of scopes module

This commit is contained in:
Michael Braun 2015-08-07 16:43:06 +02:00
parent f21da3ead6
commit fb32bbf8de
8 changed files with 81 additions and 60 deletions

View File

@ -10,23 +10,26 @@
* Return value: * Return value:
* Did we adjust anything? <BOOL> * Did we adjust anything? <BOOL>
* *
* Example:
* [player, ELEVATION_UP, false] call ace_scopes_fnc_adjustScope
*
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_3(_unit,_turretAndDirection,_majorStep); private ["_weaponIndex", "_zeroing", "_optic", "_verticalIncrement", "_horizontalIncrement", "_maxVertical", "_maxHorizontal", "_adjustment"];
params ["_unit", "_turretAndDirection", "_majorStep"];
if (!(_unit isKindOf "Man")) exitWith {false}; if (!(_unit isKindOf "Man")) exitWith {false};
if (currentMuzzle _unit != currentWeapon _unit) exitWith {false}; if (currentMuzzle _unit != currentWeapon _unit) exitWith {false};
private ["_weaponIndex", "_zeroing", "_optic", "_verticalIncrement", "_horizontalIncrement", "_maxVertical", "_maxHorizontal", "_elevation", "_windage", "_zero", "_adjustment"];
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex); _weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {false}; if (_weaponIndex < 0) exitWith {false};
_adjustment = _unit getVariable QGVAR(Adjustment); _adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then { if (isNil "_adjustment") then {
_adjustment = [[0,0,0], [0,0,0], [0,0,0]]; // [Windage, Elevation, Zero] _adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]; // [Windage, Elevation, Zero]
}; };
if (isNil QGVAR(Optics)) then { if (isNil QGVAR(Optics)) then {
@ -34,18 +37,17 @@ if (isNil QGVAR(Optics)) then {
}; };
_optic = GVAR(Optics) select _weaponIndex; _optic = GVAR(Optics) select _weaponIndex;
_verticalIncrement = getNumber (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_VerticalIncrement"); _opticConfig = configFile >> "CfgWeapons" >> _optic;
_horizontalIncrement = getNumber (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_HorizontalIncrement"); _verticalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_VerticalIncrement");
_maxVertical = getArray (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_Vertical"); _horizontalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_HorizontalIncrement");
_maxHorizontal = getArray (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_Horizontal"); _maxVertical = getArray (_opticConfig >> "ACE_ScopeAdjust_Vertical");
_maxHorizontal = getArray (_opticConfig >> "ACE_ScopeAdjust_Horizontal");
if ((count _maxHorizontal < 2) || (count _maxVertical < 2)) exitWith {false}; if ((count _maxHorizontal < 2) || (count _maxVertical < 2)) exitWith {false};
if ((_verticalIncrement == 0) && (_horizontalIncrement == 0)) exitWith {false}; if ((_verticalIncrement == 0) && (_horizontalIncrement == 0)) exitWith {false};
_zeroing = _adjustment select _weaponIndex; _zeroing = _adjustment select _weaponIndex;
_elevation = _zeroing select 0; _zeroing params ["_elevation", "_windage", "_zero"];
_windage = _zeroing select 1;
_zero = _zeroing select 2;
switch (_turretAndDirection) do { switch (_turretAndDirection) do {
case ELEVATION_UP: { _elevation = _elevation + _verticalIncrement }; case ELEVATION_UP: { _elevation = _elevation + _verticalIncrement };

View File

@ -8,29 +8,30 @@
* Return value: * Return value:
* true <BOOL> * true <BOOL>
* *
* Example:
* [player] call ace_scopes_fnc_adjustZero
*
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_unit); private ["_weaponIndex", "_adjustment", "_zeroing"];
params ["_unit"];
if (vehicle _unit != _unit) exitWith {false}; if (vehicle _unit != _unit) exitWith {false};
private ["_weaponIndex", "_adjustment", "_zeroing", "_elevation", "_windage", "_zero"];
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex); _weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {false}; if (_weaponIndex < 0) exitWith {false};
_adjustment = _unit getVariable QGVAR(Adjustment); _adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then { if (isNil "_adjustment") then {
// [Windage, Elevation, Zero] // [Windage, Elevation, Zero]
_adjustment = [[0,0,0], [0,0,0], [0,0,0]]; _adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
}; };
_zeroing = _adjustment select _weaponIndex; _zeroing = _adjustment select _weaponIndex;
_elevation = _zeroing select 0; _zeroing params ["_elevation", "_windage", "_zero"];
_windage = _zeroing select 1;
_zero = _zeroing select 2;
_zero = round((_zero + _elevation) * 10) / 10; _zero = round((_zero + _elevation) * 10) / 10;
_elevation = 0; _elevation = 0;

View File

@ -11,20 +11,23 @@
* Return value: * Return value:
* True <BOOL> * True <BOOL>
* *
* Example:
* [player, 1.3, 0.3, 0.1] call ace_scopes_fnc_applyScopeAdjustment
*
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
EXPLODE_4_PVT(_this,_unit,_elevation,_windage,_zero); private ["_adjustmentDifference", "_pitchBankYaw", "_adjustment", "_weaponIndex"];
private ["_adjustmentDifference", "_pitchbankyaw", "_pitch", "_bank", "_yaw", "_adjustment", "_weaponIndex"]; params ["_unit", "_elevation", "_windage", "_zero"];
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex); _weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
_adjustment = _unit getVariable QGVAR(Adjustment); _adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then { if (isNil "_adjustment") then {
// [Windage, Elevation, Zero] // [Windage, Elevation, Zero]
_adjustment = [[0,0,0], [0,0,0], [0,0,0]]; _adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
_unit setVariable [QGVAR(Adjustment), _adjustment]; _unit setVariable [QGVAR(Adjustment), _adjustment];
}; };
@ -39,10 +42,11 @@ playSound (["ACE_Scopes_Click_1", "ACE_Scopes_Click_2", "ACE_Scopes_Click_3"] se
if (cameraView == "GUNNER") then { if (cameraView == "GUNNER") then {
// Convert adjustmentDifference from mils to degrees // Convert adjustmentDifference from mils to degrees
_adjustmentDifference = [_adjustmentDifference, {_this * 0.05625}] call EFUNC(common,map); _adjustmentDifference = [_adjustmentDifference, {_this * 0.05625}] call EFUNC(common,map);
_pitchbankyaw = [_unit] call EFUNC(common,getPitchBankYaw); _adjustmentDifference params ["_elevationDifference", "_windageDifference"];
_pitch = (_pitchbankyaw select 0) + (_adjustmentDifference select 0); _pitchBankYaw = [_unit] call EFUNC(common,getPitchBankYaw);
_bank = (_pitchbankyaw select 1); _pitchBankYaw params ["_pitch", "_bank", "_yaw"];
_yaw = (_pitchbankyaw select 2) + (_adjustmentDifference select 1); _pitch = _pitch + _elevationDifference;
_yaw = _yaw + _windageDifference;
[_unit, _pitch, _bank, _yaw] call EFUNC(common,setPitchBankYaw); [_unit, _pitch, _bank, _yaw] call EFUNC(common,setPitchBankYaw);
} else { } else {
[] call FUNC(showZeroing); [] call FUNC(showZeroing);

View File

@ -8,17 +8,20 @@
* Return value: * Return value:
* Can we update the zero reference? <BOOL> * Can we update the zero reference? <BOOL>
* *
* Example:
* [player] call ace_scopes_fnc_canAdjustZero
*
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_unit);
private ["_weaponIndex", "_adjustment", "_elevation"]; private ["_weaponIndex", "_adjustment", "_elevation"];
params ["_unit"];
if (cameraView == "GUNNER") exitWith {false}; if (cameraView == "GUNNER") exitWith {false};
if !(vehicle _unit == _unit) exitWith {false}; if (vehicle _unit != _unit) exitWith {false};
if !(missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) exitWith {false}; if (!(missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false])) exitWith {false};
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex); _weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {false}; if (_weaponIndex < 0) exitWith {false};
@ -26,7 +29,7 @@ if (_weaponIndex < 0) exitWith {false};
_adjustment = _unit getVariable QGVAR(Adjustment); _adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then { if (isNil "_adjustment") then {
// [Windage, Elevation, Zero] // [Windage, Elevation, Zero]
_adjustment = [[0,0,0], [0,0,0], [0,0,0]]; _adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
}; };
_elevation = (_adjustment select _weaponIndex) select 0; _elevation = (_adjustment select _weaponIndex) select 0;

View File

@ -1,5 +1,5 @@
/* /*
* Author: KoffeinFlummi and esteldunedain * Author: KoffeinFlummi, esteldunedain
* Adjusts the flight path of the bullet according to the zeroing * Adjusts the flight path of the bullet according to the zeroing
* *
* Argument: * Argument:
@ -18,11 +18,11 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_adjustment", "_projectile", "_weaponIndex", "_zeroing", "_adjustment"]; private ["_adjustment", "_weaponIndex", "_zeroing", "_adjustment"];
_unit = _this select 0;
_projectile = _this select 6;
if !([_unit] call EFUNC(common,isPlayer)) exitWith {}; prams ["_unit", "", "", "", "", "", "_projectile"];
if (!([_unit] call EFUNC(common,isPlayer))) exitWith {};
_adjustment = _unit getVariable [QGVAR(Adjustment), []]; _adjustment = _unit getVariable [QGVAR(Adjustment), []];
if (_adjustment isEqualTo []) exitWith {}; if (_adjustment isEqualTo []) exitWith {};
@ -32,9 +32,10 @@ if (_weaponIndex < 0) exitWith {};
_zeroing = _adjustment select _weaponIndex; _zeroing = _adjustment select _weaponIndex;
if (_zeroing isEqualTo [0,0,0]) exitWith {}; if (_zeroing isEqualTo [0, 0, 0]) exitWith {};
// Convert zeroing from mils to degrees // Convert zeroing from mils to degrees
_zeroing = _zeroing vectorMultiply 0.05625; _zeroing = _zeroing vectorMultiply 0.05625;
_zeroing params ["_elevation", "_windage", "_zero"]
[_projectile, (_zeroing select 1), (_zeroing select 0) + (_zeroing select 2), 0] call EFUNC(common,changeProjectileDirection); [_projectile, _elevation, _elevation + _zero, 0] call EFUNC(common,changeProjectileDirection);

View File

@ -10,21 +10,25 @@
* 1: Optic of secondary <STRING> * 1: Optic of secondary <STRING>
* 2: Optic of handgun <STRING> * 2: Optic of handgun <STRING>
* *
* Example:
* [player] call ace_scopes_fnc_getOptics
*
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
EXPLODE_1_PVT(_this,_unit); private "_optics";
private ["_array"]; params ["_unit"];
_array = ["", "", ""];
if !(_unit isKindOf "CAManBase") exitWith {_array}; _optics = ["", "", ""];
if (!(_unit isKindOf "CAManBase")) exitWith {_optics};
{ {
if (count _x >= 2) then { if (count _x >= 2) then {
_array set [_forEachIndex, _x select 2]; _optics set [_forEachIndex, _x select 2];
}; };
} forEach [primaryWeaponItems _unit, secondaryWeaponItems _unit, handgunItems _unit]; } count [primaryWeaponItems _unit, secondaryWeaponItems _unit, handgunItems _unit];
_array _optics

View File

@ -1,5 +1,5 @@
/* /*
* Author: KoffeinFlummi and Commy2 * Author: KoffeinFlummi, Commy2
* Check if weapon optics changed and reset zeroing if needed * Check if weapon optics changed and reset zeroing if needed
* *
* Arguments: * Arguments:
@ -8,18 +8,21 @@
* Return Value: * Return Value:
* None * None
* *
* Example:
* [player] call ace_scopes_fnc_inventoryCheck
*
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
EXPLODE_1_PVT(_this,_player);
private ["_newOptics", "_adjustment"]; private ["_newOptics", "_adjustment"];
params ["_player"];
_adjustment = ACE_player getVariable QGVAR(Adjustment); _adjustment = ACE_player getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then { if (isNil "_adjustment") then {
// [Windage, Elevation, Zero] // [Windage, Elevation, Zero]
_adjustment = [[0,0,0], [0,0,0], [0,0,0]]; _adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
ACE_player setVariable [QGVAR(Adjustment), _adjustment]; ACE_player setVariable [QGVAR(Adjustment), _adjustment];
[ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic); [ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
}; };
@ -32,8 +35,8 @@ _newOptics = [_player] call FUNC(getOptics);
{ {
if (_newOptics select _forEachIndex != _x) then { if (_newOptics select _forEachIndex != _x) then {
// The optic for this weapon changed, set adjustment to zero // The optic for this weapon changed, set adjustment to zero
if !((_adjustment select _foreachindex) isEqualTo [0,0,0]) then { if (!((_adjustment select _foreachindex) isEqualTo [0, 0, 0])) then {
_adjustment set [_forEachIndex, [0,0,0]]; _adjustment set [_forEachIndex, [0, 0, 0]];
[ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic); [ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
}; };
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Author: KoffeinFlummi and esteldunedain * Author: KoffeinFlummi, esteldunedain
* Display the adjustment knobs, update their value and fade them out later * Display the adjustment knobs, update their value and fade them out later
* *
* Arguments: * Arguments:
@ -8,13 +8,16 @@
* Return Value: * Return Value:
* None * None
* *
* Example:
* [] call ace_scopes_fnc_showZeroing
*
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
disableSerialization; private ["_weaponIndex", "_adjustment", "_layer", "_display", "_zeroing", "_vertical", "_horizontal"];
private ["_weaponIndex","_adjustment","_layer","_display","_zeroing","_vertical","_horizontal"]; disableSerialization;
_weaponIndex = [ACE_player, currentWeapon ACE_player] call EFUNC(common,getWeaponIndex); _weaponIndex = [ACE_player, currentWeapon ACE_player] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {}; if (_weaponIndex < 0) exitWith {};
@ -22,7 +25,7 @@ if (_weaponIndex < 0) exitWith {};
_adjustment = ACE_player getVariable QGVAR(Adjustment); _adjustment = ACE_player getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then { if (isNil "_adjustment") then {
// [Windage, Elevation, Zero] // [Windage, Elevation, Zero]
_adjustment = [[0,0,0], [0,0,0], [0,0,0]]; _adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
}; };
// Display the adjustment knobs // Display the adjustment knobs
@ -35,10 +38,11 @@ if (isNull _display) exitWith {};
// Update values // Update values
_zeroing = _adjustment select _weaponIndex; _zeroing = _adjustment select _weaponIndex;
_zeroing params ["_elevation", "_windage"];
_vertical = _display displayCtrl 12; _vertical = _display displayCtrl 12;
_horizontal = _display displayCtrl 13; _horizontal = _display displayCtrl 13;
_vertical ctrlSetText (str (_zeroing select 0)); _vertical ctrlSetText (str _elevation);
_horizontal ctrlSetText (str (_zeroing select 1)); _horizontal ctrlSetText (str _windage);
// Set the ACE_time when to hide the knobs // Set the ACE_time when to hide the knobs
GVAR(timeToHide) = ACE_diagTime + 3.0; GVAR(timeToHide) = ACE_diagTime + 3.0;
@ -47,14 +51,13 @@ if !(isNil QGVAR(fadePFH)) exitWith {};
// Launch a PFH to wait and fade out the knobs // Launch a PFH to wait and fade out the knobs
GVAR(fadePFH) = [{ GVAR(fadePFH) = [{
if (ACE_diagTime >= GVAR(timeToHide)) exitWith { if (ACE_diagTime >= GVAR(timeToHide)) exitWith {
private "_layer"; private "_layer";
params ["", "_pfhId"];
_layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer; _layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer;
_layer cutFadeOut 2; _layer cutFadeOut 2;
GVAR(fadePFH) = nil; GVAR(fadePFH) = nil;
[_this select 1] call cba_fnc_removePerFrameHandler; [_pfhId] call cba_fnc_removePerFrameHandler;
}; };
}, 0.1, []] call CBA_fnc_addPerFrameHandler }, 0.1, []] call CBA_fnc_addPerFrameHandler