New ESCORT class, first version ...

This class does now detection reporting to the main client group.
This commit is contained in:
FlightControl 2016-03-19 01:45:15 +01:00
parent 6dc1b1a810
commit 11c7cea1de
7 changed files with 149 additions and 2 deletions

View File

@ -22,6 +22,7 @@ _TraceClass = {
--CARGO_SLINGLOAD = true,
--CARGO_ZONE = true,
--CLEANUP = true,
ESCORT = true,
}
--- The BASE Class

View File

@ -307,7 +307,7 @@ self:T()
self.Messages[MessageId].MessageTime = timer.getTime()
self.Messages[MessageId].MessageDuration = MessageDuration
if MessageInterval == nil then
self.Messages[MessageId].MessageInterval = 600
self.Messages[MessageId].MessageInterval = 0
else
self.Messages[MessageId].MessageInterval = MessageInterval
end

View File

@ -1,6 +1,7 @@
--- Administers the Initial Sets of the Mission Templates as defined within the Mission Editor.
-- Administers the Spawning of new Groups within the DCSRTE and administers these new Groups within the DATABASE object(s).
-- @module DATABASE
-- @author FlightControl
Include.File( "Routines" )
Include.File( "Base" )

109
Moose/Escort.lua Normal file
View File

@ -0,0 +1,109 @@
--- Taking the lead of AI escorting your flight.
-- The ESCORT class allows you to interact with escoring AI on your flight and take the lead.
-- The following commands will be available:
--
-- * Pop-up and Scan Area
-- * Re-Join Formation
-- * Hold Position in x km
-- * Report identified targets
-- * Perform tasks per identified target: Report vector to target, paint target, kill target
--
-- @module ESCORT
-- @author FlightControl
Include.File( "Routines" )
Include.File( "Base" )
Include.File( "Database" )
Include.File( "Group" )
Include.File( "Zone" )
--- ESCORT class
-- @type
--
ESCORT = {
ClassName = "ESCORT",
EscortName = nil, -- The Escort Name
Targets = {}, -- The identified targets
}
--- ESCORT class constructor for an AI group
-- @param self
-- @param #CLIENT EscortClient The client escorted by the EscortGroup.
-- @param #GROUP EscortGroup The group AI escorting the EscortClient.
-- @param #string EscortName Name of the escort.
-- @return #ESCORT self
function ESCORT:New( EscortClient, EscortGroup, EscortName )
local self = BASE:Inherit( self, BASE:New() )
self:T( { EscortClient, EscortGroup, EscortName } )
self.EscortClient = EscortClient
self.EscortGroup = EscortGroup
self.EscortName = EscortName
self.ScanForTargetsFunction = routines.scheduleFunction( self._ScanForTargets, { self }, timer.getTime() + 1, 10 )
end
function ESCORT:_ScanForTargets()
self:T()
if self.EscortGroup:IsAlive() then
local EscortTargets = self.EscortGroup:GetDetectedTargets()
local EscortTargetMessages = ""
for EscortTargetID, EscortTarget in pairs( EscortTargets ) do
local EscortObject = EscortTarget.object
self:T( EscortObject )
if EscortObject and EscortObject:isExist() and EscortObject.id_ < 50000000 then
local EscortTargetMessage = ""
local EscortTargetUnit = UNIT:New( EscortObject )
local EscortTargetCategoryName = EscortTargetUnit:GetCategoryName()
local EscortTargetCategoryType = EscortTargetUnit:GetTypeName()
-- local EscortTargetIsDetected,
-- EscortTargetIsVisible,
-- EscortTargetLastTime,
-- EscortTargetKnowType,
-- EscortTargetKnowDistance,
-- EscortTargetLastPos,
-- EscortTargetLastVelocity
-- = self.EscortGroup:IsTargetDetected( EscortObject )
--
-- self:T( { EscortTargetIsDetected,
-- EscortTargetIsVisible,
-- EscortTargetLastTime,
-- EscortTargetKnowType,
-- EscortTargetKnowDistance,
-- EscortTargetLastPos,
-- EscortTargetLastVelocity } )
if EscortTarget.distance then
local EscortTargetUnitPositionVec3 = EscortTargetUnit:GetPositionVec3()
local EscortPositionVec3 = self.EscortGroup:GetPositionVec3()
local Distance = routines.utils.get3DDist( EscortTargetUnitPositionVec3, EscortPositionVec3 ) / 1000
self:T( { self.EscortGroup:GetName(), EscortTargetUnit:GetName(), Distance, EscortTarget.visible } )
if Distance <= 8 then
EscortTargetMessage = EscortTargetMessage .. " - " .. EscortTargetCategoryName .. " (" .. EscortTargetCategoryType .. ") "
EscortTargetMessage = EscortTargetMessage .. string.format( "%.2f", Distance ) .. " km"
if EscortTarget.visible then
EscortTargetMessage = EscortTargetMessage .. " visual contact"
end
end
end
if EscortTargetMessage ~= "" then
EscortTargetMessages = EscortTargetMessages .. EscortTargetMessage .. "\n"
end
end
end
if EscortTargetMessages ~= "" then
self.EscortClient:Message( EscortTargetMessages:gsub("\n$",""), 20, "/ESCORT.DetectedTargets", self.EscortName .. " reporting detected targets within 8 km range:" )
end
else
routines.removeFunction( self.ScanForTargetsFunction )
end
end

View File

@ -130,6 +130,16 @@ function GROUP:GetPoint()
return GroupPoint
end
--- Gets the current Point of the GROUP in VEC3 format.
-- @return #Vec3 Current Vec3 position of the group.
function GROUP:GetPositionVec3()
self:T( self.GroupName )
local GroupPoint = self:GetUnit(1):GetPositionVec3()
self:T( GroupPoint )
return GroupPoint
end
--- Destroy a GROUP
-- Note that this destroy method also raises a destroy event at run-time.
-- So all event listeners will catch the destroy event of this GROUP.
@ -441,3 +451,18 @@ function GROUP:_GetController()
return self.DCSGroup:getController()
end
function GROUP:GetDetectedTargets()
return self:_GetController():getDetectedTargets()
end
function GROUP:IsTargetDetected( DCSObject )
local TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity
= self:_GetController():isTargetDetected( DCSObject )
return TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity
end

View File

@ -422,7 +422,7 @@ routines.tostringBR = function(az, dist, alt, metric)
dist = routines.utils.round(routines.utils.metersToNM(dist), 2)
end
local s = string.format('%03d°', az) .. ' for ' .. dist
local s = string.format('%03d', az) .. ' for ' .. dist
if alt then
if metric then

View File

@ -9,6 +9,13 @@ Include.File( "Message" )
-- @type
UNIT = {
ClassName="UNIT",
CategoryName = {
[Unit.Category.AIRPLANE] = "Airplane",
[Unit.Category.HELICOPTER] = "Helicoper",
[Unit.Category.GROUND_UNIT] = "Ground Unit",
[Unit.Category.SHIP] = "Ship",
[Unit.Category.STRUCTURE] = "Structure",
}
}
function UNIT:New( DCSUnit )
@ -112,3 +119,7 @@ function UNIT:OtherUnitInRadius( AwaitUnit, Radius )
return false
end
function UNIT:GetCategoryName()
return self.CategoryName[ self.DCSUnit:getDesc().category ]
end