/* subroutine to get a number from the player and allow * to mean return amt, else return the number entered */ unsigned long readnum(long mx) { int i; unsigned long amt = 0; sncbr(); if ((i = ttgetch()) == '*') amt = mx; /* allow him to say * for all gold */ else while (i != '\n') { if (i == '\033') { scbr(); lprcat(" aborted"); return (0); } if ((i <= '9') && (i >= '0') && (amt < 99999999)) amt = amt * 10 + i - '0'; i = ttgetch(); } scbr(); return (amt); }
/* subroutine to get a number from the player and allow * to mean return amt, else return the number entered */ unsigned long readnum(long mx) { int i; unsigned long amt=0; sncbr(); /* allow him to say * for all gold */ if ((i=ttgetch()) == '*') amt = mx; else /* read chars into buffer, deleting when requested */ while (i != '\n') { if (i=='\033') { scbr(); lprcat(" aborted"); return(0); } if ((i <= '9') && (i >= '0') && (amt<999999999)) amt = amt*10+i-'0'; if ((i=='\010') || (i=='\177')) amt = (long)(amt / 10) ; i = ttgetch(); } scbr(); return(amt); }
void died (int x) { int f, win; /*char ch, *mod; time_t zzz; */ if (cdesc[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 */ }; --cdesc[LIFEPROT]; cdesc[HP] = 1; --cdesc[CONSTITUTION]; cursors (); lprcat ("\nYou feel wiiieeeeerrrrrd all over! "); lflush (); nap (NAPTIME); return; /* only case where died() returns */ } cursors (); lprcat ("\nPress any key to continue. "); ttgetch (); invalid: /*clearvt100(); */ lflush (); f = 0; /* if we are not to display the scores */ if (x < 0) { f++; x = -x; } /* for quick exit or saved game */ if ((x == 300) || (x == 257)) { clearvt100 (); exit (EXIT_SUCCESS); } if (x == 263) win = 1; else win = 0; cdesc[GOLD] += cdesc[BANKACCOUNT]; cdesc[BANKACCOUNT] = 0; /* now enter the player at the end of the scoreboard */ newscore (cdesc[GOLD], logname, x, win); diedsub (x); /* print out the score line */ lflush (); set_score_output (); if ((wizard == 0) && (cdesc[GOLD] > 0)) /* wizards can't score */ { /*if (lappend(logfile)<0) { if (lcreat(logfile)<0) { lcreat((char*)0); lprcat("\nCan't open record file: I can't post your score.\n"); sncbr(); resetscroll(); lflush(); clearvt100(); exit(EXIT_SUCCESS); } _chmod(logfile,0666); } strcpy(logg.who,logname); logg.score = cdesc[GOLD]; logg.diff = cdesc[HARDGAME]; if (x < 256) { ch = *monster[x].name; if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') mod="an"; else mod="a"; sprintf(logg.what,"killed by %s %s",mod,monster[x].name); } else sprintf(logg.what,"%s",whydead[x - 256]); logg.cavelev=level; time(&zzz); logg.diedtime=zzz; #ifdef EXTRA logg.lev=cdesc[LEVEL]; logg.ac=cdesc[AC]; logg.hpmax=cdesc[HPMAX]; logg.hp=cdesc[HP]; logg.elapsedtime=(zzz-initialtime+59)/60; logg.usage=(10000*i)/(zzz-initialtime); logg.bytin=cdesc[BYTESIN]; logg.bytout=cdesc[BYTESOUT]; logg.moves=cdesc[MOVESMADE]; logg.spused=cdesc[SPELLSCAST]; logg.killed=cdesc[MONSTKILLED]; #endif lwrite((char*)&logg,sizeof(struct log_fmt)); lwclose(); */ /* now for the scoreboard maintenance -- not for a suspended game */ if (x != 257) { if (sortboard ()) scorerror = writeboard (); } } if ((x == 256) || (x == 257) || (f != 0)) { clearvt100 (); exit (EXIT_SUCCESS); } if (scorerror == 0) { lflush (); clear (); resetscroll (); showscores (); /* if we updated the scoreboard */ cursors (); lprcat ("\nPress any key to exit. "); scbr (); ttgetch (); } clearvt100 (); exit (EXIT_SUCCESS); }
/* * parse() * * get and execute a command */ static void parse(void) { 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 */ case '.': /* stay here */ if (yrepcount) viewflag=1; return; case 'c': yrepcount=0; cast(); return; /* cast a spell */ case 'd': yrepcount=0; if (c[TIMESTOP]==0) dropobj(); return; /* to drop an object */ case 'e': yrepcount=0; if (c[TIMESTOP]==0) if (!floor_consume( OCOOKIE, "eat" )) consume( OCOOKIE, "eat", showeat ); return; /* to eat a fortune cookie */ case 'g': yrepcount = 0 ; cursors(); lprintf("\nThe stuff you are carrying presently weighs %d pounds",(long)packweight()); break ; case 'i': /* inventory */ yrepcount=0; nomove=1; showstr(FALSE); return; case 'p': /* pray at an altar */ yrepcount = 0; pray_at_altar(); return; case 'q': /* quaff a potion */ yrepcount=0; if (c[TIMESTOP]==0) if (!floor_consume( OPOTION, "quaff")) consume( OPOTION, "quaff", showquaff ); return; case 'r': yrepcount=0; if (c[BLINDCOUNT]) { cursors(); lprcat("\nYou can't read anything when you're blind!"); } else if (c[TIMESTOP]==0) if (!floor_consume( OSCROLL, "read" )) if (!floor_consume( OBOOK, "read" )) consume( OSCROLL, "read", showread ); return; /* to read a scroll */ case 's': yrepcount = 0 ; sit_on_throne(); return ; case 't': /* Tidy up at fountain */ yrepcount = 0 ; wash_fountain() ; return ; case 'v': yrepcount=0; nomove = 1; cursors(); lprintf("\nLarn, Version %d.%d.%d, Diff=%d",(long)VERSION,(long)SUBVERSION,(long)PATCHLEVEL,(long)c[HARDGAME]); if (wizard) lprcat(" Wizard"); if (cheat) lprcat(" Cheater"); return; case 'w': /* wield a weapon */ yrepcount=0; wield(); return; case 'A': yrepcount = 0; desecrate_altar(); return; case 'C': /* Close something */ yrepcount = 0 ; close_something(); return; case 'D': /* Drink at fountain */ yrepcount = 0 ; drink_fountain() ; return ; case 'E': /* Enter a building */ yrepcount = 0 ; enter() ; break ; case 'I': /* list spells and scrolls */ yrepcount=0; seemagic(0); nomove=1; return; case 'O': /* Open something */ yrepcount = 0 ; open_something(); return; case 'P': cursors(); yrepcount = 0; nomove = 1; if (outstanding_taxes>0) lprintf("\nYou presently owe %d gp in taxes.",(long)outstanding_taxes); else lprcat("\nYou do not owe any taxes."); return; case 'Q': /* quit */ yrepcount=0; quit(); nomove=1; return; case 'R' : /* remove gems from a throne */ yrepcount = 0 ; remove_gems( ); return ; case 'S': /* And do the save. */ cursors(); lprintf("\nSaving to `%s' . . . ", savefilename); lflush(); save_mode = 1; savegame(savefilename); clear(); lflush(); wizard=1; died(-257); /* doesn't return */ break; case 'T': yrepcount=0; cursors(); if (c[SHIELD] != -1) { c[SHIELD] = -1; lprcat("\nYour shield is off"); bottomline(); } else if (c[WEAR] != -1) { c[WEAR] = -1; lprcat("\nYour armor is off"); bottomline(); } else lprcat("\nYou aren't wearing anything"); return; case 'W': yrepcount=0; wear(); return; /* wear armor */ 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 ' ': yrepcount=0; nomove=1; return; case 'L'-64: yrepcount=0; drawscreen(); nomove=1; return; /* look */ #if WIZID #ifdef EXTRA case 'A'-64: yrepcount=0; nomove=1; if (wizard) { diag(); return; } /* create diagnostic file */ return; #endif #endif case '<': /* Go up stairs or vol shaft */ yrepcount = 0; up_stairs(); return ; case '>': /* Go down stairs or vol shaft*/ yrepcount = 0 ; down_stairs(); return ; case '?': /* give the help screen */ yrepcount=0; help(); nomove=1; return; case ',': /* pick up an item */ yrepcount = 0 ; /* pickup, don't identify or prompt for action */ lookforobject( FALSE, TRUE, FALSE ); return; case ':': /* look at object */ yrepcount = 0 ; /* identify, don't pick up or prompt for action */ lookforobject( TRUE, FALSE, FALSE ); nomove = 1; /* assumes look takes no time */ return; case '/': /* identify object/monster */ specify_object(); nomove = 1 ; yrepcount = 0 ; return; case '^': /* identify traps */ flag = yrepcount = 0; cursors(); lprc('\n'); for (j=playery-1; j<playery+2; j++) { if (j < 0) j=0; if (j >= MAXY) break; for (i=playerx-1; i<playerx+2; i++) { if (i < 0) i=0; if (i >= MAXX) break; switch(item[i][j]) { case OTRAPDOOR: case ODARTRAP: case OTRAPARROW: case OTELEPORTER: case OPIT: lprcat("\nIts "); lprcat(objectname[item[i][j]]); flag++; }; } } if (flag==0) lprcat("\nNo traps are visible"); return; #if WIZID case '_': /* this is the fudge player password for wizard mode*/ yrepcount=0; cursors(); nomove=1; if (getpassword()==0) { scbr(); /* system("stty -echo cbreak"); */ return; } wizard=1; scbr(); /* system("stty -echo cbreak"); */ for (i=0; i<6; i++) c[i]=70; iven[0]=iven[1]=0; take(OPROTRING,50); take(OLANCE,25); c[WIELD]=1; c[LANCEDEATH]=1; c[WEAR] = c[SHIELD] = -1; raiseexperience(6000000L); c[AWARENESS] += 25000; { int i,j; for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) know[j][i]=KNOWALL; for (i=0; i<SPNUM; i++) spelknow[i]=1; for (i=0; i<MAXSCROLL; i++) scrollname[i][0]=' '; for (i=0; i<MAXPOTION; i++) potionname[i][0]=' '; } for (i=0; i<MAXSCROLL; i++) if (strlen(scrollname[i])>2) /* 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; i<MAXY; i++) { item[0][i]=i; iarg[0][i]=0; } for (i=MAXY; i<MAXY+MAXX; i++) { item[i-MAXY][MAXY-1]=i; iarg[i-MAXY][MAXY-1]=0; } for (i=MAXX+MAXY; i<MAXOBJECT; i++) { item[MAXX-1][i-MAXX-MAXY]=i; iarg[MAXX-1][i-MAXX-MAXY]=0; } c[GOLD]+=250000; drawscreen(); return; #endif }; } }
/* parse() get and execute a command */ static void parse(void) { 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 */ case '.': if (yrepcount) viewflag = 1; return; /* stay here */ case 'w': yrepcount = 0; wield(); return; /* wield a weapon */ case 'W': yrepcount = 0; wear(); return; /* wear armor */ case 'r': yrepcount = 0; if (c[BLINDCOUNT]) { cursors(); lprcat("\nYou can't read anything when you're blind!"); } else if (c[TIMESTOP] == 0) readscr(); return; /* to read a scroll */ case 'q': yrepcount = 0; if (c[TIMESTOP] == 0) quaff(); return; /* quaff a potion */ case 'd': yrepcount = 0; if (c[TIMESTOP] == 0) dropobj(); return; /* to drop an object */ case 'c': yrepcount = 0; cast(); return; /* cast a spell */ case 'i': yrepcount = 0; nomove = 1; showstr(); return; /* status */ case 'e': yrepcount = 0; if (c[TIMESTOP] == 0) eatcookie(); return; /* to eat a fortune cookie */ case 'D': yrepcount = 0; seemagic(0); nomove = 1; return; /* list spells and scrolls */ case '?': yrepcount = 0; help(); nomove = 1; return; /* give the help screen */ 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 '^': /* identify traps */ flag = yrepcount = 0; cursors(); lprc('\n'); for (j = playery - 1; j < playery + 2; j++) { if (j < 0) j = 0; if (j >= MAXY) break; for (i = playerx - 1; i < playerx + 2; i++) { if (i < 0) i = 0; if (i >= MAXX) break; switch (item[i][j]) { case OTRAPDOOR: case ODARTRAP: case OTRAPARROW: case OTELEPORTER: lprcat("\nIt's "); lprcat(objectname[item[i][j]]); flag++; }; } } if (flag == 0) lprcat("\nNo traps are visible"); return; #if WIZID case '_': /* this is the fudge player password for * wizard mode */ yrepcount = 0; cursors(); nomove = 1; if (userid != wisid) { lprcat("Sorry, you are not empowered to be a wizard.\n"); scbr(); /* system("stty -echo cbreak"); */ lflush(); return; } if (getpassword() == 0) { scbr(); /* system("stty -echo cbreak"); */ return; } wizard = 1; scbr(); /* system("stty -echo cbreak"); */ for (i = 0; i < 6; i++) c[i] = 70; iven[0] = iven[1] = 0; take(OPROTRING, 50); take(OLANCE, 25); c[WIELD] = 1; c[LANCEDEATH] = 1; c[WEAR] = c[SHIELD] = -1; raiseexperience(6000000L); c[AWARENESS] += 25000; { int i, j; for (i = 0; i < MAXY; i++) for (j = 0; j < MAXX; j++) know[j][i] = 1; for (i = 0; i < SPNUM; i++) spelknow[i] = 1; for (i = 0; i < MAXSCROLL; i++) scrollname[i] = scrollhide[i]; for (i = 0; i < MAXPOTION; i++) potionname[i] = potionhide[i]; } for (i = 0; i < MAXSCROLL; i++) if (strlen(scrollname[i]) > 2) { /* 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; i < MAXY; i++) { item[0][i] = i; iarg[0][i] = 0; } for (i = MAXY; i < MAXY + MAXX; i++) { item[i - MAXY][MAXY - 1] = i; iarg[i - MAXY][MAXY - 1] = 0; } for (i = MAXX + MAXY; i < MAXX + MAXY + MAXY; i++) { item[MAXX - 1][i - MAXX - MAXY] = i; iarg[MAXX - 1][i - MAXX - MAXY] = 0; } c[GOLD] += 25000; drawscreen(); return; #endif case 'T': yrepcount = 0; cursors(); if (c[SHIELD] != -1) { c[SHIELD] = -1; lprcat("\nYour shield is off"); bottomline(); } else if (c[WEAR] != -1) { c[WEAR] = -1; lprcat("\nYour armor is off"); bottomline(); } else lprcat("\nYou aren't wearing anything"); return; case 'g': cursors(); lprintf("\nThe stuff you are carrying presently weighs %ld pounds", (long) packweight()); case ' ': yrepcount = 0; nomove = 1; return; case 'v': yrepcount = 0; cursors(); lprintf("\nCaverns of Larn, Version %ld.%ld, Diff=%ld", (long) VERSION, (long) SUBVERSION, (long) c[HARDGAME]); if (wizard) lprcat(" Wizard"); nomove = 1; if (cheat) lprcat(" Cheater"); lprcat(copyright); return; case 'Q': yrepcount = 0; quit(); nomove = 1; return; /* quit */ case 'L' - 64: yrepcount = 0; drawscreen(); nomove = 1; return; /* look */ #if WIZID #ifdef EXTRA case 'A': yrepcount = 0; nomove = 1; if (wizard) { diag(); return; } /* create diagnostic file */ return; #endif #endif case 'P': cursors(); if (outstanding_taxes > 0) lprintf("\nYou presently owe %ld gp in taxes.", (long) outstanding_taxes); else lprcat("\nYou do not owe any taxes."); return; }; } }