2009-06-07 22:30:39 +04:00
|
|
|
/* $NetBSD: hack.vault.c,v 1.8 2009/06/07 18:30:39 dholland Exp $ */
|
1997-10-19 20:56:41 +04:00
|
|
|
|
1993-08-02 21:18:41 +04:00
|
|
|
/*
|
2003-04-02 22:36:33 +04:00
|
|
|
* 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.
|
1993-08-02 21:18:41 +04:00
|
|
|
*/
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:18:41 +04:00
|
|
|
#ifndef lint
|
2009-06-07 22:30:39 +04:00
|
|
|
__RCSID("$NetBSD: hack.vault.c,v 1.8 2009/06/07 18:30:39 dholland Exp $");
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include "hack.h"
|
|
|
|
#include "extern.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef QUEST
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
setgd(void)
|
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
}
|
2009-06-07 22:30:39 +04:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
2009-06-07 22:30:39 +04:00
|
|
|
gd_move(void)
|
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
return (2);
|
|
|
|
}
|
2009-06-07 22:30:39 +04:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
gddead(void)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
}
|
2009-06-07 22:30:39 +04:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
replgd(struct monst *mtmp __unused, struct monst *mtmp2 __unused)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
}
|
2009-06-07 22:30:39 +04:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
invault(void)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
#include "def.mkroom.h"
|
|
|
|
#define FCSIZ (ROWNO+COLNO)
|
|
|
|
struct fakecorridor {
|
1997-10-19 20:56:41 +04:00
|
|
|
xchar fx, fy, ftyp;
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct egd {
|
1997-10-19 20:56:41 +04:00
|
|
|
int fcbeg, fcend; /* fcend: first unused pos */
|
|
|
|
xchar gdx, gdy; /* goal of guard's walk */
|
|
|
|
unsigned gddone:1;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct fakecorridor fakecorr[FCSIZ];
|
|
|
|
};
|
|
|
|
|
2001-03-26 00:43:58 +04:00
|
|
|
static const struct permonst pm_guard =
|
1997-10-19 20:56:41 +04:00
|
|
|
{"guard", '@', 12, 12, -1, 4, 10, sizeof(struct egd)};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
static struct monst *guard;
|
1997-10-19 20:56:41 +04:00
|
|
|
static int gdlevel;
|
1993-03-21 12:45:37 +03:00
|
|
|
#define EGD ((struct egd *)(&(guard->mextra[0])))
|
|
|
|
|
2004-01-27 23:30:28 +03:00
|
|
|
static void restfakecorr(void);
|
|
|
|
static int goldincorridor(void);
|
1997-10-19 20:56:41 +04:00
|
|
|
|
|
|
|
static void
|
2009-06-07 22:30:39 +04:00
|
|
|
restfakecorr(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
int fcx, fcy, fcbeg;
|
|
|
|
struct rm *crm;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
while ((fcbeg = EGD->fcbeg) < EGD->fcend) {
|
1993-03-21 12:45:37 +03:00
|
|
|
fcx = EGD->fakecorr[fcbeg].fx;
|
|
|
|
fcy = EGD->fakecorr[fcbeg].fy;
|
1997-10-19 20:56:41 +04:00
|
|
|
if ((u.ux == fcx && u.uy == fcy) || cansee(fcx, fcy) ||
|
|
|
|
m_at(fcx, fcy))
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
crm = &levl[fcx][fcy];
|
|
|
|
crm->typ = EGD->fakecorr[fcbeg].ftyp;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!crm->typ)
|
|
|
|
crm->seen = 0;
|
|
|
|
newsym(fcx, fcy);
|
1993-03-21 12:45:37 +03:00
|
|
|
EGD->fcbeg++;
|
|
|
|
}
|
|
|
|
/* it seems he left the corridor - let the guard disappear */
|
|
|
|
mondead(guard);
|
|
|
|
guard = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
static int
|
2009-06-07 22:30:39 +04:00
|
|
|
goldincorridor(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
int fci;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
for (fci = EGD->fcbeg; fci < EGD->fcend; fci++)
|
|
|
|
if (g_at(EGD->fakecorr[fci].fx, EGD->fakecorr[fci].fy))
|
|
|
|
return (1);
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
setgd(void)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
struct monst *mtmp;
|
|
|
|
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
|
|
|
|
if (mtmp->isgd) {
|
|
|
|
guard = mtmp;
|
|
|
|
gdlevel = dlevel;
|
|
|
|
return;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
guard = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
invault(void)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
int tmp = inroom(u.ux, u.uy);
|
|
|
|
if (tmp < 0 || rooms[tmp].rtype != VAULT) {
|
|
|
|
u.uinvault = 0;
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (++u.uinvault % 50 == 0 && (!guard || gdlevel != dlevel)) {
|
|
|
|
char buf[BUFSZ];
|
|
|
|
int x, y, dd, gx, gy;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
/* first find the goal for the guard */
|
|
|
|
for (dd = 1; (dd < ROWNO || dd < COLNO); dd++) {
|
|
|
|
for (y = u.uy - dd; y <= u.uy + dd; y++) {
|
|
|
|
if (y < 0 || y > ROWNO - 1)
|
|
|
|
continue;
|
|
|
|
for (x = u.ux - dd; x <= u.ux + dd; x++) {
|
|
|
|
if (y != u.uy - dd && y != u.uy + dd && x != u.ux - dd)
|
|
|
|
x = u.ux + dd;
|
|
|
|
if (x < 0 || x > COLNO - 1)
|
|
|
|
continue;
|
|
|
|
if (levl[x][y].typ == CORR)
|
|
|
|
goto fnd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impossible("Not a single corridor on this level??");
|
|
|
|
tele();
|
|
|
|
return;
|
|
|
|
fnd:
|
|
|
|
gx = x;
|
|
|
|
gy = y;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
/* next find a good place for a door in the wall */
|
|
|
|
x = u.ux;
|
|
|
|
y = u.uy;
|
|
|
|
while (levl[x][y].typ == ROOM) {
|
|
|
|
int dx, dy;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
|
|
|
|
dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
|
|
|
|
if (abs(gx - x) >= abs(gy - y))
|
|
|
|
x += dx;
|
|
|
|
else
|
|
|
|
y += dy;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
/* make something interesting happen */
|
|
|
|
if (!(guard = makemon(&pm_guard, x, y)))
|
|
|
|
return;
|
|
|
|
guard->isgd = guard->mpeaceful = 1;
|
|
|
|
EGD->gddone = 0;
|
|
|
|
gdlevel = dlevel;
|
|
|
|
if (!cansee(guard->mx, guard->my)) {
|
|
|
|
mondead(guard);
|
|
|
|
guard = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pline("Suddenly one of the Vault's guards enters!");
|
|
|
|
pmon(guard);
|
|
|
|
do {
|
|
|
|
pline("\"Hello stranger, who are you?\" - ");
|
|
|
|
getlin(buf);
|
|
|
|
} while (!letter(buf[0]));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strcmp(buf, "Croesus") || !strcmp(buf, "Kroisos")) {
|
|
|
|
pline("\"Oh, yes - of course. Sorry to have disturbed you.\"");
|
|
|
|
mondead(guard);
|
|
|
|
guard = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
clrlin();
|
|
|
|
pline("\"I don't know you.\"");
|
|
|
|
if (!u.ugold)
|
|
|
|
pline("\"Please follow me.\"");
|
|
|
|
else {
|
|
|
|
pline("\"Most likely all that gold was stolen from this vault.\"");
|
|
|
|
pline("\"Please drop your gold (say d$ ) and follow me.\"");
|
|
|
|
}
|
|
|
|
EGD->gdx = gx;
|
|
|
|
EGD->gdy = gy;
|
|
|
|
EGD->fcbeg = 0;
|
|
|
|
EGD->fakecorr[0].fx = x;
|
|
|
|
EGD->fakecorr[0].fy = y;
|
|
|
|
EGD->fakecorr[0].ftyp = levl[x][y].typ;
|
|
|
|
levl[x][y].typ = DOOR;
|
|
|
|
EGD->fcend = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
2009-06-07 22:30:39 +04:00
|
|
|
gd_move(void)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
int x, y, dx, dy, gx, gy, nx, ny, typ;
|
|
|
|
struct fakecorridor *fcp;
|
|
|
|
struct rm *crm;
|
|
|
|
if (!guard || gdlevel != dlevel) {
|
1993-03-21 12:45:37 +03:00
|
|
|
impossible("Where is the guard?");
|
1997-10-19 20:56:41 +04:00
|
|
|
return (2); /* died */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (u.ugold || goldincorridor())
|
|
|
|
return (0); /* didnt move */
|
|
|
|
if (dist(guard->mx, guard->my) > 1 || EGD->gddone) {
|
1993-03-21 12:45:37 +03:00
|
|
|
restfakecorr();
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0); /* didnt move */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
x = guard->mx;
|
|
|
|
y = guard->my;
|
|
|
|
/* look around (hor & vert only) for accessible places */
|
1997-10-19 20:56:41 +04:00
|
|
|
for (nx = x - 1; nx <= x + 1; nx++)
|
|
|
|
for (ny = y - 1; ny <= y + 1; ny++) {
|
|
|
|
if (nx == x || ny == y)
|
|
|
|
if (nx != x || ny != y)
|
|
|
|
if (isok(nx, ny))
|
|
|
|
if (!IS_WALL(typ = (crm = &levl[nx][ny])->typ) && typ != POOL) {
|
|
|
|
int i;
|
|
|
|
for (i = EGD->fcbeg; i < EGD->fcend; i++)
|
|
|
|
if (EGD->fakecorr[i].fx == nx &&
|
|
|
|
EGD->fakecorr[i].fy == ny)
|
|
|
|
goto nextnxy;
|
|
|
|
if ((i = inroom(nx, ny)) >= 0 && rooms[i].rtype == VAULT)
|
|
|
|
goto nextnxy;
|
|
|
|
/*
|
|
|
|
* seems we found a
|
|
|
|
* good place to
|
|
|
|
* leave him alone
|
|
|
|
*/
|
|
|
|
EGD->gddone = 1;
|
|
|
|
if (ACCESSIBLE(typ))
|
|
|
|
goto newpos;
|
|
|
|
crm->typ = (typ == SCORR) ? CORR : DOOR;
|
|
|
|
goto proceed;
|
|
|
|
}
|
|
|
|
nextnxy: ;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
nx = x;
|
|
|
|
ny = y;
|
|
|
|
gx = EGD->gdx;
|
|
|
|
gy = EGD->gdy;
|
|
|
|
dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
|
|
|
|
dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (abs(gx - x) >= abs(gy - y))
|
|
|
|
nx += dx;
|
|
|
|
else
|
|
|
|
ny += dy;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
while ((typ = (crm = &levl[nx][ny])->typ) != 0) {
|
|
|
|
/*
|
|
|
|
* in view of the above we must have IS_WALL(typ) or typ ==
|
|
|
|
* POOL
|
|
|
|
*/
|
|
|
|
/* must be a wall here */
|
|
|
|
if (isok(nx + nx - x, ny + ny - y) && typ != POOL &&
|
|
|
|
ZAP_POS(levl[nx + nx - x][ny + ny - y].typ)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
crm->typ = DOOR;
|
|
|
|
goto proceed;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (dy && nx != x) {
|
|
|
|
nx = x;
|
|
|
|
ny = y + dy;
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (dx && ny != y) {
|
|
|
|
ny = y;
|
|
|
|
nx = x + dx;
|
|
|
|
dy = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* I don't like this, but ... */
|
|
|
|
crm->typ = DOOR;
|
|
|
|
goto proceed;
|
|
|
|
}
|
|
|
|
crm->typ = CORR;
|
|
|
|
proceed:
|
1997-10-19 20:56:41 +04:00
|
|
|
if (cansee(nx, ny)) {
|
|
|
|
mnewsym(nx, ny);
|
|
|
|
prl(nx, ny);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
fcp = &(EGD->fakecorr[EGD->fcend]);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (EGD->fcend++ == FCSIZ)
|
|
|
|
panic("fakecorr overflow");
|
1993-03-21 12:45:37 +03:00
|
|
|
fcp->fx = nx;
|
|
|
|
fcp->fy = ny;
|
|
|
|
fcp->ftyp = typ;
|
|
|
|
newpos:
|
1997-10-19 20:56:41 +04:00
|
|
|
if (EGD->gddone)
|
|
|
|
nx = ny = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
guard->mx = nx;
|
|
|
|
guard->my = ny;
|
|
|
|
pmon(guard);
|
|
|
|
restfakecorr();
|
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
|
2009-06-07 22:30:39 +04:00
|
|
|
gddead(void)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
guard = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
replgd(struct monst *mtmp, struct monst *mtmp2)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp == guard)
|
1993-03-21 12:45:37 +03:00
|
|
|
guard = mtmp2;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* QUEST */
|