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