Source:NetHack 3.4.3/src/pline.c

From NetHackWiki
(Redirected from Source:Ref/You buf)
Jump to: navigation, search

Below is the full text to src/pline.c from NetHack 3.4.3. To link to a particular line, write [[pline.c#line123]], for example.

Top of file

  1. /*	SCCS Id: @(#)pline.c	3.4	1999/11/28	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1. #define NEED_VARARGS /* Uses ... */	/* comment line for pre-compiled headers */
  2. #include "hack.h"
  3. #include "epri.h"
  4. #ifdef WIZARD
  5. #include "edog.h"
  6. #endif
  7.  
  8. #ifdef OVLB
  9.  
  10. static boolean no_repeat = FALSE;
  11.  
  12. static char *FDECL(You_buf, (int));
  13.  
  14. /*VARARGS1*/
  15. /* Note that these declarations rely on knowledge of the internals
  16. * of the variable argument handling stuff in "tradstdc.h"
  17. */
  18.  
  19. #if defined(USE_STDARG) || defined(USE_VARARGS)
  20. static void FDECL(vpline, (const char *, va_list));
  21.  
  22. void
  23. pline VA_DECL(const char *, line)
  24. 	VA_START(line);
  25. 	VA_INIT(line, char *);
  26. 	vpline(line, VA_ARGS);
  27. 	VA_END();
  28. }
  29.  
  30. # ifdef USE_STDARG
  31. static void
  32. vpline(const char *line, va_list the_args) {
  33. # else
  34. static void
  35. vpline(line, the_args) const char *line; va_list the_args; {
  36. # endif
  37.  
  38. #else	/* USE_STDARG | USE_VARARG */
  39.  
  40. #define vpline pline

pline

pline is the catch-all function that outputs text to the message area. Depending on the GUI used and how many messages there already are in the message area, NetHack may wait for player to press a key at a --more-- prompt before showing the message.

pline accepts a string constant and any number of additional values that replace placeholders marked with '%' in the string constant, just like printf does.

Example:

int count;
for (count = 1; count < 10; count++) {
  pline("%i", count);
}
pline("Hello, player!");
  1. void
  2. pline VA_DECL(const char *, line)
  3. #endif	/* USE_STDARG | USE_VARARG */
  4.  
  5. 	char pbuf[BUFSZ];
  6. /* Do NOT use VA_START and VA_END in here... see above */
  7.  
  8. 	if (!line || !*line) return;
  9. 	if (index(line, '%')) {
  10. 	    Vsprintf(pbuf,line,VA_ARGS);
  11. 	    line = pbuf;
  12. 	}
  13. 	if (!iflags.window_inited) {
  14. 	    raw_print(line);
  15. 	    return;
  16. 	}
  17. #ifndef MAC
  18. 	if (no_repeat && !strcmp(line, toplines))
  19. 	    return;
  20. #endif /* MAC */
  21. 	if (vision_full_recalc) vision_recalc(0);
  22. 	if (u.ux) flush_screen(1);		/* %% */
  23. 	putstr(WIN_MESSAGE, 0, line);
  24. }

Norep

Norep() is similar to pline(), but if the same message is repeated after another, it's not shown again.

Example:

int x;
for (x = 0; x < 100; x++) {
  Norep("Whee!");
}


  1. /*VARARGS1*/
  2. void
  3. Norep VA_DECL(const char *, line)
  4. 	VA_START(line);
  5. 	VA_INIT(line, const char *);
  6. 	no_repeat = TRUE;
  7. 	vpline(line, VA_ARGS);
  8. 	no_repeat = FALSE;
  9. 	VA_END();
  10. 	return;
  11. }

You_buf

  1. /* work buffer for You(), &c and verbalize() */
  2. static char *you_buf = 0;
  3. static int you_buf_siz = 0;
  4.  
  5. static char *
  6. You_buf(siz)
  7. int siz;
  8. {
  9. 	if (siz > you_buf_siz) {
  10. 		if (you_buf) free((genericptr_t) you_buf);
  11. 		you_buf_siz = siz + 10;
  12. 		you_buf = (char *) alloc((unsigned) you_buf_siz);
  13. 	}
  14. 	return you_buf;
  15. }

free_youbuf

  1. void
  2. free_youbuf()
  3. {
  4. 	if (you_buf) free((genericptr_t) you_buf),  you_buf = (char *)0;
  5. 	you_buf_siz = 0;
  6. }
  1. /* `prefix' must be a string literal, not a pointer */
  2. #define YouPrefix(pointer,prefix,text) \
  3. Strcpy((pointer = You_buf((int)(strlen(text) + sizeof prefix))), prefix)
  4.  
  5. #define YouMessage(pointer,prefix,text) \
  6. strcat((YouPrefix(pointer, prefix, text), pointer), text)

You

You() is similar to pline(), but the string is prefixed with "You "

Example:

You("succeed in opening the tin.");
  1. /*VARARGS1*/
  2. void
  3. You VA_DECL(const char *, line)
  4. 	char *tmp;
  5. 	VA_START(line);
  6. 	VA_INIT(line, const char *);
  7. 	vpline(YouMessage(tmp, "You ", line), VA_ARGS);
  8. 	VA_END();
  9. }

