Skip to content

Commit

Permalink
Implement environment fading, camo and audible coef setting
Browse files Browse the repository at this point in the history
  • Loading branch information
drzdo committed Aug 3, 2024
1 parent 4b7a6b3 commit 7b09edc
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 33 deletions.
1 change: 1 addition & 0 deletions addons/movement/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ PREP(speedPFH);
PREP(getStance);
PREP(getSpeed);
PREP(onLoad);
PREP(updateEnvVolume);
28 changes: 14 additions & 14 deletions addons/movement/functions/fnc_getSpeed.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
/*
* Author: Eric
* Get's the player's CE:M Speed
*
*
* Arguments:
* None
*
*
* Return Value:
* Speed <ARRAY>
* - Animation type <STRING>
* - Animation speed <NUMBER>
*
*
* Example:
* [] call cem_movement_fnc_getSpeed
*
*
* Public: Yes
*/

Expand All @@ -27,28 +27,28 @@ private _weapon = (_animation select [17,3]);
private _direction = (_animation select [21,3]);

/* If limping return max of 2 */
if (_movement isEqualTo "lmp") exitWith {
(GVAR(speeds) select (GVAR(speed) min 2)) + [cem_movement_speed];
if (_movement isEqualTo "lmp") exitWith {
(GVAR(speeds) select (GVAR(speed) min 2)) + [cem_movement_speed];
};

/* If unit is not moving */
if (_action isNotEqualTo "mov") exitWith {
["JOG", 1, 7]
if (_action isNotEqualTo "mov" && _action isNotEqualTo "adj") exitWith {
["JOG", 1, 7]
};

/* If weapon is lowered */
if (_stance isEqualTo "low") exitWith {
["JOG", 1, 7]
if (_stance isEqualTo "low") exitWith {
["JOG", 1, 7]
};

/* If is sprinting */
if (_movement isEqualTo "eva") exitWith {
["JOG", 1, 7]
if (_movement isEqualTo "eva") exitWith {
["JOG", 1, 7]
};

/* If is prone */
if (_pose isEqualTo "pne") exitWith {
["JOG", 1, 7]
if (_pose isEqualTo "pne") exitWith {
["JOG", 1, 7]
};

(GVAR(speeds) select GVAR(speed)) + [cem_movement_speed];
16 changes: 11 additions & 5 deletions addons/movement/functions/fnc_speedPFH.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
/*
* Author: Eric
* Handles movement speed changes
*
*
* Arguments:
* None
*
*
* Return Value:
* None
*
*
* Example:
* [] call cem_movement_fnc_speedPFH
*
*
* Public: No
*/

Expand All @@ -34,5 +34,11 @@ if (GVAR(oldSpeed) isNotEqualTo _speed) then {
// Setting speedcoef every frame to make compatible with other mods
// Allow overriding by other modders / scripters
if (!GVAR(override)) then {
[cem_player, (_speed select 1)] remoteExec ["setAnimSpeedCoef"];
private _speedCoeff = (_speed select 1);
[cem_player, _speedCoeff] remoteExec ["setAnimSpeedCoef"];

// _speedCoeff is in range [0.5, 1], _coeff in [0, 1].
private _coeff = (_speedCoeff - 0.5) * 2;
[cem_player, ["camouflageCoef", (_coeff max GVAR(camouflageCoefMin)) min GVAR(camouflageCoefMax)]] remoteExec ["setUnitTrait"];
[cem_player, ["audibleCoef", (_coeff max GVAR(audibleCoefMin)) min GVAR(audibleCoefMax)]] remoteExec ["setUnitTrait"];
};
18 changes: 18 additions & 0 deletions addons/movement/functions/fnc_updateEnvVolume.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "script_component.hpp"
/*
* Author: Dmitrii Zganiaiko
* Updates environment volume based on the selected speed.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call cem_movement_fnc_updateEnvVolume
*
* Public: No
*/

GVAR(envFadeTime) fadeEnvironment (((GVAR(speed) / 7.0) max GVAR(envVolumeMin)) min GVAR(envVolumeMax));
37 changes: 23 additions & 14 deletions addons/movement/initKeybinds.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ private _category = format ["CE: %1", localize LSTRING(Category)];
_category,
QGVAR(movementSpeedUp),
[
localize LSTRING(MovementSpeedUp),
localize LSTRING(MovementSpeedUp),
localize LSTRING(MovementSpeedUpTooltip)
],
],
{
/* If limping return max of 2 */
if ((toUpper ((animationState cem_player) select [8,4])) isEqualTo "MLMP") exitWith { GVAR(speed) = (GVAR(speed) + 1) min 2; };
if ((toUpper ((animationState cem_player) select [8,4])) isEqualTo "MLMP") exitWith {
GVAR(speed) = (GVAR(speed) + 1) min 2;
[] call cem_movement_fnc_updateEnvVolume;
};
GVAR(speed) = (GVAR(speed) + 1) min 7;
},
[] call cem_movement_fnc_updateEnvVolume;
},
{ },
[
INPUT_MOUSE_SCROLL_UP,
INPUT_MOUSE_SCROLL_UP,
[false, true, false]
]
] call CBA_fnc_addKeybind;
Expand All @@ -26,15 +30,16 @@ private _category = format ["CE: %1", localize LSTRING(Category)];
_category,
QGVAR(movementSpeedDown),
[
localize LSTRING(MovementSpeedDown),
localize LSTRING(MovementSpeedDown),
localize LSTRING(MovementSpeedDownTooltip)
],
],
{
GVAR(speed) = (GVAR(speed) - 1) max 0;
},
[] call cem_movement_fnc_updateEnvVolume;
},
{ },
[
INPUT_MOUSE_SCROLL_DOWN,
INPUT_MOUSE_SCROLL_DOWN,
[false, true, false]
]
] call CBA_fnc_addKeybind;
Expand All @@ -43,16 +48,20 @@ private _category = format ["CE: %1", localize LSTRING(Category)];
_category,
QGVAR(movementSpeedReset),
[
localize LSTRING(MovementSpeedReset),
localize LSTRING(MovementSpeedReset),
localize LSTRING(MovementSpeedResetTooltip)
],
],
{
if ((toUpper ((animationState cem_player) select [8,4])) isEqualTo "MLMP") exitWith { GVAR(speed) = 2; };
if ((toUpper ((animationState cem_player) select [8,4])) isEqualTo "MLMP") exitWith {
GVAR(speed) = 2;
[] call cem_movement_fnc_updateEnvVolume;
};
GVAR(speed) = 7;
},
[] call cem_movement_fnc_updateEnvVolume;
},
{ },
[
INPUT_MOUSE_SCROLL,
INPUT_MOUSE_SCROLL,
[false, true, false]
]
] call CBA_fnc_addKeybind;
57 changes: 57 additions & 0 deletions addons/movement/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,60 @@ private _category = format ["CE: %1", localize LSTRING(Category)];
false,
{ }
] call CBA_fnc_addSetting;

