Source:NetHack 5.0.0/src/engrave.c
Jump to navigation
Jump to search
Below is the full text to engrave.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/engrave.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 5.0 engrave.c $NHDT-Date: 1737345573 2025/01/19 19:59:33 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.165 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2012. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. /* doengrave() data */ 9. struct _doengrave_ctx { 10. boolean dengr; /* TRUE if we wipe out the current engraving */ 11. boolean doblind; /* TRUE if engraving blinds the player */ 12. boolean doknown; /* TRUE if we identify the stylus */ 13. boolean eow; /* TRUE if we are overwriting oep */ 14. boolean jello; /* TRUE if we are engraving in slime */ 15. boolean ptext; /* TRUE if we must prompt for engrave text */ 16. boolean teleengr; /* TRUE if we move the old engraving */ 17. boolean zapwand; /* TRUE if we remove a wand charge */ 18. boolean disprefresh; /* TRUE if the display needs a refresh */ 19. boolean frosted; /* TRUE if engraving on ice */ 20. boolean adding; /* TRUE if adding to existing engraving */ 21. 22. int ret; /* doengrave return value */ 23. int type; /* Type of engraving made */ 24. int oetype; /* will be set to type of current engraving */ 25. 26. struct obj *otmp; /* Object selected with which to engrave */ 27. struct engr* oep; /* The current engraving */ 28. 29. char buf[BUFSZ]; /* Buffer for final/poly engraving text */ 30. char ebuf[BUFSZ]; /* Buffer for initial engraving text */ 31. char fbuf[BUFSZ]; /* Buffer for "your fingers" */ 32. char qbuf[QBUFSZ]; /* Buffer for query text */ 33. char post_engr_text[BUFSZ]; /* Text displayed after engraving prompt */ 34. char *writer; /* text of item used for writing */ 35. const char *everb; /* Present tense of engraving type */ 36. const char *eloc; /* Where the engraving is (ie dust/floor/...) */ 37. 38. size_t len; /* # of nonspace chars of new engraving text */ 39. }; 40. #ifndef SFCTOOL 41. staticfn int stylus_ok(struct obj *); 42. staticfn boolean u_can_engrave(void); 43. staticfn void doengrave_ctx_init(struct _doengrave_ctx *); 44. staticfn void doengrave_sfx_item_WAN(struct _doengrave_ctx *); 45. staticfn boolean doengrave_sfx_item(struct _doengrave_ctx *); 46. staticfn void doengrave_ctx_verb(struct _doengrave_ctx *); 47. staticfn int engrave(void); 48. staticfn const char *blengr(void); 49. 50. char * 51. random_engraving(char *outbuf, char *pristine_copy) 52. { 53. const char *rumor; 54. 55. /* a random engraving may come from the "rumors" file, 56. or from the "engrave" file (formerly in an array here) */ 57. if (!rn2(4) || !(rumor = getrumor(0, pristine_copy, TRUE)) || !*rumor) 58. (void) get_rnd_text(ENGRAVEFILE, pristine_copy, rn2, MD_PAD_RUMORS); 59. 60. Strcpy(outbuf, pristine_copy); 61. wipeout_text(outbuf, (int) (strlen(outbuf) / 4), 0); 62. return outbuf; 63. } 64. 65. /* Partial rubouts for engraving characters. -3. */ 66. static const struct { 67. char wipefrom; 68. const char *wipeto; 69. } rubouts[] = { { 'A', "^" }, 70. { 'B', "Pb[" }, 71. { 'C', "(" }, 72. { 'D', "|)[" }, 73. { 'E', "|FL[_" }, 74. { 'F', "|-" }, 75. { 'G', "C(" }, 76. { 'H', "|-" }, 77. { 'I', "|" }, 78. { 'K', "|<" }, 79. { 'L', "|_" }, 80. { 'M', "|" }, 81. { 'N', "|\\" }, 82. { 'O', "C(" }, 83. { 'P', "F" }, 84. { 'Q', "C(" }, 85. { 'R', "PF" }, 86. { 'T', "|" }, 87. { 'U', "J" }, 88. { 'V', "/\\" }, 89. { 'W', "V/\\" }, 90. { 'Z', "/" }, 91. { 'b', "|" }, 92. { 'd', "c|" }, 93. { 'e', "c" }, 94. { 'g', "c" }, 95. { 'h', "n" }, 96. { 'j', "i" }, 97. { 'k', "|" }, 98. { 'l', "|" }, 99. { 'm', "nr" }, 100. { 'n', "r" }, 101. { 'o', "c" }, 102. { 'q', "c" }, 103. { 'w', "v" }, 104. { 'y', "v" }, 105. { ':', "." }, 106. { ';', ",:" }, 107. { ',', "." }, 108. { '=', "-" }, 109. { '+', "-|" }, 110. { '*', "+" }, 111. { '@', "0" }, 112. { '0', "C(" }, 113. { '1', "|" }, 114. { '6', "o" }, 115. { '7', "/" }, 116. { '8', "3o" } }; 117. 118. /* degrade some of the characters in a string */ 119. void 120. wipeout_text( 121. char *engr, /* engraving text */ 122. int cnt, /* number of chars to degrade */ 123. unsigned seed) /* for semi-controlled randomization */ 124. { 125. char *s; 126. int i, j, nxt, use_rubout; 127. unsigned lth = (unsigned) strlen(engr); 128. 129. if (lth && cnt > 0) { 130. while (cnt--) { 131. /* pick next character */ 132. if (!seed) { 133. /* random */ 134. nxt = rn2((int) lth); 135. use_rubout = rn2(4); 136. } else { 137. /* predictable; caller can reproduce the same sequence by 138. supplying the same arguments later, or a pseudo-random 139. sequence by varying any of them */ 140. nxt = seed % lth; 141. seed *= 31, seed %= (BUFSZ - 1); 142. use_rubout = seed & 3; 143. } 144. s = &engr[nxt]; 145. if (*s == ' ') 146. continue; 147. 148. /* rub out unreadable & small punctuation marks */ 149. if (strchr("?.,'`-|_", *s)) { 150. *s = ' '; 151. continue; 152. } 153. 154. if (!use_rubout) { 155. i = SIZE(rubouts); 156. } else { 157. for (i = 0; i < SIZE(rubouts); i++) 158. if (*s == rubouts[i].wipefrom) { 159. unsigned ln = (unsigned) strlen(rubouts[i].wipeto); 160. /* 161. * Pick one of the substitutes at random. 162. */ 163. if (!seed) { 164. j = rn2((int) ln); 165. } else { 166. seed *= 31, seed %= (BUFSZ - 1); 167. j = seed % ln; 168. } 169. *s = rubouts[i].wipeto[j]; 170. break; 171. } 172. } 173. 174. /* didn't pick rubout; use '?' for unreadable character */ 175. if (i == SIZE(rubouts)) 176. *s = '?'; 177. } 178. } 179. 180. /* trim trailing spaces */ 181. while (lth && engr[lth - 1] == ' ') 182. engr[--lth] = '\0'; 183. } 184. 185. /* check whether hero can reach something at ground level */ 186. boolean 187. can_reach_floor(boolean check_pit) 188. { 189. struct trap *t; 190. 191. if (u.uswallow 192. || (u.ustuck && !sticks(gy.youmonst.data) 193. /* assume that arms are pinned rather than that the hero 194. has been lifted up above the floor [doesn't explain 195. how hero can attack the creature holding him or her; 196. that's life in nethack...] */ 197. && attacktype(u.ustuck->data, AT_HUGS)) 198. || (Levitation && !(Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)))) 199. return FALSE; 200. /* Restricted/unskilled riders can't reach the floor */ 201. if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) 202. return FALSE; 203. if (u.uundetected && ceiling_hider(gy.youmonst.data)) 204. return FALSE; 205. 206. if (Flying || gy.youmonst.data->msize >= MZ_HUGE) 207. return TRUE; 208. 209. if (check_pit && (t = t_at(u.ux, u.uy)) != 0 210. && (uteetering_at_seen_pit(t) || uescaped_shaft(t))) 211. return FALSE; 212. 213. return TRUE; 214. } 215. 216. /* give a message after caller has determined that hero can't reach */ 217. void 218. cant_reach_floor(coordxy x, coordxy y, boolean up, 219. boolean check_pit, boolean wand_engraving) 220. { 221. pline("%s can't reach the %s.", 222. wand_engraving 223. ? "The wand does nothing more, and the tip of the wand" 224. : "You", 225. up ? ceiling(x, y) 226. : (check_pit && can_reach_floor(FALSE)) ? "bottom of the pit" 227. : surface(x, y)); 228. } 229. 230. struct engr * 231. engr_at(coordxy x, coordxy y) 232. { 233. struct engr *ep = head_engr; 234. 235. while (ep) { 236. if (x == ep->engr_x && y == ep->engr_y) 237. return ep; 238. ep = ep->nxt_engr; 239. } 240. return (struct engr *) 0; 241. } 242. 243. /* Decide whether a particular string is engraved at a specified 244. * location; a case-insensitive substring match is used. 245. * Ignore headstones, in case the player names herself "Elbereth". 246. * 247. * If strict checking is requested, the word is only considered to be 248. * present if it is intact and is the entire content of the engraving. 249. */ 250. struct engr * 251. sengr_at(const char *s, coordxy x, coordxy y, boolean strict) 252. { 253. struct engr *ep = engr_at(x, y); 254. 255. if (ep && ep->engr_type != HEADSTONE && ep->engr_time <= svm.moves) { 256. if (strict ? !strcmpi(ep->engr_txt[actual_text], s) 257. : (strstri(ep->engr_txt[actual_text], s) != 0)) 258. return ep; 259. } 260. return (struct engr *) NULL; 261. } 262. 263. void 264. u_wipe_engr(int cnt) 265. { 266. if (can_reach_floor(TRUE)) 267. wipe_engr_at(u.ux, u.uy, cnt, FALSE); 268. } 269. 270. void 271. wipe_engr_at(coordxy x, coordxy y, xint16 cnt, boolean magical) 272. { 273. struct engr *ep = engr_at(x, y); 274. 275. /* Headstones and some specially marked engravings are indelible */ 276. if (ep && ep->engr_type != HEADSTONE && !ep->nowipeout) { 277. debugpline1("asked to erode %d characters", cnt); 278. if (ep->engr_type != BURN || is_ice(x, y) || (magical && !rn2(2))) { 279. if (ep->engr_type != DUST && ep->engr_type != ENGR_BLOOD) { 280. cnt = rn2(1 + 50 / (cnt + 1)) ? 0 : 1; 281. debugpline1("actually eroding %d characters", cnt); 282. } 283. wipeout_text(ep->engr_txt[actual_text], (int) cnt, 0); 284. while (ep->engr_txt[actual_text][0] == ' ') 285. ep->engr_txt[actual_text]++; 286. if (!ep->engr_txt[actual_text][0]) 287. del_engr(ep); 288. } 289. } 290. } 291. 292. /* 293. * Returns: 294. * non-zero if it can be felt 295. */ 296. boolean 297. engr_can_be_felt(struct engr *ep) 298. { 299. boolean canfeel = FALSE; 300. 301. switch (ep->engr_type) { 302. case ENGRAVE: 303. case HEADSTONE: 304. case BURN: 305. canfeel = TRUE; 306. break; 307. case DUST: 308. case MARK: 309. case ENGR_BLOOD: 310. default: 311. canfeel = FALSE; 312. break; 313. } 314. return canfeel; 315. } 316. 317. void 318. read_engr_at(coordxy x, coordxy y) 319. { 320. struct engr *ep = engr_at(x, y); 321. const char *eloc = surface(x, y); 322. int sensed = 0; 323. 324. /* Sensing an engraving does not require sight for some engraving types, 325. * nor does it necessarily imply comprehension (literacy). 326. */ 327. if (ep && ep->engr_txt[actual_text][0]) { 328. switch (ep->engr_type) { 329. case DUST: 330. if (!Blind) { 331. sensed = 1; 332. pline("%s is written here in the %s.", Something, 333. is_ice(x, y) ? "frost" : "dust"); 334. } 335. break; 336. case ENGRAVE: 337. case HEADSTONE: 338. if (!Blind || can_reach_floor(TRUE)) { 339. sensed = 1; 340. pline("%s is engraved here on the %s.", Something, eloc); 341. } 342. break; 343. case BURN: 344. if (!Blind || can_reach_floor(TRUE)) { 345. sensed = 1; 346. pline("Some text has been %s into the %s here.", 347. is_ice(x, y) ? "melted" : "burned", eloc); 348. } 349. break; 350. case MARK: 351. if (!Blind) { 352. sensed = 1; 353. pline("There's some graffiti on the %s here.", eloc); 354. } 355. break; 356. case ENGR_BLOOD: 357. /* "It's a message! Scrawled in blood!" 358. * "What's it say?" 359. * "It says... `See you next Wednesday.'" -- Thriller 360. */ 361. if (!Blind) { 362. sensed = 1; 363. You_see("a message scrawled in blood here."); 364. } 365. break; 366. default: 367. impossible("%s is written in a very strange way.", Something); 368. sensed = 1; 369. } 370. 371. if (sensed) { 372. char *et, buf[BUFSZ]; 373. const char *endpunct; 374. int maxelen = (int) (sizeof buf 375. /* sizeof "literal" counts terminating \0 */ 376. - sizeof "You feel the words: \"\"."), 377. elen = (int) strlen(ep->engr_txt[actual_text]), 378. off = (int) (ep->engr_txt[actual_text] - engr_text_space(ep)); 379. 380. if (elen > maxelen) { 381. (void) strncpy(buf, ep->engr_txt[actual_text], maxelen); 382. buf[maxelen] = '\0'; 383. et = buf; 384. elen = maxelen; 385. } else { 386. et = ep->engr_txt[actual_text]; 387. } 388. endpunct = ""; 389. if (elen < 2 390. /* only skip if punctuation is original, not degraded char */ 391. || !((ep->engr_txt[pristine_text][off + elen - 1] 392. == et[elen - 1]) 393. && strchr(".!?", et[elen - 1]))) { 394. endpunct = "."; 395. } 396. You("%s: \"%s\"%s", (Blind) ? "feel the words" : "read", et, 397. endpunct); 398. Strcpy(ep->engr_txt[remembered_text], ep->engr_txt[actual_text]); 399. ep->eread = 1; 400. ep->erevealed = 1; 401. if (svc.context.run > 0) 402. nomul(0); 403. } 404. } 405. } 406. 407. void 408. make_engr_at( 409. coordxy x, coordxy y, 410. const char *s, 411. const char *pristine_s, 412. long e_time, 413. int e_type) 414. { 415. int i; 416. struct engr *ep; 417. unsigned smem = Strlen(s) + 1; 418. boolean havepristine = FALSE; 419. 420. if (pristine_s != NULL) { 421. unsigned prmem = Strlen(pristine_s) + 1; 422. if (prmem > smem) 423. smem = prmem; 424. havepristine = TRUE; 425. } 426. if ((ep = engr_at(x, y)) != 0) 427. del_engr(ep); 428. 429. ep = newengr(smem * 3); 430. (void) memset((genericptr_t) ep, 0, (smem * 3) + sizeof (struct engr)); 431. ep->nxt_engr = head_engr; 432. head_engr = ep; 433. ep->engr_x = x; 434. ep->engr_y = y; 435. ep->engr_txt[actual_text] = engr_text_space(ep); 436. ep->engr_txt[remembered_text] = ep->engr_txt[actual_text] + smem; 437. ep->engr_txt[pristine_text] = ep->engr_txt[remembered_text] + smem; 438. for(i = 0; i < text_states; ++i) 439. Strcpy(ep->engr_txt[i], s); 440. if (havepristine) 441. Strcpy(ep->engr_txt[pristine_text], pristine_s); 442. if (!strcmp(s, "Elbereth")) { 443. /* engraving "Elbereth": if done when making a level, it creates 444. an old-style Elbereth that deters monsters when any objects are 445. present; otherwise (done by the player), exercises wisdom */ 446. if (gi.in_mklev) 447. ep->guardobjects = 1; 448. else 449. exercise(A_WIS, TRUE); 450. } 451. ep->engr_time = e_time; 452. ep->engr_type = (xint8) ((e_type > 0) ? e_type : rnd(N_ENGRAVE - 1)); 453. ep->engr_szeach = smem; 454. ep->engr_alloc = smem * 3; 455. /* we do not set ep->eread or ep->erevealed; 456. * the caller will need to if required */ 457. } 458. 459. /* delete any engraving at location <x,y> */ 460. void 461. del_engr_at(coordxy x, coordxy y) 462. { 463. struct engr *ep = engr_at(x, y); 464. 465. if (ep) 466. del_engr(ep); 467. } 468. 469. /* 470. * freehand - returns true if player has a free hand 471. */ 472. int 473. freehand(void) 474. { 475. return (!uwep || !welded(uwep) 476. || (!bimanual(uwep) && (!uarms || !uarms->cursed))); 477. } 478. 479. /* getobj callback for an object to engrave with */ 480. staticfn int 481. stylus_ok(struct obj *obj) 482. { 483. if (!obj) 484. return GETOBJ_SUGGEST; 485. 486. /* Potential extension: exclude weapons that don't make any sense (such as 487. * bullwhips) and downplay rings and gems that wouldn't be good to write 488. * with (such as glass and non-gem rings) */ 489. if (obj->oclass == WEAPON_CLASS || obj->oclass == WAND_CLASS 490. || obj->oclass == GEM_CLASS || obj->oclass == RING_CLASS) 491. return GETOBJ_SUGGEST; 492. 493. /* Only markers and towels are recommended tools. */ 494. if (obj->oclass == TOOL_CLASS 495. && (obj->otyp == TOWEL || obj->otyp == MAGIC_MARKER)) 496. return GETOBJ_SUGGEST; 497. 498. return GETOBJ_DOWNPLAY; 499. } 500. 501. /* can hero engrave at all (at their location)? */ 502. staticfn boolean 503. u_can_engrave(void) 504. { 505. int levtyp = SURFACE_AT(u.ux, u.uy); 506. 507. if (u.uswallow) { 508. if (is_animal(u.ustuck->data)) { 509. pline("What would you write? \"Jonah was here\"?"); 510. return FALSE; 511. } else if (is_whirly(u.ustuck->data)) { 512. cant_reach_floor(u.ux, u.uy, FALSE, FALSE, FALSE); 513. return FALSE; 514. } 515. /* Note: for amorphous engulfers, writing attempt is allowed here 516. but yields the 'jello' result in doengrave() */ 517. } else if (is_lava(u.ux, u.uy)) { 518. You_cant("write on the %s!", surface(u.ux, u.uy)); 519. return FALSE; 520. } else if (is_pool(u.ux, u.uy) || IS_FOUNTAIN(levtyp)) { 521. You_cant("write on the %s!", surface(u.ux, u.uy)); 522. return FALSE; 523. } else if (IS_AIR(levtyp)) { 524. /* airlevel or inside bubble on waterlevel */ 525. You_cant("write in %s!", 526. (levtyp == CLOUD) ? "cloud vapor" : "thin air"); 527. return FALSE; 528. } else if (!ACCESSIBLE(levtyp)) { 529. /* stone, tree, wall, secret corridor, pool, lava, bars */ 530. You_cant("write here."); 531. return FALSE; 532. } 533. 534. if (cantwield(gy.youmonst.data)) { 535. You_cant("even hold anything!"); 536. return FALSE; 537. } 538. if (check_capacity((char *) 0)) 539. return FALSE; 540. return TRUE; 541. } 542. 543. /* initialize the doengrave data */ 544. staticfn void 545. doengrave_ctx_init(struct _doengrave_ctx *de) 546. { 547. de->dengr = FALSE; 548. de->doblind = FALSE; 549. de->doknown = FALSE; 550. de->eow = FALSE; 551. de->ptext = TRUE; 552. de->teleengr = FALSE; 553. de->zapwand = FALSE; 554. de->disprefresh = FALSE; 555. de->adding = FALSE; 556. 557. de->ret = ECMD_OK; 558. de->type = DUST; 559. de->oetype = 0; 560. 561. de->otmp = (struct obj *) 0; 562. de->oep = engr_at(u.ux, u.uy); 563. 564. de->buf[0] = (char) 0; 565. de->ebuf[0] = (char) 0; 566. de->fbuf[0] = (char) 0; 567. de->qbuf[0] = (char) 0; 568. de->post_engr_text[0] = (char) 0; 569. de->writer = (char *) 0; 570. 571. if (de->oep) 572. de->oetype = de->oep->engr_type; 573. if (is_demon(gy.youmonst.data) || is_vampire(gy.youmonst.data)) 574. de->type = ENGR_BLOOD; 575. 576. de->jello = (u.uswallow && !(is_animal(u.ustuck->data) 577. || is_whirly(u.ustuck->data))); 578. de->frosted = is_ice(u.ux, u.uy); 579. } 580. 581. /* special engraving effects for WAND objects */ 582. staticfn void 583. doengrave_sfx_item_WAN(struct _doengrave_ctx *de) 584. { 585. switch (de->otmp->otyp) { 586. /* DUST wands */ 587. default: 588. break; 589. /* NODIR wands */ 590. case WAN_LIGHT: 591. case WAN_SECRET_DOOR_DETECTION: 592. case WAN_STASIS: 593. case WAN_CREATE_MONSTER: 594. case WAN_WISHING: 595. case WAN_ENLIGHTENMENT: 596. zapnodir(de->otmp); 597. break; 598. /* IMMEDIATE wands */ 599. /* If wand is "IMMEDIATE", remember to affect the 600. * previous engraving even if turning to dust. 601. */ 602. case WAN_STRIKING: 603. Strcpy(de->post_engr_text, 604. "The wand unsuccessfully fights your attempt to write!"); 605. break; 606. case WAN_SLOW_MONSTER: 607. if (!Blind) { 608. Sprintf(de->post_engr_text, "The bugs on the %s slow down!", 609. surface(u.ux, u.uy)); 610. } 611. break; 612. case WAN_SPEED_MONSTER: 613. if (!Blind) { 614. Sprintf(de->post_engr_text, "The bugs on the %s speed up!", 615. surface(u.ux, u.uy)); 616. } 617. break; 618. case WAN_POLYMORPH: 619. if (de->oep) { 620. if (!Blind) { 621. de->type = (xint16) 0; /* random */ 622. (void) random_engraving(de->buf, de->ebuf); 623. } else { 624. /* keep the same type so that feels don't 625. change and only the text is altered, 626. but you won't know anyway because 627. you're a _blind writer_ */ 628. if (de->oetype) 629. de->type = de->oetype; 630. xcrypt(blengr(), de->buf); 631. } 632. de->dengr = TRUE; 633. } 634. break; 635. case WAN_NOTHING: 636. case WAN_UNDEAD_TURNING: 637. case WAN_OPENING: 638. case WAN_LOCKING: 639. case WAN_PROBING: 640. break; 641. /* RAY wands */ 642. case WAN_MAGIC_MISSILE: 643. de->ptext = TRUE; 644. if (!Blind) { 645. Sprintf(de->post_engr_text, 646. "The %s is riddled by bullet holes!", 647. surface(u.ux, u.uy)); 648. } 649. break; 650. /* can't tell sleep from death - Eric Backus */ 651. case WAN_SLEEP: 652. case WAN_DEATH: 653. if (!Blind) { 654. Sprintf(de->post_engr_text, "The bugs on the %s stop moving!", 655. surface(u.ux, u.uy)); 656. } 657. break; 658. case WAN_COLD: 659. if (!Blind) 660. Strcpy(de->post_engr_text, 661. "A few ice cubes drop from the wand."); 662. if (!de->oep || (de->oep->engr_type != BURN)) 663. break; 664. FALLTHROUGH; 665. /*FALLTHRU*/ 666. case WAN_CANCELLATION: 667. case WAN_MAKE_INVISIBLE: 668. if (de->oep && de->oep->engr_type != HEADSTONE) { 669. if (!Blind) 670. pline_The("engraving on the %s vanishes!", 671. surface(u.ux, u.uy)); 672. de->dengr = TRUE; 673. } 674. break; 675. case WAN_TELEPORTATION: 676. if (de->oep && de->oep->engr_type != HEADSTONE) { 677. if (!Blind) 678. pline_The("engraving on the %s vanishes!", 679. surface(u.ux, u.uy)); 680. de->teleengr = TRUE; 681. } 682. break; 683. /* type = ENGRAVE wands */ 684. case WAN_DIGGING: 685. de->ptext = TRUE; 686. de->type = ENGRAVE; 687. if (!objects[de->otmp->otyp].oc_name_known) { 688. if (flags.verbose) 689. pline("This %s is a wand of digging!", xname(de->otmp)); 690. de->doknown = TRUE; 691. } 692. Strcpy(de->post_engr_text, 693. (Blind && !Deaf) 694. ? "You hear drilling!" /* Deaf-aware */ 695. : Blind 696. ? "You feel tremors." 697. : IS_GRAVE(levl[u.ux][u.uy].typ) 698. ? "Chips fly out from the headstone." 699. : de->frosted 700. ? "Ice chips fly up from the ice surface!" 701. : (svl.level.locations[u.ux][u.uy].typ 702. == DRAWBRIDGE_DOWN) 703. ? "Splinters fly up from the bridge." 704. : "Gravel flies up from the floor."); 705. break; 706. /* type = BURN wands */ 707. case WAN_FIRE: 708. de->ptext = TRUE; 709. de->type = BURN; 710. if (!objects[de->otmp->otyp].oc_name_known) { 711. if (flags.verbose) 712. pline("This %s is a wand of fire!", xname(de->otmp)); 713. de->doknown = TRUE; 714. } 715. Strcpy(de->post_engr_text, Blind ? "You feel the wand heat up." 716. : "Flames fly from the wand."); 717. break; 718. case WAN_LIGHTNING: 719. de->ptext = TRUE; 720. de->type = BURN; 721. if (!objects[de->otmp->otyp].oc_name_known) { 722. if (flags.verbose) 723. pline("This %s is a wand of lightning!", xname(de->otmp)); 724. de->doknown = TRUE; 725. } 726. if (!Blind) { 727. Strcpy(de->post_engr_text, "Lightning arcs from the wand."); 728. de->doblind = TRUE; 729. } else { 730. Strcpy(de->post_engr_text, !Deaf 731. ? "You hear crackling!" /* Deaf-aware */ 732. : "Your hair stands up!"); 733. } 734. break; 735. /* type = MARK wands */ 736. /* type = ENGR_BLOOD wands */ 737. } 738. } 739. 740. /* special engraving effects for all objects */ 741. staticfn boolean 742. doengrave_sfx_item(struct _doengrave_ctx *de) 743. { 744. switch (de->otmp->oclass) { 745. default: 746. case AMULET_CLASS: 747. case CHAIN_CLASS: 748. case POTION_CLASS: 749. case COIN_CLASS: 750. break; 751. case RING_CLASS: 752. /* "diamond" rings and others should work */ 753. case GEM_CLASS: 754. /* diamonds & other hard gems should work */ 755. if (objects[de->otmp->otyp].oc_tough) { 756. de->type = ENGRAVE; 757. break; 758. } 759. break; 760. case ARMOR_CLASS: 761. if (is_boots(de->otmp)) { 762. de->type = DUST; 763. break; 764. } 765. FALLTHROUGH; 766. /*FALLTHRU*/ 767. /* Objects too large to engrave with */ 768. case BALL_CLASS: 769. case ROCK_CLASS: 770. You_cant("engrave with such a large object!"); 771. de->ptext = FALSE; 772. break; 773. /* Objects too silly to engrave with */ 774. case FOOD_CLASS: 775. case SCROLL_CLASS: 776. case SPBOOK_CLASS: 777. pline("%s would get %s.", Yname2(de->otmp), 778. de->frosted ? "all frosty" : "too dirty"); 779. de->ptext = FALSE; 780. break; 781. case RANDOM_CLASS: /* This should mean fingers */ 782. break; 783. 784. /* The charge is removed from the wand before prompting for 785. * the engraving text, because all kinds of setup decisions 786. * and pre-engraving messages are based upon knowing what type 787. * of engraving the wand is going to do. Also, the player 788. * will have potentially seen "You wrest .." message, and 789. * therefore will know they are using a charge. 790. */ 791. case WAND_CLASS: 792. if (zappable(de->otmp)) { 793. check_unpaid(de->otmp); 794. if (de->otmp->cursed && !rn2(WAND_BACKFIRE_CHANCE)) { 795. wand_explode(de->otmp, 0); 796. de->ret = ECMD_TIME; 797. return FALSE; 798. } 799. de->zapwand = TRUE; 800. if (!can_reach_floor(TRUE)) 801. de->ptext = FALSE; 802. doengrave_sfx_item_WAN(de); 803. } else { /* end if zappable */ 804. /* failing to wrest one last charge takes time */ 805. de->ptext = FALSE; /* use "early exit" below, return 1 */ 806. /* give feedback here if we won't be getting the 807. "can't reach floor" message below */ 808. if (can_reach_floor(TRUE)) { 809. /* cancelled wand turns to dust */ 810. if (de->otmp->spe < 0) 811. de->zapwand = TRUE; 812. /* empty wand just doesn't write */ 813. else 814. pline_The("wand is too worn out to engrave."); 815. } 816. } 817. break; 818. 819. case WEAPON_CLASS: 820. if (is_art(de->otmp, ART_FIRE_BRAND)) { 821. de->type = BURN; /* doesn't dull weapon */ 822. } else if (is_blade(de->otmp)) { 823. /* if non-blade or welded or too dull, engraving type stays set 824. to DUST; feedback for that is only given for bladed weapons */ 825. if (welded(de->otmp)) 826. pline("%s can only scratch the %s.", 827. Yname2(de->otmp), surface(u.ux, u.uy)); 828. else if ((int) de->otmp->spe <= -3) 829. pline("%s too dull for engraving.", 830. Yobjnam2(de->otmp, "are")); 831. else 832. de->type = ENGRAVE; 833. } 834. break; 835. 836. case TOOL_CLASS: 837. if (de->otmp == ublindf) { 838. pline( 839. "That is a bit difficult to engrave with, don't you think?"); 840. de->ret = ECMD_FAIL; 841. return FALSE; 842. } 843. switch (de->otmp->otyp) { 844. case MAGIC_MARKER: 845. if (de->otmp->spe <= 0) 846. Your("marker has dried out."); 847. else 848. de->type = MARK; 849. break; 850. case TOWEL: 851. /* Can't really engrave with a towel */ 852. de->ptext = FALSE; 853. if (de->oep) { 854. if (de->oep->engr_type == DUST 855. || de->oep->engr_type == ENGR_BLOOD 856. || de->oep->engr_type == MARK) { 857. if (is_wet_towel(de->otmp)) 858. dry_a_towel(de->otmp, -1, TRUE); 859. if (!Blind) 860. You("wipe out the message here."); 861. else 862. pline("%s %s.", Yobjnam2(de->otmp, "get"), 863. de->frosted ? "frosty" : "dusty"); 864. de->dengr = TRUE; 865. } else { 866. pline("%s can't wipe out this engraving.", 867. Yname2(de->otmp)); 868. } 869. } else { 870. pline("%s %s.", Yobjnam2(de->otmp, "get"), 871. de->frosted ? "frosty" : "dusty"); 872. } 873. break; 874. default: 875. break; 876. } 877. break; 878. 879. case VENOM_CLASS: 880. /* this used to be ``if (wizard) and fall through to ILLOBJ_CLASS 881. for normal play, but splash of venom isn't "illegal" because it 882. could occur in normal play via wizard mode bones */ 883. pline("Writing a poison pen letter?"); 884. break; 885. 886. case ILLOBJ_CLASS: 887. impossible("You're engraving with an illegal object!"); 888. break; 889. } 890. 891. return TRUE; 892. } 893. 894. /* which verb phrasing to use for engraving */ 895. staticfn void 896. doengrave_ctx_verb(struct _doengrave_ctx *de) 897. { 898. switch (de->type) { 899. default: 900. de->everb = de->adding ? "add to the weird writing on" 901. : "write strangely on"; 902. break; 903. case DUST: 904. de->everb = de->adding ? "add to the writing in" : "write in"; 905. de->eloc = de->frosted ? "frost" : "dust"; 906. break; 907. case HEADSTONE: 908. de->everb = de->adding ? "add to the epitaph on" : "engrave on"; 909. break; 910. case ENGRAVE: 911. de->everb = de->adding ? "add to the engraving in" : "engrave in"; 912. break; 913. case BURN: 914. de->everb = de->adding ? (de->frosted ? "add to the text melted into" 915. : "add to the text burned into") 916. : (de->frosted ? "melt into" : "burn into"); 917. break; 918. case MARK: 919. de->everb = de->adding ? "add to the graffiti on" : "scribble on"; 920. break; 921. case ENGR_BLOOD: 922. de->everb = de->adding ? "add to the scrawl on" : "scrawl on"; 923. break; 924. } 925. } 926. 927. /* Mohs' Hardness Scale: 928. * 1 - Talc 6 - Orthoclase 929. * 2 - Gypsum 7 - Quartz 930. * 3 - Calcite 8 - Topaz 931. * 4 - Fluorite 9 - Corundum 932. * 5 - Apatite 10 - Diamond 933. * 934. * Since granite is an igneous rock hardness ~ 7, anything >= 8 should 935. * probably be able to scratch the rock. 936. * Devaluation of less hard gems is not easily possible because obj struct 937. * does not contain individual oc_cost currently. 7/91 938. * 939. * steel - 5-8.5 (usu. weapon) 940. * diamond - 10 * jade - 5-6 (nephrite) 941. * ruby - 9 (corundum) * turquoise - 5-6 942. * sapphire - 9 (corundum) * opal - 5-6 943. * topaz - 8 * glass - ~5.5 944. * emerald - 7.5-8 (beryl) * dilithium - 4-5?? 945. * aquamarine - 7.5-8 (beryl) * iron - 4-5 946. * garnet - 7.25 (var. 6.5-8) * fluorite - 4 947. * agate - 7 (quartz) * brass - 3-4 948. * amethyst - 7 (quartz) * gold - 2.5-3 949. * jasper - 7 (quartz) * silver - 2.5-3 950. * onyx - 7 (quartz) * copper - 2.5-3 951. * moonstone - 6 (orthoclase) * amber - 2-2.5 952. */ 953. 954. /* the #engrave command */ 955. int 956. doengrave(void) 957. { 958. char *sp; /* Place holder for space count of engr text */ 959. struct _doengrave_ctx *de; 960. int retval; 961. boolean initial_msg_given = FALSE; 962. 963. /* Can the adventurer engrave at all? */ 964. if (!u_can_engrave()) 965. return ECMD_FAIL; 966. 967. de = (struct _doengrave_ctx *) alloc(sizeof (struct _doengrave_ctx)); 968. doengrave_ctx_init(de); 969. 970. gm.multi = 0; /* moves consumed */ 971. gn.nomovemsg = (char *) 0; /* occupation end message */ 972. 973. /* One may write with finger, or weapon, or wand, or..., or... 974. * Edited by GAN 10/20/86 so as not to change weapon wielded. 975. */ 976. 977. de->otmp = getobj("write with", stylus_ok, GETOBJ_PROMPT); 978. if (!de->otmp) {/* otmp == &hands_obj if fingers */ 979. de->ret = ECMD_CANCEL; 980. goto doengr_exit; 981. } 982. 983. if (de->otmp == &hands_obj) { 984. Strcat(strcpy(de->fbuf, "your "), body_part(FINGERTIP)); 985. de->writer = de->fbuf; 986. } else { 987. de->writer = yname(de->otmp); 988. } 989. 990. /* There's no reason you should be able to write with a wand 991. * while both your hands are tied up. 992. */ 993. if (!freehand() && de->otmp != uwep && !de->otmp->owornmask) { 994. You("have no free %s to write with!", body_part(HAND)); 995. goto doengr_exit; 996. } 997. 998. if (de->jello) { 999. You("tickle %s with %s.", mon_nam(u.ustuck), de->writer); 1000. Your("message dissolves..."); 1001. goto doengr_exit; 1002. } 1003. if (!can_reach_floor(TRUE)) { 1004. if (de->otmp->oclass != WAND_CLASS) { 1005. cant_reach_floor(u.ux, u.uy, FALSE, TRUE, FALSE); 1006. goto doengr_exit; 1007. } else { 1008. You("gesture, with your wand, towards the %s below you.", 1009. surface(u.ux, u.uy)); 1010. initial_msg_given = TRUE; 1011. } 1012. } 1013. if (IS_ALTAR(levl[u.ux][u.uy].typ)) { 1014. if (!initial_msg_given) 1015. You("make a motion towards the altar with %s.", de->writer); 1016. altar_wrath(u.ux, u.uy); 1017. goto doengr_exit; 1018. } 1019. if (IS_GRAVE(levl[u.ux][u.uy].typ)) { 1020. if (de->otmp == &hands_obj) { /* using only finger */ 1021. You("would only make a small smudge on the %s.", 1022. surface(u.ux, u.uy)); 1023. goto doengr_exit; 1024. } else if (!levl[u.ux][u.uy].disturbed) { 1025. /* disturb the grave: summon a ghoul, same as sometimes 1026. happens when kicking; sets levl[ux][uy]->disturbed so 1027. that it'll only happen once */ 1028. disturb_grave(u.ux, u.uy); 1029. goto doengr_exit; 1030. } 1031. } 1032. 1033. /* SPFX for items */ 1034. if (!doengrave_sfx_item(de)) 1035. goto doengr_exit; 1036. 1037. if (IS_GRAVE(levl[u.ux][u.uy].typ)) { 1038. if (de->type == ENGRAVE || de->type == 0) { 1039. de->type = HEADSTONE; 1040. } else { 1041. /* ensures the "cannot wipe out" case */ 1042. de->type = DUST; 1043. de->dengr = FALSE; 1044. de->teleengr = FALSE; 1045. de->buf[0] = '\0'; 1046. } 1047. } 1048. 1049. /* 1050. * End of implement setup 1051. */ 1052. 1053. /* Identify stylus */ 1054. if (de->doknown) { 1055. learnwand(de->otmp); 1056. if (objects[de->otmp->otyp].oc_name_known) 1057. more_experienced(0, 10); 1058. } 1059. if (de->teleengr) { 1060. rloc_engr(de->oep); 1061. de->oep->eread = 0; 1062. de->oep->erevealed = 0; 1063. de->disprefresh = TRUE; 1064. de->oep = (struct engr *) 0; 1065. } 1066. if (de->dengr) { 1067. del_engr(de->oep); 1068. de->oep = (struct engr *) 0; 1069. de->disprefresh = TRUE; 1070. } 1071. /* Something has changed the engraving here */ 1072. if (*de->buf) { 1073. struct engr *tmp_ep; 1074. 1075. make_engr_at(u.ux, u.uy, de->buf, de->ebuf, svm.moves, de->type); 1076. tmp_ep = engr_at(u.ux, u.uy); 1077. if (!Blind) { 1078. if (tmp_ep != 0) { 1079. pline_The("engraving now reads: \"%s\".", de->buf); 1080. tmp_ep->eread = 1; 1081. tmp_ep->erevealed = 1; 1082. de->disprefresh = TRUE; 1083. } 1084. } 1085. de->ptext = FALSE; 1086. } 1087. if (de->zapwand && (de->otmp->spe < 0)) { 1088. pline("%s %sturns to dust.", The(xname(de->otmp)), 1089. Blind ? "" : "glows violently, then "); 1090. if (!IS_GRAVE(levl[u.ux][u.uy].typ)) 1091. You( 1092. "are not going to get anywhere trying to write in the %s with your dust.", 1093. de->frosted ? "frost" : "dust"); 1094. useup(de->otmp); 1095. de->otmp = 0; /* wand is now gone */ 1096. de->ptext = FALSE; 1097. } 1098. /* Early exit for some implements. */ 1099. if (!de->ptext) { 1100. if (de->otmp && de->otmp->oclass == WAND_CLASS 1101. && !can_reach_floor(TRUE)) 1102. cant_reach_floor(u.ux, u.uy, FALSE, TRUE, TRUE); 1103. de->ret = ECMD_TIME; 1104. goto doengr_exit; 1105. } 1106. /* 1107. * Special effects should have deleted the current engraving (if 1108. * possible) by now. 1109. */ 1110. if (de->oep) { 1111. char c = 'n'; 1112. 1113. /* Give player the choice to add to engraving. */ 1114. if (de->type == HEADSTONE) { 1115. /* no choice, only append */ 1116. c = 'y'; 1117. } else if (de->type == de->oep->engr_type 1118. && (!Blind || de->oep->engr_type == BURN 1119. || de->oep->engr_type == ENGRAVE)) { 1120. c = yn_function("Do you want to add to the current engraving?", 1121. ynqchars, 'y', TRUE); 1122. if (c == 'q') { 1123. pline1(Never_mind); 1124. goto doengr_exit; 1125. } 1126. } 1127. 1128. if (c == 'n' || Blind) { 1129. if (de->oep->engr_type == DUST 1130. || de->oep->engr_type == ENGR_BLOOD 1131. || de->oep->engr_type == MARK) { 1132. if (!Blind) { 1133. You("wipe out the message that was %s here.", 1134. (de->oep->engr_type == DUST) 1135. ? (de->frosted 1136. ? "written in the frost" 1137. : "written in the dust") 1138. : (de->oep->engr_type == ENGR_BLOOD) 1139. ? "scrawled in blood" 1140. : "written"); 1141. del_engr(de->oep); 1142. de->oep = (struct engr *) 0; 1143. de->disprefresh = TRUE; 1144. } else { 1145. /* defer deletion until after we *know* we're engraving */ 1146. de->eow = TRUE; 1147. } 1148. } else if (de->type == DUST || de->type == MARK 1149. || de->type == ENGR_BLOOD) { 1150. You("cannot wipe out the message that is %s the %s here.", 1151. (de->oep->engr_type == BURN) 1152. ? (de->frosted ? "melted into" : "burned into") 1153. : "engraved in", 1154. surface(u.ux, u.uy)); 1155. de->ret = ECMD_TIME; 1156. goto doengr_exit; 1157. } else if (de->type != de->oep->engr_type || c == 'n') { 1158. if (!Blind || can_reach_floor(TRUE)) 1159. You("will overwrite the current message."); 1160. de->eow = TRUE; 1161. } 1162. } else if (de->oep 1163. && Strlen(de->oep->engr_txt[actual_text]) >= BUFSZ - 1) { 1164. There("is no room to add anything else here."); 1165. de->ret = ECMD_TIME; 1166. goto doengr_exit; 1167. } 1168. } 1169. 1170. de->eloc = surface(u.ux, u.uy); 1171. de->adding = (de->oep && !de->eow); 1172. doengrave_ctx_verb(de); 1173. 1174. /* Tell adventurer what is going on */ 1175. if (de->otmp != &hands_obj) 1176. You("%s the %s with %s%s.", de->everb, de->eloc, 1177. /* since doname() yields "N items" when quantity is more than 1178. one, match that by using "1 of" rather than "one of" when 1179. informing the player that the stack will be split */ 1180. (de->type == ENGRAVE && de->otmp->quan > 1L) ? "1 of " : "", 1181. doname(de->otmp)); 1182. else 1183. You("%s the %s with your %s.", 1184. de->everb, de->eloc, body_part(FINGERTIP)); 1185. 1186. /* Prompt for engraving! */ 1187. Sprintf(de->qbuf, "What do you want to %s the %s here?", 1188. de->everb, de->eloc); 1189. getlin(de->qbuf, de->ebuf); 1190. /* convert tabs to spaces and condense consecutive spaces to one */ 1191. mungspaces(de->ebuf); 1192. 1193. /* Count the actual # of chars engraved not including spaces */ 1194. de->len = strlen(de->ebuf); 1195. for (sp = de->ebuf; *sp; sp++) 1196. if (*sp == ' ') 1197. de->len -= 1; 1198. 1199. if (de->len == 0 || strchr(de->ebuf, '\033')) { 1200. if (de->zapwand) { 1201. if (!Blind) 1202. pline("%s, then %s.", Tobjnam(de->otmp, "glow"), 1203. otense(de->otmp, "fade")); 1204. de->ret = ECMD_TIME; 1205. goto doengr_exit; 1206. } else { 1207. pline1(Never_mind); 1208. goto doengr_exit; 1209. } 1210. } 1211. 1212. /* A single `x' is the traditional signature of an illiterate person */ 1213. if (de->len != 1 || (!strchr(de->ebuf, 'x') && !strchr(de->ebuf, 'X'))) 1214. if (!u.uconduct.literate++) 1215. livelog_printf(LL_CONDUCT, "became literate by engraving \"%s\"", 1216. de->ebuf); 1217. 1218. /* Mix up engraving if surface or state of mind is unsound. 1219. Note: this won't add or remove any spaces. */ 1220. for (sp = de->ebuf; *sp; sp++) { 1221. if (*sp == ' ') 1222. continue; 1223. if (((de->type == DUST || de->type == ENGR_BLOOD) && !rn2(25)) 1224. || (Blind && !rn2(11)) || (Confusion && !rn2(7)) 1225. || (Stunned && !rn2(4)) || (Hallucination && !rn2(2))) 1226. *sp = ' ' + rnd(96 - 2); /* ASCII '!' thru '~' 1227. (excludes ' ' and DEL) */ 1228. } 1229. 1230. /* Previous engraving is overwritten */ 1231. if (de->eow) { 1232. del_engr(de->oep); 1233. de->oep = (struct engr *) 0; 1234. de->disprefresh = TRUE; 1235. } 1236. 1237. Strcpy(svc.context.engraving.text, de->ebuf); 1238. svc.context.engraving.nextc = svc.context.engraving.text; 1239. svc.context.engraving.stylus = de->otmp; 1240. svc.context.engraving.type = de->type; 1241. svc.context.engraving.pos.x = u.ux; 1242. svc.context.engraving.pos.y = u.uy; 1243. svc.context.engraving.actionct = 0; 1244. set_occupation(engrave, "engraving", 0); 1245. 1246. if (de->post_engr_text[0]) 1247. pline("%s", de->post_engr_text); 1248. if (de->doblind && !resists_blnd(&gy.youmonst)) { 1249. You("are blinded by the flash!"); 1250. make_blinded((long) rnd(50), FALSE); 1251. if (!Blind) 1252. Your1(vision_clears); 1253. } 1254. 1255. /* Engraving will always take at least one action via being run as an 1256. occupation, so do not count this setup as taking time. */ 1257. doengr_exit: 1258. if (de->disprefresh) 1259. newsym(u.ux, u.uy); 1260. retval = de->ret; 1261. free(de); 1262. return retval; 1263. } 1264. 1265. /* occupation callback for engraving some text */ 1266. staticfn int 1267. engrave(void) 1268. { 1269. struct engr *oep; 1270. char buf[BUFSZ]; /* holds the post-this-action engr text, including 1271. * anything already there */ 1272. const char *finishverb; /* "You finish [foo]." */ 1273. struct obj * stylus; /* shorthand for svc.context.engraving.stylus */ 1274. boolean firsttime = (svc.context.engraving.actionct == 0); 1275. int rate = 10; /* # characters that can be engraved in this action */ 1276. boolean truncate = FALSE; 1277. boolean neweng = (svc.context.engraving.actionct == 0); 1278. 1279. boolean carving = (svc.context.engraving.type == ENGRAVE 1280. || svc.context.engraving.type == HEADSTONE); 1281. boolean dulling_wep, marker; 1282. char *endc; /* points at character 1 beyond the last character to engrave 1283. * this action */ 1284. int i, space_left; 1285. 1286. if (svc.context.engraving.pos.x != u.ux 1287. || svc.context.engraving.pos.y != u.uy) { /* teleported? */ 1288. You("are unable to continue engraving."); 1289. return 0; 1290. } 1291. /* Stylus might have been taken out of inventory and destroyed somehow. 1292. * Not safe to dereference stylus until after this. */ 1293. if (svc.context.engraving.stylus == &hands_obj) { /* bare finger */ 1294. stylus = (struct obj *) 0; 1295. } else { 1296. for (stylus = gi.invent; stylus; stylus = stylus->nobj) { 1297. if (stylus == svc.context.engraving.stylus) 1298. break; 1299. } 1300. if (!stylus) { 1301. You("are unable to continue engraving."); 1302. return 0; 1303. } 1304. } 1305. 1306. dulling_wep = (carving && stylus && stylus->oclass == WEAPON_CLASS 1307. && (stylus->otyp != ATHAME || stylus->cursed)); 1308. marker = (stylus && stylus->otyp == MAGIC_MARKER 1309. && svc.context.engraving.type == MARK); 1310. 1311. svc.context.engraving.actionct++; 1312. 1313. /* sanity checks */ 1314. if (dulling_wep && !is_blade(stylus)) { 1315. impossible("carving with non-bladed weapon"); 1316. } else if (svc.context.engraving.type == MARK && !marker) { 1317. impossible("making graffiti with non-marker stylus"); 1318. } 1319. 1320. /* Step 1: Compute rate. */ 1321. if (carving && stylus 1322. && (dulling_wep || stylus->oclass == RING_CLASS 1323. || stylus->oclass == GEM_CLASS)) { 1324. /* slow engraving methods */ 1325. rate = 1; 1326. } else if (marker) { 1327. /* one charge / 2 letters */ 1328. rate = min(rate, stylus->spe * 2); 1329. } 1330. 1331. /* Step 2: Compute last character that can be engraved this action. */ 1332. i = rate; 1333. for (endc = svc.context.engraving.nextc; *endc && i > 0; endc++) { 1334. if (*endc != ' ') { 1335. i--; 1336. } 1337. } 1338. 1339. /* Step 3: affect stylus from engraving - it might wear out. */ 1340. if (dulling_wep) { 1341. boolean splitstack = FALSE, dulled = FALSE; 1342. 1343. /* 'dulling_wep' guarantees that 'stylus' is a weapon which is 1344. not welded to the hero's hand(s) */ 1345. if (stylus->quan > 1L) { 1346. if (firsttime) 1347. pline("One of %s gets dull.", yname(stylus)); 1348. stylus = svc.context.engraving.stylus = splitobj(stylus, 1L); 1349. /* if stack is wielded or quivered, the split-off one isn't */ 1350. stylus->owornmask = 0L; 1351. splitstack = TRUE; 1352. } else { 1353. /* normal case: stylus->quan==1 */ 1354. if (firsttime) 1355. pline("%s gets dull.", Yname2(stylus)); 1356. } 1357. /* Dull the weapon at a rate of -1 enchantment per 2 characters, 1358. * rounding down. 1359. * The number of characters obtainable given starting enchantment: 1360. * -2 => 3, -1 => 5, 0 => 7, +1 => 9, +2 => 11 1361. * Note: this does not allow a +0 anything (except an athame) to 1362. * engrave "Elbereth" all at once. 1363. * However, you can engrave "Elb", then "ere", then "th", by taking 1364. * advantage of the rounding down. */ 1365. if (svc.context.engraving.actionct % 2 == 1) { /* 1st,3rd,... action */ 1366. /* deduct a point on 1st, 3rd, 5th, ... turns, unless this is the 1367. * last character being engraved (a rather convoluted way to round 1368. * down), but always deduct a point on the 1st turn to prevent 1369. * zero-cost engravings. 1370. * Check for truncation *before* deducting a point - otherwise, 1371. * attempting to e.g. engrave 3 characters with a -2 weapon will 1372. * stop at the 1st. */ 1373. if (stylus->spe <= -3) { 1374. if (firsttime) { 1375. impossible("<= -3 weapon valid for engraving"); 1376. } 1377. truncate = TRUE; 1378. } else if (*endc || svc.context.engraving.actionct == 1) { 1379. stylus->spe -= 1; 1380. dulled = TRUE; 1381. } 1382. } 1383. if (splitstack) { 1384. obj_extract_self(stylus); 1385. stylus = hold_another_object(stylus, "You drop one %s!", 1386. doname(stylus), (char *) NULL); 1387. nhUse(stylus); 1388. } else if (dulled && stylus->known) { 1389. /* reflect change in stylus->spe; not needed for splitstack 1390. since hold_another_object() does this */ 1391. prinv((char *) NULL, stylus, 1L); 1392. update_inventory(); 1393. } 1394. } else if (marker) { 1395. int ink_cost = max(rate / 2, 1); /* Prevent infinite graffiti */ 1396. 1397. if (stylus->spe < ink_cost) { 1398. impossible("overly dry marker valid for graffiti?"); 1399. ink_cost = stylus->spe; 1400. truncate = TRUE; 1401. } 1402. stylus->spe -= ink_cost; 1403. update_inventory(); 1404. if (stylus->spe == 0) { 1405. /* can't engrave any further; truncate the string */ 1406. Your("marker dries out."); 1407. truncate = TRUE; 1408. } 1409. } 1410. 1411. switch (svc.context.engraving.type) { 1412. default: 1413. finishverb = "your weird engraving"; 1414. break; 1415. case DUST: 1416. finishverb = is_ice(u.ux, u.uy) ? "writing in the frost" 1417. : "writing in the dust"; 1418. break; 1419. case HEADSTONE: 1420. case ENGRAVE: 1421. finishverb = "engraving"; 1422. break; 1423. case BURN: 1424. finishverb = is_ice(u.ux, u.uy) ? "melting your message into the ice" 1425. : "burning your message into the floor"; 1426. break; 1427. case MARK: 1428. finishverb = "defacing the dungeon"; 1429. break; 1430. case ENGR_BLOOD: 1431. finishverb = "scrawling"; 1432. } 1433. 1434. /* actions that happen at the end of every engraving action go here */ 1435. 1436. buf[0] = '\0'; 1437. oep = engr_at(u.ux, u.uy); 1438. if (oep) /* add to existing engraving */ 1439. Strcpy(buf, oep->engr_txt[actual_text]); 1440. 1441. space_left = (int) (sizeof buf - strlen(buf) - 1U); 1442. if (endc - svc.context.engraving.nextc > space_left) { 1443. You("run out of room to write."); 1444. endc = svc.context.engraving.nextc + space_left; 1445. truncate = TRUE; 1446. } 1447. 1448. /* If the stylus did wear out mid-engraving, truncate the input so that we 1449. * can't go any further. */ 1450. if (truncate && *endc != '\0') { 1451. *endc = '\0'; 1452. You("are only able to write \"%s\".", svc.context.engraving.text); 1453. } else { 1454. /* input was not truncated; stylus may still have worn out on the last 1455. * character, though */ 1456. truncate = FALSE; 1457. } 1458. 1459. (void) strncat(buf, svc.context.engraving.nextc, 1460. min(space_left, endc - svc.context.engraving.nextc)); 1461. make_engr_at(u.ux, u.uy, buf, NULL, svm.moves - gm.multi, 1462. svc.context.engraving.type); 1463. oep = engr_at(u.ux, u.uy); 1464. if (oep) { 1465. oep->eread = 1; 1466. oep->erevealed = 1; 1467. } 1468. 1469. if (*endc) { 1470. svc.context.engraving.nextc = endc; 1471. if (neweng) { 1472. newsym(svc.context.engraving.pos.x, svc.context.engraving.pos.y); 1473. } 1474. return 1; /* not yet finished this turn */ 1475. } else { /* finished engraving */ 1476. /* actions that happen after the engraving is finished go here */ 1477. 1478. if (truncate) { 1479. /* Now that "You are only able to write 'foo'" also prints at the 1480. * end of engraving, this might be redundant. */ 1481. You("cannot write any more."); 1482. } else if (!firsttime) { 1483. /* only print this if engraving took multiple actions */ 1484. You("finish %s.", finishverb); 1485. } 1486. svc.context.engraving.text[0] = '\0'; 1487. svc.context.engraving.nextc = (char *) 0; 1488. svc.context.engraving.stylus = (struct obj *) 0; 1489. } 1490. if (neweng) 1491. newsym(svc.context.engraving.pos.x, svc.context.engraving.pos.y); 1492. return 0; 1493. } 1494. 1495. /* while loading bones, clean up text which might accidentally 1496. or maliciously disrupt player's terminal when displayed */ 1497. void 1498. sanitize_engravings(void) 1499. { 1500. struct engr *ep; 1501. 1502. for (ep = head_engr; ep; ep = ep->nxt_engr) { 1503. sanitize_name(ep->engr_txt[actual_text]); 1504. } 1505. } 1506. 1507. /* mark all engravings as not-discovered/not-read when saving bones */ 1508. void 1509. forget_engravings(void) 1510. { 1511. struct engr *ep; 1512. 1513. for (ep = head_engr; ep; ep = ep->nxt_engr) { 1514. ep->erevealed = ep->eread = 0; 1515. 1516. /* Note: engr_txt[actual_text], engr_txt[rememberd_text], and 1517. * engr_txt[pristine_text] retain their original text rather 1518. * than get updated to reflect each engraving's current text. 1519. * Does it matter? */ 1520. } 1521. } 1522. 1523. void 1524. engraving_sanity_check(void) 1525. { 1526. struct engr *ep; 1527. int levtyp; 1528. 1529. if (head_engr && (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))) { 1530. impossible("engraving sanity: on plane of air/water"); 1531. return; 1532. } 1533. 1534. for (ep = head_engr; ep; ep = ep->nxt_engr) { 1535. coordxy x = ep->engr_x, y = ep->engr_y; 1536. 1537. if (!isok(x, y)) { 1538. impossible("engraving sanity: !isok <%i,%i>", x, y); 1539. continue; 1540. } 1541. levtyp = SURFACE_AT(x, y); 1542. if (is_pool_or_lava(x, y) || IS_AIR(levtyp) || !ACCESSIBLE(levtyp)) { 1543. impossible("engraving sanity: illegal surface (%d: \"%s\")", 1544. levtyp, surface(x, y)); 1545. continue; 1546. } 1547. } 1548. } 1549. 1550. void 1551. save_engravings(NHFILE *nhfp) 1552. { 1553. struct engr *ep, *ep2; 1554. unsigned no_more_engr = 0, engr_alloc; 1555. unsigned szeach; 1556. 1557. for (ep = head_engr; ep; ep = ep2) { 1558. ep2 = ep->nxt_engr; 1559. if (ep->engr_alloc 1560. && ep->engr_txt[actual_text][0] && update_file(nhfp)) { 1561. engr_alloc = (unsigned) ep->engr_alloc; 1562. szeach = ep->engr_szeach; 1563. Sfo_unsigned(nhfp, &engr_alloc, "engraving-engr_alloc"); 1564. Sfo_engr(nhfp, ep, "engraving"); 1565. ep->engr_txt[actual_text] = engr_text_space(ep); 1566. ep->engr_txt[remembered_text] = ep->engr_txt[actual_text] + szeach; 1567. ep->engr_txt[pristine_text] = ep->engr_txt[remembered_text] + szeach; 1568. Sfo_char(nhfp, ep->engr_txt[actual_text], "engraving-actual_text", szeach); 1569. Sfo_char(nhfp, ep->engr_txt[remembered_text], "engraving-remembered_text", szeach); 1570. Sfo_char(nhfp, ep->engr_txt[pristine_text], "engraving-pristine_text", szeach); 1571. } 1572. if (release_data(nhfp)) 1573. dealloc_engr(ep); 1574. } 1575. if (update_file(nhfp)) { 1576. Sfo_unsigned(nhfp, &no_more_engr, "engraving-engr_alloc"); 1577. } 1578. if (release_data(nhfp)) 1579. head_engr = 0; 1580. } 1581. #endif /* !SFCTOOL */ 1582. 1583. void 1584. rest_engravings(NHFILE *nhfp) 1585. { 1586. struct engr *ep; 1587. unsigned lth = 0; 1588. unsigned szeach; 1589. 1590. head_engr = 0; 1591. while (1) { 1592. Sfi_unsigned(nhfp, <h, "engraving-engr_alloc"); 1593. if (lth == 0) 1594. return; 1595. ep = newengr(lth); 1596. Sfi_engr(nhfp, ep, "engraving"); 1597. szeach = ep->engr_szeach; 1598. ep->nxt_engr = head_engr; 1599. head_engr = ep; 1600. ep->engr_txt[actual_text] = engr_text_space(ep); /* Andreas Bormann */ 1601. ep->engr_txt[remembered_text] = ep->engr_txt[actual_text] + szeach; 1602. ep->engr_txt[pristine_text] = ep->engr_txt[remembered_text] + szeach; 1603. Sfi_char(nhfp, ep->engr_txt[actual_text], 1604. "engraving-actual_text", (int) szeach); 1605. Sfi_char(nhfp, ep->engr_txt[remembered_text], 1606. "engraving-remembered_text", (int) szeach); 1607. Sfi_char(nhfp, ep->engr_txt[pristine_text], 1608. "engraving-pristine_text", (int) szeach); 1609. 1610. while (ep->engr_txt[actual_text][0] == ' ') 1611. ep->engr_txt[actual_text]++; 1612. while (ep->engr_txt[remembered_text][0] == ' ') 1613. ep->engr_txt[remembered_text]++; 1614. /* mark as finished for bones levels -- no problem for 1615. * normal levels as the player must have finished engraving 1616. * to be able to move again */ 1617. ep->engr_time = svm.moves; 1618. } 1619. } 1620. 1621. #ifndef SFCTOOL 1622. DISABLE_WARNING_FORMAT_NONLITERAL 1623. 1624. /* to support '#stats' wizard-mode command */ 1625. void 1626. engr_stats( 1627. const char *hdrfmt, 1628. char *hdrbuf, 1629. long *count, 1630. long *size) 1631. { 1632. struct engr *ep; 1633. 1634. Sprintf(hdrbuf, hdrfmt, (long) sizeof (struct engr)); 1635. *count = *size = 0L; 1636. for (ep = head_engr; ep; ep = ep->nxt_engr) { 1637. ++*count; 1638. *size += (long) sizeof *ep + (long) ep->engr_alloc; 1639. } 1640. } 1641. 1642. RESTORE_WARNING_FORMAT_NONLITERAL 1643. 1644. void 1645. del_engr(struct engr *ep) 1646. { 1647. if (ep == head_engr) { 1648. head_engr = ep->nxt_engr; 1649. } else { 1650. struct engr *ept; 1651. 1652. for (ept = head_engr; ept; ept = ept->nxt_engr) 1653. if (ept->nxt_engr == ep) { 1654. ept->nxt_engr = ep->nxt_engr; 1655. break; 1656. } 1657. if (!ept) { 1658. impossible("Error in del_engr?"); 1659. return; 1660. } 1661. } 1662. dealloc_engr(ep); 1663. } 1664. 1665. /* randomly relocate an engraving */ 1666. void 1667. rloc_engr(struct engr *ep) 1668. { 1669. int tx, ty, tryct = 200; 1670. 1671. do { 1672. if (--tryct < 0) 1673. return; 1674. tx = rn1(COLNO - 3, 2); 1675. ty = rn2(ROWNO); 1676. } while (engr_at(tx, ty) || !goodpos(tx, ty, (struct monst *) 0, 0)); 1677. 1678. ep->engr_x = tx; 1679. ep->engr_y = ty; 1680. newsym(tx, ty); /* caller took care of the old location */ 1681. } 1682. 1683. /* Create a headstone at the given location. 1684. * The caller is responsible for newsym(x, y). 1685. */ 1686. void 1687. make_grave(coordxy x, coordxy y, const char *str) 1688. { 1689. char buf[BUFSZ]; 1690. 1691. /* Can we put a grave here? */ 1692. if ((levl[x][y].typ != ROOM && levl[x][y].typ != GRAVE) || t_at(x, y)) 1693. return; 1694. /* Make the grave */ 1695. if (!set_levltyp(x, y, GRAVE)) 1696. return; 1697. /* Engrave the headstone */ 1698. del_engr_at(x, y); 1699. if (!str) 1700. str = get_rnd_text(EPITAPHFILE, buf, rn2, MD_PAD_RUMORS); 1701. make_engr_at(x, y, str, NULL, 0L, HEADSTONE); 1702. return; 1703. } 1704. 1705. /* called when kicking or engraving on a grave's headstone */ 1706. void 1707. disturb_grave(coordxy x, coordxy y) 1708. { 1709. struct rm *lev = &levl[x][y]; 1710. 1711. if (!IS_GRAVE(lev->typ)) { 1712. impossible("Disturbing grave that isn't a grave? (%d)", lev->typ); 1713. } else if (lev->disturbed) { 1714. impossible("Disturbing already disturbed grave?"); 1715. } else { 1716. You("disturb the undead!"); 1717. lev->disturbed = 1; 1718. (void) makemon(&mons[PM_GHOUL], x, y, NO_MM_FLAGS); 1719. exercise(A_WIS, FALSE); 1720. } 1721. } 1722. 1723. void 1724. see_engraving(struct engr *ep) 1725. { 1726. newsym(ep->engr_x, ep->engr_y); 1727. } 1728. 1729. /* like see_engravings() but overrides vision, but only for some types 1730. of engravings that can be felt [this isn't actually used anywhere?] */ 1731. void 1732. feel_engraving(struct engr *ep) 1733. { 1734. if (engr_can_be_felt(ep)) { 1735. ep->eread = 1; 1736. ep->erevealed = 1; 1737. map_engraving(ep, 1); 1738. /* in case it's beneath something, redisplay the something */ 1739. newsym(ep->engr_x, ep->engr_y); 1740. } 1741. } 1742. 1743. static const char blind_writing[][21] = { 1744. {0x44, 0x66, 0x6d, 0x69, 0x62, 0x65, 0x22, 0x45, 0x7b, 0x71, 1745. 0x65, 0x6d, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 1746. {0x51, 0x67, 0x60, 0x7a, 0x7f, 0x21, 0x40, 0x71, 0x6b, 0x71, 1747. 0x6f, 0x67, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 1748. {0x49, 0x6d, 0x73, 0x69, 0x62, 0x65, 0x22, 0x4c, 0x61, 0x7c, 1749. 0x6d, 0x67, 0x24, 0x42, 0x7f, 0x69, 0x6c, 0x77, 0x67, 0x7e, 0x00}, 1750. {0x4b, 0x6d, 0x6c, 0x66, 0x30, 0x4c, 0x6b, 0x68, 0x7c, 0x7f, 1751. 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 1752. {0x51, 0x67, 0x70, 0x7a, 0x7f, 0x6f, 0x67, 0x68, 0x64, 0x71, 1753. 0x21, 0x4f, 0x6b, 0x6d, 0x7e, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00}, 1754. {0x4c, 0x63, 0x76, 0x61, 0x71, 0x21, 0x48, 0x6b, 0x7b, 0x75, 1755. 0x67, 0x63, 0x24, 0x45, 0x65, 0x6b, 0x6b, 0x65, 0x00, 0x00, 0x00}, 1756. {0x4c, 0x67, 0x68, 0x6b, 0x78, 0x68, 0x6d, 0x76, 0x7a, 0x75, 1757. 0x21, 0x4f, 0x71, 0x7a, 0x75, 0x6f, 0x77, 0x00, 0x00, 0x00, 0x00}, 1758. {0x44, 0x66, 0x6d, 0x7c, 0x78, 0x21, 0x50, 0x65, 0x66, 0x65, 1759. 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 1760. {0x44, 0x66, 0x73, 0x69, 0x62, 0x65, 0x22, 0x56, 0x7d, 0x63, 1761. 0x69, 0x76, 0x6b, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 1762. }; 1763. 1764. staticfn const char * 1765. blengr(void) 1766. { 1767. return ROLL_FROM(blind_writing); 1768. } 1769. #endif /* !SFCTOOL */ 1770. /*engrave.c*/