Skip to content

Commit

Permalink
Add initial AddGroup implementation
Browse files Browse the repository at this point in the history
So far this implementation will create a ground group with a number of
ground units and return null in the gRPC response for some reason.

Many options are still hardcoded but what is currently implemented is
enough to spawn a static SAM site such as a NASAM site and have it
act as expected.
  • Loading branch information
rurounijones committed Nov 12, 2021
1 parent 77811dc commit 0a91865
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 102 deletions.
115 changes: 113 additions & 2 deletions lua/methods/coalitions.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,122 @@
--
-- RPC unit actions
-- RPC coalition actions
-- https://wiki.hoggitworld.com/view/DCS_singleton_coalition
--

local GRPC = GRPC
local coalition = coalition

local skill = {
[0] = "Random",
[1] = "Average",
[2] = "Good",
[3] = "High",
[4] = "Excellent",
[5] = "Player",
Random = 0,
Average = 1,
Good = 2,
High = 3,
Excellent = 4,
Player = 5
}

--local altitudeType = {
-- [1] = "BARO",
-- [2] = "RADIO",
-- BARO = 1,
-- RADIO = 2
--}

local createGroundUnitsTemplate = function(unitListTemplate)
local units = {}

for _, unitTemplate in pairs(unitListTemplate) do
local pos = coord.LLtoLO(unitTemplate.position.lat, unitTemplate.position.lon)
local unit = {
name = unitTemplate.name,
type = unitTemplate.type,
x = pos.x,
y = pos.z,
transportable = { randomTransportable = false },
skill = skill[unitTemplate.skill],
heading = unitTemplate.heading,
playerCanDrive = true
}
table.insert(units, unit)
end

return units
end

local createGroundGroupTemplate = function(groupTemplate)
local pos = coord.LLtoLO(groupTemplate.position.lat, groupTemplate.position.lon)

local groupTable = {
name = groupTemplate.name,
route = {
spans = {},
points = {
{
x = pos.x,
y = pos.z,
type = "Turning Point",
eta = 0,
eta_locked = true,
alt_type = "BARO",
formation_template = "",
speed = 0,
action = "Off Road",
task = {
id = "ComboTask",
params = {
tasks = {}
}
}
}
}
},
task = "Ground Nothing",
taskSelected = true,
tasks = {},
uncontrollable = false,
units = createGroundUnitsTemplate(groupTemplate.units),
visible = false,
x = pos.x,
y = pos.z
}

if groupTemplate.group_id ~= nil then
groupTable['groupId'] = groupTemplate.group_id
end
if groupTemplate.hidden ~= nil then
groupTable['hidden'] = groupTemplate.hidden
end
if groupTemplate.late_activation ~= nil then
groupTable['lateActivation'] = groupTemplate.late_activation
end
if groupTemplate.start_time ~= nil and groupTemplate.start_time > 0 then
groupTable['start_time'] = groupTemplate.start_time
end
if groupTemplate.visible ~= nil then
groupTable['visible'] = groupTemplate.visible
end

return groupTable
end

GRPC.methods.addGroup = function(params)
if params.country_id == 0 or params.country_id == 15 then
return GRPC.errorInvalidArgument("invalid country code")
end

local template = createGroundGroupTemplate(params.template.groundTemplate)

coalition.addGroup(params.country - 1, params.groupCategory, template) -- Decrement for non zero-indexed gRPC enum

return GRPC.success({group = GRPC.exporters.group(Group.getByName(template.name))})
end

GRPC.methods.getGroups = function(params)
local result = {}
for _, c in pairs(coalition.side) do
Expand All @@ -24,7 +135,7 @@ end

-- This method should be called once per coalition per mission so using COALITION_ALL to save 2
-- API calls is not worth the extra code.
GRPC.methods.getMainReferencePoint = function(params)
GRPC.methods.getBullseye = function(params)
if params.coalition == 0 then
return GRPC.errorInvalidArgument("a specific coalition must be chosen")
end
Expand Down
98 changes: 93 additions & 5 deletions protos/dcs/coalition/v0/coalition.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,113 @@ import "dcs/common/v0/common.proto";

