[comp.sources.games] v02i080: umoria - single player dungeon simulation, Part15/16

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

Submitted by: "James E. Wilson" <wilson@ji.berkeley.edu>
Comp.sources.games: Volume 2, Issue 80
Archive-name: umoria/Part15




#! /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 archive 15 (of 16)."
# Contents:  PROBLEMS io.c main.c potions.c store1.c types.h
# Wrapped by billr@tekred on Wed Nov  4 10:00:16 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f PROBLEMS -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"PROBLEMS\"
else
echo shar: Extracting \"PROBLEMS\" \(10051 characters\)
sed "s/^X//" >PROBLEMS <<'END_OF_PROBLEMS'
XFixes before 5/1
Xfixed moving into column one
Xtunnel through permanent rock prints tunnel through air? message
Xprinting of 18/ stats
X^C stops find flag, resting, searching
Xmonsters bash doors with 0 hit points
Xwhat if pto_hit is negative?
Xtest_hit, attack_blows, critical_blows are wrong
Xmon_tot_mult bug fixed
Xalways have same stats when start
Xenchant armor scroll
Xwizard_create does not set level!!
Xshould treasure level be set to finding level?
Xafter cure blindness need a move_char(5) to restore light
Xlose_exp in spells.c
Xmass_genocide when there are no monsters
Xdrop_throw, throwing object against wall goes into infinite loop
Xplayer titles for level wrong?
Xtd_destroy should unlock chests
Xuse of 8's in generate, set wallstk in build_tunnel
Xdoor/trap destroy should replace doors with corr2.floor, delete_object
Xwhen staff has 0 charges left, don't get warning message
Xrecharge spell
X-----   5/1
Xinjection from types of wands to metals
Xextra space at end of scroll names
Xprinting numbers in a field of 6
Xwarning if wielding too heavy of a weapon
Xattack_blows, penalty for wielding heavy weapon too severe,
Xsave routine, doesn't exit if you type ESCAPE, shouldn't if doing panic save
Xselling items to stores, they are still unidentified
Xitem prices in stores line up on the right
Xrogue_like key binding option
Xspelling fixes
Xfixed getlogin() call in death.c
Xdisable local special characters (^Y, ^R, ^W, ^V, ^O)
X-------------------  5/2
Xfixed .<dir> problem caused above
Xfixed problem with speed, only call search_off in signal.c if search_flag set
Xfood problems, fix initialization of py structure in variables.h
X-------------------  5/2.5
Xafter ^C, if type n, erase the line at top of screen
Xput refresh in erase_line(), so that lines really do get erased
Xmonster 'o' Ogre Magi casting unknown spells
Xm_level problems, not calculating right numbers for monster generation
Xchanged damroll/max_hd so that they no longer clear 'd' in strings
Xincreased size of dtype for damroll strings
Xincreased size of all defined strings, need one more char for the '\0'
Xwands of wonder, not generating new flag correctly
Xonly print 'too heavy weapon' message if actually wielding weapon
Xwand of heal monster, causes them to scream when hit
Xput (void) before all sscanf calls
Ximplemented shell_out and (no_)controlz functions
Xfixed build_tunnel, removed leftover fragment of earlier incorrect fix
X	to build_tunnel
Xdisplay_inventory doesn't clear last line when 12 items on one page 11 other
Xstore_purchase when over 12 items in store passed calculated wrong
X	count of number of items on second page
Xshould put priv_switch stuff back in, i.e. setuid
Xgame should be setuid
X------------------------- 5/3
Xfixed equip list bug when taking off items
Xchanged shell escape command to '!'
Xchanged version number to 4.82
Xrestore terminal modes in signal.c before core dumping
Xfixed bug in save.c, it was writting/reading too much for magic_spell
Xrefixed m_level code, m_level[0] must be added after the randint
Xwrote convert program to fix old save files
X---------------------------- 5/4
Xput sigsetmask in signals.c, now dumps core on QUIT signal
Xfixed empty chests, set flags to zero so no treasure, if search
X	then identify it as empty
Xmissing break for amulets in magic_treasurein misc.c, caused cursed
X	amulets to have positive attributes
Xdispell evil staffs gives segmentation fault, didn't check for muptr == 0
X------------------- 5/5
Xyour resist the affects -> you resist the effects
Xonly print "%s appears healthier" if can see the monster
Xcheck all uses of muptr, make sure test it not zero before using
Xcost for amulets of searching is too high
Xevil iggy prints wierd messages when he hits, break missing
X----------------------------------- 5/6
Xfixed index bug in misc.c objdes(), used 0 as null string pointer
Xadded sun to 'getuid' ifdefs in death.c and misc.c
X--------------------------- 5/8
Xfixed help page for rogue mode, searching mode command is ^S
Xwhen stun monster by bashing, now does not print name if can't see monster
Xallow controlz again, except when setuid or accessing save files
X--------------------------- 5/10
Xadded break after cure_poison() in potions.c
Xitems sold in stores do not appear in the inventory when last on second	page
Xsignals.c should restore local special chars before core dump exit
Xmonsters bashing doors end up on top of them
X	can't hit the monsters, can't cast spells at them, etc.
X----------------------- 5/11
Xfixed cast_spell, cast was not initialized to FALSE
Xinfravision in misc.c should be multiplied by 10
Xfood items become known in a more reasonable fashion
X----------------------- 5/13
Xif cast from empty spell book, print error message
Xthe base height/weight for female/male characters were reversed
X---------------------- 5/14
Xrefixed empty spell book to distinguish the three cases, cas_spell
X	now has three return values
Xremoved the numbers (1 2 3 4 6 7 8 9) from get_dir prompt
Xchanged some % chars to %% in print_monster() in files.c
Xchanged HD from %d to %s in print_monster()
Xfixed jamdoor() was setting i_ptr->p1 instead of t_ptr->p1
Xredefine Search mode command for rogue_like option to #
Xchanged message for rest_on, press '^C' not 'any key'
Xfixed potential infinite loop problem, must initialize curses before
X	install signal handlers
Xextensive mods to the save routine, added protection mechanisms
Xchanged version number to 4.83
Xminor fixes so that source passes lint, removed inkey_delay function
Xin store2.c, fix display_inventory() and purchase_haggle() so that
X	items will not be listed with 0 price for high chr characters
X------------------------ 5/15
Xcheck result of fopen for writing scoreboard in top_twenty()
Xetc. misspelled in print_monsters()
Xadded 'drools' and 'insults' messages in print_monsters()
Xmore mods to save routine, compress cave before writing to save file
Xwrote wizard restore_char() function
Xfixed test for Nighttime in generate.c, should be turn/5000 not turn%5000
Xset moria_flag true after a call to restore_char() in moria.c
Xupdate game_version() to include info about me
Xran through spell again
X---------------------------- 5/16
Xshould call prt_stat_block after wizard restore command 
Xsetuid code was just plain wrong, fixed it
X----------------------------
XSummer vacation!
X---------------------------  8/26
Xchecked every switch statement, found five missing breaks
X---------------------------  8/28
Xchanged use of geteuid() for random seeds, didn't work if setuid to root
X--------------------------- 9/4 - 9/6
Xport to SYS V
Xchanged store type (and save file format) to avoid warning about nonportable
X  signed character comparison
X---------------------------  9/9
Xadded bug fixes from doc@s.cc.purdue.edu, mainly dealing with setuid code
X---------------------------- 9/11
Xcorrect spelling of receive_offer() (was recieve)
X^R in store will 'really' clear screen now
Xget_haggle will not accept negative numbers now
Xdisarm_all caused segment faults, missing level of braces after t_ptr = &...
Xmore spelling errors: Delila(+h) Slim(-e)y Smok(-e)y
X--------------------------- 9/16
Xtook out old compatibility code in save.c
Xchanged version number to 4.84
Xchanged clear_screen and really_clear_screen so that they set msg_flag FALSE
X-------------------------- 9/17
Xremoved loop_flag = FALSE after prt_comment6(), stops wierd behavior if
X  when buy/sell give a price greater/less than that offered
Xput entry in scoreboard when quit
Xmodified get_char so that it will read 4.83 save files
X------------------------- 9/18
Xfix code so that it passes lint on ultrix and sun
Xfix curses bugs with Ultrix, by adding ifdefs for BUGGY_CURSES
X  remove calls to nl(), and nonl(), don't write chars in last column
X-------------------------- 9/19
Xport to SYSTEM V again
Xbreakup all files so that they are less than 64K, except the doc file
X-------------------------- 10/??
Xchange all instances of (index(...) > 0) to (index(...) != 0)
Xfixed three errors, calling randint with arg of 0
Xfixed bug that allowed one to buy objects for negative gold pieces
Xfixed many other errors, but forgot to document them (sorry!)
X-------------------------- 10/26
Xadd comment about defining _DNO_SIGNED_CHARS for 3Bx series computers
XSUN4 has variable class in math.h, added ifdefs to misc1.c and externs.h
X  to avoid the conflict
Xmake variables.h monsters.h treasure1.h and treasure2.h into c files
X  to avoid problems compiling the HUGE main.c file on a 3B20
Xadded an option '-o' to use the original style key bindings
Xadded compiler option to Makefile, so that installer can choose
X  which key binding style should be the default
Xcontrol-c puts you in scoreboard only after character generation complete
Xchanged all USG savetty/resetty to saveterm/resetterm, it still seems to work
Xchanged version number to 4.85 for distribution purposes
X  started mailing to comp.sources.games
X
XThings to be fixed:
Xif amulet raises stat over 118, stat will be lowered (more than it should be)
X	when take amulet off
Xloss of strength doesn't force you to drop items
Xwhat if can't write into current directory? (saves files, etc.)
Xthis file should be in reverse chronological order!
Xit is possible to get 'final offer = 0' when selling an object
X
XLong term stuff, enhancement suggestions:
Xuse environment variables, for example to specify rogue-like keys
Xand option to restore files from default save filename
Xcommands not close enough to rogue style
Xscoreboard have all scores, not top twenty
Xcommand line option to print out times open
Xstrange streatment of cursed armor
Xcan't drop or identify items in equipment list
Xlet o, c, D commands automatically pick direction when they can
XSYS V does not lock scoreboard when changing it
Xit is too slow?  spends about half of its time doing screen i/o
Xreplace magic numbers with constants
Xremove trailing blanks from every line
Xfor throw command, ask for direction first (like rogue)
Xdon't change letters of items in inventory (like rogue, again)
Xbe able to move onto objects without picking them up (like rogue)
Xwhen moving on objects, say what character moved onto (like rogue)
END_OF_PROBLEMS
if test 10051 -ne `wc -c <PROBLEMS`; then
    echo shar: \"PROBLEMS\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f io.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"io.c\"
