1 1.6 dholland /* $NetBSD: hack.search.c,v 1.6 2009/06/07 18:30:39 dholland Exp $ */ 2 1.4 christos 3 1.2 mycroft /* 4 1.5 jsm * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, 5 1.5 jsm * Amsterdam 6 1.5 jsm * All rights reserved. 7 1.5 jsm * 8 1.5 jsm * Redistribution and use in source and binary forms, with or without 9 1.5 jsm * modification, are permitted provided that the following conditions are 10 1.5 jsm * met: 11 1.5 jsm * 12 1.5 jsm * - Redistributions of source code must retain the above copyright notice, 13 1.5 jsm * this list of conditions and the following disclaimer. 14 1.5 jsm * 15 1.5 jsm * - Redistributions in binary form must reproduce the above copyright 16 1.5 jsm * notice, this list of conditions and the following disclaimer in the 17 1.5 jsm * documentation and/or other materials provided with the distribution. 18 1.5 jsm * 19 1.5 jsm * - Neither the name of the Stichting Centrum voor Wiskunde en 20 1.5 jsm * Informatica, nor the names of its contributors may be used to endorse or 21 1.5 jsm * promote products derived from this software without specific prior 22 1.5 jsm * written permission. 23 1.5 jsm * 24 1.5 jsm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 25 1.5 jsm * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 1.5 jsm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 27 1.5 jsm * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 28 1.5 jsm * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 1.5 jsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 1.5 jsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 1.5 jsm * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 1.5 jsm * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 1.5 jsm * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 1.5 jsm * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 1.5 jsm */ 36 1.5 jsm 37 1.5 jsm /* 38 1.5 jsm * Copyright (c) 1982 Jay Fenlason <hack (at) gnu.org> 39 1.5 jsm * All rights reserved. 40 1.5 jsm * 41 1.5 jsm * Redistribution and use in source and binary forms, with or without 42 1.5 jsm * modification, are permitted provided that the following conditions 43 1.5 jsm * are met: 44 1.5 jsm * 1. Redistributions of source code must retain the above copyright 45 1.5 jsm * notice, this list of conditions and the following disclaimer. 46 1.5 jsm * 2. Redistributions in binary form must reproduce the above copyright 47 1.5 jsm * notice, this list of conditions and the following disclaimer in the 48 1.5 jsm * documentation and/or other materials provided with the distribution. 49 1.5 jsm * 3. The name of the author may not be used to endorse or promote products 50 1.5 jsm * derived from this software without specific prior written permission. 51 1.5 jsm * 52 1.5 jsm * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 53 1.5 jsm * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 54 1.5 jsm * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 55 1.5 jsm * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 1.5 jsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 1.5 jsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 58 1.5 jsm * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 59 1.5 jsm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 60 1.5 jsm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 61 1.5 jsm * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 1.2 mycroft */ 63 1.2 mycroft 64 1.4 christos #include <sys/cdefs.h> 65 1.2 mycroft #ifndef lint 66 1.6 dholland __RCSID("$NetBSD: hack.search.c,v 1.6 2009/06/07 18:30:39 dholland Exp $"); 67 1.4 christos #endif /* not lint */ 68 1.1 cgd 69 1.1 cgd #include "hack.h" 70 1.4 christos #include "extern.h" 71 1.1 cgd 72 1.4 christos int 73 1.6 dholland findit(void) 74 1.4 christos { /* returns number of things found */ 75 1.4 christos int num; 76 1.4 christos xchar zx, zy; 77 1.4 christos struct trap *ttmp; 78 1.4 christos struct monst *mtmp; 79 1.4 christos xchar lx, hx, ly, hy; 80 1.4 christos 81 1.4 christos if (u.uswallow) 82 1.4 christos return (0); 83 1.4 christos for (lx = u.ux; (num = levl[lx - 1][u.uy].typ) && num != CORR; lx--); 84 1.4 christos for (hx = u.ux; (num = levl[hx + 1][u.uy].typ) && num != CORR; hx++); 85 1.4 christos for (ly = u.uy; (num = levl[u.ux][ly - 1].typ) && num != CORR; ly--); 86 1.4 christos for (hy = u.uy; (num = levl[u.ux][hy + 1].typ) && num != CORR; hy++); 87 1.1 cgd num = 0; 88 1.4 christos for (zy = ly; zy <= hy; zy++) 89 1.4 christos for (zx = lx; zx <= hx; zx++) { 90 1.4 christos if (levl[zx][zy].typ == SDOOR) { 91 1.1 cgd levl[zx][zy].typ = DOOR; 92 1.1 cgd atl(zx, zy, '+'); 93 1.1 cgd num++; 94 1.4 christos } else if (levl[zx][zy].typ == SCORR) { 95 1.1 cgd levl[zx][zy].typ = CORR; 96 1.1 cgd atl(zx, zy, CORR_SYM); 97 1.1 cgd num++; 98 1.4 christos } else if ((ttmp = t_at(zx, zy)) != NULL) { 99 1.4 christos if (ttmp->ttyp == PIERC) { 100 1.1 cgd (void) makemon(PM_PIERCER, zx, zy); 101 1.1 cgd num++; 102 1.1 cgd deltrap(ttmp); 103 1.4 christos } else if (!ttmp->tseen) { 104 1.1 cgd ttmp->tseen = 1; 105 1.4 christos if (!vism_at(zx, zy)) 106 1.4 christos atl(zx, zy, '^'); 107 1.4 christos num++; 108 1.4 christos } 109 1.4 christos } else if ((mtmp = m_at(zx, zy)) != NULL) 110 1.4 christos if (mtmp->mimic) { 111 1.4 christos seemimic(mtmp); 112 1.1 cgd num++; 113 1.1 cgd } 114 1.1 cgd } 115 1.4 christos return (num); 116 1.1 cgd } 117 1.1 cgd 118 1.4 christos int 119 1.6 dholland dosearch(void) 120 1.1 cgd { 121 1.4 christos xchar x, y; 122 1.4 christos struct trap *trap; 123 1.4 christos struct monst *mtmp; 124 1.1 cgd 125 1.4 christos if (u.uswallow) 126 1.1 cgd pline("What are you looking for? The exit?"); 127 1.1 cgd else 128 1.4 christos for (x = u.ux - 1; x < u.ux + 2; x++) 129 1.4 christos for (y = u.uy - 1; y < u.uy + 2; y++) 130 1.4 christos if (x != u.ux || y != u.uy) { 131 1.4 christos if (levl[x][y].typ == SDOOR) { 132 1.4 christos if (rn2(7)) 133 1.4 christos continue; 134 1.4 christos levl[x][y].typ = DOOR; 135 1.4 christos levl[x][y].seen = 0; /* force prl */ 136 1.4 christos prl(x, y); 137 1.4 christos nomul(0); 138 1.4 christos } else if (levl[x][y].typ == SCORR) { 139 1.4 christos if (rn2(7)) 140 1.4 christos continue; 141 1.4 christos levl[x][y].typ = CORR; 142 1.4 christos levl[x][y].seen = 0; /* force prl */ 143 1.4 christos prl(x, y); 144 1.4 christos nomul(0); 145 1.4 christos } else { 146 1.4 christos /* 147 1.4 christos * Be careful not to find 148 1.4 christos * anything in an SCORR or 149 1.4 christos * SDOOR 150 1.4 christos */ 151 1.4 christos if ((mtmp = m_at(x, y)) != NULL) 152 1.4 christos if (mtmp->mimic) { 153 1.4 christos seemimic(mtmp); 154 1.4 christos pline("You find a mimic."); 155 1.4 christos return (1); 156 1.4 christos } 157 1.4 christos for (trap = ftrap; trap; trap = trap->ntrap) 158 1.4 christos if (trap->tx == x && trap->ty == y && 159 1.4 christos !trap->tseen && !rn2(8)) { 160 1.4 christos nomul(0); 161 1.4 christos pline("You find a%s.", traps[trap->ttyp]); 162 1.4 christos if (trap->ttyp == PIERC) { 163 1.4 christos deltrap(trap); 164 1.4 christos (void) makemon(PM_PIERCER, x, y); 165 1.4 christos return (1); 166 1.4 christos } 167 1.4 christos trap->tseen = 1; 168 1.4 christos if (!vism_at(x, y)) 169 1.4 christos atl(x, y, '^'); 170 1.4 christos } 171 1.4 christos } 172 1.1 cgd } 173 1.4 christos return (1); 174 1.1 cgd } 175 1.1 cgd 176 1.4 christos int 177 1.6 dholland doidtrap(void) 178 1.4 christos { 179 1.4 christos struct trap *trap; 180 1.4 christos int x, y; 181 1.4 christos if (!getdir(1)) 182 1.4 christos return (0); 183 1.1 cgd x = u.ux + u.dx; 184 1.1 cgd y = u.uy + u.dy; 185 1.4 christos for (trap = ftrap; trap; trap = trap->ntrap) 186 1.4 christos if (trap->tx == x && trap->ty == y && trap->tseen) { 187 1.4 christos if (u.dz) 188 1.4 christos if ((u.dz < 0) != (!xdnstair && trap->ttyp == TRAPDOOR)) 189 1.4 christos continue; 190 1.4 christos pline("That is a%s.", traps[trap->ttyp]); 191 1.4 christos return (0); 192 1.1 cgd } 193 1.1 cgd pline("I can't see a trap there."); 194 1.4 christos return (0); 195 1.1 cgd } 196 1.1 cgd 197 1.4 christos void 198 1.6 dholland wakeup(struct monst *mtmp) 199 1.1 cgd { 200 1.1 cgd mtmp->msleep = 0; 201 1.1 cgd setmangry(mtmp); 202 1.4 christos if (mtmp->mimic) 203 1.4 christos seemimic(mtmp); 204 1.1 cgd } 205 1.1 cgd 206 1.1 cgd /* NOTE: we must check if(mtmp->mimic) before calling this routine */ 207 1.4 christos void 208 1.6 dholland seemimic(struct monst *mtmp) 209 1.1 cgd { 210 1.4 christos mtmp->mimic = 0; 211 1.4 christos mtmp->mappearance = 0; 212 1.4 christos unpmon(mtmp); 213 1.4 christos pmon(mtmp); 214 1.1 cgd } 215