Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r155 r156 112 112 Map: TMap; 113 113 function FindByCells(Cell1, Cell2: TCell): TCellLink; 114 function AddLink(Cell1, Cell2: TCell): TCellLink; 114 115 procedure LoadFromNode(Node: TDOMNode); 115 116 procedure SaveToNode(Node: TDOMNode); … … 204 205 procedure ComputePlayerStats; virtual; 205 206 procedure Generate; virtual; 207 procedure MakeSymetric; 206 208 procedure Clear; 207 209 constructor Create; virtual; … … 734 736 var 735 737 I: Integer; 736 LastState: Boolean;737 738 begin 738 739 for I := 0 to Cells.Count - 1 do begin … … 743 744 end; 744 745 FreeAndNil(Cells); 745 if Assigned(Map) then begin746 // To remove itself from list we need disable owning to not be called twice747 try748 LastState := Map.CellLinks.FreeObjects;749 Map.CellLinks.FreeObjects := False;750 Map.CellLinks.Remove(Self);751 finally752 Map.CellLinks.FreeObjects := LastState;753 end;754 end;755 746 inherited Destroy; 756 747 end; … … 772 763 if I < Count then Result := TCellLink(Items[I]) 773 764 else Result := nil; 765 end; 766 767 function TCellLinks.AddLink(Cell1, Cell2: TCell): TCellLink; 768 begin 769 Result := TCellLink.Create; 770 Cell1.Neighbors.Add(Cell2); 771 Cell1.Links.Add(Result); 772 Cell2.Neighbors.Add(Cell1); 773 Cell2.Links.Add(Result); 774 SetLength(Result.Points, 2); 775 Result.Cells.Add(Cell1); 776 Result.Points[0] := Cell1.PosPx; 777 Result.Cells.Add(Cell2); 778 Result.Points[1] := Cell2.PosPx; 779 Result.Map := Map; 780 Map.CellLinks.Add(Result); 774 781 end; 775 782 … … 962 969 var 963 970 I: Integer; 964 C: Integer;965 971 Cell: TPlayerCell; 966 972 PosFrom, PosTo: TPoint; … … 1596 1602 NewCell: TCell; 1597 1603 begin 1598 // Free previous1599 Cells.Count := 0; 1604 Clear; 1605 1600 1606 // Allocate and init new 1601 1607 Cells.Count := FSize.Y * FSize.X; … … 1611 1617 end; 1612 1618 1619 procedure TMap.MakeSymetric; 1620 var 1621 C: Integer; 1622 CellLink: TCellLink; 1623 OtherCell1: TCell; 1624 OtherCell2: TCell; 1625 OppositeCell: TCell; 1626 begin 1627 // Generic way to create two sides symetric map independent to shape 1628 for C := 0 to (Cells.Count div 2) - 1 do begin 1629 TCell(Cells[C]).Terrain := TCell(Cells[Cells.Count - 1 - C]).Terrain; 1630 TCell(Cells[C]).Power := TCell(Cells[Cells.Count - 1 - C]).Power; 1631 1632 Continue; // TODO 1633 1634 for CellLink in TCell(Cells[C]).Links do 1635 CellLinks.Remove(CellLink); 1636 TCell(Cells[C]).Links.Clear; 1637 OppositeCell := TCell(Cells[Cells.Count - 1 - C]); 1638 for CellLink in OppositeCell.Links do begin 1639 OtherCell1 := Cells[Cells.Count - 1 - Cells.IndexOf(CellLink.Cells[0])]; 1640 OtherCell2 := Cells[Cells.Count - 1 - Cells.IndexOf(CellLink.Cells[1])]; 1641 CellLinks.AddLink(OtherCell1, OtherCell2); 1642 end; 1643 end; 1644 end; 1645 1613 1646 procedure TMap.Clear; 1614 1647 begin 1615 1648 CellLinks.Clear; 1616 1649 Cells.Clear; 1650 FNewCellId := 1; 1617 1651 end; 1618 1652 … … 1968 2002 FreeAndNil(MovesTo); 1969 2003 for I := Links.Count - 1 downto 0 do 1970 TCellLink(Links[I]).Free;2004 FMap.CellLinks.Remove(Links[I]); 1971 2005 FreeAndNil(Links); 1972 2006 for I := Neighbors.Count - 1 downto 0 do … … 2037 2071 var 2038 2072 NewNode: TDOMNode; 2039 Move: TUnitMove;2040 2073 begin 2041 2074 Id := ReadInteger(Node, 'Id', 0); … … 2648 2681 procedure TPlayer.MoveAll; 2649 2682 var 2650 I: Integer;2651 2683 AttackerPower: Integer; 2652 2684 DefenderPower: Integer; … … 2915 2947 I: Integer; 2916 2948 J: Integer; 2917 NewLink: TCellLink;2918 2949 begin 2919 2950 List := TCells.Create; … … 2948 2979 // Check if link doesn't exist already 2949 2980 if not Assigned(FoundCell1.Links.FindByCells(FoundCell1, FoundCell2)) then begin 2950 NewLink := TCellLink.Create; 2951 FoundCell1.Neighbors.Add(FoundCell2); 2952 FoundCell1.Links.Add(NewLink); 2953 FoundCell2.Neighbors.Add(FoundCell1); 2954 FoundCell2.Links.Add(NewLink); 2955 SetLength(NewLink.Points, 2); 2956 NewLink.Cells.Add(FoundCell1); 2957 NewLink.Points[0] := FoundCell1.PosPx; 2958 NewLink.Cells.Add(FoundCell2); 2959 NewLink.Points[1] := FoundCell2.PosPx; 2960 NewLink.Map := Map; 2961 Map.CellLinks.Add(NewLink); 2981 Map.CellLinks.AddLink(FoundCell1, FoundCell2); 2962 2982 Inc(BridgeCount); 2963 2983 end; … … 3152 3172 RootNode: TDOMNode; 3153 3173 I: Integer; 3154 Move: TUnitMove;3155 3174 begin 3156 3175 Self.FileName := FileName; … … 3404 3423 var 3405 3424 I: Integer; 3406 C: Integer;3407 3425 LastAreaCount: Integer; 3408 3426 Player: TPlayer; … … 3426 3444 end; 3427 3445 3428 if SymetricMap then begin 3429 for C := 0 to (Map.Cells.Count div 2) - 1 do begin 3430 TCell(Map.Cells[C]).Terrain := 3431 TCell(Map.Cells[Map.Cells.Count - 1 - C]).Terrain; 3432 TCell(Map.Cells[C]).Power := 3433 TCell(Map.Cells[Map.Cells.Count - 1 - C]).Power; 3434 end; 3435 end; 3446 if SymetricMap then Map.MakeSymetric; 3436 3447 3437 3448 Players.Assign(PlayersSetting); … … 3468 3479 var 3469 3480 I: Integer; 3470 C: Integer;3471 3481 Cell: TCell; 3472 3482 PosFrom, PosTo: TPoint; -
trunk/UMap.pas
r145 r156 146 146 PX, PY: Double; 147 147 begin 148 // Free previous 149 Cells.Count := 0; 150 FNewCellId := 1; 148 Clear; 151 149 152 150 // Allocate and init new … … 185 183 NewCell: TCell; 186 184 begin 187 // Free previous 188 Cells.Count := 0; 189 FNewCellId := 1; 185 Clear; 186 190 187 // Allocate and init new 191 188 Cells.Count := Size.Y * Size.X; … … 244 241 NewCell: TCell; 245 242 begin 246 // Free previous 247 Cells.Count := 0; 248 FNewCellId := 1; 243 Clear; 244 249 245 // Allocate and init new 250 246 Cells.Count := Size.Y * Size.X; … … 290 286 NewCell: TCell; 291 287 begin 292 // Free previous 293 Cells.Count := 0; 294 FNewCellId := 1; 288 Clear; 289 295 290 // Allocate and init new 296 291 Cells.Count := Size.Y * Size.X;
Note:
See TracChangeset
for help on using the changeset viewer.