1 /*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)snova.c 8.1 (Berkeley) 05/31/93";
10 #endif /* not lint */
11
12 # include "trek.h"
13
14 /*
15 ** CAUSE SUPERNOVA TO OCCUR
16 **
17 ** A supernova occurs. If 'ix' < 0, a random quadrant is chosen;
18 ** otherwise, the current quadrant is taken, and (ix, iy) give
19 ** the sector quadrants of the star which is blowing up.
20 **
21 ** If the supernova turns out to be in the quadrant you are in,
22 ** you go into "emergency override mode", which tries to get you
23 ** out of the quadrant as fast as possible. However, if you
24 ** don't have enough fuel, or if you by chance run into something,
25 ** or some such thing, you blow up anyway. Oh yeh, if you are
26 ** within two sectors of the star, there is nothing that can
27 ** be done for you.
28 **
29 ** When a star has gone supernova, the quadrant becomes uninhab-
30 ** itable for the rest of eternity, i.e., the game. If you ever
31 ** try stopping in such a quadrant, you will go into emergency
32 ** override mode.
33 */
34
snova(x,y)35 snova(x, y)
36 int x, y;
37 {
38 int qx, qy;
39 register int ix, iy;
40 int f;
41 int dx, dy;
42 int n;
43 register struct quad *q;
44
45 f = 0;
46 ix = x;
47 if (ix < 0)
48 {
49 /* choose a quadrant */
50 while (1)
51 {
52 qx = ranf(NQUADS);
53 qy = ranf(NQUADS);
54 q = &Quad[qx][qy];
55 if (q->stars > 0)
56 break;
57 }
58 if (Ship.quadx == qx && Ship.quady == qy)
59 {
60 /* select a particular star */
61 n = ranf(q->stars);
62 for (ix = 0; ix < NSECTS; ix++)
63 {
64 for (iy = 0; iy < NSECTS; iy++)
65 if (Sect[ix][iy] == STAR || Sect[ix][iy] == INHABIT)
66 if ((n -= 1) <= 0)
67 break;
68 if (n <= 0)
69 break;
70 }
71 f = 1;
72 }
73 }
74 else
75 {
76 /* current quadrant */
77 iy = y;
78 qx = Ship.quadx;
79 qy = Ship.quady;
80 q = &Quad[qx][qy];
81 f = 1;
82 }
83 if (f)
84 {
85 /* supernova is in same quadrant as Enterprise */
86 printf("\nRED ALERT: supernova occuring at %d,%d\n", ix, iy);
87 dx = ix - Ship.sectx;
88 dy = iy - Ship.secty;
89 if (dx * dx + dy * dy <= 2)
90 {
91 printf("*** Emergency override attem");
92 sleep(1);
93 printf("\n");
94 lose(L_SNOVA);
95 }
96 q->scanned = 1000;
97 }
98 else
99 {
100 if (!damaged(SSRADIO))
101 {
102 q->scanned = 1000;
103 printf("\nUhura: Captain, Starfleet Command reports a supernova\n");
104 printf(" in quadrant %d,%d. Caution is advised\n", qx, qy);
105 }
106 }
107
108 /* clear out the supernova'ed quadrant */
109 dx = q->klings;
110 dy = q->stars;
111 Now.klings -= dx;
112 if (x >= 0)
113 {
114 /* Enterprise caused supernova */
115 Game.kills += dy;
116 if (q->bases)
117 killb(qx, qy, -1);
118 Game.killk += dx;
119 }
120 else
121 if (q->bases)
122 killb(qx, qy, 0);
123 killd(qx, qy, (x >= 0));
124 q->stars = -1;
125 q->klings = 0;
126 if (Now.klings <= 0)
127 {
128 printf("Lucky devil, that supernova destroyed the last klingon\n");
129 win();
130 }
131 return;
132 }
133