xref: /netbsd-src/games/trek/shield.c (revision da121b333149705fd908f272187095dff6b9353c)
1*da121b33Sdholland /*	$NetBSD: shield.c,v 1.13 2009/08/12 08:54:54 dholland Exp $	*/
2887dd216Scgd 
361f28255Scgd /*
4887dd216Scgd  * Copyright (c) 1980, 1993
5887dd216Scgd  *	The Regents of the University of California.  All rights reserved.
661f28255Scgd  *
761f28255Scgd  * Redistribution and use in source and binary forms, with or without
861f28255Scgd  * modification, are permitted provided that the following conditions
961f28255Scgd  * are met:
1061f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1261f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1461f28255Scgd  *    documentation and/or other materials provided with the distribution.
15e5aeb4eaSagc  * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd  *    may be used to endorse or promote products derived from this software
1761f28255Scgd  *    without specific prior written permission.
1861f28255Scgd  *
1961f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd  * SUCH DAMAGE.
3061f28255Scgd  */
3161f28255Scgd 
32ef383c95Schristos #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
34887dd216Scgd #if 0
35887dd216Scgd static char sccsid[] = "@(#)shield.c	8.1 (Berkeley) 5/31/93";
36887dd216Scgd #else
37*da121b33Sdholland __RCSID("$NetBSD: shield.c,v 1.13 2009/08/12 08:54:54 dholland Exp $");
38887dd216Scgd #endif
3961f28255Scgd #endif /* not lint */
4061f28255Scgd 
41ef383c95Schristos #include <stdio.h>
4261f28255Scgd #include "trek.h"
4361f28255Scgd #include "getpar.h"
4461f28255Scgd 
4561f28255Scgd /*
4661f28255Scgd **  SHIELD AND CLOAKING DEVICE CONTROL
4761f28255Scgd **
4861f28255Scgd **	'f' is one for auto shield up (in case of Condition RED),
4961f28255Scgd **	zero for shield control, and negative one for cloaking
5061f28255Scgd **	device control.
5161f28255Scgd **
5261f28255Scgd **	Called with an 'up' or 'down' on the same line, it puts
5361f28255Scgd **	the shields/cloak into the specified mode.  Otherwise it
5461f28255Scgd **	reports to the user the current mode, and asks if she wishes
5561f28255Scgd **	to change.
5661f28255Scgd **
5761f28255Scgd **	This is not a free move.  Hits that occur as a result of
5861f28255Scgd **	this move appear as though the shields are half up/down,
5961f28255Scgd **	so you get partial hits.
6061f28255Scgd */
6161f28255Scgd 
62*da121b33Sdholland static const struct cvntab Udtab[] = {
63ef383c95Schristos 	{ "u",		"p",		(cmdfun)1,	0 },
64ef383c95Schristos 	{ "d",		"own",		(cmdfun)0,	0 },
65ef383c95Schristos 	{ NULL,		NULL,		NULL,		0 }
6661f28255Scgd };
6761f28255Scgd 
68ef383c95Schristos void
shield(int f)69bf0917b6Sdholland shield(int f)
7061f28255Scgd {
71ef383c95Schristos 	int		i;
72b7e11e5cShubertf 	const struct cvntab	*r;
7361f28255Scgd 	char		s[100];
74b7e11e5cShubertf 	const char	*device, *dev2, *dev3;
7561f28255Scgd 	int		ind;
7661f28255Scgd 	char		*stat;
7761f28255Scgd 
7861f28255Scgd 	if (f > 0 && (Ship.shldup || damaged(SRSCAN)))
7961f28255Scgd 		return;
8050b862e2Sdholland 	if (f < 0) {
8161f28255Scgd 		/* cloaking device */
82ef383c95Schristos 		if (Ship.ship == QUEENE) {
8361357867Sdholland 			printf("Ye Faire Queene does not have the "
8461357867Sdholland 			       "cloaking device.\n");
85ef383c95Schristos 			return;
86ef383c95Schristos 		}
8761f28255Scgd 		device = "Cloaking device";
8861f28255Scgd 		dev2 = "is";
8961f28255Scgd 		ind = CLOAK;
9061f28255Scgd 		dev3 = "it";
9161f28255Scgd 		stat = &Ship.cloaked;
9250b862e2Sdholland 	} else {
9361f28255Scgd 		/* shields */
9461f28255Scgd 		device = "Shields";
9561f28255Scgd 		dev2 = "are";
9661f28255Scgd 		dev3 = "them";
9761f28255Scgd 		ind = SHIELD;
9861f28255Scgd 		stat = &Ship.shldup;
9961f28255Scgd 	}
10050b862e2Sdholland 	if (damaged(ind)) {
10161f28255Scgd 		if (f <= 0)
10261f28255Scgd 			out(ind);
10361f28255Scgd 		return;
10461f28255Scgd 	}
10550b862e2Sdholland 	if (Ship.cond == DOCKED) {
10661f28255Scgd 		printf("%s %s down while docked\n", device, dev2);
10761f28255Scgd 		return;
10861f28255Scgd 	}
10950b862e2Sdholland 	if (f <= 0 && !testnl()) {
11061f28255Scgd 		r = getcodpar("Up or down", Udtab);
111c4816c32Scgd 		i = (long) r->value;
11250b862e2Sdholland 	} else {
11361f28255Scgd 		if (*stat)
11496ebfddfSdholland 			(void)snprintf(s, sizeof(s),
11596ebfddfSdholland 				"%s %s up.  Do you want %s down",
11661357867Sdholland 				device, dev2, dev3);
11761f28255Scgd 		else
11896ebfddfSdholland 			(void)snprintf(s, sizeof(s),
11996ebfddfSdholland 				"%s %s down.  Do you want %s up",
12061357867Sdholland 				device, dev2, dev3);
12161f28255Scgd 		if (!getynpar(s))
12261f28255Scgd 			return;
12361f28255Scgd 		i = !*stat;
12461f28255Scgd 	}
12550b862e2Sdholland 	if (*stat == i) {
12661f28255Scgd 		printf("%s already ", device);
12761f28255Scgd 		if (i)
12861f28255Scgd 			printf("up\n");
12961f28255Scgd 		else
13061f28255Scgd 			printf("down\n");
13161f28255Scgd 		return;
13261f28255Scgd 	}
13304afeca6Sveego 	if (i) {
13461f28255Scgd 		if (f >= 0)
13561f28255Scgd 			Ship.energy -= Param.shupengy;
13661f28255Scgd 		else
13761f28255Scgd 			Ship.cloakgood = 0;
13804afeca6Sveego 	}
13961f28255Scgd 	Move.free = 0;
14061f28255Scgd 	if (f >= 0)
14161f28255Scgd 		Move.shldchg = 1;
14261f28255Scgd 	*stat = i;
14361f28255Scgd 	return;
14461f28255Scgd }
145