revisit #H4083 - glob ID and merging

Globs on the floor used different criteria (anything goes) than globs
in inventory (mostly requiring same ownership when in shops and same
curse/bless state--other stuff generally isn't applicable) when
deciding whether two globs should merge.  That was okay as long as
the globs on the floor were from being left behind when a pudding or
ooze was killed, but not if the player had picked some up, dipped
them in holy or unholy water, and dropped them again.  This changes
things so that globs on the floor use the same criteria as globs in
inventory when deciding whether to coallesce.

Also, my earlier fix was modifying globs in the mergeable() test (to
make bknown and rknown match) rather than during actual merge, which
would be a problem if the merger didn't take place for some reason.
This commit is contained in:
PatR
2016-01-28 18:13:25 -08:00
parent a309e076e0
commit b632247a74
4 changed files with 46 additions and 49 deletions
+3 -2
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 extern.h $NHDT-Date: 1453514592 2016/01/23 02:03:12 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.542 $ */ /* NetHack 3.6 extern.h $NHDT-Date: 1454033598 2016/01/29 02:13:18 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.543 $ */
/* Copyright (c) Steve Creps, 1988. */ /* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -943,6 +943,7 @@ E int NDECL(dolook);
E boolean FDECL(will_feel_cockatrice, (struct obj *, BOOLEAN_P)); E boolean FDECL(will_feel_cockatrice, (struct obj *, BOOLEAN_P));
E void FDECL(feel_cockatrice, (struct obj *, BOOLEAN_P)); E void FDECL(feel_cockatrice, (struct obj *, BOOLEAN_P));
E void FDECL(stackobj, (struct obj *)); E void FDECL(stackobj, (struct obj *));
E boolean FDECL(mergable, (struct obj *, struct obj *));
E int NDECL(doprgold); E int NDECL(doprgold);
E int NDECL(doprwep); E int NDECL(doprwep);
E int NDECL(doprarm); E int NDECL(doprarm);
@@ -1275,7 +1276,7 @@ E long FDECL(peek_at_iced_corpse_age, (struct obj *));
E int FDECL(hornoplenty, (struct obj *, BOOLEAN_P)); E int FDECL(hornoplenty, (struct obj *, BOOLEAN_P));
E void NDECL(obj_sanity_check); E void NDECL(obj_sanity_check);
E struct obj *FDECL(obj_nexto, (struct obj *)); E struct obj *FDECL(obj_nexto, (struct obj *));
E struct obj *FDECL(obj_nexto_xy, (int, int, int, unsigned)); E struct obj *FDECL(obj_nexto_xy, (struct obj *, int, int, BOOLEAN_P));
E struct obj *FDECL(obj_absorb, (struct obj **, struct obj **)); E struct obj *FDECL(obj_absorb, (struct obj **, struct obj **));
E struct obj *FDECL(obj_meld, (struct obj **, struct obj **)); E struct obj *FDECL(obj_meld, (struct obj **, struct obj **));
+3 -5
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 do.c $NHDT-Date: 1446975464 2015/11/08 09:37:44 $ $NHDT-Branch: master $:$NHDT-Revision: 1.149 $ */ /* NetHack 3.6 do.c $NHDT-Date: 1454033599 2016/01/29 02:13:19 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.153 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -215,15 +215,13 @@ const char *verb;
otense(obj, "tumble"), the_your[t->madeby_u]); otense(obj, "tumble"), the_your[t->madeby_u]);
} else if (obj->globby) { } else if (obj->globby) {
/* Globby things like puddings might stick together */ /* Globby things like puddings might stick together */
while (obj while (obj && (otmp = obj_nexto_xy(obj, x, y, TRUE)) != 0) {
&& (otmp = obj_nexto_xy(obj->otyp, x, y, obj->o_id))
!= (struct obj *) 0) {
pudding_merge_message(obj, otmp); pudding_merge_message(obj, otmp);
/* intentionally not getting the melded object; obj_meld may set /* intentionally not getting the melded object; obj_meld may set
* obj to null. */ * obj to null. */
(void) obj_meld(&obj, &otmp); (void) obj_meld(&obj, &otmp);
} }
return (boolean) (obj == NULL); return (boolean) !obj;
} }
return FALSE; return FALSE;
} }
+12 -20
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 invent.c $NHDT-Date: 1452650438 2016/01/13 02:00:38 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.188 $ */ /* NetHack 3.6 invent.c $NHDT-Date: 1454033599 2016/01/29 02:13:19 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.192 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -9,7 +9,6 @@
STATIC_DCL int FDECL(CFDECLSPEC sortloot_cmp, (struct obj *, struct obj *)); STATIC_DCL int FDECL(CFDECLSPEC sortloot_cmp, (struct obj *, struct obj *));
STATIC_DCL void NDECL(reorder_invent); STATIC_DCL void NDECL(reorder_invent);
STATIC_DCL boolean FDECL(mergable, (struct obj *, struct obj *));
STATIC_DCL void FDECL(noarmor, (BOOLEAN_P)); STATIC_DCL void FDECL(noarmor, (BOOLEAN_P));
STATIC_DCL void FDECL(invdisp_nothing, (const char *, const char *)); STATIC_DCL void FDECL(invdisp_nothing, (const char *, const char *));
STATIC_DCL boolean FDECL(worn_wield_only, (struct obj *)); STATIC_DCL boolean FDECL(worn_wield_only, (struct obj *));
@@ -335,7 +334,7 @@ struct obj **potmp, **pobj;
/* handle puddings a bit differently; absorption will /* handle puddings a bit differently; absorption will
* free the other object automatically so we can just * free the other object automatically so we can just
* return out from here. */ * return out from here. */
if (Is_pudding(obj)) { if (obj->globby) {
pudding_merge_message(otmp, obj); pudding_merge_message(otmp, obj);
obj_absorb(potmp, pobj); obj_absorb(potmp, pobj);
return 1; return 1;
@@ -2889,8 +2888,8 @@ struct obj *obj;
return; return;
} }
/* returns TRUE if obj & otmp can be merged */ /* returns TRUE if obj & otmp can be merged; used in invent.c and mkobj.c */
STATIC_OVL boolean boolean
mergable(otmp, obj) mergable(otmp, obj)
register struct obj *otmp, *obj; register struct obj *otmp, *obj;
{ {
@@ -2908,31 +2907,24 @@ register struct obj *otmp, *obj;
return TRUE; return TRUE;
if (obj->unpaid != otmp->unpaid || obj->spe != otmp->spe if (obj->unpaid != otmp->unpaid || obj->spe != otmp->spe
|| obj->dknown != otmp->dknown
|| obj->cursed != otmp->cursed || obj->blessed != otmp->blessed || obj->cursed != otmp->cursed || obj->blessed != otmp->blessed
|| obj->no_charge != otmp->no_charge || obj->obroken != otmp->obroken || obj->no_charge != otmp->no_charge || obj->obroken != otmp->obroken
|| obj->otrapped != otmp->otrapped || obj->lamplit != otmp->lamplit || obj->otrapped != otmp->otrapped || obj->lamplit != otmp->lamplit
|| obj->bypass != otmp->bypass) || obj->bypass != otmp->bypass)
return FALSE; return FALSE;
if (obj->globby)
return TRUE;
/* Checks beyond this point either aren't applicable to globs
* or don't inhibit their merger.
*/
if (obj->oclass == FOOD_CLASS if (obj->oclass == FOOD_CLASS
&& (obj->oeaten != otmp->oeaten || obj->orotten != otmp->orotten)) && (obj->oeaten != otmp->oeaten || obj->orotten != otmp->orotten))
return FALSE; return FALSE;
if (obj->globby) { if (obj->dknown != otmp->dknown
/* globs won't merge if they have different bless/curse || (obj->bknown != otmp->bknown && !Role_if(PM_PRIEST))
state, but will merge non-bknown with bknown */
if (obj->bknown != otmp->bknown)
obj->bknown = otmp->bknown = 0;
if (obj->rknown != otmp->rknown)
obj->rknown = otmp->rknown = 0;
if (obj->greased != otmp->greased)
obj->greased = otmp->greased = 0;
/* checks beyond this point aren't applicable to globs */
return TRUE;
}
if ((obj->bknown != otmp->bknown && !Role_if(PM_PRIEST))
|| obj->oeroded != otmp->oeroded || obj->oeroded2 != otmp->oeroded2 || obj->oeroded != otmp->oeroded || obj->oeroded2 != otmp->oeroded2
|| obj->greased != otmp->greased) || obj->greased != otmp->greased)
return FALSE; return FALSE;
+28 -22
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mkobj.c $NHDT-Date: 1447475943 2015/11/14 04:39:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.113 $ */ /* NetHack 3.6 mkobj.c $NHDT-Date: 1454033600 2016/01/29 02:13:20 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.116 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -2578,15 +2578,10 @@ struct obj *
obj_nexto(otmp) obj_nexto(otmp)
struct obj *otmp; struct obj *otmp;
{ {
struct obj *otmp2 = (struct obj *) 0; if (!otmp)
if (otmp) {
otmp2 = obj_nexto_xy(otmp->otyp, otmp->ox, otmp->oy, otmp->o_id);
} else {
impossible("obj_nexto: wasn't given an object to check"); impossible("obj_nexto: wasn't given an object to check");
}
return otmp2; return obj_nexto_xy(otmp, otmp->ox, otmp->oy, TRUE);
} }
/* /*
@@ -2598,24 +2593,27 @@ struct obj *otmp;
* reliably predict which one we want to 'find' first * reliably predict which one we want to 'find' first
*/ */
struct obj * struct obj *
obj_nexto_xy(otyp, x, y, oid) obj_nexto_xy(obj, x, y, recurs)
int otyp, x, y; struct obj *obj;
unsigned oid; int x, y;
boolean recurs;
{ {
struct obj *otmp; struct obj *otmp;
int fx, fy, ex, ey; int fx, fy, ex, ey, otyp = obj->otyp;
short dx, dy; short dx, dy;
/* check under our "feet" first */ /* check under our "feet" first */
otmp = sobj_at(otyp, x, y); otmp = sobj_at(otyp, x, y);
while (otmp) { while (otmp) {
/* don't be clever and find ourselves */ /* don't be clever and find ourselves */
if (otmp->o_id != oid) { if (otmp != obj && mergable(otmp, obj))
return otmp; return otmp;
}
otmp = nxtobj(otmp, otyp, TRUE); otmp = nxtobj(otmp, otyp, TRUE);
} }
if (!recurs)
return (struct obj *) 0;
/* search in a random order */ /* search in a random order */
dx = (rn2(2) ? -1 : 1); dx = (rn2(2) ? -1 : 1);
dy = (rn2(2) ? -1 : 1); dy = (rn2(2) ? -1 : 1);
@@ -2626,9 +2624,8 @@ unsigned oid;
for (fy = ey; abs(fy - ey) < 3; fy += dy) { for (fy = ey; abs(fy - ey) < 3; fy += dy) {
/* 0, 0 was checked above */ /* 0, 0 was checked above */
if (isok(fx, fy) && (fx != x || fy != y)) { if (isok(fx, fy) && (fx != x || fy != y)) {
if ((otmp = sobj_at(otyp, fx, fy)) != 0) { if ((otmp = obj_nexto_xy(obj, fx, fy, FALSE)) != 0)
return otmp; return otmp;
}
} }
} }
} }
@@ -2644,14 +2641,22 @@ struct obj *
obj_absorb(obj1, obj2) obj_absorb(obj1, obj2)
struct obj **obj1, **obj2; struct obj **obj1, **obj2;
{ {
struct obj *otmp1 = (struct obj *) 0, *otmp2 = (struct obj *) 0; struct obj *otmp1, *otmp2;
int extrawt = 0; int extrawt;
/* don't let people dumb it up */ /* don't let people dumb it up */
if (obj1 && obj2) { if (obj1 && obj2) {
otmp1 = *obj1; otmp1 = *obj1;
otmp2 = *obj2; otmp2 = *obj2;
if (otmp1 && otmp2) { if (otmp1 && otmp2 && otmp1 != otmp2) {
if (otmp1->bknown != otmp2->bknown)
otmp1->bknown = otmp2->bknown = 0;
if (otmp1->rknown != otmp2->rknown)
otmp1->rknown = otmp2->rknown = 0;
if (otmp1->greased != otmp2->greased)
otmp1->greased = otmp2->greased = 0;
if (otmp1->orotten || otmp2->orotten)
otmp1->orotten = otmp2->orotten = 1;
extrawt = otmp2->oeaten ? otmp2->oeaten : otmp2->owt; extrawt = otmp2->oeaten ? otmp2->oeaten : otmp2->owt;
otmp1->owt += extrawt; otmp1->owt += extrawt;
otmp1->oeaten += otmp1->oeaten ? extrawt : 0; otmp1->oeaten += otmp1->oeaten ? extrawt : 0;
@@ -2677,13 +2682,14 @@ struct obj *
obj_meld(obj1, obj2) obj_meld(obj1, obj2)
struct obj **obj1, **obj2; struct obj **obj1, **obj2;
{ {
struct obj *otmp1 = (struct obj *) 0, *otmp2 = (struct obj *) 0; struct obj *otmp1, *otmp2;
if (obj1 && obj2) { if (obj1 && obj2) {
otmp1 = *obj1; otmp1 = *obj1;
otmp2 = *obj2; otmp2 = *obj2;
if (otmp1 && otmp2) { if (otmp1 && otmp2 && otmp1 != otmp2) {
if (otmp1->owt > otmp2->owt || rn2(2)) { if (otmp1->owt > otmp2->owt
|| (otmp1->owt == otmp2->owt && rn2(2))) {
return obj_absorb(obj1, obj2); return obj_absorb(obj1, obj2);
} }
return obj_absorb(obj2, obj1); return obj_absorb(obj2, obj1);