Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DesertHive.cs
Go to the documentation of this file.
1using System;
6
8
9public static class DesertHive
10{
11 private struct Block
12 {
14
15 public Block(double x, double y)
16 {
17 //IL_0003: Unknown result type (might be due to invalid IL or missing references)
18 //IL_0008: Unknown result type (might be due to invalid IL or missing references)
19 Position = new Vector2D(x, y);
20 }
21 }
22
23 private class Cluster : List<Block>
24 {
25 }
26
27 private class ClusterGroup : List<Cluster>
28 {
29 public readonly int Width;
30
31 public readonly int Height;
32
33 private ClusterGroup(int width, int height)
34 {
35 Width = width;
36 Height = height;
37 Generate();
38 }
39
41 {
42 return new ClusterGroup(description.BlockColumnCount, description.BlockRowCount);
43 }
44
45 private static void SearchForCluster(bool[,] blockMap, List<Point> pointCluster, int x, int y, int level = 2)
46 {
47 pointCluster.Add(new Point(x, y));
48 blockMap[x, y] = false;
49 level--;
50 if (level != -1)
51 {
52 if (x > 0 && blockMap[x - 1, y])
53 {
54 SearchForCluster(blockMap, pointCluster, x - 1, y, level);
55 }
56 if (x < blockMap.GetLength(0) - 1 && blockMap[x + 1, y])
57 {
58 SearchForCluster(blockMap, pointCluster, x + 1, y, level);
59 }
60 if (y > 0 && blockMap[x, y - 1])
61 {
62 SearchForCluster(blockMap, pointCluster, x, y - 1, level);
63 }
64 if (y < blockMap.GetLength(1) - 1 && blockMap[x, y + 1])
65 {
66 SearchForCluster(blockMap, pointCluster, x, y + 1, level);
67 }
68 }
69 }
70
71 private static void AttemptClaim(int x, int y, int[,] clusterIndexMap, List<List<Point>> pointClusters, int index)
72 {
73 int num = clusterIndexMap[x, y];
74 if (num == -1 || num == index)
75 {
76 return;
77 }
78 int num2 = ((WorldGen.genRand.Next(2) == 0) ? (-1) : index);
79 foreach (Point item in pointClusters[num])
80 {
82 }
83 }
84
85 private void Generate()
86 {
87 Clear();
88 bool[,] array = new bool[Width, Height];
89 int num = Width / 2 - 1;
90 int num2 = Height / 2 - 1;
91 int num3 = (num + 1) * (num + 1);
92 Point point = new Point(num, num2);
93 for (int i = point.Y - num2; i <= point.Y + num2; i++)
94 {
95 double num4 = (double)num / (double)num2 * (double)(i - point.Y);
96 int num5 = Math.Min(num, (int)Math.Sqrt((double)num3 - num4 * num4));
97 for (int j = point.X - num5; j <= point.X + num5; j++)
98 {
99 array[j, i] = WorldGen.genRand.Next(2) == 0;
100 }
101 }
103 for (int k = 0; k < array.GetLength(0); k++)
104 {
105 for (int l = 0; l < array.GetLength(1); l++)
106 {
107 if (array[k, l] && WorldGen.genRand.Next(2) == 0)
108 {
111 if (list2.Count > 2)
112 {
113 list.Add(list2);
114 }
115 }
116 }
117 }
118 int[,] array2 = new int[array.GetLength(0), array.GetLength(1)];
119 for (int m = 0; m < array2.GetLength(0); m++)
120 {
121 for (int n = 0; n < array2.GetLength(1); n++)
122 {
123 array2[m, n] = -1;
124 }
125 }
126 for (int num6 = 0; num6 < list.Count; num6++)
127 {
128 foreach (Point item in list[num6])
129 {
130 array2[item.X, item.Y] = num6;
131 }
132 }
133 for (int num7 = 0; num7 < list.Count; num7++)
134 {
135 foreach (Point item2 in list[num7])
136 {
137 int x = item2.X;
138 int y = item2.Y;
139 if (array2[x, y] == -1)
140 {
141 break;
142 }
143 int index = array2[x, y];
144 if (x > 0)
145 {
146 AttemptClaim(x - 1, y, array2, list, index);
147 }
148 if (x < array2.GetLength(0) - 1)
149 {
150 AttemptClaim(x + 1, y, array2, list, index);
151 }
152 if (y > 0)
153 {
154 AttemptClaim(x, y - 1, array2, list, index);
155 }
156 if (y < array2.GetLength(1) - 1)
157 {
158 AttemptClaim(x, y + 1, array2, list, index);
159 }
160 }
161 }
162 foreach (List<Point> item3 in list)
163 {
164 item3.Clear();
165 }
166 for (int num8 = 0; num8 < array2.GetLength(0); num8++)
167 {
168 for (int num9 = 0; num9 < array2.GetLength(1); num9++)
169 {
170 if (array2[num8, num9] != -1)
171 {
172 list[array2[num8, num9]].Add(new Point(num8, num9));
173 }
174 }
175 }
176 foreach (List<Point> item4 in list)
177 {
178 if (item4.Count < 4)
179 {
180 item4.Clear();
181 }
182 }
183 foreach (List<Point> item5 in list)
184 {
185 Cluster cluster = new Cluster();
186 if (item5.Count <= 0)
187 {
188 continue;
189 }
190 foreach (Point item6 in item5)
191 {
192 cluster.Add(new Block((double)item6.X + (WorldGen.genRand.NextDouble() - 0.5) * 0.5, (double)item6.Y + (WorldGen.genRand.NextDouble() - 0.5) * 0.5));
193 }
194 Add(cluster);
195 }
196 }
197 }
198
199 [Flags]
200 private enum PostPlacementEffect : byte
201 {
202 None = 0,
203 Smooth = 1
204 }
205
206 public static void Place(DesertDescription description)
207 {
209 PlaceClusters(description, clusters);
210 AddTileVariance(description);
211 }
212
213 private static void PlaceClusters(DesertDescription description, ClusterGroup clusters)
214 {
215 Rectangle hive = description.Hive;
216 hive.Inflate(20, 20);
217 PostPlacementEffect[,] array = new PostPlacementEffect[hive.Width, hive.Height];
219 for (int i = hive.Left; i < hive.Right; i++)
220 {
221 for (int j = hive.Top; j < hive.Bottom; j++)
222 {
224 if (postPlacementEffect.HasFlag(PostPlacementEffect.Smooth))
225 {
227 }
228 }
229 }
230 }
231
233 {
234 //IL_0054: Unknown result type (might be due to invalid IL or missing references)
235 //IL_0062: Unknown result type (might be due to invalid IL or missing references)
236 //IL_0067: Unknown result type (might be due to invalid IL or missing references)
237 //IL_00fc: Unknown result type (might be due to invalid IL or missing references)
238 //IL_0101: Unknown result type (might be due to invalid IL or missing references)
239 //IL_0102: Unknown result type (might be due to invalid IL or missing references)
240 //IL_0107: Unknown result type (might be due to invalid IL or missing references)
241 //IL_0108: Unknown result type (might be due to invalid IL or missing references)
242 //IL_010d: Unknown result type (might be due to invalid IL or missing references)
243 //IL_010e: Unknown result type (might be due to invalid IL or missing references)
244 //IL_0113: Unknown result type (might be due to invalid IL or missing references)
245 //IL_012f: Unknown result type (might be due to invalid IL or missing references)
246 //IL_0139: Unknown result type (might be due to invalid IL or missing references)
247 //IL_0227: Unknown result type (might be due to invalid IL or missing references)
248 //IL_022c: Unknown result type (might be due to invalid IL or missing references)
249 //IL_022d: Unknown result type (might be due to invalid IL or missing references)
250 //IL_0232: Unknown result type (might be due to invalid IL or missing references)
251 //IL_0233: Unknown result type (might be due to invalid IL or missing references)
252 //IL_0241: Unknown result type (might be due to invalid IL or missing references)
253 //IL_0246: Unknown result type (might be due to invalid IL or missing references)
254 //IL_024b: Unknown result type (might be due to invalid IL or missing references)
255 //IL_0250: Unknown result type (might be due to invalid IL or missing references)
256 //IL_015c: Unknown result type (might be due to invalid IL or missing references)
257 //IL_0166: Unknown result type (might be due to invalid IL or missing references)
258 //IL_01aa: Unknown result type (might be due to invalid IL or missing references)
259 //IL_01af: Unknown result type (might be due to invalid IL or missing references)
261 Vector2D val = default(Vector2D);
262 ((Vector2D)(ref val))._002Ector((double)description.Hive.Width, (double)description.Hive.Height);
263 Vector2D val2 = default(Vector2D);
264 ((Vector2D)(ref val2))._002Ector((double)clusters.Width, (double)clusters.Height);
265 Vector2D val3 = description.BlockScale / 2.0;
266 for (int i = area.Left; i < area.Right; i++)
267 {
268 for (int j = area.Top; j < area.Bottom; j++)
269 {
270 byte liquid = Main.tile[i, j].liquid;
271 if (!WorldGen.InWorld(i, j, 1))
272 {
273 continue;
274 }
275 double num = 0.0;
276 int num2 = -1;
277 double num3 = 0.0;
278 ushort type = 53;
279 if (fastRandom.Next(3) == 0)
280 {
281 type = 397;
282 }
283 int num4 = i - description.Hive.X;
284 int num5 = j - description.Hive.Y;
285 Vector2D val4 = (new Vector2D((double)num4, (double)num5) - val3) / val * val2;
286 for (int k = 0; k < clusters.Count; k++)
287 {
289 if (Math.Abs(cluster[0].Position.X - val4.X) > 10.0 || Math.Abs(cluster[0].Position.Y - val4.Y) > 10.0)
290 {
291 continue;
292 }
293 double num6 = 0.0;
294 foreach (Block item in cluster)
295 {
296 num6 += 1.0 / Vector2D.DistanceSquared(item.Position, val4);
297 }
298 if (num6 > num)
299 {
300 if (num > num3)
301 {
302 num3 = num;
303 }
304 num = num6;
305 num2 = k;
306 }
307 else if (num6 > num3)
308 {
309 num3 = num6;
310 }
311 }
312 double num7 = num + num3;
313 Tile tile = Main.tile[i, j];
314 Vector2D val5 = (new Vector2D((double)num4, (double)num5) - val3) / val * 2.0 - Vector2D.One;
315 bool flag = ((Vector2D)(ref val5)).Length() >= 0.8;
317 bool flag2 = true;
318 if (num7 > 3.5)
319 {
321 tile.ClearEverything();
322 if (!WorldGen.remixWorldGen || !((double)j > Main.rockLayer + (double)WorldGen.genRand.Next(-1, 2)))
323 {
324 tile.wall = 187;
325 if (num2 % 15 == 2)
326 {
327 tile.ResetToType(404);
328 }
329 }
330 }
331 else if (num7 > 1.8)
332 {
333 if (!WorldGen.remixWorldGen || !((double)j > Main.rockLayer + (double)WorldGen.genRand.Next(-1, 2)))
334 {
335 tile.wall = 187;
336 }
337 if ((double)j < Main.worldSurface)
338 {
339 tile.liquid = 0;
340 }
341 else if (!WorldGen.remixWorldGen)
342 {
343 tile.lava(lava: true);
344 }
345 if (!flag || tile.active())
346 {
347 tile.ResetToType(396);
349 }
350 }
351 else if (num7 > 0.7 || !flag)
352 {
353 if (!WorldGen.remixWorldGen || !((double)j > Main.rockLayer + (double)WorldGen.genRand.Next(-1, 2)))
354 {
355 tile.wall = 216;
356 tile.liquid = 0;
357 }
358 if (!flag || tile.active())
359 {
360 tile.ResetToType(type);
362 }
363 }
364 else if (num7 > 0.25)
365 {
366 FastRandom fastRandom2 = fastRandom.WithModifier(num4, num5);
367 double num8 = (num7 - 0.25) / 0.45;
368 if (fastRandom2.NextDouble() < num8)
369 {
370 if (!WorldGen.remixWorldGen || !((double)j > Main.rockLayer + (double)WorldGen.genRand.Next(-1, 2)))
371 {
372 tile.wall = 187;
373 }
374 if ((double)j < Main.worldSurface)
375 {
376 tile.liquid = 0;
377 }
378 else if (!WorldGen.remixWorldGen)
379 {
380 tile.lava(lava: true);
381 }
382 if (tile.active())
383 {
384 tile.ResetToType(type);
386 }
387 }
388 }
389 else
390 {
391 flag2 = false;
392 }
393 if (flag2)
394 {
396 }
399 {
400 Main.tile[i, j].liquid = liquid;
401 }
402 }
403 }
404 }
405
406 private static void AddTileVariance(DesertDescription description)
407 {
408 for (int i = -20; i < description.Hive.Width + 20; i++)
409 {
410 for (int j = -20; j < description.Hive.Height + 20; j++)
411 {
412 int num = i + description.Hive.X;
413 int num2 = j + description.Hive.Y;
414 if (WorldGen.InWorld(num, num2, 1))
415 {
416 Tile tile = Main.tile[num, num2];
417 Tile testTile = Main.tile[num, num2 + 1];
418 Tile testTile2 = Main.tile[num, num2 + 2];
419 if (tile.type == 53 && (!WorldGen.SolidTile(testTile) || !WorldGen.SolidTile(testTile2)))
420 {
421 tile.type = 397;
422 }
423 }
424 }
425 }
426 for (int k = -20; k < description.Hive.Width + 20; k++)
427 {
428 for (int l = -20; l < description.Hive.Height + 20; l++)
429 {
430 int num3 = k + description.Hive.X;
431 int num4 = l + description.Hive.Y;
432 if (!WorldGen.InWorld(num3, num4, 1))
433 {
434 continue;
435 }
437 if (!tile2.active() || tile2.type != 396)
438 {
439 continue;
440 }
441 bool flag = true;
442 for (int num5 = -1; num5 >= -3; num5--)
443 {
444 if (Main.tile[num3, num4 + num5].active())
445 {
446 flag = false;
447 break;
448 }
449 }
450 bool flag2 = true;
451 for (int m = 1; m <= 3; m++)
452 {
453 if (Main.tile[num3, num4 + m].active())
454 {
455 flag2 = false;
456 break;
457 }
458 }
459 if (!WorldGen.remixWorldGen || !((double)num4 > Main.rockLayer + (double)WorldGen.genRand.Next(-1, 2)))
460 {
461 if (flag && WorldGen.genRand.Next(20) == 0)
462 {
463 WorldGen.PlaceTile(num3, num4 - 1, 485, mute: true, forced: true, -1, WorldGen.genRand.Next(4));
464 }
465 else if (flag && WorldGen.genRand.Next(5) == 0)
466 {
467 WorldGen.PlaceTile(num3, num4 - 1, 484, mute: true, forced: true);
468 }
469 else if ((flag ^ flag2) && WorldGen.genRand.Next(5) == 0)
470 {
471 WorldGen.PlaceTile(num3, num4 + ((!flag) ? 1 : (-1)), 165, mute: true, forced: true);
472 }
473 else if (flag && WorldGen.genRand.Next(5) == 0)
474 {
475 WorldGen.PlaceTile(num3, num4 - 1, 187, mute: true, forced: true, -1, 29 + WorldGen.genRand.Next(6));
476 }
477 }
478 }
479 }
480 }
481}
void Add(TKey key, TValue value)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Sqrt(double d)
static double Abs(double value)
static void SearchForCluster(bool[,] blockMap, List< Point > pointCluster, int x, int y, int level=2)
Definition DesertHive.cs:45
static ClusterGroup FromDescription(DesertDescription description)
Definition DesertHive.cs:40
static void AttemptClaim(int x, int y, int[,] clusterIndexMap, List< List< Point > > pointClusters, int index)
Definition DesertHive.cs:71
static void Place(DesertDescription description)
static void PlaceClustersArea(DesertDescription description, ClusterGroup clusters, Rectangle area, PostPlacementEffect[,] postEffectMap, Point postEffectMapOffset)
static void PlaceClusters(DesertDescription description, ClusterGroup clusters)
static void AddTileVariance(DesertDescription description)
static WorldFileData ActiveWorldFileData
Definition Main.cs:1946
static double worldSurface
Definition Main.cs:1272
static double rockLayer
Definition Main.cs:1274
static Tile[,] tile
Definition Main.cs:1675
static void SmoothSlope(int x, int y, bool applyToNeighbors=true, bool sync=false)
Definition Tile.cs:759
void ResetToType(ushort type)
Definition Tile.cs:266
ushort type
Definition Tile.cs:8
bool active()
Definition Tile.cs:565
void ClearEverything()
Definition Tile.cs:138
bool lava()
Definition Tile.cs:362
static bool remixWorldGen
Definition WorldGen.cs:1148
static bool SolidTile(Tile testTile)
static bool PlaceTile(int i, int j, int Type, bool mute=false, bool forced=false, int plr=-1, int style=0)
static UnifiedRandom genRand
Definition WorldGen.cs:1215
static void UpdateDesertHiveBounds(int x, int y)
Definition WorldGen.cs:7155
static bool InWorld(int x, int y, int fluff=0)
Definition WorldGen.cs:5816
static double DistanceSquared(Vector2D value1, Vector2D value2)
Definition Vector2D.cs:151
static Vector2D One
Definition Vector2D.cs:26
FastRandom WithModifier(ulong modifier)
Definition FastRandom.cs:27