Fixed friendlies nearby calculation

* Added DETECTION_BASE:FilterFriendliesCategory() method, which allows
to filter friendlies based on the category of the units found. This
method was required to be added to avoid counting airborne units as
friendlies in A2G missions.
This commit is contained in:
FlightControl_Master 2017-08-30 09:28:04 +02:00
parent ea96a5e0a3
commit 05d9faedee
15 changed files with 76 additions and 46 deletions

View File

@ -1239,7 +1239,7 @@ do -- AI_A2A_DISPATCHER
--- Set the default CAP limit for squadrons, which will be used to determine how many CAP can be airborne at the same time for the squadron. --- Set the default CAP limit for squadrons, which will be used to determine how many CAP can be airborne at the same time for the squadron.
-- The default CAP time interval is 1 CAP. -- The default CAP limit is 1 CAP, which means one CAP group being spawned.
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param #number CapLimit The maximum amount of CAP that can be airborne at the same time for the squadron. -- @param #number CapLimit The maximum amount of CAP that can be airborne at the same time for the squadron.
-- @return #AI_A2A_DISPATCHER -- @return #AI_A2A_DISPATCHER
@ -1497,7 +1497,7 @@ do -- AI_A2A_DISPATCHER
end end
--- --- Set a CAP for a Squadron.
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The squadron name. -- @param #string SquadronName The squadron name.
-- @param Core.Zone#ZONE_BASE Zone The @{Zone} object derived from @{Zone#ZONE_BASE} that defines the zone wherein the CAP will be executed. -- @param Core.Zone#ZONE_BASE Zone The @{Zone} object derived from @{Zone#ZONE_BASE} that defines the zone wherein the CAP will be executed.
@ -1549,9 +1549,13 @@ do -- AI_A2A_DISPATCHER
return self return self
end end
--- --- Set the squadron CAP parameters.
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The squadron name. -- @param #string SquadronName The squadron name.
-- @param #number CapLimit (optional) The maximum amount of CAP groups to be spawned. Note that a CAP is a group, so can consist out of 1 to 4 airplanes. The default is 1 CAP group.
-- @param #number LowInterval (optional) The minimum time boundary in seconds when a new CAP will be spawned. The default is 180 seconds.
-- @param #number HighInterval (optional) The maximum time boundary in seconds when a new CAP will be spawned. The default is 600 seconds.
-- @param #number Probability Is not in use, you can skip this parameter.
-- @return #AI_A2A_DISPATCHER -- @return #AI_A2A_DISPATCHER
-- @usage -- @usage
-- --
@ -1577,10 +1581,10 @@ do -- AI_A2A_DISPATCHER
local Cap = self.DefenderSquadrons[SquadronName].Cap local Cap = self.DefenderSquadrons[SquadronName].Cap
if Cap then if Cap then
Cap.LowInterval = LowInterval or 300 Cap.LowInterval = LowInterval or 180
Cap.HighInterval = HighInterval or 600 Cap.HighInterval = HighInterval or 600
Cap.Probability = Probability or 1 Cap.Probability = Probability or 1
Cap.CapLimit = CapLimit Cap.CapLimit = CapLimit or 1
Cap.Scheduler = Cap.Scheduler or SCHEDULER:New( self ) Cap.Scheduler = Cap.Scheduler or SCHEDULER:New( self )
local Scheduler = Cap.Scheduler -- Core.Scheduler#SCHEDULER local Scheduler = Cap.Scheduler -- Core.Scheduler#SCHEDULER
local ScheduleID = Cap.ScheduleID local ScheduleID = Cap.ScheduleID

View File

