xref: /csrg-svn/games/trek/capture.c (revision 60857)
121266Sdist /*
2*60857Sbostic  * Copyright (c) 1980, 1993
3*60857Sbostic  *	The Regents of the University of California.  All rights reserved.
434205Sbostic  *
542605Sbostic  * %sccs.include.redist.c%
621266Sdist  */
721266Sdist 
811659Smckusick #ifndef lint
9*60857Sbostic static char sccsid[] = "@(#)capture.c	8.1 (Berkeley) 05/31/93";
1034205Sbostic #endif /* not lint */
1111659Smckusick 
1211659Smckusick # include	"trek.h"
1311659Smckusick 
1411659Smckusick /*
1511659Smckusick **  Ask a Klingon To Surrender
1611659Smckusick **
1711659Smckusick **	(Fat chance)
1811659Smckusick **
1911659Smckusick **	The Subspace Radio is needed to ask a Klingon if he will kindly
2011659Smckusick **	surrender.  A random Klingon from the ones in the quadrant is
2111659Smckusick **	chosen.
2211659Smckusick **
2311659Smckusick **	The Klingon is requested to surrender.  The probability of this
2411659Smckusick **	is a function of that Klingon's remaining power, our power,
2511659Smckusick **	etc.
2611659Smckusick */
2711659Smckusick 
capture()2811659Smckusick capture()
2911659Smckusick {
3011659Smckusick 	register int		i;
3111659Smckusick 	register struct kling	*k;
3212737Slayer 	double			x;
3311659Smckusick 	extern struct kling	*selectklingon();
3411659Smckusick 
3511659Smckusick 	/* check for not cloaked */
3611659Smckusick 	if (Ship.cloaked)
3711659Smckusick 	{
3811659Smckusick 		printf("Ship-ship communications out when cloaked\n");
3911659Smckusick 		return;
4011659Smckusick 	}
4111659Smckusick 	if (damaged(SSRADIO))
4211659Smckusick 		return (out(SSRADIO));
4311659Smckusick 	/* find out if there are any at all */
4411659Smckusick 	if (Etc.nkling <= 0)
4511659Smckusick 	{
4611659Smckusick 		printf("Uhura: Getting no response, sir\n");
4711659Smckusick 		return;
4811659Smckusick 	}
4911659Smckusick 
5011659Smckusick 	/* if there is more than one Klingon, find out which one */
5111659Smckusick 	k = selectklingon();
5211659Smckusick 	Move.free = 0;
5311659Smckusick 	Move.time = 0.05;
5411659Smckusick 
5511659Smckusick 	/* check out that Klingon */
5611659Smckusick 	k->srndreq++;
5711659Smckusick 	x = Param.klingpwr;
5812344Slayer 	x *= Ship.energy;
5912344Slayer 	x /= k->power * Etc.nkling;
6012344Slayer 	x *= Param.srndrprob;
6111659Smckusick 	i = x;
6211659Smckusick #	ifdef xTRACE
6311659Smckusick 	if (Trace)
6411659Smckusick 		printf("Prob = %d (%.4f)\n", i, x);
6511659Smckusick #	endif
6611659Smckusick 	if (i > ranf(100))
6711659Smckusick 	{
6811659Smckusick 		/* guess what, he surrendered!!! */
6911659Smckusick 		printf("Klingon at %d,%d surrenders\n", k->x, k->y);
7011659Smckusick 		i = ranf(Param.klingcrew);
7112737Slayer 		if ( i > 0 )
7212737Slayer 			printf("%d klingons commit suicide rather than be taken captive\n", Param.klingcrew - i);
7311659Smckusick 		if (i > Ship.brigfree)
7411659Smckusick 			i = Ship.brigfree;
7512344Slayer 		Ship.brigfree -= i;
7611659Smckusick 		printf("%d captives taken\n", i);
7711659Smckusick 		killk(k->x, k->y);
7811659Smckusick 		return;
7911659Smckusick 	}
8011659Smckusick 
8111659Smckusick 	/* big surprise, he refuses to surrender */
8211659Smckusick 	printf("Fat chance, captain\n");
8311659Smckusick 	return;
8411659Smckusick }
8511659Smckusick 
8611659Smckusick 
8711659Smckusick /*
8811659Smckusick **  SELECT A KLINGON
8911659Smckusick **
9011659Smckusick **	Cruddy, just takes one at random.  Should ask the captain.
9111659Smckusick */
9211659Smckusick 
selectklingon()9311659Smckusick struct kling	*selectklingon()
9411659Smckusick {
9511659Smckusick 	register int		i;
9611659Smckusick 
9711659Smckusick 	if (Etc.nkling < 2)
9811659Smckusick 		i = 0;
9911659Smckusick 	else
10011659Smckusick 		i = ranf(Etc.nkling);
10111659Smckusick 	return (&Etc.klingon[i]);
10211659Smckusick }
103