xref: /csrg-svn/games/trek/autover.c (revision 34712)
121265Sdist /*
221265Sdist  * Copyright (c) 1980 Regents of the University of California.
334205Sbostic  * All rights reserved.
434205Sbostic  *
534205Sbostic  * Redistribution and use in source and binary forms are permitted
634205Sbostic  * provided that this notice is preserved and that due credit is given
734205Sbostic  * to the University of California at Berkeley. The name of the University
834205Sbostic  * may not be used to endorse or promote products derived from this
934205Sbostic  * software without specific prior written permission. This software
1034205Sbostic  * is provided ``as is'' without express or implied warranty.
1121265Sdist  */
1221265Sdist 
1311658Smckusick #ifndef lint
14*34712Sbostic static char sccsid[] = "@(#)autover.c	5.3 (Berkeley) 06/12/88";
1534205Sbostic #endif /* not lint */
1611658Smckusick 
1711658Smckusick # include	"trek.h"
1811658Smckusick 
1911658Smckusick /*
2011658Smckusick **  Automatic Override
2111658Smckusick **
2211658Smckusick **	If we should be so unlucky as to be caught in a quadrant
2311658Smckusick **	with a supernova in it, this routine is called.  It is
2411658Smckusick **	called from checkcond().
2511658Smckusick **
2611658Smckusick **	It sets you to a random warp (guaranteed to be over 6.0)
2711658Smckusick **	and starts sending you off "somewhere" (whereever that is).
2811658Smckusick **
2911658Smckusick **	Please note that it is VERY important that you reset your
3011658Smckusick **	warp speed after the automatic override is called.  The new
3111658Smckusick **	warp factor does not stay in effect for just this routine.
3211658Smckusick **
3311658Smckusick **	This routine will never try to send you more than sqrt(2)
3411658Smckusick **	quadrants, since that is all that is needed.
3511658Smckusick */
3611658Smckusick 
3711658Smckusick autover()
3811658Smckusick {
3912737Slayer 	double			dist;
4011658Smckusick 	register int		course;
4111658Smckusick 
42*34712Sbostic 	printf("\07RED ALERT:  The %s is in a supernova quadrant\n", Ship.shipname);
4311658Smckusick 	printf("***  Emergency override attempts to hurl %s to safety\n", Ship.shipname);
4411658Smckusick 	/* let's get our ass out of here */
4511658Smckusick 	Ship.warp = 6.0 + 2.0 * franf();
4611658Smckusick 	Ship.warp2 = Ship.warp * Ship.warp;
4711658Smckusick 	Ship.warp3 = Ship.warp2 * Ship.warp;
4811658Smckusick 	dist = 0.75 * Ship.energy / (Ship.warp3 * (Ship.shldup + 1));
4911658Smckusick 	if (dist > 1.4142)
5011658Smckusick 		dist = 1.4142;
5111658Smckusick 	course = ranf(360);
5211658Smckusick 	Etc.nkling = -1;
5311658Smckusick 	Ship.cond = RED;
5411658Smckusick 	warp(-1, course, dist);
5511658Smckusick 	attack(0);
5611658Smckusick }
57