Home | History | Annotate | Line # | Download | only in trek
nova.c revision 1.4
      1 /*	$NetBSD: nova.c,v 1.4 1997/10/12 21:25:03 christos 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 #include <sys/cdefs.h>
     37 #ifndef lint
     38 #if 0
     39 static char sccsid[] = "@(#)nova.c	8.1 (Berkeley) 5/31/93";
     40 #else
     41 __RCSID("$NetBSD: nova.c,v 1.4 1997/10/12 21:25:03 christos Exp $");
     42 #endif
     43 #endif /* not lint */
     44 
     45 #include <stdio.h>
     46 #include "trek.h"
     47 
     48 /*
     49 **  CAUSE A NOVA TO OCCUR
     50 **
     51 **	A nova occurs.  It is the result of having a star hit with
     52 **	a photon torpedo.  There are several things which may happen.
     53 **	The star may not be affected.  It may go nova.  It may turn
     54 **	into a black hole.  Any (yummy) it may go supernova.
     55 **
     56 **	Stars that go nova cause stars which surround them to undergo
     57 **	the same probabilistic process.  Klingons next to them are
     58 **	destroyed.  And if the starship is next to it, it gets zapped.
     59 **	If the zap is too much, it gets destroyed.
     60 */
     61 
     62 void
     63 nova(x, y)
     64 int	x, y;
     65 {
     66 	int	i, j;
     67 	int	se;
     68 
     69 	if (Sect[x][y] != STAR || Quad[Ship.quadx][Ship.quady].stars < 0)
     70 		return;
     71 	if (ranf(100) < 15)
     72 	{
     73 		printf("Spock: Star at %d,%d failed to nova.\n", x, y);
     74 		return;
     75 	}
     76 	if (ranf(100) < 5) {
     77 		snova(x, y);
     78 		return;
     79 	}
     80 	printf("Spock: Star at %d,%d gone nova\n", x, y);
     81 
     82 	if (ranf(4) != 0)
     83 		Sect[x][y] = EMPTY;
     84 	else
     85 	{
     86 		Sect[x][y] = HOLE;
     87 		Quad[Ship.quadx][Ship.quady].holes += 1;
     88 	}
     89 	Quad[Ship.quadx][Ship.quady].stars -= 1;
     90 	Game.kills += 1;
     91 	for (i = x - 1; i <= x + 1; i++)
     92 	{
     93 		if (i < 0 || i >= NSECTS)
     94 			continue;
     95 		for (j = y - 1; j <= y + 1; j++)
     96 		{
     97 			if (j < 0 || j >= NSECTS)
     98 				continue;
     99 			se = Sect[i][j];
    100 			switch (se)
    101 			{
    102 
    103 			  case EMPTY:
    104 			  case HOLE:
    105 				break;
    106 
    107 			  case KLINGON:
    108 				killk(i, j);
    109 				break;
    110 
    111 			  case STAR:
    112 				nova(i, j);
    113 				break;
    114 
    115 			  case INHABIT:
    116 				kills(i, j, -1);
    117 				break;
    118 
    119 			  case BASE:
    120 				killb(i, j);
    121 				Game.killb += 1;
    122 				break;
    123 
    124 			  case ENTERPRISE:
    125 			  case QUEENE:
    126 				se = 2000;
    127 				if (Ship.shldup)
    128 					if (Ship.shield >= se)
    129 					{
    130 						Ship.shield -= se;
    131 						se = 0;
    132 					}
    133 					else
    134 					{
    135 						se -= Ship.shield;
    136 						Ship.shield = 0;
    137 					}
    138 				Ship.energy -= se;
    139 				if (Ship.energy <= 0)
    140 					lose(L_SUICID);
    141 				break;
    142 
    143 			  default:
    144 				printf("Unknown object %c at %d,%d destroyed\n",
    145 					se, i, j);
    146 				Sect[i][j] = EMPTY;
    147 				break;
    148 			}
    149 		}
    150 	}
    151 	return;
    152 }
    153