Source:NetHack 3.6.1/src/do.c
(Redirected from Source:Do.c)
Jump to navigation
Jump to search
Below is the full text to do.c from the source code of NetHack 3.6.1. To link to a particular line, write [[Source:NetHack 3.6.1/src/do.c#line123]], for example.
Contents
- 1 Top of file
- 2 dodrop
- 3 boulder_hits_pool
- 4 flooreffects
- 5 doaltarobj
- 6 trycall
- 7 polymorph_sink
- 8 teleport_sink
- 9 dosinkring
- 10 canletgo
- 11 drop
- 12 dropx
- 13 dropy
- 14 dropz
- 15 obj_no_longer_held
- 16 doddrop
- 17 menu_drop
- 18 dodown
- 19 doup
- 20 currentlevel_rewrite
- 21 save_currentstate
- 22 goto_level
- 23 final_level
- 24 schedule_goto
- 25 deferred_goto
- 26 revive_corpse
- 27 revive_mon
- 28 donull
- 29 wipeoff
- 30 dowipe
- 31 set_wounded_legs
- 32 heal_legs
Top of file
1. /* NetHack 3.6 do.c $NHDT-Date: 1472809073 2016/09/02 09:37:53 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.158 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Derek S. Ray, 2015. */ 4. /* NetHack may be freely redistributed. See license for details. */
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.
5. 6. /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) */ 7. 8. #include "hack.h" 9. #include "lev.h" 10. 11. STATIC_DCL void FDECL(trycall, (struct obj *)); 12. STATIC_DCL void NDECL(polymorph_sink); 13. STATIC_DCL boolean NDECL(teleport_sink); 14. STATIC_DCL void FDECL(dosinkring, (struct obj *)); 15. STATIC_PTR int FDECL(drop, (struct obj *)); 16. STATIC_PTR int NDECL(wipeoff); 17. STATIC_DCL int FDECL(menu_drop, (int)); 18. STATIC_DCL int NDECL(currentlevel_rewrite); 19. STATIC_DCL void NDECL(final_level); 20. /* static boolean FDECL(badspot, (XCHAR_P,XCHAR_P)); */ 21. 22. extern int n_dgns; /* number of dungeons, from dungeon.c */ 23. 24. static NEARDATA const char drop_types[] = { ALLOW_COUNT, COIN_CLASS, 25. ALL_CLASSES, 0 }; 26.
dodrop
27. /* 'd' command: drop one inventory item */ 28. int 29. dodrop() 30. { 31. int result, i = (invent) ? 0 : (SIZE(drop_types) - 1); 32. 33. if (*u.ushops) 34. sellobj_state(SELL_DELIBERATE); 35. result = drop(getobj(&drop_types[i], "drop")); 36. if (*u.ushops) 37. sellobj_state(SELL_NORMAL); 38. if (result) 39. reset_occupations(); 40. 41. return result; 42. } 43.
boulder_hits_pool
44. /* Called when a boulder is dropped, thrown, or pushed. If it ends up 45. * in a pool, it either fills the pool up or sinks away. In either case, 46. * it's gone for good... If the destination is not a pool, returns FALSE. 47. */ 48. boolean 49. boulder_hits_pool(otmp, rx, ry, pushing) 50. struct obj *otmp; 51. register int rx, ry; 52. boolean pushing; 53. { 54. if (!otmp || otmp->otyp != BOULDER) { 55. impossible("Not a boulder?"); 56. } else if (!Is_waterlevel(&u.uz) && is_pool_or_lava(rx, ry)) { 57. boolean lava = is_lava(rx, ry), fills_up; 58. const char *what = waterbody_name(rx, ry); 59. schar ltyp = levl[rx][ry].typ; 60. int chance = rn2(10); /* water: 90%; lava: 10% */ 61. fills_up = lava ? chance == 0 : chance != 0; 62. 63. if (fills_up) { 64. struct trap *ttmp = t_at(rx, ry); 65. 66. if (ltyp == DRAWBRIDGE_UP) { 67. levl[rx][ry].drawbridgemask &= ~DB_UNDER; /* clear lava */ 68. levl[rx][ry].drawbridgemask |= DB_FLOOR; 69. } else 70. levl[rx][ry].typ = ROOM; 71. 72. if (ttmp) 73. (void) delfloortrap(ttmp); 74. bury_objs(rx, ry); 75. 76. newsym(rx, ry); 77. if (pushing) { 78. char whobuf[BUFSZ]; 79. 80. Strcpy(whobuf, "you"); 81. if (u.usteed) 82. Strcpy(whobuf, y_monnam(u.usteed)); 83. pline("%s %s %s into the %s.", upstart(whobuf), 84. vtense(whobuf, "push"), the(xname(otmp)), what); 85. if (flags.verbose && !Blind) 86. pline("Now you can cross it!"); 87. /* no splashing in this case */ 88. } 89. } 90. if (!fills_up || !pushing) { /* splashing occurs */ 91. if (!u.uinwater) { 92. if (pushing ? !Blind : cansee(rx, ry)) { 93. There("is a large splash as %s %s the %s.", 94. the(xname(otmp)), fills_up ? "fills" : "falls into", 95. what); 96. } else if (!Deaf) 97. You_hear("a%s splash.", lava ? " sizzling" : ""); 98. wake_nearto(rx, ry, 40); 99. } 100. 101. if (fills_up && u.uinwater && distu(rx, ry) == 0) { 102. u.uinwater = 0; 103. docrt(); 104. vision_full_recalc = 1; 105. You("find yourself on dry land again!"); 106. } else if (lava && distu(rx, ry) <= 2) { 107. int dmg; 108. You("are hit by molten %s%c", 109. hliquid("lava"), Fire_resistance ? '.' : '!'); 110. burn_away_slime(); 111. dmg = d((Fire_resistance ? 1 : 3), 6); 112. losehp(Maybe_Half_Phys(dmg), /* lava damage */ 113. "molten lava", KILLED_BY); 114. } else if (!fills_up && flags.verbose 115. && (pushing ? !Blind : cansee(rx, ry))) 116. pline("It sinks without a trace!"); 117. } 118. 119. /* boulder is now gone */ 120. if (pushing) 121. delobj(otmp); 122. else 123. obfree(otmp, (struct obj *) 0); 124. return TRUE; 125. } 126. return FALSE; 127. } 128.
flooreffects
129. /* Used for objects which sometimes do special things when dropped; must be 130. * called with the object not in any chain. Returns TRUE if the object goes 131. * away. 132. */ 133. boolean 134. flooreffects(obj, x, y, verb) 135. struct obj *obj; 136. int x, y; 137. const char *verb; 138. { 139. struct trap *t; 140. struct monst *mtmp; 141. struct obj *otmp; 142. 143. if (obj->where != OBJ_FREE) 144. panic("flooreffects: obj not free"); 145. 146. /* make sure things like water_damage() have no pointers to follow */ 147. obj->nobj = obj->nexthere = (struct obj *) 0; 148. 149. if (obj->otyp == BOULDER && boulder_hits_pool(obj, x, y, FALSE)) { 150. return TRUE; 151. } else if (obj->otyp == BOULDER && (t = t_at(x, y)) != 0 152. && (t->ttyp == PIT || t->ttyp == SPIKED_PIT 153. || t->ttyp == TRAPDOOR || t->ttyp == HOLE)) { 154. if (((mtmp = m_at(x, y)) && mtmp->mtrapped) 155. || (u.utrap && u.ux == x && u.uy == y)) { 156. if (*verb) 157. pline_The("boulder %s into the pit%s.", 158. vtense((const char *) 0, verb), 159. (mtmp) ? "" : " with you"); 160. if (mtmp) { 161. if (!passes_walls(mtmp->data) && !throws_rocks(mtmp->data)) { 162. int dieroll = rnd(20); 163. 164. if (hmon(mtmp, obj, HMON_THROWN, dieroll) 165. && !is_whirly(mtmp->data)) 166. return FALSE; /* still alive */ 167. } 168. mtmp->mtrapped = 0; 169. } else { 170. if (!Passes_walls && !throws_rocks(youmonst.data)) { 171. losehp(Maybe_Half_Phys(rnd(15)), 172. "squished under a boulder", NO_KILLER_PREFIX); 173. return FALSE; /* player remains trapped */ 174. } else 175. u.utrap = 0; 176. } 177. } 178. if (*verb) { 179. if (Blind && (x == u.ux) && (y == u.uy)) { 180. You_hear("a CRASH! beneath you."); 181. } else if (!Blind && cansee(x, y)) { 182. pline_The("boulder %s%s.", t->tseen ? "" : "triggers and ", 183. t->ttyp == TRAPDOOR 184. ? "plugs a trap door" 185. : t->ttyp == HOLE ? "plugs a hole" 186. : "fills a pit"); 187. } else { 188. You_hear("a boulder %s.", verb); 189. } 190. } 191. deltrap(t); 192. useupf(obj, 1L); 193. bury_objs(x, y); 194. newsym(x, y); 195. return TRUE; 196. } else if (is_lava(x, y)) { 197. return lava_damage(obj, x, y); 198. } else if (is_pool(x, y)) { 199. /* Reasonably bulky objects (arbitrary) splash when dropped. 200. * If you're floating above the water even small things make 201. * noise. Stuff dropped near fountains always misses */ 202. if ((Blind || (Levitation || Flying)) && !Deaf 203. && ((x == u.ux) && (y == u.uy))) { 204. if (!Underwater) { 205. if (weight(obj) > 9) { 206. pline("Splash!"); 207. } else if (Levitation || Flying) { 208. pline("Plop!"); 209. } 210. } 211. map_background(x, y, 0); 212. newsym(x, y); 213. } 214. return water_damage(obj, NULL, FALSE) == ER_DESTROYED; 215. } else if (u.ux == x && u.uy == y && (t = t_at(x, y)) != 0 216. && uteetering_at_seen_pit(t)) { 217. if (Blind && !Deaf) 218. You_hear("%s tumble downwards.", the(xname(obj))); 219. else 220. pline("%s %s into %s pit.", The(xname(obj)), 221. otense(obj, "tumble"), the_your[t->madeby_u]); 222. } else if (obj->globby) { 223. /* Globby things like puddings might stick together */ 224. while (obj && (otmp = obj_nexto_xy(obj, x, y, TRUE)) != 0) { 225. pudding_merge_message(obj, otmp); 226. /* intentionally not getting the melded object; obj_meld may set 227. * obj to null. */ 228. (void) obj_meld(&obj, &otmp); 229. } 230. return (boolean) !obj; 231. } 232. return FALSE; 233. } 234.
doaltarobj
235. /* obj is an object dropped on an altar */ 236. void 237. doaltarobj(obj) 238. register struct obj *obj; 239. { 240. if (Blind) 241. return; 242. 243. if (obj->oclass != COIN_CLASS) { 244. /* KMH, conduct */ 245. u.uconduct.gnostic++; 246. } else { 247. /* coins don't have bless/curse status */ 248. obj->blessed = obj->cursed = 0; 249. } 250. 251. if (obj->blessed || obj->cursed) { 252. There("is %s flash as %s %s the altar.", 253. an(hcolor(obj->blessed ? NH_AMBER : NH_BLACK)), doname(obj), 254. otense(obj, "hit")); 255. if (!Hallucination) 256. obj->bknown = 1; 257. } else { 258. pline("%s %s on the altar.", Doname2(obj), otense(obj, "land")); 259. if (obj->oclass != COIN_CLASS) 260. obj->bknown = 1; 261. } 262. } 263.
trycall
264. STATIC_OVL void 265. trycall(obj) 266. register struct obj *obj; 267. { 268. if (!objects[obj->otyp].oc_name_known && !objects[obj->otyp].oc_uname) 269. docall(obj); 270. } 271.
polymorph_sink
272. /* Transforms the sink at the player's position into 273. a fountain, throne, altar or grave. */ 274. STATIC_DCL void 275. polymorph_sink() 276. { 277. uchar sym = S_sink; 278. 279. if (levl[u.ux][u.uy].typ != SINK) 280. return; 281. 282. level.flags.nsinks--; 283. levl[u.ux][u.uy].doormask = 0; 284. switch (rn2(4)) { 285. default: 286. case 0: 287. sym = S_fountain; 288. levl[u.ux][u.uy].typ = FOUNTAIN; 289. level.flags.nfountains++; 290. break; 291. case 1: 292. sym = S_throne; 293. levl[u.ux][u.uy].typ = THRONE; 294. break; 295. case 2: 296. sym = S_altar; 297. levl[u.ux][u.uy].typ = ALTAR; 298. levl[u.ux][u.uy].altarmask = Align2amask(rn2((int) A_LAWFUL + 2) - 1); 299. break; 300. case 3: 301. sym = S_room; 302. levl[u.ux][u.uy].typ = ROOM; 303. make_grave(u.ux, u.uy, (char *) 0); 304. if (levl[u.ux][u.uy].typ == GRAVE) 305. sym = S_grave; 306. break; 307. } 308. /* give message even if blind; we know we're not levitating, 309. so can feel the outcome even if we can't directly see it */ 310. if (levl[u.ux][u.uy].typ != ROOM) 311. pline_The("sink transforms into %s!", an(defsyms[sym].explanation)); 312. else 313. pline_The("sink vanishes."); 314. newsym(u.ux, u.uy); 315. } 316.
teleport_sink
317. /* Teleports the sink at the player's position; 318. return True if sink teleported. */ 319. STATIC_DCL boolean 320. teleport_sink() 321. { 322. int cx, cy; 323. int cnt = 0; 324. struct trap *trp; 325. struct engr *eng; 326. 327. do { 328. cx = rnd(COLNO - 1); 329. cy = rn2(ROWNO); 330. trp = t_at(cx, cy); 331. eng = engr_at(cx, cy); 332. } while ((levl[cx][cy].typ != ROOM || trp || eng || cansee(cx, cy)) 333. && cnt++ < 200); 334. 335. if (levl[cx][cy].typ == ROOM && !trp && !eng) { 336. /* create sink at new position */ 337. levl[cx][cy].typ = SINK; 338. levl[cx][cy].looted = levl[u.ux][u.uy].looted; 339. newsym(cx, cy); 340. /* remove old sink */ 341. levl[u.ux][u.uy].typ = ROOM; 342. levl[u.ux][u.uy].looted = 0; 343. newsym(u.ux, u.uy); 344. return TRUE; 345. } 346. return FALSE; 347. } 348.
dosinkring
349. /* obj is a ring being dropped over a kitchen sink */ 350. STATIC_OVL void 351. dosinkring(obj) 352. register struct obj *obj; 353. { 354. struct obj *otmp, *otmp2; 355. boolean ideed = TRUE; 356. boolean nosink = FALSE; 357. 358. You("drop %s down the drain.", doname(obj)); 359. obj->in_use = TRUE; /* block free identification via interrupt */ 360. switch (obj->otyp) { /* effects that can be noticed without eyes */ 361. case RIN_SEARCHING: 362. You("thought %s got lost in the sink, but there it is!", yname(obj)); 363. goto giveback; 364. case RIN_SLOW_DIGESTION: 365. pline_The("ring is regurgitated!"); 366. giveback: 367. obj->in_use = FALSE; 368. dropx(obj); 369. trycall(obj); 370. return; 371. case RIN_LEVITATION: 372. pline_The("sink quivers upward for a moment."); 373. break; 374. case RIN_POISON_RESISTANCE: 375. You("smell rotten %s.", makeplural(fruitname(FALSE))); 376. break; 377. case RIN_AGGRAVATE_MONSTER: 378. pline("Several %s buzz angrily around the sink.", 379. Hallucination ? makeplural(rndmonnam(NULL)) : "flies"); 380. break; 381. case RIN_SHOCK_RESISTANCE: 382. pline("Static electricity surrounds the sink."); 383. break; 384. case RIN_CONFLICT: 385. You_hear("loud noises coming from the drain."); 386. break; 387. case RIN_SUSTAIN_ABILITY: /* KMH */ 388. pline_The("%s flow seems fixed.", hliquid("water")); 389. break; 390. case RIN_GAIN_STRENGTH: 391. pline_The("%s flow seems %ser now.", 392. hliquid("water"), 393. (obj->spe < 0) ? "weak" : "strong"); 394. break; 395. case RIN_GAIN_CONSTITUTION: 396. pline_The("%s flow seems %ser now.", 397. hliquid("water"), 398. (obj->spe < 0) ? "less" : "great"); 399. break; 400. case RIN_INCREASE_ACCURACY: /* KMH */ 401. pline_The("%s flow %s the drain.", 402. hliquid("water"), 403. (obj->spe < 0) ? "misses" : "hits"); 404. break; 405. case RIN_INCREASE_DAMAGE: 406. pline_The("water's force seems %ser now.", 407. (obj->spe < 0) ? "small" : "great"); 408. break; 409. case RIN_HUNGER: 410. ideed = FALSE; 411. for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp2) { 412. otmp2 = otmp->nexthere; 413. if (otmp != uball && otmp != uchain 414. && !obj_resists(otmp, 1, 99)) { 415. if (!Blind) { 416. pline("Suddenly, %s %s from the sink!", doname(otmp), 417. otense(otmp, "vanish")); 418. ideed = TRUE; 419. } 420. delobj(otmp); 421. } 422. } 423. break; 424. case MEAT_RING: 425. /* Not the same as aggravate monster; besides, it's obvious. */ 426. pline("Several flies buzz around the sink."); 427. break; 428. case RIN_TELEPORTATION: 429. nosink = teleport_sink(); 430. /* give message even if blind; we know we're not levitating, 431. so can feel the outcome even if we can't directly see it */ 432. pline_The("sink %svanishes.", nosink ? "" : "momentarily "); 433. ideed = FALSE; 434. break; 435. case RIN_POLYMORPH: 436. polymorph_sink(); 437. nosink = TRUE; 438. /* for S_room case, same message as for teleportation is given */ 439. ideed = (levl[u.ux][u.uy].typ != ROOM); 440. break; 441. default: 442. ideed = FALSE; 443. break; 444. } 445. if (!Blind && !ideed) { 446. ideed = TRUE; 447. switch (obj->otyp) { /* effects that need eyes */ 448. case RIN_ADORNMENT: 449. pline_The("faucets flash brightly for a moment."); 450. break; 451. case RIN_REGENERATION: 452. pline_The("sink looks as good as new."); 453. break; 454. case RIN_INVISIBILITY: 455. You("don't see anything happen to the sink."); 456. break; 457. case RIN_FREE_ACTION: 458. You_see("the ring slide right down the drain!"); 459. break; 460. case RIN_SEE_INVISIBLE: 461. You_see("some %s in the sink.", 462. Hallucination ? "oxygen molecules" : "air"); 463. break; 464. case RIN_STEALTH: 465. pline_The("sink seems to blend into the floor for a moment."); 466. break; 467. case RIN_FIRE_RESISTANCE: 468. pline_The("hot %s faucet flashes brightly for a moment.", 469. hliquid("water")); 470. break; 471. case RIN_COLD_RESISTANCE: 472. pline_The("cold %s faucet flashes brightly for a moment.", 473. hliquid("water")); 474. break; 475. case RIN_PROTECTION_FROM_SHAPE_CHAN: 476. pline_The("sink looks nothing like a fountain."); 477. break; 478. case RIN_PROTECTION: 479. pline_The("sink glows %s for a moment.", 480. hcolor((obj->spe < 0) ? NH_BLACK : NH_SILVER)); 481. break; 482. case RIN_WARNING: 483. pline_The("sink glows %s for a moment.", hcolor(NH_WHITE)); 484. break; 485. case RIN_TELEPORT_CONTROL: 486. pline_The("sink looks like it is being beamed aboard somewhere."); 487. break; 488. case RIN_POLYMORPH_CONTROL: 489. pline_The( 490. "sink momentarily looks like a regularly erupting geyser."); 491. break; 492. default: 493. break; 494. } 495. } 496. if (ideed) 497. trycall(obj); 498. else if (!nosink) 499. You_hear("the ring bouncing down the drainpipe."); 500. 501. if (!rn2(20) && !nosink) { 502. pline_The("sink backs up, leaving %s.", doname(obj)); 503. obj->in_use = FALSE; 504. dropx(obj); 505. } else if (!rn2(5)) { 506. freeinv(obj); 507. obj->in_use = FALSE; 508. obj->ox = u.ux; 509. obj->oy = u.uy; 510. add_to_buried(obj); 511. } else 512. useup(obj); 513. } 514.
canletgo
515. /* some common tests when trying to drop or throw items */ 516. boolean 517. canletgo(obj, word) 518. struct obj *obj; 519. const char *word; 520. { 521. if (obj->owornmask & (W_ARMOR | W_ACCESSORY)) { 522. if (*word) 523. Norep("You cannot %s %s you are wearing.", word, something); 524. return FALSE; 525. } 526. if (obj->otyp == LOADSTONE && obj->cursed) { 527. /* getobj() kludge sets corpsenm to user's specified count 528. when refusing to split a stack of cursed loadstones */ 529. if (*word) { 530. /* getobj() ignores a count for throwing since that is 531. implicitly forced to be 1; replicate its kludge... */ 532. if (!strcmp(word, "throw") && obj->quan > 1L) 533. obj->corpsenm = 1; 534. pline("For some reason, you cannot %s%s the stone%s!", word, 535. obj->corpsenm ? " any of" : "", plur(obj->quan)); 536. } 537. obj->corpsenm = 0; /* reset */ 538. obj->bknown = 1; 539. return FALSE; 540. } 541. if (obj->otyp == LEASH && obj->leashmon != 0) { 542. if (*word) 543. pline_The("leash is tied around your %s.", body_part(HAND)); 544. return FALSE; 545. } 546. if (obj->owornmask & W_SADDLE) { 547. if (*word) 548. You("cannot %s %s you are sitting on.", word, something); 549. return FALSE; 550. } 551. return TRUE; 552. } 553.
drop
554. STATIC_PTR int 555. drop(obj) 556. register struct obj *obj; 557. { 558. if (!obj) 559. return 0; 560. if (!canletgo(obj, "drop")) 561. return 0; 562. if (obj == uwep) { 563. if (welded(uwep)) { 564. weldmsg(obj); 565. return 0; 566. } 567. setuwep((struct obj *) 0); 568. } 569. if (obj == uquiver) { 570. setuqwep((struct obj *) 0); 571. } 572. if (obj == uswapwep) { 573. setuswapwep((struct obj *) 0); 574. } 575. 576. if (u.uswallow) { 577. /* barrier between you and the floor */ 578. if (flags.verbose) { 579. char buf[BUFSZ]; 580. 581. /* doname can call s_suffix, reusing its buffer */ 582. Strcpy(buf, s_suffix(mon_nam(u.ustuck))); 583. You("drop %s into %s %s.", doname(obj), buf, 584. mbodypart(u.ustuck, STOMACH)); 585. } 586. } else { 587. if ((obj->oclass == RING_CLASS || obj->otyp == MEAT_RING) 588. && IS_SINK(levl[u.ux][u.uy].typ)) { 589. dosinkring(obj); 590. return 1; 591. } 592. if (!can_reach_floor(TRUE)) { 593. /* we might be levitating due to #invoke Heart of Ahriman; 594. if so, levitation would end during call to freeinv() 595. and we want hitfloor() to happen before float_down() */ 596. boolean levhack = finesse_ahriman(obj); 597. 598. if (levhack) 599. ELevitation = W_ART; /* other than W_ARTI */ 600. if (flags.verbose) 601. You("drop %s.", doname(obj)); 602. /* Ensure update when we drop gold objects */ 603. if (obj->oclass == COIN_CLASS) 604. context.botl = 1; 605. freeinv(obj); 606. hitfloor(obj); 607. if (levhack) 608. float_down(I_SPECIAL | TIMEOUT, W_ARTI | W_ART); 609. return 1; 610. } 611. if (!IS_ALTAR(levl[u.ux][u.uy].typ) && flags.verbose) 612. You("drop %s.", doname(obj)); 613. } 614. dropx(obj); 615. return 1; 616. } 617.
dropx
618. /* dropx - take dropped item out of inventory; 619. called in several places - may produce output 620. (eg ship_object() and dropy() -> sellobj() both produce output) */ 621. void 622. dropx(obj) 623. register struct obj *obj; 624. { 625. /* Ensure update when we drop gold objects */ 626. if (obj->oclass == COIN_CLASS) 627. context.botl = 1; 628. freeinv(obj); 629. if (!u.uswallow) { 630. if (ship_object(obj, u.ux, u.uy, FALSE)) 631. return; 632. if (IS_ALTAR(levl[u.ux][u.uy].typ)) 633. doaltarobj(obj); /* set bknown */ 634. } 635. dropy(obj); 636. } 637.
dropy
638. /* dropy - put dropped object at destination; called from lots of places */ 639. void 640. dropy(obj) 641. struct obj *obj; 642. { 643. dropz(obj, FALSE); 644. } 645.
dropz
646. /* dropz - really put dropped object at its destination... */ 647. void 648. dropz(obj, with_impact) 649. struct obj *obj; 650. boolean with_impact; 651. { 652. if (obj == uwep) 653. setuwep((struct obj *) 0); 654. if (obj == uquiver) 655. setuqwep((struct obj *) 0); 656. if (obj == uswapwep) 657. setuswapwep((struct obj *) 0); 658. 659. if (!u.uswallow && flooreffects(obj, u.ux, u.uy, "drop")) 660. return; 661. /* uswallow check done by GAN 01/29/87 */ 662. if (u.uswallow) { 663. boolean could_petrify = FALSE; 664. boolean could_poly = FALSE; 665. boolean could_slime = FALSE; 666. boolean could_grow = FALSE; 667. boolean could_heal = FALSE; 668. 669. if (obj != uball) { /* mon doesn't pick up ball */ 670. if (obj->otyp == CORPSE) { 671. could_petrify = touch_petrifies(&mons[obj->corpsenm]); 672. could_poly = polyfodder(obj); 673. could_slime = (obj->corpsenm == PM_GREEN_SLIME); 674. could_grow = (obj->corpsenm == PM_WRAITH); 675. could_heal = (obj->corpsenm == PM_NURSE); 676. } 677. (void) mpickobj(u.ustuck, obj); 678. if (is_animal(u.ustuck->data)) { 679. if (could_poly || could_slime) { 680. (void) newcham(u.ustuck, 681. could_poly ? (struct permonst *) 0 682. : &mons[PM_GREEN_SLIME], 683. FALSE, could_slime); 684. delobj(obj); /* corpse is digested */ 685. } else if (could_petrify) { 686. minstapetrify(u.ustuck, TRUE); 687. /* Don't leave a cockatrice corpse in a statue */ 688. if (!u.uswallow) 689. delobj(obj); 690. } else if (could_grow) { 691. (void) grow_up(u.ustuck, (struct monst *) 0); 692. delobj(obj); /* corpse is digested */ 693. } else if (could_heal) { 694. u.ustuck->mhp = u.ustuck->mhpmax; 695. delobj(obj); /* corpse is digested */ 696. } 697. } 698. } 699. } else { 700. place_object(obj, u.ux, u.uy); 701. if (with_impact) 702. container_impact_dmg(obj, u.ux, u.uy); 703. if (obj == uball) 704. drop_ball(u.ux, u.uy); 705. else if (level.flags.has_shop) 706. sellobj(obj, u.ux, u.uy); 707. stackobj(obj); 708. if (Blind && Levitation) 709. map_object(obj, 0); 710. newsym(u.ux, u.uy); /* remap location under self */ 711. } 712. } 713.
obj_no_longer_held
714. /* things that must change when not held; recurse into containers. 715. Called for both player and monsters */ 716. void 717. obj_no_longer_held(obj) 718. struct obj *obj; 719. { 720. if (!obj) { 721. return; 722. } else if (Has_contents(obj)) { 723. struct obj *contents; 724. 725. for (contents = obj->cobj; contents; contents = contents->nobj) 726. obj_no_longer_held(contents); 727. } 728. switch (obj->otyp) { 729. case CRYSKNIFE: 730. /* Normal crysknife reverts to worm tooth when not held by hero 731. * or monster; fixed crysknife has only 10% chance of reverting. 732. * When a stack of the latter is involved, it could be worthwhile 733. * to give each individual crysknife its own separate 10% chance, 734. * but we aren't in any position to handle stack splitting here. 735. */ 736. if (!obj->oerodeproof || !rn2(10)) { 737. /* if monsters aren't moving, assume player is responsible */ 738. if (!context.mon_moving && !program_state.gameover) 739. costly_alteration(obj, COST_DEGRD); 740. obj->otyp = WORM_TOOTH; 741. obj->oerodeproof = 0; 742. } 743. break; 744. } 745. } 746.
doddrop
747. /* 'D' command: drop several things */ 748. int 749. doddrop() 750. { 751. int result = 0; 752. 753. if (!invent) { 754. You("have nothing to drop."); 755. return 0; 756. } 757. add_valid_menu_class(0); /* clear any classes already there */ 758. if (*u.ushops) 759. sellobj_state(SELL_DELIBERATE); 760. if (flags.menu_style != MENU_TRADITIONAL 761. || (result = ggetobj("drop", drop, 0, FALSE, (unsigned *) 0)) < -1) 762. result = menu_drop(result); 763. if (*u.ushops) 764. sellobj_state(SELL_NORMAL); 765. if (result) 766. reset_occupations(); 767. 768. return result; 769. } 770.
771. /* Drop things from the hero's inventory, using a menu. */ 772. STATIC_OVL int 773. menu_drop(retry) 774. int retry; 775. { 776. int n, i, n_dropped = 0; 777. long cnt; 778. struct obj *otmp, *otmp2; 779. menu_item *pick_list; 780. boolean all_categories = TRUE; 781. boolean drop_everything = FALSE; 782. 783. if (retry) { 784. all_categories = (retry == -2); 785. } else if (flags.menu_style == MENU_FULL) { 786. all_categories = FALSE; 787. n = query_category("Drop what type of items?", invent, 788. UNPAID_TYPES | ALL_TYPES | CHOOSE_ALL | BUC_BLESSED 789. | BUC_CURSED | BUC_UNCURSED | BUC_UNKNOWN, 790. &pick_list, PICK_ANY); 791. if (!n) 792. goto drop_done; 793. for (i = 0; i < n; i++) { 794. if (pick_list[i].item.a_int == ALL_TYPES_SELECTED) 795. all_categories = TRUE; 796. else if (pick_list[i].item.a_int == 'A') 797. drop_everything = TRUE; 798. else 799. add_valid_menu_class(pick_list[i].item.a_int); 800. } 801. free((genericptr_t) pick_list); 802. } else if (flags.menu_style == MENU_COMBINATION) { 803. unsigned ggoresults = 0; 804. 805. all_categories = FALSE; 806. /* Gather valid classes via traditional NetHack method */ 807. i = ggetobj("drop", drop, 0, TRUE, &ggoresults); 808. if (i == -2) 809. all_categories = TRUE; 810. if (ggoresults & ALL_FINISHED) { 811. n_dropped = i; 812. goto drop_done; 813. } 814. } 815. 816. if (drop_everything) { 817. /* 818. * Dropping a burning potion of oil while levitating can cause 819. * an explosion which might destroy some of hero's inventory, 820. * so the old code 821. * for (otmp = invent; otmp; otmp = otmp2) { 822. * otmp2 = otmp->nobj; 823. * n_dropped += drop(otmp); 824. * } 825. * was unreliable and could lead to an "object lost" panic. 826. * 827. * Use the bypass bit to mark items already processed (hence 828. * not droppable) and rescan inventory until no unbypassed 829. * items remain. 830. */ 831. bypass_objlist(invent, FALSE); /* clear bypass bit for invent */ 832. while ((otmp = nxt_unbypassed_obj(invent)) != 0) 833. n_dropped += drop(otmp); 834. /* we might not have dropped everything (worn armor, welded weapon, 835. cursed loadstones), so reset any remaining inventory to normal */ 836. bypass_objlist(invent, FALSE); 837. } else { 838. /* should coordinate with perm invent, maybe not show worn items */ 839. n = query_objlist("What would you like to drop?", &invent, 840. (USE_INVLET | INVORDER_SORT), &pick_list, PICK_ANY, 841. all_categories ? allow_all : allow_category); 842. if (n > 0) { 843. /* 844. * picklist[] contains a set of pointers into inventory, but 845. * as soon as something gets dropped, they might become stale 846. * (see the drop_everything code above for an explanation). 847. * Just checking to see whether one is still in the invent 848. * chain is not sufficient validation since destroyed items 849. * will be freed and items we've split here might have already 850. * reused that memory and put the same pointer value back into 851. * invent. Ditto for using invlet to validate. So we start 852. * by setting bypass on all of invent, then check each pointer 853. * to verify that it is in invent and has that bit set. 854. */ 855. bypass_objlist(invent, TRUE); 856. for (i = 0; i < n; i++) { 857. otmp = pick_list[i].item.a_obj; 858. for (otmp2 = invent; otmp2; otmp2 = otmp2->nobj) 859. if (otmp2 == otmp) 860. break; 861. if (!otmp2 || !otmp2->bypass) 862. continue; 863. /* found next selected invent item */ 864. cnt = pick_list[i].count; 865. if (cnt < otmp->quan) { 866. if (welded(otmp)) { 867. ; /* don't split */ 868. } else if (otmp->otyp == LOADSTONE && otmp->cursed) { 869. /* same kludge as getobj(), for canletgo()'s use */ 870. otmp->corpsenm = (int) cnt; /* don't split */ 871. } else { 872. otmp = splitobj(otmp, cnt); 873. } 874. } 875. n_dropped += drop(otmp); 876. } 877. bypass_objlist(invent, FALSE); /* reset invent to normal */ 878. free((genericptr_t) pick_list); 879. } 880. } 881. 882. drop_done: 883. return n_dropped; 884. } 885. 886. /* on a ladder, used in goto_level */ 887. static NEARDATA boolean at_ladder = FALSE; 888.
dodown
889. /* the '>' command */ 890. int 891. dodown() 892. { 893. struct trap *trap = 0; 894. boolean stairs_down = ((u.ux == xdnstair && u.uy == ydnstair) 895. || (u.ux == sstairs.sx && u.uy == sstairs.sy 896. && !sstairs.up)), 897. ladder_down = (u.ux == xdnladder && u.uy == ydnladder); 898. 899. if (u_rooted()) 900. return 1; 901. 902. if (stucksteed(TRUE)) { 903. return 0; 904. } 905. /* Levitation might be blocked, but player can still use '>' to 906. turn off controlled levitation */ 907. if (HLevitation || ELevitation) { 908. if ((HLevitation & I_SPECIAL) || (ELevitation & W_ARTI)) { 909. /* end controlled levitation */ 910. if (ELevitation & W_ARTI) { 911. struct obj *obj; 912. 913. for (obj = invent; obj; obj = obj->nobj) { 914. if (obj->oartifact 915. && artifact_has_invprop(obj, LEVITATION)) { 916. if (obj->age < monstermoves) 917. obj->age = monstermoves; 918. obj->age += rnz(100); 919. } 920. } 921. } 922. if (float_down(I_SPECIAL | TIMEOUT, W_ARTI)) { 923. return 1; /* came down, so moved */ 924. } else if (!HLevitation && !ELevitation) { 925. Your("latent levitation ceases."); 926. return 1; /* did something, effectively moved */ 927. } 928. } 929. if (BLevitation) { 930. ; /* weren't actually floating after all */ 931. } else if (Blind) { 932. /* Avoid alerting player to an unknown stair or ladder. 933. * Changes the message for a covered, known staircase 934. * too; staircase knowledge is not stored anywhere. 935. */ 936. if (stairs_down) 937. stairs_down = 938. (glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnstair); 939. else if (ladder_down) 940. ladder_down = 941. (glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnladder); 942. } 943. if (Is_airlevel(&u.uz)) 944. You("are floating in the %s.", surface(u.ux, u.uy)); 945. else if (Is_waterlevel(&u.uz)) 946. You("are floating in %s.", 947. is_pool(u.ux, u.uy) ? "the water" : "a bubble of air"); 948. else 949. floating_above(stairs_down ? "stairs" : ladder_down 950. ? "ladder" 951. : surface(u.ux, u.uy)); 952. return 0; /* didn't move */ 953. } 954. if (!stairs_down && !ladder_down) { 955. trap = t_at(u.ux, u.uy); 956. if (trap && uteetering_at_seen_pit(trap)) { 957. dotrap(trap, TOOKPLUNGE); 958. return 1; 959. } else if (!trap || (trap->ttyp != TRAPDOOR && trap->ttyp != HOLE) 960. || !Can_fall_thru(&u.uz) || !trap->tseen) { 961. if (flags.autodig && !context.nopick && uwep && is_pick(uwep)) { 962. return use_pick_axe2(uwep); 963. } else { 964. You_cant("go down here."); 965. return 0; 966. } 967. } 968. } 969. if (u.ustuck) { 970. You("are %s, and cannot go down.", 971. !u.uswallow ? "being held" : is_animal(u.ustuck->data) 972. ? "swallowed" 973. : "engulfed"); 974. return 1; 975. } 976. if (on_level(&valley_level, &u.uz) && !u.uevent.gehennom_entered) { 977. You("are standing at the gate to Gehennom."); 978. pline("Unspeakable cruelty and harm lurk down there."); 979. if (yn("Are you sure you want to enter?") != 'y') 980. return 0; 981. else 982. pline("So be it."); 983. u.uevent.gehennom_entered = 1; /* don't ask again */ 984. } 985. 986. if (!next_to_u()) { 987. You("are held back by your pet!"); 988. return 0; 989. } 990. 991. if (trap) 992. You("%s %s.", Flying ? "fly" : locomotion(youmonst.data, "jump"), 993. trap->ttyp == HOLE ? "down the hole" : "through the trap door"); 994. 995. if (trap && Is_stronghold(&u.uz)) { 996. goto_hell(FALSE, TRUE); 997. } else { 998. at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER); 999. next_level(!trap); 1000. at_ladder = FALSE; 1001. } 1002. return 1; 1003. } 1004.
doup
1005. /* the '<' command */ 1006. int 1007. doup() 1008. { 1009. if (u_rooted()) 1010. return 1; 1011. 1012. /* "up" to get out of a pit... */ 1013. if (u.utrap && u.utraptype == TT_PIT) { 1014. climb_pit(); 1015. return 1; 1016. } 1017. 1018. if ((u.ux != xupstair || u.uy != yupstair) 1019. && (!xupladder || u.ux != xupladder || u.uy != yupladder) 1020. && (!sstairs.sx || u.ux != sstairs.sx || u.uy != sstairs.sy 1021. || !sstairs.up)) { 1022. You_cant("go up here."); 1023. return 0; 1024. } 1025. if (stucksteed(TRUE)) { 1026. return 0; 1027. } 1028. if (u.ustuck) { 1029. You("are %s, and cannot go up.", 1030. !u.uswallow ? "being held" : is_animal(u.ustuck->data) 1031. ? "swallowed" 1032. : "engulfed"); 1033. return 1; 1034. } 1035. if (near_capacity() > SLT_ENCUMBER) { 1036. /* No levitation check; inv_weight() already allows for it */ 1037. Your("load is too heavy to climb the %s.", 1038. levl[u.ux][u.uy].typ == STAIRS ? "stairs" : "ladder"); 1039. return 1; 1040. } 1041. if (ledger_no(&u.uz) == 1) { 1042. if (yn("Beware, there will be no return! Still climb?") != 'y') 1043. return 0; 1044. } 1045. if (!next_to_u()) { 1046. You("are held back by your pet!"); 1047. return 0; 1048. } 1049. at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER); 1050. prev_level(TRUE); 1051. at_ladder = FALSE; 1052. return 1; 1053. } 1054. 1055. d_level save_dlevel = { 0, 0 }; 1056.
currentlevel_rewrite
1057. /* check that we can write out the current level */ 1058. STATIC_OVL int 1059. currentlevel_rewrite() 1060. { 1061. register int fd; 1062. char whynot[BUFSZ]; 1063. 1064. /* since level change might be a bit slow, flush any buffered screen 1065. * output (like "you fall through a trap door") */ 1066. mark_synch(); 1067. 1068. fd = create_levelfile(ledger_no(&u.uz), whynot); 1069. if (fd < 0) { 1070. /* 1071. * This is not quite impossible: e.g., we may have 1072. * exceeded our quota. If that is the case then we 1073. * cannot leave this level, and cannot save either. 1074. * Another possibility is that the directory was not 1075. * writable. 1076. */ 1077. pline1(whynot); 1078. return -1; 1079. } 1080. 1081. #ifdef MFLOPPY 1082. if (!savelev(fd, ledger_no(&u.uz), COUNT_SAVE)) { 1083. (void) nhclose(fd); 1084. delete_levelfile(ledger_no(&u.uz)); 1085. pline("NetHack is out of disk space for making levels!"); 1086. You("can save, quit, or continue playing."); 1087. return -1; 1088. } 1089. #endif 1090. return fd; 1091. } 1092.
save_currentstate
1093. #ifdef INSURANCE 1094. void 1095. save_currentstate() 1096. { 1097. int fd; 1098. 1099. if (flags.ins_chkpt) { 1100. /* write out just-attained level, with pets and everything */ 1101. fd = currentlevel_rewrite(); 1102. if (fd < 0) 1103. return; 1104. bufon(fd); 1105. savelev(fd, ledger_no(&u.uz), WRITE_SAVE); 1106. bclose(fd); 1107. } 1108. 1109. /* write out non-level state */ 1110. savestateinlock(); 1111. } 1112. #endif 1113. 1114. /* 1115. static boolean 1116. badspot(x, y) 1117. register xchar x, y; 1118. { 1119. return (boolean) ((levl[x][y].typ != ROOM 1120. && levl[x][y].typ != AIR 1121. && levl[x][y].typ != CORR) 1122. || MON_AT(x, y)); 1123. } 1124. */ 1125.
goto_level
1126. void 1127. goto_level(newlevel, at_stairs, falling, portal) 1128. d_level *newlevel; 1129. boolean at_stairs, falling, portal; 1130. { 1131. int fd, l_idx; 1132. xchar new_ledger; 1133. boolean cant_go_back, great_effort, 1134. up = (depth(newlevel) < depth(&u.uz)), 1135. newdungeon = (u.uz.dnum != newlevel->dnum), 1136. was_in_W_tower = In_W_tower(u.ux, u.uy, &u.uz), 1137. familiar = FALSE, 1138. new = FALSE; /* made a new level? */ 1139. struct monst *mtmp; 1140. char whynot[BUFSZ]; 1141. char *annotation; 1142. 1143. if (dunlev(newlevel) > dunlevs_in_dungeon(newlevel)) 1144. newlevel->dlevel = dunlevs_in_dungeon(newlevel); 1145. if (newdungeon && In_endgame(newlevel)) { /* 1st Endgame Level !!! */ 1146. if (!u.uhave.amulet) 1147. return; /* must have the Amulet */ 1148. if (!wizard) /* wizard ^V can bypass Earth level */ 1149. assign_level(newlevel, &earth_level); /* (redundant) */ 1150. } 1151. new_ledger = ledger_no(newlevel); 1152. if (new_ledger <= 0) 1153. done(ESCAPED); /* in fact < 0 is impossible */ 1154. 1155. /* If you have the amulet and are trying to get out of Gehennom, 1156. * going up a set of stairs sometimes does some very strange things! 1157. * Biased against law and towards chaos. (The chance to be sent 1158. * down multiple levels when attempting to go up are significantly 1159. * less than the corresponding comment in older versions indicated 1160. * due to overlooking the effect of the call to assign_rnd_lvl().) 1161. * 1162. * Odds for making it to the next level up, or of being sent down: 1163. * "up" L N C 1164. * +1 75.0 75.0 75.0 1165. * 0 6.25 8.33 12.5 1166. * -1 11.46 12.50 12.5 1167. * -2 5.21 4.17 0.0 1168. * -3 2.08 0.0 0.0 1169. */ 1170. if (Inhell && up && u.uhave.amulet && !newdungeon && !portal 1171. && (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) { 1172. if (!rn2(4)) { 1173. int odds = 3 + (int) u.ualign.type, /* 2..4 */ 1174. diff = odds <= 1 ? 0 : rn2(odds); /* paranoia */ 1175. 1176. if (diff != 0) { 1177. assign_rnd_level(newlevel, &u.uz, diff); 1178. /* if inside the tower, stay inside */ 1179. if (was_in_W_tower && !On_W_tower_level(newlevel)) 1180. diff = 0; 1181. } 1182. if (diff == 0) 1183. assign_level(newlevel, &u.uz); 1184. 1185. new_ledger = ledger_no(newlevel); 1186. 1187. pline("A mysterious force momentarily surrounds you..."); 1188. if (on_level(newlevel, &u.uz)) { 1189. (void) safe_teleds(FALSE); 1190. (void) next_to_u(); 1191. return; 1192. } else 1193. at_stairs = at_ladder = FALSE; 1194. } 1195. } 1196. 1197. /* Prevent the player from going past the first quest level unless 1198. * (s)he has been given the go-ahead by the leader. 1199. */ 1200. if (on_level(&u.uz, &qstart_level) && !newdungeon && !ok_to_quest()) { 1201. pline("A mysterious force prevents you from descending."); 1202. return; 1203. } 1204. 1205. if (on_level(newlevel, &u.uz)) 1206. return; /* this can happen */ 1207. 1208. /* tethered movement makes level change while trapped feasible */ 1209. if (u.utrap && u.utraptype == TT_BURIEDBALL) 1210. buried_ball_to_punishment(); /* (before we save/leave old level) */ 1211. 1212. fd = currentlevel_rewrite(); 1213. if (fd < 0) 1214. return; 1215. 1216. if (falling) /* assuming this is only trap door or hole */ 1217. impact_drop((struct obj *) 0, u.ux, u.uy, newlevel->dlevel); 1218. 1219. check_special_room(TRUE); /* probably was a trap door */ 1220. if (Punished) 1221. unplacebc(); 1222. u.utrap = 0; /* needed in level_tele */ 1223. fill_pit(u.ux, u.uy); 1224. u.ustuck = 0; /* idem */ 1225. u.uinwater = 0; 1226. u.uundetected = 0; /* not hidden, even if means are available */ 1227. keepdogs(FALSE); 1228. if (u.uswallow) /* idem */ 1229. u.uswldtim = u.uswallow = 0; 1230. recalc_mapseen(); /* recalculate map overview before we leave the level */ 1231. /* 1232. * We no longer see anything on the level. Make sure that this 1233. * follows u.uswallow set to null since uswallow overrides all 1234. * normal vision. 1235. */ 1236. vision_recalc(2); 1237. 1238. /* 1239. * Save the level we're leaving. If we're entering the endgame, 1240. * we can get rid of all existing levels because they cannot be 1241. * reached any more. We still need to use savelev()'s cleanup 1242. * for the level being left, to recover dynamic memory in use and 1243. * to avoid dangling timers and light sources. 1244. */ 1245. cant_go_back = (newdungeon && In_endgame(newlevel)); 1246. if (!cant_go_back) { 1247. update_mlstmv(); /* current monsters are becoming inactive */ 1248. bufon(fd); /* use buffered output */ 1249. } 1250. savelev(fd, ledger_no(&u.uz), 1251. cant_go_back ? FREE_SAVE : (WRITE_SAVE | FREE_SAVE)); 1252. bclose(fd); 1253. if (cant_go_back) { 1254. /* discard unreachable levels; keep #0 */ 1255. for (l_idx = maxledgerno(); l_idx > 0; --l_idx) 1256. delete_levelfile(l_idx); 1257. /* mark #overview data for all dungeon branches as uninteresting */ 1258. for (l_idx = 0; l_idx < n_dgns; ++l_idx) 1259. remdun_mapseen(l_idx); 1260. } 1261. 1262. if (Is_rogue_level(newlevel) || Is_rogue_level(&u.uz)) 1263. assign_graphics(Is_rogue_level(newlevel) ? ROGUESET : PRIMARY); 1264. #ifdef USE_TILES 1265. substitute_tiles(newlevel); 1266. #endif 1267. check_gold_symbol(); 1268. /* record this level transition as a potential seen branch unless using 1269. * some non-standard means of transportation (level teleport). 1270. */ 1271. if ((at_stairs || falling || portal) && (u.uz.dnum != newlevel->dnum)) 1272. recbranch_mapseen(&u.uz, newlevel); 1273. assign_level(&u.uz0, &u.uz); 1274. assign_level(&u.uz, newlevel); 1275. assign_level(&u.utolev, newlevel); 1276. u.utotype = 0; 1277. if (!builds_up(&u.uz)) { /* usual case */ 1278. if (dunlev(&u.uz) > dunlev_reached(&u.uz)) 1279. dunlev_reached(&u.uz) = dunlev(&u.uz); 1280. } else { 1281. if (dunlev_reached(&u.uz) == 0 1282. || dunlev(&u.uz) < dunlev_reached(&u.uz)) 1283. dunlev_reached(&u.uz) = dunlev(&u.uz); 1284. } 1285. reset_rndmonst(NON_PM); /* u.uz change affects monster generation */ 1286. 1287. /* set default level change destination areas */ 1288. /* the special level code may override these */ 1289. (void) memset((genericptr_t) &updest, 0, sizeof updest); 1290. (void) memset((genericptr_t) &dndest, 0, sizeof dndest); 1291. 1292. if (!(level_info[new_ledger].flags & LFILE_EXISTS)) { 1293. /* entering this level for first time; make it now */ 1294. if (level_info[new_ledger].flags & (FORGOTTEN | VISITED)) { 1295. impossible("goto_level: returning to discarded level?"); 1296. level_info[new_ledger].flags &= ~(FORGOTTEN | VISITED); 1297. } 1298. mklev(); 1299. new = TRUE; /* made the level */ 1300. } else { 1301. /* returning to previously visited level; reload it */ 1302. fd = open_levelfile(new_ledger, whynot); 1303. if (tricked_fileremoved(fd, whynot)) { 1304. /* we'll reach here if running in wizard mode */ 1305. error("Cannot continue this game."); 1306. } 1307. minit(); /* ZEROCOMP */ 1308. getlev(fd, hackpid, new_ledger, FALSE); 1309. (void) nhclose(fd); 1310. oinit(); /* reassign level dependent obj probabilities */ 1311. } 1312. reglyph_darkroom(); 1313. /* do this prior to level-change pline messages */ 1314. vision_reset(); /* clear old level's line-of-sight */ 1315. vision_full_recalc = 0; /* don't let that reenable vision yet */ 1316. flush_screen(-1); /* ensure all map flushes are postponed */ 1317. 1318. if (portal && !In_endgame(&u.uz)) { 1319. /* find the portal on the new level */ 1320. register struct trap *ttrap; 1321. 1322. for (ttrap = ftrap; ttrap; ttrap = ttrap->ntrap) 1323. if (ttrap->ttyp == MAGIC_PORTAL) 1324. break; 1325. 1326. if (!ttrap) 1327. panic("goto_level: no corresponding portal!"); 1328. seetrap(ttrap); 1329. u_on_newpos(ttrap->tx, ttrap->ty); 1330. } else if (at_stairs && !In_endgame(&u.uz)) { 1331. if (up) { 1332. if (at_ladder) 1333. u_on_newpos(xdnladder, ydnladder); 1334. else if (newdungeon) 1335. u_on_sstairs(1); 1336. else 1337. u_on_dnstairs(); 1338. /* you climb up the {stairs|ladder}; 1339. fly up the stairs; fly up along the ladder */ 1340. great_effort = (Punished && !Levitation); 1341. if (flags.verbose || great_effort) 1342. pline("%s %s up%s the %s.", 1343. great_effort ? "With great effort, you" : "You", 1344. Levitation ? "float" : Flying ? "fly" : "climb", 1345. (Flying && at_ladder) ? " along" : "", 1346. at_ladder ? "ladder" : "stairs"); 1347. } else { /* down */ 1348. if (at_ladder) 1349. u_on_newpos(xupladder, yupladder); 1350. else if (newdungeon) 1351. u_on_sstairs(0); 1352. else 1353. u_on_upstairs(); 1354. if (!u.dz) { 1355. ; /* stayed on same level? (no transit effects) */ 1356. } else if (Flying) { 1357. if (flags.verbose) 1358. You("fly down %s.", 1359. at_ladder ? "along the ladder" : "the stairs"); 1360. } else if (near_capacity() > UNENCUMBERED 1361. || Punished || Fumbling) { 1362. You("fall down the %s.", at_ladder ? "ladder" : "stairs"); 1363. if (Punished) { 1364. drag_down(); 1365. ballrelease(FALSE); 1366. } 1367. /* falling off steed has its own losehp() call */ 1368. if (u.usteed) 1369. dismount_steed(DISMOUNT_FELL); 1370. else 1371. losehp(Maybe_Half_Phys(rnd(3)), 1372. at_ladder ? "falling off a ladder" 1373. : "tumbling down a flight of stairs", 1374. KILLED_BY); 1375. selftouch("Falling, you"); 1376. } else { /* ordinary descent */ 1377. if (flags.verbose) 1378. You("%s.", at_ladder ? "climb down the ladder" 1379. : "descend the stairs"); 1380. } 1381. } 1382. } else { /* trap door or level_tele or In_endgame */ 1383. u_on_rndspot((up ? 1 : 0) | (was_in_W_tower ? 2 : 0)); 1384. if (falling) { 1385. if (Punished) 1386. ballfall(); 1387. selftouch("Falling, you"); 1388. } 1389. } 1390. 1391. if (Punished) 1392. placebc(); 1393. obj_delivery(FALSE); 1394. losedogs(); 1395. kill_genocided_monsters(); /* for those wiped out while in limbo */ 1396. /* 1397. * Expire all timers that have gone off while away. Must be 1398. * after migrating monsters and objects are delivered 1399. * (losedogs and obj_delivery). 1400. */ 1401. run_timers(); 1402. 1403. initrack(); 1404. 1405. if ((mtmp = m_at(u.ux, u.uy)) != 0 && mtmp != u.usteed) { 1406. /* There's a monster at your target destination; it might be one 1407. which accompanied you--see mon_arrive(dogmove.c)--or perhaps 1408. it was already here. Randomly move you to an adjacent spot 1409. or else the monster to any nearby location. Prior to 3.3.0 1410. the latter was done unconditionally. */ 1411. coord cc; 1412. 1413. if (!rn2(2) && enexto(&cc, u.ux, u.uy, youmonst.data) 1414. && distu(cc.x, cc.y) <= 2) 1415. u_on_newpos(cc.x, cc.y); /*[maybe give message here?]*/ 1416. else 1417. mnexto(mtmp); 1418. 1419. if ((mtmp = m_at(u.ux, u.uy)) != 0) { 1420. /* there was an unconditional impossible("mnearto failed") 1421. here, but it's not impossible and we're prepared to cope 1422. with the situation, so only say something when debugging */ 1423. if (wizard) 1424. pline("(monster in hero's way)"); 1425. if (!rloc(mtmp, TRUE)) 1426. /* no room to move it; send it away, to return later */ 1427. migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_RANDOM, 1428. (coord *) 0); 1429. } 1430. } 1431. 1432. /* initial movement of bubbles just before vision_recalc */ 1433. if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) 1434. movebubbles(); 1435. else if (Is_firelevel(&u.uz)) 1436. fumaroles(); 1437. 1438. if (level_info[new_ledger].flags & FORGOTTEN) { 1439. forget_map(ALL_MAP); /* forget the map */ 1440. forget_traps(); /* forget all traps too */ 1441. familiar = TRUE; 1442. level_info[new_ledger].flags &= ~FORGOTTEN; 1443. } 1444. 1445. /* Reset the screen. */ 1446. vision_reset(); /* reset the blockages */ 1447. docrt(); /* does a full vision recalc */ 1448. flush_screen(-1); 1449. 1450. /* 1451. * Move all plines beyond the screen reset. 1452. */ 1453. 1454. /* special levels can have a custom arrival message */ 1455. deliver_splev_message(); 1456. 1457. /* give room entrance message, if any */ 1458. check_special_room(FALSE); 1459. 1460. /* deliver objects traveling with player */ 1461. obj_delivery(TRUE); 1462. 1463. /* Check whether we just entered Gehennom. */ 1464. if (!In_hell(&u.uz0) && Inhell) { 1465. if (Is_valley(&u.uz)) { 1466. You("arrive at the Valley of the Dead..."); 1467. pline_The("odor of burnt flesh and decay pervades the air."); 1468. #ifdef MICRO 1469. display_nhwindow(WIN_MESSAGE, FALSE); 1470. #endif 1471. You_hear("groans and moans everywhere."); 1472. } else 1473. pline("It is hot here. You smell smoke..."); 1474. u.uachieve.enter_gehennom = 1; 1475. } 1476. /* in case we've managed to bypass the Valley's stairway down */ 1477. if (Inhell && !Is_valley(&u.uz)) 1478. u.uevent.gehennom_entered = 1; 1479. 1480. if (familiar) { 1481. static const char *const fam_msgs[4] = { 1482. "You have a sense of deja vu.", 1483. "You feel like you've been here before.", 1484. "This place %s familiar...", 0 /* no message */ 1485. }; 1486. static const char *const halu_fam_msgs[4] = { 1487. "Whoa! Everything %s different.", 1488. "You are surrounded by twisty little passages, all alike.", 1489. "Gee, this %s like uncle Conan's place...", 0 /* no message */ 1490. }; 1491. const char *mesg; 1492. char buf[BUFSZ]; 1493. int which = rn2(4); 1494. 1495. if (Hallucination) 1496. mesg = halu_fam_msgs[which]; 1497. else 1498. mesg = fam_msgs[which]; 1499. if (mesg && index(mesg, '%')) { 1500. Sprintf(buf, mesg, !Blind ? "looks" : "seems"); 1501. mesg = buf; 1502. } 1503. if (mesg) 1504. pline1(mesg); 1505. } 1506. 1507. /* special location arrival messages/events */ 1508. if (In_endgame(&u.uz)) { 1509. if (new &&on_level(&u.uz, &astral_level)) 1510. final_level(); /* guardian angel,&c */ 1511. else if (newdungeon && u.uhave.amulet) 1512. resurrect(); /* force confrontation with Wizard */ 1513. } else if (In_quest(&u.uz)) { 1514. onquest(); /* might be reaching locate|goal level */ 1515. } else if (In_V_tower(&u.uz)) { 1516. if (newdungeon && In_hell(&u.uz0)) 1517. pline_The("heat and smoke are gone."); 1518. } else if (Is_knox(&u.uz)) { 1519. /* alarm stops working once Croesus has died */ 1520. if (new || !mvitals[PM_CROESUS].died) { 1521. You("have penetrated a high security area!"); 1522. pline("An alarm sounds!"); 1523. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 1524. if (DEADMONSTER(mtmp)) 1525. continue; 1526. mtmp->msleeping = 0; 1527. } 1528. } 1529. } else { 1530. if (new && Is_rogue_level(&u.uz)) 1531. You("enter what seems to be an older, more primitive world."); 1532. /* main dungeon message from your quest leader */ 1533. if (!In_quest(&u.uz0) && at_dgn_entrance("The Quest") 1534. && !(u.uevent.qcompleted || u.uevent.qexpelled 1535. || quest_status.leader_is_dead)) { 1536. if (!u.uevent.qcalled) { 1537. u.uevent.qcalled = 1; 1538. com_pager(2); /* main "leader needs help" message */ 1539. } else { /* reminder message */ 1540. com_pager(Role_if(PM_ROGUE) ? 4 : 3); 1541. } 1542. } 1543. } 1544. 1545. assign_level(&u.uz0, &u.uz); /* reset u.uz0 */ 1546. #ifdef INSURANCE 1547. save_currentstate(); 1548. #endif 1549. 1550. if ((annotation = get_annotation(&u.uz)) != 0) 1551. You("remember this level as %s.", annotation); 1552. 1553. /* assume this will always return TRUE when changing level */ 1554. (void) in_out_region(u.ux, u.uy); 1555. (void) pickup(1); 1556. 1557. /* discard context which applied to previous level */ 1558. maybe_reset_pick(); /* for door or for box not accompanying hero */ 1559. reset_trapset(); /* even if to-be-armed trap obj is accompanying hero */ 1560. iflags.travelcc.x = iflags.travelcc.y = -1; /* travel destination cache */ 1561. context.polearm.hitmon = (struct monst *) 0; /* polearm target */ 1562. /* digging context is level-aware and can actually be resumed if 1563. hero returns to the previous level without any intervening dig */ 1564. } 1565.
final_level
1566. STATIC_OVL void 1567. final_level() 1568. { 1569. struct monst *mtmp; 1570. 1571. /* reset monster hostility relative to player */ 1572. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 1573. if (DEADMONSTER(mtmp)) 1574. continue; 1575. reset_hostility(mtmp); 1576. } 1577. 1578. /* create some player-monsters */ 1579. create_mplayers(rn1(4, 3), TRUE); 1580. 1581. /* create a guardian angel next to player, if worthy */ 1582. gain_guardian_angel(); 1583. } 1584. 1585. static char *dfr_pre_msg = 0, /* pline() before level change */ 1586. *dfr_post_msg = 0; /* pline() after level change */ 1587.
schedule_goto
1588. /* change levels at the end of this turn, after monsters finish moving */ 1589. void 1590. schedule_goto(tolev, at_stairs, falling, portal_flag, pre_msg, post_msg) 1591. d_level *tolev; 1592. boolean at_stairs, falling; 1593. int portal_flag; 1594. const char *pre_msg, *post_msg; 1595. { 1596. int typmask = 0100; /* non-zero triggers `deferred_goto' */ 1597. 1598. /* destination flags (`goto_level' args) */ 1599. if (at_stairs) 1600. typmask |= 1; 1601. if (falling) 1602. typmask |= 2; 1603. if (portal_flag) 1604. typmask |= 4; 1605. if (portal_flag < 0) 1606. typmask |= 0200; /* flag for portal removal */ 1607. u.utotype = typmask; 1608. /* destination level */ 1609. assign_level(&u.utolev, tolev); 1610. 1611. if (pre_msg) 1612. dfr_pre_msg = dupstr(pre_msg); 1613. if (post_msg) 1614. dfr_post_msg = dupstr(post_msg); 1615. } 1616.
deferred_goto
1617. /* handle something like portal ejection */ 1618. void 1619. deferred_goto() 1620. { 1621. if (!on_level(&u.uz, &u.utolev)) { 1622. d_level dest; 1623. int typmask = u.utotype; /* save it; goto_level zeroes u.utotype */ 1624. 1625. assign_level(&dest, &u.utolev); 1626. if (dfr_pre_msg) 1627. pline1(dfr_pre_msg); 1628. goto_level(&dest, !!(typmask & 1), !!(typmask & 2), !!(typmask & 4)); 1629. if (typmask & 0200) { /* remove portal */ 1630. struct trap *t = t_at(u.ux, u.uy); 1631. 1632. if (t) { 1633. deltrap(t); 1634. newsym(u.ux, u.uy); 1635. } 1636. } 1637. if (dfr_post_msg) 1638. pline1(dfr_post_msg); 1639. } 1640. u.utotype = 0; /* our caller keys off of this */ 1641. if (dfr_pre_msg) 1642. free((genericptr_t) dfr_pre_msg), dfr_pre_msg = 0; 1643. if (dfr_post_msg) 1644. free((genericptr_t) dfr_post_msg), dfr_post_msg = 0; 1645. } 1646.
revive_corpse
1647. /* 1648. * Return TRUE if we created a monster for the corpse. If successful, the 1649. * corpse is gone. 1650. */ 1651. boolean 1652. revive_corpse(corpse) 1653. struct obj *corpse; 1654. { 1655. struct monst *mtmp, *mcarry; 1656. boolean is_uwep, chewed; 1657. xchar where; 1658. char cname[BUFSZ]; 1659. struct obj *container = (struct obj *) 0; 1660. int container_where = 0; 1661. 1662. where = corpse->where; 1663. is_uwep = (corpse == uwep); 1664. chewed = (corpse->oeaten != 0); 1665. Strcpy(cname, 1666. corpse_xname(corpse, chewed ? "bite-covered" : (const char *) 0, 1667. CXN_SINGULAR)); 1668. mcarry = (where == OBJ_MINVENT) ? corpse->ocarry : 0; 1669. 1670. if (where == OBJ_CONTAINED) { 1671. struct monst *mtmp2; 1672. 1673. container = corpse->ocontainer; 1674. mtmp2 = 1675. get_container_location(container, &container_where, (int *) 0); 1676. /* container_where is the outermost container's location even if 1677. * nested */ 1678. if (container_where == OBJ_MINVENT && mtmp2) 1679. mcarry = mtmp2; 1680. } 1681. mtmp = revive(corpse, FALSE); /* corpse is gone if successful */ 1682. 1683. if (mtmp) { 1684. switch (where) { 1685. case OBJ_INVENT: 1686. if (is_uwep) 1687. pline_The("%s writhes out of your grasp!", cname); 1688. else 1689. You_feel("squirming in your backpack!"); 1690. break; 1691. 1692. case OBJ_FLOOR: 1693. if (cansee(mtmp->mx, mtmp->my)) 1694. pline("%s rises from the dead!", 1695. chewed ? Adjmonnam(mtmp, "bite-covered") 1696. : Monnam(mtmp)); 1697. break; 1698. 1699. case OBJ_MINVENT: /* probably a nymph's */ 1700. if (cansee(mtmp->mx, mtmp->my)) { 1701. if (canseemon(mcarry)) 1702. pline("Startled, %s drops %s as it revives!", 1703. mon_nam(mcarry), an(cname)); 1704. else 1705. pline("%s suddenly appears!", 1706. chewed ? Adjmonnam(mtmp, "bite-covered") 1707. : Monnam(mtmp)); 1708. } 1709. break; 1710. case OBJ_CONTAINED: { 1711. char sackname[BUFSZ]; 1712. 1713. if (container_where == OBJ_MINVENT && cansee(mtmp->mx, mtmp->my) 1714. && mcarry && canseemon(mcarry) && container) { 1715. pline("%s writhes out of %s!", Amonnam(mtmp), 1716. yname(container)); 1717. } else if (container_where == OBJ_INVENT && container) { 1718. Strcpy(sackname, an(xname(container))); 1719. pline("%s %s out of %s in your pack!", 1720. Blind ? Something : Amonnam(mtmp), 1721. locomotion(mtmp->data, "writhes"), sackname); 1722. } else if (container_where == OBJ_FLOOR && container 1723. && cansee(mtmp->mx, mtmp->my)) { 1724. Strcpy(sackname, an(xname(container))); 1725. pline("%s escapes from %s!", Amonnam(mtmp), sackname); 1726. } 1727. break; 1728. } 1729. default: 1730. /* we should be able to handle the other cases... */ 1731. impossible("revive_corpse: lost corpse @ %d", where); 1732. break; 1733. } 1734. return TRUE; 1735. } 1736. return FALSE; 1737. } 1738.
revive_mon
1739. /* Revive the corpse via a timeout. */ 1740. /*ARGSUSED*/ 1741. void 1742. revive_mon(arg, timeout) 1743. anything *arg; 1744. long timeout UNUSED; 1745. { 1746. struct obj *body = arg->a_obj; 1747. struct permonst *mptr = &mons[body->corpsenm]; 1748. struct monst *mtmp; 1749. xchar x, y; 1750. 1751. /* corpse will revive somewhere else if there is a monster in the way; 1752. Riders get a chance to try to bump the obstacle out of their way */ 1753. if ((mptr->mflags3 & M3_DISPLACES) != 0 && body->where == OBJ_FLOOR 1754. && get_obj_location(body, &x, &y, 0) && (mtmp = m_at(x, y)) != 0) { 1755. boolean notice_it = canseemon(mtmp); /* before rloc() */ 1756. char *monname = Monnam(mtmp); 1757. 1758. if (rloc(mtmp, TRUE)) { 1759. if (notice_it && !canseemon(mtmp)) 1760. pline("%s vanishes.", monname); 1761. else if (!notice_it && canseemon(mtmp)) 1762. pline("%s appears.", Monnam(mtmp)); /* not pre-rloc monname */ 1763. else if (notice_it && dist2(mtmp->mx, mtmp->my, x, y) > 2) 1764. pline("%s teleports.", monname); /* saw it and still see it */ 1765. } 1766. } 1767. 1768. /* if we succeed, the corpse is gone */ 1769. if (!revive_corpse(body)) { 1770. long when; 1771. int action; 1772. 1773. if (is_rider(mptr) && rn2(99)) { /* Rider usually tries again */ 1774. action = REVIVE_MON; 1775. for (when = 3L; when < 67L; when++) 1776. if (!rn2(3)) 1777. break; 1778. } else { /* rot this corpse away */ 1779. You_feel("%sless hassled.", is_rider(mptr) ? "much " : ""); 1780. action = ROT_CORPSE; 1781. when = 250L - (monstermoves - body->age); 1782. if (when < 1L) 1783. when = 1L; 1784. } 1785. (void) start_timer(when, TIMER_OBJECT, action, arg); 1786. } 1787. } 1788.
donull
1789. int 1790. donull() 1791. { 1792. return 1; /* Do nothing, but let other things happen */ 1793. } 1794.
wipeoff
1795. STATIC_PTR int 1796. wipeoff(VOID_ARGS) 1797. { 1798. if (u.ucreamed < 4) 1799. u.ucreamed = 0; 1800. else 1801. u.ucreamed -= 4; 1802. if (Blinded < 4) 1803. Blinded = 0; 1804. else 1805. Blinded -= 4; 1806. if (!Blinded) { 1807. pline("You've got the glop off."); 1808. u.ucreamed = 0; 1809. if (!gulp_blnd_check()) { 1810. Blinded = 1; 1811. make_blinded(0L, TRUE); 1812. } 1813. return 0; 1814. } else if (!u.ucreamed) { 1815. Your("%s feels clean now.", body_part(FACE)); 1816. return 0; 1817. } 1818. return 1; /* still busy */ 1819. } 1820.
dowipe
1821. int 1822. dowipe() 1823. { 1824. if (u.ucreamed) { 1825. static NEARDATA char buf[39]; 1826. 1827. Sprintf(buf, "wiping off your %s", body_part(FACE)); 1828. set_occupation(wipeoff, buf, 0); 1829. /* Not totally correct; what if they change back after now 1830. * but before they're finished wiping? 1831. */ 1832. return 1; 1833. } 1834. Your("%s is already clean.", body_part(FACE)); 1835. return 1; 1836. } 1837.
set_wounded_legs
1838. void 1839. set_wounded_legs(side, timex) 1840. register long side; 1841. register int timex; 1842. { 1843. /* KMH -- STEED 1844. * If you are riding, your steed gets the wounded legs instead. 1845. * You still call this function, but don't lose hp. 1846. * Caller is also responsible for adjusting messages. 1847. */ 1848. 1849. if (!Wounded_legs) { 1850. ATEMP(A_DEX)--; 1851. context.botl = 1; 1852. } 1853. 1854. if (!Wounded_legs || (HWounded_legs & TIMEOUT)) 1855. HWounded_legs = timex; 1856. EWounded_legs = side; 1857. (void) encumber_msg(); 1858. } 1859.
heal_legs
1860. void 1861. heal_legs() 1862. { 1863. if (Wounded_legs) { 1864. if (ATEMP(A_DEX) < 0) { 1865. ATEMP(A_DEX)++; 1866. context.botl = 1; 1867. } 1868. 1869. if (!u.usteed) { 1870. const char *legs = body_part(LEG); 1871. 1872. if ((EWounded_legs & BOTH_SIDES) == BOTH_SIDES) 1873. legs = makeplural(legs); 1874. /* this used to say "somewhat better" but that was 1875. misleading since legs are being fully healed */ 1876. Your("%s %s better.", legs, vtense(legs, "feel")); 1877. } 1878. 1879. HWounded_legs = EWounded_legs = 0; 1880. 1881. /* Wounded_legs reduces carrying capacity, so we want 1882. an encumbrance check when they're healed. However, 1883. while dismounting, first steed's legs get healed, 1884. then hero is dropped to floor and a new encumbrance 1885. check is made [in dismount_steed()]. So don't give 1886. encumbrance feedback during the dismount stage 1887. because it could seem to be shown out of order and 1888. it might be immediately contradicted [able to carry 1889. more when steed becomes healthy, then possible floor 1890. feedback, then able to carry less when back on foot]. */ 1891. if (!in_steed_dismounting) 1892. (void) encumber_msg(); 1893. } 1894. } 1895. 1896. /*do.c*/