mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
New ESCORT class, first version ...
This class does now detection reporting to the main client group.
This commit is contained in:
109
Moose/Escort.lua
Normal file
109
Moose/Escort.lua
Normal 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
|
||||
Reference in New Issue
Block a user