1*41270Sbostic /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2*41270Sbostic /* hack.vault.c - version 1.0.2 */
3*41270Sbostic
4*41270Sbostic #include "hack.h"
5*41270Sbostic #ifdef QUEST
setgd()6*41270Sbostic setgd(/* mtmp */) /* struct monst *mtmp; */ {}
gd_move()7*41270Sbostic gd_move() { return(2); }
8*41270Sbostic gddead(mtmp) struct monst *mtmp; {}
9*41270Sbostic replgd(mtmp,mtmp2) struct monst *mtmp, *mtmp2; {}
invault()10*41270Sbostic invault(){}
11*41270Sbostic
12*41270Sbostic #else
13*41270Sbostic
14*41270Sbostic
15*41270Sbostic #include "def.mkroom.h"
16*41270Sbostic extern struct monst *makemon();
17*41270Sbostic #define FCSIZ (ROWNO+COLNO)
18*41270Sbostic struct fakecorridor {
19*41270Sbostic xchar fx,fy,ftyp;
20*41270Sbostic };
21*41270Sbostic
22*41270Sbostic struct egd {
23*41270Sbostic int fcbeg, fcend; /* fcend: first unused pos */
24*41270Sbostic xchar gdx, gdy; /* goal of guard's walk */
25*41270Sbostic unsigned gddone:1;
26*41270Sbostic struct fakecorridor fakecorr[FCSIZ];
27*41270Sbostic };
28*41270Sbostic
29*41270Sbostic static struct permonst pm_guard =
30*41270Sbostic { "guard", '@', 12, 12, -1, 4, 10, sizeof(struct egd) };
31*41270Sbostic
32*41270Sbostic static struct monst *guard;
33*41270Sbostic static int gdlevel;
34*41270Sbostic #define EGD ((struct egd *)(&(guard->mextra[0])))
35*41270Sbostic
36*41270Sbostic static
restfakecorr()37*41270Sbostic restfakecorr()
38*41270Sbostic {
39*41270Sbostic register fcx,fcy,fcbeg;
40*41270Sbostic register struct rm *crm;
41*41270Sbostic
42*41270Sbostic while((fcbeg = EGD->fcbeg) < EGD->fcend) {
43*41270Sbostic fcx = EGD->fakecorr[fcbeg].fx;
44*41270Sbostic fcy = EGD->fakecorr[fcbeg].fy;
45*41270Sbostic if((u.ux == fcx && u.uy == fcy) || cansee(fcx,fcy) ||
46*41270Sbostic m_at(fcx,fcy))
47*41270Sbostic return;
48*41270Sbostic crm = &levl[fcx][fcy];
49*41270Sbostic crm->typ = EGD->fakecorr[fcbeg].ftyp;
50*41270Sbostic if(!crm->typ) crm->seen = 0;
51*41270Sbostic newsym(fcx,fcy);
52*41270Sbostic EGD->fcbeg++;
53*41270Sbostic }
54*41270Sbostic /* it seems he left the corridor - let the guard disappear */
55*41270Sbostic mondead(guard);
56*41270Sbostic guard = 0;
57*41270Sbostic }
58*41270Sbostic
59*41270Sbostic static
goldincorridor()60*41270Sbostic goldincorridor()
61*41270Sbostic {
62*41270Sbostic register int fci;
63*41270Sbostic
64*41270Sbostic for(fci = EGD->fcbeg; fci < EGD->fcend; fci++)
65*41270Sbostic if(g_at(EGD->fakecorr[fci].fx, EGD->fakecorr[fci].fy))
66*41270Sbostic return(1);
67*41270Sbostic return(0);
68*41270Sbostic }
69*41270Sbostic
setgd()70*41270Sbostic setgd(){
71*41270Sbostic register struct monst *mtmp;
72*41270Sbostic for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) if(mtmp->isgd){
73*41270Sbostic guard = mtmp;
74*41270Sbostic gdlevel = dlevel;
75*41270Sbostic return;
76*41270Sbostic }
77*41270Sbostic guard = 0;
78*41270Sbostic }
79*41270Sbostic
invault()80*41270Sbostic invault(){
81*41270Sbostic register tmp = inroom(u.ux, u.uy);
82*41270Sbostic if(tmp < 0 || rooms[tmp].rtype != VAULT) {
83*41270Sbostic u.uinvault = 0;
84*41270Sbostic return;
85*41270Sbostic }
86*41270Sbostic if(++u.uinvault % 50 == 0 && (!guard || gdlevel != dlevel)) {
87*41270Sbostic char buf[BUFSZ];
88*41270Sbostic register x,y,dd,gx,gy;
89*41270Sbostic
90*41270Sbostic /* first find the goal for the guard */
91*41270Sbostic for(dd = 1; (dd < ROWNO || dd < COLNO); dd++) {
92*41270Sbostic for(y = u.uy-dd; y <= u.uy+dd; y++) {
93*41270Sbostic if(y < 0 || y > ROWNO-1) continue;
94*41270Sbostic for(x = u.ux-dd; x <= u.ux+dd; x++) {
95*41270Sbostic if(y != u.uy-dd && y != u.uy+dd && x != u.ux-dd)
96*41270Sbostic x = u.ux+dd;
97*41270Sbostic if(x < 0 || x > COLNO-1) continue;
98*41270Sbostic if(levl[x][y].typ == CORR) goto fnd;
99*41270Sbostic }
100*41270Sbostic }
101*41270Sbostic }
102*41270Sbostic impossible("Not a single corridor on this level??");
103*41270Sbostic tele();
104*41270Sbostic return;
105*41270Sbostic fnd:
106*41270Sbostic gx = x; gy = y;
107*41270Sbostic
108*41270Sbostic /* next find a good place for a door in the wall */
109*41270Sbostic x = u.ux; y = u.uy;
110*41270Sbostic while(levl[x][y].typ == ROOM) {
111*41270Sbostic register int dx,dy;
112*41270Sbostic
113*41270Sbostic dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
114*41270Sbostic dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
115*41270Sbostic if(abs(gx-x) >= abs(gy-y))
116*41270Sbostic x += dx;
117*41270Sbostic else
118*41270Sbostic y += dy;
119*41270Sbostic }
120*41270Sbostic
121*41270Sbostic /* make something interesting happen */
122*41270Sbostic if(!(guard = makemon(&pm_guard,x,y))) return;
123*41270Sbostic guard->isgd = guard->mpeaceful = 1;
124*41270Sbostic EGD->gddone = 0;
125*41270Sbostic gdlevel = dlevel;
126*41270Sbostic if(!cansee(guard->mx, guard->my)) {
127*41270Sbostic mondead(guard);
128*41270Sbostic guard = 0;
129*41270Sbostic return;
130*41270Sbostic }
131*41270Sbostic
132*41270Sbostic pline("Suddenly one of the Vault's guards enters!");
133*41270Sbostic pmon(guard);
134*41270Sbostic do {
135*41270Sbostic pline("\"Hello stranger, who are you?\" - ");
136*41270Sbostic getlin(buf);
137*41270Sbostic } while (!letter(buf[0]));
138*41270Sbostic
139*41270Sbostic if(!strcmp(buf, "Croesus") || !strcmp(buf, "Kroisos")) {
140*41270Sbostic pline("\"Oh, yes - of course. Sorry to have disturbed you.\"");
141*41270Sbostic mondead(guard);
142*41270Sbostic guard = 0;
143*41270Sbostic return;
144*41270Sbostic }
145*41270Sbostic clrlin();
146*41270Sbostic pline("\"I don't know you.\"");
147*41270Sbostic if(!u.ugold)
148*41270Sbostic pline("\"Please follow me.\"");
149*41270Sbostic else {
150*41270Sbostic pline("\"Most likely all that gold was stolen from this vault.\"");
151*41270Sbostic pline("\"Please drop your gold (say d$ ) and follow me.\"");
152*41270Sbostic }
153*41270Sbostic EGD->gdx = gx;
154*41270Sbostic EGD->gdy = gy;
155*41270Sbostic EGD->fcbeg = 0;
156*41270Sbostic EGD->fakecorr[0].fx = x;
157*41270Sbostic EGD->fakecorr[0].fy = y;
158*41270Sbostic EGD->fakecorr[0].ftyp = levl[x][y].typ;
159*41270Sbostic levl[x][y].typ = DOOR;
160*41270Sbostic EGD->fcend = 1;
161*41270Sbostic }
162*41270Sbostic }
163*41270Sbostic
gd_move()164*41270Sbostic gd_move(){
165*41270Sbostic register int x,y,dx,dy,gx,gy,nx,ny,typ;
166*41270Sbostic register struct fakecorridor *fcp;
167*41270Sbostic register struct rm *crm;
168*41270Sbostic if(!guard || gdlevel != dlevel){
169*41270Sbostic impossible("Where is the guard?");
170*41270Sbostic return(2); /* died */
171*41270Sbostic }
172*41270Sbostic if(u.ugold || goldincorridor())
173*41270Sbostic return(0); /* didnt move */
174*41270Sbostic if(dist(guard->mx,guard->my) > 1 || EGD->gddone) {
175*41270Sbostic restfakecorr();
176*41270Sbostic return(0); /* didnt move */
177*41270Sbostic }
178*41270Sbostic x = guard->mx;
179*41270Sbostic y = guard->my;
180*41270Sbostic /* look around (hor & vert only) for accessible places */
181*41270Sbostic for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++) {
182*41270Sbostic if(nx == x || ny == y) if(nx != x || ny != y)
183*41270Sbostic if(isok(nx,ny))
184*41270Sbostic if(!IS_WALL(typ = (crm = &levl[nx][ny])->typ) && typ != POOL) {
185*41270Sbostic register int i;
186*41270Sbostic for(i = EGD->fcbeg; i < EGD->fcend; i++)
187*41270Sbostic if(EGD->fakecorr[i].fx == nx &&
188*41270Sbostic EGD->fakecorr[i].fy == ny)
189*41270Sbostic goto nextnxy;
190*41270Sbostic if((i = inroom(nx,ny)) >= 0 && rooms[i].rtype == VAULT)
191*41270Sbostic goto nextnxy;
192*41270Sbostic /* seems we found a good place to leave him alone */
193*41270Sbostic EGD->gddone = 1;
194*41270Sbostic if(ACCESSIBLE(typ)) goto newpos;
195*41270Sbostic crm->typ = (typ == SCORR) ? CORR : DOOR;
196*41270Sbostic goto proceed;
197*41270Sbostic }
198*41270Sbostic nextnxy: ;
199*41270Sbostic }
200*41270Sbostic nx = x;
201*41270Sbostic ny = y;
202*41270Sbostic gx = EGD->gdx;
203*41270Sbostic gy = EGD->gdy;
204*41270Sbostic dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
205*41270Sbostic dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
206*41270Sbostic if(abs(gx-x) >= abs(gy-y)) nx += dx; else ny += dy;
207*41270Sbostic
208*41270Sbostic while((typ = (crm = &levl[nx][ny])->typ) != 0) {
209*41270Sbostic /* in view of the above we must have IS_WALL(typ) or typ == POOL */
210*41270Sbostic /* must be a wall here */
211*41270Sbostic if(isok(nx+nx-x,ny+ny-y) && typ != POOL &&
212*41270Sbostic ZAP_POS(levl[nx+nx-x][ny+ny-y].typ)){
213*41270Sbostic crm->typ = DOOR;
214*41270Sbostic goto proceed;
215*41270Sbostic }
216*41270Sbostic if(dy && nx != x) {
217*41270Sbostic nx = x; ny = y+dy;
218*41270Sbostic continue;
219*41270Sbostic }
220*41270Sbostic if(dx && ny != y) {
221*41270Sbostic ny = y; nx = x+dx; dy = 0;
222*41270Sbostic continue;
223*41270Sbostic }
224*41270Sbostic /* I don't like this, but ... */
225*41270Sbostic crm->typ = DOOR;
226*41270Sbostic goto proceed;
227*41270Sbostic }
228*41270Sbostic crm->typ = CORR;
229*41270Sbostic proceed:
230*41270Sbostic if(cansee(nx,ny)) {
231*41270Sbostic mnewsym(nx,ny);
232*41270Sbostic prl(nx,ny);
233*41270Sbostic }
234*41270Sbostic fcp = &(EGD->fakecorr[EGD->fcend]);
235*41270Sbostic if(EGD->fcend++ == FCSIZ) panic("fakecorr overflow");
236*41270Sbostic fcp->fx = nx;
237*41270Sbostic fcp->fy = ny;
238*41270Sbostic fcp->ftyp = typ;
239*41270Sbostic newpos:
240*41270Sbostic if(EGD->gddone) nx = ny = 0;
241*41270Sbostic guard->mx = nx;
242*41270Sbostic guard->my = ny;
243*41270Sbostic pmon(guard);
244*41270Sbostic restfakecorr();
245*41270Sbostic return(1);
246*41270Sbostic }
247*41270Sbostic
gddead()248*41270Sbostic gddead(){
249*41270Sbostic guard = 0;
250*41270Sbostic }
251*41270Sbostic
replgd(mtmp,mtmp2)252*41270Sbostic replgd(mtmp,mtmp2)
253*41270Sbostic register struct monst *mtmp, *mtmp2;
254*41270Sbostic {
255*41270Sbostic if(mtmp == guard)
256*41270Sbostic guard = mtmp2;
257*41270Sbostic }
258*41270Sbostic
259*41270Sbostic #endif QUEST
260