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 $ */
19 gddead(struct monst *mtmp __unused)
24 replgd(struct monst *mtmp __unused, struct monst *mtmp2 __unused)
35 #define FCSIZ (ROWNO + COLNO)
41 int fcbeg, fcend; /* fcend: first unused pos */
42 xchar gdx, gdy; /* goal of guard's walk */
44 struct fakecorridor fakecorr[FCSIZ];
47 static struct permonst pm_guard =
48 { "guard", '@', 12, 12, -1, 4, 10, sizeof(struct egd) };
50 static struct monst *guard;
52 #define EGD ((struct egd *)(&(guard->mextra[0])))
54 static void restfakecorr(void);
55 static bool goldincorridor(void);
63 while ((fcbeg = EGD->fcbeg) < EGD->fcend) {
64 fcx = EGD->fakecorr[fcbeg].fx;
65 fcy = EGD->fakecorr[fcbeg].fy;
66 if ((u.ux == fcx && u.uy == fcy) || cansee(fcx, fcy) ||
69 crm = &levl[fcx][fcy];
70 crm->typ = EGD->fakecorr[fcbeg].ftyp;
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))
97 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
109 int tmp = inroom(u.ux, u.uy);
111 if (tmp < 0 || rooms[tmp].rtype != VAULT) {
115 if (++u.uinvault % 50 == 0 && (!guard || gdlevel != dlevel)) {
117 int x, y, dd, gx, gy;
119 /* first find the goal for the guard */
120 for (dd = 1; (dd < ROWNO || dd < COLNO); dd++) {
121 for (y = u.uy - dd; y <= u.uy + dd; y++) {
122 if (y < 0 || y > ROWNO - 1)
124 for (x = u.ux - dd; x <= u.ux + dd; x++) {
125 if (y != u.uy - dd && y != u.uy + dd && x != u.ux - dd)
127 if (x < 0 || x > COLNO - 1)
129 if (levl[x][y].typ == CORR)
134 impossible("Not a single corridor on this level??");
141 /* next find a good place for a door in the wall */
144 while (levl[x][y].typ == ROOM) {
147 dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
148 dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
149 if (abs(gx - x) >= abs(gy - y))
155 /* make something interesting happen */
156 if (!(guard = makemon(&pm_guard, x, y)))
158 guard->isgd = guard->mpeaceful = 1;
161 if (!cansee(guard->mx, guard->my)) {
167 pline("Suddenly one of the Vault's guards enters!");
170 pline("\"Hello stranger, who are you?\" - ");
172 } while (!letter(buf[0]));
174 if (!strcmp(buf, "Croesus") || !strcmp(buf, "Kroisos")) {
175 pline("\"Oh, yes - of course. Sorry to have disturbed you.\"");
181 pline("\"I don't know you.\"");
183 pline("\"Please follow me.\"");
185 pline("\"Most likely all that gold was stolen from this vault.\"");
186 pline("\"Please drop your gold (say d$ ) and follow me.\"");
191 EGD->fakecorr[0].fx = x;
192 EGD->fakecorr[0].fy = y;
193 EGD->fakecorr[0].ftyp = levl[x][y].typ;
194 levl[x][y].typ = DOOR;
202 int x, y, dx, dy, gx, gy, nx, ny, typ;
203 struct fakecorridor *fcp;
206 if (!guard || gdlevel != dlevel) {
207 impossible("Where is the guard?");
208 return (2); /* died */
210 if (u.ugold || goldincorridor())
211 return (0); /* didnt move */
212 if (dist(guard->mx, guard->my) > 1 || EGD->gddone) {
214 return (0); /* didnt move */
218 /* look around (hor & vert only) for accessible places */
219 for (nx = x - 1; nx <= x + 1; nx++)
220 for (ny = y - 1; ny <= y + 1; ny++) {
221 if (nx == x || ny == y)
222 if (nx != x || ny != y)
224 if (!IS_WALL(typ = (crm = &levl[nx][ny])->typ) && typ != POOL) {
226 for (i = EGD->fcbeg; i < EGD->fcend; i++)
227 if (EGD->fakecorr[i].fx == nx &&
228 EGD->fakecorr[i].fy == ny)
230 if ((i = inroom(nx, ny)) >= 0 && rooms[i].rtype == VAULT)
232 /* seems we found a good place to leave him alone */
236 crm->typ = (typ == SCORR) ? CORR : DOOR;
245 dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
246 dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
247 if (abs(gx - x) >= abs(gy - y))
252 while ((typ = (crm = &levl[nx][ny])->typ) != 0) {
253 /* in view of the above we must have IS_WALL(typ) or typ == POOL */
254 /* must be a wall here */
255 if (isok(nx + nx - x, ny + ny - y) && typ != POOL &&
256 ZAP_POS(levl[nx + nx - x][ny + ny - y].typ)) {
271 /* I don't like this, but ... */
277 if (cansee(nx, ny)) {
281 fcp = &(EGD->fakecorr[EGD->fcend]);
282 if (EGD->fcend++ == FCSIZ)
283 panic("fakecorr overflow");
304 replgd(struct monst *mtmp, struct monst *mtmp2)