/* Re-coding of advent in C: subroutines from main */
static char sccsid
[] = " subr.c 4.1 82/05/11 ";
/* Statement functions */
{ if (place
[objj
] == -1) return(TRUE
);
{ if (place
[objj
]==loc
|| toting(objj
)) return(TRUE
);
{ if (place
[objj
]==loc
|| fixed
[objj
]==loc
) return(TRUE
);
{ return((1-pbotl
)*water
+(pbotl
/2)*(water
+oil
));
if (i
>-1-i
) return(liq2(i
));
liqloc(locc
) /* may want to clean this one up a bit */
{ if (cond
[l
] & setbit
[n
]) return(TRUE
);
{ if (cond
[locc
]==2) return(TRUE
);
{ if ((cond
[loc
]%2)==0 && (prop
[lamp
]==0 || !here(lamp
)))
{ if (ran(100)<n
) return(TRUE
);
register struct travlist
*kk
;
if (newloc
!=loc
&&!forced(loc
)&&!bitset(loc
,3))
{ if (odloc
[i
]!=newloc
||!dseen
[i
]) continue;
if (loc
==0||forced(loc
)||bitset(newloc
,3)) return(2000);
{ if (loc
<15||pct(95)) return(2000);
if (pct(50)&&saved
== -1) dloc
[j
]=0; /* 6001 */
{ if (dloc
[i
]==loc
) dloc
[i
]=daltlc
;
odloc
[i
]=dloc
[i
]; /* 6002 */
dtotal
=attack
=stick
=0; /* 6010 */
for (i
=1; i
<=6; i
++) /* loop to 6030 */
{ if (dloc
[i
]==0) continue;
for (kk
=travel
[dloc
[i
]]; kk
!=0; kk
=kk
->next
)
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
]=odloc
[i
]; /* 6016 */
dseen
[i
]=(dseen
[i
]&&loc
>=15)||(dloc
[i
]==loc
||odloc
[i
]==loc
);
if (!dseen
[i
]) continue; /* i.e. goto 6030 */
if (i
==6) /* pirate's spotted him */
{ if (loc
==chloc
||prop
[chest
]>=0) continue;
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
;
if (tally
==tally2
+1 && k
==0 && place
[chest
]==0
&&here(lamp
) && prop
[lamp
]==1) goto l6025
;
if (odloc
[6]!=dloc
[6]&&pct(20))
if (place
[messag
]==0) move(chest
,chloc
);
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
;
if (odloc
[i
]!=dloc
[i
]) continue;
if (knfloc
>=0) knfloc
=loc
;
if (ran(1000)<95*(dflag
-2)) stick
++;
if (dtotal
==0) return(2000);
{ printf("There are %d threatening little dwarves ",dtotal
);
printf("in the room with you.\n");
if (attack
==0) return(2000);
if (saved
!= -1) dflag
=20;
{ printf("%d of them throw knives at you!\n",attack
);
l82
: if (stick
<=1) /* 82 */
if (stick
==0) return(2000);
printf("%d of them get you!\n",stick
); /* 83 */
if ((tkk
=travel
[newloc
=loc
])==0) bug(26);
{ if (detail
++<3) rspeak(15);
for (; tkk
!=0; tkk
=tkk
->next
)
if (tkk
->tverb
==1 || tkk
->tverb
==k
) break;
l11
: ll1
=tkk
->conditions
; /* 11 */
newloc
=ll1
; /* newloc=conditions */
k
=newloc
%100; /* k used for prob */
{ if (newloc
<=100) /* 13 */
{ if (newloc
!=0&&!pct(newloc
)) goto l12
; /* 14 */
l16
: newloc
=ll2
; /* newloc=location */
if (newloc
<=300) return(2);
switch(specials())/* to 30000 */
if (toting(k
)||(newloc
>200&&at(k
))) goto l16
;
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;
{ register struct travlist
*tk2
,*j
;
if (forced(k
=oldloc
)) k
=oldlc2
; /* k=location */
for (; tkk
!=0; tkk
=tkk
->next
) /* 21 */
{ k
=tkk
->tverb
; /* k back to verb */
if (forced(ll
) && k
==j
->tloc
) tk2
=tkk
;
if (holdng
==0||(holdng
==1&&toting(emrald
))) return(2);
move(troll
+100,fixd
[troll
]);
newloc
=plac
[troll
]+fixd
[troll
]-loc
; /* 30310 */
if (prop
[troll
]==0) prop
[troll
]=1;
if (!toting(bear
)) return(2);
if (prop
[spices
]<0) tally2
++;
if (k
>=43 && k
<=50) 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;
{ printf("Please tell jim@rand-unix that fatal bug %d happened.\n",n
);
checkhints() /* 2600 &c */
for (hint
=4; hint
<=hntmax
; hint
++)
{ if (hinted
[hint
]) continue;
if (!bitset(loc
,hint
)) hintlc
[hint
]= -1;
if (hintlc
[hint
]<hints
[hint
][1]) continue;
if (prop
[grate
]==0&&!here(keys
)) goto l40010
;
if (here(bird
)&&toting(rod
)&&obj
==bird
) goto l40010
;
continue; /* i.e. goto l40030 */
if (here(snake
)&&!here(bird
)) goto l40010
;
if (atloc
[loc
]==0&&atloc
[oldloc
]==0
&& atloc
[oldlc2
]==0&&holdng
>1) goto l40010
;
if (prop
[emrald
]!= -1&&prop
[pyram
]== -1) goto l40010
;
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);
if (*wd2
!=0) copystr(wd2
,wd1
);
if (i
==62||i
==65||i
==71||i
==2025)
printf("\nOkay, \"%s\".\n",wd2
);
if (toting(obj
)) return(2011); /* 9010 */
if (obj
==plant
&&prop
[plant
]<=0) spk
=115;
if (obj
==bear
&&prop
[bear
]==1) spk
=169;
if (obj
==chain
&&prop
[bear
]!=0) spk
=170;
if (fixed
[obj
]!=0) return(2011);
if (obj
==water
||obj
==oil
)
{ if (here(bottle
)&&liq(0)==obj
)
if (toting(bottle
)&&prop
[bottle
]==1)
if (prop
[bottle
]!=1) spk
=105;
if (!toting(bottle
)) spk
=104;
{ if (prop
[bird
]!=0) goto l9014
;
if (!toting(cage
)) /* 9013 */
l9014
: if ((obj
==bird
||obj
==cage
)&&prop
[bird
]!=0)
carry(bird
+cage
-obj
,loc
);
if (obj
==bottle
&& k
!=0) place
[k
] = -1;
if (obj
==bottle
&&k
!=0) place
[k
]=0;
if (obj
==cage
&&prop
[bird
]!=0) drop(bird
,loc
);
if (obj
==bird
) prop
[bird
]=0;
if (toting(rod2
)&&obj
==rod
&&!toting(rod
)) obj
=rod2
;
if (!toting(obj
)) return(2011);
if (obj
==bird
&&here(snake
))
if (closed
) return(19000);
if (obj
==coins
&&here(vend
)) /* 9024 */
if (obj
==bird
&&at(dragon
)&&prop
[dragon
]==0) /* 9025 */
if (place
[snake
]==plac
[snake
]) tally2
--;
if (obj
==bear
&&at(troll
)) /* 9026 */
move(troll2
,plac
[troll
]);
move(troll2
+100,fixd
[troll
]);
if (obj
!=vase
||loc
==plac
[pillow
]) /* 9027 */
if (at(pillow
)) prop
[vase
]=0;
pspeak(vase
,prop
[vase
]+1);
if (prop
[vase
]!=0) fixed
[vase
] = -1;
{ if (obj
==clam
||obj
==oyster
)
if (toting(obj
)) spk
=120+k
;
if (!toting(tridnt
)) spk
=122+k
;
if (spk
!=124) return(2011);
if (obj
==door
&&prop
[door
]==1) spk
=54;
if (obj
==grate
||obj
==chain
) spk
=31;
if (spk
!=31||!here(keys
)) return(2011);
{ spk
=172; /* 9049: lock */
if (prop
[chain
]!=0) spk
=34;
if (loc
!=plac
[chain
]) spk
=173;
if (spk
!=172) return(2011);
if (toting(chain
)) drop(chain
,loc
);
if (prop
[bear
]==0) spk
=41;
if (prop
[chain
]==0) spk
=37;
if (spk
!=171) return(2011);
if (prop
[bear
]!=3) prop
[bear
]=2;
fixed
[bear
]=2-prop
[bear
];
k
=34+prop
[grate
]; /* 9043 */
if (verb
==lock
) prop
[grate
]=0;
if (dloc
[i
]==loc
&&dflag
>=2) break;
if (here(snake
)) obj
=obj
*100+snake
;
if (at(dragon
)&&prop
[dragon
]==0) obj
=obj
*100+dragon
;
if (at(troll
)) obj
=obj
*100+troll
;
if (here(bear
)&&prop
[bear
]==0) obj
=obj
*100+bear
;
if (obj
>100) return(8000);
{ if (here(bird
)&&verb
!=throw) obj
=bird
;
if (here(clam
)||here(oyster
)) obj
=100*obj
+clam
;
if (obj
>100) return(8000);
if (obj
==bird
) /* 9124 */
if (closed
) return(2011);
if (place
[snake
]==plac
[snake
]) tally2
++;
if (obj
==0) spk
=44; /* 9125 */
if (obj
==clam
||obj
==oyster
) spk
=150;
if (obj
==dwarf
&&closed
) return(19000);
if (obj
==dragon
) spk
=147;
if (obj
==bear
) spk
=165+(prop
[bear
]+1)/2;
if (obj
!=dragon
||prop
[dragon
]!=0) return(2011);
if (!weq(wd1
,"y")&&!weq(wd1
,"yes")) return(2608);
k
=(plac
[dragon
]+fixd
[dragon
])/2;
for (obj
=1; obj
<=100; obj
++)
if (place
[obj
]==plac
[dragon
]||place
[obj
]==fixd
[dragon
])
trtoss() /* 9170: throw */
if (toting(rod2
)&&obj
==rod
&&!toting(rod
)) obj
=rod2
;
if (!toting(obj
)) return(2011);
if (obj
>=50&&obj
<=maxtrs
&&at(troll
))
drop(troll2
,plac
[troll
]);
drop(troll2
+100,fixd
[troll
]);
if (obj
==food
&&here(bear
))
if (obj
!=axe
) return(9020);
if (ran(3)==0||saved
!= -1)
if (at(dragon
)&&prop
[dragon
]==0)
if (at(troll
)) goto l9175
;
if (here(bear
)&&prop
[bear
]==0)
if (obj
==snake
||obj
==dragon
||obj
==troll
)
if (obj
==dragon
&&prop
[dragon
]!=0) spk
=110;
if (obj
!=snake
||closed
||!here(bird
)) return(2011);
{ if (!here(food
)) return(2011);
{ if (prop
[bear
]==0) spk
=102;
if (prop
[bear
]==3) spk
=110;
if (!here(food
)) return(2011);
if (liqloc(loc
)==0) spk
=144;
if (liqloc(loc
)==0||!toting(vase
)) return(2011);
return(9020); /* advent/10 goes to 9024 */
if (obj
!=0&&obj
!=bottle
) return(2011);
if (obj
==0&&!here(bottle
)) return(8000);
if (liqloc(loc
)==0) spk
=106;
if (spk
!=107) return(2011);
prop
[bottle
]=((cond
[loc
]%4)/2)*2;
if (toting(bottle
)) place
[k
]= -1;
prop
[grate
]=prop
[fissur
]=0;
move(troll2
,plac
[troll
]);
move(troll2
+100,fixd
[troll
]);
if(prop
[bear
]!=3) dstroy(bear
);
prop
[bottle
]=put(bottle
,115,1);
prop
[plant
]=put(plant
,115,0);
prop
[oyster
]=put(oyster
,115,0);
prop
[lamp
]=put(lamp
,115,0);
prop
[rod
]=put(rod
,115,0);
prop
[dwarf
]=put(dwarf
,115,0);
prop
[snake
]=put(snake
,116,1);
prop
[bird
]=put(bird
,116,1);
prop
[cage
]=put(cage
,116,0);
prop
[rod2
]=put(rod2
,116,0);
prop
[pillow
]=put(pillow
,116,0);
prop
[mirror
]=put(mirror
,115,0);
if (toting(i
)) dstroy(i
);