Home | History | Annotate | Line # | Download | only in trek
snova.c revision 1.2
      1 /*
      2  * Copyright (c) 1980 Regents of the University of California.
      3  * 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. 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.
     20  *
     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.
     32  */
     33 
     34 #ifndef lint
     35 /*static char sccsid[] = "from: @(#)snova.c	5.4 (Berkeley) 6/1/90";*/
     36 static char rcsid[] = "$Id: snova.c,v 1.2 1993/08/01 18:49:57 mycroft Exp $";
     37 #endif /* not lint */
     38 
     39 # include	"trek.h"
     40 
     41 /*
     42 **  CAUSE SUPERNOVA TO OCCUR
     43 **
     44 **	A supernova occurs.  If 'ix' < 0, a random quadrant is chosen;
     45 **	otherwise, the current quadrant is taken, and (ix, iy) give
     46 **	the sector quadrants of the star which is blowing up.
     47 **
     48 **	If the supernova turns out to be in the quadrant you are in,
     49 **	you go into "emergency override mode", which tries to get you
     50 **	out of the quadrant as fast as possible.  However, if you
     51 **	don't have enough fuel, or if you by chance run into something,
     52 **	or some such thing, you blow up anyway.  Oh yeh, if you are
     53 **	within two sectors of the star, there is nothing that can
     54 **	be done for you.
     55 **
     56 **	When a star has gone supernova, the quadrant becomes uninhab-
     57 **	itable for the rest of eternity, i.e., the game.  If you ever
     58 **	try stopping in such a quadrant, you will go into emergency
     59 **	override mode.
     60 */
     61 
     62 snova(x, y)
     63 int	x, y;
     64 {
     65 	int			qx, qy;
     66 	register int		ix, iy;
     67 	int			f;
     68 	int			dx, dy;
     69 	int			n;
     70 	register struct quad	*q;
     71 
     72 	f = 0;
     73 	ix = x;
     74 	if (ix < 0)
     75 	{
     76 		/* choose a quadrant */
     77 		while (1)
     78 		{
     79 			qx = ranf(NQUADS);
     80 			qy = ranf(NQUADS);
     81 			q = &Quad[qx][qy];
     82 			if (q->stars > 0)
     83 				break;
     84 		}
     85 		if (Ship.quadx == qx && Ship.quady == qy)
     86 		{
     87 			/* select a particular star */
     88 			n = ranf(q->stars);
     89 			for (ix = 0; ix < NSECTS; ix++)
     90 			{
     91 				for (iy = 0; iy < NSECTS; iy++)
     92 					if (Sect[ix][iy] == STAR || Sect[ix][iy] == INHABIT)
     93 						if ((n -= 1) <= 0)
     94 							break;
     95 				if (n <= 0)
     96 					break;
     97 			}
     98 			f = 1;
     99 		}
    100 	}
    101 	else
    102 	{
    103 		/* current quadrant */
    104 		iy = y;
    105 		qx = Ship.quadx;
    106 		qy = Ship.quady;
    107 		q = &Quad[qx][qy];
    108 		f = 1;
    109 	}
    110 	if (f)
    111 	{
    112 		/* supernova is in same quadrant as Enterprise */
    113 		printf("\nRED ALERT: supernova occuring at %d,%d\n", ix, iy);
    114 		dx = ix - Ship.sectx;
    115 		dy = iy - Ship.secty;
    116 		if (dx * dx + dy * dy <= 2)
    117 		{
    118 			printf("***  Emergency override attem");
    119 			sleep(1);
    120 			printf("\n");
    121 			lose(L_SNOVA);
    122 		}
    123 		q->scanned = 1000;
    124 	}
    125 	else
    126 	{
    127 		if (!damaged(SSRADIO))
    128 		{
    129 			q->scanned = 1000;
    130 			printf("\nUhura: Captain, Starfleet Command reports a supernova\n");
    131 			printf("  in quadrant %d,%d.  Caution is advised\n", qx, qy);
    132 		}
    133 	}
    134 
    135 	/* clear out the supernova'ed quadrant */
    136 	dx = q->klings;
    137 	dy = q->stars;
    138 	Now.klings -= dx;
    139 	if (x >= 0)
    140 	{
    141 		/* Enterprise caused supernova */
    142 		Game.kills += dy;
    143 		if (q->bases)
    144 			killb(qx, qy, -1);
    145 		Game.killk += dx;
    146 	}
    147 	else
    148 		if (q->bases)
    149 			killb(qx, qy, 0);
    150 	killd(qx, qy, (x >= 0));
    151 	q->stars = -1;
    152 	q->klings = 0;
    153 	if (Now.klings <= 0)
    154 	{
    155 		printf("Lucky devil, that supernova destroyed the last klingon\n");
    156 		win();
    157 	}
    158 	return;
    159 }
    160