Source:NetHack 3.4.3/src/sit.c

From NetHackWiki
(Redirected from Source:NetHack 3.4.3/sit.c)
Jump to: navigation, search

Below is the full text to src/sit.c from NetHack 3.4.3. To link to a particular line, write [[sit.c#line123]], for example.

Top of file

  1. /*	SCCS Id: @(#)sit.c	3.4	2002/09/21	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* 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.

  1. #include "hack.h"
  2. #include "artifact.h"

take_gold

  1. void
  2. take_gold()
  3. {
  4. #ifndef GOLDOBJ
  5. 	if (u.ugold <= 0)  {
  6. 		You_feel("a strange sensation.");
  7. 	} else {
  8. 		You("notice you have no gold!");
  9. 		u.ugold = 0;
  10. 		flags.botl = 1;
  11. 	}
  12. #else
  13. struct obj *otmp, *nobj;
  14. 	int lost_money = 0;
  15. 	for (otmp = invent; otmp; otmp = nobj) {
  16. 		nobj = otmp->nobj;
  17. 		if (otmp->oclass == COIN_CLASS) {
  18. 			lost_money = 1;
  19. 			delobj(otmp);
  20. 		}
  21. 	}
  22. 	if (!lost_money)  {
  23. 		You_feel("a strange sensation.");
  24. 	} else {
  25. 		You("notice you have no money!");
  26. 		flags.botl = 1;
  27. 	}
  28. #endif
  29. }

dosit

  1. int
  2. dosit()
  3. {
  4. 	static const char sit_message[] = "sit on the %s.";
  5. 	register struct trap *trap;
  6. 	register int typ = levl[u.ux][u.uy].typ;
  7.  
  8.  
  9. #ifdef STEED
  10. 	if (u.usteed) {
  11. 	    You("are already sitting on %s.", mon_nam(u.usteed));
  12. 	    return (0);
  13. 	}
  14. #endif
  15.  
  16. 	if(!can_reach_floor())	{
  17. 	    if (Levitation)
  18. 		You("tumble in place.");
  19. 	    else
  20. 		You("are sitting on air.");
  21. 	    return 0;
  22. 	} else if (is_pool(u.ux, u.uy) && !Underwater) {  /* water walking */
  23. 	    goto in_water;
  24. 	}
  25.  
  26. 	if(OBJ_AT(u.ux, u.uy)) {
  27. 	    register struct obj *obj;
  28.  
  29. 	    obj = level.objects[u.ux][u.uy];
  30. 	    You("sit on %s.", the(xname(obj)));
  31. 	    if (!(Is_box(obj) || objects[obj->otyp].oc_material == CLOTH))
  32. 		pline("It's not very comfortable...");
  33.  
  34. 	} else if ((trap = t_at(u.ux, u.uy)) != 0 ||
  35. 		   (u.utrap && (u.utraptype >= TT_LAVA))) {
  36.  
  37. 	    if (u.utrap) {
  38. 		exercise(A_WIS, FALSE);	/* you're getting stuck longer */
  39. 		if(u.utraptype == TT_BEARTRAP) {
  40. 		    You_cant("sit down with your %s in the bear trap.", body_part(FOOT));
  41. 		    u.utrap++;
  42. 	        } else if(u.utraptype == TT_PIT) {
  43. 		    if(trap->ttyp == SPIKED_PIT) {
  44. 			You("sit down on a spike.  Ouch!");
  45. 			losehp(1, "sitting on an iron spike", KILLED_BY);
  46. 			exercise(A_STR, FALSE);
  47. 		    } else
  48. 			You("sit down in the pit.");
  49. 		    u.utrap += rn2(5);
  50. 		} else if(u.utraptype == TT_WEB) {
  51. 		    You("sit in the spider web and get entangled further!");
  52. 		    u.utrap += rn1(10, 5);
  53. 		} else if(u.utraptype == TT_LAVA) {
  54. 		    /* Must have fire resistance or they'd be dead already */
  55. 		    You("sit in the lava!");
  56. 		    u.utrap += rnd(4);
  57. 		    losehp(d(2,10), "sitting in lava", KILLED_BY);
  58. 		} else if(u.utraptype == TT_INFLOOR) {
  59. 		    You_cant("maneuver to sit!");
  60. 		    u.utrap++;
  61. 		}
  62. 	    } else {
  63. 	        You("sit down.");
  64. 		dotrap(trap, 0);
  65. 	    }
  66. 	} else if(Underwater || Is_waterlevel(&u.uz)) {
  67. 	    if (Is_waterlevel(&u.uz))
  68. 		There("are no cushions floating nearby.");
  69. 	    else
  70. 		You("sit down on the muddy bottom.");
  71. 	} else if(is_pool(u.ux, u.uy)) {
  72. in_water:
  73. 	    You("sit in the water.");
  74. 	    if (!rn2(10) && uarm)
  75. 		(void) rust_dmg(uarm, "armor", 1, TRUE, &youmonst);
  76. 	    if (!rn2(10) && uarmf && uarmf->otyp != WATER_WALKING_BOOTS)
  77. 		(void) rust_dmg(uarm, "armor", 1, TRUE, &youmonst);
  78. #ifdef SINKS
  79. 	} else if(IS_SINK(typ)) {
  80.  
  81. 	    You(sit_message, defsyms[S_sink].explanation);
  82. 	    Your("%s gets wet.", humanoid(youmonst.data) ? "rump" : "underside");
  83. #endif
  84. 	} else if(IS_ALTAR(typ)) {
  85.  
  86. 	    You(sit_message, defsyms[S_altar].explanation);
  87. 	    altar_wrath(u.ux, u.uy);
  88.  
  89. 	} else if(IS_GRAVE(typ)) {
  90.  
  91. 	    You(sit_message, defsyms[S_grave].explanation);
  92.  
  93. 	} else if(typ == STAIRS) {
  94.  
  95. 	    You(sit_message, "stairs");
  96.  
  97. 	} else if(typ == LADDER) {
  98.  
  99. 	    You(sit_message, "ladder");
  100.  
  101. 	} else if (is_lava(u.ux, u.uy)) {
  102.  
  103. 	    /* must be WWalking */
  104. 	    You(sit_message, "lava");
  105. 	    burn_away_slime();
  106. 	    if (likes_lava(youmonst.data)) {
  107. 		pline_The("lava feels warm.");
  108. 		return 1;
  109. 	    }
  110. 	    pline_The("lava burns you!");
  111. 	    losehp(d((Fire_resistance ? 2 : 10), 10),
  112. 		   "sitting on lava", KILLED_BY);
  113.  
  114. 	} else if (is_ice(u.ux, u.uy)) {
  115.  
  116. 	    You(sit_message, defsyms[S_ice].explanation);
  117. 	    if (!Cold_resistance) pline_The("ice feels cold.");
  118.  
  119. 	} else if (typ == DRAWBRIDGE_DOWN) {
  120.  
  121. 	    You(sit_message, "drawbridge");
  122.  
  123. 	} else if(IS_THRONE(typ)) {
  124.  
  125. 	    You(sit_message, defsyms[S_throne].explanation);
  126. 	    if (rnd(6) > 4)  {
  127. 		switch (rnd(13))  {
  128. 		    case 1:
  129. 			(void) adjattrib(rn2(A_MAX), -rn1(4,3), FALSE);
  130. 			losehp(rnd(10), "cursed throne", KILLED_BY_AN);
  131. 			break;
  132. 		    case 2:
  133. 			(void) adjattrib(rn2(A_MAX), 1, FALSE);
  134. 			break;
  135. 		    case 3:
  136. 			pline("A%s electric shock shoots through your body!",
  137. 			      (Shock_resistance) ? "n" : " massive");
  138. 			losehp(Shock_resistance ? rnd(6) : rnd(30),
  139. 			       "electric chair", KILLED_BY_AN);
  140. 			exercise(A_CON, FALSE);
  141. 			break;
  142. 		    case 4:
  143. 			You_feel("much, much better!");
  144. 			if (Upolyd) {
  145. 			    if (u.mh >= (u.mhmax - 5))  u.mhmax += 4;
  146. 			    u.mh = u.mhmax;
  147. 			}
  148. 			if(u.uhp >= (u.uhpmax - 5))  u.uhpmax += 4;
  149. 			u.uhp = u.uhpmax;
  150. 			make_blinded(0L,TRUE);
  151. 			make_sick(0L, (char *) 0, FALSE, SICK_ALL);
  152. 			heal_legs();
  153. 			flags.botl = 1;
  154. 			break;
  155. 		    case 5:
  156. 			take_gold();
  157. 			break;
  158. 		    case 6:
  159. 			if(u.uluck + rn2(5) < 0) {
  160. 			    You_feel("your luck is changing.");
  161. 			    change_luck(1);
  162. 			} else	    makewish();
  163. 			break;
  164. 		    case 7:
  165. 			{
  166. 			register int cnt = rnd(10);
  167.  
  168. 			pline("A voice echoes:");
  169. 			verbalize("Thy audience hath been summoned, %s!",
  170. 				  flags.female ? "Dame" : "Sire");
  171. 			while(cnt--)
  172. 			    (void) makemon(courtmon(), u.ux, u.uy, NO_MM_FLAGS);
  173. 			break;
  174. 			}
  175. 		    case 8:
  176. 			pline("A voice echoes:");
  177. 			verbalize("By thy Imperious order, %s...",
  178. 				  flags.female ? "Dame" : "Sire");
  179. 			do_genocide(5);	/* REALLY|ONTHRONE, see do_genocide() */
  180. 			break;
  181. 		    case 9:
  182. 			pline("A voice echoes:");
  183. 	verbalize("A curse upon thee for sitting upon this most holy throne!");
  184. 			if (Luck > 0)  {
  185. 			    make_blinded(Blinded + rn1(100,250),TRUE);
  186. 			} else	    rndcurse();
  187. 			break;
  188. 		    case 10:
  189. 			if (Luck < 0 || (HSee_invisible & INTRINSIC))  {
  190. 				if (level.flags.nommap) {
  191. 					pline(
  192. 					"A terrible drone fills your head!");
  193. 					make_confused(HConfusion + rnd(30),
  194. 									FALSE);
  195. 				} else {
  196. 					pline("An image forms in your mind.");
  197. 					do_mapping();
  198. 				}
  199. 			} else  {
  200. 				Your("vision becomes clear.");
  201. 				HSee_invisible |= FROMOUTSIDE;
  202. 				newsym(u.ux, u.uy);
  203. 			}
  204. 			break;
  205. 		    case 11:
  206. 			if (Luck < 0)  {
  207. 			    You_feel("threatened.");
  208. 			    aggravate();
  209. 			} else  {
  210.  
  211. 			    You_feel("a wrenching sensation.");
  212. 			    tele();		/* teleport him */
  213. 			}
  214. 			break;
  215. 		    case 12:
  216. 			You("are granted an insight!");
  217. 			if (invent) {
  218. 			    /* rn2(5) agrees w/seffects() */
  219. 			    identify_pack(rn2(5));
  220. 			}
  221. 			break;
  222. 		    case 13:
  223. 			Your("mind turns into a pretzel!");
  224. 			make_confused(HConfusion + rn1(7,16),FALSE);
  225. 			break;
  226. 		    default:	impossible("throne effect");
  227. 				break;
  228. 		}
  229. 	    } else {
  230. 		if (is_prince(youmonst.data))
  231. 		    You_feel("very comfortable here.");
  232. 		else
  233. 		    You_feel("somehow out of place...");
  234. 	    }
  235.  
  236. 	    if (!rn2(3) && IS_THRONE(levl[u.ux][u.uy].typ)) {
  237. 		/* may have teleported */
  238. 		levl[u.ux][u.uy].typ = ROOM;
  239. 		pline_The("throne vanishes in a puff of logic.");
  240. 		newsym(u.ux,u.uy);
  241. 	    }
  242.  
  243. 	} else if (lays_eggs(youmonst.data)) {
  244. 		struct obj *uegg;
  245.  
  246. 		if (!flags.female) {
  247. 			pline("Males can't lay eggs!");
  248. 			return 0;
  249. 		}
  250.  
  251. 		if (u.uhunger < (int)objects[EGG].oc_nutrition) {
  252. 			You("don't have enough energy to lay an egg.");
  253. 			return 0;
  254. 		}
  255.  
  256. 		uegg = mksobj(EGG, FALSE, FALSE);
  257. 		uegg->spe = 1;
  258. 		uegg->quan = 1;
  259. 		uegg->owt = weight(uegg);
  260. 		uegg->corpsenm = egg_type_from_parent(u.umonnum, FALSE);
  261. 		uegg->known = uegg->dknown = 1;
  262. 		attach_egg_hatch_timeout(uegg);
  263. 		You("lay an egg.");
  264. 		dropy(uegg);
  265. 		stackobj(uegg);
  266. 		morehungry((int)objects[EGG].oc_nutrition);
  267. 	} else if (u.uswallow)
  268. 		There("are no seats in here!");
  269. 	else
  270. 		pline("Having fun sitting on the %s?", surface(u.ux,u.uy));
  271. 	return(1);
  272. }

