Changeset 248 for trunk


Ignore:
Timestamp:
Sep 22, 2018, 2:35:46 PM (6 years ago)
Author:
chronos
Message:
  • Fixed: Drawing Voronoi type map in cyclic mode.
  • Fixed: Clear player cells before map cells regeneration.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormClient.pas

    r246 r248  
    1212const
    1313  ZoomFactor = 1.5;
    14   MinZoom = 0.05;
     14  MinZoom = 0.1;
    1515  MaxZoom = 10;
    1616  MouseMinDiff = 0.1;
  • trunk/UClientGUI.pas

    r241 r248  
    507507  end;
    508508  if Assigned(NewSelectedCell) then begin
     509    if (NewSelectedCell <> SelectedCell) and (NewSelectedCell.MapCell.Player = Player) then begin
     510      SelectedCell := NewSelectedCell
     511    end else
     512    if (NewSelectedCell = SelectedCell) and (NewSelectedCell.MapCell.Player = Player) then begin
     513      SelectedCell := nil;
     514    end else
    509515    if Assigned(SelectedCell) and TGame(Game).Map.IsCellsNeighbor(NewSelectedCell.MapCell, SelectedCell.MapCell) then begin
    510516      if ssShift in ShiftState then begin
     
    530536        SelectedCell := nil;
    531537      end;
    532     end else
    533     if (NewSelectedCell <> SelectedCell) and (NewSelectedCell.MapCell.Player = Player) then
    534       SelectedCell := NewSelectedCell
    535     else
    536     if (NewSelectedCell = SelectedCell) and (NewSelectedCell.MapCell.Player = Player) then
    537       SelectedCell := nil;
     538    end;
    538539  end;
    539540end;
  • trunk/UGeometry.pas

    r236 r248  
    9898    constructor Create(const Points: TPointArray); overload;
    9999    constructor Create(const Rect: TGRect<T>); overload;
     100    procedure Move(P: T);
    100101    function GetRect: TGRect<T>;
    101102    function EdgeDistance(Polygon: TGPolygon<T>): Double;
     
    331332end;
    332333
     334procedure TGPolygon<T>.Move(P: T);
     335var
     336  I: Integer;
     337begin
     338  for I := 0 to Length(Points) - 1 do
     339    Points[I] := Points[I] + P;
     340end;
     341
    333342{ TGLine }
    334343
  • trunk/UMap.pas

    r247 r248  
    11901190end;
    11911191
    1192 
    1193 
    11941192end.
    11951193
  • trunk/UMapType.pas

    r247 r248  
    421421  MP: TPoint;
    422422  LinkLine: TLine;
     423  P: TPolygon;
     424  AreaSize: TPoint;
    423425const
    424426  CellGapWidth = 4;
     
    441443  end;
    442444
    443   // Compute polygon by catting out map area by all other cells
    444   for Cell in Cells do begin
    445     Cell.Polygon := TPolygon.Create(TRect.Create(TPoint.Create(0, 0),
    446       TPoint.Create(Size.X * DefaultCellSize.X, Size.Y * DefaultCellSize.Y)));
    447     for Cell2 in Cells do
    448     if Cell2 <> Cell then begin
    449       LinkLine := TLine.Create(Cell.PosPx, Cell2.PosPx);
    450       LinkLine.Distance := LinkLine.Distance - CellGapWidth;
    451       MP := LinkLine.GetMiddle;
    452       // Create half plane vector
    453       L1 := TLine.Create(MP, TPoint.Create(MP.X + LinkLine.GetSize.X,
    454         MP.Y + LinkLine.GetSize.Y));
    455 
    456       Cell.Polygon.CutLine(L1, Cell.PosPx);
     445  AreaSize := TPoint.Create(Size.X * DefaultCellSize.X, Size.Y * DefaultCellSize.Y);
     446
     447  // Compute polygon by cutting out map area by all other cells
     448  if Cyclic then begin
     449    for Cell in Cells do begin
     450      Cell.Polygon := TPolygon.Create(TRect.Create(
     451        TPoint.Create(-AreaSize.X, -AreaSize.Y),
     452        TPoint.Create(2 * AreaSize.X, 2 * AreaSize.Y)));
     453      for Y := -1 to 1 do
     454      for X := -1 to 1 do
     455      for Cell2 in Cells do
     456      if Cell2 <> Cell then begin
     457        LinkLine := TLine.Create(Cell.PosPx, Cell2.PosPx +
     458          TPoint.Create(X * AreaSize.X, Y * AreaSize.Y));
     459        LinkLine.Distance := LinkLine.Distance - CellGapWidth;
     460        MP := LinkLine.GetMiddle;
     461        // Create half plane vector
     462        L1 := TLine.Create(MP, TPoint.Create(MP.X + LinkLine.GetSize.X,
     463          MP.Y + LinkLine.GetSize.Y));
     464
     465        Cell.Polygon.CutLine(L1, Cell.PosPx);
     466      end;
     467    end;
     468  end else begin
     469    for Cell in Cells do begin
     470      Cell.Polygon := TPolygon.Create(TRect.Create(TPoint.Create(0, 0),
     471        AreaSize));
     472      for Cell2 in Cells do
     473      if Cell2 <> Cell then begin
     474        LinkLine := TLine.Create(Cell.PosPx, Cell2.PosPx);
     475        LinkLine.Distance := LinkLine.Distance - CellGapWidth;
     476        MP := LinkLine.GetMiddle;
     477        // Create half plane vector
     478        L1 := TLine.Create(MP, TPoint.Create(MP.X + LinkLine.GetSize.X,
     479          MP.Y + LinkLine.GetSize.Y));
     480
     481        Cell.Polygon.CutLine(L1, Cell.PosPx);
     482      end;
    457483    end;
    458484  end;
    459485
    460486  // Link all cells with neighboring polygon edges
    461   for I := 0 to Cells.Count - 1 do begin
    462     for J := I + 1 to Cells.Count - 1 do begin
    463       if Cells[I].Polygon.EdgeDistance(Cells[J].Polygon) < 2 * CellGapWidth then
    464         Cells[I].ConnectTo(Cells[J]);
     487  if Cyclic then begin
     488    for I := 0 to Cells.Count - 1 do begin
     489      for Y := -1 to 1 do
     490      for X := -1 to 1 do
     491      for J := 0 to Cells.Count - 1 do begin
     492        P := Cells[J].Polygon;
     493        P.Move(TPoint.Create(X * AreaSize.X, Y * AreaSize.Y));
     494        if Cells[I].Polygon.EdgeDistance(P) < 2 * CellGapWidth then
     495          Cells[I].ConnectTo(Cells[J]);
     496      end;
     497    end;
     498  end else begin
     499    for I := 0 to Cells.Count - 1 do begin
     500      for J := I + 1 to Cells.Count - 1 do begin
     501        if Cells[I].Polygon.EdgeDistance(Cells[J].Polygon) < 2 * CellGapWidth then
     502          Cells[I].ConnectTo(Cells[J]);
     503      end;
    465504    end;
    466505  end;
     
    476515function TVoronoiMap.CalculatePixelRect: TRect;
    477516begin
    478   Result := inherited CalculatePixelRect;
    479   Result.P2 := Result.P2 + TPoint.Create(
    480     Trunc(0.02 * DefaultCellSize.X),
    481     Trunc(0.02 * DefaultCellSize.Y)
    482   );
     517  Result.P1 := TPoint.Create(0, 0);
     518  Result.P2 := TPoint.Create(Size.X * DefaultCellSize.X, Size.Y * DefaultCellSize.Y);
    483519end;
    484520
  • trunk/UPlayer.pas

    r235 r248  
    5555    procedure SaveToNode(Node: TDOMNode);
    5656    procedure Update;
     57    procedure Clear;
    5758    constructor Create;
    5859    destructor Destroy; override;
     
    422423end;
    423424
     425procedure TPlayerMap.Clear;
     426begin
     427  Cells.Clear;
     428end;
     429
    424430constructor TPlayerMap.Create;
    425431begin
     
    730736  TurnStats.Clear;
    731737  Moves.Clear;
     738  PlayerMap.Clear;
    732739end;
    733740
Note: See TracChangeset for help on using the changeset viewer.