Changeset 90


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.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r87 r90  
    1111const
    1212  ZoomFactor = 1.5;
    13   MouseMinDiff = 6;
     13  MouseMinDiff = 0.1;
    1414
    1515type
     
    359359  if Assigned(Core.Game.CurrentPlayer) then begin
    360360    if MoveActive then
    361     if (Abs(StartMousePoint.X - X) > MouseMinDiff) or (Abs(StartMousePoint.Y - Y) > MouseMinDiff) then
     361    if (Abs(StartMousePoint.X - X) > Trunc(Screen.PixelsPerInch * MouseMinDiff)) or
     362    (Abs(StartMousePoint.Y - Y) > Trunc(Screen.PixelsPerInch * MouseMinDiff)) then
    362363    with Core.Game.CurrentPlayer do begin
    363364      if Mode = pmHuman then begin
     
    390391  Shift: TShiftState; X, Y: Integer);
    391392begin
    392   if (Abs(StartMousePoint.X - X) < MouseMinDiff) and (Abs(StartMousePoint.Y - Y) < MouseMinDiff) then begin
     393  if (Abs(StartMousePoint.X - X) < Trunc(Screen.PixelsPerInch * MouseMinDiff)) and
     394  (Abs(StartMousePoint.Y - Y) < Trunc(Screen.PixelsPerInch * MouseMinDiff)) then begin
    393395    if Core.Game.Running and (Core.Game.CurrentPlayer.Mode = pmHuman) then begin
    394396      Core.Game.CurrentPlayer.View.SelectCell(Point(X, Y), Core.Game.CurrentPlayer, Shift);
  • trunk/Forms/UFormNew.pas

    r82 r90  
    311311    NewPlayer.Color := PlayerColors[Players.Count];
    312312    NewPlayer.Mode := pmComputer;
     313    NewPlayer.Agressivity := caMedium;
    313314    Players.Add(NewPlayer);
    314315    ReloadView;
  • trunk/Forms/UFormPlayer.lfm

    r29 r90  
    11object FormPlayer: TFormPlayer
    22  Left = 470
    3   Height = 303
     3  Height = 347
    44  Top = 219
    55  Width = 551
    66  Caption = 'Player'
    7   ClientHeight = 303
     7  ClientHeight = 347
    88  ClientWidth = 551
    99  LCLVersion = '1.3'
     
    2626    Left = 307
    2727    Height = 25
    28     Top = 252
     28    Top = 296
    2929    Width = 75
    3030    Anchors = [akRight, akBottom]
     
    3636    Left = 428
    3737    Height = 25
    38     Top = 252
     38    Top = 296
    3939    Width = 75
    4040    Anchors = [akRight, akBottom]
     
    8383    TabOrder = 4
    8484  end
     85  object Label4: TLabel
     86    Left = 24
     87    Height = 22
     88    Top = 168
     89    Width = 92
     90    Caption = 'Agressivity:'
     91    ParentColor = False
     92  end
     93  object ComboBoxAgressivity: TComboBox
     94    Left = 139
     95    Height = 30
     96    Top = 168
     97    Width = 368
     98    ItemHeight = 0
     99    Items.Strings = (
     100      'Low'
     101      'Medium'
     102      'High'
     103      ''
     104    )
     105    Style = csDropDownList
     106    TabOrder = 5
     107  end
     108  object CheckBoxDefensive: TCheckBox
     109    Left = 24
     110    Height = 24
     111    Top = 208
     112    Width = 103
     113    Caption = 'Defensive'
     114    TabOrder = 6
     115  end
    85116end
  • trunk/Forms/UFormPlayer.lrt

    r29 r90  
    66TFORMPLAYER.LABEL2.CAPTION=Mode:
    77TFORMPLAYER.LABEL3.CAPTION=Color:
     8TFORMPLAYER.LABEL4.CAPTION=Agressivity:
     9TFORMPLAYER.CHECKBOXDEFENSIVE.CAPTION=Defensive
  • trunk/Forms/UFormPlayer.pas

    r55 r90  
    1616    ButtonCancel: TButton;
    1717    ButtonOk: TButton;
     18    CheckBoxDefensive: TCheckBox;
    1819    ColorBox1: TColorBox;
    1920    ComboBox1: TComboBox;
     21    ComboBoxAgressivity: TComboBox;
    2022    EditName: TEdit;
    2123    Label1: TLabel;
    2224    Label2: TLabel;
    2325    Label3: TLabel;
     26    Label4: TLabel;
    2427  private
    2528    { private declarations }
     
    4043  SHuman = 'Human';
    4144  SComputer = 'Computer';
     45  SAgroNotAttacking = 'Not attacking';
     46  SAgroLow = 'Low';
     47  SAgroMedium = 'Medium';
     48  SAgroHigh = 'High';
    4249
    4350{ TFormPlayer }
     
    5461    ItemIndex := LastIndex;
    5562  end;
     63  with ComboBoxAgressivity do begin
     64    LastIndex := ItemIndex;
     65    Clear;
     66    Items.Add(SAgroLow);
     67    Items.Add(SAgroMedium);
     68    Items.Add(SAgroHigh);
     69    ItemIndex := LastIndex;
     70  end;
    5671end;
    5772
     
    6176  ComboBox1.ItemIndex := Integer(Player.Mode);
    6277  ColorBox1.Selected := Player.Color;
     78  Label4.Visible := Player.Mode = pmComputer;
     79  ComboBoxAgressivity.Visible := Player.Mode = pmComputer;
     80  ComboBoxAgressivity.ItemIndex := Integer(Player.Agressivity);
     81  CheckBoxDefensive.Visible := Player.Mode = pmComputer;
     82  CheckBoxDefensive.Checked := Player.Defensive;
    6383end;
    6484
     
    6888  Player.Mode := TPlayerMode(ComboBox1.ItemIndex);
    6989  Player.Color := ColorBox1.Selected;
     90  Player.Agressivity := TComputerAgressivity(ComboBoxAgressivity.ItemIndex);
     91  Player.Defensive := CheckBoxDefensive.Checked;
    7092end;
    7193
  • trunk/Languages/xtactics.cs.po

    r82 r90  
    238238#: tformnew.checkboxfogofwar.caption
    239239msgid "Fog of war"
    240 msgstr ""
     240msgstr "Skrytá mapa"
    241241
    242242#: tformnew.checkboxsymetricmap.caption
     
    339339msgstr "Hráč"
    340340
     341#: tformplayer.checkboxdefensive.caption
     342msgid "Defensive"
     343msgstr "Obranný"
     344
    341345#: tformplayer.combobox1.text
    342346msgctxt "tformplayer.combobox1.text"
     
    356360msgstr "Barva:"
    357361
     362#: tformplayer.label4.caption
     363msgid "Agressivity:"
     364msgstr "Agresivita:"
     365
    358366#: tformsettings.buttoncancel.caption
    359367msgctxt "tformsettings.buttoncancel.caption"
     
    373381#: tformsettings.checkbox1.caption
    374382msgid "Autosave game on each turn"
    375 msgstr ""
     383msgstr "Automaticky uložit hru po každém tahu"
    376384
    377385#: tformsettings.checkboxdevelmode.caption
     
    501509msgstr "Zůstat naživu určený počet tahů"
    502510
     511#: uformplayer.sagrohigh
     512msgid "High"
     513msgstr "Vysoká"
     514
     515#: uformplayer.sagrolow
     516msgid "Low"
     517msgstr "Nízká"
     518
     519#: uformplayer.sagromedium
     520msgid "Medium"
     521msgstr "Střední"
     522
     523#: uformplayer.sagronotattacking
     524msgid "Not attacking"
     525msgstr ""
     526
    503527#: uformplayer.scomputer
    504528msgctxt "uformplayer.scomputer"
     
    545569msgid "Wrong file format"
    546570msgstr "Chybný formát souboru"
    547 
  • trunk/Languages/xtactics.po

    r82 r90  
    325325msgstr ""
    326326
     327#: tformplayer.checkboxdefensive.caption
     328msgid "Defensive"
     329msgstr ""
     330
    327331#: tformplayer.combobox1.text
    328332msgctxt "tformplayer.combobox1.text"
     
    342346msgstr ""
    343347
     348#: tformplayer.label4.caption
     349msgid "Agressivity:"
     350msgstr ""
     351
    344352#: tformsettings.buttoncancel.caption
    345353msgctxt "TFORMSETTINGS.BUTTONCANCEL.CAPTION"
     
    487495msgstr ""
    488496
     497#: uformplayer.sagrohigh
     498msgid "High"
     499msgstr ""
     500
     501#: uformplayer.sagrolow
     502msgid "Low"
     503msgstr ""
     504
     505#: uformplayer.sagromedium
     506msgid "Medium"
     507msgstr ""
     508
     509#: uformplayer.sagronotattacking
     510msgid "Not attacking"
     511msgstr ""
     512
    489513#: uformplayer.scomputer
    490514msgctxt "uformplayer.scomputer"
  • 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;
  • trunk/xtactics.lpi

    r87 r90  
    111111        <HasResources Value="True"/>
    112112        <ResourceBaseClass Value="Form"/>
     113        <UnitName Value="UFormPlayer"/>
    113114      </Unit3>
    114115      <Unit4>
Note: See TracChangeset for help on using the changeset viewer.