xref: /csrg-svn/games/trek/abandon.c (revision 60857)
121263Sdist /*
2*60857Sbostic  * Copyright (c) 1980, 1993
3*60857Sbostic  *	The Regents of the University of California.  All rights reserved.
434205Sbostic  *
542605Sbostic  * %sccs.include.redist.c%
621263Sdist  */
721263Sdist 
811656Smckusick #ifndef lint
9*60857Sbostic static char sccsid[] = "@(#)abandon.c	8.1 (Berkeley) 05/31/93";
1034205Sbostic #endif /* not lint */
1111656Smckusick 
1211656Smckusick # include	"trek.h"
1311656Smckusick 
1411656Smckusick /*
1511656Smckusick **  Abandon Ship
1611656Smckusick **
1711656Smckusick **	The ship is abandoned.  If your current ship is the Faire
1811656Smckusick **	Queene, or if your shuttlecraft is dead, you're out of
1911656Smckusick **	luck.  You need the shuttlecraft in order for the captain
2011656Smckusick **	(that's you!!) to escape.
2111656Smckusick **
2211656Smckusick **	Your crew can beam to an inhabited starsystem in the
2311656Smckusick **	quadrant, if there is one and if the transporter is working.
2411656Smckusick **	If there is no inhabited starsystem, or if the transporter
2511656Smckusick **	is out, they are left to die in outer space.
2611656Smckusick **
2711656Smckusick **	These currently just count as regular deaths, but they
2811656Smckusick **	should count very heavily against you.
2911656Smckusick **
3011656Smckusick **	If there are no starbases left, you are captured by the
3111656Smckusick **	Klingons, who torture you mercilessly.  However, if there
3211656Smckusick **	is at least one starbase, you are returned to the
3311656Smckusick **	Federation in a prisoner of war exchange.  Of course, this
3411656Smckusick **	can't happen unless you have taken some prisoners.
3511656Smckusick **
3611656Smckusick **	Uses trace flag 40
3711656Smckusick */
3811656Smckusick 
abandon()3911656Smckusick abandon()
4011656Smckusick {
4111656Smckusick 	register struct quad	*q;
4211656Smckusick 	register int		i;
4311656Smckusick 	int			j;
4411656Smckusick 	register struct event	*e;
4511656Smckusick 
4611656Smckusick 	if (Ship.ship == QUEENE)
4711656Smckusick 		return (printf("You may not abandon ye Faire Queene\n"));
4811656Smckusick 	if (Ship.cond != DOCKED)
4911656Smckusick 	{
5011656Smckusick 		if (damaged(SHUTTLE))
5111656Smckusick 			return (out(SHUTTLE));
5211656Smckusick 		printf("Officers escape in shuttlecraft\n");
5311656Smckusick 		/* decide on fate of crew */
5411656Smckusick 		q = &Quad[Ship.quadx][Ship.quady];
5512737Slayer 		if (q->qsystemname == 0 || damaged(XPORTER))
5611656Smckusick 		{
5711656Smckusick 			printf("Entire crew of %d left to die in outer space\n",
5811656Smckusick 				Ship.crew);
5912343Slayer 			Game.deaths += Ship.crew;
6011656Smckusick 		}
6111656Smckusick 		else
6211656Smckusick 		{
6311656Smckusick 			printf("Crew beams down to planet %s\n", systemname(q));
6411656Smckusick 		}
6511656Smckusick 	}
6611656Smckusick 	/* see if you can be exchanged */
6711656Smckusick 	if (Now.bases == 0 || Game.captives < 20 * Game.skill)
6811656Smckusick 		lose(L_CAPTURED);
6911656Smckusick 	/* re-outfit new ship */
7011656Smckusick 	printf("You are hereby put in charge of an antiquated but still\n");
7111656Smckusick 	printf("  functional ship, the Fairie Queene.\n");
7211656Smckusick 	Ship.ship = QUEENE;
7311656Smckusick 	Ship.shipname = "Fairie Queene";
7411656Smckusick 	Param.energy = Ship.energy = 3000;
7511656Smckusick 	Param.torped = Ship.torped = 6;
7611656Smckusick 	Param.shield = Ship.shield = 1250;
7711656Smckusick 	Ship.shldup = 0;
7811656Smckusick 	Ship.cloaked = 0;
7911656Smckusick 	Ship.warp = 5.0;
8011656Smckusick 	Ship.warp2 = 25.0;
8111656Smckusick 	Ship.warp3 = 125.0;
8211656Smckusick 	Ship.cond = GREEN;
8311656Smckusick 	/* clear out damages on old ship */
8411656Smckusick 	for (i = 0; i < MAXEVENTS; i++)
8511656Smckusick 	{
8611656Smckusick 		e = &Event[i];
8711656Smckusick 		if (e->evcode != E_FIXDV)
8811656Smckusick 			continue;
8911656Smckusick 		unschedule(e);
9011656Smckusick 	}
9111656Smckusick 	/* get rid of some devices and redistribute probabilities */
9211656Smckusick 	i = Param.damprob[SHUTTLE] + Param.damprob[CLOAK];
9311656Smckusick 	Param.damprob[SHUTTLE] = Param.damprob[CLOAK] = 0;
9411656Smckusick 	while (i > 0)
9511656Smckusick 		for (j = 0; j < NDEV; j++)
9611656Smckusick 		{
9711656Smckusick 			if (Param.damprob[j] != 0)
9811656Smckusick 			{
9912343Slayer 				Param.damprob[j] += 1;
10012737Slayer 				i--;
10111656Smckusick 				if (i <= 0)
10211656Smckusick 					break;
10311656Smckusick 			}
10411656Smckusick 		}
10511656Smckusick 	/* pick a starbase to restart at */
10611656Smckusick 	i = ranf(Now.bases);
10711656Smckusick 	Ship.quadx = Now.base[i].x;
10811656Smckusick 	Ship.quady = Now.base[i].y;
10911656Smckusick 	/* setup that quadrant */
11011656Smckusick 	while (1)
11111656Smckusick 	{
11211656Smckusick 		initquad(1);
11311656Smckusick 		Sect[Ship.sectx][Ship.secty] = EMPTY;
11411656Smckusick 		for (i = 0; i < 5; i++)
11511656Smckusick 		{
11611656Smckusick 			Ship.sectx = Etc.starbase.x + ranf(3) - 1;
11711656Smckusick 			if (Ship.sectx < 0 || Ship.sectx >= NSECTS)
11811656Smckusick 				continue;
11911656Smckusick 			Ship.secty = Etc.starbase.y + ranf(3) - 1;
12011656Smckusick 			if (Ship.secty < 0 || Ship.secty >= NSECTS)
12111656Smckusick 				continue;
12211656Smckusick 			if (Sect[Ship.sectx][Ship.secty] == EMPTY)
12311656Smckusick 			{
12411656Smckusick 				Sect[Ship.sectx][Ship.secty] = QUEENE;
12511656Smckusick 				dock();
12611656Smckusick 				compkldist(0);
12711656Smckusick 				return;
12811656Smckusick 			}
12911656Smckusick 		}
13011656Smckusick 	}
13111656Smckusick }
132