1 #ifndef lint 2 static char sccsid[] = "@(#)kill.c 4.2 (Berkeley) 05/27/83"; 3 #endif not lint 4 5 # include "trek.h" 6 7 /* 8 ** KILL KILL KILL !!! 9 ** 10 ** This file handles the killing off of almost anything. 11 */ 12 13 /* 14 ** Handle a Klingon's death 15 ** 16 ** The Klingon at the sector given by the parameters is killed 17 ** and removed from the Klingon list. Notice that it is not 18 ** removed from the event list; this is done later, when the 19 ** the event is to be caught. Also, the time left is recomputed, 20 ** and the game is won if that was the last klingon. 21 */ 22 23 killk(ix, iy) 24 int ix, iy; 25 { 26 register int i, j; 27 28 printf(" *** Klingon at %d,%d destroyed ***\n", ix, iy); 29 30 /* remove the scoundrel */ 31 Now.klings -= 1; 32 Sect[ix][iy] = EMPTY; 33 Quad[Ship.quadx][Ship.quady].klings -= 1; 34 /* %%% IS THIS SAFE???? %%% */ 35 Quad[Ship.quadx][Ship.quady].scanned -= 100; 36 Game.killk += 1; 37 38 /* find the Klingon in the Klingon list */ 39 for (i = 0; i < Etc.nkling; i++) 40 if (ix == Etc.klingon[i].x && iy == Etc.klingon[i].y) 41 { 42 /* purge him from the list */ 43 Etc.nkling -= 1; 44 for (; i < Etc.nkling; i++) 45 bmove(&Etc.klingon[i+1], &Etc.klingon[i], sizeof Etc.klingon[i]); 46 break; 47 } 48 49 /* find out if that was the last one */ 50 if (Now.klings <= 0) 51 win(); 52 53 /* recompute time left */ 54 Now.time = Now.resource / Now.klings; 55 return; 56 } 57 58 59 /* 60 ** handle a starbase's death 61 */ 62 63 killb(qx, qy) 64 int qx, qy; 65 { 66 register struct quad *q; 67 register struct xy *b; 68 69 q = &Quad[qx][qy]; 70 71 if (q->bases <= 0) 72 return; 73 if (!damaged(SSRADIO)) 74 /* then update starchart */ 75 if (q->scanned < 1000) 76 q->scanned -= 10; 77 else 78 if (q->scanned > 1000) 79 q->scanned = -1; 80 q->bases = 0; 81 Now.bases -= 1; 82 for (b = Now.base; ; b++) 83 if (qx == b->x && qy == b->y) 84 break; 85 bmove(&Now.base[Now.bases], b, sizeof *b); 86 if (qx == Ship.quadx && qy == Ship.quady) 87 { 88 Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY; 89 if (Ship.cond == DOCKED) 90 undock(); 91 printf("Starbase at %d,%d destroyed\n", Etc.starbase.x, Etc.starbase.y); 92 } 93 else 94 { 95 if (!damaged(SSRADIO)) 96 { 97 printf("Uhura: Starfleet command reports that the starbase in\n"); 98 printf(" quadrant %d,%d has been destroyed\n", qx, qy); 99 } 100 else 101 schedule(E_KATSB | E_GHOST, 1e50, qx, qy, 0); 102 } 103 } 104 105 106 /** 107 ** kill an inhabited starsystem 108 **/ 109 110 kills(x, y, f) 111 int x, y; /* quad coords if f == 0, else sector coords */ 112 int f; /* f != 0 -- this quad; f < 0 -- Enterprise's fault */ 113 { 114 register struct quad *q; 115 register struct event *e; 116 register char *name; 117 char *systemname(); 118 119 if (f) 120 { 121 /* current quadrant */ 122 q = &Quad[Ship.quadx][Ship.quady]; 123 Sect[x][y] = EMPTY; 124 name = systemname(q); 125 if (name == 0) 126 return; 127 printf("Inhabited starsystem %s at %d,%d destroyed\n", 128 name, x, y); 129 if (f < 0) 130 Game.killinhab += 1; 131 } 132 else 133 { 134 /* different quadrant */ 135 q = &Quad[x][y]; 136 } 137 if (q->qsystemname & Q_DISTRESSED) 138 { 139 /* distressed starsystem */ 140 e = &Event[q->qsystemname & Q_SYSTEM]; 141 printf("Distress call for %s invalidated\n", 142 Systemname[e->systemname]); 143 unschedule(e); 144 } 145 q->qsystemname = 0; 146 q->stars -= 1; 147 } 148 149 150 /** 151 ** "kill" a distress call 152 **/ 153 154 killd(x, y, f) 155 int x, y; /* quadrant coordinates */ 156 int f; /* set if user is to be informed */ 157 { 158 register struct event *e; 159 register int i; 160 register struct quad *q; 161 162 q = &Quad[x][y]; 163 for (i = 0; i < MAXEVENTS; i++) 164 { 165 e = &Event[i]; 166 if (e->x != x || e->y != y) 167 continue; 168 switch (e->evcode) 169 { 170 case E_KDESB: 171 if (f) 172 { 173 printf("Distress call for starbase in %d,%d nullified\n", 174 x, y); 175 unschedule(e); 176 } 177 break; 178 179 case E_ENSLV: 180 case E_REPRO: 181 if (f) 182 { 183 printf("Distress call for %s in quadrant %d,%d nullified\n", 184 Systemname[e->systemname], x, y); 185 q->qsystemname = e->systemname; 186 unschedule(e); 187 } 188 else 189 { 190 e->evcode |= E_GHOST; 191 } 192 } 193 } 194 } 195