From owner-freebsd-ports-bugs@FreeBSD.ORG Thu Oct 30 22:10:03 2008 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B972C1065676 for ; Thu, 30 Oct 2008 22:10:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A49258FC1A for ; Thu, 30 Oct 2008 22:10:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id m9UMA30k089384 for ; Thu, 30 Oct 2008 22:10:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id m9UMA3hf089383; Thu, 30 Oct 2008 22:10:03 GMT (envelope-from gnats) Date: Thu, 30 Oct 2008 22:10:03 GMT Message-Id: <200810302210.m9UMA3hf089383@freefall.freebsd.org> To: freebsd-ports-bugs@FreeBSD.org From: clemens fischer Cc: Subject: [patch] Re: ports/127728: ports/games/freebsd-games doesn't build, and larn(6) segfaults! X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: clemens fischer List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Oct 2008 22:10:03 -0000 The following reply was made to PR ports/127728; it has been noted by GNATS. From: clemens fischer To: bug-followup@freebsd.org, ino-news@spotteswoode.dnsalias.org Cc: Subject: [patch] Re: ports/127728: ports/games/freebsd-games doesn't build, and larn(6) segfaults! Date: Thu, 30 Oct 2008 22:42:46 +0100 --kfjH4zxOES6UT95V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline hi, when thinking about fixing our freebsd-games, I came about the following problem: to fully verify correct operation, I'd have to play all the games, since they have no test-harness! This is impossible for me to do. I only play larn(6), but my patch fixes it. In addition, it defines a knob "SWAP_YZ", which changes the hardcoded key mappings in order for people to play on eg. german keyboards with 'y' and 'z' exchanged. My biggest problem was reading and understanding the code, so I had to clean it up a little. Unfortunately, it makes the diff larger than it needs to be. It is attached. regards, clemens --kfjH4zxOES6UT95V Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="larn-spott.diff" diff --git a/work/freebsd-games-5.1.1/larn/Makefile b/work/freebsd-games-5.1.1/larn/Makefile --- a/work/freebsd-games-5.1.1/larn/Makefile +++ b/work/freebsd-games-5.1.1/larn/Makefile @@ -55,6 +55,9 @@ PROG= larn MAN= larn.6 CFLAGS+=-DPOSIX -DVER=12 -DSUBVER=0 -DNONAP -DUIDSCORE -DNOVARARGS +.ifdef SWAP_YZ +CFLAGS+=-DSWAP_YZ +.endif SRCS= main.c object.c create.c tok.c display.c global.c data.c io.c \ monster.c store.c diag.c help.c config.c nap.c bill.c scores.c \ signal.c moreobj.c movem.c regen.c fortune.c savelev.c diff --git a/work/freebsd-games-5.1.1/larn/data.c b/work/freebsd-games-5.1.1/larn/data.c --- a/work/freebsd-games-5.1.1/larn/data.c +++ b/work/freebsd-games-5.1.1/larn/data.c @@ -194,7 +194,7 @@ "","","","","","","","","","","","","","","","","","","","" }; - + /* * for the monster data * @@ -299,77 +299,81 @@ /* name array for scrolls */ -char *scrollname[] = { -"\0enchant armor", -"\0enchant weapon", -"\0enlightenment", -"\0blank paper", -"\0create monster", -"\0create artifact", -"\0aggravate monsters", -"\0time warp", -"\0teleportation", -"\0expanded awareness", -"\0haste monsters", -"\0monster healing", -"\0spirit protection", -"\0undead protection", -"\0stealth", -"\0magic mapping", -"\0hold monsters", -"\0gem perfection", -"\0spell extension", -"\0identify", -"\0remove curse", -"\0annihilation", -"\0pulverization", -"\0life protection", -"\0 ", -"\0 ", -"\0 ", -"\0 " - }; +struct scroll_or_potion +scrollname[] = { + { VALID, "enchant armor" }, + { VALID, "enchant weapon" }, + { VALID, "enlightenment" }, + { VALID, "blank paper" }, + { VALID, "create monster" }, + { VALID, "create artifact" }, + { VALID, "aggravate monsters" }, + { VALID, "time warp" }, + { VALID, "teleportation" }, + { VALID, "expanded awareness" }, + { VALID, "haste monsters" }, + { VALID, "monster healing" }, + { VALID, "spirit protection" }, + { VALID, "undead protection" }, + { VALID, "stealth" }, + { VALID, "magic mapping" }, + { VALID, "hold monsters" }, + { VALID, "gem perfection" }, + { VALID, "spell extension" }, + { VALID, "identify" }, + { VALID, "remove curse" }, + { VALID, "annihilation" }, + { VALID, "pulverization" }, + { VALID, "life protection" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, +}; -/* name array for magic potions */ -char *potionname[] = { -"\0sleep", -"\0healing", -"\0raise level", -"\0increase ability", -"\0wisdom", -"\0strength", -"\0raise charisma", -"\0dizziness", -"\0learning", -"\0gold detection", -"\0monster detection", -"\0forgetfulness", -"\0water", -"\0blindness", -"\0confusion", -"\0heroism", -"\0sturdiness", -"\0giant strength", -"\0fire resistance", -"\0treasure finding", -"\0instant healing", -" cure dianthroritis", -"\0poison", -"\0see invisible", -"\0 ", -"\0 ", -"\0 ", -"\0 ", -"\0 ", -"\0 ", -"\0 ", -"\0 ", -"\0 ", -"\0 ", -"\0 " - }; +/* name array for magic potions */ - +struct scroll_or_potion +potionname[] = { + { VALID, "sleep" }, + { VALID, "healing" }, + { VALID, "raise level" }, + { VALID, "increase ability" }, + { VALID, "wisdom" }, + { VALID, "strength" }, + { VALID, "raise charisma" }, + { VALID, "dizziness" }, + { VALID, "learning" }, + { VALID, "gold detection" }, + { VALID, "monster detection" }, + { VALID, "forgetfulness" }, + { VALID, "water" }, + { VALID, "blindness" }, + { VALID, "confusion" }, + { VALID, "heroism" }, + { VALID, "sturdiness" }, + { VALID, "giant strength" }, + { VALID, "fire resistance" }, + { VALID, "treasure finding" }, + { VALID, "instant healing" }, + { IDENTIFIED, "cure dianthroritis" }, + { VALID, "poison" }, + { VALID, "see invisible" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, + { SPARE, "" }, +}; + + /* spell data */ diff --git a/work/freebsd-games-5.1.1/larn/diag.c b/work/freebsd-games-5.1.1/larn/diag.c --- a/work/freebsd-games-5.1.1/larn/diag.c +++ b/work/freebsd-games-5.1.1/larn/diag.c @@ -77,18 +77,18 @@ (long)((hit+5)/2),(long)max(0,dam+20),(long)(monster[i].hitpoints/(dam+20)+1)); } - lprcat("\n\nHere's the list of available potions:\n\n"); - for (i=0; ip) - lwrite((char*)sp,sizeof(struct sphere)); /* save spheres of annihilation */ - time(&zzz); lprint((long)(zzz-initialtime)); - lwrite((char*)&zzz,sizeof(long)); - if (fstat(lfd,&statbuf)< 0) lprint(0L); - else lprint((long)statbuf.st_ino); /* inode # */ - lwclose(); lastmonst[0] = 0; + set_score_output(); + lwrite((char*)beenhere,MAXLEVEL+MAXVLEVEL); + for (k=0; kp) + lwrite((char*)sp,sizeof(struct sphere)); /* save spheres of annihilation */ + time(&zzz); lprint((long)(zzz-initialtime)); + lwrite((char*)&zzz,sizeof(long)); + if (fstat(lfd,&statbuf)< 0) lprint(0L); + else lprint((long)statbuf.st_ino); /* inode # */ + lwclose(); lastmonst[0] = 0; #ifndef VT100 setscroll(); #endif /* VT100 */ @@ -209,23 +214,34 @@ if (beenhere[k]) lrfill((char*)&cell[k*MAXX*MAXY],sizeof(struct cel)*MAXY*MAXX); - lrfill((char*)&c[0],100*sizeof(long)); gtime = lrint_x(); - level = c[CAVELEVEL] = lgetc(); - playerx = lgetc(); playery = lgetc(); - lrfill((char*)iven,26); lrfill((char*)ivenarg,26*sizeof(short)); - for (k=0; k zzz) fsorry(); /* file modify time */ if (c[HP]<0) { died(284); return; } /* died a post mortem death */ - oldx = oldy = 0; - i = lrint_x(); /* inode # */ - if (i && (filetimes.st_ino!=i)) fsorry(); - lrclose(); - if (strcmp(fname,ckpfile) == 0) - { - if (lappend(fname) < 0) fcheat(); else { lprc(' '); lwclose(); } - lcreat((char*)0); - } - else if (unlink(fname) < 0) fcheat(); /* can't unlink save file */ -/* for the greedy cheater checker */ - for (k=0; k<6; k++) if (c[k]>99) greedy(); - if (c[HPMAX]>999 || c[SPELLMAX]>125) greedy(); - if (c[LEVEL]==25 && c[EXPERIENCE]>skill[24]) /* if patch up lev 25 player */ - { - long tmp; - tmp = c[EXPERIENCE]-skill[24]; /* amount to go up */ - c[EXPERIENCE] = skill[24]; - raiseexperience((long)tmp); - } - getlevel(); lasttime=gtime; - } + oldx = oldy = 0; + i = lrint_x(); /* inode # */ + if (i && (filetimes.st_ino!=i)) + fsorry(); + lrclose(); + if (strcmp(fname,ckpfile) == 0) { + if (lappend(fname) < 0) + fcheat(); + else { + lprc(' '); + lwclose(); + } + lcreat((char*)0); + } + else if (unlink(fname) < 0) + fcheat(); /* can't unlink save file */ + /* for the greedy cheater checker */ + for (k=0; k<6; k++) + if (c[k]>99) + greedy(); + if (c[HPMAX]>999 || c[SPELLMAX]>125) + greedy(); + /* if patch up lev 25 player */ + if (c[LEVEL]==25 && c[EXPERIENCE]>skill[24]) { + long tmp; + tmp = c[EXPERIENCE]-skill[24]; /* amount to go up */ + c[EXPERIENCE] = skill[24]; + raiseexperience((long)tmp); + } + getlevel(); + lasttime=gtime; +} /* subroutine to not allow greedy cheaters diff --git a/work/freebsd-games-5.1.1/larn/display.c b/work/freebsd-games-5.1.1/larn/display.c --- a/work/freebsd-games-5.1.1/larn/display.c +++ b/work/freebsd-games-5.1.1/larn/display.c @@ -255,11 +255,11 @@ } } - resetbold(); if (d_flag) { always=1; botside(); always=1; bot_linex(); } - oldx=99; - d_xmin = 0 , d_xmax = MAXX , d_ymin = 0 , d_ymax = MAXY; /* for limited screen drawing */ - } - + resetbold(); if (d_flag) { always=1; botside(); always=1; bot_linex(); } + oldx=99; + d_xmin = 0 , d_xmax = MAXX , d_ymin = 0 , d_ymax = MAXY; /* for limited screen drawing */ + } + /* showcell(x,y) @@ -345,29 +345,29 @@ short diroffx[] = { 0, 0, 1, 0, -1, 1, -1, 1, -1 }; short diroffy[] = { 0, 1, 0, -1, 0, -1, -1, 1, 1 }; moveplayer(dir) - int dir; /* from = present room # direction = [1-north] - [2-east] [3-south] [4-west] [5-northeast] - [6-northwest] [7-southeast] [8-southwest] - if direction=0, don't move--just show where he is */ - { - int k,m,i,j; - if (c[CONFUSE]) if (c[LEVEL]=MAXX || m<0 || m>=MAXY) { nomove=1; return(yrepcount = 0); } - i = item[k][m]; j = mitem[k][m]; - if (i==OWALL && c[WTW]==0) { nomove=1; return(yrepcount = 0); } /* hit a wall */ - if (k==33 && m==MAXY-1 && level==1) - { - newcavelevel(0); for (k=0; k0) { hitmonster(k,m); return(yrepcount = 0); } /* hit a monster*/ - lastpx = playerx; lastpy = playery; - playerx = k; playery = m; - if (i && i!=OTRAPARROWIV && i!=OIVTELETRAP && i!=OIVDARTRAP && i!=OIVTRAPDOOR) return(yrepcount = 0); else return(1); - } - + int dir; /* from = present room # direction = [1-north] + [2-east] [3-south] [4-west] [5-northeast] + [6-northwest] [7-southeast] [8-southwest] + if direction=0, don't move--just show where he is */ + { + int k,m,i,j; + if (c[CONFUSE]) if (c[LEVEL]=MAXX || m<0 || m>=MAXY) { nomove=1; return(yrepcount = 0); } + i = item[k][m]; j = mitem[k][m]; + if (i==OWALL && c[WTW]==0) { nomove=1; return(yrepcount = 0); } /* hit a wall */ + if (k==33 && m==MAXY-1 && level==1) + { + newcavelevel(0); for (k=0; k0) { hitmonster(k,m); return(yrepcount = 0); } /* hit a monster*/ + lastpx = playerx; lastpy = playery; + playerx = k; playery = m; + if (i && i!=OTRAPARROWIV && i!=OIVTELETRAP && i!=OIVDARTRAP && i!=OIVTRAPDOOR) return(yrepcount = 0); else return(1); + } + /* * function to show what magic items have been discovered thus far * enter with -1 for just spells, anything else will give scrolls & potions @@ -403,21 +403,23 @@ lincount += 3; if (count!=0) { count=2; seepage(); } - lprcat("\nThe magic scrolls you have found to date are:\n\n"); - count=0; - for (i=0; i5) /* fast way */ + { + if (read(fd,adr,num) != num) + write(2,"error reading from input file\n",30); + num=0; + } + else { *adr++ = lgetc(); --num; } + } + else + { + num2 = iepoint-ipoint; /* # of bytes left in the buffer */ + if (num2 > num) num2=num; + pnt = inbuffer+ipoint; num -= num2; ipoint += num2; + while (num2--) *adr++ = *pnt++; + } + } + } /* - * lrfill(address,number) put input bytes into a buffer - * char *address; - * int number; + * char *lgetw() Get a whitespace ended word from input * - * Reads "number" bytes into the buffer pointed to by "address". - * Returns nothing of value + * Returns pointer to a buffer that contains word. If EOF, returns a NULL */ -lrfill(adr,num) - char *adr; - int num; - { - char *pnt; - int num2; - while (num) - { - if (iepoint == ipoint) - { - if (num>5) /* fast way */ - { - if (read(fd,adr,num) != num) - write(2,"error reading from input file\n",30); - num=0; - } - else { *adr++ = lgetc(); --num; } - } - else - { - num2 = iepoint-ipoint; /* # of bytes left in the buffer */ - if (num2 > num) num2=num; - pnt = inbuffer+ipoint; num -= num2; ipoint += num2; - while (num2--) *adr++ = *pnt++; - } - } - } +char *lgetw() +{ + char *lgp; + long cc; /* return type of lgetc() */ + int n=LINBUFSIZE, quote=0; + lgp = lgetwbuf; + do + cc=lgetc(); + while ((cc <= 32) && (cc > (long)NULL)); /* eat whitespace */ + for ( ; ; --n,cc=lgetc()) + { + if ((cc==(long)NULL) && (lgp==lgetwbuf)) + return(NULL); /* EOF */ + if ((n<=1) || ((cc<=32) && (quote==0))) { + *lgp=(char *)NULL; + return(lgetwbuf); + } + if (cc != '"') + *lgp++ = cc; + else quote ^= 1; + } +} /* - * char *lgetw() Get a whitespace ended word from input + * char *lgetl() Function to read in a line ended by newline or EOF * - * Returns pointer to a buffer that contains word. If EOF, returns a NULL + * Returns pointer to a buffer that contains the line. If EOF, returns NULL */ -char *lgetw() - { - char *lgp,cc; - int n=LINBUFSIZE,quote=0; - lgp = lgetwbuf; - do cc=lgetc(); while ((cc <= 32) && (cc > NULL)); /* eat whitespace */ - for ( ; ; --n,cc=lgetc()) - { - if ((cc==NULL) && (lgp==lgetwbuf)) return(NULL); /* EOF */ - if ((n<=1) || ((cc<=32) && (quote==0))) { *lgp=NULL; return(lgetwbuf); } - if (cc != '"') *lgp++ = cc; else quote ^= 1; - } - } +char *lgetl() +{ + int i=LINBUFSIZE; + long ch; + char *str=lgetwbuf; + for ( ; ; --i) + { + if ((*str++ = ch = lgetc()) == NULL) + { + if (str == lgetwbuf+1) + return(NULL); /* EOF */ +ot: *str = (char *)NULL; + return(lgetwbuf); /* line ended by EOF */ + } + if ((ch=='\n') || (i<=1)) + goto ot; /* line ended by \n */ + } +} /* - * char *lgetl() Function to read in a line ended by newline or EOF + * lcreat(filename) Create a new file for write + * char *filename; * - * Returns pointer to a buffer that contains the line. If EOF, returns NULL + * lcreat((char*)0); means to the terminal + * Returns -1 if error, otherwise the file descriptor opened. */ -char *lgetl() - { - int i=LINBUFSIZE,ch; - char *str=lgetwbuf; - for ( ; ; --i) - { - if ((*str++ = ch = lgetc()) == NULL) - { - if (str == lgetwbuf+1) return(NULL); /* EOF */ - ot: *str = NULL; return(lgetwbuf); /* line ended by EOF */ - } - if ((ch=='\n') || (i<=1)) goto ot; /* line ended by \n */ - } - } +lcreat(str) + char *str; + { + lpnt = lpbuf; lpend = lpbuf+BUFBIG; + if (str==NULL) return(lfd=1); + if ((lfd=creat(str,0644)) < 0) + { + lfd=1; lprintf("error creating file <%s>\n",str); lflush(); return(-1); + } + return(lfd); + } /* - * lcreat(filename) Create a new file for write - * char *filename; + * lopen(filename) Open a file for read + * char *filename; * - * lcreat((char*)0); means to the terminal - * Returns -1 if error, otherwise the file descriptor opened. + * lopen(0) means from the terminal + * Returns -1 if error, otherwise the file descriptor opened. */ -lcreat(str) - char *str; - { - lpnt = lpbuf; lpend = lpbuf+BUFBIG; - if (str==NULL) return(lfd=1); - if ((lfd=creat(str,0644)) < 0) - { - lfd=1; lprintf("error creating file <%s>\n",str); lflush(); return(-1); - } - return(lfd); - } +lopen(str) + char *str; + { + ipoint = iepoint = MAXIBUF; + if (str==NULL) return(fd=0); + if ((fd=open(str,0)) < 0) + { + lwclose(); lfd=1; lpnt=lpbuf; return(-1); + } + return(fd); + } /* - * lopen(filename) Open a file for read - * char *filename; + * lappend(filename) Open for append to an existing file + * char *filename; * - * lopen(0) means from the terminal - * Returns -1 if error, otherwise the file descriptor opened. + * lappend(0) means to the terminal + * Returns -1 if error, otherwise the file descriptor opened. */ -lopen(str) - char *str; - { - ipoint = iepoint = MAXIBUF; - if (str==NULL) return(fd=0); - if ((fd=open(str,0)) < 0) - { - lwclose(); lfd=1; lpnt=lpbuf; return(-1); - } - return(fd); - } +lappend(str) + char *str; + { + lpnt = lpbuf; lpend = lpbuf+BUFBIG; + if (str==NULL) return(lfd=1); + if ((lfd=open(str,2)) < 0) + { + lfd=1; return(-1); + } + lseek(lfd,0,2); /* seek to end of file */ + return(lfd); + } /* - * lappend(filename) Open for append to an existing file - * char *filename; + * lrclose() close the input file * - * lappend(0) means to the terminal - * Returns -1 if error, otherwise the file descriptor opened. + * Returns nothing of value. */ -lappend(str) - char *str; - { - lpnt = lpbuf; lpend = lpbuf+BUFBIG; - if (str==NULL) return(lfd=1); - if ((lfd=open(str,2)) < 0) - { - lfd=1; return(-1); - } - lseek(lfd,0,2); /* seek to end of file */ - return(lfd); - } +lrclose() + { + if (fd > 0) close(fd); + } /* - * lrclose() close the input file + * lwclose() close output file flushing if needed * * Returns nothing of value. */ -lrclose() - { - if (fd > 0) close(fd); - } +lwclose() + { + lflush(); if (lfd > 2) close(lfd); + } /* - * lwclose() close output file flushing if needed - * - * Returns nothing of value. - */ -lwclose() - { - lflush(); if (lfd > 2) close(lfd); - } - -/* - * lprcat(string) append a string to the output buffer - * avoids calls to lprintf (time consuming) + * lprcat(string) append a string to the output buffer + * avoids calls to lprintf (time consuming) */ lprcat(str) char *str; diff --git a/work/freebsd-games-5.1.1/larn/main.c b/work/freebsd-games-5.1.1/larn/main.c --- a/work/freebsd-games-5.1.1/larn/main.c +++ b/work/freebsd-games-5.1.1/larn/main.c @@ -188,47 +188,47 @@ } #endif /* HIDEBYLINK */ - if (access(savefilename,0)==0) /* restore game if need to */ - { - clear(); restorflag = 1; - hitflag=1; restoregame(savefilename); /* restore last game */ - } - sigsetup(); /* trap all needed signals */ - sethard(hard); /* set up the desired difficulty */ - setupvt100(); /* setup the terminal special mode */ - if (c[HP]==0) /* create new game */ - { - makeplayer(); /* make the character that will play */ - newcavelevel(0);/* make the dungeon */ - predostuff = 1; /* tell signals that we are in the welcome screen */ - if (nowelcome==0) welcome(); /* welcome the player to the game */ - } - drawscreen(); /* show the initial dungeon */ - predostuff = 2; /* tell the trap functions that they must do a showplayer() - from here on */ - /* nice(1); */ /* games should be run niced */ - yrepcount = hit2flag = 0; - while (1) - { - if (dropflag==0) lookforobject(); /* see if there is an object here */ - else dropflag=0; /* don't show it just dropped an item */ - if (hitflag==0) { if (c[HASTEMONST]) movemonst(); movemonst(); } /* move the monsters */ - if (viewflag==0) showcell(playerx,playery); else viewflag=0; /* show stuff around player */ - if (hit3flag) flushall(); - hitflag=hit3flag=0; nomove=1; - bot_linex(); /* update bottom line */ - while (nomove) - { - if (hit3flag) flushall(); - nomove=0; parse(); - } /* get commands and make moves */ - regen(); /* regenerate hp and spells */ - if (c[TIMESTOP]==0) - if (--rmst <= 0) - { rmst = 120-(level<<2); fillmonst(makemonst(level)); } - } - } - + if (access(savefilename,0)==0) /* restore game if need to */ + { + clear(); restorflag = 1; + hitflag=1; restoregame(savefilename); /* restore last game */ + } + sigsetup(); /* trap all needed signals */ + sethard(hard); /* set up the desired difficulty */ + setupvt100(); /* setup the terminal special mode */ + if (c[HP]==0) /* create new game */ + { + makeplayer(); /* make the character that will play */ + newcavelevel(0);/* make the dungeon */ + predostuff = 1; /* tell signals that we are in the welcome screen */ + if (nowelcome==0) welcome(); /* welcome the player to the game */ + } + drawscreen(); /* show the initial dungeon */ + predostuff = 2; /* tell the trap functions that they must do a showplayer() + from here on */ + /* nice(1); */ /* games should be run niced */ + yrepcount = hit2flag = 0; + while (1) + { + if (dropflag==0) lookforobject(); /* see if there is an object here */ + else dropflag=0; /* don't show it just dropped an item */ + if (hitflag==0) { if (c[HASTEMONST]) movemonst(); movemonst(); } /* move the monsters */ + if (viewflag==0) showcell(playerx,playery); else viewflag=0; /* show stuff around player */ + if (hit3flag) flushall(); + hitflag=hit3flag=0; nomove=1; + bot_linex(); /* update bottom line */ + while (nomove) + { + if (hit3flag) flushall(); + nomove=0; parse(); + } /* get commands and make moves */ + regen(); /* regenerate hp and spells */ + if (c[TIMESTOP]==0) + if (--rmst <= 0) + { rmst = 120-(level<<2); fillmonst(makemonst(level)); } + } + } + /* showstr() @@ -435,13 +435,19 @@ } show1(idx,str2) - int idx; - char *str2[]; - { - if (str2==0) lprintf("\n%c) %s",idx+'a',objectname[iven[idx]]); - else if (*str2[ivenarg[idx]]==0) lprintf("\n%c) %s",idx+'a',objectname[iven[idx]]); - else lprintf("\n%c) %s of%s",idx+'a',objectname[iven[idx]],str2[ivenarg[idx]]); - } + int idx; + struct scroll_or_potion *str2; + /*char *str2[];*/ +{ + if (str2==0) + lprintf("\n%c) %s",idx+'a',objectname[iven[idx]]); + /*else if (str2[ivenarg[idx]].flag == 0)*/ + else if (! IS_IDENTIFIED(str2[ivenarg[idx]].flag)) + lprintf("\n%c) %s",idx+'a',objectname[iven[idx]]); + else + lprintf("\n%c) %s of %s",idx+'a', + objectname[iven[idx]], str2[ivenarg[idx]].name); +} show3(index) int index; @@ -478,36 +484,38 @@ } } - + /* parse() get and execute a command */ parse() - { - int i,j,k,flag; - while (1) - { - k = yylex(); - switch(k) /* get the token from the input and switch on it */ - { - case 'h': moveplayer(4); return; /* west */ - case 'H': run(4); return; /* west */ - case 'l': moveplayer(2); return; /* east */ - case 'L': run(2); return; /* east */ - case 'j': moveplayer(1); return; /* south */ - case 'J': run(1); return; /* south */ - case 'k': moveplayer(3); return; /* north */ - case 'K': run(3); return; /* north */ - case 'u': moveplayer(5); return; /* northeast */ - case 'U': run(5); return; /* northeast */ - case 'y': moveplayer(6); return; /* northwest */ - case 'Y': run(6); return; /* northwest */ - case 'n': moveplayer(7); return; /* southeast */ - case 'N': run(7); return; /* southeast */ - case 'b': moveplayer(8); return; /* southwest */ - case 'B': run(8); return; /* southwest */ + { + int i,j,k,flag; + while (1) + { + k = yylex(); + switch(k) /* get the token from the input and switch on it */ + { + case 'h': moveplayer(4); return; /* west */ + case 'H': run(4); return; /* west */ + case 'l': moveplayer(2); return; /* east */ + case 'L': run(2); return; /* east */ + case 'j': moveplayer(1); return; /* south */ + case 'J': run(1); return; /* south */ + case 'k': moveplayer(3); return; /* north */ + case 'K': run(3); return; /* north */ + case 'u': moveplayer(5); return; /* northeast */ + case 'U': run(5); return; /* northeast */ + case DIRECTION_NW_y: + moveplayer(6); return; /* northwest */ + case DIRECTION_NW_Y: + run(6); return; /* northwest */ + case 'n': moveplayer(7); return; /* southeast */ + case 'N': run(7); return; /* southeast */ + case 'b': moveplayer(8); return; /* southwest */ + case 'B': run(8); return; /* southwest */ case '.': if (yrepcount) viewflag=1; return; /* stay here */ @@ -537,9 +545,15 @@ case 'S': clear(); lprcat("Saving . . ."); lflush(); savegame(savefilename); wizard=1; died(-257); /* save the game - doesn't return */ - case 'Z': yrepcount=0; if (c[LEVEL]>9) { oteleport(1); return; } - cursors(); lprcat("\nAs yet, you don't have enough experience to use teleportation"); - return; /* teleport yourself */ + case KEY_TELEPORT_Z: + yrepcount=0; + if (c[LEVEL]>9) { + oteleport(1); + return; + } + cursors(); + lprcat("\nAs yet, you don't have enough experience to use teleportation"); + return; /* teleport yourself */ case '^': /* identify traps */ flag=yrepcount=0; cursors(); lprc('\n'); for (j=playery-1; j2) /* no null items */ - { item[i][0]=OSCROLL; iarg[i][0]=i; } - for (i=MAXX-1; i>MAXX-1-MAXPOTION; i--) - if (strlen(potionname[i-MAXX+MAXPOTION])>2) /* no null items */ - { item[i][0]=OPOTION; iarg[i][0]=i-MAXX+MAXPOTION; } - for (i=1; iMAXX-1-MAXPOTION; i--) + if (IS_VALID(potionname[i-MAXX+MAXPOTION].flag)) /* no null items */ + { item[i][0]=OPOTION; iarg[i][0]=i-MAXX+MAXPOTION; } + for (i=1; i=MAXLEVEL) tmp=MAXLEVEL-1; - if (tmp<1) tmp=1; } - else - { tmp=rnd(3)+level-2; if (tmp>=MAXLEVEL+MAXVLEVEL) tmp=MAXLEVEL+MAXVLEVEL-1; - if (tmp=MAXLEVEL) tmp=MAXLEVEL-1; + if (tmp<1) tmp=1; } + else + { tmp=rnd(3)+level-2; if (tmp>=MAXLEVEL+MAXVLEVEL) tmp=MAXLEVEL+MAXVLEVEL-1; + if (tmp=MAXPOTION) return; /* check for within bounds */ - potionname[pot][0] = ' '; - switch(pot) - { - case 9: lprcat("\nYou feel greedy . . ."); nap(2000); - for (i=0; i=MAXPOTION) return; /* check for within bounds */ + MK_IDENTIFIED(potionname[pot].flag); + switch(pot) + { + case 9: lprcat("\nYou feel greedy . . ."); nap(2000); + for (i=0; i=MAXSCROLL) return; /* be sure we are within bounds */ - scrollname[typ][0] = ' '; - switch(typ) - { - case 0: lprcat("\nYour armor glows for a moment"); enchantarmor(); return; + int typ; + { + int i,j; + if (typ<0 || typ>=MAXSCROLL) return; /* be sure we are within bounds */ + MK_IDENTIFIED(scrollname[typ].flag); + switch(typ) + { + case 0: lprcat("\nYour armor glows for a moment"); enchantarmor(); return; case 1: lprcat("\nYour weapon glows for a moment"); enchweapon(); return; /* enchant weapon */ @@ -614,12 +619,14 @@ case 18: for (i=0; i<11; i++) c[exten[i]] <<= 1; /* spell extension */ break; - case 19: for (i=0; i<26; i++) /* identify */ - { - if (iven[i]==OPOTION) potionname[ivenarg[i]][0] = ' '; - if (iven[i]==OSCROLL) scrollname[ivenarg[i]][0] = ' '; - } - break; + case 19: for (i=0; i<26; i++) /* identify */ + { + if (iven[i]==OPOTION) + MK_IDENTIFIED(potionname[ivenarg[i]].flag); + if (iven[i]==OSCROLL) + MK_IDENTIFIED(scrollname[ivenarg[i]].flag); + } + break; case 20: for (i=0; i<10; i++) /* remove curse */ if (c[curse[i]]) c[curse[i]] = 1; @@ -633,7 +640,7 @@ }; } - + oorb() { } diff --git a/work/freebsd-games-5.1.1/larn/scores.c b/work/freebsd-games-5.1.1/larn/scores.c --- a/work/freebsd-games-5.1.1/larn/scores.c +++ b/work/freebsd-games-5.1.1/larn/scores.c @@ -287,16 +287,23 @@ * Returns nothing of value */ showallscores() - { - int i,j; - lflush(); lcreat((char*)0); if (readboard()<0) return; - c[WEAR] = c[WIELD] = c[SHIELD] = -1; /* not wielding or wearing anything */ - for (i=0; i'z') && (i!=' ') && (i!='\33') && (i!=12)) i=getchar(); - if (i==12) { clear(); dnd_2hed(); dnd_hed(); } - else if (i=='\33') - { drawscreen(); nosignal = 0; /* enable signals */ return; } - else if (i==' ') - { - cl_dn(1,4); - if ((dnditm += 26) >= maxitm) dnditm=0; dnd_hed(); - } - else - { /* buy something */ - lprc(i); /* echo the byte */ - i += dnditm - 'a'; - if (i>=maxitm) outofstock(); else - if (itm[i].qty <= 0) outofstock(); else - if (pocketfull()) handsfull(); else - if (c[GOLD] < itm[i].price*10) nogold(); else - { - if (itm[i].mem != 0) *itm[i].mem[itm[i].arg] = ' '; - c[GOLD] -= itm[i].price*10; - itm[i].qty--; take(itm[i].obj,itm[i].arg); - if (itm[i].qty==0) dnditem(i); nap(1001); - } - } - - } - } + dnd_hed(); + while (1) + { + cursor(59,18); + lprintf("%d gold pieces",(long)c[GOLD]); + cltoeoln(); + cl_dn(1,20); /* erase to eod */ + lprcat("\nEnter your transaction ["); + standout("space"); + lprcat(" for more, "); + standout("escape"); + lprcat(" to leave]? "); + i=0; + while ((i<'a' || i>'z') && (i!=' ') && (i!='\33') && (i!=12)) + i=getchar(); + if (i==12) { + clear(); + dnd_2hed(); + dnd_hed(); + } + else if (i=='\33') { + drawscreen(); + nosignal = 0; /* enable signals */ + return; + } + else if (i==' ') { + cl_dn(1,4); + if ((dnditm += 26) >= maxitm) + dnditm=0; + dnd_hed(); + } + else { /* buy something */ + lprc(i); /* echo the byte */ + i += dnditm - 'a'; + if (i>=maxitm) + outofstock(); + else if (itm[i].qty <= 0) + outofstock(); + else if (pocketfull()) + handsfull(); + else if (c[GOLD] < itm[i].price*10) + nogold(); + else { + if (itm[i].mem != 0) { + switch (itm[i].obj) { + case OSCROLL: + MK_IDENTIFIED(scrollname[itm[i].arg].flag); + break; + case OPOTION: + MK_IDENTIFIED(potionname[itm[i].arg].flag); + break; + default: + lprcat("\nInternal error: dndstore()!"); + lflush(); + nap(2200); + } + } + c[GOLD] -= itm[i].price*10; + itm[i].qty--; + take(itm[i].obj,itm[i].arg); + if (itm[i].qty==0) + dnditem(i); + nap(1001); + } + } + } +} /* dnditem(index) @@ -266,22 +297,31 @@ */ static void dnditem(i) - int i; - { - int j,k; - if (i >= maxitm) return; - cursor( (j=(i&1)*40+1) , (k=((i%26)>>1)+5) ); - if (itm[i].qty == 0) { lprintf("%39s",""); return; } - lprintf("%c) ",(i%26)+'a'); - if (itm[i].obj == OPOTION) - { lprcat("potion of "); lprintf("%s",&potionname[itm[i].arg][1]); } - else if (itm[i].obj == OSCROLL) - { lprcat("scroll of "); lprintf("%s",&scrollname[itm[i].arg][1]); } - else lprintf("%s",objectname[itm[i].obj]); - cursor( j+31,k ); lprintf("%6d",(long)(itm[i].price*10)); - } + int i; +{ + int j,k; + if (i >= maxitm) + return; + cursor( (j=(i&1)*40+1) , (k=((i%26)>>1)+5) ); + if (itm[i].qty == 0) { + lprintf("%39s",""); + return; + } + lprintf("%c) ",(i%26)+'a'); + if (itm[i].obj == OPOTION) { + lprcat("potion of "); + lprintf("%s",potionname[itm[i].arg].name); + } + else if (itm[i].obj == OSCROLL) { + lprcat("scroll of "); + lprintf("%s",scrollname[itm[i].arg].name); + } + else + lprintf("%s",objectname[itm[i].obj]); + cursor( j+31,k ); + lprintf("%6d",(long)(itm[i].price*10)); +} - /* for the college of larn */ @@ -394,15 +434,15 @@ course[i-'a']++; /* remember that he has taken that course */ c[HP] = c[HPMAX]; c[SPELLS] = c[SPELLMAX]; /* he regenerated */ - if (c[BLINDCOUNT]) c[BLINDCOUNT]=1; /* cure blindness too! */ - if (c[CONFUSE]) c[CONFUSE]=1; /* end confusion */ - adjtime((long)time_used); /* adjust parameters for time change */ - } - nap(1000); - } - } - } - + if (c[BLINDCOUNT]) c[BLINDCOUNT]=1; /* cure blindness too! */ + if (c[CONFUSE]) c[CONFUSE]=1; /* end confusion */ + adjtime((long)time_used); /* adjust parameters for time change */ + } + nap(1000); + } + } + } + /* * for the first national bank of Larn */ @@ -590,61 +630,100 @@ } otradepost() - { - int i,j,value,isub,izarg; - dnditm = dndcount = 0; - nosignal = 1; /* disable signals */ - resetscroll(); otradhead(); - while (1) - { - lprcat("\nWhat item do you want to sell to us ["); standout("*"); - lprcat(" for list, or "); standout("escape"); lprcat("] ? "); - i=0; while (i>'z' || (i<'a' && i!='*' && i!='\33' && i!='.')) i=getchar(); - if (i == '\33') - { setscroll(); recalc(); drawscreen(); nosignal=0; /* enable signals */ return; } - isub = i - 'a'; j=0; - if (iven[isub]==OSCROLL) if (scrollname[ivenarg[isub]][0]==0) - { j=1; cnsitm(); } /* can't sell unidentified item */ - if (iven[isub]==OPOTION) if (potionname[ivenarg[isub]][0]==0) - { j=1; cnsitm(); } /* can't sell unidentified item */ - if (!j) - if (i=='*') { clear(); qshowstr(); otradhead(); } - else if (iven[isub]==0) lprintf("\nYou don't have item %c!",isub+'a'); - else - { - for (j=0; j= 0) value *= 2; - while ((izarg-- > 0) && ((value=14*(67+value)/10) < 500000)); - } - lprintf("\nItem (%c) is worth %d gold pieces to us. Do you want to sell it? ",i,(long)value); - yrepcount=0; - if (getyn()=='y') - { - lprcat("yes\n"); c[GOLD]+=value; - if (c[WEAR] == isub) c[WEAR] = -1; - if (c[WIELD] == isub) c[WIELD] = -1; - if (c[SHIELD] == isub) c[SHIELD] = -1; - adjustcvalues(iven[isub],ivenarg[isub]); - iven[isub]=0; - } - else lprcat("no thanks.\n"); - j = maxitm+100; /* get out of the inner loop */ - } - if (j <= maxitm+2) lprcat("\nSo sorry, but we are not authorized to accept that item."); - } - } - } +{ + int i,j,value,isub,izarg; + dnditm = dndcount = 0; + nosignal = 1; /* disable signals */ + resetscroll(); + otradhead(); + while (1) + { + lprcat("\nWhat item do you want to sell to us ["); + standout("*"); + lprcat(" for list, or "); + standout("escape"); + lprcat("] ? "); + i=0; + while (i>'z' || (i<'a' && i!='*' && i!='\33' && i!='.')) i=getchar(); + if (i == '\33') { + setscroll(); + recalc(); + drawscreen(); + nosignal=0; /* enable signals */ + return; + } + isub = i - 'a'; + j=0; + if (iven[isub]==OSCROLL) + if (! IS_IDENTIFIED(scrollname[ivenarg[isub]].flag)) { + /* can't sell unidentified item */ + j=1; + cnsitm(); + } + if (iven[isub]==OPOTION) + if (! IS_IDENTIFIED(potionname[ivenarg[isub]].flag)) { + /* can't sell unidentified item */ + j=1; + cnsitm(); + } + if (!j) + if (i=='*') { + clear(); + qshowstr(); + otradhead(); + } + else + if (iven[isub]==0) + lprintf("\nYou don't have item %c!",isub+'a'); + else { + for (j=0; j= 0) + value *= 2; + while ((izarg-- > 0) && + ((value=14*(67+value)/10) < 500000)); + } + lprintf("\nItem (%c) is worth %d gold pieces to us. Do you want to sell it? ",i,(long)value); + yrepcount=0; + if (getyn()=='y') { + lprcat("yes\n"); + c[GOLD]+=value; + if (c[WEAR] == isub) + c[WEAR] = -1; + if (c[WIELD] == isub) + c[WIELD] = -1; + if (c[SHIELD] == isub) + c[SHIELD] = -1; + adjustcvalues(iven[isub],ivenarg[isub]); + iven[isub]=0; + } + else + lprcat("no thanks.\n"); + j = maxitm+100; /* get out of the inner loop */ + } + if (j <= maxitm+2) lprcat("\nSo sorry, but we are not authorized to accept that item."); + } + } +} cnsitm() { lprcat("\nSorry, we can't accept unidentified objects."); } --kfjH4zxOES6UT95V--