Changeset 202 for trunk/UCore.pas
- Timestamp:
- May 17, 2018, 5:41:47 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r199 r202 9 9 UGame, UApplicationInfo, UPersistentForm, UScaleDPI, UCoolTranslator, 10 10 URegistry, ULastOpenedList, Registry, Menus, UGeometry, UFormClient, 11 UGameServer, UGameClient, fgl, UServerList ;11 UGameServer, UGameClient, fgl, UServerList, UGameProtocol; 12 12 13 13 type … … 65 65 GameLoaded: Boolean; 66 66 procedure LoadRecentExecute(Sender: TObject); 67 procedure ProcessComputerTurns;68 67 procedure StartNewGame; 69 68 procedure DoPlayerChange(Sender: TObject); … … 91 90 ReopenLastFile: Boolean; 92 91 FormClients: TFPGObjectList<TFormClient>; 93 Clients: TClients;92 LocalClients: TClients; 94 93 ServerList: TServerList; 95 94 procedure Spectate(Player: TPlayer); … … 109 108 110 109 uses 111 UFormMain, UFormNew, UFormSettings, UFormAbout, 110 UFormMain, UFormNew, UFormSettings, UFormAbout, UClientAI, 112 111 UFormHelp, UFormCharts, UFormUnitMoves, UFormPlayersStats; 113 112 … … 240 239 begin 241 240 FirstHuman := Game.Players.GetFirstHuman; 242 if Assigned(FirstHuman) then FormClient.Client := Clients.SearchPlayer(FirstHuman)243 else FormClient.Client := TClient( Clients.First);241 if Assigned(FirstHuman) then FormClient.Client := LocalClients.SearchPlayer(FirstHuman) 242 else FormClient.Client := TClient(LocalClients.First); 244 243 end; 245 244 … … 275 274 end; 276 275 277 procedure TCore.ProcessComputerTurns;278 begin279 while Game.Running and (Game.CurrentPlayer.Mode <> pmHuman) do begin280 if Game.CurrentPlayer.Mode = pmComputer then begin281 Game.CurrentPlayer.Computer.Process;282 RedrawClients;283 Delay(Trunc((100 - AnimationSpeed) / 100 * 2000));284 end;285 Game.NextTurn;286 RedrawClients;287 Application.ProcessMessages;288 Sleep(1);289 end;290 end;291 292 276 procedure TCore.AGameEndTurnExecute(Sender: TObject); 293 277 begin 294 Game.Next Turn;278 Game.NextPlayer; 295 279 RedrawClients; 296 ProcessComputerTurns;297 280 UpdateActions; 298 281 end; … … 399 382 begin 400 383 Server := TServer.Create; 401 Clients := TClients.Create;384 LocalClients := TClients.Create; 402 385 GameSettings := TGame.Create; 403 386 Game := TGame.Create; … … 407 390 Game.OnPlayerChange := DoPlayerChange; 408 391 Server.Game := Game; 409 Clients.Game := Game;392 LocalClients.Game := Game; 410 393 StoredDimension := TControlDimension.Create; 411 394 XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml'; … … 424 407 FreeAndNil(StoredDimension); 425 408 FreeAndNil(Server); 426 FreeAndNil( Clients);409 FreeAndNil(LocalClients); 427 410 FreeAndNil(Game); 428 411 FreeAndNil(GameSettings); … … 448 431 Game.LoadFromFile(FileName); 449 432 Server.InitClients; 450 451 // Create local clients for human players 433 Server.Active := True; 434 435 // Create local LocalClients for human players 452 436 for Player in Game.Players do 453 437 with Player do 454 438 if Mode = pmHuman then begin 455 NewClient := Clients.New(Name);439 NewClient := LocalClients.New(Name); 456 440 NewClient.ControlPlayer := Player; 457 441 NewClient.View.Clear; 458 442 NewClient.View.Zoom := 1; 443 NewClient.LocalServer := Server; 444 NewClient.ConnectType := ctLocal; 445 NewClient.Active := True; 459 446 if Assigned(NewClient.ControlPlayer.StartCell) then 460 447 NewClient.View.CenterPlayerCity(NewClient.ControlPlayer) 461 448 else NewClient.View.CenterMap; 449 end else 450 if Mode = pmComputer then begin 451 NewClient := TComputer.Create; 452 NewClient.Game := Game; 453 NewClient.Name := Name; 454 LocalClients.Add(NewClient); 455 NewClient.ControlPlayer := Player; 456 NewClient.LocalServer := Server; 457 NewClient.ConnectType := ctLocal; 458 NewClient.Active := True; 462 459 end; 463 460 … … 493 490 begin 494 491 Form := TFormClient.Create(nil); 495 Form.Client := Clients.New(SSpectator);492 Form.Client := LocalClients.New(SSpectator); 496 493 //Form.Client.Form := Form; 497 494 //Form.Client.ControlPlayer := Player; … … 505 502 NewClient: TClient; 506 503 Player: TPlayer; 504 ServerClient: TServerClient; 507 505 begin 508 506 Game.New; 509 507 Server.InitClients; 510 511 // Create local clients for human players 508 Server.Active := True; 509 510 // Create local LocalClients for human players 512 511 for Player in Game.Players do 513 512 with Player do 514 513 if Mode = pmHuman then begin 515 NewClient := Clients.New(Name);514 NewClient := LocalClients.New(Name); 516 515 NewClient.ControlPlayer := Player; 517 516 NewClient.View.Clear; 518 517 NewClient.View.Zoom := 1; 518 NewClient.LocalServer := Server; 519 NewClient.ConnectType := ctLocal; 520 NewClient.Active := True; 519 521 if Assigned(NewClient.ControlPlayer.StartCell) then 520 522 NewClient.View.CenterPlayerCity(NewClient.ControlPlayer) 521 523 else NewClient.View.CenterMap; 524 end else 525 if Mode = pmComputer then begin 526 NewClient := TComputer.Create; 527 NewClient.Game := Game; 528 NewClient.Name := Name; 529 LocalClients.Add(NewClient); 530 NewClient.ControlPlayer := Player; 531 NewClient.LocalServer := Server; 532 NewClient.ConnectType := ctLocal; 533 NewClient.Active := True; 522 534 end; 523 535 … … 528 540 RedrawClients; 529 541 UpdateOtherForms; 530 ProcessComputerTurns;531 542 UpdateActions; 543 ServerClient := Server.Clients.SearchByPlayer(Game.CurrentPlayer); 544 if Assigned(ServerClient) then ServerClient.TurnStart 545 else raise Exception.Create('Server client for current player not found.'); 532 546 end; 533 547 … … 535 549 var 536 550 PlayerClient: TClient; 551 ServerClient: TServerClient; 537 552 begin 538 553 if Assigned(Game.CurrentPlayer) then begin 539 PlayerClient := Clients.SearchPlayer(Game.CurrentPlayer);554 PlayerClient := LocalClients.SearchPlayer(Game.CurrentPlayer); 540 555 if Assigned(PlayerClient) then FormClient.Client := PlayerClient; 556 557 ServerClient := Server.Clients.SearchByPlayer(Game.CurrentPlayer); 558 if Assigned(ServerClient) then ServerClient.TurnStart; 541 559 end; 542 560 UpdateOtherForms;
Note:
See TracChangeset
for help on using the changeset viewer.