Merge branch 'vendor/OPENRESOLV' with the following changes:
[dragonfly.git] / games / hack / hack.wizard.c
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.wizard.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.wizard.c,v 1.3 1999/11/16 02:57:14 billf Exp $ */
4
5 /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */
6
7 #include "hack.h"
8 extern struct permonst pm_wizard;
9
10 #define WIZSHOT     6   /* one chance in WIZSHOT that wizard will try magic */
11 #define BOLT_LIM    8   /* from this distance D and 1 will try to hit you */
12
13 char wizapp[] = "@DNPTUVXcemntx";
14
15 static void aggravate(void);
16 static void clonewiz(struct monst *);
17
18 /* If he has found the Amulet, make the wizard appear after some time */
19 void
20 amulet(void)
21 {
22         struct obj *otmp;
23         struct monst *mtmp;
24
25         if (!flags.made_amulet || !flags.no_of_wizards)
26                 return;
27         /* find wizard, and wake him if necessary */
28         for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
29                 if (mtmp->data->mlet == '1' && mtmp->msleep && !rn2(40))
30                         for (otmp = invent; otmp; otmp = otmp->nobj)
31                                 if (otmp->olet == AMULET_SYM && !otmp->spe) {
32                                         mtmp->msleep = 0;
33                                         if (dist(mtmp->mx, mtmp->my) > 2)
34                                                 pline("You get the creepy feeling that somebody noticed your taking the Amulet.");
35                                         return;
36                                 }
37 }
38
39 bool
40 wiz_hit(struct monst *mtmp)
41 {
42         /* if we have stolen or found the amulet, we disappear */
43         if (mtmp->minvent && mtmp->minvent->olet == AMULET_SYM &&
44             mtmp->minvent->spe == 0) {
45                 /* vanish -- very primitive */
46                 fall_down(mtmp);
47                 return (1);
48         }
49
50         /* if it is lying around someplace, we teleport to it */
51         if (!carrying(AMULET_OF_YENDOR)) {
52                 struct obj *otmp;
53
54                 for (otmp = fobj; otmp; otmp = otmp->nobj)
55                         if (otmp->olet == AMULET_SYM && !otmp->spe) {
56                                 if ((u.ux != otmp->ox || u.uy != otmp->oy) &&
57                                     !m_at(otmp->ox, otmp->oy)) {
58                                         /* teleport to it and pick it up */
59                                         mtmp->mx = otmp->ox;
60                                         mtmp->my = otmp->oy;
61                                         freeobj(otmp);
62                                         mpickobj(mtmp, otmp);
63                                         pmon(mtmp);
64                                         return (0);
65                                 }
66                                 goto hithim;
67                         }
68                 return (0);     /* we don't know where it is */
69         }
70 hithim:
71         if (rn2(2)) {           /* hit - perhaps steal */
72                 /*
73                  * if hit 1/20 chance of stealing amulet & vanish
74                  *  - amulet is on level 26 again.
75                  */
76                 if (hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd))
77                     && !rn2(20) && stealamulet(mtmp))
78                         return (0);
79         } else
80                 inrange(mtmp);          /* try magic */
81         return (0);
82 }
83
84 void
85 inrange(struct monst *mtmp)
86 {
87         schar tx, ty;
88
89         /* do nothing if cancelled (but make '1' say something) */
90         if (mtmp->data->mlet != '1' && mtmp->mcan)
91                 return;
92
93         /* spit fire only when both in a room or both in a corridor */
94         if (inroom(u.ux, u.uy) != inroom(mtmp->mx, mtmp->my))
95                 return;
96         tx = u.ux - mtmp->mx;
97         ty = u.uy - mtmp->my;
98         if ((!tx && abs(ty) < BOLT_LIM) || (!ty && abs(tx) < BOLT_LIM)
99             || (abs(tx) == abs(ty) && abs(tx) < BOLT_LIM)) {
100                 switch (mtmp->data->mlet) {
101                 case 'D':
102                         /* spit fire in the direction of @ (not nec. hitting) */
103                         buzz(-1, mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
104                         break;
105                 case '1':
106                         if (rn2(WIZSHOT))
107                                 break;
108                         /*
109                          * if you zapped wizard with wand of cancellation, he
110                          * has to shake off the effects before he can throw
111                          * spells successfully.  1/2 the time they fail anyway
112                          */
113                         if (mtmp->mcan || rn2(2)) {
114                                 if (canseemon(mtmp))
115                                         pline("%s makes a gesture, then curses.",
116                                             Monnam(mtmp));
117                                 else
118                                         pline("You hear mumbled cursing.");
119                                 if (!rn2(3)) {
120                                         mtmp->mspeed = 0;
121                                         mtmp->minvis = 0;
122                                 }
123                                 if (!rn2(3))
124                                         mtmp->mcan = 0;
125                         } else {
126                                 if (canseemon(mtmp)) {
127                                         if (!rn2(6) && !Invis) {
128                                                 pline("%s hypnotizes you.", Monnam(mtmp));
129                                                 nomul(rn2(3) + 3);
130                                                 break;
131                                         } else
132                                                 pline("%s chants an incantation.",
133                                                     Monnam(mtmp));
134                                 } else
135                                         pline("You hear a mumbled incantation.");
136                                 switch (rn2(Invis ? 5 : 6)) {
137                                 case 0:
138                                         /* create a nasty monster from a deep level */
139                                         /* (for the moment, 'nasty' is not implemented) */
140                                         makemon(NULL, u.ux, u.uy);
141                                         break;
142                                 case 1:
143                                         pline("\"Destroy the thief, my pets!\"");
144                                         aggravate(); /* aggravate all the monsters */
145                                         /* FALLTHROUGH */
146                                 case 2:
147                                         if (flags.no_of_wizards == 1 && rnd(5) == 0)
148                                                 /* if only 1 wizard, clone himself */
149                                                 clonewiz(mtmp);
150                                         break;
151                                 case 3:
152                                         if (mtmp->mspeed == MSLOW)
153                                                 mtmp->mspeed = 0;
154                                         else
155                                                 mtmp->mspeed = MFAST;
156                                         break;
157                                 case 4:
158                                         mtmp->minvis = 1;
159                                         break;
160                                 case 5:
161                                         /* Only if not Invisible */
162                                         pline("You hear a clap of thunder!");
163                                         /* shoot a bolt of fire or cold, or a sleep ray */
164                                         buzz(-rnd(3), mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
165                                         break;
166                                 }
167                         }
168                 }
169                 if (u.uhp < 1)
170                         done_in_by(mtmp);
171         }
172 }
173
174 static void
175 aggravate(void)
176 {
177         struct monst *mtmp;
178
179         for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
180                 mtmp->msleep = 0;
181                 if (mtmp->mfroz && !rn2(5))
182                         mtmp->mfroz = 0;
183         }
184 }
185
186 static void
187 clonewiz(struct monst *mtmp)
188 {
189         struct monst *mtmp2;
190
191         if ((mtmp2 = makemon(PM_WIZARD, mtmp->mx, mtmp->my)) != NULL) {
192                 flags.no_of_wizards = 2;
193                 unpmon(mtmp2);
194                 mtmp2->mappearance = wizapp[rn2(sizeof(wizapp) - 1)];
195                 pmon(mtmp);
196         }
197 }