Source:NetHack 5.0.0/src/iactions.c
Jump to navigation
Jump to search
Below is the full text to iactions.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/iactions.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 iactions.c $NHDT-Date: 1762680996 2025/11/09 01:36:36 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.543 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Pasi Kallinen, 2026. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. staticfn boolean item_naming_classification(struct obj *, char *, char *); 9. staticfn int item_reading_classification(struct obj *, char *); 10. staticfn void ia_addmenu(winid, int, char, const char *); 11. staticfn void itemactions_pushkeys(struct obj *, int); 12. 13. enum item_action_actions { 14. IA_NONE = 0, 15. IA_UNWIELD, /* hack for 'w-' */ 16. IA_APPLY_OBJ, /* 'a' */ 17. IA_DIP_OBJ, /* 'a' on a potion == dip */ 18. IA_NAME_OBJ, /* 'c' name individual item */ 19. IA_NAME_OTYP, /* 'C' name item's type */ 20. IA_DROP_OBJ, /* 'd' */ 21. IA_EAT_OBJ, /* 'e' */ 22. IA_ENGRAVE_OBJ, /* 'E' */ 23. IA_FIRE_OBJ, /* 'f' */ 24. IA_ADJUST_OBJ, /* 'i' #adjust inventory letter */ 25. IA_ADJUST_STACK, /* 'I' #adjust with count to split stack */ 26. IA_SACRIFICE, /* 'O' offer sacrifice */ 27. IA_BUY_OBJ, /* 'p' pay shopkeeper */ 28. IA_QUAFF_OBJ, 29. IA_QUIVER_OBJ, 30. IA_READ_OBJ, 31. IA_RUB_OBJ, 32. IA_THROW_OBJ, 33. IA_TAKEOFF_OBJ, 34. IA_TIP_CONTAINER, 35. IA_INVOKE_OBJ, 36. IA_WIELD_OBJ, 37. IA_WEAR_OBJ, 38. IA_SWAPWEAPON, 39. IA_TWOWEAPON, 40. IA_ZAP_OBJ, 41. IA_WHATIS_OBJ, /* '/' specify inventory object */ 42. }; 43. 44. /* construct text for the menu entries for IA_NAME_OBJ and IA_NAME_OTYP */ 45. staticfn boolean 46. item_naming_classification( 47. struct obj *obj, 48. char *onamebuf, 49. char *ocallbuf) 50. { 51. static const char 52. Name[] = "Name", 53. Rename[] = "Rename or un-name", 54. Call[] = "Call", 55. /* "re-call" seems a bit weird, but "recall" and 56. "rename" don't fit for changing a type name */ 57. Recall[] = "Re-call or un-call"; 58. 59. onamebuf[0] = ocallbuf[0] = '\0'; 60. if (name_ok(obj) == GETOBJ_SUGGEST) { 61. Sprintf(onamebuf, "%s %s %s", 62. (!has_oname(obj) || !*ONAME(obj)) ? Name : Rename, 63. the_unique_obj(obj) ? "the" 64. : !is_plural(obj) ? "this specific" 65. : "this stack of", /*"these",*/ 66. simpleonames(obj)); 67. } 68. if (call_ok(obj) == GETOBJ_SUGGEST) { 69. char *callname = simpleonames(obj); 70. 71. /* prefix known unique item with "the", make all other types plural */ 72. if (the_unique_obj(obj)) /* treats unID'd fake amulets as if real */ 73. callname = the(callname); 74. else if (!is_plural(obj)) 75. callname = makeplural(callname); 76. Sprintf(ocallbuf, "%s the type for %s", 77. (!objects[obj->otyp].oc_uname 78. || !*objects[obj->otyp].oc_uname) ? Call : Recall, 79. callname); 80. } 81. return (*onamebuf || *ocallbuf) ? TRUE : FALSE; 82. } 83. 84. /* construct text for the menu entries for IA_READ_OBJ */ 85. staticfn int 86. item_reading_classification(struct obj *obj, char *outbuf) 87. { 88. int otyp = obj->otyp, res = IA_READ_OBJ; 89. 90. *outbuf = '\0'; 91. if (otyp == FORTUNE_COOKIE) { 92. Strcpy(outbuf, "Read the message inside this cookie"); 93. } else if (otyp == T_SHIRT) { 94. Strcpy(outbuf, "Read the slogan on the shirt"); 95. } else if (otyp == ALCHEMY_SMOCK) { 96. Strcpy(outbuf, "Read the slogan on the apron"); 97. } else if (otyp == HAWAIIAN_SHIRT) { 98. Strcpy(outbuf, "Look at the pattern on the shirt"); 99. } else if (obj->oclass == SCROLL_CLASS) { 100. const char *magic = ((obj->dknown 101. #ifdef MAIL_STRUCTURES 102. && otyp != SCR_MAIL 103. #endif 104. && (otyp != SCR_BLANK_PAPER 105. || !objects[otyp].oc_name_known)) 106. ? " to activate its magic" : ""); 107. 108. Sprintf(outbuf, "Read this scroll%s", magic); 109. } else if (obj->oclass == SPBOOK_CLASS) { 110. boolean novel = (otyp == SPE_NOVEL), 111. blank = (otyp == SPE_BLANK_PAPER 112. && objects[otyp].oc_name_known), 113. tome = (otyp == SPE_BOOK_OF_THE_DEAD 114. && objects[otyp].oc_name_known); 115. 116. Sprintf(outbuf, "%s this %s", 117. (novel || blank) ? "Read" : tome ? "Examine" : "Study", 118. novel ? simpleonames(obj) /* "novel" or "paperback book" */ 119. : tome ? "tome" : "spellbook"); 120. } else { 121. res = IA_NONE; 122. } 123. return res; 124. } 125. 126. staticfn void 127. ia_addmenu(winid win, int act, char let, const char *txt) 128. { 129. anything any; 130. int clr = NO_COLOR; 131. 132. any = cg.zeroany; 133. any.a_int = act; 134. add_menu(win, &nul_glyphinfo, &any, let, 0, 135. ATR_NONE, clr, txt, MENU_ITEMFLAGS_NONE); 136. } 137. 138. /* set up a command to execute on a specific item next */ 139. staticfn void 140. itemactions_pushkeys(struct obj *otmp, int act) 141. { 142. switch (act) { 143. default: 144. impossible("Unknown item action %d", act); 145. break; 146. case IA_NONE: 147. break; 148. case IA_UNWIELD: 149. cmdq_add_ec(CQ_CANNED, (otmp == uwep) ? dowield 150. : (otmp == uswapwep) ? remarm_swapwep 151. : (otmp == uquiver) ? dowieldquiver 152. : donull); /* can't happen */ 153. cmdq_add_key(CQ_CANNED, HANDS_SYM); 154. break; 155. case IA_APPLY_OBJ: 156. cmdq_add_ec(CQ_CANNED, doapply); 157. cmdq_add_key(CQ_CANNED, otmp->invlet); 158. break; 159. case IA_DIP_OBJ: 160. /* #altdip instead of normal #dip - takes potion to dip into 161. first (the inventory item instigating this) and item to 162. be dipped second, also ignores floor features such as 163. fountain/sink so we don't need to force m-prefix here */ 164. cmdq_add_ec(CQ_CANNED, dip_into); 165. cmdq_add_key(CQ_CANNED, otmp->invlet); 166. break; 167. case IA_NAME_OBJ: 168. case IA_NAME_OTYP: 169. cmdq_add_ec(CQ_CANNED, docallcmd); 170. cmdq_add_key(CQ_CANNED, (act == IA_NAME_OBJ) ? 'i' : 'o'); 171. cmdq_add_key(CQ_CANNED, otmp->invlet); 172. break; 173. case IA_DROP_OBJ: 174. cmdq_add_ec(CQ_CANNED, dodrop); 175. cmdq_add_key(CQ_CANNED, otmp->invlet); 176. break; 177. case IA_EAT_OBJ: 178. /* start with m-prefix; for #eat, it means ignore floor food 179. if present and eat food from invent */ 180. cmdq_add_ec(CQ_CANNED, do_reqmenu); 181. cmdq_add_ec(CQ_CANNED, doeat); 182. cmdq_add_key(CQ_CANNED, otmp->invlet); 183. break; 184. case IA_ENGRAVE_OBJ: 185. cmdq_add_ec(CQ_CANNED, doengrave); 186. cmdq_add_key(CQ_CANNED, otmp->invlet); 187. break; 188. case IA_FIRE_OBJ: 189. cmdq_add_ec(CQ_CANNED, dofire); 190. break; 191. case IA_ADJUST_OBJ: 192. cmdq_add_ec(CQ_CANNED, doorganize); /* #adjust */ 193. cmdq_add_key(CQ_CANNED, otmp->invlet); 194. break; 195. case IA_ADJUST_STACK: 196. cmdq_add_ec(CQ_CANNED, adjust_split); /* #altadjust */ 197. cmdq_add_key(CQ_CANNED, otmp->invlet); 198. break; 199. case IA_SACRIFICE: 200. cmdq_add_ec(CQ_CANNED, dosacrifice); 201. cmdq_add_key(CQ_CANNED, otmp->invlet); 202. break; 203. case IA_BUY_OBJ: 204. cmdq_add_ec(CQ_CANNED, dopay); 205. cmdq_add_key(CQ_CANNED, otmp->invlet); 206. break; 207. case IA_QUAFF_OBJ: 208. /* start with m-prefix; for #quaff, it means ignore fountain 209. or sink if present and drink a potion from invent */ 210. cmdq_add_ec(CQ_CANNED, do_reqmenu); 211. cmdq_add_ec(CQ_CANNED, dodrink); 212. cmdq_add_key(CQ_CANNED, otmp->invlet); 213. break; 214. case IA_QUIVER_OBJ: 215. cmdq_add_ec(CQ_CANNED, dowieldquiver); 216. cmdq_add_key(CQ_CANNED, otmp->invlet); 217. break; 218. case IA_READ_OBJ: 219. cmdq_add_ec(CQ_CANNED, doread); 220. cmdq_add_key(CQ_CANNED, otmp->invlet); 221. break; 222. case IA_RUB_OBJ: 223. cmdq_add_ec(CQ_CANNED, dorub); 224. cmdq_add_key(CQ_CANNED, otmp->invlet); 225. break; 226. case IA_THROW_OBJ: 227. cmdq_add_ec(CQ_CANNED, dothrow); 228. cmdq_add_key(CQ_CANNED, otmp->invlet); 229. break; 230. case IA_TAKEOFF_OBJ: 231. cmdq_add_ec(CQ_CANNED, ia_dotakeoff); /* #altdotakeoff */ 232. cmdq_add_key(CQ_CANNED, otmp->invlet); 233. break; 234. case IA_TIP_CONTAINER: 235. /* start with m-prefix to skip floor containers; 236. for menustyle:Traditional when more than one floor container 237. is present, player will get a #tip menu and have to pick 238. the "tip something being carried" choice, then this item 239. will be already chosen from inventory; suboptimal but 240. possibly an acceptable tradeoff since combining item actions 241. with use of traditional ggetobj() is an unlikely scenario */ 242. cmdq_add_ec(CQ_CANNED, do_reqmenu); 243. cmdq_add_ec(CQ_CANNED, dotip); 244. cmdq_add_key(CQ_CANNED, otmp->invlet); 245. break; 246. case IA_INVOKE_OBJ: 247. cmdq_add_ec(CQ_CANNED, doinvoke); 248. cmdq_add_key(CQ_CANNED, otmp->invlet); 249. break; 250. case IA_WIELD_OBJ: 251. cmdq_add_ec(CQ_CANNED, dowield); 252. cmdq_add_key(CQ_CANNED, otmp->invlet); 253. break; 254. case IA_WEAR_OBJ: 255. cmdq_add_ec(CQ_CANNED, dowear); 256. cmdq_add_key(CQ_CANNED, otmp->invlet); 257. break; 258. case IA_SWAPWEAPON: 259. cmdq_add_ec(CQ_CANNED, doswapweapon); 260. break; 261. case IA_TWOWEAPON: 262. cmdq_add_ec(CQ_CANNED, dotwoweapon); 263. break; 264. case IA_ZAP_OBJ: 265. cmdq_add_ec(CQ_CANNED, dozap); 266. cmdq_add_key(CQ_CANNED, otmp->invlet); 267. break; 268. case IA_WHATIS_OBJ: 269. cmdq_add_ec(CQ_CANNED, dowhatis); /* "/" command */ 270. cmdq_add_key(CQ_CANNED, 'i'); /* "i" == item from inventory */ 271. cmdq_add_key(CQ_CANNED, otmp->invlet); 272. break; 273. } 274. } 275. 276. /* Show menu of possible actions hero could do with item otmp */ 277. int 278. itemactions(struct obj *otmp) 279. { 280. int n, act = IA_NONE; 281. winid win; 282. char buf[BUFSZ], buf2[BUFSZ]; 283. menu_item *selected; 284. struct monst *mtmp; 285. const char *light = otmp->lamplit ? "Extinguish" : "Light"; 286. boolean already_worn = (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) != 0; 287. 288. win = create_nhwindow(NHW_MENU); 289. start_menu(win, MENU_BEHAVE_STANDARD); 290. 291. /* -: unwield; picking current weapon offers an opportunity for 'w-' 292. to wield bare/gloved hands; likewise for 'Q-' with quivered item(s) */ 293. if (otmp == uwep || otmp == uswapwep || otmp == uquiver) { 294. const char *verb = (otmp == uquiver) ? "Quiver" : "Wield", 295. *action = (otmp == uquiver) ? "un-ready" : "un-wield", 296. *which = is_plural(otmp) ? "these" : "this", 297. *what = ((otmp->oclass == WEAPON_CLASS || is_weptool(otmp)) 298. ? "weapon" : "item"); 299. /* 300. * TODO: if uwep is ammo, tell player that to shoot instead of toss, 301. * the corresponding launcher must be wielded; 302. */ 303. Sprintf(buf, "%s '%c' to %s %s %s", 304. verb, HANDS_SYM, action, which, 305. is_plural(otmp) ? makeplural(what) : what); 306. ia_addmenu(win, IA_UNWIELD, '-', buf); 307. } 308. 309. /* a: apply */ 310. if (otmp->oclass == COIN_CLASS) 311. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Flip a coin"); 312. else if (otmp->otyp == CREAM_PIE) 313. ia_addmenu(win, IA_APPLY_OBJ, 'a', 314. "Hit yourself with this cream pie"); 315. else if (otmp->otyp == BULLWHIP) 316. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Lash out with this whip"); 317. else if (otmp->otyp == GRAPPLING_HOOK) 318. ia_addmenu(win, IA_APPLY_OBJ, 'a', 319. "Grapple something with this hook"); 320. else if (otmp->otyp == BAG_OF_TRICKS && objects[otmp->otyp].oc_name_known) 321. /* bag of tricks skips this unless discovered */ 322. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Reach into this bag"); 323. else if (Is_container(otmp)) 324. /* bag of tricks gets here only if not yet discovered */ 325. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Open this container"); 326. else if (otmp->otyp == CAN_OF_GREASE) 327. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Use the can to grease an item"); 328. else if (otmp->otyp == LOCK_PICK 329. || otmp->otyp == CREDIT_CARD 330. || otmp->otyp == SKELETON_KEY) 331. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Use this tool to pick a lock"); 332. else if (otmp->otyp == TINNING_KIT) 333. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Use this kit to tin a corpse"); 334. else if (otmp->otyp == LEASH) 335. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Tie a pet to this leash"); 336. else if (otmp->otyp == SADDLE) 337. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Place this saddle on a pet"); 338. else if (otmp->otyp == MAGIC_WHISTLE 339. || otmp->otyp == TIN_WHISTLE) 340. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Blow this whistle"); 341. else if (otmp->otyp == EUCALYPTUS_LEAF) 342. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Use this leaf as a whistle"); 343. else if (otmp->otyp == STETHOSCOPE) 344. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Listen through the stethoscope"); 345. else if (otmp->otyp == MIRROR) 346. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Show something its reflection"); 347. else if (otmp->otyp == BELL || otmp->otyp == BELL_OF_OPENING) 348. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Ring the bell"); 349. else if (otmp->otyp == CANDELABRUM_OF_INVOCATION) { 350. Sprintf(buf, "%s the candelabrum", light); 351. ia_addmenu(win, IA_APPLY_OBJ, 'a', buf); 352. } else if (otmp->otyp == WAX_CANDLE || otmp->otyp == TALLOW_CANDLE) { 353. boolean multiple = (otmp->quan == 1L) ? FALSE : TRUE; 354. const char *s = multiple ? "these" : "this"; 355. struct obj *o = carrying(CANDELABRUM_OF_INVOCATION); 356. 357. if (o && o->spe < 7) 358. Sprintf(buf, "Attach %s to your candelabrum, or %s %s", s, 359. !otmp->lamplit ? "light" : "extinguish", /* [lowercase] */ 360. multiple ? "them" : "it"); 361. else 362. Sprintf(buf, "%s %s %s", light, s, simpleonames(otmp)); 363. ia_addmenu(win, IA_APPLY_OBJ, 'a', buf); 364. } else if (otmp->otyp == OIL_LAMP || otmp->otyp == MAGIC_LAMP 365. || otmp->otyp == BRASS_LANTERN) { 366. Sprintf(buf, "%s this light source", light); 367. ia_addmenu(win, IA_APPLY_OBJ, 'a', buf); 368. } else if (otmp->otyp == POT_OIL && objects[otmp->otyp].oc_name_known) { 369. Sprintf(buf, "%s this oil", light); 370. ia_addmenu(win, IA_APPLY_OBJ, 'a', buf); 371. } else if (otmp->oclass == POTION_CLASS) { 372. /* FIXME? this should probably be moved to 'D' rather than be 'a' */ 373. Sprintf(buf, "Dip something into %s potion%s", 374. is_plural(otmp) ? "one of these" : "this", plur(otmp->quan)); 375. ia_addmenu(win, IA_DIP_OBJ, 'a', buf); 376. } else if (otmp->otyp == EXPENSIVE_CAMERA) 377. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Take a photograph"); 378. else if (otmp->otyp == TOWEL) 379. ia_addmenu(win, IA_APPLY_OBJ, 'a', 380. "Clean yourself off with this towel"); 381. else if (otmp->otyp == CRYSTAL_BALL) 382. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Peer into this crystal ball"); 383. else if (otmp->otyp == MAGIC_MARKER) 384. ia_addmenu(win, IA_APPLY_OBJ, 'a', 385. "Write on something with this marker"); 386. else if (otmp->otyp == FIGURINE) 387. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Make this figurine transform"); 388. else if (otmp->otyp == UNICORN_HORN) 389. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Use this unicorn horn"); 390. else if (otmp->otyp == HORN_OF_PLENTY 391. && objects[otmp->otyp].oc_name_known) 392. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Blow into the horn of plenty"); 393. else if (otmp->otyp >= WOODEN_FLUTE && otmp->otyp <= DRUM_OF_EARTHQUAKE) 394. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Play this musical instrument"); 395. else if (otmp->otyp == LAND_MINE || otmp->otyp == BEARTRAP) 396. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Arm this trap"); 397. else if (otmp->otyp == PICK_AXE || otmp->otyp == DWARVISH_MATTOCK) 398. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Dig with this digging tool"); 399. else if (otmp->oclass == WAND_CLASS) 400. ia_addmenu(win, IA_APPLY_OBJ, 'a', "Break this wand"); 401. 402. /* 'c', 'C' - call an item or its type something */ 403. if (item_naming_classification(otmp, buf, buf2)) { 404. if (*buf) 405. ia_addmenu(win, IA_NAME_OBJ, 'c', buf); 406. if (*buf2) 407. ia_addmenu(win, IA_NAME_OTYP, 'C', buf2); 408. } 409. 410. /* d: drop item, works on everything except worn items; those will 411. always have a takeoff/remove choice so we don't have to worry 412. about the menu maybe being empty when 'd' is suppressed */ 413. if (!already_worn) { 414. Sprintf(buf, "Drop this %s", (otmp->quan > 1L) ? "stack" : "item"); 415. ia_addmenu(win, IA_DROP_OBJ, 'd', buf); 416. } 417. 418. /* e: eat item */ 419. if (otmp->otyp == TIN) { 420. Sprintf(buf, "Open %s%s and eat the contents", 421. (otmp->quan > 1L) ? "one of these tins" : "this tin", 422. (otmp->otyp == TIN && uwep && uwep->otyp == TIN_OPENER) 423. ? " with your tin opener" : ""); 424. ia_addmenu(win, IA_EAT_OBJ, 'e', buf); 425. } else if (is_edible(otmp)) { 426. Sprintf(buf, "Eat %s", (otmp->quan > 1L) ? "one of these" : "this"); 427. ia_addmenu(win, IA_EAT_OBJ, 'e', buf); 428. } 429. 430. /* E: engrave with item */ 431. if (otmp->otyp == TOWEL) { 432. ia_addmenu(win, IA_ENGRAVE_OBJ, 'E', 433. "Wipe the floor with this towel"); 434. } else if (otmp->otyp == MAGIC_MARKER) { 435. ia_addmenu(win, IA_ENGRAVE_OBJ, 'E', 436. "Scribble graffiti on the floor"); 437. } else if (otmp->oclass == WEAPON_CLASS || otmp->oclass == WAND_CLASS 438. || otmp->oclass == GEM_CLASS || otmp->oclass == RING_CLASS) { 439. Sprintf(buf, "%s on the %s with %s", 440. (is_blade(otmp) || otmp->oclass == WAND_CLASS 441. || ((otmp->oclass == GEM_CLASS || otmp->oclass == RING_CLASS) 442. && objects[otmp->otyp].oc_tough)) ? "Engrave" : "Write", 443. surface(u.ux, u.uy), 444. (otmp->quan > 1L) ? "one of these items" : "this item"); 445. ia_addmenu(win, IA_ENGRAVE_OBJ, 'E', buf); 446. } 447. 448. /* f: fire quivered ammo */ 449. if (otmp == uquiver) { 450. boolean shoot = ammo_and_launcher(otmp, uwep); 451. 452. /* FIXME: see the multi-shot FIXME about "one of" for 't: throw' */ 453. Sprintf(buf, "%s %s", shoot ? "Shoot" : "Throw", 454. (otmp->quan > 1L) ? "one of these" : "this"); 455. if (shoot) { 456. assert(uwep != NULL); 457. Sprintf(eos(buf), " with your wielded %s", simpleonames(uwep)); 458. } 459. ia_addmenu(win, IA_FIRE_OBJ, 'f', buf); 460. } 461. 462. /* i: #adjust inventory letter; gold can't be adjusted unless there 463. is some in a slot other than '$' (which shouldn't be possible) */ 464. if (otmp->oclass != COIN_CLASS || check_invent_gold("item-action")) 465. ia_addmenu(win, IA_ADJUST_OBJ, 'i', 466. "Adjust inventory by assigning new letter"); 467. /* I: #adjust inventory item by splitting its stack */ 468. if (otmp->quan > 1L && otmp->oclass != COIN_CLASS) 469. ia_addmenu(win, IA_ADJUST_STACK, 'I', 470. "Adjust inventory by splitting this stack"); 471. 472. /* O: offer sacrifice */ 473. if (IS_ALTAR(levl[u.ux][u.uy].typ) && !u.uswallow) { 474. /* FIXME: this doesn't match #offer's likely candidates, which don't 475. include corpses on Astral and don't include amulets off Astral */ 476. if (otmp->otyp == CORPSE) 477. ia_addmenu(win, IA_SACRIFICE, 'O', 478. "Offer this corpse as a sacrifice at this altar"); 479. else if (otmp->otyp == AMULET_OF_YENDOR 480. || otmp->otyp == FAKE_AMULET_OF_YENDOR) 481. ia_addmenu(win, IA_SACRIFICE, 'O', 482. "Offer this amulet as a sacrifice at this altar"); 483. } 484. 485. /* p: pay for unpaid utems */ 486. if (otmp->unpaid 487. /* FIXME: should also handle player owned container (so not 488. flagged 'unpaid') holding shop owned items */ 489. && (mtmp = shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE))) != 0 490. && inhishop(mtmp)) { 491. Sprintf(buf, "Buy this unpaid %s", 492. (otmp->quan > 1L) ? "stack" : "item"); 493. ia_addmenu(win, IA_BUY_OBJ, 'p', buf); 494. } 495. 496. /* P: put on accessory */ 497. if (!already_worn) { 498. /* if 'otmp' is worn, we'll skip 'P' and show 'R' below; 499. if not worn, we show 'P - Put on this <simple-item>' if 500. the slot is available, or 'P - <unavailable>'; for the latter, 501. 'P' will fail but we don't want to omit the choice because 502. item actions can be used to learn commands */ 503. *buf = '\0'; 504. if (otmp->oclass == AMULET_CLASS) { 505. Strcpy(buf, !uamul ? "Put this amulet on" 506. : "[already wearing an amulet]"); 507. } else if (otmp->oclass == RING_CLASS || otmp->otyp == MEAT_RING) { 508. if (!uleft || !uright) 509. Strcpy(buf, "Put this ring on"); 510. else 511. Sprintf(buf, "[both ring %s in use]", 512. makeplural(body_part(FINGER))); 513. } else if (otmp->otyp == BLINDFOLD || otmp->otyp == TOWEL 514. || otmp->otyp == LENSES) { 515. if (ublindf) 516. Strcpy(buf, "[already wearing eyewear]"); 517. else if (otmp->otyp == LENSES) 518. Strcpy(buf, "Put these lenses on"); 519. else 520. Sprintf(buf, "Put this on%s", 521. (otmp->otyp == TOWEL) ? " to blindfold yourself" : ""); 522. } 523. if (*buf) 524. ia_addmenu(win, IA_WEAR_OBJ, 'P', buf); 525. } 526. 527. /* q: drink item */ 528. if (otmp->oclass == POTION_CLASS) { 529. Sprintf(buf, "Quaff (drink) %s", 530. (otmp->quan > 1L) ? "one of these potions" : "this potion"); 531. ia_addmenu(win, IA_QUAFF_OBJ, 'q', buf); 532. } 533. 534. /* Q: quiver throwable item */ 535. if ((otmp->oclass == GEM_CLASS || otmp->oclass == WEAPON_CLASS) 536. && otmp != uquiver) { 537. Sprintf(buf, "Quiver this %s for easy %s with \'f\'ire", 538. (otmp->quan > 1L) ? "stack" : "item", 539. ammo_and_launcher(otmp, uwep) ? "shooting" : "throwing"); 540. ia_addmenu(win, IA_QUIVER_OBJ, 'Q', buf); 541. } 542. 543. /* r: read item */ 544. if (item_reading_classification(otmp, buf) == IA_READ_OBJ) 545. ia_addmenu(win, IA_READ_OBJ, 'r', buf); 546. 547. /* R: remove accessory or rub item */ 548. if (otmp->owornmask & W_ACCESSORY) { 549. Sprintf(buf, "Remove this %s", 550. (otmp->owornmask & W_AMUL) ? "amulet" 551. : (otmp->owornmask & W_RING) ? "ring" 552. : (otmp->owornmask & W_TOOL) ? "eyewear" 553. : "accessory"); /* catchall -- can't happen */ 554. ia_addmenu(win, IA_TAKEOFF_OBJ, 'R', buf); 555. } 556. if (otmp->otyp == OIL_LAMP || otmp->otyp == MAGIC_LAMP 557. || otmp->otyp == BRASS_LANTERN) { 558. Sprintf(buf, "Rub this %s", simpleonames(otmp)); 559. ia_addmenu(win, IA_RUB_OBJ, 'R', buf); 560. } else if (otmp->oclass == GEM_CLASS && is_graystone(otmp)) 561. ia_addmenu(win, IA_RUB_OBJ, 'R', "Rub something on this stone"); 562. 563. /* t: throw item */ 564. if (!already_worn) { 565. boolean shoot = ammo_and_launcher(otmp, uwep); 566. 567. /* 568. * FIXME: 569. * 'one of these' should be changed to 'some of these' when there 570. * is the possibility of a multi-shot volley but we don't have 571. * any way to determine that except by actually calculating the 572. * volley count and that could randomly yield 1 here and 2..N 573. * while throwing or vice versa. 574. */ 575. Sprintf(buf, "%s %s%s", shoot ? "Shoot" : "Throw", 576. (otmp->quan == 1L) ? "this item" 577. : (otmp->otyp == GOLD_PIECE) ? "them" 578. : "one of these", 579. /* if otmp is quivered, we've already listed 580. 'f - shoot|throw this item' as a choice; 581. if 't' is duplicating that, say so ('t' and 'f' 582. behavior differs for throwing a stack of gold) */ 583. (otmp == uquiver && (otmp->otyp != GOLD_PIECE 584. || otmp->quan == 1L)) 585. ? " (same as 'f')" : ""); 586. ia_addmenu(win, IA_THROW_OBJ, 't', buf); 587. } 588. 589. /* T: take off armor, tip carried container */ 590. if (otmp->owornmask & W_ARMOR) 591. ia_addmenu(win, IA_TAKEOFF_OBJ, 'T', "Take off this armor"); 592. if ((Is_container(otmp) && (Has_contents(otmp) || !otmp->cknown)) 593. || (otmp->otyp == HORN_OF_PLENTY && (otmp->spe > 0 || !otmp->known))) 594. ia_addmenu(win, IA_TIP_CONTAINER, 'T', 595. "Tip all the contents out of this container"); 596. 597. /* V: invoke */ 598. if ((otmp->otyp == FAKE_AMULET_OF_YENDOR && !otmp->known) 599. || otmp->oartifact || objects[otmp->otyp].oc_unique 600. /* non-artifact crystal balls don't have any unique power but 601. the #invoke command lists them as likely candidates */ 602. || otmp->otyp == CRYSTAL_BALL) 603. ia_addmenu(win, IA_INVOKE_OBJ, 'V', 604. "Try to invoke a unique power of this object"); 605. 606. /* w: wield, hold in hands, works on everything but with different 607. advice text; not mentioned for things that are already wielded */ 608. if (otmp == uwep || cantwield(gy.youmonst.data)) { 609. ; /* either already wielded or can't wield anything; skip 'w' */ 610. } else if (otmp->oclass == WEAPON_CLASS || is_weptool(otmp) 611. || is_wet_towel(otmp) || otmp->otyp == HEAVY_IRON_BALL) { 612. Sprintf(buf, "Wield this %s as your weapon", 613. (otmp->quan > 1L) ? "stack" : "item"); 614. ia_addmenu(win, IA_WIELD_OBJ, 'w', buf); 615. } else if (otmp->otyp == TIN_OPENER) { 616. ia_addmenu(win, IA_WIELD_OBJ, 'w', 617. "Wield the tin opener to easily open tins"); 618. } else if (!already_worn) { 619. /* originally this was using "hold this item in your hands" but 620. there's no concept of "holding an item", plus it unwields 621. whatever item you already have wielded so use "wield this item" */ 622. Sprintf(buf, "Wield this %s in your %s", 623. (otmp->quan > 1L) ? "stack" : "item", 624. /* only two-handed weapons and unicorn horns care about 625. pluralizing "hand" and they won't reach here, but plural 626. sounds better when poly'd into something with "claw" */ 627. makeplural(body_part(HAND))); 628. ia_addmenu(win, IA_WIELD_OBJ, 'w', buf); 629. } 630. 631. /* W: wear armor */ 632. if (!already_worn) { 633. if (otmp->oclass == ARMOR_CLASS) { 634. /* if 'otmp' is worn we skip 'W' (and show 'T' above instead); 635. if it isn't, we either show "W - wear this" if otmp's slot 636. isn't populated, or "W - [already wearing <simple-armor>]"; 637. for the latter, picking 'W' will fail but we don't want to 638. omit 'W' in this situation */ 639. long Wmask = armcat_to_wornmask(objects[otmp->otyp].oc_armcat); 640. struct obj *o = wearmask_to_obj(Wmask); 641. 642. if (!o) 643. Strcpy(buf, "Wear this armor"); 644. else 645. Sprintf(buf, "[already wearing %s]", an(armor_simple_name(o))); 646. 647. ia_addmenu(win, IA_WEAR_OBJ, 'W', buf); 648. } 649. } 650. 651. /* x: Swap main and readied weapon */ 652. if (otmp == uwep && uswapwep) 653. ia_addmenu(win, IA_SWAPWEAPON, 'x', 654. "Swap this with your alternate weapon"); 655. else if (otmp == uwep) 656. ia_addmenu(win, IA_SWAPWEAPON, 'x', 657. "Ready this as an alternate weapon"); 658. else if (otmp == uswapwep) 659. ia_addmenu(win, IA_SWAPWEAPON, 'x', 660. "Swap this with your main weapon"); 661. 662. /* this is based on TWOWEAPOK() in wield.c; we don't call can_two_weapon() 663. because it is very verbose; attempting to two-weapon might be rejected 664. but we screen out most reasons for rejection before offering it as a 665. choice */ 666. #define MAYBETWOWEAPON(obj) \ 667. ((((obj)->oclass == WEAPON_CLASS) \ 668. ? !(is_launcher(obj) || is_ammo(obj) || is_missile(obj)) \ 669. : is_weptool(obj)) \ 670. && !bimanual(obj)) 671. 672. /* X: Toggle two-weapon mode on or off */ 673. if ((otmp == uwep || otmp == uswapwep) 674. /* if already two-weaponing, no special checks needed to toggle off */ 675. && (u.twoweap 676. /* but if not, try to filter most "you can't do that" here */ 677. || (could_twoweap(gy.youmonst.data) && !uarms 678. && uwep && MAYBETWOWEAPON(uwep) 679. && uswapwep && MAYBETWOWEAPON(uswapwep)))) { 680. Sprintf(buf, "Toggle two-weapon combat %s", u.twoweap ? "off" : "on"); 681. ia_addmenu(win, IA_TWOWEAPON, 'X', buf); 682. } 683. 684. #undef MAYBETWOWEAPON 685. 686. /* z: Zap wand */ 687. if (otmp->oclass == WAND_CLASS) 688. ia_addmenu(win, IA_ZAP_OBJ, 'z', 689. "Zap this wand to release its magic"); 690. 691. /* ?: Look up an item in the game's database */ 692. if (ia_checkfile(otmp)) { 693. Sprintf(buf, "Look up information about %s", 694. (otmp->quan > 1L) ? "these" : "this"); 695. ia_addmenu(win, IA_WHATIS_OBJ, '/', buf); 696. } 697. 698. Sprintf(buf, "Do what with %s?", the(cxname(otmp))); 699. end_menu(win, buf); 700. 701. n = select_menu(win, PICK_ONE, &selected); 702. 703. if (n > 0) { 704. act = selected[0].item.a_int; 705. free((genericptr_t) selected); 706. 707. itemactions_pushkeys(otmp, act); 708. } 709. destroy_nhwindow(win); 710. 711. /* finish the 'i' command: no time elapses and cancelling without 712. selecting an action doesn't matter */ 713. return ECMD_OK; 714. } 715. 716. /*iactions.c*/