Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GraniteBiome.cs
Go to the documentation of this file.
1using System;
6using Terraria.ID;
9
11
13{
14 private struct Magma
15 {
16 public readonly double Pressure;
17
18 public readonly double Resistance;
19
20 public readonly bool IsActive;
21
22 private Magma(double pressure, double resistance, bool active)
23 {
26 IsActive = active;
27 }
28
29 public Magma ToFlow()
30 {
31 return new Magma(Pressure, Resistance, active: true);
32 }
33
34 public static Magma CreateFlow(double pressure, double resistance = 0.0)
35 {
36 return new Magma(pressure, resistance, active: true);
37 }
38
39 public static Magma CreateEmpty(double resistance = 0.0)
40 {
41 return new Magma(0.0, resistance, active: false);
42 }
43 }
44
45 private const int MAX_MAGMA_ITERATIONS = 300;
46
47 private Magma[,] _sourceMagmaMap = new Magma[200, 200];
48
49 private Magma[,] _targetMagmaMap = new Magma[200, 200];
50
51 private static Vector2D[] _normalisedVectors = (Vector2D[])(object)new Vector2D[9]
52 {
53 Vector2D.Normalize(new Vector2D(-1.0, -1.0)),
54 Vector2D.Normalize(new Vector2D(-1.0, 0.0)),
55 Vector2D.Normalize(new Vector2D(-1.0, 1.0)),
56 Vector2D.Normalize(new Vector2D(0.0, -1.0)),
57 new Vector2D(0.0, 0.0),
58 Vector2D.Normalize(new Vector2D(0.0, 1.0)),
59 Vector2D.Normalize(new Vector2D(1.0, -1.0)),
60 Vector2D.Normalize(new Vector2D(1.0, 0.0)),
61 Vector2D.Normalize(new Vector2D(1.0, 1.0))
62 };
63
64 public static bool CanPlace(Point origin, StructureMap structures)
65 {
66 if (WorldGen.BiomeTileCheck(origin.X, origin.Y))
67 {
68 return false;
69 }
70 return !GenBase._tiles[origin.X, origin.Y].active();
71 }
72
73 public override bool Place(Point origin, StructureMap structures)
74 {
75 if (GenBase._tiles[origin.X, origin.Y].active())
76 {
77 return false;
78 }
79 origin.X -= _sourceMagmaMap.GetLength(0) / 2;
80 origin.Y -= _sourceMagmaMap.GetLength(1) / 2;
81 BuildMagmaMap(origin);
86 structures.AddStructure(effectedMapArea, 8);
87 return true;
88 }
89
91 {
92 _sourceMagmaMap = new Magma[200, 200];
93 _targetMagmaMap = new Magma[200, 200];
94 for (int i = 0; i < _sourceMagmaMap.GetLength(0); i++)
95 {
96 for (int j = 0; j < _sourceMagmaMap.GetLength(1); j++)
97 {
98 int i2 = i + tileOrigin.X;
99 int j2 = j + tileOrigin.Y;
102 }
103 }
104 }
105
107 {
108 //IL_0072: Unknown result type (might be due to invalid IL or missing references)
109 //IL_0077: Unknown result type (might be due to invalid IL or missing references)
110 //IL_00a4: Unknown result type (might be due to invalid IL or missing references)
111 //IL_00a9: Unknown result type (might be due to invalid IL or missing references)
112 //IL_0157: Unknown result type (might be due to invalid IL or missing references)
113 //IL_015b: Unknown result type (might be due to invalid IL or missing references)
114 //IL_015d: Unknown result type (might be due to invalid IL or missing references)
115 //IL_0162: Unknown result type (might be due to invalid IL or missing references)
116 //IL_0167: Unknown result type (might be due to invalid IL or missing references)
117 int length = _sourceMagmaMap.GetLength(0);
118 int length2 = _sourceMagmaMap.GetLength(1);
119 int num = length / 2;
120 int num2 = length2 / 2;
121 int num3 = num;
122 int num4 = num3;
123 int num5 = num2;
124 int num6 = num5;
125 for (int i = 0; i < 300; i++)
126 {
127 for (int j = num3; j <= num4; j++)
128 {
129 for (int k = num5; k <= num6; k++)
130 {
132 if (!magma.IsActive)
133 {
134 continue;
135 }
136 double num7 = 0.0;
137 Vector2D val = Vector2D.Zero;
138 for (int l = -1; l <= 1; l++)
139 {
140 for (int m = -1; m <= 1; m++)
141 {
142 if (l == 0 && m == 0)
143 {
144 continue;
145 }
146 Vector2D val2 = _normalisedVectors[(l + 1) * 3 + (m + 1)];
147 Magma magma2 = _sourceMagmaMap[j + l, k + m];
148 if (magma.Pressure > 0.01 && !magma2.IsActive)
149 {
150 if (l == -1)
151 {
152 num3 = Utils.Clamp(j + l, 1, num3);
153 }
154 else
155 {
156 num4 = Utils.Clamp(j + l, num4, length - 2);
157 }
158 if (m == -1)
159 {
160 num5 = Utils.Clamp(k + m, 1, num5);
161 }
162 else
163 {
164 num6 = Utils.Clamp(k + m, num6, length2 - 2);
165 }
166 _targetMagmaMap[j + l, k + m] = magma2.ToFlow();
167 }
168 double pressure = magma2.Pressure;
169 num7 += pressure;
170 val += pressure * val2;
171 }
172 }
173 num7 /= 8.0;
174 if (num7 > magma.Resistance)
175 {
176 double num8 = ((Vector2D)(ref val)).Length() / 8.0;
177 double val3 = Math.Max(num7 - num8 - magma.Pressure, 0.0) + num8 + magma.Pressure * 0.875 - magma.Resistance;
178 val3 = Math.Max(0.0, val3);
179 _targetMagmaMap[j, k] = Magma.CreateFlow(val3, Math.Max(0.0, magma.Resistance - val3 * 0.02));
180 }
181 }
182 }
183 if (i < 2)
184 {
185 _targetMagmaMap[num, num2] = Magma.CreateFlow(25.0);
186 }
188 }
189 effectedMapArea = new Rectangle(num3, num5, num4 - num3 + 1, num6 - num5 + 1);
190 }
191
193 {
194 int length = _sourceMagmaMap.GetLength(0);
195 int length2 = _sourceMagmaMap.GetLength(1);
196 int num = length / 2;
197 int num2 = length2 / 2;
198 if (tileOrigin.Y + num2 <= GenVars.lavaLine - 30)
199 {
200 return false;
201 }
202 for (int i = -50; i < 50; i++)
203 {
204 for (int j = -50; j < 50; j++)
205 {
206 if (GenBase._tiles[tileOrigin.X + num + i, tileOrigin.Y + num2 + j].active())
207 {
208 ushort type = GenBase._tiles[tileOrigin.X + num + i, tileOrigin.Y + num2 + j].type;
209 if (type == 147 || (uint)(type - 161) <= 2u || type == 200)
210 {
211 return false;
212 }
213 }
214 }
215 }
216 return true;
217 }
218
220 {
221 bool flag = ShouldUseLava(tileOrigin);
222 ushort type = 368;
223 ushort wall = 180;
225 {
226 type = 367;
227 wall = 178;
228 }
229 for (int i = magmaMapArea.Left; i < magmaMapArea.Right; i++)
230 {
231 for (int j = magmaMapArea.Top; j < magmaMapArea.Bottom; j++)
232 {
234 if (!magma.IsActive)
235 {
236 continue;
237 }
238 Tile tile = GenBase._tiles[tileOrigin.X + i, tileOrigin.Y + j];
239 double num = Math.Sin((double)(tileOrigin.Y + j) * 0.4) * 0.7 + 1.2;
240 double num2 = 0.2 + 0.5 / Math.Sqrt(Math.Max(0.0, magma.Pressure - magma.Resistance));
241 if (Math.Max(1.0 - Math.Max(0.0, num * num2), magma.Pressure / 15.0) > 0.35 + (WorldGen.SolidTile(tileOrigin.X + i, tileOrigin.Y + j) ? 0.0 : 0.5))
242 {
243 if (TileID.Sets.Ore[tile.type])
244 {
245 tile.ResetToType(tile.type);
246 }
247 else
248 {
249 tile.ResetToType(type);
250 }
251 tile.wall = wall;
252 }
253 else if (magma.Resistance < 0.01)
254 {
256 tile.wall = wall;
257 }
258 if (tile.liquid > 0 && flag)
259 {
260 tile.liquidType(1);
261 }
262 }
263 }
264 }
265
267 {
268 ushort wall = 180;
270 {
271 wall = 178;
272 }
274 for (int i = magmaMapArea.Left; i < magmaMapArea.Right; i++)
275 {
276 for (int j = magmaMapArea.Top; j < magmaMapArea.Bottom; j++)
277 {
278 if (!_sourceMagmaMap[i, j].IsActive)
279 {
280 continue;
281 }
282 int num = 0;
283 int num2 = i + tileOrigin.X;
284 int num3 = j + tileOrigin.Y;
286 {
287 continue;
288 }
289 for (int k = -1; k <= 1; k++)
290 {
291 for (int l = -1; l <= 1; l++)
292 {
293 if (WorldGen.SolidTile(num2 + k, num3 + l))
294 {
295 num++;
296 }
297 }
298 }
299 if (num < 3)
300 {
301 list.Add(new Point16(num2, num3));
302 }
303 }
304 }
305 foreach (Point16 item in list)
306 {
307 int x = item.X;
308 int y = item.Y;
310 GenBase._tiles[x, y].wall = wall;
311 }
312 list.Clear();
313 }
314
316 {
318 for (int i = magmaMapArea.Left; i < magmaMapArea.Right; i++)
319 {
320 for (int j = magmaMapArea.Top; j < magmaMapArea.Bottom; j++)
321 {
323 int num = i + tileOrigin.X;
324 int num2 = j + tileOrigin.Y;
325 if (!magma.IsActive)
326 {
327 continue;
328 }
331 FastRandom fastRandom2 = fastRandom.WithModifier(num, num2);
332 if (fastRandom2.Next(8) == 0 && GenBase._tiles[num, num2].active())
333 {
334 if (!GenBase._tiles[num, num2 + 1].active())
335 {
336 WorldGen.PlaceUncheckedStalactite(num, num2 + 1, fastRandom2.Next(2) == 0, fastRandom2.Next(3), spiders: false);
337 }
338 if (!GenBase._tiles[num, num2 - 1].active())
339 {
340 WorldGen.PlaceUncheckedStalactite(num, num2 - 1, fastRandom2.Next(2) == 0, fastRandom2.Next(3), spiders: false);
341 }
342 }
343 if (fastRandom2.Next(2) == 0)
344 {
345 Tile.SmoothSlope(num, num2);
346 }
347 }
348 }
349 }
350}
static double Sqrt(double d)
static double Sin(double a)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
override bool Place(Point origin, StructureMap structures)
static bool CanPlace(Point origin, StructureMap structures)
void CleanupTiles(Point tileOrigin, Rectangle magmaMapArea)
void SimulatePressure(out Rectangle effectedMapArea)
void PlaceGranite(Point tileOrigin, Rectangle magmaMapArea)
void PlaceDecorations(Point tileOrigin, Rectangle magmaMapArea)
static bool[] Ore
Definition TileID.cs:295
static WorldFileData ActiveWorldFileData
Definition Main.cs:1946
static void SmoothSlope(int x, int y, bool applyToNeighbors=true, bool sync=false)
Definition Tile.cs:759
void liquidType(int liquidType)
Definition Tile.cs:233
byte liquid
Definition Tile.cs:12
void ResetToType(ushort type)
Definition Tile.cs:266
ushort type
Definition Tile.cs:8
void AddStructure(Rectangle area, int padding=0)
static void TileFrame(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:61
static void ClearTile(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:37
static bool BiomeTileCheck(int x, int y)
Definition WorldGen.cs:7113
static bool SolidTile(Tile testTile)
static void SquareWallFrame(int i, int j, bool resetFrame=true)
static void PlaceUncheckedStalactite(int x, int y, bool preferSmall, int variation, bool spiders)
static bool drunkWorldGen
Definition WorldGen.cs:1154
static Vector2D Zero
Definition Vector2D.cs:24
Magma(double pressure, double resistance, bool active)
static Magma CreateEmpty(double resistance=0.0)
static Magma CreateFlow(double pressure, double resistance=0.0)
FastRandom WithModifier(ulong modifier)
Definition FastRandom.cs:27