Source:NetHack 3.6.2/src/sit.c
Jump to navigation
Jump to search
Below is the full text to sit.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/sit.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 sit.c $NHDT-Date: 1544442714 2018/12/10 11:51:54 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.59 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2012. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. #include "artifact.h" 8. 9. 10. /* take away the hero's money */ 11. void 12. take_gold() 13. { 14. struct obj *otmp, *nobj; 15. int lost_money = 0; 16. 17. for (otmp = invent; otmp; otmp = nobj) { 18. nobj = otmp->nobj; 19. if (otmp->oclass == COIN_CLASS) { 20. lost_money = 1; 21. remove_worn_item(otmp, FALSE); 22. delobj(otmp); 23. } 24. } 25. if (!lost_money) { 26. You_feel("a strange sensation."); 27. } else { 28. You("notice you have no money!"); 29. context.botl = 1; 30. } 31. } 32. 33. /* #sit command */ 34. int 35. dosit() 36. { 37. static const char sit_message[] = "sit on the %s."; 38. register struct trap *trap = t_at(u.ux, u.uy); 39. register int typ = levl[u.ux][u.uy].typ; 40. 41. if (u.usteed) { 42. You("are already sitting on %s.", mon_nam(u.usteed)); 43. return 0; 44. } 45. if (u.uundetected && is_hider(youmonst.data) && u.umonnum != PM_TRAPPER) 46. u.uundetected = 0; /* no longer on the ceiling */ 47. 48. if (!can_reach_floor(FALSE)) { 49. if (u.uswallow) 50. There("are no seats in here!"); 51. else if (Levitation) 52. You("tumble in place."); 53. else 54. You("are sitting on air."); 55. return 0; 56. } else if (u.ustuck && !sticks(youmonst.data)) { 57. /* holding monster is next to hero rather than beneath, but 58. hero is in no condition to actually sit at has/her own spot */ 59. if (humanoid(u.ustuck->data)) 60. pline("%s won't offer %s lap.", Monnam(u.ustuck), mhis(u.ustuck)); 61. else 62. pline("%s has no lap.", Monnam(u.ustuck)); 63. return 0; 64. } else if (is_pool(u.ux, u.uy) && !Underwater) { /* water walking */ 65. goto in_water; 66. } 67. 68. if (OBJ_AT(u.ux, u.uy) 69. /* ensure we're not standing on the precipice */ 70. && !uteetering_at_seen_pit(trap)) { 71. register struct obj *obj; 72. 73. obj = level.objects[u.ux][u.uy]; 74. if (youmonst.data->mlet == S_DRAGON && obj->oclass == COIN_CLASS) { 75. You("coil up around your %shoard.", 76. (obj->quan + money_cnt(invent) < u.ulevel * 1000) ? "meager " 77. : ""); 78. } else { 79. You("sit on %s.", the(xname(obj))); 80. if (!(Is_box(obj) || objects[obj->otyp].oc_material == CLOTH)) 81. pline("It's not very comfortable..."); 82. } 83. } else if (trap != 0 || (u.utrap && (u.utraptype >= TT_LAVA))) { 84. if (u.utrap) { 85. exercise(A_WIS, FALSE); /* you're getting stuck longer */ 86. if (u.utraptype == TT_BEARTRAP) { 87. You_cant("sit down with your %s in the bear trap.", 88. body_part(FOOT)); 89. u.utrap++; 90. } else if (u.utraptype == TT_PIT) { 91. if (trap && trap->ttyp == SPIKED_PIT) { 92. You("sit down on a spike. Ouch!"); 93. losehp(Half_physical_damage ? rn2(2) : 1, 94. "sitting on an iron spike", KILLED_BY); 95. exercise(A_STR, FALSE); 96. } else 97. You("sit down in the pit."); 98. u.utrap += rn2(5); 99. } else if (u.utraptype == TT_WEB) { 100. You("sit in the spider web and get entangled further!"); 101. u.utrap += rn1(10, 5); 102. } else if (u.utraptype == TT_LAVA) { 103. /* Must have fire resistance or they'd be dead already */ 104. You("sit in the %s!", hliquid("lava")); 105. if (Slimed) 106. burn_away_slime(); 107. u.utrap += rnd(4); 108. losehp(d(2, 10), "sitting in lava", 109. KILLED_BY); /* lava damage */ 110. } else if (u.utraptype == TT_INFLOOR 111. || u.utraptype == TT_BURIEDBALL) { 112. You_cant("maneuver to sit!"); 113. u.utrap++; 114. } 115. } else { 116. You("sit down."); 117. dotrap(trap, VIASITTING); 118. } 119. } else if ((Underwater || Is_waterlevel(&u.uz)) 120. && !eggs_in_water(youmonst.data)) { 121. if (Is_waterlevel(&u.uz)) 122. There("are no cushions floating nearby."); 123. else 124. You("sit down on the muddy bottom."); 125. } else if (is_pool(u.ux, u.uy) && !eggs_in_water(youmonst.data)) { 126. in_water: 127. You("sit in the %s.", hliquid("water")); 128. if (!rn2(10) && uarm) 129. (void) water_damage(uarm, "armor", TRUE); 130. if (!rn2(10) && uarmf && uarmf->otyp != WATER_WALKING_BOOTS) 131. (void) water_damage(uarm, "armor", TRUE); 132. } else if (IS_SINK(typ)) { 133. You(sit_message, defsyms[S_sink].explanation); 134. Your("%s gets wet.", humanoid(youmonst.data) ? "rump" : "underside"); 135. } else if (IS_ALTAR(typ)) { 136. You(sit_message, defsyms[S_altar].explanation); 137. altar_wrath(u.ux, u.uy); 138. } else if (IS_GRAVE(typ)) { 139. You(sit_message, defsyms[S_grave].explanation); 140. } else if (typ == STAIRS) { 141. You(sit_message, "stairs"); 142. } else if (typ == LADDER) { 143. You(sit_message, "ladder"); 144. } else if (is_lava(u.ux, u.uy)) { 145. /* must be WWalking */ 146. You(sit_message, hliquid("lava")); 147. burn_away_slime(); 148. if (likes_lava(youmonst.data)) { 149. pline_The("%s feels warm.", hliquid("lava")); 150. return 1; 151. } 152. pline_The("%s burns you!", hliquid("lava")); 153. losehp(d((Fire_resistance ? 2 : 10), 10), /* lava damage */ 154. "sitting on lava", KILLED_BY); 155. } else if (is_ice(u.ux, u.uy)) { 156. You(sit_message, defsyms[S_ice].explanation); 157. if (!Cold_resistance) 158. pline_The("ice feels cold."); 159. } else if (typ == DRAWBRIDGE_DOWN) { 160. You(sit_message, "drawbridge"); 161. } else if (IS_THRONE(typ)) { 162. You(sit_message, defsyms[S_throne].explanation); 163. if (rnd(6) > 4) { 164. switch (rnd(13)) { 165. case 1: 166. (void) adjattrib(rn2(A_MAX), -rn1(4, 3), FALSE); 167. losehp(rnd(10), "cursed throne", KILLED_BY_AN); 168. break; 169. case 2: 170. (void) adjattrib(rn2(A_MAX), 1, FALSE); 171. break; 172. case 3: 173. pline("A%s electric shock shoots through your body!", 174. (Shock_resistance) ? "n" : " massive"); 175. losehp(Shock_resistance ? rnd(6) : rnd(30), "electric chair", 176. KILLED_BY_AN); 177. exercise(A_CON, FALSE); 178. break; 179. case 4: 180. You_feel("much, much better!"); 181. if (Upolyd) { 182. if (u.mh >= (u.mhmax - 5)) 183. u.mhmax += 4; 184. u.mh = u.mhmax; 185. } 186. if (u.uhp >= (u.uhpmax - 5)) 187. u.uhpmax += 4; 188. u.uhp = u.uhpmax; 189. u.ucreamed = 0; 190. make_blinded(0L, TRUE); 191. make_sick(0L, (char *) 0, FALSE, SICK_ALL); 192. heal_legs(0); 193. context.botl = 1; 194. break; 195. case 5: 196. take_gold(); 197. break; 198. case 6: 199. if (u.uluck + rn2(5) < 0) { 200. You_feel("your luck is changing."); 201. change_luck(1); 202. } else 203. makewish(); 204. break; 205. case 7: 206. { 207. int cnt = rnd(10); 208. 209. /* Magical voice not affected by deafness */ 210. pline("A voice echoes:"); 211. verbalize("Thy audience hath been summoned, %s!", 212. flags.female ? "Dame" : "Sire"); 213. while (cnt--) 214. (void) makemon(courtmon(), u.ux, u.uy, NO_MM_FLAGS); 215. break; 216. } 217. case 8: 218. /* Magical voice not affected by deafness */ 219. pline("A voice echoes:"); 220. verbalize("By thine Imperious order, %s...", 221. flags.female ? "Dame" : "Sire"); 222. do_genocide(5); /* REALLY|ONTHRONE, see do_genocide() */ 223. break; 224. case 9: 225. /* Magical voice not affected by deafness */ 226. pline("A voice echoes:"); 227. verbalize( 228. "A curse upon thee for sitting upon this most holy throne!"); 229. if (Luck > 0) { 230. make_blinded(Blinded + rn1(100, 250), TRUE); 231. change_luck((Luck > 1) ? -rnd(2) : -1); 232. } else 233. rndcurse(); 234. break; 235. case 10: 236. if (Luck < 0 || (HSee_invisible & INTRINSIC)) { 237. if (level.flags.nommap) { 238. pline("A terrible drone fills your head!"); 239. make_confused((HConfusion & TIMEOUT) + (long) rnd(30), 240. FALSE); 241. } else { 242. pline("An image forms in your mind."); 243. do_mapping(); 244. } 245. } else { 246. Your("vision becomes clear."); 247. HSee_invisible |= FROMOUTSIDE; 248. newsym(u.ux, u.uy); 249. } 250. break; 251. case 11: 252. if (Luck < 0) { 253. You_feel("threatened."); 254. aggravate(); 255. } else { 256. You_feel("a wrenching sensation."); 257. tele(); /* teleport him */ 258. } 259. break; 260. case 12: 261. You("are granted an insight!"); 262. if (invent) { 263. /* rn2(5) agrees w/seffects() */ 264. identify_pack(rn2(5), FALSE); 265. } 266. break; 267. case 13: 268. Your("mind turns into a pretzel!"); 269. make_confused((HConfusion & TIMEOUT) + (long) rn1(7, 16), 270. FALSE); 271. break; 272. default: 273. impossible("throne effect"); 274. break; 275. } 276. } else { 277. if (is_prince(youmonst.data)) 278. You_feel("very comfortable here."); 279. else 280. You_feel("somehow out of place..."); 281. } 282. 283. if (!rn2(3) && IS_THRONE(levl[u.ux][u.uy].typ)) { 284. /* may have teleported */ 285. levl[u.ux][u.uy].typ = ROOM, levl[u.ux][u.uy].flags = 0; 286. pline_The("throne vanishes in a puff of logic."); 287. newsym(u.ux, u.uy); 288. } 289. } else if (lays_eggs(youmonst.data)) { 290. struct obj *uegg; 291. 292. if (!flags.female) { 293. pline("%s can't lay eggs!", 294. Hallucination 295. ? "You may think you are a platypus, but a male still" 296. : "Males"); 297. return 0; 298. } else if (u.uhunger < (int) objects[EGG].oc_nutrition) { 299. You("don't have enough energy to lay an egg."); 300. return 0; 301. } else if (eggs_in_water(youmonst.data)) { 302. if (!(Underwater || Is_waterlevel(&u.uz))) { 303. pline("A splash tetra you are not."); 304. return 0; 305. } 306. if (Upolyd && 307. (youmonst.data == &mons[PM_GIANT_EEL] 308. || youmonst.data == &mons[PM_ELECTRIC_EEL])) { 309. You("yearn for the Sargasso Sea."); 310. return 0; 311. } 312. } 313. uegg = mksobj(EGG, FALSE, FALSE); 314. uegg->spe = 1; 315. uegg->quan = 1L; 316. uegg->owt = weight(uegg); 317. /* this sets hatch timers if appropriate */ 318. set_corpsenm(uegg, egg_type_from_parent(u.umonnum, FALSE)); 319. uegg->known = uegg->dknown = 1; 320. You("%s an egg.", eggs_in_water(youmonst.data) ? "spawn" : "lay"); 321. dropy(uegg); 322. stackobj(uegg); 323. morehungry((int) objects[EGG].oc_nutrition); 324. } else { 325. pline("Having fun sitting on the %s?", surface(u.ux, u.uy)); 326. } 327. return 1; 328. } 329. 330. /* curse a few inventory items at random! */ 331. void 332. rndcurse() 333. { 334. int nobj = 0; 335. int cnt, onum; 336. struct obj *otmp; 337. static const char mal_aura[] = "feel a malignant aura surround %s."; 338. 339. if (uwep && (uwep->oartifact == ART_MAGICBANE) && rn2(20)) { 340. You(mal_aura, "the magic-absorbing blade"); 341. return; 342. } 343. 344. if (Antimagic) { 345. shieldeff(u.ux, u.uy); 346. You(mal_aura, "you"); 347. } 348. 349. for (otmp = invent; otmp; otmp = otmp->nobj) { 350. /* gold isn't subject to being cursed or blessed */ 351. if (otmp->oclass == COIN_CLASS) 352. continue; 353. nobj++; 354. } 355. if (nobj) { 356. for (cnt = rnd(6 / ((!!Antimagic) + (!!Half_spell_damage) + 1)); 357. cnt > 0; cnt--) { 358. onum = rnd(nobj); 359. for (otmp = invent; otmp; otmp = otmp->nobj) { 360. /* as above */ 361. if (otmp->oclass == COIN_CLASS) 362. continue; 363. if (--onum == 0) 364. break; /* found the target */ 365. } 366. /* the !otmp case should never happen; picking an already 367. cursed item happens--avoid "resists" message in that case */ 368. if (!otmp || otmp->cursed) 369. continue; /* next target */ 370. 371. if (otmp->oartifact && spec_ability(otmp, SPFX_INTEL) 372. && rn2(10) < 8) { 373. pline("%s!", Tobjnam(otmp, "resist")); 374. continue; 375. } 376. 377. if (otmp->blessed) 378. unbless(otmp); 379. else 380. curse(otmp); 381. } 382. update_inventory(); 383. } 384. 385. /* treat steed's saddle as extended part of hero's inventory */ 386. if (u.usteed && !rn2(4) && (otmp = which_armor(u.usteed, W_SADDLE)) != 0 387. && !otmp->cursed) { /* skip if already cursed */ 388. if (otmp->blessed) 389. unbless(otmp); 390. else 391. curse(otmp); 392. if (!Blind) { 393. pline("%s %s.", Yobjnam2(otmp, "glow"), 394. hcolor(otmp->cursed ? NH_BLACK : (const char *) "brown")); 395. otmp->bknown = TRUE; 396. } 397. } 398. } 399. 400. /* remove a random INTRINSIC ability */ 401. void 402. attrcurse() 403. { 404. switch (rnd(11)) { 405. case 1: 406. if (HFire_resistance & INTRINSIC) { 407. HFire_resistance &= ~INTRINSIC; 408. You_feel("warmer."); 409. break; 410. } 411. /*FALLTHRU*/ 412. case 2: 413. if (HTeleportation & INTRINSIC) { 414. HTeleportation &= ~INTRINSIC; 415. You_feel("less jumpy."); 416. break; 417. } 418. /*FALLTHRU*/ 419. case 3: 420. if (HPoison_resistance & INTRINSIC) { 421. HPoison_resistance &= ~INTRINSIC; 422. You_feel("a little sick!"); 423. break; 424. } 425. /*FALLTHRU*/ 426. case 4: 427. if (HTelepat & INTRINSIC) { 428. HTelepat &= ~INTRINSIC; 429. if (Blind && !Blind_telepat) 430. see_monsters(); /* Can't sense mons anymore! */ 431. Your("senses fail!"); 432. break; 433. } 434. /*FALLTHRU*/ 435. case 5: 436. if (HCold_resistance & INTRINSIC) { 437. HCold_resistance &= ~INTRINSIC; 438. You_feel("cooler."); 439. break; 440. } 441. /*FALLTHRU*/ 442. case 6: 443. if (HInvis & INTRINSIC) { 444. HInvis &= ~INTRINSIC; 445. You_feel("paranoid."); 446. break; 447. } 448. /*FALLTHRU*/ 449. case 7: 450. if (HSee_invisible & INTRINSIC) { 451. HSee_invisible &= ~INTRINSIC; 452. You("%s!", Hallucination ? "tawt you taw a puttie tat" 453. : "thought you saw something"); 454. break; 455. } 456. /*FALLTHRU*/ 457. case 8: 458. if (HFast & INTRINSIC) { 459. HFast &= ~INTRINSIC; 460. You_feel("slower."); 461. break; 462. } 463. /*FALLTHRU*/ 464. case 9: 465. if (HStealth & INTRINSIC) { 466. HStealth &= ~INTRINSIC; 467. You_feel("clumsy."); 468. break; 469. } 470. /*FALLTHRU*/ 471. case 10: 472. /* intrinsic protection is just disabled, not set back to 0 */ 473. if (HProtection & INTRINSIC) { 474. HProtection &= ~INTRINSIC; 475. You_feel("vulnerable."); 476. break; 477. } 478. /*FALLTHRU*/ 479. case 11: 480. if (HAggravate_monster & INTRINSIC) { 481. HAggravate_monster &= ~INTRINSIC; 482. You_feel("less attractive."); 483. break; 484. } 485. /*FALLTHRU*/ 486. default: 487. break; 488. } 489. } 490. 491. /*sit.c*/