From 03c031537cafd60bc681ef3f8212b2eea101108b Mon Sep 17 00:00:00 2001 From: Chris Cardozo Date: Sat, 13 Jun 2020 14:14:46 -0400 Subject: [PATCH] Updates to code finding location for missions. --- .../Functions/GMS_fnc_findSafePosn.sqf | 57 ++++++----- .../Functions/GMS_fnc_findSafePosn_2.sqf | 97 +++++++++++++++++++ .../Missions/GMS_fnc_spawnPendingMissions.sqf | 5 +- .../custom_server/Compiles/blck_functions.sqf | 1 + .../custom_server/init/blck_init_server.sqf | 37 +++++++ 5 files changed, 171 insertions(+), 26 deletions(-) create mode 100644 @GMS/addons/custom_server/Compiles/Functions/GMS_fnc_findSafePosn_2.sqf diff --git a/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_findSafePosn.sqf b/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_findSafePosn.sqf index ff9cdd0..92130c5 100644 --- a/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_findSafePosn.sqf +++ b/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_findSafePosn.sqf @@ -12,24 +12,24 @@ #include "\q\addons\custom_server\Configs\blck_defines.hpp"; if (isNil "blck_locationBlackList") then {blck_locationBlackList = []}; -private _blacklistedLocations = blck_locationBlackList; + _fn_buildBlacklistedLocationsList = { params["_minToBases","_minToPlayers","_minToMissions","_minToTowns","_minToRecentMissionLocation"]; - private _blacklistedLocations = +blck_locationBlackList; + /* locations of villages / cities / others already included in blck_locationBlackList so we do not need to add it here. */ + private _blacklistedLocs = +blck_locationBlackList; for '_i' from 1 to (count blck_recentMissionCoords) do { private _loc = blck_recentMissionCoords deleteAt 0; if (_loc select 1 < diag_tickTime) then { blck_recentMissionCoords pushBack _loc; - _blacklistedLocations pushBack [_loc select 0, _minToRecentMissionLocation]; + _blacklistedLocs pushBack [_loc select 0, _minToRecentMissionLocation]; }; }; { - - _blacklistedLocations pushBack [_x,_minToMissions]; + _blacklistedLocs pushBack [_x,_minToMissions]; } forEach blck_ActiveMissionCoords; private "_bases"; @@ -37,23 +37,21 @@ _fn_buildBlacklistedLocationsList = { if (blck_modType isEqualTo "Exile") then {_bases = nearestObjects[blck_mapCenter, ["Exile_Construction_Flag_Static"], blck_mapRange + 25000]}; { - - _blacklistedLocations pushBack [getPosATL _x,_minToBases]; + _blacklistedLocs pushBack [getPosATL _x,_minToBases]; } forEach _bases; { - - _blacklistedLocations pushBack [getPosATL _x,_minToPlayers]; + _blacklistedLocs pushBack [getPosATL _x,_minToPlayers]; } forEach allPlayers; if (blck_minDistanceFromDMS > 0) then { - _blacklistedLocations append ([] call blck_fnc_getAllDMSMarkers); + _blacklistedLocs append ([] call blck_fnc_getAllDMSMarkers); }; - - _blacklistedLocations + //diag_log format["_blacklistedLocs = %1",_blacklistedLocs]; + _blacklistedLocs }; private _minDistToBases = blck_minDistanceToBases; @@ -61,27 +59,36 @@ private _minDistToPlayers = blck_minDistanceToPlayer; private _minDistToTowns = blck_minDistanceFromTowns; private _mindistToMissions = blck_MinDistanceFromMission; private _minToRecentMissionLocation = 200; - +private _coords = []; private _blacklistedLocations = [_minDistToBases,_minDistToPlayers,_minDistToTowns,_mindistToMissions,_minToRecentMissionLocation] call _fn_buildBlacklistedLocationsList; -private _coords = [blck_mapCenter,0,blck_mapRange,3,0,5,0,_blacklistedLocations] call BIS_fnc_findSafePos; - - -if (_coords isEqualTo []) then +private _count = 25; +while {_coords isEqualTo [] && _count > 0} do { - for "_index" from 1 to 100 do + /* + 6-13-20 + Notes + increased min distance to objects from 3 to 10 + decreased max slope from 5 to 0.5 + */ + + _coords = [blck_mapCenter,0,blck_mapRange,10,0,0.5,0,_blacklistedLocations] call BIS_fnc_findSafePos; + /* Check whether the location is flat enough: returns [] if not. */ + private _isFlat = _coords isFlatEmpty [20,0,0.5,100,0,false]; + if (_coords isEqualTo [] || !(_isFlat isEqualTo [])) then { { - _x set[1, (_x select 1) * 0.8]; - - } forEach _blacklistedLocations; - _coords = [blck_mapCenter,0,blck_mapRange,3,0,5,0,_blacklistedLocations] call BIS_fnc_findSafePos; - - if !(_coords isEqualTo []) exitWith {}; - uisleep 1; + //private _range = (_x select 1) * 0.7; + _x set[1,(_x select 1) * 0.75]; + } forEach _blackListedLocations; + _count = _count - 1; }; }; +if (_coords isEqualTo []) then +{ + diag_log format["[blckeagls] Could not find a safe position for a mission, consider reducing values for minimum distances between missions and players, bases, other missions or towns"]; +}; _coords diff --git a/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_findSafePosn_2.sqf b/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_findSafePosn_2.sqf new file mode 100644 index 0000000..747e0a1 --- /dev/null +++ b/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_findSafePosn_2.sqf @@ -0,0 +1,97 @@ +private _safepos = [getMarkerPos "center",0,14000,0,0,0.5,0]; +private _validspot = false; +private "_position"; +_fnc_nearWater = { + _result = false; + _position = _this select 0; + _radius = _this select 1; + + for "_i" from 0 to 359 step 45 do { + //_checkposition = [(_position select 0) + (sin(_i)*_radius), (_position select 1) + (cos(_i)*_radius)]; + //_checkposition2 = [(_position select 0) + (sin(_i)*_radius/2), (_position select 1) + (cos(_i)*_radius/2)]; + _checkPosition = _position getPos[_radius, _i]; + if (surfaceIsWater _checkposition) exitWith { + _result = true; + }; + }; + _result +}; + +while{!_validspot} do { + //uiSleep 1; + _validspot = true; + _position = _safepos call BIS_fnc_findSafePos; + if (count _position > 2) then { + _validspot = false; + }; + if(_validspot) then { + if ([_position,500] call _fnc_nearWater) then { + _validspot = false; + }; + }; + if(_validspot) then { + _isflat = _position isFlatEmpty [20,0,0.5,100,0,false]; + if (_isflat isequalto []) then { + _validspot = false; + }; + }; + if(_validspot) then { + { + if (_position distance _x < 1500) exitwith { + _validspot = false; + }; + } foreach (missionnamespace getvariable ["blck_ActiveMissionCoords",[]]); + }; + + // Check for near Bases + if(_validspot) then { + if (blck_modType isEqualTo "Epoch") then { + { + if (_position distance _x < 1000) exitwith { + _validspot = false; + }; + } foreach (missionnamespace getvariable ["Epoch_PlotPoles",[]]); + } + else { + if (blck_modType isEqualTo "Exile") then { + { + if (_position distance _x < blck_minDistanceToBases) exitwith { + _validspot = false; + }; + } foreach (nearestObjects [blck_mapCenter, ["Exile_Construction_Flag_Static"], blck_mapRange + 25000]); + }; + }; + }; + +// Check for near Players + if(_validspot) then { + { + if (_position distance _x < blck_minDistanceToPlayer) exitwith { + _validspot = false; + }; + } foreach allplayers; + }; + + // Check for near locations + if (_validspot) then { + { + if (_position distance (_x select 0) < (_x select 1)) exitWith { + _validspot = false; + }; + } forEach blck_locationBlackList; + }; + + // Check for DMS missions + if (blck_minDistanceFromDMS > 0 && _validspot) then + { + { + if (_position distance _x < blck_minDistanceFromDMS) exitWith { + _validspot = false; + }; + } forEach ([] call blck_fnc_getAllDMSMarkers); + }; +}; +_position set [2, 0]; +_position + + diff --git a/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_spawnPendingMissions.sqf b/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_spawnPendingMissions.sqf index c424a3e..0200063 100644 --- a/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_spawnPendingMissions.sqf +++ b/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_spawnPendingMissions.sqf @@ -31,7 +31,10 @@ if (count _readyToSpawnQue > 0) then _coords = [] call blck_fnc_FindSafePosn; - + if (_coords isEqualTo []) exitWith + { + diag_log format["[blckagls] fnc_spawnPendingMissions: _fnc_findSafePosn could not find a location for this mission; consider reducing distances between players, bases, missions or towns."]; + }; _compiledMission = selectRandom (_missionToSpawn select 0); _missionMarker = _missionToSpawn select 1; diff --git a/@GMS/addons/custom_server/Compiles/blck_functions.sqf b/@GMS/addons/custom_server/Compiles/blck_functions.sqf index d2aec28..0b45d12 100644 --- a/@GMS/addons/custom_server/Compiles/blck_functions.sqf +++ b/@GMS/addons/custom_server/Compiles/blck_functions.sqf @@ -17,6 +17,7 @@ private _functions = [ ["blck_fnc_waitTimer","\q\addons\custom_server\Compiles\Functions\GMS_fnc_waitTimer.sqf"], ["blck_fnc_timedOut","\q\addons\custom_server\Compiles\Functions\GMS_fnc_timedOut.sqf"], ["blck_fnc_FindSafePosn","\q\addons\custom_server\Compiles\Functions\GMS_fnc_findSafePosn.sqf"], + ["blck_fnc_findSafePosn_2","\q\addons\custom_server\Compiles\Functions\GMS_fnc_findSafePosn_2.sqf"], ["blck_fnc_randomPosition","\q\addons\custom_server\Compiles\Functions\GMS_fnc_randomPosn.sqf"], // find a randomPosn. see script for details. ["blck_fnc_findPositionsAlongARadius","\q\addons\custom_server\Compiles\Functions\GMS_fnc_findPositionsAlongARadius.sqf"], ["blck_fnc_giveTakeCrypto","\q\addons\custom_server\Compiles\Functions\GMS_fnc_giveTakeCrypto.sqf"], diff --git a/@GMS/addons/custom_server/init/blck_init_server.sqf b/@GMS/addons/custom_server/init/blck_init_server.sqf index e739491..ad041bf 100644 --- a/@GMS/addons/custom_server/init/blck_init_server.sqf +++ b/@GMS/addons/custom_server/init/blck_init_server.sqf @@ -166,6 +166,9 @@ private _other = ["NameLocal"] call _fn_setupLocationType; private _airport = ["Airport"] call _fn_setupLocationType; blck_townLocations = _villages + _cites + _capitals + _marine + _other + _airport; +{ + blck_locationBlackList pushBack [locationPosition _x, blck_minDistanceFromTowns]; +} forEach blck_townLocations; diag_log format["_init_server: count blck_townLocations = %1 || blck_townLocations = %2",count blck_townLocations, blck_townLocations]; //Start the mission timers @@ -228,4 +231,38 @@ blck_pvs_version = blck_versionNumber; publicVariable "blck_pvs_version"; diag_log format["[blckeagls] version %1 Build %2 Date %4 Loaded in %3 seconds",blck_versionNumber,blck_buildNumber,diag_tickTime - _blck_loadingStartTime,blck_buildDate]; //,blck_modType]; +/* +if (blck_debugOn || (blck_debugLevel >= 1)) then +{ + private _pos = [] call blck_fnc_findSafePosn; + private _root = ""; + private _path = "Orange"; + private _mission = "officeComplex"; //"bunkerMission"; + private _compiledMission = compilefinal preprocessFileLineNumbers format["\q\addons\custom_server\Missions\%1\%2.sqf",_path,_mission]; + diag_log format["[blckeagls] mission test sequence run for mission path %1 name %2",_path,_mission]; + [_pos,"testMarkerGRG","blue"] spawn _compiledMission; + diag_log format["testmarker mission spawned at %1",diag_tickTime]; + { + diag_log format[" findSafePosn speed tests"; + private _allCoords = []; + private _t1 = diag_tickTime; + for "_i" from 1 to 25 do + { + private _coords = [] call blck_fnc_FindSafePosn; + }; + diag_log format["blck_init_server: time elapsed for 10000 calls to blck_fnc_findSafePosn = %1",diag_tickTime - _t1]; + _t1 = diag_tickTime; + _allCoords = []; + for "_j" from 1 to 25 do + { + private _coords = [] call blck_fnc_FindSafePosn_2; + }; + diag_log format["blck_init_server: time elapsed for 10000 calls to blck_fnc_findSafePosn_2 = %1",diag_tickTime - _t1]; +};