Changeset 157
- Timestamp:
- Nov 16, 2017, 10:32:12 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.lfm
r148 r157 36 36 Height = 557 37 37 Top = 0 38 Width = 8038 Width = 32 39 39 Align = alLeft 40 40 ButtonHeight = 32 … … 114 114 end 115 115 object PaintBox1: TPaintBox 116 Left = 80116 Left = 32 117 117 Height = 557 118 118 Top = 0 119 Width = 695119 Width = 743 120 120 Align = alClient 121 121 OnMouseDown = PaintBox1MouseDown -
trunk/UGame.pas
r156 r157 98 98 99 99 TCellLink = class 100 Allocated: Boolean; 100 101 Points: array of TPoint; 101 102 Cells: TCells; … … 179 180 procedure DrawArrow(Canvas: TCanvas; View: TView; Pos: TPoint; Angle: Double; 180 181 Text: string); 182 function SearchDifferentCellArea(List: TCells; SourceArea, 183 DestArea: TMapArea): TCell; 181 184 procedure SetSize(AValue: TPoint); virtual; 182 185 protected … … 205 208 procedure ComputePlayerStats; virtual; 206 209 procedure Generate; virtual; 210 procedure BuildMapAreas; 211 procedure BuildBridges; 207 212 procedure MakeSymetric; 213 procedure CreateLinks; 208 214 procedure Clear; 209 215 constructor Create; virtual; … … 438 444 procedure SetMapType(AValue: TMapType); 439 445 procedure SetRunning(AValue: Boolean); 440 function SearchDifferentCellArea(List: TCells; SourceArea, DestArea: TMapArea): TCell;441 446 procedure BuildTerrain; 442 procedure BuildBridges;443 procedure BuildMapAreas;444 447 procedure InitClients; 445 448 procedure SelectPlayerStartCell(Player: TPlayer); … … 729 732 constructor TCellLink.Create; 730 733 begin 734 Allocated := True; 731 735 Cells := TCells.Create; 732 736 Cells.FreeObjects := False; … … 735 739 destructor TCellLink.Destroy; 736 740 var 741 Links: TCellLinks; 742 FirstLink: TCellLink; 737 743 I: Integer; 738 744 begin … … 740 746 if TCell(Cells[I]).Neighbors.Remove(TCell(Cells[1 - I])) = -1 then 741 747 raise Exception.Create(SCellRemoveNeighborError); 748 Links := TCell(Cells[I]).Links; 749 if Links.Count > 0 then 750 FirstLink := TCellLink(Links[0]); 742 751 if TCell(Cells[I]).Links.Remove(Self) = -1 then 743 752 raise Exception.Create(SCellRemoveNeighborError); 744 753 end; 745 754 FreeAndNil(Cells); 755 Allocated := False; 746 756 inherited Destroy; 747 757 end; … … 755 765 I := 0; 756 766 while (I < Count) do begin 757 if (TCellLink(Items[I]).Cells[0] = Cell1) and (TCellLink(Items[I]).Cells[1] = Cell2) then 758 Break; 759 if (TCellLink(Items[I]).Cells[0] = Cell2) and (TCellLink(Items[I]).Cells[1] = Cell1) then 767 if ((TCellLink(Items[I]).Cells[0] = Cell1) and (TCellLink(Items[I]).Cells[1] = Cell2)) or 768 ((TCellLink(Items[I]).Cells[0] = Cell2) and (TCellLink(Items[I]).Cells[1] = Cell1)) then 760 769 Break; 761 770 Inc(I); … … 1355 1364 msRounded: begin 1356 1365 Rect := GetPixelRect; 1357 Center := Point(Rect.Left + Rect.Width div 2, Rect.Top + Rect.Height div 2); 1358 Result := Sqr(Coord.X - Center.X) / Sqr(Rect.Width div 2) + 1359 Sqr(Coord.Y - Center.Y) / Sqr(Rect.Height div 2) > 1; 1366 Center := Point(Rect.Left + (Rect.Right - Rect.Left) div 2, 1367 Rect.Top + (Rect.Bottom - Rect.Top) div 2); 1368 Result := Sqr(Coord.X - Center.X) / Sqr((Rect.Right - Rect.Left) div 2) + 1369 Sqr(Coord.Y - Center.Y) / Sqr((Rect.Bottom - Rect.Top) div 2) > 1; 1360 1370 end 1361 1371 else Result := False; … … 1620 1630 var 1621 1631 C: Integer; 1632 I: Integer; 1622 1633 CellLink: TCellLink; 1623 1634 OtherCell1: TCell; … … 1630 1641 TCell(Cells[C]).Power := TCell(Cells[Cells.Count - 1 - C]).Power; 1631 1642 1632 Continue; // TODO 1633 1634 for CellLink in TCell(Cells[C]).Links do 1635 CellLinks.Remove(CellLink); 1636 TCell(Cells[C]).Links.Clear; 1643 for I := TCell(Cells[C]).Links.Count - 1 downto 0 do begin 1644 CellLink := TCell(Cells[C]).Links[I]; 1645 1646 // Remove cells on first half of the map 1647 if (Cells.IndexOf(CellLink.Cells[0]) <= (Cells.Count div 2)) and 1648 (Cells.IndexOf(CellLink.Cells[1]) <= (Cells.Count div 2)) then 1649 begin 1650 CellLinks.Remove(CellLink); 1651 Continue; 1652 end; 1653 1654 // Make cross half links symetric 1655 if (Cells.IndexOf(CellLink.Cells[0]) <= (Cells.Count div 2)) and 1656 (Cells.IndexOf(CellLink.Cells[1]) >= (Cells.Count div 2)) then begin 1657 OtherCell1 := Cells[Cells.Count - 1 - Cells.IndexOf(CellLink.Cells[1])]; 1658 OtherCell2 := CellLink.Cells[1]; 1659 CellLinks.Remove(CellLink); 1660 if not Assigned(CellLinks.FindByCells(OtherCell1, OtherCell2)) then 1661 CellLinks.AddLink(OtherCell1, OtherCell2); 1662 end else 1663 if (Cells.IndexOf(CellLink.Cells[0]) >= (Cells.Count div 2)) and 1664 (Cells.IndexOf(CellLink.Cells[1]) <= (Cells.Count div 2)) then begin 1665 OtherCell1 := Cells[Cells.Count - 1 - Cells.IndexOf(CellLink.Cells[0])]; 1666 OtherCell2 := CellLink.Cells[0]; 1667 CellLinks.Remove(CellLink); 1668 if not Assigned(CellLinks.FindByCells(OtherCell1, OtherCell2)) then 1669 CellLinks.AddLink(OtherCell1, OtherCell2); 1670 end; 1671 end; 1672 end; 1673 1674 for C := 0 to (Cells.Count div 2) - 1 do begin 1675 // Make copy of links from second half 1637 1676 OppositeCell := TCell(Cells[Cells.Count - 1 - C]); 1638 for CellLink in OppositeCell.Links do begin 1677 for CellLink in OppositeCell.Links do 1678 if (Cells.IndexOf(CellLink.Cells[0]) > (Cells.Count div 2)) and 1679 (Cells.IndexOf(CellLink.Cells[1]) > (Cells.Count div 2)) then begin 1639 1680 OtherCell1 := Cells[Cells.Count - 1 - Cells.IndexOf(CellLink.Cells[0])]; 1640 1681 OtherCell2 := Cells[Cells.Count - 1 - Cells.IndexOf(CellLink.Cells[1])]; 1641 CellLinks.AddLink(OtherCell1, OtherCell2); 1642 end; 1682 if not Assigned(CellLinks.FindByCells(OtherCell1, OtherCell2)) then 1683 CellLinks.AddLink(OtherCell1, OtherCell2); 1684 end; 1685 end; 1686 end; 1687 1688 procedure TMap.CreateLinks; 1689 var 1690 LastAreaCount: Integer; 1691 begin 1692 BuildMapAreas; 1693 LastAreaCount := -1; 1694 while (Areas.Count > 1) and (Areas.Count <> LastAreaCount) do begin 1695 LastAreaCount := Areas.Count; 1696 BuildBridges; 1697 BuildMapAreas; 1643 1698 end; 1644 1699 end; … … 2874 2929 end; 2875 2930 2876 function T Game.SearchDifferentCellArea(List: TCells; SourceArea, DestArea: TMapArea): TCell;2931 function TMap.SearchDifferentCellArea(List: TCells; SourceArea, DestArea: TMapArea): TCell; 2877 2932 var 2878 2933 NewList: TCells; … … 2938 2993 end; 2939 2994 2940 procedure T Game.BuildBridges;2995 procedure TMap.BuildBridges; 2941 2996 var 2942 2997 List: TCells; … … 2955 3010 2956 3011 // Build area bridges 2957 if Map.Areas.Count > 1 then2958 for I := 0 to Map.Areas.Count - 1 do2959 with TMapArea( Map.Areas[I]) do begin3012 if Areas.Count > 1 then 3013 for I := 0 to Areas.Count - 1 do 3014 with TMapArea(Areas[I]) do begin 2960 3015 GetBorderCells(BorderList); 2961 3016 for J := 0 to 1 do begin … … 2991 3046 end; 2992 3047 2993 procedure T Game.BuildMapAreas;3048 procedure TMap.BuildMapAreas; 2994 3049 var 2995 3050 C: Integer; 2996 3051 NewArea: TMapArea; 2997 3052 begin 2998 for C := 0 to Map.Cells.Count - 1 do2999 with TCell( Map.Cells[C]) do3053 for C := 0 to Cells.Count - 1 do 3054 with TCell(Cells[C]) do 3000 3055 Area := nil; 3001 Map.Areas.Clear;3002 for C := 0 to Map.Cells.Count - 1 do3003 with TCell( Map.Cells[C]) do3056 Areas.Clear; 3057 for C := 0 to Cells.Count - 1 do 3058 with TCell(Cells[C]) do 3004 3059 if (Terrain <> ttVoid) and (not Assigned(Area)) then begin 3005 3060 NewArea := TMapArea.Create; 3006 3061 NewArea.Id := Map.Areas.Count; 3007 3062 NewArea.Map := Map; 3008 Map.Areas.Add(NewArea);3063 Areas.Add(NewArea); 3009 3064 Area := NewArea; 3010 3065 AreaExtend; … … 3423 3478 var 3424 3479 I: Integer; 3425 LastAreaCount: Integer;3426 3480 Player: TPlayer; 3427 3481 begin … … 3434 3488 3435 3489 // Build bridges 3436 if BridgeEnabled then begin 3437 BuildMapAreas; 3438 LastAreaCount := -1; 3439 while (Map.Areas.Count > 1) and (Map.Areas.Count <> LastAreaCount) do begin 3440 LastAreaCount := Map.Areas.Count; 3441 BuildBridges; 3442 BuildMapAreas; 3443 end; 3444 end; 3445 3446 if SymetricMap then Map.MakeSymetric; 3490 if BridgeEnabled then Map.CreateLinks; 3491 3492 if SymetricMap then begin 3493 Map.MakeSymetric; 3494 if BridgeEnabled then Map.CreateLinks; 3495 end; 3447 3496 3448 3497 Players.Assign(PlayersSetting);
Note:
See TracChangeset
for help on using the changeset viewer.