]> granicus.if.org Git - nethack/commitdiff
GOLDOBJ pickup handling (trunk only)
authornethack.rankin <nethack.rankin>
Sat, 16 Jun 2007 02:22:01 +0000 (02:22 +0000)
committernethack.rankin <nethack.rankin>
Sat, 16 Jun 2007 02:22:01 +0000 (02:22 +0000)
     For GOLDOBJ configuration, relax the 52 object limit for inventory
when gold uses the special $ slot instead of a letter.  Takes care of an
old buglist entry from the beta testers.  [It will need to be revisited
if we ever implement multiple coin types that can't all fit in one slot.]

     Also for GOLDOBJ, prevents nymphs and monkeys from stealing coins,
since allowing that made their steal-item attack be a complete superset
of leprechaun's steal-gold attack.

doc/fixes35.0
include/extern.h
src/eat.c
src/hack.c
src/invent.c
src/pickup.c
src/shk.c
src/steal.c
src/trap.c
src/uhitm.c

index 9247a412db69108dddfd9a162117d7cef4ba89c9..671f97c9c69bca8248cee36bdc43d46491b6c8f3 100644 (file)
@@ -31,6 +31,8 @@ internals: use Is_box rather than explicitly checking what it checks
 fix some unreachable messages (either make then reachable or remove them)
 can quiver coins when GOLDOBJ is defined
 make #loot behave same for GOLDOBJ as for !GOLDOBJ
+for GOLDOBJ, can pick gold up into $ when all 52 letters are in use, and
+       can pick non-gold up into unused letter when gold uses one of 52 slots
 grammar, spelling and other typos
 keep various delayed killers separate to avoid mixed up messages
 don't place randomly-placed aquatic monsters in lava on special levels
index 2989822d649096b97b965140565dc5139da6d2f1..aa2e50f84af1edfc1226a13898fa11c6acd09d0c 100644 (file)
@@ -798,7 +798,7 @@ E int NDECL(near_capacity);
 E int FDECL(calc_capacity, (int));
 E int NDECL(max_capacity);
 E boolean FDECL(check_capacity, (const char *));
-E int NDECL(inv_cnt);
+E int FDECL(inv_cnt, (BOOLEAN_P));
 #ifdef GOLDOBJ
 E long FDECL(money_cnt, (struct obj *));
 #endif
index 47c943099f95bc684b014a72a2fa3b959cbd6070..98b07811408ae63270f0d5061a2ed2d8ef0c37d3 100644 (file)
--- a/src/eat.c
+++ b/src/eat.c
@@ -341,7 +341,7 @@ register struct obj *otmp;
 
        if (carried(otmp)) {
            freeinv(otmp);
-           if (inv_cnt() >= 52) {
+           if (inv_cnt(FALSE) >= 52) {
                sellobj_state(SELL_DONTSELL);
                dropy(otmp);
                sellobj_state(SELL_NORMAL);
index cbd5bd2170ca211ac6a796e81f00f77b55529b15..3a7e2d41ee3e9dede235de4c68afc9b97275b604 100644 (file)
@@ -2479,13 +2479,14 @@ const char *str;
 }
 
 int
-inv_cnt()
+inv_cnt(incl_gold)
+boolean incl_gold;     /* only meaningful for GOLDOBJ config */
 {
        register struct obj *otmp = invent;
        register int ct = 0;
 
        while(otmp){
-               ct++;
+               if (incl_gold || otmp->invlet != GOLD_SYM) ct++;
                otmp = otmp->nobj;
        }
        return(ct);
@@ -2500,13 +2501,13 @@ long
 money_cnt(otmp)
 struct obj *otmp;
 {
-        while(otmp) {
-               /* Must change when silver & copper is implemented: */
-               if (otmp->oclass == COIN_CLASS) return otmp->quan;
-               otmp = otmp->nobj;
-       }
-       return 0;
+    while (otmp) {
+       /* Must change when silver & copper is implemented: */
+       if (otmp->oclass == COIN_CLASS) return otmp->quan;
+       otmp = otmp->nobj;
+    }
+    return 0L;
 }
-#endif
+#endif /* GOLDOBJ */
 
 /*hack.c*/
index c2a579cb410319bb40290b8e275c46e72bc8278c..0600b9841b21246aa45373f80c5231b9ff053a74 100644 (file)
@@ -420,7 +420,7 @@ const char *drop_fmt, *drop_arg, *hold_msg;
            if (drop_arg) drop_arg = strcpy(buf, drop_arg);
 
            obj = addinv(obj);
-           if (inv_cnt() > 52
+           if (inv_cnt(FALSE) > 52
                    || ((obj->otyp != LOADSTONE || !obj->cursed)
                        && near_capacity() > prev_encumbr)) {
                if (drop_fmt) pline(drop_fmt, drop_arg);
@@ -2932,7 +2932,7 @@ doorganize()      /* inventory organizer by Del Lamb */
        for (let = 'A'; let <= 'Z'; ) alphabet[ix++] = let++;
        alphabet[ix] = '\0';
        /* for floating inv letters, truncate list after the first open slot */
-       if (!flags.invlet_constant && (ix = inv_cnt()) < 52)
+       if (!flags.invlet_constant && (ix = inv_cnt(FALSE)) < 52)
            alphabet[ix + (splitting ? 0 : 1)] = '\0';
 
        /* blank out all the letters currently in use in the inventory */
@@ -3025,7 +3025,7 @@ doorganize()      /* inventory organizer by Del Lamb */
                    if (merged(&otmp, &obj)) {
                        obj = otmp;
                        extract_nobj(obj, &invent);
-                   } else if (inv_cnt() >= 52) {
+                   } else if (inv_cnt(FALSE) >= 52) {
                        (void) merged(&splitting, &obj);    /* undo split */
                        /* "knapsack cannot accommodate any more items" */
                        Your("pack is too full.");
index 9ca510734265f99e5591d1aa0183010fed94ac42..617af518525d2079e034a2ee197612d44a13662d 100644 (file)
@@ -1168,7 +1168,8 @@ boolean telekinesis;
        availability of open inventory slot iff not already carrying one */
     if (obj->otyp == LOADSTONE ||
            (obj->otyp == BOULDER && throws_rocks(youmonst.data))) {
-       if (inv_cnt() < 52 || !carrying(obj->otyp) || merge_choice(invent, obj))
+       if (inv_cnt(FALSE) < 52 || !carrying(obj->otyp) ||
+               merge_choice(invent, obj))
            return 1;   /* lift regardless of current situation */
        /* if we reach here, we're out of slots and already have at least
           one of these, so treat this one more like a normal item */
@@ -1180,11 +1181,10 @@ boolean telekinesis;
     *cnt_p = carry_count(obj, container, *cnt_p, telekinesis, &old_wt, &new_wt);
     if (*cnt_p < 1L) {
        result = -1;    /* nothing lifted */
-    } else if (
-#ifndef GOLDOBJ
-               obj->oclass != COIN_CLASS &&
-#endif
-               inv_cnt() >= 52 && !merge_choice(invent, obj)) {
+    } else if (obj->oclass != COIN_CLASS &&
+               /* [exception for gold coins will have to change
+                   if silver/copper ones ever get implemented] */
+               inv_cnt(FALSE) >= 52 && !merge_choice(invent, obj)) {
        Your("knapsack cannot accommodate any more items.");
        result = -1;    /* nothing lifted */
     } else {
@@ -1625,7 +1625,7 @@ reverse_loot()
 
     if (!rn2(3)) {
        /* n objects: 1/(n+1) chance per object plus 1/(n+1) to fall off end */
-       for (n = inv_cnt(), otmp = invent; otmp; --n, otmp = otmp->nobj)
+       for (n = inv_cnt(TRUE), otmp = invent; otmp; --n, otmp = otmp->nobj)
            if (!rn2(n + 1)) {
                prinv("You find old loot:", otmp, 0L);
                return TRUE;
index 12bb53614a21b28cf327710641b80f482e4f4e86..cd09c59d5d6a87e6a797c5330b641b15849b5136 100644 (file)
--- a/src/shk.c
+++ b/src/shk.c
@@ -146,7 +146,7 @@ long amount;
     if (mongold->quan > amount) mongold = splitobj(mongold, amount);
     obj_extract_self(mongold);
 
-    if (!merge_choice(invent, mongold) && inv_cnt() >= 52) {
+    if (!merge_choice(invent, mongold) && inv_cnt(FALSE) >= 52) {
        You("have no room for the money!");
        dropy(mongold);
     } else {
index 3ca65c16f9f4e139d11de162d480102a378cec76..58d53cf2225c275c29c450a685e8c862abf1f554 100644 (file)
@@ -263,6 +263,7 @@ boolean unchain_ball;       /* whether to unpunish or just unwield */
 /* Returns 1 when something was stolen (or at least, when N should flee now)
  * Returns -1 if the monster died in the attempt
  * Avoid stealing the object stealoid
+ * GOLDOBJ: nymphs and monkeys won't steal coins
  */
 int
 steal(mtmp, objnambuf)
@@ -282,7 +283,7 @@ char *objnambuf;
           so this will cause it to be removed now */
        if (occupation) (void) maybe_finished_meal(FALSE);
 
-       if (!invent || (inv_cnt() == 1 && uskin)) {
+       if (!invent || (inv_cnt(FALSE) == 1 && uskin)) {
 nothing_to_steal:
            /* Not even a thousand men in armor can strip a naked man. */
            if(Blind)
@@ -308,6 +309,9 @@ nothing_to_steal:
        tmp = 0;
        for(otmp = invent; otmp; otmp = otmp->nobj)
            if ((!uarm || otmp != uarmc) && otmp != uskin
+#ifdef GOLDOBJ
+                               && otmp->oclass != COIN_CLASS
+#endif
 #ifdef INVISIBLE_OBJECTS
                                && (!otmp->oinvis || perceives(mtmp->data))
 #endif
@@ -318,6 +322,9 @@ nothing_to_steal:
        tmp = rn2(tmp);
        for(otmp = invent; otmp; otmp = otmp->nobj)
            if ((!uarm || otmp != uarmc) && otmp != uskin
+#ifdef GOLDOBJ
+                               && otmp->oclass != COIN_CLASS
+#endif
 #ifdef INVISIBLE_OBJECTS
                                && (!otmp->oinvis || perceives(mtmp->data))
 #endif
@@ -375,7 +382,7 @@ gotobj:
                /* the fewer items you have, the less likely the thief
                   is going to stick around to try again (0) instead of
                   running away (1) */
-               return !rn2(inv_cnt() / 5 + 2);
+               return !rn2(inv_cnt(FALSE) / 5 + 2);
            }
        }
 
index 5d3fb60a009aadadbaa12fd295f43f9a3069415e..a0c11294761b1cfeb21e89a75170b8a293b7a245 100644 (file)
@@ -3160,7 +3160,7 @@ STATIC_OVL boolean
 emergency_disrobe(lostsome)
 boolean *lostsome;
 {
-       int invc = inv_cnt();
+       int invc = inv_cnt(TRUE);
 
        while (near_capacity() > (Punished ? UNENCUMBERED : SLT_ENCUMBER)) {
            register struct obj *obj, *otmp = (struct obj *)0;
index 3373ba7b5e0d93fc2f8dcd06771a930a19d7b98d..e969e1a81a9e2ede0ad87039534a1f27dc29ea30 100644 (file)
@@ -1478,7 +1478,8 @@ register struct attack *mattk;
                    struct obj *mongold = findgold(mdef->minvent);
                    if (mongold) {
                        obj_extract_self(mongold);  
-                       if (merge_choice(invent, mongold) || inv_cnt() < 52) {
+                       if (merge_choice(invent, mongold) ||
+                               inv_cnt(FALSE) < 52) {
                            addinv(mongold);
                            Your("purse feels heavier.");
                        } else {