Changeset 344
- Timestamp:
- Dec 23, 2024, 8:16:05 AM (6 hours ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Building.pas
r317 r344 27 27 { TBuildingKinds } 28 28 29 TBuildingKinds = class(TItemList) 30 class function GetItemClass: TItemClass; override; 31 function FindBySpecialType(SpecialType: TBuildingSpecialType): TItem; 29 TBuildingKinds = class(TItemList<TBuildingKind>) 30 function FindBySpecialType(SpecialType: TBuildingSpecialType): TBuildingKind; 32 31 end; 33 32 … … 46 45 { TBuildings } 47 46 48 TBuildings = class(TItemList )47 TBuildings = class(TItemList<TBuilding>) 49 48 Game: TObject; // TGame; 50 class function GetItemClass: TItemClass; override;51 49 end; 52 50 … … 67 65 uses 68 66 Map; 69 70 { TBuildings }71 72 class function TBuildings.GetItemClass: TItemClass;73 begin74 Result := TBuilding;75 end;76 67 77 68 { TBuilding } … … 148 139 { TBuildingKinds } 149 140 150 class function TBuildingKinds.GetItemClass: TItemClass;151 begin152 Result := TBuildingKind;153 end;154 155 141 function TBuildingKinds.FindBySpecialType(SpecialType: TBuildingSpecialType 156 ): T Item;142 ): TBuildingKind; 157 143 var 158 144 I: Integer; 159 145 begin 160 146 I := 0; 161 while (I < Count) and ( TBuildingKind(Items[I]).SpecialType <> SpecialType) do Inc(I);147 while (I < Count) and (Items[I].SpecialType <> SpecialType) do Inc(I); 162 148 if I < Count then Result := Items[I] 163 149 else Result := nil; -
trunk/Core.pas
r339 r344 606 606 FormMain.FormClient.Client := nil; 607 607 for I := 0 to Game.Players.Count - 1 do begin 608 Player := TPlayer(Game.Players[I]);608 Player := Game.Players[I]; 609 609 with Player do 610 610 if Mode = pmHuman then begin … … 739 739 FormMain.FormClient.Client := nil; 740 740 for I := 0 to Game.Players.Count - 1 do begin 741 Player := TPlayer(Game.Players[I]);741 Player := Game.Players[I]; 742 742 with Player do 743 743 if Mode = pmHuman then begin -
trunk/Forms/FormCharts.pas
r318 r344 62 62 Chart1.Series.Clear; 63 63 for I := 0 to Game.Players.Count - 1 do 64 with TPlayer(Game.Players[I])do begin64 with Game.Players[I] do begin 65 65 NewSeries := TLineSeries.Create(nil); 66 66 NewSeries.LinePen.Color := Color; -
trunk/Forms/FormGameSystem.lfm
r330 r344 1 1 object FormGameSystem: TFormGameSystem 2 2 Left = 954 3 Height = 4 823 Height = 402 4 4 Top = 479 5 Width = 6515 Width = 542 6 6 Caption = 'Game system' 7 ClientHeight = 4 828 ClientWidth = 6519 DesignTimePPI = 1 447 ClientHeight = 402 8 ClientWidth = 542 9 DesignTimePPI = 120 10 10 OnCreate = FormCreate 11 11 OnDestroy = FormDestroy 12 LCLVersion = '3. 4.0.0'12 LCLVersion = '3.6.0.0' 13 13 object ButtonSave: TButton 14 Left = 1 6015 Height = 3 816 Top = 43217 Width = 11314 Left = 133 15 Height = 32 16 Top = 360 17 Width = 94 18 18 Anchors = [akLeft, akBottom] 19 19 Caption = 'Save' … … 23 23 end 24 24 object ButtonLoad: TButton 25 Left = 2 426 Height = 3 827 Top = 43228 Width = 11325 Left = 20 26 Height = 32 27 Top = 360 28 Width = 94 29 29 Anchors = [akLeft, akBottom] 30 30 Caption = 'Load' … … 34 34 end 35 35 object ButtonCancel: TButton 36 Left = 3 7437 Height = 3 838 Top = 43239 Width = 11336 Left = 311 37 Height = 32 38 Top = 360 39 Width = 94 40 40 Anchors = [akRight, akBottom] 41 41 Caption = 'Cancel' … … 45 45 end 46 46 object ButtonOk: TButton 47 Left = 51648 Height = 3 849 Top = 43250 Width = 11347 Left = 430 48 Height = 32 49 Top = 360 50 Width = 94 51 51 Anchors = [akRight, akBottom] 52 52 Caption = 'OK' … … 56 56 end 57 57 object PageControl1: TPageControl 58 Left = 1 659 Height = 40060 Top = 1 661 Width = 61358 Left = 13 59 Height = 334 60 Top = 13 61 Width = 511 62 62 ActivePage = TabSheetGeneral 63 63 Anchors = [akTop, akLeft, akRight, akBottom] … … 67 67 object TabSheetGeneral: TTabSheet 68 68 Caption = 'General' 69 ClientHeight = 3 6270 ClientWidth = 60569 ClientHeight = 301 70 ClientWidth = 503 71 71 ParentFont = False 72 72 object CheckBoxEmptyCellsNeutral: TCheckBox 73 Left = 1 674 Height = 2 975 Top = 1 676 Width = 33073 Left = 13 74 Height = 24 75 Top = 13 76 Width = 277 77 77 Caption = 'Set cells without player units as neutral' 78 78 ParentFont = False … … 80 80 end 81 81 object CheckBoxUnitsSplitMerge: TCheckBox 82 Left = 1 683 Height = 2 984 Top = 5585 Width = 21382 Left = 13 83 Height = 24 84 Top = 46 85 Width = 178 86 86 Caption = 'Units can split or merge' 87 87 ParentFont = False … … 89 89 end 90 90 object CheckBoxUnitsMoveImmediately: TCheckBox 91 Left = 1 692 Height = 2 993 Top = 9594 Width = 21791 Left = 13 92 Height = 24 93 Top = 79 94 Width = 182 95 95 Caption = 'Units move immediately' 96 96 ParentFont = False … … 98 98 end 99 99 object Label5: TLabel 100 Left = 1 6101 Height = 2 5102 Top = 1 36103 Width = 1 53100 Left = 13 101 Height = 20 102 Top = 113 103 Width = 128 104 104 Caption = 'Preferred grid type:' 105 105 ParentColor = False … … 107 107 end 108 108 object ComboBoxPreferredGridType: TComboBox 109 Left = 2 72110 Height = 33111 Top = 1 36112 Width = 304113 ItemHeight = 2 5109 Left = 227 110 Height = 28 111 Top = 113 112 Width = 253 113 ItemHeight = 20 114 114 Items.Strings = ( 115 115 'None' … … 140 140 end 141 141 object OpenDialog1: TOpenDialog 142 Left = 440143 Top = 1 60142 Left = 367 143 Top = 133 144 144 end 145 145 object SaveDialog1: TSaveDialog 146 Left = 232147 Top = 1 60146 Left = 193 147 Top = 133 148 148 end 149 149 end -
trunk/Forms/FormGameSystem.pas
r330 r344 51 51 52 52 uses 53 MapType ;53 MapType, ItemList; 54 54 55 55 resourcestring -
trunk/Forms/FormItem.pas
r321 r344 80 80 J: Integer; 81 81 Control: TControl; 82 ReferenceList: TItemList ;82 ReferenceList: TItemList<TItem>; 83 83 ReferenceItem: TItem; 84 84 begin … … 106 106 try 107 107 TComboBox(Control).Items.Clear; 108 ReferenceList := Item.GetReferenceList(Index);108 ReferenceList := TItemList<TItem>(Item.GetReferenceList(Index)); 109 109 if Assigned(ReferenceList) then 110 110 for J := 0 to ReferenceList.Count - 1 do -
trunk/Forms/FormList.pas
r317 r344 46 46 Selected: Boolean); 47 47 private 48 FList: TItemList;49 procedure SetList(AValue: TItemList);48 FList: IList<TItem>; 49 procedure SetList(AValue: IList<TItem>); 50 50 procedure UpdateListViewColumns; 51 51 public … … 54 54 procedure UpdateInterface; 55 55 procedure UpdateList; 56 property List: TItemListread FList write SetList;56 property List: IList<TItem> read FList write SetList; 57 57 end; 58 58 … … 98 98 if Assigned(ListView1.Selected) then 99 99 with TItem(ListView1.Selected.Data) do begin 100 TempEntry := List.Create Item;100 TempEntry := List.CreateBaseItem; 101 101 TempEntry.Assign(TItem(ListView1.Selected.Data)); 102 102 FormItem := TFormItem.Create(Self); … … 122 122 if (MaxItemCount <> -1) and (List.Count >= MaxItemCount) then Exit; 123 123 124 TempEntry := List.Create Item;124 TempEntry := List.CreateBaseItem; 125 125 FormItem := TFormItem.Create(Self); 126 126 try 127 TempEntry.Name := List.GetNextAvailableName(SNew + ' ' + LowerCase(List.Get ItemClass.GetClassName));127 TempEntry.Name := List.GetNextAvailableName(SNew + ' ' + LowerCase(List.GetName)); 128 128 FormItem.Item := TempEntry; 129 129 if FormItem.ShowModal = mrOk then begin … … 146 146 if (MaxItemCount <> -1) and (List.Count >= MaxItemCount) then Exit; 147 147 148 TempEntry := List.Create Item;148 TempEntry := List.CreateBaseItem; 149 149 TempEntry.Assign(TItem(ListView1.Selected.Data)); 150 150 FormItem := TFormItem.Create(Self); … … 219 219 //Item.Caption := GetName; 220 220 Item.Data := List[Item.Index]; 221 Fields := List.GetItem Class.GetFields;221 Fields := List.GetItemFields; 222 222 try 223 223 for I := 0 to Fields.Count - 1 do begin … … 250 250 end; 251 251 252 procedure TFormList.SetList(AValue: TItemList);252 procedure TFormList.SetList(AValue: IList<TItem>); 253 253 begin 254 254 if FList = AValue then Exit; … … 261 261 Fields: TItemFields; 262 262 begin 263 Fields := List.GetItem Class.GetFields;263 Fields := List.GetItemFields; 264 264 ListView1.Columns.BeginUpdate; 265 265 try -
trunk/Forms/FormNew.pas
r330 r344 388 388 GamePreview.GeneratePlayers := False; 389 389 GamePreview.New; 390 GamePreview.CurrentPlayer := TPlayer(GamePreview.Players.First);390 GamePreview.CurrentPlayer := GamePreview.Players.First; 391 391 Bitmap := Image1.Picture.Bitmap; 392 392 Bitmap.SetSize(Image1.Width, Image1.Height); -
trunk/Game.pas
r342 r344 295 295 var 296 296 Cell: TCell; 297 NewPower: Integer;298 297 begin 299 298 // Randomize map terrain … … 317 316 NewPower := Random(MaxNeutralUnits + 1); 318 317 if (NewPower > 0) and not Assigned(OneUnit) then begin 319 OneUnit := Units.AddNew( TUnitKind(GameSystem.UnitKinds[0]), NewPower);318 OneUnit := Units.AddNew(GameSystem.UnitKinds[0], NewPower); 320 319 end; 321 320 Player := nil; … … 330 329 with Cell do begin 331 330 if (Terrain = ttNormal) and CityEnabled and (Random < CityPercentage / 100) then begin 332 Building := TBuilding(Buildings.AddItem('City'));333 Building.Kind := TBuildingKind(GameSystem.BuildingKinds.FindBySpecialType(stCity));331 Building := Buildings.AddItem('City'); 332 Building.Kind := GameSystem.BuildingKinds.FindBySpecialType(stCity); 334 333 end; 335 334 end; … … 344 343 345 344 for I := 0 to Players.Count - 1 do begin 346 TPlayer(Players[I]).Reset;347 TPlayer(Players[I]).StartCell := nil;345 Players[I].Reset; 346 Players[I].StartCell := nil; 348 347 end; 349 348 for I := 0 to Players.Count - 1 do 350 with TPlayer(Players[I])do begin351 Player := TPlayer(Players[I]);349 with Players[I] do begin 350 Player := Players[I]; 352 351 PlayerMap.Update; 353 352 if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin … … 355 354 if Assigned(Player.StartCell) then begin 356 355 if SymetricMap and (I = 1) then 357 StartCell := Map.Cells[Map.Cells.Count - 1 - Map.Cells.IndexOf( TPlayer(Players[0]).StartCell)];356 StartCell := Map.Cells[Map.Cells.Count - 1 - Map.Cells.IndexOf(Players[0].StartCell)]; 358 357 359 358 if CityEnabled then begin 360 StartCell.Building := TBuilding(Buildings.AddItem('City'));361 StartCell.Building.Kind := TBuildingKind(GameSystem.BuildingKinds.FindBySpecialType(stCity));359 StartCell.Building := Buildings.AddItem('City'); 360 StartCell.Building.Kind := GameSystem.BuildingKinds.FindBySpecialType(stCity); 362 361 end; 363 362 StartCell.Player := Player; 364 363 if GameSystem.UnitKinds.Count > 0 then begin 365 364 if not Assigned(StartCell.OneUnit) then 366 StartCell.OneUnit := Self.Units.AddNew( TUnitKind(GameSystem.UnitKinds[0]), Player.StartUnits);365 StartCell.OneUnit := Self.Units.AddNew(GameSystem.UnitKinds[0], Player.StartUnits); 367 366 StartCell.OneUnit.Power := Player.StartUnits; 368 StartCell.OneUnit.Kind := TUnitKind(GameSystem.UnitKinds[0]);367 StartCell.OneUnit.Kind := GameSystem.UnitKinds[0]; 369 368 StartCell.OneUnit.Player := Player; 370 369 end; … … 428 427 begin 429 428 for I := 0 to Players.Count - 1 do begin 430 Player := TPlayer(Players[I]);429 Player := Players[I]; 431 430 if Assigned(Player.StartCell) then begin 432 431 Player.StartCell.Weight := 1; … … 633 632 if Assigned(NewNode) then 634 633 Players.LoadFromNode(NewNode); 635 if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])634 if Players.Count > 0 then CurrentPlayer := Players[0] 636 635 else CurrentPlayer := nil; 637 636 … … 644 643 645 644 for I := 0 to Players.Count - 1 do begin 646 TPlayer(Players[I]).PlayerMap.Update;647 TPlayer(Players[I]).PlayerMap.CheckVisibility;645 Players[I].PlayerMap.Update; 646 Players[I].PlayerMap.CheckVisibility; 648 647 end; 649 648 ComputePlayerStats; … … 742 741 begin 743 742 for I := 0 to Players.Count - 1 do 744 with TPlayer(Players[I])do begin743 with Players[I] do begin 745 744 TotalUnits := 0; 746 745 TotalCells := 0; … … 763 762 begin 764 763 for I := 0 to Players.Count - 1 do 765 with TPlayer(Players[I])do begin764 with Players[I] do begin 766 765 NewStat := TGameTurnStat.Create; 767 766 NewStat.DiscoveredCells := TotalDiscovered; … … 804 803 NewPlayerIndex := NewPlayerIndex mod AlivePlayers.Count; 805 804 end; 806 CurrentPlayer := TPlayer(AlivePlayers[NewPlayerIndex]);805 CurrentPlayer := AlivePlayers[NewPlayerIndex]; 807 806 finally 808 807 AlivePlayers.Free; … … 931 930 I: Integer; 932 931 begin 933 for I := 0 to Players.Count - 1 do TPlayer(Players[I]).Clear;932 for I := 0 to Players.Count - 1 do Players[I].Clear; 934 933 Map.Clear; 935 934 Units.Clear; … … 960 959 961 960 InitPlayers; 962 if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])961 if Players.Count > 0 then CurrentPlayer := Players[0] 963 962 else CurrentPlayer := nil; 964 963 -
trunk/GameSystem.pas
r342 r344 4 4 5 5 uses 6 Classes, SysUtils, Generics.Collections, Units,DOM, XMLRead, XMLWrite, XML,6 Classes, SysUtils, Generics.Collections, DOM, XMLRead, XMLWrite, XML, 7 7 XMLConf, FileUtil, LazFileUtils, MapType, Nation, Building, ItemList, UnitKind; 8 8 -
trunk/ItemList.pas
r342 r344 7 7 8 8 type 9 TItemList= class;9 //TItemList<T> = class; 10 10 TUndefinedEnum = (eeNone); 11 11 … … 34 34 function AddField(Index: Integer; SysName, Name: string; DataType: TDataType): TItemField; 35 35 function SearchByIndex(Index: Integer): TItemField; 36 end; 37 38 { IList } 39 40 IList<T> = interface 41 function GetName: string; 42 function GetCount: SizeInt; 43 function GetItem(Index: SizeInt): T; 44 function Remove(constref AValue: T): SizeInt; 45 function Add(constref AValue: T): SizeInt; 46 function CreateBaseItem(Name: string = ''): T; 47 function GetNextAvailableName(Name: string): string; 48 function GetItemFields: TItemFields; 49 procedure SetItem(Index: SizeInt; AValue: T); 50 property Count: SizeInt read GetCount; 51 property Items[Index: SizeInt]: T read GetItem write SetItem; default; 36 52 end; 37 53 … … 71 87 class function GetClassSysName: string; virtual; 72 88 class function GetClassName: string; virtual; 73 function GetReferenceList(Index: Integer): TItemList; virtual;89 function GetReferenceList(Index: Integer): IList<TItem>; virtual; 74 90 constructor Create; virtual; 75 91 end; … … 77 93 TItemClass = class of TItem; 78 94 95 IItemList = interface(IList<TItem>) 96 end; 97 79 98 { TItemList } 80 99 81 TItemList = class(TObjectList<TItem>)100 TItemList<T: TItem> = class(TObjectList<T>, IList<TItem>) 82 101 private 83 102 procedure RecalculateNewId(Reset: Boolean); 84 103 procedure RecalculateItemsId; 104 function GetItem(Index: SizeInt): TItem; 105 procedure SetItem(Index: SizeInt; AValue: TItem); 106 protected 107 function GetCount: SizeInt; override; 85 108 public 109 type 110 var 86 111 NewId: Integer; 87 class function GetItemClass: TItemClass; virtual; 112 function GetName: string; 113 function GetItemFields: TItemFields; 114 function Remove(constref AValue: TItem): SizeInt; 115 function Add(constref AValue: TItem): SizeInt; 116 function CreateItem(Name: string = ''): T; virtual; 117 function CreateBaseItem(Name: string = ''): TItem; 88 118 function IncrementName(Name: string): string; 89 119 function GetNextAvailableName(Name: string): string; 90 function FindById(Id: Integer): T Item;91 function FindByName(Name: string): T Item;120 function FindById(Id: Integer): T; 121 function FindByName(Name: string): T; 92 122 function GetNewId: Integer; 93 123 function ToString: string; override; 94 procedure Assign(Source: TItemList); virtual; 95 function Compare(ItemList: TItemList): Boolean; virtual; 96 function AddItem(Name: string = ''): TItem; virtual; 97 function CreateItem(Name: string = ''): TItem; virtual; 124 procedure Assign(Source: TItemList<T>); virtual; 125 function Compare(ItemList: TItemList<T>): Boolean; virtual; 126 function AddItem(Name: string = ''): T; virtual; 98 127 procedure LoadFromNode(Node: TDOMNode); virtual; 99 128 procedure SaveToNode(Node: TDOMNode); virtual; 100 129 constructor Create(FreeObjects: Boolean = True); 130 function QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj) : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; 131 function _AddRef: Longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; 132 function _Release: Longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; 101 133 end; 102 134 … … 145 177 { TItemList } 146 178 147 procedure TItemList .Assign(Source: TItemList);179 procedure TItemList<T>.Assign(Source: TItemList<T>); 148 180 var 149 181 I: Integer; … … 155 187 end; 156 188 157 function TItemList .Compare(ItemList: TItemList): Boolean;189 function TItemList<T>.Compare(ItemList: TItemList<T>): Boolean; 158 190 var 159 191 I: Integer; … … 167 199 end; 168 200 169 function TItemList.AddItem(Name: string): TItem; 170 begin 171 Result := CreateItem(Name); 201 function TItemList<T>.AddItem(Name: string): T; 202 begin 203 Result := T.Create; 204 Result.Name := Name; 172 205 Result.Id := GetNewId; 173 206 Add(Result); 174 207 end; 175 208 176 function TItemList .CreateItem(Name: string): TItem;177 begin 178 Result := GetItemClass.Create;209 function TItemList<T>.CreateItem(Name: string): T; 210 begin 211 Result := T.Create; 179 212 Result.Name := Name; 180 213 end; 181 214 182 procedure TItemList.LoadFromNode(Node: TDOMNode); 215 function TItemList<T>.CreateBaseItem(Name: string): TItem; 216 begin 217 Result := TItem(CreateItem(Name)); 218 end; 219 220 procedure TItemList<T>.LoadFromNode(Node: TDOMNode); 183 221 var 184 222 Node2: TDOMNode; 185 NewItem: T Item;223 NewItem: T; 186 224 begin 187 225 Count := 0; 188 226 Node2 := Node.FirstChild; 189 while Assigned(Node2) and (Node2.NodeName = UnicodeString( GetItemClass.GetClassSysName)) do begin227 while Assigned(Node2) and (Node2.NodeName = UnicodeString(T.GetClassSysName)) do begin 190 228 NewItem := CreateItem; 191 229 NewItem.LoadFromNode(Node2); … … 195 233 end; 196 234 197 procedure TItemList .SaveToNode(Node: TDOMNode);235 procedure TItemList<T>.SaveToNode(Node: TDOMNode); 198 236 var 199 237 I: Integer; … … 203 241 for I := 0 to Count - 1 do 204 242 with TItem(Items[I]) do begin 205 NewNode2 := Node.OwnerDocument.CreateElement(UnicodeString( GetItemClass.GetClassSysName));243 NewNode2 := Node.OwnerDocument.CreateElement(UnicodeString(T.GetClassSysName)); 206 244 Node.AppendChild(NewNode2); 207 245 SaveToNode(NewNode2); … … 209 247 end; 210 248 211 constructor TItemList .Create(FreeObjects: Boolean);249 constructor TItemList<T>.Create(FreeObjects: Boolean); 212 250 begin 213 251 inherited; … … 215 253 end; 216 254 217 procedure TItemList.RecalculateNewId(Reset: Boolean); 255 function TItemList<T>.QueryInterface(constref iid: tguid; out obj): longint; 256 stdcall; 257 begin 258 end; 259 260 function TItemList<T>._AddRef: Longint; stdcall; 261 begin 262 end; 263 264 function TItemList<T>._Release: Longint; stdcall; 265 begin 266 end; 267 268 function TItemList<T>.GetCount: SizeInt; 269 begin 270 Result := Count; 271 end; 272 273 function TItemList<T>.GetName: string; 274 begin 275 Result := T.GetClassName; 276 end; 277 278 function TItemList<T>.GetItemFields: TItemFields; 279 begin 280 Result := T.GetFields; 281 end; 282 283 function TItemList<T>.Remove(constref AValue: TItem): SizeInt; 284 begin 285 Result := inherited Remove(T(AValue)); 286 end; 287 288 function TItemList<T>.Add(constref AValue: TItem): SizeInt; 289 begin 290 Result := inherited Add(T(AValue)); 291 end; 292 293 procedure TItemList<T>.RecalculateNewId(Reset: Boolean); 218 294 var 219 295 I: Integer; … … 226 302 end; 227 303 228 procedure TItemList .RecalculateItemsId;304 procedure TItemList<T>.RecalculateItemsId; 229 305 var 230 306 I: Integer; … … 235 311 end; 236 312 237 class function TItemList.GetItemClass: TItemClass; 238 begin 239 Result := TItem; 240 end; 241 242 function TItemList.IncrementName(Name: string): string; 313 function TItemList<T>.GetItem(Index: SizeInt): TItem; 314 begin 315 Result := inherited GetItem(Index); 316 end; 317 318 procedure TItemList<T>.SetItem(Index: SizeInt; AValue: TItem); 319 begin 320 inherited SetItem(Index, T(AValue)); 321 end; 322 323 function TItemList<T>.IncrementName(Name: string): string; 243 324 var 244 325 I: Integer; … … 253 334 end; 254 335 255 function TItemList .GetNextAvailableName(Name: string): string;336 function TItemList<T>.GetNextAvailableName(Name: string): string; 256 337 begin 257 338 Result := Name; … … 260 341 end; 261 342 262 function TItemList .FindById(Id: Integer): TItem;343 function TItemList<T>.FindById(Id: Integer): T; 263 344 var 264 345 I: Integer; … … 270 351 end; 271 352 272 function TItemList .FindByName(Name: string): TItem;353 function TItemList<T>.FindByName(Name: string): T; 273 354 var 274 355 I: Integer; … … 280 361 end; 281 362 282 function TItemList .GetNewId: Integer;363 function TItemList<T>.GetNewId: Integer; 283 364 begin 284 365 Result := NewId; … … 286 367 end; 287 368 288 function TItemList .ToString: string;369 function TItemList<T>.ToString: string; 289 370 var 290 371 I: Integer; … … 370 451 var 371 452 ReadId: Integer; 372 ReferenceList: TItemList;453 ReferenceList: IList<TItem>; 373 454 begin 374 455 if Field.DataType = dtString then begin … … 389 470 if Field.DataType = dtReference then begin 390 471 ReadId := ReadInteger(Node, Field.SysName, 0); 391 ReferenceList := GetReferenceList(Field.Index);472 ReferenceList := IList<TItem>(GetReferenceList(Field.Index)); 392 473 if (ReadId > 0) and Assigned(ReferenceList) then 393 474 SetValueReference(Field.Index, TItem(ReferenceList[ReadId])); … … 632 713 end; 633 714 634 function TItem.GetReferenceList(Index: Integer): TItemList;715 function TItem.GetReferenceList(Index: Integer): IList<TItem>; 635 716 begin 636 717 Result := nil; -
trunk/Nation.pas
r317 r344 21 21 { TNations } 22 22 23 TNations = class(TItemList) 24 class function GetItemClass: TItemClass; override; 23 TNations = class(TItemList<TNation>) 25 24 end; 26 25 … … 67 66 end; 68 67 69 { TNations }70 71 class function TNations.GetItemClass: TItemClass;72 begin73 Result := TNation;74 end;75 76 68 end. 77 69 -
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]; -
trunk/UnitKind.pas
r339 r344 25 25 { TUnitKinds } 26 26 27 TUnitKinds = class(TItemList )27 TUnitKinds = class(TItemList<TUnitKind>) 28 28 constructor Create(FreeObjects: Boolean = True); 29 class function GetItemClass: TItemClass; override;30 29 end; 31 30 … … 96 95 end; 97 96 98 class function TUnitKinds.GetItemClass: TItemClass;99 begin100 Result := TUnitKind;101 end;102 103 97 end. 104 98 -
trunk/Units.pas
r342 r344 177 177 begin 178 178 Player := TGame(Game).Players.FindById(PlayerId); 179 Kind := T UnitKind(TGame(Game).GameSystem.UnitKinds.FindById(KindId));179 Kind := TGame(Game).GameSystem.UnitKinds.FindById(KindId); 180 180 end; 181 181
Note:
See TracChangeset
for help on using the changeset viewer.