mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Detection class, first teaser version ...
This commit is contained in:
parent
0ad7cbe2ea
commit
e5f17213e1
@ -11,20 +11,33 @@
|
||||
-- @author Mechanic : Concept & Testing
|
||||
-- @author FlightControl : Design & Programming
|
||||
|
||||
|
||||
|
||||
--- DETECTION_BASE class
|
||||
-- @type DETECTION_BASE
|
||||
-- @field Group#GROUP FACGroup The GROUP in the Forward Air Controller role.
|
||||
-- @field DCSTypes#Distance DetectionRange The range till which targets are accepted to be detected.
|
||||
-- @field DCSTypes#Distance DetectionZoneRange The range till which targets are grouped upon the first detected target.
|
||||
-- @field #DETECTION_BASE.DetectedUnitSets DetectedUnitSets A list of @{Set#SET_UNIT}s containing the units in each set that were detected within a DetectedZoneRange.
|
||||
-- @field #DETECTION_BASE.DetectedZones DetectedZones A list of @{Zone#ZONE_UNIT}s containing the zones of the reference detected units.
|
||||
-- @extends Set#SET_BASE
|
||||
DETECTION_BASE = {
|
||||
ClassName = "DETECTION_BASE",
|
||||
Sets = {},
|
||||
DetectedUnitSets = {},
|
||||
DetectedUnits = {},
|
||||
FACGroup = nil,
|
||||
DetectionRange = nil,
|
||||
DetectionZoneRange = nil,
|
||||
}
|
||||
|
||||
--- @type DETECTION_BASE.DetectedUnitSets
|
||||
-- @list <Set#SET_UNIT>
|
||||
|
||||
|
||||
--- @type DETECTION_BASE.DetectedZones
|
||||
-- @list <Zone#ZONE_UNIT>
|
||||
|
||||
|
||||
--- DETECTION constructor.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @return #DETECTION_BASE self
|
||||
@ -37,7 +50,7 @@ function DETECTION_BASE:New( FACGroup, DetectionRange, DetectionZoneRange )
|
||||
self.DetectionRange = DetectionRange
|
||||
self.DetectionZoneRange = DetectionZoneRange
|
||||
|
||||
self.DetectionScheduler = SCHEDULER:New(self, self._DetectionScheduler, { self, "Detection" }, 1, 30, 0.2 )
|
||||
self.DetectionScheduler = SCHEDULER:New(self, self._DetectionScheduler, { self, "Detection" }, 10, 30, 0.2 )
|
||||
end
|
||||
|
||||
--- Form @{Set}s of detected @{Unit#UNIT}s in an array of @{Set#SET_UNIT}s.
|
||||
@ -45,7 +58,7 @@ end
|
||||
function DETECTION_BASE:_DetectionScheduler( SchedulerName )
|
||||
self:F2( { SchedulerName } )
|
||||
|
||||
self.Sets = {}
|
||||
self.DetectedUnitSets = {}
|
||||
|
||||
if self.FACGroup:IsAlive() then
|
||||
local FACGroupName = self.FACGroup:GetName()
|
||||
@ -57,36 +70,91 @@ function DETECTION_BASE:_DetectionScheduler( SchedulerName )
|
||||
|
||||
if FACObject and FACObject:isExist() and FACObject.id_ < 50000000 then
|
||||
|
||||
local FACDetectedTargetUnit = UNIT:Find( FACObject )
|
||||
local FACDetectedTargetUnitName = FACDetectedTargetUnit:GetName()
|
||||
local FACDetectedUnit = UNIT:Find( FACObject )
|
||||
local FACDetectedUnitName = FACDetectedUnit:GetName()
|
||||
|
||||
local FACDetectedTargetUnitPositionVec3 = FACDetectedTargetUnit:GetPointVec3()
|
||||
local FACDetectedUnitPositionVec3 = FACDetectedUnit:GetPointVec3()
|
||||
local FACGroupPositionVec3 = self.FACGroup:GetPointVec3()
|
||||
local Distance = ( ( FACDetectedTargetUnitPositionVec3.x - FACGroupPositionVec3.x )^2 +
|
||||
( FACDetectedTargetUnitPositionVec3.y - FACGroupPositionVec3.y )^2 +
|
||||
( FACDetectedTargetUnitPositionVec3.z - FACGroupPositionVec3.z )^2
|
||||
local Distance = ( ( FACDetectedUnitPositionVec3.x - FACGroupPositionVec3.x )^2 +
|
||||
( FACDetectedUnitPositionVec3.y - FACGroupPositionVec3.y )^2 +
|
||||
( FACDetectedUnitPositionVec3.z - FACGroupPositionVec3.z )^2
|
||||
) ^ 0.5 / 1000
|
||||
|
||||
self:T( { self.FACGroup:GetName(), FACDetectedTargetUnit:GetName(), Distance } )
|
||||
self:T( { FACGroupName, FACDetectedUnitName, Distance } )
|
||||
|
||||
if Distance <= self then
|
||||
if Distance <= self.DetectionRange then
|
||||
|
||||
if not ClientEscortTargets[EscortTargetUnitName] then
|
||||
ClientEscortTargets[EscortTargetUnitName] = {}
|
||||
if not self.DetectedUnits[FACDetectedUnitName] then
|
||||
self.DetectedUnits[FACDetectedUnitName] = {}
|
||||
end
|
||||
ClientEscortTargets[EscortTargetUnitName].AttackUnit = FACDetectedTargetUnit
|
||||
ClientEscortTargets[EscortTargetUnitName].visible = EscortTarget.visible
|
||||
ClientEscortTargets[EscortTargetUnitName].type = EscortTarget.type
|
||||
ClientEscortTargets[EscortTargetUnitName].distance = EscortTarget.distance
|
||||
self.DetectedUnits[FACDetectedUnitName].DetectedUnit = UNIT:FindByName( FACDetectedUnitName )
|
||||
self.DetectedUnits[FACDetectedUnitName].Visible = FACDetectedTarget.visible
|
||||
self.DetectedUnits[FACDetectedUnitName].Type = FACDetectedTarget.type
|
||||
self.DetectedUnits[FACDetectedUnitName].Distance = FACDetectedTarget.distance
|
||||
else
|
||||
if ClientEscortTargets[EscortTargetUnitName] then
|
||||
ClientEscortTargets[EscortTargetUnitName] = nil
|
||||
-- if beyond the DetectionRange then nullify...
|
||||
if self.DetectedUnits[FACDetectedUnitName] then
|
||||
self.DetectedUnits[FACDetectedUnitName] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- okay, now we have a list of detected unit names ...
|
||||
-- Sort the table based on distance ...
|
||||
self:T( { "Sorting DetectedUnits table:", self.DetectedUnits } )
|
||||
table.sort( self.DetectedUnits, function( a, b ) return a.Distance < b.Distance end )
|
||||
self:T( { "Sorted Targets Table:", self.DetectedUnits } )
|
||||
|
||||
-- Now group the DetectedUnits table into SET_UNITs, evaluating the DetectionZoneRange.
|
||||
|
||||
if self.DetectedUnits then
|
||||
for DetectedUnitName, DetectedUnitData in pairs( self.DetectedUnits ) do
|
||||
local DetectedUnit = DetectedUnitData.DetectedUnit -- Unit#UNIT
|
||||
self:T( DetectedUnit:GetName() )
|
||||
if #self.DetectedUnitSets == 0 then
|
||||
self:T( { "Adding Unit Set #", 1 } )
|
||||
self.DetectedUnitSets[1] = {}
|
||||
self.DetectedUnitSets[1].Zone = ZONE_UNIT:New( DetectedUnitName, DetectedUnit, self.DetectionZoneRange )
|
||||
self.DetectedUnitSets[1].Set = SET_UNIT:New()
|
||||
self.DetectedUnitSets[1].Set:AddUnit( DetectedUnit )
|
||||
else
|
||||
local AddedToSet = false
|
||||
for DetectedUnitSetID, DetectedUnitSetData in pairs( self.DetectedUnitSets ) do
|
||||
self:T( "Detected Unit Set #" .. DetectedUnitSetID )
|
||||
local DetectedUnitSet = DetectedUnitSetData.Set -- Set#SET_UNIT
|
||||
local DetectedZone = DetectedUnitSetData.Zone -- Zone#ZONE_UNIT
|
||||
if DetectedUnit:IsInZone( DetectedZone ) then
|
||||
self:T( "Adding to Unit Set #" .. DetectedUnitSetID )
|
||||
self.DetectedUnitSets[DetectedUnitSetID].Set:AddUnit( DetectedUnit )
|
||||
AddedToSet = true
|
||||
end
|
||||
end
|
||||
if AddedToSet == false then
|
||||
self:T( "Adding new Unit Set #" .. #self.DetectedUnitSets+1 )
|
||||
self.DetectedUnitSets[#self.DetectedUnitSets+1] = {}
|
||||
self.DetectedUnitSets[#self.DetectedUnitSets].Zone = ZONE_UNIT:New( DetectedUnitName, DetectedUnit, self.DetectionZoneRange )
|
||||
self.DetectedUnitSets[#self.DetectedUnitSets].Set = SET_UNIT:New()
|
||||
self.DetectedUnitSets[#self.DetectedUnitSets].Set:AddUnit( DetectedUnit )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Now all the tests should have been build, now make some smoke and flares...
|
||||
|
||||
for DetectedUnitSetID, DetectedUnitSetData in pairs( self.DetectedUnitSets ) do
|
||||
local DetectedUnitSet = DetectedUnitSetData.Set -- Set#SET_UNIT
|
||||
local DetectedZone = DetectedUnitSetData.Zone -- Zone#ZONE_UNIT
|
||||
self:T( "Detected Set #" .. DetectedUnitSetID )
|
||||
DetectedUnitSet:ForEachUnit(
|
||||
--- @param Unit#UNIT DetectedUnit
|
||||
function( DetectedUnit )
|
||||
self:T( DetectedUnit:GetName() )
|
||||
DetectedUnit:FlareRed()
|
||||
end
|
||||
)
|
||||
DetectedZone:SmokeZone( POINT_VEC3.SmokeColor.White, 30 )
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@ -37,6 +37,7 @@ Include.File( "Escort" )
|
||||
Include.File( "MissileTrainer" )
|
||||
Include.File( "AIBalancer" )
|
||||
Include.File( "AirbasePolice" )
|
||||
Include.File( "Detection" )
|
||||
|
||||
|
||||
|
||||
|
||||
@ -197,8 +197,6 @@ SET_BASE = {
|
||||
-- DBObject = SET_BASE:New()
|
||||
function SET_BASE:New( Database )
|
||||
|
||||
env.info( tostring( Database ) )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
|
||||
@ -894,13 +892,26 @@ function SET_UNIT:New()
|
||||
end
|
||||
|
||||
--- Add UNIT(s) to SET_UNIT.
|
||||
-- @param Set#SET_UNIT self
|
||||
-- @param #SET_UNIT self
|
||||
-- @param #string AddUnit A single UNIT.
|
||||
-- @return #SET_UNIT self
|
||||
function SET_UNIT:AddUnit( AddUnit )
|
||||
|
||||
self:Add( AddUnit:GetName(), AddUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Add UNIT(s) to SET_UNIT.
|
||||
-- @param #SET_UNIT self
|
||||
-- @param #string AddUnitNames A single name or an array of UNIT names.
|
||||
-- @return self
|
||||
-- @return #SET_UNIT self
|
||||
function SET_UNIT:AddUnitsByName( AddUnitNames )
|
||||
|
||||
local AddUnitNamesArray = ( type( AddUnitNames ) == "table" ) and AddUnitNames or { AddUnitNames }
|
||||
|
||||
self:T( AddUnitNamesArray )
|
||||
for AddUnitID, AddUnitName in pairs( AddUnitNamesArray ) do
|
||||
self:Add( AddUnitName, UNIT:FindByName( AddUnitName ) )
|
||||
end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -74,6 +74,8 @@ COPY /b Moose.lua + %1\Sead.lua Moose.lua
|
||||
COPY /b Moose.lua + %1\Escort.lua Moose.lua
|
||||
COPY /b Moose.lua + %1\MissileTrainer.lua Moose.lua
|
||||
COPY /b Moose.lua + %1\AIBalancer.lua Moose.lua
|
||||
COPY /b Moose.lua + %1\AirbasePolice.lua Moose.lua
|
||||
COPY /b Moose.lua + %1\Detection.lua Moose.lua
|
||||
|
||||
COPY /b Moose.lua + "Moose Create Static\Moose_Trace_Off.lua" Moose.lua
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,4 @@
|
||||
|
||||
local FACGroup = GROUP:FindByName( "FAC Group" )
|
||||
|
||||
local FACDetection = DETECTION_BASE:New( FACGroup, 1000, 250 )
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user