close Warning: Can't synchronize with repository "(default)" (No changeset 184 in the repository). Look in the Trac log for more information.

Changeset 82


Ignore:
Timestamp:
Nov 5, 2014, 9:51:30 AM (10 years ago)
Author:
chronos
Message:
  • Added: New game option "Fog of war" which cause map to be covered to black and only explored cells will be visible.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r79 r82  
    128128begin
    129129  DrawStart := Now;
    130   if Assigned(Core.Game.CurrentPlayer) then
    131   with Core.Game.CurrentPlayer do begin
     130  if Assigned(Core.Player) then
     131  with Core.Player do begin
    132132    View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height);
    133133    if csOpaque in PaintBox1.ControlStyle then begin
     
    151151procedure TFormMain.PaintBox1Resize(Sender: TObject);
    152152begin
    153   if Assigned(Core.Game.CurrentPlayer) then
    154   with Core.Game.CurrentPlayer do
     153  if Assigned(Core.Player) then
     154  with Core.Player do
    155155    View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height);
    156156  Redraw;
     
    240240  MapRect: TRect;
    241241begin
    242   with Core.Game, CurrentPlayer, View do begin
     242  with Core, Game, Player, View do begin
    243243    MapRect := Map.GetPixelRect;
    244244    Factor := FloatPoint((DestRect.Right - DestRect.Left) / (MapRect.Right - MapRect.Left),
     
    271271procedure TFormMain.AZoomInExecute(Sender: TObject);
    272272begin
    273   with Core.Game.CurrentPlayer do begin
     273  with Core.Player do begin
    274274    View.Zoom := View.Zoom * ZoomFactor;
    275275  end;
     
    281281  D: TPoint;
    282282begin
    283   with Core.Game.CurrentPlayer do begin
     283  with Core.Player do begin
    284284    //D := Point(Trunc(MousePos.X - View.Left / ViewZoom),
    285285    //  Trunc(MousePos.Y - View.Top / ViewZoom));
  • trunk/Forms/UFormNew.lfm

    r75 r82  
    4545    Top = 5
    4646    Width = 745
    47     ActivePage = TabSheet1
     47    ActivePage = TabSheet3
    4848    Align = alTop
    4949    Anchors = [akTop, akLeft, akRight, akBottom]
    50     TabIndex = 0
     50    TabIndex = 2
    5151    TabOrder = 3
    5252    object TabSheet1: TTabSheet
     
    407407        TabOrder = 2
    408408      end
     409      object CheckBoxFogOfWar: TCheckBox
     410        Left = 336
     411        Height = 27
     412        Top = 24
     413        Width = 120
     414        Caption = 'Fog of war'
     415        TabOrder = 3
     416      end
    409417    end
    410418  end
  • trunk/Forms/UFormNew.lrt

    r75 r82  
    2525TFORMNEW.LABEL6.CAPTION=Win objective:
    2626TFORMNEW.RADIOGROUPGROWAMOUNT.CAPTION=Per turn grow amount
     27TFORMNEW.CHECKBOXFOGOFWAR.CAPTION=Fog of war
    2728TFORMNEW.APLAYERMODIFY.CAPTION=Modify player
    2829TFORMNEW.APLAYERADD.CAPTION=Add
  • trunk/Forms/UFormNew.pas

    r76 r82  
    2424    ButtonPlayerModify: TButton;
    2525    ButtonPlayerRemove: TButton;
     26    CheckBoxFogOfWar: TCheckBox;
    2627    CheckBoxCity: TCheckBox;
    2728    CheckBoxSymetricMap: TCheckBox;
     
    351352  ComboBoxMapShape.ItemIndex := Integer(Game.Map.Shape);
    352353  EditImageFile.Text := Game.MapImageFileName;
     354  CheckBoxFogOfWar.Checked := Game.FogOfWar;
    353355end;
    354356
     
    379381  Game.Map.Shape := TMapShape(ComboBoxMapShape.ItemIndex);
    380382  Game.MapImageFileName := EditImageFile.Text;
     383  Game.FogOfWar := CheckBoxFogOfWar.Checked;
    381384end;
    382385
  • trunk/Languages/xtactics.cs.po

    r77 r82  
    236236msgstr "Města"
    237237
     238#: tformnew.checkboxfogofwar.caption
     239msgid "Fog of war"
     240msgstr ""
     241
    238242#: tformnew.checkboxsymetricmap.caption
    239243msgid "Symetric map"
  • trunk/Languages/xtactics.po

    r77 r82  
    224224msgstr ""
    225225
     226#: tformnew.checkboxfogofwar.caption
     227msgid "Fog of war"
     228msgstr ""
     229
    226230#: tformnew.checkboxsymetricmap.caption
    227231msgid "Symetric map"
  • trunk/UCore.pas

    r80 r82  
    5656  public
    5757    Game: TGame;
     58    Player: TPlayer;
    5859    UseSingleView: Boolean;
    5960    DevelMode: Boolean;
     
    238239    FormNew.Save(Game);
    239240    Game.New;
     241    Player := Game.Players.GetFirstHuman;
    240242    Game.Running := True;
    241243    FormMain.AZoomAll.Execute;
     
    308310  Game.LoadConfig(XMLConfig1, 'Game');
    309311  Game.New;
     312  Player := Game.Players.GetFirstHuman;
    310313  Game.Running := True;
    311314  FormMain.AZoomAll.Execute;
  • trunk/UGame.pas

    r81 r82  
    218218  TPlayerMap = class
    219219    Cells: TPlayerCells;
     220    Player: TPlayer;
     221    procedure Update;
    220222    constructor Create;
    221223    destructor Destroy; override;
     224    procedure CheckVisibility;
     225    procedure Paint(Canvas: TCanvas; View: TView);
    222226  end;
    223227
     
    278282    procedure SaveToNode(Node: TDOMNode);
    279283    constructor Create;
     284    function GetFirstHuman: TPlayer;
    280285  end;
    281286
     
    354359    MaxNeutralUnits: Integer;
    355360    FileName: string;
     361    FogOfWar: Boolean;
    356362    function AttackProbability(AttackCount, DefendCount, Depth: Integer): Double;
    357363    procedure LoadConfig(Config: TXmlConfig; Path: string);
     
    465471end;
    466472
     473function HalfColor(Color: TColor): TColor;
     474begin
     475  Result :=
     476    ((((Color shr 0) and $ff) shr 1) shl 0) or
     477    ((((Color shr 8) and $ff) shr 1) shl 8) or
     478    ((((Color shr 16) and $ff) shr 1) shl 16) or
     479    ((((Color shr 24) and $ff) shr 0) shl 24);
     480end;
     481
    467482{ TPlayerMap }
     483
     484procedure TPlayerMap.Update;
     485var
     486  I: Integer;
     487  OldCount: Integer;
     488begin
     489  // Update players cells count to map cells count to be 1:1
     490  OldCount := Cells.Count;
     491  Cells.Count := Player.Game.Map.Cells.Count;
     492  for I := OldCount to Cells.Count - 1 do
     493    Cells[I] := TPlayerCell.Create;
     494
     495  for I := 0 to Cells.Count - 1 do
     496  with TPlayerCell(Cells[I]) do begin
     497    Explored := False;
     498    InVisibleRange := False;
     499    MapCell := TCell(Player.Game.Map.Cells[I]);
     500  end;
     501end;
    468502
    469503constructor TPlayerMap.Create;
     
    476510  Cells.Free;
    477511  inherited Destroy;
     512end;
     513
     514procedure TPlayerMap.CheckVisibility;
     515var
     516  I: Integer;
     517  C: Integer;
     518  NeighCount: Integer;
     519begin
     520  for I := 0 to Cells.Count - 1 do
     521  with TPlayerCell(Cells[I]) do begin
     522    NeighCount := 0;
     523    for C := 0 to MapCell.Neighbors.Count - 1 do
     524      if TCell(MapCell.Neighbors[C]).Player = Player then
     525        Inc(NeighCount);
     526
     527    InVisibleRange := (NeighCount > 0) or (TCell(MapCell).Player = Player);
     528    if InVisibleRange and not Explored then Explored := True;
     529  end;
     530end;
     531
     532procedure TPlayerMap.Paint(Canvas: TCanvas; View: TView);
     533var
     534  I: Integer;
     535  C: Integer;
     536  Cell: TPlayerCell;
     537  PosFrom, PosTo: TPoint;
     538  Angle: Double;
     539  ArrowCenter: TPoint;
     540  Move: TUnitMove;
     541  CellText: string;
     542begin
     543  with Canvas, View do
     544  try
     545    Lock;
     546    for C := 0 to Cells.Count - 1 do begin
     547      Cell := TPlayerCell(Cells[C]);
     548      if (Cell.MapCell.Terrain <> ttVoid) and Cell.MapCell.IsVisible(View) then begin
     549        CellText := IntToStr(Cell.MapCell.GetAvialPower);
     550        if Assigned(SelectedCell) and (SelectedCell = Cell.MapCell) then
     551            Brush.Color := clGreen
     552          else if Assigned(SelectedCell) and Player.Game.Map.IsCellsNeighbor(SelectedCell, Cell.MapCell) then
     553            Brush.Color := clPurple
     554          else if Player.Game.FogOfWar then begin
     555            if Cell.InVisibleRange then begin
     556              if not Cell.Explored then begin
     557                Brush.Color := HalfColor(Cell.MapCell.GetColor);
     558                CellText := '';
     559              end else Brush.Color := Cell.MapCell.GetColor
     560            end else begin
     561              Brush.Color := clBlack;
     562              CellText := '';
     563            end;
     564          end else Brush.Color := Cell.MapCell.GetColor;
     565        Player.Game.Map.PaintCell(Canvas, Cell.MapCell.PosPx, CellText, View, Cell.MapCell);
     566      end else
     567      if Game.FogOfWar and (Cell.MapCell.Terrain = ttVoid) and (not Cell.Explored) then begin
     568        Brush.Color := clBlack;
     569        Player.Game.Map.PaintCell(Canvas, Cell.MapCell.PosPx, '', View, Cell.MapCell);
     570      end;
     571    end;
     572
     573    // Draw arrows
     574    Pen.Color := clCream;
     575    for I := 0 to Game.Moves.Count - 1 do begin
     576      Move := TUnitMove(Game.Moves[I]);
     577      PosFrom := Player.Game.Map.CellToPos(Move.CellFrom);
     578      PosTo := Player.Game.Map.CellToPos(Move.CellTo);
     579      if Move.CountRepeat > 0 then Pen.Width := 2
     580        else Pen.Width := 1;
     581      Angle := ArcTan((PosTo.Y - PosFrom.Y) / (PosTo.X - PosFrom.X));
     582      if Sign(PosTo.X - PosFrom.X) = -1 then Angle := Angle + Pi;
     583      ArrowCenter := View.CellToCanvasPos(Point(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2),
     584        Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2)));
     585      Player.Game.Map.DrawArrow(Canvas, View, ArrowCenter,
     586        Angle, IntToStr(Move.CountOnce));
     587    end;
     588  finally
     589    Unlock;
     590  end;
    478591end;
    479592
     
    607720  inherited Create;
    608721  NewPlayerId := 1;
     722end;
     723
     724function TPlayers.GetFirstHuman: TPlayer;
     725var
     726  I: Integer;
     727begin
     728  I := 0;
     729  while (I < Count) and (TPlayer(Items[I]).Mode <> pmHuman) do Inc(I);
     730  if I < Count then Result := TPlayer(Items[I])
     731    else Result := nil;
    609732end;
    610733
     
    17201843procedure TPlayer.Paint(Canvas: TCanvas);
    17211844begin
    1722   Game.Map.Paint(Canvas, View);
     1845  PlayerMap.Paint(Canvas, View);
    17231846end;
    17241847
     
    17291852  StartCell := nil;
    17301853  PlayerMap := TPlayerMap.Create;
     1854  PlayerMap.Player := Self;
    17311855end;
    17321856
     
    20232147    SetValue(Path + '/MapImage', MapImageFileName);
    20242148    SetValue(Path + '/SymetricMap', SymetricMap);
     2149    SetValue(Path + '/FogOfWar', FogOfWar);
    20252150    SetValue(Path + '/VoidEnabled', VoidEnabled);
    20262151    SetValue(Path + '/VoidPercentage', VoidPercentage);
     
    20442169    MapImageFileName := GetValue(Path + '/MapImage', MapImageFileName);
    20452170    SymetricMap := GetValue(Path + '/SymetricMap', False);
     2171    FogOfWar := GetValue(Path + '/FogOfWar', False);
    20462172    VoidEnabled := GetValue(Path + '/VoidEnabled', True);
    20472173    VoidPercentage := GetValue(Path + '/VoidPercentage', 20);
     
    20732199    with RootNode do begin
    20742200      SymetricMap := ReadBoolean(RootNode, 'SymetricMap', False);
     2201      FogOfWar := ReadBoolean(RootNode, 'FogOfWar', False);
    20752202      VoidEnabled := ReadBoolean(RootNode, 'VoidEnabled', False);
    20762203      VoidPercentage := ReadInteger(RootNode, 'VoidPercentage', 0);
     
    21202247    with RootNode do begin
    21212248      WriteBoolean(RootNode, 'SymetricMap', SymetricMap);
     2249      WriteBoolean(RootNode, 'FogOfWar', FogOfWar);
    21222250      WriteBoolean(RootNode, 'VoidEnabled', VoidEnabled);
    21232251      WriteInteger(RootNode, 'VoidPercentage', VoidPercentage);
     
    21942322  Map.Grow(CurrentPlayer);
    21952323  UpdateRepeatMoves(CurrentPlayer);
     2324  CurrentPlayer.PlayerMap.CheckVisibility;
    21962325  ComputePlayerStats;
    21972326  PrevPlayer := CurrentPlayer;
     
    22072336  CheckWinObjective;
    22082337  // For computers take view from previous human
    2209   if CurrentPlayer.Mode = pmComputer then CurrentPlayer.View.Assign(PrevPlayer.View);
     2338  //if CurrentPlayer.Mode = pmComputer then CurrentPlayer.View.Assign(PrevPlayer.View);
    22102339end;
    22112340
     
    22742403var
    22752404  I: Integer;
    2276   StartCell: TCell;
    22772405  Counter: Integer;
    22782406  AllCells: TCellArray;
     
    23012429
    23022430  if SymetricMap then begin
    2303     for C := 0 to Map.Cells.Count div 2 - 1 do begin
     2431    for C := 0 to (Map.Cells.Count div 2) - 1 do begin
    23042432      TCell(Map.Cells[C]).Terrain :=
    23052433        TCell(Map.Cells[Map.Cells.Count - 1 - C]).Terrain;
     
    23112439  for I := 0 to Players.Count - 1 do
    23122440  with TPlayer(Players[I]) do begin
     2441    PlayerMap.Update;
    23132442    View.Clear;
    23142443    if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin
     
    23322461    View.Zoom := 1;
    23332462    View.CenterMap;
     2463    PlayerMap.CheckVisibility;
    23342464  end;
    23352465  if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])
Note: See TracChangeset for help on using the changeset viewer.