-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincome.go
46 lines (40 loc) · 1.09 KB
/
income.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
package main
import (
"github.com/jcgraybill/ship-shape/ship"
"github.com/jcgraybill/ship-shape/structure"
)
func (g *Game) collectIncome() {
if exists, cap := g.player.Capitol(); exists {
if cap.HasShips() {
var topOfferStructure *structure.Structure
var topOfferValue float64 = 0
for _, s := range g.player.Structures() {
if s.Income() > 0 {
var offerValue float64
x1, y1 := cap.Planet().Center()
x2, y2 := s.Planet().Center()
offerValue = float64(s.Income()) / distance(x1, y1, x2, y2)
if offerValue > topOfferValue {
shipAlreadyInLane := false
for _, ship := range g.player.Ships() {
_, origin, destination := ship.Manifest()
if (origin == cap && destination == s) ||
(origin == s && destination == cap) {
shipAlreadyInLane = true
}
}
if !shipAlreadyInLane {
topOfferStructure = s
topOfferValue = offerValue
}
}
}
}
if topOfferValue > 0 {
ship := ship.New(cap, topOfferStructure, ship.Income)
cap.LaunchShip(0)
g.player.Ships()[g.count] = ship
}
}
}
}