Skip to content

Commit 3c463bb

Browse files
committed
Add GetAvailableSlots API
1 parent 32e7c21 commit 3c463bb

File tree

5 files changed

+107
-1
lines changed

5 files changed

+107
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Added
1313
- Added `SimulationFps` event that is fired every second and contains simulation fps information since the last event (i.e. for the past ~1sec).
1414
- Added `GetSessionId` API
15+
- Added `GetAvaliableSlots` API
1516

1617
## [0.6.0] - 2022-05-30
1718

STATUS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ should use their independent logging and tracing functions.
270270
- [ ] `getRealTime`
271271
- [ ] `getMissionOptions`
272272
- [ ] `getAvailableCoalitions`
273-
- [ ] `getAvailableSlots`
273+
- [x] `getAvailableSlots`
274274
- [ ] `getCurrentMission`
275275
- [x] `getMissionName`
276276
- [x] `getMissionDescription`

lua/DCS-gRPC/methods/hook.lua

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,59 @@ GRPC.methods.getUnitType = function(params)
118118

119119
return GRPC.success({type = unit_type})
120120
end
121+
122+
GRPC.methods.getAvailableSlotDetails = function()
123+
local redForSlots = DCS.getAvailableSlots('red')
124+
local blueForSlots = DCS.getAvailableSlots('blue')
125+
local slots = {}
126+
127+
for _, gameSlot in ipairs(redForSlots) do
128+
local exportSlot = {
129+
unitId = gameSlot.unitId,
130+
type = gameSlot.type,
131+
role = gameSlot.role,
132+
groupName = gameSlot.groupName,
133+
groupSize = gameSlot.groupSize,
134+
coalition = 1 + 1, -- Increment for non zero-indexed gRPC enum
135+
task = gameSlot.task,
136+
onboardNumber = gameSlot.onboard_num,
137+
}
138+
139+
if gameSlot.airdromeId ~= nil then
140+
exportSlot.airdromeId = gameSlot.airdromeId
141+
end
142+
143+
if gameSlot.helipadUnitType ~= nil then
144+
exportSlot.helipadUnitType = gameSlot.helipadUnitType
145+
exportSlot.helipadName = gameSlot.helipadName
146+
end
147+
148+
table.insert(slots, exportSlot)
149+
end
150+
151+
for _, gameSlot in ipairs(blueForSlots) do
152+
local exportSlot = {
153+
unitId = gameSlot.unitId,
154+
type = gameSlot.type,
155+
role = gameSlot.role,
156+
groupName = gameSlot.groupName,
157+
groupSize = gameSlot.groupSize,
158+
coalition = 2 + 1, -- Increment for non zero-indexed gRPC enum
159+
task = gameSlot.task,
160+
onboardNumber = gameSlot.onboard_num,
161+
}
162+
163+
if gameSlot.airdromeId ~= nil then
164+
exportSlot.airdromeId = gameSlot.airdromeId
165+
end
166+
167+
if gameSlot.helipadUnitType ~= nil then
168+
exportSlot.helipadUnitType = gameSlot.helipadUnitType
169+
exportSlot.helipadName = gameSlot.helipadName
170+
end
171+
172+
table.insert(slots, exportSlot)
173+
end
174+
175+
return GRPC.success({slots = slots})
176+
end

protos/dcs/hook/v0/hook.proto

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
syntax = "proto3";
22
package dcs.hook.v0;
3+
import "dcs/common/v0/common.proto";
34
option csharp_namespace = "RurouniJones.Dcs.Grpc.V0.Hook";
45
option go_package = "github.com/DCS-gRPC/go-bindings/dcs/v0/hook";
56

@@ -65,6 +66,10 @@ service HookService {
6566

6667
// https://wiki.hoggitworld.com/view/DCS_func_getUnitType
6768
rpc GetUnitType(GetUnitTypeRequest) returns (GetUnitTypeResponse) {}
69+
70+
// Should only be called once per session until ED implement dynamic spawning
71+
// https://wiki.hoggitworld.com/view/DCS_func_getAvailableSlots
72+
rpc GetAvailableSlotDetails(GetAvailableSlotDetailsRequest) returns (GetAvailableSlotDetailsResponse) {}
6873
}
6974

7075
message GetMissionNameRequest {
@@ -215,3 +220,39 @@ message GetUnitTypeResponse {
215220
// Type of unit (e.g. "F-14B")
216221
string type = 1;
217222
}
223+
224+
message GetAvailableSlotDetailsRequest {
225+
}
226+
227+
message GetAvailableSlotDetailsResponse {
228+
repeated AvailableSlotDetails slots = 1;
229+
}
230+
231+
message AvailableSlotDetails {
232+
// the unitId of the slot. For multi-crew it is two strings
233+
// joined by an underscore for non-pilot slots.
234+
string unitId = 1;
235+
// The aiframe type associated with the slot
236+
string type = 2;
237+
// The place number of the slot on an aircraft
238+
string multicrew_place = 3;
239+
// The role of the slot (Pilot, Radar Intercept Officer etc.)
240+
string role = 4;
241+
// The group name associated with the slot
242+
string groupName = 6;
243+
// The size of the group associated with the slot
244+
string group_size = 7;
245+
// The task of the slot (CAP, CAS, SEAD etc.)
246+
string task = 8;
247+
// Coalition associated with the slot
248+
dcs.common.v0.Coalition coalition = 9;
249+
// Visual Number of the aircaft (e.g. MODEX on US aircraft).
250+
// String to preserve leading zeroes
251+
string onboard_number = 10;
252+
// The ID of the airdrome associated with the slot, if any.
253+
optional int32 airdrome_id = 11;
254+
// The type of the unit that owns the helipad associated with this slot, if any.
255+
optional string helipad_unit_type = 12;
256+
// The name of the unit that owns the helipad associated with this slot, if any.
257+
optional string helipad_unit_name = 13;
258+
}

src/rpc/hook.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,12 @@ impl HookService for HookRpc {
144144
let res = self.request("getUnitType", request).await?;
145145
Ok(Response::new(res))
146146
}
147+
148+
async fn get_available_slot_details(
149+
&self,
150+
request: Request<hook::v0::GetAvailableSlotDetailsRequest>,
151+
) -> Result<Response<hook::v0::GetAvailableSlotDetailsResponse>, Status> {
152+
let res = self.request("getAvailableSlotDetails", request).await?;
153+
Ok(Response::new(res))
154+
}
147155
}

0 commit comments

Comments
 (0)