-
Notifications
You must be signed in to change notification settings - Fork 0
/
initquad.go
95 lines (78 loc) · 1.58 KB
/
initquad.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import "fmt"
func initquad(f int) {
var (
rx, ry int
nbases, nstars int
q *quadrant
nholes int
)
q = &quad[ship.quadx][ship.quady]
/* ignored supernova'ed quadrants (this is checked again later anyway */
if q.stars < 0 {
return
}
etc.nkling = q.klings
nbases = q.bases
nstars = q.stars
nholes = q.holes
/* have we blundered into a battle zone w/ shields down? */
if etc.nkling > 0 && f == 0 {
fmt.Printf("Condition RED\n")
ship.cond = RED
if !damaged(COMPUTER) {
shield(1)
}
}
/* clear out the quadrant */
for i := 0; i < NSECTS; i++ {
for j := 0; j < NSECTS; j++ {
sect[i][j] = EMPTY
}
}
/* initialize Enterprise */
sect[ship.sectx][ship.secty] = ship.ship
/* initialize Klingons */
for i := 0; i < etc.nkling; i++ {
rx, ry = sector()
sect[rx][ry] = KLINGON
etc.klingon[i].x = rx
etc.klingon[i].y = ry
etc.klingon[i].power = param.klingpwr
etc.klingon[i].srndreq = false
}
compkldist(true)
/* initialize star base */
if nbases > 0 {
rx, ry = sector()
sect[rx][ry] = BASE
etc.starbase.x = rx
etc.starbase.y = ry
}
/* initialize inhabited starsystem */
if q.qsystemname != 0 {
rx, ry = sector()
sect[rx][ry] = INHABIT
nstars -= 1
}
/* initialize black holes */
for i := 0; i < nholes; i++ {
rx, ry = sector()
sect[rx][ry] = HOLE
}
/* initialize stars */
for i := 0; i < nstars; i++ {
rx, ry = sector()
sect[rx][ry] = STAR
}
move.newquad = 1
}
func sector() (x, y int) {
for {
i := ranf(NSECTS)
j := ranf(NSECTS)
if sect[i][j] == EMPTY {
return i, j
}
}
}