2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-06-30 17:26:51 +00:00
|
|
|
/*
|
|
|
|
* Author: VKing, PabstMirror
|
|
|
|
* Gets a 10-digit map grid for the given world position
|
|
|
|
*
|
2015-09-21 12:20:53 +00:00
|
|
|
* Arguments:
|
2015-06-30 17:26:51 +00:00
|
|
|
* 0: Position (2D Position) <ARRAY>
|
2015-09-21 12:20:53 +00:00
|
|
|
* 1: Return type; false for array of easting and northing, true for single string (default: false) <BOOL>
|
2015-06-30 17:26:51 +00:00
|
|
|
*
|
2015-09-21 12:20:53 +00:00
|
|
|
* Return Value:
|
2015-06-30 17:26:51 +00:00
|
|
|
* 0: Easting <String>
|
|
|
|
* 1: Northing <String>
|
|
|
|
*
|
|
|
|
* Example:
|
2015-09-21 12:20:53 +00:00
|
|
|
* [getPos player] call ace_common_fnc_getMapGridFromPos
|
2015-06-30 17:26:51 +00:00
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
2015-09-21 12:20:53 +00:00
|
|
|
params ["_pos", ["_returnSingleString", false]];
|
2015-06-30 17:26:51 +00:00
|
|
|
|
|
|
|
//Fallback, when map data is weird (letters)
|
2015-09-21 12:20:53 +00:00
|
|
|
if (GVAR(mapGridData) isEqualTo []) exitWith {
|
2015-12-12 15:48:54 +00:00
|
|
|
private _nativeGrid = mapGridPosition _pos;
|
2015-09-21 12:20:53 +00:00
|
|
|
|
2015-06-30 17:26:51 +00:00
|
|
|
if (_returnSingleString) then {
|
|
|
|
_nativeGrid
|
|
|
|
} else {
|
2015-12-12 15:48:54 +00:00
|
|
|
private _count = floor ((count _nativeGrid) / 2);
|
2015-09-21 12:20:53 +00:00
|
|
|
[_nativeGrid select [0, _count], _nativeGrid select [_count, _count]]
|
2015-06-30 17:26:51 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-09-21 12:20:53 +00:00
|
|
|
GVAR(mapGridData) params ["_offsetX", "_realOffsetY", "_stepXat5", "_stepYat5"];
|
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _easting = floor (((_pos select 0) - _offsetX) / _stepXat5);
|
|
|
|
private _northing = floor (((_pos select 1) - _realOffsetY) / _stepYat5);
|
2015-06-30 17:26:51 +00:00
|
|
|
|
|
|
|
//Attempt to handle negative east/north (e.g.: moving west of map bounds)
|
|
|
|
if (_easting > 0) then {
|
|
|
|
_easting = str _easting;
|
2015-09-21 12:20:53 +00:00
|
|
|
while {count _easting < 5} do {_easting = "0" + _easting};
|
2015-06-30 17:26:51 +00:00
|
|
|
} else {
|
|
|
|
_easting = str abs _easting;
|
2015-09-21 12:20:53 +00:00
|
|
|
while {count _easting < 4} do {_easting = "0" + _easting};
|
2015-06-30 17:26:51 +00:00
|
|
|
_easting = "-" + _easting;
|
|
|
|
};
|
2015-09-21 12:20:53 +00:00
|
|
|
|
2015-06-30 17:26:51 +00:00
|
|
|
if (_northing > 0) then {
|
|
|
|
_northing = str _northing;
|
2015-09-21 12:20:53 +00:00
|
|
|
while {count _northing < 5} do {_northing = "0" + _northing};
|
2015-06-30 17:26:51 +00:00
|
|
|
} else {
|
|
|
|
_northing = str abs _northing;
|
2015-09-21 12:20:53 +00:00
|
|
|
while {count _northing < 4} do {_northing = "0" + _northing};
|
2015-06-30 17:26:51 +00:00
|
|
|
_northing = "-" + _northing;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_returnSingleString) then {
|
|
|
|
_easting + _northing
|
|
|
|
} else {
|
|
|
|
[_easting, _northing]
|
2015-09-21 12:20:53 +00:00
|
|
|
}; // return
|