]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.cmd.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.cmd.c,v 1.3 1995/03/23 08:29:52 cgd Exp $";
10 #include "def.func_tab.h"
12 int doredraw(),doredotopl(),dodrop(),dodrink(),doread(),dosearch(),dopickup(),
13 doversion(),doweararm(),dowearring(),doremarm(),doremring(),dopay(),doapply(),
14 dosave(),dowield(),ddoinv(),dozap(),ddocall(),dowhatis(),doengrave(),dotele(),
15 dohelp(),doeat(),doddrop(),do_mname(),doidtrap(),doprwep(),doprarm(),
16 doprring(),doprgold(),dodiscovered(),dotypeinv(),dolook(),doset(),
17 doup(), dodown(), done1(), donull(), dothrow(), doextcmd(), dodip(), dopray();
25 struct func_tab cmdlist
[]={
34 /* 'b', 'B' : go sw */
41 /* 'f', 'F' : multiple go (might become 'fight') */
42 /* 'g', 'G' : UNUSED */
43 /* 'h', 'H' : go west */
44 'I', dotypeinv
, /* Robert Viduya */
46 /* 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */
59 /* 'u', 'U' : go ne */
64 /* 'x', 'X' : UNUSED */
65 /* 'y', 'Y' : go nw */
80 '\\', dodiscovered
, /* Robert Viduya */
89 struct ext_func_tab extcmdlist
[] = {
95 extern char *parse(), lowc(), unctrl(), quitchars
[];
100 register struct func_tab
*tlist
= cmdlist
;
101 boolean firsttime
= FALSE
;
109 if(!*cmd
|| (*cmd
& 0377) == 0377 ||
110 (flags
.no_rest_on_space
&& *cmd
== ' ')){
113 return; /* probably we just had an interrupt */
117 if(multi
) flags
.mv
= 1;
121 if(movecmd(lowc(*cmd
))) {
125 if(!multi
) multi
= COLNO
;
130 if(flags
.run
>= 4) finddir();
139 if((*cmd
== 'f' && movecmd(cmd
[1])) || movecmd(unctrl(*cmd
))) {
143 if(*cmd
== 'F' && movecmd(lowc(cmd
[1]))) {
147 if(*cmd
== 'm' && movecmd(cmd
[1])) {
152 if(*cmd
== 'M' && movecmd(lowc(cmd
[1]))) {
158 if(*cmd
== cmd
[1] && (*cmd
== 'f' || *cmd
== 'F')) {
160 if(*cmd
== 'F') flags
.run
+= 2;
161 if(cmd
[2] == '-') flags
.run
+= 1;
165 while(tlist
->f_char
) {
166 if(*cmd
== tlist
->f_char
){
167 res
= (*(tlist
->f_funct
))();
177 register char *cp
= expcmd
;
178 while(*cmd
&& cp
-expcmd
< sizeof(expcmd
)-2) {
179 if(*cmd
>= 040 && *cmd
< 0177)
183 *cp
++ = *cmd
++ ^ 0100;
187 pline("Unknown command '%s'.", expcmd
);
189 multi
= flags
.move
= 0;
192 doextcmd() /* here after # - now read a full-word command */
195 register struct ext_func_tab
*efp
= extcmdlist
;
203 if(!strcmp(efp
->ef_txt
, buf
))
204 return((*(efp
->ef_funct
))());
207 pline("%s: unknown command.", buf
);
215 return( (sym
>= 'A' && sym
<= 'Z') ? sym
+'a'-'A' : sym
);
222 return( (sym
>= ('A' & 037) && sym
<= ('Z' & 037)) ? sym
+ 0140 : sym
);
225 /* 'rogue'-like direction commands */
226 char sdir
[] = "hykulnjb><";
227 schar xdir
[10] = { -1,-1, 0, 1, 1, 1, 0,-1, 0, 0 };
228 schar ydir
[10] = { 0,-1,-1,-1, 0, 1, 1, 1, 0, 0 };
229 schar zdir
[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1,-1 };
231 movecmd(sym
) /* also sets u.dz, but returns false for <> */
237 if(!(dp
= index(sdir
, sym
))) return(0);
238 u
.dx
= xdir
[dp
-sdir
];
239 u
.dy
= ydir
[dp
-sdir
];
240 u
.dz
= zdir
[dp
-sdir
];
249 if(s
) pline("In what direction?");
251 if(!movecmd(dirsym
) && !u
.dz
) {
252 if(!index(quitchars
, dirsym
))
253 pline("What a strange direction!");
256 if(Confusion
&& !u
.dz
)
270 register int i
, ui
= u
.di
;
271 for(i
= 0; i
<= 8; i
++){
272 if(flags
.run
& 1) ui
++; else ui
+= 7;
275 pline("Not near a wall.");
276 flags
.move
= multi
= 0;
279 if(!isroom(u
.ux
+xdir
[ui
], u
.uy
+ydir
[ui
]))
282 for(i
= 0; i
<= 8; i
++){
283 if(flags
.run
& 1) ui
+= 7; else ui
++;
286 pline("Not near a room.");
287 flags
.move
= multi
= 0;
290 if(isroom(u
.ux
+xdir
[ui
], u
.uy
+ydir
[ui
]))
298 isroom(x
,y
) register x
,y
; { /* what about POOL? */
299 return(isok(x
,y
) && (levl
[x
][y
].typ
== ROOM
||
300 (levl
[x
][y
].typ
>= LDOOR
&& flags
.run
>= 6)));
304 isok(x
,y
) register x
,y
; {
305 /* x corresponds to curx, so x==1 is the first column. Ach. %% */
306 return(x
>= 1 && x
<= COLNO
-1 && y
>= 0 && y
<= ROWNO
-1);