[
QGVAR(camouflageCoefMin),
"SLIDER",
["Camouflage Coef Min", "Minimum camouflage coef when speed is minimal"],
_category,
[0.0, 1.0, 0.1, 2]
] call CBA_fnc_addSetting;

[
QGVAR(camouflageCoefMax),
"SLIDER",
["Camouflage Coef Max", "Max camouflage coef when speed is max"],
_category,
[0.0, 1.0, 0.8, 2]
] call CBA_fnc_addSetting;

[
QGVAR(audibleCoefMin),
"SLIDER",
["Audible Coef Min", "Minimum Audible coef when speed is minimal"],
_category,
[0.0, 1.0, 0.1, 2]
] call CBA_fnc_addSetting;

[
QGVAR(audibleCoefMax),
"SLIDER",
["Audible Coef Max", "Max Audible coef when speed is max"],
_category,
[0.0, 1.0, 0.8, 2]
] call CBA_fnc_addSetting;

[
QGVAR(envVolumeMin),
"SLIDER",
["Env Volume Min", "When speed is min"],
_category,
[0.0, 1.0, 0.05, 2]
] call CBA_fnc_addSetting;

[
QGVAR(envVolumeMax),
"SLIDER",
["Env Volume Max", "When speed is max"],
_category,
[0.0, 1.0, 1.0, 2]
] call CBA_fnc_addSetting;

[
QGVAR(envFadeTime),
"SLIDER",
["Environment Fade Duration (sec)", "How fast environment volume is change"],
_category,
[0.1, 20.0, 5.0, 1]
] call CBA_fnc_addSetting;

0 comments on commit 7b09edc

Please sign in to comment.