MFC: Make apps using '#define _POSIX_C_SOURCE' compile.
[dragonfly.git] / games / hack / hack.wizard.c
blobf3a04c37b9f47ca0247e69d840f16273a6cd2238
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 $ */
6 /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */
8 #include "hack.h"
9 extern struct permonst pm_wizard;
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 */
14 char wizapp[] = "@DNPTUVXcemntx";
16 static void aggravate(void);
17 static void clonewiz(struct monst *);
19 /* If he has found the Amulet, make the wizard appear after some time */
20 void
21 amulet(void)
23 struct obj *otmp;
24 struct monst *mtmp;
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(
36 "You get the creepy feeling that somebody noticed your taking the Amulet."
38 return;
42 bool
43 wiz_hit(struct monst *mtmp)
45 /* if we have stolen or found the amulet, we disappear */
46 if(mtmp->minvent && mtmp->minvent->olet == AMULET_SYM &&
47 mtmp->minvent->spe == 0) {
48 /* vanish -- very primitive */
49 fall_down(mtmp);
50 return(1);
53 /* if it is lying around someplace, we teleport to it */
54 if(!carrying(AMULET_OF_YENDOR)) {
55 struct obj *otmp;
57 for(otmp = fobj; otmp; otmp = otmp->nobj)
58 if(otmp->olet == AMULET_SYM && !otmp->spe) {
59 if((u.ux != otmp->ox || u.uy != otmp->oy) &&
60 !m_at(otmp->ox, otmp->oy)) {
62 /* teleport to it and pick it up */
63 mtmp->mx = otmp->ox;
64 mtmp->my = otmp->oy;
65 freeobj(otmp);
66 mpickobj(mtmp, otmp);
67 pmon(mtmp);
68 return(0);
70 goto hithim;
72 return(0); /* we don't know where it is */
74 hithim:
75 if(rn2(2)) { /* hit - perhaps steal */
77 /* if hit 1/20 chance of stealing amulet & vanish
78 - amulet is on level 26 again. */
79 if(hitu(mtmp, d(mtmp->data->damn,mtmp->data->damd))
80 && !rn2(20) && stealamulet(mtmp))
81 return(0);
83 else
84 inrange(mtmp); /* try magic */
85 return(0);
88 void
89 inrange(struct monst *mtmp)
91 schar tx,ty;
93 /* do nothing if cancelled (but make '1' say something) */
94 if(mtmp->data->mlet != '1' && mtmp->mcan)
95 return;
97 /* spit fire only when both in a room or both in a corridor */
98 if(inroom(u.ux,u.uy) != inroom(mtmp->mx,mtmp->my)) return;
99 tx = u.ux - mtmp->mx;
100 ty = u.uy - mtmp->my;
101 if((!tx && abs(ty) < BOLT_LIM) || (!ty && abs(tx) < BOLT_LIM)
102 || (abs(tx) == abs(ty) && abs(tx) < BOLT_LIM)){
103 switch(mtmp->data->mlet) {
104 case 'D':
105 /* spit fire in the direction of @ (not nec. hitting) */
106 buzz(-1,mtmp->mx,mtmp->my,sgn(tx),sgn(ty));
107 break;
108 case '1':
109 if(rn2(WIZSHOT)) break;
110 /* if you zapped wizard with wand of cancellation,
111 he has to shake off the effects before he can throw
112 spells successfully. 1/2 the time they fail anyway */
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;
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((struct permonst *)0, u.ux, u.uy);
141 break;
142 case 1:
143 pline("\"Destroy the thief, my pets!\"");
144 aggravate(); /* aggravate all the monsters */
145 /* fall into next case */
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;
169 if(u.uhp < 1) done_in_by(mtmp);
173 static void
174 aggravate(void)
176 struct monst *mtmp;
178 for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
179 mtmp->msleep = 0;
180 if(mtmp->mfroz && !rn2(5))
181 mtmp->mfroz = 0;
185 static void
186 clonewiz(struct monst *mtmp)
188 struct monst *mtmp2;
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);