Your

Your() is similar to pline(), but the string is prefixed with "Your "

Example:

Your("wallet is empty.");
  1. /*VARARGS1*/
  2. void
  3. Your VA_DECL(const char *,line)
  4. 	char *tmp;
  5. 	VA_START(line);
  6. 	VA_INIT(line, const char *);
  7. 	vpline(YouMessage(tmp, "Your ", line), VA_ARGS);
  8. 	VA_END();
  9. }

You_feel

You_feel() is similar to pline(), but the string is prefixed with "You feel "

Example:

You_feel("much better!");
  1. /*VARARGS1*/
  2. void
  3. You_feel VA_DECL(const char *,line)
  4. 	char *tmp;
  5. 	VA_START(line);
  6. 	VA_INIT(line, const char *);
  7. 	vpline(YouMessage(tmp, "You feel ", line), VA_ARGS);
  8. 	VA_END();
  9. }

You_cant

You_cant() is similar to pline(), but the string is prefixed with "You can't "

Example:

You_cant("wear that!");
  1. /*VARARGS1*/
  2. void
  3. You_cant VA_DECL(const char *,line)
  4. 	char *tmp;
  5. 	VA_START(line);
  6. 	VA_INIT(line, const char *);
  7. 	vpline(YouMessage(tmp, "You can't ", line), VA_ARGS);
  8. 	VA_END();
  9. }

pline_The

pline_The() is similar to pline(), but the string is prefixed with "The "

Example:

pline_The("door resists!");
  1. /*VARARGS1*/
  2. void
  3. pline_The VA_DECL(const char *,line)
  4. 	char *tmp;
  5. 	VA_START(line);
  6. 	VA_INIT(line, const char *);
  7. 	vpline(YouMessage(tmp, "The ", line), VA_ARGS);
  8. 	VA_END();
  9. }

There

There() is similar to pline(), but the string is prefixed with "There "

Example:

There("are no seats in here!");
  1. /*VARARGS1*/
  2. void
  3. There VA_DECL(const char *,line)
  4. 	char *tmp;
  5. 	VA_START(line);
  6. 	VA_INIT(line, const char *);
  7. 	vpline(YouMessage(tmp, "There ", line), VA_ARGS);
  8. 	VA_END();
  9. }

You_hear

You_hear() is similar to pline(), but the string is prefixed with different things depeneding whether the hero is under water, asleep or awake.

Example:

You_hear("crashing rock.");
  1. /*VARARGS1*/
  2. void
  3. You_hear VA_DECL(const char *,line)
  4. 	char *tmp;
  5. 	VA_START(line);
  6. 	VA_INIT(line, const char *);
  7. 	if (Underwater)
  8. 		YouPrefix(tmp, "You barely hear ", line);
  9. 	else if (u.usleep)
  10. 		YouPrefix(tmp, "You dream that you hear ", line);
  11. 	else
  12. 		YouPrefix(tmp, "You hear ", line);
  13. 	vpline(strcat(tmp, line), VA_ARGS);
  14. 	VA_END();
  15. }

