[comp.sources.games] v01i032: rogue - a rogue5.3 clone, Patch1

games-request@tekred.TEK.COM (05/30/87)

Submitted by: tims@zeus.TEK.COM (Tim Stoehr)
Comp.sources.games: Volume 1, Issue 32
Archive-name: rogue/Patch1

	[This shar file contains bug fixes and updates to Tim's
	 rogue 5.3 clone previously posted.  This set of patches
	 includes the necessary changes to compile and run rogue
	 on System V.
	 The file "Bugs" is Tim's buglist as he sent it to me.  Use
	 this if you make the changes by hand to your source files
	 (because you already changed them, for instance).  The file
	 "Patches01" is a set of diffs suitable for using with the
	 patch(1) program.  Just type "patch <Patches01".  This is
	 the easiest way to make the changes.  The file "machdep.c"
	 is a complete replacement for the original machdep.c file.
	 Remove the original machdep.c before unsharing this posting
	 (it won't overwrite).
	 I also want to add my thanks to those people who helped in
	 making this program more robust and portable.  Additional
	 fixes/suggestions/whatever should be directed to Tim.  -br]

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Bugs Patches01 machdep.c
# Wrapped by billr@tekred on Fri May 29 15:08:32 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Bugs -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Bugs\"
else
echo shar: Extracting \"Bugs\" \(5822 characters\)
sed "s/^X//" >Bugs <<'END_OF_Bugs'
X
XHere is a list of fixes for bugs and non-portable items found in my
Xrogue clone.  Many thanks to those who reported the problems, I would
Xappreciate any further reports, particularly if the stuff below does
Xnot fix what it is intended to fix.
X			Tim Stoehr
X			tims@zeus.TEK.COM
X	----------------------------------------------------
X
X 1.)    To implement the ',' command, which allows the rogue to pick up
X        an item he is currently standing on, do the following:
X            a.)   Add the following case into the large switch statement
X                  in the routine play_level() in play.c:
X                  case ',':
X                        kick_into_pack();
X                        break;
X            b.)  Add the following routine at the bottom of pack.c:
X
Xkick_into_pack()
X{
X    object *obj;
X    char desc[DCOLS];
X    short n, stat;
X
X    if (!(dungeon[rogue.row][rogue.col] & OBJECT)) {
X        message("nothing here", 0);
X    } else {
X        if (obj = pick_up(rogue.row, rogue.col, &stat)) {
X            get_desc(obj, desc);
X            if (obj->what_is == GOLD) {
X                message(desc, 0);
X                free_object(obj);
X            } else {
X                n = strlen(desc);
X                desc[n] = '(';
X                desc[n+1] = obj->ichar;
X                desc[n+2] = ')';
X                desc[n+3] = 0;
X                message(desc, 0);
X            }
X        }
X        if (obj || (!stat)) {
X            (void) reg_move();
X        }
X    }
X}
X
X 2.)    In score.c, there is a bug.  In the routine get_value(), add the
X        following case to the existing switch statement:
X
X        case RING:
X            val = id_rings[wc].value * (obj->class + 1);
X            break;
X
X 3.)    In message.c, change any occurrence of %D to %ld, for portability.
X
X 4.)    In message.c, there is a line that looks like:
X
X        sprintf(buf, "%d", rogue.gold);
X        or
X        sprintf(buf, "%D", rogue.gold);
X
X        Change this line to:
X
X        sprintf(buf, "%ld", rogue.gold);
X
X        Do the same for the line in score.c, in the routine killed_by(),
X        which looks like this:
X
X        sprintf(buf+strlen(buf), "%d gold", rogue.gold);
X
X        That is, change the %d (or %D) to %ld.
X
X 5.)    In message.c, delete the line in rgetchar(), that looks like this:
X
X            printf(CL);
X
X        if CL is undefined during compilation.
X
X 6.)    Delete the routine free_free_list() in object.c, and any calls to it.
X
X 7.)    In the Makefile, UNIX_SYSV (system V) folks may not need -ltermlib.
X        And folks with Microport sysV for PC/AT's will need to link with -Ml.
X
X 8.)    In move.c, in the function gr_dir(), add break clauses to each of
X        the cases in the switch statement.  This is a bug.
X
X 9.)    In init.c, change the global variable restore_file to rest_file, as
X        well as all occurrences of that variable in init.c.
X        This keeps some linkers from confusing the name 'restore_file' with
X        the routine called 'restore' in save.c.
X
X10.)    Replace your version of the function get_rand() in random.c with
X        the version given below.  This is extremely important for machines
X        with 16-bit (as opposed to 32-bit) integers.
X
Xget_rand(x, y)
Xregister int x, y;
X{
X    register int r, t;
X    long lr;
X
X    if (x > y) {
X        t = y;
X        y = x;
X        x = t;
X    }
X    lr = rrandom();
X    lr &= (long) 0x00007fff;
X    r = (int) lr;
X    r = (r % ((y - x) + 1)) + x;
X    return(r);
X}
X
X11.)    In level.c, replace the declaration and initialization of
X        random_rooms with the following:
X
X        short random_rooms[MAXROOMS] = {3, 7, 5, 2, 0, 6, 1, 4, 8};
X
X		This is probably just cosmetic.
X
X12.)    In zap.c, replace the function tele_away() with the following version:
X
Xtele_away(monster)
Xobject *monster;
X{
X    short row, col;
X
X    if (monster->m_flags & HOLDS) {
X        being_held = 0;
X    }
X    gr_row_col(&row, &col, (FLOOR | TUNNEL | STAIRS | OBJECT));
X    mvaddch(monster->row, monster->col, monster->trail_char);
X    dungeon[monster->row][monster->col] &= ~MONSTER;
X    monster->row = row; monster->col = col;
X    dungeon[row][col] |= MONSTER;
X    monster->trail_char = mvinch(row, col);
X    if (detect_monster || rogue_can_see(row, col)) {
X        mvaddch(row, col, gmc(monster));
X    }
X}
X
X 13.)    In init.c, replace the function start_window() with the following
Xversion:
X
Xstart_window()
X{
X	crmode();
X	noecho();
X#ifndef BAD_NONL
X	nonl();
X#endif BAD_NONL
X	md_control_keybord(0);
X}
X
X        The symbol BAD_NONL is to be defined during compilation on systems
X	whose curses library has a buggy nonl() function/macro.  This may
X	be noticed if the game draws things on the wrong lines, particularly
X	during score file display.  Nonl() is not really necessary, although
X	it is a nice optimization for curses.
X
X 14.) In the routine inventory() in inventory.c:
X
X	for (j = 1; j < i; j++) {
X		mvaddstr(j, col, descs[j-1]);
X	}
X
Xshould be changed to:
X
X	for (j = 1; ((j < i) && (j < DROWS)); j++) {
X		mvaddstr(j, col, descs[j-1]);
X	}
X
X	This might cause some problems if the player fills his pack and has no
X	duplicate items.  The inventory, plus prompt line, would go one line
X	past the status line.
X
X 15.) Some compilers are sensitive about names after a #endif, e.g.
X	#ifdef NAME
X	#endif NAME
XIf this happens to you, simply change #endif NAME to #endif /* NAME */.
X
X 16.) [Optional] For general cleanup, in rogue.h insert the following
X	just prior to the #endif CURSES line (at the end of the file):
X
X	#else
X	#include <curses.h>
X
XThen delete the three lines:
X
X	#ifndef CURSES
X	#include <curses.h>
X	#endif CURSES
X
Xthat appear at the top of every file except main.c, random.c and ring.c.
X
X 17.) Replace the file machdep.c with the one included in this posting.
X
X 18.) Create a new file "patchlevel.h" that has a single line in it:
X
X	#define PATCHLEVEL 1
END_OF_Bugs
if test 5822 -ne `wc -c <Bugs`; then
    echo shar: \"Bugs\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Patches01 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Patches01\"
