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