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