Wikia

Wikihack

Source:NetHack 3.2.0/pline.c

2,032pages on
this wiki
Talk0

Below is the full text to pline.c from the source code of NetHack 3.2.0. To link to a particular line, write [[NetHack 3.2.0/pline.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: @(#)pline.c	3.2	96/02/01	*/
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #define NEED_VARARGS /* Uses ... */	/* comment line for pre-compiled headers */
6.    #include "hack.h"
7.    #include "epri.h"
8.    
9.    #ifdef OVLB
10.   
11.   static boolean no_repeat = FALSE;
12.   
13.   static char *FDECL(You_buf, (int));
14.   
15.   /*VARARGS1*/
16.   /* Note that these declarations rely on knowledge of the internals
17.    * of the variable argument handling stuff in "tradstdc.h"
18.    */
19.   
20.   #if defined(USE_STDARG) || defined(USE_VARARGS)
21.   static void FDECL(vpline, (const char *, va_list));
22.   
23.   void
24.   pline VA_DECL(const char *, line)
25.   	VA_START(line);
26.   	VA_INIT(line, char *);
27.   	vpline(line, VA_ARGS);
28.   	VA_END();
29.   }
30.   
31.   # ifdef USE_STDARG
32.   static void
33.   vpline(const char *line, va_list the_args) {
34.   # else
35.   static void
36.   vpline(line, the_args) const char *line; va_list the_args; {
37.   # endif
38.   
39.   #else	/* USE_STDARG | USE_VARARG */
40.   
41.   #define vpline pline
42.   
43.   void
44.   pline VA_DECL(const char *, line)
45.   #endif	/* USE_STDARG | USE_VARARG */
46.   
47.   	char pbuf[BUFSZ];
48.   /* Do NOT use VA_START and VA_END in here... see above */
49.   
50.   	if (!line || !*line) return;
51.   	if (index(line, '%')) {
52.   	    Vsprintf(pbuf,line,VA_ARGS);
53.   	    line = pbuf;
54.   	}
55.   	if (!flags.window_inited) {
56.   	    raw_print(line);
57.   	    return;
58.   	}
59.   #ifndef MAC
60.   	if (no_repeat && !strcmp(line, toplines))
61.   	    return;
62.   #endif /* MAC */
63.   	if (vision_full_recalc) vision_recalc(0);
64.   	if (u.ux) flush_screen(1);		/* %% */
65.   	putstr(WIN_MESSAGE, 0, line);
66.   }
67.   
68.   /*VARARGS1*/
69.   void
70.   Norep VA_DECL(const char *, line)
71.   	VA_START(line);
72.   	VA_INIT(line, const char *);
73.   	no_repeat = TRUE;
74.   	vpline(line, VA_ARGS);
75.   	no_repeat = FALSE;
76.   	VA_END();
77.   	return;
78.   }
79.   
80.   /* work buffer for You(), &c and verbalize() */
81.   static char *you_buf = 0;
82.   static int you_buf_siz = 0;
83.   
84.   static char *
85.   You_buf(siz) int siz; {
86.   	if (siz > you_buf_siz) {
87.   		if (you_buf_siz > 0) free((genericptr_t) you_buf);
88.   		you_buf_siz = siz + 10;
89.   		you_buf = (char *) alloc((unsigned) you_buf_siz);
90.   	}
91.   	return you_buf;
92.   }
93.   
94.   /* `prefix' must be a string literal, not a pointer */
95.   #define YouPrefix(pointer,prefix,text) \
96.    Strcpy((pointer = You_buf((int)(strlen(text) + sizeof prefix))), prefix)
97.   
98.   #define YouMessage(pointer,prefix,text) \
99.    strcat((YouPrefix(pointer, prefix, text), pointer), text)
100.  
101.  /*VARARGS1*/
102.  void
103.  You VA_DECL(const char *, line)
104.  	char *tmp;
105.  	VA_START(line);
106.  	VA_INIT(line, const char *);
107.  	vpline(YouMessage(tmp, "You ", line), VA_ARGS);
108.  	VA_END();
109.  }
110.  
111.  /*VARARGS1*/
112.  void
113.  Your VA_DECL(const char *,line)
114.  	char *tmp;
115.  	VA_START(line);
116.  	VA_INIT(line, const char *);
117.  	vpline(YouMessage(tmp, "Your ", line), VA_ARGS);
118.  	VA_END();
119.  }
120.  
121.  /*VARARGS1*/
122.  void
123.  You_feel VA_DECL(const char *,line)
124.  	char *tmp;
125.  	VA_START(line);
126.  	VA_INIT(line, const char *);
127.  	vpline(YouMessage(tmp, "You feel ", line), VA_ARGS);
128.  	VA_END();
129.  }
130.  
131.  
132.  /*VARARGS1*/
133.  void
134.  You_cant VA_DECL(const char *,line)
135.  	char *tmp;
136.  	VA_START(line);
137.  	VA_INIT(line, const char *);
138.  	vpline(YouMessage(tmp, "You can't ", line), VA_ARGS);
139.  	VA_END();
140.  }
141.  
142.  /*VARARGS1*/
143.  void
144.  pline_The VA_DECL(const char *,line)
145.  	char *tmp;
146.  	VA_START(line);
147.  	VA_INIT(line, const char *);
148.  	vpline(YouMessage(tmp, "The ", line), VA_ARGS);
149.  	VA_END();
150.  }
151.  
152.  /*VARARGS1*/
153.  void
154.  You_hear VA_DECL(const char *,line)
155.  	char *tmp;
156.  	VA_START(line);
157.  	VA_INIT(line, const char *);
158.  	if (!Underwater)
159.  		YouPrefix(tmp, "You hear ", line);
160.  	else
161.  		YouPrefix(tmp, "You barely hear ", line);
162.  	vpline(strcat(tmp, line), VA_ARGS);
163.  	VA_END();
164.  }
165.  
166.  /*VARARGS1*/
167.  void
168.  verbalize VA_DECL(const char *,line)
169.  	char *tmp;
170.  	if (!flags.soundok) return;
171.  	VA_START(line);
172.  	VA_INIT(line, const char *);
173.  	tmp = You_buf((int)strlen(line) + sizeof "\"\"");
174.  	Strcpy(tmp, "\"");
175.  	Strcat(tmp, line);
176.  	Strcat(tmp, "\"");
177.  	vpline(tmp, VA_ARGS);
178.  	VA_END();
179.  }
180.  
181.  /*VARARGS1*/
182.  /* Note that these declarations rely on knowledge of the internals
183.   * of the variable argument handling stuff in "tradstdc.h"
184.   */
185.  
186.  #if defined(USE_STDARG) || defined(USE_VARARGS)
187.  static void FDECL(vraw_printf,(const char *,va_list));
188.  
189.  void
190.  raw_printf VA_DECL(const char *, line)
191.  	VA_START(line);
192.  	VA_INIT(line, char *);
193.  	vraw_printf(line, VA_ARGS);
194.  	VA_END();
195.  }
196.  
197.  # ifdef USE_STDARG
198.  static void
199.  vraw_printf(const char *line, va_list the_args) {
200.  # else
201.  static void
202.  vraw_printf(line, the_args) const char *line; va_list the_args; {
203.  # endif
204.  
205.  #else  /* USE_STDARG | USE_VARARG */
206.  
207.  void
208.  raw_printf VA_DECL(const char *, line)
209.  #endif
210.  /* Do NOT use VA_START and VA_END in here... see above */
211.  
212.  	if(!index(line, '%'))
213.  	    raw_print(line);
214.  	else {
215.  	    char pbuf[BUFSZ];
216.  	    Vsprintf(pbuf,line,VA_ARGS);
217.  	    raw_print(pbuf);
218.  	}
219.  }
220.  
221.  
222.  /*VARARGS1*/
223.  void
224.  impossible VA_DECL(const char *, s)
225.  	VA_START(s);
226.  	VA_INIT(s, const char *);
227.  	vpline(s,VA_ARGS);
228.  	pline("Program in disorder - perhaps you'd better Quit.");
229.  	VA_END();
230.  }
231.  
232.  const char *
233.  align_str(alignment)
234.      aligntyp alignment;
235.  {
236.      switch ((int)alignment) {
237.  	case A_CHAOTIC: return "chaotic";
238.  	case A_NEUTRAL: return "neutral";
239.  	case A_LAWFUL:	return "lawful";
240.  	case A_NONE:	return "unaligned";
241.      }
242.      return "unknown";
243.  }
244.  
245.  void
246.  mstatusline(mtmp)
247.  register struct monst *mtmp;
248.  {
249.  	aligntyp alignment;
250.  	char info[BUFSZ], monnambuf[BUFSZ];
251.  
252.  	if (mtmp->ispriest || mtmp->data == &mons[PM_ALIGNED_PRIEST]
253.  				|| mtmp->data == &mons[PM_ANGEL])
254.  		alignment = EPRI(mtmp)->shralign;
255.  	else
256.  		alignment = mtmp->data->maligntyp;
257.  	alignment = (alignment > 0) ? A_LAWFUL :
258.  		(alignment < 0) ? A_CHAOTIC :
259.  		A_NEUTRAL;
260.  
261.  	info[0] = 0;
262.  	if (mtmp->mtame) {	  Strcat(info, ", tame");
263.  #ifdef WIZARD
264.  	    if (wizard)		  Sprintf(eos(info), " (%d)", mtmp->mtame);
265.  #endif
266.  	}
267.  	else if (mtmp->mpeaceful) Strcat(info, ", peaceful");
268.  	if (mtmp->meating)	  Strcat(info, ", eating");
269.  	if (mtmp->mcan)		  Strcat(info, ", cancelled");
270.  	if (mtmp->mconf)	  Strcat(info, ", confused");
271.  	if (mtmp->mblinded || !mtmp->mcansee)
272.  				  Strcat(info, ", blind");
273.  	if (mtmp->mstun)	  Strcat(info, ", stunned");
274.  	if (mtmp->msleep)	  Strcat(info, ", asleep");
275.  #if 0	/* unfortunately mfrozen covers temporary sleep and being busy
276.  	   (donning armor, for instance) as well as paralysis */
277.  	else if (mtmp->mfrozen)	  Strcat(info, ", paralyzed");
278.  #else
279.  	else if (mtmp->mfrozen || !mtmp->mcanmove)
280.  				  Strcat(info, ", can't move");
281.  #endif
282.  				  /* [arbitrary reason why it isn't moving] */
283.  	else if (mtmp->mstrategy & STRAT_WAITMASK)
284.  				  Strcat(info, ", meditating");
285.  	else if (mtmp->mflee)	  Strcat(info, ", scared");
286.  	if (mtmp->mtrapped)	  Strcat(info, ", trapped");
287.  	if (mtmp->mspeed)	  Strcat(info,
288.  					mtmp->mspeed == MFAST ? ", fast" :
289.  					mtmp->mspeed == MSLOW ? ", slow" :
290.  					", ???? speed");
291.  	if (mtmp->mundetected)	  Strcat(info, ", concealed");
292.  	if (mtmp->minvis)	  Strcat(info, ", invisible");
293.  	if (mtmp == u.ustuck)	  Strcat(info,
294.  			(u.mtimedone && sticks(uasmon)) ? ", held by you" :
295.  				u.uswallow ? (is_animal(u.ustuck->data) ?
296.  				", swallowed you" :
297.  				", engulfed you") :
298.  				", holding you");
299.  
300.  	Strcpy(monnambuf, mon_nam(mtmp));
301.  	/* avoid "Status of the invisible newt ..., invisible" */
302.  	if (mtmp->minvis && strstri(monnambuf, "invisible")) {
303.  	    mtmp->minvis = 0;
304.  	    Strcpy(monnambuf, mon_nam(mtmp));
305.  	    mtmp->minvis = 1;
306.  	}
307.  
308.  	pline("Status of %s (%s):  Level %d  HP %d(%d)  AC %d%s.",
309.  		monnambuf,
310.  		align_str(alignment),
311.  		mtmp->m_lev,
312.  		mtmp->mhp,
313.  		mtmp->mhpmax,
314.  		find_mac(mtmp),
315.  		info);
316.  }
317.  
318.  void
319.  ustatusline()
320.  {
321.  	char info[BUFSZ];
322.  
323.  	info[0] = '\0';
324.  	if (Sick) {
325.  		Strcat(info, ", dying from");
326.  		if (u.usick_type & SICK_VOMITABLE)
327.  			Strcat(info, " food poisoning");
328.  		if (u.usick_type & SICK_NONVOMITABLE) {
329.  			if (u.usick_type & SICK_VOMITABLE)
330.  				Strcat(info, " and");
331.  			Strcat(info, " illness");
332.  		}
333.  	}
334.  	if (Stoned)		Strcat(info, ", solidifying");
335.  	if (Strangled)		Strcat(info, ", being strangled");
336.  	if (Vomiting)		Strcat(info, ", nauseated"); /* !"nauseous" */
337.  	if (Confusion)		Strcat(info, ", confused");
338.  	if (Blind) {
339.  	    Strcat(info, ", blind");
340.  	    if (u.ucreamed) {
341.  		if ((long)u.ucreamed < Blinded || Blindfolded
342.  						|| !haseyes(uasmon))
343.  		    Strcat(info, ", cover");
344.  		Strcat(info, "ed by sticky goop");
345.  	    }	/* note: "goop" == "glop"; variation is intentional */
346.  	}
347.  	if (Stunned)		Strcat(info, ", stunned");
348.  	if (Wounded_legs) {
349.  	    const char *what = body_part(LEG);
350.  	    if ((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
351.  		what = makeplural(what);
352.  				Sprintf(eos(info), ", injured %s", what);
353.  	}
354.  	if (Glib)		Sprintf(eos(info), ", slippery %s",
355.  					makeplural(body_part(HAND)));
356.  	if (u.utrap)		Strcat(info, ", trapped");
357.  	if (Fast)		Strcat(info, ", fast");
358.  	if (u.uundetected)	Strcat(info, ", concealed");
359.  	if (Invis)		Strcat(info, ", invisible");
360.  	if (u.ustuck) {
361.  	    if (u.mtimedone && sticks(uasmon))
362.  		Strcat(info, ", holding ");
363.  	    else
364.  		Strcat(info, ", held by ");
365.  	    Strcat(info, mon_nam(u.ustuck));
366.  	}
367.  
368.  	pline("Status of %s (%s%s):  Level %d  HP %d(%d)  AC %d%s.",
369.  		plname,
370.  		    (u.ualign.record >= 20) ? "piously " :
371.  		    (u.ualign.record > 13) ? "devoutly " :
372.  		    (u.ualign.record > 8) ? "fervently " :
373.  		    (u.ualign.record > 3) ? "stridently " :
374.  		    (u.ualign.record == 3) ? "" :
375.  		    (u.ualign.record >= 1) ? "haltingly " :
376.  		    (u.ualign.record == 0) ? "nominally " :
377.  					    "insufficiently ",
378.  		align_str(u.ualign.type),
379.  		u.mtimedone ? mons[u.umonnum].mlevel : u.ulevel,
380.  		u.mtimedone ? u.mh : u.uhp,
381.  		u.mtimedone ? u.mhmax : u.uhpmax,
382.  		u.uac,
383.  		info);
384.  }
385.  
386.  #endif /* OVLB */
387.  
388.  /*pline.c*/

Around Wikia's network

Random Wiki