Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- DGCore_fnc_findPosition
- Purpose: Find a safe position within the given constraints using BIS_fnc_findSafePos.
- Parameters:
- _pos: Starting position for the search. Optional, defaults to DG_mapCenter.
- _minDistance: Minimum distance from the starting position. Default: 0.
- _maxDistance: Maximum distance from the starting position. Default: DG_mapRange.
- _distanceFromObjects: Minimum distance from objects. Default: 50.
- _waterMode: Mode to handle water proximity (0: ignore, 1: avoid water, 2: on water). Default: 0.
- _maxGrad: Maximum terrain gradient allowed. Default: 1.
- _shoreMode: Mode for shore proximity (0: ignore, 1: avoid shore, 2: near shore). Default: 0.
- Example:
- _pos = [] call DGCore_fnc_findPosition;
- _pos = [getPos player, 10, 500, 60] call DGCore_fnc_findPosition;
- Returns: The safe position found or [-1,-1,-1] if no valid position could be found.
- Copyright 2024 by Dagovax
- */
- private ["_pos", "_minDistance", "_maxDistance", "_distanceFromObjects", "_waterMode", "_maxGrad", "_shoreMode"];
- params [["_pos", []], ["_minDistance", 0], ["_maxDistance", DG_mapRange], ["_distanceFromObjects", 50], ["_waterMode", 0], ["_maxGrad", 0.5], ["_shoreMode", 0]];
- if(_pos isEqualTo []) then
- {
- _pos = DG_mapCenter;
- };
- private _validSpot = false;
- private _currGrad = 0.0;
- private _position = [-1,-1,-1];
- [format["Searching for a valid position until while loop ends or valid position returns..."], "DGCore_fnc_findPosition", "debug"] call DGCore_fnc_log;
- while {!_validSpot && (_currGrad <= _maxGrad)} do
- {
- if(canSuspend) then
- {
- sleep 1;
- };
- _position = [_pos, _minDistance, _maxDistance, _distanceFromObjects, _waterMode, _currGrad, _shoreMode, [], [[-1,-1,-1],[-1,-1,-1]]] call BIS_fnc_findSafePos;
- // Check if the position is valid
- if (!(_position isEqualTo [-1, -1, -1])) then {
- _validSpot = true;
- };
- _currGrad = _currGrad + 0.1; // Next loop the grad will be a bit higher
- };
- if !(_position isEqualTo [-1,-1,-1]) then
- {
- [format["Found safe position @ %1 with grad %2", _position, _currGrad], "DGCore_fnc_findPosition", "debug"] call DGCore_fnc_log;
- };
- _position
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement