Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Shapes.cs
Go to the documentation of this file.
1using System;
4
6
7public static class Shapes
8{
9 public class Circle : GenShape
10 {
11 private int _verticalRadius;
12
13 private int _horizontalRadius;
14
15 public Circle(int radius)
16 {
17 _verticalRadius = radius;
18 _horizontalRadius = radius;
19 }
20
21 public Circle(int horizontalRadius, int verticalRadius)
22 {
23 _horizontalRadius = horizontalRadius;
24 _verticalRadius = verticalRadius;
25 }
26
27 public void SetRadius(int radius)
28 {
29 _verticalRadius = radius;
30 _horizontalRadius = radius;
31 }
32
33 public override bool Perform(Point origin, GenAction action)
34 {
35 int num = (_horizontalRadius + 1) * (_horizontalRadius + 1);
36 for (int i = origin.Y - _verticalRadius; i <= origin.Y + _verticalRadius; i++)
37 {
38 double num2 = (double)_horizontalRadius / (double)_verticalRadius * (double)(i - origin.Y);
39 int num3 = Math.Min(_horizontalRadius, (int)Math.Sqrt((double)num - num2 * num2));
40 for (int j = origin.X - num3; j <= origin.X + num3; j++)
41 {
42 if (!UnitApply(action, origin, j, i) && _quitOnFail)
43 {
44 return false;
45 }
46 }
47 }
48 return true;
49 }
50 }
51
52 public class HalfCircle : GenShape
53 {
54 private int _radius;
55
56 public HalfCircle(int radius)
57 {
58 _radius = radius;
59 }
60
61 public override bool Perform(Point origin, GenAction action)
62 {
63 int num = (_radius + 1) * (_radius + 1);
64 for (int i = origin.Y - _radius; i <= origin.Y; i++)
65 {
66 int num2 = Math.Min(_radius, (int)Math.Sqrt(num - (i - origin.Y) * (i - origin.Y)));
67 for (int j = origin.X - num2; j <= origin.X + num2; j++)
68 {
69 if (!UnitApply(action, origin, j, i) && _quitOnFail)
70 {
71 return false;
72 }
73 }
74 }
75 return true;
76 }
77 }
78
79 public class Slime : GenShape
80 {
81 private int _radius;
82
83 private double _xScale;
84
85 private double _yScale;
86
87 public Slime(int radius)
88 {
89 _radius = radius;
90 _xScale = 1.0;
91 _yScale = 1.0;
92 }
93
94 public Slime(int radius, double xScale, double yScale)
95 {
96 _radius = radius;
97 _xScale = xScale;
98 _yScale = yScale;
99 }
100
101 public override bool Perform(Point origin, GenAction action)
102 {
103 double num = _radius;
104 int num2 = (_radius + 1) * (_radius + 1);
105 for (int i = origin.Y - (int)(num * _yScale); i <= origin.Y; i++)
106 {
107 double num3 = (double)(i - origin.Y) / _yScale;
108 int num4 = (int)Math.Min((double)_radius * _xScale, _xScale * Math.Sqrt((double)num2 - num3 * num3));
109 for (int j = origin.X - num4; j <= origin.X + num4; j++)
110 {
111 if (!UnitApply(action, origin, j, i) && _quitOnFail)
112 {
113 return false;
114 }
115 }
116 }
117 for (int k = origin.Y + 1; k <= origin.Y + (int)(num * _yScale * 0.5) - 1; k++)
118 {
119 double num5 = (double)(k - origin.Y) * (2.0 / _yScale);
120 int num6 = (int)Math.Min((double)_radius * _xScale, _xScale * Math.Sqrt((double)num2 - num5 * num5));
121 for (int l = origin.X - num6; l <= origin.X + num6; l++)
122 {
123 if (!UnitApply(action, origin, l, k) && _quitOnFail)
124 {
125 return false;
126 }
127 }
128 }
129 return true;
130 }
131 }
132
133 public class Rectangle : GenShape
134 {
136
138 {
139 _area = area;
140 }
141
142 public Rectangle(int width, int height)
143 {
144 _area = new Microsoft.Xna.Framework.Rectangle(0, 0, width, height);
145 }
146
148 {
149 _area = area;
150 }
151
152 public override bool Perform(Point origin, GenAction action)
153 {
154 for (int i = origin.X + _area.Left; i < origin.X + _area.Right; i++)
155 {
156 for (int j = origin.Y + _area.Top; j < origin.Y + _area.Bottom; j++)
157 {
158 if (!UnitApply(action, origin, i, j) && _quitOnFail)
159 {
160 return false;
161 }
162 }
163 }
164 return true;
165 }
166 }
167
168 public class Tail : GenShape
169 {
170 private double _width;
171
173
174 public Tail(double width, Vector2D endOffset)
175 {
176 //IL_0018: Unknown result type (might be due to invalid IL or missing references)
177 //IL_0022: Unknown result type (might be due to invalid IL or missing references)
178 //IL_0027: Unknown result type (might be due to invalid IL or missing references)
179 _width = width * 16.0;
180 _endOffset = endOffset * 16.0;
181 }
182
183 public override bool Perform(Point origin, GenAction action)
184 {
185 //IL_0037: Unknown result type (might be due to invalid IL or missing references)
186 //IL_003c: Unknown result type (might be due to invalid IL or missing references)
187 //IL_003e: Unknown result type (might be due to invalid IL or missing references)
188 //IL_0043: Unknown result type (might be due to invalid IL or missing references)
189 Vector2D val = new Vector2D((double)(origin.X << 4), (double)(origin.Y << 4));
190 return Utils.PlotTileTale(val, val + _endOffset, _width, (int x, int y) => UnitApply(action, origin, x, y) || !_quitOnFail);
191 }
192 }
193
194 public class Mound : GenShape
195 {
196 private int _halfWidth;
197
198 private int _height;
199
200 public Mound(int halfWidth, int height)
201 {
202 _halfWidth = halfWidth;
203 _height = height;
204 }
205
206 public override bool Perform(Point origin, GenAction action)
207 {
208 _ = _height;
209 double num = _halfWidth;
210 for (int i = -_halfWidth; i <= _halfWidth; i++)
211 {
212 int num2 = Math.Min(_height, (int)((0.0 - (double)(_height + 1) / (num * num)) * ((double)i + num) * ((double)i - num)));
213 for (int j = 0; j < num2; j++)
214 {
215 if (!UnitApply(action, origin, i + origin.X, origin.Y - j) && _quitOnFail)
216 {
217 return false;
218 }
219 }
220 }
221 return true;
222 }
223 }
224}
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Sqrt(double d)
static bool PlotTileTale(Vector2D start, Vector2D end, double width, TileActionAttempt plot)
Definition Utils.cs:1712
bool UnitApply(GenAction action, Point origin, int x, int y, params object[] args)
Definition GenShape.cs:13
Circle(int horizontalRadius, int verticalRadius)
Definition Shapes.cs:21
override bool Perform(Point origin, GenAction action)
Definition Shapes.cs:33
override bool Perform(Point origin, GenAction action)
Definition Shapes.cs:61
override bool Perform(Point origin, GenAction action)
Definition Shapes.cs:206
Mound(int halfWidth, int height)
Definition Shapes.cs:200
Rectangle(int width, int height)
Definition Shapes.cs:142
override bool Perform(Point origin, GenAction action)
Definition Shapes.cs:152
Microsoft.Xna.Framework.Rectangle _area
Definition Shapes.cs:135
void SetArea(Microsoft.Xna.Framework.Rectangle area)
Definition Shapes.cs:147
Rectangle(Microsoft.Xna.Framework.Rectangle area)
Definition Shapes.cs:137
override bool Perform(Point origin, GenAction action)
Definition Shapes.cs:101
Slime(int radius, double xScale, double yScale)
Definition Shapes.cs:94
override bool Perform(Point origin, GenAction action)
Definition Shapes.cs:183
Tail(double width, Vector2D endOffset)
Definition Shapes.cs:174