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