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

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