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
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @param #number Delay
|
||||
|
||||
|
||||
|
||||
self:AddTransition( "*", "LaseOn", "Lasing" )
|
||||
|
||||
@ -237,6 +239,9 @@ do -- AI_DESIGNATE
|
||||
|
||||
self:SetLaserCodes( 1688 )
|
||||
|
||||
self.LaserCodesUsed = {}
|
||||
|
||||
|
||||
self.Detection:__Start( 2 )
|
||||
|
||||
|
||||
@ -253,6 +258,8 @@ do -- AI_DESIGNATE
|
||||
|
||||
self.LaserCodes = ( type( LaserCodes ) == "table" ) and LaserCodes or { LaserCodes }
|
||||
self:E(self.LaserCodes)
|
||||
|
||||
self.LaserCodesUsed = {}
|
||||
|
||||
return self
|
||||
end
|
||||
@ -303,6 +310,8 @@ do -- AI_DESIGNATE
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:SetDesignateMenu()
|
||||
|
||||
self.GroupSet:Flush()
|
||||
|
||||
self.GroupSet:ForEachGroup(
|
||||
|
||||
--- @param Wrapper.Group#GROUP GroupReport
|
||||
@ -330,39 +339,35 @@ do -- AI_DESIGNATE
|
||||
DesignateMenu
|
||||
)
|
||||
|
||||
if self.Spots[Index] then
|
||||
|
||||
MENU_GROUP_COMMAND:New(
|
||||
AttackGroup,
|
||||
"Switch laser Off",
|
||||
DetectedMenu,
|
||||
self.MenuLaseOff,
|
||||
self,
|
||||
AttackGroup,
|
||||
Index
|
||||
)
|
||||
else
|
||||
MENU_GROUP_COMMAND:New(
|
||||
AttackGroup,
|
||||
"Lase target 60 secs",
|
||||
DetectedMenu,
|
||||
self.MenuLaseOn,
|
||||
self,
|
||||
AttackGroup,
|
||||
Index,
|
||||
60
|
||||
)
|
||||
MENU_GROUP_COMMAND:New(
|
||||
AttackGroup,
|
||||
"Lase target 120 secs",
|
||||
DetectedMenu,
|
||||
self.MenuLaseOn,
|
||||
self,
|
||||
AttackGroup,
|
||||
Index,
|
||||
120
|
||||
)
|
||||
end
|
||||
MENU_GROUP_COMMAND:New(
|
||||
AttackGroup,
|
||||
"Lase target 60 secs",
|
||||
DetectedMenu,
|
||||
self.MenuLaseOn,
|
||||
self,
|
||||
AttackGroup,
|
||||
Index,
|
||||
60
|
||||
)
|
||||
MENU_GROUP_COMMAND:New(
|
||||
AttackGroup,
|
||||
"Lase target 120 secs",
|
||||
DetectedMenu,
|
||||
self.MenuLaseOn,
|
||||
self,
|
||||
AttackGroup,
|
||||
Index,
|
||||
120
|
||||
)
|
||||
MENU_GROUP_COMMAND:New(
|
||||
AttackGroup,
|
||||
"Switch laser Off",
|
||||
DetectedMenu,
|
||||
self.MenuLaseOff,
|
||||
self,
|
||||
AttackGroup,
|
||||
Index
|
||||
)
|
||||
|
||||
MENU_GROUP_COMMAND:New(
|
||||
AttackGroup,
|
||||
@ -425,43 +430,63 @@ do -- AI_DESIGNATE
|
||||
function AI_DESIGNATE:onafterLasing( From, Event, To, AttackGroup, Index, Duration )
|
||||
|
||||
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(
|
||||
--- @param Wrapper.Unit#UNIT SmokeUnit
|
||||
function( SmokeUnit )
|
||||
function( TargetUnit )
|
||||
self:E("In procedure")
|
||||
--if math.random( 1, ( 100 * TargetSetUnit:Count() ) / 100 ) <= 100 then
|
||||
if SmokeUnit:IsAlive() then
|
||||
local NearestRecceGroup = self.RecceSet:FindNearestGroupFromPointVec2( SmokeUnit:GetPointVec2() )
|
||||
if NearestRecceGroup then
|
||||
for UnitID, UnitData in pairs( NearestRecceGroup:GetUnits() or {} ) do
|
||||
local RecceUnit = UnitData -- Wrapper.Unit#UNIT
|
||||
Targets = true
|
||||
if RecceUnit:IsLasing() == false then
|
||||
self.Spots[Index] = self.Spots[Index] or {}
|
||||
local Spots = self.Spots[Index]
|
||||
local LaserCode = self.LaserCodes[math.random(1, #self.LaserCodes)]
|
||||
local Spot = RecceUnit:LaseUnit( SmokeUnit, LaserCode, Duration )
|
||||
Spots[RecceUnit] = Spot
|
||||
RecceUnit:MessageToGroup( "Lasing " .. SmokeUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup )
|
||||
break
|
||||
else
|
||||
if TargetUnit:IsAlive() then
|
||||
local Spot = self.Spots[TargetUnit]
|
||||
if (not Spot) or ( Spot and Spot:IsLasing() == false ) then
|
||||
local NearestRecceGroup = self.RecceSet:FindNearestGroupFromPointVec2( TargetUnit:GetPointVec2() )
|
||||
if NearestRecceGroup then
|
||||
for UnitID, UnitData in pairs( NearestRecceGroup:GetUnits() or {} ) do
|
||||
local RecceUnit = UnitData -- Wrapper.Unit#UNIT
|
||||
if RecceUnit:IsLasing() == false then
|
||||
local LaserCodeIndex = math.random(1, #self.LaserCodes)
|
||||
local LaserCode = self.LaserCodes[LaserCodeIndex]
|
||||
if not self.LaserCodesUsed[LaserCode] then
|
||||
MoreTargets = true
|
||||
self.LaserCodesUsed[LaserCode] = LaserCodeIndex
|
||||
local Spot = RecceUnit:LaseUnit( TargetUnit, LaserCode, Duration )
|
||||
self.Spots[TargetUnit] = Spot
|
||||
RecceUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup )
|
||||
break
|
||||
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
|
||||
else
|
||||
self.Spots[TargetUnit] = nil
|
||||
end
|
||||
--end
|
||||
end
|
||||
)
|
||||
|
||||
if Targets == true then
|
||||
if MoreTargets == true then
|
||||
self:__Lasing( -30, AttackGroup, Index, Duration )
|
||||
else
|
||||
self:__LaseOff( -0.2, AttackGroup, Index )
|
||||
end
|
||||
|
||||
self:__LaseOff( 1, AttackGroup, Index )
|
||||
end
|
||||
self:SetDesignateMenu()
|
||||
|
||||
end
|
||||
@ -471,9 +496,11 @@ do -- AI_DESIGNATE
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:onafterLaseOff( From, Event, To, AttackGroup, Index )
|
||||
|
||||
self.RecceSet:GetFirst():MessageToGroup( "Stopped lasing.", 15, AttackGroup )
|
||||
|
||||
local TargetSetUnit = self.Detection:GetDetectedSet( Index )
|
||||
|
||||
local Spots = self.Spots[Index]
|
||||
local Spots = self.Spots
|
||||
|
||||
for SpotID, SpotData in pairs( Spots ) do
|
||||
local Spot = SpotData -- Core.Spot#SPOT
|
||||
@ -482,7 +509,8 @@ do -- AI_DESIGNATE
|
||||
end
|
||||
|
||||
Spots = nil
|
||||
self.Spots[Index] = nil
|
||||
self.Spots = {}
|
||||
self.LaserCodesUsed = {}
|
||||
|
||||
self:SetDesignateMenu()
|
||||
end
|
||||
|
||||
@ -454,6 +454,12 @@ do -- Event Handling
|
||||
-- @param #BASE self
|
||||
-- @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.
|
||||
-- initiator : The unit that is was destroyed.
|
||||
-- @function [parent=#BASE] OnEvent
|
||||
|
||||
@ -342,6 +342,26 @@ function SET_BASE:_FilterStart()
|
||||
return self
|
||||
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.
|
||||
-- @param #SET_BASE self
|
||||
-- @return #SET_BASE self
|
||||
@ -430,7 +450,7 @@ function SET_BASE:_EventOnDeadOrCrash( Event )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
local ObjectName, Object = self:FindInDatabase( Event )
|
||||
if ObjectName and Object ~= nil then
|
||||
if ObjectName then
|
||||
self:Remove( ObjectName )
|
||||
end
|
||||
end
|
||||
|
||||
@ -32,7 +32,11 @@
|
||||
do
|
||||
|
||||
--- @type SPOT
|
||||
-- @extends BASE
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
|
||||
---
|
||||
-- @field #SPOT
|
||||
SPOT = {
|
||||
ClassName = "SPOT",
|
||||
}
|
||||
@ -50,8 +54,61 @@ do
|
||||
|
||||
self:SetStartState( "Off" )
|
||||
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" , "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
|
||||
|
||||
@ -87,9 +144,22 @@ do
|
||||
self.ScheduleID = self.LaseScheduler:Schedule( self, StopLase, {self}, Duration )
|
||||
end
|
||||
|
||||
self:HandleEvent( EVENTS.Dead )
|
||||
|
||||
self:__Lasing( -0.2 )
|
||||
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 From
|
||||
-- @param Event
|
||||
@ -112,6 +182,7 @@ do
|
||||
-- @return #SPOT
|
||||
function SPOT:onafterLaseOff( From, Event, To )
|
||||
|
||||
self:E( {"Stopped lasing for ", self.Target:GetName() } )
|
||||
self.Spot:destroy()
|
||||
self.Spot = nil
|
||||
if self.ScheduleID then
|
||||
@ -120,7 +191,6 @@ do
|
||||
self.ScheduleID = nil
|
||||
|
||||
self.Target = nil
|
||||
self.LaserCode = nil
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@ -506,8 +506,6 @@ do -- DETECTION_BASE
|
||||
self.DetectionRun = 0
|
||||
self:UnIdentifyAllDetectedObjects() -- Resets the DetectedObjectsIdentified table
|
||||
|
||||
self.DetectionSetGroup:Flush()
|
||||
|
||||
for DetectionGroupID, DetectionGroupData in pairs( self.DetectionSetGroup:GetSet() ) do
|
||||
self:E( {DetectionGroupData})
|
||||
self:__DetectionGroup( DetectDelay, DetectionGroupData ) -- Process each detection asynchronously.
|
||||
@ -1132,7 +1130,7 @@ do -- DETECTION_BASE
|
||||
self.DetectedItems[self.DetectedItemCount] = DetectedItem
|
||||
end
|
||||
|
||||
DetectedItem.Set = Set or SET_UNIT:New()
|
||||
DetectedItem.Set = Set or SET_UNIT:New():FilterDeads():FilterCrashes()
|
||||
DetectedItem.ItemID = self.DetectedItemMax
|
||||
DetectedItem.Removed = false
|
||||
|
||||
|
||||
@ -475,7 +475,7 @@ function POSITIONABLE:LaseUnit( Target, LaserCode, Duration )
|
||||
local TargetVec3 = Target:GetVec3()
|
||||
|
||||
self:E("bulding spot")
|
||||
self.Spot = SPOT:New( self )
|
||||
self.Spot = SPOT:New( self ) -- Core.Spot#SPOT
|
||||
self.Spot:LaseOn( Target, LaserCode, Duration)
|
||||
|
||||
return self.Spot
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user