Source:NetHack 3.4.3/src/cmd.c

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

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

Top of file[edit]

  1. /*	SCCS Id: @(#)cmd.c	3.4	2003/02/06	*/
  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. #include "hack.h"
  2. #include "func_tab.h"
  3. /* #define DEBUG */	/* uncomment for debugging */
  4.  
  5. /*
  6. * Some systems may have getchar() return EOF for various reasons, and
  7. * we should not quit before seeing at least NR_OF_EOFS consecutive EOFs.
  8. */
  9. #if defined(SYSV) || defined(DGUX) || defined(HPUX)
  10. #define NR_OF_EOFS	20
  11. #endif
  12.  
  13. #define CMD_TRAVEL (char)0x90
  14.  
  15. #ifdef DEBUG
  16. /*
  17. * only one "wiz_debug_cmd" routine should be available (in whatever
  18. * module you are trying to debug) or things are going to get rather
  19. * hard to link :-)
  20. */
  21. extern int NDECL(wiz_debug_cmd);
  22. #endif
  23.  
  24. #ifdef DUMB	/* stuff commented out in extern.h, but needed here */
  25. extern int NDECL(doapply); /**/
  26. extern int NDECL(dorub); /**/
  27. extern int NDECL(dojump); /**/
  28. extern int NDECL(doextlist); /**/
  29. extern int NDECL(dodrop); /**/
  30. extern int NDECL(doddrop); /**/
  31. extern int NDECL(dodown); /**/
  32. extern int NDECL(doup); /**/
  33. extern int NDECL(donull); /**/
  34. extern int NDECL(dowipe); /**/
  35. extern int NDECL(do_mname); /**/
  36. extern int NDECL(ddocall); /**/
  37. extern int NDECL(dotakeoff); /**/
  38. extern int NDECL(doremring); /**/
  39. extern int NDECL(dowear); /**/
  40. extern int NDECL(doputon); /**/
  41. extern int NDECL(doddoremarm); /**/
  42. extern int NDECL(dokick); /**/
  43. extern int NDECL(dofire); /**/
  44. extern int NDECL(dothrow); /**/
  45. extern int NDECL(doeat); /**/
  46. extern int NDECL(done2); /**/
  47. extern int NDECL(doengrave); /**/
  48. extern int NDECL(dopickup); /**/
  49. extern int NDECL(ddoinv); /**/
  50. extern int NDECL(dotypeinv); /**/
  51. extern int NDECL(dolook); /**/
  52. extern int NDECL(doprgold); /**/
  53. extern int NDECL(doprwep); /**/
  54. extern int NDECL(doprarm); /**/
  55. extern int NDECL(doprring); /**/
  56. extern int NDECL(dopramulet); /**/
  57. extern int NDECL(doprtool); /**/
  58. extern int NDECL(dosuspend); /**/
  59. extern int NDECL(doforce); /**/
  60. extern int NDECL(doopen); /**/
  61. extern int NDECL(doclose); /**/
  62. extern int NDECL(dosh); /**/
  63. extern int NDECL(dodiscovered); /**/
  64. extern int NDECL(doset); /**/
  65. extern int NDECL(dotogglepickup); /**/
  66. extern int NDECL(dowhatis); /**/
  67. extern int NDECL(doquickwhatis); /**/
  68. extern int NDECL(dowhatdoes); /**/
  69. extern int NDECL(dohelp); /**/
  70. extern int NDECL(dohistory); /**/
  71. extern int NDECL(doloot); /**/
  72. extern int NDECL(dodrink); /**/
  73. extern int NDECL(dodip); /**/
  74. extern int NDECL(dosacrifice); /**/
  75. extern int NDECL(dopray); /**/
  76. extern int NDECL(doturn); /**/
  77. extern int NDECL(doredraw); /**/
  78. extern int NDECL(doread); /**/
  79. extern int NDECL(dosave); /**/
  80. extern int NDECL(dosearch); /**/
  81. extern int NDECL(doidtrap); /**/
  82. extern int NDECL(dopay); /**/
  83. extern int NDECL(dosit); /**/
  84. extern int NDECL(dotalk); /**/
  85. extern int NDECL(docast); /**/
  86. extern int NDECL(dovspell); /**/
  87. extern int NDECL(dotele); /**/
  88. extern int NDECL(dountrap); /**/
  89. extern int NDECL(doversion); /**/
  90. extern int NDECL(doextversion); /**/
  91. extern int NDECL(doswapweapon); /**/
  92. extern int NDECL(dowield); /**/
  93. extern int NDECL(dowieldquiver); /**/
  94. extern int NDECL(dozap); /**/
  95. extern int NDECL(doorganize); /**/
  96. #endif /* DUMB */
  97.  
  98. #ifdef OVL1
  99. static int NDECL((*timed_occ_fn));
  100. #endif /* OVL1 */
  101.  
  102. STATIC_PTR int NDECL(doprev_message);
  103. STATIC_PTR int NDECL(timed_occupation);
  104. STATIC_PTR int NDECL(doextcmd);
  105. STATIC_PTR int NDECL(domonability);
  106. STATIC_PTR int NDECL(dotravel);
  107. # ifdef WIZARD
  108. STATIC_PTR int NDECL(wiz_wish);
  109. STATIC_PTR int NDECL(wiz_identify);
  110. STATIC_PTR int NDECL(wiz_map);
  111. STATIC_PTR int NDECL(wiz_genesis);
  112. STATIC_PTR int NDECL(wiz_where);
  113. STATIC_PTR int NDECL(wiz_detect);
  114. STATIC_PTR int NDECL(wiz_panic);
  115. STATIC_PTR int NDECL(wiz_polyself);
  116. STATIC_PTR int NDECL(wiz_level_tele);
  117. STATIC_PTR int NDECL(wiz_level_change);
  118. STATIC_PTR int NDECL(wiz_show_seenv);
  119. STATIC_PTR int NDECL(wiz_show_vision);
  120. STATIC_PTR int NDECL(wiz_mon_polycontrol);
  121. STATIC_PTR int NDECL(wiz_show_wmodes);
  122. #if defined(__BORLANDC__) && !defined(_WIN32)
  123. extern void FDECL(show_borlandc_stats, (winid));
  124. #endif
  125. #ifdef DEBUG_MIGRATING_MONS
  126. STATIC_PTR int NDECL(wiz_migrate_mons);
  127. #endif
  128. STATIC_DCL void FDECL(count_obj, (struct obj *, long *, long *, BOOLEAN_P, BOOLEAN_P));
  129. STATIC_DCL void FDECL(obj_chain, (winid, const char *, struct obj *, long *, long *));
  130. STATIC_DCL void FDECL(mon_invent_chain, (winid, const char *, struct monst *, long *, long *));
  131. STATIC_DCL void FDECL(mon_chain, (winid, const char *, struct monst *, long *, long *));
  132. STATIC_DCL void FDECL(contained, (winid, const char *, long *, long *));
  133. STATIC_PTR int NDECL(wiz_show_stats);
  134. #  ifdef PORT_DEBUG
  135. STATIC_DCL int NDECL(wiz_port_debug);
  136. #  endif
  137. # endif
  138. STATIC_PTR int NDECL(enter_explore_mode);
  139. STATIC_PTR int NDECL(doattributes);
  140. STATIC_PTR int NDECL(doconduct); /**/
  141. STATIC_PTR boolean NDECL(minimal_enlightenment);
  142.  
  143. #ifdef OVLB
  144. STATIC_DCL void FDECL(enlght_line, (const char *,const char *,const char *));
  145. STATIC_DCL char *FDECL(enlght_combatinc, (const char *,int,int,char *));
  146. #ifdef UNIX
  147. static void NDECL(end_of_input);
  148. #endif
  149. #endif /* OVLB */
  150.  
  151. static const char* readchar_queue="";
  152.  
  153. STATIC_DCL char *NDECL(parse);
  154. STATIC_DCL boolean FDECL(help_dir, (CHAR_P,const char *));

doprev_message[edit]

  1. #ifdef OVL1
  2.  
  3. STATIC_PTR int
  4. doprev_message()
  5. {
  6. return nh_doprev_message();
  7. }

timed_occupation[edit]

  1. /* Count down by decrementing multi */
  2. STATIC_PTR int
  3. timed_occupation()
  4. {
  5. 	(*timed_occ_fn)();
  6. 	if (multi > 0)
  7. 		multi--;
  8. 	return multi > 0;
  9. }

reset_occupations[edit]

  1. /* If you have moved since initially setting some occupations, they
  2. * now shouldn't be able to restart.
  3. *
  4. * The basic rule is that if you are carrying it, you can continue
  5. * since it is with you.  If you are acting on something at a distance,
  6. * your orientation to it must have changed when you moved.
  7. *
  8. * The exception to this is taking off items, since they can be taken
  9. * off in a number of ways in the intervening time, screwing up ordering.
  10. *
  11. *	Currently:	Take off all armor.
  12. *			Picking Locks / Forcing Chests.
  13. *			Setting traps.
  14. */
  15. void
  16. reset_occupations()
  17. {
  18. 	reset_remarm();
  19. 	reset_pick();
  20. 	reset_trapset();
  21. }

set_occupation[edit]

  1. /* If a time is given, use it to timeout this function, otherwise the
  2. * function times out by its own means.
  3. */
  4. void
  5. set_occupation(fn, txt, xtime)
  6. int NDECL((*fn));
  7. const char *txt;
  8. int xtime;
  9. {
  10. 	if (xtime) {
  11. 		occupation = timed_occupation;
  12. 		timed_occ_fn = fn;
  13. 	} else
  14. 		occupation = fn;
  15. 	occtxt = txt;
  16. 	occtime = 0;
  17. 	return;
  18. }

popch[edit]

  1. #ifdef REDO
  2.  
  3. static char NDECL(popch);
  4.  
  5. /* Provide a means to redo the last command.  The flag `in_doagain' is set
  6. * to true while redoing the command.  This flag is tested in commands that
  7. * require additional input (like `throw' which requires a thing and a
  8. * direction), and the input prompt is not shown.  Also, while in_doagain is
  9. * TRUE, no keystrokes can be saved into the saveq.
  10. */
  11. #define BSIZE 20
  12. static char pushq[BSIZE], saveq[BSIZE];
  13. static NEARDATA int phead, ptail, shead, stail;
  14.  
  15. static char
  16. popch() {
  17. 	/* If occupied, return '\0', letting tgetch know a character should
  18. 	 * be read from the keyboard.  If the character read is not the
  19. 	 * ABORT character (as checked in pcmain.c), that character will be
  20. 	 * pushed back on the pushq.
  21. 	 */
  22. 	if (occupation) return '\0';
  23. 	if (in_doagain) return(char)((shead != stail) ? saveq[stail++] : '\0');
  24. 	else		return(char)((phead != ptail) ? pushq[ptail++] : '\0');
  25. }

pgetchar[edit]

  1. char
  2. pgetchar() {		/* curtesy of aeb@cwi.nl */
  3. 	register int ch;
  4.  
  5. 	if(!(ch = popch()))
  6. 		ch = nhgetch();
  7. 	return((char)ch);
  8. }

pushch[edit]

  1. /* A ch == 0 resets the pushq */
  2. void
  3. pushch(ch)
  4. char ch;
  5. {
  6. 	if (!ch)
  7. 		phead = ptail = 0;
  8. 	if (phead < BSIZE)
  9. 		pushq[phead++] = ch;
  10. 	return;
  11. }

savech[edit]

  1. /* A ch == 0 resets the saveq.	Only save keystrokes when not
  2. * replaying a previous command.
  3. */
  4. void
  5. savech(ch)
  6. char ch;
  7. {
  8. 	if (!in_doagain) {
  9. 		if (!ch)
  10. 			phead = ptail = shead = stail = 0;
  11. 		else if (shead < BSIZE)
  12. 			saveq[shead++] = ch;
  13. 	}
  14. 	return;
  15. }
  16. #endif /* REDO */
  17.  
  18. #endif /* OVL1 */

doextcmd[edit]

  1. #ifdef OVLB
  2.  
  3. STATIC_PTR int
  4. doextcmd()	/* here after # - now read a full-word command */
  5. {
  6. 	int idx, retval;
  7.  
  8. 	/* keep repeating until we don't run help or quit */
  9. 	do {
  10. 	    idx = get_ext_cmd();
  11. 	    if (idx < 0) return 0;	/* quit */
  12.  
  13. 	    retval = (*extcmdlist[idx].ef_funct)();
  14. 	} while (extcmdlist[idx].ef_funct == doextlist);
  15.  
  16. 	return retval;
  17. }

doextlist[edit]

  1. int
  2. doextlist()	/* here after #? - now list all full-word commands */
  3. {
  4. 	register const struct ext_func_tab *efp;
  5. 	char	 buf[BUFSZ];
  6. 	winid datawin;
  7.  
  8. 	datawin = create_nhwindow(NHW_TEXT);
  9. 	putstr(datawin, 0, "");
  10. 	putstr(datawin, 0, "            Extended Commands List");
  11. 	putstr(datawin, 0, "");
  12. 	putstr(datawin, 0, "    Press '#', then type:");
  13. 	putstr(datawin, 0, "");
  14.  
  15. 	for(efp = extcmdlist; efp->ef_txt; efp++) {
  16. 		Sprintf(buf, "    %-15s - %s.", efp->ef_txt, efp->ef_desc);
  17. 		putstr(datawin, 0, buf);
  18. 	}
  19. 	display_nhwindow(datawin, FALSE);
  20. 	destroy_nhwindow(datawin);
  21. 	return 0;
  22. }

