xref: /original-bsd/games/trek/initquad.c (revision c829ecf6)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)initquad.c	5.4 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 # include	"trek.h"
13 
14 /*
15 **  Paramize Quadrant Upon Entering
16 **
17 **	A quadrant is initialized from the information held in the
18 **	Quad matrix.  Basically, everything is just initialized
19 **	randomly, except for the starship, which goes into a fixed
20 **	sector.
21 **
22 **	If there are Klingons in the quadrant, the captain is informed
23 **	that the condition is RED, and he is given a chance to put
24 **	his shields up if the computer is working.
25 **
26 **	The flag `f' is set to disable the check for condition red.
27 **	This mode is used in situations where you know you are going
28 **	to be docked, i.e., abandon() and help().
29 */
30 
31 initquad(f)
32 int	f;
33 {
34 	register int		i, j;
35 	int			rx, ry;
36 	int			nbases, nstars;
37 	register struct quad	*q;
38 	int			nholes;
39 
40 	q = &Quad[Ship.quadx][Ship.quady];
41 
42 	/* ignored supernova'ed quadrants (this is checked again later anyway */
43 	if (q->stars < 0)
44 		return;
45 	Etc.nkling = q->klings;
46 	nbases = q->bases;
47 	nstars = q->stars;
48 	nholes = q->holes;
49 
50 	/* have we blundered into a battle zone w/ shields down? */
51 	if (Etc.nkling > 0 && !f)
52 	{
53 		printf("Condition RED\n");
54 		Ship.cond = RED;
55 		if (!damaged(COMPUTER))
56 			shield(1);
57 	}
58 
59 	/* clear out the quadrant */
60 	for (i = 0; i < NSECTS; i++)
61 		for (j = 0; j < NSECTS; j++)
62 			Sect[i][j] = EMPTY;
63 
64 	/* initialize Enterprise */
65 	Sect[Ship.sectx][Ship.secty] = Ship.ship;
66 
67 	/* initialize Klingons */
68 	for (i = 0; i < Etc.nkling; i++)
69 	{
70 		sector(&rx, &ry);
71 		Sect[rx][ry] = KLINGON;
72 		Etc.klingon[i].x = rx;
73 		Etc.klingon[i].y = ry;
74 		Etc.klingon[i].power = Param.klingpwr;
75 		Etc.klingon[i].srndreq = 0;
76 	}
77 	compkldist(1);
78 
79 	/* initialize star base */
80 	if (nbases > 0)
81 	{
82 		sector(&rx, &ry);
83 		Sect[rx][ry] = BASE;
84 		Etc.starbase.x = rx;
85 		Etc.starbase.y = ry;
86 	}
87 
88 	/* initialize inhabited starsystem */
89 	if (q->qsystemname != 0)
90 	{
91 		sector(&rx, &ry);
92 		Sect[rx][ry] = INHABIT;
93 		nstars -= 1;
94 	}
95 
96 	/* initialize black holes */
97 	for (i = 0; i < nholes; i++)
98 	{
99 		sector(&rx, &ry);
100 		Sect[rx][ry] = HOLE;
101 	}
102 
103 	/* initialize stars */
104 	for (i = 0; i < nstars; i++)
105 	{
106 		sector(&rx, &ry);
107 		Sect[rx][ry] = STAR;
108 	}
109 	Move.newquad = 1;
110 }
111 
112 
113 sector(x, y)
114 int	*x, *y;
115 {
116 	register int		i, j;
117 
118 	do
119 	{
120 		i = ranf(NSECTS);
121 		j = ranf(NSECTS);
122 	} while (Sect[i][j] != EMPTY);
123 	*x = i;
124 	*y = j;
125 	return;
126 }
127