1 /* $OpenBSD: nova.c,v 1.2 1998/08/19 07:41:51 pjanzen Exp $ */ 2 /* $NetBSD: nova.c,v 1.3 1995/04/22 10:59:14 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 1980, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37 #ifndef lint 38 #if 0 39 static char sccsid[] = "@(#)nova.c 8.1 (Berkeley) 5/31/93"; 40 #else 41 static char rcsid[] = "$OpenBSD: nova.c,v 1.2 1998/08/19 07:41:51 pjanzen Exp $"; 42 #endif 43 #endif /* not lint */ 44 45 #include <stdio.h> 46 #include "trek.h" 47 48 /* 49 ** CAUSE A NOVA TO OCCUR 50 ** 51 ** A nova occurs. It is the result of having a star hit with 52 ** a photon torpedo. There are several things which may happen. 53 ** The star may not be affected. It may go nova. It may turn 54 ** into a black hole. Any (yummy) it may go supernova. 55 ** 56 ** Stars that go nova cause stars which surround them to undergo 57 ** the same probabilistic process. Klingons next to them are 58 ** destroyed. And if the starship is next to it, it gets zapped. 59 ** If the zap is too much, it gets destroyed. 60 */ 61 62 void 63 nova(x, y) 64 int x, y; 65 { 66 register int i, j; 67 register int se; 68 69 if (Sect[x][y] != STAR || Quad[Ship.quadx][Ship.quady].stars < 0) 70 return; 71 if (ranf(100) < 15) 72 { 73 printf("Spock: Star at %d,%d failed to nova.\n", x, y); 74 return; 75 } 76 if (ranf(100) < 5) 77 { 78 snova(x, y); 79 return; 80 } 81 printf("Spock: Star at %d,%d gone nova\n", x, y); 82 83 if (ranf(4) != 0) 84 Sect[x][y] = EMPTY; 85 else 86 { 87 Sect[x][y] = HOLE; 88 Quad[Ship.quadx][Ship.quady].holes += 1; 89 } 90 Quad[Ship.quadx][Ship.quady].stars -= 1; 91 Game.kills += 1; 92 for (i = x - 1; i <= x + 1; i++) 93 { 94 if (i < 0 || i >= NSECTS) 95 continue; 96 for (j = y - 1; j <= y + 1; j++) 97 { 98 if (j < 0 || j >= NSECTS) 99 continue; 100 se = Sect[i][j]; 101 switch (se) 102 { 103 104 case EMPTY: 105 case HOLE: 106 break; 107 108 case KLINGON: 109 killk(i, j); 110 break; 111 112 case STAR: 113 nova(i, j); 114 break; 115 116 case INHABIT: 117 kills(i, j, -1); 118 break; 119 120 case BASE: 121 killb(i, j); 122 Game.killb += 1; 123 break; 124 125 case ENTERPRISE: 126 case QUEENE: 127 se = 2000; 128 if (Ship.shldup) 129 { 130 if (Ship.shield >= se) 131 { 132 Ship.shield -= se; 133 se = 0; 134 } 135 else 136 { 137 se -= Ship.shield; 138 Ship.shield = 0; 139 } 140 } 141 Ship.energy -= se; 142 if (Ship.energy <= 0) 143 lose(L_SUICID); 144 break; 145 146 default: 147 printf("Unknown object %c at %d,%d destroyed\n", 148 se, i, j); 149 Sect[i][j] = EMPTY; 150 break; 151 } 152 } 153 } 154 } 155