Author: SerpentSerpent wrote: ↑Tue Oct 16, 2018 7:52 pm Funkcja sortująca jednostki z listy wg. odległości od wskazanego hexa (x,y).
Zwraca tablicę w postaci:
[ [jednostka, odległość], [jednostka, odległość], ...]
Parametry:
- x,y - koordynaty
- list - lista jednostek
- asc - tryb sortowania: true -> rosnąco, false -> malejąco
Z tej funkcji wyprowadzić można sortowanie dla pozycji konkretnej jednostki:Code: Select all
Export Function SortByDistanceXY(x, y, list, asc); var i, j, tmp; begin if not list then exit; result := []; for i in list do begin tmp := GetDistUnitXY(i, x, y); if not result then result := [[i, tmp]] else begin if result[result][2] < tmp then result := Insert(result, result+1, [i, tmp]) else for j = 1 to result do begin if tmp < result[j][2] then begin result := Insert(result, j, [i, tmp]); break; end; end; end; end; if result and not asc then begin tmp := result; for i = tmp downto 1 do result := Replace(result, tmp - i + 1, tmp[i]); end; End;
Code: Select all
Export Function SortByDistanceUnit(unit, list, asc); begin result := SortByDistanceXY(GetX(unit), GetY(unit), list, asc); End;
Topic: https://forum.original-war.net/viewtopi ... =42&t=5866