xref: /netbsd/games/trek/capture.c (revision bf9ec67e)
1 /*	$NetBSD: capture.c,v 1.5 1999/09/08 21:45:32 jsm Exp $	*/
2 
3 /*
4  * Copyright (c) 1980, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)capture.c	8.1 (Berkeley) 5/31/93";
40 #else
41 __RCSID("$NetBSD: capture.c,v 1.5 1999/09/08 21:45:32 jsm Exp $");
42 #endif
43 #endif /* not lint */
44 
45 #include <stdio.h>
46 #include "trek.h"
47 
48 /*
49 **  Ask a Klingon To Surrender
50 **
51 **	(Fat chance)
52 **
53 **	The Subspace Radio is needed to ask a Klingon if he will kindly
54 **	surrender.  A random Klingon from the ones in the quadrant is
55 **	chosen.
56 **
57 **	The Klingon is requested to surrender.  The probability of this
58 **	is a function of that Klingon's remaining power, our power,
59 **	etc.
60 */
61 
62 /*ARGSUSED*/
63 void
64 capture(v)
65 	int v __attribute__((__unused__));
66 {
67 	int		i;
68 	struct kling	*k;
69 	double			x;
70 
71 	/* check for not cloaked */
72 	if (Ship.cloaked)
73 	{
74 		printf("Ship-ship communications out when cloaked\n");
75 		return;
76 	}
77 	if (damaged(SSRADIO)) {
78 		out(SSRADIO);
79 		return;
80 	}
81 	/* find out if there are any at all */
82 	if (Etc.nkling <= 0)
83 	{
84 		printf("Uhura: Getting no response, sir\n");
85 		return;
86 	}
87 
88 	/* if there is more than one Klingon, find out which one */
89 	k = selectklingon();
90 	Move.free = 0;
91 	Move.time = 0.05;
92 
93 	/* check out that Klingon */
94 	k->srndreq++;
95 	x = Param.klingpwr;
96 	x *= Ship.energy;
97 	x /= k->power * Etc.nkling;
98 	x *= Param.srndrprob;
99 	i = x;
100 #	ifdef xTRACE
101 	if (Trace)
102 		printf("Prob = %d (%.4f)\n", i, x);
103 #	endif
104 	if (i > ranf(100))
105 	{
106 		/* guess what, he surrendered!!! */
107 		printf("Klingon at %d,%d surrenders\n", k->x, k->y);
108 		i = ranf(Param.klingcrew);
109 		if ( i > 0 )
110 			printf("%d klingons commit suicide rather than be taken captive\n", Param.klingcrew - i);
111 		if (i > Ship.brigfree)
112 			i = Ship.brigfree;
113 		Ship.brigfree -= i;
114 		printf("%d captives taken\n", i);
115 		killk(k->x, k->y);
116 		return;
117 	}
118 
119 	/* big surprise, he refuses to surrender */
120 	printf("Fat chance, captain\n");
121 	return;
122 }
123 
124 
125 /*
126 **  SELECT A KLINGON
127 **
128 **	Cruddy, just takes one at random.  Should ask the captain.
129 */
130 
131 struct kling	*selectklingon()
132 {
133 	int		i;
134 
135 	if (Etc.nkling < 2)
136 		i = 0;
137 	else
138 		i = ranf(Etc.nkling);
139 	return (&Etc.klingon[i]);
140 }
141