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