extcmd_via_menu[edit]

  1. #ifdef TTY_GRAPHICS
  2. #define MAX_EXT_CMD 40		/* Change if we ever have > 40 ext cmds */
  3. /*
  4. * This is currently used only by the tty port and is
  5. * controlled via runtime option 'extmenu'
  6. */
  7. int
  8. extcmd_via_menu()	/* here after # - now show pick-list of possible commands */
  9. {
  10. const struct ext_func_tab *efp;
  11. menu_item *pick_list = (menu_item *)0;
  12. winid win;
  13. anything any;
  14. const struct ext_func_tab *choices[MAX_EXT_CMD];
  15. char buf[BUFSZ];
  16. char cbuf[QBUFSZ], prompt[QBUFSZ], fmtstr[20];
  17. int i, n, nchoices, acount;
  18. int ret,  biggest;
  19. int accelerator, prevaccelerator;
  20. int  matchlevel = 0;
  21.  
  22. ret = 0;
  23. cbuf[0] = '\0';
  24. biggest = 0;
  25. while (!ret) {
  26. 	    i = n = 0;
  27. 	    accelerator = 0;
  28. 	    any.a_void = 0;
  29. 	    /* populate choices */
  30. 	    for(efp = extcmdlist; efp->ef_txt; efp++) {
  31. 		if (!matchlevel || !strncmp(efp->ef_txt, cbuf, matchlevel)) {
  32. 			choices[i++] = efp;
  33. 			if ((int)strlen(efp->ef_desc) > biggest) {
  34. 				biggest = strlen(efp->ef_desc);
  35. 				Sprintf(fmtstr,"%%-%ds", biggest + 15);
  36. 			}
  37. #ifdef DEBUG
  38. 			if (i >= MAX_EXT_CMD - 2) {
  39. 			    impossible("Exceeded %d extended commands in doextcmd() menu",
  40. 					MAX_EXT_CMD - 2);
  41. 			    return 0;
  42. 			}
  43. #endif
  44. 		}
  45. 	    }
  46. 	    choices[i] = (struct ext_func_tab *)0;
  47. 	    nchoices = i;
  48. 	    /* if we're down to one, we have our selection so get out of here */
  49. 	    if (nchoices == 1) {
  50. 		for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++)
  51. 			if (!strncmpi(extcmdlist[i].ef_txt, cbuf, matchlevel)) {
  52. 				ret = i;
  53. 				break;
  54. 			}
  55. 		break;
  56. 	    }
  57.  
  58. 	    /* otherwise... */
  59. 	    win = create_nhwindow(NHW_MENU);
  60. 	    start_menu(win);
  61. 	    prevaccelerator = 0;
  62. 	    acount = 0;
  63. 	    for(i = 0; choices[i]; ++i) {
  64. 		accelerator = choices[i]->ef_txt[matchlevel];
  65. 		if (accelerator != prevaccelerator || nchoices < (ROWNO - 3)) {
  66. 		    if (acount) {
  67. 			/* flush the extended commands for that letter already in buf */
  68. 			Sprintf(buf, fmtstr, prompt);
  69. 			any.a_char = prevaccelerator;
  70. 			add_menu(win, NO_GLYPH, &any, any.a_char, 0,
  71. 					ATR_NONE, buf, FALSE);
  72. 			acount = 0;
  73. 		    }
  74. 		}
  75. 		prevaccelerator = accelerator;
  76. 		if (!acount || nchoices < (ROWNO - 3)) {
  77. 		    Sprintf(prompt, "%s [%s]", choices[i]->ef_txt,
  78. 				choices[i]->ef_desc);
  79. 		} else if (acount == 1) {
  80. 		    Sprintf(prompt, "%s or %s", choices[i-1]->ef_txt,
  81. 				choices[i]->ef_txt);
  82. 		} else {
  83. 		    Strcat(prompt," or ");
  84. 		    Strcat(prompt, choices[i]->ef_txt);
  85. 		}
  86. 		++acount;
  87. 	    }
  88. 	    if (acount) {
  89. 		/* flush buf */
  90. 		Sprintf(buf, fmtstr, prompt);
  91. 		any.a_char = prevaccelerator;
  92. 		add_menu(win, NO_GLYPH, &any, any.a_char, 0, ATR_NONE, buf, FALSE);
  93. 	    }
  94. 	    Sprintf(prompt, "Extended Command: %s", cbuf);
  95. 	    end_menu(win, prompt);
  96. 	    n = select_menu(win, PICK_ONE, &pick_list);
  97. 	    destroy_nhwindow(win);
  98. 	    if (n==1) {
  99. 		if (matchlevel > (QBUFSZ - 2)) {
  100. 			free((genericptr_t)pick_list);
  101. #ifdef DEBUG
  102. 			impossible("Too many characters (%d) entered in extcmd_via_menu()",
  103. 				matchlevel);
  104. #endif
  105. 			ret = -1;
  106. 		} else {
  107. 			cbuf[matchlevel++] = pick_list[0].item.a_char;
  108. 			cbuf[matchlevel] = '\0';
  109. 			free((genericptr_t)pick_list);
  110. 		}
  111. 	    } else {
  112. 		if (matchlevel) {
  113. 			ret = 0;
  114. 			matchlevel = 0;
  115. 		} else
  116. 			ret = -1;
  117. 	    }
  118. }
  119. return ret;
  120. }
  121. #endif

domonability[edit]

  1. /* #monster command - use special monster ability while polymorphed */
  2. STATIC_PTR int
  3. domonability()
  4. {
  5. 	if (can_breathe(youmonst.data)) return dobreathe();
  6. 	else if (attacktype(youmonst.data, AT_SPIT)) return dospit();
  7. 	else if (youmonst.data->mlet == S_NYMPH) return doremove();
  8. 	else if (attacktype(youmonst.data, AT_GAZE)) return dogaze();
  9. 	else if (is_were(youmonst.data)) return dosummon();
  10. 	else if (webmaker(youmonst.data)) return dospinweb();
  11. 	else if (is_hider(youmonst.data)) return dohide();
  12. 	else if (is_mind_flayer(youmonst.data)) return domindblast();
  13. 	else if (u.umonnum == PM_GREMLIN) {
  14. 	    if(IS_FOUNTAIN(levl[u.ux][u.uy].typ)) {
  15. 		if (split_mon(&youmonst, (struct monst *)0))
  16. 		    dryup(u.ux, u.uy, TRUE);
  17. 	    } else There("is no fountain here.");
  18. 	} else if (is_unicorn(youmonst.data)) {
  19. 	    use_unicorn_horn((struct obj *)0);
  20. 	    return 1;
  21. 	} else if (youmonst.data->msound == MS_SHRIEK) {
  22. 	    You("shriek.");
  23. 	    if(u.uburied)
  24. 		pline("Unfortunately sound does not carry well through rock.");
  25. 	    else aggravate();
  26. 	} else if (Upolyd)
  27. 		pline("Any special ability you may have is purely reflexive.");
  28. 	else You("don't have a special ability in your normal form!");
  29. 	return 0;
  30. }

enter_explore_mode[edit]

  1. STATIC_PTR int
  2. enter_explore_mode()
  3. {
  4. 	if(!discover && !wizard) {
  5. 		pline("Beware!  From explore mode there will be no return to normal game.");
  6. 		if (yn("Do you want to enter explore mode?") == 'y') {
  7. 			clear_nhwindow(WIN_MESSAGE);
  8. 			You("are now in non-scoring explore mode.");
  9. 			discover = TRUE;
  10. 		}
  11. 		else {
  12. 			clear_nhwindow(WIN_MESSAGE);
  13. 			pline("Resuming normal game.");
  14. 		}
  15. 	}
  16. 	return 0;
  17. }

wiz_wish[edit]

  1. #ifdef WIZARD
  2.  
  3. /* ^W command - wish for something */
  4. STATIC_PTR int
  5. wiz_wish()	/* Unlimited wishes for debug mode by Paul Polderman */
  6. {
  7. 	if (wizard) {
  8. 	    boolean save_verbose = flags.verbose;
  9.  
  10. 	    flags.verbose = FALSE;
  11. 	    makewish();
  12. 	    flags.verbose = save_verbose;
  13. 	    (void) encumber_msg();
  14. 	} else
  15. 	    pline("Unavailable command '^W'.");
  16. 	return 0;
  17. }

wiz_identify[edit]

  1. /* ^I command - identify hero's inventory */
  2. STATIC_PTR int
  3. wiz_identify()
  4. {
  5. 	if (wizard)	identify_pack(0);
  6. 	else		pline("Unavailable command '^I'.");
  7. 	return 0;
  8. }

wiz_map[edit]

  1. /* ^F command - reveal the level map and any traps on it */
  2. STATIC_PTR int
  3. wiz_map()
  4. {
  5. 	if (wizard) {
  6. 	    struct trap *t;
  7. 	    long save_Hconf = HConfusion,
  8. 		 save_Hhallu = HHallucination;
  9.  
  10. 	    HConfusion = HHallucination = 0L;
  11. 	    for (t = ftrap; t != 0; t = t->ntrap) {
  12. 		t->tseen = 1;
  13. 		map_trap(t, TRUE);
  14. 	    }
  15. 	    do_mapping();
  16. 	    HConfusion = save_Hconf;
  17. 	    HHallucination = save_Hhallu;
  18. 	} else
  19. 	    pline("Unavailable command '^F'.");
  20. 	return 0;
  21. }

wiz_genesis[edit]

  1. /* ^G command - generate monster(s); a count prefix will be honored */
  2. STATIC_PTR int
  3. wiz_genesis()
  4. {
  5. 	if (wizard)	(void) create_particular();
  6. 	else		pline("Unavailable command '^G'.");
  7. 	return 0;
  8. }

wiz_where[edit]

  1. /* ^O command - display dungeon layout */
  2. STATIC_PTR int
  3. wiz_where()
  4. {
  5. 	if (wizard) (void) print_dungeon(FALSE, (schar *)0, (xchar *)0);
  6. 	else	    pline("Unavailable command '^O'.");
  7. 	return 0;
  8. }

wiz_detect[edit]

  1. /* ^E command - detect unseen (secret doors, traps, hidden monsters) */
  2. STATIC_PTR int
  3. wiz_detect()
  4. {
  5. 	if(wizard)  (void) findit();
  6. 	else	    pline("Unavailable command '^E'.");
  7. 	return 0;
  8. }

wiz_level_tele[edit]

  1. /* ^V command - level teleport */
  2. STATIC_PTR int
  3. wiz_level_tele()
  4. {
  5. 	if (wizard)	level_tele();
  6. 	else		pline("Unavailable command '^V'.");
  7. 	return 0;
  8. }

wiz_mon_polycontrol[edit]

  1. /* #monpolycontrol command - choose new form for shapechangers, polymorphees */
  2. STATIC_PTR int
  3. wiz_mon_polycontrol()
  4. {
  5. iflags.mon_polycontrol = !iflags.mon_polycontrol;
  6. pline("Monster polymorph control is %s.",
  7. 	  iflags.mon_polycontrol ? "on" : "off");
  8. return 0;
  9. }

wiz_level_change[edit]

  1. /* #levelchange command - adjust hero's experience level */
  2. STATIC_PTR int
  3. wiz_level_change()
  4. {
  5. char buf[BUFSZ];
  6. int newlevel;
  7. int ret;
  8.  
  9. getlin("To what experience level do you want to be set?", buf);
  10. (void)mungspaces(buf);
  11. if (buf[0] == '\033' || buf[0] == '\0') ret = 0;
  12. else ret = sscanf(buf, "%d", &newlevel);
  13.  
  14. if (ret != 1) {
  15. 	pline(Never_mind);
  16. 	return 0;
  17. }
  18. if (newlevel == u.ulevel) {
  19. 	You("are already that experienced.");
  20. } else if (newlevel < u.ulevel) {
  21. 	if (u.ulevel == 1) {
  22. 	    You("are already as inexperienced as you can get.");
  23. 	    return 0;
  24. 	}
  25. 	if (newlevel < 1) newlevel = 1;
  26. 	while (u.ulevel > newlevel)
  27. 	    losexp("#levelchange");
  28. } else {
  29. 	if (u.ulevel >= MAXULEV) {
  30. 	    You("are already as experienced as you can get.");
  31. 	    return 0;
  32. 	}
  33. 	if (newlevel > MAXULEV) newlevel = MAXULEV;
  34. 	while (u.ulevel < newlevel)
  35. 	    pluslvl(FALSE);
  36. }
  37. u.ulevelmax = u.ulevel;
  38. return 0;
  39. }

wiz_panic[edit]

  1. /* #panic command - test program's panic handling */
  2. STATIC_PTR int
  3. wiz_panic()
  4. {
  5. 	if (yn("Do you want to call panic() and end your game?") == 'y')
  6. 		panic("crash test.");
  7. return 0;
  8. }

wiz_polyself[edit]

  1. /* #polyself command - change hero's form */
  2. STATIC_PTR int
  3. wiz_polyself()
  4. {
  5. polyself(TRUE);
  6. return 0;
  7. }

wiz_show_seenv[edit]

  1. /* #seenv command */
  2. STATIC_PTR int
  3. wiz_show_seenv()
  4. {
  5. 	winid win;
  6. 	int x, y, v, startx, stopx, curx;
  7. 	char row[COLNO+1];
  8.  
  9. 	win = create_nhwindow(NHW_TEXT);
  10. 	/*
  11. 	 * Each seenv description takes up 2 characters, so center
  12. 	 * the seenv display around the hero.
  13. 	 */
  14. 	startx = max(1, u.ux-(COLNO/4));
  15. 	stopx = min(startx+(COLNO/2), COLNO);
  16. 	/* can't have a line exactly 80 chars long */
  17. 	if (stopx - startx == COLNO/2) startx++;
  18.  
  19. 	for (y = 0; y < ROWNO; y++) {
  20. 	    for (x = startx, curx = 0; x < stopx; x++, curx += 2) {
  21. 		if (x == u.ux && y == u.uy) {
  22. 		    row[curx] = row[curx+1] = '@';
  23. 		} else {
  24. 		    v = levl[x][y].seenv & 0xff;
  25. 		    if (v == 0)
  26. 			row[curx] = row[curx+1] = ' ';
  27. 		    else
  28. 			Sprintf(&row[curx], "%02x", v);
  29. 		}
  30. 	    }
  31. 	    /* remove trailing spaces */
  32. 	    for (x = curx-1; x >= 0; x--)
  33. 		if (row[x] != ' ') break;
  34. 	    row[x+1] = '\0';
  35.  
  36. 	    putstr(win, 0, row);
  37. 	}
  38. 	display_nhwindow(win, TRUE);
  39. 	destroy_nhwindow(win);
  40. 	return 0;
  41. }

