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