mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge pull request #452 from FlightControl-Master/386-ai-designate
386 ai designate
This commit is contained in:
commit
1068393dde
@ -118,6 +118,8 @@ do -- AI_DESIGNATE
|
|||||||
-- @function [parent=#AI_DESIGNATE] __Detect
|
-- @function [parent=#AI_DESIGNATE] __Detect
|
||||||
-- @param #AI_DESIGNATE self
|
-- @param #AI_DESIGNATE self
|
||||||
-- @param #number Delay
|
-- @param #number Delay
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self:AddTransition( "*", "LaseOn", "Lasing" )
|
self:AddTransition( "*", "LaseOn", "Lasing" )
|
||||||
|
|
||||||
@ -237,6 +239,9 @@ do -- AI_DESIGNATE
|
|||||||
|
|
||||||
self:SetLaserCodes( 1688 )
|
self:SetLaserCodes( 1688 )
|
||||||
|
|
||||||
|
self.LaserCodesUsed = {}
|
||||||
|
|
||||||
|
|
||||||
self.Detection:__Start( 2 )
|
self.Detection:__Start( 2 )
|
||||||
|
|
||||||
|
|
||||||
@ -253,6 +258,8 @@ do -- AI_DESIGNATE
|
|||||||
|
|
||||||
self.LaserCodes = ( type( LaserCodes ) == "table" ) and LaserCodes or { LaserCodes }
|
self.LaserCodes = ( type( LaserCodes ) == "table" ) and LaserCodes or { LaserCodes }
|
||||||
self:E(self.LaserCodes)
|
self:E(self.LaserCodes)
|
||||||
|
|
||||||
|
self.LaserCodesUsed = {}
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -303,6 +310,8 @@ do -- AI_DESIGNATE
|
|||||||
-- @return #AI_DESIGNATE
|
-- @return #AI_DESIGNATE
|
||||||
function AI_DESIGNATE:SetDesignateMenu()
|
function AI_DESIGNATE:SetDesignateMenu()
|
||||||
|
|
||||||
|
self.GroupSet:Flush()
|
||||||
|
|
||||||
self.GroupSet:ForEachGroup(
|
self.GroupSet:ForEachGroup(
|
||||||
|
|
||||||
--- @param Wrapper.Group#GROUP GroupReport
|
--- @param Wrapper.Group#GROUP GroupReport
|
||||||
@ -330,39 +339,35 @@ do -- AI_DESIGNATE
|
|||||||
DesignateMenu
|
DesignateMenu
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.Spots[Index] then
|
MENU_GROUP_COMMAND:New(
|
||||||
|
AttackGroup,
|
||||||
MENU_GROUP_COMMAND:New(
|
"Lase target 60 secs",
|
||||||
AttackGroup,
|
DetectedMenu,
|
||||||
"Switch laser Off",
|
self.MenuLaseOn,
|
||||||
DetectedMenu,
|
self,
|
||||||
self.MenuLaseOff,
|
AttackGroup,
|
||||||
self,
|
Index,
|
||||||
AttackGroup,
|
60
|
||||||
Index
|
)
|
||||||
)
|
MENU_GROUP_COMMAND:New(
|
||||||
else
|
AttackGroup,
|
||||||
MENU_GROUP_COMMAND:New(
|
"Lase target 120 secs",
|
||||||
AttackGroup,
|
DetectedMenu,
|
||||||
"Lase target 60 secs",
|
self.MenuLaseOn,
|
||||||
DetectedMenu,
|
self,
|
||||||
self.MenuLaseOn,
|
AttackGroup,
|
||||||
self,
|
Index,
|
||||||
AttackGroup,
|
120
|
||||||
Index,
|
)
|
||||||
60
|
MENU_GROUP_COMMAND:New(
|
||||||
)
|
AttackGroup,
|
||||||
MENU_GROUP_COMMAND:New(
|
"Switch laser Off",
|
||||||
AttackGroup,
|
DetectedMenu,
|
||||||
"Lase target 120 secs",
|
self.MenuLaseOff,
|
||||||
DetectedMenu,
|
self,
|
||||||
self.MenuLaseOn,
|
AttackGroup,
|
||||||
self,
|
Index
|
||||||
AttackGroup,
|
)
|
||||||
Index,
|
|
||||||
120
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
MENU_GROUP_COMMAND:New(
|
MENU_GROUP_COMMAND:New(
|
||||||
AttackGroup,
|
AttackGroup,
|
||||||
@ -425,43 +430,63 @@ do -- AI_DESIGNATE
|
|||||||
function AI_DESIGNATE:onafterLasing( From, Event, To, AttackGroup, Index, Duration )
|
function AI_DESIGNATE:onafterLasing( From, Event, To, AttackGroup, Index, Duration )
|
||||||
|
|
||||||
local TargetSetUnit = self.Detection:GetDetectedSet( Index )
|
local TargetSetUnit = self.Detection:GetDetectedSet( Index )
|
||||||
|
|
||||||
local Targets = false
|
TargetSetUnit:Flush()
|
||||||
|
|
||||||
|
for TargetUnit, SpotData in pairs( self.Spots ) do
|
||||||
|
local Spot = SpotData -- Core.Spot#SPOT
|
||||||
|
if not Spot:IsLasing() then
|
||||||
|
local LaserCode = Spot.LaserCode --(Not deleted when stopping with lasing).
|
||||||
|
self.LaserCodesUsed[LaserCode] = nil
|
||||||
|
self.Spots[TargetUnit] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local MoreTargets = false
|
||||||
|
|
||||||
TargetSetUnit:ForEachUnit(
|
TargetSetUnit:ForEachUnit(
|
||||||
--- @param Wrapper.Unit#UNIT SmokeUnit
|
--- @param Wrapper.Unit#UNIT SmokeUnit
|
||||||
function( SmokeUnit )
|
function( TargetUnit )
|
||||||
self:E("In procedure")
|
self:E("In procedure")
|
||||||
--if math.random( 1, ( 100 * TargetSetUnit:Count() ) / 100 ) <= 100 then
|
--if math.random( 1, ( 100 * TargetSetUnit:Count() ) / 100 ) <= 100 then
|
||||||
if SmokeUnit:IsAlive() then
|
if TargetUnit:IsAlive() then
|
||||||
local NearestRecceGroup = self.RecceSet:FindNearestGroupFromPointVec2( SmokeUnit:GetPointVec2() )
|
local Spot = self.Spots[TargetUnit]
|
||||||
if NearestRecceGroup then
|
if (not Spot) or ( Spot and Spot:IsLasing() == false ) then
|
||||||
for UnitID, UnitData in pairs( NearestRecceGroup:GetUnits() or {} ) do
|
local NearestRecceGroup = self.RecceSet:FindNearestGroupFromPointVec2( TargetUnit:GetPointVec2() )
|
||||||
local RecceUnit = UnitData -- Wrapper.Unit#UNIT
|
if NearestRecceGroup then
|
||||||
Targets = true
|
for UnitID, UnitData in pairs( NearestRecceGroup:GetUnits() or {} ) do
|
||||||
if RecceUnit:IsLasing() == false then
|
local RecceUnit = UnitData -- Wrapper.Unit#UNIT
|
||||||
self.Spots[Index] = self.Spots[Index] or {}
|
if RecceUnit:IsLasing() == false then
|
||||||
local Spots = self.Spots[Index]
|
local LaserCodeIndex = math.random(1, #self.LaserCodes)
|
||||||
local LaserCode = self.LaserCodes[math.random(1, #self.LaserCodes)]
|
local LaserCode = self.LaserCodes[LaserCodeIndex]
|
||||||
local Spot = RecceUnit:LaseUnit( SmokeUnit, LaserCode, Duration )
|
if not self.LaserCodesUsed[LaserCode] then
|
||||||
Spots[RecceUnit] = Spot
|
MoreTargets = true
|
||||||
RecceUnit:MessageToGroup( "Lasing " .. SmokeUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup )
|
self.LaserCodesUsed[LaserCode] = LaserCodeIndex
|
||||||
break
|
local Spot = RecceUnit:LaseUnit( TargetUnit, LaserCode, Duration )
|
||||||
else
|
self.Spots[TargetUnit] = Spot
|
||||||
|
RecceUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup )
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
MoreTargets = true
|
||||||
|
local RecceUnit = Spot.Recce
|
||||||
|
RecceUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup )
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
self.Spots[TargetUnit] = nil
|
||||||
end
|
end
|
||||||
--end
|
--end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
if Targets == true then
|
if MoreTargets == true then
|
||||||
self:__Lasing( -30, AttackGroup, Index, Duration )
|
self:__Lasing( -30, AttackGroup, Index, Duration )
|
||||||
else
|
else
|
||||||
self:__LaseOff( -0.2, AttackGroup, Index )
|
self:__LaseOff( 1, AttackGroup, Index )
|
||||||
end
|
end
|
||||||
|
|
||||||
self:SetDesignateMenu()
|
self:SetDesignateMenu()
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -471,9 +496,11 @@ do -- AI_DESIGNATE
|
|||||||
-- @return #AI_DESIGNATE
|
-- @return #AI_DESIGNATE
|
||||||
function AI_DESIGNATE:onafterLaseOff( From, Event, To, AttackGroup, Index )
|
function AI_DESIGNATE:onafterLaseOff( From, Event, To, AttackGroup, Index )
|
||||||
|
|
||||||
|
self.RecceSet:GetFirst():MessageToGroup( "Stopped lasing.", 15, AttackGroup )
|
||||||
|
|
||||||
local TargetSetUnit = self.Detection:GetDetectedSet( Index )
|
local TargetSetUnit = self.Detection:GetDetectedSet( Index )
|
||||||
|
|
||||||
local Spots = self.Spots[Index]
|
local Spots = self.Spots
|
||||||
|
|
||||||
for SpotID, SpotData in pairs( Spots ) do
|
for SpotID, SpotData in pairs( Spots ) do
|
||||||
local Spot = SpotData -- Core.Spot#SPOT
|
local Spot = SpotData -- Core.Spot#SPOT
|
||||||
@ -482,7 +509,8 @@ do -- AI_DESIGNATE
|
|||||||
end
|
end
|
||||||
|
|
||||||
Spots = nil
|
Spots = nil
|
||||||
self.Spots[Index] = nil
|
self.Spots = {}
|
||||||
|
self.LaserCodesUsed = {}
|
||||||
|
|
||||||
self:SetDesignateMenu()
|
self:SetDesignateMenu()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -454,6 +454,12 @@ do -- Event Handling
|
|||||||
-- @param #BASE self
|
-- @param #BASE self
|
||||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||||
|
|
||||||
|
--- Occurs when an object is dead.
|
||||||
|
-- initiator : The unit that is dead.
|
||||||
|
-- @function [parent=#BASE] OnEventDead
|
||||||
|
-- @param #BASE self
|
||||||
|
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||||
|
|
||||||
--- Occurs when an object is completely destroyed.
|
--- Occurs when an object is completely destroyed.
|
||||||
-- initiator : The unit that is was destroyed.
|
-- initiator : The unit that is was destroyed.
|
||||||
-- @function [parent=#BASE] OnEvent
|
-- @function [parent=#BASE] OnEvent
|
||||||
|
|||||||
@ -342,6 +342,26 @@ function SET_BASE:_FilterStart()
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Starts the filtering of the Dead events for the collection.
|
||||||
|
-- @param #SET_BASE self
|
||||||
|
-- @return #SET_BASE self
|
||||||
|
function SET_BASE:FilterDeads()
|
||||||
|
|
||||||
|
self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Starts the filtering of the Crash events for the collection.
|
||||||
|
-- @param #SET_BASE self
|
||||||
|
-- @return #SET_BASE self
|
||||||
|
function SET_BASE:FilterCrashes()
|
||||||
|
|
||||||
|
self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- Stops the filtering for the defined collection.
|
--- Stops the filtering for the defined collection.
|
||||||
-- @param #SET_BASE self
|
-- @param #SET_BASE self
|
||||||
-- @return #SET_BASE self
|
-- @return #SET_BASE self
|
||||||
@ -430,7 +450,7 @@ function SET_BASE:_EventOnDeadOrCrash( Event )
|
|||||||
|
|
||||||
if Event.IniDCSUnit then
|
if Event.IniDCSUnit then
|
||||||
local ObjectName, Object = self:FindInDatabase( Event )
|
local ObjectName, Object = self:FindInDatabase( Event )
|
||||||
if ObjectName and Object ~= nil then
|
if ObjectName then
|
||||||
self:Remove( ObjectName )
|
self:Remove( ObjectName )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -32,7 +32,11 @@
|
|||||||
do
|
do
|
||||||
|
|
||||||
--- @type SPOT
|
--- @type SPOT
|
||||||
-- @extends BASE
|
-- @extends Core.Base#BASE
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
-- @field #SPOT
|
||||||
SPOT = {
|
SPOT = {
|
||||||
ClassName = "SPOT",
|
ClassName = "SPOT",
|
||||||
}
|
}
|
||||||
@ -50,8 +54,61 @@ do
|
|||||||
|
|
||||||
self:SetStartState( "Off" )
|
self:SetStartState( "Off" )
|
||||||
self:AddTransition( "Off", "LaseOn", "On" )
|
self:AddTransition( "Off", "LaseOn", "On" )
|
||||||
|
|
||||||
|
--- LaseOn Handler OnBefore for SPOT
|
||||||
|
-- @function [parent=#SPOT] OnBeforeLaseOn
|
||||||
|
-- @param #SPOT self
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string To
|
||||||
|
-- @return #boolean
|
||||||
|
|
||||||
|
--- LaseOn Handler OnAfter for SPOT
|
||||||
|
-- @function [parent=#SPOT] OnAfterLaseOn
|
||||||
|
-- @param #SPOT self
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string To
|
||||||
|
|
||||||
|
--- LaseOn Trigger for SPOT
|
||||||
|
-- @function [parent=#SPOT] LaseOn
|
||||||
|
-- @param #SPOT self
|
||||||
|
|
||||||
|
--- LaseOn Asynchronous Trigger for SPOT
|
||||||
|
-- @function [parent=#SPOT] __LaseOn
|
||||||
|
-- @param #SPOT self
|
||||||
|
-- @param #number Delay
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self:AddTransition( "On", "Lasing", "On" )
|
self:AddTransition( "On", "Lasing", "On" )
|
||||||
self:AddTransition( "On" , "LaseOff", "Off" )
|
self:AddTransition( "On" , "LaseOff", "Off" )
|
||||||
|
|
||||||
|
--- LaseOff Handler OnBefore for SPOT
|
||||||
|
-- @function [parent=#SPOT] OnBeforeLaseOff
|
||||||
|
-- @param #SPOT self
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string To
|
||||||
|
-- @return #boolean
|
||||||
|
|
||||||
|
--- LaseOff Handler OnAfter for SPOT
|
||||||
|
-- @function [parent=#SPOT] OnAfterLaseOff
|
||||||
|
-- @param #SPOT self
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string To
|
||||||
|
|
||||||
|
--- LaseOff Trigger for SPOT
|
||||||
|
-- @function [parent=#SPOT] LaseOff
|
||||||
|
-- @param #SPOT self
|
||||||
|
|
||||||
|
--- LaseOff Asynchronous Trigger for SPOT
|
||||||
|
-- @function [parent=#SPOT] __LaseOff
|
||||||
|
-- @param #SPOT self
|
||||||
|
-- @param #number Delay
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.Recce = Recce
|
self.Recce = Recce
|
||||||
|
|
||||||
@ -87,9 +144,22 @@ do
|
|||||||
self.ScheduleID = self.LaseScheduler:Schedule( self, StopLase, {self}, Duration )
|
self.ScheduleID = self.LaseScheduler:Schedule( self, StopLase, {self}, Duration )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:HandleEvent( EVENTS.Dead )
|
||||||
|
|
||||||
self:__Lasing( -0.2 )
|
self:__Lasing( -0.2 )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param #SPOT self
|
||||||
|
-- @param Core.Event#EVENTDATA EventData
|
||||||
|
function SPOT:OnEventDead(EventData)
|
||||||
|
if self.Target then
|
||||||
|
if EventData.IniDCSUnitName == self.Target:GetName() then
|
||||||
|
self:E( {"Target dead ", self.Target:GetName() } )
|
||||||
|
self:__LaseOff( 0.1 )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- @param #SPOT self
|
--- @param #SPOT self
|
||||||
-- @param From
|
-- @param From
|
||||||
-- @param Event
|
-- @param Event
|
||||||
@ -112,6 +182,7 @@ do
|
|||||||
-- @return #SPOT
|
-- @return #SPOT
|
||||||
function SPOT:onafterLaseOff( From, Event, To )
|
function SPOT:onafterLaseOff( From, Event, To )
|
||||||
|
|
||||||
|
self:E( {"Stopped lasing for ", self.Target:GetName() } )
|
||||||
self.Spot:destroy()
|
self.Spot:destroy()
|
||||||
self.Spot = nil
|
self.Spot = nil
|
||||||
if self.ScheduleID then
|
if self.ScheduleID then
|
||||||
@ -120,7 +191,6 @@ do
|
|||||||
self.ScheduleID = nil
|
self.ScheduleID = nil
|
||||||
|
|
||||||
self.Target = nil
|
self.Target = nil
|
||||||
self.LaserCode = nil
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|||||||
@ -506,8 +506,6 @@ do -- DETECTION_BASE
|
|||||||
self.DetectionRun = 0
|
self.DetectionRun = 0
|
||||||
self:UnIdentifyAllDetectedObjects() -- Resets the DetectedObjectsIdentified table
|
self:UnIdentifyAllDetectedObjects() -- Resets the DetectedObjectsIdentified table
|
||||||
|
|
||||||
self.DetectionSetGroup:Flush()
|
|
||||||
|
|
||||||
for DetectionGroupID, DetectionGroupData in pairs( self.DetectionSetGroup:GetSet() ) do
|
for DetectionGroupID, DetectionGroupData in pairs( self.DetectionSetGroup:GetSet() ) do
|
||||||
self:E( {DetectionGroupData})
|
self:E( {DetectionGroupData})
|
||||||
self:__DetectionGroup( DetectDelay, DetectionGroupData ) -- Process each detection asynchronously.
|
self:__DetectionGroup( DetectDelay, DetectionGroupData ) -- Process each detection asynchronously.
|
||||||
@ -1132,7 +1130,7 @@ do -- DETECTION_BASE
|
|||||||
self.DetectedItems[self.DetectedItemCount] = DetectedItem
|
self.DetectedItems[self.DetectedItemCount] = DetectedItem
|
||||||
end
|
end
|
||||||
|
|
||||||
DetectedItem.Set = Set or SET_UNIT:New()
|
DetectedItem.Set = Set or SET_UNIT:New():FilterDeads():FilterCrashes()
|
||||||
DetectedItem.ItemID = self.DetectedItemMax
|
DetectedItem.ItemID = self.DetectedItemMax
|
||||||
DetectedItem.Removed = false
|
DetectedItem.Removed = false
|
||||||
|
|
||||||
|
|||||||
@ -475,7 +475,7 @@ function POSITIONABLE:LaseUnit( Target, LaserCode, Duration )
|
|||||||
local TargetVec3 = Target:GetVec3()
|
local TargetVec3 = Target:GetVec3()
|
||||||
|
|
||||||
self:E("bulding spot")
|
self:E("bulding spot")
|
||||||
self.Spot = SPOT:New( self )
|
self.Spot = SPOT:New( self ) -- Core.Spot#SPOT
|
||||||
self.Spot:LaseOn( Target, LaserCode, Duration)
|
self.Spot:LaseOn( Target, LaserCode, Duration)
|
||||||
|
|
||||||
return self.Spot
|
return self.Spot
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user