2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-01-06 21:42:02 +00:00
|
|
|
/*
|
2024-07-27 12:43:07 +00:00
|
|
|
* Author: Original by Ryan Schultz, edited by KoffeinFlummi, commy2
|
2016-02-06 21:21:43 +00:00
|
|
|
* Adds camera shake when firing. Called from the unified fired EH only for the local player.
|
2016-01-06 21:42:02 +00:00
|
|
|
* From TMR: Small Arms
|
|
|
|
*
|
|
|
|
* Arguments:
|
2024-07-27 12:43:07 +00:00
|
|
|
* Parameters inherited from EFUNC(common,firedEH)
|
2016-01-06 21:42:02 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* None
|
2016-01-06 21:42:02 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2024-07-27 12:43:07 +00:00
|
|
|
* [player, currentWeapon player, currentMuzzle player] call ace_recoil_fnc_camshake
|
2016-01-06 21:42:02 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-04-25 05:21:11 +00:00
|
|
|
|
2016-02-06 21:21:43 +00:00
|
|
|
//IGNORE_PRIVATE_WARNING ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle", "_gunner", "_turret"];
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_10("firedEH:",_unit,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile,_vehicle,_gunner,_turret);
|
2016-02-06 21:21:43 +00:00
|
|
|
|
2015-04-25 05:21:11 +00:00
|
|
|
#define BASE_POWER 0.40
|
|
|
|
#define BASE_TIME 0.19
|
|
|
|
#define BASE_FREQ 13
|
|
|
|
#define RECOIL_COEF 40
|
|
|
|
|
2024-03-07 21:08:13 +00:00
|
|
|
if (toLowerANSI _weapon in ["throw", "put"]) exitWith {};
|
2015-04-25 05:21:11 +00:00
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _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));
|
2015-04-25 05:21:11 +00:00
|
|
|
|
2024-07-27 12:43:07 +00:00
|
|
|
// Get camshake read kickback
|
|
|
|
private _recoil = GVAR(recoilCache) getOrDefaultCall [_weapon + _muzzle, {
|
2016-01-06 21:42:02 +00:00
|
|
|
private _config = configFile >> "CfgWeapons" >> _weapon;
|
|
|
|
|
2024-07-27 12:43:07 +00:00
|
|
|
private _recoil = if (_muzzle == _weapon) then {
|
|
|
|
getText (_config >> "recoil")
|
2016-01-06 21:42:02 +00:00
|
|
|
} else {
|
2024-07-27 12:43:07 +00:00
|
|
|
getText (_config >> _muzzle >> "recoil")
|
2016-01-06 21:42:02 +00:00
|
|
|
};
|
2015-04-25 05:21:11 +00:00
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
if (isClass (configFile >> "CfgRecoils" >> _recoil)) then {
|
|
|
|
_recoil = getArray (configFile >> "CfgRecoils" >> _recoil >> "kickBack");
|
2024-07-27 12:43:07 +00:00
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
if (count _recoil < 2) then {
|
|
|
|
_recoil = [0, 0];
|
|
|
|
};
|
|
|
|
} else {
|
2015-04-28 17:31:38 +00:00
|
|
|
_recoil = [0, 0];
|
|
|
|
};
|
2015-04-25 05:21:11 +00:00
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
TRACE_3("Caching Recoil config",_weapon,_muzzle,_recoil);
|
|
|
|
|
2024-07-27 12:43:07 +00:00
|
|
|
// Ensure format is correct
|
|
|
|
_recoil resize [2, 0];
|
2015-04-25 05:21:11 +00:00
|
|
|
|
2024-07-27 12:43:07 +00:00
|
|
|
// Parse numbers
|
|
|
|
_recoil apply { if (_x isEqualType 0) then { _x } else { call compile format ["%1", _x] } } // return
|
|
|
|
}, true];
|
2016-01-06 21:42:02 +00:00
|
|
|
|
|
|
|
private _powerCoef = RECOIL_COEF * linearConversion [0, 1, random 1, _recoil select 0, _recoil select 1, false];
|
2015-04-25 05:21:11 +00:00
|
|
|
|
|
|
|
if (isWeaponRested _unit) then {_powerMod = _powerMod - 0.07};
|
|
|
|
if (isWeaponDeployed _unit) then {_powerMod = _powerMod - 0.11};
|
2024-08-05 09:38:26 +00:00
|
|
|
if (_weapon isEqualTo secondaryWeapon _unit) then {
|
|
|
|
_powerCoef = _powerCoef + 25.0;
|
|
|
|
};
|
2015-04-25 05:21:11 +00:00
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _camshake = [
|
2015-04-25 05:21:11 +00:00
|
|
|
_powerCoef * (BASE_POWER + _powerMod) max 0,
|
2016-01-06 21:42:02 +00:00
|
|
|
BASE_TIME,
|
|
|
|
BASE_FREQ
|
2015-04-25 05:21:11 +00:00
|
|
|
];
|
|
|
|
|
2019-03-21 13:52:32 +00:00
|
|
|
TRACE_4("addCamShake",_recoil,_powerCoef,_powerMod,_camshake);
|
2015-04-25 05:21:11 +00:00
|
|
|
|
|
|
|
addCamShake _camshake;
|