From d25d79c48518201019fa281f9ca51e17831c13d5 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 29 Sep 2015 16:22:57 +0200 Subject: [PATCH 01/12] Goggles Code refactoring initial commit --- addons/goggles/ACE_Settings.hpp | 7 +++++++ addons/goggles/CfgEventHandlers.hpp | 32 ++++++++++++++++++++++++++--- addons/goggles/XEH_postInit.sqf | 27 ++++++++---------------- addons/goggles/XEH_preInit.sqf | 20 +++++------------- 4 files changed, 49 insertions(+), 37 deletions(-) diff --git a/addons/goggles/ACE_Settings.hpp b/addons/goggles/ACE_Settings.hpp index 6b3faa1823..a78c2866e0 100644 --- a/addons/goggles/ACE_Settings.hpp +++ b/addons/goggles/ACE_Settings.hpp @@ -1,4 +1,11 @@ + class ACE_Settings { + /*class GVAR(enable) { // @todo + value = 0; + typeName = "BOOL"; + isClientSettable = 1; + displayName = CSTRING(enable); + };*/ class GVAR(showInThirdPerson) { value = 0; typeName = "BOOL"; diff --git a/addons/goggles/CfgEventHandlers.hpp b/addons/goggles/CfgEventHandlers.hpp index 8c7edda20f..67f17fda18 100644 --- a/addons/goggles/CfgEventHandlers.hpp +++ b/addons/goggles/CfgEventHandlers.hpp @@ -1,10 +1,36 @@ + class Extended_PreInit_EventHandlers { class ADDON { init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; + class Extended_PostInit_EventHandlers { - class ADDON { - init = QUOTE(call COMPILE_FILE(XEH_postInit)); - }; + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; + +class Extended_Killed_EventHandlers { + class CAManBase { + class ADDON { + killed = QUOTE(_this call FUNC(handleKilled)); + }; + }; +}; + +class Extended_Fired_EventHandlers { + class CAManBase { + class ADDON { + fired = QUOTE(if (local (_this select 0)) then {_this call FUNC(handleFired)}); + }; + }; +}; + +class Extended_Explosion_EventHandlers { + class CAManBase { + class ADDON { + explosion = QUOTE(if (local (_this select 0)) then {_this call FUNC(handleExplosion)}); + }; + }; }; diff --git a/addons/goggles/XEH_postInit.sqf b/addons/goggles/XEH_postInit.sqf index 088ccc477a..51ffd14b49 100644 --- a/addons/goggles/XEH_postInit.sqf +++ b/addons/goggles/XEH_postInit.sqf @@ -1,24 +1,8 @@ -/* - * Author: Garth 'L-H' de Wet - * Sets up the glasses mod for usage. Initialises variables and event handlers. - * Shouldn't be called by a user/modder ever. Done by the engine. - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * None - * - * Public: No - */ #include "script_component.hpp" + if (!hasInterface) exitWith {}; -["ACE3 Common", QGVAR(wipeGlasses), localize LSTRING(WipeGlasses), -{ +["ACE3 Common", QGVAR(wipeGlasses), localize LSTRING(WipeGlasses), { if (!(GETVAR(ace_player,ACE_isUnconscious,false))) exitWith { call FUNC(clearGlasses); true @@ -26,7 +10,12 @@ if (!hasInterface) exitWith {}; false }, {false}, -[20, [true, true, false]], false] call cba_fnc_addKeybind; +[20, [true, true, false]], false] call CBA_fnc_addKeybind; + + + + + if isNil(QGVAR(UsePP)) then { GVAR(UsePP) = true; diff --git a/addons/goggles/XEH_preInit.sqf b/addons/goggles/XEH_preInit.sqf index 4eb7df91d1..c6fa4e12b2 100644 --- a/addons/goggles/XEH_preInit.sqf +++ b/addons/goggles/XEH_preInit.sqf @@ -1,22 +1,12 @@ -/* - * Author: Garth 'L-H' de Wet - * Initialises Goggles. - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * None - * - * Public: No - */ #include "script_component.hpp" ADDON = false; +PREP(handleExplosion); +PREP(handleFired); +PREP(handleKilled); + + PREP(applyDirtEffect); PREP(applyDust); PREP(applyGlassesEffect); From 2731ac360ab2ccb42863ec4e34127f15764661fe Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 29 Sep 2015 16:56:10 +0200 Subject: [PATCH 02/12] more goggles code cleanup --- addons/goggles/functions/fnc_dustHandler.sqf | 71 ++++++++++++-------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/addons/goggles/functions/fnc_dustHandler.sqf b/addons/goggles/functions/fnc_dustHandler.sqf index 44475d1acc..07d1bded75 100644 --- a/addons/goggles/functions/fnc_dustHandler.sqf +++ b/addons/goggles/functions/fnc_dustHandler.sqf @@ -1,5 +1,5 @@ /* - * Author: Garth 'L-H' de Wet + * Author: Garth 'L-H' de Wet, commy2 * Determines whether to place dust on the goggles, based on calibre of weapon fired and other requirements. * * Arguments: @@ -7,67 +7,82 @@ * 1: Weapon * * Return Value: - * None - * - * Example: - *ace_player addEventHandler ["Fired", {[_this select 0, _this select 1] call ace_goggles_fnc_dustHandler;}]; + * Function is handled? * * Public: No */ #include "script_component.hpp" -private ["_bullets", "_position", "_surface", "_weapon", "_cloudType", "_unit"]; -EXPLODE_2_PVT(_this,_unit,_weapon); -if (_unit != ace_player) exitWith {true}; + +params ["_unit", "_weapon"]; + +if (_unit != ACE_player) exitWith {true}; + +// no dust in rain +if (rain > 0.1) exitWith {true}; + +// effect only aplies when lying on the ground +if (stance _unit != "PRONE") exitWith {true}; + +private ["_position", "_particleConfig", "_cloudType", "_surface", "_bullets"]; + +// check if the unit really is on the ground and not in a building +_position = getPosATL _unit; + +if (_position select 2 > 0.2) exitWith {}; + +// get weapon dust effect +_particleConfig = configFile >> "CfgWeapons" >> _weapon >> "GunParticles"; + _cloudType = ""; -if (rain > 0.1) exitWith {true}; -if ((stance _unit) != "PRONE") exitWith {true}; - -if (isClass(configFile >> "CfgWeapons" >> _weapon >> "GunParticles" >> "FirstEffect")) then { - _cloudType = getText(configFile >> "CfgWeapons" >> _weapon >> "GunParticles" >> "FirstEffect" >> "effectName"); +if (isClass (_particleConfig >> "FirstEffect")) then { // @todo read this with custom / non-standard config classnames + _cloudType = getText (_particleConfig >> "FirstEffect" >> "effectName"); } else { - if (isClass(configFile >> "CfgWeapons" >> _weapon >> "GunParticles" >> "effect1")) then { - _cloudType = getText(configFile >> "CfgWeapons" >> _weapon >> "GunParticles" >> "effect1" >> "effectName"); + if (isClass (_particleConfig >> "effect1")) then { + _cloudType = getText (_particleConfig >> "effect1" >> "effectName"); }; }; +// quit if the weapon causes no dust effect if (_cloudType == "") exitWith {true}; -_position = getPosATL _unit; +// get if the surface is dusty +if (surfaceIsWater _position) exitWith {true}; -if (surfaceIsWater _position) exitWith {}; -if ((_position select 2) > 0.2) exitWith {}; - -_surface = surfaceType _position; +_surface = surfaceType _position select [1]; // cuts of the leading # if (_surface != GVAR(surfaceCache)) then { GVAR(surfaceCache) = _surface; - _surface = ([_surface, "#"] call CBA_fnc_split) select 1; - GVAR(surfaceCacheIsDust) = getNumber (ConfigFile >> "CfgSurfaces" >> _surface >> "dust") >= 0.1; + GVAR(surfaceCacheIsDust) = getNumber (configFile >> "CfgSurfaces" >> _surface >> "dust") >= 0.1; }; +// quit if surface isn't dusty if (!GVAR(surfaceCacheIsDust)) exitWith {}; +// increment dust value with type bullet _bullets = GETDUSTT(DBULLETS); -if ((ACE_diagTime - GETDUSTT(DTIME)) > 1) then { +if (ACE_diagTime - GETDUSTT(DTIME) > 1) then { _bullets = 0; }; _bullets = _bullets + 1; + SETDUST(DBULLETS,_bullets); SETDUST(DTIME,ACE_diagTime); +// apply dust effect if the amount of fired bullets is over the threshold if (GETDUSTT(DAMOUNT) < 2) then { - private "_bulletsRequired"; - _bulletsRequired = 100; - if (isNumber (ConfigFile >> _cloudType >> "ACE_Goggles_BulletCount")) then { - _bulletsRequired = getNumber (ConfigFile >> _cloudType >> "ACE_Goggles_BulletCount"); + local _bulletsRequired = 100; + + if (isNumber (configFile >> _cloudType >> QGVAR(BulletCount))) then { + _bulletsRequired = getNumber (configFile >> _cloudType >> QGVAR(BulletCount)); }; - if (_bulletsRequired <= _bullets) then { + if (_bullets > _bulletsRequired) then { SETDUST(DACTIVE,true); call FUNC(applyDust); }; }; + true From 477e9f06b60e19dab33c53e0b77ffefee0ef2c61 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 29 Sep 2015 17:09:23 +0200 Subject: [PATCH 03/12] more goggles code cleanup --- addons/goggles/XEH_postInit.sqf | 4 ++-- addons/goggles/XEH_preInit.sqf | 4 ++-- .../functions/{fnc_applyDirtEffect.sqf => fnc_applyDirt.sqf} | 2 +- .../{fnc_applyGlassesEffect.sqf => fnc_applyGlasses.sqf} | 4 ++-- addons/goggles/functions/fnc_checkGoggles.sqf | 2 +- addons/goggles/functions/fnc_dustHandler.sqf | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) rename addons/goggles/functions/{fnc_applyDirtEffect.sqf => fnc_applyDirt.sqf} (93%) rename addons/goggles/functions/{fnc_applyGlassesEffect.sqf => fnc_applyGlasses.sqf} (94%) diff --git a/addons/goggles/XEH_postInit.sqf b/addons/goggles/XEH_postInit.sqf index 51ffd14b49..0cff31e9d2 100644 --- a/addons/goggles/XEH_postInit.sqf +++ b/addons/goggles/XEH_postInit.sqf @@ -49,7 +49,7 @@ FUNC(CheckGlasses) = { player addEventHandler ["Explosion", { private "_effects"; if (alive ace_player) then { - call FUNC(ApplyDirtEffect); + call FUNC(ApplyDirt); if (GETBROKEN) exitWith {}; if (((_this select 1) call FUNC(GetExplosionIndex)) < getNumber(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_Resistance")) exitWith {}; if !([ace_player] call FUNC(isGogglesVisible)) exitWith {["GlassesCracked",[ace_player]] call EFUNC(common,localEvent);}; @@ -90,7 +90,7 @@ player AddEventHandler ["Put", {call FUNC(checkGlasses);}]; if (call FUNC(ExternalCamera)) exitWith {call FUNC(RemoveGlassesEffect)}; if ([ace_player] call FUNC(isGogglesVisible)) then { - [_this select 0] call FUNC(applyGlassesEffect); + [_this select 0] call FUNC(applyGlasses); } else { call FUNC(removeGlassesEffect); }; diff --git a/addons/goggles/XEH_preInit.sqf b/addons/goggles/XEH_preInit.sqf index c6fa4e12b2..1a1222b4a1 100644 --- a/addons/goggles/XEH_preInit.sqf +++ b/addons/goggles/XEH_preInit.sqf @@ -7,9 +7,9 @@ PREP(handleFired); PREP(handleKilled); -PREP(applyDirtEffect); +PREP(applyDirt); PREP(applyDust); -PREP(applyGlassesEffect); +PREP(applyGlasses); PREP(checkGoggles); PREP(clearGlasses); diff --git a/addons/goggles/functions/fnc_applyDirtEffect.sqf b/addons/goggles/functions/fnc_applyDirt.sqf similarity index 93% rename from addons/goggles/functions/fnc_applyDirtEffect.sqf rename to addons/goggles/functions/fnc_applyDirt.sqf index 068f7639d2..87f140b91d 100644 --- a/addons/goggles/functions/fnc_applyDirtEffect.sqf +++ b/addons/goggles/functions/fnc_applyDirt.sqf @@ -9,7 +9,7 @@ * Succeeded * * Example: - * _applied = call ace_goggles_fnc_ApplyDirtEffect; + * _applied = call ace_goggles_fnc_ApplyDirt; * * Public: Yes */ diff --git a/addons/goggles/functions/fnc_applyGlassesEffect.sqf b/addons/goggles/functions/fnc_applyGlasses.sqf similarity index 94% rename from addons/goggles/functions/fnc_applyGlassesEffect.sqf rename to addons/goggles/functions/fnc_applyGlasses.sqf index 7abb10d448..e524a503a6 100644 --- a/addons/goggles/functions/fnc_applyGlassesEffect.sqf +++ b/addons/goggles/functions/fnc_applyGlasses.sqf @@ -11,7 +11,7 @@ * None * * Example: - * [goggles ace_player] call ace_goggles_fnc_ApplyGlassesEffect; + * [goggles ace_player] call ace_goggles_fnc_ApplyGlasses * * Public: No */ @@ -46,7 +46,7 @@ if (_glassImagePath != "") then { }; if GETDIRT then { - call FUNC(applyDirtEffect); + call FUNC(applyDirt); }; if GETDUSTT(DACTIVE) then { diff --git a/addons/goggles/functions/fnc_checkGoggles.sqf b/addons/goggles/functions/fnc_checkGoggles.sqf index 84b86c3da4..0587469f02 100644 --- a/addons/goggles/functions/fnc_checkGoggles.sqf +++ b/addons/goggles/functions/fnc_checkGoggles.sqf @@ -35,7 +35,7 @@ if (true) then { }; }; if !(GVAR(EffectsActive)) then { - [goggles ace_player] call FUNC(applyGlassesEffect); + [goggles ace_player] call FUNC(applyGlasses); } else { if ([goggles ace_player] call FUNC(isDivingGoggles) && {underwater ace_player}) then { call FUNC(removeRainEffect); diff --git a/addons/goggles/functions/fnc_dustHandler.sqf b/addons/goggles/functions/fnc_dustHandler.sqf index 07d1bded75..2f23f69afb 100644 --- a/addons/goggles/functions/fnc_dustHandler.sqf +++ b/addons/goggles/functions/fnc_dustHandler.sqf @@ -28,7 +28,7 @@ private ["_position", "_particleConfig", "_cloudType", "_surface", "_bullets"]; // check if the unit really is on the ground and not in a building _position = getPosATL _unit; -if (_position select 2 > 0.2) exitWith {}; +if (_position select 2 > 0.2) exitWith {true}; // get weapon dust effect _particleConfig = configFile >> "CfgWeapons" >> _weapon >> "GunParticles"; @@ -57,7 +57,7 @@ if (_surface != GVAR(surfaceCache)) then { }; // quit if surface isn't dusty -if (!GVAR(surfaceCacheIsDust)) exitWith {}; +if (!GVAR(surfaceCacheIsDust)) exitWith {true}; // increment dust value with type bullet _bullets = GETDUSTT(DBULLETS); From d051d4c2088aa5d3b3cf7ad2ca82ee5f955dbc3e Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 29 Sep 2015 17:57:09 +0200 Subject: [PATCH 04/12] more goggles code cleanup --- .../goggles/functions/fnc_handleExplosion.sqf | 0 addons/goggles/functions/fnc_handleFired.sqf | 0 addons/goggles/functions/fnc_handleKilled.sqf | 0 .../goggles/functions/fnc_isDivingGoggles.sqf | 20 ++++++++------- .../functions/fnc_isGogglesVisible.sqf | 25 ++++++++----------- 5 files changed, 22 insertions(+), 23 deletions(-) create mode 100644 addons/goggles/functions/fnc_handleExplosion.sqf create mode 100644 addons/goggles/functions/fnc_handleFired.sqf create mode 100644 addons/goggles/functions/fnc_handleKilled.sqf diff --git a/addons/goggles/functions/fnc_handleExplosion.sqf b/addons/goggles/functions/fnc_handleExplosion.sqf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/addons/goggles/functions/fnc_handleFired.sqf b/addons/goggles/functions/fnc_handleFired.sqf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/addons/goggles/functions/fnc_handleKilled.sqf b/addons/goggles/functions/fnc_handleKilled.sqf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/addons/goggles/functions/fnc_isDivingGoggles.sqf b/addons/goggles/functions/fnc_isDivingGoggles.sqf index bcc6b0db5e..ab5bb74269 100644 --- a/addons/goggles/functions/fnc_isDivingGoggles.sqf +++ b/addons/goggles/functions/fnc_isDivingGoggles.sqf @@ -1,22 +1,24 @@ /* - * Author: Garth 'L-H' de Wet + * Author: commy2 * Determines whether passed goggles is diving goggles or a variant of them. * * Arguments: * 0: Glasses classname * * Return Value: - * Whether diving goggles are worn + * Check if these goggles are diving goggles * * Example: - * [(goggles ace_player)] call ace_goggles_fnc_isDivingGoggles; + * [goggles ace_player] call ace_goggles_fnc_isDivingGoggles; * * Public: Yes */ #include "script_component.hpp" -private ["_result", "_glasses"]; -_glasses = _this select 0; -_result = _glasses == "G_Diving"; -if (_result) exitWith {true}; -_result = [configFile >> "CfgGlasses" >> _glasses, configFile >> "CfgGlasses" >> "G_Diving"] call CBA_fnc_inheritsFrom; -_result + +params ["_glasses"]; + +local _config = configFile >> "CfgGlasses" >> _glasses; + +if (!isClass _config) exitWith {false}; + +getNumber (_config >> "mode") == 1 // return diff --git a/addons/goggles/functions/fnc_isGogglesVisible.sqf b/addons/goggles/functions/fnc_isGogglesVisible.sqf index 80f9de4830..dfa2b97087 100644 --- a/addons/goggles/functions/fnc_isGogglesVisible.sqf +++ b/addons/goggles/functions/fnc_isGogglesVisible.sqf @@ -1,6 +1,6 @@ /* * Author: Garth 'L-H' de Wet - * Determines if goggles are visible on passed unit (Also checks if unit is in vehicle and cameraView is set to GUNNER) + * Determines if goggles are visible on passed unit. * * Arguments: * 0: Unit @@ -16,20 +16,17 @@ #include "script_component.hpp" params ["_unit"]; -private ["_currentGlasses", "_result", "_position", "_visible"]; + +private ["_currentGlasses", "_position"]; _currentGlasses = goggles _unit; -_result = false; -if (_currentGlasses != "") then { - _position = getPosASLW _unit; - if (surfaceIsWater _position && {((_position select 2) < 0.25)}) exitWith { - _result = ([_currentGlasses] call FUNC(isDivingGoggles)); - }; - if (getNumber (ConfigFile >> "CfgGlasses" >> _currentGlasses >> "ACE_Resistance") == 0) exitWith { - _result = false; - }; - _result = !([_currentGlasses] call FUNC(isDivingGoggles)); -}; +if (_currentGlasses == "") exitWith {false}; -_result +// requires ACE_Resistance config entry. Returns false for balaclavas and bandanas. +if (getNumber (configFile >> "CfgGlasses" >> _currentGlasses >> "ACE_Resistance") == 0) exitWith {false}; + +// check if in water and has diving goggles or on land and not diving goggles +_position = getPosASLW _unit; + +(surfaceIsWater _position && {_position select 2 < 0.25}) isEqualTo (_currentGlasses call FUNC(isDivingGoggles)) // return From 53bfcdb61e677dbf7b25ca6c5a2ea5c3959bd8e3 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 29 Sep 2015 18:51:24 +0200 Subject: [PATCH 05/12] more goggles code cleanup --- .../goggles/functions/fnc_externalCamera.sqf | 8 ++-- .../functions/fnc_getExplosionIndex.sqf | 17 ++++--- .../goggles/functions/fnc_isInRotorWash.sqf | 44 +++++++++---------- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/addons/goggles/functions/fnc_externalCamera.sqf b/addons/goggles/functions/fnc_externalCamera.sqf index ddc05e6b87..1af09827ab 100644 --- a/addons/goggles/functions/fnc_externalCamera.sqf +++ b/addons/goggles/functions/fnc_externalCamera.sqf @@ -6,15 +6,13 @@ * None * * Return Value: - * Whether the camera is in external view or not. If the "showInThirdPerson" option is checked, this will always return false. + * Whether the camera is in external view or not. * * Example: - * call ace_goggles_fnc_removeRainEffect; + * call ace_goggles_fnc_externalCamera; * * Public: Yes */ #include "script_component.hpp" -if (GVAR(showInThirdPerson)) exitWith { false }; - -(cameraView in ["EXTERNAL", "GROUP"] || {call EFUNC(common,isFeatureCameraActive)}) +cameraView in ["EXTERNAL", "GROUP"] || EFUNC(common,isFeatureCameraActive) // return diff --git a/addons/goggles/functions/fnc_getExplosionIndex.sqf b/addons/goggles/functions/fnc_getExplosionIndex.sqf index 6e16085b2c..9d7c4004c7 100644 --- a/addons/goggles/functions/fnc_getExplosionIndex.sqf +++ b/addons/goggles/functions/fnc_getExplosionIndex.sqf @@ -1,5 +1,5 @@ /* - * Author: Garth 'L-H' de Wet + * Author: Garth 'L-H' de Wet, commy2 * Turns 0-1 damage of explosion Event into a rating system of 0-3 * * Arguments: @@ -13,13 +13,12 @@ * * Public: No */ -private ["_effectIndex"]; +#include "script_component.hpp" -_effectIndex = switch true do { - case (_this <= 0.04): {0}; - case (_this <= 0.06): {1}; - case (_this <= 0.09): {2}; - default {3}; -}; +params ["_damage"]; -_effectIndex +if (_damage <= 0.04) exitWith {0}; +if (_damage <= 0.06) exitWith {1}; +if (_damage <= 0.09) exitWith {2}; + +3 diff --git a/addons/goggles/functions/fnc_isInRotorWash.sqf b/addons/goggles/functions/fnc_isInRotorWash.sqf index ef6391fdc6..5ddc59192a 100644 --- a/addons/goggles/functions/fnc_isInRotorWash.sqf +++ b/addons/goggles/functions/fnc_isInRotorWash.sqf @@ -1,10 +1,10 @@ /* - * Author: Garth 'L-H' de Wet + * Author: Garth 'L-H' de Wet, commy2 * Checks for nearby running helicopters (within 15m) * * Arguments: * 0: Unit - * 1: Radius to check for helicopter Default: 15 (optional) + * 1: Radius to check for helicopter (default: 15) * * Return Value: * : @@ -12,35 +12,31 @@ * 1: Amount of rotor wash. * * Example: - * if (([ace_player, 10] call ace_goggles_fnc_isInRotorWash) select 0) then { hint "Rotor wash"; }; - * if (([ace_player] call ace_goggles_fnc_isInRotorWash) select 0) then { hint "Rotor wash"; }; + * if ([ace_player, 10] call ace_goggles_fnc_isInRotorWash select 0) then { hint "Rotor wash"; }; + * if ([ace_player] call ace_goggles_fnc_isInRotorWash select 0) then { hint "Rotor wash"; }; * * Public: Yes */ #include "script_component.hpp" -private ["_heli", "_unit", "_result", "_radius"]; -_unit = _this select 0; -_radius = 15; -if (count _this > 1) then { - _radius = _this select 1; -}; -_result = [false, _radius + 2]; -_heli = (getPosATL _unit) nearEntities [["Helicopter"], _radius]; +params ["_unit", ["_radius", 15]]; + +local _rotorWash = [false, 0]; + { - if !(_x isKindOf "ParachuteBase") then { - if (isEngineOn _x) then { - private "_distance"; - _distance = (_radius - (_unit distance _x)); - if (_distance != 0) then { - _distance = _distance / _radius; - }; - if (_distance < (_result select 1)) then { - _result = [true, _distance]; - }; + if (isEngineOn _x) then { + local _distance = _unit distance _x; + + // convert distance to 0...1 range, where 0 is the maximum radius + _distance = 1 - _distance / _radius; + + // use highest amount of rotor wash as return value in case of multiple helicopters + if (_distance > _rotorWash select 1) then { + _rotorWash set [0, true]; + _rotorWash set [1, _distance]; }; }; false -} count _heli; +} count (position _unit nearEntities [["Helicopter"], _radius]); -_result +_rotorWash From d1aacf3fef3cc6c5719f5d28ab962cae9b108ecd Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 29 Sep 2015 19:51:41 +0200 Subject: [PATCH 06/12] more goggles code cleanup --- addons/goggles/XEH_postInit.sqf | 6 +- addons/goggles/XEH_preInit.sqf | 48 ++++++------ addons/goggles/functions/fnc_applyDirt.sqf | 33 -------- .../goggles/functions/fnc_applyDirtEffect.sqf | 39 ++++++++++ addons/goggles/functions/fnc_applyDust.sqf | 60 --------------- .../goggles/functions/fnc_applyDustEffect.sqf | 77 +++++++++++++++++++ ...Glasses.sqf => fnc_applyGlassesEffect.sqf} | 39 +++++----- .../goggles/functions/fnc_applyRainEffect.sqf | 68 ++++++++++++++++ addons/goggles/functions/fnc_checkGoggles.sqf | 2 +- addons/goggles/functions/fnc_dustHandler.sqf | 2 +- addons/goggles/functions/fnc_onEachFrame.sqf | 4 +- addons/goggles/functions/fnc_rainEffect.sqf | 53 ------------- 12 files changed, 238 insertions(+), 193 deletions(-) delete mode 100644 addons/goggles/functions/fnc_applyDirt.sqf create mode 100644 addons/goggles/functions/fnc_applyDirtEffect.sqf delete mode 100644 addons/goggles/functions/fnc_applyDust.sqf create mode 100644 addons/goggles/functions/fnc_applyDustEffect.sqf rename addons/goggles/functions/{fnc_applyGlasses.sqf => fnc_applyGlassesEffect.sqf} (52%) create mode 100644 addons/goggles/functions/fnc_applyRainEffect.sqf delete mode 100644 addons/goggles/functions/fnc_rainEffect.sqf diff --git a/addons/goggles/XEH_postInit.sqf b/addons/goggles/XEH_postInit.sqf index 0cff31e9d2..2d78e6f372 100644 --- a/addons/goggles/XEH_postInit.sqf +++ b/addons/goggles/XEH_postInit.sqf @@ -49,7 +49,7 @@ FUNC(CheckGlasses) = { player addEventHandler ["Explosion", { private "_effects"; if (alive ace_player) then { - call FUNC(ApplyDirt); + call FUNC(applyDirtEffect); if (GETBROKEN) exitWith {}; if (((_this select 1) call FUNC(GetExplosionIndex)) < getNumber(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_Resistance")) exitWith {}; if !([ace_player] call FUNC(isGogglesVisible)) exitWith {["GlassesCracked",[ace_player]] call EFUNC(common,localEvent);}; @@ -90,7 +90,7 @@ player AddEventHandler ["Put", {call FUNC(checkGlasses);}]; if (call FUNC(ExternalCamera)) exitWith {call FUNC(RemoveGlassesEffect)}; if ([ace_player] call FUNC(isGogglesVisible)) then { - [_this select 0] call FUNC(applyGlasses); + [_this select 0] call FUNC(applyGlassesEffect); } else { call FUNC(removeGlassesEffect); }; @@ -116,5 +116,5 @@ player AddEventHandler ["Put", {call FUNC(checkGlasses);}]; }] call EFUNC(common,addEventHandler); call FUNC(checkGlasses); [FUNC(CheckGoggles), 1, []] call CBA_fnc_addPerFrameHandler; -[FUNC(rainEffect), 0.5, []] call CBA_fnc_addPerFrameHandler; +[FUNC(applyRainEffect), 0.5, []] call CBA_fnc_addPerFrameHandler; [FUNC(onEachFrame), 0, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/goggles/XEH_preInit.sqf b/addons/goggles/XEH_preInit.sqf index 1a1222b4a1..be54cf73e6 100644 --- a/addons/goggles/XEH_preInit.sqf +++ b/addons/goggles/XEH_preInit.sqf @@ -2,31 +2,35 @@ ADDON = false; -PREP(handleExplosion); -PREP(handleFired); -PREP(handleKilled); - - -PREP(applyDirt); -PREP(applyDust); -PREP(applyGlasses); - -PREP(checkGoggles); -PREP(clearGlasses); -PREP(dustHandler); -PREP(externalCamera); -PREP(getExplosionIndex); - -PREP(isDivingGoggles); -PREP(isGogglesVisible); -PREP(isInRotorWash); - -PREP(onEachFrame); -PREP(rainEffect); - +// effects +PREP(applyDirtEffect); +PREP(applyDustEffect); +PREP(applyGlassesEffect); +PREP(applyRainEffect); PREP(removeDirtEffect); PREP(removeDustEffect); PREP(removeGlassesEffect); PREP(removeRainEffect); +// general +PREP(externalCamera); +PREP(isDivingGoggles); +PREP(isGogglesVisible); +PREP(isInRotorWash); +PREP(getExplosionIndex); + +// eventhandlers +PREP(handleExplosion); +PREP(handleFired); +PREP(handleKilled); + + + +PREP(checkGoggles); +PREP(clearGlasses); +PREP(dustHandler); + +PREP(onEachFrame); + + ADDON = true; diff --git a/addons/goggles/functions/fnc_applyDirt.sqf b/addons/goggles/functions/fnc_applyDirt.sqf deleted file mode 100644 index 87f140b91d..0000000000 --- a/addons/goggles/functions/fnc_applyDirt.sqf +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet - * Adds dirt effect to the glasses. - * - * Arguments: - * None - * - * Return Value: - * Succeeded - * - * Example: - * _applied = call ace_goggles_fnc_ApplyDirt; - * - * Public: Yes - */ -#include "script_component.hpp" - -if (cameraOn != ace_player || {call FUNC(externalCamera)}) exitWith{false}; -private ["_dirtImage", "_applied", "_effects"]; -_effects = GETGLASSES(ace_player); -_effects set [DIRT, true]; -SETGLASSES(ace_player,_effects); - -if ([ace_player] call FUNC(isGogglesVisible)) then{ - _dirtImage = getText(ConfigFile >> "CfgGlasses" >> (goggles ace_player) >> "ACE_OverlayDirt"); - if (_dirtImage != "") then { - 100 cutRsc["RscACE_GogglesEffects", "PLAIN",0.1, false]; - - (GETUVAR(GVAR(DisplayEffects),displayNull) displayCtrl 10660) ctrlSetText _dirtImage; - }; -}; - -true diff --git a/addons/goggles/functions/fnc_applyDirtEffect.sqf b/addons/goggles/functions/fnc_applyDirtEffect.sqf new file mode 100644 index 0000000000..b8aedd5e64 --- /dev/null +++ b/addons/goggles/functions/fnc_applyDirtEffect.sqf @@ -0,0 +1,39 @@ +/* + * Author: Garth 'L-H' de Wet + * Adds dirt effect to the glasses. + * + * Arguments: + * None + * + * Return Value: + * Succeeded + * + * Example: + * _applied = call ace_goggles_fnc_applyDirtEffect + * + * Public: Yes + */ +#include "script_component.hpp" + +if (GVAR(showInThirdPerson)) exitWith {false}; +if (call FUNC(externalCamera)) exitWith {false}; + +private ["_unit", "_effects"]; + +_unit = ACE_player; + +_effects = GETGLASSES(_unit); +_effects set [DIRT, true]; + +SETGLASSES(_unit,_effects); + +if ([_unit] call FUNC(isGogglesVisible)) then { + local _dirtImage = getText (configFile >> "CfgGlasses" >> goggles _unit >> "ACE_OverlayDirt"); + + if (_dirtImage != "") then { + (QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 0.1, false]; // @todo init as 100 + (GETUVAR(GVAR(DisplayEffects),displayNull) displayCtrl 10660) ctrlSetText _dirtImage; + }; +}; + +true diff --git a/addons/goggles/functions/fnc_applyDust.sqf b/addons/goggles/functions/fnc_applyDust.sqf deleted file mode 100644 index a1ac88c78d..0000000000 --- a/addons/goggles/functions/fnc_applyDust.sqf +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet - * Applies dust to screen. - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * call ace_goggles_fnc_ApplyDust; - * - * Public: Yes - */ -#include "script_component.hpp" - -if (call FUNC(ExternalCamera)) exitWith {}; -if ([ace_player] call FUNC(isGogglesVisible)) exitWith { - 100 cutRsc["RscACE_GogglesEffects", "PLAIN",2,false]; - (uiNamespace getVariable ["ACE_Goggles_DisplayEffects", displayNull] displayCtrl 10662) ctrlSetText format[getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_DustPath"), GETDUSTT(DAMOUNT)+1]; - SETDUST(DAMOUNT,CLAMP(GETDUSTT(DAMOUNT)+1,0,1)); - SETDUST(DBULLETS,0); -}; - -if (GETVAR(ace_player,ACE_EyesDamaged,false)) exitWith {SETDUST(DACTIVE,false);SETDUST(DBULLETS,0);SETDUST(DAMOUNT,0);}; -SETDUST(DAMOUNT,CLAMP(GETDUSTT(DAMOUNT)+1,0,2)); - -private "_amount"; -_amount = 1 - (GETDUSTT(DAMOUNT) * 0.125); - -GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [_amount,_amount,_amount,_amount],[1,1,1,0]]; -GVAR(PostProcessEyes) ppEffectCommit 1; -GVAR(PostProcessEyes) ppEffectEnable true; -SETDUST(DBULLETS,0); - -if (GVAR(DustHandler) != -1) then { // should be fixed in dev CBA - [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); - GVAR(DustHandler) = -1; -}; -GVAR(DustHandler) = [{ - if (ACE_diagTime >= GETDUSTT(DTIME) + 3) then { - SETDUST(DAMOUNT,CLAMP(GETDUSTT(DAMOUNT)-1,0,2)); - private "_amount"; - _amount = 1 - (GETDUSTT(DAMOUNT) * 0.125); - if !(ace_player getVariable ["ACE_EyesDamaged", false]) then { - GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [_amount,_amount,_amount,_amount],[1,1,1,0]]; - GVAR(PostProcessEyes) ppEffectCommit 0.5; - }; - if (GETDUSTT(DAMOUNT) <= 0) then { - GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [1,1,1,1],[1,1,1,0]]; - GVAR(PostProcessEyes) ppEffectCommit 2; - [{GVAR(PostProcessEyes) ppEffectEnable false;}, [], 2, 0.5] call EFUNC(common,waitAndExecute); - SETDUST(DACTIVE,false); - SETDUST(DBULLETS,0); - [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); - GVAR(DustHandler) = -1; - }; - }; -},0,[]] call CALLSTACK(CBA_fnc_addPerFrameHandler); diff --git a/addons/goggles/functions/fnc_applyDustEffect.sqf b/addons/goggles/functions/fnc_applyDustEffect.sqf new file mode 100644 index 0000000000..6e89a8df6b --- /dev/null +++ b/addons/goggles/functions/fnc_applyDustEffect.sqf @@ -0,0 +1,77 @@ +/* + * Author: Garth 'L-H' de Wet + * Applies dust to screen. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * call ace_goggles_fnc_applyDustEffect + * + * Public: Yes + */ +#include "script_component.hpp" + +if (GVAR(showInThirdPerson)) exitWith {false}; +if (call FUNC(ExternalCamera)) exitWith {}; + +private ["_unit", "_amount"]; + +_unit = ACE_player; + +if ([_unit] call FUNC(isGogglesVisible)) exitWith { + (QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 2, false]; + + ((GETUVAR(GVAR(DisplayEffects),displayNull)) displayCtrl 10662) ctrlSetText format [getText (configFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_DustPath"), GETDUSTT(DAMOUNT) + 1]; + + SETDUST(DAMOUNT,CLAMP(GETDUSTT(DAMOUNT) + 1,0,1)); + SETDUST(DBULLETS,0); +}; + +if (GETVAR(_unit,ACE_EyesDamaged,false)) exitWith { + SETDUST(DACTIVE,false); + SETDUST(DBULLETS,0); + SETDUST(DAMOUNT,0); +}; + +SETDUST(DAMOUNT,CLAMP(GETDUSTT(DAMOUNT) + 1,0,2)); + +_amount = 1 - (GETDUSTT(DAMOUNT) * 0.125); + +GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [_amount, _amount, _amount, _amount], [1, 1, 1, 0]]; +GVAR(PostProcessEyes) ppEffectCommit 1; +GVAR(PostProcessEyes) ppEffectEnable true; + +SETDUST(DBULLETS,0); + +[GVAR(DustHandler)] call CBA_fnc_removePerFrameHandler; +GVAR(DustHandler) = -1; + +GVAR(DustHandler) = [{ + if (ACE_diagTime >= GETDUSTT(DTIME) + 3) then { + SETDUST(DAMOUNT,CLAMP(GETDUSTT(DAMOUNT)-1,0,2)); + + local _amount = 1 - (GETDUSTT(DAMOUNT) * 0.125); + + if !(_unit getVariable ["ACE_EyesDamaged", false]) then { + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [_amount, _amount, _amount, _amount], [1, 1, 1, 0]]; + GVAR(PostProcessEyes) ppEffectCommit 0.5; + }; + + if (GETDUSTT(DAMOUNT) <= 0) then { + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 1, 0]]; + GVAR(PostProcessEyes) ppEffectCommit 2; + + [{GVAR(PostProcessEyes) ppEffectEnable false}, [], 2] call EFUNC(common,waitAndExecute); + + SETDUST(DACTIVE,false); + SETDUST(DBULLETS,0); + + [GVAR(DustHandler)] call CBA_fnc_removePerFrameHandler; + GVAR(DustHandler) = -1; + }; + }; +}, 0, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/goggles/functions/fnc_applyGlasses.sqf b/addons/goggles/functions/fnc_applyGlassesEffect.sqf similarity index 52% rename from addons/goggles/functions/fnc_applyGlasses.sqf rename to addons/goggles/functions/fnc_applyGlassesEffect.sqf index e524a503a6..a8ccf23633 100644 --- a/addons/goggles/functions/fnc_applyGlasses.sqf +++ b/addons/goggles/functions/fnc_applyGlassesEffect.sqf @@ -11,20 +11,23 @@ * None * * Example: - * [goggles ace_player] call ace_goggles_fnc_ApplyGlasses + * [goggles ace_player] call ace_goggles_fnc_applyGlassesEffect * * Public: No */ #include "script_component.hpp" -private["_postProcessColour", "_postProcessTintAmount", "_glassesClassname", "_glassImagePath"]; - -_glassesClassname = _this select 0; -_postProcessColour = getArray(configFile >> "CfgGlasses" >> _glassesClassname >> "ACE_Color"); -_postProcessTintAmount = getNumber(configFile >> "CfgGlasses" >> _glassesClassname >> "ACE_TintAmount"); +params ["_glasses"]; +// remove old effect call FUNC(removeGlassesEffect); -GVAR(EffectsActive) = true; + +private ["_config", "_postProcessColour", "_postProcessTintAmount", "_imagePath"]; + +_config = configFile >> "CfgGlasses" >> _glasses; + +_postProcessColour = getArray (_config >> "ACE_Color"); +_postProcessTintAmount = getNumber (_config >> "ACE_TintAmount"); if (_postProcessTintAmount != 0 && {GVAR(UsePP)}) then { _postProcessColour set [3, _postProcessTintAmount/100]; @@ -36,20 +39,20 @@ if (_postProcessTintAmount != 0 && {GVAR(UsePP)}) then { GVAR(PostProcess) ppEffectCommit 30; }; -_glassImagePath = getText(configFile >> "CfgGlasses" >> _glassesClassname >> "ACE_Overlay"); -if GETBROKEN then { - _glassImagePath = getText(configFile >> "CfgGlasses" >> _glassesClassname >> "ACE_OverlayCracked"); -}; -if (_glassImagePath != "") then { - 150 cutRsc["RscACE_Goggles", "PLAIN",1, false]; - (GLASSDISPLAY displayCtrl 10650) ctrlSetText _glassImagePath; +_imagePath = getText (_config >> ["ACE_Overlay", "ACE_OverlayCracked"] select GETBROKEN); + +if (_imagePath != "") then { + (QGVAR(GogglesLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_Goggles", "PLAIN", 1, false]; // @todo init as 150 + (GLASSDISPLAY displayCtrl 10650) ctrlSetText _imagePath; }; -if GETDIRT then { - call FUNC(applyDirt); +if (GETDIRT) then { + call FUNC(applyDirtEffect); }; -if GETDUSTT(DACTIVE) then { +if (GETDUSTT(DACTIVE)) then { SETDUST(DAMOUNT,CLAMP(GETDUSTT(DAMOUNT)-1,0,2)); - call FUNC(applyDust); + call FUNC(applyDustEffect); }; + +GVAR(EffectsActive) = true; diff --git a/addons/goggles/functions/fnc_applyRainEffect.sqf b/addons/goggles/functions/fnc_applyRainEffect.sqf new file mode 100644 index 0000000000..7e1260a453 --- /dev/null +++ b/addons/goggles/functions/fnc_applyRainEffect.sqf @@ -0,0 +1,68 @@ +/* + * Author: Garth 'L-H' de Wet + * Handles rain effects being created on glasses. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * call ace_goggles_fnc_applyRainEffect; + * + * Public: No + */ +#include "script_component.hpp" + +private ["_unit", "_fnc_underCover"]; + +_unit = ACE_player; + +if (!alive _unit) exitWith {}; + +_fnc_underCover = { + params ["_unit"]; + + if (vehicle _unit != _unit && {!isTurnedOut _unit}) exitWith {true}; + + // looking up and no roof over head + local _position = eyePos _unit; + positionCameraToWorld [0, 0, 1] select 2 < (positionCameraToWorld [0, 0, 0] select 2) - 0.4 || {(lineIntersects [_position, _position vectorAdd [0, 0, 15], _unit])} // return +}; + +if (!isNull findDisplay 312) exitWith { + if (GVAR(RainActive)) then { + call FUNC(removeRainEffect); + }; +}; + +// Ignore if unit is under water +if !(GVAR(EffectsActive) || {underwater _unit}) exitWith { + call FUNC(RemoveRainEffect); +}; + +if (GVAR(RainLastLevel) != rain) then { + call FUNC(RemoveRainEffect); + + GVAR(RainLastLevel) = rain; + + // Rain is happening + if (GVAR(RainLastLevel) > 0.05 && {!([_unit] call _fnc_underCover)}) then { + GVAR(RainActive) = true; + GVAR(RainDrops) = "#particlesource" createVehicleLocal position _unit; + GVAR(RainDrops) setParticleClass "ACERainEffect"; + GVAR(RainDrops) setDropInterval (0.07 * (1.1 - GVAR(RainLastLevel))); + GVAR(RainDrops) attachTo [vehicle _unit, [0,0,0]]; + }; +} else { + if (GVAR(RainLastLevel) > 0.05) then { + if (GVAR(RainActive) && {[_unit] call _fnc_underCover}) exitWith { + call FUNC(RemoveRainEffect); + }; + + if !(GVAR(RainActive)) then { + GVAR(RainLastLevel) = -1; + }; + }; +}; diff --git a/addons/goggles/functions/fnc_checkGoggles.sqf b/addons/goggles/functions/fnc_checkGoggles.sqf index 0587469f02..84b86c3da4 100644 --- a/addons/goggles/functions/fnc_checkGoggles.sqf +++ b/addons/goggles/functions/fnc_checkGoggles.sqf @@ -35,7 +35,7 @@ if (true) then { }; }; if !(GVAR(EffectsActive)) then { - [goggles ace_player] call FUNC(applyGlasses); + [goggles ace_player] call FUNC(applyGlassesEffect); } else { if ([goggles ace_player] call FUNC(isDivingGoggles) && {underwater ace_player}) then { call FUNC(removeRainEffect); diff --git a/addons/goggles/functions/fnc_dustHandler.sqf b/addons/goggles/functions/fnc_dustHandler.sqf index 2f23f69afb..90260d07b3 100644 --- a/addons/goggles/functions/fnc_dustHandler.sqf +++ b/addons/goggles/functions/fnc_dustHandler.sqf @@ -81,7 +81,7 @@ if (GETDUSTT(DAMOUNT) < 2) then { if (_bullets > _bulletsRequired) then { SETDUST(DACTIVE,true); - call FUNC(applyDust); + call FUNC(applyDustEffect); }; }; diff --git a/addons/goggles/functions/fnc_onEachFrame.sqf b/addons/goggles/functions/fnc_onEachFrame.sqf index 85692a0f57..b3494d1290 100644 --- a/addons/goggles/functions/fnc_onEachFrame.sqf +++ b/addons/goggles/functions/fnc_onEachFrame.sqf @@ -46,10 +46,10 @@ if !(_safe) then { if (GETDUSTT(DAMOUNT) < 2) then { if (!GETDUSTT(DACTIVE)) then { SETDUST(DACTIVE,true); - call FUNC(ApplyDust); + call FUNC(applyDustEffect); } else { if ((_rotorWash select 1) > 0.5) then { - call FUNC(ApplyDust); + call FUNC(applyDustEffect); }; }; }; diff --git a/addons/goggles/functions/fnc_rainEffect.sqf b/addons/goggles/functions/fnc_rainEffect.sqf deleted file mode 100644 index 6f351f4002..0000000000 --- a/addons/goggles/functions/fnc_rainEffect.sqf +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet - * Handles rain effects being created on glasses. - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * call ace_goggles_fnc_rainEffect; - * - * Public: No - */ -#include "script_component.hpp" -private ["_fnc_underCover"]; -if (isNull(ace_player) || {!(alive ace_player)}) exitWith {}; -_fnc_underCover = { - private ["_pos", "_unit"]; - _unit = (_this select 0); - if (vehicle _unit != _unit && {!isTurnedOut _unit}) exitWith {true}; - _pos = eyePos _unit; - ((positionCameraToWorld [0,0,1] select 2) < ((positionCameraToWorld [0,0,0] select 2) - 0.4)) || {(lineIntersects [_pos, _pos vectorAdd [0,0,15], _unit])} -}; -if (!isNull(findDisplay 312)) exitWith { - if (GVAR(RainActive)) then { - call FUNC(RemoveRainEffect); - }; -}; -// Ignore if ace_player is under water -if (!GVAR(EffectsActive) || {underwater ace_player}) exitWith{call FUNC(RemoveRainEffect);}; -if (GVAR(RainLastLevel) != rain) then { - call FUNC(RemoveRainEffect); - GVAR(RainLastLevel) = rain; - // Rain is happening - if (GVAR(RainLastLevel) > 0.05 && {!([ace_player] call _fnc_underCover)}) then { - GVAR(RainActive) = true; - GVAR(RainDrops) = "#particlesource" createVehicleLocal GetPos ace_player; - GVAR(RainDrops) setParticleClass "ACERainEffect"; - GVAR(RainDrops) setDropInterval (0.07 * (1.1 - GVAR(RainLastLevel))); - GVAR(RainDrops) attachTo [vehicle ace_player,[0,0,0]]; - }; -}else{ - if (GVAR(RainLastLevel) > 0.05) then { - if (GVAR(RainActive) && {[ace_player] call _fnc_underCover}) exitWith { - call FUNC(RemoveRainEffect); - }; - if (!GVAR(RainActive)) then { - GVAR(RainLastLevel) = -1; - }; - }; -}; From b7ce315240e9fda2be08130baf1e6b745977964d Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 29 Sep 2015 21:28:57 +0200 Subject: [PATCH 07/12] more goggles code cleanup --- addons/goggles/XEH_preInit.sqf | 12 +++++++----- addons/goggles/functions/fnc_clearGlasses.sqf | 16 ++++++++++------ .../goggles/functions/fnc_removeDirtEffect.sqf | 5 +++-- .../goggles/functions/fnc_removeDustEffect.sqf | 5 +++-- .../functions/fnc_removeGlassesEffect.sqf | 8 ++++---- .../goggles/functions/fnc_removeRainEffect.sqf | 8 +++++--- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/addons/goggles/XEH_preInit.sqf b/addons/goggles/XEH_preInit.sqf index be54cf73e6..bb96add89d 100644 --- a/addons/goggles/XEH_preInit.sqf +++ b/addons/goggles/XEH_preInit.sqf @@ -12,12 +12,16 @@ PREP(removeDustEffect); PREP(removeGlassesEffect); PREP(removeRainEffect); -// general +// public PREP(externalCamera); PREP(isDivingGoggles); PREP(isGogglesVisible); -PREP(isInRotorWash); + +// general +PREP(clearGlasses); +PREP(dustHandler); PREP(getExplosionIndex); +PREP(isInRotorWash); // eventhandlers PREP(handleExplosion); @@ -27,10 +31,8 @@ PREP(handleKilled); PREP(checkGoggles); -PREP(clearGlasses); -PREP(dustHandler); - PREP(onEachFrame); + ADDON = true; diff --git a/addons/goggles/functions/fnc_clearGlasses.sqf b/addons/goggles/functions/fnc_clearGlasses.sqf index 7fcb05a511..d0b14e4f90 100644 --- a/addons/goggles/functions/fnc_clearGlasses.sqf +++ b/addons/goggles/functions/fnc_clearGlasses.sqf @@ -10,27 +10,31 @@ * None * * Example: - * call ace_goggles_fnc_ClearGlasses; + * call ace_goggles_fnc_clearGlasses * * Public: Yes */ #include "script_component.hpp" -private ["_broken", "_effects"]; +private ["_unit", "_broken", "_effects"]; + +_unit = ACE_player; _broken = GETBROKEN; _effects = GLASSESDEFAULT; _effects set [BROKEN, _broken]; -SETGLASSES(ace_player,_effects); -if ((stance ace_player) != "PRONE") then { - ace_player playActionNow "gestureWipeFace"; +SETGLASSES(_unit,_effects); + +if (stance _unit != "PRONE") then { + _unit playActionNow "gestureWipeFace"; }; + [{ if (cameraView == "INTERNAL") then { addCamShake [5, 1.75, 2]; }; -}, [], 0.3, 0] call EFUNC(common,waitAndExecute); +}, [], 0.3] call EFUNC(common,waitAndExecute); call FUNC(removeDirtEffect); call FUNC(removeRainEffect); diff --git a/addons/goggles/functions/fnc_removeDirtEffect.sqf b/addons/goggles/functions/fnc_removeDirtEffect.sqf index f7efd39af3..a6d5a232cc 100644 --- a/addons/goggles/functions/fnc_removeDirtEffect.sqf +++ b/addons/goggles/functions/fnc_removeDirtEffect.sqf @@ -9,11 +9,12 @@ * None * * Example: - * call ace_goggles_fnc_removeDirtEffect; + * call ace_goggles_fnc_removeDirtEffect * * Public: Yes */ #include "script_component.hpp" -if (!isNull(GETUVAR(GVAR(DisplayEffects),displayNull))) then { + +if (!isNull (GETUVAR(GVAR(DisplayEffects),displayNull))) then { (GETUVAR(GVAR(DisplayEffects),displayNull) displayCtrl 10660) ctrlSetText ""; }; diff --git a/addons/goggles/functions/fnc_removeDustEffect.sqf b/addons/goggles/functions/fnc_removeDustEffect.sqf index 1e179ed6b4..a04121e8ba 100644 --- a/addons/goggles/functions/fnc_removeDustEffect.sqf +++ b/addons/goggles/functions/fnc_removeDustEffect.sqf @@ -9,11 +9,12 @@ * None * * Example: - * call ace_goggles_fnc_removeDustEffect; + * call ace_goggles_fnc_removeDustEffect * * Public: Yes */ #include "script_component.hpp" -if (!isNull(GETUVAR(GVAR(DisplayEffects),displayNull))) then { + +if (!isNull (GETUVAR(GVAR(DisplayEffects),displayNull))) then { (GETUVAR(GVAR(DisplayEffects),displayNull) displayCtrl 10662) ctrlSetText ""; }; diff --git a/addons/goggles/functions/fnc_removeGlassesEffect.sqf b/addons/goggles/functions/fnc_removeGlassesEffect.sqf index c7965fefbc..658daf1d32 100644 --- a/addons/goggles/functions/fnc_removeGlassesEffect.sqf +++ b/addons/goggles/functions/fnc_removeGlassesEffect.sqf @@ -1,7 +1,6 @@ /* * Author: Garth 'L-H' de Wet - * Removes the glasses effect from the screen, removes dirt effect, removes rain effect, - * removes dust effect. Does not reset array (glasses will still be broken, dirty, ect.) + * Removes the glasses effect from the screen, removes dirt effect, removes rain effect, removes dust effect. Does not reset array (glasses will still be broken, dirty, ect.) * * Arguments: * None @@ -10,15 +9,16 @@ * None * * Example: - * call ace_goggles_fnc_removeGlassesEffect; + * call ace_goggles_fnc_removeGlassesEffect * * Public: Yes */ #include "script_component.hpp" + GVAR(EffectsActive) = false; GVAR(PostProcess) ppEffectEnable false; -if (!isNull(GLASSDISPLAY)) then { +if (!isNull (GLASSDISPLAY)) then { GLASSDISPLAY closeDisplay 0; }; diff --git a/addons/goggles/functions/fnc_removeRainEffect.sqf b/addons/goggles/functions/fnc_removeRainEffect.sqf index 0d322e12da..fb7f3e5e2e 100644 --- a/addons/goggles/functions/fnc_removeRainEffect.sqf +++ b/addons/goggles/functions/fnc_removeRainEffect.sqf @@ -9,13 +9,15 @@ * None * * Example: - * call ace_goggles_fnc_removeRainEffect; + * call ace_goggles_fnc_removeRainEffect * * Public: Yes */ #include "script_component.hpp" -if (!isNull (GVAR(RainDrops))) then { - deleteVehicle (GVAR(RainDrops)); + +if (!isNull GVAR(RainDrops)) then { + deleteVehicle GVAR(RainDrops); }; + GVAR(RainActive) = false; GVAR(RainLastLevel) = 0; From 62349f685c37bdfdb29e8cf5c2af678b079b91f0 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 29 Sep 2015 22:01:40 +0200 Subject: [PATCH 08/12] more goggles code cleanup --- addons/goggles/XEH_postInit.sqf | 123 ++++++++---------- .../goggles/functions/fnc_applyDirtEffect.sqf | 2 +- .../goggles/functions/fnc_applyDustEffect.sqf | 2 +- .../functions/fnc_applyGlassesEffect.sqf | 2 +- addons/goggles/functions/fnc_checkGoggles.sqf | 2 +- .../goggles/functions/fnc_handleExplosion.sqf | 19 +++ addons/goggles/functions/fnc_handleFired.sqf | 2 + addons/goggles/functions/fnc_handleKilled.sqf | 13 ++ addons/goggles/functions/fnc_onEachFrame.sqf | 2 +- 9 files changed, 94 insertions(+), 73 deletions(-) diff --git a/addons/goggles/XEH_postInit.sqf b/addons/goggles/XEH_postInit.sqf index 2d78e6f372..5a3c2c875b 100644 --- a/addons/goggles/XEH_postInit.sqf +++ b/addons/goggles/XEH_postInit.sqf @@ -12,22 +12,25 @@ if (!hasInterface) exitWith {}; {false}, [20, [true, true, false]], false] call CBA_fnc_addKeybind; +// make sure to stack effect layers in correct order +QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer; +QGVAR(GogglesLayer) call BIS_fnc_RSCLayer; - - - - -if isNil(QGVAR(UsePP)) then { +if (isNil QGVAR(UsePP)) then { GVAR(UsePP) = true; }; -GVAR(PostProcess) = ppEffectCreate ["ColorCorrections", 1995]; +// init pp effects +GVAR(PostProcess) = ppEffectCreate ["ColorCorrections", 1995]; GVAR(PostProcessEyes) = ppEffectCreate ["ColorCorrections", 1992]; -GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [0,0,0,1],[1,1,1,0]]; +GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [0, 0, 0, 1], [1, 1, 1, 0]]; GVAR(PostProcessEyes) ppEffectCommit 0; GVAR(PostProcessEyes) ppEffectEnable false; + GVAR(EffectsActive) = false; + SETGLASSES(ace_player,GLASSESDEFAULT); + GVAR(Current) = "None"; GVAR(EyesDamageScript) = -1; GVAR(FrameEvent) = [false, [false,20]]; @@ -39,82 +42,66 @@ GVAR(RainLastLevel) = 0; GVAR(surfaceCache) = ""; GVAR(surfaceCacheIsDust) = false; -FUNC(CheckGlasses) = { - if (GVAR(Current) != (goggles ace_player)) then { - GVAR(Current) = (goggles ace_player); - ["GlassesChanged",[GVAR(Current)]] call EFUNC(common,localEvent); - }; -}; -player addEventHandler ["Explosion", { - private "_effects"; - if (alive ace_player) then { - call FUNC(applyDirtEffect); - if (GETBROKEN) exitWith {}; - if (((_this select 1) call FUNC(GetExplosionIndex)) < getNumber(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_Resistance")) exitWith {}; - if !([ace_player] call FUNC(isGogglesVisible)) exitWith {["GlassesCracked",[ace_player]] call EFUNC(common,localEvent);}; - _effects = GETGLASSES(ace_player); - _effects set [BROKEN, true]; - SETGLASSES(ace_player,_effects); - if (getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_OverlayCracked") != "" && {cameraOn == ace_player}) then { - if (call FUNC(ExternalCamera)) exitWith {}; - if (isNull(GLASSDISPLAY)) then { - 150 cutRsc["RscACE_Goggles", "PLAIN",1, false]; - }; - (GLASSDISPLAY displayCtrl 10650) ctrlSetText getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_OverlayCracked"); - }; - ["GlassesCracked",[ace_player]] call EFUNC(common,localEvent); - }; -}]; -player addEventHandler ["Killed",{ - GVAR(PostProcessEyes) ppEffectEnable false; - SETGLASSES(ace_player,GLASSESDEFAULT); - call FUNC(removeGlassesEffect); - GVAR(EffectsActive)=false; - ace_player setVariable ["ACE_EyesDamaged", false]; - if (GVAR(EyesDamageScript) != -1) then { - [GVAR(EyesDamageScript)] call CALLSTACK(cba_fnc_removePreFrameHandler); - }; - if (GVAR(DustHandler) != -1) then { - [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); - GVAR(DustHandler) = -1; - }; -}]; -player addEventHandler ["Fired",{[_this select 0, _this select 1] call FUNC(dustHandler);}]; -player AddEventHandler ["Take",{call FUNC(checkGlasses);}]; -player AddEventHandler ["Put", {call FUNC(checkGlasses);}]; +// init GlassesChanged eventhandler +GVAR(OldGlasses) = "#NULLSTRING"; -["GlassesChanged",{ - SETGLASSES(ace_player,GLASSESDEFAULT); +["playerInventoryChanged", { + (_this select 1) params ["", "_currentGlasses"]; + + if (GVAR(OldGlasses) != _currentGlasses) then { + ["GlassesChanged", [ACE_player, _currentGlasses]] call EFUNC(common,localEvent); + GVAR(OldGlasses) = _currentGlasses; + }; +}] call EFUNC(common,addEventHandler); + +// add glasses eventhandlers +["GlassesChanged", { + params ["_unit", "_glasses"]; + + SETGLASSES(_unit,GLASSESDEFAULT); if (call FUNC(ExternalCamera)) exitWith {call FUNC(RemoveGlassesEffect)}; - if ([ace_player] call FUNC(isGogglesVisible)) then { - [_this select 0] call FUNC(applyGlassesEffect); + if ([_unit] call FUNC(isGogglesVisible)) then { + _glasses call FUNC(applyGlassesEffect); } else { call FUNC(removeGlassesEffect); }; }] call EFUNC(common,addEventHandler); -["GlassesCracked",{ - if (_this select 0 != ace_player) exitWith {}; - ace_player setVariable ["ACE_EyesDamaged", true]; - if (GVAR(EyesDamageScript) != -1) then { - [GVAR(EyesDamageScript)] call CALLSTACK(cba_fnc_removePreFrameHandler); - }; - GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [0.5,0.5,0.5,0.5],[1,1,1,0]]; + +["GlassesCracked", { + params ["_unit"]; + + _unit setVariable ["ACE_EyesDamaged", true]; + + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [0.5, 0.5, 0.5, 0.5], [1, 1, 1, 0]]; GVAR(PostProcessEyes) ppEffectCommit 0; GVAR(PostProcessEyes) ppEffectEnable true; - GVAR(EyesDamageScript) = [{ - GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [1,1,1,1],[1,1,1,0]]; + + [{ + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 1, 0]]; GVAR(PostProcessEyes) ppEffectCommit 5; + GVAR(EyesDamageScript) = [{ + params ["_unit"]; + GVAR(PostProcessEyes) ppEffectEnable false; - ace_player setVariable ["ACE_EyesDamaged", false]; - GVAR(EyesDamageScript) = -1; - }, [], 5, 1] call EFUNC(common,waitAndExecute); - }, [], 25, 5] call EFUNC(common,waitAndExecute); + + _unit setVariable ["ACE_EyesDamaged", false]; + + }, _this, 5] call EFUNC(common,waitAndExecute); + + }, _unit, 25] call EFUNC(common,waitAndExecute); + }] call EFUNC(common,addEventHandler); -call FUNC(checkGlasses); + + + + + + + [FUNC(CheckGoggles), 1, []] call CBA_fnc_addPerFrameHandler; [FUNC(applyRainEffect), 0.5, []] call CBA_fnc_addPerFrameHandler; [FUNC(onEachFrame), 0, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/goggles/functions/fnc_applyDirtEffect.sqf b/addons/goggles/functions/fnc_applyDirtEffect.sqf index b8aedd5e64..655fec2f59 100644 --- a/addons/goggles/functions/fnc_applyDirtEffect.sqf +++ b/addons/goggles/functions/fnc_applyDirtEffect.sqf @@ -31,7 +31,7 @@ if ([_unit] call FUNC(isGogglesVisible)) then { local _dirtImage = getText (configFile >> "CfgGlasses" >> goggles _unit >> "ACE_OverlayDirt"); if (_dirtImage != "") then { - (QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 0.1, false]; // @todo init as 100 + (QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 0.1, false]; (GETUVAR(GVAR(DisplayEffects),displayNull) displayCtrl 10660) ctrlSetText _dirtImage; }; }; diff --git a/addons/goggles/functions/fnc_applyDustEffect.sqf b/addons/goggles/functions/fnc_applyDustEffect.sqf index 6e89a8df6b..f281af8c3e 100644 --- a/addons/goggles/functions/fnc_applyDustEffect.sqf +++ b/addons/goggles/functions/fnc_applyDustEffect.sqf @@ -25,7 +25,7 @@ _unit = ACE_player; if ([_unit] call FUNC(isGogglesVisible)) exitWith { (QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 2, false]; - ((GETUVAR(GVAR(DisplayEffects),displayNull)) displayCtrl 10662) ctrlSetText format [getText (configFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_DustPath"), GETDUSTT(DAMOUNT) + 1]; + ((GETUVAR(GVAR(DisplayEffects),displayNull)) displayCtrl 10662) ctrlSetText format [getText (configFile >> "CfgGlasses" >> goggles _unit >> "ACE_DustPath"), GETDUSTT(DAMOUNT) + 1]; SETDUST(DAMOUNT,CLAMP(GETDUSTT(DAMOUNT) + 1,0,1)); SETDUST(DBULLETS,0); diff --git a/addons/goggles/functions/fnc_applyGlassesEffect.sqf b/addons/goggles/functions/fnc_applyGlassesEffect.sqf index a8ccf23633..aa0ecea6af 100644 --- a/addons/goggles/functions/fnc_applyGlassesEffect.sqf +++ b/addons/goggles/functions/fnc_applyGlassesEffect.sqf @@ -42,7 +42,7 @@ if (_postProcessTintAmount != 0 && {GVAR(UsePP)}) then { _imagePath = getText (_config >> ["ACE_Overlay", "ACE_OverlayCracked"] select GETBROKEN); if (_imagePath != "") then { - (QGVAR(GogglesLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_Goggles", "PLAIN", 1, false]; // @todo init as 150 + (QGVAR(GogglesLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_Goggles", "PLAIN", 1, false]; (GLASSDISPLAY displayCtrl 10650) ctrlSetText _imagePath; }; diff --git a/addons/goggles/functions/fnc_checkGoggles.sqf b/addons/goggles/functions/fnc_checkGoggles.sqf index 84b86c3da4..2d10515fc6 100644 --- a/addons/goggles/functions/fnc_checkGoggles.sqf +++ b/addons/goggles/functions/fnc_checkGoggles.sqf @@ -23,7 +23,7 @@ if (true) then { call FUNC(removeGlassesEffect); }; }; - call FUNC(checkGlasses); + //call FUNC(checkGlasses); if !([ace_player] call FUNC(isGogglesVisible)) exitWith { if (GVAR(EffectsActive)) then { call FUNC(removeGlassesEffect); diff --git a/addons/goggles/functions/fnc_handleExplosion.sqf b/addons/goggles/functions/fnc_handleExplosion.sqf index e69de29bb2..a47b2f14ba 100644 --- a/addons/goggles/functions/fnc_handleExplosion.sqf +++ b/addons/goggles/functions/fnc_handleExplosion.sqf @@ -0,0 +1,19 @@ +#include "script_component.hpp" + private "_effects"; + if (alive ace_player) then { + call FUNC(applyDirtEffect); + if (GETBROKEN) exitWith {}; + if (((_this select 1) call FUNC(GetExplosionIndex)) < getNumber(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_Resistance")) exitWith {}; + if !([ace_player] call FUNC(isGogglesVisible)) exitWith {["GlassesCracked",[ace_player]] call EFUNC(common,localEvent);}; + _effects = GETGLASSES(ace_player); + _effects set [BROKEN, true]; + SETGLASSES(ace_player,_effects); + if (getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_OverlayCracked") != "" && {cameraOn == ace_player}) then { + if (call FUNC(ExternalCamera)) exitWith {}; + if (isNull(GLASSDISPLAY)) then { + 150 cutRsc["RscACE_Goggles", "PLAIN",1, false]; + }; + (GLASSDISPLAY displayCtrl 10650) ctrlSetText getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_OverlayCracked"); + }; + ["GlassesCracked",[ace_player]] call EFUNC(common,localEvent); + }; \ No newline at end of file diff --git a/addons/goggles/functions/fnc_handleFired.sqf b/addons/goggles/functions/fnc_handleFired.sqf index e69de29bb2..521418bea4 100644 --- a/addons/goggles/functions/fnc_handleFired.sqf +++ b/addons/goggles/functions/fnc_handleFired.sqf @@ -0,0 +1,2 @@ +#include "script_component.hpp" +[_this select 0, _this select 1] call FUNC(dustHandler); \ No newline at end of file diff --git a/addons/goggles/functions/fnc_handleKilled.sqf b/addons/goggles/functions/fnc_handleKilled.sqf index e69de29bb2..55dd926387 100644 --- a/addons/goggles/functions/fnc_handleKilled.sqf +++ b/addons/goggles/functions/fnc_handleKilled.sqf @@ -0,0 +1,13 @@ +#include "script_component.hpp" + GVAR(PostProcessEyes) ppEffectEnable false; + SETGLASSES(ace_player,GLASSESDEFAULT); + call FUNC(removeGlassesEffect); + GVAR(EffectsActive)=false; + ace_player setVariable ["ACE_EyesDamaged", false]; + if (GVAR(EyesDamageScript) != -1) then { + [GVAR(EyesDamageScript)] call CALLSTACK(cba_fnc_removePreFrameHandler); + }; + if (GVAR(DustHandler) != -1) then { + [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); + GVAR(DustHandler) = -1; + }; \ No newline at end of file diff --git a/addons/goggles/functions/fnc_onEachFrame.sqf b/addons/goggles/functions/fnc_onEachFrame.sqf index b3494d1290..d9181373a1 100644 --- a/addons/goggles/functions/fnc_onEachFrame.sqf +++ b/addons/goggles/functions/fnc_onEachFrame.sqf @@ -53,7 +53,7 @@ if !(_safe) then { }; }; }; - _safe = (getNumber (ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_Protection") == 1); + _safe = (getNumber (ConfigFile >> "CfgGlasses" >> goggles ace_player >> "ACE_Protection") == 1); }; if (_safe) exitWith {}; if ((_rotorWash select 1) <= 15) then { From 8d5ce1dbe248ebca64544b1643afc56db47d91db Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 29 Sep 2015 22:24:25 +0200 Subject: [PATCH 09/12] more goggles code cleanup --- addons/goggles/XEH_postInit.sqf | 4 +- addons/goggles/XEH_preInit.sqf | 3 +- .../goggles/functions/fnc_applyDirtEffect.sqf | 2 +- .../goggles/functions/fnc_applyDustEffect.sqf | 4 +- .../functions/fnc_applyGlassesEffect.sqf | 2 +- addons/goggles/functions/fnc_dustHandler.sqf | 88 ------------------- .../goggles/functions/fnc_handleExplosion.sqf | 68 ++++++++++---- addons/goggles/functions/fnc_handleFired.sqf | 88 ++++++++++++++++++- addons/goggles/functions/fnc_handleKilled.sqf | 43 ++++++--- 9 files changed, 175 insertions(+), 127 deletions(-) delete mode 100644 addons/goggles/functions/fnc_dustHandler.sqf diff --git a/addons/goggles/XEH_postInit.sqf b/addons/goggles/XEH_postInit.sqf index 5a3c2c875b..cc25c259e9 100644 --- a/addons/goggles/XEH_postInit.sqf +++ b/addons/goggles/XEH_postInit.sqf @@ -13,8 +13,8 @@ if (!hasInterface) exitWith {}; [20, [true, true, false]], false] call CBA_fnc_addKeybind; // make sure to stack effect layers in correct order -QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer; -QGVAR(GogglesLayer) call BIS_fnc_RSCLayer; +GVAR(GogglesEffectsLayer) = QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer; +GVAR(GogglesLayer) = QGVAR(GogglesLayer) call BIS_fnc_RSCLayer; if (isNil QGVAR(UsePP)) then { GVAR(UsePP) = true; diff --git a/addons/goggles/XEH_preInit.sqf b/addons/goggles/XEH_preInit.sqf index bb96add89d..deb2aed0fc 100644 --- a/addons/goggles/XEH_preInit.sqf +++ b/addons/goggles/XEH_preInit.sqf @@ -16,12 +16,11 @@ PREP(removeRainEffect); PREP(externalCamera); PREP(isDivingGoggles); PREP(isGogglesVisible); +PREP(isInRotorWash); // general PREP(clearGlasses); -PREP(dustHandler); PREP(getExplosionIndex); -PREP(isInRotorWash); // eventhandlers PREP(handleExplosion); diff --git a/addons/goggles/functions/fnc_applyDirtEffect.sqf b/addons/goggles/functions/fnc_applyDirtEffect.sqf index 655fec2f59..b10ebc9668 100644 --- a/addons/goggles/functions/fnc_applyDirtEffect.sqf +++ b/addons/goggles/functions/fnc_applyDirtEffect.sqf @@ -31,7 +31,7 @@ if ([_unit] call FUNC(isGogglesVisible)) then { local _dirtImage = getText (configFile >> "CfgGlasses" >> goggles _unit >> "ACE_OverlayDirt"); if (_dirtImage != "") then { - (QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 0.1, false]; + GVAR(GogglesEffectsLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 0.1, false]; (GETUVAR(GVAR(DisplayEffects),displayNull) displayCtrl 10660) ctrlSetText _dirtImage; }; }; diff --git a/addons/goggles/functions/fnc_applyDustEffect.sqf b/addons/goggles/functions/fnc_applyDustEffect.sqf index f281af8c3e..558a6c674b 100644 --- a/addons/goggles/functions/fnc_applyDustEffect.sqf +++ b/addons/goggles/functions/fnc_applyDustEffect.sqf @@ -15,7 +15,7 @@ */ #include "script_component.hpp" -if (GVAR(showInThirdPerson)) exitWith {false}; +if (GVAR(showInThirdPerson)) exitWith {}; if (call FUNC(ExternalCamera)) exitWith {}; private ["_unit", "_amount"]; @@ -23,7 +23,7 @@ private ["_unit", "_amount"]; _unit = ACE_player; if ([_unit] call FUNC(isGogglesVisible)) exitWith { - (QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 2, false]; + GVAR(GogglesEffectsLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 2, false]; ((GETUVAR(GVAR(DisplayEffects),displayNull)) displayCtrl 10662) ctrlSetText format [getText (configFile >> "CfgGlasses" >> goggles _unit >> "ACE_DustPath"), GETDUSTT(DAMOUNT) + 1]; diff --git a/addons/goggles/functions/fnc_applyGlassesEffect.sqf b/addons/goggles/functions/fnc_applyGlassesEffect.sqf index aa0ecea6af..7be010ef9c 100644 --- a/addons/goggles/functions/fnc_applyGlassesEffect.sqf +++ b/addons/goggles/functions/fnc_applyGlassesEffect.sqf @@ -42,7 +42,7 @@ if (_postProcessTintAmount != 0 && {GVAR(UsePP)}) then { _imagePath = getText (_config >> ["ACE_Overlay", "ACE_OverlayCracked"] select GETBROKEN); if (_imagePath != "") then { - (QGVAR(GogglesLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_Goggles", "PLAIN", 1, false]; + GVAR(GogglesLayer) cutRsc ["RscACE_Goggles", "PLAIN", 1, false]; (GLASSDISPLAY displayCtrl 10650) ctrlSetText _imagePath; }; diff --git a/addons/goggles/functions/fnc_dustHandler.sqf b/addons/goggles/functions/fnc_dustHandler.sqf deleted file mode 100644 index 90260d07b3..0000000000 --- a/addons/goggles/functions/fnc_dustHandler.sqf +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet, commy2 - * Determines whether to place dust on the goggles, based on calibre of weapon fired and other requirements. - * - * Arguments: - * 0: Unit - * 1: Weapon - * - * Return Value: - * Function is handled? - * - * Public: No - */ -#include "script_component.hpp" - -params ["_unit", "_weapon"]; - -if (_unit != ACE_player) exitWith {true}; - -// no dust in rain -if (rain > 0.1) exitWith {true}; - -// effect only aplies when lying on the ground -if (stance _unit != "PRONE") exitWith {true}; - -private ["_position", "_particleConfig", "_cloudType", "_surface", "_bullets"]; - -// check if the unit really is on the ground and not in a building -_position = getPosATL _unit; - -if (_position select 2 > 0.2) exitWith {true}; - -// get weapon dust effect -_particleConfig = configFile >> "CfgWeapons" >> _weapon >> "GunParticles"; - -_cloudType = ""; - -if (isClass (_particleConfig >> "FirstEffect")) then { // @todo read this with custom / non-standard config classnames - _cloudType = getText (_particleConfig >> "FirstEffect" >> "effectName"); -} else { - if (isClass (_particleConfig >> "effect1")) then { - _cloudType = getText (_particleConfig >> "effect1" >> "effectName"); - }; -}; - -// quit if the weapon causes no dust effect -if (_cloudType == "") exitWith {true}; - -// get if the surface is dusty -if (surfaceIsWater _position) exitWith {true}; - -_surface = surfaceType _position select [1]; // cuts of the leading # - -if (_surface != GVAR(surfaceCache)) then { - GVAR(surfaceCache) = _surface; - GVAR(surfaceCacheIsDust) = getNumber (configFile >> "CfgSurfaces" >> _surface >> "dust") >= 0.1; -}; - -// quit if surface isn't dusty -if (!GVAR(surfaceCacheIsDust)) exitWith {true}; - -// increment dust value with type bullet -_bullets = GETDUSTT(DBULLETS); - -if (ACE_diagTime - GETDUSTT(DTIME) > 1) then { - _bullets = 0; -}; - -_bullets = _bullets + 1; - -SETDUST(DBULLETS,_bullets); -SETDUST(DTIME,ACE_diagTime); - -// apply dust effect if the amount of fired bullets is over the threshold -if (GETDUSTT(DAMOUNT) < 2) then { - local _bulletsRequired = 100; - - if (isNumber (configFile >> _cloudType >> QGVAR(BulletCount))) then { - _bulletsRequired = getNumber (configFile >> _cloudType >> QGVAR(BulletCount)); - }; - - if (_bullets > _bulletsRequired) then { - SETDUST(DACTIVE,true); - call FUNC(applyDustEffect); - }; -}; - -true diff --git a/addons/goggles/functions/fnc_handleExplosion.sqf b/addons/goggles/functions/fnc_handleExplosion.sqf index a47b2f14ba..795cdd78b1 100644 --- a/addons/goggles/functions/fnc_handleExplosion.sqf +++ b/addons/goggles/functions/fnc_handleExplosion.sqf @@ -1,19 +1,51 @@ +/* + * Author: Garth 'L-H' de Wet, commy2 + * Handles explosions. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Function is handled? + * + * Public: No + */ #include "script_component.hpp" - private "_effects"; - if (alive ace_player) then { - call FUNC(applyDirtEffect); - if (GETBROKEN) exitWith {}; - if (((_this select 1) call FUNC(GetExplosionIndex)) < getNumber(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_Resistance")) exitWith {}; - if !([ace_player] call FUNC(isGogglesVisible)) exitWith {["GlassesCracked",[ace_player]] call EFUNC(common,localEvent);}; - _effects = GETGLASSES(ace_player); - _effects set [BROKEN, true]; - SETGLASSES(ace_player,_effects); - if (getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_OverlayCracked") != "" && {cameraOn == ace_player}) then { - if (call FUNC(ExternalCamera)) exitWith {}; - if (isNull(GLASSDISPLAY)) then { - 150 cutRsc["RscACE_Goggles", "PLAIN",1, false]; - }; - (GLASSDISPLAY displayCtrl 10650) ctrlSetText getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_OverlayCracked"); - }; - ["GlassesCracked",[ace_player]] call EFUNC(common,localEvent); - }; \ No newline at end of file + +params ["_unit"]; + +if (_unit != ACE_player) exitWith {true}; + +call FUNC(applyDirtEffect); + +if (GETBROKEN) exitWith {true}; + +private ["_config", "_effects"]; + +_config = configFile >> "CfgGlasses" >> goggles _unit; + +if ((_this select 1) call FUNC(GetExplosionIndex) < getNumber (_config >> "ACE_Resistance")) exitWith {true}; + +if !([_unit] call FUNC(isGogglesVisible)) exitWith { + ["GlassesCracked", [_unit]] call EFUNC(common,localEvent); + true +}; + +_effects = GETGLASSES(_unit); +_effects set [BROKEN, true]; + +SETGLASSES(_unit,_effects); + +if (getText (_config >> "ACE_OverlayCracked") != "") then { + if (GVAR(showInThirdPerson)) exitWith {}; + if (call FUNC(ExternalCamera)) exitWith {}; + + if (isNull (GLASSDISPLAY)) then { + GVAR(GogglesLayer) cutRsc ["RscACE_Goggles", "PLAIN", 1, false]; + }; + + (GLASSDISPLAY displayCtrl 10650) ctrlSetText getText (_config >> "ACE_OverlayCracked"); +}; + +["GlassesCracked", [_unit]] call EFUNC(common,localEvent); +true diff --git a/addons/goggles/functions/fnc_handleFired.sqf b/addons/goggles/functions/fnc_handleFired.sqf index 521418bea4..90260d07b3 100644 --- a/addons/goggles/functions/fnc_handleFired.sqf +++ b/addons/goggles/functions/fnc_handleFired.sqf @@ -1,2 +1,88 @@ +/* + * Author: Garth 'L-H' de Wet, commy2 + * Determines whether to place dust on the goggles, based on calibre of weapon fired and other requirements. + * + * Arguments: + * 0: Unit + * 1: Weapon + * + * Return Value: + * Function is handled? + * + * Public: No + */ #include "script_component.hpp" -[_this select 0, _this select 1] call FUNC(dustHandler); \ No newline at end of file + +params ["_unit", "_weapon"]; + +if (_unit != ACE_player) exitWith {true}; + +// no dust in rain +if (rain > 0.1) exitWith {true}; + +// effect only aplies when lying on the ground +if (stance _unit != "PRONE") exitWith {true}; + +private ["_position", "_particleConfig", "_cloudType", "_surface", "_bullets"]; + +// check if the unit really is on the ground and not in a building +_position = getPosATL _unit; + +if (_position select 2 > 0.2) exitWith {true}; + +// get weapon dust effect +_particleConfig = configFile >> "CfgWeapons" >> _weapon >> "GunParticles"; + +_cloudType = ""; + +if (isClass (_particleConfig >> "FirstEffect")) then { // @todo read this with custom / non-standard config classnames + _cloudType = getText (_particleConfig >> "FirstEffect" >> "effectName"); +} else { + if (isClass (_particleConfig >> "effect1")) then { + _cloudType = getText (_particleConfig >> "effect1" >> "effectName"); + }; +}; + +// quit if the weapon causes no dust effect +if (_cloudType == "") exitWith {true}; + +// get if the surface is dusty +if (surfaceIsWater _position) exitWith {true}; + +_surface = surfaceType _position select [1]; // cuts of the leading # + +if (_surface != GVAR(surfaceCache)) then { + GVAR(surfaceCache) = _surface; + GVAR(surfaceCacheIsDust) = getNumber (configFile >> "CfgSurfaces" >> _surface >> "dust") >= 0.1; +}; + +// quit if surface isn't dusty +if (!GVAR(surfaceCacheIsDust)) exitWith {true}; + +// increment dust value with type bullet +_bullets = GETDUSTT(DBULLETS); + +if (ACE_diagTime - GETDUSTT(DTIME) > 1) then { + _bullets = 0; +}; + +_bullets = _bullets + 1; + +SETDUST(DBULLETS,_bullets); +SETDUST(DTIME,ACE_diagTime); + +// apply dust effect if the amount of fired bullets is over the threshold +if (GETDUSTT(DAMOUNT) < 2) then { + local _bulletsRequired = 100; + + if (isNumber (configFile >> _cloudType >> QGVAR(BulletCount))) then { + _bulletsRequired = getNumber (configFile >> _cloudType >> QGVAR(BulletCount)); + }; + + if (_bullets > _bulletsRequired) then { + SETDUST(DACTIVE,true); + call FUNC(applyDustEffect); + }; +}; + +true diff --git a/addons/goggles/functions/fnc_handleKilled.sqf b/addons/goggles/functions/fnc_handleKilled.sqf index 55dd926387..d156fb684c 100644 --- a/addons/goggles/functions/fnc_handleKilled.sqf +++ b/addons/goggles/functions/fnc_handleKilled.sqf @@ -1,13 +1,32 @@ +/* + * Author: Garth 'L-H' de Wet, commy2 + * Handles the player dying. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Function is handled? + * + * Public: No + */ #include "script_component.hpp" - GVAR(PostProcessEyes) ppEffectEnable false; - SETGLASSES(ace_player,GLASSESDEFAULT); - call FUNC(removeGlassesEffect); - GVAR(EffectsActive)=false; - ace_player setVariable ["ACE_EyesDamaged", false]; - if (GVAR(EyesDamageScript) != -1) then { - [GVAR(EyesDamageScript)] call CALLSTACK(cba_fnc_removePreFrameHandler); - }; - if (GVAR(DustHandler) != -1) then { - [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); - GVAR(DustHandler) = -1; - }; \ No newline at end of file + +params ["_unit"]; + +if (_unit != ACE_player) exitWith {true}; + +GVAR(PostProcessEyes) ppEffectEnable false; + +SETGLASSES(_unit,GLASSESDEFAULT); + +call FUNC(removeGlassesEffect); + +GVAR(EffectsActive) = false; + +_unit setVariable ["ACE_EyesDamaged", false]; + +[GVAR(DustHandler)] call CBA_fnc_removePerFrameHandler; +GVAR(DustHandler) = -1; + +true From 8bbd6b69f0064dbb4c9fdf7fb74248c4006b1dd0 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 30 Sep 2015 00:12:35 +0200 Subject: [PATCH 10/12] change function header of removeEventhandler and waitAndExecute to public: yes --- addons/common/functions/fnc_removeEventHandler.sqf | 2 +- addons/common/functions/fnc_waitAndExecute.sqf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/functions/fnc_removeEventHandler.sqf b/addons/common/functions/fnc_removeEventHandler.sqf index c869b3d0cc..0c70046706 100644 --- a/addons/common/functions/fnc_removeEventHandler.sqf +++ b/addons/common/functions/fnc_removeEventHandler.sqf @@ -9,7 +9,7 @@ * Return Value: * None * - * Public: No + * Public: Yes */ #include "script_component.hpp" diff --git a/addons/common/functions/fnc_waitAndExecute.sqf b/addons/common/functions/fnc_waitAndExecute.sqf index c8f078854b..af59e301f7 100644 --- a/addons/common/functions/fnc_waitAndExecute.sqf +++ b/addons/common/functions/fnc_waitAndExecute.sqf @@ -13,7 +13,7 @@ * Example: * [{(_this select 0) setVelocity [0,0,200];}, [player], 10] call ace_common_fnc_waitAndExecute * - * Public: No + * Public: Yes */ #include "script_component.hpp" From dc882a3c6675b4409efd89e6da529025a21385b7 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 30 Sep 2015 01:26:08 +0200 Subject: [PATCH 11/12] more goggles code cleanup --- addons/goggles/XEH_postInit.sqf | 36 ++++-- addons/goggles/XEH_preInit.sqf | 8 +- .../goggles/functions/fnc_applyDustEffect.sqf | 12 +- .../functions/fnc_applyRotorWashEffect.sqf | 108 ++++++++++++++++++ addons/goggles/functions/fnc_checkGoggles.sqf | 46 -------- addons/goggles/functions/fnc_onEachFrame.sqf | 78 ------------- 6 files changed, 146 insertions(+), 142 deletions(-) create mode 100644 addons/goggles/functions/fnc_applyRotorWashEffect.sqf delete mode 100644 addons/goggles/functions/fnc_checkGoggles.sqf delete mode 100644 addons/goggles/functions/fnc_onEachFrame.sqf diff --git a/addons/goggles/XEH_postInit.sqf b/addons/goggles/XEH_postInit.sqf index cc25c259e9..4958c8e02b 100644 --- a/addons/goggles/XEH_postInit.sqf +++ b/addons/goggles/XEH_postInit.sqf @@ -31,9 +31,8 @@ GVAR(EffectsActive) = false; SETGLASSES(ace_player,GLASSESDEFAULT); -GVAR(Current) = "None"; GVAR(EyesDamageScript) = -1; -GVAR(FrameEvent) = [false, [false,20]]; +GVAR(FrameEvent) = [false, [false, 20]]; GVAR(PostProcessEyes_Enabled) = false; GVAR(DustHandler) = -1; GVAR(RainDrops) = objNull; @@ -42,7 +41,6 @@ GVAR(RainLastLevel) = 0; GVAR(surfaceCache) = ""; GVAR(surfaceCacheIsDust) = false; - // init GlassesChanged eventhandler GVAR(OldGlasses) = "#NULLSTRING"; @@ -96,12 +94,36 @@ GVAR(OldGlasses) = "#NULLSTRING"; }] call EFUNC(common,addEventHandler); +// check goggles +local _fnc_checkGoggles = { + params ["_unit"]; + if (GVAR(EffectsActive)) then { + if (call FUNC(externalCamera) || {!([_unit] call FUNC(isGogglesVisible))}) then { + call FUNC(removeGlassesEffect); + }; + } else { + if (!(call FUNC(externalCamera)) && {[_unit] call FUNC(isGogglesVisible)}) then { + [goggles _unit] call FUNC(applyGlassesEffect); + }; + }; +}; +["cameraViewChanged", _fnc_checkGoggles] call EFUNC(common,addEventHandler); +["activeCameraChanged", _fnc_checkGoggles] call EFUNC(common,addEventHandler); +// goggles effects main PFH +[{ + // rain + call FUNC(applyRainEffect); + // auto remove effects under water + if (GVAR(EffectsActive) && {[goggles ACE_player] call FUNC(isDivingGoggles) && {underwater ACE_player}}) then { + call FUNC(removeRainEffect); + call FUNC(removeDirtEffect); + call FUNC(removeDustEffect); + }; - -[FUNC(CheckGoggles), 1, []] call CBA_fnc_addPerFrameHandler; -[FUNC(applyRainEffect), 0.5, []] call CBA_fnc_addPerFrameHandler; -[FUNC(onEachFrame), 0, []] call CBA_fnc_addPerFrameHandler; + // rotor wash effect + call FUNC(applyRotorWashEffect) +}, 0.5, _fnc_checkGoggles] call CBA_fnc_addPerFrameHandler; diff --git a/addons/goggles/XEH_preInit.sqf b/addons/goggles/XEH_preInit.sqf index deb2aed0fc..ba5fa2373e 100644 --- a/addons/goggles/XEH_preInit.sqf +++ b/addons/goggles/XEH_preInit.sqf @@ -7,6 +7,7 @@ PREP(applyDirtEffect); PREP(applyDustEffect); PREP(applyGlassesEffect); PREP(applyRainEffect); +PREP(applyRotorWashEffect); PREP(removeDirtEffect); PREP(removeDustEffect); PREP(removeGlassesEffect); @@ -27,11 +28,4 @@ PREP(handleExplosion); PREP(handleFired); PREP(handleKilled); - - -PREP(checkGoggles); -PREP(onEachFrame); - - - ADDON = true; diff --git a/addons/goggles/functions/fnc_applyDustEffect.sqf b/addons/goggles/functions/fnc_applyDustEffect.sqf index 558a6c674b..b052f3eae7 100644 --- a/addons/goggles/functions/fnc_applyDustEffect.sqf +++ b/addons/goggles/functions/fnc_applyDustEffect.sqf @@ -62,13 +62,17 @@ GVAR(DustHandler) = [{ }; if (GETDUSTT(DAMOUNT) <= 0) then { + SETDUST(DACTIVE,false); + SETDUST(DBULLETS,0); + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 1, 0]]; GVAR(PostProcessEyes) ppEffectCommit 2; - [{GVAR(PostProcessEyes) ppEffectEnable false}, [], 2] call EFUNC(common,waitAndExecute); - - SETDUST(DACTIVE,false); - SETDUST(DBULLETS,0); + [{ + if (GVAR(DustHandler) == -1) then { + GVAR(PostProcessEyes) ppEffectEnable false + }; + }, [], 2] call EFUNC(common,waitAndExecute); [GVAR(DustHandler)] call CBA_fnc_removePerFrameHandler; GVAR(DustHandler) = -1; diff --git a/addons/goggles/functions/fnc_applyRotorWashEffect.sqf b/addons/goggles/functions/fnc_applyRotorWashEffect.sqf new file mode 100644 index 0000000000..7dc088bc4e --- /dev/null +++ b/addons/goggles/functions/fnc_applyRotorWashEffect.sqf @@ -0,0 +1,108 @@ +/* + * Author: Garth 'L-H' de Wet, commy2 + * Handles the rotor wash effects. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * call ace_goggles_fnc_applyRotorWashEffect; + * + * Public: No + */ +#include "script_component.hpp" + +private ["_unit", "_fnc_underCover"]; + +_unit = ACE_player; + +if (!alive _unit) exitWith {}; + +// idk. chaching magic? ends with isInRotorWash check. +GVAR(FrameEvent) set [0, !(GVAR(FrameEvent) select 0)]; + +if (GVAR(FrameEvent) select 0) exitWith { + if (vehicle _unit != _unit && {!isTurnedOut _unit}) exitWith { + (GVAR(FrameEvent) select 1) set [0, false]; + }; + + GVAR(FrameEvent) set [1, ([_unit] call FUNC(isInRotorWash))]; +}; + +// check if the unit is affected by rotor wash +private ["_rotorWash", "_safe"]; + +_rotorWash = GVAR(FrameEvent) select 1; +_safe = false; + +// no rotor wash? remove effects. +if !(_rotorWash select 0) exitWith { + if (GVAR(PostProcessEyes_Enabled)) then { + GVAR(PostProcessEyes_Enabled) = false; + + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [0, 0, 0, 1], [1, 1, 1, 0]]; + GVAR(PostProcessEyes) ppEffectCommit 2; + + [{ + if (GVAR(DustHandler) == -1) then { + GVAR(PostProcessEyes) ppEffectEnable false; + } + }, [], 2] call EFUNC(common,waitAndExecute); + + [GVAR(DustHandler)] call CBA_fnc_removePerFrameHandler; + GVAR(DustHandler) = -1; + }; +}; + +// check protection of helmet +if (headgear _unit != "") then { + _safe = getNumber (configFile >> "CfgWeapons" >> headgear _unit >> "ACE_Protection") == 1; +}; + +// check protection of goggles +if !(_safe) then { + if !([_unit] call FUNC(isGogglesVisible)) exitWith {}; + + if (GETDUSTT(DAMOUNT) < 2) then { + if !(GETDUSTT(DACTIVE)) then { + SETDUST(DACTIVE,true); + + call FUNC(applyDustEffect); + } else { + if (_rotorWash select 1 > 0.5) then { + call FUNC(applyDustEffect); + }; + }; + }; + + _safe = getNumber (ConfigFile >> "CfgGlasses" >> goggles _unit >> "ACE_Protection") == 1; +}; + +// quit if protected by goggles or helmet +if (_safe) exitWith {}; + +// apply rotor wash effect +if (_rotorWash select 1 > 0) then { + local _scale = 0.7; + + if (_rotorWash select 1 > 0) then { + _scale = CLAMP(0.3 * (_rotorWash select 1),0.1,0.3); + } else { + _scale = 0.1; + }; + + _scale = 1 - _scale; + + [GVAR(DustHandler)] call CBA_fnc_removePerFrameHandler; + GVAR(DustHandler) = -1; + + if !(_unit getVariable ["ACE_EyesDamaged", false]) then { + GVAR(PostProcessEyes_Enabled) = true; + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [_scale, _scale, _scale, _scale], [1, 1, 1, 0]]; + GVAR(PostProcessEyes) ppEffectCommit 0.5; + GVAR(PostProcessEyes) ppEffectEnable true; + }; +}; diff --git a/addons/goggles/functions/fnc_checkGoggles.sqf b/addons/goggles/functions/fnc_checkGoggles.sqf deleted file mode 100644 index 2d10515fc6..0000000000 --- a/addons/goggles/functions/fnc_checkGoggles.sqf +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet - * Performs rain checks and checks to see whether glasses effects have been applied or not. - * Checks for external camera and removes effects. - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * None - * - * Public: No - */ -#include "script_component.hpp" -if (!alive ace_player) exitWith {}; -if (true) then { - // Detect if curator interface is open and disable effects - if !(isNull curatorCamera) exitWith { - if (GVAR(EffectsActive)) then { - call FUNC(removeGlassesEffect); - }; - }; - //call FUNC(checkGlasses); - if !([ace_player] call FUNC(isGogglesVisible)) exitWith { - if (GVAR(EffectsActive)) then { - call FUNC(removeGlassesEffect); - }; - }; - if (call FUNC(externalCamera)) exitWith { - if (GVAR(EffectsActive)) then { - call FUNC(removeGlassesEffect); - }; - }; - if !(GVAR(EffectsActive)) then { - [goggles ace_player] call FUNC(applyGlassesEffect); - } else { - if ([goggles ace_player] call FUNC(isDivingGoggles) && {underwater ace_player}) then { - call FUNC(removeRainEffect); - call FUNC(removeDirtEffect); - call FUNC(removeDustEffect); - }; - }; -}; diff --git a/addons/goggles/functions/fnc_onEachFrame.sqf b/addons/goggles/functions/fnc_onEachFrame.sqf deleted file mode 100644 index d9181373a1..0000000000 --- a/addons/goggles/functions/fnc_onEachFrame.sqf +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet - * Checks whether the player is in the downwash of a helicopter and handles applying effects of that. - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * ["ACE_Goggles_RotorWash", "OnEachFrame", "call ace_goggles_fnc_OnEachFrame;"] call BIS_fnc_addStackedEventHandler; - * - * Public: No - */ -#include "script_component.hpp" -if (isNull(ace_player)) exitWith {}; -GVAR(FrameEvent) set [0, !(GVAR(FrameEvent) select 0)]; -if (GVAR(FrameEvent) select 0) exitWith { - if (vehicle ace_player != ace_player && {!isTurnedOut ACE_player}) exitWith {(GVAR(FrameEvent) select 1) set [0, false]; }; - GVAR(FrameEvent) set [1, ([ace_player] call FUNC(isInRotorWash))]; -}; -private ["_rotorWash","_safe"]; -_rotorWash = GVAR(FrameEvent) select 1; -_safe = false; -if !(_rotorWash select 0) exitWith { - if (GVAR(PostProcessEyes_Enabled)) then { - GVAR(PostProcessEyes_Enabled) = false; - if (GVAR(DustHandler) != -1) then { // should be fixed in dev CBA - [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); - GVAR(DustHandler) = -1; - }; - GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0,0,0,0], [0,0,0,1],[1,1,1,0]]; - GVAR(PostProcessEyes) ppEffectCommit 2; - GVAR(DustHandler) = [{ - GVAR(PostProcessEyes) ppEffectEnable false; - GVAR(DustHandler) = -1; - }, [], 2, 0.5] call EFUNC(common,waitAndExecute); - }; -}; -if ((headgear ace_player) != "") then { - _safe = (getNumber (ConfigFile >> "CfgWeapons" >> (headgear ace_player) >> "ACE_Protection") == 1); -}; -if !(_safe) then { - if !([ace_player] call FUNC(isGogglesVisible)) exitWith{}; - if (GETDUSTT(DAMOUNT) < 2) then { - if (!GETDUSTT(DACTIVE)) then { - SETDUST(DACTIVE,true); - call FUNC(applyDustEffect); - } else { - if ((_rotorWash select 1) > 0.5) then { - call FUNC(applyDustEffect); - }; - }; - }; - _safe = (getNumber (ConfigFile >> "CfgGlasses" >> goggles ace_player >> "ACE_Protection") == 1); -}; -if (_safe) exitWith {}; -if ((_rotorWash select 1) <= 15) then { - private "_scale"; - _scale = 0.7; - if ((_rotorWash select 1) != 0) then { - _scale = CLAMP(0.3*(_rotorWash select 1),0.1,0.3); - } else { - _scale = 0.1; - }; - _scale = 1 - _scale; - if (GVAR(DustHandler) != -1) then { // should be fixed in dev CBA - [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); - GVAR(DustHandler) = -1; - }; - if !(ace_player getVariable ["ACE_EyesDamaged", false]) then { - GVAR(PostProcessEyes_Enabled) = true; - GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0,0,0,0], [_scale,_scale,_scale,_scale],[1,1,1,0]]; - GVAR(PostProcessEyes) ppEffectCommit 0.5; - GVAR(PostProcessEyes) ppEffectEnable true; - }; -}; From 945ec7a38858a03287d0944f24ed22ff8927bdbb Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 30 Sep 2015 01:31:45 +0200 Subject: [PATCH 12/12] more goggles code cleanup --- addons/goggles/anim/model.cfg | 261 +++++++++++++++++----------------- 1 file changed, 133 insertions(+), 128 deletions(-) diff --git a/addons/goggles/anim/model.cfg b/addons/goggles/anim/model.cfg index 00ce647aa7..da614e05db 100644 --- a/addons/goggles/anim/model.cfg +++ b/addons/goggles/anim/model.cfg @@ -1,128 +1,133 @@ -class CfgSkeletons -{ - class Default - { - isDiscrete = 1; - skeletonInherit = ""; - skeletonBones[] = {}; - }; - class OFP2_ManSkeleton - { - isDiscrete = 0; - skeletonInherit = ""; - skeletonBones[] = - { - "Pelvis","", - "Spine","Pelvis", - "Spine1","Spine", - "Spine2","Spine1", - "Spine3","Spine2", - "Camera","Pelvis", - "weapon","Spine1", - "launcher","Spine1", - //Head skeleton in hierarchy - "neck","Spine3", - "neck1","neck", - "head","neck1", - //New facial features - "Face_Hub","head", - "Face_Jawbone","Face_Hub", - "Face_Jowl","Face_Jawbone", - "Face_chopRight","Face_Jawbone", - "Face_chopLeft","Face_Jawbone", - "Face_LipLowerMiddle","Face_Jawbone", - "Face_LipLowerLeft","Face_Jawbone", - "Face_LipLowerRight","Face_Jawbone", - "Face_Chin","Face_Jawbone", - "Face_Tongue","Face_Jawbone", - "Face_CornerRight","Face_Hub", - "Face_CheekSideRight","Face_CornerRight", - "Face_CornerLeft","Face_Hub", - "Face_CheekSideLeft","Face_CornerLeft", - "Face_CheekFrontRight","Face_Hub", - "Face_CheekFrontLeft","Face_Hub", - "Face_CheekUpperRight","Face_Hub", - "Face_CheekUpperLeft","Face_Hub", - "Face_LipUpperMiddle","Face_Hub", - "Face_LipUpperRight","Face_Hub", - "Face_LipUpperLeft","Face_Hub", - "Face_NostrilRight","Face_Hub", - "Face_NostrilLeft","Face_Hub", - "Face_Forehead","Face_Hub", - "Face_BrowFrontRight","Face_Forehead", - "Face_BrowFrontLeft","Face_Forehead", - "Face_BrowMiddle","Face_Forehead", - "Face_BrowSideRight","Face_Forehead", - "Face_BrowSideLeft","Face_Forehead", - "Face_Eyelids","Face_Hub", - "Face_EyelidUpperRight","Face_Hub", - "Face_EyelidUpperLeft","Face_Hub", - "Face_EyelidLowerRight","Face_Hub", - "Face_EyelidLowerLeft","Face_Hub", - "EyeLeft","Face_Hub", - "EyeRight","Face_Hub", - //Left upper side - "LeftShoulder","Spine3", - "LeftArm","LeftShoulder", - "LeftArmRoll","LeftArm", - "LeftForeArm","LeftArmRoll", - "LeftForeArmRoll","LeftForeArm", - "LeftHand","LeftForeArmRoll", - "LeftHandRing","LeftHand", - "LeftHandRing1","LeftHandRing", - "LeftHandRing2","LeftHandRing1", - "LeftHandRing3","LeftHandRing2", - "LeftHandPinky1","LeftHandRing", - "LeftHandPinky2","LeftHandPinky1", - "LeftHandPinky3","LeftHandPinky2", - "LeftHandMiddle1","LeftHand", - "LeftHandMiddle2","LeftHandMiddle1", - "LeftHandMiddle3","LeftHandMiddle2", - "LeftHandIndex1","LeftHand", - "LeftHandIndex2","LeftHandIndex1", - "LeftHandIndex3","LeftHandIndex2", - "LeftHandThumb1","LeftHand", - "LeftHandThumb2","LeftHandThumb1", - "LeftHandThumb3","LeftHandThumb2", - //Right upper side - "RightShoulder","Spine3", - "RightArm","RightShoulder", - "RightArmRoll","RightArm", - "RightForeArm","RightArmRoll", - "RightForeArmRoll","RightForeArm", - "RightHand","RightForeArmRoll", - "RightHandRing","RightHand", - "RightHandRing1","RightHandRing", - "RightHandRing2","RightHandRing1", - "RightHandRing3","RightHandRing2", - "RightHandPinky1","RightHandRing", - "RightHandPinky2","RightHandPinky1", - "RightHandPinky3","RightHandPinky2", - "RightHandMiddle1","RightHand", - "RightHandMiddle2","RightHandMiddle1", - "RightHandMiddle3","RightHandMiddle2", - "RightHandIndex1","RightHand", - "RightHandIndex2","RightHandIndex1", - "RightHandIndex3","RightHandIndex2", - "RightHandThumb1","RightHand", - "RightHandThumb2","RightHandThumb1", - "RightHandThumb3","RightHandThumb2", - //Left lower side - "LeftUpLeg","Pelvis", - "LeftUpLegRoll","LeftUpLeg", - "LeftLeg","LeftUpLegRoll", - "LeftLegRoll","LeftLeg", - "LeftFoot","LeftLegRoll", - "LeftToeBase","LeftFoot", - //Right lower side - "RightUpLeg","Pelvis", - "RightUpLegRoll","RightUpLeg", - "RightLeg","RightUpLegRoll", - "RightLegRoll","RightLeg", - "RightFoot","RightLegRoll", - "RightToeBase","RightFoot" - }; - // location of pivot points (local axes) for hierarchical animation - pivotsModel="A3\anims_f\data\skeleton\SkeletonPivots.p3d"; - }; -}; \ No newline at end of file + +class CfgSkeletons { + class Default { + isDiscrete = 1; + skeletonInherit = ""; + skeletonBones[] = {}; + }; + + class OFP2_ManSkeleton { + isDiscrete = 0; + skeletonInherit = ""; + skeletonBones[] = { + "Pelvis","", + "Spine","Pelvis", + "Spine1","Spine", + "Spine2","Spine1", + "Spine3","Spine2", + "Camera","Pelvis", + "weapon","Spine1", + "launcher","Spine1", + + //Head skeleton in hierarchy + "neck","Spine3", + "neck1","neck", + "head","neck1", + + //New facial features + "Face_Hub","head", + "Face_Jawbone","Face_Hub", + "Face_Jowl","Face_Jawbone", + "Face_chopRight","Face_Jawbone", + "Face_chopLeft","Face_Jawbone", + "Face_LipLowerMiddle","Face_Jawbone", + "Face_LipLowerLeft","Face_Jawbone", + "Face_LipLowerRight","Face_Jawbone", + "Face_Chin","Face_Jawbone", + "Face_Tongue","Face_Jawbone", + "Face_CornerRight","Face_Hub", + "Face_CheekSideRight","Face_CornerRight", + "Face_CornerLeft","Face_Hub", + "Face_CheekSideLeft","Face_CornerLeft", + "Face_CheekFrontRight","Face_Hub", + "Face_CheekFrontLeft","Face_Hub", + "Face_CheekUpperRight","Face_Hub", + "Face_CheekUpperLeft","Face_Hub", + "Face_LipUpperMiddle","Face_Hub", + "Face_LipUpperRight","Face_Hub", + "Face_LipUpperLeft","Face_Hub", + "Face_NostrilRight","Face_Hub", + "Face_NostrilLeft","Face_Hub", + "Face_Forehead","Face_Hub", + "Face_BrowFrontRight","Face_Forehead", + "Face_BrowFrontLeft","Face_Forehead", + "Face_BrowMiddle","Face_Forehead", + "Face_BrowSideRight","Face_Forehead", + "Face_BrowSideLeft","Face_Forehead", + "Face_Eyelids","Face_Hub", + "Face_EyelidUpperRight","Face_Hub", + "Face_EyelidUpperLeft","Face_Hub", + "Face_EyelidLowerRight","Face_Hub", + "Face_EyelidLowerLeft","Face_Hub", + "EyeLeft","Face_Hub", + "EyeRight","Face_Hub", + + //Left upper side + "LeftShoulder","Spine3", + "LeftArm","LeftShoulder", + "LeftArmRoll","LeftArm", + "LeftForeArm","LeftArmRoll", + "LeftForeArmRoll","LeftForeArm", + "LeftHand","LeftForeArmRoll", + "LeftHandRing","LeftHand", + "LeftHandRing1","LeftHandRing", + "LeftHandRing2","LeftHandRing1", + "LeftHandRing3","LeftHandRing2", + "LeftHandPinky1","LeftHandRing", + "LeftHandPinky2","LeftHandPinky1", + "LeftHandPinky3","LeftHandPinky2", + "LeftHandMiddle1","LeftHand", + "LeftHandMiddle2","LeftHandMiddle1", + "LeftHandMiddle3","LeftHandMiddle2", + "LeftHandIndex1","LeftHand", + "LeftHandIndex2","LeftHandIndex1", + "LeftHandIndex3","LeftHandIndex2", + "LeftHandThumb1","LeftHand", + "LeftHandThumb2","LeftHandThumb1", + "LeftHandThumb3","LeftHandThumb2", + + //Right upper side + "RightShoulder","Spine3", + "RightArm","RightShoulder", + "RightArmRoll","RightArm", + "RightForeArm","RightArmRoll", + "RightForeArmRoll","RightForeArm", + "RightHand","RightForeArmRoll", + "RightHandRing","RightHand", + "RightHandRing1","RightHandRing", + "RightHandRing2","RightHandRing1", + "RightHandRing3","RightHandRing2", + "RightHandPinky1","RightHandRing", + "RightHandPinky2","RightHandPinky1", + "RightHandPinky3","RightHandPinky2", + "RightHandMiddle1","RightHand", + "RightHandMiddle2","RightHandMiddle1", + "RightHandMiddle3","RightHandMiddle2", + "RightHandIndex1","RightHand", + "RightHandIndex2","RightHandIndex1", + "RightHandIndex3","RightHandIndex2", + "RightHandThumb1","RightHand", + "RightHandThumb2","RightHandThumb1", + "RightHandThumb3","RightHandThumb2", + + //Left lower side + "LeftUpLeg","Pelvis", + "LeftUpLegRoll","LeftUpLeg", + "LeftLeg","LeftUpLegRoll", + "LeftLegRoll","LeftLeg", + "LeftFoot","LeftLegRoll", + "LeftToeBase","LeftFoot", + + //Right lower side + "RightUpLeg","Pelvis", + "RightUpLegRoll","RightUpLeg", + "RightLeg","RightUpLegRoll", + "RightLegRoll","RightLeg", + "RightFoot","RightLegRoll", + "RightToeBase","RightFoot" + }; + + // location of pivot points (local axes) for hierarchical animation + pivotsModel="A3\anims_f\data\skeleton\SkeletonPivots.p3d"; + }; +};