Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DunesBiome.cs
Go to the documentation of this file.
1using System;
3using Newtonsoft.Json;
7
9
10public class DunesBiome : MicroBiome
11{
12 private class DunesDescription
13 {
14 public bool IsValid { get; private set; }
15
16 public SurfaceMap Surface { get; private set; }
17
18 public Rectangle Area { get; private set; }
19
20 public WindDirection WindDirection { get; private set; }
21
23 {
24 }
25
26 public static DunesDescription CreateFromPlacement(Point origin, int width, int height)
27 {
28 Rectangle area = new Rectangle(origin.X - width / 2, origin.Y - height / 2, width, height);
29 return new DunesDescription
30 {
31 Area = area,
32 IsValid = true,
33 Surface = SurfaceMap.FromArea(area.Left - 20, area.Width + 40),
34 WindDirection = ((WorldGen.genRand.Next(2) != 0) ? WindDirection.Right : WindDirection.Left)
35 };
36 }
37 }
38
39 private enum WindDirection
40 {
41 Left,
42 Right
43 }
44
45 [JsonProperty("SingleDunesWidth")]
47
48 [JsonProperty("HeightScale")]
49 private double _heightScale = 1.0;
50
51 public int MaximumWidth => _singleDunesWidth.ScaledMaximum * 2;
52
53 public override bool Place(Point origin, StructureMap structures)
54 {
55 int height = (int)((double)GenBase._random.Next(60, 100) * _heightScale);
56 int height2 = (int)((double)GenBase._random.Next(60, 100) * _heightScale);
59 DunesDescription description = DunesDescription.CreateFromPlacement(new Point(origin.X - random / 2 + 30, origin.Y), random, height);
60 DunesDescription description2 = DunesDescription.CreateFromPlacement(new Point(origin.X + random2 / 2 - 30, origin.Y), random2, height2);
61 PlaceSingle(description, structures);
62 PlaceSingle(description2, structures);
63 return true;
64 }
65
66 private void PlaceSingle(DunesDescription description, StructureMap structures)
67 {
68 int num = GenBase._random.Next(3) + 8;
69 for (int i = 0; i < num - 1; i++)
70 {
71 int num2 = (int)(2.0 / (double)num * (double)description.Area.Width);
72 int num3 = (int)((double)i / (double)num * (double)description.Area.Width + (double)description.Area.Left) + num2 * 2 / 5;
73 num3 += GenBase._random.Next(-5, 6);
74 double num4 = (double)i / (double)(num - 2);
75 double num5 = 1.0 - Math.Abs(num4 - 0.5) * 2.0;
76 PlaceHill(num3 - num2 / 2, num3 + num2 / 2, (num5 * 0.3 + 0.2) * _heightScale, description);
77 }
78 int num6 = GenBase._random.Next(2) + 1;
79 for (int j = 0; j < num6; j++)
80 {
81 int num7 = description.Area.Width / 2;
82 int x = description.Area.Center.X;
83 x += GenBase._random.Next(-10, 11);
84 PlaceHill(x - num7 / 2, x + num7 / 2, 0.8 * _heightScale, description);
85 }
86 structures.AddStructure(description.Area, 20);
87 }
88
89 private static void PlaceHill(int startX, int endX, double scale, DunesDescription description)
90 {
91 Point startPoint = new Point(startX, description.Surface[startX]);
92 Point endPoint = new Point(endX, description.Surface[endX]);
93 Point point = new Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2 - (int)(35.0 * scale));
94 int num = (endPoint.X - point.X) / 4;
95 int minValue = (endPoint.X - point.X) / 16;
96 if (description.WindDirection == WindDirection.Left)
97 {
98 point.X -= WorldGen.genRand.Next(minValue, num + 1);
99 }
100 else
101 {
102 point.X += WorldGen.genRand.Next(minValue, num + 1);
103 }
104 Point point2 = new Point(0, (int)(scale * 12.0));
105 Point point3 = new Point(point2.X / -2, point2.Y / -2);
106 PlaceCurvedLine(startPoint, point, (description.WindDirection != 0) ? point3 : point2, description);
107 PlaceCurvedLine(point, endPoint, (description.WindDirection == WindDirection.Left) ? point3 : point2, description);
108 }
109
110 private static void PlaceCurvedLine(Point startPoint, Point endPoint, Point anchorOffset, DunesDescription description)
111 {
112 //IL_0048: Unknown result type (might be due to invalid IL or missing references)
113 //IL_004d: Unknown result type (might be due to invalid IL or missing references)
114 //IL_004f: Unknown result type (might be due to invalid IL or missing references)
115 //IL_0054: Unknown result type (might be due to invalid IL or missing references)
116 //IL_0056: Unknown result type (might be due to invalid IL or missing references)
117 //IL_005b: Unknown result type (might be due to invalid IL or missing references)
118 //IL_0065: Unknown result type (might be due to invalid IL or missing references)
119 //IL_006b: Unknown result type (might be due to invalid IL or missing references)
120 //IL_008e: Unknown result type (might be due to invalid IL or missing references)
121 //IL_008f: Unknown result type (might be due to invalid IL or missing references)
122 //IL_0092: Unknown result type (might be due to invalid IL or missing references)
123 //IL_0097: Unknown result type (might be due to invalid IL or missing references)
124 //IL_0098: Unknown result type (might be due to invalid IL or missing references)
125 //IL_009b: Unknown result type (might be due to invalid IL or missing references)
126 //IL_00a0: Unknown result type (might be due to invalid IL or missing references)
127 //IL_00a2: Unknown result type (might be due to invalid IL or missing references)
128 //IL_00a6: Unknown result type (might be due to invalid IL or missing references)
129 Point p = new Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2);
130 p.X += anchorOffset.X;
131 p.Y += anchorOffset.Y;
132 Vector2D val = startPoint.ToVector2D();
133 Vector2D val2 = endPoint.ToVector2D();
134 Vector2D val3 = p.ToVector2D();
135 double num = 0.5 / (val2.X - val.X);
136 Point point = new Point(-1, -1);
137 for (double num2 = 0.0; num2 <= 1.0; num2 += num)
138 {
139 Vector2D val4 = Vector2D.Lerp(val, val3, num2);
140 Vector2D val5 = Vector2D.Lerp(val3, val2, num2);
141 Point point2 = Vector2D.Lerp(val4, val5, num2).ToPoint();
142 if (point2 == point)
143 {
144 continue;
145 }
146 point = point2;
147 int num3 = description.Area.Width / 2 - Math.Abs(point2.X - description.Area.Center.X);
148 int num4 = description.Surface[point2.X] + (int)(Math.Sqrt(num3) * 3.0);
149 for (int i = point2.Y - 10; i < point2.Y; i++)
150 {
151 if (GenBase._tiles[point2.X, i].active() && GenBase._tiles[point2.X, i].type != 53)
152 {
153 GenBase._tiles[point2.X, i].ClearEverything();
154 }
155 }
156 for (int j = point2.Y; j < num4; j++)
157 {
158 GenBase._tiles[point2.X, j].ResetToType(53);
159 Tile.SmoothSlope(point2.X, j);
160 }
161 }
162 }
163}
static double Sqrt(double d)
static double Abs(double value)
static SurfaceMap FromArea(int startX, int width)
Definition SurfaceMap.cs:43
static DunesDescription CreateFromPlacement(Point origin, int width, int height)
Definition DunesBiome.cs:26
override bool Place(Point origin, StructureMap structures)
Definition DunesBiome.cs:53
void PlaceSingle(DunesDescription description, StructureMap structures)
Definition DunesBiome.cs:66
static void PlaceHill(int startX, int endX, double scale, DunesDescription description)
Definition DunesBiome.cs:89
static void PlaceCurvedLine(Point startPoint, Point endPoint, Point anchorOffset, DunesDescription description)
static void SmoothSlope(int x, int y, bool applyToNeighbors=true, bool sync=false)
Definition Tile.cs:759
static UnifiedRandom _random
Definition GenBase.cs:9
void AddStructure(Rectangle area, int padding=0)
int GetRandom(UnifiedRandom random)
static readonly WorldGenRange Empty
static UnifiedRandom genRand
Definition WorldGen.cs:1215
static Vector2D Lerp(Vector2D value1, Vector2D value2, double amount)
Definition Vector2D.cs:216