Changeset 55 for trunk/UGame.pas


Ignore:
Timestamp:
Aug 18, 2014, 9:34:15 AM (10 years ago)
Author:
chronos
Message:
  • Fixed: More translation of TGroupBox and TComboBox items.
  • Fixed: Shape of hexagon was not regular due to rounding error in polygon generation and drawing. Cells are now generated internally as bigger to avoid rounding error.
  • Fixed: After game end do not allow to execute End turn and End game actions.
  • Added: Preparation for random voronoi map. So far hidden in developer mode as algorithm is missing.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r54 r55  
    9292    procedure PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView;
    9393      Cell: TCell);
     94    procedure DrawArrow(Canvas: TCanvas; View: TView; Pos: TPoint; Angle: Double;
     95      Text: string);
    9496    procedure SetSize(AValue: TPoint); virtual;
    9597  public
     
    98100    DefaultCellSize: TPoint;
    99101    Cells: TObjectList; // TList<TCell>
    100     procedure DrawArrow(Canvas: TCanvas; View: TView; Pos: TPoint; Angle: Double;
    101       Text: string);
    102102    function IsCellsNeighbor(Cell1, Cell2: TCell): Boolean; virtual;
    103103    function IsValidIndex(Index: TPoint): Boolean; virtual;
     
    151151  public
    152152    function IsValidIndex(Index: TPoint): Boolean; override;
     153    procedure Generate; override;
     154  end;
     155
     156  { TVoronoiMap }
     157
     158  TVoronoiMap = class(TMap)
     159  private
     160    function GetTrianglePolygon(Pos: TPoint; Size: TPoint; Reverse: Boolean): TPointArray;
     161  public
    153162    procedure Generate; override;
    154163  end;
     
    210219  TGrowAmount = (gaByOne, gaBySquareRoot);
    211220  TGrowCells = (gcNone, gcPlayerCities, gcPlayerAll);
    212   TMapType = (mtNone, mtHexagon, mtSquare, mtTriangle);
     221  TMapType = (mtNone, mtHexagon, mtSquare, mtTriangle, mtVoronoi);
    213222  TWinObjective = (woDefeatAllOponents, woDefeatAllOponentsCities,
    214223    woSpecialCaptureCell, woStayAliveForDefinedTurns);
     
    345354end;
    346355
     356{ TVoronoiMap }
     357
     358function TVoronoiMap.GetTrianglePolygon(Pos: TPoint; Size: TPoint;
     359  Reverse: Boolean): TPointArray;
     360begin
     361
     362end;
     363
     364procedure TVoronoiMap.Generate;
     365var
     366  X, Y: Integer;
     367  I, J, PI: Integer;
     368  V, VN: Integer;
     369  NewCell: TCell;
     370  Pos: TPoint;
     371begin
     372  inherited;
     373  // Free previous
     374  Cells.Count := 0;
     375  // Allocate and init new
     376  Cells.Count := FSize.Y * FSize.X;
     377  for Y := 0 to FSize.Y - 1 do
     378  for X := 0 to FSize.X - 1 do begin
     379    NewCell := TCell.Create;
     380    NewCell.PosPx := Point(Trunc(Random * FSize.X * DefaultCellSize.X), Trunc(Random * FSize.Y * DefaultCellSize.Y));
     381    SetLength(NewCell.Polygon, 1);
     382    NewCell.Polygon[0] := NewCell.PosPx;
     383    Cells[Y * FSize.X + X] := NewCell;
     384  end;
     385end;
     386
    347387{ TTriangleMap }
    348388
     
    503543    Brush.Style := bsClear;
    504544    Font.Color := clBlack;
    505     Font.Size := Trunc(4 * View.Zoom);
     545    Font.Size := Trunc(16 * View.Zoom);
    506546    TextOut(Pos.X - TextWidth(Text) div 2,
    507547      Pos.Y - TextHeight(Text) div 2, Text);
     
    624664    Pen.Style := psSolid;
    625665    Font.Color := clWhite;
    626     Font.Size := Trunc(12 * View.Zoom);
     666    Font.Size := Trunc(42 * View.Zoom);
    627667    TextPos := View.CellToCanvasPos(Pos);
    628668    TextOut(Round(TextPos.X) - TextWidth(Text) div 2, Round(TextPos.Y) - TextHeight(Text) div 2, Text);
     
    668708begin
    669709  MaxPower := 99;
    670   DefaultCellSize := Point(62, 62);
     710  DefaultCellSize := Point(220, 220);
    671711  Cells := TObjectList.create;
    672712  Size := Point(0, 0);
     
    11281168    mtSquare: Map := TSquareMap.Create;
    11291169    mtTriangle: Map := TTriangleMap.Create;
     1170    mtVoronoi: Map := TVoronoiMap.Create;
    11301171    else Map := TMap.Create;
    11311172  end;
     
    14321473  Shift := FloatPoint(0.5 * cos(30 / 180 * Pi), 0.5 * sin(30 / 180 * Pi));
    14331474  SetLength(Result, 6);
    1434   Result[0] := Point(Round(Pos.X + 0 * Size.X), Round(Pos.Y - 0.5 * Size.Y));
    1435   Result[1] := Point(Round(Pos.X + Shift.X * Size.X), Round(Pos.Y - Shift.Y * Size.Y));
    1436   Result[2] := Point(Round(Pos.X + Shift.X * Size.X), Round(Pos.Y + Shift.Y * Size.Y));
    1437   Result[3] := Point(Round(Pos.X + 0 * Size.X), Round(Pos.Y + 0.5 * Size.Y));
    1438   Result[4] := Point(Round(Pos.X - Shift.X * Size.X), Round(Pos.Y + Shift.Y * Size.Y));
    1439   Result[5] := Point(Round(Pos.X - Shift.X * Size.X), Round(Pos.Y - Shift.Y * Size.Y));
     1475  Result[0] := Point(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y - 0.5 * Size.Y));
     1476  Result[1] := Point(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y));
     1477  Result[2] := Point(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y));
     1478  Result[3] := Point(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y + 0.5 * Size.Y));
     1479  Result[4] := Point(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y));
     1480  Result[5] := Point(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y));
    14401481end;
    14411482
Note: See TracChangeset for help on using the changeset viewer.