From 12280bbcadf3ef46682aab21a12a9769208eb5da Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 25 Apr 2015 07:21:11 +0200 Subject: [PATCH] revive tmr camshake --- addons/recoil/CfgEventHandlers.hpp | 14 ++++ addons/recoil/CfgMoves.hpp | 85 ++++++++++++++++++++ addons/recoil/CfgRecoils.hpp | 4 +- addons/recoil/XEH_preInit.sqf | 8 ++ addons/recoil/config.cpp | 8 ++ addons/recoil/functions/fnc_camshake.sqf | 63 +++++++++++++++ addons/recoil/functions/script_component.hpp | 1 + 7 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 addons/recoil/CfgEventHandlers.hpp create mode 100644 addons/recoil/CfgMoves.hpp create mode 100644 addons/recoil/XEH_preInit.sqf create mode 100644 addons/recoil/functions/fnc_camshake.sqf create mode 100644 addons/recoil/functions/script_component.hpp diff --git a/addons/recoil/CfgEventHandlers.hpp b/addons/recoil/CfgEventHandlers.hpp new file mode 100644 index 0000000000..60fc3892fc --- /dev/null +++ b/addons/recoil/CfgEventHandlers.hpp @@ -0,0 +1,14 @@ + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_FiredBIS_EventHandlers { + class CAManBase { + class ADDON { + clientFiredBIS = QUOTE(if (_this select 0 == ACE_player) then {_this call FUNC(camshake)};); + }; + }; +}; diff --git a/addons/recoil/CfgMoves.hpp b/addons/recoil/CfgMoves.hpp new file mode 100644 index 0000000000..ecad382cb5 --- /dev/null +++ b/addons/recoil/CfgMoves.hpp @@ -0,0 +1,85 @@ + +// Completely disable BI's camshake on fire. +#define ACE_CAMSHAKEFIRE_BASE 0 +#define ACE_CAMSHAKEFIRE_LESS 0 +#define ACE_CAMSHAKEFIRE_MORE 0 + +// Go through all modes that have a camshakefire defined and change it to ours. +class CfgMovesBasic { + class Default { + camShakeFire = ACE_CAMSHAKEFIRE_NORMAL; + }; +}; + +class CfgMovesMaleSdr: CfgMovesBasic { + class States { + class AmovPercMstpSlowWrflDnon; + class AmovPknlMstpSlowWrflDnon: AmovPercMstpSlowWrflDnon { + camShakeFire = ACE_CAMSHAKEFIRE_LESS; + }; + + class AmovPercMstpSrasWrflDnon; + class AmovPpneMstpSrasWrflDnon: AmovPercMstpSrasWrflDnon { + camShakeFire = ACE_CAMSHAKEFIRE_LESS; + }; + + class AmovPknlMstpSrasWlnrDnon: Default { + camShakeFire = ACE_CAMSHAKEFIRE_LESS; + }; + + class AmovPknlMrunSlowWrflDf; + class AmovPknlMtacSlowWrflDf: AmovPknlMrunSlowWrflDf { + camShakeFire = ACE_CAMSHAKEFIRE_MORE; + }; + + class AmovPknlMrunSlowWrflDfl; + class AmovPknlMtacSlowWrflDfl: AmovPknlMrunSlowWrflDfl { + camShakeFire = ACE_CAMSHAKEFIRE_MORE; + }; + + class AmovPknlMrunSlowWrflDl; + class AmovPknlMtacSlowWrflDl: AmovPknlMrunSlowWrflDl { + camShakeFire = ACE_CAMSHAKEFIRE_MORE; + }; + + class AmovPknlMrunSlowWrflDbl; + class AmovPknlMtacSlowWrflDbl: AmovPknlMrunSlowWrflDbl { + camShakeFire = ACE_CAMSHAKEFIRE_MORE; + }; + + class AmovPknlMrunSlowWrflDb; + class AmovPknlMtacSlowWrflDb: AmovPknlMrunSlowWrflDb { + camShakeFire = ACE_CAMSHAKEFIRE_MORE; + }; + + class AmovPknlMrunSlowWrflDbr; + class AmovPknlMtacSlowWrflDbr: AmovPknlMrunSlowWrflDbr { + camShakeFire = ACE_CAMSHAKEFIRE_MORE; + }; + + class AmovPknlMrunSlowWrflDr; + class AmovPknlMtacSlowWrflDr: AmovPknlMrunSlowWrflDr { + camShakeFire = ACE_CAMSHAKEFIRE_MORE; + }; + + class AmovPknlMrunSlowWrflDfr; + class AmovPknlMtacSlowWrflDfr: AmovPknlMrunSlowWrflDfr { + camShakeFire = ACE_CAMSHAKEFIRE_MORE; + }; + + class AmovPknlMstpSrasWrflDnon; + class AmovPknlMwlkSrasWrflDf: AmovPknlMstpSrasWrflDnon { + camShakeFire = ACE_CAMSHAKEFIRE_NORMAL; + }; + + class AmovPknlMrunSrasWrflDf; + class AmovPknlMtacSrasWrflDf: AmovPknlMrunSrasWrflDf { + camShakeFire = ACE_CAMSHAKEFIRE_MORE; + }; + + class AmovPknlMwlkSrasWpstDf; + class AmovPknlMtacSrasWpstDf: AmovPknlMwlkSrasWpstDf { + camShakeFire = ACE_CAMSHAKEFIRE_MORE; + }; + }; +}; diff --git a/addons/recoil/CfgRecoils.hpp b/addons/recoil/CfgRecoils.hpp index 76bad23fb1..4b473919d5 100644 --- a/addons/recoil/CfgRecoils.hpp +++ b/addons/recoil/CfgRecoils.hpp @@ -1,11 +1,11 @@ #define KICKBACK 1.4 -#define MUZZLETEMP 1 +#define MUZZLETEMP 1.2 #define MUZZLEPERM 0.4 #define MUZZLECLIMB_POS 1 -#define MUZZLERIGHT_POS 0.4 +#define MUZZLERIGHT_POS 0.2 #define MUZZLECLIMB_MAG 1 #define MUZZLERIGHT_MAG 1 diff --git a/addons/recoil/XEH_preInit.sqf b/addons/recoil/XEH_preInit.sqf new file mode 100644 index 0000000000..f6d04886c1 --- /dev/null +++ b/addons/recoil/XEH_preInit.sqf @@ -0,0 +1,8 @@ +// by commy2 +#include "script_component.hpp" + +ADDON = false; + +PREP(camshake); + +ADDON = true; diff --git a/addons/recoil/config.cpp b/addons/recoil/config.cpp index 1e2ce69fae..5b8002bc37 100644 --- a/addons/recoil/config.cpp +++ b/addons/recoil/config.cpp @@ -12,4 +12,12 @@ class CfgPatches { }; }; +#include "CfgEventHandlers.hpp" + +#include "CfgMoves.hpp" #include "CfgRecoils.hpp" + +class CfgCameraShake { + // What does this do, really? It seems like the engine no longer respects it. + defaultCaliberCoefWeaponFire = 0; +}; diff --git a/addons/recoil/functions/fnc_camshake.sqf b/addons/recoil/functions/fnc_camshake.sqf new file mode 100644 index 0000000000..737582b1cb --- /dev/null +++ b/addons/recoil/functions/fnc_camshake.sqf @@ -0,0 +1,63 @@ +// TMR: Small Arms - Recoil initialization and functions +// (C) 2013 Ryan Schultz. See LICENSE. +// Edited prefixes for compatability in AGM_Realism by KoffeinFlummi +// Edited by commy2 +#include "script_component.hpp" + +#define BASE_POWER 0.40 +#define BASE_TIME 0.19 +#define BASE_FREQ 13 +#define RECOIL_COEF 40 + +private ["_unit", "_weapon", "_muzzle"]; + +_unit = _this select 0; +_weapon = _this select 1; +_muzzle = _this select 2; + +if (toLower _weapon in ["throw", "put"]) exitWith {}; + +private ["_powerMod", "_timeMod", "_freqMod"]; + +_powerMod = ([0, -0.1, -0.1, 0, -0.2] select (["STAND", "CROUCH", "PRONE", "UNDEFINED", ""] find stance _unit)) + ([0, -1, 0, -1] select (["INTERNAL", "EXTERNAL", "GUNNER", "GROUP"] find cameraView)); +_timeMod = 0; +_freqMod = 0; + +// to get camshake read kickback +private ["_config", "_recoil"]; + +_config = configFile >> "CfgWeapons" >> _weapon; +_recoil = if (_muzzle == _weapon) then { + getText (_config >> "recoil") +} else { + getText (_config >> _muzzle >> "recoil") +}; + +_recoil = getArray (configFile >> "CfgRecoils" >> _recoil >> "kickBack"); +if (count _recoil < 2) then { + _recoil = [0, 0]; +}; + +// parse numbers +_recoil set [0, call compile format ["%1", _recoil select 0]]; +_recoil set [1, call compile format ["%1", _recoil select 1]]; + +private "_powerCoef"; +_powerCoef = RECOIL_COEF * linearConversion [0, 1, random 1, _recoil select 0, _recoil select 1, false]; + +if (isWeaponRested _unit) then {_powerMod = _powerMod - 0.07}; +if (isWeaponDeployed _unit) then {_powerMod = _powerMod - 0.11}; + +private "_camshake"; +_camshake = [ + _powerCoef * (BASE_POWER + _powerMod) max 0, + BASE_TIME + _timeMod max 0, + BASE_FREQ + _freqMod max 0 +]; + +/* + systemChat str _camshake; + copyToClipboard format ["addCamShake %1;", _camshake]; +*/ + +addCamShake _camshake; diff --git a/addons/recoil/functions/script_component.hpp b/addons/recoil/functions/script_component.hpp new file mode 100644 index 0000000000..d66ac7aec3 --- /dev/null +++ b/addons/recoil/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\overpressure\script_component.hpp" \ No newline at end of file