abstract
| - Below is the full text to apply.c from the source code of NetHack 2.2a. To link to a particular line, write [[NetHack 2.2a/apply.c#line123]], for example. Warning! This is the source code from an old release. For the latest release, see Source code 1. /* SCCS Id: @(#)apply.c 2.1 87/09/23 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. 4. #include "hack.h" 5. #include "edog.h" 6. #include "mkroom.h" 7. static struct monst *bchit(); 8. extern struct obj *addinv(); 9. extern struct trap *maketrap(); 10. extern int (*occupation)(); 11. extern char *occtxt; 12. extern char quitchars[]; 13. extern char pl_character[]; 14. 15. #ifdef KAA 16. extern boolean unweapon; 17. #endif 18. static use_camera(), use_ice_box(), use_whistle(); 19. static use_magic_whistle(), use_pick_axe(); 20. #ifdef MARKER 21. extern int dowrite(); 22. #endif 23. #ifdef RPH 24. static use_mirror(); 25. #endif 26. 27. doapply() { 28. register struct obj *obj; 29. register int res = 1; 30. 31. obj = getobj("(", "use or apply"); 32. if(!obj) return(0); 33. 34. switch(obj->otyp){ 35. case EXPENSIVE_CAMERA: 36. use_camera(obj); break; 37. case ICE_BOX: 38. use_ice_box(obj); break; 39. case PICK_AXE: 40. res = use_pick_axe(obj); 41. break; 42. 43. case MAGIC_WHISTLE: 44. if(pl_character[0] == 'W' || u.ulevel > 9) { 45. use_magic_whistle(obj); 46. break; 47. } 48. /* fall into next case */ 49. case WHISTLE: 50. use_whistle(obj); 51. break; 52. #ifdef RPH 53. case MIRROR: 54. use_mirror(obj); 55. break; 56. #endif 57. #ifdef WALKIES 58. case LEASH: 59. use_leash(obj); 60. break; 61. #endif 62. #ifdef MARKER 63. case MAGIC_MARKER: 64. dowrite(obj); 65. break; 66. #endif 67. case CAN_OPENER: 68. if(!carrying(TIN)) { 69. pline("You have no can to open."); 70. goto xit; 71. } 72. pline("You cannot open a tin without eating its contents."); 73. pline("In order to eat, use the 'e' command."); 74. if(obj != uwep) 75. pline("Opening the tin will be much easier if you wield the can-opener."); 76. goto xit; 77. 78. #ifdef KAA 79. case STETHOSCOPE: 80. res = use_stethoscope(); 81. break; 82. #endif 83. case BLINDFOLD: 84. if (Blindfolded) { 85. Blindfolded = 0; 86. if (!Blinded) Blinded = 1; /* see on next move */ 87. else pline("You still cannot see."); 88. } else { 89. Blindfolded = 1; 90. seeoff(0); 91. } 92. break; 93. default: 94. pline("Sorry, I don't know how to use that."); 95. xit: 96. nomul(0); 97. return(0); 98. } 99. nomul(0); 100. return(res); 101. } 102. 103. /* ARGSUSED */ 104. static 105. use_camera(obj) /* register */ struct obj *obj; { 106. register struct monst *mtmp; 107. if(!getdir(1)){ /* ask: in what direction? */ 108. flags.move = multi = 0; 109. return; 110. } 111. if(u.uswallow) { 112. pline("You take a picture of %s's stomach.", monnam(u.ustuck)); 113. return; 114. } 115. if(u.dz) { 116. pline("You take a picture of the %s.", 117. (u.dz > 0) ? "floor" : "ceiling"); 118. return; 119. } 120. #ifdef KAA 121. if(!u.dx && !u.dy && !u.dz) { 122. if(!Blind) { 123. pline("You are blinded by the flash!"); 124. Blinded += rnd(25); 125. seeoff(0); 126. } 127. return; 128. } 129. #endif 130. if(mtmp = bchit(u.dx, u.dy, COLNO, '!')) { 131. if(mtmp->msleep){ 132. mtmp->msleep = 0; 133. pline("The flash awakens %s.", monnam(mtmp)); /* a3 */ 134. } else 135. if(mtmp->data->mlet != 'y') 136. if(mtmp->mcansee || mtmp->mblinded){ 137. register int tmp = dist(mtmp->mx,mtmp->my); 138. register int tmp2; 139. if(cansee(mtmp->mx,mtmp->my)) 140. pline("%s is blinded by the flash!", Monnam(mtmp)); 141. setmangry(mtmp); 142. if(tmp < 9 && !mtmp->isshk && rn2(4)) { 143. mtmp->mflee = 1; 144. if(rn2(4)) mtmp->mfleetim = rnd(100); 145. } 146. if(tmp < 3) mtmp->mcansee = mtmp->mblinded = 0; 147. else { 148. tmp2 = mtmp->mblinded; 149. tmp2 += rnd(1 + 50/tmp); 150. if(tmp2 > 127) tmp2 = 127; 151. mtmp->mblinded = tmp2; 152. mtmp->mcansee = 0; 153. } 154. } 155. } 156. } 157. 158. #ifdef KAA 159. /* Strictly speaking it makes no sense for usage of a stethoscope to 160. not take any time; however, unless it did, the stethoscope would be 161. almost useless. */ 162. static use_stethoscope() { 163. register struct monst *mtmp; 164. register struct rm *lev; 165. register int rx, ry; 166. if(!freehand()) { 167. pline("You have no free hand!"); 168. return(1); 169. } 170. if (!getdir(1)) { 171. flags.move=multi=0; 172. return(0); 173. } 174. if(u.dz < 0 || (u.dz && Levitation)) { 175. pline("You can't reach the %s!", u.dz<0 ? "ceiling" : "floor"); 176. return(1); 177. } 178. if(u.dz) { 179. pline("The floor seems healthy enough."); 180. return(0); 181. } 182. if (Confusion) confdir(); 183. rx = u.ux + u.dx; ry = u.uy + u.dy; 184. if(u.uswallow) { 185. mstatusline(u.ustuck); 186. return(0); 187. } 188. if(mtmp=m_at(rx,ry)) { 189. mstatusline(mtmp); 190. return(0); 191. } 192. if (!isok(rx,ry)) { 193. pline("You hear the sounds at the end of the universe."); 194. return(0); 195. } 196. lev = &levl[rx][ry]; 197. if(lev->typ == SDOOR) { 198. pline("You hear a hollow sound! This must be a secret door!"); 199. lev->typ = DOOR; 200. atl(rx, ry, DOOR_SYM); 201. return(0); 202. } 203. if(lev->typ == SCORR) { 204. pline("You hear a hollow sound! This must be a secret passage!"); 205. lev->typ = CORR; 206. atl(rx, ry, CORR_SYM); 207. return(0); 208. } 209. pline("You hear nothing special."); 210. return(0); 211. } 212. #endif 213. 214. static 215. struct obj *current_ice_box; /* a local variable of use_ice_box, to be 216. used by its local procedures in/ck_ice_box */ 217. static 218. in_ice_box(obj) register struct obj *obj; { 219. if(obj == current_ice_box || 220. (Punished && (obj == uball || obj == uchain))){ 221. pline("You must be kidding."); 222. return(0); 223. } 224. if(obj->owornmask & (W_ARMOR | W_RING)) { 225. pline("You cannot refrigerate something you are wearing."); 226. return(0); 227. } 228. if(obj->owt + current_ice_box->owt > 70) { 229. pline("It won't fit."); 230. return(1); /* be careful! */ 231. } 232. if(obj == uwep) { 233. if(uwep->cursed) { 234. pline("Your weapon is welded to your hand!"); 235. return(0); 236. } 237. setuwep((struct obj *) 0); 238. } 239. current_ice_box->owt += obj->owt; 240. freeinv(obj); 241. obj->o_cnt_id = current_ice_box->o_id; 242. obj->nobj = fcobj; 243. fcobj = obj; 244. obj->age = moves - obj->age; /* actual age */ 245. return(1); 246. } 247. 248. static 249. ck_ice_box(obj) register struct obj *obj; { 250. return(obj->o_cnt_id == current_ice_box->o_id); 251. } 252. 253. static 254. out_ice_box(obj) register struct obj *obj; { 255. register struct obj *otmp; 256. if(obj == fcobj) fcobj = fcobj->nobj; 257. else { 258. for(otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj) 259. if(!otmp->nobj) panic("out_ice_box"); 260. otmp->nobj = obj->nobj; 261. } 262. current_ice_box->owt -= obj->owt; 263. obj->age = moves - obj->age; /* simulated point of time */ 264. (void) addinv(obj); 265. } 266. 267. static 268. use_ice_box(obj) register struct obj *obj; { 269. register int cnt = 0; 270. register struct obj *otmp; 271. current_ice_box = obj; /* for use by in/out_ice_box */ 272. for(otmp = fcobj; otmp; otmp = otmp->nobj) 273. if(otmp->o_cnt_id == obj->o_id) 274. cnt++; 275. if(!cnt) pline("Your ice-box is empty."); 276. else { 277. pline("Do you want to take something out of the ice-box? [yn] "); 278. if(readchar() == 'y') 279. if(askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0)) 280. return; 281. pline("That was all. Do you wish to put something in? [yn] "); 282. if(readchar() != 'y') return; 283. } 284. /* call getobj: 0: allow cnt; #: allow all types; %: expect food */ 285. otmp = getobj("0#%", "put in"); 286. if(!otmp || !in_ice_box(otmp)) 287. flags.move = multi = 0; 288. } 289. 290. static 291. struct monst * 292. bchit(ddx,ddy,range,sym) register int ddx,ddy,range; char sym; { 293. register struct monst *mtmp = (struct monst *) 0; 294. register int bchx = u.ux, bchy = u.uy; 295. 296. if(sym) Tmp_at(-1, sym); /* open call */ 297. while(range--) { 298. bchx += ddx; 299. bchy += ddy; 300. if(mtmp = m_at(bchx,bchy)) 301. break; 302. if(!ZAP_POS(levl[bchx][bchy].typ)) { 303. bchx -= ddx; 304. bchy -= ddy; 305. break; 306. } 307. if(sym) Tmp_at(bchx, bchy); 308. } 309. if(sym) Tmp_at(-1, -1); 310. return(mtmp); 311. } 312. 313. /* ARGSUSED */ 314. static 315. use_whistle(obj) struct obj *obj; { 316. register struct monst *mtmp = fmon; 317. pline("You produce a high whistling sound."); 318. while(mtmp) { 319. if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) { 320. if(mtmp->msleep) 321. mtmp->msleep = 0; 322. if(mtmp->mtame) 323. EDOG(mtmp)->whistletime = moves; 324. } 325. mtmp = mtmp->nmon; 326. } 327. } 328. 329. /* ARGSUSED */ 330. static 331. use_magic_whistle(obj) struct obj *obj; { 332. register struct monst *mtmp = fmon; 333. pline("You produce a strange whistling sound."); 334. while(mtmp) { 335. if(mtmp->mtame) mnexto(mtmp); 336. mtmp = mtmp->nmon; 337. } 338. } 339. 340. #ifdef WALKIES 341. /* ARGSUSED */ 342. static 343. use_leash(obj) struct obj *obj; { 344. register struct monst *mtmp = fmon; 345. 346. while(mtmp && !mtmp->mleashed) mtmp = mtmp->nmon; 347. 348. if(mtmp) { 349. 350. if (next_to(mtmp)) { 351. 352. mtmp->mleashed = 0; 353. pline("You remove the leash from your %s.", 354. #ifdef RPH 355. /* a hack to include the dogs full name. +4 elminates */ 356. /* the 'the' at the start of the name */ 357. lmonnam(mtmp) + 4); 358. #else 359. mtmp->data->mname); 360. #endif 361. } else pline("You must be next to your %s to unleash him.", 362. #ifdef RPH 363. lmonnam(mtmp)+4); 364. #else 365. mtmp->data->mname); 366. #endif 367. } else { 368. 369. for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 370. 371. if(mtmp->mtame && next_to(mtmp)) { 372. 373. pline("You slip the leash around your %s.", mtmp->data->mname); 374. mtmp->mleashed = 1; 375. if(mtmp->msleep) mtmp->msleep = 0; 376. return(0); 377. } 378. } 379. pline("There's nothing here to put a leash on."); 380. } 381. return(0); 382. } 383. 384. next_to(mtmp) register struct monst *mtmp; { 385. 386. return((abs(u.ux - mtmp->mx) <= 1) && (abs(u.uy - mtmp->my) <= 1)); 387. } 388. #endif 389. 390. static int dig_effort; /* effort expended on current pos */ 391. static uchar dig_level; 392. static coord dig_pos; 393. static boolean dig_down; 394. 395. static 396. dig() { 397. register struct rm *lev; 398. register dpx = dig_pos.x, dpy = dig_pos.y; 399. 400. /* perhaps a nymph stole his pick-axe while he was busy digging */ 401. /* or perhaps he teleported away */ 402. if(u.uswallow || !uwep || uwep->otyp != PICK_AXE || 403. dig_level != dlevel || 404. ((dig_down && (dpx != u.ux || dpy != u.uy)) || 405. (!dig_down && dist(dpx,dpy) > 2))) 406. return(0); 407. 408. dig_effort += 10 + abon() + uwep->spe + rn2(5); 409. if(dig_down) { 410. if(!xdnstair) { 411. pline("The floor here seems too hard to dig in."); 412. return(0); 413. } 414. if(dig_effort > 250) { 415. dighole(); 416. return(0); /* done with digging */ 417. } 418. if(dig_effort > 50) { 419. register struct trap *ttmp = t_at(dpx,dpy); 420. 421. if(!ttmp) { 422. ttmp = maketrap(dpx,dpy,PIT); 423. ttmp->tseen = 1; 424. pline("You have dug a pit."); 425. u.utrap = rn1(4,2); 426. u.utraptype = TT_PIT; 427. return(0); 428. } 429. } 430. } else 431. if(dig_effort > 100) { 432. register char *digtxt; 433. register struct obj *obj; 434. 435. lev = &levl[dpx][dpy]; 436. if(obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) { 437. fracture_rock(obj); 438. digtxt = "The rock falls apart."; 439. } else if(!lev->typ || lev->typ == SCORR) { 440. lev->typ = CORR; 441. digtxt = "You succeeded in cutting away some rock."; 442. } else if(lev->typ == HWALL || lev->typ == VWALL 443. || lev->typ == SDOOR) { 444. lev->typ = xdnstair ? DOOR : ROOM; 445. digtxt = "You just made an opening in the wall."; 446. } else 447. digtxt = "Now what exactly was it that you were digging in?"; 448. mnewsym(dpx, dpy); 449. prl(dpx, dpy); 450. pline(digtxt); /* after mnewsym & prl */ 451. return(0); 452. } else { 453. if(IS_WALL(levl[dpx][dpy].typ)) { 454. register int rno = inroom(dpx,dpy); 455. 456. if(rno >= 0 && rooms[rno].rtype >= SHOPBASE) { 457. pline("This wall seems too hard to dig into."); 458. return(0); 459. } 460. } 461. pline("You hit the rock with all your might."); 462. } 463. return(1); 464. } 465. 466. /* When will hole be finished? Very rough indication used by shopkeeper. */ 467. holetime() { 468. return( (occupation == dig) ? (250 - dig_effort)/20 : -1); 469. } 470. 471. dighole() 472. { 473. register struct trap *ttmp = t_at(u.ux, u.uy); 474. 475. if(!xdnstair) { 476. pline("The floor here seems too hard to dig in."); 477. } else { 478. if(ttmp) 479. ttmp->ttyp = TRAPDOOR; 480. else 481. ttmp = maketrap(u.ux, u.uy, TRAPDOOR); 482. ttmp->tseen = 1; 483. pline("You've made a hole in the floor."); 484. if(!u.ustuck && !Levitation) { /* KAA */ 485. if(inshop()) 486. shopdig(1); 487. pline("You fall through ..."); 488. if(u.utraptype == TT_PIT) { 489. u.utrap = 0; 490. u.utraptype = 0; 491. } 492. goto_level(dlevel+1, FALSE); 493. } 494. } 495. } 496. 497. static 498. use_pick_axe(obj) 499. struct obj *obj; 500. { 501. char dirsyms[12]; 502. extern char sdir[]; 503. register char *dsp = dirsyms, *sdp = sdir; 504. register struct monst *mtmp; 505. register struct rm *lev; 506. register int rx, ry, res = 0; 507. 508. #ifndef FREEHAND 509. /* edited by GAN 10/20/86 so that you can't apply the 510. * pick-axe while wielding a cursed weapon 511. */ 512. if(!freehand()) { 513. pline("You have no free hand to dig with!"); 514. return(0); 515. } 516. # ifdef KAA 517. if(cantwield(u.usym)) { 518. pline("You can't hold it strongly enough."); 519. return(0); 520. } 521. # endif 522. #else 523. if(obj != uwep) { 524. if(uwep && uwep->cursed) { 525. /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */ 526. pline("Since your weapon is welded to your hand,"); 527. pline("you cannot use that pick-axe."); 528. return(0); 529. } 530. # ifdef KAA 531. if(cantwield(u.usym)) { 532. pline("You can't hold it strongly enough."); 533. return(0); 534. } 535. unweapon = TRUE; 536. # endif 537. pline("You now wield %s.", doname(obj)); 538. setuwep(obj); 539. res = 1; 540. } 541. #endif 542. while(*sdp) { 543. (void) movecmd(*sdp); /* sets u.dx and u.dy and u.dz */ 544. rx = u.ux + u.dx; 545. ry = u.uy + u.dy; 546. if(u.dz > 0 || (u.dz == 0 && isok(rx, ry) && 547. (IS_ROCK(levl[rx][ry].typ) 548. || sobj_at(ENORMOUS_ROCK, rx, ry)))) 549. *dsp++ = *sdp; 550. sdp++; 551. } 552. *dsp = 0; 553. pline("In what direction do you want to dig? [%s] ", dirsyms); 554. if(!getdir(0)) /* no txt */ 555. return(res); 556. if(u.uswallow && attack(u.ustuck)) /* return(1) */; 557. else 558. if(u.dz < 0) 559. pline("You cannot reach the ceiling."); 560. else 561. #ifdef KAA 562. if(!u.dx && !u.dy && !u.dz) { 563. pline("You hit yourself with your own pick-axe."); 564. losehp(rnd(2)+dbon(), "self-inflicted wound"); 565. flags.botl=1; 566. return(1); 567. } 568. #endif 569. if(u.dz == 0) { 570. if(Confusion) 571. confdir(); 572. rx = u.ux + u.dx; 573. ry = u.uy + u.dy; 574. if((mtmp = m_at(rx, ry)) && attack(mtmp)) 575. return(1); 576. if(!isok(rx, ry)) { 577. pline("Clash!"); 578. return(1); 579. } 580. lev = &levl[rx][ry]; 581. if(lev->typ == DOOR) 582. pline("Your %s against the door.", 583. aobjnam(obj, "clang")); 584. else if(!IS_ROCK(lev->typ) 585. && !sobj_at(ENORMOUS_ROCK, rx, ry)) { 586. /* ACCESSIBLE or POOL */ 587. pline("You swing your %s through thin air.", 588. aobjnam(obj, (char *) 0)); 589. } else { 590. if(dig_pos.x != rx || dig_pos.y != ry 591. || dig_level != dlevel || dig_down) { 592. dig_down = FALSE; 593. dig_pos.x = rx; 594. dig_pos.y = ry; 595. dig_level = dlevel; 596. dig_effort = 0; 597. pline("You start digging."); 598. } else 599. pline("You continue digging."); 600. #ifdef DGKMOD 601. set_occupation(dig, "digging", 0); 602. #else 603. occupation = dig; 604. occtxt = "digging"; 605. #endif 606. } 607. } else if(Levitation) { 608. pline("You cannot reach the floor."); 609. } else { 610. if(dig_pos.x != u.ux || dig_pos.y != u.uy 611. || dig_level != dlevel || !dig_down) { 612. dig_down = TRUE; 613. dig_pos.x = u.ux; 614. dig_pos.y = u.uy; 615. dig_level = dlevel; 616. dig_effort = 0; 617. pline("You start digging in the floor."); 618. if(inshop()) 619. shopdig(0); 620. } else 621. pline("You continue digging in the floor."); 622. #ifdef DGKMOD 623. set_occupation(dig, "digging", 0); 624. #else 625. occupation = dig; 626. occtxt = "digging"; 627. #endif 628. } 629. return(1); 630. } 631. 632. #ifdef RPH 633. static 634. use_mirror(obj) 635. struct obj *obj; 636. { 637. register struct monst *mtmp; 638. register char mlet; 639. extern mpickobj(), freeinv(), rloc(); 640. 641. if(!getdir(1)){ /* ask: in what direction? */ 642. flags.move = multi = 0; 643. return; 644. } 645. if(u.uswallow) { 646. pline("You reflect %s's stomach.", monnam(u.ustuck)); 647. return; 648. } 649. if(u.dz) { 650. pline("You reflect the %s.", 651. (u.dz > 0) ? "floor" : "ceiling"); 652. return; 653. } 654. if(!u.dx && !u.dy && !u.dz) { 655. if(!Blind) 656. pline ("You look as ugly as ever."); 657. else { 658. if (rn2(4-u.uluck/3) || !HTelepat) 659. pline ("You can't see your ugly face."); 660. else { 661. char *tm, *tl; int ll; 662. if (rn2(4)) { 663. tm = "ugly monster"; 664. ll = dlevel - u.medusa_level; 665. } 666. else { 667. tm = "intelligent being"; 668. ll = dlevel - u.wiz_level; 669. } 670. if (ll < -10) tl = "far below you"; 671. else if (ll < -1) tl = "below you"; 672. else if (ll == -1) tl = "under your feet"; 673. else if (ll == 0) tl = "very close to you"; 674. else if (ll == 1) tl = "above your head"; 675. else if (ll > 10) tl = "far above you"; 676. else tl = "above you"; 677. pline ("You get an impression that an %s lives %s.", 678. tm, tl); 679. } 680. } 681. return; 682. } 683. if(mtmp = bchit(u.dx, u.dy, COLNO, 0)) { 684. mlet = mtmp->data->mlet; 685. if(mtmp->msleep){ 686. pline ("%s is tired and doesn't look at your mirror.", 687. Monnam(mtmp)); 688. mtmp->msleep = 0; 689. } else 690. if (!mtmp->mcansee) { 691. pline("%s can't see anything at the moment.", 692. Monnam(mtmp)); 693. } 694. /* some monsters do special things */ 695. else if (!mtmp->mcan && index("EUN8",mlet)) 696. switch (mlet) { 697. case '8': 698. pline("%s is turned to stone!", Monnam(mtmp)); 699. killed(mtmp); 700. break; 701. case 'E': 702. pline("%s is frozen by its reflection.",Monnam(mtmp)); 703. mtmp->mfroz = 1; 704. break; 705. case 'U': 706. pline ("%s has confused itself!", Monnam(mtmp)); 707. mtmp->mconf = 1; 708. break; 709. case 'N': 710. pline ("%s looks beautiful in your mirror.",Monnam(mtmp)); 711. pline ("She decides to take it!"); 712. freeinv(obj); 713. mpickobj(mtmp,obj); 714. rloc(mtmp); 715. break; 716. default: 717. break; 718. } 719. else if (mlet == 'V' || mlet == '&') 720. pline ("%s doesn't seem to reflect anything.", Monnam(mtmp)); 721. else if (!index("agquv1N", mlet) && rn2(5)) { 722. pline ("%s is frightened by its reflection.", 723. Monnam(mtmp)); 724. mtmp->mflee = 1; 725. mtmp->mfleetim += d(2,4); 726. } 727. else 728. pline ("%s doesn't seem to mind %s refection.", 729. Monnam(mtmp), 730. (mlet=='1'?"his":(mlet=='N'?"her":"its"))); 731. }/* if monster hit with mirror */ 732. }/* use_mirror */ 733. 734. #endif
|