From 4ba1a23092f3ea57e94fe2cfbd5d3a2895db43d7 Mon Sep 17 00:00:00 2001 From: Wizxrd <85634781+Wizxrd@users.noreply.github.com> Date: Fri, 12 Nov 2021 21:36:59 -0500 Subject: [PATCH 1/6] Plane Group Spawning - initial implementation of spawning an airplane group --- .luacheckrc | 2 + lua/methods/coalitions.lua | 156 ++++++++++++++++++++++++++++++++++++- 2 files changed, 154 insertions(+), 4 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index b609e51b..51c85adc 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -19,4 +19,6 @@ read_globals = { "trigger", "Unit", "world", + "Airbase", + "country" } \ No newline at end of file diff --git a/lua/methods/coalitions.lua b/lua/methods/coalitions.lua index da3c27f5..217a29ce 100644 --- a/lua/methods/coalitions.lua +++ b/lua/methods/coalitions.lua @@ -21,6 +21,30 @@ local skill = { Player = 5 } +-- types for aircraft taking off +local takeoffTypes = { + [1] = "TakeOff", + [2] = "TakeOffParking", + [3] = "TakeOffParkingHot", + [4] = "Turning Point", + runway = "TakeOff", + cold = "TakeOffParking", + hot = "TakeOffParkingHot", + air = "Turning Point" +} + +-- actiions for aircraft taking off +local takeoffActions = { + [1] = "From Runway", + [2] = "From Parking Area", + [3] = "From Parking Area Hot", + [4] = "Turning Point", + runway = "From Runway", + cold = "From Parking Area", + hot = "From Parking Area Hot", + air = "Turning Point", +} + --local altitudeType = { -- [1] = "BARO", -- [2] = "RADIO", @@ -28,6 +52,127 @@ local skill = { -- RADIO = 2 --} +local buildAirplanePoints = function(points) + local builtPoints = {} + for _, pointData in pairs(points) do + local pointVec3 + if type(pointData.place) == "string" then + if Airbase.getByName(pointData.place) then + pointVec3 = Airbase.getByName(pointData.place):getPoint() + env.info("ab point type") + elseif trigger.misc.getZone(pointData.place) then + pointVec3 = trigger.misc.getZone(pointData.place).point + env.info("zone point type") + 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 or takeoffTypes.air, + eta = 0, + eta_locked = true, + alt_type = pointData.alt_type or "BARO", + formation_template = "", + speed = pointData.speed, + action = pointData.action or takeoffActions.air, + 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 + 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() + env.info("ab point type") + elseif trigger.misc.getZone(unitListTemplate.place) then + pointVec3 = trigger.misc.getZone(unitListTemplate.place).point + env.info("zone point type") + 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 + if type(unitTemplate) == "table" then + units[i] = { + name = unitTemplate.unitName, -- or unitTemplate.name.."-"..i + type = unitListTemplate.type, + x = pointVec3.x, + y = pointVec3.z, + alt = unitListTemplate.alt, + alt_type = unitListTemplate.alt_type or "BARO", + 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 = unitTemplate.skill or skill.Random, + livery_id = unitTemplate.livery_id or nil, + } + end + 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 = {} @@ -109,9 +254,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.groupTemplate) + elseif params.template.type == "Ground" then + template = createGroundGroupTemplate(params.template.groundTemplate) -- this should maybe hold the type o + 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))}) @@ -154,4 +302,4 @@ GRPC.methods.getPlayers = function(params) result[i] = GRPC.exporters.unit(unit) end return GRPC.success({units = result}) -end \ No newline at end of file +end From 3f5204b292279a5ea9d5ab20a3909a6acdc9438a Mon Sep 17 00:00:00 2001 From: Wizxrd <85634781+Wizxrd@users.noreply.github.com> Date: Fri, 12 Nov 2021 21:49:53 -0500 Subject: [PATCH 2/6] Update coalitions.lua --- lua/methods/coalitions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/methods/coalitions.lua b/lua/methods/coalitions.lua index 217a29ce..03c6041e 100644 --- a/lua/methods/coalitions.lua +++ b/lua/methods/coalitions.lua @@ -258,7 +258,7 @@ GRPC.methods.addGroup = function(params) if params.template.type == "Airplane" then template = createPlaneGroupTemplate(params.template.groupTemplate) elseif params.template.type == "Ground" then - template = createGroundGroupTemplate(params.template.groundTemplate) -- this should maybe hold the type o + template = createGroundGroupTemplate(params.template.groundTemplate) end coalition.addGroup(params.country - 1, params.groupCategory, template) -- Decrement for non zero-indexed gRPC enum From 82c719c1d57fc1c64c91ced5c1d7b6794622b2a2 Mon Sep 17 00:00:00 2001 From: Wizxrd <85634781+Wizxrd@users.noreply.github.com> Date: Fri, 12 Nov 2021 21:52:52 -0500 Subject: [PATCH 3/6] Update coalitions.lua --- lua/methods/coalitions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/methods/coalitions.lua b/lua/methods/coalitions.lua index 03c6041e..80c17e30 100644 --- a/lua/methods/coalitions.lua +++ b/lua/methods/coalitions.lua @@ -256,7 +256,7 @@ GRPC.methods.addGroup = function(params) end local template if params.template.type == "Airplane" then - template = createPlaneGroupTemplate(params.template.groupTemplate) + template = createPlaneGroupTemplate(params.template.airplaneTemplate) elseif params.template.type == "Ground" then template = createGroundGroupTemplate(params.template.groundTemplate) end From ce3adb644f5f7976e3a3e56678b395f8a680f75b Mon Sep 17 00:00:00 2001 From: Wizxrd <85634781+Wizxrd@users.noreply.github.com> Date: Fri, 12 Nov 2021 22:08:18 -0500 Subject: [PATCH 4/6] Update .luacheckrc --- .luacheckrc | 1 - 1 file changed, 1 deletion(-) diff --git a/.luacheckrc b/.luacheckrc index 51c85adc..ac13a5f3 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -20,5 +20,4 @@ read_globals = { "Unit", "world", "Airbase", - "country" } \ No newline at end of file From 860ec972a1bfd91b0ee374c90f208e692bfbca29 Mon Sep 17 00:00:00 2001 From: Wizxrd <85634781+Wizxrd@users.noreply.github.com> Date: Sat, 13 Nov 2021 22:39:07 -0500 Subject: [PATCH 5/6] Update coalitions.lua --- lua/methods/coalitions.lua | 84 +++++++++++++------------------------- 1 file changed, 29 insertions(+), 55 deletions(-) diff --git a/lua/methods/coalitions.lua b/lua/methods/coalitions.lua index 80c17e30..ac7b9e0f 100644 --- a/lua/methods/coalitions.lua +++ b/lua/methods/coalitions.lua @@ -21,37 +21,13 @@ local skill = { Player = 5 } --- types for aircraft taking off -local takeoffTypes = { - [1] = "TakeOff", - [2] = "TakeOffParking", - [3] = "TakeOffParkingHot", - [4] = "Turning Point", - runway = "TakeOff", - cold = "TakeOffParking", - hot = "TakeOffParkingHot", - air = "Turning Point" +local altitudeType = { + [1] = "BARO", + [2] = "RADIO", + BARO = 1, + RADIO = 2 } --- actiions for aircraft taking off -local takeoffActions = { - [1] = "From Runway", - [2] = "From Parking Area", - [3] = "From Parking Area Hot", - [4] = "Turning Point", - runway = "From Runway", - cold = "From Parking Area", - hot = "From Parking Area Hot", - air = "Turning Point", -} - ---local altitudeType = { --- [1] = "BARO", --- [2] = "RADIO", --- BARO = 1, --- RADIO = 2 ---} - local buildAirplanePoints = function(points) local builtPoints = {} for _, pointData in pairs(points) do @@ -71,13 +47,13 @@ local buildAirplanePoints = function(points) alt = pointData.alt, x = pointVec3.x, y = pointVec3.z, - type = pointData.type or takeoffTypes.air, + type = pointData.type, eta = 0, eta_locked = true, - alt_type = pointData.alt_type or "BARO", + alt_type = altitudeType[altitudeType.alt_type], formation_template = "", speed = pointData.speed, - action = pointData.action or takeoffActions.air, + action = pointData.action, task = { id = "ComboTask", params = { @@ -119,29 +95,27 @@ local createPlaneGroupUnitsTemplate = function(unitListTemplate) pointVec3 = coord.LLtoLO(unitListTemplate.place.lat, unitListTemplate.place.lon) end local fuel = Unit.getDescByName(unitListTemplate.type).fuelMassMax -- needed incase no payload table is applied - if type(unitTemplate) == "table" then - units[i] = { - name = unitTemplate.unitName, -- or unitTemplate.name.."-"..i - type = unitListTemplate.type, - x = pointVec3.x, - y = pointVec3.z, - alt = unitListTemplate.alt, - alt_type = unitListTemplate.alt_type or "BARO", - 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 = unitTemplate.skill or skill.Random, - livery_id = unitTemplate.livery_id or nil, - } - end + 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 From 8b69378206560d774d64e17ae5c9cdc8fae5ec9d Mon Sep 17 00:00:00 2001 From: Wizxrd <85634781+Wizxrd@users.noreply.github.com> Date: Sat, 13 Nov 2021 22:42:02 -0500 Subject: [PATCH 6/6] Update coalitions.lua --- lua/methods/coalitions.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua/methods/coalitions.lua b/lua/methods/coalitions.lua index ac7b9e0f..2bd098e1 100644 --- a/lua/methods/coalitions.lua +++ b/lua/methods/coalitions.lua @@ -35,10 +35,8 @@ local buildAirplanePoints = function(points) if type(pointData.place) == "string" then if Airbase.getByName(pointData.place) then pointVec3 = Airbase.getByName(pointData.place):getPoint() - env.info("ab point type") elseif trigger.misc.getZone(pointData.place) then pointVec3 = trigger.misc.getZone(pointData.place).point - env.info("zone point type") end elseif type(pointData.place) == "table" then pointVec3 = coord.LLtoLO(pointData.place.lat, pointData.place.lon) @@ -86,10 +84,8 @@ local createPlaneGroupUnitsTemplate = function(unitListTemplate) if type(unitListTemplate.place) == "string" then if Airbase.getByName(unitListTemplate.place) then pointVec3 = Airbase.getByName(unitListTemplate.place):getPoint() - env.info("ab point type") elseif trigger.misc.getZone(unitListTemplate.place) then pointVec3 = trigger.misc.getZone(unitListTemplate.place).point - env.info("zone point type") end elseif type(unitListTemplate.place) == "table" then pointVec3 = coord.LLtoLO(unitListTemplate.place.lat, unitListTemplate.place.lon)