Changeset 157 for trunk/Start.pas


Ignore:
Timestamp:
Nov 11, 2018, 3:20:27 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Start unit code cleanup. Some constants changed to enumeration type.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Start.pas

    r145 r157  
    77  GameServer, Messg, ButtonBase, ButtonA, ButtonC, ButtonB, Area, Math,
    88  LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls,
    9   Menus, Registry, DrawDlg, fgl;
     9  Menus, Registry, DrawDlg, fgl, Protocol;
    1010
    1111const
     
    2828
    2929  TPlayerSlots = class(TFPGObjectList<TPlayerSlot>)
    30 
    31   end;
     30  end;
     31
     32  TStartPage = (
     33    pgStartRandom,
     34    pgStartMap,
     35    pgNoLoad,
     36    pgLoad,
     37    pgEditRandom,
     38    pgEditMap,
     39    pgMain
     40  );
     41
     42  TStartTab = (
     43    tbMain,
     44    tbMap,
     45    tbNew,
     46    tbPrevious
     47  );
     48
     49  TMapArray = array[0 .. lxmax * lymax - 1] of Byte;
    3250
    3351  { TStartDlg }
     
    94112    MiniHeight: Integer;
    95113    SelectedAction: Integer;
    96     Page: Integer;
    97     ShowTab: Integer;
    98     Tab: Integer;
     114    Page: TStartPage;
     115    ShowTab: TStartTab;
     116    Tab: TStartTab;
    99117    Diff0: Integer;
    100118    BrainDefault: TBrain;
     
    106124    SlotAvailable: Integer;
    107125    PlayerPopupIndex: Integer; { brain concerned by brain context menu }
    108     ListIndex: array [0 .. 3] of integer;
     126    ListIndex: array [TStartTab] of Integer;
    109127    MapFileName: string;
    110128    FormerGames, Maps: TStringList;
     
    117135    TurnValid, Tracking: boolean;
    118136    DefaultAI: string;
     137    procedure DrawAction(y, IconIndex: integer; HeaderItem, TextItem: string);
    119138    procedure InitPopup(PlayerIndex: Integer);
     139    procedure OfferBrain(Brain: TBrain; FixedLines: Integer);
     140    procedure PaintFileMini(SaveMap: TMapArray);
    120141    procedure PaintInfo;
    121     procedure ChangePage(NewPage: integer);
    122     procedure ChangeTab(NewTab: integer);
     142    procedure ChangePage(NewPage: TStartPage);
     143    procedure ChangeTab(NewTab: TStartTab);
     144    procedure PaintRandomMini(Brightness: integer);
    123145    procedure UnlistBackupFile(FileName: string);
    124146    procedure SmartInvalidate(x0, y0, x1, y1: integer;
     
    133155
    134156uses
    135   Directories, Protocol, Direct, ScreenTools, Inp, Back, Locale;
     157  Directories, Direct, ScreenTools, Inp, Back, Locale;
    136158
    137159{$R *.lfm}
    138160
    139161const
     162  CevoExt = '.cevo';
     163  CevoMapExt = '.cevo map';
    140164  // predefined world size
    141165  // attention: lx*ly+1 must be prime!
     
    192216    256 + 128, 256 + 128 + 64, 256 + 128 + 64);
    193217
    194   pgStartRandom = 0;
    195   pgStartMap = 1;
    196   pgNoLoad = 2;
    197   pgLoad = 3;
    198   pgEditRandom = 4;
    199   pgEditMap = 5;
    200   pgMain = 6;
    201 
    202218  PlayerAutoDiff: array [1 .. 5] of integer = (1, 1, 2, 2, 3);
    203219  EnemyAutoDiff: array [1 .. 5] of integer = (4, 3, 2, 1, 1);
     220
    204221
    205222procedure TStartDlg.FormCreate(Sender: TObject);
     
    240257
    241258  DirectDlg.Left := (Screen.Width - DirectDlg.Width) div 2;
    242   DirectDlg.Top := (screen.Height - DirectDlg.Height) div 2;
     259  DirectDlg.Top := (Screen.Height - DirectDlg.Height) div 2;
    243260
    244261  if FullScreen then
     
    363380  PlayersBrain[0] := BrainTerm;
    364381  SlotAvailable := -1;
    365   Tab := 2;
     382  Tab := tbNew;
    366383  Diff0 := 2;
    367   TurnValid := false;
    368   Tracking := false;
     384  TurnValid := False;
     385  Tracking := False;
    369386  FormerGames := TStringList.Create;
    370387  UpdateFormerGames;
    371   ShowTab := 2; // always start with new book page
     388  ShowTab := tbNew; // always start with new book page
    372389  MapFileName := '';
    373390  Maps := TStringList.Create;
     
    468485end;
    469486
     487procedure TStartDlg.DrawAction(y, IconIndex: integer; HeaderItem, TextItem: string);
     488begin
     489  Canvas.Font.Assign(UniFont[ftCaption]);
     490  Canvas.Font.Style := Canvas.Font.Style + [fsUnderline];
     491  RisedTextOut(Canvas, xAction, y - 3, Phrases2.Lookup(HeaderItem));
     492  Canvas.Font.Assign(UniFont[ftNormal]);
     493  BiColorTextOut(Canvas, Colors.Canvas.Pixels[clkAge0 - 1, cliDimmedText],
     494    $000000, xAction, y + 21, Phrases2.Lookup(TextItem));
     495  BitBltCanvas(LogoBuffer.Canvas, 0, 0, 50, 50, Canvas,
     496    xActionIcon - 2, y - 2, SRCCOPY);
     497  GlowFrame(LogoBuffer, 8, 8, 34, 34, $202020);
     498  BitBlt(Canvas.Handle, xActionIcon - 2, y - 2, 50, 50,
     499    LogoBuffer.Canvas.Handle, 0, 0, SRCCOPY);
     500  BitBlt(Canvas.Handle, xActionIcon, y, 40, 40, BigImp.Canvas.Handle,
     501    (IconIndex mod 7) * xSizeBig + 8, (IconIndex div 7) * ySizeBig, SRCCOPY);
     502  RFrame(Canvas, xActionIcon - 1, y - 1, xActionIcon + 40, y + 40,
     503    $000000, $000000);
     504end;
     505
    470506procedure TStartDlg.FormPaint(Sender: TObject);
    471507const
    472   TabNames: array [0 .. 3] of integer = (0, 11, 3, 4);
    473 
    474   procedure DrawAction(y, IconIndex: integer; HeaderItem, TextItem: string);
    475   begin
    476     Canvas.Font.Assign(UniFont[ftCaption]);
    477     Canvas.Font.Style := Canvas.Font.Style + [fsUnderline];
    478     RisedTextOut(Canvas, xAction, y - 3, Phrases2.Lookup(HeaderItem));
    479     Canvas.Font.Assign(UniFont[ftNormal]);
    480     BiColorTextOut(Canvas, Colors.Canvas.Pixels[clkAge0 - 1, cliDimmedText],
    481       $000000, xAction, y + 21, Phrases2.Lookup(TextItem));
    482     BitBltCanvas(LogoBuffer.Canvas, 0, 0, 50, 50, Canvas,
    483       xActionIcon - 2, y - 2, SRCCOPY);
    484     GlowFrame(LogoBuffer, 8, 8, 34, 34, $202020);
    485     BitBlt(Canvas.Handle, xActionIcon - 2, y - 2, 50, 50,
    486       LogoBuffer.Canvas.Handle, 0, 0, SRCCOPY);
    487     BitBlt(Canvas.Handle, xActionIcon, y, 40, 40, BigImp.Canvas.Handle,
    488       (IconIndex mod 7) * xSizeBig + 8, (IconIndex div 7) * ySizeBig, SRCCOPY);
    489     RFrame(Canvas, xActionIcon - 1, y - 1, xActionIcon + 40, y + 40,
    490       $000000, $000000);
    491   end;
    492 
     508  TabNames: array[TStartTab] of Integer = (0, 11, 3, 4);
    493509var
    494510  i, w, h, xMini, yMini, y: integer;
    495511  s: string;
     512  Tab2: TStartTab;
    496513begin
    497514  PaintBackground(self, 3, 3, TabOffset + 4 * TabSize - 4, TabHeight - 3);
     
    515532        x0Brain + dxBrain + 64, Up2Btn.top + 38 { y0Brain+dyBrain+64 } ,
    516533        MainTexture.clBevelShade, MainTexture.clBevelLight);
    517     end
     534    end;
    518535  end
    519536  else if Page <> pgMain then
     
    523540
    524541  // draw tabs
    525   Frame(Canvas, 2, 2 + 2 * integer(Tab <> 0), TabOffset + (0 + 1) * TabSize - 1,
     542  Frame(Canvas, 2, 2 + 2 * integer(Tab <> tbMain), TabOffset + (0 + 1) * TabSize - 1,
    526543    TabHeight, MainTexture.clBevelLight, MainTexture.clBevelShade);
    527   Frame(Canvas, 1, 1 + 2 * integer(Tab <> 0), TabOffset + (0 + 1) * TabSize,
     544  Frame(Canvas, 1, 1 + 2 * integer(Tab <> tbMain), TabOffset + (0 + 1) * TabSize,
    528545    TabHeight, MainTexture.clBevelLight, MainTexture.clBevelShade);
    529   Canvas.Pixels[1, 1 + 2 * integer(Tab <> 0)] := MainTexture.clBevelShade;
    530   for i := 1 to 3 do
    531   begin
    532     Frame(Canvas, TabOffset + i * TabSize + 2, 2 + 2 * integer(Tab <> i),
    533       TabOffset + (i + 1) * TabSize - 1, TabHeight, MainTexture.clBevelLight,
     546  Canvas.Pixels[1, 1 + 2 * integer(Tab <> tbMain)] := MainTexture.clBevelShade;
     547  for Tab2 := tbMap to tbPrevious do
     548  begin
     549    Frame(Canvas, TabOffset + Integer(Tab2) * TabSize + 2, 2 + 2 * integer(Tab <> Tab2),
     550      TabOffset + (Integer(Tab2) + 1) * TabSize - 1, TabHeight, MainTexture.clBevelLight,
    534551      MainTexture.clBevelShade);
    535     Frame(Canvas, TabOffset + i * TabSize + 1, 1 + 2 * integer(Tab <> i),
    536       TabOffset + (i + 1) * TabSize, TabHeight, MainTexture.clBevelLight,
     552    Frame(Canvas, TabOffset + Integer(Tab2) * TabSize + 1, 1 + 2 * integer(Tab <> Tab2),
     553      TabOffset + (Integer(Tab2) + 1) * TabSize, TabHeight, MainTexture.clBevelLight,
    537554      MainTexture.clBevelShade);
    538     Canvas.Pixels[TabOffset + i * TabSize + 1, 1 + 2 * integer(Tab <> i)] :=
     555    Canvas.Pixels[TabOffset + Integer(Tab2) * TabSize + 1, 1 + 2 * integer(Tab <> Tab2)] :=
    539556      MainTexture.clBevelShade;
    540557  end;
    541558  Canvas.Font.Assign(UniFont[ftNormal]);
    542   for i := 1 to 3 do
    543   begin
    544     s := Phrases.Lookup('STARTCONTROLS', TabNames[i]);
    545     RisedTextOut(Canvas, TabOffset + i * TabSize + 1 +
     559  for Tab2 := tbMap to tbPrevious do
     560  begin
     561    s := Phrases.Lookup('STARTCONTROLS', TabNames[Tab2]);
     562    RisedTextOut(Canvas, TabOffset + Integer(Tab2) * TabSize + 1 +
    546563      (TabSize - BiColorTextWidth(Canvas, s)) div 2,
    547       10 + 2 * integer(Tab <> i), s);
     564      10 + 2 * integer(Tab <> Tab2), s);
    548565  end;
    549566  Frame(Canvas, TabOffset + 4 * TabSize + 1, -1, ClientWidth, TabHeight,
     
    553570  Frame(Canvas, 2, TabHeight + 2, ClientWidth - 3, ClientHeight - 3,
    554571    MainTexture.clBevelLight, MainTexture.clBevelShade);
    555   if Tab = 0 then
     572  if Tab = tbMain then
    556573  begin
    557574    PaintBackground(self, 3, TabHeight - 1, TabSize - 4 - 3 + TabOffset + 3, 4);
     
    560577  else
    561578  begin
    562     PaintBackground(self, TabOffset + 3 + Tab * TabSize, TabHeight - 1,
     579    PaintBackground(self, TabOffset + 3 + Integer(Tab) * TabSize, TabHeight - 1,
    563580      TabSize - 4, 4);
    564     Canvas.Pixels[TabOffset + Tab * TabSize + 2, TabHeight] :=
     581    Canvas.Pixels[TabOffset + Integer(Tab) * TabSize + 2, TabHeight] :=
    565582      MainTexture.clBevelLight;
    566583  end;
    567   Canvas.Pixels[TabOffset + (Tab + 1) * TabSize - 1, TabHeight + 1] :=
     584  Canvas.Pixels[TabOffset + (Integer(Tab) + 1) * TabSize - 1, TabHeight + 1] :=
    568585    MainTexture.clBevelShade;
    569   if Tab < 3 then
    570     Frame(Canvas, TabOffset + (Tab + 1) * TabSize + 1, 3,
    571       TabOffset + (Tab + 1) * TabSize + 2, TabHeight, MainTexture.clBevelShade,
     586  if Tab < tbPrevious then
     587    Frame(Canvas, TabOffset + (Integer(Tab) + 1) * TabSize + 1, 3,
     588      TabOffset + (Integer(Tab) + 1) * TabSize + 2, TabHeight, MainTexture.clBevelShade,
    572589      MainTexture.clBevelShade); // Tab shadow
    573590  BitBltCanvas(LogoBuffer.Canvas, 0, 0, 36, 36, Canvas, 6,
    574     3 + 2 * integer(Tab <> 0), SRCCOPY);
    575 
     591    3 + 2 * integer(Tab <> tbMain), SRCCOPY);
    576592
    577593  ImageOp_BCC(LogoBuffer, Templates, 0, 0, 145, 38, 36, 27, $BFBF20, $4040DF);
     
    579595  ImageOp_BCC(LogoBuffer, Templates, 10, 27, 155, 38 + 27, 26, 9, $BFBF20,
    580596    $4040DF); // logo part 2
    581   BitBlt(Canvas.Handle, 6, 3 + 2 * integer(Tab <> 0), 36, 36,
     597  BitBlt(Canvas.Handle, 6, 3 + 2 * integer(Tab <> tbMain), 36, 36,
    582598    LogoBuffer.Canvas.Handle, 0, 0, SRCCOPY);
    583599
     
    632648        end;
    633649      inc(y, ActionPitch);
    634     end
     650    end;
    635651  end
    636652  else if Page in [pgStartRandom, pgStartMap] then
     
    693709              BitBlt(Canvas.Handle, xBrain[i] - 31, yBrain[i], 13, 12,
    694710                GrExt[HGrSystem].Data.Canvas.Handle, 88, 47, SRCCOPY);
    695             end
     711            end;
    696712          end;
    697713          if Assigned(PlayersBrain[i]) then
     
    700716              [PlayersBrain[i].Name]);
    701717            PlayerSlots[i].DiffDownBtn.Hint := PlayerSlots[i].DiffUpBtn.Hint;
    702           end
     718          end;
    703719        end;
    704720    end
     
    743759      PaintLogo(Canvas, 69, yLogo, MainTexture.clBevelLight,
    744760        MainTexture.clBevelShade);
    745     end
     761    end;
    746762  end
    747763  else if Page = pgLoad then
     
    857873  SetMainTextureByAge(-1);
    858874  List.Font.Color := MainTexture.clMark;
    859   EmptyPicture.BeginUpdate;
    860875
    861876  Fill(EmptyPicture.Canvas, 0, 0, 64, 64, (wMaintexture - 64) div 2,
    862877    (hMaintexture - 64) div 2);
    863878  // darken texture for empty slot
     879  EmptyPicture.BeginUpdate;
    864880  PicturePixel.Init(EmptyPicture);
    865881  for y := 0 to 63 do begin
     
    877893
    878894  SelectedAction := -1;
    879   if ShowTab = 3 then
     895  if ShowTab = tbPrevious then
    880896    PreviewMap(StartLandMass); // avoid delay on first TabX change
    881897  ChangeTab(ShowTab);
    882   Background.Enabled := false;
     898  Background.Enabled := False;
    883899end;
    884900
    885901procedure TStartDlg.UnlistBackupFile(FileName: string);
    886902var
    887   i: integer;
     903  I: Integer;
    888904begin
    889905  if FileName[1] <> '~' then
    890906    FileName := '~' + FileName;
    891   i := FormerGames.Count - 1;
    892   while (i >= 0) and (AnsiCompareFileName(FormerGames[i], FileName) <> 0) do
    893     dec(i);
    894   if i >= 0 then
    895   begin
    896     FormerGames.Delete(i);
    897     if ListIndex[2] = i then
    898       ListIndex[2] := 0
    899   end
     907  I := FormerGames.Count - 1;
     908  while (I >= 0) and (AnsiCompareFileName(FormerGames[I], FileName) <> 0) do
     909    Dec(I);
     910  if I >= 0 then
     911  begin
     912    FormerGames.Delete(I);
     913    if ListIndex[tbNew] = I then
     914      ListIndex[tbNew] := 0
     915  end;
    900916end;
    901917
    902918procedure TStartDlg.StartBtnClick(Sender: TObject);
    903919var
    904   i, GameCount, MapCount: integer;
     920  I, GameCount, MapCount: integer;
    905921  FileName: string;
    906922  Reg: TRegistry;
     
    910926      begin // load
    911927        FileName := List.Items[List.ItemIndex];
    912         if LoadGame(DataDir + 'Saved' + DirectorySeparator, FileName + '.cevo', LoadTurn, false)
     928        if LoadGame(DataDir + 'Saved' + DirectorySeparator, FileName + CevoExt, LoadTurn, false)
    913929        then
    914930          UnlistBackupFile(FileName)
     
    917933        SlotAvailable := -1;
    918934      end;
    919 
    920935    pgStartRandom, pgStartMap:
    921936      if Assigned(PlayersBrain[0]) then
     
    925940        begin
    926941          SimpleMessage(Phrases.Lookup('NOSTARTPOS'));
    927           exit
     942          Exit;
    928943        end;
    929944
     
    938953            FileName := 'Round' + IntToStr(GetProcessID())
    939954          else begin
    940             inc(GameCount);
     955            Inc(GameCount);
    941956            FileName := Format(Phrases.Lookup('GAME'), [GameCount]);
    942957          end;
     
    949964            OpenKey(AppRegistryKey + '\AI', True);
    950965            if AutoDiff < 0 then
    951               for i := 0 to nPlOffered - 1 do begin
    952                 if not Assigned(PlayersBrain[i]) then
    953                   Reg.WriteString('Control' + IntToStr(i), '')
    954                 else Reg.WriteString('Control' + IntToStr(i),
    955                   PlayersBrain[i].FileName);
    956                 WriteInteger('Diff' + IntToStr(i), Difficulty[i]);
     966              for I := 0 to nPlOffered - 1 do begin
     967                if not Assigned(PlayersBrain[I]) then
     968                  Reg.WriteString('Control' + IntToStr(I), '')
     969                else Reg.WriteString('Control' + IntToStr(I),
     970                  PlayersBrain[I].FileName);
     971                WriteInteger('Diff' + IntToStr(I), Difficulty[I]);
    957972              end;
    958973            WriteInteger('MultiControl', MultiControl);
     
    966981            PlayersBrain[0] := BrainTerm;
    967982            Difficulty[0] := PlayerAutoDiff[AutoDiff];
    968             for i := 1 to nPl - 1 do
    969               if (Page = pgStartRandom) and (i <= AutoEnemies) or
    970                 (Page = pgStartMap) and (i < nMapStartPositions) then begin
    971                 if AutoDiff = 1 then PlayersBrain[i] := BrainBeginner
    972                   else PlayersBrain[i] := BrainDefault;
    973                 Difficulty[i] := EnemyAutoDiff[AutoDiff];
    974               end  else PlayersBrain[i] := nil;
     983            for I := 1 to nPl - 1 do
     984              if (Page = pgStartRandom) and (I <= AutoEnemies) or
     985                (Page = pgStartMap) and (I < nMapStartPositions) then begin
     986                if AutoDiff = 1 then PlayersBrain[I] := BrainBeginner
     987                  else PlayersBrain[I] := BrainDefault;
     988                Difficulty[I] := EnemyAutoDiff[AutoDiff];
     989              end  else PlayersBrain[I] := nil;
    975990          end else begin
    976             for i := 6 to 8 do
    977               if (PlayersBrain[0].Kind <> btNoTerm) and (MultiControl and (1 shl i) <> 0)
     991            for I := 6 to 8 do
     992              if (PlayersBrain[0].Kind <> btNoTerm) and (MultiControl and (1 shl I) <> 0)
    978993              then begin
    979                 PlayersBrain[i + 3] := PlayersBrain[i];
    980                 Difficulty[i + 3] := Difficulty[i];
    981                 PlayersBrain[i + 6] := PlayersBrain[i];
    982                 Difficulty[i + 6] := Difficulty[i];
     994                PlayersBrain[I + 3] := PlayersBrain[I];
     995                Difficulty[I + 3] := Difficulty[I];
     996                PlayersBrain[I + 6] := PlayersBrain[I];
     997                Difficulty[I + 6] := Difficulty[I];
    983998              end else begin
    984                 PlayersBrain[i + 3] := nil;
    985                 PlayersBrain[i + 6] := nil;
    986               end
     999                PlayersBrain[I + 3] := nil;
     1000                PlayersBrain[I + 6] := nil;
     1001              end;
    9871002          end;
    9881003
     
    9951010        end;
    9961011
    997         StartNewGame(DataDir + 'Saved' + DirectorySeparator, FileName + '.cevo', MapFileName,
     1012        StartNewGame(DataDir + 'Saved' + DirectorySeparator, FileName + CevoExt, MapFileName,
    9981013          lxpre[WorldSize], lypre[WorldSize], StartLandMass, MaxTurn);
    9991014        UnlistBackupFile(FileName);
    10001015      end;
    1001 
    10021016    pgEditMap:
    10031017      EditMap(MapFileName, lxmax, lymax, StartLandMass);
    1004 
    10051018    pgEditRandom: // new map
    10061019      begin
     
    10161029          Free;
    10171030        end;
    1018         MapFileName := Format(Phrases.Lookup('MAP'), [MapCount]) + '.cevo map';
     1031        MapFileName := Format(Phrases.Lookup('MAP'), [MapCount]) + CevoMapExt;
    10191032        EditMap(MapFileName, lxpre[WorldSize], lypre[WorldSize], StartLandMass);
    10201033      end
     
    10221035end;
    10231036
    1024 procedure TStartDlg.PaintInfo;
    1025 
    1026   procedure PaintRandomMini(Brightness: integer);
    1027   var
    1028     i, x, y, xm, cm: integer;
    1029     MiniPixel: TPixelPointer;
    1030     Map: ^TTileList;
    1031   begin
    1032     Map := PreviewMap(StartLandMass);
    1033     MiniWidth := lxpre[WorldSize];
    1034     MiniHeight := lypre[WorldSize];
    1035 
    1036     Mini.PixelFormat := pf24bit;
    1037     Mini.SetSize(MiniWidth * 2, MiniHeight);
     1037procedure TStartDlg.PaintRandomMini(Brightness: integer);
     1038var
     1039  i, x, y, xm, cm: integer;
     1040  MiniPixel: TPixelPointer;
     1041  Map: ^TTileList;
     1042begin
     1043  Map := PreviewMap(StartLandMass);
     1044  MiniWidth := lxpre[WorldSize];
     1045  MiniHeight := lypre[WorldSize];
     1046
     1047  Mini.PixelFormat := pf24bit;
     1048  Mini.SetSize(MiniWidth * 2, MiniHeight);
     1049  Mini.BeginUpdate;
     1050  MiniPixel.Init(Mini);
     1051  for y := 0 to MiniHeight - 1 do begin
     1052    for x := 0 to MiniWidth - 1 do begin
     1053      for i := 0 to 1 do begin
     1054        xm := (x * 2 + i + y and 1) mod (MiniWidth * 2);
     1055        MiniPixel.SetX(xm);
     1056        cm := MiniColors
     1057          [Map[x * lxmax div MiniWidth + lxmax *
     1058          ((y * (lymax - 1) + MiniHeight div 2) div (MiniHeight - 1))] and
     1059          fTerrain, i];
     1060        MiniPixel.Pixel^.B := ((cm shr 16) and $FF) * Brightness div 3;
     1061        MiniPixel.Pixel^.G := ((cm shr 8) and $FF) * Brightness div 3;
     1062        MiniPixel.Pixel^.R := ((cm shr 0) and $FF) * Brightness div 3;
     1063      end;
     1064    end;
     1065    MiniPixel.NextLine;
     1066  end;
     1067  Mini.EndUpdate;
     1068end;
     1069
     1070procedure TStartDlg.PaintFileMini(SaveMap: TMapArray);
     1071var
     1072  i, x, y, xm, cm, Tile, OwnColor, EnemyColor: integer;
     1073  MiniPixel, PrevMiniPixel: TPixelPointer;
     1074begin
     1075  OwnColor := GrExt[HGrSystem].Data.Canvas.Pixels[95, 67];
     1076  EnemyColor := GrExt[HGrSystem].Data.Canvas.Pixels[96, 67];
     1077  Mini.PixelFormat := pf24bit;
     1078  Mini.SetSize(MiniWidth * 2, MiniHeight);
     1079  if MiniMode = mmPicture then
     1080  begin
    10381081    Mini.BeginUpdate;
    10391082    MiniPixel.Init(Mini);
     1083    PrevMiniPixel.Init(Mini, 0, -1);
    10401084    for y := 0 to MiniHeight - 1 do begin
    10411085      for x := 0 to MiniWidth - 1 do begin
     
    10431087          xm := (x * 2 + i + y and 1) mod (MiniWidth * 2);
    10441088          MiniPixel.SetX(xm);
    1045           cm := MiniColors
    1046             [Map[x * lxmax div MiniWidth + lxmax *
    1047             ((y * (lymax - 1) + MiniHeight div 2) div (MiniHeight - 1))] and
    1048             fTerrain, i];
    1049           MiniPixel.Pixel^.B := ((cm shr 16) and $FF) * Brightness div 3;
    1050           MiniPixel.Pixel^.G := ((cm shr 8) and $FF) * Brightness div 3;
    1051           MiniPixel.Pixel^.R := ((cm shr 0) and $FF) * Brightness div 3;
     1089          Tile := SaveMap[x + MiniWidth * y];
     1090          if Tile and fTerrain = fUNKNOWN then
     1091            cm := $000000
     1092          else if Tile and smCity <> 0 then
     1093          begin
     1094            if Tile and smOwned <> 0 then
     1095              cm := OwnColor
     1096            else
     1097              cm := EnemyColor;
     1098            if y > 0 then begin
     1099              // 2x2 city dot covers two lines
     1100              PrevMiniPixel.SetX(xm);
     1101              PrevMiniPixel.Pixel^.B := cm shr 16;
     1102              PrevMiniPixel.Pixel^.G:= cm shr 8 and $FF;
     1103              PrevMiniPixel.Pixel^.R := cm and $FF;
     1104            end;
     1105          end
     1106          else if (i = 0) and (Tile and smUnit <> 0) then
     1107            if Tile and smOwned <> 0 then
     1108              cm := OwnColor
     1109            else
     1110              cm := EnemyColor
     1111          else
     1112            cm := MiniColors[Tile and fTerrain, i];
     1113          MiniPixel.Pixel^.B := cm shr 16;
     1114          MiniPixel.Pixel^.G:= cm shr 8 and $FF;
     1115          MiniPixel.Pixel^.R := cm and $FF;
    10521116        end;
    10531117      end;
    10541118      MiniPixel.NextLine;
     1119      PrevMiniPixel.NextLine;
    10551120    end;
    10561121    Mini.EndUpdate;
    10571122  end;
    1058 
    1059 var
    1060   SaveMap: array [0 .. lxmax * lymax - 1] of Byte;
    1061 
    1062   procedure PaintFileMini;
    1063   var
    1064     i, x, y, xm, cm, Tile, OwnColor, EnemyColor: integer;
    1065     MiniPixel, PrevMiniPixel: TPixelPointer;
    1066   begin
    1067     OwnColor := GrExt[HGrSystem].Data.Canvas.Pixels[95, 67];
    1068     EnemyColor := GrExt[HGrSystem].Data.Canvas.Pixels[96, 67];
    1069     Mini.PixelFormat := pf24bit;
    1070     Mini.SetSize(MiniWidth * 2, MiniHeight);
    1071     if MiniMode = mmPicture then
    1072     begin
    1073       Mini.BeginUpdate;
    1074       MiniPixel.Init(Mini);
    1075       PrevMiniPixel.Init(Mini, 0, -1);
    1076       for y := 0 to MiniHeight - 1 do begin
    1077         for x := 0 to MiniWidth - 1 do begin
    1078           for i := 0 to 1 do begin
    1079             xm := (x * 2 + i + y and 1) mod (MiniWidth * 2);
    1080             MiniPixel.SetX(xm);
    1081             Tile := SaveMap[x + MiniWidth * y];
    1082             if Tile and fTerrain = fUNKNOWN then
    1083               cm := $000000
    1084             else if Tile and smCity <> 0 then
    1085             begin
    1086               if Tile and smOwned <> 0 then
    1087                 cm := OwnColor
    1088               else
    1089                 cm := EnemyColor;
    1090               if y > 0 then begin
    1091                 // 2x2 city dot covers two lines
    1092                 PrevMiniPixel.SetX(xm);
    1093                 PrevMiniPixel.Pixel^.B := cm shr 16;
    1094                 PrevMiniPixel.Pixel^.G:= cm shr 8 and $FF;
    1095                 PrevMiniPixel.Pixel^.R := cm and $FF;
    1096               end
    1097             end
    1098             else if (i = 0) and (Tile and smUnit <> 0) then
    1099               if Tile and smOwned <> 0 then
    1100                 cm := OwnColor
    1101               else
    1102                 cm := EnemyColor
    1103             else
    1104               cm := MiniColors[Tile and fTerrain, i];
    1105             MiniPixel.Pixel^.B := cm shr 16;
    1106             MiniPixel.Pixel^.G:= cm shr 8 and $FF;
    1107             MiniPixel.Pixel^.R := cm and $FF;
    1108           end;
    1109         end;
    1110         MiniPixel.NextLine;
    1111         PrevMiniPixel.NextLine;
    1112       end;
    1113       Mini.EndUpdate;
    1114     end;
    1115   end;
    1116 
    1117 var
    1118   x, y, dummy, FileLandMass, lxFile, lyFile: integer;
     1123end;
     1124
     1125procedure TStartDlg.PaintInfo;
     1126var
     1127  SaveMap: TMapArray;
     1128  x, y, Dummy, FileLandMass, lxFile, lyFile: integer;
    11191129  LogFile, MapFile: file;
    11201130  s: string[255];
    11211131  MapRow: array [0 .. lxmax - 1] of Cardinal;
    1122 
    11231132begin
    11241133  case Page of
     
    11281137        PaintRandomMini(3);
    11291138      end;
    1130 
    11311139    pgNoLoad:
    11321140      begin
     
    11351143        MiniMode := mmNone;
    11361144      end;
    1137 
    11381145    pgLoad:
    11391146      begin
    11401147        AssignFile(LogFile, DataDir + 'Saved' + DirectorySeparator + List.Items[List.ItemIndex]
    1141           + '.cevo');
     1148          + CevoExt);
    11421149        try
    11431150          Reset(LogFile, 4);
    11441151          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 }
     1152          BlockRead(LogFile, Dummy, 1); { format id }
     1153          if Dummy >= $000E01 then
     1154            BlockRead(LogFile, Dummy, 1); { item stored since 0.14.1 }
    11481155          BlockRead(LogFile, MiniWidth, 1);
    11491156          BlockRead(LogFile, MiniHeight, 1);
     
    11521159            for y := 0 to MiniHeight - 1 do
    11531160              BlockRead(LogFile, MapRow, MiniWidth);
    1154           BlockRead(LogFile, dummy, 1);
    1155           BlockRead(LogFile, dummy, 1);
     1161          BlockRead(LogFile, Dummy, 1);
     1162          BlockRead(LogFile, Dummy, 1);
    11561163          BlockRead(LogFile, LastTurn, 1);
    11571164          BlockRead(LogFile, SaveMap, 1);
     
    11711178        end;
    11721179        // BookDate:=DateToStr(FileDateToDateTime(FileAge(FileName)));
    1173         PaintFileMini;
     1180        PaintFileMini(SaveMap);
    11741181        if not TurnValid then
    11751182        begin
     
    11781185            xTurnSlider + wTurnSlider + 2, yTurnSlider + 9);
    11791186        end;
    1180         TurnValid := true;
    1181       end;
    1182 
     1187        TurnValid := True;
     1188      end;
    11831189    pgEditRandom:
    11841190      begin
     
    11871193        PaintRandomMini(4);
    11881194      end;
    1189 
    11901195    pgStartMap, pgEditMap:
    11911196      begin
    11921197        MiniMode := mmPicture;
    11931198        if Page = pgEditMap then
    1194           MapFileName := List.Items[List.ItemIndex] + '.cevo map';
     1199          MapFileName := List.Items[List.ItemIndex] + CevoMapExt;
    11951200        if LoadGraphicFile(Mini, DataDir + 'Maps' + DirectorySeparator + Copy(MapFileName, 1,
    11961201          Length(MapFileName) - 9) + '.png', gfNoError) then
     
    12401245        if Page = pgEditMap then
    12411246          SmartInvalidate(x0Mini - 112, y0Mini + 61, x0Mini + 112, y0Mini + 91);
    1242       end
     1247      end;
    12431248  end;
    12441249  SmartInvalidate(x0Mini - lxmax, y0Mini - lymax div 2,
     
    12481253procedure TStartDlg.BrainClick(Sender: TObject);
    12491254var
    1250   i: integer;
     1255  I: Integer;
    12511256begin
    12521257  // Play('BUTTON_UP');
     
    12911296        for I := 1 to PlayerSlots.Count - 1 do
    12921297          if PlayersBrain[I].Kind = btTerm then begin
    1293             PlayersBrain[i] := nil;
    1294             PlayerSlots[i].DiffUpBtn.Visible := false;
    1295             PlayerSlots[i].DiffUpBtn.Tag := 0;
    1296             PlayerSlots[i].DiffDownBtn.Visible := false;
    1297             PlayerSlots[i].DiffDownBtn.Tag := 0;
    1298             if PlayerSlots[i].OfferMultiple then begin
    1299               PlayerSlots[i].MultiBtn.Visible := false;
    1300               PlayerSlots[i].MultiBtn.Tag := 0;
     1298            PlayersBrain[I] := nil;
     1299            PlayerSlots[I].DiffUpBtn.Visible := false;
     1300            PlayerSlots[I].DiffUpBtn.Tag := 0;
     1301            PlayerSlots[I].DiffDownBtn.Visible := false;
     1302            PlayerSlots[I].DiffDownBtn.Tag := 0;
     1303            if PlayerSlots[I].OfferMultiple then begin
     1304              PlayerSlots[I].MultiBtn.Visible := false;
     1305              PlayerSlots[I].MultiBtn.Tag := 0;
    13011306            end;
    1302             SmartInvalidate(xBrain[i] - 31, yBrain[i] - 1, xBrain[i] + 64,
    1303               PlayerSlots[i].DiffUpBtn.top + 25);
     1307            SmartInvalidate(xBrain[I] - 31, yBrain[I] - 1, xBrain[I] + 64,
     1308              PlayerSlots[I].DiffUpBtn.top + 25);
    13041309          end;
    13051310        BrainTerm.Flags := BrainTerm.Flags and not fUsed;
     
    13081313    SmartInvalidate(xBrain[PlayerPopupIndex] - 31, yBrain[PlayerPopupIndex] - 1,
    13091314      xBrain[PlayerPopupIndex] + 64, PlayerSlots[PlayerPopupIndex].DiffUpBtn.top + 25);
    1310   end
     1315  end;
     1316end;
     1317
     1318procedure TStartDlg.OfferBrain(Brain: TBrain; FixedLines: Integer);
     1319var
     1320  J: Integer;
     1321  MenuItem: TMenuItem;
     1322begin
     1323  MenuItem := TMenuItem.Create(PopupMenu1);
     1324  if not Assigned(Brain) then MenuItem.Caption := Phrases.Lookup('NOMOD')
     1325    else MenuItem.Caption := Brain.Name;
     1326  MenuItem.Tag := Brains.IndexOf(Brain);
     1327  MenuItem.OnClick := BrainClick;
     1328  J := FixedLines;
     1329  while (J < PopupMenu1.Items.Count) and
     1330    (StrIComp(pchar(MenuItem.Caption), pchar(PopupMenu1.Items[J].Caption)) > 0) do
     1331    Inc(J);
     1332  MenuItem.RadioItem := True;
     1333  if (PlayerPopupIndex < 0) then MenuItem.Checked := BrainDefault = Brain
     1334    else MenuItem.Checked := PlayersBrain[PlayerPopupIndex] = Brain;
     1335  PopupMenu1.Items.Insert(J, MenuItem);
    13111336end;
    13121337
     
    13171342  MenuItem: TMenuItem;
    13181343  AIBrains: TBrains;
    1319 
    1320   procedure OfferBrain(Brain: TBrain);
    1321   var
    1322     J: Integer;
    1323   begin
    1324     MenuItem := TMenuItem.Create(PopupMenu1);
    1325     if not Assigned(Brain) then MenuItem.Caption := Phrases.Lookup('NOMOD')
    1326       else MenuItem.Caption := Brain.Name;
    1327     MenuItem.Tag := Brains.IndexOf(Brain);
    1328     MenuItem.OnClick := BrainClick;
    1329     J := FixedLines;
    1330     while (J < PopupMenu1.Items.Count) and
    1331       (StrIComp(pchar(MenuItem.Caption), pchar(PopupMenu1.Items[J].Caption)) > 0) do
    1332       Inc(J);
    1333     MenuItem.RadioItem := True;
    1334     if (PlayerPopupIndex < 0) then MenuItem.Checked := BrainDefault = Brain
    1335       else MenuItem.Checked := PlayersBrain[PlayerPopupIndex] = Brain;
    1336     PopupMenu1.Items.Insert(J, MenuItem);
    1337   end;
    1338 
    13391344begin
    13401345  PlayerPopupIndex := PlayerIndex;
     
    13431348    FixedLines := 0;
    13441349    if Brains.GetKindCount(btAI) >= 2 then begin
    1345       OfferBrain(BrainRandom);
     1350      OfferBrain(BrainRandom, FixedLines);
    13461351      Inc(FixedLines);
    13471352    end;
     
    13501355    for I := 0 to AIBrains.Count - 1 do // offer available AIs
    13511356      if AIBrains[I].Flags and fMultiple <> 0 then
    1352         OfferBrain(AIBrains[I]);
     1357        OfferBrain(AIBrains[I], FixedLines);
    13531358    AIBrains.Free;
    13541359  end else begin
    13551360    FixedLines := 0;
    13561361    if PlayerPopupIndex > 0 then begin
    1357       OfferBrain(nil);
     1362      OfferBrain(nil, FixedLines);
    13581363      Inc(FixedLines);
    13591364    end;
     
    13611366      if (PlayerPopupIndex = 0) or (Brains[i].Kind = btTerm) and
    13621367        (PlayersBrain[0].Kind <> btNoTerm) then begin
    1363         OfferBrain(Brains[I]);
     1368        OfferBrain(Brains[I], FixedLines);
    13641369        Inc(FixedLines);
    13651370      end;
     
    13701375      Inc(FixedLines);
    13711376      if Brains.GetKindCount(btAI) >= 2 then begin
    1372         OfferBrain(BrainRandom);
     1377        OfferBrain(BrainRandom, FixedLines);
    13731378        Inc(FixedLines);
    13741379      end;
     
    13781383        if (AIBrains[I].Flags and fMultiple <> 0) or (AIBrains[I].Flags and fUsed = 0)
    13791384          or (Brains[I] = PlayersBrain[PlayerPopupIndex]) then
    1380           OfferBrain(AIBrains[i]);
     1385          OfferBrain(AIBrains[i], FixedLines);
    13811386      AIBrains.Free;
    13821387    end;
     
    13861391procedure TStartDlg.UpdateFormerGames;
    13871392var
    1388   i: integer;
     1393  I: Integer;
     1394  F: TSearchRec;
     1395begin
     1396  FormerGames.Clear;
     1397  if FindFirst(DataDir + 'Saved' + DirectorySeparator + '*' + CevoExt, $21, F) = 0 then
     1398    repeat
     1399      I := FormerGames.Count;
     1400      while (I > 0) and (F.Time < integer(FormerGames.Objects[I - 1])) do
     1401        Dec(I);
     1402      FormerGames.InsertObject(I, Copy(F.Name, 1, Length(F.Name) - 5),
     1403        TObject(F.Time));
     1404    until FindNext(F) <> 0;
     1405  FindClose(F);
     1406  ListIndex[tbNew] := FormerGames.Count - 1;
     1407  if (ShowTab = tbNew) and (FormerGames.Count > 0) then
     1408    ShowTab := tbPrevious;
     1409  TurnValid := False;
     1410end;
     1411
     1412procedure TStartDlg.UpdateMaps;
     1413var
    13891414  f: TSearchRec;
    13901415begin
    1391   FormerGames.Clear;
    1392   if FindFirst(DataDir + 'Saved' + DirectorySeparator + '*.cevo', $21, f) = 0 then
    1393     repeat
    1394       i := FormerGames.Count;
    1395       while (i > 0) and (f.Time < integer(FormerGames.Objects[i - 1])) do
    1396         dec(i);
    1397       FormerGames.InsertObject(i, Copy(f.Name, 1, Length(f.Name) - 5),
    1398         TObject(f.Time));
    1399     until FindNext(f) <> 0;
    1400   FindClose(f);
    1401   ListIndex[2] := FormerGames.Count - 1;
    1402   if (ShowTab = 2) and (FormerGames.Count > 0) then
    1403     ShowTab := 3;
    1404   TurnValid := false;
    1405 end;
    1406 
    1407 procedure TStartDlg.UpdateMaps;
    1408 var
    1409   f: TSearchRec;
    1410 begin
    14111416  Maps.Clear;
    1412   if FindFirst(DataDir + 'Maps' + DirectorySeparator + '*.cevo map', $21, f) = 0 then
     1417  if FindFirst(DataDir + 'Maps' + DirectorySeparator + '*' + CevoMapExt, $21, f) = 0 then
    14131418    repeat
    14141419      Maps.Add(Copy(f.Name, 1, Length(f.Name) - 9));
     
    14171422  Maps.Sort;
    14181423  Maps.Insert(0, Phrases.Lookup('RANMAP'));
    1419   ListIndex[0] := Maps.IndexOf(Copy(MapFileName, 1, Length(MapFileName) - 9));
    1420   if ListIndex[0] < 0 then
    1421     ListIndex[0] := 0;
    1422 end;
    1423 
    1424 procedure TStartDlg.ChangePage(NewPage: integer);
     1424  ListIndex[tbMain] := Maps.IndexOf(Copy(MapFileName, 1, Length(MapFileName) - 9));
     1425  if ListIndex[tbMain] < 0 then
     1426    ListIndex[tbMain] := 0;
     1427end;
     1428
     1429procedure TStartDlg.ChangePage(NewPage: TStartPage);
    14251430var
    14261431  i, j, p1: integer;
     
    15461551  PaintInfo;
    15471552  for i := 0 to ControlCount - 1 do
    1548     Controls[i].Visible := Controls[i].Tag and (256 shl Page) <> 0;
     1553    Controls[i].Visible := Controls[i].Tag and (256 shl Integer(Page)) <> 0;
    15491554  if Page = pgLoad then
    15501555    ReplayBtn.Visible := MiniMode <> mmMultiPlayer;
     
    15531558end;
    15541559
    1555 procedure TStartDlg.ChangeTab(NewTab: integer);
     1560procedure TStartDlg.ChangeTab(NewTab: TStartTab);
    15561561begin
    15571562  Tab := NewTab;
    15581563  case Tab of
    1559     1:
     1564    tbMap:
    15601565      List.Items.Assign(Maps);
    1561     3:
     1566    tbPrevious:
    15621567      List.Items.Assign(FormerGames);
    15631568  end;
    1564   if Tab <> 2 then
     1569  if Tab <> tbNew then
    15651570    if List.Count > 0 then begin
    15661571      if (List.Count > ListIndex[Tab]) then
     
    15691574    end else List.ItemIndex := -1;
    15701575  case Tab of
    1571     0:
     1576    tbMain:
    15721577      ChangePage(pgMain);
    1573     1:
     1578    tbMap:
    15741579      if List.ItemIndex = 0 then
    15751580        ChangePage(pgEditRandom)
    15761581      else
    15771582        ChangePage(pgEditMap);
    1578     2:
     1583    tbNew:
    15791584      if MapFileName = '' then
    15801585        ChangePage(pgStartRandom)
    15811586      else
    15821587        ChangePage(pgStartMap);
    1583     3:
     1588    tbPrevious:
    15841589      if FormerGames.Count = 0 then
    15851590        ChangePage(pgNoLoad)
     
    15921597  Shift: TShiftState; x, y: integer);
    15931598var
    1594   i: integer;
     1599  I: Integer;
    15951600begin
    15961601  if (y < TabHeight + 1) and (x - TabOffset < TabSize * 4) and
    1597     ((x - TabOffset) div TabSize <> Tab) then
     1602    ((x - TabOffset) div TabSize <> Integer(Tab)) then
    15981603  begin
    15991604    // Play('BUTTON_DOWN');
    16001605    ListIndex[Tab] := List.ItemIndex;
    1601     ChangeTab((x - TabOffset) div TabSize);
     1606    ChangeTab(TStartTab((x - TabOffset) div TabSize));
    16021607  end
    16031608  else if Page = pgMain then
     
    16261631    (nMapStartPositions > 0)) then
    16271632  begin
    1628     for i := 0 to nPlOffered - 1 do
    1629       if (1 shl i and SlotAvailable <> 0) and (x >= xBrain[i]) and
    1630         (y >= yBrain[i]) and (x < xBrain[i] + 64) and (y < yBrain[i] + 64) then
     1633    for I := 0 to nPlOffered - 1 do
     1634      if (1 shl I and SlotAvailable <> 0) and (x >= xBrain[I]) and
     1635        (y >= yBrain[I]) and (x < xBrain[I] + 64) and (y < yBrain[I] + 64) then
    16311636      begin
    1632         InitPopup(i);
    1633         if yBrain[i] > y0Brain then
    1634           PopupMenu1.Popup(left + xBrain[i] + 4, top + yBrain[i] + 60)
     1637        InitPopup(I);
     1638        if yBrain[I] > y0Brain then
     1639          PopupMenu1.Popup(left + xBrain[I] + 4, top + yBrain[I] + 60)
    16351640        else
    1636           PopupMenu1.Popup(left + xBrain[i] + 4, top + yBrain[i] + 4);
     1641          PopupMenu1.Popup(left + xBrain[I] + 4, top + yBrain[I] + 4);
    16371642      end
    16381643  end
     
    16541659    SmartInvalidate(xTurnSlider - 2, y0Mini + 61, xTurnSlider + wTurnSlider + 2,
    16551660      yTurnSlider + 9);
    1656     Tracking := true
    1657   end
     1661    Tracking := True;
     1662  end;
    16581663end;
    16591664
     
    16811686        SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 61 + 21);
    16821687      end;
    1683   end
     1688  end;
    16841689end;
    16851690
     
    17061711        PaintInfo;
    17071712        SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 61 + 21);
    1708       end
    1709   end
     1713      end;
     1714  end;
    17101715end;
    17111716
     
    17141719  if WorldSize < nWorldSize - 1 then
    17151720  begin
    1716     inc(WorldSize);
     1721    Inc(WorldSize);
    17171722    PaintInfo;
    17181723    SmartInvalidate(344, y0Mini - 77, 510, y0Mini - 77 + 21);
    1719   end
     1724  end;
    17201725end;
    17211726
     
    17241729  if WorldSize > 0 then
    17251730  begin
    1726     dec(WorldSize);
     1731    Dec(WorldSize);
    17271732    PaintInfo;
    17281733    SmartInvalidate(344, y0Mini - 77, 510, y0Mini - 77 + 21);
    1729   end
     1734  end;
    17301735end;
    17311736
    17321737procedure TStartDlg.FormClose(Sender: TObject; var Action: TCloseAction);
    17331738begin
    1734   DirectDlg.Close
     1739  DirectDlg.Close;
    17351740end;
    17361741
    17371742procedure TStartDlg.ListClick(Sender: TObject);
    17381743var
    1739   i: integer;
    1740 begin
    1741   if (Tab = 1) and ((List.ItemIndex = 0) <> (Page = pgEditRandom)) then
     1744  I: Integer;
     1745begin
     1746  if (Tab = tbMap) and ((List.ItemIndex = 0) <> (Page = pgEditRandom)) then
    17421747  begin
    17431748    if List.ItemIndex = 0 then
     
    17451750    else
    17461751      Page := pgEditMap;
    1747     for i := 0 to ControlCount - 1 do
    1748       Controls[i].Visible := Controls[i].Tag and (256 shl Page) <> 0;
     1752    for I := 0 to ControlCount - 1 do
     1753      Controls[I].Visible := Controls[I].Tag and (256 shl Integer(Page)) <> 0;
    17491754    SmartInvalidate(328, Up1Btn.top - 12, ClientWidth, Up2Btn.top + 35);
    17501755  end;
    17511756  if Page = pgLoad then
    1752     TurnValid := false;
     1757    TurnValid := False;
    17531758  PaintInfo;
    17541759  if Page = pgLoad then
     
    17851790        end;
    17861791      if Page = pgLoad then
    1787         AssignFile(f, DataDir + 'Saved' + DirectorySeparator + List.Items[List.ItemIndex] + '.cevo')
     1792        AssignFile(f, DataDir + 'Saved' + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)
    17881793      else
    17891794        AssignFile(f, DataDir + 'Maps'+ DirectorySeparator + List.Items[List.ItemIndex] +
    1790           '.cevo map');
     1795          CevoMapExt);
    17911796      ok := true;
    17921797      try
    17931798        if Page = pgLoad then
    1794           Rename(f, DataDir + 'Saved'+ DirectorySeparator + NewName + '.cevo')
     1799          Rename(f, DataDir + 'Saved'+ DirectorySeparator + NewName + CevoExt)
    17951800        else
    1796           Rename(f, DataDir + 'Maps'+ DirectorySeparator + NewName + '.cevo map');
     1801          Rename(f, DataDir + 'Maps'+ DirectorySeparator + NewName + CevoMapExt);
    17971802      except
    17981803        // Play('INVALID');
     
    18161821          PaintInfo;
    18171822        List.Invalidate;
    1818       end
    1819     end
    1820   end
     1823      end;
     1824    end;
     1825  end;
    18211826end;
    18221827
     
    18371842    begin
    18381843      if Page = pgLoad then
    1839         AssignFile(f, DataDir + 'Saved' + DirectorySeparator + List.Items[List.ItemIndex] + '.cevo')
     1844        AssignFile(f, DataDir + 'Saved' + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)
    18401845      else
    18411846        AssignFile(f, DataDir + 'Maps' + DirectorySeparator + List.Items[List.ItemIndex] +
    1842           '.cevo map');
     1847          CevoMapExt);
    18431848      Erase(f);
    18441849      iDel := List.ItemIndex;
     
    18671872            ReplayBtn.Visible := MiniMode <> mmMultiPlayer;
    18681873        end;
    1869       end
    1870     end
    1871   end
     1874      end;
     1875    end;
     1876  end;
    18721877end;
    18731878
    18741879procedure TStartDlg.DiffBtnClick(Sender: TObject);
    18751880var
    1876   i: integer;
    1877 begin
    1878   for i := 0 to nPlOffered - 1 do
    1879     if (Sender = PlayerSlots[i].DiffUpBtn) and (Difficulty[i] < 3) or
    1880       (Sender = PlayerSlots[i].DiffDownBtn) and (Difficulty[i] > 1) then
     1881  I: Integer;
     1882begin
     1883  for I := 0 to nPlOffered - 1 do
     1884    if (Sender = PlayerSlots[I].DiffUpBtn) and (Difficulty[I] < 3) or
     1885      (Sender = PlayerSlots[I].DiffDownBtn) and (Difficulty[I] > 1) then
    18811886    begin
    1882       if Sender = PlayerSlots[i].DiffUpBtn then
    1883         inc(Difficulty[i])
     1887      if Sender = PlayerSlots[I].DiffUpBtn then
     1888        Inc(Difficulty[I])
    18841889      else
    1885         dec(Difficulty[i]);
    1886       SmartInvalidate(xBrain[i] - 18, yBrain[i] + 19, xBrain[i] - 18 + 12,
    1887         yBrain[i] + (19 + 14));
    1888     end
     1890        Dec(Difficulty[I]);
     1891      SmartInvalidate(xBrain[I] - 18, yBrain[I] + 19, xBrain[I] - 18 + 12,
     1892        yBrain[I] + (19 + 14));
     1893    end;
    18891894end;
    18901895
    18911896procedure TStartDlg.MultiBtnClick(Sender: TObject);
    18921897var
    1893   i: integer;
    1894 begin
    1895   for i := 6 to 8 do
    1896     if Sender = PlayerSlots[i].MultiBtn then
     1898  I: Integer;
     1899begin
     1900  for I := 6 to 8 do
     1901    if Sender = PlayerSlots[I].MultiBtn then
    18971902    begin
    1898       MultiControl := MultiControl xor (1 shl i);
    1899       TButtonC(Sender).ButtonIndex := 2 + (MultiControl shr i) and 1;
    1900     end
     1903      MultiControl := MultiControl xor (1 shl I);
     1904      TButtonC(Sender).ButtonIndex := 2 + (MultiControl shr I) and 1;
     1905    end;
    19011906end;
    19021907
     
    19061911  ListIndex[Tab] := List.ItemIndex;
    19071912  ShowTab := Tab;
    1908   Background.Enabled := true;
     1913  Background.Enabled := True;
    19091914end;
    19101915
     
    19251930  AutoDiff := -AutoDiff;
    19261931  CustomizeBtn.ButtonIndex := CustomizeBtn.ButtonIndex xor 1;
    1927   ChangePage(Page)
     1932  ChangePage(Page);
    19281933end;
    19291934
     
    19321937  if AutoDiff < 5 then
    19331938  begin
    1934     inc(AutoDiff);
     1939    Inc(AutoDiff);
    19351940    SmartInvalidate(120, y0Mini + 61, 272, y0Mini + 61 + 21);
    19361941    SmartInvalidate(xDefault - 2, yDefault - 2, xDefault + 64 + 2,
    19371942      yDefault + 64 + 2);
    1938   end
     1943  end;
    19391944end;
    19401945
     
    19431948  if AutoDiff > 1 then
    19441949  begin
    1945     dec(AutoDiff);
     1950    Dec(AutoDiff);
    19461951    SmartInvalidate(120, y0Mini + 61, 272, y0Mini + 61 + 21);
    19471952    SmartInvalidate(xDefault - 2, yDefault - 2, xDefault + 64 + 2,
    19481953      yDefault + 64 + 2);
    1949   end
     1954  end;
    19501955end;
    19511956
     
    19531958  Shift: TShiftState; x, y: integer);
    19541959begin
    1955   Tracking := false;
     1960  Tracking := False;
    19561961end;
    19571962
     
    19591964  x, y: integer);
    19601965var
    1961   OldLoadTurn, NewSelectedAction: integer;
     1966  OldLoadTurn, NewSelectedAction: Integer;
    19621967begin
    19631968  if Tracking then
     
    20072012          - 8, ClientWidth - ActionSideBorder, yAction + (SelectedAction + 1) *
    20082013          ActionPitch - 8);
    2009     end
    2010   end
     2014    end;
     2015  end;
    20112016end;
    20122017
     
    20152020  if AutoEnemies < nPl - 1 then
    20162021  begin
    2017     inc(AutoEnemies);
     2022    Inc(AutoEnemies);
    20182023    SmartInvalidate(160, yMain + 140, 198, yMain + 140 + 21);
    2019   end
     2024  end;
    20202025end;
    20212026
     
    20242029  if AutoEnemies > 0 then
    20252030  begin
    2026     dec(AutoEnemies);
     2031    Dec(AutoEnemies);
    20272032    SmartInvalidate(160, yMain + 140, 198, yMain + 140 + 21);
    2028   end
     2033  end;
    20292034end;
    20302035
    20312036procedure TStartDlg.ReplayBtnClick(Sender: TObject);
    20322037begin
    2033   LoadGame(DataDir + 'Saved' + DirectorySeparator, List.Items[List.ItemIndex] + '.cevo',
    2034     LastTurn, true);
     2038  LoadGame(DataDir + 'Saved' + DirectorySeparator, List.Items[List.ItemIndex] + CevoExt,
     2039    LastTurn, True);
    20352040  SlotAvailable := -1;
    20362041end;
Note: See TracChangeset for help on using the changeset viewer.