/*Part of the Multiple 'OnMapSingleClick' Command Handler
    v1.1     By General Barron

Used to add commands to the handler, then to remove them later if needed. Syntax of _this:
[{click code}, <time before removing>, <# of clicks>, <{click condition}>, <{end condition}>, <{remove code}>]

Returns the index of the added command (so extra data can be passed to it).
*/


private ["_code", "_delay", "_count", "_endcond", "_idx", "_remove_code", "_clickcond"];

//code to be executed on map click
_code = _this select 0;

//number of seconds to wait before removing code
//if nothing is specified, then code will never be removed
_delay = 0;
if (count _this > 1) then {_delay = _this select 1;};
if (_delay == 0) then {_delay = 10^99;};

//number of times map can be clicked before removing code
_count = 0;
if (count _this > 2) then {_count = _this select 2;};
if (_count == 0) then {_count = 10^99;};

//condition that must be met in order for click count (above) to be changed
_clickcond = {true};
if (count _this > 3) then {_clickcond = _this select 3;};

//additional condition that will disable command before delay is reached
_endcond = {true};
if (count _this > 4) then {_endcond = _this select 4;};

//code to be executed if command is removed automatically
_remove_code = {};
if (count _this > 5) then {_remove_code = _this select 5;};

//add command to handler
_idx = count GENB_mapclicks;
GENB_mapclicks = GENB_mapclicks + [[ _code, _count, _clickcond, [], _remove_code ]];

//run cleanup script if click has limited lifetime or has removal condition
if( !call _endcond || _delay > 0 ) then {[_idx, _delay, _endcond] exec "mapclick_removeCode.sqs";};

//return index of added command (so data can be passed)
_idx
