xref: /original-bsd/games/trek/nova.c (revision 5d3a6356)
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 are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)nova.c	5.2 (Berkeley) 05/05/88";
15 #endif /* not lint */
16 
17 # include	"trek.h"
18 
19 /*
20 **  CAUSE A NOVA TO OCCUR
21 **
22 **	A nova occurs.  It is the result of having a star hit with
23 **	a photon torpedo.  There are several things which may happen.
24 **	The star may not be affected.  It may go nova.  It may turn
25 **	into a black hole.  Any (yummy) it may go supernova.
26 **
27 **	Stars that go nova cause stars which surround them to undergo
28 **	the same probabilistic process.  Klingons next to them are
29 **	destroyed.  And if the starship is next to it, it gets zapped.
30 **	If the zap is too much, it gets destroyed.
31 */
32 
33 nova(x, y)
34 int	x, y;
35 {
36 	register int		i, j;
37 	register int		se;
38 
39 	if (Sect[x][y] != STAR || Quad[Ship.quadx][Ship.quady].stars < 0)
40 		return;
41 	if (ranf(100) < 15)
42 	{
43 		printf("Spock: Star at %d,%d failed to nova.\n", x, y);
44 		return;
45 	}
46 	if (ranf(100) < 5)
47 		return (snova(x, y));
48 	printf("Spock: Star at %d,%d gone nova\n", x, y);
49 
50 	if (ranf(4) != 0)
51 		Sect[x][y] = EMPTY;
52 	else
53 	{
54 		Sect[x][y] = HOLE;
55 		Quad[Ship.quadx][Ship.quady].holes += 1;
56 	}
57 	Quad[Ship.quadx][Ship.quady].stars -= 1;
58 	Game.kills += 1;
59 	for (i = x - 1; i <= x + 1; i++)
60 	{
61 		if (i < 0 || i >= NSECTS)
62 			continue;
63 		for (j = y - 1; j <= y + 1; j++)
64 		{
65 			if (j < 0 || j >= NSECTS)
66 				continue;
67 			se = Sect[i][j];
68 			switch (se)
69 			{
70 
71 			  case EMPTY:
72 			  case HOLE:
73 				break;
74 
75 			  case KLINGON:
76 				killk(i, j);
77 				break;
78 
79 			  case STAR:
80 				nova(i, j);
81 				break;
82 
83 			  case INHABIT:
84 				kills(i, j, -1);
85 				break;
86 
87 			  case BASE:
88 				killb(i, j);
89 				Game.killb += 1;
90 				break;
91 
92 			  case ENTERPRISE:
93 			  case QUEENE:
94 				se = 2000;
95 				if (Ship.shldup)
96 					if (Ship.shield >= se)
97 					{
98 						Ship.shield -= se;
99 						se = 0;
100 					}
101 					else
102 					{
103 						se -= Ship.shield;
104 						Ship.shield = 0;
105 					}
106 				Ship.energy -= se;
107 				if (Ship.energy <= 0)
108 					lose(L_SUICID);
109 				break;
110 
111 			  default:
112 				printf("Unknown object %c at %d,%d destroyed\n",
113 					se, i, j);
114 				Sect[i][j] = EMPTY;
115 				break;
116 			}
117 		}
118 	}
119 	return;
120 }
121