Fix-up syntax after wizd.
[netbsd-mini2440.git] / games / trek / kill.c
blob051914f5c80dac4df0a0d6a9131170158f946412
1 /* $NetBSD: kill.c,v 1.10 2009/05/24 21:44:56 dholland Exp $ */
3 /*
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
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.
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.
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.10 2009/05/24 21:44:56 dholland Exp $");
38 #endif
39 #endif /* not lint */
41 #include <stdio.h>
42 #include <limits.h>
43 #include "trek.h"
46 ** KILL KILL KILL !!!
48 ** This file handles the killing off of almost anything.
52 ** Handle a Klingon's death
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.
61 void
62 killk(int ix, int iy)
64 int i;
66 printf(" *** Klingon at %d,%d destroyed ***\n", ix, iy);
68 /* remove the scoundrel */
69 Now.klings -= 1;
70 Sect[ix][iy] = EMPTY;
71 Quad[Ship.quadx][Ship.quady].klings -= 1;
72 /* %%% IS THIS SAFE???? %%% */
73 Quad[Ship.quadx][Ship.quady].scanned -= 100;
74 Game.killk += 1;
76 /* find the Klingon in the Klingon list */
77 for (i = 0; i < Etc.nkling; i++)
78 if (ix == Etc.klingon[i].x && iy == Etc.klingon[i].y) {
79 /* purge him from the list */
80 Etc.nkling -= 1;
81 for (; i < Etc.nkling; i++)
82 Etc.klingon[i] = Etc.klingon[i+1];
83 break;
86 /* find out if that was the last one */
87 if (Now.klings <= 0)
88 win();
90 /* recompute time left */
91 Now.time = Now.resource / Now.klings;
92 return;
97 ** handle a starbase's death
100 void
101 killb(int qx, int qy)
103 struct quad *q;
104 struct xy *b;
106 q = &Quad[qx][qy];
108 if (q->bases <= 0)
109 return;
110 if (!damaged(SSRADIO)) {
111 /* then update starchart */
112 if (q->scanned < 1000)
113 q->scanned -= 10;
114 else
115 if (q->scanned > 1000)
116 q->scanned = -1;
118 q->bases = 0;
119 Now.bases -= 1;
120 for (b = Now.base; ; b++)
121 if (qx == b->x && qy == b->y)
122 break;
123 *b = Now.base[Now.bases];
124 if (qx == Ship.quadx && qy == Ship.quady) {
125 Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY;
126 if (Ship.cond == DOCKED)
127 undock(0);
128 printf("Starbase at %d,%d destroyed\n",
129 Etc.starbase.x, Etc.starbase.y);
130 } else {
131 if (!damaged(SSRADIO)) {
132 printf("Uhura: Starfleet command reports that the "
133 "starbase in\n");
134 printf(" quadrant %d,%d has been destroyed\n",
135 qx, qy);
137 else
138 schedule(E_KATSB | E_GHOST, TOOLARGE, qx, qy, 0);
144 ** kill an inhabited starsystem
146 ** x, y are quad coords if f == 0, else sector coords
147 ** f != 0 -- this quad; f < 0 -- Enterprise's fault
150 void
151 kills(int x, int y, int f)
153 struct quad *q;
154 struct event *e;
155 const char *name;
157 if (f) {
158 /* current quadrant */
159 q = &Quad[Ship.quadx][Ship.quady];
160 Sect[x][y] = EMPTY;
161 name = systemname(q);
162 if (name == 0)
163 return;
164 printf("Inhabited starsystem %s at %d,%d destroyed\n",
165 name, x, y);
166 if (f < 0)
167 Game.killinhab += 1;
168 } else {
169 /* different quadrant */
170 q = &Quad[x][y];
172 if (q->qsystemname & Q_DISTRESSED) {
173 /* distressed starsystem */
174 e = &Event[q->qsystemname & Q_SYSTEM];
175 printf("Distress call for %s invalidated\n",
176 Systemname[e->systemname]);
177 unschedule(e);
179 q->qsystemname = 0;
180 q->stars -= 1;
185 ** "kill" a distress call
187 ** x, y are quadrant coordinates
188 ** f is set if user is to be informed
191 void
192 killd(int x, int y, int f)
194 struct event *e;
195 int i;
196 struct quad *q;
198 q = &Quad[x][y];
199 for (i = 0; i < MAXEVENTS; i++) {
200 e = &Event[i];
201 if (e->x != x || e->y != y)
202 continue;
203 switch (e->evcode) {
204 case E_KDESB:
205 if (f) {
206 printf("Distress call for starbase in "
207 "%d,%d nullified\n",
208 x, y);
209 unschedule(e);
211 break;
213 case E_ENSLV:
214 case E_REPRO:
215 if (f) {
216 printf("Distress call for %s in quadrant "
217 "%d,%d nullified\n",
218 Systemname[e->systemname], x, y);
219 q->qsystemname = e->systemname;
220 unschedule(e);
221 } else {
222 e->evcode |= E_GHOST;