hack.search.c 6.5 KB

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