File: CevoMapCheck.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 (204 lines) | stat: -rw-r--r-- 5,570 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
program CevoMapCheck;

{***********************************************************

Project:    C-evo External Map Generator
Copyright:  2021-2024 P Blackman
License:    GPLv3+

Program to check map file validity and
output some statistcs

***********************************************************}

{$linklib c}

uses CevoMapFile, CevoMap, MapTiles;

var
    MapFile : tMapFile;
    Map     : tMap;
    FileNam : string;


function GetMapFileName : Boolean;
begin
    if ParamCount >= 1 then
    begin
        FileNam := ParamStr(1);
        result  := True;
    end
    else
    begin
        FileNam := '';
        result  := False;
    end;
end;

procedure ShowStartPos (W,H : Integer);
var DeadLand : Boolean;
begin
    Writeln (MapFile.MapIndex(W,H)-1:5, '  ', Map.StartScore (W,H,Deadland));
end;

procedure CheckMapBody;
var StartPositions, W, H,
    DeadLands,
    Cobalt,
    Uranium,
    Mercury : Integer;

begin
    StartPositions := 0;
    DeadLands      := 0;
    Cobalt         := 0;
    Uranium        := 0;
    Mercury        := 0;

    with MapFile do
    begin
        Writeln ('Start-Positions');
        Writeln ('Locn  Score');
        Writeln ('----- ----');
        for W := 1 to Width do
            for H := 1 to height do
            begin
                If fBody[MapIndex(W,H)].StartPos and $60 in [$20, $40] then
                begin
                    inc (StartPositions);
                    ShowStartPos (W,H);
                end;

                case fBody[MapIndex(W,H)].Special and $7 of
                      0: {Nothing here};
                      1: inc (DeadLands);
                      3: inc (Cobalt);
                      5: inc (Uranium);
                      7: inc (Mercury);
                otherwise
                    writeln ('Invalid special ',fBody[MapIndex(W,H)].Special, ' at ', MapIndex(W,H));
                end;
            end;

        Writeln ('----- ----');
        Writeln ('Total  ',StartPositions);
        Writeln;
        Writeln ('Cobalt    ', Cobalt);
        Writeln ('Uranium   ', Uranium);
        Writeln ('Mercury   ', Mercury);
        Writeln ('DeadLands ', DeadLands);
    end;
end;

procedure ShowTerrain;

var W,H,MapSize,EarlyBonusRes, LateBonusRes,
    OceanTiles,CoastTiles,GrassTiles,DesertTiles,PrairieTiles,TundraTiles,
    ArcticTiles,SwampTiles,ForestTiles,HillsTiles,MountainTiles,RiverTiles : Integer;
    Bonus : tResource;
    BonusRes : Double;

begin
    OceanTiles      :=0;
    CoastTiles      :=0;
    GrassTiles      :=0;
    DesertTiles     :=0;
    PrairieTiles    :=0;
    TundraTiles     :=0;
    ArcticTiles     :=0;
    SwampTiles      :=0;
    ForestTiles     :=0;
    HillsTiles      :=0;
    MountainTiles   :=0;
    RiverTiles      :=0;
    EarlyBonusRes   :=0;
    LateBonusRes    :=0;
    MapSize         := Map.Width * Map.Height;

    with Map do
    for W := 1 to Width do
      for H := 1 to Height do
      begin
        case GetTerrain (W, H) of
            Ocean   : inc (OceanTiles);
            Coast   : inc (CoastTiles);
            Grass   : inc (GrassTiles);
            Desert  : inc (DesertTiles);
            Prairie : inc (PrairieTiles);
            Tundra  : inc (TundraTiles);
            Arctic  : inc (ArcticTiles);
            Swamp   : inc (SwampTiles);
            Forest  : inc (ForestTiles);
            Hills   : inc (HillsTiles);
            Mountain : inc (MountainTiles);
            otherwise
                Writeln ('Invalid Terrain Tile ',W, ' ',H, ' ',GetTerrain (W, H));
        end;

        if Tiles[W,H].River then
            inc (RiverTiles);

        Bonus := GetBonus (W, H);

        If (Bonus = EarlyBonus) and (GetTerrain (W, H) <> Grass) then
            inc (EarlyBonusRes);
        If Bonus = LateBonus then
            inc (LateBonusRes);
      end;

   if MapSize = OceanTiles then
        BonusRes := 0.0
    else
        BonusRes := (EarlyBonusRes+LateBonusRes) * (MapSize / (MapSize-OceanTiles));

    Writeln ('Ocean%    ', Round(100*OceanTiles   /MapSize):2);
    Writeln ('Coast%    ', Round(100*CoastTiles   /MapSize):2);
    Writeln ('Grass%    ', Round(100*GrassTiles   /MapSize):2);
    Writeln ('Desert%   ', Round(100*DesertTiles  /MapSize):2);
    Writeln ('Prairie%  ', Round(100*PrairieTiles /MapSize):2);
    Writeln ('Tundra%   ', Round(100*TundraTiles  /MapSize):2);
    Writeln ('Arctic%   ', Round(100*ArcticTiles  /MapSize):2);
    Writeln ('Swamp%    ', Round(100*SwampTiles   /MapSize):2);
    Writeln ('Forest%   ', Round(100*ForestTiles  /MapSize):2);
    Writeln ('Hills%    ', Round(100*HillsTiles   /MapSize):2);
    Writeln ('Mountain% ', Round(100*MountainTiles/MapSize):2);
    Writeln;
    Writeln ('Rivers%   ', Round(100*RiverTiles   /MapSize):2);
    Writeln ('Resource% ', (100* BonusRes / MapSize):4:1);
end;

procedure Report;
begin
    with MapFile.fHeader do
    begin
        Writeln;
        Writeln (FileNam);
        Writeln ('Size: ',LX, 'x', LY, LX*LY:6);
        Writeln;
        Map := tMap.Create (LX, LY, 0, 0);
        MapFile.LoadMapData (Map);
        CheckMapBody;
        Writeln;
        ShowTerrain;
        Writeln;
        Map.Free;
    end;
end;

begin
    MapFile := tMapFile.Create;
    FileNam := '';

    if GetMapFileName then
    begin
        if MapFile.OpenMFile (FileNam) then
            if MapFile.LoadFromFile then
                Report
            else
                Writeln ('Failed to load file: ', FileNam);
    end
    else
        Writeln ('cevomapcheck requires a filename as parameter');

     MapFile.Free;
end.