Fandom

Wikihack

Source:NetHack 3.1.0/timeout.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 timeout.c from the source code of NetHack 3.1.0. To link to a particular line, write [[NetHack 3.1.0/timeout.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: @(#)timeout.c	3.1	92/11/01	*/
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #include	"hack.h"
6.    
7.    STATIC_DCL void NDECL(stoned_dialogue);
8.    STATIC_DCL void NDECL(vomiting_dialogue);
9.    STATIC_DCL void NDECL(choke_dialogue);
10.   STATIC_DCL void FDECL(hatch_it, (struct obj *));
11.   
12.   static void FDECL(age_candle, (struct obj *));
13.   
14.   #ifdef OVLB
15.   
16.   /* He is being petrified - dialogue by inmet!tower */
17.   static const char NEARDATA *stoned_texts[] = {
18.   	"You are slowing down.",		/* 5 */
19.   	"Your limbs are stiffening.",		/* 4 */
20.   	"Your limbs have turned to stone.",	/* 3 */
21.   	"You have turned to stone.",		/* 2 */
22.   	"You are a statue."			/* 1 */
23.   };
24.   
25.   STATIC_OVL void
26.   stoned_dialogue() {
27.   	register long i = (Stoned & TIMEOUT);
28.   
29.   	if(i > 0 && i <= SIZE(stoned_texts))
30.   		pline(stoned_texts[SIZE(stoned_texts) - i]);
31.   	if(i == 5)
32.   		Fast &= ~(TIMEOUT|INTRINSIC);
33.   	if(i == 3)
34.   		nomul(-3);
35.   	exercise(A_DEX, FALSE);
36.   }
37.   
38.   /* He is getting sicker and sicker prior to vomiting */
39.   static const char NEARDATA *vomiting_texts[] = {
40.   	"You are feeling mildly nauseous.",	/* 14 */
41.   	"You feel slightly confused.",		/* 11 */
42.   	"You can't seem to think straight.",	/* 8 */
43.   	"You feel incredibly sick.",		/* 5 */
44.   	"You suddenly vomit!"			/* 2 */
45.   };
46.   
47.   STATIC_OVL void
48.   vomiting_dialogue() {
49.   	register long i = (Vomiting & TIMEOUT) / 3L;
50.   
51.   	if ((((Vomiting & TIMEOUT) % 3L) == 2) && (i >= 0)
52.   	    && (i < SIZE(vomiting_texts)))
53.   		pline(vomiting_texts[SIZE(vomiting_texts) - i - 1]);
54.   
55.   	switch ((int) i) {
56.   	case 0:
57.   		vomit();
58.   		morehungry(20);
59.   		break;
60.   	case 2:
61.   		make_stunned(HStun + d(2,4), FALSE);
62.   		/* fall through */
63.   	case 3:
64.   		make_confused(HConfusion + d(2,4), FALSE);
65.   		break;
66.   	}
67.   	exercise(A_CON, FALSE);
68.   }
69.   
70.   static const char NEARDATA *choke_texts[] = {
71.   	"You find it hard to breathe.",
72.   	"You're gasping for air.",
73.   	"You can no longer breathe.",
74.   	"You're turning %s.",
75.   	"You suffocate."
76.   };
77.   
78.   STATIC_OVL void
79.   choke_dialogue()
80.   {
81.   	register long i = (Strangled & TIMEOUT);
82.   
83.   	if(i > 0 && i <= SIZE(choke_texts))
84.   		pline(choke_texts[SIZE(choke_texts) - i], Hallucination ?
85.   			hcolor() : blue);
86.   	exercise(A_STR, FALSE);
87.   }
88.   
89.   #endif /* OVLB */
90.   #ifdef OVL0
91.   
92.   void
93.   nh_timeout()
94.   {
95.   	register struct prop *upp;
96.   	int sleeptime;
97.   
98.   	if(u.uluck && moves % (u.uhave.amulet || u.ugangr ? 300 : 600) == 0) {
99.   	/* Cursed luckstones stop bad luck from timing out; blessed luckstones
100.  	 * stop good luck from timing out; normal luckstones stop both;
101.  	 * neither is stopped if you don't have a luckstone.
102.  	 * Luck is based at 0 usually, +1 if a full moon and -1 on Friday 13th
103.  	 */
104.  	    register int time_luck = stone_luck(FALSE);
105.  	    boolean nostone = !carrying(LUCKSTONE) && !stone_luck(TRUE);
106.  	    int baseluck = (flags.moonphase == FULL_MOON) ? 1 : 0;
107.  
108.  	    baseluck -= (flags.friday13 ? 1 : 0);
109.  
110.  	    if(u.uluck > baseluck && (nostone || time_luck < 0))
111.  		u.uluck--;
112.  	    else if(u.uluck < baseluck && (nostone || time_luck > 0))
113.  		u.uluck++;
114.  	}
115.  	if(u.uinvulnerable) return; /* things past this point could kill you */
116.  	if(Stoned) stoned_dialogue();
117.  	if(Vomiting) vomiting_dialogue();
118.  	if(Strangled) choke_dialogue();
119.  #ifdef POLYSELF
120.  	if(u.mtimedone) if(!--u.mtimedone) rehumanize();
121.  #endif
122.  	if(u.ucreamed) u.ucreamed--;
123.  
124.  	for(upp = u.uprops; upp < u.uprops+SIZE(u.uprops); upp++)
125.  	    if((upp->p_flgs & TIMEOUT) && !(--upp->p_flgs & TIMEOUT)) {
126.  		if(upp->p_tofn) (*upp->p_tofn)();
127.  		else switch(upp - u.uprops){
128.  		case STONED:
129.  			if (!killer) {
130.  				killer_format = KILLED_BY_AN;
131.  				killer = "cockatrice";
132.  			} done(STONING);
133.  			break;
134.  		case VOMITING:
135.  			make_vomiting(0L, TRUE);
136.  			break;
137.  		case SICK:
138.  			You("die from your illness.");
139.  			killer_format = KILLED_BY_AN;
140.  			killer = u.usick_cause;
141.  			done(POISONING);
142.  			break;
143.  		case FAST:
144.  			if (Fast & ~INTRINSIC) /* boot speed */
145.  				;
146.  			else
147.  				You("feel yourself slowing down%s.",
148.  							Fast ? " a bit" : "");
149.  			break;
150.  		case CONFUSION:
151.  			HConfusion = 1; /* So make_confused works properly */
152.  			make_confused(0L, TRUE);
153.  			stop_occupation();
154.  			break;
155.  		case STUNNED:
156.  			HStun = 1;
157.  			make_stunned(0L, TRUE);
158.  			stop_occupation();
159.  			break;
160.  		case BLINDED:
161.  			Blinded = 1;
162.  			make_blinded(0L, TRUE);
163.  			stop_occupation();
164.  			break;
165.  		case INVIS:
166.  			newsym(u.ux,u.uy);
167.  			if (!Invis && !See_invisible && !Blind)
168.  				You("are no longer invisible.");
169.  			stop_occupation();
170.  			break;
171.  		case SEE_INVIS:
172.  			set_mimic_blocking(); /* do special mimic handling */
173.  			see_monsters();		/* make invis mons appear */
174.  			newsym(u.ux,u.uy);	/* make self appear */
175.  			stop_occupation();
176.  			break;
177.  		case WOUNDED_LEGS:
178.  			heal_legs();
179.  			stop_occupation();
180.  			break;
181.  		case HALLUC:
182.  			HHallucination = 1;
183.  			make_hallucinated(0L, TRUE, 0L);
184.  			stop_occupation();
185.  			break;
186.  		case SLEEPING:
187.  			if (unconscious() || Sleep_resistance)
188.  				Sleeping += rnd(100);
189.  			else {
190.  				You("fall asleep.");
191.  				sleeptime = rnd(20);
192.  				nomul(-sleeptime);
193.  				u.usleep = 1;
194.  				nomovemsg = "You wake up.";
195.  				Sleeping = sleeptime + rnd(100);
196.  			}
197.  			break;
198.  		case STRANGLED:
199.  			killer_format = KILLED_BY;
200.  			killer = "strangulation";
201.  			done(DIED);
202.  			break;
203.  		case FUMBLING:
204.  			/* call this only when a move took place.  */
205.  			/* otherwise handle fumbling msgs locally. */
206.  			if (!Levitation && u.umoved) {
207.  			    if (OBJ_AT(u.ux, u.uy))
208.  				You("trip over something.");
209.  			    else if (rn2(3) && is_ice(u.ux, u.uy))
210.  				You("%s on the ice.",
211.  				    rn2(2) ? "slip" : "slide");
212.  			    else
213.  				switch (rn2(4)) {
214.  				    case 1:
215.  					if (ACCESSIBLE(levl[u.ux][u.uy].typ)) { /* not POOL or STONE */
216.  					    if (Hallucination) pline("A rock bites your foot.");
217.  					    else You("trip over a rock.");
218.  					    break;
219.  					}
220.  				    case 2:
221.  					if (ACCESSIBLE(levl[u.ux][u.uy].typ)) { /* not POOL or STONE */
222.  					    if (Hallucination) You("slip on a banana peel.");
223.  					    else You("slip and nearly fall.");
224.  					    break;
225.  					}
226.  				    case 3:
227.  					You("flounder.");
228.  					break;
229.  				    default:
230.  					You("stumble.");
231.  				}
232.  			    nomul(-2);
233.  			    nomovemsg = "";
234.  			    /* Fumbling can be noisy */
235.  			    if ((inv_weight() > -500)) {
236.  			    	You("make a lot of noise!");
237.  			    	wake_nearby();
238.  			    }
239.  			}
240.  			Fumbling += rnd(20);
241.  			break;
242.  		}
243.  	}
244.  }
245.  
246.  #endif /* OVL0 */
247.  #ifdef OVLB
248.  
249.  STATIC_OVL void
250.  hatch_it(otmp)		/* hatch the egg "otmp" if possible */
251.  register struct obj *otmp;
252.  {
253.  	register struct monst *mtmp;
254.  #ifdef POLYSELF
255.  	int yours = otmp->spe;
256.  #endif
257.  
258.  	if(monstermoves-otmp->age > 200)  /* very old egg - it's dead */
259.  	    otmp->corpsenm = -1;
260.  #ifdef LINT	/* long conv. ok */
261.  	else if(rnd(150) > 150) {
262.  #else
263.  	else if(rnd((int)(monstermoves-otmp->age)) > 150) {
264.  #endif
265.  	    mtmp = makemon(&mons[big_to_little(otmp->corpsenm)], u.ux, u.uy);
266.  	    useup(otmp);
267.  	    if(mtmp) {
268.  
269.  		if(Blind)
270.  		    You("feel something %s from your pack!",
271.  			locomotion(mtmp->data, "drop"));
272.  		else
273.  		    You("see %s %s out of your pack!",
274.  			an(mtmp->data->mname),
275.  			locomotion(mtmp->data, "drop"));
276.  
277.  #ifdef POLYSELF
278.  		if (yours) {
279.  		    struct monst *mtmp2;
280.  
281.  		    pline("Its cries sound like \"%s.\"",
282.  			flags.female ? "mommy" : "daddy");
283.  		    if (mtmp2 = tamedog(mtmp, (struct obj *)0))
284.  			mtmp = mtmp2;
285.  		    mtmp->mtame = 20;
286.  		    while(otmp = (mtmp->minvent)) {
287.  			mtmp->minvent = otmp->nobj;
288.  			dealloc_obj(otmp);
289.  		    }
290.  		    return;
291.  		}
292.  #endif
293.  		if(mtmp->data->mlet == S_DRAGON) {
294.  		    struct monst *mtmp2;
295.  
296.  		    verbalize("Gleep!");		/* Mything eggs :-) */
297.  		    if (mtmp2 = tamedog(mtmp, (struct obj *)0))
298.  			mtmp = mtmp2;
299.  		    while(otmp = (mtmp->minvent)) {
300.  			mtmp->minvent = otmp->nobj;
301.  			dealloc_obj(otmp);
302.  		    }
303.  		}
304.  	    }
305.  	}
306.  }
307.  
308.  #endif /* OVLB */
309.  #ifdef OVL1
310.  
311.  void
312.  hatch_eggs()	    /* hatch any eggs that have been too long in pack */
313.  {
314.  	register struct obj *otmp, *otmp2;
315.  
316.  	for(otmp = invent; otmp; otmp = otmp2) {
317.  	    otmp2 = otmp->nobj;	    /* otmp may hatch */
318.  	    if(otmp->otyp == EGG && otmp->corpsenm >= 0) hatch_it(otmp);
319.  	    /* else if (Is_container(otmp) && otmp->cobj) ...		*/
320.  	    /*								*/
321.  	    /* Check for container here and hatch with the container.	*/
322.  	    /* One of these days...					*/
323.  	    /* Maybe call hatch_eggs() with invent as a parameter so	*/
324.  	    /* that we can call it recursively.				*/
325.  	}
326.  }
327.  
328.  /* Burn up lit lamps.  Only applies to non-magic lamps; magic lamps stay
329.   * lit as long as there's a genie inside.  We use obj->age to see how long
330.   * there is left for the lamp to burn, but this differs from the use of
331.   * age for corpses and eggs: for the latter items it's when the object was
332.   * created, but for lamps it's the number of moves remaining.
333.   */
334.  void
335.  burn_lamps()
336.  {
337.  	register struct obj *obj;
338.  
339.  	/* Note: magic lamps never go out as long as the genie's inside */
340.  	for(obj=invent; obj; obj=obj->nobj) {
341.  	    if ((obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN)
342.  							&& obj->lamplit) {
343.  		obj->age--;
344.  		switch((int)obj->age) {
345.  		    case 150:
346.  		    case 100:
347.  			if (obj->otyp == BRASS_LANTERN) goto advmsg;
348.  			if (!Blind)
349.  			    Your("%s flickers.", xname(obj));
350.  			break;
351.  		    case 50:
352.  			if (obj->otyp == BRASS_LANTERN) goto advmsg;
353.  			if (!Blind)
354.  			    Your("%s flickers considerably.", xname(obj));
355.  			break;
356.  		    case 25:
357.  	advmsg:		if (!Blind) {
358.  			    if (obj->otyp == BRASS_LANTERN) {
359.  				Your("lamp is getting dim.");
360.  				if (Hallucination)
361.  				    pline("Batteries have not been invented yet.");
362.  			    } else
363.  				Your("%s seems about to go out.", xname(obj));
364.  			}
365.  			break;
366.  		    case 0: /* even if blind you'll know */
367.  			if (obj->otyp == BRASS_LANTERN)
368.  				Your("lamp has run out of power.");
369.  			else Your("%s goes out.", xname(obj));
370.  			obj->lamplit = 0;
371.  			obj->spe = 0;
372.  			check_lamps();
373.  			break;
374.  		    default: break;
375.  		}
376.  	    }
377.  	    if ((obj->otyp == CANDELABRUM_OF_INVOCATION || Is_candle(obj)) &&
378.  			obj->lamplit)
379.  		age_candle(obj);
380.  	}
381.  }
382.  
383.  static void
384.  age_candle(otmp)
385.  register struct obj *otmp;
386.  {
387.  	register boolean many, 
388.  	                 menorah = otmp->otyp == CANDELABRUM_OF_INVOCATION;
389.  
390.  	otmp->age--;
391.  
392.  	if (otmp->age == 0L) {
393.  	    otmp->lamplit = 0;
394.  	    many = menorah ? otmp->spe > 1 : otmp->quan > 1L;
395.  	    if (menorah) {
396.  		pline("%s's flame%s.", 
397.  			The(xname(otmp)), (many ? "s die" : " dies"));
398.  		otmp->spe = 0;
399.  	    } else {
400.  		Your("%s %s consumed!  %s",
401.  			xname(otmp), (many ? "are" : "is"),
402.  			(Hallucination ?
403.  			    (many ? "They shriek!" : "It shrieks!") :
404.  			 Blind ? "" :
405.  			    (many ? "Their flames die." : "Its flame dies.")));
406.  		freeinv(otmp);
407.  		obfree(otmp, (struct obj *)0);
408.  	    }
409.  	    check_lamps();
410.  	} else if (Blind) {
411.  	    return;
412.  	} else if (otmp->age == 15L) {
413.  	    many = menorah ? otmp->spe > 1 : otmp->quan > 1L;
414.  	    Norep("The %scandle%s flame%s flicker%s low!",
415.  			(menorah ? "candelabrum's " : ""),
416.  			(many ? "s'" : "'s"),
417.  			(many ? "s" : ""),
418.  			(many ? "" : "s"));
419.  	} else if (otmp->age == 75L) {
420.  	    many = menorah ? otmp->spe > 1 : otmp->quan > 1L;
421.  	    Norep("The %scandle%s getting short.",
422.  			menorah ? "candelabrum's " : "",
423.  			(many ? "s are" : " is"));
424.  	}
425.  }
426.  void
427.  do_storms()
428.  {
429.      int nstrike;
430.      register int x, y;
431.      int dirx, diry;
432.      int count;
433.  
434.      /* no lightning if not the air level or too often, even then */
435.      if(!Is_airlevel(&u.uz) || rn2(8))
436.  	return;
437.  
438.      /* the number of strikes is 8-log2(nstrike) */
439.      for(nstrike = rnd(64); nstrike <= 64; nstrike *= 2) {
440.  	count = 0;
441.  	do {
442.  	    x = rnd(COLNO-1);
443.  	    y = rn2(ROWNO);
444.  	} while (++count < 100 && levl[x][y].typ != CLOUD);
445.  
446.  	if(count < 100) {
447.  	    dirx = rn2(3) - 1;
448.  	    diry = rn2(3) - 1;
449.  	    if(dirx != 0 || diry != 0)
450.  		buzz(-15, /* "monster" LIGHTNING spell */
451.  		     8, x, y, dirx, diry);
452.  	}
453.      }
454.  
455.      if(levl[u.ux][u.uy].typ == CLOUD) {
456.  	/* inside a cloud during a thunder storm is deafening */
457.  	pline("Kaboom!!!  Boom!!  Boom!!");
458.  	if(!u.uinvulnerable) {
459.  	    stop_occupation();
460.  	    nomul(-3);
461.  	}
462.      } else
463.  	You("hear a rumbling noise.");
464.  }
465.  #endif /* OVL1 */
466.  
467.  /*timeout.c*/

Also on Fandom

Random Wiki