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