wiz_show_vision[edit]

  1. /* #vision command */
  2. STATIC_PTR int
  3. wiz_show_vision()
  4. {
  5. 	winid win;
  6. 	int x, y, v;
  7. 	char row[COLNO+1];
  8.  
  9. 	win = create_nhwindow(NHW_TEXT);
  10. 	Sprintf(row, "Flags: 0x%x could see, 0x%x in sight, 0x%x temp lit",
  11. 		COULD_SEE, IN_SIGHT, TEMP_LIT);
  12. 	putstr(win, 0, row);
  13. 	putstr(win, 0, "");
  14. 	for (y = 0; y < ROWNO; y++) {
  15. 	    for (x = 1; x < COLNO; x++) {
  16. 		if (x == u.ux && y == u.uy)
  17. 		    row[x] = '@';
  18. 		else {
  19. 		    v = viz_array[y][x]; /* data access should be hidden */
  20. 		    if (v == 0)
  21. 			row[x] = ' ';
  22. 		    else
  23. 			row[x] = '0' + viz_array[y][x];
  24. 		}
  25. 	    }
  26. 	    /* remove trailing spaces */
  27. 	    for (x = COLNO-1; x >= 1; x--)
  28. 		if (row[x] != ' ') break;
  29. 	    row[x+1] = '\0';
  30.  
  31. 	    putstr(win, 0, &row[1]);
  32. 	}
  33. 	display_nhwindow(win, TRUE);
  34. 	destroy_nhwindow(win);
  35. 	return 0;
  36. }

wiz_show_wmodes[edit]

  1. /* #wmode command */
  2. STATIC_PTR int
  3. wiz_show_wmodes()
  4. {
  5. 	winid win;
  6. 	int x,y;
  7. 	char row[COLNO+1];
  8. 	struct rm *lev;
  9.  
  10. 	win = create_nhwindow(NHW_TEXT);
  11. 	for (y = 0; y < ROWNO; y++) {
  12. 	    for (x = 0; x < COLNO; x++) {
  13. 		lev = &levl[x][y];
  14. 		if (x == u.ux && y == u.uy)
  15. 		    row[x] = '@';
  16. 		else if (IS_WALL(lev->typ) || lev->typ == SDOOR)
  17. 		    row[x] = '0' + (lev->wall_info & WM_MASK);
  18. 		else if (lev->typ == CORR)
  19. 		    row[x] = '#';
  20. 		else if (IS_ROOM(lev->typ) || IS_DOOR(lev->typ))
  21. 		    row[x] = '.';
  22. 		else
  23. 		    row[x] = 'x';
  24. 	    }
  25. 	    row[COLNO] = '\0';
  26. 	    putstr(win, 0, row);
  27. 	}
  28. 	display_nhwindow(win, TRUE);
  29. 	destroy_nhwindow(win);
  30. 	return 0;
  31. }
  32.  
  33. #endif /* WIZARD */

enlght_line[edit]

  1. /* -enlightenment and conduct- */
  2. static winid en_win;
  3. static const char
  4. 	You_[] = "You ",
  5. 	are[]  = "are ",  were[]  = "were ",
  6. 	have[] = "have ", had[]   = "had ",
  7. 	can[]  = "can ",  could[] = "could ";
  8. static const char
  9. 	have_been[]  = "have been ",
  10. 	have_never[] = "have never ", never[] = "never ";
  11.  
  12. #define enl_msg(prefix,present,past,suffix) \
  13. 			enlght_line(prefix, final ? past : present, suffix)
  14. #define you_are(attr)	enl_msg(You_,are,were,attr)
  15. #define you_have(attr)	enl_msg(You_,have,had,attr)
  16. #define you_can(attr)	enl_msg(You_,can,could,attr)
  17. #define you_have_been(goodthing) enl_msg(You_,have_been,were,goodthing)
  18. #define you_have_never(badthing) enl_msg(You_,have_never,never,badthing)
  19. #define you_have_X(something)	enl_msg(You_,have,(const char *)"",something)
  20.  
  21. static void
  22. enlght_line(start, middle, end)
  23. const char *start, *middle, *end;
  24. {
  25. 	char buf[BUFSZ];
  26.  
  27. 	Sprintf(buf, "%s%s%s.", start, middle, end);
  28. 	putstr(en_win, 0, buf);
  29. }

enlght_combatinc[edit]

  1. /* format increased damage or chance to hit */
  2. static char *
  3. enlght_combatinc(inctyp, incamt, final, outbuf)
  4. const char *inctyp;
  5. int incamt, final;
  6. char *outbuf;
  7. {
  8. 	char numbuf[24];
  9. 	const char *modif, *bonus;
  10.  
  11. 	if (final
  12. #ifdef WIZARD
  13. 		|| wizard
  14. #endif
  15. 	  ) {
  16. 	    Sprintf(numbuf, "%s%d",
  17. 		    (incamt > 0) ? "+" : "", incamt);
  18. 	    modif = (const char *) numbuf;
  19. 	} else {
  20. 	    int absamt = abs(incamt);
  21.  
  22. 	    if (absamt <= 3) modif = "small";
  23. 	    else if (absamt <= 6) modif = "moderate";
  24. 	    else if (absamt <= 12) modif = "large";
  25. 	    else modif = "huge";
  26. 	}
  27. 	bonus = (incamt > 0) ? "bonus" : "penalty";
  28. 	/* "bonus to hit" vs "damage bonus" */
  29. 	if (!strcmp(inctyp, "damage")) {
  30. 	    const char *ctmp = inctyp;
  31. 	    inctyp = bonus;
  32. 	    bonus = ctmp;
  33. 	}
  34. 	Sprintf(outbuf, "%s %s %s", an(modif), bonus, inctyp);
  35. 	return outbuf;
  36. }

enlightenment[edit]

  1. void
  2. enlightenment(final)
  3. int final;	/* 0 => still in progress; 1 => over, survived; 2 => dead */
  4. {
  5. 	int ltmp;
  6. 	char buf[BUFSZ];
  7.  
  8. 	en_win = create_nhwindow(NHW_MENU);
  9. 	putstr(en_win, 0, final ? "Final Attributes:" : "Current Attributes:");
  10. 	putstr(en_win, 0, "");
  11.  
  12. #ifdef ELBERETH
  13. 	if (u.uevent.uhand_of_elbereth) {
  14. 	    static const char * const hofe_titles[3] = {
  15. 				"the Hand of Elbereth",
  16. 				"the Envoy of Balance",
  17. 				"the Glory of Arioch"
  18. 	    };
  19. 	    you_are(hofe_titles[u.uevent.uhand_of_elbereth - 1]);
  20. 	}
  21. #endif
  22.  
  23. 	/* note: piousness 20 matches MIN_QUEST_ALIGN (quest.h) */
  24. 	if (u.ualign.record >= 20)	you_are("piously aligned");
  25. 	else if (u.ualign.record > 13)	you_are("devoutly aligned");
  26. 	else if (u.ualign.record > 8)	you_are("fervently aligned");
  27. 	else if (u.ualign.record > 3)	you_are("stridently aligned");
  28. 	else if (u.ualign.record == 3)	you_are("aligned");
  29. 	else if (u.ualign.record > 0)	you_are("haltingly aligned");
  30. 	else if (u.ualign.record == 0)	you_are("nominally aligned");
  31. 	else if (u.ualign.record >= -3)	you_have("strayed");
  32. 	else if (u.ualign.record >= -8)	you_have("sinned");
  33. 	else you_have("transgressed");
  34. #ifdef WIZARD
  35. 	if (wizard) {
  36. 		Sprintf(buf, " %d", u.ualign.record);
  37. 		enl_msg("Your alignment ", "is", "was", buf);
  38. 	}
  39. #endif
  40.  
  41. 	/*** Resistances to troubles ***/
  42. 	if (Fire_resistance) you_are("fire resistant");
  43. 	if (Cold_resistance) you_are("cold resistant");
  44. 	if (Sleep_resistance) you_are("sleep resistant");
  45. 	if (Disint_resistance) you_are("disintegration-resistant");
  46. 	if (Shock_resistance) you_are("shock resistant");
  47. 	if (Poison_resistance) you_are("poison resistant");
  48. 	if (Drain_resistance) you_are("level-drain resistant");
  49. 	if (Sick_resistance) you_are("immune to sickness");
  50. 	if (Antimagic) you_are("magic-protected");
  51. 	if (Acid_resistance) you_are("acid resistant");
  52. 	if (Stone_resistance)
  53. 		you_are("petrification resistant");
  54. 	if (Invulnerable) you_are("invulnerable");
  55. 	if (u.uedibility) you_can("recognize detrimental food");
  56.  
  57. 	/*** Troubles ***/
  58. 	if (Halluc_resistance)
  59. 		enl_msg("You resist", "", "ed", " hallucinations");
  60. 	if (final) {
  61. 		if (Hallucination) you_are("hallucinating");
  62. 		if (Stunned) you_are("stunned");
  63. 		if (Confusion) you_are("confused");
  64. 		if (Blinded) you_are("blinded");
  65. 		if (Sick) {
  66. 			if (u.usick_type & SICK_VOMITABLE)
  67. 				you_are("sick from food poisoning");
  68. 			if (u.usick_type & SICK_NONVOMITABLE)
  69. 				you_are("sick from illness");
  70. 		}
  71. 	}
  72. 	if (Stoned) you_are("turning to stone");
  73. 	if (Slimed) you_are("turning into slime");
  74. 	if (Strangled) you_are((u.uburied) ? "buried" : "being strangled");
  75. 	if (Glib) {
  76. 		Sprintf(buf, "slippery %s", makeplural(body_part(FINGER)));
  77. 		you_have(buf);
  78. 	}
  79. 	if (Fumbling) enl_msg("You fumble", "", "d", "");
  80. 	if (Wounded_legs
  81. #ifdef STEED
  82. 	    && !u.usteed
  83. #endif
  84. 			  ) {
  85. 		Sprintf(buf, "wounded %s", makeplural(body_part(LEG)));
  86. 		you_have(buf);
  87. 	}
  88. #if defined(WIZARD) && defined(STEED)
  89. 	if (Wounded_legs && u.usteed && wizard) {
  90. 	    Strcpy(buf, x_monnam(u.usteed, ARTICLE_YOUR, (char *)0, 
  91. 		    SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION, FALSE));
  92. 	    *buf = highc(*buf);
  93. 	    enl_msg(buf, " has", " had", " wounded legs");
  94. 	}
  95. #endif
  96. 	if (Sleeping) enl_msg("You ", "fall", "fell", " asleep");
  97. 	if (Hunger) enl_msg("You hunger", "", "ed", " rapidly");
  98.  
  99. 	/*** Vision and senses ***/
  100. 	if (See_invisible) enl_msg(You_, "see", "saw", " invisible");
  101. 	if (Blind_telepat) you_are("telepathic");
  102. 	if (Warning) you_are("warned");
  103. 	if (Warn_of_mon && flags.warntype) {
  104. 		Sprintf(buf, "aware of the presence of %s",
  105. 			(flags.warntype & M2_ORC) ? "orcs" :
  106. 			(flags.warntype & M2_DEMON) ? "demons" :
  107. 			something); 
  108. 		you_are(buf);
  109. 	}
  110. 	if (Undead_warning) you_are("warned of undead");
  111. 	if (Searching) you_have("automatic searching");
  112. 	if (Clairvoyant) you_are("clairvoyant");
  113. 	if (Infravision) you_have("infravision");
  114. 	if (Detect_monsters) you_are("sensing the presence of monsters");
  115. 	if (u.umconf) you_are("going to confuse monsters");
  116.  
  117. 	/*** Appearance and behavior ***/
  118. 	if (Adornment) {
  119. 	    int adorn = 0;
  120.  
  121. 	    if(uleft && uleft->otyp == RIN_ADORNMENT) adorn += uleft->spe;
  122. 	    if(uright && uright->otyp == RIN_ADORNMENT) adorn += uright->spe;
  123. 	    if (adorn < 0)
  124. 		you_are("poorly adorned");
  125. 	    else
  126. 		you_are("adorned");
  127. 	}
  128. 	if (Invisible) you_are("invisible");
  129. 	else if (Invis) you_are("invisible to others");
  130. 	/* ordinarily "visible" is redundant; this is a special case for
  131. 	   the situation when invisibility would be an expected attribute */
  132. 	else if ((HInvis || EInvis || pm_invisible(youmonst.data)) && BInvis)
  133. 	    you_are("visible");
  134. 	if (Displaced) you_are("displaced");
  135. 	if (Stealth) you_are("stealthy");
  136. 	if (Aggravate_monster) enl_msg("You aggravate", "", "d", " monsters");
  137. 	if (Conflict) enl_msg("You cause", "", "d", " conflict");
  138.  
  139. 	/*** Transportation ***/
  140. 	if (Jumping) you_can("jump");
  141. 	if (Teleportation) you_can("teleport");
  142. 	if (Teleport_control) you_have("teleport control");
  143. 	if (Lev_at_will) you_are("levitating, at will");
  144. 	else if (Levitation) you_are("levitating");	/* without control */
  145. 	else if (Flying) you_can("fly");
  146. 	if (Wwalking) you_can("walk on water");
  147. 	if (Swimming) you_can("swim");        
  148. 	if (Breathless) you_can("survive without air");
  149. 	else if (Amphibious) you_can("breathe water");
  150. 	if (Passes_walls) you_can("walk through walls");
  151. #ifdef STEED
  152. 	/* If you die while dismounting, u.usteed is still set.  Since several
  153. 	 * places in the done() sequence depend on u.usteed, just detect this
  154. 	 * special case. */
  155. 	if (u.usteed && (final < 2 || strcmp(killer, "riding accident"))) {
  156. 	    Sprintf(buf, "riding %s", y_monnam(u.usteed));
  157. 	    you_are(buf);
  158. 	}
  159. #endif
  160. 	if (u.uswallow) {
  161. 	    Sprintf(buf, "swallowed by %s", a_monnam(u.ustuck));
  162. #ifdef WIZARD
  163. 	    if (wizard) Sprintf(eos(buf), " (%u)", u.uswldtim);
  164. #endif
  165. 	    you_are(buf);
  166. 	} else if (u.ustuck) {
  167. 	    Sprintf(buf, "%s %s",
  168. 		    (Upolyd && sticks(youmonst.data)) ? "holding" : "held by",
  169. 		    a_monnam(u.ustuck));
  170. 	    you_are(buf);
  171. 	}
  172.  
  173. 	/*** Physical attributes ***/
  174. 	if (u.uhitinc)
  175. 	    you_have(enlght_combatinc("to hit", u.uhitinc, final, buf));
  176. 	if (u.udaminc)
  177. 	    you_have(enlght_combatinc("damage", u.udaminc, final, buf));
  178. 	if (Slow_digestion) you_have("slower digestion");
  179. 	if (Regeneration) enl_msg("You regenerate", "", "d", "");
  180. 	if (u.uspellprot || Protection) {
  181. 	    int prot = 0;
  182.  
  183. 	    if(uleft && uleft->otyp == RIN_PROTECTION) prot += uleft->spe;
  184. 	    if(uright && uright->otyp == RIN_PROTECTION) prot += uright->spe;
  185. 	    if (HProtection & INTRINSIC) prot += u.ublessed;
  186. 	    prot += u.uspellprot;
  187.  
  188. 	    if (prot < 0)
  189. 		you_are("ineffectively protected");
  190. 	    else
  191. 		you_are("protected");
  192. 	}
  193. 	if (Protection_from_shape_changers)
  194. 		you_are("protected from shape changers");
  195. 	if (Polymorph) you_are("polymorphing");
  196. 	if (Polymorph_control) you_have("polymorph control");
  197. 	if (u.ulycn >= LOW_PM) {
  198. 		Strcpy(buf, an(mons[u.ulycn].mname));
  199. 		you_are(buf);
  200. 	}
  201. 	if (Upolyd) {
  202. 	    if (u.umonnum == u.ulycn) Strcpy(buf, "in beast form");
  203. 	    else Sprintf(buf, "polymorphed into %s", an(youmonst.data->mname));
  204. #ifdef WIZARD
  205. 	    if (wizard) Sprintf(eos(buf), " (%d)", u.mtimedone);
  206. #endif
  207. 	    you_are(buf);
  208. 	}
  209. 	if (Unchanging) you_can("not change from your current form");
  210. 	if (Fast) you_are(Very_fast ? "very fast" : "fast");
  211. 	if (Reflecting) you_have("reflection");
  212. 	if (Free_action) you_have("free action");
  213. 	if (Fixed_abil) you_have("fixed abilities");
  214. 	if (Lifesaved)
  215. 		enl_msg("Your life ", "will be", "would have been", " saved");
  216. 	if (u.twoweap) you_are("wielding two weapons at once");
  217.  
  218. 	/*** Miscellany ***/
  219. 	if (Luck) {
  220. 	    ltmp = abs((int)Luck);
  221. 	    Sprintf(buf, "%s%slucky",
  222. 		    ltmp >= 10 ? "extremely " : ltmp >= 5 ? "very " : "",
  223. 		    Luck < 0 ? "un" : "");
  224. #ifdef WIZARD
  225. 	    if (wizard) Sprintf(eos(buf), " (%d)", Luck);
  226. #endif
  227. 	    you_are(buf);
  228. 	}
  229. #ifdef WIZARD
  230. 	 else if (wizard) enl_msg("Your luck ", "is", "was", " zero");
  231. #endif
  232. 	if (u.moreluck > 0) you_have("extra luck");
  233. 	else if (u.moreluck < 0) you_have("reduced luck");
  234. 	if (carrying(LUCKSTONE) || stone_luck(TRUE)) {
  235. 	    ltmp = stone_luck(FALSE);
  236. 	    if (ltmp <= 0)
  237. 		enl_msg("Bad luck ", "does", "did", " not time out for you");
  238. 	    if (ltmp >= 0)
  239. 		enl_msg("Good luck ", "does", "did", " not time out for you");
  240. 	}
  241.  
  242. 	if (u.ugangr) {
  243. 	    Sprintf(buf, " %sangry with you",
  244. 		    u.ugangr > 6 ? "extremely " : u.ugangr > 3 ? "very " : "");
  245. #ifdef WIZARD
  246. 	    if (wizard) Sprintf(eos(buf), " (%d)", u.ugangr);
  247. #endif
  248. 	    enl_msg(u_gname(), " is", " was", buf);
  249. 	} else
  250. 	    /*
  251. 	     * We need to suppress this when the game is over, because death
  252. 	     * can change the value calculated by can_pray(), potentially
  253. 	     * resulting in a false claim that you could have prayed safely.
  254. 	     */
  255. 	  if (!final) {
  256. #if 0
  257. 	    /* "can [not] safely pray" vs "could [not] have safely prayed" */
  258. 	    Sprintf(buf, "%s%ssafely pray%s", can_pray(FALSE) ? "" : "not ",
  259. 		    final ? "have " : "", final ? "ed" : "");
  260. #else
  261. 	    Sprintf(buf, "%ssafely pray", can_pray(FALSE) ? "" : "not ");
  262. #endif
  263. #ifdef WIZARD
  264. 	    if (wizard) Sprintf(eos(buf), " (%d)", u.ublesscnt);
  265. #endif
  266. 	    you_can(buf);
  267. 	}
  268.  
  269. {
  270. 	const char *p;
  271.  
  272. 	buf[0] = '\0';
  273. 	if (final < 2) {    /* still in progress, or quit/escaped/ascended */
  274. 	    p = "survived after being killed ";
  275. 	    switch (u.umortality) {
  276. 	    case 0:  p = !final ? (char *)0 : "survived";  break;
  277. 	    case 1:  Strcpy(buf, "once");  break;
  278. 	    case 2:  Strcpy(buf, "twice");  break;
  279. 	    case 3:  Strcpy(buf, "thrice");  break;
  280. 	    default: Sprintf(buf, "%d times", u.umortality);
  281. 		     break;
  282. 	    }
  283. 	} else {		/* game ended in character's death */
  284. 	    p = "are dead";
  285. 	    switch (u.umortality) {
  286. 	    case 0:  impossible("dead without dying?");
  287. 	    case 1:  break;			/* just "are dead" */
  288. 	    default: Sprintf(buf, " (%d%s time!)", u.umortality,
  289. 			     ordin(u.umortality));
  290. 		     break;
  291. 	    }
  292. 	}
  293. 	if (p) enl_msg(You_, "have been killed ", p, buf);
  294. }
  295.  
  296. 	display_nhwindow(en_win, TRUE);
  297. 	destroy_nhwindow(en_win);
  298. 	return;
  299. }

