command1.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* $NetBSD: command1.c,v 1.2 2003/08/07 09:37:00 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[] = "@(#)com1.c 8.2 (Berkeley) 4/28/95";
  34. #else
  35. __RCSID("$NetBSD: command1.c,v 1.2 2003/08/07 09:37:00 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include "extern.h"
  39. int
  40. moveplayer(thataway, token)
  41. int thataway, token;
  42. {
  43. wordnumber++;
  44. if ((!notes[CANTMOVE] && !notes[LAUNCHED]) ||
  45. testbit(location[position].objects, LAND) ||
  46. (fuel > 0 && notes[LAUNCHED])) {
  47. if (thataway) {
  48. position = thataway;
  49. newway(token);
  50. ourtime++;
  51. } else {
  52. puts("You can't go this way.");
  53. newway(token);
  54. whichway(location[position]);
  55. return (0);
  56. }
  57. } else {
  58. if (notes[CANTMOVE] && !notes[LAUNCHED])
  59. puts("You aren't able to move; you better drop something.");
  60. else
  61. puts("You are out of fuel; now you will rot in space forever!");
  62. }
  63. return (1);
  64. }
  65. void
  66. convert(tothis) /* Converts day to night and vice versa. */
  67. int tothis; /* Day objects are permanent. Night objects
  68. * are added */
  69. { /* at dusk, and subtracted at dawn. */
  70. const struct objs *p;
  71. unsigned int i, j;
  72. if (tothis == TONIGHT) {
  73. for (i = 1; i <= NUMOFROOMS; i++)
  74. for (j = 0; j < NUMOFWORDS; j++)
  75. nightfile[i].objects[j] = dayfile[i].objects[j];
  76. for (p = nightobjs; p->room != 0; p++)
  77. setbit(nightfile[p->room].objects, p->obj);
  78. location = nightfile;
  79. } else {
  80. for (i = 1; i <= NUMOFROOMS; i++)
  81. for (j = 0; j < NUMOFWORDS; j++)
  82. dayfile[i].objects[j] = nightfile[i].objects[j];
  83. for (p = nightobjs; p->room != 0; p++)
  84. clearbit(dayfile[p->room].objects, p->obj);
  85. location = dayfile;
  86. }
  87. }
  88. void
  89. news()
  90. {
  91. int n;
  92. int hurt;
  93. if (ourtime > 30 && position < 32) {
  94. puts("An explosion of shuddering magnitude splinters bulkheads and");
  95. puts("ruptures the battlestar's hull. You are sucked out into the");
  96. puts("frozen void of space and killed.");
  97. die();
  98. }
  99. if (ourtime > 20 && position < 32)
  100. puts("Explosions rock the battlestar.");
  101. if (ourtime > snooze) {
  102. puts("You drop from exhaustion...");
  103. zzz();
  104. }
  105. if (ourtime > snooze - 5)
  106. puts("You're getting tired.");
  107. if (ourtime > (rythmn + CYCLE)) {
  108. if (location == nightfile) {
  109. convert(TODAY);
  110. if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
  111. puts("Dew lit sunbeams stretch out from a watery sunrise and herald the dawn.");
  112. puts("You awake from a misty dream-world into stark reality.");
  113. puts("It is day.");
  114. }
  115. } else {
  116. convert(TONIGHT);
  117. clearbit(location[POOLS].objects, BATHGOD);
  118. if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
  119. puts("The dying sun sinks into the ocean, leaving a blood-stained sunset.");
  120. puts("The sky slowly fades from orange to violet to black. A few stars");
  121. puts("flicker on, and it is night.");
  122. puts("The world seems completely different at night.");
  123. }
  124. }
  125. rythmn = ourtime - ourtime % CYCLE;
  126. }
  127. if (!wiz && !tempwiz)
  128. if ((testbit(inven, TALISMAN) || testbit(wear, TALISMAN)) && (testbit(inven, MEDALION) || testbit(wear, MEDALION)) && (testbit(inven, AMULET) || testbit(wear, AMULET))) {
  129. tempwiz = 1;
  130. puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard.");
  131. }
  132. if (testbit(location[position].objects, ELF)) {
  133. printf("%s\n", objdes[ELF]);
  134. fight(ELF, rnd(30));
  135. }
  136. if (testbit(location[position].objects, DARK)) {
  137. printf("%s\n", objdes[DARK]);
  138. fight(DARK, 100);
  139. }
  140. if (testbit(location[position].objects, WOODSMAN)) {
  141. printf("%s\n", objdes[WOODSMAN]);
  142. fight(WOODSMAN, 50);
  143. }
  144. switch (position) {
  145. case 267:
  146. case 257: /* entering a cave */
  147. case 274:
  148. case 246:
  149. notes[CANTSEE] = 1;
  150. break;
  151. case 160:
  152. case 216: /* leaving a cave */
  153. case 230:
  154. case 231:
  155. case 232:
  156. notes[CANTSEE] = 0;
  157. break;
  158. }
  159. if (testbit(location[position].objects, GIRL))
  160. meetgirl = 1;
  161. if (meetgirl && CYCLE * 1.5 - ourtime < 10) {
  162. setbit(location[GARDEN].objects, GIRLTALK);
  163. setbit(location[GARDEN].objects, LAMPON);
  164. setbit(location[GARDEN].objects, ROPE);
  165. }
  166. if (position == DOCK && (beenthere[position] || ourtime > CYCLE)) {
  167. clearbit(location[DOCK].objects, GIRL);
  168. clearbit(location[DOCK].objects, MAN);
  169. }
  170. if (meetgirl && ourtime - CYCLE * 1.5 > 10) {
  171. clearbit(location[GARDEN].objects, GIRLTALK);
  172. clearbit(location[GARDEN].objects, LAMPON);
  173. clearbit(location[GARDEN].objects, ROPE);
  174. meetgirl = 0;
  175. }
  176. if (testbit(location[position].objects, CYLON)) {
  177. puts("Oh my God, you're being shot at by an alien spacecraft!");
  178. printf("The targeting computer says we have %d seconds to attack!\n",
  179. ourclock);
  180. fflush(stdout);
  181. sleep(1);
  182. if (!visual()) {
  183. hurt = rnd(NUMOFINJURIES);
  184. injuries[hurt] = 1;
  185. puts("Laser blasts sear the cockpit, and the alien veers off in a victory roll.");
  186. puts("The viper shudders under a terrible explosion.");
  187. printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
  188. } else
  189. clearbit(location[position].objects, CYLON);
  190. }
  191. if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) {
  192. puts("I'm afraid you have suffered fatal injuries.");
  193. die();
  194. }
  195. for (n = 0; n < NUMOFINJURIES; n++)
  196. if (injuries[n] == 1) {
  197. injuries[n] = 2;
  198. if (WEIGHT > 5)
  199. WEIGHT -= 5;
  200. else
  201. WEIGHT = 0;
  202. }
  203. if (injuries[ARM] == 2) {
  204. if (CUMBER > 5)
  205. CUMBER -= 5;
  206. else
  207. CUMBER = 0;
  208. injuries[ARM]++;
  209. }
  210. if (injuries[RIBS] == 2) {
  211. if (CUMBER > 2)
  212. CUMBER -= 2;
  213. else
  214. CUMBER = 0;
  215. injuries[RIBS]++;
  216. }
  217. if (injuries[SPINE] == 2) {
  218. WEIGHT = 0;
  219. injuries[SPINE]++;
  220. }
  221. if (carrying > WEIGHT || encumber > CUMBER)
  222. notes[CANTMOVE] = 1;
  223. else
  224. notes[CANTMOVE] = 0;
  225. }
  226. void
  227. crash()
  228. {
  229. int hurt1, hurt2;
  230. fuel--;
  231. if (!location[position].flyhere ||
  232. (testbit(location[position].objects, LAND) && fuel <= 0)) {
  233. if (!location[position].flyhere)
  234. puts("You're flying too low. We're going to crash!");
  235. else {
  236. puts("You're out of fuel. We'll have to crash land!");
  237. if (!location[position].down) {
  238. puts("Your viper strikes the ground and explodes into fiery fragments.");
  239. puts("Thick black smoke billows up from the wreckage.");
  240. die();
  241. }
  242. position = location[position].down;
  243. }
  244. notes[LAUNCHED] = 0;
  245. setbit(location[position].objects, CRASH);
  246. ourtime += rnd(CYCLE / 4);
  247. puts("The viper explodes into the ground and you lose consciousness...");
  248. zzz();
  249. hurt1 = rnd(NUMOFINJURIES - 2) + 2;
  250. hurt2 = rnd(NUMOFINJURIES - 2) + 2;
  251. injuries[hurt1] = 1;
  252. injuries[hurt2] = 1;
  253. injuries[0] = 1;/* abrasions */
  254. injuries[1] = 1;/* lacerations */
  255. printf("I'm afraid you have suffered %s and %s.\n",
  256. ouch[hurt1], ouch[hurt2]);
  257. }
  258. }