private void BuildMagmaMap(Point tileOrigin) { _sourceMagmaMap = new Magma[200, 200]; _targetMagmaMap = new Magma[200, 200]; for (int i = 0; i < _sourceMagmaMap.GetLength(0); i++) { for (int j = 0; j < _sourceMagmaMap.GetLength(1); j++) { int i2 = i + tileOrigin.X; int j2 = j + tileOrigin.Y; _sourceMagmaMap[i, j] = Magma.CreateEmpty(WorldGen.SolidTile(i2, j2) ? 4f : 1f); _targetMagmaMap[i, j] = _sourceMagmaMap[i, j]; } } }
public override bool Place(Point origin, StructureMap structures) { if (GenBase._tiles[origin.X, origin.Y].active()) { return(false); } int length = _sourceMagmaMap.GetLength(0); int length2 = _sourceMagmaMap.GetLength(1); int num = length / 2; int num2 = length2 / 2; origin.X -= num; origin.Y -= num2; for (int i = 0; i < length; i++) { for (int j = 0; j < length2; j++) { int i2 = i + origin.X; int j2 = j + origin.Y; _sourceMagmaMap[i, j] = Magma.CreateEmpty(WorldGen.SolidTile(i2, j2) ? 4f : 1f); _targetMagmaMap[i, j] = _sourceMagmaMap[i, j]; } } int num3 = num; int num4 = num; int num5 = num2; int num6 = num2; for (int k = 0; k < 300; k++) { for (int l = num3; l <= num4; l++) { for (int m = num5; m <= num6; m++) { Magma magma = _sourceMagmaMap[l, m]; if (!magma.IsActive) { continue; } float num7 = 0f; Vector2 zero = Vector2.Zero; for (int n = -1; n <= 1; n++) { for (int num8 = -1; num8 <= 1; num8++) { if (n == 0 && num8 == 0) { continue; } Vector2 value = new Vector2(n, num8); value.Normalize(); Magma magma2 = _sourceMagmaMap[l + n, m + num8]; if (magma.Pressure > 0.01f && !magma2.IsActive) { if (n == -1) { num3 = Utils.Clamp(l + n, 1, num3); } else { num4 = Utils.Clamp(l + n, num4, length - 2); } if (num8 == -1) { num5 = Utils.Clamp(m + num8, 1, num5); } else { num6 = Utils.Clamp(m + num8, num6, length2 - 2); } _targetMagmaMap[l + n, m + num8] = magma2.ToFlow(); } float pressure = magma2.Pressure; num7 += pressure; zero += pressure * value; } } num7 /= 8f; if (num7 > magma.Resistance) { float num9 = zero.Length() / 8f; float val = Math.Max(num7 - num9 - magma.Pressure, 0f) + num9 + magma.Pressure * 0.875f - magma.Resistance; val = Math.Max(0f, val); _targetMagmaMap[l, m] = Magma.CreateFlow(val, Math.Max(0f, magma.Resistance - val * 0.02f)); } } } if (k < 2) { _targetMagmaMap[num, num2] = Magma.CreateFlow(25f); } Utils.Swap(ref _sourceMagmaMap, ref _targetMagmaMap); } bool flag = origin.Y + num2 > WorldGen.lavaLine - 30; bool flag2 = false; for (int num10 = -50; num10 < 50; num10++) { if (flag2) { break; } for (int num11 = -50; num11 < 50; num11++) { if (flag2) { break; } if (GenBase._tiles[origin.X + num + num10, origin.Y + num2 + num11].active()) { switch (GenBase._tiles[origin.X + num + num10, origin.Y + num2 + num11].type) { case 147: case 161: case 162: case 163: case 200: flag = false; flag2 = true; break; } } } } for (int num12 = num3; num12 <= num4; num12++) { for (int num13 = num5; num13 <= num6; num13++) { Magma magma3 = _sourceMagmaMap[num12, num13]; if (!magma3.IsActive) { continue; } Tile tile = GenBase._tiles[origin.X + num12, origin.Y + num13]; float num14 = (float)Math.Sin((float)(origin.Y + num13) * 0.4f) * 0.7f + 1.2f; float num15 = 0.2f + 0.5f / (float)Math.Sqrt(Math.Max(0f, magma3.Pressure - magma3.Resistance)); float val2 = 1f - Math.Max(0f, num14 * num15); val2 = Math.Max(val2, magma3.Pressure / 15f); if (val2 > 0.35f + (WorldGen.SolidTile(origin.X + num12, origin.Y + num13) ? 0f : 0.5f)) { if (TileID.Sets.Ore[tile.type]) { tile.ResetToType(tile.type); } else { tile.ResetToType(368); } tile.wall = 180; } else if (magma3.Resistance < 0.01f) { WorldUtils.ClearTile(origin.X + num12, origin.Y + num13); tile.wall = 180; } if (tile.liquid > 0 && flag) { tile.liquidType(1); } } } List <Point16> list = new List <Point16>(); for (int num16 = num3; num16 <= num4; num16++) { for (int num17 = num5; num17 <= num6; num17++) { Magma magma4 = _sourceMagmaMap[num16, num17]; if (!magma4.IsActive) { continue; } int num18 = 0; int num19 = num16 + origin.X; int num20 = num17 + origin.Y; if (!WorldGen.SolidTile(num19, num20)) { continue; } for (int num21 = -1; num21 <= 1; num21++) { for (int num22 = -1; num22 <= 1; num22++) { if (WorldGen.SolidTile(num19 + num21, num20 + num22)) { num18++; } } } if (num18 < 3) { list.Add(new Point16(num19, num20)); } } } foreach (Point16 item in list) { int x = item.X; int y = item.Y; WorldUtils.ClearTile(x, y, frameNeighbors: true); GenBase._tiles[x, y].wall = 180; } list.Clear(); for (int num23 = num3; num23 <= num4; num23++) { for (int num24 = num5; num24 <= num6; num24++) { Magma magma5 = _sourceMagmaMap[num23, num24]; int num25 = num23 + origin.X; int num26 = num24 + origin.Y; if (!magma5.IsActive) { continue; } WorldUtils.TileFrame(num25, num26); WorldGen.SquareWallFrame(num25, num26); if (GenBase._random.Next(8) == 0 && GenBase._tiles[num25, num26].active()) { if (!GenBase._tiles[num25, num26 + 1].active()) { WorldGen.PlaceTight(num25, num26 + 1, 165); } if (!GenBase._tiles[num25, num26 - 1].active()) { WorldGen.PlaceTight(num25, num26 - 1, 165); } } if (GenBase._random.Next(2) == 0) { Tile.SmoothSlope(num25, num26); } } } return(true); }
public override bool Place(Point origin, StructureMap structures) { if (_tiles[origin.X, origin.Y].active()) { return(false); } var length1 = _sourceMagmaMap.GetLength(0); var length2 = _sourceMagmaMap.GetLength(1); var index1 = length1 / 2; var index2 = length2 / 2; origin.X -= index1; origin.Y -= index2; for (var index3 = 0; index3 < length1; ++index3) { for (var index4 = 0; index4 < length2; ++index4) { var i = index3 + origin.X; var j = index4 + origin.Y; _sourceMagmaMap[index3, index4] = Magma.CreateEmpty(WorldGen.SolidTile(i, j) ? 4f : 1f); _targetMagmaMap[index3, index4] = _sourceMagmaMap[index3, index4]; } } var max1 = index1; var min1 = index1; var max2 = index2; var min2 = index2; for (var index3 = 0; index3 < 300; ++index3) { for (var index4 = max1; index4 <= min1; ++index4) { for (var index5 = max2; index5 <= min2; ++index5) { var sourceMagma1 = _sourceMagmaMap[index4, index5]; if (sourceMagma1.IsActive) { var num1 = 0.0f; var zero = Vector2.Zero; for (var index6 = -1; index6 <= 1; ++index6) { for (var index7 = -1; index7 <= 1; ++index7) { if (index6 != 0 || index7 != 0) { var vector2 = new Vector2(index6, index7); vector2.Normalize(); var sourceMagma2 = _sourceMagmaMap[index4 + index6, index5 + index7]; if (sourceMagma1.Pressure > 0.00999999977648258 && !sourceMagma2.IsActive) { if (index6 == -1) { max1 = Utils.Clamp(index4 + index6, 1, max1); } else { min1 = Utils.Clamp(index4 + index6, min1, length1 - 2); } if (index7 == -1) { max2 = Utils.Clamp(index5 + index7, 1, max2); } else { min2 = Utils.Clamp(index5 + index7, min2, length2 - 2); } _targetMagmaMap[index4 + index6, index5 + index7] = sourceMagma2.ToFlow(); } var pressure = sourceMagma2.Pressure; num1 += pressure; zero += pressure * vector2; } } } var num2 = num1 / 8f; if (num2 > (double)sourceMagma1.Resistance) { var num3 = zero.Length() / 8f; var pressure = Math.Max(0.0f, (float)(Math.Max(num2 - num3 - sourceMagma1.Pressure, 0.0f) + (double)num3 + sourceMagma1.Pressure * 0.875) - sourceMagma1.Resistance); _targetMagmaMap[index4, index5] = Magma.CreateFlow(pressure, Math.Max(0.0f, sourceMagma1.Resistance - pressure * 0.02f)); } } } } if (index3 < 2) { _targetMagmaMap[index1, index2] = Magma.CreateFlow(25f, 0.0f); } Utils.Swap(ref _sourceMagmaMap, ref _targetMagmaMap); } var flag1 = origin.Y + index2 > WorldGen.lavaLine - 30; var flag2 = false; for (var index3 = -50; index3 < 50 && !flag2; ++index3) { for (var index4 = -50; index4 < 50 && !flag2; ++index4) { if (_tiles[origin.X + index1 + index3, origin.Y + index2 + index4].active()) { switch (_tiles[origin.X + index1 + index3, origin.Y + index2 + index4].type) { case 147: case 161: case 162: case 163: case 200: flag1 = false; flag2 = true; continue; default: continue; } } } } for (var index3 = max1; index3 <= min1; ++index3) { for (var index4 = max2; index4 <= min2; ++index4) { var sourceMagma = _sourceMagmaMap[index3, index4]; if (sourceMagma.IsActive) { var tile = _tiles[origin.X + index3, origin.Y + index4]; if (Math.Max( 1f - Math.Max(0.0f, (float)(Math.Sin((origin.Y + index4) * 0.400000005960464) * 0.699999988079071 + 1.20000004768372) * (float)(0.200000002980232 + 0.5 / Math.Sqrt(Math.Max(0.0f, sourceMagma.Pressure - sourceMagma.Resistance)))), sourceMagma.Pressure / 15f) > 0.349999994039536 + (WorldGen.SolidTile(origin.X + index3, origin.Y + index4) ? 0.0 : 0.5)) { if (TileID.Sets.Ore[tile.type]) { tile.ResetToType(tile.type); } else { tile.ResetToType(368); } tile.wall = 180; } else if (sourceMagma.Resistance < 0.00999999977648258) { WorldUtils.ClearTile(origin.X + index3, origin.Y + index4, false); tile.wall = 180; } if (tile.liquid > 0 && flag1) { tile.liquidType(1); } } } } var point16List = new List <Point16>(); for (var index3 = max1; index3 <= min1; ++index3) { for (var index4 = max2; index4 <= min2; ++index4) { if (_sourceMagmaMap[index3, index4].IsActive) { var num1 = 0; var num2 = index3 + origin.X; var num3 = index4 + origin.Y; if (WorldGen.SolidTile(num2, num3)) { for (var index5 = -1; index5 <= 1; ++index5) { for (var index6 = -1; index6 <= 1; ++index6) { if (WorldGen.SolidTile(num2 + index5, num3 + index6)) { ++num1; } } } if (num1 < 3) { point16List.Add(new Point16(num2, num3)); } } } } } foreach (var point16 in point16List) { var x = (int)point16.X; var y = (int)point16.Y; WorldUtils.ClearTile(x, y, true); _tiles[x, y].wall = 180; } point16List.Clear(); for (var index3 = max1; index3 <= min1; ++index3) { for (var index4 = max2; index4 <= min2; ++index4) { var sourceMagma = _sourceMagmaMap[index3, index4]; var index5 = index3 + origin.X; var index6 = index4 + origin.Y; if (sourceMagma.IsActive) { WorldUtils.TileFrame(index5, index6, false); WorldGen.SquareWallFrame(index5, index6, true); if (_random.Next(8) == 0 && _tiles[index5, index6].active()) { if (!_tiles[index5, index6 + 1].active()) { WorldGen.PlaceTight(index5, index6 + 1, 165, false); } if (!_tiles[index5, index6 - 1].active()) { WorldGen.PlaceTight(index5, index6 - 1, 165, false); } } if (_random.Next(2) == 0) { Tile.SmoothSlope(index5, index6, true); } } } } return(true); }