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