xref: /csrg-svn/games/trek/initquad.c (revision 60857)
121283Sdist /*
2*60857Sbostic  * Copyright (c) 1980, 1993
3*60857Sbostic  *	The Regents of the University of California.  All rights reserved.
434205Sbostic  *
542606Sbostic  * %sccs.include.redist.c%
621283Sdist  */
721283Sdist 
811678Smckusick #ifndef lint
9*60857Sbostic static char sccsid[] = "@(#)initquad.c	8.1 (Berkeley) 05/31/93";
1034205Sbostic #endif /* not lint */
1111678Smckusick 
1211678Smckusick # include	"trek.h"
1311678Smckusick 
1411678Smckusick /*
1511678Smckusick **  Paramize Quadrant Upon Entering
1611678Smckusick **
1711678Smckusick **	A quadrant is initialized from the information held in the
1811678Smckusick **	Quad matrix.  Basically, everything is just initialized
1911678Smckusick **	randomly, except for the starship, which goes into a fixed
2011678Smckusick **	sector.
2111678Smckusick **
2211678Smckusick **	If there are Klingons in the quadrant, the captain is informed
2311678Smckusick **	that the condition is RED, and he is given a chance to put
2411678Smckusick **	his shields up if the computer is working.
2511678Smckusick **
2611678Smckusick **	The flag `f' is set to disable the check for condition red.
2711678Smckusick **	This mode is used in situations where you know you are going
2811678Smckusick **	to be docked, i.e., abandon() and help().
2911678Smckusick */
3011678Smckusick 
initquad(f)3111678Smckusick initquad(f)
3211678Smckusick int	f;
3311678Smckusick {
3411678Smckusick 	register int		i, j;
3511678Smckusick 	int			rx, ry;
3611678Smckusick 	int			nbases, nstars;
3711678Smckusick 	register struct quad	*q;
3811678Smckusick 	int			nholes;
3911678Smckusick 
4011678Smckusick 	q = &Quad[Ship.quadx][Ship.quady];
4111678Smckusick 
4211678Smckusick 	/* ignored supernova'ed quadrants (this is checked again later anyway */
4311678Smckusick 	if (q->stars < 0)
4411678Smckusick 		return;
4511678Smckusick 	Etc.nkling = q->klings;
4611678Smckusick 	nbases = q->bases;
4711678Smckusick 	nstars = q->stars;
4811678Smckusick 	nholes = q->holes;
4911678Smckusick 
5011678Smckusick 	/* have we blundered into a battle zone w/ shields down? */
5111678Smckusick 	if (Etc.nkling > 0 && !f)
5211678Smckusick 	{
5311678Smckusick 		printf("Condition RED\n");
5411678Smckusick 		Ship.cond = RED;
5511678Smckusick 		if (!damaged(COMPUTER))
5611678Smckusick 			shield(1);
5711678Smckusick 	}
5811678Smckusick 
5911678Smckusick 	/* clear out the quadrant */
6011678Smckusick 	for (i = 0; i < NSECTS; i++)
6111678Smckusick 		for (j = 0; j < NSECTS; j++)
6211678Smckusick 			Sect[i][j] = EMPTY;
6311678Smckusick 
6411678Smckusick 	/* initialize Enterprise */
6511678Smckusick 	Sect[Ship.sectx][Ship.secty] = Ship.ship;
6611678Smckusick 
6711678Smckusick 	/* initialize Klingons */
6811678Smckusick 	for (i = 0; i < Etc.nkling; i++)
6911678Smckusick 	{
7011678Smckusick 		sector(&rx, &ry);
7111678Smckusick 		Sect[rx][ry] = KLINGON;
7211678Smckusick 		Etc.klingon[i].x = rx;
7311678Smckusick 		Etc.klingon[i].y = ry;
7411678Smckusick 		Etc.klingon[i].power = Param.klingpwr;
7511678Smckusick 		Etc.klingon[i].srndreq = 0;
7611678Smckusick 	}
7711678Smckusick 	compkldist(1);
7811678Smckusick 
7911678Smckusick 	/* initialize star base */
8011678Smckusick 	if (nbases > 0)
8111678Smckusick 	{
8211678Smckusick 		sector(&rx, &ry);
8311678Smckusick 		Sect[rx][ry] = BASE;
8411678Smckusick 		Etc.starbase.x = rx;
8511678Smckusick 		Etc.starbase.y = ry;
8611678Smckusick 	}
8711678Smckusick 
8811678Smckusick 	/* initialize inhabited starsystem */
8912738Slayer 	if (q->qsystemname != 0)
9011678Smckusick 	{
9111678Smckusick 		sector(&rx, &ry);
9211678Smckusick 		Sect[rx][ry] = INHABIT;
9312344Slayer 		nstars -= 1;
9411678Smckusick 	}
9511678Smckusick 
9611678Smckusick 	/* initialize black holes */
9711678Smckusick 	for (i = 0; i < nholes; i++)
9811678Smckusick 	{
9911678Smckusick 		sector(&rx, &ry);
10011678Smckusick 		Sect[rx][ry] = HOLE;
10111678Smckusick 	}
10211678Smckusick 
10311678Smckusick 	/* initialize stars */
10411678Smckusick 	for (i = 0; i < nstars; i++)
10511678Smckusick 	{
10611678Smckusick 		sector(&rx, &ry);
10711678Smckusick 		Sect[rx][ry] = STAR;
10811678Smckusick 	}
10911678Smckusick 	Move.newquad = 1;
11011678Smckusick }
11111678Smckusick 
11211678Smckusick 
sector(x,y)11311678Smckusick sector(x, y)
11411678Smckusick int	*x, *y;
11511678Smckusick {
11611678Smckusick 	register int		i, j;
11711678Smckusick 
11811678Smckusick 	do
11911678Smckusick 	{
12011678Smckusick 		i = ranf(NSECTS);
12111678Smckusick 		j = ranf(NSECTS);
12211678Smckusick 	} while (Sect[i][j] != EMPTY);
12311678Smckusick 	*x = i;
12411678Smckusick 	*y = j;
12511678Smckusick 	return;
12611678Smckusick }
127