Skip to content

Commit

Permalink
Add GetAvailableSlots API
Browse files Browse the repository at this point in the history
  • Loading branch information
rurounijones committed Jul 24, 2022
1 parent 32e7c21 commit 3c463bb
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added `SimulationFps` event that is fired every second and contains simulation fps information since the last event (i.e. for the past ~1sec).
- Added `GetSessionId` API
- Added `GetAvaliableSlots` API

## [0.6.0] - 2022-05-30

Expand Down
2 changes: 1 addition & 1 deletion STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ should use their independent logging and tracing functions.
- [ ] `getRealTime`
- [ ] `getMissionOptions`
- [ ] `getAvailableCoalitions`
- [ ] `getAvailableSlots`
- [x] `getAvailableSlots`
- [ ] `getCurrentMission`
- [x] `getMissionName`
- [x] `getMissionDescription`
Expand Down
56 changes: 56 additions & 0 deletions lua/DCS-gRPC/methods/hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,59 @@ GRPC.methods.getUnitType = function(params)

return GRPC.success({type = unit_type})
end

GRPC.methods.getAvailableSlotDetails = function()
local redForSlots = DCS.getAvailableSlots('red')
local blueForSlots = DCS.getAvailableSlots('blue')
local slots = {}

for _, gameSlot in ipairs(redForSlots) do
local exportSlot = {
unitId = gameSlot.unitId,
type = gameSlot.type,
role = gameSlot.role,
groupName = gameSlot.groupName,
groupSize = gameSlot.groupSize,
coalition = 1 + 1, -- Increment for non zero-indexed gRPC enum
task = gameSlot.task,
onboardNumber = gameSlot.onboard_num,
}

if gameSlot.airdromeId ~= nil then
exportSlot.airdromeId = gameSlot.airdromeId
end

if gameSlot.helipadUnitType ~= nil then
exportSlot.helipadUnitType = gameSlot.helipadUnitType
exportSlot.helipadName = gameSlot.helipadName
end

table.insert(slots, exportSlot)
end

for _, gameSlot in ipairs(blueForSlots) do
local exportSlot = {
unitId = gameSlot.unitId,
type = gameSlot.type,
role = gameSlot.role,
groupName = gameSlot.groupName,
groupSize = gameSlot.groupSize,
coalition = 2 + 1, -- Increment for non zero-indexed gRPC enum
task = gameSlot.task,
onboardNumber = gameSlot.onboard_num,
}

if gameSlot.airdromeId ~= nil then
exportSlot.airdromeId = gameSlot.airdromeId
end

if gameSlot.helipadUnitType ~= nil then
exportSlot.helipadUnitType = gameSlot.helipadUnitType
exportSlot.helipadName = gameSlot.helipadName
end

table.insert(slots, exportSlot)
end

return GRPC.success({slots = slots})
end
41 changes: 41 additions & 0 deletions protos/dcs/hook/v0/hook.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
syntax = "proto3";
package dcs.hook.v0;
import "dcs/common/v0/common.proto";
option csharp_namespace = "RurouniJones.Dcs.Grpc.V0.Hook";
option go_package = "github.com/DCS-gRPC/go-bindings/dcs/v0/hook";

Expand Down Expand Up @@ -65,6 +66,10 @@ service HookService {

// https://wiki.hoggitworld.com/view/DCS_func_getUnitType
rpc GetUnitType(GetUnitTypeRequest) returns (GetUnitTypeResponse) {}

// Should only be called once per session until ED implement dynamic spawning
// https://wiki.hoggitworld.com/view/DCS_func_getAvailableSlots
rpc GetAvailableSlotDetails(GetAvailableSlotDetailsRequest) returns (GetAvailableSlotDetailsResponse) {}
}

message GetMissionNameRequest {
Expand Down Expand Up @@ -215,3 +220,39 @@ message GetUnitTypeResponse {
// Type of unit (e.g. "F-14B")
string type = 1;
}

message GetAvailableSlotDetailsRequest {
}

message GetAvailableSlotDetailsResponse {
repeated AvailableSlotDetails slots = 1;
}

message AvailableSlotDetails {
// the unitId of the slot. For multi-crew it is two strings
// joined by an underscore for non-pilot slots.
string unitId = 1;
// The aiframe type associated with the slot
string type = 2;
// The place number of the slot on an aircraft
string multicrew_place = 3;
// The role of the slot (Pilot, Radar Intercept Officer etc.)
string role = 4;
// The group name associated with the slot
string groupName = 6;
// The size of the group associated with the slot
string group_size = 7;
// The task of the slot (CAP, CAS, SEAD etc.)
string task = 8;
// Coalition associated with the slot
dcs.common.v0.Coalition coalition = 9;
// Visual Number of the aircaft (e.g. MODEX on US aircraft).
// String to preserve leading zeroes
string onboard_number = 10;
// The ID of the airdrome associated with the slot, if any.
optional int32 airdrome_id = 11;
// The type of the unit that owns the helipad associated with this slot, if any.
optional string helipad_unit_type = 12;
// The name of the unit that owns the helipad associated with this slot, if any.
optional string helipad_unit_name = 13;
}
8 changes: 8 additions & 0 deletions src/rpc/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,12 @@ impl HookService for HookRpc {
let res = self.request("getUnitType", request).await?;
Ok(Response::new(res))
}

async fn get_available_slot_details(
&self,
request: Request<hook::v0::GetAvailableSlotDetailsRequest>,
) -> Result<Response<hook::v0::GetAvailableSlotDetailsResponse>, Status> {
let res = self.request("getAvailableSlotDetails", request).await?;
Ok(Response::new(res))
}
}

0 comments on commit 3c463bb

Please sign in to comment.