Source:NetHack 3.4.3/src/pager.c

From NetHackWiki
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)pager.c	3.4	2003/08/13	*/
  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. /* This file contains the command routines dowhatis() and dohelp() and */
  2. /* a few other help related facilities */
  3.  
  4. #include "hack.h"
  5. #include "dlb.h"
  6.  
  7. STATIC_DCL boolean FDECL(is_swallow_sym, (int));
  8. STATIC_DCL int FDECL(append_str, (char *, const char *));
  9. STATIC_DCL struct permonst * FDECL(lookat, (int, int, char *, char *));
  10. STATIC_DCL void FDECL(checkfile,
  11. 		      (char *,struct permonst *,BOOLEAN_P,BOOLEAN_P));
  12. STATIC_DCL int FDECL(do_look, (BOOLEAN_P));
  13. STATIC_DCL boolean FDECL(help_menu, (int *));
  14. #ifdef PORT_HELP
  15. extern void NDECL(port_help);
  16. #endif

is_swallow_sym[edit]

  1. /* Returns "true" for characters that could represent a monster's stomach. */
  2. STATIC_OVL boolean
  3. is_swallow_sym(c)
  4. int c;
  5. {
  6. int i;
  7. for (i = S_sw_tl; i <= S_sw_br; i++)
  8. 	if ((int)showsyms[i] == c) return TRUE;
  9. return FALSE;
  10. }

append_str[edit]

  1. /*
  2. * Append new_str to the end of buf if new_str doesn't already exist as
  3. * a substring of buf.  Return 1 if the string was appended, 0 otherwise.
  4. * It is expected that buf is of size BUFSZ.
  5. */
  6. STATIC_OVL int
  7. append_str(buf, new_str)
  8. char *buf;
  9. const char *new_str;
  10. {
  11. int space_left;	/* space remaining in buf */
  12.  
  13. if (strstri(buf, new_str)) return 0;
  14.  
  15. space_left = BUFSZ - strlen(buf) - 1;
  16. (void) strncat(buf, " or ", space_left);
  17. (void) strncat(buf, new_str, space_left - 4);
  18. return 1;
  19. }

