-
Notifications
You must be signed in to change notification settings - Fork 24
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
Wizxrd
wants to merge
6
commits into
DCS-gRPC:main
Choose a base branch
from
Wizxrd:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ read_globals = { | |
"trigger", | ||
"Unit", | ||
"world", | ||
"Airbase", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = {} | ||
|
@@ -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))}) | ||
|
@@ -154,4 +272,4 @@ GRPC.methods.getPlayers = function(params) | |
result[i] = GRPC.exporters.unit(unit) | ||
end | ||
return GRPC.success({units = result}) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.