🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.games.hack
Article #744

Sorting one's inventory

#744
From: Andrew Klossner
Date: Sat, 08 Jun 1985 17:41
59 lines
2740 bytes
I like my inventory (the response to the 'i' command) to be sorted, so
that all weapons appear together, all armor appears together, etc.
This mod does that.  All weapons appear first, followed by all armor,
followed by food and corpses, then gems, then scrolls, then potions,
then wands, then rings, then apply-able items.  This order can be
revised by changing the string SORTOBJS.

This code contains many more comments than the original.  I find that I
can't hack a hack routine unless I first comment it so I can see what
I'm doing.

  -=- Andrew Klossner   (decvax!tektronix!orca!andrew)       [UUCP]
                        (orca!andrew.tektronix@csnet-relay)  [ARPA]

========================================================================
/* In hack.invent.c, replace the addinv() procedure with the following: */

/* Collating sequence for sorting objects in an inventory.
   Just rearrange the characters in this string to change the sequence. */
static char SORTOBJS[] = "$)[%*?!/=(`";

static int classLess(newLet, establishedLet)

/* Return true if the new object letter is less than the established
   object letter, using a non-ASCII collating sequence. */

{
	/* I'm told that, under system V, "index" is spelled "strchr". */
	return index(SORTOBJS,newLet)<index(SORTOBJS,establishedLet);
	}

struct obj *
addinv(obj) register struct obj *obj; {
	register struct obj *otmp;

	/* Loop through the inventory.  For each item, if we can merge
	   this with it, do so, otherwise append the item to the end
	   of the list of items of its class. */
	for(otmp = (struct obj *)&invent; otmp; otmp = otmp->nobj) {

		/* Try to merge.  If it works, just return. */
		if(merged(otmp, obj, 0)) return(otmp);

		/* Couldn't merge.
		   See if we've come to the end of this class of items;
		   if so, link this item in here and return. */
		if(!otmp->nobj || classLess(obj->olet, otmp->nobj->olet)) {
			obj->nobj = otmp->nobj;
			otmp->nobj = obj;
			return(obj);
		}
	}

	/* Here if there were no items in the list to start with.
	   This item becomes the first item in the list. */
	invent = obj;
	obj->nobj = 0;
	return(obj);
}
Technical Details
Message-ID: <1557@orca.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!bonnie!akgua!whuxlm!harpo!decvax!tektronix!orca!andrew

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site orca.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!bonnie!akgua!whuxlm!harpo!decvax!tektronix!orca!andrew
From: andrew@orca.UUCP (Andrew Klossner)
Newsgroups: net.games.hack
Subject: Sorting one's inventory
Message-ID: <1557@orca.UUCP>
Date: Sat, 8-Jun-85 13:41:14 EDT
Article-I.D.: orca.1557
Posted: Sat Jun  8 13:41:14 1985
Date-Received: Mon, 10-Jun-85 21:11:45 EDT
Organization: Tektronix, Wilsonville OR
Lines: 59