command6.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* $NetBSD: command6.c,v 1.2 2003/08/07 09:37:01 agc Exp $ */
  2. /*
  3. * Copyright (c) 1983, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the University nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #include <sys/cdefs.h>
  31. #ifndef lint
  32. #if 0
  33. static char sccsid[] = "@(#)com6.c 8.2 (Berkeley) 4/28/95";
  34. #else
  35. __RCSID("$NetBSD: command6.c,v 1.2 2003/08/07 09:37:01 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include "extern.h"
  39. #include "pathnames.h"
  40. int
  41. launch()
  42. {
  43. if (testbit(location[position].objects, VIPER) && !notes[CANTLAUNCH]) {
  44. if (fuel > 4) {
  45. clearbit(location[position].objects, VIPER);
  46. position = location[position].up;
  47. notes[LAUNCHED] = 1;
  48. ourtime++;
  49. fuel -= 4;
  50. puts("You climb into the viper and prepare for launch.");
  51. puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat.");
  52. return (1);
  53. } else
  54. puts("Not enough fuel to launch.");
  55. } else
  56. puts("Can't launch.");
  57. return (0);
  58. }
  59. int
  60. land()
  61. {
  62. if (notes[LAUNCHED] && testbit(location[position].objects, LAND) &&
  63. location[position].down) {
  64. notes[LAUNCHED] = 0;
  65. position = location[position].down;
  66. setbit(location[position].objects, VIPER);
  67. fuel -= 2;
  68. ourtime++;
  69. puts("You are down.");
  70. return (1);
  71. } else
  72. puts("You can't land here.");
  73. return (0);
  74. }
  75. void
  76. die()
  77. { /* endgame */
  78. printf("bye.\nYour rating was %s.\n", rate());
  79. post(' ');
  80. exit(0);
  81. }
  82. void
  83. diesig(dummy)
  84. int dummy __attribute__((__unused__));
  85. {
  86. die();
  87. }
  88. void
  89. live()
  90. {
  91. puts("\nYou win!");
  92. post('!');
  93. exit(0);
  94. }
  95. static FILE *score_fp;
  96. void
  97. open_score_file()
  98. {
  99. score_fp = fopen(_PATH_SCORE, "a");
  100. if (score_fp == NULL && getenv("BATTLESTAR_QUIET") == NULL)
  101. warn("open %s for append", _PATH_SCORE);
  102. if (score_fp != NULL && fileno(score_fp) < 3)
  103. exit(1);
  104. }
  105. void
  106. post(ch)
  107. char ch;
  108. {
  109. time_t tv;
  110. char *date;
  111. sigset_t sigset, osigset;
  112. sigemptyset(&sigset);
  113. sigaddset(&sigset, SIGINT);
  114. sigprocmask(SIG_BLOCK, &sigset, &osigset);
  115. tv = time(NULL);
  116. date = ctime(&tv);
  117. date[24] = '\0';
  118. if (score_fp != NULL) {
  119. fprintf(score_fp, "%s %8s %c%20s", date, username, ch, rate());
  120. if (wiz)
  121. fprintf(score_fp, " wizard\n");
  122. else
  123. if (tempwiz)
  124. fprintf(score_fp, " WIZARD!\n");
  125. else
  126. fprintf(score_fp, "\n");
  127. }
  128. sigprocmask(SIG_SETMASK, &osigset, (sigset_t *) 0);
  129. }
  130. const char *
  131. rate()
  132. {
  133. int score;
  134. score = max(max(pleasure, power), ego);
  135. if (score == pleasure) {
  136. if (score < 5)
  137. return ("novice");
  138. else if (score < 20)
  139. return ("junior voyeur");
  140. else if (score < 35)
  141. return ("Don Juan");
  142. else
  143. return ("Marquis De Sade");
  144. } else if (score == power) {
  145. if (score < 5)
  146. return ("serf");
  147. else if (score < 8)
  148. return ("Samurai");
  149. else if (score < 13)
  150. return ("Klingon");
  151. else if (score < 22)
  152. return ("Darth Vader");
  153. else
  154. return ("Sauron the Great");
  155. } else {
  156. if (score < 5)
  157. return ("Polyanna");
  158. else if (score < 10)
  159. return ("philanthropist");
  160. else if (score < 20)
  161. return ("Tattoo");
  162. else
  163. return ("Mr. Roarke");
  164. }
  165. }
  166. int
  167. drive()
  168. {
  169. if (testbit(location[position].objects, CAR)) {
  170. puts("You hop in the car and turn the key. There is a perceptible grating noise,");
  171. puts("and an explosion knocks you unconscious...");
  172. clearbit(location[position].objects, CAR);
  173. setbit(location[position].objects, CRASH);
  174. injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
  175. ourtime += 15;
  176. zzz();
  177. return (0);
  178. } else
  179. puts("There is nothing to drive here.");
  180. return (-1);
  181. }
  182. int
  183. ride()
  184. {
  185. if (testbit(location[position].objects, HORSE)) {
  186. puts("You climb onto the stallion and kick it in the guts. The stupid steed launches");
  187. puts("forward through bush and fern. You are thrown and the horse gallops off.");
  188. clearbit(location[position].objects, HORSE);
  189. while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere)
  190. continue;
  191. setbit(location[position].objects, HORSE);
  192. if (location[position].north)
  193. position = location[position].north;
  194. else if (location[position].south)
  195. position = location[position].south;
  196. else if (location[position].east)
  197. position = location[position].east;
  198. else
  199. position = location[position].west;
  200. return (0);
  201. } else
  202. puts("There is no horse here.");
  203. return (-1);
  204. }
  205. void
  206. light()
  207. { /* synonyms = {strike, smoke} *//* for
  208. * matches, cigars */
  209. if (testbit(inven, MATCHES) && matchcount) {
  210. puts("Your match splutters to life.");
  211. ourtime++;
  212. matchlight = 1;
  213. matchcount--;
  214. if (position == 217) {
  215. puts("The whole bungalow explodes with an intense blast.");
  216. die();
  217. }
  218. } else
  219. puts("You're out of matches.");
  220. }
  221. void
  222. dooropen()
  223. { /* synonyms = {open, unlock} */
  224. wordnumber++;
  225. if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS
  226. && wordvalue[wordnumber] == DOOR) {
  227. switch(position) {
  228. case 189:
  229. case 231:
  230. if (location[189].north == 231)
  231. puts("The door is already open.");
  232. else
  233. puts("The door does not budge.");
  234. break;
  235. case 30:
  236. if (location[30].west == 25)
  237. puts("The door is gone.");
  238. else
  239. puts("The door is locked tight.");
  240. break;
  241. case 31:
  242. puts("That's one immovable door.");
  243. break;
  244. case 20:
  245. puts("The door is already ajar.");
  246. break;
  247. default:
  248. puts("What door?");
  249. }
  250. } else
  251. puts("That doesn't open.");
  252. }