]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.cmd.c
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.cmd.c - version 1.0.3 */
5 #include "def.func_tab.h"
7 int doredraw(),doredotopl(),dodrop(),dodrink(),doread(),dosearch(),dopickup(),
8 doversion(),doweararm(),dowearring(),doremarm(),doremring(),dopay(),doapply(),
9 dosave(),dowield(),ddoinv(),dozap(),ddocall(),dowhatis(),doengrave(),dotele(),
10 dohelp(),doeat(),doddrop(),do_mname(),doidtrap(),doprwep(),doprarm(),
11 doprring(),doprgold(),dodiscovered(),dotypeinv(),dolook(),doset(),
12 doup(), dodown(), done1(), donull(), dothrow(), doextcmd(), dodip(), dopray();
20 struct func_tab cmdlist
[]={
29 /* 'b', 'B' : go sw */
36 /* 'f', 'F' : multiple go (might become 'fight') */
37 /* 'g', 'G' : UNUSED */
38 /* 'h', 'H' : go west */
39 'I', dotypeinv
, /* Robert Viduya */
41 /* 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */
54 /* 'u', 'U' : go ne */
59 /* 'x', 'X' : UNUSED */
60 /* 'y', 'Y' : go nw */
75 '\\', dodiscovered
, /* Robert Viduya */
84 struct ext_func_tab extcmdlist
[] = {
90 extern char *parse(), lowc(), unctrl(), quitchars
[];
95 register struct func_tab
*tlist
= cmdlist
;
96 boolean firsttime
= FALSE
;
104 if(!*cmd
|| (*cmd
& 0377) == 0377 ||
105 (flags
.no_rest_on_space
&& *cmd
== ' ')){
108 return; /* probably we just had an interrupt */
112 if(multi
) flags
.mv
= 1;
116 if(movecmd(lowc(*cmd
))) {
120 if(!multi
) multi
= COLNO
;
125 if(flags
.run
>= 4) finddir();
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')) {
155 if(*cmd
== 'F') flags
.run
+= 2;
156 if(cmd
[2] == '-') flags
.run
+= 1;
160 while(tlist
->f_char
) {
161 if(*cmd
== tlist
->f_char
){
162 res
= (*(tlist
->f_funct
))();
172 register char *cp
= expcmd
;
173 while(*cmd
&& cp
-expcmd
< sizeof(expcmd
)-2) {
174 if(*cmd
>= 040 && *cmd
< 0177)
178 *cp
++ = *cmd
++ ^ 0100;
182 pline("Unknown command '%s'.", expcmd
);
184 multi
= flags
.move
= 0;
187 doextcmd() /* here after # - now read a full-word command */
190 register struct ext_func_tab
*efp
= extcmdlist
;
198 if(!strcmp(efp
->ef_txt
, buf
))
199 return((*(efp
->ef_funct
))());
202 pline("%s: unknown command.", buf
);
210 return( (sym
>= 'A' && sym
<= 'Z') ? sym
+'a'-'A' : sym
);
217 return( (sym
>= ('A' & 037) && sym
<= ('Z' & 037)) ? sym
+ 0140 : sym
);
220 /* 'rogue'-like direction commands */
221 char sdir
[] = "hykulnjb><";
222 schar xdir
[10] = { -1,-1, 0, 1, 1, 1, 0,-1, 0, 0 };
223 schar ydir
[10] = { 0,-1,-1,-1, 0, 1, 1, 1, 0, 0 };
224 schar zdir
[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1,-1 };
226 movecmd(sym
) /* also sets u.dz, but returns false for <> */
232 if(!(dp
= index(sdir
, sym
))) return(0);
233 u
.dx
= xdir
[dp
-sdir
];
234 u
.dy
= ydir
[dp
-sdir
];
235 u
.dz
= zdir
[dp
-sdir
];
244 if(s
) pline("In what direction?");
246 if(!movecmd(dirsym
) && !u
.dz
) {
247 if(!index(quitchars
, dirsym
))
248 pline("What a strange direction!");
251 if(Confusion
&& !u
.dz
)
265 register int i
, ui
= u
.di
;
266 for(i
= 0; i
<= 8; i
++){
267 if(flags
.run
& 1) ui
++; else ui
+= 7;
270 pline("Not near a wall.");
271 flags
.move
= multi
= 0;
274 if(!isroom(u
.ux
+xdir
[ui
], u
.uy
+ydir
[ui
]))
277 for(i
= 0; i
<= 8; i
++){
278 if(flags
.run
& 1) ui
+= 7; else ui
++;
281 pline("Not near a room.");
282 flags
.move
= multi
= 0;
285 if(isroom(u
.ux
+xdir
[ui
], u
.uy
+ydir
[ui
]))
293 isroom(x
,y
) register x
,y
; { /* what about POOL? */
294 return(isok(x
,y
) && (levl
[x
][y
].typ
== ROOM
||
295 (levl
[x
][y
].typ
>= LDOOR
&& flags
.run
>= 6)));
299 isok(x
,y
) register x
,y
; {
300 /* x corresponds to curx, so x==1 is the first column. Ach. %% */
301 return(x
>= 1 && x
<= COLNO
-1 && y
>= 0 && y
<= ROWNO
-1);