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