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