Changeset 152
- Timestamp:
- Nov 15, 2017, 6:19:17 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormNew.pas
r151 r152 333 333 334 334 procedure TFormNew.Load(Game: TGame); 335 var336 I: Integer;337 335 begin 338 336 CheckBoxSymetricMap.Checked := Game.SymetricMap; … … 340 338 SpinEditVoidPercent.Value := Game.VoidPercentage; 341 339 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); 351 341 CheckBoxCity.Checked := Game.CityEnabled; 352 342 SpinEditCityPercent.Value := Game.CityPercentage; … … 367 357 368 358 procedure 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; 359 begin 360 Game.Players.Assign(Players); 380 361 Game.Players.NewPlayerId := Players.NewPlayerId; 381 362 Game.SymetricMap := CheckBoxSymetricMap.Checked; -
trunk/UGame.pas
r151 r152 310 310 destructor Destroy; override; 311 311 procedure Assign(Source: TPlayer); 312 procedure LoadConfig(Config: TXmlConfig; Path: string); 313 procedure SaveConfig(Config: TXmlConfig; Path: string); 312 314 property Game: TGame read FGame write SetGame; 313 315 property Client: TClient read FClient write SetClient; … … 345 347 constructor Create; 346 348 function GetFirstHuman: TPlayer; 349 procedure Assign(Source: TPlayers); 350 procedure LoadConfig(Config: TXmlConfig; Path: string); 351 procedure SaveConfig(Config: TXmlConfig; Path: string); 347 352 end; 348 353 … … 1201 1206 end; 1202 1207 1208 procedure TPlayers.Assign(Source: TPlayers); 1209 var 1210 I: Integer; 1211 begin 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; 1221 end; 1222 1223 procedure TPlayers.LoadConfig(Config: TXmlConfig; Path: string); 1224 var 1225 I: Integer; 1226 NewCount: Integer; 1227 begin 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; 1240 end; 1241 1242 procedure TPlayers.SaveConfig(Config: TXmlConfig; Path: string); 1243 var 1244 I: Integer; 1245 begin 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; 1251 end; 1252 1203 1253 { TUnitMoves } 1204 1254 … … 2425 2475 Agressivity := Source.Agressivity; 2426 2476 Defensive := Source.Defensive; 2477 Computer.Game := Source.Computer.Game; 2478 Computer.CellProcessDirection := Source.Computer.CellProcessDirection; 2479 end; 2480 2481 procedure TPlayer.LoadConfig(Config: TXmlConfig; Path: string); 2482 begin 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; 2491 end; 2492 2493 procedure TPlayer.SaveConfig(Config: TXmlConfig; Path: string); 2494 begin 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; 2427 2503 end; 2428 2504 … … 2968 3044 SetValue(DOMString(Path + '/GrowCells'), Integer(GrowCells)); 2969 3045 SetValue(DOMString(Path + '/WinObjective'), Integer(WinObjective)); 3046 Players.SaveConfig(Config, Path + '/Players'); 2970 3047 end; 2971 3048 end; … … 2999 3076 if (Value >= Integer(Low(TWinObjective))) and (Value <= Integer(High(TWinObjective))) then 3000 3077 WinObjective := TWinObjective(Value) else WinObjective := Low(TWinObjective); 3078 Players.LoadConfig(Config, Path + '/Players'); 3001 3079 end; 3002 3080 end;
Note:
See TracChangeset
for help on using the changeset viewer.