Ignore:
Timestamp:
Nov 30, 2023, 10:16:14 PM (18 months ago)
Author:
chronos
Message:
  • Modified: Updated high dpi branch from trunk.
  • Modified: Use generics.collections instead of fgl.
  • Modified: Compile with Delphi syntax.
Location:
branches/highdpi/LocalPlayer
Files:
25 edited
1 moved

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/highdpi/LocalPlayer/Battle.pas

    r361 r465  
    3232    uix, ToLoc: Integer;
    3333    Forecast: TBattleForecastEx;
    34     IsSuicideQuery: boolean;
    35   end;
    36 
    37 var
    38   BattleDlg: TBattleDlg;
     34    IsSuicideQuery: Boolean;
     35  end;
     36
    3937
    4038implementation
     
    6260  TextSize: TSize;
    6361  LabelText: string;
    64   FirstStrike: boolean;
     62  FirstStrike: Boolean;
    6563begin
    6664  MaxBar := 65;
     
    112110    VLightGradient(ca, xm - 8, ym + 8 + LABaseDamage, LADamage - LABaseDamage,
    113111      FanaticColor);
    114   DpiBitCanvas(ca, xm - 12, ym - 12, 24, 24,
     112  DpiBitBltCanvas(ca, xm - 12, ym - 12, 24, 24,
    115113    HGrSystem.Mask.Canvas, 26, 146, SRCAND);
    116   DpiBitCanvas(ca, xm - 12, ym - 12, 24, 24,
     114  DpiBitBltCanvas(ca, xm - 12, ym - 12, 24, 24,
    117115    HGrSystem.Data.Canvas, 26, 146, SRCPAINT);
    118116
     
    137135  if Forecast.EndHealthDef <= 0 then
    138136  begin
    139     DpiBitCanvas(ca, xm + 9 + LDDamage - 7, ym - 6, 14, 17,
     137    DpiBitBltCanvas(ca, xm + 9 + LDDamage - 7, ym - 6, 14, 17,
    140138      HGrSystem.Mask.Canvas, 51, 153, SRCAND);
    141     DpiBitCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
     139    DpiBitBltCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
    142140      HGrSystem.Mask.Canvas, 51, 153, SRCAND);
    143     DpiBitCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
     141    DpiBitBltCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
    144142      HGrSystem.Data.Canvas, 51, 153, SRCPAINT);
    145143  end;
     
    149147  begin
    150148    if Forecast.EndHealthDef > 0 then
    151       RisedTextOut(ca, xm + 10, ym - (TextSize.cy + 1) div 2, LabelText)
     149      RisedTextOut(ca, xm + 10, ym - (TextSize.cy + 1) div 2, LabelText);
    152150  end
    153151  else
     
    157155  if Forecast.EndHealthAtt <= 0 then
    158156  begin
    159     DpiBitCanvas(ca, xm - 6, ym + 9 + LADamage - 7, 14, 17,
     157    DpiBitBltCanvas(ca, xm - 6, ym + 9 + LADamage - 7, 14, 17,
    160158      HGrSystem.Mask.Canvas, 51, 153, SRCAND);
    161     DpiBitCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
     159    DpiBitBltCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
    162160      HGrSystem.Mask.Canvas, 51, 153, SRCAND);
    163     DpiBitCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
     161    DpiBitBltCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
    164162      HGrSystem.Data.Canvas, 51, 153, SRCPAINT);
    165163  end;
     
    171169    if Forecast.EndHealthAtt > 0 then
    172170      RisedTextOut(ca, xm - (TextSize.cx + 1) div 2, ym + 8 + LAAvoidedDamage,
    173         LabelText)
     171        LabelText);
    174172  end
    175173  else
     
    178176
    179177  IsoMap.SetOutput(Buffer);
    180   DpiBitCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm + 8 + 4,
     178  DpiBitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm + 8 + 4,
    181179    ym - 8 - 12 - 48);
    182180  { if TerrType<fForest then
     
    190188    end; }
    191189  IsoMap.PaintUnit(1, 0, UnitInfo, 0);
    192   DpiBitCanvas(ca, xm + 8 + 4, ym - 8 - 12 - 48, 66, 48, Buffer.Canvas,
     190  DpiBitBltCanvas(ca, xm + 8 + 4, ym - 8 - 12 - 48, 66, 48, Buffer.Canvas,
    193191    0, 0);
    194192
    195   DpiBitCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm - 8 - 4 - 66,
     193  DpiBitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm - 8 - 4 - 66,
    196194    ym + 8 + 12);
    197   MakeUnitInfo(me, MyUn[uix], UnitInfo);
     195  MakeUnitInfo(Me, MyUn[uix], UnitInfo);
    198196  UnitInfo.Flags := UnitInfo.Flags and not unFortified;
    199197  IsoMap.PaintUnit(1, 0, UnitInfo, 0);
    200   DpiBitCanvas(ca, xm - 8 - 4 - 66, ym + 8 + 12, 66, 48, Buffer.Canvas, 0, 0);
    201 end; { PaintBattleOutcome }
     198  DpiBitBltCanvas(ca, xm - 8 - 4 - 66, ym + 8 + 12, 66, 48, Buffer.Canvas, 0, 0);
     199end;
    202200
    203201procedure TBattleDlg.FormCreate(Sender: TObject);
     
    215213    ClientWidth := 300;
    216214    ClientHeight := 288;
    217     OKBtn.Visible := true;
    218     CancelBtn.Visible := true;
     215    OKBtn.Visible := True;
     216    CancelBtn.Visible := True;
    219217    Left := (DpiScreen.Width - ClientWidth) div 2; // center on screen
    220218    Top := (DpiScreen.Height - ClientHeight) div 2;
     
    224222    ClientWidth := 178;
    225223    ClientHeight := 178;
    226     OKBtn.Visible := false;
    227     CancelBtn.Visible := false;
     224    OKBtn.Visible := False;
     225    CancelBtn.Visible := False;
    228226  end;
    229227end;
     
    231229procedure TBattleDlg.FormPaint(Sender: TObject);
    232230var
    233   ym, cix, p: Integer;
    234   s, s1: string;
     231  ym, cix, P: Integer;
     232  S, s1: string;
    235233begin
    236234  with Canvas do
     
    240238    Brush.Style := bsClear;
    241239    PaintBackground(self, 3 + Border, 3 + Border,
    242       ClientWidth - (6 + 2 * Border), ClientHeight - (6 + 2 * Border))
     240      ClientWidth - (6 + 2 * Border), ClientHeight - (6 + 2 * Border));
    243241  end;
    244242  Frame(Canvas, Border + 1, Border + 1, ClientWidth - (2 + Border),
     
    252250  begin
    253251    Canvas.Font.Assign(UniFont[ftCaption]);
    254     s := Phrases.Lookup('TITLE_SUICIDE');
    255     RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
    256       7 + Border, s);
     252    S := Phrases.Lookup('TITLE_SUICIDE');
     253    RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
     254      7 + Border, S);
    257255    Canvas.Font.Assign(UniFont[ftNormal]);
    258     s := Phrases.Lookup('SUICIDE');
    259     p := pos('\', s);
    260     if p = 0 then
    261       RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s))
    262         div 2, 205, s)
     256    S := Phrases.Lookup('SUICIDE');
     257    P := Pos('\', S);
     258    if P = 0 then
     259      RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S))
     260        div 2, 205, S)
    263261    else
    264262    begin
    265       s1 := copy(s, 1, p - 1);
     263      s1 := Copy(S, 1, P - 1);
    266264      RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2,
    267265        205 - MessageLineSpacing div 2, s1);
    268       s1 := copy(s, p + 1, 255);
     266      s1 := Copy(S, P + 1, 255);
    269267      RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2,
    270268        205 + (MessageLineSpacing - MessageLineSpacing div 2), s1);
    271269    end;
    272     ym := 110
     270    ym := 110;
    273271  end
    274272  else
     
    297295begin
    298296  if not IsSuicideQuery then
    299     Close
     297    Close;
    300298end;
    301299
     
    309307    if Key <> VK_ESCAPE then
    310308      MainScreen.FormKeyDown(Sender, Key, Shift);
    311   end
     309  end;
    312310end;
    313311
  • TabularUnified branches/highdpi/LocalPlayer/CityScreen.pas

    r405 r465  
    55
    66uses
    7   UDpiControls, {$IFDEF LINUX}LMessages,{$ENDIF}
    8   Protocol, ClientTools, Term, ScreenTools, IsoEngine, BaseWin,
    9   LCLIntf, LCLType, Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,
    10   ButtonA, ButtonC, Area, GraphType, UTexture;
     7  UDpiControls, {$IFDEF UNIX}LMessages,{$ENDIF}
     8  Protocol, ClientTools, ScreenTools, IsoEngine, BaseWin, LCLIntf, LCLType,
     9  Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls, ButtonA,
     10  ButtonC, Area, GraphType, Texture;
    1111
    1212const
     
    3939    procedure FormDestroy(Sender: TObject);
    4040    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
    41       Shift: TShiftState; x, y: integer);
     41      Shift: TShiftState; X, Y: Integer);
    4242    procedure BuyClick(Sender: TObject);
    4343    procedure CloseBtnClick(Sender: TObject);
     
    4949    procedure PrevCityBtnClick(Sender: TObject);
    5050    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    51     // procedure AdviceBtnClick(Sender: TObject);
    5251    procedure PageUpBtnClick(Sender: TObject);
    5352    procedure PageDownBtnClick(Sender: TObject);
    5453  private
    55     c: TCity;
     54    C: TCity;
    5655    Report: TCityReportNew;
    5756    cOwner: Integer;
     
    7069    Optimize_cixTileChange: Integer;
    7170    Optimize_TilesBeforeChange: Integer;
    72     Happened: cardinal;
    73     imix: array [0 .. 15] of integer;
     71    Happened: Cardinal;
     72    imix: array [0 .. 15] of Integer;
    7473    CityAreaInfo: TCityAreaInfo;
    7574    AreaMap: TIsoMap;
     
    8988    procedure InitZoomCityMap;
    9089    procedure ChooseProject;
    91     procedure ChangeCity(d: integer);
    92     procedure ChangeResourceWeights(iResourceWeights: integer);
     90    procedure ChangeCity(D: Integer);
     91    procedure ChangeResourceWeights(iResourceWeights: Integer);
    9392    procedure OnPlaySound(var Msg: TMessage); message WM_PLAYSOUND;
    9493  public
    95     RestoreUnFocus: integer;
     94    RestoreUnFocus: Integer;
    9695    CloseAction: TCityCloseAction;
    9796    procedure OffscreenPaint; override;
    98     procedure ShowNewContent(NewMode, Loc: integer; ShowEvent: cardinal);
     97    procedure ShowNewContent(NewMode: TWindowMode; Loc: Integer; ShowEvent: Cardinal);
    9998    procedure Reset;
    10099    procedure CheckAge;
    101100  end;
    102101
    103 var
    104   CityDlg: TCityDlg;
    105 
    106102
    107103implementation
    108104
    109105uses
    110   Select, Messg, MessgEx, Help, Tribes, Directories, Math, Sound;
     106  Select, Messg, MessgEx, Help, Tribes, Directories, Math, Sound, Term;
    111107
    112108{$R *.lfm}
     
    148144  wZoomEnvironment = 68;
    149145
    150   ImpPosition: array [28 .. nImp - 1] of integer = (-1, // imTrGoods
     146  ImpPosition: array [28 .. nImp - 1] of Integer = (
     147    -1, // imTrGoods
    151148    21, // imBarracks
    152149    6, // imGranary
     
    192189
    193190var
    194   ImpSorted: array [0 .. nImp - 1] of integer;
     191  ImpSorted: array [0 .. nImp - 1] of Integer;
    195192
    196193procedure TCityDlg.FormCreate(Sender: TObject);
     
    201198  NoMap := TIsoMap.Create;
    202199  AreaMap := TIsoMap.Create;
    203   AreaMap.SetOutput(offscreen);
     200  AreaMap.SetOutput(Offscreen);
    204201  AreaMap.SetPaintBounds(xmArea - 192, ymArea - 96 - 32, xmArea + 192,
    205202    ymArea + 96);
    206   SmallMapMode := smImprovements;
    207   ZoomArea := 1;
    208   ProdHint := false;
     203  Reset;
     204  ProdHint := False;
    209205  RestoreUnFocus := -1;
    210206  OpenSoundEvent := -1;
     
    279275
    280276    UnshareBitmap(Back);
    281     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
     277    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
    282278      MainTexture.Image.Canvas, 0, 0);
    283279    ImageOp_B(Back, Template, 0, 0, 0, 0, ClientWidth, ClientHeight);
     
    292288procedure TCityDlg.InitSmallCityMap;
    293289var
    294   i, iix, cli1, Color0, Color1, Color2: integer;
     290  I, iix, cli1, Color0, Color1, Color2: Integer;
    295291begin
    296292  if cix >= 0 then
    297     c := MyCity[cix];
     293    C := MyCity[cix];
    298294  case MyMap[cLoc] and fTerrain of
    299295    fPrairie: cli1 := cliPrairie;
     
    307303  Color2 := Colors.Canvas.Pixels[clkAge0 + Age, cliHouse];
    308304  SmallCityMap.Canvas.FillRect(0, 0, SmallCityMap.Width, SmallCityMap.Height);
    309   DpiBitCanvas(SmallCityMap.Canvas, 0, 0, 83, hSmallMap,
     305  DpiBitBltCanvas(SmallCityMap.Canvas, 0, 0, 83, hSmallMap,
    310306    SmallCityMapTemplate.Canvas, 83 * SizeClass, 0);
    311307  if IsPort then
    312308  begin
    313     DpiBitCanvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap,
     309    DpiBitBltCanvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap,
    314310      SmallCityMapTemplate.Canvas, 332 + 15, 0);
    315311    ImageOp_CCC(SmallCityMap, 0, 0, 83, hSmallMap, Color0, Color1, Color2);
     
    319315  else
    320316  begin
    321     DpiBitCanvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap,
     317    DpiBitBltCanvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap,
    322318      SmallCityMapTemplate.Canvas, 332, 0);
    323319    ImageOp_CCC(SmallCityMap, 0, 0, wSmallMap, hSmallMap, Color0,
     
    328324  begin
    329325    Brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImp];
    330     for i := 0 to 29 do
     326    for I := 0 to 29 do
    331327    begin
    332328      for iix := nWonder to nImp - 1 do
    333         if (ImpPosition[iix] = i) and (c.Built[iix] > 0) then
     329        if (ImpPosition[iix] = I) and (C.Built[iix] > 0) then
    334330        begin
    335           FillRect(Rect(5 + 16 * (i mod 3) + 48 * (i div 18),
    336             3 + 12 * (i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (i div 18),
    337             11 + 12 * (i mod 18 div 3)));
    338           break;
     331          FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18),
     332            3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18),
     333            11 + 12 * (I mod 18 div 3)));
     334          Break;
    339335        end;
    340336    end;
    341     i := 30;
     337    I := 30;
    342338    for iix := 0 to nImp do
    343       if (c.Built[iix] > 0) and ((iix < nWonder) or (ImpPosition[iix] < 0)) then
     339      if (C.Built[iix] > 0) and ((iix < nWonder) or (ImpPosition[iix] < 0)) then
    344340      begin
    345         FillRect(Rect(5 + 16 * (i mod 3) + 48 * (i div 18),
    346           3 + 12 * (i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (i div 18),
    347           11 + 12 * (i mod 18 div 3)));
    348         inc(i);
    349         if i = 36 then
    350           break; // area is full
     341        FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18),
     342          3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18),
     343          11 + 12 * (I mod 18 div 3)));
     344        Inc(I);
     345        if I = 36 then
     346          Break; // area is full
    351347      end;
    352     if c.Project and cpImp <> 0 then
    353     begin
    354       iix := c.Project and cpIndex;
     348    if C.Project and cpImp <> 0 then
     349    begin
     350      iix := C.Project and cpIndex;
    355351      if iix <> imTrGoods then
    356352      begin
    357353        if (iix >= nWonder) and (ImpPosition[iix] >= 0) then
    358           i := ImpPosition[iix];
    359         if i < 36 then
     354          I := ImpPosition[iix];
     355        if I < 36 then
    360356        begin
    361           brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImpProject];
    362           FillRect(Rect(5 + 16 * (i mod 3) + 48 * (i div 18),
    363             3 + 12 * (i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (i div 18),
    364             11 + 12 * (i mod 18 div 3)));
     357          Brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImpProject];
     358          FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18),
     359            3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18),
     360            11 + 12 * (I mod 18 div 3)));
    365361        end;
    366362      end;
    367363    end;
    368     brush.style := bsClear;
     364    Brush.style := bsClear;
    369365  end;
    370366end;
     
    373369begin
    374370  UnshareBitmap(ZoomCityMap);
    375   DpiBitCanvas(ZoomCityMap.Canvas, 0, 0, wZoomMap, hZoomMap,
     371  DpiBitBltCanvas(ZoomCityMap.Canvas, 0, 0, wZoomMap, hZoomMap,
    376372    Back.Canvas, xZoomMap, yZoomMap);
    377373  if SmallMapMode = smImprovements then begin
     
    383379        112 * (ZoomArea - 3), wZoomMap - wZoomEnvironment, hZoomMap);
    384380      ImageOp_B(ZoomCityMap, CityMapTemplate, wZoomMap - wZoomEnvironment, 0,
    385         1504 + wZoomEnvironment * byte(IsPort), 112 * (ZoomArea - 3),
     381        1504 + wZoomEnvironment * Byte(IsPort), 112 * (ZoomArea - 3),
    386382        wZoomEnvironment, hZoomMap);
    387383    end;
     
    391387procedure TCityDlg.OffscreenPaint;
    392388
    393   procedure FillBar(x, y, pos, Growth, max, Kind: integer;
    394     IndicateComplete: boolean);
     389  procedure FillBar(X, Y, Pos, Growth, Max, Kind: Integer;
     390    IndicateComplete: Boolean);
    395391  begin
    396392    BarTex.Assign(MainTexture);
     
    399395      BarTex.ColorBevelShade := BarTex.ColorBevelLight;
    400396    end;
    401     PaintRelativeProgressBar(offscreen.Canvas, Kind, x - 3, y, wBar - 4, pos,
    402       Growth, max, IndicateComplete, BarTex);
    403   end;
    404 
    405   procedure PaintResources(x, y, Loc: integer; Add4Happy: boolean);
     397    PaintRelativeProgressBar(Offscreen.Canvas, Kind, X - 3, Y, wBar - 4, Pos,
     398      Growth, Max, IndicateComplete, BarTex);
     399  end;
     400
     401  procedure PaintResources(X, Y, Loc: Integer; Add4Happy: Boolean);
    406402  var
    407     d, i, Total, xGr, yGr: integer;
     403    D, I, Total, xGr, yGr: Integer;
    408404    TileInfo: TTileInfo;
    409     rare: boolean;
     405    rare: Boolean;
    410406  begin
    411407    with AreaMap do begin
    412     if Server(sGetCityTileInfo, me, Loc, TileInfo) <> eOk then
    413     begin
    414       assert(cix < 0);
    415       exit
     408    if Server(sGetCityTileInfo, Me, Loc, TileInfo) <> eOk then
     409    begin
     410      Assert(cix < 0);
     411      Exit
    416412    end;
    417413    Total := TileInfo.Food + TileInfo.Prod + TileInfo.Trade;
    418414    rare := MyMap[Loc] and $06000000 > 0;
    419415    if rare then
    420       inc(Total);
     416      Inc(Total);
    421417    if Add4Happy then
    422       inc(Total, 4);
     418      Inc(Total, 4);
    423419    if Total > 1 then
    424       d := (xxt - 11) div (Total - 1);
    425     if d < 1 then
    426       d := 1;
    427     if d > 4 then
    428       d := 4;
    429     for i := 0 to Total - 1 do
     420      D := (xxt - 11) div (Total - 1);
     421    if D < 1 then
     422      D := 1;
     423    if D > 4 then
     424      D := 4;
     425    for I := 0 to Total - 1 do
    430426    begin
    431427      yGr := 115;
    432       if Add4Happy and (i >= Total - 4) then
     428      if Add4Happy and (I >= Total - 4) then
    433429      begin
    434430        xGr := 132;
    435431        yGr := 126
    436432      end
    437       else if rare and (i = Total - 1) then
     433      else if rare and (I = Total - 1) then
    438434        xGr := 66 + 110
    439       else if i >= TileInfo.Food + TileInfo.Prod then
     435      else if I >= TileInfo.Food + TileInfo.Prod then
    440436        xGr := 66 + 44
    441       else if i >= TileInfo.Prod then
     437      else if I >= TileInfo.Prod then
    442438        xGr := 66
    443439      else
    444440        xGr := 66 + 22;
    445       Sprite(offscreen, HGrSystem, x + xxt - 5 + d * (2 * i + 1 - Total),
    446         y + yyt - 5, 10, 10, xGr, yGr);
     441      Sprite(Offscreen, HGrSystem, X + xxt - 5 + D * (2 * I + 1 - Total),
     442        Y + yyt - 5, 10, 10, xGr, yGr);
    447443    end;
    448444    end;
    449445  end;
    450446var
    451   line, MessageCount: integer;
    452 
    453   procedure CheckMessage(Flag: integer);
     447  Line, MessageCount: Integer;
     448
     449  procedure CheckMessage(Flag: Integer);
    454450  var
    455     i, test: integer;
    456     s: string;
     451    I, Test: Integer;
     452    S: string;
    457453  begin
    458454    if Happened and Flag <> 0 then
    459455    begin
    460       i := 0;
    461       test := 1;
    462       while test < Flag do
     456      I := 0;
     457      Test := 1;
     458      while Test < Flag do
    463459      begin
    464         inc(i);
    465         inc(test, test)
     460        Inc(I);
     461        Inc(Test, Test);
    466462      end;
    467463
    468464      if AllowChange and (Sounds <> nil) and (OpenSoundEvent = -1) then
    469465      begin
    470         s := CityEventSoundItem[i];
    471         if s <> '' then
    472           s := Sounds.Lookup(s);
    473         if (Flag = chProduction) or (s <> '') and (s[1] <> '*') and (s[1] <> '[')
     466        S := CityEventSoundItem[I];
     467        if S <> '' then
     468          S := Sounds.Lookup(S);
     469        if (Flag = chProduction) or (S <> '') and (S[1] <> '*') and (S[1] <> '[')
    474470        then
    475           OpenSoundEvent := i
     471          OpenSoundEvent := I;
    476472      end;
    477473
    478       s := CityEventName(i);
     474      S := CityEventName(I);
    479475      { if Flag=chNoGrowthWarning then
    480         if c.Built[imAqueduct]=0 then
    481         s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
    482         else s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); }
    483       RisedTextOut(offscreen.Canvas, xmOpt + 40, ymOpt - 1 - 8 * MessageCount +
    484         16 * line, s);
    485       inc(line)
     476        if C.Built[imAqueduct]=0 then
     477        S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
     478        else S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); }
     479      RisedTextOut(Offscreen.Canvas, xmOpt + 40, ymOpt - 1 - 8 * MessageCount +
     480        16 * Line, S);
     481      Inc(Line);
    486482    end;
    487483  end;
    488484
    489485var
    490   x, y, xGr, i, j, iix, d, dx, dy, PrCost, Cnt, Loc1, FreeSupp, Paintiix,
    491     HappyGain, OptiType, rx, ry, TrueFood, TrueProd, TruePoll: integer;
    492   av: integer;
    493   PrName, s: string;
     486  X, Y, xGr, I, J, iix, D, dx, dy, PrCost, Cnt, Loc1, FreeSupp, Paintiix,
     487    HappyGain, OptiType, rx, ry, TrueFood, TrueProd, TruePoll: Integer;
     488  av: Integer;
     489  PrName, S: string;
    494490  UnitInfo: TUnitInfo;
    495491  UnitReport: TUnitReport;
    496   IsCityAlive, CanGrow: boolean;
     492  IsCityAlive, CanGrow: Boolean;
    497493begin
    498494  inherited;
    499495  if cix >= 0 then
    500     c := MyCity[cix];
     496    C := MyCity[cix];
    501497  Report.HypoTiles := -1;
    502498  Report.HypoTaxRate := -1;
    503499  Report.HypoLuxuryRate := -1;
    504500  if cix >= 0 then
    505     Server(sGetCityReportNew, me, cix, Report) // own city
     501    Server(sGetCityReportNew, Me, cix, Report) // own city
    506502  else
    507     Server(sGetEnemyCityReportNew, me, cLoc, Report); // enemy city
    508   TrueFood := c.Food;
    509   TrueProd := c.Prod;
    510   TruePoll := c.Pollution;
    511   if supervising or (cix < 0) then
     503    Server(sGetEnemyCityReportNew, Me, cLoc, Report); // enemy city
     504  TrueFood := C.Food;
     505  TrueProd := C.Prod;
     506  TruePoll := C.Pollution;
     507  if Supervising or (cix < 0) then
    512508  begin // normalize city from after-turn state
    513     dec(TrueFood, Report.FoodSurplus);
     509    Dec(TrueFood, Report.FoodSurplus);
    514510    if TrueFood < 0 then
    515511      TrueFood := 0; // shouldn't happen
    516     dec(TrueProd, Report.Production);
     512    Dec(TrueProd, Report.Production);
    517513    if TrueProd < 0 then
    518514      TrueProd := 0; // shouldn't happen
    519     dec(TruePoll, Report.AddPollution);
     515    Dec(TruePoll, Report.AddPollution);
    520516    if TruePoll < 0 then
    521517      TruePoll := 0; // shouldn't happen
    522518  end;
    523   IsCityAlive := (cGov <> gAnarchy) and (c.Flags and chCaptured = 0);
     519  IsCityAlive := (cGov <> gAnarchy) and (C.Flags and chCaptured = 0);
    524520  if not IsCityAlive then
    525     Report.Working := c.Size;
     521    Report.Working := C.Size;
    526522
    527523  RedTex.Assign(MainTexture);
     
    531527  RedTex.ColorTextShade := $0000FF;
    532528
    533   DpiBitCanvas(offscreen.Canvas, 0, 0, 640, 480, Back.Canvas, 0, 0);
     529  DpiBitBltCanvas(Offscreen.Canvas, 0, 0, 640, 480, Back.Canvas, 0, 0);
    534530
    535531  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    536   RisedTextOut(offscreen.Canvas, 42, 7, Caption);
    537   with offscreen.Canvas do
     532  RisedTextOut(Offscreen.Canvas, 42, 7, Caption);
     533  with Offscreen.Canvas do
    538534  begin // city size
    539     brush.Color := $000000;
     535    Brush.Color := $000000;
    540536    FillRect(Rect(8 + 1, 7 + 1, 36 + 1, 32 + 1));
    541     brush.Color := $FFFFFF;
     537    Brush.Color := $FFFFFF;
    542538    FillRect(Rect(8, 7, 36, 32));
    543     brush.style := bsClear;
     539    Brush.style := bsClear;
    544540    Font.Color := $000000;
    545     s := inttostr(c.Size);
    546     TextOut(8 + 14 - textwidth(s) div 2, 7, s);
     541    S := IntToStr(C.Size);
     542    TextOut(8 + 14 - TextWidth(S) div 2, 7, S);
    547543  end;
    548544  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     
    552548    MakeRed(Offscreen, 18, 280, 298, 40);
    553549    if cGov = gAnarchy then
    554       s := Phrases.Lookup('GOVERNMENT', gAnarchy)
     550      S := Phrases.Lookup('GOVERNMENT', gAnarchy)
    555551    else { if c.Flags and chCaptured<>0 then }
    556       s := Phrases.Lookup('CITYEVENTS', 14);
    557     RisedTextOut(offscreen.Canvas, 167 - BiColorTextWidth(offscreen.Canvas, s)
    558       div 2, ymOpt - 9, s);
     552      S := Phrases.Lookup('CITYEVENTS', 14);
     553    RisedTextOut(Offscreen.Canvas, 167 - BiColorTextWidth(Offscreen.Canvas, S)
     554      div 2, ymOpt - 9, S);
    559555  end
    560556  else if AllowChange then
    561557  begin
    562     OptiType := c.Status shr 4 and $0F;
    563     Sprite(offscreen, HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64,
     558    OptiType := C.Status shr 4 and $0F;
     559    Sprite(Offscreen, HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64,
    564560      1 + OptiType mod 3 * 64, 217 + OptiType div 3 * 64);
    565561
    566562    { display messages now }
    567563    MessageCount := 0;
    568     for i := 0 to 31 do
    569       if Happened and ($FFFFFFFF - chCaptured) and (1 shl i) <> 0 then
    570         inc(MessageCount);
     564    for I := 0 to 31 do
     565      if Happened and ($FFFFFFFF - chCaptured) and (1 shl I) <> 0 then
     566        Inc(MessageCount);
    571567    if MessageCount > 3 then
    572568      MessageCount := 3;
    573569    if MessageCount > 0 then
    574570    begin
    575       MakeBlue(offscreen, 74, 280, 242, 40);
    576       line := 0;
    577       for i := 0 to nCityEventPriority - 1 do
    578         if line < MessageCount then
    579           CheckMessage(CityEventPriority[i]);
     571      MakeBlue(Offscreen, 74, 280, 242, 40);
     572      Line := 0;
     573      for I := 0 to nCityEventPriority - 1 do
     574        if Line < MessageCount then
     575          CheckMessage(CityEventPriority[I]);
    580576    end
    581577    else
    582578    begin
    583       s := Phrases.Lookup('CITYMANAGETYPE', OptiType);
    584       j := pos('\', s);
    585       if j = 0 then
    586         LoweredTextout(offscreen.Canvas, -1, MainTexture, xmOpt + 40,
    587           ymOpt - 9, s)
     579      S := Phrases.Lookup('CITYMANAGETYPE', OptiType);
     580      J := Pos('\', S);
     581      if J = 0 then
     582        LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40,
     583          ymOpt - 9, S)
    588584      else
    589585      begin
    590         LoweredTextout(offscreen.Canvas, -1, MainTexture, xmOpt + 40,
    591           ymOpt - 17, copy(s, 1, j - 1));
    592         LoweredTextout(offscreen.Canvas, -1, MainTexture, xmOpt + 40, ymOpt - 1,
    593           copy(s, j + 1, 255));
     586        LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40,
     587          ymOpt - 17, Copy(S, 1, J - 1));
     588        LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40, ymOpt - 1,
     589          Copy(S, J + 1, 255));
    594590      end;
    595591    end;
     
    601597    AreaMap.Paint(xmArea - xxt * 2 * rx, ymArea - yyt * 2 * ry - 3 * yyt,
    602598      dLoc(cLoc, -2 * rx + 1, -2 * ry - 1), 4 * rx - 1, 4 * ry + 1, cLoc, cOwner,
    603       false, AllowChange and IsCityAlive and
    604       (c.Status and csResourceWeightsMask = 0));
    605     DpiBitCanvas(offscreen.Canvas, xmArea + 102, 42, 90, 33, Back.Canvas,
     599      False, AllowChange and IsCityAlive and
     600      (C.Status and csResourceWeightsMask = 0));
     601    DpiBitBltCanvas(Offscreen.Canvas, xmArea + 102, 42, 90, 33, Back.Canvas,
    606602      xmArea + 102, 42);
    607603
     
    615611              ((Loc1 < 0) or (Loc1 >= G.lx * G.ly) or (MyMap[Loc1] and fCity = 0))
    616612            then
    617               Sprite(offscreen, HGrTerrain, xmArea - xxt + xxt * dx,
     613              Sprite(Offscreen, HGrTerrain, xmArea - xxt + xxt * dx,
    618614                ymArea - yyt + yyt * dy, xxt * 2, yyt * 2, 1 + 5 * (xxt * 2 + 1),
    619615                1 + yyt + 15 * (yyt * 3 + 1));
    620             if (1 shl ((dy + 3) shl 2 + (dx + 3) shr 1) and c.Tiles <> 0) then
     616            if (1 shl ((dy + 3) shl 2 + (dx + 3) shr 1) and C.Tiles <> 0) then
    621617              PaintResources(xmArea - xxt + xxt * dx, ymArea - yyt + yyt * dy,
    622618                Loc1, (dx = 0) and (dy = 0));
     
    625621
    626622  if Report.Working > 1 then
    627     d := (xService - (xmArea - 192) - 8 - 32) div (Report.Working - 1);
    628   if d > 28 then
    629     d := 28;
    630   for i := Report.Working - 1 downto 0 do
     623    D := (xService - (xmArea - 192) - 8 - 32) div (Report.Working - 1);
     624  if D > 28 then
     625    D := 28;
     626  for I := Report.Working - 1 downto 0 do
    631627  begin
    632628    if IsCityAlive then
     
    634630    else
    635631      xGr := 141;
    636     DpiBitCanvas(offscreen.Canvas, xmArea - 192 + 5 + i * d, ymArea - 96 - 29,
     632    DpiBitBltCanvas(Offscreen.Canvas, xmArea - 192 + 5 + I * D, ymArea - 96 - 29,
    637633      27, 30, HGrSystem.Mask.Canvas, xGr, 171, SRCAND); { shadow }
    638     Sprite(offscreen, HGrSystem, xmArea - 192 + 4 + i * d, ymArea - 96 - 30, 27,
     634    Sprite(Offscreen, HGrSystem, xmArea - 192 + 4 + I * D, ymArea - 96 - 30, 27,
    639635      30, xGr, 171);
    640636  end;
    641   if c.Size - Report.Working > 1 then
    642     d := (xmArea + 192 - xService - 32) div (c.Size - Report.Working - 1);
    643   if d > 28 then
    644     d := 28;
    645   for i := 0 to c.Size - Report.Working - 1 do
     637  if C.Size - Report.Working > 1 then
     638    D := (xmArea + 192 - xService - 32) div (C.Size - Report.Working - 1);
     639  if D > 28 then
     640    D := 28;
     641  for I := 0 to C.Size - Report.Working - 1 do
    646642  begin
    647643    xGr := 1 + 112;
    648     DpiBitCanvas(offscreen.Canvas, xmArea + 192 - 27 + 1 - i * d, 29 + 1, 27,
     644    DpiBitBltCanvas(Offscreen.Canvas, xmArea + 192 - 27 + 1 - I * D, 29 + 1, 27,
    649645      30, HGrSystem.Mask.Canvas, xGr, 171, SRCAND); { shadow }
    650     Sprite(offscreen, HGrSystem, xmArea + 192 - 27 - i * d, 29, 27, 30,
     646    Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 - I * D, 29, 27, 30,
    651647      xGr, 171);
    652     Sprite(offscreen, HGrSystem, xmArea + 192 - 27 + 4 - i * d, 29 + 32, 10,
     648    Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 + 4 - I * D, 29 + 32, 10,
    653649      10, 121, 126);
    654     Sprite(offscreen, HGrSystem, xmArea + 192 - 27 + 13 - i * d, 29 + 32, 10,
     650    Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 + 13 - I * D, 29 + 32, 10,
    655651      10, 121, 126);
    656652    // Sprite(offscreen,HGrSystem,xmArea+192-31+18-i*d,ymArea-96-80+32,10,10,88,115);
    657653  end;
    658654
    659   if c.Project and cpImp = 0 then
    660     PrName := Tribe[cOwner].ModelName[c.Project and cpIndex]
     655  if C.Project and cpImp = 0 then
     656    PrName := Tribe[cOwner].ModelName[C.Project and cpIndex]
    661657  else
    662     PrName := Phrases.Lookup('IMPROVEMENTS', c.Project and cpIndex);
     658    PrName := Phrases.Lookup('IMPROVEMENTS', C.Project and cpIndex);
    663659  PrCost := Report.ProjectCost;
    664660
     
    667663  begin
    668664    if cGov = gFundamentalism then
    669       CountBar(offscreen, xHapp, yHapp + dyBar, wBar, 17,
     665      CountBar(Offscreen, xHapp, yHapp + dyBar, wBar, 17,
    670666        Phrases.Lookup('FAITH'), Report.CollectedControl, MainTexture)
    671667    else
    672668    begin
    673       CountBar(offscreen, xHapp, yHapp + dyBar, wBar, 17,
     669      CountBar(Offscreen, xHapp, yHapp + dyBar, wBar, 17,
    674670        Phrases.Lookup('HAPPINESS'), Report.Morale, MainTexture);
    675       CountBar(offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16,
     671      CountBar(Offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16,
    676672        Phrases.Lookup('CONTROL'), Report.CollectedControl, MainTexture);
    677673    end;
    678     CountBar(offscreen, xHapp, yHapp, wBar, 8, Phrases.Lookup('LUX'),
     674    CountBar(Offscreen, xHapp, yHapp, wBar, 8, Phrases.Lookup('LUX'),
    679675      Report.Luxury, MainTexture);
    680     CountBar(offscreen, xHapp + dxBar, yHapp, wBar, 19,
     676    CountBar(Offscreen, xHapp + dxBar, yHapp, wBar, 19,
    681677      Phrases.Lookup('UNREST'), 2 * Report.Deployed, MainTexture);
    682     CountBar(offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17,
    683       Phrases.Lookup('HAPPINESSDEMAND'), c.Size, MainTexture);
     678    CountBar(Offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17,
     679      Phrases.Lookup('HAPPINESSDEMAND'), C.Size, MainTexture);
    684680    if Report.HappinessBalance >= 0 then
    685       CountBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17,
     681      CountBar(Offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17,
    686682        Phrases.Lookup('HAPPINESSPLUS'), Report.HappinessBalance, MainTexture)
    687683    else
    688684    begin
    689685      MakeRed(Offscreen, xHapp + dxBar - 6, yHapp + 2 * dyBar, wBar + 10, 38);
    690       CountBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18,
     686      CountBar(Offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18,
    691687        Phrases.Lookup('LACK'), -Report.HappinessBalance, RedTex);
    692688    end;
     
    696692  if IsCityAlive then
    697693  begin
    698     CountBar(offscreen, xFood, yFood + dyBar div 2, wBar, 0,
     694    CountBar(Offscreen, xFood, yFood + dyBar div 2, wBar, 0,
    699695      Phrases.Lookup('FOOD'), Report.CollectedFood, MainTexture);
    700     CountBar(offscreen, xFood + dxBar, yFood + dyBar, wBar, 0,
    701       Phrases.Lookup('DEMAND'), 2 * c.Size, MainTexture);
    702     CountBar(offscreen, xFood + dxBar, yFood, wBar, 0,
     696    CountBar(Offscreen, xFood + dxBar, yFood + dyBar, wBar, 0,
     697      Phrases.Lookup('DEMAND'), 2 * C.Size, MainTexture);
     698    CountBar(Offscreen, xFood + dxBar, yFood, wBar, 0,
    703699      Phrases.Lookup('SUPPORT'), Report.FoodSupport, MainTexture);
    704700    if Report.FoodSurplus >= 0 then
    705       if (cGov = gFuture) or (c.Size >= NeedAqueductSize) and
     701      if (cGov = gFuture) or (C.Size >= NeedAqueductSize) and
    706702        (Report.FoodSurplus < 2) then
    707         CountBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6,
     703        CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6,
    708704          Phrases.Lookup('PROFIT'), Report.FoodSurplus, MainTexture)
    709705      else
    710         CountBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0,
     706        CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0,
    711707          Phrases.Lookup('SURPLUS'), Report.FoodSurplus, MainTexture)
    712708    else
    713709    begin
    714710      MakeRed(Offscreen, xFood + dxBar - 6, yFood + 2 * dyBar, wBar + 10, 38);
    715       CountBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1,
     711      CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1,
    716712        Phrases.Lookup('LACK'), -Report.FoodSurplus, RedTex);
    717713    end;
    718714  end;
    719   CanGrow := (c.Size < MaxCitySize) and (cGov <> gFuture) and
    720     (Report.FoodSurplus > 0) and ((c.Size < NeedAqueductSize) or
    721     (c.Built[imAqueduct] = 1) and (c.Size < NeedSewerSize) or
    722     (c.Built[imSewer] = 1));
     715  CanGrow := (C.Size < MaxCitySize) and (cGov <> gFuture) and
     716    (Report.FoodSurplus > 0) and ((C.Size < NeedAqueductSize) or
     717    (C.Built[imAqueduct] = 1) and (C.Size < NeedSewerSize) or
     718    (C.Built[imSewer] = 1));
    723719  FillBar(xFood + 3, yFood + 102, TrueFood,
    724     CutCityFoodSurplus(Report.FoodSurplus, IsCityAlive, cGov, c.Size),
     720    CutCityFoodSurplus(Report.FoodSurplus, IsCityAlive, cGov, C.Size),
    725721    Report.Storage, 1, CanGrow);
    726   LoweredTextout(offscreen.Canvas, -1, MainTexture, xFood + 3 - 5,
     722  LoweredTextout(Offscreen.Canvas, -1, MainTexture, xFood + 3 - 5,
    727723    yFood + 102 - 20, Format('%d/%d', [TrueFood, Report.Storage]));
    728   LoweredTextout(offscreen.Canvas, -1, MainTexture, xFood - 2, yFood + 66,
     724  LoweredTextout(Offscreen.Canvas, -1, MainTexture, xFood - 2, yFood + 66,
    729725    Phrases.Lookup('STORAGE'));
    730726
     
    732728  if IsCityAlive then
    733729  begin
    734     CountBar(offscreen, xProd, yProd, wBar, 2, Phrases.Lookup('MATERIAL'),
     730    CountBar(Offscreen, xProd, yProd, wBar, 2, Phrases.Lookup('MATERIAL'),
    735731      Report.CollectedMaterial, MainTexture);
    736     CountBar(offscreen, xProd + dxBar, yProd, wBar, 2,
     732    CountBar(Offscreen, xProd + dxBar, yProd, wBar, 2,
    737733      Phrases.Lookup('SUPPORT'), Report.MaterialSupport, MainTexture);
    738734    if Report.Production >= 0 then
    739       if c.Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    740         CountBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6,
     735      if C.Project and (cpImp + cpIndex) = cpImp + imTrGoods then
     736        CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6,
    741737          Phrases.Lookup('PROFIT'), Report.Production, MainTexture)
    742738      else
    743         CountBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2,
     739        CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2,
    744740          Phrases.Lookup('PROD'), Report.Production, MainTexture)
    745741    else
    746742    begin
    747743      MakeRed(Offscreen, xProd + dxBar - 6, yProd + dyBar + 17, wBar + 10, 38);
    748       CountBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3,
     744      CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3,
    749745        Phrases.Lookup('LACK'), -Report.Production, RedTex);
    750746    end;
    751747  end;
    752   if c.Project and (cpImp + cpIndex) <> cpImp + imTrGoods then
    753     with offscreen.Canvas do
    754     begin
    755       i := Report.Production;
    756       if (i < 0) or not IsCityAlive then
    757         i := 0;
    758       FillBar(xProd + 3, yProd + 16 + 63, TrueProd, i, PrCost, 4, true);
    759       LoweredTextout(offscreen.Canvas, -1, MainTexture, xProd + 3 - 5,
     748  if C.Project and (cpImp + cpIndex) <> cpImp + imTrGoods then
     749    with Offscreen.Canvas do
     750    begin
     751      I := Report.Production;
     752      if (I < 0) or not IsCityAlive then
     753        I := 0;
     754      FillBar(xProd + 3, yProd + 16 + 63, TrueProd, I, PrCost, 4, True);
     755      LoweredTextout(Offscreen.Canvas, -1, MainTexture, xProd + 3 - 5,
    760756        yProd + 16 + 43, Format('%d/%d', [TrueProd, PrCost]));
    761       if BiColorTextWidth(offscreen.Canvas, PrName) > wBar + dxBar then
     757      if BiColorTextWidth(Offscreen.Canvas, PrName) > wBar + dxBar then
    762758      begin
    763759        repeat
    764           Delete(PrName, length(PrName), 1)
    765         until BiColorTextWidth(offscreen.Canvas, PrName) <= wBar + dxBar;
     760          Delete(PrName, Length(PrName), 1)
     761        until BiColorTextWidth(Offscreen.Canvas, PrName) <= wBar + dxBar;
    766762        PrName := PrName + '.'
    767763      end;
    768764    end;
    769   RisedTextOut(offscreen.Canvas, xProd - 2, yProd + 36, PrName);
     765  RisedTextOut(Offscreen.Canvas, xProd - 2, yProd + 36, PrName);
    770766
    771767  // pollution section
     
    773769  begin
    774770    FillBar(xPoll + 3, yPoll + 20, TruePoll, Report.AddPollution,
    775       MaxPollution, 3, true);
    776     RisedTextOut(offscreen.Canvas, xPoll + 3 - 5, yPoll + 20 - 20,
     771      MaxPollution, 3, True);
     772    RisedTextOut(Offscreen.Canvas, xPoll + 3 - 5, yPoll + 20 - 20,
    777773      Phrases.Lookup('POLL'));
    778774  end;
     
    781777  if IsCityAlive and (Report.CollectedTrade > 0) then
    782778  begin
    783     CountBar(offscreen, xTrade, yTrade + dyBar div 2, wBar, 4,
     779    CountBar(Offscreen, xTrade, yTrade + dyBar div 2, wBar, 4,
    784780      Phrases.Lookup('TRADE'), Report.CollectedTrade, MainTexture);
    785     CountBar(offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5,
     781    CountBar(Offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5,
    786782      Phrases.Lookup('CORR'), Report.Corruption, MainTexture);
    787     CountBar(offscreen, xTrade + dxBar, yTrade, wBar, 6, Phrases.Lookup('TAX'),
     783    CountBar(Offscreen, xTrade + dxBar, yTrade, wBar, 6, Phrases.Lookup('TAX'),
    788784      Report.Tax, MainTexture);
    789     CountBar(offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12,
     785    CountBar(Offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12,
    790786      Phrases.Lookup('SCIENCE'), Report.Science, MainTexture);
    791787  end;
    792788
    793789  // small map
    794   DpiBitCanvas(offscreen.Canvas, xSmallMap, ySmallMap, wSmallMap, hSmallMap,
     790  DpiBitBltCanvas(Offscreen.Canvas, xSmallMap, ySmallMap, wSmallMap, hSmallMap,
    795791    SmallCityMap.Canvas, 0, 0);
    796792  if SmallMapMode = smImprovements then
    797     Frame(offscreen.Canvas, xSmallMap + 48 * (ZoomArea div 3),
     793    Frame(Offscreen.Canvas, xSmallMap + 48 * (ZoomArea div 3),
    798794      ySmallMap + 24 * (ZoomArea mod 3), xSmallMap + 48 * (ZoomArea div 3) + 49,
    799795      ySmallMap + 24 * (ZoomArea mod 3) + 25, MainTexture.ColorMark,
    800796      MainTexture.ColorMark);
    801   Frame(offscreen.Canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap,
     797  Frame(Offscreen.Canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap,
    802798    ySmallMap + hSmallMap, $B0B0B0, $FFFFFF);
    803   RFrame(offscreen.Canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap +
     799  RFrame(Offscreen.Canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap +
    804800    1, ySmallMap + hSmallMap + 1, $FFFFFF, $B0B0B0);
    805801
    806   Frame(offscreen.Canvas, xSupport - 1, ySupport - 1, xSupport + wSupport,
     802  Frame(Offscreen.Canvas, xSupport - 1, ySupport - 1, xSupport + wSupport,
    807803    ySupport + hSupport, $B0B0B0, $FFFFFF);
    808   RFrame(offscreen.Canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1,
     804  RFrame(Offscreen.Canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1,
    809805    ySupport + hSupport + 1, $FFFFFF, $B0B0B0);
    810   x := xSupport + wSupport div 2;
    811   y := ySupport + hSupport div 2;
     806  X := xSupport + wSupport div 2;
     807  Y := ySupport + hSupport div 2;
    812808  if SmallMapMode = smSupportedUnits then
    813809  begin
    814     offscreen.Canvas.brush.Color := MainTexture.ColorMark;
    815     offscreen.Canvas.FillRect(Rect(x - 27, y - 6, x + 27, y + 6));
    816     offscreen.Canvas.brush.style := bsClear;
    817   end;
    818   Sprite(offscreen, HGrSystem, x - 16, y - 5, 10, 10, 88, 115);
    819   Sprite(offscreen, HGrSystem, x - 5, y - 5, 10, 10, 66, 115);
    820   Sprite(offscreen, HGrSystem, x + 6, y - 5, 10, 10, 154, 126);
    821 
    822   DpiBitCanvas(offscreen.Canvas, xZoomMap, yZoomMap, wZoomMap, hZoomMap,
     810    Offscreen.Canvas.Brush.Color := MainTexture.ColorMark;
     811    Offscreen.Canvas.FillRect(Rect(X - 27, Y - 6, X + 27, Y + 6));
     812    Offscreen.Canvas.Brush.style := bsClear;
     813  end;
     814  Sprite(Offscreen, HGrSystem, X - 16, Y - 5, 10, 10, 88, 115);
     815  Sprite(Offscreen, HGrSystem, X - 5, Y - 5, 10, 10, 66, 115);
     816  Sprite(Offscreen, HGrSystem, X + 6, Y - 5, 10, 10, 154, 126);
     817
     818  DpiBitBltCanvas(Offscreen.Canvas, xZoomMap, yZoomMap, wZoomMap, hZoomMap,
    823819    ZoomCityMap.Canvas, 0, 0);
    824820
    825   for i := 0 to 5 do
    826     imix[i] := -1;
     821  for I := 0 to 5 do
     822    imix[I] := -1;
    827823  if SmallMapMode = smImprovements then
    828824  begin
     
    831827      Cnt := 0;
    832828      for iix := 0 to nImp - 1 do
    833         if ((iix < nWonder) or (ImpPosition[iix] < 0)) and (c.Built[iix] > 0) then
     829        if ((iix < nWonder) or (ImpPosition[iix] < 0)) and (C.Built[iix] > 0) then
    834830        begin
    835           i := Cnt - Page * 6;
    836           if (i >= 0) and (i < 6) then
    837             imix[i] := iix;
    838           inc(Cnt);
     831          I := Cnt - Page * 6;
     832          if (I >= 0) and (I < 6) then
     833            imix[I] := iix;
     834          Inc(Cnt);
    839835        end;
    840836      PageCount := (Cnt + 5) div 6;
     
    844840      for iix := nWonder to nImp - 1 do
    845841      begin
    846         i := ImpPosition[iix] - 6 * ZoomArea;
    847         if (i >= 0) and (i < 6) and (c.Built[iix] > 0) then
    848           imix[i] := iix;
     842        I := ImpPosition[iix] - 6 * ZoomArea;
     843        if (I >= 0) and (I < 6) and (C.Built[iix] > 0) then
     844          imix[I] := iix;
    849845      end;
    850846      PageCount := 0;
    851847    end;
    852     for i := 0 to 5 do
    853       if imix[i] >= 0 then
     848    for I := 0 to 5 do
     849      if imix[I] >= 0 then
    854850      begin
    855         iix := imix[i];
    856         x := xZoomMap + 14 + 72 * (i mod 3);
    857         y := yZoomMap + 14 + 56 * (i div 3);
    858         ImpImage(offscreen.Canvas, x, y, iix, cGov, AllowChange and
     851        iix := imix[I];
     852        X := xZoomMap + 14 + 72 * (I mod 3);
     853        Y := yZoomMap + 14 + 56 * (I div 3);
     854        ImpImage(Offscreen.Canvas, X, Y, iix, cGov, AllowChange and
    859855          (ClientMode < scContact));
    860856        if IsCityAlive then
     
    862858          if iix = imColosseum then
    863859          begin
    864             Sprite(offscreen, HGrSystem, x + 46, y, 14, 14, 82, 100);
     860            Sprite(Offscreen, HGrSystem, X + 46, Y, 14, 14, 82, 100);
    865861          end
    866862          else
     
    880876            if HappyGain > 1 then
    881877            begin
    882               d := 30 div (HappyGain - 1);
    883               if d > 10 then
    884                 d := 10
     878              D := 30 div (HappyGain - 1);
     879              if D > 10 then
     880                D := 10
    885881            end;
    886             for j := 0 to HappyGain - 1 do
    887               Sprite(offscreen, HGrSystem, x + 50, y + d * j, 10, 10, 132, 126);
     882            for J := 0 to HappyGain - 1 do
     883              Sprite(Offscreen, HGrSystem, X + 50, Y + D * J, 10, 10, 132, 126);
    888884          end;
    889           for j := 0 to Imp[iix].Maint - 1 do
    890             Sprite(offscreen, HGrSystem, x - 4, y + 29 - 3 * j, 10, 10,
     885          for J := 0 to Imp[iix].Maint - 1 do
     886            Sprite(Offscreen, HGrSystem, X - 4, Y + 29 - 3 * J, 10, 10,
    891887              132, 115);
    892888        end
     
    919915  else { if SmallMapMode = smSupportedUnits then }
    920916  begin
    921     LoweredTextout(offscreen.Canvas, -1, MainTexture, xZoomMap + 6,
     917    LoweredTextout(Offscreen.Canvas, -1, MainTexture, xZoomMap + 6,
    922918      yZoomMap + 2, Phrases.Lookup('SUPUNITS'));
    923     FreeSupp := c.Size * SupportFree[cGov] shr 1;
     919    FreeSupp := C.Size * SupportFree[cGov] shr 1;
    924920    Cnt := 0;
    925     for i := 0 to MyRO.nUn - 1 do
    926       if (MyUn[i].Loc >= 0) and (MyUn[i].Home = cix) then
    927         with MyModel[MyUn[i].mix] do
     921    for I := 0 to MyRO.nUn - 1 do
     922      if (MyUn[I].Loc >= 0) and (MyUn[I].Home = cix) then
     923        with MyModel[MyUn[I].mix] do
    928924        begin
    929           Server(sGetUnitReport, me, i, UnitReport);
     925          Server(sGetUnitReport, Me, I, UnitReport);
    930926          if (Cnt >= 6 * Page) and (Cnt < 6 * (Page + 1)) then
    931927          begin // unit visible in display
    932             imix[Cnt - 6 * Page] := i;
    933             x := ((Cnt - 6 * Page) mod 3) * 64 + xZoomMap;
    934             y := ((Cnt - 6 * Page) div 3) * 52 + yZoomMap + 20;
    935             MakeUnitInfo(me, MyUn[i], UnitInfo);
    936             NoMap.SetOutput(offscreen);
    937             NoMap.PaintUnit(x, y, UnitInfo, MyUn[i].Status);
    938 
    939             for j := 0 to UnitReport.FoodSupport - 1 do
    940               Sprite(offscreen, HGrSystem, x + 38 + 11 * j, y + 40, 10,
     928            imix[Cnt - 6 * Page] := I;
     929            X := ((Cnt - 6 * Page) mod 3) * 64 + xZoomMap;
     930            Y := ((Cnt - 6 * Page) div 3) * 52 + yZoomMap + 20;
     931            MakeUnitInfo(Me, MyUn[I], UnitInfo);
     932            NoMap.SetOutput(Offscreen);
     933            NoMap.PaintUnit(X, Y, UnitInfo, MyUn[I].Status);
     934
     935            for J := 0 to UnitReport.FoodSupport - 1 do
     936              Sprite(Offscreen, HGrSystem, X + 38 + 11 * J, Y + 40, 10,
    941937                10, 66, 115);
    942             for j := 0 to UnitReport.ProdSupport - 1 do
     938            for J := 0 to UnitReport.ProdSupport - 1 do
    943939            begin
    944940              if (FreeSupp > 0) and
    945941                (UnitReport.ReportFlags and urfAlwaysSupport = 0) then
    946942              begin
    947                 Sprite(offscreen, HGrSystem, x + 16 - 11 * j, y + 40, 10,
     943                Sprite(Offscreen, HGrSystem, X + 16 - 11 * J, Y + 40, 10,
    948944                  10, 143, 115);
    949                 dec(FreeSupp);
     945                Dec(FreeSupp);
    950946              end
    951947              else
    952                 Sprite(offscreen, HGrSystem, x + 16 - 11 * j, y + 40, 10,
     948                Sprite(Offscreen, HGrSystem, X + 16 - 11 * J, Y + 40, 10,
    953949                  10, 88, 115);
    954950            end;
    955951            if UnitReport.ReportFlags and urfDeployed <> 0 then
    956               for j := 0 to 1 do
    957                 Sprite(offscreen, HGrSystem, x + 27 + 11 * j, y + 40, 10,
     952              for J := 0 to 1 do
     953                Sprite(Offscreen, HGrSystem, X + 27 + 11 * J, Y + 40, 10,
    958954                  10, 154, 126)
    959955          end // unit visible in display
    960956          else
    961             dec(FreeSupp, UnitReport.ProdSupport);
    962           inc(Cnt);
     957            Dec(FreeSupp, UnitReport.ProdSupport);
     958          Inc(Cnt);
    963959        end;
    964960    PageCount := (Cnt + 5) div 6;
     
    973969  PageDownBtn.Visible := PageCount > 1;
    974970
    975   with offscreen.Canvas do
     971  with Offscreen.Canvas do
    976972  begin
    977973    { display project now }
    978     DLine(offscreen.Canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10,
     974    DLine(Offscreen.Canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10,
    979975      yProd + dyBar + 16, $FFFFFF, $B0B0B0);
    980976    if ProdHint then
    981977    begin
    982       ScreenTools.Frame(offscreen.Canvas, xView + 9 - 1, yView + 5 - 1,
     978      ScreenTools.Frame(Offscreen.Canvas, xView + 9 - 1, yView + 5 - 1,
    983979        xView + 9 + xSizeBig, yView + 5 + ySizeBig, $B0B0B0, $FFFFFF);
    984       RFrame(offscreen.Canvas, xView + 9 - 2, yView + 5 - 2,
     980      RFrame(Offscreen.Canvas, xView + 9 - 2, yView + 5 - 2,
    985981        xView + 9 + xSizeBig + 1, yView + 5 + ySizeBig + 1, $FFFFFF, $B0B0B0);
    986       with offscreen.Canvas do
     982      with Offscreen.Canvas do
    987983      begin
    988         brush.Color := $000000;
     984        Brush.Color := $000000;
    989985        FillRect(Rect(xView + 9, yView + 5, xView + 1 + 72 - 8,
    990986          yView + 5 + 40));
    991         brush.style := bsClear;
     987        Brush.style := bsClear;
    992988      end;
    993989    end
    994     else if AllowChange and (c.Status and 7 <> 0) then
     990    else if AllowChange and (C.Status and 7 <> 0) then
    995991    begin // city type autobuild
    996       FrameImage(offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
    997         ySizeBig, (c.Status and 7 - 1 + 3) * xSizeBig, 0, (cix >= 0) and
     992      FrameImage(Offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
     993        ySizeBig, (C.Status and 7 - 1 + 3) * xSizeBig, 0, (cix >= 0) and
    998994        (ClientMode < scContact));
    999995    end
    1000     else if c.Project and cpImp = 0 then
     996    else if C.Project and cpImp = 0 then
    1001997    begin // project is unit
    1002       FrameImage(offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
     998      FrameImage(Offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
    1003999        ySizeBig, 0, 0, AllowChange and (ClientMode < scContact));
    1004       with Tribe[cOwner].ModelPicture[c.Project and cpIndex] do
    1005         Sprite(offscreen, HGr, xView + 5, yView + 1, 64, 44,
     1000      with Tribe[cOwner].ModelPicture[C.Project and cpIndex] do
     1001        Sprite(Offscreen, HGr, xView + 5, yView + 1, 64, 44,
    10061002          pix mod 10 * 65 + 1, pix div 10 * 49 + 1);
    10071003    end
     
    10091005    begin // project is building
    10101006      if ProdHint then
    1011         Paintiix := c.Project0 and cpIndex
     1007        Paintiix := C.Project0 and cpIndex
    10121008      else
    1013         Paintiix := c.Project and cpIndex;
    1014       ImpImage(offscreen.Canvas, xView + 9, yView + 5, Paintiix, cGov,
     1009        Paintiix := C.Project and cpIndex;
     1010      ImpImage(Offscreen.Canvas, xView + 9, yView + 5, Paintiix, cGov,
    10151011        AllowChange and (ClientMode < scContact));
    10161012    end;
     
    10191015  if AllowChange and (ClientMode < scContact) then
    10201016  begin
    1021     i := Server(sBuyCityProject - sExecute, me, cix, nil^);
    1022     BuyBtn.Visible := (i = eOk) or (i = eViolation);
     1017    I := Server(sBuyCityProject - sExecute, Me, cix, nil^);
     1018    BuyBtn.Visible := (I = eOk) or (I = eViolation);
    10231019  end
    10241020  else
    1025     BuyBtn.Visible := false;
     1021    BuyBtn.Visible := False;
    10261022
    10271023  MarkUsedOffscreen(ClientWidth, ClientHeight);
    1028 end; { OffscreenPaint }
     1024end;
    10291025
    10301026procedure TCityDlg.FormShow(Sender: TObject);
    10311027var
    1032   dx, dy, Loc1: integer;
     1028  dx, dy, Loc1: Integer;
    10331029  GetCityData: TGetCityData;
    10341030begin
     
    10361032  if cix >= 0 then
    10371033  begin { own city }
    1038     c := MyCity[cix];
    1039     cOwner := me;
     1034    C := MyCity[cix];
     1035    cOwner := Me;
    10401036    cGov := MyRO.Government;
    10411037    ProdHint := (cGov <> gAnarchy) and
    10421038      (Happened and (chProduction or chFounded or chCaptured or
    10431039      chAllImpsMade) <> 0);
    1044     Server(sGetCityAreaInfo, me, cix, CityAreaInfo);
     1040    Server(sGetCityAreaInfo, Me, cix, CityAreaInfo);
    10451041    NextCityBtn.Visible := WindowMode = wmPersistent;
    10461042    PrevCityBtn.Visible := WindowMode = wmPersistent;
     
    10491045  begin
    10501046    SmallMapMode := smImprovements;
    1051     Server(sGetCity, me, cLoc, GetCityData);
    1052     c := GetCityData.c;
     1047    Server(sGetCity, Me, cLoc, GetCityData);
     1048    C := GetCityData.C;
    10531049    cOwner := GetCityData.Owner;
    10541050    cGov := MyRO.EnemyReport[cOwner].Government;
    1055     Happened := c.Flags and $7FFFFFFF;
    1056     ProdHint := false;
    1057     Server(sGetEnemyCityAreaInfo, me, cLoc, CityAreaInfo);
    1058 
    1059     if c.Project and cpImp = 0 then
     1051    Happened := C.Flags and $7FFFFFFF;
     1052    ProdHint := False;
     1053    Server(sGetEnemyCityAreaInfo, Me, cLoc, CityAreaInfo);
     1054
     1055    if C.Project and cpImp = 0 then
    10601056    begin
    10611057      emix := MyRO.nEnemyModel - 1;
    10621058      while (emix > 0) and ((MyRO.EnemyModel[emix].Owner <> cOwner) or
    1063         (integer(MyRO.EnemyModel[emix].mix) <> c.Project and cpIndex)) do
    1064         dec(emix);
    1065       if not Assigned(Tribe[cOwner].ModelPicture[c.Project and cpIndex].HGr) then
     1059        (Integer(MyRO.EnemyModel[emix].mix) <> C.Project and cpIndex)) do
     1060        Dec(emix);
     1061      if not Assigned(Tribe[cOwner].ModelPicture[C.Project and cpIndex].HGr) then
    10661062        InitEnemyModel(emix);
    10671063    end;
    10681064
    1069     NextCityBtn.Visible := false;
    1070     PrevCityBtn.Visible := false;
     1065    NextCityBtn.Visible := False;
     1066    PrevCityBtn.Visible := False;
    10711067  end;
    10721068  Page := 0;
    10731069
    1074   if c.Size < 5 then
     1070  if C.Size < 5 then
    10751071    SizeClass := 0
    1076   else if c.Size < 9 then
     1072  else if C.Size < 9 then
    10771073    SizeClass := 1
    1078   else if c.Size < 13 then
     1074  else if C.Size < 13 then
    10791075    SizeClass := 2
    10801076  else
     
    10821078
    10831079  // check if port
    1084   IsPort := false;
     1080  IsPort := False;
    10851081  for dx := -2 to 2 do
    10861082    for dy := -2 to 2 do
    1087       if abs(dx) + abs(dy) = 2 then
     1083      if Abs(dx) + Abs(dy) = 2 then
    10881084      begin
    10891085        Loc1 := dLoc(cLoc, dx, dy);
    10901086        if (Loc1 >= 0) and (Loc1 < G.lx * G.ly) and
    10911087          (MyMap[Loc1] and fTerrain < fGrass) then
    1092           IsPort := true;
     1088          IsPort := True;
    10931089      end;
    10941090
     
    10991095  end;
    11001096
    1101   Caption := CityName(c.ID);
     1097  Caption := CityName(C.ID);
    11021098
    11031099  InitSmallCityMap;
     
    11051101  OpenSoundEvent := -1;
    11061102  OffscreenPaint;
    1107   Timer1.Enabled := true;
    1108 end;
    1109 
    1110 procedure TCityDlg.ShowNewContent(NewMode, Loc: integer; ShowEvent: cardinal);
     1103  Timer1.Enabled := True;
     1104end;
     1105
     1106procedure TCityDlg.ShowNewContent(NewMode: TWindowMode; Loc: Integer; ShowEvent: Cardinal);
    11111107begin
    11121108  if MyMap[Loc] and fOwned <> 0 then
     
    11141110    cix := MyRO.nCity - 1;
    11151111    while (cix >= 0) and (MyCity[cix].Loc <> Loc) do
    1116       dec(cix);
    1117     assert(cix >= 0);
     1112      Dec(cix);
     1113    Assert(cix >= 0);
    11181114    if (Optimize_cixTileChange >= 0) and
    11191115      (Optimize_TilesBeforeChange and not MyCity[Optimize_cixTileChange].Tiles
     
    11311127  else
    11321128    cix := -1;
    1133   AllowChange := not supervising and (cix >= 0);
     1129  AllowChange := not Supervising and (cix >= 0);
    11341130  cLoc := Loc;
    11351131  Happened := ShowEvent;
     
    11381134
    11391135procedure TCityDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
    1140   Shift: TShiftState; x, y: integer);
     1136  Shift: TShiftState; X, Y: Integer);
    11411137var
    1142   i, qx, qy, dx, dy, fix, NewTiles, Loc1, iix, SellResult: integer;
    1143   Rebuild: boolean;
    1144 begin
    1145   if (ssLeft in Shift) and (x >= xSmallMap) and (x < xSmallMap + wSmallMap) and
    1146     (y >= ySmallMap) and (y < ySmallMap + hSmallMap) then
     1138  I, qx, qy, dx, dy, fix, NewTiles, Loc1, iix, SellResult: Integer;
     1139  Rebuild: Boolean;
     1140begin
     1141  if (ssLeft in Shift) and (X >= xSmallMap) and (X < xSmallMap + wSmallMap) and
     1142    (Y >= ySmallMap) and (Y < ySmallMap + hSmallMap) then
    11471143  begin
    11481144    SmallMapMode := smImprovements;
    1149     ZoomArea := (y - ySmallMap) * 3 div hSmallMap + 3 *
    1150       ((x - xSmallMap) * 2 div wSmallMap);
     1145    ZoomArea := (Y - ySmallMap) * 3 div hSmallMap + 3 *
     1146      ((X - xSmallMap) * 2 div wSmallMap);
    11511147    Page := 0;
    11521148    InitZoomCityMap;
    11531149    SmartUpdateContent;
    1154     exit;
    1155   end;
    1156   if (ssLeft in Shift) and (x >= xSupport) and (x < xSupport + wSupport) and
    1157     (y >= ySupport) and (y < ySupport + hSupport) then
     1150    Exit;
     1151  end;
     1152  if (ssLeft in Shift) and (X >= xSupport) and (X < xSupport + wSupport) and
     1153    (Y >= ySupport) and (Y < ySupport + hSupport) then
    11581154  begin
    11591155    SmallMapMode := smSupportedUnits;
     
    11611157    InitZoomCityMap;
    11621158    SmartUpdateContent;
    1163     exit;
     1159    Exit;
    11641160  end;
    11651161  if not AllowChange then
    1166     exit; // not an own city
     1162    Exit; // Not an own city
    11671163
    11681164  if (ssLeft in Shift) then
    1169     if (ClientMode < scContact) and (x >= xView) and (y >= yView) and
    1170       (x < xView + 73) and (y < yView + 50) then
     1165    if (ClientMode < scContact) and (X >= xView) and (Y >= yView) and
     1166      (X < xView + 73) and (Y < yView + 50) then
    11711167      if cGov = gAnarchy then
    1172         with MessgExDlg do
     1168        with MainScreen.MessgExDlg do
    11731169        begin
    11741170          { MessgText:=Phrases.Lookup('OUTOFCONTROL');
    1175             if c.Project and cpImp=0 then
    1176             MessgText:=Format(MessgText,[Tribe[cOwner].ModelName[c.Project and cpIndex]])
    1177             else MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS',c.Project and cpIndex)]); }
     1171            if C.Project and cpImp=0 then
     1172            MessgText:=Format(MessgText,[Tribe[cOwner].ModelName[C.Project and cpIndex]])
     1173            else MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS',C.Project and cpIndex)]); }
    11781174          MessgText := Phrases.Lookup('NOCHANGEINANARCHY');
    11791175          Kind := mkOk;
     
    11841180        if ProdHint then
    11851181        begin
    1186           ProdHint := false;
     1182          ProdHint := False;
    11871183          SmartUpdateContent
    11881184        end;
    11891185        ChooseProject;
    11901186      end
    1191     else if (SmallMapMode = smImprovements) and (x >= xZoomMap) and (x < xZoomMap + wZoomMap) and
    1192       (y >= yZoomMap) and (y < yZoomMap + hZoomMap) then
    1193     begin
    1194       i := 5;
    1195       while (i >= 0) and not((x >= xZoomMap + 14 + 72 * (i mod 3)) and
    1196         (x < xZoomMap + 14 + 56 + 72 * (i mod 3)) and
    1197         (y >= yZoomMap + 14 + 56 * (i div 3)) and
    1198         (y < yZoomMap + 14 + 40 + 56 * (i div 3))) do
    1199         dec(i);
    1200       if i >= 0 then
     1187    else if (SmallMapMode = smImprovements) and (X >= xZoomMap) and (X < xZoomMap + wZoomMap) and
     1188      (Y >= yZoomMap) and (Y < yZoomMap + hZoomMap) then
     1189    begin
     1190      I := 5;
     1191      while (I >= 0) and not((X >= xZoomMap + 14 + 72 * (I mod 3)) and
     1192        (X < xZoomMap + 14 + 56 + 72 * (I mod 3)) and
     1193        (Y >= yZoomMap + 14 + 56 * (I div 3)) and
     1194        (Y < yZoomMap + 14 + 40 + 56 * (I div 3))) do
     1195        Dec(I);
     1196      if I >= 0 then
    12011197      begin
    1202         iix := imix[i];
     1198        iix := imix[I];
    12031199        if iix >= 0 then
    12041200          if ssShift in Shift then
    1205             HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, iix)
     1201            MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, iix)
    12061202          else if (ClientMode < scContact) then
    1207             with MessgExDlg do
     1203            with MainScreen.MessgExDlg do
    12081204            begin
    12091205              IconKind := mikImp;
     
    12201216              else
    12211217              begin
    1222                 SellResult := Server(sSellCityImprovement - sExecute, me,
     1218                SellResult := Server(sSellCityImprovement - sExecute, Me,
    12231219                  cix, iix);
    12241220                if SellResult < rExecuted then
     
    12351231                else
    12361232                begin
    1237                   if Server(sRebuildCityImprovement - sExecute, me, cix, iix) < rExecuted
     1233                  if Server(sRebuildCityImprovement - sExecute, Me, cix, iix) < rExecuted
    12381234                  then
    12391235                  begin // no rebuild possible, ask for sell only
    1240                     Rebuild := false;
     1236                    Rebuild := False;
    12411237                    MessgText := Phrases.Lookup('IMPROVEMENTS', iix);
    12421238                    if not Phrases2FallenBackToEnglish then
    12431239                      MessgText := Format(Phrases2.Lookup('SELL2'),
    12441240                        [MessgText, Imp[iix].Cost * BuildCostMod
    1245                         [G.Difficulty[me]] div 12])
     1241                        [G.Difficulty[Me]] div 12])
    12461242                    else
    12471243                      MessgText := Format(Phrases.Lookup('SELL'), [MessgText]);
    12481244                    if iix = imSpacePort then
    1249                       with MyRO.Ship[me] do
     1245                      with MyRO.Ship[Me] do
    12501246                        if Parts[0] + Parts[1] + Parts[2] > 0 then
    12511247                          MessgText := MessgText + ' ' +
     
    12581254                  else
    12591255                  begin
    1260                     Rebuild := true;
     1256                    Rebuild := True;
    12611257                    MessgText := Phrases.Lookup('IMPROVEMENTS', iix);
    12621258                    if not Phrases2FallenBackToEnglish then
    12631259                      MessgText := Format(Phrases2.Lookup('DISPOSE2'),
    12641260                        [MessgText, Imp[iix].Cost * BuildCostMod
    1265                         [G.Difficulty[me]] div 12 * 2 div 3])
     1261                        [G.Difficulty[Me]] div 12 * 2 div 3])
    12661262                    else
    12671263                      MessgText := Format(Phrases.Lookup('DISPOSE'),
    12681264                        [MessgText]);
    12691265                    if iix = imSpacePort then
    1270                       with MyRO.Ship[me] do
     1266                      with MyRO.Ship[Me] do
    12711267                        if Parts[0] + Parts[1] + Parts[2] > 0 then
    12721268                          MessgText := MessgText + ' ' +
     
    12821278                    begin
    12831279                      Play('CITY_REBUILDIMP');
    1284                       Server(sRebuildCityImprovement, me, cix, iix);
     1280                      Server(sRebuildCityImprovement, Me, cix, iix);
    12851281                    end
    12861282                    else
    12871283                    begin
    12881284                      Play('CITY_SELLIMP');
    1289                       Server(sSellCityImprovement, me, cix, iix);
     1285                      Server(sSellCityImprovement, Me, cix, iix);
    12901286                    end;
    12911287                    CityOptimizer_CityChange(cix);
     
    13001296      end;
    13011297    end
    1302     else if (SmallMapMode = smSupportedUnits) and (x >= xZoomMap) and (x < xZoomMap + wZoomMap) and
    1303       (y >= yZoomMap) and (y < yZoomMap + hZoomMap) then
    1304     begin
    1305       i := 5;
    1306       while (i >= 0) and not((x >= xZoomMap + 64 * (i mod 3)) and
    1307         (x < xZoomMap + 64 + 64 * (i mod 3)) and
    1308         (y >= yZoomMap + 20 + 48 * (i div 3)) and
    1309         (y < yZoomMap + 20 + 52 + 48 * (i div 3))) do
    1310         dec(i);
    1311       if (i >= 0) and (imix[i] >= 0) then
     1298    else if (SmallMapMode = smSupportedUnits) and (X >= xZoomMap) and (X < xZoomMap + wZoomMap) and
     1299      (Y >= yZoomMap) and (Y < yZoomMap + hZoomMap) then
     1300    begin
     1301      I := 5;
     1302      while (I >= 0) and not((X >= xZoomMap + 64 * (I mod 3)) and
     1303        (X < xZoomMap + 64 + 64 * (I mod 3)) and
     1304        (Y >= yZoomMap + 20 + 48 * (I div 3)) and
     1305        (Y < yZoomMap + 20 + 52 + 48 * (I div 3))) do
     1306        Dec(I);
     1307      if (I >= 0) and (imix[I] >= 0) then
    13121308        if ssShift in Shift then
    13131309        else if (cix >= 0) and (ClientMode < scContact) and
     
    13161312          CloseAction := None;
    13171313          Close;
    1318           MainScreen.CityClosed(imix[i], false, true);
     1314          MainScreen.CityClosed(imix[I], False, True);
    13191315        end;
    13201316    end
    1321     else if (x >= xmArea - 192) and (x < xmArea + 192) and (y >= ymArea - 96)
    1322       and (y < ymArea + 96) then
     1317    else if (X >= xmArea - 192) and (X < xmArea + 192) and (Y >= ymArea - 96)
     1318      and (Y < ymArea + 96) then
    13231319    with AreaMap do begin
    1324       qx := ((4000 * xxt * yyt) + (x - xmArea) * (yyt * 2) + (y - ymArea + yyt)
     1320      qx := ((4000 * xxt * yyt) + (X - xmArea) * (yyt * 2) + (Y - ymArea + yyt)
    13251321        * (xxt * 2)) div (xxt * yyt * 4) - 1000;
    1326       qy := ((4000 * xxt * yyt) + (y - ymArea + yyt) * (xxt * 2) - (x - xmArea)
     1322      qy := ((4000 * xxt * yyt) + (Y - ymArea + yyt) * (xxt * 2) - (X - xmArea)
    13271323        * (yyt * 2)) div (xxt * yyt * 4) - 1000;
    13281324      dx := qx - qy;
     
    13341330          Loc1 := dLoc(cLoc, dx, dy);
    13351331          if (Loc1 >= 0) and (Loc1 < G.lx * G.ly) then
    1336             HelpOnTerrain(Loc1, FWindowMode or wmPersistent)
     1332            HelpOnTerrain(Loc1, WindowModeMakePersistent(FWindowMode))
    13371333        end
    13381334        else if (ClientMode < scContact) and (cGov <> gAnarchy) and
    1339           (c.Flags and chCaptured = 0) then
     1335          (C.Flags and chCaptured = 0) then
    13401336        begin // toggle exploitation
    1341           assert(not supervising);
    1342           if c.Status and csResourceWeightsMask <> 0 then
     1337          Assert(not Supervising);
     1338          if C.Status and csResourceWeightsMask <> 0 then
    13431339          begin
    1344             with MessgExDlg do
     1340            with MainScreen.MessgExDlg do
    13451341            begin
    13461342              MessgText := Phrases.Lookup('CITYMANAGEOFF');
     
    13501346              ShowModal;
    13511347            end;
    1352             if MessgExDlg.ModalResult = mrOK then
     1348            if MainScreen.MessgExDlg.ModalResult = mrOK then
    13531349            begin
    13541350              MyCity[cix].Status := MyCity[cix].Status and
    13551351                not csResourceWeightsMask; // off
    1356               c.Status := MyCity[cix].Status;
     1352              C.Status := MyCity[cix].Status;
    13571353              SmartUpdateContent;
    13581354            end;
    1359             exit;
     1355            Exit;
    13601356          end;
    13611357          fix := (dy + 3) shl 2 + (dx + 3) shr 1;
    13621358          NewTiles := MyCity[cix].Tiles xor (1 shl fix);
    1363           if Server(sSetCityTiles, me, cix, NewTiles) >= rExecuted then
     1359          if Server(sSetCityTiles, Me, cix, NewTiles) >= rExecuted then
    13641360          begin
    13651361            SmartUpdateContent;
     
    13701366    end
    13711367    else if (ClientMode < scContact) and (cGov <> gAnarchy) and
    1372       (c.Flags and chCaptured = 0) and (x >= xmOpt - 32) and (x < xmOpt + 32)
    1373       and (y >= ymOpt - 32) and (y < ymOpt + 32) then
    1374     begin
    1375       i := sqr(x - xmOpt) + sqr(y - ymOpt); // click radius
    1376       if i <= 32 * 32 then
     1368      (C.Flags and chCaptured = 0) and (X >= xmOpt - 32) and (X < xmOpt + 32)
     1369      and (Y >= ymOpt - 32) and (Y < ymOpt + 32) then
     1370    begin
     1371      I := sqr(X - xmOpt) + sqr(Y - ymOpt); // click radius
     1372      if I <= 32 * 32 then
    13771373      begin
    1378         if i < 16 * 16 then // inner area clicked
    1379           if c.Status and csResourceWeightsMask <> 0 then
    1380             i := (c.Status shr 4 and $0F) mod 5 + 1 // rotate except off
     1374        if I < 16 * 16 then // inner area clicked
     1375          if C.Status and csResourceWeightsMask <> 0 then
     1376            I := (C.Status shr 4 and $0F) mod 5 + 1 // rotate except off
    13811377          else
    1382             i := 3 // rwGrowth
     1378            I := 3 // rwGrowth
    13831379        else
    1384           case trunc(arctan2(x - xmOpt, ymOpt - y) * 180 / pi) of
     1380          case trunc(arctan2(X - xmOpt, ymOpt - Y) * 180 / pi) of
    13851381            - 25 - 52 * 2 .. -26 - 52:
    1386               i := 1;
     1382              I := 1;
    13871383            -25 - 52 .. -26:
    1388               i := 2;
     1384              I := 2;
    13891385            -25 .. 25:
    1390               i := 3;
     1386              I := 3;
    13911387            26 .. 25 + 52:
    1392               i := 4;
     1388              I := 4;
    13931389            26 + 52 .. 25 + 52 * 2:
    1394               i := 5;
     1390              I := 5;
    13951391            180 - 26 .. 180, -180 .. -180 + 26:
    1396               i := 0;
     1392              I := 0;
    13971393          else
    1398             i := -1;
     1394            I := -1;
    13991395          end;
    1400         if i >= 0 then
     1396        if I >= 0 then
    14011397        begin
    1402           ChangeResourceWeights(i);
     1398          ChangeResourceWeights(I);
    14031399          SmartUpdateContent;
    14041400          if WindowMode <> wmModal then
     
    14071403      end;
    14081404    end;
    1409 end; { FormMouseDown }
     1405end;
    14101406
    14111407procedure TCityDlg.ChooseProject;
     
    14221418  );
    14231419
    1424   function ProjectType(Project: integer): TProjectType;
     1420  function ProjectType(Project: Integer): TProjectType;
    14251421  begin
    14261422    if Project and cpCompleted <> 0 then
     
    14441440
    14451441var
    1446   NewProject, OldMoney, cix1: integer;
     1442  NewProject, OldMoney, cix1: Integer;
    14471443  pt0, pt1: TProjectType;
    1448   QueryOk: boolean;
    1449 begin
    1450   Assert(not supervising);
    1451   ModalSelectDlg.ShowNewContent_CityProject(wmModal, cix);
    1452   if ModalSelectDlg.result <> -1 then
    1453   begin
    1454     if ModalSelectDlg.result and cpType <> 0 then
     1444  QueryOk: Boolean;
     1445begin
     1446  Assert(not Supervising);
     1447  MainScreen.ModalSelectDlg.ShowNewContent_CityProject(wmModal, cix);
     1448  if MainScreen.ModalSelectDlg.Result <> -1 then
     1449  begin
     1450    if MainScreen.ModalSelectDlg.Result and cpType <> 0 then
    14551451    begin
    14561452      MyCity[cix].Status := MyCity[cix].Status and not 7 or
    1457         (1 + ModalSelectDlg.result and cpIndex);
    1458       AutoBuild(cix, MyData.ImpOrder[ModalSelectDlg.result and cpIndex]);
     1453        (1 + MainScreen.ModalSelectDlg.Result and cpIndex);
     1454      AutoBuild(cix, MyData.ImpOrder[MainScreen.ModalSelectDlg.Result and cpIndex]);
    14591455    end
    14601456    else
    14611457    begin
    1462       NewProject := ModalSelectDlg.Result;
     1458      NewProject := MainScreen.ModalSelectDlg.Result;
    14631459      QueryOk := True;
    14641460      if (NewProject and cpImp <> 0) and (NewProject and cpIndex >= 28) and
    14651461        (MyRO.NatBuilt[NewProject and cpIndex] > 0) then
    1466         with MessgExDlg do
     1462        with MainScreen.MessgExDlg do
    14671463        begin
    14681464          cix1 := MyRO.nCity - 1;
     
    15211517        then
    15221518          NewProject := NewProject or cpDisbandCity;
    1523       Server(sSetCityProject, me, cix, NewProject);
    1524       c.Project := MyCity[cix].Project;
     1519      Server(sSetCityProject, Me, cix, NewProject);
     1520      C.Project := MyCity[cix].Project;
    15251521      if MyRO.Money > OldMoney then
    15261522        Play('CITY_SELLIMP');
     
    15371533procedure TCityDlg.BuyClick(Sender: TObject);
    15381534var
    1539   NextProd, Cost: integer;
     1535  NextProd, Cost: Integer;
    15401536begin
    15411537  if (cix < 0) or (ClientMode >= scContact) then
    1542     exit;
    1543   with MyCity[cix], MessgExDlg do
     1538    Exit;
     1539  with MyCity[cix], MainScreen.MessgExDlg do
    15441540  begin
    15451541    Cost := Report.ProjectCost;
     
    15481544      NextProd := 0;
    15491545    Cost := Cost - Prod - NextProd;
    1550     if (MyRO.Wonder[woMich].EffectiveOwner = me) and (Project and cpImp <> 0)
     1546    if (MyRO.Wonder[woMich].EffectiveOwner = Me) and (Project and cpImp <> 0)
    15511547    then
    15521548      Cost := Cost * 2
     
    15721568    if (Kind = mkYesNo) and (ModalResult = mrOK) then
    15731569    begin
    1574       if Server(sBuyCityProject, me, cix, nil^) >= rExecuted then
     1570      if Server(sBuyCityProject, Me, cix, nil^) >= rExecuted then
    15751571      begin
    15761572        Play('CITY_BUYPROJECT');
     
    15851581procedure TCityDlg.FormClose(Sender: TObject; var Action: TCloseAction);
    15861582begin
    1587   Timer1.Enabled := false;
    1588   ProdHint := false;
     1583  Timer1.Enabled := False;
     1584  ProdHint := False;
    15891585  MarkCityLoc := -1;
    15901586  if Optimize_cixTileChange >= 0 then
     
    16151611      with Canvas do
    16161612      begin
    1617         DpiBitCanvas(Canvas, xView + 5, yView + 1, 64, 2, Back.Canvas,
     1613        DpiBitBltCanvas(Canvas, xView + 5, yView + 1, 64, 2, Back.Canvas,
    16181614          xView + 5, yView + 1);
    1619         DpiBitCanvas(Canvas, xView + 5, yView + 3, 2, 42, Back.Canvas,
     1615        DpiBitBltCanvas(Canvas, xView + 5, yView + 3, 2, 42, Back.Canvas,
    16201616          xView + 5, yView + 3);
    1621         DpiBitCanvas(Canvas, xView + 5 + 62, yView + 3, 2, 42,
     1617        DpiBitBltCanvas(Canvas, xView + 5 + 62, yView + 3, 2, 42,
    16221618          Back.Canvas, xView + 5 + 62, yView + 3);
    16231619        ScreenTools.Frame(Canvas, xView + 9 - 1, yView + 5 - 1, xView + 9 + xSizeBig,
     
    16321628    else if BlinkTime = 6 then
    16331629    begin
    1634       if AllowChange and (c.Status and 7 <> 0) then
     1630      if AllowChange and (C.Status and 7 <> 0) then
    16351631      begin // city type autobuild
    16361632        FrameImage(Canvas, bigimp, xView + 9, yView + 5, xSizeBig, ySizeBig,
    1637           (c.Status and 7 - 1 + 3) * xSizeBig, 0, true);
     1633          (C.Status and 7 - 1 + 3) * xSizeBig, 0, True);
    16381634      end
    1639       else if c.Project and cpImp = 0 then
     1635      else if C.Project and cpImp = 0 then
    16401636      begin // project is unit
    1641         DpiBitCanvas(Canvas, xView + 9, yView + 5, xSizeBig, ySizeBig,
     1637        DpiBitBltCanvas(Canvas, xView + 9, yView + 5, xSizeBig, ySizeBig,
    16421638          Bigimp.Canvas, 0, 0);
    1643         with Tribe[cOwner].ModelPicture[c.Project and cpIndex] do
     1639        with Tribe[cOwner].ModelPicture[C.Project and cpIndex] do
    16441640          Sprite(Canvas, HGr, xView + 5, yView + 1, 64, 44, pix mod 10 * 65 + 1,
    16451641            pix div 10 * 49 + 1);
    16461642      end
    16471643      else
    1648         ImpImage(Canvas, xView + 9, yView + 5, c.Project0 and cpIndex,
    1649           cGov, true);
     1644        ImpImage(Canvas, xView + 9, yView + 5, C.Project0 and cpIndex,
     1645          cGov, True);
    16501646    end;
    16511647  end;
     
    16631659  if 1 shl OpenSoundEvent = chProduction then
    16641660  begin
    1665     if c.Project0 and cpImp <> 0 then
    1666     begin
    1667       if c.Project0 and cpIndex >= 28 then
     1661    if C.Project0 and cpImp <> 0 then
     1662    begin
     1663      if C.Project0 and cpIndex >= 28 then
    16681664      // wonders have already extra message with sound
    1669         if Imp[c.Project0 and cpIndex].Kind = ikShipPart then
     1665        if Imp[C.Project0 and cpIndex].Kind = ikShipPart then
    16701666          Play('SHIP_BUILT')
    16711667        else
     
    16811677end;
    16821678
    1683 function Prio(iix: integer): integer;
     1679function Prio(iix: Integer): Integer;
    16841680begin
    16851681  case Imp[iix].Kind of
    16861682    ikWonder:
    1687       result := iix + 10000;
     1683      Result := iix + 10000;
    16881684    ikNatLocal, ikNatGlobal:
    16891685      case iix of
    16901686        imPalace:
    1691           result := 0;
     1687          Result := 0;
    16921688      else
    1693         result := iix + 20000;
     1689        Result := iix + 20000;
    16941690      end;
    16951691  else
    16961692    case iix of
    16971693      imTownHall, imCourt:
    1698         result := iix + 30000;
     1694        Result := iix + 30000;
    16991695      imAqueduct, imSewer:
    1700         result := iix + 40000;
     1696        Result := iix + 40000;
    17011697      imTemple, imTheater, imCathedral:
    1702         result := iix + 50000;
    1703     else
    1704       result := iix + 90000;
     1698        Result := iix + 50000;
     1699    else
     1700      Result := iix + 90000;
    17051701    end;
    17061702  end;
     
    17171713end;
    17181714
    1719 procedure TCityDlg.ChangeCity(d: integer);
     1715procedure TCityDlg.ChangeCity(D: Integer);
    17201716var
    1721   cixNew: integer;
     1717  cixNew: Integer;
    17221718begin
    17231719  cixNew := cix;
    17241720  repeat
    1725     cixNew := (cixNew + MyRO.nCity + d) mod MyRO.nCity;
     1721    cixNew := (cixNew + MyRO.nCity + D) mod MyRO.nCity;
    17261722  until (MyCity[cixNew].Loc >= 0) or (cixNew = cix);
    17271723  if cixNew <> cix then
     
    17421738end;
    17431739
    1744 { procedure TCityDlg.AdviceBtnClick(Sender: TObject);
    1745   begin
    1746   AdvisorDlg.GiveCityAdvice(cix);
    1747   end; }
    1748 
    17491740procedure TCityDlg.PageUpBtnClick(Sender: TObject);
    17501741begin
    17511742  if Page > 0 then
    17521743  begin
    1753     dec(Page);
     1744    Dec(Page);
    17541745    SmartUpdateContent;
    17551746  end;
     
    17601751  if Page < PageCount - 1 then
    17611752  begin
    1762     inc(Page);
     1753    Inc(Page);
    17631754    SmartUpdateContent;
    17641755  end;
    17651756end;
    17661757
    1767 procedure TCityDlg.ChangeResourceWeights(iResourceWeights: integer);
     1758procedure TCityDlg.ChangeResourceWeights(iResourceWeights: Integer);
    17681759var
    17691760  Advice: TCityTileAdviceData;
    17701761begin
    1771   assert(not supervising);
    1772   assert(cix >= 0);
     1762  Assert(not Supervising);
     1763  Assert(cix >= 0);
    17731764  MyCity[cix].Status := MyCity[cix].Status and not csResourceWeightsMask or
    17741765    (iResourceWeights shl 4);
    1775   c.Status := MyCity[cix].Status;
     1766  C.Status := MyCity[cix].Status;
    17761767  if iResourceWeights > 0 then
    17771768  begin
    17781769    Advice.ResourceWeights := OfferedResourceWeights[iResourceWeights];
    1779     Server(sGetCityTileAdvice, me, cix, Advice);
     1770    Server(sGetCityTileAdvice, Me, cix, Advice);
    17801771    if Advice.Tiles <> MyCity[cix].Tiles then
    1781       Server(sSetCityTiles, me, cix, Advice.Tiles);
     1772      Server(sSetCityTiles, Me, cix, Advice.Tiles);
    17821773  end;
    17831774end;
     
    17851776procedure SortImprovements;
    17861777var
    1787   i, j, k: integer;
    1788 begin
    1789   for i := 0 to nImp - 1 do
    1790     ImpSorted[i] := i;
    1791   for i := 0 to nImp - 2 do
    1792     for j := i + 1 to nImp - 1 do
    1793       if Prio(ImpSorted[i]) > Prio(ImpSorted[j]) then begin
    1794         k := ImpSorted[i];
    1795         ImpSorted[i] := ImpSorted[j];
    1796         ImpSorted[j] := k;
     1778  I, J, K: Integer;
     1779begin
     1780  for I := 0 to nImp - 1 do
     1781    ImpSorted[I] := I;
     1782  for I := 0 to nImp - 2 do
     1783    for J := I + 1 to nImp - 1 do
     1784      if Prio(ImpSorted[I]) > Prio(ImpSorted[J]) then begin
     1785        K := ImpSorted[I];
     1786        ImpSorted[I] := ImpSorted[J];
     1787        ImpSorted[J] := K;
    17971788      end;
    17981789end;
  • TabularUnified branches/highdpi/LocalPlayer/CityType.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin, LCLIntf, LCLType,
    8   SysUtils, Classes, Graphics, Controls, Forms,
    9   ButtonB, ExtCtrls;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType,
     8  SysUtils, Classes, Graphics, Controls, Forms, ButtonB, ExtCtrls;
    109
    1110type
     
    1817    procedure FormShow(Sender: TObject);
    1918    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    20       Shift: TShiftState; x, y: integer);
     19      Shift: TShiftState; X, Y: Integer);
    2120    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    22       Shift: TShiftState; x, y: integer);
     21      Shift: TShiftState; X, Y: Integer);
    2322    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    2423    procedure DeleteBtnClick(Sender: TObject);
    2524  public
    26     procedure ShowNewContent(NewMode: integer);
     25    procedure ShowNewContent(NewMode: TWindowMode);
    2726  protected
    2827    procedure OffscreenPaint; override;
    2928  private
    30     nPool, dragiix, ctype: integer;
    31     Pooliix: array [0 .. nImp - 1] of integer;
     29    nPool, dragiix, ctype: Integer;
     30    Pooliix: array [0 .. nImp - 1] of Integer;
    3231    listed: Set of 0 .. nImp;
    33     Changed: boolean;
    34     procedure LoadType(NewType: integer);
     32    Changed: Boolean;
     33    procedure LoadType(NewType: Integer);
    3534    procedure SaveType;
    3635  end;
    3736
    38 var
    39   CityTypeDlg: TCityTypeDlg;
    4037
    4138implementation
    4239
    43 uses Help;
     40uses
     41  Help, Term;
    4442
    4543{$R *.lfm}
     
    8280procedure TCityTypeDlg.OffscreenPaint;
    8381var
    84   i, iix: integer;
    85   s: string;
     82  I, iix: Integer;
     83  S: string;
    8684begin
    8785  inherited;
    88   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     86  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    8987  FillOffscreen(xList - 7, yList, 42 * nListCol + 14, 32 * nListRow);
    9088  FillOffscreen(xPool - 7, yPool, 42 * nPoolCol + 14, 32 * nPoolRow);
     
    9290    yPool - yList - 32 * nListRow);
    9391
    94   Frame(offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,
     92  Frame(Offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,
    9593    yPool - 23, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    96   Frame(offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,
     94  Frame(Offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,
    9795    InnerWidth - 89, yPool - 23, MainTexture.ColorBevelLight,
    9896    MainTexture.ColorBevelShade);
    99   Frame(offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,
     97  Frame(Offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,
    10098    InnerWidth - 1, yPool - 23, MainTexture.ColorBevelLight,
    10199    MainTexture.ColorBevelShade);
    102   Frame(offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,
     100  Frame(Offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,
    103101    MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    104   for i := 0 to nCityType - 1 do
    105   begin
    106     RFrame(offscreen.Canvas, xSwitch + i * 42, ySwitch, xSwitch + 39 + i * 42,
     102  for I := 0 to nCityType - 1 do
     103  begin
     104    RFrame(Offscreen.Canvas, xSwitch + I * 42, ySwitch, xSwitch + 39 + I * 42,
    107105      ySwitch + 23, MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    108     if i = ctype then
    109       Frame(offscreen.Canvas, xSwitch + 1 + i * 42, ySwitch + 1,
    110         xSwitch + 38 + i * 42, ySwitch + 22, MainTexture.ColorBevelShade,
     106    if I = ctype then
     107      Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1,
     108        xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelShade,
    111109        MainTexture.ColorBevelLight)
    112110    else
    113       Frame(offscreen.Canvas, xSwitch + 1 + i * 42, ySwitch + 1,
    114         xSwitch + 38 + i * 42, ySwitch + 22, MainTexture.ColorBevelLight,
     111      Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1,
     112        xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelLight,
    115113        MainTexture.ColorBevelShade);
    116     DpiBitCanvas(offscreen.Canvas, xSwitch + 2 + i * 42, ySwitch + 2,
    117       xSizeSmall, ySizeSmall, SmallImp.Canvas, (i + 3) * xSizeSmall, 0);
    118   end;
    119   RisedTextOut(offscreen.Canvas, 8, yList + 32 * nListRow + 2,
     114    DpiBitBltCanvas(Offscreen.Canvas, xSwitch + 2 + I * 42, ySwitch + 2,
     115      xSizeSmall, ySizeSmall, SmallImp.Canvas, (I + 3) * xSizeSmall, 0);
     116  end;
     117  RisedTextOut(Offscreen.Canvas, 8, yList + 32 * nListRow + 2,
    120118    Phrases.Lookup('BUILDORDER'));
    121   RisedTextOut(offscreen.Canvas, 8, ySwitch + 26,
     119  RisedTextOut(Offscreen.Canvas, 8, ySwitch + 26,
    122120    Phrases.Lookup('CITYTYPE', ctype));
    123   s := Phrases.Lookup('BUILDREST');
    124   RisedTextOut(offscreen.Canvas,
    125     (InnerWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2,
    126     yList + 72 + 32 * nListRow, s);
    127 
    128   with offscreen.Canvas do
    129   begin
    130     for i := 1 to nListRow - 1 do
    131       DLine(offscreen.Canvas, xList - 5, xList + 4 + 42 * nListCol,
    132         yList - 1 + 32 * i, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    133     for i := 0 to nListCol * nListRow - 1 do
    134     begin
    135       s := IntToStr(i + 1);
     121  S := Phrases.Lookup('BUILDREST');
     122  RisedTextOut(Offscreen.Canvas,
     123    (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2,
     124    yList + 72 + 32 * nListRow, S);
     125
     126  with Offscreen.Canvas do
     127  begin
     128    for I := 1 to nListRow - 1 do
     129      DLine(Offscreen.Canvas, xList - 5, xList + 4 + 42 * nListCol,
     130        yList - 1 + 32 * I, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
     131    for I := 0 to nListCol * nListRow - 1 do
     132    begin
     133      S := IntToStr(I + 1);
    136134      Font.Color := MainTexture.ColorTextLight;
    137       Textout(xList + 20 + i mod nListCol * 42 - TextWidth(s) div 2,
    138         yList + 15 + i div nListCol * 32 - TextHeight(s) div 2, s);
    139     end;
    140   end;
    141 
    142   i := 0;
    143   while MyData.ImpOrder[ctype, i] >= 0 do
    144   begin
    145     RFrame(offscreen.Canvas, xList + 20 - xSizeSmall div 2 + i mod nListCol *
    146       42, yList + 15 - ySizeSmall div 2 + i div nListCol * 32,
    147       xList + 21 + xSizeSmall div 2 + i mod nListCol * 42,
    148       yList + 16 + ySizeSmall div 2 + i div nListCol * 32,
     135      Textout(xList + 20 + I mod nListCol * 42 - TextWidth(S) div 2,
     136        yList + 15 + I div nListCol * 32 - TextHeight(S) div 2, S);
     137    end;
     138  end;
     139
     140  I := 0;
     141  while MyData.ImpOrder[ctype, I] >= 0 do
     142  begin
     143    RFrame(Offscreen.Canvas, xList + 20 - xSizeSmall div 2 + I mod nListCol *
     144      42, yList + 15 - ySizeSmall div 2 + I div nListCol * 32,
     145      xList + 21 + xSizeSmall div 2 + I mod nListCol * 42,
     146      yList + 16 + ySizeSmall div 2 + I div nListCol * 32,
    149147      MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    150     DpiBitCanvas(offscreen.Canvas, xList + 21 - xSizeSmall div 2 +
    151       i mod nListCol * 42, yList + 16 - ySizeSmall div 2 + i div nListCol * 32,
     148    DpiBitBltCanvas(Offscreen.Canvas, xList + 21 - xSizeSmall div 2 +
     149      I mod nListCol * 42, yList + 16 - ySizeSmall div 2 + I div nListCol * 32,
    152150      xSizeSmall, ySizeSmall, SmallImp.Canvas,
    153       MyData.ImpOrder[ctype, i] mod 7 * xSizeSmall,
    154       (MyData.ImpOrder[ctype, i] + SystemIconLines * 7) div 7 *
     151      MyData.ImpOrder[ctype, I] mod 7 * xSizeSmall,
     152      (MyData.ImpOrder[ctype, I] + SystemIconLines * 7) div 7 *
    155153      ySizeSmall);
    156     inc(i);
     154    Inc(I);
    157155  end;
    158156
     
    165163    begin
    166164      Pooliix[nPool] := iix;
    167       RFrame(offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +
     165      RFrame(Offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +
    168166        nPool mod nPoolCol * 42, yPool + 15 - ySizeSmall div 2 +
    169167        nPool div nPoolCol * 32, xPool + 21 + xSizeSmall div 2 +
     
    171169        nPool div nPoolCol * 32, MainTexture.ColorBevelLight,
    172170        MainTexture.ColorBevelShade);
    173       DpiBitCanvas(offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +
     171      DpiBitBltCanvas(Offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +
    174172        nPool mod nPoolCol * 42, yPool + 16 - ySizeSmall div 2 +
    175173        nPool div nPoolCol * 32, xSizeSmall, ySizeSmall, SmallImp.Canvas,
    176174        iix mod 7 * xSizeSmall, (iix + SystemIconLines * 7) div 7 *
    177175        ySizeSmall);
    178       inc(nPool);
     176      Inc(nPool);
    179177    end;
    180178  DeleteBtn.Visible := MyData.ImpOrder[ctype, 0] >= 0;
     
    182180  if dragiix >= 0 then
    183181  begin
    184     ImpImage(offscreen.Canvas, xView + 9, yView + 5, dragiix);
    185     s := Phrases.Lookup('IMPROVEMENTS', dragiix);
    186     RisedTextOut(offscreen.Canvas,
    187       xView + 36 - BiColorTextWidth(offscreen.Canvas, s) div 2,
    188       ySwitch + 26, s);
     182    ImpImage(Offscreen.Canvas, xView + 9, yView + 5, dragiix);
     183    S := Phrases.Lookup('IMPROVEMENTS', dragiix);
     184    RisedTextOut(Offscreen.Canvas,
     185      xView + 36 - BiColorTextWidth(Offscreen.Canvas, S) div 2,
     186      ySwitch + 26, S);
    189187  end;
    190188  MarkUsedOffscreen(InnerWidth, InnerHeight);
    191 end; { MainPaint }
    192 
    193 procedure TCityTypeDlg.LoadType(NewType: integer);
    194 var
    195   i: integer;
     189end;
     190
     191procedure TCityTypeDlg.LoadType(NewType: Integer);
     192var
     193  I: Integer;
    196194begin
    197195  ctype := NewType;
    198196  listed := [];
    199   i := 0;
    200   while MyData.ImpOrder[ctype, i] >= 0 do
    201   begin
    202     include(listed, MyData.ImpOrder[ctype, i]);
    203     inc(i);
    204   end;
    205   Changed := false;
     197  I := 0;
     198  while MyData.ImpOrder[ctype, I] >= 0 do
     199  begin
     200    Include(listed, MyData.ImpOrder[ctype, I]);
     201    Inc(I);
     202  end;
     203  Changed := False;
    206204end;
    207205
    208206procedure TCityTypeDlg.SaveType;
    209207var
    210   cix: integer;
     208  cix: Integer;
    211209begin
    212210  if Changed then
     
    215213      if (MyCity[cix].Loc >= 0) and (MyCity[cix].Status and 7 = ctype + 1) then
    216214        AutoBuild(cix, MyData.ImpOrder[ctype]);
    217     Changed := false;
     215    Changed := False;
    218216  end;
    219217end;
     
    226224end;
    227225
    228 procedure TCityTypeDlg.ShowNewContent(NewMode: integer);
     226procedure TCityTypeDlg.ShowNewContent(NewMode: TWindowMode);
    229227begin
    230228  inherited ShowNewContent(NewMode);
     
    232230
    233231procedure TCityTypeDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    234   Shift: TShiftState; x, y: integer);
    235 var
    236   i: integer;
    237 begin
    238   x := x - SideFrame;
    239   y := y - WideFrame;
    240   i := (x - xList) div 42 + (y - yList) div 32 * nListCol;
    241   if (i < nImp) and (MyData.ImpOrder[ctype, i] >= 0) and
    242     (x > xList + 2 + i mod nListCol * 42) and
    243     (y > yList + 5 + i div nListCol * 32) and
    244     (x < xList + 3 + 36 + i mod nListCol * 42) and
    245     (y < yList + 6 + 20 + i div nListCol * 32) then
     232  Shift: TShiftState; X, Y: Integer);
     233var
     234  I: Integer;
     235begin
     236  X := X - SideFrame;
     237  Y := Y - WideFrame;
     238  I := (X - xList) div 42 + (Y - yList) div 32 * nListCol;
     239  if (I < nImp) and (MyData.ImpOrder[ctype, I] >= 0) and
     240    (X > xList + 2 + I mod nListCol * 42) and
     241    (Y > yList + 5 + I div nListCol * 32) and
     242    (X < xList + 3 + 36 + I mod nListCol * 42) and
     243    (Y < yList + 6 + 20 + I div nListCol * 32) then
    246244  begin
    247245    if ssShift in Shift then
    248       HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp,
    249         MyData.ImpOrder[ctype, i])
     246      MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp,
     247        MyData.ImpOrder[ctype, I])
    250248    else
    251249    begin
    252       dragiix := MyData.ImpOrder[ctype, i];
     250      dragiix := MyData.ImpOrder[ctype, I];
    253251      DpiScreen.Cursor := crImpDrag;
    254252      SmartUpdateContent;
    255253    end;
    256     exit;
    257   end;
    258   i := (x - xPool) div 42 + (y - yPool) div 32 * nPoolCol;
    259   if (i < nPool) and (x > xPool + 2 + i mod nPoolCol * 42) and
    260     (y > yPool + 5 + i div nPoolCol * 32) and
    261     (x < xPool + 3 + 36 + i mod nPoolCol * 42) and
    262     (y < yPool + 6 + 20 + i div nPoolCol * 32) then
     254    Exit;
     255  end;
     256  I := (X - xPool) div 42 + (Y - yPool) div 32 * nPoolCol;
     257  if (I < nPool) and (X > xPool + 2 + I mod nPoolCol * 42) and
     258    (Y > yPool + 5 + I div nPoolCol * 32) and
     259    (X < xPool + 3 + 36 + I mod nPoolCol * 42) and
     260    (Y < yPool + 6 + 20 + I div nPoolCol * 32) then
    263261  begin
    264262    if ssShift in Shift then
    265       HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, Pooliix[i])
     263      MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Pooliix[I])
    266264    else
    267265    begin
    268       dragiix := Pooliix[i];
     266      dragiix := Pooliix[I];
    269267      DpiScreen.Cursor := crImpDrag;
    270268      SmartUpdateContent;
    271269    end;
    272     exit;
    273   end;
    274   i := (x - xSwitch) div 42;
    275   if (i < nCityType) and (x > xSwitch + 2 + i * 42) and
    276     (x < xSwitch + 3 + 36 + i * 42) and (y >= ySwitch + 2) and (y < ySwitch + 22)
     270    Exit;
     271  end;
     272  I := (X - xSwitch) div 42;
     273  if (I < nCityType) and (X > xSwitch + 2 + I * 42) and
     274    (X < xSwitch + 3 + 36 + I * 42) and (Y >= ySwitch + 2) and (Y < ySwitch + 22)
    277275  then
    278276  begin
    279277    SaveType;
    280     LoadType(i);
     278    LoadType(I);
    281279    SmartUpdateContent;
    282280  end;
     
    284282
    285283procedure TCityTypeDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    286   Shift: TShiftState; x, y: integer);
    287 
    288   procedure UnList(iix: integer);
     284  Shift: TShiftState; X, Y: Integer);
     285
     286  procedure UnList(iix: Integer);
    289287  var
    290     i: integer;
    291   begin
    292     i := 0;
    293     while (MyData.ImpOrder[ctype, i] >= 0) and
    294       (MyData.ImpOrder[ctype, i] <> iix) do
    295       inc(i);
    296     assert(MyData.ImpOrder[ctype, i] = iix);
    297     move(MyData.ImpOrder[ctype, i + 1], MyData.ImpOrder[ctype, i], nImp - i);
     288    I: Integer;
     289  begin
     290    I := 0;
     291    while (MyData.ImpOrder[ctype, I] >= 0) and
     292      (MyData.ImpOrder[ctype, I] <> iix) do
     293      Inc(I);
     294    Assert(MyData.ImpOrder[ctype, I] = iix);
     295    Move(MyData.ImpOrder[ctype, I + 1], MyData.ImpOrder[ctype, I], nImp - I);
    298296    Exclude(listed, iix);
    299297  end;
    300298
    301299var
    302   i: integer;
    303 begin
    304   x := x - SideFrame;
    305   y := y - WideFrame;
     300  I: Integer;
     301begin
     302  X := X - SideFrame;
     303  Y := Y - WideFrame;
    306304  if dragiix >= 0 then
    307305  begin
    308     if (x >= xList) and (x < xList + nListCol * 42) and (y >= yList) and
    309       (y < yList + nListRow * 32) then
     306    if (X >= xList) and (X < xList + nListCol * 42) and (Y >= yList) and
     307      (Y < yList + nListRow * 32) then
    310308    begin
    311309      if dragiix in listed then
    312310        UnList(dragiix);
    313       i := (x - xList) div 42 + (y - yList) div 32 * nListCol;
    314       while (i > 0) and (MyData.ImpOrder[ctype, i - 1] < 0) do
    315         dec(i);
    316       move(MyData.ImpOrder[ctype, i], MyData.ImpOrder[ctype, i + 1],
    317         nImp - i - 1);
    318       MyData.ImpOrder[ctype, i] := dragiix;
    319       include(listed, dragiix);
    320       Changed := true;
     311      I := (X - xList) div 42 + (Y - yList) div 32 * nListCol;
     312      while (I > 0) and (MyData.ImpOrder[ctype, I - 1] < 0) do
     313        Dec(I);
     314      Move(MyData.ImpOrder[ctype, I], MyData.ImpOrder[ctype, I + 1],
     315        nImp - I - 1);
     316      MyData.ImpOrder[ctype, I] := dragiix;
     317      Include(listed, dragiix);
     318      Changed := True;
    321319    end
    322     else if (dragiix in listed) and (x >= xPool) and (x < xPool + nPoolCol * 42)
    323       and (y >= yPool) and (y < yPool + nPoolRow * 32) then
     320    else if (dragiix in listed) and (X >= xPool) and (X < xPool + nPoolCol * 42)
     321      and (Y >= yPool) and (Y < yPool + nPoolRow * 32) then
    324322    begin
    325323      UnList(dragiix);
    326       Changed := true;
     324      Changed := True;
    327325    end;
    328326    dragiix := -1;
     
    340338procedure TCityTypeDlg.DeleteBtnClick(Sender: TObject);
    341339begin
    342   fillchar(MyData.ImpOrder[ctype], sizeof(MyData.ImpOrder[ctype]), Byte(-1));
     340  FillChar(MyData.ImpOrder[ctype], SizeOf(MyData.ImpOrder[ctype]), Byte(-1));
    343341  listed := [];
    344   Changed := true;
     342  Changed := True;
    345343  SmartUpdateContent;
    346344end;
  • TabularUnified branches/highdpi/LocalPlayer/ClientTools.pas

    r405 r465  
    99const
    1010  nOfferedResourceWeights = 6;
    11   OfferedResourceWeights: array [0 .. nOfferedResourceWeights - 1] of cardinal =
     11  OfferedResourceWeights: array [0 .. nOfferedResourceWeights - 1] of Cardinal =
    1212    (rwOff, rwMaxScience, rwForceScience, rwMaxGrowth, rwForceProd, rwMaxProd);
    1313
    1414type
    15   TImpOrder = array [0 .. (nImp + 4) div 4 * 4 - 1] of shortint;
    16   TEnhancementJobs = array [0 .. 11, 0 .. 7] of byte;
     15  TImpOrder = array [0 .. (nImp + 4) div 4 * 4 - 1] of ShortInt;
     16  TEnhancementJobs = array [0 .. 11, 0 .. 7] of Byte;
    1717  JobResultSet = set of 0 .. 39;
    1818
     
    3636  Server: TServerCall;
    3737  G: TNewGameData;
    38   me: integer;
     38  Me: Integer;
    3939  MyRO: ^TPlayerContext;
    4040  MyMap: ^TTileList;
     
    4343  MyModel: ^TModelList;
    4444
    45   AdvValue: array [0 .. nAdv - 1] of integer;
    46 
    47 function dLoc(Loc, dx, dy: integer): integer;
    48 function Distance(Loc0, Loc1: integer): integer;
    49 function UnrestAtLoc(uix, Loc: integer): boolean;
    50 function GetMoveAdvice(uix, ToLoc: integer;
    51   var MoveAdviceData: TMoveAdviceData): integer;
    52 function ColorOfHealth(Health: integer): integer;
    53 function IsMultiPlayerGame: boolean;
    54 procedure ItsMeAgain(p: integer);
    55 function GetAge(p: integer): integer;
    56 function IsCivilReportNew(Enemy: integer): boolean;
    57 function IsMilReportNew(Enemy: integer): boolean;
    58 function CutCityFoodSurplus(FoodSurplus: integer; IsCityAlive: boolean;
    59   gov, size: integer): integer;
    60 function CityTaxBalance(cix: integer; const CityReport: TCityReportNew): integer;
    61 procedure SumCities(var TaxSum, ScienceSum: integer);
    62 function JobTest(uix, Job: integer; IgnoreResults: JobResultSet = []): boolean;
    63 procedure GetUnitInfo(Loc: integer; var uix: integer; var UnitInfo: TUnitInfo);
    64 procedure GetCityInfo(Loc: integer; var cix: integer; var CityInfo: TCityInfo);
    65 function UnitExhausted(uix: integer): boolean;
    66 function ModelHash(const ModelInfo: TModelInfo): integer;
    67 function ProcessEnhancement(uix: integer; const Jobs: TEnhancementJobs): integer;
    68 function AutoBuild(cix: integer; const ImpOrder: TImpOrder): boolean;
    69 procedure DebugMessage(Level: integer; Text: string);
     45  AdvValue: array [0 .. nAdv - 1] of Integer;
     46
     47function dLoc(Loc, dx, dy: Integer): Integer;
     48function Distance(Loc0, Loc1: Integer): Integer;
     49function UnrestAtLoc(uix, Loc: Integer): Boolean;
     50function GetMoveAdvice(uix, ToLoc: Integer;
     51  var MoveAdviceData: TMoveAdviceData): Integer;
     52function ColorOfHealth(Health: Integer): Integer;
     53function IsMultiPlayerGame: Boolean;
     54procedure ItsMeAgain(P: Integer);
     55function GetAge(P: Integer): Integer;
     56function IsCivilReportNew(Enemy: Integer): Boolean;
     57function IsMilReportNew(Enemy: Integer): Boolean;
     58function CutCityFoodSurplus(FoodSurplus: Integer; IsCityAlive: Boolean;
     59  gov, size: Integer): Integer;
     60function CityTaxBalance(cix: Integer; const CityReport: TCityReportNew): Integer;
     61procedure SumCities(var TaxSum, ScienceSum: Integer);
     62function JobTest(uix, Job: Integer; IgnoreResults: JobResultSet = []): Boolean;
     63procedure GetUnitInfo(Loc: Integer; var uix: Integer; var UnitInfo: TUnitInfo);
     64procedure GetCityInfo(Loc: Integer; var cix: Integer; var CityInfo: TCityInfo);
     65function UnitExhausted(uix: Integer): Boolean;
     66function ModelHash(const ModelInfo: TModelInfo): Integer;
     67function ProcessEnhancement(uix: Integer; const Jobs: TEnhancementJobs): Integer;
     68function AutoBuild(cix: Integer; const ImpOrder: TImpOrder): Boolean;
     69procedure DebugMessage(Level: Integer; Text: string);
    7070procedure CityOptimizer_BeginOfTurn;
    71 procedure CityOptimizer_CityChange(cix: integer);
    72 procedure CityOptimizer_TileBecomesAvailable(Loc: integer);
    73 procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: integer);
    74 procedure CityOptimizer_BeforeRemoveUnit(uix: integer);
     71procedure CityOptimizer_CityChange(cix: Integer);
     72procedure CityOptimizer_TileBecomesAvailable(Loc: Integer);
     73procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: Integer);
     74procedure CityOptimizer_BeforeRemoveUnit(uix: Integer);
    7575procedure CityOptimizer_AfterRemoveUnit;
    7676procedure CityOptimizer_EndOfTurn;
     
    8484
    8585var
    86   CityNeedsOptimize: array [0 .. ncmax - 1] of boolean;
    87 
    88 function dLoc(Loc, dx, dy: integer): integer;
    89 var
    90   y0: integer;
     86  CityNeedsOptimize: array [0 .. ncmax - 1] of Boolean;
     87
     88function dLoc(Loc, dx, dy: Integer): Integer;
     89var
     90  y0: Integer;
    9191begin
    9292  y0 := (Loc + G.lx * 1024) div G.lx - 1024;
     
    9494end;
    9595
    96 function Distance(Loc0, Loc1: integer): integer;
    97 var
    98   dx, dy: integer;
     96function Distance(Loc0, Loc1: Integer): Integer;
     97var
     98  dx, dy: Integer;
    9999begin
    100100  Inc(Loc0, G.lx * 1024);
     
    106106end;
    107107
    108 function UnrestAtLoc(uix, Loc: integer): boolean;
    109 var
    110   uix1: integer;
     108function UnrestAtLoc(uix, Loc: Integer): Boolean;
     109var
     110  uix1: Integer;
    111111begin
    112112  Result := False;
     
    114114    case MyRO.Government of
    115115      gRepublic, gFuture:
    116         Result := (MyRO.Territory[Loc] >= 0) and (MyRO.Territory[Loc] <> me) and
     116        Result := (MyRO.Territory[Loc] >= 0) and (MyRO.Territory[Loc] <> Me) and
    117117          (MyRO.Treaty[MyRO.Territory[Loc]] < trAlliance);
    118118      gDemocracy:
    119         Result := (MyRO.Territory[Loc] < 0) or (MyRO.Territory[Loc] <> me) and
     119        Result := (MyRO.Territory[Loc] < 0) or (MyRO.Territory[Loc] <> Me) and
    120120          (MyRO.Treaty[MyRO.Territory[Loc]] < trAlliance);
    121121    end;
     
    127127end;
    128128
    129 function GetMoveAdvice(uix, ToLoc: integer;
    130   var MoveAdviceData: TMoveAdviceData): integer;
    131 var
    132   MinEndHealth: integer;
     129function GetMoveAdvice(uix, ToLoc: Integer;
     130  var MoveAdviceData: TMoveAdviceData): Integer;
     131var
     132  MinEndHealth: Integer;
    133133begin
    134134  if MyModel[MyUn[uix].mix].Domain = dGround then
     
    142142      MoveAdviceData.MoreTurns := 999;
    143143      MoveAdviceData.MaxHostile_MovementLeft := MyUn[uix].Health - MinEndHealth;
    144       Result := Server(sGetMoveAdvice, me, uix, MoveAdviceData);
     144      Result := Server(sGetMoveAdvice, Me, uix, MoveAdviceData);
    145145      if (MinEndHealth <= 1) or (Result <> eNoWay) then
    146         exit;
     146        Exit;
    147147    end;
    148148    case MinEndHealth of
     
    159159end;
    160160
    161 function ColorOfHealth(Health: integer): integer;
    162 var
    163   red, green: integer;
    164 begin
    165   green := 400 * Health div 100;
    166   if green > 200 then
    167     green := 200;
    168   red := 510 * (100 - Health) div 100;
    169   if red > 255 then
    170     red := 255;
    171   Result := green shl 8 + red;
    172 end;
    173 
    174 function IsMultiPlayerGame: boolean;
    175 var
    176   p1: integer;
     161function ColorOfHealth(Health: Integer): Integer;
     162var
     163  Red, Green: Integer;
     164begin
     165  Green := 400 * Health div 100;
     166  if Green > 200 then
     167    Green := 200;
     168  Red := 510 * (100 - Health) div 100;
     169  if Red > 255 then
     170    Red := 255;
     171  Result := Green shl 8 + Red;
     172end;
     173
     174function IsMultiPlayerGame: Boolean;
     175var
     176  p1: Integer;
    177177begin
    178178  Result := False;
     
    182182end;
    183183
    184 procedure ItsMeAgain(p: integer);
    185 begin
    186   if G.RO[p] <> nil then
    187     MyRO := pointer(G.RO[p])
    188   else if G.SuperVisorRO[p] <> nil then
    189     MyRO := pointer(G.SuperVisorRO[p])
     184procedure ItsMeAgain(P: Integer);
     185begin
     186  if G.RO[P] <> nil then
     187    MyRO := Pointer(G.RO[P])
     188  else if G.SuperVisorRO[P] <> nil then
     189    MyRO := Pointer(G.SuperVisorRO[P])
    190190  else
    191     exit;
    192   me := p;
    193   MyMap := pointer(MyRO.Map);
    194   MyUn := pointer(MyRO.Un);
    195   MyCity := pointer(MyRO.City);
    196   MyModel := pointer(MyRO.Model);
    197 end;
    198 
    199 function GetAge(p: integer): integer;
    200 var
    201   i: integer;
    202 begin
    203   if p = me then begin
     191    Exit;
     192  Me := P;
     193  MyMap := Pointer(MyRO.Map);
     194  MyUn := Pointer(MyRO.Un);
     195  MyCity := Pointer(MyRO.City);
     196  MyModel := Pointer(MyRO.Model);
     197end;
     198
     199function GetAge(P: Integer): Integer;
     200var
     201  I: Integer;
     202begin
     203  if P = Me then begin
    204204    Result := 0;
    205     for i := 1 to 3 do
    206       if MyRO.Tech[AgePreq[i]] >= tsApplicable then
    207         Result := i;
     205    for I := 1 to 3 do
     206      if MyRO.Tech[AgePreq[I]] >= tsApplicable then
     207        Result := I;
    208208  end else begin
    209209    Result := 0;
    210     for i := 1 to 3 do
    211       if MyRO.EnemyReport[p].Tech[AgePreq[i]] >= tsApplicable then
    212         Result := i;
    213   end;
    214 end;
    215 
    216 function IsCivilReportNew(Enemy: integer): boolean;
    217 var
    218   i: integer;
    219 begin
    220   assert(Enemy <> me);
    221   i := MyRO.EnemyReport[Enemy].TurnOfCivilReport;
    222   Result := (i = MyRO.Turn) or (i = MyRO.Turn - 1) and (Enemy > me);
    223 end;
    224 
    225 function IsMilReportNew(Enemy: integer): boolean;
    226 var
    227   i: integer;
    228 begin
    229   assert(Enemy <> me);
    230   i := MyRO.EnemyReport[Enemy].TurnOfMilReport;
    231   Result := (i = MyRO.Turn) or (i = MyRO.Turn - 1) and (Enemy > me);
    232 end;
    233 
    234 function CutCityFoodSurplus(FoodSurplus: integer; IsCityAlive: boolean;
    235   gov, size: integer): integer;
     210    for I := 1 to 3 do
     211      if MyRO.EnemyReport[P].Tech[AgePreq[I]] >= tsApplicable then
     212        Result := I;
     213  end;
     214end;
     215
     216function IsCivilReportNew(Enemy: Integer): Boolean;
     217var
     218  I: Integer;
     219begin
     220  Assert(Enemy <> Me);
     221  I := MyRO.EnemyReport[Enemy].TurnOfCivilReport;
     222  Result := (I = MyRO.Turn) or (I = MyRO.Turn - 1) and (Enemy > Me);
     223end;
     224
     225function IsMilReportNew(Enemy: Integer): Boolean;
     226var
     227  I: Integer;
     228begin
     229  Assert(Enemy <> Me);
     230  I := MyRO.EnemyReport[Enemy].TurnOfMilReport;
     231  Result := (I = MyRO.Turn) or (I = MyRO.Turn - 1) and (Enemy > Me);
     232end;
     233
     234function CutCityFoodSurplus(FoodSurplus: Integer; IsCityAlive: Boolean;
     235  gov, size: Integer): Integer;
    236236begin
    237237  Result := FoodSurplus;
     
    241241end;
    242242
    243 function CityTaxBalance(cix: integer; const CityReport: TCityReportNew): integer;
    244 var
    245   i: integer;
     243function CityTaxBalance(cix: Integer; const CityReport: TCityReportNew): Integer;
     244var
     245  I: Integer;
    246246begin
    247247  Result := 0;
     
    258258      Inc(Result, CityReport.FoodSurplus);
    259259  end;
    260   for i := nWonder to nImp - 1 do
    261     if MyCity[cix].Built[i] > 0 then
    262       Dec(Result, Imp[i].Maint);
    263 end;
    264 
    265 procedure SumCities(var TaxSum, ScienceSum: integer);
    266 var
    267   cix: integer;
     260  for I := nWonder to nImp - 1 do
     261    if MyCity[cix].Built[I] > 0 then
     262      Dec(Result, Imp[I].Maint);
     263end;
     264
     265procedure SumCities(var TaxSum, ScienceSum: Integer);
     266var
     267  cix: Integer;
    268268  CityReport: TCityReportNew;
    269269begin
     
    271271  ScienceSum := 0;
    272272  if MyRO.Government = gAnarchy then
    273     exit;
     273    Exit;
    274274  for cix := 0 to MyRO.nCity - 1 do
    275275    if MyCity[cix].Loc >= 0 then
     
    278278      CityReport.HypoTaxRate := -1;
    279279      CityReport.HypoLuxuryRate := -1;
    280       Server(sGetCityReportNew, me, cix, CityReport);
     280      Server(sGetCityReportNew, Me, cix, CityReport);
    281281      if (CityReport.HappinessBalance >= 0) { no disorder } and
    282282        (MyCity[cix].Flags and chCaptured = 0) then // not captured
     
    286286end;
    287287
    288 function JobTest(uix, Job: integer; IgnoreResults: JobResultSet): boolean;
    289 var
    290   Test: integer;
    291 begin
    292   Test := Server(sStartJob + Job shl 4 - sExecute, me, uix, nil^);
     288function JobTest(uix, Job: Integer; IgnoreResults: JobResultSet): Boolean;
     289var
     290  Test: Integer;
     291begin
     292  Test := Server(sStartJob + Job shl 4 - sExecute, Me, uix, nil^);
    293293  Result := (Test >= rExecuted) or (Test in IgnoreResults);
    294294end;
    295295
    296 procedure GetUnitInfo(Loc: integer; var uix: integer; var UnitInfo: TUnitInfo);
    297 var
    298   i, Cnt: integer;
     296procedure GetUnitInfo(Loc: Integer; var uix: Integer; var UnitInfo: TUnitInfo);
     297var
     298  I, Cnt: Integer;
    299299begin
    300300  if MyMap[Loc] and fOwned <> 0 then
    301301  begin
    302     Server(sGetDefender, me, Loc, uix);
     302    Server(sGetDefender, Me, Loc, uix);
    303303    Cnt := 0;
    304     for i := 0 to MyRO.nUn - 1 do
    305       if MyUn[i].Loc = Loc then
     304    for I := 0 to MyRO.nUn - 1 do
     305      if MyUn[I].Loc = Loc then
    306306        Inc(Cnt);
    307     MakeUnitInfo(me, MyUn[uix], UnitInfo);
     307    MakeUnitInfo(Me, MyUn[uix], UnitInfo);
    308308    if Cnt > 1 then
    309309      UnitInfo.Flags := UnitInfo.Flags or unMulti;
     
    316316    UnitInfo := MyRO.EnemyUn[uix];
    317317  end;
    318 end; { GetUnitInfo }
    319 
    320 procedure GetCityInfo(Loc: integer; var cix: integer; var CityInfo: TCityInfo);
     318end;
     319
     320procedure GetCityInfo(Loc: Integer; var cix: Integer; var CityInfo: TCityInfo);
    321321begin
    322322  if MyMap[Loc] and fOwned <> 0 then
     
    328328    with CityInfo do
    329329    begin
    330       Owner := me;
     330      Owner := Me;
    331331      ID := MyCity[cix].ID;
    332332      size := MyCity[cix].size;
     
    356356end;
    357357
    358 function UnitExhausted(uix: integer): boolean;
     358function UnitExhausted(uix: Integer): Boolean;
    359359  // check if another move of this unit is still possible
    360360var
    361   dx, dy: integer;
     361  dx, dy: Integer;
    362362begin
    363363  Result := True;
    364364  if (MyUn[uix].Movement > 0) or
    365     (MyRO.Wonder[woShinkansen].EffectiveOwner = me) then
     365    (MyRO.Wonder[woShinkansen].EffectiveOwner = Me) then
    366366    if (MyUn[uix].Movement >= 100) or
    367367      ((MyModel[MyUn[uix].mix].Kind = mkCaravan) and
     
    373373          if abs(dx) + abs(dy) = 2 then
    374374            if Server(sMoveUnit - sExecute + dx and 7 shl 4 + dy and
    375               7 shl 7, me, uix, nil^) >= rExecuted then
     375              7 shl 7, Me, uix, nil^) >= rExecuted then
    376376              Result := False;
    377377end;
    378378
    379 function ModelHash(const ModelInfo: TModelInfo): integer;
    380 var
    381   i, FeatureCode, Hash1, Hash2, Hash2r, d: cardinal;
     379function ModelHash(const ModelInfo: TModelInfo): Integer;
     380var
     381  I, FeatureCode, Hash1, Hash2, Hash2r, D: Cardinal;
    382382begin
    383383  with ModelInfo do
    384384    if Kind > mkEnemyDeveloped then
    385       Result := integer($C0000000 + Speed div 50 + Kind shl 8)
     385      Result := Integer($C0000000 + Speed div 50 + Kind shl 8)
    386386    else
    387387    begin
    388388      FeatureCode := 0;
    389       for i := mcFirstNonCap to nFeature - 1 do
    390         if 1 shl Domain and Feature[i].Domains <> 0 then
     389      for I := mcFirstNonCap to nFeature - 1 do
     390        if 1 shl Domain and Feature[I].Domains <> 0 then
    391391        begin
    392392          FeatureCode := FeatureCode * 2;
    393           if 1 shl (i - mcFirstNonCap) <> 0 then
     393          if 1 shl (I - mcFirstNonCap) <> 0 then
    394394            Inc(FeatureCode);
    395395        end;
     
    397397        dGround:
    398398        begin
    399           assert(FeatureCode < 1 shl 8);
    400           assert(Attack < 5113);
    401           assert(Defense < 2273);
    402           assert(Cost < 1611);
     399          Assert(FeatureCode < 1 shl 8);
     400          Assert(Attack < 5113);
     401          Assert(Defense < 2273);
     402          Assert(Cost < 1611);
    403403          Hash1 := (Attack * 2273 + Defense) * 9 + (Speed - 150) div 50;
    404404          Hash2 := FeatureCode * 1611 + Cost;
     
    406406        dSea:
    407407        begin
    408           assert(FeatureCode < 1 shl 9);
    409           assert(Attack < 12193);
    410           assert(Defense < 6097);
    411           assert(Cost < 4381);
     408          Assert(FeatureCode < 1 shl 9);
     409          Assert(Attack < 12193);
     410          Assert(Defense < 6097);
     411          Assert(Cost < 4381);
    412412          Hash1 := ((Attack * 6097 + Defense) * 5 +
    413413            (Speed - 350) div 100) * 2;
     
    419419        dAir:
    420420        begin
    421           assert(FeatureCode < 1 shl 5);
    422           assert(Attack < 2407);
    423           assert(Defense < 1605);
    424           assert(Bombs < 4813);
    425           assert(Cost < 2089);
     421          Assert(FeatureCode < 1 shl 5);
     422          Assert(Attack < 2407);
     423          Assert(Defense < 1605);
     424          Assert(Bombs < 4813);
     425          Assert(Cost < 2089);
    426426          Hash1 := (Attack * 1605 + Defense) shl 5 + FeatureCode;
    427427          Hash2 := ((Bombs * 7 + ATrans_Fuel) * 4 + TTrans) * 2089 + Cost;
     
    429429      end;
    430430      Hash2r := 0;
    431       for i := 0 to 7 do
     431      for I := 0 to 7 do
    432432      begin
    433433        Hash2r := Hash2r * 13;
    434         d := Hash2 div 13;
    435         Inc(Hash2r, Hash2 - d * 13);
    436         Hash2 := d;
     434        D := Hash2 div 13;
     435        Inc(Hash2r, Hash2 - D * 13);
     436        Hash2 := D;
    437437      end;
    438       Result := integer(Domain shl 30 + Hash1 xor Hash2r);
     438      Result := Integer(Domain shl 30 + Hash1 xor Hash2r);
    439439    end;
    440440end;
    441441
    442 function ProcessEnhancement(uix: integer; const Jobs: TEnhancementJobs): integer;
     442function ProcessEnhancement(uix: Integer; const Jobs: TEnhancementJobs): Integer;
    443443  { return values:
    444444    eJobDone - all applicable jobs done
     
    446446    eDied - job done and died (thurst) }
    447447var
    448   stage, NextJob, Tile: integer;
     448  stage, NextJob, Tile: Integer;
    449449  Done: set of jNone .. jPoll;
    450450begin
     
    452452  Tile := MyMap[MyUn[uix].Loc];
    453453  if Tile and fRoad <> 0 then
    454     include(Done, jRoad);
     454    Include(Done, jRoad);
    455455  if Tile and fRR <> 0 then
    456     include(Done, jRR);
     456    Include(Done, jRR);
    457457  if (Tile and fTerImp = tiIrrigation) or (Tile and fTerImp = tiFarm) then
    458     include(Done, jIrr);
     458    Include(Done, jIrr);
    459459  if Tile and fTerImp = tiFarm then
    460     include(Done, jFarm);
     460    Include(Done, jFarm);
    461461  if Tile and fTerImp = tiMine then
    462     include(Done, jMine);
     462    Include(Done, jMine);
    463463  if Tile and fPoll = 0 then
    464     include(Done, jPoll);
     464    Include(Done, jPoll);
    465465
    466466  if MyUn[uix].Job = jNone then
     
    485485      Break;
    486486    end; // tile enhancement complete
    487     Result := Server(sStartJob + NextJob shl 4, me, uix, nil^);
    488     include(Done, NextJob);
    489   end;
    490 end;
    491 
    492 function AutoBuild(cix: integer; const ImpOrder: TImpOrder): boolean;
    493 var
    494   i, NewProject: integer;
     487    Result := Server(sStartJob + NextJob shl 4, Me, uix, nil^);
     488    Include(Done, NextJob);
     489  end;
     490end;
     491
     492function AutoBuild(cix: Integer; const ImpOrder: TImpOrder): Boolean;
     493var
     494  I, NewProject: Integer;
    495495begin
    496496  Result := False;
     
    498498    (MyCity[cix].Flags and chProduction <> 0) then
    499499  begin
    500     i := 0;
     500    I := 0;
    501501    repeat
    502       while (ImpOrder[i] >= 0) and (MyCity[cix].Built[ImpOrder[i]] > 0) do
    503         Inc(i);
    504       if ImpOrder[i] < 0 then
     502      while (ImpOrder[I] >= 0) and (MyCity[cix].Built[ImpOrder[I]] > 0) do
     503        Inc(I);
     504      if ImpOrder[I] < 0 then
    505505        Break;
    506       assert(i < nImp);
    507       NewProject := cpImp + ImpOrder[i];
    508       if Server(sSetCityProject, me, cix, NewProject) >= rExecuted then
     506      Assert(I < nImp);
     507      NewProject := cpImp + ImpOrder[I];
     508      if Server(sSetCityProject, Me, cix, NewProject) >= rExecuted then
    509509      begin
    510510        Result := True;
     
    512512        Break;
    513513      end;
    514       Inc(i);
     514      Inc(I);
    515515    until False;
    516516  end;
     
    519519procedure CalculateAdvValues;
    520520var
    521   i, j: integer;
    522   known: array [0 .. nAdv - 1] of integer;
    523 
    524   procedure MarkPreqs(i: integer);
    525   begin
    526     if known[i] = 0 then
     521  I, J: Integer;
     522  known: array [0 .. nAdv - 1] of Integer;
     523
     524  procedure MarkPreqs(I: Integer);
     525  begin
     526    if known[I] = 0 then
    527527    begin
    528       known[i] := 1;
    529       if (i <> adScience) and (i <> adMassProduction) then
     528      known[I] := 1;
     529      if (I <> adScience) and (I <> adMassProduction) then
    530530      begin
    531         if (AdvPreq[i, 0] >= 0) then
    532           MarkPreqs(AdvPreq[i, 0]);
    533         if (AdvPreq[i, 1] >= 0) then
    534           MarkPreqs(AdvPreq[i, 1]);
     531        if (AdvPreq[I, 0] >= 0) then
     532          MarkPreqs(AdvPreq[I, 0]);
     533        if (AdvPreq[I, 1] >= 0) then
     534          MarkPreqs(AdvPreq[I, 1]);
    535535      end;
    536536    end;
     
    539539begin
    540540  FillChar(AdvValue, SizeOf(AdvValue), 0);
    541   for i := 0 to nAdv - 1 do
     541  for I := 0 to nAdv - 1 do
    542542  begin
    543543    FillChar(known, SizeOf(known), 0);
    544     MarkPreqs(i);
    545     for j := 0 to nAdv - 1 do
    546       if known[j] > 0 then
    547         Inc(AdvValue[i]);
    548     if i in FutureTech then
    549       Inc(AdvValue[i], 3000)
     544    MarkPreqs(I);
     545    for J := 0 to nAdv - 1 do
     546      if known[J] > 0 then
     547        Inc(AdvValue[I]);
     548    if I in FutureTech then
     549      Inc(AdvValue[I], 3000)
    550550    else if known[adMassProduction] > 0 then
    551       Inc(AdvValue[i], 2000)
     551      Inc(AdvValue[I], 2000)
    552552    else if known[adScience] > 0 then
    553       Inc(AdvValue[i], 1000);
    554   end;
    555 end;
    556 
    557 procedure DebugMessage(Level: integer; Text: string);
    558 begin
    559   Server(sMessage, me, Level, PChar(Text)^);
    560 end;
    561 
    562 function MarkCitiesAround(Loc, cixExcept: integer): boolean;
     553      Inc(AdvValue[I], 1000);
     554  end;
     555end;
     556
     557procedure DebugMessage(Level: Integer; Text: string);
     558begin
     559  Server(sMessage, Me, Level, PChar(Text)^);
     560end;
     561
     562function MarkCitiesAround(Loc, cixExcept: Integer): Boolean;
    563563  // return whether a city was marked
    564564var
    565   cix: integer;
     565  cix: Integer;
    566566begin
    567567  Result := False;
     
    576576end;
    577577
    578 procedure OptimizeCities(CheckOnly: boolean);
    579 var
    580   cix, fix, dx, dy, Loc1, OptiType: integer;
    581   Done: boolean;
     578procedure OptimizeCities(CheckOnly: Boolean);
     579var
     580  cix, fix, dx, dy, Loc1, OptiType: Integer;
     581  Done: Boolean;
    582582  Advice: TCityTileAdviceData;
    583583begin
     
    591591        begin
    592592          Advice.ResourceWeights := OfferedResourceWeights[OptiType];
    593           Server(sGetCityTileAdvice, me, cix, Advice);
     593          Server(sGetCityTileAdvice, Me, cix, Advice);
    594594          if Advice.Tiles <> MyCity[cix].Tiles then
    595595            if CheckOnly then
     
    611611                    Done := False;
    612612                end;
    613               Server(sSetCityTiles, me, cix, Advice.Tiles);
     613              Server(sSetCityTiles, Me, cix, Advice.Tiles);
    614614            end;
    615615        end;
     
    621621procedure CityOptimizer_BeginOfTurn;
    622622var
    623   cix: integer;
     623  cix: Integer;
    624624begin
    625625  FillChar(CityNeedsOptimize, MyRO.nCity - 1, 0); // false
     
    634634end;
    635635
    636 procedure CityOptimizer_CityChange(cix: integer);
     636procedure CityOptimizer_CityChange(cix: Integer);
    637637begin
    638638  if (MyRO.Government <> gAnarchy) and (cix <> -1) and (MyCity[cix].Flags and
     
    644644end;
    645645
    646 procedure CityOptimizer_TileBecomesAvailable(Loc: integer);
     646procedure CityOptimizer_TileBecomesAvailable(Loc: Integer);
    647647begin
    648648  if (MyRO.Government <> gAnarchy) and MarkCitiesAround(Loc, -1) then
     
    650650end;
    651651
    652 procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: integer);
    653 var
    654   fix, dx, dy, Loc1: integer;
    655   Done: boolean;
     652procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: Integer);
     653var
     654  fix, dx, dy, Loc1: Integer;
     655  Done: Boolean;
    656656begin
    657657  if (MyRO.Government <> gAnarchy) and (ReleasedTiles <> 0) then
     
    672672end;
    673673
    674 procedure CityOptimizer_BeforeRemoveUnit(uix: integer);
    675 var
    676   uix1: integer;
     674procedure CityOptimizer_BeforeRemoveUnit(uix: Integer);
     675var
     676  uix1: Integer;
    677677begin
    678678  if MyRO.Government <> gAnarchy then
     
    698698// all cities should already be optimized here -- only check this
    699699var
    700   cix: integer;
     700  cix: Integer;
    701701begin
    702702{$IFOPT O-}
  • TabularUnified branches/highdpi/LocalPlayer/Diagram.pas

    r361 r465  
    99
    1010type
     11  TDiagramKind = (dkChart, dkShip);
     12
    1113  TDiaDlg = class(TFramedDlg)
    1214    CloseBtn: TButtonB;
     
    1921    procedure ToggleBtnClick(Sender: TObject);
    2022    procedure PlayerClick(Sender: TObject);
    21     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
    22 
     23    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    2324  public
    2425    procedure OffscreenPaint; override;
    25     procedure ShowNewContent_Charts(NewMode: integer);
    26     procedure ShowNewContent_Ship(NewMode: integer; p: integer = -1);
    27 
     26    procedure ShowNewContent_Charts(NewMode: TWindowMode);
     27    procedure ShowNewContent_Ship(NewMode: TWindowMode; P: Integer = -1);
    2828  private
    29     Kind: (dkChart, dkShip);
    30     Player, Mode: integer;
    31   end;
    32 
    33 var
    34   DiaDlg: TDiaDlg;
    35 
    36 procedure PaintColonyShip(canvas: TDpiCanvas; Player, Left, Width, Top: integer);
     29    Kind: TDiagramKind;
     30    Player: Integer;
     31    Mode: Integer;
     32  end;
     33
     34procedure PaintColonyShip(Canvas: TDpiCanvas; Player, Left, Width, Top: Integer);
     35
    3736
    3837implementation
     
    4544const
    4645  Border = 24;
    47   RoundPixels: array [0 .. nStat - 1] of integer = (0, 0, 0, 5, 5, 5);
     46  RoundPixels: array [0 .. nStat - 1] of Integer = (0, 0, 0, 5, 5, 5);
    4847
    4948  yArea = 48;
    50   xComp: array [0 .. 5] of integer = (-60, -28, 4, 4, 36, 68);
    51   yComp: array [0 .. 5] of integer = (-40, -40, -79, -1, -40, -40);
    52   xPow: array [0 .. 3] of integer = (-116, -116, -116, -116);
    53   yPow: array [0 .. 3] of integer = (-28, 0, -44, 16);
    54   xHab: array [0 .. 1] of integer = (23, 23);
    55   yHab: array [0 .. 1] of integer = (-81, 1);
    56 
    57 procedure PaintColonyShip(canvas: TDpiCanvas; Player, Left, Width, Top: integer);
     49  xComp: array [0 .. 5] of Integer = (-60, -28, 4, 4, 36, 68);
     50  yComp: array [0 .. 5] of Integer = (-40, -40, -79, -1, -40, -40);
     51  xPow: array [0 .. 3] of Integer = (-116, -116, -116, -116);
     52  yPow: array [0 .. 3] of Integer = (-28, 0, -44, 16);
     53  xHab: array [0 .. 1] of Integer = (23, 23);
     54  yHab: array [0 .. 1] of Integer = (-81, 1);
     55
     56procedure PaintColonyShip(Canvas: TDpiCanvas; Player, Left, Width, Top: Integer);
    5857var
    59   i, x, r, nComp, nPow, nHab: integer;
     58  I, X, R, nComp, nPow, nHab: Integer;
    6059begin
    6160  Canvas.Brush.Color := $000000;
    6261  Canvas.FillRect(Rect(Left, Top, Left + Width, Top + 200));
    6362  Canvas.Brush.Style := bsClear;
    64     ScreenTools.Frame(canvas, Left - 1, Top - 1, Left + Width, Top + 200,
     63    ScreenTools.Frame(Canvas, Left - 1, Top - 1, Left + Width, Top + 200,
    6564      MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    66     RFrame(canvas, Left - 2, Top - 2, Left + Width + 1, Top + 200 + 1,
     65    RFrame(Canvas, Left - 2, Top - 2, Left + Width + 1, Top + 200 + 1,
    6766      MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    6867
    6968    // stars
    7069    DelphiRandSeed := Player * 11111;
    71     for i := 1 to Width - 16 do
     70    for I := 1 to Width - 16 do
    7271    begin
    73       x := DelphiRandom((Width - 16) * 200);
    74       r := DelphiRandom(13) + 28;
    75       Canvas.Pixels[x div 200 + 8, x mod 200 + Top] :=
    76         (r * r * r * r div 10001) * $10101;
     72      X := DelphiRandom((Width - 16) * 200);
     73      R := DelphiRandom(13) + 28;
     74      Canvas.Pixels[X div 200 + 8, X mod 200 + Top] :=
     75        (R * R * R * R div 10001) * $10101;
    7776    end;
    7877
     
    8685    if nHab > 2 then
    8786      nHab := 2;
    88     for i := 0 to nHab - 1 do
    89       Sprite(canvas, HGrSystem2, Left + Width div 2 + xHab[i],
    90         Top + 100 + yHab[i], 80, 80, 34, 1);
    91     for i := 0 to nComp - 1 do
    92       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[i],
    93         Top + 100 + yComp[i], 32, 80, 1, 1);
     87    for I := 0 to nHab - 1 do
     88      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xHab[I],
     89        Top + 100 + yHab[I], 80, 80, 34, 1);
     90    for I := 0 to nComp - 1 do
     91      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[I],
     92        Top + 100 + yComp[I], 32, 80, 1, 1);
    9493    if nComp > 0 then
    95       for i := 3 downto nPow do
    96         Sprite(canvas, HGrSystem2, Left + Width div 2 + xPow[i] + 40,
    97           Top + 100 + yPow[i], 16, 27, 1, 82);
    98     for i := nPow - 1 downto 0 do
    99       Sprite(canvas, HGrSystem2, Left + Width div 2 + xPow[i],
    100         Top + 100 + yPow[i], 56, 28, 58, 82);
     94      for I := 3 downto nPow do
     95        Sprite(Canvas, HGrSystem2, Left + Width div 2 + xPow[I] + 40,
     96          Top + 100 + yPow[I], 16, 27, 1, 82);
     97    for I := nPow - 1 downto 0 do
     98      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xPow[I],
     99        Top + 100 + yPow[I], 56, 28, 58, 82);
    101100    if (nComp < 3) and (nHab >= 1) then
    102       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32 - 16,
     101      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32 - 16,
    103102        Top + 100 + 7 + yComp[2], 16, 27, 1, 82);
    104103    if (nComp >= 3) and (nHab < 1) then
    105       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32,
     104      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32,
    106105        Top + 100 + 7 + yComp[2], 16, 27, 18, 82);
    107106    if (nComp < 4) and (nHab >= 2) then
    108       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32 - 16,
     107      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32 - 16,
    109108        Top + 100 + 46 + yComp[3], 16, 27, 1, 82);
    110109    if (nComp >= 4) and (nHab < 2) then
    111       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32,
     110      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32,
    112111        Top + 100 + 46 + yComp[3], 16, 27, 18, 82);
    113112    if (nComp <> 6) and (nComp <> 2) and not((nComp = 0) and (nPow < 1)) then
    114       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
     113      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
    115114        Top + 100 + 7 + yComp[nComp], 16, 27, 18, 82);
    116115    if (nComp <> 6) and (nComp <> 3) and not((nComp = 0) and (nPow < 2)) then
    117       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
     116      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
    118117        Top + 100 + 46 + yComp[nComp], 16, 27, 18, 82);
    119118    if nComp = 2 then
    120       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[3],
     119      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3],
    121120        Top + 100 + 7 + yComp[3], 16, 27, 18, 82);
    122121    if nComp = 3 then
    123       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[4],
     122      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[4],
    124123        Top + 100 + 7 + yComp[4], 16, 27, 18, 82);
    125124end;
     
    142141procedure TDiaDlg.OffscreenPaint;
    143142var
    144   p, T, max, x, y, y0, Stop, r, RoundRange, LineStep: integer;
    145   s: string;
     143  P, T, Max, X, Y, y0, Stop, R, RoundRange, LineStep: Integer;
     144  S: string;
    146145  List: ^TChart;
    147146
    148   function Round(T: integer): integer;
     147  function Round(T: Integer): Integer;
    149148  var
    150     n, i: integer;
     149    N, I: Integer;
    151150  begin
    152151    if T < RoundRange then
    153       n := T
     152      N := T
    154153    else
    155       n := RoundRange;
    156     result := 0;
    157     for i := T - n to T do
    158       inc(result, List[i]);
    159     result := result div (n + 1);
    160   end;
    161 
    162   procedure ShareBar(x, y: integer; Cap: string; val0, val1: integer);
    163   begin
    164     LoweredTextOut(offscreen.canvas, -1, MainTexture, x - 2, y, Cap);
    165     DLine(offscreen.canvas, x - 2, x + 169, y + 16, MainTexture.ColorTextShade,
     154      N := RoundRange;
     155    Result := 0;
     156    for I := T - N to T do
     157      Inc(Result, List[I]);
     158    Result := Result div (N + 1);
     159  end;
     160
     161  procedure ShareBar(X, Y: Integer; Cap: string; val0, val1: Integer);
     162  begin
     163    LoweredTextOut(Offscreen.Canvas, -1, MainTexture, X - 2, Y, Cap);
     164    DLine(Offscreen.Canvas, X - 2, X + 169, Y + 16, MainTexture.ColorTextShade,
    166165      MainTexture.ColorTextLight);
    167166    if val0 > 0 then
    168       s := Format(Phrases.Lookup('SHARE'), [val0, val1])
     167      S := Format(Phrases.Lookup('SHARE'), [val0, val1])
    169168    else
    170       s := '0';
    171     RisedTextOut(offscreen.canvas,
    172       x + 170 - BiColorTextWidth(offscreen.canvas, s), y, s);
     169      S := '0';
     170    RisedTextOut(Offscreen.Canvas,
     171      X + 170 - BiColorTextWidth(Offscreen.Canvas, S), Y, S);
    173172  end;
    174173
     
    176175  inherited;
    177176  if Kind = dkChart then
    178     with offscreen.canvas do
     177    with Offscreen.Canvas do
    179178    begin
    180179      Font.Assign(UniFont[ftTiny]);
     
    186185      GetMem(List, 4 * (MyRO.Turn + 2));
    187186      if Mode = stExplore then
    188         max := G.lx * G.ly
     187        Max := G.lx * G.ly
    189188      else
    190189      begin
    191         max := -1;
    192         for p := 0 to nPl - 1 do
    193           if (G.Difficulty[p] > 0) and
    194             (Server(sGetChart + Mode shl 4, me, p, List^) >= rExecuted) then
     190        Max := -1;
     191        for P := 0 to nPl - 1 do
     192          if (G.Difficulty[P] > 0) and
     193            (Server(sGetChart + Mode shl 4, Me, P, List^) >= rExecuted) then
    195194            for T := 0 to MyRO.Turn - 1 do
    196195            begin
    197               r := Round(T);
    198               if r > max then
    199                 max := r;
     196              R := Round(T);
     197              if R > Max then
     198                Max := R;
    200199            end;
    201200      end;
     
    215214      for T := 0 to (MyRO.Turn - 1) div LineStep do
    216215      begin
    217         x := Border + (InnerWidth - 2 * Border) * T *
     216        X := Border + (InnerWidth - 2 * Border) * T *
    218217          LineStep div (MyRO.Turn - 1);
    219         MoveTo(x, Border);
    220         LineTo(x, InnerHeight - Border);
    221         s := IntToStr(abs(TurnToYear(T * LineStep)));
    222         Textout(x - TextWidth(s) div 2, Border - 16, s);
     218        MoveTo(X, Border);
     219        LineTo(X, InnerHeight - Border);
     220        S := IntToStr(abs(TurnToYear(T * LineStep)));
     221        Textout(X - TextWidth(S) div 2, Border - 16, S);
    223222      end;
    224223
    225224      y0 := 0;
    226       if max > 0 then
     225      if Max > 0 then
    227226      begin
    228         for p := 0 to nPl - 1 do
    229           if (G.Difficulty[p] > 0) and
    230             (Server(sGetChart + Mode shl 4, me, p, List^) >= rExecuted) then
     227        for P := 0 to nPl - 1 do
     228          if (G.Difficulty[P] > 0) and
     229            (Server(sGetChart + Mode shl 4, Me, P, List^) >= rExecuted) then
    231230          begin
    232             Pen.Color := Tribe[p].Color;
     231            Pen.Color := Tribe[P].Color;
    233232            Stop := MyRO.Turn - 1;
    234233            while (Stop > 0) and (List[Stop] = 0) do
    235               dec(Stop);
     234              Dec(Stop);
    236235            for T := 0 to Stop do
    237236            begin
    238               r := Round(T);
    239               x := Border + (InnerWidth - 2 * Border) * T div (MyRO.Turn - 1);
    240               y := InnerHeight - Border - (InnerHeight - 2 * Border) *
    241                 r div max;
     237              R := Round(T);
     238              X := Border + (InnerWidth - 2 * Border) * T div (MyRO.Turn - 1);
     239              Y := InnerHeight - Border - (InnerHeight - 2 * Border) *
     240                R div Max;
    242241              if T = 0 then
    243                 MoveTo(x, y)
     242                MoveTo(X, Y)
    244243                // else if Mode=stTerritory then
    245244                // begin LineTo(x,y0); LineTo(x,y) end
    246245              else if RoundPixels[Mode] = 0 then
    247246              begin
    248                 if (y <> y0) or (T = Stop) then
    249                   LineTo(x, y)
     247                if (Y <> y0) or (T = Stop) then
     248                  LineTo(X, Y)
    250249              end
    251250              else
    252                 LineTo(x, y);
    253               y0 := y;
     251                LineTo(X, Y);
     252              y0 := Y;
    254253            end;
    255254          end;
     
    258257    end
    259258  else
    260     with offscreen.canvas do
     259    with Offscreen.Canvas do
    261260    begin
    262261      Font.Assign(UniFont[ftSmall]);
    263262      FillOffscreen(0, 0, InnerWidth, InnerHeight);
    264263
    265       PaintColonyShip(offscreen.canvas, Player, 8, InnerWidth - 16, yArea);
     264      PaintColonyShip(Offscreen.Canvas, Player, 8, InnerWidth - 16, yArea);
    266265
    267266      ShareBar(InnerWidth div 2 - 85, InnerHeight - 62,
     
    273272    end;
    274273  MarkUsedOffscreen(InnerWidth, InnerHeight);
    275 end; // OffscreenPaint
     274end;
    276275
    277276procedure TDiaDlg.FormPaint(Sender: TObject);
    278277var
    279   s: string;
     278  S: string;
    280279begin
    281280  inherited;
    282   canvas.Font.Assign(UniFont[ftNormal]);
     281  Canvas.Font.Assign(UniFont[ftNormal]);
    283282  if Kind = dkChart then
    284     s := Phrases.Lookup('DIAGRAM', Mode)
    285   else
    286     s := Tribe[Player].TPhrase('SHORTNAME');
    287   LoweredTextOut(canvas, -1, MainTexture,
    288     (ClientWidth - BiColorTextWidth(canvas, s)) div 2, 31, s);
     283    S := Phrases.Lookup('DIAGRAM', Mode)
     284  else
     285    S := Tribe[Player].TPhrase('SHORTNAME');
     286  LoweredTextOut(Canvas, -1, MainTexture,
     287    (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, 31, S);
    289288end;
    290289
     
    299298end;
    300299
    301 procedure TDiaDlg.ShowNewContent_Charts(NewMode: integer);
     300procedure TDiaDlg.ShowNewContent_Charts(NewMode: TWindowMode);
    302301begin
    303302  Kind := dkChart;
     
    309308end;
    310309
    311 procedure TDiaDlg.ShowNewContent_Ship(NewMode, p: integer);
     310procedure TDiaDlg.ShowNewContent_Ship(NewMode: TWindowMode; P: Integer);
    312311begin
    313312  Kind := dkShip;
    314   if p < 0 then
    315   begin
    316     Player := me;
     313  if P < 0 then
     314  begin
     315    Player := Me;
    317316    while MyRO.Ship[Player].Parts[spComp] + MyRO.Ship[Player].Parts[spPow] +
    318317      MyRO.Ship[Player].Parts[spHab] = 0 do
     
    320319  end
    321320  else
    322     Player := p;
     321    Player := P;
    323322  ToggleBtn.ButtonIndex := 28;
    324323  ToggleBtn.Hint := Phrases.Lookup('BTN_SELECT');
     
    329328procedure TDiaDlg.ToggleBtnClick(Sender: TObject);
    330329var
    331   p1: integer;
    332   m: TDpiMenuItem;
     330  p1: Integer;
     331  M: TDpiMenuItem;
    333332begin
    334333  if Kind = dkChart then
     
    345344        MyRO.Ship[p1].Parts[spHab] > 0 then
    346345      begin
    347         m := TDpiMenuItem.Create(Popup);
    348         m.RadioItem := true;
    349         m.Caption := Tribe[p1].TPhrase('SHORTNAME');
    350         m.Tag := p1;
    351         m.OnClick := PlayerClick;
     346        M := TDpiMenuItem.Create(Popup);
     347        M.RadioItem := True;
     348        M.Caption := Tribe[p1].TPhrase('SHORTNAME');
     349        M.Tag := p1;
     350        M.OnClick := PlayerClick;
    352351        if p1 = Player then
    353           m.Checked := true;
    354         Popup.Items.Add(m);
     352          M.Checked := True;
     353        Popup.Items.Add(M);
    355354      end;
    356355    Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height);
     
    363362end;
    364363
    365 procedure TDiaDlg.FormKeyDown(Sender: TObject; var Key: word;
     364procedure TDiaDlg.FormKeyDown(Sender: TObject; var Key: Word;
    366365  Shift: TShiftState);
    367366begin
  • TabularUnified branches/highdpi/LocalPlayer/Diplomacy.pas

    r210 r465  
    77
    88function DipCommandToString(pSender, pTarget, Treaty, OppCommand,
    9   Command: integer; const OppOffer, Offer: TOffer): string;
     9  Command: Integer; const OppOffer, Offer: TOffer): string;
    1010
    1111implementation
     
    1616function DipCommandToString;
    1717
    18   function PriceToString(p, Price: integer): string;
     18  function PriceToString(P, Price: Integer): string;
    1919  begin
    2020    case Price and opMask of
    2121      opChoose:
    22         result := Phrases.Lookup('PRICE_CHOOSE');
     22        Result := Phrases.Lookup('PRICE_CHOOSE');
    2323      opCivilReport:
    24         result := Tribe[p].TPhrase('PRICE_CIVIL');
     24        Result := Tribe[P].TPhrase('PRICE_CIVIL');
    2525      opMilReport:
    26         result := Tribe[p].TPhrase('PRICE_MIL');
     26        Result := Tribe[P].TPhrase('PRICE_MIL');
    2727      opMap:
    28         result := Tribe[p].TPhrase('PRICE_MAP');
     28        Result := Tribe[P].TPhrase('PRICE_MAP');
    2929      opTreaty:
    3030        { if Price-opTreaty<Treaty then
    3131          case Treaty of
    32           trPeace: result:=Phrases.Lookup('FRENDTREATY_PEACE');
    33           trFriendlyContact: result:=Phrases.Lookup('FRENDTREATY_FRIENDLY');
    34           trAlliance: result:=Phrases.Lookup('FRENDTREATY_ALLIANCE');
    35           end
    36           else } result := Phrases.Lookup('TREATY', Price - opTreaty);
     32          trPeace: Result:=Phrases.Lookup('FRENDTREATY_PEACE');
     33          trFriendlyContact: Result:=Phrases.Lookup('FRENDTREATY_FRIENDLY');
     34          trAlliance: Result:=Phrases.Lookup('FRENDTREATY_ALLIANCE');
     35          end
     36          else } Result := Phrases.Lookup('TREATY', Price - opTreaty);
    3737      opShipParts:
    3838        case Price shr 16 and $F of
    3939          0:
    40             result := Format(Phrases.Lookup('PRICE_SHIPCOMP'),
     40            Result := Format(Phrases.Lookup('PRICE_SHIPCOMP'),
    4141              [Price and $FFFF]);
    4242          1:
    43             result := Format(Phrases.Lookup('PRICE_SHIPPOW'),
     43            Result := Format(Phrases.Lookup('PRICE_SHIPPOW'),
    4444              [Price and $FFFF]);
    4545          2:
    46             result := Format(Phrases.Lookup('PRICE_SHIPHAB'),
     46            Result := Format(Phrases.Lookup('PRICE_SHIPHAB'),
    4747              [Price and $FFFF]);
    4848        end;
    4949      opMoney:
    50         result := Format('%d%%c', [Price - opMoney]);
     50        Result := Format('%d%%c', [Price - opMoney]);
    5151      opTribute:
    52         result := Format(Phrases.Lookup('PRICE_TRIBUTE'), [Price - opTribute]);
     52        Result := Format(Phrases.Lookup('PRICE_TRIBUTE'), [Price - opTribute]);
    5353      opTech:
    54         result := Phrases.Lookup('ADVANCES', Price - opTech);
     54        Result := Phrases.Lookup('ADVANCES', Price - opTech);
    5555      opAllTech:
    56         result := Tribe[p].TPhrase('PRICE_ALLTECH');
     56        Result := Tribe[P].TPhrase('PRICE_ALLTECH');
    5757      opModel:
    58         result := Tribe[p].ModelName[Price - opModel];
     58        Result := Tribe[P].ModelName[Price - opModel];
    5959      opAllModel:
    60         result := Tribe[p].TPhrase('PRICE_ALLMODEL');
     60        Result := Tribe[P].TPhrase('PRICE_ALLMODEL');
    6161      { opCity:
    62         result:=Format(TPhrase('PRICE_CITY',p),[CityName(Price-opCity)]); }
     62        Result:=Format(TPhrase('PRICE_CITY',P),[CityName(Price-opCity)]); }
    6363    end
    6464  end;
    6565
    6666var
    67   i: integer;
     67  I: Integer;
    6868  sAdd, sDeliver, sCost: string;
    69   DoIntro: boolean;
     69  DoIntro: Boolean;
    7070begin
    7171  DoIntro := OppCommand = scDipStart;
     
    7575        case Treaty of
    7676          trPeace:
    77             result := Phrases.Lookup('FRCANCELTREATY_PEACE');
     77            Result := Phrases.Lookup('FRCANCELTREATY_PEACE');
    7878          trFriendlyContact:
    79             result := Phrases.Lookup('FRCANCELTREATY_FRIENDLY');
     79            Result := Phrases.Lookup('FRCANCELTREATY_FRIENDLY');
    8080          trAlliance:
    81             result := Phrases.Lookup('FRCANCELTREATY_ALLIANCE');
    82         end;
    83         DoIntro := false;
     81            Result := Phrases.Lookup('FRCANCELTREATY_ALLIANCE');
     82        end;
     83        DoIntro := False;
    8484      end;
    8585    scDipNotice:
    86       result := Phrases.Lookup('FRNOTICE');
     86      Result := Phrases.Lookup('FRNOTICE');
    8787    scDipAccept:
    8888      begin
    8989        if (OppOffer.nDeliver + OppOffer.nCost = 1) and
    9090          (OppOffer.Price[0] and opMask = opTreaty) and
    91           (integer(OppOffer.Price[0] - opTreaty) > Treaty) then
     91          (Integer(OppOffer.Price[0] - opTreaty) > Treaty) then
    9292        // simple treaty offer
    9393          { if OppOffer.Price[0]-opTreaty=trCeaseFire then
    94             result:=Tribe[pTarget].TPhrase('FRACCEPTCEASEFIRE')
    95             else } result := Tribe[pTarget].TPhrase('FRACCEPTTREATY')
     94            Result:=Tribe[pTarget].TPhrase('FRACCEPTCEASEFIRE')
     95            else } Result := Tribe[pTarget].TPhrase('FRACCEPTTREATY')
    9696        else if OppOffer.nDeliver = 0 then
    97           result := Tribe[pSender].TPhrase('FRACCEPTDEMAND_STRONG')
     97          Result := Tribe[pSender].TPhrase('FRACCEPTDEMAND_STRONG')
    9898        else if OppOffer.nCost = 0 then
    99           result := Tribe[pSender].TPhrase('FRACCEPTPRESENT')
     99          Result := Tribe[pSender].TPhrase('FRACCEPTPRESENT')
    100100        else
    101           result := Tribe[pSender].TPhrase('FRACCEPTOFFER');
     101          Result := Tribe[pSender].TPhrase('FRACCEPTOFFER');
    102102      end;
    103103    scDipBreak:
    104104      begin
    105         result := Tribe[pTarget].TPhrase('FRBREAK');
    106         DoIntro := false;
     105        Result := Tribe[pTarget].TPhrase('FRBREAK');
     106        DoIntro := False;
    107107      end;
    108108    scDipOffer:
    109109      begin
    110         result := '';
     110        Result := '';
    111111        if (OppCommand = scDipOffer) and
    112112          ((OppOffer.nDeliver > 0) or (OppOffer.nCost > 0)) and
     
    115115          if (OppOffer.nDeliver + OppOffer.nCost = 1) and
    116116            (OppOffer.Price[0] and opMask = opTreaty) and
    117             (integer(OppOffer.Price[0] - opTreaty) > Treaty) then
     117            (Integer(OppOffer.Price[0] - opTreaty) > Treaty) then
    118118          // simple treaty offer
    119             result := Tribe[pSender].TPhrase('FRNOTACCEPTTREATY') + '\'
     119            Result := Tribe[pSender].TPhrase('FRNOTACCEPTTREATY') + '\'
    120120          else if OppOffer.nDeliver = 0 then
    121             result := Tribe[pSender].TPhrase('FRNOTACCEPTDEMAND_STRONG') + '\'
     121            Result := Tribe[pSender].TPhrase('FRNOTACCEPTDEMAND_STRONG') + '\'
    122122          else if OppOffer.nCost = 0 then
    123             result := Tribe[pSender].TPhrase('FRNOTACCEPTPRESENT') + '\';
     123            Result := Tribe[pSender].TPhrase('FRNOTACCEPTPRESENT') + '\';
    124124        end;
    125125
    126126        sDeliver := '';
    127         for i := 0 to Offer.nDeliver - 1 do
    128         begin
    129           sAdd := PriceToString(pSender, Offer.Price[i]);
    130           if i = 0 then
     127        for I := 0 to Offer.nDeliver - 1 do
     128        begin
     129          sAdd := PriceToString(pSender, Offer.Price[I]);
     130          if I = 0 then
    131131            sDeliver := sAdd
    132132          else
     
    134134        end;
    135135        sCost := '';
    136         for i := 0 to Offer.nCost - 1 do
    137         begin
    138           sAdd := PriceToString(pTarget, Offer.Price[Offer.nDeliver + i]);
    139           if i = 0 then
     136        for I := 0 to Offer.nCost - 1 do
     137        begin
     138          sAdd := PriceToString(pTarget, Offer.Price[Offer.nDeliver + I]);
     139          if I = 0 then
    140140            sCost := sAdd
    141141          else
     
    147147          if (OppCommand = scDipOffer) and
    148148            ((OppOffer.nDeliver = 0) and (OppOffer.nCost = 0)) then
    149             result := Tribe[pTarget].TPhrase('FRBYE')
     149            Result := Tribe[pTarget].TPhrase('FRBYE')
    150150          else
    151151          begin
    152             if (result = '') and (OppCommand = scDipOffer) and
     152            if (Result = '') and (OppCommand = scDipOffer) and
    153153              ((OppOffer.nDeliver > 0) or (OppOffer.nCost > 0)) then
    154154            begin
    155155              if (OppOffer.nDeliver = 1) and (OppOffer.Price[0] = opChoose) and
    156156                not Phrases2FallenBackToEnglish then
    157                 result := Tribe[pSender].TString
     157                Result := Tribe[pSender].TString
    158158                  (Phrases2.Lookup('FRNOTACCEPTANYOFFER')) + ' '
    159159              else if (OppOffer.nCost = 1) and
    160160                (OppOffer.Price[OppOffer.nDeliver] = opChoose) and not Phrases2FallenBackToEnglish
    161161              then
    162                 result := Tribe[pSender].TString
     162                Result := Tribe[pSender].TString
    163163                  (Phrases2.Lookup('FRNOTACCEPTANYWANT')) + ' '
    164164              else
    165                 result := Tribe[pSender].TPhrase('FRNOTACCEPTOFFER') + ' ';
     165                Result := Tribe[pSender].TPhrase('FRNOTACCEPTOFFER') + ' ';
    166166            end;
    167             result := result + Phrases.Lookup('FRDONE');
    168             DoIntro := false
     167            Result := Result + Phrases.Lookup('FRDONE');
     168            DoIntro := False
    169169          end
    170170        end
    171171        else if (Offer.nDeliver + Offer.nCost = 1) and
    172172          (Offer.Price[0] and opMask = opTreaty) and
    173           (integer(Offer.Price[0] - opTreaty) > Treaty) then
     173          (Integer(Offer.Price[0] - opTreaty) > Treaty) then
    174174        // simple treaty offer
    175175        begin
     
    177177            // trCeaseFire: result:=result+Tribe[pTarget].TPhrase('FRCEASEFIRE');
    178178            trPeace:
    179               result := result + Tribe[pTarget].TPhrase('FRPEACE');
     179              Result := Result + Tribe[pTarget].TPhrase('FRPEACE');
    180180            trFriendlyContact:
    181               result := result + Tribe[pTarget].TPhrase('FRFRIENDLY');
     181              Result := Result + Tribe[pTarget].TPhrase('FRFRIENDLY');
    182182            trAlliance:
    183               result := result + Tribe[pTarget].TPhrase('FRALLIANCE');
     183              Result := Result + Tribe[pTarget].TPhrase('FRALLIANCE');
    184184          end
    185185        end
     
    188188          if (Treaty >= trFriendlyContact) and not Phrases2FallenBackToEnglish
    189189          then
    190             result := result +
     190            Result := Result +
    191191              Format(Tribe[pTarget].TString(Phrases2.Lookup('FRDEMAND_SOFT')
    192192              ), [sCost])
    193193          else
    194194          begin
    195             result := result +
     195            Result := Result +
    196196              Format(Tribe[pTarget].TPhrase('FRDEMAND_STRONG'), [sCost]);
    197             DoIntro := false
     197            DoIntro := False
    198198          end
    199199        end
    200200        else if Offer.nCost = 0 then // present
    201           result := result + Format(Tribe[pTarget].TPhrase('FRPRESENT'),
     201          Result := Result + Format(Tribe[pTarget].TPhrase('FRPRESENT'),
    202202            [sDeliver])
    203203        else if (Offer.nDeliver = 1) and (Offer.Price[0] = opChoose) then
    204           result := result + Format(Phrases.Lookup('FRDELCHOICE'), [sCost])
     204          Result := Result + Format(Phrases.Lookup('FRDELCHOICE'), [sCost])
    205205        else if (Offer.nCost = 1) and (Offer.Price[Offer.nDeliver] = opChoose)
    206206        then
    207           result := result + Format(Phrases.Lookup('FRCOSTCHOICE'), [sDeliver])
     207          Result := Result + Format(Phrases.Lookup('FRCOSTCHOICE'), [sDeliver])
    208208        else
    209           result := result + Format(Phrases.Lookup('FROFFER'),
     209          Result := Result + Format(Phrases.Lookup('FROFFER'),
    210210            [sDeliver, sCost]);
    211211      end;
     
    213213  if DoIntro then
    214214    if Treaty < trPeace then
    215       result := Tribe[pSender].TPhrase('FRSTART_NOTREATY') + ' ' + result
     215      Result := Tribe[pSender].TPhrase('FRSTART_NOTREATY') + ' ' + Result
    216216    else
    217       result := Tribe[pSender].TPhrase('FRSTART_PEACE') + ' ' + result
     217      Result := Tribe[pSender].TPhrase('FRSTART_PEACE') + ' ' + Result
    218218end;
    219219
  • TabularUnified branches/highdpi/LocalPlayer/Draft.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin,
    8 
    9   LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,
    10   ButtonA,
    11   ButtonB, Area;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, Controls, Forms, ExtCtrls, ButtonA, ButtonB, Area;
    129
    1310type
     
    2320    procedure CloseBtnClick(Sender: TObject);
    2421    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    25       Shift: TShiftState; x, y: integer);
     22      Shift: TShiftState; X, Y: Integer);
    2623    procedure OKBtnClick(Sender: TObject);
    2724    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    28       Shift: TShiftState; x, y: integer);
     25      Shift: TShiftState; X, Y: Integer);
    2926  public
    30     procedure ShowNewContent(NewMode: integer);
     27    procedure ShowNewContent(NewMode: TWindowMode);
    3128  protected
    3229    procedure OffscreenPaint; override;
    3330  private
    3431    Domain, MaxLines, Lines, Cut, yDomain, yFeature, yWeight, yTotal, yView,
    35       IncCap, DecCap: integer;
    36     code: array [0 .. nFeature - 1] of integer;
     32      IncCap, DecCap: Integer;
     33    Code: array [0 .. nFeature - 1] of Integer;
    3734    Template, Back: TDpiBitmap;
    38     function IsFeatureInList(d, i: integer): boolean;
    39     procedure SetDomain(d: integer);
    40   end;
    41 
    42 var
    43   DraftDlg: TDraftDlg;
     35    function IsFeatureInList(D, I: Integer): Boolean;
     36    procedure SetDomain(D: Integer);
     37  end;
     38
    4439
    4540implementation
    4641
    47 uses Help, Tribes, Directories;
     42uses
     43  Term, Help, Tribes, Directories;
    4844
    4945{$R *.lfm}
     
    109105procedure TDraftDlg.OffscreenPaint;
    110106
    111   function DomainAvailable(d: integer): boolean;
    112   begin
    113     result := (upgrade[d, 0].Preq = preNone) or
    114       (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable);
     107  function DomainAvailable(D: Integer): Boolean;
     108  begin
     109    Result := (upgrade[D, 0].Preq = preNone) or
     110      (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable);
    115111  end;
    116112
    117113  procedure PaintTotalBars;
    118114  var
    119     i, y, dx, num, w: integer;
    120     s: string;
    121   begin
    122     with offscreen.Canvas do
     115    I, Y, dx, num, W: Integer;
     116    S: string;
     117  begin
     118    with Offscreen.Canvas do
    123119    begin
    124120      // strength bar
    125       y := yTotal;
    126       DarkGradient(offscreen.Canvas, xTotal - 6, y + 1, 184, 2);
    127       DarkGradient(offscreen.Canvas, xTotal2 + 172, y + 1, 95, 2);
    128       RisedTextOut(offscreen.Canvas, xTotal - 2, y,
     121      Y := yTotal;
     122      DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 2);
     123      DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 2);
     124      RisedTextOut(Offscreen.Canvas, xTotal - 2, Y,
    129125        Phrases.Lookup('UNITSTRENGTH'));
    130       RisedTextOut(offscreen.Canvas, xTotal + 112 + 30, y,
     126      RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y,
    131127        'x' + IntToStr(MyRO.DevModel.MStrength));
    132       RisedTextOut(offscreen.Canvas, xTotal2 + 148 + 30, y, '=');
    133       s := IntToStr(MyRO.DevModel.Attack) + '/' +
     128      RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '=');
     129      S := IntToStr(MyRO.DevModel.Attack) + '/' +
    134130        IntToStr(MyRO.DevModel.Defense);
    135       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
    136         BiColorTextWidth(offscreen.Canvas, s), y, s);
     131      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
     132        BiColorTextWidth(Offscreen.Canvas, S), Y, S);
    137133
    138134      // transport bar
    139135      if MyRO.DevModel.MTrans > 0 then
    140136      begin
    141         y := yTotal + 19;
    142         DarkGradient(offscreen.Canvas, xTotal - 6, y + 1, 184, 1);
    143         DarkGradient(offscreen.Canvas, xTotal2 + 172, y + 1, 95, 1);
    144         RisedTextOut(offscreen.Canvas, xTotal - 2, y,
     137        Y := yTotal + 19;
     138        DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 1);
     139        DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 1);
     140        RisedTextOut(Offscreen.Canvas, xTotal - 2, Y,
    145141          Phrases.Lookup('UNITTRANSPORT'));
    146         RisedTextOut(offscreen.Canvas, xTotal + 112 + 30, y,
     142        RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y,
    147143          'x' + IntToStr(MyRO.DevModel.MTrans));
    148         RisedTextOut(offscreen.Canvas, xTotal2 + 148 + 30, y, '=');
     144        RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '=');
    149145
    150146        Font.Color := $000000;
    151147        dx := -237 - 30;
    152         for i := mcFirstNonCap - 1 downto 3 do
    153           if i in [mcSeaTrans, mcCarrier, mcAirTrans] then
     148        for I := mcFirstNonCap - 1 downto 3 do
     149          if I in [mcSeaTrans, mcCarrier, mcAirTrans] then
    154150          begin
    155             num := MyRO.DevModel.Cap[i] * MyRO.DevModel.MTrans;
     151            num := MyRO.DevModel.Cap[I] * MyRO.DevModel.MTrans;
    156152            if num > 0 then
    157153            begin
    158               inc(dx, 15);
     154              Inc(dx, 15);
    159155              Brush.Color := $C0C0C0;
    160               FrameRect(Rect(xTotal2 - 3 - dx, y + 2,
    161                 xTotal2 + 11 - dx, y + 16));
     156              FrameRect(Rect(xTotal2 - 3 - dx, Y + 2,
     157                xTotal2 + 11 - dx, Y + 16));
    162158              Brush.Style := bsClear;
    163               Sprite(offscreen, HGrSystem, xTotal2 - 1 - dx, y + 4, 10, 10,
    164                 66 + i mod 11 * 11, 137 + i div 11 * 11);
     159              Sprite(Offscreen, HGrSystem, xTotal2 - 1 - dx, Y + 4, 10, 10,
     160                66 + I mod 11 * 11, 137 + I div 11 * 11);
    165161              if num > 1 then
    166162              begin
    167                 s := IntToStr(num);
    168                 w := TextWidth(s);
    169                 inc(dx, w + 1);
     163                S := IntToStr(num);
     164                W := TextWidth(S);
     165                Inc(dx, W + 1);
    170166                Brush.Color := $FFFFFF;
    171                 FillRect(Rect(xTotal2 - 3 - dx, y + 2,
    172                   xTotal2 + w - 1 - dx, y + 16));
     167                FillRect(Rect(xTotal2 - 3 - dx, Y + 2,
     168                  xTotal2 + W - 1 - dx, Y + 16));
    173169                Brush.Style := bsClear;
    174                 Textout(xTotal2 - 3 - dx + 1, y, s);
     170                Textout(xTotal2 - 3 - dx + 1, Y, S);
    175171              end;
    176172            end;
    177           end
     173          end;
    178174      end;
    179175
    180176      // speed bar
    181       y := yTotal + 38;
    182       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
     177      Y := yTotal + 38;
     178      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
    183179        Phrases.Lookup('UNITSPEED'));
    184       DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     180      DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    185181        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    186       DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     182      DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    187183        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    188       s := MovementToString(MyRO.DevModel.Speed);
    189       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
    190         TextWidth(s), y, s);
     184      S := MovementToString(MyRO.DevModel.Speed);
     185      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
     186        TextWidth(S), Y, S);
    191187
    192188      // cost bar
    193       y := yTotal + 57;
    194       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
     189      Y := yTotal + 57;
     190      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
    195191        Phrases.Lookup('UNITCOST'));
    196       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, y,
     192      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, Y,
    197193        'x' + IntToStr(MyRO.DevModel.MCost));
    198       LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    199         xTotal2 + 148 + 30, y, '=');
    200       DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     194      LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     195        xTotal2 + 148 + 30, Y, '=');
     196      DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    201197        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    202       DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     198      DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    203199        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    204       s := IntToStr(MyRO.DevModel.Cost);
    205       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
    206         TextWidth(s), y, s);
    207       Sprite(offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10,
     200      S := IntToStr(MyRO.DevModel.Cost);
     201      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
     202        TextWidth(S), Y, S);
     203      Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10,
    208204        10, 88, 115);
    209205
    210       if G.Difficulty[me] <> 2 then
     206      if G.Difficulty[Me] <> 2 then
    211207      begin // corrected cost bar
    212         y := yTotal + 76;
    213         LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
    214           Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[me])));
    215         LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    216           xTotal2 + 148 + 30, y, '=');
    217         DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     208        Y := yTotal + 76;
     209        LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
     210          Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[Me])));
     211        LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     212          xTotal2 + 148 + 30, Y, '=');
     213        DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    218214          MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    219         DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     215        DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    220216          MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    221         s := IntToStr(MyRO.DevModel.Cost * BuildCostMod
    222           [G.Difficulty[me]] div 12);
    223         RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
    224           TextWidth(s), y, s);
    225         Sprite(offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10,
     217        S := IntToStr(MyRO.DevModel.Cost * BuildCostMod
     218          [G.Difficulty[Me]] div 12);
     219        RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
     220          TextWidth(S), Y, S);
     221        Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10,
    226222          10, 88, 115);
    227223      end;
     
    230226
    231227var
    232   i, j, x, d, n, TextColor, CapWeight, DomainCount: integer;
     228  I, J, X, D, N, TextColor, CapWeight, DomainCount: Integer;
    233229begin
    234230  inherited;
     
    239235  // assemble background from 2 texture tiles
    240236  begin
    241     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, 64,
     237    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, 64,
    242238      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    243239      MainTexture.Height - 64);
    244     DpiBitCanvas(Back.Canvas, 0, 64, ClientWidth, ClientHeight - 64,
     240    DpiBitBltCanvas(Back.Canvas, 0, 64, ClientWidth, ClientHeight - 64,
    245241      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    246242      0);
    247243  end
    248244  else
    249     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
     245    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
    250246      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    251247      (MainTexture.Height - ClientHeight) div 2);
     
    254250    Template.Height - 64 - Cut);
    255251
    256   DpiBitCanvas(offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
     252  DpiBitBltCanvas(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
    257253    Back.Canvas, 0, 0);
    258254
    259   offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    260   RisedTextOut(offscreen.Canvas, 10, 7, Caption);
    261   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     255  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
     256  RisedTextOut(Offscreen.Canvas, 10, 7, Caption);
     257  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    262258
    263259  with MyRO.DevModel do
    264260  begin
    265261    DomainCount := 0;
    266     for d := 0 to nDomains - 1 do
    267       if DomainAvailable(d) then
    268         inc(DomainCount);
     262    for D := 0 to nDomains - 1 do
     263      if DomainAvailable(D) then
     264        Inc(DomainCount);
    269265    if DomainCount > 1 then
    270266    begin
    271       for d := 0 to nDomains - 1 do
    272         if DomainAvailable(d) then
     267      for D := 0 to nDomains - 1 do
     268        if DomainAvailable(D) then
    273269        begin
    274           x := xDomain + d * DomainPitch;
    275           if d = Domain then
    276             ImageOp_BCC(offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,
     270          X := xDomain + D * DomainPitch;
     271          if D = Domain then
     272            ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36,
    277273              36, 0, $00C0FF)
    278274          else
    279             ImageOp_BCC(offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,
     275            ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36,
    280276              36, 0, $606060);
    281277        end;
    282       Frame(offscreen.Canvas, xDomain - 11, yDomain - 3,
     278      Frame(Offscreen.Canvas, xDomain - 11, yDomain - 3,
    283279        xDomain + 2 * DomainPitch + 46, yDomain + 38, $B0B0B0, $FFFFFF);
    284       RFrame(offscreen.Canvas, xDomain - 12, yDomain - 4,
     280      RFrame(Offscreen.Canvas, xDomain - 12, yDomain - 4,
    285281        xDomain + 2 * DomainPitch + 47, yDomain + 39, $FFFFFF, $B0B0B0);
    286282    end;
     
    295291
    296292    // display weight
    297     with offscreen.Canvas do
    298     begin
    299       for i := 0 to MaxWeight - 1 do
    300         if i < Weight then
    301           ImageOp_BCC(offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),
     293    with Offscreen.Canvas do
     294    begin
     295      for I := 0 to MaxWeight - 1 do
     296        if I < Weight then
     297          ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight),
    302298            WeightOn.BoundsRect, 0, $949494)
    303299        else
    304           ImageOp_BCC(offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),
     300          ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight),
    305301            WeightOff.BoundsRect, 0, $949494);
    306302    end;
    307303
    308     with offscreen.Canvas do
    309       for i := 0 to Lines - 1 do
     304    with Offscreen.Canvas do
     305      for I := 0 to Lines - 1 do
    310306      begin
    311         if not(code[i] in AutoFeature) then
     307        if not(Code[I] in AutoFeature) then
    312308        begin
    313309          // paint +/- butttons
    314           if code[i] < mcFirstNonCap then
     310          if Code[I] < mcFirstNonCap then
    315311          begin
    316             Dump(offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
    317               i, 12, 12, 169, 172);
    318             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    319               i, 12, 12, 169, 159);
    320             RFrame(offscreen.Canvas, xFeature - (21 + 1),
    321               yFeature + 2 + LinePitch * i - 1, xFeature - (21 - 24),
    322               yFeature + 2 + LinePitch * i + 12, MainTexture.ColorBevelShade,
     312            Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
     313              I, 12, 12, 169, 172);
     314            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     315              I, 12, 12, 169, 159);
     316            RFrame(Offscreen.Canvas, xFeature - (21 + 1),
     317              yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24),
     318              yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade,
    323319              MainTexture.ColorBevelLight);
    324320          end
    325321          else
    326322          begin
    327             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    328               i, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[code[i]]);
    329             RFrame(offscreen.Canvas, xFeature - (9 + 1),
    330               yFeature + 2 + LinePitch * i - 1, xFeature - (21 - 24),
    331               yFeature + 2 + LinePitch * i + 12, MainTexture.ColorBevelShade,
     323            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     324              I, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[Code[I]]);
     325            RFrame(Offscreen.Canvas, xFeature - (9 + 1),
     326              yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24),
     327              yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade,
    332328              MainTexture.ColorBevelLight);
    333329          end;
    334330
    335331          // paint cost
    336           LightGradient(offscreen.Canvas, xFeature + 34,
    337             yFeature + LinePitch * i, 50, HGrSystem.Data.Canvas.Pixels
     332          LightGradient(Offscreen.Canvas, xFeature + 34,
     333            yFeature + LinePitch * I, 50, HGrSystem.Data.Canvas.Pixels
    338334            [187, 137]);
    339           if (Domain = dGround) and (code[i] = mcDefense) then
     335          if (Domain = dGround) and (Code[I] = mcDefense) then
    340336            CapWeight := 2
    341337          else
    342             CapWeight := Feature[code[i]].Weight;
    343           n := CapWeight + Feature[code[i]].Cost;
    344           d := 6;
    345           while (n - 1) * d * 2 > 48 - 10 do
    346             dec(d);
    347           for j := 0 to n - 1 do
    348             if j < CapWeight then
    349               Sprite(offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,
    350                 yFeature + 2 + LinePitch * i + 1, 10, 10, 88, 126)
     338            CapWeight := Feature[Code[I]].Weight;
     339          N := CapWeight + Feature[Code[I]].Cost;
     340          D := 6;
     341          while (N - 1) * D * 2 > 48 - 10 do
     342            Dec(D);
     343          for J := 0 to N - 1 do
     344            if J < CapWeight then
     345              Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D,
     346                yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 126)
    351347            else
    352               Sprite(offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,
    353                 yFeature + 2 + LinePitch * i + 1, 10, 10, 88, 115);
     348              Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D,
     349                yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 115);
    354350        end; // if not (code[i] in AutoFeature)
    355         DarkGradient(offscreen.Canvas, xFeature + 17,
    356           yFeature + LinePitch * i, 16, 1);
    357         ScreenTools.Frame(offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * i,
    358           xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * i,
     351        DarkGradient(Offscreen.Canvas, xFeature + 17,
     352          yFeature + LinePitch * I, 16, 1);
     353        ScreenTools.Frame(Offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * I,
     354          xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * I,
    359355          $C0C0C0, $C0C0C0);
    360         Sprite(offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch
    361           * i, 10, 10, 66 + code[i] mod 11 * 11, 137 + code[i] div 11 * 11);
    362 
    363         if MyRO.DevModel.Cap[code[i]] > 0 then
     356        Sprite(Offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch
     357          * I, 10, 10, 66 + Code[I] mod 11 * 11, 137 + Code[I] div 11 * 11);
     358
     359        if MyRO.DevModel.Cap[Code[I]] > 0 then
    364360          TextColor := MainTexture.ColorLitText
    365361        else
    366362          TextColor := -1;
    367363
    368         if code[i] < mcFirstNonCap then
    369           LoweredTextOut(offscreen.Canvas, TextColor, MainTexture, xFeature + 7,
    370             yFeature + LinePitch * i - 1, IntToStr(MyRO.DevModel.Cap[code[i]]));
    371         LoweredTextOut(offscreen.Canvas, TextColor, MainTexture, xFeature + 88,
    372           yFeature + LinePitch * i - 1, Phrases.Lookup('FEATURES', code[i]));
     364        if Code[I] < mcFirstNonCap then
     365          LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 7,
     366            yFeature + LinePitch * I - 1, IntToStr(MyRO.DevModel.Cap[Code[I]]));
     367        LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 88,
     368          yFeature + LinePitch * I - 1, Phrases.Lookup('FEATURES', Code[I]));
    373369      end;
    374370  end;
    375371
    376372  // free features
    377   j := 0;
    378   for i := 0 to nFeature - 1 do
    379     if (i in AutoFeature) and (1 shl Domain and Feature[i].Domains <> 0) and
    380       (Feature[i].Preq <> preNA) and
    381       ((Feature[i].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = me)
    382       or (Feature[i].Preq >= 0) and (MyRO.Tech[Feature[i].Preq] >= tsApplicable)
    383       ) and not((Feature[i].Preq = adSteamEngine) and
     373  J := 0;
     374  for I := 0 to nFeature - 1 do
     375    if (I in AutoFeature) and (1 shl Domain and Feature[I].Domains <> 0) and
     376      (Feature[I].Preq <> preNA) and
     377      ((Feature[I].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = Me)
     378      or (Feature[I].Preq >= 0) and (MyRO.Tech[Feature[I].Preq] >= tsApplicable)
     379      ) and not((Feature[I].Preq = adSteamEngine) and
    384380      (MyRO.Tech[adNuclearPower] >= tsApplicable)) then
    385381    begin
    386       DarkGradient(offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch
    387         * j, 16, 1);
    388       Frame(offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * j,
    389         xWeight + 18, yWeight + 47 + LinePitch * j, $C0C0C0, $C0C0C0);
    390       Sprite(offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * j,
    391         10, 10, 66 + i mod 11 * 11, 137 + i div 11 * 11);
    392       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xWeight + 26,
    393         yWeight + 31 + LinePitch * j, Phrases.Lookup('FEATURES', i));
    394       inc(j);
    395     end;
    396 
    397   with Tribe[me].ModelPicture[MyRO.nModel] do
    398   begin
    399     FrameImage(offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,
     382      DarkGradient(Offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch
     383        * J, 16, 1);
     384      Frame(Offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * J,
     385        xWeight + 18, yWeight + 47 + LinePitch * J, $C0C0C0, $C0C0C0);
     386      Sprite(Offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * J,
     387        10, 10, 66 + I mod 11 * 11, 137 + I div 11 * 11);
     388      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xWeight + 26,
     389        yWeight + 31 + LinePitch * J, Phrases.Lookup('FEATURES', I));
     390      Inc(J);
     391    end;
     392
     393  with Tribe[Me].ModelPicture[MyRO.nModel] do
     394  begin
     395    FrameImage(Offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,
    400396      ySizeBig, 0, 0);
    401     Sprite(offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,
     397    Sprite(Offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,
    402398      pix div 10 * 49 + 1);
    403399  end;
    404400  MarkUsedOffscreen(ClientWidth, ClientHeight);
    405 end; { MainPaint }
    406 
    407 procedure TDraftDlg.SetDomain(d: integer);
    408 
    409   function Prio(fix: integer): integer;
     401end;
     402
     403procedure TDraftDlg.SetDomain(D: Integer);
     404
     405  function Prio(fix: Integer): Integer;
    410406  var
    411     FeaturePreq: integer;
     407    FeaturePreq: Integer;
    412408  begin
    413409    FeaturePreq := Feature[fix].Preq;
    414     assert(FeaturePreq <> preNA);
     410    Assert(FeaturePreq <> preNA);
    415411    if fix < mcFirstNonCap then
    416       result := 10000 + fix
     412      Result := 10000 + fix
    417413    else if FeaturePreq = preNone then
    418       result := 20000
     414      Result := 20000
    419415    else if FeaturePreq < 0 then
    420       result := 40000
     416      Result := 40000
    421417    else
    422       result := 30000 + AdvValue[FeaturePreq];
     418      Result := 30000 + AdvValue[FeaturePreq];
    423419    if not(fix in AutoFeature) then
    424       inc(result, 90000);
     420      Inc(Result, 90000);
    425421  end;
    426422
    427423var
    428   i, j, x: integer;
    429 begin
    430   Domain := d;
     424  I, J, X: Integer;
     425begin
     426  Domain := D;
    431427  Lines := 0;
    432   for i := 0 to nFeature - 1 do
    433     if IsFeatureInList(Domain, i) then
    434     begin
    435       code[Lines] := i;
    436       inc(Lines)
     428  for I := 0 to nFeature - 1 do
     429    if IsFeatureInList(Domain, I) then
     430    begin
     431      Code[Lines] := I;
     432      Inc(Lines);
    437433    end;
    438434  yFeature := yFeature0 + (MaxLines - Lines) * LinePitch div 2;
    439435
    440436  // sort features
    441   for i := 0 to Lines - 2 do
    442     for j := i + 1 to Lines - 1 do
    443       if Prio(code[i]) > Prio(code[j]) then
     437  for I := 0 to Lines - 2 do
     438    for J := I + 1 to Lines - 1 do
     439      if Prio(Code[I]) > Prio(Code[J]) then
    444440      begin // exchange
    445         x := code[i];
    446         code[i] := code[j];
    447         code[j] := x
     441        X := Code[I];
     442        Code[I] := Code[J];
     443        Code[J] := X;
    448444      end;
    449445end;
    450446
    451 function TDraftDlg.IsFeatureInList(d, i: integer): boolean;
    452 begin
    453   result := not(i in AutoFeature) and (1 shl d and Feature[i].Domains <> 0) and
    454     (Feature[i].Preq <> preNA) and
    455     ((Feature[i].Preq = preNone) or (Feature[i].Preq = preSun) and
    456     (MyRO.Wonder[woSun].EffectiveOwner = me) or (Feature[i].Preq >= 0) and
    457     (MyRO.Tech[Feature[i].Preq] >= tsApplicable));
     447function TDraftDlg.IsFeatureInList(D, I: Integer): Boolean;
     448begin
     449  Result := not(I in AutoFeature) and (1 shl D and Feature[I].Domains <> 0) and
     450    (Feature[I].Preq <> preNA) and
     451    ((Feature[I].Preq = preNone) or (Feature[I].Preq = preSun) and
     452    (MyRO.Wonder[woSun].EffectiveOwner = Me) or (Feature[I].Preq >= 0) and
     453    (MyRO.Tech[Feature[I].Preq] >= tsApplicable));
    458454end;
    459455
    460456procedure TDraftDlg.FormShow(Sender: TObject);
    461457var
    462   count, d, i: integer;
     458  count, D, I: Integer;
    463459begin
    464460  Domain := dGround;
    465461  while (Domain < dAir) and (upgrade[Domain, 0].Preq <> preNone) and
    466462    (MyRO.Tech[upgrade[Domain, 0].Preq] < tsApplicable) do
    467     inc(Domain);
     463    Inc(Domain);
    468464
    469465  // count max number of features in any domain
    470466  MaxLines := 0;
    471   for d := 0 to nDomains - 1 do
    472     if (upgrade[d, 0].Preq = preNone) or
    473       (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable) then
     467  for D := 0 to nDomains - 1 do
     468    if (upgrade[D, 0].Preq = preNone) or
     469      (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable) then
    474470    begin
    475471      count := 0;
    476       for i := 0 to nFeature - 1 do
    477         if IsFeatureInList(d, i) then
    478           inc(count);
     472      for I := 0 to nFeature - 1 do
     473        if IsFeatureInList(D, I) then
     474          Inc(count);
    479475      if count > MaxLines then
    480476        MaxLines := count;
     
    494490
    495491  SetDomain(Domain);
    496   Server(sCreateDevModel, me, Domain, nil^);
     492  Server(sCreateDevModel, Me, Domain, nil^);
    497493  MyModel[MyRO.nModel] := MyRO.DevModel;
    498   InitMyModel(MyRO.nModel, false);
     494  InitMyModel(MyRO.nModel, False);
    499495  OffscreenPaint;
    500496  IncCap := -1;
     
    502498end;
    503499
    504 procedure TDraftDlg.ShowNewContent(NewMode: integer);
     500procedure TDraftDlg.ShowNewContent(NewMode: TWindowMode);
    505501begin
    506502  inherited ShowNewContent(NewMode);
     
    508504
    509505procedure TDraftDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    510   Shift: TShiftState; x, y: integer);
     506  Shift: TShiftState; X, Y: Integer);
    511507var
    512   i, d: integer;
     508  I, D: Integer;
    513509begin
    514510  if Button = mbLeft then
    515511  begin
    516     for d := 0 to nDomains - 1 do
    517       if (d <> Domain) and ((upgrade[d, 0].Preq = preNone) or
    518         (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable)) and
    519         (x >= xDomain + d * DomainPitch) and
    520         (x < xDomain + d * DomainPitch + 36) and (y >= yDomain) and
    521         (y < yDomain + 36) then
     512    for D := 0 to nDomains - 1 do
     513      if (D <> Domain) and ((upgrade[D, 0].Preq = preNone) or
     514        (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable)) and
     515        (X >= xDomain + D * DomainPitch) and
     516        (X < xDomain + D * DomainPitch + 36) and (Y >= yDomain) and
     517        (Y < yDomain + 36) then
    522518      begin
    523         SetDomain(d);
    524         Server(sCreateDevModel, me, Domain, nil^);
     519        SetDomain(D);
     520        Server(sCreateDevModel, Me, Domain, nil^);
    525521        MyModel[MyRO.nModel] := MyRO.DevModel;
    526         InitMyModel(MyRO.nModel, false);
     522        InitMyModel(MyRO.nModel, False);
    527523        SmartUpdateContent;
    528524      end;
    529525
    530     if (y >= yFeature) and (y < yFeature + LinePitch * Lines) then
    531     begin
    532       i := (y - yFeature) div LinePitch;
    533       if (x >= xFeature - 21) and (x < ClientWidth) and (ssShift in Shift) then
    534         HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkFeature, code[i])
    535       else if not(code[i] in AutoFeature) then
     526    if (Y >= yFeature) and (Y < yFeature + LinePitch * Lines) then
     527    begin
     528      I := (Y - yFeature) div LinePitch;
     529      if (X >= xFeature - 21) and (X < ClientWidth) and (ssShift in Shift) then
     530        MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkFeature, Code[I])
     531      else if not(Code[I] in AutoFeature) then
    536532      begin
    537         if (code[i] < mcFirstNonCap) and (x >= xFeature - 21) and
    538           (x < xFeature - 21 + 12) then
     533        if (Code[I] < mcFirstNonCap) and (X >= xFeature - 21) and
     534          (X < xFeature - 21 + 12) then
    539535        begin
    540           IncCap := code[i];
    541           Dump(offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
    542             i, 12, 12, 182, 172);
     536          IncCap := Code[I];
     537          Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
     538            I, 12, 12, 182, 172);
    543539          SmartInvalidate;
    544540        end
    545         else if (x >= xFeature - 9) and (x < xFeature - 9 + 12) then
     541        else if (X >= xFeature - 9) and (X < xFeature - 9 + 12) then
    546542        begin
    547           DecCap := code[i];
    548           if code[i] < mcFirstNonCap then
    549             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    550               i, 12, 12, 182, 159)
     543          DecCap := Code[I];
     544          if Code[I] < mcFirstNonCap then
     545            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     546              I, 12, 12, 182, 159)
    551547          else
    552             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    553               i, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[code[i]]);
     548            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     549              I, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[Code[I]]);
    554550          SmartInvalidate;
    555551        end;
    556       end
    557     end
    558   end
     552      end;
     553    end;
     554  end;
    559555end;
    560556
    561557procedure TDraftDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    562   Shift: TShiftState; x, y: integer);
     558  Shift: TShiftState; X, Y: Integer);
    563559var
    564   NewValue: integer;
     560  NewValue: Integer;
    565561begin
    566562  if IncCap >= 0 then
    567563  begin
    568564    NewValue := MyRO.DevModel.Cap[IncCap] + 1;
    569     Server(sSetDevModelCap + NewValue shl 4, me, IncCap, nil^);
     565    Server(sSetDevModelCap + NewValue shl 4, Me, IncCap, nil^);
    570566    MyModel[MyRO.nModel] := MyRO.DevModel;
    571     InitMyModel(MyRO.nModel, false);
     567    InitMyModel(MyRO.nModel, False);
    572568    SmartUpdateContent;
    573569    IncCap := -1;
     
    580576      if DecCap >= mcFirstNonCap then
    581577        NewValue := -NewValue;
    582       Server(sSetDevModelCap + NewValue shl 4, me, DecCap, nil^);
     578      Server(sSetDevModelCap + NewValue shl 4, Me, DecCap, nil^);
    583579      MyModel[MyRO.nModel] := MyRO.DevModel;
    584       InitMyModel(MyRO.nModel, false);
     580      InitMyModel(MyRO.nModel, False);
    585581    end;
    586582    SmartUpdateContent;
  • TabularUnified branches/highdpi/LocalPlayer/Enhance.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, ScreenTools, BaseWin, Protocol, ClientTools, Term, LCLIntf, LCLType,
    8 
    9   SysUtils, Classes, Graphics, Controls, Forms, IsoEngine,
    10   ButtonB, ButtonC, Menus;
     7  UDpiControls, ScreenTools, BaseWin, Protocol, ClientTools, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, Controls, Forms, IsoEngine, ButtonB, ButtonC, Menus;
    119
    1210type
     
    3937    NoMap: TIsoMap;
    4038  public
    41     procedure ShowNewContent(NewMode: integer; TerrType: integer = -1);
     39    procedure ShowNewContent(NewMode: TWindowMode; TerrType: Integer = -1);
    4240  protected
    43     Page: integer;
     41    Page: Integer;
    4442    procedure OffscreenPaint; override;
    4543  end;
    4644
    47 var
    48   EnhanceDlg: TEnhanceDlg;
    49 
    5045
    5146implementation
    5247
    5348uses
    54   Help, UKeyBindings;
     49  Help, KeyBindings, Term;
    5550
    5651{$R *.lfm}
     
    5853procedure TEnhanceDlg.FormCreate(Sender: TObject);
    5954var
    60   TerrType: integer;
    61   m: TDpiMenuItem;
     55  TerrType: Integer;
     56  M: TDpiMenuItem;
    6257begin
    6358  inherited;
     
    7368    if TerrType <> fJungle then
    7469    begin
    75       m := TDpiMenuItem.Create(Popup);
    76       m.RadioItem := true;
     70      M := TDpiMenuItem.Create(Popup);
     71      M.RadioItem := True;
    7772      if TerrType = fGrass then
    78         m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
     73        M.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
    7974          [Phrases.Lookup('TERRAIN', fGrass), Phrases.Lookup('TERRAIN',
    8075          fGrass + 12)])
    8176      else if TerrType = fForest then
    82         m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
     77        M.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
    8378          [Phrases.Lookup('TERRAIN', fForest), Phrases.Lookup('TERRAIN',
    8479          fJungle)])
    8580      else
    86         m.Caption := Phrases.Lookup('TERRAIN', TerrType);
    87       m.Tag := TerrType;
    88       m.OnClick := TerrClick;
    89       Popup.Items.Add(m);
     81        M.Caption := Phrases.Lookup('TERRAIN', TerrType);
     82      M.Tag := TerrType;
     83      M.OnClick := TerrClick;
     84      Popup.Items.Add(M);
    9085    end;
    9186end;
     
    9893procedure TEnhanceDlg.FormPaint(Sender: TObject);
    9994var
    100   i: integer;
     95  I: Integer;
    10196begin
    10297  inherited;
     
    105100  BtnFrame(Canvas, Rect(job3.Left, job3.Top, job9.Left + job9.Width,
    106101    job3.Top + job3.Height), MainTexture);
    107   for i := 0 to ControlCount - 1 do
    108     if Controls[i] is TButtonC then
    109       DpiBitCanvas(Canvas, Controls[i].Left + 2, Controls[i].Top - 11, 8, 8,
    110         HGrSystem.Data.Canvas, 121 + Controls[i].Tag mod 7 * 9,
    111         1 + Controls[i].Tag div 7 * 9);
     102  for I := 0 to ControlCount - 1 do
     103    if Controls[I] is TButtonC then
     104      DpiBitBltCanvas(Canvas, Controls[I].Left + 2, Controls[I].Top - 11, 8, 8,
     105        HGrSystem.Data.Canvas, 121 + Controls[I].Tag mod 7 * 9,
     106        1 + Controls[I].Tag div 7 * 9);
    112107end;
    113108
     
    117112end;
    118113
    119 procedure TEnhanceDlg.ShowNewContent(NewMode, TerrType: integer);
     114procedure TEnhanceDlg.ShowNewContent(NewMode: TWindowMode; TerrType: Integer);
    120115begin
    121116  if (TerrType < fGrass) or (TerrType > fMountains) then
     
    128123procedure TEnhanceDlg.OffscreenPaint;
    129124var
    130   i, stage, TerrType, TileImp, x, EndStage, Cost, LastJob: integer;
    131   s: string;
    132   Done: Set of jNone .. jTrans;
    133   TypeChanged: boolean;
     125  I, stage, TerrType, TileImp, X, EndStage, Cost, LastJob: Integer;
     126  S: string;
     127  Done: set of jNone .. jTrans;
     128  TypeChanged: Boolean;
    134129begin
    135130  OffscreenUser := self;
    136   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     131  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    137132  FillOffscreen(0, 0, InnerWidth, InnerHeight);
    138133
    139134  EndStage := 0;
    140135  while (EndStage < 5) and (MyData.EnhancementJobs[Page, EndStage] <> jNone) do
    141     inc(EndStage);
     136    Inc(EndStage);
    142137  with NoMap do
    143     x := InnerWidth div 2 - xxt - (xxt + 3) * EndStage;
     138    X := InnerWidth div 2 - xxt - (xxt + 3) * EndStage;
    144139
    145140  TerrType := Page;
     
    151146    if stage > 0 then
    152147    begin
    153       Sprite(offscreen, HGrSystem, x - 10, 66, 14, 14, 80, 1);
     148      Sprite(Offscreen, HGrSystem, X - 10, 66, 14, 14, 80, 1);
    154149      case MyData.EnhancementJobs[Page, stage - 1] of
    155150        jRoad:
    156151          begin
    157             inc(Cost, Terrain[TerrType].MoveCost * RoadWork);
     152            Inc(Cost, Terrain[TerrType].MoveCost * RoadWork);
    158153            TileImp := TileImp or fRoad;
    159154          end;
    160155        jRR:
    161156          begin
    162             inc(Cost, Terrain[TerrType].MoveCost * RRWork);
     157            Inc(Cost, Terrain[TerrType].MoveCost * RRWork);
    163158            TileImp := TileImp or fRR;
    164159          end;
    165160        jIrr:
    166161          begin
    167             inc(Cost, Terrain[TerrType].IrrClearWork);
     162            Inc(Cost, Terrain[TerrType].IrrClearWork);
    168163            TileImp := TileImp and not fTerImp or tiIrrigation;
    169164          end;
    170165        jFarm:
    171166          begin
    172             inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);
     167            Inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);
    173168            TileImp := TileImp and not fTerImp or tiFarm;
    174169          end;
    175170        jMine:
    176171          begin
    177             inc(Cost, Terrain[TerrType].MineAfforestWork);
     172            Inc(Cost, Terrain[TerrType].MineAfforestWork);
    178173            TileImp := TileImp and not fTerImp or tiMine;
    179174          end;
    180175        jClear:
    181176          begin
    182             inc(Cost, Terrain[TerrType].IrrClearWork);
     177            Inc(Cost, Terrain[TerrType].IrrClearWork);
    183178            TerrType := Terrain[TerrType].ClearTerrain;
    184179          end;
    185180        jAfforest:
    186181          begin
    187             inc(Cost, Terrain[TerrType].MineAfforestWork);
     182            Inc(Cost, Terrain[TerrType].MineAfforestWork);
    188183            TerrType := Terrain[TerrType].AfforestTerrain;
    189184          end;
    190185        jTrans:
    191186          begin
    192             inc(Cost, Terrain[TerrType].TransWork);
     187            Inc(Cost, Terrain[TerrType].TransWork);
    193188            TerrType := Terrain[TerrType].TransTerrain;
    194189          end;
    195190      end;
    196       include(Done, MyData.EnhancementJobs[Page, stage - 1]);
     191      Include(Done, MyData.EnhancementJobs[Page, stage - 1]);
    197192    end;
    198193
    199194    with NoMap do begin
    200195      if TerrType < fForest then
    201         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     196        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    202197          1 + TerrType * (xxt * 2 + 1), 1 + yyt)
    203198      else
    204199      begin
    205         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     200        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    206201          1 + 2 * (xxt * 2 + 1), 1 + yyt + 2 * (yyt * 3 + 1));
    207         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     202        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    208203          1 + 7 * (xxt * 2 + 1), 1 + yyt + 2 * (2 + TerrType - fForest) *
    209204          (yyt * 3 + 1));
    210205      end;
    211206      if TileImp and fTerImp = tiFarm then
    212         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     207        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    213208          1 + (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1))
    214209      else if TileImp and fTerImp = tiIrrigation then
    215         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2, 1,
     210        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 1,
    216211          1 + yyt + 12 * (yyt * 3 + 1));
    217212      if TileImp and fRR <> 0 then
    218213      begin
    219         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     214        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    220215          1 + 6 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1));
    221         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     216        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    222217          1 + 2 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1));
    223218      end
    224219      else if TileImp and fRoad <> 0 then
    225220      begin
    226         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     221        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    227222          1 + 6 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1));
    228         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     223        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    229224          1 + 2 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1));
    230225      end;
    231226      if TileImp and fTerImp = tiMine then
    232         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     227        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    233228          1 + 2 * (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1));
    234       inc(x, xxt * 2 + 6);
    235     end;
    236   end;
    237 
    238   for i := 0 to Popup.Items.Count - 1 do
    239     if Popup.Items[i].Tag = Page then
    240       s := Popup.Items[i].Caption;
     229      Inc(X, xxt * 2 + 6);
     230    end;
     231  end;
     232
     233  for I := 0 to Popup.Items.Count - 1 do
     234    if Popup.Items[I].Tag = Page then
     235      S := Popup.Items[I].Caption;
    241236  if Cost > 0 then
    242     s := Format(Phrases.Lookup('ENHANCE'), [s, MovementToString(Cost)]);
    243   LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    244     (InnerWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2, 12, s);
     237    S := Format(Phrases.Lookup('ENHANCE'), [S, MovementToString(Cost)]);
     238  LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     239    (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 12, S);
    245240
    246241  if EndStage > 0 then
     
    291286    (Terrain[TerrType].MineEff > 0);
    292287  job3.Visible := not TypeChanged and (Terrain[TerrType].ClearTerrain >= 0) and
    293     ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = me)) or
     288    ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = Me)) or
    294289    (LastJob = jClear);
    295290  job6.Visible := not TypeChanged and (Terrain[TerrType].AfforestTerrain >= 0)
     
    299294
    300295  MarkUsedOffscreen(InnerWidth, InnerHeight);
    301 end; { OffscreenPaint }
     296end;
    302297
    303298procedure TEnhanceDlg.CloseBtnClick(Sender: TObject);
     
    308303procedure TEnhanceDlg.ToggleBtnClick(Sender: TObject);
    309304var
    310   i: integer;
    311 begin
    312   for i := 0 to Popup.Items.Count - 1 do
    313     Popup.Items[i].Checked := Popup.Items[i].Tag = Page;
     305  I: Integer;
     306begin
     307  for I := 0 to Popup.Items.Count - 1 do
     308    Popup.Items[I].Checked := Popup.Items[I].Tag = Page;
    314309  Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height);
    315310end;
     
    323318procedure TEnhanceDlg.JobClick(Sender: TObject);
    324319var
    325   stage, NewJob: integer;
     320  Stage, NewJob: Integer;
    326321  Done: Set of jNone .. jTrans;
    327322
    328   procedure RemoveJob(j: integer);
     323  procedure RemoveJob(J: Integer);
    329324  begin // remove job
    330     stage := 0;
    331     while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do
    332     begin
    333       if (MyData.EnhancementJobs[Page, stage] = j) or (j = jRoad) and
    334         (MyData.EnhancementJobs[Page, stage] = jRR) or (j = jIrr) and
    335         (MyData.EnhancementJobs[Page, stage] = jFarm) then
     325    Stage := 0;
     326    while (Stage < 5) and (MyData.EnhancementJobs[Page, Stage] <> jNone) do
     327    begin
     328      if (MyData.EnhancementJobs[Page, Stage] = J) or (J = jRoad) and
     329        (MyData.EnhancementJobs[Page, Stage] = jRR) or (J = jIrr) and
     330        (MyData.EnhancementJobs[Page, Stage] = jFarm) then
    336331      begin
    337         if stage < 4 then
    338           move(MyData.EnhancementJobs[Page, stage + 1],
    339             MyData.EnhancementJobs[Page, stage], 4 - stage);
     332        if Stage < 4 then
     333          Move(MyData.EnhancementJobs[Page, Stage + 1],
     334            MyData.EnhancementJobs[Page, Stage], 4 - Stage);
    340335        MyData.EnhancementJobs[Page, 4] := jNone;
    341336      end
    342337      else
    343         inc(stage);
     338        Inc(Stage);
    344339    end;
    345340  end;
     
    348343  NewJob := TButtonC(Sender).Tag;
    349344  Done := [];
    350   stage := 0;
    351   while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do
     345  Stage := 0;
     346  while (Stage < 5) and (MyData.EnhancementJobs[Page, Stage] <> jNone) do
    352347  begin
    353     include(Done, MyData.EnhancementJobs[Page, stage]);
    354     inc(stage);
     348    Include(Done, MyData.EnhancementJobs[Page, Stage]);
     349    Inc(Stage);
    355350  end;
    356351  if NewJob in Done then
     
    364359    if (NewJob = jRR) and not(jRoad in Done) then
    365360    begin
    366       MyData.EnhancementJobs[Page, stage] := jRoad;
    367       inc(stage);
     361      MyData.EnhancementJobs[Page, Stage] := jRoad;
     362      Inc(Stage);
    368363    end;
    369364    if (NewJob = jFarm) and not(jIrr in Done) then
    370365    begin
    371       MyData.EnhancementJobs[Page, stage] := jIrr;
    372       inc(stage);
    373     end;
    374     MyData.EnhancementJobs[Page, stage] := NewJob;
     366      MyData.EnhancementJobs[Page, Stage] := jIrr;
     367      Inc(Stage);
     368    end;
     369    MyData.EnhancementJobs[Page, Stage] := NewJob;
    375370  end;
    376371  SmartUpdateContent;
     
    384379  ShortCut := KeyToShortCut(Key, Shift);
    385380  if BHelp.Test(ShortCut) then
    386     HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkText,
    387       HelpDlg.TextIndex('MACRO'))
     381    MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkText,
     382      MainScreen.HelpDlg.TextIndex('MACRO'))
    388383end;
    389384
  • TabularUnified branches/highdpi/LocalPlayer/Help.pas

    r412 r465  
    77  UDpiControls, Protocol, ScreenTools, BaseWin, StringTables, Math, LCLIntf, LCLType,
    88  Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,
    9   ButtonB, PVSB, Types, fgl, IsoEngine;
     9  ButtonB, PVSB, Types, Generics.Collections, IsoEngine;
    1010
    1111const
    1212  MaxHist = 16;
    1313
    14   { link categories }
    15   hkNoLink = 0;
    16   hkAdv = 1;
    17   hkImp = 2;
    18   hkTer = 3;
    19   hkFeature = 4;
    20   hkInternet = 5;
    21   hkModel = 6;
    22   hkMisc = 7;
    23   hkCrossLink = $40;
    24   hkText = $80;
    25 
    26   liInvalid = $3FFF; // link index indicates invalid link
    27 
    28   { link indices for category hkMisc }
    29   miscMain = 0;
    30   miscCredits = 1;
    31   miscGovList = 2;
    32   miscJobList = 3;
    33   miscSearchResult = 7;
    34 
    35   fJungle = 8; // pseudo terrain
     14  fJungle = 8; // Pseudo terrain
    3615
    3716type
     17  { Link categories }
     18  TLinkCategory = (
     19    hkNoLink,
     20    hkAdv,
     21    hkImp,
     22    hkTer,
     23    hkFeature ,
     24    hkInternet,
     25    hkModel,
     26    hkMisc,
     27    hkText);
     28
     29  { Link indices for category hkMisc }
     30  TMiscLinkIndex = (
     31    miscMain,
     32    miscCredits,
     33    miscGovList,
     34    miscJobList,
     35    miscSearchResult);
     36
     37  TTextFormat = (
     38    pkNormal,
     39    pkCaption,
     40    pkSmallIcon,
     41    pkBigIcon,
     42    pkAdvIcon,
     43    pkTer,
     44    pkBigTer,
     45    pkFeature,
     46    pkDot,
     47    pkNormal_Dot,
     48    pkDomain,
     49    pkSection,
     50    pkBigFeature,
     51    pkExp,
     52    pkAITStat,
     53    pkExternal,
     54    pkModel,
     55    pkNormal_64,
     56    pkIllu,
     57    pkLogo,
     58    pkTerImp,
     59    pkRightIcon,
     60    pkAdvIcon_AsPreq,
     61    pkSmallIcon_AsPreq,
     62    pkSpecialIcon,
     63    pkGov);
    3864
    3965  { THyperText }
     
    4167  THyperText = class(TStringList)
    4268  public
    43     procedure AddLine(s: String = ''; Format: integer = 0; Picpix: Integer = 0;
    44       LinkCategory: integer = 0; LinkIndex: integer = 0);
     69    procedure AddLine(S: String = ''; Format: TTextFormat = pkNormal; Picpix: Integer = 0;
     70      LinkCategory: TLinkCategory = hkNoLink; LinkIndex: Integer = 0; CrossLink: Boolean = False);
    4571    procedure LineFeed;
    4672    procedure AppendList(Source: THyperText);
    47     destructor Destroy; override;
    4873  end;
    4974
     
    5176
    5277  THistItem = class
    53     Kind: Integer;
     78    Kind: TLinkCategory;
    5479    No: Integer;
    5580    Pos: Integer;
     
    6085  { THistItems }
    6186
    62   THistItems = class(TFPGObjectList<THistItem>)
    63     function AddNew(Kind, No, Pos: Integer; SearchContent: string): THistItem;
     87  THistItems = class(TObjectList<THistItem>)
     88    function AddNew(Kind: TLinkCategory; No, Pos: Integer; SearchContent: string): THistItem;
    6489  end;
    6590
     
    78103    procedure CloseBtnClick(Sender: TObject);
    79104    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
    80       x, y: integer);
     105      X, Y: Integer);
    81106    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    82       Shift: TShiftState; x, y: integer);
     107      Shift: TShiftState; X, Y: Integer);
    83108    procedure BackBtnClick(Sender: TObject);
    84109    procedure TopBtnClick(Sender: TObject);
     
    89114    procedure OffscreenPaint; override;
    90115  private
    91     Kind: Integer;
    92     no: Integer;
     116    Kind: TLinkCategory;
     117    No: Integer;
    93118    Sel: Integer;
    94119    CaptionColor: Integer;
     
    100125    SearchResult: THyperText;
    101126    HelpText: TStringTable;
    102     ExtPic, TerrIcon: TDpiBitmap;
     127    ExtPic: TDpiBitmap;
     128    TerrIcon: TDpiBitmap;
    103129    ScrollBar: TPVScrollbar;
    104130    NoMap: TIsoMap;
    105131    x0: array [-2..180] of Integer;
    106     procedure PaintTerrIcon(x, y, xSrc, ySrc: Integer);
     132    procedure PaintTerrIcon(X, Y, xSrc, ySrc: Integer);
    107133    procedure ScrollBarUpdate(Sender: TObject);
    108     procedure Line(ca: TDpiCanvas; i: Integer; lit: Boolean);
     134    procedure Line(ACanvas: TDpiCanvas; I: Integer; Lit: Boolean);
    109135    procedure Prepare(sbPos: Integer = 0);
    110     procedure ShowNewContentProcExecute(NewMode: Integer; HelpContext: string);
     136    procedure ShowNewContentProcExecute(NewMode: TWindowMode; HelpContext: string);
    111137    procedure WaterSign(x0, y0, iix: Integer);
    112138    procedure Search(SearchString: string);
     
    117143    Difficulty: Integer;
    118144    procedure ClearHistory;
    119     procedure ShowNewContent(NewMode, Category, Index: Integer);
     145    procedure ShowNewContent(NewMode: TWindowMode; Category: TLinkCategory; Index: Integer);
    120146    function TextIndex(Item: string): Integer;
    121147  end;
    122148
    123 var
    124   HelpDlg: THelpDlg;
    125 
    126149
    127150implementation
    128151
    129152uses
    130   Directories, ClientTools, Term, Tribes, Inp, Messg, UPixelPointer, Global,
    131   UKeyBindings;
     153  Directories, ClientTools, Term, Tribes, Inp, Messg, PixelPointer, Global,
     154  KeyBindings;
    132155
    133156{$R *.lfm}
     
    138161
    139162  THelpLineInfo = class
    140     Format: Byte;
     163    Format: TTextFormat;
    141164    Picpix: Byte;
    142     Link: Word;
     165    Category: TLinkCategory;
     166    Index: Integer;
     167    CrossLink: Boolean;
    143168    procedure Assign(Source: THelpLineInfo);
    144169  end;
    145170
    146 { THelpLineInfo }
    147 
    148 procedure THelpLineInfo.Assign(Source: THelpLineInfo);
    149 begin
    150   Format := Source.Format;
    151   PicPix := Source.PicPix;
    152   Link := Source.Link;
    153 end;
    154 
    155 { THistItem }
    156 
    157 procedure THistItem.Assign(Source: THistItem);
    158 begin
    159   Kind := Source.Kind;
    160   No := Source.No;
    161   Pos := Source.Pos;
    162   SearchContent := Source.SearchContent;
    163 end;
    164 
    165 { THistItems }
    166 
    167 function THistItems.AddNew(Kind, No, Pos: Integer; SearchContent: string
    168   ): THistItem;
    169 begin
    170   Result := THistItem.Create;
    171   Result.Kind := Kind;
    172   Result.No := No;
    173   Result.Pos := Pos;
    174   Result.SearchContent := SearchContent;
    175   Add(Result);
    176 end;
    177 
    178 procedure THyperText.AddLine(s: String; Format: integer; Picpix: integer;
    179   LinkCategory: integer; LinkIndex: integer);
    180 var
    181   HelpLineInfo: THelpLineInfo;
    182 begin
    183   HelpLineInfo := THelpLineInfo.Create;
    184   if LinkIndex < 0 then
    185     LinkIndex := liInvalid;
    186   HelpLineInfo.Format := Format;
    187   HelpLineInfo.Picpix := Picpix;
    188   HelpLineInfo.Link := LinkCategory shl 8 + LinkIndex;
    189   AddObject(s, TObject(HelpLineInfo));
    190 end;
    191 
    192 procedure THyperText.LineFeed;
    193 begin
    194   AddLine;
    195 end;
    196 
    197 procedure THyperText.AppendList(Source: THyperText);
    198 var
    199   I: Integer;
    200   HelpLineInfo: THelpLineInfo;
    201 begin
    202   for I := 0 to Source.Count - 1 do begin
    203     HelpLineInfo := THelpLineInfo.Create;
    204     HelpLineInfo.Assign(THelpLineInfo(Source.Objects[I]));
    205     AddObject(Source.Strings[I], HelpLineInfo);
    206   end;
    207 end;
    208 
    209 destructor THyperText.Destroy;
    210 begin
    211   inherited;
    212 end;
     171  TSeeAlso = record
     172    Kind: TLinkCategory;
     173    No: Integer;
     174    SeeKind: TLinkCategory;
     175    SeeNo: Integer;
     176  end;
    213177
    214178const
    215   { text formats }
    216   pkNormal = 0;
    217   pkCaption = 1;
    218   pkSmallIcon = 2;
    219   pkBigIcon = 3;
    220   pkAdvIcon = 4;
    221   pkTer = 5;
    222   pkBigTer = 6;
    223   pkFeature = 7;
    224   pkDot = 8;
    225   pkNormal_Dot = 9;
    226   pkDomain = 10;
    227   pkSection = 11;
    228   pkBigFeature = 12;
    229   pkExp = 13;
    230   pkAITStat = 14;
    231   pkExternal = 15;
    232   pkModel = 16;
    233   pkNormal_64 = 17;
    234   pkIllu = 18;
    235   pkLogo = 19;
    236   pkTerImp = 20;
    237   pkRightIcon = 21;
    238   pkAdvIcon_AsPreq = 22;
    239   pkSmallIcon_AsPreq = 23;
    240   pkSpecialIcon = 24;
    241   pkGov = 25;
    242 
    243   nSeeAlso = 14;
    244   SeeAlso: array [0 .. nSeeAlso - 1] of record
    245     Kind: Integer;
    246     no: Integer;
    247     SeeKind: Integer;
    248     SeeNo: Integer;
    249   end = ((Kind: hkImp; no: imWalls; SeeKind: hkFeature;
     179  SeeAlso: array[0..13] of TSeeAlso = ((Kind: hkImp; no: imWalls; SeeKind: hkFeature;
    250180    SeeNo: mcArtillery), (Kind: hkImp; no: imHydro; SeeKind: hkImp;
    251181    SeeNo: woHoover), (Kind: hkImp; no: imWalls; SeeKind: hkImp;
     
    262192    SeeKind: hkFeature; SeeNo: mcDefense));
    263193
    264   nTerrainHelp = 14;
    265   TerrainHelp: array [0 .. nTerrainHelp - 1] of integer = (fGrass, fGrass + 12,
     194  TerrainHelp: array[0..13] of Integer = (fGrass, fGrass + 12,
    266195    fPrairie, fForest, fJungle, fHills, fMountains, fSwamp, fTundra, fArctic,
    267     fDesert, 3 * 12 { DeadLands } , fShore, fOcean);
    268 
    269   nJobHelp = 8;
    270   JobHelp: array [0 .. nJobHelp - 1] of integer = (jRoad, jRR, jCanal, jIrr,
     196    fDesert, 3 * 12 { DeadLands }, fShore, fOcean);
     197
     198  JobHelp: array[0..7] of Integer = (jRoad, jRR, jCanal, jIrr,
    271199    jFarm, jMine, jFort, jBase);
    272200
     201{ THelpLineInfo }
     202
     203procedure THelpLineInfo.Assign(Source: THelpLineInfo);
     204begin
     205  Format := Source.Format;
     206  PicPix := Source.PicPix;
     207  Category := Source.Category;
     208  Index := Source.Index;
     209end;
     210
     211{ THistItem }
     212
     213procedure THistItem.Assign(Source: THistItem);
     214begin
     215  Kind := Source.Kind;
     216  No := Source.No;
     217  Pos := Source.Pos;
     218  SearchContent := Source.SearchContent;
     219end;
     220
     221{ THistItems }
     222
     223function THistItems.AddNew(Kind: TLinkCategory; No, Pos: Integer; SearchContent: string
     224  ): THistItem;
     225begin
     226  Result := THistItem.Create;
     227  Result.Kind := Kind;
     228  Result.No := No;
     229  Result.Pos := Pos;
     230  Result.SearchContent := SearchContent;
     231  Add(Result);
     232end;
     233
     234procedure THyperText.AddLine(S: String; Format: TTextFormat; Picpix: Integer;
     235  LinkCategory: TLinkCategory = hkNoLink; LinkIndex: Integer = 0;
     236  CrossLink: Boolean = False);
     237var
     238  HelpLineInfo: THelpLineInfo;
     239begin
     240  HelpLineInfo := THelpLineInfo.Create;
     241  HelpLineInfo.Format := Format;
     242  HelpLineInfo.Picpix := Picpix;
     243  HelpLineInfo.Category := LinkCategory;
     244  HelpLineInfo.Index := LinkIndex;
     245  HelpLineInfo.CrossLink := CrossLink;
     246  AddObject(S, HelpLineInfo);
     247end;
     248
     249procedure THyperText.LineFeed;
     250begin
     251  AddLine;
     252end;
     253
     254procedure THyperText.AppendList(Source: THyperText);
     255var
     256  I: Integer;
     257  HelpLineInfo: THelpLineInfo;
     258begin
     259  for I := 0 to Source.Count - 1 do begin
     260    HelpLineInfo := THelpLineInfo.Create;
     261    HelpLineInfo.Assign(THelpLineInfo(Source.Objects[I]));
     262    AddObject(Source.Strings[I], HelpLineInfo);
     263  end;
     264end;
     265
    273266procedure THelpDlg.FormCreate(Sender: TObject);
    274267begin
    275   inherited;
    276268  NoMap := TIsoMap.Create;
    277269
     
    280272  CaptionLeft := BackBtn.Left + BackBtn.Width;
    281273  CaptionRight := SearchBtn.Left;
    282   inc(ModalFrameIndent, 29);
     274  Inc(ModalFrameIndent, 29);
    283275  MainText := THyperText.Create;
    284276  MainText.OwnsObjects := True;
     
    290282
    291283  HelpText := TStringTable.Create;
    292   HelpText.LoadFromFile(LocalizedFilePath('Help' + DirectorySeparator + 'help.txt'));
     284  HelpText.LoadFromFile(LocalizedFilePath('Help' + DirectorySeparator + 'Help.txt'));
    293285  hADVHELP := HelpText.Gethandle('ADVHELP');
    294286  hIMPHELP := HelpText.Gethandle('IMPHELP');
     
    316308end;
    317309
    318 procedure THelpDlg.ShowNewContentProcExecute(NewMode: Integer;
     310procedure THelpDlg.ShowNewContentProcExecute(NewMode: TWindowMode;
    319311  HelpContext: string);
    320312begin
    321   HelpDlg.ShowNewContent(NewMode, hkText,
    322     HelpDlg.TextIndex(HelpContext))
     313  ShowNewContent(NewMode, hkText, TextIndex(HelpContext));
    323314end;
    324315
     
    356347  if ScrollBar.Process(Msg) then begin
    357348    Sel := -1;
    358     SmartUpdateContent(true)
     349    SmartUpdateContent(True)
    359350  end;
    360351  }
     
    364355begin
    365356  if Sel <> -1 then begin
    366     Line(Canvas, Sel, false);
    367     Sel := -1
     357    Line(Canvas, Sel, False);
     358    Sel := -1;
    368359  end;
    369360end;
     
    380371end;
    381372
    382 procedure THelpDlg.Line(ca: TDpiCanvas; i: Integer; lit: Boolean);
     373procedure THelpDlg.Line(ACanvas: TDpiCanvas; I: Integer; Lit: Boolean);
    383374var
    384   TextColor, x, y: Integer;
     375  TextColor: TColor;
     376  X, Y: Integer;
    385377  TextSize: TSize;
    386   s: string;
    387 begin
    388   s := MainText[ScrollBar.Position + i];
    389   if s = '' then
     378  S: string;
     379begin
     380  S := MainText[ScrollBar.Position + I];
     381  if S = '' then
    390382    Exit;
    391   x := x0[i];
    392   y := 2 + i * 24;
    393   if ca = Canvas then
    394   begin
    395     x := x + SideFrame;
    396     y := y + WideFrame
    397   end;
    398   if THelpLineInfo(MainText.Objects[ScrollBar.Position + i]).Format
     383  X := x0[I];
     384  Y := 2 + I * 24;
     385  if ACanvas = Canvas then
     386  begin
     387    X := X + SideFrame;
     388    Y := Y + WideFrame;
     389  end;
     390  if THelpLineInfo(MainText.Objects[ScrollBar.Position + I]).Format
    399391    in [pkCaption, pkBigTer, pkRightIcon, pkBigFeature] then
    400392  begin
    401     ca.Font.Assign(CaptionFont);
    402     { ca.brush.color:=CaptionColor;
    403       ca.FillRect(rect(x,i*24,x+24,i*24+24));
    404       ca.brush.color:=$FFFFFF;
    405       ca.FrameRect(rect(x+1,i*24+1,x+24-1,i*24+24-1));
    406       ca.Brush.Style:=bsClear; }
    407     DpiBitCanvas(ca, x, y - 4, 24, 24, HGrSystem.Data.Canvas, 1,
     393    ACanvas.Font.Assign(CaptionFont);
     394    { ACanvas.brush.color:=CaptionColor;
     395      ACanvas.FillRect(rect(X,I*24,X+24,I*24+24));
     396      ACanvas.Brush.Color:=$FFFFFF;
     397      ACanvas.FrameRect(rect(X+1,I*24+1,X+24-1,I*24+24-1));
     398      ACanvas.Brush.Style:=bsClear; }
     399    DpiBitBltCanvas(ACanvas, X, Y - 4, 24, 24, HGrSystem.Data.Canvas, 1,
    408400      146);
    409     BiColorTextOut(ca, $FFFFFF, $7F007F, x + 10 - ca.Textwidth(s[1]) div 2,
    410       y - 3, s[1]);
    411     BiColorTextOut(ca, CaptionColor, $7F007F, x + 24, y - 3, copy(s, 2, 255));
    412     ca.Font.Assign(UniFont[ftNormal]);
     401    BiColorTextOut(ACanvas, $FFFFFF, $7F007F, X + 10 - ACanvas.Textwidth(S[1]) div 2,
     402      Y - 3, S[1]);
     403    BiColorTextOut(ACanvas, CaptionColor, $7F007F, X + 24, Y - 3, Copy(S, 2, 255));
     404    ACanvas.Font.Assign(UniFont[ftNormal]);
    413405  end
    414   else if THelpLineInfo(MainText.Objects[ScrollBar.Position + i]).Format = pkSection
    415   then
    416   begin
    417     ca.Font.Assign(CaptionFont);
    418     BiColorTextOut(ca, CaptionColor, $7F007F, x, y - 3, s);
    419     ca.Font.Assign(UniFont[ftNormal]);
     406  else if THelpLineInfo(MainText.Objects[ScrollBar.Position + I]).Format = pkSection then
     407  begin
     408    ACanvas.Font.Assign(CaptionFont);
     409    BiColorTextOut(ACanvas, CaptionColor, $7F007F, X, Y - 3, S);
     410    ACanvas.Font.Assign(UniFont[ftNormal]);
    420411  end
    421412  else
    422413  begin
    423     if (Kind = hkMisc) and (no = miscMain) then
    424       ca.Font.Assign(CaptionFont);
     414    if (Kind = hkMisc) and (No = Integer(miscMain)) then
     415      ACanvas.Font.Assign(CaptionFont);
    425416    TextColor := Colors.Canvas.Pixels[clkMisc, cliPaperText];
    426     if ca = Canvas then
     417    if ACanvas = Canvas then
    427418    begin
    428       TextSize.cx := BiColorTextWidth(ca, s);
    429       TextSize.cy := ca.TextHeight(s);
    430       if y + TextSize.cy >= WideFrame + InnerHeight then
    431         TextSize.cy := WideFrame + InnerHeight - y;
    432       FillSeamless(ca, x, y, TextSize.cx, TextSize.cy, -SideFrame,
     419      TextSize.cx := BiColorTextWidth(ACanvas, S);
     420      TextSize.cy := ACanvas.TextHeight(S);
     421      if Y + TextSize.cy >= WideFrame + InnerHeight then
     422        TextSize.cy := WideFrame + InnerHeight - Y;
     423      FillSeamless(ACanvas, X, Y, TextSize.cx, TextSize.cy, -SideFrame,
    433424        ScrollBar.Position * 24 - WideFrame, Paper);
    434425    end;
    435     BiColorTextOut(ca, TextColor, $7F007F, x, y, s);
     426    BiColorTextOut(ACanvas, TextColor, $7F007F, X, Y, S);
    436427    if lit then
    437       with ca do
     428      with ACanvas do
    438429      begin
    439         Assert(ca = Canvas);
     430        Assert(ACanvas = Canvas);
    440431        Pen.Color := TextColor;
    441         MoveTo(x + 1, y + TextSize.cy - 2);
    442         LineTo(x + TextSize.cx, y + TextSize.cy - 2);
     432        MoveTo(X + 1, Y + TextSize.cy - 2);
     433        LineTo(X + TextSize.cx, Y + TextSize.cy - 2);
    443434      end;
    444     if (Kind = hkMisc) and (no = miscMain) then
    445       ca.Font.Assign(UniFont[ftNormal]);
    446   end;
    447 end;
    448 
    449 procedure THelpDlg.WaterSign(x0, y0, iix: integer);
     435    if (Kind = hkMisc) and (No = Integer(miscMain)) then
     436      ACanvas.Font.Assign(UniFont[ftNormal]);
     437  end;
     438end;
     439
     440procedure THelpDlg.WaterSign(x0, y0, iix: Integer);
    450441const
    451442  nHeaven = 28;
    452443  MaxSum = 9 * 9 * 255 * 75 div 100;
    453444var
    454   x, y, dx, dy, xSrc, ySrc, Sum, xx: integer;
    455   Heaven: array [0..nHeaven] of integer;
     445  X, Y, dx, dy, xSrc, ySrc, Sum, xx: Integer;
     446  Heaven: array [0..nHeaven] of Integer;
    456447  PaintPtr: TPixelPointer;
    457448  CoalPtr: TPixelPointer;
     
    467458  xSrc := iix mod 7 * xSizeBig;
    468459  ySrc := (iix div 7 + 1) * ySizeBig;
    469   PaintPtr := PixelPointer(OffScreen, ScaleToNative(x0), ScaleToNative(y0));
    470   CoalPtr := PixelPointer(Templates.Data, ScaleToNative(xCoal), ScaleToNative(yCoal));
     460  PaintPtr := TPixelPointer.Create(OffScreen, ScaleToNative(x0), ScaleToNative(y0));
     461  CoalPtr := TPixelPointer.Create(Templates.Data, ScaleToNative(xCoal), ScaleToNative(yCoal));
    471462  for dy := -1 to 1 do
    472     ImpPtr[dy] := PixelPointer(BigImp, ScaleToNative(xSrc), ScaleToNative(ySrc));
    473   for y := 0 to ScaleToNative(ySizeBig) * 2 - 1 do begin
    474     if ((ScaleToNative(y0) + y) >= 0) and ((ScaleToNative(y0) + y) < ScaleToNative(InnerHeight)) then begin
     463    ImpPtr[dy] := TPixelPointer.Create(BigImp, ScaleToNative(xSrc), ScaleToNative(ySrc));
     464  for Y := 0 to ScaleToNative(ySizeBig) * 2 - 1 do begin
     465    if ((ScaleToNative(y0) + Y) >= 0) and ((ScaleToNative(y0) + Y) < ScaleToNative(InnerHeight)) then begin
    475466      for dy := -1 to 1 do
    476         if ((Max(y + ScaleToNative(dy), 0) shr 1) >= 0) and ((Max(y + ScaleToNative(dy), 0) shr 1) < ScaleToNative(ySizeBig)) then
    477           ImpPtr[dy].SetXY(0, Max(y + ScaleToNative(dy), 0) shr 1);
    478       for x := 0 to ScaleToNative(xSizeBig * 2) - 1 do begin
     467        if ((Max(Y + ScaleToNative(dy), 0) shr 1) >= 0) and ((Max(Y + ScaleToNative(dy), 0) shr 1) < ScaleToNative(ySizeBig)) then
     468          ImpPtr[dy].SetXY(0, Max(Y + ScaleToNative(dy), 0) shr 1);
     469      for X := 0 to ScaleToNative(xSizeBig * 2) - 1 do begin
    479470        Sum := 0;
    480471        for dx := -1 to 1 do begin
    481           xx := Max((x + ScaleToNative(dx)), 0) shr 1;
     472          xx := Max((X + ScaleToNative(dx)), 0) shr 1;
    482473          for dy := -1 to 1 do begin
    483474            ImpPtr[dy].SetX(xx);
    484             if ((y + ScaleToNative(dy)) shr 1 < 0) or ((y + ScaleToNative(dy)) shr 1 >= ScaleToNative(ySizeBig)) or
    485               ((x + ScaleToNative(dx)) shr 1 < 0) or ((x + ScaleToNative(dx)) shr 1 >= ScaleToNative(xSizeBig)) or
    486               ((y + ScaleToNative(dy)) shr 1 < ScaleToNative(nHeaven)) and
     475            if ((Y + ScaleToNative(dy)) shr 1 < 0) or ((Y + ScaleToNative(dy)) shr 1 >= ScaleToNative(ySizeBig)) or
     476              ((X + ScaleToNative(dx)) shr 1 < 0) or ((X + ScaleToNative(dx)) shr 1 >= ScaleToNative(xSizeBig)) or
     477              ((Y + ScaleToNative(dy)) shr 1 < ScaleToNative(nHeaven)) and
    487478              (ImpPtr[dy].Pixel^.B shl 16 + ImpPtr[dy].Pixel^.G shl 8 +
    488               ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative(y + ScaleToNative(dy))) shr 1]) then
     479              ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative(Y + ScaleToNative(dy))) shr 1]) then
    489480              Sum := Sum + 9 * 255
    490481            else
     
    493484          end;
    494485        end;
    495         if Sum < MaxSum then begin // no saturation
     486        if Sum < MaxSum then begin // No saturation
    496487          Sum := 1 shl 22 - (MaxSum - Sum) * (256 - CoalPtr.Pixel^.B * 2);
    497488          PaintPtr.Pixel^.B := Min(PaintPtr.Pixel^.B * Sum shr 22, 255);
     
    510501end;
    511502
    512 procedure THelpDlg.PaintTerrIcon(x, y, xSrc, ySrc: integer);
     503procedure THelpDlg.PaintTerrIcon(X, Y, xSrc, ySrc: Integer);
    513504begin
    514505  with NoMap do begin
    515     Frame(OffScreen.Canvas, x - 1, y - 1, x + xSizeBig, y + ySizeBig,
     506    Frame(OffScreen.Canvas, X - 1, Y - 1, X + xSizeBig, Y + ySizeBig,
    516507      $000000, $000000);
    517508    if 2 * yyt < 40 then begin
    518       Sprite(OffScreen, HGrTerrain, x, y, 56, 2 * yyt, xSrc, ySrc);
    519       Sprite(OffScreen, HGrTerrain, x, y + 2 * yyt, 56, 40 - 2 * yyt,
     509      Sprite(OffScreen, HGrTerrain, X, Y, 56, 2 * yyt, xSrc, ySrc);
     510      Sprite(OffScreen, HGrTerrain, X, Y + 2 * yyt, 56, 40 - 2 * yyt,
    520511        xSrc, ySrc);
    521512    end else
    522       Sprite(OffScreen, HGrTerrain, x, y, 56, 40, xSrc, ySrc);
    523     Sprite(OffScreen, HGrTerrain, x, y, xxt, yyt, xSrc + xxt, ySrc + yyt);
    524     Sprite(OffScreen, HGrTerrain, x, y + yyt, xxt, 40 - yyt, xSrc + xxt, ySrc);
    525     Sprite(OffScreen, HGrTerrain, x + xxt, y, 56 - xxt, yyt, xSrc, ySrc + yyt);
    526     Sprite(OffScreen, HGrTerrain, x + xxt, y + yyt, 56 - xxt, 40 - yyt,
     513      Sprite(OffScreen, HGrTerrain, X, Y, 56, 40, xSrc, ySrc);
     514    Sprite(OffScreen, HGrTerrain, X, Y, xxt, yyt, xSrc + xxt, ySrc + yyt);
     515    Sprite(OffScreen, HGrTerrain, X, Y + yyt, xxt, 40 - yyt, xSrc + xxt, ySrc);
     516    Sprite(OffScreen, HGrTerrain, X + xxt, Y, 56 - xxt, yyt, xSrc, ySrc + yyt);
     517    Sprite(OffScreen, HGrTerrain, X + xxt, Y + yyt, 56 - xxt, 40 - yyt,
    527518      xSrc, ySrc);
    528519  end;
     
    531522procedure THelpDlg.OffscreenPaint;
    532523var
    533   i, j, yl, srcno, ofs, cnt, y: Integer;
    534   s: string;
     524  I, J, yl, srcno, ofs, cnt, Y: Integer;
     525  S: string;
    535526  HelpLineInfo: THelpLineInfo;
    536527begin
     
    542533  begin
    543534    Font.Assign(UniFont[ftNormal]);
    544     for i := -ScrollBar.Position to InnerHeight div 24 do
    545       if ScrollBar.Position + i < MainText.Count then
     535    for I := -ScrollBar.Position to InnerHeight div 24 do
     536      if ScrollBar.Position + I < MainText.Count then
    546537      begin
    547         HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + i]);
     538        HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + I]);
    548539        if HelpLineInfo.Format = pkExternal then
    549540        begin
    550541          yl := ExtPic.Height;
    551           if 4 + i * 24 + yl > InnerHeight then
    552             yl := InnerHeight - (4 + i * 24);
    553           DpiBitCanvas(OffScreen.Canvas, 8, 4 + i * 24, ExtPic.Width, yl, ExtPic.Canvas,
     542          if 4 + I * 24 + yl > InnerHeight then
     543            yl := InnerHeight - (4 + I * 24);
     544          DpiBitBltCanvas(OffScreen.Canvas, 8, 4 + I * 24, ExtPic.Width, yl, ExtPic.Canvas,
    554545            0, 0);
    555546        end;
    556547      end;
    557     for i := -2 to InnerHeight div 24 do
    558       if (ScrollBar.Position + i >= 0) and (ScrollBar.Position + i < MainText.Count) then
     548    for I := -2 to InnerHeight div 24 do
     549      if (ScrollBar.Position + I >= 0) and (ScrollBar.Position + I < MainText.Count) then
    559550      begin
    560         HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + i]);
    561         if HelpLineInfo.Link <> 0 then
     551        HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + I]);
     552        if (HelpLineInfo.Category <> hkNoLink) or (HelpLineInfo.Index <> 0) then
    562553        begin
    563           if (Kind = hkMisc) and (no = miscSearchResult) then
    564             Sprite(OffScreen, HGrSystem, 18, 9 + i * 24, 8, 8, 90, 16)
     554          if (Kind = hkMisc) and (No = Integer(miscSearchResult)) then
     555            Sprite(OffScreen, HGrSystem, 18, 9 + I * 24, 8, 8, 90, 16)
    565556          else if HelpLineInfo.Format in [pkSmallIcon_AsPreq, pkAdvIcon_AsPreq]
    566557          then
    567             Sprite(OffScreen, HGrSystem, 12, i * 24 + 5, 14, 14, 65, 20)
    568           else if HelpLineInfo.Link and (hkCrossLink shl 8) <> 0 then
    569             Sprite(OffScreen, HGrSystem, 12, i * 24 + 5, 14, 14, 80, 1)
    570           else if not((Kind = hkMisc) and (no = miscMain)) then
    571             Sprite(OffScreen, HGrSystem, 10, i * 24 + 6, 14, 14, 65, 1);
    572           x0[i] := 24;
     558            Sprite(OffScreen, HGrSystem, 12, I * 24 + 5, 14, 14, 65, 20)
     559          else if HelpLineInfo.CrossLink then
     560            Sprite(OffScreen, HGrSystem, 12, I * 24 + 5, 14, 14, 80, 1)
     561          else if not((Kind = hkMisc) and (No = Integer(miscMain))) then
     562            Sprite(OffScreen, HGrSystem, 10, I * 24 + 6, 14, 14, 65, 1);
     563          x0[I] := 24;
    573564        end
    574565        else
    575           x0[i] := 0;
     566          x0[I] := 0;
    576567        case HelpLineInfo.Format of
    577568          pkLogo:
    578569            begin
    579               Server(sGetVersion, 0, 0, j);
    580               s := Format('%d.%d.%d', [j shr 16 and $FF, j shr 8 and $FF,
    581                 j and $FF]);
    582               PaintLogo(OffScreen.Canvas, (InnerWidth - 122) div 2, i * 24 + 1,
     570              Server(sGetVersion, 0, 0, J);
     571              S := Format('%d.%d.%d', [J shr 16 and $FF, J shr 8 and $FF,
     572                J and $FF]);
     573              PaintLogo(OffScreen.Canvas, (InnerWidth - 122) div 2, I * 24 + 1,
    583574                HGrSystem.Data.Canvas.Pixels[95, 1], $000000);
    584575              Font.Assign(UniFont[ftSmall]);
    585576              BiColorTextOut(OffScreen.Canvas, $000000, $7F007F,
    586                 (InnerWidth - Textwidth(s)) div 2, i * 24 + 26, s);
     577                (InnerWidth - Textwidth(S)) div 2, I * 24 + 26, S);
    587578              Font.Assign(UniFont[ftNormal]);
    588579            end;
    589580          pkSmallIcon, pkSmallIcon_AsPreq:
    590581            begin
    591               ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[i], 2 - 1 + i * 24,
    592                 8 + xSizeSmall + x0[i], 2 + 20 + i * 24, $000000, $000000);
     582              ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24,
     583                8 + xSizeSmall + x0[I], 2 + 20 + I * 24, $000000, $000000);
    593584              if HelpLineInfo.Picpix = imPalace then
    594                 DpiBitCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24,
     585                DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24,
    595586                  xSizeSmall, ySizeSmall, SmallImp.Canvas,
    596587                  0 * xSizeSmall, 1 * ySizeSmall)
    597588              else
    598                 DpiBitCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24,
     589                DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24,
    599590                  xSizeSmall, ySizeSmall, SmallImp.Canvas,
    600591                  HelpLineInfo.Picpix mod 7 * xSizeSmall,
    601592                  (HelpLineInfo.Picpix + SystemIconLines * 7) div 7 *
    602593                  ySizeSmall);
    603               x0[i] := x0[i] + (8 + 8 + 36);
     594              x0[I] := x0[I] + (8 + 8 + 36);
    604595            end;
    605596          pkBigIcon:
    606597            begin
    607               FrameImage(OffScreen.Canvas, BigImp, x0[i] + 12, i * 24 - 7, 56,
     598              FrameImage(OffScreen.Canvas, BigImp, x0[I] + 12, I * 24 - 7, 56,
    608599                40, HelpLineInfo.Picpix mod 7 * xSizeBig,
    609600                HelpLineInfo.Picpix div 7 * ySizeBig);
    610               x0[i] := 64 + 8 + 8 + x0[i];
     601              x0[I] := 64 + 8 + 8 + x0[I];
    611602            end;
    612603          pkSpecialIcon:
     
    615606                0:
    616607                  FrameImage(OffScreen.Canvas, HGrSystem2.Data,
    617                     12 + x0[i], -7 + i * 24, 56, 40, 137, 127);
     608                    12 + x0[I], -7 + I * 24, 56, 40, 137, 127);
    618609                1:
    619610                  with NoMap do begin
    620                     PaintTerrIcon(12 + x0[i], -7 + i * 24,
     611                    PaintTerrIcon(12 + x0[I], -7 + I * 24,
    621612                      1 + 3 * (xxt * 2 + 1), 1 + yyt);
    622613                    if 2 * yyt < 40 then
    623                       Sprite(OffScreen, HGrTerrain, 12 + x0[i], -7 + 4 + i * 24,
     614                      Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24,
    624615                        56, 2 * yyt, 1 + 3 * (xxt * 2 + 1) + xxt - 28,
    625616                        1 + yyt + 1 * (yyt * 3 + 1))
    626617                    else
    627                       Sprite(OffScreen, HGrTerrain, 12 + x0[i],
    628                         -7 + 4 + i * 24 - 4, 56, 40, 1 + 3 * (xxt * 2 + 1) + xxt
     618                      Sprite(OffScreen, HGrTerrain, 12 + x0[I],
     619                        -7 + 4 + I * 24 - 4, 56, 40, 1 + 3 * (xxt * 2 + 1) + xxt
    629620                        - 28, 1 + yyt + 1 * (yyt * 3 + 1) + yyt - 20);
    630621                  end;
    631622                2:
    632623                  with NoMap do begin
    633                     PaintTerrIcon(12 + x0[i], -7 + i * 24,
     624                    PaintTerrIcon(12 + x0[I], -7 + I * 24,
    634625                      1 + 7 * (xxt * 2 + 1), 1 + yyt + 4 * (yyt * 3 + 1));
    635626                    if 2 * yyt < 40 then
    636                       Sprite(OffScreen, HGrTerrain, 12 + x0[i], -7 + 4 + i * 24,
     627                      Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24,
    637628                        56, 32, 1 + 4 * (xxt * 2 + 1) + xxt - 28,
    638629                        1 + yyt + 12 * (yyt * 3 + 1) + yyt - 16)
    639630                    else
    640                       Sprite(OffScreen, HGrTerrain, 12 + x0[i], -7 + 4 + i * 24,
     631                      Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24,
    641632                        56, 32, 1 + 4 * (xxt * 2 + 1) + xxt - 28,
    642633                        1 + yyt + 12 * (yyt * 3 + 1) + yyt - 16)
    643634                  end;
    644635              end;
    645               x0[i] := 64 + 8 + 8 + x0[i];
     636              x0[I] := 64 + 8 + 8 + x0[I];
    646637            end;
    647638          pkDomain:
    648639            begin
    649               ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[i], 2 - 1 + i * 24,
    650                 8 + 36 + x0[i], 2 + 20 + i * 24, $000000, $000000);
    651               Dump(OffScreen, HGrSystem, 8 + x0[i], 2 + i * 24, 36, 20,
     640              ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24,
     641                8 + 36 + x0[I], 2 + 20 + I * 24, $000000, $000000);
     642              Dump(OffScreen, HGrSystem, 8 + x0[I], 2 + I * 24, 36, 20,
    652643                75 + HelpLineInfo.Picpix * 37, 295);
    653               x0[i] := x0[i] + (8 + 8 + 36);
     644              x0[I] := x0[I] + (8 + 8 + 36);
    654645            end;
    655646          pkAdvIcon, pkAdvIcon_AsPreq:
    656647            begin
    657               ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[i], 2 - 1 + i * 24,
    658                 8 + xSizeSmall + x0[i], 2 + ySizeSmall + i * 24,
     648              ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24,
     649                8 + xSizeSmall + x0[I], 2 + ySizeSmall + I * 24,
    659650                $000000, $000000);
    660651              if AdvIcon[HelpLineInfo.Picpix] < 84 then
    661                 DpiBitCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24,
     652                DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24,
    662653                  xSizeSmall, ySizeSmall, SmallImp.Canvas,
    663654                  (AdvIcon[HelpLineInfo.Picpix] + SystemIconLines * 7) mod 7 *
     
    665656                  7) div 7 * ySizeSmall)
    666657              else
    667                 Dump(OffScreen, HGrSystem, 8 + x0[i], 2 + i * 24, 36, 20,
     658                Dump(OffScreen, HGrSystem, 8 + x0[I], 2 + I * 24, 36, 20,
    668659                  1 + (AdvIcon[HelpLineInfo.Picpix] - 84) mod 8 * 37,
    669660                  295 + (AdvIcon[HelpLineInfo.Picpix] - 84) div 8 * 21);
    670               j := AdvValue[HelpLineInfo.Picpix] div 1000;
    671               DpiBitCanvas(OffScreen.Canvas, x0[i] + 4, 4 + i * 24, 14, 14,
    672                 HGrSystem.Mask.Canvas, 127 + j * 15, 85, SRCAND);
    673               Sprite(OffScreen, HGrSystem, x0[i] + 3, 3 + i * 24, 14, 14,
    674                 127 + j * 15, 85);
    675               x0[i] := x0[i] + (8 + 8 + 36);
     661              J := AdvValue[HelpLineInfo.Picpix] div 1000;
     662              DpiBitBltCanvas(OffScreen.Canvas, x0[I] + 4, 4 + I * 24, 14, 14,
     663                HGrSystem.Mask.Canvas, 127 + J * 15, 85, SRCAND);
     664              Sprite(OffScreen, HGrSystem, x0[I] + 3, 3 + I * 24, 14, 14,
     665                127 + J * 15, 85);
     666              x0[I] := x0[I] + (8 + 8 + 36);
    676667            end;
    677668          pkRightIcon:
    678669            begin
    679670              if Imp[HelpLineInfo.Picpix].Kind <> ikWonder then
    680                 ImpImage(OffScreen.Canvas, InnerWidth - (40 + xSizeBig), i * 24,
     671                ImpImage(OffScreen.Canvas, InnerWidth - (40 + xSizeBig), I * 24,
    681672                  HelpLineInfo.Picpix, gDespotism)
    682673              else
    683                 WaterSign(InnerWidth - (40 + 2 * xSizeBig), i * 24 - 8,
     674                WaterSign(InnerWidth - (40 + 2 * xSizeBig), I * 24 - 8,
    684675                  HelpLineInfo.Picpix + 7);
    685               x0[i] := x0[i] + 8;
     676              x0[I] := x0[I] + 8;
    686677            end;
    687678          pkIllu:
    688             WaterSign(8, i * 24 - 8, HelpLineInfo.Picpix);
     679            WaterSign(8, I * 24 - 8, HelpLineInfo.Picpix);
    689680          pkBigFeature:
    690681            begin
    691682              cnt := 0;
    692               for j := nDomains - 1 downto 0 do
    693                 if 1 shl j and Feature[HelpLineInfo.Picpix].Domains <> 0 then
     683              for J := nDomains - 1 downto 0 do
     684                if 1 shl J and Feature[HelpLineInfo.Picpix].Domains <> 0 then
    694685                begin
    695                   inc(cnt);
     686                  Inc(cnt);
    696687                  Dump(OffScreen, HGrSystem, InnerWidth - 38 - 38 * cnt,
    697                     i * 24 + 1, 36, 20, 75 + j * 37, 295);
    698                   ScreenTools.Frame(OffScreen.Canvas, InnerWidth - 39 - 38 * cnt, i * 24,
    699                     InnerWidth - 2 - 38 * cnt, i * 24 + 21, $000000, $000000);
     688                    I * 24 + 1, 36, 20, 75 + J * 37, 295);
     689                  ScreenTools.Frame(OffScreen.Canvas, InnerWidth - 39 - 38 * cnt, I * 24,
     690                    InnerWidth - 2 - 38 * cnt, I * 24 + 21, $000000, $000000);
    700691                end;
    701692              DarkGradient(OffScreen.Canvas, InnerWidth - 38 - 38 * cnt,
    702                 i * 24 + 23, cnt * 38 - 2, 1);
     693                I * 24 + 23, cnt * 38 - 2, 1);
    703694              ofs := InnerWidth - (39 + 7) - 19 * cnt;
    704695              with OffScreen.Canvas do
    705696              begin
    706                 Brush.color := $C0C0C0;
    707                 FrameRect(Rect(ofs, 1 + 23 + i * 24, ofs + 14,
    708                   15 + 23 + i * 24));
     697                Brush.Color := $C0C0C0;
     698                FrameRect(Rect(ofs, 1 + 23 + I * 24, ofs + 14,
     699                  15 + 23 + I * 24));
    709700                Brush.Style := bsClear;
    710                 Sprite(OffScreen, HGrSystem, ofs + 2, 3 + 23 + i * 24, 10, 10,
     701                Sprite(OffScreen, HGrSystem, ofs + 2, 3 + 23 + I * 24, 10, 10,
    711702                  66 + HelpLineInfo.Picpix mod 11 * 11,
    712703                  137 + HelpLineInfo.Picpix div 11 * 11);
    713704              end;
    714               x0[i] := x0[i] + 8;
     705              x0[I] := x0[I] + 8;
    715706            end;
    716707          pkTer, pkBigTer:
    717708            with NoMap do begin
    718709              if HelpLineInfo.Format = pkBigTer then
    719                 y := i * 24 - 3 + yyt
     710                Y := I * 24 - 3 + yyt
    720711              else
    721                 y := i * 24 + 13;
     712                Y := I * 24 + 13;
    722713              if HelpLineInfo.Picpix >= 3 * 12 then
    723714                srcno := 2 * 9 + 6
     
    730721              if HelpLineInfo.Format = pkTer then
    731722              begin
    732                 ofs := x0[i] + 8;
    733                 x0[i] := 2 * xxt + 8 + ofs;
     723                ofs := x0[I] + 8;
     724                x0[I] := 2 * xxt + 8 + ofs;
    734725              end
    735726              else
    736727              begin
    737728                ofs := InnerWidth - (2 * xxt + 38);
    738                 x0[i] := x0[i] + 8;
     729                x0[I] := x0[I] + 8;
    739730              end;
    740731              if srcno >= fJungle then
    741732              begin
    742                 Sprite(OffScreen, HGrTerrain, ofs + 4, y - yyt + 2, xxt * 2 - 8,
     733                Sprite(OffScreen, HGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8,
    743734                  yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1),
    744735                  3 + yyt + 2 * (yyt * 3 + 1));
    745                 Sprite(OffScreen, HGrTerrain, ofs, y - 2 * yyt, xxt * 2,
     736                Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2,
    746737                  yyt * 3 - 2, 1 + srcno mod 9 * (xxt * 2 + 1),
    747738                  1 + srcno div 9 * (yyt * 3 + 1));
    748739              end
    749740              else
    750                 Sprite(OffScreen, HGrTerrain, ofs + 4, y - yyt + 2, xxt * 2 - 8,
     741                Sprite(OffScreen, HGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8,
    751742                  yyt * 2 - 4, 5 + srcno mod 9 * (xxt * 2 + 1),
    752743                  3 + yyt + srcno div 9 * (yyt * 3 + 1));
    753744              if HelpLineInfo.Picpix >= 3 * 12 then { rare resource }
    754                 Sprite(OffScreen, HGrTerrain, ofs, y - 2 * yyt, xxt * 2,
     745                Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2,
    755746                  yyt * 3, 1 + 8 * (xxt * 2 + 1),
    756747                  1 + (HelpLineInfo.Picpix - 2 * 12) * (yyt * 3 + 1))
     
    764755                  srcno := 18 + 8 + (HelpLineInfo.Picpix mod 12 - 9) * 18;
    765756                srcno := srcno + HelpLineInfo.Picpix div 12 * 9;
    766                 Sprite(OffScreen, HGrTerrain, ofs, y - 2 * yyt, xxt * 2,
     757                Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2,
    767758                  yyt * 3, 1 + srcno mod 9 * (xxt * 2 + 1),
    768759                  1 + srcno div 9 * (yyt * 3 + 1));
     
    774765              if HelpLineInfo.Picpix = 5 then
    775766              begin // display mine on hills
    776                 Sprite(OffScreen, HGrTerrain, ofs + 4, i * 24 + 13 - yyt,
     767                Sprite(OffScreen, HGrTerrain, ofs + 4, I * 24 + 13 - yyt,
    777768                  xxt * 2 - 8, yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1),
    778769                  3 + yyt + 2 * (yyt * 3 + 1));
     
    781772              else
    782773                srcno := fPrairie; // display on prairie
    783               Sprite(OffScreen, HGrTerrain, ofs + 4, i * 24 + 13 - yyt,
     774              Sprite(OffScreen, HGrTerrain, ofs + 4, I * 24 + 13 - yyt,
    784775                xxt * 2 - 8, yyt * 2 - 4, 5 + srcno mod 9 * (xxt * 2 + 1),
    785776                3 + yyt + srcno div 9 * (yyt * 3 + 1));
    786777              if HelpLineInfo.Picpix = 12 then { river }
    787                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - yyt, xxt * 2,
     778                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - yyt, xxt * 2,
    788779                  yyt * 2, 1 + 5 * (xxt * 2 + 1), 1 + yyt + 13 * (yyt * 3 + 1))
    789780              else if HelpLineInfo.Picpix >= 3 then { improvement 2 }
    790781              begin
    791782                if HelpLineInfo.Picpix = 6 then
    792                   Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     783                  Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    793784                    xxt * 2, yyt * 3, 1 + 7 * (xxt * 2 + 1),
    794785                    1 + 12 * (yyt * 3 + 1));
    795                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     786                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    796787                  xxt * 2, yyt * 3, 1 + (HelpLineInfo.Picpix - 3) *
    797788                  (xxt * 2 + 1), 1 + 12 * (yyt * 3 + 1))
     
    799790              else { improvement 1 }
    800791              begin
    801                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     792                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    802793                  xxt * 2, yyt * 3, 1 + 2 * (xxt * 2 + 1),
    803794                  1 + (9 + HelpLineInfo.Picpix) * (yyt * 3 + 1));
    804                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     795                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    805796                  xxt * 2, yyt * 3, 1 + 5 * (xxt * 2 + 1),
    806797                  1 + (9 + HelpLineInfo.Picpix) * (yyt * 3 + 1))
    807798              end;
    808               x0[i] := x0[i] + 8;
     799              x0[I] := x0[I] + 8;
    809800            end;
    810801          pkModel:
    811802            begin
    812               FrameImage(OffScreen.Canvas, BigImp, x0[i] + 12, i * 24 - 7,
     803              FrameImage(OffScreen.Canvas, BigImp, x0[I] + 12, I * 24 - 7,
    813804                56, 40, 0, 0);
    814               Sprite(OffScreen, HGrStdUnits, x0[i] + 8, i * 24 - 11, 64, 44,
     805              Sprite(OffScreen, HGrStdUnits, x0[I] + 8, I * 24 - 11, 64, 44,
    815806                1 + HelpLineInfo.Picpix mod 10 * 65,
    816807                1 + HelpLineInfo.Picpix div 10 * 49);
    817               x0[i] := 64 + 8 + 8 + x0[i];
     808              x0[I] := 64 + 8 + 8 + x0[I];
    818809            end;
    819810          pkFeature:
    820811            begin
    821               DarkGradient(OffScreen.Canvas, x0[i] + 8 - 1,
    822                 7 + i * 24 - 3, 16, 1);
    823               ScreenTools.Frame(OffScreen.Canvas, x0[i] + 8, 7 + i * 24 - 2, x0[i] + 8 + 13,
    824                 7 + i * 24 - 2 + 13, $C0C0C0, $C0C0C0);
    825               Sprite(OffScreen, HGrSystem, x0[i] + 8 + 2, 7 + i * 24, 10, 10,
     812              DarkGradient(OffScreen.Canvas, x0[I] + 8 - 1,
     813                7 + I * 24 - 3, 16, 1);
     814              ScreenTools.Frame(OffScreen.Canvas, x0[I] + 8, 7 + I * 24 - 2, x0[I] + 8 + 13,
     815                7 + I * 24 - 2 + 13, $C0C0C0, $C0C0C0);
     816              Sprite(OffScreen, HGrSystem, x0[I] + 8 + 2, 7 + I * 24, 10, 10,
    826817                66 + HelpLineInfo.Picpix mod 11 * 11,
    827818                137 + HelpLineInfo.Picpix div 11 * 11);
    828               x0[i] := x0[i] + 8 + 8 + 2 + 13;
     819              x0[I] := x0[I] + 8 + 8 + 2 + 13;
    829820            end;
    830821          pkExp:
    831822            begin
    832               ScreenTools.Frame(OffScreen.Canvas, 20 - 1, 8 - 4 + i * 24, 20 + 12,
    833                 8 + 11 + i * 24, $000000, $000000);
    834               Dump(OffScreen, HGrSystem, 20, 8 - 3 + i * 24, 12, 14,
     823              ScreenTools.Frame(OffScreen.Canvas, 20 - 1, 8 - 4 + I * 24, 20 + 12,
     824                8 + 11 + I * 24, $000000, $000000);
     825              Dump(OffScreen, HGrSystem, 20, 8 - 3 + I * 24, 12, 14,
    835826                121 + HelpLineInfo.Picpix * 13, 28);
    836               x0[i] := 20 + 8 + 11;
     827              x0[I] := 20 + 8 + 11;
    837828            end;
    838829          pkAITStat:
    839830            begin
    840               Sprite(OffScreen, HGrSystem, 20, 6 + i * 24, 14, 14,
     831              Sprite(OffScreen, HGrSystem, 20, 6 + I * 24, 14, 14,
    841832                1 + HelpLineInfo.Picpix * 15, 316);
    842               x0[i] := 20 + 8 + 11;
     833              x0[I] := 20 + 8 + 11;
    843834            end;
    844835          pkGov:
    845836            begin
    846               ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[i], 2 - 1 + i * 24,
    847                 8 + xSizeSmall + x0[i], 2 + 20 + i * 24, $000000, $000000);
    848               DpiBitCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24, xSizeSmall,
     837              ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24,
     838                8 + xSizeSmall + x0[I], 2 + 20 + I * 24, $000000, $000000);
     839              DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, xSizeSmall,
    849840                ySizeSmall, SmallImp.Canvas, (HelpLineInfo.Picpix - 1) *
    850841                xSizeSmall, ySizeSmall);
    851               x0[i] := x0[i] + (8 + 8 + 36);
     842              x0[I] := x0[I] + (8 + 8 + 36);
    852843            end;
    853844          pkDot:
    854845            begin
    855               Sprite(OffScreen, HGrSystem, x0[i] + 18, 9 + i * 24, 8,
     846              Sprite(OffScreen, HGrSystem, x0[I] + 18, 9 + I * 24, 8,
    856847                8, 81, 16);
    857               x0[i] := 20 + 8 + 4;
     848              x0[I] := 20 + 8 + 4;
    858849            end;
    859850          pkNormal_Dot:
    860             x0[i] := 20 + 8 + 4;
     851            x0[I] := 20 + 8 + 4;
    861852          pkNormal_64:
    862             x0[i] := 64 + 8 + 8;
     853            x0[I] := 64 + 8 + 8;
    863854        else
    864           x0[i] := x0[i] + 8;
     855          x0[I] := x0[I] + 8;
    865856        end;
    866         Self.Line(OffScreen.Canvas, i, False)
     857        Self.Line(OffScreen.Canvas, I, False)
    867858      end;
    868859  end;
     
    873864begin
    874865  Sel := -1;
    875   SmartUpdateContent(true)
    876 end;
    877 
    878 procedure THelpDlg.Prepare(sbPos: integer = 0);
     866  SmartUpdateContent(True);
     867end;
     868
     869procedure THelpDlg.Prepare(sbPos: Integer = 0);
    879870var
    880   i, j, Special, Domain, Headline, TerrType, TerrSubType: integer;
    881   s: string;
    882   ps: pchar;
     871  I, J, Special, Domain, Headline, TerrType, TerrSubType: Integer;
     872  S: string;
     873  ps: PChar;
    883874  List: THyperText;
    884875  CheckSeeAlso: Boolean;
    885876
    886   procedure AddAdvance(i: integer);
    887   begin
    888     MainText.AddLine(Phrases.Lookup('ADVANCES', i), pkAdvIcon, i,
    889       hkAdv + hkCrossLink, i);
    890   end;
    891 
    892   procedure AddPreqAdv(i: integer);
    893   begin
    894     MainText.AddLine(Phrases.Lookup('ADVANCES', i), pkAdvIcon_AsPreq, i,
    895       hkAdv + hkCrossLink, i);
    896   end;
    897 
    898   procedure AddImprovement(i: integer);
    899   begin
    900     MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon, i,
    901       hkImp + hkCrossLink, i);
    902   end;
    903 
    904   procedure AddPreqImp(i: integer);
    905   begin
    906     MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon_AsPreq, i,
    907       hkImp + hkCrossLink, i);
    908   end;
    909 
    910   procedure AddTerrain(i: integer);
     877  procedure AddAdvance(I: Integer);
     878  begin
     879    MainText.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon, I,
     880      hkAdv, I, True);
     881  end;
     882
     883  procedure AddPreqAdv(I: Integer);
     884  begin
     885    MainText.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon_AsPreq, I,
     886      hkAdv, I, True);
     887  end;
     888
     889  procedure AddImprovement(I: Integer);
     890  begin
     891    MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I,
     892      hkImp, I, True);
     893  end;
     894
     895  procedure AddPreqImp(I: Integer);
     896  begin
     897    MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon_AsPreq, I,
     898      hkImp, I, True);
     899  end;
     900
     901  procedure AddTerrain(I: Integer);
    911902  begin
    912903    if MainText.Count > 1 then
     
    914905      MainText.LineFeed;
    915906    end;
    916     MainText.AddLine(Phrases.Lookup('TERRAIN', i), pkTer, i, hkTer, i);
    917   end;
    918 
    919   procedure AddFeature(i: integer);
    920   begin
    921     MainText.AddLine(Phrases.Lookup('FEATURES', i), pkFeature, i,
    922       hkFeature + hkCrossLink, i);
    923   end;
    924 
    925   procedure AddModel(i: integer);
     907    MainText.AddLine(Phrases.Lookup('TERRAIN', I), pkTer, I, hkTer, I);
     908  end;
     909
     910  procedure AddFeature(I: Integer);
     911  begin
     912    MainText.AddLine(Phrases.Lookup('FEATURES', I), pkFeature, I,
     913      hkFeature, I, True);
     914  end;
     915
     916  procedure AddModel(I: Integer);
    926917  var
    927     pix: integer;
     918    pix: Integer;
    928919    Name: string;
    929920  begin
    930921    if MainText.Count > 1 then
    931922      MainText.LineFeed;
    932     FindStdModelPicture(SpecialModelPictureCode[i], pix, Name);
    933     MainText.AddLine(Name, pkModel, pix, hkModel + hkCrossLink, i)
     923    FindStdModelPicture(SpecialModelPictureCode[I], pix, Name);
     924    MainText.AddLine(Name, pkModel, pix, hkModel, I, True);
    934925  end;
    935926
    936927  procedure AddStandardBlock(Item: string);
    937928  var
    938     i: integer;
     929    I: Integer;
    939930  begin
    940931    with MainText do
     
    947938      else if Item = 'TECHFORMULA' then
    948939      begin
    949         i := Difficulty;
    950         if i = 0 then
    951           i := 2;
    952         AddLine(Format(HelpText.Lookup('TECHFORMULA'), [TechFormula_M[i],
    953           TechFormula_D[i]]))
     940        I := Difficulty;
     941        if I = 0 then
     942          I := 2;
     943        AddLine(Format(HelpText.Lookup('TECHFORMULA'), [TechFormula_M[I],
     944          TechFormula_D[I]]));
    954945      end
    955946      else if Item = 'EXPERIENCE' then
    956         for i := 0 to nExp - 1 do
    957           AddLine(Phrases.Lookup('EXPERIENCE', i), pkExp, i)
     947        for I := 0 to nExp - 1 do
     948          AddLine(Phrases.Lookup('EXPERIENCE', I), pkExp, I)
    958949      else if Item = 'MODERN' then
    959         for i := 1 to 3 do
     950        for I := 1 to 3 do
    960951        begin
    961952          LineFeed;
    962           AddLine(Phrases.Lookup('TERRAIN', 3 * 12 + i), pkTer, 3 * 12 + i);
     953          AddLine(Phrases.Lookup('TERRAIN', 3 * 12 + I), pkTer, 3 * 12 + I);
    963954        end
    964955      else if Item = 'SAVED' then
    965956        AddLine(DataDir + 'Saved', pkNormal)
    966957      else if Item = 'AITSTAT' then
    967         for i := 0 to 3 do
    968           AddLine(Phrases2.Lookup('AITSTAT', i), pkAITStat, i)
    969     end
    970   end;
    971 
    972   procedure DecodeItem(s: string; var Category, Index: Integer);
     958        for I := 0 to 3 do
     959          AddLine(Phrases2.Lookup('AITSTAT', I), pkAITStat, I)
     960    end;
     961  end;
     962
     963  procedure DecodeItem(S: string; var Category: TLinkCategory; var Index: Integer);
    973964  var
    974     i: Integer;
    975   begin
    976     if (Length(s) > 0) and (s[1] = ':') then begin
     965    I: Integer;
     966  begin
     967    if (Length(S) > 0) and (S[1] = ':') then begin
    977968      Category := hkMisc;
    978969      Index := 0;
    979       for i := 3 to length(s) do
    980         Index := Index * 10 + Ord(s[i]) - 48;
    981       case s[2] of
     970      for I := 3 to Length(S) do
     971        Index := Index * 10 + Ord(S[I]) - 48;
     972      case S[2] of
    982973        'A': Category := hkAdv;
    983974        'B': Category := hkImp;
     
    986977        'E': Category := hkInternet;
    987978        'S': Category := hkModel;
    988         'C': Index := miscCredits;
    989         'J': Index := miscJobList;
    990         'G': Index := miscGovList;
     979        'C': Index := Integer(miscCredits);
     980        'J': Index := Integer(miscJobList);
     981        'G': Index := Integer(miscGovList);
    991982      end;
    992983      if (Category <> hkMisc) and (Index = 0) then
     
    994985    end else begin
    995986      Category := hkText;
    996       Index := HelpText.Gethandle(Copy(s, 1, 255));
     987      Index := HelpText.GetHandle(Copy(S, 1, 255));
    997988    end;
    998989  end;
    999990
    1000   procedure AddTextual(s: string);
     991  procedure AddTextual(S: string);
    1001992  var
    1002     i: Integer;
    1003     p: Integer;
    1004     l: Integer;
     993    I: Integer;
     994    P: Integer;
     995    L: Integer;
    1005996    ofs: Integer;
    1006     CurrentFormat: Integer;
    1007     FollowFormat: Integer;
     997    CurrentFormat: TTextFormat;
     998    FollowFormat: TTextFormat;
    1008999    Picpix: Integer;
    1009     LinkCategory: Integer;
     1000    LinkCategory: TLinkCategory;
     1001    CrossLink: Boolean;
    10101002    LinkIndex: Integer;
    10111003    RightMargin: Integer;
     
    10131005    Text: string;
    10141006  begin
     1007    CrossLink := False;
    10151008    RightMargin := InnerWidth - 16 - DpiGetSystemMetrics(SM_CXVSCROLL);
    10161009    FollowFormat := pkNormal;
    1017     while s <> '' do
     1010    while S <> '' do
    10181011    begin
    10191012      Picpix := 0;
    1020       LinkCategory := 0;
     1013      LinkCategory := hkNoLink;
    10211014      LinkIndex := 0;
    1022       if s[1] = '$' then
    1023       begin // window caption
    1024         p := 1;
     1015      if S[1] = '$' then
     1016      begin // Window caption
     1017        P := 1;
    10251018        repeat
    1026           inc(p)
    1027         until (p > Length(s)) or (s[p] = '\');
    1028         Caption := Copy(s, 2, p - 2);
    1029         Delete(s, 1, p);
     1019          Inc(P);
     1020        until (P > Length(S)) or (S[P] = '\');
     1021        Caption := Copy(S, 2, P - 2);
     1022        Delete(S, 1, P);
    10301023      end
    1031       else if s[1] = '&' then
    1032       begin // standard block
    1033         p := 1;
     1024      else if S[1] = '&' then
     1025      begin // Standard block
     1026        P := 1;
    10341027        repeat
    1035           inc(p)
    1036         until (p > Length(s)) or (s[p] = '\');
    1037         AddStandardBlock(Copy(s, 2, p - 2));
    1038         Delete(s, 1, p);
     1028          Inc(P);
     1029        until (P > Length(S)) or (S[P] = '\');
     1030        AddStandardBlock(Copy(S, 2, P - 2));
     1031        Delete(S, 1, P);
    10391032      end
    1040       else if s[1] = '@' then
    1041       begin // image
    1042         if (Length(s) >= 2) and (s[2] = '@') then
    1043         begin // generate from icon
     1033      else if S[1] = '@' then
     1034      begin // Image
     1035        if (Length(S) >= 2) and (S[2] = '@') then
     1036        begin // Generate from icon
    10441037          Picpix := 0;
    1045           p := 3;
    1046           while (p <= Length(s)) and (s[p] <> '\') do
     1038          P := 3;
     1039          while (P <= Length(S)) and (S[P] <> '\') do
    10471040          begin
    1048             Picpix := Picpix * 10 + Ord(s[p]) - 48;
    1049             inc(p)
     1041            Picpix := Picpix * 10 + Ord(S[P]) - 48;
     1042            Inc(P);
    10501043          end;
    10511044          if (Picpix < 0) or (Picpix >= nImp) then
     
    10571050        else
    10581051        begin // external image
    1059           p := 1;
     1052          P := 1;
    10601053          repeat
    1061             Inc(p)
    1062           until (p > Length(s)) or (s[p] = '\');
     1054            Inc(P);
     1055          until (P > Length(S)) or (S[P] = '\');
    10631056          if LoadGraphicFile(ExtPic, LocalizedFilePath('Help' +
    1064             DirectorySeparator + Copy(s, 2, p - 2)) + '.png') then
     1057            DirectorySeparator + Copy(S, 2, P - 2)) + '.png') then
    10651058          begin
    10661059            MainText.AddLine('', pkExternal);
    1067             for i := 0 to (ExtPic.Height - 12) div 24 do
     1060            for I := 0 to (ExtPic.Height - 12) div 24 do
    10681061              MainText.LineFeed;
    10691062          end;
    10701063        end;
    1071         Delete(s, 1, p);
     1064        Delete(S, 1, P);
    10721065      end
    10731066      else
    10741067      begin
    1075         case s[1] of
     1068        case S[1] of
    10761069          ':', ';':
    10771070            begin // link
    1078               p := 1;
     1071              P := 1;
    10791072              repeat
    1080                 inc(p)
    1081               until (p > Length(s)) or (s[p] = '\') or (s[p] = ' ');
    1082               DecodeItem(Copy(s, 2, p - 2), LinkCategory, LinkIndex);
    1083               CurrentFormat := 0;
     1073                Inc(P);
     1074              until (P > Length(S)) or (S[P] = '\') or (S[P] = ' ');
     1075              DecodeItem(Copy(S, 2, P - 2), LinkCategory, LinkIndex);
     1076              CurrentFormat := pkNormal;
    10841077              if (LinkCategory <> hkText) and (LinkIndex < 200) then
    10851078              // show icon
     
    10881081                    begin
    10891082                      CurrentFormat := pkAdvIcon;
    1090                       Picpix := LinkIndex
     1083                      Picpix := LinkIndex;
    10911084                    end;
    10921085                  hkImp:
    10931086                    begin
    10941087                      CurrentFormat := pkSmallIcon;
    1095                       Picpix := LinkIndex
     1088                      Picpix := LinkIndex;
    10961089                    end;
    10971090                  hkTer:
     
    11031096                    begin
    11041097                      CurrentFormat := pkFeature;
    1105                       Picpix := LinkIndex
     1098                      Picpix := LinkIndex;
    11061099                    end;
    11071100                  hkModel:
     
    11121105                    end;
    11131106                end;
    1114               if s[1] = ':' then
    1115                 LinkCategory := LinkCategory + hkCrossLink;
    1116               if (p > Length(s)) or (s[p] = ' ') then
    1117                 Delete(s, 1, p)
     1107              if S[1] = ':' then
     1108                CrossLink := True;
     1109              if (P > Length(S)) or (S[P] = ' ') then
     1110                Delete(S, 1, P)
    11181111              else
    1119                 Delete(s, 1, p - 1)
    1120             end;
    1121           '!': // highlited
    1122             if (Length(s) >= 2) and (s[2] = '!') then
     1112                Delete(S, 1, P - 1)
     1113            end;
     1114          '!': // highlighted
     1115            if (Length(S) >= 2) and (S[2] = '!') then
    11231116            begin
    11241117              if MainText.Count > 1 then
     
    11261119              FollowFormat := pkCaption;
    11271120              CurrentFormat := pkCaption;
    1128               Delete(s, 1, 2);
     1121              Delete(S, 1, 2);
    11291122            end
    11301123            else
     
    11321125              FollowFormat := pkSection;
    11331126              CurrentFormat := pkSection;
    1134               Delete(s, 1, 1);
     1127              Delete(S, 1, 1);
    11351128            end;
    11361129          '-':
     
    11381131              FollowFormat := pkNormal_Dot;
    11391132              CurrentFormat := pkDot;
    1140               Delete(s, 1, 1);
     1133              Delete(S, 1, 1);
    11411134            end;
    11421135        else
     
    11471140        else
    11481141          ofs := 8;
    1149         p := 0;
     1142        P := 0;
    11501143        repeat
    11511144          repeat
    1152             Inc(p)
    1153           until (p > Length(s)) or (s[p] = ' ') or (s[p] = '\');
    1154           if (BiColorTextWidth(OffScreen.Canvas, Copy(s, 1, p - 1)) <=
     1145            Inc(P)
     1146          until (P > Length(S)) or (S[P] = ' ') or (S[P] = '\');
     1147          if (BiColorTextWidth(OffScreen.Canvas, Copy(S, 1, P - 1)) <=
    11551148            RightMargin - ofs) then
    1156             l := p - 1
     1149            L := P - 1
    11571150          else
    11581151            Break;
    1159         until (p >= Length(s)) or (s[l + 1] = '\');
    1160         Text := Copy(s, 1, l);
    1161         if LinkCategory and $3f = hkInternet then begin
     1152        until (P >= Length(S)) or (S[L + 1] = '\');
     1153        Text := Copy(S, 1, L);
     1154        if LinkCategory = hkInternet then begin
    11621155          if LinkIndex = 1 then Text := AITemplateManual
    11631156          else if LinkIndex = 2 then Text := CevoHomepageShort
     
    11651158        end;
    11661159        MainText.AddLine(Text, CurrentFormat, Picpix, LinkCategory,
    1167           LinkIndex);
    1168         if (l < Length(s)) and (s[l + 1] = '\') then
     1160          LinkIndex, CrossLink);
     1161        if (L < Length(S)) and (S[L + 1] = '\') then
    11691162          FollowFormat := pkNormal;
    1170         Delete(s, 1, l + 1);
    1171       end
    1172     end
     1163        Delete(S, 1, L + 1);
     1164      end;
     1165    end;
    11731166  end;
    11741167
     
    11781171  end;
    11791172
    1180   procedure AddModelText(i: Integer);
     1173  procedure AddModelText(I: Integer);
    11811174  var
    11821175    pix: Integer;
    1183     s: string;
     1176    S: string;
    11841177  begin
    11851178    with MainText do begin
     
    11881181        LineFeed;
    11891182      end;
    1190       FindStdModelPicture(SpecialModelPictureCode[i], pix, s);
    1191       AddLine(s, pkSection);
    1192       AddLine(Format(HelpText.Lookup('STRENGTH'), [SpecialModel[i].Attack,
    1193         SpecialModel[i].Defense]), pkNormal_64);
     1183      FindStdModelPicture(SpecialModelPictureCode[I], pix, S);
     1184      AddLine(S, pkSection);
     1185      AddLine(Format(HelpText.Lookup('STRENGTH'), [SpecialModel[I].Attack,
     1186        SpecialModel[I].Defense]), pkNormal_64);
    11941187      AddLine(Format(HelpText.Lookup('SPEED'),
    1195         [MovementToString(SpecialModel[i].Speed)]), pkModel, pix);
     1188        [MovementToString(SpecialModel[I].Speed)]), pkModel, pix);
    11961189      if Difficulty = 0 then
    1197         AddLine(Format(HelpText.Lookup('BUILDCOST'), [SpecialModel[i].Cost]),
     1190        AddLine(Format(HelpText.Lookup('BUILDCOST'), [SpecialModel[I].Cost]),
    11981191          pkNormal_64)
    11991192      else
    12001193        AddLine(Format(HelpText.Lookup('BUILDCOST'),
    1201           [SpecialModel[i].Cost * BuildCostMod[Difficulty] div 12]),
     1194          [SpecialModel[I].Cost * BuildCostMod[Difficulty] div 12]),
    12021195          pkNormal_64);
    1203       s := HelpText.LookupByHandle(hSPECIALMODEL, i);
    1204       if (s <> '') and (s <> '*') then
    1205         AddTextual(s);
    1206       if SpecialModelPreq[i] >= 0 then
    1207         AddPreqAdv(SpecialModelPreq[i])
    1208       else if SpecialModelPreq[i] = preLighthouse then
     1196      S := HelpText.LookupByHandle(hSPECIALMODEL, I);
     1197      if (S <> '') and (S <> '*') then
     1198        AddTextual(S);
     1199      if SpecialModelPreq[I] >= 0 then
     1200        AddPreqAdv(SpecialModelPreq[I])
     1201      else if SpecialModelPreq[I] = preLighthouse then
    12091202        AddPreqImp(woLighthouse)
    1210       else if SpecialModelPreq[i] = preBuilder then
     1203      else if SpecialModelPreq[I] = preBuilder then
    12111204        AddPreqImp(woPyramids)
    1212       else if SpecialModelPreq[i] = preLeo then
     1205      else if SpecialModelPreq[I] = preLeo then
    12131206        AddPreqImp(woLeo);
    1214       if SpecialModelPreq[i] <> preNone then
     1207      if SpecialModelPreq[I] <> preNone then
    12151208        MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    12161209          [MainText[Count - 1]]);
     
    12201213  procedure AddJobList;
    12211214  var
    1222     i, JobCost: Integer;
     1215    I, JobCost: Integer;
    12231216  begin
    12241217    with MainText do begin
    1225       for i := 0 to nJobHelp - 1 do begin
    1226         if i > 0 then begin
     1218      for I := 0 to Length(JobHelp) - 1 do begin
     1219        if I > 0 then begin
    12271220          LineFeed;
    12281221          LineFeed;
    12291222        end;
    1230         AddLine(Phrases.Lookup('JOBRESULT', JobHelp[i]), pkSection);
     1223        AddLine(Phrases.Lookup('JOBRESULT', JobHelp[I]), pkSection);
    12311224        AddLine;
    1232         AddLine('', pkTerImp, i);
     1225        AddLine('', pkTerImp, I);
    12331226        AddLine;
    1234         AddTextual(HelpText.LookupByHandle(hJOBHELP, i));
     1227        AddTextual(HelpText.LookupByHandle(hJOBHELP, I));
    12351228        JobCost := -1;
    1236         case JobHelp[i] of
     1229        case JobHelp[I] of
    12371230          jCanal: JobCost := CanalWork;
    12381231          jFort: JobCost := FortWork;
     
    12441237        else
    12451238          AddTextual(HelpText.Lookup('JOBCOSTVAR'));
    1246         if JobPreq[JobHelp[i]] <> preNone then begin
    1247           AddPreqAdv(JobPreq[JobHelp[i]]);
     1239        if JobPreq[JobHelp[I]] <> preNone then begin
     1240          AddPreqAdv(JobPreq[JobHelp[I]]);
    12481241          MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    12491242            [MainText[Count - 1]]);
     
    12551248  procedure AddGraphicCredits;
    12561249  var
    1257     i: Integer;
    1258     s: string;
     1250    I: Integer;
     1251    S: string;
    12591252    sr: TSearchRec;
    12601253    List, Plus: TStringList;
     
    12711264
    12721265    List.Sort;
    1273     i := 1;
    1274     while i < List.Count do
    1275       if List[i] = List[i - 1] then
    1276         List.Delete(i)
     1266    I := 1;
     1267    while I < List.Count do
     1268      if List[I] = List[I - 1] then
     1269        List.Delete(I)
    12771270      else
    1278         Inc(i);
    1279 
    1280     for i := 0 to List.Count - 1 do begin
    1281       s := List[i];
    1282       while BiColorTextWidth(OffScreen.Canvas, s) > InnerWidth - 16 -
     1271        Inc(I);
     1272
     1273    for I := 0 to List.Count - 1 do begin
     1274      S := List[I];
     1275      while BiColorTextWidth(OffScreen.Canvas, S) > InnerWidth - 16 -
    12831276        DpiGetSystemMetrics(SM_CXVSCROLL) do
    1284         Delete(s, length(s), 1);
    1285       MainText.AddLine(s);
     1277        Delete(S, Length(S), 1);
     1278      MainText.AddLine(S);
    12861279    end;
    12871280    FreeAndNil(List);
     
    12901283  procedure AddSoundCredits;
    12911284  var
    1292     i: Integer;
    1293     s: string;
     1285    I: Integer;
     1286    S: string;
    12941287    List: TStringList;
    12951288  begin
    12961289    List := TStringList.Create;
    12971290    List.LoadFromFile(GetSoundsDir + DirectorySeparator + 'sound.credits.txt');
    1298     for i := 0 to List.Count - 1 do begin
    1299       s := List[i];
    1300       while BiColorTextWidth(OffScreen.Canvas, s) > InnerWidth - 16 -
     1291    for I := 0 to List.Count - 1 do begin
     1292      S := List[I];
     1293      while BiColorTextWidth(OffScreen.Canvas, S) > InnerWidth - 16 -
    13011294        DpiGetSystemMetrics(SM_CXVSCROLL) do
    1302         Delete(s, length(s), 1);
    1303       MainText.AddLine(s);
     1295        Delete(S, Length(S), 1);
     1296      MainText.AddLine(S);
    13041297    end;
    13051298    FreeAndNil(List);
     
    13231316    Clear;
    13241317    Headline := -1;
    1325     if (no >= 200) or not(Kind in [hkAdv, hkImp, hkTer, hkFeature]) then
     1318    if (No >= 200) or not (Kind in [hkAdv, hkImp, hkTer, hkFeature]) then
    13261319      LineFeed;
    13271320    case Kind of
    13281321      hkText:
    1329         AddTextual(HelpText.LookupByHandle(no));
     1322        AddTextual(HelpText.LookupByHandle(No));
    13301323      hkMisc:
    13311324        begin
    1332           case no of
    1333             miscMain:
     1325          case No of
     1326            Integer(miscMain):
    13341327              begin
    13351328                Caption := HelpText.Lookup('HELPTITLE_MAIN');
    13361329                AddLine(HelpText.Lookup('HELPTITLE_QUICKSTART'), pkSpecialIcon,
    1337                   0, { pkBigIcon,22, } hkText, HelpText.Gethandle('QUICK'));
     1330                  0, { pkBigIcon,22, } hkText, HelpText.GetHandle('QUICK'));
    13381331                LineFeed;
    13391332                AddLine(HelpText.Lookup('HELPTITLE_CONCEPTS'), pkBigIcon, 6,
     
    13441337                LineFeed;
    13451338                AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkSpecialIcon, 2,
    1346                   hkMisc, miscJobList);
     1339                  hkMisc, Integer(miscJobList));
    13471340                LineFeed;
    13481341                AddLine(HelpText.Lookup('HELPTITLE_TECHLIST'), pkBigIcon, 39,
    13491342                  hkAdv, 200);
    13501343                LineFeed;
    1351                 FindStdModelPicture(SpecialModelPictureCode[6], i, s);
    1352                 AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkModel, i,
     1344                FindStdModelPicture(SpecialModelPictureCode[6], I, S);
     1345                AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkModel, I,
    13531346                  hkModel, 0);
    13541347                LineFeed;
     
    13661359                LineFeed;
    13671360                AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkBigIcon,
    1368                   gDemocracy + 6, hkMisc, miscGovList);
     1361                  gDemocracy + 6, hkMisc, Integer(miscGovList));
    13691362                LineFeed;
    13701363                AddLine(HelpText.Lookup('HELPTITLE_KEYS'), pkBigIcon, 2, hkText,
     
    13751368                LineFeed;
    13761369                AddLine(HelpText.Lookup('HELPTITLE_CREDITS'), pkBigIcon, 22,
    1377                   hkMisc, miscCredits);
     1370                  hkMisc, Integer(miscCredits));
    13781371              end;
    1379             miscCredits:
     1372            Integer(miscCredits):
    13801373              begin
    13811374                AddItem('CREDITS');
     
    13901383                AddItem('AUTHOR');
    13911384              end;
    1392             miscJobList:
     1385            Integer(miscJobList):
    13931386              begin
    13941387                Caption := HelpText.Lookup('HELPTITLE_JOBLIST');
     
    13991392                AddItem('TERIMPCITY');
    14001393              end;
    1401             miscGovList:
     1394            Integer(miscGovList):
    14021395              begin
    14031396                Caption := HelpText.Lookup('HELPTITLE_GOVLIST');
    1404                 for i := 1 to nGov do
     1397                for I := 1 to nGov do
    14051398                begin
    1406                   AddLine(Phrases.Lookup('GOVERNMENT', i mod nGov), pkSection);
     1399                  AddLine(Phrases.Lookup('GOVERNMENT', I mod nGov), pkSection);
    14071400                  LineFeed;
    1408                   if i = nGov then
     1401                  if I = nGov then
    14091402                    AddLine('', pkBigIcon, 7 * SystemIconLines + imPalace)
    14101403                  else
    1411                     AddLine('', pkBigIcon, i + 6);
     1404                    AddLine('', pkBigIcon, I + 6);
    14121405                  LineFeed;
    1413                   AddTextual(HelpText.LookupByHandle(hGOVHELP, i mod nGov));
    1414                   if i mod nGov >= 2 then
     1406                  AddTextual(HelpText.LookupByHandle(hGOVHELP, I mod nGov));
     1407                  if I mod nGov >= 2 then
    14151408                  begin
    1416                     AddPreqAdv(GovPreq[i mod nGov]);
     1409                    AddPreqAdv(GovPreq[I mod nGov]);
    14171410                    MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    14181411                      [MainText[Count - 1]]);
    14191412                  end;
    1420                   if i < nGov then
     1413                  if I < nGov then
    14211414                  begin
    14221415                    LineFeed;
     
    14251418                end;
    14261419              end;
    1427             miscSearchResult:
     1420            Integer(miscSearchResult):
    14281421              begin
    14291422                Caption := HelpText.Lookup('HELPTITLE_SEARCHRESULTS');
     
    14311424                MainText.AppendList(SearchResult);
    14321425              end;
    1433           end; // case no
     1426          end; // case No
    14341427        end;
    14351428
    14361429      hkAdv:
    1437         if no = 200 then
     1430        if No = 200 then
    14381431        begin // complete advance list
    14391432          Caption := HelpText.Lookup('HELPTITLE_TECHLIST');
    14401433          List := THyperText.Create;
    14411434          List.OwnsObjects := True;
    1442           for j := 0 to 3 do
     1435          for J := 0 to 3 do
    14431436          begin
    1444             if j > 0 then
     1437            if J > 0 then
    14451438            begin
    14461439              LineFeed;
    14471440              LineFeed;
    14481441            end;
    1449             AddLine(HelpText.Lookup('TECHAGE', j), pkSection);
    1450             if j = 1 then
     1442            AddLine(HelpText.Lookup('TECHAGE', J), pkSection);
     1443            if J = 1 then
    14511444              AddLine(Phrases.Lookup('ADVANCES', adScience) + ' ' +
    14521445                HelpText.Lookup('BASETECH'), pkAdvIcon, adScience, hkAdv,
    14531446                adScience);
    1454             if j = 2 then
     1447            if J = 2 then
    14551448              AddLine(Phrases.Lookup('ADVANCES', adMassProduction) + ' ' +
    14561449                HelpText.Lookup('BASETECH'), pkAdvIcon, adMassProduction, hkAdv,
    14571450                adMassProduction);
    14581451            List.Clear;
    1459             for i := 0 to nAdv - 1 do
    1460               if (i <> adScience) and (i <> adMassProduction) and
    1461                 (AdvValue[i] div 1000 = j) then
    1462                 List.AddLine(Phrases.Lookup('ADVANCES', i), pkAdvIcon, i,
    1463                   hkAdv, i);
     1452            for I := 0 to nAdv - 1 do
     1453              if (I <> adScience) and (I <> adMassProduction) and
     1454                (AdvValue[I] div 1000 = J) then
     1455                List.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon, I,
     1456                  hkAdv, I);
    14641457            List.Sort;
    14651458            AppendList(List);
     
    14691462        else // single advance
    14701463        begin
    1471           Caption := Phrases.Lookup('ADVANCES', no);
     1464          Caption := Phrases.Lookup('ADVANCES', No);
    14721465          LineFeed;
    1473           AddLine(Phrases.Lookup('ADVANCES', no), pkCaption);
    1474           if no in FutureTech then
     1466          AddLine(Phrases.Lookup('ADVANCES', No), pkCaption);
     1467          if No in FutureTech then
    14751468          begin
    14761469            AddLine(HelpText.Lookup('HELPSPEC_FUTURE'));
    14771470            LineFeed;
    1478             if no = futResearchTechnology then
     1471            if No = futResearchTechnology then
    14791472              AddItem('FUTURETECHHELP100')
    14801473            else
     
    14831476          else
    14841477            AddLine(HelpText.Lookup('HELPSPEC_ADV'));
    1485           if AdvPreq[no, 2] <> preNone then
     1478          if AdvPreq[No, 2] <> preNone then
    14861479            NextSection('PREREQALT')
    14871480          else
    14881481            NextSection('PREREQ');
    1489           for i := 0 to 2 do
    1490             if AdvPreq[no, i] <> preNone then
    1491               AddPreqAdv(AdvPreq[no, i]);
     1482          for I := 0 to 2 do
     1483            if AdvPreq[No, I] <> preNone then
     1484              AddPreqAdv(AdvPreq[No, I]);
    14921485          NextSection('GOVALLOW');
    1493           for i := 2 to nGov - 1 do
    1494             if GovPreq[i] = no then
    1495               AddLine(Phrases.Lookup('GOVERNMENT', i), pkGov, i,
    1496                 hkMisc + hkCrossLink, miscGovList);
     1486          for I := 2 to nGov - 1 do
     1487            if GovPreq[I] = No then
     1488              AddLine(Phrases.Lookup('GOVERNMENT', I), pkGov, I,
     1489                hkMisc, Integer(miscGovList), True);
    14971490          NextSection('BUILDALLOW');
    1498           for i := 0 to nWonder - 1 do
    1499             if Imp[i].Preq = no then
    1500               AddImprovement(i);
    1501           for i := nWonder to nImp - 1 do
    1502             if (Imp[i].Preq = no) and (Imp[i].Kind <> ikCommon) then
    1503               AddImprovement(i);
    1504           for i := nWonder to nImp - 1 do
    1505             if (Imp[i].Preq = no) and (Imp[i].Kind = ikCommon) then
    1506               AddImprovement(i);
     1491          for I := 0 to nWonder - 1 do
     1492            if Imp[I].Preq = No then
     1493              AddImprovement(I);
     1494          for I := nWonder to nImp - 1 do
     1495            if (Imp[I].Preq = No) and (Imp[I].Kind <> ikCommon) then
     1496              AddImprovement(I);
     1497          for I := nWonder to nImp - 1 do
     1498            if (Imp[I].Preq = No) and (Imp[I].Kind = ikCommon) then
     1499              AddImprovement(I);
    15071500          NextSection('MODELALLOW');
    1508           for i := 0 to nSpecialModel - 1 do
    1509             if SpecialModelPreq[i] = no then
    1510               AddModel(i);
     1501          for I := 0 to nSpecialModel - 1 do
     1502            if SpecialModelPreq[I] = No then
     1503              AddModel(I);
    15111504          NextSection('FEATALLOW');
    1512           for i := 0 to nFeature - 1 do
    1513             if Feature[i].Preq = no then
    1514               AddFeature(i);
     1505          for I := 0 to nFeature - 1 do
     1506            if Feature[I].Preq = No then
     1507              AddFeature(I);
    15151508          NextSection('FOLLOWADV');
    1516           for i := 0 to nAdv - 1 do
    1517             if (AdvPreq[i, 0] = no) or (AdvPreq[i, 1] = no) or
    1518               (AdvPreq[i, 2] = no) then
    1519               AddAdvance(i);
     1509          for I := 0 to nAdv - 1 do
     1510            if (AdvPreq[I, 0] = No) or (AdvPreq[I, 1] = No) or
     1511              (AdvPreq[I, 2] = No) then
     1512              AddAdvance(I);
    15201513          NextSection('UPGRADEALLOW');
    15211514          for Domain := 0 to nDomains - 1 do
    1522             for i := 1 to nUpgrade - 1 do
    1523               if upgrade[Domain, i].Preq = no then
     1515            for I := 1 to nUpgrade - 1 do
     1516              if upgrade[Domain, I].Preq = No then
    15241517              begin
    1525                 if upgrade[Domain, i].Strength > 0 then
     1518                if upgrade[Domain, I].Strength > 0 then
    15261519                  AddLine(Format(HelpText.Lookup('STRENGTHUP'),
    15271520                    [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain,
    1528                     i].Strength]), pkDomain, Domain);
    1529                 if upgrade[Domain, i].Trans > 0 then
     1521                    I].Strength]), pkDomain, Domain);
     1522                if upgrade[Domain, I].Trans > 0 then
    15301523                  AddLine(Format(HelpText.Lookup('TRANSUP'),
    1531                     [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, i].Trans]
     1524                    [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, I].Trans]
    15321525                    ), pkDomain, Domain);
    1533                 if no in FutureTech then
     1526                if No in FutureTech then
    15341527                  AddLine(Format(HelpText.Lookup('COSTUP'),
    1535                     [upgrade[Domain, i].Cost]), pkNormal_Dot)
     1528                    [upgrade[Domain, I].Cost]), pkNormal_Dot)
    15361529                else
    15371530                  AddLine(Format(HelpText.Lookup('COSTMIN'),
    1538                     [upgrade[Domain, i].Cost]), pkNormal_Dot)
     1531                    [upgrade[Domain, I].Cost]), pkNormal_Dot)
    15391532              end;
    15401533          NextSection('EXPIRATION');
    1541           for i := 0 to nWonder - 1 do
    1542             if (Imp[i].Preq <> preNA) and (Imp[i].Expiration = no) then
    1543               AddImprovement(i);
     1534          for I := 0 to nWonder - 1 do
     1535            if (Imp[I].Preq <> preNA) and (Imp[I].Expiration = No) then
     1536              AddImprovement(I);
    15441537          NextSection('ADVEFFECT');
    1545           s := HelpText.LookupByHandle(hADVHELP, no);
    1546           if s <> '*' then
    1547             AddTextual(s);
     1538          S := HelpText.LookupByHandle(hADVHELP, No);
     1539          if S <> '*' then
     1540            AddTextual(S);
    15481541          NextSection('SEEALSO');
    1549           CheckSeeAlso := true
     1542          CheckSeeAlso := True;
    15501543        end;
    15511544
    15521545      hkImp:
    1553         if no = 200 then
     1546        if No = 200 then
    15541547        begin // complete city improvement list
    15551548          Caption := HelpText.Lookup('HELPTITLE_IMPLIST');
     
    15571550          List := THyperText.Create;
    15581551          List.OwnsObjects := True;
    1559           for i := nWonder to nImp - 1 do
    1560             if (i <> imTrGoods) and (Imp[i].Preq <> preNA) and
    1561               (Imp[i].Kind = ikCommon) then
    1562               List.AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon,
    1563                 i, hkImp, i);
     1552          for I := nWonder to nImp - 1 do
     1553            if (I <> imTrGoods) and (Imp[I].Preq <> preNA) and
     1554              (Imp[I].Kind = ikCommon) then
     1555              List.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon,
     1556                I, hkImp, I);
    15641557          List.Sort;
    15651558          AppendList(List);
    15661559          FreeAndNil(List);
    15671560        end
    1568         else if no = 201 then
     1561        else if No = 201 then
    15691562        begin // complete nat. project list
    15701563          Caption := HelpText.Lookup('HELPTITLE_UNIQUELIST');
    15711564          // AddLine(HelpText.Lookup('HELPTITLE_UNIQUELIST'),pkSection);
    1572           for i := nWonder to nImp - 1 do
    1573             if (Imp[i].Preq <> preNA) and
    1574               ((Imp[i].Kind = ikNatLocal) or (Imp[i].Kind = ikNatGlobal)) then
    1575               AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon, i,
    1576                 hkImp, i);
     1565          for I := nWonder to nImp - 1 do
     1566            if (Imp[I].Preq <> preNA) and
     1567              ((Imp[I].Kind = ikNatLocal) or (Imp[I].Kind = ikNatGlobal)) then
     1568              AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I,
     1569                hkImp, I);
    15771570          { LineFeed;
    15781571            LineFeed;
    15791572            AddLine(HelpText.Lookup('HELPTITLE_SHIPPARTLIST'),pkSection);
    1580             for i:= nWonder to nImp-1 do
    1581             if (Imp[i].Preq<>preNA) and (Imp[i].Kind=ikShipPart) then
    1582             AddLine(Phrases.Lookup('IMPROVEMENTS',i),pkSmallIcon,i,hkImp,i); }
     1573            for I:= nWonder to nImp-1 do
     1574            if (Imp[I].Preq<>preNA) and (Imp[I].Kind=ikShipPart) then
     1575            AddLine(Phrases.Lookup('IMPROVEMENTS',I),pkSmallIcon,I,hkImp,I); }
    15831576        end
    1584         else if no = 202 then
     1577        else if No = 202 then
    15851578        begin // complete wonder list
    15861579          Caption := HelpText.Lookup('HELPTITLE_WONDERLIST');
    15871580          // AddLine(HelpText.Lookup('HELPTITLE_WONDERLIST'),pkSection);
    1588           for i := 0 to nWonder - 1 do
    1589             if Imp[i].Preq <> preNA then
    1590               AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon, i,
    1591                 hkImp, i);
     1581          for I := 0 to nWonder - 1 do
     1582            if Imp[I].Preq <> preNA then
     1583              AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I,
     1584                hkImp, I);
    15921585        end
    15931586        else
    15941587        begin // single building
    1595           Caption := Phrases.Lookup('IMPROVEMENTS', no);
     1588          Caption := Phrases.Lookup('IMPROVEMENTS', No);
    15961589          LineFeed;
    1597           AddLine(Phrases.Lookup('IMPROVEMENTS', no), pkRightIcon, no);
    1598           case Imp[no].Kind of
     1590          AddLine(Phrases.Lookup('IMPROVEMENTS', No), pkRightIcon, No);
     1591          case Imp[No].Kind of
    15991592            ikWonder: AddLine(HelpText.Lookup('HELPSPEC_WONDER'));
    16001593            ikCommon: AddLine(HelpText.Lookup('HELPSPEC_IMP'));
     
    16031596            AddLine(HelpText.Lookup('HELPSPEC_NAT'))
    16041597          end;
    1605           if Imp[no].Kind <> ikShipPart then begin
     1598          if Imp[No].Kind <> ikShipPart then begin
    16061599            NextSection('EFFECT');
    1607             AddTextual(HelpText.LookupByHandle(hIMPHELP, no));
     1600            AddTextual(HelpText.LookupByHandle(hIMPHELP, No));
    16081601          end;
    1609           if no = woSun then begin
     1602          if No = woSun then begin
    16101603            AddFeature(mcFirst);
    16111604            AddFeature(mcWill);
    16121605            AddFeature(mcAcademy);
    16131606          end;
    1614           if (no < nWonder) and not Phrases2FallenBackToEnglish then
     1607          if (No < nWonder) and not Phrases2FallenBackToEnglish then
    16151608          begin
    16161609            LineFeed;
    1617             if Imp[no].Expiration >= 0 then
     1610            if Imp[No].Expiration >= 0 then
    16181611              AddTextual(Phrases2.Lookup('HELP_WONDERMORALE1'))
    16191612            else
    16201613              AddTextual(Phrases2.Lookup('HELP_WONDERMORALE2'));
    16211614          end;
    1622           if Imp[no].Preq <> preNone then
     1615          if Imp[No].Preq <> preNone then
    16231616          begin
    16241617            NextSection('PREREQ');
    1625             AddPreqAdv(Imp[no].Preq);
     1618            AddPreqAdv(Imp[No].Preq);
    16261619          end;
    16271620          NextSection('COSTS');
    16281621          if Difficulty = 0 then
    1629             s := Format(HelpText.Lookup('BUILDCOST'), [Imp[no].Cost])
     1622            S := Format(HelpText.Lookup('BUILDCOST'), [Imp[No].Cost])
    16301623          else
    1631             s := Format(HelpText.Lookup('BUILDCOST'),
    1632               [Imp[no].Cost * BuildCostMod[Difficulty] div 12]);
    1633           AddLine(s);
    1634           if Imp[no].Maint > 0 then
    1635             AddLine(Format(HelpText.Lookup('MAINTCOST'), [Imp[no].Maint]));
    1636           j := 0;
    1637           for i := 0 to nImpReplacement - 1 do
    1638             if ImpReplacement[i].NewImp = no then
    1639             begin
    1640               if j = 0 then
     1624            S := Format(HelpText.Lookup('BUILDCOST'),
     1625              [Imp[No].Cost * BuildCostMod[Difficulty] div 12]);
     1626          AddLine(S);
     1627          if Imp[No].Maint > 0 then
     1628            AddLine(Format(HelpText.Lookup('MAINTCOST'), [Imp[No].Maint]));
     1629          J := 0;
     1630          for I := 0 to nImpReplacement - 1 do
     1631            if ImpReplacement[I].NewImp = No then
     1632            begin
     1633              if J = 0 then
    16411634              begin
    16421635                NextSection('REPLACE');
    16431636                AddItem('REPLACETEXT');
    1644                 j := 1;
     1637                J := 1;
    16451638              end;
    1646               AddImprovement(ImpReplacement[i].OldImp);
    1647             end;
    1648           if Imp[no].Kind = ikShipPart then
     1639              AddImprovement(ImpReplacement[I].OldImp);
     1640            end;
     1641          if Imp[No].Kind = ikShipPart then
    16491642          begin
    16501643            LineFeed;
    1651             if no = imShipComp then
    1652               i := 1
    1653             else if no = imShipPow then
    1654               i := 2
    1655             else { if no=imShipHab then }
    1656               i := 3;
     1644            if No = imShipComp then
     1645              I := 1
     1646            else if No = imShipPow then
     1647              I := 2
     1648            else { if No=imShipHab then }
     1649              I := 3;
    16571650            AddLine(Format(HelpText.Lookup('RAREREQUIRED'),
    1658               [Phrases.Lookup('TERRAIN', 3 * 12 + i)]), pkTer, 3 * 12 + i);
     1651              [Phrases.Lookup('TERRAIN', 3 * 12 + I)]), pkTer, 3 * 12 + I);
    16591652          end;
    1660           if (no < nWonder) and (Imp[no].Expiration >= 0) then
     1653          if (No < nWonder) and (Imp[No].Expiration >= 0) then
    16611654          begin
    16621655            NextSection('EXPIRATION');
    1663             s := Format(HelpText.Lookup('EXPWITH'),
    1664               [Phrases.Lookup('ADVANCES', Imp[no].Expiration)]);
    1665             if no = woPyramids then
    1666               s := s + ' ' + HelpText.Lookup('EXPSLAVE');
    1667             AddTextual(s);
     1656            S := Format(HelpText.Lookup('EXPWITH'),
     1657              [Phrases.Lookup('ADVANCES', Imp[No].Expiration)]);
     1658            if No = woPyramids then
     1659              S := S + ' ' + HelpText.Lookup('EXPSLAVE');
     1660            AddTextual(S);
    16681661          end;
    16691662          NextSection('SEEALSO');
    1670           if (no < nWonder) and (Imp[no].Expiration >= 0) then
     1663          if (No < nWonder) and (Imp[No].Expiration >= 0) then
    16711664            AddImprovement(woEiffel);
    1672           for i := 0 to nImpReplacement - 1 do
    1673             if ImpReplacement[i].OldImp = no then
    1674               AddImprovement(ImpReplacement[i].NewImp);
    1675           if no = imSupermarket then
     1665          for I := 0 to nImpReplacement - 1 do
     1666            if ImpReplacement[I].OldImp = No then
     1667              AddImprovement(ImpReplacement[I].NewImp);
     1668          if No = imSupermarket then
    16761669            AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0,
    1677               hkMisc + hkCrossLink, miscJobList);
    1678           CheckSeeAlso := true;
     1670              hkMisc, Integer(miscJobList), True);
     1671          CheckSeeAlso := True;
    16791672        end;
    16801673
    16811674      hkTer:
    1682         if no = 200 then
     1675        if No = 200 then
    16831676        begin // complete terrain type list
    16841677          Caption := HelpText.Lookup('HELPTITLE_TERLIST');
    16851678          // AddLine(HelpText.Lookup('HELPTITLE_TERLIST'),pkSection);
    1686           for i := 0 to nTerrainHelp - 1 do
    1687             AddTerrain(TerrainHelp[i]);
     1679          for I := 0 to Length(TerrainHelp) - 1 do
     1680            AddTerrain(TerrainHelp[I]);
    16881681        end
    16891682        else
    16901683        begin // sigle terrain type
    1691           TerrType := no mod 12;
     1684          TerrType := No mod 12;
    16921685          if TerrType = fJungle then
    16931686            TerrType := fForest;
    1694           TerrSubType := no div 12;
    1695           if no = 3 * 12 then
     1687          TerrSubType := No div 12;
     1688          if No = 3 * 12 then
    16961689          begin
    16971690            TerrType := fDesert;
     
    17001693          with Terrain[TerrType] do
    17011694          begin
    1702             Caption := Phrases.Lookup('TERRAIN', no);
     1695            Caption := Phrases.Lookup('TERRAIN', No);
    17031696            LineFeed;
    1704             AddLine(Phrases.Lookup('TERRAIN', no), pkBigTer, no);
     1697            AddLine(Phrases.Lookup('TERRAIN', No), pkBigTer, No);
    17051698            AddLine(HelpText.Lookup('HELPSPEC_TER'));
    17061699            LineFeed;
     
    17081701              AddLine(Format(HelpText.Lookup('RESPROD'),
    17091702                [ProdRes[TerrSubType]]));
    1710             if (no < 3 * 12) and (MineEff > 0) then
     1703            if (No < 3 * 12) and (MineEff > 0) then
    17111704              MainText[Count - 1] := MainText[Count - 1] + ' ' +
    17121705                Format(HelpText.Lookup('MOREMINE'), [MineEff]);
     
    17141707              AddLine(Format(HelpText.Lookup('RESFOOD'),
    17151708                [FoodRes[TerrSubType]]));
    1716             if (no < 3 * 12) and (IrrEff > 0) then
     1709            if (No < 3 * 12) and (IrrEff > 0) then
    17171710              MainText[Count - 1] := MainText[Count - 1] + ' ' +
    17181711                Format(HelpText.Lookup('MOREIRR'), [IrrEff]);
     
    17281721              else
    17291722                AddLine(HelpText.Lookup('MOVEPLAIN'));
    1730             if no = 3 * 12 then
     1723            if No = 3 * 12 then
    17311724            begin
    17321725              LineFeed;
    17331726              AddTextual(HelpText.Lookup('DEADLANDS'));
    17341727            end;
    1735             if (TerrType = fDesert) and (no <> fDesert + 12) then
     1728            if (TerrType = fDesert) and (No <> fDesert + 12) then
    17361729            begin
    17371730              LineFeed;
     
    17431736              AddTextual(Format(HelpText.Lookup('HOSTILE'), [ArcticThurst]));
    17441737            end;
    1745             if (no < 3 * 12) and (TransTerrain >= 0) then
     1738            if (No < 3 * 12) and (TransTerrain >= 0) then
    17461739            begin
    17471740              LineFeed;
    1748               i := TransTerrain;
    1749               if (TerrType <> fGrass) and (i <> fGrass) then
    1750                 i := i + TerrSubType * 12;
     1741              I := TransTerrain;
     1742              if (TerrType <> fGrass) and (I <> fGrass) then
     1743                I := I + TerrSubType * 12;
    17511744              // trafo to same Special resource group
    17521745              AddLine(Format(HelpText.Lookup('TRAFO'),
    1753                 [Phrases.Lookup('TERRAIN', i)]), pkTer, i,
    1754                 hkTer + hkCrossLink, i);
    1755               if no = fSwamp + 12 then
     1746                [Phrases.Lookup('TERRAIN', I)]), pkTer, I,
     1747                hkTer, I, True);
     1748              if No = fSwamp + 12 then
    17561749              begin
    17571750                LineFeed;
    17581751                AddLine(Format(HelpText.Lookup('TRAFO'),
    17591752                  [Phrases.Lookup('TERRAIN', TransTerrain + 24)]), pkTer,
    1760                   TransTerrain + 24, hkTer + hkCrossLink, TransTerrain + 24);
     1753                  TransTerrain + 24, hkTer, TransTerrain + 24, True);
    17611754              end
    1762               else if i = fGrass then
     1755              else if I = fGrass then
    17631756              begin
    17641757                LineFeed;
    17651758                AddLine(Format(HelpText.Lookup('TRAFO'),
    17661759                  [Phrases.Lookup('TERRAIN', fGrass + 12)]), pkTer, fGrass + 12,
    1767                   hkTer + hkCrossLink, fGrass + 12);
     1760                  hkTer, fGrass + 12, True);
    17681761              end;
    17691762            end;
    17701763            NextSection('SPECIAL');
    1771             if no = 3 * 12 then
     1764            if No = 3 * 12 then
    17721765            begin
    17731766              LineFeed;
     
    17801773              end;
    17811774            end
    1782             else if (no < 12) and (no <> fGrass) and (no <> fOcean) then
     1775            else if (No < 12) and (No <> fGrass) and (No <> fOcean) then
    17831776            begin
    17841777              LineFeed;
    17851778              for Special := 1 to 2 do
    1786                 if (no <> fArctic) and (no <> fSwamp) or (Special < 2) then
     1779                if (No <> fArctic) and (No <> fSwamp) or (Special < 2) then
    17871780                begin
    17881781                  if Special > 1 then
    17891782                    LineFeed;
    1790                   AddLine(Phrases.Lookup('TERRAIN', no + Special * 12), pkTer,
    1791                     no + Special * 12);
    1792                   i := FoodRes[Special] - FoodRes[0];
    1793                   if i <> 0 then
     1783                  AddLine(Phrases.Lookup('TERRAIN', No + Special * 12), pkTer,
     1784                    No + Special * 12);
     1785                  I := FoodRes[Special] - FoodRes[0];
     1786                  if I <> 0 then
    17941787                    MainText[Count - 1] := MainText[Count - 1] +
    1795                       Format(HelpText.Lookup('SPECIALFOOD'), [i]);
    1796                   i := ProdRes[Special] - ProdRes[0];
    1797                   if i <> 0 then
     1788                      Format(HelpText.Lookup('SPECIALFOOD'), [I]);
     1789                  I := ProdRes[Special] - ProdRes[0];
     1790                  if I <> 0 then
    17981791                    MainText[Count - 1] := MainText[Count - 1] +
    1799                       Format(HelpText.Lookup('SPECIALPROD'), [i]);
    1800                   i := TradeRes[Special] - TradeRes[0];
    1801                   if i <> 0 then
     1792                      Format(HelpText.Lookup('SPECIALPROD'), [I]);
     1793                  I := TradeRes[Special] - TradeRes[0];
     1794                  if I <> 0 then
    18021795                    MainText[Count - 1] := MainText[Count - 1] +
    1803                       Format(HelpText.Lookup('SPECIALTRADE'), [i]);
     1796                      Format(HelpText.Lookup('SPECIALTRADE'), [I]);
    18041797                end;
    18051798            end;
    1806             if no = 3 * 12 then
     1799            if No = 3 * 12 then
    18071800            begin
    18081801              LineFeed;
    18091802              AddTextual(HelpText.Lookup('RARE'));
    18101803            end;
    1811             if (no < 3 * 12) and (TerrType in [fDesert, fArctic]) then
     1804            if (No < 3 * 12) and (TerrType in [fDesert, fArctic]) then
    18121805            begin
    18131806              NextSection('SEEALSO');
    18141807              AddImprovement(woGardens);
    1815               CheckSeeAlso := true
     1808              CheckSeeAlso := True;
    18161809            end;
    18171810          end;
     
    18191812
    18201813      hkFeature:
    1821         if no = 200 then
     1814        if No = 200 then
    18221815        begin // complete feature list
    18231816          Caption := HelpText.Lookup('HELPTITLE_FEATURELIST');
     
    18371830            end;
    18381831            List.Clear;
    1839             for i := 0 to nFeature - 1 do
    1840               if Feature[i].Preq <> preNA then
     1832            for I := 0 to nFeature - 1 do
     1833              if Feature[I].Preq <> preNA then
    18411834              begin
    1842                 if i < mcFirstNonCap then
    1843                   j := 0
    1844                 else if i in AutoFeature then
    1845                   j := 2
     1835                if I < mcFirstNonCap then
     1836                  J := 0
     1837                else if I in AutoFeature then
     1838                  J := 2
    18461839                else
    1847                   j := 1;
    1848                 if j = Special then
    1849                   List.AddLine(Phrases.Lookup('FEATURES', i), pkFeature, i,
    1850                     hkFeature, i);
     1840                  J := 1;
     1841                if J = Special then
     1842                  List.AddLine(Phrases.Lookup('FEATURES', I), pkFeature, I,
     1843                    hkFeature, I);
    18511844              end;
    18521845            List.Sort;
     
    18571850        else
    18581851        begin // single feature
    1859           Caption := Phrases.Lookup('FEATURES', no);
     1852          Caption := Phrases.Lookup('FEATURES', No);
    18601853          LineFeed;
    1861           AddLine(Phrases.Lookup('FEATURES', no), pkBigFeature, no);
    1862           if no < mcFirstNonCap then
     1854          AddLine(Phrases.Lookup('FEATURES', No), pkBigFeature, No);
     1855          if No < mcFirstNonCap then
    18631856            AddLine(HelpText.Lookup('HELPSPEC_CAP'))
    1864           else if no in AutoFeature then
     1857          else if No in AutoFeature then
    18651858            AddLine(HelpText.Lookup('HELPSPEC_STANDARD'))
    18661859          else
    18671860            AddLine(HelpText.Lookup('HELPSPEC_FEATURE'));
    18681861          NextSection('EFFECT');
    1869           AddTextual(HelpText.LookupByHandle(hFEATUREHELP, no));
    1870           if (Feature[no].Weight <> 0) or (Feature[no].Cost <> 0) then
     1862          AddTextual(HelpText.LookupByHandle(hFEATUREHELP, No));
     1863          if (Feature[No].Weight <> 0) or (Feature[No].Cost <> 0) then
    18711864          begin
    18721865            NextSection('COSTS');
    1873             s := IntToStr(Feature[no].Cost);
    1874             if Feature[no].Cost >= 0 then
    1875               s := '+' + s;
    1876             AddLine(Format(HelpText.Lookup('COSTBASE'), [s]));
    1877             if Feature[no].Weight > 0 then
     1866            S := IntToStr(Feature[No].Cost);
     1867            if Feature[No].Cost >= 0 then
     1868              S := '+' + S;
     1869            AddLine(Format(HelpText.Lookup('COSTBASE'), [S]));
     1870            if Feature[No].Weight > 0 then
    18781871            begin
    18791872              AddLine(Format(HelpText.Lookup('WEIGHT'),
    1880                 ['+' + IntToStr(Feature[no].Weight)]));
    1881               if no = mcDefense then
     1873                ['+' + IntToStr(Feature[No].Weight)]));
     1874              if No = mcDefense then
    18821875                AddLine(Format(HelpText.Lookup('WEIGHT'), ['+2']),
    18831876                  pkDomain, dGround);
    18841877            end;
    18851878          end;
    1886           if Feature[no].Preq <> preNone then
     1879          if Feature[No].Preq <> preNone then
    18871880          begin
    18881881            LineFeed;
    1889             if Feature[no].Preq = preSun then
     1882            if Feature[No].Preq = preSun then
    18901883              AddPreqImp(woSun) // sun tsu feature
    18911884            else
    1892               AddPreqAdv(Feature[no].Preq);
     1885              AddPreqAdv(Feature[No].Preq);
    18931886            MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    18941887              [MainText[Count - 1]]);
     
    19011894        begin
    19021895          Caption := HelpText.Lookup('HELPTITLE_MODELLIST');
    1903           for i := 0 to nSpecialModel - 1 do
    1904             if i <> 2 then
    1905               AddModelText(i);
     1896          for I := 0 to nSpecialModel - 1 do
     1897            if I <> 2 then
     1898              AddModelText(I);
    19061899          LineFeed;
    19071900          AddItem('MODELNOTE');
     
    19101903    end;
    19111904    if CheckSeeAlso then
    1912       for i := 0 to nSeeAlso - 1 do
    1913         if (SeeAlso[i].Kind = Kind) and (SeeAlso[i].no = no) then
    1914           case SeeAlso[i].SeeKind of
    1915             hkImp: AddImprovement(SeeAlso[i].SeeNo);
    1916             hkAdv: AddAdvance(SeeAlso[i].SeeNo);
    1917             hkFeature: AddFeature(SeeAlso[i].SeeNo);
     1905      for I := 0 to Length(SeeAlso) - 1 do
     1906        if (SeeAlso[I].Kind = Kind) and (SeeAlso[I].No = No) then
     1907          case SeeAlso[I].SeeKind of
     1908            hkImp: AddImprovement(SeeAlso[I].SeeNo);
     1909            hkAdv: AddAdvance(SeeAlso[I].SeeNo);
     1910            hkFeature: AddFeature(SeeAlso[I].SeeNo);
    19181911          end;
    19191912    if (Headline >= 0) and (Count = Headline + 1) then
     
    19261919    ScrollBar.SetPos(sbPos);
    19271920    BackBtn.Visible := HistItems.Count > 1;
    1928     TopBtn.Visible := (HistItems.Count > 1) or (Kind <> hkMisc) or (no <> miscMain);
     1921    TopBtn.Visible := (HistItems.Count > 1) or (Kind <> hkMisc) or (No <> Integer(miscMain));
    19291922    Sel := -1;
    19301923  end; // with MainText
    19311924end;
    19321925
    1933 procedure THelpDlg.ShowNewContent(NewMode, Category, Index: Integer);
    1934 begin
    1935   if (Category <> Kind) or (Index <> no) or (Category = hkMisc) and
    1936     (Index = miscSearchResult) then begin
     1926procedure THelpDlg.ShowNewContent(NewMode: TWindowMode; Category: TLinkCategory;
     1927  Index: Integer);
     1928begin
     1929  if (Category <> Kind) or (Index <> No) or (Category = hkMisc) and
     1930    (Index = Integer(miscSearchResult)) then begin
    19371931    if HistItems.Count = MaxHist then HistItems.Delete(0);
    19381932    if HistItems.Count = 0 then
     
    19411935  end;
    19421936  Kind := Category;
    1943   no := Index;
     1937  No := Index;
    19441938  SearchContent := NewSearchContent;
    19451939  Prepare;
     
    19491943
    19501944procedure THelpDlg.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
    1951   x, y: integer);
     1945  X, Y: Integer);
    19521946var
    19531947  i0, Sel0: Integer;
    19541948begin
    1955   y := y - WideFrame;
     1949  Y := Y - WideFrame;
    19561950  i0 := ScrollBar.Position;
    19571951  Sel0 := Sel;
    1958   if (x >= SideFrame) and (x < SideFrame + InnerWidth) and (y >= 0) and
    1959     (y < InnerHeight) and (y mod 24 >= 8) then
    1960     Sel := y div 24
     1952  if (X >= SideFrame) and (X < SideFrame + InnerWidth) and (Y >= 0) and
     1953    (Y < InnerHeight) and (Y mod 24 >= 8) then
     1954    Sel := Y div 24
    19611955  else
    19621956    Sel := -1;
    19631957  if (Sel + i0 >= MainText.Count) or (Sel >= 0) and
    1964     (THelpLineInfo(MainText.Objects[Sel + i0]).Link = 0) then
     1958    (THelpLineInfo(MainText.Objects[Sel + i0]).Category = hkNoLink) and
     1959    (THelpLineInfo(MainText.Objects[Sel + i0]).Index = 0)then
    19651960    Sel := -1;
    19661961  if Sel <> Sel0 then
     
    19741969
    19751970procedure THelpDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    1976   Shift: TShiftState; x, y: integer);
     1971  Shift: TShiftState; X, Y: Integer);
    19771972begin
    19781973  if Sel >= 0 then
    19791974    with THelpLineInfo(MainText.Objects[Sel + ScrollBar.Position]) do
    1980       if Link shr 8 and $3F = hkInternet then
    1981         case Link and $FF of
     1975      if Category = hkInternet then
     1976        case Index of
    19821977          1: OpenDocument(HomeDir + AITemplateFileName);
    19831978          2: OpenURL(CevoHomepage);
     
    19861981      else
    19871982      begin
    1988         if (Link >= $8000) and (Link and $3FFF = liInvalid) then
    1989           exit; // invalid link;
    1990         if Link >= $8000 then
    1991           ShowNewContent(FWindowMode, hkText, Link and $3FFF)
    1992         else
    1993           ShowNewContent(FWindowMode, Link shr 8 and $3F, Link and $FF);
     1983        if Index < 0 then Exit; // invalid link;
     1984        ShowNewContent(FWindowMode, Category, Index);
    19941985      end;
    19951986end;
     
    20031994    HistItem.Assign(HistItems.Last);
    20041995    HistItems.Delete(HistItems.Count - 1);
    2005     if (HistItem.Kind = hkMisc) and (HistItem.No = miscSearchResult) and
     1996    if (HistItem.Kind = hkMisc) and (HistItem.No = Integer(miscSearchResult)) and
    20061997      (HistItem.SearchContent <> SearchContent) then
    20071998    begin
     
    20102001    end;
    20112002    Kind := HistItem.Kind;
    2012     no := HistItem.No;
     2003    No := HistItem.No;
    20132004    Prepare(HistItem.Pos);
    20142005    OffscreenPaint;
     
    20222013  while HistItems.Count > 1 do HistItems.Delete(HistItems.Count - 1);
    20232014  Kind := hkMisc;
    2024   no := miscMain;
     2015  No := Integer(miscMain);
    20252016  Prepare;
    20262017  OffscreenPaint;
     
    20362027function THelpDlg.TextIndex(Item: string): Integer;
    20372028begin
    2038   Result := HelpText.Gethandle(Item);
     2029  Result := HelpText.GetHandle(Item);
    20392030end;
    20402031
     
    20642055      1:
    20652056        with THelpLineInfo(SearchResult.Objects[0]) do
    2066           if Link >= $8000 then
    2067             ShowNewContent(FWindowMode, hkText, Link and $3FFF)
    2068           else
    2069             ShowNewContent(FWindowMode, Link shr 8 and $3F, Link and $FF);
    2070     else
    2071       begin
     2057          ShowNewContent(FWindowMode, Category, Index);
     2058      else begin
    20722059        NewSearchContent := InputDlg.EInput.Text;
    2073         ShowNewContent(FWindowMode, hkMisc, miscSearchResult);
     2060        ShowNewContent(FWindowMode, hkMisc, Integer(miscSearchResult));
    20742061      end;
    20752062    end;
     
    20792066procedure THelpDlg.Search(SearchString: string);
    20802067var
    2081   h, i, PrevHandle, PrevIndex, p, RightMargin: Integer;
    2082   s: string;
    2083   mADVHELP, mIMPHELP, mFEATUREHELP: set of 0 .. 255;
     2068  H, I, PrevHandle, PrevIndex, P, RightMargin: Integer;
     2069  S: string;
     2070  mADVHELP, mIMPHELP, mFEATUREHELP: set of 0..255;
    20842071  bGOVHELP, bSPECIALMODEL, bJOBHELP: Boolean;
    20852072begin
     
    20922079  bJOBHELP := False;
    20932080
    2094   // search in generic reference
     2081  // Search in generic reference
    20952082  SearchString := UpperCase(SearchString);
    2096   for i := 0 to 35 + 4 do begin
    2097     s := Phrases.Lookup('TERRAIN', i);
    2098     if pos(SearchString, UpperCase(s)) > 0 then
    2099       if i < 36 then
    2100         SearchResult.AddLine(s + ' ' + HelpText.Lookup('HELPSPEC_TER'),
    2101           pkNormal, 0, hkTer + hkCrossLink, i)
     2083  for I := 0 to 35 + 4 do begin
     2084    S := Phrases.Lookup('TERRAIN', I);
     2085    if Pos(SearchString, UpperCase(S)) > 0 then
     2086      if I < 36 then
     2087        SearchResult.AddLine(S + ' ' + HelpText.Lookup('HELPSPEC_TER'),
     2088          pkNormal, 0, hkTer, I, True)
    21022089      else
    21032090      begin
    21042091        SearchResult.AddLine(Phrases.Lookup('TERRAIN', 36) + ' ' +
    21052092          HelpText.Lookup('HELPSPEC_TER'), pkNormal, 0,
    2106           hkTer + hkCrossLink, 36);
    2107         if i > 36 then
     2093          hkTer, 36, True);
     2094        if I > 36 then
    21082095          SearchResult.AddLine(Phrases.Lookup('IMPROVEMENTS',
    2109             imShipComp + i - 37) + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'),
    2110             pkNormal, 0, hkImp + hkCrossLink, imShipComp + i - 37);
     2096            imShipComp + I - 37) + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'),
     2097            pkNormal, 0, hkImp, imShipComp + I - 37, True);
    21112098        Break;
    21122099      end;
    21132100  end;
    2114   for i := 0 to nJobHelp - 1 do
    2115     if pos(SearchString, UpperCase(Phrases.Lookup('JOBRESULT', JobHelp[i]))) > 0
     2101  for I := 0 to Length(JobHelp) - 1 do
     2102    if Pos(SearchString, UpperCase(Phrases.Lookup('JOBRESULT', JobHelp[I]))) > 0
    21162103    then
    21172104    begin
    21182105      SearchResult.AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0,
    2119         hkMisc + hkCrossLink, miscJobList);
     2106        hkMisc, Integer(miscJobList), True);
    21202107      bJOBHELP := True;
    21212108      Break;
    21222109    end;
    2123   for i := 0 to nAdv - 1 do
    2124   begin
    2125     s := Phrases.Lookup('ADVANCES', i);
    2126     if pos(SearchString, UpperCase(s)) > 0 then
     2110  for I := 0 to nAdv - 1 do
     2111  begin
     2112    S := Phrases.Lookup('ADVANCES', I);
     2113    if Pos(SearchString, UpperCase(S)) > 0 then
    21272114    begin
    2128       if i in FutureTech then
    2129         s := s + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
     2115      if I in FutureTech then
     2116        S := S + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
    21302117      else
    2131         s := s + ' ' + HelpText.Lookup('HELPSPEC_ADV');
    2132       SearchResult.AddLine(s, pkNormal, 0, hkAdv + hkCrossLink, i);
    2133       include(mADVHELP, i);
     2118        S := S + ' ' + HelpText.Lookup('HELPSPEC_ADV');
     2119      SearchResult.AddLine(S, pkNormal, 0, hkAdv, I, True);
     2120      Include(mADVHELP, I);
    21342121    end;
    21352122  end;
    2136   for i := 0 to nSpecialModel - 1 do
    2137   begin
    2138     FindStdModelPicture(SpecialModelPictureCode[i], h, s);
    2139     if pos(SearchString, UpperCase(s)) > 0 then
     2123  for I := 0 to nSpecialModel - 1 do
     2124  begin
     2125    FindStdModelPicture(SpecialModelPictureCode[I], H, S);
     2126    if Pos(SearchString, UpperCase(S)) > 0 then
    21402127    begin
    21412128      SearchResult.AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkNormal, 0,
    2142         hkModel + hkCrossLink, 0);
     2129        hkModel, 0, True);
    21432130      bSPECIALMODEL := True;
    21442131      Break;
    21452132    end;
    21462133  end;
    2147   for i := 0 to nFeature - 1 do
    2148   begin
    2149     s := Phrases.Lookup('FEATURES', i);
    2150     if Pos(SearchString, UpperCase(s)) > 0 then
     2134  for I := 0 to nFeature - 1 do
     2135  begin
     2136    S := Phrases.Lookup('FEATURES', I);
     2137    if Pos(SearchString, UpperCase(S)) > 0 then
    21512138    begin
    2152       if i < mcFirstNonCap then
    2153         s := s + ' ' + HelpText.Lookup('HELPSPEC_CAP')
    2154       else if i in AutoFeature then
    2155         s := s + ' ' + HelpText.Lookup('HELPSPEC_STANDARD')
     2139      if I < mcFirstNonCap then
     2140        S := S + ' ' + HelpText.Lookup('HELPSPEC_CAP')
     2141      else if I in AutoFeature then
     2142        S := S + ' ' + HelpText.Lookup('HELPSPEC_STANDARD')
    21562143      else
    2157         s := s + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
    2158       SearchResult.AddLine(s, pkNormal, 0, hkFeature + hkCrossLink, i);
    2159       Include(mFEATUREHELP, i);
     2144        S := S + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
     2145      SearchResult.AddLine(S, pkNormal, 0, hkFeature, I, True);
     2146      Include(mFEATUREHELP, I);
    21602147    end;
    21612148  end;
    2162   for i := 0 to nImp - 1 do
    2163   begin
    2164     s := Phrases.Lookup('IMPROVEMENTS', i);
    2165     if Pos(SearchString, UpperCase(s)) > 0 then
     2149  for I := 0 to nImp - 1 do
     2150  begin
     2151    S := Phrases.Lookup('IMPROVEMENTS', I);
     2152    if Pos(SearchString, UpperCase(S)) > 0 then
    21662153    begin
    2167       case Imp[i].Kind of
     2154      case Imp[I].Kind of
    21682155        ikWonder:
    2169           s := s + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
     2156          S := S + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
    21702157        ikCommon:
    2171           s := s + ' ' + HelpText.Lookup('HELPSPEC_IMP');
     2158          S := S + ' ' + HelpText.Lookup('HELPSPEC_IMP');
    21722159        ikShipPart:
    2173           s := s + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
     2160          S := S + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
    21742161      else
    2175         s := s + ' ' + HelpText.Lookup('HELPSPEC_NAT')
     2162        S := S + ' ' + HelpText.Lookup('HELPSPEC_NAT')
    21762163      end;
    2177       SearchResult.AddLine(s, pkNormal, 0, hkImp + hkCrossLink, i);
    2178       Include(mIMPHELP, i);
     2164      SearchResult.AddLine(S, pkNormal, 0, hkImp, I, True);
     2165      Include(mIMPHELP, I);
    21792166    end
    21802167  end;
    2181   for i := 0 to nGov - 1 do
    2182     if Pos(SearchString, UpperCase(Phrases.Lookup('GOVERNMENT', i))) > 0 then
     2168  for I := 0 to nGov - 1 do
     2169    if Pos(SearchString, UpperCase(Phrases.Lookup('GOVERNMENT', I))) > 0 then
    21832170    begin
    21842171      SearchResult.AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkNormal, 0,
    2185         hkMisc + hkCrossLink, miscGovList);
     2172        hkMisc, Integer(miscGovList), True);
    21862173      bGOVHELP := True;
    21872174      Break;
    21882175    end;
    21892176
    2190   // full text search
    2191   h := -1;
     2177  // Full text search
     2178  H := -1;
    21922179  repeat
    2193     PrevHandle := h;
    2194     PrevIndex := i;
    2195     if not HelpText.Search(SearchString, h, i) then
     2180    PrevHandle := H;
     2181    PrevIndex := I;
     2182    if not HelpText.Search(SearchString, H, I) then
    21962183      Break;
    2197     if h = hADVHELP then
     2184    if H = hADVHELP then
    21982185    begin
    2199       if (i >= 0) and ((i <> PrevIndex) or (h <> PrevHandle)) and
    2200         not(i in mADVHELP) then
     2186      if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and
     2187        not(I in mADVHELP) then
    22012188      begin
    2202         s := Phrases.Lookup('ADVANCES', i);
    2203         if i in FutureTech then
    2204           s := s + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
     2189        S := Phrases.Lookup('ADVANCES', I);
     2190        if I in FutureTech then
     2191          S := S + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
    22052192        else
    2206           s := s + ' ' + HelpText.Lookup('HELPSPEC_ADV');
    2207         SearchResult.AddLine(s, pkNormal, 0, hkAdv + hkCrossLink, i)
     2193          S := S + ' ' + HelpText.Lookup('HELPSPEC_ADV');
     2194        SearchResult.AddLine(S, pkNormal, 0, hkAdv, I, True);
    22082195      end;
    22092196    end
    2210     else if h = hIMPHELP then
     2197    else if H = hIMPHELP then
    22112198    begin
    2212       if (i >= 0) and ((i <> PrevIndex) or (h <> PrevHandle)) and
    2213         not(i in mIMPHELP) then
     2199      if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and
     2200        not(I in mIMPHELP) then
    22142201      begin
    2215         s := Phrases.Lookup('IMPROVEMENTS', i);
    2216         case Imp[i].Kind of
     2202        S := Phrases.Lookup('IMPROVEMENTS', I);
     2203        case Imp[I].Kind of
    22172204          ikWonder:
    2218             s := s + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
     2205            S := S + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
    22192206          ikCommon:
    2220             s := s + ' ' + HelpText.Lookup('HELPSPEC_IMP');
     2207            S := S + ' ' + HelpText.Lookup('HELPSPEC_IMP');
    22212208          ikShipPart:
    2222             s := s + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
     2209            S := S + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
    22232210        else
    2224           s := s + ' ' + HelpText.Lookup('HELPSPEC_NAT')
     2211          S := S + ' ' + HelpText.Lookup('HELPSPEC_NAT')
    22252212        end;
    2226         SearchResult.AddLine(s, pkNormal, 0, hkImp + hkCrossLink, i)
     2213        SearchResult.AddLine(S, pkNormal, 0, hkImp, I, True);
    22272214      end;
    22282215    end
    2229     else if h = hFEATUREHELP then
     2216    else if H = hFEATUREHELP then
    22302217    begin
    2231       if (i >= 0) and ((i <> PrevIndex) or (h <> PrevHandle)) and
    2232         not(i in mFEATUREHELP) then
     2218      if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and
     2219        not(I in mFEATUREHELP) then
    22332220      begin
    2234         s := Phrases.Lookup('FEATURES', i);
    2235         if i < mcFirstNonCap then
    2236           s := s + ' ' + HelpText.Lookup('HELPSPEC_CAP')
    2237         else if i in AutoFeature then
    2238           s := s + ' ' + HelpText.Lookup('HELPSPEC_STANDARD')
     2221        S := Phrases.Lookup('FEATURES', I);
     2222        if I < mcFirstNonCap then
     2223          S := S + ' ' + HelpText.Lookup('HELPSPEC_CAP')
     2224        else if I in AutoFeature then
     2225          S := S + ' ' + HelpText.Lookup('HELPSPEC_STANDARD')
    22392226        else
    2240           s := s + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
    2241         SearchResult.AddLine(s, pkNormal, 0, hkFeature + hkCrossLink, i);
     2227          S := S + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
     2228        SearchResult.AddLine(S, pkNormal, 0, hkFeature, I, True);
    22422229      end;
    22432230    end
    2244     else if h = hGOVHELP then
     2231    else if H = hGOVHELP then
    22452232    begin
    2246       if (i >= 0) and (h <> PrevHandle) and not bGOVHELP then
     2233      if (I >= 0) and (H <> PrevHandle) and not bGOVHELP then
    22472234        SearchResult.AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkNormal, 0,
    2248           hkMisc + hkCrossLink, miscGovList)
     2235          hkMisc, Integer(miscGovList), True);
    22492236    end
    2250     else if h = hSPECIALMODEL then
     2237    else if H = hSPECIALMODEL then
    22512238    begin
    2252       if (i >= 0) and (h <> PrevHandle) and not bSPECIALMODEL then
     2239      if (I >= 0) and (H <> PrevHandle) and not bSPECIALMODEL then
    22532240        SearchResult.AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkNormal,
    2254           0, hkModel + hkCrossLink, 0)
     2241          0, hkModel, 0, True);
    22552242    end
    2256     else if h = hJOBHELP then
     2243    else if H = hJOBHELP then
    22572244    begin
    2258       if (i >= 0) and (h <> PrevHandle) and not bJOBHELP then
     2245      if (I >= 0) and (H <> PrevHandle) and not bJOBHELP then
    22592246        SearchResult.AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0,
    2260           hkMisc + hkCrossLink, miscJobList)
     2247          hkMisc, Integer(miscJobList), True);
    22612248    end
    2262     else if { (h<>hMAIN) and } (h <> PrevHandle) then
     2249    else if { (h<>hMAIN) and } (H <> PrevHandle) then
    22632250    begin
    2264       s := HelpText.LookupByHandle(h);
    2265       p := Pos('$', s);
    2266       if p > 0 then
     2251      S := HelpText.LookupByHandle(H);
     2252      P := Pos('$', S);
     2253      if P > 0 then
    22672254      begin
    2268         s := Copy(s, p + 1, maxint);
    2269         p := Pos('\', s);
    2270         if p > 0 then
    2271           s := Copy(s, 1, p - 1);
    2272         SearchResult.AddLine(s, pkNormal, 0, hkText + hkCrossLink, h);
     2255        S := Copy(S, P + 1, MaxInt);
     2256        P := Pos('\', S);
     2257        if P > 0 then
     2258          S := Copy(S, 1, P - 1);
     2259        SearchResult.AddLine(S, pkNormal, 0, hkText, H, True);
    22732260      end;
    22742261    end;
    2275     until False;
    2276 
    2277     // cut lines to fit to window
    2278     RightMargin := InnerWidth - 16 - DpiGetSystemMetrics(SM_CXVSCROLL);
    2279     OffScreen.Canvas.Font.Assign(UniFont[ftNormal]);
    2280     for i := 0 to SearchResult.Count - 1 do
    2281     begin
    2282       while BiColorTextWidth(OffScreen.Canvas, SearchResult[i]) >
    2283         RightMargin - 32 do
    2284         SearchResult[i] := copy(SearchResult[i], 1, length(SearchResult[i]) - 1)
    2285     end;
    2286   end;
     2262  until False;
     2263
     2264  // Cut lines to fit to window
     2265  RightMargin := InnerWidth - 16 - DpiGetSystemMetrics(SM_CXVSCROLL);
     2266  OffScreen.Canvas.Font.Assign(UniFont[ftNormal]);
     2267  for I := 0 to SearchResult.Count - 1 do
     2268  begin
     2269    while BiColorTextWidth(OffScreen.Canvas, SearchResult[I]) >
     2270      RightMargin - 32 do
     2271      SearchResult[I] := Copy(SearchResult[I], 1, Length(SearchResult[I]) - 1)
     2272  end;
     2273end;
    22872274
    22882275end.
  • TabularUnified branches/highdpi/LocalPlayer/IsoEngine.pas

    r405 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, ScreenTools, Tribes,
    8   LCLIntf, LCLType, SysUtils, Classes, Graphics, UPixelPointer, UGraphicSet;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, Tribes, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, PixelPointer, GraphicSet;
    99
    1010const
     
    1313
    1414type
    15   TInitEnemyModelEvent = function(emix: integer): boolean;
     15  TInitEnemyModelEvent = function(emix: Integer): Boolean;
    1616  TTileSize = (tsSmall, tsMedium, tsBig);
    1717
     
    3333      Dirx: array [0..7] of Integer = (1, 2, 1, 0, -1, -2, -1, 0);
    3434      Diry: array [0..7] of Integer = (-1, 0, 1, 2, 1, 0, -1, -2);
    35     procedure CityGrid(xm, ym: integer; CityAllowClick: Boolean);
    36     function IsShoreTile(Loc: integer): boolean;
     35    procedure CityGrid(xm, ym: Integer; CityAllowClick: Boolean);
     36    function IsShoreTile(Loc: Integer): Boolean;
    3737    procedure MakeDark(Line: PPixelPointer; Length: Integer);
    3838    procedure SetTileSize(AValue: TTileSize);
    39     procedure ShadeOutside(x0, y0, Width, Height, xm, ym: integer);
     39    procedure ShadeOutside(x0, y0, Width, Height, xm, ym: Integer);
    4040  protected
    4141    FOutput: TDpiBitmap;
     
    6565    ShowDebug: Boolean;
    6666    FoW: Boolean;
    67     function Connection4(Loc, Mask, Value: integer): integer;
    68     function Connection8(Loc, Mask: integer): integer;
    69     function OceanConnection(Loc: integer): integer;
    70     procedure PaintShore(x, y, Loc: integer);
    71     procedure PaintTileExtraTerrain(x, y, Loc: integer);
    72     procedure PaintTileObjects(x, y, Loc, CityLoc, CityOwner: integer;
    73       UseBlink: boolean);
    74     procedure PaintGrid(x, y, nx, ny: integer);
    75     procedure FillRect(x, y, Width, Height, Color: integer);
    76     procedure Textout(x, y, Color: integer; const s: string);
    77     procedure Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
    78     procedure TSprite(xDst, yDst, grix: integer; PureBlack: boolean = false);
     67    function Connection4(Loc, Mask, Value: Integer): Integer;
     68    function Connection8(Loc, Mask: Integer): Integer;
     69    function OceanConnection(Loc: Integer): Integer;
     70    procedure PaintShore(X, Y, Loc: Integer);
     71    procedure PaintTileExtraTerrain(X, Y, Loc: Integer);
     72    procedure PaintTileObjects(X, Y, Loc, CityLoc, CityOwner: Integer;
     73      UseBlink: Boolean);
     74    procedure PaintGrid(X, Y, nx, ny: Integer);
     75    procedure FillRect(X, Y, Width, Height, Color: Integer);
     76    procedure Textout(X, Y, Color: Integer; const S: string);
     77    procedure Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
     78    procedure TSprite(xDst, yDst, grix: Integer; PureBlack: Boolean = False);
    7979    procedure ApplyTileSize(ATileSize: TTileSize);
    8080  public
     
    8989    procedure Reset;
    9090    procedure SetOutput(Output: TDpiBitmap);
    91     procedure SetPaintBounds(Left, Top, Right, Bottom: integer);
    92     procedure Paint(x, y, Loc, nx, ny, CityLoc, CityOwner: integer;
    93       UseBlink: boolean = false; CityAllowClick: boolean = false);
    94     procedure PaintUnit(x, y: integer; const UnitInfo: TUnitInfo;
    95       Status: integer);
    96     procedure PaintCity(x, y: integer; const CityInfo: TCityInfo;
    97       accessory: boolean = true);
    98     procedure BitBltBitmap(Src: TDpiBitmap; x, y, Width, Height, xSrc, ySrc,
    99       Rop: integer);
     91    procedure SetPaintBounds(Left, Top, Right, Bottom: Integer);
     92    procedure Paint(X, Y, Loc, nx, ny, CityLoc, CityOwner: Integer;
     93      UseBlink: Boolean = False; CityAllowClick: Boolean = False);
     94    procedure PaintUnit(X, Y: Integer; const UnitInfo: TUnitInfo;
     95      Status: Integer);
     96    procedure PaintCity(X, Y: Integer; const CityInfo: TCityInfo;
     97      accessory: Boolean = True);
     98    procedure BitBltBitmap(Src: TDpiBitmap; X, Y, Width, Height, xSrc, ySrc,
     99      Rop: Integer);
    100100    procedure AttackBegin(const ShowMove: TShowMove);
    101101    procedure AttackEffect(const ShowMove: TShowMove);
    102102    procedure AttackEnd;
    103103    procedure ReduceTerrainIconsSize;
    104     property AdviceLoc: integer read FAdviceLoc write FAdviceLoc;
     104    property AdviceLoc: Integer read FAdviceLoc write FAdviceLoc;
    105105    property TileSize: TTileSize read FTileSize write SetTileSize;
    106106  end;
     
    127127    (X: 72; Y: 36));
    128128
    129 function IsJungle(y: integer): boolean;
     129function IsJungle(Y: Integer): Boolean;
    130130procedure Init(InitEnemyModelHandler: TInitEnemyModelEvent);
    131131
     
    173173  IsoMapCache: array[TTileSize] of TIsoMapCache;
    174174
    175 function IsJungle(y: integer): boolean;
    176 begin
    177   result := (y > (G.ly - 2) div 4) and (G.ly - 1 - y > (G.ly - 2) div 4)
     175function IsJungle(Y: Integer): Boolean;
     176begin
     177  Result := (Y > (G.ly - 2) div 4) and (G.ly - 1 - Y > (G.ly - 2) div 4)
    178178end;
    179179
     
    254254  Mask24.BeginUpdate;
    255255  for ySrc := 0 to TerrainIconLines - 1 do begin
    256     for i := 0 to yyt * 3 - 1 do
    257       MaskLine[i] := PixelPointer(Mask24, ScaleToNative(0),
    258         ScaleToNative(1 + ySrc * (yyt * 3 + 1) + i));
     256    for I := 0 to yyt * 3 - 1 do
     257      MaskLine[I] := TPixelPointer.Create(Mask24, ScaleToNative(0),
     258        ScaleToNative(1 + ySrc * (yyt * 3 + 1) + I));
    259259    for xSrc := 0 to TerrainIconCols - 1 do begin
    260       i := ySrc * 9 + xSrc;
    261       TSpriteSize[i].Left := 0;
     260      I := ySrc * 9 + xSrc;
     261      TSpriteSize[I].Left := 0;
    262262      repeat
    263         Border := true;
    264         for y := 0 to yyt * 3 - 1 do begin
    265           MaskLine[y].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + TSpriteSize[i].Left));
    266           if MaskLine[y].Pixel^.B = 0 then Border := false;
     263        Border := True;
     264        for Y := 0 to yyt * 3 - 1 do begin
     265          MaskLine[Y].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + TSpriteSize[I].Left));
     266          if MaskLine[Y].Pixel^.B = 0 then Border := False;
    267267        end;
    268         if Border then Inc(TSpriteSize[i].Left);
    269       until not Border or (TSpriteSize[i].Left = xxt * 2 - 1);
    270       TSpriteSize[i].Top := 0;
     268        if Border then Inc(TSpriteSize[I].Left);
     269      until not Border or (TSpriteSize[I].Left = xxt * 2 - 1);
     270      TSpriteSize[I].Top := 0;
    271271      repeat
    272         Border := true;
    273         for x := 0 to xxt * 2 - 1 do begin
    274           MaskLine[TSpriteSize[i].Top].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + x));
    275           if MaskLine[TSpriteSize[i].Top].Pixel^.B = 0 then Border := false;
     272        Border := True;
     273        for X := 0 to xxt * 2 - 1 do begin
     274          MaskLine[TSpriteSize[I].Top].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + X));
     275          if MaskLine[TSpriteSize[I].Top].Pixel^.B = 0 then Border := False;
    276276        end;
    277         if Border then inc(TSpriteSize[i].Top);
    278       until not Border or (TSpriteSize[i].Top = yyt * 3 - 1);
    279       TSpriteSize[i].Right := xxt * 2;
     277        if Border then Inc(TSpriteSize[I].Top);
     278      until not Border or (TSpriteSize[I].Top = yyt * 3 - 1);
     279      TSpriteSize[I].Right := xxt * 2;
    280280      repeat
    281         Border := true;
    282         for y := 0 to yyt * 3 - 1 do begin
    283           MaskLine[y].SetX(ScaleToNative(xSrc * (xxt * 2 + 1) + TSpriteSize[i].Right));
    284           if MaskLine[y].Pixel^.B = 0 then Border := false;
     281        Border := True;
     282        for Y := 0 to yyt * 3 - 1 do begin
     283          MaskLine[Y].SetX(ScaleToNative(xSrc * (xxt * 2 + 1) + TSpriteSize[I].Right));
     284          if MaskLine[Y].Pixel^.B = 0 then Border := False;
    285285        end;
    286         if Border then Dec(TSpriteSize[i].Right);
    287       until not Border or (TSpriteSize[i].Right = TSpriteSize[i].Left);
    288       TSpriteSize[i].Bottom := yyt * 3;
     286        if Border then Dec(TSpriteSize[I].Right);
     287      until not Border or (TSpriteSize[I].Right = TSpriteSize[I].Left);
     288      TSpriteSize[I].Bottom := yyt * 3;
    289289      repeat
    290         Border := true;
    291         for x := 0 to xxt * 2 - 1 do begin
    292           MaskLine[TSpriteSize[i].Bottom - 1].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + x));
    293           if MaskLine[TSpriteSize[i].Bottom - 1].Pixel^.B = 0 then Border := false;
     290        Border := True;
     291        for X := 0 to xxt * 2 - 1 do begin
     292          MaskLine[TSpriteSize[I].Bottom - 1].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + X));
     293          if MaskLine[TSpriteSize[I].Bottom - 1].Pixel^.B = 0 then Border := False;
    294294        end;
    295         if Border then Dec(TSpriteSize[i].Bottom);
    296       until not Border or (TSpriteSize[i].Bottom = TSpriteSize[i].Top);
     295        if Border then Dec(TSpriteSize[I].Bottom);
     296      until not Border or (TSpriteSize[I].Bottom = TSpriteSize[I].Top);
    297297    end;
    298298  end;
     
    303303procedure TIsoMap.ApplyTileSize(ATileSize: TTileSize);
    304304var
    305   x: Integer;
    306   y: Integer;
     305  X: Integer;
     306  Y: Integer;
    307307  xSrc: Integer;
    308308  ySrc: Integer;
     
    357357  DitherMask.SetSize(xxt * 2, yyt * 2);
    358358  DitherMask.Canvas.FillRect(0, 0, DitherMask.Width, DitherMask.Height);
    359   DpiBitCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
     359  DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
    360360    HGrTerrain.Mask.Canvas, 1 + 7 * (xxt * 2 + 1),
    361361    1 + yyt + 15 * (yyt * 3 + 1), SRCAND);
    362362
    363   for x := -1 to 6 do begin
    364     if x = -1 then begin
     363  for X := -1 to 6 do begin
     364    if X = -1 then begin
    365365      xSrc := ShoreDither * (xxt * 2 + 1) + 1;
    366366      ySrc := 1 + yyt;
    367367    end
    368     else if x = 6 then begin
     368    else if X = 6 then begin
    369369      xSrc := 1 + (xxt * 2 + 1) * 2;
    370370      ySrc := 1 + yyt + (yyt * 3 + 1) * 2;
    371371    end else begin
    372       xSrc := (x + 2) * (xxt * 2 + 1) + 1;
     372      xSrc := (X + 2) * (xxt * 2 + 1) + 1;
    373373      ySrc := 1 + yyt;
    374374    end;
    375     for y := -1 to 6 do
    376       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     375    for Y := -1 to 6 do
     376      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt,
    377377        xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc);
    378     for y := -2 to 6 do
    379       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt,
     378    for Y := -2 to 6 do
     379      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, xxt,
    380380        yyt, HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt,
    381381        SRCPAINT);
    382     for y := -2 to 6 do
    383       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2) + xxt, (y + 2) * yyt,
     382    for Y := -2 to 6 do
     383      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2) + xxt, (Y + 2) * yyt,
    384384        xxt, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc + yyt,
    385385        SRCPAINT);
    386     for y := -2 to 6 do
    387       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt,
     386    for Y := -2 to 6 do
     387      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, xxt,
    388388        yyt, DitherMask.Canvas, xxt, yyt, SRCAND);
    389     for y := -2 to 6 do
    390       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2) + xxt, (y + 2) * yyt,
     389    for Y := -2 to 6 do
     390      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2) + xxt, (Y + 2) * yyt,
    391391        xxt, yyt, DitherMask.Canvas, 0, yyt, SRCAND);
    392392  end;
    393393
    394   for y := -1 to 6 do begin
    395     if y = -1 then begin
     394  for Y := -1 to 6 do begin
     395    if Y = -1 then begin
    396396      xSrc := ShoreDither * (xxt * 2 + 1) + 1;
    397397      ySrc := 1 + yyt;
    398398    end
    399     else if y = 6 then begin
     399    else if Y = 6 then begin
    400400      xSrc := 1 + 2 * (xxt * 2 + 1);
    401401      ySrc := 1 + yyt + 2 * (yyt * 3 + 1);
    402402    end else begin
    403       xSrc := (y + 2) * (xxt * 2 + 1) + 1;
     403      xSrc := (Y + 2) * (xxt * 2 + 1) + 1;
    404404      ySrc := 1 + yyt;
    405405    end;
    406     for x := -2 to 6 do
    407       DpiBitCanvas(LandMore.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     406    for X := -2 to 6 do
     407      DpiBitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt,
    408408        xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc);
    409     DpiBitCanvas(LandMore.Canvas, xxt * 2, (y + 2) * yyt, xxt, yyt,
     409    DpiBitBltCanvas(LandMore.Canvas, xxt * 2, (Y + 2) * yyt, xxt, yyt,
    410410      HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt, SRCPAINT);
    411     for x := 0 to 7 do
    412       DpiBitCanvas(LandMore.Canvas, (x + 2) * (xxt * 2) - xxt, (y + 2) * yyt,
     411    for X := 0 to 7 do
     412      DpiBitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2) - xxt, (Y + 2) * yyt,
    413413        xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc + yyt,
    414414        SRCPAINT);
    415     for x := -2 to 6 do
    416       DpiBitCanvas(LandMore.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     415    for X := -2 to 6 do
     416      DpiBitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt,
    417417        xxt * 2, yyt, DitherMask.Canvas, 0, 0, SRCAND);
    418418  end;
    419419
    420   for x := 0 to 3 do begin
    421     for y := 0 to 3 do begin
    422       if (x = 1) and (y = 1) then xSrc := 1
     420  for X := 0 to 3 do begin
     421    for Y := 0 to 3 do begin
     422      if (X = 1) and (Y = 1) then xSrc := 1
    423423      else
    424         xSrc := (x mod 2) * (xxt * 2 + 1) + 1;
     424        xSrc := (X mod 2) * (xxt * 2 + 1) + 1;
    425425      ySrc := 1 + yyt;
    426       if (x >= 1) = (y >= 2) then
    427         DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     426      if (X >= 1) = (Y >= 2) then
     427        DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt,
    428428          HGrTerrain.Data.Canvas, xSrc, ySrc);
    429       if (x >= 1) and ((y < 2) or (x >= 2)) then
     429      if (X >= 1) and ((Y < 2) or (X >= 2)) then
    430430      begin
    431         DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt, yyt,
     431        DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt,
    432432          HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt,
    433433          SRCPAINT);
    434         DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2) + xxt, y * yyt, xxt, yyt,
     434        DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt,
    435435          HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, SRCPAINT);
    436436      end;
    437       DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt, yyt,
     437      DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt,
    438438        DitherMask.Canvas, xxt, yyt, SRCAND);
    439       DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2) + xxt, y * yyt, xxt, yyt,
     439      DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt,
    440440        DitherMask.Canvas, 0, yyt, SRCAND);
    441441    end;
    442442  end;
    443443
    444   for y := 0 to 3 do begin
    445     for x := 0 to 3 do begin
    446       if (x = 1) and (y = 1) then xSrc := 1
     444  for Y := 0 to 3 do begin
     445    for X := 0 to 3 do begin
     446      if (X = 1) and (Y = 1) then xSrc := 1
    447447      else
    448         xSrc := (y mod 2) * (xxt * 2 + 1) + 1;
     448        xSrc := (Y mod 2) * (xxt * 2 + 1) + 1;
    449449      ySrc := 1 + yyt;
    450       if (x < 1) or (y >= 2) then
    451         DpiBitCanvas(OceanMore.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     450      if (X < 1) or (Y >= 2) then
     451        DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt,
    452452          HGrTerrain.Data.Canvas, xSrc, ySrc);
    453       if (x = 1) and (y < 2) or (x >= 2) and (y >= 1) then
     453      if (X = 1) and (Y < 2) or (X >= 2) and (Y >= 1) then
    454454      begin
    455         DpiBitCanvas(OceanMore.Canvas, x * (xxt * 2), y * yyt, xxt, yyt,
     455        DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt,
    456456          HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt,
    457457          SRCPAINT);
    458         DpiBitCanvas(OceanMore.Canvas, x * (xxt * 2) + xxt, y * yyt, xxt, yyt,
     458        DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt,
    459459          HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, SRCPAINT);
    460460      end;
    461       DpiBitCanvas(OceanMore.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     461      DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt,
    462462        DitherMask.Canvas, 0, 0, SRCAND);
    463463    end;
    464464  end;
    465465
    466   DpiBitCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
     466  DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
    467467    DitherMask.Canvas, 0, 0, DSTINVERT); { invert dither mask }
    468   DpiBitCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
     468  DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
    469469    HGrTerrain.Mask.Canvas, 1, 1 + yyt, SRCPAINT);
    470470
    471   for x := -1 to 6 do
    472     for y := -2 to 6 do
    473       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     471  for X := -1 to 6 do
     472    for Y := -2 to 6 do
     473      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt,
    474474        xxt * 2, yyt, DitherMask.Canvas, 0, 0, SRCAND);
    475475
    476   for y := -1 to 6 do
    477     for x := -2 to 7 do
    478       DpiBitCanvas(LandMore.Canvas, (x + 2) * (xxt * 2) - xxt, (y + 2) * yyt,
     476  for Y := -1 to 6 do
     477    for X := -2 to 7 do
     478      DpiBitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2) - xxt, (Y + 2) * yyt,
    479479        xxt * 2, yyt, DitherMask.Canvas, 0, yyt, SRCAND);
    480480
    481   DpiBitCanvas(LandPatch.Canvas, 0, 0, (xxt * 2) * 9, yyt * 9,
     481  DpiBitBltCanvas(LandPatch.Canvas, 0, 0, (xxt * 2) * 9, yyt * 9,
    482482    LandMore.Canvas, 0, 0, SRCPAINT);
    483483
    484   for x := 0 to 3 do
    485     for y := 0 to 3 do
    486       DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     484  for X := 0 to 3 do
     485    for Y := 0 to 3 do
     486      DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt,
    487487        DitherMask.Canvas, 0, 0, SRCAND);
    488488
    489   for y := 0 to 3 do
    490     for x := 0 to 4 do
    491       DpiBitCanvas(OceanMore.Canvas, x * (xxt * 2) - xxt, y * yyt, xxt * 2,
     489  for Y := 0 to 3 do
     490    for X := 0 to 4 do
     491      DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2) - xxt, Y * yyt, xxt * 2,
    492492        yyt, DitherMask.Canvas, 0, yyt, SRCAND);
    493493
    494   DpiBitCanvas(OceanPatch.Canvas, 0, 0, (xxt * 2) * 4, yyt * 4,
     494  DpiBitBltCanvas(OceanPatch.Canvas, 0, 0, (xxt * 2) * 4, yyt * 4,
    495495    OceanMore.Canvas, 0, 0, SRCPAINT);
    496496
     
    499499    FillRect(Rect(0, 0, xxt * 2, yyt));
    500500  end;
    501   DpiBitCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt,
     501  DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt,
    502502    HGrTerrain.Mask.Canvas, 1, 1 + yyt);
    503503
    504   for x := 0 to 6 do
    505     DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), yyt, xxt * 2, yyt,
     504  for X := 0 to 6 do
     505    DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), yyt, xxt * 2, yyt,
    506506      DitherMask.Canvas, 0, 0, SRCAND);
    507   DpiBitCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt, DitherMask.Canvas,
     507  DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt, DitherMask.Canvas,
    508508    0, 0, DSTINVERT);
    509509
    510   for y := 0 to 6 do
    511     DpiBitCanvas(LandPatch.Canvas, xxt * 2, (y + 2) * yyt, xxt * 2, yyt,
     510  for Y := 0 to 6 do
     511    DpiBitBltCanvas(LandPatch.Canvas, xxt * 2, (Y + 2) * yyt, xxt * 2, yyt,
    512512      DitherMask.Canvas, 0, 0, SRCAND);
    513513
     
    555555end;
    556556
    557 procedure TIsoMap.SetPaintBounds(Left, Top, Right, Bottom: integer);
     557procedure TIsoMap.SetPaintBounds(Left, Top, Right, Bottom: Integer);
    558558begin
    559559  FLeft := Left;
     
    563563end;
    564564
    565 procedure TIsoMap.FillRect(x, y, Width, Height, Color: integer);
    566 begin
    567   if x < FLeft then
    568   begin
    569     Width := Width - (FLeft - x);
    570     x := FLeft;
    571   end;
    572   if y < FTop then
    573   begin
    574     Height := Height - (FTop - y);
    575     y := FTop;
    576   end;
    577   if x + Width >= FRight then
    578     Width := FRight - x;
    579   if y + Height >= FBottom then
    580     Height := FBottom - y;
     565procedure TIsoMap.FillRect(X, Y, Width, Height, Color: Integer);
     566begin
     567  if X < FLeft then
     568  begin
     569    Width := Width - (FLeft - X);
     570    X := FLeft;
     571  end;
     572  if Y < FTop then
     573  begin
     574    Height := Height - (FTop - Y);
     575    Y := FTop;
     576  end;
     577  if X + Width >= FRight then
     578    Width := FRight - X;
     579  if Y + Height >= FBottom then
     580    Height := FBottom - Y;
    581581  if (Width <= 0) or (Height <= 0) then
    582     exit;
     582    Exit;
    583583
    584584  FOutput.Canvas.Brush.Color := Color;
    585   FOutput.Canvas.FillRect(Rect(x, y, x + Width, y + Height));
     585  FOutput.Canvas.FillRect(Rect(X, Y, X + Width, Y + Height));
    586586  FOutput.Canvas.Brush.Style := bsClear;
    587587end;
    588588
    589 procedure TIsoMap.Textout(x, y, Color: integer; const s: string);
     589procedure TIsoMap.Textout(X, Y, Color: Integer; const S: string);
    590590begin
    591591  FOutput.Canvas.Font.Color := Color;
    592   FOutput.Canvas.TextRect(Rect(FLeft, FTop, FRight, FBottom), x, y, s)
    593 end;
    594 
    595 procedure TIsoMap.BitBltBitmap(Src: TDpiBitmap; x, y, Width, Height, xSrc, ySrc,
    596   Rop: integer);
    597 begin
    598   if x < FLeft then
    599   begin
    600     Width := Width - (FLeft - x);
    601     xSrc := xSrc + (FLeft - x);
    602     x := FLeft;
    603   end;
    604   if y < FTop then
    605   begin
    606     Height := Height - (FTop - y);
    607     ySrc := ySrc + (FTop - y);
    608     y := FTop;
    609   end;
    610   if x + Width >= FRight then
    611     Width := FRight - x;
    612   if y + Height >= FBottom then
    613     Height := FBottom - y;
     592  FOutput.Canvas.TextRect(Rect(FLeft, FTop, FRight, FBottom), X, Y, S)
     593end;
     594
     595procedure TIsoMap.BitBltBitmap(Src: TDpiBitmap; X, Y, Width, Height, xSrc, ySrc,
     596  Rop: Integer);
     597begin
     598  if X < FLeft then
     599  begin
     600    Width := Width - (FLeft - X);
     601    xSrc := xSrc + (FLeft - X);
     602    X := FLeft;
     603  end;
     604  if Y < FTop then
     605  begin
     606    Height := Height - (FTop - Y);
     607    ySrc := ySrc + (FTop - Y);
     608    Y := FTop;
     609  end;
     610  if X + Width >= FRight then
     611    Width := FRight - X;
     612  if Y + Height >= FBottom then
     613    Height := FBottom - Y;
    614614  if (Width <= 0) or (Height <= 0) then
    615     exit;
    616 
    617   DpiBitCanvas(FOutput.Canvas, x, y, Width, Height, Src.Canvas, xSrc, ySrc, Rop);
    618 end;
    619 
    620 procedure TIsoMap.Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     615    Exit;
     616
     617  DpiBitBltCanvas(FOutput.Canvas, X, Y, Width, Height, Src.Canvas, xSrc, ySrc, Rop);
     618end;
     619
     620procedure TIsoMap.Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
    621621begin
    622622  BitBltBitmap(HGr.Mask, xDst, yDst, Width, Height, xGr, yGr, SRCAND);
     
    624624end;
    625625
    626 procedure TIsoMap.TSprite(xDst, yDst, grix: integer;
    627   PureBlack: boolean = false);
     626procedure TIsoMap.TSprite(xDst, yDst, grix: Integer;
     627  PureBlack: Boolean = False);
    628628var
    629629  Width: Integer;
    630630  Height: Integer;
    631631  xSrc: Integer;
    632   ySrc: integer;
     632  ySrc: Integer;
    633633begin
    634634  Width := TSpriteSize[grix].Right - TSpriteSize[grix].Left;
     
    653653    Height := FBottom - yDst;
    654654  if (Width <= 0) or (Height <= 0) then
    655     exit;
    656 
    657   DpiBitCanvas(FOutput.Canvas, xDst, yDst, Width, Height, MaskCanvas, xSrc, ySrc, SRCAND);
     655    Exit;
     656
     657  DpiBitBltCanvas(FOutput.Canvas, xDst, yDst, Width, Height, MaskCanvas, xSrc, ySrc, SRCAND);
    658658  if not PureBlack then
    659     DpiBitCanvas(FOutput.Canvas, xDst, yDst, Width, Height, DataCanvas, xSrc, ySrc, SRCPAINT);
    660 end;
    661 
    662 procedure TIsoMap.PaintUnit(x, y: integer; const UnitInfo: TUnitInfo;
    663   Status: integer);
    664 var
    665   xsh, ysh, xGr, yGr, j, mixShow: integer;
     659    DpiBitBltCanvas(FOutput.Canvas, xDst, yDst, Width, Height, DataCanvas, xSrc, ySrc, SRCPAINT);
     660end;
     661
     662procedure TIsoMap.PaintUnit(X, Y: Integer; const UnitInfo: TUnitInfo;
     663  Status: Integer);
     664var
     665  xsh, ysh, xGr, yGr, J, mixShow: Integer;
    666666begin
    667667  with UnitInfo do
    668     if (Owner = me) or (emix <> $FFFF) then
     668    if (Owner = Me) or (emix <> $FFFF) then
    669669    begin
    670670      if Job = jCity then
     
    675675        (@OnInitEnemyModel <> nil) then
    676676        if not OnInitEnemyModel(emix) then
    677           exit;
     677          Exit;
    678678      xsh := Tribe[Owner].ModelPicture[mixShow].xShield;
    679679      ysh := Tribe[Owner].ModelPicture[mixShow].yShield;
    680680{$IFNDEF SCR} if Status and usStay <> 0 then
    681         j := 19
     681        J := 19
    682682      else if Status and usRecover <> 0 then
    683         j := 16
     683        J := 16
    684684      else if Status and (usGoto or usEnhance) = usGoto or usEnhance then
    685         j := 18
     685        J := 18
    686686      else if Status and usEnhance <> 0 then
    687         j := 17
     687        J := 17
    688688      else if Status and usGoto <> 0 then
    689         j := 20
     689        J := 20
    690690      else {$ENDIF} if Job = jCity then
    691           j := jNone
     691          J := jNone
    692692        else
    693           j := Job;
     693          J := Job;
    694694      if Flags and unMulti <> 0 then
    695         Sprite(Tribe[Owner].symHGr, x + xsh - 1 + 4, y + ysh - 2, 14, 12,
     695        Sprite(Tribe[Owner].symHGr, X + xsh - 1 + 4, Y + ysh - 2, 14, 12,
    696696          33 + Tribe[Owner].sympix mod 10 * 65,
    697697          1 + Tribe[Owner].sympix div 10 * 49);
    698       Sprite(Tribe[Owner].symHGr, x + xsh - 1, y + ysh - 2, 14, 12,
     698      Sprite(Tribe[Owner].symHGr, X + xsh - 1, Y + ysh - 2, 14, 12,
    699699        18 + Tribe[Owner].sympix mod 10 * 65,
    700700        1 + Tribe[Owner].sympix div 10 * 49);
    701       FillRect(x + xsh, y + ysh + 5, 1 + Health * 11 div 100, 3,
     701      FillRect(X + xsh, Y + ysh + 5, 1 + Health * 11 div 100, 3,
    702702        ColorOfHealth(Health));
    703       if j > 0 then
     703      if J > 0 then
    704704      begin
    705         xGr := 121 + j mod 7 * 9;
    706         yGr := 1 + j div 7 * 9;
    707         BitBltBitmap(HGrSystem.Mask, x + xsh + 3, y + ysh + 9, 8, 8, xGr,
     705        xGr := 121 + J mod 7 * 9;
     706        yGr := 1 + J div 7 * 9;
     707        BitBltBitmap(HGrSystem.Mask, X + xsh + 3, Y + ysh + 9, 8, 8, xGr,
    708708          yGr, SRCAND);
    709         Sprite(HGrSystem, x + xsh + 2, y + ysh + 8, 8, 8, xGr, yGr);
     709        Sprite(HGrSystem, X + xsh + 2, Y + ysh + 8, 8, 8, xGr, yGr);
    710710      end;
    711711      with Tribe[Owner].ModelPicture[mixShow] do
    712         Sprite(HGr, x, y, 64, 48, pix mod 10 * 65 + 1, pix div 10 * 49 + 1);
     712        Sprite(HGr, X, Y, 64, 48, pix mod 10 * 65 + 1, pix div 10 * 49 + 1);
    713713      if Flags and unFortified <> 0 then
    714714      begin
    715715        { DataCanvas:=HGrTerrain.Data.Canvas;
    716716          MaskCanvas:=HGrTerrain.Mask.Canvas;
    717           TSprite(x,y+16,12*9+7); }
    718         Sprite(HGrStdUnits, x, y, xxu * 2, yyu * 2, 1 + 6 * (xxu * 2 + 1), 1);
     717          TSprite(X,Y+16,12*9+7); }
     718        Sprite(HGrStdUnits, X, Y, xxu * 2, yyu * 2, 1 + 6 * (xxu * 2 + 1), 1);
    719719      end;
    720720    end;
    721 end; { PaintUnit }
    722 
    723 procedure TIsoMap.PaintCity(x, y: integer; const CityInfo: TCityInfo;
    724   accessory: boolean);
     721end;
     722
     723procedure TIsoMap.PaintCity(X, Y: Integer; const CityInfo: TCityInfo;
     724  accessory: Boolean);
    725725var
    726726  age: Integer;
     
    733733  LabelLength: Integer;
    734734  cpic: TCityPicture;
    735   s: string;
     735  S: string;
    736736begin
    737737  age := GetAge(CityInfo.Owner);
     
    752752      (cHGr.Data.Canvas.Pixels[(xGr + 4) * 65, cpix * 49 + 48] = $00FFFF)
    753753    then
    754       Sprite(cHGr, x - xxc, y - 2 * yyc, xxc * 2, yyc * 3,
     754      Sprite(cHGr, X - xxc, Y - 2 * yyc, xxc * 2, yyc * 3,
    755755        xGr * (xxc * 2 + 1) + 1, 1 + cpix * (yyc * 3 + 1));
    756756    if ciWalled and CityInfo.Flags <> 0 then
    757       Sprite(cHGr, x - xxc, y - 2 * yyc, xxc * 2, yyc * 3,
     757      Sprite(cHGr, X - xxc, Y - 2 * yyc, xxc * 2, yyc * 3,
    758758        (xGr + 4) * (xxc * 2 + 1) + 1, 1 + cpix * (yyc * 3 + 1));
    759759  end
     
    761761  begin
    762762    if ciWalled and CityInfo.Flags <> 0 then
    763       Sprite(HGrCities, x - xxt, y - 2 * yyt, 2 * xxt, 3 * yyt,
     763      Sprite(HGrCities, X - xxt, Y - 2 * yyt, 2 * xxt, 3 * yyt,
    764764        (xGr + 4) * (2 * xxt + 1) + 1, 1 + (age - 2) * (3 * yyt + 1))
    765765    else
    766       Sprite(HGrCities, x - xxt, y - 2 * yyt, 2 * xxt, 3 * yyt,
     766      Sprite(HGrCities, X - xxt, Y - 2 * yyt, 2 * xxt, 3 * yyt,
    767767        xGr * (2 * xxt + 1) + 1, 1 + (age - 2) * (3 * yyt + 1));
    768768  end;
    769769
    770770  if not accessory then
    771     exit;
     771    Exit;
    772772
    773773  { if ciCapital and CityInfo.Flags<>0 then
    774     Sprite(Tribe[CityInfo.Owner].symHGr,x+cpic.xf,y-13+cpic.yf,13,14,
     774    Sprite(Tribe[CityInfo.Owner].symHGr,X+cpic.xf,Y-13+cpic.yf,13,14,
    775775    1+Tribe[CityInfo.Owner].sympix mod 10 *65,
    776776    1+Tribe[CityInfo.Owner].sympix div 10 *49); {capital -- paint flag }
     
    781781    begin
    782782      cpic := Tribe[CityInfo.Owner].CityPicture[xGr];
    783       xShield := x - xxc + cpic.xShield;
    784       yShield := y - 2 * yyc + cpic.yShield;
     783      xShield := X - xxc + cpic.xShield;
     784      yShield := Y - 2 * yyc + cpic.yShield;
    785785    end
    786786    else
    787787    begin
    788788      cpic := CitiesPictures.Pictures[age, xGr];
    789       xShield := x - xxt + cpic.xShield;
    790       yShield := y - 2 * yyt + cpic.yShield;
     789      xShield := X - xxt + cpic.xShield;
     790      yShield := Y - 2 * yyt + cpic.yShield;
    791791    end;
    792     s := IntToStr(CityInfo.size);
    793     LabelLength := FOutput.Canvas.TextWidth(s);
     792    S := IntToStr(CityInfo.size);
     793    LabelLength := FOutput.Canvas.TextWidth(S);
    794794    FillRect(xShield, yShield, LabelLength + 4, 16, $000000);
    795795    if MyMap[CityInfo.Loc] and (fUnit or fObserved) = fObserved then
     
    802802      LabelTextColor := $000000;
    803803    end;
    804     Textout(xShield + 2, yShield - 1, LabelTextColor, s);
    805   end;
    806 end; { PaintCity }
    807 
    808 function PoleTile(Loc: integer): integer;
     804    Textout(xShield + 2, yShield - 1, LabelTextColor, S);
     805  end;
     806end;
     807
     808function PoleTile(Loc: Integer): Integer;
    809809begin { virtual pole tile }
    810   result := fUNKNOWN;
     810  Result := fUNKNOWN;
    811811  if Loc < -2 * G.lx then
    812812  else if Loc < -G.lx then
     
    815815      (MyMap[dLoc(Loc, -2, 2)] and fTerrain <> fUNKNOWN) and
    816816      (MyMap[dLoc(Loc, 2, 2)] and fTerrain <> fUNKNOWN) then
    817       result := fArctic;
     817      Result := fArctic;
    818818    if (MyMap[dLoc(Loc, 0, 2)] and fObserved <> 0) and
    819819      (MyMap[dLoc(Loc, -2, 2)] and fObserved <> 0) and
    820820      (MyMap[dLoc(Loc, 2, 2)] and fObserved <> 0) then
    821       result := result or fObserved;
     821      Result := Result or fObserved;
    822822  end
    823823  else if Loc < 0 then
     
    825825    if (MyMap[dLoc(Loc, -1, 1)] and fTerrain <> fUNKNOWN) and
    826826      (MyMap[dLoc(Loc, 1, 1)] and fTerrain <> fUNKNOWN) then
    827       result := fArctic;
     827      Result := fArctic;
    828828    if (MyMap[dLoc(Loc, -1, 1)] and fObserved <> 0) and
    829829      (MyMap[dLoc(Loc, 1, 1)] and fObserved <> 0) then
    830       result := result or fObserved;
     830      Result := Result or fObserved;
    831831  end
    832832  else if Loc < G.lx * (G.ly + 1) then
     
    834834    if (MyMap[dLoc(Loc, -1, -1)] and fTerrain <> fUNKNOWN) and
    835835      (MyMap[dLoc(Loc, 1, -1)] and fTerrain <> fUNKNOWN) then
    836       result := fArctic;
     836      Result := fArctic;
    837837    if (MyMap[dLoc(Loc, -1, -1)] and fObserved <> 0) and
    838838      (MyMap[dLoc(Loc, 1, -1)] and fObserved <> 0) then
    839       result := result or fObserved;
     839      Result := Result or fObserved;
    840840  end
    841841  else if Loc < G.lx * (G.ly + 2) then
     
    844844      (MyMap[dLoc(Loc, -2, -2)] and fTerrain <> fUNKNOWN) and
    845845      (MyMap[dLoc(Loc, 2, -2)] and fTerrain <> fUNKNOWN) then
    846       result := fArctic;
     846      Result := fArctic;
    847847    if (MyMap[dLoc(Loc, 0, -2)] and fObserved <> 0) and
    848848      (MyMap[dLoc(Loc, -2, -2)] and fObserved <> 0) and
    849849      (MyMap[dLoc(Loc, 2, -2)] and fObserved <> 0) then
    850       result := result or fObserved;
    851   end;
    852 end;
    853 
    854 function TIsoMap.Connection4(Loc, Mask, Value: integer): integer;
    855 begin
    856   result := 0;
     850      Result := Result or fObserved;
     851  end;
     852end;
     853
     854function TIsoMap.Connection4(Loc, Mask, Value: Integer): Integer;
     855begin
     856  Result := 0;
    857857  if dLoc(Loc, 1, -1) >= 0 then
    858858  begin
    859859    if MyMap[dLoc(Loc, 1, -1)] and Mask = Cardinal(Value) then
    860       inc(result, 1);
     860      Inc(Result, 1);
    861861    if MyMap[dLoc(Loc, -1, -1)] and Mask = Cardinal(Value) then
    862       inc(result, 8);
     862      Inc(Result, 8);
    863863  end;
    864864  if dLoc(Loc, 1, 1) < G.lx * G.ly then
    865865  begin
    866866    if MyMap[dLoc(Loc, 1, 1)] and Mask = Cardinal(Value) then
    867       inc(result, 2);
     867      Inc(Result, 2);
    868868    if MyMap[dLoc(Loc, -1, 1)] and Mask = Cardinal(Value) then
    869       inc(result, 4);
    870   end;
    871 end;
    872 
    873 function TIsoMap.Connection8(Loc, Mask: integer): integer;
     869      Inc(Result, 4);
     870  end;
     871end;
     872
     873function TIsoMap.Connection8(Loc, Mask: Integer): Integer;
    874874var
    875875  Dir: Integer;
    876876  ConnLoc: Integer;
    877877begin
    878   result := 0;
     878  Result := 0;
    879879  for Dir := 0 to 7 do
    880880  begin
     
    882882    if (ConnLoc >= 0) and (ConnLoc < G.lx * G.ly) and
    883883      (MyMap[ConnLoc] and Mask <> 0) then
    884       inc(result, 1 shl Dir);
    885   end;
    886 end;
    887 
    888 function TIsoMap.OceanConnection(Loc: integer): integer;
     884      Inc(Result, 1 shl Dir);
     885  end;
     886end;
     887
     888function TIsoMap.OceanConnection(Loc: Integer): Integer;
    889889var
    890890  Dir: Integer;
    891891  ConnLoc: Integer;
    892892begin
    893   result := 0;
     893  Result := 0;
    894894  for Dir := 0 to 7 do
    895895  begin
     
    897897    if (ConnLoc < 0) or (ConnLoc >= G.lx * G.ly) or
    898898      ((MyMap[ConnLoc] - 2) and fTerrain < 13) then
    899       inc(result, 1 shl Dir);
    900   end;
    901 end;
    902 
    903 procedure TIsoMap.PaintShore(x, y, Loc: integer);
     899      Inc(Result, 1 shl Dir);
     900  end;
     901end;
     902
     903procedure TIsoMap.PaintShore(X, Y, Loc: Integer);
    904904var
    905905  Conn: Integer;
    906906  Tile: Integer;
    907907begin
    908   if (y <= FTop - yyt * 2) or (y > FBottom) or (x <= FLeft - xxt * 2) or
    909     (x > FRight) then
    910     exit;
     908  if (Y <= FTop - yyt * 2) or (Y > FBottom) or (X <= FLeft - xxt * 2) or
     909    (X > FRight) then
     910    Exit;
    911911  if (Loc < 0) or (Loc >= G.lx * G.ly) then
    912     exit;
     912    Exit;
    913913  Tile := MyMap[Loc];
    914914  if Tile and fTerrain >= fGrass then
    915     exit;
     915    Exit;
    916916  Conn := OceanConnection(Loc);
    917917  if Conn = 0 then
    918     exit;
    919 
    920   BitBltBitmap(HGrTerrain.Data, x + xxt div 2, y, xxt, yyt,
     918    Exit;
     919
     920  BitBltBitmap(HGrTerrain.Data, X + xxt div 2, Y, xxt, yyt,
    921921    1 + (Conn shr 6 + Conn and 1 shl 2) * (xxt * 2 + 1),
    922922    1 + yyt + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT);
    923   BitBltBitmap(HGrTerrain.Data, x + xxt, y + yyt div 2, xxt, yyt,
     923  BitBltBitmap(HGrTerrain.Data, X + xxt, Y + yyt div 2, xxt, yyt,
    924924    1 + (Conn and 7) * (xxt * 2 + 1) + xxt,
    925925    1 + yyt * 2 + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT);
    926   BitBltBitmap(HGrTerrain.Data, x + xxt div 2, y + yyt, xxt, yyt,
     926  BitBltBitmap(HGrTerrain.Data, X + xxt div 2, Y + yyt, xxt, yyt,
    927927    1 + (Conn shr 2 and 7) * (xxt * 2 + 1) + xxt,
    928928    1 + yyt + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT);
    929   BitBltBitmap(HGrTerrain.Data, x, y + yyt div 2, xxt, yyt,
     929  BitBltBitmap(HGrTerrain.Data, X, Y + yyt div 2, xxt, yyt,
    930930    1 + (Conn shr 4 and 7) * (xxt * 2 + 1),
    931931    1 + yyt * 2 + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT);
    932932  Conn := Connection4(Loc, fTerrain, fUNKNOWN); { dither to black }
    933933  if Conn and 1 <> 0 then
    934     BitBltBitmap(HGrTerrain.Mask, x + xxt, y, xxt, yyt, 1 + 7 * (xxt * 2 + 1) +
     934    BitBltBitmap(HGrTerrain.Mask, X + xxt, Y, xxt, yyt, 1 + 7 * (xxt * 2 + 1) +
    935935      xxt, 1 + yyt + 15 * (yyt * 3 + 1), SRCAND);
    936936  if Conn and 2 <> 0 then
    937     BitBltBitmap(HGrTerrain.Mask, x + xxt, y + yyt, xxt, yyt,
     937    BitBltBitmap(HGrTerrain.Mask, X + xxt, Y + yyt, xxt, yyt,
    938938      1 + 7 * (xxt * 2 + 1) + xxt, 1 + yyt * 2 + 15 * (yyt * 3 + 1), SRCAND);
    939939  if Conn and 4 <> 0 then
    940     BitBltBitmap(HGrTerrain.Mask, x, y + yyt, xxt, yyt, 1 + 7 * (xxt * 2 + 1),
     940    BitBltBitmap(HGrTerrain.Mask, X, Y + yyt, xxt, yyt, 1 + 7 * (xxt * 2 + 1),
    941941      1 + yyt * 2 + 15 * (yyt * 3 + 1), SRCAND);
    942942  if Conn and 8 <> 0 then
    943     BitBltBitmap(HGrTerrain.Mask, x, y, xxt, yyt, 1 + 7 * (xxt * 2 + 1),
     943    BitBltBitmap(HGrTerrain.Mask, X, Y, xxt, yyt, 1 + 7 * (xxt * 2 + 1),
    944944      1 + yyt + 15 * (yyt * 3 + 1), SRCAND);
    945945end;
    946946
    947 procedure TIsoMap.PaintTileExtraTerrain(x, y, Loc: integer);
    948 var
    949   Dir, Conn, RRConn, yGr, Tile, yLoc: integer;
    950 begin
    951   if (Loc < 0) or (Loc >= G.lx * G.ly) or (y <= -yyt * 2) or
    952     (y > FOutput.Height) or (x <= -xxt * 2) or (x > FOutput.Width) then
    953     exit;
     947procedure TIsoMap.PaintTileExtraTerrain(X, Y, Loc: Integer);
     948var
     949  Dir, Conn, RRConn, yGr, Tile, yLoc: Integer;
     950begin
     951  if (Loc < 0) or (Loc >= G.lx * G.ly) or (Y <= -yyt * 2) or
     952    (Y > FOutput.Height) or (X <= -xxt * 2) or (X > FOutput.Width) then
     953    Exit;
    954954  Tile := MyMap[Loc];
    955955  if Tile and fTerrain = fForest then
     
    966966    then
    967967      Conn := Conn and not 9; // no connection to north
    968     TSprite(x, y, yGr + Conn mod 8 + (Conn div 8) * TerrainIconCols);
     968    TSprite(X, Y, yGr + Conn mod 8 + (Conn div 8) * TerrainIconCols);
    969969  end
    970970  else if Tile and fTerrain in [fHills, fMountains, fForest] then
     
    972972    yGr := 3 + 2 * (Tile and fTerrain - fForest);
    973973    Conn := Connection4(Loc, fTerrain, Tile and fTerrain);
    974     TSprite(x, y, Conn mod 8 + (yGr + Conn div 8) * TerrainIconCols);
     974    TSprite(X, Y, Conn mod 8 + (yGr + Conn div 8) * TerrainIconCols);
    975975  end
    976976  else if Tile and fDeadLands <> 0 then
    977     TSprite(x, y, spRow2);
     977    TSprite(X, Y, spRow2);
    978978
    979979  if ShowObjects then
    980980  begin
    981981    if Tile and fTerImp = tiFarm then
    982       TSprite(x, y, spFarmLand)
     982      TSprite(X, Y, spFarmLand)
    983983    else if Tile and fTerImp = tiIrrigation then
    984       TSprite(x, y, spIrrigation);
     984      TSprite(X, Y, spIrrigation);
    985985  end;
    986986  if Tile and fRiver <> 0 then
     
    989989      Connection4(Loc, fTerrain, fShore) or Connection4(Loc, fTerrain,
    990990      fUNKNOWN);
    991     TSprite(x, y, spRiver + Conn mod 8 + (Conn div 8) * TerrainIconCols);
     991    TSprite(X, Y, spRiver + Conn mod 8 + (Conn div 8) * TerrainIconCols);
    992992  end;
    993993
     
    997997    for Dir := 0 to 3 do
    998998      if Conn and (1 shl Dir) <> 0 then { river mouths }
    999         TSprite(x, y, spRiverMouths + Dir);
     999        TSprite(X, Y, spRiverMouths + Dir);
    10001000    if ShowObjects then
    10011001    begin
     
    10031003      for Dir := 0 to 7 do
    10041004        if Conn and (1 shl Dir) <> 0 then { canal mouths }
    1005           TSprite(x, y, spCanalMouths + 1 + Dir);
     1005          TSprite(X, Y, spCanalMouths + 1 + Dir);
    10061006    end;
    10071007  end;
     
    10151015      if Conn = 0 then begin
    10161016        if Tile and fCanal <> 0 then
    1017           TSprite(x, y, spCanal);
     1017          TSprite(X, Y, spCanal);
    10181018      end
    10191019      else
    10201020        for Dir := 0 to 7 do
    10211021          if (1 shl Dir) and Conn <> 0 then
    1022             TSprite(x, y, spCanal + 1 + Dir);
     1022            TSprite(X, Y, spCanal + 1 + Dir);
    10231023    end;
    10241024
     
    10321032      Conn := Connection8(Loc, fRoad or fRR or fCity) and not RRConn;
    10331033      if (Conn = 0) and (Tile and (fRR or fCity) = 0) then
    1034         TSprite(x, y, spRoad)
     1034        TSprite(X, Y, spRoad)
    10351035      else if Conn > 0 then
    10361036        for Dir := 0 to 7 do
    10371037          if (1 shl Dir) and Conn <> 0 then
    1038             TSprite(x, y, spRoad + 1 + Dir);
     1038            TSprite(X, Y, spRoad + 1 + Dir);
    10391039    end;
    10401040
    10411041    // Paint railroad connections
    10421042    if (Tile and fRR <> 0) and (RRConn = 0) then
    1043       TSprite(x, y, spRailRoad)
     1043      TSprite(X, Y, spRailRoad)
    10441044    else if RRConn > 0 then begin
    10451045      for Dir := 0 to 7 do
    10461046        if (1 shl Dir) and RRConn <> 0 then
    1047           TSprite(x, y, spRailRoad + 1 + Dir);
     1047          TSprite(X, Y, spRailRoad + 1 + Dir);
    10481048    end;
    10491049  end;
     
    10511051
    10521052// (x,y) is top left pixel of (2*xxt,3*yyt) rectangle
    1053 procedure TIsoMap.PaintTileObjects(x, y, Loc, CityLoc, CityOwner: integer;
    1054   UseBlink: boolean);
    1055 var
    1056   p1, p2, uix, cix, dy, Loc1, Tile, Multi, Destination: integer;
     1053procedure TIsoMap.PaintTileObjects(X, Y, Loc, CityLoc, CityOwner: Integer;
     1054  UseBlink: Boolean);
     1055var
     1056  p1, p2, uix, cix, dy, Loc1, Tile, Multi, Destination: Integer;
    10571057  CityInfo: TCityInfo;
    10581058  UnitInfo: TUnitInfo;
    1059   fog: boolean;
     1059  fog: Boolean;
    10601060  SpecialRow: Integer;
    10611061  SpecialCol: Integer;
     
    10631063  procedure NameCity;
    10641064  var
    1065     cix, xs, w: integer;
     1065    cix, xs, W: Integer;
    10661066    BehindCityInfo: TCityInfo;
    1067     s: string;
    1068     IsCapital: boolean;
     1067    S: string;
     1068    IsCapital: Boolean;
    10691069  begin
    10701070    BehindCityInfo.Loc := Loc - 2 * G.lx;
     
    10761076      IsCapital := BehindCityInfo.Flags and ciCapital <> 0;
    10771077      { if Showuix and (cix>=0) then s:=IntToStr(cix)
    1078         else } s := CityName(BehindCityInfo.ID);
    1079       w := FOutput.Canvas.TextWidth(s);
    1080       xs := x + xxt - (w + 1) div 2;
     1078        else } S := CityName(BehindCityInfo.ID);
     1079      W := FOutput.Canvas.TextWidth(S);
     1080      xs := X + xxt - (W + 1) div 2;
    10811081      if IsCapital then
    10821082        FOutput.Canvas.Font.Style := FOutput.Canvas.Font.Style + [fsUnderline];
    1083       Textout(xs + 1, y - 9, $000000, s);
    1084       Textout(xs, y - 10, $FFFFFF, s);
     1083      Textout(xs + 1, Y - 9, $000000, S);
     1084      Textout(xs, Y - 10, $FFFFFF, S);
    10851085      if IsCapital then
    10861086        FOutput.Canvas.Font.Style := FOutput.Canvas.Font.Style - [fsUnderline];
     
    10921092    if ShowObjects and not (moEditMode in MapOptions) and
    10931093      (Tile and fCity <> 0) and (CityInfo.Flags and ciSpacePort <> 0) then
    1094       TSprite(x + xxt, y - 6, spSpacePort);
     1094      TSprite(X + xxt, Y - 6, spSpacePort);
    10951095  end;
    10961096
    10971097  procedure PaintBorder;
    10981098  var
    1099     dx, dy: integer;
     1099    dx, dy: Integer;
    11001100  begin
    11011101    if ShowBorder and (Loc >= 0) and (Loc < G.lx * G.ly) and
    11021102      (Tile and fTerrain <> fUNKNOWN) then begin
    11031103      p1 := MyRO.Territory[Loc];
    1104       if (p1 >= 0) and (ShowMyBorder or (p1 <> me)) then begin
     1104      if (p1 >= 0) and (ShowMyBorder or (p1 <> Me)) then begin
    11051105        if BordersOK^ and (1 shl p1) = 0 then begin
    11061106          UnshareBitmap(Borders);
    1107           DpiBitCanvas(Borders.Canvas, 0, p1 * (yyt * 2), xxt * 2,
     1107          DpiBitBltCanvas(Borders.Canvas, 0, p1 * (yyt * 2), xxt * 2,
    11081108            yyt * 2, HGrTerrain.Data.Canvas,
    11091109            1 + 8 * (xxt * 2 + 1), 1 + yyt + 16 * (yyt * 3 + 1));
     
    11231123              if p2 <> p1 then
    11241124              begin
    1125                 BitBltBitmap(HGrTerrain.Mask, x + dx * xxt, y + dy * yyt, xxt,
     1125                BitBltBitmap(HGrTerrain.Mask, X + dx * xxt, Y + dy * yyt, xxt,
    11261126                  yyt, 1 + 8 * (xxt * 2 + 1) + dx * xxt,
    11271127                  1 + yyt + 16 * (yyt * 3 + 1) + dy * yyt, SRCAND);
    1128                 BitBltBitmap(Borders, x + dx * xxt, y + dy * yyt, xxt, yyt, dx * xxt,
     1128                BitBltBitmap(Borders, X + dx * xxt, Y + dy * yyt, xxt, yyt, dx * xxt,
    11291129                  p1 * (yyt * 2) + dy * yyt, SRCPAINT);
    11301130              end;
     
    11431143    (Tile and fCity <> 0) then
    11441144    GetCityInfo(Loc, cix, CityInfo);
    1145   if (y <= FTop - yyt * 2) or (y > FBottom) or (x <= FLeft - xxt * 2) or
    1146     (x > FRight) then
     1145  if (Y <= FTop - yyt * 2) or (Y > FBottom) or (X <= FLeft - xxt * 2) or
     1146    (X > FRight) then
    11471147  begin
    11481148    NameCity;
    11491149    ShowSpacePort;
    1150     exit;
     1150    Exit;
    11511151  end;
    11521152  if Tile and fTerrain = fUNKNOWN then
     
    11541154    NameCity;
    11551155    ShowSpacePort;
    1156     exit;
     1156    Exit;
    11571157  end; { square not discovered }
    11581158
     
    11611161
    11621162  if (Loc >= 0) and (Loc < G.lx * G.ly) and (Loc = FAdviceLoc) then
    1163     TSprite(x, y, spPlain);
     1163    TSprite(X, Y, spPlain);
    11641164
    11651165  if (Loc >= 0) and (Loc < G.lx * G.ly) and (Tile and fSpecial <> 0)
     
    11701170    SpecialRow := Tile and fSpecial shr 5;
    11711171    if SpecialCol < fForest then
    1172       TSprite(x, y, SpecialCol + SpecialRow * TerrainIconCols)
     1172      TSprite(X, Y, SpecialCol + SpecialRow * TerrainIconCols)
    11731173    else if (SpecialCol = fForest) and IsJungle(dy) then
    1174       TSprite(x, y, spJungle - 1 + SpecialRow * TerrainIconCols)
     1174      TSprite(X, Y, spJungle - 1 + SpecialRow * TerrainIconCols)
    11751175    else
    1176       TSprite(x, y, spForest - 1 + ((SpecialCol - fForest) * 2 + SpecialRow) * TerrainIconCols);
     1176      TSprite(X, Y, spForest - 1 + ((SpecialCol - fForest) * 2 + SpecialRow) * TerrainIconCols);
    11771177  end;
    11781178
     
    11801180  begin
    11811181    if Tile and fTerImp = tiMine then
    1182       TSprite(x, y, spMine);
     1182      TSprite(X, Y, spMine);
    11831183    if Tile and fTerImp = tiBase then
    1184       TSprite(x, y, spBase);
     1184      TSprite(X, Y, spBase);
    11851185    if Tile and fPoll <> 0 then
    1186       TSprite(x, y, spPollution);
     1186      TSprite(X, Y, spPollution);
    11871187    if Tile and fTerImp = tiFort then
    11881188    begin
    1189       TSprite(x, y, spFortBack);
     1189      TSprite(X, Y, spFortBack);
    11901190      if Tile and fObserved = 0 then
    1191         TSprite(x, y, spFortFront);
     1191        TSprite(X, Y, spFortFront);
    11921192    end;
    11931193  end;
    11941194  if (Tile and fDeadLands) <> 0 then
    1195     TSprite(x, y, spMinerals + (Tile shr 25 and 3) * TerrainIconCols);
     1195    TSprite(X, Y, spMinerals + (Tile shr 25 and 3) * TerrainIconCols);
    11961196
    11971197  if moEditMode in MapOptions then
     
    12051205  if fog and ShowObjects then
    12061206    if Loc < -G.lx then
    1207       Sprite(HGrTerrain, x, y + yyt, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1),
     1207      Sprite(HGrTerrain, X, Y + yyt, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1),
    12081208        1 + yyt * 2 + 15 * (yyt * 3 + 1))
    12091209    else if Loc >= G.lx * (G.ly + 1) then
    1210       Sprite(HGrTerrain, x, y, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1),
     1210      Sprite(HGrTerrain, X, Y, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1),
    12111211        1 + yyt + 15 * (yyt * 3 + 1))
    12121212    else
    1213       TSprite(x, y, spGrid, xxt <> 33);
     1213      TSprite(X, Y, spGrid, xxt <> 33);
    12141214
    12151215  if FoW and (Tile and fObserved = 0) then
     
    12241224    if (Destination = Loc) and (Destination <> MyUn[UnFocus].Loc) then
    12251225      if not UseBlink or BlinkOn then
    1226         TSprite(x, y, spBlink1)
     1226        TSprite(X, Y, spBlink1)
    12271227      else
    1228         TSprite(x, y, spBlink2)
     1228        TSprite(X, Y, spBlink2)
    12291229  end;
    12301230{$ENDIF}
     
    12321232  begin
    12331233    if Tile and fPrefStartPos <> 0 then
    1234       TSprite(x, y, spPrefStartPos)
     1234      TSprite(X, Y, spPrefStartPos)
    12351235    else if Tile and fStartPos <> 0 then
    1236       TSprite(x, y, spStartPos);
     1236      TSprite(X, Y, spStartPos);
    12371237  end
    12381238  else if ShowObjects then
    12391239  begin
    12401240    { if (CityLoc<0) and (UnFocus>=0) and (Loc=MyUn[UnFocus].Loc) then
    1241       if BlinkOn then TSprite(x,y,8+9*0)
    1242       else TSprite(x,y,8+9*1); }
     1241      if BlinkOn then TSprite(X,Y,8+9*0)
     1242      else TSprite(X,Y,8+9*1); }
    12431243
    12441244    NameCity;
    12451245    ShowSpacePort;
    12461246    if Tile and fCity <> 0 then
    1247       PaintCity(x + xxt, y + yyt, CityInfo, CityOwner < 0);
     1247      PaintCity(X + xxt, Y + yyt, CityInfo, CityOwner < 0);
    12481248
    12491249    if (Tile and fUnit <> 0) and (Loc <> AttLoc) and
     
    12591259        UnitInfo.Health := DefHealth;
    12601260      if (UnitInfo.Owner <> CityOwner) and
    1261         not((CityOwner = me) and (MyRO.Treaty[UnitInfo.Owner] = trAlliance))
     1261        not((CityOwner = Me) and (MyRO.Treaty[UnitInfo.Owner] = trAlliance))
    12621262      then
    12631263{$IFNDEF SCR} if (UnFocus >= 0) and (Loc = MyUn[UnFocus].Loc) then { active unit }
    12641264        begin
    12651265          Multi := UnitInfo.Flags and unMulti;
    1266           MakeUnitInfo(me, MyUn[UnFocus], UnitInfo);
     1266          MakeUnitInfo(Me, MyUn[UnFocus], UnitInfo);
    12671267          UnitInfo.Flags := UnitInfo.Flags or Multi;
    1268           PaintUnit(x + (xxt - xxu), y + (yyt - yyu_anchor), UnitInfo,
     1268          PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo,
    12691269            MyUn[UnFocus].Status);
    12701270        end
    1271         else if UnitInfo.Owner = me then
     1271        else if UnitInfo.Owner = Me then
    12721272        begin
    12731273          if ClientMode = cMovieTurn then
    1274             PaintUnit(x + (xxt - xxu), y + (yyt - yyu_anchor), UnitInfo, 0)
     1274            PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo, 0)
    12751275            // status is not set with precise timing during loading
    12761276          else
    1277             PaintUnit(x + (xxt - xxu), y + (yyt - yyu_anchor), UnitInfo,
     1277            PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo,
    12781278              MyUn[uix].Status);
    12791279          // if Showuix then Textout(x+16,y+5,$80FF00,IntToStr(uix));
    12801280        end
    1281         else {$ENDIF} PaintUnit(x + (xxt - xxu), y + (yyt - yyu_anchor), UnitInfo, 0);
     1281        else {$ENDIF} PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo, 0);
    12821282    end
    12831283    else if Tile and fHiddenUnit <> 0 then
    1284       Sprite(HGrStdUnits, x + (xxt - xxu), y + (yyt - yyu_anchor), xxu * 2,
     1284      Sprite(HGrStdUnits, X + (xxt - xxu), Y + (yyt - yyu_anchor), xxu * 2,
    12851285        yyu * 2, 1 + 5 * (xxu * 2 + 1), 1)
    12861286    else if Tile and fStealthUnit <> 0 then
    1287       Sprite(HGrStdUnits, x + (xxt - xxu), y + (yyt - yyu_anchor), xxu * 2,
     1287      Sprite(HGrStdUnits, X + (xxt - xxu), Y + (yyt - yyu_anchor), xxu * 2,
    12881288        yyu * 2, 1 + 5 * (xxu * 2 + 1), 1 + 1 * (yyu * 2 + 1))
    12891289  end;
     
    12911291  if ShowObjects and (Tile and fTerImp = tiFort) and (Tile and fObserved <> 0)
    12921292  then
    1293     TSprite(x, y, spFortFront);
     1293    TSprite(X, Y, spFortFront);
    12941294
    12951295  if (Loc >= 0) and (Loc < G.lx * G.ly) then
    12961296    if ShowLoc then
    1297       Textout(x + xxt - 16, y + yyt - 9, $FFFF00, IntToStr(Loc))
     1297      Textout(X + xxt - 16, Y + yyt - 9, $FFFF00, IntToStr(Loc))
    12981298    else if ShowDebug and (DebugMap <> nil) and (Loc >= 0) and
    12991299      (Loc < G.lx * G.ly) and (DebugMap[Loc] <> 0) then
    1300       Textout(x + xxt - 16, y + yyt - 9, $00E0FF,
    1301         IntToStr(integer(DebugMap[Loc])))
    1302 end; { PaintTileObjects }
    1303 
    1304 procedure TIsoMap.PaintGrid(x, y, nx, ny: integer);
    1305 
    1306   procedure ClippedLine(dx0, dy0: integer; mirror: boolean);
     1300      Textout(X + xxt - 16, Y + yyt - 9, $00E0FF,
     1301        IntToStr(Integer(DebugMap[Loc])))
     1302end;
     1303
     1304procedure TIsoMap.PaintGrid(X, Y, nx, ny: Integer);
     1305
     1306  procedure ClippedLine(dx0, dy0: Integer; mirror: Boolean);
    13071307  var
    1308     x0, x1, dxmin, dymin, dxmax, dymax, n: integer;
     1308    x0, x1, dxmin, dymin, dxmax, dymax, N: Integer;
    13091309  begin
    13101310    with FOutput.Canvas do
    13111311    begin
    1312       dxmin := (FLeft - x) div xxt;
    1313       dymin := (RealTop - y) div yyt;
    1314       dxmax := (FRight - x - 1) div xxt + 1;
    1315       dymax := (RealBottom - y - 1) div yyt + 1;
    1316       n := dymax - dy0;
     1312      dxmin := (FLeft - X) div xxt;
     1313      dymin := (RealTop - Y) div yyt;
     1314      dxmax := (FRight - X - 1) div xxt + 1;
     1315      dymax := (RealBottom - Y - 1) div yyt + 1;
     1316      N := dymax - dy0;
    13171317      if mirror then
    13181318      begin
    1319         if dx0 - dxmin < n then
    1320           n := dx0 - dxmin;
     1319        if dx0 - dxmin < N then
     1320          N := dx0 - dxmin;
    13211321        if dx0 > dxmax then
    13221322        begin
    1323           n := n - (dx0 - dxmax);
     1323          N := N - (dx0 - dxmax);
    13241324          dy0 := dy0 + (dx0 - dxmax);
    13251325          dx0 := dxmax
     
    13271327        if dy0 < dymin then
    13281328        begin
    1329           n := n - (dymin - dy0);
     1329          N := N - (dymin - dy0);
    13301330          dx0 := dx0 - (dymin - dy0);
    13311331          dy0 := dymin
     
    13341334      else
    13351335      begin
    1336         if dxmax - dx0 < n then
    1337           n := dxmax - dx0;
     1336        if dxmax - dx0 < N then
     1337          N := dxmax - dx0;
    13381338        if dx0 < dxmin then
    13391339        begin
    1340           n := n - (dxmin - dx0);
     1340          N := N - (dxmin - dx0);
    13411341          dy0 := dy0 + (dxmin - dx0);
    13421342          dx0 := dxmin
     
    13441344        if dy0 < dymin then
    13451345        begin
    1346           n := n - (dymin - dy0);
     1346          N := N - (dymin - dy0);
    13471347          dx0 := dx0 + (dymin - dy0);
    13481348          dy0 := dymin
    13491349        end;
    13501350      end;
    1351       if n <= 0 then
    1352         exit;
     1351      if N <= 0 then
     1352        Exit;
    13531353      if mirror then
    13541354      begin
    1355         x0 := x + dx0 * xxt - 1;
    1356         x1 := x + (dx0 - n) * xxt - 1;
     1355        x0 := X + dx0 * xxt - 1;
     1356        x1 := X + (dx0 - N) * xxt - 1;
    13571357      end
    13581358      else
    13591359      begin
    1360         x0 := x + dx0 * xxt;
    1361         x1 := x + (dx0 + n) * xxt;
     1360        x0 := X + dx0 * xxt;
     1361        x1 := X + (dx0 + N) * xxt;
    13621362      end;
    1363       moveto(x0, y + dy0 * yyt);
    1364       lineto(x1, y + (dy0 + n) * yyt);
     1363      moveto(x0, Y + dy0 * yyt);
     1364      lineto(x1, Y + (dy0 + N) * yyt);
    13651365    end;
    13661366  end;
    13671367
    13681368var
    1369   i: integer;
     1369  I: Integer;
    13701370begin
    13711371  FOutput.Canvas.pen.Color := $000000; // $FF shl (8*random(3));
    1372   for i := 0 to nx div 2 do
    1373     ClippedLine(i * 2, 0, false);
    1374   for i := 1 to (nx + 1) div 2 do
    1375     ClippedLine(i * 2, 0, true);
    1376   for i := 0 to ny div 2 do
    1377   begin
    1378     ClippedLine(0, 2 * i + 2, false);
    1379     ClippedLine(nx + 1, 2 * i + 1 + nx and 1, true);
    1380   end;
    1381 end;
    1382 
    1383 function TIsoMap.IsShoreTile(Loc: integer): boolean;
     1372  for I := 0 to nx div 2 do
     1373    ClippedLine(I * 2, 0, False);
     1374  for I := 1 to (nx + 1) div 2 do
     1375    ClippedLine(I * 2, 0, True);
     1376  for I := 0 to ny div 2 do
     1377  begin
     1378    ClippedLine(0, 2 * I + 2, False);
     1379    ClippedLine(nx + 1, 2 * I + 1 + nx and 1, True);
     1380  end;
     1381end;
     1382
     1383function TIsoMap.IsShoreTile(Loc: Integer): Boolean;
    13841384var
    13851385  Dir: Integer;
    1386   ConnLoc: integer;
    1387 begin
    1388   result := false;
     1386  ConnLoc: Integer;
     1387begin
     1388  Result := False;
    13891389  for Dir := 0 to 7 do
    13901390  begin
     
    13921392    if (ConnLoc < 0) or (ConnLoc >= G.lx * G.ly) or
    13931393      ((MyMap[ConnLoc] - 2) and fTerrain < 13) then
    1394       result := true;
     1394      Result := True;
    13951395  end;
    13961396end;
     
    14011401begin
    14021402  for I := 0 to Length - 1 do begin
    1403     Line^.Pixel^.B := (Line^.Pixel^.B shr 1) and $7f;
    1404     Line^.Pixel^.G := (Line^.Pixel^.G shr 1) and $7f;
    1405     Line^.Pixel^.R := (Line^.Pixel^.R shr 1) and $7f;
     1403    Line^.Pixel^.B := (Line^.Pixel^.B shr 1) and $7F;
     1404    Line^.Pixel^.G := (Line^.Pixel^.G shr 1) and $7F;
     1405    Line^.Pixel^.R := (Line^.Pixel^.R shr 1) and $7F;
    14061406    Line^.NextPixel;
    14071407  end;
     
    14151415end;
    14161416
    1417 procedure TIsoMap.ShadeOutside(x0, y0, Width, Height, xm, ym: integer);
     1417procedure TIsoMap.ShadeOutside(x0, y0, Width, Height, xm, ym: Integer);
    14181418const
    14191419  rShade = 3.75;
    14201420var
    1421   y, wBright: integer;
    1422   y_n, w_n: single;
     1421  Y, wBright: Integer;
     1422  y_n, w_n: Single;
    14231423  Line: TPixelPointer;
    14241424begin
    14251425  FOutput.BeginUpdate;
    1426   Line := PixelPointer(FOutput, ScaleToNative(x0), ScaleToNative(y0));
    1427   for y := 0 to ScaleToNative(Height) - 1 do begin
    1428     y_n := (ScaleFromNative(y) + y0 - ym) / yyt;
     1426  Line := TPixelPointer.Create(FOutput, ScaleToNative(x0), ScaleToNative(y0));
     1427  for Y := 0 to ScaleToNative(Height) - 1 do begin
     1428    y_n := (ScaleFromNative(Y) + y0 - ym) / yyt;
    14291429    if abs(y_n) < rShade then begin
    14301430      // Darken left and right parts of elipsis
     
    14451445end;
    14461446
    1447 procedure TIsoMap.CityGrid(xm, ym: integer; CityAllowClick: Boolean);
    1448 var
    1449   i: integer;
     1447procedure TIsoMap.CityGrid(xm, ym: Integer; CityAllowClick: Boolean);
     1448var
     1449  I: Integer;
    14501450begin
    14511451  with FOutput.Canvas do
     
    14561456      pen.Color := $000000;
    14571457    pen.Width := 1;
    1458     for i := 0 to 3 do
     1458    for I := 0 to 3 do
    14591459    begin
    1460       moveto(xm - xxt * (4 - i), ym + yyt * (1 + i));
    1461       lineto(xm + xxt * (1 + i), ym - yyt * (4 - i));
    1462       moveto(xm - xxt * (4 - i), ym - yyt * (1 + i));
    1463       lineto(xm + xxt * (1 + i), ym + yyt * (4 - i));
     1460      moveto(xm - xxt * (4 - I), ym + yyt * (1 + I));
     1461      lineto(xm + xxt * (1 + I), ym - yyt * (4 - I));
     1462      moveto(xm - xxt * (4 - I), ym - yyt * (1 + I));
     1463      lineto(xm + xxt * (1 + I), ym + yyt * (4 - I));
    14641464    end;
    14651465    moveto(xm - xxt * 4, ym + yyt * 1);
     
    14751475end;
    14761476
    1477 procedure TIsoMap.Paint(x, y, Loc, nx, ny, CityLoc, CityOwner: integer;
    1478   UseBlink: boolean; CityAllowClick: boolean);
    1479 var
    1480   dx, dy, xm, ym, ALoc, BLoc, ATer, BTer, Aix, bix: integer;
    1481 begin
    1482   FoW := true;
     1477procedure TIsoMap.Paint(X, Y, Loc, nx, ny, CityLoc, CityOwner: Integer;
     1478  UseBlink: Boolean; CityAllowClick: Boolean);
     1479var
     1480  dx, dy, xm, ym, ALoc, BLoc, ATer, BTer, Aix, bix: Integer;
     1481begin
     1482  FoW := True;
    14831483  ShowLoc := moLocCodes in MapOptions;
    14841484  ShowDebug := pDebugMap >= 0;
     
    14861486  ShowCityNames := ShowObjects and (CityOwner < 0) and
    14871487    (moCityNames in MapOptions);
    1488   ShowBorder := true;
     1488  ShowBorder := True;
    14891489  ShowMyBorder := CityOwner < 0;
    14901490  ShowGrWall := (CityOwner < 0) and (moGreatWall in MapOptions);
    14911491  if ShowDebug then
    1492     Server(sGetDebugMap, me, pDebugMap, DebugMap)
     1492    Server(sGetDebugMap, Me, pDebugMap, DebugMap)
    14931493  else
    14941494    DebugMap := nil;
    14951495  with FOutput.Canvas do
    14961496  begin
    1497     RealTop := y - ((Loc + 12345 * G.lx) div G.lx - 12345) * yyt;
    1498     RealBottom := y + (G.ly - ((Loc + 12345 * G.lx) div G.lx - 12345) +
     1497    RealTop := Y - ((Loc + 12345 * G.lx) div G.lx - 12345) * yyt;
     1498    RealBottom := Y + (G.ly - ((Loc + 12345 * G.lx) div G.lx - 12345) +
    14991499      3) * yyt;
    15001500    Brush.Color := EmptySpaceColor;
     
    15731573                  bix := 0;
    15741574                end;
    1575               BitBltBitmap(OceanPatch, x + dx * xxt, y + dy * yyt, xxt, yyt,
     1575              BitBltBitmap(OceanPatch, X + dx * xxt, Y + dy * yyt, xxt, yyt,
    15761576                Aix * (xxt * 2) + (dx + dy + 1) and 1 * xxt, bix * yyt, SRCCOPY)
    15771577            end
     
    16211621                bix := Aix;
    16221622            if Aix = -1 then
    1623               BitBltBitmap(HGrTerrain.Data, x + dx * xxt, y + dy * yyt, xxt,
     1623              BitBltBitmap(HGrTerrain.Data, X + dx * xxt, Y + dy * yyt, xxt,
    16241624                yyt, 1 + 6 * (xxt * 2 + 1) + (dx + dy + 1) and 1 * xxt, 1 + yyt,
    16251625                SRCCOPY) // arctic <-> ocean
    16261626            else if bix = -1 then
    1627               BitBltBitmap(HGrTerrain.Data, x + dx * xxt, y + dy * yyt, xxt,
     1627              BitBltBitmap(HGrTerrain.Data, X + dx * xxt, Y + dy * yyt, xxt,
    16281628                yyt, 1 + 6 * (xxt * 2 + 1) + xxt - (dx + dy + 1) and 1 * xxt,
    16291629                1 + yyt * 2, SRCCOPY) // arctic <-> ocean
    16301630            else
    1631               BitBltBitmap(LandPatch, x + dx * xxt, y + dy * yyt, xxt, yyt,
     1631              BitBltBitmap(LandPatch, X + dx * xxt, Y + dy * yyt, xxt, yyt,
    16321632                Aix * (xxt * 2) + (dx + dy + 1) and 1 * xxt, bix * yyt, SRCCOPY)
    16331633          end;
     
    16391639    for dx := -1 to nx do
    16401640      if (dx + dy) and 1 = 0 then
    1641         PaintShore(x + xxt * dx, y + yyt + yyt * dy, dLoc(Loc, dx, dy));
     1641        PaintShore(X + xxt * dx, Y + yyt + yyt * dy, dLoc(Loc, dx, dy));
    16421642  for dy := -2 to ny + 1 do
    16431643    for dx := -1 to nx do
    16441644      if (dx + dy) and 1 = 0 then
    1645         PaintTileExtraTerrain(x + xxt * dx, y + yyt + yyt * dy,
     1645        PaintTileExtraTerrain(X + xxt * dx, Y + yyt + yyt * dy,
    16461646          dLoc(Loc, dx, dy));
    16471647  if CityOwner >= 0 then
     
    16531653          ALoc := dLoc(Loc, dx, dy);
    16541654          if Distance(ALoc, CityLoc) > 5 then
    1655             PaintTileObjects(x + xxt * dx, y + yyt + yyt * dy, ALoc, CityLoc,
     1655            PaintTileObjects(X + xxt * dx, Y + yyt + yyt * dy, ALoc, CityLoc,
    16561656              CityOwner, UseBlink);
    16571657        end;
     
    16601660      * G.lx) mod (2 * G.lx) - G.lx;
    16611661    dy := CityLoc div G.lx - (Loc + 666 * G.lx) div G.lx + 666;
    1662     xm := x + (dx + 1) * xxt;
    1663     ym := y + (dy + 1) * yyt + yyt;
     1662    xm := X + (dx + 1) * xxt;
     1663    ym := Y + (dy + 1) * yyt + yyt;
    16641664    ShadeOutside(FLeft, FTop, FRight - FLeft, FBottom - FTop, xm, ym);
    16651665    CityGrid(xm, ym, CityAllowClick);
     
    16701670          ALoc := dLoc(Loc, dx, dy);
    16711671          if Distance(ALoc, CityLoc) <= 5 then
    1672             PaintTileObjects(x + xxt * dx, y + yyt + yyt * dy, ALoc, CityLoc,
     1672            PaintTileObjects(X + xxt * dx, Y + yyt + yyt * dy, ALoc, CityLoc,
    16731673              CityOwner, UseBlink);
    16741674        end;
     
    16781678    if ShowLoc or (moEditMode in MapOptions) or
    16791679      (moGrid in MapOptions) then
    1680       PaintGrid(x, y, nx, ny);
     1680      PaintGrid(X, Y, nx, ny);
    16811681    for dy := -2 to ny + 1 do
    16821682      for dx := -2 to nx + 1 do
    16831683        if (dx + dy) and 1 = 0 then
    1684           PaintTileObjects(x + xxt * dx, y + yyt + yyt * dy, dLoc(Loc, dx, dy),
     1684          PaintTileObjects(X + xxt * dx, Y + yyt + yyt * dy, dLoc(Loc, dx, dy),
    16851685            CityLoc, CityOwner, UseBlink);
    16861686  end;
    16871687
    16881688  // frame(FOutput.Canvas,x+1,y+1,x+nx*33+33-2,y+ny*16+32-2,$FFFF,$FFFF);
    1689 end; { Paint }
     1689end;
    16901690
    16911691procedure TIsoMap.AttackBegin(const ShowMove: TShowMove);
  • TabularUnified branches/highdpi/LocalPlayer/KeyBindings.pas

    r464 r465  
    1 unit UKeyBindings;
    2 
    3 {$mode delphi}
     1unit KeyBindings;
    42
    53interface
    64
    75uses
    8   Classes, SysUtils, fgl, LCLProc, LCLType, Menus, Registry;
     6  Classes, SysUtils, Generics.Collections, Generics.Defaults, LCLProc, LCLType,
     7  Menus, Registry;
    98
    109type
     
    2625  { TKeyBindings }
    2726
    28   TKeyBindings = class(TFPGObjectList<TKeyBinding>)
     27  TKeyBindings = class(TObjectList<TKeyBinding>)
    2928  private
    3029  public
     
    3837    procedure ResetToDefault;
    3938    procedure RemoveShortCut(ShortCut: TShortCut);
     39    procedure SortAlpha;
    4040  end;
    4141
     
    241241  Text: string;
    242242begin
    243   Strings.Clear;
    244   for I := 0 to Count - 1 do begin
    245     Text:= '';
    246     if Items[I].ShortCut <> 0 then
    247       Text:= Text + ShortCutToText(Items[I].ShortCut);
    248     if Items[I].ShortCut2 <> 0 then begin
    249       if Text <> '' then Text := Text + ', ';
    250       Text:= Text + ShortCutToText(Items[I].ShortCut2);
     243  Strings.BeginUpdate;
     244  try
     245    Strings.Clear;
     246    for I := 0 to Count - 1 do begin
     247      Text := '';
     248      if Items[I].ShortCut <> 0 then
     249        Text := Text + ShortCutToText(Items[I].ShortCut);
     250      if Items[I].ShortCut2 <> 0 then begin
     251        if Text <> '' then Text := Text + ', ';
     252        Text := Text + ShortCutToText(Items[I].ShortCut2);
     253      end;
     254      if Text <> '' then Text := Items[I].FullName + ' (' + Text + ')'
     255        else Text := Items[I].FullName;
     256      Strings.Add(Text);
    251257    end;
    252     if Text <> '' then Text := Items[I].FullName + ' (' + Text + ')'
    253       else Text := Items[I].FullName;
    254     Strings.Add(Text);
     258  finally
     259    Strings.EndUpdate;
    255260  end;
    256261end;
     
    284289    if Items[I].ShortCut2 = ShortCut then Items[I].ShortCut2 := 0;
    285290  end;
     291end;
     292
     293function CompareAlpha(constref Item1, Item2: TKeyBinding): Integer;
     294begin
     295  Result := CompareStr(Item1.FullName, Item2.FullName);
     296end;
     297
     298procedure TKeyBindings.SortAlpha;
     299begin
     300  Sort(TComparer<TKeyBinding>.Construct(CompareAlpha));
    286301end;
    287302
     
    372387  BMoveLeftUp := AddItem('MoveLeftUp', 'Move unit left-up', 'Num7', 'Home');
    373388  BMoveLeft := AddItem('MoveLeft', 'Move unit left', 'Num4', 'Left');
     389  SortAlpha;
    374390end;
    375391
     
    381397end.
    382398
     399
  • TabularUnified branches/highdpi/LocalPlayer/LocalPlayer.pas

    r378 r465  
    44interface
    55
    6 procedure Client(Command, Player: integer; var Data); stdcall;
    7 procedure SetAIName(p: integer; Name: string);
     6procedure Client(Command, Player: Integer; var Data); stdcall;
     7procedure SetAIName(P: Integer; Name: string);
    88
    99implementation
    1010
    1111uses
    12   UDpiControls, Term, CityScreen, Draft, MessgEx, Select, CityType, Help, UnitStat, Diagram,
    13   NatStat, Wonders, Nego, Enhance, BaseWin, Battle, Rates, TechTree, Forms;
     12  UDpiControls, Term, CityScreen, Nego, BaseWin, Forms;
    1413
    1514var
    16   FormsCreated: boolean;
     15  FormsCreated: Boolean;
    1716
    18 procedure Client(Command, Player: integer; var Data);
     17procedure Client(Command, Player: Integer; var Data);
    1918begin
    2019  if not FormsCreated then
    2120  begin
    22     FormsCreated := true;
     21    FormsCreated := True;
    2322    // TODO: Changing application name in runtime will cause change of Linux XML registry file path
    24 //    DpiApplication.MainForm := MainScreen;
     23//    Application.MainForm := MainScreen;
    2524    DpiApplication.CreateForm(TMainScreen, MainScreen);
    26     DpiApplication.CreateForm(TCityDlg, CityDlg);
    27     DpiApplication.CreateForm(TModalSelectDlg, ModalSelectDlg);
    28     DpiApplication.CreateForm(TListDlg, ListDlg);
    29     DpiApplication.CreateForm(TMessgExDlg, MessgExDlg);
    30     DpiApplication.CreateForm(TDraftDlg, DraftDlg);
    31     DpiApplication.CreateForm(TCityTypeDlg, CityTypeDlg);
    32     DpiApplication.CreateForm(THelpDlg, HelpDlg);
    33     DpiApplication.CreateForm(TUnitStatDlg, UnitStatDlg);
    34     DpiApplication.CreateForm(TDiaDlg, DiaDlg);
    35     DpiApplication.CreateForm(TNatStatDlg, NatStatDlg);
    36     DpiApplication.CreateForm(TWondersDlg, WondersDlg);
    37     DpiApplication.CreateForm(TNegoDlg, NegoDlg);
    38     DpiApplication.CreateForm(TEnhanceDlg, EnhanceDlg);
    39     DpiApplication.CreateForm(TBattleDlg, BattleDlg);
    40     // DpiApplication.CreateForm(TAdvisorDlg, AdvisorDlg);
    41     DpiApplication.CreateForm(TRatesDlg, RatesDlg);
    42     DpiApplication.CreateForm(TTechTreeDlg, TechTreeDlg);
    4325  end;
    4426  MainScreen.Client(Command, Player, Data);
    4527end;
    4628
    47 procedure SetAIName(p: integer; Name: string);
     29procedure SetAIName(P: Integer; Name: string);
    4830begin
    49   MainScreen.SetAIName(p, Name);
     31  MainScreen.SetAIName(P, Name);
    5032end;
    5133
    5234initialization
    5335
    54 FormsCreated := false;
     36FormsCreated := False;
    5537
    5638end.
  • TabularUnified branches/highdpi/LocalPlayer/MessgEx.lfm

    r349 r465  
    66  BorderIcons = []
    77  BorderStyle = bsNone
    8   Caption = 'C-evo'
     8  Caption = 'Message'
    99  ClientHeight = 134
    1010  ClientWidth = 418
     
    1212  DesignTimePPI = 144
    1313  Font.Color = clWindowText
    14   Font.Height = -13
     14  Font.Height = -20
    1515  Font.Name = 'MS Sans Serif'
    1616  FormStyle = fsStayOnTop
     
    2020  OnPaint = FormPaint
    2121  OnShow = FormShow
    22   LCLVersion = '2.0.12.0'
     22  LCLVersion = '2.2.2.0'
    2323  Scaled = False
    2424  object Button1: TButtonA
     
    6161  object EInput: TDpiEdit
    6262    Left = 125
    63     Height = 26
     63    Height = 27
    6464    Top = 64
    6565    Width = 168
  • TabularUnified branches/highdpi/LocalPlayer/MessgEx.pas

    r412 r465  
    55
    66uses
    7   UDpiControls, Messg, Protocol, ScreenTools, Platform, DateUtils,
    8   LCLIntf, LCLType, Messages, SysUtils, Classes, Graphics, Controls, Forms, ButtonA,
    9   ButtonB, StdCtrls, DrawDlg;
     7  UDpiControls, Messg, Protocol, ScreenTools, Platform, DateUtils, LCLIntf, LCLType, Messages,
     8  SysUtils, Classes, Graphics, Controls, Forms, ButtonA, ButtonB, StdCtrls,
     9  DrawDlg, Help;
    1010
    1111type
     
    1313    mikPureIcon, mikMyArmy, mikEnemyArmy, mikFullControl, mikShip, mikBigIcon,
    1414    mikEnemyShipComplete);
     15
     16  { TMessgExDlg }
    1517
    1618  TMessgExDlg = class(TBaseMessgDlg)
     
    3234    Kind: TMessageKind;
    3335    IconIndex: Integer;
    34     HelpKind: Integer;
     36    HelpKind: TLinkCategory;
    3537    HelpNo: Integer;
    3638    CenterTo: Integer;
    3739    IconKind: TMessageIconKind;
    3840    OpenSound: string;
    39     function ShowModal: integer; override;
     41    function ShowModal: Integer; override;
    4042    procedure CancelMovie;
    4143  private
    42     MovieCancelled: boolean;
    43     procedure PaintBook(ca: TDpiCanvas; x, y, clPage, clCover: integer);
     44    MovieCancelled: Boolean;
     45    procedure PaintBook(ca: TDpiCanvas; X, Y, clPage, clCover: Integer);
    4446    procedure PaintMyArmy;
    4547    procedure PaintEnemyArmy;
     
    4749  end;
    4850
    49 var
    50   MessgExDlg: TMessgExDlg;
    5151
    5252procedure SoundMessageEx(SimpleText, SoundItem: string);
    53 procedure TribeMessage(p: integer; SimpleText, SoundItem: string);
     53procedure TribeMessage(P: Integer; SimpleText, SoundItem: string);
    5454function SimpleQuery(QueryKind: TMessageKind; SimpleText, SoundItem: string)
    55   : integer;
     55  : Integer;
    5656procedure ContextMessage(SimpleText, SoundItem: string;
    57   ContextKind, ContextNo: integer);
     57  ContextKind: TLinkCategory; ContextNo: Integer);
     58
    5859
    5960implementation
    6061
    6162uses
    62   ClientTools, BaseWin, Term, Help, UnitStat, Tribes, UPixelPointer,
    63   IsoEngine, Diagram, Sound;
     63  ClientTools, BaseWin, Term, UnitStat, Tribes, PixelPointer,
     64  Diagram, Sound;
    6465
    6566{$R *.lfm}
     
    7879procedure TMessgExDlg.FormShow(Sender: TObject);
    7980var
    80   i: integer;
     81  I: Integer;
    8182begin
    8283  if IconKind = mikEnemyArmy then
     
    147148  end;
    148149
    149   SplitText(true);
     150  SplitText(True);
    150151  ClientHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing;
    151152  if GameMode = cMovie then
     
    178179      end;
    179180  end;
    180   for i := 0 to ControlCount - 1 do
    181     Controls[i].Top := ClientHeight - (34 + Border);
     181  for I := 0 to ControlCount - 1 do
     182    Controls[I].Top := ClientHeight - (34 + Border);
    182183  if Kind = mkModel then
    183184    EInput.Top := ClientHeight - (76 + Border);
    184185end;
    185186
    186 function TMessgExDlg.ShowModal: integer;
     187function TMessgExDlg.ShowModal: Integer;
    187188var
    188189  Ticks0: TDateTime;
    189190  Ticks: TDateTime;
    190191begin
     192  Caption := Phrases.Lookup('TITLE_MESSAGE');
    191193  if GameMode = cMovie then
    192194  begin
    193195    if not((GameMode = cMovie) and (MovieSpeed = 4)) then
    194196    begin
    195       MovieCancelled := false;
     197      MovieCancelled := False;
    196198      Show;
    197199      Ticks0 := NowPrecise;
     
    203205      Hide;
    204206    end;
    205     result := mrOk;
     207    Result := mrOk;
    206208  end
    207209  else
    208     result := inherited;
     210    Result := inherited;
     211  //Gtk2Fix;
    209212end;
    210213
    211214procedure TMessgExDlg.CancelMovie;
    212215begin
    213   MovieCancelled := true;
    214 end;
    215 
    216 procedure TMessgExDlg.PaintBook(ca: TDpiCanvas; x, y, clPage, clCover: integer);
     216  MovieCancelled := True;
     217end;
     218
     219procedure TMessgExDlg.PaintBook(ca: TDpiCanvas; X, Y, clPage, clCover: Integer);
    217220const
    218221  xScrewed = 77;
     
    220223  wScrewed = 43;
    221224  hScrewed = 27;
     225type
     226  TScrewed = array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of Single;
    222227var
    223   ix, iy, xDst, yDst, dx, dy, xIcon, yIcon: integer;
     228  ix, iy, xDst, yDst, dx, dy, xIcon, yIcon: Integer;
    224229  BookRect: TRect;
    225   x1, xR, yR, share: single;
    226   Screwed: array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of single;
     230  x1, xR, yR, share: Single;
     231  Screwed: TScrewed;
    227232  SrcPtr: TPixelPointer;
    228233  Width: Integer;
     
    235240    yIcon := (IconIndex + SystemIconLines * 7) div 7 * ySizeBig;
    236241    // prepare screwed icon
    237     FillChar(Screwed, sizeof(Screwed), 0);
     242    Screwed := Default(TScrewed);
    238243    BigImp.BeginUpdate;
    239     SrcPtr := PixelPointer(BigImp, ScaleToNative(xIcon), ScaleToNative(yIcon));
     244    SrcPtr := TPixelPointer.Create(BigImp, ScaleToNative(xIcon), ScaleToNative(yIcon));
    240245    for iy := 0 to ScaleToNative(Height) - 1 do begin
    241246      for ix := 0 to ScaleToNative(Width) - 1 do begin
     
    277282    BookRect := SmallBook.BoundsRect;
    278283  end;
    279   x := x - BookRect.Width div 2;
     284  X := X - BookRect.Width div 2;
    280285
    281286  // paint
    282287  UnshareBitmap(LogoBuffer);
    283   DpiBitCanvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, ca, x, y);
     288  DpiBitBltCanvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, ca, X, Y);
    284289
    285290  if IconIndex >= 0 then
     
    294299  ImageOp_BCC(LogoBuffer, Templates.Data, Point(0, 0), BookRect, clCover, clPage);
    295300
    296   DpiBitCanvas(ca, x, y, BookRect.Width, BookRect.Height, LogoBuffer.Canvas, 0, 0);
     301  DpiBitBltCanvas(ca, X, Y, BookRect.Width, BookRect.Height, LogoBuffer.Canvas, 0, 0);
    297302end;
    298303
     
    303308procedure TMessgExDlg.PaintEnemyArmy;
    304309var
    305   emix, ix, iy, x, y, count, UnitsInLine: integer;
     310  emix, ix, iy, X, Y, count, UnitsInLine: Integer;
    306311begin
    307312  ix := 0;
     
    314319    for count := 0 to LostArmy[emix] - 1 do
    315320    begin
    316       x := ClientWidth div 2 + ix * 64 - UnitsInLine * 32;
    317       y := 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48;
     321      X := ClientWidth div 2 + ix * 64 - UnitsInLine * 32;
     322      Y := 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48;
    318323      with MyRO.EnemyModel[emix], Tribe[Owner].ModelPicture[mix] do
    319324      begin
    320         DpiBitCanvas(Canvas, x, y, 64, 48, HGr.Mask.Canvas,
     325        DpiBitBltCanvas(Canvas, X, Y, 64, 48, HGr.Mask.Canvas,
    321326          pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCAND);
    322         DpiBitCanvas(Canvas, x, y, 64, 48, HGr.Data.Canvas,
     327        DpiBitBltCanvas(Canvas, X, Y, 64, 48, HGr.Data.Canvas,
    323328          pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCPAINT);
    324329      end;
    325330
    326331      // next position
    327       inc(ix);
     332      Inc(ix);
    328333      if ix = LostUnitsPerLine then
    329334      begin // next line
    330335        ix := 0;
    331         inc(iy);
     336        Inc(iy);
    332337        if iy = 6 then
    333           exit;
     338          Exit;
    334339        UnitsInLine := nLostArmy - LostUnitsPerLine * iy;
    335340        if UnitsInLine > LostUnitsPerLine then
     
    341346procedure TMessgExDlg.FormPaint(Sender: TObject);
    342347var
    343   p1, clSaveTextLight, clSaveTextShade: integer;
     348  p1, clSaveTextLight, clSaveTextShade: Integer;
    344349begin
    345350  if (IconKind = mikImp) and (IconIndex = 27) then
     
    362367        p1 := MyRO.Wonder[IconIndex].EffectiveOwner;
    363368        UnshareBitmap(Buffer);
    364         DpiBitCanvas(Buffer.Canvas, 0, 0, xSizeBig + 2 * GlowRange,
     369        DpiBitBltCanvas(Buffer.Canvas, 0, 0, xSizeBig + 2 * GlowRange,
    365370          ySizeBig + 2 * GlowRange, Canvas,
    366371          ClientWidth div 2 - (28 + GlowRange), 24 - GlowRange);
    367         DpiBitCanvas(Buffer.Canvas, GlowRange, GlowRange, xSizeBig, ySizeBig,
     372        DpiBitBltCanvas(Buffer.Canvas, GlowRange, GlowRange, xSizeBig, ySizeBig,
    368373          BigImp.Canvas, IconIndex mod 7 * xSizeBig,
    369374          (IconIndex + SystemIconLines * 7) div 7 * ySizeBig);
     
    373378          GlowFrame(Buffer, GlowRange, GlowRange, xSizeBig, ySizeBig,
    374379            Tribe[p1].Color);
    375         DpiBitCanvas(Canvas, ClientWidth div 2 - (28 + GlowRange),
     380        DpiBitBltCanvas(Canvas, ClientWidth div 2 - (28 + GlowRange),
    376381          24 - GlowRange, xSizeBig + 2 * GlowRange, ySizeBig + 2 * GlowRange,
    377382          Buffer.Canvas, 0, 0);
     
    387392      end;
    388393    mikModel:
    389       with Tribe[me].ModelPicture[IconIndex] do
     394      with Tribe[Me].ModelPicture[IconIndex] do
    390395      begin
    391396        FrameImage(Canvas, BigImp, ClientWidth div 2 - 28, 24, xSizeBig,
    392397          ySizeBig, 0, 0);
    393         DpiBitCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,
     398        DpiBitBltCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,
    394399          HGr.Mask.Canvas, pix mod 10 * 65 + 1,
    395400          pix div 10 * 49 + 1, SRCAND);
    396         DpiBitCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,
     401        DpiBitBltCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,
    397402          HGr.Data.Canvas, pix mod 10 * 65 + 1,
    398403          pix div 10 * 49 + 1, SRCPAINT);
     
    406411        Frame(Canvas, ClientWidth div 2 - 32 - 1, 24 - 1,
    407412          ClientWidth div 2 + 32, 24 + 48, $000000, $000000);
    408         DpiBitCanvas(Canvas, ClientWidth div 2 - 32, 24, 64, 48,
     413        DpiBitBltCanvas(Canvas, ClientWidth div 2 - 32, 24, 64, 48,
    409414          Tribe[IconIndex].faceHGr.Data.Canvas,
    410415          1 + Tribe[IconIndex].facepix mod 10 * 65,
     
    420425    mikEnemyShipComplete:
    421426      begin
    422         DpiBitCanvas(Buffer.Canvas, 0, 0, 140, 120, Canvas,
     427        DpiBitBltCanvas(Buffer.Canvas, 0, 0, 140, 120, Canvas,
    423428          (ClientWidth - 140) div 2, 24);
    424429        ImageOp_BCC(Buffer, Templates.Data, Point(0, 0), StarshipDeparted.BoundsRect, 0, $FFFFFF);
    425         DpiBitCanvas(Canvas, (ClientWidth - 140) div 2, 24, 140, 120,
     430        DpiBitBltCanvas(Canvas, (ClientWidth - 140) div 2, 24, 140, 120,
    426431          Buffer.Canvas, 0, 0);
    427432      end;
     
    451456begin
    452457  if Kind = mkOkHelp then
    453     HelpDlg.ShowNewContent(wmSubmodal, HelpKind, HelpNo)
     458    MainScreen.HelpDlg.ShowNewContent(wmSubmodal, HelpKind, HelpNo)
    454459  else if Kind = mkModel then
    455     UnitStatDlg.ShowNewContent_OwnModel(wmSubmodal, IconIndex)
     460    MainScreen.UnitStatDlg.ShowNewContent_OwnModel(wmSubmodal, IconIndex)
    456461  else
    457462    ModalResult := mrIgnore;
     
    482487// because Messg.SoundMessage not capable of movie mode
    483488begin
    484   with MessgExDlg do
     489  with MainScreen.MessgExDlg do
    485490  begin
    486491    MessgText := SimpleText;
     
    491496end;
    492497
    493 procedure TribeMessage(p: integer; SimpleText, SoundItem: string);
    494 begin
    495   with MessgExDlg do
     498procedure TribeMessage(P: Integer; SimpleText, SoundItem: string);
     499begin
     500  with MainScreen.MessgExDlg do
    496501  begin
    497502    OpenSound := SoundItem;
     
    499504    Kind := mkOk;
    500505    IconKind := mikTribe;
    501     IconIndex := p;
     506    IconIndex := P;
    502507    ShowModal;
    503508  end;
     
    505510
    506511function SimpleQuery(QueryKind: TMessageKind; SimpleText, SoundItem: string)
    507   : integer;
    508 begin
    509   with MessgExDlg do
     512  : Integer;
     513begin
     514  with MainScreen.MessgExDlg do
    510515  begin
    511516    MessgText := SimpleText;
     
    513518    Kind := QueryKind;
    514519    ShowModal;
    515     result := ModalResult;
     520    Result := ModalResult;
    516521  end;
    517522end;
    518523
    519524procedure ContextMessage(SimpleText, SoundItem: string;
    520   ContextKind, ContextNo: integer);
    521 begin
    522   with MessgExDlg do
     525  ContextKind: TLinkCategory; ContextNo: Integer);
     526begin
     527  with MainScreen.MessgExDlg do
    523528  begin
    524529    MessgText := SimpleText;
     
    543548end;
    544549
    545 
    546 initialization
    547 
    548550end.
  • TabularUnified branches/highdpi/LocalPlayer/NatStat.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin,
    8 
    9   LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms,
    10   ButtonB, ButtonC, Menus, EOTButton;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, Controls, Forms, ButtonB, ButtonC, Menus, EOTButton;
    119
    1210type
     
    2725    procedure ToggleBtnClick(Sender: TObject);
    2826    procedure PlayerClick(Sender: TObject);
    29     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     27    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    3028    procedure FormDestroy(Sender: TObject);
    3129    procedure ScrollUpBtnClick(Sender: TObject);
    3230    procedure ScrollDownBtnClick(Sender: TObject);
    3331    procedure TellAIBtnClick(Sender: TObject);
    34 
    3532  public
    3633    procedure CheckAge;
    37     procedure ShowNewContent(NewMode: integer; p: integer = -1);
     34    procedure ShowNewContent(NewMode: TWindowMode; P: Integer = -1);
    3835    procedure EcoChange;
    39 
    4036  protected
    4137    procedure OffscreenPaint; override;
    42 
    4338  private
    44     pView, AgePrepared, LinesDown: integer;
    45     SelfReport, CurrentReport: PEnemyReport;
    46     ShowContact, ContactEnabled: boolean;
    47     Back, Template: TDpiBitmap;
     39    pView: Integer;
     40    AgePrepared: Integer;
     41    LinesDown: Integer;
     42    SelfReport: PEnemyReport;
     43    CurrentReport: PEnemyReport;
     44    ShowContact: Boolean;
     45    ContactEnabled: Boolean;
     46    Back: TDpiBitmap;
     47    Template: TDpiBitmap;
    4848    ReportText: TStringList;
    4949    procedure GenerateReportText;
    5050  end;
    5151
    52 var
    53   NatStatDlg: TNatStatDlg;
    5452
    5553implementation
     
    5856
    5957uses
    60   Messg, Tribes, Directories;
     58  Term, Messg, Tribes, Directories;
    6159
    6260const
     
    109107  if MainTexture.Age <> AgePrepared then begin
    110108    AgePrepared := MainTexture.Age;
    111     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
     109    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
    112110      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    113111      (MainTexture.Height - ClientHeight) div 2);
     
    118116procedure TNatStatDlg.FormShow(Sender: TObject);
    119117begin
    120   if pView = me then
     118  if pView = Me then
    121119  begin
    122120    SelfReport.TurnOfCivilReport := MyRO.Turn;
    123121    SelfReport.TurnOfMilReport := MyRO.Turn;
    124     move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));
     122    Move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));
    125123    SelfReport.Government := MyRO.Government;
    126124    SelfReport.Money := MyRO.Money;
    127     CurrentReport := pointer(SelfReport);
     125    CurrentReport := Pointer(SelfReport);
    128126  end
    129127  else
    130     CurrentReport := pointer(MyRO.EnemyReport[pView]);
     128    CurrentReport := Pointer(MyRO.EnemyReport[pView]);
    131129  if CurrentReport.TurnOfCivilReport >= 0 then
    132130    GenerateReportText;
    133   ShowContact := (pView <> me) and (not supervising or (me <> 0));
    134   ContactEnabled := ShowContact and not supervising and
     131  ShowContact := (pView <> Me) and (not Supervising or (Me <> 0));
     132  ContactEnabled := ShowContact and not Supervising and
    135133    (1 shl pView and MyRO.Alive <> 0);
    136134  ContactBtn.Visible := ContactEnabled and (MyRO.Happened and phGameEnd = 0) and
     
    150148end;
    151149
    152 procedure TNatStatDlg.ShowNewContent(NewMode, p: integer);
    153 begin
    154   if p < 0 then
     150procedure TNatStatDlg.ShowNewContent(NewMode: TWindowMode; P: Integer);
     151begin
     152  if P < 0 then
    155153    if ClientMode >= scContact then
    156       pView := DipMem[me].pContact
     154      pView := DipMem[Me].pContact
    157155    else
    158156    begin
     
    160158      while (pView < nPl) and ((MyRO.Treaty[pView] < trNone) or
    161159        (1 shl pView and MyRO.Alive = 0)) do
    162         inc(pView);
     160        Inc(pView);
    163161      if pView >= nPl then
    164         pView := me;
     162        pView := Me;
    165163    end
    166164  else
    167     pView := p;
     165    pView := P;
    168166  inherited ShowNewContent(NewMode);
    169167end;
     
    178176  List: ^TChart;
    179177
    180   function StatText(no: integer): string;
     178  function StatText(no: Integer): string;
    181179  var
    182     i: integer;
     180    I: Integer;
    183181  begin
    184182    if (CurrentReport.TurnOfCivilReport >= 0) and
    185       (Server(sGetChart + no shl 4, me, pView, List^) >= rExecuted) then
     183      (Server(sGetChart + no shl 4, Me, pView, List^) >= rExecuted) then
    186184    begin
    187       i := List[CurrentReport.TurnOfCivilReport];
     185      I := List[CurrentReport.TurnOfCivilReport];
    188186      case no of
    189187        stPop:
    190           result := Format(Phrases.Lookup('FRSTATPOP'), [i]);
     188          Result := Format(Phrases.Lookup('FRSTATPOP'), [I]);
    191189        stTerritory:
    192           result := Format(Phrases.Lookup('FRSTATTER'), [i]);
     190          Result := Format(Phrases.Lookup('FRSTATTER'), [I]);
    193191        stScience:
    194           result := Format(Phrases.Lookup('FRSTATTECH'), [i div nAdv]);
     192          Result := Format(Phrases.Lookup('FRSTATTECH'), [I div nAdv]);
    195193        stExplore:
    196           result := Format(Phrases.Lookup('FRSTATEXP'),
    197             [i * 100 div (G.lx * G.ly)]);
     194          Result := Format(Phrases.Lookup('FRSTATEXP'),
     195            [I * 100 div (G.lx * G.ly)]);
    198196      end;
    199     end
     197    end;
    200198  end;
    201199
    202200var
    203   p1, Treaty: integer;
    204   s: string;
    205   HasContact, ExtinctPart: boolean;
     201  p1, Treaty: Integer;
     202  S: string;
     203  HasContact, ExtinctPart: Boolean;
    206204begin
    207205  GetMem(List, 4 * (MyRO.Turn + 2));
     
    212210    (1 shl pView and MyRO.Alive <> 0) then
    213211  begin
    214     s := Format(Phrases.Lookup('FROLDCIVILREP'),
     212    S := Format(Phrases.Lookup('FROLDCIVILREP'),
    215213      [TurnToString(CurrentReport.TurnOfCivilReport)]);
    216     ReportText.Add('C' + s);
     214    ReportText.Add('C' + S);
    217215    ReportText.Add('');
    218216  end;
     
    227225  ReportText.Add('S' + StatText(stScience));
    228226  ReportText.Add('E' + StatText(stExplore));
    229   HasContact := false;
     227  HasContact := False;
    230228  for p1 := 0 to nPl - 1 do
    231     if (p1 <> me) and (CurrentReport.Treaty[p1] > trNoContact) then
    232       HasContact := true;
     229    if (p1 <> Me) and (CurrentReport.Treaty[p1] > trNoContact) then
     230      HasContact := True;
    233231  if HasContact then
    234232  begin
    235233    ReportText.Add('');
    236234    ReportText.Add(' ' + Phrases.Lookup('FRRELATIONS'));
    237     for ExtinctPart := false to true do
     235    for ExtinctPart := False to True do
    238236      for Treaty := trAlliance downto trNone do
    239237        for p1 := 0 to nPl - 1 do
    240           if (p1 <> me) and (CurrentReport.Treaty[p1] = Treaty) and
     238          if (p1 <> Me) and (CurrentReport.Treaty[p1] = Treaty) and
    241239            ((1 shl p1 and MyRO.Alive = 0) = ExtinctPart) then
    242240          begin
    243             s := Tribe[p1].TString(Phrases.Lookup('HAVETREATY', Treaty));
     241            S := Tribe[p1].TString(Phrases.Lookup('HAVETREATY', Treaty));
    244242            if ExtinctPart then
    245               s := '(' + s + ')';
    246             ReportText.Add(char(48 + Treaty) + s);
     243              S := '(' + S + ')';
     244            ReportText.Add(char(48 + Treaty) + S);
    247245          end;
    248246  end;
     
    254252procedure TNatStatDlg.OffscreenPaint;
    255253var
    256   i, y: integer;
    257   s: string;
    258   ps: pchar;
    259   Extinct: boolean;
    260 
     254  I, Y: Integer;
     255  S: string;
     256  ps: PChar;
     257  Extinct: Boolean;
    261258begin
    262259  inherited;
     
    264261  Extinct := 1 shl pView and MyRO.Alive = 0;
    265262
    266   DpiBitCanvas(offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
     263  DpiBitBltCanvas(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
    267264    Back.Canvas, 0, 0);
    268265
    269   offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    270   RisedTextout(offscreen.Canvas,
     266  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
     267  RisedTextout(Offscreen.Canvas,
    271268    40 { (ClientWidth-BiColorTextWidth(offscreen.canvas,caption)) div 2 } ,
    272269    7, Caption);
    273270
    274   offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    275 
    276   with offscreen do
     271  Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
     272
     273  with Offscreen do
    277274  begin
    278275    // show leader picture
     
    280277    if Assigned(Tribe[pView].faceHGr) then
    281278    begin
    282       Dump(offscreen, Tribe[pView].faceHGr, 18, yIcon - 4, 64, 48,
     279      Dump(Offscreen, Tribe[pView].faceHGr, 18, yIcon - 4, 64, 48,
    283280        1 + Tribe[pView].facepix mod 10 * 65,
    284281        1 + Tribe[pView].facepix div 10 * 49);
    285       frame(offscreen.Canvas, 18 - 1, yIcon - 4 - 1, 18 + 64, yIcon - 4 + 48,
     282      Frame(Offscreen.Canvas, 18 - 1, yIcon - 4 - 1, 18 + 64, yIcon - 4 + 48,
    286283        $000000, $000000);
    287284    end;
    288285
    289     if (pView = me) or not Extinct then
     286    if (pView = Me) or not Extinct then
    290287      LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib,
    291288        Phrases.Lookup('GOVERNMENT', CurrentReport.Government) +
    292289        Phrases.Lookup('FRAND'));
    293     if pView = me then
     290    if pView = Me then
    294291    begin
    295292      LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 19,
     
    305302          Phrases.Lookup('FREXTINCT'));
    306303        LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 28,
    307           TurnToString(CurrentReport.TurnOfCivilReport))
     304          TurnToString(CurrentReport.TurnOfCivilReport));
    308305      end
    309306      else
     
    318315      if MyRO.Treaty[pView] = trNoContact then
    319316      begin
    320         s := Phrases.Lookup('FRNOCONTACT');
     317        S := Phrases.Lookup('FRNOCONTACT');
    321318        LoweredTextOut(Canvas, -1, MainTexture,
    322           (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, yRelation + 9, s)
     319          (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, yRelation + 9, S);
    323320      end
    324321      else if ShowContact then
     
    344341        FrameImage(Canvas, BigImp, xIcon, yIcon, xSizeBig, ySizeBig, 0, 200)
    345342        { else if CurrentReport.Government=gAnarchy then
    346           FrameImage(canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,112,400,
     343          FrameImage(Canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,112,400,
    347344          ContactEnabled and (MyRO.Happened and phGameEnd=0) and (ClientMode<scContact))
    348345          else
    349           FrameImage(canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,
     346          FrameImage(Canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,
    350347          56*(CurrentReport.Government-1),40,
    351348          ContactEnabled and (MyRO.Happened and phGameEnd=0) and (ClientMode<scContact)) };
     
    365362      end;
    366363
    367       y := 0;
    368       for i := 0 to ReportText.Count - 1 do
    369       begin
    370         if (i >= LinesDown) and (i < LinesDown + ReportLines) then
     364      Y := 0;
     365      for I := 0 to ReportText.Count - 1 do
     366      begin
     367        if (I >= LinesDown) and (I < LinesDown + ReportLines) then
    371368        begin
    372           s := ReportText[i];
    373           if s <> '' then
     369          S := ReportText[I];
     370          if S <> '' then
    374371          begin
    375372            // LineType:=s[1];
    376             delete(s, 1, 1);
     373            Delete(S, 1, 1);
    377374            BiColorTextOut(Canvas, Colors.Canvas.Pixels[clkMisc, cliPaperText],
    378               $7F007F, xReport + 8, yReport + LineSpacing * y, s);
     375              $7F007F, xReport + 8, yReport + LineSpacing * Y, S);
    379376          end;
    380           inc(y);
    381         end
     377          Inc(Y);
     378        end;
    382379      end;
    383380    end
    384381    else
    385382    begin
    386       s := Phrases.Lookup('FRNOCIVILREP');
    387       RisedTextout(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
    388         yReport + hReport div 2 - 10, s);
     383      S := Phrases.Lookup('FRNOCIVILREP');
     384      RisedTextout(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
     385        yReport + hReport div 2 - 10, S);
    389386    end;
    390387
    391388    if soTellAI in OptionChecked then begin
    392       Server(sGetAIInfo, me, pView, ps);
     389      Server(sGetAIInfo, Me, pView, ps);
    393390      LoweredTextOut(Canvas, -1, MainTexture, 42, 445, ps);
    394391    end else
     
    396393        Phrases2.Lookup('MENU_TELLAI'));
    397394  end;
    398   ContactBtn.SetBack(offscreen.Canvas, ContactBtn.Left, ContactBtn.Top);
     395
     396  ContactBtn.SetBack(Offscreen.Canvas, ContactBtn.Left, ContactBtn.Top);
    399397
    400398  MarkUsedOffscreen(ClientWidth, ClientHeight);
    401 end; { OffscreenPaint }
     399end;
    402400
    403401procedure TNatStatDlg.CloseBtnClick(Sender: TObject);
    404402begin
    405   Close
     403  Close;
    406404end;
    407405
    408406procedure TNatStatDlg.DialogBtnClick(Sender: TObject);
    409407var
    410   ContactResult: integer;
     408  ContactResult: Integer;
    411409begin
    412410  ContactResult := MainScreen.DipCall(scContact + pView shl 4);
     
    416414      SoundMessage(Phrases.Lookup('FRCOLDWAR'), 'MSG_DEFAULT')
    417415    else if MyRO.Government = gAnarchy then
    418       SoundMessage(Tribe[me].TPhrase('FRMYANARCHY'), 'MSG_DEFAULT')
     416      SoundMessage(Tribe[Me].TPhrase('FRMYANARCHY'), 'MSG_DEFAULT')
    419417    else if ContactResult = eAnarchy then
    420418      if MyRO.Treaty[pView] >= trPeace then
    421419      begin
    422420        if MainScreen.ContactRefused(pView, 'FRANARCHY') then
    423           SmartUpdateContent
     421          SmartUpdateContent;
    424422      end
    425423      else
     
    427425  end
    428426  else
    429     Close
     427    Close;
    430428end;
    431429
    432430procedure TNatStatDlg.ToggleBtnClick(Sender: TObject);
    433431var
    434   p1, StartCount: integer;
    435   m: TDpiMenuItem;
    436   ExtinctPart: boolean;
     432  p1, StartCount: Integer;
     433  M: TDpiMenuItem;
     434  ExtinctPart: Boolean;
    437435begin
    438436  EmptyMenu(Popup.Items);
    439437
    440438  // own nation
    441   if G.Difficulty[me] <> 0 then
    442   begin
    443     m := TDpiMenuItem.Create(Popup);
    444     m.RadioItem := true;
    445     m.Caption := Tribe[me].TPhrase('TITLE_NATION');
    446     m.Tag := me;
    447     m.OnClick := PlayerClick;
    448     if me = pView then
    449       m.Checked := true;
    450     Popup.Items.Add(m);
     439  if G.Difficulty[Me] <> 0 then
     440  begin
     441    M := TDpiMenuItem.Create(Popup);
     442    M.RadioItem := True;
     443    M.Caption := Tribe[Me].TPhrase('TITLE_NATION');
     444    M.Tag := Me;
     445    M.OnClick := PlayerClick;
     446    if Me = pView then
     447      M.Checked := True;
     448    Popup.Items.Add(M);
    451449  end;
    452450
    453451  // foreign nations
    454   for ExtinctPart := false to true do
     452  for ExtinctPart := False to True do
    455453  begin
    456454    StartCount := Popup.Items.Count;
     
    460458        (1 shl p1 and MyRO.Alive <> 0) and (MyRO.Treaty[p1] >= trNone) then
    461459      begin
    462         m := TDpiMenuItem.Create(Popup);
    463         m.RadioItem := true;
    464         m.Caption := Tribe[p1].TPhrase('TITLE_NATION');
     460        M := TDpiMenuItem.Create(Popup);
     461        M.RadioItem := True;
     462        M.Caption := Tribe[p1].TPhrase('TITLE_NATION');
    465463        if ExtinctPart then
    466           m.Caption := '(' + m.Caption + ')';
    467         m.Tag := p1;
    468         m.OnClick := PlayerClick;
     464          M.Caption := '(' + M.Caption + ')';
     465        M.Tag := p1;
     466        M.OnClick := PlayerClick;
    469467        if p1 = pView then
    470           m.Checked := true;
    471         Popup.Items.Add(m);
     468          M.Checked := True;
     469        Popup.Items.Add(M);
    472470      end;
    473471    if (StartCount > 0) and (Popup.Items.Count > StartCount) then
    474472    begin // seperator
    475       m := TDpiMenuItem.Create(Popup);
    476       m.Caption := '-';
    477       Popup.Items.Insert(StartCount, m);
     473      M := TDpiMenuItem.Create(Popup);
     474      M.Caption := '-';
     475      Popup.Items.Insert(StartCount, M);
    478476    end;
    479477  end;
     
    482480end;
    483481
    484 procedure TNatStatDlg.FormKeyDown(Sender: TObject; var Key: word;
     482procedure TNatStatDlg.FormKeyDown(Sender: TObject; var Key: Word;
    485483  Shift: TShiftState);
    486484var
    487   i: integer;
     485  I: Integer;
    488486begin
    489487  if Key = VK_F9 then // my key
    490488  begin // toggle nation
    491     i := 0;
     489    I := 0;
    492490    repeat
    493491      pView := (pView + 1) mod nPl;
    494       inc(i);
    495     until (i >= nPl) or (1 shl pView and MyRO.Alive <> 0) and
     492      Inc(I);
     493    until (I >= nPl) or (1 shl pView and MyRO.Alive <> 0) and
    496494      (MyRO.Treaty[pView] >= trNone);
    497     if i >= nPl then
    498       pView := me;
     495    if I >= nPl then
     496      pView := Me;
    499497    Tag := pView;
    500498    PlayerClick(self); // no, this is not nice
    501499  end
    502500  else
    503     inherited
     501    inherited;
    504502end;
    505503
    506504procedure TNatStatDlg.EcoChange;
    507505begin
    508   if Visible and (pView = me) then
     506  if Visible and (pView = Me) then
    509507  begin
    510508    SelfReport.Government := MyRO.Government;
    511509    SelfReport.Money := MyRO.Money;
    512     SmartUpdateContent
    513   end
     510    SmartUpdateContent;
     511  end;
    514512end;
    515513
     
    518516  if LinesDown > 0 then
    519517  begin
    520     dec(LinesDown);
     518    Dec(LinesDown);
    521519    SmartUpdateContent;
    522   end
     520  end;
    523521end;
    524522
     
    527525  if LinesDown + ReportLines < ReportText.Count then
    528526  begin
    529     inc(LinesDown);
     527    Inc(LinesDown);
    530528    SmartUpdateContent;
    531   end
     529  end;
    532530end;
    533531
     
    540538  else
    541539    TellAIBtn.ButtonIndex := 2;
    542   SmartUpdateContent
     540  SmartUpdateContent;
    543541end;
    544542
  • TabularUnified branches/highdpi/LocalPlayer/Nego.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, ScreenTools, BaseWin, Protocol, Term, LCLType, SysUtils, Classes, Graphics,
     7  UDpiControls, ScreenTools, BaseWin, Protocol, LCLType, SysUtils, Classes, Graphics,
    88  Controls, Forms, ButtonA, ButtonB, ButtonN;
    99
     
    1515type
    1616  THistory = record
    17     n: Integer;
     17    N: Integer;
    1818    Text: array[0 .. MaxHistory - 1] of ansistring;
    1919  end;
    2020
    2121  TCommandAllowedEnum = scDipNoticeStart..scDipBreakStart;
     22  TPriceSet = set of $00..$FF;
    2223
    2324  { TNegoDlg }
     
    5960    procedure FormDestroy(Sender: TObject);
    6061    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
    61       Shift: TShiftState; X, Y: integer);
     62      Shift: TShiftState; X, Y: Integer);
    6263    procedure OkBtnClick(Sender: TObject);
    6364    procedure BwdBtnClick(Sender: TObject);
     
    6970    procedure OfferClick(Sender: TObject);
    7071    procedure FastBtnClick(Sender: TObject);
    71 
    7272  public
    7373    procedure Initiate; // first turn of negotiation, initiate
     
    7575    procedure Start; // next turn of negotiation
    7676    procedure OffscreenPaint; override;
    77     procedure ShowNewContent(NewMode: integer);
    78 
     77    procedure ShowNewContent(NewMode: TWindowMode);
    7978  private
    80     Page, DipCommand: integer;
     79    Page, DipCommand: Integer;
    8180    CurrentOffer: TOffer;
    8281    MyAllowed, OppoAllowed: TPriceSet;
     
    8483    History: array [0 .. nPl - 1] of THistory;
    8584    RomanFont: TDpiFont;
    86     Costs, Delivers: array [0 .. 11] of cardinal;
     85    Costs, Delivers: array [0 .. 11] of Cardinal;
    8786    procedure ResetCurrentOffer;
    8887    procedure BuildCurrentOffer;
    8988    procedure FindAllowed;
    9089    procedure SplitText(Text: string; Bounds: TRect);
    91     procedure PaintNationPicture(X, Y, p: integer);
     90    procedure PaintNationPicture(X, Y, P: Integer);
    9291    procedure SetButtonStates;
    9392  end;
    9493
    95 var
    96   NegoDlg: TNegoDlg;
    9794
    9895implementation
    9996
    10097uses
    101   Messg, ClientTools, Diplomacy, Inp, Select, NatStat, Tribes, MessgEx;
     98  Messg, ClientTools, Diplomacy, Inp, Select, NatStat, Tribes, MessgEx, Term;
    10299
    103100{$R *.lfm}
     
    136133    'VII', 'VIII', 'IX', 'X', 'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI');
    137134
    138   ButtonPrice: array [0 .. 11] of cardinal = (opChoose, opCivilReport,
     135  ButtonPrice: array [0 .. 11] of Cardinal = (opChoose, opCivilReport,
    139136    opMilReport, opMap, opAllTech, opAllTech, opAllModel, opMoney, opTreaty,
    140137    opLowTreaty, opShipParts, opShipParts);
     
    142139procedure TNegoDlg.FormCreate(Sender: TObject);
    143140var
    144   cix: integer;
     141  cix: Integer;
    145142begin
    146143  InitButtons;
     
    153150        BackGraphic := HGrSystem2.Data;
    154151        case Tag shr 8 of
    155           1:
    156             SmartHint := Phrases.Lookup('WANT', ButtonIndex - 6);
    157           2:
    158             SmartHint := Phrases.Lookup('OFFER', ButtonIndex - 6);
     152          1: SmartHint := Phrases.Lookup('WANT', ButtonIndex - 6);
     153          2: SmartHint := Phrases.Lookup('OFFER', ButtonIndex - 6);
    159154        end;
    160155      end;
    161156
    162   fillchar(History, sizeof(History), 0);
     157  FillChar(History, SizeOf(History), 0);
    163158  RomanFont := TDpiFont.Create;
    164159  RomanFont.Name := 'Times New Roman';
     
    184179procedure TNegoDlg.ResetCurrentOffer;
    185180var
    186   i: integer;
     181  I: Integer;
    187182begin
    188183  CurrentOffer.nDeliver := 0;
    189184  CurrentOffer.nCost := 0;
    190   for i := 0 to 11 do
    191     Costs[i] := $FFFFFFFF;
    192   for i := 0 to 11 do
    193     Delivers[i] := $FFFFFFFF;
    194 end;
    195 
    196 procedure TNegoDlg.ShowNewContent(NewMode: integer);
     185  for I := 0 to 11 do
     186    Costs[I] := $FFFFFFFF;
     187  for I := 0 to 11 do
     188    Delivers[I] := $FFFFFFFF;
     189end;
     190
     191procedure TNegoDlg.ShowNewContent(NewMode: TWindowMode);
    197192begin
    198193  inherited ShowNewContent(NewMode);
     
    202197  else
    203198    PassBtn.SmartHint := Phrases.Lookup('BTN_PASS');
    204   case MyRO.Treaty[DipMem[me].pContact] of
     199  case MyRO.Treaty[DipMem[Me].pContact] of
    205200    trNone:
    206201      begin
     
    238233begin
    239234  if ClientMode <> scDipStart then
    240     with History[me] do
    241     begin
    242       if n = MaxHistory then
    243       begin
    244         move(Text[2], Text[0], (MaxHistory - 2) * sizeof(integer));
    245         dec(n, 2);
     235    with History[Me] do
     236    begin
     237      if N = MaxHistory then
     238      begin
     239        Move(Text[2], Text[0], (MaxHistory - 2) * SizeOf(Integer));
     240        Dec(N, 2);
    246241      end;
    247       Text[n] := copy(DipCommandToString(DipMem[me].pContact, me,
    248         DipMem[me].FormerTreaty, DipMem[me].SentCommand, ClientMode,
    249         DipMem[me].SentOffer, ReceivedOffer), 1, 255);
    250       inc(n);
     242      Text[N] := Copy(DipCommandToString(DipMem[Me].pContact, Me,
     243        DipMem[Me].FormerTreaty, DipMem[Me].SentCommand, ClientMode,
     244        DipMem[Me].SentOffer, ReceivedOffer), 1, 255);
     245      Inc(N);
    251246    end;
    252   assert(History[me].n mod 2 = 1);
    253 
    254   Page := History[me].n;
     247  Assert(History[Me].N mod 2 = 1);
     248
     249  Page := History[Me].N;
    255250  FindAllowed;
    256251  ResetCurrentOffer;
     
    284279procedure TNegoDlg.SplitText(Text: string; Bounds: TRect);
    285280var
    286   nLines, Line, Start, Stop, OrdinaryStop, Indent, Y: integer;
    287   s: string;
    288   preview, Dot: boolean;
     281  nLines, Line, Start, Stop, OrdinaryStop, Indent, Y: Integer;
     282  S: string;
     283  preview, Dot: Boolean;
    289284begin
    290285  nLines := 0;
    291   for preview := true downto false do
     286  for preview := True downto False do
    292287  begin
    293288    Start := 1;
     
    296291    while Start < Length(Text) do
    297292    begin
    298       Dot := false;
     293      Dot := False;
    299294      if (Start = 1) or (Text[Start - 1] = '\') then
    300295        if Text[Start] = '-' then
    301296        begin
    302297          Indent := ListIndent;
    303           inc(Start);
     298          Inc(Start);
    304299          if Start = Length(Text) then
    305             break;
    306           Dot := true;
     300            Break;
     301          Dot := True;
    307302        end
    308303        else
     
    311306      while (Stop < Length(Text)) and (Text[Stop] <> '\') do
    312307      begin
    313         inc(Stop);
     308        Inc(Stop);
    314309        if BiColorTextWidth(Offscreen.Canvas,
    315           copy(Text, Start, Stop - Start + 1)) > Bounds.Right - Bounds.Left -
     310          Copy(Text, Start, Stop - Start + 1)) > Bounds.Right - Bounds.Left -
    316311          PaperBorder_Left - PaperBorder_Right - Indent then
    317312        begin
    318           dec(Stop);
    319           break
     313          Dec(Stop);
     314          Break
    320315        end;
    321316      end;
     
    325320        while (Text[OrdinaryStop + 1] <> ' ') and
    326321          (Text[OrdinaryStop + 1] <> '\') do
    327           dec(OrdinaryStop);
     322          Dec(OrdinaryStop);
    328323        if (OrdinaryStop + 1 - Start) * 2 >= Stop - Start then
    329324          Stop := OrdinaryStop
     
    335330          Sprite(Offscreen, HGrSystem, Bounds.Left + PaperBorder_Left +
    336331            (ListIndent - 14), Y + 7, 8, 8, 90, 16);
    337         s := copy(Text, Start, Stop - Start + 1);
     332        S := Copy(Text, Start, Stop - Start + 1);
    338333        BiColorTextOut(Offscreen.Canvas, Colors.Canvas.Pixels[clkMisc,
    339334          cliPaperText], $7F007F, Bounds.Left + PaperBorder_Left +
    340           Indent, Y, s);
     335          Indent, Y, S);
    341336      end;
    342       inc(Line);
     337      Inc(Line);
    343338      Start := Stop + 2;
    344339    end;
     
    349344procedure TNegoDlg.FindAllowed;
    350345var
    351   i: integer;
     346  I: Integer;
    352347begin
    353348  CommandAllowed := [scDipOffer - scDipStart];
    354349  if ClientMode <> scDipBreak then
    355     include(CommandAllowed, scDipBreak - scDipStart);
    356   if MyRO.Treaty[DipMem[me].pContact] >= trPeace then
    357     include(CommandAllowed, scDipCancelTreaty - scDipStart);
    358   if (ClientMode = scDipOffer) and (Server(scDipAccept - sExecute, me, 0, nil^)
     350    Include(CommandAllowed, scDipBreak - scDipStart);
     351  if MyRO.Treaty[DipMem[Me].pContact] >= trPeace then
     352    Include(CommandAllowed, scDipCancelTreaty - scDipStart);
     353  if (ClientMode = scDipOffer) and (Server(scDipAccept - sExecute, Me, 0, nil^)
    359354    >= rExecuted) then
    360     include(CommandAllowed, scDipAccept - scDipStart);
     355    Include(CommandAllowed, scDipAccept - scDipStart);
    361356
    362357  MyAllowed := [opChoose shr 24, opMoney shr 24];
    363358  OppoAllowed := [opChoose shr 24, opMoney shr 24];
    364   if not IsCivilReportNew(DipMem[me].pContact) then
     359  if not IsCivilReportNew(DipMem[Me].pContact) then
    365360  begin // no up-to-date civil report
    366361    MyAllowed := MyAllowed + [opCivilReport shr 24];
    367     for i := 0 to nAdv - 1 do
    368       if MyRO.Tech[i] >= tsApplicable then
     362    for I := 0 to nAdv - 1 do
     363      if MyRO.Tech[I] >= tsApplicable then
    369364      begin
    370365        MyAllowed := MyAllowed + [opAllTech shr 24];
    371         break
     366        Break
    372367      end;
    373368    OppoAllowed := OppoAllowed + [opCivilReport shr 24, opAllTech shr 24];
     
    375370  else
    376371  begin // check techs
    377     for i := 0 to nAdv - 1 do
    378       if not(i in FutureTech) then
    379         if (MyRO.Tech[i] < tsSeen) and
    380           (MyRO.EnemyReport[DipMem[me].pContact].Tech[i] >= tsApplicable) then
     372    for I := 0 to nAdv - 1 do
     373      if not(I in FutureTech) then
     374        if (MyRO.Tech[I] < tsSeen) and
     375          (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] >= tsApplicable) then
    381376          OppoAllowed := OppoAllowed + [opAllTech shr 24]
    382         else if (MyRO.EnemyReport[DipMem[me].pContact].Tech[i] < tsSeen) and
    383           (MyRO.Tech[i] >= tsApplicable) then
     377        else if (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] < tsSeen) and
     378          (MyRO.Tech[I] >= tsApplicable) then
    384379          MyAllowed := MyAllowed + [opAllTech shr 24];
    385380  end;
    386   if not IsMilReportNew(DipMem[me].pContact) then
     381  if not IsMilReportNew(DipMem[Me].pContact) then
    387382  begin // no up-to-date military report
    388383    MyAllowed := MyAllowed + [opMilReport shr 24];
     
    393388  else
    394389  begin
    395     if ModalSelectDlg.OnlyChoice(kChooseModel) <> mixAll then
     390    if MainScreen.ModalSelectDlg.OnlyChoice(kChooseModel) <> mixAll then
    396391      MyAllowed := MyAllowed + [opAllModel shr 24];
    397     if ModalSelectDlg.OnlyChoice(kChooseEModel) <> mixAll then
     392    if MainScreen.ModalSelectDlg.OnlyChoice(kChooseEModel) <> mixAll then
    398393      OppoAllowed := OppoAllowed + [opAllModel shr 24];
    399394  end;
    400   if MyRO.Treaty[DipMem[me].pContact] < trAlliance then
     395  if MyRO.Treaty[DipMem[Me].pContact] < trAlliance then
    401396  begin
    402397    MyAllowed := MyAllowed + [opTreaty shr 24, opMap shr 24];
     
    408403    OppoAllowed:=OppoAllowed+[opLowTreaty shr 24];
    409404    end; }
    410   for i := 0 to nShipPart - 1 do
    411   begin
    412     if MyRO.Ship[me].Parts[i] > 0 then
    413       include(MyAllowed, opShipParts shr 24);
    414     if MyRO.Ship[DipMem[me].pContact].Parts[i] > 0 then
    415       include(OppoAllowed, opShipParts shr 24);
    416   end;
    417   MyAllowed := MyAllowed - DipMem[me].DeliveredPrices *
     405  for I := 0 to nShipPart - 1 do
     406  begin
     407    if MyRO.Ship[Me].Parts[I] > 0 then
     408      Include(MyAllowed, opShipParts shr 24);
     409    if MyRO.Ship[DipMem[Me].pContact].Parts[I] > 0 then
     410      Include(OppoAllowed, opShipParts shr 24);
     411  end;
     412  MyAllowed := MyAllowed - DipMem[Me].DeliveredPrices *
    418413    [opAllTech shr 24, opAllModel shr 24, opCivilReport shr 24,
    419414    opMilReport shr 24, opMap shr 24];
    420   OppoAllowed := OppoAllowed - DipMem[me].ReceivedPrices *
     415  OppoAllowed := OppoAllowed - DipMem[Me].ReceivedPrices *
    421416    [opAllTech shr 24, opAllModel shr 24, opCivilReport shr 24,
    422417    opMilReport shr 24, opMap shr 24];
    423418end;
    424419
    425 procedure TNegoDlg.PaintNationPicture(X, Y, p: integer);
     420procedure TNegoDlg.PaintNationPicture(X, Y, P: Integer);
    426421begin
    427422  with Offscreen.Canvas do
    428423  begin
    429424    Pen.Color := $000000;
    430     Brush.Color := Tribe[p].Color;
     425    Brush.Color := Tribe[P].Color;
    431426    Rectangle(X - 6, Y - 1, X + 70, Y + 49);
    432427    Brush.Color := $000000;
    433     Tribe[p].InitAge(GetAge(p));
    434     if Assigned(Tribe[p].faceHGr) then
    435       Dump(Offscreen, Tribe[p].faceHGr, X, Y, 64, 48,
    436         1 + Tribe[p].facepix mod 10 * 65, 1 + Tribe[p].facepix div 10 * 49)
     428    Tribe[P].InitAge(GetAge(P));
     429    if Assigned(Tribe[P].faceHGr) then
     430      Dump(Offscreen, Tribe[P].faceHGr, X, Y, 64, 48,
     431        1 + Tribe[P].facepix mod 10 * 65, 1 + Tribe[P].facepix div 10 * 49)
    437432    else
    438433      FillRect(Rect(X, Y, X + 64, Y + 48));
     
    444439procedure TNegoDlg.SetButtonStates;
    445440var
    446   cix: integer;
    447   IsActionPage: boolean;
    448 begin
    449   IsActionPage := Page = History[me].n;
     441  cix: Integer;
     442  IsActionPage: Boolean;
     443begin
     444  IsActionPage := Page = History[Me].N;
    450445
    451446  AcceptBtn.Possible := IsActionPage and
     
    478473                (ButtonPrice[Tag and $FF] shr 24 in MyAllowed);
    479474              Lit := Delivers[Tag and $FF] <> $FFFFFFFF;
    480             end
     475            end;
    481476        end;
    482477end;
     
    484479procedure TNegoDlg.OffscreenPaint;
    485480var
    486   i, cred: integer;
    487   s: string;
    488   OkEnabled: boolean;
     481  I, cred: Integer;
     482  S: string;
     483  OkEnabled: Boolean;
    489484begin
    490485  if (OffscreenUser <> nil) and (OffscreenUser <> self) then
     
    493488  OffscreenUser := self;
    494489
    495   if (DipCommand >= 0) and (Page = History[me].n) then
    496     History[me].Text[History[me].n] :=
    497       copy(DipCommandToString(me, DipMem[me].pContact,
    498       MyRO.Treaty[DipMem[me].pContact], ClientMode, DipCommand, ReceivedOffer,
     490  if (DipCommand >= 0) and (Page = History[Me].N) then
     491    History[Me].Text[History[Me].N] :=
     492      Copy(DipCommandToString(Me, DipMem[Me].pContact,
     493      MyRO.Treaty[DipMem[Me].pContact], ClientMode, DipCommand, ReceivedOffer,
    499494      CurrentOffer), 1, 255);
    500495
    501   FwdBtn.Visible := Page < History[me].n;
     496  FwdBtn.Visible := Page < History[Me].N;
    502497  BwdBtn.Visible := Page >= 2;
    503   if Page < History[me].n then
    504     OkEnabled := false
     498  if Page < History[Me].N then
     499    OkEnabled := False
    505500  else if DipCommand = scDipOffer then
    506     OkEnabled := Server(scDipOffer - sExecute, me, 0, CurrentOffer) >= rExecuted
     501    OkEnabled := Server(scDipOffer - sExecute, Me, 0, CurrentOffer) >= rExecuted
    507502  else
    508503    OkEnabled := DipCommand >= 0;
     
    533528    yPad1 + 41 + 42 * 2, $FFFFFF, $B0B0B0);
    534529
    535   PaintNationPicture(xNationPicture0, yNationPicture, DipMem[me].pContact);
    536   PaintNationPicture(xNationPicture1, yNationPicture, me);
    537 
    538   if History[me].Text[Page - 1] <> '' then
     530  PaintNationPicture(xNationPicture0, yNationPicture, DipMem[Me].pContact);
     531  PaintNationPicture(xNationPicture1, yNationPicture, Me);
     532
     533  if History[Me].Text[Page - 1] <> '' then
    539534  begin
    540535    FillSeamless(Offscreen.Canvas, xText0, yText0, wText, hText, 0, 0, Paper);
    541     i := Page - 1;
    542     if History[me].Text[0] = '' then
    543       dec(i);
    544     if i < 16 then
     536    I := Page - 1;
     537    if History[Me].Text[0] = '' then
     538      Dec(I);
     539    if I < 16 then
    545540    begin
    546541      Offscreen.Canvas.Font.Assign(RomanFont);
    547542      Offscreen.Canvas.TextOut
    548         (xText0 + (wText - Offscreen.Canvas.TextWidth(RomanNo[i])) div 2,
    549         yText0 + (hText - Offscreen.Canvas.TextHeight(RomanNo[i])) div 2,
    550         RomanNo[i]);
     543        (xText0 + (wText - Offscreen.Canvas.TextWidth(RomanNo[I])) div 2,
     544        yText0 + (hText - Offscreen.Canvas.TextHeight(RomanNo[I])) div 2,
     545        RomanNo[I]);
    551546    end
    552547  end;
    553548  FillSeamless(Offscreen.Canvas, xText1, yText1, wText, hText, 0, 0, Paper);
    554   i := Page;
    555   if History[me].Text[0] = '' then
    556     dec(i);
    557   if i < 16 then
     549  I := Page;
     550  if History[Me].Text[0] = '' then
     551    Dec(I);
     552  if I < 16 then
    558553  begin
    559554    Offscreen.Canvas.Font.Assign(RomanFont);
    560555    Offscreen.Canvas.TextOut
    561       (xText1 + (wText - Offscreen.Canvas.TextWidth(RomanNo[i])) div 2,
    562       yText1 + (hText - Offscreen.Canvas.TextHeight(RomanNo[i])) div 2,
    563       RomanNo[i]);
     556      (xText1 + (wText - Offscreen.Canvas.TextWidth(RomanNo[I])) div 2,
     557      yText1 + (hText - Offscreen.Canvas.TextHeight(RomanNo[I])) div 2,
     558      RomanNo[I]);
    564559  end;
    565560  with Offscreen.Canvas do
    566561  begin
    567562    Brush.Color := MainTexture.ColorBevelShade;
    568     if History[me].Text[Page - 1] <> '' then
     563    if History[Me].Text[Page - 1] <> '' then
    569564    begin
    570565      FillRect(Rect(xText0 + wText, yText0 + PaperShade,
     
    584579  { if Page=History[me].n then
    585580    begin // show attitude
    586     s:=Phrases.Lookup('ATTITUDE',MyRO.EnemyReport[DipMem[me].pContact].Attitude);
     581    S:=Phrases.Lookup('ATTITUDE',MyRO.EnemyReport[DipMem[Me].pContact].Attitude);
    587582    //LoweredTextOut(Offscreen.Canvas,-1,MainTexture,
    588583    RisedTextOut(Offscreen.Canvas,xText0+wText div 2-
    589     BiColorTextWidth(Offscreen.Canvas,s) div 2,yAttitude,s);
    590     s:=Phrases.Lookup('ATTITUDE',MyRO.Attitude[DipMem[me].pContact]);
     584    BiColorTextWidth(Offscreen.Canvas,S) div 2,yAttitude,S);
     585    S:=Phrases.Lookup('ATTITUDE',MyRO.Attitude[DipMem[Me].pContact]);
    591586    //LoweredTextOut(Offscreen.Canvas,-1,MainTexture,
    592587    RisedTextOut(Offscreen.Canvas,xText1+wText div 2-
    593     BiColorTextWidth(Offscreen.Canvas,s) div 2,yAttitude,s);
     588    BiColorTextWidth(Offscreen.Canvas,S) div 2,yAttitude,S);
    594589    end; }
    595590
    596   if History[me].Text[Page - 1] <> '' then
    597     SplitText(History[me].Text[Page - 1], Rect(xText0, yText0, xText0 + wText,
     591  if History[Me].Text[Page - 1] <> '' then
     592    SplitText(History[Me].Text[Page - 1], Rect(xText0, yText0, xText0 + wText,
    598593      yText0 + hText));
    599   if (Page < History[me].n) or OkEnabled then
    600     SplitText(History[me].Text[Page], Rect(xText1, yText1, xText1 + wText,
     594  if (Page < History[Me].N) or OkEnabled then
     595    SplitText(History[Me].Text[Page], Rect(xText1, yText1, xText1 + wText,
    601596      yText1 + hText));
    602597
    603598  // show credibility
    604599  Offscreen.Canvas.Font.Assign(UniFont[ftTiny]);
    605   cred := MyRO.EnemyReport[DipMem[me].pContact].Credibility;
     600  cred := MyRO.EnemyReport[DipMem[Me].pContact].Credibility;
    606601  case cred of
    607602    0 .. 49:
    608       i := 3;
     603      I := 3;
    609604    50 .. 90:
    610       i := 0;
     605      I := 0;
    611606    91 .. 100:
    612       i := 1;
    613   end;
    614   PaintProgressBar(Offscreen.Canvas, i, xCred0, yCred0 + 17, (cred + 2) div 5,
     607      I := 1;
     608  end;
     609  PaintProgressBar(Offscreen.Canvas, I, xCred0, yCred0 + 17, (cred + 2) div 5,
    615610    0, 20, MainTexture);
    616   s := IntToStr(cred);
     611  S := IntToStr(cred);
    617612  RisedTextOut(Offscreen.Canvas, xCred0 + 10 -
    618     (BiColorTextWidth(Offscreen.Canvas, s) + 1) div 2, yCred0, s);
     613    (BiColorTextWidth(Offscreen.Canvas, S) + 1) div 2, yCred0, S);
    619614  case MyRO.Credibility of
    620615    0 .. 49:
    621       i := 3;
     616      I := 3;
    622617    50 .. 90:
    623       i := 0;
     618      I := 0;
    624619    91 .. 100:
    625       i := 1;
    626   end;
    627   PaintProgressBar(Offscreen.Canvas, i, xCred1, yCred1 + 17,
     620      I := 1;
     621  end;
     622  PaintProgressBar(Offscreen.Canvas, I, xCred1, yCred1 + 17,
    628623    (MyRO.Credibility + 2) div 5, 0, 20, MainTexture);
    629   s := IntToStr(MyRO.Credibility);
     624  S := IntToStr(MyRO.Credibility);
    630625  RisedTextOut(Offscreen.Canvas, xCred1 + 10 -
    631     (BiColorTextWidth(Offscreen.Canvas, s) + 1) div 2, yCred1, s);
     626    (BiColorTextWidth(Offscreen.Canvas, S) + 1) div 2, yCred1, S);
    632627
    633628  MarkUsedOffscreen(ClientWidth, ClientHeight);
    634 end; { OffscreenPaint }
     629end;
    635630
    636631procedure TNegoDlg.Initiate;
    637632begin
    638   History[me].n := 1;
    639   History[me].Text[0] := '';
     633  History[Me].N := 1;
     634  History[Me].Text[0] := '';
    640635end;
    641636
    642637procedure TNegoDlg.Respond;
    643638begin
    644   History[me].n := 0;
     639  History[Me].N := 0;
    645640end;
    646641
    647642procedure TNegoDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
    648   Shift: TShiftState; X, Y: integer);
     643  Shift: TShiftState; X, Y: Integer);
    649644begin
    650645  if (X >= xNationPicture0) and (X < xNationPicture0 + 64) and
    651646    (Y >= yNationPicture) and (Y < yNationPicture + 48) then
    652     NatStatDlg.ShowNewContent(FWindowMode or wmPersistent, DipMem[me].pContact)
     647    MainScreen.NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), DipMem[Me].pContact)
    653648  else if (X >= xNationPicture1) and (X < xNationPicture1 + 64) and
    654649    (Y >= yNationPicture) and (Y < yNationPicture + 48) then
    655     NatStatDlg.ShowNewContent(FWindowMode or wmPersistent, me)
     650    MainScreen.NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), Me)
    656651end;
    657652
    658653procedure TNegoDlg.BwdBtnClick(Sender: TObject);
    659654begin
    660   dec(Page, 2);
     655  Dec(Page, 2);
    661656  SetButtonStates;
    662657  SmartUpdateContent;
     
    665660procedure TNegoDlg.FwdBtnClick(Sender: TObject);
    666661begin
    667   inc(Page, 2);
     662  Inc(Page, 2);
    668663  SetButtonStates;
    669664  SmartUpdateContent;
     
    672667procedure TNegoDlg.OkBtnClick(Sender: TObject);
    673668begin
    674   inc(History[me].n);
     669  Inc(History[Me].N);
    675670  if DipCommand = scDipOffer then
    676671    MainScreen.OfferCall(CurrentOffer)
     
    698693procedure TNegoDlg.BuildCurrentOffer;
    699694var
    700   i: integer;
     695  I: Integer;
    701696begin
    702697  CurrentOffer.nDeliver := 0;
    703698  CurrentOffer.nCost := 0;
    704   for i := 0 to 11 do
    705     if Delivers[i] <> $FFFFFFFF then
    706     begin
    707       CurrentOffer.Price[CurrentOffer.nDeliver] := Delivers[i];
    708       inc(CurrentOffer.nDeliver);
     699  for I := 0 to 11 do
     700    if Delivers[I] <> $FFFFFFFF then
     701    begin
     702      CurrentOffer.Price[CurrentOffer.nDeliver] := Delivers[I];
     703      Inc(CurrentOffer.nDeliver);
    709704    end;
    710   for i := 0 to 11 do
    711     if Costs[i] <> $FFFFFFFF then
     705  for I := 0 to 11 do
     706    if Costs[I] <> $FFFFFFFF then
    712707    begin
    713708      CurrentOffer.Price[CurrentOffer.nDeliver + CurrentOffer.nCost] :=
    714         Costs[i];
    715       inc(CurrentOffer.nCost);
     709        Costs[I];
     710      Inc(CurrentOffer.nCost);
    716711    end;
    717712end;
     
    719714procedure TNegoDlg.WantClick(Sender: TObject);
    720715var
    721   a, i, max: integer;
    722   Price: cardinal;
    723 begin
    724   if (Page <> History[me].n) or (ClientMode = scDipCancelTreaty) or
     716  A, I, Max: Integer;
     717  Price: Cardinal;
     718begin
     719  if (Page <> History[Me].N) or (ClientMode = scDipCancelTreaty) or
    725720    (ClientMode = scDipBreak) then
    726     exit;
     721    Exit;
    727722  if Costs[TButtonN(Sender).Tag and $FF] <> $FFFFFFFF then
    728723    Price := $FFFFFFFF // toggle off
     
    732727    begin
    733728      SimpleMessage(Phrases.Lookup('MAX2WANTS'));
    734       exit
     729      Exit;
    735730    end;
    736731    Price := ButtonPrice[TButtonN(Sender).Tag and $FF];
    737732    if not(Price shr 24 in OppoAllowed) then
    738       exit;
     733      Exit;
    739734    case Price of
    740735      opCivilReport, opMilReport:
    741         inc(Price, DipMem[me].pContact shl 16 + MyRO.Turn);
     736        Inc(Price, DipMem[Me].pContact shl 16 + MyRO.Turn);
    742737        // !!! choose player and year!
    743738      opMoney:
     
    748743          InputDlg.ShowModal;
    749744          if InputDlg.ModalResult <> mrOK then
    750             exit;
    751           val(InputDlg.EInput.Text, a, i);
    752           if (i <> 0) or (a <= 0) or (a >= MaxMoneyPrice) then
    753             exit;
    754           inc(Price, a);
     745            Exit;
     746          val(InputDlg.EInput.Text, A, I);
     747          if (I <> 0) or (A <= 0) or (A >= MaxMoneyPrice) then
     748            Exit;
     749          Inc(Price, A);
    755750        end;
    756751      opShipParts:
    757752        begin // choose type and number
    758753          if MyRO.NatBuilt[imSpacePort] = 0 then
    759             with MessgExDlg do
     754            with MainScreen.MessgExDlg do
    760755            begin
    761756              OpenSound := 'WARNING_LOWSUPPORT';
     
    766761              ShowModal;
    767762              if ModalResult <> mrOK then
    768                 exit
     763                Exit;
    769764            end;
    770           ModalSelectDlg.ShowNewContent(wmModal, kEShipPart);
    771           if ModalSelectDlg.result < 0 then
    772             exit;
    773           inc(Price, ModalSelectDlg.result shl 16);
    774           max := MyRO.Ship[DipMem[me].pContact].Parts[ModalSelectDlg.result];
     765          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kEShipPart);
     766          if MainScreen.ModalSelectDlg.Result < 0 then
     767            Exit;
     768          Inc(Price, MainScreen.ModalSelectDlg.Result shl 16);
     769          Max := MyRO.Ship[DipMem[Me].pContact].Parts[MainScreen.ModalSelectDlg.Result];
    775770          InputDlg.Caption := Phrases.Lookup('TITLE_NUMBER');
    776771          InputDlg.EInput.Text := '';
     
    778773          InputDlg.ShowModal;
    779774          if InputDlg.ModalResult <> mrOK then
    780             exit;
    781           val(InputDlg.EInput.Text, a, i);
    782           if (i <> 0) or (a <= 0) then
    783             exit;
    784           if a > max then
    785             a := max;
    786           if a > MaxShipPartPrice then
    787             a := MaxShipPartPrice;
    788           inc(Price, a)
     775            Exit;
     776          val(InputDlg.EInput.Text, A, I);
     777          if (I <> 0) or (A <= 0) then
     778            Exit;
     779          if A > Max then
     780            A := Max;
     781          if A > MaxShipPartPrice then
     782            A := MaxShipPartPrice;
     783          Inc(Price, A);
    789784        end;
    790785      opAllTech:
    791786        begin // choose technology
    792           ModalSelectDlg.ShowNewContent(wmModal, kChooseETech);
    793           if ModalSelectDlg.result < 0 then
    794             exit;
    795           if ModalSelectDlg.result = adAll then
     787          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kChooseETech);
     788          if MainScreen.ModalSelectDlg.Result < 0 then
     789            Exit;
     790          if MainScreen.ModalSelectDlg.Result = adAll then
    796791            Price := opAllTech
    797792          else
    798             Price := OpTech + ModalSelectDlg.result;
     793            Price := OpTech + MainScreen.ModalSelectDlg.Result;
    799794        end;
    800795      opAllModel:
    801796        begin // choose model
    802           ModalSelectDlg.ShowNewContent(wmModal, kChooseEModel);
    803           if ModalSelectDlg.result < 0 then
    804             exit;
    805           if ModalSelectDlg.result = mixAll then
     797          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kChooseEModel);
     798          if MainScreen.ModalSelectDlg.Result < 0 then
     799            Exit;
     800          if MainScreen.ModalSelectDlg.Result = mixAll then
    806801            Price := opAllModel
    807802          else
    808             Price := OpModel + MyRO.EnemyModel[ModalSelectDlg.result].mix;
     803            Price := OpModel + MyRO.EnemyModel[MainScreen.ModalSelectDlg.Result].mix;
    809804        end;
    810805      opTreaty:
    811806        begin
    812           if MyRO.Treaty[DipMem[me].pContact] < trPeace then
     807          if MyRO.Treaty[DipMem[Me].pContact] < trPeace then
    813808            Price := opTreaty + trPeace
    814809          else
    815             Price := opTreaty + MyRO.Treaty[DipMem[me].pContact] + 1;
     810            Price := opTreaty + MyRO.Treaty[DipMem[Me].pContact] + 1;
    816811        end;
    817812      { opLowTreaty:
    818813        begin
    819         if MyRO.Treaty[DipMem[me].pContact]=trNone then Price:=opTreaty+trCeaseFire
    820         else Price:=opTreaty+MyRO.Treaty[DipMem[me].pContact]-1;
     814        if MyRO.Treaty[DipMem[Me].pContact]=trNone then Price:=opTreaty+trCeaseFire
     815        else Price:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1;
    821816        end }
    822817    end;
     
    832827procedure TNegoDlg.OfferClick(Sender: TObject);
    833828var
    834   a, i, max: integer;
    835   Price: cardinal;
    836 begin
    837   if (Page <> History[me].n) or (ClientMode = scDipCancelTreaty) or
     829  A, I, Max: Integer;
     830  Price: Cardinal;
     831begin
     832  if (Page <> History[Me].N) or (ClientMode = scDipCancelTreaty) or
    838833    (ClientMode = scDipBreak) then
    839     exit;
     834    Exit;
    840835  if Delivers[TButtonN(Sender).Tag and $FF] <> $FFFFFFFF then
    841836    Price := $FFFFFFFF // toggle off
     
    845840    begin
    846841      SimpleMessage(Phrases.Lookup('MAX2OFFERS'));
    847       exit
     842      Exit;
    848843    end;
    849844    Price := ButtonPrice[TButtonN(Sender).Tag and $FF];
    850845    if not(Price shr 24 in MyAllowed) then
    851       exit;
     846      Exit;
    852847    case Price of
    853848      opCivilReport, opMilReport:
    854         inc(Price, me shl 16 + MyRO.Turn); // !!! choose player and year!
     849        Inc(Price, Me shl 16 + MyRO.Turn); // !!! choose player and year!
    855850      opMoney:
    856851        begin // choose amount
     
    860855          InputDlg.ShowModal;
    861856          if InputDlg.ModalResult <> mrOK then
    862             exit;
    863           val(InputDlg.EInput.Text, a, i);
    864           if (i <> 0) or (a <= 0) or (a >= MaxMoneyPrice) then
    865             exit;
    866           if (Price = opMoney) and (a > MyRO.Money) then
    867             a := MyRO.Money;
    868           inc(Price, a);
     857            Exit;
     858          val(InputDlg.EInput.Text, A, I);
     859          if (I <> 0) or (A <= 0) or (A >= MaxMoneyPrice) then
     860            Exit;
     861          if (Price = opMoney) and (A > MyRO.Money) then
     862            A := MyRO.Money;
     863          Inc(Price, A);
    869864        end;
    870865      opShipParts:
    871866        begin // choose type and number
    872           ModalSelectDlg.ShowNewContent(wmModal, kShipPart);
    873           if ModalSelectDlg.result < 0 then
    874             exit;
    875           inc(Price, ModalSelectDlg.result shl 16);
    876           max := MyRO.Ship[me].Parts[ModalSelectDlg.result];
     867          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kShipPart);
     868          if MainScreen.ModalSelectDlg.Result < 0 then
     869            Exit;
     870          Inc(Price, MainScreen.ModalSelectDlg.Result shl 16);
     871          Max := MyRO.Ship[Me].Parts[MainScreen.ModalSelectDlg.Result];
    877872          InputDlg.Caption := Phrases.Lookup('TITLE_NUMBER');
    878873          InputDlg.EInput.Text := '';
     
    880875          InputDlg.ShowModal;
    881876          if InputDlg.ModalResult <> mrOK then
    882             exit;
    883           val(InputDlg.EInput.Text, a, i);
    884           if (i <> 0) or (a <= 0) then
    885             exit;
    886           if a > max then
    887             a := max;
    888           if a > MaxShipPartPrice then
    889             a := MaxShipPartPrice;
    890           inc(Price, a)
     877            Exit;
     878          val(InputDlg.EInput.Text, A, I);
     879          if (I <> 0) or (A <= 0) then
     880            Exit;
     881          if A > Max then
     882            A := Max;
     883          if A > MaxShipPartPrice then
     884            A := MaxShipPartPrice;
     885          Inc(Price, A);
    891886        end;
    892887      opAllTech:
    893888        begin // choose technology
    894           ModalSelectDlg.ShowNewContent(wmModal, kChooseTech);
    895           if ModalSelectDlg.result < 0 then
    896             exit;
    897           if ModalSelectDlg.result = adAll then
     889          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kChooseTech);
     890          if MainScreen.ModalSelectDlg.Result < 0 then
     891            Exit;
     892          if MainScreen.ModalSelectDlg.Result = adAll then
    898893            Price := opAllTech
    899894          else
    900             Price := OpTech + ModalSelectDlg.result;
     895            Price := OpTech + MainScreen.ModalSelectDlg.Result;
    901896        end;
    902897      opAllModel:
    903898        begin // choose model
    904           ModalSelectDlg.ShowNewContent(wmModal, kChooseModel);
    905           if ModalSelectDlg.result < 0 then
    906             exit;
    907           if ModalSelectDlg.result = mixAll then
     899          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kChooseModel);
     900          if MainScreen.ModalSelectDlg.Result < 0 then
     901            Exit;
     902          if MainScreen.ModalSelectDlg.Result = mixAll then
    908903            Price := opAllModel
    909904          else
    910             Price := OpModel + ModalSelectDlg.result
     905            Price := OpModel + MainScreen.ModalSelectDlg.Result;
    911906        end;
    912907      opTreaty:
    913908        begin
    914           if MyRO.Treaty[DipMem[me].pContact] < trPeace then
     909          if MyRO.Treaty[DipMem[Me].pContact] < trPeace then
    915910            Price := opTreaty + trPeace
    916911          else
    917             Price := opTreaty + MyRO.Treaty[DipMem[me].pContact] + 1;
     912            Price := opTreaty + MyRO.Treaty[DipMem[Me].pContact] + 1;
    918913        end;
    919914      { opLowTreaty:
    920915        begin
    921         if MyRO.Treaty[DipMem[me].pContact]=trNone then Price:=opTreaty+trCeaseFire
    922         else Price:=opTreaty+MyRO.Treaty[DipMem[me].pContact]-1;
     916        if MyRO.Treaty[DipMem[Me].pContact]=trNone then Price:=opTreaty+trCeaseFire
     917        else Price:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1;
    923918        end }
    924919    end;
     
    934929procedure TNegoDlg.FastBtnClick(Sender: TObject);
    935930var
    936   NewCommand: cardinal;
    937 begin
    938   if Page <> History[me].n then
    939     exit;
     931  NewCommand: Cardinal;
     932begin
     933  if Page <> History[Me].N then
     934    Exit;
    940935  NewCommand := TButtonN(Sender).Tag and $FF + scDipStart;
    941936  if not(NewCommand - scDipStart in CommandAllowed) then
    942     exit;
     937    Exit;
    943938  if (NewCommand = scDipCancelTreaty) and
    944     (MyRO.Turn < MyRO.LastCancelTreaty[DipMem[me].pContact] + CancelTreatyTurns)
     939    (MyRO.Turn < MyRO.LastCancelTreaty[DipMem[Me].pContact] + CancelTreatyTurns)
    945940  then
    946941  begin
    947942    SimpleMessage(Phrases.Lookup('CANCELTREATYRUSH'));
    948     exit;
     943    Exit;
    949944  end;
    950945  if (NewCommand = scDipOffer) and ((ClientMode = scDipCancelTreaty) or
  • TabularUnified branches/highdpi/LocalPlayer/PVSB.pas

    r349 r465  
    55
    66uses
    7   UDpiControls, {$IFDEF WINDOWS}
    8   Windows,
    9   {$ENDIF}
     7  UDpiControls, {$IFDEF WINDOWS}Windows,{$ENDIF}
    108  Classes, Controls, Forms, LCLIntf, LCLType, LMessages, Messages, SysUtils,
    119  StdCtrls, Math;
     
    3230    procedure Init(Max, PageSize: Integer);
    3331    procedure SetPos(Pos: Integer);
    34     function Process(const Msg: TMessage): boolean;
     32    function Process(const Msg: TMessage): Boolean;
    3533    function ProcessMouseWheel(Delta: Integer): Boolean;
    36     procedure Show(Visible: boolean);
     34    procedure Show(Visible: Boolean);
    3735    procedure EndSB;
    3836    procedure SetBorderSpacing(Top, Right, Bottom: Integer);
     
    6563end;
    6664
    67 function TPVScrollBar.Process(const Msg: TMessage): boolean;
     65function TPVScrollBar.Process(const Msg: TMessage): Boolean;
    6866var
    69   NewPos: integer;
     67  NewPos: Integer;
    7068begin
    7169    if Max < ScrollBar.PageSize then
    72       result := false
     70      Result := False
    7371    else
    7472    begin
    7573      if (Msg.wParam and $ffff) in [SB_THUMBPOSITION, SB_THUMBTRACK] then
    7674      begin
    77         result := ((Msg.wParam shr 16) and $ffff) <> ScrollBar.Position;
     75        Result := ((Msg.wParam shr 16) and $ffff) <> ScrollBar.Position;
    7876        ScrollBar.Position := (Msg.wParam shr 16) and $ffff;
    7977      end else begin
     
    9492        if NewPos > Max - ScrollBar.PageSize + 1 then
    9593          NewPos := Max - ScrollBar.PageSize + 1;
    96         result := NewPos <> ScrollBar.Position;
     94        Result := NewPos <> ScrollBar.Position;
    9795        if (NewPos <> ScrollBar.Position) or ((Msg.wParam and $ffff) = SB_ENDSCROLL) then
    9896        begin
     
    105103function TPVScrollBar.ProcessMouseWheel(Delta: Integer): Boolean;
    106104var
    107   NewPos: integer;
     105  NewPos: Integer;
    108106begin
    109107    if Max < ScrollBar.PageSize then Result := False
     
    120118end;
    121119
    122 procedure TPVScrollBar.Show(Visible: boolean);
     120procedure TPVScrollBar.Show(Visible: Boolean);
    123121begin
    124122  if not Visible or (Max < ScrollBar.PageSize) then
  • TabularUnified branches/highdpi/LocalPlayer/Rates.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, Protocol, ScreenTools, BaseWin, LCLIntf, LCLType,
    8 
    9   SysUtils, Classes, Graphics, Controls, Forms,
    10   ButtonB, ButtonC;
     7  UDpiControls, Protocol, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils, Classes, Graphics,
     8  Controls, Forms, ButtonB, ButtonC;
    119
    1210type
     
    2321  public
    2422    procedure OffscreenPaint; override;
    25     procedure ShowNewContent(NewMode: integer);
    26   end;
    27 
    28 var
    29   RatesDlg: TRatesDlg;
     23    procedure ShowNewContent(NewMode: TWindowMode);
     24  end;
     25
    3026
    3127implementation
     
    4743procedure TRatesDlg.OffscreenPaint;
    4844var
    49   p, x, y, current, max, i: integer;
    50   s, s1: string;
     45  P, X, Y, current, Max, I: Integer;
     46  S, s1: string;
    5147begin
    5248  if (OffscreenUser <> nil) and (OffscreenUser <> self) then
     
    6561  BtnFrame(Offscreen.Canvas, CloseBtn.BoundsRect, MainTexture);
    6662  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    67   s := Phrases.Lookup('TITLE_RATES');
     63  S := Phrases.Lookup('TITLE_RATES');
    6864  RisedTextOut(Offscreen.Canvas,
    69     (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s)) div 2 - 1, 7, s);
    70 
    71   if MyRO.Wonder[woLiberty].EffectiveOwner = me then
    72     s := Phrases.Lookup('NORATES')
    73   else
    74     s := Phrases.Lookup('RATES');
     65    (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2 - 1, 7, S);
     66
     67  if MyRO.Wonder[woLiberty].EffectiveOwner = Me then
     68    S := Phrases.Lookup('NORATES')
     69  else
     70    S := Phrases.Lookup('RATES');
    7571  Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    76   p := pos('\', s);
    77   if p = 0 then
    78     RisedTextOut(Offscreen.Canvas, (ClientWidth - BiColorTextWidth(Canvas, s))
    79       div 2, 114, s)
    80   else
    81   begin
    82     s1 := copy(s, 1, p - 1);
     72  P := Pos('\', S);
     73  if P = 0 then
     74    RisedTextOut(Offscreen.Canvas, (ClientWidth - BiColorTextWidth(Canvas, S))
     75      div 2, 114, S)
     76  else
     77  begin
     78    s1 := Copy(S, 1, P - 1);
    8379    RisedTextOut(Offscreen.Canvas,
    8480      (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s1)) div 2,
    8581      114 - MessageLineSpacing div 2, s1);
    86     s1 := copy(s, p + 1, 255);
     82    s1 := Copy(S, P + 1, 255);
    8783    RisedTextOut(Offscreen.Canvas,
    8884      (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s1)) div 2,
     
    9187  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    9288
    93   if MyRO.Wonder[woLiberty].EffectiveOwner = me then
     89  if MyRO.Wonder[woLiberty].EffectiveOwner = Me then
    9490  begin
    9591    GlowFrame(Offscreen, ClientWidth div 2 - xSizeBig div 2, 52, xSizeBig,
    96       ySizeBig, Tribe[me].Color);
    97     DpiBitCanvas(Offscreen.Canvas, ClientWidth div 2 - xSizeBig div 2, 52,
     92      ySizeBig, Tribe[Me].Color);
     93    DpiBitBltCanvas(Offscreen.Canvas, ClientWidth div 2 - xSizeBig div 2, 52,
    9894      xSizeBig, ySizeBig, BigImp.Canvas, (woLiberty mod 7) * xSizeBig,
    9995      (woLiberty div 7 + SystemIconLines) * ySizeBig);
     
    10399    // ImageOp_CBC(Offscreen,Templates,260,40,145,112,36,36,$404000,$8B8BEB);
    104100
    105     s := Phrases.Lookup('SCIENCE');
    106     RisedTextOut(Offscreen.Canvas,
    107       16 + 120 - BiColorTextWidth(Offscreen.Canvas, s), 44, s);
    108     s := Format('%d%%', [100 - MyRO.TaxRate - MyRO.LuxRate]);
    109     RisedTextOut(Offscreen.Canvas,
    110       16 + 120 - BiColorTextWidth(Offscreen.Canvas, s), 60, s);
     101    S := Phrases.Lookup('SCIENCE');
     102    RisedTextOut(Offscreen.Canvas,
     103      16 + 120 - BiColorTextWidth(Offscreen.Canvas, S), 44, S);
     104    S := Format('%d%%', [100 - MyRO.TaxRate - MyRO.LuxRate]);
     105    RisedTextOut(Offscreen.Canvas,
     106      16 + 120 - BiColorTextWidth(Offscreen.Canvas, S), 60, S);
    111107    // PaintProgressBar(Offscreen.Canvas,2,16,81,(100-MyRO.LuxRate-MyRO.TaxRate)*120 div 100,0,120,MainTexture);
    112108
    113109    // reverse progress bar for science
    114     x := 16;
    115     y := 81;
     110    X := 16;
     111    Y := 81;
    116112    current := (100 - MyRO.LuxRate - MyRO.TaxRate) * 120 div 100;
    117     max := 120;
    118     Frame(Offscreen.Canvas, x - 1, y - 1, x + max, y + 7, $000000, $000000);
    119     RFrame(Offscreen.Canvas, x - 2, y - 2, x + max + 1, y + 8,
     113    Max := 120;
     114    Frame(Offscreen.Canvas, X - 1, Y - 1, X + Max, Y + 7, $000000, $000000);
     115    RFrame(Offscreen.Canvas, X - 2, Y - 2, X + Max + 1, Y + 8,
    120116      MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    121117    with Offscreen.Canvas do
    122118    begin
    123       for i := 0 to current div 8 - 1 do
    124         DpiBitCanvas(Offscreen.Canvas, x + max - 8 - i * 8, y, 8, 7,
     119      for I := 0 to current div 8 - 1 do
     120        DpiBitBltCanvas(Offscreen.Canvas, X + Max - 8 - I * 8, Y, 8, 7,
    125121          HGrSystem.Data.Canvas, 104, 9 + 8 * 2);
    126       DpiBitCanvas(Offscreen.Canvas, x + max - current, y, current - 8 * (current div 8), 7,
     122      DpiBitBltCanvas(Offscreen.Canvas, X + Max - current, Y, current - 8 * (current div 8), 7,
    127123        HGrSystem.Data.Canvas, 104, 9 + 8 * 2);
    128124      Brush.Color := $000000;
    129       FillRect(Rect(x, y, x + max - current, y + 7));
     125      FillRect(Rect(X, Y, X + Max - current, Y + 7));
    130126      Brush.Style := bsClear;
    131127    end;
    132128
    133129    RisedTextOut(Offscreen.Canvas, 16 + 160, 44, Phrases.Lookup('LUX'));
    134     s := Format('%d%%', [MyRO.LuxRate]);
    135     RisedTextOut(Offscreen.Canvas,
    136       16 + 160 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 60, s);
     130    S := Format('%d%%', [MyRO.LuxRate]);
     131    RisedTextOut(Offscreen.Canvas,
     132      16 + 160 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 60, S);
    137133    PaintProgressBar(Offscreen.Canvas, 5, 16 + 160, 81,
    138134      MyRO.LuxRate * 120 div 100, 0, 120, MainTexture);
     
    145141    MainTexture.ColorBevelLight);
    146142  RisedTextOut(Offscreen.Canvas, 16 + 80, 164, Phrases.Lookup('TAXRATE'));
    147   s := Format('%d%%', [MyRO.TaxRate]);
     143  S := Format('%d%%', [MyRO.TaxRate]);
    148144  RisedTextOut(Offscreen.Canvas,
    149     16 + 80 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 180, s);
     145    16 + 80 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 180, S);
    150146  PaintProgressBar(Offscreen.Canvas, 0, 16 + 80, 201,
    151147    MyRO.TaxRate * 120 div 100, 0, 120, MainTexture);
     
    157153end;
    158154
    159 procedure TRatesDlg.ShowNewContent(NewMode: integer);
     155procedure TRatesDlg.ShowNewContent(NewMode: TWindowMode);
    160156begin
    161157  inherited ShowNewContent(NewMode);
     
    164160procedure TRatesDlg.FormShow(Sender: TObject);
    165161begin
    166   if MyRO.Wonder[woLiberty].EffectiveOwner = me then
    167   begin
    168     ScienceBtn.Visible := false;
    169     LuxBtn.Visible := false;
     162  Caption := Phrases.Lookup('TITLE_RATES');
     163  if MyRO.Wonder[woLiberty].EffectiveOwner = Me then
     164  begin
     165    ScienceBtn.Visible := False;
     166    LuxBtn.Visible := False;
    170167  end
    171168  else
    172169  begin
    173     ScienceBtn.Visible := true;
    174     LuxBtn.Visible := true;
     170    ScienceBtn.Visible := True;
     171    LuxBtn.Visible := True;
    175172  end;
    176173  OffscreenPaint;
     
    184181procedure TRatesDlg.TaxLuxBtnClick(Sender: TObject);
    185182var
    186   NewTax, NewLux: integer;
     183  NewTax, NewLux: Integer;
    187184begin
    188185  NewTax := MyRO.TaxRate div 10;
     
    191188  begin
    192189    if NewTax < 10 then
    193       inc(NewTax);
     190      Inc(NewTax);
    194191    if NewTax + NewLux > 10 then
    195       dec(NewLux);
     192      Dec(NewLux);
    196193  end
    197194  else if (Sender = TaxDownBtn) and (NewTax > 0) then
    198     dec(NewTax)
     195    Dec(NewTax)
    199196  else if (Sender = ScienceBtn) and (NewLux > 0) then
    200     dec(NewLux)
     197    Dec(NewLux)
    201198  else if (Sender = LuxBtn) and (NewLux + NewTax < 100) then
    202     inc(NewLux);
    203   if Server(sSetRates, me, NewTax + NewLux shl 4, nil^) <> eNotChanged then
     199    Inc(NewLux);
     200  if Server(sSetRates, Me, NewTax + NewLux shl 4, nil^) <> eNotChanged then
    204201  begin
    205202    CityOptimizer_BeginOfTurn;
    206203    SmartUpdateContent;
    207     MainScreen.UpdateViews(true);
     204    MainScreen.UpdateViews(True);
    208205  end;
    209206end;
  • TabularUnified branches/highdpi/LocalPlayer/Select.lfm

    r246 r465  
    11object ListDlg: TListDlg
    22  Left = 290
     3  Height = 262
    34  Top = 145
     5  Width = 381
    46  BorderIcons = []
    57  BorderStyle = bsNone
     
    79  ClientWidth = 381
    810  Color = clBtnFace
    9   Font.Charset = DEFAULT_CHARSET
     11  DesignTimePPI = 144
    1012  Font.Color = clWindowText
    11   Font.Height = -13
     13  Font.Height = -20
    1214  Font.Name = 'MS Sans Serif'
    13   Font.Style = []
    1415  FormStyle = fsStayOnTop
    1516  OnCloseQuery = FormCloseQuery
     
    1718  OnDestroy = FormDestroy
    1819  OnKeyDown = FormKeyDown
    19   OnMouseWheel = FormMouseWheel
    2020  OnMouseDown = PaintBox1MouseDown
    2121  OnMouseMove = PaintBox1MouseMove
     22  OnMouseWheel = FormMouseWheel
    2223  OnPaint = FormPaint
    2324  OnShow = FormShow
    24   PixelsPerInch = 96
     25  LCLVersion = '2.2.2.0'
    2526  Scaled = False
    2627  object CloseBtn: TButtonB
    2728    Left = 343
     29    Height = 25
    2830    Top = 6
    2931    Width = 25
    30     Height = 25
    3132    Down = False
    3233    Permanent = False
     
    3738    Tag = 2
    3839    Left = 344
     40    Height = 25
    3941    Top = 224
    4042    Width = 25
    41     Height = 25
    4243    Down = False
    4344    Permanent = True
     
    4849    Tag = 1
    4950    Left = 312
     51    Height = 25
    5052    Top = 224
    5153    Width = 25
    52     Height = 25
    5354    Down = False
    5455    Permanent = True
     
    5859  object Layer0Btn: TButtonB
    5960    Left = 280
     61    Height = 25
    6062    Top = 224
    6163    Width = 25
    62     Height = 25
    6364    Down = False
    6465    Permanent = True
     
    6869  object ToggleBtn: TButtonB
    6970    Left = 13
     71    Height = 25
    7072    Top = 6
    7173    Width = 25
    72     Height = 25
    7374    Down = False
    7475    Permanent = False
  • TabularUnified branches/highdpi/LocalPlayer/Select.pas

    r378 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, Term, ScreenTools, IsoEngine, PVSB, BaseWin,
     7  UDpiControls, Protocol, ClientTools, ScreenTools, PVSB, BaseWin,
    88  LCLIntf, LCLType, Messages, SysUtils, Classes, Graphics, Controls, Forms,
    99  ExtCtrls, ButtonB, ButtonBase, Menus, Types;
     
    2727    ToggleBtn: TButtonB;
    2828    Popup: TDpiPopupMenu;
     29    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2930    procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
    3031      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    3132    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
    32       x, y: integer);
     33      X, Y: Integer);
    3334    procedure FormCreate(Sender: TObject);
    3435    procedure FormDestroy(Sender: TObject);
    3536    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    36       Shift: TShiftState; x, y: integer);
     37      Shift: TShiftState; X, Y: Integer);
    3738    procedure FormPaint(Sender: TObject);
    3839    procedure CloseBtnClick(Sender: TObject);
    39     procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
     40    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    4041    procedure FormShow(Sender: TObject);
    4142    procedure ModeBtnClick(Sender: TObject);
    4243    procedure ToggleBtnClick(Sender: TObject);
    43     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     44    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    4445    procedure PlayerClick(Sender: TObject);
    4546  private
     
    4950    cixProject: Integer;
    5051    pView: Integer;
    51     Sel: Integer;
     52    Selected: Integer;
    5253    DispLines: Integer;
    5354    Layer: Integer;
     
    5556    TechNameSpace: Integer;
    5657    ScienceNation: Integer;
    57     sb: TPVScrollbar;
    58     Lines, FirstShrinkedLine: array [0 .. MaxLayer - 1] of integer;
    59     code: array [0 .. MaxLayer - 1, 0 .. 4095] of integer;
    60     Column: array [0 .. nPl - 1] of integer;
     58    ScrollBar: TPVScrollbar;
     59    Lines: array [0 .. MaxLayer - 1] of Integer;
     60    FirstShrinkedLine: array [0 .. MaxLayer - 1] of Integer;
     61    Code: array [0 .. MaxLayer - 1, 0 .. 4095] of Integer;
     62    Column: array [0 .. nPl - 1] of Integer;
    6163    Closable: Boolean;
    6264    MultiPage: Boolean;
     
    6466    procedure ScrollBarUpdate(Sender: TObject);
    6567    procedure InitLines;
    66     procedure line(ca: TDpiCanvas; l: integer; NonText, lit: boolean);
    67     function RenameCity(cix: integer): boolean;
    68     function RenameModel(mix: integer): boolean;
     68    procedure Line(ca: TDpiCanvas; L: Integer; NonText, lit: Boolean);
     69    function RenameCity(cix: Integer): Boolean;
     70    function RenameModel(mix: Integer): Boolean;
    6971    procedure OnScroll(var Msg: TMessage); message WM_VSCROLL;
    7072    procedure OnMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
    7173  public
    72     result: integer;
    73     function OnlyChoice(TestKind: TListKind): integer;
     74    Result: Integer;
     75    function OnlyChoice(TestKind: TListKind): Integer;
    7476    // -2=empty, -1=ambiguous, other=only choice
    7577    procedure OffscreenPaint; override;
    76     procedure ShowNewContent(NewMode: integer; ListKind: TListKind);
    77     procedure ShowNewContent_CityProject(NewMode, cix: integer);
    78     procedure ShowNewContent_MilReport(NewMode, p: integer);
     78    procedure ShowNewContent(NewMode: TWindowMode; ListKind: TListKind);
     79    procedure ShowNewContent_CityProject(NewMode: TWindowMode; cix: Integer);
     80    procedure ShowNewContent_MilReport(NewMode: TWindowMode; P: Integer);
    7981    procedure EcoChange;
    8082    procedure TechChange;
     
    9092  adAll = $10000;
    9193
    92 var
    93   ListDlg: TListDlg;
    94   ModalSelectDlg: TModalSelectDlg;
    95 
    9694
    9795implementation
    9896
    9997uses
    100   CityScreen, Help, UnitStat, Tribes, Inp;
     98  Term, CityScreen, Help, UnitStat, Tribes, Inp, CmdList;
    10199
    102100{$R *.lfm}
     
    111109  inherited;
    112110  Canvas.Font.Assign(UniFont[ftNormal]);
    113   sb := TPVScrollbar.Create(Self);
    114   sb.SetBorderSpacing(36, 10, 36);
    115   sb.OnUpdate := ScrollBarUpdate;
     111  ScrollBar := TPVScrollbar.Create(Self);
     112  ScrollBar.SetBorderSpacing(36, 10, 36);
     113  ScrollBar.OnUpdate := ScrollBarUpdate;
    116114  InitButtons;
    117115  Kind := kMission;
     
    127125procedure TListDlg.FormDestroy(Sender: TObject);
    128126begin
    129   FreeAndNil(sb);
     127  FreeAndNil(ScrollBar);
    130128  FreeAndNil(ScienceNationDotBuffer);
    131129end;
     
    133131procedure TListDlg.CloseBtnClick(Sender: TObject);
    134132begin
    135   Closable := true;
     133  Closable := True;
    136134  Close;
    137135end;
    138136
    139 procedure TListDlg.FormCloseQuery(Sender: TObject; var CanClose: boolean);
     137procedure TListDlg.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    140138begin
    141139  CanClose := Closable or not(Kind in MustChooseKind);
     
    145143begin
    146144  { TODO: Handled by MouseWheel event
    147   if sb.Process(Msg) then  begin
    148     Sel := -2;
    149     SmartUpdateContent(true);
     145  if ScrollBar.Process(Msg) then  begin
     146    Selected := -2;
     147    SmartUpdateContent(True);
    150148  end;
    151149  }
     
    154152procedure TListDlg.OnMouseLeave(var Msg: TMessage);
    155153begin
    156   if not Closable and (Sel <> -2) then
    157   begin
    158     line(Canvas, Sel, false, false);
    159     Sel := -2;
     154  if not Closable and (Selected <> -2) then
     155  begin
     156    Line(Canvas, Selected, False, False);
     157    Selected := -2;
    160158  end;
    161159end;
     
    163161procedure TListDlg.FormPaint(Sender: TObject);
    164162var
    165   s: string;
     163  S: string;
    166164begin
    167165  inherited;
    168166  Canvas.Font.Assign(UniFont[ftNormal]);
    169   if Sel <> -2 then
    170     line(Canvas, Sel, false, true);
    171   s := '';
     167  if Selected <> -2 then
     168    Line(Canvas, Selected, False, True);
     169  S := '';
    172170  if (Kind = kAdvance) and (MyData.FarTech <> adNone) then
    173     s := Format(Phrases.Lookup('TECHFOCUS'),
     171    S := Format(Phrases.Lookup('TECHFOCUS'),
    174172      [Phrases.Lookup('ADVANCES', MyData.FarTech)])
    175173  else if Kind = kModels then
    176     s := Tribe[me].TPhrase('SHORTNAME')
     174    S := Tribe[Me].TPhrase('SHORTNAME')
    177175  else if Kind = kEModels then
    178     s := Tribe[pView].TPhrase('SHORTNAME') + ' (' +
     176    S := Tribe[pView].TPhrase('SHORTNAME') + ' (' +
    179177      TurnToString(MyRO.EnemyReport[pView].TurnOfMilReport) + ')';
    180   if s <> '' then
     178  if S <> '' then
    181179    LoweredTextOut(Canvas, -1, MainTexture,
    182       (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, 31, s);
     180      (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, 31, S);
    183181  if not MultiPage and (Kind in [kProject, kAdvance, kFarAdvance]) and not Phrases2FallenBackToEnglish
    184182  then
    185183  begin
    186     s := Phrases2.Lookup('SHIFTCLICK');
     184    S := Phrases2.Lookup('SHIFTCLICK');
    187185    LoweredTextOut(Canvas, -2, MainTexture,
    188       (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, ClientHeight - 29, s);
    189   end;
    190 end;
    191 
    192 procedure TListDlg.line(ca: TDpiCanvas; l: integer; NonText, lit: boolean);
     186      (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, ClientHeight - 29, S);
     187  end;
     188end;
     189
     190procedure TListDlg.Line(ca: TDpiCanvas; L: Integer; NonText, lit: Boolean);
    193191// paint a line
    194192
    195   procedure DisplayProject(x, y, pix: integer);
     193  procedure DisplayProject(X, Y, pix: Integer);
    196194  begin
    197195    if pix and (cpType or cpImp) = 0 then
    198       with Tribe[me].ModelPicture[pix and cpIndex] do
    199         Sprite(offscreen, HGr, x, y, 64, 48, pix mod 10 * 65 + 1,
     196      with Tribe[Me].ModelPicture[pix and cpIndex] do
     197        Sprite(Offscreen, HGr, X, Y, 64, 48, pix mod 10 * 65 + 1,
    200198          pix div 10 * 49 + 1)
    201199    else
    202200    begin
    203       Frame(offscreen.Canvas, x + (16 - 1), y + (16 - 2), x + (16 + xSizeSmall),
    204         y + (16 - 1 + ySizeSmall), MainTexture.ColorBevelLight,
     201      Frame(Offscreen.Canvas, X + (16 - 1), Y + (16 - 2), X + (16 + xSizeSmall),
     202        Y + (16 - 1 + ySizeSmall), MainTexture.ColorBevelLight,
    205203        MainTexture.ColorBevelShade);
    206204      if pix and cpType = 0 then
    207205        if (pix and cpIndex = imPalace) and (MyRO.Government <> gAnarchy) then
    208           DpiBitCanvas(offscreen.Canvas, x + 16, y + (16 - 1), xSizeSmall,
     206          DpiBitBltCanvas(Offscreen.Canvas, X + 16, Y + (16 - 1), xSizeSmall,
    209207            ySizeSmall, SmallImp.Canvas, (MyRO.Government - 1) *
    210208            xSizeSmall, ySizeSmall)
    211209        else
    212           DpiBitCanvas(offscreen.Canvas, x + 16, y + (16 - 1), xSizeSmall,
     210          DpiBitBltCanvas(Offscreen.Canvas, X + 16, Y + (16 - 1), xSizeSmall,
    213211            ySizeSmall, SmallImp.Canvas, pix and cpIndex mod 7 *
    214212            xSizeSmall, (pix and cpIndex + SystemIconLines * 7) div 7 *
    215213            ySizeSmall)
    216214      else
    217         DpiBitCanvas(offscreen.Canvas, x + 16, y + (16 - 1), xSizeSmall,
     215        DpiBitBltCanvas(Offscreen.Canvas, X + 16, Y + (16 - 1), xSizeSmall,
    218216          ySizeSmall, SmallImp.Canvas, (3 + pix and cpIndex) *
    219217          xSizeSmall, 0);
     
    221219  end;
    222220
    223   procedure ReplaceText(x, y, Color: integer; s: string);
     221  procedure ReplaceText(X, Y, Color: Integer; S: string);
    224222  var
    225223    TextSize: TSize;
     
    227225    if ca = Canvas then
    228226    begin
    229       TextSize.cx := BiColorTextWidth(ca, s);
    230       TextSize.cy := ca.TextHeight(s);
    231       if y + TextSize.cy >= TitleHeight + InnerHeight then
    232         TextSize.cy := TitleHeight + InnerHeight - y;
    233       Fill(ca, x, y, TextSize.cx, TextSize.cy, (Maintexture.Width - ClientWidth)
     227      TextSize.cx := BiColorTextWidth(ca, S);
     228      TextSize.cy := ca.TextHeight(S);
     229      if Y + TextSize.cy >= TitleHeight + InnerHeight then
     230        TextSize.cy := TitleHeight + InnerHeight - Y;
     231      Fill(ca, X, Y, TextSize.cx, TextSize.cy, (Maintexture.Width - ClientWidth)
    234232        div 2, (Maintexture.Height - ClientHeight) div 2);
    235233    end;
    236     LoweredTextOut(ca, Color, MainTexture, x, y, s);
     234    LoweredTextOut(ca, Color, MainTexture, X, Y, S);
    237235  end;
    238236
    239237var
    240   icon, ofs, x, y, y0, lix, i, j, TextColor, Available, first, test,
    241     FutureCount, growth, TrueFood, TrueProd: integer;
     238  icon, ofs, X, Y, y0, lix, I, J, TextColor, Available, first, Test,
     239    FutureCount, growth, TrueFood, TrueProd: Integer;
    242240  CityReport: TCityReportNew;
    243241  mox: ^TModelInfo;
    244   s, number: string;
    245   CanGrow: boolean;
    246 begin
    247   lix := code[Layer, sb.Position + l];
    248   y0 := 2 + (l + 1) * LineDistance;
    249   if sb.Position + l >= FirstShrinkedLine[Layer] then
    250     ofs := (sb.Position + l - FirstShrinkedLine[Layer]) and 1 * 33
     242  S, number: string;
     243  CanGrow: Boolean;
     244begin
     245  lix := Code[Layer, ScrollBar.Position + L];
     246  y0 := 2 + (L + 1) * LineDistance;
     247  if ScrollBar.Position + L >= FirstShrinkedLine[Layer] then
     248    ofs := (ScrollBar.Position + L - FirstShrinkedLine[Layer]) and 1 * 33
    251249  else { if FirstShrinkedLine[Layer]<Lines[Layer] then }
    252250    ofs := 33;
     
    255253    with MyCity[lix] do
    256254    begin
    257       x := 104 - 76;
    258       y := y0;
     255      X := 104 - 76;
     256      Y := y0;
    259257      if ca = Canvas then
    260258      begin
    261         x := x + SideFrame;
    262         y := y + TitleHeight;
     259        X := X + SideFrame;
     260        Y := Y + TitleHeight;
    263261      end;
    264262      if lit then
     
    266264      else
    267265        TextColor := -1;
    268       s := CityName(ID);
    269       while BiColorTextWidth(ca, s) > CityNameSpace do
    270         delete(s, length(s), 1);
    271       ReplaceText(x + 15, y, TextColor, s);
     266      S := CityName(ID);
     267      while BiColorTextWidth(ca, S) > CityNameSpace do
     268        Delete(S, Length(S), 1);
     269      ReplaceText(X + 15, Y, TextColor, S);
    272270
    273271      if NonText then
    274         with offscreen.Canvas do
     272        with Offscreen.Canvas do
    275273        begin // city size
    276           brush.Color := $000000;
    277           fillrect(rect(x - 4 - 11, y + 1, x - 4 + 13, y + 21));
    278           brush.Color := $FFFFFF;
    279           fillrect(rect(x - 4 - 12, y, x - 4 + 12, y + 20));
    280           brush.style := bsClear;
     274          Brush.Color := $000000;
     275          FillRect(rect(X - 4 - 11, Y + 1, X - 4 + 13, Y + 21));
     276          Brush.Color := $FFFFFF;
     277          FillRect(rect(X - 4 - 12, Y, X - 4 + 12, Y + 20));
     278          Brush.style := bsClear;
    281279          Font.Color := $000000;
    282           s := inttostr(MyCity[lix].Size);
    283           TextOut(x - 4 - textwidth(s) div 2, y, s);
     280          S := IntToStr(MyCity[lix].Size);
     281          TextOut(X - 4 - textwidth(S) div 2, Y, S);
    284282        end;
    285283
     
    287285      begin
    288286        first := -1;
    289         for j := 0 to nCityEventPriority - 1 do
    290           if (Flags and CityRepMask and CityEventPriority[j] <> 0) then
    291           begin
    292             first := j;
    293             Break
     287        for J := 0 to nCityEventPriority - 1 do
     288          if (Flags and CityRepMask and CityEventPriority[J] <> 0) then
     289          begin
     290            first := J;
     291            Break;
    294292          end;
    295293        if first >= 0 then
    296294        begin
    297           i := 0;
    298           test := 1;
    299           while test < CityEventPriority[first] do
    300           begin
    301             inc(i);
    302             inc(test, test)
    303           end;
    304           s := CityEventName(i);
     295          I := 0;
     296          Test := 1;
     297          while Test < CityEventPriority[first] do
     298          begin
     299            Inc(I);
     300            Inc(Test, Test);
     301          end;
     302          S := CityEventName(I);
    305303          { if CityEventPriority[first]=chNoGrowthWarning then
    306304            if Built[imAqueduct]=0 then
    307             s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
    308             else begin s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); i:=17 end; }
    309           ReplaceText(x + (CityNameSpace + 4 + 40 + 18 + 8), y, TextColor, s);
     305            S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
     306            else begin S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); I:=17 end; }
     307          ReplaceText(X + (CityNameSpace + 4 + 40 + 18 + 8), Y, TextColor, S);
    310308          if NonText then
    311309          begin
    312             Sprite(offscreen, HGrSystem, 105 - 76 + CityNameSpace + 4 + 40,
    313               y0 + 1, 18, 18, 1 + i mod 3 * 19, 1 + i div 3 * 19);
    314             x := InnerWidth - 26;
    315             for j := nCityEventPriority - 1 downto first + 1 do
    316               if (Flags and CityRepMask and CityEventPriority[j] <> 0) then
     310            Sprite(Offscreen, HGrSystem, 105 - 76 + CityNameSpace + 4 + 40,
     311              y0 + 1, 18, 18, 1 + I mod 3 * 19, 1 + I div 3 * 19);
     312            X := InnerWidth - 26;
     313            for J := nCityEventPriority - 1 downto first + 1 do
     314              if (Flags and CityRepMask and CityEventPriority[J] <> 0) then
    317315              begin
    318                 i := 0;
    319                 test := 1;
    320                 while test < CityEventPriority[j] do
     316                I := 0;
     317                Test := 1;
     318                while Test < CityEventPriority[J] do
    321319                begin
    322                   inc(i);
    323                   inc(test, test)
     320                  Inc(I);
     321                  Inc(Test, Test);
    324322                end;
    325                 if (CityEventPriority[j] = chNoGrowthWarning) and
     323                if (CityEventPriority[J] = chNoGrowthWarning) and
    326324                  (Built[imAqueduct] > 0) then
    327                   i := 17;
    328                 Sprite(offscreen, HGrSystem, x, y0 + 1, 18, 18,
    329                   1 + i mod 3 * 19, 1 + i div 3 * 19);
    330                 dec(x, 20)
    331               end
    332           end
    333         end
     325                  I := 17;
     326                Sprite(Offscreen, HGrSystem, X, y0 + 1, 18, 18,
     327                  1 + I mod 3 * 19, 1 + I div 3 * 19);
     328                Dec(X, 20);
     329              end;
     330          end;
     331        end;
    334332      end
    335333      else
     
    338336        CityReport.HypoTaxRate := -1;
    339337        CityReport.HypoLuxuryRate := -1;
    340         Server(sGetCityReportNew, me, lix, CityReport);
     338        Server(sGetCityReportNew, Me, lix, CityReport);
    341339        TrueFood := Food;
    342340        TrueProd := Prod;
    343         if supervising then
     341        if Supervising then
    344342        begin // normalize city from after-turn state
    345           dec(TrueFood, CityReport.FoodSurplus);
     343          Dec(TrueFood, CityReport.FoodSurplus);
    346344          if TrueFood < 0 then
    347345            TrueFood := 0; // shouldn't happen
    348           dec(TrueProd, CityReport.Production);
     346          Dec(TrueProd, CityReport.Production);
    349347          if TrueProd < 0 then
    350348            TrueProd := 0; // shouldn't happen
    351349        end;
    352350
    353         s := ''; // disorder info
     351        S := ''; // disorder info
    354352        if Flags and chCaptured <> 0 then
    355           s := Phrases.Lookup('CITYEVENTS', 14)
     353          S := Phrases.Lookup('CITYEVENTS', 14)
    356354        else if CityReport.HappinessBalance < 0 then
    357           s := Phrases.Lookup('CITYEVENTS', 0);
    358         if s <> '' then
     355          S := Phrases.Lookup('CITYEVENTS', 0);
     356        if S <> '' then
    359357        begin { disorder }
    360358          if NonText then
    361359          begin
    362             DarkGradient(offscreen.Canvas, 99 + 31 + CityNameSpace + 4,
     360            DarkGradient(Offscreen.Canvas, 99 + 31 + CityNameSpace + 4,
    363361              y0 + 2, 131, 3);
    364362            ca.Font.Assign(UniFont[ftSmall]);
    365             RisedTextout(offscreen.Canvas, 103 + CityNameSpace + 4 + 31,
    366               y0 + 1, s);
     363            RisedTextout(Offscreen.Canvas, 103 + CityNameSpace + 4 + 31,
     364              y0 + 1, S);
    367365            ca.Font.Assign(UniFont[ftNormal]);
    368           end
     366          end;
    369367        end
    370368        else
    371369        begin
    372370          { s:=IntToStr(CityReport.FoodSurplus);
    373             ReplaceText(x+(CityNameSpace+4+48)-BiColorTextWidth(ca,s),y,TextColor,s); }
    374           s := inttostr(CityReport.Science);
    375           ReplaceText(x + CityNameSpace + 4 + 370 + 48 - BiColorTextWidth(ca,
    376             s), y, TextColor, s);
    377           s := inttostr(CityReport.Production);
    378           ReplaceText(x + CityNameSpace + 4 + 132 - BiColorTextWidth(ca, s), y,
    379             TextColor, s);
     371            ReplaceText(X+(CityNameSpace+4+48)-BiColorTextWidth(ca,S),Y,TextColor,S); }
     372          S := IntToStr(CityReport.Science);
     373          ReplaceText(X + CityNameSpace + 4 + 370 + 48 - BiColorTextWidth(ca,
     374            S), Y, TextColor, S);
     375          S := IntToStr(CityReport.Production);
     376          ReplaceText(X + CityNameSpace + 4 + 132 - BiColorTextWidth(ca, S), Y,
     377            TextColor, S);
    380378          if NonText then
    381379          begin
    382380            // Sprite(offscreen,HGrSystem,x+CityNameSpace+4+333+1,y+6,10,10,66,115);
    383             Sprite(offscreen, HGrSystem, x + CityNameSpace + 4 + 370 + 48 + 1,
    384               y + 6, 10, 10, 77, 126);
    385             Sprite(offscreen, HGrSystem, x + CityNameSpace + 4 + 132 + 1, y + 6,
     381            Sprite(Offscreen, HGrSystem, X + CityNameSpace + 4 + 370 + 48 + 1,
     382              Y + 6, 10, 10, 77, 126);
     383            Sprite(Offscreen, HGrSystem, X + CityNameSpace + 4 + 132 + 1, Y + 6,
    386384              10, 10, 88, 115);
    387           end
    388         end;
    389         s := inttostr(CityTaxBalance(lix, CityReport));
    390         ReplaceText(x + CityNameSpace + 4 + 370 - BiColorTextWidth(ca, s), y,
    391           TextColor, s);
     385          end;
     386        end;
     387        S := IntToStr(CityTaxBalance(lix, CityReport));
     388        ReplaceText(X + CityNameSpace + 4 + 370 - BiColorTextWidth(ca, S), Y,
     389          TextColor, S);
    392390        // if Project and (cpImp+cpIndex)<>cpImp+imTrGoods then
    393391        // ReplaceText(x+CityNameSpace+4+333+1,y,TextColor,Format('%d/%d',[TrueProd,CityReport.ProjectCost]));
    394392        if NonText then
    395393        begin
    396           Sprite(offscreen, HGrSystem, x + CityNameSpace + 4 + 370 + 1, y + 6,
     394          Sprite(Offscreen, HGrSystem, X + CityNameSpace + 4 + 370 + 1, Y + 6,
    397395            10, 10, 132, 115);
    398396
     
    402400            ((Size < NeedAqueductSize) or (Built[imAqueduct] = 1) and
    403401            (Size < NeedSewerSize) or (Built[imSewer] = 1));
    404           PaintRelativeProgressBar(offscreen.Canvas, 1, x + 15 + CityNameSpace +
    405             4, y + 7, 68, TrueFood, CutCityFoodSurplus(CityReport.FoodSurplus,
     402          PaintRelativeProgressBar(Offscreen.Canvas, 1, X + 15 + CityNameSpace +
     403            4, Y + 7, 68, TrueFood, CutCityFoodSurplus(CityReport.FoodSurplus,
    406404            (MyRO.Government <> gAnarchy) and (Flags and chCaptured = 0),
    407405            MyRO.Government, Size), CityReport.Storage, CanGrow, MainTexture);
     
    409407          if Project <> cpImp + imTrGoods then
    410408          begin
    411             DisplayProject(ofs + 104 - 76 + x - 28 + CityNameSpace + 4 + 206 -
     409            DisplayProject(ofs + 104 - 76 + X - 28 + CityNameSpace + 4 + 206 -
    412410              60, y0 - 15, Project);
    413411
     
    417415              (Flags and chCaptured <> 0) then
    418416              growth := 0;
    419             PaintRelativeProgressBar(offscreen.Canvas, 4,
    420               x + CityNameSpace + 4 + 304 - 60 + 9, y + 7, 68, TrueProd, growth,
    421               CityReport.ProjectCost, true, MainTexture);
    422           end;
    423         end
     417            PaintRelativeProgressBar(Offscreen.Canvas, 4,
     418              X + CityNameSpace + 4 + 304 - 60 + 9, Y + 7, 68, TrueProd, growth,
     419              CityReport.ProjectCost, True, MainTexture);
     420          end;
     421        end;
    424422      end;
    425423    end
    426424  else if Kind in [kModels, kEModels] then
    427425  begin
    428     x := 104;
    429     y := y0;
     426    X := 104;
     427    Y := y0;
    430428    if ca = Canvas then
    431429    begin
    432       x := x + SideFrame;
    433       y := y + TitleHeight
     430      X := X + SideFrame;
     431      Y := Y + TitleHeight;
    434432    end;
    435433    if lit then
     
    440438    begin
    441439      Available := 0;
    442       for j := 0 to MyRO.nUn - 1 do
    443         if (MyUn[j].Loc >= 0) and (MyUn[j].mix = lix) then
    444           inc(Available);
     440      for J := 0 to MyRO.nUn - 1 do
     441        if (MyUn[J].Loc >= 0) and (MyUn[J].mix = lix) then
     442          Inc(Available);
    445443      if MainScreen.mNames.Checked then
    446         s := Tribe[me].ModelName[lix]
     444        S := Tribe[Me].ModelName[lix]
    447445      else
    448         s := Format(Tribe[me].TPhrase('GENMODEL'), [lix]);
     446        S := Format(Tribe[Me].TPhrase('GENMODEL'), [lix]);
    449447      if NonText then
    450448        DisplayProject(8 + ofs, y0 - 15, lix);
     
    454452      Available := MyRO.EnemyReport[pView].UnCount[lix];
    455453      if MainScreen.mNames.Checked then
    456         s := Tribe[pView].ModelName[lix]
     454        S := Tribe[pView].ModelName[lix]
    457455      else
    458         s := Format(Tribe[pView].TPhrase('GENMODEL'), [lix]);
     456        S := Format(Tribe[pView].TPhrase('GENMODEL'), [lix]);
    459457      if NonText then
    460458        with Tribe[pView].ModelPicture[lix] do
    461           Sprite(offscreen, HGr, 8 + ofs, y0 - 15, 64, 48, pix mod 10 * 65 + 1,
     459          Sprite(Offscreen, HGr, 8 + ofs, y0 - 15, 64, 48, pix mod 10 * 65 + 1,
    462460            pix div 10 * 49 + 1);
    463461    end;
    464462    if Available > 0 then
    465       ReplaceText(x + 32 - BiColorTextWidth(ca, inttostr(Available)), y,
    466         TextColor, inttostr(Available));
    467     ReplaceText(x + 40, y, TextColor, s);
     463      ReplaceText(X + 32 - BiColorTextWidth(ca, IntToStr(Available)), Y,
     464        TextColor, IntToStr(Available));
     465    ReplaceText(X + 40, Y, TextColor, S);
    468466  end
    469467  else
     
    472470      kAllEModels, kChooseEModel:
    473471        if lix = mixAll then
    474           s := Phrases.Lookup('PRICECAT_ALLMODEL')
     472          S := Phrases.Lookup('PRICECAT_ALLMODEL')
    475473        else
    476474        begin
     
    478476          if MainScreen.mNames.Checked then
    479477          begin
    480             s := Tribe[mox.Owner].ModelName[mox.mix];
    481             if (Kind = kAllEModels) and (code[1, sb.Position + l] = 0) then
    482               s := Format(Tribe[mox.Owner].TPhrase('OWNED'), [s]);
     478            S := Tribe[mox.Owner].ModelName[mox.mix];
     479            if (Kind = kAllEModels) and (Code[1, ScrollBar.Position + L] = 0) then
     480              S := Format(Tribe[mox.Owner].TPhrase('OWNED'), [S]);
    483481          end
    484482          else
    485             s := Format(Tribe[mox.Owner].TPhrase('GENMODEL'), [mox.mix]);
     483            S := Format(Tribe[mox.Owner].TPhrase('GENMODEL'), [mox.mix]);
    486484          if NonText then
    487485            with Tribe[mox.Owner].ModelPicture[mox.mix] do
    488               Sprite(offscreen, HGr, 8 + ofs, y0 - 15, 64, 48,
     486              Sprite(Offscreen, HGr, 8 + ofs, y0 - 15, 64, 48,
    489487                pix mod 10 * 65 + 1, pix div 10 * 49 + 1);
    490488        end;
    491489      kChooseModel:
    492490        if lix = mixAll then
    493           s := Phrases.Lookup('PRICECAT_ALLMODEL')
     491          S := Phrases.Lookup('PRICECAT_ALLMODEL')
    494492        else
    495493        begin
    496           s := Tribe[me].ModelName[lix];
     494          S := Tribe[Me].ModelName[lix];
    497495          if NonText then
    498496            DisplayProject(8 + ofs, y0 - 15, lix);
     
    501499        begin
    502500          if lix and cpType <> 0 then
    503             s := Phrases.Lookup('CITYTYPE', lix and cpIndex)
     501            S := Phrases.Lookup('CITYTYPE', lix and cpIndex)
    504502          else if lix and cpImp = 0 then
    505503            with MyModel[lix and cpIndex] do
    506504            begin
    507               s := Tribe[me].ModelName[lix and cpIndex];
     505              S := Tribe[Me].ModelName[lix and cpIndex];
    508506              if lix and cpConscripts <> 0 then
    509                 s := Format(Phrases.Lookup('CONSCRIPTS'), [s]);
     507                S := Format(Phrases.Lookup('CONSCRIPTS'), [S]);
    510508            end
    511509          else
    512510          begin
    513             s := Phrases.Lookup('IMPROVEMENTS', lix and cpIndex);
     511            S := Phrases.Lookup('IMPROVEMENTS', lix and cpIndex);
    514512            if (Imp[lix and cpIndex].Kind in [ikNatLocal, ikNatGlobal]) and
    515513              (MyRO.NatBuilt[lix and cpIndex] > 0) or
     
    517515              (MyCity[cixProject].Built[imPower] + MyCity[cixProject].Built
    518516              [imHydro] + MyCity[cixProject].Built[imNuclear] > 0) then
    519               s := Format(Phrases.Lookup('NATEXISTS'), [s]);
     517              S := Format(Phrases.Lookup('NATEXISTS'), [S]);
    520518          end;
    521519          if NonText then
     
    525523        begin
    526524          if lix = adAll then
    527             s := Phrases.Lookup('PRICECAT_ALLTECH')
     525            S := Phrases.Lookup('PRICECAT_ALLTECH')
    528526          else
    529527          begin
    530528            if lix = adNexus then
    531               s := Phrases.Lookup('NEXUS')
     529              S := Phrases.Lookup('NEXUS')
    532530            else if lix = adNone then
    533               s := Phrases.Lookup('NOFARTECH')
     531              S := Phrases.Lookup('NOFARTECH')
    534532            else if lix = adMilitary then
    535               s := Phrases.Lookup('INITUNIT')
     533              S := Phrases.Lookup('INITUNIT')
    536534            else
    537535            begin
    538               s := Phrases.Lookup('ADVANCES', lix);
     536              S := Phrases.Lookup('ADVANCES', lix);
    539537              if (Kind = kAdvance) and (lix in FutureTech) then
    540538                if MyRO.Tech[lix] < tsApplicable then
    541                   s := s + ' 1'
     539                  S := S + ' 1'
    542540                else
    543                   s := s + ' ' + inttostr(MyRO.Tech[lix] + 1);
     541                  S := S + ' ' + IntToStr(MyRO.Tech[lix] + 1);
    544542            end;
    545             if BiColorTextWidth(ca, s) > TechNameSpace + 8 then
     543            if BiColorTextWidth(ca, S) > TechNameSpace + 8 then
    546544            begin
    547545              repeat
    548                 delete(s, length(s), 1);
    549               until BiColorTextWidth(ca, s) <= TechNameSpace + 5;
    550               s := s + '.';
     546                Delete(S, Length(S), 1);
     547              until BiColorTextWidth(ca, S) <= TechNameSpace + 5;
     548              S := S + '.';
    551549            end;
    552550
     
    555553              if lix = adNexus then
    556554              begin
    557                 Frame(offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
     555                Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
    558556                  y0 + 20, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    559                 Dump(offscreen, HGrSystem, (8 + 16), y0, 36, 20, 223, 295)
     557                Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20, 223, 295)
    560558              end
    561559              else if lix = adNone then
    562560              begin
    563                 Frame(offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
     561                Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
    564562                  y0 + 20, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    565                 Dump(offscreen, HGrSystem, (8 + 16), y0, 36, 20, 260, 295)
     563                Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20, 260, 295)
    566564              end
    567565              else if lix = adMilitary then
    568566              begin
    569                 Frame(offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
     567                Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
    570568                  y0 + 20, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    571                 Dump(offscreen, HGrSystem, (8 + 16), y0, 36, 20, 38, 295)
     569                Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20, 38, 295)
    572570              end
    573571              else
    574572              begin
    575                 Frame(offscreen.Canvas, (8 + 16 - 1), y0 - 1,
     573                Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1,
    576574                  (8 + 16 + xSizeSmall), y0 + ySizeSmall,
    577575                  MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    578576                if AdvIcon[lix] < 84 then
    579                   DpiBitCanvas(offscreen.Canvas, (8 + 16), y0, xSizeSmall,
     577                  DpiBitBltCanvas(Offscreen.Canvas, (8 + 16), y0, xSizeSmall,
    580578                    ySizeSmall, SmallImp.Canvas,
    581579                    (AdvIcon[lix] + SystemIconLines * 7) mod 7 * xSizeSmall,
     
    583581                    ySizeSmall)
    584582                else
    585                   Dump(offscreen, HGrSystem, (8 + 16), y0, 36, 20,
     583                  Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20,
    586584                    1 + (AdvIcon[lix] - 84) mod 8 * 37,
    587585                    295 + (AdvIcon[lix] - 84) div 8 * 21);
    588                 j := AdvValue[lix] div 1000;
    589                 DpiBitCanvas(offscreen.Canvas, (8 + 16 - 4), y0 + 2, 14, 14,
    590                   HGrSystem.Mask.Canvas, 127 + j * 15,
     586                J := AdvValue[lix] div 1000;
     587                DpiBitBltCanvas(Offscreen.Canvas, (8 + 16 - 4), y0 + 2, 14, 14,
     588                  HGrSystem.Mask.Canvas, 127 + J * 15,
    591589                  85, SRCAND);
    592                 Sprite(offscreen, HGrSystem, (8 + 16 - 5), y0 + 1, 14, 14,
    593                   127 + j * 15, 85);
     590                Sprite(Offscreen, HGrSystem, (8 + 16 - 5), y0 + 1, 14, 14,
     591                  127 + J * 15, 85);
    594592              end;
    595593            end;
     
    598596          if NonText and (Kind in [kAdvance, kScience]) then
    599597          begin // show research state
    600             for j := 0 to nColumn - 1 do
     598            for J := 0 to nColumn - 1 do
    601599            begin
    602600              FutureCount := 0;
    603               if j = 0 then // own science
     601              if J = 0 then // own science
    604602                if lix = MyRO.ResearchTech then
    605603                begin
    606                   Server(sGetTechCost, me, 0, icon);
     604                  Server(sGetTechCost, Me, 0, icon);
    607605                  icon := 4 + MyRO.Research * 4 div icon;
    608606                  if icon > 4 + 3 then
     
    623621                  icon := -1
    624622              else
    625                 with MyRO.EnemyReport[Column[j]]^ do // enemy science
    626                   if (MyRO.Alive and (1 shl Column[j]) <> 0) and
     623                with MyRO.EnemyReport[Column[J]]^ do // enemy science
     624                  if (MyRO.Alive and (1 shl Column[J]) <> 0) and
    627625                    (TurnOfCivilReport >= 0) and (lix = ResearchTech) and
    628626                    ((lix = adMilitary) or (lix in FutureTech) or
     
    631629                    icon := 4 + ResearchDone div 25;
    632630                    if icon > 4 + 3 then
    633                       icon := 4 + 3
     631                      icon := 4 + 3;
    634632                  end
    635633                  else if lix = adMilitary then
     
    647645                    icon := -1;
    648646              if icon >= 0 then
    649                 Sprite(offscreen, HGrSystem, 104 - 33 + 15 + 3 + TechNameSpace +
    650                   24 * j, y0 + 3, 14, 14, 67 + icon * 15, 85)
     647                Sprite(Offscreen, HGrSystem, 104 - 33 + 15 + 3 + TechNameSpace +
     648                  24 * J, y0 + 3, 14, 14, 67 + icon * 15, 85)
    651649              else if (Kind = kScience) and (FutureCount > 0) then
    652650              begin
    653                 number := inttostr(FutureCount);
    654                 RisedTextout(ca, 104 - 33 + 15 + 10 + TechNameSpace + 24 * j -
     651                number := IntToStr(FutureCount);
     652                RisedTextout(ca, 104 - 33 + 15 + 10 + TechNameSpace + 24 * J -
    655653                  BiColorTextWidth(ca, number) div 2, y0, number);
    656               end
    657             end
     654              end;
     655            end;
    658656          end;
    659657        end; // kAdvance, kScience
    660658      kTribe:
    661         s := TribeNames[lix];
     659        S := TribeNames[lix];
    662660      kShipPart:
    663661        begin
    664           s := Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' +
    665             inttostr(MyRO.Ship[me].Parts[lix]) + ')';
     662          S := Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' +
     663            IntToStr(MyRO.Ship[Me].Parts[lix]) + ')';
    666664          if NonText then
    667665            DisplayProject(8 + ofs, y0 - 15, cpImp + imShipComp + lix);
     
    669667      kEShipPart:
    670668        begin
    671           s := Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' +
    672             inttostr(MyRO.Ship[DipMem[me].pContact].Parts[lix]) + ')';
     669          S := Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' +
     670            IntToStr(MyRO.Ship[DipMem[Me].pContact].Parts[lix]) + ')';
    673671          if NonText then
    674672            DisplayProject(8 + ofs, y0 - 15, cpImp + imShipComp + lix);
     
    676674      kGov:
    677675        begin
    678           s := Phrases.Lookup('GOVERNMENT', lix);
     676          S := Phrases.Lookup('GOVERNMENT', lix);
    679677          if NonText then
    680678          begin
    681             Frame(offscreen.Canvas, 8 + 16 - 1, y0 - 15 + (16 - 2),
     679            Frame(Offscreen.Canvas, 8 + 16 - 1, y0 - 15 + (16 - 2),
    682680              8 + 16 + xSizeSmall, y0 - 15 + (16 - 1 + ySizeSmall),
    683681              MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    684             DpiBitCanvas(offscreen.Canvas, 8 + 16, y0 - 15 + (16 - 1),
     682            DpiBitBltCanvas(Offscreen.Canvas, 8 + 16, y0 - 15 + (16 - 1),
    685683              xSizeSmall, ySizeSmall, SmallImp.Canvas,
    686684              (lix - 1) * xSizeSmall, ySizeSmall);
    687           end
     685          end;
    688686        end;
    689687      kMission:
    690         s := Phrases.Lookup('SPYMISSION', lix);
     688        S := Phrases.Lookup('SPYMISSION', lix);
    691689    end;
    692690    case Kind of
    693691      kTribe, kMission: // center text
    694692        if Lines[0] > MaxLines then
    695           x := (InnerWidth - DpiGetSystemMetrics(SM_CXVSCROLL)) div 2 -
    696             BiColorTextWidth(ca, s) div 2
     693          X := (InnerWidth - DpiGetSystemMetrics(SM_CXVSCROLL)) div 2 -
     694            BiColorTextWidth(ca, S) div 2
    697695        else
    698           x := InnerWidth div 2 - BiColorTextWidth(ca, s) div 2;
     696          X := InnerWidth div 2 - BiColorTextWidth(ca, S) div 2;
    699697      kAdvance, kFarAdvance, kScience, kChooseTech, kChooseETech,
    700698        kStealTech, kGov:
    701         x := 104 - 33;
     699        X := 104 - 33;
    702700      kAllEModels:
    703         x := 104;
     701        X := 104;
    704702    else
    705       x := 104 + 15;
     703      X := 104 + 15;
    706704    end;
    707     y := y0;
     705    Y := y0;
    708706    if ca = Canvas then
    709707    begin
    710       x := x + SideFrame;
    711       y := y + TitleHeight
     708      X := X + SideFrame;
     709      Y := Y + TitleHeight;
    712710    end;
    713711    if lit then
     
    716714      TextColor := -1;
    717715    { if Kind=kTribe then ReplaceText_Tribe(x,y,TextColor,
    718       integer(TribeNames.Objects[lix]),s)
    719       else } ReplaceText(x, y, TextColor, s);
    720   end
     716      Integer(TribeNames.Objects[lix]),S)
     717      else } ReplaceText(X, Y, TextColor, S);
     718  end;
    721719end;
    722720
    723721procedure TListDlg.OffscreenPaint;
    724722var
    725   i, j: integer;
     723  I, J: Integer;
    726724begin
    727725  case Kind of
    728726    kCities:
    729       Caption := Tribe[me].TPhrase('TITLE_CITIES');
     727      Caption := Tribe[Me].TPhrase('TITLE_CITIES');
    730728    kCityEvents:
    731729      Caption := Format(Phrases.Lookup('TITLE_EVENTS'),
     
    734732
    735733  inherited;
    736   offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
     734  Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    737735  FillOffscreen(0, 0, InnerWidth, InnerHeight);
    738   with offscreen.Canvas do
     736  with Offscreen.Canvas do
    739737  begin
    740738    if Kind = kScience then
    741       for i := 1 to nColumn - 1 do
     739      for I := 1 to nColumn - 1 do
    742740      begin
    743741        Pen.Color := $000000;
    744         MoveTo(104 - 33 + 15 + TechNameSpace + 24 * i, 0);
    745         LineTo(104 - 33 + 15 + TechNameSpace + 24 * i, InnerHeight);
    746         MoveTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * i, 0);
    747         LineTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * i, InnerHeight);
    748         if MyRO.EnemyReport[Column[i]].TurnOfCivilReport >= MyRO.Turn - 1 then
    749         begin
    750           brush.Color := Tribe[Column[i]].Color;
    751           fillrect(rect(104 - 33 + 14 + TechNameSpace + 24 * i + 1 * 2, 0,
    752             104 - 33 + 17 + TechNameSpace + 24 * i + 8 * 2, InnerHeight));
    753           brush.style := bsClear;
     742        MoveTo(104 - 33 + 15 + TechNameSpace + 24 * I, 0);
     743        LineTo(104 - 33 + 15 + TechNameSpace + 24 * I, InnerHeight);
     744        MoveTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * I, 0);
     745        LineTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * I, InnerHeight);
     746        if MyRO.EnemyReport[Column[I]].TurnOfCivilReport >= MyRO.Turn - 1 then
     747        begin
     748          Brush.Color := Tribe[Column[I]].Color;
     749          FillRect(rect(104 - 33 + 14 + TechNameSpace + 24 * I + 1 * 2, 0,
     750            104 - 33 + 17 + TechNameSpace + 24 * I + 8 * 2, InnerHeight));
     751          Brush.style := bsClear;
    754752        end
    755753        else
    756754        begin // colored player columns
    757           Pen.Color := Tribe[Column[i]].Color;
    758           for j := 1 to 8 do
    759           begin
    760             MoveTo(104 - 33 + 15 + TechNameSpace + 24 * i + j * 2, 0);
    761             LineTo(104 - 33 + 15 + TechNameSpace + 24 * i + j * 2, InnerHeight);
    762           end
    763         end;
    764       end;
    765 
    766     for i := -1 to DispLines do
    767       if (i + sb.Position >= 0) and (i + sb.Position < Lines[Layer]) then
    768         Self.line(offscreen.Canvas, i, true, false)
     755          Pen.Color := Tribe[Column[I]].Color;
     756          for J := 1 to 8 do
     757          begin
     758            MoveTo(104 - 33 + 15 + TechNameSpace + 24 * I + J * 2, 0);
     759            LineTo(104 - 33 + 15 + TechNameSpace + 24 * I + J * 2, InnerHeight);
     760          end;
     761        end;
     762      end;
     763
     764    for I := -1 to DispLines do
     765      if (I + ScrollBar.Position >= 0) and (I + ScrollBar.Position < Lines[Layer]) then
     766        Self.Line(Offscreen.Canvas, I, True, False);
    769767  end;
    770768  MarkUsedOffscreen(InnerWidth, 8 + 48 + DispLines * LineDistance);
     
    772770
    773771procedure TListDlg.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
    774   x, y: integer);
     772  X, Y: Integer);
    775773var
    776   i0, Sel0, iColumn, OldScienceNation, xScreen: integer;
    777   s: string;
    778 begin
    779   y := y - TitleHeight;
    780   i0 := sb.Position;
    781   Sel0 := Sel;
    782   if (x >= SideFrame) and (x < SideFrame + InnerWidth) and (y >= 0) and
    783     (y < InnerHeight) and (y mod LineDistance >= 4) and (y mod LineDistance < 20)
     774  i0, Sel0, iColumn, OldScienceNation, xScreen: Integer;
     775  S: string;
     776begin
     777  Y := Y - TitleHeight;
     778  i0 := ScrollBar.Position;
     779  Sel0 := Selected;
     780  if (X >= SideFrame) and (X < SideFrame + InnerWidth) and (Y >= 0) and
     781    (Y < InnerHeight) and (Y mod LineDistance >= 4) and (Y mod LineDistance < 20)
    784782  then
    785     Sel := y div LineDistance - 1
     783    Selected := Y div LineDistance - 1
    786784  else
    787     Sel := -2;
    788   if (Sel < -1) or (Sel > DispLines) or (Sel + i0 < 0) or
    789     (Sel + i0 >= Lines[Layer]) then
    790     Sel := -2;
    791   if Sel <> Sel0 then
     785    Selected := -2;
     786  if (Selected < -1) or (Selected > DispLines) or (Selected + i0 < 0) or
     787    (Selected + i0 >= Lines[Layer]) then
     788    Selected := -2;
     789  if Selected <> Sel0 then
    792790  begin
    793791    if Sel0 <> -2 then
    794       line(Canvas, Sel0, false, false);
    795     if Sel <> -2 then
    796       line(Canvas, Sel, false, true)
     792      Line(Canvas, Sel0, False, False);
     793    if Selected <> -2 then
     794      Line(Canvas, Selected, False, True);
    797795  end;
    798796
     
    801799    OldScienceNation := ScienceNation;
    802800    ScienceNation := -1;
    803     if (x >= SideFrame + (104 - 33 + 15 + TechNameSpace)) and
    804       ((x - SideFrame - (104 - 33 + 15 + TechNameSpace)) mod 24 <= 18) and
    805       (y >= 0) and (y < InnerHeight) then
     801    if (X >= SideFrame + (104 - 33 + 15 + TechNameSpace)) and
     802      ((X - SideFrame - (104 - 33 + 15 + TechNameSpace)) mod 24 <= 18) and
     803      (Y >= 0) and (Y < InnerHeight) then
    806804    begin
    807       iColumn := (x - SideFrame - (104 - 33 + 15 + TechNameSpace)) div 24;
     805      iColumn := (X - SideFrame - (104 - 33 + 15 + TechNameSpace)) div 24;
    808806      if (iColumn >= 1) and (iColumn < nColumn) then
    809807        ScienceNation := Column[iColumn];
     
    816814      if ScienceNation >= 0 then
    817815      begin
    818         s := Tribe[ScienceNation].TPhrase('SHORTNAME');
     816        S := Tribe[ScienceNation].TPhrase('SHORTNAME');
    819817        if MyRO.Alive and (1 shl ScienceNation) = 0 then
    820           s := Format(Phrases.Lookup('SCIENCEREPORT_EXTINCT'), [s]) // extinct
     818          S := Format(Phrases.Lookup('SCIENCEREPORT_EXTINCT'), [S]) // extinct
    821819        else if MyRO.EnemyReport[ScienceNation].TurnOfCivilReport < MyRO.Turn - 1
    822820        then
    823           s := s + ' (' + TurnToString(MyRO.EnemyReport[ScienceNation]
     821          S := S + ' (' + TurnToString(MyRO.EnemyReport[ScienceNation]
    824822            .TurnOfCivilReport) + ')'; // old report
    825         xScreen := (ClientWidth - BiColorTextWidth(Canvas, s)) div 2;
     823        xScreen := (ClientWidth - BiColorTextWidth(Canvas, S)) div 2;
    826824        LoweredTextOut(Canvas, -1, MainTexture, xScreen + 10,
    827           ClientHeight - 29, s);
    828         DpiBitCanvas(ScienceNationDotBuffer.Canvas, 0, 0, ScienceNationDot.Width,
     825          ClientHeight - 29, S);
     826        DpiBitBltCanvas(ScienceNationDotBuffer.Canvas, 0, 0, ScienceNationDot.Width,
    829827          ScienceNationDot.Height, Canvas, xScreen - 10, ClientHeight - 27);
    830828        ImageOp_BCC(ScienceNationDotBuffer, Templates.Data, Point(0, 0),
    831829          ScienceNationDot.BoundsRect, MainTexture.ColorBevelShade, Tribe[ScienceNation].Color);
    832         DpiBitCanvas(Canvas, xScreen - 10, ClientHeight - 27, ScienceNationDot.Width,
     830        DpiBitBltCanvas(Canvas, xScreen - 10, ClientHeight - 27, ScienceNationDot.Width,
    833831          ScienceNationDot.Height, ScienceNationDotBuffer.Canvas, 0, 0);
    834832      end;
     
    840838  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    841839begin
    842   if sb.ProcessMouseWheel(WheelDelta) then begin
     840  if ScrollBar.ProcessMouseWheel(WheelDelta) then begin
    843841    PaintBox1MouseMove(nil, [], MousePos.X - Left,
    844842      MousePos.Y - Top);
     
    846844end;
    847845
    848 function TListDlg.RenameCity(cix: integer): boolean;
     846procedure TListDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction);
     847begin
     848  //Gtk2Fix;
     849end;
     850
     851function TListDlg.RenameCity(cix: Integer): Boolean;
    849852var
    850853  CityNameInfo: TCityNameInfo;
     
    859862    CityNameInfo.ID := MyCity[cix].ID;
    860863    CityNameInfo.NewName := InputDlg.EInput.Text;
    861     Server(cSetCityName + (length(CityNameInfo.NewName) + 8) div 4, me, 0,
    862       CityNameInfo);
    863     if CityDlg.Visible then
     864    if CityNameInfo.GetCommandDataSize > CommandDataMaxSize then
     865      Delete(CityNameInfo.NewName, Length(CityNameInfo.NewName) -
     866        (CityNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt);
     867    Server(CommandWithData(cSetCityName, CityNameInfo.GetCommandDataSize),
     868      Me, 0, CityNameInfo);
     869    if MainScreen.CityDlg.Visible then
    864870    begin
    865       CityDlg.FormShow(nil);
    866       CityDlg.Invalidate;
     871      MainScreen.CityDlg.FormShow(nil);
     872      MainScreen.CityDlg.Invalidate;
    867873    end;
    868     result := true;
     874    Result := True;
    869875  end
    870876  else
    871     result := false;
    872 end;
    873 
    874 function TListDlg.RenameModel(mix: integer): boolean;
     877    Result := False;
     878end;
     879
     880function TListDlg.RenameModel(mix: Integer): Boolean;
    875881var
    876882  ModelNameInfo: TModelNameInfo;
    877883begin
    878884  InputDlg.Caption := Phrases.Lookup('TITLE_MODELNAME');
    879   InputDlg.EInput.Text := Tribe[me].ModelName[mix];
     885  InputDlg.EInput.Text := Tribe[Me].ModelName[mix];
    880886  InputDlg.CenterToRect(BoundsRect);
    881887  InputDlg.ShowModal;
    882888  if (InputDlg.ModalResult = mrOK) and (InputDlg.EInput.Text <> '') and
    883     (InputDlg.EInput.Text <> Tribe[me].ModelName[mix]) then
     889    (InputDlg.EInput.Text <> Tribe[Me].ModelName[mix]) then
    884890  begin
    885891    ModelNameInfo.mix := mix;
    886892    ModelNameInfo.NewName := InputDlg.EInput.Text;
    887     Server(cSetModelName + (length(ModelNameInfo.NewName) + 1 + 4 + 3) div 4,
    888       me, 0, ModelNameInfo);
    889     if UnitStatDlg.Visible then
     893    if ModelNameInfo.GetCommandDataSize > CommandDataMaxSize then
     894      Delete(ModelNameInfo.NewName, Length(ModelNameInfo.NewName) -
     895        (ModelNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt);
     896    Server(CommandWithData(cSetModelName, ModelNameInfo.GetCommandDataSize),
     897      Me, 0, ModelNameInfo);
     898    if MainScreen.UnitStatDlg.Visible then
    890899    begin
    891       UnitStatDlg.FormShow(nil);
    892       UnitStatDlg.Invalidate;
     900      MainScreen.UnitStatDlg.FormShow(nil);
     901      MainScreen.UnitStatDlg.Invalidate;
    893902    end;
    894     result := true;
     903    Result := True;
    895904  end
    896905  else
    897     result := false;
     906    Result := False;
    898907end;
    899908
    900909procedure TListDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    901   Shift: TShiftState; x, y: integer);
     910  Shift: TShiftState; X, Y: Integer);
    902911var
    903   lix: integer;
    904 begin
    905   if sb.Position + Sel >= 0 then
    906     lix := code[Layer, sb.Position + Sel];
     912  lix: Integer;
     913begin
     914  if ScrollBar.Position + Selected >= 0 then
     915    lix := Code[Layer, ScrollBar.Position + Selected];
    907916  if Kind in [kScience, kCities, kCityEvents, kModels, kEModels, kAllEModels]
    908917  then
    909     include(Shift, ssShift); // don't close list window
     918    Include(Shift, ssShift); // don't close list window
    910919  if (ssLeft in Shift) and not(ssShift in Shift) then
    911920  begin
    912     if Sel <> -2 then
     921    if Selected <> -2 then
    913922    begin
    914       result := lix;
    915       Closable := true;
     923      Result := lix;
     924      Closable := True;
    916925      Close;
    917926    end;
     
    919928  else if (ssLeft in Shift) and (ssShift in Shift) then
    920929  begin // show help/info popup
    921     if Sel <> -2 then
     930    if Selected <> -2 then
    922931      case Kind of
    923932        kCities:
    924933          MainScreen.ZoomToCity(MyCity[lix].Loc);
    925934        kCityEvents:
    926           MainScreen.ZoomToCity(MyCity[lix].Loc, false, MyCity[lix].Flags and
     935          MainScreen.ZoomToCity(MyCity[lix].Loc, False, MyCity[lix].Flags and
    927936            CityRepMask);
    928937        kModels, kChooseModel:
    929938          if lix <> mixAll then
    930             UnitStatDlg.ShowNewContent_OwnModel(FWindowMode or
    931               wmPersistent, lix);
     939            MainScreen.UnitStatDlg.ShowNewContent_OwnModel(wmPersistent, lix);
    932940        kEModels:
    933           UnitStatDlg.ShowNewContent_EnemyModel(FWindowMode or wmPersistent,
    934             code[1, sb.Position + Sel]);
     941          MainScreen.UnitStatDlg.ShowNewContent_EnemyModel(wmPersistent,
     942            Code[1, ScrollBar.Position + Selected]);
    935943        kAllEModels, kChooseEModel:
    936944          if lix <> mixAll then
    937             UnitStatDlg.ShowNewContent_EnemyModel(FWindowMode or
    938               wmPersistent, lix);
     945            MainScreen.UnitStatDlg.ShowNewContent_EnemyModel(wmPersistent, lix);
    939946        kAdvance, kFarAdvance, kScience, kChooseTech, kChooseETech, kStealTech:
    940947          if lix = adMilitary then
    941             HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkText,
    942               HelpDlg.TextIndex('MILRES'))
     948            MainScreen.HelpDlg.ShowNewContent(wmPersistent, hkText,
     949              MainScreen.HelpDlg.TextIndex('MILRES'))
    943950          else if lix < adMilitary then
    944             HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkAdv, lix);
     951            MainScreen.HelpDlg.ShowNewContent(wmPersistent, hkAdv, lix);
    945952        kProject:
    946953          if lix = cpImp + imTrGoods then
    947             HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkText,
    948               HelpDlg.TextIndex('TRADINGGOODS'))
     954            MainScreen.HelpDlg.ShowNewContent(wmPersistent, hkText,
     955              MainScreen.HelpDlg.TextIndex('TRADINGGOODS'))
    949956          else if lix and (cpImp + cpType) = 0 then
    950             UnitStatDlg.ShowNewContent_OwnModel(FWindowMode or wmPersistent,
     957            MainScreen.UnitStatDlg.ShowNewContent_OwnModel(wmPersistent,
    951958              lix and cpIndex)
    952959          else if (lix and cpType = 0) and (lix <> cpImp + imTrGoods) then
    953             HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp,
     960            MainScreen.HelpDlg.ShowNewContent(wmPersistent, hkImp,
    954961              lix and cpIndex);
    955962        kGov:
    956           HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkMisc,
    957             miscGovList);
     963          MainScreen.HelpDlg.ShowNewContent(wmPersistent, hkMisc,
     964            Integer(miscGovList));
    958965        kShipPart, kEShipPart:
    959966          ;
     
    962969  else if ssRight in Shift then
    963970  begin
    964     if Sel <> -2 then
     971    if Selected <> -2 then
    965972      case Kind of
    966973        kCities, kCityEvents:
     
    976983procedure TListDlg.InitLines;
    977984var
    978   required: array [0 .. nAdv - 1] of integer;
    979 
    980   procedure TryAddImpLine(Layer, Project: integer);
    981   begin
    982     if Server(sSetCityProject - sExecute, me, cixProject, Project) >= rExecuted
     985  required: array [0 .. nAdv - 1] of Integer;
     986
     987  procedure TryAddImpLine(Layer, Project: Integer);
     988  begin
     989    if Server(sSetCityProject - sExecute, Me, cixProject, Project) >= rExecuted
    983990    then
    984991    begin
    985       code[Layer, Lines[Layer]] := Project;
    986       inc(Lines[Layer]);
     992      Code[Layer, Lines[Layer]] := Project;
     993      Inc(Lines[Layer]);
    987994    end;
    988995  end;
     
    990997  procedure SortTechs;
    991998  var
    992     i, j, swap: integer;
     999    I, J, swap: Integer;
    9931000  begin // sort by advancedness
    994     for i := 0 to Lines[0] - 2 do
    995       if code[0, i] < adMilitary then
    996         for j := i + 1 to Lines[0] - 1 do
    997           if AdvValue[code[0, i]] * nAdv + code[0, i] < AdvValue[code[0, j]] *
    998             nAdv + code[0, j] then
    999           begin
    1000             swap := code[0, i];
    1001             code[0, i] := code[0, j];
    1002             code[0, j] := swap;
     1001    for I := 0 to Lines[0] - 2 do
     1002      if Code[0, I] < adMilitary then
     1003        for J := I + 1 to Lines[0] - 1 do
     1004          if AdvValue[Code[0, I]] * nAdv + Code[0, I] < AdvValue[Code[0, J]] *
     1005            nAdv + Code[0, J] then
     1006          begin
     1007            swap := Code[0, I];
     1008            Code[0, I] := Code[0, J];
     1009            Code[0, J] := swap;
    10031010          end;
    10041011  end;
     
    10061013  procedure SortCities;
    10071014  var
    1008     i, j, swap: integer;
    1009   begin
    1010     for i := 0 to Lines[0] - 2 do
    1011       for j := i + 1 to Lines[0] - 1 do
    1012         if CityName(MyCity[code[0, i]].ID) > CityName(MyCity[code[0, j]].ID)
     1015    I, J, swap: Integer;
     1016  begin
     1017    for I := 0 to Lines[0] - 2 do
     1018      for J := I + 1 to Lines[0] - 1 do
     1019        if CityName(MyCity[Code[0, I]].ID) > CityName(MyCity[Code[0, J]].ID)
    10131020        then
    10141021        begin
    1015           swap := code[0, i];
    1016           code[0, i] := code[0, j];
    1017           code[0, j] := swap;
     1022          swap := Code[0, I];
     1023          Code[0, I] := Code[0, J];
     1024          Code[0, J] := swap;
    10181025        end;
    10191026  end;
    10201027
    10211028  function ModelSortValue(const mi: TModelInfo;
    1022     MixPlayers: boolean = false): integer;
    1023   begin
    1024     result := (mi.Domain + 1) shl 28 - mi.mix;
     1029    MixPlayers: Boolean = False): Integer;
     1030  begin
     1031    Result := (mi.Domain + 1) shl 28 - mi.mix;
    10251032    if MixPlayers then
    1026       dec(result, ModelCode(mi) shl 16);
     1033      Dec(Result, ModelCode(mi) shl 16);
    10271034  end;
    10281035
    10291036  procedure SortModels;
    10301037  var
    1031     i, j, swap: integer;
     1038    I, J, swap: Integer;
    10321039  begin // sort by code[2]
    1033     for i := 0 to Lines[0] - 2 do
    1034       for j := i + 1 to Lines[0] - 1 do
    1035         if code[2, i] > code[2, j] then
    1036         begin
    1037           swap := code[0, i];
    1038           code[0, i] := code[0, j];
    1039           code[0, j] := swap;
    1040           swap := code[1, i];
    1041           code[1, i] := code[1, j];
    1042           code[1, j] := swap;
    1043           swap := code[2, i];
    1044           code[2, i] := code[2, j];
    1045           code[2, j] := swap;
    1046         end;
    1047   end;
    1048 
    1049   procedure MarkPreqs(i: integer);
    1050   begin
    1051     required[i] := 1;
    1052     if MyRO.Tech[i] < tsSeen then
     1040    for I := 0 to Lines[0] - 2 do
     1041      for J := I + 1 to Lines[0] - 1 do
     1042        if Code[2, I] > Code[2, J] then
     1043        begin
     1044          swap := Code[0, I];
     1045          Code[0, I] := Code[0, J];
     1046          Code[0, J] := swap;
     1047          swap := Code[1, I];
     1048          Code[1, I] := Code[1, J];
     1049          Code[1, J] := swap;
     1050          swap := Code[2, I];
     1051          Code[2, I] := Code[2, J];
     1052          Code[2, J] := swap;
     1053        end;
     1054  end;
     1055
     1056  procedure MarkPreqs(I: Integer);
     1057  begin
     1058    required[I] := 1;
     1059    if MyRO.Tech[I] < tsSeen then
    10531060    begin
    1054       if (AdvPreq[i, 0] >= 0) then
    1055         MarkPreqs(AdvPreq[i, 0]);
    1056       if (AdvPreq[i, 1] >= 0) then
    1057         MarkPreqs(AdvPreq[i, 1]);
     1061      if (AdvPreq[I, 0] >= 0) then
     1062        MarkPreqs(AdvPreq[I, 0]);
     1063      if (AdvPreq[I, 1] >= 0) then
     1064        MarkPreqs(AdvPreq[I, 1]);
    10581065    end;
    10591066  end;
    10601067
    10611068var
    1062   Loc1, i, j, p1, dx, dy, mix, emix, EnemyType, TestEnemyType: integer;
     1069  Loc1, I, J, p1, dx, dy, mix, emix, EnemyType, TestEnemyType: Integer;
    10631070  mi: TModelInfo;
    10641071  PPicture, PTestPicture: ^TModelPicture;
    1065   ModelOk: array [0 .. 4095] of boolean;
    1066   ok: boolean;
    1067 begin
    1068   for i := 0 to MaxLayer - 1 do
    1069   begin
    1070     Lines[i] := 0;
    1071     FirstShrinkedLine[i] := MaxInt;
     1072  ModelOk: array [0 .. 4095] of Boolean;
     1073  ok: Boolean;
     1074begin
     1075  for I := 0 to MaxLayer - 1 do
     1076  begin
     1077    Lines[I] := 0;
     1078    FirstShrinkedLine[I] := MaxInt;
    10721079  end;
    10731080  case Kind of
     
    10751082      begin
    10761083        // improvements
    1077         code[0, 0] := cpImp + imTrGoods;
     1084        Code[0, 0] := cpImp + imTrGoods;
    10781085        Lines[0] := 1;
    1079         for i := nWonder to nImp - 1 do
    1080           if Imp[i].Kind = ikCommon then
    1081             TryAddImpLine(0, i + cpImp);
    1082         for i := nWonder to nImp - 1 do
    1083           if not(Imp[i].Kind in [ikCommon, ikTrGoods]) and
    1084             ((MyRO.NatBuilt[i] = 0) or (Imp[i].Kind = ikNatLocal)) then
    1085             TryAddImpLine(0, i + cpImp);
    1086         for i := 0 to nCityType - 1 do
    1087           if MyData.ImpOrder[i, 0] >= 0 then
    1088           begin
    1089             code[0, Lines[0]] := cpType + i;
    1090             inc(Lines[0]);
     1086        for I := nWonder to nImp - 1 do
     1087          if Imp[I].Kind = ikCommon then
     1088            TryAddImpLine(0, I + cpImp);
     1089        for I := nWonder to nImp - 1 do
     1090          if not(Imp[I].Kind in [ikCommon, ikTrGoods]) and
     1091            ((MyRO.NatBuilt[I] = 0) or (Imp[I].Kind = ikNatLocal)) then
     1092            TryAddImpLine(0, I + cpImp);
     1093        for I := 0 to nCityType - 1 do
     1094          if MyData.ImpOrder[I, 0] >= 0 then
     1095          begin
     1096            Code[0, Lines[0]] := cpType + I;
     1097            Inc(Lines[0]);
    10911098          end;
    10921099
    10931100        // wonders
    1094         for i := 0 to nWonder - 1 do
    1095           TryAddImpLine(1, i + cpImp);
     1101        for I := 0 to nWonder - 1 do
     1102          TryAddImpLine(1, I + cpImp);
    10961103
    10971104        // units
    1098         for i := 0 to MyRO.nModel - 1 do
     1105        for I := 0 to MyRO.nModel - 1 do
    10991106        begin
    11001107          { if MyModel[i].Kind=mkSlaves then
    1101             ok:= MyRO.Wonder[woPyramids].EffectiveOwner=me
    1102             else } if MyModel[i].Domain = dSea then
    1103           begin
    1104             ok := false;
     1108            ok:= MyRO.Wonder[woPyramids].EffectiveOwner=Me
     1109            else } if MyModel[I].Domain = dSea then
     1110          begin
     1111            ok := False;
    11051112            for dx := -2 to 2 do
    11061113              for dy := -2 to 2 do
     
    11111118                    ((MyMap[Loc1] and fTerrain = fShore) or
    11121119                    (MyMap[Loc1] and fCanal > 0)) then
    1113                     ok := true;
     1120                    ok := True;
    11141121                end;
    11151122          end
    11161123          else
    1117             ok := true;
     1124            ok := True;
    11181125          if ok then
    11191126          begin
    1120             if MyModel[i].Status and msObsolete = 0 then
     1127            if MyModel[I].Status and msObsolete = 0 then
    11211128            begin
    1122               code[2, Lines[2]] := i;
    1123               inc(Lines[2]);
     1129              Code[2, Lines[2]] := I;
     1130              Inc(Lines[2]);
    11241131            end;
    1125             if MyModel[i].Status and msAllowConscripts <> 0 then
     1132            if MyModel[I].Status and msAllowConscripts <> 0 then
    11261133            begin
    1127               code[2, Lines[2]] := i + cpConscripts;
    1128               inc(Lines[2]);
     1134              Code[2, Lines[2]] := I + cpConscripts;
     1135              Inc(Lines[2]);
    11291136            end;
    11301137          end;
     
    11401147          MarkPreqs(MyData.FarTech);
    11411148        end;
    1142         for i := 0 to nAdv - 1 do
    1143           if ((i in FutureTech) or (MyRO.Tech[i] < tsApplicable)) and
    1144             (Server(sSetResearch - sExecute, me, i, nil^) >= rExecuted) and
    1145             ((MyData.FarTech = adNone) or (required[i] > 0)) then
    1146           begin
    1147             code[0, Lines[0]] := i;
    1148             inc(Lines[0]);
     1149        for I := 0 to nAdv - 1 do
     1150          if ((I in FutureTech) or (MyRO.Tech[I] < tsApplicable)) and
     1151            (Server(sSetResearch - sExecute, Me, I, nil^) >= rExecuted) and
     1152            ((MyData.FarTech = adNone) or (required[I] > 0)) then
     1153          begin
     1154            Code[0, Lines[0]] := I;
     1155            Inc(Lines[0]);
    11491156          end;
    11501157        SortTechs;
    11511158        if Lines[0] = 0 then // no more techs -- offer nexus
    11521159        begin
    1153           code[0, Lines[0]] := adNexus;
    1154           inc(Lines[0]);
    1155         end;
    1156         ok := false;
    1157         for i := 0 to nDomains - 1 do
    1158           if (upgrade[i, 0].Preq = preNone) or
    1159             (MyRO.Tech[upgrade[i, 0].Preq] >= tsApplicable) then
    1160             ok := true;
     1160          Code[0, Lines[0]] := adNexus;
     1161          Inc(Lines[0]);
     1162        end;
     1163        ok := False;
     1164        for I := 0 to nDomains - 1 do
     1165          if (upgrade[I, 0].Preq = preNone) or
     1166            (MyRO.Tech[upgrade[I, 0].Preq] >= tsApplicable) then
     1167            ok := True;
    11611168        if ok then { new unit class }
    11621169        begin
    1163           code[0, Lines[0]] := adMilitary;
    1164           inc(Lines[0]);
     1170          Code[0, Lines[0]] := adMilitary;
     1171          Inc(Lines[0]);
    11651172        end;
    11661173      end;
    11671174    kFarAdvance:
    11681175      begin
    1169         code[0, Lines[0]] := adNone;
    1170         inc(Lines[0]);
    1171         for i := 0 to nAdv - 1 do
    1172           if not(i in FutureTech) and (MyRO.Tech[i] < tsApplicable) and
    1173             ((AdvValue[i] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and
    1174             ((AdvValue[i] < 1000) or (MyRO.Tech[adScience] > tsNA)) then
    1175           begin
    1176             code[0, Lines[0]] := i;
    1177             inc(Lines[0]);
     1176        Code[0, Lines[0]] := adNone;
     1177        Inc(Lines[0]);
     1178        for I := 0 to nAdv - 1 do
     1179          if not(I in FutureTech) and (MyRO.Tech[I] < tsApplicable) and
     1180            ((AdvValue[I] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and
     1181            ((AdvValue[I] < 1000) or (MyRO.Tech[adScience] > tsNA)) then
     1182          begin
     1183            Code[0, Lines[0]] := I;
     1184            Inc(Lines[0]);
    11781185          end;
    11791186        SortTechs;
     
    11811188    kChooseTech:
    11821189      begin
    1183         for i := 0 to nAdv - 1 do
    1184           if not(i in FutureTech) and (MyRO.Tech[i] >= tsApplicable) and
    1185             (MyRO.EnemyReport[DipMem[me].pContact].Tech[i] < tsSeen) then
    1186           begin
    1187             code[0, Lines[0]] := i;
    1188             inc(Lines[0]);
     1190        for I := 0 to nAdv - 1 do
     1191          if not(I in FutureTech) and (MyRO.Tech[I] >= tsApplicable) and
     1192            (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] < tsSeen) then
     1193          begin
     1194            Code[0, Lines[0]] := I;
     1195            Inc(Lines[0]);
    11891196          end;
    11901197        SortTechs;
    11911198        // if Lines[0]>1 then
    11921199        begin
    1193           code[0, Lines[0]] := adAll;
    1194           inc(Lines[0]);
     1200          Code[0, Lines[0]] := adAll;
     1201          Inc(Lines[0]);
    11951202        end;
    11961203      end;
    11971204    kChooseETech:
    11981205      begin
    1199         for i := 0 to nAdv - 1 do
    1200           if not(i in FutureTech) and (MyRO.Tech[i] < tsSeen) and
    1201             (MyRO.EnemyReport[DipMem[me].pContact].Tech[i] >= tsApplicable) then
    1202           begin
    1203             code[0, Lines[0]] := i;
    1204             inc(Lines[0]);
     1206        for I := 0 to nAdv - 1 do
     1207          if not(I in FutureTech) and (MyRO.Tech[I] < tsSeen) and
     1208            (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] >= tsApplicable) then
     1209          begin
     1210            Code[0, Lines[0]] := I;
     1211            Inc(Lines[0]);
    12051212          end;
    12061213        SortTechs;
    12071214        // if Lines[0]>1 then
    12081215        begin
    1209           code[0, Lines[0]] := adAll;
    1210           inc(Lines[0]);
     1216          Code[0, Lines[0]] := adAll;
     1217          Inc(Lines[0]);
    12111218        end;
    12121219      end;
    12131220    kStealTech:
    12141221      begin
    1215         for i := 0 to nAdv - 1 do
    1216           if Server(sStealTech - sExecute, me, i, nil^) >= rExecuted then
    1217           begin
    1218             code[0, Lines[0]] := i;
    1219             inc(Lines[0]);
     1222        for I := 0 to nAdv - 1 do
     1223          if Server(sStealTech - sExecute, Me, I, nil^) >= rExecuted then
     1224          begin
     1225            Code[0, Lines[0]] := I;
     1226            Inc(Lines[0]);
    12201227          end;
    12211228        SortTechs;
     
    12231230    kScience:
    12241231      begin
    1225         Column[0] := me;
     1232        Column[0] := Me;
    12261233        nColumn := 1;
    12271234        for EnemyType := 0 to 2 do
     
    12411248              begin
    12421249                Column[nColumn] := p1;
    1243                 inc(nColumn);
     1250                Inc(nColumn);
    12441251              end;
    12451252            end;
    1246         for i := 0 to nAdv - 1 do
    1247         begin
    1248           ok := (MyRO.Tech[i] <> tsNA) or (MyRO.ResearchTech = i);
    1249           for j := 1 to nColumn - 1 do
    1250             with MyRO.EnemyReport[Column[j]]^ do
    1251               if (Tech[i] <> tsNA) or (TurnOfCivilReport >= 0) and
    1252                 (ResearchTech = i) then
    1253                 ok := true;
     1253        for I := 0 to nAdv - 1 do
     1254        begin
     1255          ok := (MyRO.Tech[I] <> tsNA) or (MyRO.ResearchTech = I);
     1256          for J := 1 to nColumn - 1 do
     1257            with MyRO.EnemyReport[Column[J]]^ do
     1258              if (Tech[I] <> tsNA) or (TurnOfCivilReport >= 0) and
     1259                (ResearchTech = I) then
     1260                ok := True;
    12541261          if ok then
    12551262          begin
    1256             code[0, Lines[0]] := i;
    1257             inc(Lines[0]);
     1263            Code[0, Lines[0]] := I;
     1264            Inc(Lines[0]);
    12581265          end;
    12591266        end;
     
    12611268
    12621269        ok := MyRO.ResearchTech = adMilitary;
    1263         for j := 1 to nColumn - 1 do
    1264           with MyRO.EnemyReport[Column[j]]^ do
    1265             if (MyRO.Alive and (1 shl Column[j]) <> 0) and
     1270        for J := 1 to nColumn - 1 do
     1271          with MyRO.EnemyReport[Column[J]]^ do
     1272            if (MyRO.Alive and (1 shl Column[J]) <> 0) and
    12661273              (TurnOfCivilReport >= 0) and (ResearchTech = adMilitary) then
    1267               ok := true;
     1274              ok := True;
    12681275        if ok then
    12691276        begin
    1270           code[0, Lines[0]] := adMilitary;
    1271           inc(Lines[0]);
     1277          Code[0, Lines[0]] := adMilitary;
     1278          Inc(Lines[0]);
    12721279        end
    12731280      end;
     
    12751282      begin
    12761283        if ClientMode < scContact then
    1277           for i := 0 to MyRO.nCity - 1 do
    1278             if MyCity[i].Loc >= 0 then
     1284          for I := 0 to MyRO.nCity - 1 do
     1285            if MyCity[I].Loc >= 0 then
    12791286            begin
    1280               code[0, Lines[0]] := i;
    1281               inc(Lines[0]);
     1287              Code[0, Lines[0]] := I;
     1288              Inc(Lines[0]);
    12821289            end;
    12831290        SortCities;
     
    12861293    kCityEvents:
    12871294      begin
    1288         for i := 0 to MyRO.nCity - 1 do
    1289           if (MyCity[i].Loc >= 0) and (MyCity[i].Flags and CityRepMask <> 0)
     1295        for I := 0 to MyRO.nCity - 1 do
     1296          if (MyCity[I].Loc >= 0) and (MyCity[I].Flags and CityRepMask <> 0)
    12901297          then
    12911298          begin
    1292             code[0, Lines[0]] := i;
    1293             inc(Lines[0]);
     1299            Code[0, Lines[0]] := I;
     1300            Inc(Lines[0]);
    12941301          end;
    12951302        SortCities;
     
    12981305    { kChooseECity:
    12991306      begin
    1300       for i:=0 to MyRO.nEnemyCity-1 do
    1301       if (MyRO.EnemyCity[i].Loc>=0)
    1302       and (MyRO.EnemyCity[i].owner=DipMem[me].pContact) then
    1303       begin code[0,Lines[0]]:=i; inc(Lines[0]); end;
     1307      for I:=0 to MyRO.nEnemyCity-1 do
     1308      if (MyRO.EnemyCity[I].Loc>=0)
     1309      and (MyRO.EnemyCity[I].owner=DipMem[Me].pContact) then
     1310      begin Code[0,Lines[0]]:=I; Inc(Lines[0]); end;
    13041311      FirstShrinkedLine:=0
    13051312      end; }
     
    13081315        for mix := 0 to MyRO.nModel - 1 do
    13091316        begin
    1310           code[0, mix] := mix;
    1311           MakeModelInfo(me, mix, MyModel[mix], mi);
    1312           code[2, mix] := ModelSortValue(mi);
     1317          Code[0, mix] := mix;
     1318          MakeModelInfo(Me, mix, MyModel[mix], mi);
     1319          Code[2, mix] := ModelSortValue(mi);
    13131320        end;
    13141321        Lines[0] := MyRO.nModel;
     
    13201327        for mix := 3 to MyRO.nModel - 1 do
    13211328        begin // check if opponent already has this model
    1322           MakeModelInfo(me, mix, MyModel[mix], mi);
    1323           ok := true;
     1329          MakeModelInfo(Me, mix, MyModel[mix], mi);
     1330          ok := True;
    13241331          for emix := 0 to MyRO.nEnemyModel - 1 do
    1325             if (MyRO.EnemyModel[emix].Owner = DipMem[me].pContact) and
     1332            if (MyRO.EnemyModel[emix].Owner = DipMem[Me].pContact) and
    13261333              IsSameModel(MyRO.EnemyModel[emix], mi) then
    1327               ok := false;
     1334              ok := False;
    13281335          if ok then
    13291336          begin
    1330             code[0, Lines[0]] := mix;
    1331             MakeModelInfo(me, mix, MyModel[mix], mi);
    1332             code[2, Lines[0]] := ModelSortValue(mi);
    1333             inc(Lines[0]);
     1337            Code[0, Lines[0]] := mix;
     1338            MakeModelInfo(Me, mix, MyModel[mix], mi);
     1339            Code[2, Lines[0]] := ModelSortValue(mi);
     1340            Inc(Lines[0]);
    13341341          end;
    13351342        end;
     
    13371344        // if Lines[0]>1 then
    13381345        begin
    1339           code[0, Lines[0]] := mixAll;
    1340           inc(Lines[0]);;
     1346          Code[0, Lines[0]] := mixAll;
     1347          Inc(Lines[0]);;
    13411348        end;
    13421349        FirstShrinkedLine[0] := 0;
     
    13451352      begin
    13461353        if MyRO.TestFlags and tfUncover <> 0 then
    1347           Server(sGetModels, me, 0, nil^);
     1354          Server(sGetModels, Me, 0, nil^);
    13481355        for emix := 0 to MyRO.nEnemyModel - 1 do
    1349           ModelOk[emix] := MyRO.EnemyModel[emix].Owner = DipMem[me].pContact;
     1356          ModelOk[emix] := MyRO.EnemyModel[emix].Owner = DipMem[Me].pContact;
    13501357        for mix := 0 to MyRO.nModel - 1 do
    13511358        begin // don't list models I already have
    1352           MakeModelInfo(me, mix, MyModel[mix], mi);
     1359          MakeModelInfo(Me, mix, MyModel[mix], mi);
    13531360          for emix := 0 to MyRO.nEnemyModel - 1 do
    13541361            ModelOk[emix] := ModelOk[emix] and
     
    13581365          if ModelOk[emix] then
    13591366          begin
    1360             if not Assigned(Tribe[DipMem[me].pContact].ModelPicture
     1367            if not Assigned(Tribe[DipMem[Me].pContact].ModelPicture
    13611368              [MyRO.EnemyModel[emix].mix].HGr) then
    13621369              InitEnemyModel(emix);
    1363             code[0, Lines[0]] := emix;
    1364             code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix]);
    1365             inc(Lines[0]);
     1370            Code[0, Lines[0]] := emix;
     1371            Code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix]);
     1372            Inc(Lines[0]);
    13661373          end;
    13671374        SortModels;
    13681375        // if not IsMilReportNew(DipMem[me].pContact) or (Lines[0]>1) then
    13691376        begin
    1370           code[0, Lines[0]] := mixAll;
    1371           inc(Lines[0]);
     1377          Code[0, Lines[0]] := mixAll;
     1378          Inc(Lines[0]);
    13721379        end;
    13731380        FirstShrinkedLine[0] := 0;
     
    13751382    kEModels:
    13761383      begin
    1377         for i := 0 to MyRO.EnemyReport[pView].nModelCounted - 1 do
    1378         begin
    1379           code[1, Lines[0]] := MyRO.nEnemyModel - 1;
    1380           while (code[1, Lines[0]] >= 0) and
    1381             not((MyRO.EnemyModel[code[1, Lines[0]]].Owner = pView) and
    1382             (MyRO.EnemyModel[code[1, Lines[0]]].mix = i)) do
    1383             dec(code[1, Lines[0]]);
    1384           if not Assigned(Tribe[pView].ModelPicture[i].HGr) then
    1385             InitEnemyModel(code[1, Lines[0]]);
    1386           code[0, Lines[0]] := i;
    1387           code[2, Lines[0]] :=
    1388             ModelSortValue(MyRO.EnemyModel[code[1, Lines[0]]]);
    1389           inc(Lines[0]);
     1384        for I := 0 to MyRO.EnemyReport[pView].nModelCounted - 1 do
     1385        begin
     1386          Code[1, Lines[0]] := MyRO.nEnemyModel - 1;
     1387          while (Code[1, Lines[0]] >= 0) and
     1388            not((MyRO.EnemyModel[Code[1, Lines[0]]].Owner = pView) and
     1389            (MyRO.EnemyModel[Code[1, Lines[0]]].mix = I)) do
     1390            Dec(Code[1, Lines[0]]);
     1391          if not Assigned(Tribe[pView].ModelPicture[I].HGr) then
     1392            InitEnemyModel(Code[1, Lines[0]]);
     1393          Code[0, Lines[0]] := I;
     1394          Code[2, Lines[0]] :=
     1395            ModelSortValue(MyRO.EnemyModel[Code[1, Lines[0]]]);
     1396          Inc(Lines[0]);
    13901397        end;
    13911398        SortModels;
     
    13941401    kAllEModels:
    13951402      begin
    1396         if (MyRO.TestFlags and tfUncover <> 0) or (G.Difficulty[me] = 0) then
    1397           Server(sGetModels, me, 0, nil^);
     1403        if (MyRO.TestFlags and tfUncover <> 0) or (G.Difficulty[Me] = 0) then
     1404          Server(sGetModels, Me, 0, nil^);
    13981405        for emix := 0 to MyRO.nEnemyModel - 1 do
    13991406          if (MyRO.EnemyModel[emix].mix >= 3) and
     
    14051412            if not Assigned(PPicture.HGr) then
    14061413              InitEnemyModel(emix);
    1407             ok := true;
     1414            ok := True;
    14081415            if MainScreen.mNames.Checked then
    1409               for j := 0 to Lines[0] - 1 do
     1416              for J := 0 to Lines[0] - 1 do
    14101417              begin
    1411                 PTestPicture := @Tribe[MyRO.EnemyModel[code[0, j]].Owner]
    1412                   .ModelPicture[MyRO.EnemyModel[code[0, j]].mix];
     1418                PTestPicture := @Tribe[MyRO.EnemyModel[Code[0, J]].Owner]
     1419                  .ModelPicture[MyRO.EnemyModel[Code[0, J]].mix];
    14131420                if (PPicture.HGr = PTestPicture.HGr) and
    14141421                  (PPicture.pix = PTestPicture.pix) and
    14151422                  (ModelHash(MyRO.EnemyModel[emix])
    1416                   = ModelHash(MyRO.EnemyModel[code[0, j]])) then
     1423                  = ModelHash(MyRO.EnemyModel[Code[0, J]])) then
    14171424                begin
    1418                   code[1, j] := 1;
    1419                   ok := false;
     1425                  Code[1, J] := 1;
     1426                  ok := False;
    14201427                  Break;
    14211428                end;
     
    14231430            if ok then
    14241431            begin
    1425               code[0, Lines[0]] := emix;
    1426               code[1, Lines[0]] := 0;
    1427               code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix], true);
    1428               inc(Lines[0]);
     1432              Code[0, Lines[0]] := emix;
     1433              Code[1, Lines[0]] := 0;
     1434              Code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix], True);
     1435              Inc(Lines[0]);
    14291436            end;
    14301437          end;
     
    14331440      end;
    14341441    kTribe:
    1435       for i := 0 to TribeNames.Count - 1 do
    1436       begin
    1437         code[0, Lines[0]] := i;
    1438         inc(Lines[0]);
     1442      for I := 0 to TribeNames.Count - 1 do
     1443      begin
     1444        Code[0, Lines[0]] := I;
     1445        Inc(Lines[0]);
    14391446      end;
    14401447    (* kDeliver:
    1441       if MyRO.Treaty[DipMem[me].pContact]<trAlliance then
     1448      if MyRO.Treaty[DipMem[Me].pContact]<trAlliance then
    14421449      begin // suggest next treaty level
    1443       code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[me].pContact]+1;
    1444       inc(Lines[0]);
    1445       end;
    1446       if MyRO.Treaty[DipMem[me].pContact]=trNone then
     1450      Code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]+1;
     1451      Inc(Lines[0]);
     1452      end;
     1453      if MyRO.Treaty[DipMem[Me].pContact]=trNone then
    14471454      begin // suggest peace
    1448       code[0,Lines[0]]:=opTreaty+trPeace;
    1449       inc(Lines[0]);
    1450       end;
    1451       if MyRO.Treaty[DipMem[me].pContact]>trNone then
     1455      Code[0,Lines[0]]:=opTreaty+trPeace;
     1456      Inc(Lines[0]);
     1457      end;
     1458      if MyRO.Treaty[DipMem[Me].pContact]>trNone then
    14521459      begin // suggest next treaty level
    1453       code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[me].pContact]-1;
    1454       inc(Lines[0]);
     1460      Code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1;
     1461      Inc(Lines[0]);
    14551462      end; *)
    14561463    kShipPart:
    14571464      begin
    14581465        Lines[0] := 0;
    1459         for i := 0 to nShipPart - 1 do
    1460           if MyRO.Ship[me].Parts[i] > 0 then
    1461           begin
    1462             code[0, Lines[0]] := i;
    1463             inc(Lines[0]);
     1466        for I := 0 to nShipPart - 1 do
     1467          if MyRO.Ship[Me].Parts[I] > 0 then
     1468          begin
     1469            Code[0, Lines[0]] := I;
     1470            Inc(Lines[0]);
    14641471          end;
    14651472      end;
     
    14671474      begin
    14681475        Lines[0] := 0;
    1469         for i := 0 to nShipPart - 1 do
    1470           if MyRO.Ship[DipMem[me].pContact].Parts[i] > 0 then
    1471           begin
    1472             code[0, Lines[0]] := i;
    1473             inc(Lines[0]);
     1476        for I := 0 to nShipPart - 1 do
     1477          if MyRO.Ship[DipMem[Me].pContact].Parts[I] > 0 then
     1478          begin
     1479            Code[0, Lines[0]] := I;
     1480            Inc(Lines[0]);
    14741481          end;
    14751482      end;
    14761483    kGov:
    1477       for i := 1 to nGov - 1 do
    1478         if (GovPreq[i] <> preNA) and
    1479           ((GovPreq[i] = preNone) or (MyRO.Tech[GovPreq[i]] >= tsApplicable))
     1484      for I := 1 to nGov - 1 do
     1485        if (GovPreq[I] <> preNA) and
     1486          ((GovPreq[I] = preNone) or (MyRO.Tech[GovPreq[I]] >= tsApplicable))
    14801487        then
    14811488        begin
    1482           code[0, Lines[0]] := i;
    1483           inc(Lines[0]);
     1489          Code[0, Lines[0]] := I;
     1490          Inc(Lines[0]);
    14841491        end;
    14851492    kMission:
    1486       for i := 0 to nSpyMission - 1 do
    1487       begin
    1488         code[0, Lines[0]] := i;
    1489         inc(Lines[0]);
     1493      for I := 0 to nSpyMission - 1 do
     1494      begin
     1495        Code[0, Lines[0]] := I;
     1496        Inc(Lines[0]);
    14901497      end;
    14911498  end;
     
    14941501    if Lines[0] + Lines[1] + Lines[2] <= MaxLines then
    14951502    begin
    1496       for i := 0 to Lines[1] - 1 do // add wonders to first page
    1497       begin
    1498         code[0, Lines[0]] := code[1, i];
    1499         inc(Lines[0]);
     1503      for I := 0 to Lines[1] - 1 do // add wonders to first page
     1504      begin
     1505        Code[0, Lines[0]] := Code[1, I];
     1506        Inc(Lines[0]);
    15001507      end;
    15011508      Lines[1] := 0;
    15021509      FirstShrinkedLine[0] := Lines[0];
    1503       for i := 0 to Lines[2] - 1 do // add models to first page
    1504       begin
    1505         code[0, Lines[0]] := code[2, i];
    1506         inc(Lines[0]);
     1510      for I := 0 to Lines[2] - 1 do // add models to first page
     1511      begin
     1512        Code[0, Lines[0]] := Code[2, I];
     1513        Inc(Lines[0]);
    15071514      end;
    15081515      Lines[2] := 0;
    15091516    end;
    1510 end; // InitLines
    1511 
    1512 function TListDlg.OnlyChoice(TestKind: TListKind): integer;
     1517end;
     1518
     1519function TListDlg.OnlyChoice(TestKind: TListKind): Integer;
    15131520begin
    15141521  Kind := TestKind;
    15151522  InitLines;
    15161523  if Lines[0] = 0 then
    1517     result := -2
     1524    Result := -2
    15181525  else if Lines[0] > 1 then
    1519     result := -1
     1526    Result := -1
    15201527  else
    1521     result := code[0, 0];
     1528    Result := Code[0, 0];
    15221529end;
    15231530
    15241531procedure TListDlg.FormShow(Sender: TObject);
    15251532var
    1526   i: integer;
    1527 begin
    1528   result := -1;
    1529   Closable := false;
     1533  I: Integer;
     1534begin
     1535  Result := -1;
     1536  Closable := False;
    15301537
    15311538  if Kind = kTribe then
     
    15431550  InitLines;
    15441551
    1545   MultiPage := false;
    1546   for i := 1 to MaxLayer - 1 do
    1547     if Lines[i] > 0 then
    1548       MultiPage := true;
     1552  MultiPage := False;
     1553  for I := 1 to MaxLayer - 1 do
     1554    if Lines[I] > 0 then
     1555      MultiPage := True;
    15491556  WideBottom := MultiPage or (Kind = kScience) or
    15501557    not Phrases2FallenBackToEnglish and
     
    15521559  if (Kind = kAdvance) and (MyData.FarTech <> adNone) or (Kind = kModels) or
    15531560    (Kind = kEModels) then begin
    1554     sb.SetBorderSpacing(56, 10, 10);
     1561    ScrollBar.SetBorderSpacing(56, 10, 10);
    15551562    TitleHeight := WideFrame + 20;
    15561563  end else begin
    1557     sb.SetBorderSpacing(36, 10, 34);
     1564    ScrollBar.SetBorderSpacing(36, 10, 34);
    15581565    TitleHeight := WideFrame;
    15591566  end;
    15601567
    15611568  DispLines := Lines[0];
    1562   for i := 0 to MaxLayer - 1 do
    1563     if Lines[i] > DispLines then
    1564       DispLines := Lines[i];
     1569  for I := 0 to MaxLayer - 1 do
     1570    if Lines[I] > DispLines then
     1571      DispLines := Lines[I];
    15651572  if WideBottom then
    15661573  begin
     
    15771584    ClientHeight := InnerHeight + TitleHeight + NarrowFrame;
    15781585  end;
    1579   assert(ClientHeight <= Maintexture.Height);
     1586  Assert(ClientHeight <= Maintexture.Height);
    15801587
    15811588  TechNameSpace := 224;
     
    16151622  CaptionRight := CloseBtn.Left;
    16161623  { TODO:
    1617   SetWindowPos(sb.ScrollBar.Handle, 0, SideFrame + InnerWidth - DpiGetSystemMetrics(SM_CXVSCROLL),
     1624  SetWindowPos(ScrollBar.ScrollBar.Handle, 0, SideFrame + InnerWidth - DpiGetSystemMetrics(SM_CXVSCROLL),
    16181625    TitleHeight, DpiGetSystemMetrics(SM_CXVSCROLL), LineDistance * DispLines + 48,
    16191626    SWP_NOZORDER or SWP_NOREDRAW);
     
    16381645    Layer0Btn.Top := ClientHeight - 31;
    16391646    Layer0Btn.Left := ClientWidth div 2 - (12 + 29);
    1640     Layer0Btn.Down := true;
     1647    Layer0Btn.Down := True;
    16411648    Layer1Btn.Top := ClientHeight - 31;
    16421649    Layer1Btn.Left := ClientWidth div 2 - (12 - 29);
    1643     Layer1Btn.Down := false;
     1650    Layer1Btn.Down := False;
    16441651    Layer2Btn.Top := ClientHeight - 31;
    16451652    Layer2Btn.Left := ClientWidth div 2 - 12;
    1646     Layer2Btn.Down := false;
     1653    Layer2Btn.Down := False;
    16471654  end;
    16481655
    16491656  Layer := 0;
    1650   Sel := -2;
     1657  Selected := -2;
    16511658  ScienceNation := -1;
    1652   sb.Init(Lines[Layer] - 1, DispLines);
     1659  ScrollBar.Init(Lines[Layer] - 1, DispLines);
    16531660
    16541661  OffscreenPaint;
    16551662end;
    16561663
    1657 procedure TListDlg.ShowNewContent(NewMode: integer; ListKind: TListKind);
     1664procedure TListDlg.ShowNewContent(NewMode: TWindowMode; ListKind: TListKind);
    16581665var
    1659   i: integer;
    1660   ShowFocus, forceclose: boolean;
     1666  I: Integer;
     1667  ShowFocus, forceclose: Boolean;
    16611668begin
    16621669  forceclose := (ListKind <> Kind) and
     
    17221729  if Kind = kAdvance then // show focus button?
    17231730    if MyData.FarTech <> adNone then
    1724       ShowFocus := true
     1731      ShowFocus := True
    17251732    else
    17261733    begin
    1727       ShowFocus := false;
    1728       for i := 0 to nAdv - 1 do
    1729         if not(i in FutureTech) and (MyRO.Tech[i] < tsApplicable) and
    1730           ((AdvValue[i] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and
    1731           ((AdvValue[i] < 1000) or (MyRO.Tech[adScience] > tsNA)) and
    1732           (Server(sSetResearch - sExecute, me, i, nil^) < rExecuted) then
    1733           ShowFocus := true;
     1734      ShowFocus := False;
     1735      for I := 0 to nAdv - 1 do
     1736        if not(I in FutureTech) and (MyRO.Tech[I] < tsApplicable) and
     1737          ((AdvValue[I] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and
     1738          ((AdvValue[I] < 1000) or (MyRO.Tech[adScience] > tsNA)) and
     1739          (Server(sSetResearch - sExecute, Me, I, nil^) < rExecuted) then
     1740          ShowFocus := True;
    17341741    end;
    1735   ToggleBtn.Visible := (Kind = kCities) and not supervising or (Kind = kAdvance)
     1742  ToggleBtn.Visible := (Kind = kCities) and not Supervising or (Kind = kAdvance)
    17361743    and ShowFocus or (Kind = kModels) or (Kind = kEModels);
    17371744  CloseBtn.Visible := not(Kind in MustChooseKind);
    17381745
    17391746  inherited ShowNewContent(NewMode, forceclose);
    1740 end; // ShowNewContent
    1741 
    1742 procedure TListDlg.ShowNewContent_CityProject(NewMode, cix: integer);
     1747end;
     1748
     1749procedure TListDlg.ShowNewContent_CityProject(NewMode: TWindowMode; cix: Integer);
    17431750begin
    17441751  cixProject := cix;
     
    17461753end;
    17471754
    1748 procedure TListDlg.ShowNewContent_MilReport(NewMode, p: integer);
    1749 begin
    1750   pView := p;
    1751   if p = me then
     1755procedure TListDlg.ShowNewContent_MilReport(NewMode: TWindowMode; P: Integer);
     1756begin
     1757  pView := P;
     1758  if P = Me then
    17521759    ShowNewContent(NewMode, kModels)
    17531760  else
     
    17571764procedure TListDlg.PlayerClick(Sender: TObject);
    17581765begin
    1759   if TComponent(Sender).Tag = me then
     1766  if TComponent(Sender).Tag = Me then
    17601767    Kind := kModels
    17611768  else
     
    17651772  end;
    17661773  InitLines;
    1767   Sel := -2;
    1768   sb.Init(Lines[Layer] - 1, DispLines);
     1774  Selected := -2;
     1775  ScrollBar.Init(Lines[Layer] - 1, DispLines);
    17691776  OffscreenPaint;
    17701777  Invalidate;
     
    17781785  Layer := TComponent(Sender).Tag;
    17791786
    1780   Sel := -2;
    1781   sb.Init(Lines[Layer] - 1, DispLines);
     1787  Selected := -2;
     1788  ScrollBar.Init(Lines[Layer] - 1, DispLines);
    17821789  SmartUpdateContent;
    17831790end;
     
    17851792procedure TListDlg.ToggleBtnClick(Sender: TObject);
    17861793var
    1787   p1: integer;
    1788   m: TDpiMenuItem;
     1794  p1: Integer;
     1795  M: TDpiMenuItem;
    17891796begin
    17901797  case Kind of
    17911798    kAdvance:
    17921799      begin
    1793         result := adFar;
    1794         Closable := true;
     1800        Result := adFar;
     1801        Closable := True;
    17951802        Close;
    17961803      end;
     
    18071814      begin
    18081815        EmptyMenu(Popup.Items);
    1809         if G.Difficulty[me] > 0 then
    1810         begin
    1811           m := TDpiMenuItem.Create(Popup);
    1812           m.RadioItem := true;
    1813           m.Caption := Tribe[me].TPhrase('SHORTNAME');
    1814           m.Tag := me;
    1815           m.OnClick := PlayerClick;
     1816        if G.Difficulty[Me] > 0 then
     1817        begin
     1818          M := TDpiMenuItem.Create(Popup);
     1819          M.RadioItem := True;
     1820          M.Caption := Tribe[Me].TPhrase('SHORTNAME');
     1821          M.Tag := Me;
     1822          M.OnClick := PlayerClick;
    18161823          if Kind = kModels then
    1817             m.Checked := true;
    1818           Popup.Items.Add(m);
     1824            M.Checked := True;
     1825          Popup.Items.Add(M);
    18191826        end;
    18201827        for p1 := 0 to nPl - 1 do
    1821           if (p1 <> me) and (MyRO.EnemyReport[p1] <> nil) and
     1828          if (p1 <> Me) and (MyRO.EnemyReport[p1] <> nil) and
    18221829            (MyRO.EnemyReport[p1].TurnOfMilReport >= 0) then
    18231830          begin
    1824             m := TDpiMenuItem.Create(Popup);
    1825             m.RadioItem := true;
    1826             m.Caption := Tribe[p1].TPhrase('SHORTNAME');
    1827             m.Tag := p1;
    1828             m.OnClick := PlayerClick;
     1831            M := TDpiMenuItem.Create(Popup);
     1832            M.RadioItem := True;
     1833            M.Caption := Tribe[p1].TPhrase('SHORTNAME');
     1834            M.Tag := p1;
     1835            M.OnClick := PlayerClick;
    18291836            if (Kind = kEModels) and (p1 = pView) then
    1830               m.Checked := true;
    1831             Popup.Items.Add(m);
     1837              M.Checked := True;
     1838            Popup.Items.Add(M);
    18321839          end;
    18331840        Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top +
     
    18371844end;
    18381845
    1839 procedure TListDlg.FormKeyDown(Sender: TObject; var Key: word;
     1846procedure TListDlg.FormKeyDown(Sender: TObject; var Key: Word;
    18401847  Shift: TShiftState);
    18411848begin
     
    18761883procedure TListDlg.RemoveUnit;
    18771884begin
    1878   if ListDlg.Visible and (Kind = kModels) then
     1885  if Visible and (Kind = kModels) then
    18791886    SmartUpdateContent;
    18801887end;
     
    18821889procedure TListDlg.ScrollBarUpdate(Sender: TObject);
    18831890begin
    1884   Sel := -2;
    1885   SmartUpdateContent(true);
     1891  Selected := -2;
     1892  SmartUpdateContent(True);
    18861893end;
    18871894
  • TabularUnified branches/highdpi/LocalPlayer/TechTree.pas

    r349 r465  
    3030  end;
    3131
    32 var
    33   TechTreeDlg: TTechTreeDlg;
    34 
    3532
    3633implementation
     
    5552  yLegendPitch = 32;
    5653
    57 function min(a, b: Integer): Integer;
    58 begin
    59   if a < b then
    60     result := a
     54function Min(A, B: Integer): Integer;
     55begin
     56  if A < B then
     57    Result := A
    6158  else
    62     result := b;
    63 end;
    64 
    65 function max(a, b: Integer): Integer;
    66 begin
    67   if a > b then
    68     result := a
     59    Result := B;
     60end;
     61
     62function Max(A, B: Integer): Integer;
     63begin
     64  if A > B then
     65    Result := A
    6966  else
    70     result := b;
     67    Result := B;
    7168end;
    7269
     
    8481procedure TTechTreeDlg.FormPaint(Sender: TObject);
    8582var
    86   X, w: Integer;
     83  X, W: Integer;
    8784begin
    8885  with Canvas do begin
    8986    // black border
    90     brush.color := $000000;
    91     fillrect(rect(0, 0, BlackBorder, ClientHeight));
    92     fillrect(rect(BlackBorder, 0, ClientWidth - BlackBorder, BlackBorder));
    93     fillrect(rect(ClientWidth - BlackBorder, 0, ClientWidth, ClientHeight));
    94     fillrect(rect(BlackBorder, ClientHeight - BlackBorder,
     87    Brush.Color := $000000;
     88    FillRect(rect(0, 0, BlackBorder, ClientHeight));
     89    FillRect(rect(BlackBorder, 0, ClientWidth - BlackBorder, BlackBorder));
     90    FillRect(rect(ClientWidth - BlackBorder, 0, ClientWidth, ClientHeight));
     91    FillRect(rect(BlackBorder, ClientHeight - BlackBorder,
    9592      ClientWidth - BlackBorder, ClientHeight));
    9693
    9794    // texturize empty space
    98     brush.color := $FFFFFF;
     95    Brush.Color := $FFFFFF;
    9996    if xOffset > 0 then
    10097      FillRectSeamless(Canvas, BlackBorder, BlackBorder, BlackBorder + xOffset,
     
    105102        ClientWidth - BlackBorder, ClientHeight - BlackBorder,
    106103        -BlackBorder - xOffset, -BlackBorder - yOffset, Paper);
    107     X := max(BlackBorder, BlackBorder + xOffset);
    108     w := min(BlackBorder + xOffset + Image.width, ClientWidth - BlackBorder);
     104    X := Max(BlackBorder, BlackBorder + xOffset);
     105    W := Min(BlackBorder + xOffset + Image.width, ClientWidth - BlackBorder);
    109106    if yOffset > 0 then
    110       FillRectSeamless(Canvas, X, BlackBorder, w, BlackBorder + yOffset,
     107      FillRectSeamless(Canvas, X, BlackBorder, W, BlackBorder + yOffset,
    111108        -BlackBorder - xOffset, -BlackBorder - yOffset, Paper);
    112109    if yOffset + Image.height < ClientHeight - 2 * BlackBorder then
    113       FillRectSeamless(Canvas, X, BlackBorder + yOffset + Image.height, w,
     110      FillRectSeamless(Canvas, X, BlackBorder + yOffset + Image.height, W,
    114111        ClientHeight - BlackBorder, -BlackBorder - xOffset,
    115112        -BlackBorder - yOffset, Paper);
    116113  end;
    117   DpiBitCanvas(Canvas, max(BlackBorder, BlackBorder + xOffset),
    118     max(BlackBorder, BlackBorder + yOffset),
    119     min(Image.width, min(Image.width + xOffset,
    120     min(ClientWidth - 2 * BlackBorder, ClientWidth - 2 * BlackBorder - xOffset))
    121     ), min(Image.height, min(Image.height + yOffset,
    122     min(ClientHeight - 2 * BlackBorder, ClientHeight - 2 * BlackBorder -
    123     yOffset))), Image.Canvas, max(0, -xOffset),
    124     max(0, -yOffset));
     114  DpiBitBltCanvas(Canvas, Max(BlackBorder, BlackBorder + xOffset),
     115    Max(BlackBorder, BlackBorder + yOffset),
     116    Min(Image.width, Min(Image.width + xOffset,
     117    Min(ClientWidth - 2 * BlackBorder, ClientWidth - 2 * BlackBorder - xOffset))
     118    ), Min(Image.height, Min(Image.height + yOffset,
     119    Min(ClientHeight - 2 * BlackBorder, ClientHeight - 2 * BlackBorder -
     120    yOffset))), Image.Canvas, Max(0, -xOffset),
     121    Max(0, -yOffset));
    125122end;
    126123
     
    128125var
    129126  X, Y, ad: Integer;
    130   s: string;
     127  S: string;
    131128  NewWidth: Integer;
    132129  NewHeight: Integer;
    133130begin
     131  Caption := Phrases2.Lookup('MENU_ADVTREE');
    134132  if Image = nil then begin
    135133    Image := TDpiBitmap.Create;
     
    139137
    140138    with Image.Canvas do begin
    141       // write advance names
     139      // Write advance names
    142140      Font.Assign(UniFont[ftSmall]);
    143       Font.color := clBlack;
    144       brush.Style := bsClear;
    145       for X := 0 to (Image.width - xStart) div xPitch do
    146         for Y := 0 to (Image.height - yStart) div yPitch do
     141      Font.Color := clBlack;
     142      Brush.Style := bsClear;
     143      for X := 0 to (Image.Width - xStart) div xPitch do
     144        for Y := 0 to (Image.Height - yStart) div yPitch do
    147145        begin
    148146          ad := Pixels[xStart + X * xPitch + 10, yStart + Y * yPitch - 1];
    149147          if ad and $FFFF00 = 0 then
    150148          begin
    151             s := Phrases.Lookup('ADVANCES', ad);
    152             while TextWidth(s) > 112 do
    153               Delete(s, Length(s), 1);
    154             TextOut(xStart + X * xPitch + 2, yStart + Y * yPitch, s);
     149            S := Phrases.Lookup('ADVANCES', ad);
     150            while TextWidth(S) > 112 do
     151              Delete(S, Length(S), 1);
     152            TextOut(xStart + X * xPitch + 2, yStart + Y * yPitch, S);
    155153            Pixels[xStart + X * xPitch + 10, yStart + Y * yPitch - 1]
    156154              := TransparentColor2;
    157           end
     155          end;
    158156        end;
    159157
    160       // write legend
     158      // Write legend
    161159      TextOut(xLegend, yLegend, Phrases2.Lookup('ADVTREE_UP0'));
    162160      TextOut(xLegend, yLegend + yLegendPitch, Phrases2.Lookup('ADVTREE_UP1'));
     
    172170  end;
    173171
    174   // fit window to image, center image in window, center window to screen
     172  // Fit window to image, center image in window, center window to screen
    175173  NewWidth := Min(DpiScreen.Width - 40, Image.Width + LeftBorder + RightBorder + 2 * BlackBorder);
    176174  NewHeight := Min(DpiScreen.Height - 40, Image.Height + TopBorder + BottomBorder + 2 * BlackBorder);
     
    190188  if Button = mbLeft then
    191189  begin
    192     dragging := true;
     190    Dragging := True;
    193191    xDown := X;
    194192    yDown := Y;
     
    199197  Shift: TShiftState; X, Y: Integer);
    200198begin
    201   dragging := false;
     199  Dragging := False;
    202200end;
    203201
     
    205203  X, Y: Integer);
    206204begin
    207   if dragging then
     205  if Dragging then
    208206  begin
    209207    xOffset := xOffset + X - xDown;
  • TabularUnified branches/highdpi/LocalPlayer/Term.lfm

    r405 r465  
    11object MainScreen: TMainScreen
    2   Left = 516
     2  Left = 469
    33  Height = 480
    4   Top = 834
     4  Top = 251
    55  Width = 800
    66  HorzScrollBar.Visible = False
     
    1414  DesignTimePPI = 144
    1515  Font.Color = clWindowText
    16   Font.Height = -13
     16  Font.Height = -20
    1717  Font.Name = 'MS Sans Serif'
    1818  KeyPreview = True
     
    3131  OnShow = FormShow
    3232  Position = poDefault
    33   LCLVersion = '2.0.12.0'
     33  LCLVersion = '2.2.0.4'
    3434  Scaled = False
    3535  WindowState = wsMaximized
     
    227227      Tag = 7
    228228      ShortCut = 112
    229       OnClick = MenuClick
     229      OnClick = mHelpClick
    230230    end
    231231    object mTechTree: TDpiMenuItem
    232232      GroupIndex = 1
    233233      ShortCut = 84
    234       OnClick = MenuClick
     234      OnClick = mTechTreeClick
    235235    end
    236236    object N12: TDpiMenuItem
     
    251251      object mOwnMovement: TDpiMenuItem
    252252        Tag = 30
    253         GroupIndex = 1
    254         RadioItem = True
    255253        object mSlowMoves: TDpiMenuItem
    256254          Tag = 75
     
    278276      object mAllyMovement: TDpiMenuItem
    279277        Tag = 90
    280         GroupIndex = 1
    281         RadioItem = True
    282278        object mAlSlowMoves: TDpiMenuItem
    283279          Tag = 91
     
    305301      object mEnemyMovement: TDpiMenuItem
    306302        Tag = 74
    307         GroupIndex = 1
    308         RadioItem = True
    309303        object mEnMoves: TDpiMenuItem
    310304          Tag = 78
     
    349343      object mRep: TDpiMenuItem
    350344        Tag = 34
    351         GroupIndex = 1
    352345        object mRep0: TDpiMenuItem
    353346          OnClick = mRepClicked
     
    417410        Caption = '-'
    418411        GroupIndex = 1
     412        RadioItem = True
    419413      end
    420414      object mWaitTurn: TDpiMenuItem
    421415        Tag = 32
    422         GroupIndex = 1
    423416        OnClick = Toggle
    424417      end
    425418      object mScrolling: TDpiMenuItem
    426419        Tag = 84
    427         GroupIndex = 1
    428420        object mScrollSlow: TDpiMenuItem
    429421          Tag = 85
     
    444436      object mTileSize: TDpiMenuItem
    445437        Tag = 96
    446         GroupIndex = 1
    447438        object mSmallTiles: TDpiMenuItem
    448439          Tag = 97
     
    463454      object mSound: TDpiMenuItem
    464455        Tag = 80
    465         GroupIndex = 1
    466456        object mSoundOn: TDpiMenuItem
    467457          Tag = 82
     
    484474        Caption = '-'
    485475        GroupIndex = 1
     476        RadioItem = True
    486477      end
    487478      object mTest: TDpiMenuItem
    488479        Tag = 8
    489         GroupIndex = 1
    490480        object mJump: TDpiMenuItem
    491481          Tag = 54
    492482          ShortCut = 16458
    493           OnClick = MenuClick
     483          OnClick = mJumpClick
    494484        end
    495485        object mRun: TDpiMenuItem
    496486          Tag = 63
    497487          ShortCut = 16466
    498           OnClick = MenuClick
     488          OnClick = mRunClick
    499489        end
    500490        object mNames: TDpiMenuItem
     
    552542      object mEnhanceDef: TDpiMenuItem
    553543        Tag = 40
    554         OnClick = MenuClick
     544        OnClick = mEnhanceDefClick
    555545      end
    556546      object mCityTypes: TDpiMenuItem
    557547        Tag = 11
    558         OnClick = MenuClick
     548        OnClick = mCityTypesClick
    559549      end
    560550    end
     
    563553      GroupIndex = 1
    564554      ShortCut = 16466
    565       OnClick = MenuClick
     555      OnClick = mRandomMapClick
    566556    end
    567557    object N3: TDpiMenuItem
     
    572562      Tag = 88
    573563      GroupIndex = 1
    574       OnClick = MenuClick
     564      OnClick = mWebsiteClick
    575565    end
    576566    object N2: TDpiMenuItem
     
    582572      GroupIndex = 1
    583573      ShortCut = 16465
    584       OnClick = MenuClick
     574      OnClick = mResignClick
    585575    end
    586576  end
     
    592582      Tag = 72
    593583      ShortCut = 16452
    594       OnClick = MenuClick
     584      OnClick = mDisbandOrUtilizeClick
    595585    end
    596586    object mUtilize: TDpiMenuItem
    597587      ShortCut = 90
    598       OnClick = MenuClick
     588      OnClick = mDisbandOrUtilizeClick
    599589    end
    600590    object N1: TDpiMenuItem
     
    603593    object mcity: TDpiMenuItem
    604594      ShortCut = 66
    605       OnClick = MenuClick
     595      OnClick = mcityClick
    606596    end
    607597    object mPillage: TDpiMenuItem
    608598      Tag = 19
    609599      ShortCut = 16464
    610       OnClick = MenuClick
     600      OnClick = mPillageClick
    611601    end
    612602    object N5: TDpiMenuItem
     
    615605    object mhome: TDpiMenuItem
    616606      ShortCut = 72
    617       OnClick = MenuClick
     607      OnClick = mhomeClick
    618608    end
    619609    object mLoad: TDpiMenuItem
    620610      Tag = 24
    621611      ShortCut = 76
    622       OnClick = MenuClick
     612      OnClick = mLoadClick
    623613    end
    624614    object mUnload: TDpiMenuItem
    625615      Tag = 70
    626616      ShortCut = 85
    627       OnClick = MenuClick
     617      OnClick = mUnloadClick
    628618    end
    629619    object mSelectTransport: TDpiMenuItem
    630620      Tag = 73
    631621      ShortCut = 16468
    632       OnClick = MenuClick
     622      OnClick = mSelectTransportClick
    633623    end
    634624    object mGoOn: TDpiMenuItem
    635625      Tag = 13
    636626      ShortCut = 71
    637       OnClick = MenuClick
     627      OnClick = mGoOnClick
    638628    end
    639629    object mCancel: TDpiMenuItem
    640630      Tag = 1
    641631      ShortCut = 16451
    642       OnClick = MenuClick
     632      OnClick = mCancelClick
    643633    end
    644634    object mRecover: TDpiMenuItem
    645635      Tag = 69
    646636      ShortCut = 86
    647       OnClick = MenuClick
     637      OnClick = mRecoverClick
    648638    end
    649639    object mwait: TDpiMenuItem
    650640      Tag = 25
    651641      ShortCut = 87
    652       OnClick = MenuClick
     642      OnClick = mwaitClick
    653643    end
    654644    object mnoorders: TDpiMenuItem
    655645      Tag = 26
    656646      ShortCut = 32
    657       OnClick = MenuClick
     647      OnClick = mnoordersClick
    658648    end
    659649    object mstay: TDpiMenuItem
    660650      Tag = 22
    661651      ShortCut = 83
    662       OnClick = MenuClick
     652      OnClick = mstayClick
    663653    end
    664654    object mCentre: TDpiMenuItem
    665655      Tag = 12
    666656      ShortCut = 67
    667       OnClick = MenuClick
     657      OnClick = mCentreClick
    668658    end
    669659    object N13: TDpiMenuItem
     
    673663      Tag = 100
    674664      ShortCut = 46
    675       OnClick = MenuClick
     665      OnClick = mPrevUnitClick
    676666    end
    677667    object mNextUnit: TDpiMenuItem
    678668      Tag = 101
    679669      ShortCut = 45
    680       OnClick = MenuClick
     670      OnClick = mNextUnitClick
    681671    end
    682672  end
     
    688678      Tag = 9
    689679      ShortCut = 113
    690       OnClick = MenuClick
     680      OnClick = mUnitStatClick
    691681    end
    692682    object mCityStat: TDpiMenuItem
    693683      Tag = 37
    694684      ShortCut = 114
    695       OnClick = MenuClick
     685      OnClick = mCityStatClick
    696686    end
    697687    object mScienceStat: TDpiMenuItem
    698688      Tag = 38
    699689      ShortCut = 115
    700       OnClick = MenuClick
     690      OnClick = mScienceStatClick
    701691    end
    702692    object mEUnitStat: TDpiMenuItem
    703693      Tag = 50
    704694      ShortCut = 116
    705       OnClick = MenuClick
     695      OnClick = mEUnitStatClick
    706696    end
    707697    object mDiagram: TDpiMenuItem
    708698      Tag = 21
    709699      ShortCut = 117
    710       OnClick = MenuClick
     700      OnClick = mDiagramClick
    711701    end
    712702    object mWonders: TDpiMenuItem
    713703      Tag = 6
    714704      ShortCut = 118
    715       OnClick = MenuClick
     705      OnClick = mWondersClick
    716706    end
    717707    object mShips: TDpiMenuItem
    718708      Tag = 41
    719709      ShortCut = 119
    720       OnClick = MenuClick
     710      OnClick = mShipsClick
    721711    end
    722712    object N4: TDpiMenuItem
     
    726716      Tag = 55
    727717      ShortCut = 120
    728       OnClick = MenuClick
     718      OnClick = mNationsClick
    729719    end
    730720    object mEmpire: TDpiMenuItem
    731721      Tag = 3
    732722      ShortCut = 121
    733       OnClick = MenuClick
     723      OnClick = mEmpireClick
    734724    end
    735725    object mRevolution: TDpiMenuItem
    736726      Tag = 89
    737       OnClick = MenuClick
     727      OnClick = mRevolutionClick
    738728    end
    739729  end
     
    751741      Tag = 273
    752742      ShortCut = 79
    753       OnClick = MenuClick
     743      OnClick = mtransClick
    754744    end
    755745    object mAfforest: TDpiMenuItem
    756746      Tag = 301
    757747      ShortCut = 77
    758       OnClick = MenuClick
     748      OnClick = mAfforestClick
    759749    end
    760750    object mClear: TDpiMenuItem
    761751      Tag = 298
    762752      ShortCut = 73
    763       OnClick = MenuClick
     753      OnClick = mClearClick
    764754    end
    765755    object mfort: TDpiMenuItem
    766756      Tag = 276
    767757      ShortCut = 70
    768       OnClick = MenuClick
     758      OnClick = mfortClick
    769759    end
    770760    object mAirBase: TDpiMenuItem
    771761      Tag = 272
    772762      ShortCut = 65
    773       OnClick = MenuClick
     763      OnClick = mAirBaseClick
    774764    end
    775765    object mCanal: TDpiMenuItem
    776766      Tag = 279
    777767      ShortCut = 78
    778       OnClick = MenuClick
     768      OnClick = mCanalClick
    779769    end
    780770    object mmine: TDpiMenuItem
    781771      Tag = 302
    782772      ShortCut = 77
    783       OnClick = MenuClick
     773      OnClick = mmineClick
    784774    end
    785775    object mFarm: TDpiMenuItem
    786776      Tag = 300
    787777      ShortCut = 73
    788       OnClick = MenuClick
     778      OnClick = mFarmClick
    789779    end
    790780    object mirrigation: TDpiMenuItem
    791781      Tag = 299
    792782      ShortCut = 73
    793       OnClick = MenuClick
    794     end
    795     object mrr: TDpiMenuItem
     783      OnClick = mirrigationClick
     784    end
     785    object mRailRoad: TDpiMenuItem
    796786      Tag = 297
    797787      ShortCut = 82
    798       OnClick = MenuClick
     788      OnClick = mRailRoadClick
    799789    end
    800790    object mroad: TDpiMenuItem
    801791      Tag = 296
    802792      ShortCut = 82
    803       OnClick = MenuClick
     793      OnClick = mroadClick
    804794    end
    805795    object mpollution: TDpiMenuItem
    806796      Tag = 274
    807797      ShortCut = 80
    808       OnClick = MenuClick
     798      OnClick = mpollutionClick
    809799    end
    810800    object mEnhance: TDpiMenuItem
    811801      Tag = 295
    812802      ShortCut = 69
    813       OnClick = MenuClick
     803      OnClick = mEnhanceClick
    814804    end
    815805  end
  • TabularUnified branches/highdpi/LocalPlayer/Term.pas

    r405 r465  
    55
    66uses
    7   UDpiControls, {$IFDEF Windows}
     7  UDpiControls, {$IFDEF WINDOWS}
    88  Windows,
    99{$ENDIF}
    10 {$IFDEF Linux}
     10{$IFDEF UNIX}
    1111  LMessages, Messages,
    1212{$ENDIF}
     
    1414  LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, DrawDlg, Types,
    1515  Forms, Menus, ExtCtrls, dateutils, Platform, ButtonB, ButtonC, EOTButton, Area,
    16   UGraphicSet, UMiniMap, IsoEngine;
     16  GraphicSet, MiniMap, IsoEngine, Wonders, TechTree, Enhance, Nego, CityType,
     17  Diagram, CityScreen, Rates, Battle, NatStat, UnitStat, Draft, Select, MessgEx,
     18  Help;
    1719
    1820const
     
    6870    mWonders: TDpiMenuItem;
    6971    mScienceStat: TDpiMenuItem;
    70     mRR: TDpiMenuItem;
     72    mRailRoad: TDpiMenuItem;
    7173    mClear: TDpiMenuItem;
    7274    mFarm: TDpiMenuItem;
     
    181183    procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
    182184      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
     185    procedure mAfforestClick(Sender: TObject);
     186    procedure mAirBaseClick(Sender: TObject);
     187    procedure mCanalClick(Sender: TObject);
     188    procedure mCancelClick(Sender: TObject);
     189    procedure mCentreClick(Sender: TObject);
     190    procedure mcityClick(Sender: TObject);
     191    procedure mCityStatClick(Sender: TObject);
     192    procedure mCityTypesClick(Sender: TObject);
     193    procedure mClearClick(Sender: TObject);
     194    procedure mDiagramClick(Sender: TObject);
     195    procedure mEmpireClick(Sender: TObject);
     196    procedure mEnhanceClick(Sender: TObject);
     197    procedure mEnhanceDefClick(Sender: TObject);
     198    procedure mEUnitStatClick(Sender: TObject);
     199    procedure mFarmClick(Sender: TObject);
     200    procedure mfortClick(Sender: TObject);
     201    procedure mGoOnClick(Sender: TObject);
     202    procedure mHelpClick(Sender: TObject);
     203    procedure mhomeClick(Sender: TObject);
     204    procedure mirrigationClick(Sender: TObject);
     205    procedure mirrigationDrawItem(Sender: TObject; ACanvas: TDpiCanvas;
     206      ARect: TRect; AState: TOwnerDrawState);
     207    procedure mJumpClick(Sender: TObject);
     208    procedure mLoadClick(Sender: TObject);
     209    procedure mmineClick(Sender: TObject);
     210    procedure mNationsClick(Sender: TObject);
     211    procedure mNextUnitClick(Sender: TObject);
     212    procedure mnoordersClick(Sender: TObject);
     213    procedure mPillageClick(Sender: TObject);
     214    procedure mpollutionClick(Sender: TObject);
     215    procedure mPrevUnitClick(Sender: TObject);
     216    procedure mRandomMapClick(Sender: TObject);
     217    procedure mRecoverClick(Sender: TObject);
     218    procedure mResignClick(Sender: TObject);
     219    procedure mRevolutionClick(Sender: TObject);
     220    procedure mroadClick(Sender: TObject);
     221    procedure mRailRoadClick(Sender: TObject);
     222    procedure mRunClick(Sender: TObject);
     223    procedure mScienceStatClick(Sender: TObject);
     224    procedure mSelectTransportClick(Sender: TObject);
     225    procedure mShipsClick(Sender: TObject);
     226    procedure mstayClick(Sender: TObject);
     227    procedure mTechTreeClick(Sender: TObject);
     228    procedure mtransClick(Sender: TObject);
     229    procedure mUnitStatClick(Sender: TObject);
     230    procedure mUnloadClick(Sender: TObject);
     231    procedure mwaitClick(Sender: TObject);
     232    procedure mWebsiteClick(Sender: TObject);
     233    procedure mWondersClick(Sender: TObject);
    183234    procedure Timer1Timer(Sender: TObject);
    184235    procedure MapBoxMouseDown(Sender: TObject; Button: TMouseButton;
    185       Shift: TShiftState; x, y: integer);
     236      Shift: TShiftState; X, Y: Integer);
    186237    procedure EOTClick(Sender: TObject);
    187238    procedure PanelBoxMouseDown(Sender: TObject; Button: TMouseButton;
    188       Shift: TShiftState; x, y: integer);
    189     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
    190     procedure MenuClick(Sender: TObject);
     239      Shift: TShiftState; X, Y: Integer);
     240    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     241    procedure mDisbandOrUtilizeClick(Sender: TObject);
    191242    procedure FormResize(Sender: TObject);
    192243    procedure PanelBtnClick(Sender: TObject);
    193     procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
     244    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    194245    procedure Toggle(Sender: TObject);
    195246    procedure PanelBoxMouseMove(Sender: TObject; Shift: TShiftState;
    196       x, y: integer);
     247      X, Y: Integer);
    197248    procedure PanelBoxMouseUp(Sender: TObject; Button: TMouseButton;
    198       Shift: TShiftState; x, y: integer);
     249      Shift: TShiftState; X, Y: Integer);
    199250    procedure MapBoxMouseMove(Sender: TObject; Shift: TShiftState;
    200       x, y: integer);
     251      X, Y: Integer);
    201252    procedure mShowClick(Sender: TObject);
    202253    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
    203       Shift: TShiftState; x, y: integer);
    204     procedure FormMouseMove(Sender: TObject; Shift: TShiftState; x, y: integer);
     254      Shift: TShiftState; X, Y: Integer);
     255    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    205256    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
    206       Shift: TShiftState; x, y: integer);
     257      Shift: TShiftState; X, Y: Integer);
    207258    procedure FormPaint(Sender: TObject);
    208259    procedure mRepClicked(Sender: TObject);
     
    214265    procedure mNamesClick(Sender: TObject);
    215266    procedure MapBtnClick(Sender: TObject);
    216     procedure FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
     267    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    217268    procedure CreateUnitClick(Sender: TObject);
    218269    procedure mSoundOffClick(Sender: TObject);
     
    275326    NoMap: TIsoMap;
    276327    NoMapPanel: TIsoMap;
    277     function ChooseUnusedTribe: integer;
     328    // Forms
     329    FWondersDlg: TWondersDlg;
     330    FTechTreeDlg: TTechTreeDlg;
     331    FEnhanceDlg: TEnhanceDlg;
     332    FNegoDlg: TNegoDlg;
     333    FCityTypeDlg: TCityTypeDlg;
     334    FDiaDlg: TDiaDlg;
     335    FCityDlg: TCityDlg;
     336    FRatesDlg: TRatesDlg;
     337    FBattleDlg: TBattleDlg;
     338    FNatStatDlg: TNatStatDlg;
     339    FUnitStatDlg: TUnitStatDlg;
     340    FDraftDlg: TDraftDlg;
     341    FModalSelectDlg: TModalSelectDlg;
     342    FListDlg: TListDlg;
     343    FMessgExDlg: TMessgExDlg;
     344    FHelpDlg: THelpDlg;
     345    procedure ArrangeDialogs;
     346    procedure ArrangeDialog(Form: TBufferedDrawDlg);
     347    function ChooseUnusedTribe: Integer;
     348    function DoJob(j0: Integer): Integer;
     349    function GetBattleDlg: TBattleDlg;
     350    function GetCityDlg: TCityDlg;
     351    function GetCityTypeDlg: TCityTypeDlg;
     352    function GetDiaDlg: TDiaDlg;
     353    function GetDraftDlg: TDraftDlg;
     354    function GetEnhanceDlg: TEnhanceDlg;
     355    function GetHelpDlg: THelpDlg;
     356    function GetListDlg: TListDlg;
     357    function GetMessgExDlg: TMessgExDlg;
     358    function GetModalSelectDlg: TModalSelectDlg;
     359    function GetNatStatDlg: TNatStatDlg;
     360    function GetNegoDlg: TNegoDlg;
     361    function GetRatesDlg: TRatesDlg;
     362    function GetTechTreeDlg: TTechTreeDlg;
    278363    procedure GetTribeList;
     364    function GetUnitStatDlg: TUnitStatDlg;
     365    function GetWondersDlg: TWondersDlg;
    279366    procedure InitModule;
    280367    procedure DoneModule;
    281     procedure InitTurn(NewPlayer: integer);
     368    procedure InitTurn(NewPlayer: Integer);
    282369    procedure SaveMenuItemsState;
    283370    procedure ScrollBarUpdate(Sender: TObject);
     
    291378    procedure FocusNextUnit(Dir: Integer = 1);
    292379    procedure NextUnit(NearLoc: Integer; AutoTurn: Boolean);
    293     procedure Scroll(dx, dy: integer);
    294     procedure SetMapPos(Loc: integer; MapPos: TPoint);
    295     procedure Centre(Loc: integer);
    296     procedure SetTroopLoc(Loc: integer);
    297     procedure ProcessRect(x0, y0, nx, ny, Options: integer);
    298     procedure PaintLoc(Loc: integer; Radius: integer = 0);
    299     procedure PaintLoc_BeforeMove(FromLoc: integer);
    300     procedure PaintLocTemp(Loc: integer; Style: TPaintLocTempStyle = pltsNormal);
    301     procedure PaintBufferToScreen(xMap, yMap, width, height: integer);
     380    procedure Scroll(dx, dy: Integer);
     381    procedure SetMapPos(Loc: Integer; MapPos: TPoint);
     382    procedure Centre(Loc: Integer);
     383    procedure SetTroopLoc(Loc: Integer);
     384    procedure ProcessRect(x0, y0, nx, ny, Options: Integer);
     385    procedure PaintLoc(Loc: Integer; Radius: Integer = 0);
     386    procedure PaintLoc_BeforeMove(FromLoc: Integer);
     387    procedure PaintLocTemp(Loc: Integer; Style: TPaintLocTempStyle = pltsNormal);
     388    procedure PaintBufferToScreen(xMap, yMap, width, height: Integer);
    302389    procedure PaintDestination;
    303     procedure SetUnFocus(uix: integer);
    304     function MoveUnit(dx, dy: integer; Options: integer = 0): integer;
    305     procedure MoveToLoc(Loc: integer; CheckSuicide: boolean);
    306     procedure MoveOnScreen(ShowMove: TShowMove; Step0, Step1, nStep: integer;
    307       Restore: boolean = true);
    308     procedure FocusOnLoc(Loc: integer; Options: integer = 0);
    309     function EndTurn(WasSkipped: boolean = false): boolean;
     390    procedure SetUnFocus(uix: Integer);
     391    function MoveUnit(dx, dy: Integer; Options: Integer = 0): Integer;
     392    procedure MoveToLoc(Loc: Integer; CheckSuicide: Boolean);
     393    procedure MoveOnScreen(ShowMove: TShowMove; Step0, Step1, nStep: Integer;
     394      Restore: Boolean = True);
     395    procedure FocusOnLoc(Loc: Integer; Options: Integer = 0);
     396    function EndTurn(WasSkipped: Boolean = False): Boolean;
    310397    procedure EndNego;
    311     function IsPanelPixel(x, y: integer): boolean;
     398    function IsPanelPixel(X, Y: Integer): Boolean;
    312399    procedure InitPopup(Popup: TDpiPopupMenu);
    313400    procedure SetMapOptions;
     
    315402    procedure CheckTerrainBtnVisible;
    316403    procedure RememberPeaceViolation;
    317     procedure SetDebugMap(p: integer);
    318     procedure SetViewpoint(p: integer);
    319     function LocationOfScreenPixel(x, y: integer): Integer;
     404    procedure SetDebugMap(P: Integer);
     405    procedure SetViewpoint(P: Integer);
     406    function LocationOfScreenPixel(X, Y: Integer): Integer;
    320407    function GetCenterLoc: Integer;
    321408    procedure SetTileSizeCenter(TileSize: TTileSize);
    322409    procedure SetTileSize(TileSize: TTileSize; Loc: Integer; MapPos: TPoint);
    323     procedure RectInvalidate(Left, Top, Rigth, Bottom: integer);
     410    procedure RectInvalidate(Left, Top, Rigth, Bottom: Integer);
    324411    procedure ShowEnemyShipChange(ShowShipChange: TShowShipChange);
    325     procedure SmartRectInvalidate(Left, Top, Rigth, Bottom: integer);
     412    procedure SmartRectInvalidate(Left, Top, Rigth, Bottom: Integer);
    326413    procedure LoadSettings;
    327414    procedure SaveSettings;
     
    331418    procedure UpdateKeyShortcuts;
    332419    procedure SetFullScreen(Active: Boolean);
    333     procedure PaintZoomedTile(dst: TDpiBitmap; x, y, Loc: integer);
     420    procedure PaintZoomedTile(dst: TDpiBitmap; X, Y, Loc: Integer);
    334421  public
    335     UsedOffscreenWidth, UsedOffscreenHeight: integer;
     422    UsedOffscreenWidth: Integer;
     423    UsedOffscreenHeight: Integer;
    336424    Offscreen: TDpiBitmap;
    337425    OffscreenUser: TDpiForm;
    338     procedure Client(Command, NewPlayer: integer; var Data);
    339     procedure SetAIName(p: integer; Name: string);
    340     function ZoomToCity(Loc: integer; NextUnitOnClose: boolean = false;
    341       ShowEvent: integer = 0): boolean;
    342     procedure CityClosed(Activateuix: integer; StepFocus: boolean = false;
    343       SelectFocus: boolean = false);
    344     function DipCall(Command: integer): integer;
    345     function OfferCall(var Offer: TOffer): integer;
    346     procedure UpdateViews(UpdateCityScreen: boolean = false);
    347     function ContactRefused(p: integer; Item: String): boolean;
     426    procedure Client(Command, NewPlayer: Integer; var Data);
     427    procedure SetAIName(P: Integer; Name: string);
     428    function ZoomToCity(Loc: Integer; NextUnitOnClose: Boolean = False;
     429      ShowEvent: Integer = 0): Boolean;
     430    procedure CityClosed(Activateuix: Integer; StepFocus: Boolean = False;
     431      SelectFocus: Boolean = False);
     432    function DipCall(Command: Integer): Integer;
     433    function OfferCall(var Offer: TOffer): Integer;
     434    procedure UpdateViews(UpdateCityScreen: Boolean = False);
     435    function ContactRefused(P: Integer; Item: String): Boolean;
     436    // Forms
     437    property WondersDlg: TWondersDlg read GetWondersDlg;
     438    property TechTreeDlg: TTechTreeDlg read GetTechTreeDlg;
     439    property EnhanceDlg: TEnhanceDlg read GetEnhanceDlg;
     440    property NegoDlg: TNegoDlg read GetNegoDlg;
     441    property CityTypeDlg: TCityTypeDlg read GetCityTypeDlg;
     442    property DiaDlg: TDiaDlg read GetDiaDlg;
     443    property CityDlg: TCityDlg read GetCityDlg;
     444    property RatesDlg: TRatesDlg read GetRatesDlg;
     445    property BattleDlg: TBattleDlg read GetBattleDlg;
     446    property NatStatDlg: TNatStatDlg read GetNatStatDlg;
     447    property UnitStatDlg: TUnitStatDlg read GetUnitStatDlg;
     448    property DraftDlg: TDraftDlg read GetDraftDlg;
     449    property ModalSelectDlg: TModalSelectDlg read GetModalSelectDlg;
     450    property ListDlg: TListDlg read GetListDlg;
     451    property MessgExDlg: TMessgExDlg read GetMessgExDlg;
     452    property HelpDlg: THelpDlg read GetHelpDlg;
    348453  end;
    349454
     
    352457
    353458type
     459
     460  { TTribeInfo }
     461
    354462  TTribeInfo = record
    355     trix: integer;
     463    trix: Integer;
    356464    FileName: ShortString;
    357   end;
     465    function GetCommandDataSize: Byte;
     466  end;
     467
     468  { TCityNameInfo }
    358469
    359470  TCityNameInfo = record
    360     ID: integer;
     471    ID: Integer;
    361472    NewName: ShortString;
    362   end;
     473    function GetCommandDataSize: Byte;
     474  end;
     475
     476  { TModelNameInfo }
    363477
    364478  TModelNameInfo = record
    365     mix: integer;
     479    mix: Integer;
    366480    NewName: ShortString;
    367   end;
    368 
    369   TPriceSet = set of $00 .. $FF;
     481    function GetCommandDataSize: Byte;
     482  end;
     483
     484  TFormAction = (faClose, faEnable, faDisable, faUpdate, faSmartUpdateContent);
    370485
    371486const
     
    410525  usToldNoReturn = $100;
    411526  usPersistent = usStay or usGoto or usEnhance or usRecover or
    412     integer($FFFF0000);
     527    Integer($FFFF0000);
    413528
    414529  { model status flags }
     
    424539  adNexus = $803;
    425540
    426   SpecialModelPictureCode: array [0 .. nSpecialModel - 1] of integer = (10,
     541  SpecialModelPictureCode: array [0 .. nSpecialModel - 1] of Integer = (10,
    427542    11, 40, 41, 21, 30, { 50,51, } 64, 74, { 71, } 73);
    428543
     
    437552
    438553  nCityEventPriority = 16;
    439   CityEventPriority: array [0 .. nCityEventPriority - 1] of integer =
     554  CityEventPriority: array [0 .. nCityEventPriority - 1] of Integer =
    440555    (chDisorder, chImprovementLost, chUnitLost, chAllImpsMade, chProduction,
    441556    chOldWonder, chNoSettlerProd, chPopDecrease, chProductionSabotaged,
     
    504619  DestinationMarkON: Boolean;
    505620  StartRunning: Boolean;
    506   StayOnTop_Ensured: Boolean;
    507621  Supervising: Boolean;
    508622  UnusedTribeFiles: TStringList;
     
    512626  DipMem: array [0 .. nPl - 1] of TDipMem;
    513627
    514 function CityEventName(i: integer): string;
    515 function RoughCredibility(Credibility: integer): integer;
    516 
    517 function InitEnemyModel(emix: integer): boolean;
     628function CityEventName(I: Integer): string;
     629function RoughCredibility(Credibility: Integer): Integer;
     630
     631function InitEnemyModel(emix: Integer): Boolean;
    518632procedure InitAllEnemyModels;
    519 procedure InitMyModel(mix: integer; final: boolean);
    520 
    521 procedure ImpImage(ca: TDpiCanvas; x, y, iix: integer; Government: integer = -1;
    522   IsControl: boolean = false);
    523 procedure HelpOnTerrain(Loc, NewMode: integer);
     633procedure InitMyModel(Mix: Integer; Final: Boolean);
     634
     635procedure ImpImage(ca: TDpiCanvas; X, Y, iix: Integer; Government: Integer = -1;
     636  IsControl: Boolean = False);
     637procedure HelpOnTerrain(Loc: Integer; NewMode: TWindowMode);
     638function AlignUp(Value, Alignment: Integer): Integer;
    524639
    525640
     
    527642
    528643uses
    529   Directories, CityScreen, Draft, MessgEx, Select, CityType, Help,
    530   UnitStat, Log, Diagram, NatStat, Wonders, Enhance, Nego, UPixelPointer, Sound,
    531   Battle, Rates, TechTree, Registry, Global, UKeyBindings;
     644  Directories, Log, PixelPointer, Sound, Registry, Global, KeyBindings, CmdList;
    532645
    533646{$R *.lfm}
     
    536649  lxmax_xxx = 130;
    537650  LeftPanelWidth = 70;
    538   LeftPanelWidth_Editor = 46;
    539651  overlap = PanelHeight - MidPanelHeight;
    540652  yTroop = PanelHeight - 83;
    541653  xPalace = 66;
    542654  yPalace = 24; // 120;
    543   xAdvisor = 108;
    544   yAdvisor = 48;
     655{  xAdvisor = 108;
     656  yAdvisor = 48;}
    545657  xUnitText = 80;
    546   PaperShade = 3;
    547658  BlinkOnTime = 12;
    548659  BlinkOffTime = 6;
    549660  MoveTime = 300; // {time for moving a unit in ms}
    550661  WaitAfterShowMove = 32;
    551   FastScrolling = false; // causes problems with overlapping windows
     662  FastScrolling = False; // causes problems with overlapping windows
    552663
    553664  nBrushTypes = 26;
     
    587698  CurrentMoveInfo: TCurrentMoveInfo;
    588699
    589 function CityEventName(i: integer): string;
    590 begin
    591   if i = 14 then // chAllImpsMade
     700function CityEventName(I: Integer): string;
     701begin
     702  if I = 14 then // chAllImpsMade
    592703    if not Phrases2FallenBackToEnglish then
    593       result := Phrases2.Lookup('CITYEVENT_ALLIMPSMADE')
     704      Result := Phrases2.Lookup('CITYEVENT_ALLIMPSMADE')
    594705    else
    595       result := Phrases.Lookup('CITYEVENTS', 1)
     706      Result := Phrases.Lookup('CITYEVENTS', 1)
    596707  else
    597     result := Phrases.Lookup('CITYEVENTS', i);
     708    Result := Phrases.Lookup('CITYEVENTS', I);
    598709end;
    599710
     
    605716  TBuffer = array [0 .. 99999, 0 .. 2] of Integer;
    606717var
    607   Sum, Cnt, dx, dy, nx, ny, ix, iy, ir, x, y, c, ch: Integer;
     718  Sum: Int64;
     719  Cnt, dx, dy, nx, ny, ix, iy, ir, X, Y, C, ch: Integer;
    608720  xdivider, ydivider: Integer;
    609721  Resampled: ^TBuffer;
     
    611723begin
    612724  nx := BigImp.Width div xSizeBig * xSizeSmall;
    613   ny := BigImp.Height div ySizeBig * ySizeSmall;
    614   SmallImp.SetSize(nx, ny);
    615   SmallImp.Canvas.StretchDraw(Rect(0, 0, SmallImp.Width, SmallImp.Height), BigImp);
    616 
    617 {  nx := BigImp.Width div xSizeBig * xSizeSmall;
    618725  ny := BigImp.Height div ySizeBig * ySizeSmall;
    619726
     
    624731  for ix := 0 to BigImp.Width div xSizeBig - 1 do
    625732    for iy := 0 to BigImp.Height div ySizeBig - 1 do begin
    626       PixelPtr := PixelPointer(BigImp, ScaleToNative(ix * xSizeBig),
    627         ScaleToNative(cut + iy * ySizeBig));
    628       for y := 0 to ScaleToNative(ySizeBig - 2 * cut) - 1 do begin
    629         ydivider := (ScaleFromNative(y) * ySizeSmall div (ySizeBig - 2 * cut) + 1) *
    630           (ySizeBig - 2 * cut) - ScaleFromNative(y) * ySizeSmall;
     733      PixelPtr := TPixelPointer.Create(BigImp, ScaleToNative(ix * xSizeBig),
     734        ScaleToNative(Cut + iy * ySizeBig));
     735      for Y := 0 to ScaleToNative(ySizeBig - 2 * Cut) - 1 do begin
     736        ydivider := (ScaleFromNative(Y) * ySizeSmall div (ySizeBig - 2 * Cut) + 1) *
     737          (ySizeBig - 2 * Cut) - ScaleFromNative(Y) * ySizeSmall;
    631738        if ydivider > ySizeSmall then
    632739          ydivider := ySizeSmall;
    633         for x := 0 to ScaleToNative(xSizeBig) - 1 do begin
    634           ir := ix * xSizeSmall + iy * nx * ySizeSmall + ScaleFromNative(x) *
    635             xSizeSmall div xSizeBig + ScaleFromNative(y) *
    636             ySizeSmall div (ySizeBig - 2 * cut) * nx;
    637           xdivider := (ScaleFromNative(x) * xSizeSmall div xSizeBig + 1) *
    638             xSizeBig - ScaleFromNative(x) * xSizeSmall;
     740        for X := 0 to ScaleToNative(xSizeBig) - 1 do begin
     741          ir := ix * xSizeSmall + iy * nx * ySizeSmall + ScaleFromNative(X) *
     742            xSizeSmall div xSizeBig + ScaleFromNative(Y) *
     743            ySizeSmall div (ySizeBig - 2 * Cut) * nx;
     744          xdivider := (ScaleFromNative(X) * xSizeSmall div xSizeBig + 1) *
     745            xSizeBig - ScaleFromNative(X) * xSizeSmall;
    639746          if xdivider > xSizeSmall then
    640747            xdivider := xSizeSmall;
    641748          for ch := 0 to 2 do begin
    642             c := PixelPtr.Pixel^.Planes[ch];
    643             Inc(Resampled[ir, ch], c * xdivider * ydivider);
     749            C := PixelPtr.Pixel^.Planes[ch];
     750            Inc(Resampled[ir, ch], C * xdivider * ydivider);
    644751            if xdivider < xSizeSmall then
    645               Inc(Resampled[ir + 1, ch], c * (xSizeSmall - xdivider) *
     752              Inc(Resampled[ir + 1, ch], C * (xSizeSmall - xdivider) *
    646753                ydivider);
    647754            if ydivider < ySizeSmall then
    648755              Inc(Resampled[ir + nx, ch],
    649                 c * xdivider * (ySizeSmall - ydivider));
     756                C * xdivider * (ySizeSmall - ydivider));
    650757            if (xdivider < xSizeSmall) and (ydivider < ySizeSmall) then
    651               Inc(Resampled[ir + nx + 1, ch], c * (xSizeSmall - xdivider) *
     758              Inc(Resampled[ir + nx + 1, ch], C * (xSizeSmall - xdivider) *
    652759                (ySizeSmall - ydivider));
    653760          end;
     
    662769  SmallImp.SetSize(nx, ny);
    663770  SmallImp.BeginUpdate;
    664   PixelPtr := PixelPointer(SmallImp);
    665   for y := 0 to ScaleToNative(ny) - 1 do begin
    666     for x := 0 to ScaleToNative(nx) - 1 do begin
     771  PixelPtr := TPixelPointer.Create(SmallImp);
     772  for Y := 0 to ScaleToNative(ny) - 1 do begin
     773    for X := 0 to ScaleToNative(nx) - 1 do begin
    667774      for ch := 0 to 2 do begin
    668775        Sum := 0;
    669776        Cnt := 0;
    670777        for dy := -1 to 1 do
    671           if ((dy >= 0) or (ScaleFromNative(y) mod ySizeSmall > 0)) and
    672             ((dy <= 0) or (ScaleFromNative(y) mod ySizeSmall < ySizeSmall - 1)) then
     778          if ((dy >= 0) or (ScaleFromNative(Y) mod ySizeSmall > 0)) and
     779            ((dy <= 0) or (ScaleFromNative(Y) mod ySizeSmall < ySizeSmall - 1)) then
    673780            for dx := -1 to 1 do
    674               if ((dx >= 0) or (ScaleFromNative(x) mod xSizeSmall > 0)) and
    675                 ((dx <= 0) or (ScaleFromNative(x) mod xSizeSmall < xSizeSmall - 1)) then
     781              if ((dx >= 0) or (ScaleFromNative(X) mod xSizeSmall > 0)) and
     782                ((dx <= 0) or (ScaleFromNative(X) mod xSizeSmall < xSizeSmall - 1)) then
    676783              begin
    677                 Inc(Sum, Resampled[ScaleFromNative(x) + dx + nx * (ScaleFromNative(y) + dy), ch]);
     784                Inc(Sum, Resampled[ScaleFromNative(X) + dx + nx * (ScaleFromNative(Y) + dy), ch]);
    678785                Inc(Cnt);
    679786              end;
    680         Sum := ((Cnt * Sharpen + 800) * Resampled[ScaleFromNative(x) + nx * ScaleFromNative(y), ch] - Sum *
    681           Sharpen) div (800 * xSizeBig * (ySizeBig - 2 * cut));
     787        Sum := ((Cnt * Sharpen + 800) * Resampled[ScaleFromNative(X) + nx * ScaleFromNative(Y), ch] - Sum *
     788          Sharpen) div (800 * xSizeBig * (ySizeBig - 2 * Cut));
    682789        if Sum < 0 then Sum := 0;
    683790        if Sum > 255 then Sum := 255;
     
    690797  SmallImp.EndUpdate;
    691798  FreeMem(Resampled);
    692   }
    693 end;
    694 
    695 procedure ImpImage(ca: TDpiCanvas; x, y, iix: integer; Government: integer;
    696   IsControl: boolean);
     799end;
     800
     801procedure ImpImage(ca: TDpiCanvas; X, Y, iix: Integer; Government: Integer;
     802  IsControl: Boolean);
    697803begin
    698804  if Government < 0 then
     
    700806  if (iix = imPalace) and (Government <> gAnarchy) then
    701807    iix := Government - 8;
    702   FrameImage(ca, BigImp, x, y, xSizeBig, ySizeBig, (iix + SystemIconLines * 7)
     808  FrameImage(ca, BigImp, X, Y, xSizeBig, ySizeBig, (iix + SystemIconLines * 7)
    703809    mod 7 * xSizeBig, (iix + SystemIconLines * 7) div 7 * ySizeBig, IsControl);
    704810end;
    705811
    706 procedure HelpOnTerrain(Loc, NewMode: integer);
     812procedure HelpOnTerrain(Loc: Integer; NewMode: TWindowMode);
    707813begin
    708814  if MyMap[Loc] and fDeadLands <> 0 then
    709     HelpDlg.ShowNewContent(NewMode, hkTer, 3 * 12)
     815    MainScreen.HelpDlg.ShowNewContent(NewMode, hkTer, 3 * 12)
    710816  else if (MyMap[Loc] and fTerrain = fForest) and IsJungle(Loc div G.lx) then
    711     HelpDlg.ShowNewContent(NewMode, hkTer,
     817    MainScreen.HelpDlg.ShowNewContent(NewMode, hkTer,
    712818      fJungle + (MyMap[Loc] shr 5 and 3) * 12)
    713819  else
    714     HelpDlg.ShowNewContent(NewMode, hkTer, MyMap[Loc] and fTerrain +
     820    MainScreen.HelpDlg.ShowNewContent(NewMode, hkTer, MyMap[Loc] and fTerrain +
    715821      (MyMap[Loc] shr 5 and 3) * 12);
    716822end;
    717823
     824function AlignUp(Value, Alignment: Integer): Integer;
     825begin
     826  Result := Value or (Alignment - 1);
     827end;
     828
    718829{ *** tribe management procedures *** }
    719830
    720 function RoughCredibility(Credibility: integer): integer;
     831function RoughCredibility(Credibility: Integer): Integer;
    721832begin
    722833  case Credibility of
    723834    0 .. 69:
    724       result := 0;
     835      Result := 0;
    725836    70 .. 89:
    726       result := 1;
     837      Result := 1;
    727838    90 .. 99:
    728       result := 2;
     839      Result := 2;
    729840    100:
    730       result := 3
    731   end;
    732 end;
    733 
    734 procedure ChooseModelPicture(p, mix, code, Hash, Turn: integer;
    735   ForceNew, final: boolean);
     841      Result := 3;
     842  end;
     843end;
     844
     845procedure ChooseModelPicture(P, mix, Code, Hash, Turn: Integer;
     846  ForceNew, final: Boolean);
    736847var
    737   i: integer;
     848  I: Integer;
    738849  Picture: TModelPictureInfo;
    739   IsNew: boolean;
    740 begin
    741   Picture.trix := p;
     850  IsNew: Boolean;
     851begin
     852  Picture.trix := P;
    742853  Picture.mix := mix;
    743   if code = 74 then
     854  if Code = 74 then
    744855  begin // use correct pictures for slaves
    745     if Tribe[p].mixSlaves < 0 then
    746       if not TribeOriginal[p] then
    747         Tribe[p].mixSlaves := mix
     856    if Tribe[P].mixSlaves < 0 then
     857      if not TribeOriginal[P] then
     858        Tribe[P].mixSlaves := mix
    748859      else
    749860      begin
    750         i := mix + p shl 16;
    751         Server(cSetSlaveIndex, 0, 0, i);
     861        I := mix + P shl 16;
     862        Server(cSetSlaveIndex, 0, 0, I);
    752863      end;
    753864    if ToldSlavery = 1 then
     
    757868    Picture.Hash := 0;
    758869    Picture.GrName := 'StdUnits.png';
    759     IsNew := true;
     870    IsNew := True;
    760871  end
    761872  else
    762873  begin
    763874    Picture.Hash := Hash;
    764     IsNew := Tribe[p].ChooseModelPicture(Picture, code, Turn, ForceNew);
     875    IsNew := Tribe[P].ChooseModelPicture(Picture, Code, Turn, ForceNew);
    765876  end;
    766877  if final then
    767     if not TribeOriginal[p] then
    768       Tribe[p].SetModelPicture(Picture, IsNew)
     878    if not TribeOriginal[P] then
     879      Tribe[P].SetModelPicture(Picture, IsNew)
    769880    else if IsNew then
    770       Server(cSetNewModelPicture + (Length(Picture.GrName) + 1 + 16 + 3) div 4,
     881      Server(CommandWithData(cSetNewModelPicture, Picture.GetCommandDataSize),
    771882        0, 0, Picture)
    772883    else
    773       Server(cSetModelPicture + (Length(Picture.GrName) + 1 + 16 + 3) div 4, 0,
    774         0, Picture)
     884      Server(CommandWithData(cSetModelPicture, Picture.GetCommandDataSize),
     885        0, 0, Picture)
    775886  else
    776     with Tribe[p].ModelPicture[mix] do
     887    with Tribe[P].ModelPicture[mix] do
    777888    begin
    778889      HGr := LoadGraphicSet(Picture.GrName);
     
    781892end;
    782893
    783 function InitEnemyModel(emix: integer): boolean;
     894function InitEnemyModel(emix: Integer): Boolean;
    784895begin
    785896  if GameMode = cMovie then
    786897  begin
    787     result := false;
    788     exit
     898    Result := False;
     899    Exit;
    789900  end;
    790901  with MyRO.EnemyModel[emix] do
    791902    ChooseModelPicture(Owner, mix, ModelCode(MyRO.EnemyModel[emix]),
    792       ModelHash(MyRO.EnemyModel[emix]), MyRO.Turn, false, true);
    793   result := true;
     903      ModelHash(MyRO.EnemyModel[emix]), MyRO.Turn, False, True);
     904  Result := True;
    794905end;
    795906
    796907procedure InitAllEnemyModels;
    797908var
    798   emix: integer;
     909  emix: Integer;
    799910begin
    800911  for emix := 0 to MyRO.nEnemyModel - 1 do
     
    804915end;
    805916
    806 procedure InitMyModel(mix: integer; final: boolean);
     917procedure InitMyModel(Mix: Integer; Final: Boolean);
    807918var
    808919  mi: TModelInfo;
    809920begin
    810921  if (GameMode = cMovie) and (MyModel[mix].Kind < $08) then
    811     exit;
     922    Exit;
    812923  // don't exit for special units because cSetModelPicture comes after TellNewModels
    813   MakeModelInfo(me, mix, MyModel[mix], mi);
    814   ChooseModelPicture(me, mix, ModelCode(mi), ModelHash(mi), MyRO.Turn,
    815     false, final);
    816 end;
    817 
    818 function AttackSound(code: integer): string;
    819 begin
    820   result := 'ATTACK_' + char(48 + code div 100 mod 10) +
    821     char(48 + code div 10 mod 10) + char(48 + code mod 10);
    822 end;
    823 
    824 procedure CheckToldNoReturn(uix: integer);
     924  MakeModelInfo(Me, Mix, MyModel[mix], mi);
     925  ChooseModelPicture(Me, Mix, ModelCode(mi), ModelHash(mi), MyRO.Turn,
     926    False, Final);
     927end;
     928
     929function AttackSound(Code: Integer): string;
     930begin
     931  Result := 'ATTACK_' + char(48 + Code div 100 mod 10) +
     932    char(48 + Code div 10 mod 10) + char(48 + Code mod 10);
     933end;
     934
     935procedure CheckToldNoReturn(uix: Integer);
    825936// check whether aircraft survived low-fuel warning
    826937begin
    827   assert(not supervising);
     938  Assert(not Supervising);
    828939  with MyUn[uix] do
    829940    if (Status and usToldNoReturn <> 0) and
     
    833944end;
    834945
    835 function CreateTribe(p: integer; FileName: string; Original: boolean): boolean;
     946function CreateTribe(P: Integer; FileName: string; Original: Boolean): Boolean;
    836947begin
    837948  FileName := LocalizedFilePath('Tribes' + DirectorySeparator + FileName +
     
    843954  end;
    844955
    845   TribeOriginal[p] := Original;
    846   Tribe[p] := TTribe.Create(FileName);
    847   with Tribe[p] do
     956  TribeOriginal[P] := Original;
     957  Tribe[P] := TTribe.Create(FileName);
     958  with Tribe[P] do
    848959  begin
    849960    if (GameMode = cNewGame) or not Original then
    850961    begin
    851       Term.ChooseModelPicture(p, 0, 010, 1, 0, true, true);
    852       Term.ChooseModelPicture(p, 1, 040, 1, 0, true, true);
    853       Term.ChooseModelPicture(p, 2, 041, 1, 0, true, true);
    854       Term.ChooseModelPicture(p, -1, 017, 1, 0, true, true);
    855     end;
    856     DipMem[p].pContact := -1;
    857   end;
    858   result := true;
     962      Term.ChooseModelPicture(P, 0, 010, 1, 0, True, True);
     963      Term.ChooseModelPicture(P, 1, 040, 1, 0, True, True);
     964      Term.ChooseModelPicture(P, 2, 041, 1, 0, True, True);
     965      Term.ChooseModelPicture(P, -1, 017, 1, 0, True, True);
     966    end;
     967    DipMem[P].pContact := -1;
     968  end;
     969  Result := True;
    859970end;
    860971
    861972procedure TellNewContacts;
    862973var
    863   p1: integer;
    864 begin
    865   if not supervising then
     974  p1: Integer;
     975begin
     976  if not Supervising then
    866977    for p1 := 0 to nPl - 1 do
    867       if (p1 <> me) and (1 shl p1 and MyData.ToldContact = 0) and
     978      if (p1 <> Me) and (1 shl p1 and MyData.ToldContact = 0) and
    868979        (1 shl p1 and MyRO.Alive <> 0) and (MyRO.Treaty[p1] > trNoContact) then
    869980      begin
    870981        TribeMessage(p1, Tribe[p1].TPhrase('FRNEWNATION'), '');
    871982        MyData.ToldContact := MyData.ToldContact or (1 shl p1);
    872       end
     983      end;
    873984end;
    874985
    875986procedure TellNewModels;
    876987var
    877   mix: integer;
     988  mix: Integer;
    878989  ModelNameInfo: TModelNameInfo;
    879990begin
    880   if supervising then
    881     exit;
    882   with Tribe[me] do
     991  if Supervising then
     992    Exit;
     993  with Tribe[Me] do
    883994    while MyData.ToldModels < MyRO.nModel do
    884995    begin { new Unit class available }
     
    8911002      end;
    8921003      if not Assigned(ModelPicture[MyData.ToldModels].HGr) then
    893         InitMyModel(MyData.ToldModels, true);
     1004        InitMyModel(MyData.ToldModels, True);
    8941005      { only run if no researched model }
    895       with MessgExDlg do
     1006      with MainScreen.MessgExDlg do
    8961007      begin
    8971008        { MakeModelInfo(me,MyData.ToldModels,MyModel[MyData.ToldModels],mi);
     
    9191030          ModelNameInfo.mix := MyData.ToldModels;
    9201031          ModelNameInfo.NewName := EInput.Text;
    921           Server(cSetModelName + (Length(ModelNameInfo.NewName) + 1 + 4 + 3)
    922             div 4, me, 0, ModelNameInfo);
     1032          if ModelNameInfo.GetCommandDataSize > CommandDataMaxSize then
     1033            Delete(ModelNameInfo.NewName, Length(ModelNameInfo.NewName) -
     1034             (ModelNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt);
     1035          Server(CommandWithData(cSetModelName, ModelNameInfo.GetCommandDataSize),
     1036            Me, 0, ModelNameInfo);
    9231037        end;
    9241038      end;
     
    9291043            MyModel[mix].Status := MyModel[mix].Status or msObsolete;
    9301044      end;
    931       inc(MyData.ToldModels);
    932     end;
    933 end;
    934 
    935 procedure TMainScreen.PaintZoomedTile(dst: TDpiBitmap; x, y, Loc: integer);
    936 
    937   procedure TSprite(xDst, yDst, xSrc, ySrc: integer);
     1045      Inc(MyData.ToldModels);
     1046    end;
     1047end;
     1048
     1049{ TTribeInfo }
     1050
     1051function TTribeInfo.GetCommandDataSize: Byte;
     1052begin
     1053  Result := SizeOf(trix) + 1 + Length(FileName)
     1054end;
     1055
     1056{ TModelNameInfo }
     1057
     1058function TModelNameInfo.GetCommandDataSize: Byte;
     1059begin
     1060  Result := SizeOf(mix) + 1 + Length(NewName);
     1061end;
     1062
     1063{ TCityNameInfo }
     1064
     1065function TCityNameInfo.GetCommandDataSize: Byte;
     1066begin
     1067  Result := SizeOf(ID) + 1 + Length(NewName);
     1068end;
     1069
     1070procedure TMainScreen.PaintZoomedTile(dst: TDpiBitmap; X, Y, Loc: Integer);
     1071
     1072  procedure TSprite(xDst, yDst, xSrc, ySrc: Integer);
    9381073  begin
    9391074    with NoMapPanel do
    940       Sprite(dst, HGrTerrain, x + xDst, y + yDst, xxt * 2, yyt * 3,
     1075      Sprite(dst, HGrTerrain, X + xDst, Y + yDst, xxt * 2, yyt * 3,
    9411076        1 + xSrc * (xxt * 2 + 1), 1 + ySrc * (yyt * 3 + 1));
    9421077  end;
    9431078
    944   procedure TSprite4(xSrc, ySrc: integer);
     1079  procedure TSprite4(xSrc, ySrc: Integer);
    9451080  begin
    9461081    with NoMapPanel do begin
    947       Sprite(dst, HGrTerrain, x + xxt, y + yyt + 2, xxt * 2, yyt * 2 - 2,
     1082      Sprite(dst, HGrTerrain, X + xxt, Y + yyt + 2, xxt * 2, yyt * 2 - 2,
    9481083        1 + xSrc * (xxt * 2 + 1), 3 + yyt + ySrc * (yyt * 3 + 1));
    949       Sprite(dst, HGrTerrain, x + 4, y + 2 * yyt, xxt * 2 - 4, yyt * 2,
     1084      Sprite(dst, HGrTerrain, X + 4, Y + 2 * yyt, xxt * 2 - 4, yyt * 2,
    9501085        5 + xSrc * (xxt * 2 + 1), 1 + yyt + ySrc * (yyt * 3 + 1));
    951       Sprite(dst, HGrTerrain, x + xxt * 2, y + 2 * yyt, xxt * 2 - 4, yyt * 2,
     1086      Sprite(dst, HGrTerrain, X + xxt * 2, Y + 2 * yyt, xxt * 2 - 4, yyt * 2,
    9521087        1 + xSrc * (xxt * 2 + 1), 1 + yyt + ySrc * (yyt * 3 + 1));
    953       Sprite(dst, HGrTerrain, x + xxt, y + yyt * 3, xxt * 2, yyt * 2 - 2,
     1088      Sprite(dst, HGrTerrain, X + xxt, Y + yyt * 3, xxt * 2, yyt * 2 - 2,
    9541089        1 + xSrc * (xxt * 2 + 1), 1 + yyt + ySrc * (yyt * 3 + 1));
    9551090    end;
     
    9571092
    9581093var
    959   cix, ySrc, Tile: integer;
     1094  cix, ySrc, Tile: Integer;
    9601095begin
    9611096  with NoMapPanel do begin
     
    9711106        cix := MyRO.nCity - 1;
    9721107        while (cix >= 0) and (MyCity[cix].Loc <> Loc) do
    973           dec(cix);
    974         assert(cix >= 0);
     1108          Dec(cix);
     1109        Assert(cix >= 0);
    9751110        if MyCity[cix].Built[imSupermarket] > 0 then
    9761111          Tile := Tile or tiFarm
     
    10631198end;
    10641199
    1065 function ChooseResearch: boolean;
     1200function ChooseResearch: Boolean;
    10661201var
    1067   ChosenResearch: integer;
     1202  ChosenResearch: Integer;
    10681203begin
    10691204  if (MyData.FarTech <> adNone) and (MyRO.Tech[MyData.FarTech] >= tsApplicable)
     
    10731208    { research complete -- select new }
    10741209    repeat
    1075       ModalSelectDlg.ShowNewContent(wmModal, kAdvance);
    1076       if ModalSelectDlg.result < 0 then
     1210      MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kAdvance);
     1211      if MainScreen.ModalSelectDlg.Result < 0 then
    10771212      begin
    1078         result := false;
    1079         exit;
    1080       end;
    1081       ChosenResearch := ModalSelectDlg.result;
     1213        Result := False;
     1214        Exit;
     1215      end;
     1216      ChosenResearch := MainScreen.ModalSelectDlg.Result;
    10821217      if ChosenResearch = adMilitary then
    10831218      begin
    1084         DraftDlg.ShowNewContent(wmModal);
    1085         if DraftDlg.ModalResult <> mrOK then
    1086           Tribe[me].ModelPicture[MyRO.nModel].HGr := nil
    1087       end;
    1088     until (ChosenResearch <> adMilitary) or (DraftDlg.ModalResult = mrOK);
     1219        MainScreen.DraftDlg.ShowNewContent(wmModal);
     1220        if MainScreen.DraftDlg.ModalResult <> mrOK then
     1221          Tribe[Me].ModelPicture[MyRO.nModel].HGr := nil;
     1222      end;
     1223    until (ChosenResearch <> adMilitary) or (MainScreen.DraftDlg.ModalResult = mrOK);
    10891224
    10901225    if ChosenResearch = adMilitary then
    1091       InitMyModel(MyRO.nModel, true)
     1226      InitMyModel(MyRO.nModel, True)
    10921227    else if ChosenResearch = adFar then
    10931228    begin
    1094       ModalSelectDlg.ShowNewContent(wmModal, kFarAdvance);
    1095       if ModalSelectDlg.result >= 0 then
    1096         if (ModalSelectDlg.result = adNone) or
    1097           (Server(sSetResearch - sExecute, me, ModalSelectDlg.result, nil^) <
     1229      MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kFarAdvance);
     1230      if MainScreen.ModalSelectDlg.Result >= 0 then
     1231        if (MainScreen.ModalSelectDlg.Result = adNone) or
     1232          (Server(sSetResearch - sExecute, Me, MainScreen.ModalSelectDlg.Result, nil^) <
    10981233          rExecuted) then
    1099           MyData.FarTech := ModalSelectDlg.result
     1234          MyData.FarTech := MainScreen.ModalSelectDlg.Result
    11001235        else
    11011236        begin
    1102           ChosenResearch := ModalSelectDlg.result;
     1237          ChosenResearch := MainScreen.ModalSelectDlg.Result;
    11031238          // can be researched immediately
    1104           MyData.FarTech := adNone
     1239          MyData.FarTech := adNone;
    11051240        end;
    11061241    end;
     
    11091244    MyData.FarTech := adNexus
    11101245  else
    1111     Server(sSetResearch, me, ChosenResearch, nil^);
    1112   ListDlg.TechChange;
    1113   result := true;
     1246    Server(sSetResearch, Me, ChosenResearch, nil^);
     1247  MainScreen.ListDlg.TechChange;
     1248  Result := True;
     1249end;
     1250
     1251procedure ApplyToVisibleForms(FormAction: TFormAction);
     1252var
     1253  I: Integer;
     1254  Form: TDpiForm;
     1255begin
     1256  for I := 0 to DpiScreen.FormCount - 1 do begin
     1257    Form := DpiScreen.Forms[I];
     1258    if Form.Visible and (Form is TBufferedDrawDlg) then begin
     1259      case FormAction of
     1260        faClose: Form.Close;
     1261        faEnable: Form.Enabled := True;
     1262        faDisable: Form.Enabled := False;
     1263        faUpdate: begin
     1264          if @Form.OnShow <> nil then Form.OnShow(nil);
     1265            Form.Invalidate;
     1266            Form.Update;
     1267        end;
     1268        faSmartUpdateContent: TBufferedDrawDlg(Form).SmartUpdateContent(False);
     1269      end;
     1270    end;
     1271  end;
    11141272end;
    11151273
    11161274(* ** client function handling ** *)
    11171275
    1118 function TMainScreen.DipCall(Command: integer): integer;
     1276function TMainScreen.DipCall(Command: Integer): Integer;
    11191277var
    1120   i: integer;
    1121   IsTreatyDeal: boolean;
    1122 begin
    1123   result := Server(Command, me, 0, nil^);
    1124   if result >= rExecuted then
     1278  I: Integer;
     1279  IsTreatyDeal: Boolean;
     1280begin
     1281  Result := Server(Command, Me, 0, nil^);
     1282  if Result >= rExecuted then
    11251283  begin
    11261284    if Command and $FF0F = scContact then
    11271285    begin
    1128       DipMem[me].pContact := Command shr 4 and $F;
     1286      DipMem[Me].pContact := Command shr 4 and $F;
    11291287      NegoDlg.Initiate;
    1130       DipMem[me].DeliveredPrices := [];
    1131       DipMem[me].ReceivedPrices := [];
    1132     end;
    1133 
    1134     DipMem[me].SentCommand := Command;
    1135     DipMem[me].FormerTreaty := MyRO.Treaty[DipMem[me].pContact];
     1288      DipMem[Me].DeliveredPrices := [];
     1289      DipMem[Me].ReceivedPrices := [];
     1290    end;
     1291
     1292    DipMem[Me].SentCommand := Command;
     1293    DipMem[Me].FormerTreaty := MyRO.Treaty[DipMem[Me].pContact];
    11361294    if Command = scDipCancelTreaty then
    11371295      Play('CANCELTREATY')
    11381296    else if Command = scDipAccept then
    11391297    begin // remember delivered and received prices
    1140       for i := 0 to ReceivedOffer.nDeliver - 1 do
    1141         include(DipMem[me].ReceivedPrices, ReceivedOffer.Price[i] shr 24);
    1142       for i := 0 to ReceivedOffer.nCost - 1 do
    1143         include(DipMem[me].DeliveredPrices,
    1144           ReceivedOffer.Price[ReceivedOffer.nDeliver + i] shr 24);
    1145       IsTreatyDeal := false;
    1146       for i := 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do
    1147         if ReceivedOffer.Price[i] and opMask = opTreaty then
    1148           IsTreatyDeal := true;
     1298      for I := 0 to ReceivedOffer.nDeliver - 1 do
     1299        Include(DipMem[Me].ReceivedPrices, ReceivedOffer.Price[I] shr 24);
     1300      for I := 0 to ReceivedOffer.nCost - 1 do
     1301        Include(DipMem[Me].DeliveredPrices,
     1302          ReceivedOffer.Price[ReceivedOffer.nDeliver + I] shr 24);
     1303      IsTreatyDeal := False;
     1304      for I := 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do
     1305        if ReceivedOffer.Price[I] and opMask = opTreaty then
     1306          IsTreatyDeal := True;
    11491307      if IsTreatyDeal then
    11501308        Play('NEWTREATY')
     
    11531311    end;
    11541312    CityDlg.CloseAction := None;
    1155     if G.RO[DipMem[me].pContact] <> nil then
     1313    if G.RO[DipMem[Me].pContact] <> nil then
    11561314    begin // close windows for next player
    1157       for i := 0 to DpiScreen.FormCount - 1 do
    1158         if DpiScreen.Forms[i].Visible and (DpiScreen.Forms[i] is TBufferedDrawDlg)
    1159         then
    1160           DpiScreen.Forms[i].Close;
     1315      ApplyToVisibleForms(faClose);
    11611316    end
    11621317    else
     
    11701325end;
    11711326
    1172 function TMainScreen.OfferCall(var Offer: TOffer): integer;
    1173 var
    1174   i: integer;
    1175 begin
    1176   result := Server(scDipOffer, me, 0, Offer);
    1177   if result >= rExecuted then
    1178   begin
    1179     DipMem[me].SentCommand := scDipOffer;
    1180     DipMem[me].FormerTreaty := MyRO.Treaty[DipMem[me].pContact];
    1181     DipMem[me].SentOffer := Offer;
     1327function TMainScreen.OfferCall(var Offer: TOffer): Integer;
     1328begin
     1329  Result := Server(scDipOffer, Me, 0, Offer);
     1330  if Result >= rExecuted then
     1331  begin
     1332    DipMem[Me].SentCommand := scDipOffer;
     1333    DipMem[Me].FormerTreaty := MyRO.Treaty[DipMem[Me].pContact];
     1334    DipMem[Me].SentOffer := Offer;
    11821335    CityDlg.CloseAction := None;
    1183     if G.RO[DipMem[me].pContact] <> nil then
     1336    if G.RO[DipMem[Me].pContact] <> nil then
    11841337    begin // close windows for next player
    1185       for i := 0 to DpiScreen.FormCount - 1 do
    1186         if DpiScreen.Forms[i].Visible and (DpiScreen.Forms[i] is TBufferedDrawDlg)
    1187         then
    1188           DpiScreen.Forms[i].Close;
     1338      ApplyToVisibleForms(faClose);
    11891339    end
    11901340    else
     
    11981348end;
    11991349
    1200 procedure TMainScreen.SetUnFocus(uix: integer);
     1350procedure TMainScreen.SetUnFocus(uix: Integer);
    12011351var
    1202   Loc0: integer;
    1203 begin
    1204   assert(not((uix >= 0) and supervising));
     1352  Loc0: Integer;
     1353begin
     1354  Assert(not((uix >= 0) and Supervising));
    12051355  if uix <> UnFocus then
    12061356  begin
    1207     DestinationMarkON := false;
     1357    DestinationMarkON := False;
    12081358    PaintDestination;
    12091359    if uix >= 0 then
    12101360      UnStartLoc := MyUn[uix].Loc;
    1211     BlinkON := false;
     1361    BlinkON := False;
    12121362    BlinkTime := -1;
    12131363    if UnFocus >= 0 then
     
    12291379procedure TMainScreen.CheckTerrainBtnVisible;
    12301380var
    1231   Tile: integer;
     1381  Tile: Integer;
    12321382  mox: ^TModel;
    12331383begin
     
    12411391  end
    12421392  else
    1243     TerrainBtn.Visible := false;
     1393    TerrainBtn.Visible := False;
    12441394end;
    12451395
     
    12491399  begin
    12501400    MovieSpeed1Btn.Down := MovieSpeed = 1;
    1251     MovieSpeed1Btn.Visible := true;
     1401    MovieSpeed1Btn.Visible := True;
    12521402    MovieSpeed2Btn.Down := MovieSpeed = 2;
    1253     MovieSpeed2Btn.Visible := true;
     1403    MovieSpeed2Btn.Visible := True;
    12541404    MovieSpeed3Btn.Down := MovieSpeed = 3;
    1255     MovieSpeed3Btn.Visible := true;
     1405    MovieSpeed3Btn.Visible := True;
    12561406    MovieSpeed4Btn.Down := MovieSpeed = 4;
    1257     MovieSpeed4Btn.Visible := true;
     1407    MovieSpeed4Btn.Visible := True;
    12581408  end
    12591409  else
    12601410  begin
    1261     MovieSpeed1Btn.Visible := false;
    1262     MovieSpeed2Btn.Visible := false;
    1263     MovieSpeed3Btn.Visible := false;
    1264     MovieSpeed4Btn.Visible := false;
     1411    MovieSpeed1Btn.Visible := False;
     1412    MovieSpeed2Btn.Visible := False;
     1413    MovieSpeed3Btn.Visible := False;
     1414    MovieSpeed4Btn.Visible := False;
    12651415  end;
    12661416end;
     
    12761426end;
    12771427
    1278 procedure TMainScreen.UpdateViews(UpdateCityScreen: boolean);
     1428procedure TMainScreen.UpdateViews(UpdateCityScreen: Boolean);
    12791429begin
    12801430  SumCities(TaxSum, ScienceSum);
     
    12861436end;
    12871437
    1288 procedure TMainScreen.SetAIName(p: integer; Name: string);
     1438procedure TMainScreen.SetAIName(P: Integer; Name: string);
    12891439begin
    12901440  if Name = '' then
    12911441  begin
    1292     if AILogo[p] <> nil then
     1442    if AILogo[P] <> nil then
    12931443    begin
    1294       FreeAndNil(AILogo[p]);
     1444      FreeAndNil(AILogo[P]);
    12951445    end;
    12961446  end
    12971447  else
    12981448  begin
    1299     if AILogo[p] = nil then
    1300       AILogo[p] := TDpiBitmap.Create;
    1301     if not LoadGraphicFile(AILogo[p], HomeDir + Name + '.png', [gfNoError]) then
     1449    if AILogo[P] = nil then
     1450      AILogo[P] := TDpiBitmap.Create;
     1451    if not LoadGraphicFile(AILogo[P], HomeDir + Name + '.png', [gfNoError]) then
    13021452    begin
    1303       FreeAndNil(AILogo[p]);
    1304     end;
    1305   end;
    1306 end;
    1307 
    1308 function TMainScreen.ContactRefused(p: integer; Item: String): boolean;
     1453      FreeAndNil(AILogo[P]);
     1454    end;
     1455  end;
     1456end;
     1457
     1458function TMainScreen.ContactRefused(P: Integer; Item: String): Boolean;
    13091459// return whether treaty was cancelled
    13101460var
    1311   s: string;
    1312 begin
    1313   assert(MyRO.Treaty[p] >= trPeace);
    1314   s := Tribe[p].TPhrase(Item);
    1315   if MyRO.Turn < MyRO.LastCancelTreaty[p] + CancelTreatyTurns then
    1316   begin
    1317     SimpleMessage(s);
    1318     result := false;
     1461  S: string;
     1462begin
     1463  Assert(MyRO.Treaty[P] >= trPeace);
     1464  S := Tribe[P].TPhrase(Item);
     1465  if MyRO.Turn < MyRO.LastCancelTreaty[P] + CancelTreatyTurns then
     1466  begin
     1467    SimpleMessage(S);
     1468    Result := False;
    13191469  end
    13201470  else
    13211471  begin
    1322     case MyRO.Treaty[p] of
     1472    case MyRO.Treaty[P] of
    13231473      trPeace:
    1324         s := s + ' ' + Phrases.Lookup('FRCANCELQUERY_PEACE');
     1474        S := S + ' ' + Phrases.Lookup('FRCANCELQUERY_PEACE');
    13251475      trFriendlyContact:
    1326         s := s + ' ' + Phrases.Lookup('FRCANCELQUERY_FRIENDLY');
     1476        S := S + ' ' + Phrases.Lookup('FRCANCELQUERY_FRIENDLY');
    13271477      trAlliance:
    1328         s := s + ' ' + Phrases.Lookup('FRCANCELQUERY_ALLIANCE');
    1329     end;
    1330     result := SimpleQuery(mkYesNo, s, 'NEGO_REJECTED') = mrOK;
    1331     if result then
     1478        S := S + ' ' + Phrases.Lookup('FRCANCELQUERY_ALLIANCE');
     1479    end;
     1480    Result := SimpleQuery(mkYesNo, S, 'NEGO_REJECTED') = mrOK;
     1481    if Result then
    13321482    begin
    13331483      Play('CANCELTREATY');
    1334       Server(sCancelTreaty, me, 0, nil^);
    1335       if MyRO.Treaty[p] = trNone then
     1484      Server(sCancelTreaty, Me, 0, nil^);
     1485      if MyRO.Treaty[P] = trNone then
    13361486        CityOptimizer_BeginOfTurn;
    13371487      // peace treaty was cancelled -- use formerly forbidden tiles
    1338       MapValid := false;
     1488      MapValid := False;
    13391489      PaintAllMaps;
    13401490    end;
     
    13441494procedure TMainScreen.RememberPeaceViolation;
    13451495var
    1346   uix, p1: integer;
     1496  uix, p1: Integer;
    13471497begin
    13481498  MyData.PeaceEvaHappened := 0;
     
    13521502      begin
    13531503        p1 := MyRO.Territory[Loc];
    1354         if (p1 <> me) and (p1 >= 0) and
     1504        if (p1 <> Me) and (p1 >= 0) and
    13551505          (MyRO.Turn = MyRO.EvaStart[p1] + (PeaceEvaTurns - 1)) then
    13561506          MyData.PeaceEvaHappened := MyData.PeaceEvaHappened or (1 shl p1);
     
    13901540
    13911541var
    1392   i, cix, mix: integer;
    1393   need: boolean;
     1542  I, cix, mix: Integer;
     1543  need: Boolean;
    13941544  mi: TModelInfo;
    13951545begin
    13961546  if (sbStart in Check) and not (sbStart in SoundPreloadDone) then begin
    1397     for i := 0 to nStartBlock - 1 do
    1398       PreparePlay(StartBlock[i]);
     1547    for I := 0 to nStartBlock - 1 do
     1548      PreparePlay(StartBlock[I]);
    13991549    SoundPreloadDone := SoundPreloadDone + [sbStart];
    14001550  end;
    14011551  if (sbWonder in Check) and not (sbWonder in SoundPreloadDone) then begin
    1402     need := false;
    1403     for i := 0 to nWonder - 1 do
    1404       if MyRO.Wonder[i].CityID <> WonderNotBuiltYet then
    1405         need := true;
     1552    need := False;
     1553    for I := 0 to nWonder - 1 do
     1554      if MyRO.Wonder[I].CityID <> WonderNotBuiltYet then
     1555        need := True;
    14061556    if need then begin
    1407       for i := 0 to nWonderBlock - 1 do
    1408         PreparePlay(WonderBlock[i]);
     1557      for I := 0 to nWonderBlock - 1 do
     1558        PreparePlay(WonderBlock[I]);
    14091559      SoundPreloadDone := SoundPreloadDone + [sbWonder];
    14101560    end;
     
    14121562  if ((sbScience in Check) and not (sbScience in SoundPreloadDone)) and
    14131563    (MyRO.Tech[adScience] >= tsApplicable) then begin
    1414     for i := 0 to nScienceBlock - 1 do
    1415       PreparePlay(ScienceBlock[i]);
     1564    for I := 0 to nScienceBlock - 1 do
     1565      PreparePlay(ScienceBlock[I]);
    14161566    SoundPreloadDone := SoundPreloadDone + [sbScience];
    14171567  end;
    14181568  if ((sbContact in Check) and not (sbContact in SoundPreloadDone)) and
    14191569    (MyRO.nEnemyModel + MyRO.nEnemyCity > 0) then begin
    1420     for i := 0 to nContactBlock - 1 do
    1421       PreparePlay(ContactBlock[i]);
     1570    for I := 0 to nContactBlock - 1 do
     1571      PreparePlay(ContactBlock[I]);
    14221572    SoundPreloadDone := SoundPreloadDone + [sbContact];
    14231573  end;
     
    14301580      with MyCity[cix] do
    14311581        if (Loc >= 0) and (Flags and CityRepMask <> 0) then
    1432           for i := 0 to 12 do
    1433             if 1 shl i and Flags and CityRepMask <> 0 then
    1434               PreparePlay(CityEventSoundItem[i]);
     1582          for I := 0 to 12 do
     1583            if 1 shl I and Flags and CityRepMask <> 0 then
     1584              PreparePlay(CityEventSoundItem[I]);
    14351585    for mix := 0 to MyRO.nModel - 1 do
    14361586      with MyModel[mix] do
    14371587        if Attack > 0 then
    14381588        begin
    1439           MakeModelInfo(me, mix, MyModel[mix], mi);
     1589          MakeModelInfo(Me, mix, MyModel[mix], mi);
    14401590          PreparePlay(AttackSound(ModelCode(mi)));
    14411591        end;
     
    14481598  Color: TColor;
    14491599  Name: string;
    1450   ok: boolean;
     1600  ok: Boolean;
    14511601begin
    14521602  UnusedTribeFiles.Clear;
     
    14681618end;
    14691619
    1470 function TMainScreen.ChooseUnusedTribe: integer;
     1620function TMainScreen.GetUnitStatDlg: TUnitStatDlg;
     1621begin
     1622  if not Assigned(FUnitStatDlg) then begin
     1623    FUnitStatDlg := TUnitStatDlg.Create(nil);
     1624    ArrangeDialog(FUnitStatDlg);
     1625    FUnitStatDlg.CheckAge;
     1626  end;
     1627  Result := FUnitStatDlg;
     1628end;
     1629
     1630function TMainScreen.GetWondersDlg: TWondersDlg;
     1631begin
     1632  if not Assigned(FWondersDlg) then FWondersDlg := TWondersDlg.Create(nil);
     1633  Result := FWondersDlg;
     1634end;
     1635
     1636function TMainScreen.ChooseUnusedTribe: Integer;
    14711637var
    1472   i: Integer;
    1473   j: Integer;
     1638  I: Integer;
     1639  J: Integer;
    14741640  ColorDistance: Integer;
    14751641  BestColorDistance: Integer;
     
    14771643  CountBest: Integer;
    14781644begin
    1479   assert(UnusedTribeFiles.Count > 0);
    1480   result := -1;
     1645  Assert(UnusedTribeFiles.Count > 0);
     1646  Result := -1;
    14811647  BestColorDistance := -1;
    1482   for j := 0 to UnusedTribeFiles.Count - 1 do
     1648  for J := 0 to UnusedTribeFiles.Count - 1 do
    14831649  begin
    14841650    ColorDistance := 250; // consider differences more than this infinite
    1485     for i := 0 to nPl - 1 do
    1486       if Tribe[i] <> nil then
     1651    for I := 0 to nPl - 1 do
     1652      if Tribe[I] <> nil then
    14871653      begin
    1488         TestColorDistance := abs(integer(UnusedTribeFiles.Objects[j])
    1489           shr 16 and $FF - Tribe[i].Color shr 16 and $FF) +
    1490           abs(integer(UnusedTribeFiles.Objects[j]) shr 8 and
    1491           $FF - Tribe[i].Color shr 8 and $FF) * 3 +
    1492           abs(integer(UnusedTribeFiles.Objects[j]) and
    1493           $FF - Tribe[i].Color and $FF) * 2;
     1654        TestColorDistance := abs(Integer(UnusedTribeFiles.Objects[J])
     1655          shr 16 and $FF - Tribe[I].Color shr 16 and $FF) +
     1656          abs(Integer(UnusedTribeFiles.Objects[J]) shr 8 and
     1657          $FF - Tribe[I].Color shr 8 and $FF) * 3 +
     1658          abs(Integer(UnusedTribeFiles.Objects[J]) and
     1659          $FF - Tribe[I].Color and $FF) * 2;
    14941660        if TestColorDistance < ColorDistance then
    14951661          ColorDistance := TestColorDistance;
     
    15021668    if ColorDistance = BestColorDistance then
    15031669    begin
    1504       inc(CountBest);
     1670      Inc(CountBest);
    15051671      if DelphiRandom(CountBest) = 0 then
    1506         result := j;
     1672        Result := J;
    15071673    end;
    15081674  end;
     
    15111677procedure TMainScreen.ShowEnemyShipChange(ShowShipChange: TShowShipChange);
    15121678var
    1513   i, TestCost, MostCost: integer;
    1514   Ship1Plus, Ship2Plus: boolean;
     1679  I, TestCost, MostCost: Integer;
     1680  Ship1Plus, Ship2Plus: Boolean;
    15151681begin
    15161682  with ShowShipChange, MessgExDlg do
     
    15351701        begin
    15361702          OpenSound := 'SHIP_TRADED';
    1537           Ship1Plus := false;
    1538           Ship2Plus := false;
    1539           for i := 0 to nShipPart - 1 do
     1703          Ship1Plus := False;
     1704          Ship2Plus := False;
     1705          for I := 0 to nShipPart - 1 do
    15401706          begin
    1541             if Ship1Change[i] > 0 then
    1542               Ship1Plus := true;
    1543             if Ship2Change[i] > 0 then
    1544               Ship2Plus := true;
     1707            if Ship1Change[I] > 0 then
     1708              Ship1Plus := True;
     1709            if Ship2Change[I] > 0 then
     1710              Ship2Plus := True;
    15451711          end;
    15461712          if Ship1Plus and Ship2Plus then
     
    15691735    begin
    15701736      MostCost := 0;
    1571       for i := 0 to nShipPart - 1 do
     1737      for I := 0 to nShipPart - 1 do
    15721738      begin
    1573         TestCost := abs(Ship1Change[i]) * Imp[imShipComp + i].Cost;
     1739        TestCost := abs(Ship1Change[I]) * Imp[imShipComp + I].Cost;
    15741740        if TestCost > MostCost then
    15751741        begin
    15761742          MostCost := TestCost;
    1577           IconIndex := imShipComp + i;
     1743          IconIndex := imShipComp + I;
    15781744        end;
    15791745      end;
     
    15871753procedure TMainScreen.InitModule;
    15881754var
    1589   i, j, Domain: integer;
     1755  I, J, Domain: Integer;
    15901756begin
    15911757  { search icons for advances: }
    1592   for i := 0 to nAdv - 1 do
    1593     if i in FutureTech then
    1594       AdvIcon[i] := 96 + i - futResearchTechnology
     1758  for I := 0 to nAdv - 1 do
     1759    if I in FutureTech then
     1760      AdvIcon[I] := 96 + I - futResearchTechnology
    15951761    else
    15961762    begin
    1597       AdvIcon[i] := -1;
     1763      AdvIcon[I] := -1;
    15981764      for Domain := 0 to nDomains - 1 do
    1599         for j := 0 to nUpgrade - 1 do
    1600           if upgrade[Domain, j].Preq = i then
    1601             if AdvIcon[i] >= 0 then
    1602               AdvIcon[i] := 85
     1765        for J := 0 to nUpgrade - 1 do
     1766          if upgrade[Domain, J].Preq = I then
     1767            if AdvIcon[I] >= 0 then
     1768              AdvIcon[I] := 85
    16031769            else
    1604               AdvIcon[i] := 86 + Domain;
    1605       for j := 0 to nFeature - 1 do
    1606         if Feature[j].Preq = i then
     1770              AdvIcon[I] := 86 + Domain;
     1771      for J := 0 to nFeature - 1 do
     1772        if Feature[J].Preq = I then
    16071773          for Domain := 0 to nDomains - 1 do
    1608             if 1 shl Domain and Feature[j].Domains <> 0 then
    1609               if (AdvIcon[i] >= 0) and (AdvIcon[i] <> 86 + Domain) then
    1610                 AdvIcon[i] := 85
     1774            if 1 shl Domain and Feature[J].Domains <> 0 then
     1775              if (AdvIcon[I] >= 0) and (AdvIcon[I] <> 86 + Domain) then
     1776                AdvIcon[I] := 85
    16111777              else
    1612                 AdvIcon[i] := 86 + Domain;
    1613       for j := nWonder to nImp - 1 do
    1614         if Imp[j].Preq = i then
    1615           AdvIcon[i] := j;
    1616       for j := nWonder to nImp - 1 do
    1617         if (Imp[j].Preq = i) and (Imp[j].Kind <> ikCommon) then
    1618           AdvIcon[i] := j;
    1619       for j := 0 to nJob - 1 do
    1620         if i = JobPreq[j] then
    1621           AdvIcon[i] := 84;
    1622       for j := 0 to nWonder - 1 do
    1623         if Imp[j].Preq = i then
    1624           AdvIcon[i] := j;
    1625       if AdvIcon[i] < 0 then
    1626         if AdvValue[i] < 1000 then
    1627           AdvIcon[i] := -7
     1778                AdvIcon[I] := 86 + Domain;
     1779      for J := nWonder to nImp - 1 do
     1780        if Imp[J].Preq = I then
     1781          AdvIcon[I] := J;
     1782      for J := nWonder to nImp - 1 do
     1783        if (Imp[J].Preq = I) and (Imp[J].Kind <> ikCommon) then
     1784          AdvIcon[I] := J;
     1785      for J := 0 to nJob - 1 do
     1786        if I = JobPreq[J] then
     1787          AdvIcon[I] := 84;
     1788      for J := 0 to nWonder - 1 do
     1789        if Imp[J].Preq = I then
     1790          AdvIcon[I] := J;
     1791      if AdvIcon[I] < 0 then
     1792        if AdvValue[I] < 1000 then
     1793          AdvIcon[I] := -7
    16281794        else
    1629           AdvIcon[i] := 24 + AdvValue[i] div 1000;
    1630       for j := 2 to nGov - 1 do
    1631         if GovPreq[j] = i then
    1632           AdvIcon[i] := j - 8;
     1795          AdvIcon[I] := 24 + AdvValue[I] div 1000;
     1796      for J := 2 to nGov - 1 do
     1797        if GovPreq[J] = I then
     1798          AdvIcon[I] := J - 8;
    16331799    end;
    16341800  AdvIcon[adConscription] := 86 + dGround;
    16351801
    16361802  UnusedTribeFiles := tstringlist.Create;
    1637   UnusedTribeFiles.Sorted := true;
     1803  UnusedTribeFiles.Sorted := True;
    16381804  TribeNames := tstringlist.Create;
    16391805
    16401806  IsoEngine.Init(InitEnemyModel);
    16411807  // non-default tile size is missing a file, switch to default
    1642   MainMap.SetOutput(offscreen);
     1808  MainMap.SetOutput(Offscreen);
    16431809
    16441810  HGrStdUnits := LoadGraphicSet('StdUnits.png');
     
    16471813  InitSmallImp;
    16481814  SoundPreloadDone := [];
    1649   StartRunning := false;
    1650   StayOnTop_Ensured := false;
     1815  StartRunning := False;
    16511816
    16521817  sb := TPVScrollbar.Create(Self);
     
    16591824  FreeAndNil(UnusedTribeFiles);
    16601825  FreeAndNil(TribeNames);
    1661   // AdvisorDlg.DeInit;
    1662 end;
    1663 
    1664 procedure TMainScreen.InitTurn(NewPlayer: integer);
     1826end;
     1827
     1828procedure TMainScreen.InitTurn(NewPlayer: Integer);
    16651829const
    16661830  nAdvBookIcon = 16;
    16671831  AdvBookIcon: array [0 .. nAdvBookIcon - 1] of record Adv,
    1668     Icon: integer end = ((Adv: adPolyTheism; Icon: woZeus),
     1832    Icon: Integer end = ((Adv: adPolyTheism; Icon: woZeus),
    16691833    (Adv: adBronzeWorking; Icon: woColossus), (Adv: adMapMaking;
    16701834    Icon: woLighthouse), (Adv: adPoetry; Icon: imTheater), (Adv: adMonotheism;
     
    16781842  sbAll = [sbStart, sbWonder, sbScience, sbContact, sbTurn];
    16791843var
    1680   p1, i, ad, uix, cix, MoveOptions, MoveResult, Loc1,
     1844  p1, I, ad, uix, cix, MoveOptions, MoveResult, Loc1,
    16811845    NewAgeCenterTo, Winners, NewGovAvailable, dx,
    1682     dy: integer;
     1846    dy: Integer;
    16831847  MoveAdviceData: TMoveAdviceData;
    16841848  Picture: TModelPictureInfo;
    1685   s, Item, Item2: string;
     1849  S, Item, Item2: string;
    16861850  UpdatePanel, OwnWonder, ok, Stop, ShowCityList, WondersOnly,
    1687     AllowCityScreen: boolean;
    1688 begin
    1689   if IsMultiPlayerGame and (NewPlayer <> me) then
    1690   begin
    1691     UnitInfoBtn.Visible := false;
    1692     UnitBtn.Visible := false;
    1693     TerrainBtn.Visible := false;
    1694     EOT.Visible := false;
    1695   end;
    1696   if IsMultiPlayerGame and (NewPlayer <> me) and
     1851    AllowCityScreen: Boolean;
     1852begin
     1853  if IsMultiPlayerGame and (NewPlayer <> Me) then
     1854  begin
     1855    UnitInfoBtn.Visible := False;
     1856    UnitBtn.Visible := False;
     1857    TerrainBtn.Visible := False;
     1858    EOT.Visible := False;
     1859  end;
     1860  if IsMultiPlayerGame and (NewPlayer <> Me) and
    16971861    (G.RO[0].Happened and phShipComplete = 0) then
    16981862  begin // inter player screen
    1699     for i := 0 to ControlCount - 1 do
    1700       if Controls[i] is TButtonC then
    1701         Controls[i].Visible := false;
    1702     me := -1;
     1863    for I := 0 to ControlCount - 1 do
     1864      if Controls[I] is TButtonC then
     1865        Controls[I].Visible := False;
     1866    Me := -1;
    17031867    MainTexture.Age := -1;
    17041868    with Panel.Canvas do
     
    17161880    Invalidate;
    17171881
    1718     s := TurnToString(G.RO[0].Turn);
    1719     if supervising then
    1720       SimpleMessage(Format(Phrases.Lookup('SUPERTURN'), [s]))
     1882    S := TurnToString(G.RO[0].Turn);
     1883    if Supervising then
     1884      SimpleMessage(Format(Phrases.Lookup('SUPERTURN'), [S]))
    17211885    else
    1722       SimpleMessage(Format(Tribe[NewPlayer].TPhrase('TURN'), [s]));
    1723   end;
    1724   for i := 0 to ControlCount - 1 do
    1725     if Controls[i] is TButtonC then
    1726       Controls[i].Visible := true;
     1886      SimpleMessage(Format(Tribe[NewPlayer].TPhrase('TURN'), [S]));
     1887  end;
     1888  for I := 0 to ControlCount - 1 do
     1889    if Controls[I] is TButtonC then
     1890      Controls[I].Visible := True;
    17271891
    17281892  ItsMeAgain(NewPlayer);
    17291893  MyData := G.RO[NewPlayer].Data;
    1730   if not supervising then
     1894  if not Supervising then
    17311895    SoundPreload(sbAll);
    1732   if (me = 0) and ((MyRO.Turn = 0) or (ClientMode = cResume)) then
     1896  if (Me = 0) and ((MyRO.Turn = 0) or (ClientMode = cResume)) then
    17331897    Invalidate; // colorize empty space
    17341898
    1735   if not supervising then
     1899  if not Supervising then
    17361900  begin
    17371901
     
    17431907      else }
    17441908    begin
    1745       Age := GetAge(me);
     1909      Age := GetAge(Me);
    17461910      if MainTexture.Age <> Age then begin
    17471911        MainTexture.Age := Age;
     
    17671931  end;
    17681932  InitCityMark(MainTexture);
    1769   CityDlg.CheckAge;
    1770   NatStatDlg.CheckAge;
    1771   UnitStatDlg.CheckAge;
    1772   HelpDlg.Difficulty := G.Difficulty[me];
     1933  if Assigned(FCityDlg) then FCityDlg.CheckAge;
     1934  if Assigned(FNatStatDlg) then FNatStatDlg.CheckAge;
     1935  if Assigned(FUnitStatDlg) then FUnitStatDlg.CheckAge;
     1936  if Assigned(FHelpDlg) then FHelpDlg.Difficulty := G.Difficulty[Me];
    17731937
    17741938  UnFocus := -1;
    17751939  MarkCityLoc := -1;
    1776   BlinkON := false;
     1940  BlinkON := False;
    17771941  BlinkTime := -1;
    1778   Tracking := false;
    1779   TurnComplete := false;
     1942  Tracking := False;
     1943  TurnComplete := False;
    17801944
    17811945  if (ToldSlavery < 0) or
     
    17971961          Hash := 0;
    17981962          GrName := 'StdUnits.png';
    1799           Tribe[p1].SetModelPicture(Picture, true);
    1800         end
    1801   end;
    1802 
    1803   if not supervising and (ClientMode = cTurn) then
     1963          Tribe[p1].SetModelPicture(Picture, True);
     1964        end;
     1965  end;
     1966
     1967  if not Supervising and (ClientMode = cTurn) then
    18041968  begin
    18051969    for cix := 0 to MyRO.nCity - 1 do
     
    18161980  if ClientMode = cMovieTurn then
    18171981  begin
    1818     UnitInfoBtn.Visible := false;
    1819     UnitBtn.Visible := false;
    1820     TerrainBtn.Visible := false;
     1982    UnitInfoBtn.Visible := False;
     1983    UnitBtn.Visible := False;
     1984    TerrainBtn.Visible := False;
    18211985    EOT.Hint := Phrases.Lookup('BTN_STOP');
    1822     EOT.Visible := true;
     1986    EOT.Visible := True;
    18231987  end
    18241988  else if ClientMode < scContact then
     
    18271991    UnitBtn.Visible := UnFocus >= 0;
    18281992    CheckTerrainBtnVisible;
    1829     TurnComplete := supervising;
     1993    TurnComplete := Supervising;
    18301994    EOT.Hint := Phrases.Lookup('BTN_ENDTURN');
    1831     EOT.Visible := Server(sTurn - sExecute, me, 0, nil^) >= rExecuted;
     1995    EOT.Visible := Server(sTurn - sExecute, Me, 0, nil^) >= rExecuted;
    18321996  end
    18331997  else
    18341998  begin
    1835     UnitInfoBtn.Visible := false;
    1836     UnitBtn.Visible := false;
    1837     TerrainBtn.Visible := false;
     1999    UnitInfoBtn.Visible := False;
     2000    UnitBtn.Visible := False;
     2001    TerrainBtn.Visible := False;
    18382002    EOT.Hint := Phrases.Lookup('BTN_NEGO');
    1839     EOT.Visible := true;
     2003    EOT.Visible := True;
    18402004  end;
    18412005  SetTroopLoc(-1);
    1842   MapValid := false;
     2006  MapValid := False;
    18432007  NewAgeCenterTo := 0;
    1844   if ((MyRO.Turn = 0) and not supervising or IsMultiPlayerGame or
     2008  if ((MyRO.Turn = 0) and not Supervising or IsMultiPlayerGame or
    18452009    (ClientMode = cResume)) and (MyRO.nCity > 0) then
    18462010  begin
     
    18572021      begin
    18582022        NewAgeCenterTo := -1;
    1859         Loc1 := dLoc(Loc1, -dx, -dy)
     2023        Loc1 := dLoc(Loc1, -dx, -dy);
    18602024      end
    18612025      else
     
    18652029      end
    18662030    end;
    1867     Centre(Loc1)
    1868   end;
    1869 
    1870   for i := 0 to DpiScreen.FormCount - 1 do
    1871     if DpiScreen.Forms[i] is TBufferedDrawDlg then
    1872       DpiScreen.Forms[i].Enabled := true;
     2031    Centre(Loc1);
     2032  end;
     2033
     2034  ApplyToVisibleForms(faEnable);
    18732035
    18742036  if ClientMode <> cResume then
     
    18812043    // first turn after anarchy -- don't show despotism palace!
    18822044    Update;
    1883     for i := 0 to DpiScreen.FormCount - 1 do
    1884       if (DpiScreen.Forms[i].Visible) and (DpiScreen.Forms[i] is TBufferedDrawDlg)
    1885       then
    1886       begin
    1887         if @DpiScreen.Forms[i].OnShow <> nil then
    1888           DpiScreen.Forms[i].OnShow(nil);
    1889         DpiScreen.Forms[i].Invalidate;
    1890         DpiScreen.Forms[i].Update;
    1891       end;
     2045    ApplyToVisibleForms(faUpdate);
    18922046
    18932047    if MyRO.Happened and phGameEnd <> 0 then
     
    18972051        begin
    18982052          OpenSound := 'MSG_GAMEOVER';
    1899           MessgText := Tribe[me].TPhrase('GAMEOVER');
     2053          MessgText := Tribe[Me].TPhrase('GAMEOVER');
    19002054          IconKind := mikBigIcon;
    19012055          IconIndex := 8;
     
    19082062            begin
    19092063              Winners := Winners or 1 shl p1;
    1910               for i := 0 to nShipPart - 1 do
    1911                 if MyRO.Ship[p1].Parts[i] < ShipNeed[i] then
     2064              for I := 0 to nShipPart - 1 do
     2065                if MyRO.Ship[p1].Parts[I] < ShipNeed[I] then
    19122066                  Winners := Winners and not(1 shl p1);
    19132067            end;
    1914           assert(Winners <> 0);
    1915           if Winners and (1 shl me) <> 0 then
     2068          Assert(Winners <> 0);
     2069          if Winners and (1 shl Me) <> 0 then
    19162070          begin
    1917             s := '';
     2071            S := '';
    19182072            for p1 := 0 to nPl - 1 do
    1919               if (p1 <> me) and (1 shl p1 and Winners <> 0) then
    1920                 if s = '' then
    1921                   s := Tribe[p1].TPhrase('SHORTNAME')
     2073              if (p1 <> Me) and (1 shl p1 and Winners <> 0) then
     2074                if S = '' then
     2075                  S := Tribe[p1].TPhrase('SHORTNAME')
    19222076                else
    1923                   s := Format(Phrases.Lookup('SHAREDWIN_CONCAT'),
    1924                     [s, Tribe[p1].TPhrase('SHORTNAME')]);
     2077                  S := Format(Phrases.Lookup('SHAREDWIN_CONCAT'),
     2078                    [S, Tribe[p1].TPhrase('SHORTNAME')]);
    19252079
    19262080            OpenSound := 'MSG_YOUWIN';
    1927             MessgText := Tribe[me].TPhrase('MYSPACESHIP');
    1928             if s <> '' then
     2081            MessgText := Tribe[Me].TPhrase('MYSPACESHIP');
     2082            if S <> '' then
    19292083              MessgText := MessgText + '\' +
    1930                 Format(Phrases.Lookup('SHAREDWIN'), [s]);
     2084                Format(Phrases.Lookup('SHAREDWIN'), [S]);
    19312085            IconKind := mikBigIcon;
    19322086            IconIndex := 9;
     
    19342088          else
    19352089          begin
    1936             assert(me = 0);
     2090            Assert(Me = 0);
    19372091            OpenSound := 'MSG_GAMEOVER';
    19382092            MessgText := '';
     
    19462100        else { if MyRO.Happened and fTimeUp<>0 then }
    19472101        begin
    1948           assert(me = 0);
     2102          Assert(Me = 0);
    19492103          OpenSound := 'MSG_GAMEOVER';
    1950           if not supervising then
    1951             MessgText := Tribe[me].TPhrase('TIMEUP')
     2104          if not Supervising then
     2105            MessgText := Tribe[Me].TPhrase('TIMEUP')
    19522106          else
    19532107            MessgText := Phrases.Lookup('TIMEUPSUPER');
     
    19612115          p1 := 0;
    19622116          while (p1 < nPl - 1) and (Winners and (1 shl p1) = 0) do
    1963             inc(p1);
     2117            Inc(p1);
    19642118          if MyRO.Happened and phShipComplete = 0 then
    19652119            DiaDlg.ShowNewContent_Charts(wmModal);
    19662120        end;
    1967         TurnComplete := true;
    1968         exit;
    1969       end;
    1970     if not supervising and (1 shl me and MyRO.Alive = 0) then
     2121        TurnComplete := True;
     2122        Exit;
     2123      end;
     2124    if not Supervising and (1 shl Me and MyRO.Alive = 0) then
    19712125    begin
    1972       TurnComplete := true;
    1973       exit;
     2126      TurnComplete := True;
     2127      Exit;
    19742128    end;
    19752129
    19762130    if (ClientMode = cContinue) and
    1977       (DipMem[me].SentCommand and $FF0F = scContact) then
     2131      (DipMem[Me].SentCommand and $FF0F = scContact) then
    19782132      // contact was refused
    1979       if MyRO.Treaty[DipMem[me].pContact] >= trPeace then
    1980         ContactRefused(DipMem[me].pContact, 'FRREJECTED')
     2133      if MyRO.Treaty[DipMem[Me].pContact] >= trPeace then
     2134        ContactRefused(DipMem[Me].pContact, 'FRREJECTED')
    19812135      else
    1982         SoundMessage(Tribe[DipMem[me].pContact].TPhrase('FRREJECTED'),
     2136        SoundMessage(Tribe[DipMem[Me].pContact].TPhrase('FRREJECTED'),
    19832137          'NEGO_REJECTED');
    19842138
    1985     if not supervising and (Age > MyData.ToldAge) and
     2139    if not Supervising and (Age > MyData.ToldAge) and
    19862140      ((Age > 0) or (ClientMode <> cMovieTurn)) then
    19872141      with MessgExDlg do
     
    19912145          if Phrases2FallenBackToEnglish then
    19922146          begin
    1993             s := Tribe[me].TPhrase('AGE0');
     2147            S := Tribe[Me].TPhrase('AGE0');
    19942148            MessgText :=
    1995               Format(s, [TurnToString(MyRO.Turn), CityName(MyCity[0].ID)])
     2149              Format(S, [TurnToString(MyRO.Turn), CityName(MyCity[0].ID)]);
    19962150          end
    19972151          else
    19982152          begin
    1999             s := Tribe[me].TString(Phrases2.Lookup('AGE0'));
    2000             MessgText := Format(s, [TurnToString(MyRO.Turn)]);
    2001           end
     2153            S := Tribe[Me].TString(Phrases2.Lookup('AGE0'));
     2154            MessgText := Format(S, [TurnToString(MyRO.Turn)]);
     2155          end;
    20022156        end
    20032157        else
    20042158        begin
    2005           s := Tribe[me].TPhrase('AGE' + char(48 + Age));
    2006           MessgText := Format(s, [TurnToString(MyRO.Turn)]);
     2159          S := Tribe[Me].TPhrase('AGE' + char(48 + Age));
     2160          MessgText := Format(S, [TurnToString(MyRO.Turn)]);
    20072161        end;
    20082162        IconKind := mikAge;
     
    20122166        CenterTo := NewAgeCenterTo;
    20132167        OpenSound := 'AGE_' + char(48 + Age);
     2168        DpiApplication.ProcessMessages;
    20142169        ShowModal;
    20152170        MyData.ToldAge := Age;
     
    20252180          begin
    20262181            OpenSound := 'MSG_EXTINCT';
    2027             s := Tribe[p1].TPhrase('EXTINCT');
    2028             MessgText := Format(s, [TurnToString(MyRO.Turn)]);
    2029             if MyRO.Alive = 1 shl me then
     2182            S := Tribe[p1].TPhrase('EXTINCT');
     2183            MessgText := Format(S, [TurnToString(MyRO.Turn)]);
     2184            if MyRO.Alive = 1 shl Me then
    20302185              MessgText := MessgText + Phrases.Lookup('EXTINCTALL');
    20312186            Kind := mkOk;
     
    20342189            ShowModal;
    20352190          end;
    2036       if (ClientMode <> cMovieTurn) and not supervising then
     2191      if (ClientMode <> cMovieTurn) and not Supervising then
    20372192        DiaDlg.ShowNewContent_Charts(wmModal);
    20382193    end;
    20392194
    20402195    // tell changes of own credibility
    2041     if not supervising then
     2196    if not Supervising then
    20422197    begin
    20432198      if RoughCredibility(MyRO.Credibility) <>
     
    20462201        if RoughCredibility(MyRO.Credibility) >
    20472202          RoughCredibility(MyData.ToldOwnCredibility) then
    2048           s := Phrases.Lookup('CREDUP')
     2203          S := Phrases.Lookup('CREDUP')
    20492204        else
    2050           s := Phrases.Lookup('CREDDOWN');
    2051         TribeMessage(me, Format(s, [Phrases.Lookup('CREDIBILITY',
     2205          S := Phrases.Lookup('CREDDOWN');
     2206        TribeMessage(Me, Format(S, [Phrases.Lookup('CREDIBILITY',
    20522207          RoughCredibility(MyRO.Credibility))]), '');
    20532208      end;
     
    20552210    end;
    20562211
    2057     for i := 0 to nWonder - 1 do
     2212    for I := 0 to nWonder - 1 do
    20582213    begin
    2059       OwnWonder := false;
     2214      OwnWonder := False;
    20602215      for cix := 0 to MyRO.nCity - 1 do
    2061         if (MyCity[cix].Loc >= 0) and (MyCity[cix].ID = MyRO.Wonder[i].CityID)
     2216        if (MyCity[cix].Loc >= 0) and (MyCity[cix].ID = MyRO.Wonder[I].CityID)
    20622217        then
    2063           OwnWonder := true;
    2064       if MyRO.Wonder[i].CityID <> MyData.ToldWonders[i].CityID then
     2218          OwnWonder := True;
     2219      if MyRO.Wonder[I].CityID <> MyData.ToldWonders[I].CityID then
    20652220      begin
    2066         if MyRO.Wonder[i].CityID = WonderDestroyed then
     2221        if MyRO.Wonder[I].CityID = WonderDestroyed then
    20672222          with MessgExDlg do
    20682223          begin { tell about destroyed wonders }
    20692224            OpenSound := 'WONDER_DESTROYED';
    20702225            MessgText := Format(Phrases.Lookup('WONDERDEST'),
    2071               [Phrases.Lookup('IMPROVEMENTS', i)]);
     2226              [Phrases.Lookup('IMPROVEMENTS', I)]);
    20722227            Kind := mkOkHelp;
    20732228            HelpKind := hkImp;
    2074             HelpNo := i;
     2229            HelpNo := I;
    20752230            IconKind := mikImp;
    2076             IconIndex := i;
     2231            IconIndex := I;
    20772232            ShowModal;
    20782233          end
    20792234        else
    20802235        begin
    2081           if i = woManhattan then
    2082             if MyRO.Wonder[i].EffectiveOwner > me then
     2236          if I = woManhattan then
     2237            if MyRO.Wonder[I].EffectiveOwner > Me then
    20832238              MyData.ColdWarStart := MyRO.Turn - 1
    20842239            else
     
    20872242            with MessgExDlg do
    20882243            begin { tell about newly built wonders }
    2089               if i = woManhattan then
     2244              if I = woManhattan then
    20902245              begin
    20912246                OpenSound := 'MSG_COLDWAR';
    2092                 s := Tribe[MyRO.Wonder[i].EffectiveOwner].TPhrase('COLDWAR')
     2247                S := Tribe[MyRO.Wonder[I].EffectiveOwner].TPhrase('COLDWAR');
    20932248              end
    2094               else if MyRO.Wonder[i].EffectiveOwner >= 0 then
     2249              else if MyRO.Wonder[I].EffectiveOwner >= 0 then
    20952250              begin
    20962251                OpenSound := 'WONDER_BUILT';
    2097                 s := Tribe[MyRO.Wonder[i].EffectiveOwner]
    2098                   .TPhrase('WONDERBUILT')
     2252                S := Tribe[MyRO.Wonder[I].EffectiveOwner]
     2253                  .TPhrase('WONDERBUILT');
    20992254              end
    21002255              else
    21012256              begin
    21022257                OpenSound := 'MSG_DEFAULT';
    2103                 s := Phrases.Lookup('WONDERBUILTEXP');
     2258                S := Phrases.Lookup('WONDERBUILTEXP');
    21042259                // already expired when built
    21052260              end;
    2106               MessgText := Format(s, [Phrases.Lookup('IMPROVEMENTS', i),
    2107                 CityName(MyRO.Wonder[i].CityID)]);
     2261              MessgText := Format(S, [Phrases.Lookup('IMPROVEMENTS', I),
     2262                CityName(MyRO.Wonder[I].CityID)]);
    21082263              Kind := mkOkHelp;
    21092264              HelpKind := hkImp;
    2110               HelpNo := i;
     2265              HelpNo := I;
    21112266              IconKind := mikImp;
    2112               IconIndex := i;
     2267              IconIndex := I;
    21132268              ShowModal;
    2114             end
    2115         end
     2269            end;
     2270        end;
    21162271      end
    2117       else if (MyRO.Wonder[i].EffectiveOwner <> MyData.ToldWonders[i]
    2118         .EffectiveOwner) and (MyRO.Wonder[i].CityID > WonderDestroyed) then
    2119         if MyRO.Wonder[i].EffectiveOwner < 0 then
     2272      else if (MyRO.Wonder[I].EffectiveOwner <> MyData.ToldWonders[I]
     2273        .EffectiveOwner) and (MyRO.Wonder[I].CityID > WonderDestroyed) then
     2274        if MyRO.Wonder[I].EffectiveOwner < 0 then
    21202275        begin
    2121           if i <> woMIR then
     2276          if I <> woMIR then
    21222277            with MessgExDlg do
    21232278            begin { tell about expired wonders }
    21242279              OpenSound := 'WONDER_EXPIRED';
    21252280              MessgText := Format(Phrases.Lookup('WONDEREXP'),
    2126                 [Phrases.Lookup('IMPROVEMENTS', i),
    2127                 CityName(MyRO.Wonder[i].CityID)]);
     2281                [Phrases.Lookup('IMPROVEMENTS', I),
     2282                CityName(MyRO.Wonder[I].CityID)]);
    21282283              Kind := mkOkHelp;
    21292284              HelpKind := hkImp;
    2130               HelpNo := i;
     2285              HelpNo := I;
    21312286              IconKind := mikImp;
    2132               IconIndex := i;
     2287              IconIndex := I;
    21332288              ShowModal;
    2134             end
     2289            end;
    21352290        end
    2136         else if (MyData.ToldWonders[i].EffectiveOwner >= 0) and not OwnWonder
     2291        else if (MyData.ToldWonders[I].EffectiveOwner >= 0) and not OwnWonder
    21372292        then
    21382293          with MessgExDlg do
    21392294          begin { tell about capture of wonders }
    21402295            OpenSound := 'WONDER_CAPTURED';
    2141             s := Tribe[MyRO.Wonder[i].EffectiveOwner].TPhrase('WONDERCAPT');
    2142             MessgText := Format(s, [Phrases.Lookup('IMPROVEMENTS', i),
    2143               CityName(MyRO.Wonder[i].CityID)]);
     2296            S := Tribe[MyRO.Wonder[I].EffectiveOwner].TPhrase('WONDERCAPT');
     2297            MessgText := Format(S, [Phrases.Lookup('IMPROVEMENTS', I),
     2298              CityName(MyRO.Wonder[I].CityID)]);
    21442299            Kind := mkOkHelp;
    21452300            HelpKind := hkImp;
    2146             HelpNo := i;
     2301            HelpNo := I;
    21472302            IconKind := mikImp;
    2148             IconIndex := i;
     2303            IconIndex := I;
    21492304            ShowModal;
    21502305          end;
     
    21542309    begin
    21552310      SoundMessageEx(Phrases.Lookup('COLDWAREND'), 'MSG_DEFAULT');
    2156       MyData.ColdWarStart := -ColdWarTurns - 1
     2311      MyData.ColdWarStart := -ColdWarTurns - 1;
    21572312    end;
    21582313
     
    21602315  end; // ClientMode<>cResume
    21612316  MyData.ToldAlive := MyRO.Alive;
    2162   move(MyRO.Wonder, MyData.ToldWonders, SizeOf(MyData.ToldWonders));
     2317  Move(MyRO.Wonder, MyData.ToldWonders, SizeOf(MyData.ToldWonders));
    21632318
    21642319  NewGovAvailable := -1;
     
    21842339          IconKind := mikBook;
    21852340          IconIndex := -1;
    2186           for i := 0 to nAdvBookIcon - 1 do
    2187             if AdvBookIcon[i].Adv = ad then
    2188               IconIndex := AdvBookIcon[i].Icon;
     2341          for I := 0 to nAdvBookIcon - 1 do
     2342            if AdvBookIcon[I].Adv = ad then
     2343              IconIndex := AdvBookIcon[I].Icon;
    21892344          ShowModal;
    21902345          MyData.ToldTech[ad] := MyRO.Tech[ad];
    2191           for i := gMonarchy to nGov - 1 do
    2192             if GovPreq[i] = ad then
    2193               NewGovAvailable := i;
     2346          for I := gMonarchy to nGov - 1 do
     2347            if GovPreq[I] = ad then
     2348              NewGovAvailable := I;
    21942349        end;
    21952350  end;
    21962351
    2197   ShowCityList := false;
     2352  ShowCityList := False;
    21982353  if ClientMode = cTurn then
    21992354  begin
     
    22012356      ChooseResearch;
    22022357
    2203     UpdatePanel := false;
     2358    UpdatePanel := False;
    22042359    if MyRO.Happened and phChangeGov <> 0 then
    22052360    begin
    22062361      ModalSelectDlg.ShowNewContent(wmModal, kGov);
    22072362      Play('NEWGOV');
    2208       Server(sSetGovernment, me, ModalSelectDlg.result, nil^);
     2363      Server(sSetGovernment, Me, ModalSelectDlg.Result, nil^);
    22092364      CityOptimizer_BeginOfTurn;
    2210       UpdatePanel := true;
     2365      UpdatePanel := True;
    22112366    end;
    22122367  end; // ClientMode=cTurn
    22132368
    2214   if not supervising and ((ClientMode = cTurn) or (ClientMode = cMovieTurn))
     2369  if not Supervising and ((ClientMode = cTurn) or (ClientMode = cMovieTurn))
    22152370  then
    22162371    for cix := 0 to MyRO.nCity - 1 do
     
    22222377  begin
    22232378    // tell what happened in cities
    2224     for WondersOnly := true downto false do
     2379    for WondersOnly := True downto False do
    22252380      for cix := 0 to MyRO.nCity - 1 do
    22262381        with MyCity[cix] do
     
    22332388              begin { tell about newly built wonder }
    22342389                OpenSound := 'WONDER_BUILT';
    2235                 s := Tribe[me].TPhrase('WONDERBUILTOWN');
     2390                S := Tribe[Me].TPhrase('WONDERBUILTOWN');
    22362391                MessgText :=
    2237                   Format(s, [Phrases.Lookup('IMPROVEMENTS',
     2392                  Format(S, [Phrases.Lookup('IMPROVEMENTS',
    22382393                  Project0 and cpIndex), CityName(ID)]);
    22392394                Kind := mkOkHelp;
     
    22442399                ShowModal;
    22452400              end;
    2246             if not supervising and (ClientMode = cTurn) then
     2401            if not Supervising and (ClientMode = cTurn) then
    22472402            begin
    2248               AllowCityScreen := true;
     2403              AllowCityScreen := True;
    22492404              if (Status and 7 <> 0) and
    22502405                (Project and (cpImp + cpIndex) = cpImp + imTrGoods) then
     
    22522407                begin
    22532408                  if AutoBuild(cix, MyData.ImpOrder[Status and 7 - 1]) then
    2254                     AllowCityScreen := false
     2409                    AllowCityScreen := False
    22552410                  else if Flags and chProduction <> 0 then
    22562411                    Flags := (Flags and not chProduction) or chAllImpsMade
     
    22802435                  CityDlg.ShowNewContent(wmModal, MyCity[cix].Loc,
    22812436                    Flags and CityRepMask);
    2282                   UpdatePanel := true;
     2437                  UpdatePanel := True;
    22832438                end;
    22842439              end
     
    22862441              begin
    22872442                if Flags and CityRepMask <> 0 then
    2288                   ShowCityList := true
     2443                  ShowCityList := True;
    22892444              end;
    22902445            end;
     
    23062461        begin
    23072462          Play('REVOLUTION');
    2308           Server(sRevolution, me, 0, nil^);
     2463          Server(sRevolution, Me, 0, nil^);
    23092464        end;
    23102465      end;
     
    23402495    DpiApplication.ProcessMessages;
    23412496
    2342     if not supervising then
     2497    if not Supervising then
    23432498      for uix := 0 to MyRO.nUn - 1 do
    23442499        with MyUn[uix] do
     
    23682523              begin // !!! Shinkansen
    23692524                MoveResult := eOK;
    2370                 ok := true;
    2371                 for i := 0 to MoveAdviceData.nStep - 1 do
     2525                ok := True;
     2526                for I := 0 to MoveAdviceData.nStep - 1 do
    23722527                begin
    2373                   Loc1 := dLoc(Loc, MoveAdviceData.dx[i],
    2374                     MoveAdviceData.dy[i]);
     2528                  Loc1 := dLoc(Loc, MoveAdviceData.dx[I],
     2529                    MoveAdviceData.dy[I]);
    23752530                  if (MyMap[Loc1] and (fCity or fOwned) = fCity)
    23762531                  // don't capture cities during auto move
     
    23782533                  // don't attack during auto move
    23792534                  begin
    2380                     ok := false;
     2535                    ok := False;
    23812536                    Break
    23822537                  end
     
    23852540                    if (Loc1 = MoveAdviceData.ToLoc) or
    23862541                      (MoveAdviceData.ToLoc = maNextCity) and
    2387                       (MyMap[dLoc(Loc, MoveAdviceData.dx[i],
    2388                       MoveAdviceData.dy[i])] and fCity <> 0) then
     2542                      (MyMap[dLoc(Loc, MoveAdviceData.dx[I],
     2543                      MoveAdviceData.dy[I])] and fCity <> 0) then
    23892544                      MoveOptions := muAutoNoWait
    23902545                    else
    23912546                      MoveOptions := 0;
    2392                     MoveResult := MoveUnit(MoveAdviceData.dx[i],
    2393                       MoveAdviceData.dy[i], MoveOptions);
     2547                    MoveResult := MoveUnit(MoveAdviceData.dx[I],
     2548                      MoveAdviceData.dy[I], MoveOptions);
    23942549                    if (MoveResult < rExecuted) or (MoveResult = eEnemySpotted)
    23952550                    then
    23962551                    begin
    2397                       ok := false;
     2552                      ok := False;
    23982553                      Break
    23992554                    end;
     
    24072562              begin
    24082563                MoveResult := eOK;
    2409                 Stop := true;
     2564                Stop := True;
    24102565              end;
    24112566
     
    24302585  end; // ClientMode=cTurn
    24312586
    2432   HaveStrategyAdvice := false;
    2433   // (GameMode<>cMovie) and not supervising
    2434   // and AdvisorDlg.HaveStrategyAdvice;
    2435   GoOnPhase := true;
    2436   if supervising or (GameMode = cMovie) then
     2587  HaveStrategyAdvice := False;
     2588  GoOnPhase := True;
     2589  if Supervising or (GameMode = cMovie) then
    24372590  begin
    24382591    SetTroopLoc(-1);
     
    24492602      SetUnFocus(-1)
    24502603    else
    2451       NextUnit(-1, false);
     2604      NextUnit(-1, False);
    24522605    if UnFocus < 0 then
    24532606    begin
     
    24662619end;
    24672620
    2468 procedure TMainScreen.Client(Command, NewPlayer: integer; var Data);
     2621procedure TMainScreen.Client(Command, NewPlayer: Integer; var Data);
    24692622var
    2470   i, j, p1, mix, ToLoc, AnimationSpeed, ShowMoveDomain, cix, ecix: integer;
     2623  I, J, p1, mix, ToLoc, AnimationSpeed, ShowMoveDomain, cix, ecix: Integer;
    24712624  Color: TColor;
    2472   Name, s: string;
     2625  Name, S: string;
    24732626  TribeInfo: TTribeInfo;
    24742627  mi: TModelInfo;
    2475   SkipTurn, IsAlpine, IsTreatyDeal: boolean;
     2628  SkipTurn, IsAlpine, IsTreatyDeal: Boolean;
    24762629begin
    24772630  case Command of
    24782631    cTurn, cResume, cContinue, cMovieTurn, scContact, scDipStart .. scDipBreak:
    24792632      begin
    2480         supervising := G.Difficulty[NewPlayer] = 0;
     2633        Supervising := G.Difficulty[NewPlayer] = 0;
    24812634        ArrangeMidPanel;
    24822635      end
     
    24842637  case Command of
    24852638    cDebugMessage:
    2486       LogDlg.Add(NewPlayer, G.RO[0].Turn, pchar(@Data));
     2639      LogDlg.Add(NewPlayer, G.RO[0].Turn, PChar(@Data));
    24872640
    24882641    cShowNego:
    24892642      with TShowNegoData(Data) do
    24902643      begin
    2491         s := Format('P%d to P%d: ', [pSender, pTarget]);
     2644        S := Format('P%d to P%d: ', [pSender, pTarget]);
    24922645        if (Action = scDipOffer) and (Offer.nDeliver + Offer.nCost > 0) then
    24932646        begin
    2494           s := s + 'Offer ';
    2495           for i := 0 to Offer.nDeliver + Offer.nCost - 1 do
     2647          S := S + 'Offer ';
     2648          for I := 0 to Offer.nDeliver + Offer.nCost - 1 do
    24962649          begin
    2497             if i = Offer.nDeliver then
    2498               s := s + ' for '
    2499             else if i > 0 then
    2500               s := s + '+';
    2501             case Offer.Price[i] and opMask of
     2650            if I = Offer.nDeliver then
     2651              S := S + ' for '
     2652            else if I > 0 then
     2653              S := S + '+';
     2654            case Offer.Price[I] and opMask of
    25022655              opChoose:
    2503                 s := s + 'Price of choice';
     2656                S := S + 'Price of choice';
    25042657              opCivilReport:
    2505                 s := s + 'State report';
     2658                S := S + 'State report';
    25062659              opMilReport:
    2507                 s := s + 'Military report';
     2660                S := S + 'Military report';
    25082661              opMap:
    2509                 s := s + 'Map';
     2662                S := S + 'Map';
    25102663              opTreaty:
    2511                 s := s + 'Treaty';
     2664                S := S + 'Treaty';
    25122665              opShipParts:
    2513                 s := s + 'Ship part';
     2666                S := S + 'Ship part';
    25142667              opMoney:
    2515                 s := s + IntToStr(Offer.Price[i] and $FFFFFF) + 'o';
     2668                S := S + IntToStr(Offer.Price[I] and $FFFFFF) + 'o';
    25162669              opTribute:
    2517                 s := s + IntToStr(Offer.Price[i] and $FFFFFF) + 'o tribute';
     2670                S := S + IntToStr(Offer.Price[I] and $FFFFFF) + 'o tribute';
    25182671              opTech:
    2519                 s := s + Phrases.Lookup('ADVANCES', Offer.Price[i] and $FFFFFF);
     2672                S := S + Phrases.Lookup('ADVANCES', Offer.Price[I] and $FFFFFF);
    25202673              opAllTech:
    2521                 s := s + 'All advances';
     2674                S := S + 'All advances';
    25222675              opModel:
    2523                 s := s + Tribe[pSender].ModelName[Offer.Price[i] and $FFFFFF];
     2676                S := S + Tribe[pSender].ModelName[Offer.Price[I] and $FFFFFF];
    25242677              opAllModel:
    2525                 s := s + 'All models';
     2678                S := S + 'All models';
    25262679            end;
    25272680          end;
    2528           LogDlg.Add(NewPlayer, G.RO[0].Turn, pchar(s));
     2681          LogDlg.Add(NewPlayer, G.RO[0].Turn, PChar(S));
    25292682        end
    25302683        else if Action = scDipAccept then
    25312684        begin
    2532           s := s + '--- ACCEPTED! ---';
    2533           LogDlg.Add(NewPlayer, G.RO[0].Turn, pchar(s));
     2685          S := S + '--- ACCEPTED! ---';
     2686          LogDlg.Add(NewPlayer, G.RO[0].Turn, PChar(S));
    25342687        end;
    25352688      end;
     
    25382691      begin
    25392692        Server := TInitModuleData(Data).Server;
    2540         // AdvisorDlg.Init;
    25412693        InitModule;
    25422694        TInitModuleData(Data).DataSize := SizeOf(TPersistentData);
     
    25522704          MainTexture.Age := -1;
    25532705        Tribes.Init;
    2554         HelpDlg.UserLeft := (DpiScreen.width - HelpDlg.width) div 2;
    2555         HelpDlg.UserTop := (DpiScreen.height - HelpDlg.height) div 2;
     2706        HelpDlg.UserLeft := (DpiScreen.Width - HelpDlg.Width) div 2;
     2707        HelpDlg.UserTop := (DpiScreen.Height - HelpDlg.Height) div 2;
    25562708        HelpDlg.Difficulty := 0;
    25572709        if Command = cStartCredits then
    2558           HelpDlg.ShowNewContent(wmModal, hkMisc, miscCredits)
     2710          HelpDlg.ShowNewContent(wmModal, hkMisc, Integer(miscCredits))
    25592711        else
    2560           HelpDlg.ShowNewContent(wmModal, hkMisc, miscMain);
     2712          HelpDlg.ShowNewContent(wmModal, hkMisc, Integer(miscMain));
    25612713        Tribes.Done;
    25622714      end;
     
    25642716    cNewGame, cLoadGame, cMovie, cNewMap:
    25652717      begin
    2566         { if (Command=cNewGame) or (Command=cLoadGame) then
    2567           AdvisorDlg.NewGame(Data); }
    25682718        GenerateNames := mNames.Checked;
    2569         GameOK := true;
     2719        GameOK := True;
    25702720        G := TNewGameData(Data);
    2571         me := -1;
     2721        Me := -1;
    25722722        pLogo := -1;
    25732723        ClientMode := -1;
    25742724        SetMapOptions;
    25752725        MainMap.pDebugMap := -1;
    2576         idle := false;
     2726        Idle := False;
    25772727        FillChar(Jump, SizeOf(Jump), 0);
    25782728        if StartRunning then
     
    25972747              ToldContact := 0;
    25982748              ToldOwnCredibility := InitialCredibility;
    2599               for i := 0 to nPl - 1 do
    2600                 if G.Difficulty[i] > 0 then
    2601                   inc(ToldAlive, 1 shl i);
     2749              for I := 0 to nPl - 1 do
     2750                if G.Difficulty[I] > 0 then
     2751                  Inc(ToldAlive, 1 shl I);
    26022752              PeaceEvaHappened := 0;
    2603               for i := 0 to nWonder - 1 do
    2604                 with ToldWonders[i] do
     2753              for I := 0 to nWonder - 1 do
     2754                with ToldWonders[I] do
    26052755                begin
    26062756                  CityID := -1;
    2607                   EffectiveOwner := -1
     2757                  EffectiveOwner := -1;
    26082758                end;
    26092759              FillChar(ToldTech, SizeOf(ToldTech), Byte(tsNA));
     
    26122762            end;
    26132763
    2614         // arrange dialogs
    2615         ListDlg.UserLeft := 8;
    2616         ListDlg.UserTop := TopBarHeight + 8;
    2617         HelpDlg.UserLeft := DpiScreen.width - HelpDlg.width - 8;
    2618         HelpDlg.UserTop := TopBarHeight + 8;
    2619         UnitStatDlg.UserLeft := 397;
    2620         UnitStatDlg.UserTop := TopBarHeight + 64;
    2621         DiaDlg.UserLeft := (DpiScreen.width - DiaDlg.width) div 2;
    2622         DiaDlg.UserTop := (DpiScreen.height - DiaDlg.height) div 2;
    2623         NatStatDlg.UserLeft := DpiScreen.width - NatStatDlg.width - 8;
    2624         NatStatDlg.UserTop := DpiScreen.height - PanelHeight -
    2625           NatStatDlg.height - 8;
    2626         if NatStatDlg.UserTop < 8 then
    2627           NatStatDlg.UserTop := 8;
     2764        ArrangeDialogs;
    26282765
    26292766        Age := 0;
    26302767        MovieSpeed := 1;
    2631         LogDlg.mSlot.Visible := true;
    2632         LogDlg.Host := self;
    2633         HelpDlg.ClearHistory;
    2634         CityDlg.Reset;
     2768        LogDlg.mSlot.Visible := True;
     2769        LogDlg.Host := Self;
     2770        if Assigned(FHelpDlg) then FHelpDlg.ClearHistory;
     2771        if Assigned(FCityDlg) then FCityDlg.Reset;
    26352772
    26362773        MiniMap.Size := Point(G.lx, G.ly);
    2637         for i := 0 to nPl - 1 do
     2774        for I := 0 to nPl - 1 do
    26382775        begin
    2639           Tribe[i] := nil;
    2640           TribeOriginal[i] := false;
     2776          Tribe[I] := nil;
     2777          TribeOriginal[I] := False;
    26412778        end;
    26422779        ToldSlavery := -1;
    2643         RepaintOnResize := false;
    2644         Closable := false;
    2645         FirstMovieTurn := true;
     2780        RepaintOnResize := False;
     2781        Closable := False;
     2782        FirstMovieTurn := True;
    26462783
    26472784        MenuArea.Visible := GameMode <> cMovie;
     
    26542791      if NewPlayer = 0 then
    26552792      begin
    2656         i := 0;
     2793        I := 0;
    26572794        for p1 := 0 to nPl - 1 do
    26582795          if (G.Difficulty[p1] > 0) and (Tribe[p1] = nil) then
    2659             inc(i);
    2660         if i > UnusedTribeFiles.Count then
     2796            Inc(I);
     2797        if I > UnusedTribeFiles.Count then
    26612798        begin
    2662           GameOK := false;
     2799          GameOK := False;
    26632800          SimpleMessage(Phrases.Lookup('TOOFEWTRIBES'));
    26642801        end
     
    26712808              TribeInfo.trix := p1;
    26722809              TribeNames.Clear;
    2673               for j := 0 to UnusedTribeFiles.Count - 1 do
     2810              for J := 0 to UnusedTribeFiles.Count - 1 do
    26742811              begin
    2675                 GetTribeInfo(UnusedTribeFiles[j], Name, Color);
     2812                GetTribeInfo(UnusedTribeFiles[J], Name, Color);
    26762813                TribeNames.AddObject(Name, TObject(Color));
    26772814              end;
    2678               assert(TribeNames.Count > 0);
     2815              Assert(TribeNames.Count > 0);
    26792816              ModalSelectDlg.ShowNewContent(wmModal, kTribe);
    26802817              DpiApplication.ProcessMessages;
    2681               TribeInfo.FileName := UnusedTribeFiles[ModalSelectDlg.result];
    2682               UnusedTribeFiles.Delete(ModalSelectDlg.result);
     2818              TribeInfo.FileName := UnusedTribeFiles[ModalSelectDlg.Result];
     2819              UnusedTribeFiles.Delete(ModalSelectDlg.Result);
    26832820
    26842821              if GameMode = cLoadGame then
    2685                 CreateTribe(TribeInfo.trix, TribeInfo.FileName, false)
     2822                CreateTribe(TribeInfo.trix, TribeInfo.FileName, False)
    26862823              else
    2687                 Server(cSetTribe + (Length(TribeInfo.FileName) + 1 + 7) div 4,
     2824                Server(CommandWithData(cSetTribe, TribeInfo.GetCommandDataSize),
    26882825                  0, 0, TribeInfo);
    26892826            end;
     
    26932830            then
    26942831            begin // autoselect enemy tribes
    2695               j := ChooseUnusedTribe;
    2696               TribeInfo.FileName := UnusedTribeFiles[j];
    2697               UnusedTribeFiles.Delete(j);
     2832              J := ChooseUnusedTribe;
     2833              TribeInfo.FileName := UnusedTribeFiles[J];
     2834              UnusedTribeFiles.Delete(J);
    26982835              TribeInfo.trix := p1;
    26992836              if GameMode = cLoadGame then
    2700                 CreateTribe(TribeInfo.trix, TribeInfo.FileName, false)
     2837                CreateTribe(TribeInfo.trix, TribeInfo.FileName, False)
    27012838              else
    2702                 Server(cSetTribe + (Length(TribeInfo.FileName) + 1 + 7) div 4,
     2839                Server(CommandWithData(cSetTribe, TribeInfo.GetCommandDataSize),
    27032840                  0, 0, TribeInfo);
    27042841            end;
     
    27142851        SaveSettings;
    27152852        CityDlg.CloseAction := None;
    2716         for i := 0 to DpiScreen.FormCount - 1 do
    2717           if DpiScreen.Forms[i].Visible and (DpiScreen.Forms[i] is TBufferedDrawDlg)
    2718           then
    2719             DpiScreen.Forms[i].Close;
     2853        ApplyToVisibleForms(faClose);
    27202854        if LogDlg.Visible then
    27212855          LogDlg.Close;
    27222856        LogDlg.List.Clear;
    2723         StartRunning := not idle and (Jump[0] > 0); // AI called Reload
    2724         me := -1;
    2725         idle := false;
     2857        StartRunning := not Idle and (Jump[0] > 0); // AI called Reload
     2858        Me := -1;
     2859        Idle := False;
    27262860        ClientMode := -1;
    2727         UnitInfoBtn.Visible := false;
    2728         UnitBtn.Visible := false;
    2729         TerrainBtn.Visible := false;
    2730         MovieSpeed1Btn.Visible := false;
    2731         MovieSpeed2Btn.Visible := false;
    2732         MovieSpeed3Btn.Visible := false;
    2733         MovieSpeed4Btn.Visible := false;
    2734         EOT.Visible := false;
    2735         for i := 0 to ControlCount - 1 do
    2736           if Controls[i] is TButtonC then
    2737             Controls[i].Visible := false;
     2861        UnitInfoBtn.Visible := False;
     2862        UnitBtn.Visible := False;
     2863        TerrainBtn.Visible := False;
     2864        MovieSpeed1Btn.Visible := False;
     2865        MovieSpeed2Btn.Visible := False;
     2866        MovieSpeed3Btn.Visible := False;
     2867        MovieSpeed4Btn.Visible := False;
     2868        EOT.Visible := False;
     2869        for I := 0 to ControlCount - 1 do
     2870          if Controls[I] is TButtonC then
     2871            Controls[I].Visible := False;
    27382872        sb.Init(0, 1);
    27392873        for p1 := 0 to nPl - 1 do
     
    27412875            FreeAndNil(Tribe[p1]);
    27422876        Tribes.Done;
    2743         RepaintOnResize := false;
    2744         Closable := true;
     2877        RepaintOnResize := False;
     2878        Closable := True;
    27452879        Close;
    2746         { if (GameMode=cNewGame) or (GameMode=cLoadGame) then
    2747           AdvisorDlg.BreakGame; }
    27482880      end;
    27492881
     
    27652897        Show;
    27662898        Update;
    2767         RepaintOnResize := true;
     2899        RepaintOnResize := True;
    27682900        xw := 0;
    27692901        yw := ywcenter;
    2770         if not StayOnTop_Ensured then
    2771         begin
    2772           StayOnTop_Ensured := true;
    2773           CityDlg.StayOnTop_Workaround;
    2774           CityTypeDlg.StayOnTop_Workaround;
    2775           DiaDlg.StayOnTop_Workaround;
    2776           DraftDlg.StayOnTop_Workaround;
    2777           EnhanceDlg.StayOnTop_Workaround;
    2778           HelpDlg.StayOnTop_Workaround;
    2779           NatStatDlg.StayOnTop_Workaround;
    2780           NegoDlg.StayOnTop_Workaround;
    2781           ModalSelectDlg.StayOnTop_Workaround;
    2782           ListDlg.StayOnTop_Workaround;
    2783           UnitStatDlg.StayOnTop_Workaround;
    2784           WondersDlg.StayOnTop_Workaround;
    2785           RatesDlg.StayOnTop_Workaround;
    2786         end;
    27872902      end;
    27882903
    27892904    cShowTurnChange:
    27902905      begin
    2791         if integer(Data) >= 0 then
     2906        if Integer(Data) >= 0 then
    27922907        begin
    2793           pLogo := integer(Data);
     2908          pLogo := Integer(Data);
    27942909          if G.RO[pLogo] = nil then
    27952910          begin
    27962911            if AILogo[pLogo] <> nil then
    2797               DpiBitCanvas(Canvas, (xRightPanel + 10) - (16 + 64),
     2912              DpiBitBltCanvas(Canvas, (xRightPanel + 10) - (16 + 64),
    27982913                ClientHeight - PanelHeight, 64, 64, AILogo[pLogo].Canvas,
    27992914                0, 0);
    2800           end
    2801         end
     2915          end;
     2916        end;
    28022917      end;
    28032918
     
    28182933              ItsMeAgain(p1);
    28192934              for mix := 0 to MyRO.nModel - 1 do
    2820                 if not Assigned(Tribe[me].ModelPicture[mix].HGr) then
    2821                   InitMyModel(mix, true);
     2935                if not Assigned(Tribe[Me].ModelPicture[mix].HGr) then
     2936                  InitMyModel(mix, True);
    28222937            end;
    2823           me := -1;
     2938          Me := -1;
    28242939        end;
    28252940
     
    28302945            Jump[pTurn] := 0
    28312946          else
    2832             dec(Jump[pTurn]);
     2947            Dec(Jump[pTurn]);
    28332948        SkipTurn := Jump[pTurn] > 0;
    28342949        if SkipTurn then
     
    28392954          MiniMapPaint;
    28402955          InitAllEnemyModels; // necessary for correct replay
    2841           if not EndTurn(true) then
    2842             SkipTurn := false;
     2956          if not EndTurn(True) then
     2957            SkipTurn := False;
    28432958        end;
    28442959        if not SkipTurn then
     
    28472962            NegoDlg.Visible then
    28482963            NegoDlg.Close;
    2849           skipped := false; // always show my moves during my turn
    2850           idle := true;
     2964          Skipped := False; // always show my moves during my turn
     2965          Idle := True;
    28512966          InitTurn(NewPlayer);
    2852           DipMem[me].pContact := -1;
    2853           (* if (me=0) and (MyRO.Alive and (1 shl me)=0)} then
     2967          DipMem[Me].pContact := -1;
     2968          (* if (Me=0) and (MyRO.Alive and (1 shl Me)=0)} then
    28542969            begin
    28552970            if SimpleQuery(Phrases.Lookup('RESIGN'))=mrIgnore then
    2856             Server(sResign,me,0,nil^)
    2857             else Server(sBreak,me,0,nil^)
     2971            Server(sResign,Me,0,nil^)
     2972            else Server(sBreak,Me,0,nil^)
    28582973            end
    28592974            else Play('TURNSTART'); *)
     
    28662981        pTurn := NewPlayer;
    28672982        pLogo := -1;
    2868         skipped := false; // always show my moves during my turn
    2869         idle := true;
     2983        Skipped := False; // always show my moves during my turn
     2984        Idle := True;
    28702985        if FirstMovieTurn then
    28712986        begin
    28722987          CheckMovieSpeedBtnState;
    2873           FirstMovieTurn := false;
     2988          FirstMovieTurn := False;
    28742989        end;
    28752990        InitTurn(NewPlayer);
     
    28883003        pTurn := -1;
    28893004        pLogo := -1;
    2890         MapValid := false;
     3005        MapValid := False;
    28913006        ClientMode := -1;
    2892         idle := false;
    2893         skipped := false;
     3007        Idle := False;
     3008        Skipped := False;
    28943009      end;
    28953010
     
    29013016        ItsMeAgain(0);
    29023017        MyData := nil;
    2903         UnitInfoBtn.Visible := false;
    2904         UnitBtn.Visible := false;
    2905         TerrainBtn.Visible := false;
    2906         MovieSpeed1Btn.Visible := false;
    2907         MovieSpeed2Btn.Visible := false;
    2908         MovieSpeed3Btn.Visible := false;
    2909         MovieSpeed4Btn.Visible := false;
    2910         EOT.Visible := false;
     3018        UnitInfoBtn.Visible := False;
     3019        UnitBtn.Visible := False;
     3020        TerrainBtn.Visible := False;
     3021        MovieSpeed1Btn.Visible := False;
     3022        MovieSpeed2Btn.Visible := False;
     3023        MovieSpeed3Btn.Visible := False;
     3024        MovieSpeed4Btn.Visible := False;
     3025        EOT.Visible := False;
    29113026        HelpDlg.Difficulty := 0;
    29123027        BrushType := fGrass;
    29133028        BrushLoc := -1;
    2914         Edited := false;
     3029        Edited := False;
    29153030        UnFocus := -1;
    29163031        MarkCityLoc := -1;
    2917         Tracking := false;
    2918         TurnComplete := false;
    2919         MapValid := false;
     3032        Tracking := False;
     3033        TurnComplete := False;
     3034        MapValid := False;
    29203035        FormResize(nil); // calculate geometrics and paint all
    29213036        SetTroopLoc(-1);
    2922         idle := true;
     3037        Idle := True;
    29233038      end;
    29243039
     
    29303045    scContact:
    29313046      begin
    2932         DipMem[NewPlayer].pContact := integer(Data);
     3047        DipMem[NewPlayer].pContact := Integer(Data);
    29333048        if Jump[NewPlayer] > 0 then
    29343049          DipCall(scReject)
     
    29373052          ClientMode := Command;
    29383053          InitTurn(NewPlayer);
    2939           MyData.ToldContact := MyData.ToldContact or (1 shl integer(Data));
     3054          MyData.ToldContact := MyData.ToldContact or (1 shl Integer(Data));
    29403055          // don't tell about new nation when already contacted by them
    29413056          with MessgExDlg do
    29423057          begin
    2943             OpenSound := 'CONTACT_' + char(48 + MyRO.EnemyReport[integer(Data)
     3058            OpenSound := 'CONTACT_' + char(48 + MyRO.EnemyReport[Integer(Data)
    29443059              ].Attitude);
    2945             MessgText := Tribe[integer(Data)].TPhrase('FRCONTACT');
     3060            MessgText := Tribe[Integer(Data)].TPhrase('FRCONTACT');
    29463061            Kind := mkYesNo;
    29473062            IconKind := mikTribe;
    2948             IconIndex := integer(Data);
     3063            IconIndex := Integer(Data);
    29493064            ShowModal;
    29503065            if ModalResult = mrOK then
    29513066            begin
    29523067              NegoDlg.Respond;
    2953               DipMem[me].DeliveredPrices := [];
    2954               DipMem[me].ReceivedPrices := [];
     3068              DipMem[Me].DeliveredPrices := [];
     3069              DipMem[Me].ReceivedPrices := [];
    29553070              DipCall(scDipStart);
    29563071            end
     
    29803095        else if Command = scDipAccept then
    29813096        begin // remember delivered and received prices
    2982           for i := 0 to DipMem[me].SentOffer.nDeliver - 1 do
    2983             include(DipMem[me].DeliveredPrices,
    2984               DipMem[me].SentOffer.Price[i] shr 24);
    2985           for i := 0 to DipMem[me].SentOffer.nCost - 1 do
    2986             include(DipMem[me].ReceivedPrices,
    2987               DipMem[me].SentOffer.Price[DipMem[me].SentOffer.nDeliver +
    2988               i] shr 24);
    2989           IsTreatyDeal := false;
    2990           for i := 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do
    2991             if DipMem[me].SentOffer.Price[i] and opMask = opTreaty then
    2992               IsTreatyDeal := true;
     3097          for I := 0 to DipMem[Me].SentOffer.nDeliver - 1 do
     3098            Include(DipMem[Me].DeliveredPrices,
     3099              DipMem[Me].SentOffer.Price[I] shr 24);
     3100          for I := 0 to DipMem[Me].SentOffer.nCost - 1 do
     3101            Include(DipMem[Me].ReceivedPrices,
     3102              DipMem[Me].SentOffer.Price[DipMem[Me].SentOffer.nDeliver +
     3103              I] shr 24);
     3104          IsTreatyDeal := False;
     3105          for I := 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do
     3106            if DipMem[Me].SentOffer.Price[I] and opMask = opTreaty then
     3107              IsTreatyDeal := True;
    29933108          if IsTreatyDeal then
    29943109            Play('NEWTREATY')
     
    29973112        end;
    29983113        NegoDlg.Start;
    2999         idle := true;
     3114        Idle := True;
    30003115      end;
    30013116
     
    30033118      if not IsMultiPlayerGame then
    30043119      begin
    3005         case G.RO[NewPlayer].Treaty[integer(Data)] of
     3120        case G.RO[NewPlayer].Treaty[Integer(Data)] of
    30063121          trPeace:
    3007             s := Tribe[integer(Data)].TPhrase('FRCANCELBYREJECT_PEACE');
     3122            S := Tribe[Integer(Data)].TPhrase('FRCANCELBYREJECT_PEACE');
    30083123          trFriendlyContact:
    3009             s := Tribe[integer(Data)].TPhrase('FRCANCELBYREJECT_FRIENDLY');
     3124            S := Tribe[Integer(Data)].TPhrase('FRCANCELBYREJECT_FRIENDLY');
    30103125          trAlliance:
    3011             s := Tribe[integer(Data)].TPhrase('FRCANCELBYREJECT_ALLIANCE');
     3126            S := Tribe[Integer(Data)].TPhrase('FRCANCELBYREJECT_ALLIANCE');
    30123127        end;
    3013         TribeMessage(integer(Data), s, 'CANCELTREATY');
     3128        TribeMessage(Integer(Data), S, 'CANCELTREATY');
    30143129      end;
    30153130
    30163131    cShowCancelTreatyByAlliance:
    3017       if idle and (NewPlayer = me) then
    3018         TribeMessage(integer(Data), Tribe[integer(Data)
     3132      if Idle and (NewPlayer = Me) then
     3133        TribeMessage(Integer(Data), Tribe[Integer(Data)
    30193134          ].TPhrase('FRENEMYALLIANCE'), 'CANCELTREATY');
    30203135
    30213136    cShowSupportAllianceAgainst:
    30223137      if not IsMultiPlayerGame and (Jump[0] = 0) then
    3023         TribeMessage(integer(Data) and $F, Tribe[integer(Data) and $F]
    3024           .TPhrase('FRMYALLIANCE1') + ' ' + Tribe[integer(Data) shr 4]
     3138        TribeMessage(Integer(Data) and $F, Tribe[Integer(Data) and $F]
     3139          .TPhrase('FRMYALLIANCE1') + ' ' + Tribe[Integer(Data) shr 4]
    30253140          .TPhrase('FRMYALLIANCE2'), 'CANCELTREATY');
    30263141
    30273142    cShowPeaceViolation:
    30283143      if not IsMultiPlayerGame and (Jump[0] = 0) then
    3029         TribeMessage(integer(Data),
    3030           Format(Tribe[integer(Data)].TPhrase('EVIOLATION'),
     3144        TribeMessage(Integer(Data),
     3145          Format(Tribe[Integer(Data)].TPhrase('EVIOLATION'),
    30313146          [TurnToString(MyRO.Turn + PeaceEvaTurns - 1)]), 'MSG_WITHDRAW');
    30323147
     
    30353150
    30363151    cShowUnitChanged, cShowCityChanged, cShowAfterMove, cShowAfterAttack:
    3037       if (idle and (NewPlayer = me) or not idle and not skipped) and
     3152      if (Idle and (NewPlayer = Me) or not Idle and not skipped) and
    30383153        not((GameMode = cMovie) and (MovieSpeed = 4)) then
    30393154      begin
    3040         assert(NewPlayer = me);
    3041         if not idle or (GameMode = cMovie) then
     3155        Assert(NewPlayer = Me);
     3156        if not Idle or (GameMode = cMovie) then
    30423157          DpiApplication.ProcessMessages;
    30433158        if Command = cShowCityChanged then
    30443159        begin
    3045           CurrentMoveInfo.DoShow := false;
    3046           if idle then
    3047             CurrentMoveInfo.DoShow := true
     3160          CurrentMoveInfo.DoShow := False;
     3161          if Idle then
     3162            CurrentMoveInfo.DoShow := True
    30483163          else if CurrentMoveInfo.IsAlly then
    30493164            CurrentMoveInfo.DoShow := not mAlNoMoves.Checked
     
    30533168        else if Command = cShowUnitChanged then
    30543169        begin
    3055           CurrentMoveInfo.DoShow := false;
    3056           if idle then
     3170          CurrentMoveInfo.DoShow := False;
     3171          if Idle then
    30573172            CurrentMoveInfo.DoShow := not mEffectiveMovesOnly.Checked
    30583173          else if CurrentMoveInfo.IsAlly then
     
    30683183        begin
    30693184          if Command = cShowCityChanged then
    3070             MapValid := false;
    3071           FocusOnLoc(integer(Data), flImmUpdate);
     3185            MapValid := False;
     3186          FocusOnLoc(Integer(Data), flImmUpdate);
    30723187          // OldUnFocus:=UnFocus;
    30733188          // UnFocus:=-1;
    30743189          if Command = cShowAfterMove then
    3075             PaintLoc(integer(Data), CurrentMoveInfo.AfterMovePaintRadius)
     3190            PaintLoc(Integer(Data), CurrentMoveInfo.AfterMovePaintRadius)
    30763191            // show discovered areas
    30773192          else
    3078             PaintLoc(integer(Data), 1);
     3193            PaintLoc(Integer(Data), 1);
    30793194          // UnFocus:=OldUnFocus;
    30803195          if (Command = cShowAfterAttack) and
     
    30863201            Update; // remove message box from screen
    30873202          end
    3088           else if not idle then
     3203          else if not Idle then
    30893204            if Command = cShowCityChanged then
    30903205              Sleep(MoveTime * WaitAfterShowMove div 16)
    30913206            else if (Command = cShowUnitChanged) and
    3092               (MyMap[integer(Data)] and fUnit <> 0) then
     3207              (MyMap[Integer(Data)] and fUnit <> 0) then
    30933208              Sleep(MoveTime * WaitAfterShowMove div 32)
    30943209        end // if CurrentMoveInfo.DoShow
    30953210        else
    3096           MapValid := false;
     3211          MapValid := False;
    30973212      end;
    30983213
    30993214    cShowMoving, cShowCapturing:
    3100       if (idle and (NewPlayer = me) or not idle and not skipped and
     3215      if (Idle and (NewPlayer = Me) or not Idle and not skipped and
    31013216        (TShowMove(Data).emix <> $FFFF)) and
    31023217        not((GameMode = cMovie) and (MovieSpeed = 4)) then
    31033218      begin
    3104         assert(NewPlayer = me);
    3105         if not idle or (GameMode = cMovie) then
     3219        Assert(NewPlayer = Me);
     3220        if not Idle or (GameMode = cMovie) then
    31063221          DpiApplication.ProcessMessages;
    31073222        with TShowMove(Data) do
    31083223        begin
    3109           CurrentMoveInfo.DoShow := false;
    3110           if not idle and (not Assigned(Tribe[Owner].ModelPicture[mix].HGr)) then
     3224          CurrentMoveInfo.DoShow := False;
     3225          if not Idle and (not Assigned(Tribe[Owner].ModelPicture[mix].HGr)) then
    31113226            InitEnemyModel(emix);
    31123227
    31133228          ToLoc := dLoc(FromLoc, dx, dy);
    3114           if idle then
     3229          if Idle then
    31153230          begin // own unit -- make discovered land visible
    3116             assert(Owner = me); // no foreign moves during my turn!
     3231            Assert(Owner = Me); // no foreign moves during my turn!
    31173232            CurrentMoveInfo.DoShow := not mEffectiveMovesOnly.Checked or
    31183233              (Command = cShowCapturing);
     
    31473262                else
    31483263                  CurrentMoveInfo.AfterMovePaintRadius := 1;
    3149                 if (MyRO.Wonder[woShinkansen].EffectiveOwner = me) and
     3264                if (MyRO.Wonder[woShinkansen].EffectiveOwner = Me) and
    31503265                  (Domain = dGround) and
    31513266                  (MyMap[FromLoc] and (fRR or fCity) <> 0) and
     
    31623277            CurrentMoveInfo.IsAlly := MyRO.Treaty[Owner] = trAlliance;
    31633278            if GameMode = cMovie then
    3164               CurrentMoveInfo.DoShow := true
     3279              CurrentMoveInfo.DoShow := True
    31653280            else if CurrentMoveInfo.IsAlly then
    31663281              CurrentMoveInfo.DoShow := not mAlNoMoves.Checked and
     
    31783293                  cix := MyRO.nCity - 1;
    31793294                  while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do
    3180                     dec(cix);
    3181                   s := CityName(MyCity[cix].ID);
     3295                    Dec(cix);
     3296                  S := CityName(MyCity[cix].ID);
    31823297                end
    31833298                else
     
    31853300                  ecix := MyRO.nEnemyCity - 1;
    31863301                  while (ecix >= 0) and (MyRO.EnemyCity[ecix].Loc <> ToLoc) do
    3187                     dec(ecix);
    3188                   s := CityName(MyRO.EnemyCity[ecix].ID);
     3302                    Dec(ecix);
     3303                  S := CityName(MyRO.EnemyCity[ecix].ID);
    31893304                end;
    31903305                TribeMessage(Owner, Format(Tribe[Owner].TPhrase('CAPTURE'),
    3191                   [s]), '');
     3306                  [S]), '');
    31923307                Update; // remove message box from screen
    31933308              end;
     
    32743389          end // if CurrentMoveInfo.DoShow
    32753390          else
    3276             MapValid := false;
     3391            MapValid := False;
    32773392        end;
    32783393      end;
    32793394
    32803395    cShowAttacking:
    3281       if (idle and (NewPlayer = me) or not idle and not skipped and
     3396      if (Idle and (NewPlayer = Me) or not Idle and not skipped and
    32823397        (TShowMove(Data).emix <> $FFFF)) and
    32833398        not((GameMode = cMovie) and (MovieSpeed = 4)) then
    32843399      begin
    3285         assert(NewPlayer = me);
    3286         if not idle or (GameMode = cMovie) then
     3400        Assert(NewPlayer = Me);
     3401        if not Idle or (GameMode = cMovie) then
    32873402          DpiApplication.ProcessMessages;
    32883403        with TShowMove(Data) do
    32893404        begin
    32903405          CurrentMoveInfo.AfterAttackExpeller := -1;
    3291           CurrentMoveInfo.DoShow := false;
    3292           if idle then
    3293             CurrentMoveInfo.DoShow := true // own unit -- always show attacks
     3406          CurrentMoveInfo.DoShow := False;
     3407          if Idle then
     3408            CurrentMoveInfo.DoShow := True // own unit -- always show attacks
    32943409          else
    32953410          begin
     
    33113426              cix := MyRO.nCity - 1;
    33123427              while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do
    3313                 dec(cix);
     3428                Dec(cix);
    33143429              if MyCity[cix].Status and csToldBombard = 0 then
    33153430              begin
    3316                 if not supervising then
     3431                if not Supervising then
    33173432                  MyCity[cix].Status := MyCity[cix].Status or csToldBombard;
    3318                 s := CityName(MyCity[cix].ID);
     3433                S := CityName(MyCity[cix].ID);
    33193434                SoundMessageEx(Format(Tribe[Owner].TPhrase('BOMBARD'),
    3320                   [s]), '');
     3435                  [S]), '');
    33213436                Update; // remove message box from screen
    33223437              end;
     
    33273442            if Flags and umExpelling <> 0 then
    33283443              Play('MOVE_EXPEL')
    3329             else if Owner = me then
     3444            else if Owner = Me then
    33303445            begin
    3331               MakeModelInfo(me, mix, MyModel[mix], mi);
     3446              MakeModelInfo(Me, mix, MyModel[mix], mi);
    33323447              Play(AttackSound(ModelCode(mi)));
    33333448            end
     
    33543469              MoveOnScreen(TShowMove(Data), 10, 0, 16);
    33553470            end
    3356             else if not idle then
     3471            else if not Idle then
    33573472              Sleep(MoveTime div 2);
    33583473            MainMap.AttackEnd;
    33593474          end // if CurrentMoveInfo.DoShow
    33603475          else
    3361             MapValid := false;
     3476            MapValid := False;
    33623477        end;
    33633478      end;
     
    33683483      else
    33693484      begin
    3370         s := Phrases.Lookup('FOREIGNINFO');
     3485        S := Phrases.Lookup('FOREIGNINFO');
    33713486        for p1 := 0 to nPl - 1 do
    33723487          if 3 shl (p1 * 2) and Cardinal(Data) <> 0 then
    3373             s := s + '\' + Tribe[p1].TPhrase('SHORTNAME');
    3374         SoundMessageEx(s, '');
     3488            S := S + '\' + Tribe[p1].TPhrase('SHORTNAME');
     3489        SoundMessageEx(S, '');
    33753490      end;
    33763491
     
    33843499        begin
    33853500          MessgText := Format(Phrases.Lookup('GRLIB_GENERAL'),
    3386             [Phrases.Lookup('ADVANCES', integer(Data))]);
     3501            [Phrases.Lookup('ADVANCES', Integer(Data))]);
    33873502          OpenSound := 'NEWADVANCE_GRLIB';
    33883503          Kind := mkOk;
     
    33943509    cRefreshDebugMap:
    33953510      begin
    3396         if integer(Data) = MainMap.pDebugMap then
     3511        if Integer(Data) = MainMap.pDebugMap then
    33973512        begin
    3398           MapValid := false;
     3513          MapValid := False;
    33993514          MainOffscreenPaint;
    34003515          Update;
    3401         end
     3516        end;
    34023517      end;
    34033518
    34043519  else
    34053520    if Command >= cClientEx then
    3406       case Command and $FFF0 of
    3407 
     3521      case Command and (not Integer(CommandDataElementCountMask)) of
    34083522        cSetTribe:
    3409           with TTribeInfo(Data) do
    3410           begin
    3411             i := UnusedTribeFiles.Count - 1;
    3412             while (i >= 0) and
    3413               (AnsiCompareFileName(UnusedTribeFiles[i], FileName) <> 0) do
    3414               dec(i);
    3415             if i >= 0 then
    3416               UnusedTribeFiles.Delete(i);
    3417             CreateTribe(trix, FileName, true);
     3523          with TTribeInfo(Data) do begin
     3524            I := UnusedTribeFiles.Count - 1;
     3525            while (I >= 0) and
     3526              (AnsiCompareFileName(UnusedTribeFiles[I], FileName) <> 0) do
     3527              Dec(I);
     3528            if I >= 0 then
     3529              UnusedTribeFiles.Delete(I);
     3530            CreateTribe(trix, FileName, True);
    34183531          end;
    3419 
    3420         cSetNewModelPicture, cSetModelPicture:
     3532        cSetNewModelPicture:
    34213533          if TribeOriginal[TModelPictureInfo(Data).trix] then
    34223534            Tribe[TModelPictureInfo(Data).trix].SetModelPicture
    3423               (TModelPictureInfo(Data), Command and
    3424               $FFF0 = cSetNewModelPicture);
    3425 
    3426         cSetSlaveIndex and $FFF0:
    3427           Tribe[integer(Data) shr 16].mixSlaves := integer(Data) and $FFFF;
    3428 
     3535              (TModelPictureInfo(Data), True);
     3536        cSetModelPicture:
     3537          if TribeOriginal[TModelPictureInfo(Data).trix] then
     3538            Tribe[TModelPictureInfo(Data).trix].SetModelPicture
     3539              (TModelPictureInfo(Data), False);
     3540        cSetSlaveIndex:
     3541          Tribe[Integer(Data) shr 16].mixSlaves := Integer(Data) and $FFFF;
    34293542        cSetCityName:
    34303543          with TCityNameInfo(Data) do
    34313544            if TribeOriginal[ID shr 12] then
    34323545              Tribe[ID shr 12].SetCityName(ID and $FFF, NewName);
    3433 
    34343546        cSetModelName:
    34353547          with TModelNameInfo(Data) do
     
    34443556procedure TMainScreen.FormCreate(Sender: TObject);
    34453557var
    3446   i, j: integer;
     3558  I, J: Integer;
    34473559begin
    34483560  NoMap := TIsoMap.Create;
     
    34863598
    34873599  // tag-controlled language
    3488   for i := 0 to ComponentCount - 1 do
    3489     if Components[i].Tag and $FF <> 0 then
    3490       if Components[i] is TDpiMenuItem then begin
    3491         TDpiMenuItem(Components[i]).Caption := Phrases.Lookup('CONTROLS',
    3492           -1 + Components[i].Tag and $FF);
    3493         for j := 0 to Length(SaveOption) - 1 do
    3494           if Components[i].Tag and $FF = SaveOption[j] then
    3495             TDpiMenuItem(Components[i]).Checked := TSaveOption(j) in OptionChecked;
     3600  for I := 0 to ComponentCount - 1 do
     3601    if Components[I].Tag and $FF <> 0 then
     3602      if Components[I] is TDpiMenuItem then begin
     3603        TDpiMenuItem(Components[I]).Caption := Phrases.Lookup('CONTROLS',
     3604          -1 + Components[I].Tag and $FF);
     3605        for J := 0 to Length(SaveOption) - 1 do
     3606          if Components[I].Tag and $FF = SaveOption[J] then
     3607            TDpiMenuItem(Components[I]).Checked := TSaveOption(J) in OptionChecked;
    34963608      end else
    3497       if Components[i] is TButtonBase then begin
    3498         TButtonBase(Components[i]).Hint := Phrases.Lookup('CONTROLS',
    3499           -1 + Components[i].Tag and $FF);
    3500         if (Components[i] is TButtonC) and
    3501           (TButtonC(Components[i]).ButtonIndex <> 1) then
    3502           TButtonC(Components[i]).ButtonIndex :=
    3503             Integer(MapOptionChecked) shr (Components[i].Tag shr 8) and 1 + 2
     3609      if Components[I] is TButtonBase then begin
     3610        TButtonBase(Components[I]).Hint := Phrases.Lookup('CONTROLS',
     3611          -1 + Components[I].Tag and $FF);
     3612        if (Components[I] is TButtonC) and
     3613          (TButtonC(Components[I]).ButtonIndex <> 1) then
     3614          TButtonC(Components[I]).ButtonIndex :=
     3615            Integer(MapOptionChecked) shr (Components[I].Tag shr 8) and 1 + 2
    35043616      end;
    35053617
     
    35143626    ManagementArea.Hint := Phrases2.Lookup('BTN_MANAGE');
    35153627  end;
    3516   for i := 0 to mRep.Count - 1 do
    3517   begin
    3518     j := mRep[i].Tag shr 8;
    3519     mRep[i].Caption := CityEventName(j);
    3520     mRep[i].Checked := CityRepMask and (1 shl j) <> 0;
     3628  for I := 0 to mRep.Count - 1 do
     3629  begin
     3630    J := mRep[I].Tag shr 8;
     3631    mRep[I].Caption := CityEventName(J);
     3632    mRep[I].Checked := CityRepMask and (1 shl J) <> 0;
    35213633  end;
    35223634
     
    35373649    else Buffer.height := 3 * ySizeBig;
    35383650  Buffer.Canvas.Font.Assign(UniFont[ftSmall]);
    3539   for i := 0 to nPl - 1 do
    3540     AILogo[i] := nil;
     3651  for I := 0 to nPl - 1 do
     3652    AILogo[I] := nil;
    35413653  Canvas.Font.Assign(UniFont[ftSmall]);
    35423654  InitButtons;
     
    35483660  I: Integer;
    35493661begin
     3662  if Assigned(FWondersDlg) then FreeAndNil(FWondersDlg);
     3663  if Assigned(FTechTreeDlg) then FreeAndNil(FTechTreeDlg);
     3664  if Assigned(FEnhanceDlg) then FreeAndNil(FEnhanceDlg);
     3665  if Assigned(FNegoDlg) then FreeAndNil(FNegoDlg);
     3666  if Assigned(FCityTypeDlg) then FreeAndNil(FCityTypeDlg);
     3667  if Assigned(FDiaDlg) then FreeAndNil(FDiaDlg);
     3668  if Assigned(FCityDlg) then FreeAndNil(FCityDlg);
     3669  if Assigned(FRatesDlg) then FreeAndNil(FRatesDlg);
     3670  if Assigned(FBattleDlg) then FreeAndNil(FBattleDlg);
     3671  if Assigned(FNatStatDlg) then FreeAndNil(FNatStatDlg);
     3672  if Assigned(FUnitStatDlg) then FreeAndNil(FUnitStatDlg);
     3673  if Assigned(FDraftDlg) then FreeAndNil(FDraftDlg);
     3674  if Assigned(FModalSelectDlg) then FreeAndNil(FModalSelectDlg);
     3675  if Assigned(FListDlg) then FreeAndNil(FListDlg);
     3676  if Assigned(FMessgExDlg) then FreeAndNil(FMessgExDlg);
     3677  if Assigned(FHelpDlg) then FreeAndNil(FHelpDlg);
     3678
    35503679  MainFormKeyDown := nil;
    35513680  FreeAndNil(sb);
     
    35553684  FreeAndNil(Panel);
    35563685  for I := 0 to nPl - 1 do
    3557     if AILogo[i] <> nil then
     3686    if AILogo[I] <> nil then
    35583687      FreeAndNil(AILogo[I]);
    35593688  FreeAndNil(Offscreen);
     
    35863715end;
    35873716
     3717procedure TMainScreen.mAfforestClick(Sender: TObject);
     3718begin
     3719  if UnFocus >= 0 then
     3720    with TUn(MyUn[UnFocus]) do
     3721      DoJob(jAfforest);
     3722end;
     3723
     3724procedure TMainScreen.mAirBaseClick(Sender: TObject);
     3725begin
     3726  if UnFocus >= 0 then
     3727    with TUn(MyUn[UnFocus]) do
     3728      DoJob(jBase);
     3729end;
     3730
     3731procedure TMainScreen.mCanalClick(Sender: TObject);
     3732begin
     3733  if UnFocus >= 0 then
     3734    with TUn(MyUn[UnFocus]) do
     3735      DoJob(jCanal);
     3736end;
     3737
     3738procedure TMainScreen.mCancelClick(Sender: TObject);
     3739begin
     3740  if UnFocus >= 0 then
     3741  with MyUn[UnFocus] do begin
     3742    DestinationMarkON := False;
     3743    PaintDestination;
     3744    Status := Status and ($FFFF - usRecover - usGoto - usEnhance);
     3745    if Job > jNone then
     3746      Server(sStartJob + jNone shl 4, Me, UnFocus, nil^);
     3747  end;
     3748end;
     3749
     3750procedure TMainScreen.mCentreClick(Sender: TObject);
     3751begin
     3752  if UnFocus >= 0 then
     3753  with TUn(MyUn[UnFocus]) do begin
     3754    Centre(Loc);
     3755    PaintAllMaps;
     3756  end;
     3757end;
     3758
     3759procedure TMainScreen.mcityClick(Sender: TObject);
     3760var
     3761  Loc0: Integer;
     3762  cix: Integer;
     3763  ServerResult: Integer;
     3764begin
     3765  if UnFocus >= 0 then
     3766  with TUn(MyUn[UnFocus]) do begin
     3767    Loc0 := Loc;
     3768    if MyMap[Loc] and fCity = 0 then
     3769    begin // build city
     3770      if DoJob(jCity) = eCity then
     3771      begin
     3772        MapValid := False;
     3773        PaintAll;
     3774        ZoomToCity(Loc0, True, chFounded);
     3775      end;
     3776    end else begin
     3777      CityOptimizer_BeforeRemoveUnit(UnFocus);
     3778      ServerResult := Server(sAddToCity, Me, UnFocus, nil^);
     3779      if ServerResult >= rExecuted then
     3780      begin
     3781        cix := MyRO.nCity - 1;
     3782        while (cix >= 0) and (MyCity[cix].Loc <> Loc0) do
     3783          Dec(cix);
     3784        Assert(cix >= 0);
     3785        CityOptimizer_CityChange(cix);
     3786        CityOptimizer_AfterRemoveUnit; // does nothing here
     3787        SetTroopLoc(Loc0);
     3788        UpdateViews(True);
     3789        DestinationMarkON := False;
     3790        PaintDestination;
     3791        UnFocus := -1;
     3792        PaintLoc(Loc0);
     3793        NextUnit(UnStartLoc, True);
     3794      end
     3795      else if ServerResult = eMaxSize then
     3796        SimpleMessage(Phrases.Lookup('ADDTOMAXSIZE'));
     3797    end;
     3798  end;
     3799end;
     3800
     3801procedure TMainScreen.mCityStatClick(Sender: TObject);
     3802begin
     3803  ListDlg.ShowNewContent(wmPersistent, kCities);
     3804end;
     3805
     3806procedure TMainScreen.mCityTypesClick(Sender: TObject);
     3807begin
     3808  CityTypeDlg.ShowNewContent(wmModal);
     3809  // must be modal because types are not saved before closing
     3810end;
     3811
     3812procedure TMainScreen.mClearClick(Sender: TObject);
     3813begin
     3814  if UnFocus >= 0 then
     3815    with TUn(MyUn[UnFocus]) do
     3816      DoJob(jClear);
     3817end;
     3818
     3819procedure TMainScreen.mDiagramClick(Sender: TObject);
     3820begin
     3821  DiaDlg.ShowNewContent_Charts(wmPersistent);
     3822end;
     3823
     3824procedure TMainScreen.mEmpireClick(Sender: TObject);
     3825begin
     3826  RatesDlg.ShowNewContent(wmPersistent);
     3827end;
     3828
     3829procedure TMainScreen.mEnhanceClick(Sender: TObject);
     3830begin
     3831  if UnFocus >= 0 then
     3832    with TUn(MyUn[UnFocus]) do
     3833      DoJob(-1);
     3834end;
     3835
     3836procedure TMainScreen.mEnhanceDefClick(Sender: TObject);
     3837begin
     3838  if UnFocus >= 0 then
     3839    EnhanceDlg.ShowNewContent(wmPersistent,
     3840      MyMap[MyUn[UnFocus].Loc] and fTerrain)
     3841  else
     3842    EnhanceDlg.ShowNewContent(wmPersistent);
     3843end;
     3844
     3845procedure TMainScreen.mEUnitStatClick(Sender: TObject);
     3846begin
     3847  if MyRO.nEnemyModel > 0 then
     3848    ListDlg.ShowNewContent(wmPersistent, kAllEModels);
     3849end;
     3850
     3851procedure TMainScreen.mFarmClick(Sender: TObject);
     3852begin
     3853  if UnFocus >= 0 then
     3854    with TUn(MyUn[UnFocus]) do
     3855      DoJob(jFarm);
     3856end;
     3857
     3858procedure TMainScreen.mfortClick(Sender: TObject);
     3859begin
     3860  if UnFocus >= 0 then
     3861    with TUn(MyUn[UnFocus]) do
     3862      DoJob(jFort);
     3863end;
     3864
     3865procedure TMainScreen.mGoOnClick(Sender: TObject);
     3866var
     3867  Destination: Integer;
     3868begin
     3869  if UnFocus >= 0 then
     3870  with TUn(MyUn[UnFocus]) do begin
     3871    if Status shr 16 = $7FFF then
     3872      Destination := maNextCity
     3873    else
     3874      Destination := Status shr 16;
     3875    Status := Status and not(usStay or usRecover) or usWaiting;
     3876    MoveToLoc(Destination, True);
     3877  end;
     3878end;
     3879
     3880procedure TMainScreen.mHelpClick(Sender: TObject);
     3881begin
     3882  if ClientMode = cEditMap then
     3883    HelpDlg.ShowNewContent(wmPersistent, hkText, HelpDlg.TextIndex('MAPEDIT'))
     3884  else
     3885    HelpDlg.ShowNewContent(wmPersistent, hkMisc, Integer(miscMain));
     3886end;
     3887
     3888procedure TMainScreen.mhomeClick(Sender: TObject);
     3889var
     3890  cixOldHome: Integer;
     3891begin
     3892  if UnFocus >= 0 then
     3893  with TUn(MyUn[UnFocus]) do begin
     3894    if MyMap[Loc] and fCity <> 0 then
     3895    begin
     3896      cixOldHome := Home;
     3897      if Server(sSetUnitHome, Me, UnFocus, nil^) >= rExecuted then
     3898      begin
     3899        CityOptimizer_CityChange(cixOldHome);
     3900        CityOptimizer_CityChange(Home);
     3901        UpdateViews(True);
     3902      end
     3903      else
     3904        Play('INVALID');
     3905    end
     3906    else
     3907    begin
     3908      Status := Status and not(usStay or usRecover or usEnhance);
     3909      MoveToLoc(maNextCity, True);
     3910    end;
     3911  end;
     3912end;
     3913
     3914procedure TMainScreen.mirrigationClick(Sender: TObject);
     3915begin
     3916  if UnFocus >= 0 then
     3917    with TUn(MyUn[UnFocus]) do
     3918        DoJob(jIrr);
     3919end;
     3920
     3921procedure TMainScreen.mirrigationDrawItem(Sender: TObject; ACanvas: TDpiCanvas;
     3922  ARect: TRect; AState: TOwnerDrawState);
     3923begin
     3924
     3925end;
     3926
     3927procedure TMainScreen.mJumpClick(Sender: TObject);
     3928begin
     3929  if Supervising then
     3930    Jump[0] := 20
     3931  else
     3932    Jump[Me] := 20;
     3933  EndTurn(True);
     3934end;
     3935
     3936procedure TMainScreen.mLoadClick(Sender: TObject);
     3937var
     3938  I: Integer;
     3939begin
     3940  if UnFocus >= 0 then
     3941  with MyUn[UnFocus] do begin
     3942    I := Server(sLoadUnit, Me, UnFocus, nil^);
     3943    if I >= rExecuted then
     3944    begin
     3945      if MyModel[mix].Domain = dAir then
     3946        Play('MOVE_PLANELANDING')
     3947      else
     3948        Play('MOVE_LOAD');
     3949      DestinationMarkON := False;
     3950      PaintDestination;
     3951      Status := Status and ($FFFF - usWaiting - usStay - usRecover - usGoto - usEnhance);
     3952      NextUnit(UnStartLoc, True);
     3953    end
     3954    else if I = eNoTime_Load then
     3955      if MyModel[mix].Domain = dAir then
     3956        SoundMessage(Phrases.Lookup('NOTIMELOADAIR'), 'NOMOVE_TIME')
     3957      else
     3958        SoundMessage(Format(Phrases.Lookup('NOTIMELOADGROUND'),
     3959          [MovementToString(MyModel[mix].speed)]), 'NOMOVE_TIME');
     3960  end;
     3961end;
     3962
     3963procedure TMainScreen.mmineClick(Sender: TObject);
     3964begin
     3965  if UnFocus >= 0 then
     3966    with TUn(MyUn[UnFocus]) do
     3967      DoJob(jMine);
     3968end;
     3969
     3970procedure TMainScreen.mNationsClick(Sender: TObject);
     3971begin
     3972  NatStatDlg.ShowNewContent(wmPersistent);
     3973end;
     3974
     3975procedure TMainScreen.mNextUnitClick(Sender: TObject);
     3976begin
     3977  if UnFocus >= 0 then
     3978  with MyUn[UnFocus] do begin
     3979    Status := Status and not usWaiting;
     3980    FocusNextUnit(1);
     3981  end;
     3982end;
     3983
     3984procedure TMainScreen.mnoordersClick(Sender: TObject);
     3985begin
     3986  if UnFocus >= 0 then
     3987  with MyUn[UnFocus] do begin
     3988    Status := Status and not usWaiting;
     3989    NextUnit(UnStartLoc, True);
     3990  end;
     3991end;
     3992
     3993procedure TMainScreen.mPillageClick(Sender: TObject);
     3994begin
     3995  DoJob(jPillage);
     3996end;
     3997
     3998procedure TMainScreen.mpollutionClick(Sender: TObject);
     3999begin
     4000  if UnFocus >= 0 then
     4001    with TUn(MyUn[UnFocus]) do
     4002      DoJob(jPoll);
     4003end;
     4004
     4005procedure TMainScreen.mPrevUnitClick(Sender: TObject);
     4006begin
     4007  if UnFocus >= 0 then
     4008  with MyUn[UnFocus] do begin
     4009    Status := Status and not usWaiting;
     4010    FocusNextUnit(-1);
     4011  end;
     4012end;
     4013
     4014procedure TMainScreen.mRandomMapClick(Sender: TObject);
     4015begin
     4016  if not Edited or (SimpleQuery(mkYesNo, Phrases.Lookup('MAP_RANDOM'), '')
     4017      = mrOK) then begin
     4018    Server(sRandomMap, Me, 0, nil^);
     4019    Edited := True;
     4020    MapValid := False;
     4021    PaintAllMaps;
     4022  end;
     4023end;
     4024
     4025procedure TMainScreen.mRecoverClick(Sender: TObject);
     4026begin
     4027  if UnFocus >= 0 then
     4028  with MyUn[UnFocus] do begin
     4029    DestinationMarkON := False;
     4030    PaintDestination;
     4031    Status := Status and ($FFFF - usStay - usGoto - usEnhance) or usRecover;
     4032    if Job > jNone then
     4033      Server(sStartJob + jNone shl 4, Me, UnFocus, nil^);
     4034    NextUnit(UnStartLoc, True);
     4035  end;
     4036end;
     4037
     4038procedure TMainScreen.mResignClick(Sender: TObject);
     4039var
     4040  QueryText: string;
     4041begin
     4042  if ClientMode = cEditMap then begin
     4043    if Edited then begin
     4044      QueryText := Phrases.Lookup('MAP_CLOSE');
     4045      case SimpleQuery(mkYesNoCancel, QueryText, '') of
     4046        mrIgnore: Server(sAbandonMap, Me, 0, nil^);
     4047        mrOK: Server(sSaveMap, Me, 0, nil^);
     4048      end;
     4049    end else
     4050      Server(sAbandonMap, Me, 0, nil^);
     4051  end else begin
     4052    if Server(sGetGameChanged, 0, 0, nil^) = eOK then begin
     4053      QueryText := Phrases.Lookup('RESIGN');
     4054      case SimpleQuery(mkYesNoCancel, QueryText, '') of
     4055        mrIgnore: Server(sResign, 0, 0, nil^);
     4056        mrOK: Server(sBreak, 0, 0, nil^);
     4057      end;
     4058    end else
     4059      Server(sResign, 0, 0, nil^);
     4060  end;
     4061end;
     4062
     4063procedure TMainScreen.mRevolutionClick(Sender: TObject);
     4064var
     4065  AltGovs: Boolean;
     4066  RevolutionChanged: Boolean;
     4067  I: Integer;
     4068begin
     4069  AltGovs := False;
     4070    for I := 2 to nGov - 1 do
     4071      if (GovPreq[I] <> preNA) and
     4072        ((GovPreq[I] = preNone) or (MyRO.Tech[GovPreq[I]] >= tsApplicable)) then
     4073        AltGovs := True;
     4074
     4075    if not AltGovs then
     4076      SoundMessage(Phrases.Lookup('NOALTGOVS'), 'MSG_DEFAULT')
     4077    else
     4078    begin
     4079      RevolutionChanged := False;
     4080      if MyRO.Happened and phChangeGov <> 0 then
     4081      begin
     4082        ModalSelectDlg.ShowNewContent(wmModal, kGov);
     4083        if ModalSelectDlg.Result >= 0 then
     4084        begin
     4085          Play('NEWGOV');
     4086          Server(sSetGovernment, Me, ModalSelectDlg.Result, nil^);
     4087          CityOptimizer_BeginOfTurn;
     4088          RevolutionChanged := True;
     4089        end;
     4090      end
     4091      else
     4092      with MessgExDlg do
     4093      begin // revolution!
     4094        MessgExDlg.MessgText := Tribe[Me].TPhrase('REVOLUTION');
     4095        MessgExDlg.Kind := mkYesNo;
     4096        MessgExDlg.IconKind := mikPureIcon;
     4097        MessgExDlg.IconIndex := 72; // anarchy palace
     4098        MessgExDlg.ShowModal;
     4099        if ModalResult = mrOK then
     4100        begin
     4101          Play('REVOLUTION');
     4102          Server(sRevolution, Me, 0, nil^);
     4103          RevolutionChanged := True;
     4104          if NatStatDlg.Visible then
     4105            NatStatDlg.Close;
     4106          if CityDlg.Visible then
     4107            CityDlg.Close;
     4108        end
     4109      end;
     4110      if RevolutionChanged then
     4111        UpdateViews(True);
     4112    end;
     4113end;
     4114
     4115procedure TMainScreen.mroadClick(Sender: TObject);
     4116begin
     4117  if UnFocus >= 0 then
     4118    with TUn(MyUn[UnFocus]) do
     4119      DoJob(jRoad);
     4120end;
     4121
     4122procedure TMainScreen.mRailRoadClick(Sender: TObject);
     4123begin
     4124  if UnFocus >= 0 then
     4125    with TUn(MyUn[UnFocus]) do
     4126      DoJob(jRR);
     4127end;
     4128
     4129procedure TMainScreen.mRunClick(Sender: TObject);
     4130begin
     4131  if Supervising then
     4132    Jump[0] := 999999
     4133  else
     4134    Jump[Me] := 999999;
     4135  EndTurn(True);
     4136end;
     4137
     4138procedure TMainScreen.mScienceStatClick(Sender: TObject);
     4139begin
     4140  ListDlg.ShowNewContent(wmPersistent, kScience);
     4141end;
     4142
     4143procedure TMainScreen.mSelectTransportClick(Sender: TObject);
     4144begin
     4145  if UnFocus >= 0 then
     4146    with TUn(MyUn[UnFocus]) do
     4147      Server(sSelectTransport, Me, UnFocus, nil^);
     4148end;
     4149
     4150procedure TMainScreen.mShipsClick(Sender: TObject);
     4151begin
     4152  DiaDlg.ShowNewContent_Ship(wmPersistent);
     4153end;
     4154
     4155procedure TMainScreen.mstayClick(Sender: TObject);
     4156begin
     4157  if UnFocus >= 0 then
     4158  with TUn(MyUn[UnFocus]) do begin
     4159    DestinationMarkON := False;
     4160    PaintDestination;
     4161    Status := Status and ($FFFF - usRecover - usGoto - usEnhance) or usStay;
     4162    if Job > jNone then
     4163      Server(sStartJob + jNone shl 4, Me, UnFocus, nil^);
     4164    NextUnit(UnStartLoc, True);
     4165  end;
     4166end;
     4167
     4168procedure TMainScreen.mTechTreeClick(Sender: TObject);
     4169begin
     4170  TechTreeDlg.ShowModal;
     4171end;
     4172
     4173procedure TMainScreen.mtransClick(Sender: TObject);
     4174begin
     4175  if UnFocus >= 0 then
     4176    with TUn(MyUn[UnFocus]) do
     4177      DoJob(jTrans);
     4178end;
     4179
     4180procedure TMainScreen.mUnitStatClick(Sender: TObject);
     4181var
     4182  I: Integer;
     4183begin
     4184  if G.Difficulty[Me] > 0 then
     4185    ListDlg.ShowNewContent_MilReport(wmPersistent, Me)
     4186  else
     4187  begin
     4188    I := 1;
     4189    while (I < nPl) and (1 shl I and MyRO.Alive = 0) do
     4190      Inc(I);
     4191    if I < nPl then
     4192      ListDlg.ShowNewContent_MilReport(wmPersistent, I);
     4193  end;
     4194end;
     4195
     4196procedure TMainScreen.mUnloadClick(Sender: TObject);
     4197var
     4198  I: Integer;
     4199  OldMaster: Integer;
     4200  NewFocus: Integer;
     4201  uix: Integer;
     4202begin
     4203  if UnFocus >= 0 then
     4204  with MyUn[UnFocus] do begin
     4205    if Master >= 0 then begin
     4206      OldMaster := Master;
     4207      I := Server(sUnloadUnit, Me, UnFocus, nil^);
     4208      if I >= rExecuted then
     4209      begin
     4210        if MyModel[mix].Domain = dAir then
     4211          Play('MOVE_PLANESTART')
     4212        else if (MyModel[MyUn[OldMaster].mix].Domain = dAir) and
     4213          (MyMap[Loc] and fCity = 0) and (MyMap[Loc] and fTerImp <> tiBase)
     4214        then
     4215          Play('MOVE_PARACHUTE')
     4216        else
     4217          Play('MOVE_UNLOAD');
     4218        Status := Status and not usWaiting;
     4219        if MyModel[mix].Domain <> dAir then
     4220          NextUnit(Loc, True)
     4221        else
     4222          PanelPaint;
     4223      end
     4224      else if I = eNoTime_Load then
     4225        if MyModel[mix].Domain = dAir then
     4226          SoundMessage(Phrases.Lookup('NOTIMELOADAIR'), 'NOMOVE_TIME')
     4227        else
     4228          SoundMessage(Format(Phrases.Lookup('NOTIMELOADGROUND'),
     4229            [MovementToString(MyModel[mix].speed)]), 'NOMOVE_TIME');
     4230    end else begin
     4231      NewFocus := -1;
     4232      uix := UnFocus;
     4233      for I := 1 to MyRO.nUn - 1 do
     4234      begin
     4235        uix := (uix + MyRO.nUn - 1) mod MyRO.nUn;
     4236        if (MyUn[uix].Master = UnFocus) and
     4237          (MyUn[uix].Movement = Integer(MyModel[MyUn[uix].mix].speed)) then
     4238        begin
     4239          MyUn[uix].Status := MyUn[uix].Status or usWaiting;
     4240          NewFocus := uix;
     4241        end;
     4242      end;
     4243      if NewFocus >= 0 then
     4244      begin
     4245        SetUnFocus(NewFocus);
     4246        SetTroopLoc(Loc);
     4247        PanelPaint;
     4248      end;
     4249    end;
     4250  end;
     4251end;
     4252
     4253procedure TMainScreen.mwaitClick(Sender: TObject);
     4254begin
     4255  if UnFocus >= 0 then
     4256  with MyUn[UnFocus] do begin
     4257    DestinationMarkON := False;
     4258    PaintDestination;
     4259    Status := Status and ($FFFF - usStay - usRecover - usGoto - usEnhance) or usWaiting;
     4260  end;
     4261  NextUnit(-1, False);
     4262end;
     4263
     4264procedure TMainScreen.mWebsiteClick(Sender: TObject);
     4265begin
     4266  OpenURL(CevoHomepage);
     4267end;
     4268
     4269procedure TMainScreen.mWondersClick(Sender: TObject);
     4270begin
     4271  WondersDlg.ShowNewContent(wmPersistent);
     4272end;
     4273
    35884274procedure TMainScreen.FormResize(Sender: TObject);
    35894275var
    3590   MiniFrame, MaxMapWidth: integer;
     4276  MiniFrame, MaxMapWidth: Integer;
    35914277begin
    35924278  SmallScreen := ClientWidth < 1024;
     
    36664352  begin
    36674353    RectInvalidate(0, TopBarHeight, ClientWidth, TopBarHeight + MapHeight);
    3668     MapValid := false;
     4354    MapValid := False;
    36694355    PaintAll;
    36704356  end;
    36714357end;
    36724358
    3673 procedure TMainScreen.FormCloseQuery(Sender: TObject; var CanClose: boolean);
     4359procedure TMainScreen.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    36744360begin
    36754361  CanClose := Closable;
    3676   if not Closable and idle and (me = 0) and (ClientMode < scContact) then
    3677     MenuClick(mResign);
     4362  if not Closable and Idle and (Me = 0) and (ClientMode < scContact) then
     4363    mResign.Click;
    36784364end;
    36794365
     
    36964382  begin
    36974383    MessgExDlg.CancelMovie;
    3698     Server(sBreak, me, 0, nil^);
     4384    Server(sBreak, Me, 0, nil^);
    36994385  end
    37004386  else if ClientMode < 0 then
    3701     skipped := true
     4387    Skipped := True
    37024388  else if ClientMode >= scContact then
    37034389    NegoDlg.ShowNewContent(wmPersistent)
     
    37054391  begin
    37064392    Jump[pTurn] := 0;
    3707     StartRunning := false;
     4393    StartRunning := False;
    37084394  end
    37094395  else
     
    37184404  else
    37194405  with MainMap do begin
    3720     if supervising then
     4406    if Supervising then
    37214407      xTerrain := xMidPanel + 2 * xxt + 14
    37224408    else if ClientWidth < 1280 then
     
    37254411      xTerrain := ClientWidth div 2;
    37264412    xTroop := xTerrain + 2 * xxt + 12;
    3727     if SmallScreen and not supervising then
     4413    if SmallScreen and not Supervising then
    37284414      xTroop := xRightPanel + 10 - 3 * 66 -
    37294415        DpiGetSystemMetrics(SM_CXVSCROLL) - 19 - 4;
     
    37344420end;
    37354421
    3736 function TMainScreen.EndTurn(WasSkipped: boolean): boolean;
    3737 
    3738   function IsResourceUnused(cix, NeedFood, NeedProd: integer): boolean;
     4422function TMainScreen.EndTurn(WasSkipped: Boolean): Boolean;
     4423
     4424  function IsResourceUnused(cix, NeedFood, NeedProd: Integer): Boolean;
    37394425  var
    3740     dx, dy, fix: integer;
     4426    dx, dy, fix: Integer;
    37414427    CityAreaInfo: TCityAreaInfo;
    37424428    TileInfo: TTileInfo;
    37434429  begin
    3744     Server(sGetCityAreaInfo, me, cix, CityAreaInfo);
     4430    Server(sGetCityAreaInfo, Me, cix, CityAreaInfo);
    37454431    for dy := -3 to 3 do
    37464432      for dx := -3 to 3 do
     
    37524438          begin
    37534439            TileInfo.ExplCity := cix;
    3754             Server(sGetHypoCityTileInfo, me, dLoc(MyCity[cix].Loc, dx, dy),
     4440            Server(sGetHypoCityTileInfo, Me, dLoc(MyCity[cix].Loc, dx, dy),
    37554441              TileInfo);
    37564442            if (TileInfo.Food >= NeedFood) and (TileInfo.Prod >= NeedProd) then
    37574443            begin
    3758               result := true;
    3759               exit
     4444              Result := True;
     4445              Exit
    37604446            end;
    37614447          end
    37624448        end;
    3763     result := false;
     4449    Result := False;
    37644450  end;
    37654451
    37664452var
    3767   i, p1, uix, cix, CenterLoc: integer;
     4453  p1, uix, cix, CenterLoc: Integer;
    37684454  MsgItem: string;
    37694455  CityReport: TCityReport;
    37704456  PlaneReturnData: TPlaneReturnData;
    3771   Zoom: boolean;
    3772 begin
    3773   result := false;
     4457  Zoom: Boolean;
     4458begin
     4459  Result := False;
    37744460  if ClientMode >= scDipOffer then
    3775     exit;
    3776 
    3777   if supervising and (me <> 0) then
    3778   begin
    3779     for i := 0 to DpiScreen.FormCount - 1 do
    3780       if DpiScreen.Forms[i].Visible and (DpiScreen.Forms[i] is TBufferedDrawDlg) then
    3781         DpiScreen.Forms[i].Close; // close windows
     4461    Exit;
     4462
     4463  if Supervising and (Me <> 0) then begin
     4464    ApplyToVisibleForms(faClose);
    37824465    ItsMeAgain(0);
    37834466  end;
     
    37974480          PlaneReturnData.Loc := Loc;
    37984481          PlaneReturnData.Movement := 0; // end turn without further movement?
    3799           if Server(sGetPlaneReturn, me, uix, PlaneReturnData) = eNoWay then
     4482          if Server(sGetPlaneReturn, Me, uix, PlaneReturnData) = eNoWay then
    38004483          begin
    38014484            CenterLoc := Loc + G.lx * 6;
    38024485            // centering the unit itself would make it covered by the query dialog
    38034486            while CenterLoc >= G.lx * G.ly do
    3804               dec(CenterLoc, G.lx * 2);
     4487              Dec(CenterLoc, G.lx * 2);
    38054488            Centre(CenterLoc);
    38064489            SetTroopLoc(-1);
     
    38174500              SetTroopLoc(Loc);
    38184501              PanelPaint;
    3819               exit;
     4502              Exit;
    38204503            end;
    38214504            MyUn[uix].Status := MyUn[uix].Status or usToldNoReturn;
    3822           end
     4505          end;
    38234506        end;
    38244507
    3825     if not supervising and (MyRO.TestFlags and tfImmImprove = 0) and
     4508    if not Supervising and (MyRO.TestFlags and tfImmImprove = 0) and
    38264509      (MyRO.Government <> gAnarchy) and (MyRO.Money + TaxSum < 0) and
    38274510      (MyRO.TaxRate < 100) then // low funds!
     
    38354518        ShowModal;
    38364519        if ModalResult <> mrOK then
    3837           exit
     4520          Exit;
    38384521      end;
    38394522
     
    38434526          if (Loc >= 0) and (Flags and chCaptured = 0) then
    38444527          begin
    3845             Zoom := false;
     4528            Zoom := False;
    38464529            CityReport.HypoTiles := -1;
    38474530            CityReport.HypoTax := -1;
    38484531            CityReport.HypoLux := -1;
    3849             Server(sGetCityReport, me, cix, CityReport);
     4532            Server(sGetCityReport, Me, cix, CityReport);
    38504533
    38514534            if (CityReport.Working - CityReport.Happy > Size shr 1) and
     
    39044587            begin // zoom to city
    39054588              ZoomToCity(Loc);
    3906               exit
    3907             end
     4589              Exit;
     4590            end;
    39084591          end;
    39094592
     
    39114594      (MyData.FarTech <> adNexus) then
    39124595      if not ChooseResearch then
    3913         exit;
     4596        Exit;
    39144597  end;
    39154598
     
    39214604
    39224605  CityDlg.CloseAction := None;
    3923   if IsMultiPlayerGame then
    3924   begin // close windows for next player
    3925     for i := 0 to DpiScreen.FormCount - 1 do
    3926       if DpiScreen.Forms[i].Visible and (DpiScreen.Forms[i] is TBufferedDrawDlg) then
    3927         DpiScreen.Forms[i].Close;
    3928   end
    3929   else
    3930   begin
     4606  if IsMultiPlayerGame then begin
     4607    // Close windows for next player
     4608    ApplyToVisibleForms(faClose);
     4609  end else begin
    39314610    if CityDlg.Visible then
    39324611      CityDlg.Close;
     
    39344613      UnitStatDlg.Close;
    39354614  end;
    3936   for i := 0 to DpiScreen.FormCount - 1 do
    3937     if DpiScreen.Forms[i].Visible and (DpiScreen.Forms[i] is TBufferedDrawDlg) then
    3938       DpiScreen.Forms[i].Enabled := false;
     4615  ApplyToVisibleForms(faDisable);
    39394616
    39404617  if Server(sTurn, pTurn, 0, nil^) >= rExecuted then
     
    39444621    else
    39454622      EOT.Hint := Phrases.Lookup('BTN_SKIP');
    3946     result := true;
     4623    Result := True;
    39474624    SetTroopLoc(-1);
    39484625    pTurn := -1;
    39494626    pLogo := -1;
    3950     UnitInfoBtn.Visible := false;
    3951     UnitBtn.Visible := false;
    3952     TerrainBtn.Visible := false;
     4627    UnitInfoBtn.Visible := False;
     4628    UnitBtn.Visible := False;
     4629    TerrainBtn.Visible := False;
    39534630    EOT.ButtonIndex := eotCancel;
    3954     EOT.Visible := true;
    3955     MapValid := false;
     4631    EOT.Visible := True;
     4632    MapValid := False;
    39564633    PanelPaint;
    39574634    Update;
    39584635    ClientMode := -1;
    3959     idle := false;
    3960     skipped := WasSkipped;
     4636    Idle := False;
     4637    Skipped := WasSkipped;
    39614638    for p1 := 1 to nPl - 1 do
    39624639      if G.RO[p1] <> nil then
    3963         skipped := true; // don't show enemy moves in hotseat mode
     4640        Skipped := True; // don't show enemy moves in hotseat mode
    39644641  end
    39654642  else
    3966     PanelPaint
    3967 end; // EndTurn
     4643    PanelPaint;
     4644end;
    39684645
    39694646procedure TMainScreen.EndNego;
     
    39714648  if NegoDlg.Visible then
    39724649    NegoDlg.Close;
    3973   HaveStrategyAdvice := false;
    3974   // AdvisorDlg.HaveStrategyAdvice;
    3975   // negotiation might have changed advices
     4650  HaveStrategyAdvice := False;
    39764651  EOT.ButtonIndex := eotCancel;
    3977   EOT.Visible := true;
     4652  EOT.Visible := True;
    39784653  PanelPaint;
    39794654  Update;
    39804655  ClientMode := -1;
    3981   idle := false;
    3982 end;
    3983 
    3984 procedure TMainScreen.ProcessRect(x0, y0, nx, ny, Options: integer);
     4656  Idle := False;
     4657end;
     4658
     4659procedure TMainScreen.ProcessRect(x0, y0, nx, ny, Options: Integer);
    39854660var
    3986   xs, ys, xl, yl: integer;
     4661  xs, ys, xl, yl: Integer;
    39874662begin
    39884663  with MainMap do begin
     
    39934668    while abs(2 * (xs + G.lx * (xxt * 2)) + xl - MapWidth) <
    39944669      abs(2 * xs + xl - MapWidth) do
    3995         inc(xs, G.lx * (xxt * 2));
     4670        Inc(xs, G.lx * (xxt * 2));
    39964671    ys := (y0 - yw) * yyt - yyt;
    39974672    if xs + xl > MapWidth then
     
    40004675      yl := MapHeight - ys;
    40014676    if (xl <= 0) or (yl <= 0) then
    4002       exit;
     4677      Exit;
    40034678    if Options and prPaint <> 0 then begin
    40044679      if Options and prAutoBounds <> 0 then
     
    40124687end;
    40134688
    4014 procedure TMainScreen.PaintLoc(Loc: integer; Radius: integer = 0);
     4689procedure TMainScreen.PaintLoc(Loc: Integer; Radius: Integer = 0);
    40154690var
    4016   yLoc, x0: integer;
     4691  yLoc, x0: Integer;
    40174692begin
    40184693  if MapValid then begin
    40194694    yLoc := (Loc + G.lx * 1024) div G.lx - 1024;
    40204695    x0 := (Loc + (yLoc and 1 - 2 * Radius + G.lx * 1024) div 2) mod G.lx;
    4021     offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     4696    Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    40224697    ProcessRect(x0, yLoc - 2 * Radius, 4 * Radius + 1, 4 * Radius + 1,
    40234698      prPaint or prAutoBounds or prInvalidate);
     
    40264701end;
    40274702
    4028 procedure TMainScreen.PaintLocTemp(Loc: integer; Style: TPaintLocTempStyle);
     4703procedure TMainScreen.PaintLocTemp(Loc: Integer; Style: TPaintLocTempStyle);
    40294704var
    4030   y0, x0, xMap, yMap: integer;
     4705  y0, x0, xMap, yMap: Integer;
    40314706begin
    40324707  with NoMap do begin
    40334708    if not MapValid then
    4034       exit;
     4709      Exit;
    40354710    Buffer.Canvas.Font.Assign(UniFont[ftSmall]);
    40364711    y0 := Loc div G.lx;
     
    40404715    while abs(2 * (xMap + G.lx * (xxt * 2)) + 2 * xxt - MapWidth) <
    40414716      abs(2 * xMap + 2 * xxt - MapWidth) do
    4042       inc(xMap, G.lx * (xxt * 2));
     4717      Inc(xMap, G.lx * (xxt * 2));
    40434718    yMap := (y0 - yw) * yyt - yyt;
    40444719    NoMap.SetOutput(Buffer);
     
    40524727// panel protusions are added
    40534728// NoMap must be set to buffer and bounds before
    4054 procedure TMainScreen.PaintBufferToScreen(xMap, yMap, width, height: integer);
     4729procedure TMainScreen.PaintBufferToScreen(xMap, yMap, width, height: Integer);
    40554730begin
    40564731  if xMap + width > MapWidth then
     
    40604735  if (width <= 0) or (height <= 0) or (width + xMap <= 0) or (height + yMap <= 0)
    40614736  then
    4062     exit;
     4737    Exit;
    40634738
    40644739  NoMap.BitBltBitmap(Panel, -xMap - MapOffset, -yMap + MapHeight - overlap, xMidPanel,
     
    40704745  begin
    40714746    if xMap < 0 then
    4072       DpiBitCanvas(Canvas, MapOffset, TopBarHeight, width + xMap,
     4747      DpiBitBltCanvas(Canvas, MapOffset, TopBarHeight, width + xMap,
    40734748        height + yMap, Buffer.Canvas, -xMap, -yMap)
    40744749    else
    4075       DpiBitCanvas(Canvas, xMap + MapOffset, TopBarHeight, width,
     4750      DpiBitBltCanvas(Canvas, xMap + MapOffset, TopBarHeight, width,
    40764751        height + yMap, Buffer.Canvas, 0, -yMap);
    40774752  end
     
    40794754  begin
    40804755    if xMap < 0 then
    4081       DpiBitCanvas(Canvas, MapOffset, TopBarHeight + yMap, width + xMap,
     4756      DpiBitBltCanvas(Canvas, MapOffset, TopBarHeight + yMap, width + xMap,
    40824757        height, Buffer.Canvas, -xMap, 0)
    40834758    else
    4084       DpiBitCanvas(Canvas, xMap + MapOffset, TopBarHeight + yMap, width,
     4759      DpiBitBltCanvas(Canvas, xMap + MapOffset, TopBarHeight + yMap, width,
    40854760        height, Buffer.Canvas, 0, 0);
    40864761  end;
    40874762end;
    40884763
    4089 procedure TMainScreen.PaintLoc_BeforeMove(FromLoc: integer);
     4764procedure TMainScreen.PaintLoc_BeforeMove(FromLoc: Integer);
    40904765var
    4091   yLoc, x0: integer;
     4766  yLoc, x0: Integer;
    40924767begin
    40934768  if MapValid then
     
    40954770    yLoc := (FromLoc + G.lx * 1024) div G.lx - 1024;
    40964771    x0 := (FromLoc + (yLoc and 1 + G.lx * 1024) div 2) mod G.lx;
    4097     offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     4772    Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    40984773    ProcessRect(x0, yLoc, 1, 1, prPaint or prAutoBounds);
    40994774  end
     
    41024777procedure TMainScreen.PaintDestination;
    41034778var
    4104   Destination: integer;
     4779  Destination: Integer;
    41054780begin
    41064781  if (UnFocus >= 0) and (MyUn[UnFocus].Status and usGoto <> 0) then
     
    41124787end;
    41134788
    4114 {$IFDEF LINUX}
     4789{$IFDEF UNIX}
    41154790// Can't do scrolling of DC under Linux, then fallback into BitBlt.
    41164791function DpiScrollDC(Canvas: TDpiCanvas; dx: longint; dy: longint; const lprcScroll:TRect; const lprcClip:TRect; hrgnUpdate:HRGN; lprcUpdate: PRect):Boolean;
    41174792begin
    4118   Result := DpiBitCanvas(Canvas, lprcScroll.Left + dx, lprcScroll.Top + dy, lprcScroll.Right - lprcScroll.Left, lprcScroll.Bottom - lprcScroll.Top,
     4793  Result := DpiBitBltCanvas(Canvas, lprcScroll.Left + dx, lprcScroll.Top + dy, lprcScroll.Right - lprcScroll.Left, lprcScroll.Bottom - lprcScroll.Top,
    41194794    Canvas, lprcScroll.Left, lprcScroll.Top);
    41204795end;
     
    41234798procedure TMainScreen.MainOffscreenPaint;
    41244799var
    4125   ProcessOptions: integer;
     4800  ProcessOptions: Integer;
    41264801  rec: TRect;
    4127   DoInvalidate: boolean;
    4128 begin
    4129   if me < 0 then
    4130     with offscreen.Canvas do
     4802  DoInvalidate: Boolean;
     4803begin
     4804  if Me < 0 then
     4805    with Offscreen.Canvas do
    41314806    begin
    41324807      Brush.Color := $000000;
     
    41344809      Brush.Style := bsClear;
    41354810      OffscreenUser := self;
    4136       exit;
     4811      Exit;
    41374812    end;
    41384813
     
    41454820    if MapValid and (xwd = xw) and (ywd = yw) then
    41464821      MainMap.SetPaintBounds(0, 0, UsedOffscreenWidth, UsedOffscreenHeight);
    4147     MapValid := false;
     4822    MapValid := False;
    41484823    OffscreenUser := self;
    41494824  end;
     
    41584833      (ywd - yw > MapHeight div yyt) then
    41594834    begin
    4160       offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     4835      Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    41614836      ProcessRect(xw, yw, MapWidth div xxt, MapHeight div yyt,
    41624837        prPaint or prInvalidate);
    41634838    end else begin
    41644839      if (xwd = xw) and (ywd = yw) then
    4165         exit; { map window not moved }
    4166       offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     4840        Exit; { map window not moved }
     4841      Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    41674842      rec := Rect(0, 0, MapWidth, MapHeight);
    41684843{$IFDEF WINDOWS}
    4169       DpiScrollDC(offscreen.Canvas, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,
     4844      DpiScrollDC(Offscreen.Canvas.Handle, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,
    41704845        rec, rec, 0, nil);
    41714846{$ENDIF}
    4172 {$IFDEF LINUX}
    4173       DpiScrollDC(offscreen.Canvas, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,
     4847{$IFDEF UNIX}
     4848      DpiScrollDC(Offscreen.Canvas, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,
    41744849        rec, rec, 0, nil);
    41754850{$ENDIF}
    4176       for DoInvalidate := false to FastScrolling do begin
     4851      for DoInvalidate := False to FastScrolling do begin
    41774852        if DoInvalidate then begin
    41784853          rec.Bottom := MapHeight - overlap;
    41794854{$IFDEF WINDOWS}
    4180           DpiScrollDC(Canvas, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt, rec,
     4855          DpiScrollDC(Canvas.Handle, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt, rec,
    41814856            rec, 0, nil);
    41824857{$ENDIF}
    4183 {$IFDEF LINUX}
     4858{$IFDEF UNIX}
    41844859          DpiScrollDC(Canvas, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,
    41854860            rec, rec, 0, nil);
     
    42314906  xwd := xw;
    42324907  ywd := yw;
    4233   MapValid := true;
     4908  MapValid := True;
    42344909end;
    42354910
     
    42644939begin
    42654940  with MainMap do begin
    4266     DpiBitCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
     4941    DpiBitBltCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
    42674942      MiniMap.Bitmap.Canvas, 0, 0);
    42684943    if MarkCityLoc >= 0 then
     
    42884963  function MovementToString(var Un: TUn): string;
    42894964  begin
    4290     result := ScreenTools.MovementToString(Un.Movement);
     4965    Result := ScreenTools.MovementToString(Un.Movement);
    42914966    if Un.Master >= 0 then
    4292       result := '(' + result + ')'
     4967      Result := '(' + Result + ')'
    42934968    else if (MyModel[Un.mix].Domain = dAir) and
    42944969      (MyModel[Un.mix].Kind <> mkSpecial_Glider) then
    4295       result := Format('%s(%d)', [result, Un.Fuel]);
     4970      Result := Format('%s(%d)', [Result, Un.Fuel]);
    42964971  end;
    42974972
    42984973var
    4299   i, uix, uixDefender, x, xSrc, ySrc, xSrcBase, ySrcBase, CostFactor, Count,
     4974  I, uix, uixDefender, X, xSrc, ySrc, xSrcBase, ySrcBase, CostFactor, Count,
    43004975    mixShow, xTreasurySection, xResearchSection, JobFocus, TrueMoney,
    4301     TrueResearch: integer;
     4976    TrueResearch: Integer;
    43024977  Tile: Cardinal;
    4303   s: string;
     4978  S: string;
    43044979  unx: TUn;
    43054980  UnitInfo: TUnitInfo;
    43064981  JobProgressData: TJobProgressData;
    4307   Prio: boolean;
     4982  Prio: Boolean;
    43084983begin
    43094984  if not Assigned(MyRO) then Exit;
     
    43495024    if ClientMode <> cEditMap then
    43505025    begin
    4351       if supervising then
     5026      if Supervising then
    43525027      begin
    43535028        ScreenTools.Frame(Panel.Canvas, ClientWidth - xPalace - 1, yPalace - 1,
     
    43575032          ClientWidth - xPalace + xSizeBig + 1, yPalace + ySizeBig + 1,
    43585033          $FFFFFF, $B0B0B0);
    4359         DpiBitCanvas(Panel.Canvas, ClientWidth - xPalace, yPalace, xSizeBig,
     5034        DpiBitBltCanvas(Panel.Canvas, ClientWidth - xPalace, yPalace, xSizeBig,
    43605035          ySizeBig, HGrSystem2.Data.Canvas, 70, 123);
    43615036      end
     
    43825057    CopyMiniToPanel;
    43835058    if ClientMode <> cEditMap then // MapBtn icons
    4384       for i := 0 to 5 do
    4385         if i <> 3 then
    4386           Dump(Panel, HGrSystem, xMini + G.lx - 42 + 16 * i, PanelHeight - 26,
    4387             8, 8, 121 + i * 9, 61);
     5059      for I := 0 to 5 do
     5060        if I <> 3 then
     5061          Dump(Panel, HGrSystem, xMini + G.lx - 42 + 16 * I, PanelHeight - 26,
     5062            8, 8, 121 + I * 9, 61);
    43885063
    43895064    if ClientMode = cEditMap then
    43905065    begin
    4391       for i := 0 to TrRow - 1 do
    4392         trix[i] := -1;
     5066      for I := 0 to TrRow - 1 do
     5067        trix[I] := -1;
    43935068      Count := 0;
    4394       for i := 0 to nBrushTypes - 1 do
     5069      for I := 0 to nBrushTypes - 1 do
    43955070      begin // display terrain types
    43965071        if (Count >= TrRow * sb.Position) and (Count < TrRow * (sb.Position + 1))
    43975072        then
    43985073        begin
    4399           trix[Count - TrRow * sb.Position] := BrushTypes[i];
    4400           x := (Count - TrRow * sb.Position) * TrPitch;
     5074          trix[Count - TrRow * sb.Position] := BrushTypes[I];
     5075          X := (Count - TrRow * sb.Position) * TrPitch;
    44015076          xSrcBase := -1;
    4402           case BrushTypes[i] of
     5077          case BrushTypes[I] of
    44035078            0 .. 8:
    44045079              begin
    4405                 xSrc := BrushTypes[i];
     5080                xSrc := BrushTypes[I];
    44065081                ySrc := 0
    44075082              end;
     
    44115086                ySrcBase := 2;
    44125087                xSrc := 0;
    4413                 ySrc := 2 * integer(BrushTypes[i]) - 15
     5088                ySrc := 2 * Integer(BrushTypes[I]) - 15
    44145089              end;
    44155090            fRiver:
     
    44445119                ySrcBase := 2;
    44455120                xSrc := 8;
    4446                 ySrc := 12 + BrushTypes[i] shr 25;
     5121                ySrc := 12 + BrushTypes[I] shr 25;
    44475122              end;
    44485123            tiIrrigation, tiFarm, tiMine, tiBase:
    44495124              begin
    4450                 xSrc := BrushTypes[i] shr 12 - 1;
     5125                xSrc := BrushTypes[I] shr 12 - 1;
    44515126                ySrc := 12
    44525127              end;
     
    44715146          with MainMap do begin
    44725147            if xSrcBase >= 0 then
    4473               Sprite(Panel, HGrTerrain, xTroop + 2 + x, yTroop + 9 - yyt, xxt * 2,
     5148              Sprite(Panel, HGrTerrain, xTroop + 2 + X, yTroop + 9 - yyt, xxt * 2,
    44745149                yyt * 3, 1 + xSrcBase * (xxt * 2 + 1),
    44755150                1 + ySrcBase * (yyt * 3 + 1));
    4476             Sprite(Panel, HGrTerrain, xTroop + 2 + x, yTroop + 9 - yyt, xxt * 2,
     5151            Sprite(Panel, HGrTerrain, xTroop + 2 + X, yTroop + 9 - yyt, xxt * 2,
    44775152              yyt * 3, 1 + xSrc * (xxt * 2 + 1), 1 + ySrc * (yyt * 3 + 1));
    4478             if BrushTypes[i] = BrushType then begin
    4479               ScreenTools.Frame(Panel.Canvas, xTroop + 2 + x,
    4480                 yTroop + 7 - yyt div 2, xTroop + 2 * xxt + x,
     5153            if BrushTypes[I] = BrushType then begin
     5154              ScreenTools.Frame(Panel.Canvas, xTroop + 2 + X,
     5155                yTroop + 7 - yyt div 2, xTroop + 2 * xxt + X,
    44815156                yTroop + 2 * yyt + 11, $000000, $000000);
    4482               ScreenTools.Frame(Panel.Canvas, xTroop + 1 + x,
    4483                 yTroop + 6 - yyt div 2, xTroop + 2 * xxt - 1 + x,
     5157              ScreenTools.Frame(Panel.Canvas, xTroop + 1 + X,
     5158                yTroop + 6 - yyt div 2, xTroop + 2 * xxt - 1 + X,
    44845159                yTroop + 2 * yyt + 10, MainTexture.ColorMark, MainTexture.ColorMark);
    44855160            end;
    44865161          end;
    44875162        end;
    4488         inc(Count)
     5163        Inc(Count)
    44895164      end;
    44905165      case BrushType of
    44915166        fDesert, fPrairie, fTundra, fArctic, fSwamp, fHills, fMountains:
    4492           s := Phrases.Lookup('TERRAIN', BrushType);
     5167          S := Phrases.Lookup('TERRAIN', BrushType);
    44935168        fShore:
    4494           s := Format(Phrases.Lookup('TWOTERRAINS'),
     5169          S := Format(Phrases.Lookup('TWOTERRAINS'),
    44955170            [Phrases.Lookup('TERRAIN', fOcean), Phrases.Lookup('TERRAIN',
    44965171            fShore)]);
    44975172        fGrass:
    4498           s := Format(Phrases.Lookup('TWOTERRAINS'),
     5173          S := Format(Phrases.Lookup('TWOTERRAINS'),
    44995174            [Phrases.Lookup('TERRAIN', fGrass), Phrases.Lookup('TERRAIN',
    45005175            fGrass + 12)]);
    45015176        fForest:
    4502           s := Format(Phrases.Lookup('TWOTERRAINS'),
     5177          S := Format(Phrases.Lookup('TWOTERRAINS'),
    45035178            [Phrases.Lookup('TERRAIN', fForest), Phrases.Lookup('TERRAIN',
    45045179            fJungle)]);
    45055180        fRiver:
    4506           s := Phrases.Lookup('RIVER');
     5181          S := Phrases.Lookup('RIVER');
    45075182        fDeadLands, fDeadLands or fCobalt, fDeadLands or fUranium,
    45085183          fDeadLands or fMercury:
    4509           s := Phrases.Lookup('TERRAIN', 3 * 12 + BrushType shr 25);
     5184          S := Phrases.Lookup('TERRAIN', 3 * 12 + BrushType shr 25);
    45105185        fPrefStartPos:
    4511           s := Phrases.Lookup('MAP_PREFSTART');
     5186          S := Phrases.Lookup('MAP_PREFSTART');
    45125187        fStartPos:
    4513           s := Phrases.Lookup('MAP_START');
     5188          S := Phrases.Lookup('MAP_START');
    45145189        fPoll:
    4515           s := Phrases.Lookup('POLL');
     5190          S := Phrases.Lookup('POLL');
    45165191      else // terrain improvements
    45175192        begin
    45185193          case BrushType of
    45195194            fRoad:
    4520               i := 1;
     5195              I := 1;
    45215196            fRR:
    4522               i := 2;
     5197              I := 2;
    45235198            tiIrrigation:
    4524               i := 4;
     5199              I := 4;
    45255200            tiFarm:
    4526               i := 5;
     5201              I := 5;
    45275202            tiMine:
    4528               i := 7;
     5203              I := 7;
    45295204            fCanal:
    4530               i := 8;
     5205              I := 8;
    45315206            tiFort:
    4532               i := 10;
     5207              I := 10;
    45335208            tiBase:
    4534               i := 12;
     5209              I := 12;
    45355210          end;
    4536           s := Phrases.Lookup('JOBRESULT', i);
     5211          S := Phrases.Lookup('JOBRESULT', I);
    45375212        end
    45385213      end;
    45395214      LoweredTextOut(Panel.Canvas, -1, MainTexture, xTroop + 1,
    4540         PanelHeight - 19, s);
     5215        PanelHeight - 19, S);
    45415216    end
    45425217    else if TroopLoc >= 0 then
     
    45445219      Brush.Style := bsClear;
    45455220      if UnFocus >= 0 then
    4546         with MyUn[UnFocus] do
    4547         with MyModel[mix] do
     5221        with MyUn^[UnFocus] do
     5222        with MyModel^[mix] do
    45485223        begin { display info about selected unit }
    45495224          if Job = jCity then
     
    45515226          else
    45525227            mixShow := mix;
    4553           with Tribe[me].ModelPicture[mixShow] do
     5228          with Tribe[Me].ModelPicture[mixShow] do
    45545229          begin
    45555230            Sprite(Panel, HGr, xMidPanel + 7 + 12, yTroop + 1, 64, 48,
     
    45615236
    45625237          MakeBlue(Panel, xMidPanel + 7 + 12 + 10, yTroop - 13, 44, 12);
    4563           s := MovementToString(MyUn[UnFocus]);
     5238          S := MovementToString(MyUn[UnFocus]);
    45645239          RisedTextOut(Panel.Canvas, xMidPanel + 7 + 12 + 32 -
    4565             BiColorTextWidth(Panel.Canvas, s) div 2, yTroop - 16, s);
    4566 
    4567           s := IntToStr(Health) + '%';
     5240            BiColorTextWidth(Panel.Canvas, S) div 2, yTroop - 16, S);
     5241
     5242          S := IntToStr(Health) + '%';
    45685243          LightGradient(Panel.Canvas, xMidPanel + 7 + 12 + 7, PanelHeight - 22,
    45695244            (Health + 1) div 2, (ColorOfHealth(Health) and $FEFEFE shr 2) * 3);
     
    45725247              div 2, PanelHeight - 22, 50 - (Health + 1) div 2, $000000);
    45735248          RisedTextOut(Panel.Canvas, xMidPanel + 7 + 12 + 32 -
    4574             BiColorTextWidth(Panel.Canvas, s) div 2, PanelHeight - 23, s);
     5249            BiColorTextWidth(Panel.Canvas, S) div 2, PanelHeight - 23, S);
    45755250
    45765251          FrameImage(Panel.Canvas, HGrSystem.Data,
     
    45785253            121 + Exp div ExpCost * 13, 28);
    45795254          if Job = jCity then
    4580             s := Tribe[me].ModelName[-1]
     5255            S := Tribe[Me].ModelName[-1]
    45815256          else
    4582             s := Tribe[me].ModelName[mix];
     5257            S := Tribe[Me].ModelName[mix];
    45835258          if Home >= 0 then
    45845259          begin
    45855260            LoweredTextOut(Panel.Canvas, -1, MainTexture,
    4586               xMidPanel + 7 + xUnitText + 18, yTroop + 5, s);
     5261              xMidPanel + 7 + xUnitText + 18, yTroop + 5, S);
    45875262            LoweredTextOut(Panel.Canvas, -1, MainTexture,
    45885263              xMidPanel + 7 + xUnitText + 18, yTroop + 21,
     
    45915266          else
    45925267            LoweredTextOut(Panel.Canvas, -1, MainTexture,
    4593               xMidPanel + 7 + xUnitText + 18, yTroop + 13, s);
     5268              xMidPanel + 7 + xUnitText + 18, yTroop + 13, S);
    45945269        end;
    45955270
    45965271      if (UnFocus >= 0) and (MyUn[UnFocus].Loc <> TroopLoc) then
    45975272      begin // divide panel
    4598         if SmallScreen and not supervising then
    4599           x := xTroop - 8
     5273        if SmallScreen and not Supervising then
     5274          X := xTroop - 8
    46005275        else
    4601           x := xTroop - 152;
     5276          X := xTroop - 152;
    46025277        Pen.Color := MainTexture.ColorBevelShade;
    4603         MoveTo(x - 1, PanelHeight - MidPanelHeight + 2);
    4604         LineTo(x - 1, PanelHeight);
     5278        MoveTo(X - 1, PanelHeight - MidPanelHeight + 2);
     5279        LineTo(X - 1, PanelHeight);
    46055280        Pen.Color := MainTexture.ColorBevelLight;
    4606         MoveTo(x, PanelHeight - MidPanelHeight + 2);
    4607         LineTo(x, PanelHeight);
    4608       end;
    4609 
    4610       for i := 0 to 23 do
    4611         trix[i] := -1;
     5281        MoveTo(X, PanelHeight - MidPanelHeight + 2);
     5282        LineTo(X, PanelHeight);
     5283      end;
     5284
     5285      for I := 0 to 23 do
     5286        trix[I] := -1;
    46125287      if MyMap[TroopLoc] and fUnit <> 0 then
    46135288      begin
     
    46195294            LoweredTextOut(Panel.Canvas, -1, MainTexture, xTroop + 10,
    46205295              PanelHeight - 24, Phrases.Lookup('PRESENT'));
    4621             Server(sGetDefender, me, TroopLoc, uixDefender);
     5296            Server(sGetDefender, Me, TroopLoc, uixDefender);
    46225297            Count := 0;
    4623             for Prio := true downto false do
     5298            for Prio := True downto False do
    46245299              for uix := 0 to MyRO.nUn - 1 do
    46255300                if (uix = uixDefender) = Prio then
     
    46325307                    begin
    46335308                      trix[Count - TrRow * sb.Position] := uix;
    4634                       MakeUnitInfo(me, unx, UnitInfo);
    4635                       x := (Count - TrRow * sb.Position) * TrPitch;
     5309                      MakeUnitInfo(Me, unx, UnitInfo);
     5310                      X := (Count - TrRow * sb.Position) * TrPitch;
    46365311                      if uix = UnFocus then
    46375312                      begin
    4638                         ScreenTools.Frame(Panel.Canvas, xTroop + 4 + x,
    4639                           yTroop + 3, xTroop + 64 + x, yTroop + 47,
     5313                        ScreenTools.Frame(Panel.Canvas, xTroop + 4 + X,
     5314                          yTroop + 3, xTroop + 64 + X, yTroop + 47,
    46405315                          $000000, $000000);
    4641                         ScreenTools.Frame(Panel.Canvas, xTroop + 3 + x,
    4642                           yTroop + 2, xTroop + 63 + x, yTroop + 46,
     5316                        ScreenTools.Frame(Panel.Canvas, xTroop + 3 + X,
     5317                          yTroop + 2, xTroop + 63 + X, yTroop + 46,
    46435318                          MainTexture.ColorMark, MainTexture.ColorMark);
    46445319                      end
    46455320                      else if (unx.Master >= 0) and (unx.Master = UnFocus) then
    46465321                      begin
    4647                         CFrame(Panel.Canvas, xTroop + 4 + x, yTroop + 3,
    4648                           xTroop + 64 + x, yTroop + 47, 8, $000000);
    4649                         CFrame(Panel.Canvas, xTroop + 3 + x, yTroop + 2,
    4650                           xTroop + 63 + x, yTroop + 46, 8, MainTexture.ColorMark);
     5322                        CFrame(Panel.Canvas, xTroop + 4 + X, yTroop + 3,
     5323                          xTroop + 64 + X, yTroop + 47, 8, $000000);
     5324                        CFrame(Panel.Canvas, xTroop + 3 + X, yTroop + 2,
     5325                          xTroop + 63 + X, yTroop + 46, 8, MainTexture.ColorMark);
    46515326                      end;
    46525327                      NoMapPanel.SetOutput(Panel);
    4653                       NoMapPanel.PaintUnit(xTroop + 2 + x, yTroop + 1, UnitInfo,
     5328                      NoMapPanel.PaintUnit(xTroop + 2 + X, yTroop + 1, UnitInfo,
    46545329                        unx.Status);
    46555330                      if (ClientMode < scContact) and
     
    46575332                        (unx.Status and (usStay or usRecover or usGoto) <> 0))
    46585333                      then
    4659                         Sprite(Panel, HGrSystem, xTroop + 2 + 60 - 20 + x,
     5334                        Sprite(Panel, HGrSystem, xTroop + 2 + 60 - 20 + X,
    46605335                          yTroop + 35, 20, 20, 81, 25);
    46615336
    4662                       if not supervising then
     5337                      if not Supervising then
    46635338                      begin
    4664                         MakeBlue(Panel, xTroop + 2 + 10 + x,
     5339                        MakeBlue(Panel, xTroop + 2 + 10 + X,
    46655340                          yTroop - 13, 44, 12);
    4666                         s := MovementToString(unx);
     5341                        S := MovementToString(unx);
    46675342                        RisedTextOut(Panel.Canvas,
    4668                           xTroop + x + 34 - BiColorTextWidth(Panel.Canvas, s)
    4669                           div 2, yTroop - 16, s);
     5343                          xTroop + X + 34 - BiColorTextWidth(Panel.Canvas, S)
     5344                          div 2, yTroop - 16, S);
    46705345                      end;
    46715346                    end;
    4672                     inc(Count)
     5347                    Inc(Count)
    46735348                  end;
    46745349                end; // for uix:=0 to MyRO.nUn-1
    4675             assert(Count = TrCnt);
     5350            Assert(Count = TrCnt);
    46765351          end;
    46775352        end
     
    46805355          LoweredTextOut(Panel.Canvas, -1, MainTexture, xTroop + 8,
    46815356            PanelHeight - 24, Phrases.Lookup('PRESENT'));
    4682           Server(sGetUnits, me, TroopLoc, Count);
    4683           for i := 0 to Count - 1 do
    4684             if (i >= TrRow * sb.Position) and (i < TrRow * (sb.Position + 1)) then
     5357          Server(sGetUnits, Me, TroopLoc, Count);
     5358          for I := 0 to Count - 1 do
     5359            if (I >= TrRow * sb.Position) and (I < TrRow * (sb.Position + 1)) then
    46855360            begin // display enemy units
    4686               trix[i - TrRow * sb.Position] := i;
    4687               x := (i - TrRow * sb.Position) * TrPitch;
     5361              trix[I - TrRow * sb.Position] := I;
     5362              X := (I - TrRow * sb.Position) * TrPitch;
    46885363              NoMapPanel.SetOutput(Panel);
    4689               NoMapPanel.PaintUnit(xTroop + 2 + x, yTroop + 1,
    4690                 MyRO.EnemyUn[MyRO.nEnemyUn + i], 0);
     5364              NoMapPanel.PaintUnit(xTroop + 2 + X, yTroop + 1,
     5365                MyRO.EnemyUn[MyRO.nEnemyUn + I], 0);
    46915366            end;
    46925367        end;
    46935368      end;
    4694       if not SmallScreen or supervising then
     5369      if not SmallScreen or Supervising then
    46955370      begin // show terrain and improvements
    46965371        with NoMapPanel do
     
    46985373        if (UnFocus >= 0) and (MyUn[UnFocus].Job <> jNone) then begin
    46995374          JobFocus := MyUn[UnFocus].Job;
    4700           Server(sGetJobProgress, me, MyUn[UnFocus].Loc, JobProgressData);
     5375          Server(sGetJobProgress, Me, MyUn[UnFocus].Loc, JobProgressData);
    47015376          MakeBlue(Panel, xTerrain - 72, 148 - 17, 144, 31);
    47025377          PaintRelativeProgressBar(Panel.Canvas, 3, xTerrain - 68, 148 + 3, 63,
    47035378            JobProgressData[JobFocus].Done,
    47045379            JobProgressData[JobFocus].NextTurnPlus,
    4705             JobProgressData[JobFocus].Required, true, MainTexture);
    4706           s := Format('%s/%s',
     5380            JobProgressData[JobFocus].Required, True, MainTexture);
     5381          S := Format('%s/%s',
    47075382            [ScreenTools.MovementToString(JobProgressData[JobFocus].Done),
    47085383            ScreenTools.MovementToString(JobProgressData[JobFocus].Required)]);
    4709           RisedTextOut(Panel.Canvas, xTerrain + 6, 148 - 3, s);
     5384          RisedTextOut(Panel.Canvas, xTerrain + 6, 148 - 3, S);
    47105385          Tile := MyMap[MyUn[UnFocus].Loc];
    47115386          if (JobFocus = jRoad) and (Tile and fRiver <> 0) then
     
    47225397              JobFocus := nJob + 4
    47235398          end;
    4724           s := Phrases.Lookup('JOBRESULT', JobFocus);
     5399          S := Phrases.Lookup('JOBRESULT', JobFocus);
    47255400          RisedTextOut(Panel.Canvas, xTerrain - BiColorTextWidth(Panel.Canvas,
    4726             s) div 2, 148 - 19, s);
     5401            S) div 2, 148 - 19, S);
    47275402        end;
    47285403        if MyMap[TroopLoc] and (fTerrain or fSpecial) = fGrass or fSpecial1 then
    4729           s := Phrases.Lookup('TERRAIN', fGrass + 12)
     5404          S := Phrases.Lookup('TERRAIN', fGrass + 12)
    47305405        else if MyMap[TroopLoc] and fDeadLands <> 0 then
    4731           s := Phrases.Lookup('TERRAIN', 3 * 12)
     5406          S := Phrases.Lookup('TERRAIN', 3 * 12)
    47325407        else if (MyMap[TroopLoc] and fTerrain = fForest) and
    47335408          IsJungle(TroopLoc div G.lx) then
    4734           s := Phrases.Lookup('TERRAIN', fJungle)
     5409          S := Phrases.Lookup('TERRAIN', fJungle)
    47355410        else
    4736           s := Phrases.Lookup('TERRAIN', MyMap[TroopLoc] and fTerrain);
    4737         RisedTextOut(Panel.Canvas, xTerrain - BiColorTextWidth(Panel.Canvas, s)
    4738           div 2, 99, s);
     5411          S := Phrases.Lookup('TERRAIN', MyMap[TroopLoc] and fTerrain);
     5412        RisedTextOut(Panel.Canvas, xTerrain - BiColorTextWidth(Panel.Canvas, S)
     5413          div 2, 99, S);
    47395414      end;
    47405415
     
    47475422  end;
    47485423
    4749   for i := 0 to ControlCount - 1 do
    4750     if Controls[i] is TButtonB then
    4751       with TButtonB(Controls[i]) do
     5424  for I := 0 to ControlCount - 1 do
     5425    if Controls[I] is TButtonB then
     5426      with TButtonB(Controls[I]) do
    47525427      begin
    47535428        if Visible then
     
    47655440  if ClientMode <> cEditMap then
    47665441  begin
    4767     for i := 0 to ControlCount - 1 do
    4768       if Controls[i] is TButtonC then
    4769         with TButtonC(Controls[i]) do
     5442    for I := 0 to ControlCount - 1 do
     5443      if Controls[I] is TButtonC then
     5444        with TButtonC(Controls[I]) do
    47705445        begin
    47715446          Dump(Panel, HGrSystem, Left, Top - self.ClientHeight + PanelHeight,
     
    48075482    TrueMoney := MyRO.Money;
    48085483    TrueResearch := MyRO.Research;
    4809     if supervising then
     5484    if Supervising then
    48105485    begin // normalize values from after-turn state
    4811       dec(TrueMoney, TaxSum);
     5486      Dec(TrueMoney, TaxSum);
    48125487      if TrueMoney < 0 then
    48135488        TrueMoney := 0; // shouldn't happen
    4814       dec(TrueResearch, ScienceSum);
     5489      Dec(TrueResearch, ScienceSum);
    48155490      if TrueResearch < 0 then
    48165491        TrueResearch := 0; // shouldn't happen
     
    48205495    ImageOp_BCC(TopBar, Templates.Data, Point(xTreasurySection + 8, 1), TreasuryIcon.BoundsRect,
    48215496      $40A040, $4030C0);
    4822     s := IntToStr(TrueMoney);
     5497    S := IntToStr(TrueMoney);
    48235498    LoweredTextOut(TopBar.Canvas, -1, MainTexture, xTreasurySection + 48, 0,
    4824       s + '%c');
     5499      S + '%c');
    48255500    if MyRO.Government <> gAnarchy then
    48265501    begin
     
    48285503        $0000C0, $0080C0);
    48295504      if TaxSum >= 0 then
    4830         s := Format(Phrases.Lookup('MONEYGAINPOS'), [TaxSum])
     5505        S := Format(Phrases.Lookup('MONEYGAINPOS'), [TaxSum])
    48315506      else
    4832         s := Format(Phrases.Lookup('MONEYGAINNEG'), [TaxSum]);
     5507        S := Format(Phrases.Lookup('MONEYGAINNEG'), [TaxSum]);
    48335508      LoweredTextOut(TopBar.Canvas, -1, MainTexture, xTreasurySection + 48 +
    4834         15, 18, s);
     5509        15, 18, S);
    48355510    end;
    48365511
     
    48525527      else
    48535528        CostFactor := 2;
    4854       Server(sGetTechCost, me, 0, i);
     5529      Server(sGetTechCost, Me, 0, I);
    48555530      CostFactor := CostFactor * 22; // length of progress bar
    48565531      PaintRelativeProgressBar(TopBar.Canvas, 2, xResearchSection + 48 + 1, 26,
    4857         CostFactor, TrueResearch, ScienceSum, i, true, MainTexture);
     5532        CostFactor, TrueResearch, ScienceSum, I, True, MainTexture);
    48585533
    48595534      if MyRO.ResearchTech < 0 then
    4860         s := Phrases.Lookup('SCIENCE')
     5535        S := Phrases.Lookup('SCIENCE')
    48615536      else if MyRO.ResearchTech = adMilitary then
    4862         s := Phrases.Lookup('INITUNIT')
     5537        S := Phrases.Lookup('INITUNIT')
    48635538      else
    48645539      begin
    4865         s := Phrases.Lookup('ADVANCES', MyRO.ResearchTech);
     5540        S := Phrases.Lookup('ADVANCES', MyRO.ResearchTech);
    48665541        if MyRO.ResearchTech in FutureTech then
    48675542          if MyRO.Tech[MyRO.ResearchTech] >= 1 then
    4868             s := s + ' ' + IntToStr(MyRO.Tech[MyRO.ResearchTech] + 1)
     5543            S := S + ' ' + IntToStr(MyRO.Tech[MyRO.ResearchTech] + 1)
    48695544          else
    4870             s := s + ' 1';
     5545            S := S + ' 1';
    48715546      end;
    48725547      if ScienceSum > 0 then
    48735548      begin
    48745549        { j:=(i-MyRO.Research-1) div ScienceSum +1;
    4875           if j<1 then j:=1;
    4876           if j>1 then
    4877           s:=Format(Phrases.Lookup('TECHWAIT'),[s,j]); }
     5550          if J<1 then J:=1;
     5551          if J>1 then
     5552          S:=Format(Phrases.Lookup('TECHWAIT'),[S,J]); }
    48785553        LoweredTextOut(TopBar.Canvas, -1, MainTexture,
    4879           xResearchSection + 48, 0, s);
     5554          xResearchSection + 48, 0, S);
    48805555      end
    48815556      else
    48825557        LoweredTextOut(TopBar.Canvas, -1, MainTexture,
    4883           xResearchSection + 48, 0, s);
     5558          xResearchSection + 48, 0, S);
    48845559    end
    48855560    else
     
    48895564      ImageOp_BCC(TopBar, Templates.Data, Point(xResearchSection + 48 + CostFactor + 11,
    48905565        22), ChangeIcon.BoundsRect, $0000C0, $0080C0);
    4891       s := Format(Phrases.Lookup('TECHGAIN'), [ScienceSum]);
     5566      S := Format(Phrases.Lookup('TECHGAIN'), [ScienceSum]);
    48925567      LoweredTextOut(TopBar.Canvas, -1, MainTexture, xResearchSection + 48 +
    4893         CostFactor + 26, 18, s);
     5568        CostFactor + 26, 18, S);
    48945569    end;
    48955570  end;
     
    48975572  begin
    48985573    TopBar.Canvas.Font.Assign(UniFont[ftCaption]);
    4899     s := TurnToString(MyRO.Turn);
     5574    S := TurnToString(MyRO.Turn);
    49005575    RisedTextOut(TopBar.Canvas,
    4901       40 + (xTreasurySection - 40 - BiColorTextWidth(TopBar.Canvas, s))
    4902       div 2, 6, s);
     5576      40 + (xTreasurySection - 40 - BiColorTextWidth(TopBar.Canvas, S))
     5577      div 2, 6, S);
    49035578    TopBar.Canvas.Font.Assign(UniFont[ftNormal]);
    49045579  end;
     
    49085583procedure TMainScreen.FocusNextUnit(Dir: Integer);
    49095584var
    4910   i, uix, NewFocus: Integer;
     5585  I, uix, NewFocus: Integer;
    49115586begin
    49125587  if ClientMode >= scContact then
     
    49155590  PaintDestination;
    49165591  NewFocus := -1;
    4917   for i := 1 to MyRO.nUn do begin
    4918     uix := (UnFocus + i * Dir + MyRO.nUn) mod MyRO.nUn;
     5592  for I := 1 to MyRO.nUn do begin
     5593    uix := (UnFocus + I * Dir + MyRO.nUn) mod MyRO.nUn;
    49195594    if (MyUn[uix].Loc >= 0) and (MyUn[uix].Status and usStay = 0) then begin
    49205595      NewFocus := uix;
     
    49295604end;
    49305605
    4931 procedure TMainScreen.FocusOnLoc(Loc: integer; Options: integer = 0);
     5606procedure TMainScreen.FocusOnLoc(Loc: Integer; Options: Integer = 0);
    49325607var
    4933   dx: integer;
    4934   Outside, Changed: boolean;
     5608  dx: Integer;
     5609  Outside, Changed: Boolean;
    49355610begin
    49365611  with MainMap do begin
     
    49405615      (Loc div G.lx >= yw + (MapHeight - 1) div yyt - 2));
    49415616  end;
    4942   Changed := true;
     5617  Changed := True;
    49435618  if Outside then begin
    49445619    Centre(Loc);
     
    49485623    PaintAllMaps
    49495624  else
    4950     Changed := false;
     5625    Changed := False;
    49515626  if Options and flRepaintPanel <> 0 then
    49525627    PanelPaint;
     
    49585633var
    49595634  Dist, TestDist: Single;
    4960   i, uix, NewFocus: Integer;
     5635  I, uix, NewFocus: Integer;
    49615636  GotoOnly: Boolean;
    49625637begin
     
    49685643  for GotoOnly := GoOnPhase downto False do begin
    49695644    NewFocus := -1;
    4970     for i := 1 to MyRO.nUn do begin
    4971       uix := (UnFocus + i) mod MyRO.nUn;
     5645    for I := 1 to MyRO.nUn do begin
     5646      uix := (UnFocus + I) mod MyRO.nUn;
    49725647      if (MyUn[uix].Loc >= 0) and (MyUn[uix].Job = jNone) and
    49735648        (MyUn[uix].Status and (usStay or usRecover or usWaiting) = usWaiting)
     
    50085683end;
    50095684
    5010 procedure TMainScreen.Scroll(dx, dy: integer);
     5685procedure TMainScreen.Scroll(dx, dy: Integer);
    50115686begin
    50125687  xw := (xw + G.lx + dx) mod G.lx;
     
    50325707procedure TMainScreen.Timer1Timer(Sender: TObject);
    50335708var
    5034   dx, dy, ScrollSpeed: integer;
    5035 begin
    5036   if idle and (me >= 0) and (GameMode <> cMovie) then
     5709  dx, dy, ScrollSpeed: Integer;
     5710begin
     5711  if Idle and (Me >= 0) and (GameMode <> cMovie) then
    50375712    if (fsModal in DpiScreen.ActiveForm.FormState) or
    50385713      (DpiScreen.ActiveForm is TBufferedDrawDlg) and
     
    50425717      if not BlinkON then
    50435718      begin
    5044         BlinkON := true;
     5719        BlinkON := True;
    50455720        if UnFocus >= 0 then
    50465721          PaintLocTemp(MyUn[UnFocus].Loc)
    5047         else if TurnComplete and not supervising then
     5722        else if TurnComplete and not Supervising then
    50485723          EOT.SetButtonIndexFast(eotBlinkOn);
    50495724      end;
     
    50575732        dx := 0;
    50585733        dy := 0;
    5059         if DpiMouse.CursorPos.y < DpiScreen.height - PanelHeight then
    5060           if DpiMouse.CursorPos.x = 0 then
     5734        if DpiMouse.CursorPos.Y < DpiScreen.height - PanelHeight then
     5735          if DpiMouse.CursorPos.X = 0 then
    50615736            dx := -ScrollSpeed // scroll left
    5062           else if DpiMouse.CursorPos.x = DpiScreen.width - 1 then
     5737          else if DpiMouse.CursorPos.X = DpiScreen.width - 1 then
    50635738            dx := ScrollSpeed; // scroll right
    5064         if DpiMouse.CursorPos.y = 0 then
     5739        if DpiMouse.CursorPos.Y = 0 then
    50655740          dy := -ScrollSpeed // scroll up
    5066         else if (DpiMouse.CursorPos.y = DpiScreen.height - 1) and
    5067           (DpiMouse.CursorPos.x >= TerrainBtn.Left + TerrainBtn.width) and
    5068           (DpiMouse.CursorPos.x < xRightPanel + 10 - 8) then
     5741        else if (DpiMouse.CursorPos.Y = DpiScreen.height - 1) and
     5742          (DpiMouse.CursorPos.X >= TerrainBtn.Left + TerrainBtn.width) and
     5743          (DpiMouse.CursorPos.X < xRightPanel + 10 - 8) then
    50695744          dy := ScrollSpeed; // scroll down
    50705745        if (dx <> 0) or (dy <> 0) then
     
    50795754      BlinkTime := (BlinkTime + 1) mod (BlinkOnTime + BlinkOffTime);
    50805755      BlinkON := BlinkTime >= BlinkOffTime;
    5081       DestinationMarkON := true;
     5756      DestinationMarkON := True;
    50825757      if UnFocus >= 0 then
    50835758      begin
     
    50905765        end;
    50915766      end
    5092       else if TurnComplete and not supervising then
     5767      else if TurnComplete and not Supervising then
    50935768      begin
    50945769        if BlinkTime = 0 then
     
    51005775end;
    51015776
    5102 procedure TMainScreen.SetMapPos(Loc: integer; MapPos: TPoint);
     5777procedure TMainScreen.SetMapPos(Loc: Integer; MapPos: TPoint);
    51035778begin
    51045779  with MainMap do begin
     
    51185793end;
    51195794
    5120 procedure TMainScreen.Centre(Loc: integer);
     5795procedure TMainScreen.Centre(Loc: Integer);
    51215796begin
    51225797  SetMapPos(Loc, Point(MapWidth div 2, MapHeight div 2));
    51235798end;
    51245799
    5125 function TMainScreen.ZoomToCity(Loc: integer; NextUnitOnClose: boolean = false;
    5126   ShowEvent: integer = 0): boolean;
    5127 begin
    5128   result := MyMap[Loc] and (fOwned or fSpiedOut) <> 0;
    5129   if result then
     5800function TMainScreen.ZoomToCity(Loc: Integer; NextUnitOnClose: Boolean = False;
     5801  ShowEvent: Integer = 0): Boolean;
     5802begin
     5803  Result := MyMap[Loc] and (fOwned or fSpiedOut) <> 0;
     5804  if Result then
    51305805    with CityDlg do
    51315806    begin
     
    51535828end;
    51545829
    5155 function TMainScreen.LocationOfScreenPixel(x, y: integer): Integer;
     5830function TMainScreen.LocationOfScreenPixel(X, Y: Integer): Integer;
    51565831var
    5157   qx, qy: integer;
     5832  qx, qy: Integer;
    51585833begin
    51595834  with MainMap do begin
    5160     qx := (x * (yyt * 2) + y * (xxt * 2) + xxt * yyt * 2) div (xxt * yyt * 4) - 1;
    5161     qy := (y * (xxt * 2) - x * (yyt * 2) - xxt * yyt * 2 + 4000 * xxt * yyt)
     5835    qx := (X * (yyt * 2) + Y * (xxt * 2) + xxt * yyt * 2) div (xxt * yyt * 4) - 1;
     5836    qy := (Y * (xxt * 2) - X * (yyt * 2) - xxt * yyt * 2 + 4000 * xxt * yyt)
    51625837      div (xxt * yyt * 4) - 999;
    51635838    Result := (xw + (qx - qy + 2048) div 2 - 1024 + G.lx) mod G.lx + G.lx *
     
    51735848
    51745849procedure TMainScreen.MapBoxMouseDown(Sender: TObject; Button: TMouseButton;
    5175   Shift: TShiftState; x, y: integer);
     5850  Shift: TShiftState; X, Y: Integer);
    51765851var
    5177   i, uix, emix, p1, dx, dy, MouseLoc: integer;
     5852  I, uix, emix, p1, dx, dy, MouseLoc: Integer;
    51785853  EditTileData: TEditTileData;
    5179   m, m2: TDpiMenuItem;
     5854  M, m2: TDpiMenuItem;
    51805855  MoveAdviceData: TMoveAdviceData;
    5181   DoCenter: boolean;
     5856  DoCenter: Boolean;
    51825857begin
    51835858  if GameMode = cMovie then
    5184     exit;
    5185 
    5186   if CityDlg.Visible then
     5859    Exit;
     5860
     5861  if Assigned(FCityDlg) and CityDlg.Visible then
    51875862    CityDlg.Close;
    5188   if UnitStatDlg.Visible then
     5863  if Assigned(FUnitStatDlg) and UnitStatDlg.Visible then
    51895864    UnitStatDlg.Close;
    5190   MouseLoc := LocationOfScreenPixel(x, y);
     5865  MouseLoc := LocationOfScreenPixel(X, Y);
    51915866  if (MouseLoc < 0) or (MouseLoc >= G.lx * G.ly) then
    5192     exit;
     5867    Exit;
    51935868  if (Button = mbLeft) and not(ssShift in Shift) then
    51945869  begin
    5195     DoCenter := true;
     5870    DoCenter := True;
    51965871    if ClientMode = cEditMap then
    51975872    begin
    5198       DoCenter := false;
     5873      DoCenter := False;
    51995874      EditTileData.Loc := MouseLoc;
    52005875      if ssCtrl in Shift then // toggle special resource
     
    52345909      else
    52355910        EditTileData.NewTile := MyMap[MouseLoc] xor BrushType;
    5236       Server(sEditTile, me, 0, EditTileData);
    5237       Edited := true;
     5911      Server(sEditTile, Me, 0, EditTileData);
     5912      Edited := True;
    52385913      BrushLoc := MouseLoc;
    52395914      PaintLoc(MouseLoc, 2);
    52405915      MiniMapPaint;
    5241       DpiBitCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
     5916      DpiBitBltCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
    52425917        MiniMap.Bitmap.Canvas, 0, 0);
    52435918      with MainMap do begin
     
    52615936      begin
    52625937        ZoomToCity(MouseLoc);
    5263         DoCenter := false;
     5938        DoCenter := False;
    52645939      end
    52655940      else
    52665941      begin
    52675942        UnitStatDlg.ShowNewContent_EnemyCity(wmPersistent, MouseLoc);
    5268         DoCenter := false;
     5943        DoCenter := False;
    52695944      end;
    52705945    end
     
    52725947      if MyMap[MouseLoc] and fOwned <> 0 then
    52735948      begin
    5274         DoCenter := false;
    5275         if not supervising and (ClientMode < scContact) then
     5949        DoCenter := False;
     5950        if not Supervising and (ClientMode < scContact) then
    52765951        begin // not in negotiation mode
    52775952          if (UnFocus >= 0) and (MyUn[UnFocus].Loc = MouseLoc) then
    52785953          begin // rotate
    52795954            uix := (UnFocus + 1) mod MyRO.nUn;
    5280             i := MyRO.nUn - 1;
    5281             while i > 0 do
     5955            I := MyRO.nUn - 1;
     5956            while I > 0 do
    52825957            begin
    52835958              if (MyUn[uix].Loc = MouseLoc) and (MyUn[uix].Job = jNone) and
     
    52855960                usWaiting) = usWaiting) then
    52865961                Break;
    5287               dec(i);
     5962              Dec(I);
    52885963              uix := (uix + 1) mod MyRO.nUn;
    52895964            end;
    5290             if i = 0 then
     5965            if I = 0 then
    52915966              uix := UnFocus;
    52925967          end
    52935968          else
    5294             Server(sGetDefender, me, MouseLoc, uix);
     5969            Server(sGetDefender, Me, MouseLoc, uix);
    52955970          if uix <> UnFocus then
    52965971            SetUnFocus(uix);
    5297           TurnComplete := false;
     5972          TurnComplete := False;
    52985973          EOT.ButtonIndex := eotGray;
    52995974        end;
     
    53035978      else if (MyMap[MouseLoc] and fSpiedOut <> 0) and not(ssCtrl in Shift) then
    53045979      begin
    5305         DoCenter := false;
     5980        DoCenter := False;
    53065981        SetTroopLoc(MouseLoc);
    53075982        PanelPaint;
     
    53095984      else
    53105985      begin
    5311         DoCenter := false;
     5986        DoCenter := False;
    53125987        UnitStatDlg.ShowNewContent_EnemyLoc(wmPersistent, MouseLoc);
    53135988      end;
     
    53215996    not(ssShift in Shift) then
    53225997  begin
    5323     if supervising then
     5998    if Supervising then
    53245999    begin
    53256000      EditLoc := MouseLoc;
    5326       Server(sGetModels, me, 0, nil^);
     6001      Server(sGetModels, Me, 0, nil^);
    53276002      EmptyMenu(mCreateUnit);
    53286003      for p1 := 0 to nPl - 1 do
    53296004        if 1 shl p1 and MyRO.Alive <> 0 then
    53306005        begin
    5331           m := TDpiMenuItem.Create(mCreateUnit);
    5332           m.Caption := Tribe[p1].TPhrase('SHORTNAME');
     6006          M := TDpiMenuItem.Create(mCreateUnit);
     6007          M.Caption := Tribe[p1].TPhrase('SHORTNAME');
    53336008          for emix := MyRO.nEnemyModel - 1 downto 0 do
    53346009            if (MyRO.EnemyModel[emix].Owner = p1) and
    5335               (Server(sCreateUnit - sExecute + p1 shl 4, me,
     6010              (Server(sCreateUnit - sExecute + p1 shl 4, Me,
    53366011              MyRO.EnemyModel[emix].mix, MouseLoc) >= rExecuted) then
    53376012            begin
    53386013              if not Assigned(Tribe[p1].ModelPicture[MyRO.EnemyModel[emix].mix].HGr) then
    53396014                InitEnemyModel(emix);
    5340               m2 := TDpiMenuItem.Create(m);
     6015              m2 := TDpiMenuItem.Create(M);
    53416016              m2.Caption := Tribe[p1].ModelName[MyRO.EnemyModel[emix].mix];
    53426017              m2.Tag := p1 shl 16 + MyRO.EnemyModel[emix].mix;
    53436018              m2.OnClick := CreateUnitClick;
    5344               m.Add(m2);
     6019              M.Add(m2);
    53456020            end;
    5346           m.Visible := m.Count > 0;
    5347           mCreateUnit.Add(m);
     6021          M.Visible := M.Count > 0;
     6022          mCreateUnit.Add(M);
    53486023        end;
    53496024      if FullScreen then
    5350         EditPopup.Popup(Left + x, Top + y)
     6025        EditPopup.Popup(Left + X, Top + Y)
    53516026      else
    5352         EditPopup.Popup(Left + x + 4,
    5353           Top + y + DpiGetSystemMetrics(SM_CYCAPTION) + 4);
     6027        EditPopup.Popup(Left + X + 4,
     6028          Top + Y + DpiGetSystemMetrics(SM_CYCAPTION) + 4);
    53546029    end
    53556030    else if (UnFocus >= 0) and (MyUn[UnFocus].Loc <> MouseLoc) then
     
    53626037        if abs(dx) + abs(dy) < 3 then
    53636038        begin
    5364           DestinationMarkON := false;
     6039          DestinationMarkON := False;
    53656040          PaintDestination;
    53666041          Status := Status and ($FFFF - usStay - usRecover - usGoto - usEnhance)
     
    53756050            with MyUn[UnFocus], BattleDlg.Forecast do
    53766051            begin
    5377               pAtt := me;
     6052              pAtt := Me;
    53786053              mixAtt := mix;
    53796054              HealthAtt := Health;
     
    53826057            end;
    53836058            BattleDlg.Forecast.Movement := MyUn[UnFocus].Movement;
    5384             if (Server(sGetBattleForecastEx, me, MouseLoc, BattleDlg.Forecast)
     6059            if (Server(sGetBattleForecastEx, Me, MouseLoc, BattleDlg.Forecast)
    53856060              >= rExecuted) and (BattleDlg.Forecast.EndHealthAtt <= 0) then
    53866061            begin
    53876062              BattleDlg.uix := UnFocus;
    53886063              BattleDlg.ToLoc := MouseLoc;
    5389               BattleDlg.IsSuicideQuery := true;
     6064              BattleDlg.IsSuicideQuery := True;
    53906065              BattleDlg.ShowModal;
    53916066              if BattleDlg.ModalResult <> mrOK then
    5392                 exit;
     6067                Exit;
    53936068            end;
    53946069          end;
    5395           DestinationMarkON := false;
     6070          DestinationMarkON := False;
    53966071          PaintDestination;
    53976072          Status := Status and not(usStay or usRecover or usEnhance) or
    53986073            usWaiting;
    5399           MoveToLoc(MouseLoc, false); { goto }
     6074          MoveToLoc(MouseLoc, False); { goto }
    54006075        end;
    54016076      end;
     
    54046079    (MyModel[MyUn[UnFocus].mix].Kind in [mkSettler, mkSlaves]) then
    54056080  begin
    5406     DestinationMarkON := false;
     6081    DestinationMarkON := False;
    54076082    PaintDestination;
    54086083    MyUn[UnFocus].Status := MyUn[UnFocus].Status and
     
    54106085    uix := UnFocus;
    54116086    if MouseLoc <> MyUn[uix].Loc then
    5412       MoveToLoc(MouseLoc, true); { goto }
     6087      MoveToLoc(MouseLoc, True); { goto }
    54136088    if (UnFocus = uix) and (MyUn[uix].Loc = MouseLoc) then
    5414       MenuClick(mEnhance);
     6089      mEnhance.Click;
    54156090  end
    54166091  else if (Button = mbLeft) and (ssShift in Shift) and
     
    54236098    with MyUn[UnFocus], BattleDlg.Forecast do
    54246099    begin
    5425       pAtt := me;
     6100      pAtt := Me;
    54266101      mixAtt := mix;
    54276102      HealthAtt := Health;
     
    54306105    end;
    54316106    BattleDlg.Forecast.Movement := MyUn[UnFocus].Movement;
    5432     if Server(sGetBattleForecastEx, me, MouseLoc, BattleDlg.Forecast) >= rExecuted
     6107    if Server(sGetBattleForecastEx, Me, MouseLoc, BattleDlg.Forecast) >= rExecuted
    54336108    then
    54346109    begin
    54356110      BattleDlg.uix := UnFocus;
    54366111      BattleDlg.ToLoc := MouseLoc;
    5437       BattleDlg.Left := x - BattleDlg.width div 2;
     6112      BattleDlg.Left := X - BattleDlg.width div 2;
    54386113      if BattleDlg.Left < 0 then
    54396114        BattleDlg.Left := 0
    54406115      else if BattleDlg.Left + BattleDlg.width > DpiScreen.width then
    54416116        BattleDlg.Left := DpiScreen.width - BattleDlg.width;
    5442       BattleDlg.Top := y - BattleDlg.height div 2;
     6117      BattleDlg.Top := Y - BattleDlg.height div 2;
    54436118      if BattleDlg.Top < 0 then
    54446119        BattleDlg.Top := 0
    54456120      else if BattleDlg.Top + BattleDlg.height > DpiScreen.height then
    54466121        BattleDlg.Top := DpiScreen.height - BattleDlg.height;
    5447       BattleDlg.IsSuicideQuery := false;
     6122      BattleDlg.IsSuicideQuery := False;
    54486123      BattleDlg.Show;
    54496124    end;
     
    54516126end;
    54526127
    5453 function TMainScreen.MoveUnit(dx, dy: integer; Options: integer): integer;
     6128function TMainScreen.MoveUnit(dx, dy: Integer; Options: Integer): Integer;
    54546129// move focused unit to adjacent tile
    54556130var
    5456   i, cix, uix, euix, FromLoc, ToLoc, DirCode, UnFocus0, Defender, Mission, p1,
    5457     NewTiles, cixChanged: integer;
     6131  I, cix, uix, euix, FromLoc, ToLoc, DirCode, UnFocus0, Defender, Mission, p1,
     6132    NewTiles, cixChanged: Integer;
    54586133  OldToTile: Cardinal;
    54596134  CityCaptured, IsAttack, OldUnrest, NewUnrest, NeedEcoUpdate, NeedRepaintPanel,
    5460     ToTransport, ToShip: boolean;
     6135    ToTransport, ToShip: Boolean;
    54616136  PlaneReturnData: TPlaneReturnData;
    54626137  QueryItem: string;
    54636138begin
    5464   result := eInvalid;
     6139  Result := eInvalid;
    54656140  UnFocus0 := UnFocus;
    54666141  FromLoc := MyUn[UnFocus].Loc;
     
    54686143  if (ToLoc < 0) or (ToLoc >= G.lx * G.ly) then
    54696144  begin
    5470     result := eInvalid;
    5471     exit;
     6145    Result := eInvalid;
     6146    Exit;
    54726147  end;
    54736148  if MyMap[ToLoc] and fStealthUnit <> 0 then
    54746149  begin
    54756150    SoundMessage(Phrases.Lookup('ATTACKSTEALTH'), '');
    5476     exit;
     6151    Exit;
    54776152  end;
    54786153  if MyMap[ToLoc] and fHiddenUnit <> 0 then
    54796154  begin
    54806155    SoundMessage(Phrases.Lookup('ATTACKSUB'), '');
    5481     exit;
     6156    Exit;
    54826157  end;
    54836158
     
    54896164    begin
    54906165      SoundMessage(Phrases.Lookup('NOATTACKER'), '');
    5491       exit;
     6166      Exit;
    54926167    end;
    54936168    euix := MyRO.nEnemyUn - 1;
    54946169    while (euix >= 0) and (MyRO.EnemyUn[euix].Loc <> ToLoc) do
    5495       dec(euix);
     6170      Dec(euix);
    54966171  end;
    54976172
    54986173  DirCode := dx and 7 shl 4 + dy and 7 shl 7;
    5499   result := Server(sMoveUnit - sExecute + DirCode, me, UnFocus, nil^);
    5500   if (result < rExecuted) and (MyUn[UnFocus].Job > jNone) then
    5501     Server(sStartJob + jNone shl 4, me, UnFocus, nil^);
    5502   if (result < rExecuted) and (result <> eNoTime_Move) then
    5503   begin
    5504     case result of
     6174  Result := Server(sMoveUnit - sExecute + DirCode, Me, UnFocus, nil^);
     6175  if (Result < rExecuted) and (MyUn[UnFocus].Job > jNone) then
     6176    Server(sStartJob + jNone shl 4, Me, UnFocus, nil^);
     6177  if (Result < rExecuted) and (Result <> eNoTime_Move) then
     6178  begin
     6179    case Result of
    55056180      eNoTime_Load:
    55066181        if MyModel[MyUn[UnFocus].mix].Domain = dAir then
     
    55386213            (MyMap[ToLoc] and (fUnit or fOwned) = fUnit or fOwned) then
    55396214          begin // false load attempt
    5540             ToShip := false;
    5541             ToTransport := false;
     6215            ToShip := False;
     6216            ToTransport := False;
    55426217            for uix := 0 to MyRO.nUn - 1 do
    55436218              if (MyUn[uix].Loc = ToLoc) and
    55446219                (MyModel[MyUn[uix].mix].Domain = dSea) then
    55456220              begin
    5546                 ToShip := true;
     6221                ToShip := True;
    55476222                if MyModel[MyUn[uix].mix].Cap[mcSeaTrans] > 0 then
    5548                   ToTransport := true;
     6223                  ToTransport := True;
    55496224              end;
    55506225            if ToTransport then
     
    55616236      Play('NOMOVE_DEFAULT');
    55626237    end;
    5563     exit;
    5564   end;
    5565 
    5566   if ((result = eWon) or (result = eLost) or (result = eBloody)) and
     6238    Exit;
     6239  end;
     6240
     6241  if ((Result = eWon) or (Result = eLost) or (Result = eBloody)) and
    55676242    (MyUn[UnFocus].Movement < 100) and
    55686243    (MyModel[MyUn[UnFocus].mix].Cap[mcWill] = 0) then
     
    55716246      [MyUn[UnFocus].Movement]), 'NOMOVE_TIME') <> mrOK then
    55726247    begin
    5573       result := eInvalid;
    5574       exit;
     6248      Result := eInvalid;
     6249      Exit;
    55756250    end;
    55766251    Update; // remove message box from screen
    55776252  end;
    55786253
    5579   OldUnrest := false;
    5580   NewUnrest := false;
    5581   if (result >= rExecuted) and (result and rUnitRemoved = 0) and
     6254  OldUnrest := False;
     6255  NewUnrest := False;
     6256  if (Result >= rExecuted) and (Result and rUnitRemoved = 0) and
    55826257    (MyMap[ToLoc] and (fUnit or fOwned) <> fUnit) then
    55836258  begin
     
    55896264      begin
    55906265        QueryItem := 'UNREST_NOTOWN';
    5591         p1 := me;
     6266        p1 := Me;
    55926267      end
    55936268      else
     
    56066281        if ModalResult <> mrOK then
    56076282        begin
    5608           result := eInvalid;
    5609           exit;
     6283          Result := eInvalid;
     6284          Exit;
    56106285        end;
    56116286      end;
    56126287      Update; // remove message box from screen
    5613     end
    5614   end;
    5615 
    5616   if (result >= rExecuted) and (MyModel[MyUn[UnFocus].mix].Domain = dAir) and
     6288    end;
     6289  end;
     6290
     6291  if (Result >= rExecuted) and (MyModel[MyUn[UnFocus].mix].Domain = dAir) and
    56176292    (MyUn[UnFocus].Status and usToldNoReturn = 0) then
    56186293  begin // can plane return?
     
    56346309        PlaneReturnData.Movement := MyUn[UnFocus].Movement - 150;
    56356310    end;
    5636     if Server(sGetPlaneReturn, me, UnFocus, PlaneReturnData) = eNoWay then
     6311    if Server(sGetPlaneReturn, Me, UnFocus, PlaneReturnData) = eNoWay then
    56376312    begin
    56386313      if MyModel[MyUn[UnFocus].mix].Kind = mkSpecial_Glider then
     
    56436318        <> mrOK then
    56446319      begin
    5645         result := eInvalid;
    5646         exit;
     6320        Result := eInvalid;
     6321        Exit;
    56476322      end;
    56486323      Update; // remove message box from screen
    56496324      MyUn[UnFocus].Status := MyUn[UnFocus].Status or usToldNoReturn;
    5650     end
    5651   end;
    5652 
    5653   if result = eMissionDone then
     6325    end;
     6326  end;
     6327
     6328  if Result = eMissionDone then
    56546329  begin
    56556330    ModalSelectDlg.ShowNewContent(wmModal, kMission);
    56566331    Update; // dialog still on screen
    5657     Mission := ModalSelectDlg.result;
     6332    Mission := ModalSelectDlg.Result;
    56586333    if Mission < 0 then
    5659       exit;
    5660     Server(sSetSpyMission + Mission shl 4, me, 0, nil^);
    5661   end;
    5662 
    5663   CityCaptured := false;
    5664   if result = eNoTime_Move then
     6334      Exit;
     6335    Server(sSetSpyMission + Mission shl 4, Me, 0, nil^);
     6336  end;
     6337
     6338  CityCaptured := False;
     6339  if Result = eNoTime_Move then
    56656340    Play('NOMOVE_TIME')
    56666341  else
    56676342  begin
    5668     NeedEcoUpdate := false;
    5669     DestinationMarkON := false;
     6343    NeedEcoUpdate := False;
     6344    DestinationMarkON := False;
    56706345    PaintDestination;
    5671     if result and rUnitRemoved <> 0 then
     6346    if Result and rUnitRemoved <> 0 then
    56726347      CityOptimizer_BeforeRemoveUnit(UnFocus);
    5673     IsAttack := (result = eBombarded) or (result <> eMissionDone) and
     6348    IsAttack := (Result = eBombarded) or (Result <> eMissionDone) and
    56746349      (MyMap[ToLoc] and (fUnit or fOwned) = fUnit);
    56756350    if not IsAttack then
     
    56776352      cix := MyRO.nCity - 1; { look for own city at dest location }
    56786353      while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do
    5679         dec(cix);
    5680       if (result <> eMissionDone) and (MyMap[ToLoc] and fCity <> 0) and (cix < 0)
     6354        Dec(cix);
     6355      if (Result <> eMissionDone) and (MyMap[ToLoc] and fCity <> 0) and (cix < 0)
    56816356      then
    5682         CityCaptured := true;
    5683       result := Server(sMoveUnit + DirCode, me, UnFocus, nil^);
    5684       case result of
     6357        CityCaptured := True;
     6358      Result := Server(sMoveUnit + DirCode, Me, UnFocus, nil^);
     6359      case Result of
    56856360        eHiddenUnit:
    56866361          begin
    56876362            Play('NOMOVE_SUBMARINE');
    5688             PaintLoc(ToLoc)
     6363            PaintLoc(ToLoc);
    56896364          end;
    56906365        eStealthUnit:
    56916366          begin
    56926367            Play('NOMOVE_STEALTH');
    5693             PaintLoc(ToLoc)
     6368            PaintLoc(ToLoc);
    56946369          end;
    56956370        eZOC_EnemySpotted:
    56966371          begin
    56976372            Play('NOMOVE_ZOC');
    5698             PaintLoc(ToLoc, 1)
     6373            PaintLoc(ToLoc, 1);
    56996374          end;
    5700         rExecuted .. maxint:
     6375        rExecuted..MaxInt:
    57016376          begin
    5702             if result and rUnitRemoved <> 0 then
     6377            if Result and rUnitRemoved <> 0 then
    57036378              UnFocus := -1 // unit died
    57046379            else
    57056380            begin
    5706               assert(UnFocus >= 0);
     6381              Assert(UnFocus >= 0);
    57076382              MyUn[UnFocus].Status := MyUn[UnFocus].Status and
    57086383                not(usStay or usRecover);
     
    57146389              begin // borders have moved, unrest might have changed in any city
    57156390                CityOptimizer_BeginOfTurn;
    5716                 NeedEcoUpdate := true;
     6391                NeedEcoUpdate := True;
    57176392              end
    57186393              else
     
    57246399                    if MyUn[uix].Master = UnFocus then
    57256400                      CityOptimizer_CityChange(MyUn[uix].Home);
    5726                   NeedEcoUpdate := true;
     6401                  NeedEcoUpdate := True;
    57276402                end;
    57286403                if (MyRO.Government = gDespotism) and
     
    57346409                    while (cixChanged >= 0) and
    57356410                      (MyCity[cixChanged].Loc <> FromLoc) do
    5736                       dec(cixChanged);
    5737                     assert(cixChanged >= 0);
     6411                      Dec(cixChanged);
     6412                    Assert(cixChanged >= 0);
    57386413                    if cixChanged >= 0 then
    57396414                    begin
    57406415                      CityOptimizer_CityChange(cixChanged);
    5741                       NeedEcoUpdate := true;
     6416                      NeedEcoUpdate := True;
    57426417                    end;
    57436418                  end;
     
    57476422                    while (cixChanged >= 0) and
    57486423                      (MyCity[cixChanged].Loc <> ToLoc) do
    5749                       dec(cixChanged);
    5750                     assert(cixChanged >= 0);
     6424                      Dec(cixChanged);
     6425                    Assert(cixChanged >= 0);
    57516426                    if cixChanged >= 0 then
    57526427                    begin
    57536428                      CityOptimizer_CityChange(cixChanged);
    5754                       NeedEcoUpdate := true;
     6429                      NeedEcoUpdate := True;
    57556430                    end;
    57566431                  end;
     
    57606435          end;
    57616436      else
    5762         assert(false);
     6437        Assert(False);
    57636438      end;
    57646439      SetTroopLoc(ToLoc);
     
    57666441    else
    57676442    begin { enemy unit -- attack }
    5768       if result = eBombarded then
     6443      if Result = eBombarded then
    57696444        Defender := MyRO.Territory[ToLoc]
    57706445      else
     
    57736448        if SimpleQuery(mkYesNo,Phrases.Lookup('FRCANCELQUERY_CEASEFIRE'),
    57746449        'MSG_DEFAULT')<>mrOK then
    5775         exit; }
    5776       if (Options and muNoSuicideCheck = 0) and (result and rUnitRemoved <> 0)
    5777         and (result <> eMissionDone) then
     6450        Exit; }
     6451      if (Options and muNoSuicideCheck = 0) and (Result and rUnitRemoved <> 0)
     6452        and (Result <> eMissionDone) then
    57786453      begin // suicide query
    57796454        with MyUn[UnFocus], BattleDlg.Forecast do
    57806455        begin
    5781           pAtt := me;
     6456          pAtt := Me;
    57826457          mixAtt := mix;
    57836458          HealthAtt := Health;
     
    57866461        end;
    57876462        BattleDlg.Forecast.Movement := MyUn[UnFocus].Movement;
    5788         Server(sGetBattleForecastEx, me, ToLoc, BattleDlg.Forecast);
     6463        Server(sGetBattleForecastEx, Me, ToLoc, BattleDlg.Forecast);
    57896464        BattleDlg.uix := UnFocus;
    57906465        BattleDlg.ToLoc := ToLoc;
    5791         BattleDlg.IsSuicideQuery := true;
     6466        BattleDlg.IsSuicideQuery := True;
    57926467        BattleDlg.ShowModal;
    57936468        if BattleDlg.ModalResult <> mrOK then
    5794           exit;
     6469          Exit;
    57956470      end;
    57966471
    57976472      cixChanged := -1;
    5798       if (result and rUnitRemoved <> 0) and (MyRO.Government = gDespotism) and
     6473      if (Result and rUnitRemoved <> 0) and (MyRO.Government = gDespotism) and
    57996474        (MyModel[MyUn[UnFocus].mix].Kind = mkSpecial_TownGuard) and
    58006475        (MyMap[FromLoc] and fCity <> 0) then
     
    58026477        cixChanged := MyRO.nCity - 1;
    58036478        while (cixChanged >= 0) and (MyCity[cixChanged].Loc <> FromLoc) do
    5804           dec(cixChanged);
    5805         assert(cixChanged >= 0);
    5806       end;
    5807 
    5808       for i := 0 to MyRO.nEnemyModel - 1 do
    5809         LostArmy[i] := MyRO.EnemyModel[i].Lost;
     6479          Dec(cixChanged);
     6480        Assert(cixChanged >= 0);
     6481      end;
     6482
     6483      for I := 0 to MyRO.nEnemyModel - 1 do
     6484        LostArmy[I] := MyRO.EnemyModel[I].Lost;
    58106485      OldToTile := MyMap[ToLoc];
    5811       result := Server(sMoveUnit + DirCode, me, UnFocus, nil^);
     6486      Result := Server(sMoveUnit + DirCode, Me, UnFocus, nil^);
    58126487      nLostArmy := 0;
    5813       for i := 0 to MyRO.nEnemyModel - 1 do
     6488      for I := 0 to MyRO.nEnemyModel - 1 do
    58146489      begin
    5815         LostArmy[i] := MyRO.EnemyModel[i].Lost - LostArmy[i];
    5816         inc(nLostArmy, LostArmy[i])
    5817       end;
    5818       if result and rUnitRemoved <> 0 then
     6490        LostArmy[I] := MyRO.EnemyModel[I].Lost - LostArmy[I];
     6491        Inc(nLostArmy, LostArmy[I]);
     6492      end;
     6493      if Result and rUnitRemoved <> 0 then
    58196494      begin
    58206495        UnFocus := -1;
     
    58256500      begin // city was destroyed, borders have moved, unrest might have changed in any city
    58266501        CityOptimizer_BeginOfTurn;
    5827         NeedEcoUpdate := true;
    5828       end
    5829       else
    5830       begin
     6502        NeedEcoUpdate := True;
     6503      end else begin
    58316504        if cixChanged >= 0 then
    58326505        begin
    58336506          CityOptimizer_CityChange(cixChanged);
    5834           NeedEcoUpdate := true;
     6507          NeedEcoUpdate := True;
    58356508        end;
    5836         if (result = eWon) or (result = eBloody) or (result = eExpelled) then
     6509        if (Result = eWon) or (Result = eBloody) or (Result = eExpelled) then
    58376510        begin
    58386511          CityOptimizer_TileBecomesAvailable(ToLoc);
    5839           NeedEcoUpdate := true;
     6512          NeedEcoUpdate := True;
    58406513        end;
    58416514      end;
     
    58496522            MyRO.EnemyModel[MyRO.EnemyUn[euix].emix].Domain));
    58506523          ShowModal;
    5851         end
    5852       end
    5853     end;
    5854     if result and rUnitRemoved <> 0 then
     6524        end;
     6525      end;
     6526    end;
     6527    if Result and rUnitRemoved <> 0 then
    58556528    begin
    58566529      CityOptimizer_AfterRemoveUnit;
    58576530      ListDlg.RemoveUnit;
    5858       NeedEcoUpdate := true;
     6531      NeedEcoUpdate := True;
    58596532    end;
    58606533    if NeedEcoUpdate then
    58616534    begin
    5862       UpdateViews(true);
    5863       Update
    5864     end
    5865   end;
    5866 
    5867   if result = eMissionDone then
     6535      UpdateViews(True);
     6536      Update;
     6537    end;
     6538  end;
     6539
     6540  if Result = eMissionDone then
    58686541  begin
    58696542    p1 := MyRO.Territory[ToLoc];
     
    58716544      smStealMap:
    58726545        begin
    5873           MapValid := false;
     6546          MapValid := False;
    58746547          PaintAllMaps
    58756548        end;
     
    58846557    CheckToldNoReturn(UnFocus);
    58856558
    5886   NeedRepaintPanel := false;
    5887   if result >= rExecuted then
     6559  NeedRepaintPanel := False;
     6560  if Result >= rExecuted then
    58886561  begin
    58896562    if CityCaptured and (MyMap[ToLoc] and fCity = 0) then
    58906563    begin // city destroyed
    5891       for i := 0 to nWonder - 1 do { tell about destroyed wonders }
    5892         if (MyRO.Wonder[i].CityID = WonderDestroyed) and (MyData.ToldWonders[i].CityID <> WonderDestroyed)
     6564      for I := 0 to nWonder - 1 do { tell about destroyed wonders }
     6565        if (MyRO.Wonder[I].CityID = WonderDestroyed) and (MyData.ToldWonders[I].CityID <> WonderDestroyed)
    58936566        then
    58946567          with MessgExDlg do
    58956568          begin
    58966569            if WondersDlg.Visible then
    5897               WondersDlg.SmartUpdateContent(false);
     6570              WondersDlg.SmartUpdateContent(False);
    58986571            OpenSound := 'WONDER_DESTROYED';
    58996572            MessgText := Format(Phrases.Lookup('WONDERDEST'),
    5900               [Phrases.Lookup('IMPROVEMENTS', i)]);
     6573              [Phrases.Lookup('IMPROVEMENTS', I)]);
    59016574            Kind := mkOkHelp;
    59026575            HelpKind := hkImp;
    5903             HelpNo := i;
     6576            HelpNo := I;
    59046577            IconKind := mikImp;
    5905             IconIndex := i;
     6578            IconIndex := I;
    59066579            ShowModal;
    5907             MyData.ToldWonders[i] := MyRO.Wonder[i];
    5908           end
     6580            MyData.ToldWonders[I] := MyRO.Wonder[I];
     6581          end;
    59096582    end;
    59106583    if CityCaptured and (MyMap[ToLoc] and fCity <> 0) then
    59116584    begin // city captured
    59126585      ListDlg.AddCity;
    5913       for i := 0 to nWonder - 1 do { tell about capture of wonders }
    5914         if MyRO.City[MyRO.nCity - 1].Built[i] > 0 then
     6586      for I := 0 to nWonder - 1 do { tell about capture of wonders }
     6587        if MyRO.City[MyRO.nCity - 1].Built[I] > 0 then
    59156588          with MessgExDlg do
    59166589          begin
    59176590            if WondersDlg.Visible then
    5918               WondersDlg.SmartUpdateContent(false);
     6591              WondersDlg.SmartUpdateContent(False);
    59196592            OpenSound := 'WONDER_CAPTURED';
    5920             MessgText := Format(Tribe[me].TPhrase('WONDERCAPTOWN'),
    5921               [Phrases.Lookup('IMPROVEMENTS', i)]);
     6593            MessgText := Format(Tribe[Me].TPhrase('WONDERCAPTOWN'),
     6594              [Phrases.Lookup('IMPROVEMENTS', I)]);
    59226595            Kind := mkOkHelp;
    59236596            HelpKind := hkImp;
    5924             HelpNo := i;
     6597            HelpNo := I;
    59256598            IconKind := mikImp;
    5926             IconIndex := i;
     6599            IconIndex := I;
    59276600            ShowModal;
    5928             MyData.ToldWonders[i] := MyRO.Wonder[i];
     6601            MyData.ToldWonders[I] := MyRO.Wonder[I];
    59296602          end;
    59306603
     
    59326605      begin { Temple of Zeus -- choose advance to steal }
    59336606        ModalSelectDlg.ShowNewContent(wmModal, kStealTech);
    5934         Server(sStealTech, me, ModalSelectDlg.result, nil^);
     6607        Server(sStealTech, Me, ModalSelectDlg.Result, nil^);
    59356608      end;
    59366609      TellNewModels;
     
    59386611      cix := MyRO.nCity - 1;
    59396612      while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do
    5940         dec(cix);
    5941       assert(cix >= 0);
     6613        Dec(cix);
     6614      Assert(cix >= 0);
    59426615      MyCity[cix].Status := MyCity[cix].Status and not csResourceWeightsMask or
    59436616        (3 shl 4);
    59446617      // captured city, set to maximum growth
    59456618      NewTiles := 1 shl 13; { exploit central tile only }
    5946       Server(sSetCityTiles, me, cix, NewTiles);
     6619      Server(sSetCityTiles, Me, cix, NewTiles);
    59476620    end
    59486621    else
    5949       NeedRepaintPanel := true;
     6622      NeedRepaintPanel := True;
    59506623  end;
    59516624  TellNewContacts;
     
    59616634  if Options and (muAutoNoWait or muAutoNext) <> 0 then
    59626635  begin
    5963     if (UnFocus >= 0) and ((result = eNoTime_Move) or UnitExhausted(UnFocus) or
     6636    if (UnFocus >= 0) and ((Result = eNoTime_Move) or UnitExhausted(UnFocus) or
    59646637      (MyUn[UnFocus].Master >= 0) or (MyModel[MyUn[UnFocus].mix].Domain = dAir)
    59656638      and ((MyMap[MyUn[UnFocus].Loc] and fCity <> 0)
     
    59756648        end
    59766649        else
    5977           NextUnit(UnStartLoc, true);
     6650          NextUnit(UnStartLoc, True);
    59786651    end
    59796652    else if (UnFocus < 0) and (Options and muAutoNext <> 0) then
    5980       NextUnit(UnStartLoc, result <> eMissionDone);
     6653      NextUnit(UnStartLoc, Result <> eMissionDone);
    59816654  end;
    59826655
     
    59866659    else
    59876660    begin
    5988       assert(result <> eMissionDone);
     6661      Assert(Result <> eMissionDone);
    59896662      CheckTerrainBtnVisible;
    5990       FocusOnLoc(ToLoc, flRepaintPanel or flImmUpdate)
    5991     end;
    5992 
    5993   if (result >= rExecuted) and CityCaptured and (MyMap[ToLoc] and fCity <> 0)
     6663      FocusOnLoc(ToLoc, flRepaintPanel or flImmUpdate);
     6664    end;
     6665
     6666  if (Result >= rExecuted) and CityCaptured and (MyMap[ToLoc] and fCity <> 0)
    59946667  then
    59956668    ZoomToCity(ToLoc, UnFocus < 0, chCaptured); // show captured city
    5996 end; // moveunit
     6669end;
    59976670
    59986671procedure TMainScreen.MoveOnScreen(ShowMove: TShowMove;
    5999   Step0, Step1, nStep: integer; Restore: boolean = true);
     6672  Step0, Step1, nStep: Integer; Restore: Boolean = True);
    60006673var
    60016674  ToLoc, xFromLoc, yFromLoc, xToLoc, yToLoc, xFrom, yFrom, xTo, yTo, xMin, yMin,
    6002     xRange, yRange, xw1, Step, xMoving, yMoving, SliceCount: integer;
     6675    xRange, yRange, xw1, Step, xMoving, yMoving, SliceCount: Integer;
    60036676  UnitInfo: TUnitInfo;
    60046677  Ticks0, Ticks: TDateTime;
    60056678begin
    6006   Timer1.Enabled := false;
     6679  Timer1.Enabled := False;
    60076680  Ticks0 := NowPrecise;
    60086681  with ShowMove do
     
    60136686    UnitInfo.Job := jNone;
    60146687    UnitInfo.Flags := Flags;
    6015     if Owner <> me then
     6688    if Owner <> Me then
    60166689      UnitInfo.emix := emix;
    60176690
     
    60326705        * xxt - MapWidth) < abs(((xFromLoc - xw1) * 2 + yFromLoc and 1 + 1) * xxt
    60336706        * 2 + dx * xxt - MapWidth) do
    6034         dec(xw1, G.lx);
     6707        Dec(xw1, G.lx);
    60356708
    60366709      xTo := (xToLoc - xw1) * (xxt * 2) + yToLoc and 1 * xxt + (xxt - xxu);
     
    60406713      if xFrom < xTo then begin
    60416714        xMin := xFrom;
    6042         xRange := xTo - xFrom
     6715        xRange := xTo - xFrom;
    60436716      end else begin
    60446717        xMin := xTo;
    6045         xRange := xFrom - xTo
     6718        xRange := xFrom - xTo;
    60466719      end;
    60476720      if yFrom < yTo then begin
    60486721        yMin := yFrom;
    6049         yRange := yTo - yFrom
     6722        yRange := yTo - yFrom;
    60506723      end else begin
    60516724        yMin := yTo;
    6052         yRange := yFrom - yTo
    6053       end;
    6054       inc(xRange, xxt * 2);
    6055       inc(yRange, yyt * 3);
     6725        yRange := yFrom - yTo;
     6726      end;
     6727      Inc(xRange, xxt * 2);
     6728      Inc(yRange, yyt * 3);
    60566729    end;
    60576730
     
    60616734    for Step := 0 to abs(Step1 - Step0) do
    60626735    begin
    6063       DpiBitCanvas(Buffer.Canvas, 0, 0, xRange, yRange,
    6064         offscreen.Canvas, xMin, yMin);
     6736      DpiBitBltCanvas(Buffer.Canvas, 0, 0, xRange, yRange,
     6737        Offscreen.Canvas, xMin, yMin);
    60656738      if Step1 <> Step0 then
    60666739      begin
     
    60796752      NoMap.PaintUnit(xMoving - xMin, yMoving - yMin, UnitInfo, 0);
    60806753      PaintBufferToScreen(xMin, yMin, xRange, yRange);
    6081       {$IFDEF LINUX}
    6082       // TODO: Force animation under linux
     6754      {$IFDEF UNIX}
     6755      // TODO: Force animation under UNIX
    60836756      DpiApplication.ProcessMessages;
    60846757      {$ENDIF}
     
    60916764          < MoveTime) then
    60926765        begin
    6093           if not idle or (GameMode = cMovie) then
     6766          if not Idle or (GameMode = cMovie) then
    60946767            DpiApplication.ProcessMessages;
    60956768          Sleep(1);
    6096           inc(SliceCount)
     6769          Inc(SliceCount)
    60976770        end;
    60986771        Ticks := NowPrecise;
    60996772      until (((Ticks - Ticks0) * 12) / OneMillisecond) >= MoveTime;
    6100       Ticks0 := Ticks
     6773      Ticks0 := Ticks;
    61016774    end;
    61026775  end;
    61036776  if Restore then
    61046777  begin
    6105     DpiBitCanvas(Buffer.Canvas, 0, 0, xRange, yRange, offscreen.Canvas, xMin, yMin);
     6778    DpiBitBltCanvas(Buffer.Canvas, 0, 0, xRange, yRange, Offscreen.Canvas, xMin, yMin);
    61066779    PaintBufferToScreen(xMin, yMin, xRange, yRange);
    61076780  end;
    61086781  BlinkTime := -1;
    6109   Timer1.Enabled := true;
    6110 end;
    6111 
    6112 procedure TMainScreen.MoveToLoc(Loc: integer; CheckSuicide: boolean);
     6782  Timer1.Enabled := True;
     6783end;
     6784
     6785procedure TMainScreen.MoveToLoc(Loc: Integer; CheckSuicide: Boolean);
    61136786// path finder: move focused unit to loc, start multi-turn goto if too far
    61146787var
    6115   uix, i, MoveOptions, NextLoc, MoveResult: integer;
     6788  uix, I, MoveOptions, NextLoc, MoveResult: Integer;
    61166789  MoveAdviceData: TMoveAdviceData;
    61176790  StopReason: (None, Arrived, Dead, NoTime, EnemySpotted, MoveError);
    61186791begin
    61196792  if MyUn[UnFocus].Job > jNone then
    6120     Server(sStartJob + jNone shl 4, me, UnFocus, nil^);
     6793    Server(sStartJob + jNone shl 4, Me, UnFocus, nil^);
    61216794  if GetMoveAdvice(UnFocus, Loc, MoveAdviceData) >= rExecuted then
    61226795  begin
     
    61246797    StopReason := None;
    61256798    repeat
    6126       for i := 0 to MoveAdviceData.nStep - 1 do
     6799      for I := 0 to MoveAdviceData.nStep - 1 do
    61276800      begin
    6128         if i = MoveAdviceData.nStep - 1 then
     6801        if I = MoveAdviceData.nStep - 1 then
    61296802          MoveOptions := muAutoNext
    61306803        else
    61316804          MoveOptions := 0;
    6132         NextLoc := dLoc(MyUn[uix].Loc, MoveAdviceData.dx[i],
    6133           MoveAdviceData.dy[i]);
     6805        NextLoc := dLoc(MyUn[uix].Loc, MoveAdviceData.dx[I],
     6806          MoveAdviceData.dy[I]);
    61346807        if (NextLoc = Loc) or (Loc = maNextCity) and
    61356808          (MyMap[NextLoc] and fCity <> 0) then
     
    61376810        if not CheckSuicide and (NextLoc = Loc) then
    61386811          MoveOptions := MoveOptions or muNoSuicideCheck;
    6139         MoveResult := MoveUnit(MoveAdviceData.dx[i], MoveAdviceData.dy[i],
     6812        MoveResult := MoveUnit(MoveAdviceData.dx[I], MoveAdviceData.dy[I],
    61406813          MoveOptions);
    61416814        if MoveResult < rExecuted then
     
    61496822      end;
    61506823      if (StopReason = None) and ((MoveAdviceData.nStep < 25) or
    6151         (MyRO.Wonder[woShinkansen].EffectiveOwner <> me)) then
     6824        (MyRO.Wonder[woShinkansen].EffectiveOwner <> Me)) then
    61526825        StopReason := NoTime;
    61536826      if StopReason <> None then
     
    61556828      if GetMoveAdvice(UnFocus, Loc, MoveAdviceData) < rExecuted then
    61566829      begin
    6157         assert(false);
     6830        Assert(False);
    61586831        Break;
    61596832      end;
    6160     until false;
     6833    until False;
    61616834
    61626835    case StopReason of
    61636836      None:
    6164         assert(false);
     6837        Assert(False);
    61656838      Arrived:
    61666839        MyUn[uix].Status := MyUn[uix].Status and ($FFFF - usGoto);
    61676840      Dead:
    61686841        if UnFocus < 0 then
    6169           NextUnit(UnStartLoc, false);
     6842          NextUnit(UnStartLoc, False);
    61706843    else
    61716844      begin // multi-turn goto
     
    61806853        begin
    61816854          MyUn[uix].Status := MyUn[uix].Status and not usWaiting;
    6182           NextUnit(UnStartLoc, true);
     6855          NextUnit(UnStartLoc, True);
    61836856        end;
    61846857      end;
     
    61886861
    61896862procedure TMainScreen.PanelBoxMouseDown(Sender: TObject; Button: TMouseButton;
    6190   Shift: TShiftState; x, y: integer);
     6863  Shift: TShiftState; X, Y: Integer);
    61916864var
    6192   i, xMouse, MouseLoc, p1: integer;
     6865  I, xMouse, MouseLoc, p1: Integer;
    61936866begin
    61946867  if GameMode = cMovie then
    6195     exit;
     6868    Exit;
    61966869
    61976870  if Button = mbLeft then
    61986871  begin
    6199     if (x >= xMini + 2) and (y >= yMini + 2) and (x < xMini + 2 + 2 * G.lx) and
    6200       (y < yMini + 2 + G.ly) then
     6872    if (X >= xMini + 2) and (Y >= yMini + 2) and (X < xMini + 2 + 2 * G.lx) and
     6873      (Y < yMini + 2 + G.ly) then
    62016874      if ssShift in Shift then
    62026875      begin
    62036876        with MainMap do
    6204           xMouse := (xwMini + (x - (xMini + 2) + MapWidth div (xxt * 2) + G.lx)
     6877          xMouse := (xwMini + (X - (xMini + 2) + MapWidth div (xxt * 2) + G.lx)
    62056878            div 2) mod G.lx;
    6206         MouseLoc := xMouse + G.lx * (y - (yMini + 2));
     6879        MouseLoc := xMouse + G.lx * (Y - (yMini + 2));
    62076880        if MyMap[MouseLoc] and fTerrain <> fUNKNOWN then
    62086881        begin
    62096882          p1 := MyRO.Territory[MouseLoc];
    6210           if (p1 = me) or (p1 >= 0) and (MyRO.Treaty[p1] >= trNone) then
     6883          if (p1 = Me) or (p1 >= 0) and (MyRO.Treaty[p1] >= trNone) then
    62116884            NatStatDlg.ShowNewContent(wmPersistent, p1);
    62126885        end;
     
    62186891        if UnitStatDlg.Visible then
    62196892          UnitStatDlg.Close;
    6220         Tracking := true;
    6221         PanelBoxMouseMove(Sender, Shift + [ssLeft], x, y);
     6893        Tracking := True;
     6894        PanelBoxMouseMove(Sender, Shift + [ssLeft], X, Y);
    62226895      end
    6223     else if (ClientMode <> cEditMap) and (x >= ClientWidth - xPalace) and
    6224       (y >= yPalace) and (x < ClientWidth - xPalace + xSizeBig) and
    6225       (y < yPalace + ySizeBig) then
     6896    else if (ClientMode <> cEditMap) and (X >= ClientWidth - xPalace) and
     6897      (Y >= yPalace) and (X < ClientWidth - xPalace + xSizeBig) and
     6898      (Y < yPalace + ySizeBig) then
    62266899    begin
    62276900      InitPopup(StatPopup);
     
    62346907          DpiGetSystemMetrics(SM_CYCAPTION) + 3)
    62356908    end
    6236     (* else if (x>=xAdvisor-3) and (y>=yAdvisor-3)
    6237       and (x<xAdvisor+16+3) and (y<yAdvisor+16+3) and HaveStrategyAdvice then
     6909    (* else if (X>=xAdvisor-3) and (Y>=yAdvisor-3)
     6910      and (X<xAdvisor+16+3) and (Y<yAdvisor+16+3) and HaveStrategyAdvice then
    62386911      AdviceBtnClick *)
    6239     else if (x >= xTroop + 1) and (y >= yTroop + 1) and
    6240       (x < xTroop + TrRow * TrPitch) and (y <= yTroop + 55) then
     6912    else if (X >= xTroop + 1) and (Y >= yTroop + 1) and
     6913      (X < xTroop + TrRow * TrPitch) and (Y <= yTroop + 55) then
    62416914    begin
    6242       i := (x - xTroop - 1) div TrPitch;
    6243       if trix[i] >= 0 then
     6915      I := (X - xTroop - 1) div TrPitch;
     6916      if trix[I] >= 0 then
    62446917        if ClientMode = cEditMap then
    62456918        begin
    6246           BrushType := trix[i];
    6247           PanelPaint
     6919          BrushType := trix[I];
     6920          PanelPaint;
    62486921        end
    62496922        else if (TroopLoc >= 0) then
     
    62526925            if ssShift in Shift then
    62536926              UnitStatDlg.ShowNewContent_OwnModel(wmPersistent,
    6254                 MyUn[trix[i]].mix)
    6255             else if not supervising and (ClientMode < scContact) and
    6256               (x - xTroop - 1 - i * TrPitch >= 60 - 20) and (y >= yTroop + 35)
    6257               and ((MyUn[trix[i]].Job > jNone) or (MyUn[trix[i]].Status and
     6927                MyUn[trix[I]].mix)
     6928            else if not Supervising and (ClientMode < scContact) and
     6929              (X - xTroop - 1 - I * TrPitch >= 60 - 20) and (Y >= yTroop + 35)
     6930              and ((MyUn[trix[I]].Job > jNone) or (MyUn[trix[I]].Status and
    62586931              (usStay or usRecover or usGoto) <> 0)) then
    62596932            begin // wake up
    6260               MyUn[trix[i]].Status := MyUn[trix[i]].Status and
     6933              MyUn[trix[I]].Status := MyUn[trix[I]].Status and
    62616934                ($FFFF - usStay - usRecover - usGoto - usEnhance) or usWaiting;
    6262               if MyUn[trix[i]].Job > jNone then
    6263                 Server(sStartJob + jNone shl 4, me, trix[i], nil^);
     6935              if MyUn[trix[I]].Job > jNone then
     6936                Server(sStartJob + jNone shl 4, Me, trix[I], nil^);
    62646937              if (UnFocus < 0) and not CityDlg.Visible then
    62656938              begin
    6266                 SetUnFocus(trix[i]);
    6267                 SetTroopLoc(MyUn[trix[i]].Loc);
     6939                SetUnFocus(trix[I]);
     6940                SetTroopLoc(MyUn[trix[I]].Loc);
    62686941                FocusOnLoc(TroopLoc, flRepaintPanel)
    62696942              end
     
    62716944              begin
    62726945                if CityDlg.Visible and (CityDlg.RestoreUnFocus < 0) then
    6273                   CityDlg.RestoreUnFocus := trix[i];
     6946                  CityDlg.RestoreUnFocus := trix[I];
    62746947                PanelPaint;
    62756948              end
     
    62776950            else if (ClientMode < scContact) then
    62786951            begin
    6279               if supervising then
    6280                 UnitStatDlg.ShowNewContent_OwnUnit(wmPersistent, trix[i])
     6952              if Supervising then
     6953                UnitStatDlg.ShowNewContent_OwnUnit(wmPersistent, trix[I])
    62816954              else if CityDlg.Visible then
    62826955              begin
     
    62846957                CityDlg.Close;
    62856958                SumCities(TaxSum, ScienceSum);
    6286                 SetUnFocus(trix[i]);
     6959                SetUnFocus(trix[I]);
    62876960              end
    62886961              else
    62896962              begin
    6290                 DestinationMarkON := false;
     6963                DestinationMarkON := False;
    62916964                PaintDestination;
    6292                 UnFocus := trix[i];
     6965                UnFocus := trix[I];
    62936966                UnStartLoc := TroopLoc;
    62946967                BlinkTime := 0;
    6295                 BlinkON := false;
     6968                BlinkON := False;
    62966969                PaintLoc(TroopLoc);
    62976970              end;
    62986971              if UnFocus >= 0 then
    62996972              begin
    6300                 UnitInfoBtn.Visible := true;
    6301                 UnitBtn.Visible := true;
    6302                 TurnComplete := false;
     6973                UnitInfoBtn.Visible := True;
     6974                UnitBtn.Visible := True;
     6975                TurnComplete := False;
    63036976                EOT.ButtonIndex := eotGray;
    63046977              end;
     
    63076980            end;
    63086981          end
    6309           else if Server(sGetUnits, me, TroopLoc, TrCnt) >= rExecuted then
     6982          else if Server(sGetUnits, Me, TroopLoc, TrCnt) >= rExecuted then
    63106983            if ssShift in Shift then
    63116984              UnitStatDlg.ShowNewContent_EnemyModel(wmPersistent,
    6312                 MyRO.EnemyUn[MyRO.nEnemyUn + trix[i]].emix) // model info
     6985                MyRO.EnemyUn[MyRO.nEnemyUn + trix[I]].emix) // model info
    63136986            else
    63146987              UnitStatDlg.ShowNewContent_EnemyUnit(wmPersistent,
    6315                 MyRO.nEnemyUn + trix[i]); // unit info
    6316     end;
    6317   end;
    6318 end;
    6319 
    6320 procedure TMainScreen.SetTroopLoc(Loc: integer);
     6988                MyRO.nEnemyUn + trix[I]); // unit info
     6989    end;
     6990  end;
     6991end;
     6992
     6993procedure TMainScreen.SetTroopLoc(Loc: Integer);
    63216994var
    6322   trixFocus, uix, uixDefender: integer;
    6323   Prio: boolean;
     6995  trixFocus, uix, uixDefender: Integer;
     6996  Prio: Boolean;
    63246997begin
    63256998  TroopLoc := Loc;
     
    63337006    if MyMap[Loc] and fOwned <> 0 then
    63347007    begin // count own units here
    6335       Server(sGetDefender, me, TroopLoc, uixDefender);
    6336       for Prio := true downto false do
     7008      Server(sGetDefender, Me, TroopLoc, uixDefender);
     7009      for Prio := True downto False do
    63377010        for uix := 0 to MyRO.nUn - 1 do
    63387011          if ((uix = uixDefender) = Prio) and (MyUn[uix].Loc = Loc) then
     
    63407013            if uix = UnFocus then
    63417014              trixFocus := TrCnt;
    6342             inc(TrCnt);
     7015            Inc(TrCnt);
    63437016          end;
    63447017    end
    63457018    else // count enemy units here
    6346       Server(sGetUnits, me, Loc, TrCnt);
     7019      Server(sGetUnits, Me, Loc, TrCnt);
    63477020  if TrCnt = 0 then
    63487021    sb.Init(0, 1)
     
    63557028end;
    63567029
    6357 (* procedure TMainScreen.ShowMoveHint(ToLoc: integer; Force: boolean = false);
     7030(* procedure TMainScreen.ShowMoveHint(ToLoc: Integer; Force: Boolean = False);
    63587031  var
    6359   Step,Loc,x0,y0,xs,ys: integer;
     7032  Step,Loc,x0,y0,xs,ys: Integer;
    63607033  Info: string;
    63617034  InfoSize: TSize;
     
    63707043  MoveAdvice.MoreTurns:=0;
    63717044  MoveAdvice.MaxHostile_MovementLeft:=MyUn[UnFocus].Health-50;
    6372   if Server(sGetMoveAdvice,me,UnFocus,MoveAdvice)<rExecuted then
     7045  if Server(sGetMoveAdvice,Me,UnFocus,MoveAdvice)<rExecuted then
    63737046  ToLoc:=-1
    63747047  end;
    6375   if (ToLoc=MoveHintToLoc) and not Force then exit;
     7048  if (ToLoc=MoveHintToLoc) and not Force then Exit;
    63767049  if (ToLoc<>MoveHintToLoc) and (MoveHintToLoc>=0) then
    63777050  begin invalidate; update end; // clear old hint from screen
    63787051  MoveHintToLoc:=ToLoc;
    6379   if ToLoc<0 then exit;
    6380 
    6381   with canvas do
     7052  if ToLoc<0 then Exit;
     7053
     7054  with Canvas do
    63827055  begin
    63837056  Pen.Color:=$80C0FF;
     
    63907063  xs:=(x0-xw)*66+y0 and 1*33-G.lx*66;
    63917064  while abs(2*(xs+G.lx*66)-MapWidth)<abs(2*xs-MapWidth) do
    6392   inc(xs,G.lx*66);
     7065  Inc(xs,G.lx*66);
    63937066  ys:=(y0-yw)*16;
    63947067  if Step=0 then moveto(xs+33,ys+16)
     
    63987071  end;
    63997072  Brush.Color:=$80C0FF;
    6400   Info:=' '+inttostr(88)+' ';
     7073  Info:=' '+IntToStr(88)+' ';
    64017074  InfoSize:=TextExtent(Info);
    64027075  TextOut(xs+33-InfoSize.cx div 2, ys+16-InfoSize.cy div 2, Info);
     
    64057078  end; *)
    64067079
    6407 procedure TMainScreen.SetDebugMap(p: integer);
    6408 begin
    6409   MainMap.pDebugMap := p;
     7080procedure TMainScreen.SetDebugMap(P: Integer);
     7081begin
     7082  MainMap.pDebugMap := P;
    64107083  MapOptions := MapOptions - [moLocCodes];
    6411   mLocCodes.Checked := false;
    6412   MapValid := false;
     7084  mLocCodes.Checked := False;
     7085  MapValid := False;
    64137086  MainOffscreenPaint;
    64147087end;
    64157088
    6416 procedure TMainScreen.SetViewpoint(p: integer);
     7089procedure TMainScreen.SetViewpoint(P: Integer);
    64177090var
    6418   i: Integer;
    6419 begin
    6420   if supervising and (G.RO[0].Turn > 0) and
    6421     ((p = 0) or (1 shl p and G.RO[0].Alive <> 0)) then
    6422   begin
    6423     for i := 0 to DpiScreen.FormCount - 1 do
    6424       if DpiScreen.Forms[i].Visible and (DpiScreen.Forms[i] is TBufferedDrawDlg) then
    6425         DpiScreen.Forms[i].Close; // close windows
    6426     ItsMeAgain(p);
     7091  I: Integer;
     7092begin
     7093  if Supervising and (G.RO[0].Turn > 0) and
     7094    ((P = 0) or (1 shl P and G.RO[0].Alive <> 0)) then
     7095  begin
     7096    ApplyToVisibleForms(faClose);
     7097    ItsMeAgain(P);
    64277098    SumCities(TaxSum, ScienceSum);
    6428     for i := 0 to MyRO.nModel - 1 do
    6429       if not Assigned(Tribe[me].ModelPicture[i].HGr) then
    6430         InitMyModel(i, True);
     7099    for I := 0 to MyRO.nModel - 1 do
     7100      if not Assigned(Tribe[Me].ModelPicture[I].HGr) then
     7101        InitMyModel(I, True);
    64317102
    64327103    SetTroopLoc(-1);
     
    64817152  MTrans.ShortCut := BTrans.ShortCut;
    64827153  mPollution.ShortCut := BPollution.ShortCut;
    6483   mRR.ShortCut := BRailRoad.ShortCut;
     7154  mRailRoad.ShortCut := BRailRoad.ShortCut;
    64847155  mRoad.ShortCut := BRailRoad.ShortCut;
    64857156  mUnload.ShortCut := BUnload.ShortCut;
     
    65167187end;
    65177188
    6518 procedure TMainScreen.FormKeyDown(Sender: TObject; var Key: word;
     7189procedure TMainScreen.FormKeyDown(Sender: TObject; var Key: Word;
    65197190  Shift: TShiftState);
    65207191
     
    65237194    InitPopup(Popup);
    65247195    if Item.Visible and Item.Enabled then
    6525       MenuClick(Item);
    6526   end;
    6527 
    6528   procedure SetViewpointMe(p: Integer);
    6529   begin
    6530     if p = me then SetViewpoint(p)
    6531       else SetViewpoint(p);
     7196      Item.Click;
     7197  end;
     7198
     7199  procedure SetViewpointMe(P: Integer);
     7200  begin
     7201    if P = Me then SetViewpoint(P)
     7202      else SetViewpoint(P);
    65327203  end;
    65337204
     
    65587229
    65597230  if ClientMode = cEditMap then begin
    6560     if BResign.Test(ShortCut) then MenuClick(mResign)
    6561     else if BRandomMap.Test(ShortCut) then MenuClick(mRandomMap)
    6562     else if BHelp.Test(ShortCut) then MenuClick(mHelp);
     7231    if BResign.Test(ShortCut) then mResign.Click
     7232    else if BRandomMap.Test(ShortCut) then mRandomMap.Click
     7233    else if BHelp.Test(ShortCut) then mHelp.Click;
    65637234    (*if Shift = [ssCtrl] then
    65647235      case char(Key) of
    65657236         'A':
    65667237          begin // auto symmetry
    6567           Server($7F0,me,0,nil^);
    6568           MapValid:=false;
     7238          Server($7F0,Me,0,nil^);
     7239          MapValid:=False;
    65697240          PaintAll;
    65707241          end;
     
    65737244          dy:=0;
    65747245          for dx:=G.lx to G.lx*(G.ly-1)-1 do
    6575           if MyMap[dx] and fTerrain>=fGrass then inc(dy);
     7246          if MyMap[dx] and fTerrain>=fGrass then Inc(dy);
    65767247          dy:=dy
    65777248          end;
     
    65867257    SetFullScreen(FullScreen);
    65877258  end
    6588   else if BHelp.Test(ShortCut) then MenuClick(mHelp)
     7259  else if BHelp.Test(ShortCut) then mHelp.Click
    65897260  else if BUnitStat.Test(ShortCut) then MenuClick_Check(StatPopup, mUnitStat)
    65907261  else if BCityStat.Test(ShortCut) then MenuClick_Check(StatPopup, mCityStat)
     
    66087279  else if BSetDebugMap9.Test(ShortCut) then SetDebugMap(9)
    66097280
    6610   else if BJump.Test(ShortCut) then MenuClick(mJump)
     7281  else if BJump.Test(ShortCut) then mJump.Click
    66117282  else if BDebugMap.Test(ShortCut) then mShowClick(mDebugMap)
    66127283  else if BLocCodes.Test(ShortCut) then mShowClick(mLocCodes)
     
    66177288  else if BNames.Test(ShortCut) then mNamesClick(mNames)
    66187289  else if BResign.Test(ShortCut) then MenuClick_Check(GamePopup, mResign)
    6619   else if BRun.Test(ShortCut) then MenuClick(mRun)
     7290  else if BRun.Test(ShortCut) then mRun.Click
    66207291  else if BTestMapRepaint.Test(ShortCut) then begin // test map repaint time
    66217292    Time0 := NowPrecise;
     
    66427313  else if BMapBtn5.Test(ShortCut) then MapBtnClick(MapBtn5)
    66437314  else if BMapBtn6.Test(ShortCut) then MapBtnClick(MapBtn6)
    6644   else if BTechTree.Test(ShortCut) then MenuClick(mTechTree)
    6645   else if BWait.Test(ShortCut) then MenuClick(mWait);
     7315  else if BTechTree.Test(ShortCut) then mTechTree.Click
     7316  else if BWait.Test(ShortCut) then mWait.Click;
    66467317
    66477318  if UnFocus >= 0 then begin
    6648     if BDisbandUnit.Test(ShortCut) then MenuClick(mDisband)
     7319    if BDisbandUnit.Test(ShortCut) then mDisband.Click
    66497320    else if BFortify.Test(ShortCut) then MenuClick_Check(TerrainPopup, mFort)
    6650     else if BCenterUnit.Test(ShortCut) then MenuClick(mCentre)
    6651     else if BStay.Test(ShortCut) then MenuClick(mStay)
    6652     else if BNoOrders.Test(ShortCut) then MenuClick(mNoOrders)
    6653     else if BPrevUnit.Test(ShortCut) then MenuClick(mPrevUnit)
    6654     else if BNextUnit.Test(ShortCut) then MenuClick(mNextUnit)
     7321    else if BCenterUnit.Test(ShortCut) then mCentre.Click
     7322    else if BStay.Test(ShortCut) then mStay.Click
     7323    else if BNoOrders.Test(ShortCut) then mNoOrders.Click
     7324    else if BPrevUnit.Test(ShortCut) then mPrevUnit.Click
     7325    else if BNextUnit.Test(ShortCut) then mNextUnit.Click
    66557326    else if BCancel.Test(ShortCut) then MenuClick_Check(UnitPopup, mCancel)
    66567327    else if BPillage.Test(ShortCut) then MenuClick_Check(UnitPopup, mPillage)
     
    66607331    else if BEnhance.Test(ShortCut) then begin
    66617332      InitPopup(TerrainPopup);
    6662       if mEnhance.Visible and mEnhance.Enabled then MenuClick(mEnhance)
    6663         else MenuClick(mEnhanceDef)
     7333      if mEnhance.Visible and mEnhance.Enabled then mEnhance.Click
     7334        else mEnhanceDef.Click
    66647335    end
    66657336    else if BGoOn.Test(ShortCut) then MenuClick_Check(UnitPopup, mGoOn)
     
    66677338    else if BFarmClearIrrigation.Test(ShortCut) then begin
    66687339      if JobTest(UnFocus, jFarm, [eTreaty]) then
    6669         MenuClick(mFarm)
     7340        mFarm.Click
    66707341      else if JobTest(UnFocus, jClear, [eTreaty]) then
    6671         MenuClick(mClear)
     7342        mClear.Click
    66727343      else MenuClick_Check(TerrainPopup, mIrrigation);
    66737344    end
    66747345    else if BLoad.Test(ShortCut) then MenuClick_Check(UnitPopup, mLoad)
    66757346    else if BAfforestMine.Test(ShortCut) then begin
    6676       if JobTest(UnFocus, jAfforest, [eTreaty]) then MenuClick(mAfforest)
     7347      if JobTest(UnFocus, jAfforest, [eTreaty]) then mAfforest.Click
    66777348        else MenuClick_Check(TerrainPopup, mMine);
    66787349    end
     
    66817352    else if BPollution.Test(ShortCut) then MenuClick_Check(TerrainPopup, mPollution)
    66827353    else if BRailRoad.Test(ShortCut) then begin
    6683       if JobTest(UnFocus, jRR, [eTreaty]) then MenuClick(mRR)
     7354      if JobTest(UnFocus, jRR, [eTreaty]) then mRailRoad.Click
    66847355        else MenuClick_Check(TerrainPopup, mRoad);
    66857356    end
     
    66987369end;
    66997370
    6700 procedure TMainScreen.MenuClick(Sender: TObject);
    6701 
    6702   function DoJob(j0: integer): integer;
    6703   var
    6704     Loc0, Movement0: integer;
    6705   begin
    6706     with MyUn[UnFocus] do
     7371function TMainScreen.DoJob(j0: Integer): Integer;
     7372var
     7373  Loc0, Movement0: Integer;
     7374begin
     7375  with MyUn[UnFocus] do
     7376  begin
     7377    DestinationMarkON := False;
     7378    PaintDestination;
     7379    Loc0 := Loc;
     7380    Movement0 := Movement;
     7381    if j0 < 0 then
     7382      Result := ProcessEnhancement(UnFocus, MyData.EnhancementJobs)
     7383      // terrain enhancement
     7384    else
     7385      Result := Server(sStartJob + j0 shl 4, Me, UnFocus, nil^);
     7386    if Result >= rExecuted then
    67077387    begin
    6708       DestinationMarkON := false;
    6709       PaintDestination;
    6710       Loc0 := Loc;
    6711       Movement0 := Movement;
    6712       if j0 < 0 then
    6713         result := ProcessEnhancement(UnFocus, MyData.EnhancementJobs)
    6714         // terrain enhancement
    6715       else
    6716         result := Server(sStartJob + j0 shl 4, me, UnFocus, nil^);
    6717       if result >= rExecuted then
     7388      if Result = eDied then
     7389        UnFocus := -1;
     7390      PaintLoc(Loc0);
     7391      if UnFocus >= 0 then
    67187392      begin
    6719         if result = eDied then
    6720           UnFocus := -1;
    6721         PaintLoc(Loc0);
    6722         if UnFocus >= 0 then
     7393        if (j0 < 0) and (Result <> eJobDone) then
     7394          // multi-turn terrain enhancement
     7395          Status := Status and ($FFFF - usStay - usRecover - usGoto) or
     7396            usEnhance
     7397        else
     7398          Status := Status and
     7399            ($FFFF - usStay - usRecover - usGoto - usEnhance);
     7400        if (Job <> jNone) or (Movement0 < 100) then
    67237401        begin
    6724           if (j0 < 0) and (result <> eJobDone) then
    6725             // multi-turn terrain enhancement
    6726             Status := Status and ($FFFF - usStay - usRecover - usGoto) or
    6727               usEnhance
    6728           else
    6729             Status := Status and
    6730               ($FFFF - usStay - usRecover - usGoto - usEnhance);
    6731           if (Job <> jNone) or (Movement0 < 100) then
    6732           begin
    6733             Status := Status and not usWaiting;
    6734             NextUnit(UnStartLoc, true);
    6735           end
    6736           else
    6737             PanelPaint;
     7402          Status := Status and not usWaiting;
     7403          NextUnit(UnStartLoc, True);
    67387404        end
    67397405        else
    6740           NextUnit(UnStartLoc, true);
    6741       end;
    6742     end;
    6743     case result of
    6744       eNoBridgeBuilding:
    6745         SoundMessage(Phrases.Lookup('NOBB'), 'INVALID');
    6746       eNoCityTerrain:
    6747         SoundMessage(Phrases.Lookup('NOCITY'), 'INVALID');
    6748       eTreaty:
    6749         SoundMessage(Tribe[MyRO.Territory[Loc0]].TPhrase('PEACE_NOWORK'),
    6750           'NOMOVE_TREATY');
    6751     else
    6752       if result < rExecuted then
    6753         Play('INVALID')
    6754     end;
    6755   end;
    6756 
    6757 var
    6758   i, uix, NewFocus, Loc0, OldMaster, Destination, cix, cixOldHome,
    6759     ServerResult: integer;
    6760   AltGovs, RevolutionChanged: boolean;
    6761   QueryText: string;
    6762 
    6763 begin
    6764   if Sender = mResign then
    6765     if ClientMode = cEditMap then
    6766     begin
    6767       if Edited then
    6768       begin
    6769         QueryText := Phrases.Lookup('MAP_CLOSE');
    6770         case SimpleQuery(mkYesNoCancel, QueryText, '') of
    6771           mrIgnore:
    6772             Server(sAbandonMap, me, 0, nil^);
    6773           mrOK:
    6774             Server(sSaveMap, me, 0, nil^);
    6775         end
     7406          PanelPaint;
    67767407      end
    67777408      else
    6778         Server(sAbandonMap, me, 0, nil^)
    6779     end
     7409        NextUnit(UnStartLoc, True);
     7410    end;
     7411  end;
     7412  case Result of
     7413    eNoBridgeBuilding:
     7414      SoundMessage(Phrases.Lookup('NOBB'), 'INVALID');
     7415    eNoCityTerrain:
     7416      SoundMessage(Phrases.Lookup('NOCITY'), 'INVALID');
     7417    eTreaty:
     7418      SoundMessage(Tribe[MyRO.Territory[Loc0]].TPhrase('PEACE_NOWORK'),
     7419        'NOMOVE_TREATY');
     7420  else
     7421    if Result < rExecuted then
     7422      Play('INVALID');
     7423  end;
     7424end;
     7425
     7426function TMainScreen.GetBattleDlg: TBattleDlg;
     7427begin
     7428  if not Assigned(FBattleDlg) then FBattleDlg := TBattleDlg.Create(nil);
     7429  Result := FBattleDlg;
     7430end;
     7431
     7432function TMainScreen.GetCityDlg: TCityDlg;
     7433begin
     7434  if not Assigned(FCityDlg) then begin
     7435    FCityDlg := TCityDlg.Create(nil);
     7436    FCityDlg.CheckAge;
     7437  end;
     7438  Result := FCityDlg;
     7439end;
     7440
     7441function TMainScreen.GetCityTypeDlg: TCityTypeDlg;
     7442begin
     7443  if not Assigned(FCityTypeDlg) then FCityTypeDlg := TCityTypeDlg.Create(nil);
     7444  Result := FCityTypeDlg;
     7445end;
     7446
     7447function TMainScreen.GetDiaDlg: TDiaDlg;
     7448begin
     7449  if not Assigned(FDiaDlg) then begin
     7450    FDiaDlg := TDiaDlg.Create(nil);
     7451    ArrangeDialog(FDiaDlg);
     7452  end;
     7453  Result := FDiaDlg;
     7454end;
     7455
     7456function TMainScreen.GetDraftDlg: TDraftDlg;
     7457begin
     7458  if not Assigned(FDraftDlg) then FDraftDlg := TDraftDlg.Create(nil);
     7459  Result := FDraftDlg;
     7460end;
     7461
     7462function TMainScreen.GetEnhanceDlg: TEnhanceDlg;
     7463begin
     7464  if not Assigned(FEnhanceDlg) then FEnhanceDlg := TEnhanceDlg.Create(nil);
     7465  Result := FEnhanceDlg;
     7466end;
     7467
     7468function TMainScreen.GetHelpDlg: THelpDlg;
     7469begin
     7470  if not Assigned(FHelpDlg) then begin
     7471    FHelpDlg := THelpDlg.Create(nil);
     7472    ArrangeDialog(FHelpDlg);
     7473    FHelpDlg.Difficulty := G.Difficulty[Me];
     7474  end;
     7475  Result := FHelpDlg;
     7476end;
     7477
     7478function TMainScreen.GetListDlg: TListDlg;
     7479begin
     7480  if not Assigned(FListDlg) then begin
     7481    FListDlg := TListDlg.Create(nil);
     7482    ArrangeDialog(FListDlg);
     7483  end;
     7484  Result := FListDlg;
     7485end;
     7486
     7487function TMainScreen.GetMessgExDlg: TMessgExDlg;
     7488begin
     7489  if not Assigned(FMessgExDlg) then FMessgExDlg := TMessgExDlg.Create(nil);
     7490    Result := FMessgExDlg;
     7491end;
     7492
     7493function TMainScreen.GetModalSelectDlg: TModalSelectDlg;
     7494begin
     7495  if not Assigned(FModalSelectDlg) then FModalSelectDlg := TModalSelectDlg.Create(nil);
     7496  Result := FModalSelectDlg;
     7497end;
     7498
     7499function TMainScreen.GetNatStatDlg: TNatStatDlg;
     7500begin
     7501  if not Assigned(FNatStatDlg) then begin
     7502    FNatStatDlg := TNatStatDlg.Create(nil);
     7503    ArrangeDialog(FNatStatDlg);
     7504    FNatStatDlg.CheckAge;
     7505  end;
     7506  Result := FNatStatDlg;
     7507end;
     7508
     7509function TMainScreen.GetNegoDlg: TNegoDlg;
     7510begin
     7511  if not Assigned(FNegoDlg) then FNegoDlg := TNegoDlg.Create(nil);
     7512  Result := FNegoDlg;
     7513end;
     7514
     7515function TMainScreen.GetRatesDlg: TRatesDlg;
     7516begin
     7517  if not Assigned(FRatesDlg) then begin
     7518    //FRatesDlg := TRatesDlg.Create(nil);
     7519    DpiApplication.CreateForm(TRatesDlg, FRatesDlg);
     7520    FRatesDlg.Show;
     7521  end;
     7522  Result := FRatesDlg;
     7523end;
     7524
     7525function TMainScreen.GetTechTreeDlg: TTechTreeDlg;
     7526begin
     7527  if not Assigned(FTechTreeDlg) then FTechTreeDlg := TTechTreeDlg.Create(nil);
     7528  Result := FTechTreeDlg;
     7529end;
     7530
     7531procedure TMainScreen.mDisbandOrUtilizeClick(Sender: TObject);
     7532var
     7533  Loc0: Integer;
     7534begin
     7535  if UnFocus >= 0 then
     7536  with TUn(MyUn[UnFocus]) do begin
     7537    if (Sender = mUtilize) and
     7538      not(Server(sRemoveUnit - sExecute, Me, UnFocus, nil^) = eUtilized) then
     7539    begin
     7540      SimpleMessage(Phrases2.Lookup('SHIP_UTILIZE'));
     7541      // freight for colony ship is the only case in which the command is
     7542      // available to player though not valid
     7543      Exit;
     7544    end;
     7545    if (Sender = mUtilize) and (Health < 100) then
     7546      if SimpleQuery(mkYesNo, Phrases.Lookup('DAMAGED_UTILIZE'), '') <> mrOK
     7547      then
     7548        Exit;
     7549    Loc0 := Loc;
     7550    CityOptimizer_BeforeRemoveUnit(UnFocus);
     7551    if Server(sRemoveUnit, Me, UnFocus, nil^) = eUtilized then
     7552      Play('CITY_UTILIZE')
    67807553    else
    6781     begin
    6782       if Server(sGetGameChanged, 0, 0, nil^) = eOK then
    6783       begin
    6784         QueryText := Phrases.Lookup('RESIGN');
    6785         case SimpleQuery(mkYesNoCancel, QueryText, '') of
    6786           mrIgnore:
    6787             Server(sResign, 0, 0, nil^);
    6788           mrOK:
    6789             Server(sBreak, 0, 0, nil^)
    6790         end
    6791       end
    6792       else
    6793         Server(sResign, 0, 0, nil^)
    6794     end
    6795   else if Sender = mEmpire then
    6796     RatesDlg.ShowNewContent(wmPersistent)
    6797   else if Sender = mRevolution then
    6798   begin
    6799     AltGovs := false;
    6800     for i := 2 to nGov - 1 do
    6801       if (GovPreq[i] <> preNA) and
    6802         ((GovPreq[i] = preNone) or (MyRO.Tech[GovPreq[i]] >= tsApplicable)) then
    6803         AltGovs := true;
    6804 
    6805     if not AltGovs then
    6806       SoundMessage(Phrases.Lookup('NOALTGOVS'), 'MSG_DEFAULT')
    6807     else
    6808     begin
    6809       RevolutionChanged := false;
    6810       if MyRO.Happened and phChangeGov <> 0 then
    6811       begin
    6812         ModalSelectDlg.ShowNewContent(wmModal, kGov);
    6813         if ModalSelectDlg.result >= 0 then
    6814         begin
    6815           Play('NEWGOV');
    6816           Server(sSetGovernment, me, ModalSelectDlg.result, nil^);
    6817           CityOptimizer_BeginOfTurn;
    6818           RevolutionChanged := true;
    6819         end
    6820       end
    6821       else
    6822       with MessgExDlg do
    6823       begin // revolution!
    6824         MessgExDlg.MessgText := Tribe[me].TPhrase('REVOLUTION');
    6825         MessgExDlg.Kind := mkYesNo;
    6826         MessgExDlg.IconKind := mikPureIcon;
    6827         MessgExDlg.IconIndex := 72; // anarchy palace
    6828         MessgExDlg.ShowModal;
    6829         if ModalResult = mrOK then
    6830         begin
    6831           Play('REVOLUTION');
    6832           Server(sRevolution, me, 0, nil^);
    6833           RevolutionChanged := true;
    6834           if NatStatDlg.Visible then
    6835             NatStatDlg.Close;
    6836           if CityDlg.Visible then
    6837             CityDlg.Close;
    6838         end
    6839       end;
    6840       if RevolutionChanged then
    6841         UpdateViews(true);
    6842     end
    6843   end
    6844   else if Sender = mWebsite then
    6845     OpenURL(CevoHomepage)
    6846   else if Sender = mRandomMap then
    6847   begin
    6848     if not Edited or (SimpleQuery(mkYesNo, Phrases.Lookup('MAP_RANDOM'), '')
    6849       = mrOK) then
    6850     begin
    6851       Server(sRandomMap, me, 0, nil^);
    6852       Edited := true;
    6853       MapValid := false;
    6854       PaintAllMaps;
    6855     end
    6856   end
    6857   else if Sender = mJump then
    6858   begin
    6859     if supervising then
    6860       Jump[0] := 20
    6861     else
    6862       Jump[me] := 20;
    6863     EndTurn(true);
    6864   end
    6865   else if Sender = mRun then
    6866   begin
    6867     if supervising then
    6868       Jump[0] := 999999
    6869     else
    6870       Jump[me] := 999999;
    6871     EndTurn(true);
    6872   end
    6873   else if Sender = mEnhanceDef then
    6874   begin
    6875     if UnFocus >= 0 then
    6876       EnhanceDlg.ShowNewContent(wmPersistent,
    6877         MyMap[MyUn[UnFocus].Loc] and fTerrain)
    6878     else
    6879       EnhanceDlg.ShowNewContent(wmPersistent)
    6880   end
    6881   else if Sender = mCityTypes then
    6882     CityTypeDlg.ShowNewContent(wmModal)
    6883     // must be modal because types are not saved before closing
    6884   else if Sender = mUnitStat then
    6885   begin
    6886     if G.Difficulty[me] > 0 then
    6887       ListDlg.ShowNewContent_MilReport(wmPersistent, me)
    6888     else
    6889     begin
    6890       i := 1;
    6891       while (i < nPl) and (1 shl i and MyRO.Alive = 0) do
    6892         inc(i);
    6893       if i < nPl then
    6894         ListDlg.ShowNewContent_MilReport(wmPersistent, i);
    6895     end;
    6896   end
    6897   else if Sender = mEUnitStat then
    6898   begin
    6899     if MyRO.nEnemyModel > 0 then
    6900       ListDlg.ShowNewContent(wmPersistent, kAllEModels);
    6901   end
    6902   else if Sender = mCityStat then
    6903     ListDlg.ShowNewContent(wmPersistent, kCities)
    6904   else if Sender = mScienceStat then
    6905     ListDlg.ShowNewContent(wmPersistent, kScience)
    6906   else if Sender = mNations then
    6907     NatStatDlg.ShowNewContent(wmPersistent)
    6908   else if Sender = mHelp then
    6909     if ClientMode = cEditMap then
    6910       HelpDlg.ShowNewContent(wmPersistent, hkText, HelpDlg.TextIndex('MAPEDIT'))
    6911     else
    6912       HelpDlg.ShowNewContent(wmPersistent, hkMisc, miscMain)
    6913   else if Sender = mTechTree then
    6914     TechTreeDlg.ShowModal
    6915   else if Sender = mWonders then
    6916     WondersDlg.ShowNewContent(wmPersistent)
    6917   else if Sender = mDiagram then
    6918     DiaDlg.ShowNewContent_Charts(wmPersistent)
    6919   else if Sender = mShips then
    6920     DiaDlg.ShowNewContent_Ship(wmPersistent)
    6921   else if Sender = mWait then
    6922   begin
    6923     if UnFocus >= 0 then
    6924     begin
    6925       DestinationMarkON := false;
    6926       PaintDestination;
    6927       MyUn[UnFocus].Status := MyUn[UnFocus].Status and
    6928         ($FFFF - usStay - usRecover - usGoto - usEnhance) or usWaiting;
    6929     end;
    6930     NextUnit(-1, false);
    6931   end
    6932   else if UnFocus >= 0 then
    6933     with TUn(MyUn[UnFocus]) do
    6934       if Sender = mGoOn then
    6935       begin
    6936         if Status shr 16 = $7FFF then
    6937           Destination := maNextCity
    6938         else
    6939           Destination := Status shr 16;
    6940         Status := Status and not(usStay or usRecover) or usWaiting;
    6941         MoveToLoc(Destination, true);
    6942       end
    6943       else if Sender = mHome then
    6944         if MyMap[Loc] and fCity <> 0 then
    6945         begin
    6946           cixOldHome := Home;
    6947           if Server(sSetUnitHome, me, UnFocus, nil^) >= rExecuted then
    6948           begin
    6949             CityOptimizer_CityChange(cixOldHome);
    6950             CityOptimizer_CityChange(Home);
    6951             UpdateViews(true);
    6952           end
    6953           else
    6954             Play('INVALID');
    6955         end
    6956         else
    6957         begin
    6958           Status := Status and not(usStay or usRecover or usEnhance);
    6959           MoveToLoc(maNextCity, true)
    6960         end
    6961       else if Sender = mCentre then
    6962       begin
    6963         Centre(Loc);
    6964         PaintAllMaps;
    6965       end
    6966       else if Sender = mCity then
    6967       begin
    6968         Loc0 := Loc;
    6969         if MyMap[Loc] and fCity = 0 then
    6970         begin // build city
    6971           if DoJob(jCity) = eCity then
    6972           begin
    6973             MapValid := false;
    6974             PaintAll;
    6975             ZoomToCity(Loc0, true, chFounded);
    6976           end;
    6977         end
    6978         else
    6979         begin
    6980           CityOptimizer_BeforeRemoveUnit(UnFocus);
    6981           ServerResult := Server(sAddToCity, me, UnFocus, nil^);
    6982           if ServerResult >= rExecuted then
    6983           begin
    6984             cix := MyRO.nCity - 1;
    6985             while (cix >= 0) and (MyCity[cix].Loc <> Loc0) do
    6986               dec(cix);
    6987             assert(cix >= 0);
    6988             CityOptimizer_CityChange(cix);
    6989             CityOptimizer_AfterRemoveUnit; // does nothing here
    6990             SetTroopLoc(Loc0);
    6991             UpdateViews(true);
    6992             DestinationMarkON := false;
    6993             PaintDestination;
    6994             UnFocus := -1;
    6995             PaintLoc(Loc0);
    6996             NextUnit(UnStartLoc, true);
    6997           end
    6998           else if ServerResult = eMaxSize then
    6999             SimpleMessage(Phrases.Lookup('ADDTOMAXSIZE'));
    7000         end
    7001       end
    7002       else if Sender = mRoad then
    7003         DoJob(jRoad)
    7004       else if Sender = mRR then
    7005         DoJob(jRR)
    7006       else if Sender = mClear then
    7007         DoJob(jClear)
    7008       else if Sender = mIrrigation then
    7009         DoJob(jIrr)
    7010       else if Sender = mFarm then
    7011         DoJob(jFarm)
    7012       else if Sender = mAfforest then
    7013         DoJob(jAfforest)
    7014       else if Sender = mMine then
    7015         DoJob(jMine)
    7016       else if Sender = mCanal then
    7017         DoJob(jCanal)
    7018       else if Sender = MTrans then
    7019         DoJob(jTrans)
    7020       else if Sender = mFort then
    7021         DoJob(jFort)
    7022       else if Sender = mAirBase then
    7023         DoJob(jBase)
    7024       else if Sender = mPollution then
    7025         DoJob(jPoll)
    7026       else if Sender = mPillage then
    7027         DoJob(jPillage)
    7028       else if Sender = mEnhance then
    7029         DoJob(-1)
    7030       else if Sender = mStay then
    7031       begin
    7032         DestinationMarkON := false;
    7033         PaintDestination;
    7034         Status := Status and ($FFFF - usRecover - usGoto - usEnhance) or usStay;
    7035         if Job > jNone then
    7036           Server(sStartJob + jNone shl 4, me, UnFocus, nil^);
    7037         NextUnit(UnStartLoc, true);
    7038       end
    7039       else if Sender = mRecover then
    7040       begin
    7041         DestinationMarkON := false;
    7042         PaintDestination;
    7043         Status := Status and ($FFFF - usStay - usGoto - usEnhance) or usRecover;
    7044         if Job > jNone then
    7045           Server(sStartJob + jNone shl 4, me, UnFocus, nil^);
    7046         NextUnit(UnStartLoc, true);
    7047       end
    7048       else if Sender = mNoOrders then
    7049       begin
    7050         Status := Status and not usWaiting;
    7051         NextUnit(UnStartLoc, true);
    7052       end
    7053       else if Sender = mPrevUnit then
    7054       begin
    7055         Status := Status and not usWaiting;
    7056         FocusNextUnit(-1);
    7057       end
    7058       else if Sender = mNextUnit then
    7059       begin
    7060         Status := Status and not usWaiting;
    7061         FocusNextUnit(1);
    7062       end
    7063       else if Sender = mCancel then
    7064       begin
    7065         DestinationMarkON := false;
    7066         PaintDestination;
    7067         Status := Status and ($FFFF - usRecover - usGoto - usEnhance);
    7068         if Job > jNone then
    7069           Server(sStartJob + jNone shl 4, me, UnFocus, nil^);
    7070       end
    7071       else if (Sender = mDisband) or (Sender = mUtilize) then
    7072       begin
    7073         if (Sender = mUtilize) and
    7074           not(Server(sRemoveUnit - sExecute, me, UnFocus, nil^) = eUtilized)
    7075         then
    7076         begin
    7077           SimpleMessage(Phrases2.Lookup('SHIP_UTILIZE'));
    7078           // freight for colony ship is the only case in which the command is
    7079           // available to player though not valid
    7080           exit
    7081         end;
    7082         if (Sender = mUtilize) and (Health < 100) then
    7083           if SimpleQuery(mkYesNo, Phrases.Lookup('DAMAGED_UTILIZE'), '') <> mrOK
    7084           then
    7085             exit;
    7086         Loc0 := Loc;
    7087         CityOptimizer_BeforeRemoveUnit(UnFocus);
    7088         if Server(sRemoveUnit, me, UnFocus, nil^) = eUtilized then
    7089           Play('CITY_UTILIZE')
    7090         else
    7091           Play('DISBAND');
    7092         CityOptimizer_AfterRemoveUnit;
    7093         SetTroopLoc(Loc0);
    7094         UpdateViews(true);
    7095         DestinationMarkON := false;
    7096         PaintDestination;
    7097         UnFocus := -1;
    7098         PaintLoc(Loc0);
    7099         NextUnit(UnStartLoc, true);
    7100       end
    7101       else if Sender = mLoad then
    7102       begin
    7103         i := Server(sLoadUnit, me, UnFocus, nil^);
    7104         if i >= rExecuted then
    7105         begin
    7106           if MyModel[mix].Domain = dAir then
    7107             Play('MOVE_PLANELANDING')
    7108           else
    7109             Play('MOVE_LOAD');
    7110           DestinationMarkON := false;
    7111           PaintDestination;
    7112           Status := Status and ($FFFF - usWaiting - usStay - usRecover - usGoto
    7113             - usEnhance);
    7114           NextUnit(UnStartLoc, true);
    7115         end
    7116         else if i = eNoTime_Load then
    7117           if MyModel[mix].Domain = dAir then
    7118             SoundMessage(Phrases.Lookup('NOTIMELOADAIR'), 'NOMOVE_TIME')
    7119           else
    7120             SoundMessage(Format(Phrases.Lookup('NOTIMELOADGROUND'),
    7121               [MovementToString(MyModel[mix].speed)]), 'NOMOVE_TIME');
    7122       end
    7123       else if Sender = mUnload then
    7124         if Master >= 0 then
    7125         begin
    7126           OldMaster := Master;
    7127           i := Server(sUnloadUnit, me, UnFocus, nil^);
    7128           if i >= rExecuted then
    7129           begin
    7130             if MyModel[mix].Domain = dAir then
    7131               Play('MOVE_PLANESTART')
    7132             else if (MyModel[MyUn[OldMaster].mix].Domain = dAir) and
    7133               (MyMap[Loc] and fCity = 0) and (MyMap[Loc] and fTerImp <> tiBase)
    7134             then
    7135               Play('MOVE_PARACHUTE')
    7136             else
    7137               Play('MOVE_UNLOAD');
    7138             Status := Status and not usWaiting;
    7139             if MyModel[mix].Domain <> dAir then
    7140               NextUnit(Loc, true)
    7141             else
    7142               PanelPaint;
    7143           end
    7144           else if i = eNoTime_Load then
    7145             if MyModel[mix].Domain = dAir then
    7146               SoundMessage(Phrases.Lookup('NOTIMELOADAIR'), 'NOMOVE_TIME')
    7147             else
    7148               SoundMessage(Format(Phrases.Lookup('NOTIMELOADGROUND'),
    7149                 [MovementToString(MyModel[mix].speed)]), 'NOMOVE_TIME');
    7150         end
    7151         else
    7152         begin
    7153           NewFocus := -1;
    7154           uix := UnFocus;
    7155           for i := 1 to MyRO.nUn - 1 do
    7156           begin
    7157             uix := (uix + MyRO.nUn - 1) mod MyRO.nUn;
    7158             if (MyUn[uix].Master = UnFocus) and
    7159               (MyUn[uix].Movement = integer(MyModel[MyUn[uix].mix].speed)) then
    7160             begin
    7161               MyUn[uix].Status := MyUn[uix].Status or usWaiting;
    7162               NewFocus := uix
    7163             end;
    7164           end;
    7165           if NewFocus >= 0 then
    7166           begin
    7167             SetUnFocus(NewFocus);
    7168             SetTroopLoc(Loc);
    7169             PanelPaint
    7170           end;
    7171         end
    7172       else if Sender = mSelectTransport then
    7173         Server(sSelectTransport, me, UnFocus, nil^)
     7554      Play('DISBAND');
     7555    CityOptimizer_AfterRemoveUnit;
     7556    SetTroopLoc(Loc0);
     7557    UpdateViews(True);
     7558    DestinationMarkON := False;
     7559    PaintDestination;
     7560    UnFocus := -1;
     7561    PaintLoc(Loc0);
     7562    NextUnit(UnStartLoc, True);
     7563  end;
    71747564end;
    71757565
    71767566procedure TMainScreen.InitPopup(Popup: TDpiPopupMenu);
    71777567var
    7178   i, p1, Tile, Test: integer;
    7179   NoSuper, extended, Multi, NeedSep, HaveCities: boolean;
    7180   LastSep, m: TDpiMenuItem;
     7568  I, p1, Tile, Test: Integer;
     7569  NoSuper, Extended, Multi, NeedSep, HaveCities: Boolean;
     7570  LastSep, M: TDpiMenuItem;
    71817571  mox: ^TModel;
    71827572begin
    7183   NoSuper := not supervising and (1 shl me and MyRO.Alive <> 0);
    7184   HaveCities := false;
    7185   for i := 0 to MyRO.nCity - 1 do
    7186     if MyCity[i].Loc >= 0 then
     7573  NoSuper := not Supervising and (1 shl Me and MyRO.Alive <> 0);
     7574  HaveCities := False;
     7575  for I := 0 to MyRO.nCity - 1 do
     7576    if MyCity[I].Loc >= 0 then
    71877577    begin
    7188       HaveCities := true;
     7578      HaveCities := True;
    71897579      Break;
    71907580    end;
     
    71927582  begin
    71937583    mTechTree.Visible := ClientMode <> cEditMap;
    7194     mResign.Enabled := supervising or (me = 0) and (ClientMode < scContact);
     7584    mResign.Enabled := Supervising or (Me = 0) and (ClientMode < scContact);
    71957585    mRandomMap.Visible := (ClientMode = cEditMap) and
    7196       (Server(sMapGeneratorRequest, me, 0, nil^) = eOK);
     7586      (Server(sMapGeneratorRequest, Me, 0, nil^) = eOK);
    71977587    mOptions.Visible := ClientMode <> cEditMap;
    71987588    mManip.Visible := ClientMode <> cEditMap;
     
    72087598      case SoundMode of
    72097599        smOff:
    7210           mSoundOff.Checked := true;
     7600          mSoundOff.Checked := True;
    72117601        smOn:
    7212           mSoundOn.Checked := true;
     7602          mSoundOn.Checked := True;
    72137603        smOnAlt:
    7214           mSoundOnAlt.Checked := true;
    7215       end;
    7216 
    7217       for i := 0 to nTestFlags - 1 do
    7218         mManip[i].Checked := MyRO.TestFlags and (1 shl i) <> 0;
    7219       mManip.Enabled := supervising or (me = 0);
    7220 
    7221       Multi := false;
     7604          mSoundOnAlt.Checked := True;
     7605      end;
     7606
     7607      for I := 0 to nTestFlags - 1 do
     7608        mManip[I].Checked := MyRO.TestFlags and (1 shl I) <> 0;
     7609      mManip.Enabled := Supervising or (Me = 0);
     7610
     7611      Multi := False;
    72227612      for p1 := 1 to nPl - 1 do
    72237613        if G.RO[p1] <> nil then
    7224           Multi := true;
     7614          Multi := True;
    72257615      mEnemyMovement.Visible := not Multi;
    72267616    end;
     
    72287618    if NoSuper and (ClientMode < scContact) then
    72297619    begin
    7230       mCityTypes.Enabled := false;
     7620      mCityTypes.Enabled := False;
    72317621      // check if city types already usefull:
    72327622      if MyRO.nCity > 0 then
    7233         for i := nWonder to nImp - 1 do
    7234           if (i <> imTrGoods) and (Imp[i].Kind = ikCommon) and
    7235             (Imp[i].Preq <> preNA) and
    7236             ((Imp[i].Preq = preNone) or (MyRO.Tech[Imp[i].Preq] >= tsApplicable))
     7623        for I := nWonder to nImp - 1 do
     7624          if (I <> imTrGoods) and (Imp[I].Kind = ikCommon) and
     7625            (Imp[I].Preq <> preNA) and
     7626            ((Imp[I].Preq = preNone) or (MyRO.Tech[Imp[I].Preq] >= tsApplicable))
    72377627          then
    72387628          begin
    7239             mCityTypes.Enabled := true;
     7629            mCityTypes.Enabled := True;
    72407630            Break
    72417631          end;
    72427632    end;
    7243     mViewpoint.Visible := (ClientMode <> cEditMap) and supervising;
     7633    mViewpoint.Visible := (ClientMode <> cEditMap) and Supervising;
    72447634    mViewpoint.Enabled := G.RO[0].Turn > 0;
    7245     if supervising then
     7635    if Supervising then
    72467636    begin
    72477637      EmptyMenu(mViewpoint);
     
    72497639        if (p1 = 0) or (1 shl p1 and G.RO[0].Alive <> 0) then
    72507640        begin
    7251           m := TDpiMenuItem.Create(mViewpoint);
     7641          M := TDpiMenuItem.Create(mViewpoint);
    72527642          if p1 = 0 then
    7253             m.Caption := Phrases.Lookup('SUPER')
     7643            M.Caption := Phrases.Lookup('SUPER')
    72547644          else
    7255             m.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG'));
    7256           m.Tag := p1;
    7257           m.OnClick := ViewpointClick;
     7645            M.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG'));
     7646          M.Tag := p1;
     7647          M.OnClick := ViewpointClick;
    72587648          if p1 < 10 then
    7259             m.ShortCut := ShortCut(48 + p1, [ssCtrl]);
    7260           m.RadioItem := true;
    7261           if p1 = me then
    7262             m.Checked := true;
    7263           mViewpoint.Add(m);
     7649            M.ShortCut := ShortCut(48 + p1, [ssCtrl]);
     7650          M.RadioItem := True;
     7651          if p1 = Me then
     7652            M.Checked := True;
     7653          mViewpoint.Add(M);
    72647654        end
    72657655    end;
    7266     mDebugMap.Visible := (ClientMode <> cEditMap) and supervising;
    7267     if supervising then
     7656    mDebugMap.Visible := (ClientMode <> cEditMap) and Supervising;
     7657    if Supervising then
    72687658    begin
    72697659      EmptyMenu(mDebugMap);
     
    72717661        if (p1 = 0) or (1 shl p1 and G.RO[0].Alive <> 0) then
    72727662        begin
    7273           m := TDpiMenuItem.Create(mDebugMap);
     7663          M := TDpiMenuItem.Create(mDebugMap);
    72747664          if p1 = 0 then
    7275             m.Caption := Phrases2.Lookup('MENU_DEBUGMAPOFF')
     7665            M.Caption := Phrases2.Lookup('MENU_DEBUGMAPOFF')
    72767666          else
    7277             m.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG'));
     7667            M.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG'));
    72787668          if p1 = 0 then
    7279             m.Tag := -1
     7669            M.Tag := -1
    72807670          else
    7281             m.Tag := p1;
    7282           m.OnClick := DebugMapClick;
     7671            M.Tag := p1;
     7672          M.OnClick := DebugMapClick;
    72837673          if p1 < 10 then
    7284             m.ShortCut := ShortCut(48 + p1, [ssAlt]);
    7285           m.RadioItem := true;
    7286           if m.Tag = MainMap.pDebugMap then
    7287             m.Checked := true;
    7288           mDebugMap.Add(m);
     7674            M.ShortCut := ShortCut(48 + p1, [ssAlt]);
     7675          M.RadioItem := True;
     7676          if M.Tag = MainMap.pDebugMap then
     7677            M.Checked := True;
     7678          mDebugMap.Add(M);
    72897679        end;
    72907680    end;
     
    73017691      (ClientMode < scContact);
    73027692    mUnitStat.Enabled := NoSuper or (MyRO.Turn > 0);
    7303     mCityStat.Visible := 1 shl me and MyRO.Alive <> 0;
     7693    mCityStat.Visible := 1 shl Me and MyRO.Alive <> 0;
    73047694    mCityStat.Enabled := HaveCities;
    7305     mScienceStat.Visible := true;
     7695    mScienceStat.Visible := True;
    73067696    mScienceStat.Enabled := not NoSuper or (MyRO.ResearchTech >= 0) or
    73077697      (MyRO.Happened and phTech <> 0) or (MyRO.Happened and phGameEnd <> 0)
     
    73107700    mEUnitStat.Enabled := MyRO.nEnemyModel > 0;
    73117701    { mWonders.Enabled:= false;
    7312       for i:=0 to nWonder - 1 do if MyRO.Wonder[i].CityID <> WonderNotBuiltYet then
    7313       mWonders.Enabled:=true; }
     7702      for I:=0 to nWonder - 1 do if MyRO.Wonder[I].CityID <> WonderNotBuiltYet then
     7703      mWonders.Enabled:=True; }
    73147704    mDiagram.Enabled := MyRO.Turn >= 2;
    7315     mShips.Enabled := false;
     7705    mShips.Enabled := False;
    73167706    for p1 := 0 to nPl - 1 do
    73177707      if MyRO.Ship[p1].Parts[spComp] + MyRO.Ship[p1].Parts[spPow] +
    73187708        MyRO.Ship[p1].Parts[spHab] > 0 then
    7319         mShips.Enabled := true;
     7709        mShips.Enabled := True;
    73207710  end
    73217711  else if Popup = UnitPopup then
     
    73237713    mox := @MyModel[MyUn[UnFocus].mix];
    73247714    Tile := MyMap[MyUn[UnFocus].Loc];
    7325     extended := Tile and fCity = 0;
    7326     if extended then
     7715    Extended := Tile and fCity = 0;
     7716    if Extended then
    73277717    begin
    73287718      mCity.Caption := Phrases.Lookup('BTN_FOUND');
     
    73357725    end;
    73367726
    7337     extended := extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves)
     7727    Extended := Extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves)
    73387728      and (MyRO.Wonder[woPyramids].EffectiveOwner >= 0)) and
    73397729      (MyUn[UnFocus].Master < 0) and (Tile and fDeadLands = 0);
    73407730    if (mox.Kind = mkFreight) and (Tile and fCity <> 0) and
    73417731      not Phrases2FallenBackToEnglish or
    7342       (Server(sRemoveUnit - sExecute, me, UnFocus, nil^) = eUtilized) then
     7732      (Server(sRemoveUnit - sExecute, Me, UnFocus, nil^) = eUtilized) then
    73437733    begin
    7344       mDisband.Visible := false;
    7345       mUtilize.Visible := true;
     7734      mDisband.Visible := False;
     7735      mUtilize.Visible := True;
    73467736      if mox.Kind = mkFreight then
    73477737        mUtilize.Caption := Phrases.Lookup('UTILIZE')
     
    73517741    else
    73527742    begin
    7353       mDisband.Visible := true;
    7354       mUtilize.Visible := false
     7743      mDisband.Visible := True;
     7744      mUtilize.Visible := False
    73557745    end;
    73567746    mGoOn.Visible := MyUn[UnFocus].Status and (usGoto or usWaiting) = usGoto or
     
    73597749    mRecover.Visible := (MyUn[UnFocus].Health < 100) and
    73607750      (Tile and fTerrain >= fGrass) and
    7361       ((MyRO.Wonder[woGardens].EffectiveOwner = me) or
     7751      ((MyRO.Wonder[woGardens].EffectiveOwner = Me) or
    73627752      (Tile and fTerrain <> fArctic) and (Tile and fTerrain <> fDesert)) and
    73637753      not((mox.Domain = dAir) and (Tile and fCity = 0) and
     
    73657755    mStay.Visible := not((mox.Domain = dAir) and (Tile and fCity = 0) and
    73667756      (Tile and fTerImp <> tiBase));
    7367     mCity.Visible := extended and (mox.Kind = mkSettler) or
     7757    mCity.Visible := Extended and (mox.Kind = mkSettler) or
    73687758      (Tile and fCity <> 0) and ((mox.Kind in [mkSettler, mkSlaves]) or
    73697759      (MyUn[UnFocus].Flags and unConscripts <> 0));
     
    73737763      (MyUn[UnFocus].Status and (usRecover or usGoto) <> 0);
    73747764
    7375     Test := Server(sLoadUnit - sExecute, me, UnFocus, nil^);
     7765    Test := Server(sLoadUnit - sExecute, Me, UnFocus, nil^);
    73767766    mLoad.Visible := (Test >= rExecuted) or (Test = eNoTime_Load);
    73777767    mUnload.Visible := (MyUn[UnFocus].Master >= 0) or
    73787768      (MyUn[UnFocus].TroopLoad + MyUn[UnFocus].AirLoad > 0);
    7379     mSelectTransport.Visible := Server(sSelectTransport - sExecute, me, UnFocus,
     7769    mSelectTransport.Visible := Server(sSelectTransport - sExecute, Me, UnFocus,
    73807770      nil^) >= rExecuted;
    73817771  end
     
    73847774    mox := @MyModel[MyUn[UnFocus].mix];
    73857775    Tile := MyMap[MyUn[UnFocus].Loc];
    7386     extended := Tile and fCity = 0;
     7776    Extended := Tile and fCity = 0;
    73877777
    73887778    if (Tile and fRiver <> 0) and (MyRO.Tech[adBridgeBuilding] >= tsApplicable)
     
    73907780    begin
    73917781      mRoad.Caption := Phrases.Lookup('BTN_BUILDBRIDGE');
    7392       mRR.Caption := Phrases.Lookup('BTN_BUILDRRBRIDGE');
     7782      mRailRoad.Caption := Phrases.Lookup('BTN_BUILDRRBRIDGE');
    73937783    end
    73947784    else
    73957785    begin
    73967786      mRoad.Caption := Phrases.Lookup('BTN_BUILDROAD');
    7397       mRR.Caption := Phrases.Lookup('BTN_BUILDRR');
     7787      mRailRoad.Caption := Phrases.Lookup('BTN_BUILDRR');
    73987788    end;
    73997789    if Tile and fTerrain = fForest then
     
    74047794      mClear.Caption := Phrases.Lookup('BTN_DRAIN');
    74057795
    7406     extended := extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves)
     7796    Extended := Extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves)
    74077797      and (MyRO.Wonder[woPyramids].EffectiveOwner >= 0)) and
    74087798      (MyUn[UnFocus].Master < 0);
    7409     if extended then
     7799    if Extended then
    74107800    begin
    74117801      mRoad.Visible := JobTest(UnFocus, jRoad, [eNoBridgeBuilding, eTreaty]);
    7412       mRR.Visible := JobTest(UnFocus, jRR, [eNoBridgeBuilding, eTreaty]);
     7802      mRailRoad.Visible := JobTest(UnFocus, jRR, [eNoBridgeBuilding, eTreaty]);
    74137803      mClear.Visible := JobTest(UnFocus, jClear, [eTreaty]);
    74147804      mIrrigation.Visible := JobTest(UnFocus, jIrr, [eTreaty]);
     
    74277817    else
    74287818    begin
    7429       for i := 0 to Popup.Items.Count - 1 do
    7430         Popup.Items[i].Visible := false;
     7819      for I := 0 to Popup.Items.Count - 1 do
     7820        Popup.Items[I].Visible := False;
    74317821    end;
    74327822  end;
     
    74347824  // set menu seperators
    74357825  LastSep := nil;
    7436   NeedSep := false;
    7437   for i := 0 to Popup.Items.Count - 1 do
    7438     if Popup.Items[i].Caption = '-' then
     7826  NeedSep := False;
     7827  for I := 0 to Popup.Items.Count - 1 do
     7828    if Popup.Items[I].Caption = '-' then
    74397829    begin
    7440       Popup.Items[i].Visible := NeedSep;
     7830      Popup.Items[I].Visible := NeedSep;
    74417831      if NeedSep then
    7442         LastSep := Popup.Items[i];
    7443       NeedSep := false
     7832        LastSep := Popup.Items[I];
     7833      NeedSep := False
    74447834    end
    7445     else if Popup.Items[i].Visible then
    7446       NeedSep := true;
     7835    else if Popup.Items[I].Visible then
     7836      NeedSep := True;
    74477837  if (LastSep <> nil) and not NeedSep then
    7448     LastSep.Visible := false
     7838    LastSep.Visible := False
    74497839end;
    74507840
     
    74657855end;
    74667856
    7467 procedure TMainScreen.CityClosed(Activateuix: integer; StepFocus: boolean;
    7468   SelectFocus: boolean);
    7469 begin
    7470   if supervising then
     7857procedure TMainScreen.CityClosed(Activateuix: Integer; StepFocus: Boolean;
     7858  SelectFocus: Boolean);
     7859begin
     7860  if Supervising then
    74717861  begin
    74727862    SetTroopLoc(-1);
     
    74857875    end
    74867876    else if StepFocus then
    7487       NextUnit(TroopLoc, true)
     7877      NextUnit(TroopLoc, True)
    74887878    else
    74897879    begin
     
    74967886procedure TMainScreen.Toggle(Sender: TObject);
    74977887begin
    7498   TDpiMenuItem(Sender).Checked := not TDpiMenuItem(Sender).Checked
     7888  TDpiMenuItem(Sender).Checked := not TDpiMenuItem(Sender).Checked;
    74997889end;
    75007890
    75017891procedure TMainScreen.PanelBoxMouseMove(Sender: TObject; Shift: TShiftState;
    7502   x, y: integer);
     7892  X, Y: Integer);
    75037893var
    7504   xCentre, yCentre: integer;
     7894  xCentre, yCentre: Integer;
    75057895begin
    75067896  if Tracking and (ssLeft in Shift) then
    75077897  with MainMap do begin
    7508     if (x >= xMini + 2) and (y >= yMini + 2) and (x < xMini + 2 + 2 * G.lx) and
    7509       (y < yMini + 2 + G.ly) then
     7898    if (X >= xMini + 2) and (Y >= yMini + 2) and (X < xMini + 2 + 2 * G.lx) and
     7899      (Y < yMini + 2 + G.ly) then
    75107900    begin
    7511       xCentre := (xwMini + (x - xMini - 2) div 2 + G.lx div 2 +
     7901      xCentre := (xwMini + (X - xMini - 2) div 2 + G.lx div 2 +
    75127902        MapWidth div (xxt * 4)) mod G.lx;
    7513       yCentre := (y - yMini - 2);
     7903      yCentre := (Y - yMini - 2);
    75147904      xw := (xCentre - MapWidth div (xxt * 4) + G.lx) mod G.lx;
    75157905      if ywmax <= 0 then
     
    75237913          yw := ywmax;
    75247914      end;
    7525       DpiBitCanvas(Buffer.Canvas, 0, 0, G.lx * 2, G.ly, MiniMap.Bitmap.Canvas, 0, 0);
     7915      DpiBitBltCanvas(Buffer.Canvas, 0, 0, G.lx * 2, G.ly, MiniMap.Bitmap.Canvas, 0, 0);
    75267916      if ywmax <= 0 then
    7527         Frame(Buffer.Canvas, x - xMini - 2 - MapWidth div (xxt * 2), 0,
    7528           x - xMini - 2 + MapWidth div (xxt * 2) - 1, G.ly - 1,
     7917        Frame(Buffer.Canvas, X - xMini - 2 - MapWidth div (xxt * 2), 0,
     7918          X - xMini - 2 + MapWidth div (xxt * 2) - 1, G.ly - 1,
    75297919          MainTexture.ColorMark, MainTexture.ColorMark)
    75307920      else
    7531         Frame(Buffer.Canvas, x - xMini - 2 - MapWidth div (xxt * 2), yw,
    7532           x - xMini - 2 + MapWidth div (xxt * 2) - 1, yw + MapHeight div yyt -
     7921        Frame(Buffer.Canvas, X - xMini - 2 - MapWidth div (xxt * 2), yw,
     7922          X - xMini - 2 + MapWidth div (xxt * 2) - 1, yw + MapHeight div yyt -
    75337923          2, MainTexture.ColorMark, MainTexture.ColorMark);
    7534       DpiBitCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
     7924      DpiBitBltCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
    75357925        Buffer.Canvas, 0, 0);
    75367926      MainOffscreenPaint;
     
    75427932  end
    75437933  else
    7544     Tracking := false;
     7934    Tracking := False;
    75457935end;
    75467936
    75477937procedure TMainScreen.PanelBoxMouseUp(Sender: TObject; Button: TMouseButton;
    7548   Shift: TShiftState; x, y: integer);
     7938  Shift: TShiftState; X, Y: Integer);
    75497939begin
    75507940  if Tracking then
    75517941  begin
    7552     Tracking := false;
     7942    Tracking := False;
    75537943    xwMini := xw;
    75547944    ywMini := yw;
     
    75597949
    75607950procedure TMainScreen.MapBoxMouseMove(Sender: TObject; Shift: TShiftState;
    7561   x, y: integer);
     7951  X, Y: Integer);
    75627952var
    7563   MouseLoc: integer;
    7564 begin
    7565   xMouse := x;
    7566   yMouse := y;
     7953  MouseLoc: Integer;
     7954begin
     7955  xMouse := X;
     7956  yMouse := Y;
    75677957  if (ClientMode = cEditMap) and (ssLeft in Shift) and not Tracking then
    75687958  begin
    7569     MouseLoc := LocationOfScreenPixel(x, y);
     7959    MouseLoc := LocationOfScreenPixel(X, Y);
    75707960    if MouseLoc <> BrushLoc then
    7571       MapBoxMouseDown(nil, mbLeft, Shift, x, y);
     7961      MapBoxMouseDown(nil, mbLeft, Shift, X, Y);
    75727962  end
    7573   (* else if idle and (UnFocus>=0) then
     7963  (* else if Idle and (UnFocus>=0) then
    75747964    begin
    75757965    qx:=(xMouse*32+yMouse*66+16*66) div(32*66)-1;
     
    75847974  TDpiMenuItem(Sender).Checked := not TDpiMenuItem(Sender).Checked;
    75857975  SetMapOptions;
    7586   MapValid := false;
     7976  MapValid := False;
    75877977  PaintAllMaps;
    75887978end;
     
    75907980procedure TMainScreen.mNamesClick(Sender: TObject);
    75917981var
    7592   p1: integer;
     7982  p1: Integer;
    75937983begin
    75947984  mNames.Checked := not mNames.Checked;
     
    76007990      else
    76017991        Tribe[p1].NumberName := p1;
    7602   MapValid := false;
     7992  MapValid := False;
    76037993  PaintAll;
    76047994end;
    76057995
    7606 function TMainScreen.IsPanelPixel(x, y: integer): boolean;
    7607 begin
    7608   result := (y >= TopBarHeight + MapHeight) or (y >= ClientHeight - PanelHeight)
    7609     and ((x < xMidPanel) or (x >= xRightPanel));
     7996function TMainScreen.IsPanelPixel(X, Y: Integer): Boolean;
     7997begin
     7998  Result := (Y >= TopBarHeight + MapHeight) or (Y >= ClientHeight - PanelHeight)
     7999    and ((X < xMidPanel) or (X >= xRightPanel));
    76108000end;
    76118001
    76128002procedure TMainScreen.FormMouseDown(Sender: TObject; Button: TMouseButton;
    7613   Shift: TShiftState; x, y: integer);
    7614 begin
    7615   if idle then
    7616     if (x < 40) and (y < 40) then
     8003  Shift: TShiftState; X, Y: Integer);
     8004begin
     8005  if Idle then
     8006    if (X < 40) and (Y < 40) then
    76178007    begin
    76188008      if GameMode <> cMovie then
     
    76268016      end;
    76278017    end
    7628     else if IsPanelPixel(x, y) then
    7629       PanelBoxMouseDown(Sender, Button, Shift, x,
    7630         y - (ClientHeight - PanelHeight))
    7631     else if (y >= TopBarHeight) and (x >= MapOffset) and
    7632       (x < MapOffset + MapWidth) then
    7633       MapBoxMouseDown(Sender, Button, Shift, x - MapOffset, y - TopBarHeight)
     8018    else if IsPanelPixel(X, Y) then
     8019      PanelBoxMouseDown(Sender, Button, Shift, X,
     8020        Y - (ClientHeight - PanelHeight))
     8021    else if (Y >= TopBarHeight) and (X >= MapOffset) and
     8022      (X < MapOffset + MapWidth) then
     8023      MapBoxMouseDown(Sender, Button, Shift, X - MapOffset, Y - TopBarHeight)
    76348024end;
    76358025
    76368026procedure TMainScreen.FormMouseMove(Sender: TObject; Shift: TShiftState;
    7637   x, y: integer);
    7638 begin
    7639   if idle then
    7640     if IsPanelPixel(x, y) then
    7641       PanelBoxMouseMove(Sender, Shift, x, y - (ClientHeight - PanelHeight))
    7642     else if (y >= TopBarHeight) and (x >= MapOffset) and
    7643       (x < MapOffset + MapWidth) then
    7644       MapBoxMouseMove(Sender, Shift, x - MapOffset, y - TopBarHeight);
     8027  X, Y: Integer);
     8028begin
     8029  if Idle then
     8030    if IsPanelPixel(X, Y) then
     8031      PanelBoxMouseMove(Sender, Shift, X, Y - (ClientHeight - PanelHeight))
     8032    else if (Y >= TopBarHeight) and (X >= MapOffset) and
     8033      (X < MapOffset + MapWidth) then
     8034      MapBoxMouseMove(Sender, Shift, X - MapOffset, Y - TopBarHeight);
    76458035end;
    76468036
    76478037procedure TMainScreen.FormMouseUp(Sender: TObject; Button: TMouseButton;
    7648   Shift: TShiftState; x, y: integer);
    7649 begin
    7650   if idle then
    7651     PanelBoxMouseUp(Sender, Button, Shift, x, y - (ClientHeight - PanelHeight));
     8038  Shift: TShiftState; X, Y: Integer);
     8039begin
     8040  if Idle then
     8041    PanelBoxMouseUp(Sender, Button, Shift, X, Y - (ClientHeight - PanelHeight));
    76528042end;
    76538043
     
    76588048    with Canvas do
    76598049    begin // pillarbox, make left and right border black
    7660       if me < 0 then
     8050      if Me < 0 then
    76618051        Brush.Color := $000000
    76628052      else
     
    76848074      Brush.Style := bsClear;
    76858075    end;
    7686   DpiBitCanvas(Canvas, MapOffset, TopBarHeight, MapWidth, MapHeight - overlap,
    7687     offscreen.Canvas, 0, 0);
    7688   DpiBitCanvas(Canvas, 0, 0, ClientWidth, TopBarHeight, TopBar.Canvas,
     8076  DpiBitBltCanvas(Canvas, MapOffset, TopBarHeight, MapWidth, MapHeight - overlap,
     8077    Offscreen.Canvas, 0, 0);
     8078  DpiBitBltCanvas(Canvas, 0, 0, ClientWidth, TopBarHeight, TopBar.Canvas,
    76898079    0, 0);
    76908080  if xMidPanel > MapOffset then
    7691     DpiBitCanvas(Canvas, xMidPanel, TopBarHeight + MapHeight - overlap,
    7692       ClientWidth div 2 - xMidPanel, overlap, offscreen.Canvas,
     8081    DpiBitBltCanvas(Canvas, xMidPanel, TopBarHeight + MapHeight - overlap,
     8082      ClientWidth div 2 - xMidPanel, overlap, Offscreen.Canvas,
    76938083      xMidPanel - MapOffset, MapHeight - overlap)
    76948084  else
    7695     DpiBitCanvas(Canvas, MapOffset, TopBarHeight + MapHeight - overlap,
    7696       ClientWidth div 2 - MapOffset, overlap, offscreen.Canvas, 0,
     8085    DpiBitBltCanvas(Canvas, MapOffset, TopBarHeight + MapHeight - overlap,
     8086      ClientWidth div 2 - MapOffset, overlap, Offscreen.Canvas, 0,
    76978087      MapHeight - overlap);
    76988088  if xRightPanel < MapOffset + MapWidth then
    7699     DpiBitCanvas(Canvas, ClientWidth div 2, TopBarHeight + MapHeight - overlap,
    7700       xRightPanel - ClientWidth div 2, overlap, offscreen.Canvas,
     8089    DpiBitBltCanvas(Canvas, ClientWidth div 2, TopBarHeight + MapHeight - overlap,
     8090      xRightPanel - ClientWidth div 2, overlap, Offscreen.Canvas,
    77018091      ClientWidth div 2 - MapOffset, MapHeight - overlap)
    77028092  else
    7703     DpiBitCanvas(Canvas, ClientWidth div 2, TopBarHeight + MapHeight - overlap,
     8093    DpiBitBltCanvas(Canvas, ClientWidth div 2, TopBarHeight + MapHeight - overlap,
    77048094      MapOffset + MapWidth - ClientWidth div 2, overlap,
    7705       offscreen.Canvas, ClientWidth div 2 - MapOffset,
     8095      Offscreen.Canvas, ClientWidth div 2 - MapOffset,
    77068096      MapHeight - overlap);
    7707   DpiBitCanvas(Canvas, 0, TopBarHeight + MapHeight - overlap, xMidPanel,
     8097  DpiBitBltCanvas(Canvas, 0, TopBarHeight + MapHeight - overlap, xMidPanel,
    77088098    overlap, Panel.Canvas, 0, 0);
    7709   DpiBitCanvas(Canvas, xRightPanel, TopBarHeight + MapHeight - overlap,
     8099  DpiBitBltCanvas(Canvas, xRightPanel, TopBarHeight + MapHeight - overlap,
    77108100    Panel.width - xRightPanel, overlap, Panel.Canvas, xRightPanel, 0);
    7711   DpiBitCanvas(Canvas, 0, TopBarHeight + MapHeight, Panel.width,
     8101  DpiBitBltCanvas(Canvas, 0, TopBarHeight + MapHeight, Panel.width,
    77128102    PanelHeight - overlap, Panel.Canvas, 0, overlap);
    77138103  if (pLogo >= 0) and (G.RO[pLogo] = nil) and (AILogo[pLogo] <> nil) then
    7714     DpiBitCanvas(Canvas, xRightPanel + 10 - (16 + 64),
     8104    DpiBitBltCanvas(Canvas, xRightPanel + 10 - (16 + 64),
    77158105      ClientHeight - PanelHeight, 64, 64, AILogo[pLogo].Canvas, 0, 0);
    77168106end;
    77178107
    7718 procedure TMainScreen.RectInvalidate(Left, Top, Rigth, Bottom: integer);
     8108procedure TMainScreen.RectInvalidate(Left, Top, Rigth, Bottom: Integer);
    77198109var
    77208110  r0: HRgn;
    77218111begin
    77228112  r0 := DpiCreateRectRgn(Left, Top, Rigth, Bottom);
    7723   InvalidateRgn(Handle, r0, false);
     8113  InvalidateRgn(Handle, r0, False);
    77248114  DeleteObject(r0);
    77258115end;
    77268116
    7727 procedure TMainScreen.SmartRectInvalidate(Left, Top, Rigth, Bottom: integer);
     8117procedure TMainScreen.SmartRectInvalidate(Left, Top, Rigth, Bottom: Integer);
    77288118var
    7729   i: integer;
     8119  I: Integer;
    77308120  r0, r1: HRgn;
    77318121begin
    77328122  r0 := DpiCreateRectRgn(Left, Top, Rigth, Bottom);
    7733   for i := 0 to ControlCount - 1 do
    7734     if not(Controls[i] is TArea) and Controls[i].Visible then
     8123  for I := 0 to ControlCount - 1 do
     8124    if not(Controls[I] is TArea) and Controls[I].Visible then
    77358125    begin
    7736       with Controls[i].BoundsRect do
     8126      with Controls[I].BoundsRect do
    77378127        r1 := DpiCreateRectRgn(Left, Top, Right, Bottom);
    77388128      CombineRgn(r0, r0, r1, RGN_DIFF);
    77398129      DeleteObject(r1);
    77408130    end;
    7741   InvalidateRgn(Handle, r0, false);
     8131  InvalidateRgn(Handle, r0, False);
    77428132  DeleteObject(r0);
    77438133end;
     
    78048194procedure TMainScreen.FormClose(Sender: TObject; var Action: TCloseAction);
    78058195begin
    7806   Timer1.Enabled := false;
     8196  Timer1.Enabled := False;
    78078197end;
    78088198
    78098199procedure TMainScreen.Radio(Sender: TObject);
    78108200begin
    7811   TDpiMenuItem(Sender).Checked := true;
     8201  TDpiMenuItem(Sender).Checked := True;
    78128202end;
    78138203
    78148204procedure TMainScreen.mManipClick(Sender: TObject);
    78158205var
    7816   Flag: integer;
     8206  Flag: Integer;
    78178207begin
    78188208  with TDpiMenuItem(Sender) do
     
    78268216      Play('CHEAT');
    78278217    end;
    7828     if not supervising then
     8218    if not Supervising then
    78298219    begin
    78308220      if Flag = tfUncover then
    78318221      begin
    7832         MapValid := false;
     8222        MapValid := False;
    78338223        PaintAllMaps;
    78348224      end
     
    78548244  else
    78558245  begin
    7856     MapValid := false;
     8246    MapValid := False;
    78578247    PaintAllMaps;
    78588248  end; // update main map
     
    78738263  end;
    78748264  SetMapOptions;
    7875   MapValid := false;
     8265  MapValid := False;
    78768266  PaintAllMaps;
    78778267end;
     
    78918281  end;
    78928282  SetMapOptions;
    7893   MapValid := false;
     8283  MapValid := False;
    78948284  PaintAllMaps;
    78958285end;
    78968286
    7897 procedure TMainScreen.FormKeyUp(Sender: TObject; var Key: word;
     8287procedure TMainScreen.FormKeyUp(Sender: TObject; var Key: Word;
    78988288  Shift: TShiftState);
    78998289begin
    7900   if idle and (Key = VK_APPS) then
     8290  if Idle and (Key = VK_APPS) then
    79018291  begin
    79028292    InitPopup(GamePopup);
     
    79068296      GamePopup.Popup(Left + 4, Top + DpiGetSystemMetrics(SM_CYCAPTION) + 4 +
    79078297        TopBarHeight - 1);
    7908     exit;
     8298    Exit;
    79098299  end; // windows menu button calls game menu
    79108300end;
     
    79128302procedure TMainScreen.CreateUnitClick(Sender: TObject);
    79138303var
    7914   p1, mix: integer;
     8304  p1, mix: Integer;
    79158305begin
    79168306  p1 := TComponent(Sender).Tag shr 16;
    79178307  mix := TComponent(Sender).Tag and $FFFF;
    7918   if Server(sCreateUnit + p1 shl 4, me, mix, EditLoc) >= rExecuted then
     8308  if Server(sCreateUnit + p1 shl 4, Me, mix, EditLoc) >= rExecuted then
    79198309    PaintLoc(EditLoc);
    79208310end;
     
    79348324  SoundMode := smOnAlt;
    79358325end;
    7936 
    7937 { procedure TMainScreen.AdviceBtnClick;
    7938   var
    7939   OldAdviceLoc: integer;
    7940   begin
    7941   DestinationMarkON:=false;
    7942   PaintDestination;
    7943   AdvisorDlg.GiveStrategyAdvice;
    7944   OldAdviceLoc:=MainMap.AdviceLoc;
    7945   MainMap.AdviceLoc:=-1;
    7946   PaintLoc(OldAdviceLoc);
    7947   end; }
    7948 
    7949 { procedure TMainScreen.SetAdviceLoc(Loc: integer; AvoidRect: TRect);
    7950   var
    7951   OldAdviceLoc,x,y: integer;
    7952   begin
    7953   if Loc<>MainMap.AdviceLoc then
    7954   begin
    7955   if Loc>=0 then
    7956   begin // center
    7957   y:=Loc div G.lx;
    7958   x:=(Loc+G.lx - AvoidRect.Right div (2*66)) mod G.lx;
    7959   Centre(y*G.lx+x);
    7960   PaintAllMaps;
    7961   end;
    7962   OldAdviceLoc:=MainMap.AdviceLoc;
    7963   MainMap.AdviceLoc:=Loc;
    7964   PaintLoc(OldAdviceLoc);
    7965   PaintLoc(MainMap.AdviceLoc);
    7966   end;
    7967   end; }
    79688326
    79698327procedure TMainScreen.UnitInfoBtnClick(Sender: TObject);
     
    80048362
    80058363procedure TMainScreen.SetTileSize(TileSize: TTileSize; Loc: Integer; MapPos: TPoint);
    8006 var
    8007   i: integer;
    80088364begin
    80098365  MainMap.TileSize := TileSize;
     
    80128368  SetMapPos(Loc, MapPos);
    80138369  PaintAllMaps;
    8014   for i := 0 to DpiScreen.FormCount - 1 do
    8015     if DpiScreen.Forms[i].Visible and (DpiScreen.Forms[i] is TBufferedDrawDlg) then
    8016       TBufferedDrawDlg(DpiScreen.Forms[i]).SmartUpdateContent(false);
     8370  ApplyToVisibleForms(faSmartUpdateContent);
    80178371end;
    80188372
    80198373procedure TMainScreen.SaveMenuItemsState;
    80208374var
    8021   i, j: integer;
     8375  I, J: Integer;
    80228376begin
    80238377  if soTellAI in OptionChecked then OptionChecked := [soTellAI]
    80248378    else OptionChecked := [];
    8025   for i := 0 to ComponentCount - 1 do
    8026     if Components[i] is TDpiMenuItem then
    8027       for j := 0 to Length(SaveOption) - 1 do
    8028         if TDpiMenuItem(Components[i]).Checked and
    8029           (TDpiMenuItem(Components[i]).Tag = SaveOption[j]) then
    8030           OptionChecked := OptionChecked + [TSaveOption(j)];
     8379  for I := 0 to ComponentCount - 1 do
     8380    if Components[I] is TDpiMenuItem then
     8381      for J := 0 to Length(SaveOption) - 1 do
     8382        if TDpiMenuItem(Components[I]).Checked and
     8383          (TDpiMenuItem(Components[I]).Tag = SaveOption[J]) then
     8384          OptionChecked := OptionChecked + [TSaveOption(J)];
    80318385end;
    80328386
     
    80408394  with Reg do
    80418395  try
    8042     OpenKey(AppRegistryKey, true);
     8396    OpenKey(AppRegistryKey, True);
    80438397    WriteInteger('TileSize', Integer(MainMap.TileSize));
    80448398    WriteInteger('OptionChecked', Integer(OptionChecked));
    80458399    WriteInteger('MapOptionChecked', Integer(MapOptionChecked));
    8046     WriteInteger('CityReport', integer(CityRepMask));
     8400    WriteInteger('CityReport', Integer(CityRepMask));
    80478401  finally
    80488402    Free;
     
    80568410end;
    80578411
     8412procedure TMainScreen.ArrangeDialogs;
     8413begin
     8414  ArrangeDialog(FListDlg);
     8415  ArrangeDialog(FHelpDlg);
     8416  ArrangeDialog(FUnitStatDlg);
     8417  ArrangeDialog(FDiaDlg);
     8418  ArrangeDialog(FNatStatDlg);
     8419end;
     8420
     8421procedure TMainScreen.ArrangeDialog(Form: TBufferedDrawDlg);
     8422begin
     8423  if not Assigned(Form) then Exit;
     8424
     8425  if Form is TListDlg then begin;
     8426    ListDlg.UserLeft := 8;
     8427    ListDlg.UserTop := TopBarHeight + 8;
     8428  end;
     8429  if Form is THelpDlg then begin
     8430   HelpDlg.UserLeft := DpiScreen.Width - HelpDlg.Width - 8;
     8431    HelpDlg.UserTop := TopBarHeight + 8;
     8432  end;
     8433  if Form is TUnitStatDlg then begin
     8434    UnitStatDlg.UserLeft := 397;
     8435    UnitStatDlg.UserTop := TopBarHeight + 64;
     8436  end;
     8437  if Form is TDiaDlg then begin
     8438    DiaDlg.UserLeft := (DpiScreen.Width - DiaDlg.Width) div 2;
     8439    DiaDlg.UserTop := (DpiScreen.Height - DiaDlg.Height) div 2;
     8440  end;
     8441  if Form is TNatStatDlg then begin
     8442    NatStatDlg.UserLeft := DpiScreen.Width - NatStatDlg.Width - 8;
     8443    NatStatDlg.UserTop := DpiScreen.Height - PanelHeight - NatStatDlg.Height - 8;
     8444    if NatStatDlg.UserTop < 8 then
     8445      NatStatDlg.UserTop := 8;
     8446  end;
     8447end;
     8448
    80588449procedure TMainScreen.ScrollBarUpdate(Sender: TObject);
    80598450begin
  • TabularUnified branches/highdpi/LocalPlayer/Tribes.pas

    r349 r465  
    66uses
    77  Protocol, ScreenTools, LazFileUtils, Classes, Graphics, SysUtils, Global,
    8   UGraphicSet;
     8  GraphicSet;
    99
    1010type
     
    2020    yShield: Integer;
    2121  end;
     22
     23  { TModelPictureInfo }
    2224
    2325  TModelPictureInfo = record
     
    2729    Hash: Integer;
    2830    GrName: ShortString;
     31    function GetCommandDataSize: Byte;
    2932  end;
    3033
     
    4649    constructor Create(FileName: string);
    4750    destructor Destroy; override;
    48     function GetCityName(i: Integer): string;
    49 {$IFNDEF SCR} procedure SetCityName(i: Integer; NewName: string); {$ENDIF}
     51    function GetCityName(I: Integer): string;
     52{$IFNDEF SCR} procedure SetCityName(I: Integer; NewName: string); {$ENDIF}
    5053{$IFNDEF SCR} function TString(Template: string): string;
    5154    function TPhrase(Item: string): string; {$ENDIF}
     
    6972function CityName(Founder: Integer): string;
    7073function ModelCode(const ModelInfo: TModelInfo): Integer;
    71 procedure FindStdModelPicture(Code: Integer; var pix: Integer; var Name: string);
     74procedure FindStdModelPicture(Code: Integer; out pix: Integer; out Name: string);
    7275function GetTribeInfo(FileName: string; var Name: string; var Color: TColor): Boolean;
    73 procedure FindPosition(HGr: TGraphicSet; x, y, xmax, ymax: Integer; Mark: TColor;
     76procedure FindPosition(HGr: TGraphicSet; X, Y, xmax, ymax: Integer; Mark: TColor;
    7477  var xp, yp: Integer);
    7578
     
    212215function Get: string;
    213216var
    214   p: Integer;
     217  P: Integer;
    215218begin
    216219  while (Input <> '') and ((Input[1] = ' ') or (Input[1] = #9)) do
    217220    Delete(Input, 1, 1);
    218   p := Pos(',', Input);
    219   if p = 0 then
    220     p := Length(Input) + 1;
    221   Result := Copy(Input, 1, p - 1);
    222   Delete(Input, 1, p);
     221  P := Pos(',', Input);
     222  if P = 0 then
     223    P := Length(Input) + 1;
     224  Result := Copy(Input, 1, P - 1);
     225  Delete(Input, 1, P);
    223226end;
    224227
    225228function GetNum: Integer;
    226229var
    227   i: Integer;
    228 begin
    229   Val(Get, Result, i);
    230   if i <> 0 then
     230  I: Integer;
     231begin
     232  Val(Get, Result, I);
     233  if I <> 0 then
    231234    Result := 0;
    232235end;
    233236
    234 procedure FindStdModelPicture(Code: Integer; var pix: Integer; var Name: string);
    235 var
    236   i: Integer;
    237 begin
    238   for i := 0 to StdUnitScript.Count - 1 do
     237procedure FindStdModelPicture(Code: Integer; out pix: Integer; out Name: string);
     238var
     239  I: Integer;
     240begin
     241  for I := 0 to StdUnitScript.Count - 1 do
    239242  begin // look through StdUnits
    240     Input := StdUnitScript[i];
     243    Input := StdUnitScript[I];
    241244    pix := GetNum;
    242245    if Code = GetNum then
     
    281284  CloseFile(TribeScript);
    282285  Result := Found = 3;
     286end;
     287
     288{ TModelPictureInfo }
     289
     290function TModelPictureInfo.GetCommandDataSize: Byte;
     291begin
     292  Result := SizeOf(trix) + SizeOf(mix) + SizeOf(pix) + SizeOf(Hash) + 1 +
     293    Length(GrName);
    283294end;
    284295
     
    329340end;
    330341
    331 procedure FindPosition(HGr: TGraphicSet; x, y, xmax, ymax: Integer; Mark: TColor;
     342procedure FindPosition(HGr: TGraphicSet; X, Y, xmax, ymax: Integer; Mark: TColor;
    332343  var xp, yp: Integer);
    333344begin
    334345  xp := 0;
    335   while (xp < xmax) and (HGr.Data.Canvas.Pixels[x + 1 + xp, y] <> Mark) do
     346  while (xp < xmax) and (HGr.Data.Canvas.Pixels[X + 1 + xp, Y] <> Mark) do
    336347    Inc(xp);
    337348  yp := 0;
    338   while (yp < ymax) and (HGr.Data.Canvas.Pixels[x, y + 1 + yp] <> Mark) do
     349  while (yp < ymax) and (HGr.Data.Canvas.Pixels[X, Y + 1 + yp] <> Mark) do
    339350    Inc(yp);
    340351end;
    341352
    342 function TTribe.GetCityName(i: Integer): string;
     353function TTribe.GetCityName(I: Integer): string;
    343354begin
    344355  Result := '';
    345   if nCityLines > i then
    346   begin
    347     Result := Script[CityLine0 + i];
     356  if nCityLines > I then
     357  begin
     358    Result := Script[CityLine0 + I];
    348359    while (Result <> '') and ((Result[1] = ' ') or (Result[1] = #9)) do
    349360      Delete(Result, 1, 1);
     
    351362{$IFNDEF SCR}
    352363  else
    353     Result := Format(TPhrase('GENCITY'), [i + 1]);
     364    Result := Format(TPhrase('GENCITY'), [I + 1]);
    354365{$ENDIF}
    355366end;
    356367
    357368{$IFNDEF SCR}
    358 procedure TTribe.SetCityName(i: Integer; NewName: string);
    359 begin
    360   while nCityLines <= i do
     369procedure TTribe.SetCityName(I: Integer; NewName: string);
     370begin
     371  while nCityLines <= I do
    361372  begin
    362373    Script.Insert(CityLine0 + nCityLines, Format(TPhrase('GENCITY'),
     
    364375    Inc(nCityLines);
    365376  end;
    366   Script[CityLine0 + i] := NewName;
     377  Script[CityLine0 + I] := NewName;
    367378end;
    368379
    369380function TTribe.TString(Template: string): string;
    370381var
    371   p: Integer;
     382  P: Integer;
    372383  Variant: Char;
    373384  CaseUp: Boolean;
    374385begin
    375386  repeat
    376     p := pos('#', Template);
    377     if (p = 0) or (p = Length(Template)) then
     387    P := Pos('#', Template);
     388    if (P = 0) or (P = Length(Template)) then
    378389      Break;
    379     Variant := Template[p + 1];
     390    Variant := Template[P + 1];
    380391    CaseUp := Variant in ['A' .. 'Z'];
    381392    if CaseUp then
    382393      Inc(Variant, 32);
    383     Delete(Template, p, 2);
     394    Delete(Template, P, 2);
    384395    if Variant in ['a' .. 'z'] then
    385396    begin
    386397      if NumberName < 0 then
    387         Insert(Name[Variant], Template, p)
     398        Insert(Name[Variant], Template, P)
    388399      else
    389         Insert(Format('P%d', [NumberName]), Template, p);
    390       if CaseUp and (Length(Template) >= p) and
    391         (Template[p] in ['a' .. 'z', #$E0 .. #$FF]) then
    392         Dec(Template[p], 32);
     400        Insert(Format('P%d', [NumberName]), Template, P);
     401      if CaseUp and (Length(Template) >= P) and
     402        (Template[P] in ['a' .. 'z', #$E0 .. #$FF]) then
     403        Dec(Template[P], 32);
    393404    end
    394405  until False;
     
    407418  TLine = array [0 .. 649, 0 .. 2] of Byte;
    408419var
    409   i, x, Gray: Integer;
     420  I, X, Gray: Integer;
    410421  Item: string;
    411422begin
     
    415426  with Script do
    416427  begin
    417     i := 0;
    418     while (i < Count) and (Copy(Strings[i], 1, 6) <>
     428    I := 0;
     429    while (I < Count) and (Copy(Strings[I], 1, 6) <>
    419430        '#AGE' + char(48 + Age) + ' ') do
    420       Inc(i);
    421     if i < Count then
    422     begin
    423       Input := Strings[i];
     431      Inc(I);
     432    if I < Count then
     433    begin
     434      Input := Strings[I];
    424435      system.Delete(Input, 1, 6);
    425436      Item := Get;
     
    430441        if CompareText(Item, 'stdcities') = 0 then
    431442          case cpix of
    432             3:
    433               cpix := 0;
    434             6:
    435             begin
     443            3: cpix := 0;
     444            6: begin
    436445              cpix := 0;
    437446              Item := 'Nation2';
    438             end
     447            end;
    439448          end;
    440449        cHGr := LoadGraphicSet(Item + '.png');
    441         for x := 0 to 3 do
    442           with CityPicture[x] do
    443           begin
    444             FindPosition(cHGr, x * 65, cpix * 49, 63, 47, $00FFFF,
     450        for X := 0 to 3 do
     451          with CityPicture[X] do begin
     452            FindPosition(cHGr, X * 65, cpix * 49, 63, 47, $00FFFF,
    445453              xShield, yShield);
    446454            // FindPosition(cHGr,x*65,cpix*49,$FFFFFF,xf,yf);
     
    478486procedure TTribe.SetModelPicture(const Info: TModelPictureInfo; IsNew: Boolean);
    479487var
    480   i: Integer;
     488  I: Integer;
    481489  ok: Boolean;
    482490begin
     
    485493    if not IsNew then
    486494    begin
    487       i := nPictureList - 1;
    488       while (i >= 0) and (PictureList[i].Hash <> Info.Hash) do
    489         Dec(i);
    490       assert(i >= 0);
    491       assert(PictureList[i].HGr = LoadGraphicSet(GrName));
    492       assert(PictureList[i].pix = pix);
    493       ModelPicture[mix].HGr := PictureList[i].HGr;
    494       ModelPicture[mix].pix := PictureList[i].pix;
    495       ModelName[mix] := PictureList[i].ModelName;
     495      I := nPictureList - 1;
     496      while (I >= 0) and (PictureList[I].Hash <> Info.Hash) do
     497        Dec(I);
     498      Assert(I >= 0);
     499      Assert(PictureList[I].HGr = LoadGraphicSet(GrName));
     500      Assert(PictureList[I].pix = pix);
     501      ModelPicture[mix].HGr := PictureList[I].HGr;
     502      ModelPicture[mix].pix := PictureList[I].pix;
     503      ModelName[mix] := PictureList[I].ModelName;
    496504    end
    497505    else
     
    507515      // read model name from tribe script
    508516      ok := False;
    509       for i := 0 to Script.Count - 1 do
    510       begin
    511         Input := Script[i];
     517      for I := 0 to Script.Count - 1 do
     518      begin
     519        Input := Script[I];
    512520        if Input = '#UNITS ' + ExtractFileNameOnly(GrName) then
    513521          ok := True
     
    523531      if ModelName[mix] = '' then
    524532      begin // read model name from StdUnits.txt
    525         for i := 0 to StdUnitScript.Count - 1 do
     533        for I := 0 to StdUnitScript.Count - 1 do
    526534        begin
    527           Input := StdUnitScript[i];
     535          Input := StdUnitScript[I];
    528536          if GetNum = pix then
    529537          begin
     
    559567  Code, Turn: Integer; ForceNew: Boolean): Boolean;
    560568var
    561   i: Integer;
     569  I: Integer;
    562570  Cnt: Integer;
    563571  HGr: TGraphicSet;
     
    598606  if not ForceNew and (Picture.Hash > 0) then
    599607  begin
    600     for i := 0 to nPictureList - 1 do
    601       if PictureList[i].Hash = Picture.Hash then
    602       begin
    603         Picture.GrName := PictureList[i].HGr.Name;
    604         Picture.pix := PictureList[i].pix;
     608    for I := 0 to nPictureList - 1 do
     609      if PictureList[I].Hash = Picture.Hash then
     610      begin
     611        Picture.GrName := PictureList[I].HGr.Name;
     612        Picture.pix := PictureList[I].pix;
    605613        Result := False;
    606614        Exit;
     
    614622  TestPic.GrName := 'StdUnits.png';
    615623  HGr := HGrStdUnits;
    616   for i := 0 to StdUnitScript.Count - 1 do
     624  for I := 0 to StdUnitScript.Count - 1 do
    617625  begin // look through StdUnits
    618     Input := StdUnitScript[i];
     626    Input := StdUnitScript[I];
    619627    Check;
    620628  end;
    621629
    622630  ok := False;
    623   for i := 0 to Script.Count - 1 do
     631  for I := 0 to Script.Count - 1 do
    624632  begin // look through units defined in tribe script
    625     Input := Script[i];
     633    Input := Script[I];
    626634    if Copy(Input, 1, 6) = '#UNITS' then
    627635    begin
  • TabularUnified branches/highdpi/LocalPlayer/UnitStat.pas

    r405 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin,
    8   LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms,
    9   ButtonB, ButtonC, IsoEngine;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, Controls, Forms, ButtonB, ButtonC, IsoEngine;
    109
    1110type
     11  TUnitStatDialogKind = (dkOwnModel, dkOwnUnit, dkEnemyModel, dkEnemyUnit,
     12    dkEnemyCityDefense, dkEnemyCity);
     13
    1214  TUnitStatDlg = class(TBufferedDrawDlg)
    1315    SwitchBtn: TButtonB;
     
    2628  private
    2729    NoMap: TIsoMap;
     30  protected
     31    mixShow, // for dkOwnModel
     32    uixShow, euixShow, ecixShow, UnitLoc, AgePrepared: Integer;
     33    // for dkEnemyUnit, euixShow=-1 ->
     34    mox: ^TModelInfo; // for dkEnemyModel
     35    Kind: TUnitStatDialogKind;
     36    Back: TDpiBitmap;
     37    Template: TDpiBitmap;
     38    procedure OffscreenPaint; override;
    2839  public
    2940    procedure CheckAge;
    30     procedure ShowNewContent_OwnModel(NewMode, mix: integer);
    31     procedure ShowNewContent_OwnUnit(NewMode, uix: integer);
    32     procedure ShowNewContent_EnemyUnit(NewMode, euix: integer);
    33     procedure ShowNewContent_EnemyLoc(NewMode, Loc: integer);
    34     procedure ShowNewContent_EnemyModel(NewMode, emix: integer);
    35     procedure ShowNewContent_EnemyCity(NewMode, Loc: integer);
    36 
    37   protected
    38     mixShow, // for dkOwnModel
    39     uixShow, euixShow, ecixShow, UnitLoc, AgePrepared: integer;
    40     // for dkEnemyUnit, euixShow=-1 ->
    41     mox: ^TModelInfo; // for dkEnemyModel
    42     Kind: (dkOwnModel, dkOwnUnit, dkEnemyModel, dkEnemyUnit, dkEnemyCityDefense,
    43       dkEnemyCity);
    44     Back, Template: TDpiBitmap;
    45     procedure OffscreenPaint; override;
    46   end;
    47 
    48 var
    49   UnitStatDlg: TUnitStatDlg;
     41    procedure ShowNewContent_OwnModel(NewMode: TWindowMode; mix: Integer);
     42    procedure ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: Integer);
     43    procedure ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: Integer);
     44    procedure ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: Integer);
     45    procedure ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: Integer);
     46    procedure ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: Integer);
     47  end;
     48
    5049
    5150implementation
    5251
    5352uses
    54   Tribes, Help, Directories, UTexture;
     53  Term, Tribes, Help, Directories, Texture;
    5554
    5655{$R *.lfm}
     
    8281  Back.PixelFormat := pf24bit;
    8382  Back.SetSize(5 * wCommon, hMax);
    84   Back.Canvas.FillRect(0, 0, Back.Width,Back.Height);
     83  Back.Canvas.FillRect(0, 0, Back.Width, Back.Height);
    8584  Template := TDpiBitmap.Create;
    8685  Template.PixelFormat := pf24bit;
     
    10099  if MainTexture.Age <> AgePrepared then begin
    101100    AgePrepared := MainTexture.Age;
    102     DpiBitCanvas(Back.Canvas, 0, 0, wCommon, hOwnModel,
     101    DpiBitBltCanvas(Back.Canvas, 0, 0, wCommon, hOwnModel,
    103102      MainTexture.Image.Canvas, (MainTexture.Width - wCommon) div 2,
    104103      (MainTexture.Height - hOwnModel) div 2);
    105     DpiBitCanvas(Back.Canvas, wCommon, 0, wCommon, hEnemyModel,
     104    DpiBitBltCanvas(Back.Canvas, wCommon, 0, wCommon, hEnemyModel,
    106105      MainTexture.Image.Canvas, (MainTexture.Width - wCommon) div 2,
    107106      (MainTexture.Height - hEnemyModel) div 2);
    108     DpiBitCanvas(Back.Canvas, 2 * wCommon, 0, wCommon, hEnemyUnit,
     107    DpiBitBltCanvas(Back.Canvas, 2 * wCommon, 0, wCommon, hEnemyUnit,
    109108      MainTexture.Image.Canvas, (MainTexture.Width - wCommon) div 2,
    110109      (MainTexture.Height - hEnemyUnit) div 2);
    111     DpiBitCanvas(Back.Canvas, 3 * wCommon, 0, wCommon, hEnemyCityDefense,
     110    DpiBitBltCanvas(Back.Canvas, 3 * wCommon, 0, wCommon, hEnemyCityDefense,
    112111      MainTexture.Image.Canvas, (MainTexture.Width - wCommon) div 2,
    113112      (MainTexture.Height - hEnemyCityDefense) div 2);
    114     DpiBitCanvas(Back.Canvas, 4 * wCommon, 0, wCommon, hEnemyCity,
     113    DpiBitBltCanvas(Back.Canvas, 4 * wCommon, 0, wCommon, hEnemyCity,
    115114      MainTexture.Image.Canvas, (MainTexture.Width - wCommon) div 2,
    116115      (MainTexture.Height - hEnemyCity) div 2);
     
    121120procedure TUnitStatDlg.FormShow(Sender: TObject);
    122121var
    123   owner, mix: integer;
    124   IsSpecialUnit: boolean;
     122  Owner, mix: Integer;
     123  IsSpecialUnit: Boolean;
    125124begin
    126125  if Kind in [dkEnemyUnit, dkEnemyCityDefense, dkEnemyCity] then
     
    132131        euixShow := MyRO.nEnemyUn - 1;
    133132        while (euixShow >= 0) and (MyRO.EnemyUn[euixShow].Loc <> UnitLoc) do
    134           dec(euixShow);
    135         assert(euixShow >= 0);
     133          Dec(euixShow);
     134        Assert(euixShow >= 0);
    136135      end;
    137136      with MyRO.EnemyUn[euixShow] do
    138137      begin
    139138        mox := @MyRO.EnemyModel[emix];
    140         if not Assigned(Tribe[owner].ModelPicture[mix].HGr) then
     139        if not Assigned(Tribe[Owner].ModelPicture[mix].HGr) then
    141140          InitEnemyModel(emix);
    142       end
     141      end;
    143142    end
    144143    else
     
    148147      ecixShow := MyRO.nEnemyCity - 1;
    149148      while (ecixShow >= 0) and (MyRO.EnemyCity[ecixShow].Loc <> UnitLoc) do
    150         dec(ecixShow);
    151       assert(ecixShow >= 0);
     149        Dec(ecixShow);
     150      Assert(ecixShow >= 0);
    152151    end;
    153152  end;
    154153  case Kind of
    155     dkOwnModel:
    156       ClientHeight := hOwnModel;
    157     dkOwnUnit:
    158       ClientHeight := hEnemyUnit;
    159     dkEnemyModel:
    160       ClientHeight := hEnemyModel;
    161     dkEnemyUnit:
    162       ClientHeight := hEnemyUnit;
    163     dkEnemyCityDefense:
    164       ClientHeight := hEnemyCityDefense;
    165     dkEnemyCity:
    166       ClientHeight := hEnemyCity;
     154    dkOwnModel: ClientHeight := hOwnModel;
     155    dkOwnUnit: ClientHeight := hEnemyUnit;
     156    dkEnemyModel: ClientHeight := hEnemyModel;
     157    dkEnemyUnit: ClientHeight := hEnemyUnit;
     158    dkEnemyCityDefense: ClientHeight := hEnemyCityDefense;
     159    dkEnemyCity: ClientHeight := hEnemyCity;
    167160  end;
    168161
     
    171164    Left := UserLeft;
    172165    Top := UserTop;
    173   end
    174   else
    175   begin
     166  end else begin
    176167    Left := (DpiScreen.Width - Width) div 2;
    177168    Top := (DpiScreen.Height - Height) div 2;
    178169  end;
    179170
    180   SwitchBtn.Visible := not supervising and (Kind = dkOwnModel);
    181   ConscriptsBtn.Visible := not supervising and (Kind = dkOwnModel) and
     171  SwitchBtn.Visible := not Supervising and (Kind = dkOwnModel);
     172  ConscriptsBtn.Visible := not Supervising and (Kind = dkOwnModel) and
    182173    (MyRO.Tech[adConscription] >= tsApplicable) and
    183174    (MyModel[mixShow].Domain = dGround) and (MyModel[mixShow].Kind < mkScout);
    184   IsSpecialUnit := false;
     175  IsSpecialUnit := False;
    185176  if Kind in [dkEnemyCity, dkEnemyCityDefense] then
    186177    Caption := CityName(MyRO.EnemyCity[ecixShow].ID)
     
    188179  begin
    189180    case Kind of
    190       dkOwnModel:
    191         begin
    192           owner := me;
    193           mix := mixShow;
    194           IsSpecialUnit := MyModel[mix].Kind >= $10;
    195         end;
    196       dkOwnUnit:
    197         begin
    198           owner := me;
    199           mix := MyUn[uixShow].mix;
    200           IsSpecialUnit := MyModel[mix].Kind >= $10;
    201         end
    202     else
    203       begin
    204         owner := mox.owner;
     181      dkOwnModel: begin
     182        Owner := Me;
     183        mix := mixShow;
     184        IsSpecialUnit := MyModel[mix].Kind >= $10;
     185      end;
     186      dkOwnUnit: begin
     187        Owner := Me;
     188        mix := MyUn[uixShow].mix;
     189        IsSpecialUnit := MyModel[mix].Kind >= $10;
     190      end;
     191      else begin
     192        Owner := mox.Owner;
    205193        mix := mox.mix;
    206194        IsSpecialUnit := mox.Kind >= $10;
     
    218206end;
    219207
    220 procedure TUnitStatDlg.ShowNewContent_OwnModel(NewMode, mix: integer);
     208procedure TUnitStatDlg.ShowNewContent_OwnModel(NewMode: TWindowMode; mix: Integer);
    221209begin
    222210  Kind := dkOwnModel;
     
    225213end;
    226214
    227 procedure TUnitStatDlg.ShowNewContent_OwnUnit(NewMode, uix: integer);
     215procedure TUnitStatDlg.ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: Integer);
    228216begin
    229217  Kind := dkOwnUnit;
     
    232220end;
    233221
    234 procedure TUnitStatDlg.ShowNewContent_EnemyUnit(NewMode, euix: integer);
     222procedure TUnitStatDlg.ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: Integer);
    235223begin
    236224  Kind := dkEnemyUnit;
     
    240228end;
    241229
    242 procedure TUnitStatDlg.ShowNewContent_EnemyLoc(NewMode, Loc: integer);
     230procedure TUnitStatDlg.ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: Integer);
    243231begin
    244232  Kind := dkEnemyUnit;
     
    248236end;
    249237
    250 procedure TUnitStatDlg.ShowNewContent_EnemyModel(NewMode, emix: integer);
     238procedure TUnitStatDlg.ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: Integer);
    251239begin
    252240  Kind := dkEnemyModel;
     
    255243end;
    256244
    257 procedure TUnitStatDlg.ShowNewContent_EnemyCity(NewMode, Loc: integer);
     245procedure TUnitStatDlg.ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: Integer);
    258246begin
    259247  if MyMap[Loc] and fUnit <> 0 then
     
    271259  begin
    272260    UserLeft := Left;
    273     UserTop := Top
    274   end;
    275   if OffscreenUser = self then
     261    UserTop := Top;
     262  end;
     263  if OffscreenUser = Self then
    276264    OffscreenUser := nil;
    277265end;
     
    286274  PPicture: ^TModelPicture;
    287275
    288   function IsToCount(emix: integer): boolean;
     276  function IsToCount(emix: Integer): Boolean;
    289277  var
    290278    PTestPicture: ^TModelPicture;
     
    294282      PTestPicture := @Tribe[MyRO.EnemyModel[emix].owner].ModelPicture
    295283        [MyRO.EnemyModel[emix].mix];
    296       result := (PPicture.HGr = PTestPicture.HGr) and
     284      Result := (PPicture.HGr = PTestPicture.HGr) and
    297285        (PPicture.pix = PTestPicture.pix) and
    298286        (ModelHash(mox^) = ModelHash(MyRO.EnemyModel[emix]));
    299287    end
    300288    else
    301       result := (MyRO.EnemyModel[emix].owner = mox.owner) and
     289      Result := (MyRO.EnemyModel[emix].owner = mox.owner) and
    302290        (MyRO.EnemyModel[emix].mix = mox.mix);
    303291  end;
    304292
    305   procedure FeatureBar(dst: TDpiBitmap; x, y: integer; const mi: TModelInfo;
     293  procedure FeatureBar(dst: TDpiBitmap; X, Y: Integer; const mi: TModelInfo;
    306294    T: TTexture);
    307295  var
    308     i, w, dx, num: integer;
    309     s: string;
    310   begin
    311     DarkGradient(dst.Canvas, x - 6, y + 1, 180, 1);
     296    I, W, dx, num: Integer;
     297    S: string;
     298  begin
     299    DarkGradient(dst.Canvas, X - 6, Y + 1, 180, 1);
    312300    with dst.Canvas do
    313301      if mi.Kind >= $10 then
    314302      begin
    315         s := Phrases.Lookup('UNITSPECIAL');
     303        S := Phrases.Lookup('UNITSPECIAL');
    316304        Font.Color := $000000;
    317         Textout(x - 1, y + 1, s);
     305        Textout(X - 1, Y + 1, S);
    318306        Font.Color := $B0B0B0;
    319         Textout(x - 2, y, s);
     307        Textout(X - 2, Y, S);
    320308      end
    321309      else
     
    323311        Font.Color := $000000;
    324312        dx := 2;
    325         for i := 3 to nFeature - 1 do
     313        for I := 3 to nFeature - 1 do
    326314        begin
    327315          num := 0;
    328           case i of
     316          case I of
    329317            mcSeaTrans:
    330318              if mi.Domain = dSea then
     
    342330                num := mi.TTrans;
    343331            mcFirstNonCap .. nFeature - 1:
    344               if mi.Cap and (1 shl (i - mcFirstNonCap)) <> 0 then
    345                 num := 1
     332              if mi.Cap and (1 shl (I - mcFirstNonCap)) <> 0 then
     333                num := 1;
    346334          end;
    347335          if (num > 0) and
    348             ((i <> mcSE) or (mi.Cap and (1 shl (mcNP - mcFirstNonCap)) = 0))
     336            ((I <> mcSE) or (mi.Cap and (1 shl (mcNP - mcFirstNonCap)) = 0))
    349337          then
    350338          begin
    351339            if num > 1 then
    352340            begin
    353               s := IntToStr(num);
    354               w := TextWidth(s);
     341              S := IntToStr(num);
     342              W := TextWidth(S);
    355343              Brush.Color := $FFFFFF;
    356               FillRect(Rect(x - 3 + dx, y + 2, x + w - 1 + dx, y + 16));
     344              FillRect(Rect(X - 3 + dx, Y + 2, X + W - 1 + dx, Y + 16));
    357345              Brush.Style := bsClear;
    358               Textout(x - 3 + dx + 1, y, s);
    359               inc(dx, w + 1)
     346              Textout(X - 3 + dx + 1, Y, S);
     347              Inc(dx, W + 1);
    360348            end;
    361349            Brush.Color := $C0C0C0;
    362             FrameRect(Rect(x - 3 + dx, y + 2, x + 11 + dx, y + 16));
     350            FrameRect(Rect(X - 3 + dx, Y + 2, X + 11 + dx, Y + 16));
    363351            Brush.Style := bsClear;
    364             Sprite(dst, HGrSystem, x - 1 + dx, y + 4, 10, 10,
    365               66 + i mod 11 * 11, 137 + i div 11 * 11);
    366             inc(dx, 15)
     352            Sprite(dst, HGrSystem, X - 1 + dx, Y + 4, 10, 10,
     353              66 + I mod 11 * 11, 137 + I div 11 * 11);
     354            Inc(dx, 15);
    367355          end;
    368356        end;
    369357      end;
    370   end; { featurebar }
    371 
    372   procedure NumberBarS(dst: TDpiBitmap; x, y: integer; Cap, s: string; T: TTexture);
    373   begin
    374     DLine(dst.Canvas, x - 2, x + 170, y + 16, T.ColorBevelShade, T.ColorBevelLight);
    375     LoweredTextOut(dst.Canvas, -1, T, x - 2, y, Cap);
    376     RisedTextout(dst.Canvas, x + 170 - BiColorTextWidth(dst.Canvas, s), y, s);
     358  end;
     359
     360  procedure NumberBarS(dst: TDpiBitmap; X, Y: Integer; Cap, S: string; T: TTexture);
     361  begin
     362    DLine(dst.Canvas, X - 2, X + 170, Y + 16, T.ColorBevelShade, T.ColorBevelLight);
     363    LoweredTextOut(dst.Canvas, -1, T, X - 2, Y, Cap);
     364    RisedTextout(dst.Canvas, X + 170 - BiColorTextWidth(dst.Canvas, S), Y, S);
    377365  end;
    378366
    379367var
    380   i, j, x, y, cix, uix, emix, InProd, Available, Destroyed, Loc, Cnt, yView,
    381     yTotal, yCaption: integer;
    382   s: string;
     368  I, J, X, Y, cix, uix, emix, InProd, Available, Destroyed, Loc, Cnt, yView,
     369    yTotal, yCaption: Integer;
     370  S: string;
    383371  ui: TUnitInfo;
    384372  mi: TModelInfo;
     
    387375
    388376  case Kind of
    389     dkOwnModel:
    390       begin
    391         DpiBitCanvas(offscreen.Canvas, 0, 0, wCommon, hOwnModel,
    392           Back.Canvas, 0, 0);
    393         yView := 13;
    394         yTotal := 92;
    395       end;
    396     dkEnemyModel:
    397       begin
    398         DpiBitCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyModel,
    399           Back.Canvas, wCommon, 0);
    400         yView := 13;
    401         yTotal := 92;
    402       end;
    403     dkEnemyUnit, dkOwnUnit:
    404       begin
    405         DpiBitCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyUnit,
    406           Back.Canvas, 2 * wCommon, 0);
    407         yView := 13;
    408         yTotal := 123;
    409       end;
    410     dkEnemyCityDefense:
    411       begin
    412         DpiBitCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyCityDefense,
    413           Back.Canvas, 3 * wCommon, 0);
    414         yView := 171;
    415         yTotal := 231;
    416       end;
    417     dkEnemyCity:
    418       begin
    419         DpiBitCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyCity,
    420           Back.Canvas, 4 * wCommon, 0);
    421       end;
     377    dkOwnModel: begin
     378      DpiBitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hOwnModel,
     379        Back.Canvas, 0, 0);
     380      yView := 13;
     381      yTotal := 92;
     382    end;
     383    dkEnemyModel: begin
     384      DpiBitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyModel,
     385        Back.Canvas, wCommon, 0);
     386      yView := 13;
     387      yTotal := 92;
     388    end;
     389    dkEnemyUnit, dkOwnUnit: begin
     390      DpiBitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyUnit,
     391        Back.Canvas, 2 * wCommon, 0);
     392      yView := 13;
     393      yTotal := 123;
     394    end;
     395    dkEnemyCityDefense: begin
     396      DpiBitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyCityDefense,
     397        Back.Canvas, 3 * wCommon, 0);
     398      yView := 171;
     399      yTotal := 231;
     400    end;
     401    dkEnemyCity: begin
     402      DpiBitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyCity,
     403        Back.Canvas, 4 * wCommon, 0);
     404    end;
    422405  end;
    423406  MarkUsedOffscreen(ClientWidth, ClientHeight);
     
    427410  begin // show city defense facilities
    428411    Cnt := 0;
    429     for i := 0 to 3 do
    430       if MyRO.EnemyCity[ecixShow].Flags and (2 shl i) <> 0 then
    431         inc(Cnt);
    432     x := (wCommon - Cnt * xSizeSmall) div 2 - (Cnt - 1) * 2;
    433     for i := 0 to 3 do
    434       if MyRO.EnemyCity[ecixShow].Flags and (2 shl i) <> 0 then
    435       begin
    436         case i of
    437           0: j := imWalls;
    438           1: j := imCoastalFort;
    439           2: j := imMissileBat;
    440           3: j := imBunker
     412    for I := 0 to 3 do
     413      if MyRO.EnemyCity[ecixShow].Flags and (2 shl I) <> 0 then
     414        Inc(Cnt);
     415    X := (wCommon - Cnt * xSizeSmall) div 2 - (Cnt - 1) * 2;
     416    for I := 0 to 3 do
     417      if MyRO.EnemyCity[ecixShow].Flags and (2 shl I) <> 0 then
     418      begin
     419        case I of
     420          0: J := imWalls;
     421          1: J := imCoastalFort;
     422          2: J := imMissileBat;
     423          3: J := imBunker;
    441424        end;
    442         Frame(offscreen.Canvas, x - 1, yImp - 1, x + xSizeSmall,
     425        Frame(Offscreen.Canvas, X - 1, yImp - 1, X + xSizeSmall,
    443426          yImp + ySizeSmall, MainTexture.ColorBevelLight,
    444427          MainTexture.ColorBevelShade);
    445         DpiBitCanvas(offscreen.Canvas, x, yImp, xSizeSmall, ySizeSmall,
    446           SmallImp.Canvas, j mod 7 * xSizeSmall,
    447           (j + SystemIconLines * 7) div 7 * ySizeSmall);
    448         inc(x, xSizeSmall + 4);
     428        DpiBitBltCanvas(Offscreen.Canvas, X, yImp, xSizeSmall, ySizeSmall,
     429          SmallImp.Canvas, J mod 7 * xSizeSmall,
     430          (J + SystemIconLines * 7) div 7 * ySizeSmall);
     431        Inc(X, xSizeSmall + 4);
    449432      end;
    450433  end;
     
    454437    PPicture := @Tribe[mox.owner].ModelPicture[mox.mix];
    455438    Available := 0;
    456     if G.Difficulty[me] = 0 then // supervisor -- count stacked units too
     439    if G.Difficulty[Me] = 0 then // supervisor -- count stacked units too
    457440      for Loc := 0 to G.lx * G.ly - 1 do
    458441      begin
    459442        if MyMap[Loc] and fUnit <> 0 then
    460443        begin
    461           Server(sGetUnits, me, Loc, Cnt);
     444          Server(sGetUnits, Me, Loc, Cnt);
    462445          for uix := 0 to Cnt - 1 do
    463446            if IsToCount(MyRO.EnemyUn[MyRO.nEnemyUn + uix].emix) then
    464               inc(Available);
     447              Inc(Available);
    465448        end;
    466449      end
     
    469452        if (MyRO.EnemyUn[uix].Loc >= 0) and IsToCount(MyRO.EnemyUn[uix].emix)
    470453        then
    471           inc(Available);
     454          Inc(Available);
    472455    Destroyed := 0;
    473456    for emix := 0 to MyRO.nEnemyModel - 1 do
    474457      if IsToCount(emix) then
    475         inc(Destroyed, MyRO.EnemyModel[emix].Lost);
     458        Inc(Destroyed, MyRO.EnemyModel[emix].Lost);
    476459  end
    477460  else
     
    480463    for uix := 0 to MyRO.nUn - 1 do
    481464      if (MyUn[uix].Loc >= 0) and (MyUn[uix].mix = mixShow) then
    482         inc(Available);
     465        Inc(Available);
    483466    InProd := 0;
    484467    for cix := 0 to MyRO.nCity - 1 do
    485468      if (MyCity[cix].Loc >= 0) and
    486469        (MyCity[cix].Project and (cpImp + cpIndex) = mixShow) then
    487         inc(InProd);
    488   end;
    489 
    490   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     470        Inc(InProd);
     471  end;
     472
     473  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    491474  if Kind in [dkEnemyCityDefense, dkEnemyCity] then
    492475  begin
    493     NoMap.SetOutput(offscreen);
    494     NoMap.PaintCity(ClientWidth div 2, 53, MyRO.EnemyCity[ecixShow], false);
    495 
    496     s := Tribe[MyRO.EnemyCity[ecixShow].owner].TPhrase('UNITOWNER');
    497     LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    498       (ClientWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2, 105, s);
     476    NoMap.SetOutput(Offscreen);
     477    NoMap.PaintCity(ClientWidth div 2, 53, MyRO.EnemyCity[ecixShow], False);
     478
     479    S := Tribe[MyRO.EnemyCity[ecixShow].owner].TPhrase('UNITOWNER');
     480    LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     481      (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 105, S);
    499482  end;
    500483
     
    502485  begin // show unit stats
    503486    if Kind = dkOwnModel then
    504       MakeModelInfo(me, mixShow, MyModel[mixShow], mi)
     487      MakeModelInfo(Me, mixShow, MyModel[mixShow], mi)
    505488    else if Kind = dkOwnUnit then
    506489    begin
    507       MakeUnitInfo(me, MyUn[uixShow], ui);
    508       MakeModelInfo(me, MyUn[uixShow].mix, MyModel[MyUn[uixShow].mix], mi);
     490      MakeUnitInfo(Me, MyUn[uixShow], ui);
     491      MakeModelInfo(Me, MyUn[uixShow].mix, MyModel[MyUn[uixShow].mix], mi);
    509492    end
    510493    else
     
    522505          { Frame(offscreen.canvas,xView-1,yView-1,xView+64,yView+48,
    523506            MainTexture.ColorBevelShade,MainTexture.ColorBevelLight);
    524             RFrame(offscreen.canvas,xView-2,yView-2,xView+65,yView+49,
     507            RFrame(Offscreen.Canvas,xView-2,yView-2,xView+65,yView+49,
    525508            MainTexture.ColorBevelShade,MainTexture.ColorBevelLight); }
    526           with offscreen.Canvas do
     509          with Offscreen.Canvas do
    527510          begin
    528511            Brush.Color := HGrSystem.Data.Canvas.Pixels[98, 67];
    529             offscreen.Canvas.FillRect(Rect(xView, yView, xView + 64,
     512            Offscreen.Canvas.FillRect(Rect(xView, yView, xView + 64,
    530513              yView + 16));
    531514            Brush.Style := bsClear;
     
    534517          if MyMap[Loc] and fTerrain >= fForest then
    535518          begin
    536             x := 1 + 2 * (xxt * 2 + 1);
    537             y := 1 + yyt + 2 * (yyt * 3 + 1);
     519            X := 1 + 2 * (xxt * 2 + 1);
     520            Y := 1 + yyt + 2 * (yyt * 3 + 1);
    538521          end
    539522          else
    540523          begin
    541             x := integer(MyMap[Loc] and fTerrain) * (xxt * 2 + 1) + 1;
    542             y := 1 + yyt;
     524            X := Integer(MyMap[Loc] and fTerrain) * (xxt * 2 + 1) + 1;
     525            Y := 1 + yyt;
    543526          end;
    544           for j := -1 to 1 do
    545             for i := -1 to 1 do
    546               if (i + j) and 1 = 0 then
     527          for J := -1 to 1 do
     528            for I := -1 to 1 do
     529              if (I + J) and 1 = 0 then
    547530              begin
    548                 Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2,
    549                   yyt * 2, x, y);
     531                Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2,
     532                  yyt * 2, X, Y);
    550533                if MyMap[Loc] and (fTerrain or fSpecial) = fGrass or fSpecial1
    551534                then
    552                   Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
     535                  Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2, yyt * 2,
    553536                    1 + 2 * (xxt * 2 + 1), 1 + yyt + 1 * (yyt * 3 + 1))
    554537                else if (MyMap[Loc] and fTerrain = fForest) and
    555538                  IsJungle(Loc div G.lx) then
    556                   Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
     539                  Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2, yyt * 2,
    557540                    1 + 7 * (xxt * 2 + 1), 1 + yyt + 19 * (yyt * 3 + 1))
    558541                else if MyMap[Loc] and fTerrain >= fForest then
    559                   Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
     542                  Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2, yyt * 2,
    560543                    1 + 7 * (xxt * 2 + 1),
    561                     1 + yyt + 2 * integer(2 + MyMap[Loc] and fTerrain - fForest)
     544                    1 + yyt + 2 * Integer(2 + MyMap[Loc] and fTerrain - fForest)
    562545                    * (yyt * 3 + 1));
    563546              end;
    564           DpiBitCanvas(offscreen.Canvas, xView, yView + 16, 64, 32,
     547          DpiBitBltCanvas(Offscreen.Canvas, xView, yView + 16, 64, 32,
    565548            Buffer.Canvas, 1, 0);
    566549
    567550          // show unit, experience and health
    568           Sprite(offscreen, HGr, xView, yView, 64, 48, pix mod 10 * 65 + 1,
     551          Sprite(Offscreen, HGr, xView, yView, 64, 48, pix mod 10 * 65 + 1,
    569552            pix div 10 * 49 + 1);
    570553          if Flags and unFortified <> 0 then
    571             Sprite(offscreen, HGrStdUnits, xView, yView, xxu * 2, yyu * 2,
     554            Sprite(Offscreen, HGrStdUnits, xView, yView, xxu * 2, yyu * 2,
    572555              1 + 6 * (xxu * 2 + 1), 1);
    573           FrameImage(offscreen.Canvas, HGrSystem.Data, xView - 20,
     556          FrameImage(Offscreen.Canvas, HGrSystem.Data, xView - 20,
    574557            yView + 5, 12, 14, 121 + Exp div ExpCost * 13, 28);
    575558          if Health < 100 then
    576559          begin
    577             s := IntToStr(Health) + '%';
    578             LightGradient(offscreen.Canvas, xView - 45, yView + 24, 38,
     560            S := IntToStr(Health) + '%';
     561            LightGradient(Offscreen.Canvas, xView - 45, yView + 24, 38,
    579562              (ColorOfHealth(Health) and $FEFEFE shr 2) * 3);
    580             RisedTextout(offscreen.Canvas, xView - 45 + 20 -
    581               BiColorTextWidth(offscreen.Canvas, s) div 2, yView + 23, s);
     563            RisedTextout(Offscreen.Canvas, xView - 45 + 20 -
     564              BiColorTextWidth(Offscreen.Canvas, S) div 2, yView + 23, S);
    582565          end;
    583566
    584567          if Kind = dkEnemyUnit then
    585568          begin
    586             s := Tribe[mox.owner].TPhrase('UNITOWNER');
    587             LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    588               (ClientWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2,
    589               yView + 80, s);
     569            S := Tribe[mox.owner].TPhrase('UNITOWNER');
     570            LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     571              (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2,
     572              yView + 80, S);
    590573          end;
    591574        end
    592575      else
    593576      begin
    594         FrameImage(offscreen.Canvas, BigImp, xView + 4, yView, 56, 40, 0, 0);
    595         Sprite(offscreen, HGr, xView, yView - 4, 64, 44, pix mod 10 * 65 + 1,
     577        FrameImage(Offscreen.Canvas, BigImp, xView + 4, yView, 56, 40, 0, 0);
     578        Sprite(Offscreen, HGr, xView, yView - 4, 64, 44, pix mod 10 * 65 + 1,
    596579          pix div 10 * 49 + 1);
    597580      end;
    598581
    599       DarkGradient(offscreen.Canvas, xTotal - 6, yTotal + 1, 180, 2);
    600       RisedTextout(offscreen.Canvas, xTotal - 2, yTotal,
     582      DarkGradient(Offscreen.Canvas, xTotal - 6, yTotal + 1, 180, 2);
     583      RisedTextout(Offscreen.Canvas, xTotal - 2, yTotal,
    601584        Phrases.Lookup('UNITSTRENGTH'));
    602       s := IntToStr(mi.Attack) + '/' + IntToStr(mi.Defense);
    603       RisedTextout(offscreen.Canvas,
    604         xTotal + 170 - BiColorTextWidth(offscreen.Canvas, s), yTotal, s);
    605       FeatureBar(offscreen, xTotal, yTotal + 19, mi, MainTexture);
    606       NumberBarS(offscreen, xTotal, yTotal + 38, Phrases.Lookup('UNITSPEED'),
     585      S := IntToStr(mi.Attack) + '/' + IntToStr(mi.Defense);
     586      RisedTextout(Offscreen.Canvas,
     587        xTotal + 170 - BiColorTextWidth(Offscreen.Canvas, S), yTotal, S);
     588      FeatureBar(Offscreen, xTotal, yTotal + 19, mi, MainTexture);
     589      NumberBarS(Offscreen, xTotal, yTotal + 38, Phrases.Lookup('UNITSPEED'),
    607590        MovementToString(mi.Speed), MainTexture);
    608       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, yTotal + 57,
     591      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, yTotal + 57,
    609592        Phrases.Lookup('UNITCOST'));
    610       DLine(offscreen.Canvas, xTotal - 2, xTotal + 170, yTotal + 57 + 16,
     593      DLine(Offscreen.Canvas, xTotal - 2, xTotal + 170, yTotal + 57 + 16,
    611594        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    612       if G.Difficulty[me] = 0 then
    613         s := IntToStr(mi.cost)
     595      if G.Difficulty[Me] = 0 then
     596        S := IntToStr(mi.cost)
    614597      else
    615         s := IntToStr(mi.cost * BuildCostMod[G.Difficulty[me]] div 12);
    616       RisedTextout(offscreen.Canvas,
    617         xTotal + 159 - BiColorTextWidth(offscreen.Canvas, s), yTotal + 57, s);
    618       Sprite(offscreen, HGrSystem, xTotal + 160, yTotal + 57 + 5, 10,
     598        S := IntToStr(mi.cost * BuildCostMod[G.Difficulty[Me]] div 12);
     599      RisedTextout(Offscreen.Canvas,
     600        xTotal + 159 - BiColorTextWidth(Offscreen.Canvas, S), yTotal + 57, S);
     601      Sprite(Offscreen, HGrSystem, xTotal + 160, yTotal + 57 + 5, 10,
    619602        10, 88, 115);
    620603
     
    624607        begin
    625608          if MyModel[mixShow].Kind = mkEnemyDeveloped then
    626             LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2,
     609            LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2,
    627610              (yTotal + StatDown - 19), Phrases.Lookup('UNITADOPT'))
    628611          else
    629             LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2,
     612            LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2,
    630613              (yTotal + StatDown - 19), Phrases.Lookup('UNITINTRO'));
    631           DLine(offscreen.Canvas, xTotal - 2, xTotal + 170,
     614          DLine(Offscreen.Canvas, xTotal - 2, xTotal + 170,
    632615            (yTotal + StatDown - 19) + 16, MainTexture.ColorTextShade,
    633616            MainTexture.ColorTextLight);
    634           s := TurnToString(MyModel[mixShow].IntroTurn);
    635           RisedTextout(offscreen.Canvas,
    636             xTotal + 170 - BiColorTextWidth(offscreen.Canvas, s),
    637             (yTotal + StatDown - 19), s);
     617          S := TurnToString(MyModel[mixShow].IntroTurn);
     618          RisedTextout(Offscreen.Canvas,
     619            xTotal + 170 - BiColorTextWidth(Offscreen.Canvas, S),
     620            (yTotal + StatDown - 19), S);
    638621        end;
    639622
    640         NumberBar(offscreen, xTotal, yTotal + StatDown,
     623        NumberBar(Offscreen, xTotal, yTotal + StatDown,
    641624          Phrases.Lookup('UNITBUILT'), MyModel[mixShow].Built, MainTexture);
    642625        if MyModel[mixShow].Lost > 0 then
    643           NumberBar(offscreen, xTotal, yTotal + StatDown + 19,
     626          NumberBar(Offscreen, xTotal, yTotal + StatDown + 19,
    644627            Phrases.Lookup('UNITLOST'), MyModel[mixShow].Lost, MainTexture);
    645628        if InProd > 0 then
    646           NumberBar(offscreen, xTotal, yTotal + StatDown + 57,
     629          NumberBar(Offscreen, xTotal, yTotal + StatDown + 57,
    647630            Phrases.Lookup('UNITINPROD'), InProd, MainTexture);
    648631        if Available > 0 then
    649           NumberBar(offscreen, xTotal, yTotal + StatDown + 38,
     632          NumberBar(Offscreen, xTotal, yTotal + StatDown + 38,
    650633            Phrases.Lookup('UNITAVAILABLE'), Available, MainTexture);
    651634
     
    674657      begin
    675658        if Destroyed > 0 then
    676           NumberBar(offscreen, xTotal, yTotal + StatDown - 19,
     659          NumberBar(Offscreen, xTotal, yTotal + StatDown - 19,
    677660            Phrases.Lookup('UNITDESTROYED'), Destroyed, MainTexture);
    678661        if Available > 0 then
    679           NumberBar(offscreen, xTotal, yTotal + StatDown,
     662          NumberBar(Offscreen, xTotal, yTotal + StatDown,
    680663            Phrases.Lookup('UNITKNOWN'), Available, MainTexture);
    681664      end;
     
    683666  end;
    684667
    685   offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
     668  Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    686669  case Kind of
    687670    dkOwnModel, dkEnemyModel:
     
    692675      yCaption := 79;
    693676  end;
    694   RisedTextout(offscreen.Canvas,
    695     (ClientWidth - BiColorTextWidth(offscreen.Canvas, Caption)) div 2,
     677  RisedTextout(Offscreen.Canvas,
     678    (ClientWidth - BiColorTextWidth(Offscreen.Canvas, Caption)) div 2,
    696679    yCaption, Caption);
    697 end; { OffscreenPaint }
     680end;
    698681
    699682procedure TUnitStatDlg.ModelBoxChange(Sender: TObject);
     
    734717procedure TUnitStatDlg.HelpBtnClick(Sender: TObject);
    735718begin
    736   HelpDlg.ShowNewContent(wmPersistent, hkModel, 0);
     719  MainScreen.HelpDlg.ShowNewContent(wmPersistent, hkModel, 0);
    737720end;
    738721
  • TabularUnified branches/highdpi/LocalPlayer/Wonders.pas

    r361 r465  
    2323    Selection: Integer;
    2424    Center: TPoint;
    25     procedure DarkIcon(i: Integer);
    26     procedure Glow(i, GlowColor: Integer);
     25    procedure DarkIcon(I: Integer);
     26    procedure Glow(I, GlowColor: Integer);
    2727    procedure PaintBackgroundShape;
    2828  public
    2929    procedure OffscreenPaint; override;
    30     procedure ShowNewContent(NewMode: Integer);
    31   end;
    32 
    33 var
    34   WondersDlg: TWondersDlg;
     30    procedure ShowNewContent(NewMode: TWindowMode);
     31  end;
    3532
    3633
     
    3835
    3936uses
    40   Term, ClientTools, Help, Tribes, UPixelPointer;
     37  Term, ClientTools, Help, Tribes, PixelPointer;
    4138
    4239{$R *.lfm}
     
    7673procedure TWondersDlg.FormShow(Sender: TObject);
    7774begin
     75  Caption := Phrases.Lookup('TITLE_WONDERS');
    7876  Selection := -1;
    7977  OffscreenPaint;
    8078end;
    8179
    82 procedure TWondersDlg.ShowNewContent(NewMode: Integer);
     80procedure TWondersDlg.ShowNewContent(NewMode: TWindowMode);
    8381begin
    8482  inherited ShowNewContent(NewMode);
     
    109107  Height := ScaleToNative(128);
    110108  Offscreen.BeginUpdate;
    111   Line[0] := PixelPointer(Offscreen, ScaleToNative(Center.X), ScaleToNative(Center.Y));
    112   Line[1] := PixelPointer(Offscreen, ScaleToNative(Center.X), ScaleToNative(Center.Y) - 1);
    113   Line[2] := PixelPointer(Offscreen, ScaleToNative(Center.X) - 1, ScaleToNative(Center.Y));
    114   Line[3] := PixelPointer(Offscreen, ScaleToNative(Center.X) - 1, ScaleToNative(Center.Y) - 1);
     109  Line[0] := TPixelPointer.Create(Offscreen, ScaleToNative(Center.X), ScaleToNative(Center.Y));
     110  Line[1] := TPixelPointer.Create(Offscreen, ScaleToNative(Center.X), ScaleToNative(Center.Y) - 1);
     111  Line[2] := TPixelPointer.Create(Offscreen, ScaleToNative(Center.X) - 1, ScaleToNative(Center.Y));
     112  Line[3] := TPixelPointer.Create(Offscreen, ScaleToNative(Center.X) - 1, ScaleToNative(Center.Y) - 1);
    115113  for Y := 0 to Height - 1 do begin
    116114    for X := 0 to Width - 1 do begin
    117       r := X * X * ((Height div 4) * (Height div 4)) + Y * Y * ((Width div 4) * (Width div 4));
     115      R := X * X * ((Height div 4) * (Height div 4)) + Y * Y * ((Width div 4) * (Width div 4));
    118116      ax := ((1 shl 16 div (Height div 4)) * (Width div 4)) * Y;
    119       if (r < ScaleToNative(8) * Height * Width * Width) and
    120         ((r >= (Height div 4) * (Height div 2) * (Width div 2) * (Width div 2)) and (ax < amax2 * X) and
     117      if (R < ScaleToNative(8) * Height * Width * Width) and
     118        ((R >= (Height div 4) * (Height div 2) * (Width div 2) * (Width div 2)) and (ax < amax2 * X) and
    121119        ((ax < amax0 * X) or (ax > amin2 * X)) or (ax > amin1 * X) and
    122120        ((ax < amax1 * X) or (ax > amin3 * X))) then begin
    123121        for ch := 0 to 2 do begin
    124           c := Line[0].Pixel^.Planes[ch] - Darken;
    125           if c < 0 then Line[0].Pixel^.Planes[ch] := 0
    126             else Line[0].Pixel^.Planes[ch] := c;
    127           c := Line[1].Pixel^.Planes[ch] - Darken;
    128           if c < 0 then Line[1].Pixel^.Planes[ch] := 0
    129             else Line[1].Pixel^.Planes[ch] := c;
    130           c := Line[2].Pixel^.Planes[ch] - Darken;
    131           if c < 0 then Line[2].Pixel^.Planes[ch] := 0
    132             else Line[2].Pixel^.Planes[ch] := c;
    133           c := Line[3].Pixel^.Planes[ch] - Darken;
    134           if c < 0 then Line[3].Pixel^.Planes[ch] := 0
    135             else Line[3].Pixel^.Planes[ch] := c;
     122          C := Line[0].Pixel^.Planes[ch] - Darken;
     123          if C < 0 then Line[0].Pixel^.Planes[ch] := 0
     124            else Line[0].Pixel^.Planes[ch] := C;
     125          C := Line[1].Pixel^.Planes[ch] - Darken;
     126          if C < 0 then Line[1].Pixel^.Planes[ch] := 0
     127            else Line[1].Pixel^.Planes[ch] := C;
     128          C := Line[2].Pixel^.Planes[ch] - Darken;
     129          if C < 0 then Line[2].Pixel^.Planes[ch] := 0
     130            else Line[2].Pixel^.Planes[ch] := C;
     131          C := Line[3].Pixel^.Planes[ch] - Darken;
     132          if C < 0 then Line[3].Pixel^.Planes[ch] := 0
     133            else Line[3].Pixel^.Planes[ch] := C;
    136134        end;
    137135      end;
     
    149147end;
    150148
    151 procedure TWondersDlg.DarkIcon(i: Integer);
     149procedure TWondersDlg.DarkIcon(I: Integer);
    152150var
    153   X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, c: Integer;
     151  X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, C: Integer;
    154152  Src, Dst: TPixelPointer;
    155153begin
    156154  Offscreen.BeginUpdate;
    157   x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[i].X;
    158   y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[i].Y;
    159   x0Src := (i mod 7) * xSizeBig;
    160   y0Src := (i div 7 + SystemIconLines) * ySizeBig;
    161   Src := PixelPointer(BigImp, ScaleToNative(x0Src), ScaleToNative(y0Src));
    162   Dst := PixelPointer(Offscreen, ScaleToNative(x0Dst), ScaleToNative(y0Dst));
     155  x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[I].X;
     156  y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[I].Y;
     157  x0Src := (I mod 7) * xSizeBig;
     158  y0Src := (I div 7 + SystemIconLines) * ySizeBig;
     159  Src := TPixelPointer.Create(BigImp, ScaleToNative(x0Src), ScaleToNative(y0Src));
     160  Dst := TPixelPointer.Create(Offscreen, ScaleToNative(x0Dst), ScaleToNative(y0Dst));
    163161  for Y := 0 to ScaleToNative(ySizeBig) - 1 do begin
    164162    for X := 0 to ScaleToNative(xSizeBig) - 1 do begin
     
    166164        15 + (255 - Src.Pixel^.R) * 9) div 128;
    167165      for ch := 0 to 2 do begin
    168         c := Dst.Pixel^.Planes[ch] - Darken;
    169         if c < 0 then Dst.Pixel^.Planes[ch] := 0
    170           else Dst.Pixel^.Planes[ch] := c;
     166        C := Dst.Pixel^.Planes[ch] - Darken;
     167        if C < 0 then Dst.Pixel^.Planes[ch] := 0
     168          else Dst.Pixel^.Planes[ch] := C;
    171169      end;
    172170      Src.NextPixel;
     
    179177end;
    180178
    181 procedure TWondersDlg.Glow(i, GlowColor: Integer);
     179procedure TWondersDlg.Glow(I, GlowColor: Integer);
    182180begin
    183181  GlowFrame(Offscreen,
    184     ClientWidth div 2 - xSizeBig div 2 + RingPosition[i].X,
    185     ClientHeight div 2 - ySizeBig div 2 + RingPosition[i].Y,
     182    ClientWidth div 2 - xSizeBig div 2 + RingPosition[I].X,
     183    ClientHeight div 2 - ySizeBig div 2 + RingPosition[I].Y,
    186184    xSizeBig, ySizeBig, GlowColor);
    187185end;
     
    235233        WonderDestroyed: begin
    236234          HaveWonder := True;
    237           DpiBitCanvas(Offscreen.Canvas,
     235          DpiBitBltCanvas(Offscreen.Canvas,
    238236            Center.X - xSizeBig div 2 + RingPosition[I].X,
    239237            Center.Y - ySizeBig div 2 + RingPosition[I].Y, xSizeBig,
     
    243241        else begin
    244242          HaveWonder := True;
    245           DpiBitCanvas(Offscreen.Canvas,
     243          DpiBitBltCanvas(Offscreen.Canvas,
    246244            Center.X - xSizeBig div 2 + RingPosition[I].X,
    247245            Center.Y - ySizeBig div 2 + RingPosition[I].Y, xSizeBig, ySizeBig,
     
    280278
    281279  MarkUsedOffscreen(ClientWidth, ClientHeight);
    282 end; { OffscreenPaint }
     280end;
    283281
    284282procedure TWondersDlg.CloseBtnClick(Sender: TObject);
     
    350348begin
    351349  if Selection >= 0 then
    352     HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, Selection);
     350    MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Selection);
    353351end;
    354352
Note: See TracChangeset for help on using the changeset viewer.