diff --git a/CHANGELOG.md b/CHANGELOG.md index 282e1926..c36d8386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/STATUS.md b/STATUS.md index 49d17bc7..1398effe 100644 --- a/STATUS.md +++ b/STATUS.md @@ -270,7 +270,7 @@ should use their independent logging and tracing functions. - [ ] `getRealTime` - [ ] `getMissionOptions` - [ ] `getAvailableCoalitions` -- [ ] `getAvailableSlots` +- [x] `getAvailableSlots` - [ ] `getCurrentMission` - [x] `getMissionName` - [x] `getMissionDescription` diff --git a/lua/DCS-gRPC/methods/hook.lua b/lua/DCS-gRPC/methods/hook.lua index eadc52db..14864bb8 100644 --- a/lua/DCS-gRPC/methods/hook.lua +++ b/lua/DCS-gRPC/methods/hook.lua @@ -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 diff --git a/protos/dcs/hook/v0/hook.proto b/protos/dcs/hook/v0/hook.proto index 7ca236bf..77be2a07 100644 --- a/protos/dcs/hook/v0/hook.proto +++ b/protos/dcs/hook/v0/hook.proto @@ -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"; @@ -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 { @@ -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 unit_ud = 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 group_name = 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; +} diff --git a/src/rpc/hook.rs b/src/rpc/hook.rs index 9a79ca98..7c689124 100644 --- a/src/rpc/hook.rs +++ b/src/rpc/hook.rs @@ -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, + ) -> Result, Status> { + let res = self.request("getAvailableSlotDetails", request).await?; + Ok(Response::new(res)) + } }