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