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