Changeset 344 for trunk/Building.pas


Ignore:
Timestamp:
Dec 23, 2024, 8:16:05 AM (9 hours ago)
Author:
chronos
Message:
  • Modified: Improved implementation of TItemList class to be generic class to avoid explicit typecasting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Building.pas

    r317 r344  
    2727  { TBuildingKinds }
    2828
    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;
    3231  end;
    3332
     
    4645  { TBuildings }
    4746
    48   TBuildings = class(TItemList)
     47  TBuildings = class(TItemList<TBuilding>)
    4948    Game: TObject; // TGame;
    50     class function GetItemClass: TItemClass; override;
    5149  end;
    5250
     
    6765uses
    6866  Map;
    69 
    70 { TBuildings }
    71 
    72 class function TBuildings.GetItemClass: TItemClass;
    73 begin
    74   Result := TBuilding;
    75 end;
    7667
    7768{ TBuilding }
     
    148139{ TBuildingKinds }
    149140
    150 class function TBuildingKinds.GetItemClass: TItemClass;
    151 begin
    152   Result := TBuildingKind;
    153 end;
    154 
    155141function TBuildingKinds.FindBySpecialType(SpecialType: TBuildingSpecialType
    156   ): TItem;
     142  ): TBuildingKind;
    157143var
    158144  I: Integer;
    159145begin
    160146  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);
    162148  if I < Count then Result := Items[I]
    163149    else Result := nil;
Note: See TracChangeset for help on using the changeset viewer.