mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Fixes
AI_PATROL: - Target unit is nil. Issue #1234 DETECTION: - ReportFriendliesNearBy ForEachPlayer added nil check. CONTROLLABLE: - Added IsHelicopter() - Added OptionRestrictBurner() AI_A2A_Cap - AtteckUnit not nil check. AI_A2A_Dispatcher: - DefenderGroup not nil and alive check #1228 AI_A2A_GCICAP: - AttackCoordinate nil check
This commit is contained in:
parent
60042e14dc
commit
169c5a674c
@ -200,8 +200,7 @@ function AI_A2A_CAP:CreateAttackUnitTasks( AttackSetUnit, DefenderGroup, EngageA
|
|||||||
|
|
||||||
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
|
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
|
||||||
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
|
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
|
||||||
self:T( { "Attacking Unit:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
if AttackUnit and AttackUnit:IsAlive() and AttackUnit:IsAir() then
|
||||||
if AttackUnit:IsAlive() and AttackUnit:IsAir() then
|
|
||||||
-- TODO: Add coalition check? Only attack units of if AttackUnit:GetCoalition()~=AICap:GetCoalition()
|
-- TODO: Add coalition check? Only attack units of if AttackUnit:GetCoalition()~=AICap:GetCoalition()
|
||||||
-- Maybe the detected set also contains
|
-- Maybe the detected set also contains
|
||||||
self:T( { "Attacking Task:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
self:T( { "Attacking Task:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
||||||
|
|||||||
@ -3231,6 +3231,8 @@ do -- AI_A2A_DISPATCHER
|
|||||||
self:SetDefenderTask( SquadronName, DefenderCAP, "CAP", AI_A2A_Fsm )
|
self:SetDefenderTask( SquadronName, DefenderCAP, "CAP", AI_A2A_Fsm )
|
||||||
|
|
||||||
function AI_A2A_Fsm:onafterTakeoff( DefenderGroup, From, Event, To )
|
function AI_A2A_Fsm:onafterTakeoff( DefenderGroup, From, Event, To )
|
||||||
|
-- Issue GetCallsign() returns nil, see https://github.com/FlightControl-Master/MOOSE/issues/1228
|
||||||
|
if DefenderGroup and DefenderGroup:IsAlive() then
|
||||||
self:F({"CAP Takeoff", DefenderGroup:GetName()})
|
self:F({"CAP Takeoff", DefenderGroup:GetName()})
|
||||||
--self:GetParent(self).onafterBirth( self, Defender, From, Event, To )
|
--self:GetParent(self).onafterBirth( self, Defender, From, Event, To )
|
||||||
|
|
||||||
@ -3243,8 +3245,10 @@ do -- AI_A2A_DISPATCHER
|
|||||||
AI_A2A_Fsm:__Patrol( 2 ) -- Start Patrolling
|
AI_A2A_Fsm:__Patrol( 2 ) -- Start Patrolling
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function AI_A2A_Fsm:onafterPatrolRoute( DefenderGroup, From, Event, To )
|
function AI_A2A_Fsm:onafterPatrolRoute( DefenderGroup, From, Event, To )
|
||||||
|
if DefenderGroup and DefenderGroup:IsAlive() then
|
||||||
self:F({"CAP PatrolRoute", DefenderGroup:GetName()})
|
self:F({"CAP PatrolRoute", DefenderGroup:GetName()})
|
||||||
self:GetParent(self).onafterPatrolRoute( self, DefenderGroup, From, Event, To )
|
self:GetParent(self).onafterPatrolRoute( self, DefenderGroup, From, Event, To )
|
||||||
|
|
||||||
@ -3257,9 +3261,10 @@ do -- AI_A2A_DISPATCHER
|
|||||||
|
|
||||||
Dispatcher:ClearDefenderTaskTarget( DefenderGroup )
|
Dispatcher:ClearDefenderTaskTarget( DefenderGroup )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function AI_A2A_Fsm:onafterRTB( DefenderGroup, From, Event, To )
|
function AI_A2A_Fsm:onafterRTB( DefenderGroup, From, Event, To )
|
||||||
|
if DefenderGroup and DefenderGroup:IsAlive() then
|
||||||
self:F({"CAP RTB", DefenderGroup:GetName()})
|
self:F({"CAP RTB", DefenderGroup:GetName()})
|
||||||
|
|
||||||
self:GetParent(self).onafterRTB( self, DefenderGroup, From, Event, To )
|
self:GetParent(self).onafterRTB( self, DefenderGroup, From, Event, To )
|
||||||
@ -3272,9 +3277,11 @@ do -- AI_A2A_DISPATCHER
|
|||||||
end
|
end
|
||||||
Dispatcher:ClearDefenderTaskTarget( DefenderGroup )
|
Dispatcher:ClearDefenderTaskTarget( DefenderGroup )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- @param #AI_A2A_DISPATCHER self
|
--- @param #AI_A2A_DISPATCHER self
|
||||||
function AI_A2A_Fsm:onafterHome( Defender, From, Event, To, Action )
|
function AI_A2A_Fsm:onafterHome( Defender, From, Event, To, Action )
|
||||||
|
if Defender and Defender:IsAlive() then
|
||||||
self:F({"CAP Home", Defender:GetName()})
|
self:F({"CAP Home", Defender:GetName()})
|
||||||
self:GetParent(self).onafterHome( self, Defender, From, Event, To )
|
self:GetParent(self).onafterHome( self, Defender, From, Event, To )
|
||||||
|
|
||||||
@ -3295,6 +3302,7 @@ do -- AI_A2A_DISPATCHER
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -3636,10 +3644,17 @@ do -- AI_A2A_DISPATCHER
|
|||||||
--- Assigns A2G AI Tasks in relation to the detected items.
|
--- Assigns A2G AI Tasks in relation to the detected items.
|
||||||
-- @param #AI_A2G_DISPATCHER self
|
-- @param #AI_A2G_DISPATCHER self
|
||||||
function AI_A2A_DISPATCHER:Order( DetectedItem )
|
function AI_A2A_DISPATCHER:Order( DetectedItem )
|
||||||
local AttackCoordinate = self.Detection:GetDetectedItemCoordinate( DetectedItem )
|
|
||||||
|
local detection=self.Detection -- Functional.Detection#DETECTION_AREAS
|
||||||
|
|
||||||
local ShortestDistance = 999999999
|
local ShortestDistance = 999999999
|
||||||
|
|
||||||
|
-- Get coordinate (or nil).
|
||||||
|
local AttackCoordinate = detection:GetDetectedItemCoordinate( DetectedItem )
|
||||||
|
|
||||||
|
-- Issue https://github.com/FlightControl-Master/MOOSE/issues/1232
|
||||||
|
if AttackCoordinate then
|
||||||
|
|
||||||
for DefenderSquadronName, DefenderSquadron in pairs( self.DefenderSquadrons ) do
|
for DefenderSquadronName, DefenderSquadron in pairs( self.DefenderSquadrons ) do
|
||||||
|
|
||||||
self:I( { DefenderSquadron = DefenderSquadron.Name } )
|
self:I( { DefenderSquadron = DefenderSquadron.Name } )
|
||||||
@ -3654,12 +3669,15 @@ do -- AI_A2A_DISPATCHER
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
return ShortestDistance
|
return ShortestDistance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Shows the tactical display.
|
--- Shows the tactical display.
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
|
-- @param Functional.Detection#DETECTION_BASE Detection The detection created by the @{Functional.Detection#DETECTION_BASE} derived object.
|
||||||
function AI_A2A_DISPATCHER:ShowTacticalDisplay( Detection )
|
function AI_A2A_DISPATCHER:ShowTacticalDisplay( Detection )
|
||||||
|
|
||||||
local AreaMsg = {}
|
local AreaMsg = {}
|
||||||
|
|||||||
@ -667,6 +667,10 @@ function AI_PATROL_ZONE:onafterDetect( Controllable, From, Event, To )
|
|||||||
if TargetObject and TargetObject:isExist() and TargetObject.id_ < 50000000 then
|
if TargetObject and TargetObject:isExist() and TargetObject.id_ < 50000000 then
|
||||||
|
|
||||||
local TargetUnit = UNIT:Find( TargetObject )
|
local TargetUnit = UNIT:Find( TargetObject )
|
||||||
|
|
||||||
|
-- Check that target is alive due to issue https://github.com/FlightControl-Master/MOOSE/issues/1234
|
||||||
|
if TargetUnit and TargetUnit:IsAlive() then
|
||||||
|
|
||||||
local TargetUnitName = TargetUnit:GetName()
|
local TargetUnitName = TargetUnit:GetName()
|
||||||
|
|
||||||
if self.DetectionZone then
|
if self.DetectionZone then
|
||||||
@ -683,6 +687,8 @@ function AI_PATROL_ZONE:onafterDetect( Controllable, From, Event, To )
|
|||||||
end
|
end
|
||||||
Detected = true
|
Detected = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1438,8 +1438,11 @@ do -- DETECTION_BASE
|
|||||||
function( PlayerUnitName )
|
function( PlayerUnitName )
|
||||||
local PlayerUnit = UNIT:FindByName( PlayerUnitName )
|
local PlayerUnit = UNIT:FindByName( PlayerUnitName )
|
||||||
|
|
||||||
if PlayerUnit and PlayerUnit:GetCoordinate():IsInRadius( DetectedUnitCoord, self.FriendliesRange ) then
|
-- Fix for issue https://github.com/FlightControl-Master/MOOSE/issues/1225
|
||||||
--if PlayerUnit and PlayerUnit:IsInZone(DetectionZone) then
|
if PlayerUnit and PlayerUnit:IsAlive() then
|
||||||
|
local coord=PlayerUnit:GetCoordinate()
|
||||||
|
|
||||||
|
if coord and coord:IsInRadius( DetectedUnitCoord, self.FriendliesRange ) then
|
||||||
|
|
||||||
local PlayerUnitCategory = PlayerUnit:GetDesc().category
|
local PlayerUnitCategory = PlayerUnit:GetDesc().category
|
||||||
|
|
||||||
@ -1462,6 +1465,7 @@ do -- DETECTION_BASE
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -3480,3 +3480,48 @@ function CONTROLLABLE:IsAirPlane()
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns if the Controllable contains Helicopters.
|
||||||
|
-- @param #CONTROLLABLE self
|
||||||
|
-- @return #boolean true if Controllable contains Helicopters.
|
||||||
|
function CONTROLLABLE:IsHelicopter()
|
||||||
|
self:F2()
|
||||||
|
|
||||||
|
local DCSObject = self:GetDCSObject()
|
||||||
|
|
||||||
|
if DCSObject then
|
||||||
|
local Category = DCSObject:getDesc().category
|
||||||
|
return Category == Unit.Category.HELICOPTER
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Sets Controllable Option for Restriction of Afterburner.
|
||||||
|
-- @param #CONTROLLABLE self
|
||||||
|
-- @param #boolean RestrictBurner If true, restrict burner. If false or nil, allow (unrestrict) burner.
|
||||||
|
function CONTROLLABLE:OptionRestrictBurner(RestrictBurner)
|
||||||
|
self:F2({self.ControllableName})
|
||||||
|
|
||||||
|
local DCSControllable = self:GetDCSObject()
|
||||||
|
|
||||||
|
if DCSControllable then
|
||||||
|
local Controller = self:_GetController()
|
||||||
|
|
||||||
|
if Controller then
|
||||||
|
|
||||||
|
-- Issue https://github.com/FlightControl-Master/MOOSE/issues/1216
|
||||||
|
if RestrictBurner == true then
|
||||||
|
if self:IsAir() then
|
||||||
|
Controller:setOption(16, true)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if self:IsAir() then
|
||||||
|
Controller:setOption(16, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user