Jump to content
Sign in to follow this  
dimon

Function random location of the object(s) in the specified radius.

Recommended Posts

Function random location of the object(s) in the specified radius.

Based on BIS_fnc_findSafePos.

example:

Pos_mark_fnc3 = compile preprocessFile "Pos_mark_fnc3.sqf";
_count=400;
for "_cnt" from 0 to (_count-1) step 1 do
{
       _veh=createVehicle ["Sign_sphere100cm_EP1", getpos player, [], 50, "CAN_COLLIDE"];
       _newPos=[getpos player, [0,400], 10, [100, 100], [10, 10], 0.1, [0,false], [0], 20, 60], [["House","Sign_sphere100cm_EP1"],10],1500,_cnt] call Pos_mark_fnc3;
       _veh setpos _newPos;
};

_newPos=[getpos player, [0,400], 10, [100, 100], [10, 10], 0.1, [0,false], [0, 20, 60], [["House","Sign_sphere100cm_EP1"],10],1500,_cnt] call Pos_mark_fnc3;

_newPos=[getpos player, [0,400], 10, [100, 100], [10, 10], 0.1, [0,false], [1, 20, 60], [["House","Sign_sphere100cm_EP1"],10],1500,_cnt] call Pos_mark_fnc3;

_newPos=[getpos player, [0,400], 10, [100, 100], [10, 10], 0.1, [0,false], [2, 20, 60], [["House","Sign_sphere100cm_EP1"],10],1500,_cnt] call Pos_mark_fnc3;

_newPos=[getpos player, [0,400], 10, [100, 100], [10, 10], 0.1, [0,false], [3, 20, 60], [["House","Sign_sphere100cm_EP1"],10],1500,_cnt] call Pos_mark_fnc3;

_newPos=[getpos player, [0,400], 10, [100, 100], [10, 10], 0.1, [0,false], [4, 20, 60], [["House","Sign_sphere100cm_EP1"],10],1500,_cnt] call Pos_mark_fnc3;

_newPos=[getpos player, [0,400], 10, [100, 100], [10, 10], 0.1, [0,false], [5, 20, 60], [["House","Sign_sphere100cm_EP1"],10],1500,_cnt] call Pos_mark_fnc3;

_newPos=[getpos player, [0,400], 10, [100, 100], [10, 10], 0.1, [0,false], [6, 20, 60], [["House","Sign_sphere100cm_EP1"],10],1500,_cnt] call Pos_mark_fnc3;

_newPos=[getpos player, [0,400], 10, [100, 100], [10, 10], 0.1, [2,false], [1, 20, 60], [["House","Sign_sphere100cm_EP1"],10],1500,_cnt] call Pos_mark_fnc3;

_newPos=[getpos player, [0,400], 1, [100, 100], [10, 10], 0.1, [0,true], [1, 20, 60], [["House","Sign_sphere100cm_EP1"],10],1500,_cnt] call Pos_mark_fnc3;

POS_FNC3

Pos_mark_fnc3

Changelog:

2 in 1: test and main functions

/*
* Pos_fnc3.sqf

* POS_FNC3 = compile preprocessFile "Pos_fnc3.sqf";

* Dimon UA Find position SCRIPT 3.

*

* пример:

_spawnpoint=[position, [800,1300], 0.1, [0, 100], [10, 10], 0.1, [0,false], [4, 50, 60], [["Static"],20],150, [[[3588.96,3627.49], [4195.73,3122.66]]], [markerpos "6", markerpos "7"]] call Pos_fnc3;


* _onroad:
0 - roads should not be
1 - anyway
2 - only on the road
3 - the road should not be, but within the radius from the road
4 - way shall be valid or radius from the road.
5 - roads should not be and min radius from the road where there should be + radius from the road where you can place
6 - the road should not be the radius of the road where there should be
*/

#define cn !(isOnRoad _testPos)
#define ucn (isOnRoad _testPos)
#define tn (count (_testPos nearRoads _xr) == 0)
#define utn (count (_testPos nearRoads _xr) > 0)
#define uctn (count (_testPos nearRoads _xrm) > 0)
#define mn (count (nearestObjects [ _testPos , _neartype, _xdistance]) == 0)
#define sw (surfaceIsWater _testPos)

scopeName "main";

private["_type","_count","_marker","_radius","_minDistance","_minradius","_maxradius","_minGradient","_maxGradient","_gradientRadius","_onShore","_onroad",
       "_xr","_xc","_xrm","_posfind","_neartype","_xdistance","_damage","_typecount","_unittype","_xradius","_xGradient", "_xcountx","_cnt","_isFlat","_poss","_veh"];

_pos = _this select 0;      // the search center placement of the object
_minDist = ((_this select 1) select 0);  //the minimum distance search positions
_maxDist = ((_this select 1) select 1); //the maximum distance search positions
_minDistance = _this select 2;                          // Minimal distance from another object >>>> https://community.bistudio.com/wiki/isFlatEmpty
_minradius = ((_this select 3) select 0);       // If 0, just check position. If >0, select new one (the minimum value of the parameter) >>>> https://community.bistudio.com/wiki/isFlatEmpty
_maxradius = ((_this select 3) select 1);       // If 0, just check position. If >0, select new one (the maximum value of the parameter _minradius )
_minGradient=((_this select 4) select 0);   // Max gradient (the minimum value of the parameter) >>>> https://community.bistudio.com/wiki/isFlatEmpty
_maxGradient=((_this select 4) select 1);   // Max gradient (the maximum value of the parameter _minGradient)
_gradientRadius = _this select 5;                       // Gradient area >>>> https://community.bistudio.com/wiki/isFlatEmpty 
_waterMode=((_this select 6) select 0); //0 for restricted water, 2 for required water, >>>> https://community.bistudio.com/wiki/isFlatEmpty
_onShore=((_this select 6) select 1);                           //True if some water can be in 25m radius  >>>> https://community.bistudio.com/wiki/isFlatEmpty
_onroad=((_this select 7) select 0);           // 6 values, read above
_xr=((_this select 7) select 1);                // the first radius which is searched for the presence of roads (optional)
_xrm=((_this select 7) select 2);               //the second radius which is searched for the presence of roads (optional)
_neartype=((_this select 8) select 0);      // an array of objects near which, at a given distance from the object, you cannot put the object.
_xdistance=((_this select 8) select 1);     // distance to objects near which cannot be put we need the object(s).
_xc     = _this select 9; // specify the number of audits
_blacklist = [];   //(optional) blacklist (Array of Arrays): (_this select 10) select X: Top-left and bottom-right coordinates of blacklisted area (Array)
if ((count _this) > 10) then { _blacklist = _this select 10;}; // >>>> https://community.bistudio.com/wiki/BIS_fnc_findSafePos
_defaultPos = []; //_this select 11: (optional) default positions (Array of Arrays): 
                                                                                                                //     (_this select 8) select 0: default position on land (Array)
					                                                                 //     (_this select 8) select 1: default position on water (Array)
