Ignore:
Timestamp:
Nov 30, 2023, 10:16:14 PM (12 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/CityScreen.pas

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