mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
#Changes from Develop
This commit is contained in:
@@ -653,131 +653,132 @@ do -- DETECTION_BASE
|
||||
-- self:T2( { TargetIsDetected = TargetIsDetected, TargetIsVisible = TargetIsVisible, TargetLastTime = TargetLastTime, TargetKnowType = TargetKnowType, TargetKnowDistance = TargetKnowDistance, TargetLastPos = TargetLastPos, TargetLastVelocity = TargetLastVelocity } )
|
||||
|
||||
-- Only process if the target is visible. Detection also returns invisible units.
|
||||
-- if Detection.visible == true then
|
||||
|
||||
local DetectionAccepted = true
|
||||
|
||||
local DetectedObjectName = DetectedObject:getName()
|
||||
local DetectedObjectType = DetectedObject:getTypeName()
|
||||
|
||||
local DetectedObjectVec3 = DetectedObject:getPoint()
|
||||
local DetectedObjectVec2 = { x = DetectedObjectVec3.x, y = DetectedObjectVec3.z }
|
||||
local DetectionGroupVec3 = Detection:GetVec3() or {x=0,y=0,z=0}
|
||||
local DetectionGroupVec2 = { x = DetectionGroupVec3.x, y = DetectionGroupVec3.z }
|
||||
|
||||
local Distance = ((DetectedObjectVec3.x - DetectionGroupVec3.x) ^ 2 +
|
||||
(DetectedObjectVec3.y - DetectionGroupVec3.y) ^ 2 +
|
||||
(DetectedObjectVec3.z - DetectionGroupVec3.z) ^ 2) ^ 0.5 / 1000
|
||||
|
||||
local DetectedUnitCategory = DetectedObject:getDesc().category
|
||||
|
||||
-- self:F( { "Detected Target:", DetectionGroupName, DetectedObjectName, DetectedObjectType, Distance, DetectedUnitCategory } )
|
||||
|
||||
-- Calculate Acceptance
|
||||
|
||||
DetectionAccepted = self._.FilterCategories[DetectedUnitCategory] ~= nil and DetectionAccepted or false
|
||||
|
||||
-- if Distance > 15000 then
|
||||
-- if DetectedUnitCategory == Unit.Category.GROUND_UNIT or DetectedUnitCategory == Unit.Category.SHIP then
|
||||
-- if DetectedObject:hasSensors( Unit.SensorType.RADAR, Unit.RadarType.AS ) == false then
|
||||
-- DetectionAccepted = false
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
if self.AcceptRange and Distance * 1000 > self.AcceptRange then
|
||||
DetectionAccepted = false
|
||||
end
|
||||
|
||||
if self.AcceptZones then
|
||||
local AnyZoneDetection = false
|
||||
for AcceptZoneID, AcceptZone in pairs( self.AcceptZones ) do
|
||||
local AcceptZone = AcceptZone -- Core.Zone#ZONE_BASE
|
||||
if AcceptZone:IsVec2InZone( DetectedObjectVec2 ) then
|
||||
AnyZoneDetection = true
|
||||
--if Detection.visible == true then
|
||||
|
||||
local DetectionAccepted = true
|
||||
|
||||
local DetectedObjectName = DetectedObject:getName()
|
||||
local DetectedObjectType = DetectedObject:getTypeName()
|
||||
|
||||
local DetectedObjectVec3 = DetectedObject:getPoint()
|
||||
local DetectedObjectVec2 = { x = DetectedObjectVec3.x, y = DetectedObjectVec3.z }
|
||||
local DetectionGroupVec3 = Detection:GetVec3() or {x=0,y=0,z=0}
|
||||
local DetectionGroupVec2 = { x = DetectionGroupVec3.x, y = DetectionGroupVec3.z }
|
||||
|
||||
local Distance = ( ( DetectedObjectVec3.x - DetectionGroupVec3.x )^2 +
|
||||
( DetectedObjectVec3.y - DetectionGroupVec3.y )^2 +
|
||||
( DetectedObjectVec3.z - DetectionGroupVec3.z )^2
|
||||
) ^ 0.5 / 1000
|
||||
|
||||
local DetectedUnitCategory = DetectedObject:getDesc().category
|
||||
|
||||
--self:F( { "Detected Target:", DetectionGroupName, DetectedObjectName, DetectedObjectType, Distance, DetectedUnitCategory } )
|
||||
|
||||
-- Calculate Acceptance
|
||||
|
||||
DetectionAccepted = self._.FilterCategories[DetectedUnitCategory] ~= nil and DetectionAccepted or false
|
||||
|
||||
-- if Distance > 15000 then
|
||||
-- if DetectedUnitCategory == Unit.Category.GROUND_UNIT or DetectedUnitCategory == Unit.Category.SHIP then
|
||||
-- if DetectedObject:hasSensors( Unit.SensorType.RADAR, Unit.RadarType.AS ) == false then
|
||||
-- DetectionAccepted = false
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
if self.AcceptRange and Distance * 1000 > self.AcceptRange then
|
||||
DetectionAccepted = false
|
||||
end
|
||||
|
||||
if self.AcceptZones then
|
||||
local AnyZoneDetection = false
|
||||
for AcceptZoneID, AcceptZone in pairs( self.AcceptZones ) do
|
||||
local AcceptZone = AcceptZone -- Core.Zone#ZONE_BASE
|
||||
if AcceptZone:IsVec2InZone( DetectedObjectVec2 ) then
|
||||
AnyZoneDetection = true
|
||||
end
|
||||
end
|
||||
if not AnyZoneDetection then
|
||||
DetectionAccepted = false
|
||||
end
|
||||
end
|
||||
if not AnyZoneDetection then
|
||||
DetectionAccepted = false
|
||||
end
|
||||
end
|
||||
|
||||
if self.RejectZones then
|
||||
for RejectZoneID, RejectZone in pairs( self.RejectZones ) do
|
||||
local RejectZone = RejectZone -- Core.Zone#ZONE_BASE
|
||||
if RejectZone:IsVec2InZone( DetectedObjectVec2 ) == true then
|
||||
DetectionAccepted = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Calculate additional probabilities
|
||||
|
||||
if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.DistanceProbability then
|
||||
local DistanceFactor = Distance / 4
|
||||
local DistanceProbabilityReversed = (1 - self.DistanceProbability) * DistanceFactor
|
||||
local DistanceProbability = 1 - DistanceProbabilityReversed
|
||||
DistanceProbability = DistanceProbability * 30 / 300
|
||||
local Probability = math.random() -- Selects a number between 0 and 1
|
||||
-- self:T( { Probability, DistanceProbability } )
|
||||
if Probability > DistanceProbability then
|
||||
DetectionAccepted = false
|
||||
end
|
||||
end
|
||||
|
||||
if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.AlphaAngleProbability then
|
||||
local NormalVec2 = { x = DetectedObjectVec2.x - DetectionGroupVec2.x, y = DetectedObjectVec2.y - DetectionGroupVec2.y }
|
||||
local AlphaAngle = math.atan2( NormalVec2.y, NormalVec2.x )
|
||||
local Sinus = math.sin( AlphaAngle )
|
||||
local AlphaAngleProbabilityReversed = (1 - self.AlphaAngleProbability) * (1 - Sinus)
|
||||
local AlphaAngleProbability = 1 - AlphaAngleProbabilityReversed
|
||||
|
||||
AlphaAngleProbability = AlphaAngleProbability * 30 / 300
|
||||
|
||||
local Probability = math.random() -- Selects a number between 0 and 1
|
||||
-- self:T( { Probability, AlphaAngleProbability } )
|
||||
if Probability > AlphaAngleProbability then
|
||||
DetectionAccepted = false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.ZoneProbability then
|
||||
|
||||
for ZoneDataID, ZoneData in pairs( self.ZoneProbability ) do
|
||||
self:F( { ZoneData } )
|
||||
local ZoneObject = ZoneData[1] -- Core.Zone#ZONE_BASE
|
||||
local ZoneProbability = ZoneData[2] -- #number
|
||||
ZoneProbability = ZoneProbability * 30 / 300
|
||||
|
||||
if ZoneObject:IsVec2InZone( DetectedObjectVec2 ) == true then
|
||||
local Probability = math.random() -- Selects a number between 0 and 1
|
||||
-- self:T( { Probability, ZoneProbability } )
|
||||
if Probability > ZoneProbability then
|
||||
|
||||
if self.RejectZones then
|
||||
for RejectZoneID, RejectZone in pairs( self.RejectZones ) do
|
||||
local RejectZone = RejectZone -- Core.Zone#ZONE_BASE
|
||||
if RejectZone:IsVec2InZone( DetectedObjectVec2 ) == true then
|
||||
DetectionAccepted = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if DetectionAccepted then
|
||||
|
||||
HasDetectedObjects = true
|
||||
|
||||
self.DetectedObjects[DetectedObjectName] = self.DetectedObjects[DetectedObjectName] or {}
|
||||
self.DetectedObjects[DetectedObjectName].Name = DetectedObjectName
|
||||
|
||||
if TargetIsDetected and TargetIsDetected == true then
|
||||
self.DetectedObjects[DetectedObjectName].IsDetected = TargetIsDetected
|
||||
|
||||
-- Calculate additional probabilities
|
||||
|
||||
if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.DistanceProbability then
|
||||
local DistanceFactor = Distance / 4
|
||||
local DistanceProbabilityReversed = ( 1 - self.DistanceProbability ) * DistanceFactor
|
||||
local DistanceProbability = 1 - DistanceProbabilityReversed
|
||||
DistanceProbability = DistanceProbability * 30 / 300
|
||||
local Probability = math.random() -- Selects a number between 0 and 1
|
||||
--self:T( { Probability, DistanceProbability } )
|
||||
if Probability > DistanceProbability then
|
||||
DetectionAccepted = false
|
||||
end
|
||||
end
|
||||
|
||||
if TargetIsDetected and TargetIsVisible and TargetIsVisible == true then
|
||||
self.DetectedObjects[DetectedObjectName].IsVisible = TargetIsDetected and TargetIsVisible
|
||||
|
||||
if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.AlphaAngleProbability then
|
||||
local NormalVec2 = { x = DetectedObjectVec2.x - DetectionGroupVec2.x, y = DetectedObjectVec2.y - DetectionGroupVec2.y }
|
||||
local AlphaAngle = math.atan2( NormalVec2.y, NormalVec2.x )
|
||||
local Sinus = math.sin( AlphaAngle )
|
||||
local AlphaAngleProbabilityReversed = ( 1 - self.AlphaAngleProbability ) * ( 1 - Sinus )
|
||||
local AlphaAngleProbability = 1 - AlphaAngleProbabilityReversed
|
||||
|
||||
AlphaAngleProbability = AlphaAngleProbability * 30 / 300
|
||||
|
||||
local Probability = math.random() -- Selects a number between 0 and 1
|
||||
--self:T( { Probability, AlphaAngleProbability } )
|
||||
if Probability > AlphaAngleProbability then
|
||||
DetectionAccepted = false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if TargetIsDetected and not self.DetectedObjects[DetectedObjectName].KnowType then
|
||||
self.DetectedObjects[DetectedObjectName].KnowType = TargetIsDetected and TargetKnowType
|
||||
|
||||
if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.ZoneProbability then
|
||||
|
||||
for ZoneDataID, ZoneData in pairs( self.ZoneProbability ) do
|
||||
self:F({ZoneData})
|
||||
local ZoneObject = ZoneData[1] -- Core.Zone#ZONE_BASE
|
||||
local ZoneProbability = ZoneData[2] -- #number
|
||||
ZoneProbability = ZoneProbability * 30 / 300
|
||||
|
||||
if ZoneObject:IsVec2InZone( DetectedObjectVec2 ) == true then
|
||||
local Probability = math.random() -- Selects a number between 0 and 1
|
||||
--self:T( { Probability, ZoneProbability } )
|
||||
if Probability > ZoneProbability then
|
||||
DetectionAccepted = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if DetectionAccepted then
|
||||
|
||||
HasDetectedObjects = true
|
||||
|
||||
self.DetectedObjects[DetectedObjectName] = self.DetectedObjects[DetectedObjectName] or {}
|
||||
self.DetectedObjects[DetectedObjectName].Name = DetectedObjectName
|
||||
|
||||
if TargetIsDetected and TargetIsDetected == true then
|
||||
self.DetectedObjects[DetectedObjectName].IsDetected = TargetIsDetected
|
||||
end
|
||||
|
||||
if TargetIsDetected and TargetIsVisible and TargetIsVisible == true then
|
||||
self.DetectedObjects[DetectedObjectName].IsVisible = TargetIsDetected and TargetIsVisible
|
||||
end
|
||||
|
||||
if TargetIsDetected and not self.DetectedObjects[DetectedObjectName].KnowType then
|
||||
self.DetectedObjects[DetectedObjectName].KnowType = TargetIsDetected and TargetKnowType
|
||||
end
|
||||
self.DetectedObjects[DetectedObjectName].KnowDistance = TargetKnowDistance -- Detection.distance -- TargetKnowDistance
|
||||
self.DetectedObjects[DetectedObjectName].LastTime = (TargetIsDetected and TargetIsVisible == false) and TargetLastTime
|
||||
@@ -2439,16 +2440,16 @@ do -- DETECTION_AREAS
|
||||
-- A set with multiple detected zones will be created as there are groups of units detected.
|
||||
--
|
||||
-- ## 4.1) Retrieve the Detected Unit Sets and Detected Zones
|
||||
--
|
||||
-- The methods to manage the DetectedItems[].Set(s) are implemented in @{Functional.Detection#DETECTION_BASE} and
|
||||
--
|
||||
-- The methods to manage the DetectedItems[].Set(s) are implemented in @{Functional.Detection#DECTECTION_BASE} and
|
||||
-- the methods to manage the DetectedItems[].Zone(s) are implemented in @{Functional.Detection#DETECTION_AREAS}.
|
||||
--
|
||||
--
|
||||
-- Retrieve the DetectedItems[].Set with the method @{Functional.Detection#DETECTION_BASE.GetDetectedSet}(). A @{Core.Set#SET_UNIT} object will be returned.
|
||||
--
|
||||
--
|
||||
-- Retrieve the formed @{Zone@ZONE_UNIT}s as a result of the grouping the detected units within the DetectionZoneRange, use the method @{Functional.Detection#DETECTION_AREAS.GetDetectionZones}().
|
||||
-- To understand the amount of zones created, use the method @{Functional.Detection#DETECTION_AREAS.GetDetectionZoneCount}().
|
||||
-- To understand the amount of zones created, use the method @{Functional.Detection#DETECTION_AREAS.GetDetectionZoneCount}().
|
||||
-- If you want to obtain a specific zone from the DetectedZones, use the method @{Functional.Detection#DETECTION_AREAS.GetDetectionZoneByID}() with a given index.
|
||||
--
|
||||
--
|
||||
-- ## 4.4) Flare or Smoke detected units
|
||||
--
|
||||
-- Use the methods @{Functional.Detection#DETECTION_AREAS.FlareDetectedUnits}() or @{Functional.Detection#DETECTION_AREAS.SmokeDetectedUnits}() to flare or smoke the detected units when a new detection has taken place.
|
||||
@@ -2489,7 +2490,7 @@ do -- DETECTION_AREAS
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Retrieve set of detected zones.
|
||||
-- @param #DETECTION_AREAS self
|
||||
-- @return Core.Set#SET_ZONE The @{Set} of ZONE_UNIT objects detected.
|
||||
|
||||
Reference in New Issue
Block a user