if ((count _this) > 11) then { _defaultPos = _this select 11;}; // >>>> https://community.bistudio.com/wiki/BIS_fnc_findSafePos

if (_waterMode == 2) then { _onroad = 7;}; //if water is required, disable the search of the road
[b]_debug = false;[/b] // enable/disable test
private ["_newPos", "_posX", "_posY"];
_newPos = [];
_posX = _pos select 0;
_posY = _pos select 1;

private ["_xcountx"];

_xradius = (_maxradius - _minradius) / _xc;
_xGradient = (_maxGradient - _minGradient) / _xc;
_xcountx = 0;
_isFlat = [];
while {_xcountx < _xc} do
{
       private ["_newX", "_newY", "_testPos"];
       _newX = _posX + (_maxDist - (random (_maxDist * 2)));
       _newY = _posY + (_maxDist - (random (_maxDist * 2)));
       _testPos = [_newX, _newY];

       if (!([_testPos, _blacklist] call BIS_fnc_isPosBlacklisted) && {(_pos distance _testPos) >= _minDist} && {!((count (_testPos isFlatEmpty [_minDistance, _minradius, _minGradient, _gradientRadius, 0, _onShore, objNull])) == 0)}) then
       {
               call
               {
                       if ((_onroad == 1) && {mn}) exitwith  
                       {
                               _newPos = _testPos;
[b]                                if (_debug) then
                               {
                                       //To create a marker for possible allocation
                                       _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                                       _debugMarker = createMarker [str(_newPos), _newPos];
                                       _debugMarker setMarkerShape "ICON";
                                       _debugMarker setMarkerType "mil_dot";
                                       _debugMarker setMarkerColor "ColorRed";
                               };[/b]
                               breakTo "main";
                       };
                       if ( (_onroad == 0) && {cn} && {tn} && {mn}) exitwith  
                       {
                               _newPos = _testPos;
                               if (_debug) then
                               {
                                       // To create a marker for possible allocation
                                       _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                                       _debugMarker = createMarker [str(_newPos), _newPos];
                                       _debugMarker setMarkerShape "ICON";
                                       _debugMarker setMarkerType "mil_dot";
                                       _debugMarker setMarkerColor "ColorRed";
                               };
                               breakTo "main";
                       };
                       if ( (_onroad == 2) && {ucn} && {mn}) exitwith  
                       {
                               _newPos = _testPos;
                               if (_debug) then
                               {
                                       // Создать маркер возможного размещениÑ
                                       _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                                       _debugMarker = createMarker [str(_newPos), _newPos];
                                       _debugMarker setMarkerShape "ICON";
                                       _debugMarker setMarkerType "mil_dot";
                                       _debugMarker setMarkerColor "ColorRed";
                               };
                               breakTo "main";
                       };
                       if ( (_onroad == 3) && {cn} && {utn} && {mn}) exitwith  
                       {
                               _newPos = _testPos;
                               if (_debug) then
                               {
                                       // Создать маркер возможного размещениÑ
                                       _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                                       _debugMarker = createMarker [str(_newPos), _newPos];
                                       _debugMarker setMarkerShape "ICON";
                                       _debugMarker setMarkerType "mil_dot";
                                       _debugMarker setMarkerColor "ColorRed";
                               };
                               breakTo "main";
                       };
                       if ( (_onroad == 4) && {( ucn || {utn})} && {mn}) exitwith  
                       {
                               _newPos = _testPos;
                               if (_debug) then
                               {
                                       // Создать маркер возможного размещениÑ
                                       _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                                       _debugMarker = createMarker [str(_newPos), _newPos];
                                       _debugMarker setMarkerShape "ICON";
                                       _debugMarker setMarkerType "mil_dot";
                                       _debugMarker setMarkerColor "ColorRed";
                               };
                               breakTo "main";
                       };
                       if ( (_onroad == 5) && {cn} && {tn} && {uctn} && {mn}) exitwith  
                       {
                               _newPos = _testPos;
                               if (_debug) then
                               {
                                       // Создать маркер возможного размещениÑ
                                       _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                                       _debugMarker = createMarker [str(_newPos), _newPos];
                                       _debugMarker setMarkerShape "ICON";
                                       _debugMarker setMarkerType "mil_dot";
                                       _debugMarker setMarkerColor "ColorRed";
                               };
                               breakTo "main";
                       };
                       if ( (_onroad == 6) && {cn} && {tn} && {mn}) exitwith  
                       {
                               _newPos = _testPos;
                               if (_debug) then
                               {
                                       // Создать маркер возможного размещениÑ
                                       _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                                       _debugMarker = createMarker [str(_newPos), _newPos];
                                       _debugMarker setMarkerShape "ICON";
                                       _debugMarker setMarkerType "mil_dot";
                                       _debugMarker setMarkerColor "ColorRed";
                               };
                               breakTo "main";
                       };
               };
       };
       _xcountx = _xcountx + 1;
       _minradius = _minradius + _xradius;
       _minGradient = _minGradient + _xGradient;
};

