Changeset 590 for trunk/MiniMap.pas


Ignore:
Timestamp:
Jul 24, 2024, 10:25:56 PM (8 weeks ago)
Author:
chronos
Message:
  • Modified: Map load and save moved to separate class TMap.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MiniMap.pas

    r545 r590  
    55
    66uses
    7   Classes, SysUtils, Protocol, ClientTools,
     7  Classes, SysUtils, Protocol, ClientTools, Map,
    88  {$IFDEF DPI}Dpi.Graphics, Dpi.Common{$ELSE}Graphics{$ENDIF};
    99
     
    111111procedure TMiniMap.LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);
    112112var
    113   x, y, lxFile, lyFile: integer;
    114   MapFile: file;
    115   s: string[255];
     113  x, y: integer;
    116114  MapRow: array [0 .. lxmax - 1] of Cardinal;
    117115  ImageFileName: string;
     116  Map: TMap;
     117  Tile: Cardinal;
    118118begin
    119119  ImageFileName := Copy(FileName, 1, Length(FileName) - Length(CevoMapExt)) + CevoMapPictureExt;
     
    125125    if Bitmap.Height > MaxHeightMapLogo then
    126126      Bitmap.Height := MaxHeightMapLogo;
    127     Size.X := Bitmap.Width div 2;
    128     Size.Y := Bitmap.Height;
     127    Size := Point(Bitmap.Width div 2, Bitmap.Height);
    129128  end else begin
    130129    Mode := mmNone;
    131     Size.X := MaxWidthMapLogo;
    132     Size.Y := MaxHeightMapLogo;
    133   end;
    134 
    135   AssignFile(MapFile, FileName);
     130    Size := Point(MaxWidthMapLogo, MaxHeightMapLogo);
     131  end;
     132
     133  Map := TMap.Create;
    136134  try
    137     Reset(MapFile, 4);
    138     BlockRead(MapFile, s[1], 2); { file id }
    139     BlockRead(MapFile, x, 1); { format id }
    140     BlockRead(MapFile, x, 1); // MaxTurn
    141     BlockRead(MapFile, lxFile, 1);
    142     BlockRead(MapFile, lyFile, 1);
     135    Map.LoadFromFile(FileName);
    143136    nMapLandTiles := 0;
    144137    nMapStartPositions := 0;
    145     for y := 0 to lyFile - 1 do begin
    146       BlockRead(MapFile, MapRow, lxFile);
    147       for x := 0 to lxFile - 1 do
    148       begin
    149         if (MapRow[x] and fTerrain) in [fGrass, fPrairie, fTundra, fSwamp,
     138    for y := 0 to Map.Size.Y - 1 do begin
     139      for X := 0 to Map.Size.X - 1 do begin
     140        Tile := Map.Tiles[Y * Map.Size.X + X];
     141        if (Tile and fTerrain) in [fGrass, fPrairie, fTundra, fSwamp,
    150142          fForest, fHills] then
    151143          Inc(nMapLandTiles);
    152         if MapRow[x] and (fPrefStartPos or fStartPos) <> 0 then
     144        if Tile and (fPrefStartPos or fStartPos) <> 0 then
    153145          Inc(nMapStartPositions);
    154       end
     146      end;
    155147    end;
    156148    if nMapStartPositions > nPl then
    157149      nMapStartPositions := nPl;
    158     CloseFile(MapFile);
    159   except
    160     CloseFile(MapFile);
     150  finally
     151    FreeAndNil(Map);
    161152  end;
    162153end;
Note: See TracChangeset for help on using the changeset viewer.