4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / games / trek / initquad.c
CommitLineData
b6f0a7e4 1/*
82daddb0
KB
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
e9fb6bea 4 *
b2e7427f 5 * %sccs.include.redist.c%
b6f0a7e4
DF
6 */
7
e28303e4 8#ifndef lint
82daddb0 9static char sccsid[] = "@(#)initquad.c 8.1 (Berkeley) %G%";
e9fb6bea 10#endif /* not lint */
e28303e4
KM
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
31initquad(f)
32int 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 */
06d69904 89 if (q->qsystemname != 0)
e28303e4
KM
90 {
91 sector(&rx, &ry);
92 Sect[rx][ry] = INHABIT;
35b95499 93 nstars -= 1;
e28303e4
KM
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
113sector(x, y)
114int *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}