2015-05-10 10:20:42 +00:00
|
|
|
/*
|
|
|
|
* Author: VKing
|
|
|
|
* Gets a 10-digit map grid for the given world position
|
|
|
|
*
|
|
|
|
* Argument:
|
2015-06-23 01:36:37 +00:00
|
|
|
* 0: Position (2D Position) <ARRAY>
|
|
|
|
* 1: Return type; false for array of easting and northing, true for single string <Bool>
|
2015-05-10 10:20:42 +00:00
|
|
|
*
|
2015-05-10 15:26:28 +00:00
|
|
|
* Return values:
|
2015-06-23 01:36:37 +00:00
|
|
|
* 0: Easting <String>
|
|
|
|
* 1: Northing <String>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [(getPos player)] call ace_map_fnc_getMapGridFromPos;
|
|
|
|
*
|
|
|
|
* Public: Yes
|
2015-05-10 10:20:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// #define DEBUG_MODE_FULL
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-05-10 10:36:44 +00:00
|
|
|
PARAMS_1(_pos);
|
2015-06-23 01:36:37 +00:00
|
|
|
DEFAULT_PARAM(1,_returnSingleString,false);
|
2015-05-10 10:20:42 +00:00
|
|
|
|
2015-06-30 16:11:53 +00:00
|
|
|
private["_count", "_easting", "_nativeGrid", "_northing"];
|
|
|
|
|
|
|
|
//Fallback, when map data is weird (letters)
|
2015-06-30 02:18:21 +00:00
|
|
|
if ((count GVAR(mapGridData)) == 0) exitWith {
|
2015-06-30 16:11:53 +00:00
|
|
|
_nativeGrid = mapGridPosition _pos;
|
2015-06-30 02:18:21 +00:00
|
|
|
if (_returnSingleString) then {
|
2015-06-30 16:11:53 +00:00
|
|
|
_nativeGrid
|
2015-06-30 02:18:21 +00:00
|
|
|
} else {
|
2015-06-30 16:11:53 +00:00
|
|
|
_count = floor ((count _nativeGrid) / 2);
|
|
|
|
[(_nativeGrid select [0, _count]), (_nativeGrid select [_count, _count])]
|
2015-06-30 02:18:21 +00:00
|
|
|
};
|
2015-05-10 10:20:42 +00:00
|
|
|
};
|
2015-06-23 01:36:37 +00:00
|
|
|
|
2015-06-30 02:18:21 +00:00
|
|
|
EXPLODE_4_PVT(GVAR(mapGridData),_offsetX,_realOffsetY,_stepXat5,_stepYat5);
|
2015-06-30 16:11:53 +00:00
|
|
|
_easting = floor (((_pos select 0) - _offsetX) / _stepXat5);
|
|
|
|
_northing = floor (((_pos select 1) - _realOffsetY) / _stepYat5);
|
2015-05-10 10:20:42 +00:00
|
|
|
|
2015-06-30 16:11:53 +00:00
|
|
|
//Attempt to handle negative east/north (e.g.: moving west of map bounds)
|
|
|
|
if (_easting > 0) then {
|
|
|
|
_easting = str _easting;
|
|
|
|
while {count _easting < 5} do {_easting = "0" + _easting;};
|
|
|
|
} else {
|
|
|
|
_easting = str abs _easting;
|
|
|
|
while {count _easting < 4} do {_easting = "0" + _easting;};
|
|
|
|
_easting = "-" + _easting;
|
|
|
|
};
|
|
|
|
if (_northing > 0) then {
|
|
|
|
_northing = str _northing;
|
|
|
|
while {count _northing < 5} do {_northing = "0" + _northing;};
|
|
|
|
} else {
|
|
|
|
_northing = str abs _northing;
|
|
|
|
while {count _northing < 4} do {_northing = "0" + _northing;};
|
|
|
|
_northing = "-" + _northing;
|
|
|
|
};
|
2015-05-10 10:20:42 +00:00
|
|
|
|
2015-06-23 01:36:37 +00:00
|
|
|
if (_returnSingleString) then {
|
2015-06-30 16:11:53 +00:00
|
|
|
_easting + _northing
|
2015-05-10 16:05:28 +00:00
|
|
|
} else {
|
2015-06-30 02:18:21 +00:00
|
|
|
[_easting, _northing]
|
2015-06-23 01:36:37 +00:00
|
|
|
};
|