else
echo shar: Extracting \"Patches01\" \(14080 characters\)
sed "s/^X//" >Patches01 <<'END_OF_Patches01'
X*** Makefile.orig	Mon May 11 12:10:18 1987
X--- Makefile	Thu May 28 15:24:33 1987
X***************
X*** 4,19 ****
X  
X  CC = cc
X  
X! # Remember to remove the "-lcurses -ltermlib" if compiling with -DCURSES.
X! # Put into CFLAGS those UNIX "defines" which apply to your system.  Their
X! # should be at least two.
X! # -DCURSES enables a self-contained curses emulation package.  See notes
X! # in curses.c for more info.
X  
X! CFLAGS = -c -DUNIX -DUNIX_BSD4_2
X  
X  rogue: $(ROGUE_OBJS)
X! 	$(CC) $(ROGUE_OBJS) -lcurses -ltermlib -o rogue
X  
X  curses.o: curses.c rogue.h
X  	$(CC) $(CFLAGS) curses.c
X--- 4,39 ----
X  
X  CC = cc
X  
X! # Put into CFLAGS those UNIX "defines" which apply to your system.
X! #
X! # Options:
X! #	-DUNIX		for all Unix based systems
X! #	-DUNIX_BSD4_2	for most BSD based Unix systems
X! #	-DUNIX_SYSV	for System V based Unix systems
X! #	-DBAD_NONL	for systems with the nonl() curses bug
X! #	-DCURSES 	enables a self-contained curses emulation package
X! # 			Remember to remove the "-lcurses -ltermlib"
X! #			if compiling with -DCURSES.
X! #	-Ml		compile with large model (SysV PC/AT's)
X  
X! CFLAGS = -c -DUNIX -DUNIX_BSD4_2	# BSD4.[23]
X! #CFLAGS = -c -DUNIX -DUNIX_SYSV		# Vanilla SysV
X! #CFLAGS = -c -DUNIX -DUNIX_SYSV -DINT16 -Ml # Microport SysV, Rel2 for PC/AT
X  
X+ # Put into LDFLAGS those options which apply to your system.
X+ #
X+ # Options:
X+ #	-lcurses	use standard curses package
X+ #	-ltermlib	to extract terminal capabilities
X+ #	-Ml		link with large model (SysV PC/AT's)
X+ 
X+ LDFLAGS = -lcurses -ltermlib	# Vanilla BSD and SysV
X+ #LDFLAGS = -Ml -lcurses		# Microport SysV, Rel2 for PC/AT
X+ #LDFLAGS =			# for use with self-contained curses
X+ 				# package (-DCURSES)
X+ 
X  rogue: $(ROGUE_OBJS)
X! 	$(CC) $(ROGUE_OBJS) $(LDFLAGS) -o rogue
X  
X  curses.o: curses.c rogue.h
X  	$(CC) $(CFLAGS) curses.c
X*** rogue.h.orig	Mon May 11 12:10:22 1987
X--- rogue.h	Fri May 29 14:18:42 1987
X***************
X*** 435,439 ****
X  extern char *CL;
X  
X  char *md_gdtcf();
X! 
X! #endif CURSES
X--- 435,440 ----
X  extern char *CL;
X  
X  char *md_gdtcf();
X! #else
X! #include <curses.h>
X! #endif /* CURSES */
X*** /dev/null	Fri May 29 14:38:00 1987
X--- patchlevel.h	Thu May 28 15:06:56 1987
X***************
X*** 0 ****
X--- 1 ----
X+ #define PATCHLEVEL 1
X*** curses.c.orig	Mon May 11 12:10:43 1987
X--- curses.c	Fri May 29 14:19:41 1987
X***************
X*** 647,650 ****
X  	cm_end[j] = 0;
X  }
X  
X! #endif CURSES
X--- 647,650 ----
X  	cm_end[j] = 0;
X  }
X  
X! #endif /* CURSES */
X*** hit.c.orig	Mon May 11 12:10:24 1987
X--- hit.c	Fri May 29 14:20:03 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  object *fight_monster = 0;
X--- 10,15 ----
X*** init.c.orig	Mon May 11 12:10:25 1987
X--- init.c	Fri May 29 14:20:21 1987
X***************
X*** 10,24 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include <stdio.h>
X  #include "rogue.h"
X  
X  char login_name[30];
X  char *nick_name = "";
X! char *restore_file = 0;
X  boolean cant_int = 0, did_int = 0, score_only, init_curses = 0;
X  boolean save_is_interactive = 1;
X  boolean ask_quit = 1, show_skull = 1;
X--- 10,21 ----
X   *
X   */
X  
X  #include <stdio.h>
X  #include "rogue.h"
X  
X  char login_name[30];
X  char *nick_name = "";
X! char *rest_file = 0;
X  boolean cant_int = 0, did_int = 0, score_only, init_curses = 0;
X  boolean save_is_interactive = 1;
X  boolean ask_quit = 1, show_skull = 1;
X***************
X*** 46,52 ****
X  	}
X  	(void) strcpy(login_name, pn);
X  
X! 	if (!score_only && !restore_file) {
X  		printf("Hello %s, just a moment while I dig the dungeon...",
X  		((nick_name[0]) ? nick_name : login_name));
X  		fflush(stdout);
X--- 43,49 ----
X  	}
X  	(void) strcpy(login_name, pn);
X  
X! 	if (!score_only && !rest_file) {
X  		printf("Hello %s, just a moment while I dig the dungeon...",
X  		((nick_name[0]) ? nick_name : login_name));
X  		fflush(stdout);
X***************
X*** 66,73 ****
X  	}
X  	seed = md_gseed();
X  	(void) srrandom(seed);
X! 	if (restore_file) {
X! 		restore(restore_file);
X  		return(1);
X  	}
X  	mix_colors();
X--- 63,70 ----
X  	}
X  	seed = md_gseed();
X  	(void) srrandom(seed);
X! 	if (rest_file) {
X! 		restore(rest_file);
X  		return(1);
X  	}
X  	mix_colors();
X***************
X*** 148,154 ****
X--- 145,153 ----
X  {
X  	crmode();
X  	noecho();
X+ #ifndef BAD_NONL
X  	nonl();
X+ #endif /* BAD_NONL */
X  	md_control_keybord(0);
X  }
X  
X***************
X*** 204,210 ****
X  				}
X  			}
X  		} else {
X! 			restore_file = argv[i];
X  		}
X  	}
X  }
X--- 203,209 ----
X  				}
X  			}
X  		} else {
X! 			rest_file = argv[i];
X  		}
X  	}
X  }
X*** inventory.c.orig	Mon May 11 12:10:28 1987
X--- inventory.c	Fri May 29 14:20:35 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  #define swap_string(x,y) {t = x; x = y; y = t;}
X--- 10,15 ----
X***************
X*** 165,171 ****
X  	move(0, 0);
X  	clrtoeol();
X  
X! 	for (j = 1; j < i; j++) {
X  		mvaddstr(j, col, descs[j-1]);
X  	}
X  }
X--- 162,168 ----
X  	move(0, 0);
X  	clrtoeol();
X  
X! 	for (j = 1; ((j < i) && (j < DROWS)); j++) {
X  		mvaddstr(j, col, descs[j-1]);
X  	}
X  }
X*** level.c.orig	Mon May 11 12:10:34 1987
X--- level.c	Fri May 29 14:20:48 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  #define swap(x,y) {t = x; x = y; y = t;}
X--- 10,15 ----
X***************
X*** 46,52 ****
X  	99900000L
X  };
X  
X! char random_rooms[MAXROOMS+1] = "\003\007\005\002\010\006\001\004\0";
X  
X  extern boolean being_held, wizard, detect_monster;
X  extern boolean see_invisible;
X--- 43,49 ----
X  	99900000L
X  };
X  
X! short random_rooms[MAXROOMS] = {3, 7, 5, 2, 0, 6, 1, 4, 8};
X  
X  extern boolean being_held, wizard, detect_monster;
X  extern boolean see_invisible;
X*** message.c.orig	Mon May 11 12:10:37 1987
X--- message.c	Fri May 29 14:21:38 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include <stdio.h>
X  #include "rogue.h"
X  
X--- 10,15 ----
X***************
X*** 150,156 ****
X  			fflush(stdout);
X  			tstp();
X  			break;
X! #endif UNIX_BSD4_2
X  		case 'X':
X  			save_screen();
X  			break;
X--- 147,153 ----
X  			fflush(stdout);
X  			tstp();
X  			break;
X! #endif /* UNIX_BSD4_2 */
X  		case 'X':
X  			save_screen();
X  			break;
X***************
X*** 189,195 ****
X  			}
X  			mvaddstr(row, 10, "Gold: ");
X  		}
X! 		sprintf(buf, "%d", rogue.gold);
X  		mvaddstr(row, 16, buf);
X  		pad(buf, 6);
X  	}
X--- 186,192 ----
X  			}
X  			mvaddstr(row, 10, "Gold: ");
X  		}
X! 		sprintf(buf, "%ld", rogue.gold);
X  		mvaddstr(row, 16, buf);
X  		pad(buf, 6);
X  	}
X***************
X*** 234,240 ****
X  			mvaddstr(row, 56, "Exp: ");
X  		}
X  		/*  Max exp taken care of in add_exp() */
X! 		sprintf(buf, "%d/%D", rogue.exp, rogue.exp_points);
X  		mvaddstr(row, 61, buf);
X  		pad(buf, 11);
X  	}
X--- 231,237 ----
X  			mvaddstr(row, 56, "Exp: ");
X  		}
X  		/*  Max exp taken care of in add_exp() */
X! 		sprintf(buf, "%d/%ld", rogue.exp, rogue.exp_points);
X  		mvaddstr(row, 61, buf);
X  		pad(buf, 11);
X  	}
X*** monster.c.orig	Mon May 11 12:10:41 1987
X--- monster.c	Fri May 29 14:21:49 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  object level_monsters;
X--- 10,15 ----
X*** move.c.orig	Mon May 11 12:10:48 1987
X--- move.c	Fri May 29 14:22:01 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  short m_moves = 0;
X--- 10,15 ----
X***************
X*** 449,468 ****
X--- 446,473 ----
X  	switch(d) {
X  		case 1:
X  			d = 'j';
X+ 			break;
X  		case 2:
X  			d = 'k';
X+ 			break;
X  		case 3:
X  			d = 'l';
X+ 			break;
X  		case 4:
X  			d = 'h';
X+ 			break;
X  		case 5:
X  			d = 'y';
X+ 			break;
X  		case 6:
X  			d = 'u';
X+ 			break;
X  		case 7:
X  			d = 'b';
X+ 			break;
X  		case 8:
X  			d = 'n';
X+ 			break;
X  	}
X  	return(d);
X  }
X*** object.c.orig	Mon May 11 12:11:06 1987
X--- object.c	Fri May 29 14:22:10 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  object level_objects;
X--- 10,15 ----
X***************
X*** 240,256 ****
X  	}
X  }
X  
X- free_free_list()
X- {
X- 	object *obj;
X- 
X- 	while (free_list) {
X- 		obj = free_list;
X- 		free_list = free_list->next_object;
X- 		free_object(obj);
X- 	}
X- }
X- 
X  char *
X  name_of(obj)
X  object *obj;
X--- 237,242 ----
X***************
X*** 593,599 ****
X  		obj = free_list;
X  		free_list = free_list->next_object;
X  	} else if (!(obj = (object *) md_malloc(sizeof(object)))) {
X- 			free_free_list();
X  			message("cannot allocate object, saving game", 0);
X  			save_into_file(error_file);
X  	}
X--- 579,584 ----
X*** pack.c.orig	Mon May 11 12:11:20 1987
X--- pack.c	Fri May 29 14:22:20 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  char *curse_message = "you can't, it appears to be cursed";
X--- 10,15 ----
X***************
X*** 486,489 ****
X--- 483,515 ----
X  has_amulet()
X  {
X  	return(mask_pack(&rogue.pack, AMULET));
X+ }
X+ 
X+ kick_into_pack()
X+ {
X+ 	object *obj;
X+ 	char desc[DCOLS];
X+ 	short n, stat;
X+ 
X+ 	if (!(dungeon[rogue.row][rogue.col] & OBJECT)) {
X+ 		message("nothing here", 0);
X+ 	} else {
X+ 		if (obj = pick_up(rogue.row, rogue.col, &stat)) {
X+ 			get_desc(obj, desc);
X+ 			if (obj->what_is == GOLD) {
X+ 				message(desc, 0);
X+ 				free_object(obj);
X+ 			} else {
X+ 				n = strlen(desc);
X+ 				desc[n] = '(';
X+ 				desc[n+1] = obj->ichar;
X+ 				desc[n+2] = ')';
X+ 				desc[n+3] = 0;
X+ 				message(desc, 0);
X+ 			}
X+ 		}
X+ 		if (obj || (!stat)) {
X+ 			(void) reg_move();
X+ 		}
X+ 	}
X  }
X*** play.c.orig	Mon May 11 12:11:23 1987
X--- play.c	Fri May 29 14:22:29 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  boolean interrupted = 0;
X--- 10,15 ----
X***************
X*** 232,237 ****
X--- 229,237 ----
X  			break;
X  		case 'S':
X  			save_game();
X+ 			break;
X+ 		case ',':
X+ 			kick_into_pack();
X  			break;
X  		default:
X  			message(unknown_command, 0);
X*** random.c.orig	Mon May 11 12:11:32 1987
X--- random.c	Thu May 28 15:04:24 1987
X***************
X*** 61,74 ****
X  register int x, y;
X  {
X  	register int r, t;
X! 
X  	if (x > y) {
X  		t = y;
X  		y = x;
X  		x = t;
X  	}
X! 	r = (int) rrandom();
X! 	r = (r % ((y-x)+1)) + x;
X  	return(r);
X  }
X  
X--- 61,77 ----
X  register int x, y;
X  {
X  	register int r, t;
X! 	long lr;
X! 	
X  	if (x > y) {
X  		t = y;
X  		y = x;
X  		x = t;
X  	}
X! 	lr = rrandom();
X! 	lr &= (long) 0x00007fff;
X! 	r = (int) lr;
X! 	r = (r % ((y - x) + 1)) + x;
X  	return(r);
X  }
X  
X*** room.c.orig	Mon May 11 12:11:37 1987
X--- room.c	Fri May 29 14:22:54 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  room rooms[MAXROOMS];
X--- 10,15 ----
X*** save.c.orig	Mon May 11 12:11:40 1987
X--- save.c	Fri May 29 14:24:31 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include <stdio.h>
X  #include "rogue.h"
X  
X--- 10,15 ----
X*** score.c.orig	Mon May 11 12:11:46 1987
X--- score.c	Fri May 29 14:25:01 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include <stdio.h>
X  #include "rogue.h"
X  
X--- 10,15 ----
X***************
X*** 61,67 ****
X  		(void) strcat(buf, m_names[monster->m_char - 'A']);
X  	}
X  	(void) strcat(buf, " with ");
X! 	sprintf(buf+strlen(buf), "%d gold", rogue.gold);
X  	if ((!other) && show_skull) {
X  		clear();
X  		mvaddstr(4, 32, "__---------__");
X--- 58,64 ----
X  		(void) strcat(buf, m_names[monster->m_char - 'A']);
X  	}
X  	(void) strcat(buf, " with ");
X! 	sprintf(buf+strlen(buf), "%ld gold", rogue.gold);
X  	if ((!other) && show_skull) {
X  		clear();
X  		mvaddstr(4, 32, "__---------__");
X***************
X*** 414,419 ****
X--- 411,419 ----
X  		break;
X  	case AMULET:
X  		val = 5000;
X+ 		break;
X+ 	case RING:
X+ 		val = id_rings[wc].value * (obj->class + 1);
X  		break;
X  	}
X  	if (val <= 0) {
X*** spec_hit.c.orig	Mon May 11 12:10:52 1987
X--- spec_hit.c	Fri May 29 14:25:11 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  short less_hp = 0;
X--- 10,15 ----
X*** throw.c.orig	Mon May 11 12:11:50 1987
X--- throw.c	Fri May 29 14:25:22 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  extern short cur_room;
X--- 10,15 ----
X*** trap.c.orig	Mon May 11 12:11:53 1987
X--- trap.c	Fri May 29 14:25:42 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  trap traps[MAX_TRAPS];
X--- 10,15 ----
X*** use.c.orig	Mon May 11 12:11:31 1987
X--- use.c	Fri May 29 14:25:52 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  short halluc = 0;
X--- 10,15 ----
X*** zap.c.orig	Mon May 11 12:11:55 1987
X--- zap.c	Fri May 29 14:26:04 1987
X***************
X*** 10,18 ****
X   *
X   */
X  
X- #ifndef CURSES
X- #include <curses.h>
X- #endif CURSES
X  #include "rogue.h"
X  
X  boolean wizard = 0;
X--- 10,15 ----
X***************
X*** 173,183 ****
X  		being_held = 0;
X  	}
X  	gr_row_col(&row, &col, (FLOOR | TUNNEL | STAIRS | OBJECT));
X  	dungeon[monster->row][monster->col] &= ~MONSTER;
X- 
X  	monster->row = row; monster->col = col;
X  	dungeon[row][col] |= MONSTER;
X  	monster->trail_char = mvinch(row, col);
X  }
X  
X  wizardize()
X--- 170,183 ----
X  		being_held = 0;
X  	}
X  	gr_row_col(&row, &col, (FLOOR | TUNNEL | STAIRS | OBJECT));
X+ 	mvaddch(monster->row, monster->col, monster->trail_char);
X  	dungeon[monster->row][monster->col] &= ~MONSTER;
X  	monster->row = row; monster->col = col;
X  	dungeon[row][col] |= MONSTER;
X  	monster->trail_char = mvinch(row, col);
X+ 	if (detect_monster || rogue_can_see(row, col)) {
X+ 		mvaddch(row, col, gmc(monster));
X+ 	}
X  }
X  
X  wizardize()
END_OF_Patches01
if test 14080 -ne `wc -c <Patches01`; then
    echo shar: \"Patches01\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f machdep.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"machdep.c\"