rndcurse

  1. void
  2. rndcurse()			/* curse a few inventory items at random! */
  3. {
  4. 	int	nobj = 0;
  5. 	int	cnt, onum;
  6. 	struct	obj	*otmp;
  7. 	static const char mal_aura[] = "feel a malignant aura surround %s.";
  8.  
  9. 	if (uwep && (uwep->oartifact == ART_MAGICBANE) && rn2(20)) {
  10. 	    You(mal_aura, "the magic-absorbing blade");
  11. 	    return;
  12. 	}
  13.  
  14. 	if(Antimagic) {
  15. 	    shieldeff(u.ux, u.uy);
  16. 	    You(mal_aura, "you");
  17. 	}
  18.  
  19. 	for (otmp = invent; otmp; otmp = otmp->nobj) {
  20. #ifdef GOLDOBJ
  21. 	    /* gold isn't subject to being cursed or blessed */
  22. 	    if (otmp->oclass == COIN_CLASS) continue;
  23. #endif
  24. 	    nobj++;
  25. 	}
  26. 	if (nobj) {
  27. 	    for (cnt = rnd(6/((!!Antimagic) + (!!Half_spell_damage) + 1));
  28. 		 cnt > 0; cnt--)  {
  29. 		onum = rnd(nobj);
  30. 		for (otmp = invent; otmp; otmp = otmp->nobj) {
  31. #ifdef GOLDOBJ
  32. 		    /* as above */
  33. 		    if (otmp->oclass == COIN_CLASS) continue;
  34. #endif
  35. 		    if (--onum == 0) break;	/* found the target */
  36. 		}
  37. 		/* the !otmp case should never happen; picking an already
  38. 		   cursed item happens--avoid "resists" message in that case */
  39. 		if (!otmp || otmp->cursed) continue;	/* next target */
  40.  
  41. 		if(otmp->oartifact && spec_ability(otmp, SPFX_INTEL) &&
  42. 		   rn2(10) < 8) {
  43. 		    pline("%s!", Tobjnam(otmp, "resist"));
  44. 		    continue;
  45. 		}
  46.  
  47. 		if(otmp->blessed)
  48. 			unbless(otmp);
  49. 		else
  50. 			curse(otmp);
  51. 	    }
  52. 	    update_inventory();
  53. 	}
  54.  
  55. #ifdef STEED
  56. 	/* treat steed's saddle as extended part of hero's inventory */
  57. 	if (u.usteed && !rn2(4) &&
  58. 		(otmp = which_armor(u.usteed, W_SADDLE)) != 0 &&
  59. 		!otmp->cursed) {	/* skip if already cursed */
  60. 	    if (otmp->blessed)
  61. 		unbless(otmp);
  62. 	    else
  63. 		curse(otmp);
  64. 	    if (!Blind) {
  65. 		pline("%s %s %s.",
  66. 		      s_suffix(upstart(y_monnam(u.usteed))),
  67. 		      aobjnam(otmp, "glow"),
  68. 		      hcolor(otmp->cursed ? NH_BLACK : (const char *)"brown"));
  69. 		otmp->bknown = TRUE;
  70. 	    }
  71. 	}
  72. #endif	/*STEED*/
  73. }

