xref: /csrg-svn/games/trek/snova.c (revision 60859)
121296Sdist /*
2*60859Sbostic  * Copyright (c) 1980, 1993
3*60859Sbostic  *	The Regents of the University of California.  All rights reserved.
434205Sbostic  *
542606Sbostic  * %sccs.include.redist.c%
621296Sdist  */
721296Sdist 
811698Smckusick #ifndef lint
9*60859Sbostic static char sccsid[] = "@(#)snova.c	8.1 (Berkeley) 05/31/93";
1034205Sbostic #endif /* not lint */
1111698Smckusick 
1211698Smckusick # include	"trek.h"
1311698Smckusick 
1411698Smckusick /*
1511698Smckusick **  CAUSE SUPERNOVA TO OCCUR
1611698Smckusick **
1711698Smckusick **	A supernova occurs.  If 'ix' < 0, a random quadrant is chosen;
1811698Smckusick **	otherwise, the current quadrant is taken, and (ix, iy) give
1911698Smckusick **	the sector quadrants of the star which is blowing up.
2011698Smckusick **
2111698Smckusick **	If the supernova turns out to be in the quadrant you are in,
2211698Smckusick **	you go into "emergency override mode", which tries to get you
2311698Smckusick **	out of the quadrant as fast as possible.  However, if you
2411698Smckusick **	don't have enough fuel, or if you by chance run into something,
2511698Smckusick **	or some such thing, you blow up anyway.  Oh yeh, if you are
2611698Smckusick **	within two sectors of the star, there is nothing that can
2711698Smckusick **	be done for you.
2811698Smckusick **
2911698Smckusick **	When a star has gone supernova, the quadrant becomes uninhab-
3011698Smckusick **	itable for the rest of eternity, i.e., the game.  If you ever
3111698Smckusick **	try stopping in such a quadrant, you will go into emergency
3211698Smckusick **	override mode.
3311698Smckusick */
3411698Smckusick 
snova(x,y)3511698Smckusick snova(x, y)
3611698Smckusick int	x, y;
3711698Smckusick {
3811698Smckusick 	int			qx, qy;
3911698Smckusick 	register int		ix, iy;
4011698Smckusick 	int			f;
4111698Smckusick 	int			dx, dy;
4211698Smckusick 	int			n;
4311698Smckusick 	register struct quad	*q;
4411698Smckusick 
4511698Smckusick 	f = 0;
4611698Smckusick 	ix = x;
4711698Smckusick 	if (ix < 0)
4811698Smckusick 	{
4911698Smckusick 		/* choose a quadrant */
5011698Smckusick 		while (1)
5111698Smckusick 		{
5211698Smckusick 			qx = ranf(NQUADS);
5311698Smckusick 			qy = ranf(NQUADS);
5411698Smckusick 			q = &Quad[qx][qy];
5511698Smckusick 			if (q->stars > 0)
5611698Smckusick 				break;
5711698Smckusick 		}
5811698Smckusick 		if (Ship.quadx == qx && Ship.quady == qy)
5911698Smckusick 		{
6011698Smckusick 			/* select a particular star */
6111698Smckusick 			n = ranf(q->stars);
6211698Smckusick 			for (ix = 0; ix < NSECTS; ix++)
6311698Smckusick 			{
6411698Smckusick 				for (iy = 0; iy < NSECTS; iy++)
6511698Smckusick 					if (Sect[ix][iy] == STAR || Sect[ix][iy] == INHABIT)
6612344Slayer 						if ((n -= 1) <= 0)
6711698Smckusick 							break;
6811698Smckusick 				if (n <= 0)
6911698Smckusick 					break;
7011698Smckusick 			}
7111698Smckusick 			f = 1;
7211698Smckusick 		}
7311698Smckusick 	}
7411698Smckusick 	else
7511698Smckusick 	{
7611698Smckusick 		/* current quadrant */
7711698Smckusick 		iy = y;
7811698Smckusick 		qx = Ship.quadx;
7911698Smckusick 		qy = Ship.quady;
8011698Smckusick 		q = &Quad[qx][qy];
8111698Smckusick 		f = 1;
8211698Smckusick 	}
8311698Smckusick 	if (f)
8411698Smckusick 	{
8511698Smckusick 		/* supernova is in same quadrant as Enterprise */
8611698Smckusick 		printf("\nRED ALERT: supernova occuring at %d,%d\n", ix, iy);
8711698Smckusick 		dx = ix - Ship.sectx;
8811698Smckusick 		dy = iy - Ship.secty;
8911698Smckusick 		if (dx * dx + dy * dy <= 2)
9011698Smckusick 		{
9111698Smckusick 			printf("***  Emergency override attem");
9211698Smckusick 			sleep(1);
9311698Smckusick 			printf("\n");
9411698Smckusick 			lose(L_SNOVA);
9511698Smckusick 		}
9611698Smckusick 		q->scanned = 1000;
9711698Smckusick 	}
9811698Smckusick 	else
9911698Smckusick 	{
10011698Smckusick 		if (!damaged(SSRADIO))
10111698Smckusick 		{
10211698Smckusick 			q->scanned = 1000;
10311698Smckusick 			printf("\nUhura: Captain, Starfleet Command reports a supernova\n");
10411698Smckusick 			printf("  in quadrant %d,%d.  Caution is advised\n", qx, qy);
10511698Smckusick 		}
10611698Smckusick 	}
10711698Smckusick 
10811698Smckusick 	/* clear out the supernova'ed quadrant */
10911698Smckusick 	dx = q->klings;
11011698Smckusick 	dy = q->stars;
11112344Slayer 	Now.klings -= dx;
11211698Smckusick 	if (x >= 0)
11311698Smckusick 	{
11411698Smckusick 		/* Enterprise caused supernova */
11512344Slayer 		Game.kills += dy;
11611698Smckusick 		if (q->bases)
11711698Smckusick 			killb(qx, qy, -1);
11812344Slayer 		Game.killk += dx;
11911698Smckusick 	}
12011698Smckusick 	else
12111698Smckusick 		if (q->bases)
12211698Smckusick 			killb(qx, qy, 0);
12311698Smckusick 	killd(qx, qy, (x >= 0));
12411698Smckusick 	q->stars = -1;
12511698Smckusick 	q->klings = 0;
12611698Smckusick 	if (Now.klings <= 0)
12711698Smckusick 	{
12811698Smckusick 		printf("Lucky devil, that supernova destroyed the last klingon\n");
12911698Smckusick 		win();
13011698Smckusick 	}
13111698Smckusick 	return;
13211698Smckusick }
133