lookat[edit]

  1. /*
  2. * Return the name of the glyph found at (x,y).
  3. * If not hallucinating and the glyph is a monster, also monster data.
  4. */
  5. STATIC_OVL struct permonst *
  6. lookat(x, y, buf, monbuf)
  7. int x, y;
  8. char *buf, *monbuf;
  9. {
  10. register struct monst *mtmp = (struct monst *) 0;
  11. struct permonst *pm = (struct permonst *) 0;
  12. int glyph;
  13.  
  14. buf[0] = monbuf[0] = 0;
  15. glyph = glyph_at(x,y);
  16. if (u.ux == x && u.uy == y && senseself()) {
  17. 	char race[QBUFSZ];
  18.  
  19. 	/* if not polymorphed, show both the role and the race */
  20. 	race[0] = 0;
  21. 	if (!Upolyd) {
  22. 	    Sprintf(race, "%s ", urace.adj);
  23. 	}
  24.  
  25. 	Sprintf(buf, "%s%s%s called %s",
  26. 		Invis ? "invisible " : "",
  27. 		race,
  28. 		mons[u.umonnum].mname,
  29. 		plname);
  30. 	/* file lookup can't distinguish between "gnomish wizard" monster
  31. 	   and correspondingly named player character, always picking the
  32. 	   former; force it to find the general "wizard" entry instead */
  33. 	if (Role_if(PM_WIZARD) && Race_if(PM_GNOME) && !Upolyd)
  34. 	    pm = &mons[PM_WIZARD];
  35.  
  36. #ifdef STEED
  37. 	if (u.usteed) {
  38. 	    char steedbuf[BUFSZ];
  39.  
  40. 	    Sprintf(steedbuf, ", mounted on %s", y_monnam(u.usteed));
  41. 	    /* assert((sizeof buf >= strlen(buf)+strlen(steedbuf)+1); */
  42. 	    Strcat(buf, steedbuf);
  43. 	}
  44. #endif
  45. 	/* When you see yourself normally, no explanation is appended
  46. 	   (even if you could also see yourself via other means).
  47. 	   Sensing self while blind or swallowed is treated as if it
  48. 	   were by normal vision (cf canseeself()). */
  49. 	if ((Invisible || u.uundetected) && !Blind && !u.uswallow) {
  50. 	    unsigned how = 0;
  51.  
  52. 	    if (Infravision)	 how |= 1;
  53. 	    if (Unblind_telepat) how |= 2;
  54. 	    if (Detect_monsters) how |= 4;
  55.  
  56. 	    if (how)
  57. 		Sprintf(eos(buf), " [seen: %s%s%s%s%s]",
  58. 			(how & 1) ? "infravision" : "",
  59. 			/* add comma if telep and infrav */
  60. 			((how & 3) > 2) ? ", " : "",
  61. 			(how & 2) ? "telepathy" : "",
  62. 			/* add comma if detect and (infrav or telep or both) */
  63. 			((how & 7) > 4) ? ", " : "",
  64. 			(how & 4) ? "monster detection" : "");
  65. 	}
  66. } else if (u.uswallow) {
  67. 	/* all locations when swallowed other than the hero are the monster */
  68. 	Sprintf(buf, "interior of %s",
  69. 				    Blind ? "a monster" : a_monnam(u.ustuck));
  70. 	pm = u.ustuck->data;
  71. } else if (glyph_is_monster(glyph)) {
  72. 	bhitpos.x = x;
  73. 	bhitpos.y = y;
  74. 	mtmp = m_at(x,y);
  75. 	if (mtmp != (struct monst *) 0) {
  76. 	    char *name, monnambuf[BUFSZ];
  77. 	    boolean accurate = !Hallucination;
  78.  
  79. 	    if (mtmp->data == &mons[PM_COYOTE] && accurate)
  80. 		name = coyotename(mtmp, monnambuf);
  81. 	    else
  82. 		name = distant_monnam(mtmp, ARTICLE_NONE, monnambuf);
  83.  
  84. 	    pm = mtmp->data;
  85. 	    Sprintf(buf, "%s%s%s",
  86. 		    (mtmp->mx != x || mtmp->my != y) ?
  87. 			((mtmp->isshk && accurate)
  88. 				? "tail of " : "tail of a ") : "",
  89. 		    (mtmp->mtame && accurate) ? "tame " :
  90. 		    (mtmp->mpeaceful && accurate) ? "peaceful " : "",
  91. 		    name);
  92. 	    if (u.ustuck == mtmp)
  93. 		Strcat(buf, (Upolyd && sticks(youmonst.data)) ?
  94. 			", being held" : ", holding you");
  95. 	    if (mtmp->mleashed)
  96. 		Strcat(buf, ", leashed to you");
  97.  
  98. 	    if (mtmp->mtrapped && cansee(mtmp->mx, mtmp->my)) {
  99. 		struct trap *t = t_at(mtmp->mx, mtmp->my);
  100. 		int tt = t ? t->ttyp : NO_TRAP;
  101.  
  102. 		/* newsym lets you know of the trap, so mention it here */
  103. 		if (tt == BEAR_TRAP || tt == PIT ||
  104. 			tt == SPIKED_PIT || tt == WEB)
  105. 		    Sprintf(eos(buf), ", trapped in %s",
  106. 			    an(defsyms[trap_to_defsym(tt)].explanation));
  107. 	    }
  108.  
  109. 	    {
  110. 		int ways_seen = 0, normal = 0, xraydist;
  111. 		boolean useemon = (boolean) canseemon(mtmp);
  112.  
  113. 		xraydist = (u.xray_range<0) ? -1 : u.xray_range * u.xray_range;
  114. 		/* normal vision */
  115. 		if ((mtmp->wormno ? worm_known(mtmp) : cansee(mtmp->mx, mtmp->my)) &&
  116. 			mon_visible(mtmp) && !mtmp->minvis) {
  117. 		    ways_seen++;
  118. 		    normal++;
  119. 		}
  120. 		/* see invisible */
  121. 		if (useemon && mtmp->minvis)
  122. 		    ways_seen++;
  123. 		/* infravision */
  124. 		if ((!mtmp->minvis || See_invisible) && see_with_infrared(mtmp))
  125. 		    ways_seen++;
  126. 		/* telepathy */
  127. 		if (tp_sensemon(mtmp))
  128. 		    ways_seen++;
  129. 		/* xray */
  130. 		if (useemon && xraydist > 0 &&
  131. 			distu(mtmp->mx, mtmp->my) <= xraydist)
  132. 		    ways_seen++;
  133. 		if (Detect_monsters)
  134. 		    ways_seen++;
  135. 		if (MATCH_WARN_OF_MON(mtmp))
  136. 		    ways_seen++;
  137.  
  138. 		if (ways_seen > 1 || !normal) {
  139. 		    if (normal) {
  140. 			Strcat(monbuf, "normal vision");
  141. 			/* can't actually be 1 yet here */
  142. 			if (ways_seen-- > 1) Strcat(monbuf, ", ");
  143. 		    }
  144. 		    if (useemon && mtmp->minvis) {
  145. 			Strcat(monbuf, "see invisible");
  146. 			if (ways_seen-- > 1) Strcat(monbuf, ", ");
  147. 		    }
  148. 		    if ((!mtmp->minvis || See_invisible) &&
  149. 			    see_with_infrared(mtmp)) {
  150. 			Strcat(monbuf, "infravision");
  151. 			if (ways_seen-- > 1) Strcat(monbuf, ", ");
  152. 		    }
  153. 		    if (tp_sensemon(mtmp)) {
  154. 			Strcat(monbuf, "telepathy");
  155. 			if (ways_seen-- > 1) Strcat(monbuf, ", ");
  156. 		    }
  157. 		    if (useemon && xraydist > 0 &&
  158. 			    distu(mtmp->mx, mtmp->my) <= xraydist) {
  159. 			/* Eyes of the Overworld */
  160. 			Strcat(monbuf, "astral vision");
  161. 			if (ways_seen-- > 1) Strcat(monbuf, ", ");
  162. 		    }
  163. 		    if (Detect_monsters) {
  164. 			Strcat(monbuf, "monster detection");
  165. 			if (ways_seen-- > 1) Strcat(monbuf, ", ");
  166. 		    }
  167. 		    if (MATCH_WARN_OF_MON(mtmp)) {
  168. 		    	char wbuf[BUFSZ];
  169. 			if (Hallucination)
  170. 				Strcat(monbuf, "paranoid delusion");
  171. 			else {
  172. 				Sprintf(wbuf, "warned of %s",
  173. 					makeplural(mtmp->data->mname));
  174. 		    		Strcat(monbuf, wbuf);
  175. 		    	}
  176. 		    	if (ways_seen-- > 1) Strcat(monbuf, ", ");
  177. 		    }
  178. 		}
  179. 	    }
  180. 	}
  181. }
  182. else if (glyph_is_object(glyph)) {
  183. 	struct obj *otmp = vobj_at(x,y);
  184.  
  185. 	if (!otmp || otmp->otyp != glyph_to_obj(glyph)) {
  186. 	    if (glyph_to_obj(glyph) != STRANGE_OBJECT) {
  187. 		otmp = mksobj(glyph_to_obj(glyph), FALSE, FALSE);
  188. 		if (otmp->oclass == COIN_CLASS)
  189. 		    otmp->quan = 2L; /* to force pluralization */
  190. 		else if (otmp->otyp == SLIME_MOLD)
  191. 		    otmp->spe = current_fruit;	/* give the fruit a type */
  192. 		Strcpy(buf, distant_name(otmp, xname));
  193. 		dealloc_obj(otmp);
  194. 	    }
  195. 	} else
  196. 	    Strcpy(buf, distant_name(otmp, xname));
  197.  
  198. 	if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR)
  199. 	    Strcat(buf, " embedded in stone");
  200. 	else if (IS_WALL(levl[x][y].typ) || levl[x][y].typ == SDOOR)
  201. 	    Strcat(buf, " embedded in a wall");
  202. 	else if (closed_door(x,y))
  203. 	    Strcat(buf, " embedded in a door");
  204. 	else if (is_pool(x,y))
  205. 	    Strcat(buf, " in water");
  206. 	else if (is_lava(x,y))
  207. 	    Strcat(buf, " in molten lava");	/* [can this ever happen?] */
  208. } else if (glyph_is_trap(glyph)) {
  209. 	int tnum = what_trap(glyph_to_trap(glyph));
  210. 	Strcpy(buf, defsyms[trap_to_defsym(tnum)].explanation);
  211. } else if(!glyph_is_cmap(glyph)) {
  212. 	Strcpy(buf,"dark part of a room");
  213. } else switch(glyph_to_cmap(glyph)) {
  214. case S_altar:
  215. 	if(!In_endgame(&u.uz))
  216. 	    Sprintf(buf, "%s altar",
  217. 		align_str(Amask2align(levl[x][y].altarmask & ~AM_SHRINE)));
  218. 	else Sprintf(buf, "aligned altar");
  219. 	break;
  220. case S_ndoor:
  221. 	if (is_drawbridge_wall(x, y) >= 0)
  222. 	    Strcpy(buf,"open drawbridge portcullis");
  223. 	else if ((levl[x][y].doormask & ~D_TRAPPED) == D_BROKEN)
  224. 	    Strcpy(buf,"broken door");
  225. 	else
  226. 	    Strcpy(buf,"doorway");
  227. 	break;
  228. case S_cloud:
  229. 	Strcpy(buf, Is_airlevel(&u.uz) ? "cloudy area" : "fog/vapor cloud");
  230. 	break;
  231. default:
  232. 	Strcpy(buf,defsyms[glyph_to_cmap(glyph)].explanation);
  233. 	break;
  234. }
  235.  
  236. return ((pm && !Hallucination) ? pm : (struct permonst *) 0);
  237. }

