Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
MapGenDungen.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using Dungen;
3using UnityEngine;
4
5public class MapGenDungen : BaseMapGen
6{
7 private static MapGenDungen _Instance;
8
9 public static MapGenDungen Instance => _Instance ?? (_Instance = new MapGenDungen());
10
11 protected override bool OnGenerateTerrain()
12 {
13 DunGen.Init();
14 MapGenerator generator = zone.Generator;
15 MapData mapData = DunGen.Generate(generator);
16 width = mapData.size_X + 2;
17 height = mapData.size_Y + 2;
18 SetSize(Mathf.Max(width, height), 10);
22 map.config.blockHeight = EClass.core.gameSetting.gen.defaultBlockHeight;
23 BiomeProfile biome = zone.biome;
24 if (zone is Zone_Void)
25 {
26 biome = biome.Instantiate();
27 biome.interior.block.mat = MATERIAL.GetRandomMaterialFromCategory(zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
28 biome.interior.block.matSub = MATERIAL.GetRandomMaterialFromCategory(zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
29 biome.interior.floor.mat = MATERIAL.GetRandomMaterialFromCategory(zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
30 biome.interior.floor.matSub = MATERIAL.GetRandomMaterialFromCategory(zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
31 biome.exterior.block.mat = MATERIAL.GetRandomMaterialFromCategory(zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
32 biome.exterior.block.matSub = MATERIAL.GetRandomMaterialFromCategory(zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
33 biome.exterior.floor.mat = MATERIAL.GetRandomMaterialFromCategory(zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
34 biome.exterior.floor.matSub = MATERIAL.GetRandomMaterialFromCategory(zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
35 }
38 int idMat = -1;
39 if (zone is Zone_RandomDungeonNature && EClass.rnd(3) != 0)
40 {
41 block = EClass.core.refs.biomes.dict["Dungeon_Forest"].exterior.block;
43 {
44 idMat = 5;
45 }
46 }
47 bool flag = zone.lv <= 0;
48 bool flag2 = false;
49 bool flag3 = false;
50 Point point = new Point();
51 Thing thing = null;
52 Thing thing2 = null;
53 for (int i = 0; i < mapData.size_X + 2; i++)
54 {
55 for (int j = 0; j < mapData.size_Y + 2; j++)
56 {
57 if (i == 0 || j == 0 || i >= mapData.size_X || j >= mapData.size_Y)
58 {
59 SetFloor(floor, i, j);
60 SetBlock(block, i, j, idMat);
61 continue;
62 }
63 Dungen.Cell cell = mapData.cellsOnMap[i - 1, j - 1];
64 CellType type = cell.type;
65 point.Set(i, j);
66 SetFloor(floor, i, j);
67 switch (type.name)
68 {
69 case "Entrance":
70 {
71 if (flag2)
72 {
73 Debug.LogError("exception: already created entrance");
74 break;
75 }
76 flag2 = true;
77 Thing thing4 = ThingGen.Create(biome.style.GetIdStairs(flag), biome.style.matStairs);
78 if (!flag)
79 {
80 thing = thing4;
81 }
82 else
83 {
84 thing2 = thing4;
85 }
86 zone.AddCard(thing4, i, j).Install();
87 break;
88 }
89 case "Exit":
90 {
92 {
93 break;
94 }
95 if (flag3)
96 {
97 Debug.LogError("exception: already created exit");
98 break;
99 }
100 flag3 = true;
101 Thing thing3 = ThingGen.Create(EClass._zone.LockExit ? "stairs_locked" : biome.style.GetIdStairs(!flag), zone.LockExit ? (-1) : biome.style.matStairs);
102 if (flag)
103 {
104 thing = thing3;
105 }
106 else
107 {
108 thing2 = thing3;
109 }
110 zone.AddCard(thing3, i, j).Install();
111 break;
112 }
113 case "Door":
114 if (!(biome.style.doorChance < Rand.Range(0f, 1f)))
115 {
116 SetBlock(block, i, j, idMat);
117 Thing t2 = ThingGen.Create(biome.style.GetIdDoor(), biome.style.matDoor);
118 zone.AddCard(t2, i, j).Install();
119 }
120 break;
121 case "Abyss":
122 SetBlock(block, i, j, idMat);
123 break;
124 default:
125 if (type.passable == generator.reversePassage)
126 {
127 SetBlock(block, i, j, idMat);
128 }
129 break;
130 }
131 if (!cell.isRoomCell)
132 {
133 biome.Populate(point);
134 }
135 }
136 }
137 if (!flag2)
138 {
139 Debug.LogError("exception: Failed to create entrance:");
140 return false;
141 }
142 if (zone.ShouldMakeExit && !flag3)
143 {
144 Debug.LogError("exception: Failed to create exist:");
145 return false;
146 }
147 if (thing2 != null)
148 {
149 thing2.pos.cell._block = 0;
150 thing2.pos.cell.obj = 0;
151 }
152 if (thing != null)
153 {
154 thing.pos.cell._block = 0;
155 thing.pos.cell.obj = 0;
156 }
157 Dictionary<int, GenRoom> rooms = new Dictionary<int, GenRoom>();
158 int count = 0;
159 int num = 0;
160 foreach (Dungen.Room room in mapData.rooms)
161 {
162 if (room.width != 0 && room.height != 0)
163 {
164 num++;
165 }
166 }
167 if (num == 0)
168 {
169 mapData.rooms.Clear();
170 }
171 if (mapData.rooms.Count == 0)
172 {
173 GenRoomBig genRoomBig = new GenRoomBig();
174 genRoomBig.Init(1, 1, width - 1, height - 1);
175 SetRoom(genRoomBig);
176 }
177 else
178 {
179 foreach (Dungen.Room room2 in mapData.rooms)
180 {
181 GenRoom genRoom = ChooseRoom();
182 genRoom.Init(room2);
183 SetRoom(genRoom);
184 }
185 }
187 foreach (GenRoom value in rooms.Values)
188 {
189 value.Populate();
190 }
191 zone.OnGenerateRooms(this);
192 map.ReloadRoom();
193 Debug.Log("Dungen: room:" + rooms.Count + "/" + mapData.rooms.Count + " width:" + width + " height:" + height);
194 int num2 = EClass.rnd(Size * Size / 50 + EClass.rnd(20)) + 5;
195 num2 = num2 * Mathf.Min(20 + zone.DangerLv * 5, 100) / 100;
197 {
198 num2 /= 5;
199 }
200 for (int k = 0; k < num2; k++)
201 {
202 point = EClass._map.GetRandomPoint();
203 if (!point.cell.isModified && !point.HasThing && !point.HasBlock && !point.HasObj)
204 {
206 EClass._zone.AddCard(t3, point).Install();
207 }
208 }
210 {
211 Crawler crawler = Crawler.Create("pasture");
212 int tries = 3;
213 crawler.CrawlUntil(EClass._map, () => EClass._map.GetRandomPoint(), tries, delegate(Crawler.Result r)
214 {
215 int id = ((EClass.rnd(3) == 0) ? 108 : 105);
216 foreach (Point point2 in r.points)
217 {
218 if (!point2.cell.isModified && !point2.HasThing && !point2.HasBlock && !point2.HasObj)
219 {
220 map.SetObj(point2.x, point2.z, id);
221 int num3 = 3;
222 if (EClass.rnd(6) == 0)
223 {
224 num3++;
225 }
226 point2.growth.SetStage(num3);
227 }
228 }
229 return false;
230 });
231 }
232 map.things.ForeachReverse(delegate(Thing t)
233 {
234 if (t.trait is TraitDoor traitDoor && !traitDoor.IsValid())
235 {
236 Debug.Log("Purging Door:" + t.Name + "/" + t.pos);
237 t.Destroy();
238 }
239 });
240 if (thing != null)
241 {
242 ClearPos(thing);
243 }
244 if (thing2 != null)
245 {
246 ClearPos(thing2);
247 }
248 return true;
249 static void ClearPos(Thing t)
250 {
251 foreach (Card item in t.pos.ListCards())
252 {
253 if (item != t && item.isThing)
254 {
255 item.Destroy();
256 }
257 }
258 t.pos.SetObj();
259 t.pos.SetBlock();
260 t.pos.cell.height = 0;
261 }
262 void SetRoom(GenRoom room)
263 {
264 room.map = map;
265 room.zone = zone;
266 room.gen = this;
267 room.group = ((zone is Zone_RandomDungeonNature) ? biome.exterior : biome.interior);
268 rooms[room.Index] = room;
269 room.Fill();
270 Debug.Log("Room" + count + " " + room.width + "*" + room.height + " " + room);
271 count++;
272 }
273 }
274
276 {
277 if (EClass.rnd(100) < 5)
278 {
279 return new GenRoomMonsterHouse();
280 }
281 return new GenRoom();
282 }
283}
void SetSize(int size, int _poiSize)
Definition: BaseMapGen.cs:91
string GetIdStairs(bool upstairs)
TileGroup exterior
void Populate(Point point, bool interior=false)
Definition: Card.cs:11
Point pos
Definition: Card.cs:55
Trait trait
Definition: Card.cs:49
Card Install()
Definition: Card.cs:3448
UD_Biome dict
Definition: CoreRef.cs:142
Biomes biomes
Definition: CoreRef.cs:325
CoreRef refs
Definition: Core.cs:51
GameSetting gameSetting
Definition: Core.cs:47
static Crawler Create(string id)
Definition: Crawler.cs:190
bool CrawlUntil(Map map, Func< Point > onStart, int tries, Func< Result, bool > canComplete, Action onFail=null)
Definition: Crawler.cs:57
Definition: EClass.cs:5
static int rnd(int a)
Definition: EClass.cs:50
static Core core
Definition: EClass.cs:6
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static SourceManager sources
Definition: EClass.cs:42
GenSetting gen
Definition: GameSetting.cs:311
int height
Definition: GenBounds.cs:19
void SetBlock(BiomeProfile.Tile t, int x, int z, int idMat=-1)
Definition: GenBounds.cs:43
int width
Definition: GenBounds.cs:17
Zone zone
Definition: GenBounds.cs:9
int Size
Definition: GenBounds.cs:11
Map map
Definition: GenBounds.cs:7
void SetFloor(BiomeProfile.Tile t, int x, int z)
Definition: GenBounds.cs:37
void Fill()
Definition: GenRoom.cs:176
void Populate()
Definition: GenRoom.cs:41
int Index
Definition: GenRoom.cs:17
void Init(Dungen.Room room)
Definition: GenRoom.cs:23
static SourceMaterial.Row GetRandomMaterialFromCategory(int lv, string cat, SourceMaterial.Row fallback)
Definition: MATERIAL.cs:81
static MapGenDungen _Instance
Definition: MapGenDungen.cs:7
GenRoom ChooseRoom()
static MapGenDungen Instance
Definition: MapGenDungen.cs:9
override bool OnGenerateTerrain()
Definition: MapGenDungen.cs:11
Point GetRandomPoint(Point center, int radius, int tries=100, bool mustBeWalkable=true, bool requireLos=true)
Definition: Map.cs:2193
void SetZone(Zone _zone)
Definition: Map.cs:181
List< Thing > things
Definition: Map.cs:49
POIMap poiMap
Definition: Map.cs:97
void ReloadRoom()
Definition: Map.cs:325
void CreateNew(int size, bool setReference=true)
Definition: Map.cs:153
void RefreshAllTiles()
Definition: Map.cs:2086
void Reset()
Definition: POIMap.cs:35
Definition: Point.cs:9
void SetObj(int id=0, int value=1, int dir=0)
Definition: Point.cs:892
List< Card > ListCards(bool includeMasked=false)
Definition: Point.cs:1015
Point Set(int _x, int _z)
Definition: Point.cs:479
void SetBlock(int idMat=0, int idBlock=0)
Definition: Point.cs:882
Definition: Rand.cs:4
static int Range(int min, int max)
Definition: Rand.cs:42
SourceMaterial materials
int lv
Definition: Spatial.cs:142
static Thing CreateFromCategory(string idCat, int lv=-1)
Definition: ThingGen.cs:75
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
bool IsValid(bool shouldLookGood=true)
Definition: TraitDoor.cs:115
virtual bool LockExit
Definition: Zone.cs:268
BiomeProfile biome
Definition: Zone.cs:126
virtual bool ShouldMakeExit
Definition: Zone.cs:359
MapGenerator Generator
Definition: Zone.cs:134
virtual void OnGenerateRooms(BaseMapGen gen)
Definition: Zone.cs:2525
override int DangerLv
Definition: Zone.cs:107
Card AddCard(Card t, Point point)
Definition: Zone.cs:1893