Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ShapeBranch.cs
Go to the documentation of this file.
1using System;
6
8
9public class ShapeBranch : GenShape
10{
11 private Point _offset;
12
14
15 public ShapeBranch()
16 {
17 _offset = new Point(10, -5);
18 }
19
21 {
23 }
24
25 public ShapeBranch(double angle, double distance)
26 {
27 _offset = new Point((int)(Math.Cos(angle) * distance), (int)(Math.Sin(angle) * distance));
28 }
29
30 private bool PerformSegment(Point origin, GenAction action, Point start, Point end, int size)
31 {
32 size = Math.Max(1, size);
33 for (int i = -(size >> 1); i < size - (size >> 1); i++)
34 {
35 for (int j = -(size >> 1); j < size - (size >> 1); j++)
36 {
37 if (!Utils.PlotLine(new Point(start.X + i, start.Y + j), end, (int tileX, int tileY) => UnitApply(action, origin, tileX, tileY) || !_quitOnFail, jump: false))
38 {
39 return false;
40 }
41 }
42 }
43 return true;
44 }
45
46 public override bool Perform(Point origin, GenAction action)
47 {
48 //IL_012e: Unknown result type (might be due to invalid IL or missing references)
49 //IL_0163: Unknown result type (might be due to invalid IL or missing references)
50 //IL_0169: Unknown result type (might be due to invalid IL or missing references)
51 //IL_016b: Unknown result type (might be due to invalid IL or missing references)
52 //IL_0179: Unknown result type (might be due to invalid IL or missing references)
53 //IL_017e: Unknown result type (might be due to invalid IL or missing references)
54 //IL_0182: Unknown result type (might be due to invalid IL or missing references)
55 //IL_0192: Unknown result type (might be due to invalid IL or missing references)
56 Vector2D val = default(Vector2D);
57 ((Vector2D)(ref val))._002Ector((double)_offset.X, (double)_offset.Y);
58 double num = ((Vector2D)(ref val)).Length();
59 int num2 = (int)(num / 6.0);
60 if (_endPoints != null)
61 {
62 _endPoints.Add(new Point(origin.X + _offset.X, origin.Y + _offset.Y));
63 }
64 if (!PerformSegment(origin, action, origin, new Point(origin.X + _offset.X, origin.Y + _offset.Y), num2))
65 {
66 return false;
67 }
68 int num3 = (int)(num / 8.0);
69 Vector2D val2 = default(Vector2D);
70 for (int i = 0; i < num3; i++)
71 {
72 double num4 = ((double)i + 1.0) / ((double)num3 + 1.0);
73 Point point = new Point((int)(num4 * (double)_offset.X), (int)(num4 * (double)_offset.Y));
74 ((Vector2D)(ref val2))._002Ector((double)(_offset.X - point.X), (double)(_offset.Y - point.Y));
75 val2 = val2.RotatedBy((GenBase._random.NextDouble() * 0.5 + 1.0) * (double)((GenBase._random.Next(2) != 0) ? 1 : (-1))) * 0.75;
76 Point point2 = new Point((int)val2.X + point.X, (int)val2.Y + point.Y);
77 if (_endPoints != null)
78 {
79 _endPoints.Add(new Point(point2.X + origin.X, point2.Y + origin.Y));
80 }
81 if (!PerformSegment(origin, action, new Point(point.X + origin.X, point.Y + origin.Y), new Point(point2.X + origin.X, point2.Y + origin.Y), num2 - 1))
82 {
83 return false;
84 }
85 }
86 return true;
87 }
88
90 {
92 return this;
93 }
94}
static double Cos(double d)
static double Sin(double a)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
ShapeBranch(double angle, double distance)
bool PerformSegment(Point origin, GenAction action, Point start, Point end, int size)
ShapeBranch OutputEndpoints(List< Point > endpoints)
override bool Perform(Point origin, GenAction action)
static bool PlotLine(Point16 p0, Point16 p1, TileActionAttempt plot, bool jump=true)
Definition Utils.cs:1566
static UnifiedRandom _random
Definition GenBase.cs:9
bool UnitApply(GenAction action, Point origin, int x, int y, params object[] args)
Definition GenShape.cs:13