mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge branch 'master' into ForEachStatic
This commit is contained in:
@@ -1,9 +1,35 @@
|
||||
--- **AI (Release 2.1)** -- Management of target designation.
|
||||
--- **AI R2.1** -- Management of target **Designation**.
|
||||
--
|
||||
-- --
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- AI_DESIGNATE is orchestrating the designation of potential targets executed by a Recce group,
|
||||
-- and communicates these to a dedicated attacking group of players,
|
||||
-- so that following a dynamically generated menu system,
|
||||
-- each detected set of potential targets can be lased or smoked...
|
||||
--
|
||||
-- Targets can be:
|
||||
--
|
||||
-- * **Lased** for a period of time.
|
||||
-- * **Smoked**. Artillery or airplanes with Illuminatino ordonance need to be present. (WIP, but early demo ready.)
|
||||
-- * **Illuminated** through an illumination bomb. Artillery or airplanes with Illuminatino ordonance need to be present. (WIP, but early demo ready.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # **AUTHORS and CONTRIBUTIONS**
|
||||
--
|
||||
-- ### Contributions:
|
||||
--
|
||||
-- * [**Ciribob**](https://forums.eagle.ru/member.php?u=112175): Showing the way how to lase targets + how laser codes work!!! Explained the autolase script.
|
||||
-- * [**EasyEB**](https://forums.eagle.ru/member.php?u=112055): Ideas and Beta Testing
|
||||
-- * [**Wingthor**](https://forums.eagle.ru/member.php?u=123698): Beta Testing
|
||||
--
|
||||
--
|
||||
-- ### Authors:
|
||||
--
|
||||
-- * **FlightControl**: Design & Programming
|
||||
--
|
||||
-- @module AI_Designate
|
||||
|
||||
|
||||
@@ -19,20 +45,57 @@ do -- AI_DESIGNATE
|
||||
-- so that following a dynamically generated menu system,
|
||||
-- each detected set of potential targets can be lased or smoked...
|
||||
--
|
||||
-- The Recce group is detecting as part of the DETECTION_ class continuously targets.
|
||||
-- Once targets have been detected, they will be reported. The AI_DESIGNATE object will fire the **Detect** event in this case!
|
||||
-- As part of the reporting, the following happens:
|
||||
-- Targets can be:
|
||||
--
|
||||
-- * A message is sent to each GROUP of the Attack SET_GROUP, containing the threat level and the target composition.
|
||||
-- * A menu is created and updated for each GROUP of the Attack SET_GROUP, containing the the treat level and the target composition.
|
||||
-- * **Lased** for a period of time.
|
||||
-- * **Smoked**. Artillery or airplanes with Illuminatino ordonance need to be present. (WIP, but early demo ready.)
|
||||
-- * **Illuminated** through an illumination bomb. Artillery or airplanes with Illuminatino ordonance need to be present. (WIP, but early demo ready.
|
||||
--
|
||||
-- One of the players in one of the Attack GROUPs, can then select a Target Set by selecting one of the menu options.
|
||||
-- Each menu option has two modes:
|
||||
-- The following terminology is being used throughout this document:
|
||||
--
|
||||
-- * If the Target Set is not being designated, then the Designate menu for the target Set will provide options to Lase or Smoke the targets.
|
||||
-- * If the Target Set is being designated, then the Designate menu will provide an option to cancel the designation.
|
||||
-- * The **DesignateObject** is the object of the AI_DESIGNATE class, which is this class explained in the document.
|
||||
-- * The **DetectionObject** is the object of a DETECTION_ class (DETECTION_TYPES, DETECTION_AREAS, DETECTION_UNITS), which is executing the detection and grouping of Targets into _DetectionItems_.
|
||||
-- * **DetectionItems** is the list of detected target groupings by the _DetectionObject_. Each _DetectionItem_ contains a _TargetSet_.
|
||||
-- * **DetectionItem** is one element of the _DetectionItems_ list, and contains a _TargetSet_.
|
||||
-- * The **TargetSet** is a SET_UNITS collection of _Targets_, that have been detected by the _DetectionObject_.
|
||||
-- * A **Target** is a detected UNIT object by the _DetectionObject_.
|
||||
-- * A **Threat Level** is a number from 0 to 10 that is calculated based on the threat of the Target in an Air to Ground battle scenario.
|
||||
-- * The **RecceSet** is a SET_GROUP collection that contains the **RecceGroups**.
|
||||
-- * A **RecceGroup** is a GROUP object containing the **Recces**.
|
||||
-- * A **Recce** is a UNIT object executing the reconnaissance as part the _DetectionObject_. A Recce can be of any UNIT type.
|
||||
-- * An **AttackGroup** is a GROUP object that contain _Players_.
|
||||
-- * A **Player** is an active CLIENT object containing a human player.
|
||||
-- * A **Designate Menu** is the menu that is dynamically created during the designation process for each _AttackGroup_.
|
||||
--
|
||||
-- In this way, the AI can assist players to designate ground targets for a coordinated attack!
|
||||
-- The _RecceSet_ is continuously detecting for potential _Targets_, executing its task as part of the _DetectionObject_.
|
||||
-- Once _Targets_ have been detected, the _DesignateObject_ will trigger the **Detect Event**.
|
||||
--
|
||||
-- As part of the Detect Event, the _DetectionItems_ list is used by the _DesignateObject_ to provide the _Players_ with:
|
||||
--
|
||||
-- * The _RecceGroups_ are reporting to each _AttackGroup_, sending **Messages** containing the _Threat Level_ and the _TargetSet_ composition.
|
||||
-- * **Menu options** are created and updated for each _AttackGroup_, containing the _Threat Level_ and the _TargetSet_ composition.
|
||||
--
|
||||
-- A _Player_ can then select an action from the _Designate Menu_.
|
||||
--
|
||||
-- **Note that each selected action will be executed for a _TargetSet_, thus the _Target_ grouping done by the _DetectionObject_.**
|
||||
--
|
||||
-- Each **Menu Option** in the _Designate Menu_ has two modes:
|
||||
--
|
||||
-- 1. If the _TargetSet_ **is not being designated**, then the **Designate Menu** option for the target Set will provide options to **Lase** or **Smoke** the targets.
|
||||
-- 2. If the Target Set **is being designated**, then the **Designate Menu** option will provide an option to stop or cancel the designation.
|
||||
--
|
||||
-- While designating, the _RecceGroups_ will report any change in _TargetSet_ composition or _Target_ presence.
|
||||
--
|
||||
-- The following logic is executed when a _TargetSet_ is selected to be *lased* from the _Designation Menu_:
|
||||
--
|
||||
-- * The _RecceSet_ is searched for any _Recce_ that is within *designation distance* from a _Target_ in the _TargetSet_ that is currently not being designated.
|
||||
-- * If there is a _Recce_ found that is currently no designating a target, and is within designation distance from the _Target_, then that _Target_ will be designated.
|
||||
-- * During designation, any _Recce_ that does not have Line of Sight (LOS) and is not within disignation distance from the _Target_, will stop designating the _Target_, and a report is given.
|
||||
-- * When a _Recce_ is designating a _Target_, and that _Target_ is destroyed, then the _Recce_ will stop designating the _Target_, and will report the event.
|
||||
-- * When a _Recce_ is designating a _Target_, and that _Recce_ is destroyed, then the _Recce_ will be removed from the _RecceSet_ and designation will stop without reporting.
|
||||
-- * When all _RecceGroups_ are destroyed from the _RecceSet_, then the DesignationObject will stop functioning, and nothing will be reported.
|
||||
--
|
||||
-- In this way, the DesignationObject assists players to designate ground targets for a coordinated attack!
|
||||
--
|
||||
-- Have FUN!
|
||||
--
|
||||
@@ -42,7 +105,7 @@ do -- AI_DESIGNATE
|
||||
--
|
||||
-- ## 2. AI_DESIGNATE is a FSM
|
||||
--
|
||||
-- 
|
||||
-- ![Process]()
|
||||
--
|
||||
-- ### 2.1 AI_DESIGNATE States
|
||||
--
|
||||
@@ -74,7 +137,16 @@ do -- AI_DESIGNATE
|
||||
--
|
||||
-- The above sets a collection of possible laser codes that can be assigned. **Note the { } notation!**
|
||||
--
|
||||
-- ## 4. Autolase to automatically lase detected targets.
|
||||
--
|
||||
-- _DetectionItems_ can be auto lased once detected by _Recces_. As such, there is almost no action required from the _Players_ using the _Designate Menu_.
|
||||
-- The **auto lase** function can be activated through the Designation Menu.
|
||||
-- Use the method @{#AI_DESIGNATE.SetAutoLase}() to activate or deactivate the auto lase function programmatically.
|
||||
-- Note that autolase will automatically activate lasing for ALL _DetectedItems_. Individual items can be switched-off if required using the _Designation Menu_.
|
||||
--
|
||||
-- AIDesignate:SetAutoLase( true )
|
||||
--
|
||||
-- Activate the auto lasing.
|
||||
--
|
||||
-- @field #AI_DESIGNATE
|
||||
--
|
||||
@@ -85,9 +157,9 @@ do -- AI_DESIGNATE
|
||||
--- AI_DESIGNATE Constructor. This class is an abstract class and should not be instantiated.
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @param Functional.Detection#DETECTION_BASE Detection
|
||||
-- @param Core.Set#SET_GROUP GroupSet The set of groups to designate for.
|
||||
-- @param Core.Set#SET_GROUP AttackSet The Attack collection of GROUP objects to designate and report for.
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:New( Detection, GroupSet )
|
||||
function AI_DESIGNATE:New( Detection, AttackSet )
|
||||
|
||||
local self = BASE:Inherit( self, FSM:New() ) -- #AI_DESIGNATE
|
||||
self:F( { Detection } )
|
||||
@@ -118,6 +190,8 @@ do -- AI_DESIGNATE
|
||||
-- @function [parent=#AI_DESIGNATE] __Detect
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @param #number Delay
|
||||
|
||||
|
||||
|
||||
self:AddTransition( "*", "LaseOn", "Lasing" )
|
||||
|
||||
@@ -147,7 +221,6 @@ do -- AI_DESIGNATE
|
||||
|
||||
self:AddTransition( "Lasing", "Lasing", "Lasing" )
|
||||
|
||||
|
||||
self:AddTransition( "*", "LaseOff", "Designate" )
|
||||
|
||||
--- LaseOff Handler OnBefore for AI_DESIGNATE
|
||||
@@ -202,7 +275,33 @@ do -- AI_DESIGNATE
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @param #number Delay
|
||||
|
||||
self:AddTransition( "*", "Illuminate", "*" )
|
||||
|
||||
--- Illuminate Handler OnBefore for AI_DESIGNATE
|
||||
-- @function [parent=#AI_DESIGNATE] OnBeforeIlluminate
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
-- @return #boolean
|
||||
|
||||
--- Illuminate Handler OnAfter for AI_DESIGNATE
|
||||
-- @function [parent=#AI_DESIGNATE] OnAfterIlluminate
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
|
||||
--- Illuminate Trigger for AI_DESIGNATE
|
||||
-- @function [parent=#AI_DESIGNATE] Illuminate
|
||||
-- @param #AI_DESIGNATE self
|
||||
|
||||
--- Illuminate Asynchronous Trigger for AI_DESIGNATE
|
||||
-- @function [parent=#AI_DESIGNATE] __Illuminate
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @param #number Delay
|
||||
|
||||
self:AddTransition( "*", "Done", "*" )
|
||||
|
||||
self:AddTransition( "*", "Status", "*" )
|
||||
|
||||
@@ -231,14 +330,22 @@ do -- AI_DESIGNATE
|
||||
-- @param #number Delay
|
||||
|
||||
self.Detection = Detection
|
||||
self.GroupSet = GroupSet
|
||||
self.AttackSet = AttackSet
|
||||
self.RecceSet = Detection:GetDetectionSetGroup()
|
||||
self.Spots = {}
|
||||
self.Recces = {}
|
||||
self.Designating = {}
|
||||
|
||||
self.LaseDuration = 60
|
||||
|
||||
self:SetLaserCodes( 1688 ) -- set self.LaserCodes
|
||||
self:SetAutoLase( false ) -- set self.Autolase
|
||||
|
||||
self.LaserCodesUsed = {}
|
||||
|
||||
self:SetLaserCodes( 1688 )
|
||||
|
||||
self.Detection:__Start( 2 )
|
||||
|
||||
|
||||
self:SetDesignateMenu()
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -249,10 +356,35 @@ do -- AI_DESIGNATE
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @param #list<#number> LaserCodes
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:SetLaserCodes( LaserCodes )
|
||||
function AI_DESIGNATE:SetLaserCodes( LaserCodes ) --R2.1
|
||||
|
||||
self.LaserCodes = ( type( LaserCodes ) == "table" ) and LaserCodes or { LaserCodes }
|
||||
self:E(self.LaserCodes)
|
||||
|
||||
self.LaserCodesUsed = {}
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set auto lase.
|
||||
-- Auto lase will start lasing targets immediately when these are in range.
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @param #boolean AutoLase
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:SetAutoLase( AutoLase ) --R2.1
|
||||
|
||||
self.AutoLase = AutoLase
|
||||
|
||||
local AutoLaseOnOff = ( AutoLase == true ) and "On" or "Off"
|
||||
|
||||
local Recce = self.RecceSet:GetFirst()
|
||||
|
||||
if Recce then
|
||||
Recce:MessageToSetGroup( "Auto Lase " .. AutoLaseOnOff .. ".", 15, self.AttackSet )
|
||||
end
|
||||
|
||||
self:ActivateAutoLase()
|
||||
self:SetDesignateMenu()
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -265,7 +397,11 @@ do -- AI_DESIGNATE
|
||||
|
||||
self:__Detect( -60 )
|
||||
|
||||
self:ActivateAutoLase()
|
||||
|
||||
self:SendStatus()
|
||||
|
||||
|
||||
self:SetDesignateMenu()
|
||||
|
||||
return self
|
||||
@@ -287,11 +423,32 @@ do -- AI_DESIGNATE
|
||||
|
||||
local RecceLeader = self.RecceSet:GetFirst() -- Wrapper.Group#GROUP
|
||||
|
||||
self.GroupSet:ForEachGroup(
|
||||
RecceLeader:MessageToSetGroup( DetectedReport:Text( "\n" ), 15, self.AttackSet )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Coordinates the Auto Lase.
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:ActivateAutoLase()
|
||||
|
||||
self.AttackSet:Flush()
|
||||
|
||||
self.AttackSet:ForEachGroup(
|
||||
|
||||
--- @param Wrapper.Group#GROUP GroupReport
|
||||
function( AttackGroup )
|
||||
RecceLeader:MessageToGroup( DetectedReport:Text( "\n" ), 15, AttackGroup )
|
||||
|
||||
local DetectedItems = self.Detection:GetDetectedItems()
|
||||
|
||||
for Index, DetectedItemData in pairs( DetectedItems ) do
|
||||
if self.AutoLase then
|
||||
if not self.Designating[Index] then
|
||||
self:LaseOn( Index, self.LaseDuration )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
@@ -303,7 +460,9 @@ do -- AI_DESIGNATE
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:SetDesignateMenu()
|
||||
|
||||
self.GroupSet:ForEachGroup(
|
||||
self.AttackSet:Flush()
|
||||
|
||||
self.AttackSet:ForEachGroup(
|
||||
|
||||
--- @param Wrapper.Group#GROUP GroupReport
|
||||
function( AttackGroup )
|
||||
@@ -313,10 +472,19 @@ do -- AI_DESIGNATE
|
||||
DesignateMenu = nil
|
||||
self:E("Remove Menu")
|
||||
end
|
||||
DesignateMenu = MENU_GROUP:New( AttackGroup, "Designate Targets" )
|
||||
DesignateMenu = MENU_GROUP:New( AttackGroup, "Designate" )
|
||||
self:E(DesignateMenu)
|
||||
AttackGroup:SetState( AttackGroup, "DesignateMenu", DesignateMenu )
|
||||
|
||||
-- Set Menu option for auto lase
|
||||
|
||||
if self.AutoLase then
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Auto Lase Off", DesignateMenu, self.MenuAutoLase, self, false )
|
||||
else
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Auto Lase On", DesignateMenu, self.MenuAutoLase, self, true )
|
||||
end
|
||||
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Report Designation Status", DesignateMenu, self.MenuStatus, self, AttackGroup )
|
||||
|
||||
local DetectedItems = self.Detection:GetDetectedItems()
|
||||
|
||||
@@ -324,144 +492,184 @@ do -- AI_DESIGNATE
|
||||
|
||||
local Report = self.Detection:DetectedItemReportSummary( Index )
|
||||
|
||||
local DetectedMenu = MENU_GROUP:New(
|
||||
AttackGroup,
|
||||
Report,
|
||||
DesignateMenu
|
||||
)
|
||||
|
||||
if self.Spots[Index] then
|
||||
|
||||
MENU_GROUP_COMMAND:New(
|
||||
AttackGroup,
|
||||
"Switch laser Off",
|
||||
DetectedMenu,
|
||||
self.MenuLaseOff,
|
||||
self,
|
||||
AttackGroup,
|
||||
Index
|
||||
)
|
||||
if not self.Designating[Index] then
|
||||
local DetectedMenu = MENU_GROUP:New( AttackGroup, Report, DesignateMenu )
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Lase target 60 secs", DetectedMenu, self.MenuLaseOn, self, Index, 60 )
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Lase target 120 secs", DetectedMenu, self.MenuLaseOn, self, Index, 120 )
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Smoke red", DetectedMenu, self.MenuSmoke, self, Index, SMOKECOLOR.Red )
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Smoke blue", DetectedMenu, self.MenuSmoke, self, Index, SMOKECOLOR.Blue )
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Smoke green", DetectedMenu, self.MenuSmoke, self, Index, SMOKECOLOR.Green )
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Smoke white", DetectedMenu, self.MenuSmoke, self, Index, SMOKECOLOR.White )
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Smoke orange", DetectedMenu, self.MenuSmoke, self, Index, SMOKECOLOR.Orange )
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Illuminate", DetectedMenu, self.MenuIlluminate, self, 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
|
||||
)
|
||||
if self.Designating[Index] == "Laser" then
|
||||
Report = "Lasing " .. Report
|
||||
elseif self.Designating[Index] == "Smoke" then
|
||||
Report = "Smoking " .. Report
|
||||
elseif self.Designating[Index] == "Illuminate" then
|
||||
Report = "Illuminating " .. Report
|
||||
end
|
||||
local DetectedMenu = MENU_GROUP:New( AttackGroup, Report, DesignateMenu )
|
||||
if self.Designating[Index] == "Laser" then
|
||||
MENU_GROUP_COMMAND:New( AttackGroup, "Stop lasing", DetectedMenu, self.MenuLaseOff, self, Index )
|
||||
else
|
||||
end
|
||||
end
|
||||
|
||||
MENU_GROUP_COMMAND:New(
|
||||
AttackGroup,
|
||||
"Smoke",
|
||||
DetectedMenu,
|
||||
self.MenuSmoke,
|
||||
self,
|
||||
AttackGroup,
|
||||
Index
|
||||
)
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
---
|
||||
-- @param #AI_DESIGNATE self
|
||||
function AI_DESIGNATE:MenuStatus( AttackGroup )
|
||||
|
||||
self:E("Status")
|
||||
|
||||
self.RecceSet:ForEachGroup(
|
||||
function( RecceGroup )
|
||||
local RecceUnits = RecceGroup:GetUnits()
|
||||
for UnitID, RecceData in pairs( RecceUnits ) do
|
||||
local Recce = RecceData -- Wrapper.Unit#UNIT
|
||||
if Recce:IsLasing() then
|
||||
Recce:MessageToGroup( "Marking " .. Recce:GetSpot().Target:GetTypeName() .. " with laser " .. Recce:GetSpot().LaserCode .. ".", 5, AttackGroup )
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- @param #AI_DESIGNATE self
|
||||
function AI_DESIGNATE:MenuSmoke( AttackGroup, Index )
|
||||
function AI_DESIGNATE:MenuAutoLase( AutoLase )
|
||||
|
||||
self:E("AutoLase")
|
||||
|
||||
self:SetAutoLase( AutoLase )
|
||||
end
|
||||
|
||||
---
|
||||
-- @param #AI_DESIGNATE self
|
||||
function AI_DESIGNATE:MenuSmoke( Index, Color )
|
||||
|
||||
self:E("Designate through Smoke")
|
||||
|
||||
self:__Smoke( 1, AttackGroup, Index )
|
||||
self.Designating[Index] = "Smoke"
|
||||
self:__Smoke( 1, Index, Color )
|
||||
end
|
||||
|
||||
---
|
||||
-- @param #AI_DESIGNATE self
|
||||
function AI_DESIGNATE:MenuLaseOn( AttackGroup, Index, Duration )
|
||||
function AI_DESIGNATE:MenuIlluminate( Index )
|
||||
|
||||
self:E("Designate through Illumination")
|
||||
|
||||
self.Designating[Index] = "Illuminate"
|
||||
|
||||
self:__Illuminate( 1, Index )
|
||||
end
|
||||
|
||||
---
|
||||
-- @param #AI_DESIGNATE self
|
||||
function AI_DESIGNATE:MenuLaseOn( Index, Duration )
|
||||
|
||||
self:E("Designate through Lase")
|
||||
|
||||
self:__LaseOn( 1, AttackGroup, Index, Duration )
|
||||
|
||||
self:__LaseOn( 1, Index, Duration )
|
||||
end
|
||||
|
||||
---
|
||||
-- @param #AI_DESIGNATE self
|
||||
function AI_DESIGNATE:MenuLaseOff( AttackGroup, Index, Duration )
|
||||
function AI_DESIGNATE:MenuLaseOff( Index, Duration )
|
||||
|
||||
self:E("Lasing off")
|
||||
|
||||
self:__LaseOff( 1, AttackGroup, Index )
|
||||
self.Designating[Index] = nil
|
||||
self:__LaseOff( 1, Index )
|
||||
end
|
||||
|
||||
---
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:onafterLaseOn( From, Event, To, AttackGroup, Index, Duration )
|
||||
|
||||
self:__Lasing( -5, AttackGroup, Index, Duration )
|
||||
function AI_DESIGNATE:onafterLaseOn( From, Event, To, Index, Duration )
|
||||
|
||||
self.Designating[Index] = "Laser"
|
||||
self:Lasing( Index, Duration )
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:onafterLasing( From, Event, To, AttackGroup, Index, Duration )
|
||||
function AI_DESIGNATE:onafterLasing( From, Event, To, Index, Duration )
|
||||
|
||||
local TargetSetUnit = self.Detection:GetDetectedSet( Index )
|
||||
|
||||
local Targets = false
|
||||
|
||||
TargetSetUnit:Flush()
|
||||
|
||||
for TargetUnit, RecceData in pairs( self.Recces ) do
|
||||
local Recce = RecceData -- Wrapper.Unit#UNIT
|
||||
if not Recce:IsLasing() then
|
||||
local LaserCode = Recce:GetLaserCode() --(Not deleted when stopping with lasing).
|
||||
self.LaserCodesUsed[LaserCode] = nil
|
||||
self.Recces[TargetUnit] = nil
|
||||
end
|
||||
end
|
||||
|
||||
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 Recce = self.Recces[TargetUnit]
|
||||
if not Recce then
|
||||
for RecceGroupID, RecceGroup in pairs( self.RecceSet:GetSet() ) do
|
||||
for UnitID, UnitData in pairs( RecceGroup:GetUnits() or {} ) do
|
||||
local RecceUnit = UnitData -- Wrapper.Unit#UNIT
|
||||
if RecceUnit:IsLasing() == false then
|
||||
if RecceUnit:IsDetected( TargetUnit ) and RecceUnit:IsLOS( TargetUnit ) then
|
||||
local LaserCodeIndex = math.random( 1, #self.LaserCodes )
|
||||
local LaserCode = self.LaserCodes[LaserCodeIndex]
|
||||
if not self.LaserCodesUsed[LaserCode] then
|
||||
self.LaserCodesUsed[LaserCode] = LaserCodeIndex
|
||||
local Spot = RecceUnit:LaseUnit( TargetUnit, LaserCode, Duration )
|
||||
local AttackSet = self.AttackSet
|
||||
function Spot:OnAfterDestroyed( From, Event, To )
|
||||
self:E( "Destroyed Message" )
|
||||
self.Recce:MessageToSetGroup( "Target " .. TargetUnit:GetTypeName() .. " destroyed." .. TargetSetUnit:Count() .. " targets left.", 15, AttackSet )
|
||||
end
|
||||
self.Recces[TargetUnit] = RecceUnit
|
||||
RecceUnit:MessageToSetGroup( "Marking " .. TargetUnit:GetTypeName() .. " with laser " .. RecceUnit:GetSpot().LaserCode .. " for " .. Duration .. "s.", 5, self.AttackSet )
|
||||
break
|
||||
end
|
||||
else
|
||||
RecceUnit:MessageToSetGroup( "Can't lase " .. TargetUnit:GetTypeName(), 5, self.AttackSet )
|
||||
end
|
||||
else
|
||||
-- The Recce is lasing, but the Target is not detected or within LOS. So stop lasing and send a report.
|
||||
if not RecceUnit:IsDetected( TargetUnit ) or not RecceUnit:IsLOS( TargetUnit ) then
|
||||
local Recce = self.Recces[TargetUnit] -- Wrapper.Unit#UNIT
|
||||
if Recce then
|
||||
Recce:LaseOff()
|
||||
Recce:MessageToGroup( "Target " .. TargetUnit:GetTypeName() "out of LOS. Cancelling lase!", 5, self.AttackSet )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
Recce:MessageToSetGroup( "Marking " .. TargetUnit:GetTypeName() .. " with laser " .. Recce.LaserCode .. ".", 5, self.AttackSet )
|
||||
end
|
||||
end
|
||||
--end
|
||||
end
|
||||
)
|
||||
|
||||
if Targets == true then
|
||||
self:__Lasing( -30, AttackGroup, Index, Duration )
|
||||
else
|
||||
self:__LaseOff( -0.2, AttackGroup, Index )
|
||||
end
|
||||
|
||||
self:__Lasing( 15, Index, Duration )
|
||||
|
||||
self:SetDesignateMenu()
|
||||
|
||||
end
|
||||
@@ -469,20 +677,27 @@ do -- AI_DESIGNATE
|
||||
---
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:onafterLaseOff( From, Event, To, AttackGroup, Index )
|
||||
function AI_DESIGNATE:onafterLaseOff( From, Event, To, Index )
|
||||
|
||||
local TargetSetUnit = self.Detection:GetDetectedSet( Index )
|
||||
local Recce = self.RecceSet:GetFirst()
|
||||
|
||||
local Spots = self.Spots[Index]
|
||||
|
||||
for SpotID, SpotData in pairs( Spots ) do
|
||||
local Spot = SpotData -- Core.Spot#SPOT
|
||||
Spot.Recce:MessageToGroup( "Stopped lasing " .. Spot.Target:GetTypeName() .. ".", 15, AttackGroup )
|
||||
Spot:LaseOff()
|
||||
if Recce then
|
||||
Recce:MessageToSetGroup( "Stopped lasing.", 15, self.AttackSet )
|
||||
end
|
||||
|
||||
Spots = nil
|
||||
self.Spots[Index] = nil
|
||||
local TargetSetUnit = self.Detection:GetDetectedSet( Index )
|
||||
|
||||
local Recces = self.Recces
|
||||
|
||||
for TargetID, RecceData in pairs( Recces ) do
|
||||
local Recce = RecceData -- Wrapper.Unit#UNIT
|
||||
Recce:MessageToSetGroup( "Stopped lasing " .. Recce:GetSpot().Target:GetTypeName() .. ".", 15, self.AttackSet )
|
||||
Recce:LaseOff()
|
||||
end
|
||||
|
||||
Recces = nil
|
||||
self.Recces = {}
|
||||
self.LaserCodesUsed = {}
|
||||
|
||||
self:SetDesignateMenu()
|
||||
end
|
||||
@@ -491,30 +706,72 @@ do -- AI_DESIGNATE
|
||||
---
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:onafterSmoke( From, Event, To, AttackGroup, Index )
|
||||
function AI_DESIGNATE:onafterSmoke( From, Event, To, Index, Color )
|
||||
|
||||
|
||||
local TargetSetUnit = self.Detection:GetDetectedSet( Index )
|
||||
local TargetSetUnitCount = TargetSetUnit:Count()
|
||||
|
||||
TargetSetUnit:ForEachUnit(
|
||||
--- @param Wrapper.Unit#UNIT SmokeUnit
|
||||
function( SmokeUnit )
|
||||
self:E("In procedure")
|
||||
--if math.random( 1, ( 100 * TargetSetUnit:Count() ) / 100 ) <= 100 then
|
||||
SCHEDULER:New( self,
|
||||
function()
|
||||
if SmokeUnit:IsAlive() then
|
||||
SmokeUnit:Smoke( SMOKECOLOR.Red, 150 )
|
||||
end
|
||||
end, {}, math.random( 10, 60 )
|
||||
)
|
||||
--end
|
||||
if math.random( 1, TargetSetUnitCount ) == math.random( 1, TargetSetUnitCount ) then
|
||||
local RecceGroup = self.RecceSet:FindNearestGroupFromPointVec2(SmokeUnit:GetPointVec2())
|
||||
local RecceUnit = RecceGroup:GetUnit( 1 )
|
||||
if RecceUnit then
|
||||
RecceUnit:MessageToSetGroup( "Smoking " .. SmokeUnit:GetTypeName() .. ".", 5, self.AttackSet )
|
||||
SCHEDULER:New( self,
|
||||
function()
|
||||
if SmokeUnit:IsAlive() then
|
||||
SmokeUnit:Smoke( Color, 150 )
|
||||
end
|
||||
self:Done( Index )
|
||||
end, {}, math.random( 5, 20 )
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
end
|
||||
|
||||
--- Illuminating
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:onafterIlluminate( From, Event, To, Index )
|
||||
|
||||
local TargetSetUnit = self.Detection:GetDetectedSet( Index )
|
||||
|
||||
local TargetUnit = TargetSetUnit:GetFirst()
|
||||
|
||||
if TargetUnit then
|
||||
local RecceGroup = self.RecceSet:FindNearestGroupFromPointVec2(TargetUnit:GetPointVec2())
|
||||
local RecceUnit = RecceGroup:GetUnit( 1 )
|
||||
if RecceUnit then
|
||||
RecceUnit:MessageToGroup( "Illuminating " .. TargetUnit:GetTypeName() .. ".", 5, self.AttackSet )
|
||||
SCHEDULER:New( self,
|
||||
function()
|
||||
if TargetUnit:IsAlive() then
|
||||
TargetUnit:GetPointVec3():AddY(300):IlluminationBomb()
|
||||
end
|
||||
self:Done( Index )
|
||||
end, {}, math.random( 5, 20 )
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Done
|
||||
-- @param #AI_DESIGNATE self
|
||||
-- @return #AI_DESIGNATE
|
||||
function AI_DESIGNATE:onafterDone( From, Event, To, Index )
|
||||
|
||||
self.Designating[Index] = nil
|
||||
self:SetDesignateMenu()
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
--- **Core** -- Management of CARGO logistics, that can be transported from and to transportation carriers.
|
||||
--- **(R2.1) Core** -- Management of CARGO logistics, that can be transported from and to transportation carriers.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
@@ -165,7 +165,7 @@ do -- CARGO
|
||||
-- @field #boolean Representable This flag defines if the cargo can be represented by a DCS Unit.
|
||||
-- @field #boolean Containable This flag defines if the cargo can be contained within a DCS Unit.
|
||||
|
||||
--- # CARGO class, extends @{Fsm#FSM_PROCESS}
|
||||
--- # (R2.1) CARGO class, extends @{Fsm#FSM_PROCESS}
|
||||
--
|
||||
-- The CARGO class defines the core functions that defines a cargo object within MOOSE.
|
||||
-- A cargo is a logical object defined that is available for transport, and has a life status within a simulation.
|
||||
@@ -231,7 +231,7 @@ do -- CARGO
|
||||
-- @param #number Weight
|
||||
-- @param #number NearRadius (optional)
|
||||
-- @return #CARGO
|
||||
function CARGO:New( Type, Name, Weight )
|
||||
function CARGO:New( Type, Name, Weight ) --R2.1
|
||||
|
||||
local self = BASE:Inherit( self, FSM:New() ) -- #CARGO
|
||||
self:F( { Type, Name, Weight } )
|
||||
@@ -269,7 +269,7 @@ end
|
||||
--- Get the name of the Cargo.
|
||||
-- @param #CARGO self
|
||||
-- @return #string The name of the Cargo.
|
||||
function CARGO:GetName()
|
||||
function CARGO:GetName() --R2.1
|
||||
return self.Name
|
||||
end
|
||||
|
||||
|
||||
@@ -789,6 +789,25 @@ function POINT_VEC3:FlareRed( Azimuth )
|
||||
self:Flare( FLARECOLOR.Red, Azimuth )
|
||||
end
|
||||
|
||||
--- Returns if a PointVec3 has Line of Sight (LOS) with the ToPointVec3.
|
||||
-- @param #POINT_VEC3 self
|
||||
-- @param #POINT_VEC3 ToPointVec3
|
||||
-- @return #boolean true If the ToPointVec3 has LOS with the PointVec3, otherwise false.
|
||||
function POINT_VEC3:IsLOS( ToPointVec3 ) --R2.1
|
||||
|
||||
-- Measurement of visibility should not be from the ground, so Adding a hypotethical 2 meters to each PointVec3.
|
||||
local FromVec3 = self:GetVec3()
|
||||
FromVec3.y = FromVec3.y + 2
|
||||
|
||||
local ToVec3 = ToPointVec3:GetVec3()
|
||||
ToVec3.y = ToVec3.y + 2
|
||||
|
||||
local IsLOS = land.isVisible( FromVec3, ToVec3 )
|
||||
|
||||
return IsLOS
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
do -- POINT_VEC2
|
||||
|
||||
@@ -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
|
||||
@@ -961,6 +981,185 @@ function SET_GROUP:ForEachGroupNotInZone( ZoneObject, IteratorFunction, ... )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and return true if all the @{Wrapper.Group#GROUP} are completely in the @{Core.Zone#ZONE}
|
||||
-- @param #SET_GROUP self
|
||||
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
|
||||
-- @return #boolean true if all the @{Wrapper.Group#GROUP} are completly in the @{Core.Zone#ZONE}, false otherwise
|
||||
-- @usage
|
||||
-- local MyZone = ZONE:New("Zone1")
|
||||
-- local MySetGroup = SET_GROUP:New()
|
||||
-- MySetGroup:AddGroupsByName({"Group1", "Group2"})
|
||||
--
|
||||
-- if MySetGroup:AllCompletelyInZone(MyZone) then
|
||||
-- MESSAGE:New("All the SET's GROUP are in zone !", 10):ToAll()
|
||||
-- else
|
||||
-- MESSAGE:New("Some or all SET's GROUP are outside zone !", 10):ToAll()
|
||||
-- end
|
||||
function SET_GROUP:AllCompletelyInZone(Zone)
|
||||
self:F2(Zone)
|
||||
local Set = self:GetSet()
|
||||
for GroupID, GroupData in pairs(Set) do -- For each GROUP in SET_GROUP
|
||||
if not GroupData:IsCompletelyInZone(Zone) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and return true if at least one of the @{Wrapper.Group#GROUP} is completely inside the @{Core.Zone#ZONE}
|
||||
-- @param #SET_GROUP self
|
||||
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
|
||||
-- @return #boolean true if at least one of the @{Wrapper.Group#GROUP} is completly inside the @{Core.Zone#ZONE}, false otherwise.
|
||||
-- @usage
|
||||
-- local MyZone = ZONE:New("Zone1")
|
||||
-- local MySetGroup = SET_GROUP:New()
|
||||
-- MySetGroup:AddGroupsByName({"Group1", "Group2"})
|
||||
--
|
||||
-- if MySetGroup:AnyCompletelyInZone(MyZone) then
|
||||
-- MESSAGE:New("At least one GROUP is completely in zone !", 10):ToAll()
|
||||
-- else
|
||||
-- MESSAGE:New("No GROUP is completely in zone !", 10):ToAll()
|
||||
-- end
|
||||
function SET_GROUP:AnyCompletelyInZone(Zone)
|
||||
self:F2(Zone)
|
||||
local Set = self:GetSet()
|
||||
for GroupID, GroupData in pairs(Set) do -- For each GROUP in SET_GROUP
|
||||
if GroupData:IsCompletelyInZone(Zone) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and return true if at least one @{#UNIT} of one @{GROUP} of the @{SET_GROUP} is in @{ZONE}
|
||||
-- @param #SET_GROUP self
|
||||
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
|
||||
-- @return #boolean true if at least one of the @{Wrapper.Group#GROUP} is partly or completly inside the @{Core.Zone#ZONE}, false otherwise.
|
||||
-- @usage
|
||||
-- local MyZone = ZONE:New("Zone1")
|
||||
-- local MySetGroup = SET_GROUP:New()
|
||||
-- MySetGroup:AddGroupsByName({"Group1", "Group2"})
|
||||
--
|
||||
-- if MySetGroup:AnyPartlyInZone(MyZone) then
|
||||
-- MESSAGE:New("At least one GROUP has at least one UNIT in zone !", 10):ToAll()
|
||||
-- else
|
||||
-- MESSAGE:New("No UNIT of any GROUP is in zone !", 10):ToAll()
|
||||
-- end
|
||||
function SET_GROUP:AnyInZone(Zone)
|
||||
self:F2(Zone)
|
||||
local Set = self:GetSet()
|
||||
for GroupID, GroupData in pairs(Set) do -- For each GROUP in SET_GROUP
|
||||
if GroupData:IsPartlyInZone(Zone) or GroupData:IsCompletelyInZone(Zone) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and return true if at least one @{GROUP} of the @{SET_GROUP} is partly in @{ZONE}.
|
||||
-- Will return false if a @{GROUP} is fully in the @{ZONE}
|
||||
-- @param #SET_GROUP self
|
||||
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
|
||||
-- @return #boolean true if at least one of the @{Wrapper.Group#GROUP} is partly or completly inside the @{Core.Zone#ZONE}, false otherwise.
|
||||
-- @usage
|
||||
-- local MyZone = ZONE:New("Zone1")
|
||||
-- local MySetGroup = SET_GROUP:New()
|
||||
-- MySetGroup:AddGroupsByName({"Group1", "Group2"})
|
||||
--
|
||||
-- if MySetGroup:AnyPartlyInZone(MyZone) then
|
||||
-- MESSAGE:New("At least one GROUP is partially in the zone, but none are fully in it !", 10):ToAll()
|
||||
-- else
|
||||
-- MESSAGE:New("No GROUP are in zone, or one (or more) GROUP is completely in it !", 10):ToAll()
|
||||
-- end
|
||||
function SET_GROUP:AnyPartlyInZone(Zone)
|
||||
self:F2(Zone)
|
||||
local IsPartlyInZone = false
|
||||
local Set = self:GetSet()
|
||||
for GroupID, GroupData in pairs(Set) do -- For each GROUP in SET_GROUP
|
||||
if GroupData:IsCompletelyInZone(Zone) then
|
||||
return false
|
||||
elseif GroupData:IsPartlyInZone(Zone) then
|
||||
IsPartlyInZone = true -- at least one GROUP is partly in zone
|
||||
end
|
||||
end
|
||||
|
||||
if IsPartlyInZone then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and return true if no @{GROUP} of the @{SET_GROUP} is in @{ZONE}
|
||||
-- This could also be achieved with `not SET_GROUP:AnyPartlyInZone(Zone)`, but it's easier for the
|
||||
-- mission designer to add a dedicated method
|
||||
-- @param #SET_GROUP self
|
||||
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
|
||||
-- @return #boolean true if no @{Wrapper.Group#GROUP} is inside the @{Core.Zone#ZONE} in any way, false otherwise.
|
||||
-- @usage
|
||||
-- local MyZone = ZONE:New("Zone1")
|
||||
-- local MySetGroup = SET_GROUP:New()
|
||||
-- MySetGroup:AddGroupsByName({"Group1", "Group2"})
|
||||
--
|
||||
-- if MySetGroup:NoneInZone(MyZone) then
|
||||
-- MESSAGE:New("No GROUP is completely in zone !", 10):ToAll()
|
||||
-- else
|
||||
-- MESSAGE:New("No UNIT of any GROUP is in zone !", 10):ToAll()
|
||||
-- end
|
||||
function SET_GROUP:NoneInZone(Zone)
|
||||
self:F2(Zone)
|
||||
local Set = self:GetSet()
|
||||
for GroupID, GroupData in pairs(Set) do -- For each GROUP in SET_GROUP
|
||||
if not GroupData:IsNotInZone(Zone) then -- If the GROUP is in Zone in any way
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and count how many GROUPs are completely in the Zone
|
||||
-- That could easily be done with SET_GROUP:ForEachGroupCompletelyInZone(), but this function
|
||||
-- provides an easy to use shortcut...
|
||||
-- @param #SET_GROUP self
|
||||
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
|
||||
-- @return #number the number of GROUPs completely in the Zone
|
||||
-- @usage
|
||||
-- local MyZone = ZONE:New("Zone1")
|
||||
-- local MySetGroup = SET_GROUP:New()
|
||||
-- MySetGroup:AddGroupsByName({"Group1", "Group2"})
|
||||
--
|
||||
-- MESSAGE:New("There are " .. MySetGroup:CountInZone(MyZone) .. " GROUPs in the Zone !", 10):ToAll()
|
||||
function SET_GROUP:CountInZone(Zone)
|
||||
self:F2(Zone)
|
||||
local Count = 0
|
||||
local Set = self:GetSet()
|
||||
for GroupID, GroupData in pairs(Set) do -- For each GROUP in SET_GROUP
|
||||
if GroupData:IsCompletelyInZone(Zone) then
|
||||
Count = Count + 1
|
||||
end
|
||||
end
|
||||
return Count
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and count how many UNITs are completely in the Zone
|
||||
-- @param #SET_GROUP self
|
||||
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
|
||||
-- @return #number the number of GROUPs completely in the Zone
|
||||
-- @usage
|
||||
-- local MyZone = ZONE:New("Zone1")
|
||||
-- local MySetGroup = SET_GROUP:New()
|
||||
-- MySetGroup:AddGroupsByName({"Group1", "Group2"})
|
||||
--
|
||||
-- MESSAGE:New("There are " .. MySetGroup:CountUnitInZone(MyZone) .. " UNITs in the Zone !", 10):ToAll()
|
||||
function SET_GROUP:CountUnitInZone(Zone)
|
||||
self:F2(Zone)
|
||||
local Count = 0
|
||||
local Set = self:GetSet()
|
||||
for GroupID, GroupData in pairs(Set) do -- For each GROUP in SET_GROUP
|
||||
Count = Count + GroupData:CountInZone(Zone)
|
||||
end
|
||||
return Count
|
||||
end
|
||||
|
||||
----- Iterate the SET_GROUP and call an interator function for each **alive** player, providing the Group of the player and optional parameters.
|
||||
---- @param #SET_GROUP self
|
||||
@@ -2420,7 +2619,7 @@ end
|
||||
--- @type SET_CARGO
|
||||
-- @extends Core.Set#SET_BASE
|
||||
|
||||
--- # SET_CARGO class, extends @{Set#SET_BASE}
|
||||
--- # (R2.1) SET_CARGO class, extends @{Set#SET_BASE}
|
||||
--
|
||||
-- Mission designers can use the @{Set#SET_CARGO} class to build sets of cargos optionally belonging to certain:
|
||||
--
|
||||
@@ -2482,7 +2681,7 @@ SET_CARGO = {
|
||||
}
|
||||
|
||||
|
||||
--- Creates a new SET_CARGO object, building a set of cargos belonging to a coalitions and categories.
|
||||
--- (R2.1) Creates a new SET_CARGO object, building a set of cargos belonging to a coalitions and categories.
|
||||
-- @param #SET_CARGO self
|
||||
-- @return #SET_CARGO self
|
||||
-- @usage
|
||||
@@ -2495,7 +2694,7 @@ function SET_CARGO:New()
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add CARGOs to SET_CARGO.
|
||||
--- (R2.1) Add CARGOs to SET_CARGO.
|
||||
-- @param Core.Set#SET_CARGO self
|
||||
-- @param #string AddCargoNames A single name or an array of CARGO names.
|
||||
-- @return self
|
||||
@@ -2510,7 +2709,7 @@ function SET_CARGO:AddCargosByName( AddCargoNames )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Remove CARGOs from SET_CARGO.
|
||||
--- (R2.1) Remove CARGOs from SET_CARGO.
|
||||
-- @param Core.Set#SET_CARGO self
|
||||
-- @param Wrapper.Cargo#CARGO RemoveCargoNames A single name or an array of CARGO names.
|
||||
-- @return self
|
||||
@@ -2526,7 +2725,7 @@ function SET_CARGO:RemoveCargosByName( RemoveCargoNames )
|
||||
end
|
||||
|
||||
|
||||
--- Finds a Cargo based on the Cargo Name.
|
||||
--- (R2.1) Finds a Cargo based on the Cargo Name.
|
||||
-- @param #SET_CARGO self
|
||||
-- @param #string CargoName
|
||||
-- @return Wrapper.Cargo#CARGO The found Cargo.
|
||||
@@ -2538,7 +2737,7 @@ end
|
||||
|
||||
|
||||
|
||||
--- Builds a set of cargos of coalitions.
|
||||
--- (R2.1) Builds a set of cargos of coalitions.
|
||||
-- Possible current coalitions are red, blue and neutral.
|
||||
-- @param #SET_CARGO self
|
||||
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral".
|
||||
@@ -2556,7 +2755,7 @@ function SET_CARGO:FilterCoalitions( Coalitions )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Builds a set of cargos of defined cargo types.
|
||||
--- (R2.1) Builds a set of cargos of defined cargo types.
|
||||
-- Possible current types are those types known within DCS world.
|
||||
-- @param #SET_CARGO self
|
||||
-- @param #string Types Can take those type strings known within DCS world.
|
||||
@@ -2575,7 +2774,7 @@ function SET_CARGO:FilterTypes( Types )
|
||||
end
|
||||
|
||||
|
||||
--- Builds a set of cargos of defined countries.
|
||||
--- (R2.1) Builds a set of cargos of defined countries.
|
||||
-- Possible current countries are those known within DCS world.
|
||||
-- @param #SET_CARGO self
|
||||
-- @param #string Countries Can take those country strings known within DCS world.
|
||||
@@ -2594,7 +2793,7 @@ function SET_CARGO:FilterCountries( Countries )
|
||||
end
|
||||
|
||||
|
||||
--- Builds a set of cargos of defined cargo prefixes.
|
||||
--- (R2.1) Builds a set of cargos of defined cargo prefixes.
|
||||
-- All the cargos starting with the given prefixes will be included within the set.
|
||||
-- @param #SET_CARGO self
|
||||
-- @param #string Prefixes The prefix of which the cargo name starts with.
|
||||
@@ -2614,7 +2813,7 @@ end
|
||||
|
||||
|
||||
|
||||
--- Starts the filtering.
|
||||
--- (R2.1) Starts the filtering.
|
||||
-- @param #SET_CARGO self
|
||||
-- @return #SET_CARGO self
|
||||
function SET_CARGO:FilterStart()
|
||||
@@ -2630,7 +2829,7 @@ function SET_CARGO:FilterStart()
|
||||
end
|
||||
|
||||
|
||||
--- Handles the Database to check on an event (birth) that the Object was added in the Database.
|
||||
--- (R2.1) Handles the Database to check on an event (birth) that the Object was added in the Database.
|
||||
-- This is required, because sometimes the _DATABASE birth event gets called later than the SET_BASE birth event!
|
||||
-- @param #SET_CARGO self
|
||||
-- @param Core.Event#EVENTDATA Event
|
||||
@@ -2642,7 +2841,7 @@ function SET_CARGO:AddInDatabase( Event )
|
||||
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
|
||||
end
|
||||
|
||||
--- Handles the Database to check on any event that Object exists in the Database.
|
||||
--- (R2.1) Handles the Database to check on any event that Object exists in the Database.
|
||||
-- This is required, because sometimes the _DATABASE event gets called later than the SET_BASE event or vise versa!
|
||||
-- @param #SET_CARGO self
|
||||
-- @param Core.Event#EVENTDATA Event
|
||||
@@ -2654,7 +2853,7 @@ function SET_CARGO:FindInDatabase( Event )
|
||||
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
|
||||
end
|
||||
|
||||
--- Iterate the SET_CARGO and call an interator function for each CARGO, providing the CARGO and optional parameters.
|
||||
--- (R2.1) Iterate the SET_CARGO and call an interator function for each CARGO, providing the CARGO and optional parameters.
|
||||
-- @param #SET_CARGO self
|
||||
-- @param #function IteratorFunction The function that will be called when there is an alive CARGO in the SET_CARGO. The function needs to accept a CARGO parameter.
|
||||
-- @return #SET_CARGO self
|
||||
@@ -2666,7 +2865,7 @@ function SET_CARGO:ForEachCargo( IteratorFunction, ... )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Iterate the SET_CARGO while identifying the nearest @{Cargo#CARGO} from a @{Point#POINT_VEC2}.
|
||||
--- (R2.1) Iterate the SET_CARGO while identifying the nearest @{Cargo#CARGO} from a @{Point#POINT_VEC2}.
|
||||
-- @param #SET_CARGO self
|
||||
-- @param Core.Point#POINT_VEC2 PointVec2 A @{Point#POINT_VEC2} object from where to evaluate the closest @{Cargo#CARGO}.
|
||||
-- @return Wrapper.Cargo#CARGO The closest @{Cargo#CARGO}.
|
||||
@@ -2679,7 +2878,7 @@ end
|
||||
|
||||
|
||||
|
||||
---
|
||||
--- (R2.1)
|
||||
-- @param #SET_CARGO self
|
||||
-- @param AI.AI_Cargo#AI_CARGO MCargo
|
||||
-- @return #SET_CARGO self
|
||||
@@ -2733,7 +2932,7 @@ function SET_CARGO:IsIncludeObject( MCargo )
|
||||
return MCargoInclude
|
||||
end
|
||||
|
||||
--- Handles the OnEventNewCargo event for the Set.
|
||||
--- (R2.1) Handles the OnEventNewCargo event for the Set.
|
||||
-- @param #SET_CARGO self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function SET_CARGO:OnEventNewCargo( EventData )
|
||||
@@ -2745,7 +2944,7 @@ function SET_CARGO:OnEventNewCargo( EventData )
|
||||
end
|
||||
end
|
||||
|
||||
--- Handles the OnDead or OnCrash event for alive units set.
|
||||
--- (R2.1) Handles the OnDead or OnCrash event for alive units set.
|
||||
-- @param #SET_CARGO self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function SET_CARGO:OnEventDeleteCargo( EventData )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
--- **Core** -- Spawn dynamically new STATICs in your missions.
|
||||
--- (R2.1) **Core** -- Spawn dynamically new STATICs in your missions.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
@@ -95,7 +95,7 @@ SPAWNSTATIC = {
|
||||
-- @param #SPAWNSTATIC self
|
||||
-- @param #string SpawnTemplatePrefix is the name of the Group in the ME that defines the Template. Each new group will have the name starting with SpawnTemplatePrefix.
|
||||
-- @return #SPAWNSTATIC
|
||||
function SPAWNSTATIC:NewFromStatic( SpawnTemplatePrefix, CountryID )
|
||||
function SPAWNSTATIC:NewFromStatic( SpawnTemplatePrefix, CountryID ) --R2.1
|
||||
local self = BASE:Inherit( self, BASE:New() ) -- #SPAWNSTATIC
|
||||
self:F( { SpawnTemplatePrefix } )
|
||||
|
||||
@@ -117,7 +117,7 @@ end
|
||||
-- @param #SPAWNSTATIC self
|
||||
-- @param #string SpawnTypeName is the name of the type.
|
||||
-- @return #SPAWNSTATIC
|
||||
function SPAWNSTATIC:NewFromType( SpawnTypeName, SpawnShapeName, SpawnCategory, CountryID )
|
||||
function SPAWNSTATIC:NewFromType( SpawnTypeName, SpawnShapeName, SpawnCategory, CountryID ) --R2.1
|
||||
local self = BASE:Inherit( self, BASE:New() ) -- #SPAWNSTATIC
|
||||
self:F( { SpawnTypeName } )
|
||||
|
||||
@@ -137,7 +137,7 @@ end
|
||||
-- @param #number Heading The heading of the static, which is a number in degrees from 0 to 360.
|
||||
-- @param #string (optional) The name of the new static.
|
||||
-- @return #SPAWNSTATIC
|
||||
function SPAWNSTATIC:SpawnFromPointVec2( PointVec2, Heading, NewName )
|
||||
function SPAWNSTATIC:SpawnFromPointVec2( PointVec2, Heading, NewName ) --R2.1
|
||||
self:F( { PointVec2, Heading, NewName } )
|
||||
|
||||
local CountryName = _DATABASE.COUNTRY_NAME[self.CountryID]
|
||||
@@ -167,7 +167,7 @@ end
|
||||
-- @param #number Heading The heading of the static, which is a number in degrees from 0 to 360.
|
||||
-- @param #string (optional) The name of the new static.
|
||||
-- @return #SPAWNSTATIC
|
||||
function SPAWNSTATIC:SpawnFromZone( Zone, Heading, NewName )
|
||||
function SPAWNSTATIC:SpawnFromZone( Zone, Heading, NewName ) --R2.1
|
||||
self:F( { Zone, Heading, NewName } )
|
||||
|
||||
local Static = self:SpawnFromPointVec2( Zone:GetPointVec2(), Heading, NewName )
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
--- **Core (Release 2.1)** -- Management of SPOT logistics, that can be transported from and to transportation carriers.
|
||||
--- **Core 2.1** -- Management of SPOT logistics, that can be transported from and to transportation carriers.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- Spot lases points endlessly or for a duration.
|
||||
-- SPOT implements the DCS Spot class functionality, but adds additional luxury to be able to:
|
||||
--
|
||||
-- * Spot for a defined duration.
|
||||
-- * wiggle the spot at the target.
|
||||
-- * Provide a @{Unit} as a target, instead of a point.
|
||||
-- * Implement a status machine, LaseOn, LaseOff.
|
||||
--
|
||||
-- ====
|
||||
--
|
||||
@@ -22,9 +27,20 @@
|
||||
--
|
||||
-- ### [SPOT YouTube Channel]()
|
||||
--
|
||||
-- ====
|
||||
-- ===
|
||||
--
|
||||
-- This module is still under construction, but is described above works already, and will keep working ...
|
||||
-- # **AUTHORS and CONTRIBUTIONS**
|
||||
--
|
||||
-- ### Contributions:
|
||||
--
|
||||
-- * [**Ciribob**](https://forums.eagle.ru/member.php?u=112175): Showing the way how to lase targets + how laser codes work!!! Explained the autolase script.
|
||||
-- * [**EasyEB**](https://forums.eagle.ru/member.php?u=112055): Ideas and Beta Testing
|
||||
-- * [**Wingthor**](https://forums.eagle.ru/member.php?u=123698): Beta Testing
|
||||
--
|
||||
--
|
||||
-- ### Authors:
|
||||
--
|
||||
-- * **FlightControl**: Design & Programming
|
||||
--
|
||||
-- @module Spot
|
||||
|
||||
@@ -32,7 +48,44 @@
|
||||
do
|
||||
|
||||
--- @type SPOT
|
||||
-- @extends BASE
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
|
||||
--- # SPOT class, extends @{Fsm#FSM}
|
||||
--
|
||||
-- SPOT implements the DCS Spot class functionality, but adds additional luxury to be able to:
|
||||
--
|
||||
-- * Spot for a defined duration.
|
||||
-- * wiggle the spot at the target.
|
||||
-- * Provide a @{Unit} as a target, instead of a point.
|
||||
-- * Implement a status machine, LaseOn, LaseOff.
|
||||
--
|
||||
-- ## 1. SPOT constructor
|
||||
--
|
||||
-- * @{#SPOT.New}(): Creates a new SPOT object.
|
||||
--
|
||||
-- ## 2. SPOT is a FSM
|
||||
--
|
||||
-- ![Process]()
|
||||
--
|
||||
-- ### 2.1 SPOT States
|
||||
--
|
||||
-- * **Off**: Lasing is switched off.
|
||||
-- * **On**: Lasing is switched on.
|
||||
-- * **Destroyed**: Target is destroyed.
|
||||
--
|
||||
-- ### 2.2 SPOT Events
|
||||
--
|
||||
-- * **@{#SPOT.LaseOn}(Target, LaserCode, Duration)**: Lase to a target.
|
||||
-- * **@{#SPOT.LaseOff}()**: Stop lasing the target.
|
||||
-- * **@{#SPOT.Lasing}()**: Target is being lased.
|
||||
-- * **@{#SPOT.Destroyed}()**: Triggered when target is destroyed.
|
||||
--
|
||||
-- ## 3. Check if a Target is being lased
|
||||
--
|
||||
-- The method @{#SPOT.IsLasing}() indicates whether lasing is on or off.
|
||||
--
|
||||
-- @field #SPOT
|
||||
SPOT = {
|
||||
ClassName = "SPOT",
|
||||
}
|
||||
@@ -46,18 +99,99 @@ do
|
||||
function SPOT:New( Recce )
|
||||
|
||||
local self = BASE:Inherit( self, FSM:New() ) -- #SPOT
|
||||
self:F( { Type, Name, Weight } )
|
||||
self:F( {} )
|
||||
|
||||
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" )
|
||||
self:AddTransition( { "On", "Destroyed" } , "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:AddTransition( "*" , "Destroyed", "Destroyed" )
|
||||
|
||||
--- Destroyed Handler OnBefore for SPOT
|
||||
-- @function [parent=#SPOT] OnBeforeDestroyed
|
||||
-- @param #SPOT self
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
-- @return #boolean
|
||||
|
||||
--- Destroyed Handler OnAfter for SPOT
|
||||
-- @function [parent=#SPOT] OnAfterDestroyed
|
||||
-- @param #SPOT self
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
|
||||
--- Destroyed Trigger for SPOT
|
||||
-- @function [parent=#SPOT] Destroyed
|
||||
-- @param #SPOT self
|
||||
|
||||
--- Destroyed Asynchronous Trigger for SPOT
|
||||
-- @function [parent=#SPOT] __Destroyed
|
||||
-- @param #SPOT self
|
||||
-- @param #number Delay
|
||||
|
||||
|
||||
|
||||
self.Recce = Recce
|
||||
|
||||
self.LaseScheduler = SCHEDULER:New( self )
|
||||
|
||||
self:SetEventPriority( 5 )
|
||||
|
||||
self.Lasing = false
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -70,6 +204,7 @@ do
|
||||
-- @param #number LaserCode
|
||||
-- @param #number Duration
|
||||
function SPOT:onafterLaseOn( From, Event, To, Target, LaserCode, Duration )
|
||||
self:E( { "LaseOn", Target, LaserCode, Duration } )
|
||||
|
||||
local function StopLase( self )
|
||||
self:LaseOff()
|
||||
@@ -78,17 +213,34 @@ do
|
||||
self.Target = Target
|
||||
self.LaserCode = LaserCode
|
||||
|
||||
self.Lasing = true
|
||||
|
||||
local RecceDcsUnit = self.Recce:GetDCSObject()
|
||||
|
||||
self.Spot = Spot.createInfraRed( RecceDcsUnit, { x = 0, y = 2, z = 0 }, Target:GetPointVec3():AddY(1):GetVec3() )
|
||||
self.Spot = Spot.createLaser( RecceDcsUnit, { x = 0, y = 2, z = 0 }, Target:GetPointVec3():AddY(1):GetVec3(), LaserCode )
|
||||
self.SpotIR = Spot.createInfraRed( RecceDcsUnit, { x = 0, y = 2, z = 0 }, Target:GetPointVec3():AddY(1):GetVec3() )
|
||||
self.SpotLaser = Spot.createLaser( RecceDcsUnit, { x = 0, y = 2, z = 0 }, Target:GetPointVec3():AddY(1):GetVec3(), LaserCode )
|
||||
|
||||
if Duration then
|
||||
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)
|
||||
self:E( { Dead = EventData.IniDCSUnitName, Target = self.Target } )
|
||||
if self.Target then
|
||||
if EventData.IniDCSUnitName == self.Target:GetName() then
|
||||
self:E( {"Target dead ", self.Target:GetName() } )
|
||||
self:Destroyed()
|
||||
self:LaseOff()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #SPOT self
|
||||
-- @param From
|
||||
@@ -97,10 +249,11 @@ do
|
||||
function SPOT:onafterLasing( From, Event, To )
|
||||
|
||||
if self.Target:IsAlive() then
|
||||
self.Spot:setPoint( self.Target:GetPointVec3():AddY(1):GetVec3() )
|
||||
self.SpotIR:setPoint( self.Target:GetPointVec3():AddY(1):AddY(math.random(-100,100)/100):AddX(math.random(-100,100)/100):GetVec3() )
|
||||
self.SpotLaser:setPoint( self.Target:GetPointVec3():AddY(1):GetVec3() )
|
||||
self:__Lasing( -0.2 )
|
||||
else
|
||||
self:__LaseOff( 0.2 )
|
||||
self:E( { "Target is not alive", self.Target:IsAlive() } )
|
||||
end
|
||||
|
||||
end
|
||||
@@ -112,15 +265,22 @@ do
|
||||
-- @return #SPOT
|
||||
function SPOT:onafterLaseOff( From, Event, To )
|
||||
|
||||
self.Spot:destroy()
|
||||
self.Spot = nil
|
||||
self:E( {"Stopped lasing for ", self.Target:GetName() , SpotIR = self.SportIR, SpotLaser = self.SpotLaser } )
|
||||
|
||||
self.Lasing = false
|
||||
|
||||
self.SpotIR:destroy()
|
||||
self.SpotLaser:destroy()
|
||||
|
||||
self.SpotIR = nil
|
||||
self.SpotLaser = nil
|
||||
|
||||
if self.ScheduleID then
|
||||
self.LaseScheduler:Stop(self.ScheduleID)
|
||||
end
|
||||
self.ScheduleID = nil
|
||||
|
||||
self.Target = nil
|
||||
self.LaserCode = nil
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -129,15 +289,7 @@ do
|
||||
-- @param #SPOT self
|
||||
-- @return #boolean true if it is lasing
|
||||
function SPOT:IsLasing()
|
||||
self:F2()
|
||||
|
||||
local Lasing = false
|
||||
|
||||
if self.Spot then
|
||||
Lasing = true
|
||||
end
|
||||
|
||||
return Lasing
|
||||
return self.Lasing
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -22,46 +22,6 @@
|
||||
--
|
||||
-- ### [SPAWN YouTube Channel](https://www.youtube.com/playlist?list=PL7ZUrU4zZUl1jirWIo4t4YxqN-HxjqRkL)
|
||||
--
|
||||
-- ====
|
||||
--
|
||||
-- # **API CHANGE HISTORY**
|
||||
--
|
||||
-- The underlying change log documents the API changes. Please read this carefully. The following notation is used:
|
||||
--
|
||||
-- * **Added** parts are expressed in bold type face.
|
||||
-- * _Removed_ parts are expressed in italic type face.
|
||||
--
|
||||
-- Hereby the change log:
|
||||
--
|
||||
-- 2017-04-08: SPAWN:**InitDelayOnOff( DelayOnOff )** added.
|
||||
-- 2017-04-08: SPAWN:**InitDelayOn()** added.
|
||||
-- 2017-04-08: SPAWN:**InitDelayOff()** added.
|
||||
--
|
||||
-- 2017-03-14: SPAWN:**InitKeepUnitNames()** added.
|
||||
-- 2017-03-14: SPAWN:**InitRandomizePosition( RandomizePosition, OuterRadious, InnerRadius )** added.
|
||||
--
|
||||
-- 2017-02-04: SPAWN:InitUnControlled( **UnControlled** ) replaces SPAWN:InitUnControlled().
|
||||
--
|
||||
-- 2017-01-24: SPAWN:**InitAIOnOff( AIOnOff )** added.
|
||||
-- 2017-01-24: SPAWN:**InitAIOn()** added.
|
||||
-- 2017-01-24: SPAWN:**InitAIOff()** added.
|
||||
--
|
||||
-- 2016-08-15: SPAWN:**InitCleanUp**( SpawnCleanUpInterval ) replaces SPAWN:_CleanUp_( SpawnCleanUpInterval ).
|
||||
-- 2016-08-15: SPAWN:**InitRandomizeZones( SpawnZones )** added.
|
||||
--
|
||||
-- 2016-08-14: SPAWN:**OnSpawnGroup**( SpawnCallBackFunction, ... ) replaces SPAWN:_SpawnFunction_( SpawnCallBackFunction, ... ).
|
||||
-- 2016-08-14: SPAWN.SpawnInZone( Zone, __RandomizeGroup__, SpawnIndex ) replaces SpawnInZone( Zone, _RandomizeUnits, OuterRadius, InnerRadius,_ SpawnIndex ).
|
||||
-- 2016-08-14: SPAWN.SpawnFromVec3( Vec3, SpawnIndex ) replaces SpawnFromVec3( Vec3, _RandomizeUnits, OuterRadius, InnerRadius,_ SpawnIndex ).
|
||||
-- 2016-08-14: SPAWN.SpawnFromVec2( Vec2, SpawnIndex ) replaces SpawnFromVec2( Vec2, _RandomizeUnits, OuterRadius, InnerRadius,_ SpawnIndex ).
|
||||
-- 2016-08-14: SPAWN.SpawnFromUnit( SpawnUnit, SpawnIndex ) replaces SpawnFromUnit( SpawnUnit, _RandomizeUnits, OuterRadius, InnerRadius,_ SpawnIndex ).
|
||||
-- 2016-08-14: SPAWN.SpawnFromUnit( SpawnUnit, SpawnIndex ) replaces SpawnFromStatic( SpawnStatic, _RandomizeUnits, OuterRadius, InnerRadius,_ SpawnIndex ).
|
||||
-- 2016-08-14: SPAWN.**InitRandomizeUnits( RandomizeUnits, OuterRadius, InnerRadius )** added.
|
||||
-- 2016-08-14: SPAWN.**Init**Limit( SpawnMaxUnitsAlive, SpawnMaxGroups ) replaces SPAWN._Limit_( SpawnMaxUnitsAlive, SpawnMaxGroups ).
|
||||
-- 2016-08-14: SPAWN.**Init**Array( SpawnAngle, SpawnWidth, SpawnDeltaX, SpawnDeltaY ) replaces SPAWN._Array_( SpawnAngle, SpawnWidth, SpawnDeltaX, SpawnDeltaY ).
|
||||
-- 2016-08-14: SPAWN.**Init**RandomizeRoute( SpawnStartPoint, SpawnEndPoint, SpawnRadius, SpawnHeight ) replaces SPAWN._RandomizeRoute_( SpawnStartPoint, SpawnEndPoint, SpawnRadius, SpawnHeight ).
|
||||
-- 2016-08-14: SPAWN.**Init**RandomizeTemplate( SpawnTemplatePrefixTable ) replaces SPAWN._RandomizeTemplate_( SpawnTemplatePrefixTable ).
|
||||
-- 2016-08-14: SPAWN.**Init**UnControlled() replaces SPAWN._UnControlled_().
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # **AUTHORS and CONTRIBUTIONS**
|
||||
|
||||
@@ -1786,17 +1786,21 @@ function CONTROLLABLE:IsTargetDetected( DCSObject )
|
||||
self:F2( self.ControllableName )
|
||||
|
||||
local DCSControllable = self:GetDCSObject()
|
||||
|
||||
if DCSControllable then
|
||||
|
||||
local DetectionVisual = ( DetectVisual and DetectVisual == true ) and Controller.Detection.VISUAL or nil
|
||||
local DetectionOptical = ( DetectOptical and DetectOptical == true ) and Controller.Detection.OPTICAL or nil
|
||||
local DetectionRadar = ( DetectRadar and DetectRadar == true ) and Controller.Detection.RADAR or nil
|
||||
local DetectionIRST = ( DetectIRST and DetectIRST == true ) and Controller.Detection.IRST or nil
|
||||
local DetectionRWR = ( DetectRWR and DetectRWR == true ) and Controller.Detection.RWR or nil
|
||||
local DetectionDLINK = ( DetectDLINK and DetectDLINK == true ) and Controller.Detection.DLINK or nil
|
||||
|
||||
local Controller = self:_GetController()
|
||||
|
||||
local TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity
|
||||
= self:_GetController().isTargetDetected( self:_GetController(), DCSObject,
|
||||
Controller.Detection.VISUAL,
|
||||
Controller.Detection.OPTIC,
|
||||
Controller.Detection.RADAR,
|
||||
Controller.Detection.IRST,
|
||||
Controller.Detection.RWR,
|
||||
Controller.Detection.DLINK
|
||||
)
|
||||
= Controller:isTargetDetected( DCSObject, DetectionVisual, DetectionOptical, DetectionRadar, DetectionIRST, DetectionRWR, DetectionDLINK )
|
||||
|
||||
return TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity
|
||||
end
|
||||
|
||||
|
||||
@@ -555,22 +555,23 @@ end
|
||||
function GROUP:IsPartlyInZone( Zone )
|
||||
self:F2( { self.GroupName, Zone } )
|
||||
|
||||
local PartlyInZone = false
|
||||
local IsOneUnitInZone = false
|
||||
local IsOneUnitOutsideZone = false
|
||||
|
||||
for UnitID, UnitData in pairs( self:GetUnits() ) do
|
||||
local Unit = UnitData -- Wrapper.Unit#UNIT
|
||||
if Zone:IsVec3InZone( Unit:GetVec3() ) then
|
||||
PartlyInZone = true
|
||||
IsOneUnitInZone = true
|
||||
else
|
||||
-- So, if there were groups in the zone found, and suddenly one NOT in the zone,
|
||||
-- then the group is partialy in the zone :-)
|
||||
if PartlyInZone == true then
|
||||
return true
|
||||
end
|
||||
IsOneUnitOutsideZone = true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
if IsOneUnitInZone and IsOneUnitOutsideZone then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns true if none of the group units of the group are within a @{Zone}.
|
||||
@@ -590,6 +591,24 @@ function GROUP:IsNotInZone( Zone )
|
||||
return true
|
||||
end
|
||||
|
||||
--- Returns the number of UNITs that are in the @{Zone}
|
||||
-- @param #GROUP self
|
||||
-- @param Core.Zone#ZONE_BASE Zone The zone to test.
|
||||
-- @return #number The number of UNITs that are in the @{Zone}
|
||||
function GROUP:CountInZone( Zone )
|
||||
self:F2( {self.GroupName, Zone} )
|
||||
local Count = 0
|
||||
|
||||
for UnitID, UnitData in pairs( self:GetUnits() ) do
|
||||
local Unit = UnitData -- Wrapper.Unit#UNIT
|
||||
if Zone:IsVec3InZone( Unit:GetVec3() ) then
|
||||
Count = Count + 1
|
||||
end
|
||||
end
|
||||
|
||||
return Count
|
||||
end
|
||||
|
||||
--- Returns if the group is of an air category.
|
||||
-- If the group is a helicopter or a plane, then this method will return true, otherwise false.
|
||||
-- @param #GROUP self
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
-- @type POSITIONABLE
|
||||
-- @extends Wrapper.Identifiable#IDENTIFIABLE
|
||||
-- @field #string PositionableName The name of the measurable.
|
||||
-- @field Core.Spot#SPOT Spot The laser Spot.
|
||||
-- @field #number LaserCode The last assigned laser code.
|
||||
POSITIONABLE = {
|
||||
ClassName = "POSITIONABLE",
|
||||
PositionableName = "",
|
||||
@@ -426,6 +428,30 @@ function POSITIONABLE:MessageToGroup( Message, Duration, MessageGroup, Name )
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Send a message to a @{Set#SET_GROUP}.
|
||||
-- The message will appear in the message area. The message will begin with the callsign of the group and the type of the first unit sending the message.
|
||||
-- @param #POSITIONABLE self
|
||||
-- @param #string Message The message text
|
||||
-- @param Dcs.DCSTypes#Duration Duration The duration of the message.
|
||||
-- @param Core.Set#SET_GROUP MessageSetGroup The SET_GROUP collection receiving the message.
|
||||
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
|
||||
function POSITIONABLE:MessageToSetGroup( Message, Duration, MessageSetGroup, Name ) --R2.1
|
||||
self:F2( { Message, Duration } )
|
||||
|
||||
local DCSObject = self:GetDCSObject()
|
||||
if DCSObject then
|
||||
if DCSObject:isExist() then
|
||||
MessageSetGroup:ForEachGroup(
|
||||
function( MessageGroup )
|
||||
self:GetMessage( Message, Duration, Name ):ToGroup( MessageGroup )
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Send a message to the players in the @{Group}.
|
||||
-- The message will appear in the message area. The message will begin with the callsign of the group and the type of the first unit sending the message.
|
||||
-- @param #POSITIONABLE self
|
||||
@@ -447,7 +473,7 @@ end
|
||||
-- Set parameters with the methods provided, then use RADIO:Broadcast() to actually broadcast the message
|
||||
-- @param #POSITIONABLE self
|
||||
-- @return #RADIO Radio
|
||||
function POSITIONABLE:GetRadio()
|
||||
function POSITIONABLE:GetRadio() --R2.1
|
||||
self:F2(self)
|
||||
return RADIO:New(self)
|
||||
end
|
||||
@@ -455,7 +481,7 @@ end
|
||||
--- Create a @{Radio#BEACON}, to allow this POSITIONABLE to broadcast beacon signals
|
||||
-- @param #POSITIONABLE self
|
||||
-- @return #RADIO Radio
|
||||
function POSITIONABLE:GetBeacon()
|
||||
function POSITIONABLE:GetBeacon() --R2.1
|
||||
self:F2(self)
|
||||
return BEACON:New(self)
|
||||
end
|
||||
@@ -466,7 +492,7 @@ end
|
||||
-- @param #number LaserCode
|
||||
-- @param #number Duration
|
||||
-- @return Core.Spot#SPOT
|
||||
function POSITIONABLE:LaseUnit( Target, LaserCode, Duration )
|
||||
function POSITIONABLE:LaseUnit( Target, LaserCode, Duration ) --R2.1
|
||||
self:F2()
|
||||
|
||||
LaserCode = LaserCode or math.random( 1000, 9999 )
|
||||
@@ -475,8 +501,9 @@ 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)
|
||||
self.LaserCode = LaserCode
|
||||
|
||||
return self.Spot
|
||||
|
||||
@@ -484,13 +511,10 @@ end
|
||||
|
||||
--- Stop Lasing a POSITIONABLE
|
||||
-- @param #POSITIONABLE self
|
||||
-- @param #POSITIONABLE Target
|
||||
-- @return #POSITIONABLE
|
||||
function POSITIONABLE:LaseOff( Target )
|
||||
function POSITIONABLE:LaseOff() --R2.1
|
||||
self:F2()
|
||||
|
||||
local TargetUnitName = Target:GetName()
|
||||
|
||||
if self.Spot then
|
||||
self.Spot:LaseOff()
|
||||
self.Spot = nil
|
||||
@@ -502,7 +526,7 @@ end
|
||||
--- Check if the POSITIONABLE is lasing a target
|
||||
-- @param #POSITIONABLE self
|
||||
-- @return #boolean true if it is lasing a target
|
||||
function POSITIONABLE:IsLasing()
|
||||
function POSITIONABLE:IsLasing() --R2.1
|
||||
self:F2()
|
||||
|
||||
local Lasing = false
|
||||
@@ -513,3 +537,19 @@ function POSITIONABLE:IsLasing()
|
||||
|
||||
return Lasing
|
||||
end
|
||||
|
||||
--- Get the Spot
|
||||
-- @param #POSITIONABLE self
|
||||
-- @return Core.Spot#SPOT The Spot
|
||||
function POSITIONABLE:GetSpot() --R2.1
|
||||
|
||||
return self.Spot
|
||||
end
|
||||
|
||||
--- Get the last assigned laser code
|
||||
-- @param #POSITIONABLE self
|
||||
-- @return #number The laser code
|
||||
function POSITIONABLE:GetLaserCode() --R2.1
|
||||
|
||||
return self.LaserCode
|
||||
end
|
||||
|
||||
@@ -64,13 +64,18 @@
|
||||
--
|
||||
-- The UNIT class contains methods to test the location or proximity against zones or other objects.
|
||||
--
|
||||
-- ### Zones
|
||||
-- ### Zones range
|
||||
--
|
||||
-- To test whether the Unit is within a **zone**, use the @{#UNIT.IsInZone}() or the @{#UNIT.IsNotInZone}() methods. Any zone can be tested on, but the zone must be derived from @{Zone#ZONE_BASE}.
|
||||
--
|
||||
-- ### Units
|
||||
-- ### Unit range
|
||||
--
|
||||
-- * Test if another DCS Unit is within a given radius of the current DCS Unit, use the @{#UNIT.OtherUnitInRadius}() method.
|
||||
--
|
||||
-- ## Test Line of Sight
|
||||
--
|
||||
-- * Use the @{#UNIT.IsLOS}() method to check if the given unit is within line of sight.
|
||||
--
|
||||
-- Test if another DCS Unit is within a given radius of the current DCS Unit, use the @{#UNIT.OtherUnitInRadius}() method.
|
||||
--
|
||||
-- @field #UNIT UNIT
|
||||
UNIT = {
|
||||
@@ -1002,6 +1007,32 @@ do -- Event Handling
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
do -- Detection
|
||||
|
||||
--- Returns if a unit is detecting the TargetUnit.
|
||||
-- @param #UNIT self
|
||||
-- @param #UNIT TargetUnit
|
||||
-- @return #boolean true If the TargetUnit is detected by the unit, otherwise false.
|
||||
function UNIT:IsDetected( TargetUnit ) --R2.1
|
||||
|
||||
local TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity = self:IsTargetDetected( TargetUnit:GetDCSObject() )
|
||||
|
||||
return TargetIsDetected
|
||||
end
|
||||
|
||||
--- Returns if a unit has Line of Sight (LOS) with the TargetUnit.
|
||||
-- @param #UNIT self
|
||||
-- @param #UNIT TargetUnit
|
||||
-- @return #boolean true If the TargetUnit has LOS with the unit, otherwise false.
|
||||
function UNIT:IsLOS( TargetUnit ) --R2.1
|
||||
|
||||
local IsLOS = self:GetPointVec3():IsLOS( TargetUnit:GetPointVec3() )
|
||||
|
||||
return IsLOS
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user