147851Sbostic /*- 2*59968Sbostic * Copyright (c) 1991, 1993 The Regents of the University of California. 347851Sbostic * All rights reserved. 447851Sbostic * 5*59968Sbostic * The game adventure was originally written in Fortran by Will Crowther 6*59968Sbostic * and Don Woods. It was later translated to C and enhanced by Jim 7*59968Sbostic * Gillogly. This code is derived from software contributed to Berkeley 8*59968Sbostic * by Jim Gillogly at The Rand Corporation. 947851Sbostic * 1047851Sbostic * %sccs.include.redist.c% 1147851Sbostic */ 1247851Sbostic 136735Srrh /* Re-coding of advent in C: data initialization */ 146735Srrh 1537005Sbostic #include <sys/types.h> 1637005Sbostic #include <stdio.h> 1737005Sbostic #include "hdr.h" 186735Srrh 196735Srrh int blklin = TRUE; 206735Srrh 216735Srrh int setbit[16] = {1,2,4,010,020,040,0100,0200,0400,01000,02000,04000, 226735Srrh 010000,020000,040000,0100000}; 236735Srrh 246735Srrh 256735Srrh init(command) /* everything for 1st time run */ 266735Srrh char *command; /* command we were called with */ 27*59968Sbostic { 286735Srrh rdata(); /* read data from orig. file */ 296735Srrh linkdata(); 306735Srrh poof(); 316735Srrh } 326735Srrh 33*59968Sbostic char *decr(a,b,c,d,e) 34*59968Sbostic char a,b,c,d,e; 35*59968Sbostic { 36*59968Sbostic static char buf[6]; 376735Srrh 38*59968Sbostic buf[0] = a-'+'; 39*59968Sbostic buf[1] = b-'-'; 40*59968Sbostic buf[2] = c-'#'; 41*59968Sbostic buf[3] = d-'&'; 42*59968Sbostic buf[4] = e-'%'; 43*59968Sbostic buf[5] = 0; 44*59968Sbostic return buf; 45*59968Sbostic } 46*59968Sbostic 476735Srrh linkdata() /* secondary data manipulation */ 486735Srrh { register int i,j; 49*59968Sbostic 506735Srrh /* array linkages */ 516735Srrh for (i=1; i<=LOCSIZ; i++) 526735Srrh if (ltext[i].seekadr!=0 && travel[i] != 0) 536735Srrh if ((travel[i]->tverb)==1) cond[i]=2; 546735Srrh for (j=100; j>0; j--) 556735Srrh if (fixd[j]>0) 566735Srrh { drop(j+100,fixd[j]); 576735Srrh drop(j,plac[j]); 586735Srrh } 596735Srrh for (j=100; j>0; j--) 606735Srrh { fixed[j]=fixd[j]; 616735Srrh if (plac[j]!=0 && fixd[j]<=0) drop(j,plac[j]); 626735Srrh } 636735Srrh 646735Srrh maxtrs=79; 656735Srrh tally=0; 666735Srrh tally2=0; 676735Srrh 686735Srrh for (i=50; i<=maxtrs; i++) 696735Srrh { if (ptext[i].seekadr!=0) prop[i] = -1; 706735Srrh tally -= prop[i]; 716735Srrh } 726735Srrh 736735Srrh /* define mnemonics */ 74*59968Sbostic keys = vocab(DECR(k,e,y,s,\0), 1); 75*59968Sbostic lamp = vocab(DECR(l,a,m,p,\0), 1); 76*59968Sbostic grate = vocab(DECR(g,r,a,t,e), 1); 77*59968Sbostic cage = vocab(DECR(c,a,g,e,\0),1); 78*59968Sbostic rod = vocab(DECR(r,o,d,\0,\0),1); 796735Srrh rod2=rod+1; 80*59968Sbostic steps=vocab(DECR(s,t,e,p,s),1); 81*59968Sbostic bird = vocab(DECR(b,i,r,d,\0),1); 82*59968Sbostic door = vocab(DECR(d,o,o,r,\0),1); 83*59968Sbostic pillow= vocab(DECR(p,i,l,l,o), 1); 84*59968Sbostic snake = vocab(DECR(s,n,a,k,e), 1); 85*59968Sbostic fissur= vocab(DECR(f,i,s,s,u), 1); 86*59968Sbostic tablet= vocab(DECR(t,a,b,l,e), 1); 87*59968Sbostic clam = vocab(DECR(c,l,a,m,\0),1); 88*59968Sbostic oyster= vocab(DECR(o,y,s,t,e), 1); 89*59968Sbostic magzin= vocab(DECR(m,a,g,a,z), 1); 90*59968Sbostic dwarf = vocab(DECR(d,w,a,r,f), 1); 91*59968Sbostic knife = vocab(DECR(k,n,i,f,e), 1); 92*59968Sbostic food = vocab(DECR(f,o,o,d,\0),1); 93*59968Sbostic bottle= vocab(DECR(b,o,t,t,l), 1); 94*59968Sbostic water = vocab(DECR(w,a,t,e,r), 1); 95*59968Sbostic oil = vocab(DECR(o,i,l,\0,\0),1); 96*59968Sbostic plant = vocab(DECR(p,l,a,n,t), 1); 976735Srrh plant2=plant+1; 98*59968Sbostic axe = vocab(DECR(a,x,e,\0,\0),1); 99*59968Sbostic mirror= vocab(DECR(m,i,r,r,o), 1); 100*59968Sbostic dragon= vocab(DECR(d,r,a,g,o), 1); 101*59968Sbostic chasm = vocab(DECR(c,h,a,s,m), 1); 102*59968Sbostic troll = vocab(DECR(t,r,o,l,l), 1); 1036735Srrh troll2=troll+1; 104*59968Sbostic bear = vocab(DECR(b,e,a,r,\0),1); 105*59968Sbostic messag= vocab(DECR(m,e,s,s,a), 1); 106*59968Sbostic vend = vocab(DECR(v,e,n,d,i), 1); 107*59968Sbostic batter= vocab(DECR(b,a,t,t,e), 1); 1086735Srrh 109*59968Sbostic nugget= vocab(DECR(g,o,l,d,\0),1); 110*59968Sbostic coins = vocab(DECR(c,o,i,n,s), 1); 111*59968Sbostic chest = vocab(DECR(c,h,e,s,t), 1); 112*59968Sbostic eggs = vocab(DECR(e,g,g,s,\0),1); 113*59968Sbostic tridnt= vocab(DECR(t,r,i,d,e), 1); 114*59968Sbostic vase = vocab(DECR(v,a,s,e,\0),1); 115*59968Sbostic emrald= vocab(DECR(e,m,e,r,a), 1); 116*59968Sbostic pyram = vocab(DECR(p,y,r,a,m), 1); 117*59968Sbostic pearl = vocab(DECR(p,e,a,r,l), 1); 118*59968Sbostic rug = vocab(DECR(r,u,g,\0,\0),1); 119*59968Sbostic chain = vocab(DECR(c,h,a,i,n), 1); 1206735Srrh 121*59968Sbostic back = vocab(DECR(b,a,c,k,\0),0); 122*59968Sbostic look = vocab(DECR(l,o,o,k,\0),0); 123*59968Sbostic cave = vocab(DECR(c,a,v,e,\0),0); 124*59968Sbostic null = vocab(DECR(n,u,l,l,\0),0); 125*59968Sbostic entrnc= vocab(DECR(e,n,t,r,a), 0); 126*59968Sbostic dprssn= vocab(DECR(d,e,p,r,e), 0); 127*59968Sbostic enter = vocab(DECR(e,n,t,e,r), 0); 1286735Srrh 129*59968Sbostic pour = vocab(DECR(p,o,u,r,\0), 2); 130*59968Sbostic say = vocab(DECR(s,a,y,\0,\0),2); 131*59968Sbostic lock = vocab(DECR(l,o,c,k,\0),2); 132*59968Sbostic throw = vocab(DECR(t,h,r,o,w), 2); 133*59968Sbostic find = vocab(DECR(f,i,n,d,\0),2); 134*59968Sbostic invent= vocab(DECR(i,n,v,e,n), 2); 135*59968Sbostic 1366735Srrh /* initialize dwarves */ 1376735Srrh chloc=114; 1386735Srrh chloc2=140; 1396735Srrh for (i=1; i<=6; i++) 1406735Srrh dseen[i]=FALSE; 1416735Srrh dflag=0; 1426735Srrh dloc[1]=19; 1436735Srrh dloc[2]=27; 1446735Srrh dloc[3]=33; 1456735Srrh dloc[4]=44; 1466735Srrh dloc[5]=64; 1476735Srrh dloc[6]=chloc; 1486735Srrh daltlc=18; 1496735Srrh 1506735Srrh /* random flags & ctrs */ 1516735Srrh turns=0; 1526735Srrh lmwarn=FALSE; 1536735Srrh iwest=0; 1546735Srrh knfloc=0; 1556735Srrh detail=0; 1566735Srrh abbnum=5; 1576735Srrh for (i=0; i<=4; i++) 1586735Srrh if (rtext[2*i+81].seekadr!=0) maxdie=i+1; 1596735Srrh numdie=holdng=dkill=foobar=bonus=0; 1606735Srrh clock1=30; 1616735Srrh clock2=50; 1626735Srrh saved=0; 1636735Srrh closng=panic=closed=scorng=FALSE; 1646735Srrh } 1656735Srrh 1666735Srrh 1676735Srrh 1686735Srrh trapdel() /* come here if he hits a del */ 1696735Srrh { delhit++; /* main checks, treats as QUIT */ 1706735Srrh signal(2,trapdel); /* catch subsequent DELs */ 1716735Srrh } 1726735Srrh 1736735Srrh 1746735Srrh startup() 17537005Sbostic { 17637005Sbostic time_t time(); 17737005Sbostic 1786735Srrh demo=start(0); 17937005Sbostic srand((int)(time((time_t *)NULL))); /* random seed */ 18037005Sbostic /* srand(371); /* non-random seed */ 1816735Srrh hinted[3]=yes(65,1,0); 1826735Srrh newloc=1; 183*59968Sbostic delhit = 0; 1846735Srrh limit=330; 1856735Srrh if (hinted[3]) limit=1000; /* better batteries if instrucs */ 1866735Srrh } 187