checkfile[edit]

  1. /*
  2. * Look in the "data" file for more info.  Called if the user typed in the
  3. * whole name (user_typed_name == TRUE), or we've found a possible match
  4. * with a character/glyph and flags.help is TRUE.
  5. *
  6. * NOTE: when (user_typed_name == FALSE), inp is considered read-only and
  7. *	 must not be changed directly, e.g. via lcase(). We want to force
  8. *	 lcase() for data.base lookup so that we can have a clean key.
  9. *	 Therefore, we create a copy of inp _just_ for data.base lookup.
  10. */
  11. STATIC_OVL void
  12. checkfile(inp, pm, user_typed_name, without_asking)
  13. char *inp;
  14. struct permonst *pm;
  15. boolean user_typed_name, without_asking;
  16. {
  17. dlb *fp;
  18. char buf[BUFSZ], newstr[BUFSZ];
  19. char *ep, *dbase_str;
  20. long txt_offset;
  21. int chk_skip;
  22. boolean found_in_file = FALSE, skipping_entry = FALSE;
  23.  
  24. fp = dlb_fopen(DATAFILE, "r");
  25. if (!fp) {
  26. 	pline("Cannot open data file!");
  27. 	return;
  28. }
  29.  
  30. /* To prevent the need for entries in data.base like *ngel to account
  31. * for Angel and angel, make the lookup string the same for both
  32. * user_typed_name and picked name.
  33. */
  34. if (pm != (struct permonst *) 0 && !user_typed_name)
  35. 	dbase_str = strcpy(newstr, pm->mname);
  36. else dbase_str = strcpy(newstr, inp);
  37. (void) lcase(dbase_str);
  38.  
  39. if (!strncmp(dbase_str, "interior of ", 12))
  40. 	dbase_str += 12;
  41. if (!strncmp(dbase_str, "a ", 2))
  42. 	dbase_str += 2;
  43. else if (!strncmp(dbase_str, "an ", 3))
  44. 	dbase_str += 3;
  45. else if (!strncmp(dbase_str, "the ", 4))
  46. 	dbase_str += 4;
  47. if (!strncmp(dbase_str, "tame ", 5))
  48. 	dbase_str += 5;
  49. else if (!strncmp(dbase_str, "peaceful ", 9))
  50. 	dbase_str += 9;
  51. if (!strncmp(dbase_str, "invisible ", 10))
  52. 	dbase_str += 10;
  53. if (!strncmp(dbase_str, "statue of ", 10))
  54. 	dbase_str[6] = '\0';
  55. else if (!strncmp(dbase_str, "figurine of ", 12))
  56. 	dbase_str[8] = '\0';
  57.  
  58. /* Make sure the name is non-empty. */
  59. if (*dbase_str) {
  60. 	/* adjust the input to remove "named " and convert to lower case */
  61. 	char *alt = 0;	/* alternate description */
  62.  
  63. 	if ((ep = strstri(dbase_str, " named ")) != 0)
  64. 	    alt = ep + 7;
  65. 	else
  66. 	    ep = strstri(dbase_str, " called ");
  67. 	if (!ep) ep = strstri(dbase_str, ", ");
  68. 	if (ep && ep > dbase_str) *ep = '\0';
  69.  
  70. 	/*
  71. 	 * If the object is named, then the name is the alternate description;
  72. 	 * otherwise, the result of makesingular() applied to the name is. This
  73. 	 * isn't strictly optimal, but named objects of interest to the user
  74. 	 * will usually be found under their name, rather than under their
  75. 	 * object type, so looking for a singular form is pointless.
  76. 	 */
  77.  
  78. 	if (!alt)
  79. 	    alt = makesingular(dbase_str);
  80. 	else
  81. 	    if (user_typed_name)
  82. 		(void) lcase(alt);
  83.  
  84. 	/* skip first record; read second */
  85. 	txt_offset = 0L;
  86. 	if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) {
  87. 	    impossible("can't read 'data' file");
  88. 	    (void) dlb_fclose(fp);
  89. 	    return;
  90. 	} else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 || txt_offset <= 0)
  91. 	    goto bad_data_file;
  92.  
  93. 	/* look for the appropriate entry */
  94. 	while (dlb_fgets(buf,BUFSZ,fp)) {
  95. 	    if (*buf == '.') break;  /* we passed last entry without success */
  96.  
  97. 	    if (digit(*buf)) {
  98. 		/* a number indicates the end of current entry */
  99. 		skipping_entry = FALSE;
  100. 	    } else if (!skipping_entry) {
  101. 		if (!(ep = index(buf, '\n'))) goto bad_data_file;
  102. 		*ep = 0;
  103. 		/* if we match a key that begins with "~", skip this entry */
  104. 		chk_skip = (*buf == '~') ? 1 : 0;
  105. 		if (pmatch(&buf[chk_skip], dbase_str) ||
  106. 			(alt && pmatch(&buf[chk_skip], alt))) {
  107. 		    if (chk_skip) {
  108. 			skipping_entry = TRUE;
  109. 			continue;
  110. 		    } else {
  111. 			found_in_file = TRUE;
  112. 			break;
  113. 		    }
  114. 		}
  115. 	    }
  116. 	}
  117. }
  118.  
  119. if(found_in_file) {
  120. 	long entry_offset;
  121. 	int  entry_count;
  122. 	int  i;
  123.  
  124. 	/* skip over other possible matches for the info */
  125. 	do {
  126. 	    if (!dlb_fgets(buf, BUFSZ, fp)) goto bad_data_file;
  127. 	} while (!digit(*buf));
  128. 	if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2) {
  129. bad_data_file:	impossible("'data' file in wrong format");
  130. 		(void) dlb_fclose(fp);
  131. 		return;
  132. 	}
  133.  
  134. 	if (user_typed_name || without_asking || yn("More info?") == 'y') {
  135. 	    winid datawin;
  136.  
  137. 	    if (dlb_fseek(fp, txt_offset + entry_offset, SEEK_SET) < 0) {
  138. 		pline("? Seek error on 'data' file!");
  139. 		(void) dlb_fclose(fp);
  140. 		return;
  141. 	    }
  142. 	    datawin = create_nhwindow(NHW_MENU);
  143. 	    for (i = 0; i < entry_count; i++) {
  144. 		if (!dlb_fgets(buf, BUFSZ, fp)) goto bad_data_file;
  145. 		if ((ep = index(buf, '\n')) != 0) *ep = 0;
  146. 		if (index(buf+1, '\t') != 0) (void) tabexpand(buf+1);
  147. 		putstr(datawin, 0, buf+1);
  148. 	    }
  149. 	    display_nhwindow(datawin, FALSE);
  150. 	    destroy_nhwindow(datawin);
  151. 	}
  152. } else if (user_typed_name)
  153. 	pline("I don't have any information on those things.");
  154.  
  155. (void) dlb_fclose(fp);
  156. }

