1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.vault.c - version 1.0.2 */
6 setgd(/* mtmp */) /* struct monst *mtmp; */ {}
7 gd_move() { return(2); }
8 gddead(mtmp) struct monst *mtmp; {}
9 replgd(mtmp,mtmp2) struct monst *mtmp, *mtmp2; {}
15 #include "def.mkroom.h"
16 extern struct monst *makemon();
17 #define FCSIZ (ROWNO+COLNO)
23 int fcbeg, fcend; /* fcend: first unused pos */
24 xchar gdx, gdy; /* goal of guard's walk */
26 struct fakecorridor fakecorr[FCSIZ];
29 static struct permonst pm_guard =
30 { "guard", '@', 12, 12, -1, 4, 10, sizeof(struct egd) };
32 static struct monst *guard;
34 #define EGD ((struct egd *)(&(guard->mextra[0])))
39 register fcx,fcy,fcbeg;
40 register struct rm *crm;
42 while((fcbeg = EGD->fcbeg) < EGD->fcend) {
43 fcx = EGD->fakecorr[fcbeg].fx;
44 fcy = EGD->fakecorr[fcbeg].fy;
45 if((u.ux == fcx && u.uy == fcy) || cansee(fcx,fcy) ||
48 crm = &levl[fcx][fcy];
49 crm->typ = EGD->fakecorr[fcbeg].ftyp;
50 if(!crm->typ) crm->seen = 0;
54 /* it seems he left the corridor - let the guard disappear */
64 for(fci = EGD->fcbeg; fci < EGD->fcend; fci++)
65 if(g_at(EGD->fakecorr[fci].fx, EGD->fakecorr[fci].fy))
71 register struct monst *mtmp;
72 for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) if(mtmp->isgd){
81 register tmp = inroom(u.ux, u.uy);
82 if(tmp < 0 || rooms[tmp].rtype != VAULT) {
86 if(++u.uinvault % 50 == 0 && (!guard || gdlevel != dlevel)) {
88 register x,y,dd,gx,gy;
90 /* first find the goal for the guard */
91 for(dd = 1; (dd < ROWNO || dd < COLNO); dd++) {
92 for(y = u.uy-dd; y <= u.uy+dd; y++) {
93 if(y < 0 || y > ROWNO-1) continue;
94 for(x = u.ux-dd; x <= u.ux+dd; x++) {
95 if(y != u.uy-dd && y != u.uy+dd && x != u.ux-dd)
97 if(x < 0 || x > COLNO-1) continue;
98 if(levl[x][y].typ == CORR) goto fnd;
102 impossible("Not a single corridor on this level??");
108 /* next find a good place for a door in the wall */
110 while(levl[x][y].typ == ROOM) {
113 dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
114 dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
115 if(abs(gx-x) >= abs(gy-y))
121 /* make something interesting happen */
122 if(!(guard = makemon(&pm_guard,x,y))) return;
123 guard->isgd = guard->mpeaceful = 1;
126 if(!cansee(guard->mx, guard->my)) {
132 pline("Suddenly one of the Vault's guards enters!");
135 pline("\"Hello stranger, who are you?\" - ");
137 } while (!letter(buf[0]));
139 if(!strcmp(buf, "Croesus") || !strcmp(buf, "Kroisos")) {
140 pline("\"Oh, yes - of course. Sorry to have disturbed you.\"");
146 pline("\"I don't know you.\"");
148 pline("\"Please follow me.\"");
150 pline("\"Most likely all that gold was stolen from this vault.\"");
151 pline("\"Please drop your gold (say d$ ) and follow me.\"");
156 EGD->fakecorr[0].fx = x;
157 EGD->fakecorr[0].fy = y;
158 EGD->fakecorr[0].ftyp = levl[x][y].typ;
159 levl[x][y].typ = DOOR;
165 register int x,y,dx,dy,gx,gy,nx,ny,typ;
166 register struct fakecorridor *fcp;
167 register struct rm *crm;
168 if(!guard || gdlevel != dlevel){
169 impossible("Where is the guard?");
170 return(2); /* died */
172 if(u.ugold || goldincorridor())
173 return(0); /* didnt move */
174 if(dist(guard->mx,guard->my) > 1 || EGD->gddone) {
176 return(0); /* didnt move */
180 /* look around (hor & vert only) for accessible places */
181 for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++) {
182 if(nx == x || ny == y) if(nx != x || ny != y)
184 if(!IS_WALL(typ = (crm = &levl[nx][ny])->typ) && typ != POOL) {
186 for(i = EGD->fcbeg; i < EGD->fcend; i++)
187 if(EGD->fakecorr[i].fx == nx &&
188 EGD->fakecorr[i].fy == ny)
190 if((i = inroom(nx,ny)) >= 0 && rooms[i].rtype == VAULT)
192 /* seems we found a good place to leave him alone */
194 if(ACCESSIBLE(typ)) goto newpos;
195 crm->typ = (typ == SCORR) ? CORR : DOOR;
204 dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
205 dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
206 if(abs(gx-x) >= abs(gy-y)) nx += dx; else ny += dy;
208 while((typ = (crm = &levl[nx][ny])->typ) != 0) {
209 /* in view of the above we must have IS_WALL(typ) or typ == POOL */
210 /* must be a wall here */
211 if(isok(nx+nx-x,ny+ny-y) && typ != POOL &&
212 ZAP_POS(levl[nx+nx-x][ny+ny-y].typ)){
221 ny = y; nx = x+dx; dy = 0;
224 /* I don't like this, but ... */
234 fcp = &(EGD->fakecorr[EGD->fcend]);
235 if(EGD->fcend++ == FCSIZ) panic("fakecorr overflow");
240 if(EGD->gddone) nx = ny = 0;
253 register struct monst *mtmp, *mtmp2;