xref: /netbsd/games/trek/shield.c (revision bf9ec67e)
1 /*	$NetBSD: shield.c,v 1.7 1999/07/21 13:19:11 hubertf 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[] = "@(#)shield.c	8.1 (Berkeley) 5/31/93";
40 #else
41 __RCSID("$NetBSD: shield.c,v 1.7 1999/07/21 13:19:11 hubertf Exp $");
42 #endif
43 #endif /* not lint */
44 
45 #include <stdio.h>
46 #include "trek.h"
47 #include "getpar.h"
48 
49 /*
50 **  SHIELD AND CLOAKING DEVICE CONTROL
51 **
52 **	'f' is one for auto shield up (in case of Condition RED),
53 **	zero for shield control, and negative one for cloaking
54 **	device control.
55 **
56 **	Called with an 'up' or 'down' on the same line, it puts
57 **	the shields/cloak into the specified mode.  Otherwise it
58 **	reports to the user the current mode, and asks if she wishes
59 **	to change.
60 **
61 **	This is not a free move.  Hits that occur as a result of
62 **	this move appear as though the shields are half up/down,
63 **	so you get partial hits.
64 */
65 
66 const struct cvntab Udtab[] =
67 {
68 	{ "u",		"p",		(cmdfun)1,	0 },
69 	{ "d",		"own",		(cmdfun)0,	0 },
70 	{ NULL,		NULL,		NULL,		0 }
71 };
72 
73 void
74 shield(f)
75 int	f;
76 {
77 	int		i;
78 	const struct cvntab	*r;
79 	char		s[100];
80 	const char	*device, *dev2, *dev3;
81 	int		ind;
82 	char		*stat;
83 
84 	if (f > 0 && (Ship.shldup || damaged(SRSCAN)))
85 		return;
86 	if (f < 0)
87 	{
88 		/* cloaking device */
89 		if (Ship.ship == QUEENE) {
90 			printf("Ye Faire Queene does not have the cloaking device.\n");
91 			return;
92 		}
93 		device = "Cloaking device";
94 		dev2 = "is";
95 		ind = CLOAK;
96 		dev3 = "it";
97 		stat = &Ship.cloaked;
98 	}
99 	else
100 	{
101 		/* shields */
102 		device = "Shields";
103 		dev2 = "are";
104 		dev3 = "them";
105 		ind = SHIELD;
106 		stat = &Ship.shldup;
107 	}
108 	if (damaged(ind))
109 	{
110 		if (f <= 0)
111 			out(ind);
112 		return;
113 	}
114 	if (Ship.cond == DOCKED)
115 	{
116 		printf("%s %s down while docked\n", device, dev2);
117 		return;
118 	}
119 	if (f <= 0 && !testnl())
120 	{
121 		r = getcodpar("Up or down", Udtab);
122 		i = (long) r->value;
123 	}
124 	else
125 	{
126 		if (*stat)
127 			(void)sprintf(s, "%s %s up.  Do you want %s down", device, dev2, dev3);
128 		else
129 			(void)sprintf(s, "%s %s down.  Do you want %s up", device, dev2, dev3);
130 		if (!getynpar(s))
131 			return;
132 		i = !*stat;
133 	}
134 	if (*stat == i)
135 	{
136 		printf("%s already ", device);
137 		if (i)
138 			printf("up\n");
139 		else
140 			printf("down\n");
141 		return;
142 	}
143 	if (i) {
144 		if (f >= 0)
145 			Ship.energy -= Param.shupengy;
146 		else
147 			Ship.cloakgood = 0;
148 	}
149 	Move.free = 0;
150 	if (f >= 0)
151 		Move.shldchg = 1;
152 	*stat = i;
153 	return;
154 }
155