Patch: Sticky Objects for 3.4.0 (contains DIFF)

2 views
Skip to first unread message

Tapio Kelloniemi

unread,
Mar 22, 2002, 3:53:08 PM3/22/02
to
I have converted Scott Bigham's Sticky objects patch for NH 3.4.0. I
made it PatchHack compatible (#define STICKY_OBJECTS in config.h).

Use the following command to aply this patch in root directory of
NetHack 3.4.0 source tree:
patch -p1 -i filename

This pathc can't be found from the web yet, for my site is not ready. It
is small, so I'll put it here.

I tested it in wizard mode and noticed no BUGS. Although I didn't test,
if NetHack works properly, when STICKY_OBJECTS is not defined. My
computer is so slow, that I didn't want to waste time.

--
Tappi the Reconnoiterer


diff -r -u -B --exclude=*.o --exclude=config.h nethack.org/include/extern.h nethack/include/extern.h
--- nethack.org/include/extern.h Fri Mar 22 21:42:10 2002
+++ nethack/include/extern.h Fri Mar 22 20:14:42 2002
@@ -1,4 +1,4 @@
-/* SCCS Id: @(#)extern.h 3.4 2002/03/09 */
+/* SCCS Id: @(#)extern.h 3.4 2002/03/22 */
/* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */

@@ -786,6 +786,9 @@
E void NDECL(free_invbuf);
E void NDECL(reassign);
E int NDECL(doorganize);
+#ifdef STICKY_OBJECTS
+E int NDECL(dosticky);
+#endif /* STICKY_OBJECTS */
E int FDECL(count_unpaid, (struct obj *));
E int FDECL(count_buc, (struct obj *,int));
E void FDECL(carry_obj_effects, (struct obj *));
diff -r -u -B --exclude=*.o --exclude=config.h nethack.org/include/obj.h nethack/include/obj.h
--- nethack.org/include/obj.h Fri Mar 22 21:42:10 2002
+++ nethack/include/obj.h Fri Mar 22 20:17:08 2002
@@ -1,4 +1,4 @@
-/* SCCS Id: @(#)obj.h 3.4 2002/01/07 */
+/* SCCS Id: @(#)obj.h 3.4 2002/03/22 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */

@@ -86,7 +86,13 @@

Bitfield(in_use,1); /* for magic items before useup items */
Bitfield(bypass,1); /* mark this as an object to be skipped by bhito() */
+#ifndef STICKY_OBJECTS
/* 6 free bits */
+#else
+ Bitfield(sticky,1); /* "sticky" inventory slot */
+ /* 5 free bits */
+#endif /* STICKY_OBJECTS */
+

int corpsenm; /* type of corpse is mons[corpsenm] */
#define leashmon corpsenm /* gets m_id of attached pet */
diff -r -u -B --exclude=*.o --exclude=config.h nethack.org/src/bones.c nethack/src/bones.c
--- nethack.org/src/bones.c Fri Mar 22 21:42:14 2002
+++ nethack/src/bones.c Fri Mar 22 20:06:54 2002
@@ -1,4 +1,4 @@
-/* SCCS Id: @(#)bones.c 3.4 2001/04/12 */
+/* SCCS Id: @(#)bones.c 3.4 2002/03/22 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985,1993. */
/* NetHack may be freely redistributed. See license for details. */

@@ -81,6 +81,9 @@
otmp->dknown = otmp->bknown = 0;
otmp->rknown = 0;
otmp->invlet = 0;
+#ifdef STICKY_OBJECTS
+ otmp->sticky = 0;
+#endif /* STICKY_OBJECTS */
otmp->no_charge = 0;

if (otmp->otyp == SLIME_MOLD) goodfruit(otmp->spe);
diff -r -u -B --exclude=*.o --exclude=config.h nethack.org/src/cmd.c nethack/src/cmd.c
--- nethack.org/src/cmd.c Fri Mar 22 21:42:14 2002
+++ nethack/src/cmd.c Fri Mar 22 20:12:08 2002
@@ -1,4 +1,4 @@
-/* SCCS Id: @(#)cmd.c 3.4 2002/01/17 */
+/* SCCS Id: @(#)cmd.c 3.4 2002/03/22 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */

@@ -97,6 +97,9 @@
extern int NDECL(dowieldquiver); /**/
extern int NDECL(dozap); /**/
extern int NDECL(doorganize); /**/
+#ifdef STICKY_OBJECTS
+extern int NDECL(dosticky); /**/
+#endif /* STICKY_OBJECTS */
#endif /* DUMB */

#ifdef OVL1
@@ -1338,6 +1341,9 @@
{'x', FALSE, doswapweapon},
{'X', TRUE, enter_explore_mode},
/* 'y', 'Y' : go nw */
+#ifdef STICKY_OBJECTS
+ {M('y'), TRUE, dosticky},
+#endif /* STICKY_OBJECTS */
{'z', FALSE, dozap},
{'Z', TRUE, docast},
{'<', FALSE, doup},
@@ -1392,6 +1398,9 @@
#endif
{"rub", "rub a lamp or a stone", dorub, FALSE},
{"sit", "sit down", dosit, FALSE},
+#ifdef STICKY_OBJECTS
+ {"sticky", "set 'sticky' inventory slots", dosticky, TRUE},
+#endif /* STICKY_OBJECTS */
{"turn", "turn undead", doturn, TRUE},
{"twoweapon", "toggle two-weapon combat", dotwoweapon, FALSE},
{"untrap", "untrap something", dountrap, FALSE},
diff -r -u -B --exclude=*.o --exclude=config.h nethack.org/src/invent.c nethack/src/invent.c
--- nethack.org/src/invent.c Fri Mar 22 21:42:20 2002
+++ nethack/src/invent.c Fri Mar 22 21:17:08 2002
@@ -1,4 +1,4 @@
-/* SCCS Id: @(#)invent.c 3.4 2002/02/23 */
+/* SCCS Id: @(#)invent.c 3.4 2002/03/22 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */

@@ -32,6 +32,9 @@

#ifdef OVLB

+#ifdef STICKY_OBJECTS
+boolean sticky_inv_hack = 0; /* blech ick yuck... */
+#endif /* STICKY_OBJECTS */
static int lastinvnr = 51; /* 0 ... 51 (never saved&restored) */

#ifdef WIZARD
@@ -160,6 +163,9 @@
struct obj **potmp, **pobj;
{
register struct obj *otmp = *potmp, *obj = *pobj;
+#ifdef STICKY_OBJECTS
+ boolean sticky_hack = 0;
+#endif /* STICKY_OBJECTS */

if(mergable(otmp, obj)) {
/* Approximate age: we do it this way because if we were to
@@ -224,7 +230,19 @@
}
#endif /*0*/

+#ifdef STICKY_OBJECTS
+ if (flags.invlet_constant && obj->invlet &&
+ obj->sticky && !otmp->sticky) {
+ otmp->invlet = obj->invlet;
+ otmp->sticky = 1;
+ sticky_hack = 1;
+ }
+#endif /* STICKY_OBJECTS */
obfree(obj,otmp); /* free(obj), bill->otmp */
+#ifdef STICKY_OBJECTS
+ /* if we're not merging in inventory, this will be a nop */
+ if (sticky_hack) reorder_invent();
+#endif /* STICKY_OBJECTS */
return(1);
}
return 0;
@@ -304,6 +322,10 @@
struct obj *obj;
{
struct obj *otmp, *prev;
+#ifdef STICKY_OBJECTS
+ struct obj *otmp2;
+ char save_invlet = '\0';
+#endif /* STICKY_OBJECTS */

if (obj->where != OBJ_FREE)
panic("addinv: obj not free");
@@ -316,6 +338,16 @@
return obj;
#endif

+#ifdef STICKY_OBJECTS
+ /* if object is sticky, find the object we'll be displacing */
+ if (flags.invlet_constant && obj->invlet && obj->sticky) {
+ save_invlet = obj->invlet;
+ for (otmp2 = invent; otmp2; otmp2 = otmp2->nobj)
+ if (otmp2->invlet == save_invlet)
+ break;
+ }
+#endif /* STICKY_OBJECTS */
+
/* merge if possible; find end of chain in the process */
for (prev = 0, otmp = invent; otmp; prev = otmp, otmp = otmp->nobj)
if (merged(&otmp, &obj)) {
@@ -324,7 +356,15 @@
}
/* didn't merge, so insert into chain */
if (flags.invlet_constant || !prev) {
- if (flags.invlet_constant) assigninvlet(obj);
+ if (flags.invlet_constant) {
+ assigninvlet(obj);
+#ifdef STICKY_OBJECTS
+ if (save_invlet) {
+ if (otmp2) otmp2->invlet = obj->invlet;
+ obj->invlet = save_invlet;
+ }
+#endif /* STICKY_OBJECTS */
+ }
obj->nobj = invent; /* insert at beginning */
invent = obj;
if (flags.invlet_constant) reorder_invent();
@@ -1522,9 +1562,16 @@
#endif
} else {
/* ordinary inventory display or pickup message */
+#ifndef STICKY_OBJECTS
Sprintf(li, "%c - %s%s",
(use_invlet ? obj->invlet : let),
(txt ? txt : doname(obj)), (dot ? "." : ""));
+#else
+ Sprintf(li, "%c %c %s%s",
+ (use_invlet ? obj->invlet : let),
+ (use_invlet && obj->sticky ? '=' : '-'),
+ (txt ? txt : doname(obj)), (dot ? "." : ""));
+#endif /* STICKY_OBJECTS */
}
if (savequan) obj->quan = savequan;

@@ -1658,9 +1705,19 @@
classcount++;
}
any.a_char = ilet;
+#ifdef STICKY_OBJECTS
+ /*
+ * Yes, this is evil and disgusting. If you
+ * have a better way of doing this, jump on it.
+ */
+ sticky_inv_hack = otmp->sticky;
+#endif /* STICKY_OBJECTS */
add_menu(win, obj_to_glyph(otmp),
&any, ilet, 0, ATR_NONE, doname(otmp),
MENU_UNSELECTED);
+#ifdef STICKY_OBJECTS
+ sticky_inv_hack = 0;
+#endif /* STICKY_OBJECTS */
}
}
}
@@ -2594,6 +2651,23 @@
return(0);
}

+#ifdef STICKY_OBJECTS
+int
+dosticky() /* toggle "sticky" inventory slot */
+{
+ struct obj *obj;
+ char allowall[2];
+
+ /* get a pointer to the object the user wants to modify */
+ allowall[0] = ALL_CLASSES; allowall[1] = '\0';
+ if (!(obj = getobj(allowall,"mark"))) return 0;
+
+ obj->sticky = !obj->sticky;
+ prinv(obj->sticky ? "Marking:" : "Unmarking:", obj, 0L);
+ return(0);
+}
+#endif /* STICKY_OBJECTS */
+
/* common to display_minventory and display_cinventory */
STATIC_OVL void
invdisp_nothing(hdr, txt)

Reply all
Reply to author
Forward
0 new messages