Fix two typos
[dragonfly.git] / games / trek / kill.c
blob870bb13b83f717c984281b1fc356fece3d23dc63
1 /*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
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.
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.
33 * @(#)kill.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/trek/kill.c,v 1.4 1999/11/30 03:49:49 billf Exp $
35 * $DragonFly: src/games/trek/kill.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
38 # include "trek.h"
41 ** KILL KILL KILL !!!
43 ** This file handles the killing off of almost anything.
47 ** Handle a Klingon's death
49 ** The Klingon at the sector given by the parameters is killed
50 ** and removed from the Klingon list. Notice that it is not
51 ** removed from the event list; this is done later, when the
52 ** the event is to be caught. Also, the time left is recomputed,
53 ** and the game is won if that was the last klingon.
56 void
57 killk(int ix, int iy)
59 int i;
61 printf(" *** Klingon at %d,%d destroyed ***\n", ix, iy);
63 /* remove the scoundrel */
64 Now.klings -= 1;
65 Sect[ix][iy] = EMPTY;
66 Quad[Ship.quadx][Ship.quady].klings -= 1;
67 /* %%% IS THIS SAFE???? %%% */
68 Quad[Ship.quadx][Ship.quady].scanned -= 100;
69 Game.killk += 1;
71 /* find the Klingon in the Klingon list */
72 for (i = 0; i < Etc.nkling; i++)
73 if (ix == Etc.klingon[i].x && iy == Etc.klingon[i].y)
75 /* purge him from the list */
76 Etc.nkling -= 1;
77 for (; i < Etc.nkling; i++)
78 bmove(&Etc.klingon[i+1], &Etc.klingon[i], sizeof Etc.klingon[i]);
79 break;
82 /* find out if that was the last one */
83 if (Now.klings <= 0)
84 win();
86 /* recompute time left */
87 Now.time = Now.resource / Now.klings;
88 return;
93 ** handle a starbase's death
96 void
97 killb(int qx, int qy)
99 struct quad *q;
100 struct xy *b;
102 q = &Quad[qx][qy];
104 if (q->bases <= 0)
105 return;
106 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;
115 q->bases = 0;
116 Now.bases -= 1;
117 for (b = Now.base; ; b++)
118 if (qx == b->x && qy == b->y)
119 break;
120 bmove(&Now.base[Now.bases], b, sizeof *b);
121 if (qx == Ship.quadx && qy == Ship.quady)
123 Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY;
124 if (Ship.cond == DOCKED)
125 undock(0);
126 printf("Starbase at %d,%d destroyed\n", Etc.starbase.x, Etc.starbase.y);
128 else
130 if (!damaged(SSRADIO))
132 printf("Uhura: Starfleet command reports that the starbase in\n");
133 printf(" quadrant %d,%d has been destroyed\n", qx, qy);
135 else
136 schedule(E_KATSB | E_GHOST, 1e50, qx, qy, 0);
142 ** kill an inhabited starsystem
145 void
146 kills(int x, int y, int f)
147 /* x,y: quad coords if f == 0, else sector coords */
148 /* f != 0 -- this quad; f < 0 -- Enterprise's fault */
150 struct quad *q;
151 struct event *e;
152 const char *name;
154 if (f)
156 /* current quadrant */
157 q = &Quad[Ship.quadx][Ship.quady];
158 Sect[x][y] = EMPTY;
159 name = systemname(q);
160 if (name == 0)
161 return;
162 printf("Inhabited starsystem %s at %d,%d destroyed\n",
163 name, x, y);
164 if (f < 0)
165 Game.killinhab += 1;
167 else
169 /* different quadrant */
170 q = &Quad[x][y];
172 if (q->qsystemname & Q_DISTRESSED)
174 /* distressed starsystem */
175 e = &Event[q->qsystemname & Q_SYSTEM];
176 printf("Distress call for %s invalidated\n",
177 Systemname[e->systemname]);
178 unschedule(e);
180 q->qsystemname = 0;
181 q->stars -= 1;
186 ** "kill" a distress call
189 void
190 killd(int x, int y, int f)
191 /* x,y: quadrant coordinates */
192 /* f: set if user is to be informed */
194 struct event *e;
195 int i;
196 struct quad *q;
198 q = &Quad[x][y];
199 for (i = 0; i < MAXEVENTS; i++)
201 e = &Event[i];
202 if (e->x != x || e->y != y)
203 continue;
204 switch (e->evcode)
206 case E_KDESB:
207 if (f)
209 printf("Distress call for starbase in %d,%d nullified\n",
210 x, y);
211 unschedule(e);
213 break;
215 case E_ENSLV:
216 case E_REPRO:
217 if (f)
219 printf("Distress call for %s in quadrant %d,%d nullified\n",
220 Systemname[e->systemname], x, y);
221 q->qsystemname = e->systemname;
222 unschedule(e);
224 else
226 e->evcode |= E_GHOST;