else
echo shar: Extracting \"io.c\" \(8910 characters\)
sed "s/^X//" >io.c <<'END_OF_io.c'
X#include <curses.h>
X#ifdef USG
X#include <string.h>
X#else
X#include <strings.h>
X#include <sgtty.h>
X#include <sys/wait.h>
X#endif
X#include <sys/types.h>
X#include <sys/ioctl.h>
X#include <sys/file.h>
X
X#include "constants.h"
X#include "types.h"
X#include "externs.h"
X
X#ifdef sun   /* correct SUN stupidity in the stdio.h file */
Xchar *sprintf();
X#endif
X
Xvtype pad_output;   /* static output string for the pad function */
X
Xchar *getenv();
X
X#ifdef USG
Xvoid exit();
Xunsigned sleep();
X#endif
X#ifdef ultrix
Xvoid exit();
Xvoid sleep();
X#endif
X
X#ifdef USG
X/* no local special characters */
X#else
Xstruct ltchars save_special_chars;
X#endif
X
X/* initializes curses routines */
Xinit_curses()
X{
X#ifdef USG
X  /* no local special characters */
X#else
X  struct ltchars buf;
X#endif
X
X#ifdef USG
X  if (initscr() == NULL)
X#else
X  if (initscr() == ERR)
X#endif
X    {
X      (void) printf("error allocating screen in curses package\n");
X      exit_game();
X    }
X  clear();
X#ifdef USG
X  saveterm();
X#endif
X#ifdef ultrix
X  crmode();
X#else
X  cbreak();
X#endif
X  noecho();
X#ifndef BUGGY_CURSES
X  nonl();
X#endif
X  /* save old settings of the local special characters */
X#ifdef USG
X  /* no local special characters */
X#else
X  (void) ioctl(0, TIOCGLTC, (char *)&save_special_chars);
X  /* disable all of the local special characters except the suspend char */
X  /* have to disable ^Y for tunneling */
X  buf.t_suspc = (char)26;  /* control-Z */
X  buf.t_dsuspc = (char)-1;
X  buf.t_rprntc = (char)-1;
X  buf.t_flushc = (char)-1;
X  buf.t_werasc = (char)-1;
X  buf.t_lnextc = (char)-1;
X  (void) ioctl(0, TIOCSLTC, (char *)&buf);
X#endif
X}
X
X
X/* Dump IO to buffer					-RAK-	*/
Xput_buffer(out_str, row, col)
Xchar *out_str;
Xint row, col;
X{
X  vtype tmp_str;
X
X  if (mvaddstr(row, col, out_str) == ERR)
X    {
X      (void) sprintf(tmp_str, "error row = %d col = %d\n", row, col);
X      prt(tmp_str, 0, 0);
X      (void) sleep(2);
X    }
X  refresh();
X}
X
X
X/* Dump the IO buffer to terminal			-RAK-	*/
X/* NOTE: Source is PUTQIO.MAR					*/
Xput_qio()
X{
X  refresh();
X}
X
X
Xshell_out()
X{
X  int val;
X  char *str;
X#ifdef USG
X  /* no local special characters */
X#else
X  struct ltchars buf;
X#endif
X
X#ifndef BUGGY_CURSES
X  nl();
X#endif
X#ifdef ultrix
X  nocrmode();
X#else
X  nocbreak();
X#endif
X  echo();
X  val = fork();
X  if (val == 0)
X    {
X#ifdef USG
X      /* no local special characters */
X      resetterm();
X#else
X      (void) ioctl(0, TIOCSLTC, (char *)&save_special_chars);
X#endif
X      if (str = getenv("SHELL"))
X	(void) execl(str, str, (char *) 0);
X      else
X	(void) execl("/bin/sh", "sh", (char *) 0);
X      msg_print("Cannot execute shell");
X      exit(1);
X    }
X  if (val == -1)
X    {
X      msg_print("Fork failed. Try again.");
X      return;
X    }
X#ifdef USG
X  (void) wait((int *) 0);
X#else
X  (void) wait((union wait *) 0);
X#endif
X  really_clear_screen();
X#ifdef ultrix
X  crmode();
X#else
X  cbreak();
X#endif
X  noecho();
X#ifndef BUGGY_CURSES
X  nonl();
X#endif
X  /* disable all of the local special characters except the suspend char */
X  /* have to disable ^Y for tunneling */
X#ifdef USG
X  /* no local special characters */
X#else
X  buf.t_suspc = (char)26;  /* control-Z */
X  buf.t_dsuspc = (char)-1;
X  buf.t_rprntc = (char)-1;
X  buf.t_flushc = (char)-1;
X  buf.t_werasc = (char)-1;
X  buf.t_lnextc = (char)-1;
X  (void) ioctl(0, TIOCSLTC, (char *)&buf);
X#endif
X}
X
Xexit_game()
X{
X  /* restore the saved values of the local special chars */
X  put_qio();	/* Dump any remaining buffer	*/
X  endwin();     /* exit curses */
X  echo();
X#ifndef BUGGY_CURSES
X  nl();
X#endif
X#ifdef ultrix
X  nocrmode();
X#else
X  nocbreak();
X#endif
X#ifdef USG
X  /* no local special characters */
X  resetterm();
X#else
X  (void) ioctl(0, TIOCSLTC, (char *)&save_special_chars);
X#endif
X  exit(0);	/* exit from game		*/
X}
X
X
X/* Gets single character from keyboard and returns		*/
Xinkey(ch)
Xchar *ch;
X{
X  put_qio();			/* Dump IO buffer		*/
X  *ch = getch();
X  msg_flag = FALSE;
X}
X
X
X/* Flush the buffer					-RAK-	*/
Xflush()
X{
X#ifdef USG
X  (void) ioctl(0, TCFLSH, 0);  /* flush the input queue */
X#else
X  int arg;
X
X  arg = FREAD;
X  (void) ioctl(0, TIOCFLUSH, (char *)&arg);   /* flush all input */
X#endif
X
X  /* Now flush				*/
X  refresh();
X}
X
X
X/* Flush buffer before input				-RAK-	*/
Xinkey_flush(x)
Xchar *x;
X{
X  put_qio();	/* Dup the IO buffer	*/
X  if (!wizard1)  flush();
X  inkey(x);
X}
X
X
X/* Clears given line of text				-RAK-	*/
Xerase_line(row, col)
Xint row;
Xint col;
X{
X  move(row, col);
X  clrtoeol();
X  refresh();
X}
X
X
X/* Clears screen at given row, column				*/
Xclear_screen(row, col)
Xint row, col;
X{
X  int i;
X
X  for (i = 1; i <= 23; i++)
X    used_line[i] = FALSE;
X  move(row, col);
X  clrtobot();
X  put_qio();	/* Dump the Clear Sequence	*/
X  msg_flag = FALSE;
X}
X
X
X/* Clears entire screen, even if there are characters that curses
X   does not know about */
Xreally_clear_screen()
X{
X  int i;
X
X  for (i = 1; i <= 23; i++)
X    used_line[i] = FALSE;
X  clear();
X  put_qio();	/* Dump the Clear Sequence	*/
X  msg_flag = FALSE;
X}
X
X
X/* Outputs a line to a given interpolated y, x position	-RAK-	*/
Xprint(str_buff, row, col)
Xchar *str_buff;
Xint row;
Xint col;
X{
X  row -= panel_row_prt;/* Real co-ords convert to screen positions */
X  col -= panel_col_prt;
X  used_line[row] = TRUE;
X  put_buffer(str_buff, row, col);
X}
X
X
X/* Outputs a line to a given y, x position		-RAK-	*/
Xprt(str_buff, row, col)
Xchar *str_buff;
Xint row;
Xint col;
X{
X  move(row, col);
X  clrtoeol();
X  put_buffer(str_buff, row, col);
X}
X
X
X/* Outputs message to top line of screen				*/
Xmsg_print(str_buff)
Xchar *str_buff;
X{
X  int old_len;
X  char in_char;
X
X  if (msg_flag) 
X    {
X      old_len = strlen(old_msg) + 1;
X      put_buffer(" -more-", msg_line, old_len);
X      do
X	{
X	  inkey(&in_char);
X	}
X      while ((in_char != ' ') && (in_char != '\033'));
X    }
X  move(msg_line, msg_line);
X  clrtoeol();
X  put_buffer(str_buff, msg_line, msg_line);
X  (void) strcpy(old_msg, str_buff);
X  msg_flag = TRUE;
X}
X
X
X/* Prompts (optional) and returns ord value of input char	*/
X/* Function returns false if <ESCAPE> is input	*/
Xget_com(prompt, command)
Xchar *prompt;
Xchar *command;
X{
X  int com_val;
X  int res;
X
X  if (strlen(prompt) > 1)
X    prt(prompt, 0, 0);
X  inkey(command);
X  com_val = (*command);
X  switch(com_val)
X    {
X    case 27:
X      res = FALSE;
X      break;
X    default:
X      res = TRUE;
X      break;
X    }
X  erase_line(msg_line, msg_line);
X  msg_flag = FALSE;
X  return(res);
X}
X
X
X/* Gets a string terminated by <RETURN>				*/
X/* Function returns false if <ESCAPE>, CNTL/(Y, C, Z) is input	*/
Xint get_string(in_str, row, column, slen)
Xchar *in_str;
Xint row, column, slen;
X{
X  int start_col, end_col, i;
X  char x;
X  vtype tmp;
X  int flag, abort;
X
X  abort = FALSE;
X  flag  = FALSE;
X  in_str[0] = '\0';
X  put_buffer(pad(in_str, " ", slen), row, column);
X  put_buffer("\0", row, column);
X  start_col = column;
X  end_col = column + slen - 1;
X  do
X    {
X      inkey(&x);
X      switch(x)
X	{
X	case 27:
X	  abort = TRUE;
X	  break;
X	case 10: case 13:
X	  flag  = TRUE;
X	  break;
X	case 127: case 8:
X	  if (column > start_col) 
X	    {
X	      column--;
X	      put_buffer(" \b", row, column);
X	      in_str[strlen(in_str)-1] = '\0';
X	    }
X	  break;
X	default:
X	  (void) sprintf(tmp, "%c", x);
X	  put_buffer(tmp, row, column);
X	  (void) strcat(in_str, tmp);
X	  column++;
X	  if (column > end_col) 
X	    flag = TRUE;
X	  break;
X	}
X    }
X  while ((!flag) && (!abort));
X  if (abort) 
X    return(FALSE);
X  else
X    {			/* Remove trailing blanks	*/
X      i = strlen(in_str);
X      if (i > 0)
X	{
X	  while ((in_str[i] == ' ') && (i > 0))
X	    i--;
X	  in_str[i+1] = '\0';
X	}
X    }
X  return(TRUE);
X}
X
X
X/* Return integer value of hex string			-RAK-	*/
Xint get_hex_value(row, col, slen)
Xint row, col, slen;
X{
X  vtype tmp_str;
X  int hex_value;
X
X  hex_value = 0;
X  if (get_string(tmp_str, row, col, slen)) 
X    if (strlen(tmp_str) <= 8) 
X      {
X	(void) sscanf(tmp_str, "%x", &hex_value);
X      }
X  return(hex_value);
X}
X
X
X/* Pauses for user response before returning		-RAK-	*/
Xpause_line(prt_line)
Xint prt_line;
X{
X  char dummy;
X
X  prt("[Press any key to continue]", prt_line, 23);
X  inkey(&dummy);
X  erase_line(23, 0);
X}
X
X
X/* Pauses for user response before returning		-RAK-	*/
X/* NOTE: Delay is for players trying to roll up "perfect"	*/
X/*	characters.  Make them wait a bit...			*/
Xpause_exit(prt_line, delay)
Xint prt_line;
Xint delay;
X{
X  char dummy;
X
X  prt("[Press any key to continue, or ESC to exit]", prt_line, 10);
X  inkey(&dummy);
X  switch(dummy)
X    {
X    case 27:
X      erase_line(prt_line, 0);
X      if (delay > 0)  (void) sleep((unsigned)delay);
X      exit_game();
X      break;
X    default:
X      break;
X    }
X  erase_line(prt_line, 0);
X}
X
X
X/* pad a string with fill characters to specified length */
Xchar *pad(string, fill, filllength)
Xchar *string;
Xchar *fill;
Xint filllength;
X{
X  int length;
X  int i;
X
X  (void) strcpy(pad_output, string);
X  length = strlen(pad_output);
X  for (i = length; i < filllength; i++)
X    pad_output[i] = *fill;
X  pad_output[i] = '\0';
X  return(pad_output);
X}
END_OF_io.c
if test 8910 -ne `wc -c <io.c`; then
    echo shar: \"io.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f main.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"main.c\"
