xref: /dragonfly/games/hack/hack.wizard.c (revision 0ca59c34)
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 /* $DragonFly: src/games/hack/hack.wizard.c,v 1.3 2006/08/21 19:45:32 pavalos Exp $ */
5 
6 /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */
7 
8 #include "hack.h"
9 extern struct permonst pm_wizard;
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 static void aggravate(void);
17 static void clonewiz(struct monst *);
18 
19 /* If he has found the Amulet, make the wizard appear after some time */
20 void
21 amulet(void)
22 {
23 	struct obj *otmp;
24 	struct monst *mtmp;
25 
26 	if (!flags.made_amulet || !flags.no_of_wizards)
27 		return;
28 	/* find wizard, and wake him if necessary */
29 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
30 		if (mtmp->data->mlet == '1' && mtmp->msleep && !rn2(40))
31 			for (otmp = invent; otmp; otmp = otmp->nobj)
32 				if (otmp->olet == AMULET_SYM && !otmp->spe) {
33 					mtmp->msleep = 0;
34 					if (dist(mtmp->mx, mtmp->my) > 2)
35 						pline("You get the creepy feeling that somebody noticed your taking the Amulet.");
36 					return;
37 				}
38 }
39 
40 bool
41 wiz_hit(struct monst *mtmp)
42 {
43 	/* if we have stolen or found the amulet, we disappear */
44 	if (mtmp->minvent && mtmp->minvent->olet == AMULET_SYM &&
45 	    mtmp->minvent->spe == 0) {
46 		/* vanish -- very primitive */
47 		fall_down(mtmp);
48 		return (1);
49 	}
50 
51 	/* if it is lying around someplace, we teleport to it */
52 	if (!carrying(AMULET_OF_YENDOR)) {
53 		struct obj *otmp;
54 
55 		for (otmp = fobj; otmp; otmp = otmp->nobj)
56 			if (otmp->olet == AMULET_SYM && !otmp->spe) {
57 				if ((u.ux != otmp->ox || u.uy != otmp->oy) &&
58 				    !m_at(otmp->ox, otmp->oy)) {
59 					/* teleport to it and pick it up */
60 					mtmp->mx = otmp->ox;
61 					mtmp->my = otmp->oy;
62 					freeobj(otmp);
63 					mpickobj(mtmp, otmp);
64 					pmon(mtmp);
65 					return (0);
66 				}
67 				goto hithim;
68 			}
69 		return (0);	/* we don't know where it is */
70 	}
71 hithim:
72 	if (rn2(2)) {		/* hit - perhaps steal */
73 		/*
74 		 * if hit 1/20 chance of stealing amulet & vanish
75 		 *  - amulet is on level 26 again.
76 		 */
77 		if (hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd))
78 		    && !rn2(20) && stealamulet(mtmp))
79 			return (0);
80 	} else
81 		inrange(mtmp);		/* try magic */
82 	return (0);
83 }
84 
85 void
86 inrange(struct monst *mtmp)
87 {
88 	schar tx, ty;
89 
90 	/* do nothing if cancelled (but make '1' say something) */
91 	if (mtmp->data->mlet != '1' && mtmp->mcan)
92 		return;
93 
94 	/* spit fire only when both in a room or both in a corridor */
95 	if (inroom(u.ux, u.uy) != inroom(mtmp->mx, mtmp->my))
96 		return;
97 	tx = u.ux - mtmp->mx;
98 	ty = u.uy - mtmp->my;
99 	if ((!tx && abs(ty) < BOLT_LIM) || (!ty && abs(tx) < BOLT_LIM)
100 	    || (abs(tx) == abs(ty) && abs(tx) < BOLT_LIM)) {
101 		switch (mtmp->data->mlet) {
102 		case 'D':
103 			/* spit fire in the direction of @ (not nec. hitting) */
104 			buzz(-1, mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
105 			break;
106 		case '1':
107 			if (rn2(WIZSHOT))
108 				break;
109 			/*
110 			 * if you zapped wizard with wand of cancellation, he
111 			 * has to shake off the effects before he can throw
112 			 * spells successfully.  1/2 the time they fail anyway
113 			 */
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 					makemon(NULL, 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)
171 			done_in_by(mtmp);
172 	}
173 }
174 
175 static void
176 aggravate(void)
177 {
178 	struct monst *mtmp;
179 
180 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
181 		mtmp->msleep = 0;
182 		if (mtmp->mfroz && !rn2(5))
183 			mtmp->mfroz = 0;
184 	}
185 }
186 
187 static void
188 clonewiz(struct monst *mtmp)
189 {
190 	struct monst *mtmp2;
191 
192 	if ((mtmp2 = makemon(PM_WIZARD, mtmp->mx, mtmp->my)) != NULL) {
193 		flags.no_of_wizards = 2;
194 		unpmon(mtmp2);
195 		mtmp2->mappearance = wizapp[rn2(sizeof(wizapp) - 1)];
196 		pmon(mtmp);
197 	}
198 }
199