xref: /csrg-svn/games/trek/kill.c (revision 60857)
125992Smckusick /*
2*60857Sbostic  * Copyright (c) 1980, 1993
3*60857Sbostic  *	The Regents of the University of California.  All rights reserved.
434205Sbostic  *
542606Sbostic  * %sccs.include.redist.c%
625992Smckusick  */
725992Smckusick 
811679Smckusick #ifndef lint
9*60857Sbostic static char sccsid[] = "@(#)kill.c	8.1 (Berkeley) 05/31/93";
1034205Sbostic #endif /* not lint */
1111679Smckusick 
1211679Smckusick # include	"trek.h"
1311679Smckusick 
1411679Smckusick /*
1511679Smckusick **  KILL KILL KILL !!!
1611679Smckusick **
1711679Smckusick **	This file handles the killing off of almost anything.
1811679Smckusick */
1911679Smckusick 
2011679Smckusick /*
2111679Smckusick **  Handle a Klingon's death
2211679Smckusick **
2311679Smckusick **	The Klingon at the sector given by the parameters is killed
2411679Smckusick **	and removed from the Klingon list.  Notice that it is not
2511679Smckusick **	removed from the event list; this is done later, when the
2611679Smckusick **	the event is to be caught.  Also, the time left is recomputed,
2711679Smckusick **	and the game is won if that was the last klingon.
2811679Smckusick */
2911679Smckusick 
killk(ix,iy)3011679Smckusick killk(ix, iy)
3111679Smckusick int	ix, iy;
3211679Smckusick {
3311679Smckusick 	register int		i, j;
3411679Smckusick 
3511679Smckusick 	printf("   *** Klingon at %d,%d destroyed ***\n", ix, iy);
3611679Smckusick 
3711679Smckusick 	/* remove the scoundrel */
3812738Slayer 	Now.klings -= 1;
3911679Smckusick 	Sect[ix][iy] = EMPTY;
4012738Slayer 	Quad[Ship.quadx][Ship.quady].klings -= 1;
4111679Smckusick 	/* %%% IS THIS SAFE???? %%% */
4212738Slayer 	Quad[Ship.quadx][Ship.quady].scanned -= 100;
4312738Slayer 	Game.killk += 1;
4411679Smckusick 
4511679Smckusick 	/* find the Klingon in the Klingon list */
4611679Smckusick 	for (i = 0; i < Etc.nkling; i++)
4711679Smckusick 		if (ix == Etc.klingon[i].x && iy == Etc.klingon[i].y)
4811679Smckusick 		{
4911679Smckusick 			/* purge him from the list */
5012738Slayer 			Etc.nkling -= 1;
5111679Smckusick 			for (; i < Etc.nkling; i++)
5211679Smckusick 				bmove(&Etc.klingon[i+1], &Etc.klingon[i], sizeof Etc.klingon[i]);
5311679Smckusick 			break;
5411679Smckusick 		}
5511679Smckusick 
5611679Smckusick 	/* find out if that was the last one */
5711679Smckusick 	if (Now.klings <= 0)
5811679Smckusick 		win();
5911679Smckusick 
6011679Smckusick 	/* recompute time left */
6111679Smckusick 	Now.time = Now.resource / Now.klings;
6211679Smckusick 	return;
6311679Smckusick }
6411679Smckusick 
6511679Smckusick 
6611679Smckusick /*
6711679Smckusick **  handle a starbase's death
6811679Smckusick */
6911679Smckusick 
killb(qx,qy)7011679Smckusick killb(qx, qy)
7111679Smckusick int	qx, qy;
7211679Smckusick {
7311679Smckusick 	register struct quad	*q;
7411679Smckusick 	register struct xy	*b;
7511679Smckusick 
7611679Smckusick 	q = &Quad[qx][qy];
7711679Smckusick 
7811679Smckusick 	if (q->bases <= 0)
7911679Smckusick 		return;
8011679Smckusick 	if (!damaged(SSRADIO))
8111679Smckusick 		/* then update starchart */
8211679Smckusick 		if (q->scanned < 1000)
8312738Slayer 			q->scanned -= 10;
8411679Smckusick 		else
8511679Smckusick 			if (q->scanned > 1000)
8611679Smckusick 				q->scanned = -1;
8711679Smckusick 	q->bases = 0;
8812738Slayer 	Now.bases -= 1;
8911679Smckusick 	for (b = Now.base; ; b++)
9011679Smckusick 		if (qx == b->x && qy == b->y)
9111679Smckusick 			break;
9211679Smckusick 	bmove(&Now.base[Now.bases], b, sizeof *b);
9311679Smckusick 	if (qx == Ship.quadx && qy == Ship.quady)
9411679Smckusick 	{
9511679Smckusick 		Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY;
9611679Smckusick 		if (Ship.cond == DOCKED)
9711679Smckusick 			undock();
9811679Smckusick 		printf("Starbase at %d,%d destroyed\n", Etc.starbase.x, Etc.starbase.y);
9911679Smckusick 	}
10011679Smckusick 	else
10111679Smckusick 	{
10211679Smckusick 		if (!damaged(SSRADIO))
10311679Smckusick 		{
10411679Smckusick 			printf("Uhura: Starfleet command reports that the starbase in\n");
10511679Smckusick 			printf("   quadrant %d,%d has been destroyed\n", qx, qy);
10611679Smckusick 		}
10711679Smckusick 		else
10811679Smckusick 			schedule(E_KATSB | E_GHOST, 1e50, qx, qy, 0);
10911679Smckusick 	}
11011679Smckusick }
11111679Smckusick 
11211679Smckusick 
11311679Smckusick /**
11411679Smckusick  **	kill an inhabited starsystem
11511679Smckusick  **/
11611679Smckusick 
kills(x,y,f)11711679Smckusick kills(x, y, f)
11811679Smckusick int	x, y;	/* quad coords if f == 0, else sector coords */
11911679Smckusick int	f;	/* f != 0 -- this quad;  f < 0 -- Enterprise's fault */
12011679Smckusick {
12111679Smckusick 	register struct quad	*q;
12211679Smckusick 	register struct event	*e;
12311679Smckusick 	register char		*name;
12412738Slayer 	char			*systemname();
12511679Smckusick 
12611679Smckusick 	if (f)
12711679Smckusick 	{
12811679Smckusick 		/* current quadrant */
12911679Smckusick 		q = &Quad[Ship.quadx][Ship.quady];
13011679Smckusick 		Sect[x][y] = EMPTY;
13111679Smckusick 		name = systemname(q);
13211679Smckusick 		if (name == 0)
13311679Smckusick 			return;
13411679Smckusick 		printf("Inhabited starsystem %s at %d,%d destroyed\n",
13511679Smckusick 			name, x, y);
13611679Smckusick 		if (f < 0)
13712738Slayer 			Game.killinhab += 1;
13811679Smckusick 	}
13911679Smckusick 	else
14011679Smckusick 	{
14111679Smckusick 		/* different quadrant */
14211679Smckusick 		q = &Quad[x][y];
14311679Smckusick 	}
14412738Slayer 	if (q->qsystemname & Q_DISTRESSED)
14511679Smckusick 	{
14611679Smckusick 		/* distressed starsystem */
14712738Slayer 		e = &Event[q->qsystemname & Q_SYSTEM];
14811679Smckusick 		printf("Distress call for %s invalidated\n",
14911679Smckusick 			Systemname[e->systemname]);
15011679Smckusick 		unschedule(e);
15111679Smckusick 	}
15212738Slayer 	q->qsystemname = 0;
15312738Slayer 	q->stars -= 1;
15411679Smckusick }
15511679Smckusick 
15611679Smckusick 
15711679Smckusick /**
15811679Smckusick  **	"kill" a distress call
15911679Smckusick  **/
16011679Smckusick 
killd(x,y,f)16111679Smckusick killd(x, y, f)
16211679Smckusick int	x, y;		/* quadrant coordinates */
16311679Smckusick int	f;		/* set if user is to be informed */
16411679Smckusick {
16511679Smckusick 	register struct event	*e;
16611679Smckusick 	register int		i;
16711679Smckusick 	register struct quad	*q;
16811679Smckusick 
16911679Smckusick 	q = &Quad[x][y];
17011679Smckusick 	for (i = 0; i < MAXEVENTS; i++)
17111679Smckusick 	{
17211679Smckusick 		e = &Event[i];
17311679Smckusick 		if (e->x != x || e->y != y)
17411679Smckusick 			continue;
17511679Smckusick 		switch (e->evcode)
17611679Smckusick 		{
17711679Smckusick 		  case E_KDESB:
17811679Smckusick 			if (f)
17911679Smckusick 			{
18011679Smckusick 				printf("Distress call for starbase in %d,%d nullified\n",
18111679Smckusick 					x, y);
18211679Smckusick 				unschedule(e);
18311679Smckusick 			}
18411679Smckusick 			break;
18511679Smckusick 
18611679Smckusick 		  case E_ENSLV:
18711679Smckusick 		  case E_REPRO:
18811679Smckusick 			if (f)
18911679Smckusick 			{
19011679Smckusick 				printf("Distress call for %s in quadrant %d,%d nullified\n",
19111679Smckusick 					Systemname[e->systemname], x, y);
19212738Slayer 				q->qsystemname = e->systemname;
19311679Smckusick 				unschedule(e);
19411679Smckusick 			}
19511679Smckusick 			else
19611679Smckusick 			{
19712738Slayer 				e->evcode |= E_GHOST;
19811679Smckusick 			}
19911679Smckusick 		}
20011679Smckusick 	}
20111679Smckusick }
202