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.3 2004/11/06 12:29:17 eirikn Exp $ */
8 setgd(/* mtmp */) /* struct monst *mtmp; */ {}
9 gd_move() { return(2); }
10 gddead(mtmp) struct monst *mtmp; {}
11 replgd(mtmp,mtmp2) struct monst *mtmp, *mtmp2; {}
17 #include "def.mkroom.h"
18 extern struct monst *makemon();
19 #define FCSIZ (ROWNO+COLNO)
25 int fcbeg, fcend; /* fcend: first unused pos */
26 xchar gdx, gdy; /* goal of guard's walk */
28 struct fakecorridor fakecorr[FCSIZ];
31 static struct permonst pm_guard =
32 { "guard", '@', 12, 12, -1, 4, 10, sizeof(struct egd) };
34 static struct monst *guard;
36 #define EGD ((struct egd *)(&(guard->mextra[0])))
44 while((fcbeg = EGD->fcbeg) < EGD->fcend) {
45 fcx = EGD->fakecorr[fcbeg].fx;
46 fcy = EGD->fakecorr[fcbeg].fy;
47 if((u.ux == fcx && u.uy == fcy) || cansee(fcx,fcy) ||
50 crm = &levl[fcx][fcy];
51 crm->typ = EGD->fakecorr[fcbeg].ftyp;
52 if(!crm->typ) crm->seen = 0;
56 /* it seems he left the corridor - let the guard disappear */
66 for(fci = EGD->fcbeg; fci < EGD->fcend; fci++)
67 if(g_at(EGD->fakecorr[fci].fx, EGD->fakecorr[fci].fy))
74 for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) if(mtmp->isgd){
83 int tmp = inroom(u.ux, u.uy);
84 if(tmp < 0 || rooms[tmp].rtype != VAULT) {
88 if(++u.uinvault % 50 == 0 && (!guard || gdlevel != dlevel)) {
92 /* first find the goal for the guard */
93 for(dd = 1; (dd < ROWNO || dd < COLNO); dd++) {
94 for(y = u.uy-dd; y <= u.uy+dd; y++) {
95 if(y < 0 || y > ROWNO-1) continue;
96 for(x = u.ux-dd; x <= u.ux+dd; x++) {
97 if(y != u.uy-dd && y != u.uy+dd && x != u.ux-dd)
99 if(x < 0 || x > COLNO-1) continue;
100 if(levl[x][y].typ == CORR) goto fnd;
104 impossible("Not a single corridor on this level??");
110 /* next find a good place for a door in the wall */
112 while(levl[x][y].typ == ROOM) {
115 dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
116 dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
117 if(abs(gx-x) >= abs(gy-y))
123 /* make something interesting happen */
124 if(!(guard = makemon(&pm_guard,x,y))) return;
125 guard->isgd = guard->mpeaceful = 1;
128 if(!cansee(guard->mx, guard->my)) {
134 pline("Suddenly one of the Vault's guards enters!");
137 pline("\"Hello stranger, who are you?\" - ");
139 } while (!letter(buf[0]));
141 if(!strcmp(buf, "Croesus") || !strcmp(buf, "Kroisos")) {
142 pline("\"Oh, yes - of course. Sorry to have disturbed you.\"");
148 pline("\"I don't know you.\"");
150 pline("\"Please follow me.\"");
152 pline("\"Most likely all that gold was stolen from this vault.\"");
153 pline("\"Please drop your gold (say d$ ) and follow me.\"");
158 EGD->fakecorr[0].fx = x;
159 EGD->fakecorr[0].fy = y;
160 EGD->fakecorr[0].ftyp = levl[x][y].typ;
161 levl[x][y].typ = DOOR;
167 int x,y,dx,dy,gx,gy,nx,ny,typ;
168 struct fakecorridor *fcp;
170 if(!guard || gdlevel != dlevel){
171 impossible("Where is the guard?");
172 return(2); /* died */
174 if(u.ugold || goldincorridor())
175 return(0); /* didnt move */
176 if(dist(guard->mx,guard->my) > 1 || EGD->gddone) {
178 return(0); /* didnt move */
182 /* look around (hor & vert only) for accessible places */
183 for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++) {
184 if(nx == x || ny == y) if(nx != x || ny != y)
186 if(!IS_WALL(typ = (crm = &levl[nx][ny])->typ) && typ != POOL) {
188 for(i = EGD->fcbeg; i < EGD->fcend; i++)
189 if(EGD->fakecorr[i].fx == nx &&
190 EGD->fakecorr[i].fy == ny)
192 if((i = inroom(nx,ny)) >= 0 && rooms[i].rtype == VAULT)
194 /* seems we found a good place to leave him alone */
196 if(ACCESSIBLE(typ)) goto newpos;
197 crm->typ = (typ == SCORR) ? CORR : DOOR;
206 dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
207 dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
208 if(abs(gx-x) >= abs(gy-y)) nx += dx; else ny += dy;
210 while((typ = (crm = &levl[nx][ny])->typ) != 0) {
211 /* in view of the above we must have IS_WALL(typ) or typ == POOL */
212 /* must be a wall here */
213 if(isok(nx+nx-x,ny+ny-y) && typ != POOL &&
214 ZAP_POS(levl[nx+nx-x][ny+ny-y].typ)){
223 ny = y; nx = x+dx; dy = 0;
226 /* I don't like this, but ... */
236 fcp = &(EGD->fakecorr[EGD->fcend]);
237 if(EGD->fcend++ == FCSIZ) panic("fakecorr overflow");
242 if(EGD->gddone) nx = ny = 0;
255 struct monst *mtmp, *mtmp2;