1 /* $OpenBSD: warp.c,v 1.6 2009/10/27 23:59:27 deraadt Exp $ */ 2 /* $NetBSD: warp.c,v 1.3 1995/04/22 10:59:40 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 1980, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #include <stdio.h> 34 #include <math.h> 35 #include <string.h> 36 #include <unistd.h> 37 #include "trek.h" 38 #include "getpar.h" 39 40 /* 41 ** MOVE UNDER WARP POWER 42 ** 43 ** This is both the "move" and the "ram" commands, differing 44 ** only in the flag 'fl'. It is also used for automatic 45 ** emergency override mode, when 'fl' is < 0 and 'c' and 'd' 46 ** are the course and distance to be moved. If 'fl' >= 0, 47 ** the course and distance are asked of the captain. 48 ** 49 ** The guts of this routine are in the routine move(), which 50 ** is shared with impulse(). Also, the working part of this 51 ** routine is very small; the rest is to handle the slight chance 52 ** that you may be moving at some riduculous speed. In that 53 ** case, there is code to handle time warps, etc. 54 */ 55 56 void 57 dowarp(fl) 58 int fl; 59 { 60 int c; 61 double d; 62 63 if (getcodi(&c, &d)) 64 return; 65 warp(fl, c, d); 66 } 67 68 void 69 warp(fl, c, d) 70 int fl, c; 71 double d; 72 { 73 char *p; 74 double power, dist, time, speed, frac; 75 int course, percent, i; 76 77 if (Ship.cond == DOCKED) 78 { 79 printf("%s is docked\n", Ship.shipname); 80 return; 81 } 82 if (damaged(WARP)) 83 { 84 out(WARP); 85 return; 86 } 87 88 course = c; 89 dist = d; 90 91 /* check to see that we are not using an absurd amount of power */ 92 power = (dist + 0.05) * Ship.warp3; 93 percent = 100 * power / Ship.energy + 0.5; 94 if (percent >= 85) 95 { 96 printf("Scotty: That would consume %d%% of our remaining energy.\n", 97 percent); 98 if (!getynpar("Are you sure that is wise")) 99 return; 100 } 101 102 /* compute the speed we will move at, and the time it will take */ 103 speed = Ship.warp2 / Param.warptime; 104 time = dist / speed; 105 106 /* check to see that that value is not ridiculous */ 107 percent = 100 * time / Now.time + 0.5; 108 if (percent >= 85) 109 { 110 printf("Spock: That would take %d%% of our remaining time.\n", 111 percent); 112 if (!getynpar("Are you sure that is wise")) 113 return; 114 } 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 125 /* do the move */ 126 Move.time = move(fl, course, time, speed); 127 128 /* see how far we actually went, and decrement energy appropriately */ 129 dist = Move.time * speed; 130 Ship.energy -= dist * Ship.warp3 * (Ship.shldup + 1); 131 132 /* test for bizarre events */ 133 if (Ship.warp <= 9.0) 134 return; 135 printf("\n\n ___ Speed exceeding warp nine ___\n\n"); 136 sleep(2); 137 printf("Ship's safety systems malfunction\n"); 138 sleep(2); 139 printf("Crew experiencing extreme sensory distortion\n"); 140 sleep(4); 141 if (ranf(100) >= 100 * dist) 142 { 143 printf("Equilibrium restored -- all systems normal\n"); 144 return; 145 } 146 147 /* select a bizarre thing to happen to us */ 148 percent = ranf(100); 149 if (percent < 70) 150 { 151 /* time warp */ 152 if (percent < 35 || !Game.snap) 153 { 154 /* positive time warp */ 155 time = (Ship.warp - 8.0) * dist * (franf() + 1.0); 156 Now.date += time; 157 printf("Positive time portal entered -- it is now Stardate %.2f\n", 158 Now.date); 159 for (i = 0; i < MAXEVENTS; i++) 160 { 161 percent = Event[i].evcode; 162 if (percent == E_FIXDV || percent == E_LRTB) 163 Event[i].date += time; 164 } 165 return; 166 } 167 168 /* s/he got lucky: a negative time portal */ 169 time = Now.date; 170 p = (char *) Etc.snapshot; 171 memcpy(p, Quad, sizeof Quad); 172 p += sizeof Quad; 173 memcpy(p, Event, sizeof Event); 174 p += sizeof Event; 175 memcpy(p, &Now, sizeof Now); 176 printf("Negative time portal entered -- it is now Stardate %.2f\n", 177 Now.date); 178 for (i = 0; i < MAXEVENTS; i++) 179 if (Event[i].evcode == E_FIXDV) 180 reschedule(&Event[i], Event[i].date - time); 181 return; 182 } 183 184 /* test for just a lot of damage */ 185 if (percent < 80) 186 lose(L_TOOFAST); 187 printf("Equilibrium restored -- extreme damage occurred to ship systems\n"); 188 for (i = 0; i < NDEV; i++) 189 damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]); 190 Ship.shldup = 0; 191 } 192