Changeset 344 for trunk/Player.pas
- Timestamp:
- Dec 23, 2024, 8:16:05 AM (10 hours ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Player.pas
r342 r344 100 100 procedure GetValue(Index: Integer; out Value); override; 101 101 procedure SetValue(Index: Integer; var Value); override; 102 function GetReferenceList(Index: Integer): TItemList; override;102 function GetReferenceList(Index: Integer): IList<TItem>; override; 103 103 class function GetClassSysName: string; override; 104 104 class function GetClassName: string; override; … … 134 134 { TPlayers } 135 135 136 TPlayers = class(TItemList )136 TPlayers = class(TItemList<TPlayer>) 137 137 public 138 138 Game: TObject; //TGame; 139 class function GetItemClass: TItemClass; override;140 139 procedure New(Name: string; Color: TColor; Mode: TPlayerMode); 141 function CreateItem(Name: string = ''): T Item; override;140 function CreateItem(Name: string = ''): TPlayer; override; 142 141 function GetFirstHuman: TPlayer; 143 142 procedure LoadConfig(Config: TXmlConfig; Path: string); … … 488 487 Result := 0; 489 488 for I := 0 to Count - 1 do 490 if TPlayer(Items[I]).IsAlive then Inc(Result);489 if Items[I].IsAlive then Inc(Result); 491 490 end; 492 491 … … 497 496 Players.Clear; 498 497 for I := 0 to Count - 1 do 499 if TPlayer(Items[I]).IsAlive then Players.Add(TPlayer(Items[I])); 500 end; 501 502 class function TPlayers.GetItemClass: TItemClass; 503 begin 504 Result := TPlayer; 498 if Items[I].IsAlive then Players.Add(Items[I]); 505 499 end; 506 500 … … 508 502 begin 509 503 AddItem(Name); 510 TPlayer(Last).Color := Color;511 TPlayer(Last).Mode := Mode;504 Last.Color := Color; 505 Last.Mode := Mode; 512 506 if Mode = pmComputer then 513 TPlayer(Last).Agressivity := caMedium;514 end; 515 516 function TPlayers.CreateItem(Name: string): T Item;507 Last.Agressivity := caMedium; 508 end; 509 510 function TPlayers.CreateItem(Name: string): TPlayer; 517 511 begin 518 512 Result := inherited; 519 TPlayer(Result).Game := Game;513 Result.Game := Game; 520 514 end; 521 515 … … 525 519 begin 526 520 I := 0; 527 while (I < Count) and ( TPlayer(Items[I]).Mode <> pmHuman) do Inc(I);528 if I < Count then Result := TPlayer(Items[I])521 while (I < Count) and (Items[I].Mode <> pmHuman) do Inc(I); 522 if I < Count then Result := Items[I] 529 523 else Result := nil; 530 524 end; … … 544 538 Items[I] := CreateItem; 545 539 Items[I].Id := GetNewId; 546 TPlayer(Items[I]).LoadConfig(Config, Path + '/Player' + IntToStr(I));540 Items[I].LoadConfig(Config, Path + '/Player' + IntToStr(I)); 547 541 end; 548 542 end; … … 555 549 begin 556 550 for I := 0 to Count - 1 do 557 TPlayer(Items[I]).SaveConfig(Config, Path + '/Player' + IntToStr(I));551 Items[I].SaveConfig(Config, Path + '/Player' + IntToStr(I)); 558 552 with Config do begin 559 553 SetValue(DOMString(Path + '/Count'), Count); … … 568 562 SetLength(Result, 0); 569 563 for I := 0 to Count - 1 do 570 if TPlayer(Items[I]).IsAlive then begin564 if Items[I].IsAlive then begin 571 565 SetLength(Result, Length(Result) + 1); 572 Result[Length(Result) - 1] := TPlayer(Items[I]);566 Result[Length(Result) - 1] := Items[I]; 573 567 end; 574 568 end; … … 581 575 SetLength(Result, 0); 582 576 for I := 0 to Count - 1 do 583 if TPlayer(Items[I]).TotalCities > 0 then begin577 if Items[I].TotalCities > 0 then begin 584 578 SetLength(Result, Length(Result) + 1); 585 Result[Length(Result) - 1] := TPlayer(Items[I]);579 Result[Length(Result) - 1] := Items[I]; 586 580 end; 587 581 end; … … 828 822 Defensive := GetValue(DOMString(Path + '/Defensive'), False); 829 823 Agressivity := TComputerAgressivity(GetValue(DOMString(Path + '/Agressivity'), 0)); 830 Nation := T Nation(TGame(Game).GameSystem.Nations.FindById(GetValue(DOMString(Path + '/Nation'), 0)));824 Nation := TGame(Game).GameSystem.Nations.FindById(GetValue(DOMString(Path + '/Nation'), 0)); 831 825 end; 832 826 end; … … 1228 1222 end; 1229 1223 1230 function TPlayer.GetReferenceList(Index: Integer): TItemList;1224 function TPlayer.GetReferenceList(Index: Integer): IList<TItem>; 1231 1225 begin 1232 1226 if Index = 2 then Result := TGame(Game).GameSystem.Nations … … 1272 1266 ((TGame(Game).GrowCells = gcPlayerCities) and (Assigned(Building) and (Building.Kind.SpecialType = stCity)))) then begin 1273 1267 if not Assigned(OneUnit) then begin 1274 NewUnit := TGame(Game).Units.AddNew(T UnitKind(TGame(Game).GameSystem.UnitKinds.First), 0);1268 NewUnit := TGame(Game).Units.AddNew(TGame(Game).GameSystem.UnitKinds.First, 0); 1275 1269 NewUnit.Player := Self; 1276 1270 NewUnit.MapCell := Cells[I];
Note:
See TracChangeset
for help on using the changeset viewer.