From bd1a6d14a80ba54238ebdceaffe179df13d1afe3 Mon Sep 17 00:00:00 2001
From: jokoho48 <hoffmann.jonas@gmail.com>
Date: Sun, 9 Aug 2015 02:33:00 +0200
Subject: [PATCH] Code cleanup of Dagr module

---
 addons/dagr/XEH_postInit.sqf                |  2 +-
 addons/dagr/functions/fnc_menuInit.sqf      | 16 ++++++++--------
 addons/dagr/functions/fnc_outputData.sqf    | 13 +++++++------
 addons/dagr/functions/fnc_outputVector.sqf  | 19 +++++++++----------
 addons/dagr/functions/fnc_outputWP.sqf      | 19 ++++++++++---------
 addons/dagr/functions/fnc_toggleOverlay.sqf |  5 +++--
 6 files changed, 38 insertions(+), 36 deletions(-)

diff --git a/addons/dagr/XEH_postInit.sqf b/addons/dagr/XEH_postInit.sqf
index 39f2a7ea28..883a73d418 100644
--- a/addons/dagr/XEH_postInit.sqf
+++ b/addons/dagr/XEH_postInit.sqf
@@ -30,4 +30,4 @@ GVAR(vectorConnected) = false;
 GVAR(noVectorData) = true;
 GVAR(vectorGrid) = "00000000";
 
-["RangerfinderData", {_this call FUNC(handleRangeFinderData)}] call EFUNC(common,addEventHandler);
+["RangerfinderData", FUNC(handleRangeFinderData)] call EFUNC(common,addEventHandler);
diff --git a/addons/dagr/functions/fnc_menuInit.sqf b/addons/dagr/functions/fnc_menuInit.sqf
index 739f41df0b..e4fb341537 100644
--- a/addons/dagr/functions/fnc_menuInit.sqf
+++ b/addons/dagr/functions/fnc_menuInit.sqf
@@ -74,13 +74,13 @@ GVAR(menuRun) = true;
         GVAR(menuRun) = false;
         [_this select 1] call CBA_fnc_removePerFrameHandler;
     };
-    
+
     if (GVAR(MENU_B)) then {
         GVAR(menu) = "main";
         GVAR(selection) = 0;
         GVAR(numSelections) = 5;
     };
-    
+
     if (!GVAR(add) && !GVAR(edit)) then {
         if (GVAR(DOWN)) then {
             GVAR(selection) = (GVAR(numSelections) + GVAR(selection) + 1);
@@ -90,7 +90,7 @@ GVAR(menuRun) = true;
         };
         GVAR(selection) = if (GVAR(numSelections) > 0) then { GVAR(selection) % GVAR(numSelections) } else { 0 };
     };
-    
+
     if (GVAR(LEFT)) then {
         GVAR(pointer) = (8 + GVAR(pointer) - 1);
     };
@@ -98,7 +98,7 @@ GVAR(menuRun) = true;
         GVAR(pointer) = (8 + GVAR(pointer) + 1);
     };
     GVAR(pointer) = GVAR(pointer) % 8;
-    
+
     (__dsp displayCtrl __PSelection1) ctrlSetText "";
     (__dsp displayCtrl __PSelection2) ctrlSetText "";
     (__dsp displayCtrl __PSelection3) ctrlSetText "";
@@ -113,7 +113,7 @@ GVAR(menuRun) = true;
     (__dsp displayCtrl __Selection2) ctrlSetText "";
     (__dsp displayCtrl __Selection3) ctrlSetText "";
     (__dsp displayCtrl __Selection4) ctrlSetText "";
-    
+
     (__dsp displayCtrl __F1) ctrlSetText "";
     (__dsp displayCtrl __F2) ctrlSetText "";
     (__dsp displayCtrl __F3) ctrlSetText "";
@@ -124,7 +124,7 @@ GVAR(menuRun) = true;
     (__dsp displayCtrl __Option2) ctrlSetText "";
     (__dsp displayCtrl __Option3) ctrlSetText "";
     (__dsp displayCtrl __Option4) ctrlSetText "";
-    
+
     switch (GVAR(menu)) do {
         case "main": {
             if (GVAR(SEL)) then {
@@ -500,7 +500,7 @@ GVAR(menuRun) = true;
                         case 6: { GVAR(digit6) = (10 + GVAR(digit6) - 1) % 10 };
                         case 7: { GVAR(digit7) = (10 + GVAR(digit7) - 1) % 10 };
                         case 8: { GVAR(digit8) = (10 + GVAR(digit8) - 1) % 10 };
-                    };                        
+                    };
                 };
             };
         };
@@ -590,7 +590,7 @@ GVAR(menuRun) = true;
             };
         };
     };
