Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HouseUtils.cs
Go to the documentation of this file.
1using System;
4using Terraria.ID;
6
8
9public static class HouseUtils
10{
11 private static readonly bool[] BlacklistedTiles = TileID.Sets.Factory.CreateBoolSet(true, 225, 41, 43, 44, 226, 203, 112, 25, 151, 21, 467);
12
13 private static readonly bool[] BeelistedTiles = TileID.Sets.Factory.CreateBoolSet(true, 41, 43, 44, 226, 203, 112, 25, 151, 21, 467);
14
15 public static HouseBuilder CreateBuilder(Point origin, StructureMap structures)
16 {
18 if (list.Count == 0 || !AreRoomLocationsValid(list))
19 {
20 return HouseBuilder.Invalid;
21 }
23 if (!AreRoomsValid(list, structures, houseType))
24 {
25 return HouseBuilder.Invalid;
26 }
27 return houseType switch
28 {
29 HouseType.Wood => new WoodHouseBuilder(list),
30 HouseType.Desert => new DesertHouseBuilder(list),
31 HouseType.Granite => new GraniteHouseBuilder(list),
32 HouseType.Ice => new IceHouseBuilder(list),
33 HouseType.Jungle => new JungleHouseBuilder(list),
34 HouseType.Marble => new MarbleHouseBuilder(list),
35 HouseType.Mushroom => new MushroomHouseBuilder(list),
36 _ => new WoodHouseBuilder(list),
37 };
38 }
39
40 private static List<Rectangle> CreateRooms(Point origin)
41 {
42 if (!WorldUtils.Find(origin, Searches.Chain(new Searches.Down(200), new Conditions.IsSolid()), out var result) || result == origin)
43 {
44 return new List<Rectangle>();
45 }
46 Rectangle item = FindRoom(result);
47 Rectangle rectangle = FindRoom(new Point(item.Center.X, item.Y + 1));
48 Rectangle rectangle2 = FindRoom(new Point(item.Center.X, item.Y + item.Height + 10));
49 rectangle2.Y = item.Y + item.Height - 1;
52 item.Y += 3;
53 rectangle.Y += 3;
54 rectangle2.Y += 3;
56 if (WorldGen.genRand.NextDouble() > roomSolidPrecentage + 0.2)
57 {
58 list.Add(rectangle);
59 }
60 list.Add(item);
61 if (WorldGen.genRand.NextDouble() > roomSolidPrecentage2 + 0.2)
62 {
63 list.Add(rectangle2);
64 }
65 return list;
66 }
67
68 private static Rectangle FindRoom(Point origin)
69 {
70 Point result;
71 bool flag = WorldUtils.Find(origin, Searches.Chain(new Searches.Left(25), new Conditions.IsSolid()), out result);
73 bool num = WorldUtils.Find(origin, Searches.Chain(new Searches.Right(25), new Conditions.IsSolid()), out result2);
74 if (!flag)
75 {
76 result = new Point(origin.X - 25, origin.Y);
77 }
78 if (!num)
79 {
80 result2 = new Point(origin.X + 25, origin.Y);
81 }
82 Rectangle result3 = new Rectangle(origin.X, origin.Y, 0, 0);
83 if (origin.X - result.X > result2.X - origin.X)
84 {
85 result3.X = result.X;
86 result3.Width = Utils.Clamp(result2.X - result.X, 15, 30);
87 }
88 else
89 {
90 result3.Width = Utils.Clamp(result2.X - result.X, 15, 30);
91 result3.X = result2.X - result3.Width;
92 }
94 bool flag2 = WorldUtils.Find(result, Searches.Chain(new Searches.Up(10), new Conditions.IsSolid()), out result4);
97 if (!flag2)
98 {
99 result4 = new Point(origin.X, origin.Y - 10);
100 }
101 if (!num2)
102 {
103 result5 = new Point(origin.X, origin.Y - 10);
104 }
105 result3.Height = Utils.Clamp(Math.Max(origin.Y - result4.Y, origin.Y - result5.Y), 8, 12);
106 result3.Y -= result3.Height;
107 return result3;
108 }
109
110 private static double GetRoomSolidPrecentage(Rectangle room)
111 {
112 double num = room.Width * room.Height;
113 Ref<int> @ref = new Ref<int>(0);
114 WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new Modifiers.IsSolid(), new Actions.Count(@ref)));
115 return (double)@ref.Value / num;
116 }
117
119 {
120 return item2.Item2.CompareTo(item1.Item2);
121 }
122
124 {
125 foreach (Rectangle room in rooms)
126 {
127 if (room.Y + room.Height > Main.maxTilesY - 220)
128 {
129 return false;
130 }
131 }
132 return true;
133 }
134
136 {
138 foreach (Rectangle room in rooms)
139 {
140 WorldUtils.Gen(new Point(room.X - 10, room.Y - 10), new Shapes.Rectangle(room.Width + 20, room.Height + 20), new Actions.TileScanner(0, 59, 147, 1, 161, 53, 396, 397, 368, 367, 60, 70).Output(dictionary));
141 }
143 list.Add(Tuple.Create(HouseType.Wood, dictionary[0] + dictionary[1]));
144 list.Add(Tuple.Create(HouseType.Jungle, dictionary[59] + dictionary[60] * 10));
145 list.Add(Tuple.Create(HouseType.Mushroom, dictionary[59] + dictionary[70] * 10));
146 list.Add(Tuple.Create(HouseType.Ice, dictionary[147] + dictionary[161]));
147 list.Add(Tuple.Create(HouseType.Desert, dictionary[397] + dictionary[396] + dictionary[53]));
148 list.Add(Tuple.Create(HouseType.Granite, dictionary[368]));
149 list.Add(Tuple.Create(HouseType.Marble, dictionary[367]));
151 return list[0].Item1;
152 }
153
154 private static bool AreRoomsValid(IEnumerable<Rectangle> rooms, StructureMap structures, HouseType style)
155 {
156 foreach (Rectangle room in rooms)
157 {
158 if (style != HouseType.Granite && WorldUtils.Find(new Point(room.X - 2, room.Y - 2), Searches.Chain(new Searches.Rectangle(room.Width + 4, room.Height + 4).RequireAll(mode: false), new Conditions.HasLava()), out var _))
159 {
160 return false;
161 }
163 {
164 if (!structures.CanPlace(room, BeelistedTiles, 5))
165 {
166 return false;
167 }
168 }
169 else if (!structures.CanPlace(room, BlacklistedTiles, 5))
170 {
171 return false;
172 }
173 }
174 return true;
175 }
176}
void Add(TKey key, TValue value)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static double GetRoomSolidPrecentage(Rectangle room)
static HouseBuilder CreateBuilder(Point origin, StructureMap structures)
Definition HouseUtils.cs:15
static bool AreRoomLocationsValid(IEnumerable< Rectangle > rooms)
static HouseType GetHouseType(IEnumerable< Rectangle > rooms)
static bool AreRoomsValid(IEnumerable< Rectangle > rooms, StructureMap structures, HouseType style)
static int SortBiomeResults(Tuple< HouseType, int > item1, Tuple< HouseType, int > item2)
static List< Rectangle > CreateRooms(Point origin)
Definition HouseUtils.cs:40
static Rectangle FindRoom(Point origin)
Definition HouseUtils.cs:68
static SetFactory Factory
Definition TileID.cs:81
static int maxTilesY
Definition Main.cs:1116
TileScanner Output(Dictionary< ushort, int > resultsOutput)
Definition Actions.cs:86
static GenAction Chain(params GenAction[] actions)
Definition Actions.cs:470
GenSearch RequireAll(bool mode)
Definition GenSearch.cs:33
static GenSearch Chain(GenSearch search, params GenCondition[] conditions)
Definition Searches.cs:123
static bool Find(Point origin, GenSearch search, out Point result)
Definition WorldUtils.cs:27
static bool Gen(Point origin, GenShape shape, GenAction action)
Definition WorldUtils.cs:17
static UnifiedRandom genRand
Definition WorldGen.cs:1215
static bool notTheBees
Definition WorldGen.cs:1164