Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
GenRoom.cs
Go to the documentation of this file.
1using System;
2using Dungen;
3using UnityEngine;
4
5public class GenRoom : GenBounds
6{
8
10
11 public static int[] ListWrecks = new int[6] { 34, 46, 83, 85, 86, 87 };
12
13 private Point _p = new Point();
14
15 private Cell _c;
16
17 public int Index => x + y * Size;
18
19 public virtual bool PopulateCluster => true;
20
21 public virtual bool IsBigRoom => false;
22
23 public void Init(Dungen.Room room)
24 {
25 x = room.x + 1;
26 y = room.y + 1;
27 width = room.width;
28 height = room.height;
29 Size = width * height;
30 }
31
32 public void Init(int _x, int _y, int w, int h)
33 {
34 x = _x;
35 y = _y;
36 width = w;
37 height = h;
38 Size = width * height;
39 }
40
41 public void Populate()
42 {
43 PartialMap partialMap = TryAddMapPiece();
44 OnPopulate();
45 BiomeProfile biome = zone.biome;
46 if (biome.style.lights.Count > 0 && (partialMap == null || !partialMap.result.hasLight))
47 {
48 foreach (BiomeProfile.Cluster.ItemThing light in biome.style.lights)
49 {
50 if (Rand.Range(0f, 1f) > light.chance)
51 {
52 continue;
53 }
54 Thing thing = ThingGen.Create(light.id);
55 Point point = new Point();
56 for (int i = 0; i < 100; i++)
57 {
58 if (thing.TileType.UseMountHeight)
59 {
60 point.Set(x + EClass.rnd(width), y + EClass.rnd(height));
61 Cell cell = point.cell;
62 if (cell.Left.hasDoor || cell.Right.hasDoor || cell.Front.hasDoor || cell.Back.hasDoor || (!cell.Left.HasBlock && !cell.Right.HasBlock && !cell.Front.HasBlock && !cell.Back.HasBlock))
63 {
64 continue;
65 }
66 }
67 else
68 {
69 int a = Mathf.Min(i / 3 + 2, width / 2);
70 int a2 = Mathf.Min(i / 3 + 2, height / 2);
71 point.Set(x + width / 2 + EClass.rnd(a) - EClass.rnd(a), y + height / 2 + EClass.rnd(a2) - EClass.rnd(a2));
72 }
73 if (!point.cell.blocked && !point.HasBlock && !point.HasObj && point.Installed == null)
74 {
75 int desiredDir = thing.TileType.GetDesiredDir(point, 0);
76 if (desiredDir != -1)
77 {
78 thing.dir = desiredDir;
79 }
80 zone.AddCard(thing, point).Install();
81 break;
82 }
83 }
84 break;
85 }
86 }
87 if (!PopulateCluster)
88 {
89 return;
90 }
91 Point point2 = new Point();
92 for (int j = x; j < x + width; j++)
93 {
94 for (int k = y; k < y + height; k++)
95 {
96 point2.Set(j, k);
97 if (!point2.cell.isModified && !point2.cell.blocked)
98 {
99 biome.Populate(point2, interior: true);
100 }
101 }
102 }
103 }
104
105 public void SpawnMob(Point p)
106 {
107 if (EClass.rnd(100) <= 55 + zone.DangerLv * 3)
108 {
109 zone.SpawnMob(p);
110 }
111 }
112
113 public virtual void OnPopulate()
114 {
115 for (int i = 0; i < EClass.rnd(3 + Size / 8) + 1; i++)
116 {
117 SetRandomPoint(delegate(Point p)
118 {
119 switch (EClass.rnd(7))
120 {
121 case 0:
122 case 1:
123 if (zone.biome.spawn.thing.Count > 0)
124 {
125 Thing thing2 = ThingGen.CreateFromFilter(zone.biome.spawn.GetRandomThingId(), EClass._zone.DangerLv);
126 if (thing2 != null)
127 {
128 zone.AddCard(thing2, p);
129 }
130 }
131 break;
132 case 2:
133 if (EClass.rnd(5) == 0)
134 {
135 map.SetObj(p.x, p.z, 82);
136 if (EClass.rnd(2) == 0)
137 {
138 map.ApplyBackerObj(p);
139 }
140 }
141 else
142 {
143 map.SetObj(p.x, p.z, ListWrecks.RandomItem());
144 }
145 break;
146 default:
147 SpawnMob(p);
148 break;
149 }
150 });
151 }
152 if (Size <= 25)
153 {
154 return;
155 }
156 for (int j = 0; j < Size / 25 + EClass.rnd(Size / 25); j++)
157 {
158 SetRandomPoint(delegate(Point p)
159 {
160 if (EClass.rnd(3) == 0)
161 {
162 Thing thing = ThingGen.CreateFromFilter(zone.biome.spawn.GetRandomThingId(), EClass._zone.DangerLv);
163 if (thing != null)
164 {
165 zone.AddCard(thing, p);
166 }
167 }
168 else
169 {
170 SpawnMob(p);
171 }
172 });
173 }
174 }
175
176 public void Fill()
177 {
178 BiomeProfile.TileFloor floor = group.floor;
179 BiomeProfile.TileBlock block = group.block;
180 int idMat = block.mat;
181 if (zone is Zone_RandomDungeonNature && EClass.rnd(3) != 0)
182 {
183 block = EClass.core.refs.biomes.dict["Dungeon_Forest"].exterior.block;
184 if (zone is Zone_RandomDungeonPlain)
185 {
186 idMat = 5;
187 }
188 }
189 for (int i = x; i < x + width; i++)
190 {
191 for (int j = y; j < y + height; j++)
192 {
193 if (map.cells[i, j]._block != 0)
194 {
195 SetBlock(i, j, idMat, block.id, EClass.rnd(EClass.rnd(4) + 1));
196 }
197 SetFloor(i, j, floor.mat, floor.id, EClass.rnd(EClass.rnd(8) + 1));
198 }
199 }
200 }
201
202 public void SetRandomPoint(Action<Point> action)
203 {
204 int a = Mathf.Max(width - 2, 1);
205 int a2 = Mathf.Max(height - 2, 1);
206 for (int i = 0; i < 100; i++)
207 {
208 _p.x = x + 1 + EClass.rnd(a);
209 _p.z = y + 1 + EClass.rnd(a2);
210 _c = map.cells[_p.x, _p.z];
211 if (!_c.blocked && !_c.HasBlock && !_p.HasThing && !_p.HasChara)
212 {
213 action(_p);
214 break;
215 }
216 }
217 }
218
219 public void SetRandomPointCentered(Action<Point> action)
220 {
221 int a = Mathf.Max(width / 2 - 1, 1);
222 int a2 = Mathf.Max(height / 2 - 1, 1);
223 for (int i = 0; i < 100; i++)
224 {
225 _p.x = x + width / 2 + EClass.rnd(EClass.rnd(a) + 1) - EClass.rnd(EClass.rnd(a) + 1);
226 _p.z = y + height / 2 + EClass.rnd(EClass.rnd(a2) + 1) - EClass.rnd(EClass.rnd(a2) + 1);
227 _c = map.cells[_p.x, _p.z];
228 if (!_c.blocked && !_c.HasBlock && !_p.HasThing && !_p.HasChara)
229 {
230 action(_p);
231 break;
232 }
233 }
234 }
235}
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
List< Cluster.ItemThing > lights
void Populate(Point point, bool interior=false)
TileType TileType
Definition: Card.cs:2011
Card Install()
Definition: Card.cs:3448
Definition: Cell.cs:7
bool HasBlock
Definition: Cell.cs:643
Cell Back
Definition: Cell.cs:153
Cell Front
Definition: Cell.cs:129
bool isModified
Definition: Cell.cs:438
Cell Left
Definition: Cell.cs:165
Cell Right
Definition: Cell.cs:141
bool hasDoor
Definition: Cell.cs:258
UD_Biome dict
Definition: CoreRef.cs:142
Biomes biomes
Definition: CoreRef.cs:325
CoreRef refs
Definition: Core.cs:51
Definition: EClass.cs:5
static int rnd(int a)
Definition: EClass.cs:50
static Core core
Definition: EClass.cs:6
int height
Definition: GenBounds.cs:19
int width
Definition: GenBounds.cs:17
Zone zone
Definition: GenBounds.cs:9
PartialMap TryAddMapPiece(MapPiece.Type type=MapPiece.Type.Any, float ruin=-1f, string tags=null, Action< PartialMap, GenBounds > onCreate=null)
Definition: GenBounds.cs:183
int Size
Definition: GenBounds.cs:11
Map map
Definition: GenBounds.cs:7
void Init(int _x, int _y, int w, int h)
Definition: GenRoom.cs:32
void Fill()
Definition: GenRoom.cs:176
virtual bool IsBigRoom
Definition: GenRoom.cs:21
void Populate()
Definition: GenRoom.cs:41
MapGenDungen gen
Definition: GenRoom.cs:9
BiomeProfile.TileGroup group
Definition: GenRoom.cs:7
void SetRandomPoint(Action< Point > action)
Definition: GenRoom.cs:202
int Index
Definition: GenRoom.cs:17
Point _p
Definition: GenRoom.cs:13
virtual bool PopulateCluster
Definition: GenRoom.cs:19
void Init(Dungen.Room room)
Definition: GenRoom.cs:23
static int[] ListWrecks
Definition: GenRoom.cs:11
virtual void OnPopulate()
Definition: GenRoom.cs:113
Cell _c
Definition: GenRoom.cs:15
void SetRandomPointCentered(Action< Point > action)
Definition: GenRoom.cs:219
void SpawnMob(Point p)
Definition: GenRoom.cs:105
void SetObj(int x, int z, int id=0, int value=1, int dir=0)
Definition: Map.cs:1522
Result result
Definition: PartialMap.cs:84
Definition: Point.cs:9
Thing Installed
Definition: Point.cs:303
Point Set(int _x, int _z)
Definition: Point.cs:479
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
bool HasObj
Definition: Point.cs:137
bool HasBlock
Definition: Point.cs:141
Cell cell
Definition: Point.cs:51
Definition: Rand.cs:4
static int Range(int min, int max)
Definition: Rand.cs:42
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
virtual int GetDesiredDir(Point p, int d)
Definition: TileType.cs:362
virtual bool UseMountHeight
Definition: TileType.cs:209
BiomeProfile biome
Definition: Zone.cs:126
Chara SpawnMob(Point pos=null, SpawnSetting setting=null)
Definition: Zone.cs:2543
override int DangerLv
Definition: Zone.cs:107
Card AddCard(Card t, Point point)
Definition: Zone.cs:1893