2015-08-28 21:52:56 +00:00
/*
2015-09-05 03:40:00 +00:00
DMS_fnc_findSafePos
2015-08-28 21:52:56 +00:00
Created by eraser1
Usage:
[
2015-08-31 02:42:02 +00:00
_nearestObjectMinDistance, // (OPTIONAL) Number: Minimum distance from nearest object
_maxTerrainGradient // (OPTIONAL) Number: Maximum terrain gradient (slope)
2015-09-05 03:40:00 +00:00
] call DMS_fnc_findSafePos;
2015-08-28 21:52:56 +00:00
*/
private ["_nearestObjectMinDistance","_maxTerrainGradient","_safePosParams","_validspot","_i","_pos"];
2015-08-28 19:14:59 +00:00
2015-08-31 02:42:02 +00:00
params
[
["_nearestObjectMinDistance",25,[0]],
["_maxTerrainGradient",10,[0]]
];
2015-08-28 06:04:50 +00:00
2015-09-12 01:21:53 +00:00
// Some custom maps don't have the proper safePos config entries.
// If you are using one and you have an issue with mission spawns, please create an issue on GitHub or post a comment in the DMS thread.
switch (toLower worldName) do
{
case "altis" : { _safePosParams = [[16000,16000],0,16000,_nearestObjectMinDistance,0,_maxTerrainGradient,0,DMS_findSafePosBlacklist]; }; //[16000,16000] w/ radius of 16000 works well for Altis
case "bornholm" : { _safePosParams = [[11264,11264],0,12000,_nearestObjectMinDistance,0,_maxTerrainGradient,0,DMS_findSafePosBlacklist]; }; // Thanks to thirdhero for testing this info
2015-09-14 00:50:34 +00:00
case "esseker" : { _safePosParams = [[6276.77,6352.98,0],0,5000,_nearestObjectMinDistance,0,_maxTerrainGradient,0,DMS_findSafePosBlacklist]; }; // Thanks to Flowrider for this info
2015-09-12 15:05:17 +00:00
case "tavi" : { _safePosParams = [[12800,12800],0,12800,_nearestObjectMinDistance,0,_maxTerrainGradient,0,DMS_findSafePosBlacklist]; }; // Thanks to JamieKG for this info
2015-09-12 06:34:03 +00:00
default { _safePosParams = [[],0,-1,_nearestObjectMinDistance,0,_maxTerrainGradient,0,DMS_findSafePosBlacklist]; };
2015-09-12 01:21:53 +00:00
};
2015-08-28 06:04:50 +00:00
_validspot = false;
_i = 0;
2015-09-12 01:21:53 +00:00
while{!_validspot} do
{
2015-08-28 19:14:59 +00:00
_pos = _safePosParams call BIS_fnc_findSafePos;
2015-08-28 06:04:50 +00:00
_i = _i+1;
2015-08-28 21:52:56 +00:00
try
{
2015-08-28 19:14:59 +00:00
// Check for nearby water
2015-09-15 03:50:09 +00:00
if ((DMS_WaterNearBlacklist>0) && {[_pos,DMS_WaterNearBlacklist] call DMS_fnc_isNearWater}) then
2015-08-28 06:04:50 +00:00
{
2015-08-28 19:14:59 +00:00
throw ("water");
2015-08-28 06:04:50 +00:00
};
2015-08-28 19:14:59 +00:00
// Check for nearby players
2015-09-15 03:50:09 +00:00
if ((DMS_PlayerNearBlacklist>0) && {[_pos,DMS_PlayerNearBlacklist] call DMS_fnc_IsPlayerNearby}) then
2015-08-28 06:04:50 +00:00
{
2015-08-28 19:14:59 +00:00
throw ("players");
2015-08-28 06:04:50 +00:00
};
2015-08-28 19:14:59 +00:00
{
// Check for nearby spawn points
2015-09-15 03:50:09 +00:00
if ((DMS_SpawnZoneNearBlacklist>0) && {((markertype _x) == "ExileSpawnZone") && {((getMarkerPos _x) distance2D _pos)<=DMS_SpawnZoneNearBlacklist}}) then
2015-08-28 19:14:59 +00:00
{
throw ("a spawn zone");
};
2015-08-28 06:04:50 +00:00
2015-08-28 19:14:59 +00:00
// Check for nearby trader zones
2015-09-15 03:50:09 +00:00
if ((DMS_TraderZoneNearBlacklist>0) && {((markertype _x) == "ExileTraderZone") && {((getMarkerPos _x) distance2D _pos)<=DMS_TraderZoneNearBlacklist}}) then
2015-08-28 19:14:59 +00:00
{
throw ("a trader zone");
};
2015-08-28 06:04:50 +00:00
2015-08-28 19:14:59 +00:00
// Check for nearby missions
2015-09-15 03:50:09 +00:00
if ((DMS_MissionNearBlacklist>0) && {((_x find "DMS_MissionMarkerDot")>-1) && {((getMarkerPos _x) distance2D _pos)<=DMS_MissionNearBlacklist}}) then
2015-08-28 06:04:50 +00:00
{
2015-08-28 19:14:59 +00:00
throw ("another mission");
2015-08-28 06:04:50 +00:00
};
2015-09-04 16:35:19 +00:00
} forEach allMapMarkers;
2015-08-28 19:14:59 +00:00
// No exceptions found
_validspot = true;
}
catch
{
2015-09-12 01:21:53 +00:00
if (DMS_DEBUG) then
{
2015-08-28 19:14:59 +00:00
diag_log format ["DMS_DEBUG findSafePos :: Exception in attempt %1 | Position %2 is too close to %3!",_i,_pos,_exception];
};
2015-08-28 06:04:50 +00:00
};
};
2015-08-28 19:14:59 +00:00
if(DMS_DEBUG) then {
diag_log format["DMS_DEBUG findSafePos :: Mission position %1 with %2 params found in %3 attempts.",_pos,_safePosParams,_i];
};
_pos set [2, 0];
_pos;