else
echo shar: Extracting \"main.c\" \(5395 characters\)
sed "s/^X//" >main.c <<'END_OF_main.c'
X/* Moria Version 4.8	COPYRIGHT (c) Robert Alan Koeneke		*/
X/*                       Public Domain                                   */
X/*                                                                       */
X/*       I lovingly dedicate this game to hackers and adventurers        */
X/*       everywhere...                                                   */
X/*                                                                       */
X/*                                                                       */
X/*       Designer and Programmer : Robert Alan Koeneke                   */
X/*                                 University of Oklahoma                */
X/*                                                                       */
X/*       Assistant Programmers   : Jimmey Wayne Todd                     */
X/*                                 University of Oklahoma                */
X/*                                                                       */
X/*                                 Gary D. McAdoo                        */
X/*                                 University of Oklahoma                */
X/*                                                                       */
X/*       UNIX Port               : James E. Wilson                       */
X/*                                 UC Berkeley                           */
X/*                                 wilson@ernie.Berkeley.EDU             */
X/*                                 ucbvax!ucbernie!wilson                */
X/*                                                                       */
X/*       Moria may be copied and modified freely as long as the above    */
X/*       credits are retained.  No one who-so-ever may sell or market    */
X/*       this software in any form without the expressed written consent */
X/*       of the author Robert Alan Koeneke.                              */
X/*                                                                       */
X
X#include <curses.h>
X#ifdef USG
X#include <string.h>
X#else
X#include <strings.h>
X#endif
X#include <sys/types.h>
X
X#include "constants.h"
X#include "types.h"
X#include "externs.h"
X
X#if defined(ultrix) || defined(sun) || defined(USG)
Xint getuid();
X#else
Xuid_t getuid();
X#endif
X
X#if defined(ultrix) || defined(USG)
Xvoid perror();
Xvoid exit();
X#endif
X
Xextern int key_bindings;
X
X/* Initialize, restore, and get the ball rolling...	-RAK-	*/
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X  /* call this routine to grab a file pointer to the highscore file *
X  /* and prepare things to relinquish setuid privileges */
X  init_scorefile();
X
X  if (0 != setuid(getuid()))
X    {
X      perror("Gack!  Can't set permissions correctly!  Exiting!\n");
X      exit(0);
X    }
X 
X  /* use curses */
X  init_curses();
X  
X  /* catch those nasty signals */
X  /* must come after init_curses as some of the signal handlers use curses */
X  init_signals();
X
X  /* Build the secret wizard and god passwords	*/
X  bpswd();
X  
X  /* check for user interface option */
X  key_bindings = KEY_BINDINGS;
X  if (argc >= 2)
X    {
X      if (!strcmp(argv[1], "-r"))
X        {
X          key_bindings = ROGUE_LIKE;
X          argv[1][0] = '\0';
X        }
X      if (!strcmp(argv[1], "-o"))
X	{
X	  key_bindings = ORIGINAL;
X	  argv[1][0] = '\0';
X	}
X      if (!strcmp(argv[1], "-s"))
X	{
X	  display_scores();
X	  exit_game();
X	}
X    }
X
X  /* Check operating hours 			*/
X  /* If not wizard  No_Control_Y               */
X  /* Check or create hours.dat, print message	*/
X  /* if last arg is ^ then start as wizard, can not restore game also */
X  if (argc >= 2)
X    intro(argv[argc - 1]);
X  else
X    intro("");
X  
X  /* Some necessary initializations		*/
X  msg_line       = 0;
X  quart_height   = SCREEN_HEIGHT / 4;
X  quart_width    = SCREEN_WIDTH / 4;
X  dun_level      = 0;
X  
X  /* Grab a random seed from the clock		*/
X  init_seeds();
X  
X  /* Sort the objects by level			*/
X  sort_objects();
X  
X  /* Init monster and treasure levels for allocate */
X  init_m_level();
X  init_t_level();
X  
X  /* Init the store inventories			*/
X  store_init();
X  if (COST_ADJ != 1.00)  price_adjust();
X  
X  /* Generate a character, or retrieve old one...	*/
X  if ((argc > 1) && strlen(argv[argc-1]))
X    {     /* Retrieve character    */
X      generate = get_char(argv[argc-1]);
X      change_name();
X      magic_init();
X    }
X  else
X    {     /* Create character      */
X      create_character();
X      char_inven_init();
X      if (class[py.misc.pclass].mspell) 
X	{         /* Magic realm   */
X	  (void) learn_spell(&msg_flag);
X	  gain_mana(int_adj());
X	}
X      else if (class[py.misc.pclass].pspell) 
X	{         /* Clerical realm*/
X	  (void) learn_prayer();
X	  gain_mana(wis_adj());
X	}
X      py.misc.cmana = (double)py.misc.mana;
X      magic_init();
X      generate = TRUE;
X    }
X  
X  /* Begin the game				*/
X  /*    This determines the maximum player level    */
X  player_max_exp = (player_exp[MAX_PLAYER_LEVEL-1]*py.misc.expfact);
X  clear_screen(0, 0);
X  prt_stat_block();
X  /* prevent ^c quit from entering score into scoreboard until this point */
X  character_generated = 1;
X  
X  /* Loop till dead, or exit			*/
X  while(!death) {
X    if (generate)  generate_cave();         /* New level     */
X    dungeon();                                  /* Dungeon logic */
X    generate = TRUE;
X  }
X  upon_death();                         /* Character gets buried */
X  /* should never reach here, but just in case */
X  return (0);
X}
END_OF_main.c
if test 5395 -ne `wc -c <main.c`; then
    echo shar: \"main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f potions.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"potions.c\"
