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