1*1fa8a9a6Sdholland /* $NetBSD: hack.search.c,v 1.6 2009/06/07 18:30:39 dholland Exp $ */
23ea4a95cSchristos
3210cab45Smycroft /*
41c7f94e5Sjsm * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
51c7f94e5Sjsm * Amsterdam
61c7f94e5Sjsm * All rights reserved.
71c7f94e5Sjsm *
81c7f94e5Sjsm * Redistribution and use in source and binary forms, with or without
91c7f94e5Sjsm * modification, are permitted provided that the following conditions are
101c7f94e5Sjsm * met:
111c7f94e5Sjsm *
121c7f94e5Sjsm * - Redistributions of source code must retain the above copyright notice,
131c7f94e5Sjsm * this list of conditions and the following disclaimer.
141c7f94e5Sjsm *
151c7f94e5Sjsm * - Redistributions in binary form must reproduce the above copyright
161c7f94e5Sjsm * notice, this list of conditions and the following disclaimer in the
171c7f94e5Sjsm * documentation and/or other materials provided with the distribution.
181c7f94e5Sjsm *
191c7f94e5Sjsm * - Neither the name of the Stichting Centrum voor Wiskunde en
201c7f94e5Sjsm * Informatica, nor the names of its contributors may be used to endorse or
211c7f94e5Sjsm * promote products derived from this software without specific prior
221c7f94e5Sjsm * written permission.
231c7f94e5Sjsm *
241c7f94e5Sjsm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
251c7f94e5Sjsm * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
261c7f94e5Sjsm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
271c7f94e5Sjsm * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
281c7f94e5Sjsm * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
291c7f94e5Sjsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
301c7f94e5Sjsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
311c7f94e5Sjsm * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
321c7f94e5Sjsm * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
331c7f94e5Sjsm * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
341c7f94e5Sjsm * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
351c7f94e5Sjsm */
361c7f94e5Sjsm
371c7f94e5Sjsm /*
381c7f94e5Sjsm * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
391c7f94e5Sjsm * All rights reserved.
401c7f94e5Sjsm *
411c7f94e5Sjsm * Redistribution and use in source and binary forms, with or without
421c7f94e5Sjsm * modification, are permitted provided that the following conditions
431c7f94e5Sjsm * are met:
441c7f94e5Sjsm * 1. Redistributions of source code must retain the above copyright
451c7f94e5Sjsm * notice, this list of conditions and the following disclaimer.
461c7f94e5Sjsm * 2. Redistributions in binary form must reproduce the above copyright
471c7f94e5Sjsm * notice, this list of conditions and the following disclaimer in the
481c7f94e5Sjsm * documentation and/or other materials provided with the distribution.
491c7f94e5Sjsm * 3. The name of the author may not be used to endorse or promote products
501c7f94e5Sjsm * derived from this software without specific prior written permission.
511c7f94e5Sjsm *
521c7f94e5Sjsm * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
531c7f94e5Sjsm * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
541c7f94e5Sjsm * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
551c7f94e5Sjsm * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
561c7f94e5Sjsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
571c7f94e5Sjsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
581c7f94e5Sjsm * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
591c7f94e5Sjsm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
601c7f94e5Sjsm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
611c7f94e5Sjsm * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62210cab45Smycroft */
63210cab45Smycroft
643ea4a95cSchristos #include <sys/cdefs.h>
65210cab45Smycroft #ifndef lint
66*1fa8a9a6Sdholland __RCSID("$NetBSD: hack.search.c,v 1.6 2009/06/07 18:30:39 dholland Exp $");
67210cab45Smycroft #endif /* not lint */
6861f28255Scgd
6961f28255Scgd #include "hack.h"
703ea4a95cSchristos #include "extern.h"
7161f28255Scgd
723ea4a95cSchristos int
findit(void)73*1fa8a9a6Sdholland findit(void)
743ea4a95cSchristos { /* returns number of things found */
7561f28255Scgd int num;
763ea4a95cSchristos xchar zx, zy;
773ea4a95cSchristos struct trap *ttmp;
783ea4a95cSchristos struct monst *mtmp;
7961f28255Scgd xchar lx, hx, ly, hy;
8061f28255Scgd
813ea4a95cSchristos if (u.uswallow)
823ea4a95cSchristos return (0);
8361f28255Scgd for (lx = u.ux; (num = levl[lx - 1][u.uy].typ) && num != CORR; lx--);
8461f28255Scgd for (hx = u.ux; (num = levl[hx + 1][u.uy].typ) && num != CORR; hx++);
8561f28255Scgd for (ly = u.uy; (num = levl[u.ux][ly - 1].typ) && num != CORR; ly--);
8661f28255Scgd for (hy = u.uy; (num = levl[u.ux][hy + 1].typ) && num != CORR; hy++);
8761f28255Scgd num = 0;
8861f28255Scgd for (zy = ly; zy <= hy; zy++)
8961f28255Scgd for (zx = lx; zx <= hx; zx++) {
9061f28255Scgd if (levl[zx][zy].typ == SDOOR) {
9161f28255Scgd levl[zx][zy].typ = DOOR;
9261f28255Scgd atl(zx, zy, '+');
9361f28255Scgd num++;
9461f28255Scgd } else if (levl[zx][zy].typ == SCORR) {
9561f28255Scgd levl[zx][zy].typ = CORR;
9661f28255Scgd atl(zx, zy, CORR_SYM);
9761f28255Scgd num++;
983ea4a95cSchristos } else if ((ttmp = t_at(zx, zy)) != NULL) {
9961f28255Scgd if (ttmp->ttyp == PIERC) {
10061f28255Scgd (void) makemon(PM_PIERCER, zx, zy);
10161f28255Scgd num++;
10261f28255Scgd deltrap(ttmp);
10361f28255Scgd } else if (!ttmp->tseen) {
10461f28255Scgd ttmp->tseen = 1;
10561f28255Scgd if (!vism_at(zx, zy))
10661f28255Scgd atl(zx, zy, '^');
10761f28255Scgd num++;
10861f28255Scgd }
1093ea4a95cSchristos } else if ((mtmp = m_at(zx, zy)) != NULL)
1103ea4a95cSchristos if (mtmp->mimic) {
11161f28255Scgd seemimic(mtmp);
11261f28255Scgd num++;
11361f28255Scgd }
11461f28255Scgd }
11561f28255Scgd return (num);
11661f28255Scgd }
11761f28255Scgd
1183ea4a95cSchristos int
dosearch(void)119*1fa8a9a6Sdholland dosearch(void)
12061f28255Scgd {
1213ea4a95cSchristos xchar x, y;
1223ea4a95cSchristos struct trap *trap;
1233ea4a95cSchristos struct monst *mtmp;
12461f28255Scgd
12561f28255Scgd if (u.uswallow)
12661f28255Scgd pline("What are you looking for? The exit?");
12761f28255Scgd else
12861f28255Scgd for (x = u.ux - 1; x < u.ux + 2; x++)
1293ea4a95cSchristos for (y = u.uy - 1; y < u.uy + 2; y++)
1303ea4a95cSchristos if (x != u.ux || y != u.uy) {
13161f28255Scgd if (levl[x][y].typ == SDOOR) {
1323ea4a95cSchristos if (rn2(7))
1333ea4a95cSchristos continue;
13461f28255Scgd levl[x][y].typ = DOOR;
13561f28255Scgd levl[x][y].seen = 0; /* force prl */
13661f28255Scgd prl(x, y);
13761f28255Scgd nomul(0);
13861f28255Scgd } else if (levl[x][y].typ == SCORR) {
1393ea4a95cSchristos if (rn2(7))
1403ea4a95cSchristos continue;
14161f28255Scgd levl[x][y].typ = CORR;
14261f28255Scgd levl[x][y].seen = 0; /* force prl */
14361f28255Scgd prl(x, y);
14461f28255Scgd nomul(0);
14561f28255Scgd } else {
1463ea4a95cSchristos /*
1473ea4a95cSchristos * Be careful not to find
1483ea4a95cSchristos * anything in an SCORR or
1493ea4a95cSchristos * SDOOR
1503ea4a95cSchristos */
1513ea4a95cSchristos if ((mtmp = m_at(x, y)) != NULL)
1523ea4a95cSchristos if (mtmp->mimic) {
15361f28255Scgd seemimic(mtmp);
15461f28255Scgd pline("You find a mimic.");
15561f28255Scgd return (1);
15661f28255Scgd }
15761f28255Scgd for (trap = ftrap; trap; trap = trap->ntrap)
15861f28255Scgd if (trap->tx == x && trap->ty == y &&
15961f28255Scgd !trap->tseen && !rn2(8)) {
16061f28255Scgd nomul(0);
16161f28255Scgd pline("You find a%s.", traps[trap->ttyp]);
16261f28255Scgd if (trap->ttyp == PIERC) {
16361f28255Scgd deltrap(trap);
16461f28255Scgd (void) makemon(PM_PIERCER, x, y);
16561f28255Scgd return (1);
16661f28255Scgd }
16761f28255Scgd trap->tseen = 1;
1683ea4a95cSchristos if (!vism_at(x, y))
1693ea4a95cSchristos atl(x, y, '^');
17061f28255Scgd }
17161f28255Scgd }
17261f28255Scgd }
17361f28255Scgd return (1);
17461f28255Scgd }
17561f28255Scgd
1763ea4a95cSchristos int
doidtrap(void)177*1fa8a9a6Sdholland doidtrap(void)
1783ea4a95cSchristos {
1793ea4a95cSchristos struct trap *trap;
1803ea4a95cSchristos int x, y;
1813ea4a95cSchristos if (!getdir(1))
1823ea4a95cSchristos return (0);
18361f28255Scgd x = u.ux + u.dx;
18461f28255Scgd y = u.uy + u.dy;
18561f28255Scgd for (trap = ftrap; trap; trap = trap->ntrap)
18661f28255Scgd if (trap->tx == x && trap->ty == y && trap->tseen) {
18761f28255Scgd if (u.dz)
18861f28255Scgd if ((u.dz < 0) != (!xdnstair && trap->ttyp == TRAPDOOR))
18961f28255Scgd continue;
19061f28255Scgd pline("That is a%s.", traps[trap->ttyp]);
19161f28255Scgd return (0);
19261f28255Scgd }
19361f28255Scgd pline("I can't see a trap there.");
19461f28255Scgd return (0);
19561f28255Scgd }
19661f28255Scgd
1973ea4a95cSchristos void
wakeup(struct monst * mtmp)198*1fa8a9a6Sdholland wakeup(struct monst *mtmp)
19961f28255Scgd {
20061f28255Scgd mtmp->msleep = 0;
20161f28255Scgd setmangry(mtmp);
2023ea4a95cSchristos if (mtmp->mimic)
2033ea4a95cSchristos seemimic(mtmp);
20461f28255Scgd }
20561f28255Scgd
20661f28255Scgd /* NOTE: we must check if(mtmp->mimic) before calling this routine */
2073ea4a95cSchristos void
seemimic(struct monst * mtmp)208*1fa8a9a6Sdholland seemimic(struct monst *mtmp)
20961f28255Scgd {
21061f28255Scgd mtmp->mimic = 0;
21161f28255Scgd mtmp->mappearance = 0;
21261f28255Scgd unpmon(mtmp);
21361f28255Scgd pmon(mtmp);
21461f28255Scgd }
215