📄 subr.c
字号:
#/* Re-coding of advent in C: subroutines from main */static char sccsid[] = " subr.c 4.1 82/05/11 ";# include "hdr.h"/* Statement functions */toting(objj)int objj;{ if (place[objj] == -1) return(TRUE); else return(FALSE);}here(objj)int objj;{ if (place[objj]==loc || toting(objj)) return(TRUE); else return(FALSE);}at(objj)int objj;{ if (place[objj]==loc || fixed[objj]==loc) return(TRUE); else return (FALSE);}liq2(pbotl)int pbotl;{ return((1-pbotl)*water+(pbotl/2)*(water+oil));}liq(foo){ register int i; i=prop[bottle]; if (i>-1-i) return(liq2(i)); else return(liq2(-1-i));}liqloc(locc) /* may want to clean this one up a bit */int locc;{ register int i,j,l; i=cond[locc]/2; j=((i*2)%8)-5; l=cond[locc]/4; l=l%2; return(liq2(j*l+1));}bitset(l,n)int l,n;{ if (cond[l] & setbit[n]) return(TRUE); return(FALSE);}forced(locc)int locc;{ if (cond[locc]==2) return(TRUE); return(FALSE);}dark(foo){ if ((cond[loc]%2)==0 && (prop[lamp]==0 || !here(lamp))) return(TRUE); return(FALSE);}pct(n)int n;{ if (ran(100)<n) return(TRUE); return(FALSE);}fdwarf() /* 71 */{ register int i,j; register struct travlist *kk; if (newloc!=loc&&!forced(loc)&&!bitset(loc,3)) { for (i=1; i<=5; i++) { if (odloc[i]!=newloc||!dseen[i]) continue; newloc=loc; rspeak(2); break; } } loc=newloc; /* 74 */ if (loc==0||forced(loc)||bitset(newloc,3)) return(2000); if (dflag==0) { if (loc>=15) dflag=1; return(2000); } if (dflag==1) /* 6000 */ { if (loc<15||pct(95)) return(2000); dflag=2; for (i=1; i<=2; i++) { j=1+ran(5); if (pct(50)&&saved== -1) dloc[j]=0; /* 6001 */ } for (i=1; i<=5; i++) { if (dloc[i]==loc) dloc[i]=daltlc; odloc[i]=dloc[i]; /* 6002 */ } rspeak(3); drop(axe,loc); return(2000); } dtotal=attack=stick=0; /* 6010 */ for (i=1; i<=6; i++) /* loop to 6030 */ { if (dloc[i]==0) continue; j=1; for (kk=travel[dloc[i]]; kk!=0; kk=kk->next) { newloc=kk->tloc; if (newloc>300||newloc<15||newloc==odloc[i] ||(j>1&&newloc==tk[j-1])||j>=20 ||newloc==dloc[i]||forced(newloc) ||(i==6&&bitset(newloc,3)) ||kk->conditions==100) continue; tk[j++]=newloc; } tk[j]=odloc[i]; /* 6016 */ if (j>=2) j--; j=1+ran(j); odloc[i]=dloc[i]; dloc[i]=tk[j]; dseen[i]=(dseen[i]&&loc>=15)||(dloc[i]==loc||odloc[i]==loc); if (!dseen[i]) continue; /* i.e. goto 6030 */ dloc[i]=loc; if (i==6) /* pirate's spotted him */ { if (loc==chloc||prop[chest]>=0) continue; k=0; for (j=50; j<=maxtrs; j++) /* loop to 6020 */ { if (j==pyram&&(loc==plac[pyram] || loc==plac[emrald])) goto l6020; if (toting(j)) goto l6022; l6020: if (here(j)) k=1; } /* 6020 */ if (tally==tally2+1 && k==0 && place[chest]==0 &&here(lamp) && prop[lamp]==1) goto l6025; if (odloc[6]!=dloc[6]&&pct(20)) rspeak(127); continue; /* to 6030 */ l6022: rspeak(128); if (place[messag]==0) move(chest,chloc); move(messag,chloc2); for (j=50; j<=maxtrs; j++) /* loop to 6023 */ { if (j==pyram && (loc==plac[pyram] || loc==plac[emrald])) continue; if (at(j)&&fixed[j]==0) carry(j,loc); if (toting(j)) drop(j,chloc); } l6024: dloc[6]=odloc[6]=chloc; dseen[6]=FALSE; continue; l6025: rspeak(186); move(chest,chloc); move(messag,chloc2); goto l6024; } dtotal++; /* 6027 */ if (odloc[i]!=dloc[i]) continue; attack++; if (knfloc>=0) knfloc=loc; if (ran(1000)<95*(dflag-2)) stick++; } /* 6030 */ if (dtotal==0) return(2000); if (dtotal!=1) { printf("There are %d threatening little dwarves ",dtotal); printf("in the room with you.\n"); } else rspeak(4); if (attack==0) return(2000); if (dflag==2) dflag=3; if (saved!= -1) dflag=20; if (attack!=1) { printf("%d of them throw knives at you!\n",attack); k=6; l82: if (stick<=1) /* 82 */ { rspeak(k+stick); if (stick==0) return(2000); } else printf("%d of them get you!\n",stick); /* 83 */ oldlc2=loc; return(99); } rspeak(5); k=52; goto l82;}march() /* label 8 */{ register int ll1,ll2; if ((tkk=travel[newloc=loc])==0) bug(26); if (k==null) return(2); if (k==cave) /* 40 */ { if (loc<8) rspeak(57); if (loc>=8) rspeak(58); return(2); } if (k==look) /* 30 */ { if (detail++<3) rspeak(15); wzdark=FALSE; abb[loc]=0; return(2); } if (k==back) /* 20 */ { switch(mback()) { case 2: return(2); case 9: goto l9; default: bug(100); } } oldlc2=oldloc; oldloc=loc;l9: for (; tkk!=0; tkk=tkk->next) if (tkk->tverb==1 || tkk->tverb==k) break; if (tkk==0) { badmove(); return(2); }l11: ll1=tkk->conditions; /* 11 */ ll2=tkk->tloc; newloc=ll1; /* newloc=conditions */ k=newloc%100; /* k used for prob */ if (newloc<=300) { if (newloc<=100) /* 13 */ { if (newloc!=0&&!pct(newloc)) goto l12; /* 14 */ l16: newloc=ll2; /* newloc=location */ if (newloc<=300) return(2); if (newloc<=500) switch(specials())/* to 30000 */ { case 2: return(2); case 12: goto l12; case 99: return(99); default: bug(101); } rspeak(newloc-500); newloc=loc; return(2); } if (toting(k)||(newloc>200&&at(k))) goto l16; goto l12; } if (prop[k]!=(newloc/100)-3) goto l16; /* newloc still conditions*/l12: /* alternative to probability move */ for (; tkk!=0; tkk=tkk->next) if (tkk->tloc!=ll2 || tkk->conditions!=ll1) break; if (tkk==0) bug(25); goto l11;}mback() /* 20 */{ register struct travlist *tk2,*j; register int ll; if (forced(k=oldloc)) k=oldlc2; /* k=location */ oldlc2=oldloc; oldloc=loc; tk2=0; if (k==loc) { rspeak(91); return(2); } for (; tkk!=0; tkk=tkk->next) /* 21 */ { ll=tkk->tloc; if (ll==k) { k=tkk->tverb; /* k back to verb */ tkk=travel[loc]; return(9); } if (ll<=300) { j=travel[loc]; if (forced(ll) && k==j->tloc) tk2=tkk; } } tkk=tk2; /* 23 */ if (tkk!=0) { k=tkk->tverb; tkk=travel[loc]; return(9); } rspeak(140); return(2);}specials() /* 30000 */{ switch(newloc -= 300) { case 1: /* 30100 */ newloc = 99+100-loc; if (holdng==0||(holdng==1&&toting(emrald))) return(2); newloc=loc; rspeak(117); return(2); case 2: /* 30200 */ drop(emrald,loc); return(12); case 3: /* to 30300 */ return(trbridge()); default: bug(29); }}trbridge() /* 30300 */{ if (prop[troll]==1) { pspeak(troll,1); prop[troll]=0; move(troll2,0); move(troll2+100,0); move(troll,plac[troll]); move(troll+100,fixd[troll]); juggle(chasm); newloc=loc; return(2); } newloc=plac[troll]+fixd[troll]-loc; /* 30310 */ if (prop[troll]==0) prop[troll]=1; if (!toting(bear)) return(2); rspeak(162); prop[chasm]=1; prop[troll]=2; drop(bear,newloc); fixed[bear] = -1; prop[bear]=3; if (prop[spices]<0) tally2++; oldlc2=newloc; return(99);}badmove() /* 20 */{ spk=12; if (k>=43 && k<=50) spk=9; if (k==29||k==30) spk=9; if (k==7||k==36||k==37) spk=10; if (k==11||k==19) spk=11; if (verb==find||verb==invent) spk=59; if (k==62||k==65) spk=42; if (k==17) spk=80; rspeak(spk); return(2);}bug(n)int n;{ printf("Please tell jim@rand-unix that fatal bug %d happened.\n",n); exit(0);}checkhints() /* 2600 &c */{ register int hint; for (hint=4; hint<=hntmax; hint++) { if (hinted[hint]) continue; if (!bitset(loc,hint)) hintlc[hint]= -1; hintlc[hint]++; if (hintlc[hint]<hints[hint][1]) continue; switch(hint) { case 4: /* 40400 */ if (prop[grate]==0&&!here(keys)) goto l40010; goto l40020; case 5: /* 40500 */ if (here(bird)&&toting(rod)&&obj==bird) goto l40010; continue; /* i.e. goto l40030 */ case 6: /* 40600 */ if (here(snake)&&!here(bird)) goto l40010; goto l40020; case 7: /* 40700 */ if (atloc[loc]==0&&atloc[oldloc]==0 && atloc[oldlc2]==0&&holdng>1) goto l40010; goto l40020; case 8: /* 40800 */ if (prop[emrald]!= -1&&prop[pyram]== -1) goto l40010; goto l40020; case 9: goto l40010; /* 40900 */ default: bug(27); } l40010: hintlc[hint]=0; if (!yes(hints[hint][3],0,54)) continue; printf("I am prepared to give you a hint, but it will "); printf("cost you %d points.\n",hints[hint][2]); hinted[hint]=yes(175,hints[hint][4],54); l40020: hintlc[hint]=0; }}trsay() /* 9030 */{ register int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -