Changeset 32


Ignore:
Timestamp:
Mar 4, 2014, 11:40:01 PM (11 years ago)
Author:
chronos
Message:
  • Fixed: Do not update player move settings if not comfirmed by hitting Ok button.
  • Modified: Automatic pairing player moves objects with CellFrom and CellTo.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        44xtactics.res
        55xtactics.dbg
         6heaptrclog.trc
  • trunk/UCore.pas

    r30 r32  
    3030    FInitialized: Boolean;
    3131    procedure DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
    32       CountRepeat: Integer; Update: Boolean);
     32      CountRepeat: Integer; Update: Boolean; var Confirm: Boolean);
    3333    procedure DoOnWin(Player: TPlayer);
    3434  public
     
    5858
    5959procedure TCore.DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
    60   CountRepeat: Integer; Update: Boolean);
     60  CountRepeat: Integer; Update: Boolean; var Confirm: Boolean);
    6161begin
    6262  if Update then FormMove.SpinEditOnce.MaxValue := CellFrom.GetAvialPower + CountOnce
     
    7272    CountOnce := FormMove.SpinEditOnce.Value;
    7373    CountRepeat := FormMove.SpinEditRepeat.Value;
    74   end;
     74    Confirm := True;
     75  end else Confirm := False;
    7576end;
    7677
  • trunk/UFormMain.pas

    r30 r32  
    187187    if Assigned(Cell) then begin
    188188      Core.Game.CurrentPlayer.View.FocusedCell := Cell;
    189       StatusBar1.Panels[0].Text := '[' + IntToStr(Cell.Pos.X) + ', ' + IntToStr(Cell.Pos.Y) + ']';
     189      StatusBar1.Panels[0].Text := '[' + IntToStr(Cell.Pos.X) + ', ' + IntToStr(Cell.Pos.Y) + '] (' + IntToStr(Cell.MovesFrom.Count) + ', ' + IntToStr(Cell.MovesTo.Count) + ')';
    190190    end else begin
    191191      Core.Game.CurrentPlayer.View.FocusedCell := nil;
  • trunk/UGame.pas

    r31 r32  
    9595    destructor Destroy; override;
    9696    procedure Grow(APlayer: TPlayer);
    97     procedure ClearCellMoves;
    9897    procedure ComputePlayerStats;
    9998    function GetPixelSize: TPoint;
     
    132131  end;
    133132
     133  { TMove }
     134
    134135  TMove = class
    135     CellFrom: TCell;
    136     CellTo: TCell;
     136  private
     137    FCellFrom: TCell;
     138    FCellTo: TCell;
     139    procedure SetCellFrom(AValue: TCell);
     140    procedure SetCellTo(AValue: TCell);
     141  public
     142    List: TObjectList; // TList<TMove>
    137143    CountOnce: Integer;
    138144    CountRepeat: Integer;
     145    constructor Create;
     146    destructor Destroy; override;
     147    property CellFrom: TCell read FCellFrom write SetCellFrom;
     148    property CellTo: TCell read FCellTo write SetCellTo;
    139149  end;
    140150
     
    142152
    143153  TMoveEvent = procedure(CellFrom, CellTo: TCell; var CountOnce, CountRepeat: Integer;
    144     Update: Boolean) of object;
     154    Update: Boolean; var Confirm: Boolean) of object;
    145155  TWinEvent = procedure(Player: TPlayer) of object;
    146156
     
    179189  PlayerModeText: array[TPlayerMode] of string = ('Human', 'Computer');
    180190  clOrange = $009Aff;
    181   PlayerColors: array[0..7] of TColor = (clBlue, clRed, clGreen, clOrange, clPurple, clMaroon, clAqua, clFuchsia);
     191  PlayerColors: array[0..7] of TColor = (clBlue, clRed, clGreen, clOrange,
     192    clPurple, clMaroon, clAqua, clFuchsia);
    182193
    183194
     
    239250end;
    240251
     252{ TMove }
     253
     254procedure TMove.SetCellFrom(AValue: TCell);
     255begin
     256  if FCellFrom = AValue then Exit;
     257  if Assigned(AValue) and not Assigned(FCellFrom) then begin
     258    AValue.MovesFrom.Add(Self);
     259  end else
     260  if not Assigned(AValue) and Assigned(FCellFrom) then begin
     261    FCellFrom.MovesFrom.Remove(Self);
     262  end;
     263  FCellFrom := AValue;
     264end;
     265
     266procedure TMove.SetCellTo(AValue: TCell);
     267begin
     268  if FCellTo = AValue then Exit;
     269  if Assigned(AValue) and not Assigned(FCellTo) then begin
     270    AValue.MovesTo.Add(Self);
     271  end else
     272  if not Assigned(AValue) and Assigned(FCellTo) then begin
     273    FCellTo.MovesTo.Remove(Self);
     274  end;
     275  FCellTo := AValue;
     276end;
     277
     278constructor TMove.Create;
     279begin
     280  FCellFrom := nil;
     281  FCellTo := nil;
     282end;
     283
     284destructor TMove.Destroy;
     285begin
     286  CellFrom := nil;
     287  CellTo := nil;
     288  if Assigned(List) then
     289    List.Remove(Self);
     290  inherited Destroy;
     291end;
     292
    241293{ TView }
    242294
     
    303355
    304356destructor TCell.Destroy;
    305 begin
     357var
     358  I: Integer;
     359begin
     360  for I := MovesFrom.Count - 1 downto 0 do
     361    TMove(MovesFrom[I]).Free;
    306362  FreeAndNil(MovesFrom);
     363  for I := MovesTo.Count - 1 downto 0 do
     364    TMove(MovesTo[I]).Free;
    307365  FreeAndNil(MovesTo);
    308366  inherited Destroy;
     
    464522  I: Integer;
    465523begin
    466   for I := 0 to Moves.Count - 1 do
     524  I := 0;
     525  while I < Moves.Count do
    467526  with TMove(Moves[I]) do begin
    468527    if CellFrom.Player = Player then begin
     
    486545      CountOnce := 0;
    487546    end;
     547    Inc(I);
    488548  end;
    489549  // Remove empty moves
    490550  for I := Moves.Count - 1 downto 0 do
    491551  if (TMove(Moves[I]).CellFrom.Player = Player) and
    492     (TMove(Moves[I]).CountOnce = 0) and (TMove(Moves[I]).CountRepeat = 0) then begin
    493     TMove(Moves[I]).CellFrom.MovesFrom.Remove(TMove(Moves[I]));
    494     TMove(Moves[I]).CellTo.MovesTo.Remove(TMove(Moves[I]));
     552    (TMove(Moves[I]).CountOnce = 0) and (TMove(Moves[I]).CountRepeat = 0) then
    495553    Moves.Delete(I);
    496   end;
    497554end;
    498555
     
    501558  I: Integer;
    502559begin
    503   for I := Moves.Count - 1 to 0 do
     560  for I := Moves.Count - 1 downto 0 do
    504561  if TMove(Moves[I]).CellFrom = Cell then
    505562    Moves.Delete(I);
     
    509566var
    510567  NewMove: TMove;
     568  OldMove: TMove;
    511569  I: Integer;
    512570  CountOnce: Integer;
    513571  CountRepeat: Integer;
     572  Confirm: Boolean;
    514573begin
    515574  I := 0;
    516575  while (I < Moves.Count) and ((TMove(Moves[I]).CellFrom <> CellFrom) or
    517576    (TMove(Moves[I]).CellTo <> CellTo)) do Inc(I);
    518   if I < Moves.Count then begin
    519     CountOnce := TMove(Moves[I]).CountOnce;
    520     CountRepeat := TMove(Moves[I]).CountRepeat;
     577  if I < Moves.Count then OldMove := TMove(Moves[I])
     578    else OldMove := nil;
     579  if Assigned(OldMove) then begin
     580    CountOnce := OldMove.CountOnce;
     581    CountRepeat := OldMove.CountRepeat;
    521582    if Assigned(CurrentPlayer) and (CurrentPlayer.Mode = pmHuman) and
    522       Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, True);
     583      Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, True, Confirm);
    523584  end else begin
    524585    CountOnce := Power;
    525586    CountRepeat := 0;
    526587    if Assigned(CurrentPlayer) and (CurrentPlayer.Mode = pmHuman) and
    527       Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, False);
    528   end;
    529   if I < Moves.Count then begin
     588      Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, False, Confirm);
     589  end;
     590  if Confirm then begin
     591  if Assigned(OldMove) then begin
    530592    // Already have such move
    531593    if (CountOnce = 0) and (CountRepeat = 0) then Moves.Delete(I)
     
    538600    if (CountOnce > 0) or (CountRepeat > 0) then begin
    539601      NewMove := TMove(Moves[Moves.Add(TMove.Create)]);
     602      NewMove.List := Moves;
    540603      NewMove.CellFrom := CellFrom;
    541604      NewMove.CellTo := CellTo;
    542605      NewMove.CountOnce := CountOnce;
    543606      NewMove.CountRepeat := CountRepeat;
    544       CellFrom.MovesFrom.Add(NewMove);
    545       CellTo.MovesTo.Add(NewMove);
    546     end;
     607    end;
     608  end;
    547609  end;
    548610end;
     
    630692  Player: TPlayer;
    631693begin
     694  Moves := TObjectList.Create;
     695  Map := THexMap.Create;
     696  Players := TPlayers.Create;
     697
    632698  Randomize;
    633699
    634   Players := TPlayers.Create;
    635700  Player := TPlayer.Create;
    636701  Player.Name := 'Player 1';
     
    648713  VoidPercentage := 20;
    649714
    650   Map := THexMap.Create;
    651715  Map.Game := Self;
    652   Map.Size := Point(20, 16);
    653   Moves := TObjectList.Create;
     716  Map.Size := Point(3, 3);
    654717end;
    655718
     
    671734  TurnCounter := 1;
    672735  Moves.Clear;
    673   Map.ClearCellMoves;
    674736  for Y := 0 to Map.Size.Y - 1 do
    675737  for X := 0 to Map.Size.X - 1 do
     
    859921  with Canvas, View do try
    860922    Lock;
    861     ClearCellMoves;
    862     // Update moves in cells
    863     for I := 0 to Game.Moves.Count - 1 do
    864     with TMove(Game.Moves[I]) do begin
    865       CellFrom.MovesFrom.Add(TMove(Game.Moves[I]));
    866       CellTo.MovesTo.Add(TMove(Game.Moves[I]));
    867     end;
    868 
    869923    for CY := Trunc(SourceRect.Top / CellSize.Y) to Trunc(SourceRect.Bottom / CellSize.Y) + 1 do
    870924    for CX := Trunc(SourceRect.Left / CellSize.X) to Trunc(SourceRect.Right / CellSize.X) + 1 do begin
     
    932986end;
    933987
    934 procedure THexMap.ClearCellMoves;
    935 var
    936   X, Y: Integer;
    937 begin
    938   for Y := 0 to Size.Y - 1 do
    939   for X := 0 to Size.X - 1 do begin
    940     Cells[Y, X].MovesFrom.Clear;
    941     Cells[Y, X].MovesTo.Clear;
    942   end;
    943 end;
    944 
    945988procedure THexMap.ComputePlayerStats;
    946989var
  • trunk/xtactics.lpi

    r29 r32  
    168168        <MsgFileName Value=""/>
    169169      </CompilerMessages>
     170      <CustomOptions Value="-dDEBUG"/>
    170171      <CompilerPath Value="$(CompPath)"/>
    171172    </Other>
  • trunk/xtactics.lpr

    r29 r32  
    99  Interfaces, // this includes the LCL widgetset
    1010  Forms, UFormMain, UGame, UFormNew, UFormMove, UCore, UFormPlayer
    11   { you can add units after this };
     11  { you can add units after this },
     12  SysUtils;
    1213
    1314{$R *.res}
    1415
     16{$IFDEF DEBUG}
     17const
     18  HeapTraceLog = 'heaptrclog.trc';
     19{$ENDIF}
     20
     21
    1522begin
     23  {$IFDEF DEBUG}
     24  // Heap trace
     25  DeleteFile(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     26  SetHeapTraceOutput(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     27  {$ENDIF}
     28
    1629  RequireDerivedFormResource := True;
    1730  Application.Initialize;
Note: See TracChangeset for help on using the changeset viewer.