Fandom

Wikihack

Source:NetHack 3.1.0/sit.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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

Also on Fandom

Random Wiki