close Warning: Can't synchronize with repository "(default)" (No changeset 184 in the repository). Look in the Trac log for more information.

Changeset 146


Ignore:
Timestamp:
Nov 12, 2017, 1:57:59 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Use generic lists instead classic untyped lists.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r145 r146  
    66
    77uses
    8   Classes, SysUtils, ExtCtrls, Graphics, Contnrs, XMLConf, XMLRead, XMLWrite,
     8  Classes, SysUtils, ExtCtrls, Graphics, XMLConf, XMLRead, XMLWrite,
    99  DOM, Math, LazFileUtils, UXMLUtils, Dialogs, Types, LCLType, LCLIntf, fgl;
    1010
     
    8080  { TCells }
    8181
    82   TCells = class(TObjectList)
     82  TCells = class(TFPGObjectList<TCell>)
    8383    Map: TMap;
    8484    procedure FixRefId;
     
    103103  { TCellLinks }
    104104
    105   TCellLinks = class(TObjectList)
     105  TCellLinks = class(TFPGObjectList<TCellLink>)
    106106    Map: TMap;
    107107    function FindByCells(Cell1, Cell2: TCell): TCellLink;
     
    159159  end;
    160160
    161   TMapAreas = class(TObjectList)
     161  TMapAreas = class(TFPGObjectList<TMapArea>)
    162162  end;
    163163
     
    222222  { TPlayerCells }
    223223
    224   TPlayerCells = class(TObjectList)
     224  TPlayerCells = class(TFPGObjectList<TPlayerCell>)
    225225    Map: TPlayerMap;
    226226    function SearchCell(Cell: TCell): TPlayerCell;
     
    256256  { TGameTurnStats }
    257257
    258   TGameTurnStats = class(TObjectList)
     258  TGameTurnStats = class(TFPGObjectList<TGameTurnStat>)
    259259    procedure LoadFromNode(Node: TDOMNode);
    260260    procedure SaveToNode(Node: TDOMNode);
     
    303303  TComputer = class
    304304    Game: TGame;
    305     Targets: TObjectList;
     305    //Targets: TFPGObjectList<TPlayer>;
    306306    CellProcessDirection: Boolean;
    307307    procedure AttackNeutral;
     
    318318  { TPlayers }
    319319
    320   TPlayers = class(TObjectList)
     320  TPlayers = class(TFPGObjectList<TPlayer>)
    321321    Game: TGame;
    322322    NewPlayerId: Integer;
     
    352352  { TUnitMoves }
    353353
    354   TUnitMoves = class(TObjectList)
     354  TUnitMoves = class(TFPGObjectList<TUnitMove>)
    355355    Game: TGame;
    356356    procedure LoadFromNode(Node: TDOMNode);
     
    377377  { TClients }
    378378
    379   TClients = class(TObjectList)
     379  TClients = class(TFPGObjectList<TClient>)
    380380    Game: TGame;
    381381    procedure New(Name: string);
     
    695695begin
    696696  Cells := TCells.Create;
    697   Cells.OwnsObjects := False;
     697  Cells.FreeObjects := False;
    698698end;
    699699
     
    713713    // To remove itself from list we need disable owning to not be called twice
    714714    try
    715       LastState := Map.CellLinks.OwnsObjects;
    716       Map.CellLinks.OwnsObjects := False;
     715      LastState := Map.CellLinks.FreeObjects;
     716      Map.CellLinks.FreeObjects := False;
    717717      Map.CellLinks.Remove(Self);
    718718    finally
    719       Map.CellLinks.OwnsObjects := LastState;
     719      Map.CellLinks.FreeObjects := LastState;
    720720    end;
    721721  end;
     
    799799begin
    800800  Cells := TCells.Create;
    801   Cells.OwnsObjects := False;
     801  Cells.FreeObjects := False;
    802802end;
    803803
     
    16101610    // To remove itself from list we need disable owning to not be called twice
    16111611    try
    1612       LastState := List.OwnsObjects;
    1613       List.OwnsObjects := False;
     1612      LastState := List.FreeObjects;
     1613      List.FreeObjects := False;
    16141614      List.Remove(Self);
    16151615    finally
    1616       List.OwnsObjects := LastState;
     1616      List.FreeObjects := LastState;
    16171617    end;
    16181618  end;
     
    18231823  Player := nil;
    18241824  Neighbors := TCells.Create;
    1825   Neighbors.OwnsObjects := False;
     1825  Neighbors.FreeObjects := False;
    18261826  MovesFrom := TUnitMoves.Create;
    1827   MovesFrom.OwnsObjects := False;
     1827  MovesFrom.FreeObjects := False;
    18281828  MovesTo := TUnitMoves.Create;
    1829   MovesTo.OwnsObjects := False;
     1829  MovesTo.FreeObjects := False;
    18301830  Links := TCellLinks.Create;
    1831   Links.OwnsObjects := False;
     1831  Links.FreeObjects := False;
    18321832end;
    18331833
     
    19561956end;
    19571957
    1958 function CellCompare(Item1, Item2: Pointer): Integer;
    1959 begin
    1960   if TCell(Item1).Power > TCell(Item2).Power then Result := 1
    1961   else if TCell(Item1).Power < TCell(Item2).Power then Result := -1
     1958function CellCompare(const Item1, Item2: TCell): Integer;
     1959begin
     1960  if Item1.Power > Item2.Power then Result := 1
     1961  else if Item1.Power < Item2.Power then Result := -1
    19621962  else Result := 0;
    19631963end;
    19641964
    1965 function CellCompareDescending(Item1, Item2: Pointer): Integer;
    1966 begin
    1967   if TCell(Item1).Power > TCell(Item2).Power then Result := -1
    1968   else if TCell(Item1).Power < TCell(Item2).Power then Result := 1
     1965function CellCompareDescending(const Item1, Item2: TCell): Integer;
     1966begin
     1967  if Item1.Power > Item2.Power then Result := -1
     1968  else if Item1.Power < Item2.Power then Result := 1
    19691969  else Result := 0;
    19701970end;
     
    19851985  AllCells := Game.Map.Cells;
    19861986  TargetCells := TCells.Create;
    1987   TargetCells.OwnsObjects := False;
     1987  TargetCells.FreeObjects := False;
    19881988
    19891989  // Get list of all attack target cells
     
    20462046  AllCells := Game.Map.Cells;
    20472047  TargetCells := TCells.Create;
    2048   TargetCells.OwnsObjects := False;
     2048  TargetCells.FreeObjects := False;
    20492049
    20502050  // Get list of all attack target cells
     
    21132113  AllCells := Game.Map.Cells;
    21142114  TargetCells := TCells.Create;
    2115   TargetCells.OwnsObjects := False;
     2115  TargetCells.FreeObjects := False;
    21162116  NewTargetCells := TCells.Create;
    2117   NewTargetCells.OwnsObjects := False;
     2117  NewTargetCells.FreeObjects := False;
    21182118
    21192119  // Get list of all enemy border cells
     
    21772177    TargetCells := NewTargetCells;
    21782178    NewTargetCells := TCells.Create;
    2179     NewTargetCells.OwnsObjects := False;
     2179    NewTargetCells.FreeObjects := False;
    21802180  end;
    21812181
     
    22182218begin
    22192219  BorderCells := TCells.Create;
    2220   BorderCells.OwnsObjects := False;
     2220  BorderCells.FreeObjects := False;
    22212221  AllCells := Game.Map.Cells;
    22222222
     
    26562656  Result := nil;
    26572657  NewList := TCells.Create;
    2658   NewList.OwnsObjects := False;
     2658  NewList.FreeObjects := False;
    26592659  NewListVoid := TCells.Create;
    2660   NewListVoid.OwnsObjects := False;
     2660  NewListVoid.FreeObjects := False;
    26612661
    26622662  for C := 0 to List.Count - 1 do
     
    27232723begin
    27242724  List := TCells.Create;
    2725   List.OwnsObjects := False;
     2725  List.FreeObjects := False;
    27262726
    27272727  BorderList := TCells.Create;
    2728   BorderList.OwnsObjects := False;
     2728  BorderList.FreeObjects := False;
    27292729
    27302730  // Build area bridges
Note: See TracChangeset for help on using the changeset viewer.