-
Notifications
You must be signed in to change notification settings - Fork 0
/
medivac.go
82 lines (73 loc) · 2.14 KB
/
medivac.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
package micro
import (
"bitbucket.org/aisee/veterran/bot"
"github.com/aiseeq/s2l/lib/scl"
"github.com/aiseeq/s2l/protocol/enums/ability"
)
func MedivacsLogic(us scl.Units) {
if us.Empty() {
return
}
patients := append(B.Groups.Get(bot.Marines).Units, B.Groups.Get(bot.Marauders).Units...)
if patients.Empty() {
patients = B.Groups.Get(bot.Thors).Units
if patients.Empty() {
patients = B.Groups.Get(bot.Miners).Units
}
}
if patients.Empty() {
return
}
injured := patients.Filter(func(unit *scl.Unit) bool { return unit.Hits < unit.HitsMax })
injured.OrderBy(func(unit *scl.Unit) float64 { return unit.Hits / unit.HitsMax }, false)
enemiesCenter := B.Enemies.AllReady.Center()
if enemiesCenter == 0 {
enemiesCenter = B.Locs.EnemyStart
}
firstPatient := patients.ClosestTo(enemiesCenter)
for _, u := range us {
if DefaultRetreat(u) || u.EvadeEffects() {
continue
}
// quickfix: I don't know how medivac can grab thor while he is not in ThorEvacs group
if len(u.Passengers) > 0 {
u.CommandPos(ability.UnloadAllAt_Medivac, u)
continue
}
enemies := B.Enemies.AllReady.CanAttack(u, 2)
pos, safe := u.AirEvade(enemies, 2, u)
if !safe {
outranged, stronger := u.AssessStrength(enemies)
if !outranged || stronger {
safe = true
} else {
u.CommandPos(ability.Move, pos)
continue
}
}
// This should be most damaged unit
closeInjured := injured.CloserThan(float64(u.Radius)+4, u).First()
if closeInjured == nil {
closeInjured = injured.ClosestTo(u)
}
if u.Energy >= 5 && u.HasAbility(ability.Effect_Heal) && closeInjured != nil {
if closeInjured.IsFurtherThan(8, u) &&
u.HasAbility(ability.Effect_MedivacIgniteAfterburners) {
u.Command(ability.Effect_MedivacIgniteAfterburners)
// u.CommandTagQueue(ability.Effect_Heal, closeInjured.Tag)
} else {
u.CommandTag(ability.Effect_Heal, closeInjured.Tag)
}
continue
}
if closeInjured == nil {
closeInjured = firstPatient
}
pos, safe = u.AirEvade(B.Enemies.AllReady.CanAttack(u, 2), 2, closeInjured)
if !safe {
u.CommandPos(ability.Move, pos)
} else {
u.CommandTag(ability.Move, closeInjured.Tag)
}
}
}