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 */
| 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 */ |
| 3957 | int |
| 3958 | getdir(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 */ |
no test coverage detected