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
},
26 /* 'b', 'B' : go sw */
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 */
51 /* 'u', 'U' : go ne */
56 /* 'x', 'X' : UNUSED */
57 /* 'y', 'Y' : go nw */
72 { '\\', dodiscovered
}, /* Robert Viduya */
73 { WEAPON_SYM
, doprwep
},
74 { ARMOR_SYM
, doprarm
},
75 { RING_SYM
, doprring
},
81 struct ext_func_tab extcmdlist
[] = {
84 { (char *) 0, donull
}
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 */
109 if(multi
) flags
.mv
= 1;
113 if(movecmd(lowc(*cmd
))) {
117 if(!multi
) multi
= COLNO
;
122 if(flags
.run
>= 4) finddir();
131 if((*cmd
== 'f' && movecmd(cmd
[1])) || movecmd(unctrl(*cmd
))) {
135 if(*cmd
== 'F' && movecmd(lowc(cmd
[1]))) {
139 if(*cmd
== 'm' && movecmd(cmd
[1])) {
144 if(*cmd
== 'M' && movecmd(lowc(cmd
[1]))) {
150 if(*cmd
== cmd
[1] && (*cmd
== 'f' || *cmd
== 'F')) {
152 if(*cmd
== 'F') flags
.run
+= 2;
153 if(cmd
[2] == '-') flags
.run
+= 1;
157 while(tlist
->f_char
) {
158 if(*cmd
== tlist
->f_char
){
159 res
= (*(tlist
->f_funct
))();
170 while(*cmd
&& cp
-expcmd
< (int)sizeof(expcmd
)-2) {
171 if(*cmd
>= 040 && *cmd
< 0177)
175 *cp
++ = *cmd
++ ^ 0100;
179 pline("Unknown command '%s'.", expcmd
);
181 multi
= flags
.move
= 0;
185 doextcmd(void) /* here after # - now read a full-word command */
188 struct ext_func_tab
*efp
= extcmdlist
;
196 if(!strcmp(efp
->ef_txt
, buf
))
197 return((*(efp
->ef_funct
))());
200 pline("%s: unknown command.", buf
);
207 return( (sym
>= 'A' && sym
<= 'Z') ? sym
+'a'-'A' : sym
);
213 return( (sym
>= ('A' & 037) && sym
<= ('Z' & 037)) ? sym
+ 0140 : sym
);
216 /* 'rogue'-like direction commands */
217 char sdir
[] = "hykulnjb><";
218 schar xdir
[10] = { -1,-1, 0, 1, 1, 1, 0,-1, 0, 0 };
219 schar ydir
[10] = { 0,-1,-1,-1, 0, 1, 1, 1, 0, 0 };
220 schar zdir
[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1,-1 };
223 movecmd(char sym
) /* also sets u.dz, but returns false for <> */
228 if(!(dp
= index(sdir
, sym
))) return(0);
229 u
.dx
= xdir
[dp
-sdir
];
230 u
.dy
= ydir
[dp
-sdir
];
231 u
.dz
= zdir
[dp
-sdir
];
240 if(s
) pline("In what direction?");
242 if(!movecmd(dirsym
) && !u
.dz
) {
243 if(!index(quitchars
, dirsym
))
244 pline("What a strange direction!");
247 if(Confusion
&& !u
.dz
)
265 for(i
= 0; i
<= 8; i
++){
266 if(flags
.run
& 1) ui
++; else ui
+= 7;
269 pline("Not near a wall.");
270 flags
.move
= multi
= 0;
273 if(!isroom(u
.ux
+xdir
[ui
], u
.uy
+ydir
[ui
]))
276 for(i
= 0; i
<= 8; i
++){
277 if(flags
.run
& 1) ui
+= 7; else ui
++;
280 pline("Not near a room.");
281 flags
.move
= multi
= 0;
284 if(isroom(u
.ux
+xdir
[ui
], u
.uy
+ydir
[ui
]))
294 { /* what about POOL? */
295 return(isok(x
,y
) && (levl
[x
][y
].typ
== ROOM
||
296 (levl
[x
][y
].typ
>= LDOOR
&& flags
.run
>= 6)));
303 /* x corresponds to curx, so x==1 is the first column. Ach. %% */
304 return(x
>= 1 && x
<= COLNO
-1 && y
>= 0 && y
<= ROWNO
-1);
308 * done2 is a function that fits into cmdlist[] (int func(void))
309 * and calls done1 which discards its argument.