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
)
25 replgd(struct monst
*mtmp
, struct monst
*mtmp2
)
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
;
72 if(!crm
->typ
) crm
->seen
= 0;
76 /* it seems he left the corridor - let the guard disappear */
86 for(fci
= EGD
->fcbeg
; fci
< EGD
->fcend
; fci
++)
87 if(g_at(EGD
->fakecorr
[fci
].fx
, EGD
->fakecorr
[fci
].fy
))
96 for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) if(mtmp
->isgd
){
107 int tmp
= inroom(u
.ux
, u
.uy
);
108 if(tmp
< 0 || rooms
[tmp
].rtype
!= VAULT
) {
112 if(++u
.uinvault
% 50 == 0 && (!guard
|| gdlevel
!= dlevel
)) {
116 /* first find the goal for the guard */
117 for(dd
= 1; (dd
< ROWNO
|| dd
< COLNO
); dd
++) {
118 for(y
= u
.uy
-dd
; y
<= u
.uy
+dd
; y
++) {
119 if(y
< 0 || y
> ROWNO
-1) continue;
120 for(x
= u
.ux
-dd
; x
<= u
.ux
+dd
; x
++) {
121 if(y
!= u
.uy
-dd
&& y
!= u
.uy
+dd
&& x
!= u
.ux
-dd
)
123 if(x
< 0 || x
> COLNO
-1) continue;
124 if(levl
[x
][y
].typ
== CORR
) goto fnd
;
128 impossible("Not a single corridor on this level??");
134 /* next find a good place for a door in the wall */
136 while(levl
[x
][y
].typ
== ROOM
) {
139 dx
= (gx
> x
) ? 1 : (gx
< x
) ? -1 : 0;
140 dy
= (gy
> y
) ? 1 : (gy
< y
) ? -1 : 0;
141 if(abs(gx
-x
) >= abs(gy
-y
))
147 /* make something interesting happen */
148 if(!(guard
= makemon(&pm_guard
,x
,y
))) return;
149 guard
->isgd
= guard
->mpeaceful
= 1;
152 if(!cansee(guard
->mx
, guard
->my
)) {
158 pline("Suddenly one of the Vault's guards enters!");
161 pline("\"Hello stranger, who are you?\" - ");
163 } while (!letter(buf
[0]));
165 if(!strcmp(buf
, "Croesus") || !strcmp(buf
, "Kroisos")) {
166 pline("\"Oh, yes - of course. Sorry to have disturbed you.\"");
172 pline("\"I don't know you.\"");
174 pline("\"Please follow me.\"");
176 pline("\"Most likely all that gold was stolen from this vault.\"");
177 pline("\"Please drop your gold (say d$ ) and follow me.\"");
182 EGD
->fakecorr
[0].fx
= x
;
183 EGD
->fakecorr
[0].fy
= y
;
184 EGD
->fakecorr
[0].ftyp
= levl
[x
][y
].typ
;
185 levl
[x
][y
].typ
= DOOR
;
193 int x
,y
,dx
,dy
,gx
,gy
,nx
,ny
,typ
;
194 struct fakecorridor
*fcp
;
196 if(!guard
|| gdlevel
!= dlevel
){
197 impossible("Where is the guard?");
198 return(2); /* died */
200 if(u
.ugold
|| goldincorridor())
201 return(0); /* didnt move */
202 if(dist(guard
->mx
,guard
->my
) > 1 || EGD
->gddone
) {
204 return(0); /* didnt move */
208 /* look around (hor & vert only) for accessible places */
209 for(nx
= x
-1; nx
<= x
+1; nx
++) for(ny
= y
-1; ny
<= y
+1; ny
++) {
210 if(nx
== x
|| ny
== y
) if(nx
!= x
|| ny
!= y
)
212 if(!IS_WALL(typ
= (crm
= &levl
[nx
][ny
])->typ
) && typ
!= POOL
) {
214 for(i
= EGD
->fcbeg
; i
< EGD
->fcend
; i
++)
215 if(EGD
->fakecorr
[i
].fx
== nx
&&
216 EGD
->fakecorr
[i
].fy
== ny
)
218 if((i
= inroom(nx
,ny
)) >= 0 && rooms
[i
].rtype
== VAULT
)
220 /* seems we found a good place to leave him alone */
222 if(ACCESSIBLE(typ
)) goto newpos
;
223 crm
->typ
= (typ
== SCORR
) ? CORR
: DOOR
;
232 dx
= (gx
> x
) ? 1 : (gx
< x
) ? -1 : 0;
233 dy
= (gy
> y
) ? 1 : (gy
< y
) ? -1 : 0;
234 if(abs(gx
-x
) >= abs(gy
-y
)) nx
+= dx
; else ny
+= dy
;
236 while((typ
= (crm
= &levl
[nx
][ny
])->typ
) != 0) {
237 /* in view of the above we must have IS_WALL(typ) or typ == POOL */
238 /* must be a wall here */
239 if(isok(nx
+nx
-x
,ny
+ny
-y
) && typ
!= POOL
&&
240 ZAP_POS(levl
[nx
+nx
-x
][ny
+ny
-y
].typ
)){
249 ny
= y
; nx
= x
+dx
; dy
= 0;
252 /* I don't like this, but ... */
262 fcp
= &(EGD
->fakecorr
[EGD
->fcend
]);
263 if(EGD
->fcend
++ == FCSIZ
) panic("fakecorr overflow");
268 if(EGD
->gddone
) nx
= ny
= 0;
283 replgd(struct monst
*mtmp
, struct monst
*mtmp2
)