///////////////////////
////VARIABLES DECLARATION
///////////////////////
private ["_ca","_ta","_sa","_as","_i"];
_ca = nearestlocations [[0,0,0], ["namecitycapital"], 1*10^10];
_ta = nearestlocations [[0,0,0], ["namecity"], 1*10^10];
_sa = nearestlocations [[0,0,0], ["namevillage"], 1*10^10];
call {
private ["_c","_s"];
_c = (configfile >> "cfgworlds" >> worldname);
_s = getarray(_c >> "ilsposition");
_c = (configfile >> "cfgworlds" >> worldname >> "secondaryairports");
_as = []; _as set [count _as,_s];
while {count _as <= count _c} do {
_s = getarray(_c select ((count _as) - 1) >> "ilsposition");
_as set [count _as,_s];
};
};
_i = 0;
///////////////////////
////PROCESSING OF DATA
///////////////////////
{
private ["_l","_n","_t","_m","_v"];
_l = locationposition _x;
_n = _ca select 0;
{
private ["_d"];
_d = (locationposition _x) distance _l;
_v = (locationposition _n) distance _l;
if (_d < _v) then {_n = _x};
} foreach _ca;
_t = ((_l select 0)-(locationposition _n select 0)) atan2 ((_l select 1)-(locationposition _n select 1));
_v = (locationposition _n) distance _l;
_m = createmarkerlocal [str(text _x)+ str(_i), locationposition _n];
_m setmarkerposlocal [sin (_t)*(_v/2) + (locationposition _n select 0), cos(_t)*(_v/2) + (locationposition _n select 1)];
_m setmarkershapelocal "rectangle"; _m setmarkerbrushlocal "solid"; _m setmarkercolorlocal "coloryellow";
_m setmarkerdirlocal _t; _m setmarkersizelocal [20, (_v/2)];
_i = _i + 1;
} foreach _ta;
{
private ["_l","_n","_t","_m","_v"];
_l = locationposition _x;
_n = (_ca + _ta) select 0;
{
private ["_d"];
_d = (locationposition _x) distance _l;
_v = (locationposition _n) distance _l;
if (_d < _v) then {_n = _x};
} foreach (_ca + _ta);
_t = ((_l select 0)-(locationposition _n select 0)) atan2 ((_l select 1)-(locationposition _n select 1));
_v = (locationposition _n) distance _l;
_m = createmarkerlocal [str(text _x)+ str(_i), locationposition _n];
_m setmarkerposlocal [sin (_t)*(_v/2) + (locationposition _n select 0), cos(_t)*(_v/2) + (locationposition _n select 1)];
_m setmarkershapelocal "rectangle"; _m setmarkerbrushlocal "solid"; _m setmarkercolorlocal "colorblue";
_m setmarkerdirlocal _t; _m setmarkersizelocal [10, (_v/2)];
_i = _i + 1;
} foreach _sa;
hint str(_as);
{
private ["_l","_n","_t","_m","_v"];
_l = _x;
_n = (_ca + _ta + _sa) select 0;
{
private ["_d"];
_d = (locationposition _x) distance _l;
_v = (locationposition _n) distance _l;
if (_d < _v) then {_n = _x};
} foreach (_ca + _ta + _sa);
_t = ((_l select 0)-(locationposition _n select 0)) atan2 ((_l select 1)-(locationposition _n select 1));
_v = (locationposition _n) distance _l;
_m = createmarkerlocal ["mkrAIR_"+ str(_i), locationposition _n];
_m setmarkerposlocal [sin (_t)*(_v/2) + (locationposition _n select 0), cos(_t)*(_v/2) + (locationposition _n select 1)];
_m setmarkershapelocal "rectangle"; _m setmarkerbrushlocal "solid"; _m setmarkercolorlocal "colorred";
_m setmarkerdirlocal _t; _m setmarkersizelocal [10,(_v/2)];
_i = _i + 1;
} foreach _as;
--------------
The ProblemThis 'as is' works perfect, however that was only after adding:
_v = (locationposition _n) distance _l;
after each
foreach loop.
_n = nearest
_l = location
Now what would happen if the foreach was not there, was the very last few markers (linked to Masbete, the last of the _ta array) would move off to a random location. This would also occur to all the markers linked to Bagango, (the last of the _ca array).
What was strange is that it would only occur on the last town if it is closest, and even though the:
_v = (locationposition _n) distance _l;
Inside the foreach loop was being declared and _n
is being found by this distance, it comes up outside the loop as a random number between 1 and ten thousand. I then found by re-defining _v it would find the actual distance, but that seems strange considering it had found the distance moments before via foreach loop with _n...