Advertisement
ardwin22

DGCore_fnc_findPosition

Oct 10th, 2024
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 2.19 KB | Gaming | 0 0
  1. /*
  2.     DGCore_fnc_findPosition
  3.  
  4.     Purpose: Find a safe position within the given constraints using BIS_fnc_findSafePos.
  5.  
  6.     Parameters:
  7.         _pos: Starting position for the search. Optional, defaults to DG_mapCenter.
  8.         _minDistance: Minimum distance from the starting position. Default: 0.
  9.         _maxDistance: Maximum distance from the starting position. Default: DG_mapRange.
  10.         _distanceFromObjects: Minimum distance from objects. Default: 50.
  11.         _waterMode: Mode to handle water proximity (0: ignore, 1: avoid water, 2: on water). Default: 0.
  12.         _maxGrad: Maximum terrain gradient allowed. Default: 1.
  13.         _shoreMode: Mode for shore proximity (0: ignore, 1: avoid shore, 2: near shore). Default: 0.
  14.  
  15.     Example:
  16.         _pos = [] call DGCore_fnc_findPosition;
  17.         _pos = [getPos player, 10, 500, 60] call DGCore_fnc_findPosition;
  18.  
  19.     Returns: The safe position found or [-1,-1,-1] if no valid position could be found.
  20.  
  21.     Copyright 2024 by Dagovax
  22. */
  23.  
  24. private ["_pos", "_minDistance", "_maxDistance", "_distanceFromObjects", "_waterMode", "_maxGrad", "_shoreMode"];
  25. params [["_pos", []], ["_minDistance", 0], ["_maxDistance", DG_mapRange], ["_distanceFromObjects", 50], ["_waterMode", 0], ["_maxGrad", 0.5], ["_shoreMode", 0]];
  26.  
  27. if(_pos isEqualTo []) then
  28. {
  29.     _pos = DG_mapCenter;
  30. };
  31.  
  32. private _validSpot  = false;
  33. private _currGrad   = 0.0;
  34. private _position   = [-1,-1,-1];
  35.  
  36. [format["Searching for a valid position until while loop ends or valid position returns..."], "DGCore_fnc_findPosition", "debug"] call DGCore_fnc_log;
  37. while {!_validSpot && (_currGrad <= _maxGrad)} do
  38. {
  39.     if(canSuspend) then
  40.     {
  41.         sleep 1;
  42.     };
  43.    
  44.     _position = [_pos, _minDistance, _maxDistance, _distanceFromObjects, _waterMode, _currGrad, _shoreMode, [], [[-1,-1,-1],[-1,-1,-1]]] call BIS_fnc_findSafePos;
  45.    
  46.     // Check if the position is valid
  47.     if (!(_position isEqualTo [-1, -1, -1])) then {
  48.         _validSpot = true;
  49.     };
  50.    
  51.     _currGrad = _currGrad + 0.1; // Next loop the grad will be a bit higher
  52. }; 
  53.  
  54. if !(_position isEqualTo [-1,-1,-1]) then
  55. {
  56.     [format["Found safe position @ %1 with grad %2", _position, _currGrad], "DGCore_fnc_findPosition", "debug"] call DGCore_fnc_log;
  57. };
  58.  
  59. _position
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement