Changeset 149 for trunk/UGame.pas


Ignore:
Timestamp:
Nov 13, 2017, 12:17:04 AM (7 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r148 r149  
    16361636
    16371637destructor TUnitMove.Destroy;
    1638 var
    1639   LastState: Boolean;
    16401638begin
    16411639  CellFrom := nil;
    16421640  CellTo := nil;
    1643   if Assigned(List) then begin
    1644     // To remove itself from list we need disable owning to not be called twice
    1645     try
    1646       LastState := List.FreeObjects;
    1647       List.FreeObjects := False;
    1648       List.Remove(Self);
    1649     finally
    1650       List.FreeObjects := LastState;
    1651     end;
    1652   end;
     1641  List := nil;
    16531642  inherited Destroy;
    16541643end;
     
    18871876begin
    18881877  for I := MovesFrom.Count - 1 downto 0 do
    1889     TUnitMove(MovesFrom[I]).Free;
     1878    TUnitMove(MovesFrom[I]).List.Remove(TUnitMove(MovesFrom[I]));
    18901879  FreeAndNil(MovesFrom);
    18911880  for I := MovesTo.Count - 1 downto 0 do
    1892     TUnitMove(MovesTo[I]).Free;
     1881    TUnitMove(MovesTo[I]).List.Remove(TUnitMove(MovesTo[I]));
    18931882  FreeAndNil(MovesTo);
    18941883  for I := Links.Count - 1 downto 0 do
     
    23072296      // Fallback
    23082297      for I := MovesTo.Count - 1 downto 0 do
    2309         TUnitMove(MovesTo[I]).Free;
     2298        Player.Moves.Remove(MovesTo[I]);
    23102299      for I := 0 to Neighbors.Count - 1 do
    23112300      if (TCell(Neighbors[I]).Player = Player) and (AttackersCount(TCell(Neighbors[I])) = 0) then begin
     
    23422331      if ssShift in ShiftState then begin
    23432332        // Make maximum unit move without confirmation dialog
    2344         for I := SelectedCell.MovesFrom.Count - 1 downto 0 do
    2345           TUnitMove(SelectedCell.MovesFrom[I]).Free;
     2333        for I := SelectedCell.MovesFrom.Count - 1 downto 0 do begin
     2334          Player.Moves.Remove(SelectedCell.MovesFrom[I]);
     2335        end;
    23462336        Game.CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell.Power, False);
    23472337        SelectedCell := nil;
     
    23512341        // move all power to new selected cell
    23522342        for I := SelectedCell.MovesFrom.Count - 1 downto 0 do
    2353           TUnitMove(SelectedCell.MovesFrom[I]).Free;
     2343          Player.Moves.Remove(SelectedCell.MovesFrom[I]);
    23542344        UnitMove := Game.CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell.Power, False);
    23552345        if Assigned(UnitMove) then
     
    26202610var
    26212611  NewMove: TUnitMove;
    2622   I: Integer;
    26232612  CountOnce: Integer;
    26242613  CountRepeat: Integer;
    26252614  Confirm: Boolean;
    26262615begin
    2627   I := 0;
    26282616  Confirm := True;
    26292617  Result := Moves.SearchByFromTo(CellFrom, CellTo);
     
    26432631    if Assigned(Result) then begin
    26442632      // Already have such move
    2645       if (CountOnce = 0) and (CountRepeat = 0) then Moves.Delete(I)
    2646         else begin
     2633      if (CountOnce = 0) and (CountRepeat = 0) then begin
     2634          Result.List.Remove(Result);
     2635        end else begin
    26472636          Result.CountOnce := CountOnce;
    26482637          Result.CountRepeat := CountRepeat;
     
    29032892
    29042893    List := TCells.Create;
    2905     List.FreeObjects := False;
    2906     Map.Cells.GetCellsWithWeight(List, Round(LongestDistance * 0.6), Round(LongestDistance * 0.8));
    2907     StartCell := List[Random(List.Count)];
    2908     FreeAndNil(List);
     2894    try
     2895      List.FreeObjects := False;
     2896      Map.Cells.GetCellsWithWeight(List, Round(LongestDistance * 0.6), Round(LongestDistance * 0.8));
     2897      StartCell := List[Random(List.Count)];
     2898    finally
     2899      FreeAndNil(List);
     2900    end;
    29092901  end;
    29102902end;
Note: See TracChangeset for help on using the changeset viewer.