From fb76cd730f52c2606dbd65236ffa062a3cd65e83 Mon Sep 17 00:00:00 2001
From: ulteq <ulteq@web.de>
Date: Mon, 8 Jun 2015 14:32:42 +0200
Subject: [PATCH] Proper handling of grid boundaries

---
 addons/dagr/functions/fnc_DAGR_OUTPUT_DATA.sqf  |  8 ++++----
 .../dagr/functions/fnc_DAGR_OUTPUT_VECTOR.sqf   | 17 ++++++++++-------
 addons/dagr/functions/fnc_DAGR_OUTPUT_WP.sqf    |  8 ++++----
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/addons/dagr/functions/fnc_DAGR_OUTPUT_DATA.sqf b/addons/dagr/functions/fnc_DAGR_OUTPUT_DATA.sqf
index d693c28387..197a973e17 100644
--- a/addons/dagr/functions/fnc_DAGR_OUTPUT_DATA.sqf
+++ b/addons/dagr/functions/fnc_DAGR_OUTPUT_DATA.sqf
@@ -38,6 +38,10 @@ __background ctrlSetText QUOTE(PATHTOF(UI\dagr_gps.paa));
     
     // GRID
     _pos = getPosASL ACE_player;
+    
+    // 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];};
 
     _xGrid = toArray Str(round(_pos select 0));
     while {count _xGrid < 5} do {
@@ -55,10 +59,6 @@ __background ctrlSetText QUOTE(PATHTOF(UI\dagr_gps.paa));
     _yGrid = toString _yGrid;
     _yGrid = parseNumber _yGrid;
 
-    // Incase grids go neg due to 99-00 boundry
-    if (_xgrid < 0) then {_xgrid = _xgrid + 9999;};
-    if (_ygrid < 0) then {_ygrid = _ygrid + 9999;};
-
     _xCoord = switch true do {
         case (_xGrid >= 1000): { "" + Str(_xGrid) };
         case (_xGrid >= 100): { "0" + Str(_xGrid) };
diff --git a/addons/dagr/functions/fnc_DAGR_OUTPUT_VECTOR.sqf b/addons/dagr/functions/fnc_DAGR_OUTPUT_VECTOR.sqf
index 3067857a4b..81429e554b 100644
--- a/addons/dagr/functions/fnc_DAGR_OUTPUT_VECTOR.sqf
+++ b/addons/dagr/functions/fnc_DAGR_OUTPUT_VECTOR.sqf
@@ -14,7 +14,7 @@
  */
 #include "script_component.hpp"
 
-private ["_xGrid", "_yGrid", "_dagrGrid", "_bearing", "_dagrDist", "_dagrElevation", "_dagrTime", "_elevation", "_xCoord", "_yCoord"];
+private ["_pos", "_xGrid", "_yGrid", "_dagrGrid", "_bearing", "_dagrDist", "_dagrElevation", "_dagrTime", "_elevation", "_xCoord", "_yCoord"];
 
 135471 cutRsc ["DAGR_DISPLAY", "plain down"];
 
@@ -31,8 +31,15 @@ __background ctrlSetText QUOTE(PATHTOF(UI\dagr_vector.paa));
 
 if (DAGR_NO_DISPLAY) exitwith {};
 
+_pos = [GVAR(LAZPOS) select 0, GVAR(LAZPOS) select 1];
+
+// 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];};
+    
 // Find laser position
-_xGrid = toArray Str(round(GVAR(LAZPOS) select 0));
+_xGrid = toArray Str(round(_pos select 0));
+
 while {count _xGrid < 5} do {
     _xGrid = [48] + _xGrid;
 };
@@ -40,7 +47,7 @@ _xGrid resize 4;
 _xGrid = toString _xGrid;
 _xGrid = parseNumber _xGrid;
 
-_yGrid = toArray Str(round(GVAR(LAZPOS) select 1));
+_yGrid = toArray Str(round(_pos select 1));
 while {count _yGrid < 5} do {
     _yGrid = [48] + _yGrid;
 };
@@ -48,10 +55,6 @@ _yGrid resize 4;
 _yGrid = toString _yGrid;
 _yGrid = parseNumber _yGrid;
 
-// Incase grids go neg due to 99-00 boundry
-if (_xGrid < 0) then {_xGrid = _xGrid + 9999;};
-if (_yGrid < 0) then {_yGrid = _yGrid + 9999;};
-
 _xCoord = switch true do {
     case (_xGrid >= 1000): { "" + Str(_xGrid) };
     case (_xGrid >= 100): { "0" + Str(_xGrid) };
diff --git a/addons/dagr/functions/fnc_DAGR_OUTPUT_WP.sqf b/addons/dagr/functions/fnc_DAGR_OUTPUT_WP.sqf
index a5e6c2d23c..9859fdcdc6 100644
--- a/addons/dagr/functions/fnc_DAGR_OUTPUT_WP.sqf
+++ b/addons/dagr/functions/fnc_DAGR_OUTPUT_WP.sqf
@@ -38,6 +38,10 @@ __background ctrlSetText QUOTE(PATHTOF(UI\dagr_wp.paa));
     
     // GRID
     _pos = getPosASL ACE_player;
+    
+    // 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];};
 
     _xGrid = toArray Str(round(_pos select 0));
     while {count _xGrid < 5} do {
@@ -55,10 +59,6 @@ __background ctrlSetText QUOTE(PATHTOF(UI\dagr_wp.paa));
     _yGrid = toString _yGrid;
     _yGrid = parseNumber _yGrid;
 
-    // Incase grids go neg due to 99-00 boundry
-    if (_xGrid < 0) then {_xGrid = _xGrid + 9999;};
-    if (_yGrid < 0) then {_yGrid = _yGrid + 9999;};
-
     _xCoord = switch true do {
         case (_xGrid >= 1000): { "" + Str(_xGrid) };
         case (_xGrid >= 100): { "0" + Str(_xGrid) };