do_look[edit]

  1. /* getpos() return values */
  2. #define LOOK_TRADITIONAL	0	/* '.' -- ask about "more info?" */
  3. #define LOOK_QUICK		1	/* ',' -- skip "more info?" */
  4. #define LOOK_ONCE		2	/* ';' -- skip and stop looping */
  5. #define LOOK_VERBOSE		3	/* ':' -- show more info w/o asking */
  6.  
  7. /* also used by getpos hack in do_name.c */
  8. const char what_is_an_unknown_object[] = "an unknown object";
  9.  
  10. STATIC_OVL int
  11. do_look(quick)
  12. boolean quick;	/* use cursor && don't search for "more info" */
  13. {
  14. char    out_str[BUFSZ], look_buf[BUFSZ];
  15. const char *x_str, *firstmatch = 0;
  16. struct permonst *pm = 0;
  17. int     i, ans = 0;
  18. int     sym;		/* typed symbol or converted glyph */
  19. int	    found;		/* count of matching syms found */
  20. coord   cc;			/* screen pos of unknown glyph */
  21. boolean save_verbose;	/* saved value of flags.verbose */
  22. boolean from_screen;	/* question from the screen */
  23. boolean need_to_look;	/* need to get explan. from glyph */
  24. boolean hit_trap;		/* true if found trap explanation */
  25. int skipped_venom;		/* non-zero if we ignored "splash of venom" */
  26. static const char *mon_interior = "the interior of a monster";
  27.  
  28. if (quick) {
  29. 	from_screen = TRUE;	/* yes, we want to use the cursor */
  30. } else {
  31. 	i = ynq("Specify unknown object by cursor?");
  32. 	if (i == 'q') return 0;
  33. 	from_screen = (i == 'y');
  34. }
  35.  
  36. if (from_screen) {
  37. 	cc.x = u.ux;
  38. 	cc.y = u.uy;
  39. 	sym = 0;		/* gcc -Wall lint */
  40. } else {
  41. 	getlin("Specify what? (type the word)", out_str);
  42. 	if (out_str[0] == '\0' || out_str[0] == '\033')
  43. 	    return 0;
  44.  
  45. 	if (out_str[1]) {	/* user typed in a complete string */
  46. 	    checkfile(out_str, pm, TRUE, TRUE);
  47. 	    return 0;
  48. 	}
  49. 	sym = out_str[0];
  50. }
  51.  
  52. /* Save the verbose flag, we change it later. */
  53. save_verbose = flags.verbose;
  54. flags.verbose = flags.verbose && !quick;
  55. /*
  56. * The user typed one letter, or we're identifying from the screen.
  57. */
  58. do {
  59. 	/* Reset some variables. */
  60. 	need_to_look = FALSE;
  61. 	pm = (struct permonst *)0;
  62. 	skipped_venom = 0;
  63. 	found = 0;
  64. 	out_str[0] = '\0';
  65.  
  66. 	if (from_screen) {
  67. 	    int glyph;	/* glyph at selected position */
  68.  
  69. 	    if (flags.verbose)
  70. 		pline("Please move the cursor to %s.",
  71. 		       what_is_an_unknown_object);
  72. 	    else
  73. 		pline("Pick an object.");
  74.  
  75. 	    ans = getpos(&cc, quick, what_is_an_unknown_object);
  76. 	    if (ans < 0 || cc.x < 0) {
  77. 		flags.verbose = save_verbose;
  78. 		return 0;	/* done */
  79. 	    }
  80. 	    flags.verbose = FALSE;	/* only print long question once */
  81.  
  82. 	    /* Convert the glyph at the selected position to a symbol. */
  83. 	    glyph = glyph_at(cc.x,cc.y);
  84. 	    if (glyph_is_cmap(glyph)) {
  85. 		sym = showsyms[glyph_to_cmap(glyph)];
  86. 	    } else if (glyph_is_trap(glyph)) {
  87. 		sym = showsyms[trap_to_defsym(glyph_to_trap(glyph))];
  88. 	    } else if (glyph_is_object(glyph)) {
  89. 		sym = oc_syms[(int)objects[glyph_to_obj(glyph)].oc_class];
  90. 		if (sym == '`' && iflags.bouldersym && (int)glyph_to_obj(glyph) == BOULDER)
  91. 			sym = iflags.bouldersym;
  92. 	    } else if (glyph_is_monster(glyph)) {
  93. 		/* takes care of pets, detected, ridden, and regular mons */
  94. 		sym = monsyms[(int)mons[glyph_to_mon(glyph)].mlet];
  95. 	    } else if (glyph_is_swallow(glyph)) {
  96. 		sym = showsyms[glyph_to_swallow(glyph)+S_sw_tl];
  97. 	    } else if (glyph_is_invisible(glyph)) {
  98. 		sym = DEF_INVISIBLE;
  99. 	    } else if (glyph_is_warning(glyph)) {
  100. 		sym = glyph_to_warning(glyph);
  101. 	    	sym = warnsyms[sym];
  102. 	    } else {
  103. 		impossible("do_look:  bad glyph %d at (%d,%d)",
  104. 						glyph, (int)cc.x, (int)cc.y);
  105. 		sym = ' ';
  106. 	    }
  107. 	}
  108.  
  109. 	/*
  110. 	 * Check all the possibilities, saving all explanations in a buffer.
  111. 	 * When all have been checked then the string is printed.
  112. 	 */
  113.  
  114. 	/* Check for monsters */
  115. 	for (i = 0; i < MAXMCLASSES; i++) {
  116. 	    if (sym == (from_screen ? monsyms[i] : def_monsyms[i]) &&
  117. 		monexplain[i]) {
  118. 		need_to_look = TRUE;
  119. 		if (!found) {
  120. 		    Sprintf(out_str, "%c       %s", sym, an(monexplain[i]));
  121. 		    firstmatch = monexplain[i];
  122. 		    found++;
  123. 		} else {
  124. 		    found += append_str(out_str, an(monexplain[i]));
  125. 		}
  126. 	    }
  127. 	}
  128. 	/* handle '@' as a special case if it refers to you and you're
  129. 	   playing a character which isn't normally displayed by that
  130. 	   symbol; firstmatch is assumed to already be set for '@' */
  131. 	if ((from_screen ?
  132. 		(sym == monsyms[S_HUMAN] && cc.x == u.ux && cc.y == u.uy) :
  133. 		(sym == def_monsyms[S_HUMAN] && !iflags.showrace)) &&
  134. 	    !(Race_if(PM_HUMAN) || Race_if(PM_ELF)) && !Upolyd)
  135. 	    found += append_str(out_str, "you");	/* tack on "or you" */
  136.  
  137. 	/*
  138. 	 * Special case: if identifying from the screen, and we're swallowed,
  139. 	 * and looking at something other than our own symbol, then just say
  140. 	 * "the interior of a monster".
  141. 	 */
  142. 	if (u.uswallow && from_screen && is_swallow_sym(sym)) {
  143. 	    if (!found) {
  144. 		Sprintf(out_str, "%c       %s", sym, mon_interior);
  145. 		firstmatch = mon_interior;
  146. 	    } else {
  147. 		found += append_str(out_str, mon_interior);
  148. 	    }
  149. 	    need_to_look = TRUE;
  150. 	}
  151.  
  152. 	/* Now check for objects */
  153. 	for (i = 1; i < MAXOCLASSES; i++) {
  154. 	    if (sym == (from_screen ? oc_syms[i] : def_oc_syms[i])) {
  155. 		need_to_look = TRUE;
  156. 		if (from_screen && i == VENOM_CLASS) {
  157. 		    skipped_venom++;
  158. 		    continue;
  159. 		}
  160. 		if (!found) {
  161. 		    Sprintf(out_str, "%c       %s", sym, an(objexplain[i]));
  162. 		    firstmatch = objexplain[i];
  163. 		    found++;
  164. 		} else {
  165. 		    found += append_str(out_str, an(objexplain[i]));
  166. 		}
  167. 	    }
  168. 	}
  169.  
  170. 	if (sym == DEF_INVISIBLE) {
  171. 	    if (!found) {
  172. 		Sprintf(out_str, "%c       %s", sym, an(invisexplain));
  173. 		firstmatch = invisexplain;
  174. 		found++;
  175. 	    } else {
  176. 		found += append_str(out_str, an(invisexplain));
  177. 	    }
  178. 	}
  179.  
  180. #define is_cmap_trap(i) ((i) >= S_arrow_trap && (i) <= S_polymorph_trap)
  181. #define is_cmap_drawbridge(i) ((i) >= S_vodbridge && (i) <= S_hcdbridge)
  182.  
  183. 	/* Now check for graphics symbols */
  184. 	for (hit_trap = FALSE, i = 0; i < MAXPCHARS; i++) {
  185. 	    x_str = defsyms[i].explanation;
  186. 	    if (sym == (from_screen ? showsyms[i] : defsyms[i].sym) && *x_str) {
  187. 		/* avoid "an air", "a water", or "a floor of a room" */
  188. 		int article = (i == S_room) ? 2 :		/* 2=>"the" */
  189. 			      !(strcmp(x_str, "air") == 0 ||	/* 1=>"an"  */
  190. 				strcmp(x_str, "water") == 0);	/* 0=>(none)*/
  191.  
  192. 		if (!found) {
  193. 		    if (is_cmap_trap(i)) {
  194. 			Sprintf(out_str, "%c       a trap", sym);
  195. 			hit_trap = TRUE;
  196. 		    } else {
  197. 			Sprintf(out_str, "%c       %s", sym,
  198. 				article == 2 ? the(x_str) :
  199. 				article == 1 ? an(x_str) : x_str);
  200. 		    }
  201. 		    firstmatch = x_str;
  202. 		    found++;
  203. 		} else if (!u.uswallow && !(hit_trap && is_cmap_trap(i)) &&
  204. 			   !(found >= 3 && is_cmap_drawbridge(i))) {
  205. 		    found += append_str(out_str,
  206. 					article == 2 ? the(x_str) :
  207. 					article == 1 ? an(x_str) : x_str);
  208. 		    if (is_cmap_trap(i)) hit_trap = TRUE;
  209. 		}
  210.  
  211. 		if (i == S_altar || is_cmap_trap(i))
  212. 		    need_to_look = TRUE;
  213. 	    }
  214. 	}
  215.  
  216. 	/* Now check for warning symbols */
  217. 	for (i = 1; i < WARNCOUNT; i++) {
  218. 	    x_str = def_warnsyms[i].explanation;
  219. 	    if (sym == (from_screen ? warnsyms[i] : def_warnsyms[i].sym)) {
  220. 		if (!found) {
  221. 			Sprintf(out_str, "%c       %s",
  222. 				sym, def_warnsyms[i].explanation);
  223. 			firstmatch = def_warnsyms[i].explanation;
  224. 			found++;
  225. 		} else {
  226. 			found += append_str(out_str, def_warnsyms[i].explanation);
  227. 		}
  228. 		/* Kludge: warning trumps boulders on the display.
  229. 		   Reveal the boulder too or player can get confused */
  230. 		if (from_screen && sobj_at(BOULDER, cc.x, cc.y))
  231. 			Strcat(out_str, " co-located with a boulder");
  232. 		break;	/* out of for loop*/
  233. 	    }
  234. 	}
  235.  
  236. 	/* if we ignored venom and list turned out to be short, put it back */
  237. 	if (skipped_venom && found < 2) {
  238. 	    x_str = objexplain[VENOM_CLASS];
  239. 	    if (!found) {
  240. 		Sprintf(out_str, "%c       %s", sym, an(x_str));
  241. 		firstmatch = x_str;
  242. 		found++;
  243. 	    } else {
  244. 		found += append_str(out_str, an(x_str));
  245. 	    }
  246. 	}
  247.  
  248. 	/* handle optional boulder symbol as a special case */ 
  249. 	if (iflags.bouldersym && sym == iflags.bouldersym) {
  250. 	    if (!found) {
  251. 		firstmatch = "boulder";
  252. 		Sprintf(out_str, "%c       %s", sym, an(firstmatch));
  253. 		found++;
  254. 	    } else {
  255. 		found += append_str(out_str, "boulder");
  256. 	    }
  257. 	}
  258.  
  259. 	/*
  260. 	 * If we are looking at the screen, follow multiple possibilities or
  261. 	 * an ambiguous explanation by something more detailed.
  262. 	 */
  263. 	if (from_screen) {
  264. 	    if (found > 1 || need_to_look) {
  265. 		char monbuf[BUFSZ];
  266. 		char temp_buf[BUFSZ];
  267.  
  268. 		pm = lookat(cc.x, cc.y, look_buf, monbuf);
  269. 		firstmatch = look_buf;
  270. 		if (*firstmatch) {
  271. 		    Sprintf(temp_buf, " (%s)", firstmatch);
  272. 		    (void)strncat(out_str, temp_buf, BUFSZ-strlen(out_str)-1);
  273. 		    found = 1;	/* we have something to look up */
  274. 		}
  275. 		if (monbuf[0]) {
  276. 		    Sprintf(temp_buf, " [seen: %s]", monbuf);
  277. 		    (void)strncat(out_str, temp_buf, BUFSZ-strlen(out_str)-1);
  278. 		}
  279. 	    }
  280. 	}
  281.  
  282. 	/* Finally, print out our explanation. */
  283. 	if (found) {
  284. 	    pline("%s", out_str);
  285. 	    /* check the data file for information about this thing */
  286. 	    if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE &&
  287. 			(ans == LOOK_VERBOSE || (flags.help && !quick))) {
  288. 		char temp_buf[BUFSZ];
  289. 		Strcpy(temp_buf, firstmatch);
  290. 		checkfile(temp_buf, pm, FALSE, (boolean)(ans == LOOK_VERBOSE));
  291. 	    }
  292. 	} else {
  293. 	    pline("I've never heard of such things.");
  294. 	}
  295.  
  296. } while (from_screen && !quick && ans != LOOK_ONCE);
  297.  
  298. flags.verbose = save_verbose;
  299. return 0;
  300. }

