Changeset 152


Ignore:
Timestamp:
Nov 15, 2017, 6:19:17 PM (7 years ago)
Author:
chronos
Message:
  • Added: Remember players configuration for new game.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormNew.pas

    r151 r152  
    333333
    334334procedure TFormNew.Load(Game: TGame);
    335 var
    336   I: Integer;
    337335begin
    338336  CheckBoxSymetricMap.Checked := Game.SymetricMap;
     
    340338  SpinEditVoidPercent.Value := Game.VoidPercentage;
    341339  SpinEditVoidPercent.Enabled := Game.VoidEnabled;
    342   for I := 0 to Players.Count - 1 do
    343     Players[I] := nil;
    344   Players.Count := Game.Players.Count;
    345   for I := 0 to Game.Players.Count - 1 do begin
    346     Players[I] := TPlayer.Create;
    347     TPlayer(Players[I]).Assign(TPlayer(Game.Players[I]));
    348   end;
    349   Players.NewPlayerId := Game.Players.NewPlayerId;
    350 
     340  Players.Assign(Game.Players);
    351341  CheckBoxCity.Checked := Game.CityEnabled;
    352342  SpinEditCityPercent.Value := Game.CityPercentage;
     
    367357
    368358procedure TFormNew.Save(Game: TGame);
    369 var
    370   I: Integer;
    371 begin
    372   while Game.Players.Count > Players.Count do
    373     Game.Players.Delete(Game.Players.Count - 1);
    374   while Game.Players.Count < Players.Count do
    375     Game.Players.Add(TPlayer.Create);
    376   for I := 0 to Game.Players.Count - 1 do begin
    377     TPlayer(Game.Players[I]).Assign(TPlayer(Players[I]));
    378     TPlayer(Game.Players[I]).Game := Game;
    379   end;
     359begin
     360  Game.Players.Assign(Players);
    380361  Game.Players.NewPlayerId := Players.NewPlayerId;
    381362  Game.SymetricMap := CheckBoxSymetricMap.Checked;
  • trunk/UGame.pas

    r151 r152  
    310310    destructor Destroy; override;
    311311    procedure Assign(Source: TPlayer);
     312    procedure LoadConfig(Config: TXmlConfig; Path: string);
     313    procedure SaveConfig(Config: TXmlConfig; Path: string);
    312314    property Game: TGame read FGame write SetGame;
    313315    property Client: TClient read FClient write SetClient;
     
    345347    constructor Create;
    346348    function GetFirstHuman: TPlayer;
     349    procedure Assign(Source: TPlayers);
     350    procedure LoadConfig(Config: TXmlConfig; Path: string);
     351    procedure SaveConfig(Config: TXmlConfig; Path: string);
    347352  end;
    348353
     
    12011206end;
    12021207
     1208procedure TPlayers.Assign(Source: TPlayers);
     1209var
     1210  I: Integer;
     1211begin
     1212  while Count > Source.Count do
     1213    Delete(Count - 1);
     1214  while Count < Source.Count do
     1215    Add(TPlayer.Create);
     1216  for I := 0 to Count - 1 do begin
     1217    TPlayer(Items[I]).Assign(TPlayer(Source[I]));
     1218    TPlayer(Items[I]).Game := Game;
     1219  end;
     1220  NewPlayerId := Source.NewPlayerId;
     1221end;
     1222
     1223procedure TPlayers.LoadConfig(Config: TXmlConfig; Path: string);
     1224var
     1225  I: Integer;
     1226  NewCount: Integer;
     1227begin
     1228  with Config do begin
     1229    NewCount := GetValue(DOMString(Path + '/Count'), -1);
     1230    if NewCount >= 2 then begin
     1231      Self.Clear;
     1232      Count := NewCount;
     1233      for I := 0 to Count - 1 do begin
     1234        Items[I] := TPlayer.Create;
     1235        TPlayer(Items[I]).Game := Game;
     1236        TPlayer(Items[I]).LoadConfig(Config, Path + '/Player' + IntToStr(I));
     1237      end;
     1238    end;
     1239  end;
     1240end;
     1241
     1242procedure TPlayers.SaveConfig(Config: TXmlConfig; Path: string);
     1243var
     1244  I: Integer;
     1245begin
     1246  for I := 0 to Count - 1 do
     1247    TPlayer(Items[I]).SaveConfig(Config, Path + '/Player' + IntToStr(I));
     1248  with Config do begin
     1249    SetValue(DOMString(Path + '/Count'), Count);
     1250  end;
     1251end;
     1252
    12031253{ TUnitMoves }
    12041254
     
    24252475  Agressivity := Source.Agressivity;
    24262476  Defensive := Source.Defensive;
     2477  Computer.Game := Source.Computer.Game;
     2478  Computer.CellProcessDirection := Source.Computer.CellProcessDirection;
     2479end;
     2480
     2481procedure TPlayer.LoadConfig(Config: TXmlConfig; Path: string);
     2482begin
     2483  with Config do begin
     2484    Self.Name := string(GetValue(DOMString(Path + '/Name'), ''));
     2485    Color := TColor(GetValue(DOMString(Path + '/Color'), 0));
     2486    StartUnits := GetValue(DOMString(Path + '/StartUnits'), 5);
     2487    Mode := TPlayerMode(GetValue(DOMString(Path + '/Mode'), 0));
     2488    Defensive := GetValue(DOMString(Path + '/Defensive'), False);
     2489    Agressivity := TComputerAgressivity(GetValue(DOMString(Path + '/Agressivity'), 0));
     2490  end;
     2491end;
     2492
     2493procedure TPlayer.SaveConfig(Config: TXmlConfig; Path: string);
     2494begin
     2495  with Config do begin
     2496    SetValue(DOMString(Path + '/Name'), DOMString(Self.Name));
     2497    SetValue(DOMString(Path + '/Color'), Integer(Color));
     2498    SetValue(DOMString(Path + '/StartUnits'), StartUnits);
     2499    SetValue(DOMString(Path + '/Mode'), Integer(Mode));
     2500    SetValue(DOMString(Path + '/Defensive'), Defensive);
     2501    SetValue(DOMString(Path + '/Agressivity'), Integer(Agressivity));
     2502  end;
    24272503end;
    24282504
     
    29683044    SetValue(DOMString(Path + '/GrowCells'), Integer(GrowCells));
    29693045    SetValue(DOMString(Path + '/WinObjective'), Integer(WinObjective));
     3046    Players.SaveConfig(Config, Path + '/Players');
    29703047  end;
    29713048end;
     
    29993076    if (Value >= Integer(Low(TWinObjective))) and (Value <= Integer(High(TWinObjective))) then
    30003077      WinObjective := TWinObjective(Value) else WinObjective := Low(TWinObjective);
     3078    Players.LoadConfig(Config, Path + '/Players');
    30013079  end;
    30023080end;
Note: See TracChangeset for help on using the changeset viewer.