Source:NetHack 3.2.0/sit.c

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

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)sit.c	3.2	95/01/31	*/ 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    #include "hack.h"  6.    #include "artifact.h"  7. 8.   void 9.   take_gold 10.  {  11.   	if (u.ugold <= 0)  { 12.  		You_feel("a strange sensation."); 13.  	} else { 14.  		You("notice you have no gold!"); 15.  		u.ugold = 0; 16.  		flags.botl = 1; 17.  	}  18.   }  19.    20.   int 21.  dosit 22.  {  23.   	static const char *sit_message = "sit on the %s."; 24.  	register struct trap *trap; 25.  	register int typ = levl[u.ux][u.uy].typ; 26.   27.   	if(!can_reach_floor)	{ 28.  	    You("are sitting on air."); 29.  	    return 0; 30.  	}  31.    32.   	if(OBJ_AT(u.ux, u.uy)) { 33.  	    register struct obj *obj; 34.   35.   	    obj = level.objects[u.ux][u.uy]; 36.  	    You("sit on %s.", the(xname(obj))); 37.  	    if(!Is_box(obj)) pline("It's not very comfortable..."); 38.   39.   	} else if ((trap = t_at(u.ux, u.uy)) != 0) { 40.   41.   	    if (u.utrap) { 42.  		exercise(A_WIS, FALSE);	/* you're getting stuck longer */ 43.  		if(u.utraptype == TT_BEARTRAP) { 44.  		    You_cant("sit down with your %s in the bear trap.", body_part(FOOT)); 45.  		    u.utrap++; 46.  	        } else if(u.utraptype == TT_PIT) { 47.  		    if(trap->ttyp == SPIKED_PIT) { 48.  			You("sit down on a spike.  Ouch!"); 49.  			losehp(1, "sitting on an iron spike", KILLED_BY); 50.  			exercise(A_STR, FALSE); 51.  		    } else 52.  			You("sit down in the pit."); 53.  		    u.utrap += rn2(5); 54.  		} else if(u.utraptype == TT_WEB) { 55.  		    You("sit in the spider web and get entangled further!"); 56.  		    u.utrap += rn1(10, 5); 57.  		} else if(u.utraptype == TT_LAVA) { 58.  		    /* Must have fire resistance or they'd be dead already */ 59.  		    You("sit in the lava!"); 60.  		    u.utrap += rnd(4); 61.  		    losehp(d(2,10), "sitting in lava", KILLED_BY); 62.  		} else if(u.utraptype == TT_INFLOOR) { 63.  		    You_cant("maneuver to sit!"); 64.  		    u.utrap++; 65.  		}  66.   	    } else { 67.  	        You("sit down."); 68.  		dotrap(trap); 69.  	    }  70.   	} else if(Underwater || Is_waterlevel(&u.uz)) { 71.  	    if (Is_waterlevel(&u.uz)) 72.  		pline("There are no cushions floating nearby."); 73.  	    else 74.  		You("sit down on the muddy bottom."); 75.  	} else if(is_pool(u.ux, u.uy)) { 76.   77.   	    You("sit in the water."); 78.  	    if (!rn2(10) && uarm) 79.  		(void) rust_dmg(uarm, "armor", 1, TRUE); 80.  	    if (!rn2(10) && uarmf && uarmf->otyp != WATER_WALKING_BOOTS) 81.  		(void) rust_dmg(uarm, "armor", 1, TRUE); 82.  #ifdef SINKS 83.  	} else if(IS_SINK(typ)) { 84.   85.   	    You(sit_message, defsyms[S_sink].explanation); 86.  	    Your("%s gets wet.", humanoid(uasmon) ? "rump" : "underside"); 87.  #endif 88.  	} else if(IS_ALTAR(typ)) { 89.   90.   	    You(sit_message, defsyms[S_altar].explanation); 91.  	    altar_wrath(u.ux, u.uy); 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. 	    if (likes_lava(uasmon)) { 106. 		pline_The("lava feels warm."); 107. 		return 1; 108. 	    }  109.  	    pline_The("lava burns you!"); 110. 	    losehp(d((Fire_resistance ? 2 : 10), 10),  111.  		   "sitting on lava", KILLED_BY); 112.  113.  	} else if (is_ice(u.ux, u.uy)) { 114.  115.  	    You(sit_message, defsyms[S_ice].explanation); 116. 	    if (!Cold_resistance) pline_The("ice feels cold."); 117.  118.  	} else if (typ == DRAWBRIDGE_DOWN) { 119.  120.  	    You(sit_message, "drawbridge"); 121.  122.  	} else if(IS_THRONE(typ)) { 123.  124.  	    You(sit_message, defsyms[S_throne].explanation); 125. 	    if (rnd(6) > 4)  { 126. 		switch (rnd(13))  { 127. 		    case 1: 128. 			(void) adjattrib(rn2(A_MAX), -rn1(4,3), FALSE); 129. 			losehp(rnd(10), "cursed throne", KILLED_BY_AN); 130. 			break; 131. 		    case 2: 132. 			(void) adjattrib(rn2(A_MAX), 1, FALSE); 133. 			break; 134. 		    case 3: 135. 			pline("A%s electric shock shoots through your body!",  136.  			      (Shock_resistance) ? "n" : " massive"); 137. 			losehp(Shock_resistance ? rnd(6) : rnd(30),  138.  			       "electric chair", KILLED_BY_AN); 139. 			exercise(A_CON, FALSE); 140. 			break; 141. 		    case 4: 142. 			You_feel("much, much better!"); 143. 			if(u.uhp >= (u.uhpmax - 5))  u.uhpmax += 4; 144. 			u.uhp = u.uhpmax; 145. 			make_blinded(0L,TRUE); 146. 			make_sick(0L, (char *) 0, FALSE, SICK_ALL); 147. 			heal_legs; 148. 			flags.botl = 1; 149. 			break; 150. 		    case 5: 151. 			take_gold; 152. 			break; 153. 		    case 6: 154. 			if(u.uluck + rn2(5) < 0) { 155. 			    You_feel("your luck is changing."); 156. 			    change_luck(1); 157. 			} else	    makewish; 158. 			break; 159. 		    case 7: 160. 			{  161.  			register int cnt = rnd(10); 162.  163.  			pline("A voice echoes:"); 164. 			verbalize("Thy audience hath been summoned, %s!",  165.  				  flags.female ? "Dame" : "Sire"); 166. 			while(cnt--) 167. 			    (void) makemon(courtmon, u.ux, u.uy); 168. 			break; 169. 			}  170.  		    case 8: 171. 			pline("A voice echoes:"); 172. 			verbalize("By thy Imperious order, %s...",  173.  				  flags.female ? "Dame" : "Sire"); 174. 			do_genocide(1); 175. 			break; 176. 		    case 9: 177. 			pline("A voice echoes:"); 178. 	verbalize("A curse upon thee for sitting upon this most holy throne!"); 179. 			if (Luck > 0)  { 180. 			    make_blinded(Blinded + rn1(100,250),TRUE); 181. 			} else	    rndcurse; 182. 			break; 183. 		    case 10: 184. 			if (Luck < 0 || (HSee_invisible & INTRINSIC))  { 185. 				if (level.flags.nommap) { 186. 					pline(  187.  					"A terrible drone fills your head!"); 188. 					make_confused(HConfusion + rnd(30),  189.  									FALSE); 190. 				} else { 191. 					pline("An image forms in your mind."); 192. 					do_mapping; 193. 				}  194.  			} else  { 195. 				Your("vision becomes clear."); 196. 				HSee_invisible |= FROMOUTSIDE; 197. 				newsym(u.ux, u.uy); 198. 			}  199.  			break; 200. 		    case 11: 201. 			if (Luck < 0)  { 202. 			    You_feel("threatened."); 203. 			    aggravate; 204. 			} else  { 205.  206.  			    You_feel("a wrenching sensation."); 207. 			    tele;		/* teleport him */ 208. 			}  209.  			break; 210. 		    case 12: 211. 			You("are granted an insight!"); 212. 			if (invent) { 213. 			    /* rn2(5) agrees w/seffects */ 214. 			    identify_pack(rn2(5)); 215. 			}  216.  			break; 217. 		    case 13: 218. 			Your("mind turns into a pretzel!"); 219. 			make_confused(HConfusion + rn1(7,16),FALSE); 220. 			break; 221. 		    default:	impossible("throne effect"); 222. 				break; 223. 		}  224.  	    } else	You_feel("somehow out of place..."); 225.  226.  	    if (!rn2(3) && IS_THRONE(levl[u.ux][u.uy].typ)) { 227. 		/* may have teleported */ 228. 		pline_The("throne vanishes in a puff of logic."); 229. 		levl[u.ux][u.uy].typ = ROOM; 230. 		if(Invisible) newsym(u.ux,u.uy); 231. 	    }  232.   233.  	} else if (lays_eggs(uasmon)) { 234. 		struct obj *uegg; 235.  236.  		if (!flags.female) { 237. 			pline("Males can't lay eggs!"); 238. 			return 0; 239. 		}  240.   241.  		if (u.uhunger < (int)objects[EGG].oc_nutrition) { 242. 			You("don't have enough energy to lay an egg."); 243. 			return 0; 244. 		}  245.   246.  		uegg = mksobj(EGG, FALSE, FALSE); 247. 		uegg->spe = 1; 248. 		uegg->quan = 1; 249. 		uegg->owt = weight(uegg); 250. 		uegg->corpsenm = egg_type_from_parent(u.umonnum, FALSE); 251. 		uegg->known = uegg->dknown = 1; 252. 		attach_egg_hatch_timeout(uegg); 253. 		You("lay an egg."); 254. 		dropy(uegg); 255. 		stackobj(uegg); 256. 		morehungry((int)objects[EGG].oc_nutrition); 257. 	} else if (u.uswallow) 258. 		pline("There are no seats in here!"); 259. 	else 260. 		pline("Having fun sitting on the %s?", surface(u.ux,u.uy)); 261. 	return(1); 262. }  263.   264.  void 265. rndcurse			/* curse a few inventory items at random! */ 266.  {  267.  	int	nobj = 0; 268. 	int	cnt, onum; 269. 	struct	obj	*otmp; 270. 	static const char *mal_aura = "feel a malignant aura surround %s."; 271.  272.  	if (uwep && (uwep->oartifact == ART_MAGICBANE) && rn2(20)) { 273. 	    You(mal_aura, "the magic-absorbing blade"); 274. 	    return; 275. 	}  276.   277.  	if(Antimagic) { 278. 	    shieldeff(u.ux, u.uy); 279. 	    You(mal_aura, "you"); 280. 	}  281.   282.  	for (otmp = invent; otmp; otmp = otmp->nobj)  nobj++; 283.  284.  	if (nobj) 285. 	    for (cnt = rnd(6/((!!Antimagic) + (!!Half_spell_damage) + 1));  286.  		 cnt > 0; cnt--)  { 287. 		onum = rn2(nobj); 288. 		for(otmp = invent; onum != 0; onum--) 289. 		    otmp = otmp->nobj; 290.  291.  		if(otmp->oartifact && spec_ability(otmp, SPFX_INTEL) &&  292.  		   rn2(10) < 8) { 293. 		    pline("%s resists!", The(xname(otmp))); 294. 		    continue; 295. 		}  296.   297.  		if(otmp->blessed) 298. 			unbless(otmp); 299. 		else 300. 			curse(otmp); 301. 	    }  302.  }  303.   304.  void 305. attrcurse			/* remove a random INTRINSIC ability */ 306. {  307.  	switch(rnd(11)) { 308. 	case 1 : if (HFire_resistance & INTRINSIC) { 309. 			HFire_resistance &= ~INTRINSIC; 310. 			You_feel("warmer."); 311. 			break; 312. 		}  313.  	case 2 : if (HTeleportation & INTRINSIC) { 314. 			HTeleportation &= ~INTRINSIC; 315. 			You_feel("less jumpy."); 316. 			break; 317. 		}  318.  	case 3 : if (HPoison_resistance & INTRINSIC) { 319. 			HPoison_resistance &= ~INTRINSIC; 320. 			You_feel("a little sick!"); 321. 			break; 322. 		}  323.  	case 4 : if (HTelepat & INTRINSIC) { 324. 			HTelepat &= ~INTRINSIC; 325. 			if (Blind && !Telepat) 326. 			    see_monsters;	/* Can't sense mons anymore! */ 327.  			Your("senses fail!"); 328. 			break; 329. 		}  330.  	case 5 : if (HCold_resistance & INTRINSIC) { 331. 			HCold_resistance &= ~INTRINSIC; 332. 			You_feel("cooler."); 333. 			break; 334. 		}  335.  	case 6 : if (HInvis & INTRINSIC) { 336. 			HInvis &= ~INTRINSIC; 337. 			You_feel("paranoid."); 338. 			break; 339. 		}  340.  	case 7 : if (HSee_invisible & INTRINSIC) { 341. 			HSee_invisible &= ~INTRINSIC; 342. 			You("%s!", Hallucination ? "tawt you taw a puttie tat"  343.  						: "thought you saw something"); 344. 			break; 345. 		}  346.  	case 8 : if (Fast & INTRINSIC) { 347. 			Fast &= ~INTRINSIC; 348. 			You_feel("slower."); 349. 			break; 350. 		}  351.  	case 9 : if (Stealth & INTRINSIC) { 352. 			Stealth &= ~INTRINSIC; 353. 			You_feel("clumsy."); 354. 			break; 355. 		}  356.  	case 10: if (Protection & INTRINSIC) { 357. 			Protection &= ~INTRINSIC; 358. 			You_feel("vulnerable."); 359. 			break; 360. 		}  361.  	case 11: if (Aggravate_monster & INTRINSIC) { 362. 			Aggravate_monster &= ~INTRINSIC; 363. 			You_feel("less attractive."); 364. 			break; 365. 		}  366.  	default: break; 367. 	}  368.  }  369.   370.  /*sit.c*/