1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.cmd.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.cmd.c,v 1.4 1999/11/16 10:26:35 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.cmd.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */
7 #include "def.func_tab.h"
9 static int doextcmd(void);
10 static char lowc(char);
11 static char unctrl(char);
13 static bool isroom(int, int);
15 static int done2(void);
17 struct func_tab cmdlist
[]={
18 { '\020', doredotopl
},
22 { '\032', dosuspend
},
33 /*'f', 'F' : multiple go (might become 'fight') */
34 /*'g', 'G' : UNUSED */
35 /*'h', 'H' : go west */
36 { 'I', dotypeinv
}, /* Robert Viduya */
38 /*'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */
56 /*'x', 'X' : UNUSED */
72 { '\\', dodiscovered
}, /* Robert Viduya */
73 { WEAPON_SYM
, doprwep
},
74 { ARMOR_SYM
, doprarm
},
75 { RING_SYM
, doprring
},
81 struct ext_func_tab extcmdlist
[] = {
87 extern char quitchars
[];
90 rhack(const char *cmd
)
92 struct func_tab
*tlist
= cmdlist
;
93 boolean firsttime
= FALSE
;
101 if (!*cmd
|| (*cmd
& 0377) == 0377 ||
102 (flags
.no_rest_on_space
&& *cmd
== ' ')) {
105 return; /* probably we just had an interrupt */
114 if (movecmd(lowc(*cmd
))) {
134 if ((*cmd
== 'f' && movecmd(cmd
[1])) || movecmd(unctrl(*cmd
))) {
138 if (*cmd
== 'F' && movecmd(lowc(cmd
[1]))) {
142 if (*cmd
== 'm' && movecmd(cmd
[1])) {
147 if (*cmd
== 'M' && movecmd(lowc(cmd
[1]))) {
153 if (*cmd
== cmd
[1] && (*cmd
== 'f' || *cmd
== 'F')) {
162 while (tlist
->f_char
) {
163 if (*cmd
== tlist
->f_char
) {
164 res
= (*(tlist
->f_funct
))();
176 while (*cmd
&& cp
- expcmd
< (int)sizeof(expcmd
) - 2) {
177 if (*cmd
>= 040 && *cmd
< 0177)
181 *cp
++ = *cmd
++ ^ 0100;
185 pline("Unknown command '%s'.", expcmd
);
187 multi
= flags
.move
= 0;
191 doextcmd(void) /* here after # - now read a full-word command */
194 struct ext_func_tab
*efp
= extcmdlist
;
199 if (buf
[0] == '\033')
201 while (efp
->ef_txt
) {
202 if (!strcmp(efp
->ef_txt
, buf
))
203 return ((*(efp
->ef_funct
))());
206 pline("%s: unknown command.", buf
);
213 return ((sym
>= 'A' && sym
<= 'Z') ? sym
+ 'a' - 'A' : sym
);
219 return ((sym
>= ('A' & 037) && sym
<= ('Z' & 037)) ? sym
+ 0140 : sym
);
222 /* 'rogue'-like direction commands */
223 char sdir
[] = "hykulnjb><";
224 schar xdir
[10] = { -1, -1, 0, 1, 1, 1, 0, -1, 0, 0 };
225 schar ydir
[10] = { 0, -1, -1, -1, 0, 1, 1, 1, 0, 0 };
226 schar zdir
[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 };
229 movecmd(char sym
) /* also sets u.dz, but returns false for <> */
234 if (!(dp
= strchr(sdir
, sym
)))
236 u
.dx
= xdir
[dp
- sdir
];
237 u
.dy
= ydir
[dp
- sdir
];
238 u
.dz
= zdir
[dp
- sdir
];
248 pline("In what direction?");
250 if (!movecmd(dirsym
) && !u
.dz
) {
251 if (!strchr(quitchars
, dirsym
))
252 pline("What a strange direction!");
255 if (Confusion
&& !u
.dz
)
275 for (i
= 0; i
<= 8; i
++) {
282 pline("Not near a wall.");
283 flags
.move
= multi
= 0;
286 if (!isroom(u
.ux
+ xdir
[ui
], u
.uy
+ ydir
[ui
]))
289 for (i
= 0; i
<= 8; i
++) {
296 pline("Not near a room.");
297 flags
.move
= multi
= 0;
300 if (isroom(u
.ux
+ xdir
[ui
], u
.uy
+ ydir
[ui
]))
310 { /* what about POOL? */
311 return (isok(x
, y
) && (levl
[x
][y
].typ
== ROOM
||
312 (levl
[x
][y
].typ
>= LDOOR
&& flags
.run
>= 6)));
319 /* x corresponds to curx, so x==1 is the first column. Ach. %% */
320 return (x
>= 1 && x
<= COLNO
- 1 && y
>= 0 && y
<= ROWNO
- 1);
324 * done2 is a function that fits into cmdlist[] (int func(void))
325 * and calls done1 which discards its argument.