|
| 1 | +#include "script_component.hpp" |
| 2 | +/* |
| 3 | + * Author: ACRE2Team |
| 4 | + * Gets the local radio volume affected by intercom. |
| 5 | + * |
| 6 | + * Arguments: |
| 7 | + * 0: Radio ID <STRING> |
| 8 | + * 1: Volume <NUMBER> |
| 9 | + * 2: Vehicle <OBJECT> (default: objNull) |
| 10 | + * 3: Rack ID <STRING> (default: "") |
| 11 | + * |
| 12 | + * Return Value: |
| 13 | + * Radio volume affected by intercom <NUMBER> |
| 14 | + * |
| 15 | + * Example: |
| 16 | + * ["acre_prc152_id_1", 0.8] call acre_sys_intercom_fnc_modifyRadioVolume |
| 17 | + * |
| 18 | + * Public: No |
| 19 | + */ |
| 20 | + |
| 21 | +params ["_radioId", "_volume", ["_vehicle", objNull], ["_rackId", ""]]; |
| 22 | + |
| 23 | +if (!(_radioId in ACRE_ACCESSIBLE_RACK_RADIOS) && {!(_radioId in ACRE_HEARABLE_RACK_RADIOS)}) exitWith {_volume}; |
| 24 | + |
| 25 | +if (_rackId isEqualTo "") then { |
| 26 | + _rackId = [_radioId] call EFUNC(sys_rack,getRackFromRadio); |
| 27 | +}; |
| 28 | + |
| 29 | +if (_rackId == "") exitWith {_volume}; |
| 30 | + |
| 31 | +if (isNull _vehicle) then { |
| 32 | + _vehicle = [_rackId] call EFUNC(sys_rack,getVehicleFromRack); |
| 33 | +}; |
| 34 | + |
| 35 | +private _accentConfig = _vehicle getVariable [QGVAR(accent), [false]]; |
| 36 | +private _connectedIntercoms = [_rackId] call EFUNC(sys_rack,getWiredIntercoms); |
| 37 | +if (_connectedIntercoms isEqualTo []) exitWith {_volume}; |
| 38 | + |
| 39 | +private _modifiedVolume = 0; |
| 40 | +{ |
| 41 | + _x params ["_intercomName", "_intercomInUse"]; |
| 42 | + private _connected = ([_vehicle, acre_player, _forEachIndex, INTERCOM_STATIONSTATUS_CONNECTION] call FUNC(getStationConfiguration)) > 0; |
| 43 | + if ((_intercomName in _connectedIntercoms) && {_connected}) then { |
| 44 | + private _intercomVolume = [_vehicle, acre_player, _forEachIndex, INTERCOM_STATIONSTATUS_VOLUME] call FUNC(getStationConfiguration); |
| 45 | + private _tempVolume = _intercomVolume; |
| 46 | + if (_intercomInUse && {_accentConfig select _forEachIndex}) then { |
| 47 | + _tempVolume = _intercomVolume * INTERCOM_ACCENT_VOLUME_FACTOR; // Reduce volume by 20% if intercom is active and there is an incomming radio transmission |
| 48 | + if (_tempVolume < MINIMUM_INTERCOM_ACCENT_VOLUME) then { |
| 49 | + _tempVolume = MINIMUM_INTERCOM_ACCENT_VOLUME; |
| 50 | + }; |
| 51 | + }; |
| 52 | + |
| 53 | + // Always return the highest intercome outcome |
| 54 | + if (_tempVolume > _modifiedVolume) then { |
| 55 | + _modifiedVolume = _tempVolume; |
| 56 | + }; |
| 57 | + }; |
| 58 | +} forEach GVAR(intercomUse); |
| 59 | + |
| 60 | +if (_modifiedVolume > 0) exitWith {_modifiedVolume}; |
| 61 | + |
| 62 | +_volume |
0 commit comments