From a893e7aa74dabefb760496609630b253b14f43ac Mon Sep 17 00:00:00 2001 From: Raymix Date: Sat, 21 Oct 2017 23:35:53 +0100 Subject: [PATCH] Geiger counter GUI release --- .../compile/inventory/EPOCH_equip.sqf | 4 ++ .../compile/setup/masterLoop/Event2.sqf | 7 --- .../compile/setup/masterLoop/Event5.sqf | 4 +- .../compile/setup/masterLoop/Event9.sqf | 9 ++++ .../compile/setup/masterLoop/init.sqf | 7 ++- .../scripts/geiger/epoch_geiger_animate.sqf | 51 +++++++++++++++++++ .../scripts/geiger/epoch_geiger_show_hide.sqf | 44 ++++++++++++++++ .../scripts/geiger/epoch_geiger_simulate.sqf | 46 +++++++++++++++++ Sources/epoch_code/init/client_init.sqf | 7 +++ .../CfgActionMenu/CfgActionMenu_self.hpp | 43 ++++++++++++++++ .../Configs/CfgClientFunctions.hpp | 6 +++ .../epoch_config/Configs/CfgMasterLoop.hpp | 4 ++ Sources/epoch_server/init/server_init.sqf | 4 +- .../EpochEvents/Satellite.sqf | 2 +- 14 files changed, 226 insertions(+), 12 deletions(-) create mode 100644 Sources/epoch_code/compile/setup/masterLoop/Event9.sqf create mode 100644 Sources/epoch_code/gui/scripts/geiger/epoch_geiger_animate.sqf create mode 100644 Sources/epoch_code/gui/scripts/geiger/epoch_geiger_show_hide.sqf create mode 100644 Sources/epoch_code/gui/scripts/geiger/epoch_geiger_simulate.sqf diff --git a/Sources/epoch_code/compile/inventory/EPOCH_equip.sqf b/Sources/epoch_code/compile/inventory/EPOCH_equip.sqf index 80b4d1cf..e7bb981f 100644 --- a/Sources/epoch_code/compile/inventory/EPOCH_equip.sqf +++ b/Sources/epoch_code/compile/inventory/EPOCH_equip.sqf @@ -423,6 +423,10 @@ switch _slot do { //can't find a way to display it in A3 "Use [O] to toggle watch" call epoch_message; }; + case "ItemGeigerCounter_EPOCH": + { + call epoch_geiger_show_hide; + }; case default { //do stuff with radios here diff --git a/Sources/epoch_code/compile/setup/masterLoop/Event2.sqf b/Sources/epoch_code/compile/setup/masterLoop/Event2.sqf index 26530cdc..50273f3d 100644 --- a/Sources/epoch_code/compile/setup/masterLoop/Event2.sqf +++ b/Sources/epoch_code/compile/setup/masterLoop/Event2.sqf @@ -47,13 +47,6 @@ _playerRadiation = missionNamespace getVariable [_playerRadiationKey, _playerRad if (_playerRadiation > 1) then { _radiationVal = linearConversion [0,100,_playerRadiation,0.1,1,true]; [_radiationVal, 2] call epoch_setRadiation; - - // if player has geiger counter make sound based on rads level - if ('ItemGeigerCounter_EPOCH' in assignedItems player) then { - _level = round(linearConversion [0,100,_radsLevel,0,3,true]); - _sound = format ["geiger_%1",_level]; - playSound _sound; - }; } else { [0, 2] call epoch_setRadiation; }; diff --git a/Sources/epoch_code/compile/setup/masterLoop/Event5.sqf b/Sources/epoch_code/compile/setup/masterLoop/Event5.sqf index 97568c3c..8368c3ea 100644 --- a/Sources/epoch_code/compile/setup/masterLoop/Event5.sqf +++ b/Sources/epoch_code/compile/setup/masterLoop/Event5.sqf @@ -5,7 +5,7 @@ EPOCH_nearestLocations = _nearestLocations; _powerSources = nearestObjects[player, ["Land_spp_Tower_F","Land_wpp_Turbine_V2_F","Land_wpp_Turbine_V1_F","SolarGen_EPOCH","Land_Wreck_Satellite_EPOCH"], _energyRange]; // TODO: add more sources and config based check instead of global var -_nearbyRadioactiveObjects = (_powerSources + _nearestLocations) select {_x getVariable ["EPOCH_Rads", 0] > 0}; +_nearbyRadioactiveObjects = (_powerSources + _nearestLocations) select {(_x getVariable ["EPOCH_Rads", []]) select 0 > 0}; // check if player is out of map bounds. _radsLevel = 0; @@ -20,7 +20,7 @@ if (_outOfBounds) then { if !(_nearbyRadioactiveObjects isEqualTo []) then { // add extra rads based on intensity and distance from site. _radioActiveSite = _nearbyRadioactiveObjects select 0; - _radsLevel = (_radioActiveSite getVariable ["EPOCH_Rads", 0]) / (player distance _radioActiveSite); + _radsLevel = ((_radioActiveSite getVariable ["EPOCH_Rads", 0])select 0) / (player distance _radioActiveSite); }; }; diff --git a/Sources/epoch_code/compile/setup/masterLoop/Event9.sqf b/Sources/epoch_code/compile/setup/masterLoop/Event9.sqf new file mode 100644 index 00000000..eb7e7578 --- /dev/null +++ b/Sources/epoch_code/compile/setup/masterLoop/Event9.sqf @@ -0,0 +1,9 @@ +if ('ItemGeigerCounter_EPOCH' in assignedItems player) then { + if (!EPOCH_geiger_mute_counter || !EPOCH_geiger_mute_warning || EPOCH_geiger_shown) then { //only run if geiger activated + _energyRange call epoch_geiger_simulate; + }; +} else { + if (EPOCH_geiger_shown) then { + call epoch_geiger_show_hide; + }; +}; \ No newline at end of file diff --git a/Sources/epoch_code/compile/setup/masterLoop/init.sqf b/Sources/epoch_code/compile/setup/masterLoop/init.sqf index e3d8dab1..15812021 100644 --- a/Sources/epoch_code/compile/setup/masterLoop/init.sqf +++ b/Sources/epoch_code/compile/setup/masterLoop/init.sqf @@ -335,8 +335,13 @@ EPOCH_ActiveTraderMission = []; _LastMissionTrigger = 0; // setup radio active locations +//Commented out by Raymix: Does not set variable on locations for some reason +/* { _x params ["_loc", "_rads"]; - _loc setVariable ["EPOCH_Rads", _rads]; + _locSize = size _loc; + _radius = sqrt((_locSize select 0)^2 + (_locSize select 1)^2); + _loc setVariable ["EPOCH_Rads", [_rads,_radius]]; } forEach (missionNamespace getVariable ["EPOCH_radioactiveLocations", []]); +*/ // diff --git a/Sources/epoch_code/gui/scripts/geiger/epoch_geiger_animate.sqf b/Sources/epoch_code/gui/scripts/geiger/epoch_geiger_animate.sqf new file mode 100644 index 00000000..e199aaa2 --- /dev/null +++ b/Sources/epoch_code/gui/scripts/geiger/epoch_geiger_animate.sqf @@ -0,0 +1,51 @@ +disableSerialization; +_rads = param [0,0,[0]]; +_play = { + if (!EPOCH_geiger_mute_counter) then { + playSound "geiger_epoch_tick"; + playSound "geiger_epoch_tick"; //makes geiger louder, remove if affects performance + }; +}; +_lcd = uiNamespace getVariable ["EPOCH_geiger_LCD",controlNull]; +_led = uiNamespace getVariable ["EPOCH_geiger_LED",controlNull]; + +if (_rads >= 10) then { + if (!EPOCH_geiger_mute_warning) then { + playSound "geiger_epoch_alarm"; + }; + [] spawn { + disableSerialization; + _lcd = uiNamespace getVariable ["EPOCH_geiger_LCD",controlNull]; + _lcd ctrlSetFade 1; + _lcd ctrlCommit 1; + uiSleep 1; + if (EPOCH_playerEnergy <= 100) then { + _lcd ctrlSetFade 1-(EPOCH_playerEnergy / 100); + } else { + _lcd ctrlSetFade 0; + }; + _lcd ctrlCommit 1; + }; +}; + +for "_i" from 1 to (ceil _rads) do { + if (!EPOCH_geiger_mute_counter) then { + playSound "geiger_epoch_tick"; + playSound "geiger_epoch_tick"; //makes geiger louder, remove if affects performance + }; + _led ctrlSetText "x\addons\a3_epoch_assets_1\pictures\geiger\geiger_4on"; + uiSleep (random 0.5); + _led ctrlSetText ""; +}; + +if (EPOCH_playerEnergy <= 100) then { + _lcd ctrlSetFade 1-(EPOCH_playerEnergy / 100); + _lcd ctrlCommit 1; + _led ctrlSetFade 1-(EPOCH_playerEnergy / 100); + _led ctrlCommit 1; +} else { + _lcd ctrlSetFade 0; + _lcd ctrlCommit 1; + _led ctrlSetFade 0; + _led ctrlCommit 1; +}; \ No newline at end of file diff --git a/Sources/epoch_code/gui/scripts/geiger/epoch_geiger_show_hide.sqf b/Sources/epoch_code/gui/scripts/geiger/epoch_geiger_show_hide.sqf new file mode 100644 index 00000000..abfd8b6c --- /dev/null +++ b/Sources/epoch_code/gui/scripts/geiger/epoch_geiger_show_hide.sqf @@ -0,0 +1,44 @@ +_removeControls = { + EPOCH_geiger_shown = false; + for "_i" from 1 to 8 do{ + (["geigerCounter", _i] call epoch_getHUDCtrl) ctrlSetText ""; + }; + ctrlDelete (uiNamespace getVariable ["EPOCH_geiger_LCD",controlNull]); + ctrlDelete (uiNamespace getVariable ["EPOCH_geiger_LED",controlNull]); +}; + +if !('ItemGeigerCounter_EPOCH' in assignedItems player) exitWith {call _removeControls; false}; + +if (ctrlText(["geigerCounter", 1] call epoch_getHUDCtrl) isEqualTo "") then { + EPOCH_geiger_shown = true; + + for "_i" from 1 to 8 do{ + (["geigerCounter", _i] call epoch_getHUDCtrl) ctrlSetText format ["x\addons\a3_epoch_assets_1\pictures\geiger\geiger_%1",_i]; + }; + _ledBG = (["geigerCounter", 4] call epoch_getHUDCtrl); + _lcdBG = (["geigerCounter", 5] call epoch_getHUDCtrl); + _lcdPos = ctrlPosition _lcdBG; + _ledPos = ctrlPosition _ledBG; + _parent = ctrlParentControlsGroup _lcdBG; + + _lcdPos set [0,(_lcdPos select 2) / 3.35]; + _lcdPos set [2,(_lcdPos select 2) * 43 / 100]; + + _lcd = (findDisplay 46) ctrlCreate ["rmx_geigerTXT",65765,_parent]; + _lcd ctrlSetPosition _lcdPos; + _lcd ctrlCommit 0; + _lcd ctrlSetText ""; //(random 1000 toFixed 1); + + _led = (findDisplay 46) ctrlCreate ["RscPicture",65766,_parent]; + _led ctrlSetPosition _ledPos; + _led ctrlCommit 0; + _led ctrlSetText ""; //"x\addons\a3_epoch_assets_1\pictures\geiger\geiger_4on"; + + uiNamespace setVariable ["EPOCH_geiger_LCD",_lcd]; + uiNamespace setVariable ["EPOCH_geiger_LED",_led]; + +} else { + call _removeControls; +}; + +true \ No newline at end of file diff --git a/Sources/epoch_code/gui/scripts/geiger/epoch_geiger_simulate.sqf b/Sources/epoch_code/gui/scripts/geiger/epoch_geiger_simulate.sqf new file mode 100644 index 00000000..14b2749f --- /dev/null +++ b/Sources/epoch_code/gui/scripts/geiger/epoch_geiger_simulate.sqf @@ -0,0 +1,46 @@ +disableSerialization; +_energyRange = _this; +_lcd = uiNamespace getVariable ["EPOCH_geiger_LCD",controlNull]; +_led = uiNamespace getVariable ["EPOCH_geiger_LED",controlNull]; + +_src = nearestObjects[player,["All"],_energyRange]; +_radObjects = _src select {(_x getVariable ["EPOCH_Rads", []]) select 0 > 0}; +_rads = 0; +{ + _reldir = player getRelDir _x; + + if (_reldir > 315 || _reldir < 45) then { //only capture 90 degrees in front of player + _reldir = if (_reldir > 315) then { 360 - _reldir} else {_reldir}; //convert into 0-45 degrees + _prc = 100 - (_reldir / 45 * 100); //current direction percent, 45 = 100% + + _x getVariable "EPOCH_Rads" params ["_str","_intensity"]; + _dist = player distance _x; + _radIntensity = if (_dist <= _intensity) then { //only capture rads when within distance + _rds = (_str / _dist); + _rdsPrc = (_prc / 100 * _rds); + _rdsPrc + } else { + 0 + }; + _rads = _rads + _radIntensity + }; +} forEach _radObjects; //sum up radiation of all objects in vicinity and in FOV + +{ + if ((_x select 0) in EPOCH_nearestLocations) then { + _x select 1 params ["_str","_intensity"]; + _dist = player distance getPos (_x select 0); + _radIntensity = if (_dist <= _intensity) then { + _str / _dist + } else { + 0 + }; + _rads = _rads + _radIntensity; + }; +}foreach EPOCH_radioactiveLocations; //sum up radiation of all radiactive locations in vicinity + +_rads = _rads + EPOCH_ambientRadiation; +_lcd ctrlSetText format ["%1r",_rads toFixed 1]; +_rads spawn epoch_geiger_animate; + +true diff --git a/Sources/epoch_code/init/client_init.sqf b/Sources/epoch_code/init/client_init.sqf index 2fa7d1d6..cded592f 100644 --- a/Sources/epoch_code/init/client_init.sqf +++ b/Sources/epoch_code/init/client_init.sqf @@ -58,6 +58,13 @@ EPOCH_buildOption = 0; EPOCH_nearestLocations = []; EPOCH_lastFiredLocation = []; +//Radiation +EPOCH_geiger_shown = false; +EPOCH_geiger_on = false; +EPOCH_geiger_mute_counter = false; +EPOCH_geiger_mute_warning = false; +EPOCH_ambientRadiation = 0; //TODO: needs to go server side. Adds constant incremental radiation to all players. Use in special events. + rmx_var_drag_MouseDown = false; rmx_var_dynamicHUD_groups = []; rmx_var_dynamicHUD_groupCTRL = []; diff --git a/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_self.hpp b/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_self.hpp index 7e166618..f091d83b 100644 --- a/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_self.hpp +++ b/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_self.hpp @@ -219,3 +219,46 @@ class veh_RemoveAmmo4 icon = "x\addons\a3_epoch_code\Data\UI\buttons\RemoveMag.paa"; tooltipcode = "format['Remove %1 from %2',getText(configFile >> 'CfgMagazines' >> (dyna_WeapsMagsTurret select 3 select 1) >> 'displayName'),getText(configFile >> 'CfgWeapons' >> (dyna_WeapsMagsTurret select 3 select 0) >> 'displayName')]"; }; + +class geiger_menu +{ + condition = "'ItemGeigerCounter_EPOCH' in dyna_assigneditems"; + icon = "x\addons\a3_epoch_assets_1\pictures\geiger\geiger_radiation.paa"; + tooltip = "Geiger counter settings"; + + class geiger_toggle + { + condition = "true"; + action = "call epoch_geiger_show_hide"; + icon = "x\addons\a3_epoch_assets_1\pictures\geiger\geiger_toggle.paa"; + tooltip = "Toggle HUD"; + }; + class geiger_counter_mute + { + condition = "!EPOCH_geiger_mute_counter"; + action = "EPOCH_geiger_mute_counter = !EPOCH_geiger_mute_counter"; + icon = "x\addons\a3_epoch_assets_1\pictures\geiger\geiger_volumeoff.paa"; + tooltip = "Mute counter"; + }; + class geiger_counter_unmute + { + condition = "EPOCH_geiger_mute_counter"; + action = "EPOCH_geiger_mute_counter = !EPOCH_geiger_mute_counter"; + icon = "x\addons\a3_epoch_assets_1\pictures\geiger\geiger_volumeon.paa"; + tooltip = "Unmute counter"; + }; + class geiger_warning_mute + { + condition = "!EPOCH_geiger_mute_warning"; + action = "EPOCH_geiger_mute_warning = !EPOCH_geiger_mute_warning"; + icon = "x\addons\a3_epoch_assets_1\pictures\geiger\geiger_alarmoff.paa"; + tooltip = "Mute warnings"; + }; + class geiger_warning_unmute + { + condition = "EPOCH_geiger_mute_warning"; + action = "EPOCH_geiger_mute_warning = !EPOCH_geiger_mute_warning"; + icon = "x\addons\a3_epoch_assets_1\pictures\geiger\geiger_alarmon.paa"; + tooltip = "Unmute warnings"; + }; +}; diff --git a/Sources/epoch_config/Configs/CfgClientFunctions.hpp b/Sources/epoch_config/Configs/CfgClientFunctions.hpp index 35661373..a11f1315 100644 --- a/Sources/epoch_config/Configs/CfgClientFunctions.hpp +++ b/Sources/epoch_config/Configs/CfgClientFunctions.hpp @@ -387,6 +387,12 @@ class CfgClientFunctions class favBar_getGearItem {}; class favBar_modifier {}; }; + class geiger { + file = "epoch_code\gui\scripts\geiger"; + class geiger_animate {}; + class geiger_show_hide {}; + class geiger_simulate {}; + }; }; }; diff --git a/Sources/epoch_config/Configs/CfgMasterLoop.hpp b/Sources/epoch_config/Configs/CfgMasterLoop.hpp index 20ff39e9..5d5ca975 100644 --- a/Sources/epoch_config/Configs/CfgMasterLoop.hpp +++ b/Sources/epoch_config/Configs/CfgMasterLoop.hpp @@ -48,6 +48,10 @@ class CfgMasterLoop { delay = 5; //used for FavBar, adjust as required }; + class Event9 + { + delay = 2; //used for geiger counter UI + }; }; }; diff --git a/Sources/epoch_server/init/server_init.sqf b/Sources/epoch_server/init/server_init.sqf index e4f9f038..25950bdf 100644 --- a/Sources/epoch_server/init/server_init.sqf +++ b/Sources/epoch_server/init/server_init.sqf @@ -269,7 +269,9 @@ if !(_radioactiveLocations isEqualTo []) then { if (_locations isEqualTo []) exitWith {}; private _selectedLoc = selectRandom _locations; _locations = _locations - [_selectedLoc]; - _radioactiveLocationsTmp pushBack [_selectedLoc,random 666]; + _locSize = size _selectedLoc; + _radius = sqrt((_locSize select 0)^2 + (_locSize select 1)^2); + _radioactiveLocationsTmp pushBack [_selectedLoc,[random 666,_radius]]; private _position = locationPosition _selectedLoc; _markers = ["Radiation", _position] call EPOCH_server_createGlobalMarkerSet; }; diff --git a/Sources/epoch_server_settings/EpochEvents/Satellite.sqf b/Sources/epoch_server_settings/EpochEvents/Satellite.sqf index 3e6feaab..f73216a2 100644 --- a/Sources/epoch_server_settings/EpochEvents/Satellite.sqf +++ b/Sources/epoch_server_settings/EpochEvents/Satellite.sqf @@ -22,7 +22,7 @@ if ((count _position) == 2) then{ }; // set rads - _satellite setVariable ["EPOCH_Rads", 10, true]; + _satellite setVariable ["EPOCH_Rads", [30,50], true]; //30 rads within 50 meters if (EPOCH_showSatellites) then{ _markers = ["Satellite",_position] call EPOCH_server_createGlobalMarkerSet;