/* ^Y */ static void tstop() { /* Nothing if inhibited */ if(nosignal) { return; } lcreat((char *)0); clearvt100(); lflush(); signal(SIGTSTP, SIG_DFL); #ifdef SIGVTALRM /* Looks like BSD4.2 or higher - must clr mask for signal to take effect */ sigset_t set; sigprocmask(0, NULL, &set); sigprocmask(~BIT(SIGTSTP) & SIG_BLOCK, &set, NULL); #endif kill(getpid(), SIGTSTP); setupvt100(); signal(SIGTSTP, tstop); if(predostuff == 1) { s2choose(); } else { drawscreen(); } showplayer(); lflush(); }
void showscores (void) { int i, j; lflush (); lcreat ((char *) 0); if (readboard () < 0) { return; } i = winshou (); j = shou (0); if (i + j == 0) { lprcat (esb); } else { lprc ('\n'); } lflush (); }
/* * writeboard() * Function to write the scoreboard from readboard()'s buffer * * returns -1 if unable to write the scoreboard, returns 0 if all is OK */ writeboard() { FILE *fp; if ((fp = fopen(scorefile, "w")) == (FILE *)NULL) { lprcat("Can't open scorefile for writing\n"); lflush(); return(-1); } if (fwrite((char * )sco, sizeof(sco), 1, fp) != 1) { lprcat("Can't write scorefile\n"); lflush(); fclose(fp); return(-1); } if (fwrite((char * )winr, sizeof(winr), 1, fp) != 1) { lprcat("Can't write scorefile\n"); lflush(); fclose(fp); return(-1); } fflush(fp); fclose(fp); return(0); }
static void tstop() /* control Y */ { if (nosignal) return; /* nothing if inhibited */ lcreat((char*)0); clearvt100(); lflush(); signal(SIGTSTP,SIG_DFL); #ifdef SIGVTALRM /* looks like BSD4.2 or higher - must clr mask for signal to take effect*/ sigsetmask(sigblock(0)& ~BIT(SIGTSTP)); #endif kill(getpid(),SIGTSTP); setupvt100(); signal(SIGTSTP,tstop); if (predostuff==1) s2choose(); else drawscreen(); showplayer(); lflush(); }
void oelevator(int dir) { if (dir==1) { if (level == 0) { lprcat(",\nunfortunately, it is out of order."); return; } playerx = rnd(MAXX-2); playery = rnd(MAXY-2); nap(2000); newcavelevel(rund(level)); } else { if (level==DBOTTOM || level==VBOTTOM) { nap(2000); lprcat("\nand it leads straight to HELL!"); beep(); lflush(); nap(3000); died(287); } playerx = rnd(MAXX-2); playery = rnd(MAXY-2); nap(2000); newcavelevel(level + rnd(DBOTTOM - level)); } positionplayer(); draws(0,MAXX,0,MAXY); bot_linex(); }
void opit() { int i; if (rnd(101)>81) return; if (rnd(70) > 9*c[DEXTERITY]-packweight() || rnd(101)<5) { for (i=0;i<IVENSIZE;i++) if (iven[i]==OWWAND) { lprcat("\nYou float right over the pit."); return; } if (level==DBOTTOM || level == VBOTTOM) obottomless(); else { if (rnd(101)<20) { i=0; lprcat("\nYou fell ino a pit! " "A poor monster cushions your fall!\n"); } else { i = rnd(level*3+3); if (i > c[HP]) i = c[HP]; lprintf("\nYou fell into a pit! " "You suffer %d hit point%s damage.",(long)i, (i==1)?"":"s"); lastnum=261; /* if he dies scoreboard will say so */ } losehp(i); lflush(); nap(2000); newcavelevel(level+1); draws(0,MAXX,0,MAXY); } } }
static void outofstock() { lprcat("\nSorry, but we are out of that item."); lflush(); nap(2200); }
/* * readboard() Function to read in the scoreboard into a static buffer * * returns -1 if unable to read in the scoreboard, returns 0 if all is OK */ readboard() { if (lopen(scorefile)<0) { lprcat("Can't read scoreboard\n"); lflush(); return(-1); } lrfill((char*)sco,sizeof(sco)); lrfill((char*)winr,sizeof(winr)); lrclose(); lcreat((char*)0); return(0); }
static void handsfull() { lprcat("\nYou can't carry anything more!"); lflush(); nap(2200); }
/* * writeboard() Function to write the scoreboard from readboard()'s buffer * * returns -1 if unable to write the scoreboard, returns 0 if all is OK */ writeboard() { set_score_output(); if (lcreat(scorefile)<0) { lprcat("Can't write scoreboard\n"); lflush(); return(-1); } lwrite((char*)sco,sizeof(sco)); lwrite((char*)winr,sizeof(winr)); lwclose(); lcreat((char*)0); return(0); }
void obottomless() { lprcat("\nYou fell into a pit leading straight to HELL!"); beep(); lflush(); nap(3000); died(262); }
/* * routine to take a nap for n milliseconds */ void nap(int x) { if (x <= 0) return; /* eliminate chance for infinite loop */ lflush(); usleep(x * 1000); }
static void cntlc() /* what to do for a ^C */ { if (nosignal) return; /* don't do anything if inhibited */ signal(SIGQUIT,SIG_IGN); signal(SIGINT,SIG_IGN); quit(); if (predostuff==1) s2choose(); else showplayer(); lflush(); signal(SIGQUIT,cntlc); signal(SIGINT,cntlc); }
/* * routine to take a nap for n milliseconds */ void nap(int x) { if (x<=0 || nonap) return; /* eliminate chance for infinite loop */ lflush(); if (x > 999) sleep ((int)(x/1000)); else napms(x); }
/* Text to be displayed if ^C during intro screen */ static void s2choose() { cursor(1, 24); lprcat("Prees "); setbold(); lprcat("return"); resetbold(); lprcat(" to continue: "); lflush(); }
static void s2choose(void) /* text to be displayed if ^C during intro screen */ { cursor(1, 24); lprcat("Press "); setbold(); lprcat("return"); resetbold(); lprcat(" to continue: "); lflush(); }
dndstore() { register int i; dnditm = 0; nosignal = 1; /* disable signals */ clear(); dnd_2hed(); if (outstanding_taxes>0) { lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n"); beep(); lprintf("They have also told us that you owe %d gp in back taxes, and as we must\n",(long)outstanding_taxes); lprcat("comply with the law, we cannot serve you at this time. Soo Sorry.\n"); cursors(); lprcat("\nPress "); standout("escape"); lprcat(" to leave: "); lflush(); i=0; while (i!='\33') i=getchar(); drawscreen(); nosignal = 0; /* enable signals */ return; } 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) *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); } } } }
/* * showallscores() Function to show scores and the iven lists that go with them * * Returns nothing of value */ void showallscores(void) { 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 < MAXPOTION; i++) potionname[i] = potionhide[i]; for (i = 0; i < MAXSCROLL; i++) scrollname[i] = scrollhide[i]; i = winshou(); j = shou(1); if (i + j == 0) lprcat(esb); else lprc('\n'); lflush(); }
/* * routine to open the help file and return the first character - '0' */ static int openhelp(void) { if (lopen(helpfile) < 0) { lprintf("Can't open help file \"%s\" ", helpfile); lflush(); sleep(4); drawscreen(); setscroll(); return (-1); } resetscroll(); return (lgetc() - '0'); }
/* * diedlog() Subroutine to read a log file and print it out in ascii format */ void diedlog (void) { int n; char *p; struct stat stbuf; lcreat ((char *) 0); if (lopen (logfile) < 0) { lprintf ("Can't locate log file <%s>\n", logfile); return; } if (fstat (fd, &stbuf) < 0) { lprintf ("Can't stat log file <%s>\n", logfile); return; } for (n = stbuf.st_size / sizeof (struct log_fmt); n > 0; --n) { lrfill ((char *) &logg, sizeof (struct log_fmt)); p = ctime ((time_t *) & logg.diedtime); p[16] = '\n'; p[17] = 0; lprintf ("Score: %d, Diff: %d, %s %s on %d at %s", (int) (logg.score), (int) (logg.diff), logg.who, logg.what, (int) (logg.cavelev), p + 4); #ifdef EXTRA if (logg.moves <= 0) logg.moves = 1; lprintf (" Experience Level: %d, AC: %d, HP: %d/%d, Elapsed Time: %d minutes\n", (int) (logg.lev), (int) (logg.ac), (int) (logg.hp), (int) (logg.hpmax), (int) (logg.elapsedtime)); lprintf (" BYTES in: %d, out: %d, moves: %d, deaths: %d, spells cast: %d\n", (int) (logg.bytin), (int) (logg.bytout), (int) (logg.moves), (int) (logg.killed), (int) (logg.spused)); lprintf (" out bytes per move: %d", (int) (logg.bytout / logg.moves)); lprintf ("\n"); #endif } lflush (); lrclose (); return; }
int getplid (char *nam) { int fd7, high = 999, no; char *p, *p2; char name[80]; if (havepid != -1) return (havepid); /* already did it */ lflush (); /* flush any pending I/O */ sprintf (name, "%s\n", nam); /* append a \n to name */ if (lopen (playerids) < 0) /* no file, make it */ { if ((fd7 = _creat (playerids, _S_IWRITE)) < 0) return (-1); /* can't make it */ _close (fd7); goto addone; /* now append new playerid record to file */ } for (;;) /* now search for the name in the player id file */ { p = lgetl (); if (p == NULL) break; /* EOF? */ no = atoi (p); /* the id # */ p2 = lgetl (); if (p2 == NULL) break; /* EOF? */ if (no > high) high = no; /* accumulate highest id # */ if (strcmp (p2, name) == 0) /* we found him */ { return (no); /* his id number */ } } lrclose (); /* if we get here, we didn't find him in the file -- put him there */ addone: if (lappend (playerids) < 0) return (-1); /* can't open file for append */ lprintf ("%d\n%s", (int) ++high, name); /* new id # and name */ lwclose (); lcreat ((char *) 0); /* re-open terminal channel */ return (high); }
/* * readboard() Function to read in the scoreboard into a static buffer * * returns -1 if unable to read in the scoreboard, returns 0 if all is OK */ static int readboard (void) { if (lopen (scorefile) < 0) { lprcat ("Can't read scoreboard\n"); lflush (); return -1; } lrfill ((char *) sco, sizeof (sco)); lrfill ((char *) winr, sizeof (winr)); lrclose (); lcreat ((char *) 0); return 0; }
/* * readboard() Function to read in the scoreboard into a static buffer * * returns -1 if unable to read in the scoreboard, returns 0 if all is OK */ int readboard() { int i; setegid(egid); i = lopen(scorefile); setegid(gid); if (i < 0) { lprcat("Can't read scoreboard\n"); lflush(); return (-1); } lrfill((char *) sco, sizeof(sco)); lrfill((char *) winr, sizeof(winr)); lrclose(); lcreat((char *) 0); return (0); }
/* * diedlog() Subroutine to read a log file and print it out in ascii format */ void diedlog(void) { int n; char *p; static char q[] = "?"; struct stat stbuf; time_t t; lcreat((char *) 0); if (lopen(logfile) < 0) { lprintf("Can't locate log file <%s>\n", logfile); return; } if (fstat(io_infd, &stbuf) < 0) { lprintf("Can't stat log file <%s>\n", logfile); return; } for (n = stbuf.st_size / sizeof(struct log_fmt); n > 0; --n) { lrfill((char *) &logg, sizeof(struct log_fmt)); t = logg.diedtime; if ((p = ctime(&t)) == NULL) p = q; else { p[16] = '\n'; p[17] = 0; } lprintf("Score: %ld, Diff: %ld, %s %s on %ld at %s", (long) (logg.score), (long) (logg.diff), logg.who, logg.what, (long) (logg.cavelev), p + 4); #ifdef EXTRA if (logg.moves <= 0) logg.moves = 1; lprintf(" Experience Level: %ld, AC: %ld, HP: %ld/%ld, Elapsed Time: %ld minutes\n", (long) (logg.lev), (long) (logg.ac), (long) (logg.hp), (long) (logg.hpmax), (long) (logg.elapsedtime)); lprintf(" CPU time used: %ld seconds, Machine usage: %ld.%02ld%%\n", (long) (logg.cputime), (long) (logg.usage / 100), (long) (logg.usage % 100)); lprintf(" BYTES in: %ld, out: %ld, moves: %ld, deaths: %ld, spells cast: %ld\n", (long) (logg.bytin), (long) (logg.bytout), (long) (logg.moves), (long) (logg.killed), (long) (logg.spused)); lprintf(" out bytes per move: %ld, time per move: %ld ms\n", (long) (logg.bytout / logg.moves), (long) ((logg.cputime * 1000) / logg.moves)); #endif } lflush(); lrclose(); return; }
/* Code to perform the action of drinking at a fountian. Assumes that cursors() has already been called, and that a check has been made that the player is actually standing at a live fountain. */ void act_drink_fountain(void) { int x ; if (rnd(1501)<2) { lprcat("\nOops! You seem to have caught the dreadful sleep!"); lflush(); nap(3000); died(280); return; } x = rnd(100); if (x<7) { c[HALFDAM] += 200 + rnd(200); lprcat("\nYou feel a sickness coming on"); } else if (x < 13) quaffpotion(23, FALSE ); /* see invisible,but don't know the potion */ else if (x < 45) lprcat("\nnothing seems to have happened"); else if (rnd(3) != 2) fntchange(1); /* change char levels upward */ else fntchange(-1); /* change char levels downward */ if (rnd(12)<3) { lprcat("\nThe fountains bubbling slowly quiets"); item[playerx][playery]=ODEADFOUNTAIN; /* dead fountain */ know[playerx][playery]=0; } return; }
/* Perform the action of climbing up the volcanic shaft. Assumes cursors() has been called and that a check has been made that are actually at an up shaft. */ void act_up_shaft(void) { if (level!=11) { lprcat("\nThe shaft only extends 8 feet upwards before you find a blockage!"); return; } if (packweight() > 45+5*(c[STRENGTH]+c[STREXTRA])) { lprcat("\nYou slip and fall down the shaft"); lastnum=275; losehp(15+rnd(20)); bottomhp(); return; } lflush(); newcavelevel(0); volshaft_climbed( OVOLDOWN ); return; }
/* What to do for a ^C */ static void cntlc() { /* Don't do anything if inhibited */ if(nosignal) { return; } signal(SIGQUIT, SIG_IGN); signal(SIGINT, SIG_IGN); quit(); if(predostuff == 1) { s2choose(); } else { showplayer(); } lflush(); signal(SIGQUIT, cntlc); signal(SIGINT, cntlc); }
/* * writeboard() Function to write the scoreboard from readboard()'s buffer * * returns -1 if unable to write the scoreboard, returns 0 if all is OK */ static int writeboard(void) { int i; set_score_output(); if (gid != egid) setegid(egid); i = lcreat(scorefile); if (gid != egid) setegid(gid); if (i < 0) { lprcat("Can't write scoreboard\n"); lflush(); return (-1); } lwrite((char *) sco, sizeof(sco)); lwrite((char *) winr, sizeof(winr)); lwclose(); lcreat((char *) 0); return (0); }
void died(int x) { int f, win; char ch; const char *mod; time_t zzz; if (c[LIFEPROT] > 0) { /* if life protection */ switch ((x > 0) ? x : -x) { case 256: case 257: case 262: case 263: case 265: case 266: case 267: case 268: case 269: case 271: case 282: case 284: case 285: case 300: goto invalid; /* can't be saved */ }; --c[LIFEPROT]; c[HP] = 1; --c[CONSTITUTION]; cursors(); lprcat("\nYou feel wiiieeeeerrrrrd all over! "); emit_beep(); lflush(); sleep(4); return; /* only case where died() returns */ } invalid: clearvt100(); lflush(); f = 0; if (ckpflag) unlink(ckpfile);/* remove checkpoint file if used */ if (x < 0) { f++; x = -x; } /* if we are not to display the scores */ if ((x == 300) || (x == 257)) exit(0); /* for quick exit or saved game */ if (x == 263) win = 1; else win = 0; c[GOLD] += c[BANKACCOUNT]; c[BANKACCOUNT] = 0; /* now enter the player at the end of the scoreboard */ newscore(c[GOLD], logname, x, win); diedsub(x); /* print out the score line */ lflush(); set_score_output(); if ((wizard == 0) && (c[GOLD] > 0)) { /* wizards can't score */ #ifndef NOLOG if (gid != egid) setegid(egid); if (lappend(logfile) < 0) { /* append to file */ if (lcreat(logfile) < 0) { /* and can't create new * log file */ lcreat((char *) 0); lprcat("\nCan't open record file: I can't post your score.\n"); sncbr(); resetscroll(); lflush(); exit(0); } if (gid != egid) setegid(egid); chmod(logfile, 0660); if (gid != egid) setegid(gid); } if (gid != egid) setegid(gid); strcpy(logg.who, loginname); logg.score = c[GOLD]; logg.diff = c[HARDGAME]; if (x < 256) { ch = *monster[x].name; if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') mod = "an"; else mod = "a"; snprintf(logg.what, sizeof(logg.what), "killed by %s %s", mod, monster[x].name); } else snprintf(logg.what, sizeof(logg.what), "%s", whydead[x - 256]); logg.cavelev = level; time(&zzz); /* get CPU time -- write out score info */ logg.diedtime = zzz; #ifdef EXTRA times(&cputime);/* get CPU time -- write out score info */ logg.cputime = i = (cputime.tms_utime + cputime.tms_stime) / 60 + c[CPUTIME]; logg.lev = c[LEVEL]; logg.ac = c[AC]; logg.hpmax = c[HPMAX]; logg.hp = c[HP]; logg.elapsedtime = (zzz - initialtime + 59) / 60; logg.usage = (10000 * i) / (zzz - initialtime); logg.bytin = c[BYTESIN]; logg.bytout = c[BYTESOUT]; logg.moves = c[MOVESMADE]; logg.spused = c[SPELLSCAST]; logg.killed = c[MONSTKILLED]; #endif lwrite((char *) &logg, sizeof(struct log_fmt)); lwclose(); #endif /* NOLOG */ /* * now for the scoreboard maintenance -- not for a suspended * game */ if (x != 257) { if (sortboard()) { set_score_output(); scorerror = writeboard(); } } } if ((x == 256) || (x == 257) || (f != 0)) exit(0); if (scorerror == 0) showscores(); /* if we updated the scoreboard */ if (x == 263) mailbill(); exit(0); }
void diag(void) { int i, j; if ((dfile = fopen(diagfile, "w")) == (FILE *)NULL) return; lprcat("\nDiagnosing . . .\n"); lflush(); fprintf(dfile,"\n-------- Beginning of DIAG diagnostics ---------\n\n"); fprintf(dfile, "Hit points: %2ld(%2ld)\n", c[HP], c[HPMAX]); fprintf(dfile, "gold: %ld Experience: %ld Character level: %ld Level in caverns: %d\n", (long) c[GOLD], (long) c[EXPERIENCE], (long) c[LEVEL], level); fprintf(dfile, "\nFor the c[] array:\n"); fflush(dfile); for( j=0; j<100; j++) fprintf(dfile, "c[%d]\t%-20s\t= %ld\n", j, cdef[j], c[j]); fprintf(dfile, "\n\n"); fflush(dfile); fprintf(dfile, "Inventory\n"); for (j=0; j<IVENSIZE; j++) { fprintf (dfile, "iven[%d] %-12s = %d", j, ivendef[iven[j]], iven[j] ); fprintf (dfile, "\t%s", objectname[iven[j]] ); fprintf (dfile, "\t+ %d\n", ivenarg[j] ); } fprintf(dfile, "\nHere are the maps:\n\n"); monstnamelist[DEMONLORD] = '1'; monstnamelist[DEMONLORD+1] = '2'; monstnamelist[DEMONLORD+2] = '3'; monstnamelist[DEMONLORD+3] = '4'; monstnamelist[DEMONLORD+4] = '5'; monstnamelist[DEMONLORD+5] = '6'; monstnamelist[DEMONLORD+6] = '7'; monstnamelist[DEMONPRINCE] = '9'; monstnamelist[LUCIFER] = '0'; i = level; for (j = 0; j < NLEVELS; j++) { newcavelevel(j); fprintf(dfile, "\n-------------------------------------------------------------------\n"); fprintf(dfile, "Map %s level %d\n", levelname[level], level); fprintf(dfile, "-------------------------------------------------------------------\n"); diagdrawscreen(); fflush(dfile); } level = i; getlevel(); fprintf(dfile, "\n\nNow for the monster data:\n\n"); fprintf(dfile, "\nTotal types of monsters: %d\n\n", MAXMONST + 8); fprintf(dfile, " Monster Name LEV AC DAM ATT GOLD HP EXP\n"); fprintf(dfile, "-----------------------------------------------------------------\n"); fflush(dfile); for (i = 0; i <= MAXMONST + 8; i++) { fprintf(dfile, "%19s %2d %3d ", monster[i].name, monster[i].level, monster[i].armorclass); fprintf(dfile, " %3d %3d ", monster[i].damage, monster[i].attack); fprintf(dfile, "%6d %3d %6ld\n", monster[i].gold, monster[i].hitpoints, (long) monster[i].experience); fflush(dfile); } fprintf(dfile, "\nAvailable potions:\n\n"); for (i = 0; i < MAXPOTION; i++) fprintf(dfile, "%20s\n", &potionname[i][1]); fflush(dfile); fprintf(dfile, "\nAvailable scrolls:\n\n"); for (i = 0; i < MAXSCROLL; i++) fprintf(dfile, "%20s\n", &scrollname[i][1]); fflush(dfile); fprintf(dfile, "\nSpell list:\n\n"); fprintf(dfile, "spell# name description\n"); fprintf(dfile, "-------------------------------------------------\n\n"); for (j = 0; j < SPNUM; j++) { fprintf(dfile, "%-10s", spelcode[j]); fprintf(dfile," %21s\n", spelname[j]); fprintf(dfile,"%s\n", speldescript[j]); } fflush(dfile); fprintf(dfile, "\nObject list\n\n"); fprintf(dfile, "\nj \tObject \tName\n"); fprintf(dfile, "---------------------------------\n"); for (j = 0; j < MAXOBJ; j++) fprintf(dfile, "%d \t%c \t%s\n", j, objnamelist[j], objectname[j] ); fflush(dfile); fprintf(dfile,"\n-------- End of DIAG diagnostics ---------\n"); fflush(dfile); fclose(dfile); lprcat("\nDone Diagnosing.\n"); lflush(); }