hi folks
iÂ'm a ofp script newbee and i think i need some help.
what i need is a way to sort units asc to distance.
i did it with a rank idea but its a damn performance hog and
more dirty then clear
look at this
_unit is player for ex. _units is a simple 2d unit array like
list trigger. can be used with [player,units] call distfunc
where distfunc is preprocessed file
distance.sqf
----------------------------------------
private ["_units","_unit"];
_unit = _this select 0;
_units = _this select 1;
_i = 0;
_j = count _units;
while ("_i<_j") do {
_u1 = _units select _i;
_d1 = _u1 distance _unit;
_near set [_i, _u1];
_o = _i + 1;
_p = count _units;
while ("_o<_p") do {
_u2 = _units select _o;
_d2 = _u2 distance _unit;
if (_d1<_d2) then { _rank set [_i, ((_rank select _i) + 1)] }
else { _rank set [_o, ((_rank select _o) + 1)] };
_o = _o + 1;
};
_i = _i + 1;
};
_i = 0;
_j = count _rank;
while ("_i<_j") do {
_o = _j - ((_rank select _i) + 1);
_nearest set [_o, (_near select _i)];
_i = _i + 1;
}
---------------------------------
now nearest unit to _unit is first in _nearest, second - second in
_nearest ...
well this works but when i put this on 20 units my cpu is going
down. i need this to provide waypoints to a helicopter pilot who
pickup units from a custom rescue area. i cant do this with
simple waypoints couse unit count and position is never
the same.
another idea is to create a couple of units that group and regroup
automaticaly. nearest with next - next with next ...
is there a good way to sort arrays or another funktion like
nearplayer. i saw this nearestobject "streetlamp" stuff but it
seems not to work with custom objects.
what do you think ?