dowhatis[edit]

  1. int
  2. dowhatis()
  3. {
  4. 	return do_look(FALSE);
  5. }

doquickwhatis[edit]

  1. int
  2. doquickwhatis()
  3. {
  4. 	return do_look(TRUE);
  5. }

doidtrap[edit]

  1. int
  2. doidtrap()
  3. {
  4. 	register struct trap *trap;
  5. 	int x, y, tt;
  6.  
  7. 	if (!getdir("^")) return 0;
  8. 	x = u.ux + u.dx;
  9. 	y = u.uy + u.dy;
  10. 	for (trap = ftrap; trap; trap = trap->ntrap)
  11. 	    if (trap->tx == x && trap->ty == y) {
  12. 		if (!trap->tseen) break;
  13. 		tt = trap->ttyp;
  14. 		if (u.dz) {
  15. 		    if (u.dz < 0 ? (tt == TRAPDOOR || tt == HOLE) :
  16. 			    tt == ROCKTRAP) break;
  17. 		}
  18. 		tt = what_trap(tt);
  19. 		pline("That is %s%s%s.",
  20. 		      an(defsyms[trap_to_defsym(tt)].explanation),
  21. 		      !trap->madeby_u ? "" : (tt == WEB) ? " woven" :
  22. 			  /* trap doors & spiked pits can't be made by
  23. 			     player, and should be considered at least
  24. 			     as much "set" as "dug" anyway */
  25. 			  (tt == HOLE || tt == PIT) ? " dug" : " set",
  26. 		      !trap->madeby_u ? "" : " by you");
  27. 		return 0;
  28. 	    }
  29. 	pline("I can't see a trap there.");
  30. 	return 0;
  31. }

