warp.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* $NetBSD: warp.c,v 1.8 2003/08/07 09:37:55 agc Exp $ */
  2. /*
  3. * Copyright (c) 1980, 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[] = "@(#)warp.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: warp.c,v 1.8 2003/08/07 09:37:55 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include <stdio.h>
  39. #include <math.h>
  40. #include <string.h>
  41. #include <unistd.h>
  42. #include "trek.h"
  43. #include "getpar.h"
  44. /*
  45. ** MOVE UNDER WARP POWER
  46. **
  47. ** This is both the "move" and the "ram" commands, differing
  48. ** only in the flag 'fl'. It is also used for automatic
  49. ** emergency override mode, when 'fl' is < 0 and 'c' and 'd'
  50. ** are the course and distance to be moved. If 'fl' >= 0,
  51. ** the course and distance are asked of the captain.
  52. **
  53. ** The guts of this routine are in the routine move(), which
  54. ** is shared with impulse(). Also, the working part of this
  55. ** routine is very small; the rest is to handle the slight chance
  56. ** that you may be moving at some riduculous speed. In that
  57. ** case, there is code to handle time warps, etc.
  58. */
  59. void
  60. dowarp(fl)
  61. int fl;
  62. {
  63. int c;
  64. double d;
  65. if (getcodi(&c, &d))
  66. return;
  67. warp(fl, c, d);
  68. }
  69. void
  70. warp(fl, c, d)
  71. int fl, c;
  72. double d;
  73. {
  74. char *p;
  75. int course;
  76. double power;
  77. double dist;
  78. double time;
  79. double speed;
  80. double frac;
  81. int percent;
  82. int i;
  83. if (Ship.cond == DOCKED) {
  84. printf("%s is docked\n", Ship.shipname);
  85. return;
  86. }
  87. if (damaged(WARP))
  88. {
  89. out(WARP);
  90. return;
  91. }
  92. course = c;
  93. dist = d;
  94. /* check to see that we are not using an absurd amount of power */
  95. power = (dist + 0.05) * Ship.warp3;
  96. percent = 100 * power / Ship.energy + 0.5;
  97. if (percent >= 85)
  98. {
  99. printf("Scotty: That would consume %d%% of our remaining energy.\n",
  100. percent);
  101. if (!getynpar("Are you sure that is wise"))
  102. return;
  103. }
  104. /* compute the speed we will move at, and the time it will take */
  105. speed = Ship.warp2 / Param.warptime;
  106. time = dist / speed;
  107. /* check to see that that value is not ridiculous */
  108. percent = 100 * time / Now.time + 0.5;
  109. if (percent >= 85)
  110. {
  111. printf("Spock: That would take %d%% of our remaining time.\n",
  112. percent);
  113. if (!getynpar("Are you sure that is wise"))
  114. return;
  115. }
  116. /* compute how far we will go if we get damages */
  117. if (Ship.warp > 6.0 && ranf(100) < 20 + 15 * (Ship.warp - 6.0))
  118. {
  119. frac = franf();
  120. dist *= frac;
  121. time *= frac;
  122. damage(WARP, (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20);
  123. }
  124. /* do the move */
  125. Move.time = move(fl, course, time, speed);
  126. /* see how far we actually went, and decrement energy appropriately */
  127. dist = Move.time * speed;
  128. Ship.energy -= dist * Ship.warp3 * (Ship.shldup + 1);
  129. /* test for bizarre events */
  130. if (Ship.warp <= 9.0)
  131. return;
  132. printf("\n\n ___ Speed exceeding warp nine ___\n\n");
  133. sleep(2);
  134. printf("Ship's safety systems malfunction\n");
  135. sleep(2);
  136. printf("Crew experiencing extreme sensory distortion\n");
  137. sleep(4);
  138. if (ranf(100) >= 100 * dist)
  139. {
  140. printf("Equilibrium restored -- all systems normal\n");
  141. return;
  142. }
  143. /* select a bizzare thing to happen to us */
  144. percent = ranf(100);
  145. if (percent < 70)
  146. {
  147. /* time warp */
  148. if (percent < 35 || !Game.snap)
  149. {
  150. /* positive time warp */
  151. time = (Ship.warp - 8.0) * dist * (franf() + 1.0);
  152. Now.date += time;
  153. printf("Positive time portal entered -- it is now Stardate %.2f\n",
  154. Now.date);
  155. for (i = 0; i < MAXEVENTS; i++)
  156. {
  157. percent = Event[i].evcode;
  158. if (percent == E_FIXDV || percent == E_LRTB)
  159. Event[i].date += time;
  160. }
  161. return;
  162. }
  163. /* s/he got lucky: a negative time portal */
  164. time = Now.date;
  165. p = (char *) Etc.snapshot;
  166. memcpy(p, Quad, sizeof Quad);
  167. p += sizeof Quad;
  168. memcpy(p, Event, sizeof Event);
  169. p += sizeof Event;
  170. memcpy(p, &Now, sizeof Now);
  171. printf("Negative time portal entered -- it is now Stardate %.2f\n",
  172. Now.date);
  173. for (i = 0; i < MAXEVENTS; i++)
  174. if (Event[i].evcode == E_FIXDV)
  175. reschedule(&Event[i], Event[i].date - time);
  176. return;
  177. }
  178. /* test for just a lot of damage */
  179. if (percent < 80)
  180. lose(L_TOOFAST);
  181. printf("Equilibrium restored -- extreme damage occurred to ship systems\n");
  182. for (i = 0; i < NDEV; i++)
  183. damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]);
  184. Ship.shldup = 0;
  185. }