if ((count _newPos) == 0) then
{
       if (_waterMode == 0) then
       {
               if ((count _defaultPos) > 0) then
               {
                       _newPos = _defaultPos select 0;
                       if (_debug) then
                       {
                               // Создать маркер возможного размещениÑ
                               _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                               _debugMarker = createMarker [str(_newPos), _newPos];
                               _debugMarker setMarkerShape "ICON";
                               _debugMarker setMarkerType "mil_dot";
                               _debugMarker setMarkerColor "ColorRed";
                       };
               }
               else
               {
                       //Use world Armory default position:
                       _newPos = getArray(configFile >> "CfgWorlds" >> worldName >> "Armory" >> "positionStart");
                       if (_debug) then
                       {
                               // Создать маркер возможного размещениÑ
                               _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                               _debugMarker = createMarker [str(_newPos), _newPos];
                               _debugMarker setMarkerShape "ICON";
                               _debugMarker setMarkerType "mil_dot";
                               _debugMarker setMarkerColor "ColorRed";
                       };
               };
       }
       else
       {
               if ((count _defaultPos) > 1) then
               {
                       _newPos = _defaultPos select 1;
                       if (_debug) then
                       {
                               // Создать маркер возможного размещениÑ
                               _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                               _debugMarker = createMarker [str(_newPos), _newPos];
                               _debugMarker setMarkerShape "ICON";
                               _debugMarker setMarkerType "mil_dot";
                               _debugMarker setMarkerColor "ColorRed";
                       };
               }
               else
               {
                       //Use world Armory default water position:
                       _newPos = getArray(configFile >> "CfgWorlds" >> worldName >> "Armory" >> "positionStartWater");
                       if (_debug) then
                       {
                               // Создать маркер возможного размещениÑ
                               _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
                               _debugMarker = createMarker [str(_newPos), _newPos];
                               _debugMarker setMarkerShape "ICON";
                               _debugMarker setMarkerType "mil_dot";
                               _debugMarker setMarkerColor "ColorRed";
                       };
               };
       };
};

if ((count _newPos) == 0) then
{
       //Still nothing was found, use world center positions.
       _newPos = getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition");
       if (_debug) then
       {
               // Создать маркер возможного размещениÑ
               _dummy = createVehicle ["Sign_sphere25cm_EP1", _newPos, [], 0, "NONE"];
               _debugMarker = createMarker [str(_newPos), _newPos];
               _debugMarker setMarkerShape "ICON";
               _debugMarker setMarkerType "mil_dot";
               _debugMarker setMarkerColor "ColorRed";
       };
};

_newPos

POS_FNC3 2 in1

Pos_fnc4

=======================================================

Pos_fnc6

The function of the search positions with a variety of additional conditions

Returns:

Array - format PositionATL

/*
* Pos_fnc6.sqf

*       Author: Dimon UA

*
Description:
       The function of the search positions with a variety of additional conditions

*
Example:
       arx=[getmarkerpos "m2", [1000,1200], 0.1, [0, 0], [10, 10], 0.1, [0,false], [2,objNull, objNull], [["Static"],20],3000] call Pos_fnc6;


* _onroad:
[0,objNull,objNull] - дороги не должно быть
[1,objNull,objNull] - вÑе равно
[2,objNull,objNull] - только на дороге
[3,20,objNull] - дороги не должно быть, но в пределах Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги
[4,20,objNull] - дорога должна быть или допуÑтимый Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги.
[5,20,60] - дороги не должно быть и мин Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где не должно быть, + Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где можно размеÑтить
[6,40,objNull] - дороги не должно быть и Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где не должно быть

Returns:
Array - format PositionATL
*/

#define cn !(isOnRoad _testPos)
#define ucn (isOnRoad _testPos)
#define tn (count (_testPos nearRoads _xr) == 0)
#define utn (count (_testPos nearRoads _xr) > 0)
#define uctn (count (_testPos nearRoads _xrm) > 0)
#define mn (count (nearestObjects [ _testPos , _neartype, _xdistance]) == 0)
#define sw (surfaceIsWater _testPos)

//scopeName "main";

private["_type","_count","_marker","_radius","_minDistance","_minradius","_maxrad ius","_minGradient","_maxGradient","_gradientRadius","_onShore","_onroad",
       "_xr","_xc","_xrm","_posfind","_neartype","_xdistance","_damage","_typecount","_ unittype","_xradius","_xGradient", "_xcountx","_cnt","_isFlat","_poss","_veh"];

_pos = _this select 0;      // центр радиуÑа Ñ€Ð°Ð·Ð¼ÐµÑ‰ÐµÐ½Ð¸Ñ Ð¾Ð±ÑŒÐµÐºÑ‚Ð°
_minDist = ((_this select 1) select 0);
_maxDist = ((_this select 1) select 1);
_minDistance = _this select 2;                          // минимально допуÑÑ‚Ð¸Ð¼Ð°Ñ Ð´Ð¸ÑÑ‚Ð°Ð½Ñ†Ð¸Ñ Ð´Ð¾ ближайшего объекта. 0 - по дефолту
_minradius = ((_this select 3) select 0);       // минимальный Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¿Ð¾Ð¸Ñка площадки вокруг обьекта
_maxradius = ((_this select 3) select 1);       // макÑимальный Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¿Ð¾Ð¸Ñка площадки вокруг обьекта
_minGradient=((_this select 4) select 0);   // минимальное значение макÑимального допуÑтимого наклона (разница выÑот) площадки
_maxGradient=((_this select 4) select 1);   // макÑимальное значение макÑимального допуÑтимого наклона (разница выÑот) площадки
_gradientRadius = _this select 5;                       // Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾ÐºÑ€ÑƒÐ¶Ð½Ð¾Ñти, в пределах которой учитываетÑÑ _minGradient
_waterMode=((_this select 6) select 0);
_onShore=((_this select 6) select 1);                           // true еÑли необходима вода в радиуÑе 25 метров
_onroad=((_this select 7) select 0);          
_xr=((_this select 7) select 1);                // 1 Ñ€Ð°Ð´Ð¸ÑƒÑ Ð² котором ищетÑÑ Ð½Ð°Ð»Ð¸Ñ‡Ð¸Ðµ дороги.
_xrm=((_this select 7) select 2);               // 2 Ñ€Ð°Ð´Ð¸ÑƒÑ Ð² котором ищетÑÑ Ð½Ð°Ð»Ð¸Ñ‡Ð¸Ðµ дороги.
_neartype=((_this select 8) select 0);      // маÑÑив обьектов возле которых при заданной диÑтанции от обьекта Ð½ÐµÐ»ÑŒÐ·Ñ Ñтавить обьект.
_xdistance=((_this select 8) select 1);     // диÑÑ‚Ð°Ð½Ñ†Ð¸Ñ Ð´Ð¾ обьектов возле которых Ð½ÐµÐ»ÑŒÐ·Ñ Ñтавить нужный нам обьект(Ñ‹).
_xc     = _this select 9; // кол-во проверок позиций
_blacklist = [];
if ((count _this) > 10) then { _blacklist = _this select 10;};

if (_waterMode == 2) then { _onroad = 7;};
//_debug = false;
_debug = false;
private ["_newPos", "_posX", "_posY"];
_newPos = [];
_posX = _pos select 0;
_posY = _pos select 1;

private ["_xcountx"];

