home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sources / games / 321 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  57.2 KB

  1. Path: sparky!uunet!news.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v16i013:  nethack31 - display oriented dungeons & dragons (Ver. 3.1), Part13/108
  5. Message-ID: <4296@master.CNA.TEK.COM>
  6. Date: 28 Jan 93 19:13:10 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 2148
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: izchak@linc.cis.upenn.edu (Izchak Miller)
  12. Posting-number: Volume 16, Issue 13
  13. Archive-name: nethack31/Part13
  14. Supersedes: nethack3p9: Volume 10, Issue 46-102
  15. Environment: Amiga, Atari, Mac, MS-DOS, OS2, Unix, VMS, X11
  16.  
  17.  
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of archive 13 (of 108)."
  26. # Contents:  dat/yendor.des src/invent.c
  27. # Wrapped by billr@saab on Wed Jan 27 16:08:50 1993
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'dat/yendor.des' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'dat/yendor.des'\"
  31. else
  32. echo shar: Extracting \"'dat/yendor.des'\" \(6672 characters\)
  33. sed "s/^X//" >'dat/yendor.des' <<'END_OF_FILE'
  34. X#    SCCS Id: @(#)yendor.des    3.1    92/01/10
  35. X#    Copyright (c) 1989 by Jean-Christophe Collet
  36. X#    Copyright (c) 1992 by M. Stephenson and Izchak Miller
  37. X# NetHack may be freely redistributed.  See license for details.
  38. X#
  39. X# The top (real) wizard level.
  40. X# Keeping the Moat for old-time's sake
  41. XMAZE:"wizard1",random
  42. XFLAGS:noteleport
  43. XGEOMETRY:center,center
  44. XMAP
  45. X----------------------------.
  46. X|.......|..|.........|.....|.
  47. X|.......S..|.}}}}}}}.|.....|.
  48. X|..--S--|..|.}}---}}.|---S-|.
  49. X|..|....|..|.}--.--}.|..|..|.
  50. X|..|....|..|.}|...|}.|..|..|.
  51. X|..--------|.}--.--}.|..|..|.
  52. X|..|.......|.}}---}}.|..|..|.
  53. X|..S.......|.}}}}}}}.|..|..|.
  54. X|..|.......|.........|..|..|.
  55. X|..|.......|-----------S-S-|.
  56. X|..|.......S...............|.
  57. X----------------------------.
  58. XENDMAP
  59. XSTAIR:levregion(01,00,79,20),(0,0,28,12),up
  60. XSTAIR:levregion(01,00,79,20),(0,0,28,12),down
  61. XBRANCH:levregion(01,00,79,20),(0,0,28,12)
  62. XTELEPORT_REGION:levregion(01,00,79,20),(0,0,28,12)
  63. X# Make it a morgue for rm id in mkmaze.c
  64. X# for the purpose of random sdoor placement
  65. XREGION:(12,01,20,09),unlit,"morgue",unfilled
  66. XMAZEWALK:(28,05),east
  67. XLADDER:(06,05),down
  68. X# Non diggable walls
  69. X# Walls inside the moat stay diggable
  70. XNON_DIGGABLE:(00,00,11,12)
  71. XNON_DIGGABLE:(11,00,21,00)
  72. XNON_DIGGABLE:(11,10,27,12)
  73. XNON_DIGGABLE:(21,00,27,10)
  74. X# The wizard and his guards
  75. XMONSTER:'@',"Wizard of Yendor",(16,05),asleep
  76. XMONSTER:'d',"hell hound",(15,05)
  77. XMONSTER:'V',"vampire lord",(17,05)
  78. X# The local treasure
  79. XOBJECT:'+',"Book of the Dead",(16,05)
  80. X# Surrounding terror
  81. XMONSTER:';',"kraken",(14,02)
  82. XMONSTER:';',"giant eel",(17,02)
  83. XMONSTER:';',"kraken",(13,04)
  84. XMONSTER:';',"giant eel",(13,06)
  85. XMONSTER:';',"kraken",(19,04)
  86. XMONSTER:';',"giant eel",(19,06)
  87. XMONSTER:';',"kraken",(15,08)
  88. XMONSTER:';',"giant eel",(17,08)
  89. X# Random monsters
  90. XMONSTER:'D',random,random
  91. XMONSTER:'H',random,random
  92. XMONSTER:'&',random,random
  93. XMONSTER:'&',random,random
  94. XMONSTER:'&',random,random
  95. XMONSTER:'&',random,random
  96. X# And to make things a little harder.
  97. XTRAP:"board",(16,04)
  98. XTRAP:"board",(16,06)
  99. XTRAP:"board",(15,05)
  100. XTRAP:"board",(17,05)
  101. X# Random traps.
  102. XTRAP:"spiked pit",random
  103. XTRAP:"sleep gas",random
  104. XTRAP:"anti magic",random
  105. XTRAP:"magic",random
  106. X# Some random loot.
  107. XOBJECT:'*',"ruby",random
  108. XOBJECT:'!',random,random
  109. XOBJECT:'!',random,random
  110. XOBJECT:'?',random,random
  111. XOBJECT:'?',random,random
  112. XOBJECT:'+',random,random
  113. XOBJECT:'+',random,random
  114. XOBJECT:'+',random,random
  115. X
  116. X
  117. X# The middle wizard level.
  118. XMAZE:"wizard2",random
  119. XFLAGS:noteleport
  120. XGEOMETRY:center,center
  121. XMAP
  122. X----------------------------.
  123. X|.....|.S....|.............|.
  124. X|.....|.-------S--------S--|.
  125. X|.....|.|.........|........|.
  126. X|..-S--S|.........|........|.
  127. X|..|....|.........|------S-|.
  128. X|..|....|.........|.....|..|.
  129. X|-S-----|.........|.....|..|.
  130. X|.......|.........|S--S--..|.
  131. X|.......|.........|.|......|.
  132. X|-----S----S-------.|......|.
  133. X|............|....S.|......|.
  134. X----------------------------.
  135. XENDMAP
  136. XSTAIR:levregion(01,00,79,20),(0,0,28,12),up
  137. XSTAIR:levregion(01,00,79,20),(0,0,28,12),down
  138. XBRANCH:levregion(01,00,79,20),(0,0,28,12)
  139. XTELEPORT_REGION:levregion(01,00,79,20),(0,0,28,12)
  140. XREGION:(09,03,17,09),unlit,"zoo"
  141. XDOOR:closed,(15,02)
  142. XDOOR:closed,(11,10)
  143. XMAZEWALK:(28,05),east
  144. XLADDER:(12,01),up
  145. XLADDER:(14,11),down
  146. X# Non diggable walls everywhere
  147. XNON_DIGGABLE:(00,00,27,12)
  148. X# Random traps.
  149. XTRAP:"spiked pit",random
  150. XTRAP:"sleep gas",random
  151. XTRAP:"anti magic",random
  152. XTRAP:"magic",random
  153. X# Some random loot.
  154. XOBJECT:'!',random,random
  155. XOBJECT:'!',random,random
  156. XOBJECT:'?',random,random
  157. XOBJECT:'?',random,random
  158. XOBJECT:'+',random,random
  159. X# treasures
  160. XOBJECT:'"',random,(04,06)
  161. X
  162. X
  163. X# The bottom wizard level.
  164. X# Memorialize the fakewiz setup.
  165. XMAZE:"wizard3",random
  166. XFLAGS:noteleport
  167. XGEOMETRY:center,center
  168. XMAP
  169. X----------------------------.
  170. X|..|............S..........|.
  171. X|..|..------------------S--|.
  172. X|..|..|.........|..........|.
  173. X|..S..|.}}}}}}}.|..........|.
  174. X|..|..|.}}---}}.|-S--------|.
  175. X|..|..|.}--.--}.|..|.......|.
  176. X|..|..|.}|...|}.|..|.......|.
  177. X|..---|.}--.--}.|..|.......|.
  178. X|.....|.}}---}}.|..|.......|.
  179. X|.....S.}}}}}}}.|..|.......|.
  180. X|.....|.........|..S.......|.
  181. X----------------------------.
  182. XENDMAP
  183. XSTAIR:levregion(01,00,79,20),(0,0,28,12),up
  184. XSTAIR:levregion(01,00,79,20),(0,0,28,12),down
  185. XBRANCH:levregion(01,00,79,20),(0,0,28,12)
  186. XTELEPORT_REGION:levregion(01,00,79,20),(0,0,28,12)
  187. XPORTAL:(25,11,25,11),(0,0,0,0),"fakewiz1"
  188. XMAZEWALK:(28,09),east
  189. XREGION:(07,03,15,11),unlit,"morgue",unfilled
  190. XREGION:(17,06,18,11),unlit,"beehive"
  191. XDOOR:closed,(18,05)
  192. XDOOR:closed,(19,11)
  193. XLADDER:(11,07),up
  194. X# Non diggable walls
  195. X# Walls inside the moat stay diggable
  196. XNON_DIGGABLE:(00,00,06,12)
  197. XNON_DIGGABLE:(06,00,27,02)
  198. XNON_DIGGABLE:(16,02,27,12)
  199. XNON_DIGGABLE:(06,12,16,12)
  200. XMONSTER:'L',random,(10,07)
  201. XMONSTER:'V',"vampire lord",(12,07)
  202. X# Some surrounding horrors
  203. XMONSTER:';',"kraken",(08,05)
  204. XMONSTER:';',"giant eel",(08,08)
  205. XMONSTER:';',"kraken",(14,05)
  206. XMONSTER:';',"giant eel",(14,08)
  207. X# Other monsters
  208. XMONSTER:'L',random,random
  209. XMONSTER:'D',random,random
  210. XMONSTER:'D',random,(26,09)
  211. XMONSTER:'&',random,random
  212. XMONSTER:'&',random,random
  213. XMONSTER:'&',random,random
  214. X# And to make things a little harder.
  215. XTRAP:"board",(10,07)
  216. XTRAP:"board",(12,07)
  217. XTRAP:"board",(11,06)
  218. XTRAP:"board",(11,08)
  219. X# Some loot
  220. XOBJECT:')',random,random
  221. XOBJECT:'!',random,random
  222. XOBJECT:'?',random,random
  223. XOBJECT:'?',random,random
  224. XOBJECT:'(',random,random
  225. X# treasures
  226. XOBJECT:'"',random,(11,07)
  227. X
  228. X
  229. X# The former decoy wizard levels.
  230. X# There are two of these, and we need to
  231. X# distinguish between them for the portal.
  232. XMAZE:"fakewiz1",random
  233. XGEOMETRY:center,center
  234. XMAP
  235. X.........
  236. X.}}}}}}}.
  237. X.}}---}}.
  238. X.}--.--}.
  239. X.}|...|}.
  240. X.}--.--}.
  241. X.}}---}}.
  242. X.}}}}}}}.
  243. XENDMAP
  244. XSTAIR:levregion(01,00,79,20),(0,0,8,7),up
  245. XSTAIR:levregion(01,00,79,20),(0,0,8,7),down
  246. XBRANCH:levregion(01,00,79,20),(0,0,8,7)
  247. XTELEPORT_REGION:levregion(01,00,79,20),(0,0,8,7)
  248. XPORTAL:(4,4,4,4),(0,0,0,0),"wizard3"
  249. XMAZEWALK:(08,05),east
  250. XREGION:(04,03,06,06),unlit,"ordinary",unfilled,true
  251. XMONSTER:'L',random,(04,04)
  252. XMONSTER:'V',"vampire lord",(03,04)
  253. XMONSTER:';',"kraken",(06,06)
  254. X# And to make things a little harder.
  255. XTRAP:"board",(04,03)
  256. XTRAP:"board",(04,05)
  257. XTRAP:"board",(03,04)
  258. XTRAP:"board",(05,04)
  259. X
  260. X
  261. XMAZE:"fakewiz2",random
  262. XGEOMETRY:center,center
  263. XMAP
  264. X.........
  265. X.}}}}}}}.
  266. X.}}---}}.
  267. X.}--.--}.
  268. X.}|...|}.
  269. X.}--.--}.
  270. X.}}---}}.
  271. X.}}}}}}}.
  272. XENDMAP
  273. XSTAIR:levregion(01,00,79,20),(0,0,8,7),up
  274. XSTAIR:levregion(01,00,79,20),(0,0,8,7),down
  275. XBRANCH:levregion(01,00,79,20),(0,0,8,7)
  276. XTELEPORT_REGION:levregion(01,00,79,20),(0,0,8,7)
  277. XMAZEWALK:(08,05),east
  278. XREGION:(04,03,06,06),unlit,"ordinary",unfilled,true
  279. XMONSTER:'L',random,(04,04)
  280. XMONSTER:'V',"vampire lord",(03,04)
  281. XMONSTER:';',"kraken",(06,06)
  282. X# And to make things a little harder.
  283. XTRAP:"board",(04,03)
  284. XTRAP:"board",(04,05)
  285. XTRAP:"board",(03,04)
  286. XTRAP:"board",(05,04)
  287. X# treasures
  288. XOBJECT:'"',random,(04,04)
  289. END_OF_FILE
  290. if test 6672 -ne `wc -c <'dat/yendor.des'`; then
  291.     echo shar: \"'dat/yendor.des'\" unpacked with wrong size!
  292. fi
  293. # end of 'dat/yendor.des'
  294. fi
  295. if test -f 'src/invent.c' -a "${1}" != "-c" ; then 
  296.   echo shar: Will not clobber existing file \"'src/invent.c'\"
  297. else
  298. echo shar: Extracting \"'src/invent.c'\" \(47145 characters\)
  299. sed "s/^X//" >'src/invent.c' <<'END_OF_FILE'
  300. X/*    SCCS Id: @(#)invent.c    3.1    92/12/11    */
  301. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  302. X/* NetHack may be freely redistributed.  See license for details. */
  303. X
  304. X#include "hack.h"
  305. X#include "artifact.h"
  306. X
  307. X#define    NOINVSYM    '#'
  308. X#define    CONTAINED_SYM    '>'    /* designator for inside a container */
  309. X
  310. X#ifdef OVL1
  311. Xstatic void NDECL(reorder_invent);
  312. Xstatic boolean FDECL(mergable,(struct obj *,struct obj *));
  313. Xstatic int FDECL(merged,(struct obj *,struct obj *,int));
  314. X#endif /* OVL1 */
  315. XSTATIC_DCL void FDECL(assigninvlet,(struct obj *));
  316. XSTATIC_DCL void FDECL(unlinkinv,(struct obj*));
  317. XSTATIC_DCL void FDECL(compactify,(char *));
  318. XSTATIC_PTR int FDECL(ckunpaid,(struct obj *));
  319. X#ifdef OVLB
  320. Xstatic struct obj *FDECL(find_unpaid,(struct obj *,struct obj **));
  321. Xstatic boolean NDECL(wearing_armor);
  322. Xstatic boolean FDECL(is_worn,(struct obj *));
  323. X#endif /* OVLB */
  324. XSTATIC_DCL char FDECL(obj_to_let,(struct obj *));
  325. X
  326. X#ifdef OVLB
  327. X
  328. Xstatic int lastinvnr = 51;    /* 0 ... 51 (never saved&restored) */
  329. X
  330. Xchar inv_order[] = {    /* manipulated in options.c, used below */
  331. X    AMULET_CLASS, WEAPON_CLASS, ARMOR_CLASS, FOOD_CLASS, SCROLL_CLASS,
  332. X    SPBOOK_CLASS, POTION_CLASS, RING_CLASS, WAND_CLASS, TOOL_CLASS, 
  333. X    GEM_CLASS, ROCK_CLASS, BALL_CLASS, CHAIN_CLASS, 0 };
  334. X
  335. X#ifdef WIZARD
  336. X/* wizards can wish for venom, which will become an invisible inventory
  337. X * item without this.  putting it in inv_order would mean venom would
  338. X * suddenly become a choice for all the inventory-class commands, which
  339. X * would probably cause mass confusion.  the test for inventory venom
  340. X * is only WIZARD and not wizard because the wizard can leave venom lying
  341. X * around on a bones level for normal players to find.
  342. X */
  343. Xstatic char venom_inv[] = { VENOM_CLASS, 0 };    /* (constant) */
  344. X#endif
  345. X
  346. XSTATIC_OVL void
  347. Xassigninvlet(otmp)
  348. Xregister struct obj *otmp;
  349. X{
  350. X    boolean inuse[52];
  351. X    register int i;
  352. X    register struct obj *obj;
  353. X
  354. X    for(i = 0; i < 52; i++) inuse[i] = FALSE;
  355. X    for(obj = invent; obj; obj = obj->nobj) if(obj != otmp) {
  356. X        i = obj->invlet;
  357. X        if('a' <= i && i <= 'z') inuse[i - 'a'] = TRUE; else
  358. X        if('A' <= i && i <= 'Z') inuse[i - 'A' + 26] = TRUE;
  359. X        if(i == otmp->invlet) otmp->invlet = 0;
  360. X    }
  361. X    if((i = otmp->invlet) &&
  362. X        (('a' <= i && i <= 'z') || ('A' <= i && i <= 'Z')))
  363. X        return;
  364. X    for(i = lastinvnr+1; i != lastinvnr; i++) {
  365. X        if(i == 52) { i = -1; continue; }
  366. X        if(!inuse[i]) break;
  367. X    }
  368. X    otmp->invlet = (inuse[i] ? NOINVSYM :
  369. X            (i < 26) ? ('a'+i) : ('A'+i-26));
  370. X    lastinvnr = i;
  371. X}
  372. X
  373. X#endif /* OVLB */
  374. X#ifdef OVL1
  375. X
  376. X/* note: assumes ASCII; toggling a bit puts lowercase in front of uppercase */
  377. X#define inv_rank(o) ((o)->invlet ^ 040)
  378. X
  379. X/* sort the inventory; used by addinv() and doorganize() */
  380. Xstatic void
  381. Xreorder_invent()
  382. X{
  383. X    struct obj *otmp, *prev, *next;
  384. X    boolean need_more_sorting;
  385. X
  386. X    do {
  387. X        /*
  388. X         * We expect at most one item to be out of order, so this
  389. X         * isn't nearly as inefficient as it may first appear.
  390. X         */
  391. X        need_more_sorting = FALSE;
  392. X        for (otmp = invent, prev = 0; otmp; ) {
  393. X        next = otmp->nobj;
  394. X        if (next && inv_rank(next) < inv_rank(otmp)) {
  395. X            need_more_sorting = TRUE;
  396. X            if (prev) prev->nobj = next;
  397. X            else      invent = next;
  398. X            otmp->nobj = next->nobj;
  399. X            next->nobj = otmp;
  400. X            prev = next;
  401. X        } else {
  402. X            prev = otmp;
  403. X            otmp = next;
  404. X        }
  405. X        }
  406. X    } while (need_more_sorting);
  407. X}
  408. X
  409. X#undef inv_rank
  410. X
  411. X/* merge obj with otmp and delete obj if types agree */
  412. XSTATIC_OVL int
  413. Xmerged(otmp, obj, lose)
  414. Xregister struct obj *otmp, *obj;
  415. Xregister int lose;
  416. X{
  417. X    if(mergable(otmp, obj)) {
  418. X        /* Approximate age: we do it this way because if we were to
  419. X         * do it "accurately" (merge only when ages are identical)
  420. X         * we'd wind up never merging any corpses.
  421. X         * otmp->age = otmp->age*(1-proportion) + obj->age*proportion;
  422. X         */
  423. X        otmp->age = ((otmp->age*otmp->quan) + (obj->age*obj->quan))
  424. X            / (otmp->quan + obj->quan);
  425. X        otmp->quan += obj->quan;
  426. X        otmp->owt += obj->owt;
  427. X        if(!otmp->onamelth && obj->onamelth)
  428. X            otmp = oname(otmp, ONAME(obj), 1);
  429. X        if(lose) freeobj(obj);
  430. X        obfree(obj,otmp);    /* free(obj), bill->otmp */
  431. X        return(1);
  432. X    } else    return(0);
  433. X}
  434. X
  435. Xstruct obj *
  436. Xaddinv(obj)
  437. Xregister struct obj *obj;
  438. X{
  439. X    register struct obj *otmp, *prev;
  440. X
  441. X    if (obj->otyp == GOLD_PIECE) {
  442. X        u.ugold += obj->quan;
  443. X        flags.botl = 1;
  444. X        return obj;
  445. X    } else if (obj->otyp == AMULET_OF_YENDOR) {
  446. X        if (u.uhave.amulet) impossible ("already have amulet?");
  447. X        u.uhave.amulet = 1;
  448. X    } else if (obj->otyp == CANDELABRUM_OF_INVOCATION) {
  449. X        if (u.uhave.menorah) impossible ("already have candelabrum?");
  450. X        u.uhave.menorah = 1;
  451. X    } else if (obj->otyp == BELL_OF_OPENING) {
  452. X        if (u.uhave.bell) impossible ("already have silver bell?");
  453. X        u.uhave.bell = 1;
  454. X    } else if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  455. X        if (u.uhave.book) impossible ("already have the book?");
  456. X        u.uhave.book = 1;
  457. X#ifdef MULDGN
  458. X    } else if (is_quest_artifact(obj)) {
  459. X        if (u.uhave.questart) impossible ("already have the artifact?");
  460. X        u.uhave.questart = 1;
  461. X        artitouch();
  462. X        set_artifact_intrinsic(obj, 1, W_ART);
  463. X#endif
  464. X    } else if(obj->oartifact) {
  465. X        set_artifact_intrinsic(obj, 1, W_ART);
  466. X    }
  467. X    /* merge if possible; find end of chain in the process */
  468. X    for (prev = 0, otmp = invent; otmp; prev = otmp, otmp = otmp->nobj)
  469. X        if (merged(otmp, obj, 0)) {
  470. X        obj = otmp;
  471. X        goto added;
  472. X        }
  473. X    /* didn't merge, so insert into chain */
  474. X    if (flags.invlet_constant || !prev) {
  475. X        if (flags.invlet_constant) assigninvlet(obj);
  476. X        obj->nobj = invent;        /* insert at beginning */
  477. X        invent = obj;
  478. X        if (flags.invlet_constant) reorder_invent();
  479. X    } else {
  480. X        prev->nobj = obj;        /* insert at end */
  481. X        obj->nobj = 0;
  482. X    }
  483. X
  484. Xadded:
  485. X    if (obj->otyp == LUCKSTONE
  486. X        || (obj->oartifact && spec_ability(obj, SPFX_LUCK))) {
  487. X        /* new luckstone must be in inventory by this point
  488. X         * for correct calculation */
  489. X        if (stone_luck(TRUE) >= 0) u.moreluck = LUCKADD;
  490. X        else u.moreluck = -LUCKADD;
  491. X    } else if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP)
  492. X        check_lamps();
  493. X    update_inventory();
  494. X    return(obj);
  495. X}
  496. X
  497. X#endif /* OVL1 */
  498. X#ifdef OVLB
  499. X
  500. X/* Add an item to the inventory unless we're fumbling, and give a message.
  501. X * If there aren't any free inventory slots, we'll drop it instead.
  502. X * If both success and failure messages are NULL, then we're just doing the
  503. X * fumbling/slot-limit checking for a silent grab.
  504. X * Note: will drop the whole bunch if the object merges first.
  505. X */
  506. Xstruct obj *
  507. Xhold_another_object(obj, drop_fmt, drop_arg, hold_msg)
  508. Xstruct obj *obj;
  509. Xconst char *drop_fmt, *drop_arg, *hold_msg;
  510. X{
  511. X    long oquan = obj->quan;
  512. X    if (!Blind) obj->dknown = 1;    /* maximize mergibility */
  513. X    if (Fumbling) {
  514. X        if (drop_fmt) pline(drop_fmt, drop_arg);
  515. X        dropy(obj);
  516. X    } else {
  517. X        obj = addinv(obj);
  518. X        if (inv_cnt() > 52
  519. X            || ((obj->otyp != LOADSTONE || !obj->cursed)
  520. X            && near_capacity() >= OVERLOADED)) {
  521. X            if (drop_fmt) pline(drop_fmt, drop_arg);
  522. X            dropx(obj);
  523. X        } else {
  524. X            if (hold_msg || drop_fmt) prinv(hold_msg, obj, oquan);
  525. X        }
  526. X    }
  527. X    return obj;
  528. X}
  529. X
  530. Xvoid
  531. Xuseup(obj)
  532. Xregister struct obj *obj;
  533. X{
  534. X    /*  Note:  This works correctly for containers because they */
  535. X    /*       (containers) don't merge.                */
  536. X    if(obj->quan > 1L){
  537. X#ifndef NO_SIGNAL
  538. X        obj->in_use = FALSE;    /* no longer in use */
  539. X#endif
  540. X        obj->quan--;
  541. X        obj->owt = weight(obj);
  542. X    } else {
  543. X        setnotworn(obj);
  544. X        freeinv(obj);
  545. X        obfree(obj, (struct obj *) 0);    /* deletes contents also */
  546. X    }
  547. X}
  548. X
  549. X#endif /* OVLB */
  550. X#ifdef OVL3
  551. X
  552. X/* used by freeinv and doorganize to do list manipulation */
  553. XSTATIC_OVL
  554. Xvoid
  555. Xunlinkinv(obj)
  556. Xregister struct obj *obj;
  557. X{
  558. X    register struct obj *otmp;
  559. X
  560. X    if(obj == invent)
  561. X        invent = invent->nobj;
  562. X    else {
  563. X        for(otmp = invent; otmp->nobj != obj; otmp = otmp->nobj)
  564. X            if(!otmp->nobj) panic("unlinkinv");
  565. X        otmp->nobj = obj->nobj;
  566. X    }
  567. X    obj->nobj = 0;
  568. X}
  569. X
  570. Xvoid
  571. Xfreeinv(obj)
  572. Xregister struct obj *obj;
  573. X{
  574. X    unlinkinv(obj);
  575. X
  576. X    if (obj->otyp == GOLD_PIECE) {
  577. X        u.ugold -= obj->quan;
  578. X        flags.botl = 1;
  579. X        return;
  580. X    } else if (obj->otyp == AMULET_OF_YENDOR) {
  581. X        if (!u.uhave.amulet) impossible ("don't have amulet?");
  582. X        u.uhave.amulet = 0;
  583. X    } else if (obj->otyp == CANDELABRUM_OF_INVOCATION) {
  584. X        if (!u.uhave.menorah) impossible ("don't have candelabrum?");
  585. X        u.uhave.menorah = 0;
  586. X    } else if (obj->otyp == BELL_OF_OPENING) {
  587. X        if (!u.uhave.bell) impossible ("don't have silver bell?");
  588. X        u.uhave.bell = 0;
  589. X    } else if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  590. X        if (!u.uhave.book) impossible ("don't have the book?");
  591. X        u.uhave.book = 0;
  592. X#ifdef MULDGN
  593. X    } else if (is_quest_artifact(obj)) {
  594. X        if(!u.uhave.questart) impossible ("don't have the artifact?");
  595. X        u.uhave.questart = 0;
  596. X        set_artifact_intrinsic(obj, 0, W_ART);
  597. X#endif
  598. X    } else if (obj->oartifact) {
  599. X        set_artifact_intrinsic(obj, 0, W_ART);
  600. X    } else if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP
  601. X           || obj->otyp == BRASS_LANTERN) {
  602. X        if (obj->lamplit) {
  603. X            obj->lamplit = 0;
  604. X            if (!Blind) pline("%s goes out!", The(xname(obj)));
  605. X        }
  606. X        check_lamps();
  607. X    } else if (obj->otyp == LOADSTONE) {
  608. X        curse(obj);
  609. X    } else if (obj->otyp == LUCKSTONE
  610. X           || (obj->oartifact && spec_ability(obj, SPFX_LUCK))) {
  611. X        int luckbon = stone_luck(TRUE);
  612. X        if (!luckbon && !carrying(LUCKSTONE)) u.moreluck = 0;
  613. X        else if (luckbon >= 0) u.moreluck = LUCKADD;
  614. X        else u.moreluck = -LUCKADD;
  615. X        flags.botl = 1;
  616. X    }
  617. X    update_inventory();
  618. X}
  619. X
  620. Xvoid
  621. Xdelallobj(x, y)
  622. Xint x, y;
  623. X{
  624. X    struct obj *otmp, *otmp2;
  625. X
  626. X    for (otmp = level.objects[x][y]; otmp; otmp = otmp2) {
  627. X        otmp2 = otmp->nexthere;
  628. X        if (otmp == uball)
  629. X            unpunish();
  630. X        if (otmp == uchain)
  631. X            continue;
  632. X        delobj(otmp);
  633. X    }
  634. X}
  635. X
  636. X#endif /* OVL3 */
  637. X#ifdef OVL2
  638. X
  639. X/* destroy object in fobj chain (if unpaid, it remains on the bill) */
  640. Xvoid
  641. Xdelobj(obj)
  642. Xregister struct obj *obj;
  643. X{
  644. X#ifdef WALKIES
  645. X    if(obj->otyp == LEASH && obj->leashmon != 0) o_unleash(obj);
  646. X#endif
  647. X    freeobj(obj);
  648. X    newsym(obj->ox,obj->oy);
  649. X    obfree(obj, (struct obj *) 0);    /* frees contents also */
  650. X}
  651. X
  652. X/* unlink obj from chain starting with fobj */
  653. Xvoid
  654. Xfreeobj(obj)
  655. Xregister struct obj *obj;
  656. X{
  657. X    register struct obj *otmp;
  658. X
  659. X    if (obj == fobj)
  660. X        fobj = fobj->nobj;
  661. X    else {
  662. X        for(otmp = fobj; otmp; otmp = otmp->nobj)
  663. X        if (otmp->nobj == obj) {
  664. X            otmp->nobj = obj->nobj;
  665. X            break;
  666. X        }
  667. X        if (!otmp) panic("error in freeobj");
  668. X    }
  669. X    remove_object(obj);
  670. X}
  671. X
  672. X#endif /* OVL2 */
  673. X#ifdef OVL0
  674. X
  675. Xstruct obj *
  676. Xsobj_at(n,x,y)
  677. Xregister int n, x, y;
  678. X{
  679. X    register struct obj *otmp;
  680. X
  681. X    for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
  682. X        if(otmp->otyp == n)
  683. X            return(otmp);
  684. X    return((struct obj *)0);
  685. X}
  686. X
  687. X#endif /* OVL0 */
  688. X#ifdef OVLB
  689. X
  690. Xint
  691. Xcarried(obj)
  692. Xregister struct obj *obj;
  693. X{
  694. X    register struct obj *otmp;
  695. X
  696. X    for(otmp = invent; otmp; otmp = otmp->nobj)
  697. X        if(otmp == obj) return(1);
  698. X    return(0);
  699. X}
  700. X
  701. Xstruct obj *
  702. Xcarrying(type)
  703. Xregister int type;
  704. X{
  705. X    register struct obj *otmp;
  706. X
  707. X    for(otmp = invent; otmp; otmp = otmp->nobj)
  708. X        if(otmp->otyp == type)
  709. X            return(otmp);
  710. X    return((struct obj *) 0);
  711. X}
  712. X
  713. Xboolean
  714. Xhave_lizard()
  715. X{
  716. X    register struct obj *otmp;
  717. X
  718. X    for(otmp = invent; otmp; otmp = otmp->nobj)
  719. X        if(otmp->otyp == CORPSE && otmp->corpsenm == PM_LIZARD)
  720. X            return(TRUE);
  721. X    return(FALSE);
  722. X}
  723. X
  724. Xstruct obj *
  725. Xo_on(id, objchn)
  726. Xunsigned int id;
  727. Xregister struct obj *objchn;
  728. X{
  729. X    struct obj *temp;
  730. X
  731. X    while(objchn) {
  732. X        if(objchn->o_id == id) return(objchn);
  733. X        if (Is_container(objchn) && (temp = o_on(id,objchn->cobj)))
  734. X            return temp;
  735. X        objchn = objchn->nobj;
  736. X    }
  737. X    return((struct obj *) 0);
  738. X}
  739. X
  740. Xboolean
  741. Xobj_here(obj, x, y)
  742. Xregister struct obj *obj;
  743. Xint x, y;
  744. X{
  745. X    register struct obj *otmp;
  746. X
  747. X    for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
  748. X        if(obj == otmp) return(TRUE);
  749. X    return(FALSE);
  750. X}
  751. X
  752. X#endif /* OVLB */
  753. X#ifdef OVL2
  754. X
  755. Xstruct obj *
  756. Xg_at(x,y)
  757. Xregister int x, y;
  758. X{
  759. X    register struct obj *obj = level.objects[x][y];
  760. X    while(obj) {
  761. X        if (obj->otyp == GOLD_PIECE) return obj;
  762. X        obj = obj->nexthere;
  763. X    }
  764. X    return((struct obj *)0);
  765. X}
  766. X
  767. X#endif /* OVL2 */
  768. X#ifdef OVLB
  769. X
  770. X/* Make a gold object from the hero's gold. */
  771. Xstruct obj *
  772. Xmkgoldobj(q)
  773. Xregister long q;
  774. X{
  775. X    register struct obj *otmp;
  776. X
  777. X    otmp = mksobj(GOLD_PIECE, FALSE, FALSE);
  778. X    u.ugold -= q;
  779. X    otmp->quan = q;
  780. X    otmp->owt = weight(otmp);
  781. X    flags.botl = 1;
  782. X    return(otmp);
  783. X}
  784. X
  785. X#endif /* OVLB */
  786. X#ifdef OVL1
  787. X
  788. XSTATIC_OVL void
  789. Xcompactify(buf)
  790. Xregister char *buf;
  791. X/* compact a string of inventory letters by dashing runs of letters */
  792. X{
  793. X    register int i1 = 1, i2 = 1;
  794. X    register char ilet, ilet1, ilet2;
  795. X
  796. X    ilet2 = buf[0];
  797. X    ilet1 = buf[1];
  798. X    buf[++i2] = buf[++i1];
  799. X    ilet = buf[i1];
  800. X    while(ilet) {
  801. X        if(ilet == ilet1+1) {
  802. X            if(ilet1 == ilet2+1)
  803. X                buf[i2 - 1] = ilet1 = '-';
  804. X            else if(ilet2 == '-') {
  805. X                buf[i2 - 1] = ++ilet1;
  806. X                buf[i2] = buf[++i1];
  807. X                ilet = buf[i1];
  808. X                continue;
  809. X            }
  810. X        }
  811. X        ilet2 = ilet1;
  812. X        ilet1 = ilet;
  813. X        buf[++i2] = buf[++i1];
  814. X        ilet = buf[i1];
  815. X    }
  816. X}
  817. X
  818. X/*
  819. X * getobj returns:
  820. X *    struct obj *xxx:    object to do something with.
  821. X *    (struct obj *) 0    error return: no object.
  822. X *    &zeroobj        explicitly no object (as in w-).
  823. X */
  824. Xstruct obj *
  825. Xgetobj(let,word)
  826. Xregister const char *let,*word;
  827. X{
  828. X    register struct obj *otmp;
  829. X    register char ilet;
  830. X    char buf[BUFSZ], qbuf[QBUFSZ];
  831. X    char lets[BUFSZ];
  832. X    register int foo = 0;
  833. X    register char *bp = buf;
  834. X    xchar allowcnt = 0;    /* 0, 1 or 2 */
  835. X    boolean allowgold = FALSE, usegold = FALSE;
  836. X        /* Two possibilities: they can't use gold because it's illegal,
  837. X         * or they can't use gold because they don't have any.
  838. X         */
  839. X    boolean allowall = FALSE;
  840. X    boolean allownone = FALSE;
  841. X    xchar foox = 0;
  842. X    long cnt;
  843. X    boolean prezero = FALSE;
  844. X
  845. X    if(*let == ALLOW_COUNT) let++, allowcnt = 1;
  846. X    if(*let == GOLD_CLASS) let++,
  847. X        usegold = TRUE, allowgold = (u.ugold ? TRUE : FALSE);
  848. X#ifdef POLYSELF
  849. X    /* Equivalent of an "ugly check" for gold */
  850. X    if (usegold && !strcmp(word, "eat") && !metallivorous(uasmon))
  851. X        usegold = allowgold = FALSE;
  852. X#endif
  853. X    if(*let == ALL_CLASSES) let++, allowall = TRUE;
  854. X    if(*let == ALLOW_NONE) let++, allownone = TRUE;
  855. X    /* "ugly check" for reading fortune cookies, part 1 */
  856. X    if(allowall && !strcmp(word, "read")) allowall = FALSE;
  857. X
  858. X    if(allownone) *bp++ = '-';
  859. X    if(allowgold) *bp++ = def_oc_syms[GOLD_CLASS];
  860. X    if(bp > buf && bp[-1] == '-') *bp++ = ' ';
  861. X
  862. X    ilet = 'a';
  863. X    for(otmp = invent; otmp; otmp = otmp->nobj){
  864. X        if(!*let || index(let, otmp->oclass)) {
  865. X        bp[foo++] = flags.invlet_constant ? otmp->invlet : ilet;
  866. X
  867. X        /* ugly check: remove inappropriate things */
  868. X        if((!strcmp(word, "take off") &&
  869. X            (!(otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))
  870. X             || (otmp==uarm && uarmc)
  871. X#ifdef TOURIST
  872. X             || (otmp==uarmu && (uarm || uarmc))
  873. X#endif
  874. X            ))
  875. X        || (!strcmp(word, "wear") &&
  876. X             (otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)))
  877. X                            /* already worn */
  878. X        || (!strcmp(word, "wield") &&
  879. X            (otmp->owornmask & W_WEP))
  880. X            ) {
  881. X            foo--;
  882. X            foox++;
  883. X        }
  884. X
  885. X        /* Second ugly check; unlike the first it won't trigger an
  886. X         * "else" in "you don't have anything else to ___".
  887. X         */
  888. X        else if ((!strcmp(word, "wear") &&
  889. X            (otmp->oclass == TOOL_CLASS &&
  890. X             otmp->otyp != BLINDFOLD && otmp->otyp != TOWEL))
  891. X#ifdef POLYSELF
  892. X        || (!strcmp(word, "eat") && !is_edible(otmp))
  893. X#endif
  894. X        || (!strcmp(word, "can") &&
  895. X            (otmp->otyp != CORPSE))
  896. X        || (!strcmp(word, "write with") &&
  897. X            (otmp->oclass == TOOL_CLASS &&
  898. X             otmp->otyp != MAGIC_MARKER && otmp->otyp != TOWEL))
  899. X        || (!strcmp(word, "rub") &&
  900. X            (otmp->oclass == TOOL_CLASS &&
  901. X             otmp->otyp != OIL_LAMP && otmp->otyp != MAGIC_LAMP &&
  902. X             otmp->otyp != BRASS_LANTERN))
  903. X        || (!strcmp(word, "wield") &&
  904. X            (otmp->oclass == TOOL_CLASS &&
  905. X             otmp->otyp != PICK_AXE && otmp->otyp != UNICORN_HORN))
  906. X            )
  907. X            foo--;
  908. X        } else {
  909. X
  910. X        /* "ugly check" for reading fortune cookies, part 2 */
  911. X        if ((!strcmp(word, "read") && otmp->otyp == FORTUNE_COOKIE))
  912. X            allowall = TRUE;
  913. X        }
  914. X
  915. X        if(ilet == 'z') ilet = 'A'; else ilet++;
  916. X    }
  917. X    bp[foo] = 0;
  918. X    if(foo == 0 && bp > buf && bp[-1] == ' ') *--bp = 0;
  919. X    Strcpy(lets, bp);    /* necessary since we destroy buf */
  920. X    if(foo > 5)            /* compactify string */
  921. X        compactify(bp);
  922. X
  923. X    if(!foo && !allowall && !allowgold && !allownone) {
  924. X        You("don't have anything %sto %s.",
  925. X            foox ? "else " : "", word);
  926. X        return((struct obj *)0);
  927. X    }
  928. X    for(;;) {
  929. X        cnt = 0;
  930. X        if (allowcnt == 2) allowcnt = 1;  /* abort previous count */
  931. X        if(!buf[0]) {
  932. X            Sprintf(qbuf, "What do you want to %s? [*]", word);
  933. X        } else {
  934. X            Sprintf(qbuf, "What do you want to %s? [%s or ?*]",
  935. X                word, buf);
  936. X        }
  937. X#ifdef REDO
  938. X        if(!in_doagain)
  939. X            ilet = yn_function(qbuf, NULL, '\0');
  940. X        else
  941. X#endif
  942. X            ilet = readchar();
  943. X        if(ilet == '0') prezero = TRUE;
  944. X        while(digit(ilet) && allowcnt) {
  945. X#ifdef REDO
  946. X            if (ilet != '?' && ilet != '*')    savech(ilet);
  947. X#endif
  948. X            cnt = 10*cnt + (ilet - '0');
  949. X            allowcnt = 2;    /* signal presence of cnt */
  950. X            ilet = readchar();
  951. X        }
  952. X        if(digit(ilet)) {
  953. X            pline("No count allowed with this command.");
  954. X            continue;
  955. X        }
  956. X        if(index(quitchars,ilet)) {
  957. X            if(flags.verbose)
  958. X            pline("Never mind.");
  959. X            return((struct obj *)0);
  960. X        }
  961. X        if(ilet == '-') {
  962. X            return(allownone ? &zeroobj : (struct obj *) 0);
  963. X        }
  964. X        if(ilet == def_oc_syms[GOLD_CLASS]) {
  965. X            if(!usegold){
  966. X                You("cannot %s gold.", word);
  967. X                return(struct obj *)0;
  968. X            } else if (!allowgold) {
  969. X                You("are not carrying any gold.");
  970. X                return(struct obj *)0;
  971. X            }
  972. X            if(cnt == 0 && prezero) return((struct obj *)0);
  973. X            /* Historic note: early Nethack had a bug which was
  974. X             * first reported for Larn, where trying to drop 2^32-n
  975. X             * gold pieces was allowed, and did interesting things
  976. X             * to your money supply.  The LRS is the tax bureau
  977. X             * from Larn.
  978. X             */
  979. X            if(cnt < 0) {
  980. X    pline("The LRS would be very interested to know you have that much.");
  981. X                return(struct obj *)0;
  982. X            }
  983. X
  984. X            if(!(allowcnt == 2 && cnt < u.ugold))
  985. X                cnt = u.ugold;
  986. X            return(mkgoldobj(cnt));
  987. X        }
  988. X        if(allowcnt == 2 && !strcmp(word,"throw")) {
  989. X            /* permit counts for throwing gold, but don't accept
  990. X             * counts for other things since the throw code will
  991. X             * split off a single item anyway */
  992. X            allowcnt = 1;
  993. X            if(cnt == 0 && prezero) return((struct obj *)0);
  994. X            if(cnt > 1) {
  995. X                You("can only throw one item at a time.");
  996. X                continue;
  997. X            }
  998. X        }
  999. X        if(ilet == '?' || ilet == '*') {
  1000. X            ilet = display_inventory(ilet == '?' ? lets : NULL, FALSE);
  1001. X            if(!ilet) continue;
  1002. X            if(ilet == '\033') {
  1003. X            if(flags.verbose)
  1004. X                pline("Never mind.");
  1005. X            return((struct obj *)0);
  1006. X            }
  1007. X            /* they typed a letter (not a space) at the prompt */
  1008. X        }
  1009. X#ifdef REDO
  1010. X        savech(ilet);
  1011. X#endif
  1012. X        if(flags.invlet_constant) {
  1013. X            for(otmp = invent; otmp; otmp = otmp->nobj)
  1014. X                if(otmp->invlet == ilet) break;
  1015. X        } else {
  1016. X            if(ilet >= 'A' && ilet <= 'Z') ilet += 'z' - 'A' + 1;
  1017. X            ilet -= 'a';
  1018. X            for(otmp = invent; otmp && ilet;
  1019. X                    ilet--, otmp = otmp->nobj) ;
  1020. X        }
  1021. X        if(!otmp) {
  1022. X            You("don't have that object.");
  1023. X            continue;
  1024. X        } else if (cnt < 0 || otmp->quan < cnt) {
  1025. X            You("don't have that many!  You have only %ld.",
  1026. X                otmp->quan);
  1027. X            continue;
  1028. X        }
  1029. X        break;
  1030. X    }
  1031. X    if(!allowall && let && !index(let,otmp->oclass)) {
  1032. X        pline(silly_thing_to, word);
  1033. X        return((struct obj *)0);
  1034. X    }
  1035. X    if(allowcnt == 2) {    /* cnt given */
  1036. X        if(cnt == 0) return (struct obj *)0;
  1037. X        if(cnt != otmp->quan) {
  1038. X            register struct obj *obj = splitobj(otmp, cnt);
  1039. X        /* Very ugly kludge necessary to prevent someone from trying
  1040. X         * to drop one of several loadstones and having the loadstone
  1041. X         * now be separate.
  1042. X         */
  1043. X            if (!strcmp(word, "drop") &&
  1044. X                obj->otyp == LOADSTONE && obj->cursed)
  1045. X                otmp->corpsenm = obj->invlet;
  1046. X            if(otmp == uwep) setuwep(obj);
  1047. X        }
  1048. X    }
  1049. X    return(otmp);
  1050. X}
  1051. X
  1052. X#endif /* OVL1 */
  1053. X#ifdef OVLB
  1054. X
  1055. XSTATIC_PTR int
  1056. Xckunpaid(otmp)
  1057. Xregister struct obj *otmp;
  1058. X{
  1059. X    return((int)(otmp->unpaid));
  1060. X}
  1061. X
  1062. Xstatic boolean
  1063. Xwearing_armor() {
  1064. X    return(uarm || uarmc || uarmf || uarmg || uarmh || uarms
  1065. X#ifdef TOURIST
  1066. X        || uarmu
  1067. X#endif
  1068. X        );
  1069. X}
  1070. X
  1071. Xstatic boolean
  1072. Xis_worn(otmp)
  1073. Xregister struct obj *otmp;
  1074. X{
  1075. X    return(!!(otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL | W_WEP)));
  1076. X}
  1077. X
  1078. Xstatic const char NEARDATA removeables[] =
  1079. X    { ARMOR_CLASS, WEAPON_CLASS, RING_CLASS, AMULET_CLASS, TOOL_CLASS, 0 };
  1080. X
  1081. X/* interactive version of getobj - used for Drop, Identify and */
  1082. X/* Takeoff (A). Return the number of times fn was called successfully */
  1083. Xint
  1084. Xggetobj(word, fn, mx)
  1085. Xregister const char *word;
  1086. Xregister int FDECL((*fn),(OBJ_P)), mx;
  1087. X{
  1088. X    char buf[BUFSZ], qbuf[QBUFSZ];
  1089. X    register char *ip;
  1090. X    register char sym;
  1091. X    register int oletct = 0, iletct = 0;
  1092. X    register boolean allflag = FALSE;
  1093. X    char olets[20], ilets[20];
  1094. X    int FDECL((*ckfn),(OBJ_P)) = (int (*)()) 0;
  1095. X    xchar allowgold = (u.ugold && !strcmp(word, "drop")) ? 1 : 0; /* BAH */
  1096. X    register boolean takeoff = !strcmp(word, "take off");
  1097. X    struct obj *obj;
  1098. X    int unpaid, oc_of_sym;
  1099. X
  1100. X    if(takeoff && !wearing_armor() && !uwep && !uamul &&
  1101. X            !uleft && !uright && !ublindf) {
  1102. X        You("are not wearing anything.");
  1103. X        return(0);
  1104. X    }
  1105. X    if(!invent && !allowgold){
  1106. X        You("have nothing to %s.", word);
  1107. X        return(0);
  1108. X    }
  1109. X
  1110. X    if (allowgold) ilets[iletct++] = def_oc_syms[GOLD_CLASS];
  1111. X    ilets[iletct] = '\0';    /* terminate for index() */
  1112. X    unpaid = 0;
  1113. X    for (obj = invent; obj; obj = obj->nobj) {
  1114. X        sym = (char) def_oc_syms[(int) obj->oclass];
  1115. X        if (!index(ilets, sym) && (!takeoff || is_worn(obj))) {
  1116. X            ilets[iletct++] = sym;
  1117. X            /* necessary because of index() being used above */
  1118. X            ilets[iletct] = '\0';
  1119. X        }
  1120. X
  1121. X        if (obj->unpaid) unpaid = 1;
  1122. X    }
  1123. X
  1124. X    if (!takeoff && (unpaid || invent)) {
  1125. X        ilets[iletct++] = ' ';
  1126. X        if (unpaid) ilets[iletct++] = 'u';
  1127. X        if (invent) ilets[iletct++] = 'a';
  1128. X    }
  1129. X    ilets[iletct] = '\0';    /* outside the if to catch iletct==0 case */
  1130. X
  1131. X    Sprintf(qbuf,"What kinds of thing do you want to %s? [%s]",
  1132. X        word, ilets);
  1133. X    getlin(qbuf, buf);
  1134. X    if(buf[0] == '\033') {
  1135. X        clear_nhwindow(WIN_MESSAGE);
  1136. X        return(0);
  1137. X    }
  1138. X    ip = buf;
  1139. X    olets[0] = 0;
  1140. X    while ((sym = *ip++) != 0) {
  1141. X        if(sym == ' ') continue;
  1142. X        oc_of_sym = def_char_to_objclass(sym);
  1143. X        if(takeoff && !(uwep && oc_of_sym == uwep->oclass)
  1144. X           && (oc_of_sym != MAXOCLASSES)) {
  1145. X            if(!index(removeables,oc_of_sym)) {
  1146. X            pline("Not applicable.");
  1147. X            return(0);
  1148. X            } else if(oc_of_sym == ARMOR_CLASS && !wearing_armor()) {
  1149. X            You("are not wearing any armor.");
  1150. X            return(0);
  1151. X            } else if(oc_of_sym == WEAPON_CLASS && !uwep) {
  1152. X            You("are not wielding anything.");
  1153. X            return(0);
  1154. X            } else if(oc_of_sym == RING_CLASS && !uright && !uleft) {
  1155. X            You("are not wearing rings.");
  1156. X            return(0);
  1157. X            } else if(oc_of_sym == AMULET_CLASS && !uamul) {
  1158. X            You("are not wearing an amulet.");
  1159. X            return(0);
  1160. X            } else if(oc_of_sym == TOOL_CLASS && !ublindf) {
  1161. X            You("are not wearing a blindfold.");
  1162. X            return(0);
  1163. X            }
  1164. X        }
  1165. X        if(oc_of_sym == GOLD_CLASS) {
  1166. X            if(allowgold == 1)
  1167. X                (*fn)(mkgoldobj(u.ugold));
  1168. X            else if(!u.ugold)
  1169. X                You("have no gold.");
  1170. X            allowgold = 2;
  1171. X        } else if(sym == 'a' || sym == 'A')
  1172. X            allflag = TRUE;
  1173. X        else if(sym == 'u' || sym == 'U')
  1174. X            ckfn = ckunpaid;
  1175. X        else if (oc_of_sym == MAXOCLASSES)
  1176. X            You("don't have any %c's.", sym);
  1177. X        else if (oc_of_sym != VENOM_CLASS) {/* venom doesn't show up */
  1178. X            if (!index(olets, oc_of_sym)) {
  1179. X                olets[oletct++] = oc_of_sym;
  1180. X                olets[oletct] = 0;
  1181. X            }
  1182. X        }
  1183. X    }
  1184. X    if(allowgold == 2 && !oletct)
  1185. X        return 1;    /* you dropped gold (or at least tried to) */
  1186. X    else
  1187. X        return askchain((struct obj **)&invent, olets, allflag,
  1188. X                fn, ckfn, mx, word);
  1189. X}
  1190. X
  1191. X/*
  1192. X * Walk through the chain starting at objchn and ask for all objects
  1193. X * with olet in olets (if nonNULL) and satisfying ckfn (if nonNULL)
  1194. X * whether the action in question (i.e., fn) has to be performed.
  1195. X * If allflag then no questions are asked. Max gives the max nr of
  1196. X * objects to be treated. Return the number of objects treated.
  1197. X */
  1198. Xint
  1199. Xaskchain(objchn, olets, allflag, fn, ckfn, mx, word)
  1200. Xstruct obj **objchn;
  1201. Xregister int allflag, mx;
  1202. Xregister const char *olets, *word;    /* olets is an Obj Class char array */
  1203. Xregister int FDECL((*fn),(OBJ_P)), FDECL((*ckfn),(OBJ_P));
  1204. X{
  1205. X    register struct obj *otmp, *otmp2;
  1206. X    register char sym, ilet;
  1207. X    register int cnt = 0, dud = 0, tmp;
  1208. X    boolean takeoff, nodot, ident, ininv;
  1209. X    char qbuf[QBUFSZ];
  1210. X
  1211. X    takeoff = !strcmp(word, "take off");
  1212. X    ident = !strcmp(word, "identify");
  1213. X    nodot = (!strcmp(word, "nodot") || !strcmp(word, "drop") ||
  1214. X         ident || takeoff);
  1215. X    ininv = (*objchn == invent);
  1216. X    /* Changed so the askchain is interrogated in the order specified.
  1217. X     * For example, if a person specifies =/ then first all rings will be
  1218. X     * asked about followed by all wands -dgk
  1219. X     */
  1220. Xnextclass:
  1221. X    ilet = 'a'-1;
  1222. X    if ((*objchn)->otyp == GOLD_PIECE) ilet--;    /* extra iteration */
  1223. X    for (otmp = *objchn; otmp; otmp = otmp2) {
  1224. X        if(ilet == 'z') ilet = 'A'; else ilet++;
  1225. X        otmp2 = otmp->nobj;
  1226. X        if (olets && *olets && otmp->oclass != *olets) continue;
  1227. X        if(takeoff && !is_worn(otmp)) continue;
  1228. X        if(ckfn && !(*ckfn)(otmp)) continue;
  1229. X        if(!allflag) {
  1230. X            Strcpy(qbuf, ininv ?
  1231. X                xprname(otmp, ilet, !nodot, 0L) : doname(otmp));
  1232. X            Strcat(qbuf, "?");
  1233. X            sym = (takeoff || ident || otmp->quan < 2L) ?
  1234. X                nyaq(qbuf) : nyNaq(qbuf);
  1235. X        }
  1236. X        else    sym = 'y';
  1237. X
  1238. X        if (sym == '#') {
  1239. X         /* Number was entered; split the object unless it corresponds
  1240. X            to 'none' or 'all'.  2 special cases: cursed loadstones and
  1241. X            welded weapons (eg, multiple daggers) will remain as merged
  1242. X            unit; done to avoid splitting an object that won't be
  1243. X            droppable (even if we're picking up rather than dropping).
  1244. X          */
  1245. X            if (!yn_number)
  1246. X            sym = 'n';
  1247. X            else {
  1248. X            sym = 'y';
  1249. X            if (yn_number < otmp->quan && !welded(otmp) &&
  1250. X                (!otmp->cursed || otmp->otyp != LOADSTONE)) {
  1251. X                struct obj *otmpx = splitobj(otmp, yn_number);
  1252. X                if (!otmpx || otmpx->nobj != otmp2)
  1253. X                impossible("bad object split in askchain");
  1254. X            }
  1255. X            }
  1256. X        }
  1257. X        switch(sym){
  1258. X        case 'a':
  1259. X            allflag = 1;
  1260. X        case 'y':
  1261. X            tmp = (*fn)(otmp);
  1262. X            if(tmp < 0) goto ret;
  1263. X            cnt += tmp;
  1264. X            if(--mx == 0) goto ret;
  1265. X        case 'n':
  1266. X            if(nodot) dud++;
  1267. X        default:
  1268. X            break;
  1269. X        case 'q':
  1270. X            goto ret;
  1271. X        }
  1272. X    }
  1273. X    if (olets && *olets && *++olets)
  1274. X        goto nextclass;
  1275. X    if(!takeoff && (dud || cnt)) pline("That was all.");
  1276. X    else if(!dud && !cnt) pline("No applicable objects.");
  1277. Xret:
  1278. X    return(cnt);
  1279. X}
  1280. X
  1281. X#endif /* OVLB */
  1282. X#ifdef OVL2
  1283. X
  1284. XSTATIC_OVL char
  1285. Xobj_to_let(obj)    /* should of course only be called for things in invent */
  1286. Xregister struct obj *obj;
  1287. X{
  1288. X    register struct obj *otmp;
  1289. X    register char ilet;
  1290. X
  1291. X    if (obj->otyp == GOLD_PIECE)
  1292. X        return GOLD_SYM;
  1293. X    else if (flags.invlet_constant)
  1294. X        return obj->invlet;
  1295. X    ilet = 'a';
  1296. X    for(otmp = invent; otmp && otmp != obj; otmp = otmp->nobj)
  1297. X        if(++ilet > 'z') ilet = 'A';
  1298. X    return(otmp ? ilet : NOINVSYM);
  1299. X}
  1300. X
  1301. X/*
  1302. X * Print the indicated quantity of the given object.  If quan == 0L then use
  1303. X * the current quantity.
  1304. X */
  1305. Xvoid
  1306. Xprinv(prefix, obj, quan)
  1307. Xconst char *prefix;
  1308. Xregister struct obj *obj;
  1309. Xlong quan;
  1310. X{
  1311. X#ifdef GCC_WARN
  1312. X    long savequan = 0;
  1313. X#else
  1314. X    long savequan;
  1315. X#endif
  1316. X    if ( !prefix ) prefix = "";
  1317. X    if (quan) {
  1318. X        savequan = obj->quan;
  1319. X        obj->quan = quan;
  1320. X    }
  1321. X    pline("%s%s%s",
  1322. X          prefix, *prefix ? " " : "",
  1323. X          xprname(obj, obj_to_let(obj), TRUE, 0L));
  1324. X    if (quan) obj->quan = savequan;
  1325. X}
  1326. X
  1327. X#endif /* OVL2 */
  1328. X#ifdef OVL1
  1329. X
  1330. Xchar *
  1331. Xxprname(obj,let,dot,cost)
  1332. Xregister struct obj *obj;
  1333. Xregister char let;
  1334. Xregister boolean dot;   /* append period; (dot && cost => Iu) */
  1335. Xregister long cost;     /* cost (for inventory of unpaid or expended items) */
  1336. X{
  1337. X#ifdef LINT    /* handle static char li[BUFSZ]; */
  1338. X    char li[BUFSZ];
  1339. X#else
  1340. X    static char li[BUFSZ];
  1341. X#endif
  1342. X    boolean use_invlet = flags.invlet_constant && let != CONTAINED_SYM;
  1343. X    /*
  1344. X     * If let is:
  1345. X     *    *  Then obj == NULL and we are printing a total amount.
  1346. X     *    >  Then the object is contained and doesn't have an inventory letter.
  1347. X     */
  1348. X    if (cost != 0 || let == '*') {
  1349. X    /* if dot is true, we're doing Iu, otherwise Ix */
  1350. X    Sprintf(li, "%c - %-45s %6ld zorkmid%s",
  1351. X        (dot && use_invlet ? obj->invlet : let),
  1352. X        (let != '*' ? doname(obj) : "Total:"), cost, plur(cost));
  1353. X    } else if (obj->otyp == GOLD_PIECE) {
  1354. X    Sprintf(li, "%ld gold piece%s%s", obj->quan, plur(obj->quan),
  1355. X        (dot ? "." : ""));
  1356. X    } else {
  1357. X    /* ordinary inventory display or pickup message */
  1358. X    Sprintf(li, "%c - %s",
  1359. X        (use_invlet ? obj->invlet : let),
  1360. X        doname(obj));
  1361. X    if(dot) Strcat(li,".");
  1362. X    }
  1363. X    return li;
  1364. X}
  1365. X
  1366. X#endif /* OVL1 */
  1367. X#ifdef OVLB
  1368. X
  1369. Xint
  1370. Xddoinv()
  1371. X{
  1372. X    (void) display_inventory(NULL, FALSE);
  1373. X    return 0;
  1374. X}
  1375. X
  1376. X/*
  1377. X *  find_unpaid()
  1378. X *
  1379. X *  Scan the given list of objects.  If last_found is NULL, return the first
  1380. X *  unpaid object found.  If last_found is not NULL, then skip over unpaid
  1381. X *  objects until last_found is reached, then set last_found to NULL so the
  1382. X *  next unpaid object is returned.  This routine recursively follows
  1383. X *  containers.
  1384. X */
  1385. Xstatic struct obj *
  1386. Xfind_unpaid(list, last_found)
  1387. X    struct obj *list, **last_found;
  1388. X{
  1389. X    struct obj *obj;
  1390. X
  1391. X    while (list) {
  1392. X    if (list->unpaid) {
  1393. X        if (*last_found) {
  1394. X        /* still looking for previous unpaid object */
  1395. X        if (list == *last_found)
  1396. X            *last_found = (struct obj *) 0;
  1397. X        } else
  1398. X        return (*last_found = list);
  1399. X    }
  1400. X    if (Is_container(list) && list->cobj) {
  1401. X        if ((obj = find_unpaid(list->cobj, last_found)) != 0)
  1402. X        return obj;
  1403. X    }
  1404. X    list = list->nobj;
  1405. X    }
  1406. X    return (struct obj *) 0;
  1407. X}
  1408. X
  1409. X/*
  1410. X *  If lets == NULL or "", list all objects in the inventory.  Otherwise,
  1411. X *  list all objects with object classes that match the order in lets.
  1412. X *  The last letter could possibly be a '>' which means list unpaid contained
  1413. X *  objects.
  1414. X *  Returns the letter identifier of a selected item, or 0 (nothing was
  1415. X *  selected), or '\033' (the menu was cancelled).
  1416. X */
  1417. Xchar
  1418. Xdisplay_inventory(lets,show_cost)
  1419. Xregister const char *lets;
  1420. Xboolean show_cost;
  1421. X{
  1422. X    register struct obj *otmp;
  1423. X    struct obj *z_obj;
  1424. X    register char ilet;
  1425. X    char *invlet = inv_order;
  1426. X    int classcount;
  1427. X#if defined(LINT) || defined(GCC_WARN)
  1428. X    int save_unpaid = 0;
  1429. X#else
  1430. X    int save_unpaid;
  1431. X#endif
  1432. X    long cost, totcost;
  1433. X    boolean do_containers = FALSE;
  1434. X
  1435. X    if(!invent){
  1436. X        pline("Not carrying anything.");
  1437. X        return 0;
  1438. X    }
  1439. X    if (lets != NULL) {
  1440. X        int ct = strlen(lets); /* count number of inventory slots to show */
  1441. X        /* If we've got unpaid items in containers, count all unpaid
  1442. X           objects.  At least one won't be in any inventory slot. */
  1443. X        do_containers = (ct && lets[ct-1] == CONTAINED_SYM);
  1444. X        if (do_containers && ct == 1) ct = count_unpaid(invent);
  1445. X        /* if only one item of interest, use pline instead of menus */
  1446. X        if (ct == 1) {
  1447. X        if (do_containers) {    /* single non-inventory object */
  1448. X            z_obj = (struct obj *) 0;
  1449. X            if ((otmp = find_unpaid(invent, &z_obj)) != 0)
  1450. X            pline(xprname(otmp, CONTAINED_SYM, TRUE,
  1451. X                     (show_cost ? unpaid_cost(otmp) : 0L)));
  1452. X            else
  1453. X            impossible(
  1454. X            "display_inventory: no singular unpaid contained objects");
  1455. X        } else {
  1456. X            for(otmp = invent; otmp; otmp = otmp->nobj) {
  1457. X            if (otmp->invlet == lets[0]) {
  1458. X                pline(xprname(otmp, lets[0], TRUE,
  1459. X                     (show_cost ? unpaid_cost(otmp) : 0L)));
  1460. X                break;
  1461. X            }
  1462. X            }
  1463. X        }
  1464. X        return 0;
  1465. X        }
  1466. X    }
  1467. X
  1468. X    start_menu(WIN_INVEN);
  1469. X    cost = totcost = 0;
  1470. Xnextclass:
  1471. X    classcount = 0;
  1472. X    ilet = 'a';
  1473. X    for(otmp = invent; otmp; otmp = otmp->nobj) {
  1474. X        if(flags.invlet_constant) ilet = otmp->invlet;
  1475. X        if(!lets || !*lets || index(lets, ilet)) {
  1476. X            if (!flags.sortpack || otmp->oclass == *invlet) {
  1477. X                if (flags.sortpack && !classcount) {
  1478. X                add_menu(WIN_INVEN, 0, ATR_INVERSE,
  1479. X                     let_to_name(*invlet, show_cost));
  1480. X                classcount++;
  1481. X                }
  1482. X                if (show_cost) {
  1483. X                totcost += cost = unpaid_cost(otmp);
  1484. X                /* suppress "(unpaid)" suffix */
  1485. X                save_unpaid = otmp->unpaid;
  1486. X                otmp->unpaid = 0;
  1487. X                }
  1488. X                add_menu(WIN_INVEN, ilet, 0,
  1489. X                     xprname(otmp, ilet, TRUE, cost));
  1490. X                if (show_cost)  otmp->unpaid = save_unpaid;
  1491. X            }
  1492. X        }
  1493. X        if(!flags.invlet_constant) if(++ilet > 'z') ilet = 'A';
  1494. X    }
  1495. X    if (flags.sortpack) {
  1496. X        if (*++invlet) goto nextclass;
  1497. X#ifdef WIZARD
  1498. X        if (--invlet != venom_inv) {
  1499. X            invlet = venom_inv;
  1500. X            goto nextclass;
  1501. X        }
  1502. X#endif
  1503. X    }
  1504. X
  1505. X    /* right now, we only do this for unpaid items, so always do cost */
  1506. X    if (do_containers) {
  1507. X        if (flags.sortpack) add_menu(WIN_INVEN, 0, ATR_INVERSE,
  1508. X                     let_to_name(CONTAINED_SYM, 1));
  1509. X        /*
  1510. X         *  Search through the container objects in the inventory for
  1511. X         *  unpaid items.  Note that we check each container, not
  1512. X         *  the invent list.  This is because the invent list could
  1513. X         *  have unpaid items that have been already listed.
  1514. X         */
  1515. X        for (otmp = invent; otmp; otmp = otmp->nobj) {
  1516. X        if (Is_container(otmp) && otmp->cobj) {
  1517. X            z_obj = (struct obj *) 0;    /* haven't found any */
  1518. X            while (find_unpaid(otmp->cobj, (struct obj **)&z_obj)) {
  1519. X            totcost += cost = unpaid_cost(z_obj);
  1520. X            save_unpaid = z_obj->unpaid;
  1521. X            z_obj->unpaid = 0;    /* suppress "(unpaid)" suffix */
  1522. X            add_menu(WIN_INVEN, 0, 0,
  1523. X                 xprname(z_obj, CONTAINED_SYM, TRUE, cost));
  1524. X            z_obj->unpaid = save_unpaid;
  1525. X            }
  1526. X        }
  1527. X        }
  1528. X    }
  1529. X
  1530. X    if (show_cost) {
  1531. X        /* give 'Totals' line */
  1532. X        add_menu(WIN_INVEN, 0, 0, "");
  1533. X        add_menu(WIN_INVEN, 0, 0,
  1534. X             xprname((struct obj *)0, '*', FALSE, totcost));
  1535. X    }
  1536. X    end_menu(WIN_INVEN, '\033', "\033 ", NULL);
  1537. X    return select_menu(WIN_INVEN);
  1538. X}
  1539. X
  1540. X/*
  1541. X *  Returns the number of unpaid items within the given list.  This includes
  1542. X *  contained objects.
  1543. X */
  1544. Xint
  1545. Xcount_unpaid(list)
  1546. X    struct obj *list;
  1547. X{
  1548. X    int count = 0;
  1549. X
  1550. X    while (list) {
  1551. X    if (list->unpaid) count++;
  1552. X    if (Is_container(list) && list->cobj)
  1553. X        count += count_unpaid(list->cobj);
  1554. X    list = list->nobj;
  1555. X    }
  1556. X    return count;
  1557. X}
  1558. X
  1559. Xint
  1560. Xdotypeinv()                /* free after Robert Viduya */
  1561. X/* Changed to one type only, so you don't have to type return */
  1562. X{
  1563. X    char c, ilet;
  1564. X    char stuff[BUFSZ];
  1565. X    register int stct;
  1566. X    register struct obj *otmp;
  1567. X    boolean billx = *u.ushops && doinvbill(0);
  1568. X    boolean do_unpd = FALSE;
  1569. X    int unpd, class;
  1570. X
  1571. X    if (!invent && !u.ugold && !billx) {
  1572. X        You("aren't carrying anything.");
  1573. X        return 0;
  1574. X    }
  1575. X
  1576. X    Strcpy(stuff, "What type of object do you want an inventory of? [");
  1577. X    /* collect a list of classes of objects carried, for use as a prompt */
  1578. X    stct = collect_obj_classes(eos(stuff), invent, FALSE, (u.ugold != 0));
  1579. X    unpd = count_unpaid(invent);
  1580. X    if(unpd) Strcat(stuff, "u");
  1581. X    if(billx) Strcat(stuff, "x");
  1582. X    Strcat(stuff, "]");
  1583. X
  1584. X    if(stct > 1) {
  1585. X      c = yn_function(stuff, NULL, '\0');
  1586. X#ifdef REDO
  1587. X        savech(c);
  1588. X#endif
  1589. X        if(c == '\0') {
  1590. X        clear_nhwindow(WIN_MESSAGE);
  1591. X        return 0;
  1592. X        }
  1593. X    } else
  1594. X        c = stuff[0];
  1595. X
  1596. X    if(c == 'x' || c == 'X') {
  1597. X        if(billx)
  1598. X        (void) doinvbill(1);
  1599. X        else
  1600. X        pline("No used-up objects on the shopping bill.");
  1601. X        return(0);
  1602. X    }
  1603. X
  1604. X    if (c == 'u' || c == 'U') {
  1605. X        if (!unpd) {
  1606. X        You("are not carrying any unpaid objects.");
  1607. X        return(0);
  1608. X        }
  1609. X        do_unpd = TRUE;
  1610. X    }
  1611. X
  1612. X    class = def_char_to_objclass(c);    /* change to object class */
  1613. X
  1614. X    if(class == GOLD_CLASS)
  1615. X        return(doprgold());
  1616. X
  1617. X    /* collect all items which match the selected objclass */
  1618. X    stct = 0;
  1619. X    ilet = 'a';
  1620. X    for (otmp = invent; otmp; otmp = otmp->nobj) {
  1621. X        if(flags.invlet_constant) ilet = otmp->invlet;
  1622. X        if (class == otmp->oclass || (do_unpd && otmp->unpaid)) {
  1623. X        stuff[stct++] = ilet;
  1624. X        --unpd;    /* decrement unpaid count */
  1625. X        }
  1626. X        if(!flags.invlet_constant) if(++ilet > 'z') ilet = 'A';
  1627. X    }
  1628. X    /* unpd is now the number of unpaid contained objects */
  1629. X    if (do_unpd && unpd)
  1630. X        stuff[stct++] = CONTAINED_SYM;    /* list contained unpaid items */
  1631. X
  1632. X    stuff[stct] = '\0';
  1633. X    if(stct == 0)
  1634. X        You("have no such objects.");
  1635. X    else
  1636. X        (void) display_inventory(stuff, do_unpd);
  1637. X
  1638. X    return(0);
  1639. X}
  1640. X
  1641. X/* look at what is here */
  1642. Xint
  1643. Xdolook()
  1644. X{
  1645. X    register struct obj *otmp, *otmp0;
  1646. X    struct trap *trap;
  1647. X    const char *verb = Blind ? "feel" : "see";
  1648. X    const char *dfeature = (char*) 0;
  1649. X    char fbuf[BUFSZ], fbuf2[BUFSZ];
  1650. X    int ct;
  1651. X    boolean no_article = FALSE;
  1652. X    winid tmpwin;
  1653. X
  1654. X    if(u.uswallow) {
  1655. X        You("%s no objects here.", verb);
  1656. X        return(!!Blind);
  1657. X    }
  1658. X    read_engr_at(u.ux, u.uy); /* Eric Backus */
  1659. X    if ((trap = t_at(u.ux,u.uy)) && trap->tseen)
  1660. X        pline("There is a%s here.", traps[trap->ttyp]);
  1661. X
  1662. X    otmp0 = level.objects[u.ux][u.uy];
  1663. X
  1664. X    if(IS_DOOR(levl[u.ux][u.uy].typ))  {
  1665. X        switch(levl[u.ux][u.uy].doormask) {
  1666. X            case D_NODOOR:
  1667. X            dfeature = "doorway"; break;
  1668. X            case D_ISOPEN:
  1669. X            dfeature = "open door"; break;
  1670. X            case D_BROKEN:
  1671. X            dfeature = "broken door"; break;
  1672. X            default:
  1673. X            dfeature = "closed door";
  1674. X        }
  1675. X    } else if(IS_FOUNTAIN(levl[u.ux][u.uy].typ))
  1676. X        /* added by GAN 10/30/86 */
  1677. X        dfeature = "fountain";
  1678. X    else if(IS_THRONE(levl[u.ux][u.uy].typ))
  1679. X        dfeature = "opulent throne";
  1680. X    else if(is_lava(u.ux,u.uy))
  1681. X        dfeature = "molten lava",  no_article = TRUE;
  1682. X    else if(is_ice(u.ux,u.uy))
  1683. X        dfeature = "ice",  no_article = TRUE;
  1684. X    else if(is_pool(u.ux,u.uy) && !Underwater)
  1685. X        dfeature = "pool of water";
  1686. X#ifdef SINKS
  1687. X    else if(IS_SINK(levl[u.ux][u.uy].typ))
  1688. X        dfeature = "kitchen sink";
  1689. X#endif
  1690. X    else if(IS_ALTAR(levl[u.ux][u.uy].typ))  {
  1691. X        Sprintf(fbuf2, "altar to %s (%s)",
  1692. X            a_gname(),
  1693. X            align_str(Amask2align(levl[u.ux][u.uy].altarmask
  1694. X                                & ~AM_SHRINE)));
  1695. X        dfeature = fbuf2;
  1696. X    } else if(u.ux == xupstair && u.uy == yupstair)
  1697. X        dfeature = "stairway up";
  1698. X    else if(u.ux == xdnstair && u.uy == ydnstair)
  1699. X        dfeature = "stairway down";
  1700. X    else if(u.ux == sstairs.sx && u.uy == sstairs.sy) {
  1701. X        if (sstairs.up)
  1702. X            dfeature = "stairway up";
  1703. X        else
  1704. X            dfeature = "stairway down";
  1705. X    } else if(u.ux == xupladder && u.uy == yupladder)
  1706. X        dfeature = "ladder up";
  1707. X    else if(u.ux == xdnladder && u.uy == ydnladder)
  1708. X        dfeature = "ladder down";
  1709. X    else if (levl[u.ux][u.uy].typ == DRAWBRIDGE_DOWN)
  1710. X        dfeature = "lowered drawbridge";
  1711. X
  1712. X    if (Blind) {
  1713. X        You("try to feel what is %s.",
  1714. X            Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) ?
  1715. X            "floating here" :
  1716. X            "lying here on the floor");
  1717. X         if (Levitation &&
  1718. X            !Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz)) {
  1719. X            pline("But you can't reach it!");
  1720. X            return(0);
  1721. X         }
  1722. X    }
  1723. X
  1724. X    if (dfeature)
  1725. X        Sprintf(fbuf, "There is %s%s here.",
  1726. X            no_article ? "" :
  1727. X                index(vowels,dfeature[0]) ? "an " : "a ",
  1728. X            dfeature);
  1729. X
  1730. X    if(!otmp0 || (is_pool(u.ux,u.uy) && !Underwater)) {
  1731. X            if(dfeature) pline(fbuf);
  1732. X        if(Blind || !dfeature)
  1733. X            You("%s no objects here.", verb);
  1734. X        return(!!Blind);
  1735. X    }
  1736. X    /* we know there is something here */
  1737. X
  1738. X    /* find out if there is more than one object there */
  1739. X    for (ct = 0, otmp = otmp0; otmp; otmp = otmp->nexthere)
  1740. X        if (++ct > 1) break;
  1741. X
  1742. X    if (ct == 1) {
  1743. X        if (dfeature) pline(fbuf);
  1744. X        You("%s here %s.", verb, doname(otmp0));
  1745. X    } else {
  1746. X        display_nhwindow(NHW_MESSAGE, FALSE);
  1747. X        tmpwin = create_nhwindow(NHW_MENU);
  1748. X        if(dfeature) {
  1749. X        putstr(tmpwin, 0, fbuf);
  1750. X        putstr(tmpwin, 0, "");
  1751. X        }
  1752. X        putstr(tmpwin, 0, "Things that are here:");
  1753. X        for(otmp = otmp0; otmp; otmp = otmp->nexthere) {
  1754. X        putstr(tmpwin, 0, doname(otmp));
  1755. X
  1756. X        if(Blind  && !uarmg &&
  1757. X#ifdef POLYSELF
  1758. X                !resists_ston(uasmon) &&
  1759. X#endif
  1760. X                (otmp->otyp == CORPSE &&
  1761. X                    otmp->corpsenm == PM_COCKATRICE)) {
  1762. X#if defined(POLYSELF)
  1763. X            if(poly_when_stoned(uasmon)) {
  1764. X            You("touched the cockatrice corpse with your bare hands.");
  1765. X            (void) polymon(PM_STONE_GOLEM);
  1766. X            } else
  1767. X#endif
  1768. X            {
  1769. X            pline("Touching the cockatrice corpse is a fatal mistake...");
  1770. X            You("turn to stone...");
  1771. X            killer_format = KILLED_BY_AN;
  1772. X            killer = "cockatrice corpse";
  1773. X            done(STONING);
  1774. X            }
  1775. X        }
  1776. X        }
  1777. X        display_nhwindow(tmpwin, TRUE);
  1778. X        destroy_nhwindow(tmpwin);
  1779. X    }
  1780. X    return(!!Blind);
  1781. X}
  1782. X
  1783. X#endif /* OVLB */
  1784. X#ifdef OVL1
  1785. X
  1786. Xvoid
  1787. Xstackobj(obj)
  1788. Xregister struct obj *obj;
  1789. X{
  1790. X    register struct obj *otmp;
  1791. X
  1792. X    for(otmp = level.objects[obj->ox][obj->oy]; otmp; otmp = otmp->nexthere)
  1793. X        if(otmp != obj && merged(obj,otmp,1))
  1794. X            break;
  1795. X    return;
  1796. X}
  1797. X
  1798. Xstatic boolean
  1799. Xmergable(otmp, obj)    /* returns TRUE if obj  & otmp can be merged */
  1800. X    register struct obj *otmp, *obj;
  1801. X{
  1802. X    if(obj->otyp != otmp->otyp || obj->unpaid != otmp->unpaid ||
  1803. X       obj->spe != otmp->spe || obj->dknown != otmp->dknown ||
  1804. X       (obj->bknown != otmp->bknown && pl_character[0] != 'P') ||
  1805. X       obj->cursed != otmp->cursed || obj->blessed != otmp->blessed ||
  1806. X       obj->no_charge != otmp->no_charge ||
  1807. X       obj->obroken != otmp->obroken ||
  1808. X       obj->otrapped != otmp->otrapped ||
  1809. X       obj->oeroded != otmp->oeroded)
  1810. X        return(FALSE);
  1811. X
  1812. X    if((obj->oclass==WEAPON_CLASS || obj->oclass==ARMOR_CLASS) &&
  1813. X       (obj->oerodeproof!=otmp->oerodeproof || obj->rknown!=otmp->rknown))
  1814. X        return FALSE;
  1815. X
  1816. X    if(obj->oclass == FOOD_CLASS && (obj->oeaten != otmp->oeaten ||
  1817. X        obj->orotten != otmp->orotten))
  1818. X        return(FALSE);
  1819. X
  1820. X    if(obj->otyp == CORPSE || obj->otyp == EGG || obj->otyp == TIN) {
  1821. X        if((obj->corpsenm != otmp->corpsenm) ||
  1822. X            (ONAME(obj) && strcmp(ONAME(obj), ONAME(otmp))))
  1823. X                return FALSE;
  1824. X    }
  1825. X
  1826. X/* if they have names, make sure they're the same */
  1827. X    if ( (obj->onamelth != otmp->onamelth &&
  1828. X        ((obj->onamelth && otmp->onamelth) || obj->otyp == CORPSE)
  1829. X         ) ||
  1830. X        (obj->onamelth &&
  1831. X            strncmp(ONAME(obj), ONAME(otmp), (int)obj->onamelth)))
  1832. X        return FALSE;
  1833. X
  1834. X    if(obj->oartifact != otmp->oartifact) return FALSE;
  1835. X
  1836. X    if(obj->known == otmp->known ||
  1837. X        !objects[otmp->otyp].oc_uses_known) {
  1838. X        return(objects[obj->otyp].oc_merge);
  1839. X    } else return(FALSE);
  1840. X}
  1841. X
  1842. X#endif /* OVL1 */
  1843. X#ifdef OVLB
  1844. X
  1845. Xint
  1846. Xdoprgold(){
  1847. X    if(!u.ugold)
  1848. X        You("do not carry any gold.");
  1849. X    else
  1850. X        You("are carrying %ld gold piece%s.", u.ugold, plur(u.ugold));
  1851. X    return 0;
  1852. X}
  1853. X
  1854. Xint
  1855. Xdoprwep()
  1856. X{
  1857. X    if(!uwep) You("are empty %s.", body_part(HANDED));
  1858. X    else prinv(NULL, uwep, 0L);
  1859. X    return 0;
  1860. X}
  1861. X
  1862. Xint
  1863. Xdoprarm(){
  1864. X    if(!wearing_armor())
  1865. X        You("are not wearing any armor.");
  1866. X    else {
  1867. X#ifdef TOURIST
  1868. X        char lets[8];
  1869. X#else
  1870. X        char lets[7];
  1871. X#endif
  1872. X        register int ct = 0;
  1873. X
  1874. X#ifdef TOURIST
  1875. X        if(uarmu) lets[ct++] = obj_to_let(uarmu);
  1876. X#endif
  1877. X        if(uarm) lets[ct++] = obj_to_let(uarm);
  1878. X        if(uarmc) lets[ct++] = obj_to_let(uarmc);
  1879. X        if(uarmh) lets[ct++] = obj_to_let(uarmh);
  1880. X        if(uarms) lets[ct++] = obj_to_let(uarms);
  1881. X        if(uarmg) lets[ct++] = obj_to_let(uarmg);
  1882. X        if(uarmf) lets[ct++] = obj_to_let(uarmf);
  1883. X        lets[ct] = 0;
  1884. X        (void) display_inventory(lets, FALSE);
  1885. X    }
  1886. X    return 0;
  1887. X}
  1888. X
  1889. Xint
  1890. Xdoprring(){
  1891. X    if(!uleft && !uright)
  1892. X        You("are not wearing any rings.");
  1893. X    else {
  1894. X        char lets[3];
  1895. X        register int ct = 0;
  1896. X
  1897. X        if(uleft) lets[ct++] = obj_to_let(uleft);
  1898. X        if(uright) lets[ct++] = obj_to_let(uright);
  1899. X        lets[ct] = 0;
  1900. X        (void) display_inventory(lets, FALSE);
  1901. X    }
  1902. X    return 0;
  1903. X}
  1904. X
  1905. Xint
  1906. Xdopramulet(){
  1907. X    if (!uamul)
  1908. X        You("are not wearing an amulet.");
  1909. X    else
  1910. X        prinv(NULL, uamul, 0L);
  1911. X    return 0;
  1912. X}
  1913. X
  1914. Xint
  1915. Xdoprtool(){
  1916. X    register struct obj *otmp;
  1917. X    register int ct=0;
  1918. X    char lets[3]; /* Maximum: pick-axe, blindfold */
  1919. X
  1920. X    for(otmp = invent; otmp; otmp = otmp->nobj) {
  1921. X        if (((otmp->owornmask & W_TOOL) && otmp->oclass==TOOL_CLASS)
  1922. X           || (otmp==uwep &&
  1923. X           (otmp->otyp==PICK_AXE || otmp->otyp==TIN_OPENER)))
  1924. X            lets[ct++] = obj_to_let(otmp);
  1925. X    }
  1926. X    lets[ct] = 0;
  1927. X    if (!ct) You("are not using any tools.");
  1928. X    else (void) display_inventory(lets, FALSE);
  1929. X    return 0;
  1930. X}
  1931. X
  1932. X/*
  1933. X * uses up an object that's on the floor, charging for it as necessary
  1934. X */
  1935. Xvoid
  1936. Xuseupf(obj)
  1937. Xregister struct obj *obj;
  1938. X{
  1939. X    register struct obj *otmp;
  1940. X
  1941. X    /* burn_floor_paper() keeps an object pointer that it tries to
  1942. X     * useupf() multiple times, so obj must survive if plural */
  1943. X    if(obj->quan > 1L)
  1944. X        otmp = splitobj(obj, obj->quan - 1L);
  1945. X    else
  1946. X        otmp = obj;
  1947. X    if(costly_spot(otmp->ox, otmp->oy)) {
  1948. X        if(index(u.urooms, *in_rooms(otmp->ox, otmp->oy, 0)))
  1949. X            addtobill(otmp, FALSE, FALSE, FALSE);
  1950. X        else (void)stolen_value(otmp, otmp->ox, otmp->oy, FALSE, FALSE);
  1951. X    }
  1952. X    delobj(otmp);
  1953. X}
  1954. X
  1955. X#endif /* OVLB */
  1956. X#ifdef OVL1
  1957. X
  1958. Xextern const char obj_symbols[];    /* o_init.c */
  1959. X/*
  1960. X * Conversion from a symbol to a string for printing object classes.
  1961. X * This must match the array obj_symbols[].
  1962. X */
  1963. Xstatic const char NEARDATA *names[] = {
  1964. X    "Illegal objects", "Amulets", "Coins", "Comestibles", "Weapons",
  1965. X    "Tools", "Iron balls", "Chains", "Boulders/Statues", "Armor",
  1966. X    "Potions", "Scrolls", "Wands", "Spellbooks", "Rings", "Gems"
  1967. X};
  1968. X
  1969. Xstatic const char NEARDATA oth_symbols[] = {
  1970. X#ifdef WIZARD
  1971. X    VENOM_CLASS,
  1972. X#endif
  1973. X    CONTAINED_SYM,
  1974. X    '\0'
  1975. X};
  1976. X
  1977. Xstatic const char NEARDATA *oth_names[] = {
  1978. X#ifdef WIZARD
  1979. X    "Venoms",
  1980. X#endif
  1981. X    "Bagged/Boxed items"
  1982. X};
  1983. X
  1984. Xchar *
  1985. Xlet_to_name(let,unpaid)
  1986. Xchar let;
  1987. Xboolean unpaid;
  1988. X{
  1989. X    const char *class_name;
  1990. X    const char *pos = index(obj_symbols, let);
  1991. X    int len;
  1992. X    static char NEARDATA *buf = NULL;
  1993. X    static unsigned NEARDATA bufsiz = 0;
  1994. X
  1995. X    if (pos)
  1996. X        class_name = names[pos - obj_symbols];
  1997. X    else if ((pos = index(oth_symbols, let)) != 0)
  1998. X        class_name = oth_names[pos - oth_symbols];
  1999. X    else
  2000. X        class_name = names[0];
  2001. X
  2002. X    len = strlen(class_name)
  2003. X         + (unpaid ? sizeof("unpaid_") : 1);    /* count terminating NUL */
  2004. X    if (len > bufsiz) {
  2005. X        if (buf)  free((genericptr_t)buf),  buf = NULL;
  2006. X        bufsiz = len + 10; /* add slop to avoid incremental reallocations */
  2007. X        buf = (char *) alloc(bufsiz);
  2008. X    }
  2009. X    if (unpaid)
  2010. X        Strcat(strcpy(buf, "Unpaid "), class_name);
  2011. X    else
  2012. X        Strcpy(buf, class_name);
  2013. X    return (buf);
  2014. X}
  2015. X
  2016. X#endif /* OVL1 */
  2017. X#ifdef OVLB 
  2018. X
  2019. Xvoid
  2020. Xreassign()
  2021. X{
  2022. X    register int i;
  2023. X    register struct obj *obj;
  2024. X
  2025. X    for(obj = invent, i = 0; obj; obj = obj->nobj, i++)
  2026. X        obj->invlet = (i < 26) ? ('a'+i) : ('A'+i-26);
  2027. X    lastinvnr = i;
  2028. X}
  2029. X
  2030. X#endif /* OVLB */
  2031. X#ifdef OVL1
  2032. Xint
  2033. Xdoorganize()    /* inventory organizer by Del Lamb */
  2034. X{
  2035. X    register struct obj *obj, *otmp;
  2036. X    register int ix, cur;
  2037. X    register char let;
  2038. X    char alphabet[52+1], buf[52+1];
  2039. X    char qbuf[QBUFSZ];
  2040. X    char allow_all[2];
  2041. X    const char *adj_type;
  2042. X
  2043. X    /* check to see if the inventory is of the fixed kind */
  2044. X    if (!flags.invlet_constant ) {
  2045. X        pline("Sorry, only fixed inventories can be adjusted.");
  2046. X        return(0);
  2047. X    }
  2048. X#if 0
  2049. X    /* check to see if the inventory has any gaps left in it */
  2050. X    if (inv_cnt() >= 52) {
  2051. X        pline("Sorry, no available letters for adjustment.");
  2052. X        return(0);
  2053. X    }
  2054. X#endif
  2055. X    /* get a pointer to the object the user wants to organize */
  2056. X    allow_all[0] = ALL_CLASSES; allow_all[1] = '\0';
  2057. X    if (!(obj = getobj(allow_all,"adjust"))) return(0);
  2058. X
  2059. X    /* initialize the list with all upper and lower case letters */
  2060. X    for (let = 'a', ix = 0;  let <= 'z';) alphabet[ix++] = let++;
  2061. X    for (let = 'A', ix = 26; let <= 'Z';) alphabet[ix++] = let++;
  2062. X    alphabet[52] = 0;
  2063. X
  2064. X    /* blank out all the letters currently in use in the inventory */
  2065. X    /* except those that will be merged with the selected object   */
  2066. X    for (otmp = invent; otmp; otmp = otmp->nobj)
  2067. X        if (otmp != obj && !mergable(otmp,obj))
  2068. X            if (otmp->invlet <= 'Z')
  2069. X                alphabet[(otmp->invlet) - 'A' + 26] = ' ';
  2070. X            else    alphabet[(otmp->invlet) - 'a']        = ' ';
  2071. X
  2072. X    /* compact the list by removing all the blanks */
  2073. X    for (ix = cur = 0; ix <= 52; ix++)
  2074. X        if (alphabet[ix] != ' ') buf[cur++] = alphabet[ix];
  2075. X
  2076. X    /* and by dashing runs of letters */
  2077. X    if(cur > 5) compactify(buf);
  2078. X
  2079. X    /* get new letter to use as inventory letter */
  2080. X    for (;;) {
  2081. X        Sprintf(qbuf, "Adjust letter to what [%s]?",buf);
  2082. X        let = yn_function(qbuf, NULL, '\0');
  2083. X        if(index(quitchars,let)) {
  2084. X            pline("Never mind.");
  2085. X            return(0);
  2086. X        }
  2087. X        if (let == '@' || !letter(let))
  2088. X            pline("Select an inventory slot letter.");
  2089. X        else
  2090. X            break;
  2091. X    }
  2092. X
  2093. X    /* change the inventory and print the resulting item */
  2094. X    adj_type = "Moving:";
  2095. X
  2096. X    /*
  2097. X     * don't use freeinv/addinv to avoid double-touching artifacts,
  2098. X     * dousing lamps, losing luck, cursing loadstone, etc.
  2099. X     */
  2100. X    unlinkinv(obj);
  2101. X
  2102. X    for (otmp = invent; otmp;)
  2103. X        if (merged(otmp,obj,0)) {
  2104. X            adj_type = "Merging:";
  2105. X            obj = otmp;
  2106. X            otmp = otmp->nobj;
  2107. X            unlinkinv(obj);
  2108. X        } else {
  2109. X            if (otmp->invlet == let) {
  2110. X                adj_type = "Swapping:";
  2111. X                otmp->invlet = obj->invlet;
  2112. X            }
  2113. X            otmp = otmp->nobj;
  2114. X        }
  2115. X
  2116. X    /* inline addinv (assuming flags.invlet_constant and !merged) */
  2117. X    obj->invlet = let;
  2118. X    obj->nobj = invent; /* insert at beginning */
  2119. X    invent = obj;
  2120. X    reorder_invent();
  2121. X
  2122. X    prinv(adj_type, obj, 0L);
  2123. X    update_inventory();
  2124. X    return(0);
  2125. X}
  2126. X
  2127. X#endif /* OVL1 */
  2128. X
  2129. X/*invent.c*/
  2130. END_OF_FILE
  2131. if test 47145 -ne `wc -c <'src/invent.c'`; then
  2132.     echo shar: \"'src/invent.c'\" unpacked with wrong size!
  2133. fi
  2134. # end of 'src/invent.c'
  2135. fi
  2136. echo shar: End of archive 13 \(of 108\).
  2137. cp /dev/null ark13isdone
  2138. MISSING=""
  2139. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
  2140. 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
  2141. 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
  2142. 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \
  2143. 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \
  2144. 101 102 103 104 105 106 107 108 ; do
  2145.     if test ! -f ark${I}isdone ; then
  2146.     MISSING="${MISSING} ${I}"
  2147.     fi
  2148. done
  2149. if test "${MISSING}" = "" ; then
  2150.     echo You have unpacked all 108 archives.
  2151.     echo "Now execute 'rebuild.sh'"
  2152.     rm -f ark10[0-8]isdone ark[1-9]isdone ark[1-9][0-9]isdone
  2153. else
  2154.     echo You still need to unpack the following archives:
  2155.     echo "        " ${MISSING}
  2156. fi
  2157. ##  End of shell archive.
  2158. exit 0
  2159.