else
echo shar: Extracting \"potions.c\" \(8700 characters\)
sed "s/^X//" >potions.c <<'END_OF_potions.c'
X#include "constants.h"
X#include "types.h"
X#include "externs.h"
X
X
X/* Potions for the quaffing				-RAK-	*/
Xquaff()
X{
X  unsigned int i;
X  int j, k, l, m, item_val;
X  int redraw, ident;
X  treasure_type *i_ptr;
X  struct misc *m_ptr;
X  struct flags *f_ptr;
X  struct stats *s_ptr;
X  class_type *c_ptr;
X
X  reset_flag = TRUE;
X  if (inven_ctr > 0) 
X    {
X      if (find_range(75, 76, &j, &k)) 
X	{
X	  redraw = FALSE;
X	  if (get_item(&item_val, "Quaff which potion?", &redraw, j, k)) 
X	    {
X	      i_ptr = &inventory[item_val];
X	      if (redraw)  draw_cave();
X	      reset_flag = FALSE;
X	      i = i_ptr->flags;
X	      ident = FALSE;
X	      while (i != 0)
X		{
X		  j = bit_pos(&i) + 1;
X		  if (i_ptr->tval == 76)
X		    j += 31;
X		  /* Potions						*/
X		  switch(j)
X		    {
X		    case 1:
X		      s_ptr = &py.stats;
X		      s_ptr->cstr = in_statp(s_ptr->cstr);
X		      if (s_ptr->cstr > s_ptr->str) 
X			s_ptr->str = s_ptr->cstr;
X		      msg_print("Wow!  What bulging muscles!");
X		      prt_strength();
X		      ident = TRUE;
X		      break;
X		    case 2:
X		      ident = lose_str();
X		      break;
X		    case 3:
X		      s_ptr = &py.stats;
X		      s_ptr->cstr = s_ptr->str;
X		      msg_print("You feel warm all over.");
X		      prt_strength();
X		      ident = TRUE;
X		      break;
X		    case 4:
X		      s_ptr = &py.stats;
X		      s_ptr->cint = in_statp(s_ptr->cint);
X		      if (s_ptr->cint > py.stats.intel) 
X			py.stats.intel = s_ptr->cint;
X		      msg_print("Aren't you brilliant!");
X		      prt_intelligence();
X		      ident = TRUE;
X		      break;
X		    case 5:
X		      msg_print("This potion tastes very dull.");
X		      ident = lose_int();
X		      break;
X		    case 6:
X		      s_ptr = &py.stats;
X		      s_ptr->cint = py.stats.intel;
X		      msg_print("You have have a warm feeling.");
X		      prt_intelligence();
X		      ident = TRUE;
X		      break;
X		    case 7:
X		      s_ptr = &py.stats;
X		      s_ptr->cwis = in_statp(s_ptr->cwis);
X		      if (s_ptr->cwis > s_ptr->wis) 
X			s_ptr->wis = s_ptr->cwis;
X		      msg_print("You suddenly have a profound thought!");
X		      prt_wisdom();
X		      ident = TRUE;
X		      break;
X		    case 8:
X		      ident = lose_wis();
X		      break;
X		    case 9:
X		      s_ptr = &py.stats;
X		      if (s_ptr->cwis < s_ptr->wis) 
X			{
X			  s_ptr->cwis = s_ptr->wis;
X			  msg_print("You feel your wisdom returning.");
X			  prt_wisdom();
X			  ident = TRUE;
X			}
X		      break;
X		    case 10:
X		      s_ptr = &py.stats;
X		      s_ptr->cchr = in_statp(s_ptr->cchr);
X		      if (s_ptr->cchr > s_ptr->chr) 
X			s_ptr->chr = s_ptr->cchr;
X		      msg_print("Gee,  ain't you cute!");
X		      prt_charisma();
X		      ident = TRUE;
X		      break;
X		    case 11:
X		      ident = lose_chr();
X		      break;
X		    case 12:
X		      s_ptr = &py.stats;
X		      if (s_ptr->cchr < s_ptr->chr) 
X			{
X			  s_ptr->cchr = s_ptr->chr;
X			  msg_print("You feel your looks returning.");
X			  prt_charisma();
X			  ident = TRUE;
X			}
X		      break;
X		    case 13:
X		      ident = hp_player(damroll("2d7"), "a potion.");
X		      break;
X		    case 14:
X		      ident = hp_player(damroll("4d7"), "a potion.");
X		      break;
X		    case 15:
X		      ident = hp_player(damroll("6d7"), "a potion.");
X		      break;
X		    case 16:
X		      ident = hp_player(1000, "a potion.");
X		      break;
X		    case 17:
X		      m_ptr = &py.misc;
X		      py.stats.ccon = in_statp(py.stats.ccon);
X		      if (py.stats.ccon > py.stats.con) 
X			py.stats.con = py.stats.ccon;
X		      m_ptr->mhp++;
X		      m_ptr->chp += m_ptr->mhp;
X		      msg_print("You feel tingly for a moment.");
X		      prt_mhp();
X		      prt_chp();
X		      prt_constitution();
X		      ident = TRUE;
X		      break;
X		    case 18:
X		      m_ptr = &py.misc;
X		      m = (m_ptr->exp / 2) + 10;
X		      if (m > 100000)  m = 100000;
X		      m_ptr->exp += m;
X		      msg_print("You feel more experienced.");
X		      prt_experience();
X		      ident = TRUE;
X		      break;
X		    case 19:
X		      f_ptr = &py.flags;
X		      if (!f_ptr->free_act) 
X			{
X			  msg_print("You fall asleep.");
X			  f_ptr->paralysis += randint(4) + 4;
X			  ident = TRUE;
X			}
X		      break;
X		    case 20:
X		      f_ptr = &py.flags;
X		      msg_print("You are covered by a veil of darkness.");
X		      f_ptr->blind += randint(100) + 100;
X		      ident = TRUE;
X		      break;
X		    case 21:
X		      f_ptr = &py.flags;
X		      msg_print("Hey!  This is good stuff!  * Hick! *");
X		      f_ptr->confused += randint(20) + 12;
X		      ident = TRUE;
X		      break;
X		    case 22:
X		      f_ptr = &py.flags;
X		      msg_print("You feel very sick.");
X		      f_ptr->poisoned += randint(15) + 10;
X		      ident = TRUE;
X		      break;
X		    case 23:
X		      py.flags.fast += randint(25) + 15;
X		      ident = TRUE;
X		      break;
X		    case 24:
X		      py.flags.slow += randint(25) + 15;
X		      ident = TRUE;
X		      break;
X		    case 25:
X		      ident = detect_monsters();
X		      break;
X		    case 26:
X		      s_ptr = &py.stats;
X		      s_ptr->cdex = in_statp(s_ptr->cdex);
X		      if (s_ptr->cdex > s_ptr->dex) 
X			s_ptr->dex = s_ptr->cdex;
X		      msg_print("You feel more limber!");
X		      prt_dexterity();
X		      ident = TRUE;
X		      break;
X		    case 27:
X		      s_ptr = &py.stats;
X		      if (s_ptr->cdex < s_ptr->dex) 
X			{
X			  s_ptr->cdex = s_ptr->dex;
X			  msg_print("You feel less clumsy.");
X			  prt_dexterity();
X			  ident = TRUE;
X			}
X		      break;
X		    case 28:
X		      s_ptr= &py.stats;
X		      if (s_ptr->ccon < s_ptr->con) 
X			{
X			  s_ptr->ccon = s_ptr->con;
X			  msg_print("You feel your health returning!");
X			  prt_constitution();
X			  ident = TRUE;
X			}
X		      break;
X		    case 29:
X		      (void) cure_blindness();
X		      break;
X		    case 30:
X		      (void) cure_confusion();
X		      break;
X		    case 31:
X		      (void) cure_poison();
X		      break;
X		    case 32:
X		      m_ptr = &py.misc;
X		      c_ptr = &class[m_ptr->pclass];
X		      if (c_ptr->mspell) 
X			{
X			  ident = learn_spell(&redraw);
X			  if (redraw)  draw_cave();
X			}
X		      else if (c_ptr->pspell) 
X			ident = learn_prayer();
X		      break;
X		    case 33:
X		      msg_print("You feel your memories fade...");
X		      msg_print("");
X		      l = (py.misc.exp/5.0); 
X		      lose_exp(randint(l)+l);
X		      ident = TRUE;
X		      break;
X		    case 34:
X		      f_ptr = &py.flags;
X		      f_ptr->poisoned = 0;
X		      if (f_ptr->food > 150)  f_ptr->food = 150;
X		      f_ptr->paralysis = 4;
X		      msg_print("The potion makes you vomit!");
X		      ident = TRUE;
X		      break;
X		    case 35:
X		      py.flags.invuln += randint(10) + 10;
X		      ident = TRUE;
X		      break;
X		    case 36:
X		      py.flags.hero += randint(25) + 25;
X		      ident = TRUE;
X		      break;
X		    case 37:
X		      py.flags.shero += randint(25) + 25;
X		      ident = TRUE;
X		      break;
X		    case 38:
X		      ident = remove_fear();
X		      break;
X		    case 39:
X		      ident = restore_level();
X		      break;
X		    case 40:
X		      f_ptr = &py.flags;
X		      f_ptr->resist_heat += randint(10) + 10;
X		      break;
X		    case 41:
X		      f_ptr = &py.flags;
X		      f_ptr->resist_cold += randint(10) + 10;
X                      break;
X		    case 42:
X		      detect_inv2(randint(12)+12);
X		      break;
X		    case 43:
X		      ident = slow_poison();
X		      break;
X		    case 44:
X		      ident = cure_poison();
X		      break;
X		    case 45:
X		      m_ptr = &py.misc;
X		      if (m_ptr->cmana < m_ptr->mana) 
X			{
X			  m_ptr->cmana = (double)m_ptr->mana;
X			  ident = TRUE;
X			  msg_print("Your feel your head clear...");
X			}
X		      break;
X		    case 46:
X		      f_ptr = &py.flags;
X		      f_ptr->tim_infra += 100 + randint(100);
X		      ident = TRUE;
X		      msg_print("Your eyes begin to tingle.");
X		      break;
X		    case 47:
X		      break;
X		    case 48:
X		      break;
X		    case 49:
X		      break;
X		    case 50:
X		      break;
X		    case 51:
X		      break;
X		    case 52:
X		      break;
X		    case 53:
X		      break;
X		    case 54:
X		      break;
X		    case 55:
X		      break;
X		    case 56:
X		      break;
X		    case 57:
X		      break;
X		    case 58:
X		      break;
X		    case 59:
X		      break;
X		    case 60:
X		      break;
X		    case 61:
X		      break;
X		    case 62:
X		      break;
X		    default:
X		      break;
X		    }
X		  /* End of Potions...					*/
X		}
X	      if (ident) 
X		identify(inventory[item_val]);
X	      if (i_ptr->flags != 0) 
X		{
X		  m_ptr = &py.misc;
X		  m_ptr->exp += (int)(i_ptr->level/m_ptr->lev + 0.5);
X		  prt_experience();
X		}
X	      add_food(i_ptr->p1);
X	      desc_remain(item_val);
X	      inven_destroy(item_val);
X	    }
X	  else
X	    if (redraw)  draw_cave();
X	}
X      else
X	msg_print("You are not carrying any potions.");
X    }
X  else
X    msg_print("But you are not carrying anything.");
X}
END_OF_potions.c
if test 8700 -ne `wc -c <potions.c`; then
    echo shar: \"potions.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f store1.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"store1.c\"