verbalize

verbalize() is similar to pline(), but the string is prefixed and suffixed with double quotes, making it seem as if something said it. If hero cannot hear, this outputs nothing.

Example:

verbalize("You freed me!");
  1. /*VARARGS1*/
  2. void
  3. verbalize VA_DECL(const char *,line)
  4. 	char *tmp;
  5. 	if (!flags.soundok) return;
  6. 	VA_START(line);
  7. 	VA_INIT(line, const char *);
  8. 	tmp = You_buf((int)strlen(line) + sizeof "\"\"");
  9. 	Strcpy(tmp, "\"");
  10. 	Strcat(tmp, line);
  11. 	Strcat(tmp, "\"");
  12. 	vpline(tmp, VA_ARGS);
  13. 	VA_END();
  14. }


raw_printf

raw_printf() is only used if the GUI isn't yet initialized, but we still need to tell the player something important. For example, config file errors are output with this. Accepts the same kind of variable parameters as pline().

  1. /*VARARGS1*/
  2. /* Note that these declarations rely on knowledge of the internals
  3. * of the variable argument handling stuff in "tradstdc.h"
  4. */
  5.  
  6. #if defined(USE_STDARG) || defined(USE_VARARGS)
  7. static void FDECL(vraw_printf,(const char *,va_list));
  8.  
  9. void
  10. raw_printf VA_DECL(const char *, line)
  11. 	VA_START(line);
  12. 	VA_INIT(line, char *);
  13. 	vraw_printf(line, VA_ARGS);
  14. 	VA_END();
  15. }
  16.  
  17. # ifdef USE_STDARG
  18. static void
  19. vraw_printf(const char *line, va_list the_args) {
  20. # else
  21. static void
  22. vraw_printf(line, the_args) const char *line; va_list the_args; {
  23. # endif
  24.  
  25. #else  /* USE_STDARG | USE_VARARG */
  26.  
  27. void
  28. raw_printf VA_DECL(const char *, line)
  29. #endif
  30. /* Do NOT use VA_START and VA_END in here... see above */
  31.  
  32. 	if(!index(line, '%'))
  33. 	    raw_print(line);
  34. 	else {
  35. 	    char pbuf[BUFSZ];
  36. 	    Vsprintf(pbuf,line,VA_ARGS);
  37. 	    raw_print(pbuf);
  38. 	}
  39. }

impossible

impossible() is used to tell the player that NetHack thinks something is wrong. This might or might not be bad enough that NetHack will crash. It accepts the same parameters as pline().

  1. /*VARARGS1*/
  2. void
  3. impossible VA_DECL(const char *, s)
  4. 	VA_START(s);
  5. 	VA_INIT(s, const char *);
  6. 	if (program_state.in_impossible)
  7. 		panic("impossible called impossible");
  8. 	program_state.in_impossible = 1;
  9. 	{
  10. 	    char pbuf[BUFSZ];
  11. 	    Vsprintf(pbuf,s,VA_ARGS);
  12. 	    paniclog("impossible", pbuf);
  13. 	}
  14. 	vpline(s,VA_ARGS);
  15. 	pline("Program in disorder - perhaps you'd better #quit.");
  16. 	program_state.in_impossible = 0;
  17. 	VA_END();
  18. }

align_str

align_str() takes one parameter, an alignment, and returns a string describing it.

  1. const char *
  2. align_str(alignment)
  3. aligntyp alignment;
  4. {
  5. switch ((int)alignment) {
  6. 	case A_CHAOTIC: return "chaotic";
  7. 	case A_NEUTRAL: return "neutral";
  8. 	case A_LAWFUL:	return "lawful";
  9. 	case A_NONE:	return "unaligned";
  10. }
  11. return "unknown";
  12. }

mstatusline