@ -1140,7 +1140,7 @@ do -- DETECTION_BASE
end end
do -- Threat do -- NearBy calculations
--- Returns if there are friendlies nearby the FAC units ... --- Returns if there are friendlies nearby the FAC units ...
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
@ -1158,6 +1158,15 @@ do -- DETECTION_BASE
return DetectedItem.FriendliesNearBy return DetectedItem.FriendliesNearBy
end end
--- Filters friendly units by unit category.
-- @param #DETECTION_BASE self
-- @param FriendliesCategory
-- @return #DETECTION_BASE
function DETECTION_BASE:FilterFriendliesCategory( FriendliesCategory )
self.FriendliesCategory = FriendliesCategory
return self
end
--- Returns if there are friendlies nearby the intercept ... --- Returns if there are friendlies nearby the intercept ...
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @return #boolean trhe if there are friendlies near the intercept. -- @return #boolean trhe if there are friendlies near the intercept.
@ -1245,15 +1254,18 @@ do -- DETECTION_BASE
--self:F( { "Friendlies search:", FoundUnitName, FoundUnitCoalition, EnemyUnitName, EnemyCoalition, FoundUnitInReportSetGroup } ) --self:F( { "Friendlies search:", FoundUnitName, FoundUnitCoalition, EnemyUnitName, EnemyCoalition, FoundUnitInReportSetGroup } )
if FoundUnitCoalition ~= EnemyCoalition and FoundUnitInReportSetGroup == false then if FoundUnitCoalition ~= EnemyCoalition and FoundUnitInReportSetGroup == false then
DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {}
local FriendlyUnit = UNIT:Find( FoundDCSUnit ) local FriendlyUnit = UNIT:Find( FoundDCSUnit )
local FriendlyUnitName = FriendlyUnit:GetName() local FriendlyUnitName = FriendlyUnit:GetName()
local FriendlyUnitCategory = FriendlyUnit:GetDesc().category
self:T( { FriendlyUnitCategory = FriendlyUnitCategory, FriendliesCategory = self.FriendliesCategory } )
DetectedItem.FriendliesNearBy[FriendlyUnitName] = FriendlyUnit if ( not self.FriendliesCategory ) or ( self.FriendliesCategory and ( self.FriendliesCategory == FriendlyUnitCategory ) ) then
DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {}
local Distance = DetectedUnitCoord:Get2DDistance( FriendlyUnit:GetCoordinate() ) DetectedItem.FriendliesNearBy[FriendlyUnitName] = FriendlyUnit
DetectedItem.FriendliesDistance = DetectedItem.FriendliesDistance or {} local Distance = DetectedUnitCoord:Get2DDistance( FriendlyUnit:GetCoordinate() )
DetectedItem.FriendliesDistance[Distance] = FriendlyUnit DetectedItem.FriendliesDistance = DetectedItem.FriendliesDistance or {}
DetectedItem.FriendliesDistance[Distance] = FriendlyUnit
end
return true return true
end end
@ -1269,23 +1281,28 @@ do -- DETECTION_BASE
--- @param Wrapper.Unit#UNIT PlayerUnit --- @param Wrapper.Unit#UNIT PlayerUnit
function( PlayerUnitName ) function( PlayerUnitName )
local PlayerUnit = UNIT:FindByName( PlayerUnitName ) local PlayerUnit = UNIT:FindByName( PlayerUnitName )
local PlayerUnitCategory = PlayerUnit:GetDesc().category
if PlayerUnit and PlayerUnit:IsInZone(DetectionZone) then if PlayerUnit and PlayerUnit:IsInZone(DetectionZone) then
DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {} if ( not self.FriendliesCategory ) or ( self.FriendliesCategory and ( self.FriendliesCategory == PlayerUnitCategory ) ) then
local PlayerUnitName = PlayerUnit:GetName()
DetectedItem.PlayersNearBy = DetectedItem.PlayersNearBy or {} DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {}
DetectedItem.PlayersNearBy[PlayerUnitName] = PlayerUnit local PlayerUnitName = PlayerUnit:GetName()
DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {} DetectedItem.PlayersNearBy = DetectedItem.PlayersNearBy or {}
DetectedItem.FriendliesNearBy[PlayerUnitName] = PlayerUnit DetectedItem.PlayersNearBy[PlayerUnitName] = PlayerUnit
local CenterCoord = DetectedUnit:GetCoordinate() DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {}
DetectedItem.FriendliesNearBy[PlayerUnitName] = PlayerUnit
local Distance = CenterCoord:Get2DDistance( PlayerUnit:GetCoordinate() ) local CenterCoord = DetectedUnit:GetCoordinate()
DetectedItem.FriendliesDistance = DetectedItem.FriendliesDistance or {}
DetectedItem.FriendliesDistance[Distance] = PlayerUnit local Distance = CenterCoord:Get2DDistance( PlayerUnit:GetCoordinate() )
DetectedItem.FriendliesDistance = DetectedItem.FriendliesDistance or {}
DetectedItem.FriendliesDistance[Distance] = PlayerUnit
end
end end
end end
) )

View File

@ -59,6 +59,7 @@ do -- TASK_A2G_DISPATCHER
self.Mission = Mission self.Mission = Mission
self.Detection:FilterCategories( Unit.Category.GROUND_UNIT, Unit.Category.SHIP ) self.Detection:FilterCategories( Unit.Category.GROUND_UNIT, Unit.Category.SHIP )
self.Detection:FilterFriendliesCategory( Unit.Category.GROUND_UNIT )
self:AddTransition( "Started", "Assign", "Started" ) self:AddTransition( "Started", "Assign", "Started" )

View File

