mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Group Set progresss
need to fix some bugs still
This commit is contained in:
@@ -1,321 +0,0 @@
|
||||
--- Create and manage a set of groups.
|
||||
--
|
||||
-- @{#GROUPSET} class
|
||||
-- ==================
|
||||
-- Mission designers can use the GROUPSET class to build sets of groups belonging to certain:
|
||||
--
|
||||
-- * Coalitions
|
||||
-- * Categories
|
||||
-- * Countries
|
||||
-- * Starting with certain prefix strings.
|
||||
--
|
||||
-- GROUPSET construction methods:
|
||||
-- =================================
|
||||
-- Create a new GROUPSET object with the @{#GROUPSET.New} method:
|
||||
--
|
||||
-- * @{#GROUPSET.New}: Creates a new GROUPSET object.
|
||||
--
|
||||
--
|
||||
-- GROUPSET filter criteria:
|
||||
-- =========================
|
||||
-- You can set filter criteria to define the set of groups within the GROUPSET.
|
||||
-- Filter criteria are defined by:
|
||||
--
|
||||
-- * @{#GROUPSET.FilterCoalitions}: Builds the GROUPSET with the groups belonging to the coalition(s).
|
||||
-- * @{#GROUPSET.FilterCategories}: Builds the GROUPSET with the groups belonging to the category(ies).
|
||||
-- * @{#GROUPSET.FilterCountries}: Builds the GROUPSET with the gruops belonging to the country(ies).
|
||||
-- * @{#GROUPSET.FilterPrefixes}: Builds the GROUPSET with the groups starting with the same prefix string(s).
|
||||
--
|
||||
-- Once the filter criteria have been set for the GROUPSET, you can start filtering using:
|
||||
--
|
||||
-- * @{#GROUPSET.FilterStart}: Starts the filtering of the groups within the GROUPSET.
|
||||
--
|
||||
-- Planned filter criteria within development are (so these are not yet available):
|
||||
--
|
||||
-- * @{#GROUPSET.FilterZones}: Builds the GROUPSET with the groups within a @{Zone#ZONE}.
|
||||
--
|
||||
--
|
||||
-- GROUPSET iterators:
|
||||
-- ===================
|
||||
-- Once the filters have been defined and the GROUPSET has been built, you can iterate the GROUPSET with the available iterator methods.
|
||||
-- The iterator methods will walk the GROUPSET set, and call for each element within the set a function that you provide.
|
||||
-- The following iterator methods are currently available within the GROUPSET:
|
||||
--
|
||||
-- * @{#GROUPSET.ForEachGroup}: Calls a function for each alive group it finds within the GROUPSET.
|
||||
--
|
||||
-- @module GroupSet
|
||||
-- @author FlightControl
|
||||
|
||||
Include.File( "Routines" )
|
||||
Include.File( "Base" )
|
||||
Include.File( "Group" )
|
||||
Include.File( "Set" )
|
||||
|
||||
|
||||
--- GROUPSET class
|
||||
-- @type GROUPSET
|
||||
-- @extends Set#SET
|
||||
GROUPSET = {
|
||||
ClassName = "GROUPSET",
|
||||
Filter = {
|
||||
Coalitions = nil,
|
||||
Categories = nil,
|
||||
Countries = nil,
|
||||
GroupPrefixes = nil,
|
||||
},
|
||||
FilterMeta = {
|
||||
Coalitions = {
|
||||
red = coalition.side.RED,
|
||||
blue = coalition.side.BLUE,
|
||||
neutral = coalition.side.NEUTRAL,
|
||||
},
|
||||
Categories = {
|
||||
plane = Group.Category.AIRPLANE,
|
||||
helicopter = Group.Category.HELICOPTER,
|
||||
ground = Group.Category.GROUND_UNIT,
|
||||
ship = Group.Category.SHIP,
|
||||
structure = Group.Category.STRUCTURE,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
--- Creates a new GROUPSET object, building a set of groups belonging to a coalitions, categories, countries, types or with defined prefix names.
|
||||
-- @param #GROUPSET self
|
||||
-- @return #GROUPSET
|
||||
-- @usage
|
||||
-- -- Define a new GROUPSET Object. This DBObject will contain a reference to all alive GROUPS.
|
||||
-- DBObject = GROUPSET:New()
|
||||
function GROUPSET:New()
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, SET:New( _DATABASE.GROUPS ) )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Finds a Group based on the Group Name.
|
||||
-- @param #GROUPSET self
|
||||
-- @param #string GroupName
|
||||
-- @return Group#GROUP The found Group.
|
||||
function GROUPSET:FindGroup( GroupName )
|
||||
|
||||
local GroupFound = self.Set[GroupName]
|
||||
return GroupFound
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Builds a set of groups of coalitions.
|
||||
-- Possible current coalitions are red, blue and neutral.
|
||||
-- @param #GROUPSET self
|
||||
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral".
|
||||
-- @return #GROUPSET self
|
||||
function GROUPSET: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 groups out of categories.
|
||||
-- Possible current categories are plane, helicopter, ground, ship.
|
||||
-- @param #GROUPSET self
|
||||
-- @param #string Categories Can take the following values: "plane", "helicopter", "ground", "ship".
|
||||
-- @return #GROUPSET self
|
||||
function GROUPSET: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 groups of defined countries.
|
||||
-- Possible current countries are those known within DCS world.
|
||||
-- @param #GROUPSET self
|
||||
-- @param #string Countries Can take those country strings known within DCS world.
|
||||
-- @return #GROUPSET self
|
||||
function GROUPSET: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 groups of defined GROUP prefixes.
|
||||
-- All the groups starting with the given prefixes will be included within the set.
|
||||
-- @param #GROUPSET self
|
||||
-- @param #string Prefixes The prefix of which the group name starts with.
|
||||
-- @return #GROUPSET self
|
||||
function GROUPSET:FilterPrefixes( Prefixes )
|
||||
if not self.Filter.GroupPrefixes then
|
||||
self.Filter.GroupPrefixes = {}
|
||||
end
|
||||
if type( Prefixes ) ~= "table" then
|
||||
Prefixes = { Prefixes }
|
||||
end
|
||||
for PrefixID, Prefix in pairs( Prefixes ) do
|
||||
self.Filter.GroupPrefixes[Prefix] = Prefix
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Starts the filtering.
|
||||
-- @param #GROUPSET self
|
||||
-- @return #GROUPSET self
|
||||
function GROUPSET: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 birth event!
|
||||
-- @param #GROUPSET self
|
||||
-- @param Event#EVENTDATA Event
|
||||
-- @return #string The name of the GROUP
|
||||
-- @return #table The GROUP
|
||||
function GROUPSET:AddInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
if not self.Database[Event.IniDCSGroupName] then
|
||||
self.Database[Event.IniDCSGroupName] = GROUP:Register( Event.IniDCSGroupName )
|
||||
self:T3( self.Database[Event.IniDCSGroupName] )
|
||||
end
|
||||
|
||||
return Event.IniDCSGroupName, self.Database[Event.IniDCSGroupName]
|
||||
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 event or vise versa!
|
||||
-- @param #GROUPSET self
|
||||
-- @param Event#EVENTDATA Event
|
||||
-- @return #string The name of the GROUP
|
||||
-- @return #table The GROUP
|
||||
function GROUPSET:FindInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
return Event.IniDCSGroupName, self.Database[Event.IniDCSGroupName]
|
||||
end
|
||||
|
||||
--- Interate the GROUPSET and call an interator function for each **alive** GROUP, providing the GROUP and optional parameters.
|
||||
-- @param #GROUPSET self
|
||||
-- @param #function IteratorFunction The function that will be called when there is an alive GROUP in the GROUPSET. The function needs to accept a GROUP parameter.
|
||||
-- @return #GROUPSET self
|
||||
function GROUPSET:ForEachGroup( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self.Set )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
----- Interate the GROUPSET and call an interator function for each **alive** player, providing the Group of the player and optional parameters.
|
||||
---- @param #GROUPSET self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the GROUPSET. The function needs to accept a GROUP parameter.
|
||||
---- @return #GROUPSET self
|
||||
--function GROUPSET:ForEachPlayer( IteratorFunction, ... )
|
||||
-- self:F2( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.PlayersAlive )
|
||||
--
|
||||
-- return self
|
||||
--end
|
||||
--
|
||||
--
|
||||
----- Interate the GROUPSET and call an interator function for each client, providing the Client to the function and optional parameters.
|
||||
---- @param #GROUPSET self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the GROUPSET. The function needs to accept a CLIENT parameter.
|
||||
---- @return #GROUPSET self
|
||||
--function GROUPSET:ForEachClient( IteratorFunction, ... )
|
||||
-- self:F2( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.Clients )
|
||||
--
|
||||
-- return self
|
||||
--end
|
||||
|
||||
|
||||
---
|
||||
-- @param #GROUPSET self
|
||||
-- @param Group#GROUP MooseGroup
|
||||
-- @return #GROUPSET self
|
||||
function GROUPSET:IsIncludeObject( MooseGroup )
|
||||
self:F2( MooseGroup )
|
||||
local MooseGroupInclude = true
|
||||
|
||||
if self.Filter.Coalitions then
|
||||
local MooseGroupCoalition = false
|
||||
for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do
|
||||
self:T3( { "Coalition:", MooseGroup:GetCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } )
|
||||
if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == MooseGroup:GetCoalition() then
|
||||
MooseGroupCoalition = true
|
||||
end
|
||||
end
|
||||
MooseGroupInclude = MooseGroupInclude and MooseGroupCoalition
|
||||
end
|
||||
|
||||
if self.Filter.Categories then
|
||||
local MooseGroupCategory = false
|
||||
for CategoryID, CategoryName in pairs( self.Filter.Categories ) do
|
||||
self:T3( { "Category:", MooseGroup:GetCategory(), self.FilterMeta.Categories[CategoryName], CategoryName } )
|
||||
if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == MooseGroup:GetCategory() then
|
||||
MooseGroupCategory = true
|
||||
end
|
||||
end
|
||||
MooseGroupInclude = MooseGroupInclude and MooseGroupCategory
|
||||
end
|
||||
|
||||
if self.Filter.Countries then
|
||||
local MooseGroupCountry = false
|
||||
for CountryID, CountryName in pairs( self.Filter.Countries ) do
|
||||
self:T3( { "Country:", MooseGroup:GetCountry(), CountryName } )
|
||||
if country.id[CountryName] == MooseGroup:GetCountry() then
|
||||
MooseGroupCountry = true
|
||||
end
|
||||
end
|
||||
MooseGroupInclude = MooseGroupInclude and MooseGroupCountry
|
||||
end
|
||||
|
||||
if self.Filter.GroupPrefixes then
|
||||
local MooseGroupPrefix = false
|
||||
for GroupPrefixId, GroupPrefix in pairs( self.Filter.GroupPrefixes ) do
|
||||
self:T3( { "Prefix:", string.find( MooseGroup:GetName(), GroupPrefix, 1 ), GroupPrefix } )
|
||||
if string.find( MooseGroup:GetName(), GroupPrefix, 1 ) then
|
||||
MooseGroupPrefix = true
|
||||
end
|
||||
end
|
||||
MooseGroupInclude = MooseGroupInclude and MooseGroupPrefix
|
||||
end
|
||||
|
||||
self:T2( MooseGroupInclude )
|
||||
return MooseGroupInclude
|
||||
end
|
||||
|
||||
|
||||
@@ -1,8 +1,60 @@
|
||||
--- Manage sets of units and groups.
|
||||
--- This module contains the SET classes.
|
||||
--
|
||||
-- @{#Set} class
|
||||
-- ==================
|
||||
-- Mission designers can use the SET class to build sets of units belonging to certain:
|
||||
-- ===
|
||||
--
|
||||
-- 1) @{Set#SET_BASE} class, extending @{Base#BASE}
|
||||
-- ================================================
|
||||
-- The @{Set#SET_BASE} class defines the core functions that define a collection of objects.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- 2) @{Set#SET_GROUP} class, extending @{Set#SET_BASE}
|
||||
-- ====================================================
|
||||
-- Mission designers can use the @{Set#SET_GROUP} class to build sets of groups belonging to certain:
|
||||
--
|
||||
-- * Coalitions
|
||||
-- * Categories
|
||||
-- * Countries
|
||||
-- * Starting with certain prefix strings.
|
||||
--
|
||||
-- 2.1) SET_GROUP construction methods:
|
||||
-- ------------------------------------
|
||||
-- Create a new SET_GROUP object with the @{#SET_GROUP.New} method:
|
||||
--
|
||||
-- * @{#SET_GROUP.New}: Creates a new SET_GROUP object.
|
||||
--
|
||||
-- 2.2) SET_GROUP filter criteria:
|
||||
-- -------------------------------
|
||||
-- You can set filter criteria to define the set of groups within the SET_GROUP.
|
||||
-- Filter criteria are defined by:
|
||||
--
|
||||
-- * @{#SET_GROUP.FilterCoalitions}: Builds the SET_GROUP with the groups belonging to the coalition(s).
|
||||
-- * @{#SET_GROUP.FilterCategories}: Builds the SET_GROUP with the groups belonging to the category(ies).
|
||||
-- * @{#SET_GROUP.FilterCountries}: Builds the SET_GROUP with the gruops belonging to the country(ies).
|
||||
-- * @{#SET_GROUP.FilterPrefixes}: Builds the SET_GROUP with the groups starting with the same prefix string(s).
|
||||
--
|
||||
-- Once the filter criteria have been set for the SET_GROUP, you can start filtering using:
|
||||
--
|
||||
-- * @{#SET_GROUP.FilterStart}: Starts the filtering of the groups within the SET_GROUP.
|
||||
--
|
||||
-- Planned filter criteria within development are (so these are not yet available):
|
||||
--
|
||||
-- * @{#SET_GROUP.FilterZones}: Builds the SET_GROUP with the groups within a @{Zone#ZONE}.
|
||||
--
|
||||
--
|
||||
-- 2.3) SET_GROUP iterators:
|
||||
-- -------------------------
|
||||
-- Once the filters have been defined and the SET_GROUP has been built, you can iterate the SET_GROUP with the available iterator methods.
|
||||
-- The iterator methods will walk the SET_GROUP set, and call for each element within the set a function that you provide.
|
||||
-- The following iterator methods are currently available within the SET_GROUP:
|
||||
--
|
||||
-- * @{#SET_GROUP.ForEachGroup}: Calls a function for each alive group it finds within the SET_GROUP.
|
||||
--
|
||||
-- ====
|
||||
--
|
||||
-- 3) @{Set#SET_UNIT} class, extending @{Set#SET_BASE}
|
||||
-- ===================================================
|
||||
-- Mission designers can use the @{Set#SET_UNIT} class to build sets of units belonging to certain:
|
||||
--
|
||||
-- * Coalitions
|
||||
-- * Categories
|
||||
@@ -10,55 +62,48 @@
|
||||
-- * Unit types
|
||||
-- * Starting with certain prefix strings.
|
||||
--
|
||||
-- This list will grow over time. Planned developments are to include filters and iterators.
|
||||
-- Additional filters will be added around @{Zone#ZONEs}, Radiuses, Active players, ...
|
||||
-- More iterators will be implemented in the near future ...
|
||||
--
|
||||
-- Administers the Initial Sets of the Mission Templates as defined within the Mission Editor.
|
||||
-- 3.1) SET_UNIT construction methods:
|
||||
-- -----------------------------------
|
||||
-- Create a new SET_UNIT object with the @{#SET_UNIT.New} method:
|
||||
--
|
||||
-- SET construction methods:
|
||||
-- =================================
|
||||
-- Create a new SET object with the @{#SET.New} method:
|
||||
--
|
||||
-- * @{#SET.New}: Creates a new SET object.
|
||||
-- * @{#SET_UNIT.New}: Creates a new SET_UNIT object.
|
||||
--
|
||||
--
|
||||
-- SET filter criteria:
|
||||
-- =========================
|
||||
-- You can set filter criteria to define the set of units within the SET.
|
||||
-- 3.2) SET_UNIT filter criteria:
|
||||
-- ------------------------------
|
||||
-- You can set filter criteria to define the set of units within the SET_UNIT.
|
||||
-- Filter criteria are defined by:
|
||||
--
|
||||
-- * @{#SET.FilterCoalitions}: Builds the SET with the units belonging to the coalition(s).
|
||||
-- * @{#SET.FilterCategories}: Builds the SET with the units belonging to the category(ies).
|
||||
-- * @{#SET.FilterTypes}: Builds the SET with the units belonging to the unit type(s).
|
||||
-- * @{#SET.FilterCountries}: Builds the SET with the units belonging to the country(ies).
|
||||
-- * @{#SET.FilterUnitPrefixes}: Builds the SET with the units starting with the same prefix string(s).
|
||||
-- * @{#SET_UNIT.FilterCoalitions}: Builds the SET_UNIT with the units belonging to the coalition(s).
|
||||
-- * @{#SET_UNIT.FilterCategories}: Builds the SET_UNIT with the units belonging to the category(ies).
|
||||
-- * @{#SET_UNIT.FilterTypes}: Builds the SET_UNIT with the units belonging to the unit type(s).
|
||||
-- * @{#SET_UNIT.FilterCountries}: Builds the SET_UNIT with the units belonging to the country(ies).
|
||||
-- * @{#SET_UNIT.FilterPrefixes}: Builds the SET_UNIT with the units starting with the same prefix string(s).
|
||||
--
|
||||
-- Once the filter criteria have been set for the SET, you can start filtering using:
|
||||
-- Once the filter criteria have been set for the SET_UNIT, you can start filtering using:
|
||||
--
|
||||
-- * @{#SET.FilterStart}: Starts the filtering of the units within the SET.
|
||||
-- * @{#SET_UNIT.FilterStart}: Starts the filtering of the units within the SET_UNIT.
|
||||
--
|
||||
-- Planned filter criteria within development are (so these are not yet available):
|
||||
--
|
||||
-- * @{#SET.FilterGroupPrefixes}: Builds the SET with the groups of the units starting with the same prefix string(s).
|
||||
-- * @{#SET.FilterZones}: Builds the SET with the units within a @{Zone#ZONE}.
|
||||
-- * @{#SET_UNIT.FilterZones}: Builds the SET_UNIT with the units within a @{Zone#ZONE}.
|
||||
--
|
||||
-- 3.3) SET_UNIT iterators:
|
||||
-- ------------------------
|
||||
-- Once the filters have been defined and the SET_UNIT has been built, you can iterate the SET_UNIT with the available iterator methods.
|
||||
-- The iterator methods will walk the SET_UNIT set, and call for each element within the set a function that you provide.
|
||||
-- The following iterator methods are currently available within the SET_UNIT:
|
||||
--
|
||||
-- SET iterators:
|
||||
-- ===================
|
||||
-- Once the filters have been defined and the SET has been built, you can iterate the SET with the available iterator methods.
|
||||
-- The iterator methods will walk the SET set, and call for each element within the set a function that you provide.
|
||||
-- The following iterator methods are currently available within the SET:
|
||||
--
|
||||
-- * @{#SET.ForEachAliveUnit}: Calls a function for each alive unit it finds within the SET.
|
||||
-- * @{#SET_UNIT.ForEachUnit}: Calls a function for each alive unit it finds within the SET_UNIT.
|
||||
--
|
||||
-- Planned iterators methods in development are (so these are not yet available):
|
||||
--
|
||||
-- * @{#SET.ForEachUnit}: Calls a function for each unit contained within the SET.
|
||||
-- * @{#SET.ForEachGroup}: Calls a function for each group contained within the SET.
|
||||
-- * @{#SET.ForEachUnitInZone}: Calls a function for each unit within a certain zone contained within the SET.
|
||||
-- * @{#SET_UNIT.ForEachUnitInGroup}: Calls a function for each group contained within the SET_UNIT.
|
||||
-- * @{#SET_UNIT.ForEachUnitInZone}: Calls a function for each unit within a certain zone contained within the SET_UNIT.
|
||||
--
|
||||
--
|
||||
-- ====
|
||||
--
|
||||
-- @module Set
|
||||
-- @author FlightControl
|
||||
|
||||
@@ -70,22 +115,22 @@ Include.File( "Unit" )
|
||||
Include.File( "Event" )
|
||||
Include.File( "Client" )
|
||||
|
||||
--- SET class
|
||||
-- @type SET
|
||||
--- SET_BASE class
|
||||
-- @type SET_BASE
|
||||
-- @extends Base#BASE
|
||||
SET = {
|
||||
ClassName = "SET",
|
||||
SET_BASE = {
|
||||
ClassName = "SET_BASE",
|
||||
Set = {},
|
||||
Database = {},
|
||||
}
|
||||
|
||||
--- Creates a new SET object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
|
||||
-- @param #SET self
|
||||
-- @return #SET
|
||||
--- Creates a new SET_BASE object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
|
||||
-- @param #SET_BASE self
|
||||
-- @return #SET_BASE
|
||||
-- @usage
|
||||
-- -- Define a new SET Object. This DBObject will contain a reference to all Group and Unit Templates defined within the ME and the DCSRTE.
|
||||
-- DBObject = SET:New()
|
||||
function SET:New( Database )
|
||||
-- -- Define a new SET_BASE Object. This DBObject will contain a reference to all Group and Unit Templates defined within the ME and the DCSRTE.
|
||||
-- DBObject = SET_BASE:New()
|
||||
function SET_BASE:New( Database )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
@@ -96,29 +141,29 @@ function SET:New( Database )
|
||||
end
|
||||
|
||||
--- Finds an Object based on the Object Name.
|
||||
-- @param #SET self
|
||||
-- @param #SET_BASE self
|
||||
-- @param #string ObjectName
|
||||
-- @return #table The Object found.
|
||||
function SET:_Find( ObjectName )
|
||||
function SET_BASE:_Find( ObjectName )
|
||||
|
||||
local ObjectFound = self.Set[ObjectName]
|
||||
return ObjectFound
|
||||
end
|
||||
|
||||
--- Adds a Object based on the Object Name.
|
||||
-- @param #SET self
|
||||
-- @param #SET_BASE self
|
||||
-- @param #string ObjectName
|
||||
-- @param #table Object
|
||||
-- @return #table The added Object.
|
||||
function SET:_Add( ObjectName, Object )
|
||||
function SET_BASE:_Add( ObjectName, Object )
|
||||
|
||||
self.Set[ObjectName] = Object
|
||||
end
|
||||
|
||||
--- Starts the filtering for the defined collection.
|
||||
-- @param #SET self
|
||||
-- @return #SET self
|
||||
function SET:_FilterStart()
|
||||
-- @param #SET_BASE self
|
||||
-- @return #SET_BASE self
|
||||
function SET_BASE:_FilterStart()
|
||||
|
||||
for ObjectName, Object in pairs( self.Database ) do
|
||||
|
||||
@@ -143,9 +188,9 @@ end
|
||||
|
||||
|
||||
----- Private method that registers all alive players in the mission.
|
||||
---- @param #SET self
|
||||
---- @return #SET self
|
||||
--function SET:_RegisterPlayers()
|
||||
---- @param #SET_BASE self
|
||||
---- @return #SET_BASE self
|
||||
--function SET_BASE:_RegisterPlayers()
|
||||
--
|
||||
-- local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) }
|
||||
-- for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
|
||||
@@ -167,9 +212,9 @@ end
|
||||
--- Events
|
||||
|
||||
--- Handles the OnBirth event for the Set.
|
||||
-- @param #SET self
|
||||
-- @param #SET_BASE self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function SET:_EventOnBirth( Event )
|
||||
function SET_BASE:_EventOnBirth( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
@@ -183,9 +228,9 @@ function SET:_EventOnBirth( Event )
|
||||
end
|
||||
|
||||
--- Handles the OnDead or OnCrash event for alive units set.
|
||||
-- @param #SET self
|
||||
-- @param #SET_BASE self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function SET:_EventOnDeadOrCrash( Event )
|
||||
function SET_BASE:_EventOnDeadOrCrash( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
@@ -197,9 +242,9 @@ function SET:_EventOnDeadOrCrash( Event )
|
||||
end
|
||||
|
||||
----- Handles the OnPlayerEnterUnit event to fill the active players table (with the unit filter applied).
|
||||
---- @param #SET self
|
||||
---- @param #SET_BASE self
|
||||
---- @param Event#EVENTDATA Event
|
||||
--function SET:_EventOnPlayerEnterUnit( Event )
|
||||
--function SET_BASE:_EventOnPlayerEnterUnit( Event )
|
||||
-- self:F3( { Event } )
|
||||
--
|
||||
-- if Event.IniDCSUnit then
|
||||
@@ -214,9 +259,9 @@ end
|
||||
--end
|
||||
--
|
||||
----- Handles the OnPlayerLeaveUnit event to clean the active players table.
|
||||
---- @param #SET self
|
||||
---- @param #SET_BASE self
|
||||
---- @param Event#EVENTDATA Event
|
||||
--function SET:_EventOnPlayerLeaveUnit( Event )
|
||||
--function SET_BASE:_EventOnPlayerLeaveUnit( Event )
|
||||
-- self:F3( { Event } )
|
||||
--
|
||||
-- if Event.IniDCSUnit then
|
||||
@@ -232,11 +277,11 @@ end
|
||||
|
||||
--- Iterators
|
||||
|
||||
--- Interate the SET and call an interator function for the given set, providing the Object for each element within the set and optional parameters.
|
||||
-- @param #SET self
|
||||
-- @param #function IteratorFunction The function that will be called when there is an alive player in the SET.
|
||||
-- @return #SET self
|
||||
function SET:ForEach( IteratorFunction, arg, Set )
|
||||
--- Interate the SET_BASE and call an interator function for the given set, providing the Object for each element within the set and optional parameters.
|
||||
-- @param #SET_BASE self
|
||||
-- @param #function IteratorFunction The function that will be called when there is an alive player in the SET_BASE.
|
||||
-- @return #SET_BASE self
|
||||
function SET_BASE:ForEach( IteratorFunction, arg, Set )
|
||||
self:F3( arg )
|
||||
|
||||
local function CoRoutine()
|
||||
@@ -269,17 +314,17 @@ function SET:ForEach( IteratorFunction, arg, Set )
|
||||
return false
|
||||
end
|
||||
|
||||
local Scheduler = SCHEDULER:New( self, Schedule, {}, 0.001, 0.001, 0 )
|
||||
local Scheduler = SCHEDULER:New( self, Schedule, {}, 0.001, 30, 0 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
----- Interate the SET and call an interator function for each **alive** unit, providing the Unit and optional parameters.
|
||||
---- @param #SET self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive unit in the SET. The function needs to accept a UNIT parameter.
|
||||
---- @return #SET self
|
||||
--function SET:ForEachDCSUnitAlive( IteratorFunction, ... )
|
||||
----- Interate the SET_BASE and call an interator function for each **alive** unit, providing the Unit and optional parameters.
|
||||
---- @param #SET_BASE self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive unit in the SET_BASE. The function needs to accept a UNIT parameter.
|
||||
---- @return #SET_BASE self
|
||||
--function SET_BASE:ForEachDCSUnitAlive( IteratorFunction, ... )
|
||||
-- self:F3( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.DCSUnitsAlive )
|
||||
@@ -287,11 +332,11 @@ end
|
||||
-- return self
|
||||
--end
|
||||
--
|
||||
----- Interate the SET and call an interator function for each **alive** player, providing the Unit of the player and optional parameters.
|
||||
---- @param #SET self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the SET. The function needs to accept a UNIT parameter.
|
||||
---- @return #SET self
|
||||
--function SET:ForEachPlayer( IteratorFunction, ... )
|
||||
----- Interate the SET_BASE and call an interator function for each **alive** player, providing the Unit of the player and optional parameters.
|
||||
---- @param #SET_BASE self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the SET_BASE. The function needs to accept a UNIT parameter.
|
||||
---- @return #SET_BASE self
|
||||
--function SET_BASE:ForEachPlayer( IteratorFunction, ... )
|
||||
-- self:F3( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.PlayersAlive )
|
||||
@@ -300,11 +345,11 @@ end
|
||||
--end
|
||||
--
|
||||
--
|
||||
----- Interate the SET and call an interator function for each client, providing the Client to the function and optional parameters.
|
||||
---- @param #SET self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the SET. The function needs to accept a CLIENT parameter.
|
||||
---- @return #SET self
|
||||
--function SET:ForEachClient( IteratorFunction, ... )
|
||||
----- Interate the SET_BASE and call an interator function for each client, providing the Client to the function and optional parameters.
|
||||
---- @param #SET_BASE self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the SET_BASE. The function needs to accept a CLIENT parameter.
|
||||
---- @return #SET_BASE self
|
||||
--function SET_BASE:ForEachClient( IteratorFunction, ... )
|
||||
-- self:F3( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.Clients )
|
||||
@@ -314,19 +359,19 @@ end
|
||||
|
||||
|
||||
--- Decides whether to include the Object
|
||||
-- @param #SET self
|
||||
-- @param #SET_BASE self
|
||||
-- @param #table Object
|
||||
-- @return #SET self
|
||||
function SET:IsIncludeObject( Object )
|
||||
-- @return #SET_BASE self
|
||||
function SET_BASE:IsIncludeObject( Object )
|
||||
self:F3( Object )
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Flushes the current SET contents in the log ... (for debug reasons).
|
||||
-- @param #SET self
|
||||
--- Flushes the current SET_BASE contents in the log ... (for debug reasons).
|
||||
-- @param #SET_BASE self
|
||||
-- @return #string A string with the names of the objects.
|
||||
function SET:Flush()
|
||||
function SET_BASE:Flush()
|
||||
self:F3()
|
||||
|
||||
local ObjectNames = ""
|
||||
@@ -338,4 +383,572 @@ function SET:Flush()
|
||||
return ObjectNames
|
||||
end
|
||||
|
||||
-- SET_GROUP
|
||||
|
||||
--- SET_GROUP class
|
||||
-- @type SET_GROUP
|
||||
-- @extends Set#SET_BASE
|
||||
SET_GROUP = {
|
||||
ClassName = "SET_GROUP",
|
||||
Filter = {
|
||||
Coalitions = nil,
|
||||
Categories = nil,
|
||||
Countries = nil,
|
||||
GroupPrefixes = nil,
|
||||
},
|
||||
FilterMeta = {
|
||||
Coalitions = {
|
||||
red = coalition.side.RED,
|
||||
blue = coalition.side.BLUE,
|
||||
neutral = coalition.side.NEUTRAL,
|
||||
},
|
||||
Categories = {
|
||||
plane = Group.Category.AIRPLANE,
|
||||
helicopter = Group.Category.HELICOPTER,
|
||||
ground = Group.Category.GROUND_UNIT,
|
||||
ship = Group.Category.SHIP,
|
||||
structure = Group.Category.STRUCTURE,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
--- Creates a new SET_GROUP object, building a set of groups belonging to a coalitions, categories, countries, types or with defined prefix names.
|
||||
-- @param #SET_GROUP self
|
||||
-- @return #SET_GROUP
|
||||
-- @usage
|
||||
-- -- Define a new SET_GROUP Object. This DBObject will contain a reference to all alive GROUPS.
|
||||
-- DBObject = SET_GROUP:New()
|
||||
function SET_GROUP:New()
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, SET_BASE:New( _DATABASE.GROUPS ) )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Finds a Group based on the Group Name.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param #string GroupName
|
||||
-- @return Group#GROUP The found Group.
|
||||
function SET_GROUP:FindGroup( GroupName )
|
||||
|
||||
local GroupFound = self.Set[GroupName]
|
||||
return GroupFound
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Builds a set of groups of coalitions.
|
||||
-- Possible current coalitions are red, blue and neutral.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral".
|
||||
-- @return #SET_GROUP self
|
||||
function SET_GROUP: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 groups out of categories.
|
||||
-- Possible current categories are plane, helicopter, ground, ship.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param #string Categories Can take the following values: "plane", "helicopter", "ground", "ship".
|
||||
-- @return #SET_GROUP self
|
||||
function SET_GROUP: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 groups of defined countries.
|
||||
-- Possible current countries are those known within DCS world.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param #string Countries Can take those country strings known within DCS world.
|
||||
-- @return #SET_GROUP self
|
||||
function SET_GROUP: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 groups of defined GROUP prefixes.
|
||||
-- All the groups starting with the given prefixes will be included within the set.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param #string Prefixes The prefix of which the group name starts with.
|
||||
-- @return #SET_GROUP self
|
||||
function SET_GROUP:FilterPrefixes( Prefixes )
|
||||
if not self.Filter.GroupPrefixes then
|
||||
self.Filter.GroupPrefixes = {}
|
||||
end
|
||||
if type( Prefixes ) ~= "table" then
|
||||
Prefixes = { Prefixes }
|
||||
end
|
||||
for PrefixID, Prefix in pairs( Prefixes ) do
|
||||
self.Filter.GroupPrefixes[Prefix] = Prefix
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Starts the filtering.
|
||||
-- @param #SET_GROUP self
|
||||
-- @return #SET_GROUP self
|
||||
function SET_GROUP: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_GROUP self
|
||||
-- @param Event#EVENTDATA Event
|
||||
-- @return #string The name of the GROUP
|
||||
-- @return #table The GROUP
|
||||
function SET_GROUP:AddInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
if not self.Database[Event.IniDCSGroupName] then
|
||||
self.Database[Event.IniDCSGroupName] = GROUP:Register( Event.IniDCSGroupName )
|
||||
self:T3( self.Database[Event.IniDCSGroupName] )
|
||||
end
|
||||
|
||||
return Event.IniDCSGroupName, self.Database[Event.IniDCSGroupName]
|
||||
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_GROUP self
|
||||
-- @param Event#EVENTDATA Event
|
||||
-- @return #string The name of the GROUP
|
||||
-- @return #table The GROUP
|
||||
function SET_GROUP:FindInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
return Event.IniDCSGroupName, self.Database[Event.IniDCSGroupName]
|
||||
end
|
||||
|
||||
--- Interate the SET_GROUP and call an interator function for each **alive** GROUP, providing the GROUP and optional parameters.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param #function IteratorFunction The function that will be called when there is an alive GROUP in the SET_GROUP. The function needs to accept a GROUP parameter.
|
||||
-- @return #SET_GROUP self
|
||||
function SET_GROUP:ForEachGroup( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self.Set )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
----- Interate 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
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the SET_GROUP. The function needs to accept a GROUP parameter.
|
||||
---- @return #SET_GROUP self
|
||||
--function SET_GROUP:ForEachPlayer( IteratorFunction, ... )
|
||||
-- self:F2( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.PlayersAlive )
|
||||
--
|
||||
-- return self
|
||||
--end
|
||||
--
|
||||
--
|
||||
----- Interate the SET_GROUP and call an interator function for each client, providing the Client to the function and optional parameters.
|
||||
---- @param #SET_GROUP self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the SET_GROUP. The function needs to accept a CLIENT parameter.
|
||||
---- @return #SET_GROUP self
|
||||
--function SET_GROUP:ForEachClient( IteratorFunction, ... )
|
||||
-- self:F2( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.Clients )
|
||||
--
|
||||
-- return self
|
||||
--end
|
||||
|
||||
|
||||
---
|
||||
-- @param #SET_GROUP self
|
||||
-- @param Group#GROUP MooseGroup
|
||||
-- @return #SET_GROUP self
|
||||
function SET_GROUP:IsIncludeObject( MooseGroup )
|
||||
self:F2( MooseGroup )
|
||||
local MooseGroupInclude = true
|
||||
|
||||
if self.Filter.Coalitions then
|
||||
local MooseGroupCoalition = false
|
||||
for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do
|
||||
self:T3( { "Coalition:", MooseGroup:GetCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } )
|
||||
if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == MooseGroup:GetCoalition() then
|
||||
MooseGroupCoalition = true
|
||||
end
|
||||
end
|
||||
MooseGroupInclude = MooseGroupInclude and MooseGroupCoalition
|
||||
end
|
||||
|
||||
if self.Filter.Categories then
|
||||
local MooseGroupCategory = false
|
||||
for CategoryID, CategoryName in pairs( self.Filter.Categories ) do
|
||||
self:T3( { "Category:", MooseGroup:GetCategory(), self.FilterMeta.Categories[CategoryName], CategoryName } )
|
||||
if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == MooseGroup:GetCategory() then
|
||||
MooseGroupCategory = true
|
||||
end
|
||||
end
|
||||
MooseGroupInclude = MooseGroupInclude and MooseGroupCategory
|
||||
end
|
||||
|
||||
if self.Filter.Countries then
|
||||
local MooseGroupCountry = false
|
||||
for CountryID, CountryName in pairs( self.Filter.Countries ) do
|
||||
self:T3( { "Country:", MooseGroup:GetCountry(), CountryName } )
|
||||
if country.id[CountryName] == MooseGroup:GetCountry() then
|
||||
MooseGroupCountry = true
|
||||
end
|
||||
end
|
||||
MooseGroupInclude = MooseGroupInclude and MooseGroupCountry
|
||||
end
|
||||
|
||||
if self.Filter.GroupPrefixes then
|
||||
local MooseGroupPrefix = false
|
||||
for GroupPrefixId, GroupPrefix in pairs( self.Filter.GroupPrefixes ) do
|
||||
self:T3( { "Prefix:", string.find( MooseGroup:GetName(), GroupPrefix, 1 ), GroupPrefix } )
|
||||
if string.find( MooseGroup:GetName(), GroupPrefix, 1 ) then
|
||||
MooseGroupPrefix = true
|
||||
end
|
||||
end
|
||||
MooseGroupInclude = MooseGroupInclude and MooseGroupPrefix
|
||||
end
|
||||
|
||||
self:T2( MooseGroupInclude )
|
||||
return MooseGroupInclude
|
||||
end
|
||||
|
||||
--- SET_UNIT class
|
||||
-- @type SET_UNIT
|
||||
-- @extends Set#SET_BASE
|
||||
SET_UNIT = {
|
||||
ClassName = "SET_UNIT",
|
||||
Units = {},
|
||||
Filter = {
|
||||
Coalitions = nil,
|
||||
Categories = nil,
|
||||
Types = nil,
|
||||
Countries = nil,
|
||||
UnitPrefixes = 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_UNIT,
|
||||
ship = Unit.Category.SHIP,
|
||||
structure = Unit.Category.STRUCTURE,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
--- Creates a new SET_UNIT object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
|
||||
-- @param #SET_UNIT self
|
||||
-- @return #SET_UNIT
|
||||
-- @usage
|
||||
-- -- Define a new SET_UNIT Object. This DBObject will contain a reference to all alive Units.
|
||||
-- DBObject = SET_UNIT:New()
|
||||
function SET_UNIT:New()
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, SET_BASE:New( _DATABASE.UNITS ) )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Finds a Unit based on the Unit Name.
|
||||
-- @param #SET_UNIT self
|
||||
-- @param #string UnitName
|
||||
-- @return Unit#UNIT The found Unit.
|
||||
function SET_UNIT:FindUnit( UnitName )
|
||||
|
||||
local UnitFound = self.Set[UnitName]
|
||||
return UnitFound
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Builds a set of units of coalitions.
|
||||
-- Possible current coalitions are red, blue and neutral.
|
||||
-- @param #SET_UNIT self
|
||||
-- @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
|
||||
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_UNIT self
|
||||
-- @param #string Categories Can take the following values: "plane", "helicopter", "ground", "ship".
|
||||
-- @return #SET_UNIT self
|
||||
function SET_UNIT: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_UNIT self
|
||||
-- @param #string Types Can take those type strings known within DCS world.
|
||||
-- @return #SET_UNIT self
|
||||
function SET_UNIT: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_UNIT self
|
||||
-- @param #string Countries Can take those country strings known within DCS world.
|
||||
-- @return #SET_UNIT self
|
||||
function SET_UNIT: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_UNIT self
|
||||
-- @param #string Prefixes The prefix of which the unit name starts with.
|
||||
-- @return #SET_UNIT self
|
||||
function SET_UNIT:FilterPrefixes( Prefixes )
|
||||
if not self.Filter.UnitPrefixes then
|
||||
self.Filter.UnitPrefixes = {}
|
||||
end
|
||||
if type( Prefixes ) ~= "table" then
|
||||
Prefixes = { Prefixes }
|
||||
end
|
||||
for PrefixID, Prefix in pairs( Prefixes ) do
|
||||
self.Filter.UnitPrefixes[Prefix] = Prefix
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Starts the filtering.
|
||||
-- @param #SET_UNIT self
|
||||
-- @return #SET_UNIT self
|
||||
function SET_UNIT: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_UNIT self
|
||||
-- @param Event#EVENTDATA Event
|
||||
-- @return #string The name of the UNIT
|
||||
-- @return #table The UNIT
|
||||
function SET_UNIT:AddInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
if not self.Database[Event.IniDCSUnitName] then
|
||||
self.Database[Event.IniDCSUnitName] = UNIT:Register( Event.IniDCSUnitName )
|
||||
self:T3( self.Database[Event.IniDCSUnitName] )
|
||||
end
|
||||
|
||||
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
|
||||
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_UNIT self
|
||||
-- @param Event#EVENTDATA Event
|
||||
-- @return #string The name of the UNIT
|
||||
-- @return #table The UNIT
|
||||
function SET_UNIT:FindInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
|
||||
end
|
||||
|
||||
--- Interate 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.
|
||||
-- @return #SET_UNIT self
|
||||
function SET_UNIT:ForEachUnit( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self.Set )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
----- Interate the SET_UNIT and call an interator function for each **alive** player, providing the Unit of the player and optional parameters.
|
||||
---- @param #SET_UNIT self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the SET_UNIT. The function needs to accept a UNIT parameter.
|
||||
---- @return #SET_UNIT self
|
||||
--function SET_UNIT:ForEachPlayer( IteratorFunction, ... )
|
||||
-- self:F2( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.PlayersAlive )
|
||||
--
|
||||
-- return self
|
||||
--end
|
||||
--
|
||||
--
|
||||
----- Interate the SET_UNIT and call an interator function for each client, providing the Client to the function and optional parameters.
|
||||
---- @param #SET_UNIT self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the SET_UNIT. The function needs to accept a CLIENT parameter.
|
||||
---- @return #SET_UNIT self
|
||||
--function SET_UNIT:ForEachClient( IteratorFunction, ... )
|
||||
-- self:F2( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.Clients )
|
||||
--
|
||||
-- return self
|
||||
--end
|
||||
|
||||
|
||||
---
|
||||
-- @param #SET_UNIT self
|
||||
-- @param Unit#UNIT MUnit
|
||||
-- @return #SET_UNIT self
|
||||
function SET_UNIT:IsIncludeObject( MUnit )
|
||||
self:F2( MUnit )
|
||||
local MUnitInclude = true
|
||||
|
||||
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 } )
|
||||
if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == MUnit:GetCoalition() then
|
||||
MUnitCoalition = true
|
||||
end
|
||||
end
|
||||
MUnitInclude = MUnitInclude and MUnitCoalition
|
||||
end
|
||||
|
||||
if self.Filter.Categories then
|
||||
local MUnitCategory = false
|
||||
for CategoryID, CategoryName in pairs( self.Filter.Categories ) do
|
||||
self:T3( { "Category:", MUnit:GetDesc().category, self.FilterMeta.Categories[CategoryName], CategoryName } )
|
||||
if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == MUnit:GetDesc().category then
|
||||
MUnitCategory = true
|
||||
end
|
||||
end
|
||||
MUnitInclude = MUnitInclude and MUnitCategory
|
||||
end
|
||||
|
||||
if self.Filter.Types then
|
||||
local MUnitType = false
|
||||
for TypeID, TypeName in pairs( self.Filter.Types ) do
|
||||
self:T3( { "Type:", MUnit:GetTypeName(), TypeName } )
|
||||
if TypeName == MUnit:GetTypeName() then
|
||||
MUnitType = true
|
||||
end
|
||||
end
|
||||
MUnitInclude = MUnitInclude and MUnitType
|
||||
end
|
||||
|
||||
if self.Filter.Countries then
|
||||
local MUnitCountry = false
|
||||
for CountryID, CountryName in pairs( self.Filter.Countries ) do
|
||||
self:T3( { "Country:", MUnit:GetCountry(), CountryName } )
|
||||
if country.id[CountryName] == MUnit:GetCountry() then
|
||||
MUnitCountry = true
|
||||
end
|
||||
end
|
||||
MUnitInclude = MUnitInclude and MUnitCountry
|
||||
end
|
||||
|
||||
if self.Filter.UnitPrefixes then
|
||||
local MUnitPrefix = false
|
||||
for UnitPrefixId, UnitPrefix in pairs( self.Filter.UnitPrefixes ) do
|
||||
self:T3( { "Prefix:", string.find( MUnit:GetName(), UnitPrefix, 1 ), UnitPrefix } )
|
||||
if string.find( MUnit:GetName(), UnitPrefix, 1 ) then
|
||||
MUnitPrefix = true
|
||||
end
|
||||
end
|
||||
MUnitInclude = MUnitInclude and MUnitPrefix
|
||||
end
|
||||
|
||||
self:T2( MUnitInclude )
|
||||
return MUnitInclude
|
||||
end
|
||||
|
||||
|
||||
@@ -473,12 +473,6 @@ function SPAWN:SpawnWithIndex( SpawnIndex )
|
||||
end
|
||||
|
||||
self.SpawnGroups[self.SpawnIndex].Spawned = true
|
||||
|
||||
local SpawnGroup = self.SpawnGroups[self.SpawnIndex].Group -- Group#GROUP
|
||||
local Route = SpawnGroup:GetTaskRoute()
|
||||
SpawnGroup:Route(Route)
|
||||
|
||||
|
||||
return self.SpawnGroups[self.SpawnIndex].Group
|
||||
else
|
||||
--self:E( { self.SpawnTemplatePrefix, "No more Groups to Spawn:", SpawnIndex, self.SpawnMaxGroups } )
|
||||
|
||||
@@ -1,363 +0,0 @@
|
||||
--- Create and manage a set of units.
|
||||
--
|
||||
-- @{#UNITSET} class
|
||||
-- ==================
|
||||
-- Mission designers can use the UNITSET class to build sets of units belonging to certain:
|
||||
--
|
||||
-- * Coalitions
|
||||
-- * Categories
|
||||
-- * Countries
|
||||
-- * Unit types
|
||||
-- * Starting with certain prefix strings.
|
||||
--
|
||||
-- UNITSET construction methods:
|
||||
-- =================================
|
||||
-- Create a new UNITSET object with the @{#UNITSET.New} method:
|
||||
--
|
||||
-- * @{#UNITSET.New}: Creates a new UNITSET object.
|
||||
--
|
||||
--
|
||||
-- UNITSET filter criteria:
|
||||
-- =========================
|
||||
-- You can set filter criteria to define the set of units within the UNITSET.
|
||||
-- Filter criteria are defined by:
|
||||
--
|
||||
-- * @{#UNITSET.FilterCoalitions}: Builds the UNITSET with the units belonging to the coalition(s).
|
||||
-- * @{#UNITSET.FilterCategories}: Builds the UNITSET with the units belonging to the category(ies).
|
||||
-- * @{#UNITSET.FilterTypes}: Builds the UNITSET with the units belonging to the unit type(s).
|
||||
-- * @{#UNITSET.FilterCountries}: Builds the UNITSET with the units belonging to the country(ies).
|
||||
-- * @{#UNITSET.FilterPrefixes}: Builds the UNITSET with the units starting with the same prefix string(s).
|
||||
--
|
||||
-- Once the filter criteria have been set for the UNITSET, you can start filtering using:
|
||||
--
|
||||
-- * @{#UNITSET.FilterStart}: Starts the filtering of the units within the UNITSET.
|
||||
--
|
||||
-- Planned filter criteria within development are (so these are not yet available):
|
||||
--
|
||||
-- * @{#UNITSET.FilterZones}: Builds the UNITSET with the units within a @{Zone#ZONE}.
|
||||
--
|
||||
--
|
||||
-- UNITSET iterators:
|
||||
-- ===================
|
||||
-- Once the filters have been defined and the UNITSET has been built, you can iterate the UNITSET with the available iterator methods.
|
||||
-- The iterator methods will walk the UNITSET set, and call for each element within the set a function that you provide.
|
||||
-- The following iterator methods are currently available within the UNITSET:
|
||||
--
|
||||
-- * @{#UNITSET.ForEachUnit}: Calls a function for each alive unit it finds within the UNITSET.
|
||||
--
|
||||
-- Planned iterators methods in development are (so these are not yet available):
|
||||
--
|
||||
-- * @{#UNITSET.ForEachUnitInGroup}: Calls a function for each group contained within the UNITSET.
|
||||
-- * @{#UNITSET.ForEachUnitInZone}: Calls a function for each unit within a certain zone contained within the UNITSET.
|
||||
--
|
||||
-- @module UnitSet
|
||||
-- @author FlightControl
|
||||
|
||||
Include.File( "Routines" )
|
||||
Include.File( "Base" )
|
||||
Include.File( "Unit" )
|
||||
Include.File( "Set" )
|
||||
|
||||
|
||||
--- UNITSET class
|
||||
-- @type UNITSET
|
||||
-- @extends Set#SET
|
||||
UNITSET = {
|
||||
ClassName = "UNITSET",
|
||||
Units = {},
|
||||
Filter = {
|
||||
Coalitions = nil,
|
||||
Categories = nil,
|
||||
Types = nil,
|
||||
Countries = nil,
|
||||
UnitPrefixes = 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_UNIT,
|
||||
ship = Unit.Category.SHIP,
|
||||
structure = Unit.Category.STRUCTURE,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
--- Creates a new UNITSET object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
|
||||
-- @param #UNITSET self
|
||||
-- @return #UNITSET
|
||||
-- @usage
|
||||
-- -- Define a new UNITSET Object. This DBObject will contain a reference to all alive Units.
|
||||
-- DBObject = UNITSET:New()
|
||||
function UNITSET:New()
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, SET:New( _DATABASE.UNITS ) )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Finds a Unit based on the Unit Name.
|
||||
-- @param #UNITSET self
|
||||
-- @param #string UnitName
|
||||
-- @return Unit#UNIT The found Unit.
|
||||
function UNITSET:FindUnit( UnitName )
|
||||
|
||||
local UnitFound = self.Set[UnitName]
|
||||
return UnitFound
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Builds a set of units of coalitions.
|
||||
-- Possible current coalitions are red, blue and neutral.
|
||||
-- @param #UNITSET self
|
||||
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral".
|
||||
-- @return #UNITSET self
|
||||
function UNITSET: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 #UNITSET self
|
||||
-- @param #string Categories Can take the following values: "plane", "helicopter", "ground", "ship".
|
||||
-- @return #UNITSET self
|
||||
function UNITSET: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 #UNITSET self
|
||||
-- @param #string Types Can take those type strings known within DCS world.
|
||||
-- @return #UNITSET self
|
||||
function UNITSET: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 #UNITSET self
|
||||
-- @param #string Countries Can take those country strings known within DCS world.
|
||||
-- @return #UNITSET self
|
||||
function UNITSET: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 #UNITSET self
|
||||
-- @param #string Prefixes The prefix of which the unit name starts with.
|
||||
-- @return #UNITSET self
|
||||
function UNITSET:FilterPrefixes( Prefixes )
|
||||
if not self.Filter.UnitPrefixes then
|
||||
self.Filter.UnitPrefixes = {}
|
||||
end
|
||||
if type( Prefixes ) ~= "table" then
|
||||
Prefixes = { Prefixes }
|
||||
end
|
||||
for PrefixID, Prefix in pairs( Prefixes ) do
|
||||
self.Filter.UnitPrefixes[Prefix] = Prefix
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Starts the filtering.
|
||||
-- @param #UNITSET self
|
||||
-- @return #UNITSET self
|
||||
function UNITSET: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 birth event!
|
||||
-- @param #UNITSET self
|
||||
-- @param Event#EVENTDATA Event
|
||||
-- @return #string The name of the UNIT
|
||||
-- @return #table The UNIT
|
||||
function UNITSET:AddInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
if not self.Database[Event.IniDCSUnitName] then
|
||||
self.Database[Event.IniDCSUnitName] = UNIT:Register( Event.IniDCSUnitName )
|
||||
self:T3( self.Database[Event.IniDCSUnitName] )
|
||||
end
|
||||
|
||||
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
|
||||
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 event or vise versa!
|
||||
-- @param #UNITSET self
|
||||
-- @param Event#EVENTDATA Event
|
||||
-- @return #string The name of the UNIT
|
||||
-- @return #table The UNIT
|
||||
function UNITSET:FindInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
|
||||
end
|
||||
|
||||
--- Interate the UNITSET and call an interator function for each **alive** UNIT, providing the UNIT and optional parameters.
|
||||
-- @param #UNITSET self
|
||||
-- @param #function IteratorFunction The function that will be called when there is an alive UNIT in the UNITSET. The function needs to accept a UNIT parameter.
|
||||
-- @return #UNITSET self
|
||||
function UNITSET:ForEachUnit( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self.Set )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
----- Interate the UNITSET and call an interator function for each **alive** player, providing the Unit of the player and optional parameters.
|
||||
---- @param #UNITSET self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the UNITSET. The function needs to accept a UNIT parameter.
|
||||
---- @return #UNITSET self
|
||||
--function UNITSET:ForEachPlayer( IteratorFunction, ... )
|
||||
-- self:F2( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.PlayersAlive )
|
||||
--
|
||||
-- return self
|
||||
--end
|
||||
--
|
||||
--
|
||||
----- Interate the UNITSET and call an interator function for each client, providing the Client to the function and optional parameters.
|
||||
---- @param #UNITSET self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the UNITSET. The function needs to accept a CLIENT parameter.
|
||||
---- @return #UNITSET self
|
||||
--function UNITSET:ForEachClient( IteratorFunction, ... )
|
||||
-- self:F2( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.Clients )
|
||||
--
|
||||
-- return self
|
||||
--end
|
||||
|
||||
|
||||
---
|
||||
-- @param #UNITSET self
|
||||
-- @param Unit#UNIT MUnit
|
||||
-- @return #UNITSET self
|
||||
function UNITSET:IsIncludeObject( MUnit )
|
||||
self:F2( MUnit )
|
||||
local MUnitInclude = true
|
||||
|
||||
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 } )
|
||||
if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == MUnit:GetCoalition() then
|
||||
MUnitCoalition = true
|
||||
end
|
||||
end
|
||||
MUnitInclude = MUnitInclude and MUnitCoalition
|
||||
end
|
||||
|
||||
if self.Filter.Categories then
|
||||
local MUnitCategory = false
|
||||
for CategoryID, CategoryName in pairs( self.Filter.Categories ) do
|
||||
self:T3( { "Category:", MUnit:GetDesc().category, self.FilterMeta.Categories[CategoryName], CategoryName } )
|
||||
if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == MUnit:GetDesc().category then
|
||||
MUnitCategory = true
|
||||
end
|
||||
end
|
||||
MUnitInclude = MUnitInclude and MUnitCategory
|
||||
end
|
||||
|
||||
if self.Filter.Types then
|
||||
local MUnitType = false
|
||||
for TypeID, TypeName in pairs( self.Filter.Types ) do
|
||||
self:T3( { "Type:", MUnit:GetTypeName(), TypeName } )
|
||||
if TypeName == MUnit:GetTypeName() then
|
||||
MUnitType = true
|
||||
end
|
||||
end
|
||||
MUnitInclude = MUnitInclude and MUnitType
|
||||
end
|
||||
|
||||
if self.Filter.Countries then
|
||||
local MUnitCountry = false
|
||||
for CountryID, CountryName in pairs( self.Filter.Countries ) do
|
||||
self:T3( { "Country:", MUnit:GetCountry(), CountryName } )
|
||||
if country.id[CountryName] == MUnit:GetCountry() then
|
||||
MUnitCountry = true
|
||||
end
|
||||
end
|
||||
MUnitInclude = MUnitInclude and MUnitCountry
|
||||
end
|
||||
|
||||
if self.Filter.UnitPrefixes then
|
||||
local MUnitPrefix = false
|
||||
for UnitPrefixId, UnitPrefix in pairs( self.Filter.UnitPrefixes ) do
|
||||
self:T3( { "Prefix:", string.find( MUnit:GetName(), UnitPrefix, 1 ), UnitPrefix } )
|
||||
if string.find( MUnit:GetName(), UnitPrefix, 1 ) then
|
||||
MUnitPrefix = true
|
||||
end
|
||||
end
|
||||
MUnitInclude = MUnitInclude and MUnitPrefix
|
||||
end
|
||||
|
||||
self:T2( MUnitInclude )
|
||||
return MUnitInclude
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user