Changeset 364 for trunk/Start.pas


Ignore:
Timestamp:
Apr 12, 2021, 11:55:20 PM (4 years ago)
Author:
chronos
Message:
  • Added: Partial network game play implementation.
  • Modified: Code cleanup.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Start.pas

    r363 r364  
    1010
    1111type
     12
     13  { TPlayerSlot }
     14
    1215  TPlayerSlot = class
    1316    DiffUpBtn: TButtonC;
     
    8487    procedure AutoEnemyDownBtnClick(Sender: TObject);
    8588    procedure ReplayBtnClick(Sender: TObject);
    86   public
    87     EmptyPicture: TBitmap;
    88     procedure UpdateFormerGames;
    89     procedure UpdateMaps;
    9089  private
    9190    WorldSize: Integer;
     
    134133    procedure LoadAiBrainsPictures;
    135134    procedure UpdateInterface;
     135    procedure ShowSettings;
     136  public
     137    EmptyPicture: TBitmap;
     138    procedure UpdateFormerGames;
     139    procedure UpdateMaps;
    136140  end;
    137141
     
    492496      (Screen.Height - Height) div 2, Width, Height)
    493497  end;
     498end;
     499
     500procedure TStartDlg.ShowSettings;
     501begin
     502  SettingsDlg := TSettingsDlg.Create(nil);
     503  if SettingsDlg.ShowModal = mrOk then begin
     504    LoadAssets;
     505    Invalidate;
     506    UpdateInterface;
     507    Background.UpdateInterface;
     508  end;
     509  FreeAndNil(SettingsDlg);
    494510end;
    495511
     
    968984
    969985          OpenKey(AppRegistryKey, True);
    970           if AutoDiff > 0 then
    971           begin
    972             WriteString('DefaultAI', BrainDefault.FileName);
    973             SlotAvailable := 0; // PlayerSlot will be invalid hereafter
    974             PlayersBrain[0] := BrainTerm;
    975             Difficulty[0] := PlayerAutoDiff[AutoDiff];
    976             for I := 1 to nPl - 1 do
    977               if (Page = pgStartRandom) and (I <= AutoEnemies) or
    978                 (Page = pgStartMap) and (I < nMapStartPositions) then begin
    979                 if AutoDiff = 1 then PlayersBrain[I] := Brains.GetBeginner
    980                   else PlayersBrain[I] := BrainDefault;
    981                 Difficulty[I] := EnemyAutoDiff[AutoDiff];
    982               end  else PlayersBrain[I] := nil;
    983           end else begin
    984             for I := 6 to 8 do
    985               if (PlayersBrain[0].Kind <> btNoTerm) and (MultiControl and (1 shl I) <> 0)
    986               then begin
    987                 PlayersBrain[I + 3] := PlayersBrain[I];
    988                 Difficulty[I + 3] := Difficulty[I];
    989                 PlayersBrain[I + 6] := PlayersBrain[I];
    990                 Difficulty[I + 6] := Difficulty[I];
    991               end else begin
    992                 PlayersBrain[I + 3] := nil;
    993                 PlayersBrain[I + 6] := nil;
    994               end;
     986          if BrainDefault.Kind <> btNetworkClient then begin
     987            if AutoDiff > 0 then begin
     988              WriteString('DefaultAI', BrainDefault.FileName);
     989              SlotAvailable := 0; // PlayerSlot will be invalid hereafter
     990              PlayersBrain[0] := BrainTerm;
     991              Difficulty[0] := PlayerAutoDiff[AutoDiff];
     992              for I := 1 to nPl - 1 do
     993                if (Page = pgStartRandom) and (I <= AutoEnemies) or
     994                  (Page = pgStartMap) and (I < nMapStartPositions) then begin
     995                  if AutoDiff = 1 then PlayersBrain[I] := Brains.GetBeginner
     996                    else PlayersBrain[I] := BrainDefault;
     997                  Difficulty[I] := EnemyAutoDiff[AutoDiff];
     998                end else PlayersBrain[I] := nil;
     999            end else begin
     1000              for I := 6 to 8 do
     1001                if (PlayersBrain[0].Kind <> btNoTerm) and (MultiControl and (1 shl I) <> 0)
     1002                then begin
     1003                  PlayersBrain[I + 3] := PlayersBrain[I];
     1004                  Difficulty[I + 3] := Difficulty[I];
     1005                  PlayersBrain[I + 6] := PlayersBrain[I];
     1006                  Difficulty[I + 6] := Difficulty[I];
     1007                end else begin
     1008                  PlayersBrain[I + 3] := nil;
     1009                  PlayersBrain[I + 6] := nil;
     1010                end;
     1011            end;
    9951012          end;
    9961013
     
    11621179  AIBrains: TBrains;
    11631180begin
     1181  FixedLines := 0;
    11641182  PlayerPopupIndex := PlayerIndex;
    11651183  EmptyMenu(PopupMenu1.Items);
    11661184  if PlayerPopupIndex < 0 then begin // select default AI
    1167     FixedLines := 0;
     1185    OfferBrain(BrainNetworkClient, FixedLines);
     1186    Inc(FixedLines);
     1187
     1188    MenuItem := TMenuItem.Create(PopupMenu1);
     1189    MenuItem.Caption := '-';
     1190    PopupMenu1.Items.Add(MenuItem);
     1191
     1192    Inc(FixedLines);
    11681193    if Brains.GetKindCount(btAI) >= 2 then begin
    11691194      OfferBrain(BrainRandom, FixedLines);
     
    11771202    FreeAndNil(AIBrains);
    11781203  end else begin
    1179     FixedLines := 0;
    11801204    if PlayerPopupIndex > 0 then begin
    11811205      OfferBrain(nil, FixedLines);
     
    11891213      end;
    11901214    if PlayerPopupIndex > 0 then begin
     1215      OfferBrain(BrainNetworkServer, FixedLines);
     1216      Inc(FixedLines);
     1217
    11911218      MenuItem := TMenuItem.Create(PopupMenu1);
    11921219      MenuItem.Caption := '-';
     
    12671294          begin
    12681295            PlayersBrain[0] := BrainSuperVirtual;
    1269             Difficulty[0] := 0
     1296            Difficulty[0] := 0;
    12701297          end;
    12711298          if PlayersBrain[0].Kind in [btNoTerm, btSuperVirtual] then
     
    14241451    ChangeTab(TStartTab((x - TabOffset) div TabSize));
    14251452  end
    1426   else if Page = pgMain then
    1427   begin
     1453  else if Page = pgMain then begin
    14281454    case SelectedAction of
    1429       maConfig:
    1430         begin
    1431           SettingsDlg := TSettingsDlg.Create(nil);
    1432           if SettingsDlg.ShowModal = mrOk then begin
    1433             LoadAssets;
    1434             Invalidate;
    1435             UpdateInterface;
    1436             Background.UpdateInterface;
    1437           end;
    1438           FreeAndNil(SettingsDlg);
    1439         end;
    1440       maManual:
    1441         DirectHelp(cStartHelp);
    1442       maCredits:
    1443         DirectHelp(cStartCredits);
    1444       maAIDev:
    1445         OpenDocument(HomeDir + AITemplateFileName);
    1446       maWeb:
    1447         OpenURL(CevoHomepage);
     1455      maConfig: ShowSettings;
     1456      maManual: DirectHelp(cStartHelp);
     1457      maCredits: DirectHelp(cStartCredits);
     1458      maAIDev: OpenDocument(HomeDir + AITemplateFileName);
     1459      maWeb: OpenURL(CevoHomepage);
    14481460    end;
    14491461  end
     
    14601472        else
    14611473          PopupMenu1.Popup(left + xBrain[I] + 4, top + yBrain[I] + 4);
    1462       end
     1474      end;
    14631475  end
    14641476  else if (AutoDiff > 1) and ((Page = pgStartRandom) or (Page = pgStartMap)) and
Note: See TracChangeset for help on using the changeset viewer.