]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.vault.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.vault.c,v 1.3 1995/03/23 08:31:59 cgd Exp $";
11 setgd(/* mtmp */) /* struct monst *mtmp; */ {}
12 gd_move() { return(2); }
13 gddead(mtmp
) struct monst
*mtmp
; {}
14 replgd(mtmp
,mtmp2
) struct monst
*mtmp
, *mtmp2
; {}
20 #include "def.mkroom.h"
21 extern struct monst
*makemon();
22 #define FCSIZ (ROWNO+COLNO)
28 int fcbeg
, fcend
; /* fcend: first unused pos */
29 xchar gdx
, gdy
; /* goal of guard's walk */
31 struct fakecorridor fakecorr
[FCSIZ
];
34 static struct permonst pm_guard
=
35 { "guard", '@', 12, 12, -1, 4, 10, sizeof(struct egd
) };
37 static struct monst
*guard
;
39 #define EGD ((struct egd *)(&(guard->mextra[0])))
44 register fcx
,fcy
,fcbeg
;
45 register struct rm
*crm
;
47 while((fcbeg
= EGD
->fcbeg
) < EGD
->fcend
) {
48 fcx
= EGD
->fakecorr
[fcbeg
].fx
;
49 fcy
= EGD
->fakecorr
[fcbeg
].fy
;
50 if((u
.ux
== fcx
&& u
.uy
== fcy
) || cansee(fcx
,fcy
) ||
53 crm
= &levl
[fcx
][fcy
];
54 crm
->typ
= EGD
->fakecorr
[fcbeg
].ftyp
;
55 if(!crm
->typ
) crm
->seen
= 0;
59 /* it seems he left the corridor - let the guard disappear */
69 for(fci
= EGD
->fcbeg
; fci
< EGD
->fcend
; fci
++)
70 if(g_at(EGD
->fakecorr
[fci
].fx
, EGD
->fakecorr
[fci
].fy
))
76 register struct monst
*mtmp
;
77 for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) if(mtmp
->isgd
){
86 register tmp
= inroom(u
.ux
, u
.uy
);
87 if(tmp
< 0 || rooms
[tmp
].rtype
!= VAULT
) {
91 if(++u
.uinvault
% 50 == 0 && (!guard
|| gdlevel
!= dlevel
)) {
93 register x
,y
,dd
,gx
,gy
;
95 /* first find the goal for the guard */
96 for(dd
= 1; (dd
< ROWNO
|| dd
< COLNO
); dd
++) {
97 for(y
= u
.uy
-dd
; y
<= u
.uy
+dd
; y
++) {
98 if(y
< 0 || y
> ROWNO
-1) continue;
99 for(x
= u
.ux
-dd
; x
<= u
.ux
+dd
; x
++) {
100 if(y
!= u
.uy
-dd
&& y
!= u
.uy
+dd
&& x
!= u
.ux
-dd
)
102 if(x
< 0 || x
> COLNO
-1) continue;
103 if(levl
[x
][y
].typ
== CORR
) goto fnd
;
107 impossible("Not a single corridor on this level??");
113 /* next find a good place for a door in the wall */
115 while(levl
[x
][y
].typ
== ROOM
) {
118 dx
= (gx
> x
) ? 1 : (gx
< x
) ? -1 : 0;
119 dy
= (gy
> y
) ? 1 : (gy
< y
) ? -1 : 0;
120 if(abs(gx
-x
) >= abs(gy
-y
))
126 /* make something interesting happen */
127 if(!(guard
= makemon(&pm_guard
,x
,y
))) return;
128 guard
->isgd
= guard
->mpeaceful
= 1;
131 if(!cansee(guard
->mx
, guard
->my
)) {
137 pline("Suddenly one of the Vault's guards enters!");
140 pline("\"Hello stranger, who are you?\" - ");
142 } while (!letter(buf
[0]));
144 if(!strcmp(buf
, "Croesus") || !strcmp(buf
, "Kroisos")) {
145 pline("\"Oh, yes - of course. Sorry to have disturbed you.\"");
151 pline("\"I don't know you.\"");
153 pline("\"Please follow me.\"");
155 pline("\"Most likely all that gold was stolen from this vault.\"");
156 pline("\"Please drop your gold (say d$ ) and follow me.\"");
161 EGD
->fakecorr
[0].fx
= x
;
162 EGD
->fakecorr
[0].fy
= y
;
163 EGD
->fakecorr
[0].ftyp
= levl
[x
][y
].typ
;
164 levl
[x
][y
].typ
= DOOR
;
170 register int x
,y
,dx
,dy
,gx
,gy
,nx
,ny
,typ
;
171 register struct fakecorridor
*fcp
;
172 register struct rm
*crm
;
173 if(!guard
|| gdlevel
!= dlevel
){
174 impossible("Where is the guard?");
175 return(2); /* died */
177 if(u
.ugold
|| goldincorridor())
178 return(0); /* didnt move */
179 if(dist(guard
->mx
,guard
->my
) > 1 || EGD
->gddone
) {
181 return(0); /* didnt move */
185 /* look around (hor & vert only) for accessible places */
186 for(nx
= x
-1; nx
<= x
+1; nx
++) for(ny
= y
-1; ny
<= y
+1; ny
++) {
187 if(nx
== x
|| ny
== y
) if(nx
!= x
|| ny
!= y
)
189 if(!IS_WALL(typ
= (crm
= &levl
[nx
][ny
])->typ
) && typ
!= POOL
) {
191 for(i
= EGD
->fcbeg
; i
< EGD
->fcend
; i
++)
192 if(EGD
->fakecorr
[i
].fx
== nx
&&
193 EGD
->fakecorr
[i
].fy
== ny
)
195 if((i
= inroom(nx
,ny
)) >= 0 && rooms
[i
].rtype
== VAULT
)
197 /* seems we found a good place to leave him alone */
199 if(ACCESSIBLE(typ
)) goto newpos
;
200 crm
->typ
= (typ
== SCORR
) ? CORR
: DOOR
;
209 dx
= (gx
> x
) ? 1 : (gx
< x
) ? -1 : 0;
210 dy
= (gy
> y
) ? 1 : (gy
< y
) ? -1 : 0;
211 if(abs(gx
-x
) >= abs(gy
-y
)) nx
+= dx
; else ny
+= dy
;
213 while((typ
= (crm
= &levl
[nx
][ny
])->typ
) != 0) {
214 /* in view of the above we must have IS_WALL(typ) or typ == POOL */
215 /* must be a wall here */
216 if(isok(nx
+nx
-x
,ny
+ny
-y
) && typ
!= POOL
&&
217 ZAP_POS(levl
[nx
+nx
-x
][ny
+ny
-y
].typ
)){
226 ny
= y
; nx
= x
+dx
; dy
= 0;
229 /* I don't like this, but ... */
239 fcp
= &(EGD
->fakecorr
[EGD
->fcend
]);
240 if(EGD
->fcend
++ == FCSIZ
) panic("fakecorr overflow");
245 if(EGD
->gddone
) nx
= ny
= 0;
258 register struct monst
*mtmp
, *mtmp2
;