| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 
 | /*	$NetBSD: hack.cmd.c,v 1.7 2003/04/02 18:36:35 jsm Exp $	*/
/*
 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
 * Amsterdam
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * - Neither the name of the Stichting Centrum voor Wiskunde en
 * Informatica, nor the names of its contributors may be used to endorse or
 * promote products derived from this software without specific prior
 * written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/*
 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: hack.cmd.c,v 1.7 2003/04/02 18:36:35 jsm Exp $");
#endif				/* not lint */
#include	"hack.h"
#include	"extern.h"
#include	"def.func_tab.h"
const struct func_tab cmdlist[] = {
	{ '\020', doredotopl },
	{ '\022', doredraw },
	{ '\024', dotele },
#ifdef SUSPEND
	{ '\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 },
#ifdef SHELL
	{ '!', dosh },
#endif	/* SHELL */
	{ '.', donull },
	{ ' ', donull },
	{ ',', dopickup },
	{ ':', dolook },
	{ '^', doidtrap },
	{ '\\', dodiscovered },	/* Robert Viduya */
	{ WEAPON_SYM, doprwep },
	{ ARMOR_SYM, doprarm },
	{ RING_SYM, doprring },
	{ '$', doprgold },
	{ '#', doextcmd },
	{ 0, 0 }
};
const struct ext_func_tab extcmdlist[] = {
	{ "dip", dodip },
	{ "pray", dopray },
	{ (char *) 0, donull }
};
void
rhack(cmd)
	const char  *cmd;
{
	const struct func_tab *tlist = cmdlist;
	boolean         firsttime = FALSE;
	int res;
	if (!cmd) {
		firsttime = TRUE;
		flags.nopick = 0;
		cmd = parse();
	}
	if (!*cmd || (*cmd & 0377) == 0377 ||
	    (flags.no_rest_on_space && *cmd == ' ')) {
		bell();
		flags.move = 0;
		return;		/* probably we just had an interrupt */
	}
	if (movecmd(*cmd)) {
walk:
		if (multi)
			flags.mv = 1;
		domove();
		return;
	}
	if (movecmd(lowc(*cmd))) {
		flags.run = 1;
rush:
		if (firsttime) {
			if (!multi)
				multi = COLNO;
			u.last_str_turn = 0;
		}
		flags.mv = 1;
#ifdef QUEST
		if (flags.run >= 4)
			finddir();
		if (firsttime) {
			u.ux0 = u.ux + u.dx;
			u.uy0 = u.uy + u.dy;
		}
#endif	/* QUEST */
		domove();
		return;
	}
	if ((*cmd == 'f' && movecmd(cmd[1])) || movecmd(unctrl(*cmd))) {
		flags.run = 2;
		goto rush;
	}
	if (*cmd == 'F' && movecmd(lowc(cmd[1]))) {
		flags.run = 3;
		goto rush;
	}
	if (*cmd == 'm' && movecmd(cmd[1])) {
		flags.run = 0;
		flags.nopick = 1;
		goto walk;
	}
	if (*cmd == 'M' && movecmd(lowc(cmd[1]))) {
		flags.run = 1;
		flags.nopick = 1;
		goto rush;
	}
#ifdef QUEST
	if (*cmd == cmd[1] && (*cmd == 'f' || *cmd == 'F')) {
		flags.run = 4;
		if (*cmd == 'F')
			flags.run += 2;
		if (cmd[2] == '-')
			flags.run += 1;
		goto rush;
	}
#endif	/* QUEST */
	while (tlist->f_char) {
		if (*cmd == tlist->f_char) {
			res = (*(tlist->f_funct)) ();
			if (!res) {
				flags.move = 0;
				multi = 0;
			}
			return;
		}
		tlist++;
	}
	{
		char            expcmd[10];
		char  *cp = expcmd;
		while (*cmd && cp - expcmd < (int)sizeof(expcmd) - 2) {
			if (*cmd >= 040 && *cmd < 0177)
				*cp++ = *cmd++;
			else {
				*cp++ = '^';
				*cp++ = *cmd++ ^ 0100;
			}
		}
		*cp++ = 0;
		pline("Unknown command '%s'.", expcmd);
	}
	multi = flags.move = 0;
}
int
doextcmd()
{				/* here after # - now read a full-word
				 * command */
	char            buf[BUFSZ];
	const struct ext_func_tab *efp = extcmdlist;
	pline("# ");
	getlin(buf);
	clrlin();
	if (buf[0] == '\033')
		return (0);
	while (efp->ef_txt) {
		if (!strcmp(efp->ef_txt, buf))
			return ((*(efp->ef_funct)) ());
		efp++;
	}
	pline("%s: unknown command.", buf);
	return (0);
}
char
lowc(sym)
	char            sym;
{
	return ((sym >= 'A' && sym <= 'Z') ? sym + 'a' - 'A' : sym);
}
char
unctrl(sym)
	char            sym;
{
	return ((sym >= ('A' & 037) && sym <= ('Z' & 037)) ? sym + 0140 : sym);
}
/* 'rogue'-like direction commands */
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};
int
movecmd(sym)			/* also sets u.dz, but returns false for <> */
	char            sym;
{
	char  *dp;
	u.dz = 0;
	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);
}
int
getdir(s)
	boolean         s;
{
	char            dirsym;
	if (s)
		pline("In what direction?");
	dirsym = readchar();
	if (!movecmd(dirsym) && !u.dz) {
		if (!strchr(quitchars, dirsym))
			pline("What a strange direction!");
		return (0);
	}
	if (Confusion && !u.dz)
		confdir();
	return (1);
}
void
confdir()
{
	int x = rn2(8);
	u.dx = xdir[x];
	u.dy = ydir[x];
}
#ifdef QUEST
int
finddir()
{
	int    i, ui = u.di;
	for (i = 0; i <= 8; i++) {
		if (flags.run & 1)
			ui++;
		else
			ui += 7;
		ui %= 8;
		if (i == 8) {
			pline("Not near a wall.");
			flags.move = multi = 0;
			return (0);
		}
		if (!isroom(u.ux + xdir[ui], u.uy + ydir[ui]))
			break;
	}
	for (i = 0; i <= 8; i++) {
		if (flags.run & 1)
			ui += 7;
		else
			ui++;
		ui %= 8;
		if (i == 8) {
			pline("Not near a room.");
			flags.move = multi = 0;
			return (0);
		}
		if (isroom(u.ux + xdir[ui], u.uy + ydir[ui]))
			break;
	}
	u.di = ui;
	u.dx = xdir[ui];
	u.dy = ydir[ui];
	return 0;
}
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)));
}
#endif	/* QUEST */
int
isok(x, y)
	int x, y;
{
	/* x corresponds to curx, so x==1 is the first column. Ach. %% */
	return (x >= 1 && x <= COLNO - 1 && y >= 0 && y <= ROWNO - 1);
}
 |