more common code cleanup

This commit is contained in:
commy2 2015-09-21 14:20:53 +02:00
parent b0f9eab1f7
commit df3211cc42
4 changed files with 94 additions and 82 deletions

View File

@ -1,13 +1,16 @@
/* /*
* Author: commy2 * Author: commy2
* * Returns all hitpoints and their selections of any vehicle. Might contain duplicates if the turrets contain non unique hitpoints with different selection names.
* Returns all hitpoints of any vehicle. Might contain duplicates if the turrets contain non unique hitpoints with different selection names.
* *
* Arguments: * Arguments:
* 0: A vehicle, not the classname (Object) * 0: Vehicle <OBJECT>
* *
* Return Value: * Return Value:
* The hitpoints (Array) * Hitpoints <ARRAY>
*
* Public: Yes
*
* Deprecated
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,13 +1,17 @@
/* /*
* Author: commy2 * Author: commy2
* * Returns all hitpoints and their respective selections of any vehicle. Might contain duplicates for non unique hitpoints in turrets.
* Returns all hitpoints and their selections of any vehicle. Might contain duplicates if the turrets contain non unique hitpoints with different selection names.
* *
* Arguments: * Arguments:
* 0: A vehicle, not the classname (Object) * 0: Vehicle <OBJECT>
* *
* Return Value: * Return Value:
* The hitpoints with selections. Format: [hitpoints, selections]. They correspond by index. (Array) * 0: Hitpoints <ARRAY>
* 1: Selections <ARRAY>
*
* Public: Yes
*
* Deprecated
*/ */
#include "script_component.hpp" #include "script_component.hpp"
@ -15,5 +19,7 @@ params ["_vehicle"];
private "_hitPointsWithSelections"; private "_hitPointsWithSelections";
_hitPointsWithSelections = getAllHitPointsDamage _vehicle; _hitPointsWithSelections = getAllHitPointsDamage _vehicle;
_hitPointsWithSelections resize 2; _hitPointsWithSelections resize 2;
_hitPointsWithSelections _hitPointsWithSelections

View File

