WIZKIT inventory overflow (trunk only)

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.
This commit is contained in:
nethack.rankin
2007-06-16 04:18:14 +00:00
parent 2ad3afee05
commit d1387f2b6b
5 changed files with 35 additions and 9 deletions

View 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();

View 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 */

View 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);