-
Notifications
You must be signed in to change notification settings - Fork 22
/
object.lua
134 lines (117 loc) · 3.68 KB
/
object.lua
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
--
-- Converts DCS tables in the Object hierarchy into tables suitable for
-- serialization into GRPC responses
-- Each exporter has an equivalent .proto Message defined and they must
-- be kept in sync
--
GRPC.exporters.position = function(pos)
local lat, lon, alt = coord.LOtoLL(pos)
return {
lat = lat,
lon = lon,
alt = alt,
u = pos.z,
v = pos.x,
}
end
GRPC.exporters.unit = function(unit)
return {
id = tonumber(unit:getID()),
name = unit:getName(),
callsign = unit:getCallsign(),
coalition = unit:getCoalition() + 1, -- Increment for non zero-indexed gRPC enum
type = unit:getTypeName(),
playerName = Unit.getPlayerName(unit),
group = GRPC.exporters.group(Unit.getGroup(unit)),
numberInGroup = unit:getNumber(),
rawTransform = GRPC.exporters.rawTransform(unit),
}
end
-- Data used to calculate position/orientation/velocity on the Rust side.
GRPC.exporters.rawTransform = function(object)
local p = object:getPosition()
local position = GRPC.exporters.position(p.p)
return {
position = position,
positionNorth = coord.LLtoLO(position.lat + 1, position.lon),
forward = p.x,
right = p.z,
up = p.y,
velocity = object:getVelocity(),
}
end
GRPC.exporters.group = function(group)
return {
id = tonumber(group:getID()),
name = group:getName(),
coalition = group:getCoalition() + 1, -- Increment for non zero-indexed gRPC enum
category = group:getCategory() + 1, -- Increment for non zero-indexed gRPC enum
}
end
GRPC.exporters.weapon = function(weapon)
return {
id = tonumber(weapon:getName()),
type = weapon:getTypeName(),
rawTransform = GRPC.exporters.rawTransform(weapon),
}
end
GRPC.exporters.static = function(static)
return {
id = tonumber(static:getID()),
type = static:getTypeName(),
name = static:getName(),
coalition = static:getCoalition() + 1, -- Increment for non zero-indexed gRPC enum
position = GRPC.exporters.position(static:getPoint()),
}
end
GRPC.exporters.airbase = function(airbase)
local a = {
name = airbase:getName(),
callsign = airbase:getCallsign(),
coalition = airbase:getCoalition() + 1, -- Increment for non zero-indexed gRPC enum
category = airbase:getDesc()['category'] + 1, -- Increment for non zero-indexed gRPC enum
displayName = airbase:getDesc()['displayName'],
position = GRPC.exporters.position(airbase:getPoint())
}
local unit = airbase:getUnit()
if unit then
a.unit = GRPC.exporters.unit(unit)
end
return a
end
GRPC.exporters.scenery = function(scenery)
return {
id = tonumber(scenery:getName()),
type = scenery:getTypeName(),
position = GRPC.exporters.position(scenery:getPoint()),
}
end
GRPC.exporters.cargo = function()
return {}
end
-- every object, even an unknown one, should at least have getName implemented as it is
-- in the base object of the hierarchy
-- https://wiki.hoggitworld.com/view/DCS_Class_Object
GRPC.exporters.unknown = function(object)
return {
name = tostring(object:getName()),
}
end
GRPC.exporters.markPanel = function(markPanel)
local mp = {
id = markPanel.idx,
time = markPanel.time,
text = markPanel.text,
position = GRPC.exporters.position(markPanel.pos),
}
if markPanel.initiator then
mp.initiator = GRPC.exporters.unit(markPanel.initiator)
end
if (markPanel.coalition >= 0 and markPanel.coalition <= 2) then
mp.coalition = markPanel.coalition + 1; -- Increment for non zero-indexed gRPC enum
end
if (markPanel.groupID > 0) then
mp.groupId = markPanel.groupID;
end
return mp
end