mirror of
https://github.com/akaAgar/the-universal-mission-for-dcs-world.git
synced 2025-11-25 19:31:01 +00:00
Contact detection report more efficient
This commit is contained in:
parent
d11e1dc3a2
commit
ea97c40f25
@ -9,7 +9,7 @@ do
|
|||||||
local CONTACT_REPORT_INTERVAL = 8 -- onClockTick is called four times by minute, so multiply this by 15 seconds (CONTACT_REPORT_INTERVAL = 8 means "every 2 minutes")
|
local CONTACT_REPORT_INTERVAL = 8 -- onClockTick is called four times by minute, so multiply this by 15 seconds (CONTACT_REPORT_INTERVAL = 8 means "every 2 minutes")
|
||||||
local DEFAULT_PAYLOAD = "attack" -- Default payload
|
local DEFAULT_PAYLOAD = "attack" -- Default payload
|
||||||
|
|
||||||
local knownContacts = {}
|
local knownGroupsID = {}
|
||||||
local nextContactReportTick = CONTACT_REPORT_INTERVAL
|
local nextContactReportTick = CONTACT_REPORT_INTERVAL
|
||||||
local wingmenGroupID = nil
|
local wingmenGroupID = nil
|
||||||
local wingmenUnitID = {}
|
local wingmenUnitID = {}
|
||||||
@ -91,7 +91,7 @@ do
|
|||||||
wingmenUnitID = DCSEx.table.deepCopy(groupInfo.unitsID)
|
wingmenUnitID = DCSEx.table.deepCopy(groupInfo.unitsID)
|
||||||
|
|
||||||
-- Reinitialize list of known contacts and contact report interval
|
-- Reinitialize list of known contacts and contact report interval
|
||||||
knownContacts = {}
|
knownGroupsID = {}
|
||||||
nextContactReportTick = CONTACT_REPORT_INTERVAL
|
nextContactReportTick = CONTACT_REPORT_INTERVAL
|
||||||
|
|
||||||
TUM.log("Spawned AI wingmen")
|
TUM.log("Spawned AI wingmen")
|
||||||
@ -126,13 +126,16 @@ do
|
|||||||
local gPos = DCSEx.world.getGroupCenter(g)
|
local gPos = DCSEx.world.getGroupCenter(g)
|
||||||
local gCateg = Group.getCategory(g)
|
local gCateg = Group.getCategory(g)
|
||||||
|
|
||||||
local specialGroupProperties = nil
|
|
||||||
|
|
||||||
local detectionRange = DCSEx.converter.nmToMeters(20 * detectionRangeMultiplier)
|
local detectionRange = DCSEx.converter.nmToMeters(20 * detectionRangeMultiplier)
|
||||||
if gCateg == Group.Category.AIRPLANE then
|
if gCateg == Group.Category.AIRPLANE then
|
||||||
detectionRange = DCSEx.converter.nmToMeters(50 * detectionRangeMultiplier)
|
detectionRange = DCSEx.converter.nmToMeters(50 * detectionRangeMultiplier)
|
||||||
elseif gCateg == Group.Category.SHIP then
|
elseif gCateg == Group.Category.SHIP then
|
||||||
detectionRange = DCSEx.converter.nmToMeters(30 * detectionRangeMultiplier)
|
detectionRange = DCSEx.converter.nmToMeters(30 * detectionRangeMultiplier)
|
||||||
|
local allSpeedboats = true
|
||||||
|
for _,u in ipairs(g:getUnits()) do
|
||||||
|
if not u:getTypeName() == "speedboat" then allSpeedboats = false end
|
||||||
|
end
|
||||||
|
if allSpeedboats then detectionRange = detectionRange / 8 end -- Speedboats are HARD to spot
|
||||||
elseif gCateg == Group.Category.GROUND then
|
elseif gCateg == Group.Category.GROUND then
|
||||||
local allInfantry = true
|
local allInfantry = true
|
||||||
local airDefenseCount = 0
|
local airDefenseCount = 0
|
||||||
@ -140,26 +143,14 @@ do
|
|||||||
if not u:hasAttribute("Infantry") then allInfantry = false end
|
if not u:hasAttribute("Infantry") then allInfantry = false end
|
||||||
if u:hasAttribute("Air Defence") then airDefenseCount = airDefenseCount + 1 end
|
if u:hasAttribute("Air Defence") then airDefenseCount = airDefenseCount + 1 end
|
||||||
end
|
end
|
||||||
|
if allInfantry then detectionRange = detectionRange / 8 end -- Infantry is HARD to spot
|
||||||
if allInfantry then
|
|
||||||
detectionRange = detectionRange / 8 -- Infantry is HARD to spot
|
|
||||||
specialGroupProperties = "Infantry"
|
|
||||||
elseif airDefenseCount >= g:getSize() / 1.5 then
|
|
||||||
specialGroupProperties = "Air Defence"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if at least one wingman is in detection range
|
local distanceToGroup = DCSEx.math.getDistance2D(gPos, searchPoint)
|
||||||
local inRange = false
|
if distanceToGroup <= detectionRange then -- Check if wingman group is in detection range
|
||||||
if DCSEx.math.getDistance2D(gPos, searchPoint) <= detectionRange then
|
|
||||||
inRange = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
if inRange then
|
|
||||||
local newGroup = false
|
local newGroup = false
|
||||||
if not DCSEx.table.contains(knownContacts) then
|
if not DCSEx.table.contains(knownGroupsID) then
|
||||||
table.insert(knownContacts, gID)
|
table.insert(knownGroupsID, gID)
|
||||||
newGroup = true
|
newGroup = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -170,23 +161,9 @@ do
|
|||||||
type = "unknown"
|
type = "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
if gCateg == Group.Category.AIRPLANE then
|
groupInfo.type = Library.objectNames.getGenericGroup(g, distanceToGroup > detectionRange / 2)
|
||||||
groupInfo.type = "aircraft"
|
-- if gCateg == Group.Category.AIRPLANE or gCateg == Group.Category.HELICOPTER then
|
||||||
elseif gCateg == Group.Category.HELICOPTER then
|
-- end
|
||||||
groupInfo.type = "helicopters"
|
|
||||||
elseif gCateg == Group.Category.GROUND then
|
|
||||||
if specialGroupProperties == "Infantry" then
|
|
||||||
groupInfo.type = "infantry"
|
|
||||||
elseif specialGroupProperties == "Air Defence" then
|
|
||||||
groupInfo.type = "air defense"
|
|
||||||
else
|
|
||||||
groupInfo.type = "vehicles"
|
|
||||||
end
|
|
||||||
elseif gCateg == Group.Category.SHIP then
|
|
||||||
groupInfo.type = "ships"
|
|
||||||
elseif gCateg == Group.Category.TRAIN then
|
|
||||||
groupInfo.type = "trains"
|
|
||||||
end
|
|
||||||
|
|
||||||
if not newContactsOnly or newGroup then
|
if not newContactsOnly or newGroup then
|
||||||
table.insert(detectedTargets, groupInfo)
|
table.insert(detectedTargets, groupInfo)
|
||||||
@ -198,22 +175,20 @@ do
|
|||||||
return detectedTargets
|
return detectedTargets
|
||||||
end
|
end
|
||||||
|
|
||||||
function TUM.wingmen.getContactsAsReportString(groupCategory, newContactsOnly, giveRelativePositionToPlayer)
|
function TUM.wingmen.getContactsAsReportString(groupCategory, newContactsOnly, giveRelativePosition)
|
||||||
giveRelativePositionToPlayer = giveRelativePositionToPlayer or false
|
if TUM.settings.getValue(TUM.settings.id.MULTIPLAYER) then return nil end -- No wingmen in multiplayer
|
||||||
|
|
||||||
|
giveRelativePosition = giveRelativePosition or false
|
||||||
local contacts = TUM.wingmen.getContacts(groupCategory, newContactsOnly)
|
local contacts = TUM.wingmen.getContacts(groupCategory, newContactsOnly)
|
||||||
if not contacts or #contacts == 0 then return nil end
|
if not contacts or #contacts == 0 then return nil end
|
||||||
|
|
||||||
local player = world:getPlayer()
|
local refPoint = DCSEx.world.getGroupCenter(TUM.wingmen.getGroup())
|
||||||
local refPoint = nil
|
|
||||||
if player then
|
|
||||||
refPoint = DCSEx.math.vec3ToVec2(player:getPoint())
|
|
||||||
end
|
|
||||||
|
|
||||||
local reportText = ""
|
local reportText = ""
|
||||||
for _,t in ipairs(contacts) do
|
for _,t in ipairs(contacts) do
|
||||||
reportText = reportText.."\n - "..tostring(t.size).."x "..t.type
|
reportText = reportText.."\n - "..tostring(t.size).."x "..t.type
|
||||||
if refPoint and giveRelativePositionToPlayer then
|
if refPoint and giveRelativePosition then
|
||||||
reportText = reportText..", "..DCSEx.dcs.getBRAA(t.point2, refPoint, false, false, false).." from you"
|
reportText = reportText..", "..DCSEx.dcs.getBRAA(t.point2, refPoint, false, false, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return reportText
|
return reportText
|
||||||
@ -278,11 +253,11 @@ do
|
|||||||
if TUM.mission.getStatus() == TUM.mission.status.NONE then return false end
|
if TUM.mission.getStatus() == TUM.mission.status.NONE then return false end
|
||||||
|
|
||||||
-- If new contacts are detected, report them immediately, no need to wait for next report tick
|
-- If new contacts are detected, report them immediately, no need to wait for next report tick
|
||||||
local newContactsReportString = TUM.wingmen.getContactsAsReportString(nil, true, true)
|
-- local newContactsReportString = TUM.wingmen.getContactsAsReportString(nil, true, true)
|
||||||
if newContactsReportString then
|
-- if newContactsReportString then
|
||||||
TUM.radio.playForAll("pilotWingmanReportContactsNew", { TUM.wingmen.getFirstWingmanNumber(), newContactsReportString }, TUM.wingmen.getFirstWingmanCallsign(), false)
|
-- TUM.radio.playForAll("pilotWingmanReportContactsNew", { TUM.wingmen.getFirstWingmanNumber(), newContactsReportString }, TUM.wingmen.getFirstWingmanCallsign(), false)
|
||||||
return true
|
-- return true
|
||||||
end
|
-- end
|
||||||
|
|
||||||
nextContactReportTick = nextContactReportTick - 1
|
nextContactReportTick = nextContactReportTick - 1
|
||||||
if nextContactReportTick > 0 then return false end
|
if nextContactReportTick > 0 then return false end
|
||||||
|
|||||||
@ -124,8 +124,8 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
function TUM.wingmenTasking.commandReportContacts(groupCategory, noReportIfNoContacts, delayRadioAnswer)
|
function TUM.wingmenTasking.commandReportContacts(groupCategory, noReportIfNoContacts, delayRadioAnswer)
|
||||||
delayRadioAnswer = delayRadioAnswer or false
|
|
||||||
noReportIfNoContacts = noReportIfNoContacts or false
|
noReportIfNoContacts = noReportIfNoContacts or false
|
||||||
|
delayRadioAnswer = delayRadioAnswer or false
|
||||||
|
|
||||||
local reportString = TUM.wingmen.getContactsAsReportString(groupCategory, false, true)
|
local reportString = TUM.wingmen.getContactsAsReportString(groupCategory, false, true)
|
||||||
|
|
||||||
@ -145,8 +145,10 @@ do
|
|||||||
local wingmenGroup = TUM.wingmen.getGroup()
|
local wingmenGroup = TUM.wingmen.getGroup()
|
||||||
if not wingmenGroup then return end
|
if not wingmenGroup then return end
|
||||||
|
|
||||||
|
local groupUnits = wingmenGroup:getUnits()
|
||||||
|
|
||||||
local statusMsg = ""
|
local statusMsg = ""
|
||||||
for i,u in ipairs(wingmenGroup:getUnits()) do
|
for i,u in ipairs(groupUnits) do
|
||||||
statusMsg = statusMsg..u:getCallsign():upper().."\n"
|
statusMsg = statusMsg..u:getCallsign():upper().."\n"
|
||||||
if u:getLife() >= u:getLife0() then
|
if u:getLife() >= u:getLife0() then
|
||||||
statusMsg = statusMsg.."- No damage sustained, fuel green"
|
statusMsg = statusMsg.."- No damage sustained, fuel green"
|
||||||
@ -168,7 +170,7 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if i < #wingmenGroup:getUnits() then statusMsg = statusMsg.."\n\n" end
|
if i < #groupUnits then statusMsg = statusMsg.."\n\n" end
|
||||||
end
|
end
|
||||||
|
|
||||||
TUM.radio.playForAll("pilotWingmanReportStatus", { TUM.wingmen.getFirstWingmanNumber(), statusMsg }, TUM.wingmen.getFirstWingmanCallsign(), delayRadioAnswer)
|
TUM.radio.playForAll("pilotWingmanReportStatus", { TUM.wingmen.getFirstWingmanNumber(), statusMsg }, TUM.wingmen.getFirstWingmanCallsign(), delayRadioAnswer)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user