dowhatdoes_core[edit]

  1. char *
  2. dowhatdoes_core(q, cbuf)
  3. char q;
  4. char *cbuf;
  5. {
  6. 	dlb *fp;
  7. 	char bufr[BUFSZ];
  8. 	register char *buf = &bufr[6], *ep, ctrl, meta;
  9.  
  10. 	fp = dlb_fopen(CMDHELPFILE, "r");
  11. 	if (!fp) {
  12. 		pline("Cannot open data file!");
  13. 		return 0;
  14. 	}
  15.  
  16. 	ctrl = ((q <= '\033') ? (q - 1 + 'A') : 0);
  17. 	meta = ((0x80 & q) ? (0x7f & q) : 0);
  18. 	while(dlb_fgets(buf,BUFSZ-6,fp)) {
  19. 	    if ((ctrl && *buf=='^' && *(buf+1)==ctrl) ||
  20. 		(meta && *buf=='M' && *(buf+1)=='-' && *(buf+2)==meta) ||
  21. 		*buf==q) {
  22. 		ep = index(buf, '\n');
  23. 		if(ep) *ep = 0;
  24. 		if (ctrl && buf[2] == '\t'){
  25. 			buf = bufr + 1;
  26. 			(void) strncpy(buf, "^?      ", 8);
  27. 			buf[1] = ctrl;
  28. 		} else if (meta && buf[3] == '\t'){
  29. 			buf = bufr + 2;
  30. 			(void) strncpy(buf, "M-?     ", 8);
  31. 			buf[2] = meta;
  32. 		} else if(buf[1] == '\t'){
  33. 			buf = bufr;
  34. 			buf[0] = q;
  35. 			(void) strncpy(buf+1, "       ", 7);
  36. 		}
  37. 		(void) dlb_fclose(fp);
  38. 		Strcpy(cbuf, buf);
  39. 		return cbuf;
  40. 	    }
  41. 	}
  42. 	(void) dlb_fclose(fp);
  43. 	return (char *)0;
  44. }

