|
|
1.1 ! root 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 provided ! 6: * that: (1) source distributions retain this entire copyright notice and ! 7: * comment, and (2) distributions including binaries display the following ! 8: * acknowledgement: ``This product includes software developed by the ! 9: * University of California, Berkeley and its contributors'' in the ! 10: * documentation or other materials provided with the distribution and in ! 11: * all advertising materials mentioning features or use of this software. ! 12: * Neither the name of the University nor the names of its contributors may ! 13: * be used to endorse or promote products derived from this software without ! 14: * specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 16: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 17: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)snova.c 5.4 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: # include "trek.h" ! 25: ! 26: /* ! 27: ** CAUSE SUPERNOVA TO OCCUR ! 28: ** ! 29: ** A supernova occurs. If 'ix' < 0, a random quadrant is chosen; ! 30: ** otherwise, the current quadrant is taken, and (ix, iy) give ! 31: ** the sector quadrants of the star which is blowing up. ! 32: ** ! 33: ** If the supernova turns out to be in the quadrant you are in, ! 34: ** you go into "emergency override mode", which tries to get you ! 35: ** out of the quadrant as fast as possible. However, if you ! 36: ** don't have enough fuel, or if you by chance run into something, ! 37: ** or some such thing, you blow up anyway. Oh yeh, if you are ! 38: ** within two sectors of the star, there is nothing that can ! 39: ** be done for you. ! 40: ** ! 41: ** When a star has gone supernova, the quadrant becomes uninhab- ! 42: ** itable for the rest of eternity, i.e., the game. If you ever ! 43: ** try stopping in such a quadrant, you will go into emergency ! 44: ** override mode. ! 45: */ ! 46: ! 47: snova(x, y) ! 48: int x, y; ! 49: { ! 50: int qx, qy; ! 51: register int ix, iy; ! 52: int f; ! 53: int dx, dy; ! 54: int n; ! 55: register struct quad *q; ! 56: ! 57: f = 0; ! 58: ix = x; ! 59: if (ix < 0) ! 60: { ! 61: /* choose a quadrant */ ! 62: while (1) ! 63: { ! 64: qx = ranf(NQUADS); ! 65: qy = ranf(NQUADS); ! 66: q = &Quad[qx][qy]; ! 67: if (q->stars > 0) ! 68: break; ! 69: } ! 70: if (Ship.quadx == qx && Ship.quady == qy) ! 71: { ! 72: /* select a particular star */ ! 73: n = ranf(q->stars); ! 74: for (ix = 0; ix < NSECTS; ix++) ! 75: { ! 76: for (iy = 0; iy < NSECTS; iy++) ! 77: if (Sect[ix][iy] == STAR || Sect[ix][iy] == INHABIT) ! 78: if ((n -= 1) <= 0) ! 79: break; ! 80: if (n <= 0) ! 81: break; ! 82: } ! 83: f = 1; ! 84: } ! 85: } ! 86: else ! 87: { ! 88: /* current quadrant */ ! 89: iy = y; ! 90: qx = Ship.quadx; ! 91: qy = Ship.quady; ! 92: q = &Quad[qx][qy]; ! 93: f = 1; ! 94: } ! 95: if (f) ! 96: { ! 97: /* supernova is in same quadrant as Enterprise */ ! 98: printf("\nRED ALERT: supernova occuring at %d,%d\n", ix, iy); ! 99: dx = ix - Ship.sectx; ! 100: dy = iy - Ship.secty; ! 101: if (dx * dx + dy * dy <= 2) ! 102: { ! 103: printf("*** Emergency override attem"); ! 104: sleep(1); ! 105: printf("\n"); ! 106: lose(L_SNOVA); ! 107: } ! 108: q->scanned = 1000; ! 109: } ! 110: else ! 111: { ! 112: if (!damaged(SSRADIO)) ! 113: { ! 114: q->scanned = 1000; ! 115: printf("\nUhura: Captain, Starfleet Command reports a supernova\n"); ! 116: printf(" in quadrant %d,%d. Caution is advised\n", qx, qy); ! 117: } ! 118: } ! 119: ! 120: /* clear out the supernova'ed quadrant */ ! 121: dx = q->klings; ! 122: dy = q->stars; ! 123: Now.klings -= dx; ! 124: if (x >= 0) ! 125: { ! 126: /* Enterprise caused supernova */ ! 127: Game.kills += dy; ! 128: if (q->bases) ! 129: killb(qx, qy, -1); ! 130: Game.killk += dx; ! 131: } ! 132: else ! 133: if (q->bases) ! 134: killb(qx, qy, 0); ! 135: killd(qx, qy, (x >= 0)); ! 136: q->stars = -1; ! 137: q->klings = 0; ! 138: if (Now.klings <= 0) ! 139: { ! 140: printf("Lucky devil, that supernova destroyed the last klingon\n"); ! 141: win(); ! 142: } ! 143: return; ! 144: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.