-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.nim
85 lines (80 loc) · 2.9 KB
/
actions.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
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
from analyze import WorldState
from groupcounter import GroupCounter
from utils import Point
from pbehavior import Action, PBRType, PBResult
from model.move import Move
proc actmove*(shift: Point, maxspeed: float64 = 0): Action
proc scale*(center: Point, factor, maxspeed: float64 = 0): Action
proc rotate*(center: Point, angle, maxspeed: float64 = 0): Action
proc nuke*(target: Point, vehicle: int64): Action
from model.action_type import ActionType
from model.vehicle_type import VehicleType
from enhanced import Group
from utils import Area
import macros
macro genSelectsNGroups(): untyped =
let names = [!"newSelection", !"addToSelection", !"deselect",
!"group", !"ungroup", !"disband"]
let actions = [ActionType.CLEAR_AND_SELECT,
ActionType.ADD_TO_SELECTION,
ActionType.DESELECT,
ActionType.ASSIGN,
ActionType.DISMISS,
ActionType.DISBAND]
result = newStmtList()
for i in 0..<names.len():
let name = names[i]
let action = newIntLitNode(actions[i].ord)
result.add quote do:
proc `name`*(group: Group): Action =
proc r(ws: WorldState, gc: var GroupCounter, m: var Move): PBResult =
m.action = `action`.ActionType
m.group = group.int32
PBResult(kind: PBRType.priority)
r
if i > 2: continue
result.add quote do:
proc `name`*(a: Area, vt: VehicleType = VehicleType.UNKNOWN): Action =
proc r(ws: WorldState, gc: var GroupCounter, m: var Move): PBResult =
m.action = `action`.ActionType
m.vehicleType = vt
m.left = a.left
m.right = a.right
m.top = a.top
m.bottom = a.bottom
PBResult(kind: PBRType.priority)
r
genSelectsNGroups()
proc actmove(shift: Point, maxspeed: float64 = 0): Action =
proc i_move(ws: WorldState, gc: var GroupCounter, m: var Move): PBResult =
m.action = ActionType.MOVE
m.x = shift.x
m.y = shift.y
m.maxspeed = maxspeed
PBResult(kind: PBRType.priority)
return imove
proc scale(center: Point, factor, maxspeed: float64 = 0): Action =
proc inner(ws: WorldState, gc: var GroupCounter, m: var Move): PBResult =
m.action = ActionType.SCALE
m.x = center.x
m.y = center.y
m.factor = factor
m.maxspeed = maxspeed
return inner
proc rotate(center: Point, angle, maxspeed: float64 = 0): Action =
proc inner(ws: WorldState, gc: var GroupCounter, m: var Move): PBResult =
m.action = ActionType.ROTATE
m.x = center.x
m.y = center.y
m.angle = angle
m.maxAngularSpeed = maxspeed
PBResult(kind: PBRType.priority)
return inner
proc nuke(target: Point, vehicle: int64): Action =
proc inner(ws: WorldState, gc: var GroupCounter, m: var Move): PBResult =
m.action = ActionType.TACTICAL_NUCLEAR_STRIKE
m.x = target.x
m.y = target.y
m.vehicleId = vehicle
PBResult(kind: PBRType.priority)
return inner