From d5b3b03c1ce3705dd1018c7c36bef92adc6d87de Mon Sep 17 00:00:00 2001 From: voiper Date: Fri, 17 Jun 2016 17:18:06 -0700 Subject: [PATCH] Make flashlight on/off + glow a PVAR. Clean up all privates. Change glow proxies to not inherit from chemlight_base, to avoid ammo detection issues. Make handleDisconnect glow deletion dedi server compatible (was only listen server compatible). Clean up determineMapLight: faster when no chemlights nearby, a tad slower when chemlights nearby, however sources the colour settings directly from the chemlight's config. --- addons/map/CfgAmmo.hpp | 53 ++++--- addons/map/CfgEventHandlers.hpp | 5 +- addons/map/XEH_postInitClient.sqf | 61 +++----- addons/map/XEH_postInitServer.sqf | 16 +++ .../functions/fnc_blueForceTrackingUpdate.sqf | 8 +- .../functions/fnc_compileFlashlightMenu.sqf | 22 +-- .../map/functions/fnc_determineMapLight.sqf | 130 +++++++----------- addons/map/functions/fnc_determineZoom.sqf | 11 +- addons/map/functions/fnc_flashlightGlow.sqf | 38 +++-- addons/map/functions/fnc_simulateMapLight.sqf | 69 +++++----- addons/map/functions/fnc_switchFlashlight.sqf | 24 ++-- addons/map/functions/fnc_updateMapEffects.sqf | 41 +++--- 12 files changed, 226 insertions(+), 252 deletions(-) create mode 100644 addons/map/XEH_postInitServer.sqf diff --git a/addons/map/CfgAmmo.hpp b/addons/map/CfgAmmo.hpp index 48b3d91527..aca4042b4f 100644 --- a/addons/map/CfgAmmo.hpp +++ b/addons/map/CfgAmmo.hpp @@ -1,39 +1,34 @@ class CfgAmmo { - class Chemlight_base; + class Grenade; - class ACE_FlashlightProxy_White: Chemlight_base { - model = "\A3\Weapons_f\empty"; + class ACE_FlashlightProxy_White: Grenade { effectsSmoke = "ACE_FlashlightEffect_White"; explosionTime = 0.01; + grenadeBurningSound[] = {}; + grenadeFireSound[] = {}; + hit = 0; + model = "\A3\Weapons_f\empty.p3d"; + simulation = "shotSmokeX"; + smokeColor[] = {1,1,1,1}; timeToLive = 1e10; - soundImpactHard1[] = {"",1,1}; - soundImpactHard2[] = {"",1,1}; - soundImpactHard3[] = {"",1,1}; - soundImpactHard4[] = {"",1,1}; - soundImpactHard5[] = {"",1,1}; - soundImpactHard6[] = {"",1,1}; - soundImpactHard7[] = {"",1,1}; - soundImpactIron1[] = {"",1,1}; - soundImpactIron2[] = {"",1,1}; - soundImpactIron3[] = {"",1,1}; - soundImpactIron4[] = {"",1,1}; - soundImpactIron5[] = {"",1,1}; - soundImpactSoft1[] = {"",1,1}; - soundImpactSoft2[] = {"",1,1}; - soundImpactSoft3[] = {"",1,1}; - soundImpactSoft4[] = {"",1,1}; - soundImpactSoft5[] = {"",1,1}; - soundImpactSoft6[] = {"",1,1}; - soundImpactSoft7[] = {"",1,1}; - soundImpactWater1[] = {"",1,1}; - soundImpactWater2[] = {"",1,1}; - soundImpactWater3[] = {"",1,1}; - soundImpactWoodExt1[] = {"",1,1}; - soundImpactWoodExt2[] = {"",1,1}; - soundImpactWoodExt3[] = {"",1,1}; - soundImpactWoodExt4[] = {"",1,1}; + impactArmor[] = {}; + impactConcrete[] = {}; + impactDefault[] = {}; + impactGlass[] = {}; + impactGlassArmored[] = {}; + impactGroundHard[] = {}; + impactGroundSoft[] = {}; + impactIron[] = {}; + impactMan[] = {}; + impactMetal[] = {}; + impactMetalPlate[] = {}; + impactMetalPlastic[] = {}; + impactRubber[] = {}; + impactTyre[] = {}; + impactWater[] = {}; + impactWood[] = {}; }; class ACE_FlashlightProxy_Red: ACE_FlashlightProxy_White { diff --git a/addons/map/CfgEventHandlers.hpp b/addons/map/CfgEventHandlers.hpp index 5c77927e53..0a9f567e49 100644 --- a/addons/map/CfgEventHandlers.hpp +++ b/addons/map/CfgEventHandlers.hpp @@ -7,12 +7,13 @@ class Extended_PreStart_EventHandlers { class Extended_PreInit_EventHandlers { class ADDON { - init = QUOTE(call COMPILE_FILE(XEH_preInit) ); + init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; class Extended_PostInit_EventHandlers { class ADDON { - clientInit = QUOTE(call COMPILE_FILE(XEH_postInitClient) ); + clientInit = QUOTE(call COMPILE_FILE(XEH_postInitClient)); + serverInit = QUOTE(call COMPILE_FILE(XEH_postInitServer)); }; }; diff --git a/addons/map/XEH_postInitClient.sqf b/addons/map/XEH_postInitClient.sqf index f598266695..874681606c 100644 --- a/addons/map/XEH_postInitClient.sqf +++ b/addons/map/XEH_postInitClient.sqf @@ -1,23 +1,5 @@ #include "script_component.hpp" -//Delete map glow lights from disconnecting players #2810 -if (isServer) then { - addMissionEventHandler ["HandleDisconnect",{ - params ["_disconnectedPlayer"]; - - if ((!GVAR(mapGlow)) || {isNull _disconnectedPlayer}) exitWith {}; - { - if (_x isKindOf "ACE_FlashlightProxy_White") then { - // ACE_LOGINFO_2("Deleting leftover light [%1:%2] from DC player [%3]", _x, typeOf _x, _disconnectedPlayer); - detach _x; - deleteVehicle _x; - }; - } forEach attachedObjects _disconnectedPlayer; - - nil - }]; -}; - // Exit on Headless as well if (!hasInterface) exitWith {}; @@ -39,12 +21,11 @@ call FUNC(determineZoom); //Allow panning the lastStillPosition while mapShake is active GVAR(rightMouseButtonLastPos) = []; - ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw", {[] call FUNC(updateMapEffects);}]; + ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw", {_this call FUNC(updateMapEffects)}]; ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["MouseMoving", { if (GVAR(isShaking) && {(count GVAR(rightMouseButtonLastPos)) == 2}) then { - private["_lastPos", "_newPos"]; - _lastPos = (_this select 0) ctrlMapScreenToWorld GVAR(rightMouseButtonLastPos); - _newPos = (_this select 0) ctrlMapScreenToWorld (_this select [1,2]); + private _lastPos = (_this select 0) ctrlMapScreenToWorld GVAR(rightMouseButtonLastPos); + private _newPos = (_this select 0) ctrlMapScreenToWorld (_this select [1,2]); GVAR(lastStillPosition) set [0, (GVAR(lastStillPosition) select 0) + (_lastPos select 0) - (_newPos select 0)]; GVAR(lastStillPosition) set [1, (GVAR(lastStillPosition) select 1) + (_lastPos select 1) - (_newPos select 1)]; GVAR(rightMouseButtonLastPos) = _this select [1,2]; @@ -97,35 +78,33 @@ call FUNC(determineZoom); //illumination settings if (GVAR(mapIllumination)) then { - GVAR(flashlightInUse) = ""; - GVAR(glow) = objNull; - ["ace_playerInventoryChanged", { - private _flashlights = [ACE_player] call FUNC(getUnitFlashlights); - if ((GVAR(flashlightInUse) != "") && !(GVAR(flashlightInUse) in _flashlights)) then { - GVAR(flashlightInUse) = ""; + params ["_player", ""]; + private _flashlightItems = [_player] call FUNC(getUnitFlashlights); + private _unitLight = _player getVariable [QGVAR(flashlight), ["", objNull]]; + _unitLight params ["_flashlight", "_glow"]; + if (!(_flashlight isEqualTo "") && {!(_flashlight in _flashlightItems)}) then { + if (!isNull _glow) then { + _glow = [_player, "", false] call FUNC(flashlightGlow); + }; + _player setVariable [QGVAR(flashlight), ["", _glow], true]; }; }] call CBA_fnc_addEventHandler; if (GVAR(mapGlow)) then { ["ace_visibleMapChanged", { params ["_player", "_mapOn"]; + private _unitLight = _player getVariable [QGVAR(flashlight), ["", objNull]]; + _unitLight params ["_flashlight", "_glow"]; + private _flashlightOn = !(_flashlight isEqualTo ""); if (_mapOn) then { - if (!alive _player && !isNull GVAR(glow)) then { - GVAR(flashlightInUse) = ""; - }; - if (GVAR(flashlightInUse) != "") then { - if (isNull GVAR(glow)) then { - [GVAR(flashlightInUse)] call FUNC(flashlightGlow); - }; - } else { - if (!isNull GVAR(glow)) then { - [""] call FUNC(flashlightGlow); - }; + if (_flashlightOn && {isNull _glow}) then { + [_player, _flashlight] call FUNC(flashlightGlow); + playSound QGVAR(flashlightClick); }; } else { - if (!isNull GVAR(glow)) then { - [""] call FUNC(flashlightGlow); + if (!isNull _glow) then { + [_player, ""] call FUNC(flashlightGlow); }; }; }] call CBA_fnc_addEventHandler; diff --git a/addons/map/XEH_postInitServer.sqf b/addons/map/XEH_postInitServer.sqf new file mode 100644 index 0000000000..763c21b002 --- /dev/null +++ b/addons/map/XEH_postInitServer.sqf @@ -0,0 +1,16 @@ +#include "script_component.hpp" + +// Delete map glow lights from disconnecting players, #2810 +addMissionEventHandler ["HandleDisconnect",{ + params ["_disconnectedPlayer"]; + if (!GVAR(mapGlow)) exitWith {}; + private _unitLight = _disconnectedPlayer getVariable [QGVAR(flashlight), ["", objNull]]; + _unitLight params ["", "_glow"]; + + if ((!isNull _disconnectedPlayer) && {!isNull _glow}) then { + detach _glow; + deleteVehicle _glow; + }; + + nil +}]; \ No newline at end of file diff --git a/addons/map/functions/fnc_blueForceTrackingUpdate.sqf b/addons/map/functions/fnc_blueForceTrackingUpdate.sqf index cecf228924..3fe7dd07fc 100644 --- a/addons/map/functions/fnc_blueForceTrackingUpdate.sqf +++ b/addons/map/functions/fnc_blueForceTrackingUpdate.sqf @@ -2,8 +2,6 @@ #include "script_component.hpp" // BEGIN_COUNTER(blueForceTrackingUpdate); -private ["_groupsToDrawMarkers", "_playersToDrawMarkers", "_playerSide", "_anyPlayers", "_colour", "_marker"]; - // Delete last set of markers (always) { deleteMarkerLocal _x; @@ -13,8 +11,8 @@ GVAR(BFT_markers) = []; if (GVAR(BFT_Enabled) and {(!isNil "ACE_player") and {alive ACE_player}}) then { - _groupsToDrawMarkers = []; - _playerSide = call EFUNC(common,playerSide); + private _groupsToDrawMarkers = []; + private _playerSide = call EFUNC(common,playerSide); _groupsToDrawMarkers = allGroups select {side _x == _playerSide}; @@ -27,7 +25,7 @@ if (GVAR(BFT_Enabled) and {(!isNil "ACE_player") and {alive ACE_player}}) then { }; if (GVAR(BFT_ShowPlayerNames)) then { - _playersToDrawMarkers = allPlayers select {side _x == _playerSide}; + private _playersToDrawMarkers = allPlayers select {side _x == _playerSide}; { private _markerType = [_x] call EFUNC(common,getMarkerType); diff --git a/addons/map/functions/fnc_compileFlashlightMenu.sqf b/addons/map/functions/fnc_compileFlashlightMenu.sqf index 836b483a20..2ba2c215f5 100644 --- a/addons/map/functions/fnc_compileFlashlightMenu.sqf +++ b/addons/map/functions/fnc_compileFlashlightMenu.sqf @@ -20,27 +20,27 @@ params ["", "_player"]; -private["_action", "_actions", "_cfg", "_displayName", "_flashlights", "_icon", "_statement"]; - -_actions = []; -_flashlights = [_player] call FUNC(getUnitFlashlights); +private _actions = []; +private _flashlightItems = [_player] call FUNC(getUnitFlashlights); +private _unitLight = _player getVariable [QGVAR(flashlight), ["", objNull]]; +_unitLight params ["_flashlight", ""]; //add all carried flashlight menus and on/off submenu actions { - _cfg = (configFile >> "CfgWeapons" >> _x); - _displayName = getText (_cfg >> "displayName"); - _icon = getText (_cfg >> "picture"); + private _cfg = (configFile >> "CfgWeapons" >> _x); + private _displayName = getText (_cfg >> "displayName"); + private _icon = getText (_cfg >> "picture"); - _statement = if (GVAR(flashlightInUse) == _x) then { + private _statement = if (_flashlight == _x) then { _displayName = format [localize LSTRING(turnLightOff), _displayName]; - {[""] call FUNC(switchFlashlight)} + {[_player, ""] call FUNC(switchFlashlight)} } else { _displayName = format [localize LSTRING(turnLightOn), _displayName]; - {[_this select 2] call FUNC(switchFlashlight)} + {[_player, _this select 2] call FUNC(switchFlashlight)} }; _action = [_x, _displayName, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); _actions pushBack [_action, [], _player]; -} forEach _flashlights; +} forEach _flashlightItems; _actions diff --git a/addons/map/functions/fnc_determineMapLight.sqf b/addons/map/functions/fnc_determineMapLight.sqf index c647e93e0c..3269c5a056 100644 --- a/addons/map/functions/fnc_determineMapLight.sqf +++ b/addons/map/functions/fnc_determineMapLight.sqf @@ -1,83 +1,50 @@ /* -* Author: Rocko and esteldunedain -* Calculates the current map illumination for a given unit -* -* Arguments: -* 0: Unit -* -* Return Value: -* 0: Does the map needs shading? -* 1: Color of the overlay -* -* Public: No -*/ + * Author: Rocko and esteldunedain + * Calculates the current map illumination for a given unit + * + * Arguments: + * 0: Unit + * + * Return Value: + * 0: Does the map needs shading? + * 1: Color of the overlay + * + * Public: No + */ + #include "script_component.hpp" + params ["_unit"]; -private ["_fnc_blendColor", "_lightTint", "_fnc_calcColor", "_l", "_lightLevel", "_vehicle", "_isEnclosed", "_nearObjects", "_light", "_ll", "_flashlight", "_flareTint"]; - // Blend two colors -_fnc_blendColor = { +private _fnc_blendColor = { params ["_c1", "_c2", "_alpha"]; [(_c1 select 0) * (1 - _alpha) + (_c2 select 0) * _alpha, - (_c1 select 1) * (1 - _alpha) + (_c2 select 1) * _alpha, - (_c1 select 2) * (1 - _alpha) + (_c2 select 2) * _alpha, - (_c1 select 3) * (1 - _alpha) + (_c2 select 3) * _alpha] + (_c1 select 1) * (1 - _alpha) + (_c2 select 1) * _alpha, + (_c1 select 2) * (1 - _alpha) + (_c2 select 2) * _alpha, + (_c1 select 3) * (1 - _alpha) + (_c2 select 3) * _alpha] }; // Ambient light tint depending on time of day -_lightTint = call { - if (sunOrMoon == 1.0) exitWith { [0.5,0.5,0.5,1] }; - if (sunOrMoon > 0.80) exitWith { [[1.0 - overcast,0.2,0,1], [1,1,1,1], (sunOrMoon - 0.8)/0.2] call _fnc_blendColor }; - if (sunOrMoon > 0.50) exitWith { [[0,0,0.1,1], [1.0 - overcast,0.2,0,1], (sunOrMoon - 0.5)/0.3] call _fnc_blendColor }; - if (sunOrMoon <= 0.5) exitWith { [0,0,0.1,1] }; +private _lightTint = call { + if (sunOrMoon == 1.0) exitWith {[0.5,0.5,0.5,1]}; + if (sunOrMoon > 0.80) exitWith {[[1.0 - overcast,0.2,0,1], [1,1,1,1], (sunOrMoon - 0.8) / 0.2] call _fnc_blendColor}; + if (sunOrMoon > 0.50) exitWith {[[0,0,0.1,1], [1.0 - overcast,0.2,0,1], (sunOrMoon - 0.5) / 0.3] call _fnc_blendColor}; + if (sunOrMoon <= 0.5) exitWith {[0,0,0.1,1]}; [0,0,0,0] }; -// Calculates overlay color from tint and light level -_fnc_calcColor = { - params ["_c1", "_lightLevel"]; - - if (_lightLevel < 0.5) then { - _l = _lightLevel / 0.5; - [(_c1 select 0) * _l, - (_c1 select 1) * _l, - (_c1 select 2) * _l, - (_c1 select 3) * (1 - _lightLevel)] - } else { - _l = (_lightLevel - 0.5) / 0.5; - [(_c1 select 0) * (1 - _l) + _l, - (_c1 select 1) * (1 - _l) + _l, - (_c1 select 2) * (1 - _l) + _l, - (_c1 select 3) * (1 - _lightLevel)] - }; -}; - -_lightLevel = 0.04 + (0.96 * call EFUNC(common,ambientBrightness)); - -/* -// check if player has NVG enabled -if (currentVisionMode _unit == 1) exitWith { - // stick to nvg color - [true, [154/255,253/255,177/255,0.5]] -}; -*/ +private _lightLevel = 0.04 + (0.96 * call EFUNC(common,ambientBrightness)); // Do not obscure the map if the ambient light level is above 0.95 if (_lightLevel > 0.95) exitWith { - [false, [0.5,0.5,0.5,0]] + [false, [1,1,1,0]] }; -_vehicle = vehicle _unit; +private _vehicle = vehicle _unit; // Do not obscure the map if the player is on a enclosed vehicle (assume internal illumination) -if (_vehicle != _unit) then { - // Player is in a vehicle - if (!isTurnedOut _unit && { _vehicle isKindOf "Tank" || { ( _vehicle isKindOf "Helicopter" || _vehicle isKindOf "Plane" ) && { (driver _vehicle) == _unit || { (gunner _vehicle) == _unit } } } || {_vehicle isKindOf "Wheeled_APC"}}) then { - _isEnclosed = true; - }; -}; -if (_isEnclosed) exitWith { +if ((_vehicle != _unit) && {!isTurnedOut _unit && {_vehicle isKindOf "Tank" || {(_vehicle isKindOf "Helicopter" || _vehicle isKindOf "Plane") && {driver _vehicle == _unit || {gunner _vehicle == _unit}}} || {_vehicle isKindOf "Wheeled_APC"}}}) exitWith { TRACE_1("Player in a enclosed vehicle",""); [false, [1,1,1,0]] }; @@ -93,29 +60,38 @@ TRACE_1("Player is on foot or in an open vehicle",""); // @todo: Illumination flares (timed) // Using chemlights -_nearObjects = (_unit nearObjects ["SmokeShell", 4]) select {alive _x && {toLower typeOf _x in ["chemlight_red", "chemlight_green", "chemlight_blue", "chemlight_yellow"]}}; +private _nearObjects = (_unit nearObjects ["Chemlight_base", 4]) select {alive _x}; -if (count (_nearObjects) > 0) then { - _light = _nearObjects select 0; - - _ll = (1 - ((((_unit distance _light) - 2)/2) max 0)) * 0.4; - if (_ll > _lightLevel) then { - _flareTint = switch (toLower typeOf _light) do { - case "chemlight_red" : {[1,0,0,1]}; - case "chemlight_green" : {[0,1,0,1]}; - case "chemlight_blue" : {[0,0,1,1]}; - case "chemlight_yellow" : {[1,1,0,1]}; - }; - _lightTint = [_lightTint, _flareTint, (_ll - _lightLevel)/(1 - _lightLevel)] call _fnc_blendColor; - _lightLevel = _ll; +if !(_nearObjects isEqualTo []) then { + private _nearestlight = _nearObjects select 0; + private _lightLevelTemp = (1 - ((((_unit distance _nearestlight) - 2) / 2) max 0)) * 0.4; + if (_lightLevelTemp > _lightLevel) then { + private _flareTint = getArray (configFile >> "CfgLights" >> (getText (configFile >> (getText (configFile >> "CfgAmmo" >> typeOf _nearestlight >> "EffectsSmoke")) >> "Light1" >> "type")) >> "color"); + _lightTint = [_lightTint, _flareTint, (_lightLevelTemp - _lightLevel) / (1 - _lightLevel)] call _fnc_blendColor; + _lightLevel = _lightLevelTemp; TRACE_1("player near chemlight",""); }; }; // Do not obscure the map if the ambient light level is above 0.95 if (_lightLevel > 0.95) exitWith { - [false, [0.5,0.5,0.5,0]] + [false, [1,1,1,0]] }; -// Calculate resulting map color -[true, [_lightTint, _lightLevel] call _fnc_calcColor] +// Calculate resulting map color from tint and light level +private _halfLight = _lightLevel / 0.5; + +private _finalLevel = if (_lightLevel < 0.5) then { + [(_lightTint select 0) * _halfLight, + (_lightTint select 1) * _halfLight, + (_lightTint select 2) * _halfLight, + (_lightTint select 3) * (1 - _lightLevel)] +} else { + _halfLight = (_lightLevel - 0.5) / 0.5; + [(_lightTint select 0) * (1 - _halfLight) + _halfLight, + (_lightTint select 1) * (1 - _halfLight) + _halfLight, + (_lightTint select 2) * (1 - _halfLight) + _halfLight, + (_lightTint select 3) * (1 - _lightLevel)] +}; + +[true, _finalLevel] diff --git a/addons/map/functions/fnc_determineZoom.sqf b/addons/map/functions/fnc_determineZoom.sqf index bdfc9a866b..efe20a0e52 100644 --- a/addons/map/functions/fnc_determineZoom.sqf +++ b/addons/map/functions/fnc_determineZoom.sqf @@ -12,15 +12,14 @@ */ #include "script_component.hpp" -private ["_grids", "_fourSize", "_sixSize", "_continue", "_size", "_i"]; -_grids = (configFile >> "CfgWorlds" >> worldName >> "Grid"); -_fourSize = -1; -_sixSize = -1; +private _grids = (configFile >> "CfgWorlds" >> worldName >> "Grid"); +private _fourSize = -1; +private _sixSize = -1; for "_i" from 1 to 10 do { - _continue = false; + private _continue = false; if (isClass(_grids >> format["Zoom%1", _i])) then { _continue = true; - _size = getText(_grids >> format["Zoom%1", _i] >> "formatX"); + private _size = getText(_grids >> format["Zoom%1", _i] >> "formatX"); if ((count toArray(_size)) == 2) then { _fourSize = getNumber(_grids >> format["Zoom%1", _i] >> "zoomMax"); }; diff --git a/addons/map/functions/fnc_flashlightGlow.sqf b/addons/map/functions/fnc_flashlightGlow.sqf index 565182c2a6..9d65c93b98 100644 --- a/addons/map/functions/fnc_flashlightGlow.sqf +++ b/addons/map/functions/fnc_flashlightGlow.sqf @@ -3,36 +3,44 @@ * Add or remove global flashlight glow for when player is looking at map. * * Arguments: - * 0: Flashlight classname ("" for off) + * 0: Unit + * 1: Flashlight classname ("" for off) + * 2: Set the PVAR? (default: true) * * Return value: - * None + * Glow object * * Example: - * ["ACE_Flashlight_MX991"] call ace_map_fnc_flashlightGlow; + * [ACE_player, "ACE_Flashlight_MX991"] call ace_map_fnc_flashlightGlow; * * Public: No */ #include "script_component.hpp" -params ["_flashlight"]; +params ["_unit", "_flashlightType", ["_set", true]]; -private _light = GVAR(glow); -if (!isNull _light) then { - detach _light; - deleteVehicle _light; +private _unitLight = _unit getVariable [QGVAR(flashlight), ["", objNull]]; +_unitLight params ["_flashlight", "_glow"]; + +if (!isNull _glow) then { + detach _glow; + deleteVehicle _glow; }; -if (_flashlight != "") then { - private _color = getText (configFile >> "CfgWeapons" >> _flashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Colour"); +if !(_flashlightType isEqualTo "") then { + private _color = getText (configFile >> "CfgWeapons" >> _flashlightType >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Colour"); if !(_color in ["white", "red", "green", "blue", "yellow", "orange"]) then {_color = "white"}; - private _class = format["ACE_FlashlightProxy_%1", _color]; + private _class = format ["ACE_FlashlightProxy_%1", _color]; - _light = _class createVehicle [0,0,0]; - _light attachTo [ACE_player, [0,0.1,-0.05], "neck"]; + _glow = _class createVehicle [0,0,0]; + _glow attachTo [_unit, [0,0.1,-0.05], "neck"]; } else { - _light = objNull; + _glow = objNull; }; -GVAR(glow) = _light; \ No newline at end of file +if (_set) then { + _unit setVariable [QGVAR(flashlight), [_flashlight, _glow], true]; +}; + +_glow diff --git a/addons/map/functions/fnc_simulateMapLight.sqf b/addons/map/functions/fnc_simulateMapLight.sqf index 30a9802e54..ba03c421a7 100644 --- a/addons/map/functions/fnc_simulateMapLight.sqf +++ b/addons/map/functions/fnc_simulateMapLight.sqf @@ -1,48 +1,47 @@ /* -* Author: voiper -* Draw nearby lighting and sexy flashlight beams on main map. -* -* Arguments: -* 0: Map control -* 1: Map zoom level -* 2: Current map centre -* 3: Light level from ace_map_fnc_determineMapLight -* -* Return Value: -* None -* -* Public: No -*/ + * Author: voiper + * Draw nearby lighting and sexy flashlight beams on main map. + * + * Arguments: + * 0: Map control + * 1: Map zoom level + * 2: Current map centre + * 3: Light level from ace_map_fnc_determineMapLight + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" -private ["_hmd", "_flashlight", "_screenSize", "_realViewPortY", "_realViewPortX", "_fillTex", "_colourAlpha", "_shadeAlpha", "_colourList", "_maxColour"]; params ["_mapCtrl", "_mapScale", "_mapCentre", "_lightLevel"]; -_hmd = hmd ACE_player; -_flashlight = GVAR(flashlightInUse); +private _unitLight = ACE_player getVariable [QGVAR(flashlight), ["", objNull]]; +_unitLight params ["_flashlight", ""]; //map width (on screen) in pixels -_screenSize = 640 * safeZoneWAbs; +private _screenSize = 640 * safeZoneWAbs; //resolution params (every frame in case resolution change) getResolution params ["_resX", "_resY", "_viewPortX", "_viewPortY", "", "_uiScale"]; //engine rounds the viewport ratios, when they should be fractions; this can cause problems -_realViewPortY = _resY * _uiScale; -_realViewPortX = _realViewPortY * 4/3; +private _realViewPortY = _resY * _uiScale; +private _realViewPortX = _realViewPortY * 4/3; //textures -_fillTex = "#(rgb,8,8,3)color(0,0,0,1)"; +private _fillTex = "#(rgb,8,8,3)color(0,0,0,1)"; //colour/alpha _lightLevel params ["_r", "_g", "_b", "_a"]; -_colourAlpha = (_r + _g + _b) min _a; -_shadeAlpha = _a; +private _colourAlpha = (_r + _g + _b) min _a; +private _shadeAlpha = _a; -_colourList = [_r, _g, _b]; +private _colourList = [_r, _g, _b]; _colourList sort false; -_maxColour = _colourList select 0; +private _maxColour = _colourList select 0; //ambient colour fill _mapCtrl drawIcon [format["#(rgb,8,8,3)color(%1,%2,%3,1)", _r / _maxColour, _g / _maxColour, _b / _maxColour], [1,1,1,_colourAlpha], _mapCentre, _screenSize, _screenSize, 0, "", 0]; @@ -51,21 +50,19 @@ if (_flashlight == "") then { //ambient shade fill _mapCtrl drawIcon [_fillTex, [1,1,1,_shadeAlpha], _mapCentre, _screenSize, _screenSize, 0, "", 0]; } else { - private ["_mousePos", "_cfg", "_size", "_flashTex", "_beamSize", "_viewPortRatioFixY", "_offsetX", "_offsetYDown", "_offsetYUp"]; - //mouse pos - _mousePos = GVAR(mousePos); + private _mousePos = GVAR(mousePos); //flashlight settings - _cfg = (configFile >> "CfgWeapons" >> _flashlight >> "ItemInfo" >> "FlashLight"); - _size = getNumber (_cfg >> "ACE_Flashlight_Size"); - _flashTex = getText (_cfg >> "ACE_Flashlight_Beam"); - _beamSize = (safeZoneW/safeZoneWAbs) * _screenSize / _size; + private _cfg = (configFile >> "CfgWeapons" >> _flashlight >> "ItemInfo" >> "FlashLight"); + private _size = getNumber (_cfg >> "ACE_Flashlight_Size"); + private _flashTex = getText (_cfg >> "ACE_Flashlight_Beam"); + private _beamSize = (safeZoneW/safeZoneWAbs) * _screenSize / _size; //after 5x zoom, it's simulated to be fixed (it actually gets bigger relative to zoom) if (_mapScale < 0.2) then {_beamSize = _beamSize / (_mapScale * (1 / 0.2))}; //assign corrective ratio to fix sub-pixel gaps/overlaps (symptom of viewport * X/Y resolution rounding) - _viewPortRatioFixY = if (_realViewPortY != _viewPortY) then { + private _viewPortRatioFixY = if (_realViewPortY != _viewPortY) then { _realViewPortX / (_realViewPortY / _viewPortY * _viewPortX) } else { if (_realViewPortX != _viewPortX) then { @@ -76,10 +73,10 @@ if (_flashlight == "") then { }; //offset the elements - _offsetX = _mapScale * GVAR(worldSize) * (_screenSize * 2 + _beamSize); - _offsetYDown = _mapScale * GVAR(worldSize) * (_screenSize + _beamSize) * _viewPortRatioFixY; + private _offsetX = _mapScale * GVAR(worldSize) * (_screenSize * 2 + _beamSize); + private _offsetYDown = _mapScale * GVAR(worldSize) * (_screenSize + _beamSize) * _viewPortRatioFixY; //up is bigger because of a potential exploit - _offsetYUp = _mapScale * GVAR(worldSize) * (_screenSize * 4 + _beamSize) * _viewPortRatioFixY; + private _offsetYUp = _mapScale * GVAR(worldSize) * (_screenSize * 4 + _beamSize) * _viewPortRatioFixY; //draw the matrix /whoa _mapCtrl drawIcon [_flashTex, [1,1,1,_shadeAlpha], _mousePos, _beamSize, _beamSize, 0, "", 0]; //centre beam diff --git a/addons/map/functions/fnc_switchFlashlight.sqf b/addons/map/functions/fnc_switchFlashlight.sqf index e7843e5fa1..2d6d4c5ac2 100644 --- a/addons/map/functions/fnc_switchFlashlight.sqf +++ b/addons/map/functions/fnc_switchFlashlight.sqf @@ -3,31 +3,37 @@ * Switch flashlight on/off. * * Arguments: - * 0: New flashlight classname ("" for off) + * 0: Unit + * 1: New flashlight classname ("" for off) * * Return value: * None * * Example: - * ["ACE_Flashlight_MX991"] call ace_map_fnc_switchFlashlight; + * [ACE_player, "ACE_Flashlight_MX991"] call ace_map_fnc_switchFlashlight; * * Public: No */ #include "script_component.hpp" -params ["_newFlashlight"]; -private _oldFlashlight = GVAR(flashlightInUse); +params ["_unit", "_newFlashlight"]; + +private _unitLight = _unit getVariable [QGVAR(flashlight), ["", objNull]]; +_unitLight params ["_flashlight", "_glow"]; if (GVAR(mapGlow)) then { - [_newFlashlight] call FUNC(flashlightGlow); + // we don't want to set the PVAR twice in a row, so tell this func not to set it + _glow = [_unit, _newFlashlight, false] call FUNC(flashlightGlow); }; +private _config = (configFile >> "CfgWeapons"); + if ( - (getNumber (configFile >> "CfgWeapons" >> _newFlashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Sound") > 0) || - {getNumber (configFile >> "CfgWeapons" >> _oldFlashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Sound") > 0} -) then { + (getNumber (_config >> _newFlashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Sound") > 0) || + {getNumber (_config >> _flashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Sound") > 0} +) then { playSound QGVAR(flashlightClick); }; -GVAR(flashlightInUse) = _newFlashlight; \ No newline at end of file +_unit setVariable [QGVAR(flashlight), [_newFlashlight, _glow], true]; diff --git a/addons/map/functions/fnc_updateMapEffects.sqf b/addons/map/functions/fnc_updateMapEffects.sqf index b89a75aa32..23e97114a8 100644 --- a/addons/map/functions/fnc_updateMapEffects.sqf +++ b/addons/map/functions/fnc_updateMapEffects.sqf @@ -1,25 +1,25 @@ /* -* Author: Rocko and esteldunedain -* On map draw, updates the effects -* -* Arguments: -* None -* -* Return Value: -* None -* -* Public: No -*/ + * Author: Rocko and esteldunedain + * On map draw, updates the effects + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" -private ["_mapCtrl", "_mapScale", "_mapCentre", "_light"]; -_mapCtrl = findDisplay 12 displayCtrl 51; -_mapScale = ctrlMapScale _mapCtrl; -_mapCentre = _mapCtrl ctrlMapScreenToWorld [0.5, 0.5]; + +params ["_mapCtrl"]; +private _mapScale = ctrlMapScale _mapCtrl; +private _mapCentre = _mapCtrl ctrlMapScreenToWorld [0.5, 0.5]; if (GVAR(mapIllumination)) then { //get nearby lighting - _light = [[ACE_player], FUNC(determineMapLight), missionNamespace, QGVAR(mapLight), 0.1] call EFUNC(common,cachedCall); + private _light = [[ACE_player], FUNC(determineMapLight), missionNamespace, QGVAR(mapLight), 0.1] call EFUNC(common,cachedCall); _light params ["_applyLighting", "_lightLevel"]; @@ -29,10 +29,9 @@ if (GVAR(mapIllumination)) then { }; if (GVAR(mapShake)) then { - private ["_speed","_amplitude", "_time", "_shakePos"]; // Only shake map while moving on foot - _speed = 0; + private _speed = 0; if (vehicle ACE_player == ACE_player) then { _speed = vectorMagnitude (velocity ACE_player); }; @@ -41,10 +40,10 @@ if (GVAR(mapShake)) then { if (_speed > 0.1) then { if (ctrlMapAnimDone _mapCtrl) then { - _amplitude = (_speed - 0.1) / 5 * (1000 * _mapScale); - _time = 0.1; + private _amplitude = (_speed - 0.1) / 5 * (1000 * _mapScale); + private _time = 0.1; - _shakePos = [(GVAR(lastStillPosition) select 0) + sin((CBA_missionTime + _time - GVAR(lastStillTime))*100) * _amplitude * 0.25, + private _shakePos = [(GVAR(lastStillPosition) select 0) + sin((CBA_missionTime + _time - GVAR(lastStillTime))*100) * _amplitude * 0.25, (GVAR(lastStillPosition) select 1) + sin((CBA_missionTime + _time - GVAR(lastStillTime))*260) * _amplitude]; _mapCtrl ctrlMapAnimAdd [_time, _mapScale, _shakePos];