mstatusline() takes one parameter, a monster, and shows the player a short status of that monster. This is used when probing a monster.

  1. void
  2. mstatusline(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	aligntyp alignment;
  6. 	char info[BUFSZ], monnambuf[BUFSZ];
  7.  
  8. 	if (mtmp->ispriest || mtmp->data == &mons[PM_ALIGNED_PRIEST]
  9. 				|| mtmp->data == &mons[PM_ANGEL])
  10. 		alignment = EPRI(mtmp)->shralign;
  11. 	else
  12. 		alignment = mtmp->data->maligntyp;
  13. 	alignment = (alignment > 0) ? A_LAWFUL :
  14. 		(alignment < 0) ? A_CHAOTIC :
  15. 		A_NEUTRAL;
  16.  
  17. 	info[0] = 0;
  18. 	if (mtmp->mtame) {	  Strcat(info, ", tame");
  19. #ifdef WIZARD
  20. 	    if (wizard) {
  21. 		Sprintf(eos(info), " (%d", mtmp->mtame);
  22. 		if (!mtmp->isminion)
  23. 		    Sprintf(eos(info), "; hungry %ld; apport %d",
  24. 			EDOG(mtmp)->hungrytime, EDOG(mtmp)->apport);
  25. 		Strcat(info, ")");
  26. 	    }
  27. #endif
  28. 	}
  29. 	else if (mtmp->mpeaceful) Strcat(info, ", peaceful");
  30. 	if (mtmp->meating)	  Strcat(info, ", eating");
  31. 	if (mtmp->mcan)		  Strcat(info, ", cancelled");
  32. 	if (mtmp->mconf)	  Strcat(info, ", confused");
  33. 	if (mtmp->mblinded || !mtmp->mcansee)
  34. 				  Strcat(info, ", blind");
  35. 	if (mtmp->mstun)	  Strcat(info, ", stunned");
  36. 	if (mtmp->msleeping)	  Strcat(info, ", asleep");
  37. #if 0	/* unfortunately mfrozen covers temporary sleep and being busy
  38. 	   (donning armor, for instance) as well as paralysis */
  39. 	else if (mtmp->mfrozen)	  Strcat(info, ", paralyzed");
  40. #else
  41. 	else if (mtmp->mfrozen || !mtmp->mcanmove)
  42. 				  Strcat(info, ", can't move");
  43. #endif
  44. 				  /* [arbitrary reason why it isn't moving] */
  45. 	else if (mtmp->mstrategy & STRAT_WAITMASK)
  46. 				  Strcat(info, ", meditating");
  47. 	else if (mtmp->mflee)	  Strcat(info, ", scared");
  48. 	if (mtmp->mtrapped)	  Strcat(info, ", trapped");
  49. 	if (mtmp->mspeed)	  Strcat(info,
  50. 					mtmp->mspeed == MFAST ? ", fast" :
  51. 					mtmp->mspeed == MSLOW ? ", slow" :
  52. 					", ???? speed");
  53. 	if (mtmp->mundetected)	  Strcat(info, ", concealed");
  54. 	if (mtmp->minvis)	  Strcat(info, ", invisible");
  55. 	if (mtmp == u.ustuck)	  Strcat(info,
  56. 			(sticks(youmonst.data)) ? ", held by you" :
  57. 				u.uswallow ? (is_animal(u.ustuck->data) ?
  58. 				", swallowed you" :
  59. 				", engulfed you") :
  60. 				", holding you");
  61. #ifdef STEED
  62. 	if (mtmp == u.usteed)	  Strcat(info, ", carrying you");
  63. #endif
  64.  
  65. 	/* avoid "Status of the invisible newt ..., invisible" */
  66. 	/* and unlike a normal mon_nam, use "saddled" even if it has a name */
  67. 	Strcpy(monnambuf, x_monnam(mtmp, ARTICLE_THE, (char *)0,
  68. 	    (SUPPRESS_IT|SUPPRESS_INVISIBLE), FALSE));
  69.  
  70. 	pline("Status of %s (%s):  Level %d  HP %d(%d)  AC %d%s.",
  71. 		monnambuf,
  72. 		align_str(alignment),
  73. 		mtmp->m_lev,
  74. 		mtmp->mhp,
  75. 		mtmp->mhpmax,
  76. 		find_mac(mtmp),
  77. 		info);
  78. }

ustatusline

