feat(radar state): initial scaffolding

This commit is contained in:
MarcoJayUsai
2025-03-18 14:42:46 +01:00
parent 16e77087f5
commit ee15106be1
8 changed files with 244 additions and 133 deletions

View File

@@ -1072,10 +1072,69 @@ function Olympus.setOnOff(groupName, onOff)
end
end
-- Disable the AI of a group on or off entirely
function Olympus.setRedGreenAuto(groupName, redGreenAuto)
Olympus.debug("Olympus.setRedGreenAuto " .. groupName .. " " .. tostring(redGreenAuto), 2)
local group = Group.getByName(groupName)
if group ~= nil then
if redGreenAuto == 'RED' then
group:getController():setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.RED)
end
if redGreenAuto == 'GREEN' then
group:getController():setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.GREEN)
end
if redGreenAuto == 'AUTO' then
group:getController():setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.AUTO)
end
Olympus.debug("Olympus.setRedGreenAuto completed successfully", 2)
end
end
function getUnitDescription(unit)
return unit:getDescr()
end
-- This function gets the navpoints from the DCS mission
function Olympus.getNavPoints()
local function extract_tag(str)
return str:match("^%[(.-)%]")
end
local navpoints = {}
if mist.DBs.navPoints ~= nil then
for coalitionName, coalitionNavpoints in pairs(mist.DBs.navPoints) do
if navpoints[coalitionName] == nil then
navpoints[coalitionName] = {}
end
for index, navpointDrawingData in pairs(coalitionNavpoints) do
local navpointCustomLayer = extract_tag(navpointDrawingData['callsignStr']);
-- Let's convert DCS coords to lat lon
local vec3 = { x = navpointDrawingData['x'], y = 0, z = navpointDrawingData['y'] }
local lat, lng = coord.LOtoLL(vec3)
navpointDrawingData['lat'] = lat
navpointDrawingData['lng'] = lng
navpointDrawingData['coalition'] = coalitionName
if navpointCustomLayer ~= nil then
if navpoints[coalitionName][navpointCustomLayer] == nil then
navpoints[coalitionName][navpointCustomLayer] = {}
end
navpoints[coalitionName][navpointCustomLayer][navpointDrawingData['callsignStr']] = navpointDrawingData
else
navpoints[coalitionName][navpointDrawingData['callsignStr']] = navpointDrawingData
end
end
end
end
return navpoints
end
-- This function is periodically called to collect the data of all the existing drawings in the mission to be transmitted to the olympus.dll
function Olympus.initializeDrawings()
local drawings = {}
@@ -1129,6 +1188,10 @@ function Olympus.initializeDrawings()
end
end
local navpoints = Olympus.getNavPoints()
drawings['navpoints'] = navpoints
Olympus.drawingsByLayer["drawings"] = drawings
-- Send the drawings to the DLL
@@ -1214,6 +1277,18 @@ function Olympus.setUnitsData(arg, time)
end
table["isAlive"] = unit:isExist() and unit:isActive() and unit:getLife() >= 1
table["radarState"] = "AUTO"
if unit:isActive() then
if unit:getRadar() then
-- Olympus.log:info("radarState: unit active and getRadar is true, setting RED.")
table["radarState"] = "RED"
else
-- Olympus.log:info("radarState: unit active and getRadar is false, setting GREEN.")
table["radarState"] = "GREEN"
end
end
local group = unit:getGroup()
if group ~= nil then