Changeset 176 for trunk/UGame.pas


Ignore:
Timestamp:
Jan 30, 2018, 6:36:50 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Clients moved to TServer class.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        88backup
        99xtactics.exe
         10*.lrj
  • trunk/UGame.pas

    r171 r176  
    3030  TMapArea = class;
    3131  TClient = class;
     32  TServer = class;
    3233
    3334  TTerrainType = (ttVoid, ttNormal, ttCity);
     
    430431    Game: TGame;
    431432    procedure New(Name: string);
     433    constructor Create(FreeObjects: Boolean = True);
    432434  end;
    433435
     
    460462    procedure SetRunning(AValue: Boolean);
    461463    procedure BuildTerrain;
    462     procedure InitClients;
    463464    procedure SelectPlayerStartCell(Player: TPlayer);
    464465    procedure CalculatePlayersDistance;
     
    466467    procedure InitDefaultPlayersSetting;
    467468  public
     469    Server: TServer;
    468470    DevelMode: Boolean;
    469471    Players: TPlayers;
    470472    PlayersSetting: TPlayers;
    471     Clients: TClients;
    472473    Map: TMap;
    473474    MapImageFileName: string;
     
    511512  end;
    512513
     514  { TServer }
     515
     516  TServer = class
     517  private
     518    FGame: TGame;
     519    procedure SetGame(AValue: TGame);
     520  public
     521    Clients: TClients;
     522    procedure InitClients;
     523    procedure Clear;
     524    constructor Create;
     525    destructor Destroy; override;
     526    property Game: TGame read FGame write SetGame;
     527  end;
     528
    513529var
    514530  PlayerModeText: array[TPlayerMode] of string;
     
    617633  NewClient.Name := Name;
    618634  Add(NewClient);
     635end;
     636
     637constructor TClients.Create(FreeObjects: Boolean = True);
     638begin
     639  Game := nil;
     640  inherited;
    619641end;
    620642
     
    29062928  end else begin
    29072929    FRunning := AValue;
    2908     for I := 0 to Clients.Count - 1 do
    2909     with TClient(Clients[I]) do begin
     2930    for I := 0 to Server.Clients.Count - 1 do
     2931    with TClient(Server.Clients[I]) do begin
    29102932      View.Clear;
    29112933    end;
     
    30983120end;
    30993121
    3100 procedure TGame.InitClients;
     3122procedure TServer.SetGame(AValue: TGame);
     3123var
     3124  I: Integer;
     3125begin
     3126  if FGame = AValue then Exit;
     3127  FGame := AValue;
     3128  for I := 0 to Clients.Count - 1 do
     3129    Clients[I].Game := FGame;
     3130  Clients.Game := Game;
     3131end;
     3132
     3133procedure TServer.InitClients;
    31013134var
    31023135  Client: TClient;
     
    31063139  Clients.New('Spectator');
    31073140
    3108   for Player in Players do
     3141  for Player in Game.Players do
    31093142  with Player do
    31103143  if Mode = pmHuman then begin
     
    31213154      else View.CenterMap;
    31223155  end;
     3156end;
     3157
     3158procedure TServer.Clear;
     3159begin
     3160  Clients.Clear;
     3161  Game.Clear;
     3162end;
     3163
     3164constructor TServer.Create;
     3165begin
     3166  FGame := nil;
     3167  Clients := TClients.Create;
     3168end;
     3169
     3170destructor TServer.Destroy;
     3171begin
     3172  FreeAndNil(Clients);
     3173  inherited Destroy;
    31233174end;
    31243175
     
    33003351        else CurrentPlayer := nil;
    33013352
    3302       InitClients;
    33033353      Map.Cells.FixRefId;
    33043354
     
    34843534  PlayersSetting := TPlayers.Create;
    34853535  PlayersSetting.Game := Self;
    3486   Clients := TClients.Create;
    3487   Clients.Game := Self;
    34883536
    34893537  MapImageFileName := 'Images/Maps/WorldMap.png';
     
    35013549destructor TGame.Destroy;
    35023550begin
    3503   FreeAndNil(Clients);
    35043551  FreeAndNil(PlayersSetting);
    35053552  FreeAndNil(Players);
     
    35103557procedure TGame.Clear;
    35113558begin
    3512   Clients.Clear;
    35133559  Players.Clear;
    35143560  Map.Clear;
     
    35583604    else CurrentPlayer := nil;
    35593605
    3560   InitClients;
    35613606  ComputePlayerStats;
    35623607end;
Note: See TracChangeset for help on using the changeset viewer.