1*47851Sbostic /*- 2*47851Sbostic * Copyright (c) 1991 The Regents of the University of California. 3*47851Sbostic * All rights reserved. 4*47851Sbostic * 5*47851Sbostic * The game adventure was original written Fortran by Will Crowther 6*47851Sbostic * and Don Woods. It was later translated to C and enhanced by 7*47851Sbostic * Jim Gillogly. 8*47851Sbostic * 9*47851Sbostic * %sccs.include.redist.c% 10*47851Sbostic */ 11*47851Sbostic 12*47851Sbostic #ifndef lint 13*47851Sbostic static char sccsid[] = "@(#)init.c 5.1 (Berkeley) 04/08/91"; 14*47851Sbostic #endif /* not lint */ 15*47851Sbostic 166735Srrh /* Re-coding of advent in C: data initialization */ 176735Srrh 1837005Sbostic #include <sys/types.h> 1937005Sbostic #include <stdio.h> 2037005Sbostic #include "hdr.h" 2137005Sbostic #include "pathnames.h" 226735Srrh 236735Srrh int blklin = TRUE; 246735Srrh int setup = 0; 256735Srrh 266735Srrh int setbit[16] = {1,2,4,010,020,040,0100,0200,0400,01000,02000,04000, 276735Srrh 010000,020000,040000,0100000}; 286735Srrh 296735Srrh 306735Srrh init(command) /* everything for 1st time run */ 316735Srrh char *command; /* command we were called with */ 326735Srrh { int stat,adfd; 336735Srrh rdata(); /* read data from orig. file */ 346735Srrh linkdata(); 356735Srrh poof(); 366735Srrh setup=1; /* indicate that data is in */ 3737005Sbostic if (save(command, "adventure") < 0) { 3837005Sbostic fprintf(stderr, "adventure: save failed\n"); 3937005Sbostic exit(1); 406735Srrh } 4137005Sbostic adfd=open("adventure",1); 426735Srrh lseek(adfd,0L,2); 436735Srrh close(datfd); 4437005Sbostic if (vfork() == 0) { 4537005Sbostic dup2(adfd, 1); 4637005Sbostic execl(_PATH_CAT, "cat", TMPFILE, 0); 4737005Sbostic fprintf(stderr, "adventure: unable to find %s\n", _PATH_CAT); 4837005Sbostic exit(1); 496735Srrh } 506735Srrh wait(&stat); 516735Srrh unlink(TMPFILE); 5237005Sbostic exit(stat); 536735Srrh } 546735Srrh 556735Srrh 566735Srrh linkdata() /* secondary data manipulation */ 576735Srrh { register int i,j; 586735Srrh /* array linkages */ 596735Srrh for (i=1; i<=LOCSIZ; i++) 606735Srrh if (ltext[i].seekadr!=0 && travel[i] != 0) 616735Srrh if ((travel[i]->tverb)==1) cond[i]=2; 626735Srrh for (j=100; j>0; j--) 636735Srrh if (fixd[j]>0) 646735Srrh { drop(j+100,fixd[j]); 656735Srrh drop(j,plac[j]); 666735Srrh } 676735Srrh for (j=100; j>0; j--) 686735Srrh { fixed[j]=fixd[j]; 696735Srrh if (plac[j]!=0 && fixd[j]<=0) drop(j,plac[j]); 706735Srrh } 716735Srrh 726735Srrh maxtrs=79; 736735Srrh tally=0; 746735Srrh tally2=0; 756735Srrh 766735Srrh for (i=50; i<=maxtrs; i++) 776735Srrh { if (ptext[i].seekadr!=0) prop[i] = -1; 786735Srrh tally -= prop[i]; 796735Srrh } 806735Srrh 816735Srrh /* define mnemonics */ 826735Srrh keys=vocab("keys",1); 836735Srrh lamp=vocab("lamp",1); 846735Srrh grate=vocab("grate",1); 856735Srrh cage=vocab("cage",1); 866735Srrh rod=vocab("rod",1); 876735Srrh rod2=rod+1; 886735Srrh steps=vocab("steps",1); 896735Srrh bird=vocab("bird",1); 906735Srrh door=vocab("door",1); 916735Srrh pillow=vocab("pillow",1); 926735Srrh snake=vocab("snake",1); 936735Srrh fissur=vocab("fissu",1); 946735Srrh tablet=vocab("table",1); 956735Srrh clam=vocab("clam",1); 966735Srrh oyster=vocab("oyster",1); 976735Srrh magzin=vocab("magaz",1); 986735Srrh dwarf=vocab("dwarf",1); 996735Srrh knife=vocab("knife",1); 1006735Srrh food=vocab("food",1); 1016735Srrh bottle=vocab("bottl",1); 1026735Srrh water=vocab("water",1); 1036735Srrh oil=vocab("oil",1); 1046735Srrh plant=vocab("plant",1); 1056735Srrh plant2=plant+1; 1066735Srrh axe=vocab("axe",1); 1076735Srrh mirror=vocab("mirro",1); 1086735Srrh dragon=vocab("drago",1); 1096735Srrh chasm=vocab("chasm",1); 1106735Srrh troll=vocab("troll",1); 1116735Srrh troll2=troll+1; 1126735Srrh bear=vocab("bear",1); 1136735Srrh messag=vocab("messa",1); 1146735Srrh vend=vocab("vendi",1); 1156735Srrh batter=vocab("batte",1); 1166735Srrh 1176735Srrh nugget=vocab("gold",1); 1186735Srrh coins=vocab("coins",1); 1196735Srrh chest=vocab("chest",1); 1206735Srrh eggs=vocab("eggs",1); 1216735Srrh tridnt=vocab("tride",1); 1226735Srrh vase=vocab("vase",1); 1236735Srrh emrald=vocab("emera",1); 1246735Srrh pyram=vocab("pyram",1); 1256735Srrh pearl=vocab("pearl",1); 1266735Srrh rug=vocab("rug",1); 1276735Srrh chain=vocab("chain",1); 1286735Srrh 1296735Srrh back=vocab("back",0); 1306735Srrh look=vocab("look",0); 1316735Srrh cave=vocab("cave",0); 1326735Srrh null=vocab("null",0); 1336735Srrh entrnc=vocab("entra",0); 1346735Srrh dprssn=vocab("depre",0); 1356735Srrh 1366735Srrh say=vocab("say",2); 1376735Srrh lock=vocab("lock",2); 1386735Srrh throw=vocab("throw",2); 1396735Srrh find=vocab("find",2); 1406735Srrh invent=vocab("inven",2); 1416735Srrh /* initialize dwarves */ 1426735Srrh chloc=114; 1436735Srrh chloc2=140; 1446735Srrh for (i=1; i<=6; i++) 1456735Srrh dseen[i]=FALSE; 1466735Srrh dflag=0; 1476735Srrh dloc[1]=19; 1486735Srrh dloc[2]=27; 1496735Srrh dloc[3]=33; 1506735Srrh dloc[4]=44; 1516735Srrh dloc[5]=64; 1526735Srrh dloc[6]=chloc; 1536735Srrh daltlc=18; 1546735Srrh 1556735Srrh /* random flags & ctrs */ 1566735Srrh turns=0; 1576735Srrh lmwarn=FALSE; 1586735Srrh iwest=0; 1596735Srrh knfloc=0; 1606735Srrh detail=0; 1616735Srrh abbnum=5; 1626735Srrh for (i=0; i<=4; i++) 1636735Srrh if (rtext[2*i+81].seekadr!=0) maxdie=i+1; 1646735Srrh numdie=holdng=dkill=foobar=bonus=0; 1656735Srrh clock1=30; 1666735Srrh clock2=50; 1676735Srrh saved=0; 1686735Srrh closng=panic=closed=scorng=FALSE; 1696735Srrh } 1706735Srrh 1716735Srrh 1726735Srrh 1736735Srrh trapdel() /* come here if he hits a del */ 1746735Srrh { delhit++; /* main checks, treats as QUIT */ 1756735Srrh signal(2,trapdel); /* catch subsequent DELs */ 1766735Srrh } 1776735Srrh 1786735Srrh 1796735Srrh startup() 18037005Sbostic { 18137005Sbostic time_t time(); 18237005Sbostic 1836735Srrh demo=start(0); 18437005Sbostic srand((int)(time((time_t *)NULL))); /* random seed */ 18537005Sbostic /* srand(371); /* non-random seed */ 1866735Srrh hinted[3]=yes(65,1,0); 1876735Srrh newloc=1; 1886735Srrh setup=3; 1896735Srrh limit=330; 1906735Srrh if (hinted[3]) limit=1000; /* better batteries if instrucs */ 1916735Srrh } 1926735Srrh 193