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