2015-08-28 21:52:56 +00:00
/*
2015-10-04 03:32:42 +00:00
DMS_fnc_FindSafePos
2015-08-28 21:52:56 +00:00
Created by eraser1
2015-10-04 03:32:42 +00:00
ALL PARAMETERS ARE OPTIONAL (as long as configs are properly defined).
Excluding parameters will create some RPT spam, but it's not too much of an issue.
2015-08-28 21:52:56 +00:00
Usage:
[
2015-10-04 03:32:42 +00:00
_nearestObjectMinDistance, // NUMBER (distance): Minimum distance from the nearest object.
_waterNearLimit, // NUMBER (distance): Minimum distance from water.
_maxSurfaceNormal, // NUMBER (between 0-1): Maximum "surfaceNormal"; Basically determines how steep a position is. Check the comment for config value "DMS_MaxSurfaceNormal" in config.sqf for more info
_spawnZoneNearLimit, // NUMBER (distance): Minimum distance from a spawn point.
_traderZoneNearLimit, // NUMBER (distance): Minimum distance from a trader zone.
_missionNearLimit, // NUMBER (distance): Minimum distance from another mission.
_playerNearLimit, // NUMBER (distance): Minimum distance from a player.
_throttleParams // BOOLEAN: Whether or not some of the distance values should be throttled on repeated attempts.
2015-09-05 03:40:00 +00:00
] call DMS_fnc_findSafePos;
2015-08-28 21:52:56 +00:00
*/
2015-10-04 03:32:42 +00:00
private ["_nearestObjectMinDistance", "_waterNearLimit", "_maxSurfaceNormal", "_spawnZoneNearLimit", "_traderZoneNearLimit", "_missionNearLimit", "_playerNearLimit", "_throttleParams", "_safePosParams", "_validspot", "_attempts", "_pos"];
2015-08-28 19:14:59 +00:00
2015-08-31 02:42:02 +00:00
params
[
2015-10-04 03:32:42 +00:00
["_nearestObjectMinDistance", 25, [0] ],
["_waterNearLimit", DMS_WaterNearBlacklist, [0] ],
["_maxSurfaceNormal", DMS_MaxSurfaceNormal, [0] ],
["_spawnZoneNearLimit", DMS_SpawnZoneNearBlacklist, [0] ],
["_traderZoneNearLimit", DMS_TraderZoneNearBlacklist,[0] ],
["_missionNearLimit", DMS_MissionNearBlacklist, [0] ],
["_playerNearLimit", DMS_PlayerNearBlacklist, [0] ],
["_throttleParams", DMS_ThrottleBlacklists, [true]]
2015-08-31 02:42:02 +00:00
];
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
{
2015-10-04 03:32:42 +00:00
case "altis": { _safePosParams = [[16000,16000],0,16000]; }; // [16000,16000] w/ radius of 16000 works well for Altis
case "bornholm": { _safePosParams = [[11265,11265],0,12000]; }; // Thanks to thirdhero for testing this info
case "esseker": { _safePosParams = [[6275,6350,0],0,5000]; }; // Thanks to Flowrider for this info
case "tavi": { _safePosParams = [[12800,12800],0,12800]; }; // Thanks to JamieKG for this info
default { _safePosParams = [[],0,-1]; }; // Use default BIS_fnc_findSafePos methods for finding map center (worldSize)
2015-09-12 01:21:53 +00:00
};
2015-10-04 03:32:42 +00:00
_safePosParams append [_nearestObjectMinDistance,0,9999,0,DMS_findSafePosBlacklist];
2015-08-28 06:04:50 +00:00
_validspot = false;
2015-10-04 03:32:42 +00:00
_attempts = 0;
2015-09-12 01:21:53 +00:00
while{!_validspot} do
{
2015-10-04 03:32:42 +00:00
_pos = _safePosParams call BIS_fnc_findSafePos;
_attempts = _attempts+1;
2015-09-20 20:26:08 +00:00
2015-10-04 03:32:42 +00:00
// It will only throttle the missionNear blacklist and playerNear limits because those are the most likely to throw an exception.
// The throttling works by decreasing the parameters by 10% every 15 attempts, until it reaches 100 meters (by default).
if (_throttleParams && {(_attempts>=DMS_AttemptsUntilThrottle) && {(_attempts%DMS_AttemptsUntilThrottle)==0}}) then
2015-08-28 19:14:59 +00:00
{
2015-10-04 03:32:42 +00:00
_missionNearLimit = (DMS_ThrottleCoefficient * _missionNearLimit) max DMS_MinThrottledDistance;
_playerNearLimit = (DMS_ThrottleCoefficient * _playerNearLimit) max DMS_MinThrottledDistance;
2015-09-12 01:21:53 +00:00
if (DMS_DEBUG) then
{
2015-10-04 03:32:42 +00:00
diag_log format ["DMS_DEBUG FindSafePos :: Throttling _missionNearLimit to %1 and _playerNearLimit to %2 after %3 failed attempts to find a safe position! FPS: %4",_missionNearLimit,_playerNearLimit,_attempts,diag_fps];
2015-08-28 19:14:59 +00:00
};
2015-08-28 06:04:50 +00:00
};
2015-10-04 03:32:42 +00:00
_validspot = [_pos, _waterNearLimit, _maxSurfaceNormal, _spawnZoneNearLimit, _traderZoneNearLimit, _missionNearLimit, _playerNearLimit] call DMS_fnc_IsValidPosition;
2015-08-28 06:04:50 +00:00
};
2015-10-04 03:32:42 +00:00
if(DMS_DEBUG) then
{
diag_log format["DMS_DEBUG FindSafePos :: Found mission position %1 with %2 params in %3 attempts. _this: %4",_pos,_safePosParams,_attempts,_this];
2015-08-28 19:14:59 +00:00
};
2015-10-04 03:32:42 +00:00
2015-08-28 19:14:59 +00:00
_pos set [2, 0];
_pos;