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