Source:NetHack 3.6.2/src/mkmaze.c
Jump to navigation
Jump to search
Below is the full text to mkmaze.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/mkmaze.c#line12]], for example.
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* NetHack 3.6 mkmaze.c $NHDT-Date: 1555022325 2019/04/11 22:38:45 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.68 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Pasi Kallinen, 2018. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. #include "sp_lev.h" 8. #include "lev.h" /* save & restore info */ 9. 10. /* from sp_lev.c, for fixup_special() */ 11. extern lev_region *lregions; 12. extern int num_lregions; 13. /* for preserving the insect legs when wallifying baalz level */ 14. static lev_region bughack = { {COLNO, ROWNO, 0, 0}, {COLNO, ROWNO, 0, 0} }; 15. 16. STATIC_DCL int FDECL(iswall, (int, int)); 17. STATIC_DCL int FDECL(iswall_or_stone, (int, int)); 18. STATIC_DCL boolean FDECL(is_solid, (int, int)); 19. STATIC_DCL int FDECL(extend_spine, (int[3][3], int, int, int)); 20. STATIC_DCL boolean FDECL(okay, (int, int, int)); 21. STATIC_DCL void FDECL(maze0xy, (coord *)); 22. STATIC_DCL boolean FDECL(put_lregion_here, (XCHAR_P, XCHAR_P, XCHAR_P, 23. XCHAR_P, XCHAR_P, XCHAR_P, 24. XCHAR_P, BOOLEAN_P, d_level *)); 25. STATIC_DCL void NDECL(baalz_fixup); 26. STATIC_DCL void NDECL(setup_waterlevel); 27. STATIC_DCL void NDECL(unsetup_waterlevel); 28. STATIC_DCL void FDECL(check_ransacked, (char *)); 29. STATIC_DCL void FDECL(migr_booty_item, (int, const char *)); 30. STATIC_DCL void FDECL(migrate_orc, (struct monst *, unsigned long)); 31. STATIC_DCL void NDECL(stolen_booty); 32. 33. /* adjust a coordinate one step in the specified direction */ 34. #define mz_move(X, Y, dir) \ 35. do { \ 36. switch (dir) { \ 37. case 0: --(Y); break; \ 38. case 1: (X)++; break; \ 39. case 2: (Y)++; break; \ 40. case 3: --(X); break; \ 41. default: panic("mz_move: bad direction %d", dir); \ 42. } \ 43. } while (0) 44. 45. STATIC_OVL int 46. iswall(x, y) 47. int x, y; 48. { 49. int type; 50. 51. if (!isok(x, y)) 52. return 0; 53. type = levl[x][y].typ; 54. return (IS_WALL(type) || IS_DOOR(type) 55. || type == SDOOR || type == IRONBARS); 56. } 57. 58. STATIC_OVL int 59. iswall_or_stone(x, y) 60. int x, y; 61. { 62. /* out of bounds = stone */ 63. if (!isok(x, y)) 64. return 1; 65. 66. return (levl[x][y].typ == STONE || iswall(x, y)); 67. } 68. 69. /* return TRUE if out of bounds, wall or rock */ 70. STATIC_OVL boolean 71. is_solid(x, y) 72. int x, y; 73. { 74. return (boolean) (!isok(x, y) || IS_STWALL(levl[x][y].typ)); 75. } 76. 77. /* 78. * Return 1 (not TRUE - we're doing bit vectors here) if we want to extend 79. * a wall spine in the (dx,dy) direction. Return 0 otherwise. 80. * 81. * To extend a wall spine in that direction, first there must be a wall there. 82. * Then, extend a spine unless the current position is surrounded by walls 83. * in the direction given by (dx,dy). E.g. if 'x' is our location, 'W' 84. * a wall, '.' a room, 'a' anything (we don't care), and our direction is 85. * (0,1) - South or down - then: 86. * 87. * a a a 88. * W x W This would not extend a spine from x down 89. * W W W (a corridor of walls is formed). 90. * 91. * a a a 92. * W x W This would extend a spine from x down. 93. * . W W 94. */ 95. STATIC_OVL int 96. extend_spine(locale, wall_there, dx, dy) 97. int locale[3][3]; 98. int wall_there, dx, dy; 99. { 100. int spine, nx, ny; 101. 102. nx = 1 + dx; 103. ny = 1 + dy; 104. 105. if (wall_there) { /* wall in that direction */ 106. if (dx) { 107. if (locale[1][0] && locale[1][2] /* EW are wall/stone */ 108. && locale[nx][0] && locale[nx][2]) { /* diag are wall/stone */ 109. spine = 0; 110. } else { 111. spine = 1; 112. } 113. } else { /* dy */ 114. if (locale[0][1] && locale[2][1] /* NS are wall/stone */ 115. && locale[0][ny] && locale[2][ny]) { /* diag are wall/stone */ 116. spine = 0; 117. } else { 118. spine = 1; 119. } 120. } 121. } else { 122. spine = 0; 123. } 124. 125. return spine; 126. } 127. 128. /* Remove walls totally surrounded by stone */ 129. void 130. wall_cleanup(x1, y1, x2, y2) 131. int x1, y1, x2, y2; 132. { 133. uchar type; 134. int x, y; 135. struct rm *lev; 136. 137. /* sanity check on incoming variables */ 138. if (x1 < 0 || x2 >= COLNO || x1 > x2 || y1 < 0 || y2 >= ROWNO || y1 > y2) 139. panic("wall_cleanup: bad bounds (%d,%d) to (%d,%d)", x1, y1, x2, y2); 140. 141. /* change walls surrounded by rock to rock. */ 142. for (x = x1; x <= x2; x++) 143. for (y = y1; y <= y2; y++) { 144. if (within_bounded_area(x, y, 145. bughack.inarea.x1, bughack.inarea.y1, 146. bughack.inarea.x2, bughack.inarea.y2)) 147. continue; 148. lev = &levl[x][y]; 149. type = lev->typ; 150. if (IS_WALL(type) && type != DBWALL) { 151. if (is_solid(x - 1, y - 1) && is_solid(x - 1, y) 152. && is_solid(x - 1, y + 1) && is_solid(x, y - 1) 153. && is_solid(x, y + 1) && is_solid(x + 1, y - 1) 154. && is_solid(x + 1, y) && is_solid(x + 1, y + 1)) 155. lev->typ = STONE; 156. } 157. } 158. } 159. 160. /* Correct wall types so they extend and connect to each other */ 161. void 162. fix_wall_spines(x1, y1, x2, y2) 163. int x1, y1, x2, y2; 164. { 165. uchar type; 166. int x, y; 167. struct rm *lev; 168. int FDECL((*loc_f), (int, int)); 169. int bits; 170. int locale[3][3]; /* rock or wall status surrounding positions */ 171. 172. /* 173. * Value 0 represents a free-standing wall. It could be anything, 174. * so even though this table says VWALL, we actually leave whatever 175. * typ was there alone. 176. */ 177. static xchar spine_array[16] = { VWALL, HWALL, HWALL, HWALL, 178. VWALL, TRCORNER, TLCORNER, TDWALL, 179. VWALL, BRCORNER, BLCORNER, TUWALL, 180. VWALL, TLWALL, TRWALL, CROSSWALL }; 181. 182. /* sanity check on incoming variables */ 183. if (x1 < 0 || x2 >= COLNO || x1 > x2 || y1 < 0 || y2 >= ROWNO || y1 > y2) 184. panic("wall_extends: bad bounds (%d,%d) to (%d,%d)", x1, y1, x2, y2); 185. 186. /* set the correct wall type. */ 187. for (x = x1; x <= x2; x++) 188. for (y = y1; y <= y2; y++) { 189. lev = &levl[x][y]; 190. type = lev->typ; 191. if (!(IS_WALL(type) && type != DBWALL)) 192. continue; 193. 194. /* set the locations TRUE if rock or wall or out of bounds */ 195. loc_f = within_bounded_area(x, y, /* for baalz insect */ 196. bughack.inarea.x1, bughack.inarea.y1, 197. bughack.inarea.x2, bughack.inarea.y2) 198. ? iswall 199. : iswall_or_stone; 200. locale[0][0] = (*loc_f)(x - 1, y - 1); 201. locale[1][0] = (*loc_f)(x, y - 1); 202. locale[2][0] = (*loc_f)(x + 1, y - 1); 203. 204. locale[0][1] = (*loc_f)(x - 1, y); 205. locale[2][1] = (*loc_f)(x + 1, y); 206. 207. locale[0][2] = (*loc_f)(x - 1, y + 1); 208. locale[1][2] = (*loc_f)(x, y + 1); 209. locale[2][2] = (*loc_f)(x + 1, y + 1); 210. 211. /* determine if wall should extend to each direction NSEW */ 212. bits = (extend_spine(locale, iswall(x, y - 1), 0, -1) << 3) 213. | (extend_spine(locale, iswall(x, y + 1), 0, 1) << 2) 214. | (extend_spine(locale, iswall(x + 1, y), 1, 0) << 1) 215. | extend_spine(locale, iswall(x - 1, y), -1, 0); 216. 217. /* don't change typ if wall is free-standing */ 218. if (bits) 219. lev->typ = spine_array[bits]; 220. } 221. } 222. 223. void 224. wallification(x1, y1, x2, y2) 225. int x1, y1, x2, y2; 226. { 227. wall_cleanup(x1, y1, x2, y2); 228. fix_wall_spines(x1, y1, x2, y2); 229. } 230. 231. STATIC_OVL boolean 232. okay(x, y, dir) 233. int x, y; 234. int dir; 235. { 236. mz_move(x, y, dir); 237. mz_move(x, y, dir); 238. if (x < 3 || y < 3 || x > x_maze_max || y > y_maze_max 239. || levl[x][y].typ != STONE) 240. return FALSE; 241. return TRUE; 242. } 243. 244. /* find random starting point for maze generation */ 245. STATIC_OVL void 246. maze0xy(cc) 247. coord *cc; 248. { 249. cc->x = 3 + 2 * rn2((x_maze_max >> 1) - 1); 250. cc->y = 3 + 2 * rn2((y_maze_max >> 1) - 1); 251. return; 252. } 253. 254. /* 255. * Bad if: 256. * pos is occupied OR 257. * pos is inside restricted region (lx,ly,hx,hy) OR 258. * NOT (pos is corridor and a maze level OR pos is a room OR pos is air) 259. */ 260. boolean 261. bad_location(x, y, lx, ly, hx, hy) 262. xchar x, y; 263. xchar lx, ly, hx, hy; 264. { 265. return (boolean) (occupied(x, y) 266. || within_bounded_area(x, y, lx, ly, hx, hy) 267. || !((levl[x][y].typ == CORR && level.flags.is_maze_lev) 268. || levl[x][y].typ == ROOM 269. || levl[x][y].typ == AIR)); 270. } 271. 272. /* pick a location in area (lx, ly, hx, hy) but not in (nlx, nly, nhx, nhy) 273. and place something (based on rtype) in that region */ 274. void 275. place_lregion(lx, ly, hx, hy, nlx, nly, nhx, nhy, rtype, lev) 276. xchar lx, ly, hx, hy; 277. xchar nlx, nly, nhx, nhy; 278. xchar rtype; 279. d_level *lev; 280. { 281. int trycnt; 282. boolean oneshot; 283. xchar x, y; 284. 285. if (!lx) { /* default to whole level */ 286. /* 287. * if there are rooms and this a branch, let place_branch choose 288. * the branch location (to avoid putting branches in corridors). 289. */ 290. if (rtype == LR_BRANCH && nroom) { 291. place_branch(Is_branchlev(&u.uz), 0, 0); 292. return; 293. } 294. 295. lx = 1; /* column 0 is not used */ 296. hx = COLNO - 1; 297. ly = 0; /* 3.6.0 and earlier erroneously had 1 here */ 298. hy = ROWNO - 1; 299. } 300. 301. /* first a probabilistic approach */ 302. 303. oneshot = (lx == hx && ly == hy); 304. for (trycnt = 0; trycnt < 200; trycnt++) { 305. x = rn1((hx - lx) + 1, lx); 306. y = rn1((hy - ly) + 1, ly); 307. if (put_lregion_here(x, y, nlx, nly, nhx, nhy, rtype, oneshot, lev)) 308. return; 309. } 310. 311. /* then a deterministic one */ 312. 313. for (x = lx; x <= hx; x++) 314. for (y = ly; y <= hy; y++) 315. if (put_lregion_here(x, y, nlx, nly, nhx, nhy, rtype, TRUE, lev)) 316. return; 317. 318. impossible("Couldn't place lregion type %d!", rtype); 319. } 320. 321. STATIC_OVL boolean 322. put_lregion_here(x, y, nlx, nly, nhx, nhy, rtype, oneshot, lev) 323. xchar x, y; 324. xchar nlx, nly, nhx, nhy; 325. xchar rtype; 326. boolean oneshot; 327. d_level *lev; 328. { 329. struct monst *mtmp; 330. 331. if (bad_location(x, y, nlx, nly, nhx, nhy)) { 332. if (!oneshot) { 333. return FALSE; /* caller should try again */ 334. } else { 335. /* Must make do with the only location possible; 336. avoid failure due to a misplaced trap. 337. It might still fail if there's a dungeon feature here. */ 338. struct trap *t = t_at(x, y); 339. 340. if (t && t->ttyp != MAGIC_PORTAL && t->ttyp != VIBRATING_SQUARE) 341. deltrap(t); 342. if (bad_location(x, y, nlx, nly, nhx, nhy)) 343. return FALSE; 344. } 345. } 346. switch (rtype) { 347. case LR_TELE: 348. case LR_UPTELE: 349. case LR_DOWNTELE: 350. /* "something" means the player in this case */ 351. if ((mtmp = m_at(x, y)) != 0) { 352. /* move the monster if no choice, or just try again */ 353. if (oneshot) { 354. if (!rloc(mtmp, TRUE)) 355. m_into_limbo(mtmp); 356. } else 357. return FALSE; 358. } 359. u_on_newpos(x, y); 360. break; 361. case LR_PORTAL: 362. mkportal(x, y, lev->dnum, lev->dlevel); 363. break; 364. case LR_DOWNSTAIR: 365. case LR_UPSTAIR: 366. mkstairs(x, y, (char) rtype, (struct mkroom *) 0); 367. break; 368. case LR_BRANCH: 369. place_branch(Is_branchlev(&u.uz), x, y); 370. break; 371. } 372. return TRUE; 373. } 374. 375. /* fix up Baalzebub's lair, which depicts a level-sized beetle; 376. its legs are walls within solid rock--regular wallification 377. classifies them as superfluous and gets rid of them */ 378. STATIC_OVL void 379. baalz_fixup() 380. { 381. struct monst *mtmp; 382. int x, y, lastx, lasty; 383. 384. /* 385. * baalz level's nondiggable region surrounds the "insect" and rooms. 386. * The outermost perimeter of that region is subject to wall cleanup 387. * (hence 'x + 1' and 'y + 1' for starting don't-clean column and row, 388. * 'lastx - 1' and 'lasty - 1' for ending don't-clean column and row) 389. * and the interior is protected against that (in wall_cleanup()). 390. * 391. * Assumes level.flags.corrmaze is True, otherwise the bug legs will 392. * have already been "cleaned" away by general wallification. 393. */ 394. 395. /* find low and high x for to-be-wallified portion of level */ 396. y = ROWNO / 2; 397. for (lastx = x = 0; x < COLNO; ++x) 398. if ((levl[x][y].wall_info & W_NONDIGGABLE) != 0) { 399. if (!lastx) 400. bughack.inarea.x1 = x + 1; 401. lastx = x; 402. } 403. bughack.inarea.x2 = ((lastx > bughack.inarea.x1) ? lastx : x) - 1; 404. /* find low and high y for to-be-wallified portion of level */ 405. x = bughack.inarea.x1; 406. for (lasty = y = 0; y < ROWNO; ++y) 407. if ((levl[x][y].wall_info & W_NONDIGGABLE) != 0) { 408. if (!lasty) 409. bughack.inarea.y1 = y + 1; 410. lasty = y; 411. } 412. bughack.inarea.y2 = ((lasty > bughack.inarea.y1) ? lasty : y) - 1; 413. /* two pools mark where special post-wallify fix-ups are needed */ 414. for (x = bughack.inarea.x1; x <= bughack.inarea.x2; ++x) 415. for (y = bughack.inarea.y1; y <= bughack.inarea.y2; ++y) 416. if (levl[x][y].typ == POOL) { 417. levl[x][y].typ = HWALL; 418. if (bughack.delarea.x1 == COLNO) 419. bughack.delarea.x1 = x, bughack.delarea.y1 = y; 420. else 421. bughack.delarea.x2 = x, bughack.delarea.y2 = y; 422. } else if (levl[x][y].typ == IRONBARS) { 423. /* novelty effect; allowing digging in front of 'eyes' */ 424. levl[x - 1][y].wall_info &= ~W_NONDIGGABLE; 425. if (isok(x - 2, y)) 426. levl[x - 2][y].wall_info &= ~W_NONDIGGABLE; 427. } 428. 429. wallification(max(bughack.inarea.x1 - 2, 1), 430. max(bughack.inarea.y1 - 2, 0), 431. min(bughack.inarea.x2 + 2, COLNO - 1), 432. min(bughack.inarea.y2 + 2, ROWNO - 1)); 433. 434. /* bughack hack for rear-most legs on baalz level; first joint on 435. both top and bottom gets a bogus extra connection to room area, 436. producing unwanted rectangles; change back to separated legs */ 437. x = bughack.delarea.x1, y = bughack.delarea.y1; 438. if (isok(x, y) && levl[x][y].typ == TLWALL 439. && isok(x, y + 1) && levl[x][y + 1].typ == TUWALL) { 440. levl[x][y].typ = BRCORNER; 441. levl[x][y + 1].typ = HWALL; 442. if ((mtmp = m_at(x, y)) != 0) /* something at temporary pool... */ 443. (void) rloc(mtmp, FALSE); 444. } 445. x = bughack.delarea.x2, y = bughack.delarea.y2; 446. if (isok(x, y) && levl[x][y].typ == TLWALL 447. && isok(x, y - 1) && levl[x][y - 1].typ == TDWALL) { 448. levl[x][y].typ = TRCORNER; 449. levl[x][y - 1].typ = HWALL; 450. if ((mtmp = m_at(x, y)) != 0) /* something at temporary pool... */ 451. (void) rloc(mtmp, FALSE); 452. } 453. 454. /* reset bughack region; set low end to <COLNO,ROWNO> so that 455. within_bounded_region() in fix_wall_spines() will fail 456. most quickly--on its first test--when loading other levels */ 457. bughack.inarea.x1 = bughack.delarea.x1 = COLNO; 458. bughack.inarea.y1 = bughack.delarea.y1 = ROWNO; 459. bughack.inarea.x2 = bughack.delarea.x2 = 0; 460. bughack.inarea.y2 = bughack.delarea.y2 = 0; 461. } 462. 463. static boolean was_waterlevel; /* ugh... this shouldn't be needed */ 464. 465. /* this is special stuff that the level compiler cannot (yet) handle */ 466. void 467. fixup_special() 468. { 469. lev_region *r = lregions; 470. struct d_level lev; 471. int x, y; 472. struct mkroom *croom; 473. boolean added_branch = FALSE; 474. 475. if (was_waterlevel) { 476. was_waterlevel = FALSE; 477. u.uinwater = 0; 478. unsetup_waterlevel(); 479. } 480. if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) { 481. level.flags.hero_memory = 0; 482. was_waterlevel = TRUE; 483. /* water level is an odd beast - it has to be set up 484. before calling place_lregions etc. */ 485. setup_waterlevel(); 486. } 487. for (x = 0; x < num_lregions; x++, r++) { 488. switch (r->rtype) { 489. case LR_BRANCH: 490. added_branch = TRUE; 491. goto place_it; 492. 493. case LR_PORTAL: 494. if (*r->rname.str >= '0' && *r->rname.str <= '9') { 495. /* "chutes and ladders" */ 496. lev = u.uz; 497. lev.dlevel = atoi(r->rname.str); 498. } else { 499. s_level *sp = find_level(r->rname.str); 500. lev = sp->dlevel; 501. } 502. /*FALLTHRU*/ 503. 504. case LR_UPSTAIR: 505. case LR_DOWNSTAIR: 506. place_it: 507. place_lregion(r->inarea.x1, r->inarea.y1, r->inarea.x2, 508. r->inarea.y2, r->delarea.x1, r->delarea.y1, 509. r->delarea.x2, r->delarea.y2, r->rtype, &lev); 510. break; 511. 512. case LR_TELE: 513. case LR_UPTELE: 514. case LR_DOWNTELE: 515. /* save the region outlines for goto_level() */ 516. if (r->rtype == LR_TELE || r->rtype == LR_UPTELE) { 517. updest.lx = r->inarea.x1; 518. updest.ly = r->inarea.y1; 519. updest.hx = r->inarea.x2; 520. updest.hy = r->inarea.y2; 521. updest.nlx = r->delarea.x1; 522. updest.nly = r->delarea.y1; 523. updest.nhx = r->delarea.x2; 524. updest.nhy = r->delarea.y2; 525. } 526. if (r->rtype == LR_TELE || r->rtype == LR_DOWNTELE) { 527. dndest.lx = r->inarea.x1; 528. dndest.ly = r->inarea.y1; 529. dndest.hx = r->inarea.x2; 530. dndest.hy = r->inarea.y2; 531. dndest.nlx = r->delarea.x1; 532. dndest.nly = r->delarea.y1; 533. dndest.nhx = r->delarea.x2; 534. dndest.nhy = r->delarea.y2; 535. } 536. /* place_lregion gets called from goto_level() */ 537. break; 538. } 539. 540. if (r->rname.str) 541. free((genericptr_t) r->rname.str), r->rname.str = 0; 542. } 543. 544. /* place dungeon branch if not placed above */ 545. if (!added_branch && Is_branchlev(&u.uz)) { 546. place_lregion(0, 0, 0, 0, 0, 0, 0, 0, LR_BRANCH, (d_level *) 0); 547. } 548. 549. /* Still need to add some stuff to level file */ 550. if (Is_medusa_level(&u.uz)) { 551. struct obj *otmp; 552. int tryct; 553. 554. croom = &rooms[0]; /* only one room on the medusa level */ 555. for (tryct = rnd(4); tryct; tryct--) { 556. x = somex(croom); 557. y = somey(croom); 558. if (goodpos(x, y, (struct monst *) 0, 0)) { 559. otmp = mk_tt_object(STATUE, x, y); 560. while (otmp && (poly_when_stoned(&mons[otmp->corpsenm]) 561. || pm_resistance(&mons[otmp->corpsenm], 562. MR_STONE))) { 563. /* set_corpsenm() handles weight too */ 564. set_corpsenm(otmp, rndmonnum()); 565. } 566. } 567. } 568. 569. if (rn2(2)) 570. otmp = mk_tt_object(STATUE, somex(croom), somey(croom)); 571. else /* Medusa statues don't contain books */ 572. otmp = 573. mkcorpstat(STATUE, (struct monst *) 0, (struct permonst *) 0, 574. somex(croom), somey(croom), CORPSTAT_NONE); 575. if (otmp) { 576. while (pm_resistance(&mons[otmp->corpsenm], MR_STONE) 577. || poly_when_stoned(&mons[otmp->corpsenm])) { 578. /* set_corpsenm() handles weight too */ 579. set_corpsenm(otmp, rndmonnum()); 580. } 581. } 582. } else if (Is_wiz1_level(&u.uz)) { 583. croom = search_special(MORGUE); 584. 585. create_secret_door(croom, W_SOUTH | W_EAST | W_WEST); 586. } else if (Is_knox(&u.uz)) { 587. /* using an unfilled morgue for rm id */ 588. croom = search_special(MORGUE); 589. /* avoid inappropriate morgue-related messages */ 590. level.flags.graveyard = level.flags.has_morgue = 0; 591. croom->rtype = OROOM; /* perhaps it should be set to VAULT? */ 592. /* stock the main vault */ 593. for (x = croom->lx; x <= croom->hx; x++) 594. for (y = croom->ly; y <= croom->hy; y++) { 595. (void) mkgold((long) rn1(300, 600), x, y); 596. if (!rn2(3) && !is_pool(x, y)) 597. (void) maketrap(x, y, rn2(3) ? LANDMINE : SPIKED_PIT); 598. } 599. } else if (Role_if(PM_PRIEST) && In_quest(&u.uz)) { 600. /* less chance for undead corpses (lured from lower morgues) */ 601. level.flags.graveyard = 1; 602. } else if (Is_stronghold(&u.uz)) { 603. level.flags.graveyard = 1; 604. } else if (Is_sanctum(&u.uz)) { 605. croom = search_special(TEMPLE); 606. 607. create_secret_door(croom, W_ANY); 608. } else if (on_level(&u.uz, &orcus_level)) { 609. struct monst *mtmp, *mtmp2; 610. 611. /* it's a ghost town, get rid of shopkeepers */ 612. for (mtmp = fmon; mtmp; mtmp = mtmp2) { 613. mtmp2 = mtmp->nmon; 614. if (mtmp->isshk) 615. mongone(mtmp); 616. } 617. } else if (on_level(&u.uz, &baalzebub_level)) { 618. /* custom wallify the "beetle" potion of the level */ 619. baalz_fixup(); 620. } else if (u.uz.dnum == mines_dnum && ransacked) { 621. stolen_booty(); 622. } 623. 624. if (lregions) 625. free((genericptr_t) lregions), lregions = 0; 626. num_lregions = 0; 627. } 628. 629. void 630. check_ransacked(s) 631. char *s; 632. { 633. /* this kludge only works as long as orctown is minetn-1 */ 634. ransacked = (u.uz.dnum == mines_dnum && !strcmp(s, "minetn-1")); 635. } 636. 637. #define ORC_LEADER 1 638. static const char *orcfruit[] = { "paddle cactus", "dwarven root" }; 639. 640. void 641. migrate_orc(mtmp, mflags) 642. struct monst *mtmp; 643. unsigned long mflags; 644. { 645. int nlev, max_depth, cur_depth; 646. d_level dest; 647. 648. cur_depth = (int) depth(&u.uz); 649. max_depth = dunlevs_in_dungeon(&u.uz) 650. + (dungeons[u.uz.dnum].depth_start - 1); 651. if (mflags == ORC_LEADER) { 652. /* Note that the orc leader will take possession of any 653. * remaining stuff not already delivered to other 654. * orcs between here and the bottom of the mines. 655. */ 656. nlev = max_depth; 657. /* once in a blue moon, he won't be at the very bottom */ 658. if (!rn2(40)) 659. nlev--; 660. mtmp->mspare1 = MIGR_LEFTOVERS; 661. } else { 662. nlev = rn2((max_depth - cur_depth) + 1) + cur_depth; 663. if (nlev == cur_depth) 664. nlev++; 665. if (nlev > max_depth) 666. nlev = max_depth; 667. mtmp->mspare1 = 0L; 668. } 669. get_level(&dest, nlev); 670. migrate_to_level(mtmp, ledger_no(&dest), MIGR_RANDOM, (coord *) 0); 671. } 672. 673. void 674. shiny_orc_stuff(mtmp) 675. struct monst *mtmp; 676. { 677. int gemprob, goldprob, otyp; 678. struct obj *otmp; 679. boolean is_captain = (mtmp->data == &mons[PM_ORC_CAPTAIN]); 680. 681. /* probabilities */ 682. goldprob = is_captain ? 600 : 300; 683. gemprob = goldprob / 4; 684. if (rn2(1000) < goldprob) { 685. if ((otmp = mksobj(GOLD_PIECE, FALSE, FALSE)) != 0) { 686. otmp->quan = 1L + rnd(goldprob); 687. otmp->owt = weight(otmp); 688. add_to_minv(mtmp, otmp); 689. } 690. } 691. if (rn2(1000) < gemprob) { 692. if ((otmp = mkobj(GEM_CLASS, FALSE)) != 0) { 693. if (otmp->otyp == ROCK) 694. dealloc_obj(otmp); 695. else 696. add_to_minv(mtmp, otmp); 697. } 698. } 699. if (is_captain || !rn2(8)) { 700. otyp = shiny_obj(RING_CLASS); 701. if (otyp != STRANGE_OBJECT && (otmp = mksobj(otyp, FALSE, FALSE)) != 0) 702. add_to_minv(mtmp, otmp); 703. } 704. } 705. void 706. migr_booty_item(otyp, gang) 707. int otyp; 708. const char *gang; 709. { 710. struct obj *otmp; 711. 712. otmp = mksobj_migr_to_species(otyp, (unsigned long) M2_ORC, FALSE, FALSE); 713. if (otmp && gang) { 714. new_oname(otmp, strlen(gang) + 1); /* removes old name if present */ 715. Strcpy(ONAME(otmp), gang); 716. if (otyp >= TRIPE_RATION && otyp <= TIN) { 717. if (otyp == SLIME_MOLD) 718. otmp->spe = fruitadd((char *) orcfruit[rn2(SIZE(orcfruit))], 719. (struct fruit *) 0); 720. otmp->quan += (long) rn2(3); 721. otmp->owt = weight(otmp); 722. } 723. } 724. } 725. 726. void 727. stolen_booty(VOID_ARGS) 728. { 729. char *gang, gang_name[BUFSZ]; 730. struct monst *mtmp; 731. int cnt, i, otyp; 732. 733. /* 734. * -------------------------------------------------------- 735. * Mythos: 736. * 737. * A tragic accident has occurred in Frontier Town... 738. * It has been overrun by orcs. 739. * 740. * The booty that the orcs took from the town is now 741. * in the possession of the orcs that did this and 742. * have long since fled the level. 743. * -------------------------------------------------------- 744. */ 745. 746. gang = rndorcname(gang_name); 747. /* create the stuff that the gang took */ 748. cnt = rnd(4); 749. for (i = 0; i < cnt; ++i) 750. migr_booty_item(rn2(4) ? TALLOW_CANDLE : WAX_CANDLE, gang); 751. cnt = rnd(3); 752. for (i = 0; i < cnt; ++i) 753. migr_booty_item(SKELETON_KEY, gang); 754. otyp = rn2((GAUNTLETS_OF_DEXTERITY - LEATHER_GLOVES) + 1) + LEATHER_GLOVES; 755. migr_booty_item(otyp, gang); 756. cnt = rnd(10); 757. for (i = 0; i < cnt; ++i) { 758. /* Food items - but no lembas! (or some other weird things) */ 759. otyp = rn2((TIN - TRIPE_RATION) + 1) + TRIPE_RATION; 760. if (otyp != LEMBAS_WAFER && otyp != GLOB_OF_GRAY_OOZE 761. && otyp != GLOB_OF_BROWN_PUDDING && otyp != GLOB_OF_GREEN_SLIME 762. && otyp != GLOB_OF_BLACK_PUDDING && otyp != MEAT_STICK 763. && otyp != MEATBALL && otyp != MEAT_STICK && otyp != MEAT_RING 764. && otyp != HUGE_CHUNK_OF_MEAT && otyp != CORPSE) 765. migr_booty_item(otyp, gang); 766. } 767. migr_booty_item(rn2(2) ? LONG_SWORD : SILVER_SABER, gang); 768. /* create the leader of the orc gang */ 769. mtmp = makemon(&mons[PM_ORC_CAPTAIN], 0, 0, MM_NONAME); 770. if (mtmp) { 771. mtmp = christen_monst(mtmp, upstart(gang)); 772. mtmp->mpeaceful = 0; 773. shiny_orc_stuff(mtmp); 774. migrate_orc(mtmp, ORC_LEADER); 775. } 776. /* Make most of the orcs on the level be part of the invading gang */ 777. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 778. if (DEADMONSTER(mtmp)) 779. continue; 780. 781. if (is_orc(mtmp->data) && !has_mname(mtmp) && rn2(10)) { 782. /* 783. * We'll consider the orc captain from the level 784. * .des file to be the captain of a rival orc horde 785. * who is there to see what has transpired, and to 786. * contemplate future action. 787. * 788. * Don't christen the orc captain as a subordinate 789. * member of the main orc horde. 790. */ 791. if (mtmp->data != &mons[PM_ORC_CAPTAIN]) 792. mtmp = christen_orc(mtmp, upstart(gang), ""); 793. } 794. } 795. /* Lastly, ensure there's several more orcs from the gang along the way. 796. * The mechanics are such that they aren't actually identified as 797. * members of the invading gang until they get their spoils assigned 798. * to the inventory; handled during that assignment. 799. */ 800. cnt = rn2(10) + 5; 801. for (i = 0; i < cnt; ++i) { 802. int mtyp; 803. 804. mtyp = rn2((PM_ORC_SHAMAN - PM_ORC) + 1) + PM_ORC; 805. mtmp = makemon(&mons[mtyp], 0, 0, MM_NONAME); 806. if (mtmp) { 807. shiny_orc_stuff(mtmp); 808. migrate_orc(mtmp, 0UL); 809. } 810. } 811. ransacked = 0; 812. } 813. 814. #undef ORC_LEADER 815. 816. boolean 817. maze_inbounds(x, y) 818. int x, y; 819. { 820. return (x >= 2 && y >= 2 821. && x < x_maze_max && y < y_maze_max && isok(x, y)); 822. } 823. 824. void 825. maze_remove_deadends(typ) 826. xchar typ; 827. { 828. char dirok[4]; 829. int x, y, dir, idx, idx2, dx, dy, dx2, dy2; 830. 831. dirok[0] = 0; /* lint suppression */ 832. for (x = 2; x < x_maze_max; x++) 833. for (y = 2; y < y_maze_max; y++) 834. if (ACCESSIBLE(levl[x][y].typ) && (x % 2) && (y % 2)) { 835. idx = idx2 = 0; 836. for (dir = 0; dir < 4; dir++) { 837. /* note: mz_move() is a macro which modifies 838. one of its first two parameters */ 839. dx = dx2 = x; 840. dy = dy2 = y; 841. mz_move(dx, dy, dir); 842. if (!maze_inbounds(dx, dy)) { 843. idx2++; 844. continue; 845. } 846. mz_move(dx2, dy2, dir); 847. mz_move(dx2, dy2, dir); 848. if (!maze_inbounds(dx2, dy2)) { 849. idx2++; 850. continue; 851. } 852. if (!ACCESSIBLE(levl[dx][dy].typ) 853. && ACCESSIBLE(levl[dx2][dy2].typ)) { 854. dirok[idx++] = dir; 855. idx2++; 856. } 857. } 858. if (idx2 >= 3 && idx > 0) { 859. dx = x; 860. dy = y; 861. dir = dirok[rn2(idx)]; 862. mz_move(dx, dy, dir); 863. levl[dx][dy].typ = typ; 864. } 865. } 866. } 867. 868. /* Create a maze with specified corridor width and wall thickness 869. * TODO: rewrite walkfrom so it works on temp space, not levl 870. */ 871. void 872. create_maze(corrwid, wallthick) 873. int corrwid; 874. int wallthick; 875. { 876. int x,y; 877. coord mm; 878. int tmp_xmax = x_maze_max; 879. int tmp_ymax = y_maze_max; 880. int rdx = 0; 881. int rdy = 0; 882. int scale; 883. 884. if (wallthick < 1) 885. wallthick = 1; 886. else if (wallthick > 5) 887. wallthick = 5; 888. 889. if (corrwid < 1) 890. corrwid = 1; 891. else if (corrwid > 5) 892. corrwid = 5; 893. 894. scale = corrwid + wallthick; 895. rdx = (x_maze_max / scale); 896. rdy = (y_maze_max / scale); 897. 898. if (level.flags.corrmaze) 899. for (x = 2; x < (rdx * 2); x++) 900. for (y = 2; y < (rdy * 2); y++) 901. levl[x][y].typ = STONE; 902. else 903. for (x = 2; x <= (rdx * 2); x++) 904. for (y = 2; y <= (rdy * 2); y++) 905. levl[x][y].typ = ((x % 2) && (y % 2)) ? STONE : HWALL; 906. 907. /* set upper bounds for maze0xy and walkfrom */ 908. x_maze_max = (rdx * 2); 909. y_maze_max = (rdy * 2); 910. 911. /* create maze */ 912. maze0xy(&mm); 913. walkfrom((int) mm.x, (int) mm.y, 0); 914. 915. if (!rn2(5)) 916. maze_remove_deadends((level.flags.corrmaze) ? CORR : ROOM); 917. 918. /* restore bounds */ 919. x_maze_max = tmp_xmax; 920. y_maze_max = tmp_ymax; 921. 922. /* scale maze up if needed */ 923. if (scale > 2) { 924. char tmpmap[COLNO][ROWNO]; 925. int rx = 1, ry = 1; 926. 927. /* back up the existing smaller maze */ 928. for (x = 1; x < x_maze_max; x++) 929. for (y = 1; y < y_maze_max; y++) { 930. tmpmap[x][y] = levl[x][y].typ; 931. } 932. 933. /* do the scaling */ 934. rx = x = 2; 935. while (rx < x_maze_max) { 936. int mx = (x % 2) ? corrwid 937. : ((x == 2 || x == (rdx * 2)) ? 1 938. : wallthick); 939. ry = y = 2; 940. while (ry < y_maze_max) { 941. int dx = 0, dy = 0; 942. int my = (y % 2) ? corrwid 943. : ((y == 2 || y == (rdy * 2)) ? 1 944. : wallthick); 945. for (dx = 0; dx < mx; dx++) 946. for (dy = 0; dy < my; dy++) { 947. if (rx+dx >= x_maze_max 948. || ry+dy >= y_maze_max) 949. break; 950. levl[rx + dx][ry + dy].typ = tmpmap[x][y]; 951. } 952. ry += my; 953. y++; 954. } 955. rx += mx; 956. x++; 957. } 958. 959. } 960. } 961. 962. 963. void 964. makemaz(s) 965. const char *s; 966. { 967. int x, y; 968. char protofile[20]; 969. s_level *sp = Is_special(&u.uz); 970. coord mm; 971. 972. if (*s) { 973. if (sp && sp->rndlevs) 974. Sprintf(protofile, "%s-%d", s, rnd((int) sp->rndlevs)); 975. else 976. Strcpy(protofile, s); 977. } else if (*(dungeons[u.uz.dnum].proto)) { 978. if (dunlevs_in_dungeon(&u.uz) > 1) { 979. if (sp && sp->rndlevs) 980. Sprintf(protofile, "%s%d-%d", dungeons[u.uz.dnum].proto, 981. dunlev(&u.uz), rnd((int) sp->rndlevs)); 982. else 983. Sprintf(protofile, "%s%d", dungeons[u.uz.dnum].proto, 984. dunlev(&u.uz)); 985. } else if (sp && sp->rndlevs) { 986. Sprintf(protofile, "%s-%d", dungeons[u.uz.dnum].proto, 987. rnd((int) sp->rndlevs)); 988. } else 989. Strcpy(protofile, dungeons[u.uz.dnum].proto); 990. 991. } else 992. Strcpy(protofile, ""); 993. 994. /* SPLEVTYPE format is "level-choice,level-choice"... */ 995. if (wizard && *protofile && sp && sp->rndlevs) { 996. char *ep = getenv("SPLEVTYPE"); /* not nh_getenv */ 997. if (ep) { 998. /* rindex always succeeds due to code in prior block */ 999. int len = (int) ((rindex(protofile, '-') - protofile) + 1); 1000. 1001. while (ep && *ep) { 1002. if (!strncmp(ep, protofile, len)) { 1003. int pick = atoi(ep + len); 1004. /* use choice only if valid */ 1005. if (pick > 0 && pick <= (int) sp->rndlevs) 1006. Sprintf(protofile + len, "%d", pick); 1007. break; 1008. } else { 1009. ep = index(ep, ','); 1010. if (ep) 1011. ++ep; 1012. } 1013. } 1014. } 1015. } 1016. 1017. if (*protofile) { 1018. check_ransacked(protofile); 1019. Strcat(protofile, LEV_EXT); 1020. if (load_special(protofile)) { 1021. /* some levels can end up with monsters 1022. on dead mon list, including light source monsters */ 1023. dmonsfree(); 1024. return; /* no mazification right now */ 1025. } 1026. impossible("Couldn't load \"%s\" - making a maze.", protofile); 1027. } 1028. 1029. level.flags.is_maze_lev = TRUE; 1030. level.flags.corrmaze = !rn2(3); 1031. 1032. if (!Invocation_lev(&u.uz) && rn2(2)) { 1033. int corrscale = rnd(4); 1034. create_maze(corrscale,rnd(4)-corrscale); 1035. } else { 1036. create_maze(1,1); 1037. } 1038. 1039. if (!level.flags.corrmaze) 1040. wallification(2, 2, x_maze_max, y_maze_max); 1041. 1042. mazexy(&mm); 1043. mkstairs(mm.x, mm.y, 1, (struct mkroom *) 0); /* up */ 1044. if (!Invocation_lev(&u.uz)) { 1045. mazexy(&mm); 1046. mkstairs(mm.x, mm.y, 0, (struct mkroom *) 0); /* down */ 1047. } else { /* choose "vibrating square" location */ 1048. #define x_maze_min 2 1049. #define y_maze_min 2 1050. /* 1051. * Pick a position where the stairs down to Moloch's Sanctum 1052. * level will ultimately be created. At that time, an area 1053. * will be altered: walls removed, moat and traps generated, 1054. * boulders destroyed. The position picked here must ensure 1055. * that that invocation area won't extend off the map. 1056. * 1057. * We actually allow up to 2 squares around the usual edge of 1058. * the area to get truncated; see mkinvokearea(mklev.c). 1059. */ 1060. #define INVPOS_X_MARGIN (6 - 2) 1061. #define INVPOS_Y_MARGIN (5 - 2) 1062. #define INVPOS_DISTANCE 11 1063. int x_range = x_maze_max - x_maze_min - 2 * INVPOS_X_MARGIN - 1, 1064. y_range = y_maze_max - y_maze_min - 2 * INVPOS_Y_MARGIN - 1; 1065. 1066. if (x_range <= INVPOS_X_MARGIN || y_range <= INVPOS_Y_MARGIN 1067. || (x_range * y_range) <= (INVPOS_DISTANCE * INVPOS_DISTANCE)) { 1068. debugpline2("inv_pos: maze is too small! (%d x %d)", 1069. x_maze_max, y_maze_max); 1070. } 1071. inv_pos.x = inv_pos.y = 0; /*{occupied() => invocation_pos()}*/ 1072. do { 1073. x = rn1(x_range, x_maze_min + INVPOS_X_MARGIN + 1); 1074. y = rn1(y_range, y_maze_min + INVPOS_Y_MARGIN + 1); 1075. /* we don't want it to be too near the stairs, nor 1076. to be on a spot that's already in use (wall|trap) */ 1077. } while (x == xupstair || y == yupstair /*(direct line)*/ 1078. || abs(x - xupstair) == abs(y - yupstair) 1079. || distmin(x, y, xupstair, yupstair) <= INVPOS_DISTANCE 1080. || !SPACE_POS(levl[x][y].typ) || occupied(x, y)); 1081. inv_pos.x = x; 1082. inv_pos.y = y; 1083. maketrap(inv_pos.x, inv_pos.y, VIBRATING_SQUARE); 1084. #undef INVPOS_X_MARGIN 1085. #undef INVPOS_Y_MARGIN 1086. #undef INVPOS_DISTANCE 1087. #undef x_maze_min 1088. #undef y_maze_min 1089. } 1090. 1091. /* place branch stair or portal */ 1092. place_branch(Is_branchlev(&u.uz), 0, 0); 1093. 1094. for (x = rn1(8, 11); x; x--) { 1095. mazexy(&mm); 1096. (void) mkobj_at(rn2(2) ? GEM_CLASS : 0, mm.x, mm.y, TRUE); 1097. } 1098. for (x = rn1(10, 2); x; x--) { 1099. mazexy(&mm); 1100. (void) mksobj_at(BOULDER, mm.x, mm.y, TRUE, FALSE); 1101. } 1102. for (x = rn2(3); x; x--) { 1103. mazexy(&mm); 1104. (void) makemon(&mons[PM_MINOTAUR], mm.x, mm.y, NO_MM_FLAGS); 1105. } 1106. for (x = rn1(5, 7); x; x--) { 1107. mazexy(&mm); 1108. (void) makemon((struct permonst *) 0, mm.x, mm.y, NO_MM_FLAGS); 1109. } 1110. for (x = rn1(6, 7); x; x--) { 1111. mazexy(&mm); 1112. (void) mkgold(0L, mm.x, mm.y); 1113. } 1114. for (x = rn1(6, 7); x; x--) 1115. mktrap(0, 1, (struct mkroom *) 0, (coord *) 0); 1116. } 1117. 1118. #ifdef MICRO 1119. /* Make the mazewalk iterative by faking a stack. This is needed to 1120. * ensure the mazewalk is successful in the limited stack space of 1121. * the program. This iterative version uses the minimum amount of stack 1122. * that is totally safe. 1123. */ 1124. void 1125. walkfrom(x, y, typ) 1126. int x, y; 1127. schar typ; 1128. { 1129. #define CELLS (ROWNO * COLNO) / 4 /* a maze cell is 4 squares */ 1130. char mazex[CELLS + 1], mazey[CELLS + 1]; /* char's are OK */ 1131. int q, a, dir, pos; 1132. int dirs[4]; 1133. 1134. if (!typ) { 1135. if (level.flags.corrmaze) 1136. typ = CORR; 1137. else 1138. typ = ROOM; 1139. } 1140. 1141. pos = 1; 1142. mazex[pos] = (char) x; 1143. mazey[pos] = (char) y; 1144. while (pos) { 1145. x = (int) mazex[pos]; 1146. y = (int) mazey[pos]; 1147. if (!IS_DOOR(levl[x][y].typ)) { 1148. /* might still be on edge of MAP, so don't overwrite */ 1149. levl[x][y].typ = typ; 1150. levl[x][y].flags = 0; 1151. } 1152. q = 0; 1153. for (a = 0; a < 4; a++) 1154. if (okay(x, y, a)) 1155. dirs[q++] = a; 1156. if (!q) 1157. pos--; 1158. else { 1159. dir = dirs[rn2(q)]; 1160. mz_move(x, y, dir); 1161. levl[x][y].typ = typ; 1162. mz_move(x, y, dir); 1163. pos++; 1164. if (pos > CELLS) 1165. panic("Overflow in walkfrom"); 1166. mazex[pos] = (char) x; 1167. mazey[pos] = (char) y; 1168. } 1169. } 1170. } 1171. #else /* !MICRO */ 1172. 1173. void 1174. walkfrom(x, y, typ) 1175. int x, y; 1176. schar typ; 1177. { 1178. int q, a, dir; 1179. int dirs[4]; 1180. 1181. if (!typ) { 1182. if (level.flags.corrmaze) 1183. typ = CORR; 1184. else 1185. typ = ROOM; 1186. } 1187. 1188. if (!IS_DOOR(levl[x][y].typ)) { 1189. /* might still be on edge of MAP, so don't overwrite */ 1190. levl[x][y].typ = typ; 1191. levl[x][y].flags = 0; 1192. } 1193. 1194. while (1) { 1195. q = 0; 1196. for (a = 0; a < 4; a++) 1197. if (okay(x, y, a)) 1198. dirs[q++] = a; 1199. if (!q) 1200. return; 1201. dir = dirs[rn2(q)]; 1202. mz_move(x, y, dir); 1203. levl[x][y].typ = typ; 1204. mz_move(x, y, dir); 1205. walkfrom(x, y, typ); 1206. } 1207. } 1208. #endif /* ?MICRO */ 1209. 1210. /* find random point in generated corridors, 1211. so we don't create items in moats, bunkers, or walls */ 1212. void 1213. mazexy(cc) 1214. coord *cc; 1215. { 1216. int cpt = 0; 1217. 1218. do { 1219. cc->x = 1 + rn2(x_maze_max); 1220. cc->y = 1 + rn2(y_maze_max); 1221. cpt++; 1222. } while (cpt < 100 1223. && levl[cc->x][cc->y].typ 1224. != (level.flags.corrmaze ? CORR : ROOM)); 1225. if (cpt >= 100) { 1226. int x, y; 1227. 1228. /* last try */ 1229. for (x = 1; x < x_maze_max; x++) 1230. for (y = 1; y < y_maze_max; y++) { 1231. cc->x = x; 1232. cc->y = y; 1233. if (levl[cc->x][cc->y].typ 1234. == (level.flags.corrmaze ? CORR : ROOM)) 1235. return; 1236. } 1237. panic("mazexy: can't find a place!"); 1238. } 1239. return; 1240. } 1241. 1242. /* put a non-diggable boundary around the initial portion of a level map. 1243. * assumes that no level will initially put things beyond the isok() range. 1244. * 1245. * we can't bound unconditionally on the last line with something in it, 1246. * because that something might be a niche which was already reachable, 1247. * so the boundary would be breached 1248. * 1249. * we can't bound unconditionally on one beyond the last line, because 1250. * that provides a window of abuse for wallified special levels 1251. */ 1252. void 1253. bound_digging() 1254. { 1255. int x, y; 1256. unsigned typ; 1257. struct rm *lev; 1258. boolean found, nonwall; 1259. int xmin, xmax, ymin, ymax; 1260. 1261. if (Is_earthlevel(&u.uz)) 1262. return; /* everything diggable here */ 1263. 1264. found = nonwall = FALSE; 1265. for (xmin = 0; !found && xmin <= COLNO; xmin++) { 1266. lev = &levl[xmin][0]; 1267. for (y = 0; y <= ROWNO - 1; y++, lev++) { 1268. typ = lev->typ; 1269. if (typ != STONE) { 1270. found = TRUE; 1271. if (!IS_WALL(typ)) 1272. nonwall = TRUE; 1273. } 1274. } 1275. } 1276. xmin -= (nonwall || !level.flags.is_maze_lev) ? 2 : 1; 1277. if (xmin < 0) 1278. xmin = 0; 1279. 1280. found = nonwall = FALSE; 1281. for (xmax = COLNO - 1; !found && xmax >= 0; xmax--) { 1282. lev = &levl[xmax][0]; 1283. for (y = 0; y <= ROWNO - 1; y++, lev++) { 1284. typ = lev->typ; 1285. if (typ != STONE) { 1286. found = TRUE; 1287. if (!IS_WALL(typ)) 1288. nonwall = TRUE; 1289. } 1290. } 1291. } 1292. xmax += (nonwall || !level.flags.is_maze_lev) ? 2 : 1; 1293. if (xmax >= COLNO) 1294. xmax = COLNO - 1; 1295. 1296. found = nonwall = FALSE; 1297. for (ymin = 0; !found && ymin <= ROWNO; ymin++) { 1298. lev = &levl[xmin][ymin]; 1299. for (x = xmin; x <= xmax; x++, lev += ROWNO) { 1300. typ = lev->typ; 1301. if (typ != STONE) { 1302. found = TRUE; 1303. if (!IS_WALL(typ)) 1304. nonwall = TRUE; 1305. } 1306. } 1307. } 1308. ymin -= (nonwall || !level.flags.is_maze_lev) ? 2 : 1; 1309. 1310. found = nonwall = FALSE; 1311. for (ymax = ROWNO - 1; !found && ymax >= 0; ymax--) { 1312. lev = &levl[xmin][ymax]; 1313. for (x = xmin; x <= xmax; x++, lev += ROWNO) { 1314. typ = lev->typ; 1315. if (typ != STONE) { 1316. found = TRUE; 1317. if (!IS_WALL(typ)) 1318. nonwall = TRUE; 1319. } 1320. } 1321. } 1322. ymax += (nonwall || !level.flags.is_maze_lev) ? 2 : 1; 1323. 1324. for (x = 0; x < COLNO; x++) 1325. for (y = 0; y < ROWNO; y++) 1326. if (y <= ymin || y >= ymax || x <= xmin || x >= xmax) { 1327. #ifdef DCC30_BUG 1328. lev = &levl[x][y]; 1329. lev->wall_info |= W_NONDIGGABLE; 1330. #else 1331. levl[x][y].wall_info |= W_NONDIGGABLE; 1332. #endif 1333. } 1334. } 1335. 1336. void 1337. mkportal(x, y, todnum, todlevel) 1338. xchar x, y, todnum, todlevel; 1339. { 1340. /* a portal "trap" must be matched by a 1341. portal in the destination dungeon/dlevel */ 1342. struct trap *ttmp = maketrap(x, y, MAGIC_PORTAL); 1343. 1344. if (!ttmp) { 1345. impossible("portal on top of portal??"); 1346. return; 1347. } 1348. debugpline4("mkportal: at <%d,%d>, to %s, level %d", x, y, 1349. dungeons[todnum].dname, todlevel); 1350. ttmp->dst.dnum = todnum; 1351. ttmp->dst.dlevel = todlevel; 1352. return; 1353. } 1354. 1355. void 1356. fumaroles() 1357. { 1358. xchar n; 1359. boolean snd = FALSE, loud = FALSE; 1360. 1361. for (n = rn2(3) + 2; n; n--) { 1362. xchar x = rn1(COLNO - 4, 3); 1363. xchar y = rn1(ROWNO - 4, 3); 1364. 1365. if (levl[x][y].typ == LAVAPOOL) { 1366. NhRegion *r = create_gas_cloud(x, y, 4 + rn2(5), rn1(10, 5)); 1367. 1368. clear_heros_fault(r); 1369. snd = TRUE; 1370. if (distu(x, y) < 15) 1371. loud = TRUE; 1372. } 1373. } 1374. if (snd && !Deaf) 1375. Norep("You hear a %swhoosh!", loud ? "loud " : ""); 1376. } 1377. 1378. /* 1379. * Special waterlevel stuff in endgame (TH). 1380. * 1381. * Some of these functions would probably logically belong to some 1382. * other source files, but they are all so nicely encapsulated here. 1383. */ 1384. 1385. static struct bubble *bbubbles, *ebubbles; 1386. 1387. static struct trap *wportal; 1388. static int xmin, ymin, xmax, ymax; /* level boundaries */ 1389. /* bubble movement boundaries */ 1390. #define bxmin (xmin + 1) 1391. #define bymin (ymin + 1) 1392. #define bxmax (xmax - 1) 1393. #define bymax (ymax - 1) 1394. 1395. STATIC_DCL void NDECL(set_wportal); 1396. STATIC_DCL void FDECL(mk_bubble, (int, int, int)); 1397. STATIC_DCL void FDECL(mv_bubble, (struct bubble *, int, int, BOOLEAN_P)); 1398. 1399. void 1400. movebubbles() 1401. { 1402. static boolean up; 1403. struct bubble *b; 1404. int x, y, i, j; 1405. struct trap *btrap; 1406. static const struct rm water_pos = { cmap_to_glyph(S_water), WATER, 0, 0, 1407. 0, 0, 0, 0, 0, 0 }; 1408. static const struct rm air_pos = { cmap_to_glyph(S_cloud), AIR, 0, 0, 0, 1409. 1, 0, 0, 0, 0 }; 1410. 1411. /* set up the portal the first time bubbles are moved */ 1412. if (!wportal) 1413. set_wportal(); 1414. 1415. vision_recalc(2); 1416. 1417. if (Is_waterlevel(&u.uz)) { 1418. /* keep attached ball&chain separate from bubble objects */ 1419. if (Punished) 1420. unplacebc(); 1421. 1422. /* 1423. * Pick up everything inside of a bubble then fill all bubble 1424. * locations. 1425. */ 1426. for (b = up ? bbubbles : ebubbles; b; b = up ? b->next : b->prev) { 1427. if (b->cons) 1428. panic("movebubbles: cons != null"); 1429. for (i = 0, x = b->x; i < (int) b->bm[0]; i++, x++) 1430. for (j = 0, y = b->y; j < (int) b->bm[1]; j++, y++) 1431. if (b->bm[j + 2] & (1 << i)) { 1432. if (!isok(x, y)) { 1433. impossible("movebubbles: bad pos (%d,%d)", x, y); 1434. continue; 1435. } 1436. 1437. /* pick up objects, monsters, hero, and traps */ 1438. if (OBJ_AT(x, y)) { 1439. struct obj *olist = (struct obj *) 0, *otmp; 1440. struct container *cons = 1441. (struct container *) alloc( 1442. sizeof(struct container)); 1443. 1444. while ((otmp = level.objects[x][y]) != 0) { 1445. remove_object(otmp); 1446. otmp->ox = otmp->oy = 0; 1447. otmp->nexthere = olist; 1448. olist = otmp; 1449. } 1450. 1451. cons->x = x; 1452. cons->y = y; 1453. cons->what = CONS_OBJ; 1454. cons->list = (genericptr_t) olist; 1455. cons->next = b->cons; 1456. b->cons = cons; 1457. } 1458. if (MON_AT(x, y)) { 1459. struct monst *mon = m_at(x, y); 1460. struct container *cons = 1461. (struct container *) alloc( 1462. sizeof(struct container)); 1463. 1464. cons->x = x; 1465. cons->y = y; 1466. cons->what = CONS_MON; 1467. cons->list = (genericptr_t) mon; 1468. 1469. cons->next = b->cons; 1470. b->cons = cons; 1471. 1472. if (mon->wormno) 1473. remove_worm(mon); 1474. else 1475. remove_monster(x, y); 1476. 1477. newsym(x, y); /* clean up old position */ 1478. mon->mx = mon->my = 0; 1479. } 1480. if (!u.uswallow && x == u.ux && y == u.uy) { 1481. struct container *cons = 1482. (struct container *) alloc( 1483. sizeof(struct container)); 1484. 1485. cons->x = x; 1486. cons->y = y; 1487. cons->what = CONS_HERO; 1488. cons->list = (genericptr_t) 0; 1489. 1490. cons->next = b->cons; 1491. b->cons = cons; 1492. } 1493. if ((btrap = t_at(x, y)) != 0) { 1494. struct container *cons = 1495. (struct container *) alloc( 1496. sizeof(struct container)); 1497. 1498. cons->x = x; 1499. cons->y = y; 1500. cons->what = CONS_TRAP; 1501. cons->list = (genericptr_t) btrap; 1502. 1503. cons->next = b->cons; 1504. b->cons = cons; 1505. } 1506. 1507. levl[x][y] = water_pos; 1508. block_point(x, y); 1509. } 1510. } 1511. } else if (Is_airlevel(&u.uz)) { 1512. for (x = 0; x < COLNO; x++) 1513. for (y = 0; y < ROWNO; y++) { 1514. levl[x][y] = air_pos; 1515. unblock_point(x, y); 1516. } 1517. } 1518. 1519. /* 1520. * Every second time traverse down. This is because otherwise 1521. * all the junk that changes owners when bubbles overlap 1522. * would eventually end up in the last bubble in the chain. 1523. */ 1524. up = !up; 1525. for (b = up ? bbubbles : ebubbles; b; b = up ? b->next : b->prev) { 1526. int rx = rn2(3), ry = rn2(3); 1527. 1528. mv_bubble(b, b->dx + 1 - (!b->dx ? rx : (rx ? 1 : 0)), 1529. b->dy + 1 - (!b->dy ? ry : (ry ? 1 : 0)), FALSE); 1530. } 1531. 1532. /* put attached ball&chain back */ 1533. if (Is_waterlevel(&u.uz) && Punished) 1534. placebc(); 1535. vision_full_recalc = 1; 1536. } 1537. 1538. /* when moving in water, possibly (1 in 3) alter the intended destination */ 1539. void 1540. water_friction() 1541. { 1542. int x, y, dx, dy; 1543. boolean eff = FALSE; 1544. 1545. if (Swimming && rn2(4)) 1546. return; /* natural swimmers have advantage */ 1547. 1548. if (u.dx && !rn2(!u.dy ? 3 : 6)) { /* 1/3 chance or half that */ 1549. /* cancel delta x and choose an arbitrary delta y value */ 1550. x = u.ux; 1551. do { 1552. dy = rn2(3) - 1; /* -1, 0, 1 */ 1553. y = u.uy + dy; 1554. } while (dy && (!isok(x, y) || !is_pool(x, y))); 1555. u.dx = 0; 1556. u.dy = dy; 1557. eff = TRUE; 1558. } else if (u.dy && !rn2(!u.dx ? 3 : 5)) { /* 1/3 or 1/5*(5/6) */ 1559. /* cancel delta y and choose an arbitrary delta x value */ 1560. y = u.uy; 1561. do { 1562. dx = rn2(3) - 1; /* -1 .. 1 */ 1563. x = u.ux + dx; 1564. } while (dx && (!isok(x, y) || !is_pool(x, y))); 1565. u.dy = 0; 1566. u.dx = dx; 1567. eff = TRUE; 1568. } 1569. if (eff) 1570. pline("Water turbulence affects your movements."); 1571. } 1572. 1573. void 1574. save_waterlevel(fd, mode) 1575. int fd, mode; 1576. { 1577. struct bubble *b; 1578. 1579. if (!Is_waterlevel(&u.uz) && !Is_airlevel(&u.uz)) 1580. return; 1581. 1582. if (perform_bwrite(mode)) { 1583. int n = 0; 1584. for (b = bbubbles; b; b = b->next) 1585. ++n; 1586. bwrite(fd, (genericptr_t) &n, sizeof(int)); 1587. bwrite(fd, (genericptr_t) &xmin, sizeof(int)); 1588. bwrite(fd, (genericptr_t) &ymin, sizeof(int)); 1589. bwrite(fd, (genericptr_t) &xmax, sizeof(int)); 1590. bwrite(fd, (genericptr_t) &ymax, sizeof(int)); 1591. for (b = bbubbles; b; b = b->next) 1592. bwrite(fd, (genericptr_t) b, sizeof(struct bubble)); 1593. } 1594. if (release_data(mode)) 1595. unsetup_waterlevel(); 1596. } 1597. 1598. void 1599. restore_waterlevel(fd) 1600. int fd; 1601. { 1602. struct bubble *b = (struct bubble *) 0, *btmp; 1603. int i, n; 1604. 1605. if (!Is_waterlevel(&u.uz) && !Is_airlevel(&u.uz)) 1606. return; 1607. 1608. set_wportal(); 1609. mread(fd, (genericptr_t) &n, sizeof(int)); 1610. mread(fd, (genericptr_t) &xmin, sizeof(int)); 1611. mread(fd, (genericptr_t) &ymin, sizeof(int)); 1612. mread(fd, (genericptr_t) &xmax, sizeof(int)); 1613. mread(fd, (genericptr_t) &ymax, sizeof(int)); 1614. for (i = 0; i < n; i++) { 1615. btmp = b; 1616. b = (struct bubble *) alloc(sizeof(struct bubble)); 1617. mread(fd, (genericptr_t) b, sizeof(struct bubble)); 1618. if (bbubbles) { 1619. btmp->next = b; 1620. b->prev = btmp; 1621. } else { 1622. bbubbles = b; 1623. b->prev = (struct bubble *) 0; 1624. } 1625. mv_bubble(b, 0, 0, TRUE); 1626. } 1627. ebubbles = b; 1628. b->next = (struct bubble *) 0; 1629. was_waterlevel = TRUE; 1630. } 1631. 1632. const char * 1633. waterbody_name(x, y) 1634. xchar x, y; 1635. { 1636. struct rm *lev; 1637. schar ltyp; 1638. 1639. if (!isok(x, y)) 1640. return "drink"; /* should never happen */ 1641. lev = &levl[x][y]; 1642. ltyp = lev->typ; 1643. if (ltyp == DRAWBRIDGE_UP) 1644. ltyp = db_under_typ(lev->drawbridgemask); 1645. 1646. if (ltyp == LAVAPOOL) 1647. return hliquid("lava"); 1648. else if (ltyp == ICE) 1649. return "ice"; 1650. else if (ltyp == POOL) 1651. return "pool of water"; 1652. else if (ltyp == WATER || Is_waterlevel(&u.uz)) 1653. ; /* fall through to default return value */ 1654. else if (Is_juiblex_level(&u.uz)) 1655. return "swamp"; 1656. else if (ltyp == MOAT && !Is_medusa_level(&u.uz)) 1657. return "moat"; 1658. 1659. return hliquid("water"); 1660. } 1661. 1662. STATIC_OVL void 1663. set_wportal() 1664. { 1665. /* there better be only one magic portal on water level... */ 1666. for (wportal = ftrap; wportal; wportal = wportal->ntrap) 1667. if (wportal->ttyp == MAGIC_PORTAL) 1668. return; 1669. impossible("set_wportal(): no portal!"); 1670. } 1671. 1672. STATIC_OVL void 1673. setup_waterlevel() 1674. { 1675. int x, y; 1676. int xskip, yskip; 1677. int water_glyph = cmap_to_glyph(S_water), 1678. air_glyph = cmap_to_glyph(S_air); 1679. 1680. /* ouch, hardcoded... */ 1681. 1682. xmin = 3; 1683. ymin = 1; 1684. xmax = 78; 1685. ymax = 20; 1686. 1687. /* set hero's memory to water */ 1688. 1689. for (x = xmin; x <= xmax; x++) 1690. for (y = ymin; y <= ymax; y++) 1691. levl[x][y].glyph = Is_waterlevel(&u.uz) ? water_glyph : air_glyph; 1692. 1693. /* make bubbles */ 1694. 1695. if (Is_waterlevel(&u.uz)) { 1696. xskip = 10 + rn2(10); 1697. yskip = 4 + rn2(4); 1698. } else { 1699. xskip = 6 + rn2(4); 1700. yskip = 3 + rn2(3); 1701. } 1702. 1703. for (x = bxmin; x <= bxmax; x += xskip) 1704. for (y = bymin; y <= bymax; y += yskip) 1705. mk_bubble(x, y, rn2(7)); 1706. } 1707. 1708. STATIC_OVL void 1709. unsetup_waterlevel() 1710. { 1711. struct bubble *b, *bb; 1712. 1713. /* free bubbles */ 1714. 1715. for (b = bbubbles; b; b = bb) { 1716. bb = b->next; 1717. free((genericptr_t) b); 1718. } 1719. bbubbles = ebubbles = (struct bubble *) 0; 1720. } 1721. 1722. STATIC_OVL void 1723. mk_bubble(x, y, n) 1724. int x, y, n; 1725. { 1726. /* 1727. * These bit masks make visually pleasing bubbles on a normal aspect 1728. * 25x80 terminal, which naturally results in them being mathematically 1729. * anything but symmetric. For this reason they cannot be computed 1730. * in situ, either. The first two elements tell the dimensions of 1731. * the bubble's bounding box. 1732. */ 1733. static uchar bm2[] = { 2, 1, 0x3 }, 1734. bm3[] = { 3, 2, 0x7, 0x7 }, 1735. bm4[] = { 4, 3, 0x6, 0xf, 0x6 }, 1736. bm5[] = { 5, 3, 0xe, 0x1f, 0xe }, 1737. bm6[] = { 6, 4, 0x1e, 0x3f, 0x3f, 0x1e }, 1738. bm7[] = { 7, 4, 0x3e, 0x7f, 0x7f, 0x3e }, 1739. bm8[] = { 8, 4, 0x7e, 0xff, 0xff, 0x7e }, 1740. *bmask[] = { bm2, bm3, bm4, bm5, bm6, bm7, bm8 }; 1741. struct bubble *b; 1742. 1743. if (x >= bxmax || y >= bymax) 1744. return; 1745. if (n >= SIZE(bmask)) { 1746. impossible("n too large (mk_bubble)"); 1747. n = SIZE(bmask) - 1; 1748. } 1749. if (bmask[n][1] > MAX_BMASK) { 1750. panic("bmask size is larger than MAX_BMASK"); 1751. } 1752. b = (struct bubble *) alloc(sizeof(struct bubble)); 1753. if ((x + (int) bmask[n][0] - 1) > bxmax) 1754. x = bxmax - bmask[n][0] + 1; 1755. if ((y + (int) bmask[n][1] - 1) > bymax) 1756. y = bymax - bmask[n][1] + 1; 1757. b->x = x; 1758. b->y = y; 1759. b->dx = 1 - rn2(3); 1760. b->dy = 1 - rn2(3); 1761. /* y dimension is the length of bitmap data - see bmask above */ 1762. (void) memcpy((genericptr_t) b->bm, (genericptr_t) bmask[n], 1763. (bmask[n][1] + 2) * sizeof(b->bm[0])); 1764. b->cons = 0; 1765. if (!bbubbles) 1766. bbubbles = b; 1767. if (ebubbles) { 1768. ebubbles->next = b; 1769. b->prev = ebubbles; 1770. } else 1771. b->prev = (struct bubble *) 0; 1772. b->next = (struct bubble *) 0; 1773. ebubbles = b; 1774. mv_bubble(b, 0, 0, TRUE); 1775. } 1776. 1777. /* 1778. * The player, the portal and all other objects and monsters 1779. * float along with their associated bubbles. Bubbles may overlap 1780. * freely, and the contents may get associated with other bubbles in 1781. * the process. Bubbles are "sticky", meaning that if the player is 1782. * in the immediate neighborhood of one, he/she may get sucked inside. 1783. * This property also makes leaving a bubble slightly difficult. 1784. */ 1785. STATIC_OVL void 1786. mv_bubble(b, dx, dy, ini) 1787. struct bubble *b; 1788. int dx, dy; 1789. boolean ini; 1790. { 1791. int x, y, i, j, colli = 0; 1792. struct container *cons, *ctemp; 1793. 1794. /* clouds move slowly */ 1795. if (!Is_airlevel(&u.uz) || !rn2(6)) { 1796. /* move bubble */ 1797. if (dx < -1 || dx > 1 || dy < -1 || dy > 1) { 1798. /* pline("mv_bubble: dx = %d, dy = %d", dx, dy); */ 1799. dx = sgn(dx); 1800. dy = sgn(dy); 1801. } 1802. 1803. /* 1804. * collision with level borders? 1805. * 1 = horizontal border, 2 = vertical, 3 = corner 1806. */ 1807. if (b->x <= bxmin) 1808. colli |= 2; 1809. if (b->y <= bymin) 1810. colli |= 1; 1811. if ((int) (b->x + b->bm[0] - 1) >= bxmax) 1812. colli |= 2; 1813. if ((int) (b->y + b->bm[1] - 1) >= bymax) 1814. colli |= 1; 1815. 1816. if (b->x < bxmin) { 1817. pline("bubble xmin: x = %d, xmin = %d", b->x, bxmin); 1818. b->x = bxmin; 1819. } 1820. if (b->y < bymin) { 1821. pline("bubble ymin: y = %d, ymin = %d", b->y, bymin); 1822. b->y = bymin; 1823. } 1824. if ((int) (b->x + b->bm[0] - 1) > bxmax) { 1825. pline("bubble xmax: x = %d, xmax = %d", b->x + b->bm[0] - 1, 1826. bxmax); 1827. b->x = bxmax - b->bm[0] + 1; 1828. } 1829. if ((int) (b->y + b->bm[1] - 1) > bymax) { 1830. pline("bubble ymax: y = %d, ymax = %d", b->y + b->bm[1] - 1, 1831. bymax); 1832. b->y = bymax - b->bm[1] + 1; 1833. } 1834. 1835. /* bounce if we're trying to move off the border */ 1836. if (b->x == bxmin && dx < 0) 1837. dx = -dx; 1838. if (b->x + b->bm[0] - 1 == bxmax && dx > 0) 1839. dx = -dx; 1840. if (b->y == bymin && dy < 0) 1841. dy = -dy; 1842. if (b->y + b->bm[1] - 1 == bymax && dy > 0) 1843. dy = -dy; 1844. 1845. b->x += dx; 1846. b->y += dy; 1847. } 1848. 1849. /* draw the bubbles */ 1850. for (i = 0, x = b->x; i < (int) b->bm[0]; i++, x++) 1851. for (j = 0, y = b->y; j < (int) b->bm[1]; j++, y++) 1852. if (b->bm[j + 2] & (1 << i)) { 1853. if (Is_waterlevel(&u.uz)) { 1854. levl[x][y].typ = AIR; 1855. levl[x][y].lit = 1; 1856. unblock_point(x, y); 1857. } else if (Is_airlevel(&u.uz)) { 1858. levl[x][y].typ = CLOUD; 1859. levl[x][y].lit = 1; 1860. block_point(x, y); 1861. } 1862. } 1863. 1864. if (Is_waterlevel(&u.uz)) { 1865. /* replace contents of bubble */ 1866. for (cons = b->cons; cons; cons = ctemp) { 1867. ctemp = cons->next; 1868. cons->x += dx; 1869. cons->y += dy; 1870. 1871. switch (cons->what) { 1872. case CONS_OBJ: { 1873. struct obj *olist, *otmp; 1874. 1875. for (olist = (struct obj *) cons->list; olist; olist = otmp) { 1876. otmp = olist->nexthere; 1877. place_object(olist, cons->x, cons->y); 1878. } 1879. break; 1880. } 1881. 1882. case CONS_MON: { 1883. struct monst *mon = (struct monst *) cons->list; 1884. 1885. (void) mnearto(mon, cons->x, cons->y, TRUE); 1886. break; 1887. } 1888. 1889. case CONS_HERO: { 1890. int ux0 = u.ux, uy0 = u.uy; 1891. 1892. /* change u.ux0 and u.uy0? */ 1893. u.ux = cons->x; 1894. u.uy = cons->y; 1895. newsym(ux0, uy0); /* clean up old position */ 1896. 1897. if (MON_AT(cons->x, cons->y)) { 1898. mnexto(m_at(cons->x, cons->y)); 1899. } 1900. break; 1901. } 1902. 1903. case CONS_TRAP: { 1904. struct trap *btrap = (struct trap *) cons->list; 1905. btrap->tx = cons->x; 1906. btrap->ty = cons->y; 1907. break; 1908. } 1909. 1910. default: 1911. impossible("mv_bubble: unknown bubble contents"); 1912. break; 1913. } 1914. free((genericptr_t) cons); 1915. } 1916. b->cons = 0; 1917. } 1918. 1919. /* boing? */ 1920. switch (colli) { 1921. case 1: 1922. b->dy = -b->dy; 1923. break; 1924. case 3: 1925. b->dy = -b->dy; /* fall through */ 1926. case 2: 1927. b->dx = -b->dx; 1928. break; 1929. default: 1930. /* sometimes alter direction for fun anyway 1931. (higher probability for stationary bubbles) */ 1932. if (!ini && ((b->dx || b->dy) ? !rn2(20) : !rn2(5))) { 1933. b->dx = 1 - rn2(3); 1934. b->dy = 1 - rn2(3); 1935. } 1936. } 1937. } 1938. 1939. /*mkmaze.c*/