Calc real X and Y offsets

This commit is contained in:
PabstMirror 2015-06-29 21:18:21 -05:00
parent d5757c090a
commit 1f7994e10f
4 changed files with 95 additions and 56 deletions

View File

@ -8,35 +8,14 @@ PREP(blueForceTrackingUpdate);
PREP(determineMapLight);
PREP(determineZoom);
PREP(getMapGridFromPos);
PREP(getMapPosFromGrid);
PREP(getMGRSdata);
PREP(moduleMap);
PREP(onDrawMap);
PREP(prepareMapGrid);
PREP(updateMapEffects);
//Prepare variables for FUNC(getMapGridFromPos):
private["_length", "_mapSize", "_northingReversed", "_offsetPadding", "_originGrid"];
_northingReversed = [] call CBA_fnc_northingReversed;
_mapsize = getNumber (ConfigFile >> "CfgWorlds" >> worldName >> "mapSize");
_originGrid = if (_northingReversed) then {
mapGridPosition [0,_mapsize,0];
} else {
mapGridPosition [0,0,0];
};
_length = (count _originGrid) / 2;
_offsetPadding = switch (_length) do {
case 1: {"0000"};
case 2: {"000"};
case 3: {"00"};
case 4: {"0"};
default {""};
};
GVAR(gridOffsetX) = parseNumber ((_originGrid select [0,_length]) + _offsetPadding);
GVAR(gridOffsetY) = parseNumber ((_originGrid select [_length,_length]) + _offsetPadding);
if (_northingReversed) then {
GVAR(gridOffsetY) = GVAR(gridOffsetY) + _mapSize;
};
[] call FUNC(prepareMapGrid);
ADDON = true;

View File

@ -22,42 +22,23 @@
PARAMS_1(_pos);
DEFAULT_PARAM(1,_returnSingleString,false);
private["_posX", "_posY"];
TRACE_2("",_pos select 0, _pos select 1);
_posX = GVAR(gridOffsetX) + floor (_pos select 0);
TRACE_1("",_posX);
_posX = str ((100000 + _posX) % 100000);
if (cba_common_mapReversed) then {
_posY = GVAR(gridOffsetY) - ceil(_pos select 1);
} else {
_posY = GVAR(gridOffsetY) + floor(_pos select 1);
if ((count GVAR(mapGridData)) == 0) exitWith {
if (_returnSingleString) then {
mapGridPosition _pos
} else {
[(mapGridPosition _pos) select [0,5], (mapGridPosition _pos) select [5,5]]
};
};
TRACE_1("",_posY);
_posY = str ((100000 + _posY) % 100000);
TRACE_2("",_posX,_posY);
EXPLODE_4_PVT(GVAR(mapGridData),_offsetX,_realOffsetY,_stepXat5,_stepYat5);
_easting = str floor (((_pos select 0) - _offsetX) / _stepXat5);
_northing = str floor (((_pos select 1) - _realOffsetY) / _stepYat5);
_posX = switch (count _posX) do {
case 1: {"0000"+_posX};
case 2: {"000"+_posX};
case 3: {"00"+_posX};
case 4: {"0"+_posX};
default {_posX};
};
_posY = switch (count _posY) do {
case 1: {"0000"+_posY};
case 2: {"000"+_posY};
case 3: {"00"+_posY};
case 4: {"0"+_posY};
default {_posY};
};
TRACE_3("",mapGridPosition _pos,_posX,_posY);
while {count _easting < 5} do {_easting = "0" + _easting;};
while {count _northing < 5} do {_northing = "0" + _northing;};
if (_returnSingleString) then {
_posX+_posY
_easting+_northing
} else {
[_posX,_posY]
[_easting, _northing]
};

View File

@ -0,0 +1,40 @@
/*
* Author: PabstMirror
* Gets position from grid cords
*
* Argument:
* 0: Grid Cords <STRING>
*
* Return values:
* 0: Position <ARRAY>
*
* Example:
* ["6900080085"] call ace_map_fnc_getMapPosFromGrid
*
* Public: Yes
*/
// #define DEBUG_MODE_FULL
#include "script_component.hpp"
PARAMS_1(_inputString);
DEFAULT_PARAM(1,_getCenterOfGrid,true);
EXPLODE_4_PVT(GVAR(mapGridData),_offsetX,_realOffsetY,_stepXat5,_stepYat5);
_countInput = count _inputString;
_countInputHalf = floor (_countInput / 2);
//Split string, ignoring middle
_xPart = _inputString select [0, _countInputHalf];
_yPart = _inputString select [(ceil (_countInput / 2)), _countInputHalf];
_xPos = ((parseNumber _xPart) * _stepXat5 * 10 ^ (5 - _countInputHalf)) + _offsetX;
_yPos = ((parseNumber _yPart) * _stepYat5 * 10 ^ (5 - _countInputHalf)) + _realOffsetY;
if (_getCenterOfGrid) then {
_xPos = _xPos + 0.5 * _stepXat5 * 10 ^ (5 - _countInputHalf);
_yPos = _yPos + 0.5 * _stepYat5 * 10 ^ (5 - _countInputHalf);
};
[_xPos, _yPos, 0];

View File

@ -0,0 +1,39 @@
#include "script_component.hpp"
//--- Extract grid values from world config (Borrowed from BIS_fnc_gridToPos)
//
_cfgGrid = configfile >> "CfgWorlds" >> worldname >> "Grid";
_offsetX = getnumber (_cfgGrid >> "offsetX");
_offsetY = getnumber (_cfgGrid >> "offsetY");
_zoomMax = 1e99;
_format = "";
_formatX = "";
_formatY = "";
_stepX = 1e10;
_stepY = 1e10;
{
_zoom = getnumber (_x >> "zoomMax");
if (_zoom < _zoomMax) then {
_zoomMax = _zoom;
_format = gettext (_x >> "format");
_formatX = gettext (_x >> "formatX");
_formatY = gettext (_x >> "formatY");
_stepX = getnumber (_x >> "stepX");
_stepY = getnumber (_x >> "stepY");
};
} foreach configproperties [_cfgGrid,"isclass _x",false];
_heightOffset = 500;
_startGrid = mapGridPosition [0, _heightOffset];
_originGrid = _startGrid;
while {_startGrid == _originGrid} do {
_heightOffset = _heightOffset + 1;
_originGrid = mapGridPosition [0, _heightOffset];
};
_realOffsetY = parseNumber (_originGrid select [(count _formatX), (count _formatY)]) * _stepY + _heightOffset - 1;
_stepXat5 = _stepX * 10 ^ ((count _formatX) - 5);
_stepYat5 = -1 * _stepY * 10 ^ ((count _formatY) - 5);
GVAR(mapGridData) = [_offsetX, _realOffsetY, _stepXat5, _stepYat5];