@ -757,13 +757,13 @@ Per one, two, three, four?</p>
<tr> <tr>
<td class="name" nowrap="nowrap"><a href="##(AI_A2A_DISPATCHER).SetSquadronCap">AI_A2A_DISPATCHER:SetSquadronCap(SquadronName, Zone, FloorAltitude, CeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, EngageMinSpeed, EngageMaxSpeed, AltType)</a></td> <td class="name" nowrap="nowrap"><a href="##(AI_A2A_DISPATCHER).SetSquadronCap">AI_A2A_DISPATCHER:SetSquadronCap(SquadronName, Zone, FloorAltitude, CeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, EngageMinSpeed, EngageMaxSpeed, AltType)</a></td>
<td class="summary"> <td class="summary">
<p>Set a CAP for a Squadron.</p>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap="nowrap"><a href="##(AI_A2A_DISPATCHER).SetSquadronCapInterval">AI_A2A_DISPATCHER:SetSquadronCapInterval(SquadronName, CapLimit, LowInterval, HighInterval, Probability)</a></td> <td class="name" nowrap="nowrap"><a href="##(AI_A2A_DISPATCHER).SetSquadronCapInterval">AI_A2A_DISPATCHER:SetSquadronCapInterval(SquadronName, CapLimit, LowInterval, HighInterval, Probability)</a></td>
<td class="summary"> <td class="summary">
<p>Set the squadron CAP parameters.</p>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -3293,7 +3293,7 @@ or
<p>Set the default CAP limit for squadrons, which will be used to determine how many CAP can be airborne at the same time for the squadron.</p> <p>Set the default CAP limit for squadrons, which will be used to determine how many CAP can be airborne at the same time for the squadron.</p>
<p>The default CAP time interval is 1 CAP.</p> <p>The default CAP limit is 1 CAP, which means one CAP group being spawned.</p>
<h3>Parameter</h3> <h3>Parameter</h3>
<ul> <ul>
@ -4251,7 +4251,7 @@ If you have only one prefix name for a squadron, you don't need to use the <code
</dt> </dt>
<dd> <dd>
<p>Set a CAP for a Squadron.</p>
<h3>Parameters</h3> <h3>Parameters</h3>
<ul> <ul>
@ -4342,8 +4342,11 @@ The altitude type, which is a string "BARO" defining Barometric or "RADIO" defin
</dt> </dt>
<dd> <dd>
<p>Set the squadron CAP parameters.</p>
<p> </p>
<h3>Parameters</h3> <h3>Parameters</h3>
<ul> <ul>
<li> <li>
@ -4354,22 +4357,26 @@ The squadron name.</p>
</li> </li>
<li> <li>
<p><code><em> CapLimit </em></code>: </p> <p><code><em>#number CapLimit </em></code>:
(optional) The maximum amount of CAP groups to be spawned. Note that a CAP is a group, so can consist out of 1 to 4 airplanes. The default is 1 CAP group.</p>
</li> </li>
<li> <li>
<p><code><em> LowInterval </em></code>: </p> <p><code><em>#number LowInterval </em></code>:
(optional) The minimum time boundary in seconds when a new CAP will be spawned. The default is 180 seconds.</p>
</li> </li>
<li> <li>
<p><code><em> HighInterval </em></code>: </p> <p><code><em>#number HighInterval </em></code>:
(optional) The maximum time boundary in seconds when a new CAP will be spawned. The default is 600 seconds.</p>
</li> </li>
<li> <li>
<p><code><em> Probability </em></code>: </p> <p><code><em>#number Probability </em></code>:
Is not in use, you can skip this parameter.</p>
</li> </li>
</ul> </ul>

View File

@ -3542,7 +3542,6 @@ The range till cargo will board.</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em>#number</em>
<a id="#(CARGO_UNIT).RunCount" > <a id="#(CARGO_UNIT).RunCount" >
<strong>CARGO_UNIT.RunCount</strong> <strong>CARGO_UNIT.RunCount</strong>
</a> </a>

View File

@ -1130,6 +1130,7 @@ function below will use the range 1-7 just in case</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em></em>
<a id="#(DESIGNATE).LaserCodes" > <a id="#(DESIGNATE).LaserCodes" >
<strong>DESIGNATE.LaserCodes</strong> <strong>DESIGNATE.LaserCodes</strong>
</a> </a>

View File

@ -2619,7 +2619,7 @@ The group to generate the report for.</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em></em> <em>#number</em>
<a id="#(DETECTION_BASE).DetectionInterval" > <a id="#(DETECTION_BASE).DetectionInterval" >
<strong>DETECTION_BASE.DetectionInterval</strong> <strong>DETECTION_BASE.DetectionInterval</strong>
</a> </a>

View File

