1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
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.8 2003/08/07 09:37:55 agc Exp $");
38: #endif
39: #endif
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:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64: void
65: dowarp(fl)
66: int fl;
67: {
68: int c;
69: double d;
70:
71: if (getcodi(&c, &d))
72: return;
73: warp(fl, c, d);
74: }
75:
76: void
77: warp(fl, c, d)
78: int fl, c;
79: double d;
80: {
81: char *p;
82: int course;
83: double power;
84: double dist;
85: double time;
86: double speed;
87: double frac;
88: int percent;
89: int i;
90:
91: if (Ship.cond == DOCKED) {
92: printf("%s is docked\n", Ship.shipname);
93: return;
94: }
95: if (damaged(WARP))
96: {
97: out(WARP);
98: return;
99: }
100:
101: course = c;
102: dist = d;
103:
104:
105: power = (dist + 0.05) * Ship.warp3;
106: percent = 100 * power / Ship.energy + 0.5;
107: if (percent >= 85)
108: {
109: printf("Scotty: That would consume %d%% of our remaining energy.\n",
110: percent);
111: if (!getynpar("Are you sure that is wise"))
112: return;
113: }
114:
115:
116: speed = Ship.warp2 / Param.warptime;
117: time = dist / speed;
118:
119:
120: percent = 100 * time / Now.time + 0.5;
121: if (percent >= 85)
122: {
123: printf("Spock: That would take %d%% of our remaining time.\n",
124: percent);
125: if (!getynpar("Are you sure that is wise"))
126: return;
127: }
128:
129:
130: if (Ship.warp > 6.0 && ranf(100) < 20 + 15 * (Ship.warp - 6.0))
131: {
132: frac = franf();
133: dist *= frac;
134: time *= frac;
135: damage(WARP, (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20);
136: }
137:
138:
139: Move.time = move(fl, course, time, speed);
140:
141:
142: dist = Move.time * speed;
143: Ship.energy -= dist * Ship.warp3 * (Ship.shldup + 1);
144:
145:
146: if (Ship.warp <= 9.0)
147: return;
148: printf("\n\n ___ Speed exceeding warp nine ___\n\n");
149: sleep(2);
150: printf("Ship's safety systems malfunction\n");
151: sleep(2);
152: printf("Crew experiencing extreme sensory distortion\n");
153: sleep(4);
154: if (ranf(100) >= 100 * dist)
155: {
156: printf("Equilibrium restored -- all systems normal\n");
157: return;
158: }
159:
160:
161: percent = ranf(100);
162: if (percent < 70)
163: {
164:
165: if (percent < 35 || !Game.snap)
166: {
167:
168: time = (Ship.warp - 8.0) * dist * (franf() + 1.0);
169: Now.date += time;
170: printf("Positive time portal entered -- it is now Stardate %.2f\n",
171: Now.date);
172: for (i = 0; i < MAXEVENTS; i++)
173: {
174: percent = Event[i].evcode;
175: if (percent == E_FIXDV || percent == E_LRTB)
176: Event[i].date += time;
177: }
178: return;
179: }
180:
181:
182: time = Now.date;
183: p = (char *) Etc.snapshot;
184: memcpy(p, Quad, sizeof Quad);
185: p += sizeof Quad;
186: memcpy(p, Event, sizeof Event);
187: p += sizeof Event;
188: memcpy(p, &Now, sizeof Now);
189: printf("Negative time portal entered -- it is now Stardate %.2f\n",
190: Now.date);
191: for (i = 0; i < MAXEVENTS; i++)
192: if (Event[i].evcode == E_FIXDV)
193: reschedule(&Event[i], Event[i].date - time);
194: return;
195: }
196:
197:
198: if (percent < 80)
199: lose(L_TOOFAST);
200: printf("Equilibrium restored -- extreme damage occurred to ship systems\n");
201: for (i = 0; i < NDEV; i++)
202: damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]);
203: Ship.shldup = 0;
204: }