Changeset 84 for trunk


Ignore:
Timestamp:
Nov 5, 2014, 10:11:26 PM (10 years ago)
Author:
chronos
Message:
  • Added: Discovered flag in player map is now stored to game save.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r83 r84  
    200200  end;
    201201
     202  TPlayerCells = class;
     203  TPlayerMap = class;
     204
    202205  { TPlayerCell }
    203206
     
    206209    InVisibleRange: Boolean;
    207210    MapCell: TCell;
     211    List: TPlayerCells;
     212    procedure LoadFromNode(Node: TDOMNode);
     213    procedure SaveToNode(Node: TDOMNode);
    208214  end;
    209215
     
    211217
    212218  TPlayerCells = class(TObjectList)
     219    Map: TPlayerMap;
    213220    function SearchCell(Cell: TCell): TPlayerCell;
     221    procedure LoadFromNode(Node: TDOMNode);
     222    procedure SaveToNode(Node: TDOMNode);
    214223  end;
    215224
     
    219228    Cells: TPlayerCells;
    220229    Player: TPlayer;
     230    procedure LoadFromNode(Node: TDOMNode);
     231    procedure SaveToNode(Node: TDOMNode);
    221232    procedure Update;
    222233    constructor Create;
     
    480491end;
    481492
     493{ TPlayerCell }
     494
     495procedure TPlayerCell.LoadFromNode(Node: TDOMNode);
     496begin
     497  Explored := ReadBoolean(Node, 'Explored', False);
     498  MapCell := List.Map.Player.Game.Map.Cells.FindById(ReadInteger(Node, 'MapCell', 0));
     499end;
     500
     501procedure TPlayerCell.SaveToNode(Node: TDOMNode);
     502begin
     503  WriteBoolean(Node, 'Explored', Explored);
     504  WriteInteger(Node, 'MapCell', MapCell.Id);
     505end;
     506
    482507{ TPlayerCells }
    483508
     
    492517end;
    493518
     519procedure TPlayerCells.LoadFromNode(Node: TDOMNode);
     520var
     521  Node2: TDOMNode;
     522  NewCell: TPlayerCell;
     523begin
     524  Count := 0;
     525  Node2 := Node.FirstChild;
     526  while Assigned(Node2) and (Node2.NodeName = 'Cell') do begin
     527    NewCell := TPlayerCell.Create;
     528    NewCell.List := Self;
     529    NewCell.LoadFromNode(Node2);
     530    Add(NewCell);
     531    Node2 := Node2.NextSibling;
     532  end;
     533end;
     534
     535procedure TPlayerCells.SaveToNode(Node: TDOMNode);
     536var
     537  I: Integer;
     538  NewNode: TDOMNode;
     539begin
     540  for I := 0 to Count - 1 do begin;
     541    NewNode := Node.OwnerDocument.CreateElement('Cell');
     542    Node.AppendChild(NewNode);
     543    TPlayerCell(Items[I]).SaveToNode(NewNode);
     544  end;
     545end;
     546
    494547{ TPlayerMap }
     548
     549procedure TPlayerMap.LoadFromNode(Node: TDOMNode);
     550var
     551  NewNode: TDOMNode;
     552begin
     553  with Node do begin
     554    NewNode := FindNode('Cells');
     555    if Assigned(NewNode) then
     556      Cells.LoadFromNode(NewNode);
     557  end;
     558end;
     559
     560procedure TPlayerMap.SaveToNode(Node: TDOMNode);
     561var
     562  NewNode: TDOMNode;
     563begin
     564  with Node do begin
     565    NewNode := OwnerDocument.CreateElement('Cells');
     566    AppendChild(NewNode);
     567    Cells.SaveToNode(NewNode);
     568  end;
     569end;
    495570
    496571procedure TPlayerMap.Update;
     
    507582  for I := 0 to Cells.Count - 1 do
    508583  with TPlayerCell(Cells[I]) do begin
     584    List := Cells;
    509585    Explored := False;
    510586    InVisibleRange := False;
     
    516592begin
    517593  Cells := TPlayerCells.Create;
     594  Cells.Map := Self;
    518595end;
    519596
     
    15691646
    15701647procedure TPlayer.LoadFromNode(Node: TDOMNode);
     1648var
     1649  NewNode: TDOMNode;
    15711650begin
    15721651  Id := ReadInteger(Node, 'Id', 0);
     
    15761655  StartCell := FGame.Map.Cells.FindById(ReadInteger(Node, 'StartCell', 0));
    15771656  StartUnits := ReadInteger(Node, 'StartUnits', 0);
     1657
     1658  with Node do begin
     1659    NewNode := FindNode('Map');
     1660    if Assigned(NewNode) then
     1661      PlayerMap.LoadFromNode(NewNode);
     1662  end;
    15781663end;
    15791664
    15801665procedure TPlayer.SaveToNode(Node: TDOMNode);
     1666var
     1667  NewNode: TDOMNode;
    15811668begin
    15821669  WriteInteger(Node, 'Id', Id);
     
    15861673  WriteInteger(Node, 'StartCell', StartCell.Id);
    15871674  WriteInteger(Node, 'StartUnits', StartUnits);
     1675
     1676  with Node do begin
     1677    NewNode := OwnerDocument.CreateElement('Map');
     1678    AppendChild(NewNode);
     1679    PlayerMap.SaveToNode(NewNode);
     1680  end;
    15881681end;
    15891682
Note: See TracChangeset for help on using the changeset viewer.