Source:NetHack 3.0.0/mondata.c
Jump to navigation
Jump to search
Below is the full text to mondata.c from the source code of NetHack 3.0.0. To link to a particular line, write [[NetHack 3.0.0/mondata.c#line123]], for example.
Warning! This is the source code from an old release. For the latest release, see Source code
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. /* SCCS Id: @(#)mondata.c 3.0 89/01/10 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #include "hack.h" 6. #include "eshk.h" 7. #include "epri.h" 8. 9. /* These routines provide basic data for any type of monster. */ 10. 11. boolean 12. attacktype(ptr, atyp) 13. register struct permonst *ptr; 14. register int atyp; 15. { 16. int i; 17. 18. for(i = 0; i < NATTK; i++) 19. if(ptr->mattk[i].aatyp == atyp) return(TRUE); 20. 21. return(FALSE); 22. } 23. 24. boolean 25. resists_ston(ptr) /* returns TRUE if monster is petrify resistant */ 26. register struct permonst *ptr; 27. { 28. return (ptr->mflags1 & M1_STON_RES || dmgtype(ptr, AD_STON) || 29. dmgtype(ptr, AD_ACID)); 30. } 31. 32. boolean 33. resists_drli(ptr) /* returns TRUE if monster is drain-life resistant */ 34. 35. register struct permonst *ptr; 36. { 37. return(is_undead(ptr) || is_demon(ptr) || is_were(ptr)); 38. } 39. 40. boolean 41. ranged_attk(ptr) /* returns TRUE if monster can attack at range */ 42. register struct permonst *ptr; 43. { 44. return (attacktype(ptr, AT_BREA) || attacktype(ptr, AT_WEAP) || 45. attacktype(ptr, AT_SPIT) || attacktype(ptr, AT_GAZE) || 46. attacktype(ptr, AT_MAGC)); 47. } 48. 49. boolean 50. can_track(ptr) /* returns TRUE if monster can track well */ 51. register struct permonst *ptr; 52. { 53. #ifdef NAMED_ITEMS 54. if(uwep && !strcmp(ONAME(uwep), "Excalibur")) return TRUE; 55. #endif 56. return(haseyes(ptr)); 57. } 58. 59. #ifdef POLYSELF 60. boolean 61. breakarm(ptr) /* creature will break out of armor */ 62. register struct permonst *ptr; 63. { 64. return(bigmonst(ptr) || (!verysmall(ptr) && !humanoid(ptr)) 65. #ifdef HARD 66. || ptr == &mons[PM_MARILITH] 67. #endif 68. ); 69. /* Marilith is about the only case of a monster which is otherwise 70. * humanoid but cannot wear armor (too many arms). Centaurs would 71. * be another except that they are already accounted for by 72. * bigmonst. 73. */ 74. } 75. 76. boolean 77. sliparm(ptr) /* creature will slide out of armor */ 78. register struct permonst *ptr; 79. { 80. return(!bigmonst(ptr) && (verysmall(ptr) || ptr == &mons[PM_GHOST])); 81. } 82. #endif 83. 84. boolean 85. sticks(ptr) /* creature sticks other creatures it hits */ 86. register struct permonst *ptr; 87. { 88. return(dmgtype(ptr,AD_STCK) || dmgtype(ptr,AD_WRAP) || 89. attacktype(ptr,AT_HUGS)); 90. } 91. 92. /* not one hundred percent correct: now a snake may hide under an 93. * invisible object. 94. */ 95. boolean 96. canseemon(mtmp) 97. register struct monst *mtmp; 98. { 99. return((!mtmp->minvis || See_invisible) 100. && (!mtmp->mhide || 101. (levl[mtmp->mx][mtmp->my].omask == 0 && 102. levl[mtmp->mx][mtmp->my].gmask == 0)) 103. && cansee(mtmp->mx, mtmp->my)); 104. } 105. 106. boolean 107. dmgtype(ptr, dtyp) 108. register struct permonst *ptr; 109. register int dtyp; 110. { 111. int i; 112. 113. for(i = 0; i < NATTK; i++) 114. if(ptr->mattk[i].adtyp == dtyp) return TRUE; 115. 116. return FALSE; 117. } 118. 119. int 120. monsndx(ptr) /* return an index into the mons array */ 121. struct permonst *ptr; 122. { 123. register int i; 124. register struct permonst *mdat; 125. 126. if(ptr == &playermon) return(-1); 127. 128. for(i = 0, mdat = &mons[0]; mdat->mlet; i++) 129. if(ptr == mdat++) return(i); 130. 131. panic("monsndx - could not index monster (%x)", ptr); 132. return FALSE; /* will not get here */ 133. } 134. 135. int 136. name_to_mon(str) 137. char *str; 138. { 139. /* Be careful. We must check the entire string in case it was 140. * something such as "ettin zombie corpse". The calling routine 141. * doesn't know about the "corpse" until the monster name has 142. * already been taken off the front, so we have to be able to 143. * read the name with extraneous stuff such as "corpse" stuck on 144. * the end. 145. * This causes a problem for names which prefix other names such 146. * as "ettin" on "ettin zombie". In this case we want the _longest_ 147. * name which exists. 148. * This also permits plurals created by adding suffixes such as 's' 149. * or 'es'. Other plurals must still be handled explicitly. 150. */ 151. register int i; 152. register int mntmp = -1; 153. register char *s; 154. char buf[BUFSZ]; 155. int len=0; 156. 157. Strcpy(buf, str); 158. str = buf; 159. if (!strncmp(str, "a ", 2)) str += 2; 160. else if (!strncmp(str, "an ", 3)) str += 3; 161. 162. /* Some irregular plurals */ 163. #ifdef HARD 164. if (!strncmp(str, "incubi", 6)) return PM_INCUBUS; 165. if (!strncmp(str, "succubi", 7)) return PM_SUCCUBUS; 166. #endif 167. if (!strncmp(str, "violet fungi", 12)) return PM_VIOLET_FUNGUS; 168. if (!strncmp(str, "homunculi", 9)) return PM_HOMUNCULUS; 169. if (!strncmp(str, "baluchitheria", 13)) return PM_BALUCHITHERIUM; 170. if (!strncmp(str, "lurkers above", 13)) return PM_LURKER_ABOVE; 171. if (!strncmp(str, "cavemen", 7)) return PM_CAVEMAN; 172. if (!strncmp(str, "cavewomen", 9)) return PM_CAVEWOMAN; 173. if (!strncmp(str, "zruties", 7)) return PM_ZRUTY; 174. if (!strncmp(str, "djinn", 5)) return PM_DJINNI; 175. /* be careful with "ies"; "priest", "zombies" */ 176. for(s=str; *s; s++) { 177. if (!strncmp(s, "vortices", 8)) { 178. Strcpy(s+4, "ex"); 179. break; 180. } 181. if (!strncmp(s, "jellies", 7) || !strncmp(s, "mummies", 7)) { 182. Strcpy(s+4, "y"); 183. break; 184. } 185. if (!strncmp(s, "ves", 3)) { 186. /* luckily no monster names end in fe or ve with ves plurals */ 187. Strcpy(s, "f"); 188. break; 189. } 190. } 191. 192. for(i = 0; mons[i].mlet; i++) { 193. if(!strncmp(mons[i].mname, str, strlen(mons[i].mname))) { 194. if (strlen(mons[i].mname) > len) { 195. mntmp = i; 196. len = strlen(mons[i].mname); 197. } 198. } 199. } 200. return mntmp; 201. } 202. 203. #ifdef POLYSELF 204. boolean 205. webmaker(ptr) /* creature can spin a web */ 206. register struct permonst *ptr; 207. { 208. return (ptr->mlet == S_SPIDER && ptr != &mons[PM_SCORPION]); 209. } 210. #endif 211. 212. boolean 213. is_female(mtmp) 214. register struct monst *mtmp; 215. { 216. if (mtmp->isshk) return !ESHK(mtmp)->ismale; 217. #if defined(ALTARS) && defined(THEOLOGY) 218. if (mtmp->ispriest) return !EPRI(mtmp)->ismale; 219. #endif 220. return !!(mtmp->data->mflags1 & M1_FEM); 221. } 222. 223. /* Gender function. Differs from is_female() in that 1) It allows the monster 224. * type of a polymorphed shopkeeper to override ESHK(mtmp)->ismale, and 2) 225. * it returns 3 values (0=male, 1=female, 2=none) instead of 2. 226. */ 227. int 228. gender(mtmp) 229. register struct monst *mtmp; 230. { 231. if (!humanoid(mtmp->data)) return 2; 232. if (mtmp->data->mflags1 & M1_FEM) return 1; 233. if (mtmp->data == &mons[PM_CAVEMAN] 234. || mtmp->data == &mons[PM_PRIEST] 235. #ifdef HARD 236. || mtmp->data == &mons[PM_INCUBUS] 237. #endif 238. ) return 0; 239. #if defined(ALTARS) && defined(THEOLOGY) 240. if (mtmp->ispriest) return !EPRI(mtmp)->ismale; 241. #endif 242. if (mtmp->isshk) return !ESHK(mtmp)->ismale; 243. return 0; 244. } 245. 246. boolean 247. levl_follower(mtmp) 248. register struct monst *mtmp; 249. { 250. return (mtmp->mtame || (mtmp->data->mflags1 & M1_STALK) || is_fshk(mtmp) 251. || (mtmp->iswiz && !mon_has_amulet(mtmp))); 252. } 253. 254. struct permonst * 255. player_mon() 256. { 257. switch (pl_character[0]) { 258. case 'A': return &mons[PM_ARCHEOLOGIST]; 259. case 'B': return &mons[PM_BARBARIAN]; 260. case 'C': if (flags.female) return &mons[PM_CAVEWOMAN]; 261. else return &mons[PM_CAVEMAN]; 262. case 'E': return &mons[PM_ELF]; 263. case 'H': return &mons[PM_HEALER]; 264. case 'K': return &mons[PM_KNIGHT]; 265. case 'P': if (flags.female) return &mons[PM_PRIESTESS]; 266. else return &mons[PM_PRIEST]; 267. case 'R': return &mons[PM_ROGUE]; 268. case 'S': return &mons[PM_SAMURAI]; 269. case 'T': return &mons[PM_TOURIST]; 270. case 'V': return &mons[PM_VALKYRIE]; 271. case 'W': return &mons[PM_WIZARD]; 272. default: impossible("what are you?"); 273. return &mons[PM_HUMAN]; 274. } 275. } 276. 277. const int grownups[][2] = { {PM_LITTLE_DOG, PM_DOG}, {PM_DOG, PM_LARGE_DOG}, 278. {PM_HELL_HOUND_PUP, PM_HELL_HOUND}, {PM_KITTEN, PM_HOUSECAT}, 279. {PM_HOUSECAT, PM_LARGE_CAT}, {PM_BABY_GREY_DRAGON, PM_GREY_DRAGON}, 280. {PM_BABY_RED_DRAGON, PM_RED_DRAGON}, 281. {PM_BABY_WHITE_DRAGON, PM_WHITE_DRAGON}, 282. {PM_BABY_BLUE_DRAGON, PM_BLUE_DRAGON}, 283. {PM_BABY_GREEN_DRAGON, PM_GREEN_DRAGON}, 284. {PM_BABY_ORANGE_DRAGON, PM_ORANGE_DRAGON}, 285. {PM_BABY_BLACK_DRAGON, PM_BLACK_DRAGON}, 286. {PM_BABY_YELLOW_DRAGON, PM_YELLOW_DRAGON}, 287. {PM_RED_NAGA_HATCHLING, PM_RED_NAGA}, 288. {PM_BLACK_NAGA_HATCHLING, PM_BLACK_NAGA}, 289. {PM_GOLDEN_NAGA_HATCHLING, PM_GOLDEN_NAGA}, 290. {PM_GUARDIAN_NAGA_HATCHLING, PM_GUARDIAN_NAGA}, 291. {PM_BABY_PURPLE_WORM, PM_PURPLE_WORM}, 292. #ifdef WORM 293. {PM_BABY_LONG_WORM, PM_LONG_WORM}, 294. #endif 295. #ifdef ARMY 296. {PM_SOLDIER, PM_SERGEANT}, 297. {PM_SERGEANT, PM_LIEUTENANT}, 298. {PM_LIEUTENANT, PM_CAPTAIN}, 299. #endif 300. {-1,-1} 301. }; 302. 303. int little_to_big(montype) 304. int montype; 305. { 306. register int *i; 307. 308. for(i=grownups[0]; *i >= 0; i++) 309. if(montype == *i) return *(i+1); 310. return montype; 311. } 312. 313. int big_to_little(montype) 314. int montype; 315. { 316. register int *i; 317. 318. for(i=grownups[0]; *i >= 0; i++) 319. if(montype == *(i+1)) return *i; 320. return montype; 321. } 322. 323. 324. #ifdef STUPID_CPP /* otherwise these functions are macros in mondata.h */ 325. 326. int 327. bigmonst(ptr) struct permonst *ptr; { 328. return((ptr->mflags1 & M1_BIG) != 0L); 329. } 330. 331. int 332. verysmall(ptr) struct permonst *ptr; { 333. return((ptr->mflags1 & M1_VSMALL) != 0L); 334. } 335. 336. int 337. is_flyer(ptr) struct permonst *ptr; { 338. return((ptr->mflags1 & M1_FLY) != 0L); 339. } 340. 341. int 342. is_floater(ptr) struct permonst *ptr; { 343. return(ptr->mlet == S_EYE); 344. } 345. 346. int 347. is_swimmer(ptr) struct permonst *ptr; { 348. return((ptr->mflags1 & M1_SWIM) != 0L); 349. } 350. 351. int 352. passes_walls(ptr) struct permonst *ptr; { 353. return((ptr->mflags1 & M1_WALLWALK) != 0L); 354. } 355. 356. int 357. noncorporeal(ptr) struct permonst *ptr; { 358. return(ptr->mlet == S_GHOST); 359. } 360. 361. int 362. is_animal(ptr) struct permonst *ptr; { 363. return((ptr->mflags1 & M1_ANIMAL) != 0L); 364. } 365. 366. int 367. humanoid(ptr) struct permonst *ptr; { 368. return((ptr->mflags1 & M1_HUMANOID) != 0L); 369. } 370. 371. int 372. is_undead(ptr) struct permonst *ptr; { 373. return((ptr->mflags1 & M1_UNDEAD) != 0L); 374. } 375. 376. int 377. is_were(ptr) struct permonst *ptr; { 378. return((ptr->mflags1 & M1_WERE) != 0L); 379. } 380. 381. int haseyes(ptr) struct permonst *ptr; { 382. return((ptr->mflags1 & M1_NOEYES) == 0L); 383. } 384. 385. int 386. nohands(ptr) struct permonst *ptr; { 387. return((ptr->mflags1 & M1_NOHANDS) != 0L); 388. } 389. 390. int 391. lays_eggs(ptr) struct permonst *ptr; { 392. return((ptr->mflags1 & M1_EGGS) != 0L); 393. } 394. 395. int 396. poisonous(ptr) struct permonst *ptr; { 397. return((ptr->mflags1 & M1_POIS) != 0L); 398. } 399. 400. int 401. resists_poison(ptr) struct permonst *ptr; { 402. return((ptr->mflags1 & (M1_POIS | M1_POIS_RES)) != 0L); 403. } 404. 405. int 406. resists_fire(ptr) struct permonst *ptr; { 407. return((ptr->mflags1 & M1_FIRE_RES) != 0L); 408. } 409. 410. int 411. resists_cold(ptr) struct permonst *ptr; { 412. return((ptr->mflags1 & M1_COLD_RES) != 0L); 413. } 414. 415. int 416. resists_acid(ptr) struct permonst *ptr; { 417. return(dmgtype(ptr, AD_ACID)); 418. } 419. 420. int 421. resists_elec(ptr) struct permonst *ptr; { 422. return((ptr->mflags1 & M1_ELEC_RES) != 0L); 423. } 424. 425. int 426. resists_sleep(ptr) struct permonst *ptr; { 427. return((ptr->mflags1 & (M1_SLEE_RES | M1_UNDEAD)) != 0L); 428. } 429. 430. int 431. resists_disint(ptr) struct permonst *ptr; { 432. return(ptr == &mons[PM_BLACK_DRAGON] || 433. ptr == &mons[PM_BABY_BLACK_DRAGON]); 434. } 435. 436. int 437. regenerates(ptr) struct permonst *ptr; { 438. return((ptr->mflags1 & M1_REGEN) != 0L); 439. } 440. 441. int 442. perceives(ptr) struct permonst *ptr; { 443. return((ptr->mflags1 & M1_SEE_INVIS) != 0L); 444. } 445. 446. int 447. can_teleport(ptr) struct permonst *ptr; { 448. return((ptr->mflags1 & M1_TPORT) != 0L); 449. } 450. 451. int 452. control_teleport(ptr) struct permonst *ptr; { 453. return((ptr->mflags1 & M1_TPORT_CONTROL) != 0L); 454. } 455. 456. int 457. is_armed(ptr) struct permonst *ptr; { 458. return(attacktype(ptr, AT_WEAP)); 459. } 460. 461. int 462. likes_gold(ptr) struct permonst *ptr; { 463. return((ptr->mflags1 & M1_GREEDY) != 0L); 464. } 465. 466. int 467. likes_gems(ptr) struct permonst *ptr; { 468. return((ptr->mflags1 & M1_JEWELS) != 0L); 469. } 470. 471. int 472. likes_objs(ptr) struct permonst *ptr; { 473. return((ptr->mflags1 & M1_COLLECT) != 0L || is_armed(ptr)); 474. } 475. 476. int 477. likes_magic(ptr) struct permonst *ptr; { 478. return((ptr->mflags1 & M1_MAGIC) != 0L); 479. } 480. 481. int 482. hides_under(ptr) struct permonst *ptr; { 483. return((ptr->mflags2 & M2_CONCEAL) != 0L); 484. } 485. 486. int 487. is_hider(ptr) struct permonst *ptr; { 488. return((ptr->mflags2 & M2_HIDE) != 0L); 489. } 490. 491. # ifdef POLYSELF 492. int 493. polyok(ptr) struct permonst *ptr; { 494. return((ptr->mflags1 & M1_NOPOLY) == 0L); 495. } 496. # endif /* POLYSELF */ 497. 498. int 499. tunnels(ptr) struct permonst *ptr; { 500. return((ptr->mflags2 & M2_TUNNEL) != 0L); 501. } 502. 503. int 504. needspick(ptr) struct permonst *ptr; { 505. return((ptr->mflags2 & M2_NEEDPICK) != 0L); 506. } 507. 508. int 509. is_elf(ptr) struct permonst *ptr; { 510. return((ptr->mflags2 & M2_ELF) != 0L); 511. } 512. 513. int 514. is_dwarf(ptr) struct permonst *ptr; { 515. return((ptr->mflags2 & M2_DWARF) != 0L); 516. } 517. 518. int 519. is_giant(ptr) struct permonst *ptr; { 520. return((ptr->mflags2 & M2_GIANT) != 0L); 521. } 522. 523. # ifdef GOLEMS 524. int 525. is_golem(ptr) struct permonst *ptr; { 526. return(ptr->mlet == S_GOLEM); 527. } 528. # endif /* GOLEMS */ 529. 530. int 531. is_orc(ptr) struct permonst *ptr; { 532. return((ptr->mflags2 & M2_ORC) != 0L); 533. } 534. 535. int 536. is_human(ptr) struct permonst *ptr; { 537. return((ptr->mflags2 & M2_HUMAN) != 0L); 538. } 539. 540. int 541. is_demon(ptr) struct permonst *ptr; { 542. return((ptr->mflags2 & M2_DEMON) != 0L); 543. } 544. 545. int 546. is_mercenary(ptr) struct permonst *ptr; { 547. return((ptr->mflags2 & M2_MERC) != 0L); 548. } 549. 550. int 551. throws_rocks(ptr) struct permonst *ptr; { 552. return((ptr->mflags2 & M2_ROCKTHROW) != 0L); 553. } 554. 555. int 556. is_wanderer(ptr) struct permonst *ptr; { 557. return((ptr->mflags2 & M2_WANDER) != 0L); 558. } 559. 560. int 561. is_lord(ptr) struct permonst *ptr; { 562. return((ptr->mflags1 & M1_LORD) != 0L); 563. } 564. 565. int 566. is_prince(ptr) struct permonst *ptr; { 567. return((ptr->mflags1 & M1_PRINCE) != 0L); 568. } 569. 570. # ifdef HARD 571. int 572. is_ndemon(ptr) struct permonst *ptr; { 573. return(is_demon(ptr) && 574. (ptr->mflags1 & (M1_LORD | M1_PRINCE)) == 0L); 575. } 576. # else /* HARD */ 577. int 578. is_ndemon(ptr) struct permonst *ptr; { 579. return(ptr == &mons[PM_DEMON]); 580. } 581. # endif /* HARD */ 582. 583. int 584. is_dlord(ptr) struct permonst *ptr; { 585. return(is_demon(ptr) && is_lord(ptr)); 586. } 587. 588. int 589. is_dprince(ptr) struct permonst *ptr; { 590. return(is_demon(ptr) && is_prince(ptr)); 591. } 592. 593. int 594. type_is_pname(ptr) struct permonst *ptr; { 595. return((ptr->mflags2 & M2_PNAME) != 0L); 596. } 597. 598. int 599. always_hostile(ptr) struct permonst *ptr; { 600. return((ptr->mflags2 & M2_HOSTILE) != 0L); 601. } 602. 603. int 604. always_peaceful(ptr) struct permonst *ptr; { 605. return((ptr->mflags2 & M2_PEACEFUL) != 0L); 606. } 607. 608. int 609. strongmonst(ptr) struct permonst *ptr; { 610. return((ptr->mflags2 & M2_STRONG) != 0L); 611. } 612. 613. int 614. extra_nasty(ptr) struct permonst *ptr; { 615. return((ptr->mflags2 & M2_NASTY) != 0L); 616. } 617. 618. # ifdef POLYSELF 619. int 620. can_breathe(ptr) struct permonst *ptr; { 621. return(attacktype(ptr, AT_BREA)); 622. } 623. 624. int 625. cantwield(ptr) struct permonst *ptr; { 626. return(nohands(ptr) || verysmall(ptr)); 627. } 628. 629. int 630. cantweararm(ptr) struct permonst *ptr; { 631. return(breakarm(ptr) || sliparm(ptr)); 632. } 633. 634. int 635. nolimbs(ptr) struct permonst *ptr; { 636. return((ptr->mflags2 & M2_NOLIMBS) != 0L); 637. } 638. # endif /* POLYSELF */ 639. 640. int 641. carnivorous(ptr) struct permonst *ptr; { 642. return((ptr->mflags2 & M2_CARNIVORE) != 0L); 643. } 644. 645. int 646. herbivorous(ptr) struct permonst *ptr; { 647. return((ptr->mflags2 & M2_HERBIVORE) != 0L); 648. } 649. 650. int 651. thick_skinned(ptr) struct permonst *ptr; { 652. return((ptr->mflags2 & M2_THICK_HIDE) != 0L); 653. } 654. 655. int 656. amorphous(ptr) struct permonst *ptr; { 657. return((ptr->mflags2 & M2_AMORPHOUS) != 0L); 658. } 659. 660. #endif /* STUPID_CPP */