[net.games.hack] Sorted Inventory List for 1.0.3

barry@adelie.UUCP (Barry A. Burke) (01/14/86)

ough for login name .99 */
  
  boolean in_mklev, restoring;
  

--- 5,11 -----
  char nul[40];			/* contains zeros */
  char plname[PL_NSIZ];		/* player name */
  char lock[PL_NSIZ+4] = "1lock";	/* long enough for login name .99 */
+ char sortlist[SOBJLEN+1];     	/* sort order for inventory list */
  
  boolean in_mklev, restoring;
  
*** hack.invent.c.old	Tue Dec 31 15:48:32 1985
--- hack.invent.c	Mon Jan  6 22:54:27 1986
***************
*** 43,48
  			(i < 26) ? ('a'+i) : ('A'+i-26));
  	lastinvnr = i;
  }
  
  struct obj *
  addinv(obj)

--- 43,50 -----
  			(i < 26) ? ('a'+i) : ('A'+i-26));
  	lastinvnr = i;
  }
+ /* Barry A. Burke <barry@adelie.UUCP> modified addinv() Jan  6, 1985 to 
+    sort the inventory list by type. */
  
  struct obj *
  addinv(obj)
***************
*** 49,54
  register struct obj *obj;
  {
  	register struct obj *otmp;
  
  	/* merge or attach to end of chain */
  	if(!invent) {

--- 51,58 -----
  register struct obj *obj;
  {
  	register struct obj *otmp;
+ 	int i;
+ 	extern char sortlist[];
  
  	/* merge or attach to end of chain */
  	if(!invent) {
***************
*** 65,91
  	}
  	obj->nobj = 0;
  
! 	if(flags.invlet_constant) {
! 		assigninvlet(obj);
! 		/*
! 		 * The ordering of the chain is nowhere significant
! 		 * so in case you prefer some other order than the
! 		 * historical one, change the code below.
! 		 */
! 		if(otmp) {	/* find proper place in chain */
! 			otmp->nobj = 0;
! 			if((invent->invlet ^ 040) > (obj->invlet ^ 040)) {
! 				obj->nobj = invent;
! 				invent = obj;
! 			} else
! 			for(otmp = invent; ; otmp = otmp->nobj) {
! 			    if(!otmp->nobj ||
! 				(otmp->nobj->invlet ^ 040) > (obj->invlet ^ 040)){
! 				obj->nobj = otmp->nobj;
! 				otmp->nobj = obj;
! 				break;
! 			    }
! 			}
  		}
  	}
  

--- 69,95 -----
  	}
  	obj->nobj = 0;
  
! 	if(flags.invlet_constant)
! 		assigninvlet(obj);     /* gotta have a letter assigned! */
! 
! 	/* Now, let's sort the new object into the list by object type. */
!      	i = (int) (index(sortlist, obj->olet) - sortlist);
! 	if ( i <= 0 )
! 	        i = 100;
! 
! 	if(otmp) {	/* find proper place in chain */
! 		otmp->nobj = 0;
! 		if ( i < (int) (index(sortlist, invent->olet) - sortlist)) {
! 			obj->nobj = invent;
! 			invent = obj;
! 		} else
! 		for(otmp = invent; ; otmp = otmp->nobj) {
! 		    if(!otmp->nobj ||
! 		     	(i<(int)(index(sortlist,otmp->nobj->olet)-sortlist))) {
! 			obj->nobj = otmp->nobj;
! 			otmp->nobj = obj;
! 			break;
! 		    }
  		}
  	}
  
*** hack.options.c.orig	Mon Dec 23 11:40:24 1985
--- hack.options.c	Wed Jan  8 14:23:38 1986
***************
*** 5,10
  #include "hack.h"
  extern char *eos();
  
  initoptions()
  {
  	register char *opts;

--- 5,12 -----
  #include "hack.h"
  extern char *eos();
  
+ extern char sortlist[];
+ 
  initoptions()
  {
  	register char *opts;
***************
*** 17,22
  	flags.end_top = 5;
  	flags.end_around = 4;
  	flags.female = FALSE;			/* players are usually male */
  
  	if(opts = getenv("HACKOPTIONS"))
  		parseoptions(opts,TRUE);

--- 19,26 -----
  	flags.end_top = 5;
  	flags.end_around = 4;
  	flags.female = FALSE;			/* players are usually male */
+ 	(void) strcpy( sortlist, "$" );      	/* gotta seed it for `index' */
+ 	(void) strncat( sortlist, SORTOBJ, strlen(SORTOBJ) );
  
  	if(opts = getenv("HACKOPTIONS"))
  		parseoptions(opts,TRUE);
***************
*** 107,112
  		return;
  	}
  
  	/* endgame:5t[op] 5a[round] o[wn] */
  	if(!strncmp(opts,"endgame",3)) {
  		op = index(opts,':');

--- 111,129 -----
  		return;
  	}
  
+ 	/* sortobj:string */
+ 	if(!strncmp(opts,"sortobj",4)) {
+ 	        if(!from_env) {
+ 		  pline("The inventory sort list can be set only from HACKOPTIONS.");
+ 		  return;
+ 	        }
+ 		op = index(opts,':');
+ 		if(!op) goto bad;
+ 		(void) strcpy(sortlist, "$");	   /* Need an offset of 1 */
+ 		(void) strncat(sortlist, op+1, SOBJLEN-1);
+ 		return;
+ 	 }
+ 
  	/* endgame:5t[op] 5a[round] o[wn] */
  	if(!strncmp(opts,"endgame",3)) {
  		op = index(opts,':');
***************
*** 145,151
  		if(!strncmp(opts, "help", 4)) {
  			pline("%s%s%s",
  "To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ",
! "give the command 'o' followed by the line `<options>' while playing. ",
  "Here <options> is a list of <option>s separated by commas." );
  			pline("%s%s%s",
  "Simple (boolean) options are rest_on_space, news, time, ",

--- 162,168 -----
  		if(!strncmp(opts, "help", 4)) {
  			pline("%s%s%s",
  "To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ",
! "give the command 'O' followed by the line `<options>' while playing. ",
  "Here <options> is a list of <option>s separated by commas." );
  			pline("%s%s%s",
  "Simple (boolean) options are rest_on_space, news, time, ",
***************
*** 149,155
  "Here <options> is a list of <option>s separated by commas." );
  			pline("%s%s%s",
  "Simple (boolean) options are rest_on_space, news, time, ",
! "null, tombstone, (fe)male. ",
  "These can be negated by prefixing them with '!' or \"no\"." );
  			pline("%s",
  "A string option is name, as in HACKOPTIONS=\"name:Merlin-W\"." );

--- 166,172 -----
  "Here <options> is a list of <option>s separated by commas." );
  			pline("%s%s%s",
  "Simple (boolean) options are rest_on_space, news, time, ",
! "null, tombstone, (fe)male, fixinvlet. ",
  "These can be negated by prefixing them with '!' or \"no\"." );
  			pline("%s",
  "A string option is name, as in HACKOPTIONS=\"name:Merlin-W\"." );
***************
*** 153,158
  "These can be negated by prefixing them with '!' or \"no\"." );
  			pline("%s",
  "A string option is name, as in HACKOPTIONS=\"name:Merlin-W\"." );
  			pline("%s%s%s",
  "A compound option is endgame; it is followed by a description of what ",
  "parts of the scorelist you want to see. You might for example say: ",

--- 170,181 -----
  "These can be negated by prefixing them with '!' or \"no\"." );
  			pline("%s",
  "A string option is name, as in HACKOPTIONS=\"name:Merlin-W\"." );
+       	       	     	pline("%s%s%s%s%s",
+ "A string option is sortobj; it is followed by a list of the 11 object ",
+ "class letters in the order you want inventories sorted.  If all 11 ",
+ "letters are not provided, unspecified items are tacked onto the end; ",
+ "a null string means do no sorting.  The default sort order is \"", 
+ SORTOBJ, "\"." );
  			pline("%s%s%s",
  "A compound option is endgame; it is followed by a description of what ",
  "parts of the scorelist you want to see. You might for example say: ",
***************
*** 160,166
  			return;
  		}
  		pline("Bad option: %s.", opts);
! 		pline("Type `o help<cr>' for help.");
  		return;
  	}
  	puts("Bad syntax in HACKOPTIONS.");

--- 183,189 -----
  			return;
  		}
  		pline("Bad option: %s.", opts);
! 		pline("Type `O help<cr>' for help.");
  		return;
  	}
  	puts("Bad syntax in HACKOPTIONS.");
***************
*** 187,192
  	    if(flags.notombstone) (void) strcat(buf,"notombstone,");
  	    if(flags.no_rest_on_space)
  		(void) strcat(buf,"!rest_on_space,");
  	    if(flags.end_top != 5 || flags.end_around != 4 || flags.end_own){
  		(void) sprintf(eos(buf), "endgame: %u topscores/%u around me",
  			flags.end_top, flags.end_around);

--- 210,217 -----
  	    if(flags.notombstone) (void) strcat(buf,"notombstone,");
  	    if(flags.no_rest_on_space)
  		(void) strcat(buf,"!rest_on_space,");
+ 	    (void) strcat(buf,"sortobj:");
+ 	    (void) strcat(buf,sortlist);
  	    if(flags.end_top != 5 || flags.end_around != 4 || flags.end_own){
  		(void) sprintf(eos(buf), "endgame: %u topscores/%u around me",
  			flags.end_top, flags.end_around);
*** help.orig	Mon Dec 23 11:42:07 1985
--- help	Tue Jan  7 13:21:00 1986
***************
*** 109,114
  		They can be negated by prefixing them with '!' or "no".
  		A string option is name; it supplies the answer to the question
  		"Who are you?"; it may have a suffix.
  		A compound option is endgame; it is followed by a description
  		of what parts of the list of topscorers should be printed
  		when the game is finished.

--- 109,117 -----
  		They can be negated by prefixing them with '!' or "no".
  		A string option is name; it supplies the answer to the question
  		"Who are you?"; it may have a suffix.
+ 		A string option is sortobj; this is a list of the object
+ 		type letters in the order you would like them shown in
+ 		inventories.
  		A compound option is endgame; it is followed by a description
  		of what parts of the list of topscorers should be printed
  		when the game is finished.

-- 
LIVE:	Barry A. Burke, (617) 965-8480 x26
USPS:	Adelie Corporation, 288 Walnut St., Newtonville, MA  02160
UUCP:	..!{harvard | decvax!linus!axiom}!adelie!barry
ARPA:	adelie!barry@harvard.HARVARD.EDU, barry%adelie.UUCP@harvard.HARVARD.EDU