Commit | Line | Data |
---|---|---|
9758240b KM |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
e9fb6bea KB |
3 | * All rights reserved. |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
d99e6414 KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
9758240b KM |
16 | */ |
17 | ||
060604f0 | 18 | #ifndef lint |
d99e6414 | 19 | static char sccsid[] = "@(#)kill.c 5.3 (Berkeley) %G%"; |
e9fb6bea | 20 | #endif /* not lint */ |
060604f0 KM |
21 | |
22 | # include "trek.h" | |
23 | ||
24 | /* | |
25 | ** KILL KILL KILL !!! | |
26 | ** | |
27 | ** This file handles the killing off of almost anything. | |
28 | */ | |
29 | ||
30 | /* | |
31 | ** Handle a Klingon's death | |
32 | ** | |
33 | ** The Klingon at the sector given by the parameters is killed | |
34 | ** and removed from the Klingon list. Notice that it is not | |
35 | ** removed from the event list; this is done later, when the | |
36 | ** the event is to be caught. Also, the time left is recomputed, | |
37 | ** and the game is won if that was the last klingon. | |
38 | */ | |
39 | ||
40 | killk(ix, iy) | |
41 | int ix, iy; | |
42 | { | |
43 | register int i, j; | |
44 | ||
45 | printf(" *** Klingon at %d,%d destroyed ***\n", ix, iy); | |
46 | ||
47 | /* remove the scoundrel */ | |
06d69904 | 48 | Now.klings -= 1; |
060604f0 | 49 | Sect[ix][iy] = EMPTY; |
06d69904 | 50 | Quad[Ship.quadx][Ship.quady].klings -= 1; |
060604f0 | 51 | /* %%% IS THIS SAFE???? %%% */ |
06d69904 KL |
52 | Quad[Ship.quadx][Ship.quady].scanned -= 100; |
53 | Game.killk += 1; | |
060604f0 KM |
54 | |
55 | /* find the Klingon in the Klingon list */ | |
56 | for (i = 0; i < Etc.nkling; i++) | |
57 | if (ix == Etc.klingon[i].x && iy == Etc.klingon[i].y) | |
58 | { | |
59 | /* purge him from the list */ | |
06d69904 | 60 | Etc.nkling -= 1; |
060604f0 KM |
61 | for (; i < Etc.nkling; i++) |
62 | bmove(&Etc.klingon[i+1], &Etc.klingon[i], sizeof Etc.klingon[i]); | |
63 | break; | |
64 | } | |
65 | ||
66 | /* find out if that was the last one */ | |
67 | if (Now.klings <= 0) | |
68 | win(); | |
69 | ||
70 | /* recompute time left */ | |
71 | Now.time = Now.resource / Now.klings; | |
72 | return; | |
73 | } | |
74 | ||
75 | ||
76 | /* | |
77 | ** handle a starbase's death | |
78 | */ | |
79 | ||
80 | killb(qx, qy) | |
81 | int qx, qy; | |
82 | { | |
83 | register struct quad *q; | |
84 | register struct xy *b; | |
85 | ||
86 | q = &Quad[qx][qy]; | |
87 | ||
88 | if (q->bases <= 0) | |
89 | return; | |
90 | if (!damaged(SSRADIO)) | |
91 | /* then update starchart */ | |
92 | if (q->scanned < 1000) | |
06d69904 | 93 | q->scanned -= 10; |
060604f0 KM |
94 | else |
95 | if (q->scanned > 1000) | |
96 | q->scanned = -1; | |
97 | q->bases = 0; | |
06d69904 | 98 | Now.bases -= 1; |
060604f0 KM |
99 | for (b = Now.base; ; b++) |
100 | if (qx == b->x && qy == b->y) | |
101 | break; | |
102 | bmove(&Now.base[Now.bases], b, sizeof *b); | |
103 | if (qx == Ship.quadx && qy == Ship.quady) | |
104 | { | |
105 | Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY; | |
106 | if (Ship.cond == DOCKED) | |
107 | undock(); | |
108 | printf("Starbase at %d,%d destroyed\n", Etc.starbase.x, Etc.starbase.y); | |
109 | } | |
110 | else | |
111 | { | |
112 | if (!damaged(SSRADIO)) | |
113 | { | |
114 | printf("Uhura: Starfleet command reports that the starbase in\n"); | |
115 | printf(" quadrant %d,%d has been destroyed\n", qx, qy); | |
116 | } | |
117 | else | |
118 | schedule(E_KATSB | E_GHOST, 1e50, qx, qy, 0); | |
119 | } | |
120 | } | |
121 | ||
122 | ||
123 | /** | |
124 | ** kill an inhabited starsystem | |
125 | **/ | |
126 | ||
127 | kills(x, y, f) | |
128 | int x, y; /* quad coords if f == 0, else sector coords */ | |
129 | int f; /* f != 0 -- this quad; f < 0 -- Enterprise's fault */ | |
130 | { | |
131 | register struct quad *q; | |
132 | register struct event *e; | |
133 | register char *name; | |
06d69904 | 134 | char *systemname(); |
060604f0 KM |
135 | |
136 | if (f) | |
137 | { | |
138 | /* current quadrant */ | |
139 | q = &Quad[Ship.quadx][Ship.quady]; | |
140 | Sect[x][y] = EMPTY; | |
141 | name = systemname(q); | |
142 | if (name == 0) | |
143 | return; | |
144 | printf("Inhabited starsystem %s at %d,%d destroyed\n", | |
145 | name, x, y); | |
146 | if (f < 0) | |
06d69904 | 147 | Game.killinhab += 1; |
060604f0 KM |
148 | } |
149 | else | |
150 | { | |
151 | /* different quadrant */ | |
152 | q = &Quad[x][y]; | |
153 | } | |
06d69904 | 154 | if (q->qsystemname & Q_DISTRESSED) |
060604f0 KM |
155 | { |
156 | /* distressed starsystem */ | |
06d69904 | 157 | e = &Event[q->qsystemname & Q_SYSTEM]; |
060604f0 KM |
158 | printf("Distress call for %s invalidated\n", |
159 | Systemname[e->systemname]); | |
160 | unschedule(e); | |
161 | } | |
06d69904 KL |
162 | q->qsystemname = 0; |
163 | q->stars -= 1; | |
060604f0 KM |
164 | } |
165 | ||
166 | ||
167 | /** | |
168 | ** "kill" a distress call | |
169 | **/ | |
170 | ||
171 | killd(x, y, f) | |
172 | int x, y; /* quadrant coordinates */ | |
173 | int f; /* set if user is to be informed */ | |
174 | { | |
175 | register struct event *e; | |
176 | register int i; | |
177 | register struct quad *q; | |
178 | ||
179 | q = &Quad[x][y]; | |
180 | for (i = 0; i < MAXEVENTS; i++) | |
181 | { | |
182 | e = &Event[i]; | |
183 | if (e->x != x || e->y != y) | |
184 | continue; | |
185 | switch (e->evcode) | |
186 | { | |
187 | case E_KDESB: | |
188 | if (f) | |
189 | { | |
190 | printf("Distress call for starbase in %d,%d nullified\n", | |
191 | x, y); | |
192 | unschedule(e); | |
193 | } | |
194 | break; | |
195 | ||
196 | case E_ENSLV: | |
197 | case E_REPRO: | |
198 | if (f) | |
199 | { | |
200 | printf("Distress call for %s in quadrant %d,%d nullified\n", | |
201 | Systemname[e->systemname], x, y); | |
06d69904 | 202 | q->qsystemname = e->systemname; |
060604f0 KM |
203 | unschedule(e); |
204 | } | |
205 | else | |
206 | { | |
06d69904 | 207 | e->evcode |= E_GHOST; |
060604f0 KM |
208 | } |
209 | } | |
210 | } | |
211 | } |