Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SurfaceMap.cs
Go to the documentation of this file.
1using System;
2
4
5public class SurfaceMap
6{
7 public readonly double Average;
8
9 public readonly int Bottom;
10
11 public readonly int Top;
12
13 public readonly int X;
14
15 private readonly short[] _heights;
16
17 public int Width => _heights.Length;
18
19 public short this[int absoluteX] => _heights[absoluteX - X];
20
21 private SurfaceMap(short[] heights, int x)
22 {
23 _heights = heights;
24 X = x;
25 int num = 0;
26 int num2 = int.MaxValue;
27 int num3 = 0;
28 for (int i = 0; i < heights.Length; i++)
29 {
30 num3 += heights[i];
31 num = Math.Max(num, heights[i]);
32 num2 = Math.Min(num2, heights[i]);
33 }
34 if ((double)num > Main.worldSurface - 10.0)
35 {
36 num = (int)Main.worldSurface - 10;
37 }
38 Bottom = num;
39 Top = num2;
40 Average = (double)num3 / (double)_heights.Length;
41 }
42
43 public static SurfaceMap FromArea(int startX, int width)
44 {
45 int num = Main.maxTilesY / 2;
46 short[] array = new short[width];
47 for (int i = startX; i < startX + width; i++)
48 {
49 bool flag = false;
50 int num2 = 0;
51 for (int j = 50; j < 50 + num; j++)
52 {
53 if (Main.tile[i, j].active())
54 {
55 if (Main.tile[i, j].type == 189 || Main.tile[i, j].type == 196 || Main.tile[i, j].type == 460)
56 {
57 flag = false;
58 }
59 else if (!flag)
60 {
61 num2 = j;
62 flag = true;
63 }
64 }
65 if (!flag)
66 {
67 num2 = num + 50;
68 }
69 }
70 array[i - startX] = (short)num2;
71 }
72 return new SurfaceMap(array, startX);
73 }
74}
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static SurfaceMap FromArea(int startX, int width)
Definition SurfaceMap.cs:43
static double worldSurface
Definition Main.cs:1272
static Tile[,] tile
Definition Main.cs:1675