dowhatdoes[edit]

  1. int
  2. dowhatdoes()
  3. {
  4. 	char bufr[BUFSZ];
  5. 	char q, *reslt;
  6.  
  7. #if defined(UNIX) || defined(VMS)
  8. 	introff();
  9. #endif
  10. 	q = yn_function("What command?", (char *)0, '\0');
  11. #if defined(UNIX) || defined(VMS)
  12. 	intron();
  13. #endif
  14. 	reslt = dowhatdoes_core(q, bufr);
  15. 	if (reslt)
  16. 		pline("%s", reslt);
  17. 	else
  18. 		pline("I've never heard of such commands.");
  19. 	return 0;
  20. }

help_menu[edit]

  1. /* data for help_menu() */
  2. static const char *help_menu_items[] = {
  3. /* 0*/	"Long description of the game and commands.",
  4. /* 1*/	"List of game commands.",
  5. /* 2*/	"Concise history of NetHack.",
  6. /* 3*/	"Info on a character in the game display.",
  7. /* 4*/	"Info on what a given key does.",
  8. /* 5*/	"List of game options.",
  9. /* 6*/	"Longer explanation of game options.",
  10. /* 7*/	"List of extended commands.",
  11. /* 8*/	"The NetHack license.",
  12. #ifdef PORT_HELP
  13. 	"%s-specific help and commands.",
  14. #define PORT_HELP_ID 100
  15. #define WIZHLP_SLOT 10
  16. #else
  17. #define WIZHLP_SLOT 9
  18. #endif
  19. #ifdef WIZARD
  20. 	"List of wizard-mode commands.",
  21. #endif
  22. 	"",
  23. 	(char *)0
  24. };
  25.  
  26. STATIC_OVL boolean
  27. help_menu(sel)
  28. 	int *sel;
  29. {
  30. 	winid tmpwin = create_nhwindow(NHW_MENU);
  31. #ifdef PORT_HELP
  32. 	char helpbuf[QBUFSZ];
  33. #endif
  34. 	int i, n;
  35. 	menu_item *selected;
  36. 	anything any;
  37.  
  38. 	any.a_void = 0;		/* zero all bits */
  39. 	start_menu(tmpwin);
  40. #ifdef WIZARD
  41. 	if (!wizard) help_menu_items[WIZHLP_SLOT] = "",
  42. 		     help_menu_items[WIZHLP_SLOT+1] = (char *)0;
  43. #endif
  44. 	for (i = 0; help_menu_items[i]; i++)
  45. #ifdef PORT_HELP
  46. 	    /* port-specific line has a %s in it for the PORT_ID */
  47. 	    if (help_menu_items[i][0] == '%') {
  48. 		Sprintf(helpbuf, help_menu_items[i], PORT_ID);
  49. 		any.a_int = PORT_HELP_ID + 1;
  50. 		add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
  51. 			 helpbuf, MENU_UNSELECTED);
  52. 	    } else
  53. #endif
  54. 	    {
  55. 		any.a_int = (*help_menu_items[i]) ? i+1 : 0;
  56. 		add_menu(tmpwin, NO_GLYPH, &any, 0, 0,
  57. 			ATR_NONE, help_menu_items[i], MENU_UNSELECTED);
  58. 	    }
  59. 	end_menu(tmpwin, "Select one item:");
  60. 	n = select_menu(tmpwin, PICK_ONE, &selected);
  61. 	destroy_nhwindow(tmpwin);
  62. 	if (n > 0) {
  63. 	    *sel = selected[0].item.a_int - 1;
  64. 	    free((genericptr_t)selected);
  65. 	    return TRUE;
  66. 	}
  67. 	return FALSE;
  68. }

