-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit.go
97 lines (90 loc) · 2.36 KB
/
unit.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
96
97
package micro
import (
"bitbucket.org/aisee/veterran/bot"
"github.com/aiseeq/s2l/lib/point"
"github.com/aiseeq/s2l/lib/scl"
"github.com/aiseeq/s2l/protocol/enums/ability"
"github.com/aiseeq/s2l/protocol/enums/buff"
"github.com/aiseeq/s2l/protocol/enums/terran"
"math/rand"
)
func DefaultRetreat(u *scl.Unit) bool {
if (u.Hits < u.HitsMax/2) || u.HasBuff(buff.RavenScramblerMissile) {
B.Groups.Add(bot.MechRetreat, u)
return true
}
return false
}
func DefaultManeuver(u *scl.Unit) bool {
if !u.IsCoolToAttack() {
attackers := B.Enemies.AllReady.CanAttack(u, 4)
if attackers.Exists() {
outranged, stronger := u.AssessStrength(attackers)
if outranged && stronger {
return false // Attack them
}
// Not outranged - we can safely fall back
// Or we are weaker - fall back (there should be no attack)
if scl.Ground(u) {
u.GroundFallback(B.Locs.MyStart - B.Locs.MyStartMinVec*3, false)
return true
} else {
target := u.TargetPos()
if target == 0 {
target = u.Point()
} else {
target = u.Point().Towards(target, 1)
}
pos, safe := u.AirEvade(attackers, 2, target)
if !safe {
u.CommandPos(ability.Move, pos)
return true
}
}
}
}
return u.EvadeEffects()
}
func DefaultAttack(u *scl.Unit) bool {
if Targets.All.Exists() {
u.Attack(Targets.Armed, Targets.All)
return true
}
return false
}
func GetDefensivePos(u *scl.Unit) point.Point {
pos := B.Ramps.My.Top
ccs := B.Units.My.OfType(B.U.UnitAliases.For(terran.CommandCenter)...).
FurtherThan(scl.ResourceSpreadDistance, B.Locs.MyStart)
if ccs.Exists() {
ccs.OrderByDistanceTo(B.Locs.MyStart, false)
pos = ccs[int(u.Tag)%ccs.Len()].Towards(B.Locs.MapCenter, 4)
}
return pos
}
func DefaultExplore(u *scl.Unit) bool {
if B.PlayDefensive {
if exps := B.Locs.MyExps[0:5].CloserThan(70, B.Locs.MyStart).Filter(func(pt point.Point) bool {
return !B.Grid.IsExplored(pt)
}); exps.Exists() {
pos := exps.ClosestTo(u)
u.CommandPos(ability.Move, pos)
return true
}
pos := GetDefensivePos(u)
if u.IsFarFrom(pos) {
u.CommandPos(ability.Move, pos)
}
return true
}
if !B.Grid.IsExplored(B.Locs.EnemyStart) {
u.CommandPos(ability.Attack, B.Locs.EnemyStart)
} else {
// Search for other bases
if u.IsIdle() {
pos := B.Locs.EnemyExps[rand.Intn(len(B.Locs.EnemyExps))]
u.CommandPos(ability.Move, pos)
}
}
return true
}