@ -1598,7 +1598,7 @@ A string defining the start state.</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em>#string</em> <em></em>
<a id="#(FSM)._StartState" > <a id="#(FSM)._StartState" >
<strong>FSM._StartState</strong> <strong>FSM._StartState</strong>
</a> </a>
@ -1897,6 +1897,7 @@ A string defining the start state.</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em></em>
<a id="#(FSM).current" > <a id="#(FSM).current" >
<strong>FSM.current</strong> <strong>FSM.current</strong>
</a> </a>

View File

@ -227,7 +227,6 @@ on defined intervals (currently every minute).</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em>#number</em>
<a id="#(MOVEMENT).AliveUnits" > <a id="#(MOVEMENT).AliveUnits" >
<strong>MOVEMENT.AliveUnits</strong> <strong>MOVEMENT.AliveUnits</strong>
</a> </a>
@ -236,9 +235,6 @@ on defined intervals (currently every minute).</p>
<p> Contains the counter how many units are currently alive</p>
</dd> </dd>
</dl> </dl>
<dl class="function"> <dl class="function">

View File

@ -2862,6 +2862,7 @@ The y coordinate.</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em></em>
<a id="#(POINT_VEC2).z" > <a id="#(POINT_VEC2).z" >
<strong>POINT_VEC2.z</strong> <strong>POINT_VEC2.z</strong>
</a> </a>

View File

@ -1836,7 +1836,6 @@ The height in meters to add to the altitude of the positionable.</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em><a href="Core.Spot.html##(SPOT)">Core.Spot#SPOT</a></em>
<a id="#(POSITIONABLE).Spot" > <a id="#(POSITIONABLE).Spot" >
<strong>POSITIONABLE.Spot</strong> <strong>POSITIONABLE.Spot</strong>
</a> </a>

View File

@ -1093,7 +1093,7 @@ true if metric.</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em>#boolean</em> <em></em>
<a id="#(SETTINGS).Metric" > <a id="#(SETTINGS).Metric" >
<strong>SETTINGS.Metric</strong> <strong>SETTINGS.Metric</strong>
</a> </a>

View File

@ -3150,7 +3150,7 @@ Spawn_BE_KA50 = SPAWN:New( 'BE KA-50@RAMP-Ground Defense' ):Schedule( 600, 0.5 )
<p> Flag that indicates if all the Groups of the SpawnGroup need to be visible when Spawned.</p> <p> When the first Spawn executes, all the Groups need to be made visible before start.</p>
</dd> </dd>
</dl> </dl>

View File

@ -765,6 +765,7 @@ true if it is lasing</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em></em>
<a id="#(SPOT).ScheduleID" > <a id="#(SPOT).ScheduleID" >
<strong>SPOT.ScheduleID</strong> <strong>SPOT.ScheduleID</strong>
</a> </a>
@ -778,6 +779,7 @@ true if it is lasing</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em></em>
<a id="#(SPOT).SpotIR" > <a id="#(SPOT).SpotIR" >
<strong>SPOT.SpotIR</strong> <strong>SPOT.SpotIR</strong>
</a> </a>
@ -791,6 +793,7 @@ true if it is lasing</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em></em>
<a id="#(SPOT).SpotLaser" > <a id="#(SPOT).SpotLaser" >
<strong>SPOT.SpotLaser</strong> <strong>SPOT.SpotLaser</strong>
</a> </a>
@ -804,6 +807,7 @@ true if it is lasing</p>
<dl class="function"> <dl class="function">
<dt> <dt>
<em></em>
<a id="#(SPOT).Target" > <a id="#(SPOT).Target" >
<strong>SPOT.Target</strong> <strong>SPOT.Target</strong>
</a> </a>

View File

@ -552,7 +552,7 @@ based on the tasking capabilities defined in <a href="Task.html##(TASK)">Task#TA
<dl class="function"> <dl class="function">
<dt> <dt>
<em><a href="Core.Cargo.html##(CARGO_GROUP)">Core.Cargo#CARGO_GROUP</a></em> <em><a href="Core.Cargo.html##(CARGO)">Core.Cargo#CARGO</a></em>
<a id="#(FSM_PROCESS).Cargo" > <a id="#(FSM_PROCESS).Cargo" >
<strong>FSM_PROCESS.Cargo</strong> <strong>FSM_PROCESS.Cargo</strong>
</a> </a>
@ -631,7 +631,7 @@ based on the tasking capabilities defined in <a href="Task.html##(TASK)">Task#TA
<dl class="function"> <dl class="function">
<dt> <dt>
<em>#number</em> <em></em>
<a id="#(TASK_CARGO).CargoLimit" > <a id="#(TASK_CARGO).CargoLimit" >
<strong>TASK_CARGO.CargoLimit</strong> <strong>TASK_CARGO.CargoLimit</strong>
</a> </a>