Source:NetHack 3.6.3/src/mthrowu.c
Jump to navigation
Jump to search
Below is the full text to mthrowu.c from the source code of NetHack 3.6.3. To link to a particular line, write [[Source:NetHack 3.6.3/src/mthrowu.c#line12]], for example.
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* NetHack 3.6 mthrowu.c $NHDT-Date: 1573688695 2019/11/13 23:44:55 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.86 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Pasi Kallinen, 2016. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. STATIC_DCL int FDECL(monmulti, (struct monst *, struct obj *, struct obj *)); 9. STATIC_DCL void FDECL(monshoot, (struct monst *, struct obj *, struct obj *)); 10. STATIC_DCL int FDECL(drop_throw, (struct obj *, BOOLEAN_P, int, int)); 11. STATIC_DCL boolean FDECL(m_lined_up, (struct monst *, struct monst *)); 12. 13. #define URETREATING(x, y) \ 14. (distmin(u.ux, u.uy, x, y) > distmin(u.ux0, u.uy0, x, y)) 15. 16. #define POLE_LIM 5 /* How far monsters can use pole-weapons */ 17. 18. #define PET_MISSILE_RANGE2 36 /* Square of distance within which pets shoot */ 19. 20. /* 21. * Keep consistent with breath weapons in zap.c, and AD_* in monattk.h. 22. */ 23. STATIC_OVL NEARDATA const char *breathwep[] = { 24. "fragments", "fire", "frost", "sleep gas", "a disintegration blast", 25. "lightning", "poison gas", "acid", "strange breath #8", 26. "strange breath #9" 27. }; 28. 29. extern boolean notonhead; /* for long worms */ 30. STATIC_VAR int mesg_given; /* for m_throw()/thitu() 'miss' message */ 31. 32. /* hero is hit by something other than a monster */ 33. int 34. thitu(tlev, dam, objp, name) 35. int tlev, dam; 36. struct obj **objp; 37. const char *name; /* if null, then format `*objp' */ 38. { 39. struct obj *obj = objp ? *objp : 0; 40. const char *onm, *knm; 41. boolean is_acid; 42. int kprefix = KILLED_BY_AN, dieroll; 43. char onmbuf[BUFSZ], knmbuf[BUFSZ]; 44. 45. if (!name) { 46. if (!obj) 47. panic("thitu: name & obj both null?"); 48. name = strcpy(onmbuf, 49. (obj->quan > 1L) ? doname(obj) : mshot_xname(obj)); 50. knm = strcpy(knmbuf, killer_xname(obj)); 51. kprefix = KILLED_BY; /* killer_name supplies "an" if warranted */ 52. } else { 53. knm = name; 54. /* [perhaps ought to check for plural here to] */ 55. if (!strncmpi(name, "the ", 4) || !strncmpi(name, "an ", 3) 56. || !strncmpi(name, "a ", 2)) 57. kprefix = KILLED_BY; 58. } 59. onm = (obj && obj_is_pname(obj)) ? the(name) 60. : (obj && obj->quan > 1L) ? name 61. : an(name); 62. is_acid = (obj && obj->otyp == ACID_VENOM); 63. 64. if (u.uac + tlev <= (dieroll = rnd(20))) { 65. ++mesg_given; 66. if (Blind || !flags.verbose) { 67. pline("It misses."); 68. } else if (u.uac + tlev <= dieroll - 2) { 69. if (onm != onmbuf) 70. Strcpy(onmbuf, onm); /* [modifiable buffer for upstart()] */ 71. pline("%s %s you.", upstart(onmbuf), vtense(onmbuf, "miss")); 72. } else 73. You("are almost hit by %s.", onm); 74. return 0; 75. } else { 76. if (Blind || !flags.verbose) 77. You("are hit%s", exclam(dam)); 78. else 79. You("are hit by %s%s", onm, exclam(dam)); 80. 81. if (is_acid && Acid_resistance) { 82. pline("It doesn't seem to hurt you."); 83. } else if (obj && obj->oclass == POTION_CLASS) { 84. /* an explosion which scatters objects might hit hero with one 85. (potions deliberately thrown at hero are handled by m_throw) */ 86. potionhit(&youmonst, obj, POTHIT_OTHER_THROW); 87. *objp = obj = 0; /* potionhit() uses up the potion */ 88. } else { 89. if (obj && objects[obj->otyp].oc_material == SILVER 90. && Hate_silver) { 91. /* extra damage already applied by dmgval() */ 92. pline_The("silver sears your flesh!"); 93. exercise(A_CON, FALSE); 94. } 95. if (is_acid) 96. pline("It burns!"); 97. losehp(dam, knm, kprefix); /* acid damage */ 98. exercise(A_STR, FALSE); 99. } 100. return 1; 101. } 102. } 103. 104. /* Be sure this corresponds with what happens to player-thrown objects in 105. * dothrow.c (for consistency). --KAA 106. * Returns 0 if object still exists (not destroyed). 107. */ 108. STATIC_OVL int 109. drop_throw(obj, ohit, x, y) 110. register struct obj *obj; 111. boolean ohit; 112. int x, y; 113. { 114. int retvalu = 1; 115. int create; 116. struct monst *mtmp; 117. struct trap *t; 118. 119. if (obj->otyp == CREAM_PIE || obj->oclass == VENOM_CLASS 120. || (ohit && obj->otyp == EGG)) 121. create = 0; 122. else if (ohit && (is_multigen(obj) || obj->otyp == ROCK)) 123. create = !rn2(3); 124. else 125. create = 1; 126. 127. if (create && !((mtmp = m_at(x, y)) != 0 && mtmp->mtrapped 128. && (t = t_at(x, y)) != 0 129. && is_pit(t->ttyp))) { 130. int objgone = 0; 131. 132. if (down_gate(x, y) != -1) 133. objgone = ship_object(obj, x, y, FALSE); 134. if (!objgone) { 135. if (!flooreffects(obj, x, y, "fall")) { 136. place_object(obj, x, y); 137. if (!mtmp && x == u.ux && y == u.uy) 138. mtmp = &youmonst; 139. if (mtmp && ohit) 140. passive_obj(mtmp, obj, (struct attack *) 0); 141. stackobj(obj); 142. retvalu = 0; 143. } 144. } 145. } else 146. obfree(obj, (struct obj *) 0); 147. return retvalu; 148. } 149. 150. /* The monster that's being shot at when one monster shoots at another */ 151. STATIC_OVL struct monst *target = 0; 152. /* The monster that's doing the shooting/throwing */ 153. STATIC_OVL struct monst *archer = 0; 154. 155. /* calculate multishot volley count for mtmp throwing otmp (if not ammo) or 156. shooting otmp with mwep (if otmp is ammo and mwep appropriate launcher) */ 157. STATIC_OVL int 158. monmulti(mtmp, otmp, mwep) 159. struct monst *mtmp; 160. struct obj *otmp, *mwep; 161. { 162. int skill = (int) objects[otmp->otyp].oc_skill; 163. int multishot = 1; 164. 165. if (otmp->quan > 1L /* no point checking if there's only 1 */ 166. /* ammo requires corresponding launcher be wielded */ 167. && (is_ammo(otmp) 168. ? matching_launcher(otmp, mwep) 169. /* otherwise any stackable (non-ammo) weapon */ 170. : otmp->oclass == WEAPON_CLASS) 171. && !mtmp->mconf) { 172. /* Assumes lords are skilled, princes are expert */ 173. if (is_prince(mtmp->data)) 174. multishot += 2; 175. else if (is_lord(mtmp->data)) 176. multishot++; 177. /* fake players treated as skilled (regardless of role limits) */ 178. else if (is_mplayer(mtmp->data)) 179. multishot++; 180. 181. /* this portion is different from hero multishot; from slash'em? 182. */ 183. /* Elven Craftsmanship makes for light, quick bows */ 184. if (otmp->otyp == ELVEN_ARROW && !otmp->cursed) 185. multishot++; 186. /* for arrow, we checked bow&arrow when entering block, but for 187. bow, so far we've only validated that otmp is a weapon stack; 188. need to verify that it's a stack of arrows rather than darts */ 189. if (mwep && mwep->otyp == ELVEN_BOW && ammo_and_launcher(otmp, mwep) 190. && !mwep->cursed) 191. multishot++; 192. /* 1/3 of launcher enchantment */ 193. if (ammo_and_launcher(otmp, mwep) && mwep->spe > 1) 194. multishot += (long) rounddiv(mwep->spe, 3); 195. /* Some randomness */ 196. multishot = (long) rnd((int) multishot); 197. 198. /* class bonus */ 199. switch (monsndx(mtmp->data)) { 200. case PM_CAVEMAN: /* give bonus for low-tech gear */ 201. if (skill == -P_SLING || skill == P_SPEAR) 202. multishot++; 203. break; 204. case PM_MONK: /* allow higher volley count */ 205. if (skill == -P_SHURIKEN) 206. multishot++; 207. break; 208. case PM_RANGER: 209. if (skill != P_DAGGER) 210. multishot++; 211. break; 212. case PM_ROGUE: 213. if (skill == P_DAGGER) 214. multishot++; 215. break; 216. case PM_NINJA: 217. if (skill == -P_SHURIKEN || skill == -P_DART) 218. multishot++; 219. /*FALLTHRU*/ 220. case PM_SAMURAI: 221. if (otmp->otyp == YA && mwep->otyp == YUMI) 222. multishot++; 223. break; 224. default: 225. break; 226. } 227. /* racial bonus */ 228. if ((is_elf(mtmp->data) && otmp->otyp == ELVEN_ARROW 229. && mwep->otyp == ELVEN_BOW) 230. || (is_orc(mtmp->data) && otmp->otyp == ORCISH_ARROW 231. && mwep->otyp == ORCISH_BOW) 232. || (is_gnome(mtmp->data) && otmp->otyp == CROSSBOW_BOLT 233. && mwep->otyp == CROSSBOW)) 234. multishot++; 235. } 236. 237. if (otmp->quan < multishot) 238. multishot = (int) otmp->quan; 239. if (multishot < 1) 240. multishot = 1; 241. return multishot; 242. } 243. 244. /* mtmp throws otmp, or shoots otmp with mwep, at hero or at monster mtarg */ 245. STATIC_OVL void 246. monshoot(mtmp, otmp, mwep) 247. struct monst *mtmp; 248. struct obj *otmp, *mwep; 249. { 250. struct monst *mtarg = target; 251. int dm = distmin(mtmp->mx, mtmp->my, 252. mtarg ? mtarg->mx : mtmp->mux, 253. mtarg ? mtarg->my : mtmp->muy), 254. multishot = monmulti(mtmp, otmp, mwep); 255. /* 256. * Caller must have called linedup() to set up tbx, tby. 257. */ 258. 259. if (canseemon(mtmp)) { 260. const char *onm; 261. char onmbuf[BUFSZ], trgbuf[BUFSZ]; 262. 263. if (multishot > 1) { 264. /* "N arrows"; multishot > 1 implies otmp->quan > 1, so 265. xname()'s result will already be pluralized */ 266. Sprintf(onmbuf, "%d %s", multishot, xname(otmp)); 267. onm = onmbuf; 268. } else { 269. /* "an arrow" */ 270. onm = singular(otmp, xname); 271. onm = obj_is_pname(otmp) ? the(onm) : an(onm); 272. } 273. m_shot.s = ammo_and_launcher(otmp, mwep) ? TRUE : FALSE; 274. Strcpy(trgbuf, mtarg ? mon_nam(mtarg) : ""); 275. if (!strcmp(trgbuf, "it")) 276. Strcpy(trgbuf, humanoid(mtmp->data) ? "someone" : something); 277. pline("%s %s %s%s%s!", Monnam(mtmp), 278. m_shot.s ? "shoots" : "throws", onm, 279. mtarg ? " at " : "", trgbuf); 280. m_shot.o = otmp->otyp; 281. } else { 282. m_shot.o = STRANGE_OBJECT; /* don't give multishot feedback */ 283. } 284. m_shot.n = multishot; 285. for (m_shot.i = 1; m_shot.i <= m_shot.n; m_shot.i++) { 286. m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby), dm, otmp); 287. /* conceptually all N missiles are in flight at once, but 288. if mtmp gets killed (shot kills adjacent gas spore and 289. triggers explosion, perhaps), inventory will be dropped 290. and otmp might go away via merging into another stack */ 291. if (DEADMONSTER(mtmp) && m_shot.i < m_shot.n) 292. /* cancel pending shots (perhaps ought to give a message here 293. since we gave one above about throwing/shooting N missiles) */ 294. break; /* endmultishot(FALSE); */ 295. } 296. /* reset 'm_shot' */ 297. m_shot.n = m_shot.i = 0; 298. m_shot.o = STRANGE_OBJECT; 299. m_shot.s = FALSE; 300. } 301. 302. /* an object launched by someone/thing other than player attacks a monster; 303. return 1 if the object has stopped moving (hit or its range used up) */ 304. int 305. ohitmon(mtmp, otmp, range, verbose) 306. struct monst *mtmp; /* accidental target, located at <bhitpos.x,.y> */ 307. struct obj *otmp; /* missile; might be destroyed by drop_throw */ 308. int range; /* how much farther will object travel if it misses; 309. use -1 to signify to keep going even after hit, 310. unless it's gone (used for rolling_boulder_traps) */ 311. boolean verbose; /* give message(s) even when you can't see what happened */ 312. { 313. int damage, tmp; 314. boolean vis, ismimic; 315. int objgone = 1; 316. struct obj *mon_launcher = archer ? MON_WEP(archer) : NULL; 317. 318. notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); 319. ismimic = M_AP_TYPE(mtmp) && M_AP_TYPE(mtmp) != M_AP_MONSTER; 320. vis = cansee(bhitpos.x, bhitpos.y); 321. 322. tmp = 5 + find_mac(mtmp) + omon_adj(mtmp, otmp, FALSE); 323. /* High level monsters will be more likely to hit */ 324. /* This check applies only if this monster is the target 325. * the archer was aiming at. */ 326. if (archer && target == mtmp) { 327. if (archer->m_lev > 5) 328. tmp += archer->m_lev - 5; 329. if (mon_launcher && mon_launcher->oartifact) 330. tmp += spec_abon(mon_launcher, mtmp); 331. } 332. if (tmp < rnd(20)) { 333. if (!ismimic) { 334. if (vis) 335. miss(distant_name(otmp, mshot_xname), mtmp); 336. else if (verbose && !target) 337. pline("It is missed."); 338. } 339. if (!range) { /* Last position; object drops */ 340. (void) drop_throw(otmp, 0, mtmp->mx, mtmp->my); 341. return 1; 342. } 343. } else if (otmp->oclass == POTION_CLASS) { 344. if (ismimic) 345. seemimic(mtmp); 346. mtmp->msleeping = 0; 347. if (vis) 348. otmp->dknown = 1; 349. /* probably thrown by a monster rather than 'other', but the 350. distinction only matters when hitting the hero */ 351. potionhit(mtmp, otmp, POTHIT_OTHER_THROW); 352. return 1; 353. } else { 354. damage = dmgval(otmp, mtmp); 355. if (otmp->otyp == ACID_VENOM && resists_acid(mtmp)) 356. damage = 0; 357. #if 0 /* can't use this because we don't have the attacker */ 358. if (is_orc(mtmp->data) && is_elf(?magr?)) 359. damage++; 360. #endif 361. if (ismimic) 362. seemimic(mtmp); 363. mtmp->msleeping = 0; 364. if (vis) { 365. if (otmp->otyp == EGG) 366. pline("Splat! %s is hit with %s egg!", Monnam(mtmp), 367. otmp->known ? an(mons[otmp->corpsenm].mname) : "an"); 368. else 369. hit(distant_name(otmp, mshot_xname), mtmp, exclam(damage)); 370. } else if (verbose && !target) 371. pline("%s%s is hit%s", (otmp->otyp == EGG) ? "Splat! " : "", 372. Monnam(mtmp), exclam(damage)); 373. 374. if (otmp->opoisoned && is_poisonable(otmp)) { 375. if (resists_poison(mtmp)) { 376. if (vis) 377. pline_The("poison doesn't seem to affect %s.", 378. mon_nam(mtmp)); 379. } else { 380. if (rn2(30)) { 381. damage += rnd(6); 382. } else { 383. if (vis) 384. pline_The("poison was deadly..."); 385. damage = mtmp->mhp; 386. } 387. } 388. } 389. if (objects[otmp->otyp].oc_material == SILVER 390. && mon_hates_silver(mtmp)) { 391. boolean flesh = (!noncorporeal(mtmp->data) 392. && !amorphous(mtmp->data)); 393. 394. /* note: extra silver damage is handled by dmgval() */ 395. if (vis) { 396. char *m_name = mon_nam(mtmp); 397. 398. if (flesh) /* s_suffix returns a modifiable buffer */ 399. m_name = strcat(s_suffix(m_name), " flesh"); 400. pline_The("silver sears %s!", m_name); 401. } else if (verbose && !target) { 402. pline("%s is seared!", flesh ? "Its flesh" : "It"); 403. } 404. } 405. if (otmp->otyp == ACID_VENOM && cansee(mtmp->mx, mtmp->my)) { 406. if (resists_acid(mtmp)) { 407. if (vis || (verbose && !target)) 408. pline("%s is unaffected.", Monnam(mtmp)); 409. } else { 410. if (vis) 411. pline_The("%s burns %s!", hliquid("acid"), mon_nam(mtmp)); 412. else if (verbose && !target) 413. pline("It is burned!"); 414. } 415. } 416. if (otmp->otyp == EGG && touch_petrifies(&mons[otmp->corpsenm])) { 417. if (!munstone(mtmp, TRUE)) 418. minstapetrify(mtmp, TRUE); 419. if (resists_ston(mtmp)) 420. damage = 0; 421. } 422. 423. if (!DEADMONSTER(mtmp)) { /* might already be dead (if petrified) */ 424. mtmp->mhp -= damage; 425. if (DEADMONSTER(mtmp)) { 426. if (vis || (verbose && !target)) 427. pline("%s is %s!", Monnam(mtmp), 428. (nonliving(mtmp->data) || is_vampshifter(mtmp) 429. || !canspotmon(mtmp)) ? "destroyed" : "killed"); 430. /* don't blame hero for unknown rolling boulder trap */ 431. if (!context.mon_moving && (otmp->otyp != BOULDER 432. || range >= 0 || otmp->otrapped)) 433. xkilled(mtmp, XKILL_NOMSG); 434. else 435. mondied(mtmp); 436. } 437. } 438. 439. /* blinding venom and cream pie do 0 damage, but verify 440. that the target is still alive anyway */ 441. if (!DEADMONSTER(mtmp) 442. && can_blnd((struct monst *) 0, mtmp, 443. (uchar) ((otmp->otyp == BLINDING_VENOM) ? AT_SPIT 444. : AT_WEAP), 445. otmp)) { 446. if (vis && mtmp->mcansee) 447. pline("%s is blinded by %s.", Monnam(mtmp), the(xname(otmp))); 448. mtmp->mcansee = 0; 449. tmp = (int) mtmp->mblinded + rnd(25) + 20; 450. if (tmp > 127) 451. tmp = 127; 452. mtmp->mblinded = tmp; 453. } 454. 455. objgone = drop_throw(otmp, 1, bhitpos.x, bhitpos.y); 456. if (!objgone && range == -1) { /* special case */ 457. obj_extract_self(otmp); /* free it for motion again */ 458. return 0; 459. } 460. return 1; 461. } 462. return 0; 463. } 464. 465. #define MT_FLIGHTCHECK(pre) \ 466. (/* missile hits edge of screen */ \ 467. !isok(bhitpos.x + dx, bhitpos.y + dy) \ 468. /* missile hits the wall */ \ 469. || IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ) \ 470. /* missile hit closed door */ \ 471. || closed_door(bhitpos.x + dx, bhitpos.y + dy) \ 472. /* missile might hit iron bars */ \ 473. /* the random chance for small objects hitting bars is */ \ 474. /* skipped when reaching them at point blank range */ \ 475. || (levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS \ 476. && hits_bars(&singleobj, \ 477. bhitpos.x, bhitpos.y, \ 478. bhitpos.x + dx, bhitpos.y + dy, \ 479. ((pre) ? 0 : !rn2(5)), 0)) \ 480. /* Thrown objects "sink" */ \ 481. || (!(pre) && IS_SINK(levl[bhitpos.x][bhitpos.y].typ))) 482. 483. void 484. m_throw(mon, x, y, dx, dy, range, obj) 485. struct monst *mon; /* launching monster */ 486. int x, y, dx, dy, range; /* launch point, direction, and range */ 487. struct obj *obj; /* missile (or stack providing it) */ 488. { 489. struct monst *mtmp; 490. struct obj *singleobj; 491. char sym = obj->oclass; 492. int hitu = 0, oldumort, blindinc = 0; 493. 494. bhitpos.x = x; 495. bhitpos.y = y; 496. notonhead = FALSE; /* reset potentially stale value */ 497. 498. if (obj->quan == 1L) { 499. /* 500. * Remove object from minvent. This cannot be done later on; 501. * what if the player dies before then, leaving the monster 502. * with 0 daggers? (This caused the infamous 2^32-1 orcish 503. * dagger bug). 504. * 505. * VENOM is not in minvent - it should already be OBJ_FREE. 506. * The extract below does nothing. 507. */ 508. 509. /* not possibly_unwield, which checks the object's */ 510. /* location, not its existence */ 511. if (MON_WEP(mon) == obj) 512. setmnotwielded(mon, obj); 513. obj_extract_self(obj); 514. singleobj = obj; 515. obj = (struct obj *) 0; 516. } else { 517. singleobj = splitobj(obj, 1L); 518. obj_extract_self(singleobj); 519. } 520. 521. singleobj->owornmask = 0; /* threw one of multiple weapons in hand? */ 522. 523. if ((singleobj->cursed || singleobj->greased) && (dx || dy) && !rn2(7)) { 524. if (canseemon(mon) && flags.verbose) { 525. if (is_ammo(singleobj)) 526. pline("%s misfires!", Monnam(mon)); 527. else 528. pline("%s as %s throws it!", Tobjnam(singleobj, "slip"), 529. mon_nam(mon)); 530. } 531. dx = rn2(3) - 1; 532. dy = rn2(3) - 1; 533. /* check validity of new direction */ 534. if (!dx && !dy) { 535. (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y); 536. return; 537. } 538. } 539. 540. if (MT_FLIGHTCHECK(TRUE)) { 541. (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y); 542. return; 543. } 544. mesg_given = 0; /* a 'missile misses' message has not yet been shown */ 545. 546. /* Note: drop_throw may destroy singleobj. Since obj must be destroyed 547. * early to avoid the dagger bug, anyone who modifies this code should 548. * be careful not to use either one after it's been freed. 549. */ 550. if (sym) 551. tmp_at(DISP_FLASH, obj_to_glyph(singleobj, rn2_on_display_rng)); 552. while (range-- > 0) { /* Actually the loop is always exited by break */ 553. bhitpos.x += dx; 554. bhitpos.y += dy; 555. mtmp = m_at(bhitpos.x, bhitpos.y); 556. if (mtmp && shade_miss(mon, mtmp, singleobj, TRUE, TRUE)) { 557. /* if mtmp is a shade and missile passes harmlessly through it, 558. give message and skip it in order to keep going */ 559. mtmp = (struct monst *) 0; 560. } else if (mtmp) { 561. if (ohitmon(mtmp, singleobj, range, TRUE)) 562. break; 563. } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) { 564. if (multi) 565. nomul(0); 566. 567. if (singleobj->oclass == GEM_CLASS 568. && singleobj->otyp <= LAST_GEM + 9 /* 9 glass colors */ 569. && is_unicorn(youmonst.data)) { 570. if (singleobj->otyp > LAST_GEM) { 571. You("catch the %s.", xname(singleobj)); 572. You("are not interested in %s junk.", 573. s_suffix(mon_nam(mon))); 574. makeknown(singleobj->otyp); 575. dropy(singleobj); 576. } else { 577. You( 578. "accept %s gift in the spirit in which it was intended.", 579. s_suffix(mon_nam(mon))); 580. (void) hold_another_object(singleobj, 581. "You catch, but drop, %s.", 582. xname(singleobj), 583. "You catch:"); 584. } 585. break; 586. } 587. if (singleobj->oclass == POTION_CLASS) { 588. if (!Blind) 589. singleobj->dknown = 1; 590. potionhit(&youmonst, singleobj, POTHIT_MONST_THROW); 591. break; 592. } 593. oldumort = u.umortality; 594. switch (singleobj->otyp) { 595. int dam, hitv; 596. case EGG: 597. if (!touch_petrifies(&mons[singleobj->corpsenm])) { 598. impossible("monster throwing egg type %d", 599. singleobj->corpsenm); 600. hitu = 0; 601. break; 602. } 603. /* fall through */ 604. case CREAM_PIE: 605. case BLINDING_VENOM: 606. hitu = thitu(8, 0, &singleobj, (char *) 0); 607. break; 608. default: 609. dam = dmgval(singleobj, &youmonst); 610. hitv = 3 - distmin(u.ux, u.uy, mon->mx, mon->my); 611. if (hitv < -4) 612. hitv = -4; 613. if (is_elf(mon->data) 614. && objects[singleobj->otyp].oc_skill == P_BOW) { 615. hitv++; 616. if (MON_WEP(mon) && MON_WEP(mon)->otyp == ELVEN_BOW) 617. hitv++; 618. if (singleobj->otyp == ELVEN_ARROW) 619. dam++; 620. } 621. if (bigmonst(youmonst.data)) 622. hitv++; 623. hitv += 8 + singleobj->spe; 624. if (dam < 1) 625. dam = 1; 626. hitu = thitu(hitv, dam, &singleobj, (char *) 0); 627. } 628. if (hitu && singleobj->opoisoned && is_poisonable(singleobj)) { 629. char onmbuf[BUFSZ], knmbuf[BUFSZ]; 630. 631. Strcpy(onmbuf, xname(singleobj)); 632. Strcpy(knmbuf, killer_xname(singleobj)); 633. poisoned(onmbuf, A_STR, knmbuf, 634. /* if damage triggered life-saving, 635. poison is limited to attrib loss */ 636. (u.umortality > oldumort) ? 0 : 10, TRUE); 637. } 638. if (hitu && can_blnd((struct monst *) 0, &youmonst, 639. (uchar) ((singleobj->otyp == BLINDING_VENOM) 640. ? AT_SPIT 641. : AT_WEAP), 642. singleobj)) { 643. blindinc = rnd(25); 644. if (singleobj->otyp == CREAM_PIE) { 645. if (!Blind) 646. pline("Yecch! You've been creamed."); 647. else 648. pline("There's %s sticky all over your %s.", 649. something, body_part(FACE)); 650. } else if (singleobj->otyp == BLINDING_VENOM) { 651. const char *eyes = body_part(EYE); 652. 653. if (eyecount(youmonst.data) != 1) 654. eyes = makeplural(eyes); 655. /* venom in the eyes */ 656. if (!Blind) 657. pline_The("venom blinds you."); 658. else 659. Your("%s %s.", eyes, vtense(eyes, "sting")); 660. } 661. } 662. if (hitu && singleobj->otyp == EGG) { 663. if (!Stoned && !Stone_resistance 664. && !(poly_when_stoned(youmonst.data) 665. && polymon(PM_STONE_GOLEM))) { 666. make_stoned(5L, (char *) 0, KILLED_BY, ""); 667. } 668. } 669. stop_occupation(); 670. if (hitu) { 671. (void) drop_throw(singleobj, hitu, u.ux, u.uy); 672. break; 673. } 674. } 675. if (!range /* reached end of path */ 676. || MT_FLIGHTCHECK(FALSE)) { 677. if (singleobj) { /* hits_bars might have destroyed it */ 678. if (m_shot.n > 1 679. && (!mesg_given || bhitpos.x != u.ux || bhitpos.y != u.uy) 680. && (cansee(bhitpos.x, bhitpos.y) 681. || (archer && canseemon(archer)))) 682. pline("%s misses.", The(mshot_xname(singleobj))); 683. (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y); 684. } 685. break; 686. } 687. tmp_at(bhitpos.x, bhitpos.y); 688. delay_output(); 689. } 690. tmp_at(bhitpos.x, bhitpos.y); 691. delay_output(); 692. tmp_at(DISP_END, 0); 693. mesg_given = 0; /* reset */ 694. 695. if (blindinc) { 696. u.ucreamed += blindinc; 697. make_blinded(Blinded + (long) blindinc, FALSE); 698. if (!Blind) 699. Your1(vision_clears); 700. } 701. } 702. 703. #undef MT_FLIGHTCHECK 704. 705. /* Monster throws item at another monster */ 706. int 707. thrwmm(mtmp, mtarg) 708. struct monst *mtmp, *mtarg; 709. { 710. struct obj *otmp, *mwep; 711. register xchar x, y; 712. boolean ispole; 713. 714. /* Polearms won't be applied by monsters against other monsters */ 715. if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) { 716. mtmp->weapon_check = NEED_RANGED_WEAPON; 717. /* mon_wield_item resets weapon_check as appropriate */ 718. if (mon_wield_item(mtmp) != 0) 719. return 0; 720. } 721. 722. /* Pick a weapon */ 723. otmp = select_rwep(mtmp); 724. if (!otmp) 725. return 0; 726. ispole = is_pole(otmp); 727. 728. x = mtmp->mx; 729. y = mtmp->my; 730. 731. mwep = MON_WEP(mtmp); /* wielded weapon */ 732. 733. if (!ispole && m_lined_up(mtarg, mtmp)) { 734. int chance = max(BOLT_LIM - distmin(x, y, mtarg->mx, mtarg->my), 1); 735. 736. if (!mtarg->mflee || !rn2(chance)) { 737. if (ammo_and_launcher(otmp, mwep) 738. && dist2(mtmp->mx, mtmp->my, mtarg->mx, mtarg->my) 739. > PET_MISSILE_RANGE2) 740. return 0; /* Out of range */ 741. /* Set target monster */ 742. target = mtarg; 743. archer = mtmp; 744. monshoot(mtmp, otmp, mwep); /* multishot shooting or throwing */ 745. archer = target = (struct monst *) 0; 746. nomul(0); 747. return 1; 748. } 749. } 750. return 0; 751. } 752. 753. /* monster spits substance at monster */ 754. int 755. spitmm(mtmp, mattk, mtarg) 756. struct monst *mtmp, *mtarg; 757. struct attack *mattk; 758. { 759. struct obj *otmp; 760. 761. if (mtmp->mcan) { 762. if (!Deaf) 763. pline("A dry rattle comes from %s throat.", 764. s_suffix(mon_nam(mtmp))); 765. return 0; 766. } 767. if (m_lined_up(mtarg, mtmp)) { 768. switch (mattk->adtyp) { 769. case AD_BLND: 770. case AD_DRST: 771. otmp = mksobj(BLINDING_VENOM, TRUE, FALSE); 772. break; 773. default: 774. impossible("bad attack type in spitmu"); 775. /*FALLTHRU*/ 776. case AD_ACID: 777. otmp = mksobj(ACID_VENOM, TRUE, FALSE); 778. break; 779. } 780. if (!rn2(BOLT_LIM-distmin(mtmp->mx,mtmp->my,mtarg->mx,mtarg->my))) { 781. if (canseemon(mtmp)) 782. pline("%s spits venom!", Monnam(mtmp)); 783. target = mtarg; 784. m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby), 785. distmin(mtmp->mx,mtmp->my,mtarg->mx,mtarg->my), otmp); 786. target = (struct monst *)0; 787. nomul(0); 788. 789. /* If this is a pet, it'll get hungry. Minions and 790. * spell beings won't hunger */ 791. if (mtmp->mtame && !mtmp->isminion) { 792. struct edog *dog = EDOG(mtmp); 793. 794. /* Hunger effects will catch up next move */ 795. if (dog->hungrytime > 1) 796. dog->hungrytime -= 5; 797. } 798. 799. return 1; 800. } 801. } 802. return 0; 803. } 804. 805. /* monster breathes at monster (ranged) */ 806. int 807. breamm(mtmp, mattk, mtarg) 808. struct monst *mtmp, *mtarg; 809. struct attack *mattk; 810. { 811. /* if new breath types are added, change AD_ACID to max type */ 812. int typ = (mattk->adtyp == AD_RBRE) ? rnd(AD_ACID) : mattk->adtyp ; 813. 814. if (m_lined_up(mtarg, mtmp)) { 815. if (mtmp->mcan) { 816. if (!Deaf) { 817. if (canseemon(mtmp)) 818. pline("%s coughs.", Monnam(mtmp)); 819. else 820. You_hear("a cough."); 821. } 822. return 0; 823. } 824. if (!mtmp->mspec_used && rn2(3)) { 825. if ((typ >= AD_MAGM) && (typ <= AD_ACID)) { 826. if (canseemon(mtmp)) 827. pline("%s breathes %s!", Monnam(mtmp), breathwep[typ - 1]); 828. dobuzz((int) (-20 - (typ - 1)), (int) mattk->damn, 829. mtmp->mx, mtmp->my, sgn(tbx), sgn(tby), FALSE); 830. nomul(0); 831. /* breath runs out sometimes. Also, give monster some 832. * cunning; don't breath if the target fell asleep. 833. */ 834. mtmp->mspec_used = 6 + rn2(18); 835. 836. /* If this is a pet, it'll get hungry. Minions and 837. * spell beings won't hunger */ 838. if (mtmp->mtame && !mtmp->isminion) { 839. struct edog *dog = EDOG(mtmp); 840. 841. /* Hunger effects will catch up next move */ 842. if (dog->hungrytime >= 10) 843. dog->hungrytime -= 10; 844. } 845. } else impossible("Breath weapon %d used", typ-1); 846. } else 847. return 0; 848. } 849. return 1; 850. } 851. 852. 853. 854. /* remove an entire item from a monster's inventory; destroy that item */ 855. void 856. m_useupall(mon, obj) 857. struct monst *mon; 858. struct obj *obj; 859. { 860. obj_extract_self(obj); 861. if (obj->owornmask) { 862. if (obj == MON_WEP(mon)) 863. mwepgone(mon); 864. mon->misc_worn_check &= ~obj->owornmask; 865. update_mon_intrinsics(mon, obj, FALSE, FALSE); 866. obj->owornmask = 0L; 867. } 868. obfree(obj, (struct obj *) 0); 869. } 870. 871. /* remove one instance of an item from a monster's inventory */ 872. void 873. m_useup(mon, obj) 874. struct monst *mon; 875. struct obj *obj; 876. { 877. if (obj->quan > 1L) { 878. obj->quan--; 879. obj->owt = weight(obj); 880. } else { 881. m_useupall(mon, obj); 882. } 883. } 884. 885. /* monster attempts ranged weapon attack against player */ 886. void 887. thrwmu(mtmp) 888. struct monst *mtmp; 889. { 890. struct obj *otmp, *mwep; 891. xchar x, y; 892. const char *onm; 893. 894. /* Rearranged beginning so monsters can use polearms not in a line */ 895. if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) { 896. mtmp->weapon_check = NEED_RANGED_WEAPON; 897. /* mon_wield_item resets weapon_check as appropriate */ 898. if (mon_wield_item(mtmp) != 0) 899. return; 900. } 901. 902. /* Pick a weapon */ 903. otmp = select_rwep(mtmp); 904. if (!otmp) 905. return; 906. 907. if (is_pole(otmp)) { 908. int dam, hitv; 909. 910. if (otmp != MON_WEP(mtmp)) 911. return; /* polearm must be wielded */ 912. if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) > POLE_LIM 913. || !couldsee(mtmp->mx, mtmp->my)) 914. return; /* Out of range, or intervening wall */ 915. 916. if (canseemon(mtmp)) { 917. onm = xname(otmp); 918. pline("%s thrusts %s.", Monnam(mtmp), 919. obj_is_pname(otmp) ? the(onm) : an(onm)); 920. } 921. 922. dam = dmgval(otmp, &youmonst); 923. hitv = 3 - distmin(u.ux, u.uy, mtmp->mx, mtmp->my); 924. if (hitv < -4) 925. hitv = -4; 926. if (bigmonst(youmonst.data)) 927. hitv++; 928. hitv += 8 + otmp->spe; 929. if (dam < 1) 930. dam = 1; 931. 932. (void) thitu(hitv, dam, &otmp, (char *) 0); 933. stop_occupation(); 934. return; 935. } 936. 937. x = mtmp->mx; 938. y = mtmp->my; 939. /* If you are coming toward the monster, the monster 940. * should try to soften you up with missiles. If you are 941. * going away, you are probably hurt or running. Give 942. * chase, but if you are getting too far away, throw. 943. */ 944. if (!lined_up(mtmp) 945. || (URETREATING(x, y) 946. && rn2(BOLT_LIM - distmin(x, y, mtmp->mux, mtmp->muy)))) 947. return; 948. 949. mwep = MON_WEP(mtmp); /* wielded weapon */ 950. monshoot(mtmp, otmp, mwep); /* multishot shooting or throwing */ 951. nomul(0); 952. } 953. 954. /* monster spits substance at you */ 955. int 956. spitmu(mtmp, mattk) 957. struct monst *mtmp; 958. struct attack *mattk; 959. { 960. struct obj *otmp; 961. 962. if (mtmp->mcan) { 963. if (!Deaf) 964. pline("A dry rattle comes from %s throat.", 965. s_suffix(mon_nam(mtmp))); 966. return 0; 967. } 968. if (lined_up(mtmp)) { 969. switch (mattk->adtyp) { 970. case AD_BLND: 971. case AD_DRST: 972. otmp = mksobj(BLINDING_VENOM, TRUE, FALSE); 973. break; 974. default: 975. impossible("bad attack type in spitmu"); 976. /* fall through */ 977. case AD_ACID: 978. otmp = mksobj(ACID_VENOM, TRUE, FALSE); 979. break; 980. } 981. if (!rn2(BOLT_LIM 982. - distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy))) { 983. if (canseemon(mtmp)) 984. pline("%s spits venom!", Monnam(mtmp)); 985. m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby), 986. distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp); 987. nomul(0); 988. return 0; 989. } else { 990. obj_extract_self(otmp); 991. obfree(otmp, (struct obj *) 0); 992. } 993. } 994. return 0; 995. } 996. 997. /* monster breathes at you (ranged) */ 998. int 999. breamu(mtmp, mattk) 1000. struct monst *mtmp; 1001. struct attack *mattk; 1002. { 1003. /* if new breath types are added, change AD_ACID to max type */ 1004. int typ = (mattk->adtyp == AD_RBRE) ? rnd(AD_ACID) : mattk->adtyp; 1005. 1006. if (lined_up(mtmp)) { 1007. if (mtmp->mcan) { 1008. if (!Deaf) { 1009. if (canseemon(mtmp)) 1010. pline("%s coughs.", Monnam(mtmp)); 1011. else 1012. You_hear("a cough."); 1013. } 1014. return 0; 1015. } 1016. if (!mtmp->mspec_used && rn2(3)) { 1017. if ((typ >= AD_MAGM) && (typ <= AD_ACID)) { 1018. if (canseemon(mtmp)) 1019. pline("%s breathes %s!", Monnam(mtmp), 1020. breathwep[typ - 1]); 1021. buzz((int) (-20 - (typ - 1)), (int) mattk->damn, mtmp->mx, 1022. mtmp->my, sgn(tbx), sgn(tby)); 1023. nomul(0); 1024. /* breath runs out sometimes. Also, give monster some 1025. * cunning; don't breath if the player fell asleep. 1026. */ 1027. if (!rn2(3)) 1028. mtmp->mspec_used = 10 + rn2(20); 1029. if (typ == AD_SLEE && !Sleep_resistance) 1030. mtmp->mspec_used += rnd(20); 1031. } else 1032. impossible("Breath weapon %d used", typ - 1); 1033. } 1034. } 1035. return 1; 1036. } 1037. 1038. boolean 1039. linedup(ax, ay, bx, by, boulderhandling) 1040. register xchar ax, ay, bx, by; 1041. int boulderhandling; /* 0=block, 1=ignore, 2=conditionally block */ 1042. { 1043. int dx, dy, boulderspots; 1044. 1045. /* These two values are set for use after successful return. */ 1046. tbx = ax - bx; 1047. tby = ay - by; 1048. 1049. /* sometimes displacement makes a monster think that you're at its 1050. own location; prevent it from throwing and zapping in that case */ 1051. if (!tbx && !tby) 1052. return FALSE; 1053. 1054. if ((!tbx || !tby || abs(tbx) == abs(tby)) /* straight line or diagonal */ 1055. && distmin(tbx, tby, 0, 0) < BOLT_LIM) { 1056. if ((ax == u.ux && ay == u.uy) ? (boolean) couldsee(bx, by) 1057. : clear_path(ax, ay, bx, by)) 1058. return TRUE; 1059. /* don't have line of sight, but might still be lined up 1060. if that lack of sight is due solely to boulders */ 1061. if (boulderhandling == 0) 1062. return FALSE; 1063. dx = sgn(ax - bx), dy = sgn(ay - by); 1064. boulderspots = 0; 1065. do { 1066. /* <bx,by> is guaranteed to eventually converge with <ax,ay> */ 1067. bx += dx, by += dy; 1068. if (IS_ROCK(levl[bx][by].typ) || closed_door(bx, by)) 1069. return FALSE; 1070. if (sobj_at(BOULDER, bx, by)) 1071. ++boulderspots; 1072. } while (bx != ax || by != ay); 1073. /* reached target position without encountering obstacle */ 1074. if (boulderhandling == 1 || rn2(2 + boulderspots) < 2) 1075. return TRUE; 1076. } 1077. return FALSE; 1078. } 1079. 1080. STATIC_OVL boolean 1081. m_lined_up(mtarg, mtmp) 1082. struct monst *mtarg, *mtmp; 1083. { 1084. return (linedup(mtarg->mx, mtarg->my, mtmp->mx, mtmp->my, 0)); 1085. } 1086. 1087. 1088. /* is mtmp in position to use ranged attack? */ 1089. boolean 1090. lined_up(mtmp) 1091. register struct monst *mtmp; 1092. { 1093. boolean ignore_boulders; 1094. 1095. /* hero concealment usually trumps monst awareness of being lined up */ 1096. if (Upolyd && rn2(25) 1097. && (u.uundetected || (U_AP_TYPE != M_AP_NOTHING 1098. && U_AP_TYPE != M_AP_MONSTER))) 1099. return FALSE; 1100. 1101. ignore_boulders = (throws_rocks(mtmp->data) 1102. || m_carrying(mtmp, WAN_STRIKING)); 1103. return linedup(mtmp->mux, mtmp->muy, mtmp->mx, mtmp->my, 1104. ignore_boulders ? 1 : 2); 1105. } 1106. 1107. /* check if a monster is carrying a particular item */ 1108. struct obj * 1109. m_carrying(mtmp, type) 1110. struct monst *mtmp; 1111. int type; 1112. { 1113. register struct obj *otmp; 1114. 1115. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 1116. if (otmp->otyp == type) 1117. return otmp; 1118. return (struct obj *) 0; 1119. } 1120. 1121. void 1122. hit_bars(objp, objx, objy, barsx, barsy, your_fault, from_invent) 1123. struct obj **objp; /* *objp will be set to NULL if object breaks */ 1124. int objx, objy, barsx, barsy; 1125. boolean your_fault, from_invent; 1126. { 1127. struct obj *otmp = *objp; 1128. int obj_type = otmp->otyp; 1129. boolean unbreakable = (levl[barsx][barsy].wall_info & W_NONDIGGABLE) != 0; 1130. 1131. if (your_fault 1132. ? hero_breaks(otmp, objx, objy, from_invent) 1133. : breaks(otmp, objx, objy)) { 1134. *objp = 0; /* object is now gone */ 1135. /* breakage makes its own noises */ 1136. if (obj_type == POT_ACID) { 1137. if (cansee(barsx, barsy) && !unbreakable) 1138. pline_The("iron bars are dissolved!"); 1139. else 1140. You_hear(Hallucination ? "angry snakes!" : "a hissing noise."); 1141. if (!unbreakable) 1142. dissolve_bars(barsx, barsy); 1143. } 1144. } 1145. else if (obj_type == BOULDER || obj_type == HEAVY_IRON_BALL) 1146. pline("Whang!"); 1147. else if (otmp->oclass == COIN_CLASS 1148. || objects[obj_type].oc_material == GOLD 1149. || objects[obj_type].oc_material == SILVER) 1150. pline("Clink!"); 1151. else 1152. pline("Clonk!"); 1153. } 1154. 1155. /* TRUE iff thrown/kicked/rolled object doesn't pass through iron bars */ 1156. boolean 1157. hits_bars(obj_p, x, y, barsx, barsy, always_hit, whodidit) 1158. struct obj **obj_p; /* *obj_p will be set to NULL if object breaks */ 1159. int x, y, barsx, barsy; 1160. int always_hit; /* caller can force a hit for items which would fit through */ 1161. int whodidit; /* 1==hero, 0=other, -1==just check whether it'll pass thru */ 1162. { 1163. struct obj *otmp = *obj_p; 1164. int obj_type = otmp->otyp; 1165. boolean hits = always_hit; 1166. 1167. if (!hits) 1168. switch (otmp->oclass) { 1169. case WEAPON_CLASS: { 1170. int oskill = objects[obj_type].oc_skill; 1171. 1172. hits = (oskill != -P_BOW && oskill != -P_CROSSBOW 1173. && oskill != -P_DART && oskill != -P_SHURIKEN 1174. && oskill != P_SPEAR 1175. && oskill != P_KNIFE); /* but not dagger */ 1176. break; 1177. } 1178. case ARMOR_CLASS: 1179. hits = (objects[obj_type].oc_armcat != ARM_GLOVES); 1180. break; 1181. case TOOL_CLASS: 1182. hits = (obj_type != SKELETON_KEY && obj_type != LOCK_PICK 1183. && obj_type != CREDIT_CARD && obj_type != TALLOW_CANDLE 1184. && obj_type != WAX_CANDLE && obj_type != LENSES 1185. && obj_type != TIN_WHISTLE && obj_type != MAGIC_WHISTLE); 1186. break; 1187. case ROCK_CLASS: /* includes boulder */ 1188. if (obj_type != STATUE || mons[otmp->corpsenm].msize > MZ_TINY) 1189. hits = TRUE; 1190. break; 1191. case FOOD_CLASS: 1192. if (obj_type == CORPSE && mons[otmp->corpsenm].msize > MZ_TINY) 1193. hits = TRUE; 1194. else 1195. hits = (obj_type == MEAT_STICK 1196. || obj_type == HUGE_CHUNK_OF_MEAT); 1197. break; 1198. case SPBOOK_CLASS: 1199. case WAND_CLASS: 1200. case BALL_CLASS: 1201. case CHAIN_CLASS: 1202. hits = TRUE; 1203. break; 1204. default: 1205. break; 1206. } 1207. 1208. if (hits && whodidit != -1) { 1209. hit_bars(obj_p, x,y, barsx,barsy, whodidit, FALSE); 1210. } 1211. 1212. return hits; 1213. } 1214. 1215. /*mthrowu.c*/