Changeset 27


Ignore:
Timestamp:
Mar 3, 2014, 1:24:06 AM (11 years ago)
Author:
chronos
Message:
  • Modified: Computer strategy can now attack to weaker neighbour from multiple own cells.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UFormMove.lfm

    r26 r27  
    6666    Width = 296
    6767    OnChange = TrackBarOnceChange
     68    PageSize = 1
    6869    Position = 0
    6970    TickStyle = tsNone
     
    7778    Width = 304
    7879    OnChange = TrackBarRepeatChange
     80    PageSize = 1
    7981    Position = 0
    8082    TickStyle = tsNone
  • trunk/UGame.pas

    r26 r27  
    141141    FRunning: Boolean;
    142142    procedure MoveAll(Player: TPlayer);
    143     procedure SetMove(CellFrom, CellTo: TCell);
     143    procedure SetMove(CellFrom, CellTo: TCell; Power: Integer);
    144144    procedure SetRunning(AValue: Boolean);
    145145  public
     
    316316  Cells: TCellArray;
    317317  X, Y: Integer;
    318   Target: TCell;
    319   MinPower: Integer;
     318  TotalPower: Integer;
     319  AttackPower: Integer;
     320  TotalAttackPower: Integer;
    320321  I: Integer;
    321322begin
     
    323324  for X := 0 to Game.Map.Size.Y - 1 do
    324325  with TCell(Game.Map.Cells[Y, X]) do begin
    325     if Player = Self then begin
    326       // Search not own neighbour with lowes power
     326    if (Terrain <> ttVoid) and (Player <> Self) then begin
     327      // Count own possible power
    327328      Cells := Game.Map.GetCellNeighbours(Game.Map.Cells[Y, X]);
    328       Target := nil;
     329      TotalPower := 0;
    329330      for I := 0 to Length(Cells) - 1 do
    330       if (Cells[I].Terrain <> ttVoid) and (Cells[I].Player <> Self) then begin
    331         if Target = nil then begin
    332           MinPower := Cells[I].Power;
    333           Target := Cells[I];
    334         end else if Cells[I].Power < MinPower then begin
    335           MinPower := Cells[I].Power;
    336           Target := Cells[I];
     331      if (Cells[I].Player = Self) then begin
     332        TotalPower := TotalPower + Cells[I].GetAvialPower;
     333      end;
     334      // Attack if target is weaker
     335      if TotalPower > Power then begin
     336        TotalAttackPower := 0;
     337        for I := 0 to Length(Cells) - 1 do
     338        if (Cells[I].Player = Self) then begin
     339          // Use only necessary power
     340          AttackPower := Power - TotalAttackPower + 1;
     341          if Cells[I].Power < AttackPower then
     342            AttackPower := Cells[I].Power;
     343          Game.SetMove(Cells[I], Game.Map.Cells[Y, X], AttackPower);
     344          TotalAttackPower := TotalAttackPower + AttackPower;
    337345        end;
    338346      end;
    339       // Attack if target is weaker
    340       if Assigned(Target) and (Target.Power < Power) then
    341         Game.SetMove(Game.Map.Cells[Y, X], Target);
    342347    end;
    343348  end;
     
    353358  if Assigned(NewSelectedCell) then begin
    354359    if Assigned(SelectedCell) and IsCellsNeighbor(NewSelectedCell, SelectedCell) then begin
    355       Game.SetMove(SelectedCell, NewSelectedCell);
     360      Game.SetMove(SelectedCell, NewSelectedCell, SelectedCell.Power);
    356361      SelectedCell := nil;
    357362    end else
     
    433438end;
    434439
    435 procedure TGame.SetMove(CellFrom, CellTo: TCell);
     440procedure TGame.SetMove(CellFrom, CellTo: TCell; Power: Integer);
    436441var
    437442  NewMove: TMove;
     
    449454      Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, True);
    450455  end else begin
    451     CountOnce := CellFrom.Power;
     456    CountOnce := Power;
    452457    CountRepeat := 0;
    453458    if Assigned(CurrentPlayer) and (CurrentPlayer.Mode = pmHuman) and
Note: See TracChangeset for help on using the changeset viewer.