done.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* $NetBSD: done.c,v 1.8 2003/08/07 09:36:50 agc Exp $ */
  2. /*-
  3. * Copyright (c) 1991, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * The game adventure was originally written in Fortran by Will Crowther
  7. * and Don Woods. It was later translated to C and enhanced by Jim
  8. * Gillogly. This code is derived from software contributed to Berkeley
  9. * by Jim Gillogly at The Rand Corporation.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the University nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. */
  35. #include <sys/cdefs.h>
  36. #ifndef lint
  37. #if 0
  38. static char sccsid[] = "@(#)done.c 8.1 (Berkeley) 5/31/93";
  39. #else
  40. __RCSID("$NetBSD: done.c,v 1.8 2003/08/07 09:36:50 agc Exp $");
  41. #endif
  42. #endif /* not lint */
  43. /* Re-coding of advent in C: termination routines */
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include "hdr.h"
  47. #include "extern.h"
  48. int
  49. score()
  50. { /* sort of like 20000 */
  51. int scor, i;
  52. mxscor = scor = 0;
  53. for (i = 50; i <= maxtrs; i++) {
  54. if (ptext[i].txtlen == 0)
  55. continue;
  56. k = 12;
  57. if (i == chest)
  58. k = 14;
  59. if (i > chest)
  60. k = 16;
  61. if (prop[i] >= 0)
  62. scor += 2;
  63. if (place[i] == 3 && prop[i] == 0)
  64. scor += k - 2;
  65. mxscor += k;
  66. }
  67. scor += (maxdie - numdie) * 10;
  68. mxscor += maxdie * 10;
  69. if (!(scorng || gaveup))
  70. scor += 4;
  71. mxscor += 4;
  72. if (dflag != 0)
  73. scor += 25;
  74. mxscor += 25;
  75. if (closng)
  76. scor += 25;
  77. mxscor += 25;
  78. if (closed) {
  79. if (bonus == 0)
  80. scor += 10;
  81. if (bonus == 135)
  82. scor += 25;
  83. if (bonus == 134)
  84. scor += 30;
  85. if (bonus == 133)
  86. scor += 45;
  87. }
  88. mxscor += 45;
  89. if (place[magzin] == 108)
  90. scor++;
  91. mxscor++;
  92. scor += 2;
  93. mxscor += 2;
  94. for (i = 1; i <= hntmax; i++)
  95. if (hinted[i])
  96. scor -= hints[i][2];
  97. return (scor);
  98. }
  99. void
  100. done(entry) /* entry=1 means goto 13000 */ /* game is over */
  101. int entry; /* entry=2 means goto 20000 */ /* 3=19000 */
  102. {
  103. int i, sc;
  104. if (entry == 1)
  105. mspeak(1);
  106. if (entry == 3)
  107. rspeak(136);
  108. printf("\n\n\nYou scored %d out of a ", (sc = score()));
  109. printf("possible %d using %d turns.\n", mxscor, turns);
  110. for (i = 1; i <= clsses; i++)
  111. if (cval[i] >= sc) {
  112. speak(&ctext[i]);
  113. if (i == clsses - 1) {
  114. printf("To achieve the next higher rating");
  115. printf(" would be a neat trick!\n\n");
  116. printf("Congratulations!!\n");
  117. exit(0);
  118. }
  119. k = cval[i] + 1 - sc;
  120. printf("To achieve the next higher rating, you need");
  121. printf(" %d more point", k);
  122. if (k == 1)
  123. printf(".\n");
  124. else
  125. printf("s.\n");
  126. exit(0);
  127. }
  128. printf("You just went off my scale!!!\n");
  129. exit(0);
  130. }
  131. void
  132. die(entry) /* label 90 */
  133. int entry;
  134. {
  135. int i;
  136. if (entry != 99) {
  137. rspeak(23);
  138. oldlc2 = loc;
  139. }
  140. if (closng) { /* 99 */
  141. rspeak(131);
  142. numdie++;
  143. done(2);
  144. }
  145. yea = yes(81 + numdie * 2, 82 + numdie * 2, 54);
  146. numdie++;
  147. if (numdie == maxdie || !yea)
  148. done(2);
  149. place[water] = 0;
  150. place[oil] = 0;
  151. if (toting(lamp))
  152. prop[lamp] = 0;
  153. for (i = 100; i >= 1; i--) {
  154. if (!toting(i))
  155. continue;
  156. k = oldlc2;
  157. if (i == lamp)
  158. k = 1;
  159. drop(i, k);
  160. }
  161. loc = 3;
  162. oldloc = loc;
  163. }