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