_xradius = (_maxradius - _minradius) / _xc;
_xGradient = (_maxGradient - _minGradient) / _xc;
_xcountx = 0;
_array = [];
for "_xcountx" from 1 to _xc step 1 do
{
       private ["_newX", "_newY", "_testPos"];
       _newX = _posX + (_maxDist - (random (_maxDist * 2)));
       _newY = _posY + (_maxDist - (random (_maxDist * 2)));
       _testPos = [_newX, _newY];

       if (!([_testPos, _blacklist] call BIS_fnc_isPosBlacklisted) && {(_pos distance _testPos) >= _minDist} && {!((count (_testPos isFlatEmpty [_minDistance, _minradius, _minGradient, _gradientRadius, 0, _onShore, objNull])) == 0)}) then
       {
               call
               {
                       if ((_onroad == 1) && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 0) && {cn} && {tn} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 2) && {ucn} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 3) && {cn} && {utn} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 4) && {( ucn || {utn})} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 5) && {cn} && {tn} && {uctn} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 6) && {cn} && {tn} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
               };
       };
       _minradius = _minradius + _xradius;
       _minGradient = _minGradient + _xGradient;
};
if _debug then
{
       {
               call compile format ["
                       _m%1 = createMarker[""markerblue%1"",[ _x select 0,_x select 1]];
                       _m%1 setMarkerShape ""ICON"";
                       _m%1 setMarkerType ""DOT"";
                       _m%1 setmarkercolor ""Colorblue"";  ",_forEachIndex];
       } foreach _array;
};
_array

Pos_fnc6

====================================================

fnc_spiral

Ðвтор: ArseniyK

Creating a spiral grid positions added in one array

Parameter(s):

_this select 0: position (Array)

_this select 1: шаг (Number)

(_this select 2) select 0: min radius

(_this select 2) select 1:max radius

/*
       File: fnc_spiral.sqf
       Author: ArseniyK

       Description:
       Creating spiral

       Parameter(s):
       _this select 0: position (Array)
       _this select 1: step (Number)
       (_this select 2) select 0: min radius (Number)
       (_this select 2) select 1: max radius

       Returns:
       Array - format PositionASL
*/
private ["_pos","_step","_minrad","_maxrad","_posx","_a","_posy","_x","_y","_arr","_debug     ","_r","_tx","_ty","_len","_k"];

_pos = _this select 0;
_step = _this select 1;
_minrad = (_this select 2) select 0;
_maxrad = (_this select 2) select 1;
_debug = false;
//=============Creating spiral=============//
step = _step;
_a = -0.3* step;
_posx = _pos select 0;
_posy = _pos select 1;
_x = _minrad;
_y = 1;
_arr=[];
for [{_i=0},{true},{_i=_i+1}] do
{
       _r = sqrt (_x*_x+_y*_y);
       _tx = _a*_x+_r*_y;
       _ty = _a*_y - _r*_x;
       _len = sqrt(_tx*_tx + _ty*_ty);
       _k = step/_len;
       _x = _x + _tx*_k;
       _y = _y + _ty*_k;
       _arr set [_i,[_x+_posx,_y+_posy,getTerrainHeightASL [_x+_posx, _y+_posy]]];
       if (((ASLToATL (_arr select _i)) distance _pos) >= _maxrad) exitwith {};
};
if _debug then
{
       {
               call compile format ["
                       _m%1 = createMarker[""markerRed%1"",[ _x select 0,_x select 1]];
                       _m%1 setMarkerShape ""ICON"";
                       _m%1 setMarkerType ""DOT"";
                       _m%1 setmarkercolor ""Colorred"";  ",_forEachIndex];
       } foreach _arr;
};
_arr

fnc_spiral

============================================

Pos_fnc7

Description:

The function of the search positions with a variety of additional conditions

/*
* Pos_fnc7.sqf

*       Author: Dimon UA

*
Description:
       The function of the search positions with a variety of additional conditions

*
Example:
       arx=[arrays,[4, 50, 60], [["Static"],20]] call POS_FNC7;


* _onroad:
[0,objNull,objNull] - дороги не должно быть
[1,objNull,objNull] - вÑе равно
[2,objNull,objNull] - только на дороге
[3,20,objNull] - дороги не должно быть, но в пределах Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги
[4,20,objNull] - дорога должна быть или допуÑтимый Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги.
[5,20,60] - дороги не должно быть и мин Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где не должно быть, + Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где можно размеÑтить
[6,40,objNull] - дороги не должно быть и Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где не должно быть

Returns:
Array - format PositionATL
*/

#define cn !(isOnRoad _testPos)
#define ucn (isOnRoad _testPos)
#define tn (count (_testPos nearRoads _xr) == 0)
#define utn (count (_testPos nearRoads _xr) > 0)
#define uctn (count (_testPos nearRoads _xrm) > 0)
#define mn (count (nearestObjects [ _testPos , _neartype, _xdistance]) == 0)
#define sw (surfaceIsWater _testPos)

private["_ar","_onroad","_xr","_xrm","_neartype","_xdistance","_newPos","_testPos  ","_arx","_debug","_i"];

_ar = _this select 0; //arrays
_onroad=((_this select 1) select 0);          
_xr=((_this select 1) select 1);                // 1 Ñ€Ð°Ð´Ð¸ÑƒÑ Ð² котором ищетÑÑ Ð½Ð°Ð»Ð¸Ñ‡Ð¸Ðµ дороги.
_xrm=((_this select 1) select 2);
_neartype=((_this select 2) select 0);      // маÑÑив обьектов возле которых при заданной диÑтанции от обьекта Ð½ÐµÐ»ÑŒÐ·Ñ Ñтавить обьект.
_xdistance=((_this select 2) select 1);     // диÑÑ‚Ð°Ð½Ñ†Ð¸Ñ Ð´Ð¾ обьектов возле которых Ð½ÐµÐ»ÑŒÐ·Ñ Ñтавить нужный нам обьект(Ñ‹).
_debug =false;// debug

_arx = [];
for "_i" from 0 to (count _ar) -1 do
{
       _testPos = ASLToATL (_ar select _i);
       call
       {
               if ((_onroad == 1) && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 0) && {cn} && {tn} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 2) && {ucn} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 3) && {cn} && {utn} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 4) && {( ucn || {utn})} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 5) && {cn} && {tn} && {uctn} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 6) && {cn} && {tn} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
       };
};
if _debug then
{
       {
               call compile format ["
                       _m%1 = createMarker[""markerblack%1"",[ _x select 0,_x select 1]];
                       _m%1 setMarkerShape ""ICON"";
                       _m%1 setMarkerType ""DOT"";
                       _m%1 setmarkercolor ""Colorblack"";  ",_forEachIndex];
       } foreach _arx;
};
_arx

Pos_fnc7

This method search (fnc_spiral+Pos_fnc7) showed the best result in speed in comparison with the previous variant functions Pos_fnc6 and produces several times more array in the result.

Edited by Dimon

Share this post


Link to post
Share on other sites

small optimization

/*
* Pos_fnc3.sqf
* POS_FNC3 = compile preprocessFile "Pos_fnc3.sqf";
* Dimon UA Find position SCRIPT 3.
*
* пример:
   _spawnpoint=[position, [800,1300], 0.1, [0, 100], [10, 10], 0.1, [0,false], [4, 50, 60], [["Static"],20],150] call Pos_fnc3;

* _onroad:
 0 - дороги не должно быть
 1 - вÑе равно
 2 - только на дороге
 3 - дороги не должно быть, но в пределах Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги
 4 - дорога должна быть или допуÑтимый Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги.
 5 - дороги не должно быть и мин Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где не должно быть, + Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где можно размеÑтить
 6 - дороги не должно быть и Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где не должно быть
*/

#define cn !(isOnRoad _testPos)
#define ucn (isOnRoad _testPos)
#define tn (count (_testPos nearRoads _xr) == 0)
#define utn (count (_testPos nearRoads _xr) > 0)
#define uctn (count (_testPos nearRoads _xrm) > 0)
#define mn (count (nearestObjects [ _testPos , _neartype, _xdistance]) == 0)
#define sw (surfaceIsWater _testPos)

scopeName "main";

private["_type","_count","_marker","_radius","_minDistance","_minradius","_maxradius","_minGradient","_maxGradient","_gradientRadius","_onShore","_onroad",
       "_xr","_xc","_xrm","_posfind","_neartype","_xdistance","_damage","_typecount","_unittype","_xradius","_xGradient", "_xcountx","_cnt","_isFlat","_poss","_veh"];

_pos = _this select 0;      // центр радиуÑа Ñ€Ð°Ð·Ð¼ÐµÑ‰ÐµÐ½Ð¸Ñ Ð¾Ð±ÑŒÐµÐºÑ‚Ð°
_minDist = ((_this select 1) select 0);
_maxDist = ((_this select 1) select 1);
_minDistance = _this select 2;                 // минимально допуÑÑ‚Ð¸Ð¼Ð°Ñ Ð´Ð¸ÑÑ‚Ð°Ð½Ñ†Ð¸Ñ Ð´Ð¾ ближайшего объекта. 0 - по дефолту
_minradius = ((_this select 3) select 0);      // минимальный Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¿Ð¾Ð¸Ñка площадки вокруг обьекта
_maxradius = ((_this select 3) select 1);     // макÑимальный Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¿Ð¾Ð¸Ñка площадки вокруг обьекта
_minGradient=((_this select 4) select 0);   // минимальное значение макÑимального допуÑтимого наклона (разница выÑот) площадки
_maxGradient=((_this select 4) select 1);   // макÑимальное значение макÑимального допуÑтимого наклона (разница выÑот) площадки
_gradientRadius = _this select 5;              // Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾ÐºÑ€ÑƒÐ¶Ð½Ð¾Ñти, в пределах которой учитываетÑÑ _minGradient
_waterMode=((_this select 6) select 0);
_onShore=((_this select 6) select 1);                      // true еÑли необходима вода в радиуÑе 25 метров
_onroad=((_this select 7) select 0);      
_xr=((_this select 7) select 1);         // 1 Ñ€Ð°Ð´Ð¸ÑƒÑ Ð² котором ищетÑÑ Ð½Ð°Ð»Ð¸Ñ‡Ð¸Ðµ дороги.
_xrm=((_this select 7) select 2);         // 2 Ñ€Ð°Ð´Ð¸ÑƒÑ Ð² котором ищетÑÑ Ð½Ð°Ð»Ð¸Ñ‡Ð¸Ðµ дороги.
_neartype=((_this select 8) select 0);      // маÑÑив обьектов возле которых при заданной диÑтанции от обьекта Ð½ÐµÐ»ÑŒÐ·Ñ Ñтавить обьект.
_xdistance=((_this select 8) select 1);     // диÑÑ‚Ð°Ð½Ñ†Ð¸Ñ Ð´Ð¾ обьектов возле которых Ð½ÐµÐ»ÑŒÐ·Ñ Ñтавить нужный нам обьект(Ñ‹).
_xc    = _this select 9; // кол-во проверок позиций
_blacklist = [];
if ((count _this) > 10) then { _blacklist = _this select 10;};
_defaultPos = [];
if ((count _this) > 11) then { _defaultPos = _this select 11;};

if (_waterMode == 2) then { _onroad = 7;};

private ["_newPos", "_posX", "_posY"];
_newPos = [];
_posX = _pos select 0;
_posY = _pos select 1;

private ["_xcountx"];

_xradius = (_maxradius - _minradius) / _xc;
_xGradient = (_maxGradient - _minGradient) / _xc;
_xcountx = 0;
_isFlat = [];
while {_xcountx < _xc} do
{
   sleep 0.01;
   private ["_newX", "_newY", "_testPos"];
   _newX = _posX + (_maxDist - (random (_maxDist * 2)));
   _newY = _posY + (_maxDist - (random (_maxDist * 2)));
   _testPos = [_newX, _newY];

   if (!([_testPos, _blacklist] call BIS_fnc_isPosBlacklisted) && {(_pos distance _testPos) >= _minDist} && {!((count (_testPos isFlatEmpty [_minDistance, _minradius, _minGradient, _gradientRadius, 0, _onShore, objNull])) == 0)}) then
   {
       call
       {
           if ((_onroad == 1) && {mn}) exitwith
           {
               _newPos = _testPos;
               breakTo "main";
           };
           if ( (_onroad == 0) && {cn} && {tn} && {mn}) exitwith
           {
               _newPos = _testPos;
               breakTo "main";
           };
           if ( (_onroad == 2) && {ucn} && {mn}) exitwith
           {
               _newPos = _testPos;
               breakTo "main";
           };
           if ( (_onroad == 3) && {cn} && {utn} && {mn}) exitwith
           {
               _newPos = _testPos;
               breakTo "main";
           };
           if ( (_onroad == 4) && {( ucn || {utn})} && {mn}) exitwith
           {
               _newPos = _testPos;
               breakTo "main";
           };
           if ( (_onroad == 5) && {cn} && {tn} && {uctn} && {mn}) exitwith
           {
               _newPos = _testPos;
               breakTo "main";
           };
           if ( (_onroad == 6) && {cn} && {tn} && {mn}) exitwith
           {
               _newPos = _testPos;
               breakTo "main";
           };
       };
   };
   _xcountx = _xcountx + 1;
   _minradius = _minradius + _xradius;
   _minGradient = _minGradient + _xGradient;
};

if ((count _newPos) == 0) then
{
   if (_waterMode == 0) then
   {
       if ((count _defaultPos) > 0) then
       {
           _newPos = _defaultPos select 0;
       }
       else
       {
           //Use world Armory default position:
           _newPos = getArray(configFile >> "CfgWorlds" >> worldName >> "Armory" >> "positionStart");
       };
   }
   else
   {
       if ((count _defaultPos) > 1) then
       {
           _newPos = _defaultPos select 1;
       }
       else
       {
           //Use world Armory default water position:
           _newPos = getArray(configFile >> "CfgWorlds" >> worldName >> "Armory" >> "positionStartWater");
       };
   };
};

if ((count _newPos) == 0) then
{
   //Still nothing was found, use world center positions.
   _newPos = getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition");
};

_newPos

POS_FNC3

Share this post


Link to post
Share on other sites

First off, good job taking the time to develop this.

Now, how about some constructive criticism?

I don't read Russian, So it's hard to figure out what exactly you require for array elements, or optional elements.

You should really look into similar technique as ruebe, or others who use selection via key and element. With 12 possible elements, I need a guide handy to figure out what each one was for(after I learn Russian).

One quick question is about the default position.

It is initialized as an array:

_defaultPos = [];

if ((count _this) > 11) then { _defaultPos = _this select 11;};

but then:

if (_waterMode == 0) then
   {
       if (([color="#FF0000"]count _defaultPos[/color]) > 0) then
       {
           _newPos = [color="#FF0000"]_defaultPos select 0;[/color]
       }
       else
       {
           //Use world Armory default position:
           _newPos = getArray(configFile >> "CfgWorlds" >> worldName >> "Armory" >> "positionStart");
       };
   }
   else
   {
       if (([color="#FF0000"]count _defaultPos[/color]) > 1) then
       {
           _newPos = [color="#FF0000"]_defaultPos select 1[/color];
       }
       else
       {
           //Use world Armory default water position:
           _newPos = getArray(configFile >> "CfgWorlds" >> worldName >> "Armory" >> "positionStartWater");
       };
   };

So my default position must be an array of an array(s)? Otherwise, if I just pass getMarkerPos "whatever", that may count to more than 0... returns [5850.45,11121.5,-0.0307541]. That counts 3, but will fail in the code, because it's not an array of array.

More explanation in the first post may have drawn more attention. But like I stated earlier, having 12 elements, of which it looks like 10 are required, will deter most.

Again, I don't mean to upset you, just some food for thought.

Share this post


Link to post
Share on other sites

Changelog:

2 in 1: test and main functions

POS_FNC3 2 in1

The programming language does not require translation, for everything else there's Google translate.

Updated the first post.

Share this post


Link to post
Share on other sites

optimization

Pos_fnc4

while {_xcountx < _xc} do {

on

for "_xcountx" from 1 to _xc step 1 do {

github

Share this post


Link to post
Share on other sites

Preview.

1.The highest point in a given perimeter:

http://i59.fastpic.ru/big/2015/0122/13/001dda4ddc2af2d4e616625dca7c0b13.jpg (619 kB)

2.The lowest point

http://i59.fastpic.ru/big/2015/0122/1e/2589b8ba1992eb3a7bdcb76d069e431e.jpg (621 kB)

3.For additional terms and conditions... for example the highest with an unimpeded view to the center of the perimeter:

http://i64.fastpic.ru/big/2015/0122/aa/1f45b62a53bb5901afa33ab0ca3a4aaa.jpg (627 kB)

Share this post


Link to post
Share on other sites

Pos_fnc6

The function of the search positions with a variety of additional conditions

Returns:

Array - format PositionATL

/*
* Pos_fnc6.sqf

*       Author: Dimon UA

*
Description:
       The function of the search positions with a variety of additional conditions

*
Example:
       arx=[getmarkerpos "m2", [1000,1200], 0.1, [0, 0], [10, 10], 0.1, [0,false], [2,objNull, objNull], [["Static"],20],3000] call Pos_fnc6;


* _onroad:
[0,objNull,objNull] - дороги не должно быть
[1,objNull,objNull] - вÑе равно
[2,objNull,objNull] - только на дороге
[3,20,objNull] - дороги не должно быть, но в пределах Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги
[4,20,objNull] - дорога должна быть или допуÑтимый Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги.
[5,20,60] - дороги не должно быть и мин Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где не должно быть, + Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где можно размеÑтить
[6,40,objNull] - дороги не должно быть и Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где не должно быть

Returns:
Array - format PositionATL
*/

#define cn !(isOnRoad _testPos)
#define ucn (isOnRoad _testPos)
#define tn (count (_testPos nearRoads _xr) == 0)
#define utn (count (_testPos nearRoads _xr) > 0)
#define uctn (count (_testPos nearRoads _xrm) > 0)
#define mn (count (nearestObjects [ _testPos , _neartype, _xdistance]) == 0)
#define sw (surfaceIsWater _testPos)

//scopeName "main";

private["_type","_count","_marker","_radius","_minDistance","_minradius","_maxrad ius","_minGradient","_maxGradient","_gradientRadius","_onShore","_onroad",
       "_xr","_xc","_xrm","_posfind","_neartype","_xdistance","_damage","_typecount","_ unittype","_xradius","_xGradient", "_xcountx","_cnt","_isFlat","_poss","_veh"];

_pos = _this select 0;      // центр радиуÑа Ñ€Ð°Ð·Ð¼ÐµÑ‰ÐµÐ½Ð¸Ñ Ð¾Ð±ÑŒÐµÐºÑ‚Ð°
_minDist = ((_this select 1) select 0);
_maxDist = ((_this select 1) select 1);
_minDistance = _this select 2;                          // минимально допуÑÑ‚Ð¸Ð¼Ð°Ñ Ð´Ð¸ÑÑ‚Ð°Ð½Ñ†Ð¸Ñ Ð´Ð¾ ближайшего объекта. 0 - по дефолту
_minradius = ((_this select 3) select 0);       // минимальный Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¿Ð¾Ð¸Ñка площадки вокруг обьекта
_maxradius = ((_this select 3) select 1);       // макÑимальный Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¿Ð¾Ð¸Ñка площадки вокруг обьекта
_minGradient=((_this select 4) select 0);   // минимальное значение макÑимального допуÑтимого наклона (разница выÑот) площадки
_maxGradient=((_this select 4) select 1);   // макÑимальное значение макÑимального допуÑтимого наклона (разница выÑот) площадки
_gradientRadius = _this select 5;                       // Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾ÐºÑ€ÑƒÐ¶Ð½Ð¾Ñти, в пределах которой учитываетÑÑ _minGradient
_waterMode=((_this select 6) select 0);
_onShore=((_this select 6) select 1);                           // true еÑли необходима вода в радиуÑе 25 метров
_onroad=((_this select 7) select 0);          
_xr=((_this select 7) select 1);                // 1 Ñ€Ð°Ð´Ð¸ÑƒÑ Ð² котором ищетÑÑ Ð½Ð°Ð»Ð¸Ñ‡Ð¸Ðµ дороги.
_xrm=((_this select 7) select 2);               // 2 Ñ€Ð°Ð´Ð¸ÑƒÑ Ð² котором ищетÑÑ Ð½Ð°Ð»Ð¸Ñ‡Ð¸Ðµ дороги.
_neartype=((_this select 8) select 0);      // маÑÑив обьектов возле которых при заданной диÑтанции от обьекта Ð½ÐµÐ»ÑŒÐ·Ñ Ñтавить обьект.
_xdistance=((_this select 8) select 1);     // диÑÑ‚Ð°Ð½Ñ†Ð¸Ñ Ð´Ð¾ обьектов возле которых Ð½ÐµÐ»ÑŒÐ·Ñ Ñтавить нужный нам обьект(Ñ‹).
_xc     = _this select 9; // кол-во проверок позиций
_blacklist = [];
if ((count _this) > 10) then { _blacklist = _this select 10;};

if (_waterMode == 2) then { _onroad = 7;};
//_debug = false;
_debug = false;
private ["_newPos", "_posX", "_posY"];
_newPos = [];
_posX = _pos select 0;
_posY = _pos select 1;

private ["_xcountx"];

_xradius = (_maxradius - _minradius) / _xc;
_xGradient = (_maxGradient - _minGradient) / _xc;
_xcountx = 0;
_array = [];
for "_xcountx" from 1 to _xc step 1 do
{
       private ["_newX", "_newY", "_testPos"];
       _newX = _posX + (_maxDist - (random (_maxDist * 2)));
       _newY = _posY + (_maxDist - (random (_maxDist * 2)));
       _testPos = [_newX, _newY];

       if (!([_testPos, _blacklist] call BIS_fnc_isPosBlacklisted) && {(_pos distance _testPos) >= _minDist} && {!((count (_testPos isFlatEmpty [_minDistance, _minradius, _minGradient, _gradientRadius, 0, _onShore, objNull])) == 0)}) then
       {
               call
               {
                       if ((_onroad == 1) && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 0) && {cn} && {tn} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 2) && {ucn} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 3) && {cn} && {utn} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 4) && {( ucn || {utn})} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 5) && {cn} && {tn} && {uctn} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
                       if ( (_onroad == 6) && {cn} && {tn} && {mn}) exitwith
                       {
                               _newPos = _testPos;
                               _array set [count _array, _newPos];
                       };
               };
       };
       _minradius = _minradius + _xradius;
       _minGradient = _minGradient + _xGradient;
};
if _debug then
{
       {
               call compile format ["
                       _m%1 = createMarker[""markerblue%1"",[ _x select 0,_x select 1]];
                       _m%1 setMarkerShape ""ICON"";
                       _m%1 setMarkerType ""DOT"";
                       _m%1 setmarkercolor ""Colorblue"";  ",_forEachIndex];
       } foreach _array;
};
_array

Pos_fnc6

====================================================

fnc_spiral

Ðвтор: ArseniyK

Creating a spiral grid positions added in one array

Parameter(s):

_this select 0: position (Array)

_this select 1: шаг (Number)

(_this select 2) select 0: min radius

(_this select 2) select 1:max radius

/*
       File: fnc_spiral.sqf
       Author: ArseniyK

       Description:
       Creating spiral

       Parameter(s):
       _this select 0: position (Array)
       _this select 1: step (Number)
       (_this select 2) select 0: min radius (Number)
       (_this select 2) select 1: max radius

       Returns:
       Array - format PositionASL
*/
private ["_pos","_step","_minrad","_maxrad","_posx","_a","_posy","_x","_y","_arr","_debug     ","_r","_tx","_ty","_len","_k"];

_pos = _this select 0;
_step = _this select 1;
_minrad = (_this select 2) select 0;
_maxrad = (_this select 2) select 1;
_debug = false;
//=============Creating spiral=============//
step = _step;
_a = -0.3* step;
_posx = _pos select 0;
_posy = _pos select 1;
_x = _minrad;
_y = 1;
_arr=[];
for [{_i=0},{true},{_i=_i+1}] do
{
       _r = sqrt (_x*_x+_y*_y);
       _tx = _a*_x+_r*_y;
       _ty = _a*_y - _r*_x;
       _len = sqrt(_tx*_tx + _ty*_ty);
       _k = step/_len;
       _x = _x + _tx*_k;
       _y = _y + _ty*_k;
       _arr set [_i,[_x+_posx,_y+_posy,getTerrainHeightASL [_x+_posx, _y+_posy]]];
       if (((ASLToATL (_arr select _i)) distance _pos) >= _maxrad) exitwith {};
};
if _debug then
{
       {
               call compile format ["
                       _m%1 = createMarker[""markerRed%1"",[ _x select 0,_x select 1]];
                       _m%1 setMarkerShape ""ICON"";
                       _m%1 setMarkerType ""DOT"";
                       _m%1 setmarkercolor ""Colorred"";  ",_forEachIndex];
       } foreach _arr;
};
_arr

fnc_spiral

============================================

Pos_fnc7

Description:

The function of the search positions with a variety of additional conditions

/*
* Pos_fnc7.sqf

*       Author: Dimon UA

*
Description:
       The function of the search positions with a variety of additional conditions

*
Example:
       arx=[arrays,[4, 50, 60], [["Static"],20]] call POS_FNC7;


* _onroad:
[0,objNull,objNull] - дороги не должно быть
[1,objNull,objNull] - вÑе равно
[2,objNull,objNull] - только на дороге
[3,20,objNull] - дороги не должно быть, но в пределах Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги
[4,20,objNull] - дорога должна быть или допуÑтимый Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги.
[5,20,60] - дороги не должно быть и мин Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где не должно быть, + Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где можно размеÑтить
[6,40,objNull] - дороги не должно быть и Ñ€Ð°Ð´Ð¸ÑƒÑ Ð¾Ñ‚ дороги где не должно быть

Returns:
Array - format PositionATL
*/

#define cn !(isOnRoad _testPos)
#define ucn (isOnRoad _testPos)
#define tn (count (_testPos nearRoads _xr) == 0)
#define utn (count (_testPos nearRoads _xr) > 0)
#define uctn (count (_testPos nearRoads _xrm) > 0)
#define mn (count (nearestObjects [ _testPos , _neartype, _xdistance]) == 0)
#define sw (surfaceIsWater _testPos)

private["_ar","_onroad","_xr","_xrm","_neartype","_xdistance","_newPos","_testPos  ","_arx","_debug","_i"];

_ar = _this select 0; //arrays
_onroad=((_this select 1) select 0);          
_xr=((_this select 1) select 1);                // 1 Ñ€Ð°Ð´Ð¸ÑƒÑ Ð² котором ищетÑÑ Ð½Ð°Ð»Ð¸Ñ‡Ð¸Ðµ дороги.
_xrm=((_this select 1) select 2);
_neartype=((_this select 2) select 0);      // маÑÑив обьектов возле которых при заданной диÑтанции от обьекта Ð½ÐµÐ»ÑŒÐ·Ñ Ñтавить обьект.
_xdistance=((_this select 2) select 1);     // диÑÑ‚Ð°Ð½Ñ†Ð¸Ñ Ð´Ð¾ обьектов возле которых Ð½ÐµÐ»ÑŒÐ·Ñ Ñтавить нужный нам обьект(Ñ‹).
_debug =false;// debug

_arx = [];
for "_i" from 0 to (count _ar) -1 do
{
       _testPos = ASLToATL (_ar select _i);
       call
       {
               if ((_onroad == 1) && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 0) && {cn} && {tn} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 2) && {ucn} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 3) && {cn} && {utn} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 4) && {( ucn || {utn})} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 5) && {cn} && {tn} && {uctn} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
               if ( (_onroad == 6) && {cn} && {tn} && {mn}) exitwith
               {
                       _newPos = _testPos;
                       _arx set [count _arx,_newPos];
               };
       };
};
if _debug then
{
       {
               call compile format ["
                       _m%1 = createMarker[""markerblack%1"",[ _x select 0,_x select 1]];
                       _m%1 setMarkerShape ""ICON"";
                       _m%1 setMarkerType ""DOT"";
                       _m%1 setmarkercolor ""Colorblack"";  ",_forEachIndex];
       } foreach _arx;
};
_arx

Pos_fnc7

This method search (fnc_spiral+Pos_fnc7) showed the best result in speed in comparison with the previous variant functions Pos_fnc6 and produces several times more array in the result.

Edited by Dimon

Share this post


Link to post
Share on other sites

Сonvert array of positions in the array with sub-arrays distributed according to the principle given distance,

in the picture example with the following parameters:

1. search for items only on the road

2. the radius from a point 1000-1200m

3.the radius of the sub-array 150m

4.must be >3 elements in sub-array

http://i63.fastpic.ru/big/2015/0127/8a/f83c4166daafe5bf03ef5b5512cf5a8a.png (665 kB)

[
[
	[5983.95,5524.77,0],[5988.4,5509.88,0],[5998.27,5502.11,0],[6007.52,5493.52,0],[6001.37,5485.63,0],[6099.22,5608.83,0],[6009.96,5476.22,0],[6092.36,5572.47,0],[6087.1,5563.96,0],[6017.9,5466,0],[6083.97,5535.82,0],[6025.17,5454.97,0],[6031.78,5443.14,0],[6091.78,5502.44,0],[6037.71,5430.52,0],[6097.51,5488.67,0],[6042.96,5417.11,0],[6102.59,5474.07,0],[6053.89,5410.62,0],[6057.77,5395.64,0]
],
[
	[5230.22,5127.53,0],[5232.62,5115.07,0],[5243.97,5103.09,0],[5253.56,5078.5,0],[5261.78,5066.48,0],[5268.95,5054.42,0],[5275.08,5042.31,0],[5294.19,5018.82,0],[5297.2,5006.5,0]
],
[
	[6154.12,5754.06,0],[6150.48,5744.75,0],[6146.75,5735.47,0],[6142.92,5726.23,0],[6139.01,5717.03,0],[6135.01,5707.86,0],[6118.3,5643.98,0],[6113.66,5635.12,0],[6108.93,5626.31,0],[6104.11,5617.55,0],[6126.92,5633.33,0],[6139.68,5630.61,0],[6151.95,5626.98,0],[6163.74,5622.42,0],[6190.44,5619.43,0],[6205.29,5621.02,0]
],
[
	[4267.91,5719.63,0],[4263.86,5728.77,0],[4255.15,5717.37,0],[4241.99,5716.06,0],[4228.42,5715.71,0],[4218.45,5707.16,0],[4204.06,5708.73,0],[4193.24,5702.09,0],[4182.01,5696.4,0],[4170.37,5691.67,0],[4158.31,5687.9,0],[4145.84,5685.08,0]
],
[
	[6191.13,5926.22,0],[6211.04,5966.15,0],[6209.43,5956.27,0],[6225.18,5975.57,0],[6239.06,5983.97,0],[6252.7,5991.35,0],[6278.25,5993.1,0],[6291.43,5997.39,0],[6316.21,5992.93,0]
],
[
	[4267.91,5719.63,0],[4263.86,5728.77,0],[4255.15,5717.37,0],[4241.99,5716.06,0],[4228.42,5715.71,0],[4218.45,5707.16,0],[4204.06,5708.73,0],[4193.24,5702.09,0],[4182.01,5696.4,0],[4170.37,5691.67,0],[4158.31,5687.9,0],[4145.84,5685.08,0]
]
]

an example of one sub-array

http://i66.fastpic.ru/big/2015/0127/ce/2eb1798956cf698a32590579973bd9ce.png (444 kB)

Edited by Dimon

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×