// https://wiki.hoggitworld.com/view/DCS_singleton_coalition
service CoalitionService {
// https://wiki.hoggitworld.com/view/DCS_func_addGroup
rpc AddGroup(AddGroupRequest) returns (AddGroupResponse) {}

// https://wiki.hoggitworld.com/view/DCS_func_getGroups
rpc GetGroups(GetGroupsRequest) returns (GetGroupsResponse) {}

/*
* Get the Main Reference Point ("Bullseye") for the coalition
* Get the Bullseye for the coalition
*
* This position is set at mission start and does not change for the duration
* of the mission.
*
* See https://wiki.hoggitworld.com/view/DCS_func_getMainRefPoint for more
* details
*/
rpc GetMainReferencePoint(GetMainReferencePointRequest)
returns (GetMainReferencePointResponse) {}
rpc GetBullseye(GetBullseyeRequest)
returns (GetBullseyeResponse) {}

// https://wiki.hoggitworld.com/view/DCS_func_getPlayers
rpc GetPlayers(GetPlayersRequest) returns (GetPlayersResponse) {}
}

message AddGroupRequest {
// The coalition is determined by the provided Country
// and the coalition setup of the mission
dcs.common.v0.Country country = 2;
dcs.common.v0.GroupCategory group_category = 3;
oneof template {
GroundGroupTemplate ground_template = 4;
ShipGroupTemplate ship_template = 5;
HelicopterGroupTemplate helicopter_template = 6;
PlaneGroupTemplate plane_template = 7;
}

message GroundGroupTemplate {
optional uint32 group_id = 1;
bool hidden = 2;
bool late_activation = 3;
string name = 4;
dcs.common.v0.Position position = 5;
repeated Point route = 6;
uint32 start_time = 7;
string task = 8;
bool task_selected = 9;
repeated Task tasks = 10;
bool uncontrollable = 11;
repeated GroundUnitTemplate units = 12;
bool visible = 13;
}
message GroundUnitTemplate {
string name = 1;
string type = 2;
dcs.common.v0.Position position = 3;
optional uint32 unit_id = 4;
optional uint32 heading = 5;
Skill skill = 6;
}

message ShipGroupTemplate {}
message ShipUnitTemplate {}

message HelicopterGroupTemplate {}
message HelicopterUnitTemplate {}

message PlaneGroupTemplate {}
message PlaneUnitTemplate {}

message Point {
enum AltitudeType {
ALTITUDE_TYPE_UNSPECIFIED = 0;
ALTITUDE_TYPE_BAROMETRIC = 1;
ALTITUDE_TYPE_RADIO = 2;
}

enum Type {
TYPE_UNSPECIFIED = 0;
TAKEOFF = 1;
TAKEOFF_PARKING = 2;
TURNING_POINT = 3;
TAKEOFF_PARKING_HOT = 4;
LAND = 5;
}

dcs.common.v0.Position position = 1;
AltitudeType altitude_type = 2;
Type type = 3;
string action = 4;
string form = 5;
double speed = 6;
}

enum Skill {
SKILL_RANDOM = 0;
SKILL_AVERAGE = 1;
SKILL_GOOD = 2;
SKILL_HIGH = 3;
SKILL_EXCELLENT = 4;
SKILL_PLAYER = 5;
}

message Task{}
}

message AddGroupResponse {
dcs.common.v0.Group group = 1;
}

message GetGroupsRequest {
dcs.common.v0.Coalition coalition = 1;
optional dcs.common.v0.GroupCategory category = 2;
Expand All @@ -32,13 +120,13 @@ message GetGroupsResponse {
repeated dcs.common.v0.Group groups = 1;
}

message GetMainReferencePointRequest {
message GetBullseyeRequest {
// A specific coalition must be used for this API call. Do not use
// `COALITION_ALL`
dcs.common.v0.Coalition coalition = 1;
}

message GetMainReferencePointResponse {
message GetBullseyeResponse {
dcs.common.v0.Position position = 1;
}

Expand Down
Loading

0 comments on commit 0a91865

Please sign in to comment.