Ignore:
Timestamp:
Nov 30, 2023, 10:16:14 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Updated high dpi branch from trunk.
  • Modified: Use generics.collections instead of fgl.
  • Modified: Compile with Delphi syntax.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.