Changeset 258 for trunk/UMap.pas


Ignore:
Timestamp:
Sep 23, 2018, 1:43:52 PM (6 years ago)
Author:
chronos
Message:
  • Fixed: Bad cell links in Voronoi map type causing problems on openning saved file.
  • Added: More checks for loaded game file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UMap.pas

    r248 r258  
    467467end;
    468468
    469 {procedure TMap.Paint(Canvas: TCanvas; View: TView);
    470 var
    471   I: Integer;
    472   Cell: TCell;
    473   PosFrom, PosTo: TPoint;
    474   Angle: Double;
    475   ArrowCenter: TPoint;
    476   Move: TUnitMove;
    477   CellLink: TCellLink;
    478 begin
    479   with Canvas, View do
    480   try
    481     Lock;
    482 
    483     // Draw cell links
    484     Pen.Color := clBlack;
    485     Pen.Style := psSolid;
    486     Pen.Width := 3;
    487     for CellLink in CellLinks do
    488     with CellLink do begin
    489       if Length(Points) >= 2 then begin
    490         MoveTo(PointToStdPoint(View.CellToCanvasPos(Points[0])));
    491         for I := 1 to Length(Points) - 1 do
    492           LineTo(PointToStdPoint(View.CellToCanvasPos(Points[I])));
    493       end;
    494     end;
    495 
    496     // Draw cells
    497     for Cell in Cells do begin
    498       if (Cell.Terrain <> ttVoid) and Cell.IsVisible(View) then begin
    499         if Assigned(SelectedCell) and (SelectedCell.MapCell = Cell) then
    500           Brush.Color := clGreen
    501           else if Assigned(SelectedCell) and IsCellsNeighbor(SelectedCell.MapCell, Cell) then
    502             Brush.Color := clPurple
    503           else Brush.Color := Cell.GetColor;
    504         //Pen.Color := clBlack;
    505         PaintCell(Canvas, Cell.PosPx, IntToStr(Cell.Power), View, Cell);
    506       end;
    507     end;
    508   finally
    509     Unlock;
    510   end;
    511 end;
    512 }
    513 
    514469function TMap.GetNewCellId: Integer;
    515470begin
     
    647602  Result := Cell.PosPx;
    648603end;
    649 
    650 {procedure TMap.PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView;
    651   Cell: TCell);
    652 var
    653   I: Integer;
    654   TextPos: TPoint;
    655   Points: array of Classes.TPoint;
    656   TextSize: TSize;
    657 begin
    658   if Cell.Extra = etObjectiveTarget then begin
    659     Text := Text + '!';
    660   end;
    661   with Canvas do begin
    662     if Assigned(View.FocusedCell) and (View.FocusedCell.MapCell = Cell) then begin
    663       Pen.Color := clYellow;
    664       Pen.Style := psSolid;
    665       Pen.Width := 1;
    666     end else
    667     if Cell.Terrain = ttCity then begin
    668       // Cannot set clear border as it will display shifted on gtk2
    669       //Pen.Style := psClear;
    670       Pen.Color := clBlack;
    671       Pen.Style := psSolid;
    672       Pen.Width := 3;
    673     end else begin
    674       // Cannot set clear border as it will display shifted on gtk2
    675       //Pen.Style := psClear;
    676       Pen.Color := Brush.Color;
    677       Pen.Style := psSolid;
    678       Pen.Width := 0;
    679     end;
    680     // Transform view
    681     SetLength(Points, Length(Cell.Polygon.Points));
    682     for I := 0 to Length(Points) - 1 do
    683       Points[I] := PointToStdPoint(View.CellToCanvasPos(Cell.Polygon.Points[I]));
    684     Brush.Style := bsSolid;
    685     //Polygon(Points, False, 0, Length(Points));
    686     TCanvasEx.PolygonEx(Canvas, Points, False);
    687     //MoveTo(Points[0].X, Points[0].Y);
    688     //LineTo(Points[1].X, Points[1].Y);
    689 
    690     // Show cell text
    691     if (Cell.Power <> 0) or (Cell.Extra = etObjectiveTarget) then begin
    692       Pen.Style := psSolid;
    693       Font.Color := clWhite;
    694       Brush.Style := bsClear;
    695       Font.Size := Trunc(42 * View.Zoom);
    696       TextPos := View.CellToCanvasPos(Pos);
    697       TextSize := TextExtent(Text);
    698       TCanvasEx.TextOutEx(Canvas, Round(TextPos.X) - TextSize.cx div 2,
    699         Round(TextPos.Y) - TextSize.cy div 2, Text, False);
    700     end;
    701   end;
    702 end;
    703 }
    704604
    705605procedure TMap.ComputePlayerStats;
     
    1010910procedure TCell.ConnectTo(Cell: TCell);
    1011911begin
     912  if Cell = Self then
     913    raise Exception.Create('Can''t connect map cell to itself');
    1012914  // Connect only if already not connected
    1013915  if Neighbors.IndexOf(Cell) < 0 then begin
     
    1068970var
    1069971  I: Integer;
     972  Cell: TCell;
    1070973begin
    1071974  Player := TGame(Map.Game).Players.FindById(PlayerId);
    1072975
    1073976  Neighbors.Count := Length(NeighborsId);
     977  for I := 0 to Length(NeighborsId) - 1 do
     978    Neighbors[I] := nil;
    1074979  for I := 0 to Length(NeighborsId) - 1 do begin
    1075     Neighbors[I] := Map.Cells.FindById(NeighborsId[I]);
     980    Cell := Map.Cells.FindById(NeighborsId[I]);
     981    if not Assigned(Cell) then
     982      raise Exception.Create('Neighbor cell id not found ' + IntToStr(NeighborsId[I]));
     983    if Neighbors.IndexOf(Cell) <> -1 then
     984      raise Exception.Create('Duplicate neighbor cell ' + IntToStr(NeighborsId[I]) + ' found for cell ' + IntToStr(Id));
     985    Neighbors[I] := Cell;
    1076986  end;
    1077987end;
Note: See TracChangeset for help on using the changeset viewer.