147851Sbostic /*-
2*60730Sbostic * Copyright (c) 1991, 1993
3*60730Sbostic * The Regents of the University of California. All rights reserved.
447851Sbostic *
559968Sbostic * The game adventure was originally written in Fortran by Will Crowther
659968Sbostic * and Don Woods. It was later translated to C and enhanced by Jim
759968Sbostic * Gillogly. This code is derived from software contributed to Berkeley
859968Sbostic * by Jim Gillogly at The Rand Corporation.
947851Sbostic *
1047851Sbostic * %sccs.include.redist.c%
1147851Sbostic */
126734Srrh
1347851Sbostic #ifndef lint
14*60730Sbostic static char sccsid[] = "@(#)done.c 8.1 (Berkeley) 05/31/93";
1547851Sbostic #endif /* not lint */
166734Srrh
1747851Sbostic /* Re-coding of advent in C: termination routines */
186734Srrh
1947851Sbostic #include "hdr.h"
206734Srrh
score()216734Srrh score() /* sort of like 20000 */
226734Srrh { register int scor,i;
236734Srrh mxscor=scor=0;
246734Srrh for (i=50; i<=maxtrs; i++)
256734Srrh { if (ptext[i].txtlen==0) continue;
266734Srrh k=12;
276734Srrh if (i==chest) k=14;
286734Srrh if (i>chest) k=16;
296734Srrh if (prop[i]>=0) scor += 2;
306734Srrh if (place[i]==3&&prop[i]==0) scor += k-2;
316734Srrh mxscor += k;
326734Srrh }
336734Srrh scor += (maxdie-numdie)*10;
346734Srrh mxscor += maxdie*10;
356734Srrh if (!(scorng||gaveup)) scor += 4;
366734Srrh mxscor += 4;
376734Srrh if (dflag!=0) scor += 25;
386734Srrh mxscor += 25;
396734Srrh if (closng) scor += 25;
406734Srrh mxscor += 25;
416734Srrh if (closed)
426734Srrh { if (bonus==0) scor += 10;
436734Srrh if (bonus==135) scor += 25;
446734Srrh if (bonus==134) scor += 30;
456734Srrh if (bonus==133) scor += 45;
466734Srrh }
476734Srrh mxscor += 45;
486734Srrh if (place[magzin]==108) scor++;
496734Srrh mxscor++;
506734Srrh scor += 2;
516734Srrh mxscor += 2;
526734Srrh for (i=1; i<=hntmax; i++)
536734Srrh if (hinted[i]) scor -= hints[i][2];
546734Srrh return(scor);
556734Srrh }
566734Srrh
done(entry)576734Srrh done(entry) /* entry=1 means goto 13000 */ /* game is over */
586734Srrh int entry; /* entry=2 means goto 20000 */ /* 3=19000 */
596734Srrh { register int i,sc;
606734Srrh if (entry==1) mspeak(1);
616734Srrh if (entry==3) rspeak(136);
626734Srrh printf("\n\n\nYou scored %d out of a ",(sc=score()));
636734Srrh printf("possible %d using %d turns.\n",mxscor,turns);
646734Srrh for (i=1; i<=clsses; i++)
656734Srrh if (cval[i]>=sc)
666734Srrh { speak(&ctext[i]);
676734Srrh if (i==clsses-1)
686734Srrh { printf("To achieve the next higher rating");
696734Srrh printf(" would be a neat trick!\n\n");
706734Srrh printf("Congratulations!!\n");
716734Srrh exit(0);
726734Srrh }
736734Srrh k=cval[i]+1-sc;
746734Srrh printf("To achieve the next higher rating, you need");
756734Srrh printf(" %d more point",k);
766734Srrh if (k==1) printf(".\n");
776734Srrh else printf("s.\n");
786734Srrh exit(0);
796734Srrh }
806734Srrh printf("You just went off my scale!!!\n");
816734Srrh exit(0);
826734Srrh }
836734Srrh
846734Srrh
die(entry)856734Srrh die(entry) /* label 90 */
866734Srrh int entry;
876734Srrh { register int i;
886734Srrh if (entry != 99)
896734Srrh { rspeak(23);
906734Srrh oldlc2=loc;
916734Srrh }
926734Srrh if (closng) /* 99 */
936734Srrh { rspeak(131);
946734Srrh numdie++;
956734Srrh done(2);
966734Srrh }
976734Srrh yea=yes(81+numdie*2,82+numdie*2,54);
986734Srrh numdie++;
996734Srrh if (numdie==maxdie || !yea) done(2);
1006734Srrh place[water]=0;
1016734Srrh place[oil]=0;
1026734Srrh if (toting(lamp)) prop[lamp]=0;
1036734Srrh for (i=100; i>=1; i--)
1046734Srrh { if (!toting(i)) continue;
1056734Srrh k=oldlc2;
1066734Srrh if (i==lamp) k=1;
1076734Srrh drop(i,k);
1086734Srrh }
1096734Srrh loc=3;
1106734Srrh oldloc=loc;
1116734Srrh return(2000);
1126734Srrh }
113