minimal_enlightenment[edit]

  1. /*
  2. * Courtesy function for non-debug, non-explorer mode players
  3. * to help refresh them about who/what they are.
  4. * Returns FALSE if menu cancelled (dismissed with ESC), TRUE otherwise.
  5. */
  6. STATIC_OVL boolean
  7. minimal_enlightenment()
  8. {
  9. 	winid tmpwin;
  10. 	menu_item *selected;
  11. 	anything any;
  12. 	int genidx, n;
  13. 	char buf[BUFSZ], buf2[BUFSZ];
  14. 	static const char untabbed_fmtstr[] = "%-15s: %-12s";
  15. 	static const char untabbed_deity_fmtstr[] = "%-17s%s";
  16. 	static const char tabbed_fmtstr[] = "%s:\t%-12s";
  17. 	static const char tabbed_deity_fmtstr[] = "%s\t%s";
  18. 	static const char *fmtstr;
  19. 	static const char *deity_fmtstr;
  20.  
  21. 	fmtstr = iflags.menu_tab_sep ? tabbed_fmtstr : untabbed_fmtstr;
  22. 	deity_fmtstr = iflags.menu_tab_sep ?
  23. 			tabbed_deity_fmtstr : untabbed_deity_fmtstr; 
  24. 	any.a_void = 0;
  25. 	buf[0] = buf2[0] = '\0';
  26. 	tmpwin = create_nhwindow(NHW_MENU);
  27. 	start_menu(tmpwin);
  28. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, "Starting", FALSE);
  29.  
  30. 	/* Starting name, race, role, gender */
  31. 	Sprintf(buf, fmtstr, "name", plname);
  32. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  33. 	Sprintf(buf, fmtstr, "race", urace.noun);
  34. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  35. 	Sprintf(buf, fmtstr, "role",
  36. 		(flags.initgend && urole.name.f) ? urole.name.f : urole.name.m);
  37. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  38. 	Sprintf(buf, fmtstr, "gender", genders[flags.initgend].adj);
  39. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  40.  
  41. 	/* Starting alignment */
  42. 	Sprintf(buf, fmtstr, "alignment", align_str(u.ualignbase[A_ORIGINAL]));
  43. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  44.  
  45. 	/* Current name, race, role, gender */
  46. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", FALSE);
  47. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, "Current", FALSE);
  48. 	Sprintf(buf, fmtstr, "race", Upolyd ? youmonst.data->mname : urace.noun);
  49. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  50. 	if (Upolyd) {
  51. 	    Sprintf(buf, fmtstr, "role (base)",
  52. 		(u.mfemale && urole.name.f) ? urole.name.f : urole.name.m);
  53. 	    add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  54. 	} else {
  55. 	    Sprintf(buf, fmtstr, "role",
  56. 		(flags.female && urole.name.f) ? urole.name.f : urole.name.m);
  57. 	    add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  58. 	}
  59. 	/* don't want poly_gender() here; it forces `2' for non-humanoids */
  60. 	genidx = is_neuter(youmonst.data) ? 2 : flags.female;
  61. 	Sprintf(buf, fmtstr, "gender", genders[genidx].adj);
  62. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  63. 	if (Upolyd && (int)u.mfemale != genidx) {
  64. 	    Sprintf(buf, fmtstr, "gender (base)", genders[u.mfemale].adj);
  65. 	    add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  66. 	}
  67.  
  68. 	/* Current alignment */
  69. 	Sprintf(buf, fmtstr, "alignment", align_str(u.ualign.type));
  70. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  71.  
  72. 	/* Deity list */
  73. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", FALSE);
  74. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, "Deities", FALSE);
  75. 	Sprintf(buf2, deity_fmtstr, align_gname(A_CHAOTIC),
  76. 	    (u.ualignbase[A_ORIGINAL] == u.ualign.type
  77. 		&& u.ualign.type == A_CHAOTIC) ? " (s,c)" :
  78. 	    (u.ualignbase[A_ORIGINAL] == A_CHAOTIC)       ? " (s)" :
  79. 	    (u.ualign.type   == A_CHAOTIC)       ? " (c)" : "");
  80. 	Sprintf(buf, fmtstr, "Chaotic", buf2);
  81. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  82.  
  83. 	Sprintf(buf2, deity_fmtstr, align_gname(A_NEUTRAL),
  84. 	    (u.ualignbase[A_ORIGINAL] == u.ualign.type
  85. 		&& u.ualign.type == A_NEUTRAL) ? " (s,c)" :
  86. 	    (u.ualignbase[A_ORIGINAL] == A_NEUTRAL)       ? " (s)" :
  87. 	    (u.ualign.type   == A_NEUTRAL)       ? " (c)" : "");
  88. 	Sprintf(buf, fmtstr, "Neutral", buf2);
  89. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  90.  
  91. 	Sprintf(buf2, deity_fmtstr, align_gname(A_LAWFUL),
  92. 	    (u.ualignbase[A_ORIGINAL] == u.ualign.type &&
  93. 		u.ualign.type == A_LAWFUL)  ? " (s,c)" :
  94. 	    (u.ualignbase[A_ORIGINAL] == A_LAWFUL)        ? " (s)" :
  95. 	    (u.ualign.type   == A_LAWFUL)        ? " (c)" : "");
  96. 	Sprintf(buf, fmtstr, "Lawful", buf2);
  97. 	add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  98.  
  99. 	end_menu(tmpwin, "Base Attributes");
  100. 	n = select_menu(tmpwin, PICK_NONE, &selected);
  101. 	destroy_nhwindow(tmpwin);
  102. 	return (n != -1);
  103. }

doattributes[edit]

  1. STATIC_PTR int
  2. doattributes()
  3. {
  4. 	if (!minimal_enlightenment())
  5. 		return 0;
  6. 	if (wizard || discover)
  7. 		enlightenment(0);
  8. 	return 0;
  9. }

doconduct[edit]

  1. /* KMH, #conduct
  2. * (shares enlightenment's tense handling)
  3. */
  4. STATIC_PTR int
  5. doconduct()
  6. {
  7. 	show_conduct(0);
  8. 	return 0;
  9. }