else
echo shar: Extracting \"machdep.c\" \(16483 characters\)
sed "s/^X//" >machdep.c <<'END_OF_machdep.c'
X/*
X * machdep.c
X *
X * This source herein may be modified and/or distributed by anybody who
X * so desires, with the following restrictions:
X *    1.)  No portion of this notice shall be removed.
X *    2.)  Credit shall not be taken for the creation of this source.
X *    3.)  This code is not to be traded, sold, or used for personal
X *         gain or profit.
X *
X */
X
X/* Included in this file are all system dependent routines.  Extensive use
X * of #ifdef's will be used to compile the appropriate code on each system:
X *
X *    UNIX:        all UNIX systems.
X *    UNIX_BSD4_2: UNIX BSD 4.2 and later, UTEK, (4.1 BSD too?)
X *    UNIX_SYSV:   UNIX system V
X *    UNIX_V7:     UNIX version 7
X *
X * All UNIX code should be included between the single "#ifdef UNIX" at the
X * top of this file, and the "#endif UNIX" at the bottom.
X * 
X * To change a routine to include a new UNIX system, simply #ifdef the
X * existing routine, as in the following example:
X *
X *   To make a routine compatible with UNIX system V, change the first
X *   function to the second:
X *
X *      md_function()
X *      {
X *         code;
X *      }
X *
X *      md_function()
X *      {
X *      #ifdef UNIX_SYSV
X *         sysVcode;
X *      #else
X *         code;
X *      #endif /* UNIX_SYSV */
X *      }
X *
X * Appropriate variations of this are of course acceptible.
X * The use of "#elseif" is discouraged because of non-portability.
X * If the correct #define doesn't exist, "UNIX_SYSV" in this case, make it up
X * and insert it in the list at the top of the file.  Alter the CFLAGS
X * in you Makefile appropriately.
X *
X */
X
X#ifdef UNIX
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/file.h>
X#include <sys/stat.h>
X
X#ifdef UNIX_SYSV
X#include <time.h>
X#include <termio.h>
X#endif /* UNIX_SYSV */
X#ifdef UNIX_BSD4_2
X#include <sys/time.h>
X#include <sgtty.h>
X#endif /* UNIX_BSD4_2 */
X
X#include <signal.h>
X#include "rogue.h"
X
X/* md_slurp:
X *
X * This routine throws away all keyboard input that has not
X * yet been read.  It is used to get rid of input that the user may have
X * typed-ahead.
X *
X * This function is not necessary, so it may be stubbed.  The might cause
X * message-line output to flash by because the game has continued to read
X * input without waiting for the user to read the message.  Not such a
X * big deal.
X */
X
Xmd_slurp()
X{
X	long ln;
X
X#ifdef UNIX_BSD4_2
X	ioctl(0, TIOCFLUSH, &ln);
X#endif /* UNIX_BSD4_2 */
X#ifdef UNIX_SYSV
X	ioctl(0, TCFLSH, &ln);
X#endif /* UNIX_SYSV */
X
X	for (ln = stdin->_cnt; ln > 0; ln--) {
X		(void) getchar();
X	}
X}
X
X/* md_control_keyboard():
X *
X * This routine is much like md_cbreak_no_echo_nonl() below.  It sets up the
X * keyboard for appropriate input.  Specifically, it prevents the tty driver
X * from stealing characters.  For example, ^Y is needed as a command
X * character, but the tty driver intercepts it for another purpose.  Any
X * such behavior should be stopped.  This routine could be avoided if
X * we used RAW mode instead of CBREAK.  But RAW mode does not allow the
X * generation of keyboard signals, which the program uses.
X *
X * The parameter 'mode' when true, indicates that the keyboard should
X * be set up to play rogue.  When false, it should be restored if
X * necessary.
X *
X * This routine is not strictly necessary and may be stubbed.  This may
X * cause certain command characters to be unavailable.
X */
X
Xmd_control_keybord(mode)
Xboolean mode;
X{
X	static boolean called_before = 0;
X#ifdef UNIX_BSD4_2
X	static struct ltchars ltc_orig;
X	static struct tchars tc_orig;
X	struct ltchars ltc_temp;
X	struct tchars tc_temp;
X#endif /* UNIX_BSD4_2 */
X#ifdef UNIX_SYSV
X	static struct termio _oldtty;
X	struct termio _tty;
X#endif /* UNIX_SYSV */
X
X	if (!called_before) {
X		called_before = 1;
X#ifdef UNIX_BSD4_2
X		ioctl(0, TIOCGETC, &tc_orig);
X		ioctl(0, TIOCGLTC, &ltc_orig);
X#endif /* UNIX_BSD4_2 */
X#ifdef UNIX_SYSV
X		ioctl(0, TCGETA, &_oldtty);
X#endif /* UNIX_SYSV */
X	}
X#ifdef UNIX_BSD4_2
X	ltc_temp = ltc_orig;
X	tc_temp = tc_orig;
X#endif /* UNIX_BSD4_2 */
X#ifdef UNIX_SYSV
X	_tty = _oldtty;
X#endif /* UNIX_SYSV */
X
X	if (!mode) {
X#ifdef UNIX_BSD4_2
X		ltc_temp.t_suspc = ltc_temp.t_dsuspc = -1;
X		ltc_temp.t_rprntc = ltc_temp.t_flushc = -1;
X		ltc_temp.t_werasc = ltc_temp.t_lnextc = -1;
X		tc_temp.t_startc = tc_temp.t_stopc = -1;
X#endif /* UNIX_BSD4_2 */
X#ifdef UNIX_SYSV
X		_tty.c_cc[VSWTCH] = CNSWTCH;
X#endif /* UNIX_SYSV */
X	}
X#ifdef UNIX_BSD4_2
X	ioctl(0, TIOCSETC, &tc_temp);
X	ioctl(0, TIOCSLTC, &ltc_temp);
X#endif /* UNIX_BSD4_2 */
X#ifdef UNIX_SYSV
X	ioctl(0, TCSETA, &_tty);
X#endif /* UNIX_SYSV */
X}
X
X/* md_heed_signals():
X *
X * This routine tells the program to call particular routines when
X * certain interrupts/events occur:
X *
X *      SIGINT: call onintr() to interrupt fight with monster or long rest.
X *      SIGQUIT: call byebye() to check for game termination.
X *      SIGHUP: call error_save() to save game when terminal hangs up.
X *
X *		On VMS, SIGINT and SIGQUIT correspond to ^C and ^Y.
X *
X * This routine is not strictly necessary and can be stubbed.  This will
X * mean that the game cannot be interrupted properly with keyboard
X * input, this is not usually critical.
X */
X
Xmd_heed_signals()
X{
X	signal(SIGINT, onintr);
X	signal(SIGQUIT, byebye);
X	signal(SIGHUP, error_save);
X}
X
X/* md_ignore_signals():
X *
X * This routine tells the program to completely ignore the events mentioned
X * in md_heed_signals() above.  The event handlers will later be turned on
X * by a future call to md_heed_signals(), so md_heed_signals() and
X * md_ignore_signals() need to work together.
X *
X * This function should be implemented or the user risks interrupting
X * critical sections of code, which could cause score file, or saved-game
X * file, corruption.
X */
X
Xmd_ignore_signals()
X{
X	signal(SIGQUIT, SIG_IGN);
X	signal(SIGINT, SIG_IGN);
X	signal(SIGHUP, SIG_IGN);
X}
X
X/* md_get_file_id():
X *
X * This function returns an integer that uniquely identifies the specified
X * file.  It need not check for the file's existence.  In UNIX, the inode
X * number is used.
X *
X * This function need not be implemented.  To stub the routine, just make
X * it return 0.  This will make the game less able to prevent users from
X * modifying saved-game files.  This is probably no big deal.
X */
X
Xint
Xmd_get_file_id(fname)
Xchar *fname;
X{
X	struct stat sbuf;
X
X	if (stat(fname, &sbuf)) {
X		return(-1);
X	}
X	return((int) sbuf.st_ino);
X}
X
X/* md_link_count():
X *
X * This routine returns the number of hard links to the specified file.
X *
X * This function is not strictly necessary.  On systems without hard links
X * this routine can be stubbed by just returning 1.
X */
X
Xint
Xmd_link_count(fname)
Xchar *fname;
X{
X	struct stat sbuf;
X
X	stat(fname, &sbuf);
X	return((int) sbuf.st_nlink);
X}
X
X/* md_gct(): (Get Current Time)
X *
X * This function returns the current year, month(1-12), day(1-31), hour(0-23),
X * minute(0-59), and second(0-59).  This is used for identifying the time
X * at which a game is saved.
X *
X * This function is not strictly necessary.  It can be stubbed by returing
X * zeros instead of the correct year, month, etc.  If your operating
X * system doesn't provide all of the time units requested here, then you
X * can provide only those that it does, and return zeros for the others.
X * If you cannot provide good time values, then users may be able to copy
X * saved-game files and play them.  
X */
X
Xmd_gct(rt_buf)
Xstruct rogue_time *rt_buf;
X{
X	struct tm *t, *localtime();
X	long seconds;
X
X	time(&seconds);
X	t = localtime(&seconds);
X
X	rt_buf->year = t->tm_year;
X	rt_buf->month = t->tm_mon + 1;
X	rt_buf->day = t->tm_mday;
X	rt_buf->hour = t->tm_hour;
X	rt_buf->minute = t->tm_min;
X	rt_buf->second = t->tm_sec;
X}
X
X/* md_gfmt: (Get File Modification Time)
X *
X * This routine returns a file's date of last modification in the same format
X * as md_gct() above.
X *
X * This function is not strictly necessary.  It is used to see if saved-game
X * files have been modified since they were saved.  If you have stubbed the
X * routine md_gct() above by returning constant values, then you may do
X * exactly the same here.
X * Or if md_gct() is implemented correctly, but your system does not provide
X * file modification dates, you may return some date far in the past so
X * that the program will never know that a saved-game file being modified.  
X * You may also do this if you wish to be able to restore games from
X * saved-games that have been modified.
X */
X
Xmd_gfmt(fname, rt_buf)
Xchar *fname;
Xstruct rogue_time *rt_buf;
X{
X	struct stat sbuf;
X	long seconds;
X	struct tm *t;
X
X	stat(fname, &sbuf);
X	seconds = (long) sbuf.st_mtime;
X	t = localtime(&seconds);
X
X	rt_buf->year = t->tm_year;
X	rt_buf->month = t->tm_mon + 1;
X	rt_buf->day = t->tm_mday;
X	rt_buf->hour = t->tm_hour;
X	rt_buf->minute = t->tm_min;
X	rt_buf->second = t->tm_sec;
X}
X
X/* md_df: (Delete File)
X *
X * This function deletes the specified file, and returns true (1) if the
X * operation was successful.  This is used to delete saved-game files
X * after restoring games from them.
X *
X * Again, this function is not strictly necessary, and can be stubbed
X * by simply returning 1.  In this case, saved-game files will not be
X * deleted and can be replayed.
X */
X
Xboolean
Xmd_df(fname)
Xchar *fname;
X{
X	if (unlink(fname)) {
X		return(0);
X	}
X	return(1);
X}
X
X/* md_gln: (Get login name)
X *
X * This routine returns the login name of the user.  This string is
X * used mainly for identifying users in score files.
X *
X * A dummy string may be returned if you are unable to implement this
X * function, but then the score file would only have one name in it.
X */
X
Xchar *
Xmd_gln()
X{
X	char *getlogin();
X	char *t;
X
X	t = getlogin();
X	return(t);
X}
X
X/* md_sleep:
X *
X * This routine causes the game to pause for the specified number of
X * seconds.
X *
X * This routine is not necessary at all, and can be stubbed with no ill
X * effects.
X */
X
Xmd_sleep(nsecs)
Xint nsecs;
X{
X	(void) sleep(nsecs);
X}
X
X/* md_getenv()
X *
X * This routine gets certain values from the user's environment.  These
X * values are strings, and each string is identified by a name.  The names
X * of the values needed, and their use, is as follows:
X *
X *   TERMCAP
X *     The name of the users's termcap file, NOT the termcap entries
X *     themselves.  This is used ONLY if the program is compiled with
X *     CURSES defined (-DCURSES).  Even in this case, the program need
X *     not find a string for TERMCAP.  If it does not, it will use the
X *     default termcap file as returned by md_gdtcf();
X *   TERM
X *     The name of the users's terminal.  This is used ONLY if the program
X *     is compiled with CURSES defined (-DCURSES).  In this case, the string
X *     value for TERM must be found, or the routines in curses.c cannot
X *     function, and the program will quit.
X *   ROGUEOPTS
X *     A string containing the various game options.  This need not be
X *     defined.
X *   HOME
X *     The user's home directory.  This is only used when the user specifies
X *     '~' as the first character of a saved-game file.  This string need
X *     not be defined.
X *
X * If your system does not provide a means of searching for these values,
X * you will have to do it yourself.  None of the values above really need
X * to be defined except TERM when the program is compiled with CURSES
X * defined.  In this case, as a bare minimum, you can check the 'name'
X * parameter, and if it is "TERM" find the terminal name and return that,
X * else return zero.  If the program is not compiled with CURSES, you can
X * get by with simply always returning zero.  Returning zero indicates
X * that their is no defined value for the given string.
X */
X
Xchar *
Xmd_getenv(name)
Xchar *name;
X{
X	char *value;
X	char *getenv();
X
X	value = getenv(name);
X
X	return(value);
X}
X
X/* md_malloc()
X *
X * This routine allocates, and returns a pointer to, the specified number
X * of bytes.  This routines absolutely MUST be implemented for your
X * particular system or the program will not run at all.  Return zero
X * when no more memory can be allocated.
X */
X
Xchar *
Xmd_malloc(n)
Xint n;
X{
X	char *malloc();
X	char *t;
X
X	t = malloc(n);
X	return(t);
X}
X
X/* md_gseed() (Get Seed)
X *
X * This function returns a seed for the random number generator (RNG).  This
X * seed causes the RNG to begin generating numbers at some point in it's
X * sequence.  Without a random seed, the RNG will generate the same set
X * of numbers, and every game will start out exactly the same way.  A good
X * number to use is the process id, given by getpid() on most UNIX systems.
X *
X * You need to find some single random integer, such as:
X *   process id.
X *   current time (minutes + seconds) returned from md_gct(), if implemented.
X *   
X * It will not help to return "get_rand()" or "rand()" or the return value of
X * any pseudo-RNG.  If you don't have a random number, you can just return 1,
X * but this means your games will ALWAYS start the same way, and will play
X * exactly the same way given the same input.
X */
X
Xmd_gseed()
X{
X	return(getpid());
X}
X
X/* md_exit():
X *
X * This function causes the program to discontinue execution and exit.
X * This function must be implemented or the program will continue to
X * hang when it should quit.
X */
X
Xmd_exit(status)
Xint status;
X{
X	exit(status);
X}
X
X/* If you have a viable curses/termlib library, then use it and don't bother
X * implementing the routines below.  And don't compile with -DCURSES.
X */
X
X#ifdef CURSES
X
X/* md_cbreak_no_echo_nonl:
X *
X * This routine sets up some terminal characteristics.  The tty-driver
X * must be told to:
X *   1.)  Not echo input.
X *   2.)  Transmit input characters immediately upon typing. (cbreak mode)
X *   3.)  Move the cursor down one line, without changing column, and
X *        without generating a carriage-return, when it
X *        sees a line-feed.  This is only necessary if line-feed is ever
X *        used in the termcap 'do' (cursor down) entry, in which case,
X *        your system should must have a way of accomplishing this.
X *
X * When the parameter 'on' is true, the terminal is set up as specified
X * above.  When this parameter is false, the terminal is restored to the
X * original state.
X *
X * Raw mode should not to be used.  Keyboard signals/events/interrupts should
X * be sent, although they are not strictly necessary.  See notes in
X * md_heed_signals().
X *
X * This function must be implemented for rogue to run properly if the
X * program is compiled with CURSES defined to use the enclosed curses
X * emulation package.  If you are not using this, then this routine is
X * totally unnecessary.
X * 
X * Notice that information is saved between calls.  This is used to
X * restore the terminal to an initial saved state.
X *
X */
X
Xmd_cbreak_no_echo_nonl(on)
Xboolean on;
X{
X#ifdef UNIX_BSD4_2
X	static struct sgttyb tty_buf;
X	static int tsave_flags;
X
X	if (on) {
X		ioctl(0, TIOCGETP, &tty_buf);
X		tsave_flags = tty_buf.sg_flags;
X		tty_buf.sg_flags |= CBREAK;
X		tty_buf.sg_flags &= ~(ECHO | CRMOD);	/* CRMOD: see note 3 above */
X		ioctl(0, TIOCSETP, &tty_buf);
X	} else {
X		tty_buf.sg_flags = tsave_flags;
X		ioctl(0, TIOCSETP, &tty_buf);
X	}
X#endif /* UNIX_BSD4_2 */
X#ifdef UNIX_SYSV
X	struct termio tty_buf;
X	static struct termio tty_save;
X
X	if (on) {
X		ioctl(0, TCGETA, &tty_buf);
X		tty_save = tty_buf;
X		tty_buf.c_lflag &= ~(ICANON | ECHO);
X		tty_buf.c_oflag &= ~ONLCR;
X		tty_buf.c_cc[4] = 1;  /* MIN */
X		tty_buf.c_cc[5] = 2;  /* TIME */
X		ioctl(0, TCSETAF, &tty_buf);
X	} else {
X		ioctl(0, TCSETAF, &tty_save);
X	}
X#endif /* UNIX_SYSV */
X}
X
X/* md_gdtcf(): (Get Default Termcap File)
X *
X * This function is called ONLY when the program is compiled with CURSES
X * defined.  If you use your system's curses/termlib library, this function
X * won't be called.  On most UNIX systems, "/etc/termcap" suffices.
X *
X * If their is no such termcap file, then return 0, but in that case, you
X * must have a TERMCAP file returned from md_getenv("TERMCAP").  The latter
X * will override the value returned from md_gdtcf().  If the program is
X * compiled with CURSES defined, and md_gdtcf() returns 0, and
X * md_getenv("TERMCAP") returns 0, the program will have no terminal
X * capability information and will quit.
X */
X
Xchar *
Xmd_gdtcf()
X{
X	return("/etc/termcap");
X}
X
X/* md_tstp():
X *
X * This function puts the game to sleep and returns to the shell.  This
X * only applies to UNIX 4.2 and 4.3.  For other systems, the routine should
X * be provided as a do-nothing routine.  md_tstp() will only be referenced
X * in the code when compiled with CURSES defined.
X *
X */
X
Xmd_tstp()
X{
X#ifdef UNIX_BSD4_2
X	kill(0, SIGTSTP);
X#endif /* UNIX_BSD4_2 */
X}
X
X#endif /* CURSES */
X
X#endif /* UNIX */
END_OF_machdep.c
if test 16483 -ne `wc -c <machdep.c`; then
    echo shar: \"machdep.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0