attrcurse

  1. void
  2. attrcurse()			/* remove a random INTRINSIC ability */
  3. {
  4. 	switch(rnd(11)) {
  5. 	case 1 : if (HFire_resistance & INTRINSIC) {
  6. 			HFire_resistance &= ~INTRINSIC;
  7. 			You_feel("warmer.");
  8. 			break;
  9. 		}
  10. 	case 2 : if (HTeleportation & INTRINSIC) {
  11. 			HTeleportation &= ~INTRINSIC;
  12. 			You_feel("less jumpy.");
  13. 			break;
  14. 		}
  15. 	case 3 : if (HPoison_resistance & INTRINSIC) {
  16. 			HPoison_resistance &= ~INTRINSIC;
  17. 			You_feel("a little sick!");
  18. 			break;
  19. 		}
  20. 	case 4 : if (HTelepat & INTRINSIC) {
  21. 			HTelepat &= ~INTRINSIC;
  22. 			if (Blind && !Blind_telepat)
  23. 			    see_monsters();	/* Can't sense mons anymore! */
  24. 			Your("senses fail!");
  25. 			break;
  26. 		}
  27. 	case 5 : if (HCold_resistance & INTRINSIC) {
  28. 			HCold_resistance &= ~INTRINSIC;
  29. 			You_feel("cooler.");
  30. 			break;
  31. 		}
  32. 	case 6 : if (HInvis & INTRINSIC) {
  33. 			HInvis &= ~INTRINSIC;
  34. 			You_feel("paranoid.");
  35. 			break;
  36. 		}
  37. 	case 7 : if (HSee_invisible & INTRINSIC) {
  38. 			HSee_invisible &= ~INTRINSIC;
  39. 			You("%s!", Hallucination ? "tawt you taw a puttie tat"
  40. 						: "thought you saw something");
  41. 			break;
  42. 		}
  43. 	case 8 : if (HFast & INTRINSIC) {
  44. 			HFast &= ~INTRINSIC;
  45. 			You_feel("slower.");
  46. 			break;
  47. 		}
  48. 	case 9 : if (HStealth & INTRINSIC) {
  49. 			HStealth &= ~INTRINSIC;
  50. 			You_feel("clumsy.");
  51. 			break;
  52. 		}
  53. 	case 10: if (HProtection & INTRINSIC) {
  54. 			HProtection &= ~INTRINSIC;
  55. 			You_feel("vulnerable.");
  56. 			break;
  57. 		}
  58. 	case 11: if (HAggravate_monster & INTRINSIC) {
  59. 			HAggravate_monster &= ~INTRINSIC;
  60. 			You_feel("less attractive.");
  61. 			break;
  62. 		}
  63. 	default: break;
  64. 	}
  65. }
  66.  
  67. /*sit.c*/