else
echo shar: Extracting \"store1.c\" \(8587 characters\)
sed "s/^X//" >store1.c <<'END_OF_store1.c'
X#ifdef USG
X#include <string.h>
X#else
X#include <strings.h>
X#endif
X
X#include "constants.h"
X#include "types.h"
X#include "externs.h"
X
Xint search_list(x1, x2)
Xbyteint x1;
Xint x2;
X{
X  int i, j;
X  treasure_type *o_ptr;
X
X  i = 0;
X  j = 0;
X  do
X    {
X      o_ptr = &object_list[i];
X      if ((o_ptr->tval == x1) && (o_ptr->subval == x2)) 
X	j = o_ptr->cost;
X      i++;
X    }
X  while ((i != MAX_OBJECTS) && (j <= 0));
X  return(j);
X}
X
X
X/* Returns the value for any given object		-RAK-	*/
Xint item_value(item)
Xtreasure_type item;
X{
X  int value;
X  treasure_type *i_ptr;
X
X  i_ptr = &item;
X  value = i_ptr->cost;
X  if (((i_ptr->tval >= 20) && (i_ptr->tval <= 23)) ||
X      ((i_ptr->tval >= 30) && (i_ptr->tval <= 36)))
X    {	/* Weapons and armor	*/
X      if (index(i_ptr->name, '^') != 0)
X	value = search_list(i_ptr->tval, i_ptr->subval) * i_ptr->number;
X      else if ((i_ptr->tval >= 20) && (i_ptr->tval <= 23))
X	{
X	  if (i_ptr->tohit < 0) 
X	    value = 0;
X	  else if (i_ptr->todam < 0) 
X	    value = 0;
X	  else if (i_ptr->toac < 0) 
X	    value = 0;
X	  else
X	    value = (i_ptr->cost+(i_ptr->tohit+i_ptr->todam+i_ptr->toac)*100)*
X	      i_ptr->number;
X	}
X      else
X	{
X	  if (i_ptr->toac < 0) 
X	    value = 0;
X	  else
X	    value = (i_ptr->cost+i_ptr->toac*100)*i_ptr->number;
X	}
X    }
X  else if ((i_ptr->tval >= 10) && (i_ptr->tval <= 13))
X    {	/* Ammo			*/
X      if (index(i_ptr->name, '^') != 0) 
X	value = search_list(i_ptr->tval, 1)*i_ptr->number;
X      else
X	{
X	  if (i_ptr->tohit < 0) 
X	    value = 0;
X	  else if (i_ptr->todam < 0) 
X	    value = 0;
X	  else if (i_ptr->toac < 0) 
X	    value = 0;
X	  else
X	    value = (i_ptr->cost+(i_ptr->tohit+i_ptr->todam+i_ptr->toac)*10)*
X	      i_ptr->number;
X	}
X    }
X  else if ((i_ptr->tval == 70) || (i_ptr->tval == 71) ||
X	   (i_ptr->tval == 75) || (i_ptr->tval == 76) || (i_ptr->tval == 80)) 
X    {	/* Potions, Scrolls, and Food	*/
X      if (index(i_ptr->name, '|') != 0) 
X	switch(i_ptr->tval)
X	  {
X	  case 70: case 71: value =  20; break;
X	  case 75: case 76: value =  20; break;
X	  case 80:          value =   1; break;
X	  default:          break;
X	  }
X    }
X  else if ((i_ptr->tval == 40) || (i_ptr->tval == 45)) 
X    {	/* Rings and amulets	*/
X      if (index(i_ptr->name, '|') != 0) 
X	switch(i_ptr->tval)
X	  {
X	  case 40: value = 45; break;
X	  case 45: value = 45; break;
X	  default: break;
X	  }
X      else if (index(i_ptr->name, '^') != 0) 
X	value = abs(i_ptr->cost);
X    }
X  else if ((i_ptr->tval == 55) || (i_ptr->tval == 60) || (i_ptr->tval == 65)) 
X    {	/* Wands rods, and staffs*/
X      if (index(i_ptr->name, '|') != 0) 
X	switch(i_ptr->tval)
X	  {
X	  case 55: value = 70; break;
X	  case 60: value = 60; break;
X	  case 65: value = 50; break;
X	  default: break;
X	  }
X      else if (index(i_ptr->name, '^') == 0) 
X	{
X	  value = i_ptr->cost + (i_ptr->cost/20.0)*i_ptr->p1;
X	}
X    }
X  return(value);
X}
X
X
X/* Asking price for an item				-RAK-	*/
Xint sell_price(snum, max_sell, min_sell, item)
Xint snum;
Xint *max_sell, *min_sell;
Xtreasure_type item;
X{
X  int i;
X  store_type *s_ptr;
X
X  s_ptr = &store[snum];
X  i = item_value(item);
X  if (item.cost > 0) 
X    {
X      i += (i * rgold_adj[owners[s_ptr->owner].owner_race][py.misc.prace]);
X      if (i < 1)  i = 1;
X      *max_sell = (i * (1+owners[s_ptr->owner].max_inflate));
X      *min_sell = (i * (1+owners[s_ptr->owner].min_inflate));
X      if (min_sell > max_sell)  min_sell = max_sell;
X      return(i);
X    }
X  else
X    {
X      *max_sell = 0;
X      *min_sell = 0;
X      return(i);
X    }
X}
X
X
X/* Check to see if he will be carrying too many objects	-RAK-	*/
Xint store_check_num(store_num)
Xint store_num;
X{
X  int store_check;
X  int i;
X  store_type *s_ptr;
X  treasure_type *i_ptr;
X
X  store_check = FALSE;
X  s_ptr = &store[store_num];
X  if (s_ptr->store_ctr < STORE_INVEN_MAX) 
X    store_check = TRUE;
X  else if ((inventory[INVEN_MAX].subval > 255) && 
X	   (inventory[INVEN_MAX].subval < 512)) 
X    for (i = 0; i < s_ptr->store_ctr; i++)
X      {
X	i_ptr = &s_ptr->store_inven[i].sitem;
X	if (i_ptr->tval == inventory[INVEN_MAX].tval) 
X	  if (i_ptr->subval == inventory[INVEN_MAX].subval) 
X	    store_check = TRUE;
X      }
X  return(store_check);
X}
X
X
X/* Insert INVEN_MAX at given location	*/
Xinsert_store(store_num, pos, icost)
Xint store_num, pos, icost;
X{
X  int i;
X  store_type *s_ptr;
X
X  s_ptr = &store[store_num];
X  for (i = s_ptr->store_ctr-1; i >= pos; i--)
X    s_ptr->store_inven[i+1] = s_ptr->store_inven[i];
X  s_ptr->store_inven[pos].sitem = inventory[INVEN_MAX];
X  s_ptr->store_inven[pos].scost = -icost;
X  s_ptr->store_ctr++;
X}
X
X
X/* Add the item in INVEN_MAX to stores inventory.	-RAK-	*/
Xstore_carry(store_num, ipos)
Xint store_num;
Xint *ipos;
X{
X  int item_num, item_val;
X  int typ, subt, icost, dummy;
X  int flag;
X  treasure_type *i_ptr;
X  store_type *s_ptr;
X
X  *ipos = 0;
X  identify(inventory[INVEN_MAX]);
X  known2(inventory[INVEN_MAX].name);
X  (void) sell_price(store_num, &icost, &dummy, inventory[INVEN_MAX]);
X  if (icost > 0) 
X    {
X      i_ptr = &inventory[INVEN_MAX];
X      s_ptr = &store[store_num];
X      item_val = 0;
X      item_num = i_ptr->number;
X      flag = FALSE;
X      typ  = i_ptr->tval;
X      subt = i_ptr->subval;
X      do
X	{
X	  i_ptr = &s_ptr->store_inven[item_val].sitem;
X	  if (typ == i_ptr->tval) 
X	    {
X	      if (subt == i_ptr->subval) /* Adds to other item	*/
X		if (subt > 255) 
X		  {
X		    if (i_ptr->number < 24)  
X		      i_ptr->number += item_num;
X		    flag = TRUE;
X		  }
X	    }
X	  else if (typ > i_ptr->tval) 
X	    {		/* Insert into list		*/
X	      insert_store(store_num, item_val, icost);
X	      flag = TRUE;
X	      *ipos = item_val;
X	    }
X	  item_val++;
X	}
X      while ((item_val < s_ptr->store_ctr) && (!flag));
X      if (!flag) 	/* Becomes last item in list	*/
X	{
X	  insert_store(store_num, (int)s_ptr->store_ctr, icost);
X	  *ipos = s_ptr->store_ctr - 1;
X	}
X    }
X}
X
X/* Destroy an item in the stores inventory.  Note that if	*/
X/* "one_of" is false, an entire slot is destroyed	-RAK-	*/
Xstore_destroy(store_num, item_val, one_of)
Xint store_num, item_val;
Xint one_of;
X{
X  int j;
X  store_type *s_ptr;
X  treasure_type *i_ptr;
X  
X  s_ptr = &store[store_num];
X  inventory[INVEN_MAX] = s_ptr->store_inven[item_val].sitem;
X  i_ptr = &s_ptr->store_inven[item_val].sitem;
X  if ((i_ptr->number > 1) && (i_ptr->subval < 512) && (one_of))  
X    {
X      i_ptr->number--;
X      inventory[INVEN_MAX].number = 1;
X    }
X  else
X    {
X      for (j = item_val; j < s_ptr->store_ctr-1; j++)
X	s_ptr->store_inven[j] = s_ptr->store_inven[j+1];
X      s_ptr->store_inven[s_ptr->store_ctr-1].sitem = blank_treasure;
X      s_ptr->store_inven[s_ptr->store_ctr-1].scost = 0;
X      s_ptr->store_ctr--;
X    }
X}
X
X
X/* Initializes the stores with owners			-RAK-	*/
Xstore_init()
X{
X  int i, j, k;
X  store_type *s_ptr;
X
X  i = MAX_OWNERS / MAX_STORES;
X  for (j = 0; j < MAX_STORES; j++)
X    {
X      s_ptr = &store[j];
X      s_ptr->owner = MAX_STORES*(randint(i)-1) + j;
X      s_ptr->insult_cur = 0;
X      s_ptr->store_open = 0;
X      s_ptr->store_ctr  = 0;
X      for (k = 0; k < STORE_INVEN_MAX; k++)
X	{
X	  s_ptr->store_inven[k].sitem = blank_treasure;
X	  s_ptr->store_inven[k].scost = 0;
X	}
X    }
X}
X
X
X/* Creates an item and inserts it into store's inven	-RAK-	*/
Xstore_create(store_num)
Xint store_num;
X{
X  int i, tries, cur_pos, dummy;
X  store_type *s_ptr;
X  treasure_type *t_ptr;
X
X  tries = 0;
X  popt(&cur_pos);
X  s_ptr = &store[store_num];
X  do
X    {
X      i = store_choice[store_num][randint(STORE_CHOICES)-1];
X      t_list[cur_pos] = inventory_init[i];
X      magic_treasure(cur_pos, OBJ_TOWN_LEVEL);
X      inventory[INVEN_MAX] = t_list[cur_pos];
X      if (store_check_num(store_num)) 
X	{
X	  t_ptr = &t_list[cur_pos];
X	  if (t_ptr->cost > 0) 	/* Item must be good	*/
X	    if (t_ptr->cost < owners[s_ptr->owner].max_cost) 
X	      {
X		store_carry(store_num, &dummy);
X		tries = 10;
X	      }
X	}
X      tries++;
X    }
X  while (tries <= 3);
X  pusht(cur_pos);
X}
X
X
X/* Initialize and up-keep the store's inventory.		-RAK-	*/
Xstore_maint()
X{
X  int i, j;
X  store_type *s_ptr;
X
X  for (i = 0; i < MAX_STORES; i++)
X    {
X      s_ptr = &store[i];
X      s_ptr->insult_cur = 0;
X      if (s_ptr->store_ctr > STORE_MAX_INVEN) 
X	for (j = 0; j < (s_ptr->store_ctr-STORE_MAX_INVEN+2); j++)
X	  store_destroy(i, randint((int)s_ptr->store_ctr)-1, FALSE);
X      else if (s_ptr->store_ctr < STORE_MIN_INVEN) 
X	{
X	  for (j = 0; j < (STORE_MIN_INVEN-s_ptr->store_ctr+2); j++)
X	    store_create(i);
X	}
X      else
X	{
X	  for (j = 0; j < (1+randint(STORE_TURN_AROUND)); j++)
X	    store_destroy(i, randint((int)s_ptr->store_ctr)-1, TRUE);
X	  for (j = 0; j < (1+randint(STORE_TURN_AROUND)); j++)
X	    store_create(i);
X	}
X    }
X}
END_OF_store1.c
if test 8587 -ne `wc -c <store1.c`; then
    echo shar: \"store1.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f types.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"types.h\"
