Wikihack
Register
Advertisement

Below is the full text to pline.c from the source code of NetHack 3.3.0. To link to a particular line, write [[NetHack 3.3.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.3	1999/11/28	*/
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 (!iflags.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)
86.   int siz;
87.   {
88.   	if (siz > you_buf_siz) {
89.   		if (you_buf) free((genericptr_t) you_buf);
90.   		you_buf_siz = siz + 10;
91.   		you_buf = (char *) alloc((unsigned) you_buf_siz);
92.   	}
93.   	return you_buf;
94.   }
95.   
96.   void
97.   free_youbuf()
98.   {
99.   	if (you_buf) free((genericptr_t) you_buf),  you_buf = (char *)0;
100.  	you_buf_siz = 0;
101.  }
102.  
103.  /* `prefix' must be a string literal, not a pointer */
104.  #define YouPrefix(pointer,prefix,text) \
105.   Strcpy((pointer = You_buf((int)(strlen(text) + sizeof prefix))), prefix)
106.  
107.  #define YouMessage(pointer,prefix,text) \
108.   strcat((YouPrefix(pointer, prefix, text), pointer), text)
109.  
110.  /*VARARGS1*/
111.  void
112.  You VA_DECL(const char *, line)
113.  	char *tmp;
114.  	VA_START(line);
115.  	VA_INIT(line, const char *);
116.  	vpline(YouMessage(tmp, "You ", line), VA_ARGS);
117.  	VA_END();
118.  }
119.  
120.  /*VARARGS1*/
121.  void
122.  Your VA_DECL(const char *,line)
123.  	char *tmp;
124.  	VA_START(line);
125.  	VA_INIT(line, const char *);
126.  	vpline(YouMessage(tmp, "Your ", line), VA_ARGS);
127.  	VA_END();
128.  }
129.  
130.  /*VARARGS1*/
131.  void
132.  You_feel VA_DECL(const char *,line)
133.  	char *tmp;
134.  	VA_START(line);
135.  	VA_INIT(line, const char *);
136.  	vpline(YouMessage(tmp, "You feel ", line), VA_ARGS);
137.  	VA_END();
138.  }
139.  
140.  
141.  /*VARARGS1*/
142.  void
143.  You_cant VA_DECL(const char *,line)
144.  	char *tmp;
145.  	VA_START(line);
146.  	VA_INIT(line, const char *);
147.  	vpline(YouMessage(tmp, "You can't ", line), VA_ARGS);
148.  	VA_END();
149.  }
150.  
151.  /*VARARGS1*/
152.  void
153.  pline_The VA_DECL(const char *,line)
154.  	char *tmp;
155.  	VA_START(line);
156.  	VA_INIT(line, const char *);
157.  	vpline(YouMessage(tmp, "The ", line), VA_ARGS);
158.  	VA_END();
159.  }
160.  
161.  /*VARARGS1*/
162.  void
163.  You_hear VA_DECL(const char *,line)
164.  	char *tmp;
165.  	VA_START(line);
166.  	VA_INIT(line, const char *);
167.  	if (!Underwater)
168.  		YouPrefix(tmp, "You hear ", line);
169.  	else
170.  		YouPrefix(tmp, "You barely hear ", line);
171.  	vpline(strcat(tmp, line), VA_ARGS);
172.  	VA_END();
173.  }
174.  
175.  /*VARARGS1*/
176.  void
177.  verbalize VA_DECL(const char *,line)
178.  	char *tmp;
179.  	if (!flags.soundok) return;
180.  	VA_START(line);
181.  	VA_INIT(line, const char *);
182.  	tmp = You_buf((int)strlen(line) + sizeof "\"\"");
183.  	Strcpy(tmp, "\"");
184.  	Strcat(tmp, line);
185.  	Strcat(tmp, "\"");
186.  	vpline(tmp, VA_ARGS);
187.  	VA_END();
188.  }
189.  
190.  /*VARARGS1*/
191.  /* Note that these declarations rely on knowledge of the internals
192.   * of the variable argument handling stuff in "tradstdc.h"
193.   */
194.  
195.  #if defined(USE_STDARG) || defined(USE_VARARGS)
196.  static void FDECL(vraw_printf,(const char *,va_list));
197.  
198.  void
199.  raw_printf VA_DECL(const char *, line)
200.  	VA_START(line);
201.  	VA_INIT(line, char *);
202.  	vraw_printf(line, VA_ARGS);
203.  	VA_END();
204.  }
205.  
206.  # ifdef USE_STDARG
207.  static void
208.  vraw_printf(const char *line, va_list the_args) {
209.  # else
210.  static void
211.  vraw_printf(line, the_args) const char *line; va_list the_args; {
212.  # endif
213.  
214.  #else  /* USE_STDARG | USE_VARARG */
215.  
216.  void
217.  raw_printf VA_DECL(const char *, line)
218.  #endif
219.  /* Do NOT use VA_START and VA_END in here... see above */
220.  
221.  	if(!index(line, '%'))
222.  	    raw_print(line);
223.  	else {
224.  	    char pbuf[BUFSZ];
225.  	    Vsprintf(pbuf,line,VA_ARGS);
226.  	    raw_print(pbuf);
227.  	}
228.  }
229.  
230.  
231.  /*VARARGS1*/
232.  void
233.  impossible VA_DECL(const char *, s)
234.  	VA_START(s);
235.  	VA_INIT(s, const char *);
236.  	vpline(s,VA_ARGS);
237.  	pline("Program in disorder - perhaps you'd better #quit.");
238.  	VA_END();
239.  }
240.  
241.  const char *
242.  align_str(alignment)
243.      aligntyp alignment;
244.  {
245.      switch ((int)alignment) {
246.  	case A_CHAOTIC: return "chaotic";
247.  	case A_NEUTRAL: return "neutral";
248.  	case A_LAWFUL:	return "lawful";
249.  	case A_NONE:	return "unaligned";
250.      }
251.      return "unknown";
252.  }
253.  
254.  void
255.  mstatusline(mtmp)
256.  register struct monst *mtmp;
257.  {
258.  	aligntyp alignment;
259.  	char info[BUFSZ], monnambuf[BUFSZ];
260.  
261.  	if (mtmp->ispriest || mtmp->data == &mons[PM_ALIGNED_PRIEST]
262.  				|| mtmp->data == &mons[PM_ANGEL])
263.  		alignment = EPRI(mtmp)->shralign;
264.  	else
265.  		alignment = mtmp->data->maligntyp;
266.  	alignment = (alignment > 0) ? A_LAWFUL :
267.  		(alignment < 0) ? A_CHAOTIC :
268.  		A_NEUTRAL;
269.  
270.  	info[0] = 0;
271.  	if (mtmp->mtame) {	  Strcat(info, ", tame");
272.  #ifdef WIZARD
273.  	    if (wizard)		  Sprintf(eos(info), " (%d)", mtmp->mtame);
274.  #endif
275.  	}
276.  	else if (mtmp->mpeaceful) Strcat(info, ", peaceful");
277.  	if (mtmp->meating)	  Strcat(info, ", eating");
278.  	if (mtmp->mcan)		  Strcat(info, ", cancelled");
279.  	if (mtmp->mconf)	  Strcat(info, ", confused");
280.  	if (mtmp->mblinded || !mtmp->mcansee)
281.  				  Strcat(info, ", blind");
282.  	if (mtmp->mstun)	  Strcat(info, ", stunned");
283.  	if (mtmp->msleeping)	  Strcat(info, ", asleep");
284.  #if 0	/* unfortunately mfrozen covers temporary sleep and being busy
285.  	   (donning armor, for instance) as well as paralysis */
286.  	else if (mtmp->mfrozen)	  Strcat(info, ", paralyzed");
287.  #else
288.  	else if (mtmp->mfrozen || !mtmp->mcanmove)
289.  				  Strcat(info, ", can't move");
290.  #endif
291.  				  /* [arbitrary reason why it isn't moving] */
292.  	else if (mtmp->mstrategy & STRAT_WAITMASK)
293.  				  Strcat(info, ", meditating");
294.  	else if (mtmp->mflee)	  Strcat(info, ", scared");
295.  	if (mtmp->mtrapped)	  Strcat(info, ", trapped");
296.  	if (mtmp->mspeed)	  Strcat(info,
297.  					mtmp->mspeed == MFAST ? ", fast" :
298.  					mtmp->mspeed == MSLOW ? ", slow" :
299.  					", ???? speed");
300.  	if (mtmp->mundetected)	  Strcat(info, ", concealed");
301.  	if (mtmp->minvis)	  Strcat(info, ", invisible");
302.  	if (mtmp == u.ustuck)	  Strcat(info,
303.  			(sticks(youmonst.data)) ? ", held by you" :
304.  				u.uswallow ? (is_animal(u.ustuck->data) ?
305.  				", swallowed you" :
306.  				", engulfed you") :
307.  				", holding you");
308.  #ifdef STEED
309.  	if (mtmp == u.usteed)	  Strcat(info, ", carrying you");
310.  #endif
311.  
312.  	Strcpy(monnambuf, mon_nam(mtmp));
313.  	/* avoid "Status of the invisible newt ..., invisible" */
314.  	if (mtmp->minvis && strstri(monnambuf, "invisible")) {
315.  	    mtmp->minvis = 0;
316.  	    Strcpy(monnambuf, mon_nam(mtmp));
317.  	    mtmp->minvis = 1;
318.  	}
319.  
320.  	pline("Status of %s (%s):  Level %d  HP %d(%d)  AC %d%s.",
321.  		monnambuf,
322.  		align_str(alignment),
323.  		mtmp->m_lev,
324.  		mtmp->mhp,
325.  		mtmp->mhpmax,
326.  		find_mac(mtmp),
327.  		info);
328.  }
329.  
330.  void
331.  ustatusline()
332.  {
333.  	char info[BUFSZ];
334.  
335.  	info[0] = '\0';
336.  	if (Sick) {
337.  		Strcat(info, ", dying from");
338.  		if (u.usick_type & SICK_VOMITABLE)
339.  			Strcat(info, " food poisoning");
340.  		if (u.usick_type & SICK_NONVOMITABLE) {
341.  			if (u.usick_type & SICK_VOMITABLE)
342.  				Strcat(info, " and");
343.  			Strcat(info, " illness");
344.  		}
345.  	}
346.  	if (Stoned)		Strcat(info, ", solidifying");
347.  	if (Strangled)		Strcat(info, ", being strangled");
348.  	if (Vomiting)		Strcat(info, ", nauseated"); /* !"nauseous" */
349.  	if (Confusion)		Strcat(info, ", confused");
350.  	if (Blind) {
351.  	    Strcat(info, ", blind");
352.  	    if (u.ucreamed) {
353.  		if ((long)u.ucreamed < Blinded || Blindfolded
354.  						|| !haseyes(youmonst.data))
355.  		    Strcat(info, ", cover");
356.  		Strcat(info, "ed by sticky goop");
357.  	    }	/* note: "goop" == "glop"; variation is intentional */
358.  	}
359.  	if (Stunned)		Strcat(info, ", stunned");
360.  #ifdef STEED
361.  	if (!u.usteed)
362.  #endif
363.  	if (Wounded_legs) {
364.  	    const char *what = body_part(LEG);
365.  	    if ((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
366.  		what = makeplural(what);
367.  				Sprintf(eos(info), ", injured %s", what);
368.  	}
369.  	if (Glib)		Sprintf(eos(info), ", slippery %s",
370.  					makeplural(body_part(HAND)));
371.  	if (u.utrap)		Strcat(info, ", trapped");
372.  	if (Fast)		Strcat(info, (Fast & ~INTRINSIC) ?
373.  						", very fast" : ", fast");
374.  	if (u.uundetected)	Strcat(info, ", concealed");
375.  	if (Invis)		Strcat(info, ", invisible");
376.  	if (u.ustuck) {
377.  	    if (sticks(youmonst.data))
378.  		Strcat(info, ", holding ");
379.  	    else
380.  		Strcat(info, ", held by ");
381.  	    Strcat(info, mon_nam(u.ustuck));
382.  	}
383.  
384.  	pline("Status of %s (%s%s):  Level %d  HP %d(%d)  AC %d%s.",
385.  		plname,
386.  		    (u.ualign.record >= 20) ? "piously " :
387.  		    (u.ualign.record > 13) ? "devoutly " :
388.  		    (u.ualign.record > 8) ? "fervently " :
389.  		    (u.ualign.record > 3) ? "stridently " :
390.  		    (u.ualign.record == 3) ? "" :
391.  		    (u.ualign.record >= 1) ? "haltingly " :
392.  		    (u.ualign.record == 0) ? "nominally " :
393.  					    "insufficiently ",
394.  		align_str(u.ualign.type),
395.  		Upolyd ? mons[u.umonnum].mlevel : u.ulevel,
396.  		Upolyd ? u.mh : u.uhp,
397.  		Upolyd ? u.mhmax : u.uhpmax,
398.  		u.uac,
399.  		info);
400.  }
401.  
402.  void self_invis_message()
403.  {
404.  	pline("%s %s.",
405.  	    Hallucination ? "Far out, man!  You" : "Gee!  All of a sudden, you",
406.  	    See_invisible ? "can see right through yourself" :
407.  		"can't see yourself");
408.  }
409.  
410.  #endif /* OVLB */
411.  
412.  /*pline.c*/
Advertisement