mhitu.c (8422B)
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 2 /* mhitu.c - version 1.0.3 */ 3 4 #include "hack.h" 5 extern struct monst *makemon(); 6 7 /* 8 * mhitu: monster hits you 9 * returns 1 if monster dies (e.g. 'y', 'F'), 0 otherwise 10 */ 11 mhitu(mtmp) 12 register struct monst *mtmp; 13 { 14 register struct permonst *mdat = mtmp->data; 15 register int tmp, ctmp; 16 17 nomul(0); 18 19 /* If swallowed, can only be affected by hissers and by u.ustuck */ 20 if(u.uswallow) { 21 if(mtmp != u.ustuck) { 22 if(mdat->mlet == 'c' && !rn2(13)) { 23 pline("Outside, you hear %s's hissing!", 24 monnam(mtmp)); 25 pline("%s gets turned to stone!", 26 Monnam(u.ustuck)); 27 pline("And the same fate befalls you."); 28 done_in_by(mtmp); 29 /* "notreached": not return(1); */ 30 } 31 return(0); 32 } 33 switch(mdat->mlet) { /* now mtmp == u.ustuck */ 34 case ',': 35 youswld(mtmp, (u.uac > 0) ? u.uac+4 : 4, 36 5, "The trapper"); 37 break; 38 case '\'': 39 youswld(mtmp,rnd(6),7,"The lurker above"); 40 break; 41 case 'P': 42 youswld(mtmp,d(2,4),12,"The purple worm"); 43 break; 44 default: 45 /* This is not impossible! */ 46 #ifdef DGK 47 /* If the swallowing monster changes into a monster 48 * that is not capable of swallowing you, you get 49 * regurgitated - dgk 50 */ 51 pline("You get regurgitated!"); 52 u.ux = mtmp->mx; 53 u.uy = mtmp->my; 54 u.uswallow = 0; 55 u.ustuck = 0; 56 mnexto(mtmp); 57 setsee(); 58 docrt(); 59 break; 60 #else 61 pline("The mysterious monster totally digests you."); 62 u.uhp = 0; 63 #endif /* DGK /**/ 64 } 65 if(u.uhp < 1) done_in_by(mtmp); 66 return(0); 67 } 68 69 if(mdat->mlet == 'c' && Stoned) 70 return(0); 71 72 /* make eels visible the moment they hit/miss us */ 73 if(mdat->mlet == ';' && mtmp->minvis && cansee(mtmp->mx,mtmp->my)){ 74 mtmp->minvis = 0; 75 pmon(mtmp); 76 } 77 if(!index("1&DuxynNF",mdat->mlet)) 78 tmp = hitu(mtmp,d(mdat->damn,mdat->damd)); 79 else 80 tmp = 0; 81 if(index(UNDEAD, mdat->mlet) && midnight()) 82 tmp += hitu(mtmp,d(mdat->damn,mdat->damd)); 83 84 ctmp = tmp && !mtmp->mcan && 85 (!uarm || objects[uarm->otyp].a_can < rnd(3) || !rn2(50)); 86 switch(mdat->mlet) { 87 case '1': 88 if(wiz_hit(mtmp)) return(1); /* he disappeared */ 89 break; 90 case '&': 91 if(!mtmp->cham && !mtmp->mcan && !rn2(13)) { 92 (void) makemon(PM_DEMON,u.ux,u.uy); 93 } else { 94 (void) hitu(mtmp,d(2,6)); 95 (void) hitu(mtmp,d(2,6)); 96 (void) hitu(mtmp,rnd(3)); 97 (void) hitu(mtmp,rnd(3)); 98 (void) hitu(mtmp,rn1(4,2)); 99 } 100 break; 101 case ',': 102 if(tmp) justswld(mtmp,"The trapper"); 103 break; 104 case '\'': 105 if(tmp) justswld(mtmp, "The lurker above"); 106 break; 107 case ';': 108 if(ctmp) { 109 if(!u.ustuck && !rn2(10)) { 110 pline("%s swings itself around you!", 111 Monnam(mtmp)); 112 u.ustuck = mtmp; 113 } else if(u.ustuck == mtmp && 114 levl[mtmp->mx][mtmp->my].typ == POOL) { 115 pline("%s drowns you ...", Monnam(mtmp)); 116 done("drowned"); 117 } 118 } 119 break; 120 case 'A': 121 if(ctmp && rn2(2)) { 122 if(Poison_resistance) 123 pline("The sting doesn't seem to affect you."); 124 else { 125 pline("You feel weaker!"); 126 losestr(1); 127 } 128 } 129 break; 130 case 'C': 131 (void) hitu(mtmp,rnd(6)); 132 break; 133 case 'c': 134 if(!rn2(5)) { 135 pline("You hear %s's hissing!", monnam(mtmp)); 136 if(ctmp || !rn2(20) || (flags.moonphase == NEW_MOON 137 && !carrying(DEAD_LIZARD))) { 138 Stoned = 5; 139 /* pline("You get turned to stone!"); */ 140 /* done_in_by(mtmp); */ 141 } 142 } 143 break; 144 case 'D': 145 if(rn2(6) || mtmp->mcan) { 146 (void) hitu(mtmp,d(3,10)); 147 (void) hitu(mtmp,rnd(8)); 148 (void) hitu(mtmp,rnd(8)); 149 break; 150 } 151 kludge("%s breathes fire!","The dragon"); 152 buzz(-1,mtmp->mx,mtmp->my,u.ux-mtmp->mx,u.uy-mtmp->my); 153 break; 154 case 'd': 155 (void) hitu(mtmp,d(2, (flags.moonphase == FULL_MOON) ? 3 : 4)); 156 break; 157 case 'e': 158 (void) hitu(mtmp,d(3,6)); 159 break; 160 case 'F': 161 if(mtmp->mcan) break; 162 kludge("%s explodes!","The freezing sphere"); 163 if(Cold_resistance) pline("You don't seem affected by it."); 164 else { 165 xchar dn; 166 if(17-(u.ulevel/2) > rnd(20)) { 167 pline("You get blasted!"); 168 dn = 6; 169 } else { 170 pline("You duck the blast..."); 171 dn = 3; 172 } 173 losehp_m(d(dn,6), mtmp); 174 } 175 mondead(mtmp); 176 return(1); 177 case 'g': 178 if(ctmp && multi >= 0 && !rn2(3)) { 179 kludge("You are frozen by %ss juices","the cube'"); 180 nomul(-rnd(10)); 181 } 182 break; 183 case 'h': 184 if(ctmp && multi >= 0 && !rn2(5)) { 185 nomul(-rnd(10)); 186 kludge("You are put to sleep by %ss bite!", 187 "the homunculus'"); 188 } 189 break; 190 case 'j': 191 tmp = hitu(mtmp,rnd(3)); 192 tmp &= hitu(mtmp,rnd(3)); 193 if(tmp){ 194 (void) hitu(mtmp,rnd(4)); 195 (void) hitu(mtmp,rnd(4)); 196 } 197 break; 198 case 'k': 199 if((hitu(mtmp,rnd(4)) || !rn2(3)) && ctmp){ 200 poisoned("bee's sting",mdat->mname); 201 } 202 break; 203 case 'L': 204 if(tmp) stealgold(mtmp); 205 break; 206 case 'N': 207 if(mtmp->mcan && !Blind) { 208 pline("%s tries to seduce you, but you seem not interested.", 209 Amonnam(mtmp, "plain")); 210 if(rn2(3)) rloc(mtmp); 211 } else if(steal(mtmp)) { 212 rloc(mtmp); 213 mtmp->mflee = 1; 214 } 215 break; 216 case 'n': 217 if(!uwep && !uarm && !uarmh && !uarms && !uarmg) { 218 pline("%s hits! (I hope you don't mind)", 219 Monnam(mtmp)); 220 u.uhp += rnd(7); 221 if(!rn2(7)) u.uhpmax++; 222 if(u.uhp > u.uhpmax) u.uhp = u.uhpmax; 223 flags.botl = 1; 224 if(!rn2(50)) rloc(mtmp); 225 } else { 226 (void) hitu(mtmp,d(2,6)); 227 (void) hitu(mtmp,d(2,6)); 228 } 229 break; 230 case 'o': 231 tmp = hitu(mtmp,rnd(6)); 232 if(hitu(mtmp,rnd(6)) && tmp && /* hits with both paws */ 233 !u.ustuck && rn2(2)) { 234 u.ustuck = mtmp; 235 kludge("%s has grabbed you!","The owlbear"); 236 u.uhp -= d(2,8); 237 } else if(u.ustuck == mtmp) { 238 u.uhp -= d(2,8); 239 pline("You are being crushed."); 240 } 241 break; 242 case 'P': 243 if(ctmp && !rn2(4)) 244 justswld(mtmp,"The purple worm"); 245 else 246 (void) hitu(mtmp,d(2,4)); 247 break; 248 case 'Q': 249 (void) hitu(mtmp,rnd(2)); 250 (void) hitu(mtmp,rnd(2)); 251 break; 252 case 'R': 253 if(tmp && uarmh && !uarmh->rustfree && 254 (int) uarmh->spe >= -1) { 255 pline("Your helmet rusts!"); 256 uarmh->spe--; 257 } else 258 if(ctmp && uarm && !uarm->rustfree && /* Mike Newton */ 259 uarm->otyp < STUDDED_LEATHER_ARMOR && 260 (int) uarm->spe >= -1) { 261 pline("Your armor rusts!"); 262 uarm->spe--; 263 } 264 break; 265 case 'S': 266 if(ctmp && !rn2(8)) { 267 poisoned("snake's bite",mdat->mname); 268 } 269 break; 270 case 's': 271 if(tmp && !rn2(8)) { 272 poisoned("scorpion's sting",mdat->mname); 273 } 274 (void) hitu(mtmp,rnd(8)); 275 (void) hitu(mtmp,rnd(8)); 276 break; 277 case 'T': 278 (void) hitu(mtmp,rnd(6)); 279 (void) hitu(mtmp,rnd(6)); 280 break; 281 case 't': 282 if(!rn2(5)) rloc(mtmp); 283 break; 284 case 'u': 285 mtmp->mflee = 1; 286 break; 287 case 'U': 288 (void) hitu(mtmp,d(3,4)); 289 (void) hitu(mtmp,d(3,4)); 290 break; 291 case 'v': 292 if(ctmp && !u.ustuck) u.ustuck = mtmp; 293 break; 294 case 'V': 295 if(tmp) u.uhp -= 4; 296 if(ctmp) losexp(); 297 break; 298 case 'W': 299 if(ctmp) losexp(); 300 break; 301 #ifndef NOWORM 302 case 'w': 303 if(tmp) wormhit(mtmp); 304 #endif /* NOWORM /**/ 305 break; 306 case 'X': 307 (void) hitu(mtmp,rnd(5)); 308 (void) hitu(mtmp,rnd(5)); 309 (void) hitu(mtmp,rnd(5)); 310 break; 311 case 'x': 312 { register long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE; 313 pline("%s pricks in your %s leg!", 314 Monnam(mtmp), (side == RIGHT_SIDE) ? "right" : "left"); 315 set_wounded_legs(side, rnd(50)); 316 losehp_m(2, mtmp); 317 break; 318 } 319 case 'y': 320 if(mtmp->mcan) break; 321 mondead(mtmp); 322 if(!Blind) { 323 pline("You are blinded by a blast of light!"); 324 Blind = d(4,12); 325 seeoff(0); 326 } 327 return(1); 328 case 'Y': 329 (void) hitu(mtmp,rnd(6)); 330 break; 331 } 332 if(u.uhp < 1) done_in_by(mtmp); 333 return(0); 334 } 335 336 hitu(mtmp,dam) 337 register struct monst *mtmp; 338 register dam; 339 { 340 register tmp, res; 341 342 nomul(0); 343 if(u.uswallow) return(0); 344 345 if(mtmp->mhide && mtmp->mundetected) { 346 mtmp->mundetected = 0; 347 if(!Blind) { 348 register struct obj *obj; 349 extern char * Xmonnam(); 350 if(obj = o_at(mtmp->mx,mtmp->my)) 351 pline("%s was hidden under %s!", 352 Xmonnam(mtmp), doname(obj)); 353 } 354 } 355 356 tmp = u.uac; 357 /* give people with Ac = -10 at least some vulnerability */ 358 if(tmp < 0) { 359 dam += tmp; /* decrease damage */ 360 if(dam <= 0) dam = 1; 361 tmp = -rn2(-tmp); 362 } 363 tmp += mtmp->data->mlevel; 364 if(multi < 0) tmp += 4; 365 if((Invis && mtmp->data->mlet != 'I') || !mtmp->mcansee) tmp -= 2; 366 if(mtmp->mtrapped) tmp -= 2; 367 if(tmp <= rnd(20)) { 368 if(Blind) pline("It misses."); 369 else pline("%s misses.",Monnam(mtmp)); 370 res = 0; 371 } else { 372 if(Blind) pline("It hits!"); 373 else pline("%s hits!",Monnam(mtmp)); 374 losehp_m(dam, mtmp); 375 res = 1; 376 } 377 stop_occupation(); 378 return(res); 379 }