Changeset 90 for trunk/UGame.pas


Ignore:
Timestamp:
Nov 16, 2014, 5:12:25 PM (10 years ago)
Author:
chronos
Message:
  • Added: Computer player settings to be low, medium or highly aggresive in attacking.
  • Fixed: Mouse move insensitivity zone is now DPI aware.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r89 r90  
    239239
    240240  TPlayerMode = (pmHuman, pmComputer);
     241  TComputerAgressivity = (caLow, caMedium, caHigh);
    241242
    242243  { TPlayer }
     
    258259    StartCell: TCell;
    259260    PlayerMap: TPlayerMap;
     261    Defensive: Boolean;
     262    Agressivity: TComputerAgressivity;
    260263    procedure LoadFromNode(Node: TDOMNode);
    261264    procedure SaveToNode(Node: TDOMNode);
     
    404407  PlayerColors: array[0..7] of TColor = (clBlue, clRed, clGreen, clOrange,
    405408    clPurple, clMaroon, clAqua, clFuchsia);
     409  ComputerAggroProbability: array[TComputerAgressivity] of Single = (0.9, 0.7, 0.5);
    406410
    407411procedure InitStrings;
     
    787791  NewPlayer.Mode := Mode;
    788792  NewPlayer.Id := GetNewPlayerId;
     793  if Mode = pmComputer then
     794    NewPlayer.Agressivity := caMedium;
    789795  Add(NewPlayer);
    790796end;
     
    16711677  StartCell := FGame.Map.Cells.FindById(ReadInteger(Node, 'StartCell', 0));
    16721678  StartUnits := ReadInteger(Node, 'StartUnits', 0);
     1679  Agressivity := TComputerAgressivity(ReadInteger(Node, 'Agressivity', Integer(caMedium)));
     1680  Defensive := ReadBoolean(Node, 'Defensive', False);
    16731681
    16741682  with Node do begin
     
    16891697  WriteInteger(Node, 'StartCell', StartCell.Id);
    16901698  WriteInteger(Node, 'StartUnits', StartUnits);
     1699  WriteInteger(Node, 'Agressivity', Integer(Agressivity));
     1700  WriteBoolean(Node, 'Defensive', Defensive);
    16911701
    16921702  with Node do begin
     
    17871797  AttackDiff = 2;
    17881798begin
     1799  if Game.CurrentPlayer.Defensive then Exit;
     1800
    17891801  AllCells := Game.Map.Cells;
    17901802  TargetCells := TCells.Create;
     
    18181830      end;
    18191831      // Attack if target is weaker
    1820       if TotalPower >= (Power + AttackDiff) then begin
     1832      if Game.AttackProbability(TotalPower, Power) >= ComputerAggroProbability[Game.CurrentPlayer.Agressivity] then begin
     1833        // Try to limit total attacking power to necessary minimum
     1834        while Game.AttackProbability(TotalPower - 1, Power) >= ComputerAggroProbability[Game.CurrentPlayer.Agressivity] do
     1835          Dec(TotalPower);
     1836
     1837        // Collect required attack units from our cells
    18211838        TotalAttackPower := 0;
    18221839        for I := 0 to Neighbors.Count - 1 do
    18231840        if (TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin
    18241841          // Use only necessary power
    1825           AttackPower := Power - TotalAttackPower + AttackDiff;
     1842          AttackPower := TotalPower - TotalAttackPower;
    18261843          if TCell(Neighbors[I]).GetAvialPower < AttackPower then
    18271844            AttackPower := TCell(Neighbors[I]).GetAvialPower;
    18281845          Game.SetMove(TCell(Neighbors[I]), TCell(TargetCells[C]), AttackPower, False);
    18291846          TotalAttackPower := TotalAttackPower + AttackPower;
     1847          if TotalAttackPower >= TotalPower then Break;
    18301848        end;
    18311849      end;
     
    20842102  StartUnits := Source.StartUnits;
    20852103  StartCell := Source.StartCell;
     2104  Agressivity := Source.Agressivity;
     2105  Defensive := Source.Defensive;
    20862106  View.Assign(Source.View);
    20872107end;
Note: See TracChangeset for help on using the changeset viewer.