File: SortTiles.pas

package info (click to toggle)
cevomapgen 39-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 476 kB
  • sloc: pascal: 2,765; xml: 169; makefile: 50
file content (69 lines) | stat: -rw-r--r-- 1,424 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
unit SortTiles;

interface uses MapTiles;

type tTileData =
    record
        Food,
        Prod,
        Trade : Integer;
        tt : tTerrain;
    end;
    tTileArray = array [0..20] of tTileData;

    procedure TileSort (Var TileArray : tTileArray);


implementation

// Sort by Food, Production then Trade
function Compare (const T1, T2 : tTileData) : Integer;
begin
    if T1.Food < T2.Food then
        Compare := -1
    else
    if T1.Food > T2.Food then
        Compare := 1
    else
    if T1.Prod < T2.Prod then
        Compare := -1
    else
    if T1.Prod > T2.Prod then
        Compare := 1
    else
    if T1.Trade < T2.Trade then
        Compare := -1
    else
    if T1.Trade > T2.Trade then
        Compare := 1
    else
        Compare := 0;
end;


procedure TileSort (Var TileArray : tTileArray);
Var J,K     : Integer;
    Found   : Boolean;
    Temp    : tTileData;

begin
    for K := 2 to 20 do  // City square 0, always included
        if compare (TileArray[K], TileArray[K-1]) > 0 then
        begin
            temp := TileArray[K];
            J := K;
            Found := False;

            while (J > 1) and not Found do
            iF Compare (TileArray[J-1], Temp) >= 0 then
                Found := True
            else
            begin
                TileArray[J] := TileArray[J-1];
                J := J-1;
            end;
            TileArray[J] := Temp;
        end;
end;

end.