Changeset 85


Ignore:
Timestamp:
Nov 5, 2014, 10:38:34 PM (10 years ago)
Author:
chronos
Message:
  • Added: With mouse click and with CTRL key pressed new move will set maximum one time and repeated unit counts to selected target cell.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r82 r85  
    378378  if (Abs(StartMousePoint.X - X) < MouseMinDiff) and (Abs(StartMousePoint.Y - Y) < MouseMinDiff) then begin
    379379    if Core.Game.Running and (Core.Game.CurrentPlayer.Mode = pmHuman) then begin
    380       Core.Game.CurrentPlayer.View.SelectCell(Point(X, Y), Core.Game.CurrentPlayer);
     380      Core.Game.CurrentPlayer.View.SelectCell(Point(X, Y), Core.Game.CurrentPlayer, Shift);
    381381      Redraw;
    382382    end;
  • trunk/UGame.pas

    r84 r85  
    9696    constructor Create;
    9797    destructor Destroy; override;
    98     procedure SelectCell(Pos: TPoint; Player: TPlayer);
     98    procedure SelectCell(Pos: TPoint; Player: TPlayer; ShiftState: TShiftState);
    9999    procedure CenterMap;
    100100    function CanvasToCellPos(Pos: TPoint): TPoint;
     
    347347    procedure ClearMovesFromCell(Cell: TCell);
    348348    procedure SetMapType(AValue: TMapType);
    349     procedure SetMove(CellFrom, CellTo: TCell; Power: Integer);
     349    function SetMove(CellFrom, CellTo: TCell; Power: Integer; Confirmation: Boolean = True): TUnitMove;
    350350    procedure SetRunning(AValue: Boolean);
    351351    procedure UpdateRepeatMoves(Player: TPlayer);
     
    17481748          if TCell(Neighbors[I]).GetAvialPower < AttackPower then
    17491749            AttackPower := TCell(Neighbors[I]).GetAvialPower;
    1750           Game.SetMove(Tcell(Neighbors[I]), TCell(TargetCells[C]), AttackPower);
     1750          Game.SetMove(Tcell(Neighbors[I]), TCell(TargetCells[C]), AttackPower, False);
    17511751          TotalAttackPower := TotalAttackPower + AttackPower;
    17521752        end;
     
    18101810          if TCell(Neighbors[I]).GetAvialPower < AttackPower then
    18111811            AttackPower := TCell(Neighbors[I]).GetAvialPower;
    1812           Game.SetMove(TCell(Neighbors[I]), TCell(TargetCells[C]), AttackPower);
     1812          Game.SetMove(TCell(Neighbors[I]), TCell(TargetCells[C]), AttackPower, False);
    18131813          TotalAttackPower := TotalAttackPower + AttackPower;
    18141814        end;
     
    18831883            end;
    18841884            if CanAttack = 0 then
    1885               Game.SetMove(TCell(Neighbors[I]), TCell(TargetCells[C]), TCell(Neighbors[I]).GetAvialPower);
     1885              Game.SetMove(TCell(Neighbors[I]), TCell(TargetCells[C]), TCell(Neighbors[I]).GetAvialPower, False);
    18861886          end;
    18871887          TCell(Neighbors[I]).Mark := True;
     
    19231923end;
    19241924
    1925 procedure TView.SelectCell(Pos: TPoint; Player: TPlayer);
     1925procedure TView.SelectCell(Pos: TPoint; Player: TPlayer; ShiftState: TShiftState);
    19261926var
    19271927  NewSelectedCell: TCell;
     1928  UnitMove: TUnitMove;
     1929  I: Integer;
    19281930begin
    19291931  NewSelectedCell := Game.Map.PosToCell(CanvasToCellPos(Pos), Self);
    19301932  if Assigned(NewSelectedCell) then begin
    19311933    if Assigned(SelectedCell) and Game.Map.IsCellsNeighbor(NewSelectedCell, SelectedCell) then begin
    1932       Game.SetMove(SelectedCell, NewSelectedCell, SelectedCell.Power);
    1933       SelectedCell := nil;
     1934      if ssCtrl in ShiftState then begin
     1935        // If CTRL key pressed then storno all moved from selected cell and
     1936        // move all power to new selected cell
     1937        for I := SelectedCell.MovesFrom.Count - 1 downto 0 do
     1938          TUnitMove(SelectedCell.MovesFrom[I]).Free;
     1939        UnitMove := Game.SetMove(SelectedCell, NewSelectedCell, SelectedCell.Power, False);
     1940        if Assigned(UnitMove) then
     1941          UnitMove.CountRepeat := Player.Game.Map.MaxPower;
     1942        if NewSelectedCell.Player = Player then SelectedCell := NewSelectedCell
     1943          else SelectedCell := nil;
     1944      end else begin
     1945        Game.SetMove(SelectedCell, NewSelectedCell, SelectedCell.Power);
     1946        SelectedCell := nil;
     1947      end;
    19341948    end else
    19351949    if (NewSelectedCell <> SelectedCell) and (NewSelectedCell.Player = Player) then
     
    21552169end;
    21562170
    2157 procedure TGame.SetMove(CellFrom, CellTo: TCell; Power: Integer);
     2171function TGame.SetMove(CellFrom, CellTo: TCell; Power: Integer; Confirmation: Boolean = True): TUnitMove;
    21582172var
    21592173  NewMove: TUnitMove;
     
    21702184  if I < Moves.Count then OldMove := TUnitMove(Moves[I])
    21712185    else OldMove := nil;
     2186  Result := OldMove;
    21722187  if Assigned(OldMove) then begin
    21732188    CountOnce := OldMove.CountOnce;
    21742189    CountRepeat := OldMove.CountRepeat;
    2175     if Assigned(CurrentPlayer) and (CurrentPlayer.Mode = pmHuman) and
     2190    if Assigned(CurrentPlayer) and Confirmation and
    21762191      Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, True, Confirm);
    21772192  end else begin
    21782193    CountOnce := Power;
    21792194    CountRepeat := 0;
    2180     if Assigned(CurrentPlayer) and (CurrentPlayer.Mode = pmHuman) and
     2195    if Assigned(CurrentPlayer) and Confirmation and
    21812196      Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, False, Confirm);
    21822197  end;
     
    21992214        NewMove.CountOnce := CountOnce;
    22002215        NewMove.CountRepeat := CountRepeat;
     2216        Result := NewMove;
    22012217        CheckCounterMove(NewMove);
    22022218      end;
    22032219    end;
    2204 
    22052220  end;
    22062221end;
Note: See TracChangeset for help on using the changeset viewer.