@ -1,28 +1,28 @@
/* /*
* Author: VKing * Author: VKing
* Gets the current map's MGRS grid zone designator and 100km square. * Gets the current map's MGRS grid zone designator and 100km square.
* Also gets longitude, latitude and altitude offset for the map * Also gets longitude, latitude and altitude offset for the map.
* Writes return values to GVAR(MGRS_data) if run on the current map.
* *
* Argument: * Argument:
* 0: Optional: Map name, if undefined the current map is used (String) * 0: Map name (default: worldName) <STRING>
* *
* Return value: * Return Value:
* 0: Grid zone designator (String) * 0: Grid zone designator <STRING>
* 1: 100km square (String) * 1: 100km square <STRING>
* 2: GZD + 100km sq. as a single string (String) * 2: GZD + 100km sq. as a single string <STRING>
* Writes return values to GVAR(MGRS_data) if run on the current map *
* Public: No
*/ */
// #define DEBUG_MODE_FULL
#include "script_component.hpp" #include "script_component.hpp"
private ["_zone","_band","_GZD","_long","_lat","_UTM","_easting","_northing", "_altitude"]; params [["_map", worldName]];
DEFAULT_PARAM(0,_map,worldName); private ["_long", "_lat", "_altitude", "_UTM", "_easting", "_northing", "_zone", "_band", "_GZD"];
_long = getNumber (ConfigFile >> "CfgWorlds" >> _map >> "longitude"); _long = getNumber (configFile >> "CfgWorlds" >> _map >> "longitude");
_lat = getNumber (ConfigFile >> "CfgWorlds" >> _map >> "latitude"); _lat = getNumber (configFile >> "CfgWorlds" >> _map >> "latitude");
_altitude = getNumber (ConfigFile >> "CfgWorlds" >> _map >> "elevationOffset"); _altitude = getNumber (configFile >> "CfgWorlds" >> _map >> "elevationOffset");
if (_map in ["Chernarus", "Bootcamp_ACR", "Woodland_ACR", "utes"]) then { _lat = 50; _altitude = 0; }; if (_map in ["Chernarus", "Bootcamp_ACR", "Woodland_ACR", "utes"]) then { _lat = 50; _altitude = 0; };
if (_map in ["Altis", "Stratis"]) then { _lat = 40; _altitude = 0; }; if (_map in ["Altis", "Stratis"]) then { _lat = 40; _altitude = 0; };
@ -46,11 +46,10 @@ if (_map in ["lingor"]) then { _lat = -4; _altitude = 0; };
if (_map in ["Panthera3"]) then { _lat = 46; _altitude = 0; }; if (_map in ["Panthera3"]) then { _lat = 46; _altitude = 0; };
if (_map in ["Kunduz"]) then { _lat = 37; _altitude = 400; }; if (_map in ["Kunduz"]) then { _lat = 37; _altitude = 400; };
_UTM = [_long,_lat] call BIS_fnc_posDegToUTM; _UTM = [_long,_lat] call BIS_fnc_posDegToUTM;
_easting = _UTM select 0; _easting = _UTM select 0;
_northing = _UTM select 1; _northing = _UTM select 1;
// _zone = _UTM select 2; //_zone = _UTM select 2;
TRACE_4("",_UTM,_easting,_northing,_zone); TRACE_4("",_UTM,_easting,_northing,_zone);
/* /*
@ -76,9 +75,11 @@ _band = switch (true) do {
case (_lat>8): {"P"}; case (_lat>8): {"P"};
case (_lat>=0): {"N"}; case (_lat>=0): {"N"};
}; };
*/ */
_zone = 1 + (floor ((_long + 180) / 6)); _zone = 1 + (floor ((_long + 180) / 6));
_band = "Z"; _band = "Z";
if (_lat <= -80) then { if (_lat <= -80) then {
_band = "A"; _band = "A";
} else { } else {
@ -86,13 +87,13 @@ if (_lat <= -80) then {
_band = "CDEFGHJKLMNPQRSTUVWXX" select [(floor ((_lat / 8) + 10)), 1]; _band = "CDEFGHJKLMNPQRSTUVWXX" select [(floor ((_lat / 8) + 10)), 1];
}; };
}; };
if (_map == "VR") then {_zone = 0; _band = "RV";}; if (_map == "VR") then {_zone = 0; _band = "RV";};
_GZD = format ["%1%2",_zone,_band]; _GZD = format ["%1%2",_zone,_band];
TRACE_3("",_zone,_band,_GZD); TRACE_3("",_zone,_band,_GZD);
private ["_set1", "_set2", "_set3", "_set4", "_set5", "_set6", "_metaE", "_metaN", "_letterE", "_letterN", "_grid100km"];
private ["_set1","_set2","_set3","_set4","_set5","_set6","_metaE","_metaN","_letterE","_letterN","_grid100km"];
_set1 = [1,7,13,19,25,31,37,43,49,55]; _set1 = [1,7,13,19,25,31,37,43,49,55];
_set2 = [2,8,14,20,26,32,38,44,50,56]; _set2 = [2,8,14,20,26,32,38,44,50,56];
@ -102,25 +103,25 @@ _set5 = [5,11,17,23,29,35,41,47,53,59];
_set6 = [6,12,18,24,30,36,42,48,54,60]; _set6 = [6,12,18,24,30,36,42,48,54,60];
switch (true) do { switch (true) do {
case (_zone in _set1): {_metaE = 1; _metaN = 1;}; case (_zone in _set1): {_metaE = 1; _metaN = 1;};
case (_zone in _set2): {_metaE = 2; _metaN = 2;}; case (_zone in _set2): {_metaE = 2; _metaN = 2;};
case (_zone in _set3): {_metaE = 3; _metaN = 1;}; case (_zone in _set3): {_metaE = 3; _metaN = 1;};
case (_zone in _set4): {_metaE = 1; _metaN = 2;}; case (_zone in _set4): {_metaE = 1; _metaN = 2;};
case (_zone in _set5): {_metaE = 2; _metaN = 1;}; case (_zone in _set5): {_metaE = 2; _metaN = 1;};
case (_zone in _set6): {_metaE = 3; _metaN = 2;}; case (_zone in _set6): {_metaE = 3; _metaN = 2;};
}; };
TRACE_2("",_metaE,_metaN); TRACE_2("",_metaE,_metaN);
switch (true) do { switch (true) do {
case (_zone == 0): {_letterE = "E"}; case (_zone == 0): {_letterE = "E"};
case (_easting > 800000): {LOG("E8"); switch (_metaE) do {case 1: {_letterE="H"}; case 2: {_letterE="R"}; case 3: {_letterE="Z"}; }; }; case (_easting > 800000): {LOG("E8"); switch (_metaE) do {case 1: {_letterE="H"}; case 2: {_letterE="R"}; case 3: {_letterE="Z"}; }; };
case (_easting > 700000): {LOG("E7"); switch (_metaE) do {case 1: {_letterE="G"}; case 2: {_letterE="Q"}; case 3: {_letterE="Y"}; }; }; case (_easting > 700000): {LOG("E7"); switch (_metaE) do {case 1: {_letterE="G"}; case 2: {_letterE="Q"}; case 3: {_letterE="Y"}; }; };
case (_easting > 600000): {LOG("E6"); switch (_metaE) do {case 1: {_letterE="F"}; case 2: {_letterE="P"}; case 3: {_letterE="X"}; }; }; case (_easting > 600000): {LOG("E6"); switch (_metaE) do {case 1: {_letterE="F"}; case 2: {_letterE="P"}; case 3: {_letterE="X"}; }; };
case (_easting > 500000): {LOG("E5"); switch (_metaE) do {case 1: {_letterE="E"}; case 2: {_letterE="N"}; case 3: {_letterE="W"}; }; }; case (_easting > 500000): {LOG("E5"); switch (_metaE) do {case 1: {_letterE="E"}; case 2: {_letterE="N"}; case 3: {_letterE="W"}; }; };
case (_easting > 400000): {LOG("E4"); switch (_metaE) do {case 1: {_letterE="D"}; case 2: {_letterE="M"}; case 3: {_letterE="V"}; }; }; case (_easting > 400000): {LOG("E4"); switch (_metaE) do {case 1: {_letterE="D"}; case 2: {_letterE="M"}; case 3: {_letterE="V"}; }; };
case (_easting > 300000): {LOG("E3"); switch (_metaE) do {case 1: {_letterE="C"}; case 2: {_letterE="L"}; case 3: {_letterE="U"}; }; }; case (_easting > 300000): {LOG("E3"); switch (_metaE) do {case 1: {_letterE="C"}; case 2: {_letterE="L"}; case 3: {_letterE="U"}; }; };
case (_easting > 200000): {LOG("E2"); switch (_metaE) do {case 1: {_letterE="B"}; case 2: {_letterE="K"}; case 3: {_letterE="T"}; }; }; case (_easting > 200000): {LOG("E2"); switch (_metaE) do {case 1: {_letterE="B"}; case 2: {_letterE="K"}; case 3: {_letterE="T"}; }; };
case (_easting > 100000): {LOG("E1"); switch (_metaE) do {case 1: {_letterE="A"}; case 2: {_letterE="J"}; case 3: {_letterE="S"}; }; }; case (_easting > 100000): {LOG("E1"); switch (_metaE) do {case 1: {_letterE="A"}; case 2: {_letterE="J"}; case 3: {_letterE="S"}; }; };
default {_letterE="@"}; default {_letterE="@"};
}; };
TRACE_1("",_letterE); TRACE_1("",_letterE);
@ -129,37 +130,38 @@ _northing = _northing mod 2000000;
TRACE_1("",_northing); TRACE_1("",_northing);
switch (true) do { switch (true) do {
case (_zone == 0): {_letterN = "N"}; case (_zone == 0): {_letterN = "N"};
case (_northing > 1900000): {LOG("N19"); switch (_metaN) do {case 1: {_letterN = "V"}; case 2: {_letterN = "E"}; }; }; case (_northing > 1900000): {LOG("N19"); switch (_metaN) do {case 1: {_letterN = "V"}; case 2: {_letterN = "E"}; }; };
case (_northing > 1800000): {LOG("N18"); switch (_metaN) do {case 1: {_letterN = "U"}; case 2: {_letterN = "D"}; }; }; case (_northing > 1800000): {LOG("N18"); switch (_metaN) do {case 1: {_letterN = "U"}; case 2: {_letterN = "D"}; }; };
case (_northing > 1700000): {LOG("N17"); switch (_metaN) do {case 1: {_letterN = "T"}; case 2: {_letterN = "C"}; }; }; case (_northing > 1700000): {LOG("N17"); switch (_metaN) do {case 1: {_letterN = "T"}; case 2: {_letterN = "C"}; }; };
case (_northing > 1600000): {LOG("N16"); switch (_metaN) do {case 1: {_letterN = "S"}; case 2: {_letterN = "B"}; }; }; case (_northing > 1600000): {LOG("N16"); switch (_metaN) do {case 1: {_letterN = "S"}; case 2: {_letterN = "B"}; }; };
case (_northing > 1500000): {LOG("N15"); switch (_metaN) do {case 1: {_letterN = "R"}; case 2: {_letterN = "A"}; }; }; case (_northing > 1500000): {LOG("N15"); switch (_metaN) do {case 1: {_letterN = "R"}; case 2: {_letterN = "A"}; }; };
case (_northing > 1400000): {LOG("N14"); switch (_metaN) do {case 1: {_letterN = "Q"}; case 2: {_letterN = "V"}; }; }; case (_northing > 1400000): {LOG("N14"); switch (_metaN) do {case 1: {_letterN = "Q"}; case 2: {_letterN = "V"}; }; };
case (_northing > 1300000): {LOG("N13"); switch (_metaN) do {case 1: {_letterN = "P"}; case 2: {_letterN = "U"}; }; }; case (_northing > 1300000): {LOG("N13"); switch (_metaN) do {case 1: {_letterN = "P"}; case 2: {_letterN = "U"}; }; };
case (_northing > 1200000): {LOG("N12"); switch (_metaN) do {case 1: {_letterN = "N"}; case 2: {_letterN = "T"}; }; }; case (_northing > 1200000): {LOG("N12"); switch (_metaN) do {case 1: {_letterN = "N"}; case 2: {_letterN = "T"}; }; };
case (_northing > 1100000): {LOG("N11"); switch (_metaN) do {case 1: {_letterN = "M"}; case 2: {_letterN = "S"}; }; }; case (_northing > 1100000): {LOG("N11"); switch (_metaN) do {case 1: {_letterN = "M"}; case 2: {_letterN = "S"}; }; };
case (_northing > 1000000): {LOG("N10"); switch (_metaN) do {case 1: {_letterN = "L"}; case 2: {_letterN = "R"}; }; }; case (_northing > 1000000): {LOG("N10"); switch (_metaN) do {case 1: {_letterN = "L"}; case 2: {_letterN = "R"}; }; };
case (_northing > 900000): {LOG("N09"); switch (_metaN) do {case 1: {_letterN = "K"}; case 2: {_letterN = "Q"}; }; }; case (_northing > 900000): {LOG("N09"); switch (_metaN) do {case 1: {_letterN = "K"}; case 2: {_letterN = "Q"}; }; };
case (_northing > 800000): {LOG("N08"); switch (_metaN) do {case 1: {_letterN = "J"}; case 2: {_letterN = "P"}; }; }; case (_northing > 800000): {LOG("N08"); switch (_metaN) do {case 1: {_letterN = "J"}; case 2: {_letterN = "P"}; }; };
case (_northing > 700000): {LOG("N07"); switch (_metaN) do {case 1: {_letterN = "H"}; case 2: {_letterN = "N"}; }; }; case (_northing > 700000): {LOG("N07"); switch (_metaN) do {case 1: {_letterN = "H"}; case 2: {_letterN = "N"}; }; };
case (_northing > 600000): {LOG("N06"); switch (_metaN) do {case 1: {_letterN = "G"}; case 2: {_letterN = "M"}; }; }; case (_northing > 600000): {LOG("N06"); switch (_metaN) do {case 1: {_letterN = "G"}; case 2: {_letterN = "M"}; }; };
case (_northing > 500000): {LOG("N05"); switch (_metaN) do {case 1: {_letterN = "F"}; case 2: {_letterN = "L"}; }; }; case (_northing > 500000): {LOG("N05"); switch (_metaN) do {case 1: {_letterN = "F"}; case 2: {_letterN = "L"}; }; };
case (_northing > 400000): {LOG("N04"); switch (_metaN) do {case 1: {_letterN = "E"}; case 2: {_letterN = "K"}; }; }; case (_northing > 400000): {LOG("N04"); switch (_metaN) do {case 1: {_letterN = "E"}; case 2: {_letterN = "K"}; }; };
case (_northing > 300000): {LOG("N03"); switch (_metaN) do {case 1: {_letterN = "D"}; case 2: {_letterN = "J"}; }; }; case (_northing > 300000): {LOG("N03"); switch (_metaN) do {case 1: {_letterN = "D"}; case 2: {_letterN = "J"}; }; };
case (_northing > 200000): {LOG("N02"); switch (_metaN) do {case 1: {_letterN = "C"}; case 2: {_letterN = "H"}; }; }; case (_northing > 200000): {LOG("N02"); switch (_metaN) do {case 1: {_letterN = "C"}; case 2: {_letterN = "H"}; }; };
case (_northing > 100000): {LOG("N01"); switch (_metaN) do {case 1: {_letterN = "B"}; case 2: {_letterN = "G"}; }; }; case (_northing > 100000): {LOG("N01"); switch (_metaN) do {case 1: {_letterN = "B"}; case 2: {_letterN = "G"}; }; };
case (_northing > 0): {LOG("N00"); switch (_metaN) do {case 1: {_letterN = "A"}; case 2: {_letterN = "F"}; }; }; case (_northing > 0): {LOG("N00"); switch (_metaN) do {case 1: {_letterN = "A"}; case 2: {_letterN = "F"}; }; };
}; };
TRACE_1("",_letterN); TRACE_1("",_letterN);
_grid100km = _letterE+_letterN; _grid100km = _letterE + _letterN;
TRACE_1("",_grid100km); TRACE_1("",_grid100km);
if (_map == worldName) then { if (_map == worldName) then {
GVAR(MGRS_data) = [_GZD,_grid100km,_GZD+_grid100km]; GVAR(MGRS_data) = [_GZD, _grid100km, _GZD + _grid100km];
GVAR(mapAltitude) = _altitude; GVAR(mapAltitude) = _altitude;
GVAR(mapLatitude) = _lat; GVAR(mapLatitude) = _lat;
GVAR(mapLongitude) = _long; GVAR(mapLongitude) = _long;
}; };
[_GZD,_grid100km,_GZD+_grid100km]
[_GZD, _grid100km, _GZD + _grid100km]

