]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.vault.c
1 /* $NetBSD: hack.vault.c,v 1.5 2001/03/25 20:44:03 jsm Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.vault.c,v 1.5 2001/03/25 20:44:03 jsm Exp $");
17 { /* struct monst *mtmp; */
29 struct monst
*mtmp
, *mtmp2
;
40 #include "def.mkroom.h"
41 #define FCSIZ (ROWNO+COLNO)
47 int fcbeg
, fcend
; /* fcend: first unused pos */
48 xchar gdx
, gdy
; /* goal of guard's walk */
50 struct fakecorridor fakecorr
[FCSIZ
];
53 static const struct permonst pm_guard
=
54 {"guard", '@', 12, 12, -1, 4, 10, sizeof(struct egd
)};
56 static struct monst
*guard
;
58 #define EGD ((struct egd *)(&(guard->mextra[0])))
60 static void restfakecorr
__P((void));
61 static int goldincorridor
__P((void));
69 while ((fcbeg
= EGD
->fcbeg
) < EGD
->fcend
) {
70 fcx
= EGD
->fakecorr
[fcbeg
].fx
;
71 fcy
= EGD
->fakecorr
[fcbeg
].fy
;
72 if ((u
.ux
== fcx
&& u
.uy
== fcy
) || cansee(fcx
, fcy
) ||
75 crm
= &levl
[fcx
][fcy
];
76 crm
->typ
= EGD
->fakecorr
[fcbeg
].ftyp
;
82 /* it seems he left the corridor - let the guard disappear */
92 for (fci
= EGD
->fcbeg
; fci
< EGD
->fcend
; fci
++)
93 if (g_at(EGD
->fakecorr
[fci
].fx
, EGD
->fakecorr
[fci
].fy
))
102 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
114 int tmp
= inroom(u
.ux
, u
.uy
);
115 if (tmp
< 0 || rooms
[tmp
].rtype
!= VAULT
) {
119 if (++u
.uinvault
% 50 == 0 && (!guard
|| gdlevel
!= dlevel
)) {
121 int x
, y
, dd
, gx
, gy
;
123 /* first find the goal for the guard */
124 for (dd
= 1; (dd
< ROWNO
|| dd
< COLNO
); dd
++) {
125 for (y
= u
.uy
- dd
; y
<= u
.uy
+ dd
; y
++) {
126 if (y
< 0 || y
> ROWNO
- 1)
128 for (x
= u
.ux
- dd
; x
<= u
.ux
+ dd
; x
++) {
129 if (y
!= u
.uy
- dd
&& y
!= u
.uy
+ dd
&& x
!= u
.ux
- dd
)
131 if (x
< 0 || x
> COLNO
- 1)
133 if (levl
[x
][y
].typ
== CORR
)
138 impossible("Not a single corridor on this level??");
145 /* next find a good place for a door in the wall */
148 while (levl
[x
][y
].typ
== ROOM
) {
151 dx
= (gx
> x
) ? 1 : (gx
< x
) ? -1 : 0;
152 dy
= (gy
> y
) ? 1 : (gy
< y
) ? -1 : 0;
153 if (abs(gx
- x
) >= abs(gy
- y
))
159 /* make something interesting happen */
160 if (!(guard
= makemon(&pm_guard
, x
, y
)))
162 guard
->isgd
= guard
->mpeaceful
= 1;
165 if (!cansee(guard
->mx
, guard
->my
)) {
170 pline("Suddenly one of the Vault's guards enters!");
173 pline("\"Hello stranger, who are you?\" - ");
175 } while (!letter(buf
[0]));
177 if (!strcmp(buf
, "Croesus") || !strcmp(buf
, "Kroisos")) {
178 pline("\"Oh, yes - of course. Sorry to have disturbed you.\"");
184 pline("\"I don't know you.\"");
186 pline("\"Please follow me.\"");
188 pline("\"Most likely all that gold was stolen from this vault.\"");
189 pline("\"Please drop your gold (say d$ ) and follow me.\"");
194 EGD
->fakecorr
[0].fx
= x
;
195 EGD
->fakecorr
[0].fy
= y
;
196 EGD
->fakecorr
[0].ftyp
= levl
[x
][y
].typ
;
197 levl
[x
][y
].typ
= DOOR
;
205 int x
, y
, dx
, dy
, gx
, gy
, nx
, ny
, typ
;
206 struct fakecorridor
*fcp
;
208 if (!guard
|| gdlevel
!= dlevel
) {
209 impossible("Where is the guard?");
210 return (2); /* died */
212 if (u
.ugold
|| goldincorridor())
213 return (0); /* didnt move */
214 if (dist(guard
->mx
, guard
->my
) > 1 || EGD
->gddone
) {
216 return (0); /* didnt move */
220 /* look around (hor & vert only) for accessible places */
221 for (nx
= x
- 1; nx
<= x
+ 1; nx
++)
222 for (ny
= y
- 1; ny
<= y
+ 1; ny
++) {
223 if (nx
== x
|| ny
== y
)
224 if (nx
!= x
|| ny
!= y
)
226 if (!IS_WALL(typ
= (crm
= &levl
[nx
][ny
])->typ
) && typ
!= POOL
) {
228 for (i
= EGD
->fcbeg
; i
< EGD
->fcend
; i
++)
229 if (EGD
->fakecorr
[i
].fx
== nx
&&
230 EGD
->fakecorr
[i
].fy
== ny
)
232 if ((i
= inroom(nx
, ny
)) >= 0 && rooms
[i
].rtype
== VAULT
)
242 crm
->typ
= (typ
== SCORR
) ? CORR
: DOOR
;
251 dx
= (gx
> x
) ? 1 : (gx
< x
) ? -1 : 0;
252 dy
= (gy
> y
) ? 1 : (gy
< y
) ? -1 : 0;
253 if (abs(gx
- x
) >= abs(gy
- y
))
258 while ((typ
= (crm
= &levl
[nx
][ny
])->typ
) != 0) {
260 * in view of the above we must have IS_WALL(typ) or typ ==
263 /* must be a wall here */
264 if (isok(nx
+ nx
- x
, ny
+ ny
- y
) && typ
!= POOL
&&
265 ZAP_POS(levl
[nx
+ nx
- x
][ny
+ ny
- y
].typ
)) {
280 /* I don't like this, but ... */
286 if (cansee(nx
, ny
)) {
290 fcp
= &(EGD
->fakecorr
[EGD
->fcend
]);
291 if (EGD
->fcend
++ == FCSIZ
)
292 panic("fakecorr overflow");
314 struct monst
*mtmp
, *mtmp2
;