-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyearly.go
41 lines (36 loc) · 963 Bytes
/
yearly.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
package main
import "github.com/jcgraybill/ship-shape/structure"
func (g *Game) structuresGenerateIncome() {
for _, s := range g.player.Structures() {
if s.Class() == structure.Residential {
s.GenerateIncome()
}
}
}
func (g *Game) payWorkers() {
for _, s := range g.player.Structures() {
g.player.RemoveMoney(uint(s.LaborCost()))
}
}
func (g *Game) distributeWorkers() {
for _, s := range g.player.Structures() {
s.AssignWorkers(0)
}
budget := g.player.Money()
for workersToAssign := g.player.Population(); workersToAssign > 0; {
workersAssigned := false
for _, s := range g.player.Structures() {
if s.ActiveWorkers() < s.WorkerCapacity() && workersToAssign > 0 && s.CanProduce() && !s.IsPaused() {
if budget >= s.WorkerCost() {
budget -= s.WorkerCost()
s.AssignWorkers(s.ActiveWorkers() + 1)
workersToAssign -= 1
workersAssigned = true
}
}
}
if !workersAssigned {
workersToAssign = 0
}
}
}