-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnukealert.nim
49 lines (45 loc) · 1.67 KB
/
nukealert.nim
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
from behavior import Behavior
from enhanced import Group
proc initNukeAlert*(): Behavior
from analyze import WorldState, Players
from behavior import BehaviorStatus
from vehicles import resolve, toGroup
from utils import areaFromUnits, inArea, debug, getSqDistance
from formation_info import FormationInfo
from model.action_type import ActionType
from model.move import Move
proc initNukeAlert(): Behavior =
var silent = true
result.tick = proc (ws: WorldState, fi: FormationInfo): BehaviorStatus =
let enemy = ws.players[Players.enemy]
if enemy.nextNuclearStrikeTickIndex > 0:
let epicenter = (x: enemy.nextNuclearStrikeX, y: enemy.nextNuclearStrikeY)
let sqRad = ws.game.tacticalNuclearStrikeRadius *
ws.game.tacticalNuclearStrikeRadius
debug("Nuke detected in " & $epicenter)
let centerdistance = epicenter.getSqDistance(fi.center)
if centerdistance < sqRad:
debug("Nuke on me!")
return BehaviorStatus.act
for v in fi.vertices:
if v.distanceToCenter != 0:
let distance = epicenter.getSqDistance(v.point)
if distance < sqRad:
debug("Nuke on me!")
return BehaviorStatus.act
if silent:
# give other formation a tick to check if nuke on it
silent = false
return BehaviorStatus.hold
else:
silent = true
return BehaviorStatus.inactive
result.action = proc (ws: WorldState, fi: FormationInfo, m: var Move) =
let enemy = ws.players[Players.enemy]
m.action = ActionType.SCALE
m.x = enemy.nextNuclearStrikeX
m.y = enemy.nextNuclearStrikeY
m.factor = 10
debug("Scalling out")
result.reset = proc () =
discard