MCPcopy Create free account
hub / github.com/NetHack/NetHack / getdir

Function getdir

src/cmd.c:3957–4119  ·  view source on GitHub ↗

prompt for a direction (specified via movement keystroke) and return it in u.dx, u.dy, and u.dz; function return value is 1 for ok, 0 otherwise */

Source from the content-addressed store, hash-verified

3955/* prompt for a direction (specified via movement keystroke) and return it
3956 in u.dx, u.dy, and u.dz; function return value is 1 for ok, 0 otherwise */
3957int
3958getdir(const char *s)
3959{
3960 char dirsym;
3961 int is_mov;
3962 struct _cmd_queue *cmdq = cmdq_pop();
3963
3964 if (cmdq) {
3965 if (cmdq->typ == CMDQ_DIR) {
3966 if (!cmdq->dirz) {
3967 dirsym = gc.Cmd.dirchars[xytodir(cmdq->dirx, cmdq->diry)];
3968 } else {
3969 dirsym = gc.Cmd.dirchars[(cmdq->dirz > 0) ? DIR_DOWN
3970 : DIR_UP];
3971 }
3972 } else if (cmdq->typ == CMDQ_KEY) {
3973 dirsym = cmdq->key;
3974 } else {
3975 cmdq_clear(CQ_CANNED);
3976 dirsym = '\0';
3977 impossible("getdir: command queue had no dir?");
3978 }
3979 free(cmdq);
3980 goto got_dirsym;
3981 }
3982
3983 retry:
3984 program_state.input_state = getdirInp;
3985 if (gi.in_doagain || *readchar_queue) {
3986 dirsym = readchar();
3987 } else {
3988 dirsym = yn_function((s && *s != '^') ? s : "In what direction?",
3989 (char *) 0, '\0', FALSE);
3990
3991 /* for the fuzzer, usually force the result to be a valid direction,
3992 but sometimes let it exercise the invalid direction code; we
3993 don't try to enforce no-diagonal for hero in grid bug form since
3994 things like '^' to look at adjacent trap shouldn't be bound by
3995 that (caller is expected to handle situations where it matters) */
3996 if (iflags.debug_fuzzer && rn2(20)) {
3997 switch (rn2(20)) {
3998 case 0:
3999 dirsym = gc.Cmd.spkeys[rn2(2) ? NHKF_GETDIR_SELF : NHKF_ESC];
4000 break;
4001 case 1:
4002 dirsym = gc.Cmd.dirchars[rn2(2) ? DIR_DOWN : DIR_UP];
4003 break;
4004 default:
4005 dirsym = gc.Cmd.dirchars[rn2(N_DIRS)];
4006 break;
4007 }
4008 }
4009 }
4010 /* remove the prompt string so caller won't have to */
4011 clear_nhwindow(WIN_MESSAGE);
4012
4013 if (redraw_cmd(dirsym)) { /* ^R */
4014 docrt_flags(docrtRefresh); /* redraw */

Callers 15

use_saddleFunction · 0.85
dorideFunction · 0.85
dochatFunction · 0.85
tiphatFunction · 0.85
invoke_fling_poisonFunction · 0.85
invoke_blinding_rayFunction · 0.85
use_pick_axeFunction · 0.85
throw_objFunction · 0.85
docloseFunction · 0.85
do_improvisationFunction · 0.85
wiz_telekinesisFunction · 0.85
dobreatheFunction · 0.85

Calls 15

cmdq_popFunction · 0.85
xytodirFunction · 0.85
cmdq_clearFunction · 0.85
readcharFunction · 0.85
yn_functionFunction · 0.85
rn2Function · 0.85
redraw_cmdFunction · 0.85
docrt_flagsFunction · 0.85
cmdq_add_keyFunction · 0.85
visctrlFunction · 0.85
getposFunction · 0.85
sgnFunction · 0.85

Tested by

no test coverage detected