/*
 RANDOM_MINEFIELDS.SQF © Pumpkin
 ---------------------

 génére des champs de mines aléatoirement

 Paramètres:
 [nombre de champs de mine, position du pivot, rayon de placement] execVM "Minefields/random_Minefields.sqf"

*/

if (not isServer) exitwith {};
sleep 1;

_nbmf = _this select 0;
if (_nbmf < 1) then { _nbmf = 1 };

_pivot = _this select 1;

_rayon = _this select 2;
if (_rayon < 50) then { _rayon = 50 };

//_visibility = true;
//if (count _this > 3) then { _visibility = _this select 3 };

_camp = "WEST";
_visibility = true;

if (count _this > 3) then {
	_option = _this select 3;
	if (typename _option == "SIDE") then { _camp = str _option };
	if (typename _option == "BOOL") then { _visibility = _option };
};
if (count _this > 4) then {
	_option = _this select 4;
	if (typename _option == "SIDE") then { _camp = str _option };
	if (typename _option == "BOOL") then { _visibility = _option };
};


for [{_i = 0},{_i < _nbmf},{_i = _i + 1}] do {

	_surfX = (random 50) + 20;
	_surfY = (random 50) + 20;
	_ang = (random 36) * 10;
	_dist = (random (_rayon / 10)) * 10;
	_coordX = (_pivot select 0) + ((sin _ang) * _dist);
	_coordY = (_pivot select 1) + ((cos _ang) * _dist);
	_dirang = random 360;

	_mkname = "PUMPKINminefield_1";
	_mkcnt = 1;
	while {(markerShape _mkname) != ""} do {
		_mkcnt = _mkcnt + 1;
		_mkname = format ["PUMPKINminefield_%1",_mkcnt];
	};

	createMarker [_mkname, [_coordX, _coordY]];
	_mkname setMarkerShape "ELLIPSE";
	_mkname setMarkerBrush "DIAGGRID";
	_mkname setMarkerColor "ColorRed";
	if (_visibility) then {
		_mkname setMarkerSize [_surfX, _surfY];
	}
	else {
		_mkname setMarkerSize [_surfX / 10000, _surfY / 10000];
	};
	_mkname setMarkerPos [_coordX, _coordY];
	_mkname setMarkerDir _dirang;

	_minetrg = createTrigger["EmptyDetector",[_coordX,_coordY]];
	_minetrg setTriggerActivation[_camp,"PRESENT",true];
	_minetrg setTriggerTimeout [0,0,0,false];
	_minetrg setTriggerArea [_surfX,_surfY,_dirang,false];
	_minetrg setTriggerStatements ["this", "nul = [thislist,5,[""skeetdisk""]] execVM ""Minefields\Minefield.sqf""",""];
	_minetrg setTriggerType "NONE";

	sleep 0.1;
};