1 /* $NetBSD: kill.c,v 1.3 1995/04/22 10:59:06 cgd Exp $ */ 2 3 /* 4 * Copyright (c) 1980, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #ifndef lint 37 #if 0 38 static char sccsid[] = "@(#)kill.c 8.1 (Berkeley) 5/31/93"; 39 #else 40 static char rcsid[] = "$NetBSD: kill.c,v 1.3 1995/04/22 10:59:06 cgd Exp $"; 41 #endif 42 #endif /* not lint */ 43 44 # include "trek.h" 45 46 /* 47 ** KILL KILL KILL !!! 48 ** 49 ** This file handles the killing off of almost anything. 50 */ 51 52 /* 53 ** Handle a Klingon's death 54 ** 55 ** The Klingon at the sector given by the parameters is killed 56 ** and removed from the Klingon list. Notice that it is not 57 ** removed from the event list; this is done later, when the 58 ** the event is to be caught. Also, the time left is recomputed, 59 ** and the game is won if that was the last klingon. 60 */ 61 62 killk(ix, iy) 63 int ix, iy; 64 { 65 register int i, j; 66 67 printf(" *** Klingon at %d,%d destroyed ***\n", ix, iy); 68 69 /* remove the scoundrel */ 70 Now.klings -= 1; 71 Sect[ix][iy] = EMPTY; 72 Quad[Ship.quadx][Ship.quady].klings -= 1; 73 /* %%% IS THIS SAFE???? %%% */ 74 Quad[Ship.quadx][Ship.quady].scanned -= 100; 75 Game.killk += 1; 76 77 /* find the Klingon in the Klingon list */ 78 for (i = 0; i < Etc.nkling; i++) 79 if (ix == Etc.klingon[i].x && iy == Etc.klingon[i].y) 80 { 81 /* purge him from the list */ 82 Etc.nkling -= 1; 83 for (; i < Etc.nkling; i++) 84 bmove(&Etc.klingon[i+1], &Etc.klingon[i], sizeof Etc.klingon[i]); 85 break; 86 } 87 88 /* find out if that was the last one */ 89 if (Now.klings <= 0) 90 win(); 91 92 /* recompute time left */ 93 Now.time = Now.resource / Now.klings; 94 return; 95 } 96 97 98 /* 99 ** handle a starbase's death 100 */ 101 102 killb(qx, qy) 103 int qx, qy; 104 { 105 register struct quad *q; 106 register struct xy *b; 107 108 q = &Quad[qx][qy]; 109 110 if (q->bases <= 0) 111 return; 112 if (!damaged(SSRADIO)) 113 /* then update starchart */ 114 if (q->scanned < 1000) 115 q->scanned -= 10; 116 else 117 if (q->scanned > 1000) 118 q->scanned = -1; 119 q->bases = 0; 120 Now.bases -= 1; 121 for (b = Now.base; ; b++) 122 if (qx == b->x && qy == b->y) 123 break; 124 bmove(&Now.base[Now.bases], b, sizeof *b); 125 if (qx == Ship.quadx && qy == Ship.quady) 126 { 127 Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY; 128 if (Ship.cond == DOCKED) 129 undock(); 130 printf("Starbase at %d,%d destroyed\n", Etc.starbase.x, Etc.starbase.y); 131 } 132 else 133 { 134 if (!damaged(SSRADIO)) 135 { 136 printf("Uhura: Starfleet command reports that the starbase in\n"); 137 printf(" quadrant %d,%d has been destroyed\n", qx, qy); 138 } 139 else 140 schedule(E_KATSB | E_GHOST, 1e50, qx, qy, 0); 141 } 142 } 143 144 145 /** 146 ** kill an inhabited starsystem 147 **/ 148 149 kills(x, y, f) 150 int x, y; /* quad coords if f == 0, else sector coords */ 151 int f; /* f != 0 -- this quad; f < 0 -- Enterprise's fault */ 152 { 153 register struct quad *q; 154 register struct event *e; 155 register char *name; 156 char *systemname(); 157 158 if (f) 159 { 160 /* current quadrant */ 161 q = &Quad[Ship.quadx][Ship.quady]; 162 Sect[x][y] = EMPTY; 163 name = systemname(q); 164 if (name == 0) 165 return; 166 printf("Inhabited starsystem %s at %d,%d destroyed\n", 167 name, x, y); 168 if (f < 0) 169 Game.killinhab += 1; 170 } 171 else 172 { 173 /* different quadrant */ 174 q = &Quad[x][y]; 175 } 176 if (q->qsystemname & Q_DISTRESSED) 177 { 178 /* distressed starsystem */ 179 e = &Event[q->qsystemname & Q_SYSTEM]; 180 printf("Distress call for %s invalidated\n", 181 Systemname[e->systemname]); 182 unschedule(e); 183 } 184 q->qsystemname = 0; 185 q->stars -= 1; 186 } 187 188 189 /** 190 ** "kill" a distress call 191 **/ 192 193 killd(x, y, f) 194 int x, y; /* quadrant coordinates */ 195 int f; /* set if user is to be informed */ 196 { 197 register struct event *e; 198 register int i; 199 register struct quad *q; 200 201 q = &Quad[x][y]; 202 for (i = 0; i < MAXEVENTS; i++) 203 { 204 e = &Event[i]; 205 if (e->x != x || e->y != y) 206 continue; 207 switch (e->evcode) 208 { 209 case E_KDESB: 210 if (f) 211 { 212 printf("Distress call for starbase in %d,%d nullified\n", 213 x, y); 214 unschedule(e); 215 } 216 break; 217 218 case E_ENSLV: 219 case E_REPRO: 220 if (f) 221 { 222 printf("Distress call for %s in quadrant %d,%d nullified\n", 223 Systemname[e->systemname], x, y); 224 q->qsystemname = e->systemname; 225 unschedule(e); 226 } 227 else 228 { 229 e->evcode |= E_GHOST; 230 } 231 } 232 } 233 } 234