1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.vault.c - version 1.0.2 */
3 /* $FreeBSD: src/games/hack/hack.vault.c,v 1.4 1999/11/16 10:26:38 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.vault.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */
20 gddead(struct monst
*mtmp __unused
)
25 replgd(struct monst
*mtmp __unused
, struct monst
*mtmp2 __unused
)
36 #define FCSIZ (ROWNO + COLNO)
42 int fcbeg
, fcend
; /* fcend: first unused pos */
43 xchar gdx
, gdy
; /* goal of guard's walk */
45 struct fakecorridor fakecorr
[FCSIZ
];
48 static struct permonst pm_guard
=
49 { "guard", '@', 12, 12, -1, 4, 10, sizeof(struct egd
) };
51 static struct monst
*guard
;
53 #define EGD ((struct egd *)(&(guard->mextra[0])))
55 static void restfakecorr(void);
56 static bool goldincorridor(void);
64 while ((fcbeg
= EGD
->fcbeg
) < EGD
->fcend
) {
65 fcx
= EGD
->fakecorr
[fcbeg
].fx
;
66 fcy
= EGD
->fakecorr
[fcbeg
].fy
;
67 if ((u
.ux
== fcx
&& u
.uy
== fcy
) || cansee(fcx
, fcy
) ||
70 crm
= &levl
[fcx
][fcy
];
71 crm
->typ
= EGD
->fakecorr
[fcbeg
].ftyp
;
77 /* it seems he left the corridor - let the guard disappear */
87 for (fci
= EGD
->fcbeg
; fci
< EGD
->fcend
; fci
++)
88 if (g_at(EGD
->fakecorr
[fci
].fx
, EGD
->fakecorr
[fci
].fy
))
98 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
110 int tmp
= inroom(u
.ux
, u
.uy
);
112 if (tmp
< 0 || rooms
[tmp
].rtype
!= VAULT
) {
116 if (++u
.uinvault
% 50 == 0 && (!guard
|| gdlevel
!= dlevel
)) {
118 int x
, y
, dd
, gx
, gy
;
120 /* first find the goal for the guard */
121 for (dd
= 1; (dd
< ROWNO
|| dd
< COLNO
); dd
++) {
122 for (y
= u
.uy
- dd
; y
<= u
.uy
+ dd
; y
++) {
123 if (y
< 0 || y
> ROWNO
- 1)
125 for (x
= u
.ux
- dd
; x
<= u
.ux
+ dd
; x
++) {
126 if (y
!= u
.uy
- dd
&& y
!= u
.uy
+ dd
&& x
!= u
.ux
- dd
)
128 if (x
< 0 || x
> COLNO
- 1)
130 if (levl
[x
][y
].typ
== CORR
)
135 impossible("Not a single corridor on this level??");
142 /* next find a good place for a door in the wall */
145 while (levl
[x
][y
].typ
== ROOM
) {
148 dx
= (gx
> x
) ? 1 : (gx
< x
) ? -1 : 0;
149 dy
= (gy
> y
) ? 1 : (gy
< y
) ? -1 : 0;
150 if (abs(gx
- x
) >= abs(gy
- y
))
156 /* make something interesting happen */
157 if (!(guard
= makemon(&pm_guard
, x
, y
)))
159 guard
->isgd
= guard
->mpeaceful
= 1;
162 if (!cansee(guard
->mx
, guard
->my
)) {
168 pline("Suddenly one of the Vault's guards enters!");
171 pline("\"Hello stranger, who are you?\" - ");
173 } while (!letter(buf
[0]));
175 if (!strcmp(buf
, "Croesus") || !strcmp(buf
, "Kroisos")) {
176 pline("\"Oh, yes - of course. Sorry to have disturbed you.\"");
182 pline("\"I don't know you.\"");
184 pline("\"Please follow me.\"");
186 pline("\"Most likely all that gold was stolen from this vault.\"");
187 pline("\"Please drop your gold (say d$ ) and follow me.\"");
192 EGD
->fakecorr
[0].fx
= x
;
193 EGD
->fakecorr
[0].fy
= y
;
194 EGD
->fakecorr
[0].ftyp
= levl
[x
][y
].typ
;
195 levl
[x
][y
].typ
= DOOR
;
203 int x
, y
, dx
, dy
, gx
, gy
, nx
, ny
, typ
;
204 struct fakecorridor
*fcp
;
207 if (!guard
|| gdlevel
!= dlevel
) {
208 impossible("Where is the guard?");
209 return (2); /* died */
211 if (u
.ugold
|| goldincorridor())
212 return (0); /* didnt move */
213 if (dist(guard
->mx
, guard
->my
) > 1 || EGD
->gddone
) {
215 return (0); /* didnt move */
219 /* look around (hor & vert only) for accessible places */
220 for (nx
= x
- 1; nx
<= x
+ 1; nx
++)
221 for (ny
= y
- 1; ny
<= y
+ 1; ny
++) {
222 if (nx
== x
|| ny
== y
)
223 if (nx
!= x
|| ny
!= y
)
225 if (!IS_WALL(typ
= (crm
= &levl
[nx
][ny
])->typ
) && typ
!= POOL
) {
227 for (i
= EGD
->fcbeg
; i
< EGD
->fcend
; i
++)
228 if (EGD
->fakecorr
[i
].fx
== nx
&&
229 EGD
->fakecorr
[i
].fy
== ny
)
231 if ((i
= inroom(nx
, ny
)) >= 0 && rooms
[i
].rtype
== VAULT
)
233 /* seems we found a good place to leave him alone */
237 crm
->typ
= (typ
== SCORR
) ? CORR
: DOOR
;
246 dx
= (gx
> x
) ? 1 : (gx
< x
) ? -1 : 0;
247 dy
= (gy
> y
) ? 1 : (gy
< y
) ? -1 : 0;
248 if (abs(gx
- x
) >= abs(gy
- y
))
253 while ((typ
= (crm
= &levl
[nx
][ny
])->typ
) != 0) {
254 /* in view of the above we must have IS_WALL(typ) or typ == POOL */
255 /* must be a wall here */
256 if (isok(nx
+ nx
- x
, ny
+ ny
- y
) && typ
!= POOL
&&
257 ZAP_POS(levl
[nx
+ nx
- x
][ny
+ ny
- y
].typ
)) {
272 /* I don't like this, but ... */
278 if (cansee(nx
, ny
)) {
282 fcp
= &(EGD
->fakecorr
[EGD
->fcend
]);
283 if (EGD
->fcend
++ == FCSIZ
)
284 panic("fakecorr overflow");
305 replgd(struct monst
*mtmp
, struct monst
*mtmp2
)