]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.wizard.c
f1b5b0313e7ef82a838f1f0efbe7518c5a236629
[bsdgames-darwin.git] / hack / hack.wizard.c
1 /* $NetBSD: hack.wizard.c,v 1.8 2009/06/07 18:30:39 dholland Exp $ */
2
3 /*
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
5 * Amsterdam
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
22 * written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 /*
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 */
63
64 #include <sys/cdefs.h>
65 #ifndef lint
66 __RCSID("$NetBSD: hack.wizard.c,v 1.8 2009/06/07 18:30:39 dholland Exp $");
67 #endif /* not lint */
68
69 /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */
70
71 #include "hack.h"
72 #include "extern.h"
73
74 #define WIZSHOT 6 /* one chance in WIZSHOT that wizard will try
75 * magic */
76 #define BOLT_LIM 8 /* from this distance D and 1 will try to hit
77 * you */
78
79 const char wizapp[] = "@DNPTUVXcemntx";
80
81 /* If he has found the Amulet, make the wizard appear after some time */
82 void
83 amulet(void)
84 {
85 struct obj *otmp;
86 struct monst *mtmp;
87
88 if (!flags.made_amulet || !flags.no_of_wizards)
89 return;
90 /* find wizard, and wake him if necessary */
91 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
92 if (mtmp->data->mlet == '1' && mtmp->msleep && !rn2(40))
93 for (otmp = invent; otmp; otmp = otmp->nobj)
94 if (otmp->olet == AMULET_SYM && !otmp->spe) {
95 mtmp->msleep = 0;
96 if (dist(mtmp->mx, mtmp->my) > 2)
97 pline(
98 "You get the creepy feeling that somebody noticed your taking the Amulet."
99 );
100 return;
101 }
102 }
103
104 int
105 wiz_hit(struct monst *mtmp)
106 {
107 /* if we have stolen or found the amulet, we disappear */
108 if (mtmp->minvent && mtmp->minvent->olet == AMULET_SYM &&
109 mtmp->minvent->spe == 0) {
110 /* vanish -- very primitive */
111 fall_down(mtmp);
112 return (1);
113 }
114 /* if it is lying around someplace, we teleport to it */
115 if (!carrying(AMULET_OF_YENDOR)) {
116 struct obj *otmp;
117
118 for (otmp = fobj; otmp; otmp = otmp->nobj)
119 if (otmp->olet == AMULET_SYM && !otmp->spe) {
120 if ((u.ux != otmp->ox || u.uy != otmp->oy) &&
121 !m_at(otmp->ox, otmp->oy)) {
122
123 /* teleport to it and pick it up */
124 mtmp->mx = otmp->ox;
125 mtmp->my = otmp->oy;
126 freeobj(otmp);
127 mpickobj(mtmp, otmp);
128 pmon(mtmp);
129 return (0);
130 }
131 goto hithim;
132 }
133 return (0); /* we don't know where it is */
134 }
135 hithim:
136 if (rn2(2)) { /* hit - perhaps steal */
137
138 /*
139 * if hit 1/20 chance of stealing amulet & vanish - amulet is
140 * on level 26 again.
141 */
142 if (hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd))
143 && !rn2(20) && stealamulet(mtmp)) {
144 /* nothing */
145 }
146 } else
147 inrange(mtmp); /* try magic */
148 return (0);
149 }
150
151 void
152 inrange(struct monst *mtmp)
153 {
154 schar tx, ty;
155
156 /* do nothing if cancelled (but make '1' say something) */
157 if (mtmp->data->mlet != '1' && mtmp->mcan)
158 return;
159
160 /* spit fire only when both in a room or both in a corridor */
161 if (inroom(u.ux, u.uy) != inroom(mtmp->mx, mtmp->my))
162 return;
163 tx = u.ux - mtmp->mx;
164 ty = u.uy - mtmp->my;
165 if ((!tx && abs(ty) < BOLT_LIM) || (!ty && abs(tx) < BOLT_LIM)
166 || (abs(tx) == abs(ty) && abs(tx) < BOLT_LIM)) {
167 switch (mtmp->data->mlet) {
168 case 'D':
169 /* spit fire in the direction of @ (not nec. hitting) */
170 buzz(-1, mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
171 break;
172 case '1':
173 if (rn2(WIZSHOT))
174 break;
175 /*
176 * if you zapped wizard with wand of cancellation, he
177 * has to shake off the effects before he can throw
178 * spells successfully. 1/2 the time they fail
179 * anyway
180 */
181 if (mtmp->mcan || rn2(2)) {
182 if (canseemon(mtmp))
183 pline("%s makes a gesture, then curses.",
184 Monnam(mtmp));
185 else
186 pline("You hear mumbled cursing.");
187 if (!rn2(3)) {
188 mtmp->mspeed = 0;
189 mtmp->minvis = 0;
190 }
191 if (!rn2(3))
192 mtmp->mcan = 0;
193 } else {
194 if (canseemon(mtmp)) {
195 if (!rn2(6) && !Invis) {
196 pline("%s hypnotizes you.", Monnam(mtmp));
197 nomul(rn2(3) + 3);
198 break;
199 } else
200 pline("%s chants an incantation.",
201 Monnam(mtmp));
202 } else
203 pline("You hear a mumbled incantation.");
204 switch (rn2(Invis ? 5 : 6)) {
205 case 0:
206 /*
207 * create a nasty monster from a deep
208 * level
209 */
210 /*
211 * (for the moment, 'nasty' is not
212 * implemented)
213 */
214 (void) makemon((struct permonst *) 0, u.ux, u.uy);
215 break;
216 case 1:
217 pline("\"Destroy the thief, my pets!\"");
218 aggravate(); /* aggravate all the
219 * monsters */
220 /* fall into next case */
221 case 2:
222 if (flags.no_of_wizards == 1 && rnd(5) == 0)
223 /*
224 * if only 1 wizard, clone
225 * himself
226 */
227 clonewiz(mtmp);
228 break;
229 case 3:
230 if (mtmp->mspeed == MSLOW)
231 mtmp->mspeed = 0;
232 else
233 mtmp->mspeed = MFAST;
234 break;
235 case 4:
236 mtmp->minvis = 1;
237 break;
238 case 5:
239 /* Only if not Invisible */
240 pline("You hear a clap of thunder!");
241 /*
242 * shoot a bolt of fire or cold, or a
243 * sleep ray
244 */
245 buzz(-rnd(3), mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
246 break;
247 }
248 }
249 }
250 if (u.uhp < 1)
251 done_in_by(mtmp);
252 }
253 }
254
255 void
256 aggravate(void)
257 {
258 struct monst *mtmp;
259
260 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
261 mtmp->msleep = 0;
262 if (mtmp->mfroz && !rn2(5))
263 mtmp->mfroz = 0;
264 }
265 }
266
267 void
268 clonewiz(struct monst *mtmp)
269 {
270 struct monst *mtmp2;
271
272 if ((mtmp2 = makemon(PM_WIZARD, mtmp->mx, mtmp->my)) != NULL) {
273 flags.no_of_wizards = 2;
274 unpmon(mtmp2);
275 mtmp2->mappearance = wizapp[rn2(sizeof(wizapp) - 1)];
276 pmon(mtmp);
277 }
278 }