xref: /csrg-svn/games/trek/shield.c (revision 34205)
125995Smckusick /*
225995Smckusick  * Copyright (c) 1980 Regents of the University of California.
3*34205Sbostic  * All rights reserved.
4*34205Sbostic  *
5*34205Sbostic  * Redistribution and use in source and binary forms are permitted
6*34205Sbostic  * provided that this notice is preserved and that due credit is given
7*34205Sbostic  * to the University of California at Berkeley. The name of the University
8*34205Sbostic  * may not be used to endorse or promote products derived from this
9*34205Sbostic  * software without specific prior written permission. This software
10*34205Sbostic  * is provided ``as is'' without express or implied warranty.
1125995Smckusick  */
1225995Smckusick 
1311697Smckusick #ifndef lint
14*34205Sbostic static char sccsid[] = "@(#)shield.c	5.3 (Berkeley) 05/05/88";
15*34205Sbostic #endif /* not lint */
1611697Smckusick 
1711697Smckusick # include	"trek.h"
1811697Smckusick # include	"getpar.h"
1911697Smckusick 
2011697Smckusick /*
2111697Smckusick **  SHIELD AND CLOAKING DEVICE CONTROL
2211697Smckusick **
2311697Smckusick **	'f' is one for auto shield up (in case of Condition RED),
2411697Smckusick **	zero for shield control, and negative one for cloaking
2511697Smckusick **	device control.
2611697Smckusick **
2711697Smckusick **	Called with an 'up' or 'down' on the same line, it puts
2811697Smckusick **	the shields/cloak into the specified mode.  Otherwise it
2911697Smckusick **	reports to the user the current mode, and asks if she wishes
3011697Smckusick **	to change.
3111697Smckusick **
3211697Smckusick **	This is not a free move.  Hits that occur as a result of
3311697Smckusick **	this move appear as though the shields are half up/down,
3411697Smckusick **	so you get partial hits.
3511697Smckusick */
3611697Smckusick 
3712798Slayer struct cvntab Udtab[] =
3811697Smckusick {
3912798Slayer 	"u",		"p",			(int (*)())1,		0,
4011697Smckusick 	"d",		"own",			0,		0,
4111697Smckusick 	0
4211697Smckusick };
4311697Smckusick 
4411697Smckusick shield(f)
4511697Smckusick int	f;
4611697Smckusick {
4711697Smckusick 	register int		i;
4811697Smckusick 	char			c;
4911697Smckusick 	struct cvntab		*r;
5011697Smckusick 	char			s[100];
5111697Smckusick 	char			*device, *dev2, *dev3;
5211697Smckusick 	int			ind;
5311697Smckusick 	char			*stat;
5411697Smckusick 
5511697Smckusick 	if (f > 0 && (Ship.shldup || damaged(SRSCAN)))
5611697Smckusick 		return;
5711697Smckusick 	if (f < 0)
5811697Smckusick 	{
5911697Smckusick 		/* cloaking device */
6011697Smckusick 		if (Ship.ship == QUEENE)
6111697Smckusick 			return (printf("Ye Faire Queene does not have the cloaking device.\n"));
6211697Smckusick 		device = "Cloaking device";
6311697Smckusick 		dev2 = "is";
6411697Smckusick 		ind = CLOAK;
6511697Smckusick 		dev3 = "it";
6611697Smckusick 		stat = &Ship.cloaked;
6711697Smckusick 	}
6811697Smckusick 	else
6911697Smckusick 	{
7011697Smckusick 		/* shields */
7111697Smckusick 		device = "Shields";
7211697Smckusick 		dev2 = "are";
7311697Smckusick 		dev3 = "them";
7411697Smckusick 		ind = SHIELD;
7511697Smckusick 		stat = &Ship.shldup;
7611697Smckusick 	}
7711697Smckusick 	if (damaged(ind))
7811697Smckusick 	{
7911697Smckusick 		if (f <= 0)
8011697Smckusick 			out(ind);
8111697Smckusick 		return;
8211697Smckusick 	}
8311697Smckusick 	if (Ship.cond == DOCKED)
8411697Smckusick 	{
8511697Smckusick 		printf("%s %s down while docked\n", device, dev2);
8611697Smckusick 		return;
8711697Smckusick 	}
8811697Smckusick 	if (f <= 0 && !testnl())
8911697Smckusick 	{
9011697Smckusick 		r = getcodpar("Up or down", Udtab);
9112798Slayer 		i = (int) r->value;
9211697Smckusick 	}
9311697Smckusick 	else
9411697Smckusick 	{
9511697Smckusick 		if (*stat)
9632482Sbostic 			(void)sprintf(s, "%s %s up.  Do you want %s down", device, dev2, dev3);
9711697Smckusick 		else
9832482Sbostic 			(void)sprintf(s, "%s %s down.  Do you want %s up", device, dev2, dev3);
9911697Smckusick 		if (!getynpar(s))
10011697Smckusick 			return;
10111697Smckusick 		i = !*stat;
10211697Smckusick 	}
10311697Smckusick 	if (*stat == i)
10411697Smckusick 	{
10511697Smckusick 		printf("%s already ", device);
10611697Smckusick 		if (i)
10711697Smckusick 			printf("up\n");
10811697Smckusick 		else
10911697Smckusick 			printf("down\n");
11011697Smckusick 		return;
11111697Smckusick 	}
11211697Smckusick 	if (i)
11311697Smckusick 		if (f >= 0)
11412798Slayer 			Ship.energy -= Param.shupengy;
11511697Smckusick 		else
11611697Smckusick 			Ship.cloakgood = 0;
11711697Smckusick 	Move.free = 0;
11811697Smckusick 	if (f >= 0)
11911697Smckusick 		Move.shldchg = 1;
12011697Smckusick 	*stat = i;
12111697Smckusick 	return;
12211697Smckusick }
123