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