Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HiveBiome.cs
Go to the documentation of this file.
1using System;
6
8
9public class HiveBiome : MicroBiome
10{
11 public override bool Place(Point origin, StructureMap structures)
12 {
13 //IL_00ec: Unknown result type (might be due to invalid IL or missing references)
14 //IL_00f1: Unknown result type (might be due to invalid IL or missing references)
15 //IL_0139: Unknown result type (might be due to invalid IL or missing references)
16 //IL_013b: Unknown result type (might be due to invalid IL or missing references)
17 //IL_0150: Unknown result type (might be due to invalid IL or missing references)
18 //IL_0158: Unknown result type (might be due to invalid IL or missing references)
19 //IL_0165: Unknown result type (might be due to invalid IL or missing references)
20 //IL_016a: Unknown result type (might be due to invalid IL or missing references)
21 //IL_0178: Unknown result type (might be due to invalid IL or missing references)
22 //IL_017a: Unknown result type (might be due to invalid IL or missing references)
23 //IL_017f: Unknown result type (might be due to invalid IL or missing references)
24 //IL_018b: Unknown result type (might be due to invalid IL or missing references)
25 //IL_0247: Unknown result type (might be due to invalid IL or missing references)
26 //IL_0260: Unknown result type (might be due to invalid IL or missing references)
27 //IL_0262: Unknown result type (might be due to invalid IL or missing references)
28 //IL_0298: Unknown result type (might be due to invalid IL or missing references)
29 //IL_02a0: Unknown result type (might be due to invalid IL or missing references)
30 //IL_02b0: Unknown result type (might be due to invalid IL or missing references)
31 //IL_02b2: Unknown result type (might be due to invalid IL or missing references)
32 //IL_02c9: Unknown result type (might be due to invalid IL or missing references)
33 //IL_02d1: Unknown result type (might be due to invalid IL or missing references)
34 //IL_02ea: Unknown result type (might be due to invalid IL or missing references)
35 //IL_02f2: Unknown result type (might be due to invalid IL or missing references)
36 //IL_0308: Unknown result type (might be due to invalid IL or missing references)
37 if (!structures.CanPlace(new Rectangle(origin.X - 50, origin.Y - 50, 100, 100)))
38 {
39 return false;
40 }
42 {
43 return false;
44 }
45 Ref<int> @ref = new Ref<int>(0);
46 Ref<int> ref2 = new Ref<int>(0);
47 Ref<int> ref3 = new Ref<int>(0);
48 WorldUtils.Gen(origin, new Shapes.Circle(15), Actions.Chain(new Modifiers.IsSolid(), new Actions.Scanner(@ref), new Modifiers.OnlyTiles(60, 59), new Actions.Scanner(ref2), new Modifiers.OnlyTiles(60), new Actions.Scanner(ref3)));
49 if ((double)ref2.Value / (double)@ref.Value < 0.75 || ref3.Value < 2)
50 {
51 return false;
52 }
53 int num = 0;
54 int[] array = new int[1000];
55 int[] array2 = new int[1000];
56 Vector2D val = origin.ToVector2D();
57 int num2 = WorldGen.genRand.Next(2, 5);
59 {
60 num2 += WorldGen.genRand.Next(7, 10);
61 }
62 else if (WorldGen.remixWorldGen)
63 {
64 num2 += WorldGen.genRand.Next(2, 5);
65 }
66 for (int i = 0; i < num2; i++)
67 {
68 Vector2D val2 = val;
69 int num3 = WorldGen.genRand.Next(2, 5);
70 for (int j = 0; j < num3; j++)
71 {
72 val2 = CreateHiveTunnel((int)val.X, (int)val.Y, WorldGen.genRand);
73 }
74 val = val2;
75 array[num] = (int)val.X;
76 array2[num] = (int)val.Y;
77 num++;
78 }
79 FrameOutAllHiveContents(origin, 50);
80 for (int k = 0; k < num; k++)
81 {
82 int num4 = array[k];
83 int y = array2[k];
84 int num5 = 1;
85 if (WorldGen.genRand.Next(2) == 0)
86 {
87 num5 = -1;
88 }
89 bool flag = false;
90 while (WorldGen.InWorld(num4, y, 10) && BadSpotForHoneyFall(num4, y))
91 {
92 num4 += num5;
93 if (Math.Abs(num4 - array[k]) > 50)
94 {
95 flag = true;
96 break;
97 }
98 }
99 if (!flag)
100 {
101 num4 += num5;
102 if (!SpotActuallyNotInHive(num4, y))
103 {
104 CreateBlockedHoneyCube(num4, y);
105 CreateDentForHoneyFall(num4, y, num5);
106 }
107 }
108 }
111 {
112 for (int l = 0; l < 1000; l++)
113 {
114 Vector2D val3 = val;
115 val3.X += WorldGen.genRand.Next(-50, 51);
116 val3.Y += WorldGen.genRand.Next(-50, 51);
117 if (WorldGen.InWorld((int)val3.X, (int)val3.Y) && Vector2D.Distance(val, val3) > 10.0 && !Main.tile[(int)val3.X, (int)val3.Y].active() && Main.tile[(int)val3.X, (int)val3.Y].wall == 86)
118 {
120 break;
121 }
122 }
123 }
124 structures.AddProtectedStructure(new Rectangle(origin.X - 50, origin.Y - 50, 100, 100), 5);
125 return true;
126 }
127
128 private static void FrameOutAllHiveContents(Point origin, int squareHalfWidth)
129 {
130 int num = Math.Max(10, origin.X - squareHalfWidth);
131 int num2 = Math.Min(Main.maxTilesX - 10, origin.X + squareHalfWidth);
132 int num3 = Math.Max(10, origin.Y - squareHalfWidth);
133 int num4 = Math.Min(Main.maxTilesY - 10, origin.Y + squareHalfWidth);
134 for (int i = num; i < num2; i++)
135 {
136 for (int j = num3; j < num4; j++)
137 {
138 Tile tile = Main.tile[i, j];
139 if (tile.active() && tile.type == 225)
140 {
142 }
143 if (tile.wall == 86)
144 {
146 }
147 }
148 }
149 }
150
151 private static Vector2D CreateHiveTunnel(int i, int j, UnifiedRandom random)
152 {
153 //IL_052f: Unknown result type (might be due to invalid IL or missing references)
154 //IL_00cf: Unknown result type (might be due to invalid IL or missing references)
155 //IL_011b: Unknown result type (might be due to invalid IL or missing references)
156 //IL_0126: Unknown result type (might be due to invalid IL or missing references)
157 //IL_0131: Unknown result type (might be due to invalid IL or missing references)
158 //IL_013c: Unknown result type (might be due to invalid IL or missing references)
159 //IL_04bf: Unknown result type (might be due to invalid IL or missing references)
160 //IL_04c0: Unknown result type (might be due to invalid IL or missing references)
161 //IL_04c2: Unknown result type (might be due to invalid IL or missing references)
162 //IL_04c7: Unknown result type (might be due to invalid IL or missing references)
163 //IL_026b: Unknown result type (might be due to invalid IL or missing references)
164 //IL_027a: Unknown result type (might be due to invalid IL or missing references)
165 double num = random.Next(12, 21);
166 double num2 = random.Next(10, 21);
168 {
169 num = random.Next(8, 26);
170 num2 = random.Next(10, 41);
171 double num3 = (double)Main.maxTilesX / 4200.0;
172 num3 = (num3 + 1.0) / 2.0;
173 num *= num3;
174 num2 *= num3;
175 }
176 else if (WorldGen.remixWorldGen)
177 {
178 num += (double)random.Next(3);
179 }
180 double num4 = num;
181 Vector2D val = default(Vector2D);
182 val.X = i;
183 val.Y = j;
184 Vector2D val2 = default(Vector2D);
185 val2.X = (double)random.Next(-10, 11) * 0.2;
186 val2.Y = (double)random.Next(-10, 11) * 0.2;
187 while (num > 0.0 && num2 > 0.0)
188 {
189 if (val.Y > (double)(Main.maxTilesY - 250))
190 {
191 num2 = 0.0;
192 }
193 num = num4 * (1.0 + (double)random.Next(-20, 20) * 0.01);
194 num2 -= 1.0;
195 int num5 = (int)(val.X - num);
196 int num6 = (int)(val.X + num);
197 int num7 = (int)(val.Y - num);
198 int num8 = (int)(val.Y + num);
199 if (num5 < 1)
200 {
201 num5 = 1;
202 }
203 if (num6 > Main.maxTilesX - 1)
204 {
205 num6 = Main.maxTilesX - 1;
206 }
207 if (num7 < 1)
208 {
209 num7 = 1;
210 }
211 if (num8 > Main.maxTilesY - 1)
212 {
213 num8 = Main.maxTilesY - 1;
214 }
215 for (int k = num5; k < num6; k++)
216 {
217 for (int l = num7; l < num8; l++)
218 {
219 if (!WorldGen.InWorld(k, l, 50))
220 {
221 num2 = 0.0;
222 }
223 else
224 {
225 if (Main.tile[k - 10, l].wall == 87)
226 {
227 num2 = 0.0;
228 }
229 if (Main.tile[k + 10, l].wall == 87)
230 {
231 num2 = 0.0;
232 }
233 if (Main.tile[k, l - 10].wall == 87)
234 {
235 num2 = 0.0;
236 }
237 if (Main.tile[k, l + 10].wall == 87)
238 {
239 num2 = 0.0;
240 }
241 }
242 if ((double)l < Main.worldSurface && Main.tile[k, l - 5].wall == 0)
243 {
244 num2 = 0.0;
245 }
246 double num9 = Math.Abs((double)k - val.X);
247 double num10 = Math.Abs((double)l - val.Y);
248 double num11 = Math.Sqrt(num9 * num9 + num10 * num10);
249 if (num11 < num4 * 0.4 * (1.0 + (double)random.Next(-10, 11) * 0.005))
250 {
251 if (random.Next(3) == 0)
252 {
253 Main.tile[k, l].liquid = byte.MaxValue;
254 }
256 {
257 Main.tile[k, l].liquid = byte.MaxValue;
258 }
259 Main.tile[k, l].honey(honey: true);
260 Main.tile[k, l].wall = 86;
261 Main.tile[k, l].active(active: false);
262 Main.tile[k, l].halfBrick(halfBrick: false);
263 Main.tile[k, l].slope(0);
264 }
265 else if (num11 < num4 * 0.75 * (1.0 + (double)random.Next(-10, 11) * 0.005))
266 {
267 Main.tile[k, l].liquid = 0;
268 if (Main.tile[k, l].wall != 86)
269 {
270 Main.tile[k, l].active(active: true);
271 Main.tile[k, l].halfBrick(halfBrick: false);
272 Main.tile[k, l].slope(0);
273 Main.tile[k, l].type = 225;
274 }
275 }
276 if (num11 < num4 * 0.6 * (1.0 + (double)random.Next(-10, 11) * 0.005))
277 {
278 Main.tile[k, l].wall = 86;
279 if (WorldGen.drunkWorldGen && random.Next(2) == 0)
280 {
281 Main.tile[k, l].liquid = byte.MaxValue;
282 Main.tile[k, l].honey(honey: true);
283 }
284 }
285 }
286 }
287 val += val2;
288 num2 -= 1.0;
289 val2.Y += (double)random.Next(-10, 11) * 0.05;
290 val2.X += (double)random.Next(-10, 11) * 0.05;
291 }
292 return val;
293 }
294
295 private static bool TooCloseToImportantLocations(Point origin)
296 {
297 int x = origin.X;
298 int y = origin.Y;
299 int num = 150;
300 for (int i = x - num; i < x + num; i += 10)
301 {
302 if (i <= 0 || i > Main.maxTilesX - 1)
303 {
304 continue;
305 }
306 for (int j = y - num; j < y + num; j += 10)
307 {
308 if (j > 0 && j <= Main.maxTilesY - 1)
309 {
310 if (Main.tile[i, j].active() && Main.tile[i, j].type == 226)
311 {
312 return true;
313 }
314 if (Main.tile[i, j].wall == 83 || Main.tile[i, j].wall == 3 || Main.tile[i, j].wall == 87)
315 {
316 return true;
317 }
318 }
319 }
320 }
321 return false;
322 }
323
324 private static void CreateDentForHoneyFall(int x, int y, int dir)
325 {
326 dir *= -1;
327 y++;
328 int num = 0;
329 while ((num < 4 || WorldGen.SolidTile(x, y)) && x > 10 && x < Main.maxTilesX - 10)
330 {
331 num++;
332 x += dir;
333 if (WorldGen.SolidTile(x, y))
334 {
335 WorldGen.PoundTile(x, y);
336 if (!Main.tile[x, y + 1].active())
337 {
338 Main.tile[x, y + 1].active(active: true);
339 Main.tile[x, y + 1].type = 225;
340 }
341 }
342 }
343 }
344
345 private static void CreateBlockedHoneyCube(int x, int y)
346 {
347 for (int i = x - 1; i <= x + 2; i++)
348 {
349 for (int j = y - 1; j <= y + 2; j++)
350 {
351 if (i >= x && i <= x + 1 && j >= y && j <= y + 1)
352 {
353 Main.tile[i, j].active(active: false);
354 Main.tile[i, j].liquid = byte.MaxValue;
355 Main.tile[i, j].honey(honey: true);
356 }
357 else
358 {
359 Main.tile[i, j].active(active: true);
360 Main.tile[i, j].type = 225;
361 }
362 }
363 }
364 }
365
366 private static bool SpotActuallyNotInHive(int x, int y)
367 {
368 for (int i = x - 1; i <= x + 2; i++)
369 {
370 for (int j = y - 1; j <= y + 2; j++)
371 {
372 if (i < 10 || i > Main.maxTilesX - 10)
373 {
374 return true;
375 }
376 if (Main.tile[i, j].active() && Main.tile[i, j].type != 225)
377 {
378 return true;
379 }
380 }
381 }
382 return false;
383 }
384
385 private static bool BadSpotForHoneyFall(int x, int y)
386 {
387 if (Main.tile[x, y].active() && Main.tile[x, y + 1].active() && Main.tile[x + 1, y].active())
388 {
389 return !Main.tile[x + 1, y + 1].active();
390 }
391 return true;
392 }
393
394 public static void CreateStandForLarva(Vector2D position)
395 {
396 //IL_000a: Unknown result type (might be due to invalid IL or missing references)
397 //IL_0029: Unknown result type (might be due to invalid IL or missing references)
398 //IL_0066: Unknown result type (might be due to invalid IL or missing references)
399 //IL_006e: Unknown result type (might be due to invalid IL or missing references)
400 GenVars.larvaX[GenVars.numLarva] = Utils.Clamp((int)position.X, 5, Main.maxTilesX - 5);
401 GenVars.larvaY[GenVars.numLarva] = Utils.Clamp((int)position.Y, 5, Main.maxTilesY - 5);
403 if (GenVars.numLarva >= GenVars.larvaX.Length)
404 {
405 GenVars.numLarva = GenVars.larvaX.Length - 1;
406 }
407 int num = (int)position.X;
408 int num2 = (int)position.Y;
409 for (int i = num - 1; i <= num + 1 && i > 0 && i < Main.maxTilesX; i++)
410 {
411 for (int j = num2 - 2; j <= num2 + 1 && j > 0 && j < Main.maxTilesY; j++)
412 {
413 if (j != num2 + 1)
414 {
415 Main.tile[i, j].active(active: false);
416 continue;
417 }
418 Main.tile[i, j].active(active: true);
419 Main.tile[i, j].type = 225;
420 Main.tile[i, j].slope(0);
421 Main.tile[i, j].halfBrick(halfBrick: false);
422 }
423 }
424 }
425}
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Sqrt(double d)
static double Abs(double value)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static void CreateStandForLarva(Vector2D position)
Definition HiveBiome.cs:394
static void CreateDentForHoneyFall(int x, int y, int dir)
Definition HiveBiome.cs:324
static bool BadSpotForHoneyFall(int x, int y)
Definition HiveBiome.cs:385
static void FrameOutAllHiveContents(Point origin, int squareHalfWidth)
Definition HiveBiome.cs:128
static void CreateBlockedHoneyCube(int x, int y)
Definition HiveBiome.cs:345
static Vector2D CreateHiveTunnel(int i, int j, UnifiedRandom random)
Definition HiveBiome.cs:151
override bool Place(Point origin, StructureMap structures)
Definition HiveBiome.cs:11
static bool SpotActuallyNotInHive(int x, int y)
Definition HiveBiome.cs:366
static bool TooCloseToImportantLocations(Point origin)
Definition HiveBiome.cs:295
static int maxTilesY
Definition Main.cs:1116
static double worldSurface
Definition Main.cs:1272
static int maxTilesX
Definition Main.cs:1114
static Tile[,] tile
Definition Main.cs:1675
T Value
Definition Ref.cs:5
ushort type
Definition Tile.cs:8
bool active()
Definition Tile.cs:565
ushort wall
Definition Tile.cs:10
static GenAction Chain(params GenAction[] actions)
Definition Actions.cs:470
void AddProtectedStructure(Rectangle area, int padding=0)
bool CanPlace(Rectangle area, int padding=0)
static bool Gen(Point origin, GenShape shape, GenAction action)
Definition WorldUtils.cs:17
static bool remixWorldGen
Definition WorldGen.cs:1148
static bool SolidTile(Tile testTile)
static bool PoundTile(int i, int j)
static UnifiedRandom genRand
Definition WorldGen.cs:1215
static void SquareWallFrame(int i, int j, bool resetFrame=true)
static bool drunkWorldGen
Definition WorldGen.cs:1154
static bool InWorld(int x, int y, int fluff=0)
Definition WorldGen.cs:5816
static void SquareTileFrame(int i, int j, bool resetFrame=true)
static double Distance(Vector2D value1, Vector2D value2)
Definition Vector2D.cs:137