show_conduct[edit]

  1. void
  2. show_conduct(final)
  3. int final;
  4. {
  5. 	char buf[BUFSZ];
  6. 	int ngenocided;
  7.  
  8. 	/* Create the conduct window */
  9. 	en_win = create_nhwindow(NHW_MENU);
  10. 	putstr(en_win, 0, "Voluntary challenges:");
  11. 	putstr(en_win, 0, "");
  12.  
  13. 	if (!u.uconduct.food)
  14. 	    enl_msg(You_, "have gone", "went", " without food");
  15. 	    /* But beverages are okay */
  16. 	else if (!u.uconduct.unvegan)
  17. 	    you_have_X("followed a strict vegan diet");
  18. 	else if (!u.uconduct.unvegetarian)
  19. 	    you_have_been("vegetarian");
  20.  
  21. 	if (!u.uconduct.gnostic)
  22. 	    you_have_been("an atheist");
  23.  
  24. 	if (!u.uconduct.weaphit)
  25. 	    you_have_never("hit with a wielded weapon");
  26. #ifdef WIZARD
  27. 	else if (wizard) {
  28. 	    Sprintf(buf, "used a wielded weapon %ld time%s",
  29. 		    u.uconduct.weaphit, plur(u.uconduct.weaphit));
  30. 	    you_have_X(buf);
  31. 	}
  32. #endif
  33. 	if (!u.uconduct.killer)
  34. 	    you_have_been("a pacifist");
  35.  
  36. 	if (!u.uconduct.literate)
  37. 	    you_have_been("illiterate");
  38. #ifdef WIZARD
  39. 	else if (wizard) {
  40. 	    Sprintf(buf, "read items or engraved %ld time%s",
  41. 		    u.uconduct.literate, plur(u.uconduct.literate));
  42. 	    you_have_X(buf);
  43. 	}
  44. #endif
  45.  
  46. 	ngenocided = num_genocides();
  47. 	if (ngenocided == 0) {
  48. 	    you_have_never("genocided any monsters");
  49. 	} else {
  50. 	    Sprintf(buf, "genocided %d type%s of monster%s",
  51. 		    ngenocided, plur(ngenocided), plur(ngenocided));
  52. 	    you_have_X(buf);
  53. 	}
  54.  
  55. 	if (!u.uconduct.polypiles)
  56. 	    you_have_never("polymorphed an object");
  57. #ifdef WIZARD
  58. 	else if (wizard) {
  59. 	    Sprintf(buf, "polymorphed %ld item%s",
  60. 		    u.uconduct.polypiles, plur(u.uconduct.polypiles));
  61. 	    you_have_X(buf);
  62. 	}
  63. #endif
  64.  
  65. 	if (!u.uconduct.polyselfs)
  66. 	    you_have_never("changed form");
  67. #ifdef WIZARD
  68. 	else if (wizard) {
  69. 	    Sprintf(buf, "changed form %ld time%s",
  70. 		    u.uconduct.polyselfs, plur(u.uconduct.polyselfs));
  71. 	    you_have_X(buf);
  72. 	}
  73. #endif
  74.  
  75. 	if (!u.uconduct.wishes)
  76. 	    you_have_X("used no wishes");
  77. 	else {
  78. 	    Sprintf(buf, "used %ld wish%s",
  79. 		    u.uconduct.wishes, (u.uconduct.wishes > 1L) ? "es" : "");
  80. 	    you_have_X(buf);
  81.  
  82. 	    if (!u.uconduct.wisharti)
  83. 		enl_msg(You_, "have not wished", "did not wish",
  84. 			" for any artifacts");
  85. 	}
  86.  
  87. 	/* Pop up the window and wait for a key */
  88. 	display_nhwindow(en_win, TRUE);
  89. 	destroy_nhwindow(en_win);
  90. }
  91.  
  92. #endif /* OVLB */

cmdlist[edit]

This array defines handlers for all of Nethack's various commands. The func_tab structure is defined in func_tab.h. It has 4 fields, the key to press, a Boolean indicating whether or not you can perform the action while buried, a pointer to the function used to handle the command, and a string that presumably would describe the command, if any of the commands bothered to set that field.

  1. #ifdef OVL1
  2.  
  3. #ifndef M
  4. # ifndef NHSTDC
  5. #  define M(c)		(0x80 | (c))
  6. # else
  7. #  define M(c)		((c) - 128)
  8. # endif /* NHSTDC */
  9. #endif
  10. #ifndef C
  11. #define C(c)		(0x1f & (c))
  12. #endif
  13.  
  14. static const struct func_tab cmdlist[] = {
  15. 	{C('d'), FALSE, dokick}, /* "D" is for door!...?  Msg is in dokick.c */
  16. #ifdef WIZARD
  17. 	{C('e'), TRUE, wiz_detect},
  18. 	{C('f'), TRUE, wiz_map},
  19. 	{C('g'), TRUE, wiz_genesis},
  20. 	{C('i'), TRUE, wiz_identify},
  21. #endif
  22. 	{C('l'), TRUE, doredraw}, /* if number_pad is set */
  23. #ifdef WIZARD
  24. 	{C('o'), TRUE, wiz_where},
  25. #endif
  26. 	{C('p'), TRUE, doprev_message},
  27. 	{C('r'), TRUE, doredraw},
  28. 	{C('t'), TRUE, dotele},
  29. #ifdef WIZARD
  30. 	{C('v'), TRUE, wiz_level_tele},
  31. 	{C('w'), TRUE, wiz_wish},
  32. #endif
  33. 	{C('x'), TRUE, doattributes},
  34. #ifdef SUSPEND
  35. 	{C('z'), TRUE, dosuspend},
  36. #endif
  37. 	{'a', FALSE, doapply},
  38. 	{'A', FALSE, doddoremarm},
  39. 	{M('a'), TRUE, doorganize},
  40. /*	'b', 'B' : go sw */
  41. 	{'c', FALSE, doclose},
  42. 	{'C', TRUE, do_mname},
  43. 	{M('c'), TRUE, dotalk},
  44. 	{'d', FALSE, dodrop},
  45. 	{'D', FALSE, doddrop},
  46. 	{M('d'), FALSE, dodip},
  47. 	{'e', FALSE, doeat},
  48. 	{'E', FALSE, doengrave},
  49. 	{M('e'), TRUE, enhance_weapon_skill},
  50. 	{'f', FALSE, dofire},
  51. /*	'F' : fight (one time) */
  52. 	{M('f'), FALSE, doforce},
  53. /*	'g', 'G' : multiple go */
  54. /*	'h', 'H' : go west */
  55. 	{'h', TRUE, dohelp}, /* if number_pad is set */
  56. 	{'i', TRUE, ddoinv},
  57. 	{'I', TRUE, dotypeinv},		/* Robert Viduya */
  58. 	{M('i'), TRUE, doinvoke},
  59. /*	'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */
  60. 	{'j', FALSE, dojump}, /* if number_pad is on */
  61. 	{M('j'), FALSE, dojump},
  62. 	{'k', FALSE, dokick}, /* if number_pad is on */
  63. 	{'l', FALSE, doloot}, /* if number_pad is on */
  64. 	{M('l'), FALSE, doloot},
  65. /*	'n' prefixes a count if number_pad is on */
  66. 	{M('m'), TRUE, domonability},
  67. 	{'N', TRUE, ddocall}, /* if number_pad is on */
  68. 	{M('n'), TRUE, ddocall},
  69. 	{M('N'), TRUE, ddocall},
  70. 	{'o', FALSE, doopen},
  71. 	{'O', TRUE, doset},
  72. 	{M('o'), FALSE, dosacrifice},
  73. 	{'p', FALSE, dopay},
  74. 	{'P', FALSE, doputon},
  75. 	{M('p'), TRUE, dopray},
  76. 	{'q', FALSE, dodrink},
  77. 	{'Q', FALSE, dowieldquiver},
  78. 	{M('q'), TRUE, done2},
  79. 	{'r', FALSE, doread},
  80. 	{'R', FALSE, doremring},
  81. 	{M('r'), FALSE, dorub},
  82. 	{'s', TRUE, dosearch, "searching"},
  83. 	{'S', TRUE, dosave},
  84. 	{M('s'), FALSE, dosit},
  85. 	{'t', FALSE, dothrow},
  86. 	{'T', FALSE, dotakeoff},
  87. 	{M('t'), TRUE, doturn},
  88. /*	'u', 'U' : go ne */
  89. 	{'u', FALSE, dountrap}, /* if number_pad is on */
  90. 	{M('u'), FALSE, dountrap},
  91. 	{'v', TRUE, doversion},
  92. 	{'V', TRUE, dohistory},
  93. 	{M('v'), TRUE, doextversion},
  94. 	{'w', FALSE, dowield},
  95. 	{'W', FALSE, dowear},
  96. 	{M('w'), FALSE, dowipe},
  97. 	{'x', FALSE, doswapweapon},
  98. 	{'X', TRUE, enter_explore_mode},
  99. /*	'y', 'Y' : go nw */
  100. 	{'z', FALSE, dozap},
  101. 	{'Z', TRUE, docast},
  102. 	{'<', FALSE, doup},
  103. 	{'>', FALSE, dodown},
  104. 	{'/', TRUE, dowhatis},
  105. 	{'&', TRUE, dowhatdoes},
  106. 	{'?', TRUE, dohelp},
  107. 	{M('?'), TRUE, doextlist},
  108. #ifdef SHELL
  109. 	{'!', TRUE, dosh},
  110. #endif
  111. 	{'.', TRUE, donull, "waiting"},
  112. 	{' ', TRUE, donull, "waiting"},
  113. 	{',', FALSE, dopickup},
  114. 	{':', TRUE, dolook},
  115. 	{';', TRUE, doquickwhatis},
  116. 	{'^', TRUE, doidtrap},
  117. 	{'\\', TRUE, dodiscovered},		/* Robert Viduya */
  118. 	{'@', TRUE, dotogglepickup},
  119. 	{M('2'), FALSE, dotwoweapon},
  120. 	{WEAPON_SYM,  TRUE, doprwep},
  121. 	{ARMOR_SYM,  TRUE, doprarm},
  122. 	{RING_SYM,  TRUE, doprring},
  123. 	{AMULET_SYM, TRUE, dopramulet},
  124. 	{TOOL_SYM, TRUE, doprtool},
  125. 	{'*', TRUE, doprinuse},	/* inventory of all equipment in use */
  126. 	{GOLD_SYM, TRUE, doprgold},
  127. 	{SPBOOK_SYM, TRUE, dovspell},			/* Mike Stephenson */
  128. 	{'#', TRUE, doextcmd},
  129. 	{'_', TRUE, dotravel},
  130. 	{0,0,0,0}
  131. };

extcmdlist[edit]

  1. struct ext_func_tab extcmdlist[] = {
  2. 	{"adjust", "adjust inventory letters", doorganize, TRUE},
  3. 	{"chat", "talk to someone", dotalk, TRUE},	/* converse? */
  4. 	{"conduct", "list which challenges you have adhered to", doconduct, TRUE},
  5. 	{"dip", "dip an object into something", dodip, FALSE},
  6. 	{"enhance", "advance or check weapons skills", enhance_weapon_skill,
  7. 							TRUE},
  8. 	{"force", "force a lock", doforce, FALSE},
  9. 	{"invoke", "invoke an object's powers", doinvoke, TRUE},
  10. 	{"jump", "jump to a location", dojump, FALSE},
  11. 	{"loot", "loot a box on the floor", doloot, FALSE},
  12. 	{"monster", "use a monster's special ability", domonability, TRUE},
  13. 	{"name", "name an item or type of object", ddocall, TRUE},
  14. 	{"offer", "offer a sacrifice to the gods", dosacrifice, FALSE},
  15. 	{"pray", "pray to the gods for help", dopray, TRUE},
  16. 	{"quit", "exit without saving current game", done2, TRUE},
  17. #ifdef STEED
  18. 	{"ride", "ride (or stop riding) a monster", doride, FALSE},
  19. #endif
  20. 	{"rub", "rub a lamp or a stone", dorub, FALSE},
  21. 	{"sit", "sit down", dosit, FALSE},
  22. 	{"turn", "turn undead", doturn, TRUE},
  23. 	{"twoweapon", "toggle two-weapon combat", dotwoweapon, FALSE},
  24. 	{"untrap", "untrap something", dountrap, FALSE},
  25. 	{"version", "list compile time options for this version of NetHack",
  26. 		doextversion, TRUE},
  27. 	{"wipe", "wipe off your face", dowipe, FALSE},
  28. 	{"?", "get this list of extended commands", doextlist, TRUE},
  29. #if defined(WIZARD)
  30. 	/*
  31. 	 * There must be a blank entry here for every entry in the table
  32. 	 * below.
  33. 	 */
  34. 	{(char *)0, (char *)0, donull, TRUE},
  35. 	{(char *)0, (char *)0, donull, TRUE},
  36. #ifdef DEBUG_MIGRATING_MONS
  37. 	{(char *)0, (char *)0, donull, TRUE},
  38. #endif
  39. 	{(char *)0, (char *)0, donull, TRUE},
  40. 	{(char *)0, (char *)0, donull, TRUE},
  41. 	{(char *)0, (char *)0, donull, TRUE},
  42. #ifdef PORT_DEBUG
  43. 	{(char *)0, (char *)0, donull, TRUE},
  44. #endif
  45. 	{(char *)0, (char *)0, donull, TRUE},
  46. {(char *)0, (char *)0, donull, TRUE},
  47. 	{(char *)0, (char *)0, donull, TRUE},
  48. 	{(char *)0, (char *)0, donull, TRUE},
  49. #ifdef DEBUG
  50. 	{(char *)0, (char *)0, donull, TRUE},
  51. #endif
  52. 	{(char *)0, (char *)0, donull, TRUE},
  53. #endif
  54. 	{(char *)0, (char *)0, donull, TRUE}	/* sentinel */
  55. };

debug_extcmdlist[edit]

  1. #if defined(WIZARD)
  2. static const struct ext_func_tab debug_extcmdlist[] = {
  3. 	{"levelchange", "change experience level", wiz_level_change, TRUE},
  4. 	{"lightsources", "show mobile light sources", wiz_light_sources, TRUE},
  5. #ifdef DEBUG_MIGRATING_MONS
  6. 	{"migratemons", "migrate n random monsters", wiz_migrate_mons, TRUE},
  7. #endif
  8. 	{"monpolycontrol", "control monster polymorphs", wiz_mon_polycontrol, TRUE},
  9. 	{"panic", "test panic routine (fatal to game)", wiz_panic, TRUE},
  10. 	{"polyself", "polymorph self", wiz_polyself, TRUE},
  11. #ifdef PORT_DEBUG
  12. 	{"portdebug", "wizard port debug command", wiz_port_debug, TRUE},
  13. #endif
  14. 	{"seenv", "show seen vectors", wiz_show_seenv, TRUE},
  15. 	{"stats", "show memory statistics", wiz_show_stats, TRUE},
  16. 	{"timeout", "look at timeout queue", wiz_timeout_queue, TRUE},
  17. 	{"vision", "show vision array", wiz_show_vision, TRUE},
  18. #ifdef DEBUG
  19. 	{"wizdebug", "wizard debug command", wiz_debug_cmd, TRUE},
  20. #endif
  21. 	{"wmode", "show wall modes", wiz_show_wmodes, TRUE},
  22. 	{(char *)0, (char *)0, donull, TRUE}
  23. };

