SAIL - SortByDistance (sortowanie wg. odległości)

Wszelkie pytania na temat SAIL'a i modowania OW.
Post Reply
User avatar
Serpent
Soldier level 10
Soldier level 10
Estonia
Posts: 4175
Joined: Tue Jul 07, 2009 9:13 pm
Location: Polska - EuroStan ZSRE
Contact:

SAIL - SortByDistance (sortowanie wg. odległości)

Post by Serpent »

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

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;
Z tej funkcji wyprowadzić można sortowanie dla pozycji konkretnej jednostki:

Code: Select all

Export Function SortByDistanceUnit(unit, list, asc);
begin
result := SortByDistanceXY(GetX(unit), GetY(unit), list, asc);
End;
Epickie teksty:
Marek1906: jak zrobic aby sail był zielony?
Kvantovy: Wszystko normalne, wszystko w koło było dziwne
Kvantovy:: To jest fajne, że to nie jest takie głupie
Kvantovy:: remove sos from kanapeczka
Kvantovy:: zdarzają się rzezy które sie filozofom nie śniły
Cenwen: problemem jest gejostwo
"Taki z niego fizyk jak ze mnie baletnica" - Profesor Scholtze o Kvantovym.
JAKBYŁ BYM CZECHEM TO BYM ROZŁOŻYŁ NAMIOT ~Kvanciak
Post Reply