-    
+
     if (!GVAR(busy)) then {
         GVAR(F3) = false;
         GVAR(F2) = false;
diff --git a/addons/dagr/functions/fnc_outputData.sqf b/addons/dagr/functions/fnc_outputData.sqf
index 9bcf244fbc..63350c71a3 100644
--- a/addons/dagr/functions/fnc_outputData.sqf
+++ b/addons/dagr/functions/fnc_outputData.sqf
@@ -31,18 +31,19 @@ if (GVAR(outputPFH) != -1) exitWith {};
 
 GVAR(outputPFH) = [{
     private["_dagrElevation", "_dagrGrid", "_dagrHeading", "_dagrSpeed", "_dagrTime", "_elevation", "_gridArray", "_speed"];
-    
+
     // Abort Condition
     if !(GVAR(run) && [ACE_player, "ACE_DAGR"] call EFUNC(common,hasItem)) exitWith {
         GVAR(outputPFH) = -1;
         135471 cutText ["", "PLAIN"];
         [_this select 1] call CBA_fnc_removePerFrameHandler;
     };
-    
+
     // GRID
     _gridArray = [(getPos ACE_player), false] call EFUNC(common,getMapGridFromPos);
-    _dagrGrid = format ["%1 %2", ((_gridArray select 0) select [0,4]), ((_gridArray select 1) select [0,4])];
-    
+    _gridArray params ["_gridArrayX","_gridArrayY"];
+    _dagrGrid = format ["%1 %2", ((_gridArrayX) select [0,4]), ((_gridArrayY) select [0,4])];
+
     // SPEED
     _speed = speed (vehicle ACE_player);
     _speed = floor (_speed * 10) / 10;
@@ -68,7 +69,7 @@ GVAR(outputPFH) = [{
     __gridControl ctrlSetText format ["%1", _dagrGrid];
     __speedControl ctrlSetText format ["%1", _dagrSpeed];
     __elevationControl ctrlSetText format ["%1", _dagrElevation];
-    __headingControl ctrlSetText (if (!GVAR(useDegrees)) then { format ["%1", _dagrHeading] } else { format ["%1 �", _dagrHeading] });
+    __headingControl ctrlSetText (if (!GVAR(useDegrees)) then { format ["%1", _dagrHeading] } else { format ["%1 �", _dagrHeading] });
     __timeControl ctrlSetText format ["%1", _dagrTime];
-    
+
 }, GVAR(updateInterval), []] call CBA_fnc_addPerFrameHandler;
diff --git a/addons/dagr/functions/fnc_outputVector.sqf b/addons/dagr/functions/fnc_outputVector.sqf
index ad9068344f..7787a7ff96 100644
--- a/addons/dagr/functions/fnc_outputVector.sqf
+++ b/addons/dagr/functions/fnc_outputVector.sqf
@@ -14,7 +14,7 @@
  */
 #include "script_component.hpp"
 
-private ["_pos", "_xGrid", "_yGrid", "_dagrGrid", "_bearing", "_dagrDist", "_dagrElevation", "_dagrTime", "_elevation", "_xCoord", "_yCoord"];
+private ["_xGrid", "_yGrid", "_dagrGrid", "_bearing", "_dagrDist", "_dagrElevation", "_dagrTime", "_elevation", "_xCoord", "_yCoord"];
 
 135471 cutRsc ["DAGR_DISPLAY", "plain down"];
 
@@ -30,15 +30,14 @@ private ["_pos", "_xGrid", "_yGrid", "_dagrGrid", "_bearing", "_dagrDist", "_dag
 __background ctrlSetText QUOTE(PATHTOF(UI\dagr_vector.paa));
 
 if (GVAR(noVectorData)) exitwith {};
-
-_pos = [GVAR(LAZPOS) select 0, GVAR(LAZPOS) select 1];
+GVAR(LAZPOS) params ["_lazPosX", "_lazPosY", "_lazPosZ"];
 
 // Incase grids go neg due to 99-00 boundry
-if (_pos select 0 < 0) then {_pos set [0, (_pos select 0) + 99999];};
-if (_pos select 1 < 0) then {_pos set [1, (_pos select 1) + 99999];};
-    
+if (_lazPosX < 0) then { _lazPosX = _lazPosX + 99999;};
+if (_lazPosY < 0) then {_lazPosY = _lazPosY + 99999;};
+
 // Find laser position
-_xGrid = toArray Str(round(_pos select 0));
+_xGrid = toArray Str(round _lazPosX);
 
 while {count _xGrid < 5} do {
     _xGrid = [48] + _xGrid;
@@ -47,7 +46,7 @@ _xGrid resize 4;
 _xGrid = toString _xGrid;
 _xGrid = parseNumber _xGrid;
 
-_yGrid = toArray Str(round(_pos select 1));
+_yGrid = toArray Str(round _lazPosY);
 while {count _yGrid < 5} do {
     _yGrid = [48] + _yGrid;
 };
@@ -72,7 +71,7 @@ _yCoord = switch true do {
 _dagrGrid = _xCoord + " " + _yCoord;
 
 // Find target elevation
-_elevation = floor ((GVAR(LAZPOS) select 2) + EGVAR(common,mapAltitude));
+_elevation = floor (_lazPosZ) + EGVAR(common,mapAltitude));
 _dagrElevation = str _elevation + "m";
 
 // Time
@@ -94,5 +93,5 @@ GVAR(vectorGrid) = _dagrGrid;
 __gridControl ctrlSetText format ["%1", _dagrGrid];
 __speedControl ctrlSetText format ["%1", _dagrDist];
 __elevationControl ctrlSetText format ["%1", _dagrElevation];
-__headingControl ctrlSetText (if (!GVAR(useDegrees)) then { format ["%1", _bearing] } else { format ["%1�", _bearing] });
+__headingControl ctrlSetText (if (!GVAR(useDegrees)) then { format ["%1", _bearing] } else { format ["%1�", _bearing] });
 __timeControl ctrlSetText format ["%1", _dagrTime];
diff --git a/addons/dagr/functions/fnc_outputWP.sqf b/addons/dagr/functions/fnc_outputWP.sqf
index 71c3e7c1a7..77bee00398 100644
--- a/addons/dagr/functions/fnc_outputWP.sqf
+++ b/addons/dagr/functions/fnc_outputWP.sqf
@@ -31,22 +31,23 @@ if (GVAR(outputPFH) != -1) exitWith {};
 
 GVAR(outputPFH) = [{
     private["_MYpos", "_WPpos", "_bearing", "_dagrDistance", "_dagrGrid", "_dagrHeading", "_distance", "_gridArray"];
-    
+
     // Abort Condition
     if !(GVAR(run) && [ACE_player, "ACE_DAGR"] call EFUNC(common,hasItem)) exitWith {
         GVAR(outputPFH) = -1;
         135471 cutText ["", "PLAIN"];
         [_this select 1] call CBA_fnc_removePerFrameHandler;
     };
-    
+
     // GRID
     _gridArray = [(getPos ACE_player), false] call EFUNC(common,getMapGridFromPos);
-    _dagrGrid = format ["%1 %2", ((_gridArray select 0) select [0,4]), ((_gridArray select 1) select [0,4])];
+    _gridArray params ["_gridArrayX","_gridArrayY"];
+    _dagrGrid = format ["%1 %2", (_gridArrayX select [0,4]), (_gridArrayY select [0,4])];
 
     // WP Grid
     _xGrid2 = floor (DAGR_WP_INFO / 10000);
     _yGrid2 = DAGR_WP_INFO - _xGrid2 * 10000;
-    
+
     _xCoord2 = switch true do {
         case (_xGrid2 >= 1000): { "" + Str(_xGrid2) };
         case (_xGrid2 >= 100): { "0" + Str(_xGrid2) };
@@ -60,7 +61,7 @@ GVAR(outputPFH) = [{
         case (_yGrid2 >= 10): { "00" + Str(_yGrid2) };
         default             { "000" + Str(_yGrid2) };
     };
-    
+
     _dagrGrid2 = _xCoord2 + " " + _yCoord2;
 
     // Distance
@@ -69,7 +70,7 @@ GVAR(outputPFH) = [{
     _distance = _MYpos distance _WPpos;
     _distance = floor (_distance * 10) / 10;
     _dagrDistance = str _distance + "m";
-    
+
     // Heading
     _dagrHeading = floor (if (GVAR(useDegrees)) then {
         direction (vehicle ACE_player)
@@ -79,12 +80,12 @@ GVAR(outputPFH) = [{
 
     // WP Heading
     _bearing = floor ((_WPpos vectorDiff _MYpos) call CBA_fnc_vectDir);
-    
+
     // Output
     __gridControl ctrlSetText format ["%1", _dagrGrid];
     __speedControl ctrlSetText format ["%1", _bearing];
     __elevationControl ctrlSetText format ["%1", _dagrGrid2];
-    __headingControl ctrlSetText (if (!GVAR(useDegrees)) then { format ["%1", _dagrHeading] } else { format ["%1�", _dagrHeading] });
+    __headingControl ctrlSetText (if (!GVAR(useDegrees)) then { format ["%1", _dagrHeading] } else { format ["%1�", _dagrHeading] });
     __timeControl ctrlSetText format ["%1", _dagrDistance];
-    
+
 }, GVAR(updateInterval), []] call CBA_fnc_addPerFrameHandler;
diff --git a/addons/dagr/functions/fnc_toggleOverlay.sqf b/addons/dagr/functions/fnc_toggleOverlay.sqf
index 1fcb87d0ff..d48a83ae51 100644
--- a/addons/dagr/functions/fnc_toggleOverlay.sqf
+++ b/addons/dagr/functions/fnc_toggleOverlay.sqf
@@ -23,11 +23,12 @@ if (GVAR(run)) then {
     };
     GVAR(hidden) = true;
     [{
-        EXPLODE_1_PVT(_this select 0,_vehicle);
+        params ["_args", "_idPFH"];
+        _args params ["_vehicle"];
         if (!GVAR(run) || (!alive ACE_player) || (vehicle ACE_player != _vehicle)) exitWith {
             GVAR(run) = false;
             135471 cutText ["", "PLAIN"];
-            [_this select 1] call CBA_fnc_removePerFrameHandler;
+            [_idPFH] call CBA_fnc_removePerFrameHandler;
         };
         if (cameraView == "GUNNER") then {
             if (!GVAR(hidden)) then {