diff --git a/addons/missionmodules/$PBOPREFIX$ b/addons/missionmodules/$PBOPREFIX$ new file mode 100644 index 0000000000..ea1be0daee --- /dev/null +++ b/addons/missionmodules/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\missionModules \ No newline at end of file diff --git a/addons/missionmodules/CfgEventHandlers.hpp b/addons/missionmodules/CfgEventHandlers.hpp new file mode 100644 index 0000000000..f0a9f14d91 --- /dev/null +++ b/addons/missionmodules/CfgEventHandlers.hpp @@ -0,0 +1,6 @@ + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; diff --git a/addons/missionmodules/CfgFactionClasses.hpp b/addons/missionmodules/CfgFactionClasses.hpp new file mode 100644 index 0000000000..792f4d31e3 --- /dev/null +++ b/addons/missionmodules/CfgFactionClasses.hpp @@ -0,0 +1,6 @@ +class CfgFactionClasses { + class NO_CATEGORY; + class ACE_missionModules: NO_CATEGORY { + displayName = "ACE Mission Modules"; + }; +}; \ No newline at end of file diff --git a/addons/missionmodules/CfgVehicles.hpp b/addons/missionmodules/CfgVehicles.hpp new file mode 100644 index 0000000000..afdb58006b --- /dev/null +++ b/addons/missionmodules/CfgVehicles.hpp @@ -0,0 +1,68 @@ +class CfgVehicles { + class Logic; + class Module_F: Logic { + class ArgumentsBaseUnits { + }; + }; + + // TODO make a curator variant for this + class ACE_moduleAmbianceSound: Module_F { + scope = 2; + displayName = "Ambiance Sounds [ACE]"; + icon = QUOTE(PATHTOF(data\moduleSound.paa)); + category = "ACE_missionModules"; + function = QUOTE(FUNC(moduleAmbianceSound); + functionPriority = 1; + isGlobal = 1; + isTriggerActivated = 0; + author = "Glowbal"; + class Arguments { + class soundFiles { + displayName = "Sounds"; + description = "Classnames of the ambiance sounds played. Seperated by ','. "; + typeName = "STRING"; + defaultValue = ""; + }; + class minimalDistance { + displayName = "Minimal Distance"; + description = "Minimal Distance"; + typeName = "NUMBER"; + defaultValue = 400; + }; + class maximalDistance { + displayName = "Maximal Distance"; + description = "Maximal Distance"; + typeName = "NUMBER"; + defaultValue = 900; + }; + class minimalDelay { + displayName = "Minimal Delay"; + description = "Minimal Delay between sounds played"; + typeName = "NUMBER"; + defaultValue = 10; + }; + class maximalDelay { + displayName = "Maximal Delay"; + description = "Maximal Delay between sounds played"; + typeName = "NUMBER"; + defaultValue = 170; + }; + class followPlayers { + displayName = "Follow Players"; + description = "Follow players. If set to false, loop will play sounds only nearby logic position."; + typeName = "BOOL"; + defaultValue = 0; + }; + class soundVolume { + displayName = "Volume"; + description = "The volume of the sounds played"; + typeName = "NUMBER"; + defaultValue = 0; + }; + }; + class ModuleDescription { + description = "Ambiance sounds loop (synced across MP)"; + sync[] = {}; + }; + }; +}; diff --git a/addons/missionmodules/XEH_preInit.sqf b/addons/missionmodules/XEH_preInit.sqf new file mode 100644 index 0000000000..cadbbabdd1 --- /dev/null +++ b/addons/missionmodules/XEH_preInit.sqf @@ -0,0 +1,7 @@ +#include "script_component.hpp" + +ADDON = false; + +PREP(moduleAmbianceSound); + +ADDON = true; diff --git a/addons/missionmodules/config.cpp b/addons/missionmodules/config.cpp new file mode 100644 index 0000000000..0867b486c6 --- /dev/null +++ b/addons/missionmodules/config.cpp @@ -0,0 +1,17 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {"cse_moduleAmbianceSound"}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_common"}; + author[] = {"Glowbal"}; + authorUrl = ""; + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" +#include "CfgFactionClasses.hpp" +#include "CfgVehicles.hpp" diff --git a/addons/missionmodules/data/moduleSound.paa b/addons/missionmodules/data/moduleSound.paa new file mode 100644 index 0000000000..bfe3b80327 Binary files /dev/null and b/addons/missionmodules/data/moduleSound.paa differ diff --git a/addons/missionmodules/functions/fnc_moduleAmbianceSound.sqf b/addons/missionmodules/functions/fnc_moduleAmbianceSound.sqf new file mode 100644 index 0000000000..95153be8d1 --- /dev/null +++ b/addons/missionmodules/functions/fnc_moduleAmbianceSound.sqf @@ -0,0 +1,123 @@ +/* + * Author: Glowbal + * Plays synchronized ambiance sounds while the module is alive. + * + * Arguments: + * 0: Logic + * 1: Units + * 2: Activated + * + * Return Value: + * Nothing + * + * Example: + * N/A + * + * Public: No + */ + +#include "script_component.hpp" + +private ["_logic", "_units", "_activated","_ambianceSounds", "_soundFiles", "_minimalDistance","_maximalDistance", "_minimalDistance", "_maxDelayBetweenSounds", "_allUnits", "_newPos", "_targetUnit", "_soundToPlay", "_soundPath", "_unparsedSounds", "_list", "_splittedList", "_nilCheckPassedList"]; +_logic = [_this,0,objNull,[objNull]] call BIS_fnc_param; +_units = [_this,1,[],[[]]] call BIS_fnc_param; +_activated = [_this,2,true,[true]] call BIS_fnc_param; + +// We only play this on the locality of the logic, since the sounds are broadcasted across the network +if (_activated && local _logic) then { + _ambianceSounds = []; + _unparsedSounds = _logic getvariable ["soundFiles", ""]; + _minimalDistance = (_logic getvariable ["minimalDistance", 400]) max 1; + _maximalDistance = (_logic getvariable ["maximalDistance", 10]) max _minimalDistance; + _minDelayBetweensounds = (_logic getvariable ["minimalDelay", 10]) max 1; + _maxDelayBetweenSounds = (_logic getvariable ["maximalDelay", 170]) max _minDelayBetweensounds; + _volume = (_logic getvariable ["soundVolume", 30]) max 1; + _followPlayers = _logic getvariable ["followPlayers", false]; + + _splittedList = [_unparsedSounds, ","] call BIS_fnc_splitString; + + _nilCheckPassedList = ""; + { + _x = [_x] call EFUNC(common,removeWhiteSpace); + _splittedList set [_foreachIndex, _x]; + }foreach _splittedList; + + _soundPath = [(str missionConfigFile), 0, -15] call BIS_fnc_trimString; + { + if (isclass (missionConfigFile >> "CfgSounds" >> _x)) then { + _ambianceSounds pushback (_soundPath + (getArray(missionConfigFile >> "CfgSounds" >> _x >> "sound") select 0)); + } else { + if (isclass (configFile >> "CfgSounds" >> _x)) then { + _ambianceSounds pushback ((getArray(configFile >> "CfgSounds" >> _x >> "sound") select 0)); + }; + }; + }foreach _splittedList; + + if (count _ambianceSounds == 0) exitwith {}; + { + if !([".", _x, true] call BIS_fnc_inString) then { + _ambianceSounds set [_foreachIndex, _x + ".wss"]; + }; + }foreach _ambianceSounds; + + [{ + private ["_args", "_logic", "_ambianceSounds", "_minimalDistance", "_maximalDistance", "_minDelayBetweensounds", "_maxDelayBetweenSounds", "_volume", "_followPlayers","_lastTimePlayed", "_newPos"] + _args = _this select 0; + _logic = _args select 0; + _lastTimePlayed = _args select 8; + + if (!alive _logic) exitwith { + [(_this select 1)] call cba_fnc_removePerFrameHandler; + }; + + if (_lastTimePlayed - time >= ((_minDelayBetweensounds + random(_maxDelayBetweenSounds)) min _maxDelayBetweenSounds)) then { + _ambianceSounds = _args select 1; + _minimalDistance = _args select 2; + _maximalDistance = _args select 3; + _minDelayBetweensounds = _args select 4; + _maxDelayBetweenSounds = _args select 5; + _volume = _args select 6; + _followPlayers = _args select 7; + + // Find all players in session. + _allUnits = if (isMultiplayer) then {playableUnits} else {[ACE_player]}; + + // Check if there are enough players to even start playing this sound. + if (count _allUnits > 0) then { + + // Select a target unit at random. + _targetUnit = _allUnits select (round(random((count _allUnits)-1))); + + // find the position from which we are going to play this sound from. + _newPos = (getPos _targetUnit); + if (!_followPlayers) then { + _newPos = getPos _logic; + }; + + // Randomize this position. + if (random(1) >= 0.5) then { + if (random(1) >= 0.5) then { + _newPos set [0, (_newPos select 0) + (_minimalDistance + random(_maximalDistance))]; + } else { + _newPos set [0, (_newPos select 0) - (_minimalDistance + random(_maximalDistance))]; + }; + } else { + if (random(1) >= 0.5) then { + _newPos set [1, (_newPos select 1) + (_minimalDistance + random(_maximalDistance))]; + } else { + _newPos set [1, (_newPos select 1) - (_minimalDistance + random(_maximalDistance))]; + }; + }; + + // If no unit is to close to this position, we will play the sound. + if ({(_newPos distance _x < (_minimalDistance / 2))}count _allUnits == 0) then { + + playSound3D [_ambianceSounds select (round(random((count _ambianceSounds)-1))), ObjNull, false, _newPos, _volume, 1, 1000]; + _args set [8, time]; + }; + }; + }; + }, 0.1, [_logic, _ambianceSounds, _minimalDistance, _maximalDistance, _minDelayBetweensounds, _maxDelayBetweenSounds, _volume, _followPlayers, time] ] call CBA_fnc_addPerFrameHandler; +}; + +true; diff --git a/addons/missionmodules/functions/script_component.hpp b/addons/missionmodules/functions/script_component.hpp new file mode 100644 index 0000000000..42d34d4801 --- /dev/null +++ b/addons/missionmodules/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\missionmodules\script_component.hpp" \ No newline at end of file diff --git a/addons/missionmodules/script_component.hpp b/addons/missionmodules/script_component.hpp new file mode 100644 index 0000000000..a567966c7b --- /dev/null +++ b/addons/missionmodules/script_component.hpp @@ -0,0 +1,12 @@ +#define COMPONENT missionModules +#include "\z\ace\addons\main\script_mod.hpp" + +#ifdef DEBUG_ENABLED_MISSIONMODULES + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_MISSIONMODULES + #define DEBUG_SETTINGS DEBUG_SETTINGS_MISSIONMODULES +#endif + +#include "\z\ace\addons\main\script_macros.hpp" \ No newline at end of file