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,7 +46,6 @@ 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;
@ -77,8 +76,10 @@ _band = switch (true) do {
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,12 +87,12 @@ 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];
@ -162,4 +163,5 @@ if (_map == worldName) then {
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