Changeset 320 for trunk


Ignore:
Timestamp:
Mar 22, 2021, 9:53:40 PM (4 years ago)
Author:
chronos
Message:
  • Modified: TMiniMap moved from Start unit to UMiniMap unit.
Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Integrated.lpi

    r317 r320  
    9595      </Item2>
    9696    </RequiredPackages>
    97     <Units Count="42">
     97    <Units Count="43">
    9898      <Unit0>
    9999        <Filename Value="Integrated.lpr"/>
     
    336336        <IsPartOfProject Value="True"/>
    337337      </Unit41>
     338      <Unit42>
     339        <Filename Value="UMiniMap.pas"/>
     340        <IsPartOfProject Value="True"/>
     341      </Unit42>
    338342    </Units>
    339343  </ProjectOptions>
  • trunk/Start.pas

    r318 r320  
    77  GameServer, Messg, ButtonBase, ButtonA, ButtonC, ButtonB, Area, Types,
    88  LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls,
    9   Menus, Registry, DrawDlg, fgl, Protocol;
     9  Menus, Registry,  DrawDlg, fgl, Protocol, UMiniMap;
    1010
    1111type
     
    3434  TMainAction = (maConfig, maManual, maCredits, maAIDev, maWeb, maNone);
    3535  TMainActionSet = set of TMainAction;
    36 
    37   TMapArray = array[0 .. lxmax * lymax - 1] of Byte;
    38 
    39   TMiniMode = (mmNone, mmPicture, mmMultiPlayer);
    40 
    41   { TMiniMap }
    42 
    43   TMiniMap = class
    44   const
    45     MaxWidthMapLogo = 96;
    46     MaxHeightMapLogo = 96;
    47   var
    48     Bitmap: TBitmap; { game world sample preview }
    49     Size: TPoint;
    50     Colors: array [0 .. 11, 0 .. 1] of TColor;
    51     Mode: TMiniMode;
    52     procedure LoadFromLogFile(FileName: string; var LastTurn: Integer);
    53     procedure LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);
    54     procedure PaintRandom(Brightness, StartLandMass, WorldSize: Integer);
    55     procedure PaintFile(SaveMap: TMapArray);
    56     constructor Create;
    57     destructor Destroy; override;
    58   end;
    5936
    6037  { TStartDlg }
     
    166143
    167144uses
    168   Global, Directories, Direct, ScreenTools, Inp, Back, Settings, UPixelPointer;
     145  Global, Directories, Direct, ScreenTools, Inp, Back, Settings;
    169146
    170147{$R *.lfm}
     
    225202  PlayerAutoDiff: array [1 .. 5] of integer = (1, 1, 2, 2, 3);
    226203  EnemyAutoDiff: array [1 .. 5] of integer = (4, 3, 2, 1, 1);
    227 
    228 { TMiniMap }
    229 
    230 constructor TMiniMap.Create;
    231 var
    232   X, Y: Integer;
    233 begin
    234   Bitmap := TBitmap.Create;
    235 
    236   for X := 0 to 11 do
    237     for Y := 0 to 1 do
    238       Colors[x, y] := HGrSystem.Data.Canvas.Pixels[66 + x, 67 + y];
    239 end;
    240 
    241 destructor TMiniMap.Destroy;
    242 begin
    243   FreeAndNil(Bitmap);
    244   inherited;
    245 end;
    246 
    247 procedure TMiniMap.LoadFromLogFile(FileName: string; var LastTurn: Integer);
    248 var
    249   SaveMap: TMapArray;
    250   y: Integer;
    251   Dummy: Integer;
    252   FileLandMass: integer;
    253   LogFile: file;
    254   s: string[255];
    255   MapRow: array [0 .. lxmax - 1] of Cardinal;
    256 begin
    257   AssignFile(LogFile, FileName);
    258   try
    259     Reset(LogFile, 4);
    260     BlockRead(LogFile, s[1], 2); { file id }
    261     BlockRead(LogFile, Dummy, 1); { format id }
    262     if Dummy >= $000E01 then
    263       BlockRead(LogFile, Dummy, 1); { item stored since 0.14.1 }
    264     BlockRead(LogFile, Size.X, 1);
    265     BlockRead(LogFile, Size.Y, 1);
    266     BlockRead(LogFile, FileLandMass, 1);
    267     if FileLandMass = 0 then
    268       for y := 0 to Size.Y - 1 do
    269         BlockRead(LogFile, MapRow, Size.X);
    270     BlockRead(LogFile, Dummy, 1);
    271     BlockRead(LogFile, Dummy, 1);
    272     BlockRead(LogFile, LastTurn, 1);
    273     BlockRead(LogFile, SaveMap, 1);
    274     if SaveMap[0] = $80 then
    275       Mode := mmMultiPlayer
    276     else
    277       Mode := mmPicture;
    278     if Mode = mmPicture then
    279       BlockRead(LogFile, SaveMap[4], (Size.X * Size.Y - 1) div 4);
    280     CloseFile(LogFile);
    281   except
    282     CloseFile(LogFile);
    283     LastTurn := 0;
    284     Size := WorldSizes[DefaultWorldSize];
    285     Mode := mmNone;
    286   end;
    287   PaintFile(SaveMap);
    288 end;
    289 
    290 procedure TMiniMap.LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);
    291 var
    292   x, y, lxFile, lyFile: integer;
    293   MapFile: file;
    294   s: string[255];
    295   MapRow: array [0 .. lxmax - 1] of Cardinal;
    296   ImageFileName: string;
    297 begin
    298   ImageFileName := Copy(FileName, 1, Length(FileName) - Length(CevoMapExt)) + '.png';
    299   Mode := mmPicture;
    300   if LoadGraphicFile(Bitmap, ImageFileName, [gfNoError]) then
    301   begin
    302     if Bitmap.width div 2 > MaxWidthMapLogo then
    303       Bitmap.width := MaxWidthMapLogo * 2;
    304     if Bitmap.height > MaxHeightMapLogo then
    305       Bitmap.height := MaxHeightMapLogo;
    306     Size.X := Bitmap.width div 2;
    307     Size.Y := Bitmap.height;
    308   end
    309   else
    310   begin
    311     Mode := mmNone;
    312     Size.X := MaxWidthMapLogo;
    313     Size.Y := MaxHeightMapLogo;
    314   end;
    315 
    316   AssignFile(MapFile, FileName);
    317   try
    318     Reset(MapFile, 4);
    319     BlockRead(MapFile, s[1], 2); { file id }
    320     BlockRead(MapFile, x, 1); { format id }
    321     BlockRead(MapFile, x, 1); // MaxTurn
    322     BlockRead(MapFile, lxFile, 1);
    323     BlockRead(MapFile, lyFile, 1);
    324     nMapLandTiles := 0;
    325     nMapStartPositions := 0;
    326     for y := 0 to lyFile - 1 do begin
    327       BlockRead(MapFile, MapRow, lxFile);
    328       for x := 0 to lxFile - 1 do
    329       begin
    330         if (MapRow[x] and fTerrain) in [fGrass, fPrairie, fTundra, fSwamp,
    331           fForest, fHills] then
    332           inc(nMapLandTiles);
    333         if MapRow[x] and (fPrefStartPos or fStartPos) <> 0 then
    334           inc(nMapStartPositions);
    335       end
    336     end;
    337     if nMapStartPositions > nPl then
    338       nMapStartPositions := nPl;
    339     CloseFile(MapFile);
    340   except
    341     CloseFile(MapFile);
    342   end;
    343 end;
    344 
    345 procedure TMiniMap.PaintRandom(Brightness, StartLandMass, WorldSize: Integer);
    346 var
    347   i, x, y, xm, cm: Integer;
    348   MiniPixel: TPixelPointer;
    349   Map: ^TTileList;
    350 begin
    351   Map := PreviewMap(StartLandMass);
    352   Size := WorldSizes[WorldSize];
    353 
    354   Bitmap.PixelFormat := pf24bit;
    355   Bitmap.SetSize(Size.X * 2, Size.Y);
    356   Bitmap.BeginUpdate;
    357   MiniPixel := PixelPointer(Bitmap);
    358   for y := 0 to ScaleToNative(Size.Y) - 1 do begin
    359     for x := 0 to ScaleToNative(Size.X) - 1 do begin
    360       for i := 0 to 1 do begin
    361         xm := (x * 2 + i + y and 1) mod (ScaleToNative(Size.X) * 2);
    362         MiniPixel.SetX(xm);
    363         cm := Colors
    364           [Map[ScaleFromNative(x) * lxmax div Size.X + lxmax *
    365           ((ScaleFromNative(y) * (lymax - 1) + Size.Y div 2) div (Size.Y - 1))] and
    366           fTerrain, i];
    367         MiniPixel.Pixel^.B := ((cm shr 16) and $FF) * Brightness div 3;
    368         MiniPixel.Pixel^.G := ((cm shr 8) and $FF) * Brightness div 3;
    369         MiniPixel.Pixel^.R := ((cm shr 0) and $FF) * Brightness div 3;
    370       end;
    371     end;
    372     MiniPixel.NextLine;
    373   end;
    374   Bitmap.EndUpdate;
    375 end;
    376 
    377 procedure TMiniMap.PaintFile(SaveMap: TMapArray);
    378 var
    379   i, x, y, xm, cm, Tile, OwnColor, EnemyColor: integer;
    380   MiniPixel: TPixelPointer;
    381   PrevMiniPixel: TPixelPointer;
    382 begin
    383   OwnColor := HGrSystem.Data.Canvas.Pixels[95, 67];
    384   EnemyColor := HGrSystem.Data.Canvas.Pixels[96, 67];
    385   Bitmap.PixelFormat := pf24bit;
    386   Bitmap.SetSize(Size.X * 2, Size.Y);
    387   if Mode = mmPicture then begin
    388     Bitmap.BeginUpdate;
    389     MiniPixel := PixelPointer(Bitmap);
    390     PrevMiniPixel := PixelPointer(Bitmap, 0, -1);
    391     for y := 0 to ScaleToNative(Size.Y) - 1 do begin
    392       for x := 0 to ScaleToNative(Size.X) - 1 do begin
    393         for i := 0 to 1 do begin
    394           xm := (x * 2 + i + y and 1) mod (ScaleToNative(Size.X) * 2);
    395           MiniPixel.SetX(xm);
    396           Tile := SaveMap[ScaleFromNative(x) + Size.X * ScaleFromNative(y)];
    397           if Tile and fTerrain = fUNKNOWN then
    398             cm := $000000
    399           else if Tile and smCity <> 0 then
    400           begin
    401             if Tile and smOwned <> 0 then
    402               cm := OwnColor
    403             else
    404               cm := EnemyColor;
    405             if y > 0 then begin
    406               // 2x2 city dot covers two lines
    407               PrevMiniPixel.SetX(xm);
    408               PrevMiniPixel.Pixel^.B := cm shr 16;
    409               PrevMiniPixel.Pixel^.G:= cm shr 8 and $FF;
    410               PrevMiniPixel.Pixel^.R := cm and $FF;
    411             end;
    412           end
    413           else if (i = 0) and (Tile and smUnit <> 0) then
    414             if Tile and smOwned <> 0 then
    415               cm := OwnColor
    416             else cm := EnemyColor
    417           else
    418             cm := Colors[Tile and fTerrain, i];
    419           MiniPixel.Pixel^.B := (cm shr 16) and $ff;
    420           MiniPixel.Pixel^.G := (cm shr 8) and $ff;
    421           MiniPixel.Pixel^.R := (cm shr 0) and $ff;
    422         end;
    423       end;
    424       MiniPixel.NextLine;
    425       PrevMiniPixel.NextLine;
    426     end;
    427     Bitmap.EndUpdate;
    428   end;
    429 end;
    430204
    431205{ TStartDlg }
     
    12611035    pgStartRandom: begin
    12621036      MiniMap.Mode := mmPicture;
    1263       MiniMap.PaintRandom(3, StartLandMass, WorldSize);
     1037      MiniMap.PaintRandom(3, StartLandMass, WorldSizes[WorldSize]);
    12641038    end;
    12651039    pgNoLoad: begin
     
    12691043    pgLoad: begin
    12701044        MiniMap.LoadFromLogFile(GetSavedDir + DirectorySeparator +
    1271           List.Items[List.ItemIndex] + CevoExt, LastTurn);
     1045          List.Items[List.ItemIndex] + CevoExt, LastTurn, WorldSizes[DefaultWorldSize]);
    12721046        // BookDate:=DateToStr(FileDateToDateTime(FileAge(FileName)));
    12731047        if not TurnValid then  begin
     
    12811055      MapFileName := '';
    12821056      MiniMap.Mode := mmPicture;
    1283       MiniMap.PaintRandom(4, StartLandMass, WorldSize);
     1057      MiniMap.PaintRandom(4, StartLandMass, WorldSizes[WorldSize]);
    12841058    end;
    12851059    pgStartMap, pgEditMap:
Note: See TracChangeset for help on using the changeset viewer.