handle 2d optics recoil

This commit is contained in:
commy2 2015-04-04 06:19:19 +02:00
parent 9968bc132c
commit 98d217d97e
7 changed files with 147 additions and 3 deletions

View File

@ -10,3 +10,11 @@ class Extended_PostInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_postInit)); 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)};);
};
};
};

View File

@ -69,7 +69,7 @@ class RscInGameUI {
text = QUOTE(PATHTOF(reticles\hamr-reticle65Illum_ca.paa)); 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 { class BodyDay: ReticleDay {
idc = 1713005; idc = 1713005;
text = QUOTE(PATHTOF(reticles\hamr-body_ca.paa)); text = QUOTE(PATHTOF(reticles\hamr-body_ca.paa));

View File

@ -63,10 +63,12 @@ class CfgWeapons {
class Hamr2Collimator: Hamr2Collimator {}; class Hamr2Collimator: Hamr2Collimator {};
class Hamr2Scope: Hamr2Scope { class Hamr2Scope: Hamr2Scope {
// zoom 0.0872664626 to all
opticsDisplayName = "IHAMR"; // test?? opticsDisplayName = "IHAMR"; // test??
modelOptics = QUOTE(PATHTOF(models\ace_optics_pip.p3d)); modelOptics = QUOTE(PATHTOF(models\ace_optics_pip.p3d));
useModelOptics = 1; useModelOptics = 1;
opticsZoomInit = 0.0872664626;
opticsZoomMax = 0.0872664626;
opticsZoomMin = 0.0872664626;
opticsPPEffects[] += {"ACE_OpticsRadBlur1"}; opticsPPEffects[] += {"ACE_OpticsRadBlur1"};
opticsDisablePeripherialVision = 0; opticsDisablePeripherialVision = 0;
visionMode[] = {"Normal","NVG"}; visionMode[] = {"Normal","NVG"};

View File

@ -18,3 +18,10 @@
// @todo // @todo
//waitUntil {[] call AGM_Optics_fnc_mainLoop; False}; //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);

View File

@ -2,6 +2,7 @@
ADDON = false; ADDON = false;
PREP(handleFired);
PREP(onDrawScope); PREP(onDrawScope);
PREP(onDrawScopePIP); PREP(onDrawScopePIP);

View File

@ -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;

View File

@ -10,3 +10,18 @@
#endif #endif
#include "\z\ace\addons\main\script_macros.hpp" #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