1 /**********************************************************************************
2 * Copyright (c) 2008, 2009 Derek Yu and Mossmouth, LLC
3 * Copyright (c) 2018, Ketmar Dark
5 * This file is part of Spelunky.
7 * You can redistribute and/or modify Spelunky, including its source code, under
8 * the terms of the Spelunky User License.
10 * Spelunky is distributed in the hope that it will be entertaining and useful,
11 * but WITHOUT WARRANTY. Please see the Spelunky User License for more details.
13 * The Spelunky User License should be available in "Game Information", which
14 * can be found in the Resource Explorer, or as an external file called COPYING.
15 * If not, please obtain a new copy of Spelunky from <http://spelunkyworld.com/>
17 **********************************************************************************/
18 // ////////////////////////////////////////////////////////////////////////// //
19 void scrLevGenShopkeeper (int xpos, int ypos, name shopType) {
20 auto obj = MonsterShopkeeper(MakeMapObject(xpos, ypos, 'oShopkeeper'));
22 //if (shopType == 'Ankh') writeln("::: ", shopType, " :::");
24 if (shopType == 'Craps') obj.generatePrizes();
29 // ////////////////////////////////////////////////////////////////////////// //
36 MapObject scrGenerateItem (int objx, int objy, GenItemSet setType) {
40 case GenItemSet.Crate: // crate set
41 if (global.randRoom(1, 500) == 1) obj = MakeMapObject(objx, objy, 'oJetpack');
42 else if (global.randRoom(1, 200) == 1) obj = MakeMapObject(objx, objy, 'oCapePickup');
43 else if (global.randRoom(1, 100) == 1) obj = MakeMapObject(objx, objy, 'oShotgun');
44 else if (!global.isTunnelMan && global.randRoom(1, 100) == 1) obj = MakeMapObject(objx, objy, 'oMattock');
45 else if (global.randRoom(1, 100) == 1) obj = MakeMapObject(objx, objy, 'oTeleporter');
46 else if (global.randRoom(1, 90) == 1) obj = MakeMapObject(objx, objy, 'oGloves');
47 else if (global.randRoom(1, 90) == 1) obj = MakeMapObject(objx, objy, 'oSpectacles');
48 else if (global.randRoom(1, 80) == 1) obj = MakeMapObject(objx, objy, 'oWebCannon');
49 else if (global.randRoom(1, 80) == 1) obj = MakeMapObject(objx, objy, 'oPistol');
50 else if (global.randRoom(1, 80) == 1) obj = MakeMapObject(objx, objy, 'oMitt');
51 else if (global.randRoom(1, 60) == 1) obj = MakeMapObject(objx, objy, 'oPaste');
52 else if (global.randRoom(1, 60) == 1) obj = MakeMapObject(objx, objy, 'oSpringShoes');
53 else if (global.randRoom(1, 60) == 1) obj = MakeMapObject(objx, objy, 'oSpikeShoes');
54 else if (global.randRoom(1, 60) == 1) obj = MakeMapObject(objx, objy, 'oMachete');
55 else if (global.randRoom(1, 40) == 1) obj = MakeMapObject(objx, objy, 'oBombBox');
56 else if (global.randRoom(1, 40) == 1) obj = MakeMapObject(objx, objy, 'oBow');
57 else if (global.randRoom(1, 20) == 1) obj = MakeMapObject(objx, objy, 'oCompass');
58 else if (global.randRoom(1, 10) == 1) obj = MakeMapObject(objx, objy, 'oParaPickup');
59 else obj = MakeMapObject(objx, objy, 'oRopePile');
62 case GenItemSet.Craps: // high end set -- craps game prizes
63 if (global.randRoom(1, 40) == 1) obj = MakeMapObject(objx, objy, 'oJetpack');
64 else if (global.randRoom(1, 25) == 1) obj = MakeMapObject(objx, objy, 'oCapePickup');
65 else if (global.randRoom(1, 20) == 1) obj = MakeMapObject(objx, objy, 'oShotgun');
66 else if (global.randRoom(1, 10) == 1) obj = MakeMapObject(objx, objy, 'oGloves');
67 else if (global.randRoom(1, 10) == 1) obj = MakeMapObject(objx, objy, 'oTeleporter');
68 else if (!global.isTunnelMan && global.randRoom(1, 8) == 1) obj = MakeMapObject(objx, objy, 'oMattock');
69 else if (global.randRoom(1, 8) == 1) obj = MakeMapObject(objx, objy, 'oPaste');
70 else if (global.randRoom(1, 8) == 1) obj = MakeMapObject(objx, objy, 'oSpringShoes');
71 else if (global.randRoom(1, 8) == 1) obj = MakeMapObject(objx, objy, 'oSpikeShoes');
72 else if (global.randRoom(1, 8) == 1) obj = MakeMapObject(objx, objy, 'oCompass');
73 else if (global.randRoom(1, 8) == 1) obj = MakeMapObject(objx, objy, 'oPistol');
74 else if (global.randRoom(1, 8) == 1) obj = MakeMapObject(objx, objy, 'oMachete');
75 else obj = MakeMapObject(objx, objy, 'oBombBox');
77 case GenItemSet.Underground: // Underground Set (items hidden inside solid walls, see oBrick etc)
78 switch (global.randRoom(0, 18)) {
79 case 0: obj = MakeMapObject(objx, objy-2, 'oJetpack'); break;
80 case 1: obj = MakeMapObject(objx, objy, 'oCapePickup'); break;
81 case 2: obj = MakeMapObject(objx, objy, 'oShotgun'); break;
83 if (global.isTunnelMan) obj = MakeMapObject(objx, objy, 'oRopePile');
84 else obj = MakeMapObject(objx, objy, 'oMattock');
86 case 4: obj = MakeMapObject(objx, objy+3, 'oTeleporter'); break;
87 case 5: obj = MakeMapObject(objx, objy-1, 'oGloves'); break;
88 case 6: obj = MakeMapObject(objx, objy, 'oSpectacles'); break;
89 case 7: obj = MakeMapObject(objx-2, objy, 'oWebCannon'); break;
90 case 8: obj = MakeMapObject(objx, objy, 'oPistol'); break;
91 case 9: obj = MakeMapObject(objx, objy-1, 'oMitt'); break;
92 case 10: obj = MakeMapObject(objx, objy, 'oPaste'); break;
93 case 11: obj = MakeMapObject(objx, objy, 'oSpringShoes'); break;
94 case 12: obj = MakeMapObject(objx, objy, 'oSpikeShoes'); break;
95 case 13: obj = MakeMapObject(objx, objy, 'oMachete'); break;
96 case 14: obj = MakeMapObject(objx, objy-2, 'oBombBox'); break;
97 case 15: obj = MakeMapObject(objx, objy, 'oBow'); break;
98 case 16: obj = MakeMapObject(objx, objy, 'oCompass'); break;
99 case 17: obj = MakeMapObject(objx, objy, 'oParaPickup'); break;
100 case 18: obj = MakeMapObject(objx, objy, 'oRopePile'); break;
109 // generate shop items
110 MapObject scrShopItemsGen (int xpos, int ypos, name shopType) {
111 MapObject obj = none;
113 writeln("generating items for shop \"", shopType, "\"...");
115 if (shopType == 'Bomb') {
117 if (global.randRoom(1, 5) == 1) {
118 if (!findAnyObjectOfType('oPaste')) { obj = MakeMapObject(xpos+8, ypos+10, 'oPaste'); break; }
119 } else if (global.randRoom(1, 4) == 1) {
120 obj = MakeMapObject(xpos+8, ypos+8, 'oBombBox');
122 } else if (global.config.optSGAmmo && global.randRoom(1, 10) == 1) {
123 obj = MakeMapObject(xpos+4, ypos+10, 'oShells');
126 if (global.config.optSGAmmo && findAnyObjectOfType('oShotgun')) {
127 obj = MakeMapObject(xpos+4, ypos+10, 'oShells');
129 obj = MakeMapObject(xpos+8, ypos+10, 'oBombBag');
134 } else if (shopType == 'Weapon') {
137 int n = global.randRoom(1, 4);
139 obj = MakeMapObject(xpos+8, ypos+10, 'oBombBag');
141 } else if (global.randRoom(1, 12) == 1) {
142 if (!findAnyObjectOfType('oWebCannon')) { obj = MakeMapObject(xpos+8, ypos+12, 'oWebCannon'); break; }
143 } else if (global.randRoom(1, 10) == 1) {
144 if (!findAnyObjectOfType('oShotgun')) { obj = MakeMapObject(xpos+8, ypos+12, 'oShotgun'); break; }
145 } else if (global.randRoom(1, 6) == 1) {
146 obj = MakeMapObject(xpos+8, ypos+10, 'oBombBox');
149 if (!findAnyObjectOfType('oPistol')) { obj = MakeMapObject(xpos+8, ypos+12, 'oPistol'); break; }
151 if (!findAnyObjectOfType('oMachete')) { obj = MakeMapObject(xpos+8, ypos+12, 'oMachete'); break; }
153 if (global.config.optSGAmmo && findAnyObjectOfType('oShotgun')) {
154 obj = MakeMapObject(xpos+4, ypos+10, 'oShells');
156 obj = MakeMapObject(xpos+8, ypos+10, 'oBombBag');
160 if (!findAnyObjectOfType('oBow')) { obj = MakeMapObject(xpos+8, ypos+12, 'oBow'); break; }
164 } else if (shopType == 'Clothing') {
167 int n = global.randRoom(1, 6);
168 if (global.randRoom(1, m) == 1) { obj = MakeMapObject(xpos+8, ypos+11, 'oRopePile'); break; }
169 else if (n == 1) { if (!findAnyObjectOfType('oSpringShoes')) { obj = MakeMapObject(xpos+8, ypos+10, 'oSpringShoes'); break; } }
170 else if (n == 2) { if (!findAnyObjectOfType('oSpectacles')) { obj = MakeMapObject(xpos+8, ypos+10, 'oSpectacles'); break; } }
171 else if (n == 3) { if (!findAnyObjectOfType('oGloves')) { obj = MakeMapObject(xpos+8, ypos+8, 'oGloves'); break; } }
172 else if (n == 4) { if (!findAnyObjectOfType('oMitt')) { obj = MakeMapObject(xpos+8, ypos+8, 'oMitt'); break; } }
173 else if (n == 5) { if (!findAnyObjectOfType('oCapePickup')) { obj = MakeMapObject(xpos+8, ypos+10, 'oCapePickup'); break; } }
174 else if (n == 6) { if (!findAnyObjectOfType('oSpikeShoes')) { obj = MakeMapObject(xpos+8, ypos+10, 'oSpikeShoes'); break; } }
177 } else if (shopType == 'Rare') {
180 int n = global.randRoom(1, 11);
181 if (global.randRoom(1, m) == 1) { obj = MakeMapObject(xpos+8, ypos+8, 'oBombBox'); break; }
182 else if (n == 1) { if (!findAnyObjectOfType('oSpringShoes')) { obj = MakeMapObject(xpos+8, ypos+10, 'oSpringShoes'); break; } }
183 else if (n == 2) { if (!findAnyObjectOfType('oCompass')) { obj = MakeMapObject(xpos+8, ypos+10, 'oCompass'); break; } }
184 else if (n == 3) { if (!findAnyObjectOfType('oMattock') && !global.isTunnelMan) { obj = MakeMapObject(xpos+8, ypos+10, 'oMattock'); break; } }
185 else if (n == 4) { if (!findAnyObjectOfType('oSpectacles')) { obj = MakeMapObject(xpos+8, ypos+10, 'oSpectacles'); break; } }
186 else if (n == 5) { if (!findAnyObjectOfType('oJetpack')) { obj = MakeMapObject(xpos+8, ypos+8, 'oJetpack'); break; } }
187 else if (n == 6) { if (!findAnyObjectOfType('oGloves')) { obj = MakeMapObject(xpos+8, ypos+8, 'oGloves'); break; } }
188 else if (n == 7) { if (!findAnyObjectOfType('oMitt')) { obj = MakeMapObject(xpos+8, ypos+8, 'oMitt'); break; } }
189 else if (n == 8) { if (!findAnyObjectOfType('oWebCannon')) { obj = MakeMapObject(xpos+8, ypos+12, 'oWebCannon'); break; } }
190 else if (n == 9) { if (!findAnyObjectOfType('oCapePickup')) { obj = MakeMapObject(xpos+8, ypos+10, 'oCapePickup'); break; } }
191 else if (n == 10) { if (!findAnyObjectOfType('oTeleporter')) { obj = MakeMapObject(xpos+8, ypos+12, 'oTeleporter'); break; } }
192 else if (n == 11) { if (!findAnyObjectOfType('oSpikeShoes')) { obj = MakeMapObject(xpos+8, ypos+10, 'oSpikeShoes'); break; } }
197 int n = global.randRoom(1, 3);
198 if (global.randRoom(1, 20) == 1) { if (!findAnyObjectOfType('oMattock') && !global.isTunnelMan) { obj = MakeMapObject(xpos+8, ypos+10, 'oMattock'); break; } }
199 else if (global.randRoom(1, 10) == 1) { if (!findAnyObjectOfType('oGloves')) { obj = MakeMapObject(xpos+8, ypos+8, 'oGloves'); break; } }
200 else if (global.randRoom(1, 10) == 1) { if (!findAnyObjectOfType('oCompass')) { obj = MakeMapObject(xpos+8, ypos+10, 'oCompass'); break; } }
202 if (global.config.optSGAmmo && findAnyObjectOfType('oShotgun')) {
203 obj = MakeMapObject(xpos+4, ypos+10, 'oShells');
205 obj = MakeMapObject(xpos+8, ypos+10, 'oBombBag');
208 } else if (n == 2) { obj = MakeMapObject(xpos+8, ypos+11, 'oRopePile'); break; }
209 else if (n == 3) { obj = MakeMapObject(xpos+8, ypos+10, 'oParaPickup'); break; }
215 obj.shopType = shopType;
216 if (global.currLevel > 2) {
217 if (obj.cost <= 0) obj.cost = 100;
218 obj.cost += (obj.cost/100)*10*(global.currLevel-2);
219 //if (shopDesc == "") buyMessage = "A "+string_upper(type)+" FOR $"+string(cost)+".";
220 //else buyMessage = shopDesc+" FOR $"+string(cost)+".";
228 // ////////////////////////////////////////////////////////////////////////// //
229 //WARNING: keep this in sync with `ItemJar::onDestroy()`!
230 name scrLevGenCreateJarContents () {
233 if (global.randRoom(1, 3) == 1) ctx = 'oGoldChunk';
234 else if (global.config.optSGAmmo && global.randRoom(1, 4) == 1) ctx = 'oShellSingle';
235 else if (global.randRoom(1, 6) == 1) ctx = 'oGoldNugget';
236 else if (global.randRoom(1, 12) == 1) ctx = 'oEmeraldBig';
237 else if (global.randRoom(1, 12) == 1) ctx = 'oSapphireBig';
238 else if (global.randRoom(1, 12) == 1) ctx = 'oRubyBig';
239 else if (global.randRoom(1, 6) == 1) ctx = 'oSpider';
240 else if (global.randRoom(1, 12) == 1) { if (global.randRoom(1, 50) == 1) ctx = 'oCobra'; else ctx = 'oSnake'; }
241 else if (global.randRoom(1, 100) == 1) ctx = 'oAlien';
242 else if (global.randRoom(1, 300) == 1) ctx = 'oBlob';
245 switch (global.randRoom(0, 2)) {
246 case 0: ctx = 'oEmeraldBig'; break;
247 case 1: ctx = 'oSapphireBig'; break;
248 case 2: ctx = 'oRubyBig'; break;
256 final MapObject scrLevGenCreateJar (int x, int y) {
257 auto obj = MakeMapObject(x, y, 'oJar');
258 MapItem(obj).contents = scrLevGenCreateJarContents();
263 // ////////////////////////////////////////////////////////////////////////// //
264 final bool cbIsGoldIdol (MapObject o) { return (o isa ItemGoldIdol); }
265 final bool cbIsGiantSpider (MapObject o) { return (o isa EnemyGiantSpider); }
266 final bool cbIsChestObject (MapObject o) { return (o isa ItemChest); }
268 final bool cbIsTreasureTile (MapTile t) { return !!t.gem; } //K8:FIXME: only real treasures?
269 final bool cbIsBadTile (MapTile t) { return (t.spikes || t.enter || t.exit); }
270 final bool cbIsBlockTile (MapTile t) { return (t.objType == 'oBlock'); }
271 final bool cbIsLiquidTile (MapTile t) { return (t.water || t.lava); }
274 // Generates crates, chests, gold, gems, and bones
275 void scrTreasureGen (int x, int y, optional int bonesChance) {
279 if (calcNearestEnterDist(x+8, y+8) < 32) return;
280 if (calcNearestExitDist(x+8, y+8) < 32) return;
281 if (calcNearestObjectDist(x+8, y+8, &cbIsGoldIdol) < 64) return;
284 isSolidAtPoint(x, y-16) ||
285 checkTileAtPoint(x, y-1, &cbIsTreasureTile) ||
286 isObjectAtTilePix(x, y-8, &cbIsChestObject) || //<-collision_point(x, y-8, oChest, 0, 0) &&
287 checkTileAtPoint(x, y-8, &cbIsBadTile);
290 if (global.randRoom(1, 100) == 1) { MakeMapObject(x+8, y-4, 'oRock'); return; }
291 if (global.randRoom(1, 40) == 1) { scrLevGenCreateJar(x+8, y-6); return; }
296 isSolidAtPoint(x, y-32) &&
297 (isSolidAtPoint(x-16, y-16) ||
298 isSolidAtPoint(x+16, y-16) ||
299 checkTileAtPoint(x-16, y-16, &cbIsBlockTile) ||
300 checkTileAtPoint(x+16, y-16, &cbIsBlockTile)))
303 if (calcNearestObjectDist(x+8, y+8, &cbIsGiantSpider) < 100) n = 5;
304 if (global.levelType != 2 && global.randRoom(1, n) == 1) {
305 MakeMapObject(x, y-16, 'oWeb');
306 } else if (global.genUdjatEye && !global.LockedChest) {
307 if (global.randRoom(1, global.lockedChestChance) == 1) {
308 MakeMapObject(x+8, y-16, 'oLockedChest');
309 global.LockedChest = true;
310 writeln("*** GENERATED LOCKED CHEST");
312 global.lockedChestChance -= 1;
314 } else if (global.randRoom(1, 10) == 1) {
315 scrLevGenCreateCrate(x+8, y-8);
316 } else if (global.randRoom(1, 15) == 1) {
317 scrLevGenCreateChest(x+8, y-8);
318 } else if (!global.damsel && global.randRoom(1, 8) == 1 && !checkTileAtPoint(x+8, y-8, &cbIsLiquidTile)) {
319 auto obj = MakeMapObject(x+8, y-8, 'oDamsel');
320 if (obj) global.damsel = true;
321 } else if (global.randRoom(1, 40-2*global.currLevel) <= 1+bonesChance) {
322 //writeln("=== BONES ===");
323 if (global.randRoom(1, 8) == 1) {
324 MakeMapObject(x, y-16, 'oFakeBones');
326 MakeMapObject(x, y-16, 'oBones');
327 MakeMapObject(x+12, y-4, 'oSkull');
330 else if (global.randRoom(1, 3) == 1) MakeMapObject(x+8, y-4, 'oGoldBar');
331 else if (global.randRoom(1, 6) == 1) MakeMapObject(x+8, y-8, 'oGoldBars');
332 else if (global.randRoom(1, 6) == 1) MakeMapObject(x+8, y-4, 'oEmeraldBig');
333 else if (global.randRoom(1, 8) == 1) MakeMapObject(x+8, y-4, 'oSapphireBig');
334 else if (global.randRoom(1, 10) == 1) MakeMapObject(x+8, y-4, 'oRubyBig');
335 //else if (global.bizarre && randRoom(1, 6) == 1) {obj = MakeMapObject(x+8, y-8, 'oAntidote'); obj.cost = 0; obj.forSale = false} // in the original
337 else if (!colStuff && isSolidAtPoint(x-16, y-16) && isSolidAtPoint(x+16, y-16)) {
339 if (calcNearestObjectDist(x+8, y+8, &cbIsGiantSpider) < 100) n = 10;
340 if (global.levelType != 2 && global.randRoom(1, n) == 1) MakeMapObject(x, y-16, 'oWeb');
341 else if (global.randRoom(1, 4) == 1) MakeMapObject(x+8, y-4, 'oGoldBar');
342 else if (global.randRoom(1, 8) == 1) MakeMapObject(x+8, y-8, 'oGoldBars');
343 else if (global.randRoom(1, 80-global.currLevel) <= 1+bonesChance) {
344 if (global.randRoom(1, 8) == 1) {
345 MakeMapObject(x, y-16, 'oFakeBones');
347 MakeMapObject(x, y-16, 'oBones');
348 MakeMapObject(x+12, y-4, 'oSkull');
351 else if (global.randRoom(1, 8) == 1) MakeMapObject(x+8, y-4, 'oEmeraldBig');
352 else if (global.randRoom(1, 9) == 1) MakeMapObject(x+8, y-4, 'oSapphireBig');
353 else if (global.randRoom(1, 10) == 1) MakeMapObject(x+8, y-4, 'oRubyBig');
354 //else if (global.bizarre && randRoom(1, 10) == 1) {obj = MakeMapObject(x+8, y-8, 'oAntidote'); obj.cost = 0; obj.forSale = false} // in the original
356 else if (!isSolidAtPoint(x, y-16) &&
357 isObjectAtTilePix(x, y-8, &cbIsChestObject) && //<-collision_point(x, y-8, oChest, 0, 0) &&
358 !checkTileAtPoint(x, y-8, &cbIsBadTile))
360 if (global.randRoom(1, 40) == 1) MakeMapObject(x+8, y-4, 'oGoldBar');
361 else if (global.randRoom(1, 50) == 1) MakeMapObject(x+8, y-8, 'oGoldBars');
362 else if (global.randRoom(1, 140-2*global.currLevel) <= 1+bonesChance) {
363 if (global.randRoom(1, 8) == 1) {
364 MakeMapObject(x, y-16, 'oFakeBones');
366 MakeMapObject(x, y-16, 'oBones');
367 MakeMapObject(x+12, y-4, 'oSkull');
374 // ////////////////////////////////////////////////////////////////////////// //
375 name scrGenGetFrogType () {
376 if (global.config.optEnemyVariations) {
377 int totdeath789 = stats.getDeathCountOnLevel(7)+stats.getDeathCountOnLevel(8)+stats.getDeathCountOnLevel(9);
378 if (totdeath789 < 22) {
379 if (global.randOther(0, 100) >= 99-(global.currLevel-4)*8) return 'oGreenFrog';
382 if (totdeath789 < 32) {
383 if (global.randOther(0, 100) >= 85-(global.currLevel-4)*8) return 'oGreenFrog';
386 if (totdeath789 < 42) {
387 if (global.randOther(0, 100) >= 75-(global.currLevel-4)*8) return 'oGreenFrog';
390 if (totdeath789 < 52) {
391 if (global.randOther(0, 100) >= 65-(global.currLevel-4)*8) return 'oGreenFrog';
394 if (totdeath789 < 62) {
395 if (global.randOther(0, 100) >= 55-(global.currLevel-4)*8) return 'oGreenFrog';
398 if (global.randOther(0, 100) >= 50-(global.currLevel-4)*8) return 'oGreenFrog';
404 // ////////////////////////////////////////////////////////////////////////// //
406 private final bool scrGenEntitiesInMinesCB (int tileX, int tileY, MapTile t) {
407 if (!isInShop(tileX, tileY) && tileY > 1) {
408 if (t.objType != 'Altar') {
409 scrTreasureGen(tileX*16, tileY*16);
412 tileXY2roomXY(tileX, tileY-1, roomX, roomY); //k8: why -1?
414 if (roomX != startRoomX || roomY != startRoomY) {
415 if (tileY < GameLevel::NormalTilesHeight-4 &&
416 !checkTilesInRect(tileX*16, (tileY+1)*16, 17, 33, &cbCollisionAnySolidOrLiquid) &&
417 !isObjectAtPoint(tileX*16+8, (tileY+1)*16+8))
419 if (global.genGiantSpider && !global.giantSpider &&
420 global.randRoom(1, trunc(ceil(40.0/global.config.enemyMult))) == 1 &&
421 !checkTilesInRect((tileX+1)*16, (tileY+1)*16, 17, 33, &cbCollisionAnySolid/*k8:???OrLiquid*/))
423 MakeMapObject(tileX*16, (tileY+1)*16, 'oGiantSpiderHang');
424 global.giantSpider = true;
426 else if (global.darkLevel && global.randRoom(1, 60) == 1) MakeMapTile(tileX, tileY+1, 'oLamp');
427 else if (global.darkLevel && global.randRoom(1, 40) == 1) MakeMapObject(tileX*16, (tileY+1)*16, 'oScarab');
428 else if (global.randRoom(1, trunc(ceil(60.0/global.config.enemyMult))) == 1) MakeMapObject(tileX*16, (tileY+1)*16, 'oBat');
429 else if (global.randRoom(1, trunc(ceil(80.0/global.config.enemyMult))) == 1) MakeMapObject(tileX*16, (tileY+1)*16, scrGenGetSpiderType());
431 if (global.giantSpider && global.config.enemyMult >= 2) {
432 if (global.randRoom(1, trunc(ceil(2400.0/global.config.enemyMult))) == 1) {
433 global.genGiantSpider = true;
434 global.giantSpider = false;
437 if (!checkTileAtPoint(tileX*16, (tileY-1)*16, &cbCollisionAnySolid/*k8:???OrLiquid*/)) {
438 if (global.randRoom(1, trunc(ceil(60.0/global.config.enemyMult))) == 1) {
439 MakeMapObject(tileX*16, (tileY-1)*16, scrGenGetSnakeType());
440 } else if (global.randRoom(1, trunc(ceil(800.0/global.config.enemyMult))) == 1) {
441 MakeMapObject(tileX*16, (tileY-1)*16, 'oCaveman');
446 // `false` means "continue"
452 // ////////////////////////////////////////////////////////////////////////// //
453 final bool isTreasureObjectCB (MapObject o) { return o.isTreasure; }
454 final bool isChestObjectCB (MapObject o) { return (o isa ItemOpenableContainer); } // not only chest, but a crate too
456 //private transient bool ashGraveGenerated;
459 // generates enemies, traps, and treasure
461 final void scrGenerateEntities () {
462 } else if (global.levelType == 2) {
463 // level type 2 (ice caves)
466 if (!isInShop(x, y)) {
469 if (global.yetiLair) n = 90;
471 if (scrGetRoomX(x) != global.startRoomX || scrGetRoomY(y-16) != global.startRoomY) {
472 if (y < room_height-64 &&
473 !collision_point(x, y+16, oSolid, 0, 0) && !collision_point(x, y+32, oSolid, 0, 0) &&
474 !collision_point(x, y+16, oWater, 0, 0) && !collision_point(x, y+32, oWater, 0, 0))
476 if (global.darkLevel && global.randRoom(1, 40) == 1) MakeMapObject(x, y+16, 'oScarab');
477 } else if (y > 16 && y < 592 && !collision_point(x, y-16, oSolid, 0, 0) && !isInShop(x, y)) {
478 if (global.randRoom(1, ceil(float(n)/ceil(global.config.enemyMult/2.0))) == 1) MakeMapObject(x, y-16, 'oUFO');
482 if (y > 16 && y < 592 &&
483 !collision_point(x, y-16, oSolid, 0, 0) &&
484 !collision_point(x+8, y-8, oEnemy, 0, 0) &&
485 !collision_point(x+8, y-1, oSpikes, 0, 0) &&
486 !collision_point(x+8, y-1, oSpikesWood, 0, 0) &&
487 point_distance(x, y, oEntrance.x, oEntrance.y) > 64 &&
490 if (global.randRoom(1, ceil(10.0/global.trapMult)) == 1 && sprite_index == sDark && !collision_rectangle(x, y-64, x+15, y-1, oSolid, 0, 0) && distance_to_object(oExit) > 64) MakeMapObject(x, y-16, 'oSpringTrap');
491 else if (global.randRoom(1, ceil(20.0/global.config.enemyMult)) == 1 && point_distance(x, y, oEntrance.x, oEntrance.y) > 64) MakeMapObject(x, y-16, 'oYeti');
494 if (type != "Altar") scrTreasureGen();
498 } else if (global.levelType == 3) {
499 // level type 3 (temple)
501 global.TombLord = false;
502 global.totalTombLords = 0;
503 global.gaveSceptre = false;
504 global.genTombLord = false;
505 if (global.currLevel == 13) global.genTombLord = true;
506 else if (global.randRoom(1, ceil(4.0/global.config.enemyMult)) == 1) global.genTombLord = true;
508 global.genGoldEntrance = false;
509 if (global.currLevel == 14) global.genGoldEntrance = true;
510 global.madeGoldEntrance = false;
514 if (global.randRoom(1, 100) == 1 && !collision_point(x, y-16, oSolid, 0, 0)) tile_add(bgStatues, 0, 0, 16, 48, x, y-32, 9005);
516 if (!isInShop(x, y)) {
518 if (y > 32 && !collision_point(x, y-16, oSolid, 0, 0) && global.genGoldEntrance && !global.madeGoldEntrance) {
519 if (global.randRoom(1, global.goldChance) == 1) {
520 MakeMapObject(x, y-16, 'oGoldDoor');
522 global.madeGoldEntrance = true;
524 global.goldChance -= 1;
526 } else if (type != "Tree" && type != "Altar" && y != 0 &&
527 !collision_point(x, y-16, oSolid, 0, 0) &&
528 !collision_point(x, y-16, oLava, 0, 0) &&
529 !collision_rectangle(x, y-16, x+15, y-1, oEnemy, 0, 0) &&
530 !collision_point(x, y-32, oSolid, 0, 0) &&
531 (!collision_point(x-16, y, oSolid, 0, 0) || !collision_point(x+16, y, oSolid, 0, 0)) &&
532 collision_point(x, y+16, oSolid, 0, 0) &&
534 x != 160 && x != 176 && x != 320 && x != 336 && x != 480 && x != 496)
536 if (global.randRoom(1, ceil(12.0/global.trapMult)) == 1 && point_distance(x, y, oEntrance.x, oEntrance.y) > 64) {
537 // to keep the spear trap from plugging up lava passage
538 if (collision_point(x-16, y-32, oSolid, 0, 0) && collision_point(x+16, y-32, oSolid, 0, 0) &&
539 !collision_point(x, y-32, oSolid, 0, 0))
543 if (collision_point(x, y-16, oSolid, 0, 0)) {
544 sol = instance_nearest(x, y-16, oSolid);
545 with (sol) { cleanDeath = true; instance_destroy(); }
547 MakeMapObject(x, y, 'oSpearTrapBottom');
548 if (global.darkLevel) MakeMapObject(x, y-16, 'oSpearTrapLit');
549 else MakeMapObject(x, y-16, 'oSpearTrapTop');
557 if (y < room_height-64 &&
558 !collision_point(x, y+16, oSolid, 0, 0) && !collision_point(x, y+32, oSolid, 0, 0) &&
559 !collision_point(x, y+16, oWater, 0, 0) && !collision_point(x, y+32, oWater, 0, 0))
561 if (global.darkLevel && global.randRoom(1, 40) == 1) MakeMapObject(x, y+16, 'oScarab');
564 if (scrGetRoomX(x) != global.startRoomX || scrGetRoomY(y-16) != global.startRoomY &&
565 !collision_point(x, y-16, oEnemy, 0, 0))
567 if (y > 16 && !collision_point(x, y-16, oSolid, 0, 0)) {
568 if (global.genTombLord &&
570 !collision_rectangle(x, y-32, x+32, y-1, oSolid, 0, 0) &&
571 global.randRoom(1, ceil(40.0/global.config.enemyMult)) == 1)
573 obj = MakeMapObject(x, y-32, 'oTombLord');
574 global.totalTombLords += 1;
575 if (global.currLevel == 13) {
576 if (!global.gaveSceptre) {
577 if (global.randRoom(1, global.config.enemyMult) == 1) {
578 obj.hasSceptre = true;
579 global.gaveSceptre = true;
582 if (global.randRoom(1, global.config.enemyMult) == 1 || global.totalTombLords >= global.config.enemyMult) global.TombLord = true; // don't make any more tomb lords
583 if (global.TombLord == true && !global.gaveSceptre) {
584 obj.hasSceptre = true;
585 global.gaveSceptre = true;
589 else if (global.randRoom(1, ceil(40.0/global.config.enemyMult)) == 1) MakeMapObject(x, y-16, 'oCaveman');
590 else if (global.randRoom(1, ceil(40.0/global.config.enemyMult)) == 1) MakeMapObject(x, y-16, 'oHawkman');
591 else if (global.randRoom(1, ceil(60.0/global.config.trapMult)) == 1) {
592 if (global.darkLevel) MakeMapObject(x, y-16, 'oSmashTrapLit'); else MakeMapObject(x, y-16, 'oSmashTrap');
598 if (scrGetRoomX(x) != global.startRoomX || scrGetRoomY(y) != global.startRoomY) &&
599 y >=16 && y < room_height-64 &&
600 !collision_rectangle(x, y+16, x+15, y+64, oSolid, 0, 0)
602 if randRoom(1, ceil(60.0/global.trapMult)) == 1 MakeMapObject(x, y+16, 'oThwompTrap');
606 if (type != "Altar") scrTreasureGen();
610 // force generate tomb lord
611 if (global.currLevel == 13 && global.genTombLord && !global.TombLord) {
612 if (findAnyObjectOfType('oExit')) {
613 obj = MakeMapObject(oExit.x, oExit.y-16, 'oTombLord');
614 global.totalTombLords += 1;
615 obj.hasSceptre = true;
616 global.gaveSceptre = true;
620 // force generate gold door
621 if (global.genGoldEntrance && !global.madeGoldEntrance) {
623 if (y > 32 && !collision_point(x, y-16, oSolid, 0, 0)) {
624 MakeMapObject(x, y-16, 'oGoldDoor');
626 global.madeGoldEntrance = true;
634 if (!isInShop(x, y)) {
635 n = point_distance(x, y, oEntrance.x, oEntrance.y);
636 if (!isInShop(x, y) &&
637 global.randRoom(1, ceil(3.0/global.trapMult)) == 1 && !(y == oEntrance.y && n < 144) &&
640 if (collision_point(x+16, y, oSolid, 0, 0) && !collision_rectangle(x-32, y, x-1, y+15, oSolid, 0, 0))
642 if (global.darkLevel) MakeMapObject(x, y, 'oArrowTrapLeftLit'); else MakeMapObject(x, y, 'oArrowTrapLeft');
645 } else if (collision_point(x-16, y, oSolid, 0, 0) && !collision_rectangle(x+16, y, x+48, y+15, oSolid, 0, 0))
647 if (global.darkLevel) MakeMapObject(x, y, 'oArrowTrapRightLit'); else MakeMapObject(x, y, 'oArrowTrapRight');
655 if (global.trapMult >= 2) {
657 if (!isInShop(x, y)) {
658 n = point_distance(x, y, oEntrance.x, oEntrance.y);
659 if (!isInShop(x, y) &&
660 global.randRoom(1, ceil(60.0/global.trapMult)) == 1 &&
661 x >= 16 && x < room_width -16 && !(y == oEntrance.y && n < 144) &&
664 if (collision_point(x+16, y, oSolid, 0, 0) && !collision_rectangle(x-32, y, x-1, y+15, oSolid, 0, 0))
666 if (global.darkLevel) MakeMapObject(x, y, 'oArrowTrapLeftLit'); else MakeMapObject(x, y, 'oArrowTrapLeft');
669 } else if (collision_point(x-16, y, oSolid, 0, 0) && !collision_rectangle(x+16, y, x+48, y+15, oSolid, 0, 0))
671 if (global.darkLevel) MakeMapObject(x, y, 'oArrowTrapRightLit'); else MakeMapObject(x, y, 'oArrowTrapRight');
682 // add box of flares to dark level
684 if (global.darkLevel) {
686 if (!collision_point(x-16, y, oSolid, 0, 0)) MakeMapObject(x-16+8, y+8, 'oFlareCrate');
687 else if (!collision_point(x+16, y, oSolid, 0, 0)) MakeMapObject(x+16+8, y+8, 'oFlareCrate');
688 else MakeMapObject(x+8, y+8, 'oFlareCrate');
693 //k8: this is hack in the original, so destroyed tiles won't generate treasure
694 //global.cleanSolids = false;