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