13 {
14 DunGen.Init();
16 MapData mapData = DunGen.Generate(generator);
17 width = mapData.size_X + 2;
18 height = mapData.size_Y + 2;
26 {
27 biome = biome.Instantiate();
36 }
37 if (biome.name == "Dungeon_Water")
38 {
40 biome.exterior.block.id = (biome.interior.block.id = num);
41 if (num == 189)
42 {
44 }
45 else
46 {
47 biome.exterior.block.mat = (biome.interior.block.mat = 3);
48 }
49 }
52 int idMat = -1;
54 {
57 {
58 idMat = 5;
59 }
60 }
61 bool flag = zone.lv <= 0;
62 bool flag2 = false;
63 bool flag3 = false;
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 {
75 continue;
76 }
77 Dungen.Cell cell = mapData.cellsOnMap[i - 1, j - 1];
78 CellType type = cell.type;
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;
92 if (!flag)
93 {
94 thing = thing4;
95 }
96 else
97 {
98 thing2 = thing4;
99 }
101 break;
102 }
103 case "Exit":
104 {
106 {
107 break;
108 }
109 if (flag3)
110 {
111 Debug.LogError(
"exception: already created exit");
112 break;
113 }
114 flag3 = true;
116 if (flag)
117 {
118 thing = thing3;
119 }
120 else
121 {
122 thing2 = thing3;
123 }
125 break;
126 }
127 case "Door":
129 {
133 }
134 break;
135 case "Abyss":
137 break;
138 default:
139 if (type.passable == generator.reversePassage)
140 {
142 }
143 break;
144 }
145 if (!cell.isRoomCell)
146 {
148 }
149 }
150 }
151 if (!flag2)
152 {
153 Debug.LogError(
"exception: Failed to create entrance:");
154 return false;
155 }
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 {
189 SetRoom(genRoomBig);
190 }
191 else
192 {
193 foreach (Dungen.Room room2 in mapData.rooms)
194 {
197 SetRoom(genRoom);
198 }
199 }
201 foreach (
GenRoom value
in rooms.Values)
202 {
204 }
207 Debug.Log(
"Dungen: room:" + rooms.Count +
"/" + mapData.rooms.Count +
" width:" +
width +
" height:" +
height);
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 {
218 {
221 }
222 }
225 {
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 }
260 {
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 {
279 {
281 {
283 }
284 }
287 t.pos.cell.height = 0;
288 }
290 {
293 room.gen = this;
295 rooms[room.
Index] = room;
297 Debug.Log(
"Room" + count +
" " + room.
width +
"*" + room.
height +
" " + room);
298 count++;
299 }
300 }
void SetSize(int size, int _poiSize)
string GetIdStairs(bool upstairs)
void Populate(Point point, bool interior=false)
static Crawler Create(string id)
bool CrawlUntil(Map map, Func< Point > onStart, int tries, Func< Result, bool > canComplete, Action onFail=null)
static SourceManager sources
static int rndSeed(int a, int seed)
void SetBlock(BiomeProfile.Tile t, int x, int z, int idMat=-1)
void SetFloor(BiomeProfile.Tile t, int x, int z)
void Init(Dungen.Room room)
static SourceMaterial.Row GetRandomMaterialFromCategory(int lv, string cat, SourceMaterial.Row fallback)
Point GetRandomPoint(Point center, int radius, int tries=100, bool mustBeWalkable=true, bool requireLos=true)
void CreateNew(int size, bool setReference=true)
void SetObj(int id=0, int value=1, int dir=0)
List< Card > ListCards(bool includeMasked=false)
Point Set(int _x, int _z)
void SetBlock(int idMat=0, int idBlock=0)
static int Range(int min, int max)
static Thing CreateFromCategory(string idCat, int lv=-1)
static Thing Create(string id, int idMat=-1, int lv=-1)
bool IsValid(bool shouldLookGood=true)
virtual bool ShouldMakeExit
virtual void OnGenerateRooms(BaseMapGen gen)
Card AddCard(Card t, Point point)