else
echo shar: Extracting \"types.h\" \(10579 characters\)
sed "s/^X//" >types.h <<'END_OF_types.h'
Xtypedef unsigned char byteint;
X#ifdef NO_SIGNED_CHARS
Xtypedef short bytlint;
X#else
Xtypedef char bytlint;
X#endif
Xtypedef unsigned short wordint;
Xtypedef short worlint;
X
Xtypedef char atype[17];
Xtypedef char btype[15];
Xtypedef char ctype[27];
Xtypedef char dtype[6];
Xtypedef char etype[35];
Xtypedef char ttype[80];
Xtypedef char vtype[80];
Xtypedef char stat_type[7];
X
Xtypedef struct creature_type
X{
X  ctype name;           /* Descrip of creature	*/
X  unsigned int cmove;	/* Bit field		*/
X  unsigned int spells;  /* Creature spells	*/
X  wordint cdefense;	/* Bit field		*/
X  worlint sleep;	/* Inactive counter	*/
X  wordint mexp; 	/* Exp value for kill	*/
X  byteint aaf;          /* Area affect radius	*/
X  byteint ac;           /* AC			*/
X  bytlint speed;	/* Movement speed	*/
X  char cchar;		/* Character rep.	*/
X  dtype hd;             /* Creatures hit die	*/
X  etype damage;         /* Type attack and damage*/
X  byteint level;	/* Level of creature	*/
X} creature_type;
X
Xtypedef struct monster_type
X{
X  worlint hp;   	/* Hit points		*/
X  worlint csleep;	/* Inactive counter	*/
X  worlint cdis;	        /* Cur dis from player	*/
X  wordint mptr;	        /* Pointer into creature	*/
X  wordint nptr;	        /* Pointer to next block	*/
X  bytlint cspeed;	/* Movement speed	*/
X  /* Note: FY and FX constrain dungeon size to 255	*/
X  byteint fy;	        /* Y Pointer into map	*/
X  byteint fx;	        /* X Pointer into map	*/
X  int stunned;           /* Rounds stunned*/
X  int ml;               /* On if shown   */
X  int confused;         /* On if confused*/
X} monster_type;
X
Xtypedef struct treasure_type
X{
X  ttype name;	        /* Object name		*/
X  byteint tval;	        /* Category number	*/
X  char tchar;		/* Character representation*/
X  unsigned int flags;	/* Special flags		*/
X  int p1;	        /* Misc. use variable	*/
X  int cost;	        /* Cost of item		*/
X  int subval;	        /* Sub-category number	*/
X  wordint weight;	/* Weight		*/
X  wordint number;	/* Number of items	*/
X  worlint tohit;	/* Plusses to hit		*/
X  worlint todam;	/* Plusses to damage	*/
X  worlint ac;	        /* Normal AC		*/
X  worlint toac;	        /* Plusses to AC		*/
X  dtype damage;	        /* Damage when hits	*/
X  bytlint level;	/* Level item found	*/
X} treasure_type;
X
Xtypedef struct player_type 
X{
X  struct misc
X    {
X      vtype name;	/* Name of character	*/
X      vtype race;	/* Race of character	*/
X      vtype sex;	/* Sex of character	*/
X      vtype title;	/* Character's title	*/
X      vtype tclass;	/* Character's class	*/
X      int max_exp;	/* Max experience*/
X      int exp;	        /* Cur experience	*/
X      int au;	        /* Gold		*/
X      wordint age;	/* Characters age*/
X      wordint ht;	/* Height	*/
X      wordint wt;	/* Weight	*/
X      wordint lev;	/* Level		*/
X      wordint max_lev;	/* Max level explored*/
X      worlint srh;	/* Chance in search*/
X      worlint fos;	/* Frenq of search*/
X      worlint bth;	/* Base to hit	*/
X      worlint bthb;	/* BTH with bows	*/
X      worlint mana;	/* Mana points	*/
X      worlint mhp;	/* Max hit pts	*/
X      worlint ptohit;	/* Plusses to hit	*/
X      worlint ptodam;	/* Plusses to dam	*/
X      worlint pac;	/* Total AC	*/
X      worlint ptoac;	/* Magical AC	*/
X      worlint dis_th;	/* Display +ToHit*/
X      worlint dis_td;	/* Display +ToDam*/
X      worlint dis_ac;	/* Display +ToAC */
X      worlint dis_tac;	/* Display +ToTAC*/
X      worlint disarm;	/* % to Disarm	*/
X      worlint save;	/* Saving throw	*/
X      worlint sc;	/* Social Class	*/
X      byteint pclass;	/* # of class		*/
X      byteint prace;	/* # of race		*/
X      byteint hitdie;	/* Char hit die	*/
X      bytlint stl;	/* Stealth factor*/
X      double expfact;	/* Experience factor*/
X      double cmana;	/* Cur mana pts  */
X      double chp;  	/* Cur hit pts	*/
X      vtype history[5]; /* History record*/
X    } misc;
X  struct stats
X    {
X      byteint str;	/* Max strength	      */
X      byteint cstr;	/* Current strength    */
X      byteint dex;	/* Max dexterity	      */
X      byteint cdex;	/* Current dexterity   */
X      byteint con;	/* Max constitution    */
X      byteint ccon;	/* Current constitution*/
X      byteint intel;	/* Max intelligence    */
X      byteint cint;	/* Current intelligence*/
X      byteint wis;	/* Max wisdom	      */
X      byteint cwis;	/* Current wisdom      */
X      byteint chr;	/* Max charisma	      */
X      byteint cchr;	/* Current charisma    */
X    } stats;
X  struct flags
X    {
X      unsigned int status;	/* Status of player    */
X      int rest;	                /* Rest counter	      */
X      int blind;	        /* Blindness counter   */
X      int paralysis;	        /* Paralysis counter   */
X      int confused;	        /* Confusion counter   */
X      int food;	                /* Food counter        */
X      int food_digested;	/* Food per round      */
X      int protection;	        /* Protection fr. evil */
X      int speed;	        /* Cur speed adjust    */
X      int fast;	                /* Temp speed change   */
X      int slow;	                /* Temp speed change   */
X      int afraid;	        /* Fear                */
X      int poisoned;	        /* Poisoned            */
X      int image;	        /* Hallucinate          */
X      int protevil;	        /* Protect VS evil     */
X      int invuln;	        /* Increases AC        */
X      int hero;	                /* Heroism	      */
X      int shero;	        /* Super Heroism	      */
X      int blessed;	        /* Blessed	      */
X      int resist_heat;	        /* Timed heat resist   */
X      int resist_cold;	        /* Timed cold resist   */
X      int detect_inv;	        /* Timed see invisible */
X      int word_recall;	        /* Timed teleport level*/
X      int see_infra;	        /* See warm creatures  */
X      int tim_infra;	        /* Timed infra vision  */
X      int see_inv;	        /* Can see invisible   */
X      int teleport;	        /* Random teleportation*/
X      int free_act;	        /* Never paralyzed     */
X      int slow_digest;	        /* Lower food needs    */
X      int aggravate;	        /* Aggravate monsters   */
X      int fire_resist;	        /* Resistance to fire  */
X      int cold_resist;	        /* Resistance to cold  */
X      int acid_resist;	        /* Resistance to acid  */
X      int regenerate;	        /* Regenerate hit pts  */
X      int lght_resist;	        /* Resistance to light */
X      int ffall;	        /* No damage falling   */
X      int sustain_str;	        /* Keep strength       */
X      int sustain_int;	        /* Keep intelligence   */
X      int sustain_wis;	        /* Keep wisdom         */
X      int sustain_con;	        /* Keep constitution   */
X      int sustain_dex;	        /* Keep dexterity      */
X      int sustain_chr;	        /* Keep charisma       */
X      int confuse_monster;	/* Glowing hands...    */
X    } flags;
X} player_type;
X
Xtypedef struct spell_type
X{
X  ctype sname;
X  byteint slevel;
X  byteint smana;
X  wordint sexp;
X  byteint sfail;
X  int learned;
X} spell_type;
X
Xtypedef struct spl_rec
X{
X  int splnum;
X  int splchn;
X} spl_rec;
X
Xtypedef spl_rec spl_type[22];
X
Xtypedef struct race_type
X{
X  vtype trace;		/* Type of race		*/
X  bytlint str_adj;	/* adjustments		*/
X  bytlint int_adj;
X  bytlint wis_adj;
X  bytlint dex_adj;
X  bytlint con_adj;
X  bytlint chr_adj;
X  wordint b_age;        /* Base age of character	*/
X  wordint m_age;        /* Maximum age of character	*/
X  wordint m_b_ht;       /* base height for males	*/
X  wordint m_m_ht;       /* mod height for males	*/
X  wordint m_b_wt;       /* base weight for males	*/
X  wordint m_m_wt;       /* mod weight for males	*/
X  wordint f_b_ht;       /* base height females	*/
X  wordint f_m_ht;       /* mod height for females	*/
X  wordint f_b_wt;       /* base weight for female	*/
X  wordint f_m_wt;       /* mod weight for females	*/
X  double b_exp;	        /* Base experience factor	*/
X  bytlint b_dis;        /* base chance to disarm	*/
X  bytlint srh;          /* base chance for search	*/
X  bytlint stl;          /* Stealth of character	*/
X  bytlint fos;          /* frequency of auto search	*/
X  bytlint bth;          /* adj base chance to hit	*/
X  bytlint bthb;         /* adj base to hit with bows	*/
X  bytlint bsav;         /* Race base for saving throw	*/
X  bytlint bhitdie;      /* Base hit points for race	*/
X  bytlint infra;        /* See infra-red		*/
X  unsigned int tclass;  /* Bit field for class types	*/
X} race_type;
X
Xtypedef struct class_type
X{
X  vtype title;	         /* type of class		*/
X  double m_exp;		 /* Class experience factor	*/
X  bytlint adj_hd;        /* Adjust hit points		*/
X  bytlint mdis;          /* mod disarming traps	*/
X  bytlint msrh;          /* modifier to searching	*/
X  bytlint mstl;          /* modifier to stealth	*/
X  bytlint mfos;          /* modifier to freq-of-search	*/
X  bytlint mbth;          /* modifier to base to hit	*/
X  bytlint mbthb;         /* modifier to base to hit - bows*/
X  bytlint msav;          /* Class modifier to save	*/
X  bytlint madj_str;      /* Class modifier for strength*/
X  bytlint madj_int;      /* Class modifier for intelligence*/
X  bytlint madj_wis;      /* Class modifier for wisdom	*/
X  bytlint madj_dex;      /* Class modifier for dexterity*/
X  bytlint madj_con;      /* Class modifier for constitution*/
X  bytlint madj_chr;      /* Class modifier for charisma*/
X  int pspell;	         /* class use priest spells	*/
X  int mspell;	         /* class use mage spells	*/
X} class_type;
X
Xtypedef struct background_type
X{
X  vtype info;	   /* History information	*/
X  byteint roll;    /* Die roll needed for history*/
X  byteint chart;   /* Table number		*/
X  bytlint next;    /* Pointer to next table	*/
X  bytlint bonus;   /*  Bonus to the Social Class	*/
X} background_type;
X
Xtypedef struct floor_type
X{
X  int ftval;
X  int ftopen;
X} floor_type;
X
Xtypedef struct cave_type
X{
X  byteint cptr;
X  byteint tptr;
X  int fval;
X  int fopen;
X  int fm;          /* used for hidden objects */
X  int pl;
X  int tl;
X} cave_type;
X
Xtypedef struct owner_type
X{
X  vtype owner_name;
X  worlint max_cost;
X  double max_inflate;
X  double min_inflate;
X  double haggle_per;
X  byteint owner_race;
X  byteint insult_max;
X} owner_type;
X
Xtypedef struct inven_record
X{
X  int scost;
X  treasure_type sitem;
X} inven_record;
X
Xtypedef struct store_type
X{
X  worlint store_open;
X  short insult_cur;
X  byteint owner;
X  byteint store_ctr;
X  inven_record store_inven[STORE_INVEN_MAX];
X} store_type;
X
Xtypedef struct high_scores
X{
X  long int points;
X  wordint lev;
X  wordint max_lev;
X  worlint mhp;
X  double chp;
X  int uid;
X  int dun_level;
X  char sex;
X  vtype name;
X  vtype died_from;
X  byteint pclass;
X  byteint prace;
X} high_scores;
END_OF_types.h
if test 10579 -ne `wc -c <types.h`; then
    echo shar: \"types.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 15 \(of 16\).
cp /dev/null ark15isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 16 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0