From 98d217d97e41d14863080d4d6885c9be53813a3f Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 4 Apr 2015 06:19:19 +0200 Subject: [PATCH] handle 2d optics recoil --- addons/optics/CfgEventHandlers.hpp | 8 ++ addons/optics/CfgRscTitles.hpp | 2 +- addons/optics/CfgWeapons.hpp | 4 +- addons/optics/XEH_postInit.sqf | 7 ++ addons/optics/XEH_preInit.sqf | 1 + addons/optics/functions/fnc_handleFired.sqf | 111 ++++++++++++++++++++ addons/optics/script_component.hpp | 17 ++- 7 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 addons/optics/functions/fnc_handleFired.sqf diff --git a/addons/optics/CfgEventHandlers.hpp b/addons/optics/CfgEventHandlers.hpp index 0cd959a047..6c6e824b16 100644 --- a/addons/optics/CfgEventHandlers.hpp +++ b/addons/optics/CfgEventHandlers.hpp @@ -10,3 +10,11 @@ class Extended_PostInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_postInit)); }; }; + +class Extended_FiredBIS_EventHandlers { + class CAManBase { + class AGM_Optics { + clientFiredBIS = QUOTE(if (_this select 0 == ACE_player) then {_this call DFUNC(handleFired)};); + }; + }; +}; diff --git a/addons/optics/CfgRscTitles.hpp b/addons/optics/CfgRscTitles.hpp index 2f6703dd42..ec92a9a3cc 100644 --- a/addons/optics/CfgRscTitles.hpp +++ b/addons/optics/CfgRscTitles.hpp @@ -69,7 +69,7 @@ class RscInGameUI { text = QUOTE(PATHTOF(reticles\hamr-reticle65Illum_ca.paa)); }; - #define SIZEX 1.54/(getResolution select 5) + #define SIZEX 2*0.76/(getResolution select 5) class BodyDay: ReticleDay { idc = 1713005; text = QUOTE(PATHTOF(reticles\hamr-body_ca.paa)); diff --git a/addons/optics/CfgWeapons.hpp b/addons/optics/CfgWeapons.hpp index 60f52e5a1b..ab4c2e76bb 100644 --- a/addons/optics/CfgWeapons.hpp +++ b/addons/optics/CfgWeapons.hpp @@ -63,10 +63,12 @@ class CfgWeapons { class Hamr2Collimator: Hamr2Collimator {}; class Hamr2Scope: Hamr2Scope { - // zoom 0.0872664626 to all opticsDisplayName = "IHAMR"; // test?? modelOptics = QUOTE(PATHTOF(models\ace_optics_pip.p3d)); useModelOptics = 1; + opticsZoomInit = 0.0872664626; + opticsZoomMax = 0.0872664626; + opticsZoomMin = 0.0872664626; opticsPPEffects[] += {"ACE_OpticsRadBlur1"}; opticsDisablePeripherialVision = 0; visionMode[] = {"Normal","NVG"}; diff --git a/addons/optics/XEH_postInit.sqf b/addons/optics/XEH_postInit.sqf index de8d6c28da..04bb6bcb63 100644 --- a/addons/optics/XEH_postInit.sqf +++ b/addons/optics/XEH_postInit.sqf @@ -18,3 +18,10 @@ // @todo //waitUntil {[] call AGM_Optics_fnc_mainLoop; False}; }; + +// save control for fired EH +["infoDisplayChanged", { + if (!isNull ((_this select 0) displayCtrl 1713001)) then { + uiNamespace setVariable [QGVAR(RscWeaponInfoPIP), _this select 0]; + }; +}] call EFUNC(common,addEventHandler); diff --git a/addons/optics/XEH_preInit.sqf b/addons/optics/XEH_preInit.sqf index e4b7bbe2e0..a681bfe04f 100644 --- a/addons/optics/XEH_preInit.sqf +++ b/addons/optics/XEH_preInit.sqf @@ -2,6 +2,7 @@ ADDON = false; +PREP(handleFired); PREP(onDrawScope); PREP(onDrawScopePIP); diff --git a/addons/optics/functions/fnc_handleFired.sqf b/addons/optics/functions/fnc_handleFired.sqf new file mode 100644 index 0000000000..a4c546a6bf --- /dev/null +++ b/addons/optics/functions/fnc_handleFired.sqf @@ -0,0 +1,111 @@ +/* + * Original Author: Taosenai + * Adapted By: KoffeinFlummi, commy2 + * + * Animates the scope when firing. + * + * Arguments: + * 0: Unit (Object) + * 1: Weapon (String) + * 2: Muzzle (String) + * 3: Mode (String) + * 4: Ammo (Object) + * 5: Magazine (String) + * 6: Projectile (Object) + * + * Return Value: + * None + */ +#include "script_component.hpp" + +private ["_unit", "_weapon"]; + +_unit = _this select 0; +_weapon = _this select 1; + +// check if compatible scope is used +private "_display"; +_display = uiNamespace getVariable [QGVAR(RscWeaponInfoPIP), displayNull]; + +if (isNull _display) exitWith {}; + +// Reduce the reticle movement as the player drops into lower, supported stances. +private "_recoilCoef"; +_recoilCoef = switch (true) do { + case (isWeaponDeployed _unit): {0.1}; + case (isWeaponRested _unit): {0.4}; + default {1}; +}; + +// Constants which determine how the scope recoils +private ["_recoilScope", "_reticleShiftX", "_reticleShiftY", "_scopeShiftX", "_scopeShiftY"]; + +_recoilScope = _recoilCoef * linearConversion [0, 1, random 1, SCOPE_RECOIL_MIN, SCOPE_RECOIL_MAX, false]; + +_reticleShiftX = _recoilCoef * linearConversion [0, 1, random 1, RETICLE_SHIFT_X_MIN, RETICLE_SHIFT_X_MAX, false]; +_reticleShiftY = _recoilCoef * linearConversion [0, 1, random 1, RETICLE_SHIFT_Y_MIN, RETICLE_SHIFT_Y_MAX, false]; + +_scopeShiftX = _recoilCoef * linearConversion [0, 1, random 1, SCOPE_SHIFT_X_MIN, SCOPE_SHIFT_X_MAX, false]; +_scopeShiftY = _recoilCoef * linearConversion [0, 1, random 1, SCOPE_SHIFT_Y_MIN, SCOPE_SHIFT_Y_MAX, false]; + +// Create and commit recoil effect +private ["_sizeX", "_sizeY"]; + +_sizeX = (0.76+_recoilScope)/(getResolution select 5); +_sizeY = _sizeX*safezoneW/safezoneH; + +private "_positionReticle"; +_positionReticle = [ + safezoneX+0.5*safezoneW-0.5*(_sizeX+_reticleShiftX), + safezoneY+0.5*safezoneH-0.5*(_sizeY+_reticleShiftY), + _sizeX, + _sizeY +]; + +(_display displayCtrl 1713001) ctrlSetPosition _positionReticle; +(_display displayCtrl 1713002) ctrlSetPosition _positionReticle; + +private "_positionBody"; +_positionBody = [ + safezoneX+0.5*safezoneW-0.5*(2*_sizeX+_scopeShiftX), + safezoneY+0.5*safezoneH-0.5*(2*_sizeY+_scopeShiftY), + 2*_sizeX, + 2*_sizeY +]; + +(_display displayCtrl 1713005) ctrlSetPosition _positionBody; +(_display displayCtrl 1713006) ctrlSetPosition _positionBody; + +(_display displayCtrl 1713001) ctrlCommit 0; +(_display displayCtrl 1713002) ctrlCommit 0; +(_display displayCtrl 1713005) ctrlCommit 0; +(_display displayCtrl 1713006) ctrlCommit 0; + +// Bring them all back +_sizeX = 0.76/(getResolution select 5); +_sizeY = _sizeX*safezoneW/safezoneH; + +_positionReticle = [ + safezoneX+0.5*safezoneW-0.5*_sizeX, + safezoneY+0.5*safezoneH-0.5*_sizeY, + _sizeX, + _sizeY +]; + +(_display displayCtrl 1713001) ctrlSetPosition _positionReticle; +(_display displayCtrl 1713002) ctrlSetPosition _positionReticle; + +_positionBody = [ + safezoneX+0.5*safezoneW-0.5*2*_sizeX, + safezoneY+0.5*safezoneH-0.5*2*_sizeY, + 2*_sizeX, + 2*_sizeY +]; + +(_display displayCtrl 1713005) ctrlSetPosition _positionBody; +(_display displayCtrl 1713006) ctrlSetPosition _positionBody; + +(_display displayCtrl 1713001) ctrlCommit RECENTER_TIME; +(_display displayCtrl 1713002) ctrlCommit RECENTER_TIME; +(_display displayCtrl 1713005) ctrlCommit RECENTER_TIME; +(_display displayCtrl 1713006) ctrlCommit RECENTER_TIME; diff --git a/addons/optics/script_component.hpp b/addons/optics/script_component.hpp index 94d0bab5dc..58b2d4756a 100644 --- a/addons/optics/script_component.hpp +++ b/addons/optics/script_component.hpp @@ -9,4 +9,19 @@ #define DEBUG_SETTINGS DEBUG_ENABLED_OPTICS #endif -#include "\z\ace\addons\main\script_macros.hpp" \ No newline at end of file +#include "\z\ace\addons\main\script_macros.hpp" + +#define SCOPE_RECOIL_MIN 0.03 +#define SCOPE_RECOIL_MAX 0.032 + +#define SCOPE_SHIFT_X_MIN 0.04 +#define SCOPE_SHIFT_X_MAX 0.05 +#define SCOPE_SHIFT_Y_MIN -0.02 +#define SCOPE_SHIFT_Y_MAX -0.03 + +#define RETICLE_SHIFT_X_MIN 0.006 +#define RETICLE_SHIFT_X_MAX 0.011 +#define RETICLE_SHIFT_Y_MIN -0.009 +#define RETICLE_SHIFT_Y_MAX -0.014 + +#define RECENTER_TIME 0.09