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