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