ustatusline() shows the player the hero's status as if he was probed.

  1. void
  2. ustatusline()
  3. {
  4. 	char info[BUFSZ];
  5.  
  6. 	info[0] = '\0';
  7. 	if (Sick) {
  8. 		Strcat(info, ", dying from");
  9. 		if (u.usick_type & SICK_VOMITABLE)
  10. 			Strcat(info, " food poisoning");
  11. 		if (u.usick_type & SICK_NONVOMITABLE) {
  12. 			if (u.usick_type & SICK_VOMITABLE)
  13. 				Strcat(info, " and");
  14. 			Strcat(info, " illness");
  15. 		}
  16. 	}
  17. 	if (Stoned)		Strcat(info, ", solidifying");
  18. 	if (Slimed)		Strcat(info, ", becoming slimy");
  19. 	if (Strangled)		Strcat(info, ", being strangled");
  20. 	if (Vomiting)		Strcat(info, ", nauseated"); /* !"nauseous" */
  21. 	if (Confusion)		Strcat(info, ", confused");
  22. 	if (Blind) {
  23. 	    Strcat(info, ", blind");
  24. 	    if (u.ucreamed) {
  25. 		if ((long)u.ucreamed < Blinded || Blindfolded
  26. 						|| !haseyes(youmonst.data))
  27. 		    Strcat(info, ", cover");
  28. 		Strcat(info, "ed by sticky goop");
  29. 	    }	/* note: "goop" == "glop"; variation is intentional */
  30. 	}
  31. 	if (Stunned)		Strcat(info, ", stunned");
  32. #ifdef STEED
  33. 	if (!u.usteed)
  34. #endif
  35. 	if (Wounded_legs) {
  36. 	    const char *what = body_part(LEG);
  37. 	    if ((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
  38. 		what = makeplural(what);
  39. 				Sprintf(eos(info), ", injured %s", what);
  40. 	}
  41. 	if (Glib)		Sprintf(eos(info), ", slippery %s",
  42. 					makeplural(body_part(HAND)));
  43. 	if (u.utrap)		Strcat(info, ", trapped");
  44. 	if (Fast)		Strcat(info, Very_fast ?
  45. 						", very fast" : ", fast");
  46. 	if (u.uundetected)	Strcat(info, ", concealed");
  47. 	if (Invis)		Strcat(info, ", invisible");
  48. 	if (u.ustuck) {
  49. 	    if (sticks(youmonst.data))
  50. 		Strcat(info, ", holding ");
  51. 	    else
  52. 		Strcat(info, ", held by ");
  53. 	    Strcat(info, mon_nam(u.ustuck));
  54. 	}
  55.  
  56. 	pline("Status of %s (%s%s):  Level %d  HP %d(%d)  AC %d%s.",
  57. 		plname,
  58. 		    (u.ualign.record >= 20) ? "piously " :
  59. 		    (u.ualign.record > 13) ? "devoutly " :
  60. 		    (u.ualign.record > 8) ? "fervently " :
  61. 		    (u.ualign.record > 3) ? "stridently " :
  62. 		    (u.ualign.record == 3) ? "" :
  63. 		    (u.ualign.record >= 1) ? "haltingly " :
  64. 		    (u.ualign.record == 0) ? "nominally " :
  65. 					    "insufficiently ",
  66. 		align_str(u.ualign.type),
  67. 		Upolyd ? mons[u.umonnum].mlevel : u.ulevel,
  68. 		Upolyd ? u.mh : u.uhp,
  69. 		Upolyd ? u.mhmax : u.uhpmax,
  70. 		u.uac,
  71. 		info);
  72. }

self_invis_message

self_invis_message() shows the player a message about the hero's invisibility; this should only be called if the hero just turned invisible.

  1. void
  2. self_invis_message()
  3. {
  4. 	pline("%s %s.",
  5. 	    Hallucination ? "Far out, man!  You" : "Gee!  All of a sudden, you",
  6. 	    See_invisible ? "can see right through yourself" :
  7. 		"can't see yourself");
  8. }
  9.  
  10. #endif /* OVLB */
  11. /*pline.c*/