📄 main.c
字号:
show3(index) register int index; { switch(iven[index]) { case OPOTION: show1(index,potionname); break; case OSCROLL: show1(index,scrollname); break; case OLARNEYE: case OBOOK: case OSPIRITSCARAB: case ODIAMOND: case ORUBY: case OCUBEofUNDEAD: case OEMERALD: case OCHEST: case OCOOKIE: case OSAPPHIRE: case ONOTHEFT: show1(index,(char **)0); break; default: lprintf("\n%c) %s",index+'a',objectname[iven[index]]); if (ivenarg[index]>0) lprintf(" + %d",(long)ivenarg[index]); else if (ivenarg[index]<0) lprintf(" %d",(long)ivenarg[index]); break; } if (c[WIELD]==index) lprcat(" (weapon in hand)"); if ((c[WEAR]==index) || (c[SHIELD]==index)) lprcat(" (being worn)"); if (++srcount>=22) { srcount=0; more(); clear(); } }/* subroutine to randomly create monsters if needed */randmonst() { if (c[TIMESTOP]) return; /* don't make monsters if time is stopped */ if (--rmst <= 0) { rmst = 120 - (level<<2); fillmonst(makemonst(level)); } }/* parse() get and execute a command */parse() { register 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("\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 (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; { register 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][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<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 %d pounds",(long)packweight()); case ' ': yrepcount=0; nomove=1; return; case 'v': yrepcount=0; cursors(); lprintf("\nCaverns of Larn, Version %d.%d, Diff=%d",(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 %d gp in taxes.",(long)outstanding_taxes); else lprcat("\nYou do not owe any taxes."); return; }; } }parse2() { if (c[HASTEMONST]) movemonst(); movemonst(); /* move the monsters */ randmonst(); regen(); }run(dir) int dir; { register int i; i=1; while (i) { i=moveplayer(dir); if (i>0) { if (c[HASTEMONST]) movemonst(); movemonst(); randmonst(); regen(); } if (hitflag) i=0; if (i!=0) showcell(playerx,playery); } }/* function to wield a weapon */wield() { register int i; while (1) { if ((i = whatitem("wield"))=='\33') return; if (i != '.') { if (i=='*') showwield(); else if (iven[i-'a']==0) { ydhi(i); return; } else if (iven[i-'a']==OPOTION) { ycwi(i); return; } else if (iven[i-'a']==OSCROLL) { ycwi(i); return; } else if ((c[SHIELD]!= -1) && (iven[i-'a']==O2SWORD)) { lprcat("\nBut one arm is busy with your shield!"); return; } else { c[WIELD]=i-'a'; if (iven[i-'a'] == OLANCE) c[LANCEDEATH]=1; else c[LANCEDEATH]=0; bottomline(); return; } } } }/* common routine to say you don't have an item */ydhi(x) int x; { cursors(); lprintf("\nYou don't have item %c!",x); }ycwi(x) int x; { cursors(); lprintf("\nYou can't wield item %c!",x); }/* function to wear armor */wear() { register int i; while (1) { if ((i = whatitem("wear"))=='\33') return; if (i != '.') { if (i=='*') showwear(); else switch(iven[i-'a']) { case 0: ydhi(i); return; case OLEATHER: case OCHAIN: case OPLATE: case OSTUDLEATHER: case ORING: case OSPLINT: case OPLATEARMOR: case OSSPLATE: if (c[WEAR] != -1) { lprcat("\nYou're already wearing some armor"); return; } c[WEAR]=i-'a'; bottomline(); return; case OSHIELD: if (c[SHIELD] != -1) { lprcat("\nYou are already wearing a shield"); return; } if (iven[c[WIELD]]==O2SWORD) { lprcat("\nYour hands are busy with the two handed sword!"); return; } c[SHIELD] = i-'a'; bottomline(); return; default: lprcat("\nYou can't wear that!"); }; } } }/* function to drop an object */dropobj() { register int i; register char *p; long amt; p = &item[playerx][playery]; while (1) { if ((i = whatitem("drop"))=='\33') return; if (i=='*') showstr(); else { if (i=='.') /* drop some gold */ { if (*p) { lprcat("\nThere's something here already!"); return; } lprcat("\n\n"); cl_dn(1,23); lprcat("How much gold do you drop? "); if ((amt=readnum((long)c[GOLD])) == 0) return; if (amt>c[GOLD]) { lprcat("\nYou don't have that much!"); return; } if (amt<=32767) { *p=OGOLDPILE; i=amt; } else if (amt<=327670L) { *p=ODGOLD; i=amt/10; amt = 10*i; } else if (amt<=3276700L) { *p=OMAXGOLD; i=amt/100; amt = 100*i; } else if (amt<=32767000L) { *p=OKGOLD; i=amt/1000; amt = 1000*i; } else { *p=OKGOLD; i=32767; amt = 32767000L; } c[GOLD] -= amt; lprintf("You drop %d gold pieces",(long)amt); iarg[playerx][playery]=i; bottomgold(); know[playerx][playery]=0; dropflag=1; return; } drop_object(i-'a'); return; } } }/* * readscr() Subroutine to read a scroll one is carrying */readscr() { register int i; while (1) { if ((i = whatitem("read"))=='\33') return; if (i != '.') { if (i=='*') showread(); else { if (iven[i-'a']==OSCROLL) { read_scroll(ivenarg[i-'a']); iven[i-'a']=0; return; } if (iven[i-'a']==OBOOK) { readbook(ivenarg[i-'a']); iven[i-'a']=0; return; } if (iven[i-'a']==0) { ydhi(i); return; } lprcat("\nThere's nothing on it to read"); return; } } } }/* * subroutine to eat a cookie one is carrying */eatcookie(){register int i;char *p;while (1) { if ((i = whatitem("eat"))=='\33') return; if (i != '.') if (i=='*') showeat(); else { if (iven[i-'a']==OCOOKIE) { lprcat("\nThe cookie was delicious."); iven[i-'a']=0; if (!c[BLINDCOUNT]) { if (p=fortune(fortfile)) { lprcat(" Inside you find a scrap of paper that says:\n"); lprcat(p); } } return; } if (iven[i-'a']==0) { ydhi(i); return; } lprcat("\nYou can't eat that!"); return; } }}/* * subroutine to quaff a potion one is carrying */quaff() { register int i; while (1) { if ((i = whatitem("quaff"))=='\33') return; if (i != '.') { if (i=='*') showquaff(); else { if (iven[i-'a']==OPOTION) { quaffpotion(ivenarg[i-'a']); iven[i-'a']=0; return; } if (iven[i-'a']==0) { ydhi(i); return; } lprcat("\nYou wouldn't want to quaff that, would you? "); return; } } } }/* function to ask what player wants to do */whatitem(str) char *str; { int i; cursors(); lprintf("\nWhat do you want to %s [* for all] ? ",str); i=0; while (i>'z' || (i<'a' && i!='*' && i!='\33' && i!='.')) i=getchar(); if (i=='\33') lprcat(" aborted"); return(i); }/* subroutine to get a number from the player and allow * to mean return amt, else return the number entered */unsigned long readnum(mx) long mx; { register int i; register unsigned long amt=0; sncbr(); if ((i=getchar()) == '*') 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 = getchar(); } scbr(); return(amt); }#ifdef HIDEBYLINK/* * routine to zero every byte in a string */szero(str) register char *str; { while (*str) *str++ = 0; }#endif HIDEBYLINK
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -