-+-+-+-+-+-+-+-+ START OF PART 9 -+-+-+-+-+-+-+-+ X DECgraphicsOFF(); X `7D else X# endif X lprc(objnamelist`5Bk`5D); X break; X X default: X if (boldobjects) X setbold(); X lprc(objnamelist`5Bk`5D); X if (boldobjects) X resetbold(); X break; X `7D; X know`5Bx`5D`5By`5D = KNOWALL; /* we end up knowing about it */ X `7D X X/* X showplayer() X X subroutine to show where the player is on the screen X cursor values start from 1 up X */ Xshowplayer() X `7B X show1cell( oldx, oldy ); X cursor(playerx+1,playery+1); X lprc('@'); X cursor(playerx+1,playery+1); X oldx=playerx; oldy=playery; X `7D X X/* X moveplayer(dir) X X subroutine to move the player from one room to another X returns 0 if can't move in that direction or hit a monster or on an obje Vct X else returns 1 X nomove is set to 1 to stop the next move (inadvertent monsters hitting X players when walking into walls) if player walks off screen or into wall X */ Xshort diroffx`5B`5D = `7B 0, 0, 1, 0, -1, 1, -1, 1, -1 `7D; Xshort diroffy`5B`5D = `7B 0, 1, 0, -1, 0, -1, -1, 1, 1 `7D; Xmoveplayer(dir) X int dir; /* from = present room # direction = `5B1-north`5D X `5B2-east`5D `5B3-south`5D `5B4-west`5D `5B5-nor Vtheast`5D X `5B6-northwest`5D `5B7-southeast`5D `5B8-southwe Vst`5D X if direction=0, don't move--just show where he is */ X `7B X register int k,m,i,j; X extern char prayed ; X X if (c`5BCONFUSE`5D) if (c`5BLEVEL`5D=MAXX `7C`7C m<0 `7C`7C m>=MAXY) `7B nomove=1; return(y Vrepcount = 0); `7D X i = item`5Bk`5D`5Bm`5D; j = mitem`5Bk`5D`5Bm`5D; X X /* prevent the player from moving onto a wall, or a closed door when X in command mode, unless the character has Walk-Through-Walls. X */ X if ((i==OCLOSEDDOOR && !prompt_mode) `7C`7C (i==OWALL) && c`5BWTW`5D==0) X `7B`20 X nomove=1; `20 X return(yrepcount = 0);`20 X `7D X if (k==33 && m==MAXY-1 && level==1) X `7B X newcavelevel(0);`20 X for (k=0; k0) `20 X `7B hitmonster(k,m); return(yrepcount = 0); `7D`20 X X /* check for the player ignoring an altar when in command mode. X */ X if ((!prompt_mode) && X (item`5Bplayerx`5D`5Bplayery`5D == OALTAR) && X (!prayed)) X `7B X cursors(); X lprcat("\nYou have ignored the altar!"); X act_ignore_altar(); X `7D X prayed = 0 ; X X lastpx = playerx; lastpy = playery; X playerx = k; playery = m; X if (i && i!=OTRAPARROWIV && i!=OIVTELETRAP && i!=OIVDARTRAP && i!=OIVTRA VPDOOR)`20 X return(yrepcount = 0); `20 X else`20 X return(1); X `7D X`0C X/* X * function to show what magic items have been discovered thus far X * enter with -1 for just spells, anything else will give scrolls & potions X */ Xstatic int lincount,count; Xseemagic(arg) X int arg; X `7B X register int i,j,k,number; X char sort`5BSPNUM+1`5D; /* OK as long as SPNUM > MAXSCROLL,MAXPOTION */ X X count = lincount = 0; X nosignal=1; X X /* count and sort the known spell codes X */ X for (j=0; j <= SPNUM ; j++ ) X sort`5Bj`5D = SPNUM ; X for (number = i = 0 ; i < SPNUM ; i++ ) X if (spelknow`5Bi`5D) X `7B X number++; X j = 0 ; X while ( strncmp( spelcode`5B sort`5Bj`5D `5D, spelcode`5B i `5D, V 3 ) < 0 ) X j++ ; X k = number - 1; X while ( k > j ) X sort`5Bk`5D = sort`5B k-1 `5D, k-- ; X sort`5Bj`5D = i ; X `7D X X if (arg == -1) /* if display spells while casting one */ X `7B X cl_up(79, ((number + 2) / 3 + 4 )); /* lines needed for display */ X cursor(1,1); X `7D X else X `7B X resetscroll(); X clear(); X `7D X X lprcat("The magic spells you have discovered thus far:\n\n"); X for (i=0; i j ) X sort`5Bk`5D = sort`5B k-1 `5D, k-- ; X sort`5Bj`5D = i ; X `7D X X lprcat("\nThe magic scrolls you have found to date are:\n\n"); X count=0; X for (i=0; i < number; i++ ) X `7B X lprintf("%-26s", &scrollname`5Bsort`5Bi`5D`5D`5B1`5D); X seepage(); X `7D X X lincount += 3; X if ( count != 0 ) X `7B X count=2; X seepage(); X `7D X X /* count and sort the known potions X */ X for (j=0; j <= MAXPOTION ; j++ ) X sort`5Bj`5D = MAXPOTION ; X for (number = i = 0 ; i < MAXPOTION ; i++ ) X if (potionname`5Bi`5D`5B0`5D) X `7B X number++; X j = 0 ; X while ( strcmp( &potionname`5Bsort`5Bj`5D`5D`5B1`5D, &potionname V`5Bi`5D`5B1`5D ) < 0 ) X j++ ; X k = number - 1; X while ( k > j ) X sort`5Bk`5D = sort`5B k-1 `5D, k-- ; X sort`5Bj`5D = i ; X `7D X X lprcat("\nThe magic potions you have found to date are:\n\n"); X count=0; X for (i=0; i < number; i++) X `7B X lprintf("%-26s",&potionname`5Bsort`5Bi`5D`5D`5B1`5D); X seepage(); X `7D X X if (lincount!=0) X more(FALSE); X nosignal=0; X setscroll(); X drawscreen(); X `7D X X/* X * subroutine to paginate the seemagic function X */ Xstatic seepage() X `7B X if (++count==3) X `7B X lincount++; count=0; lprc('\n'); X if (lincount>17) `7B lincount=0; more(FALSE); clear(); `7D X `7D X `7D $ CALL UNPACK DISPLAY.C;1 273451397 $ create 'f' X/************************************************************************ X * * X * Copyright (c) 1982, Fred Fish * X * All Rights Reserved * X * * X * This software and/or documentation is released for public * X * distribution for personal, non-commercial use only. * X * Limited rights to use, modify, and redistribute are hereby * X * granted for non-commercial purposes, provided that all * X * copyright notices remain intact and all changes are clearly * X * documented. The author makes no warranty of any kind with * X * respect to this product and explicitly disclaims any implied * X * warranties of merchantability or fitness for any particular * X * purpose. * X * * X ************************************************************************ X */ X X`0C X/* X * LIBRARY FUNCTION X * X * fgetlr get logical record from a file X * X * KEY WORDS X * X * fgetlr X * string functions X * X * SYNOPSIS X * X * char *fgetlr(bp,bpsize,fp) X * char *bp; X * int bpsize; X * FILE *fp; X * X * DESCRIPTION X * X * Reads the next logical record from stream "fp" into buffer "bp" X * until next unescaped newline, "bpsize" minus one characters X * have been read, end of file, or read error. X * The last character read is followed by a NULL. X * X * A logical record may span several physical records by having X * each newline escaped with the standard C escape character X * (backslash). X * X * This is particularly useful for things like the termcap X * file, where a single entry is too long for one physical X * line, yet needs to be treated as a single record. X * X * Returns its first argument unless an end of file or read X * error occurs prior to any characters being read. X * X * BUGS X * X * The only way to know if read was terminated due to buffer size X * limitation is to test for a newline before the terminating X * null. X * X */ X X#include X`0C X/* X * PSEUDO CODE X * X * Begin fgetlr X * If read fails then X * Return NULL. X * Else X * Find out how many characters were read. X * Initialize pointer to terminating null. X * If last char read was newline then X * If newline was escaped then X * Replace backslash with the newline. X * Replace newline with null. X * Read and append more. X * End if X * End if X * Return buffer pointer. X * End if X * End fgetlr X * X */ X Xchar *fgetlr(bp,bpsize,fp) Xchar *bp; Xint bpsize; XFILE *fp; X`7B X int numch; X char *cp; X X if (fgets(bp,bpsize,fp) == NULL) `7B X return(NULL); X `7D else `7B X numch = strlen(bp); X cp = &bp`5Bnumch`5D; X if (*--cp == '\n') `7B X if (numch > 1 && *--cp == '\\') `7B X *cp++ = '\n'; X *cp = (char) NULL; X fgetlr(cp,bpsize-numch+1,fp); X `7D X `7D X return(bp); X `7D X`7D $ CALL UNPACK FGETLR.C;1 1797404434 $ create 'f' X/* fortune.c */ X#ifdef VMS X#include X#include X#include X#else X# include X# include X# ifndef BSD4.1 X# include X# else BSD4.1 X# define O_RDONLY 0 X# endif BSD4.1 X#endif VMS X X#include "header.h" X#include "player.h" X#include "larndefs.h" Xextern char fortfile`5B`5D; X Xoutfortune() X `7B X char *p; X X lprcat("\nThe cookie was delicious."); X if (c`5BBLINDCOUNT`5D) X return; X#ifdef MSDOS X msdosfortune(); X#else X if (p=fortune(fortfile)) X `7B X lprcat(" Inside you find a scrap of paper that says:\n"); X lprcat(p); X `7D X#endif X `7D X X# ifdef MSDOS X# include X/* Rumors has been entirely rewritten to be disk based. This is marginally X * slower, but requires no mallocked memory. Notice this in only valid for X * files smaller than 32K. X */ Xstatic int fortsize = 0; X Xstatic msdosfortune() X`7B X int fd, status, i; X char buf`5BBUFSIZ`5D, ch; X X if (fortsize < 0) /* We couldn't open fortunes */ X return; X if ((fd = open(fortfile, O_RDONLY `7C O_BINARY)) >= 0) `7B X if (fortsize == 0) X fortsize = (int) lseek(fd, 0L, 2); X if (lseek(fd, (long) rund(fortsize), 0) < 0) X return; X X /* Skip to next newline or EOF X */ X do `7B X status = read(fd, &ch, 1); X `7D while (status != EOF && ch != '\n'); X if (status == EOF) X if (lseek(fd, 0L, 0) < 0) /* back to the beginning */ X return; X X /* Read in the line. Search for CR ('\r'), not NL X */ X for (i = 0; i < BUFSIZ - 1; i++) X if (read(fd, &buf`5Bi`5D, 1) == EOF `7C`7C buf`5Bi`5D == '\r') X break; X buf`5Bi`5D = '\0'; X X /* And spit it out X */ X lprcat(" Inside you find a scrap of paper that says:\n"); X lprcat(buf); X close(fd); X `7D else X fortsize = -1; /* Don't try opening it again */ X`7D X X# else X X/* X * function to return a random fortune from the fortune file X */ Xstatic char *base=0; /* pointer to the fortune text */ Xstatic char **flines=0; /* array of pointers to each fortune */ Xstatic int fd=0; /* true if we have load the fortune info */ Xstatic int nlines=0; /* # lines in fortune database */ X Xstatic char *fortune(file) Xchar *file; X`7B X register char *p; X register int lines,tmp; X struct stat stat; X void *malloc(); X X if (fd == 0) `7B X if ((fd=open(file,O_RDONLY)) < 0) /* open the file */ X return(0); /* can't find file */ X X /* find out how big fortune file is and get memory for it */ X stat.st_size = 16384; X if ((fstat(fd,&stat) < 0) X `7C`7C ((base=(char *)malloc(1+stat.st_size)) == 0)) `7B X close(fd); X fd= -1; X free((char*)base); X return(0); /* can't stat file */ X `7D X X /* read in the entire fortune file */ X#ifdef VMS X /* X * fstat lies about the size (each record has up to X * three bytes of fill reported as actual size). X * vread returns correct size. X */ X stat.st_size = vread(fd,base,stat.st_size); X if (stat.st_size <= 0) X#else X if (vread(fd,base,stat.st_size) != stat.st_size) X#endif X `7B X close(fd); X fd= -1; X free((char*)base); X return(0); /* can't read file */ X `7D X close(fd); X base`5Bstat.st_size`5D=0; /* final NULL termination */ X X /* count up all the lines (and 0 terminate) to know memory X * needs X */ X for (p=base,lines=0; p