Changeset 591


Ignore:
Timestamp:
Jul 24, 2024, 11:02:31 PM (4 months ago)
Author:
chronos
Message:
  • Modified: Draw graphical preview for maps which doesn't have associated image.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Database.pas

    r590 r591  
    598598}
    599599var
    600   primitive: Integer;
     600  Primitive: Integer;
    601601  StartLoc, StartLoc2: array [0 .. nPl - 1] of Integer; { starting coordinates }
    602602  Elevation: array [0 .. lxmax * lymax - 1] of Byte; { map elevation }
     
    607607  I, J: Integer;
    608608begin
    609   primitive := 1;
     609  Primitive := 1;
    610610  I := 2;
    611611  while I * I <= MapSize + 1 do // test whether prime
    612612  begin
    613613    if (MapSize + 1) mod I = 0 then
    614       primitive := 0;
     614      Primitive := 0;
    615615    Inc(I);
    616616  end;
    617617
    618   if primitive > 0 then
     618  if Primitive > 0 then
    619619    repeat
    620       Inc(primitive);
     620      Inc(Primitive);
    621621      I := 1;
    622622      J := 0;
    623623      repeat
    624624        Inc(J);
    625         I := I * primitive mod (MapSize + 1);
     625        I := I * Primitive mod (MapSize + 1);
    626626      until (I = 1) or (J = MapSize + 1);
    627627    until J = MapSize;
     
    630630function MapGeneratorAvailable: Boolean;
    631631begin
    632   Result := (primitive > 0) and (lx >= 20) and (ly >= 40);
     632  Result := (Primitive > 0) and (lx >= 20) and (ly >= 40);
    633633end;
    634634
     
    11551155        (Loc0 < MapSize - lx) then
    11561156        RunRiver(Loc0);
    1157       Loc0 := (Loc0 + 1) * primitive mod (MapSize + 1) - 1;
     1157      Loc0 := (Loc0 + 1) * Primitive mod (MapSize + 1) - 1;
    11581158    end;
    11591159  end;
     
    14131413        end;
    14141414      end;
    1415       Loc := (Loc + 1) * primitive mod (MapSize + 1) - 1;
     1415      Loc := (Loc + 1) * Primitive mod (MapSize + 1) - 1;
    14161416    end;
    14171417
  • trunk/GameServer.pas

    r590 r591  
    291291  LandMass := ALandMass;
    292292  DelphiRandSeed := PreviewRND;
    293   if not PreviewElevation then
    294   begin
     293  if not PreviewElevation then begin
    295294    CreateElevation;
    296295    PreviewElevation := True;
     
    13821381  GAlive := 0;
    13831382  GWatching := 1;
    1384   for Loc1 := 0 to MapSize - 1 do
    1385     RealMap[Loc1] := fOcean or ($F shl 27);
    13861383  if FileExists(MapFileName) then begin
    13871384    Map := TMap.Create;
     
    13921389    Move(Map.Tiles[0], RealMap, MapSize * 4);
    13931390    FreeAndNil(Map);
     1391  end else begin
     1392    for Loc1 := 0 to MapSize - 1 do
     1393      RealMap[Loc1] := fOcean or ($F shl 27);
    13941394  end;
    13951395  CL := nil;
  • trunk/MiniMap.pas

    r590 r591  
    2626    procedure LoadFromLogFile(FileName: string; var LastTurn: Integer; DefaultSize: TPoint);
    2727    procedure LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);
     28    procedure PaintMap(Map: TMap);
    2829    procedure PaintRandom(Brightness, StartLandMass: Integer; WorldSize: TPoint);
    2930    procedure PaintFile(SaveMap: TMapArray);
     
    111112procedure TMiniMap.LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);
    112113var
    113   x, y: integer;
    114   MapRow: array [0 .. lxmax - 1] of Cardinal;
     114  X, Y: Integer;
    115115  ImageFileName: string;
    116116  Map: TMap;
    117117  Tile: Cardinal;
     118  PaintMapEnabled: Boolean;
    118119begin
    119120  ImageFileName := Copy(FileName, 1, Length(FileName) - Length(CevoMapExt)) + CevoMapPictureExt;
     
    126127      Bitmap.Height := MaxHeightMapLogo;
    127128    Size := Point(Bitmap.Width div 2, Bitmap.Height);
     129    PaintMapEnabled := False;
    128130  end else begin
    129     Mode := mmNone;
     131    Mode := mmPicture;
    130132    Size := Point(MaxWidthMapLogo, MaxHeightMapLogo);
     133    PaintMapEnabled := True;
    131134  end;
    132135
     
    136139    nMapLandTiles := 0;
    137140    nMapStartPositions := 0;
    138     for y := 0 to Map.Size.Y - 1 do begin
     141    for Y := 0 to Map.Size.Y - 1 do begin
    139142      for X := 0 to Map.Size.X - 1 do begin
    140143        Tile := Map.Tiles[Y * Map.Size.X + X];
     
    148151    if nMapStartPositions > nPl then
    149152      nMapStartPositions := nPl;
     153
     154    if PaintMapEnabled then begin
     155      Size := Map.Size;
     156      PaintMap(Map);
     157    end;
    150158  finally
    151159    FreeAndNil(Map);
     160  end;
     161end;
     162
     163procedure TMiniMap.PaintMap(Map: TMap);
     164var
     165  i, x, y, xm, cm, Tile, OwnColor, EnemyColor: integer;
     166  MiniPixel: TPixelPointer;
     167  PrevMiniPixel: TPixelPointer;
     168  xx, yy: Integer;
     169begin
     170  OwnColor := HGrSystem.Data.Canvas.Pixels[95, 67];
     171  EnemyColor := HGrSystem.Data.Canvas.Pixels[96, 67];
     172  Bitmap.PixelFormat := TPixelFormat.pf24bit;
     173  Bitmap.SetSize(Size.X * 2, Size.Y);
     174  if Mode = mmPicture then begin
     175    Bitmap.BeginUpdate;
     176    MiniPixel := TPixelPointer.Create(Bitmap);
     177    PrevMiniPixel := TPixelPointer.Create(Bitmap);
     178    xx := ScaleToNative(Size.X);
     179    yy := ScaleToNative(Size.Y);
     180    for y := 0 to yy - 1 do begin
     181      for x := 0 to xx - 1 do begin
     182        for i := 0 to 1 do begin
     183          xm := (x * 2 + i + y and 1) mod (xx * 2);
     184          MiniPixel.SetX(xm);
     185          Tile := Map.Tiles[ScaleFromNative(x) + Size.X * ScaleFromNative(y)];
     186          if Tile and fTerrain = fUNKNOWN then
     187            cm := $000000
     188          else if Tile and smCity <> 0 then begin
     189            if Tile and smOwned <> 0 then cm := OwnColor
     190              else cm := EnemyColor;
     191            if y > 0 then begin
     192              // 2x2 city dot covers two lines
     193              PrevMiniPixel.SetX(xm);
     194              if (PByte(PrevMiniPixel.Pixel) >= Bitmap.RawImage.Data) and
     195              (PByte(PrevMiniPixel.Pixel) < (Bitmap.RawImage.Data + yy * PrevMiniPixel.BytesPerLine)) then begin
     196                PrevMiniPixel.PixelB := cm shr 16;
     197                PrevMiniPixel.PixelG:= cm shr 8 and $FF;
     198                PrevMiniPixel.PixelR := cm and $FF;
     199              end;
     200            end;
     201          end
     202          else if (i = 0) and (Tile and smUnit <> 0) then begin
     203            if Tile and smOwned <> 0 then cm := OwnColor
     204              else cm := EnemyColor;
     205          end else
     206            cm := Colors[Tile and fTerrain, i];
     207          if (PByte(MiniPixel.Pixel) >= Bitmap.RawImage.Data) and
     208          (PByte(MiniPixel.Pixel) < (Bitmap.RawImage.Data + yy * MiniPixel.BytesPerLine)) then begin
     209            MiniPixel.PixelB := (cm shr 16) and $ff;
     210            MiniPixel.PixelG := (cm shr 8) and $ff;
     211            MiniPixel.PixelR := (cm shr 0) and $ff;
     212          end;
     213        end;
     214      end;
     215      MiniPixel.NextLine;
     216      if y > 0 then PrevMiniPixel.NextLine;
     217    end;
     218    Bitmap.EndUpdate;
    152219  end;
    153220end;
Note: See TracChangeset for help on using the changeset viewer.