add_debug_extended_commands[edit]

  1. /*
  2. * Insert debug commands into the extended command list.  This function
  3. * assumes that the last entry will be the help entry.
  4. *
  5. * You must add entries in ext_func_tab every time you add one to the
  6. * debug_extcmdlist().
  7. */
  8. void
  9. add_debug_extended_commands()
  10. {
  11. 	int i, j, k, n;
  12.  
  13. 	/* count the # of help entries */
  14. 	for (n = 0; extcmdlist[n].ef_txt[0] != '?'; n++)
  15. 	    ;
  16.  
  17. 	for (i = 0; debug_extcmdlist[i].ef_txt; i++) {
  18. 	    for (j = 0; j < n; j++)
  19. 		if (strcmp(debug_extcmdlist[i].ef_txt, extcmdlist[j].ef_txt) < 0) break;
  20.  
  21. 	    /* insert i'th debug entry into extcmdlist[j], pushing down  */
  22. 	    for (k = n; k >= j; --k)
  23. 		extcmdlist[k+1] = extcmdlist[k];
  24. 	    extcmdlist[j] = debug_extcmdlist[i];
  25. 	    n++;	/* now an extra entry */
  26. 	}
  27. }

count_obj[edit]

  1. static const char template[] = "%-18s %4ld  %6ld";
  2. static const char count_str[] = "                   count  bytes";
  3. static const char separator[] = "------------------ -----  ------";
  4.  
  5. STATIC_OVL void
  6. count_obj(chain, total_count, total_size, top, recurse)
  7. 	struct obj *chain;
  8. 	long *total_count;
  9. 	long *total_size;
  10. 	boolean top;
  11. 	boolean recurse;
  12. {
  13. 	long count, size;
  14. 	struct obj *obj;
  15.  
  16. 	for (count = size = 0, obj = chain; obj; obj = obj->nobj) {
  17. 	    if (top) {
  18. 		count++;
  19. 		size += sizeof(struct obj) + obj->oxlth + obj->onamelth;
  20. 	    }
  21. 	    if (recurse && obj->cobj)
  22. 		count_obj(obj->cobj, total_count, total_size, TRUE, TRUE);
  23. 	}
  24. 	*total_count += count;
  25. 	*total_size += size;
  26. }

obj_chain[edit]

  1. STATIC_OVL void
  2. obj_chain(win, src, chain, total_count, total_size)
  3. 	winid win;
  4. 	const char *src;
  5. 	struct obj *chain;
  6. 	long *total_count;
  7. 	long *total_size;
  8. {
  9. 	char buf[BUFSZ];
  10. 	long count = 0, size = 0;
  11.  
  12. 	count_obj(chain, &count, &size, TRUE, FALSE);
  13. 	*total_count += count;
  14. 	*total_size += size;
  15. 	Sprintf(buf, template, src, count, size);
  16. 	putstr(win, 0, buf);
  17. }

mon_invent_chain[edit]

  1. STATIC_OVL void
  2. mon_invent_chain(win, src, chain, total_count, total_size)
  3. 	winid win;
  4. 	const char *src;
  5. 	struct monst *chain;
  6. 	long *total_count;
  7. 	long *total_size;
  8. {
  9. 	char buf[BUFSZ];
  10. 	long count = 0, size = 0;
  11. 	struct monst *mon;
  12.  
  13. 	for (mon = chain; mon; mon = mon->nmon)
  14. 	    count_obj(mon->minvent, &count, &size, TRUE, FALSE);
  15. 	*total_count += count;
  16. 	*total_size += size;
  17. 	Sprintf(buf, template, src, count, size);
  18. 	putstr(win, 0, buf);
  19. }

contained[edit]

  1. STATIC_OVL void
  2. contained(win, src, total_count, total_size)
  3. 	winid win;
  4. 	const char *src;
  5. 	long *total_count;
  6. 	long *total_size;
  7. {
  8. 	char buf[BUFSZ];
  9. 	long count = 0, size = 0;
  10. 	struct monst *mon;
  11.  
  12. 	count_obj(invent, &count, &size, FALSE, TRUE);
  13. 	count_obj(fobj, &count, &size, FALSE, TRUE);
  14. 	count_obj(level.buriedobjlist, &count, &size, FALSE, TRUE);
  15. 	count_obj(migrating_objs, &count, &size, FALSE, TRUE);
  16. 	/* DEADMONSTER check not required in this loop since they have no inventory */
  17. 	for (mon = fmon; mon; mon = mon->nmon)
  18. 	    count_obj(mon->minvent, &count, &size, FALSE, TRUE);
  19. 	for (mon = migrating_mons; mon; mon = mon->nmon)
  20. 	    count_obj(mon->minvent, &count, &size, FALSE, TRUE);
  21.  
  22. 	*total_count += count; *total_size += size;
  23.  
  24. 	Sprintf(buf, template, src, count, size);
  25. 	putstr(win, 0, buf);
  26. }

mon_chain[edit]

  1. STATIC_OVL void
  2. mon_chain(win, src, chain, total_count, total_size)
  3. 	winid win;
  4. 	const char *src;
  5. 	struct monst *chain;
  6. 	long *total_count;
  7. 	long *total_size;
  8. {
  9. 	char buf[BUFSZ];
  10. 	long count, size;
  11. 	struct monst *mon;
  12.  
  13. 	for (count = size = 0, mon = chain; mon; mon = mon->nmon) {
  14. 	    count++;
  15. 	    size += sizeof(struct monst) + mon->mxlth + mon->mnamelth;
  16. 	}
  17. 	*total_count += count;
  18. 	*total_size += size;
  19. 	Sprintf(buf, template, src, count, size);
  20. 	putstr(win, 0, buf);
  21. }

wiz_show_stats[edit]

  1. /*
  2. * Display memory usage of all monsters and objects on the level.
  3. */
  4. static int
  5. wiz_show_stats()
  6. {
  7. 	char buf[BUFSZ];
  8. 	winid win;
  9. 	long total_obj_size = 0, total_obj_count = 0;
  10. 	long total_mon_size = 0, total_mon_count = 0;
  11.  
  12. 	win = create_nhwindow(NHW_TEXT);
  13. 	putstr(win, 0, "Current memory statistics:");
  14. 	putstr(win, 0, "");
  15. 	Sprintf(buf, "Objects, size %d", (int) sizeof(struct obj));
  16. 	putstr(win, 0, buf);
  17. 	putstr(win, 0, "");
  18. 	putstr(win, 0, count_str);
  19.  
  20. 	obj_chain(win, "invent", invent, &total_obj_count, &total_obj_size);
  21. 	obj_chain(win, "fobj", fobj, &total_obj_count, &total_obj_size);
  22. 	obj_chain(win, "buried", level.buriedobjlist,
  23. 				&total_obj_count, &total_obj_size);
  24. 	obj_chain(win, "migrating obj", migrating_objs,
  25. 				&total_obj_count, &total_obj_size);
  26. 	mon_invent_chain(win, "minvent", fmon,
  27. 				&total_obj_count,&total_obj_size);
  28. 	mon_invent_chain(win, "migrating minvent", migrating_mons,
  29. 				&total_obj_count, &total_obj_size);
  30.  
  31. 	contained(win, "contained",
  32. 				&total_obj_count, &total_obj_size);
  33.  
  34. 	putstr(win, 0, separator);
  35. 	Sprintf(buf, template, "Total", total_obj_count, total_obj_size);
  36. 	putstr(win, 0, buf);
  37.  
  38. 	putstr(win, 0, "");
  39. 	putstr(win, 0, "");
  40. 	Sprintf(buf, "Monsters, size %d", (int) sizeof(struct monst));
  41. 	putstr(win, 0, buf);
  42. 	putstr(win, 0, "");
  43.  
  44. 	mon_chain(win, "fmon", fmon,
  45. 				&total_mon_count, &total_mon_size);
  46. 	mon_chain(win, "migrating", migrating_mons,
  47. 				&total_mon_count, &total_mon_size);
  48.  
  49. 	putstr(win, 0, separator);
  50. 	Sprintf(buf, template, "Total", total_mon_count, total_mon_size);
  51. 	putstr(win, 0, buf);
  52.  
  53. #if defined(__BORLANDC__) && !defined(_WIN32)
  54. 	show_borlandc_stats(win);
  55. #endif
  56.  
  57. 	display_nhwindow(win, FALSE);
  58. 	destroy_nhwindow(win);
  59. 	return 0;
  60. }

sanity_check[edit]

wiz_migrate_mons[edit]

  1. #ifdef DEBUG_MIGRATING_MONS
  2. static int
  3. wiz_migrate_mons()
  4. {
  5. 	int mcount = 0;
  6. 	char inbuf[BUFSZ];
  7. 	struct permonst *ptr;
  8. 	struct monst *mtmp;
  9. 	d_level tolevel;
  10. 	getlin("How many random monsters to migrate? [0]", inbuf);
  11. 	if (*inbuf == '\033') return 0;
  12. 	mcount = atoi(inbuf);
  13. 	if (mcount < 0 || mcount > (COLNO * ROWNO) || Is_botlevel(&u.uz))
  14. 		return 0;
  15. 	while (mcount > 0) {
  16. 		if (Is_stronghold(&u.uz))
  17. 		    assign_level(&tolevel, &valley_level);
  18. 		else
  19. 		    get_level(&tolevel, depth(&u.uz) + 1);
  20. 		ptr = rndmonst();
  21. 		mtmp = makemon(ptr, 0, 0, NO_MM_FLAGS);
  22. 		if (mtmp) migrate_to_level(mtmp, ledger_no(&tolevel),
  23. 				MIGR_RANDOM, (coord *)0);
  24. 		mcount--;
  25. 	}
  26. 	return 0;
  27. }
  28. #endif
  29.  
  30. #endif /* WIZARD */

