1 /* $NetBSD: hack.cmd.c,v 1.9 2009/06/07 18:30:39 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.cmd.c,v 1.9 2009/06/07 18:30:39 dholland Exp $");
71 #include "def.func_tab.h"
73 static int doextcmd(void);
75 static const struct func_tab cmdlist
[] = {
76 { '\020', doredotopl
},
80 { '\032', dosuspend
},
84 /* 'b', 'B' : go sw */
91 /* 'f', 'F' : multiple go (might become 'fight') */
92 /* 'g', 'G' : UNUSED */
93 /* 'h', 'H' : go west */
94 { 'I', dotypeinv
}, /* Robert Viduya */
96 /* 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */
109 /* 'u', 'U' : go ne */
114 /* 'x', 'X' : UNUSED */
115 /* 'y', 'Y' : go nw */
130 { '\\', dodiscovered
}, /* Robert Viduya */
131 { WEAPON_SYM
, doprwep
},
132 { ARMOR_SYM
, doprarm
},
133 { RING_SYM
, doprring
},
139 static const struct ext_func_tab extcmdlist
[] = {
142 { (char *) 0, donull
}
145 static char lowc(int);
146 static char unctrl(int);
149 rhack(const char *cmd
)
151 const struct func_tab
*tlist
= cmdlist
;
152 boolean firsttime
= FALSE
;
160 if (!*cmd
|| (*cmd
& 0377) == 0377 ||
161 (flags
.no_rest_on_space
&& *cmd
== ' ')) {
164 return; /* probably we just had an interrupt */
173 if (movecmd(lowc(*cmd
))) {
193 if ((*cmd
== 'f' && movecmd(cmd
[1])) || movecmd(unctrl(*cmd
))) {
197 if (*cmd
== 'F' && movecmd(lowc(cmd
[1]))) {
201 if (*cmd
== 'm' && movecmd(cmd
[1])) {
206 if (*cmd
== 'M' && movecmd(lowc(cmd
[1]))) {
212 if (*cmd
== cmd
[1] && (*cmd
== 'f' || *cmd
== 'F')) {
221 while (tlist
->f_char
) {
222 if (*cmd
== tlist
->f_char
) {
223 res
= (*(tlist
->f_funct
)) ();
235 while (*cmd
&& cp
- expcmd
< (int)sizeof(expcmd
) - 2) {
236 if (*cmd
>= 040 && *cmd
< 0177)
240 *cp
++ = *cmd
++ ^ 0100;
244 pline("Unknown command '%s'.", expcmd
);
246 multi
= flags
.move
= 0;
251 { /* here after # - now read a full-word
254 const struct ext_func_tab
*efp
= extcmdlist
;
259 if (buf
[0] == '\033')
261 while (efp
->ef_txt
) {
262 if (!strcmp(efp
->ef_txt
, buf
))
263 return ((*(efp
->ef_funct
)) ());
266 pline("%s: unknown command.", buf
);
273 return ((sym
>= 'A' && sym
<= 'Z') ? sym
+ 'a' - 'A' : sym
);
279 return ((sym
>= ('A' & 037) && sym
<= ('Z' & 037)) ? sym
+ 0140 : sym
);
282 /* 'rogue'-like direction commands */
283 char sdir
[] = "hykulnjb><";
284 schar xdir
[10] = {-1, -1, 0, 1, 1, 1, 0, -1, 0, 0};
285 schar ydir
[10] = {0, -1, -1, -1, 0, 1, 1, 1, 0, 0};
286 static schar zdir
[10] = {0, 0, 0, 0, 0, 0, 0, 0, 1, -1};
289 movecmd(int sym
) /* also sets u.dz, but returns false for <> */
294 if (!(dp
= strchr(sdir
, sym
)))
296 u
.dx
= xdir
[dp
- sdir
];
297 u
.dy
= ydir
[dp
- sdir
];
298 u
.dz
= zdir
[dp
- sdir
];
308 pline("In what direction?");
310 if (!movecmd(dirsym
) && !u
.dz
) {
311 if (!strchr(quitchars
, dirsym
))
312 pline("What a strange direction!");
315 if (Confusion
&& !u
.dz
)
333 for (i
= 0; i
<= 8; i
++) {
340 pline("Not near a wall.");
341 flags
.move
= multi
= 0;
344 if (!isroom(u
.ux
+ xdir
[ui
], u
.uy
+ ydir
[ui
]))
347 for (i
= 0; i
<= 8; i
++) {
354 pline("Not near a room.");
355 flags
.move
= multi
= 0;
358 if (isroom(u
.ux
+ xdir
[ui
], u
.uy
+ ydir
[ui
]))
369 { /* what about POOL? */
370 return (isok(x
, y
) && (levl
[x
][y
].typ
== ROOM
||
371 (levl
[x
][y
].typ
>= LDOOR
&& flags
.run
>= 6)));
378 /* x corresponds to curx, so x==1 is the first column. Ach. %% */
379 return (x
>= 1 && x
<= COLNO
- 1 && y
>= 0 && y
<= ROWNO
- 1);