xref: /csrg-svn/games/trek/shield.c (revision 60859)
125995Smckusick /*
2*60859Sbostic  * Copyright (c) 1980, 1993
3*60859Sbostic  *	The Regents of the University of California.  All rights reserved.
434205Sbostic  *
542606Sbostic  * %sccs.include.redist.c%
625995Smckusick  */
725995Smckusick 
811697Smckusick #ifndef lint
9*60859Sbostic static char sccsid[] = "@(#)shield.c	8.1 (Berkeley) 05/31/93";
1034205Sbostic #endif /* not lint */
1111697Smckusick 
1211697Smckusick # include	"trek.h"
1311697Smckusick # include	"getpar.h"
1411697Smckusick 
1511697Smckusick /*
1611697Smckusick **  SHIELD AND CLOAKING DEVICE CONTROL
1711697Smckusick **
1811697Smckusick **	'f' is one for auto shield up (in case of Condition RED),
1911697Smckusick **	zero for shield control, and negative one for cloaking
2011697Smckusick **	device control.
2111697Smckusick **
2211697Smckusick **	Called with an 'up' or 'down' on the same line, it puts
2311697Smckusick **	the shields/cloak into the specified mode.  Otherwise it
2411697Smckusick **	reports to the user the current mode, and asks if she wishes
2511697Smckusick **	to change.
2611697Smckusick **
2711697Smckusick **	This is not a free move.  Hits that occur as a result of
2811697Smckusick **	this move appear as though the shields are half up/down,
2911697Smckusick **	so you get partial hits.
3011697Smckusick */
3111697Smckusick 
3212798Slayer struct cvntab Udtab[] =
3311697Smckusick {
3412798Slayer 	"u",		"p",			(int (*)())1,		0,
3511697Smckusick 	"d",		"own",			0,		0,
3611697Smckusick 	0
3711697Smckusick };
3811697Smckusick 
shield(f)3911697Smckusick shield(f)
4011697Smckusick int	f;
4111697Smckusick {
4211697Smckusick 	register int		i;
4311697Smckusick 	char			c;
4411697Smckusick 	struct cvntab		*r;
4511697Smckusick 	char			s[100];
4611697Smckusick 	char			*device, *dev2, *dev3;
4711697Smckusick 	int			ind;
4811697Smckusick 	char			*stat;
4911697Smckusick 
5011697Smckusick 	if (f > 0 && (Ship.shldup || damaged(SRSCAN)))
5111697Smckusick 		return;
5211697Smckusick 	if (f < 0)
5311697Smckusick 	{
5411697Smckusick 		/* cloaking device */
5511697Smckusick 		if (Ship.ship == QUEENE)
5611697Smckusick 			return (printf("Ye Faire Queene does not have the cloaking device.\n"));
5711697Smckusick 		device = "Cloaking device";
5811697Smckusick 		dev2 = "is";
5911697Smckusick 		ind = CLOAK;
6011697Smckusick 		dev3 = "it";
6111697Smckusick 		stat = &Ship.cloaked;
6211697Smckusick 	}
6311697Smckusick 	else
6411697Smckusick 	{
6511697Smckusick 		/* shields */
6611697Smckusick 		device = "Shields";
6711697Smckusick 		dev2 = "are";
6811697Smckusick 		dev3 = "them";
6911697Smckusick 		ind = SHIELD;
7011697Smckusick 		stat = &Ship.shldup;
7111697Smckusick 	}
7211697Smckusick 	if (damaged(ind))
7311697Smckusick 	{
7411697Smckusick 		if (f <= 0)
7511697Smckusick 			out(ind);
7611697Smckusick 		return;
7711697Smckusick 	}
7811697Smckusick 	if (Ship.cond == DOCKED)
7911697Smckusick 	{
8011697Smckusick 		printf("%s %s down while docked\n", device, dev2);
8111697Smckusick 		return;
8211697Smckusick 	}
8311697Smckusick 	if (f <= 0 && !testnl())
8411697Smckusick 	{
8511697Smckusick 		r = getcodpar("Up or down", Udtab);
8612798Slayer 		i = (int) r->value;
8711697Smckusick 	}
8811697Smckusick 	else
8911697Smckusick 	{
9011697Smckusick 		if (*stat)
9132482Sbostic 			(void)sprintf(s, "%s %s up.  Do you want %s down", device, dev2, dev3);
9211697Smckusick 		else
9332482Sbostic 			(void)sprintf(s, "%s %s down.  Do you want %s up", device, dev2, dev3);
9411697Smckusick 		if (!getynpar(s))
9511697Smckusick 			return;
9611697Smckusick 		i = !*stat;
9711697Smckusick 	}
9811697Smckusick 	if (*stat == i)
9911697Smckusick 	{
10011697Smckusick 		printf("%s already ", device);
10111697Smckusick 		if (i)
10211697Smckusick 			printf("up\n");
10311697Smckusick 		else
10411697Smckusick 			printf("down\n");
10511697Smckusick 		return;
10611697Smckusick 	}
10711697Smckusick 	if (i)
10811697Smckusick 		if (f >= 0)
10912798Slayer 			Ship.energy -= Param.shupengy;
11011697Smckusick 		else
11111697Smckusick 			Ship.cloakgood = 0;
11211697Smckusick 	Move.free = 0;
11311697Smckusick 	if (f >= 0)
11411697Smckusick 		Move.shldchg = 1;
11511697Smckusick 	*stat = i;
11611697Smckusick 	return;
11711697Smckusick }
118