Home | History | Annotate | Line # | Download | only in trek
warp.c revision 1.3
      1 /*	$NetBSD: warp.c,v 1.3 1995/04/22 10:59:40 cgd 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. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #ifndef lint
     37 #if 0
     38 static char sccsid[] = "@(#)warp.c	8.1 (Berkeley) 5/31/93";
     39 #else
     40 static char rcsid[] = "$NetBSD: warp.c,v 1.3 1995/04/22 10:59:40 cgd Exp $";
     41 #endif
     42 #endif /* not lint */
     43 
     44 # include	"trek.h"
     45 
     46 /*
     47 **  MOVE UNDER WARP POWER
     48 **
     49 **	This is both the "move" and the "ram" commands, differing
     50 **	only in the flag 'fl'.  It is also used for automatic
     51 **	emergency override mode, when 'fl' is < 0 and 'c' and 'd'
     52 **	are the course and distance to be moved.  If 'fl' >= 0,
     53 **	the course and distance are asked of the captain.
     54 **
     55 **	The guts of this routine are in the routine move(), which
     56 **	is shared with impulse().  Also, the working part of this
     57 **	routine is very small; the rest is to handle the slight chance
     58 **	that you may be moving at some riduculous speed.  In that
     59 **	case, there is code to handle time warps, etc.
     60 */
     61 
     62 warp(fl, c, d)
     63 int	fl, c;
     64 double	d;
     65 {
     66 	int			course;
     67 	double			power;
     68 	double			dist;
     69 	double			time;
     70 	double			speed;
     71 	double			frac;
     72 	register int		percent;
     73 	register int		i;
     74 	extern double		move();
     75 
     76 	if (Ship.cond == DOCKED)
     77 		return (printf("%s is docked\n", Ship.shipname));
     78 	if (damaged(WARP))
     79 	{
     80 		return (out(WARP));
     81 	}
     82 	if (fl < 0)
     83 	{
     84 		course = c;
     85 		dist = d;
     86 	}
     87 	else
     88 		if (getcodi(&course, &dist))
     89 			return;
     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 		return (printf("Equilibrium restored -- all systems normal\n"));
    144 	}
    145 
    146 	/* select a bizzare thing to happen to us */
    147 	percent = ranf(100);
    148 	if (percent < 70)
    149 	{
    150 		/* time warp */
    151 		if (percent < 35 || !Game.snap)
    152 		{
    153 			/* positive time warp */
    154 			time = (Ship.warp - 8.0) * dist * (franf() + 1.0);
    155 			Now.date += time;
    156 			printf("Positive time portal entered -- it is now Stardate %.2f\n",
    157 				Now.date);
    158 			for (i = 0; i < MAXEVENTS; i++)
    159 			{
    160 				percent = Event[i].evcode;
    161 				if (percent == E_FIXDV || percent == E_LRTB)
    162 					Event[i].date += time;
    163 			}
    164 			return;
    165 		}
    166 
    167 		/* s/he got lucky: a negative time portal */
    168 		time = Now.date;
    169 		i = (int) Etc.snapshot;
    170 		bmove(i, Quad, sizeof Quad);
    171 		bmove(i += sizeof Quad, Event, sizeof Event);
    172 		bmove(i += sizeof Event, &Now, sizeof Now);
    173 		printf("Negative time portal entered -- it is now Stardate %.2f\n",
    174 			Now.date);
    175 		for (i = 0; i < MAXEVENTS; i++)
    176 			if (Event[i].evcode == E_FIXDV)
    177 				reschedule(&Event[i], Event[i].date - time);
    178 		return;
    179 	}
    180 
    181 	/* test for just a lot of damage */
    182 	if (percent < 80)
    183 		lose(L_TOOFAST);
    184 	printf("Equilibrium restored -- extreme damage occured to ship systems\n");
    185 	for (i = 0; i < NDEV; i++)
    186 		damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]);
    187 	Ship.shldup = 0;
    188 }
    189