Changeset 326 for trunk


Ignore:
Timestamp:
Mar 24, 2021, 12:08:28 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Mini map paint method moved from TMainScreen class to TMiniMap class.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/GameServer.pas

    r319 r326  
    4444  fDotNet = $20000000;
    4545  fUsed = $40000000;
    46 
    47   // save map tile flags
    48   smOwned = $20;
    49   smUnit = $40;
    50   smCity = $80;
    5146
    5247  maxBrain = 255;
  • trunk/LocalPlayer/ClientTools.pas

    r294 r326  
    5959procedure CityOptimizer_AfterRemoveUnit;
    6060procedure CityOptimizer_EndOfTurn;
     61function GetMyCityByLoc(Loc: Integer): PCity;
     62function GetEnemyCityByLoc(Loc: Integer): PCityInfo;
     63function GetMyUnitByLoc(Loc: Integer): PUn;
     64function GetEnemyUnitByLoc(Loc: Integer): PUnitInfo;
    6165
    6266
     
    696700end;
    697701
     702function GetMyCityByLoc(Loc: Integer): PCity;
     703var
     704  I: Integer;
     705begin
     706  I := MyRO.nCity - 1;
     707  while (I >= 0) and (MyCity[I].Loc <> Loc) do Dec(I);
     708  if I >= 0 then Result := @MyCity[I]
     709    else Result := nil;
     710end;
     711
     712function GetEnemyCityByLoc(Loc: Integer): PCityInfo;
     713var
     714  I: Integer;
     715begin
     716  I := MyRO.nEnemyCity - 1;
     717  while (I >= 0) and (MyRo.EnemyCity[I].Loc <> Loc) do Dec(I);
     718  if I >= 0 then Result := @MyRo.EnemyCity[I]
     719    else Result := nil;
     720end;
     721
     722function GetMyUnitByLoc(Loc: Integer): PUn;
     723var
     724  I: Integer;
     725begin
     726  I := MyRO.nUn - 1;
     727  while (I >= 0) and (MyUn[I].Loc <> Loc) do Dec(I);
     728  if I >= 0 then Result := @MyUn[I]
     729    else Result := nil;
     730end;
     731
     732function GetEnemyUnitByLoc(Loc: Integer): PUnitInfo;
     733var
     734  I: Integer;
     735begin
     736  I := MyRO.nEnemyUn - 1;
     737  while (I >= 0) and (MyRO.EnemyUn[I].Loc <> Loc) do Dec(I);
     738  if I >= 0 then Result := @MyRO.EnemyUn[I]
     739    else Result := nil;
     740end;
     741
     742
    698743initialization
    699744
  • trunk/LocalPlayer/IsoEngine.pas

    r325 r326  
    8080var
    8181  NoMap: TIsoMap;
    82   Options: integer;
    83   pDebugMap: integer; // -1 for off
     82  Options: Integer;
     83  pDebugMap: Integer; // -1 for off
    8484
    8585function IsJungle(y: integer): boolean;
     
    8787function ApplyTileSize(ATileSize: TTileSize): boolean;
    8888procedure Done;
    89 procedure Reset;
     89procedure IsoEngineReset;
    9090
    9191implementation
     
    466466end;
    467467
    468 procedure Reset;
     468procedure IsoEngineReset;
    469469begin
    470470  BordersOK := 0;
  • trunk/LocalPlayer/Term.pas

    r325 r326  
    1414  LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, DrawDlg, Types,
    1515  Forms, Menus, ExtCtrls, dateutils, Platform, ButtonB, ButtonC, EOTButton, Area,
    16   UGraphicSet;
     16  UGraphicSet, UMiniMap;
    1717
    1818const
     
    253253    trix: array [0 .. 63] of Integer;
    254254    AILogo: array [0 .. nPl - 1] of TBitmap;
    255     Mini: TBitmap;
     255    MiniMap: TMiniMap;
    256256    Panel: TBitmap;
    257257    TopBar: TBitmap;
     
    274274    procedure ArrangeMidPanel;
    275275    procedure MainOffscreenPaint;
    276     procedure MiniPaint;
     276    procedure MiniMapPaint;
    277277    procedure PaintAll;
    278278    procedure PaintAllMaps;
     
    12661266procedure TMainScreen.SetMapOptions;
    12671267begin
     1268  MiniMap.Options := MapOptionChecked;
    12681269  IsoEngine.Options := MapOptionChecked;
    12691270  if ClientMode = cEditMap then
     
    25862587        GameMode := Command;
    25872588        GrExt.ResetPixUsed;
    2588         IsoEngine.Reset;
     2589        IsoEngineReset;
    25892590        Tribes.Init;
    25902591        GetTribeList;
     
    26392640        CityDlg.Reset;
    26402641
    2641         Mini.SetSize(G.lx * 2, G.ly);
     2642        MiniMap.Size := Point(G.lx, G.ly);
    26422643        for i := 0 to nPl - 1 do
    26432644        begin
     
    28422843          MyData := G.RO[NewPlayer].Data;
    28432844          SetTroopLoc(-1);
    2844           MiniPaint;
     2845          MiniMapPaint;
    28452846          InitAllEnemyModels; // necessary for correct replay
    28462847          if not EndTurn(true) then
     
    35243525  end;
    35253526
    3526   Mini := TBitmap.Create;
    3527   Mini.PixelFormat := pf24bit;
     3527  MiniMap := TMiniMap.Create;
    35283528  Panel := TBitmap.Create;
    35293529  Panel.PixelFormat := pf24bit;
     
    35603560  FreeAndNil(sb);
    35613561  FreeAndNil(TopBar);
    3562   FreeAndNil(Mini);
     3562  FreeAndNil(MiniMap);
    35633563  FreeAndNil(Buffer);
    35643564  FreeAndNil(Panel);
     
    41064106end;
    41074107
    4108 procedure TMainScreen.MiniPaint;
    4109 var
    4110   uix, cix, x, y, Loc, i, hw, xm, cm, cmPolOcean, cmPolNone: integer;
    4111   PrevMiniPixel: TPixelPointer;
    4112   MiniPixel: TPixelPointer;
    4113   TerrainTile: Cardinal;
    4114 begin
    4115   if not Assigned(MyMap) then Exit;
    4116   cmPolOcean := HGrSystem.Data.Canvas.Pixels[101, 67];
    4117   cmPolNone := HGrSystem.Data.Canvas.Pixels[102, 67];
    4118   hw := MapWidth div (xxt * 2);
    4119   with Mini.Canvas do begin
    4120     Brush.Color := $000000;
    4121     FillRect(Rect(0, 0, Mini.width, Mini.height));
    4122   end;
    4123   Mini.BeginUpdate;
    4124   MiniPixel := PixelPointer(Mini);
    4125   PrevMiniPixel := PixelPointer(Mini);
    4126   for y := 0 to ScaleToNative(G.ly) - 1 do begin
    4127     for x := 0 to ScaleToNative(G.lx) - 1 do begin
    4128       Loc := ScaleFromNative(x) + G.lx * ScaleFromNative(y);
    4129       if (MyMap[Loc] and fTerrain) <> fUNKNOWN then begin
    4130         for i := 0 to 1 do begin
    4131           xm := ((x - ScaleToNative(xwMini)) * 2 + i + y and 1 - ScaleToNative(hw) +
    4132             ScaleToNative(G.lx) * 5) mod (ScaleToNative(G.lx) * 2);
    4133           MiniPixel.SetXY(xm, y);
    4134           TerrainTile := MyMap[Loc] and fTerrain;
    4135           if TerrainTile > 11 then TerrainTile := 0;
    4136           cm := MiniColors[TerrainTile, i];
    4137           if ClientMode = cEditMap then
    4138           begin
    4139             if MyMap[Loc] and (fPrefStartPos or fStartPos) <> 0 then
    4140               cm := $FFFFFF;
    4141           end
    4142           else if MyMap[Loc] and fCity <> 0 then
    4143           begin
    4144             cix := MyRO.nCity - 1;
    4145             while (cix >= 0) and (MyCity[cix].Loc <> Loc) do
    4146               dec(cix);
    4147             if cix >= 0 then
    4148               cm := Tribe[me].Color
    4149             else
    4150             begin
    4151               cix := MyRO.nEnemyCity - 1;
    4152               while (cix >= 0) and (MyRO.EnemyCity[cix].Loc <> Loc) do
    4153                 dec(cix);
    4154               if cix >= 0 then
    4155                 cm := Tribe[MyRO.EnemyCity[cix].Owner].Color
    4156             end;
    4157             cm := $808080 or cm shr 1; { increase brightness }
    4158             if y > 0 then begin
    4159               // 2x2 city dot covers two lines
    4160               PrevMiniPixel.SetXY(xm, y - 1);
    4161               PrevMiniPixel.Pixel^.B := cm shr 16;
    4162               PrevMiniPixel.Pixel^.G := cm shr 8 and $FF;
    4163               PrevMiniPixel.Pixel^.R := cm and $FF;
    4164             end;
    4165           end
    4166           else if (i = 0) and (MyMap[Loc] and fUnit <> 0) then
    4167           begin
    4168             uix := MyRO.nUn - 1;
    4169             while (uix >= 0) and (MyUn[uix].Loc <> Loc) do
    4170               dec(uix);
    4171             if uix >= 0 then
    4172               cm := Tribe[me].Color
    4173             else
    4174             begin
    4175               uix := MyRO.nEnemyUn - 1;
    4176               while (uix >= 0) and (MyRO.EnemyUn[uix].Loc <> Loc) do
    4177                 dec(uix);
    4178               if uix >= 0 then
    4179                 cm := Tribe[MyRO.EnemyUn[uix].Owner].Color
    4180             end;
    4181             cm := $808080 or cm shr 1; { increase brightness }
    4182           end
    4183           else if MapOptionChecked and (1 shl moPolitical) <> 0 then
    4184           begin
    4185             if MyMap[Loc] and fTerrain < fGrass then
    4186               cm := cmPolOcean
    4187             else if MyRO.Territory[Loc] < 0 then
    4188               cm := cmPolNone
    4189             else
    4190               cm := Tribe[MyRO.Territory[Loc]].Color;
    4191           end;
    4192           MiniPixel.Pixel^.B := cm shr 16;
    4193           MiniPixel.Pixel^.G := cm shr 8 and $FF;
    4194           MiniPixel.Pixel^.R := cm and $FF;
    4195         end;
    4196       end;
    4197     end;
    4198   end;
    4199   Mini.EndUpdate;
    4200 end;
    4201 
    42024108{$IFDEF LINUX}
    42034109// Can't do scrolling of DC under Linux, then fallback into BitBlt.
     
    43274233end;
    43284234
     4235procedure TMainScreen.MiniMapPaint;
     4236begin
     4237  MiniMap.Paint(MyMap, MapWidth, ClientMode, xxt, xwMini);
     4238end;
     4239
    43294240procedure TMainScreen.PaintAll;
    43304241begin
     
    43324243  xwMini := xw;
    43334244  ywMini := yw;
    4334   MiniPaint;
     4245  MiniMapPaint;
    43354246  PanelPaint;
    43364247end;
     
    43414252  xwMini := xw;
    43424253  ywMini := yw;
    4343   MiniPaint;
     4254  MiniMapPaint;
    43444255  CopyMiniToPanel;
    43454256  RectInvalidate(xMini + 2, TopBarHeight + MapHeight - overlap + yMini + 2,
     
    43514262begin
    43524263  BitBltCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
    4353     Mini.Canvas, 0, 0);
     4264    MiniMap.Bitmap.Canvas, 0, 0);
    43544265  if MarkCityLoc >= 0 then
    43554266    Sprite(Panel, HGrSystem, xMini - 2 + (4 * G.lx + 2 * (MarkCityLoc mod G.lx)
     
    43584269      CityMark2.Height, CityMark2.Left, CityMark2.Top)
    43594270  else if ywmax <= 0 then
    4360     Frame(Panel.Canvas, xMini + 2 + G.lx - MapWidth div (xxt * 2), yMini + 2,
     4271    Frame(Panel.Canvas,
     4272      xMini + 2 + G.lx - MapWidth div (xxt * 2), yMini + 2,
    43614273      xMini + 1 + G.lx + MapWidth div (xxt * 2), yMini + 2 + G.ly - 1,
    43624274      MainTexture.clMark, MainTexture.clMark)
    43634275  else
    4364     Frame(Panel.Canvas, xMini + 2 + G.lx - MapWidth div (xxt * 2),
    4365       yMini + 2 + yw, xMini + 1 + G.lx + MapWidth div (xxt * 2),
    4366       yMini + yw + MapHeight div yyt, MainTexture.clMark, MainTexture.clMark);
     4276    Frame(Panel.Canvas,
     4277      xMini + 2 + G.lx - MapWidth div (xxt * 2), yMini + 2 + yw,
     4278      xMini + 1 + G.lx + MapWidth div (xxt * 2), yMini + yw + MapHeight div yyt,
     4279      MainTexture.clMark, MainTexture.clMark);
    43674280end;
    43684281
     
    50925005  xwMini := xw;
    50935006  ywMini := yw;
    5094   MiniPaint;
     5007  MiniMapPaint;
    50955008  CopyMiniToPanel;
    50965009  RectInvalidate(xMini + 2, TopBarHeight + MapHeight - overlap + yMini + 2,
     
    52985211      BrushLoc := MouseLoc;
    52995212      PaintLoc(MouseLoc, 2);
    5300       MiniPaint;
     5213      MiniMapPaint;
    53015214      BitBltCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
    5302         Mini.Canvas, 0, 0);
     5215        MiniMap.Bitmap.Canvas, 0, 0);
    53035216      if ywmax <= 0 then
    53045217        Frame(Panel.Canvas, xMini + 2 + G.lx - MapWidth div (2 * xxt),
     
    75707483          yw := ywmax;
    75717484      end;
    7572       BitBltCanvas(Buffer.Canvas, 0, 0, G.lx * 2, G.ly, Mini.Canvas, 0, 0);
     7485      BitBltCanvas(Buffer.Canvas, 0, 0, G.lx * 2, G.ly, MiniMap.Bitmap.Canvas, 0, 0);
    75737486      if ywmax <= 0 then
    75747487        Frame(Buffer.Canvas, x - xMini - 2 - MapWidth div (xxt * 2), 0,
     
    76007513    xwMini := xw;
    76017514    ywMini := yw;
    7602     MiniPaint;
     7515    MiniMapPaint;
    76037516    PanelPaint;
    76047517  end;
     
    78817794      end
    78827795      else if Flag = tfAllTechs then
    7883         TellNewModels
     7796        TellNewModels;
    78847797    end;
    78857798  end;
     
    78927805    MapOptionChecked := MapOptionChecked xor (1 shl (Tag shr 8));
    78937806    SetMapOptions;
    7894     ButtonIndex := MapOptionChecked shr (Tag shr 8) and 1 + 2
     7807    ButtonIndex := MapOptionChecked shr (Tag shr 8) and 1 + 2;
    78957808  end;
    78967809  if Sender = MapBtn0 then
    78977810  begin
    7898     MiniPaint;
    7899     PanelPaint
     7811    MiniMapPaint;
     7812    PanelPaint;
    79007813  end // update mini map only
    79017814  else
  • trunk/Protocol.pas

    r319 r326  
    12911291    Flags: Cardinal;
    12921292  end;
     1293  PUn = ^TUn;
    12931294
    12941295  { TCity }
     
    13141315    // array value =1 indicates built improvement
    13151316  end;
     1317  PCity = ^TCity;
    13161318
    13171319  TModel = packed record
     
    13521354    Flags: Word;
    13531355  end;
     1356  PUnitInfo = ^TUnitInfo;
    13541357
    13551358  TCityInfo = packed record
     
    13621365    Flags: Word;
    13631366  end;
     1367  PCityInfo = ^TCityInfo;
    13641368
    13651369  TModelInfo = packed record
     
    15911595
    15921596  TTileList = array [0 .. INFIN] of Cardinal;
     1597  PTileList = ^TTileList;
    15931598  TTileObservedLastList = array [0 .. INFIN] of SmallInt;
    15941599  TOwnerList = array [0 .. INFIN] of ShortInt;
  • trunk/UMiniMap.pas

    r320 r326  
    2222    Colors: array [0 .. 11, 0 .. 1] of TColor;
    2323    Mode: TMiniMode;
     24    Options: Integer;
    2425    procedure LoadFromLogFile(FileName: string; var LastTurn: Integer; DefaultSize: TPoint);
    2526    procedure LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);
    2627    procedure PaintRandom(Brightness, StartLandMass: Integer; WorldSize: TPoint);
    2728    procedure PaintFile(SaveMap: TMapArray);
     29    procedure Paint(MyMap: PTileList; MapWidth: Integer; ClientMode: Integer;
     30      xxt, xwMini: Integer);
    2831    constructor Create;
    2932    destructor Destroy; override;
     
    3437
    3538uses
    36   ScreenTools, UPixelPointer, Global, GameServer;
     39  ScreenTools, UPixelPointer, Global, GameServer, IsoEngine, Tribes, ClientTools;
     40
     41const
     42  // save map tile flags
     43  smOwned = $20;
     44  smUnit = $40;
     45  smCity = $80;
    3746
    3847{ TMiniMap }
     
    169178        xm := (x * 2 + i + y and 1) mod (ScaleToNative(Size.X) * 2);
    170179        MiniPixel.SetX(xm);
    171         cm := Colors
    172           [Map[ScaleFromNative(x) * lxmax div Size.X + lxmax *
     180        cm := Colors[Map[ScaleFromNative(x) * lxmax div Size.X + lxmax *
    173181          ((ScaleFromNative(y) * (lymax - 1) + Size.Y div 2) div (Size.Y - 1))] and
    174182          fTerrain, i];
     
    205213          if Tile and fTerrain = fUNKNOWN then
    206214            cm := $000000
    207           else if Tile and smCity <> 0 then
    208           begin
    209             if Tile and smOwned <> 0 then
    210               cm := OwnColor
    211             else
    212               cm := EnemyColor;
     215          else if Tile and smCity <> 0 then begin
     216            if Tile and smOwned <> 0 then cm := OwnColor
     217              else cm := EnemyColor;
    213218            if y > 0 then begin
    214219              // 2x2 city dot covers two lines
     
    219224            end;
    220225          end
    221           else if (i = 0) and (Tile and smUnit <> 0) then
    222             if Tile and smOwned <> 0 then
    223               cm := OwnColor
    224             else cm := EnemyColor
    225           else
     226          else if (i = 0) and (Tile and smUnit <> 0) then begin
     227            if Tile and smOwned <> 0 then cm := OwnColor
     228              else cm := EnemyColor;
     229          end else
    226230            cm := Colors[Tile and fTerrain, i];
    227231          MiniPixel.Pixel^.B := (cm shr 16) and $ff;
     
    237241end;
    238242
     243procedure TMiniMap.Paint(MyMap: PTileList; MapWidth: Integer; ClientMode: Integer;
     244  xxt, xwMini: Integer);
     245var
     246  x, y, Loc, i, hw, xm, cm, cmPolOcean, cmPolNone: integer;
     247  PrevMiniPixel: TPixelPointer;
     248  MiniPixel: TPixelPointer;
     249  TerrainTile: Cardinal;
     250  MyCity: PCity;
     251  EnemyCity: PCityInfo;
     252  MyUnit: PUn;
     253  EnemyUnit: PUnitInfo;
     254begin
     255  if not Assigned(MyMap) then Exit;
     256  cmPolOcean := HGrSystem.Data.Canvas.Pixels[101, 67];
     257  cmPolNone := HGrSystem.Data.Canvas.Pixels[102, 67];
     258  hw := MapWidth div (xxt * 2);
     259  with Bitmap.Canvas do begin
     260    Brush.Color := $000000;
     261    FillRect(Rect(0, 0, Bitmap.Width, Bitmap.Height));
     262  end;
     263  Bitmap.PixelFormat := pf24bit;
     264  Bitmap.SetSize(Size.X * 2, Size.Y);
     265  Bitmap.BeginUpdate;
     266  MiniPixel := PixelPointer(Bitmap);
     267  PrevMiniPixel := PixelPointer(Bitmap, 0, -1);
     268  for y := 0 to ScaleToNative(Size.Y) - 1 do begin
     269    for x := 0 to ScaleToNative(Size.X) - 1 do begin
     270      Loc := ScaleFromNative(x) + Size.X * ScaleFromNative(y);
     271      if (MyMap[Loc] and fTerrain) <> fUNKNOWN then begin
     272        for i := 0 to 1 do begin
     273          xm := ((x - ScaleToNative(xwMini)) * 2 + i + y and 1 - ScaleToNative(hw) +
     274            ScaleToNative(Size.X) * 5) mod (ScaleToNative(Size.X) * 2);
     275          MiniPixel.SetX(xm);
     276          TerrainTile := MyMap[Loc] and fTerrain;
     277          if TerrainTile > 11 then TerrainTile := 0;
     278          cm := Colors[TerrainTile, i];
     279          if ClientMode = cEditMap then begin
     280            if MyMap[Loc] and (fPrefStartPos or fStartPos) <> 0 then
     281              cm := $FFFFFF;
     282          end
     283          else if MyMap[Loc] and fCity <> 0 then begin
     284            // City
     285            MyCity := GetMyCityByLoc(Loc);
     286            if Assigned(MyCity) then cm := Tribe[me].Color
     287            else begin
     288              EnemyCity := GetEnemyCityByLoc(Loc);
     289              if Assigned(EnemyCity) then
     290                cm := Tribe[EnemyCity^.Owner].Color;
     291            end;
     292            cm := $808080 or cm shr 1; { increase brightness }
     293            if y > 0 then begin
     294              // 2x2 city dot covers two lines
     295              PrevMiniPixel.SetX(xm);
     296              PrevMiniPixel.Pixel^.B := (cm shr 16) and $ff;
     297              PrevMiniPixel.Pixel^.G := (cm shr 8) and $ff;
     298              PrevMiniPixel.Pixel^.R := (cm shr 0) and $ff;
     299            end;
     300          end
     301          else if (i = 0) and (MyMap[Loc] and fUnit <> 0) then begin
     302            // Unit
     303            MyUnit := GetMyUnitByLoc(Loc);
     304            if Assigned(MyUnit) then cm := Tribe[me].Color
     305            else begin
     306              EnemyUnit := GetEnemyUnitByLoc(Loc);
     307              if Assigned(EnemyUnit) then
     308                cm := Tribe[EnemyUnit.Owner].Color;
     309            end;
     310            cm := $808080 or cm shr 1; { increase brightness }
     311          end
     312          else if Options and (1 shl moPolitical) <> 0 then begin
     313            // Political
     314            if MyMap[Loc] and fTerrain < fGrass then
     315              cm := cmPolOcean
     316            else if MyRO.Territory[Loc] < 0 then
     317              cm := cmPolNone
     318            else
     319              cm := Tribe[MyRO.Territory[Loc]].Color;
     320          end;
     321          MiniPixel.Pixel^.B := (cm shr 16) and $ff;
     322          MiniPixel.Pixel^.G := (cm shr 8) and $ff;
     323          MiniPixel.Pixel^.R := (cm shr 0) and $ff;
     324        end;
     325      end;
     326    end;
     327    MiniPixel.NextLine;
     328    PrevMiniPixel.NextLine;
     329  end;
     330  Bitmap.EndUpdate;
     331end;
     332
    239333
    240334end.
Note: See TracChangeset for help on using the changeset viewer.