rhack[edit]

  1. #define unctrl(c)	((c) <= C('z') ? (0x60 | (c)) : (c))
  2. #define unmeta(c)	(0x7f & (c))
  3.  
  4.  
  5. void
  6. rhack(cmd)
  7. register char *cmd;
  8. {
  9. 	boolean do_walk, do_rush, prefix_seen, bad_command,
  10. 		firsttime = (cmd == 0);
  11.  
  12. 	iflags.menu_requested = FALSE;
  13. 	if (firsttime) {
  14. 		flags.nopick = 0;
  15. 		cmd = parse();
  16. 	}
  17. 	if (*cmd == '\033') {
  18. 		flags.move = FALSE;
  19. 		return;
  20. 	}
  21. #ifdef REDO
  22. 	if (*cmd == DOAGAIN && !in_doagain && saveq[0]) {
  23. 		in_doagain = TRUE;
  24. 		stail = 0;
  25. 		rhack((char *)0);	/* read and execute command */
  26. 		in_doagain = FALSE;
  27. 		return;
  28. 	}
  29. 	/* Special case of *cmd == ' ' handled better below */
  30. 	if(!*cmd || *cmd == (char)0377)
  31. #else
  32. 	if(!*cmd || *cmd == (char)0377 || (!flags.rest_on_space && *cmd == ' '))
  33. #endif
  34. 	{
  35. 		nhbell();
  36. 		flags.move = FALSE;
  37. 		return;		/* probably we just had an interrupt */
  38. 	}
  39. 	if (iflags.num_pad && iflags.num_pad_mode == 1) {
  40. 		/* This handles very old inconsistent DOS/Windows behaviour
  41. 		 * in a new way: earlier, the keyboard handler mapped these,
  42. 		 * which caused counts to be strange when entered from the
  43. 		 * number pad. Now do not map them until here. 
  44. 		 */
  45. 		switch (*cmd) {
  46. 		    case '5':       *cmd = 'g'; break;
  47. 		    case M('5'):    *cmd = 'G'; break;
  48. 		    case M('0'):    *cmd = 'I'; break;
  49. 	}
  50. }
  51. 	/* handle most movement commands */
  52. 	do_walk = do_rush = prefix_seen = FALSE;
  53. 	flags.travel = iflags.travel1 = 0;
  54. 	switch (*cmd) {
  55. 	 case 'g':  if (movecmd(cmd[1])) {
  56. 			flags.run = 2;
  57. 			do_rush = TRUE;
  58. 		    } else
  59. 			prefix_seen = TRUE;
  60. 		    break;
  61. 	 case '5':  if (!iflags.num_pad) break;	/* else FALLTHRU */
  62. 	 case 'G':  if (movecmd(lowc(cmd[1]))) {
  63. 			flags.run = 3;
  64. 			do_rush = TRUE;
  65. 		    } else
  66. 			prefix_seen = TRUE;
  67. 		    break;
  68. 	 case '-':  if (!iflags.num_pad) break;	/* else FALLTHRU */
  69. 	/* Effects of movement commands and invisible monsters:
  70. 	 * m: always move onto space (even if 'I' remembered)
  71. 	 * F: always attack space (even if 'I' not remembered)
  72. 	 * normal movement: attack if 'I', move otherwise
  73. 	 */
  74. 	 case 'F':  if (movecmd(cmd[1])) {
  75. 			flags.forcefight = 1;
  76. 			do_walk = TRUE;
  77. 		    } else
  78. 			prefix_seen = TRUE;
  79. 		    break;
  80. 	 case 'm':  if (movecmd(cmd[1]) || u.dz) {
  81. 			flags.run = 0;
  82. 			flags.nopick = 1;
  83. 			if (!u.dz) do_walk = TRUE;
  84. 			else cmd[0] = cmd[1];	/* "m<" or "m>" */
  85. 		    } else
  86. 			prefix_seen = TRUE;
  87. 		    break;
  88. 	 case 'M':  if (movecmd(lowc(cmd[1]))) {
  89. 			flags.run = 1;
  90. 			flags.nopick = 1;
  91. 			do_rush = TRUE;
  92. 		    } else
  93. 			prefix_seen = TRUE;
  94. 		    break;
  95. 	 case '0':  if (!iflags.num_pad) break;
  96. 		    (void)ddoinv(); /* a convenience borrowed from the PC */
  97. 		    flags.move = FALSE;
  98. 		    multi = 0;
  99. 		    return;
  100. 	 case CMD_TRAVEL:
  101. 		    if (iflags.travelcmd) {
  102. 			    flags.travel = 1;
  103. 			    iflags.travel1 = 1;
  104. 			    flags.run = 8;
  105. 			    flags.nopick = 1;
  106. 			    do_rush = TRUE;
  107. 			    break;
  108. 		    }
  109. 		    /*FALLTHRU*/
  110. 	 default:   if (movecmd(*cmd)) {	/* ordinary movement */
  111. 			flags.run = 0;	/* only matters here if it was 8 */
  112. 			do_walk = TRUE;
  113. 		    } else if (movecmd(iflags.num_pad ?
  114. 				       unmeta(*cmd) : lowc(*cmd))) {
  115. 			flags.run = 1;
  116. 			do_rush = TRUE;
  117. 		    } else if (movecmd(unctrl(*cmd))) {
  118. 			flags.run = 3;
  119. 			do_rush = TRUE;
  120. 		    }
  121. 		    break;
  122. 	}
  123.  
  124. 	/* some special prefix handling */
  125. 	/* overload 'm' prefix for ',' to mean "request a menu" */
  126. 	if (prefix_seen && cmd[1] == ',') {
  127. 		iflags.menu_requested = TRUE;
  128. 		++cmd;
  129. 	}
  130.  
  131. 	if (do_walk) {
  132. 	    if (multi) flags.mv = TRUE;
  133. 	    domove();
  134. 	    flags.forcefight = 0;
  135. 	    return;
  136. 	} else if (do_rush) {
  137. 	    if (firsttime) {
  138. 		if (!multi) multi = max(COLNO,ROWNO);
  139. 		u.last_str_turn = 0;
  140. 	    }
  141. 	    flags.mv = TRUE;
  142. 	    domove();
  143. 	    return;
  144. 	} else if (prefix_seen && cmd[1] == '\033') {	/* <prefix><escape> */
  145. 	    /* don't report "unknown command" for change of heart... */
  146. 	    bad_command = FALSE;
  147. 	} else if (*cmd == ' ' && !flags.rest_on_space) {
  148. 	    bad_command = TRUE;		/* skip cmdlist[] loop */
  149.  
  150. 	/* handle all other commands */
  151. 	} else {
  152. 	    register const struct func_tab *tlist;
  153. 	    int res, NDECL((*func));
  154.  
  155. 	    for (tlist = cmdlist; tlist->f_char; tlist++) {
  156. 		if ((*cmd & 0xff) != (tlist->f_char & 0xff)) continue;
  157.  
  158. 		if (u.uburied && !tlist->can_if_buried) {
  159. 		    You_cant("do that while you are buried!");
  160. 		    res = 0;
  161. 		} else {
  162. 		    /* we discard 'const' because some compilers seem to have
  163. 		       trouble with the pointer passed to set_occupation() */
  164. 		    func = ((struct func_tab *)tlist)->f_funct;
  165. 		    if (tlist->f_text && !occupation && multi)
  166. 			set_occupation(func, tlist->f_text, multi);
  167. 		    res = (*func)();		/* perform the command */
  168. 		}
  169. 		if (!res) {
  170. 		    flags.move = FALSE;
  171. 		    multi = 0;
  172. 		}
  173. 		return;
  174. 	    }
  175. 	    /* if we reach here, cmd wasn't found in cmdlist[] */
  176. 	    bad_command = TRUE;
  177. 	}
  178.  
  179. 	if (bad_command) {
  180. 	    char expcmd[10];
  181. 	    register char *cp = expcmd;
  182.  
  183. 	    while (*cmd && (int)(cp - expcmd) < (int)(sizeof expcmd - 3)) {
  184. 		if (*cmd >= 040 && *cmd < 0177) {
  185. 		    *cp++ = *cmd++;
  186. 		} else if (*cmd & 0200) {
  187. 		    *cp++ = 'M';
  188. 		    *cp++ = '-';
  189. 		    *cp++ = *cmd++ &= ~0200;
  190. 		} else {
  191. 		    *cp++ = '^';
  192. 		    *cp++ = *cmd++ ^ 0100;
  193. 		}
  194. 	    }
  195. 	    *cp = '\0';
  196. 	    if (!prefix_seen || !iflags.cmdassist ||
  197. 		!help_dir(0, "Invalid direction key!"))
  198. 		Norep("Unknown command '%s'.", expcmd);
  199. 	}
  200. 	/* didn't move */
  201. 	flags.move = FALSE;
  202. 	multi = 0;
  203. 	return;
  204. }

xytod[edit]

  1. int
  2. xytod(x, y)	/* convert an x,y pair into a direction code */
  3. schar x, y;
  4. {
  5. 	register int dd;
  6.  
  7. 	for(dd = 0; dd < 8; dd++)
  8. 	    if(x == xdir[dd] && y == ydir[dd]) return dd;
  9.  
  10. 	return -1;
  11. }

dtoxy[edit]

  1. void
  2. dtoxy(cc,dd)	/* convert a direction code into an x,y pair */
  3. coord *cc;
  4. register int dd;
  5. {
  6. 	cc->x = xdir[dd];
  7. 	cc->y = ydir[dd];
  8. 	return;
  9. }

movecmd[edit]

  1. int
  2. movecmd(sym)	/* also sets u.dz, but returns false for <> */
  3. char sym;
  4. {
  5. 	register const char *dp;
  6. 	register const char *sdp;
  7. 	if(iflags.num_pad) sdp = ndir; else sdp = sdir;	/* DICE workaround */
  8.  
  9. 	u.dz = 0;
  10. 	if(!(dp = index(sdp, sym))) return 0;
  11. 	u.dx = xdir[dp-sdp];
  12. 	u.dy = ydir[dp-sdp];
  13. 	u.dz = zdir[dp-sdp];
  14. 	if (u.dx && u.dy && u.umonnum == PM_GRID_BUG) {
  15. 		u.dx = u.dy = 0;
  16. 		return 0;
  17. 	}
  18. 	return !u.dz;
  19. }

get_adjacent_loc[edit]

  1. /*
  2. * uses getdir() but unlike getdir() it specifically
  3. * produces coordinates using the direction from getdir()
  4. * and verifies that those coordinates are ok.
  5. *
  6. * If the call to getdir() returns 0, Never_mind is displayed.
  7. * If the resulting coordinates are not okay, emsg is displayed.
  8. *
  9. * Returns non-zero if coordinates in cc are valid.
  10. */
  11. int get_adjacent_loc(prompt,emsg,x,y,cc)
  12. const char *prompt, *emsg;
  13. xchar x,y;
  14. coord *cc;
  15. {
  16. 	xchar new_x, new_y;
  17. 	if (!getdir(prompt)) {
  18. 		pline(Never_mind);
  19. 		return 0;
  20. 	}
  21. 	new_x = x + u.dx;
  22. 	new_y = y + u.dy;
  23. 	if (cc && isok(new_x,new_y)) {
  24. 		cc->x = new_x;
  25. 		cc->y = new_y;
  26. 	} else {
  27. 		if (emsg) pline(emsg);
  28. 		return 0;
  29. 	}
  30. 	return 1;
  31. }

getdir[edit]

  1. int
  2. getdir(s)
  3. const char *s;
  4. {
  5. 	char dirsym;
  6.  
  7. #ifdef REDO
  8. 	if(in_doagain || *readchar_queue)
  9. 	    dirsym = readchar();
  10. 	else
  11. #endif
  12. 	    dirsym = yn_function ((s && *s != '^') ? s : "In what direction?",
  13. 					(char *)0, '\0');
  14. #ifdef REDO
  15. 	savech(dirsym);
  16. #endif
  17. 	if(dirsym == '.' || dirsym == 's')
  18. 		u.dx = u.dy = u.dz = 0;
  19. 	else if(!movecmd(dirsym) && !u.dz) {
  20. 		boolean did_help = FALSE;
  21. 		if(!index(quitchars, dirsym)) {
  22. 		    if (iflags.cmdassist) {
  23. 			did_help = help_dir((s && *s == '^') ? dirsym : 0,
  24. 					    "Invalid direction key!");
  25. 		    }
  26. 		    if (!did_help) pline("What a strange direction!");
  27. 		}
  28. 		return 0;
  29. 	}
  30. 	if(!u.dz && (Stunned || (Confusion && !rn2(5)))) confdir();
  31. 	return 1;
  32. }

help_dir[edit]

  1. STATIC_OVL boolean
  2. help_dir(sym, msg)
  3. char sym;
  4. const char *msg;
  5. {
  6. 	char ctrl;
  7. 	winid win;
  8. 	static const char wiz_only_list[] = "EFGIOVW";
  9. 	char buf[BUFSZ], buf2[BUFSZ], *expl;
  10.  
  11. 	win = create_nhwindow(NHW_TEXT);
  12. 	if (!win) return FALSE;
  13. 	if (msg) {
  14. 		Sprintf(buf, "cmdassist: %s", msg);
  15. 		putstr(win, 0, buf);
  16. 		putstr(win, 0, "");
  17. 	}
  18. 	if (letter(sym)) { 
  19. 	    sym = highc(sym);
  20. 	    ctrl = (sym - 'A') + 1;
  21. 	    if ((expl = dowhatdoes_core(ctrl, buf2))
  22. 		&& (!index(wiz_only_list, sym)
  23. #ifdef WIZARD
  24. 		    || wizard
  25. #endif
  26. 	                     )) {
  27. 		Sprintf(buf, "Are you trying to use ^%c%s?", sym,
  28. 			index(wiz_only_list, sym) ? "" :
  29. 			" as specified in the Guidebook");
  30. 		putstr(win, 0, buf);
  31. 		putstr(win, 0, "");
  32. 		putstr(win, 0, expl);
  33. 		putstr(win, 0, "");
  34. 		putstr(win, 0, "To use that command, you press");
  35. 		Sprintf(buf,
  36. 			"the <Ctrl> key, and the <%c> key at the same time.", sym);
  37. 		putstr(win, 0, buf);
  38. 		putstr(win, 0, "");
  39. 	    }
  40. 	}
  41. 	if (iflags.num_pad && u.umonnum == PM_GRID_BUG) {
  42. 	    putstr(win, 0, "Valid direction keys in your current form (with number_pad on) are:");
  43. 	    putstr(win, 0, "             8   ");
  44. 	    putstr(win, 0, "             |   ");
  45. 	    putstr(win, 0, "          4- . -6");
  46. 	    putstr(win, 0, "             |   ");
  47. 	    putstr(win, 0, "             2   ");
  48. 	} else if (u.umonnum == PM_GRID_BUG) {
  49. 	    putstr(win, 0, "Valid direction keys in your current form are:");
  50. 	    putstr(win, 0, "             k   ");
  51. 	    putstr(win, 0, "             |   ");
  52. 	    putstr(win, 0, "          h- . -l");
  53. 	    putstr(win, 0, "             |   ");
  54. 	    putstr(win, 0, "             j   ");
  55. 	} else if (iflags.num_pad) {
  56. 	    putstr(win, 0, "Valid direction keys (with number_pad on) are:");
  57. 	    putstr(win, 0, "          7  8  9");
  58. 	    putstr(win, 0, "           \\ | / ");
  59. 	    putstr(win, 0, "          4- . -6");
  60. 	    putstr(win, 0, "           / | \\ ");
  61. 	    putstr(win, 0, "          1  2  3");
  62. 	} else {
  63. 	    putstr(win, 0, "Valid direction keys are:");
  64. 	    putstr(win, 0, "          y  k  u");
  65. 	    putstr(win, 0, "           \\ | / ");
  66. 	    putstr(win, 0, "          h- . -l");
  67. 	    putstr(win, 0, "           / | \\ ");
  68. 	    putstr(win, 0, "          b  j  n");
  69. 	};
  70. 	putstr(win, 0, "");
  71. 	putstr(win, 0, "          <  up");
  72. 	putstr(win, 0, "          >  down");
  73. 	putstr(win, 0, "          .  direct at yourself");
  74. 	putstr(win, 0, "");
  75. 	putstr(win, 0, "(Suppress this message with !cmdassist in config file.)");
  76. 	display_nhwindow(win, FALSE);
  77. 	destroy_nhwindow(win);
  78. 	return TRUE;
  79. }
  80.  
  81. #endif /* OVL1 */

confdir[edit]

  1. #ifdef OVLB
  2.  
  3. void
  4. confdir()
  5. {
  6. 	register int x = (u.umonnum == PM_GRID_BUG) ? 2*rn2(4) : rn2(8);
  7. 	u.dx = xdir[x];
  8. 	u.dy = ydir[x];
  9. 	return;
  10. }
  11.  
  12. #endif /* OVLB */

isok[edit]

isok() takes two parameters, x and y coordinate, and returns 1 if the coordinate (x,y) is inside the map area, 0 otherwise.

  1. #ifdef OVL0
  2.  
  3. int
  4. isok(x,y)
  5. register int x, y;
  6. {
  7. 	/* x corresponds to curx, so x==1 is the first column. Ach. %% */
  8. 	return x >= 1 && x <= COLNO-1 && y >= 0 && y <= ROWNO-1;
  9. }

