hack.wizard.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /* $NetBSD: hack.wizard.c,v 1.6 2003/04/02 18:36:41 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.wizard.c,v 1.6 2003/04/02 18:36:41 jsm Exp $");
  64. #endif /* not lint */
  65. /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */
  66. #include "hack.h"
  67. #include "extern.h"
  68. #define WIZSHOT 6 /* one chance in WIZSHOT that wizard will try
  69. * magic */
  70. #define BOLT_LIM 8 /* from this distance D and 1 will try to hit
  71. * you */
  72. const char wizapp[] = "@DNPTUVXcemntx";
  73. /* If he has found the Amulet, make the wizard appear after some time */
  74. void
  75. amulet()
  76. {
  77. struct obj *otmp;
  78. struct monst *mtmp;
  79. if (!flags.made_amulet || !flags.no_of_wizards)
  80. return;
  81. /* find wizard, and wake him if necessary */
  82. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  83. if (mtmp->data->mlet == '1' && mtmp->msleep && !rn2(40))
  84. for (otmp = invent; otmp; otmp = otmp->nobj)
  85. if (otmp->olet == AMULET_SYM && !otmp->spe) {
  86. mtmp->msleep = 0;
  87. if (dist(mtmp->mx, mtmp->my) > 2)
  88. pline(
  89. "You get the creepy feeling that somebody noticed your taking the Amulet."
  90. );
  91. return;
  92. }
  93. }
  94. int
  95. wiz_hit(mtmp)
  96. struct monst *mtmp;
  97. {
  98. /* if we have stolen or found the amulet, we disappear */
  99. if (mtmp->minvent && mtmp->minvent->olet == AMULET_SYM &&
  100. mtmp->minvent->spe == 0) {
  101. /* vanish -- very primitive */
  102. fall_down(mtmp);
  103. return (1);
  104. }
  105. /* if it is lying around someplace, we teleport to it */
  106. if (!carrying(AMULET_OF_YENDOR)) {
  107. struct obj *otmp;
  108. for (otmp = fobj; otmp; otmp = otmp->nobj)
  109. if (otmp->olet == AMULET_SYM && !otmp->spe) {
  110. if ((u.ux != otmp->ox || u.uy != otmp->oy) &&
  111. !m_at(otmp->ox, otmp->oy)) {
  112. /* teleport to it and pick it up */
  113. mtmp->mx = otmp->ox;
  114. mtmp->my = otmp->oy;
  115. freeobj(otmp);
  116. mpickobj(mtmp, otmp);
  117. pmon(mtmp);
  118. return (0);
  119. }
  120. goto hithim;
  121. }
  122. return (0); /* we don't know where it is */
  123. }
  124. hithim:
  125. if (rn2(2)) { /* hit - perhaps steal */
  126. /*
  127. * if hit 1/20 chance of stealing amulet & vanish - amulet is
  128. * on level 26 again.
  129. */
  130. if (hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd))
  131. && !rn2(20) && stealamulet(mtmp))
  132. (void)0;
  133. } else
  134. inrange(mtmp); /* try magic */
  135. return (0);
  136. }
  137. void
  138. inrange(mtmp)
  139. struct monst *mtmp;
  140. {
  141. schar tx, ty;
  142. /* do nothing if cancelled (but make '1' say something) */
  143. if (mtmp->data->mlet != '1' && mtmp->mcan)
  144. return;
  145. /* spit fire only when both in a room or both in a corridor */
  146. if (inroom(u.ux, u.uy) != inroom(mtmp->mx, mtmp->my))
  147. return;
  148. tx = u.ux - mtmp->mx;
  149. ty = u.uy - mtmp->my;
  150. if ((!tx && abs(ty) < BOLT_LIM) || (!ty && abs(tx) < BOLT_LIM)
  151. || (abs(tx) == abs(ty) && abs(tx) < BOLT_LIM)) {
  152. switch (mtmp->data->mlet) {
  153. case 'D':
  154. /* spit fire in the direction of @ (not nec. hitting) */
  155. buzz(-1, mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
  156. break;
  157. case '1':
  158. if (rn2(WIZSHOT))
  159. break;
  160. /*
  161. * if you zapped wizard with wand of cancellation, he
  162. * has to shake off the effects before he can throw
  163. * spells successfully. 1/2 the time they fail
  164. * anyway
  165. */
  166. if (mtmp->mcan || rn2(2)) {
  167. if (canseemon(mtmp))
  168. pline("%s makes a gesture, then curses.",
  169. Monnam(mtmp));
  170. else
  171. pline("You hear mumbled cursing.");
  172. if (!rn2(3)) {
  173. mtmp->mspeed = 0;
  174. mtmp->minvis = 0;
  175. }
  176. if (!rn2(3))
  177. mtmp->mcan = 0;
  178. } else {
  179. if (canseemon(mtmp)) {
  180. if (!rn2(6) && !Invis) {
  181. pline("%s hypnotizes you.", Monnam(mtmp));
  182. nomul(rn2(3) + 3);
  183. break;
  184. } else
  185. pline("%s chants an incantation.",
  186. Monnam(mtmp));
  187. } else
  188. pline("You hear a mumbled incantation.");
  189. switch (rn2(Invis ? 5 : 6)) {
  190. case 0:
  191. /*
  192. * create a nasty monster from a deep
  193. * level
  194. */
  195. /*
  196. * (for the moment, 'nasty' is not
  197. * implemented)
  198. */
  199. (void) makemon((struct permonst *) 0, u.ux, u.uy);
  200. break;
  201. case 1:
  202. pline("\"Destroy the thief, my pets!\"");
  203. aggravate(); /* aggravate all the
  204. * monsters */
  205. /* fall into next case */
  206. case 2:
  207. if (flags.no_of_wizards == 1 && rnd(5) == 0)
  208. /*
  209. * if only 1 wizard, clone
  210. * himself
  211. */
  212. clonewiz(mtmp);
  213. break;
  214. case 3:
  215. if (mtmp->mspeed == MSLOW)
  216. mtmp->mspeed = 0;
  217. else
  218. mtmp->mspeed = MFAST;
  219. break;
  220. case 4:
  221. mtmp->minvis = 1;
  222. break;
  223. case 5:
  224. /* Only if not Invisible */
  225. pline("You hear a clap of thunder!");
  226. /*
  227. * shoot a bolt of fire or cold, or a
  228. * sleep ray
  229. */
  230. buzz(-rnd(3), mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
  231. break;
  232. }
  233. }
  234. }
  235. if (u.uhp < 1)
  236. done_in_by(mtmp);
  237. }
  238. }
  239. void
  240. aggravate()
  241. {
  242. struct monst *mtmp;
  243. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  244. mtmp->msleep = 0;
  245. if (mtmp->mfroz && !rn2(5))
  246. mtmp->mfroz = 0;
  247. }
  248. }
  249. void
  250. clonewiz(mtmp)
  251. struct monst *mtmp;
  252. {
  253. struct monst *mtmp2;
  254. if ((mtmp2 = makemon(PM_WIZARD, mtmp->mx, mtmp->my)) != NULL) {
  255. flags.no_of_wizards = 2;
  256. unpmon(mtmp2);
  257. mtmp2->mappearance = wizapp[rn2(sizeof(wizapp) - 1)];
  258. pmon(mtmp);
  259. }
  260. }