Changeset 6 for trunk/Start.pas


Ignore:
Timestamp:
Jan 7, 2017, 11:32:14 AM (7 years ago)
Author:
chronos
Message:
  • Modified: Formated all project source files using Delphi formatter as original indentation and other formatting was really bad.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Start.pas

    r4 r6  
    11{$INCLUDE switches}
    2 
    32unit Start;
    43
     
    65
    76uses
    8   GameServer,Messg,ButtonBase,ButtonA,ButtonC,ButtonB,Area,
    9 
    10   Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,StdCtrls,
    11   Menus,Registry;
    12 
     7  GameServer, Messg, ButtonBase, ButtonA, ButtonC, ButtonB, Area,
     8
     9  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls,
     10  Menus, Registry;
    1311
    1412const
    15 // main actions
    16 nMainActions=5; maConfig=0; maManual=1; maCredits=2; maAIDev=3; maWeb=4;
    17 
     13  // main actions
     14  nMainActions = 5;
     15  maConfig = 0;
     16  maManual = 1;
     17  maCredits = 2;
     18  maAIDev = 3;
     19  maWeb = 4;
    1820
    1921type
     
    3537    AutoEnemyDownBtn: TButtonC;
    3638    ReplayBtn: TButtonB;
    37     procedure StartBtnClick(Sender:TObject);
    38     procedure FormPaint(Sender:TObject);
    39     procedure FormShow(Sender:TObject);
    40     procedure FormDestroy(Sender:TObject);
    41     procedure FormCreate(Sender:TObject);
     39    procedure StartBtnClick(Sender: TObject);
     40    procedure FormPaint(Sender: TObject);
     41    procedure FormShow(Sender: TObject);
     42    procedure FormDestroy(Sender: TObject);
     43    procedure FormCreate(Sender: TObject);
    4244    procedure BrainClick(Sender: TObject);
    4345    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
     
    5557    procedure FormHide(Sender: TObject);
    5658    procedure QuitBtnClick(Sender: TObject);
    57     procedure FormKeyDown(Sender: TObject; var Key: Word;
    58       Shift: TShiftState);
     59    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    5960    procedure CustomizeBtnClick(Sender: TObject);
    6061    procedure AutoDiffUpBtnClick(Sender: TObject);
    6162    procedure AutoDiffDownBtnClick(Sender: TObject);
    6263    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
    63       Shift: TShiftState; X, Y: Integer);
    64     procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
    65       Y: Integer);
     64      Shift: TShiftState; x, y: integer);
     65    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; x, y: integer);
    6666    procedure AutoEnemyUpBtnClick(Sender: TObject);
    6767    procedure AutoEnemyDownBtnClick(Sender: TObject);
    6868    procedure ReplayBtnClick(Sender: TObject);
    6969  public
    70     BrainPicture: array[0..maxBrain-1] of TBitmap;
     70    BrainPicture: array [0 .. maxBrain - 1] of TBitmap;
    7171    EmptyPicture: TBitmap;
    7272    procedure UpdateFormerGames;
     
    7474  private
    7575    WorldSize, StartLandMass, MaxTurn, AutoEnemies, AutoDiff, MultiControl,
    76     MiniWidth, MiniHeight, SelectedAction,
    77     Page, ShowTab, Tab, Diff0, bixDefault,
    78     nMapLandTiles,nMapStartPositions,
    79     LoadTurn, LastTurn, {last turn of selected former game}
    80     SlotAvailable,
    81     bixPopup: integer; {brain concerned by brain context menu}
    82     ListIndex: array[0..3] of integer;
     76      MiniWidth, MiniHeight, SelectedAction, Page, ShowTab, Tab, Diff0,
     77      bixDefault, nMapLandTiles, nMapStartPositions, LoadTurn, LastTurn,
     78    { last turn of selected former game }
     79    SlotAvailable, bixPopup: integer; { brain concerned by brain context menu }
     80    ListIndex: array [0 .. 3] of integer;
    8381    MapFileName: string;
    8482    FormerGames, Maps: TStringList;
    85     LogoBuffer,
    86     Mini:TBitmap; {game world sample preview}
    87     MiniColors: array[0..11,0..1] of TColor;
    88 //    BookDate: string;
    89     DiffUpBtn: array[0..8] of TButtonC;
    90     DiffDownBtn: array[0..8] of TButtonC;
    91     MultiBtn: array[6..8] of TButtonC;
    92     MiniMode: (mmNone,mmPicture,mmMultiPlayer);
    93     ActionsOffered: set of 0..nMainActions-1;
     83    LogoBuffer, Mini: TBitmap; { game world sample preview }
     84    MiniColors: array [0 .. 11, 0 .. 1] of TColor;
     85    // BookDate: string;
     86    DiffUpBtn: array [0 .. 8] of TButtonC;
     87    DiffDownBtn: array [0 .. 8] of TButtonC;
     88    MultiBtn: array [6 .. 8] of TButtonC;
     89    MiniMode: (mmNone, mmPicture, mmMultiPlayer);
     90    ActionsOffered: set of 0 .. nMainActions - 1;
    9491    TurnValid, Tracking: boolean;
    9592    procedure InitPopup(PopupIndex: integer);
     
    9895    procedure ChangeTab(NewTab: integer);
    9996    procedure UnlistBackupFile(FileName: string);
    100     procedure SmartInvalidate(x0,y0,x1,y1: integer; invalidateTab0: boolean = false);
    101   end;
    102 
    103 var
    104   StartDlg:TStartDlg;
     97    procedure SmartInvalidate(x0, y0, x1, y1: integer;
     98      invalidateTab0: boolean = false);
     99  end;
     100
     101var
     102  StartDlg: TStartDlg;
    105103
    106104implementation
    107105
    108106uses
    109 Directories, Protocol, Direct, ScreenTools, Inp, Back,
    110 
    111 ShellAPI;
     107  Directories, Protocol, Direct, ScreenTools, Inp, Back,
     108
     109  ShellAPI;
    112110
    113111{$R *.DFM}
    114112
    115113const
    116 // predefined world size
    117 // attention: lx*ly+1 must be prime!
    118 {nWorldSize=8;
    119 lxpre: array[0..nWorldSize-1] of integer =(30,40,50,60,70,90,110,130);
    120 lypre: array[0..nWorldSize-1] of integer =(46,52,60,70,84,94,110,130);
    121 DefaultWorldTiles=4200;}
    122 nWorldSize=6;
    123 lxpre: array[0..nWorldSize-1] of integer =(30,40,50,60,75,100);
    124 lypre: array[0..nWorldSize-1] of integer =(46,52,60,70,82,96);
    125 DefaultWorldTiles=4150;
    126 DefaultWorldSize=3;
    127 DefaultLandMass=30;
    128 
    129 nPlOffered=9;
    130 yMain=14;
    131 xActionIcon=55; xAction=111; yAction=60; ActionPitch=56; ActionSideBorder=24;
    132 ActionBottomBorder=10;
    133 wBuffer=91;
    134 x0Mini=437; y0Mini=178;
    135 xTurnSlider=346; yTurnSlider=262; wTurnSlider=168;
    136 yLogo=74;
    137 xDefault=234; yDefault=148;
    138 x0Brain=146; y0Brain=148;
    139 dxBrain=104; dyBrain=80;
    140 xBrain: array[0..nPlOffered-1] of integer =
    141   (x0Brain,x0Brain,x0Brain+dxBrain,x0Brain+dxBrain,x0Brain+dxBrain,x0Brain,
    142   x0Brain-dxBrain,x0Brain-dxBrain,x0Brain-dxBrain);
    143 yBrain: array[0..nPlOffered-1] of integer =
    144   (y0Brain,y0Brain-dyBrain,y0Brain-dyBrain,y0Brain,y0Brain+dyBrain,
    145   y0Brain+dyBrain,y0Brain+dyBrain,y0Brain,y0Brain-dyBrain);
    146 TabOffset=-115; TabSize=159; TabHeight=40;
    147 
    148 MaxWidthMapLogo=96; MaxHeightMapLogo=96;
    149 
    150 InitAlive: array[1..nPl] of integer=
    151 (1,1+2,1+2+32,1+2+8+128,1+2+8+32+128,1+2+8+16+64+128,1+2+4+16+32+64+256,
    152 511-32,511,511-32,511,511-32,511,511-32,511);
    153 InitMulti: array[nPlOffered+1..nPl] of integer=
    154 (256,256,256+128,256+128,256+128+64,256+128+64);
    155 
    156 pgStartRandom=0; pgStartMap=1; pgNoLoad=2; pgLoad=3; pgEditRandom=4;
    157 pgEditMap=5; pgMain=6;
    158 
    159 OfferMultiple=[6,7,8];
    160 
    161 PlayerAutoDiff: array[1..5] of integer=(1,1,2,2,3);
    162 EnemyAutoDiff: array[1..5] of integer=(4,3,2,1,1);
    163 
    164 
    165 procedure TStartDlg.FormCreate(Sender:TObject);
    166 var
    167 x,y,i,ResolutionX,ResolutionY,ResolutionBPP,ResolutionFreq,ScreenMode: integer;
    168 DefaultAI,s: string;
    169 r0,r1: HRgn;
    170 Reg: TRegistry;
    171 FirstStart: boolean;
    172 begin
    173 Reg:=TRegistry.Create;
    174 FirstStart:=not Reg.KeyExists('SOFTWARE\cevo\RegVer9\Start');
    175 
    176 if FirstStart then
    177   begin
    178   // initialize AI assignment
    179   Reg.OpenKey('SOFTWARE\cevo\RegVer9\Start',true);
    180   for i:=0 to nPlOffered-1 do
    181     begin
    182     if i=0 then s:=':StdIntf'
    183     else s:='StdAI';
    184     Reg.WriteString('Control'+IntToStr(i),s);
    185     Reg.WriteInteger('Diff'+IntToStr(i),2);
     114  // predefined world size
     115  // attention: lx*ly+1 must be prime!
     116  { nWorldSize=8;
     117    lxpre: array[0..nWorldSize-1] of integer =(30,40,50,60,70,90,110,130);
     118    lypre: array[0..nWorldSize-1] of integer =(46,52,60,70,84,94,110,130);
     119    DefaultWorldTiles=4200; }
     120  nWorldSize = 6;
     121  lxpre: array [0 .. nWorldSize - 1] of integer = (30, 40, 50, 60, 75, 100);
     122  lypre: array [0 .. nWorldSize - 1] of integer = (46, 52, 60, 70, 82, 96);
     123  DefaultWorldTiles = 4150;
     124  DefaultWorldSize = 3;
     125  DefaultLandMass = 30;
     126
     127  nPlOffered = 9;
     128  yMain = 14;
     129  xActionIcon = 55;
     130  xAction = 111;
     131  yAction = 60;
     132  ActionPitch = 56;
     133  ActionSideBorder = 24;
     134  ActionBottomBorder = 10;
     135  wBuffer = 91;
     136  x0Mini = 437;
     137  y0Mini = 178;
     138  xTurnSlider = 346;
     139  yTurnSlider = 262;
     140  wTurnSlider = 168;
     141  yLogo = 74;
     142  xDefault = 234;
     143  yDefault = 148;
     144  x0Brain = 146;
     145  y0Brain = 148;
     146  dxBrain = 104;
     147  dyBrain = 80;
     148  xBrain: array [0 .. nPlOffered - 1] of integer = (x0Brain, x0Brain,
     149    x0Brain + dxBrain, x0Brain + dxBrain, x0Brain + dxBrain, x0Brain,
     150    x0Brain - dxBrain, x0Brain - dxBrain, x0Brain - dxBrain);
     151  yBrain: array [0 .. nPlOffered - 1] of integer = (y0Brain, y0Brain - dyBrain,
     152    y0Brain - dyBrain, y0Brain, y0Brain + dyBrain, y0Brain + dyBrain,
     153    y0Brain + dyBrain, y0Brain, y0Brain - dyBrain);
     154  TabOffset = -115;
     155  TabSize = 159;
     156  TabHeight = 40;
     157
     158  MaxWidthMapLogo = 96;
     159  MaxHeightMapLogo = 96;
     160
     161  InitAlive: array [1 .. nPl] of integer = (1, 1 + 2, 1 + 2 + 32,
     162    1 + 2 + 8 + 128, 1 + 2 + 8 + 32 + 128, 1 + 2 + 8 + 16 + 64 + 128,
     163    1 + 2 + 4 + 16 + 32 + 64 + 256, 511 - 32, 511, 511 - 32, 511, 511 - 32, 511,
     164    511 - 32, 511);
     165  InitMulti: array [nPlOffered + 1 .. nPl] of integer = (256, 256, 256 + 128,
     166    256 + 128, 256 + 128 + 64, 256 + 128 + 64);
     167
     168  pgStartRandom = 0;
     169  pgStartMap = 1;
     170  pgNoLoad = 2;
     171  pgLoad = 3;
     172  pgEditRandom = 4;
     173  pgEditMap = 5;
     174  pgMain = 6;
     175
     176  OfferMultiple = [6, 7, 8];
     177
     178  PlayerAutoDiff: array [1 .. 5] of integer = (1, 1, 2, 2, 3);
     179  EnemyAutoDiff: array [1 .. 5] of integer = (4, 3, 2, 1, 1);
     180
     181procedure TStartDlg.FormCreate(Sender: TObject);
     182var
     183  x, y, i, ResolutionX, ResolutionY, ResolutionBPP, ResolutionFreq,
     184    ScreenMode: integer;
     185  DefaultAI, s: string;
     186  r0, r1: HRgn;
     187  Reg: TRegistry;
     188  FirstStart: boolean;
     189begin
     190  Reg := TRegistry.Create;
     191  FirstStart := not Reg.KeyExists('SOFTWARE\cevo\RegVer9\Start');
     192
     193  if FirstStart then
     194  begin
     195    // initialize AI assignment
     196    Reg.OpenKey('SOFTWARE\cevo\RegVer9\Start', true);
     197    for i := 0 to nPlOffered - 1 do
     198    begin
     199      if i = 0 then
     200        s := ':StdIntf'
     201      else
     202        s := 'StdAI';
     203      Reg.WriteString('Control' + IntToStr(i), s);
     204      Reg.WriteInteger('Diff' + IntToStr(i), 2);
    186205    end;
    187   Reg.WriteInteger('MultiControl',0);
    188   Reg.closekey;
    189 
    190   // register file type: "cevo Book" -- fails with no administrator rights!
    191   try
    192     Reg.RootKey:=HKEY_CLASSES_ROOT;
    193     Reg.OpenKey ('.cevo',true);
    194     Reg.WriteString ('','cevoBook');
     206    Reg.WriteInteger('MultiControl', 0);
    195207    Reg.closekey;
    196     Reg.OpenKey ('cevoBook',true);
    197     Reg.WriteString ('','cevo Book');
     208
     209    // register file type: "cevo Book" -- fails with no administrator rights!
     210    try
     211      Reg.RootKey := HKEY_CLASSES_ROOT;
     212      Reg.OpenKey('.cevo', true);
     213      Reg.WriteString('', 'cevoBook');
     214      Reg.closekey;
     215      Reg.OpenKey('cevoBook', true);
     216      Reg.WriteString('', 'cevo Book');
     217      Reg.closekey;
     218      Reg.OpenKey('cevoBook\DefaultIcon', true);
     219      Reg.WriteString('', ParamStr(0) + ',0');
     220      Reg.closekey;
     221      Reg.OpenKey('cevoBook\shell\open\command', true);
     222      Reg.WriteString('', ParamStr(0) + ' "%1"');
     223      Reg.closekey;
     224    except
     225    end;
     226  end
     227  else
     228  begin
     229    Reg.OpenKey('SOFTWARE\cevo\RegVer9\Start', false);
     230    try
     231      WorldSize := Reg.ReadInteger('WorldSize');
     232      StartLandMass := Reg.ReadInteger('LandMass');
     233      MaxTurn := Reg.ReadInteger('MaxTurn');
     234      DefaultAI := Reg.ReadString('DefaultAI');
     235      AutoEnemies := Reg.ReadInteger('AutoEnemies');
     236      AutoDiff := Reg.ReadInteger('AutoDiff');
     237    except
     238      FirstStart := true;
     239    end;
    198240    Reg.closekey;
    199     Reg.OpenKey ('cevoBook\DefaultIcon',true);
    200     Reg.WriteString ('',ParamStr(0)+',0');
     241  end;
     242
     243  FullScreen := true;
     244  if FirstStart then
     245  begin
     246    WorldSize := DefaultWorldSize;
     247    StartLandMass := DefaultLandMass;
     248    MaxTurn := 800;
     249    DefaultAI := 'StdAI';
     250    AutoEnemies := 8;
     251    AutoDiff := 1;
     252  end
     253  else
     254  begin
     255    Reg.OpenKey('SOFTWARE\cevo\RegVer9', false);
     256    try
     257      ScreenMode := Reg.ReadInteger('ScreenMode');
     258      FullScreen := ScreenMode > 0;
     259      if Reg.ValueExists('ResolutionX') then
     260        ResolutionX := Reg.ReadInteger('ResolutionX');
     261      if Reg.ValueExists('ResolutionY') then
     262        ResolutionY := Reg.ReadInteger('ResolutionY');
     263      if Reg.ValueExists('ResolutionBPP') then
     264        ResolutionBPP := Reg.ReadInteger('ResolutionBPP');
     265      if Reg.ValueExists('ResolutionFreq') then
     266        ResolutionFreq := Reg.ReadInteger('ResolutionFreq');
     267      if ScreenMode = 2 then
     268        ChangeResolution(ResolutionX, ResolutionY, ResolutionBPP,
     269          ResolutionFreq);
     270    except
     271    end;
    201272    Reg.closekey;
    202     Reg.OpenKey ('cevoBook\shell\open\command',true);
    203     Reg.WriteString ('',ParamStr(0)+' "%1"');
    204     Reg.closekey;
    205   except
    206     end;
    207   end
    208 else
    209   begin
    210   Reg.OpenKey('SOFTWARE\cevo\RegVer9\Start',false);
    211   try
    212     WorldSize:=Reg.ReadInteger('WorldSize');
    213     StartLandMass:=Reg.ReadInteger('LandMass');
    214     MaxTurn:=Reg.ReadInteger('MaxTurn');
    215     DefaultAI:=Reg.ReadString('DefaultAI');
    216     AutoEnemies:=Reg.ReadInteger('AutoEnemies');
    217     AutoDiff:=Reg.ReadInteger('AutoDiff');
    218   except
    219     FirstStart:=true;
    220     end;
    221   Reg.closekey;
    222   end;
    223 
    224 FullScreen:=true;
    225 if FirstStart then
    226   begin
    227   WorldSize:=DefaultWorldSize;
    228   StartLandMass:=DefaultLandMass;
    229   MaxTurn:=800;
    230   DefaultAI:='StdAI';
    231   AutoEnemies:=8;
    232   AutoDiff:=1;
    233   end
    234 else
    235   begin
    236   Reg.OpenKey('SOFTWARE\cevo\RegVer9',false);
    237   try
    238     ScreenMode:=Reg.ReadInteger('ScreenMode');
    239     FullScreen:= ScreenMode>0;
    240     if Reg.ValueExists('ResolutionX') then
    241       ResolutionX:=Reg.ReadInteger('ResolutionX');
    242     if Reg.ValueExists('ResolutionY') then
    243         ResolutionY:=Reg.ReadInteger('ResolutionY');
    244     if Reg.ValueExists('ResolutionBPP') then
    245         ResolutionBPP:=Reg.ReadInteger('ResolutionBPP');
    246     if Reg.ValueExists('ResolutionFreq') then
    247         ResolutionFreq:=Reg.ReadInteger('ResolutionFreq');
    248     if ScreenMode=2 then
    249       ChangeResolution(ResolutionX,ResolutionY,ResolutionBPP,ResolutionFreq);
    250   except
    251     end;
    252   Reg.closekey;
    253   end;
    254 Reg.Free;
    255 
    256 ActionsOffered:=[maManual,maCredits,maWeb];
    257 if FileExists(HomeDir+'Configurator.exe') then
    258   include(ActionsOffered,maConfig);
    259 if FileExists(HomeDir+'AI Template\AI development manual.html') then
    260   include(ActionsOffered,maAIDev);
    261 
    262 bixDefault:=-1;
    263 for i:=bixRandom to nBrain-1 do
    264   if AnsiCompareFileName(DefaultAI,Brain[i].FileName)=0 then bixDefault:=i;
    265 if (bixDefault=bixRandom) and (nBrain<bixFirstAI+2) then
    266   bixDefault:=-1;
    267 if (bixDefault<0) and (nBrain>bixFirstAI) then bixDefault:=bixFirstAI; // default AI not found, use any
    268 
    269 DirectDlg.left:=(screen.width-DirectDlg.width) div 2;
    270 DirectDlg.top:=(screen.height-DirectDlg.height) div 2;
    271 
    272 if FullScreen then
    273   begin
    274   Left:=(Screen.Width-800)*3 div 8;
    275   Top:=Screen.Height-ClientHeight-(Screen.Height-600) div 3;
    276 
    277   r0:=CreateRectRgn(0,0,ClientWidth,ClientHeight);
    278   r1:=CreateRectRgn(TabOffset+4*TabSize+2,0,ClientWidth,TabHeight);
    279   CombineRgn(r0,r0,r1,RGN_DIFF);
    280   //DeleteObject(r1);
    281   r1:=CreateRectRgn(QuitBtn.left,QuitBtn.Top,QuitBtn.left+QuitBtn.Width,
    282     QuitBtn.Top+QuitBtn.Height);
    283   CombineRgn(r0,r0,r1,RGN_OR);
    284   //DeleteObject(r1);
    285   SetWindowRgn(Handle,r0,false);
    286   //DeleteObject(r0); // causes crash with Windows 95
    287   end
    288 else
    289   begin
    290   Left:=(Screen.Width-Width) div 2;
    291   Top:=(Screen.Height-Height) div 2;
    292   end;
    293 
    294 Canvas.Font.Assign(UniFont[ftNormal]);
    295 Canvas.Brush.Style:=bsClear;
    296 
    297 QuitBtn.Hint:=Phrases.Lookup('STARTCONTROLS',0);
    298 ReplayBtn.Hint:=Phrases.Lookup('BTN_REPLAY');
    299 for i:=0 to nPlOffered-1 do
    300   begin
    301   DiffUpBtn[i]:=TButtonC.Create(self);
    302   DiffUpBtn[i].Graphic:=GrExt[HGrSystem].Data;
    303   DiffUpBtn[i].Left:=xBrain[i]-18;
    304   DiffUpBtn[i].Top:=yBrain[i]+39;
    305   DiffUpBtn[i].ButtonIndex:=1;
    306   DiffUpBtn[i].Parent:=self;
    307   DiffUpBtn[i].OnClick:=DiffBtnClick;
    308   DiffDownBtn[i]:=TButtonC.Create(self);
    309   DiffDownBtn[i].Graphic:=GrExt[HGrSystem].Data;
    310   DiffDownBtn[i].Left:=xBrain[i]-18;
    311   DiffDownBtn[i].Top:=yBrain[i]+51;
    312   DiffDownBtn[i].ButtonIndex:=0;
    313   DiffDownBtn[i].Parent:=self;
    314   DiffDownBtn[i].OnClick:=DiffBtnClick;
    315   end;
    316 for i:=6 to 8 do
    317   begin
    318   MultiBtn[i]:=TButtonC.Create(self);
    319   MultiBtn[i].Graphic:=GrExt[HGrSystem].Data;
    320   MultiBtn[i].Left:=xBrain[i]-18;
    321   MultiBtn[i].Top:=yBrain[i];
    322   MultiBtn[i].Parent:=self;
    323   MultiBtn[i].OnClick:=MultiBtnClick;
    324   end;
    325 
    326 x:=BiColorTextWidth(Canvas,Phrases.Lookup('STARTCONTROLS',7)) div 2;
    327 CustomizeBtn.Left:=x0Brain+32-16-x;
    328 if AutoDiff<0 then CustomizeBtn.ButtonIndex:=3
    329 else CustomizeBtn.ButtonIndex:=2;
    330 
    331 BrainPicture[0]:=TBitmap.Create;
    332 BrainPicture[0].Width:=64; BrainPicture[0].Height:=64;
    333 BitBlt(BrainPicture[0].Canvas.Handle,0,0,64,64,
    334   GrExt[HGrSystem2].Data.Canvas.Handle,1,111,SRCCOPY);
    335 BrainPicture[1]:=TBitmap.Create;
    336 BrainPicture[1].Width:=64; BrainPicture[1].Height:=64;
    337 BitBlt(BrainPicture[1].Canvas.Handle,0,0,64,64,
    338   GrExt[HGrSystem2].Data.Canvas.Handle,66,111,SRCCOPY);
    339 BrainPicture[2]:=TBitmap.Create;
    340 BrainPicture[2].Width:=64; BrainPicture[2].Height:=64;
    341 BitBlt(BrainPicture[2].Canvas.Handle,0,0,64,64,
    342   GrExt[HGrSystem2].Data.Canvas.Handle,131,111,SRCCOPY);
    343 BrainPicture[3]:=TBitmap.Create;
    344 BrainPicture[3].Width:=64; BrainPicture[3].Height:=64;
    345 BitBlt(BrainPicture[3].Canvas.Handle,0,0,64,64,
    346   GrExt[HGrSystem2].Data.Canvas.Handle,131,46,SRCCOPY);
    347 for i:=bixFirstAI to nBrain-1 do
    348   begin
    349   BrainPicture[i]:=TBitmap.Create;
    350   if not LoadGraphicFile(BrainPicture[i], HomeDir+Brain[i].FileName, gfNoError) then
    351     begin
    352     BrainPicture[i].Width:=64; BrainPicture[i].Height:=64;
    353     with BrainPicture[i].Canvas do
    354       begin
    355       Brush.Color:=$904830;
    356       FillRect(Rect(0,0,64,64));
    357       Font.Assign(UniFont[ftTiny]);
    358       Font.Style:=[];
    359       Font.Color:=$5FDBFF;
    360       Textout(32-TextWidth(Brain[i].FileName) div 2,
    361         32-TextHeight(Brain[i].FileName) div 2,Brain[i].FileName);
     273  end;
     274  Reg.Free;
     275
     276  ActionsOffered := [maManual, maCredits, maWeb];
     277  if FileExists(HomeDir + 'Configurator.exe') then
     278    include(ActionsOffered, maConfig);
     279  if FileExists(HomeDir + 'AI Template\AI development manual.html') then
     280    include(ActionsOffered, maAIDev);
     281
     282  bixDefault := -1;
     283  for i := bixRandom to nBrain - 1 do
     284    if AnsiCompareFileName(DefaultAI, Brain[i].FileName) = 0 then
     285      bixDefault := i;
     286  if (bixDefault = bixRandom) and (nBrain < bixFirstAI + 2) then
     287    bixDefault := -1;
     288  if (bixDefault < 0) and (nBrain > bixFirstAI) then
     289    bixDefault := bixFirstAI; // default AI not found, use any
     290
     291  DirectDlg.left := (screen.width - DirectDlg.width) div 2;
     292  DirectDlg.top := (screen.height - DirectDlg.height) div 2;
     293
     294  if FullScreen then
     295  begin
     296    left := (screen.width - 800) * 3 div 8;
     297    top := screen.height - ClientHeight - (screen.height - 600) div 3;
     298
     299    r0 := CreateRectRgn(0, 0, ClientWidth, ClientHeight);
     300    r1 := CreateRectRgn(TabOffset + 4 * TabSize + 2, 0, ClientWidth, TabHeight);
     301    CombineRgn(r0, r0, r1, RGN_DIFF);
     302    // DeleteObject(r1);
     303    r1 := CreateRectRgn(QuitBtn.left, QuitBtn.top, QuitBtn.left + QuitBtn.width,
     304      QuitBtn.top + QuitBtn.height);
     305    CombineRgn(r0, r0, r1, RGN_OR);
     306    // DeleteObject(r1);
     307    SetWindowRgn(Handle, r0, false);
     308    // DeleteObject(r0); // causes crash with Windows 95
     309  end
     310  else
     311  begin
     312    left := (screen.width - width) div 2;
     313    top := (screen.height - height) div 2;
     314  end;
     315
     316  Canvas.Font.Assign(UniFont[ftNormal]);
     317  Canvas.Brush.Style := bsClear;
     318
     319  QuitBtn.Hint := Phrases.Lookup('STARTCONTROLS', 0);
     320  ReplayBtn.Hint := Phrases.Lookup('BTN_REPLAY');
     321  for i := 0 to nPlOffered - 1 do
     322  begin
     323    DiffUpBtn[i] := TButtonC.Create(self);
     324    DiffUpBtn[i].Graphic := GrExt[HGrSystem].Data;
     325    DiffUpBtn[i].left := xBrain[i] - 18;
     326    DiffUpBtn[i].top := yBrain[i] + 39;
     327    DiffUpBtn[i].ButtonIndex := 1;
     328    DiffUpBtn[i].Parent := self;
     329    DiffUpBtn[i].OnClick := DiffBtnClick;
     330    DiffDownBtn[i] := TButtonC.Create(self);
     331    DiffDownBtn[i].Graphic := GrExt[HGrSystem].Data;
     332    DiffDownBtn[i].left := xBrain[i] - 18;
     333    DiffDownBtn[i].top := yBrain[i] + 51;
     334    DiffDownBtn[i].ButtonIndex := 0;
     335    DiffDownBtn[i].Parent := self;
     336    DiffDownBtn[i].OnClick := DiffBtnClick;
     337  end;
     338  for i := 6 to 8 do
     339  begin
     340    MultiBtn[i] := TButtonC.Create(self);
     341    MultiBtn[i].Graphic := GrExt[HGrSystem].Data;
     342    MultiBtn[i].left := xBrain[i] - 18;
     343    MultiBtn[i].top := yBrain[i];
     344    MultiBtn[i].Parent := self;
     345    MultiBtn[i].OnClick := MultiBtnClick;
     346  end;
     347
     348  x := BiColorTextWidth(Canvas, Phrases.Lookup('STARTCONTROLS', 7)) div 2;
     349  CustomizeBtn.left := x0Brain + 32 - 16 - x;
     350  if AutoDiff < 0 then
     351    CustomizeBtn.ButtonIndex := 3
     352  else
     353    CustomizeBtn.ButtonIndex := 2;
     354
     355  BrainPicture[0] := TBitmap.Create;
     356  BrainPicture[0].width := 64;
     357  BrainPicture[0].height := 64;
     358  BitBlt(BrainPicture[0].Canvas.Handle, 0, 0, 64, 64,
     359    GrExt[HGrSystem2].Data.Canvas.Handle, 1, 111, SRCCOPY);
     360  BrainPicture[1] := TBitmap.Create;
     361  BrainPicture[1].width := 64;
     362  BrainPicture[1].height := 64;
     363  BitBlt(BrainPicture[1].Canvas.Handle, 0, 0, 64, 64,
     364    GrExt[HGrSystem2].Data.Canvas.Handle, 66, 111, SRCCOPY);
     365  BrainPicture[2] := TBitmap.Create;
     366  BrainPicture[2].width := 64;
     367  BrainPicture[2].height := 64;
     368  BitBlt(BrainPicture[2].Canvas.Handle, 0, 0, 64, 64,
     369    GrExt[HGrSystem2].Data.Canvas.Handle, 131, 111, SRCCOPY);
     370  BrainPicture[3] := TBitmap.Create;
     371  BrainPicture[3].width := 64;
     372  BrainPicture[3].height := 64;
     373  BitBlt(BrainPicture[3].Canvas.Handle, 0, 0, 64, 64,
     374    GrExt[HGrSystem2].Data.Canvas.Handle, 131, 46, SRCCOPY);
     375  for i := bixFirstAI to nBrain - 1 do
     376  begin
     377    BrainPicture[i] := TBitmap.Create;
     378    if not LoadGraphicFile(BrainPicture[i], HomeDir + Brain[i].FileName,
     379      gfNoError) then
     380    begin
     381      BrainPicture[i].width := 64;
     382      BrainPicture[i].height := 64;
     383      with BrainPicture[i].Canvas do
     384      begin
     385        Brush.Color := $904830;
     386        FillRect(Rect(0, 0, 64, 64));
     387        Font.Assign(UniFont[ftTiny]);
     388        Font.Style := [];
     389        Font.Color := $5FDBFF;
     390        Textout(32 - TextWidth(Brain[i].FileName) div 2,
     391          32 - TextHeight(Brain[i].FileName) div 2, Brain[i].FileName);
    362392      end
    363393    end
    364394  end;
    365395
    366 EmptyPicture:=TBitmap.Create;
    367 EmptyPicture.PixelFormat:=pf24bit;
    368 EmptyPicture.Width:=64; EmptyPicture.Height:=64;
    369 LogoBuffer:=TBitmap.Create;
    370 LogoBuffer.PixelFormat:=pf24bit;
    371 LogoBuffer.Width:=wBuffer; LogoBuffer.Height:=56;
    372 
    373 Mini:=TBitmap.Create;
    374 for x:=0 to 11 do for y:=0 to 1 do
    375   MiniColors[x,y]:=GrExt[HGrSystem].Data.Canvas.Pixels[66+x,67+y];
    376 InitButtons();
    377 
    378 bixView[0]:=bixTerm;
    379 SlotAvailable:=-1;
    380 Tab:=2;
    381 Diff0:=2;
    382 TurnValid:=false;
    383 Tracking:=false;
    384 FormerGames:=TStringList.Create;
    385 UpdateFormerGames;
    386 ShowTab:=2; // always start with new book page
    387 MapFileName:='';
    388 Maps:=TStringList.Create;
    389 UpdateMaps;
    390 end;
    391 
    392 procedure TStartDlg.FormDestroy(Sender:TObject);
    393 var
    394 i: integer;
    395 begin
    396 FormerGames.Free;
    397 Maps.Free;
    398 Mini.Free;
    399 EmptyPicture.Free;
    400 LogoBuffer.Free;
    401 for i:=0 to nBrain-1 do
    402   BrainPicture[i].Free;
    403 end;
    404 
    405 procedure TStartDlg.SmartInvalidate(x0,y0,x1,y1: integer; InvalidateTab0: boolean);
    406 var
    407 i: integer;
    408 r0,r1: HRgn;
    409 begin
    410 r0:=CreateRectRgn(x0,y0,x1,y1);
    411 for i:=0 to ControlCount-1 do
    412   if not (Controls[i] is TArea) and Controls[i].Visible then
    413     begin
    414     with Controls[i].BoundsRect do
    415       r1:=CreateRectRgn(Left,Top,Right,Bottom);
    416     CombineRgn(r0,r0,r1,RGN_DIFF);
     396  EmptyPicture := TBitmap.Create;
     397  EmptyPicture.PixelFormat := pf24bit;
     398  EmptyPicture.width := 64;
     399  EmptyPicture.height := 64;
     400  LogoBuffer := TBitmap.Create;
     401  LogoBuffer.PixelFormat := pf24bit;
     402  LogoBuffer.width := wBuffer;
     403  LogoBuffer.height := 56;
     404
     405  Mini := TBitmap.Create;
     406  for x := 0 to 11 do
     407    for y := 0 to 1 do
     408      MiniColors[x, y] := GrExt[HGrSystem].Data.Canvas.Pixels[66 + x, 67 + y];
     409  InitButtons();
     410
     411  bixView[0] := bixTerm;
     412  SlotAvailable := -1;
     413  Tab := 2;
     414  Diff0 := 2;
     415  TurnValid := false;
     416  Tracking := false;
     417  FormerGames := TStringList.Create;
     418  UpdateFormerGames;
     419  ShowTab := 2; // always start with new book page
     420  MapFileName := '';
     421  Maps := TStringList.Create;
     422  UpdateMaps;
     423end;
     424
     425procedure TStartDlg.FormDestroy(Sender: TObject);
     426var
     427  i: integer;
     428begin
     429  FormerGames.Free;
     430  Maps.Free;
     431  Mini.Free;
     432  EmptyPicture.Free;
     433  LogoBuffer.Free;
     434  for i := 0 to nBrain - 1 do
     435    BrainPicture[i].Free;
     436end;
     437
     438procedure TStartDlg.SmartInvalidate(x0, y0, x1, y1: integer;
     439  invalidateTab0: boolean);
     440var
     441  i: integer;
     442  r0, r1: HRgn;
     443begin
     444  r0 := CreateRectRgn(x0, y0, x1, y1);
     445  for i := 0 to ControlCount - 1 do
     446    if not(Controls[i] is TArea) and Controls[i].Visible then
     447    begin
     448      with Controls[i].BoundsRect do
     449        r1 := CreateRectRgn(left, top, Right, Bottom);
     450      CombineRgn(r0, r0, r1, RGN_DIFF);
     451      DeleteObject(r1);
     452    end;
     453  if not invalidateTab0 then
     454  begin
     455    r1 := CreateRectRgn(0, 0, 6 + 36, 3 + 38); // tab 0 icon
     456    CombineRgn(r0, r0, r1, RGN_DIFF);
    417457    DeleteObject(r1);
     458  end;
     459  InvalidateRgn(Handle, r0, false);
     460  DeleteObject(r0);
     461end;
     462
     463procedure TStartDlg.FormPaint(Sender: TObject);
     464const
     465  TabNames: array [0 .. 3] of integer = (0, 11, 3, 4);
     466
     467  procedure DrawAction(y, IconIndex: integer; HeaderItem, TextItem: string);
     468  begin
     469    Canvas.Font.Assign(UniFont[ftCaption]);
     470    Canvas.Font.Style := Canvas.Font.Style + [fsUnderline];
     471    RisedTextOut(Canvas, xAction, y - 3, Phrases2.Lookup(HeaderItem));
     472    Canvas.Font.Assign(UniFont[ftNormal]);
     473    BiColorTextOut(Canvas, Colors.Canvas.Pixels[clkAge0 - 1, cliDimmedText],
     474      $000000, xAction, y + 21, Phrases2.Lookup(TextItem));
     475    BitBlt(LogoBuffer.Canvas.Handle, 0, 0, 50, 50, Canvas.Handle,
     476      xActionIcon - 2, y - 2, SRCCOPY);
     477    GlowFrame(LogoBuffer, 8, 8, 34, 34, $202020);
     478    BitBlt(Canvas.Handle, xActionIcon - 2, y - 2, 50, 50,
     479      LogoBuffer.Canvas.Handle, 0, 0, SRCCOPY);
     480    BitBlt(Canvas.Handle, xActionIcon, y, 40, 40, BigImp.Canvas.Handle,
     481      (IconIndex mod 7) * xSizeBig + 8, (IconIndex div 7) * ySizeBig, SRCCOPY);
     482    RFrame(Canvas, xActionIcon - 1, y - 1, xActionIcon + 40, y + 40,
     483      $000000, $000000);
     484  end;
     485
     486var
     487  i, w, h, xMini, yMini, y: integer;
     488  s: string;
     489begin
     490  PaintBackground(self, 3, 3, TabOffset + 4 * TabSize - 4, TabHeight - 3);
     491  PaintBackground(self, 3, TabHeight + 3, ClientWidth - 6,
     492    ClientHeight - TabHeight - 6);
     493  with Canvas do
     494  begin
     495    Brush.Color := $000000;
     496    FillRect(Rect(0, 1, ClientWidth, 3));
     497    FillRect(Rect(TabOffset + 4 * TabSize + 2, 0, ClientWidth, TabHeight));
     498    Brush.Style := bsClear;
     499  end;
     500  if Page in [pgStartRandom, pgStartMap] then
     501  begin
     502    Frame(Canvas, 328, yMain + 112 - 15, ClientWidth, Up2Btn.top + 38,
     503      MainTexture.clBevelShade, MainTexture.clBevelLight);
     504    if AutoDiff > 0 then
     505    begin
     506      Frame(Canvas, -1 { x0Brain-dxBrain } ,
     507        yMain + 112 - 15 { Up1Btn.Top-12 }{ y0Brain-dyBrain } ,
     508        x0Brain + dxBrain + 64, Up2Btn.top + 38 { y0Brain+dyBrain+64 } ,
     509        MainTexture.clBevelShade, MainTexture.clBevelLight);
     510    end
     511  end
     512  else if Page <> pgMain then
     513    Frame(Canvas, 328, Up1Btn.top - 15, ClientWidth, Up2Btn.top + 38,
     514      MainTexture.clBevelShade, MainTexture.clBevelLight);
     515  Frame(Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
     516
     517  // draw tabs
     518  Frame(Canvas, 2, 2 + 2 * integer(Tab <> 0), TabOffset + (0 + 1) * TabSize - 1,
     519    TabHeight, MainTexture.clBevelLight, MainTexture.clBevelShade);
     520  Frame(Canvas, 1, 1 + 2 * integer(Tab <> 0), TabOffset + (0 + 1) * TabSize,
     521    TabHeight, MainTexture.clBevelLight, MainTexture.clBevelShade);
     522  Canvas.Pixels[1, 1 + 2 * integer(Tab <> 0)] := MainTexture.clBevelShade;
     523  for i := 1 to 3 do
     524  begin
     525    Frame(Canvas, TabOffset + i * TabSize + 2, 2 + 2 * integer(Tab <> i),
     526      TabOffset + (i + 1) * TabSize - 1, TabHeight, MainTexture.clBevelLight,
     527      MainTexture.clBevelShade);
     528    Frame(Canvas, TabOffset + i * TabSize + 1, 1 + 2 * integer(Tab <> i),
     529      TabOffset + (i + 1) * TabSize, TabHeight, MainTexture.clBevelLight,
     530      MainTexture.clBevelShade);
     531    Canvas.Pixels[TabOffset + i * TabSize + 1, 1 + 2 * integer(Tab <> i)] :=
     532      MainTexture.clBevelShade;
     533  end;
     534  Canvas.Font.Assign(UniFont[ftNormal]);
     535  for i := 1 to 3 do
     536  begin
     537    s := Phrases.Lookup('STARTCONTROLS', TabNames[i]);
     538    RisedTextOut(Canvas, TabOffset + i * TabSize + 1 +
     539      (TabSize - BiColorTextWidth(Canvas, s)) div 2,
     540      10 + 2 * integer(Tab <> i), s);
     541  end;
     542  Frame(Canvas, TabOffset + 4 * TabSize + 1, -1, ClientWidth, TabHeight,
     543    $000000, $000000);
     544  Frame(Canvas, 1, TabHeight + 1, ClientWidth - 2, ClientHeight - 2,
     545    MainTexture.clBevelLight, MainTexture.clBevelShade);
     546  Frame(Canvas, 2, TabHeight + 2, ClientWidth - 3, ClientHeight - 3,
     547    MainTexture.clBevelLight, MainTexture.clBevelShade);
     548  if Tab = 0 then
     549  begin
     550    PaintBackground(self, 3, TabHeight - 1, TabSize - 4 - 3 + TabOffset + 3, 4);
     551    Canvas.Pixels[2, TabHeight] := MainTexture.clBevelLight;
     552  end
     553  else
     554  begin
     555    PaintBackground(self, TabOffset + 3 + Tab * TabSize, TabHeight - 1,
     556      TabSize - 4, 4);
     557    Canvas.Pixels[TabOffset + Tab * TabSize + 2, TabHeight] :=
     558      MainTexture.clBevelLight;
     559  end;
     560  Canvas.Pixels[TabOffset + (Tab + 1) * TabSize - 1, TabHeight + 1] :=
     561    MainTexture.clBevelShade;
     562  if Tab < 3 then
     563    Frame(Canvas, TabOffset + (Tab + 1) * TabSize + 1, 3,
     564      TabOffset + (Tab + 1) * TabSize + 2, TabHeight, MainTexture.clBevelShade,
     565      MainTexture.clBevelShade); // Tab shadow
     566  BitBlt(LogoBuffer.Canvas.Handle, 0, 0, 36, 36, Canvas.Handle, 6,
     567    3 + 2 * integer(Tab <> 0), SRCCOPY);
     568  ImageOp_BCC(LogoBuffer, Templates, 0, 0, 145, 38, 36, 27, $BFBF20, $4040DF);
     569  // logo part 1
     570  ImageOp_BCC(LogoBuffer, Templates, 10, 27, 155, 38 + 27, 26, 9, $BFBF20,
     571    $4040DF); // logo part 2
     572  BitBlt(Canvas.Handle, 6, 3 + 2 * integer(Tab <> 0), 36, 36,
     573    LogoBuffer.Canvas.Handle, 0, 0, SRCCOPY);
     574
     575  if Page = pgMain then
     576  begin
     577    if SelectedAction >= 0 then // mark selected action
     578      for i := 0 to (ClientWidth - 2 * ActionSideBorder) div wBuffer + 1 do
     579      begin
     580        w := ClientWidth - 2 * ActionSideBorder - i * wBuffer;
     581        if w > wBuffer then
     582          w := wBuffer;
     583        h := ActionPitch;
     584        if yAction + SelectedAction * ActionPitch - 8 + h > ClientHeight - ActionBottomBorder
     585        then
     586          h := ClientHeight - ActionBottomBorder -
     587            (yAction + SelectedAction * ActionPitch - 8);
     588        BitBlt(LogoBuffer.Canvas.Handle, 0, 0, w, h, Canvas.Handle,
     589          ActionSideBorder + i * wBuffer, yAction + SelectedAction * ActionPitch
     590          - 8, SRCCOPY);
     591        MakeBlue(LogoBuffer, 0, 0, w, h);
     592        BitBlt(Canvas.Handle, ActionSideBorder + i * wBuffer,
     593          yAction + SelectedAction * ActionPitch - 8, w, h,
     594          LogoBuffer.Canvas.Handle, 0, 0, SRCCOPY);
     595      end;
     596    y := yAction;
     597    for i := 0 to nMainActions - 1 do
     598    begin
     599      if i in ActionsOffered then
     600        case i of
     601          maConfig:
     602            DrawAction(y, 25, 'ACTIONHEADER_CONFIG', 'ACTION_CONFIG');
     603          maManual:
     604            DrawAction(y, 19, 'ACTIONHEADER_MANUAL', 'ACTION_MANUAL');
     605          maCredits:
     606            DrawAction(y, 22, 'ACTIONHEADER_CREDITS', 'ACTION_CREDITS');
     607          maAIDev:
     608            DrawAction(y, 24, 'ACTIONHEADER_AIDEV', 'ACTION_AIDEV');
     609          maWeb:
     610            begin
     611              Canvas.Font.Assign(UniFont[ftCaption]);
     612              // Canvas.Font.Style:=Canvas.Font.Style+[fsUnderline];
     613              RisedTextOut(Canvas, xActionIcon + 99, y,
     614                Phrases2.Lookup('ACTIONHEADER_WEB'));
     615              Canvas.Font.Assign(UniFont[ftNormal]);
     616              BitBlt(LogoBuffer.Canvas.Handle, 0, 0, 91, 25, Canvas.Handle,
     617                xActionIcon, y + 2, SRCCOPY);
     618              ImageOp_BCC(LogoBuffer, Templates, 0, 0, 1, 400, 91, 25, 0,
     619                Colors.Canvas.Pixels[clkAge0 - 1, cliDimmedText]);
     620              BitBlt(Canvas.Handle, xActionIcon, y + 2, 91, 25,
     621                LogoBuffer.Canvas.Handle, 0, 0, SRCCOPY);
     622            end;
     623        end;
     624      inc(y, ActionPitch);
     625    end
     626  end
     627  else if Page in [pgStartRandom, pgStartMap] then
     628  begin
     629    DLine(Canvas, 344, 514, y0Mini + 61 + 19, MainTexture.clBevelLight,
     630      MainTexture.clBevelShade);
     631    RisedTextOut(Canvas, 344, y0Mini + 61, Phrases.Lookup('STARTCONTROLS', 10));
     632    s := TurnToString(MaxTurn);
     633    RisedTextOut(Canvas, 514 - BiColorTextWidth(Canvas, s), y0Mini + 61, s);
     634    s := Phrases.Lookup('STARTCONTROLS', 7);
     635    w := Canvas.TextWidth(s);
     636    LoweredTextOut(Canvas, -2, MainTexture, x0Brain + 32 - w div 2,
     637      y0Brain + dyBrain + 69, s);
     638
     639    InitOrnament;
     640    if AutoDiff < 0 then
     641    begin
     642      for i := 12 to 19 do
     643        if (i < 13) or (i > 17) then
     644        begin
     645          BitBlt(Canvas.Handle, 9 + i * 27, yLogo - 2, wOrna, hOrna,
     646            GrExt[HGrSystem2].Mask.Canvas.Handle, xOrna, yOrna, SRCAND);
     647          BitBlt(Canvas.Handle, 9 + i * 27, yLogo - 2, wOrna, hOrna,
     648            GrExt[HGrSystem2].Data.Canvas.Handle, xOrna, yOrna, SRCPAINT);
     649        end;
     650      PaintLogo(Canvas, 69 + 11 * 27, yLogo, MainTexture.clBevelLight,
     651        MainTexture.clBevelShade);
     652
     653      for i := 0 to nPlOffered - 1 do
     654        if 1 shl i and SlotAvailable <> 0 then
     655        begin
     656          if bixView[i] >= 0 then
     657            FrameImage(Canvas, BrainPicture[bixView[i]], xBrain[i], yBrain[i],
     658              64, 64, 0, 0, true)
     659          else
     660            FrameImage(Canvas, EmptyPicture, xBrain[i], yBrain[i], 64, 64,
     661              0, 0, true);
     662          if bixView[i] >= bixTerm then
     663          begin
     664            BitBlt(Canvas.Handle, xBrain[i] - 18, yBrain[i] + 19, 12, 14,
     665              GrExt[HGrSystem].Data.Canvas.Handle, 134 + (Difficulty[i] - 1) *
     666              13, 28, SRCCOPY);
     667            Frame(Canvas, xBrain[i] - 19, yBrain[i] + 18, xBrain[i] - 18 + 12,
     668              yBrain[i] + (19 + 14), $000000, $000000);
     669            RFrame(Canvas, DiffUpBtn[i].left - 1, DiffUpBtn[i].top - 1,
     670              DiffUpBtn[i].left + 12, DiffUpBtn[i].top + 24,
     671              MainTexture.clBevelShade, MainTexture.clBevelLight);
     672            with Canvas do
     673            begin
     674              Brush.Color := $000000;
     675              FillRect(Rect(xBrain[i] - 5, yBrain[i] + 25, xBrain[i] - 2,
     676                yBrain[i] + 27));
     677              Brush.Style := bsClear;
     678            end;
     679            if i in OfferMultiple then
     680            begin
     681              RFrame(Canvas, MultiBtn[i].left - 1, MultiBtn[i].top - 1,
     682                MultiBtn[i].left + 12, MultiBtn[i].top + 12,
     683                MainTexture.clBevelShade, MainTexture.clBevelLight);
     684              BitBlt(Canvas.Handle, xBrain[i] - 31, yBrain[i], 13, 12,
     685                GrExt[HGrSystem].Data.Canvas.Handle, 88, 47, SRCCOPY);
     686            end
     687          end;
     688          if bixView[i] >= 0 then
     689          begin
     690            DiffUpBtn[i].Hint := Format(Phrases.Lookup('STARTCONTROLS', 9),
     691              [Brain[bixView[i]].Name]);
     692            DiffDownBtn[i].Hint := DiffUpBtn[i].Hint;
     693          end
     694        end;
     695    end
     696    else
     697    begin
     698      DLine(Canvas, 24, 198, yMain + 140 + 19, MainTexture.clBevelLight,
     699        MainTexture.clBevelShade);
     700      RisedTextOut(Canvas, 24 { x0Brain+32-BiColorTextWidth(Canvas,s) div 2 } ,
     701        yMain + 140 { y0Mini-77 } , Phrases.Lookup('STARTCONTROLS', 15));
     702      if Page = pgStartRandom then
     703        s := IntToStr(AutoEnemies)
     704      else if nMapStartPositions = 0 then
     705        s := '0'
     706      else
     707        s := IntToStr(nMapStartPositions - 1);
     708      RisedTextOut(Canvas, 198 - BiColorTextWidth(Canvas, s), yMain + 140, s);
     709      DLine(Canvas, 24, xDefault - 6, yMain + 164 + 19,
     710        MainTexture.clBevelLight, MainTexture.clBevelShade);
     711      RisedTextOut(Canvas, 24 { x0Brain+32-BiColorTextWidth(Canvas,s) div 2 } ,
     712        yMain + 164 { y0Mini-77 } , Phrases.Lookup('STARTCONTROLS', 16));
     713      if AutoDiff = 1 then
     714        FrameImage(Canvas, BrainPicture[bixBeginner], xDefault, yDefault, 64,
     715          64, 0, 0, false)
     716      else
     717        FrameImage(Canvas, BrainPicture[bixDefault], xDefault, yDefault, 64, 64,
     718          0, 0, true);
     719      DLine(Canvas, 56, 272, y0Mini + 61 + 19, MainTexture.clBevelLight,
     720        MainTexture.clBevelShade);
     721      RisedTextOut(Canvas, 56, y0Mini + 61,
     722        Phrases.Lookup('STARTCONTROLS', 14));
     723      s := Phrases.Lookup('AUTODIFF', AutoDiff - 1);
     724      RisedTextOut(Canvas, 272 - BiColorTextWidth(Canvas, s), y0Mini + 61, s);
     725
     726      for i := 0 to 19 do
     727        if (i < 2) or (i > 6) then
     728        begin
     729          BitBlt(Canvas.Handle, 9 + i * 27, yLogo - 2, wOrna, hOrna,
     730            GrExt[HGrSystem2].Mask.Canvas.Handle, xOrna, yOrna, SRCAND);
     731          BitBlt(Canvas.Handle, 9 + i * 27, yLogo - 2, wOrna, hOrna,
     732            GrExt[HGrSystem2].Data.Canvas.Handle, xOrna, yOrna, SRCPAINT);
     733        end;
     734      PaintLogo(Canvas, 69, yLogo, MainTexture.clBevelLight,
     735        MainTexture.clBevelShade);
     736    end
     737  end
     738  else if Page = pgLoad then
     739  begin
     740    // RisedTextOut(Canvas,x0Mini+2-BiColorTextWidth(Canvas,BookDate) div 2,y0Mini-73,BookDate);
     741    if LastTurn > 0 then
     742    begin
     743      PaintProgressBar(Canvas, 6, xTurnSlider, yTurnSlider, 0,
     744        LoadTurn * wTurnSlider div LastTurn, wTurnSlider, MainTexture);
     745      Frame(Canvas, xTurnSlider - 2, yTurnSlider - 2, xTurnSlider + wTurnSlider
     746        + 1, yTurnSlider + 8, $B0B0B0, $FFFFFF);
     747      RFrame(Canvas, xTurnSlider - 3, yTurnSlider - 3, xTurnSlider + wTurnSlider
     748        + 2, yTurnSlider + 9, $FFFFFF, $B0B0B0);
     749    end
     750    else
     751      DLine(Canvas, 344, 514, y0Mini + 61 + 19, MainTexture.clBevelLight,
     752        MainTexture.clBevelShade);
     753    RisedTextOut(Canvas, 344, y0Mini + 61, Phrases.Lookup('STARTCONTROLS', 8));
     754    s := TurnToString(LoadTurn);
     755    RisedTextOut(Canvas, 514 - BiColorTextWidth(Canvas, s), y0Mini + 61, s);
     756  end
     757  else if Page = pgEditRandom then
     758  begin
     759    DLine(Canvas, 344, 514, y0Mini - 77 + 19, MainTexture.clBevelLight,
     760      MainTexture.clBevelShade);
     761    RisedTextOut(Canvas, 344, y0Mini - 77, Phrases.Lookup('STARTCONTROLS', 5));
     762    s := IntToStr((lxpre[WorldSize] * lypre[WorldSize] * 20 +
     763      DefaultWorldTiles div 2) div DefaultWorldTiles * 5) + '%';
     764    RisedTextOut(Canvas, 514 - BiColorTextWidth(Canvas, s), y0Mini - 77, s);
     765    DLine(Canvas, 344, 514, y0Mini + 61 + 19, MainTexture.clBevelLight,
     766      MainTexture.clBevelShade);
     767    RisedTextOut(Canvas, 344, y0Mini + 61, Phrases.Lookup('STARTCONTROLS', 6));
     768    s := IntToStr(StartLandMass) + '%';
     769    RisedTextOut(Canvas, 514 - BiColorTextWidth(Canvas, s), y0Mini + 61, s);
     770  end
     771  else if Page = pgEditMap then
     772  begin
     773    // DLine(Canvas,344,514,y0Mini+61+19,MainTexture.clBevelLight,MainTexture.clBevelShade);
     774    s := Format(Phrases2.Lookup('MAPPROP'),
     775      [(nMapLandTiles * 100 + 556) div 1112,
     776      // 1112 is typical for world with 100% size and default land mass
     777      nMapStartPositions]);
     778    RisedTextOut(Canvas, x0Mini - BiColorTextWidth(Canvas, s) div 2,
     779      y0Mini + 61, s);
     780  end;
     781
     782  if StartBtn.Visible then
     783    BtnFrame(Canvas, StartBtn.BoundsRect, MainTexture);
     784  if Up2Btn.Visible then
     785    RFrame(Canvas, Up2Btn.left - 1, Up2Btn.top - 1, Up2Btn.left + 12,
     786      Up2Btn.top + 24, MainTexture.clBevelShade, MainTexture.clBevelLight);
     787  if Up1Btn.Visible then
     788    RFrame(Canvas, Up1Btn.left - 1, Up1Btn.top - 1, Up1Btn.left + 12,
     789      Up1Btn.top + 24, MainTexture.clBevelShade, MainTexture.clBevelLight);
     790  if AutoDiffUpBtn.Visible then
     791    RFrame(Canvas, AutoDiffUpBtn.left - 1, AutoDiffUpBtn.top - 1,
     792      AutoDiffUpBtn.left + 12, AutoDiffUpBtn.top + 24, MainTexture.clBevelShade,
     793      MainTexture.clBevelLight);
     794  if AutoEnemyUpBtn.Visible then
     795    RFrame(Canvas, AutoEnemyUpBtn.left - 1, AutoEnemyUpBtn.top - 1,
     796      AutoEnemyUpBtn.left + 12, AutoEnemyUpBtn.top + 24,
     797      MainTexture.clBevelShade, MainTexture.clBevelLight);
     798  if CustomizeBtn.Visible then
     799    RFrame(Canvas, CustomizeBtn.left - 1, CustomizeBtn.top - 1,
     800      CustomizeBtn.left + 12, CustomizeBtn.top + 12, MainTexture.clBevelShade,
     801      MainTexture.clBevelLight);
     802  if List.Visible then
     803    EditFrame(Canvas, List.BoundsRect, MainTexture);
     804  if RenameBtn.Visible then
     805    BtnFrame(Canvas, RenameBtn.BoundsRect, MainTexture);
     806  if DeleteBtn.Visible then
     807    BtnFrame(Canvas, DeleteBtn.BoundsRect, MainTexture);
     808  if Page = pgLoad then
     809    BtnFrame(Canvas, ReplayBtn.BoundsRect, MainTexture);
     810
     811  if not(Page in [pgMain, pgNoLoad]) then
     812  begin
     813    xMini := x0Mini - MiniWidth;
     814    yMini := y0Mini - MiniHeight div 2;
     815    Frame(Canvas, xMini, yMini, xMini + 3 + MiniWidth * 2,
     816      yMini + 3 + MiniHeight, MainTexture.clBevelLight,
     817      MainTexture.clBevelShade);
     818    Frame(Canvas, xMini + 1, yMini + 1, xMini + 2 + MiniWidth * 2,
     819      yMini + 2 + MiniHeight, MainTexture.clBevelShade,
     820      MainTexture.clBevelLight);
     821  end;
     822  s := '';
     823  if MiniMode = mmPicture then
     824  begin
     825    BitBlt(Canvas.Handle, xMini + 2, yMini + 2, MiniWidth * 2, MiniHeight,
     826      Mini.Canvas.Handle, 0, 0, SRCCOPY);
     827    if Page = pgStartRandom then
     828      s := Phrases.Lookup('RANMAP')
     829  end
     830  else if MiniMode = mmMultiPlayer then
     831    s := Phrases.Lookup('MPMAP')
     832  else if Page = pgStartMap then
     833    s := Copy(MapFileName, 1, Length(MapFileName) - 9)
     834  else if Page = pgEditMap then
     835    s := List.Items[List.ItemIndex]
     836  else if Page = pgNoLoad then
     837    s := Phrases.Lookup('NOGAMES');
     838  if s <> '' then
     839    RisedTextOut(Canvas, x0Mini + 2 - BiColorTextWidth(Canvas, s) div 2,
     840      y0Mini - 8, s);
     841end;
     842
     843procedure TStartDlg.FormShow(Sender: TObject);
     844type
     845  TLine = array [0 .. 99999999] of Byte;
     846var
     847  i, x, y: integer;
     848  PictureLine: ^TLine;
     849begin
     850  SetMainTextureByAge(-1);
     851  List.Font.Color := MainTexture.clMark;
     852  Fill(EmptyPicture.Canvas, 0, 0, 64, 64, (wMaintexture - 64) div 2,
     853    (hMaintexture - 64) div 2);
     854  for y := 0 to 63 do
     855  begin // darken texture for empty slot
     856    PictureLine := EmptyPicture.ScanLine[y];
     857    for x := 0 to 64 * 3 - 1 do
     858    begin
     859      i := integer(PictureLine[x]) - 28;
     860      if i < 0 then
     861        i := 0;
     862      PictureLine[x] := i;
     863    end
     864  end;
     865
     866  Difficulty[0] := Diff0;
     867
     868  SelectedAction := -1;
     869  if ShowTab = 3 then
     870    PreviewMap(StartLandMass); // avoid delay on first TabX change
     871  ChangeTab(ShowTab);
     872  Background.Enabled := false;
     873end;
     874
     875procedure TStartDlg.UnlistBackupFile(FileName: string);
     876var
     877  i: integer;
     878begin
     879  if FileName[1] <> '~' then
     880    FileName := '~' + FileName;
     881  i := FormerGames.Count - 1;
     882  while (i >= 0) and (AnsiCompareFileName(FormerGames[i], FileName) <> 0) do
     883    dec(i);
     884  if i >= 0 then
     885  begin
     886    FormerGames.Delete(i);
     887    if ListIndex[2] = i then
     888      ListIndex[2] := 0
     889  end
     890end;
     891
     892procedure TStartDlg.StartBtnClick(Sender: TObject);
     893var
     894  i, GameCount, MapCount: integer;
     895  FileName: string;
     896  Reg: TRegistry;
     897begin
     898  case Page of
     899    pgLoad:
     900      begin // load
     901        FileName := List.Items[List.ItemIndex];
     902        if LoadGame(DataDir + 'Saved\', FileName + '.cevo', LoadTurn, false)
     903        then
     904          UnlistBackupFile(FileName)
     905        else
     906          SimpleMessage(Phrases.Lookup('LOADERR'));
     907        SlotAvailable := -1;
     908      end;
     909
     910    pgStartRandom, pgStartMap:
     911      if bixView[0] >= 0 then
     912      begin
     913        if (Page = pgStartMap) and (nMapStartPositions = 0) and (AutoDiff > 0)
     914        then
     915        begin
     916          SimpleMessage(Phrases.Lookup('NOSTARTPOS'));
     917          exit
     918        end;
     919
     920        Reg := TRegistry.Create;
     921        Reg.OpenKey('SOFTWARE\cevo\RegVer9\Start', true);
     922        try
     923          GameCount := Reg.ReadInteger('GameCount');
     924        except
     925          GameCount := 0;
     926        end;
     927
     928        if (AutoDiff < 0) and (bixView[0] = bixNoTerm) then
     929          FileName := 'Round' + IntToStr(GetCurrentProcessID())
     930        else
     931        begin
     932          inc(GameCount);
     933          FileName := Format(Phrases.Lookup('GAME'), [GameCount]);
     934        end;
     935
     936        // save settings and AI assignment
     937        if Page = pgStartRandom then
     938        begin
     939          Reg.WriteInteger('WorldSize', WorldSize);
     940          Reg.WriteInteger('LandMass', StartLandMass);
     941          if AutoDiff < 0 then
     942            for i := 0 to nPlOffered - 1 do
     943            begin
     944              if bixView[i] = -1 then
     945                Reg.WriteString('Control' + IntToStr(i), '')
     946              else
     947                Reg.WriteString('Control' + IntToStr(i),
     948                  Brain[bixView[i]].FileName);
     949              Reg.WriteInteger('Diff' + IntToStr(i), Difficulty[i]);
     950            end;
     951          Reg.WriteInteger('MultiControl', MultiControl);
     952        end;
     953
     954        if AutoDiff > 0 then
     955        begin
     956          Reg.WriteString('DefaultAI', Brain[bixDefault].FileName);
     957          SlotAvailable := 0; // bixView will be invalid hereafter
     958          bixView[0] := bixTerm;
     959          Difficulty[0] := PlayerAutoDiff[AutoDiff];
     960          for i := 1 to nPl - 1 do
     961            if (Page = pgStartRandom) and (i <= AutoEnemies) or
     962              (Page = pgStartMap) and (i < nMapStartPositions) then
     963            begin
     964              if AutoDiff = 1 then
     965                bixView[i] := bixBeginner
     966              else
     967                bixView[i] := bixDefault;
     968              Difficulty[i] := EnemyAutoDiff[AutoDiff];
     969            end
     970            else
     971              bixView[i] := -1;
     972        end
     973        else
     974        begin
     975          for i := 6 to 8 do
     976            if (bixView[0] <> bixNoTerm) and (MultiControl and (1 shl i) <> 0)
     977            then
     978            begin
     979              bixView[i + 3] := bixView[i];
     980              Difficulty[i + 3] := Difficulty[i];
     981              bixView[i + 6] := bixView[i];
     982              Difficulty[i + 6] := Difficulty[i];
     983            end
     984            else
     985            begin
     986              bixView[i + 3] := -1;
     987              bixView[i + 6] := -1;
     988            end
     989        end;
     990
     991        Reg.WriteInteger('AutoDiff', AutoDiff);
     992        Reg.WriteInteger('AutoEnemies', AutoEnemies);
     993        Reg.WriteInteger('MaxTurn', MaxTurn);
     994        Reg.WriteInteger('GameCount', GameCount);
     995        Reg.closekey;
     996        Reg.Free;
     997
     998        StartNewGame(DataDir + 'Saved\', FileName + '.cevo', MapFileName,
     999          lxpre[WorldSize], lypre[WorldSize], StartLandMass, MaxTurn);
     1000        UnlistBackupFile(FileName);
     1001      end;
     1002
     1003    pgEditMap:
     1004      EditMap(MapFileName, lxmax, lymax, StartLandMass);
     1005
     1006    pgEditRandom: // new map
     1007      begin
     1008        Reg := TRegistry.Create;
     1009        Reg.OpenKey('SOFTWARE\cevo\RegVer9\Start', true);
     1010        try
     1011          MapCount := Reg.ReadInteger('MapCount');
     1012        except
     1013          MapCount := 0;
     1014        end;
     1015        inc(MapCount);
     1016        Reg.WriteInteger('MapCount', MapCount);
     1017        Reg.closekey;
     1018        Reg.Free;
     1019        MapFileName := Format(Phrases.Lookup('MAP'), [MapCount]) + '.cevo map';
     1020        EditMap(MapFileName, lxpre[WorldSize], lypre[WorldSize], StartLandMass);
     1021      end
     1022  end
     1023end;
     1024
     1025procedure TStartDlg.PaintInfo;
     1026
     1027  procedure PaintRandomMini(Brightness: integer);
     1028  type
     1029    TLine = array [0 .. lxmax * 2, 0 .. 2] of Byte;
     1030  var
     1031    i, x, y, xm, cm: integer;
     1032    MiniLine: ^TLine;
     1033    Map: ^TTileList;
     1034  begin
     1035    Map := PreviewMap(StartLandMass);
     1036    MiniWidth := lxpre[WorldSize];
     1037    MiniHeight := lypre[WorldSize];
     1038
     1039    Mini.PixelFormat := pf24bit;
     1040    Mini.width := MiniWidth * 2;
     1041    Mini.height := MiniHeight;
     1042    for y := 0 to MiniHeight - 1 do
     1043    begin
     1044      MiniLine := Mini.ScanLine[y];
     1045      for x := 0 to MiniWidth - 1 do
     1046        for i := 0 to 1 do
     1047        begin
     1048          xm := (x * 2 + i + y and 1) mod (MiniWidth * 2);
     1049          cm := MiniColors
     1050            [Map[x * lxmax div MiniWidth + lxmax *
     1051            ((y * (lymax - 1) + MiniHeight div 2) div (MiniHeight - 1))] and
     1052            fTerrain, i];
     1053          MiniLine[xm, 0] := cm shr 16 * Brightness div 3;
     1054          MiniLine[xm, 1] := cm shr 8 and $FF * Brightness div 3;
     1055          MiniLine[xm, 2] := cm and $FF * Brightness div 3;
     1056        end;
    4181057    end;
    419 if not invalidateTab0 then
    420   begin
    421   r1:=CreateRectRgn(0,0,6+36,3+38); // tab 0 icon
    422   CombineRgn(r0,r0,r1,RGN_DIFF);
    423   DeleteObject(r1);
    424   end;
    425 InvalidateRgn(Handle,r0,false);
    426 DeleteObject(r0);
    427 end;
    428 
    429 procedure TStartDlg.FormPaint(Sender:TObject);
    430 const
    431 TabNames: array[0..3] of integer=(0,11,3,4);
    432 
    433   procedure DrawAction(y,IconIndex: integer; HeaderItem, TextItem: string);
    434   begin
    435   Canvas.Font.Assign(UniFont[ftCaption]);
    436   Canvas.Font.Style:=Canvas.Font.Style+[fsUnderline];
    437   RisedTextOut(Canvas,xAction,y-3,Phrases2.Lookup(HeaderItem));
    438   Canvas.Font.Assign(UniFont[ftNormal]);
    439   BiColorTextOut(Canvas,Colors.Canvas.Pixels[clkAge0-1,cliDimmedText],
    440     $000000,xAction,y+21,Phrases2.Lookup(TextItem));
    441   BitBlt(LogoBuffer.Canvas.Handle,0,0,50,50,Canvas.Handle,xActionIcon-2,y-2,SRCCOPY);
    442   GlowFrame(LogoBuffer,8,8,34,34,$202020);
    443   BitBlt(Canvas.Handle,xActionIcon-2,y-2,50,50,LogoBuffer.Canvas.Handle,0,0,SRCCOPY);
    444   BitBlt(Canvas.Handle,xActionIcon,y,40,40,BigImp.Canvas.Handle,(IconIndex mod 7)*xSizeBig+8,
    445     (IconIndex div 7)*ySizeBig, SRCCOPY);
    446   RFrame(Canvas,xActionIcon-1,y-1,xActionIcon+40,y+40,$000000,$000000);
    447   end;
    448 
    449 var
    450 i,w,h,xMini,yMini,y:integer;
    451 s: string;
    452 begin
    453 PaintBackground(self,3,3,TabOffset+4*TabSize-4,TabHeight-3);
    454 PaintBackground(self,3,TabHeight+3,ClientWidth-6,ClientHeight-TabHeight-6);
    455 with Canvas do
    456   begin
    457   Brush.Color:=$000000;
    458   FillRect(Rect(0,1,ClientWidth,3));
    459   FillRect(Rect(TabOffset+4*TabSize+2,0,ClientWidth,TabHeight));
    460   Brush.Style:=bsClear;
    461   end;
    462 if Page in [pgStartRandom,pgStartMap] then
    463   begin
    464   Frame(Canvas,328,yMain+112-15,ClientWidth,Up2Btn.Top+38,
    465     MainTexture.clBevelShade,MainTexture.clBevelLight);
    466   if AutoDiff>0 then
    467     begin
    468     Frame(Canvas,-1{x0Brain-dxBrain},yMain+112-15{Up1Btn.Top-12}{y0Brain-dyBrain},x0Brain+dxBrain+64,
    469       Up2Btn.Top+38{y0Brain+dyBrain+64}, MainTexture.clBevelShade,MainTexture.clBevelLight);
    470     end
    471   end
    472 else if Page<>pgMain then
    473   Frame(Canvas,328,Up1Btn.Top-15,ClientWidth,Up2Btn.Top+38,
    474     MainTexture.clBevelShade,MainTexture.clBevelLight);
    475 Frame(Canvas,0,0,ClientWidth-1,ClientHeight-1,0,0);
    476 
    477 // draw tabs
    478 Frame(Canvas,2,2+2*integer(Tab<>0),TabOffset+(0+1)*TabSize-1,TabHeight,MainTexture.clBevelLight,MainTexture.clBevelShade);
    479 Frame(Canvas,1,1+2*integer(Tab<>0),TabOffset+(0+1)*TabSize,TabHeight,MainTexture.clBevelLight,MainTexture.clBevelShade);
    480 Canvas.Pixels[1,1+2*integer(Tab<>0)]:=MainTexture.clBevelShade;
    481 for i:=1 to 3 do
    482   begin
    483   Frame(Canvas,TabOffset+i*TabSize+2,2+2*integer(Tab<>i),TabOffset+(i+1)*TabSize-1,TabHeight,MainTexture.clBevelLight,MainTexture.clBevelShade);
    484   Frame(Canvas,TabOffset+i*TabSize+1,1+2*integer(Tab<>i),TabOffset+(i+1)*TabSize,TabHeight,MainTexture.clBevelLight,MainTexture.clBevelShade);
    485   Canvas.Pixels[TabOffset+i*TabSize+1,1+2*integer(Tab<>i)]:=MainTexture.clBevelShade;
    486   end;
    487 Canvas.Font.Assign(UniFont[ftNormal]);
    488 for i:=1 to 3 do
    489   begin
    490   s:=Phrases.Lookup('STARTCONTROLS',TabNames[i]);
    491   RisedTextOut(Canvas,TabOffset+i*TabSize+1+(TabSize-BiColorTextWidth(Canvas,s)) div 2,
    492     10+2*integer(Tab<>i),s);
    493   end;
    494 Frame(Canvas,TabOffset+4*TabSize+1,-1,ClientWidth,TabHeight,$000000,$000000);
    495 Frame(Canvas,1,TabHeight+1,ClientWidth-2,ClientHeight-2,MainTexture.clBevelLight,
    496   MainTexture.clBevelShade);
    497 Frame(Canvas,2,TabHeight+2,ClientWidth-3,ClientHeight-3,MainTexture.clBevelLight,
    498   MainTexture.clBevelShade);
    499 if Tab=0 then
    500   begin
    501   PaintBackground(self,3,TabHeight-1,TabSize-4-3+TabOffset+3,4);
    502   Canvas.Pixels[2,TabHeight]:=MainTexture.clBevelLight;
    503   end
    504 else
    505   begin
    506   PaintBackground(self,TabOffset+3+Tab*TabSize,TabHeight-1,TabSize-4,4);
    507   Canvas.Pixels[TabOffset+Tab*TabSize+2,TabHeight]:=MainTexture.clBevelLight;
    508   end;
    509 Canvas.Pixels[TabOffset+(Tab+1)*TabSize-1,TabHeight+1]:=MainTexture.clBevelShade;
    510 if Tab<3 then
    511   Frame(Canvas,TabOffset+(Tab+1)*TabSize+1,3,TabOffset+(Tab+1)*TabSize+2,TabHeight,
    512     MainTexture.clBevelShade,MainTexture.clBevelShade); // Tab shadow
    513 BitBlt(LogoBuffer.Canvas.Handle,0,0,36,36,Canvas.Handle,6,3+2*integer(Tab<>0),SRCCOPY);
    514 ImageOp_BCC(LogoBuffer,Templates,0,0,145,38,36,27,$BFBF20,$4040DF); // logo part 1
    515 ImageOp_BCC(LogoBuffer,Templates,10,27,155,38+27,26,9,$BFBF20,$4040DF); // logo part 2
    516 BitBlt(Canvas.Handle,6,3+2*integer(Tab<>0),36,36,LogoBuffer.Canvas.Handle,0,0,SRCCOPY);
    517 
    518 if page=pgMain then
    519   begin
    520   if SelectedAction>=0 then // mark selected action
    521     for i:=0 to (ClientWidth-2*ActionSideBorder) div wBuffer+1 do
    522       begin
    523       w:=ClientWidth-2*ActionSideBorder-i*wBuffer;
    524       if w>wBuffer then
    525         w:=wBuffer;
    526       h:=ActionPitch;
    527       if yAction+SelectedAction*ActionPitch-8+h>ClientHeight-ActionBottomBorder then
    528         h:=ClientHeight-ActionBottomBorder-(yAction+SelectedAction*ActionPitch-8);
    529       BitBlt(LogoBuffer.Canvas.Handle,0,0,w,h,Canvas.Handle,
    530         ActionSideBorder+i*wBuffer,yAction+SelectedAction*ActionPitch-8,SRCCOPY);
    531       MakeBlue(LogoBuffer,0,0,w,h);
    532       BitBlt(Canvas.Handle,ActionSideBorder+i*wBuffer,
    533         yAction+SelectedAction*ActionPitch-8,w,h,
    534         LogoBuffer.Canvas.Handle,0,0,SRCCOPY);
     1058  end;
     1059
     1060var
     1061  SaveMap: array [0 .. lxmax * lymax - 1] of Byte;
     1062
     1063  procedure PaintFileMini;
     1064  type
     1065    TLine = array [0 .. 99999999, 0 .. 2] of Byte;
     1066  var
     1067    i, x, y, xm, cm, Tile, OwnColor, EnemyColor: integer;
     1068    MiniLine, PrevMiniLine: ^TLine;
     1069  begin
     1070    OwnColor := GrExt[HGrSystem].Data.Canvas.Pixels[95, 67];
     1071    EnemyColor := GrExt[HGrSystem].Data.Canvas.Pixels[96, 67];
     1072    Mini.PixelFormat := pf24bit;
     1073    Mini.width := MiniWidth * 2;
     1074    Mini.height := MiniHeight;
     1075    if MiniMode = mmPicture then
     1076    begin
     1077      MiniLine := nil;
     1078      for y := 0 to MiniHeight - 1 do
     1079      begin
     1080        PrevMiniLine := MiniLine;
     1081        MiniLine := Mini.ScanLine[y];
     1082        for x := 0 to MiniWidth - 1 do
     1083          for i := 0 to 1 do
     1084          begin
     1085            xm := (x * 2 + i + y and 1) mod (MiniWidth * 2);
     1086            Tile := SaveMap[x + MiniWidth * y];
     1087            if Tile and fTerrain = fUNKNOWN then
     1088              cm := $000000
     1089            else if Tile and smCity <> 0 then
     1090            begin
     1091              if Tile and smOwned <> 0 then
     1092                cm := OwnColor
     1093              else
     1094                cm := EnemyColor;
     1095              if PrevMiniLine <> nil then
     1096              begin // 2x2 city dot covers two scanlines
     1097                PrevMiniLine[xm, 0] := cm shr 16;
     1098                PrevMiniLine[xm, 1] := cm shr 8 and $FF;
     1099                PrevMiniLine[xm, 2] := cm and $FF;
     1100              end
     1101            end
     1102            else if (i = 0) and (Tile and smUnit <> 0) then
     1103              if Tile and smOwned <> 0 then
     1104                cm := OwnColor
     1105              else
     1106                cm := EnemyColor
     1107            else
     1108              cm := MiniColors[Tile and fTerrain, i];
     1109            MiniLine[xm, 0] := cm shr 16;
     1110            MiniLine[xm, 1] := cm shr 8 and $FF;
     1111            MiniLine[xm, 2] := cm and $FF;
     1112          end;
     1113      end
     1114    end;
     1115  end;
     1116
     1117var
     1118  x, y, dummy, FileLandMass, lxFile, lyFile: integer;
     1119  LogFile, MapFile: file;
     1120  s: string[255];
     1121  MapRow: array [0 .. lxmax - 1] of Cardinal;
     1122
     1123begin
     1124  case Page of
     1125    pgStartRandom:
     1126      begin
     1127        MiniMode := mmPicture;
     1128        PaintRandomMini(3);
    5351129      end;
    536   y:=yAction;
    537   for i:=0 to nMainActions-1 do
    538     begin
    539     if i in ActionsOffered then
    540       case i of
    541         maConfig:
    542           DrawAction(y,25,'ACTIONHEADER_CONFIG','ACTION_CONFIG');
    543         maManual:
    544           DrawAction(y,19,'ACTIONHEADER_MANUAL','ACTION_MANUAL');
    545         maCredits:
    546           DrawAction(y,22,'ACTIONHEADER_CREDITS','ACTION_CREDITS');
    547         maAIDev:
    548           DrawAction(y,24,'ACTIONHEADER_AIDEV','ACTION_AIDEV');
    549         maWeb:
     1130
     1131    pgNoLoad:
     1132      begin
     1133        MiniWidth := lxpre[DefaultWorldSize];
     1134        MiniHeight := lypre[DefaultWorldSize];
     1135        MiniMode := mmNone;
     1136      end;
     1137
     1138    pgLoad:
     1139      begin
     1140        AssignFile(LogFile, DataDir + 'Saved\' + List.Items[List.ItemIndex]
     1141          + '.cevo');
     1142        try
     1143          Reset(LogFile, 4);
     1144          BlockRead(LogFile, s[1], 2); { file id }
     1145          BlockRead(LogFile, dummy, 1); { format id }
     1146          if dummy >= $000E01 then
     1147            BlockRead(LogFile, dummy, 1); { item stored since 0.14.1 }
     1148          BlockRead(LogFile, MiniWidth, 1);
     1149          BlockRead(LogFile, MiniHeight, 1);
     1150          BlockRead(LogFile, FileLandMass, 1);
     1151          if FileLandMass = 0 then
     1152            for y := 0 to MiniHeight - 1 do
     1153              BlockRead(LogFile, MapRow, MiniWidth);
     1154          BlockRead(LogFile, dummy, 1);
     1155          BlockRead(LogFile, dummy, 1);
     1156          BlockRead(LogFile, LastTurn, 1);
     1157          BlockRead(LogFile, SaveMap, 1);
     1158          if SaveMap[0] = $80 then
     1159            MiniMode := mmMultiPlayer
     1160          else
     1161            MiniMode := mmPicture;
     1162          if MiniMode = mmPicture then
     1163            BlockRead(LogFile, SaveMap[4], (MiniWidth * MiniHeight - 1) div 4);
     1164          CloseFile(LogFile);
     1165        except
     1166          CloseFile(LogFile);
     1167          LastTurn := 0;
     1168          MiniWidth := lxpre[DefaultWorldSize];
     1169          MiniHeight := lypre[DefaultWorldSize];
     1170          MiniMode := mmNone;
     1171        end;
     1172        // BookDate:=DateToStr(FileDateToDateTime(FileAge(FileName)));
     1173        PaintFileMini;
     1174        if not TurnValid then
     1175        begin
     1176          LoadTurn := LastTurn;
     1177          SmartInvalidate(xTurnSlider - 2, y0Mini + 61,
     1178            xTurnSlider + wTurnSlider + 2, yTurnSlider + 9);
     1179        end;
     1180        TurnValid := true;
     1181      end;
     1182
     1183    pgEditRandom:
     1184      begin
     1185        MapFileName := '';
     1186        MiniMode := mmPicture;
     1187        PaintRandomMini(4);
     1188      end;
     1189
     1190    pgStartMap, pgEditMap:
     1191      begin
     1192        MiniMode := mmPicture;
     1193        if Page = pgEditMap then
     1194          MapFileName := List.Items[List.ItemIndex] + '.cevo map';
     1195        if LoadGraphicFile(Mini, DataDir + 'Maps\' + Copy(MapFileName, 1,
     1196          Length(MapFileName) - 9), gfNoError) then
     1197        begin
     1198          if Mini.width div 2 > MaxWidthMapLogo then
     1199            Mini.width := MaxWidthMapLogo * 2;
     1200          if Mini.height > MaxHeightMapLogo then
     1201            Mini.height := MaxHeightMapLogo;
     1202          MiniWidth := Mini.width div 2;
     1203          MiniHeight := Mini.height;
     1204        end
     1205        else
     1206        begin
     1207          MiniMode := mmNone;
     1208          MiniWidth := MaxWidthMapLogo;
     1209          MiniHeight := MaxHeightMapLogo;
     1210        end;
     1211
     1212        AssignFile(MapFile, DataDir + 'Maps\' + MapFileName);
     1213        try
     1214          Reset(MapFile, 4);
     1215          BlockRead(MapFile, s[1], 2); { file id }
     1216          BlockRead(MapFile, x, 1); { format id }
     1217          BlockRead(MapFile, x, 1); // MaxTurn
     1218          BlockRead(MapFile, lxFile, 1);
     1219          BlockRead(MapFile, lyFile, 1);
     1220          nMapLandTiles := 0;
     1221          nMapStartPositions := 0;
     1222          for y := 0 to lyFile - 1 do
    5501223          begin
    551           Canvas.Font.Assign(UniFont[ftCaption]);
    552           //Canvas.Font.Style:=Canvas.Font.Style+[fsUnderline];
    553           RisedTextOut(Canvas,xActionIcon+99,y,Phrases2.Lookup('ACTIONHEADER_WEB'));
    554           Canvas.Font.Assign(UniFont[ftNormal]);
    555           BitBlt(LogoBuffer.Canvas.Handle,0,0,91,25,Canvas.Handle,xActionIcon,y+2,SRCCOPY);
    556           ImageOp_BCC(LogoBuffer,Templates,0,0,1,400,91,25,0,
    557             Colors.Canvas.Pixels[clkAge0-1,cliDimmedText]);
    558           BitBlt(Canvas.Handle,xActionIcon,y+2,91,25,LogoBuffer.Canvas.Handle,0,0,SRCCOPY);
     1224            BlockRead(MapFile, MapRow, lxFile);
     1225            for x := 0 to lxFile - 1 do
     1226            begin
     1227              if (MapRow[x] and fTerrain) in [fGrass, fPrairie, fTundra, fSwamp,
     1228                fForest, fHills] then
     1229                inc(nMapLandTiles);
     1230              if MapRow[x] and (fPrefStartPos or fStartPos) <> 0 then
     1231                inc(nMapStartPositions);
     1232            end
    5591233          end;
    560         end;
    561     inc(y,ActionPitch);
    562     end
    563   end
    564 else if Page in [pgStartRandom,pgStartMap] then
    565   begin
    566   DLine(Canvas,344,514,y0Mini+61+19,MainTexture.clBevelLight,MainTexture.clBevelShade);
    567   RisedTextOut(Canvas,344,y0Mini+61,Phrases.Lookup('STARTCONTROLS',10));
    568   s:=TurnToString(MaxTurn);
    569   RisedTextOut(Canvas,514-BiColorTextWidth(Canvas,s),y0Mini+61,s);
    570   s:=Phrases.Lookup('STARTCONTROLS',7);
    571   w:=Canvas.TextWidth(s);
    572   LoweredTextOut(Canvas,-2,MainTexture,x0Brain+32-w div 2,y0Brain+dyBrain+69,s);
    573 
    574   InitOrnament;
    575   if AutoDiff<0 then
    576     begin
    577     for i:=12 to 19 do if (i<13) or (i>17) then
    578       begin
    579       BitBlt(Canvas.Handle,9+i*27,yLogo-2,wOrna,hOrna,
    580         GrExt[HGrSystem2].Mask.Canvas.Handle,xOrna,yOrna,SRCAND);
    581       BitBlt(Canvas.Handle,9+i*27,yLogo-2,wOrna,hOrna,
    582         GrExt[HGrSystem2].Data.Canvas.Handle,xOrna,yOrna,SRCPAINT);
     1234          if nMapStartPositions > nPl then
     1235            nMapStartPositions := nPl;
     1236          CloseFile(MapFile);
     1237        except
     1238          CloseFile(MapFile);
     1239        end;
     1240        if Page = pgEditMap then
     1241          SmartInvalidate(x0Mini - 112, y0Mini + 61, x0Mini + 112, y0Mini + 91);
     1242      end
     1243  end;
     1244  SmartInvalidate(x0Mini - lxmax, y0Mini - lymax div 2,
     1245    x0Mini - lxmax + 2 * lxmax + 4, y0Mini - lymax div 2 + lymax + 4);
     1246end;
     1247
     1248procedure TStartDlg.BrainClick(Sender: TObject);
     1249var
     1250  i: integer;
     1251begin
     1252  // Play('BUTTON_UP');
     1253  if bixPopup < 0 then
     1254  begin // change default AI
     1255    bixDefault := TMenuItem(Sender).Tag;
     1256    SmartInvalidate(xDefault, yDefault, xDefault + 64, yDefault + 64);
     1257  end
     1258  else
     1259  begin
     1260    Brain[bixView[bixPopup]].Flags := Brain[bixView[bixPopup]].Flags and
     1261      not fUsed;
     1262    bixView[bixPopup] := TMenuItem(Sender).Tag;
     1263    DiffUpBtn[bixPopup].Visible := bixView[bixPopup] >= bixTerm;
     1264    DiffDownBtn[bixPopup].Visible := bixView[bixPopup] >= bixTerm;
     1265    if bixPopup in OfferMultiple then
     1266    begin
     1267      MultiBtn[bixPopup].Visible := bixView[bixPopup] >= bixTerm;
     1268      MultiBtn[bixPopup].ButtonIndex := 2 + (MultiControl shr bixPopup) and 1;
     1269    end;
     1270    Brain[bixView[bixPopup]].Flags := Brain[bixView[bixPopup]].Flags or fUsed;
     1271    if bixView[bixPopup] < bixTerm then
     1272      Difficulty[bixPopup] := 0 { supervisor }
     1273    else
     1274      Difficulty[bixPopup] := 2;
     1275    if (Page = pgStartRandom) and (bixPopup in OfferMultiple) and
     1276      (bixView[bixPopup] < 0) then
     1277      MultiControl := MultiControl and not(1 shl bixPopup);
     1278    if (bixPopup = 0) and (MapFileName <> '') then
     1279      ChangePage(Page);
     1280    if bixView[bixPopup] = bixNoTerm then
     1281    begin // turn all local players off
     1282      for i := 1 to nPlOffered - 1 do
     1283        if bixView[i] = bixTerm then
     1284        begin
     1285          bixView[i] := -1;
     1286          DiffUpBtn[i].Visible := false;
     1287          DiffUpBtn[i].Tag := 0;
     1288          DiffDownBtn[i].Visible := false;
     1289          DiffDownBtn[i].Tag := 0;
     1290          if i in OfferMultiple then
     1291          begin
     1292            MultiBtn[i].Visible := false;
     1293            MultiBtn[i].Tag := 0;
     1294          end;
     1295          SmartInvalidate(xBrain[i] - 31, yBrain[i] - 1, xBrain[i] + 64,
     1296            DiffUpBtn[i].top + 25);
     1297        end;
     1298      Brain[bixTerm].Flags := Brain[bixTerm].Flags and not fUsed;
     1299    end;
     1300    SmartInvalidate(xBrain[bixPopup] - 31, yBrain[bixPopup] - 1,
     1301      xBrain[bixPopup] + 64, DiffUpBtn[bixPopup].top + 25);
     1302  end
     1303end;
     1304
     1305procedure TStartDlg.InitPopup(PopupIndex: integer);
     1306var
     1307  i, FixedLines: integer;
     1308  m: TMenuItem;
     1309
     1310  procedure OfferBrain(Index: integer);
     1311  var
     1312    j: integer;
     1313  begin
     1314    m := TMenuItem.Create(PopupMenu1);
     1315    if Index < 0 then
     1316      m.Caption := Phrases.Lookup('NOMOD')
     1317    else
     1318      m.Caption := Brain[Index].Name;
     1319    m.Tag := Index;
     1320    m.OnClick := BrainClick;
     1321    j := FixedLines;
     1322    while (j < PopupMenu1.Items.Count) and
     1323      (StrIComp(pchar(m.Caption), pchar(PopupMenu1.Items[j].Caption)) > 0) do
     1324      inc(j);
     1325    m.RadioItem := true;
     1326    if bixPopup < 0 then
     1327      m.Checked := bixDefault = Index
     1328    else
     1329      m.Checked := bixView[bixPopup] = Index;
     1330    PopupMenu1.Items.Insert(j, m);
     1331  end;
     1332
     1333begin
     1334  bixPopup := PopupIndex;
     1335  EmptyMenu(PopupMenu1.Items);
     1336  if bixPopup < 0 then
     1337  begin // select default AI
     1338    FixedLines := 0;
     1339    if nBrain >= bixFirstAI + 2 then
     1340    begin
     1341      OfferBrain(bixRandom);
     1342      inc(FixedLines)
     1343    end;
     1344    for i := bixFirstAI to nBrain - 1 do // offer available AIs
     1345      if Brain[i].Flags and fMultiple <> 0 then
     1346        OfferBrain(i);
     1347  end
     1348  else
     1349  begin
     1350    FixedLines := 0;
     1351    if bixPopup > 0 then
     1352    begin
     1353      OfferBrain(-1);
     1354      inc(FixedLines);
     1355    end;
     1356    for i := bixTerm downto 0 do // offer game interfaces
     1357      if (bixPopup = 0) or (i = bixTerm) and (bixView[0] <> bixNoTerm) then
     1358      begin
     1359        OfferBrain(i);
     1360        inc(FixedLines);
    5831361      end;
    584     PaintLogo(Canvas,69+11*27,yLogo,MainTexture.clBevelLight,MainTexture.clBevelShade);
    585 
    586     for i:=0 to nPlOffered-1 do if 1 shl i and SlotAvailable<>0 then
    587       begin
    588       if bixView[i]>=0 then
    589         FrameImage(Canvas,BrainPicture[bixView[i]],xBrain[i],yBrain[i],64,64,0,0,true)
    590       else FrameImage(Canvas,EmptyPicture,xBrain[i],yBrain[i],64,64,0,0,true);
    591       if bixView[i]>=bixTerm then
     1362    if bixPopup > 0 then
     1363    begin
     1364      m := TMenuItem.Create(PopupMenu1);
     1365      m.Caption := '-';
     1366      PopupMenu1.Items.Add(m);
     1367      inc(FixedLines);
     1368      if nBrain >= bixFirstAI + 2 then
     1369      begin
     1370        OfferBrain(bixRandom);
     1371        inc(FixedLines);
     1372      end;
     1373      for i := bixFirstAI to nBrain - 1 do // offer available AIs
     1374        if (Brain[i].Flags and fMultiple <> 0) or (Brain[i].Flags and fUsed = 0)
     1375          or (i = bixView[bixPopup]) then
     1376          OfferBrain(i);
     1377    end;
     1378  end
     1379end;
     1380
     1381procedure TStartDlg.UpdateFormerGames;
     1382var
     1383  i: integer;
     1384  f: TSearchRec;
     1385begin
     1386  FormerGames.Clear;
     1387  if FindFirst(DataDir + 'Saved\*.cevo', $21, f) = 0 then
     1388    repeat
     1389      i := FormerGames.Count;
     1390      while (i > 0) and (f.Time < integer(FormerGames.Objects[i - 1])) do
     1391        dec(i);
     1392      FormerGames.InsertObject(i, Copy(f.Name, 1, Length(f.Name) - 5),
     1393        TObject(f.Time));
     1394    until FindNext(f) <> 0;
     1395  ListIndex[2] := FormerGames.Count - 1;
     1396  if (ShowTab = 2) and (FormerGames.Count > 0) then
     1397    ShowTab := 3;
     1398  TurnValid := false;
     1399end;
     1400
     1401procedure TStartDlg.UpdateMaps;
     1402var
     1403  f: TSearchRec;
     1404begin
     1405  Maps.Clear;
     1406  if FindFirst(DataDir + 'Maps\*.cevo map', $21, f) = 0 then
     1407    repeat
     1408      Maps.Add(Copy(f.Name, 1, Length(f.Name) - 9));
     1409    until FindNext(f) <> 0;
     1410  Maps.Sort;
     1411  Maps.Insert(0, Phrases.Lookup('RANMAP'));
     1412  ListIndex[0] := Maps.IndexOf(Copy(MapFileName, 1, Length(MapFileName) - 9));
     1413  if ListIndex[0] < 0 then
     1414    ListIndex[0] := 0;
     1415end;
     1416
     1417procedure TStartDlg.ChangePage(NewPage: integer);
     1418var
     1419  i, j, p1: integer;
     1420  s: string;
     1421  Reg: TRegistry;
     1422  invalidateTab0: boolean;
     1423begin
     1424  invalidateTab0 := (Page = pgMain) or (NewPage = pgMain);
     1425  Page := NewPage;
     1426  case Page of
     1427    pgStartRandom, pgStartMap:
     1428      begin
     1429        StartBtn.Caption := Phrases.Lookup('STARTCONTROLS', 1);
     1430        if Page = pgStartRandom then
     1431          i := nPlOffered
     1432        else
    5921433        begin
    593         BitBlt(Canvas.Handle,xBrain[i]-18,yBrain[i]+19,12,14,
    594           GrExt[HGrSystem].Data.Canvas.Handle,134+(Difficulty[i]-1)*13,28,SRCCOPY);
    595         Frame(Canvas,xBrain[i]-19,yBrain[i]+18,xBrain[i]-18+12,yBrain[i]+(19+14),
    596           $000000,$000000);
    597         RFrame(Canvas,DiffUpBtn[i].Left-1,DiffUpBtn[i].Top-1,DiffUpBtn[i].Left+12,
    598           DiffUpBtn[i].Top+24,MainTexture.clBevelShade,MainTexture.clBevelLight);
    599         with Canvas do
     1434          i := nMapStartPositions;
     1435          if i = 0 then
    6001436          begin
    601           Brush.Color:=$000000;
    602           FillRect(Rect(xBrain[i]-5,yBrain[i]+25,xBrain[i]-2,yBrain[i]+27));
    603           Brush.Style:=bsClear;
     1437            bixView[0] := bixSuper_Virtual;
     1438            Difficulty[0] := 0
    6041439          end;
    605         if i in OfferMultiple then
     1440          if bixView[0] < bixTerm then
     1441            inc(i);
     1442          if i > nPl then
     1443            i := nPl;
     1444          if i <= nPlOffered then
     1445            MultiControl := 0
     1446          else
     1447            MultiControl := InitMulti[i];
     1448        end;
     1449        if InitAlive[i] <> SlotAvailable then
     1450          if Page = pgStartRandom then
     1451          begin // restore AI assignment of last start
     1452            Reg := TRegistry.Create;
     1453            Reg.OpenKey('SOFTWARE\cevo\RegVer9\Start', false);
     1454            for p1 := 0 to nPlOffered - 1 do
     1455            begin
     1456              bixView[p1] := -1;
     1457              s := Reg.ReadString('Control' + IntToStr(p1));
     1458              Difficulty[p1] := Reg.ReadInteger('Diff' + IntToStr(p1));
     1459              if s <> '' then
     1460                for j := 0 to nBrain - 1 do
     1461                  if AnsiCompareFileName(s, Brain[j].FileName) = 0 then
     1462                    bixView[p1] := j;
     1463            end;
     1464            MultiControl := Reg.ReadInteger('MultiControl');
     1465            Reg.closekey;
     1466            Reg.Free;
     1467          end
     1468          else
     1469            for p1 := 1 to nPl - 1 do
     1470              if 1 shl p1 and InitAlive[i] <> 0 then
     1471              begin
     1472                bixView[p1] := bixDefault;
     1473                Difficulty[p1] := 2;
     1474              end
     1475              else
     1476                bixView[p1] := -1;
     1477        SlotAvailable := InitAlive[i];
     1478        for i := 0 to nPlOffered - 1 do
     1479          if (AutoDiff < 0) and (bixView[i] >= bixTerm) then
    6061480          begin
    607           RFrame(Canvas,MultiBtn[i].Left-1,MultiBtn[i].Top-1,MultiBtn[i].Left+12,
    608             MultiBtn[i].Top+12,MainTexture.clBevelShade,MainTexture.clBevelLight);
    609           BitBlt(Canvas.Handle,xBrain[i]-31,yBrain[i],13,12,
    610             GrExt[HGrSystem].Data.Canvas.Handle,88,47,SRCCOPY);
     1481            DiffUpBtn[i].Tag := 768;
     1482            DiffDownBtn[i].Tag := 768;
    6111483          end
    612         end;
    613       if bixView[i]>=0 then
     1484          else
     1485          begin
     1486            DiffUpBtn[i].Tag := 0;
     1487            DiffDownBtn[i].Tag := 0;
     1488          end;
     1489        for i := 6 to 8 do
     1490          if (AutoDiff < 0) and (bixView[i] >= bixTerm) then
     1491          begin
     1492            MultiBtn[i].Tag := 768;
     1493            MultiBtn[i].ButtonIndex := 2 + (MultiControl shr i) and 1;
     1494            MultiBtn[i].Enabled := Page = pgStartRandom
     1495          end
     1496          else
     1497            MultiBtn[i].Tag := 0;
     1498        if (AutoDiff > 0) and (Page <> pgStartMap) then
    6141499        begin
    615         DiffUpBtn[i].Hint:=Format(Phrases.Lookup('STARTCONTROLS',9),
    616           [Brain[bixView[i]].Name]);
    617         DiffDownBtn[i].Hint:=DiffUpBtn[i].Hint;
     1500          AutoEnemyUpBtn.Tag := 768;
     1501          AutoEnemyDownBtn.Tag := 768;
     1502        end
     1503        else
     1504        begin
     1505          AutoEnemyUpBtn.Tag := 0;
     1506          AutoEnemyDownBtn.Tag := 0;
     1507        end;
     1508        if AutoDiff > 0 then
     1509        begin
     1510          AutoDiffUpBtn.Tag := 768;
     1511          AutoDiffDownBtn.Tag := 768;
     1512        end
     1513        else
     1514        begin
     1515          AutoDiffUpBtn.Tag := 0;
     1516          AutoDiffDownBtn.Tag := 0;
    6181517        end
    6191518      end;
    620     end
    621   else
    622     begin
    623     DLine(Canvas,24,198,yMain+140+19,MainTexture.clBevelLight,MainTexture.clBevelShade);
    624     RisedTextOut(Canvas,24{x0Brain+32-BiColorTextWidth(Canvas,s) div 2},yMain+140{y0Mini-77},
    625       Phrases.Lookup('STARTCONTROLS',15));
    626     if Page=pgStartRandom then s:=IntToStr(AutoEnemies)
    627     else if nMapStartPositions=0 then s:='0'
    628     else s:=IntToStr(nMapStartPositions-1);
    629     RisedTextOut(Canvas,198-BiColorTextWidth(Canvas,s),yMain+140,s);
    630     DLine(Canvas,24,xDefault-6,yMain+164+19,MainTexture.clBevelLight,MainTexture.clBevelShade);
    631     RisedTextOut(Canvas,24{x0Brain+32-BiColorTextWidth(Canvas,s) div 2},yMain+164{y0Mini-77},
    632       Phrases.Lookup('STARTCONTROLS',16));
    633     if AutoDiff=1 then
    634       FrameImage(Canvas,BrainPicture[bixBeginner],xDefault,yDefault,64,64,0,0,false)
    635     else FrameImage(Canvas,BrainPicture[bixDefault],xDefault,yDefault,64,64,0,0,true);
    636     DLine(Canvas,56,272,y0Mini+61+19,MainTexture.clBevelLight,MainTexture.clBevelShade);
    637     RisedTextOut(Canvas,56,y0Mini+61,Phrases.Lookup('STARTCONTROLS',14));
    638     s:=Phrases.Lookup('AUTODIFF',AutoDiff-1);
    639     RisedTextOut(Canvas,272-BiColorTextWidth(Canvas,s),y0Mini+61,s);
    640 
    641     for i:=0 to 19 do if (i<2) or (i>6) then
    642       begin
    643       BitBlt(Canvas.Handle,9+i*27,yLogo-2,wOrna,hOrna,
    644         GrExt[HGrSystem2].Mask.Canvas.Handle,xOrna,yOrna,SRCAND);
    645       BitBlt(Canvas.Handle,9+i*27,yLogo-2,wOrna,hOrna,
    646         GrExt[HGrSystem2].Data.Canvas.Handle,xOrna,yOrna,SRCPAINT);
     1519
     1520    pgNoLoad, pgLoad:
     1521      begin
     1522        StartBtn.Caption := Phrases.Lookup('STARTCONTROLS', 2);
     1523        RenameBtn.Hint := Phrases.Lookup('BTN_RENGAME');
     1524        DeleteBtn.Hint := Phrases.Lookup('BTN_DELGAME');
    6471525      end;
    648     PaintLogo(Canvas,69,yLogo,MainTexture.clBevelLight,MainTexture.clBevelShade);
    649     end
    650   end
    651 else if Page=pgLoad then
    652   begin
    653 //  RisedTextOut(Canvas,x0Mini+2-BiColorTextWidth(Canvas,BookDate) div 2,y0Mini-73,BookDate);
    654   if LastTurn>0 then
    655     begin
    656     PaintProgressBar(canvas,6,xTurnSlider,yTurnSlider,0,
    657       LoadTurn*wTurnSlider div LastTurn,wTurnSlider,MainTexture);
    658     Frame(canvas,xTurnSlider-2,yTurnSlider-2,xTurnSlider+wTurnSlider+1,
    659       yTurnSlider+8,$B0B0B0,$FFFFFF);
    660     RFrame(canvas,xTurnSlider-3,yTurnSlider-3,xTurnSlider+wTurnSlider+2,
    661       yTurnSlider+9,$FFFFFF,$B0B0B0);
    662     end
    663   else DLine(Canvas,344,514,y0Mini+61+19,MainTexture.clBevelLight,MainTexture.clBevelShade);
    664   RisedTextOut(Canvas,344,y0Mini+61,Phrases.Lookup('STARTCONTROLS',8));
    665   s:=TurnToString(LoadTurn);
    666   RisedTextOut(Canvas,514-BiColorTextWidth(Canvas,s),y0Mini+61,s);
    667   end
    668 else if Page=pgEditRandom then
    669   begin
    670   DLine(Canvas,344,514,y0Mini-77+19,MainTexture.clBevelLight,MainTexture.clBevelShade);
    671   RisedTextOut(Canvas,344,y0Mini-77,Phrases.Lookup('STARTCONTROLS',5));
    672   s:=IntToStr((lxpre[WorldSize]*lypre[WorldSize]*20 + DefaultWorldTiles div 2)
    673     div DefaultWorldTiles *5)+'%';
    674   RisedTextOut(Canvas,514-BiColorTextWidth(Canvas,s),y0Mini-77,s);
    675   DLine(Canvas,344,514,y0Mini+61+19,MainTexture.clBevelLight,MainTexture.clBevelShade);
    676   RisedTextOut(Canvas,344,y0Mini+61,Phrases.Lookup('STARTCONTROLS',6));
    677   s:=IntToStr(StartLandMass)+'%';
    678   RisedTextOut(Canvas,514-BiColorTextWidth(Canvas,s),y0Mini+61,s);
    679   end
    680 else if Page=pgEditMap then
    681   begin
    682   //DLine(Canvas,344,514,y0Mini+61+19,MainTexture.clBevelLight,MainTexture.clBevelShade);
    683   s:=Format(Phrases2.Lookup('MAPPROP'), [(nMapLandTiles*100+556) div 1112,
    684     // 1112 is typical for world with 100% size and default land mass
    685     nMapStartPositions]);
    686   RisedTextOut(Canvas,x0Mini-BiColorTextWidth(Canvas,s) div 2,y0Mini+61,s);
    687   end;
    688 
    689 if StartBtn.Visible then
    690   BtnFrame(Canvas,StartBtn.BoundsRect,MainTexture);
    691 if Up2Btn.Visible then
    692   RFrame(Canvas,Up2Btn.Left-1,Up2Btn.Top-1,Up2Btn.Left+12,
    693     Up2Btn.Top+24,MainTexture.clBevelShade,MainTexture.clBevelLight);
    694 if Up1Btn.Visible then
    695   RFrame(Canvas,Up1Btn.Left-1,Up1Btn.Top-1,Up1Btn.Left+12,
    696     Up1Btn.Top+24,MainTexture.clBevelShade,MainTexture.clBevelLight);
    697 if AutoDiffUpBtn.Visible then
    698   RFrame(Canvas,AutoDiffUpBtn.Left-1,AutoDiffUpBtn.Top-1,AutoDiffUpBtn.Left+12,
    699     AutoDiffUpBtn.Top+24,MainTexture.clBevelShade,MainTexture.clBevelLight);
    700 if AutoEnemyUpBtn.Visible then
    701   RFrame(Canvas,AutoEnemyUpBtn.Left-1,AutoEnemyUpBtn.Top-1,AutoEnemyUpBtn.Left+12,
    702     AutoEnemyUpBtn.Top+24,MainTexture.clBevelShade,MainTexture.clBevelLight);
    703 if CustomizeBtn.Visible then
    704   RFrame(Canvas,CustomizeBtn.Left-1,CustomizeBtn.Top-1,CustomizeBtn.Left+12,
    705     CustomizeBtn.Top+12,MainTexture.clBevelShade,MainTexture.clBevelLight);
    706 if List.Visible then
    707   EditFrame(Canvas,List.BoundsRect,MainTexture);
    708 if RenameBtn.Visible then
    709   BtnFrame(Canvas,RenameBtn.BoundsRect,MainTexture);
    710 if DeleteBtn.Visible then
    711   BtnFrame(Canvas,DeleteBtn.BoundsRect,MainTexture);
    712 if Page=pgLoad then
    713   BtnFrame(Canvas,ReplayBtn.BoundsRect,MainTexture);
    714 
    715 if not (Page in [pgMain,pgNoLoad]) then
    716   begin
    717   xMini:=x0Mini-MiniWidth;
    718   yMini:=y0Mini-MiniHeight div 2;
    719   Frame(Canvas,xMini,yMini,xMini+3+MiniWidth*2,yMini+3+MiniHeight,MainTexture.clBevelLight,
    720     MainTexture.clBevelShade);
    721   Frame(Canvas,xMini+1,yMini+1,xMini+2+MiniWidth*2,yMini+2+MiniHeight,MainTexture.clBevelShade,
    722     MainTexture.clBevelLight);
    723   end;
    724 s:='';
    725 if MiniMode=mmPicture then
    726   begin
    727   BitBlt(Canvas.Handle,xMini+2,yMini+2,MiniWidth*2,MiniHeight,Mini.Canvas.Handle,0,0,SRCCOPY);
    728   if page=pgStartRandom then s:=Phrases.Lookup('RANMAP')
    729   end
    730 else if MiniMode=mmMultiPlayer then s:=Phrases.Lookup('MPMAP')
    731 else if page=pgStartMap then s:=Copy(MapFileName,1,Length(MapFileName)-9)
    732 else if page=pgEditMap then s:=List.Items[List.ItemIndex]
    733 else if page=pgNoLoad then s:=Phrases.Lookup('NOGAMES');
    734 if s<>'' then
    735   RisedTextOut(Canvas,x0Mini+2-BiColorTextWidth(Canvas,s) div 2,y0Mini-8,s);
    736 end;
    737 
    738 procedure TStartDlg.FormShow(Sender:TObject);
    739 type
    740 TLine=array[0..99999999] of Byte;
    741 var
    742 i,x,y: integer;
    743 PictureLine: ^TLine;
    744 begin
    745 SetMainTextureByAge(-1);
    746 List.Font.Color:=MainTexture.clMark;
    747 Fill(EmptyPicture.Canvas,0,0,64,64,(wMaintexture-64) div 2,
    748   (hMaintexture-64) div 2);
    749 for y:=0 to 63 do
    750   begin // darken texture for empty slot
    751   PictureLine:=EmptyPicture.ScanLine[y];
    752   for x:=0 to 64*3-1 do
    753     begin
    754     i:=integer(PictureLine[x])-28;
    755     if i<0 then i:=0;
    756     PictureLine[x]:=i;
    757     end
    758   end;
    759 
    760 Difficulty[0]:=Diff0;
    761 
    762 SelectedAction:=-1;
    763 if ShowTab=3 then PreviewMap(StartLandMass); // avoid delay on first TabX change
    764 ChangeTab(ShowTab);
    765 Background.Enabled:=false;
    766 end;
    767 
    768 procedure TStartDlg.UnlistBackupFile(FileName: string);
    769 var
    770 i: integer;
    771 begin
    772 if FileName[1]<>'~' then FileName:='~'+FileName;
    773 i:=FormerGames.Count-1;
    774 while (i>=0) and (AnsiCompareFileName(FormerGames[i],FileName)<>0) do dec(i);
    775 if i>=0 then
    776   begin
    777   FormerGames.Delete(i);
    778   if ListIndex[2]=i then ListIndex[2]:=0
    779   end
    780 end;
    781 
    782 procedure TStartDlg.StartBtnClick(Sender:TObject);
    783 var
    784 i,GameCount,MapCount: integer;
    785 FileName: string;
    786 Reg: TRegistry;
    787 begin
    788 case Page of
    789   pgLoad:
    790     begin //load
    791     FileName:=List.Items[List.ItemIndex];
    792     if LoadGame(DataDir+'Saved\', FileName+'.cevo', LoadTurn,false) then
    793       UnlistBackupFile(FileName)
    794     else SimpleMessage(Phrases.Lookup('LOADERR'));
    795     SlotAvailable:=-1;
    796     end;
    797 
    798   pgStartRandom,pgStartMap: if bixView[0]>=0 then
    799     begin
    800     if (page=pgStartMap) and (nMapStartPositions=0) and (AutoDiff>0) then
    801       begin
    802       SimpleMessage(Phrases.Lookup('NOSTARTPOS'));
    803       exit
     1526
     1527    pgEditRandom, pgEditMap:
     1528      begin
     1529        StartBtn.Caption := Phrases.Lookup('STARTCONTROLS', 12);
     1530        RenameBtn.Hint := Phrases.Lookup('BTN_RENMAP');
     1531        DeleteBtn.Hint := Phrases.Lookup('BTN_DELMAP');
    8041532      end;
    805 
    806     Reg:=TRegistry.Create;
    807     Reg.OpenKey('SOFTWARE\cevo\RegVer9\Start',true);
    808     try
    809       GameCount:=Reg.ReadInteger('GameCount');
    810     except
    811       GameCount:=0;
    812       end;
    813 
    814     if (AutoDiff<0) and (bixView[0]=bixNoTerm) then
    815       FileName:='Round'+IntToStr(GetCurrentProcessID())
     1533  end;
     1534
     1535  PaintInfo;
     1536  for i := 0 to ControlCount - 1 do
     1537    Controls[i].Visible := Controls[i].Tag and (256 shl Page) <> 0;
     1538  if Page = pgLoad then
     1539    ReplayBtn.Visible := MiniMode <> mmMultiPlayer;
     1540  List.Invalidate;
     1541  SmartInvalidate(0, 0, ClientWidth, ClientHeight, invalidateTab0);
     1542end;
     1543
     1544procedure TStartDlg.ChangeTab(NewTab: integer);
     1545begin
     1546  Tab := NewTab;
     1547  case Tab of
     1548    1:
     1549      List.Items.Assign(Maps);
     1550    3:
     1551      List.Items.Assign(FormerGames);
     1552  end;
     1553  if Tab <> 2 then
     1554    if ListIndex[Tab] >= 0 then
     1555      List.ItemIndex := ListIndex[Tab]
    8161556    else
    817       begin
    818       inc(GameCount);
    819       FileName:=Format(Phrases.Lookup('GAME'),[GameCount]);
    820       end;
    821 
    822     // save settings and AI assignment
    823     if page=pgStartRandom then
    824       begin
    825       Reg.WriteInteger('WorldSize',WorldSize);
    826       Reg.WriteInteger('LandMass',StartLandMass);
    827       if AutoDiff<0 then
    828         for i:=0 to nPlOffered-1 do
    829           begin
    830           if bixView[i]=-1 then Reg.WriteString('Control'+IntToStr(i),'')
    831           else Reg.WriteString('Control'+IntToStr(i),Brain[bixView[i]].FileName);
    832           Reg.WriteInteger('Diff'+IntToStr(i),Difficulty[i]);
    833           end;
    834       Reg.WriteInteger('MultiControl',MultiControl);
    835       end;
    836 
    837     if AutoDiff>0 then
    838       begin
    839       Reg.WriteString('DefaultAI',Brain[bixDefault].FileName);
    840       SlotAvailable:=0; // bixView will be invalid hereafter
    841       bixView[0]:=bixTerm;
    842       Difficulty[0]:=PlayerAutoDiff[AutoDiff];
    843       for i:=1 to nPl-1 do
    844         if (Page=pgStartRandom) and (i<=AutoEnemies)
    845           or (Page=pgStartMap) and (i<nMapStartPositions) then
    846           begin
    847           if AutoDiff=1 then
    848             bixView[i]:=bixBeginner
    849           else bixView[i]:=bixDefault;
    850           Difficulty[i]:=EnemyAutoDiff[AutoDiff];
    851           end
    852         else bixView[i]:=-1;
    853       end
    854     else
    855       begin
    856       for i:=6 to 8 do
    857         if (bixView[0]<>bixNoTerm) and (MultiControl and (1 shl i)<>0) then
    858           begin
    859           bixView[i+3]:=bixView[i];
    860           Difficulty[i+3]:=Difficulty[i];
    861           bixView[i+6]:=bixView[i];
    862           Difficulty[i+6]:=Difficulty[i];
    863           end
    864         else
    865           begin
    866           bixView[i+3]:=-1;
    867           bixView[i+6]:=-1;
    868           end
    869       end;
    870 
    871     Reg.WriteInteger('AutoDiff',AutoDiff);
    872     Reg.WriteInteger('AutoEnemies',AutoEnemies);
    873     Reg.WriteInteger('MaxTurn',MaxTurn);
    874     Reg.WriteInteger('GameCount',GameCount);
    875     Reg.closekey;
    876     Reg.Free;
    877 
    878     StartNewGame(DataDir+'Saved\', FileName+'.cevo', MapFileName,
    879       lxpre[WorldSize], lypre[WorldSize], StartLandMass, MaxTurn);
    880     UnlistBackupFile(FileName);
    881     end;
    882 
    883   pgEditMap: EditMap(MapFileName, lxmax, lymax, StartLandMass);
    884 
    885   pgEditRandom: // new map
    886     begin
    887     Reg:=TRegistry.Create;
    888     Reg.OpenKey('SOFTWARE\cevo\RegVer9\Start',true);
    889     try
    890       MapCount:=Reg.ReadInteger('MapCount');
    891     except
    892       MapCount:=0;
    893       end;
    894     inc(MapCount);
    895     Reg.WriteInteger('MapCount',MapCount);
    896     Reg.closekey;
    897     Reg.Free;
    898     MapFileName:=Format(Phrases.Lookup('MAP'),[MapCount])+'.cevo map';
    899     EditMap(MapFileName, lxpre[WorldSize], lypre[WorldSize], StartLandMass);
    900     end
    901   end
    902 end;
    903 
    904 procedure TStartDlg.PaintInfo;
    905 
    906   procedure PaintRandomMini(Brightness: integer);
    907   type
    908   TLine=array[0..lxmax*2,0..2] of Byte;
    909   var
    910   i,x,y,xm,cm:integer;
    911   MiniLine:^TLine;
    912   Map: ^TTileList;
    913   begin
    914   Map:=PreviewMap(StartLandMass);
    915   MiniWidth:=lxpre[WorldSize]; MiniHeight:=lypre[WorldSize];
    916 
    917   Mini.PixelFormat:=pf24bit;
    918   Mini.Width:=MiniWidth*2;Mini.Height:=MiniHeight;
    919   for y:=0 to MiniHeight-1 do
    920     begin
    921     MiniLine:=Mini.ScanLine[y];
    922     for x:=0 to MiniWidth-1 do for i:=0 to 1 do
    923       begin
    924       xm:=(x*2+i+y and 1) mod (MiniWidth*2);
    925       cm:=MiniColors[Map[x*lxmax div MiniWidth
    926         +lxmax*((y*(lymax-1)+MiniHeight div 2) div (MiniHeight-1))] and fTerrain,i];
    927       MiniLine[xm,0]:=cm shr 16 *Brightness div 3;
    928       MiniLine[xm,1]:=cm shr 8 and $FF *Brightness div 3;
    929       MiniLine[xm,2]:=cm and $FF *Brightness div 3;
    930       end;
    931     end;
    932   end;
    933 
    934 var
    935 SaveMap: array[0..lxmax*lymax-1] of Byte;
    936 
    937   procedure PaintFileMini;
    938   type
    939   TLine=array[0..99999999,0..2] of Byte;
    940   var
    941   i,x,y,xm,cm,Tile,OwnColor,EnemyColor: integer;
    942   MiniLine,PrevMiniLine:^TLine;
    943   begin
    944   OwnColor:=GrExt[HGrSystem].Data.Canvas.Pixels[95,67];
    945   EnemyColor:=GrExt[HGrSystem].Data.Canvas.Pixels[96,67];
    946   Mini.PixelFormat:=pf24bit;
    947   Mini.Width:=MiniWidth*2;Mini.Height:=MiniHeight;
    948   if MiniMode=mmPicture then
    949     begin
    950     MiniLine:=nil;
    951     for y:=0 to MiniHeight-1 do
    952       begin
    953       PrevMiniLine:=MiniLine;
    954       MiniLine:=Mini.ScanLine[y];
    955       for x:=0 to MiniWidth-1 do for i:=0 to 1 do
    956         begin
    957         xm:=(x*2+i+y and 1) mod (MiniWidth*2);
    958         Tile:=SaveMap[x+MiniWidth*y];
    959         if Tile and fTerrain=fUNKNOWN then cm:=$000000
    960         else if Tile and smCity<>0 then
    961           begin
    962           if Tile and smOwned<>0 then cm:=OwnColor
    963           else cm:=EnemyColor;
    964           if PrevMiniLine<>nil then
    965             begin // 2x2 city dot covers two scanlines
    966             PrevMiniLine[xm,0]:=cm shr 16;
    967             PrevMiniLine[xm,1]:=cm shr 8 and $FF;
    968             PrevMiniLine[xm,2]:=cm and $FF;
    969             end
    970           end
    971         else if (i=0) and (Tile and smUnit<>0) then
    972           if Tile and smOwned<>0 then cm:=OwnColor
    973           else cm:=EnemyColor
    974         else cm:=MiniColors[Tile and fTerrain,i];
    975         MiniLine[xm,0]:=cm shr 16;
    976         MiniLine[xm,1]:=cm shr 8 and $FF;
    977         MiniLine[xm,2]:=cm and $FF;
    978         end;
    979       end
    980     end;
    981   end;
    982 
    983 var
    984 x,y,dummy, FileLandMass, lxFile, lyFile: integer;
    985 LogFile, MapFile: file;
    986 s: string[255];
    987 MapRow: array[0..lxmax-1] of Cardinal;
    988 
    989 begin
    990 case Page of
    991   pgStartRandom:
    992     begin
    993     MiniMode:=mmPicture;
    994     PaintRandomMini(3);
    995     end;
    996 
    997   pgNoLoad:
    998     begin
    999     MiniWidth:=lxpre[DefaultWorldSize]; MiniHeight:=lypre[DefaultWorldSize];
    1000     MiniMode:=mmNone;
    1001     end;
    1002 
    1003   pgLoad:
    1004     begin
    1005     AssignFile(LogFile,DataDir+'Saved\'+List.Items[List.ItemIndex]+'.cevo');
    1006     try
    1007       Reset(LogFile,4);
    1008       BlockRead(LogFile,s[1],2); {file id}
    1009       BlockRead(LogFile,dummy,1); {format id}
    1010       if dummy>=$000E01 then
    1011         BlockRead(LogFile,dummy,1); {item stored since 0.14.1}
    1012       BlockRead(LogFile,MiniWidth,1);
    1013       BlockRead(LogFile,MiniHeight,1);
    1014       BlockRead(LogFile,FileLandMass,1);
    1015       if FileLandMass=0 then
    1016         for y:=0 to MiniHeight-1 do BlockRead(LogFile,MapRow,MiniWidth);
    1017       BlockRead(LogFile,dummy,1);
    1018       BlockRead(LogFile,dummy,1);
    1019       BlockRead(LogFile,LastTurn,1);
    1020       BlockRead(LogFile,SaveMap,1);
    1021       if SaveMap[0]=$80 then MiniMode:=mmMultiPlayer
    1022       else MiniMode:=mmPicture;
    1023       if MiniMode=mmPicture then BlockRead(LogFile,SaveMap[4],(MiniWidth*MiniHeight-1) div 4);
    1024       CloseFile(LogFile);
    1025     except
    1026       CloseFile(LogFile);
    1027       LastTurn:=0;
    1028       MiniWidth:=lxpre[DefaultWorldSize]; MiniHeight:=lypre[DefaultWorldSize];
    1029       MiniMode:=mmNone;
    1030       end;
    1031     //BookDate:=DateToStr(FileDateToDateTime(FileAge(FileName)));
    1032     PaintFileMini;
    1033     if not TurnValid then
    1034       begin
    1035       LoadTurn:=LastTurn;
    1036       SmartInvalidate(xTurnSlider-2,y0Mini+61,xTurnSlider+wTurnSlider+2,yTurnSlider+9);
    1037       end;
    1038     TurnValid:=true;
    1039     end;
    1040 
    1041   pgEditRandom:
    1042     begin
    1043     MapFileName:='';
    1044     MiniMode:=mmPicture;
    1045     PaintRandomMini(4);
    1046     end;
    1047 
    1048   pgStartMap,pgEditMap:
    1049     begin
    1050     MiniMode:=mmPicture;
    1051     if Page=pgEditMap then MapFileName:=List.Items[List.ItemIndex]+'.cevo map';
    1052     if LoadGraphicFile(Mini, DataDir+'Maps\'+Copy(MapFileName,1,Length(MapFileName)-9), gfNoError) then
    1053       begin
    1054       if Mini.Width div 2>MaxWidthMapLogo then Mini.Width:=MaxWidthMapLogo*2;
    1055       if Mini.Height>MaxHeightMapLogo then Mini.Height:=MaxHeightMapLogo;
    1056       MiniWidth:=Mini.Width div 2;
    1057       MiniHeight:=Mini.Height;
    1058       end
    1059     else
    1060       begin
    1061       MiniMode:=mmNone;
    1062       MiniWidth:=MaxWidthMapLogo; MiniHeight:=MaxHeightMapLogo;
    1063       end;
    1064 
    1065     AssignFile(MapFile,DataDir+'Maps\'+MapFileName);
    1066     try
    1067       Reset(MapFile,4);
    1068       BlockRead(MapFile,s[1],2); {file id}
    1069       BlockRead(MapFile,x,1); {format id}
    1070       BlockRead(MapFile,x,1); //MaxTurn
    1071       BlockRead(MapFile,lxFile,1);
    1072       BlockRead(MapFile,lyFile,1);
    1073       nMapLandTiles:=0;
    1074       nMapStartPositions:=0;
    1075       for y:=0 to lyFile-1 do
    1076         begin
    1077         BlockRead(MapFile,MapRow,lxFile);
    1078         for x:=0 to lxFile-1 do
    1079           begin
    1080           if (MapRow[x] and fTerrain) in
    1081             [fGrass,fPrairie,fTundra,fSwamp,fForest,fHills] then
    1082             inc(nMapLandTiles);
    1083           if MapRow[x] and (fPrefStartPos or fStartPos)<>0 then
    1084             inc(nMapStartPositions);
    1085           end
    1086         end;
    1087       if nMapStartPositions>nPl then nMapStartPositions:=nPl;
    1088       CloseFile(MapFile);
    1089     except
    1090       CloseFile(MapFile);
    1091       end;
    1092     if Page=pgEditMap then
    1093       SmartInvalidate(x0Mini-112,y0Mini+61,x0Mini+112,y0Mini+91);
    1094     end
    1095   end;
    1096 SmartInvalidate(x0Mini-lxmax,y0Mini-lymax div 2,
    1097   x0Mini-lxmax+2*lxmax+4,y0Mini-lymax div 2+lymax+4);
    1098 end;
    1099 
    1100 procedure TStartDlg.BrainClick(Sender: TObject);
    1101 var
    1102 i: integer;
    1103 begin
    1104 //Play('BUTTON_UP');
    1105 if bixPopup<0 then
    1106   begin // change default AI
    1107   bixDefault:=TMenuItem(Sender).Tag;
    1108   SmartInvalidate(xDefault,yDefault,xDefault+64,yDefault+64);
    1109   end
    1110 else
    1111   begin
    1112   Brain[bixView[bixPopup]].Flags:=Brain[bixView[bixPopup]].Flags and not fUsed;
    1113   bixView[bixPopup]:=TMenuItem(Sender).Tag;
    1114   DiffUpBtn[bixPopup].Visible:= bixView[bixPopup]>=bixTerm;
    1115   DiffDownBtn[bixPopup].Visible:= bixView[bixPopup]>=bixTerm;
    1116   if bixPopup in OfferMultiple then
    1117     begin
    1118     MultiBtn[bixPopup].Visible:= bixView[bixPopup]>=bixTerm;
    1119     MultiBtn[bixPopup].ButtonIndex:=2+(MultiControl shr bixPopup) and 1;
    1120     end;
    1121   Brain[bixView[bixPopup]].Flags:=Brain[bixView[bixPopup]].Flags or fUsed;
    1122   if bixView[bixPopup]<bixTerm then Difficulty[bixPopup]:=0 {supervisor}
    1123   else Difficulty[bixPopup]:=2;
    1124   if (Page=pgStartRandom) and (bixPopup in OfferMultiple)
    1125     and (bixView[bixPopup]<0) then
    1126     MultiControl:=MultiControl and not (1 shl bixPopup);
    1127   if (bixPopup=0) and (MapFileName<>'') then ChangePage(Page);
    1128   if bixView[bixPopup]=bixNoTerm then
    1129     begin // turn all local players off
    1130     for i:=1 to nPlOffered-1 do if bixView[i]=bixTerm then
    1131       begin
    1132       bixView[i]:=-1;
    1133       DiffUpBtn[i].Visible:=false;
    1134       DiffUpBtn[i].Tag:=0;
    1135       DiffDownBtn[i].Visible:=false;
    1136       DiffDownBtn[i].Tag:=0;
    1137       if i in OfferMultiple then
    1138         begin
    1139         MultiBtn[i].Visible:=false;
    1140         MultiBtn[i].Tag:=0;
    1141         end;
    1142       SmartInvalidate(xBrain[i]-31,yBrain[i]-1,xBrain[i]+64,DiffUpBtn[i].Top+25);
    1143       end;
    1144     Brain[bixTerm].Flags:=Brain[bixTerm].Flags and not fUsed;
    1145     end;
    1146   SmartInvalidate(xBrain[bixPopup]-31,yBrain[bixPopup]-1,xBrain[bixPopup]+64,
    1147     DiffUpBtn[bixPopup].Top+25);
    1148   end
    1149 end;
    1150 
    1151 procedure TStartDlg.InitPopup(PopupIndex: integer);
    1152 var
    1153 i, FixedLines: integer;
    1154 m: TMenuItem;
    1155 
    1156   procedure OfferBrain(Index: integer);
    1157   var
    1158   j: integer;
    1159   begin
    1160   m:=TMenuItem.Create(PopupMenu1);
    1161   if Index<0 then m.Caption:=Phrases.Lookup('NOMOD')
    1162   else m.Caption:=Brain[Index].Name;
    1163   m.Tag:=Index;
    1164   m.OnClick:=BrainClick;
    1165   j:=FixedLines;
    1166   while (j<PopupMenu1.Items.Count) and (StrIComp(pchar(m.Caption),
    1167     pchar(PopupMenu1.Items[j].Caption))>0) do inc(j);
    1168   m.RadioItem:=true;
    1169   if bixPopup<0 then m.Checked:= bixDefault=Index
    1170   else m.Checked:= bixView[bixPopup]=Index;
    1171   PopupMenu1.Items.Insert(j,m);
    1172   end;
    1173 
    1174 begin
    1175 bixPopup:=PopupIndex;
    1176 EmptyMenu(PopupMenu1.Items);
    1177 if bixPopup<0 then
    1178   begin // select default AI
    1179   FixedLines:=0;
    1180   if nBrain>=bixFirstAI+2 then
    1181     begin OfferBrain(bixRandom); inc(FixedLines) end;
    1182   for i:=bixFirstAI to nBrain-1 do // offer available AIs
    1183     if Brain[i].Flags and fMultiple<>0 then
    1184       OfferBrain(i);
    1185   end
    1186 else
    1187   begin
    1188   FixedLines:=0;
    1189   if bixPopup>0 then begin OfferBrain(-1); inc(FixedLines); end;
    1190   for i:=bixTerm downto 0 do // offer game interfaces
    1191     if (bixPopup=0) or (i=bixTerm) and (bixView[0]<>bixNoTerm) then
    1192       begin OfferBrain(i); inc(FixedLines); end;
    1193   if bixPopup>0 then
    1194     begin
    1195     m:=TMenuItem.Create(PopupMenu1);
    1196     m.Caption:='-';
    1197     PopupMenu1.Items.Add(m);
    1198     inc(FixedLines);
    1199     if nBrain>=bixFirstAI+2 then
    1200       begin OfferBrain(bixRandom); inc(FixedLines); end;
    1201     for i:=bixFirstAI to nBrain-1 do // offer available AIs
    1202       if (Brain[i].Flags and fMultiple<>0) or (Brain[i].Flags and fUsed=0)
    1203         or (i=bixView[bixPopup]) then
    1204         OfferBrain(i);
    1205     end;
    1206   end
    1207 end;
    1208 
    1209 procedure TStartDlg.UpdateFormerGames;
    1210 var
    1211 i: integer;
    1212 f: TSearchRec;
    1213 begin
    1214 FormerGames.Clear;
    1215 if FindFirst(DataDir+'Saved\*.cevo',$21,f)=0 then
    1216   repeat
    1217     i:=FormerGames.Count;
    1218     while (i>0) and (f.Time<integer(FormerGames.Objects[i-1])) do
    1219       dec(i);
    1220     FormerGames.InsertObject(i,Copy(f.Name,1,Length(f.Name)-5),
    1221       TObject(f.Time));
    1222   until FindNext(f)<>0;
    1223 ListIndex[2]:=FormerGames.Count-1;
    1224 if (ShowTab=2) and (FormerGames.Count>0) then ShowTab:=3;
    1225 TurnValid:=false;
    1226 end;
    1227 
    1228 procedure TStartDlg.UpdateMaps;
    1229 var
    1230 f: TSearchRec;
    1231 begin
    1232 Maps.Clear;
    1233 if FindFirst(DataDir+'Maps\*.cevo map',$21,f)=0 then
    1234   repeat
    1235     Maps.Add(Copy(f.Name,1,Length(f.Name)-9));
    1236   until FindNext(f)<>0;
    1237 Maps.Sort;
    1238 Maps.Insert(0,Phrases.Lookup('RANMAP'));
    1239 ListIndex[0]:=Maps.IndexOf(Copy(MapFileName,1,Length(MapFileName)-9));
    1240 if ListIndex[0]<0 then ListIndex[0]:=0;
    1241 end;
    1242 
    1243 procedure TStartDlg.ChangePage(NewPage: integer);
    1244 var
    1245 i,j,p1: integer;
    1246 s: string;
    1247 Reg: TRegistry;
    1248 invalidateTab0: boolean;
    1249 begin
    1250 invalidateTab0:= (Page=pgMain) or (NewPage=pgMain);
    1251 Page:=NewPage;
    1252 case Page of
    1253   pgStartRandom, pgStartMap:
    1254     begin
    1255     StartBtn.Caption:=Phrases.Lookup('STARTCONTROLS',1);
    1256     if Page=pgStartRandom then i:=nPlOffered
    1257     else
    1258       begin
    1259       i:=nMapStartPositions;
    1260       if i=0 then begin bixView[0]:=bixSuper_Virtual; Difficulty[0]:=0 end;
    1261       if bixView[0]<bixTerm then inc(i);
    1262       if i>nPl then i:=nPl;
    1263       if i<=nPlOffered then MultiControl:=0
    1264       else MultiControl:=InitMulti[i];
    1265       end;
    1266     if InitAlive[i]<>SlotAvailable then
    1267       if Page=pgStartRandom then
    1268         begin // restore AI assignment of last start
    1269         Reg:=TRegistry.Create;
    1270         Reg.OpenKey('SOFTWARE\cevo\RegVer9\Start',false);
    1271         for p1:=0 to nPlOffered-1 do
    1272           begin
    1273           bixView[p1]:=-1;
    1274           s:=Reg.ReadString('Control'+IntToStr(p1));
    1275           Difficulty[p1]:=Reg.ReadInteger('Diff'+IntToStr(p1));
    1276           if s<>'' then
    1277             for j:=0 to nBrain-1 do
    1278               if AnsiCompareFileName(s,Brain[j].FileName)=0 then bixView[p1]:=j;
    1279           end;
    1280         MultiControl:=Reg.ReadInteger('MultiControl');
    1281         Reg.closekey;
    1282         Reg.Free;
    1283         end
     1557      List.ItemIndex := 0;
     1558  case Tab of
     1559    0:
     1560      ChangePage(pgMain);
     1561    1:
     1562      if List.ItemIndex = 0 then
     1563        ChangePage(pgEditRandom)
    12841564      else
    1285         for p1:=1 to nPl-1 do
    1286           if 1 shl p1 and InitAlive[i]<>0 then
    1287             begin bixView[p1]:=bixDefault; Difficulty[p1]:=2; end
    1288           else bixView[p1]:=-1;
    1289     SlotAvailable:=InitAlive[i];
    1290     for i:=0 to nPlOffered-1 do
    1291       if (AutoDiff<0) and (bixView[i]>=bixTerm) then
    1292         begin DiffUpBtn[i].Tag:=768; DiffDownBtn[i].Tag:=768; end
    1293       else begin DiffUpBtn[i].Tag:=0; DiffDownBtn[i].Tag:=0; end;
    1294     for i:=6 to 8 do
    1295       if (AutoDiff<0) and (bixView[i]>=bixTerm) then
    1296         begin
    1297         MultiBtn[i].Tag:=768;
    1298         MultiBtn[i].ButtonIndex:=2+(MultiControl shr i) and 1;
    1299         MultiBtn[i].Enabled:=Page=pgStartRandom
    1300         end
    1301       else MultiBtn[i].Tag:=0;
    1302     if (AutoDiff>0) and (Page<>pgStartMap) then
    1303       begin
    1304       AutoEnemyUpBtn.Tag:=768;
    1305       AutoEnemyDownBtn.Tag:=768;
    1306       end
    1307     else
    1308       begin
    1309       AutoEnemyUpBtn.Tag:=0;
    1310       AutoEnemyDownBtn.Tag:=0;
    1311       end;
    1312     if AutoDiff>0 then
    1313       begin
    1314       AutoDiffUpBtn.Tag:=768;
    1315       AutoDiffDownBtn.Tag:=768;
    1316       end
    1317     else
    1318       begin
    1319       AutoDiffUpBtn.Tag:=0;
    1320       AutoDiffDownBtn.Tag:=0;
    1321       end
    1322     end;
    1323 
    1324   pgNoLoad,pgLoad:
    1325     begin
    1326     StartBtn.Caption:=Phrases.Lookup('STARTCONTROLS',2);
    1327     RenameBtn.Hint:=Phrases.Lookup('BTN_RENGAME');
    1328     DeleteBtn.Hint:=Phrases.Lookup('BTN_DELGAME');
    1329     end;
    1330 
    1331   pgEditRandom,pgEditMap:
    1332     begin
    1333     StartBtn.Caption:=Phrases.Lookup('STARTCONTROLS',12);
    1334     RenameBtn.Hint:=Phrases.Lookup('BTN_RENMAP');
    1335     DeleteBtn.Hint:=Phrases.Lookup('BTN_DELMAP');
    1336     end;
    1337   end;
    1338 
    1339 PaintInfo;
    1340 for i:=0 to ControlCount-1 do
    1341   Controls[i].Visible:= Controls[i].Tag and (256 shl Page)<>0;
    1342 if Page=pgLoad then
    1343   ReplayBtn.Visible:= MiniMode<>mmMultiPlayer;
    1344 List.Invalidate;
    1345 SmartInvalidate(0,0,ClientWidth,ClientHeight,invalidateTab0);
    1346 end;
    1347 
    1348 procedure TStartDlg.ChangeTab(NewTab: integer);
    1349 begin
    1350 Tab:=NewTab;
    1351 case Tab of
    1352   1: List.Items.Assign(Maps);
    1353   3: List.Items.Assign(FormerGames);
    1354   end;
    1355 if Tab<>2 then
    1356   if ListIndex[Tab]>=0 then List.ItemIndex:=ListIndex[Tab]
    1357   else List.ItemIndex:=0;
    1358 case Tab of
    1359   0: ChangePage(pgMain);
    1360   1:
    1361     if List.ItemIndex=0 then ChangePage(pgEditRandom)
    1362     else ChangePage(pgEditMap);
    1363   2:
    1364     if MapFileName='' then ChangePage(pgStartRandom)
    1365     else ChangePage(pgStartMap);
    1366   3:
    1367     if FormerGames.Count=0 then ChangePage(pgNoLoad)
    1368     else ChangePage(pgLoad);
     1565        ChangePage(pgEditMap);
     1566    2:
     1567      if MapFileName = '' then
     1568        ChangePage(pgStartRandom)
     1569      else
     1570        ChangePage(pgStartMap);
     1571    3:
     1572      if FormerGames.Count = 0 then
     1573        ChangePage(pgNoLoad)
     1574      else
     1575        ChangePage(pgLoad);
    13691576  end;
    13701577end;
     
    13731580  Shift: TShiftState; x, y: integer);
    13741581var
    1375 i: integer;
    1376 begin
    1377 if (y<TabHeight+1) and (x-TabOffset<TabSize*4) and ((x-TabOffset) div TabSize<>Tab) then
    1378   begin
    1379 //  Play('BUTTON_DOWN');
    1380   ListIndex[Tab]:=List.ItemIndex;
    1381   ChangeTab((x-TabOffset) div TabSize);
    1382   end
    1383 else if page=pgMain then
    1384   begin
    1385   case SelectedAction of
    1386     maConfig:
    1387       begin
    1388       ShellExecute(Handle,'open',pchar(HomeDir+'Configurator.exe'),
    1389         pchar('-r"'+paramstr(0)+'"'),'',SW_SHOWNORMAL);
    1390       Close
    1391       end;
    1392     maManual: DirectHelp(cStartHelp);
    1393     maCredits: DirectHelp(cStartCredits);
    1394     maAIDev: ShellExecute(Handle,'open',
    1395       pchar(HomeDir+'AI Template\AI development manual.html'),'','',
    1396       SW_SHOWNORMAL);
    1397     maWeb:ShellExecute(Handle,'open','http://c-evo.org','','',SW_SHOWNORMAL)
     1582  i: integer;
     1583begin
     1584  if (y < TabHeight + 1) and (x - TabOffset < TabSize * 4) and
     1585    ((x - TabOffset) div TabSize <> Tab) then
     1586  begin
     1587    // Play('BUTTON_DOWN');
     1588    ListIndex[Tab] := List.ItemIndex;
     1589    ChangeTab((x - TabOffset) div TabSize);
     1590  end
     1591  else if Page = pgMain then
     1592  begin
     1593    case SelectedAction of
     1594      maConfig:
     1595        begin
     1596          ShellExecute(Handle, 'open', pchar(HomeDir + 'Configurator.exe'),
     1597            pchar('-r"' + ParamStr(0) + '"'), '', SW_SHOWNORMAL);
     1598          Close
     1599        end;
     1600      maManual:
     1601        DirectHelp(cStartHelp);
     1602      maCredits:
     1603        DirectHelp(cStartCredits);
     1604      maAIDev:
     1605        ShellExecute(Handle, 'open',
     1606          pchar(HomeDir + 'AI Template\AI development manual.html'), '', '',
     1607          SW_SHOWNORMAL);
     1608      maWeb:
     1609        ShellExecute(Handle, 'open', 'http://c-evo.org', '', '', SW_SHOWNORMAL)
    13981610    end;
    13991611  end
    1400 else if (AutoDiff<0) and ((page=pgStartRandom)
    1401   or (page=pgStartMap) and (nMapStartPositions>0)) then
    1402   begin
    1403   for i:=0 to nPlOffered-1 do
    1404     if (1 shl i and SlotAvailable<>0) and (x>=xBrain[i]) and (y>=yBrain[i])
    1405       and (x<xBrain[i]+64) and (y<yBrain[i]+64) then
    1406       begin
    1407       InitPopup(i);
    1408       if yBrain[i]>y0Brain then
    1409         PopupMenu1.Popup(Left+xBrain[i]+4,Top+yBrain[i]+60)
    1410       else PopupMenu1.Popup(Left+xBrain[i]+4,Top+yBrain[i]+4);
     1612  else if (AutoDiff < 0) and ((Page = pgStartRandom) or (Page = pgStartMap) and
     1613    (nMapStartPositions > 0)) then
     1614  begin
     1615    for i := 0 to nPlOffered - 1 do
     1616      if (1 shl i and SlotAvailable <> 0) and (x >= xBrain[i]) and
     1617        (y >= yBrain[i]) and (x < xBrain[i] + 64) and (y < yBrain[i] + 64) then
     1618      begin
     1619        InitPopup(i);
     1620        if yBrain[i] > y0Brain then
     1621          PopupMenu1.Popup(left + xBrain[i] + 4, top + yBrain[i] + 60)
     1622        else
     1623          PopupMenu1.Popup(left + xBrain[i] + 4, top + yBrain[i] + 4);
    14111624      end
    14121625  end
    1413 else if (AutoDiff>1) and ((page=pgStartRandom) or (page=pgStartMap))
    1414   and (x>=xDefault) and (y>=yDefault) and (x<xDefault+64) and (y<yDefault+64) then
    1415     if nBrain<bixFirstAI+2 then
     1626  else if (AutoDiff > 1) and ((Page = pgStartRandom) or (Page = pgStartMap)) and
     1627    (x >= xDefault) and (y >= yDefault) and (x < xDefault + 64) and
     1628    (y < yDefault + 64) then
     1629    if nBrain < bixFirstAI + 2 then
    14161630      SimpleMessage(Phrases.Lookup('NOALTAI'))
    14171631    else
    1418       begin
     1632    begin
    14191633      InitPopup(-1);
    1420       PopupMenu1.Popup(Left+xDefault+4,Top+yDefault+4);
     1634      PopupMenu1.Popup(left + xDefault + 4, top + yDefault + 4);
     1635    end
     1636  else if (Page = pgLoad) and (LastTurn > 0) and (y >= yTurnSlider) and
     1637    (y < yTurnSlider + 7) and (x >= xTurnSlider) and
     1638    (x <= xTurnSlider + wTurnSlider) then
     1639  begin
     1640    LoadTurn := LastTurn * (x - xTurnSlider) div wTurnSlider;
     1641    SmartInvalidate(xTurnSlider - 2, y0Mini + 61, xTurnSlider + wTurnSlider + 2,
     1642      yTurnSlider + 9);
     1643    Tracking := true
     1644  end
     1645end;
     1646
     1647procedure TStartDlg.Up2BtnClick(Sender: TObject);
     1648begin
     1649  case Page of
     1650    pgStartRandom, pgStartMap:
     1651      if MaxTurn < 1400 then
     1652      begin
     1653        inc(MaxTurn, 200);
     1654        SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 82);
     1655      end;
     1656    pgLoad:
     1657      if LoadTurn < LastTurn then
     1658      begin
     1659        inc(LoadTurn);
     1660        SmartInvalidate(xTurnSlider - 2, y0Mini + 61, xTurnSlider + wTurnSlider
     1661          + 2, yTurnSlider + 9);
     1662      end;
     1663    pgEditRandom:
     1664      if StartLandMass < 96 then
     1665      begin
     1666        inc(StartLandMass, 5);
     1667        PaintInfo;
     1668        SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 61 + 21);
     1669      end;
     1670  end
     1671end;
     1672
     1673procedure TStartDlg.Down2BtnClick(Sender: TObject);
     1674begin
     1675  case Page of
     1676    pgStartRandom, pgStartMap:
     1677      if MaxTurn > 400 then
     1678      begin
     1679        dec(MaxTurn, 200);
     1680        SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 82);
     1681      end;
     1682    pgLoad:
     1683      if LoadTurn > 0 then
     1684      begin
     1685        dec(LoadTurn);
     1686        SmartInvalidate(xTurnSlider - 2, y0Mini + 61, xTurnSlider + wTurnSlider
     1687          + 2, yTurnSlider + 9);
     1688      end;
     1689    pgEditRandom:
     1690      if StartLandMass > 10 then
     1691      begin
     1692        dec(StartLandMass, 5);
     1693        PaintInfo;
     1694        SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 61 + 21);
    14211695      end
    1422 else if (page=pgLoad) and (LastTurn>0) and (y>=yTurnSlider) and (y<yTurnSlider+7)
    1423   and (x>=xTurnSlider) and (x<=xTurnSlider+wTurnSlider) then
    1424     begin
    1425     LoadTurn:=LastTurn*(x-xTurnSlider) div wTurnSlider;
    1426     SmartInvalidate(xTurnSlider-2,y0Mini+61,xTurnSlider+wTurnSlider+2,yTurnSlider+9);
    1427     Tracking:=true
    1428     end
    1429 end;
    1430 
    1431 procedure TStartDlg.Up2BtnClick(Sender: TObject);
    1432 begin
    1433 case Page of
    1434   pgStartRandom,pgStartMap:
    1435     if MaxTurn<1400 then
    1436       begin
    1437       inc(MaxTurn,200);
    1438       SmartInvalidate(344,y0Mini+61,514,y0Mini+82);
     1696  end
     1697end;
     1698
     1699procedure TStartDlg.Up1BtnClick(Sender: TObject);
     1700begin
     1701  if WorldSize < nWorldSize - 1 then
     1702  begin
     1703    inc(WorldSize);
     1704    PaintInfo;
     1705    SmartInvalidate(344, y0Mini - 77, 510, y0Mini - 77 + 21);
     1706  end
     1707end;
     1708
     1709procedure TStartDlg.Down1BtnClick(Sender: TObject);
     1710begin
     1711  if WorldSize > 0 then
     1712  begin
     1713    dec(WorldSize);
     1714    PaintInfo;
     1715    SmartInvalidate(344, y0Mini - 77, 510, y0Mini - 77 + 21);
     1716  end
     1717end;
     1718
     1719procedure TStartDlg.FormClose(Sender: TObject; var Action: TCloseAction);
     1720begin
     1721  DirectDlg.Close
     1722end;
     1723
     1724procedure TStartDlg.ListClick(Sender: TObject);
     1725var
     1726  i: integer;
     1727begin
     1728  if (Tab = 1) and ((List.ItemIndex = 0) <> (Page = pgEditRandom)) then
     1729  begin
     1730    if List.ItemIndex = 0 then
     1731      Page := pgEditRandom
     1732    else
     1733      Page := pgEditMap;
     1734    for i := 0 to ControlCount - 1 do
     1735      Controls[i].Visible := Controls[i].Tag and (256 shl Page) <> 0;
     1736    SmartInvalidate(328, Up1Btn.top - 12, ClientWidth, Up2Btn.top + 35);
     1737  end;
     1738  if Page = pgLoad then
     1739    TurnValid := false;
     1740  PaintInfo;
     1741  if Page = pgLoad then
     1742    ReplayBtn.Visible := MiniMode <> mmMultiPlayer;
     1743end;
     1744
     1745procedure TStartDlg.RenameBtnClick(Sender: TObject);
     1746var
     1747  i: integer;
     1748  NewName: string;
     1749  f: file;
     1750  ok: boolean;
     1751begin
     1752  if List.ItemIndex >= 0 then
     1753  begin
     1754    if Page = pgLoad then
     1755      InputDlg.Caption := Phrases.Lookup('TITLE_BOOKNAME')
     1756    else
     1757      InputDlg.Caption := Phrases.Lookup('TITLE_MAPNAME');
     1758    InputDlg.EInput.Text := List.Items[List.ItemIndex];
     1759    InputDlg.CenterToRect(BoundsRect);
     1760    InputDlg.ShowModal;
     1761    NewName := InputDlg.EInput.Text;
     1762    while (NewName <> '') and (NewName[1] = '~') do
     1763      Delete(NewName, 1, 1);
     1764    if (InputDlg.ModalResult = mrOK) and (NewName <> '') and
     1765      (NewName <> List.Items[List.ItemIndex]) then
     1766    begin
     1767      for i := 1 to Length(NewName) do
     1768        if NewName[i] in ['\', '/', ':', '*', '?', '"', '<', '>', '|'] then
     1769        begin
     1770          SimpleMessage(Format(Phrases.Lookup('NOFILENAME'), [NewName[i]]));
     1771          exit
     1772        end;
     1773      if Page = pgLoad then
     1774        AssignFile(f, DataDir + 'Saved\' + List.Items[List.ItemIndex] + '.cevo')
     1775      else
     1776        AssignFile(f, DataDir + 'Maps\' + List.Items[List.ItemIndex] +
     1777          '.cevo map');
     1778      ok := true;
     1779      try
     1780        if Page = pgLoad then
     1781          Rename(f, DataDir + 'Saved\' + NewName + '.cevo')
     1782        else
     1783          Rename(f, DataDir + 'Maps\' + NewName + '.cevo map');
     1784      except
     1785        // Play('INVALID');
     1786        ok := false
    14391787      end;
    1440   pgLoad:
    1441     if LoadTurn<LastTurn then
    1442       begin
    1443       inc(LoadTurn);
    1444       SmartInvalidate(xTurnSlider-2,y0Mini+61,xTurnSlider+wTurnSlider+2,yTurnSlider+9);
    1445       end;
    1446   pgEditRandom:
    1447     if StartLandMass<96 then
    1448       begin
    1449       inc(StartLandMass,5);
    1450       PaintInfo;
    1451       SmartInvalidate(344,y0Mini+61,514,y0Mini+61+21);
    1452       end;
    1453   end
    1454 end;
    1455 
    1456 procedure TStartDlg.Down2BtnClick(Sender: TObject);
    1457 begin
    1458 case Page of
    1459   pgStartRandom,pgStartMap:
    1460     if MaxTurn>400 then
    1461       begin
    1462       dec(MaxTurn,200);
    1463       SmartInvalidate(344,y0Mini+61,514,y0Mini+82);
    1464       end;
    1465   pgLoad:
    1466     if LoadTurn>0 then
    1467       begin
    1468       dec(LoadTurn);
    1469       SmartInvalidate(xTurnSlider-2,y0Mini+61,xTurnSlider+wTurnSlider+2,yTurnSlider+9);
    1470       end;
    1471   pgEditRandom:
    1472     if StartLandMass>10 then
    1473       begin
    1474       dec(StartLandMass,5);
    1475       PaintInfo;
    1476       SmartInvalidate(344,y0Mini+61,514,y0Mini+61+21);
    1477       end
    1478   end
    1479 end;
    1480 
    1481 procedure TStartDlg.Up1BtnClick(Sender: TObject);
    1482 begin
    1483 if WorldSize<nWorldSize-1 then
    1484   begin
    1485   inc(WorldSize);
    1486   PaintInfo;
    1487   SmartInvalidate(344,y0Mini-77,510,y0Mini-77+21);
    1488   end
    1489 end;
    1490 
    1491 procedure TStartDlg.Down1BtnClick(Sender: TObject);
    1492 begin
    1493 if WorldSize>0 then
    1494   begin
    1495   dec(WorldSize);
    1496   PaintInfo;
    1497   SmartInvalidate(344,y0Mini-77,510,y0Mini-77+21);
    1498   end
    1499 end;
    1500 
    1501 procedure TStartDlg.FormClose(Sender: TObject; var Action: TCloseAction);
    1502 begin
    1503 DirectDlg.Close
    1504 end;
    1505 
    1506 procedure TStartDlg.ListClick(Sender: TObject);
    1507 var
    1508 i: integer;
    1509 begin
    1510 if (Tab=1) and ((List.ItemIndex=0)<>(Page=pgEditRandom)) then
    1511   begin
    1512   if List.ItemIndex=0 then Page:=pgEditRandom
    1513   else Page:=pgEditMap;
    1514   for i:=0 to ControlCount-1 do
    1515     Controls[i].Visible:= Controls[i].Tag and (256 shl Page)<>0;
    1516   SmartInvalidate(328,Up1Btn.Top-12,ClientWidth,Up2Btn.Top+35);
    1517   end;
    1518 if Page=pgLoad then TurnValid:=false;
    1519 PaintInfo;
    1520 if Page=pgLoad then
    1521   ReplayBtn.Visible:= MiniMode<>mmMultiPlayer;
    1522 end;
    1523 
    1524 procedure TStartDlg.RenameBtnClick(Sender: TObject);
    1525 var
    1526 i: integer;
    1527 NewName: string;
    1528 f: file;
    1529 ok: boolean;
    1530 begin
    1531 if List.ItemIndex>=0 then
    1532   begin
    1533   if Page=pgLoad then InputDlg.Caption:=Phrases.Lookup('TITLE_BOOKNAME')
    1534   else InputDlg.Caption:=Phrases.Lookup('TITLE_MAPNAME');
    1535   InputDlg.EInput.Text:=List.Items[List.ItemIndex];
    1536   InputDlg.CenterToRect(BoundsRect);
    1537   InputDlg.ShowModal;
    1538   NewName:=InputDlg.EInput.Text;
    1539   while (NewName<>'') and (NewName[1]='~') do delete(NewName,1,1);
    1540   if (InputDlg.ModalResult=mrOK) and (NewName<>'')
    1541     and (NewName<>List.Items[List.ItemIndex]) then
    1542     begin
    1543     for i:=1 to Length(NewName) do
    1544       if NewName[i] in ['\','/',':','*','?','"','<','>','|'] then
    1545         begin
    1546         SimpleMessage(Format(Phrases.Lookup('NOFILENAME'),[NewName[i]]));
    1547         exit
    1548         end;
    1549     if Page=pgLoad then
    1550       AssignFile(f,DataDir+'Saved\'+List.Items[List.ItemIndex]+'.cevo')
    1551     else AssignFile(f,DataDir+'Maps\'+List.Items[List.ItemIndex]+'.cevo map');
    1552     ok:=true;
    1553     try
    1554       if Page=pgLoad then
    1555         Rename(f,DataDir+'Saved\'+NewName+'.cevo')
    1556       else Rename(f,DataDir+'Maps\'+NewName+'.cevo map');
    1557     except
    1558 //      Play('INVALID');
    1559       ok:=false
    1560       end;
    1561     if Page<>pgLoad then
    1562       try // rename map picture
    1563         AssignFile(f,DataDir+'Maps\'+List.Items[List.ItemIndex]+'.bmp');
    1564         Rename(f,DataDir+'Maps\'+NewName+'.bmp');
    1565       except
    1566         end;
    1567     if ok then
    1568       begin
    1569       if Page=pgLoad then
    1570         FormerGames[List.ItemIndex]:=NewName
    1571       else Maps[List.ItemIndex]:=NewName;
    1572       List.Items[List.ItemIndex]:=NewName;
    1573       if Page=pgEditMap then PaintInfo;
    1574       List.Invalidate;
     1788      if Page <> pgLoad then
     1789        try // rename map picture
     1790          AssignFile(f, DataDir + 'Maps\' + List.Items[List.ItemIndex]
     1791            + '.bmp');
     1792          Rename(f, DataDir + 'Maps\' + NewName + '.bmp');
     1793        except
     1794        end;
     1795      if ok then
     1796      begin
     1797        if Page = pgLoad then
     1798          FormerGames[List.ItemIndex] := NewName
     1799        else
     1800          Maps[List.ItemIndex] := NewName;
     1801        List.Items[List.ItemIndex] := NewName;
     1802        if Page = pgEditMap then
     1803          PaintInfo;
     1804        List.Invalidate;
    15751805      end
    15761806    end
     
    15801810procedure TStartDlg.DeleteBtnClick(Sender: TObject);
    15811811var
    1582 iDel: integer;
    1583 f: file;
    1584 begin
    1585 if List.ItemIndex>=0 then
    1586   begin
    1587   if Page=pgLoad then MessgDlg.MessgText:=Phrases.Lookup('DELETEQUERY')
    1588   else MessgDlg.MessgText:=Phrases.Lookup('MAPDELETEQUERY');
    1589   MessgDlg.Kind:=mkOKCancel;
    1590   MessgDlg.ShowModal;
    1591   if MessgDlg.ModalResult=mrOK then
    1592     begin
    1593     if Page=pgLoad then
    1594       AssignFile(f,DataDir+'Saved\'+List.Items[List.ItemIndex]+'.cevo')
    1595     else AssignFile(f,DataDir+'Maps\'+List.Items[List.ItemIndex]+'.cevo map');
    1596     Erase(f);
    1597     iDel:=List.ItemIndex;
    1598     if Page=pgLoad then FormerGames.Delete(iDel)
    1599     else Maps.Delete(iDel);
    1600     List.Items.Delete(iDel);
    1601     if List.Items.Count=0 then ChangePage(pgNoLoad)
     1812  iDel: integer;
     1813  f: file;
     1814begin
     1815  if List.ItemIndex >= 0 then
     1816  begin
     1817    if Page = pgLoad then
     1818      MessgDlg.MessgText := Phrases.Lookup('DELETEQUERY')
    16021819    else
    1603       begin
    1604       if iDel=0 then List.ItemIndex:=0
    1605       else List.ItemIndex:=iDel-1;
    1606       if (Page=pgEditMap) and (List.ItemIndex=0) then ChangePage(pgEditRandom)
     1820      MessgDlg.MessgText := Phrases.Lookup('MAPDELETEQUERY');
     1821    MessgDlg.Kind := mkOKCancel;
     1822    MessgDlg.ShowModal;
     1823    if MessgDlg.ModalResult = mrOK then
     1824    begin
     1825      if Page = pgLoad then
     1826        AssignFile(f, DataDir + 'Saved\' + List.Items[List.ItemIndex] + '.cevo')
    16071827      else
    1608         begin List.Invalidate;
    1609         if Page=pgLoad then TurnValid:=false;
    1610         PaintInfo;
    1611         if Page=pgLoad then
    1612           ReplayBtn.Visible:= MiniMode<>mmMultiPlayer;
     1828        AssignFile(f, DataDir + 'Maps\' + List.Items[List.ItemIndex] +
     1829          '.cevo map');
     1830      Erase(f);
     1831      iDel := List.ItemIndex;
     1832      if Page = pgLoad then
     1833        FormerGames.Delete(iDel)
     1834      else
     1835        Maps.Delete(iDel);
     1836      List.Items.Delete(iDel);
     1837      if List.Items.Count = 0 then
     1838        ChangePage(pgNoLoad)
     1839      else
     1840      begin
     1841        if iDel = 0 then
     1842          List.ItemIndex := 0
     1843        else
     1844          List.ItemIndex := iDel - 1;
     1845        if (Page = pgEditMap) and (List.ItemIndex = 0) then
     1846          ChangePage(pgEditRandom)
     1847        else
     1848        begin
     1849          List.Invalidate;
     1850          if Page = pgLoad then
     1851            TurnValid := false;
     1852          PaintInfo;
     1853          if Page = pgLoad then
     1854            ReplayBtn.Visible := MiniMode <> mmMultiPlayer;
    16131855        end;
    16141856      end
     
    16191861procedure TStartDlg.DiffBtnClick(Sender: TObject);
    16201862var
    1621 i: integer;
    1622 begin
    1623 for i:=0 to nPlOffered-1 do
    1624   if (Sender=DiffUpBtn[i]) and (Difficulty[i]<3)
    1625     or (Sender=DiffDownBtn[i]) and (Difficulty[i]>1) then
    1626     begin
    1627     if Sender=DiffUpBtn[i] then inc(Difficulty[i])
    1628     else dec(Difficulty[i]);
    1629     SmartInvalidate(xBrain[i]-18,yBrain[i]+19,xBrain[i]-18+12,yBrain[i]+(19+14));
     1863  i: integer;
     1864begin
     1865  for i := 0 to nPlOffered - 1 do
     1866    if (Sender = DiffUpBtn[i]) and (Difficulty[i] < 3) or
     1867      (Sender = DiffDownBtn[i]) and (Difficulty[i] > 1) then
     1868    begin
     1869      if Sender = DiffUpBtn[i] then
     1870        inc(Difficulty[i])
     1871      else
     1872        dec(Difficulty[i]);
     1873      SmartInvalidate(xBrain[i] - 18, yBrain[i] + 19, xBrain[i] - 18 + 12,
     1874        yBrain[i] + (19 + 14));
    16301875    end
    16311876end;
     
    16331878procedure TStartDlg.MultiBtnClick(Sender: TObject);
    16341879var
    1635 i: integer;
    1636 begin
    1637 for i:=6 to 8 do if Sender=MultiBtn[i] then
    1638   begin
    1639   MultiControl:=MultiControl xor (1 shl i);
    1640   TButtonC(Sender).ButtonIndex:=2+(MultiControl shr i) and 1;
    1641   end
     1880  i: integer;
     1881begin
     1882  for i := 6 to 8 do
     1883    if Sender = MultiBtn[i] then
     1884    begin
     1885      MultiControl := MultiControl xor (1 shl i);
     1886      TButtonC(Sender).ButtonIndex := 2 + (MultiControl shr i) and 1;
     1887    end
    16421888end;
    16431889
    16441890procedure TStartDlg.FormHide(Sender: TObject);
    16451891begin
    1646 Diff0:=Difficulty[0];
    1647 ListIndex[Tab]:=List.ItemIndex;
    1648 ShowTab:=Tab;
    1649 Background.Enabled:=true;
     1892  Diff0 := Difficulty[0];
     1893  ListIndex[Tab] := List.ItemIndex;
     1894  ShowTab := Tab;
     1895  Background.Enabled := true;
    16501896end;
    16511897
    16521898procedure TStartDlg.QuitBtnClick(Sender: TObject);
    16531899begin
    1654 Close
     1900  Close
    16551901end;
    16561902
     
    16581904  Shift: TShiftState);
    16591905begin
    1660 if (Shift=[]) and (Key=VK_F1) then DirectHelp(cStartHelp);
     1906  if (Shift = []) and (Key = VK_F1) then
     1907    DirectHelp(cStartHelp);
    16611908end;
    16621909
    16631910procedure TStartDlg.CustomizeBtnClick(Sender: TObject);
    16641911begin
    1665 AutoDiff:=-AutoDiff;
    1666 CustomizeBtn.ButtonIndex:=CustomizeBtn.ButtonIndex xor 1;
    1667 ChangePage(Page)
     1912  AutoDiff := -AutoDiff;
     1913  CustomizeBtn.ButtonIndex := CustomizeBtn.ButtonIndex xor 1;
     1914  ChangePage(Page)
    16681915end;
    16691916
    16701917procedure TStartDlg.AutoDiffUpBtnClick(Sender: TObject);
    16711918begin
    1672 if AutoDiff<5 then
    1673   begin
    1674   inc(AutoDiff);
    1675   SmartInvalidate(120,y0Mini+61,272,y0Mini+61+21);
    1676   SmartInvalidate(xDefault-2,yDefault-2,xDefault+64+2,yDefault+64+2);
     1919  if AutoDiff < 5 then
     1920  begin
     1921    inc(AutoDiff);
     1922    SmartInvalidate(120, y0Mini + 61, 272, y0Mini + 61 + 21);
     1923    SmartInvalidate(xDefault - 2, yDefault - 2, xDefault + 64 + 2,
     1924      yDefault + 64 + 2);
    16771925  end
    16781926end;
     
    16801928procedure TStartDlg.AutoDiffDownBtnClick(Sender: TObject);
    16811929begin
    1682 if AutoDiff>1 then
    1683   begin
    1684   dec(AutoDiff);
    1685   SmartInvalidate(120,y0Mini+61,272,y0Mini+61+21);
    1686   SmartInvalidate(xDefault-2,yDefault-2,xDefault+64+2,yDefault+64+2);
     1930  if AutoDiff > 1 then
     1931  begin
     1932    dec(AutoDiff);
     1933    SmartInvalidate(120, y0Mini + 61, 272, y0Mini + 61 + 21);
     1934    SmartInvalidate(xDefault - 2, yDefault - 2, xDefault + 64 + 2,
     1935      yDefault + 64 + 2);
    16871936  end
    16881937end;
    16891938
    16901939procedure TStartDlg.FormMouseUp(Sender: TObject; Button: TMouseButton;
    1691   Shift: TShiftState; X, Y: Integer);
    1692 begin
    1693 Tracking:=false
    1694 end;
    1695 
    1696 procedure TStartDlg.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
    1697   Y: Integer);
    1698 var
    1699 OldLoadTurn,NewSelectedAction: integer;
    1700 begin
    1701 if Tracking then
    1702   begin
    1703   x:=x-xTurnSlider;
    1704   if x<0 then x:=0
    1705   else if x>wTurnSlider then x:=wTurnSlider;
    1706   OldLoadTurn:=LoadTurn;
    1707   LoadTurn:=LastTurn*x div wTurnSlider;
    1708   if LoadTurn<OldLoadTurn then
    1709     begin
    1710     SmartInvalidate(xTurnSlider+LoadTurn*wTurnSlider div LastTurn,yTurnSlider,
    1711       xTurnSlider+OldLoadTurn*wTurnSlider div LastTurn+1,yTurnSlider+7);
    1712     SmartInvalidate(344,y0Mini+61,514,y0Mini+82);
     1940  Shift: TShiftState; x, y: integer);
     1941begin
     1942  Tracking := false
     1943end;
     1944
     1945procedure TStartDlg.FormMouseMove(Sender: TObject; Shift: TShiftState;
     1946  x, y: integer);
     1947var
     1948  OldLoadTurn, NewSelectedAction: integer;
     1949begin
     1950  if Tracking then
     1951  begin
     1952    x := x - xTurnSlider;
     1953    if x < 0 then
     1954      x := 0
     1955    else if x > wTurnSlider then
     1956      x := wTurnSlider;
     1957    OldLoadTurn := LoadTurn;
     1958    LoadTurn := LastTurn * x div wTurnSlider;
     1959    if LoadTurn < OldLoadTurn then
     1960    begin
     1961      SmartInvalidate(xTurnSlider + LoadTurn * wTurnSlider div LastTurn,
     1962        yTurnSlider, xTurnSlider + OldLoadTurn * wTurnSlider div LastTurn + 1,
     1963        yTurnSlider + 7);
     1964      SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 82);
    17131965    end
    1714   else if LoadTurn>OldLoadTurn then
    1715     begin
    1716     SmartInvalidate(xTurnSlider+OldLoadTurn*wTurnSlider div LastTurn,yTurnSlider,
    1717       xTurnSlider+LoadTurn*wTurnSlider div LastTurn+1,yTurnSlider+7);
    1718     SmartInvalidate(344,y0Mini+61,514,y0Mini+82);
     1966    else if LoadTurn > OldLoadTurn then
     1967    begin
     1968      SmartInvalidate(xTurnSlider + OldLoadTurn * wTurnSlider div LastTurn,
     1969        yTurnSlider, xTurnSlider + LoadTurn * wTurnSlider div LastTurn + 1,
     1970        yTurnSlider + 7);
     1971      SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 82);
    17191972    end;
    17201973  end
    1721 else if Page=pgMain then
    1722   begin
    1723   if (x>=ActionSideBorder) and (x<ClientWidth-ActionSideBorder)
    1724     and (y>=yAction-8) and (y<ClientHeight-ActionBottomBorder) then
    1725     begin
    1726     NewSelectedAction:=(y-(yAction-8)) div ActionPitch;
    1727     if not (NewSelectedAction in ActionsOffered) then
    1728       NewSelectedAction:=-1;
     1974  else if Page = pgMain then
     1975  begin
     1976    if (x >= ActionSideBorder) and (x < ClientWidth - ActionSideBorder) and
     1977      (y >= yAction - 8) and (y < ClientHeight - ActionBottomBorder) then
     1978    begin
     1979      NewSelectedAction := (y - (yAction - 8)) div ActionPitch;
     1980      if not(NewSelectedAction in ActionsOffered) then
     1981        NewSelectedAction := -1;
    17291982    end
    1730   else NewSelectedAction:=-1;
    1731   if NewSelectedAction<>SelectedAction then
    1732     begin
    1733     if SelectedAction>=0 then
    1734       SmartInvalidate(ActionSideBorder,yAction+SelectedAction*ActionPitch-8,
    1735         ClientWidth-ActionSideBorder,yAction+(SelectedAction+1)*ActionPitch-8);
    1736     SelectedAction:=NewSelectedAction;
    1737     if SelectedAction>=0 then
    1738       SmartInvalidate(ActionSideBorder,yAction+SelectedAction*ActionPitch-8,
    1739         ClientWidth-ActionSideBorder,yAction+(SelectedAction+1)*ActionPitch-8);
     1983    else
     1984      NewSelectedAction := -1;
     1985    if NewSelectedAction <> SelectedAction then
     1986    begin
     1987      if SelectedAction >= 0 then
     1988        SmartInvalidate(ActionSideBorder, yAction + SelectedAction * ActionPitch
     1989          - 8, ClientWidth - ActionSideBorder, yAction + (SelectedAction + 1) *
     1990          ActionPitch - 8);
     1991      SelectedAction := NewSelectedAction;
     1992      if SelectedAction >= 0 then
     1993        SmartInvalidate(ActionSideBorder, yAction + SelectedAction * ActionPitch
     1994          - 8, ClientWidth - ActionSideBorder, yAction + (SelectedAction + 1) *
     1995          ActionPitch - 8);
    17401996    end
    17411997  end
     
    17442000procedure TStartDlg.AutoEnemyUpBtnClick(Sender: TObject);
    17452001begin
    1746 if AutoEnemies<nPl-1 then
    1747   begin
    1748   inc(AutoEnemies);
    1749   SmartInvalidate(160,yMain+140,198,yMain+140+21);
     2002  if AutoEnemies < nPl - 1 then
     2003  begin
     2004    inc(AutoEnemies);
     2005    SmartInvalidate(160, yMain + 140, 198, yMain + 140 + 21);
    17502006  end
    17512007end;
     
    17532009procedure TStartDlg.AutoEnemyDownBtnClick(Sender: TObject);
    17542010begin
    1755 if AutoEnemies>0 then
    1756   begin
    1757   dec(AutoEnemies);
    1758   SmartInvalidate(160,yMain+140,198,yMain+140+21);
     2011  if AutoEnemies > 0 then
     2012  begin
     2013    dec(AutoEnemies);
     2014    SmartInvalidate(160, yMain + 140, 198, yMain + 140 + 21);
    17592015  end
    17602016end;
     
    17622018procedure TStartDlg.ReplayBtnClick(Sender: TObject);
    17632019begin
    1764 LoadGame(DataDir+'Saved\', List.Items[List.ItemIndex]+'.cevo', LastTurn, true);
    1765 SlotAvailable:=-1;
     2020  LoadGame(DataDir + 'Saved\', List.Items[List.ItemIndex] + '.cevo',
     2021    LastTurn, true);
     2022  SlotAvailable := -1;
    17662023end;
    17672024
    17682025end.
    1769 
Note: See TracChangeset for help on using the changeset viewer.