Changeset 170 for trunk/UMap.pas
- Timestamp:
- Nov 23, 2017, 5:02:49 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UMap.pas
r168 r170 6 6 7 7 uses 8 Classes, SysUtils, UGame, XMLRead, XMLWrite, DOM, Contnrs, UGeometry; 8 Classes, SysUtils, UGame, XMLRead, XMLWrite, DOM, Contnrs, UGeometryClasses, 9 UGeometry; 9 10 10 11 type … … 53 54 TVoronoiMap = class(TMap) 54 55 private 55 function GetTrianglePolygon(Pos: TPoint; Size: TPoint; Reverse: Boolean): TPointArray;56 56 public 57 57 procedure Generate; override; … … 68 68 Shift := FloatPoint(0.5 * cos(30 / 180 * Pi), 0.5 * sin(30 / 180 * Pi)); 69 69 SetLength(Result.Points, 6); 70 Result.Points[0] := Point(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y - 0.5 * Size.Y));71 Result.Points[1] := Point(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y));72 Result.Points[2] := Point(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y));73 Result.Points[3] := Point(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y + 0.5 * Size.Y));74 Result.Points[4] := Point(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y));75 Result.Points[5] := Point(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y));70 Result.Points[0] := TPoint.Create(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y - 0.5 * Size.Y)); 71 Result.Points[1] := TPoint.Create(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y)); 72 Result.Points[2] := TPoint.Create(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y)); 73 Result.Points[3] := TPoint.Create(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y + 0.5 * Size.Y)); 74 Result.Points[4] := TPoint.Create(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y)); 75 Result.Points[5] := TPoint.Create(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y)); 76 76 end; 77 77 … … 139 139 for Y := -1 to 1 do 140 140 for X := -1 to 1 do 141 if IsValidIndex( Point(CellPos.X + X, CellPos.Y + Y)) and142 IsCellsPosNeighbor(CellPos, Point((CellPos.X + X), (CellPos.Y + Y))) then begin141 if IsValidIndex(TPoint.Create(CellPos.X + X, CellPos.Y + Y)) and 142 IsCellsPosNeighbor(CellPos, TPoint.Create((CellPos.X + X), (CellPos.Y + Y))) then begin 143 143 Neighbours.Add(TCell(Cells[(CellPos.Y + Y) * Size.X + (CellPos.X + X)])); 144 144 end; … … 165 165 //Y := Y + 0.5; 166 166 end; 167 NewCell.PosPx := Point(Trunc(PX * DefaultCellSize.X / HexCellMulX),167 NewCell.PosPx := TPoint.Create(Trunc(PX * DefaultCellSize.X / HexCellMulX), 168 168 Trunc(PY * DefaultCellSize.Y / HexCellMulY)); 169 169 NewCell.Polygon := GetHexagonPolygon(NewCell.PosPx, DefaultCellSize); … … 176 176 for X := 0 to Size.X - 1 do 177 177 with TCell(Cells[Y * Size.X + X]) do begin 178 GetCellPosNeighbors( Point(X, Y), Neighbors);178 GetCellPosNeighbors(TPoint.Create(X, Y), Neighbors); 179 179 end; 180 180 … … 198 198 NewCell := TCell.Create; 199 199 NewCell.Map := Self; 200 NewCell.PosPx := Point(Trunc(X * DefaultCellSize.X * SquareCellMulX),200 NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X * SquareCellMulX), 201 201 Trunc(Y * DefaultCellSize.Y * SquareCellMulY)); 202 202 NewCell.Polygon := GetSquarePolygon(NewCell.PosPx, DefaultCellSize); … … 209 209 for X := 0 to Size.X - 1 do 210 210 with TCell(Cells[Y * Size.X + X]) do begin 211 if IsValidIndex( Point(X + 1, Y + 0)) then211 if IsValidIndex(TPoint.Create(X + 1, Y + 0)) then 212 212 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X + 1)])); 213 if IsValidIndex( Point(X + 0, Y + 1)) then213 if IsValidIndex(TPoint.Create(X + 0, Y + 1)) then 214 214 Neighbors.Add(TCell(Cells[(Y + 1) * Size.X + (X + 0)])); 215 if IsValidIndex( Point(X - 1, Y + 0)) then215 if IsValidIndex(TPoint.Create(X - 1, Y + 0)) then 216 216 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X - 1)])); 217 if IsValidIndex( Point(X + 0, Y - 1)) then217 if IsValidIndex(TPoint.Create(X + 0, Y - 1)) then 218 218 Neighbors.Add(TCell(Cells[(Y - 1) * Size.X + (X + 0)])); 219 219 end; … … 231 231 begin 232 232 SetLength(Result.Points, 4); 233 Result.Points[0] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - Size.Y / 2));234 Result.Points[1] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - Size.Y / 2));235 Result.Points[2] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y + Size.Y / 2));236 Result.Points[3] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y + Size.Y / 2));233 Result.Points[0] := TPoint.Create(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - Size.Y / 2)); 234 Result.Points[1] := TPoint.Create(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - Size.Y / 2)); 235 Result.Points[2] := TPoint.Create(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y + Size.Y / 2)); 236 Result.Points[3] := TPoint.Create(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y + Size.Y / 2)); 237 237 end; 238 238 239 239 { TVoronoiMap } 240 241 function TVoronoiMap.GetTrianglePolygon(Pos: TPoint; Size: TPoint;242 Reverse: Boolean): TPointArray;243 begin244 SetLength(Result, 0);245 end;246 240 247 241 function CompareDistance(C1, C2: Pointer): Integer; … … 309 303 NewCell := TCell.Create; 310 304 NewCell.Map := Self; 311 NewCell.PosPx := Point(Trunc(Random * Size.X * DefaultCellSize.X),305 NewCell.PosPx := TPoint.Create(Trunc(Random * Size.X * DefaultCellSize.X), 312 306 Trunc(Random * Size.Y * DefaultCellSize.Y)); 313 307 SetLength(NewCell.Polygon.Points, 1); … … 324 318 NewCellDist.Cell1 := Cells[I1]; 325 319 NewCellDist.Cell2 := Cells[I2]; 326 NewCellDist.Distance := Distance(NewCellDist.Cell1.PosPx, NewCellDist.Cell2.PosPx);320 NewCellDist.Distance := TLine.Create(NewCellDist.Cell1.PosPx, NewCellDist.Cell2.PosPx).Distance; 327 321 CellsDistance.Add(NewCellDist); 328 322 end; … … 344 338 L2 := TLine.Create(TCellsDistance(SelectedCells[J]).Cell1.PosPx, 345 339 TCellsDistance(SelectedCells[J]).Cell2.PosPx); 346 if LineIntersect(L1, L2, Intersection) then begin347 if PointInRect(Intersection, L1.ToRect) and348 PointInRect(Intersection, L2.ToRect) then begin340 if TLine.LineIntersect(L1, L2, Intersection) then begin 341 if L1.ToRect.IsPointInside(Intersection) and 342 L2.ToRect.IsPointInside(Intersection) then begin 349 343 Intersected := True; 350 344 Break; … … 423 417 // Use whole map first for cell polygon 424 418 if Cell.Neighbors.Count > 0 then begin 425 Polygon := TPolygon.Create( Rect(0, 0,426 Size.X * DefaultCellSize.X, Size.Y * DefaultCellSize.Y));419 Polygon := TPolygon.Create(TRect.Create(TPoint.Create(0, 0), 420 TPoint.Create(Size.X * DefaultCellSize.X, Size.Y * DefaultCellSize.Y))); 427 421 for NeighborCell in Cell.Neighbors do begin 428 422 LinkLine := TLine.Create(Cell.PosPx, NeighborCell.PosPx); … … 430 424 MP := LinkLine.GetMiddle; 431 425 // Create half plane vector 432 L1 := TLine.Create(MP, Point(MP.X + LinkLine.GetSize.X,426 L1 := TLine.Create(MP, TPoint.Create(MP.X + LinkLine.GetSize.X, 433 427 MP.Y + LinkLine.GetSize.Y)); 434 428 … … 452 446 else Rev := 1; 453 447 SetLength(Result.Points, 3); 454 Result.Points[0] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev));455 Result.Points[1] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev));456 Result.Points[2] := Point(Trunc(Pos.X), Trunc(Pos.Y + (Size.Y * 1.2) / 2 * Rev));448 Result.Points[0] := TPoint.Create(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev)); 449 Result.Points[1] := TPoint.Create(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev)); 450 Result.Points[2] := TPoint.Create(Trunc(Pos.X), Trunc(Pos.Y + (Size.Y * 1.2) / 2 * Rev)); 457 451 end; 458 452 … … 481 475 if Reverse then Rev := -1 482 476 else Rev := 1; 483 NewCell.PosPx := Point(Trunc(X * DefaultCellSize.X * TriangleCellMulX),477 NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X * TriangleCellMulX), 484 478 Trunc((Y * DefaultCellSize.Y * TriangleCellMulY) - (0.1 * Rev * DefaultCellSize.Y))); 485 479 NewCell.Polygon := GetTrianglePolygon(NewCell.PosPx, DefaultCellSize, Reverse); … … 494 488 if Boolean(X mod 2) xor Boolean(Y mod 2) then Rev := -1 495 489 else Rev := 1; 496 if IsValidIndex( Point(X + 1, Y + 0)) then490 if IsValidIndex(TPoint.Create(X + 1, Y + 0)) then 497 491 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X + 1)])); 498 if IsValidIndex( Point(X + 0, Y - 1 * Rev)) then492 if IsValidIndex(TPoint.Create(X + 0, Y - 1 * Rev)) then 499 493 Neighbors.Add(TCell(Cells[(Y - 1 * Rev) * Size.X + (X + 0)])); 500 if IsValidIndex( Point(X - 1, Y + 0)) then494 if IsValidIndex(TPoint.Create(X - 1, Y + 0)) then 501 495 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X - 1)])); 502 496 end;
Note:
See TracChangeset
for help on using the changeset viewer.