click_to_cmd[edit]

  1. static NEARDATA int last_multi;
  2.  
  3. /*
  4. * convert a MAP window position into a movecmd
  5. */
  6. const char *
  7. click_to_cmd(x, y, mod)
  8. int x, y, mod;
  9. {
  10. int dir;
  11. static char cmd[4];
  12. cmd[1]=0;
  13.  
  14. x -= u.ux;
  15. y -= u.uy;
  16.  
  17. if (iflags.travelcmd) {
  18. if (abs(x) <= 1 && abs(y) <= 1 ) {
  19. x = sgn(x), y = sgn(y);
  20. } else {
  21. u.tx = u.ux+x;
  22. u.ty = u.uy+y;
  23. cmd[0] = CMD_TRAVEL;
  24. return cmd;
  25. }
  26.  
  27. if(x == 0 && y == 0) {
  28. /* here */
  29. if(IS_FOUNTAIN(levl[u.ux][u.uy].typ) || IS_SINK(levl[u.ux][u.uy].typ)) {
  30. cmd[0]=mod == CLICK_1 ? 'q' : M('d');
  31. return cmd;
  32. } else if(IS_THRONE(levl[u.ux][u.uy].typ)) {
  33. cmd[0]=M('s');
  34. return cmd;
  35. } else if((u.ux == xupstair && u.uy == yupstair)
  36. || (u.ux == sstairs.sx && u.uy == sstairs.sy && sstairs.up)
  37. || (u.ux == xupladder && u.uy == yupladder)) {
  38. return "<";
  39. } else if((u.ux == xdnstair && u.uy == ydnstair)
  40. || (u.ux == sstairs.sx && u.uy == sstairs.sy && !sstairs.up)
  41. || (u.ux == xdnladder && u.uy == ydnladder)) {
  42. return ">";
  43. } else if(OBJ_AT(u.ux, u.uy)) {
  44. cmd[0] = Is_container(level.objects[u.ux][u.uy]) ? M('l') : ',';
  45. return cmd;
  46. } else {
  47. return "."; /* just rest */
  48. }
  49. }
  50.  
  51. /* directional commands */
  52.  
  53. dir = xytod(x, y);
  54.  
  55. 	if (!m_at(u.ux+x, u.uy+y) && !test_move(u.ux, u.uy, x, y, TEST_MOVE)) {
  56. cmd[1] = (iflags.num_pad ? ndir[dir] : sdir[dir]);
  57. cmd[2] = 0;
  58. if (IS_DOOR(levl[u.ux+x][u.uy+y].typ)) {
  59. /* slight assistance to the player: choose kick/open for them */
  60. if (levl[u.ux+x][u.uy+y].doormask & D_LOCKED) {
  61. cmd[0] = C('d');
  62. return cmd;
  63. }
  64. if (levl[u.ux+x][u.uy+y].doormask & D_CLOSED) {
  65. cmd[0] = 'o';
  66. return cmd;
  67. }
  68. }
  69. if (levl[u.ux+x][u.uy+y].typ <= SCORR) {
  70. cmd[0] = 's';
  71. cmd[1] = 0;
  72. return cmd;
  73. }
  74. }
  75. } else {
  76. /* convert without using floating point, allowing sloppy clicking */
  77. if(x > 2*abs(y))
  78. x = 1, y = 0;
  79. else if(y > 2*abs(x))
  80. x = 0, y = 1;
  81. else if(x < -2*abs(y))
  82. x = -1, y = 0;
  83. else if(y < -2*abs(x))
  84. x = 0, y = -1;
  85. else
  86. x = sgn(x), y = sgn(y);
  87.  
  88. if(x == 0 && y == 0)	/* map click on player to "rest" command */
  89. return ".";
  90.  
  91. dir = xytod(x, y);
  92. }
  93.  
  94. /* move, attack, etc. */
  95. cmd[1] = 0;
  96. if(mod == CLICK_1) {
  97. 	cmd[0] = (iflags.num_pad ? ndir[dir] : sdir[dir]);
  98. } else {
  99. 	cmd[0] = (iflags.num_pad ? M(ndir[dir]) :
  100. 		(sdir[dir] - 'a' + 'A')); /* run command */
  101. }
  102.  
  103. return cmd;
  104. }

parse[edit]

  1. STATIC_OVL char *
  2. parse()
  3. {
  4. #ifdef LINT	/* static char in_line[COLNO]; */
  5. 	char in_line[COLNO];
  6. #else
  7. 	static char in_line[COLNO];
  8. #endif
  9. 	register int foo;
  10. 	boolean prezero = FALSE;
  11.  
  12. 	multi = 0;
  13. 	flags.move = 1;
  14. 	flush_screen(1); /* Flush screen buffer. Put the cursor on the hero. */
  15.  
  16. 	if (!iflags.num_pad || (foo = readchar()) == 'n')
  17. 	    for (;;) {
  18. 		foo = readchar();
  19. 		if (foo >= '0' && foo <= '9') {
  20. 		    multi = 10 * multi + foo - '0';
  21. 		    if (multi < 0 || multi >= LARGEST_INT) multi = LARGEST_INT;
  22. 		    if (multi > 9) {
  23. 			clear_nhwindow(WIN_MESSAGE);
  24. 			Sprintf(in_line, "Count: %d", multi);
  25. 			pline(in_line);
  26. 			mark_synch();
  27. 		    }
  28. 		    last_multi = multi;
  29. 		    if (!multi && foo == '0') prezero = TRUE;
  30. 		} else break;	/* not a digit */
  31. 	    }
  32.  
  33. 	if (foo == '\033') {   /* esc cancels count (TH) */
  34. 	    clear_nhwindow(WIN_MESSAGE);
  35. 	    multi = last_multi = 0;
  36. # ifdef REDO
  37. 	} else if (foo == DOAGAIN || in_doagain) {
  38. 	    multi = last_multi;
  39. 	} else {
  40. 	    last_multi = multi;
  41. 	    savech(0);	/* reset input queue */
  42. 	    savech((char)foo);
  43. # endif
  44. 	}
  45.  
  46. 	if (multi) {
  47. 	    multi--;
  48. 	    save_cm = in_line;
  49. 	} else {
  50. 	    save_cm = (char *)0;
  51. 	}
  52. 	in_line[0] = foo;
  53. 	in_line[1] = '\0';
  54. 	if (foo == 'g' || foo == 'G' || foo == 'm' || foo == 'M' ||
  55. 	    foo == 'F' || (iflags.num_pad && (foo == '5' || foo == '-'))) {
  56. 	    foo = readchar();
  57. #ifdef REDO
  58. 	    savech((char)foo);
  59. #endif
  60. 	    in_line[1] = foo;
  61. 	    in_line[2] = 0;
  62. 	}
  63. 	clear_nhwindow(WIN_MESSAGE);
  64. 	if (prezero) in_line[0] = '\033';
  65. 	return(in_line);
  66. }
  67.  
  68. #endif /* OVL0 */

end_of_input[edit]

  1. #ifdef OVLB
  2.  
  3. #ifdef UNIX
  4. static
  5. void
  6. end_of_input()
  7. {
  8. #ifndef NOSAVEONHANGUP
  9. 	if (!program_state.done_hup++ && program_state.something_worth_saving)
  10. 	    (void) dosave0();
  11. #endif
  12. 	exit_nhwindows((char *)0);
  13. 	clearlocks();
  14. 	terminate(EXIT_SUCCESS);
  15. }
  16. #endif
  17.  
  18. #endif /* OVLB */

readchar[edit]

The readchar function waits for an event from the keyboard and returns the next character typed by a user. NetHack has many reasons to need to wait for your command: you might on the map, at a menu, at a "-- More --" prompt, or elsewhere. The readchar functions acts as a gate through which all of these places obtain your instruction. Most of the calls to readchar are elsewhere in cmd.c, though two are in invent.c.

  1. #ifdef OVL0
  2.  
  3. char
  4. readchar()
  5. {
  6. 	register int sym;
  7. 	int x = u.ux, y = u.uy, mod = 0;
  8.  
  9. 	if ( *readchar_queue )
  10. 	    sym = *readchar_queue++;
  11. 	else
  12. #ifdef REDO
  13. 	    sym = in_doagain ? Getchar() : nh_poskey(&x, &y, &mod);
  14. #else
  15. 	    sym = Getchar();
  16. #endif
  17.  
  18. #ifdef UNIX
  19. # ifdef NR_OF_EOFS
  20. 	if (sym == EOF) {
  21. 	    register int cnt = NR_OF_EOFS;
  22. 	  /*
  23. 	   * Some SYSV systems seem to return EOFs for various reasons
  24. 	   * (?like when one hits break or for interrupted systemcalls?),
  25. 	   * and we must see several before we quit.
  26. 	   */
  27. 	    do {
  28. 		clearerr(stdin);	/* omit if clearerr is undefined */
  29. 		sym = Getchar();
  30. 	    } while (--cnt && sym == EOF);
  31. 	}
  32. # endif /* NR_OF_EOFS */
  33. 	if (sym == EOF)
  34. 	    end_of_input();
  35. #endif /* UNIX */
  36.  
  37. 	if(sym == 0) {
  38. 	    /* click event */
  39. 	    readchar_queue = click_to_cmd(x, y, mod);
  40. 	    sym = *readchar_queue++;
  41. 	}
  42. 	return((char) sym);
  43. }

The C language getchar function waits for a character on the standard input and use it. Though the tty window port could use getchar to access keyboard events, the other window ports must use different mechanisms, like X11 events or Qt signals.

Thus, the DevTeam now uses a Getchar macro (starting with an uppercase G). This macro calls a window-port-specific function to grab the key. Thus the Getchar macro takes the place of the getchar function that NetHack used when it was a tty-only game.

Given this, it seems strange that the NR_OF_EOFS code is here. On a SYSV system, NR_OF_EOFS became 20 at cmd.c#line14. This crude hack attempts to distinguish a permanent end-of-file (EOF) from a temporary interruption by re-reading the character 20 times. (The more correct way to do this would be to check the global errno variable for the EINTR error from the Unix read system call.) The strange situation is that this hack calls clearerr(stdin) even if standard input is not the source of our key events. It would be reasonable to move this code to the tty-specific implementation of the Getchar function.

Other than calling Getchar, the readchar function also needs to worry about mouse clicks from window ports that support them. It deals with them by calling the click_to_cmd function to translate the mouse click into equivalent key events. It then stores the key characters in the readchar_queue. Until this queue is empty, subsequent calls to readchar use this queue instead of requesting another event from Getchar.

dotravel[edit]

  1. STATIC_PTR int
  2. dotravel()
  3. {
  4. 	/* Keyboard travel command */
  5. 	static char cmd[2];
  6. 	coord cc;
  7.  
  8. 	if (!iflags.travelcmd) return 0;
  9. 	cmd[1]=0;
  10. 	cc.x = iflags.travelcc.x;
  11. 	cc.y = iflags.travelcc.y;
  12. 	if (cc.x == -1 && cc.y == -1) {
  13. 	    /* No cached destination, start attempt from current position */
  14. 	    cc.x = u.ux;
  15. 	    cc.y = u.uy;
  16. 	}
  17. 	pline("Where do you want to travel to?");
  18. 	if (getpos(&cc, TRUE, "the desired destination") < 0) {
  19. 		/* user pressed ESC */
  20. 		return 0;
  21. 	}
  22. 	iflags.travelcc.x = u.tx = cc.x;
  23. 	iflags.travelcc.y = u.ty = cc.y;
  24. 	cmd[0] = CMD_TRAVEL;
  25. 	readchar_queue = cmd;
  26. 	return 0;
  27. }

wiz_port_debug[edit]

  1. #ifdef PORT_DEBUG
  2. # ifdef WIN32CON
  3. extern void NDECL(win32con_debug_keystrokes);
  4. extern void NDECL(win32con_handler_info);
  5. # endif
  6.  
  7. int
  8. wiz_port_debug()
  9. {
  10. 	int n, k;
  11. 	winid win;
  12. 	anything any;
  13. 	int item = 'a';
  14. 	int num_menu_selections;
  15. 	struct menu_selection_struct {
  16. 		char *menutext;
  17. 		void NDECL((*fn));
  18. 	} menu_selections[] = {
  19. #ifdef WIN32CON
  20. 		{"test win32 keystrokes", win32con_debug_keystrokes},
  21. 		{"show keystroke handler information", win32con_handler_info},
  22. #endif
  23. 		{(char *)0, (void NDECL((*)))0}		/* array terminator */
  24. 	};
  25.  
  26. 	num_menu_selections = SIZE(menu_selections) - 1;
  27. 	if (num_menu_selections > 0) {
  28. 		menu_item *pick_list;
  29. 		win = create_nhwindow(NHW_MENU);
  30. 		start_menu(win);
  31. 		for (k=0; k < num_menu_selections; ++k) {
  32. 			any.a_int = k+1;
  33. 			add_menu(win, NO_GLYPH, &any, item++, 0, ATR_NONE,
  34. 				menu_selections[k].menutext, MENU_UNSELECTED);
  35. 		}
  36. 		end_menu(win, "Which port debugging feature?");
  37. 		n = select_menu(win, PICK_ONE, &pick_list);
  38. 		destroy_nhwindow(win);
  39. 		if (n > 0) {
  40. 			n = pick_list[0].item.a_int - 1;
  41. 			free((genericptr_t) pick_list);
  42. 			/* execute the function */
  43. 			(*menu_selections[n].fn)();
  44. 		}
  45. 	} else
  46. 		pline("No port-specific debug capability defined.");
  47. 	return 0;
  48. }
  49. # endif /*PORT_DEBUG*/
  50.  
  51. #endif /* OVL0 */

yn_function[edit]

  1. #ifdef OVLB
  2. /*
  3. *   Parameter validator for generic yes/no function to prevent
  4. *   the core from sending too long a prompt string to the
  5. *   window port causing a buffer overflow there.
  6. */
  7. char
  8. yn_function(query,resp, def)
  9. const char *query,*resp;
  10. char def;
  11. {
  12. 	char qbuf[QBUFSZ];
  13. 	unsigned truncspot, reduction = sizeof(" [N]  ?") + 1;
  14.  
  15. 	if (resp) reduction += strlen(resp) + sizeof(" () ");
  16. 	if (strlen(query) < (QBUFSZ - reduction))
  17. 		return (*windowprocs.win_yn_function)(query, resp, def);
  18. 	paniclog("Query truncated: ", query);
  19. 	reduction += sizeof("...");
  20. 	truncspot = QBUFSZ - reduction;
  21. 	(void) strncpy(qbuf, query, (int)truncspot);
  22. 	qbuf[truncspot] = '\0';
  23. 	Strcat(qbuf,"...");
  24. 	return (*windowprocs.win_yn_function)(qbuf, resp, def);
  25. }
  26. #endif
  27.  
  28. /*cmd.c*/