Ignore:
Timestamp:
Apr 21, 2024, 8:55:53 PM (4 weeks ago)
Author:
chronos
Message:
  • Modified: Optimize code with earlier break from for cycle evaluating boolean result.
  • Modified: Code cleanup.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/IsoEngine.pas

    r548 r549  
    3939    function IsShoreTile(Loc: Integer): Boolean;
    4040    procedure MakeDark(Line: PPixelPointer; Length: Integer);
     41    procedure NameCity(X, Y, Loc: Integer);
     42    procedure PaintBorder(X, Y, Loc, Tile: Integer);
     43    function PoleTile(Loc: Integer): Integer;
    4144    procedure SetTileSize(AValue: TTileSize);
    4245    procedure ShadeOutside(x0, y0, Width, Height, xm, ym: Integer);
     46    procedure ShowSpacePort(X, Y, Tile: Integer; CityInfo: TCityInfo);
    4347  protected
    4448    FOutput: TBitmap;
     
    803807end;
    804808
    805 function PoleTile(Loc: Integer): Integer;
     809function TIsoMap.PoleTile(Loc: Integer): Integer;
    806810begin { virtual pole tile }
    807811  Result := fUNKNOWN;
     
    10471051end;
    10481052
     1053procedure TIsoMap.NameCity(X, Y, Loc: Integer);
     1054var
     1055  cix, xs, W: Integer;
     1056  BehindCityInfo: TCityInfo;
     1057  S: string;
     1058  IsCapital: Boolean;
     1059begin
     1060  BehindCityInfo.Loc := Loc - 2 * G.lx;
     1061  if ShowCityNames and not (moEditMode in MapOptions) and
     1062    (BehindCityInfo.Loc >= 0) and (BehindCityInfo.Loc < G.lx * G.ly) and
     1063    (MyMap[BehindCityInfo.Loc] and fCity <> 0) then
     1064  begin
     1065    GetCityInfo(BehindCityInfo.Loc, cix, BehindCityInfo);
     1066    IsCapital := BehindCityInfo.Flags and ciCapital <> 0;
     1067    { if Showuix and (cix>=0) then s:=IntToStr(cix)
     1068      else } S := CityName(BehindCityInfo.ID);
     1069    W := FOutput.Canvas.TextWidth(S);
     1070    xs := X + xxt - (W + 1) div 2;
     1071    if IsCapital then
     1072      FOutput.Canvas.Font.Style := FOutput.Canvas.Font.Style + [TFontStyle.fsUnderline];
     1073    TextOut(xs + 1, Y - 9, $000000, S);
     1074    TextOut(xs, Y - 10, $FFFFFF, S);
     1075    if IsCapital then
     1076      FOutput.Canvas.Font.Style := FOutput.Canvas.Font.Style - [TFontStyle.fsUnderline];
     1077  end;
     1078end;
     1079
     1080procedure TIsoMap.PaintBorder(X, Y, Loc, Tile: Integer);
     1081var
     1082  dx, dy: Integer;
     1083  p1, p2, Loc1: Integer;
     1084begin
     1085  if ShowBorder and (Loc >= 0) and (Loc < G.lx * G.ly) and
     1086    (Tile and fTerrain <> fUNKNOWN) then begin
     1087    p1 := MyRO.Territory[Loc];
     1088    if (p1 >= 0) and (ShowMyBorder or (p1 <> Me)) then begin
     1089      if BordersOK^ and (1 shl p1) = 0 then begin
     1090        UnshareBitmap(Borders);
     1091        BitBltBitmap(Borders, 0, p1 * (yyt * 2), xxt * 2,
     1092          yyt * 2, HGrTerrain.Data,
     1093          1 + 8 * (xxt * 2 + 1), 1 + yyt + 16 * (yyt * 3 + 1));
     1094        BitmapReplaceColor(Borders, 0, p1 * (yyt * 2), xxt * 2, yyt * 2, $636363, Tribe[p1].Color);
     1095        BordersOK^ := BordersOK^ or 1 shl p1;
     1096      end;
     1097      for dy := 0 to 1 do
     1098        for dx := 0 to 1 do begin
     1099          Loc1 := dLoc(Loc, dx * 2 - 1, dy * 2 - 1);
     1100          begin
     1101            if (Loc1 < 0) or (Loc1 >= G.lx * G.ly) then
     1102              p2 := -1
     1103            else if MyMap[Loc1] and fTerrain = fUNKNOWN then
     1104              p2 := p1
     1105            else
     1106              p2 := MyRO.Territory[Loc1];
     1107            if p2 <> p1 then
     1108            begin
     1109              BitBltBitmapOutput(HGrTerrain.Mask, X + dx * xxt, Y + dy * yyt, xxt,
     1110                yyt, 1 + 8 * (xxt * 2 + 1) + dx * xxt,
     1111                1 + yyt + 16 * (yyt * 3 + 1) + dy * yyt, SRCAND);
     1112              BitBltBitmapOutput(Borders, X + dx * xxt, Y + dy * yyt, xxt, yyt, dx * xxt,
     1113                p1 * (yyt * 2) + dy * yyt, SRCPAINT);
     1114            end;
     1115          end;
     1116        end;
     1117    end;
     1118  end;
     1119end;
     1120
     1121procedure TIsoMap.ShowSpacePort(X, Y, Tile: Integer; CityInfo: TCityInfo);
     1122begin
     1123  if ShowObjects and not (moEditMode in MapOptions) and
     1124    (Tile and fCity <> 0) and (CityInfo.Flags and ciSpacePort <> 0) then
     1125    TerrainSprite(X + xxt, Y - 6, spSpacePort);
     1126end;
     1127
    10491128// (x,y) is top left pixel of (2*xxt,3*yyt) rectangle
    10501129procedure TIsoMap.PaintTileObjects(X, Y, Loc, CityLoc, CityOwner: Integer;
    10511130  UseBlink: Boolean);
    10521131var
    1053   p1, p2, uix, cix, dy, Loc1, Tile, Multi, Destination: Integer;
     1132  uix, cix, dy, Tile, Multi, Destination: Integer;
    10541133  CityInfo: TCityInfo;
    10551134  UnitInfo: TUnitInfo;
     
    10571136  SpecialRow: Integer;
    10581137  SpecialCol: Integer;
    1059 
    1060   procedure NameCity;
    1061   var
    1062     cix, xs, W: Integer;
    1063     BehindCityInfo: TCityInfo;
    1064     S: string;
    1065     IsCapital: Boolean;
    1066   begin
    1067     BehindCityInfo.Loc := Loc - 2 * G.lx;
    1068     if ShowCityNames and not (moEditMode in MapOptions) and
    1069       (BehindCityInfo.Loc >= 0) and (BehindCityInfo.Loc < G.lx * G.ly) and
    1070       (MyMap[BehindCityInfo.Loc] and fCity <> 0) then
    1071     begin
    1072       GetCityInfo(BehindCityInfo.Loc, cix, BehindCityInfo);
    1073       IsCapital := BehindCityInfo.Flags and ciCapital <> 0;
    1074       { if Showuix and (cix>=0) then s:=IntToStr(cix)
    1075         else } S := CityName(BehindCityInfo.ID);
    1076       W := FOutput.Canvas.TextWidth(S);
    1077       xs := X + xxt - (W + 1) div 2;
    1078       if IsCapital then
    1079         FOutput.Canvas.Font.Style := FOutput.Canvas.Font.Style + [TFontStyle.fsUnderline];
    1080       TextOut(xs + 1, Y - 9, $000000, S);
    1081       TextOut(xs, Y - 10, $FFFFFF, S);
    1082       if IsCapital then
    1083         FOutput.Canvas.Font.Style := FOutput.Canvas.Font.Style - [TFontStyle.fsUnderline];
    1084     end;
    1085   end;
    1086 
    1087   procedure ShowSpacePort;
    1088   begin
    1089     if ShowObjects and not (moEditMode in MapOptions) and
    1090       (Tile and fCity <> 0) and (CityInfo.Flags and ciSpacePort <> 0) then
    1091       TerrainSprite(X + xxt, Y - 6, spSpacePort);
    1092   end;
    1093 
    1094   procedure PaintBorder;
    1095   var
    1096     dx, dy: Integer;
    1097   begin
    1098     if ShowBorder and (Loc >= 0) and (Loc < G.lx * G.ly) and
    1099       (Tile and fTerrain <> fUNKNOWN) then begin
    1100       p1 := MyRO.Territory[Loc];
    1101       if (p1 >= 0) and (ShowMyBorder or (p1 <> Me)) then begin
    1102         if BordersOK^ and (1 shl p1) = 0 then begin
    1103           UnshareBitmap(Borders);
    1104           BitBltBitmap(Borders, 0, p1 * (yyt * 2), xxt * 2,
    1105             yyt * 2, HGrTerrain.Data,
    1106             1 + 8 * (xxt * 2 + 1), 1 + yyt + 16 * (yyt * 3 + 1));
    1107           BitmapReplaceColor(Borders, 0, p1 * (yyt * 2), xxt * 2, yyt * 2, $636363, Tribe[p1].Color);
    1108           BordersOK^ := BordersOK^ or 1 shl p1;
    1109         end;
    1110         for dy := 0 to 1 do
    1111           for dx := 0 to 1 do begin
    1112             Loc1 := dLoc(Loc, dx * 2 - 1, dy * 2 - 1);
    1113             begin
    1114               if (Loc1 < 0) or (Loc1 >= G.lx * G.ly) then
    1115                 p2 := -1
    1116               else if MyMap[Loc1] and fTerrain = fUNKNOWN then
    1117                 p2 := p1
    1118               else
    1119                 p2 := MyRO.Territory[Loc1];
    1120               if p2 <> p1 then
    1121               begin
    1122                 BitBltBitmapOutput(HGrTerrain.Mask, X + dx * xxt, Y + dy * yyt, xxt,
    1123                   yyt, 1 + 8 * (xxt * 2 + 1) + dx * xxt,
    1124                   1 + yyt + 16 * (yyt * 3 + 1) + dy * yyt, SRCAND);
    1125                 BitBltBitmapOutput(Borders, X + dx * xxt, Y + dy * yyt, xxt, yyt, dx * xxt,
    1126                   p1 * (yyt * 2) + dy * yyt, SRCPAINT);
    1127               end;
    1128             end;
    1129           end;
    1130       end;
    1131     end;
    1132   end;
    1133 
    11341138begin
    11351139  if (Loc < 0) or (Loc >= G.lx * G.ly) then
     
    11431147    (X > FRight) then
    11441148  begin
    1145     NameCity;
    1146     ShowSpacePort;
     1149    NameCity(X, Y, Loc);
     1150    ShowSpacePort(X, Y, Tile, CityInfo);
    11471151    Exit;
    11481152  end;
    11491153  if Tile and fTerrain = fUNKNOWN then
    11501154  begin
    1151     NameCity;
    1152     ShowSpacePort;
     1155    NameCity(X, Y, Loc);
     1156    ShowSpacePort(X, Y, Tile, CityInfo);
    11531157    Exit;
    11541158  end; { square not discovered }
    11551159
    11561160  if not (FoW and (Tile and fObserved = 0)) then
    1157     PaintBorder;
     1161    PaintBorder(X, Y, Loc, Tile);
    11581162
    11591163  if (Loc >= 0) and (Loc < G.lx * G.ly) and (Loc = FAdviceLoc) then
     
    12111215
    12121216  if FoW and (Tile and fObserved = 0) then
    1213     PaintBorder;
     1217    PaintBorder(X, Y, Loc, Tile);
    12141218
    12151219{$IFNDEF SCR}
     
    12391243      else TerrainSprite(X, Y, 8 + 9 * 1); }
    12401244
    1241     NameCity;
    1242     ShowSpacePort;
     1245    NameCity(X, Y, Loc);
     1246    ShowSpacePort(X, Y, Tile, CityInfo);
    12431247    if Tile and fCity <> 0 then
    12441248      PaintCity(X + xxt, Y + yyt, CityInfo, CityOwner < 0);
     
    13831387begin
    13841388  Result := False;
    1385   for Dir := 0 to 7 do
    1386   begin
     1389  for Dir := 0 to 7 do begin
    13871390    ConnLoc := dLoc(Loc, Dirx[Dir], Diry[Dir]);
    13881391    if (ConnLoc < 0) or (ConnLoc >= G.lx * G.ly) or
    1389       ((MyMap[ConnLoc] - 2) and fTerrain < 13) then
    1390       Result := True;
     1392      ((MyMap[ConnLoc] - 2) and fTerrain < 13) then begin
     1393        Result := True;
     1394        Break;
     1395      end;
    13911396  end;
    13921397end;
Note: See TracChangeset for help on using the changeset viewer.