1997-10-19 20:56:41 +04:00
|
|
|
/* $NetBSD: hack.cmd.c,v 1.4 1997/10/19 16:57:39 christos Exp $ */
|
|
|
|
|
1993-08-02 21:16:36 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
|
|
|
|
*/
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:16:36 +04:00
|
|
|
#ifndef lint
|
1997-10-19 20:56:41 +04:00
|
|
|
__RCSID("$NetBSD: hack.cmd.c,v 1.4 1997/10/19 16:57:39 christos Exp $");
|
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#include "hack.h"
|
1997-10-19 20:56:41 +04:00
|
|
|
#include "extern.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "def.func_tab.h"
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
struct func_tab cmdlist[] = {
|
|
|
|
{ '\020', doredotopl },
|
|
|
|
{ '\022', doredraw },
|
|
|
|
{ '\024', dotele },
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef SUSPEND
|
1997-10-19 20:56:41 +04:00
|
|
|
{ '\032', dosuspend },
|
|
|
|
#endif { /* SUSPEND */
|
|
|
|
{ 'a', doapply },
|
|
|
|
/* 'A' : UNUSED */
|
|
|
|
/* 'b', 'B' : go sw */
|
|
|
|
{ 'c', ddocall },
|
|
|
|
{ 'C', do_mname },
|
|
|
|
{ 'd', dodrop },
|
|
|
|
{ 'D', doddrop },
|
|
|
|
{ 'e', doeat },
|
|
|
|
{ 'E', doengrave },
|
|
|
|
/* 'f', 'F' : multiple go (might become 'fight') */
|
|
|
|
/* 'g', 'G' : UNUSED */
|
|
|
|
/* 'h', 'H' : go west */
|
|
|
|
{ 'I', dotypeinv }, /* Robert Viduya */
|
|
|
|
{ 'i', ddoinv },
|
|
|
|
/* 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */
|
|
|
|
/* 'o', doopen, */
|
|
|
|
{ 'O', doset },
|
|
|
|
{ 'p', dopay },
|
|
|
|
{ 'P', dowearring },
|
|
|
|
{ 'q', dodrink },
|
|
|
|
{ 'Q', dodone },
|
|
|
|
{ 'r', doread },
|
|
|
|
{ 'R', doremring },
|
|
|
|
{ 's', dosearch },
|
|
|
|
{ 'S', dosave },
|
|
|
|
{ 't', dothrow },
|
|
|
|
{ 'T', doremarm },
|
|
|
|
/* 'u', 'U' : go ne */
|
|
|
|
{ 'v', doversion },
|
|
|
|
/* 'V' : UNUSED */
|
|
|
|
{ 'w', dowield },
|
|
|
|
{ 'W', doweararm },
|
|
|
|
/* 'x', 'X' : UNUSED */
|
|
|
|
/* 'y', 'Y' : go nw */
|
|
|
|
{ 'z', dozap },
|
|
|
|
/* 'Z' : UNUSED */
|
|
|
|
{ '<', doup },
|
|
|
|
{ '>', dodown },
|
|
|
|
{ '/', dowhatis },
|
|
|
|
{ '?', dohelp },
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef SHELL
|
1997-10-19 20:56:41 +04:00
|
|
|
{ '!', dosh },
|
|
|
|
#endif { /* SHELL */
|
|
|
|
{ '.', donull },
|
|
|
|
{ ' ', donull },
|
|
|
|
{ ',', dopickup },
|
|
|
|
{ ':', dolook },
|
|
|
|
{ '^', doidtrap },
|
|
|
|
{ '\\', dodiscovered }, /* Robert Viduya */
|
|
|
|
{ WEAPON_SYM, doprwep },
|
|
|
|
{ ARMOR_SYM, doprarm },
|
|
|
|
{ RING_SYM, doprring },
|
|
|
|
{ '$', doprgold },
|
|
|
|
{ '#', doextcmd },
|
|
|
|
{ 0, 0 }
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ext_func_tab extcmdlist[] = {
|
1997-10-19 20:56:41 +04:00
|
|
|
{ "dip", dodip },
|
|
|
|
{ "pray", dopray },
|
|
|
|
{ (char *) 0, donull }
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
rhack(cmd)
|
1997-10-19 20:56:41 +04:00
|
|
|
char *cmd;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct func_tab *tlist = cmdlist;
|
|
|
|
boolean firsttime = FALSE;
|
|
|
|
int res;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!cmd) {
|
1993-03-21 12:45:37 +03:00
|
|
|
firsttime = TRUE;
|
|
|
|
flags.nopick = 0;
|
|
|
|
cmd = parse();
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!*cmd || (*cmd & 0377) == 0377 ||
|
|
|
|
(flags.no_rest_on_space && *cmd == ' ')) {
|
1993-03-21 12:45:37 +03:00
|
|
|
bell();
|
|
|
|
flags.move = 0;
|
|
|
|
return; /* probably we just had an interrupt */
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (movecmd(*cmd)) {
|
|
|
|
walk:
|
|
|
|
if (multi)
|
|
|
|
flags.mv = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
domove();
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (movecmd(lowc(*cmd))) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.run = 1;
|
1997-10-19 20:56:41 +04:00
|
|
|
rush:
|
|
|
|
if (firsttime) {
|
|
|
|
if (!multi)
|
|
|
|
multi = COLNO;
|
1993-03-21 12:45:37 +03:00
|
|
|
u.last_str_turn = 0;
|
|
|
|
}
|
|
|
|
flags.mv = 1;
|
|
|
|
#ifdef QUEST
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.run >= 4)
|
|
|
|
finddir();
|
|
|
|
if (firsttime) {
|
1993-03-21 12:45:37 +03:00
|
|
|
u.ux0 = u.ux + u.dx;
|
|
|
|
u.uy0 = u.uy + u.dy;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* QUEST */
|
1993-03-21 12:45:37 +03:00
|
|
|
domove();
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if ((*cmd == 'f' && movecmd(cmd[1])) || movecmd(unctrl(*cmd))) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.run = 2;
|
|
|
|
goto rush;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (*cmd == 'F' && movecmd(lowc(cmd[1]))) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.run = 3;
|
|
|
|
goto rush;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (*cmd == 'm' && movecmd(cmd[1])) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.run = 0;
|
|
|
|
flags.nopick = 1;
|
|
|
|
goto walk;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (*cmd == 'M' && movecmd(lowc(cmd[1]))) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.run = 1;
|
|
|
|
flags.nopick = 1;
|
|
|
|
goto rush;
|
|
|
|
}
|
|
|
|
#ifdef QUEST
|
1997-10-19 20:56:41 +04:00
|
|
|
if (*cmd == cmd[1] && (*cmd == 'f' || *cmd == 'F')) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.run = 4;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (*cmd == 'F')
|
|
|
|
flags.run += 2;
|
|
|
|
if (cmd[2] == '-')
|
|
|
|
flags.run += 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
goto rush;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* QUEST */
|
|
|
|
while (tlist->f_char) {
|
|
|
|
if (*cmd == tlist->f_char) {
|
|
|
|
res = (*(tlist->f_funct)) ();
|
|
|
|
if (!res) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.move = 0;
|
|
|
|
multi = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tlist++;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
char expcmd[10];
|
|
|
|
char *cp = expcmd;
|
|
|
|
while (*cmd && cp - expcmd < sizeof(expcmd) - 2) {
|
|
|
|
if (*cmd >= 040 && *cmd < 0177)
|
|
|
|
*cp++ = *cmd++;
|
|
|
|
else {
|
|
|
|
*cp++ = '^';
|
|
|
|
*cp++ = *cmd++ ^ 0100;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
*cp++ = 0;
|
|
|
|
pline("Unknown command '%s'.", expcmd);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
multi = flags.move = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
doextcmd()
|
|
|
|
{ /* here after # - now read a full-word
|
|
|
|
* command */
|
|
|
|
char buf[BUFSZ];
|
|
|
|
struct ext_func_tab *efp = extcmdlist;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
pline("# ");
|
|
|
|
getlin(buf);
|
|
|
|
clrlin();
|
1997-10-19 20:56:41 +04:00
|
|
|
if (buf[0] == '\033')
|
|
|
|
return (0);
|
|
|
|
while (efp->ef_txt) {
|
|
|
|
if (!strcmp(efp->ef_txt, buf))
|
|
|
|
return ((*(efp->ef_funct)) ());
|
1993-03-21 12:45:37 +03:00
|
|
|
efp++;
|
|
|
|
}
|
|
|
|
pline("%s: unknown command.", buf);
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
char
|
|
|
|
lowc(sym)
|
1997-10-19 20:56:41 +04:00
|
|
|
char sym;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
return ((sym >= 'A' && sym <= 'Z') ? sym + 'a' - 'A' : sym);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
char
|
|
|
|
unctrl(sym)
|
1997-10-19 20:56:41 +04:00
|
|
|
char sym;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
return ((sym >= ('A' & 037) && sym <= ('Z' & 037)) ? sym + 0140 : sym);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 'rogue'-like direction commands */
|
1997-10-19 20:56:41 +04:00
|
|
|
char sdir[] = "hykulnjb><";
|
|
|
|
schar xdir[10] = {-1, -1, 0, 1, 1, 1, 0, -1, 0, 0};
|
|
|
|
schar ydir[10] = {0, -1, -1, -1, 0, 1, 1, 1, 0, 0};
|
|
|
|
schar zdir[10] = {0, 0, 0, 0, 0, 0, 0, 0, 1, -1};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
movecmd(sym) /* also sets u.dz, but returns false for <> */
|
|
|
|
char sym;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
char *dp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
u.dz = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!(dp = strchr(sdir, sym)))
|
|
|
|
return (0);
|
|
|
|
u.dx = xdir[dp - sdir];
|
|
|
|
u.dy = ydir[dp - sdir];
|
|
|
|
u.dz = zdir[dp - sdir];
|
|
|
|
return (!u.dz);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
getdir(s)
|
1997-10-19 20:56:41 +04:00
|
|
|
boolean s;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
char dirsym;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (s)
|
|
|
|
pline("In what direction?");
|
1993-03-21 12:45:37 +03:00
|
|
|
dirsym = readchar();
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!movecmd(dirsym) && !u.dz) {
|
|
|
|
if (!strchr(quitchars, dirsym))
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("What a strange direction!");
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (Confusion && !u.dz)
|
1993-03-21 12:45:37 +03:00
|
|
|
confdir();
|
1997-10-19 20:56:41 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
confdir()
|
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
int x = rn2(8);
|
1993-03-21 12:45:37 +03:00
|
|
|
u.dx = xdir[x];
|
|
|
|
u.dy = ydir[x];
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef QUEST
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
finddir()
|
|
|
|
{
|
|
|
|
int i, ui = u.di;
|
|
|
|
for (i = 0; i <= 8; i++) {
|
|
|
|
if (flags.run & 1)
|
|
|
|
ui++;
|
|
|
|
else
|
|
|
|
ui += 7;
|
1993-03-21 12:45:37 +03:00
|
|
|
ui %= 8;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (i == 8) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("Not near a wall.");
|
|
|
|
flags.move = multi = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!isroom(u.ux + xdir[ui], u.uy + ydir[ui]))
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
for (i = 0; i <= 8; i++) {
|
|
|
|
if (flags.run & 1)
|
|
|
|
ui += 7;
|
|
|
|
else
|
|
|
|
ui++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ui %= 8;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (i == 8) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("Not near a room.");
|
|
|
|
flags.move = multi = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (isroom(u.ux + xdir[ui], u.uy + ydir[ui]))
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
u.di = ui;
|
|
|
|
u.dx = xdir[ui];
|
|
|
|
u.dy = ydir[ui];
|
1997-10-19 20:56:41 +04:00
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
isroom(x, y)
|
|
|
|
int x, y;
|
|
|
|
{ /* what about POOL? */
|
|
|
|
return (isok(x, y) && (levl[x][y].typ == ROOM ||
|
|
|
|
(levl[x][y].typ >= LDOOR && flags.run >= 6)));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* QUEST */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
isok(x, y)
|
|
|
|
int x, y;
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
/* x corresponds to curx, so x==1 is the first column. Ach. %% */
|
1997-10-19 20:56:41 +04:00
|
|
|
return (x >= 1 && x <= COLNO - 1 && y >= 0 && y <= ROWNO - 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|