Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Airplane Group Spawning #77

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ read_globals = {
"trigger",
"Unit",
"world",
"Airbase",
}
138 changes: 128 additions & 10 deletions lua/methods/coalitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,127 @@ local skill = {
Player = 5
}

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

local buildAirplanePoints = function(points)
local builtPoints = {}
for _, pointData in pairs(points) do
local pointVec3
if type(pointData.place) == "string" then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll think about if we can do this in a different way by having gRPC types. No need to change this for the moment, just an FYI.

If may be that we do not allow clients to specify anything other than a Lat/Lon/Alt point since the client can get the information on airfield locations and zones themselves and send us that data instead of making us find it server-side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On reflection I think we should only allow Lat/Lon/alt using the Position Protobuf message. Clients should be able to get all the information they need to be able to popualte this information themselves and it simplifies the lua a lot.

if Airbase.getByName(pointData.place) then
pointVec3 = Airbase.getByName(pointData.place):getPoint()
elseif trigger.misc.getZone(pointData.place) then
pointVec3 = trigger.misc.getZone(pointData.place).point
end
elseif type(pointData.place) == "table" then
pointVec3 = coord.LLtoLO(pointData.place.lat, pointData.place.lon)
end
builtPoints[#builtPoints+1] = {
alt = pointData.alt,
x = pointVec3.x,
y = pointVec3.z,
type = pointData.type,
eta = 0,
eta_locked = true,
alt_type = altitudeType[altitudeType.alt_type],
formation_template = "",
speed = pointData.speed,
action = pointData.action,
task = {
id = "ComboTask",
params = {
tasks = {}
}
}
}
end
-- here we ammend the first point to allow for spawns from airbases if it isn't an airspawn
if Airbase.getByName(points[1].place) then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again as an FYI this bit may change, but nothing to do yet.

if points[1].type ~= "Turning Point" and points[1].action ~= "Turning Point" then
local ab = Airbase.getByName(points[1].place)
local abId = Airbase.getID(ab)
local abCat = Airbase.getDesc(ab).category
if abCat == 0 then -- Airbase.Category.AIRDROME
builtPoints[1].airdromeId = abId
elseif abCat == 2 then -- Airbase.Category.HELIPAD
builtPoints[1].linkUnit = abId
builtPoints[1].helipadId = abId -- why its named helipad i dont know
end
end
end
return builtPoints
end

local createPlaneGroupUnitsTemplate = function(unitListTemplate)
local units = {}
for i, unitTemplate in pairs(unitListTemplate) do
local pointVec3
if type(unitListTemplate.place) == "string" then
if Airbase.getByName(unitListTemplate.place) then
pointVec3 = Airbase.getByName(unitListTemplate.place):getPoint()
elseif trigger.misc.getZone(unitListTemplate.place) then
pointVec3 = trigger.misc.getZone(unitListTemplate.place).point
end
elseif type(unitListTemplate.place) == "table" then
pointVec3 = coord.LLtoLO(unitListTemplate.place.lat, unitListTemplate.place.lon)
end
local fuel = Unit.getDescByName(unitListTemplate.type).fuelMassMax -- needed incase no payload table is applied
units[i] = {
name = unitTemplate.unitName, -- or unitTemplate.name.."-"..i
type = unitListTemplate.type,
x = pointVec3.x,
y = pointVec3.z,
alt = unitListTemplate.alt,
alt_type = altitudeType[unitTemplate.alt_type],
speed = unitListTemplate.speed,
payload = unitTemplate.payload or {
["pylons"] = {},
["fuel"] = fuel,
["flare"] = 0,
["chaff"] = 0,
["gun"] = 0,
},
parking = unitTemplate.parking or nil,
parking_id = unitTemplate.parking_id or nil,
callsign = unitTemplate.callsign or nil,
skill = skill[unitListTemplate.skill],
livery_id = unitTemplate.livery_id or nil,
}
end
return units
end

local createPlaneGroupTemplate = function(planeGroupTemplate)
local groupTable = {
name = planeGroupTemplate.groupName,
task = planeGroupTemplate.task,
route = {
points = buildAirplanePoints(planeGroupTemplate.points)
}
}
groupTable.units = createPlaneGroupUnitsTemplate(planeGroupTemplate.units)
if planeGroupTemplate.group_id ~= nil then
groupTable['groupId'] = planeGroupTemplate.group_id
end
if planeGroupTemplate.hidden ~= nil then
groupTable['hidden'] = planeGroupTemplate.hidden
end
if planeGroupTemplate.late_activation ~= nil then
groupTable['lateActivation'] = planeGroupTemplate.late_activation
end
if planeGroupTemplate.start_time ~= nil and planeGroupTemplate.start_time > 0 then
groupTable['start_time'] = planeGroupTemplate.start_time
end
if planeGroupTemplate.visible ~= nil then
groupTable['visible'] = planeGroupTemplate.visible
end
return groupTable
end

local createGroundUnitsTemplate = function(unitListTemplate)
local units = {}
Expand Down Expand Up @@ -109,9 +224,12 @@ 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)

local template
if params.template.type == "Airplane" then
template = createPlaneGroupTemplate(params.template.airplaneTemplate)
elseif params.template.type == "Ground" then
template = createGroundGroupTemplate(params.template.groundTemplate)
end
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))})
Expand Down Expand Up @@ -154,4 +272,4 @@ GRPC.methods.getPlayers = function(params)
result[i] = GRPC.exporters.unit(unit)
end
return GRPC.success({units = result})
end
end