]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.vault.c
1 /* $NetBSD: hack.vault.c,v 1.7 2004/01/27 20:30:29 jsm 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.vault.c,v 1.7 2004/01/27 20:30:29 jsm Exp $");
74 { /* struct monst *mtmp; */
86 struct monst
*mtmp
, *mtmp2
;
97 #include "def.mkroom.h"
98 #define FCSIZ (ROWNO+COLNO)
104 int fcbeg
, fcend
; /* fcend: first unused pos */
105 xchar gdx
, gdy
; /* goal of guard's walk */
107 struct fakecorridor fakecorr
[FCSIZ
];
110 static const struct permonst pm_guard
=
111 {"guard", '@', 12, 12, -1, 4, 10, sizeof(struct egd
)};
113 static struct monst
*guard
;
115 #define EGD ((struct egd *)(&(guard->mextra[0])))
117 static void restfakecorr(void);
118 static int goldincorridor(void);
126 while ((fcbeg
= EGD
->fcbeg
) < EGD
->fcend
) {
127 fcx
= EGD
->fakecorr
[fcbeg
].fx
;
128 fcy
= EGD
->fakecorr
[fcbeg
].fy
;
129 if ((u
.ux
== fcx
&& u
.uy
== fcy
) || cansee(fcx
, fcy
) ||
132 crm
= &levl
[fcx
][fcy
];
133 crm
->typ
= EGD
->fakecorr
[fcbeg
].ftyp
;
139 /* it seems he left the corridor - let the guard disappear */
149 for (fci
= EGD
->fcbeg
; fci
< EGD
->fcend
; fci
++)
150 if (g_at(EGD
->fakecorr
[fci
].fx
, EGD
->fakecorr
[fci
].fy
))
159 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
171 int tmp
= inroom(u
.ux
, u
.uy
);
172 if (tmp
< 0 || rooms
[tmp
].rtype
!= VAULT
) {
176 if (++u
.uinvault
% 50 == 0 && (!guard
|| gdlevel
!= dlevel
)) {
178 int x
, y
, dd
, gx
, gy
;
180 /* first find the goal for the guard */
181 for (dd
= 1; (dd
< ROWNO
|| dd
< COLNO
); dd
++) {
182 for (y
= u
.uy
- dd
; y
<= u
.uy
+ dd
; y
++) {
183 if (y
< 0 || y
> ROWNO
- 1)
185 for (x
= u
.ux
- dd
; x
<= u
.ux
+ dd
; x
++) {
186 if (y
!= u
.uy
- dd
&& y
!= u
.uy
+ dd
&& x
!= u
.ux
- dd
)
188 if (x
< 0 || x
> COLNO
- 1)
190 if (levl
[x
][y
].typ
== CORR
)
195 impossible("Not a single corridor on this level??");
202 /* next find a good place for a door in the wall */
205 while (levl
[x
][y
].typ
== ROOM
) {
208 dx
= (gx
> x
) ? 1 : (gx
< x
) ? -1 : 0;
209 dy
= (gy
> y
) ? 1 : (gy
< y
) ? -1 : 0;
210 if (abs(gx
- x
) >= abs(gy
- y
))
216 /* make something interesting happen */
217 if (!(guard
= makemon(&pm_guard
, x
, y
)))
219 guard
->isgd
= guard
->mpeaceful
= 1;
222 if (!cansee(guard
->mx
, guard
->my
)) {
227 pline("Suddenly one of the Vault's guards enters!");
230 pline("\"Hello stranger, who are you?\" - ");
232 } while (!letter(buf
[0]));
234 if (!strcmp(buf
, "Croesus") || !strcmp(buf
, "Kroisos")) {
235 pline("\"Oh, yes - of course. Sorry to have disturbed you.\"");
241 pline("\"I don't know you.\"");
243 pline("\"Please follow me.\"");
245 pline("\"Most likely all that gold was stolen from this vault.\"");
246 pline("\"Please drop your gold (say d$ ) and follow me.\"");
251 EGD
->fakecorr
[0].fx
= x
;
252 EGD
->fakecorr
[0].fy
= y
;
253 EGD
->fakecorr
[0].ftyp
= levl
[x
][y
].typ
;
254 levl
[x
][y
].typ
= DOOR
;
262 int x
, y
, dx
, dy
, gx
, gy
, nx
, ny
, typ
;
263 struct fakecorridor
*fcp
;
265 if (!guard
|| gdlevel
!= dlevel
) {
266 impossible("Where is the guard?");
267 return (2); /* died */
269 if (u
.ugold
|| goldincorridor())
270 return (0); /* didnt move */
271 if (dist(guard
->mx
, guard
->my
) > 1 || EGD
->gddone
) {
273 return (0); /* didnt move */
277 /* look around (hor & vert only) for accessible places */
278 for (nx
= x
- 1; nx
<= x
+ 1; nx
++)
279 for (ny
= y
- 1; ny
<= y
+ 1; ny
++) {
280 if (nx
== x
|| ny
== y
)
281 if (nx
!= x
|| ny
!= y
)
283 if (!IS_WALL(typ
= (crm
= &levl
[nx
][ny
])->typ
) && typ
!= POOL
) {
285 for (i
= EGD
->fcbeg
; i
< EGD
->fcend
; i
++)
286 if (EGD
->fakecorr
[i
].fx
== nx
&&
287 EGD
->fakecorr
[i
].fy
== ny
)
289 if ((i
= inroom(nx
, ny
)) >= 0 && rooms
[i
].rtype
== VAULT
)
299 crm
->typ
= (typ
== SCORR
) ? CORR
: DOOR
;
308 dx
= (gx
> x
) ? 1 : (gx
< x
) ? -1 : 0;
309 dy
= (gy
> y
) ? 1 : (gy
< y
) ? -1 : 0;
310 if (abs(gx
- x
) >= abs(gy
- y
))
315 while ((typ
= (crm
= &levl
[nx
][ny
])->typ
) != 0) {
317 * in view of the above we must have IS_WALL(typ) or typ ==
320 /* must be a wall here */
321 if (isok(nx
+ nx
- x
, ny
+ ny
- y
) && typ
!= POOL
&&
322 ZAP_POS(levl
[nx
+ nx
- x
][ny
+ ny
- y
].typ
)) {
337 /* I don't like this, but ... */
343 if (cansee(nx
, ny
)) {
347 fcp
= &(EGD
->fakecorr
[EGD
->fcend
]);
348 if (EGD
->fcend
++ == FCSIZ
)
349 panic("fakecorr overflow");
371 struct monst
*mtmp
, *mtmp2
;