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