dohelp[edit]

  1. int
  2. dohelp()
  3. {
  4. 	int sel = 0;
  5.  
  6. 	if (help_menu(&sel)) {
  7. 		switch (sel) {
  8. 			case  0:  display_file(HELP, TRUE);  break;
  9. 			case  1:  display_file(SHELP, TRUE);  break;
  10. 			case  2:  (void) dohistory();  break;
  11. 			case  3:  (void) dowhatis();  break;
  12. 			case  4:  (void) dowhatdoes();  break;
  13. 			case  5:  option_help();  break;
  14. 			case  6:  display_file(OPTIONFILE, TRUE);  break;
  15. 			case  7:  (void) doextlist();  break;
  16. 			case  8:  display_file(LICENSE, TRUE);  break;
  17. #ifdef WIZARD
  18. 			/* handle slot 9 or 10 */
  19. 			default: display_file(DEBUGHELP, TRUE);  break;
  20. #endif
  21. #ifdef PORT_HELP
  22. 			case PORT_HELP_ID:  port_help();  break;
  23. #endif
  24. 		}
  25. 	}
  26. 	return 0;
  27. }

dohistory[edit]

  1. int
  2. dohistory()
  3. {
  4. 	display_file(HISTORY, TRUE);
  5. 	return 0;
  6. }
  7.  
  8. /*pager.c*/