Overhauled the scope adjustment module:

*Added configs for the new marksmen scopes
*Introduced minor and major steps
*Introcuded a new increment config (ACE_ScopeAdjust_Increment)
*Changed the default zero range to 100m
*Added a zero reference setting
*Added an interaction menu entry to update the zero reference setting
This commit is contained in:
ulteq 2015-04-11 14:02:44 +02:00
parent 127d100628
commit fee65cd56f
15 changed files with 267 additions and 116 deletions

View File

@ -0,0 +1,19 @@
class CfgVehicles {
class Man;
class CAManBase: Man {
class ACE_SelfActions {
class ACE_Equipment {
class GVAR(adjustZero) {
// Updates the zero reference
displayName = "$STR_ACE_Scopes_AdjustZero";
condition = QUOTE([ACE_player] call FUNC(canAdjustZero));
statement = QUOTE([ACE_player] call FUNC(adjustZero));
showDisabled = 0;
priority = 0.2;
//icon = QUOTE(PATHTOF(UI\...)); // TODO
exceptions[] = {"notOnMap", "isNotInside"};
};
};
};
};
};

View File

@ -1,14 +1,15 @@
class CfgWeapons {
class ItemCore;
class InventoryOpticsItem_Base_F;
class optic_LRPS : ItemCore {
ACE_ScopeAdjust_Horizontal[] = { -50, 50 };
ACE_ScopeAdjust_Vertical[] = { -70, 70 };
ACE_ScopeAdjust_Vertical[] = { -4, 30 };
ACE_ScopeAdjust_Horizontal[] = { -6, 6 };
ACE_ScopeAdjust_Increment = 0.1;
class ItemInfo : InventoryOpticsItem_Base_F {
class OpticsModes {
class Snip {
discreteDistance[] = { 1 };
discreteDistance[] = { 100 };
discreteDistanceInitIndex = 0;
};
};
@ -16,12 +17,13 @@ class CfgWeapons {
};
class optic_SOS : ItemCore {
ACE_ScopeAdjust_Horizontal[] = { -50, 50 };
ACE_ScopeAdjust_Vertical[] = { -60, 60 };
ACE_ScopeAdjust_Vertical[] = { -4, 30 };
ACE_ScopeAdjust_Horizontal[] = { -6, 6 };
ACE_ScopeAdjust_Increment = 0.1;
class ItemInfo : InventoryOpticsItem_Base_F {
class OpticsModes {
class Snip {
discreteDistance[] = { 1 };
discreteDistance[] = { 100 };
discreteDistanceInitIndex = 0;
};
};
@ -29,12 +31,41 @@ class CfgWeapons {
};
class optic_DMS : ItemCore {
ACE_ScopeAdjust_Horizontal[] = { -40, 40 };
ACE_ScopeAdjust_Vertical[] = { -40, 40 };
ACE_ScopeAdjust_Vertical[] = { -4, 20 };
ACE_ScopeAdjust_Horizontal[] = { -6, 6 };
ACE_ScopeAdjust_Increment = 0.1;
class ItemInfo : InventoryOpticsItem_Base_F {
class OpticsModes {
class Snip {
discreteDistance[] = { 1 };
discreteDistance[] = { 100 };
discreteDistanceInitIndex = 0;
};
};
};
};
class optic_AMS_base : ItemCore {
ACE_ScopeAdjust_Vertical[] = { -4, 30 };
ACE_ScopeAdjust_Horizontal[] = { -6, 6 };
ACE_ScopeAdjust_Increment = 0.1;
class ItemInfo : InventoryOpticsItem_Base_F {
class OpticsModes {
class AMS {
discreteDistance[] = { 100 };
discreteDistanceInitIndex = 0;
};
};
};
};
class optic_KHS_base : ItemCore {
ACE_ScopeAdjust_Vertical[] = { -4, 30 };
ACE_ScopeAdjust_Horizontal[] = { -6, 6 };
ACE_ScopeAdjust_Increment = 0.1;
class ItemInfo : InventoryOpticsItem_Base_F {
class OpticsModes {
class KHS {
discreteDistance[] = { 100 };
discreteDistanceInitIndex = 0;
};
};

View File

@ -1,5 +1,5 @@
/*
* Author: KoffeinFlummi and esteldunedain
* Author: KoffeinFlummi, esteldunedain, Ruthberg
*
* Watches for scope changes.
* Defines key bindings
@ -39,10 +39,9 @@ if !(hasInterface) exitWith {};
if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
[ACE_player] call FUNC(inventoryCheck);
if !([ACE_player, 0, 0.1] call FUNC(canAdjustScope)) exitWith {false};
// Statement
[ACE_player, 0, 0.1] call FUNC(adjustScope);
[ACE_player, ELEVATION_UP, MINOR_INCREMENT] call FUNC(adjustScope);
true
},
{false},
@ -54,10 +53,9 @@ if !(hasInterface) exitWith {};
if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
[ACE_player] call FUNC(inventoryCheck);
if !([ACE_player, 0, -0.1] call FUNC(canAdjustScope)) exitWith {false};
// Statement
[ACE_player, 0, -0.1] call FUNC(adjustScope);
[ACE_player, ELEVATION_DOWN, MINOR_INCREMENT] call FUNC(adjustScope);
true
},
{false},
@ -69,10 +67,9 @@ if !(hasInterface) exitWith {};
if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
[ACE_player] call FUNC(inventoryCheck);
if !([ACE_player, -0.1, 0] call FUNC(canAdjustScope)) exitWith {false};
// Statement
[ACE_player, -0.1, 0] call FUNC(adjustScope);
[ACE_player, WINDAGE_LEFT, MINOR_INCREMENT] call FUNC(adjustScope);
true
},
{false},
@ -84,10 +81,9 @@ if !(hasInterface) exitWith {};
if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
[ACE_player] call FUNC(inventoryCheck);
if !([ACE_player, 0.1, 0] call FUNC(canAdjustScope)) exitWith {false};
// Statement
[ACE_player, 0.1, 0] call FUNC(adjustScope);
[ACE_player, WINDAGE_RIGHT, MINOR_INCREMENT] call FUNC(adjustScope);
true
},
{false},
@ -99,10 +95,9 @@ if !(hasInterface) exitWith {};
if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
[ACE_player] call FUNC(inventoryCheck);
if !([ACE_player, 0, 1.0] call FUNC(canAdjustScope)) exitWith {false};
// Statement
[ACE_player, 0, 1.0] call FUNC(adjustScope);
[ACE_player, ELEVATION_UP, MAJOR_INCREMENT] call FUNC(adjustScope);
true
},
{false},
@ -114,10 +109,9 @@ if !(hasInterface) exitWith {};
if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
[ACE_player] call FUNC(inventoryCheck);
if !([ACE_player, 0, -1.0] call FUNC(canAdjustScope)) exitWith {false};
// Statement
[ACE_player, 0, -1.0] call FUNC(adjustScope);
[ACE_player, ELEVATION_DOWN, MAJOR_INCREMENT] call FUNC(adjustScope);
true
},
{false},
@ -129,10 +123,9 @@ if !(hasInterface) exitWith {};
if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
[ACE_player] call FUNC(inventoryCheck);
if !([ACE_player, -1.0, 0] call FUNC(canAdjustScope)) exitWith {false};
// Statement
[ACE_player, -1.0, 0] call FUNC(adjustScope);
[ACE_player, WINDAGE_LEFT, MAJOR_INCREMENT] call FUNC(adjustScope);
true
},
{false},
@ -144,10 +137,9 @@ if !(hasInterface) exitWith {};
if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
[ACE_player] call FUNC(inventoryCheck);
if !([ACE_player, 1.0, 0] call FUNC(canAdjustScope)) exitWith {false};
// Statement
[ACE_player, 1.0, 0] call FUNC(adjustScope);
[ACE_player, WINDAGE_RIGHT, MAJOR_INCREMENT] call FUNC(adjustScope);
true
},
{false},

View File

@ -3,7 +3,9 @@
ADDON = false;
PREP(adjustScope);
PREP(canAdjustScope);
PREP(adjustZero);
PREP(applyScopeAdjustment);
PREP(canAdjustZero);
PREP(firedEH);
PREP(getOptics);
PREP(inventoryCheck);

View File

@ -16,6 +16,8 @@ class CfgPatches {
#include "CfgSounds.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
#include "RscTitles.hpp"

View File

@ -1,56 +1,71 @@
/*
* Author: KoffeinFlummi
* Author: KoffeinFlummi, Ruthberg
* Changes the adjustment for the current scope
*
* Argument:
* 0: Unit <OBJECT>
* 1: Horizontal adjustment <NUMBER>
* 2: Vertical adjustment <NUMBER>
* 1: Turret and Direction <NUMBER>
* 2: Major Step <BOOL>
*
* Return value:
* True <BOOL>
* Did we adjust anything? <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit", "_weapons", "_zeroing", "_pitchbankyaw", "_pitch", "_bank", "_yaw", "_hint"];
if !(vehicle _unit == _unit) exitWith {false};
_unit = _this select 0;
private ["_unit", "_turretAndDirection", "_majorStep", "_weaponIndex", "_zeroing", "_optic", "_increment", "_maxVertical", "_maxHorizontal", "_elevation", "_windage", "_zero"];
EXPLODE_3_PVT(_this,_unit,_turretAndDirection,_majorStep);
_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]];
_unit setVariable [QGVAR(Adjustment), _adjustment];
_adjustment = [[0,0,0], [0,0,0], [0,0,0]]; // [Windage, Elevation, Zero]
};
_zeroing = _adjustment select _weaponIndex;
_zeroing set [0, (round (((_zeroing select 0) + (_this select 1)) * 10)) / 10];
_zeroing set [1, (round (((_zeroing select 1) + (_this select 2)) * 10)) / 10];
// Change the adjustment array
_adjustment set [_weaponIndex, _zeroing];
[_unit, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
playSound (["ACE_Scopes_Click_1", "ACE_Scopes_Click_2", "ACE_Scopes_Click_3"] select floor random 3);
// slightly rotate the player if looking through optic
if (cameraView == "GUNNER") then {
_pitchbankyaw = [_unit] call EFUNC(common,getPitchBankYaw);
// these are not exact mil-to-degree conversions, but instead chosen
// to minimize the effect of rounding errors
_pitch = (_pitchbankyaw select 0) + ((_this select 2) * -0.04);
_bank = _pitchbankyaw select 1;
_yaw = (_pitchbankyaw select 2) + ((_this select 1) * -0.04);
[_unit, _pitch, _bank, _yaw] call EFUNC(common,setPitchBankYaw)
} else {
[] call FUNC(showZeroing);
if (isNil QGVAR(Optics)) then {
GVAR(Optics) = ["", "", ""];
};
true
_optic = GVAR(Optics) select _weaponIndex;
_increment = getNumber (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_Increment");
_maxVertical = getArray (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_Vertical");
_maxHorizontal = getArray (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_Horizontal");
if ((count _maxHorizontal < 2) or (count _maxVertical < 2)) exitWith {false};
_zeroing = _adjustment select _weaponIndex;
_elevation = _zeroing select 0;
_windage = _zeroing select 1;
_zero = _zeroing select 2;
switch (_turretAndDirection) do
{
case ELEVATION_UP: { _elevation = _elevation + _increment };
case ELEVATION_DOWN: { _elevation = _elevation - _increment };
case WINDAGE_LEFT: { _windage = _windage - _increment };
case WINDAGE_RIGHT: { _windage = _windage + _increment };
};
if (_majorStep) then {
switch (_turretAndDirection) do
{
case ELEVATION_UP: { _elevation = ceil(_elevation) };
case ELEVATION_DOWN: { _elevation = floor(_elevation) };
case WINDAGE_LEFT: { _windage = floor(_windage) };
case WINDAGE_RIGHT: { _windage = ceil(_windage) };
};
};
_elevation = round(_elevation * 10) / 10;
_windage = round(_windage * 10) / 10;
if (_elevation < _maxVertical select 0 or _elevation > _maxVertical select 1) exitWith {false};
if (_windage < _maxHorizontal select 0 or _windage > _maxHorizontal select 1) exitWith {false};
[_unit, _elevation, _windage, _zero] call FUNC(applyScopeAdjustment);

View File

@ -0,0 +1,39 @@
/*
* Author: KoffeinFlummi, Ruthberg
* Updates the zero reference for the current scope
*
* Argument:
* 0: Unit <OBJECT>
*
* Return value:
* true <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
if !(vehicle _unit == _unit) exitWith {false};
private ["_unit", "_adjustment", "_zeroing", "_elevation", "_windage", "_zero"];
_unit = _this select 0;
_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]];
};
_zeroing = _adjustment select _weaponIndex;
_elevation = _zeroing select 0;
_windage = _zeroing select 1;
_zero = _zeroing select 2;
_zero = round((_zero + _elevation) * 10) / 10;
_elevation = 0;
[_unit, _elevation, _windage, _zero] call FUNC(applyScopeAdjustment);
true

View File

@ -0,0 +1,51 @@
/*
* Author: KoffeinFlummi, Ruthberg
* Applies the adjustment for the current scope
*
* Argument:
* 0: Unit <OBJECT>
* 1: Absolute elevation <NUMBER>
* 2: Absolute windage <NUMBER>
* 3: Absolute zero reference <NUMBER>
*
* Return value:
* True <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit", "_elevation", "_windage", "_zero", "_adjustmentDifference", "_pitchbankyaw", "_pitch", "_bank", "_yaw"];
EXPLODE_4_PVT(_this,_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];
};
_adjustmentDifference = (_adjustment select _weaponIndex) vectorDiff [_elevation, _windage, _zero];
_adjustment set [_weaponIndex, [_elevation, _windage, _zero]];
[_unit, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
playSound (["ACE_Scopes_Click_1", "ACE_Scopes_Click_2", "ACE_Scopes_Click_3"] select floor random 3);
// slightly rotate the player if looking through optic
if (cameraView == "GUNNER") then {
// Convert adjustmentDifference from mils to degrees
_adjustmentDifference = [_adjustmentDifference, {_this * 0.05625}] call EFUNC(common,map);
_pitchbankyaw = [_unit] call EFUNC(common,getPitchBankYaw);
_pitch = (_pitchbankyaw select 0) + (_adjustmentDifference select 0);
_bank = (_pitchbankyaw select 1);
_yaw = (_pitchbankyaw select 2) + (_adjustmentDifference select 1);
[_unit, _pitch, _bank, _yaw] call EFUNC(common,setPitchBankYaw);
} else {
[] call FUNC(showZeroing);
};
true

View File

@ -1,46 +0,0 @@
/*
* Author: KoffeinFlummi
* Checks if a player can adjust his optic in the given way.
*
* Argument:
* 0: Unit <OBJECT>
* 1: Horizontal adjustment <NUMBER>
* 2: Vertical adjustment <NUMBER>
*
* Return value:
* Can adjustment be done? <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit", "_weaponIndex", "_zeroing", "_optic", "_maxHorizontal", "_maxVertical"];
_unit = _this select 0;
_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]];
};
if (isNil QGVAR(Optics)) then {
GVAR(Optics) = ["", "", ""];
};
_zeroing = _adjustment select _weaponIndex;
_zeroX = (_zeroing select 0) + (_this select 1);
_zeroY = (_zeroing select 1) + (_this select 2);
_optic = GVAR(Optics) select _weaponIndex;
_maxHorizontal = getArray (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_Horizontal");
_maxVertical = getArray (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_Vertical");
if ((count _maxHorizontal < 2) or (count _maxVertical < 2)) exitWith {false};
if ((_maxHorizontal isEqualTo [0,0]) or (_maxVertical isEqualTo [0,0])) exitWith {false};
if (_zeroX < _maxHorizontal select 0 or _zeroX > _maxHorizontal select 1) exitWith {false};
if (_zeroY < _maxVertical select 0 or _zeroY > _maxVertical select 1) exitWith {false};
vehicle _unit == _unit

View File

@ -0,0 +1,33 @@
/*
* Author: KoffeinFlummi, Ruthberg
* Changes the adjustment for the current scope
*
* Argument:
* 0: Unit <OBJECT>
*
* Return value:
* Can we update the zero reference? <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
if (cameraView == "GUNNER") exitWith {false};
if !(vehicle _unit == _unit) exitWith {false};
private ["_unit", "_adjustment", "_elevation"];
_unit = _this select 0;
_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]];
};
_elevation = (_adjustment select _weaponIndex) select 0;
// You can only adjust your zero reference, if your relative elevation setting is not 0
_elevation != 0

View File

@ -39,4 +39,4 @@ _zeroing = _adjustment select _weaponIndex;
// Convert zeroing from mils to degrees
_zeroing = [_zeroing, {_this * 0.05625}] call EFUNC(common,map);
[_projectile, _zeroing select 0, _zeroing select 1, 0] call EFUNC(common,changeProjectileDirection);
[_projectile, (_zeroing select 1), (_zeroing select 0) + (_zeroing select 2), 0] call EFUNC(common,changeProjectileDirection);

View File

@ -18,7 +18,8 @@ private ["_newOptics", "_adjustment"];
_adjustment = ACE_player getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
_adjustment = [[0,0], [0,0], [0,0]];
// [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);
};
@ -31,8 +32,8 @@ _newOptics = [_player] call FUNC(getOptics);
{
if (_newOptics select _forEachIndex != _x) then {
// The optic for this weapon changed, set adjustment to zero
if !((_adjustment select _foreachindex) isEqualTo [0,0]) then {
_adjustment set [_forEachIndex, [0,0]];
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);
};
};

View File

@ -21,7 +21,8 @@ if (_weaponIndex < 0) exitWith {};
_adjustment = ACE_player getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
_adjustment = [[0,0], [0,0], [0,0]];
// [Windage, Elevation, Zero]
_adjustment = [[0,0,0], [0,0,0], [0,0,0]];
};
// Display the adjustment knobs
@ -36,8 +37,8 @@ if (isNull _display) exitWith {};
_zeroing = _adjustment select _weaponIndex;
_vertical = _display displayCtrl 12;
_horizontal = _display displayCtrl 13;
_vertical ctrlSetText (str (_zeroing select 1));
_horizontal ctrlSetText (str (_zeroing select 0));
_vertical ctrlSetText (str (_zeroing select 0));
_horizontal ctrlSetText (str (_zeroing select 1));
// Set the time when to hide the knobs
GVAR(timeToHide) = diag_tickTime + 3.0;

View File

@ -1,6 +1,14 @@
#define COMPONENT scopes
#include "\z\ace\addons\main\script_mod.hpp"
#define ELEVATION_UP 0
#define ELEVATION_DOWN 1
#define WINDAGE_LEFT 2
#define WINDAGE_RIGHT 3
#define MINOR_INCREMENT false
#define MAJOR_INCREMENT true
#ifdef DEBUG_ENABLED_SCOPES
#define DEBUG_MODE_FULL
#endif

View File

@ -26,5 +26,8 @@
<Key ID="STR_ACE_Scopes_AdjustLeftMajor">
<English>Major adjustment left</English>
</Key>
<Key ID="STR_ACE_Scopes_AdjustZero">
<English>Set zero adjustment</English>
</Key>
</Package>
</Project>