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