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