Changeset 346 for trunk/Player.pas


Ignore:
Timestamp:
Dec 25, 2024, 11:04:56 AM (27 hours ago)
Author:
chronos
Message:
  • Fixed: Build on Linux.
  • Modified: Improved internal code structure.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Player.pas

    r344 r346  
    137137  public
    138138    Game: TObject; //TGame;
     139    procedure Assign(Source: TItemList<TPlayer>); override;
    139140    procedure New(Name: string; Color: TColor; Mode: TPlayerMode);
    140141    function CreateItem(Name: string = ''): TPlayer; override;
     
    160161    CountOnce: Integer;
    161162    CountRepeat: Integer;
     163    procedure Assign(Source: TUnitMove);
    162164    procedure LoadFromNode(Node: TDOMNode);
    163165    procedure SaveToNode(Node: TDOMNode);
     
    173175    Game: TObject; //TGame;
    174176    Player: TPlayer;
     177    procedure Assign(Source: TUnitMoves);
    175178    function SearchByFromTo(CellFrom, CellTo: TPlayerCell): TUnitMove;
    176179    procedure LoadFromNode(Node: TDOMNode);
     
    416419begin
    417420  for I := 0 to Cells.Count - 1 do
    418   with TPlayerCell(Cells[I]) do begin
     421  with Cells[I] do begin
    419422    for J := Neighbors.Count - 1 downto 0 do
    420423      DisconnectFrom(Neighbors[J]);
     
    440443  with TPlayerCell(Cells[I]) do begin
    441444    for J := 0 to MapCell.Neighbors.Count - 1 do
    442       ConnectTo(TPlayerCell(TCell(MapCell.Neighbors[J]).PlayerCell));
     445      ConnectTo(TPlayerCell(MapCell.Neighbors[J].PlayerCell));
    443446  end;
    444447end;
     
    499502end;
    500503
     504procedure TPlayers.Assign(Source: TItemList<TPlayer>);
     505var
     506  I: Integer;
     507begin
     508  inherited;
     509  for I := 0 to Count - 1 do
     510    Items[I].Game := Game;
     511end;
     512
    501513procedure TPlayers.New(Name: string; Color: TColor; Mode: TPlayerMode);
    502 begin
    503   AddItem(Name);
    504   Last.Color := Color;
    505   Last.Mode := Mode;
     514var
     515  NewPlayer: TPlayer;
     516begin
     517  NewPlayer := AddItem(Name);
     518  NewPlayer.Color := Color;
     519  NewPlayer.Mode := Mode;
    506520  if Mode = pmComputer then
    507     Last.Agressivity := caMedium;
     521    NewPlayer.Agressivity := caMedium;
    508522end;
    509523
     
    583597{ TUnitMoves }
    584598
     599procedure TUnitMoves.Assign(Source: TUnitMoves);
     600var
     601  I: Integer;
     602begin
     603  while Count > Source.Count do
     604    Delete(Count - 1);
     605  while Count < Source.Count do
     606    Add(TUnitMove.Create);
     607  for I := 0 to Count - 1 do begin
     608    Items[I].Assign(Source.Items[I]);
     609  end;
     610end;
     611
    585612function TUnitMoves.SearchByFromTo(CellFrom, CellTo: TPlayerCell): TUnitMove;
    586613var
     
    663690      else raise Exception.Create('Unit move already exists');
    664691  end else
     692end;
     693
     694procedure TUnitMove.Assign(Source: TUnitMove);
     695begin
     696  CountOnce := Source.CountOnce;
     697  CountRepeat := Source.CountRepeat;
     698  CellFrom.MapCell.Id := Source.CellFrom.MapCell.Id;
     699  CellTo.MapCell.Id := Source.CellTo.MapCell.Id;
    665700end;
    666701
     
    801836begin
    802837  inherited;
    803   //Game := TPlayer(Source).Game;
    804838  TotalCells := TPlayer(Source).TotalCells;
    805839  TotalUnits := TPlayer(Source).TotalUnits;
     
    809843  StartCell := TPlayer(Source).StartCell;
    810844  Color := TPlayer(Source).Color;
    811   //Units.Assign(TPlayer(Source).Units);
     845  Units.Assign(TPlayer(Source).Units);
     846  Moves.Assign(TPlayer(Source).Moves);
    812847  Nation := TPlayer(Source).Nation;
    813848end;
Note: See TracChangeset for help on using the changeset viewer.