View File

@ -2,57 +2,58 @@
* Author: VKing, PabstMirror * Author: VKing, PabstMirror
* Gets a 10-digit map grid for the given world position * Gets a 10-digit map grid for the given world position
* *
* Argument: * Arguments:
* 0: Position (2D Position) <ARRAY> * 0: Position (2D Position) <ARRAY>
* 1: Return type; false for array of easting and northing, true for single string <Bool> * 1: Return type; false for array of easting and northing, true for single string (default: false) <BOOL>
* *
* Return values: * Return Value:
* 0: Easting <String> * 0: Easting <String>
* 1: Northing <String> * 1: Northing <String>
* *
* Example: * Example:
* [(getPos player)] call ace_common_fnc_getMapGridFromPos; * [getPos player] call ace_common_fnc_getMapGridFromPos
* *
* Public: Yes * Public: Yes
*/ */
// #define DEBUG_MODE_FULL
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_pos); params ["_pos", ["_returnSingleString", false]];
DEFAULT_PARAM(1,_returnSingleString,false);
private["_count", "_easting", "_nativeGrid", "_northing"]; private ["_nativeGrid", "_count", "_easting", "_northing"];
//Fallback, when map data is weird (letters) //Fallback, when map data is weird (letters)
if ((count GVAR(mapGridData)) == 0) exitWith { if (GVAR(mapGridData) isEqualTo []) exitWith {
_nativeGrid = mapGridPosition _pos; _nativeGrid = mapGridPosition _pos;
if (_returnSingleString) then { if (_returnSingleString) then {
_nativeGrid _nativeGrid
} else { } else {
_count = floor ((count _nativeGrid) / 2); _count = floor ((count _nativeGrid) / 2);
[(_nativeGrid select [0, _count]), (_nativeGrid select [_count, _count])] [_nativeGrid select [0, _count], _nativeGrid select [_count, _count]]
}; };
}; };
EXPLODE_4_PVT(GVAR(mapGridData),_offsetX,_realOffsetY,_stepXat5,_stepYat5); GVAR(mapGridData) params ["_offsetX", "_realOffsetY", "_stepXat5", "_stepYat5"];
_easting = floor (((_pos select 0) - _offsetX) / _stepXat5); _easting = floor (((_pos select 0) - _offsetX) / _stepXat5);
_northing = floor (((_pos select 1) - _realOffsetY) / _stepYat5); _northing = floor (((_pos select 1) - _realOffsetY) / _stepYat5);
//Attempt to handle negative east/north (e.g.: moving west of map bounds) //Attempt to handle negative east/north (e.g.: moving west of map bounds)
if (_easting > 0) then { if (_easting > 0) then {
_easting = str _easting; _easting = str _easting;
while {count _easting < 5} do {_easting = "0" + _easting;}; while {count _easting < 5} do {_easting = "0" + _easting};
} else { } else {
_easting = str abs _easting; _easting = str abs _easting;
while {count _easting < 4} do {_easting = "0" + _easting;}; while {count _easting < 4} do {_easting = "0" + _easting};
_easting = "-" + _easting; _easting = "-" + _easting;
}; };
if (_northing > 0) then { if (_northing > 0) then {
_northing = str _northing; _northing = str _northing;
while {count _northing < 5} do {_northing = "0" + _northing;}; while {count _northing < 5} do {_northing = "0" + _northing};
} else { } else {
_northing = str abs _northing; _northing = str abs _northing;
while {count _northing < 4} do {_northing = "0" + _northing;}; while {count _northing < 4} do {_northing = "0" + _northing};
_northing = "-" + _northing; _northing = "-" + _northing;
}; };
@ -60,4 +61,4 @@ if (_returnSingleString) then {
_easting + _northing _easting + _northing
} else { } else {
[_easting, _northing] [_easting, _northing]
}; }; // return