This commit is contained in:
FlightControl_Master 2017-09-28 19:54:44 +02:00
parent 9227bbdfca
commit 57eeefcf06
4 changed files with 1746 additions and 27216 deletions

View File

@ -1271,6 +1271,9 @@ function SET_GROUP:IsIncludeObject( MooseGroup )
return MooseGroupInclude
end
do -- SET_UNIT
--- @type SET_UNIT
-- @extends Core.Set#SET_BASE
@ -1447,9 +1450,8 @@ end
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral".
-- @return #SET_UNIT self
function SET_UNIT:FilterCoalitions( Coalitions )
if not self.Filter.Coalitions then
self.Filter.Coalitions = {}
end
if type( Coalitions ) ~= "table" then
Coalitions = { Coalitions }
end
@ -1607,6 +1609,77 @@ function SET_UNIT:FindInDatabase( Event )
return Event.IniDCSUnitName, self.Set[Event.IniDCSUnitName]
end
do -- Is Zone methods
--- Check if minimal one element of the SET_UNIT is in the Zone.
-- @param #SET_UNIT self
-- @param Core.Zone#ZONE ZoneTest The Zone to be tested for.
-- @return #boolean
function SET_UNIT:IsPartiallyInZone( ZoneTest )
local IsPartiallyInZone = false
local function EvaluateZone( ZoneUnit )
local ZoneUnitName = ZoneUnit:GetName()
self:E( { ZoneUnitName = ZoneUnitName } )
if self:FindUnit( ZoneUnitName ) then
IsPartiallyInZone = true
self:E( { Found = true } )
return false
end
return true
end
ZoneTest:SearchZone( EvaluateZone )
return IsPartiallyInZone
end
--- Check if no element of the SET_UNIT is in the Zone.
-- @param #SET_UNIT self
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
-- @return #boolean
function SET_UNIT:IsNotInZone( Zone )
local IsNotInZone = true
local function EvaluateZone( ZoneUnit )
local ZoneUnitName = ZoneUnit:GetName()
if self:FindUnit( ZoneUnitName ) then
IsNotInZone = false
return false
end
return true
end
Zone:SearchZone( EvaluateZone )
return IsNotInZone
end
--- Check if minimal one element of the SET_UNIT is in the Zone.
-- @param #SET_UNIT self
-- @param #function IteratorFunction The function that will be called when there is an alive UNIT in the SET_UNIT. The function needs to accept a UNIT parameter.
-- @return #SET_UNIT self
function SET_UNIT:ForEachUnitInZone( IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.Set )
return self
end
end
--- Iterate the SET_UNIT and call an interator function for each **alive** UNIT, providing the UNIT and optional parameters.
-- @param #SET_UNIT self
-- @param #function IteratorFunction The function that will be called when there is an alive UNIT in the SET_UNIT. The function needs to accept a UNIT parameter.
@ -2035,7 +2108,7 @@ function SET_UNIT:IsIncludeObject( MUnit )
if self.Filter.Coalitions then
local MUnitCoalition = false
for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do
self:T3( { "Coalition:", MUnit:GetCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } )
self:E( { "Coalition:", MUnit:GetCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } )
if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == MUnit:GetCoalition() then
MUnitCoalition = true
end
@ -2139,6 +2212,677 @@ function SET_UNIT:GetTypeNames( Delimiter )
return TypeReport:Text( Delimiter )
end
end
do -- SET_STATIC
--- @type SET_STATIC
-- @extends Core.Set#SET_BASE
--- # 3) SET_STATIC class, extends @{Set#SET_BASE}
--
-- Mission designers can use the SET_STATIC class to build sets of Statics belonging to certain:
--
-- * Coalitions
-- * Categories
-- * Countries
-- * Static types
-- * Starting with certain prefix strings.
--
-- ## 3.1) SET_STATIC constructor
--
-- Create a new SET_STATIC object with the @{#SET_STATIC.New} method:
--
-- * @{#SET_STATIC.New}: Creates a new SET_STATIC object.
--
-- ## 3.2) Add or Remove STATIC(s) from SET_STATIC
--
-- STATICs can be added and removed using the @{Set#SET_STATIC.AddStaticsByName} and @{Set#SET_STATIC.RemoveStaticsByName} respectively.
-- These methods take a single STATIC name or an array of STATIC names to be added or removed from SET_STATIC.
--
-- ## 3.3) SET_STATIC filter criteria
--
-- You can set filter criteria to define the set of units within the SET_STATIC.
-- Filter criteria are defined by:
--
-- * @{#SET_STATIC.FilterCoalitions}: Builds the SET_STATIC with the units belonging to the coalition(s).
-- * @{#SET_STATIC.FilterCategories}: Builds the SET_STATIC with the units belonging to the category(ies).
-- * @{#SET_STATIC.FilterTypes}: Builds the SET_STATIC with the units belonging to the unit type(s).
-- * @{#SET_STATIC.FilterCountries}: Builds the SET_STATIC with the units belonging to the country(ies).
-- * @{#SET_STATIC.FilterPrefixes}: Builds the SET_STATIC with the units starting with the same prefix string(s).
--
-- Once the filter criteria have been set for the SET_STATIC, you can start filtering using:
--
-- * @{#SET_STATIC.FilterStart}: Starts the filtering of the units within the SET_STATIC.
--
-- Planned filter criteria within development are (so these are not yet available):
--
-- * @{#SET_STATIC.FilterZones}: Builds the SET_STATIC with the units within a @{Zone#ZONE}.
--
-- ## 3.4) SET_STATIC iterators
--
-- Once the filters have been defined and the SET_STATIC has been built, you can iterate the SET_STATIC with the available iterator methods.
-- The iterator methods will walk the SET_STATIC set, and call for each element within the set a function that you provide.
-- The following iterator methods are currently available within the SET_STATIC:
--
-- * @{#SET_STATIC.ForEachStatic}: Calls a function for each alive unit it finds within the SET_STATIC.
-- * @{#SET_GROUP.ForEachGroupCompletelyInZone}: Iterate the SET_GROUP and call an iterator function for each **alive** GROUP presence completely in a @{Zone}, providing the GROUP and optional parameters to the called function.
-- * @{#SET_GROUP.ForEachGroupNotInZone}: Iterate the SET_GROUP and call an iterator function for each **alive** GROUP presence not in a @{Zone}, providing the GROUP and optional parameters to the called function.
--
-- Planned iterators methods in development are (so these are not yet available):
--
-- * @{#SET_STATIC.ForEachStaticInZone}: Calls a function for each unit contained within the SET_STATIC.
-- * @{#SET_STATIC.ForEachStaticCompletelyInZone}: Iterate and call an iterator function for each **alive** STATIC presence completely in a @{Zone}, providing the STATIC and optional parameters to the called function.
-- * @{#SET_STATIC.ForEachStaticNotInZone}: Iterate and call an iterator function for each **alive** STATIC presence not in a @{Zone}, providing the STATIC and optional parameters to the called function.
--
-- ## 3.5 ) SET_STATIC atomic methods
--
-- Various methods exist for a SET_STATIC to perform actions or calculations and retrieve results from the SET_STATIC:
--
-- * @{#SET_STATIC.GetTypeNames}(): Retrieve the type names of the @{Static}s in the SET, delimited by a comma.
--
-- ===
-- @field #SET_STATIC SET_STATIC
SET_STATIC = {
ClassName = "SET_STATIC",
Statics = {},
Filter = {
Coalitions = nil,
Categories = nil,
Types = nil,
Countries = nil,
StaticPrefixes = nil,
},
FilterMeta = {
Coalitions = {
red = coalition.side.RED,
blue = coalition.side.BLUE,
neutral = coalition.side.NEUTRAL,
},
Categories = {
plane = Unit.Category.AIRPLANE,
helicopter = Unit.Category.HELICOPTER,
ground = Unit.Category.GROUND_STATIC,
ship = Unit.Category.SHIP,
structure = Unit.Category.STRUCTURE,
},
},
}
--- Get the first unit from the set.
-- @function [parent=#SET_STATIC] GetFirst
-- @param #SET_STATIC self
-- @return Wrapper.Static#STATIC The STATIC object.
--- Creates a new SET_STATIC object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
-- @param #SET_STATIC self
-- @return #SET_STATIC
-- @usage
-- -- Define a new SET_STATIC Object. This DBObject will contain a reference to all alive Statics.
-- DBObject = SET_STATIC:New()
function SET_STATIC:New()
-- Inherits from BASE
local self = BASE:Inherit( self, SET_BASE:New( _DATABASE.STATICS ) ) -- Core.Set#SET_STATIC
return self
end
--- Add STATIC(s) to SET_STATIC.
-- @param #SET_STATIC self
-- @param #string AddStatic A single STATIC.
-- @return #SET_STATIC self
function SET_STATIC:AddStatic( AddStatic )
self:F2( AddStatic:GetName() )
self:Add( AddStatic:GetName(), AddStatic )
return self
end
--- Add STATIC(s) to SET_STATIC.
-- @param #SET_STATIC self
-- @param #string AddStaticNames A single name or an array of STATIC names.
-- @return #SET_STATIC self
function SET_STATIC:AddStaticsByName( AddStaticNames )
local AddStaticNamesArray = ( type( AddStaticNames ) == "table" ) and AddStaticNames or { AddStaticNames }
self:T( AddStaticNamesArray )
for AddStaticID, AddStaticName in pairs( AddStaticNamesArray ) do
self:Add( AddStaticName, STATIC:FindByName( AddStaticName ) )
end
return self
end
--- Remove STATIC(s) from SET_STATIC.
-- @param Core.Set#SET_STATIC self
-- @param Wrapper.Static#STATIC RemoveStaticNames A single name or an array of STATIC names.
-- @return self
function SET_STATIC:RemoveStaticsByName( RemoveStaticNames )
local RemoveStaticNamesArray = ( type( RemoveStaticNames ) == "table" ) and RemoveStaticNames or { RemoveStaticNames }
for RemoveStaticID, RemoveStaticName in pairs( RemoveStaticNamesArray ) do
self:Remove( RemoveStaticName )
end
return self
end
--- Finds a Static based on the Static Name.
-- @param #SET_STATIC self
-- @param #string StaticName
-- @return Wrapper.Static#STATIC The found Static.
function SET_STATIC:FindStatic( StaticName )
local StaticFound = self.Set[StaticName]
return StaticFound
end
--- Builds a set of units of coalitions.
-- Possible current coalitions are red, blue and neutral.
-- @param #SET_STATIC self
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral".
-- @return #SET_STATIC self
function SET_STATIC:FilterCoalitions( Coalitions )
if not self.Filter.Coalitions then
self.Filter.Coalitions = {}
end
if type( Coalitions ) ~= "table" then
Coalitions = { Coalitions }
end
for CoalitionID, Coalition in pairs( Coalitions ) do
self.Filter.Coalitions[Coalition] = Coalition
end
return self
end
--- Builds a set of units out of categories.
-- Possible current categories are plane, helicopter, ground, ship.
-- @param #SET_STATIC self
-- @param #string Categories Can take the following values: "plane", "helicopter", "ground", "ship".
-- @return #SET_STATIC self
function SET_STATIC:FilterCategories( Categories )
if not self.Filter.Categories then
self.Filter.Categories = {}
end
if type( Categories ) ~= "table" then
Categories = { Categories }
end
for CategoryID, Category in pairs( Categories ) do
self.Filter.Categories[Category] = Category
end
return self
end
--- Builds a set of units of defined unit types.
-- Possible current types are those types known within DCS world.
-- @param #SET_STATIC self
-- @param #string Types Can take those type strings known within DCS world.
-- @return #SET_STATIC self
function SET_STATIC:FilterTypes( Types )
if not self.Filter.Types then
self.Filter.Types = {}
end
if type( Types ) ~= "table" then
Types = { Types }
end
for TypeID, Type in pairs( Types ) do
self.Filter.Types[Type] = Type
end
return self
end
--- Builds a set of units of defined countries.
-- Possible current countries are those known within DCS world.
-- @param #SET_STATIC self
-- @param #string Countries Can take those country strings known within DCS world.
-- @return #SET_STATIC self
function SET_STATIC:FilterCountries( Countries )
if not self.Filter.Countries then
self.Filter.Countries = {}
end
if type( Countries ) ~= "table" then
Countries = { Countries }
end
for CountryID, Country in pairs( Countries ) do
self.Filter.Countries[Country] = Country
end
return self
end
--- Builds a set of units of defined unit prefixes.
-- All the units starting with the given prefixes will be included within the set.
-- @param #SET_STATIC self
-- @param #string Prefixes The prefix of which the unit name starts with.
-- @return #SET_STATIC self
function SET_STATIC:FilterPrefixes( Prefixes )
if not self.Filter.StaticPrefixes then
self.Filter.StaticPrefixes = {}
end
if type( Prefixes ) ~= "table" then
Prefixes = { Prefixes }
end
for PrefixID, Prefix in pairs( Prefixes ) do
self.Filter.StaticPrefixes[Prefix] = Prefix
end
return self
end
--- Starts the filtering.
-- @param #SET_STATIC self
-- @return #SET_STATIC self
function SET_STATIC:FilterStart()
if _DATABASE then
self:_FilterStart()
end
return self
end
--- 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_STATIC self
-- @param Core.Event#EVENTDATA Event
-- @return #string The name of the STATIC
-- @return #table The STATIC
function SET_STATIC:AddInDatabase( Event )
self:F3( { Event } )
if Event.IniObjectCategory == 1 then
if not self.Database[Event.IniDCSStaticName] then
self.Database[Event.IniDCSStaticName] = STATIC:Register( Event.IniDCSStaticName )
self:T3( self.Database[Event.IniDCSStaticName] )
end
end
return Event.IniDCSStaticName, self.Database[Event.IniDCSStaticName]
end
--- 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_STATIC self
-- @param Core.Event#EVENTDATA Event
-- @return #string The name of the STATIC
-- @return #table The STATIC
function SET_STATIC:FindInDatabase( Event )
self:F2( { Event.IniDCSStaticName, self.Set[Event.IniDCSStaticName], Event } )
return Event.IniDCSStaticName, self.Set[Event.IniDCSStaticName]
end
do -- Is Zone methods
--- Check if minimal one element of the SET_STATIC is in the Zone.
-- @param #SET_STATIC self
-- @param Core.Zone#ZONE Zone The Zone to be tested for.
-- @return #boolean
function SET_STATIC:IsPatriallyInZone( Zone )
local IsPartiallyInZone = false
local function EvaluateZone( ZoneStatic )
local ZoneStaticName = ZoneStatic:GetName()
if self:FindStatic( ZoneStaticName ) then
IsPartiallyInZone = true
return false
end
return true
end
return IsPartiallyInZone
end
--- Check if no element of the SET_STATIC is in the Zone.
-- @param #SET_STATIC self
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
-- @return #boolean
function SET_STATIC:IsNotInZone( Zone )
local IsNotInZone = true
local function EvaluateZone( ZoneStatic )
local ZoneStaticName = ZoneStatic:GetName()
if self:FindStatic( ZoneStaticName ) then
IsNotInZone = false
return false
end
return true
end
Zone:Search( EvaluateZone )
return IsNotInZone
end
--- Check if minimal one element of the SET_STATIC is in the Zone.
-- @param #SET_STATIC self
-- @param #function IteratorFunction The function that will be called when there is an alive STATIC in the SET_STATIC. The function needs to accept a STATIC parameter.
-- @return #SET_STATIC self
function SET_STATIC:ForEachStaticInZone( IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.Set )
return self
end
end
--- Iterate the SET_STATIC and call an interator function for each **alive** STATIC, providing the STATIC and optional parameters.
-- @param #SET_STATIC self
-- @param #function IteratorFunction The function that will be called when there is an alive STATIC in the SET_STATIC. The function needs to accept a STATIC parameter.
-- @return #SET_STATIC self
function SET_STATIC:ForEachStatic( IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.Set )
return self
end
--- Iterate the SET_STATIC and call an iterator function for each **alive** STATIC presence completely in a @{Zone}, providing the STATIC and optional parameters to the called function.
-- @param #SET_STATIC self
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
-- @param #function IteratorFunction The function that will be called when there is an alive STATIC in the SET_STATIC. The function needs to accept a STATIC parameter.
-- @return #SET_STATIC self
function SET_STATIC:ForEachStaticCompletelyInZone( ZoneObject, IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.Set,
--- @param Core.Zone#ZONE_BASE ZoneObject
-- @param Wrapper.Static#STATIC StaticObject
function( ZoneObject, StaticObject )
if StaticObject:IsInZone( ZoneObject ) then
return true
else
return false
end
end, { ZoneObject } )
return self
end
--- Iterate the SET_STATIC and call an iterator function for each **alive** STATIC presence not in a @{Zone}, providing the STATIC and optional parameters to the called function.
-- @param #SET_STATIC self
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
-- @param #function IteratorFunction The function that will be called when there is an alive STATIC in the SET_STATIC. The function needs to accept a STATIC parameter.
-- @return #SET_STATIC self
function SET_STATIC:ForEachStaticNotInZone( ZoneObject, IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.Set,
--- @param Core.Zone#ZONE_BASE ZoneObject
-- @param Wrapper.Static#STATIC StaticObject
function( ZoneObject, StaticObject )
if StaticObject:IsNotInZone( ZoneObject ) then
return true
else
return false
end
end, { ZoneObject } )
return self
end
--- Returns map of unit types.
-- @param #SET_STATIC self
-- @return #map<#string,#number> A map of the unit types found. The key is the StaticTypeName and the value is the amount of unit types found.
function SET_STATIC:GetStaticTypes()
self:F2()
local MT = {} -- Message Text
local StaticTypes = {}
for StaticID, StaticData in pairs( self:GetSet() ) do
local TextStatic = StaticData -- Wrapper.Static#STATIC
if TextStatic:IsAlive() then
local StaticType = TextStatic:GetTypeName()
if not StaticTypes[StaticType] then
StaticTypes[StaticType] = 1
else
StaticTypes[StaticType] = StaticTypes[StaticType] + 1
end
end
end
for StaticTypeID, StaticType in pairs( StaticTypes ) do
MT[#MT+1] = StaticType .. " of " .. StaticTypeID
end
return StaticTypes
end
--- Returns a comma separated string of the unit types with a count in the @{Set}.
-- @param #SET_STATIC self
-- @return #string The unit types string
function SET_STATIC:GetStaticTypesText()
self:F2()
local MT = {} -- Message Text
local StaticTypes = self:GetStaticTypes()
for StaticTypeID, StaticType in pairs( StaticTypes ) do
MT[#MT+1] = StaticType .. " of " .. StaticTypeID
end
return table.concat( MT, ", " )
end
--- Get the center coordinate of the SET_STATIC.
-- @param #SET_STATIC self
-- @return Core.Point#COORDINATE The center coordinate of all the units in the set, including heading in degrees and speed in mps in case of moving units.
function SET_STATIC:GetCoordinate()
local Coordinate = self:GetFirst():GetCoordinate()
local x1 = Coordinate.x
local x2 = Coordinate.x
local y1 = Coordinate.y
local y2 = Coordinate.y
local z1 = Coordinate.z
local z2 = Coordinate.z
local MaxVelocity = 0
local AvgHeading = nil
local MovingCount = 0
for StaticName, StaticData in pairs( self:GetSet() ) do
local Static = StaticData -- Wrapper.Static#STATIC
local Coordinate = Static:GetCoordinate()
x1 = ( Coordinate.x < x1 ) and Coordinate.x or x1
x2 = ( Coordinate.x > x2 ) and Coordinate.x or x2
y1 = ( Coordinate.y < y1 ) and Coordinate.y or y1
y2 = ( Coordinate.y > y2 ) and Coordinate.y or y2
z1 = ( Coordinate.y < z1 ) and Coordinate.z or z1
z2 = ( Coordinate.y > z2 ) and Coordinate.z or z2
local Velocity = Coordinate:GetVelocity()
if Velocity ~= 0 then
MaxVelocity = ( MaxVelocity < Velocity ) and Velocity or MaxVelocity
local Heading = Coordinate:GetHeading()
AvgHeading = AvgHeading and ( AvgHeading + Heading ) or Heading
MovingCount = MovingCount + 1
end
end
AvgHeading = AvgHeading and ( AvgHeading / MovingCount )
Coordinate.x = ( x2 - x1 ) / 2 + x1
Coordinate.y = ( y2 - y1 ) / 2 + y1
Coordinate.z = ( z2 - z1 ) / 2 + z1
Coordinate:SetHeading( AvgHeading )
Coordinate:SetVelocity( MaxVelocity )
self:F( { Coordinate = Coordinate } )
return Coordinate
end
--- Get the maximum velocity of the SET_STATIC.
-- @param #SET_STATIC self
-- @return #number The speed in mps in case of moving units.
function SET_STATIC:GetVelocity()
return 0
end
--- Get the average heading of the SET_STATIC.
-- @param #SET_STATIC self
-- @return #number Heading Heading in degrees and speed in mps in case of moving units.
function SET_STATIC:GetHeading()
local HeadingSet = nil
local MovingCount = 0
for StaticName, StaticData in pairs( self:GetSet() ) do
local Static = StaticData -- Wrapper.Static#STATIC
local Coordinate = Static:GetCoordinate()
local Velocity = Coordinate:GetVelocity()
if Velocity ~= 0 then
local Heading = Coordinate:GetHeading()
if HeadingSet == nil then
HeadingSet = Heading
else
local HeadingDiff = ( HeadingSet - Heading + 180 + 360 ) % 360 - 180
HeadingDiff = math.abs( HeadingDiff )
if HeadingDiff > 5 then
HeadingSet = nil
break
end
end
end
end
return HeadingSet
end
---
-- @param #SET_STATIC self
-- @param Wrapper.Static#STATIC MStatic
-- @return #SET_STATIC self
function SET_STATIC:IsIncludeObject( MStatic )
self:F2( MStatic )
local MStaticInclude = true
if self.Filter.Coalitions then
local MStaticCoalition = false
for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do
self:T3( { "Coalition:", MStatic:GetCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } )
if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == MStatic:GetCoalition() then
MStaticCoalition = true
end
end
MStaticInclude = MStaticInclude and MStaticCoalition
end
if self.Filter.Categories then
local MStaticCategory = false
for CategoryID, CategoryName in pairs( self.Filter.Categories ) do
self:T3( { "Category:", MStatic:GetDesc().category, self.FilterMeta.Categories[CategoryName], CategoryName } )
if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == MStatic:GetDesc().category then
MStaticCategory = true
end
end
MStaticInclude = MStaticInclude and MStaticCategory
end
if self.Filter.Types then
local MStaticType = false
for TypeID, TypeName in pairs( self.Filter.Types ) do
self:T3( { "Type:", MStatic:GetTypeName(), TypeName } )
if TypeName == MStatic:GetTypeName() then
MStaticType = true
end
end
MStaticInclude = MStaticInclude and MStaticType
end
if self.Filter.Countries then
local MStaticCountry = false
for CountryID, CountryName in pairs( self.Filter.Countries ) do
self:T3( { "Country:", MStatic:GetCountry(), CountryName } )
if country.id[CountryName] == MStatic:GetCountry() then
MStaticCountry = true
end
end
MStaticInclude = MStaticInclude and MStaticCountry
end
if self.Filter.StaticPrefixes then
local MStaticPrefix = false
for StaticPrefixId, StaticPrefix in pairs( self.Filter.StaticPrefixes ) do
self:T3( { "Prefix:", string.find( MStatic:GetName(), StaticPrefix, 1 ), StaticPrefix } )
if string.find( MStatic:GetName(), StaticPrefix, 1 ) then
MStaticPrefix = true
end
end
MStaticInclude = MStaticInclude and MStaticPrefix
end
self:T2( MStaticInclude )
return MStaticInclude
end
--- Retrieve the type names of the @{Static}s in the SET, delimited by an optional delimiter.
-- @param #SET_STATIC self
-- @param #string Delimiter (optional) The delimiter, which is default a comma.
-- @return #string The types of the @{Static}s delimited.
function SET_STATIC:GetTypeNames( Delimiter )
Delimiter = Delimiter or ", "
local TypeReport = REPORT:New()
local Types = {}
for StaticName, StaticData in pairs( self:GetSet() ) do
local Static = StaticData -- Wrapper.Static#STATIC
local StaticTypeName = Static:GetTypeName()
if not Types[StaticTypeName] then
Types[StaticTypeName] = StaticTypeName
TypeReport:Add( StaticTypeName )
end
end
return TypeReport:Text( Delimiter )
end
end
--- SET_CLIENT

View File

@ -562,6 +562,39 @@ function ZONE_RADIUS:GetVec3( Height )
end
--- Searches the zone
-- @param #ZONE_RADIUS self
-- @param EvaluateFunction
function ZONE_RADIUS:SearchZone( EvaluateFunction )
local SearchZoneResult = true
local ZoneCoord = self:GetCoordinate()
local ZoneRadius = self:GetRadius()
self:E({ZoneCoord = ZoneCoord, ZoneRadius = ZoneRadius, ZoneCoordLL = ZoneCoord:ToStringLLDMS()})
local SphereSearch = {
id = world.VolumeType.SPHERE,
params = {
point = ZoneCoord:GetVec3(),
radius = ZoneRadius / 2,
}
}
local function EvaluateZone( DCSZoneUnit )
env.info( DCSZoneUnit:getName() )
local ZoneUnit = UNIT:Find( DCSZoneUnit )
return EvaluateFunction( ZoneUnit )
end
world.searchObjects( Object.Category.UNIT, SphereSearch, EvaluateZone )
end
--- Returns if a location is within the zone.
-- @param #ZONE_RADIUS self
-- @param Dcs.DCSTypes#Vec2 Vec2 The location to test.

View File

@ -36,6 +36,7 @@ function PROTECT:New( ProtectZone )
self.ProtectZone = ProtectZone
self.ProtectUnitSet = SET_UNIT:New()
self.ProtectStaticSet = SET_STATIC:New()
self.CaptureUnitSet = SET_UNIT:New()
self:SetStartState( "Idle" )
@ -62,6 +63,27 @@ function PROTECT:AddProtectUnit( ProtectUnit )
self.ProtectUnitSet:AddUnit( ProtectUnit )
end
--- Get the Protect unit Set.
-- @param #PROTECT self
-- @return Wrapper.Unit#UNIT The Set of capture units.
function PROTECT:GetProtectUnitSet()
return self.ProtectUnitSet
end
--- Add a static to the protection.
-- @param #PROTECT self
-- @param Wrapper.Unit#UNIT ProtectStatic A @{Static} object to protect.
function PROTECT:AddProtectStatic( ProtectStatic )
self.ProtectStaticSet:AddStatic( ProtectStatic )
end
--- Get the Protect static Set.
-- @param #PROTECT self
-- @return Wrapper.Unit#UNIT The Set of capture statics.
function PROTECT:GetProtectStaticSet()
return self.ProtectStaticSet
end
--- Add a Capture unit to allow to capture the zone.
-- @param #PROTECT self
-- @param Wrapper.Unit#UNIT CaptureUnit A @{Unit} object to allow a capturing.
@ -98,25 +120,38 @@ function PROTECT:AreProtectUnitsAlive()
return IsAlive
end
--- Check if the statics are still alive.
-- @param #PROTECT self
function PROTECT:AreProtectStaticsAlive()
local IsAlive = false
local StaticSet = self.ProtectStaticSet
StaticSet:Flush()
local StaticList = StaticSet:GetSet()
for UnitID, ProtectStatic in pairs( StaticList ) do
local IsStaticAlive = ProtectStatic:IsAlive()
if IsStaticAlive == true then
IsAlive = true
break
end
end
return IsAlive
end
--- Check if there is a capture unit in the zone.
-- @param #PROTECT self
function PROTECT:IsCaptureUnitInZone()
local IsInZone = false
local CaptureUnitSet = self.CaptureUnitSet
CaptureUnitSet:Flush()
local CaptureUnitList = CaptureUnitSet:GetSet()
for UnitID, CaptureUnit in pairs( CaptureUnitList ) do
local IsUnitAlive = CaptureUnit:IsAlive()
if IsUnitAlive == true then
if CaptureUnit:IsInZone( self.ProtectZone ) then
IsInZone = true
break
end
end
end
local IsInZone = self.CaptureUnitSet:IsPartiallyInZone( self.ProtectZone )
self:E({IsInZone = IsInZone})
return IsInZone
end
@ -136,7 +171,9 @@ end
function PROTECT:onafterCheck()
if self:AreProtectUnitsAlive() or not self:IsCaptureUnitInZone() then
if ( self.ProtectUnitSet and self:AreProtectUnitsAlive() ) or
( self.ProtectStaticSet and self:AreProtectStaticsAlive() ) or
self:IsCaptureUnitInZone() == false then
self:__Check( -1 )
else
self:Capture()

File diff suppressed because it is too large Load Diff