]> granicus.if.org Git - nethack/commitdiff
WIZKIT inventory overflow (trunk only)
authornethack.rankin <nethack.rankin>
Sat, 16 Jun 2007 04:18:14 +0000 (04:18 +0000)
committernethack.rankin <nethack.rankin>
Sat, 16 Jun 2007 04:18:14 +0000 (04:18 +0000)
     Wizard mode's $WIZKIT can specify an unlimited number of items to
add to starting inventory and they'd be put there without regard to the
number of slots in use, potentially resulting in an arbitrary number of
'#' slot items.  Cap at 52 slots, same as when picking up, and put any
excess items at the hero's feet.  It's slightly tricky because the level
hasn't been created yet at the time the wizkit gets processed.

doc/fixes35.0
include/dungeon.h
src/allmain.c
src/dokick.c
src/files.c

index 671f97c9c69bca8248cee36bdc43d46491b6c8f3..b9ee5e937fcb10f75db0e2abfbd7e16b481b05f9 100644 (file)
@@ -250,6 +250,7 @@ sometimes when hero is forced to buy an unpaid shop item its price changed
 monster could attack with a polearm even after attempt to wield that failed
 sometimes got "you trip over it" after intervening messages following the
        one which described "it"
+wizard mode: WIZKIT wishes could overflow inventory's 52 slots
 
 
 Platform- and/or Interface-Specific Fixes
index 3b1b04fc91457a6a6425158dbc0817e943816e4a..ed38f6e883d6486c60119e4974d6fc4379a6bde8 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)dungeon.h  3.5     1999/07/02      */
+/*     SCCS Id: @(#)dungeon.h  3.5     2007/06/15      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -142,6 +142,7 @@ typedef struct branch {
 #define MIGR_SSTAIRS           7       /* dungeon branch */
 #define MIGR_PORTAL            8       /* magic portal */
 #define MIGR_NEAR_PLAYER       9       /* mon: followers; obj: trap door */
+#define MIGR_AT_HERO          10       /* wizkit overflow */
 #define MIGR_NOBREAK        1024       /* bitmask: don't break on delivery */
 
 /* level information (saved via ledger number) */
index 70b975413350d51374c9fb992bf1de500955a827..6e5f068facab03898b85eebec80126147832a2d5 100644 (file)
@@ -524,14 +524,12 @@ newgame()
 
        mklev();
        u_on_upstairs();
+#ifdef WIZARD
+       if (wizard) obj_delivery(FALSE);        /* finish wizkit */
+#endif
        vision_reset();         /* set up internals for level (after mklev) */
        check_special_room(FALSE);
 
-
-       /* Move the monster from under you or else
-        * makedog() will fail when it calls makemon().
-        *                      - ucsfcgl!kneller
-        */
        if(MON_AT(u.ux, u.uy)) mnexto(m_at(u.ux, u.uy));
        (void) makedog();
        docrt();
index 4bc98344355ef321fb1f07f93a8f9e96d0b1c9e0..6f8d0c39045fc8a0b7c2f365255a5b0d43195d2b 100644 (file)
@@ -1430,7 +1430,7 @@ boolean near_hero;
        register struct obj *otmp, *otmp2;
        register int nx, ny;
        long where;
-       boolean nobreak;
+       boolean nobreak, noscatter = FALSE;
 
        for (otmp = migrating_objs; otmp; otmp = otmp2) {
            otmp2 = otmp->nobj;
@@ -1453,6 +1453,7 @@ boolean near_hero;
                                break;
             case MIGR_SSTAIRS:     nx = sstairs.sx,  ny = sstairs.sy;
                                break;
+            case MIGR_AT_HERO:     noscatter = TRUE; /*FALLTHRU*/
             case MIGR_NEAR_PLAYER: nx = u.ux,  ny = u.uy;
                                break;
             default:
@@ -1471,7 +1472,7 @@ boolean near_hero;
                    }
                }
                stackobj(otmp);
-               (void)scatter(nx, ny, rnd(2), 0, otmp);
+               if (!noscatter) (void)scatter(nx, ny, rnd(2), 0, otmp);
            } else {            /* random location */
                /* set dummy coordinates because there's no
                   current position for rloco() to update */
index 5056b708a0abf40fe4dee95d27be2df5608ae7ba..9f4b89c88c4099b3e2e71c91ca3bbe2ed9413377 100644 (file)
@@ -127,6 +127,7 @@ boolean nethack_thinks_it_is_open;  /* Does NetHack think it's open?       */
 #define WIZKIT_MAX 128
 static char wizkit[WIZKIT_MAX];
 STATIC_DCL FILE *NDECL(fopen_wizkit_file);
+STATIC_DCL void FDECL(wizkit_addinv, (struct obj *));
 #endif
 
 #ifdef AMIGA
@@ -2409,6 +2410,30 @@ fopen_wizkit_file()
        return (FILE *)0;
 }
 
+/* add to hero's inventory if there's room, otherwise put item on floor */
+STATIC_DCL void
+wizkit_addinv(obj)
+struct obj *obj;
+{
+    if (!obj || obj == &zeroobj) return;
+
+    /* subset of starting inventory pre-ID */
+    obj->dknown = 1;
+    if (Role_if(PM_PRIEST)) obj->bknown = 1;
+    /* same criteria as lift_object()'s check for available inventory slot */
+    if (obj->oclass != COIN_CLASS &&
+           inv_cnt(FALSE) >= 52 && !merge_choice(invent, obj)) {
+       /* inventory overflow; can't just place & stack object since
+          hero isn't in position yet, so schedule for arrival later */
+       add_to_migration(obj);
+       obj->ox = 0;    /* index of main dungeon */
+       obj->oy = 1;    /* starting level number */
+       obj->owornmask = (long)(MIGR_AT_HERO|MIGR_NOBREAK);
+    } else {
+       (void)addinv(obj);
+    }
+}
+
 void
 read_wizkit()
 {
@@ -2432,7 +2457,7 @@ read_wizkit()
                        otmp = readobjnam(buf, (struct obj *)0);
                        if (otmp) {
                            if (otmp != &zeroobj)
-                               otmp = addinv(otmp);
+                               wizkit_addinv(otmp);
                        } else {
                            /* .60 limits output line width to 79 chars */
                            raw_printf("Bad wizkit item: \"%.60s\"", buf);