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