Wikia

Wikihack

Source:NetHack 3.4.0/sit.c

2,032pages on
this wiki
Talk0

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

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

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

Around Wikia's network

Random Wiki