/
helpers.go
46 lines (38 loc) · 1.21 KB
/
helpers.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 scl
import (
log "bitbucket.org/aisee/minilog"
"github.com/aiseeq/s2l/protocol/api"
)
func TimeToLoop(minutes, seconds int) int {
return int(float64(minutes*60+seconds) * FPS)
}
func (b *Bot) MyRace() api.Race {
return B.Info.PlayerInfo[B.Obs.PlayerCommon.PlayerId-1].RaceActual
}
func (b *Bot) CanBuy(ability api.AbilityID) bool {
cost, ok := b.U.AbilityCost[ability]
if !ok {
log.Warning("no cost for ability: ", ability)
}
return (cost.Minerals == 0 || b.Minerals >= cost.Minerals) &&
(cost.Vespene == 0 || b.Vespene >= cost.Vespene) &&
(cost.Food <= 0 || b.FoodLeft >= cost.Food)
}
func (b *Bot) DeductResources(aid api.AbilityID) {
cost := b.U.AbilityCost[aid]
b.Minerals -= cost.Minerals
b.Vespene -= cost.Vespene
if cost.Food > 0 {
b.FoodUsed += cost.Food
b.FoodLeft -= cost.Food
}
}
func (b *Bot) Pending(aid api.AbilityID) int {
return b.Units.My[b.U.AbilityUnit[aid]].Len() + b.Orders[aid]
}
func (b *Bot) PendingAliases(aid api.AbilityID) int {
return b.Units.My.OfType(b.U.UnitAliases.For(b.U.AbilityUnit[aid])...).Len() + b.Orders[aid]
}
func (b *Bot) CanBuild(aid api.AbilityID, limit, active int) bool {
return b.CanBuy(aid) && b.Pending(aid) < limit && b.Orders[aid] < active
}