Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ placeTrap()

static bool Terraria.WorldGen.placeTrap ( int x2,
int y2,
int type = -1 )
inlinestatic

Definition at line 5155 of file WorldGen.cs.

5156 {
5157 //IL_0008: Unknown result type (might be due to invalid IL or missing references)
5158 //IL_000d: Unknown result type (might be due to invalid IL or missing references)
5159 int num = y2;
5160 if (Vector2D.Distance(new Vector2D((double)x2, (double)y2), GenVars.shimmerPosition) < 100.0)
5161 {
5162 return false;
5163 }
5164 bool flag = false;
5165 bool flag2 = false;
5166 if (noTrapsWorldGen)
5167 {
5168 Main.tileSolid[138] = false;
5169 }
5170 while (!SolidTile(x2, num))
5171 {
5172 num++;
5173 if (num > Main.maxTilesY - 10)
5174 {
5175 return false;
5176 }
5177 if (num >= Main.maxTilesY - 300)
5178 {
5179 flag2 = true;
5180 }
5181 }
5182 if (noTrapsWorldGen)
5183 {
5184 Main.tileSolid[138] = true;
5185 }
5186 num--;
5187 if (!noTrapsWorldGen && IsTileNearby(x2, num, 70, 20))
5188 {
5189 return false;
5190 }
5191 if (Main.tile[x2, num].wall == 87)
5192 {
5193 return false;
5194 }
5195 if (Main.tile[x2, num].liquid > 0 && Main.tile[x2, num].lava())
5196 {
5197 flag = true;
5198 }
5199 if (Main.remixWorld)
5200 {
5201 if (type == -1 && genRand.Next(20) == 0)
5202 {
5203 type = 2;
5204 }
5205 else if (type == -1 && (double)num < Main.rockLayer - 30.0 && genRand.Next(3) != 0)
5206 {
5207 type = 3;
5208 }
5209 else if (type == -1)
5210 {
5211 type = genRand.Next(2);
5212 }
5213 }
5214 else if (type == -1 && genRand.Next(20) == 0)
5215 {
5216 type = 2;
5217 }
5218 else if (type == -1 && num > GenVars.lavaLine + 30 && genRand.Next(6) != 0)
5219 {
5220 type = 3;
5221 }
5222 else if (type == -1)
5223 {
5224 type = genRand.Next(2);
5225 }
5226 if (!InWorld(x2, num, 3))
5227 {
5228 return false;
5229 }
5230 if (flag && type != 3)
5231 {
5232 return false;
5233 }
5234 if (flag2 && type != 3)
5235 {
5236 return false;
5237 }
5238 if (Main.tile[x2, num].nactive() || Main.tile[x2 - 1, num].nactive() || Main.tile[x2 + 1, num].nactive() || Main.tile[x2, num - 1].nactive() || Main.tile[x2 - 1, num - 1].nactive() || Main.tile[x2 + 1, num - 1].nactive() || Main.tile[x2, num - 2].nactive() || Main.tile[x2 - 1, num - 2].nactive() || Main.tile[x2 + 1, num - 2].nactive())
5239 {
5240 return false;
5241 }
5242 if (Main.tile[x2, num + 1].type == 48)
5243 {
5244 return false;
5245 }
5246 if (Main.tile[x2, num + 1].type == 232)
5247 {
5248 return false;
5249 }
5250 if (type == 1)
5251 {
5252 for (int i = x2 - 3; i <= x2 + 3; i++)
5253 {
5254 for (int j = num - 3; j <= num + 3; j++)
5255 {
5256 if (Main.tile[i, j].type == 147 || Main.tile[i, j].type == 161)
5257 {
5258 type = 0;
5259 }
5260 }
5261 }
5262 }
5263 if (noTrapsWorldGen)
5264 {
5265 Main.tileSolid[138] = false;
5266 }
5267 switch (type)
5268 {
5269 case 0:
5270 {
5271 int num20 = x2;
5272 int num21 = num;
5273 num21 -= genRand.Next(3);
5274 while (!SolidTile(num20, num21) && !Main.tileCracked[Main.tile[num20, num21].type])
5275 {
5276 num20--;
5277 if (num20 < 0)
5278 {
5279 return false;
5280 }
5281 }
5282 int num22 = num20;
5283 num20 = x2;
5284 while (!SolidTile(num20, num21) && !Main.tileCracked[Main.tile[num20, num21].type])
5285 {
5286 num20++;
5287 if (num20 > Main.maxTilesX)
5288 {
5289 return false;
5290 }
5291 }
5292 int num23 = num20;
5293 int num24 = x2 - num22;
5294 int num25 = num23 - x2;
5295 bool flag5 = false;
5296 bool flag6 = false;
5297 if (num24 > 5 && num24 < 50)
5298 {
5299 flag5 = true;
5300 }
5301 if (num25 > 5 && num25 < 50)
5302 {
5303 flag6 = true;
5304 }
5305 if (flag5 && !SolidTile(num22, num21 + 1))
5306 {
5307 flag5 = false;
5308 }
5309 if (flag6 && !SolidTile(num23, num21 + 1))
5310 {
5311 flag6 = false;
5312 }
5313 if (flag5 && (Main.tile[num22, num21].type == 10 || Main.tile[num22, num21].type == 48 || Main.tile[num22, num21 + 1].type == 10 || Main.tile[num22, num21 + 1].type == 48))
5314 {
5315 flag5 = false;
5316 }
5317 if (flag6 && (Main.tile[num23, num21].type == 10 || Main.tile[num23, num21].type == 48 || Main.tile[num23, num21 + 1].type == 10 || Main.tile[num23, num21 + 1].type == 48))
5318 {
5319 flag6 = false;
5320 }
5321 int num26 = 0;
5322 if (flag5 && flag6)
5323 {
5324 num26 = 1;
5325 num20 = num22;
5326 if (genRand.Next(2) == 0)
5327 {
5328 num20 = num23;
5329 num26 = -1;
5330 }
5331 }
5332 else if (flag6)
5333 {
5334 num20 = num23;
5335 num26 = -1;
5336 }
5337 else
5338 {
5339 if (!flag5)
5340 {
5341 trapDiag[type, 0]++;
5342 return false;
5343 }
5344 num20 = num22;
5345 num26 = 1;
5346 }
5347 if (Main.tile[num20, num21].type == 190)
5348 {
5349 trapDiag[type, 0]++;
5350 return false;
5351 }
5352 if (Main.tile[x2, num].wall > 0)
5353 {
5354 PlaceTile(x2, num, 135, mute: true, forced: true, -1, 2);
5355 }
5356 else
5357 {
5358 PlaceTile(x2, num, 135, mute: true, forced: true, -1, genRand.Next(2, 4));
5359 }
5362 if (num26 == 1)
5363 {
5364 Main.tile[num20, num21].frameX += 18;
5365 }
5366 int num27 = x2;
5367 int num28 = num;
5368 while (num27 != num20 || num28 != num21)
5369 {
5370 Main.tile[num27, num28].wire(wire: true);
5371 if (num27 > num20)
5372 {
5373 num27--;
5374 }
5375 if (num27 < num20)
5376 {
5377 num27++;
5378 }
5379 Main.tile[num27, num28].wire(wire: true);
5380 if (num28 > num21)
5381 {
5382 num28--;
5383 }
5384 if (num28 < num21)
5385 {
5386 num28++;
5387 }
5388 Main.tile[num27, num28].wire(wire: true);
5389 }
5390 trapDiag[type, 1]++;
5391 return true;
5392 }
5393 case 1:
5394 {
5395 if (noTrapsWorldGen)
5396 {
5397 Main.tileSolid[138] = true;
5398 }
5399 int num3 = x2;
5400 int num4 = num - 8;
5401 num3 += genRand.Next(-1, 2);
5402 if (noTrapsWorldGen)
5403 {
5404 if (IsTileNearby(num3, num4, 138, 6))
5405 {
5406 return false;
5407 }
5408 if (IsTileNearby(num3, num4, 664, 6))
5409 {
5410 return false;
5411 }
5412 }
5413 else
5414 {
5415 if (IsTileNearby(num3, num4, 138, 10))
5416 {
5417 return false;
5418 }
5419 if (IsTileNearby(num3, num4, 664, 10))
5420 {
5421 return false;
5422 }
5423 if (IsTileNearby(num3, num4, 665, 10))
5424 {
5425 return false;
5426 }
5427 }
5428 bool flag3 = true;
5429 while (flag3)
5430 {
5431 bool flag4 = true;
5432 int num5 = 0;
5433 for (int m = num3 - 2; m <= num3 + 3; m++)
5434 {
5435 for (int n = num4; n <= num4 + 3; n++)
5436 {
5437 if (!SolidTile(m, n))
5438 {
5439 flag4 = false;
5440 }
5441 if (Main.tile[m, n].active())
5442 {
5443 if (Main.tile[m, n].type == 226)
5444 {
5445 trapDiag[type, 0]++;
5446 return false;
5447 }
5448 if (Main.tile[m, n].type == 0 || Main.tile[m, n].type == 1 || Main.tile[m, n].type == 59)
5449 {
5450 num5++;
5451 }
5452 }
5453 }
5454 }
5455 num4--;
5456 if ((double)num4 < Main.worldSurface)
5457 {
5458 trapDiag[type, 0]++;
5459 return false;
5460 }
5461 if (flag4 && num5 > 2)
5462 {
5463 flag3 = false;
5464 }
5465 }
5466 if (num - num4 <= 5 || num - num4 >= 40)
5467 {
5468 trapDiag[type, 0]++;
5469 return false;
5470 }
5471 for (int num6 = num3; num6 <= num3 + 1; num6++)
5472 {
5473 for (int num7 = num4; num7 <= num; num7++)
5474 {
5475 KillTile(num6, num7);
5476 }
5477 }
5478 for (int num8 = num3 - 2; num8 <= num3 + 3; num8++)
5479 {
5480 for (int num9 = num4 - 2; num9 <= num4 + 3; num9++)
5481 {
5482 if (SolidTile(num8, num9))
5483 {
5484 Main.tile[num8, num9].type = 1;
5485 }
5486 }
5487 }
5488 if (IsTileNearby(num3, num4, 21, 4) || IsTileNearby(num3, num4, 467, 4))
5489 {
5490 trapDiag[type, 0]++;
5491 return false;
5492 }
5493 PlaceTile(x2, num, 135, mute: true, forced: true, -1, 7);
5494 PlaceTile(num3, num4 + 2, 130, mute: true);
5495 PlaceTile(num3 + 1, num4 + 2, 130, mute: true);
5496 if ((tenthAnniversaryWorldGen || noTrapsWorldGen) && genRand.Next(3) == 0)
5497 {
5498 PlaceTile(num3 + 1, num4 + 1, 664, mute: true);
5499 }
5500 else
5501 {
5502 PlaceTile(num3 + 1, num4 + 1, 138, mute: true);
5503 }
5504 num4 += 2;
5505 Main.tile[num3, num4].wire(wire: true);
5506 Main.tile[num3 + 1, num4].wire(wire: true);
5507 num4++;
5508 PlaceTile(num3, num4, 130, mute: true);
5509 PlaceTile(num3 + 1, num4, 130, mute: true);
5510 Main.tile[num3, num4].wire(wire: true);
5511 Main.tile[num3 + 1, num4].wire(wire: true);
5512 PlaceTile(num3, num4 + 1, 130, mute: true);
5513 PlaceTile(num3 + 1, num4 + 1, 130, mute: true);
5514 Main.tile[num3, num4 + 1].wire(wire: true);
5515 Main.tile[num3 + 1, num4 + 1].wire(wire: true);
5516 int num10 = x2;
5517 int num11 = num;
5518 while (num10 != num3 || num11 != num4)
5519 {
5520 Main.tile[num10, num11].wire(wire: true);
5521 if (num10 > num3)
5522 {
5523 num10--;
5524 }
5525 if (num10 < num3)
5526 {
5527 num10++;
5528 }
5529 Main.tile[num10, num11].wire(wire: true);
5530 if (num11 > num4)
5531 {
5532 num11--;
5533 }
5534 if (num11 < num4)
5535 {
5536 num11++;
5537 }
5538 Main.tile[num10, num11].wire(wire: true);
5539 }
5540 trapDiag[type, 1]++;
5541 return true;
5542 }
5543 case 2:
5544 {
5545 int num12 = genRand.Next(4, 7);
5546 int num13 = x2;
5547 num13 += genRand.Next(-1, 2);
5548 int num14 = num;
5549 for (int num15 = 0; num15 < num12; num15++)
5550 {
5551 num14++;
5552 if (!SolidTile(num13, num14))
5553 {
5554 trapDiag[type, 0]++;
5555 return false;
5556 }
5557 }
5558 for (int num16 = num13 - 2; num16 <= num13 + 2; num16++)
5559 {
5560 for (int num17 = num14 - 2; num17 <= num14 + 2; num17++)
5561 {
5562 if (!SolidTile(num16, num17))
5563 {
5564 return false;
5565 }
5566 }
5567 }
5569 Main.tile[num13, num14].active(active: true);
5570 Main.tile[num13, num14].type = 141;
5571 Main.tile[num13, num14].frameX = 0;
5572 Main.tile[num13, num14].frameY = (short)(18 * genRand.Next(2));
5573 PlaceTile(x2, num, 135, mute: true, forced: true, -1, genRand.Next(2, 4));
5574 int num18 = x2;
5575 int num19 = num;
5576 while (num18 != num13 || num19 != num14)
5577 {
5578 Main.tile[num18, num19].wire(wire: true);
5579 if (num18 > num13)
5580 {
5581 num18--;
5582 }
5583 if (num18 < num13)
5584 {
5585 num18++;
5586 }
5587 Main.tile[num18, num19].wire(wire: true);
5588 if (num19 > num14)
5589 {
5590 num19--;
5591 }
5592 if (num19 < num14)
5593 {
5594 num19++;
5595 }
5596 Main.tile[num18, num19].wire(wire: true);
5597 }
5598 trapDiag[type, 1]++;
5599 break;
5600 }
5601 case 3:
5602 {
5603 if (Main.tile[x2 + 1, num].active())
5604 {
5605 return false;
5606 }
5607 if (Main.tile[x2, num].liquid > 0 && !Main.tile[x2, num].lava())
5608 {
5609 return false;
5610 }
5612 {
5613 if (genRand.Next(3) != 0)
5614 {
5615 return false;
5616 }
5617 if (IsTileNearby(x2, num, 443, 30))
5618 {
5619 return false;
5620 }
5621 }
5622 for (int k = x2; k <= x2 + 1; k++)
5623 {
5624 int j2 = num + 1;
5625 if (!SolidTile(k, j2))
5626 {
5627 return false;
5628 }
5629 }
5630 int num2 = genRand.Next(2);
5631 for (int l = 0; l < 2; l++)
5632 {
5633 Main.tile[x2 + l, num].active(active: true);
5634 Main.tile[x2 + l, num].type = 443;
5635 Main.tile[x2 + l, num].frameX = (short)(18 * l + 36 * num2);
5636 Main.tile[x2 + l, num].frameY = 0;
5637 }
5638 return true;
5639 }
5640 }
5641 if (noTrapsWorldGen)
5642 {
5643 Main.tileSolid[138] = true;
5644 }
5645 return false;
5646 }
static Vector2D shimmerPosition
Definition GenVars.cs:310
static int[,] trapDiag
Definition WorldGen.cs:1124
static void KillTile(int i, int j, bool fail=false, bool effectOnly=false, bool noItem=false)
static bool noTrapsWorldGen
Definition WorldGen.cs:1152
static bool PlaceTile(int i, int j, int Type, bool mute=false, bool forced=false, int plr=-1, int style=0)
static bool tenthAnniversaryWorldGen
Definition WorldGen.cs:1160
static UnifiedRandom genRand
Definition WorldGen.cs:1215
static bool InWorld(int x, int y, int fluff=0)
Definition WorldGen.cs:5816
static bool notTheBees
Definition WorldGen.cs:1164
static bool IsTileNearby(int x, int y, int type, int distance)
Definition WorldGen.cs:5117
static double Distance(Vector2D value1, Vector2D value2)
Definition Vector2D.cs:137

References ReLogic.Utilities.Vector2D.Distance(), Terraria.WorldGen.genRand, Terraria.WorldGen.InWorld(), Terraria.WorldGen.IsTileNearby(), Terraria.WorldGen.KillTile(), Terraria.WorldBuilding.GenVars.lavaLine, Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.WorldGen.noTrapsWorldGen, Terraria.WorldGen.notTheBees, Terraria.WorldGen.PlaceTile(), Terraria.Main.remixWorld, Terraria.Main.rockLayer, Terraria.WorldBuilding.GenVars.shimmerPosition, Terraria.Enums.SolidTile, Terraria.WorldGen.tenthAnniversaryWorldGen, Terraria.Main.tile, Terraria.Main.tileCracked, Terraria.Main.tileSolid, Terraria.WorldGen.trapDiag, System.type, and Terraria.Main.worldSurface.