Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StructureMap.cs
Go to the documentation of this file.
2using System.Linq;
4using Terraria.ID;
5
7
8public class StructureMap
9{
10 private readonly List<Rectangle> _structures = new List<Rectangle>(2048);
11
13
14 private readonly object _lock = new object();
15
16 public bool CanPlace(Rectangle area, int padding = 0)
17 {
19 }
20
21 public bool CanPlace(Rectangle area, bool[] validTiles, int padding = 0)
22 {
23 lock (_lock)
24 {
25 if (area.X < 0 || area.Y < 0 || area.X + area.Width > Main.maxTilesX - 1 || area.Y + area.Height > Main.maxTilesY - 1)
26 {
27 return false;
28 }
29 Rectangle rectangle = new Rectangle(area.X - padding, area.Y - padding, area.Width + padding * 2, area.Height + padding * 2);
30 for (int i = 0; i < _protectedStructures.Count; i++)
31 {
32 if (rectangle.Intersects(_protectedStructures[i]))
33 {
34 return false;
35 }
36 }
37 for (int j = rectangle.X; j < rectangle.X + rectangle.Width; j++)
38 {
39 for (int k = rectangle.Y; k < rectangle.Y + rectangle.Height; k++)
40 {
41 if (Main.tile[j, k].active())
42 {
43 ushort type = Main.tile[j, k].type;
44 if (!validTiles[type])
45 {
46 return false;
47 }
48 }
49 }
50 }
51 return true;
52 }
53 }
54
56 {
57 lock (_lock)
58 {
59 if (_structures.Count == 0)
60 {
61 return Rectangle.Empty;
62 }
63 Point point = new Point(_structures.Min((Rectangle rect) => rect.Left), _structures.Min((Rectangle rect) => rect.Top));
64 Point point2 = new Point(_structures.Max((Rectangle rect) => rect.Right), _structures.Max((Rectangle rect) => rect.Bottom));
65 return new Rectangle(point.X, point.Y, point2.X - point.X, point2.Y - point.Y);
66 }
67 }
68
69 public void AddStructure(Rectangle area, int padding = 0)
70 {
71 lock (_lock)
72 {
73 area.Inflate(padding, padding);
75 }
76 }
77
78 public void AddProtectedStructure(Rectangle area, int padding = 0)
79 {
80 lock (_lock)
81 {
82 area.Inflate(padding, padding);
85 }
86 }
87
88 public void Reset()
89 {
90 lock (_lock)
91 {
93 }
94 }
95}
static bool[] GeneralPlacementTiles
Definition TileID.cs:221
static int maxTilesY
Definition Main.cs:1116
static int maxTilesX
Definition Main.cs:1114
static Tile[,] tile
Definition Main.cs:1675
void AddProtectedStructure(Rectangle area, int padding=0)
void AddStructure(Rectangle area, int padding=0)
bool CanPlace(Rectangle area, int padding=0)
readonly List< Rectangle > _structures
bool CanPlace(Rectangle area, bool[] validTiles, int padding=0)
readonly List< Rectangle > _protectedStructures