GROUPSET and UNITSET are working now !!

- GROUPSET and UNITSET inherit SET
- DATABASE optimized
- Tracing levels tuned.
This commit is contained in:
FlightControl 2016-05-27 11:32:49 +02:00
parent dc662849d4
commit 645d074a7d
19 changed files with 634 additions and 33881 deletions

View File

@ -226,9 +226,9 @@ end
-- @param #table SpawnTemplate -- @param #table SpawnTemplate
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:Spawn( SpawnTemplate ) function DATABASE:Spawn( SpawnTemplate )
self:F( SpawnTemplate.name ) self:F2( SpawnTemplate.name )
self:T( { SpawnTemplate.SpawnCountryID, SpawnTemplate.SpawnCategoryID } ) self:T2( { SpawnTemplate.SpawnCountryID, SpawnTemplate.SpawnCategoryID } )
-- Copy the spawn variables of the template in temporary storage, nullify, and restore the spawn variables. -- Copy the spawn variables of the template in temporary storage, nullify, and restore the spawn variables.
local SpawnCoalitionID = SpawnTemplate.SpawnCoalitionID local SpawnCoalitionID = SpawnTemplate.SpawnCoalitionID
@ -240,7 +240,7 @@ function DATABASE:Spawn( SpawnTemplate )
SpawnTemplate.SpawnCountryID = nil SpawnTemplate.SpawnCountryID = nil
SpawnTemplate.SpawnCategoryID = nil SpawnTemplate.SpawnCategoryID = nil
self:_RegisterGroup( SpawnTemplate ) self:_RegisterTemplate( SpawnTemplate )
coalition.addGroup( SpawnCountryID, SpawnCategoryID, SpawnTemplate ) coalition.addGroup( SpawnCountryID, SpawnCategoryID, SpawnTemplate )
-- Restore -- Restore
@ -256,7 +256,7 @@ end
--- Set a status to a Group within the Database, this to check crossing events for example. --- Set a status to a Group within the Database, this to check crossing events for example.
function DATABASE:SetStatusGroup( GroupName, Status ) function DATABASE:SetStatusGroup( GroupName, Status )
self:F( Status ) self:F2( Status )
self.Templates.Groups[GroupName].Status = Status self.Templates.Groups[GroupName].Status = Status
end end
@ -264,7 +264,7 @@ end
--- Get a status to a Group within the Database, this to check crossing events for example. --- Get a status to a Group within the Database, this to check crossing events for example.
function DATABASE:GetStatusGroup( GroupName ) function DATABASE:GetStatusGroup( GroupName )
self:F( Status ) self:F2( Status )
if self.Templates.Groups[GroupName] then if self.Templates.Groups[GroupName] then
return self.Templates.Groups[GroupName].Status return self.Templates.Groups[GroupName].Status
@ -277,7 +277,7 @@ end
-- @param #DATABASE self -- @param #DATABASE self
-- @param #table GroupTemplate -- @param #table GroupTemplate
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:_RegisterGroup( GroupTemplate ) function DATABASE:_RegisterTemplate( GroupTemplate )
local GroupTemplateName = env.getValueDictByKey(GroupTemplate.name) local GroupTemplateName = env.getValueDictByKey(GroupTemplate.name)
@ -297,7 +297,7 @@ function DATABASE:_RegisterGroup( GroupTemplate )
self.Templates.Groups[GroupTemplateName].UnitCount = #GroupTemplate.units self.Templates.Groups[GroupTemplateName].UnitCount = #GroupTemplate.units
self.Templates.Groups[GroupTemplateName].Units = GroupTemplate.units self.Templates.Groups[GroupTemplateName].Units = GroupTemplate.units
self:T( { "Group", self.Templates.Groups[GroupTemplateName].GroupName, self.Templates.Groups[GroupTemplateName].UnitCount } ) self:T2( { "Group", self.Templates.Groups[GroupTemplateName].GroupName, self.Templates.Groups[GroupTemplateName].UnitCount } )
for unit_num, UnitTemplate in pairs( GroupTemplate.units ) do for unit_num, UnitTemplate in pairs( GroupTemplate.units ) do
@ -381,7 +381,7 @@ end
-- @param #DATABASE self -- @param #DATABASE self
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function DATABASE:_EventOnBirth( Event ) function DATABASE:_EventOnBirth( Event )
self:F( { Event } ) self:F2( { Event } )
if Event.IniDCSUnit then if Event.IniDCSUnit then
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
@ -396,7 +396,7 @@ end
-- @param #DATABASE self -- @param #DATABASE self
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function DATABASE:_EventOnDeadOrCrash( Event ) function DATABASE:_EventOnDeadOrCrash( Event )
self:F( { Event } ) self:F2( { Event } )
if Event.IniDCSUnit then if Event.IniDCSUnit then
if self.DCSUnits[Event.IniDCSUnitName] then if self.DCSUnits[Event.IniDCSUnitName] then
@ -410,7 +410,7 @@ end
-- @param #DATABASE self -- @param #DATABASE self
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function DATABASE:_EventOnPlayerEnterUnit( Event ) function DATABASE:_EventOnPlayerEnterUnit( Event )
self:F( { Event } ) self:F2( { Event } )
if Event.IniDCSUnit then if Event.IniDCSUnit then
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
@ -427,7 +427,7 @@ end
-- @param #DATABASE self -- @param #DATABASE self
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function DATABASE:_EventOnPlayerLeaveUnit( Event ) function DATABASE:_EventOnPlayerLeaveUnit( Event )
self:F( { Event } ) self:F2( { Event } )
if Event.IniDCSUnit then if Event.IniDCSUnit then
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
@ -447,7 +447,7 @@ end
-- @param #function IteratorFunction The function that will be called when there is an alive player in the database. -- @param #function IteratorFunction The function that will be called when there is an alive player in the database.
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:ForEach( IteratorFunction, arg, Set ) function DATABASE:ForEach( IteratorFunction, arg, Set )
self:F( arg ) self:F2( arg )
local function CoRoutine() local function CoRoutine()
local Count = 0 local Count = 0
@ -467,7 +467,7 @@ function DATABASE:ForEach( IteratorFunction, arg, Set )
local function Schedule() local function Schedule()
local status, res = coroutine.resume( co ) local status, res = coroutine.resume( co )
self:T( { status, res } ) self:T2( { status, res } )
if status == false then if status == false then
error( res ) error( res )
@ -490,7 +490,7 @@ end
-- @param #function IteratorFunction The function that will be called when there is an alive unit in the database. The function needs to accept a UNIT parameter. -- @param #function IteratorFunction The function that will be called when there is an alive unit in the database. The function needs to accept a UNIT parameter.
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:ForEachDCSUnit( IteratorFunction, ... ) function DATABASE:ForEachDCSUnit( IteratorFunction, ... )
self:F( arg ) self:F2( arg )
self:ForEach( IteratorFunction, arg, self.DCSUnits ) self:ForEach( IteratorFunction, arg, self.DCSUnits )
@ -502,7 +502,7 @@ end
-- @param #function IteratorFunction The function that will be called when there is an alive player in the database. The function needs to accept a UNIT parameter. -- @param #function IteratorFunction The function that will be called when there is an alive player in the database. The function needs to accept a UNIT parameter.
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:ForEachPlayer( IteratorFunction, ... ) function DATABASE:ForEachPlayer( IteratorFunction, ... )
self:F( arg ) self:F2( arg )
self:ForEach( IteratorFunction, arg, self.PlayersAlive ) self:ForEach( IteratorFunction, arg, self.PlayersAlive )
@ -515,7 +515,7 @@ end
-- @param #function IteratorFunction The function that will be called when there is an alive player in the database. The function needs to accept a CLIENT parameter. -- @param #function IteratorFunction The function that will be called when there is an alive player in the database. The function needs to accept a CLIENT parameter.
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:ForEachClient( IteratorFunction, ... ) function DATABASE:ForEachClient( IteratorFunction, ... )
self:F( arg ) self:F2( arg )
self:ForEach( IteratorFunction, arg, self.CLIENTS ) self:ForEach( IteratorFunction, arg, self.CLIENTS )
@ -524,7 +524,7 @@ end
function DATABASE:ScanEnvironment() function DATABASE:ScanEnvironment()
self:F() self:F2()
self.Navpoints = {} self.Navpoints = {}
self.UNITS = {} self.UNITS = {}
@ -574,7 +574,7 @@ function DATABASE:ScanEnvironment()
for group_num, GroupTemplate in pairs(obj_type_data.group) do for group_num, GroupTemplate in pairs(obj_type_data.group) do
if GroupTemplate and GroupTemplate.units and type(GroupTemplate.units) == 'table' then --making sure again- this is a valid group if GroupTemplate and GroupTemplate.units and type(GroupTemplate.units) == 'table' then --making sure again- this is a valid group
self:_RegisterGroup( GroupTemplate ) self:_RegisterTemplate( GroupTemplate )
end --if GroupTemplate and GroupTemplate.units then end --if GroupTemplate and GroupTemplate.units then
end --for group_num, GroupTemplate in pairs(obj_type_data.group) do end --for group_num, GroupTemplate in pairs(obj_type_data.group) do
end --if ((type(obj_type_data) == 'table') and obj_type_data.group and (type(obj_type_data.group) == 'table') and (#obj_type_data.group > 0)) then end --if ((type(obj_type_data) == 'table') and obj_type_data.group and (type(obj_type_data.group) == 'table') and (#obj_type_data.group > 0)) then
@ -598,13 +598,13 @@ end
-- @param DCSUnit#Unit DCSUnit -- @param DCSUnit#Unit DCSUnit
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:_IsIncludeDCSUnit( DCSUnit ) function DATABASE:_IsIncludeDCSUnit( DCSUnit )
self:F( DCSUnit ) self:F2( DCSUnit )
local DCSUnitInclude = true local DCSUnitInclude = true
if self.Filter.Coalitions then if self.Filter.Coalitions then
local DCSUnitCoalition = false local DCSUnitCoalition = false
for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do
self:T( { "Coalition:", DCSUnit:getCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } ) self:T2( { "Coalition:", DCSUnit:getCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } )
if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == DCSUnit:getCoalition() then if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == DCSUnit:getCoalition() then
DCSUnitCoalition = true DCSUnitCoalition = true
end end
@ -615,7 +615,7 @@ function DATABASE:_IsIncludeDCSUnit( DCSUnit )
if self.Filter.Categories then if self.Filter.Categories then
local DCSUnitCategory = false local DCSUnitCategory = false
for CategoryID, CategoryName in pairs( self.Filter.Categories ) do for CategoryID, CategoryName in pairs( self.Filter.Categories ) do
self:T( { "Category:", DCSUnit:getDesc().category, self.FilterMeta.Categories[CategoryName], CategoryName } ) self:T2( { "Category:", DCSUnit:getDesc().category, self.FilterMeta.Categories[CategoryName], CategoryName } )
if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == DCSUnit:getDesc().category then if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == DCSUnit:getDesc().category then
DCSUnitCategory = true DCSUnitCategory = true
end end
@ -626,7 +626,7 @@ function DATABASE:_IsIncludeDCSUnit( DCSUnit )
if self.Filter.Types then if self.Filter.Types then
local DCSUnitType = false local DCSUnitType = false
for TypeID, TypeName in pairs( self.Filter.Types ) do for TypeID, TypeName in pairs( self.Filter.Types ) do
self:T( { "Type:", DCSUnit:getTypeName(), TypeName } ) self:T2( { "Type:", DCSUnit:getTypeName(), TypeName } )
if TypeName == DCSUnit:getTypeName() then if TypeName == DCSUnit:getTypeName() then
DCSUnitType = true DCSUnitType = true
end end
@ -637,7 +637,7 @@ function DATABASE:_IsIncludeDCSUnit( DCSUnit )
if self.Filter.Countries then if self.Filter.Countries then
local DCSUnitCountry = false local DCSUnitCountry = false
for CountryID, CountryName in pairs( self.Filter.Countries ) do for CountryID, CountryName in pairs( self.Filter.Countries ) do
self:T( { "Country:", DCSUnit:getCountry(), CountryName } ) self:T2( { "Country:", DCSUnit:getCountry(), CountryName } )
if country.id[CountryName] == DCSUnit:getCountry() then if country.id[CountryName] == DCSUnit:getCountry() then
DCSUnitCountry = true DCSUnitCountry = true
end end
@ -648,7 +648,7 @@ function DATABASE:_IsIncludeDCSUnit( DCSUnit )
if self.Filter.UnitPrefixes then if self.Filter.UnitPrefixes then
local DCSUnitPrefix = false local DCSUnitPrefix = false
for UnitPrefixId, UnitPrefix in pairs( self.Filter.UnitPrefixes ) do for UnitPrefixId, UnitPrefix in pairs( self.Filter.UnitPrefixes ) do
self:T( { "Unit Prefix:", string.find( DCSUnit:getName(), UnitPrefix, 1 ), UnitPrefix } ) self:T2( { "Unit Prefix:", string.find( DCSUnit:getName(), UnitPrefix, 1 ), UnitPrefix } )
if string.find( DCSUnit:getName(), UnitPrefix, 1 ) then if string.find( DCSUnit:getName(), UnitPrefix, 1 ) then
DCSUnitPrefix = true DCSUnitPrefix = true
end end
@ -656,7 +656,7 @@ function DATABASE:_IsIncludeDCSUnit( DCSUnit )
DCSUnitInclude = DCSUnitInclude and DCSUnitPrefix DCSUnitInclude = DCSUnitInclude and DCSUnitPrefix
end end
self:T( DCSUnitInclude ) self:T2( DCSUnitInclude )
return DCSUnitInclude return DCSUnitInclude
end end
@ -665,14 +665,14 @@ end
-- @param DCSUnit#Unit DCSUnit -- @param DCSUnit#Unit DCSUnit
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:_IsAliveDCSUnit( DCSUnit ) function DATABASE:_IsAliveDCSUnit( DCSUnit )
self:F( DCSUnit ) self:F2( DCSUnit )
local DCSUnitAlive = false local DCSUnitAlive = false
if DCSUnit and DCSUnit:isExist() and DCSUnit:isActive() then if DCSUnit and DCSUnit:isExist() and DCSUnit:isActive() then
if self.DCSUnits[DCSUnit:getName()] then if self.DCSUnits[DCSUnit:getName()] then
DCSUnitAlive = true DCSUnitAlive = true
end end
end end
self:T( DCSUnitAlive ) self:T2( DCSUnitAlive )
return DCSUnitAlive return DCSUnitAlive
end end
@ -681,25 +681,15 @@ end
-- @param DCSGroup#Group DCSGroup -- @param DCSGroup#Group DCSGroup
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:_IsAliveDCSGroup( DCSGroup ) function DATABASE:_IsAliveDCSGroup( DCSGroup )
self:F( DCSGroup ) self:F2( DCSGroup )
local DCSGroupAlive = false local DCSGroupAlive = false
if DCSGroup and DCSGroup:isExist() then if DCSGroup and DCSGroup:isExist() then
if self.DCSGroups[DCSGroup:getName()] then if self.DCSGroups[DCSGroup:getName()] then
DCSGroupAlive = true DCSGroupAlive = true
end end
end end
self:T( DCSGroupAlive ) self:T2( DCSGroupAlive )
return DCSGroupAlive return DCSGroupAlive
end end
--- Traces the current database contents in the log ... (for debug reasons).
-- @param #DATABASE self
-- @return #DATABASE self
function DATABASE:TraceDatabase()
self:F()
self:T( { "DCSUnits:", self.DCSUnits } )
end

View File

@ -64,7 +64,7 @@ local _EVENTCODES = {
function EVENT:New() function EVENT:New()
local self = BASE:Inherit( self, BASE:New() ) local self = BASE:Inherit( self, BASE:New() )
self:F() self:F2()
self.EventHandler = world.addEventHandler( self ) self.EventHandler = world.addEventHandler( self )
return self return self
end end
@ -154,7 +154,7 @@ end
-- @param EventSelf The self instance of the class for which the event is. -- @param EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnBirthForTemplate( EventTemplate, EventFunction, EventSelf ) function EVENT:OnBirthForTemplate( EventTemplate, EventFunction, EventSelf )
self:F( EventTemplate.name ) self:F2( EventTemplate.name )
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnBirthForUnit ) self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnBirthForUnit )
@ -167,7 +167,7 @@ end
-- @param Base#BASE EventSelf -- @param Base#BASE EventSelf
-- @return #EVENT -- @return #EVENT
function EVENT:OnBirth( EventFunction, EventSelf ) function EVENT:OnBirth( EventFunction, EventSelf )
self:F() self:F2()
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_BIRTH ) self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_BIRTH )
@ -181,7 +181,7 @@ end
-- @param Base#BASE EventSelf -- @param Base#BASE EventSelf
-- @return #EVENT -- @return #EVENT
function EVENT:OnBirthForUnit( EventDCSUnitName, EventFunction, EventSelf ) function EVENT:OnBirthForUnit( EventDCSUnitName, EventFunction, EventSelf )
self:F( EventDCSUnitName ) self:F2( EventDCSUnitName )
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_BIRTH ) self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_BIRTH )
@ -195,7 +195,7 @@ end
-- @param EventSelf The self instance of the class for which the event is. -- @param EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnCrashForTemplate( EventTemplate, EventFunction, EventSelf ) function EVENT:OnCrashForTemplate( EventTemplate, EventFunction, EventSelf )
self:F( EventTemplate.name ) self:F2( EventTemplate.name )
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnCrashForUnit ) self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnCrashForUnit )
@ -208,7 +208,7 @@ end
-- @param Base#BASE EventSelf -- @param Base#BASE EventSelf
-- @return #EVENT -- @return #EVENT
function EVENT:OnCrash( EventFunction, EventSelf ) function EVENT:OnCrash( EventFunction, EventSelf )
self:F() self:F2()
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_CRASH ) self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_CRASH )
@ -222,7 +222,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnCrashForUnit( EventDCSUnitName, EventFunction, EventSelf ) function EVENT:OnCrashForUnit( EventDCSUnitName, EventFunction, EventSelf )
self:F( EventDCSUnitName ) self:F2( EventDCSUnitName )
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_CRASH ) self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_CRASH )
@ -236,7 +236,7 @@ end
-- @param EventSelf The self instance of the class for which the event is. -- @param EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnDeadForTemplate( EventTemplate, EventFunction, EventSelf ) function EVENT:OnDeadForTemplate( EventTemplate, EventFunction, EventSelf )
self:F( EventTemplate.name ) self:F2( EventTemplate.name )
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnDeadForUnit ) self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnDeadForUnit )
@ -249,7 +249,7 @@ end
-- @param Base#BASE EventSelf -- @param Base#BASE EventSelf
-- @return #EVENT -- @return #EVENT
function EVENT:OnDead( EventFunction, EventSelf ) function EVENT:OnDead( EventFunction, EventSelf )
self:F() self:F2()
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_DEAD ) self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_DEAD )
@ -264,7 +264,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnDeadForUnit( EventDCSUnitName, EventFunction, EventSelf ) function EVENT:OnDeadForUnit( EventDCSUnitName, EventFunction, EventSelf )
self:F( EventDCSUnitName ) self:F2( EventDCSUnitName )
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_DEAD ) self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_DEAD )
@ -278,7 +278,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnPilotDeadForUnit( EventDCSUnitName, EventFunction, EventSelf ) function EVENT:OnPilotDeadForUnit( EventDCSUnitName, EventFunction, EventSelf )
self:F( EventDCSUnitName ) self:F2( EventDCSUnitName )
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_PILOT_DEAD ) self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_PILOT_DEAD )
@ -292,7 +292,7 @@ end
-- @param EventSelf The self instance of the class for which the event is. -- @param EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnLandForTemplate( EventTemplate, EventFunction, EventSelf ) function EVENT:OnLandForTemplate( EventTemplate, EventFunction, EventSelf )
self:F( EventTemplate.name ) self:F2( EventTemplate.name )
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnLandForUnit ) self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnLandForUnit )
@ -306,7 +306,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnLandForUnit( EventDCSUnitName, EventFunction, EventSelf ) function EVENT:OnLandForUnit( EventDCSUnitName, EventFunction, EventSelf )
self:F( EventDCSUnitName ) self:F2( EventDCSUnitName )
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_LAND ) self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_LAND )
@ -320,7 +320,7 @@ end
-- @param EventSelf The self instance of the class for which the event is. -- @param EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnTakeOffForTemplate( EventTemplate, EventFunction, EventSelf ) function EVENT:OnTakeOffForTemplate( EventTemplate, EventFunction, EventSelf )
self:F( EventTemplate.name ) self:F2( EventTemplate.name )
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnTakeOffForUnit ) self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnTakeOffForUnit )
@ -334,7 +334,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnTakeOffForUnit( EventDCSUnitName, EventFunction, EventSelf ) function EVENT:OnTakeOffForUnit( EventDCSUnitName, EventFunction, EventSelf )
self:F( EventDCSUnitName ) self:F2( EventDCSUnitName )
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_TAKEOFF ) self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_TAKEOFF )
@ -348,7 +348,7 @@ end
-- @param EventSelf The self instance of the class for which the event is. -- @param EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnEngineShutDownForTemplate( EventTemplate, EventFunction, EventSelf ) function EVENT:OnEngineShutDownForTemplate( EventTemplate, EventFunction, EventSelf )
self:F( EventTemplate.name ) self:F2( EventTemplate.name )
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnEngineShutDownForUnit ) self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnEngineShutDownForUnit )
@ -362,7 +362,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnEngineShutDownForUnit( EventDCSUnitName, EventFunction, EventSelf ) function EVENT:OnEngineShutDownForUnit( EventDCSUnitName, EventFunction, EventSelf )
self:F( EventDCSUnitName ) self:F2( EventDCSUnitName )
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_ENGINE_SHUTDOWN ) self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_ENGINE_SHUTDOWN )
@ -376,7 +376,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnEngineStartUpForUnit( EventDCSUnitName, EventFunction, EventSelf ) function EVENT:OnEngineStartUpForUnit( EventDCSUnitName, EventFunction, EventSelf )
self:F( EventDCSUnitName ) self:F2( EventDCSUnitName )
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_ENGINE_STARTUP ) self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_ENGINE_STARTUP )
@ -389,7 +389,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnShot( EventFunction, EventSelf ) function EVENT:OnShot( EventFunction, EventSelf )
self:F() self:F2()
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_SHOT ) self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_SHOT )
@ -403,7 +403,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnShotForUnit( EventDCSUnitName, EventFunction, EventSelf ) function EVENT:OnShotForUnit( EventDCSUnitName, EventFunction, EventSelf )
self:F( EventDCSUnitName ) self:F2( EventDCSUnitName )
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_SHOT ) self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_SHOT )
@ -416,7 +416,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnHit( EventFunction, EventSelf ) function EVENT:OnHit( EventFunction, EventSelf )
self:F() self:F2()
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_HIT ) self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_HIT )
@ -430,7 +430,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnHitForUnit( EventDCSUnitName, EventFunction, EventSelf ) function EVENT:OnHitForUnit( EventDCSUnitName, EventFunction, EventSelf )
self:F( EventDCSUnitName ) self:F2( EventDCSUnitName )
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_HIT ) self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_HIT )
@ -443,7 +443,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnPlayerEnterUnit( EventFunction, EventSelf ) function EVENT:OnPlayerEnterUnit( EventFunction, EventSelf )
self:F() self:F2()
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_PLAYER_ENTER_UNIT ) self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_PLAYER_ENTER_UNIT )
@ -456,7 +456,7 @@ end
-- @param Base#BASE EventSelf The self instance of the class for which the event is. -- @param Base#BASE EventSelf The self instance of the class for which the event is.
-- @return #EVENT -- @return #EVENT
function EVENT:OnPlayerLeaveUnit( EventFunction, EventSelf ) function EVENT:OnPlayerLeaveUnit( EventFunction, EventSelf )
self:F() self:F2()
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_PLAYER_LEAVE_UNIT ) self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_PLAYER_LEAVE_UNIT )
@ -466,7 +466,7 @@ end
function EVENT:onEvent( Event ) function EVENT:onEvent( Event )
self:F( { _EVENTCODES[Event.id], Event } ) self:F2( { _EVENTCODES[Event.id], Event } )
if self and self.Events and self.Events[Event.id] then if self and self.Events and self.Events[Event.id] then
if Event.initiator and Event.initiator:getCategory() == Object.Category.UNIT then if Event.initiator and Event.initiator:getCategory() == Object.Category.UNIT then

View File

@ -198,6 +198,23 @@ function GROUP:GetCoalition()
return nil return nil
end end
--- Returns the country of the DCS Group.
-- @param #GROUP self
-- @return DCScountry#country.id The country identifier.
-- @return #nil The DCS Group is not existing or alive.
function GROUP:GetCountry()
self:F2( self.GroupName )
local DCSGroup = self:GetDCSGroup()
if DCSGroup then
local GroupCountry = DCSGroup:getUnit(1):getCountry()
self:T3( GroupCountry )
return GroupCountry
end
return nil
end
--- Returns the name of the DCS Group. --- Returns the name of the DCS Group.
-- @param #GROUP self -- @param #GROUP self
-- @return #string The DCS Group name. -- @return #string The DCS Group name.

View File

@ -0,0 +1,327 @@
--- 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.FilterTypes}: Builds the GROUPSET with the groups belonging to the unit type(s).
-- * @{#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 unit it finds within the GROUPSET.
--
-- Planned iterators methods in development are (so these are not yet available):
--
-- * @{#GROUPSET.ForEachUnitInGroup}: Calls a function for each group contained within the GROUPSET.
-- * @{#GROUPSET.ForEachUnitInZone}: Calls a function for each unit within a certain zone contained 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",
Units = {},
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 Unit based on the Unit Name.
-- @param #GROUPSET self
-- @param #string GroupName
-- @return Group#GROUP The found Unit.
function GROUPSET:FindUnit( 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 unit 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:ForEachUnit( 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 Unit 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

View File

@ -75,66 +75,10 @@ Include.File( "Client" )
-- @extends Base#BASE -- @extends Base#BASE
SET = { SET = {
ClassName = "SET", ClassName = "SET",
Templates = { Set = {},
Units = {}, Database = {},
Groups = {},
ClientsByName = {},
ClientsByID = {},
},
DCSUnits = {},
DCSUnitsAlive = {},
DCSGroups = {},
DCSGroupsAlive = {},
Units = {},
UnitsAlive = {},
Groups = {},
GroupsAlive = {},
NavPoints = {},
Statics = {},
Players = {},
PlayersAlive = {},
Clients = {},
ClientsAlive = {},
Filter = {
Coalitions = nil,
Categories = nil,
Types = nil,
Countries = nil,
UnitPrefixes = nil,
GroupPrefixes = 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,
},
},
} }
local _DATABASECoalition =
{
[1] = "Red",
[2] = "Blue",
}
local _DATABASECategory =
{
[Unit.Category.AIRPLANE] = "Plane",
[Unit.Category.HELICOPTER] = "Helicopter",
[Unit.Category.GROUND_UNIT] = "Vehicle",
[Unit.Category.SHIP] = "Ship",
[Unit.Category.STRUCTURE] = "Structure",
}
--- Creates a new SET object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names. --- 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 -- @param #SET self
-- @return #SET -- @return #SET
@ -146,21 +90,7 @@ function SET:New( Database )
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, BASE:New() ) local self = BASE:Inherit( self, BASE:New() )
_EVENTDISPATCHER:OnBirth( self._EventOnBirth, self ) self.Database = Database
_EVENTDISPATCHER:OnDead( self._EventOnDeadOrCrash, self )
_EVENTDISPATCHER:OnCrash( self._EventOnDeadOrCrash, self )
-- Add SET with registered clients and already alive players
-- Follow alive players and clients
_EVENTDISPATCHER:OnPlayerEnterUnit( self._EventOnPlayerEnterUnit, self )
_EVENTDISPATCHER:OnPlayerLeaveUnit( self._EventOnPlayerLeaveUnit, self )
self.Collection = Database
self:_RegisterSet()
self:_RegisterPlayers()
return self return self
end end
@ -190,7 +120,7 @@ end
-- @return #SET self -- @return #SET self
function SET:_FilterStart() function SET:_FilterStart()
for ObjectName, Object in pairs( self.Collection ) do for ObjectName, Object in pairs( self.Database ) do
if self:IsIncludeObject( Object ) then if self:IsIncludeObject( Object ) then
self:E( { "Adding Object:", ObjectName } ) self:E( { "Adding Object:", ObjectName } )
@ -198,32 +128,41 @@ function SET:_FilterStart()
end end
end end
_EVENTDISPATCHER:OnBirth( self._EventOnBirth, self )
_EVENTDISPATCHER:OnDead( self._EventOnDeadOrCrash, self )
_EVENTDISPATCHER:OnCrash( self._EventOnDeadOrCrash, self )
-- Follow alive players and clients
-- _EVENTDISPATCHER:OnPlayerEnterUnit( self._EventOnPlayerEnterUnit, self )
-- _EVENTDISPATCHER:OnPlayerLeaveUnit( self._EventOnPlayerLeaveUnit, self )
return self return self
end end
--- Private method that registers all alive players in the mission. ----- Private method that registers all alive players in the mission.
-- @param #SET self ---- @param #SET self
-- @return #SET self ---- @return #SET self
function SET:_RegisterPlayers() --function SET:_RegisterPlayers()
--
local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) } -- local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) }
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do -- for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
for UnitId, UnitData in pairs( CoalitionData ) do -- for UnitId, UnitData in pairs( CoalitionData ) do
self:T3( { "UnitData:", UnitData } ) -- self:T3( { "UnitData:", UnitData } )
if UnitData and UnitData:isExist() then -- if UnitData and UnitData:isExist() then
local UnitName = UnitData:getName() -- local UnitName = UnitData:getName()
if not self.PlayersAlive[UnitName] then -- if not self.PlayersAlive[UnitName] then
self:E( { "Add player for unit:", UnitName, UnitData:getPlayerName() } ) -- self:E( { "Add player for unit:", UnitName, UnitData:getPlayerName() } )
self.PlayersAlive[UnitName] = UnitData:getPlayerName() -- self.PlayersAlive[UnitName] = UnitData:getPlayerName()
end -- end
end -- end
end -- end
end -- end
--
return self -- return self
end --end
--- Events --- Events
@ -231,10 +170,11 @@ end
-- @param #SET self -- @param #SET self
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function SET:_EventOnBirth( Event ) function SET:_EventOnBirth( Event )
self:F( { Event } ) self:F3( { Event } )
if Event.IniDCSUnit then if Event.IniDCSUnit then
local ObjectName, Object = self:AddInDatabase( Event ) local ObjectName, Object = self:AddInDatabase( Event )
self:T3( ObjectName, Object )
if self:IsIncludeObject( Object ) then if self:IsIncludeObject( Object ) then
self:_Add( ObjectName, Object ) self:_Add( ObjectName, Object )
--self:_EventOnPlayerEnterUnit( Event ) --self:_EventOnPlayerEnterUnit( Event )
@ -246,7 +186,7 @@ end
-- @param #SET self -- @param #SET self
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function SET:_EventOnDeadOrCrash( Event ) function SET:_EventOnDeadOrCrash( Event )
self:F( { Event } ) self:F3( { Event } )
if Event.IniDCSUnit then if Event.IniDCSUnit then
local ObjectName, Object = self:FindInDatabase( Event ) local ObjectName, Object = self:FindInDatabase( Event )
@ -260,7 +200,7 @@ end
---- @param #SET self ---- @param #SET self
---- @param Event#EVENTDATA Event ---- @param Event#EVENTDATA Event
--function SET:_EventOnPlayerEnterUnit( Event ) --function SET:_EventOnPlayerEnterUnit( Event )
-- self:F( { Event } ) -- self:F3( { Event } )
-- --
-- if Event.IniDCSUnit then -- if Event.IniDCSUnit then
-- if self:IsIncludeObject( Event.IniDCSUnit ) then -- if self:IsIncludeObject( Event.IniDCSUnit ) then
@ -277,7 +217,7 @@ end
---- @param #SET self ---- @param #SET self
---- @param Event#EVENTDATA Event ---- @param Event#EVENTDATA Event
--function SET:_EventOnPlayerLeaveUnit( Event ) --function SET:_EventOnPlayerLeaveUnit( Event )
-- self:F( { Event } ) -- self:F3( { Event } )
-- --
-- if Event.IniDCSUnit then -- if Event.IniDCSUnit then
-- if self:IsIncludeObject( Event.IniDCSUnit ) then -- if self:IsIncludeObject( Event.IniDCSUnit ) then
@ -297,7 +237,7 @@ end
-- @param #function IteratorFunction The function that will be called when there is an alive player in the SET. -- @param #function IteratorFunction The function that will be called when there is an alive player in the SET.
-- @return #SET self -- @return #SET self
function SET:ForEach( IteratorFunction, arg, Set ) function SET:ForEach( IteratorFunction, arg, Set )
self:F( arg ) self:F3( arg )
local function CoRoutine() local function CoRoutine()
local Count = 0 local Count = 0
@ -317,7 +257,7 @@ function SET:ForEach( IteratorFunction, arg, Set )
local function Schedule() local function Schedule()
local status, res = coroutine.resume( co ) local status, res = coroutine.resume( co )
self:T( { status, res } ) self:T3( { status, res } )
if status == false then if status == false then
error( res ) error( res )
@ -335,42 +275,42 @@ function SET:ForEach( IteratorFunction, arg, Set )
end end
--- Interate the SET and call an interator function for each **alive** unit, providing the Unit and optional parameters. ----- Interate the SET and call an interator function for each **alive** unit, providing the Unit and optional parameters.
-- @param #SET self ---- @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. ---- @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 ---- @return #SET self
function SET:ForEachDCSUnitAlive( IteratorFunction, ... ) --function SET:ForEachDCSUnitAlive( IteratorFunction, ... )
self:F( arg ) -- self:F3( arg )
--
self:ForEach( IteratorFunction, arg, self.DCSUnitsAlive ) -- self:ForEach( IteratorFunction, arg, self.DCSUnitsAlive )
--
return self -- return self
end --end
--
--- Interate the SET and call an interator function for each **alive** player, providing the Unit of the player and optional parameters. ----- 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 #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. ---- @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 ---- @return #SET self
function SET:ForEachPlayer( IteratorFunction, ... ) --function SET:ForEachPlayer( IteratorFunction, ... )
self:F( arg ) -- self:F3( arg )
--
self:ForEach( IteratorFunction, arg, self.PlayersAlive ) -- self:ForEach( IteratorFunction, arg, self.PlayersAlive )
--
return self -- return self
end --end
--
--
--- Interate the SET and call an interator function for each client, providing the Client to the function and optional parameters. ----- Interate the SET and call an interator function for each client, providing the Client to the function and optional parameters.
-- @param #SET self ---- @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. ---- @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 ---- @return #SET self
function SET:ForEachClient( IteratorFunction, ... ) --function SET:ForEachClient( IteratorFunction, ... )
self:F( arg ) -- self:F3( arg )
--
self:ForEach( IteratorFunction, arg, self.Clients ) -- self:ForEach( IteratorFunction, arg, self.Clients )
--
return self -- return self
end --end
--- Decides whether to include the Object --- Decides whether to include the Object
@ -378,53 +318,22 @@ end
-- @param #table Object -- @param #table Object
-- @return #SET self -- @return #SET self
function SET:IsIncludeObject( Object ) function SET:IsIncludeObject( Object )
self:F( Object ) self:F3( Object )
return true return true
end end
--- Flushes the current SET contents in the log ... (for debug reasons).
---
-- @param #SET self -- @param #SET self
-- @param DCSUnit#Unit DCSUnit
-- @return #SET self -- @return #SET self
function SET:_IsAliveDCSUnit( DCSUnit ) function SET:Flush()
self:F( DCSUnit ) self:F3()
local DCSUnitAlive = false
if DCSUnit and DCSUnit:isExist() and DCSUnit:isActive() then local ObjectNames = ""
if self.DCSUnits[DCSUnit:getName()] then for ObjectName, Object in pairs( self.Set ) do
DCSUnitAlive = true ObjectNames = ObjectNames .. ObjectName .. ", "
end
end end
self:T( DCSUnitAlive ) self:T( { "Objects in Set:", ObjectNames } )
return DCSUnitAlive
end
---
-- @param #SET self
-- @param DCSGroup#Group DCSGroup
-- @return #SET self
function SET:_IsAliveDCSGroup( DCSGroup )
self:F( DCSGroup )
local DCSGroupAlive = false
if DCSGroup and DCSGroup:isExist() then
if self.DCSGroups[DCSGroup:getName()] then
DCSGroupAlive = true
end
end
self:T( DCSGroupAlive )
return DCSGroupAlive
end
--- Traces the current SET contents in the log ... (for debug reasons).
-- @param #SET self
-- @return #SET self
function SET:TraceDatabase()
self:F()
self:T( { "DCSUnits:", self.DCSUnits } )
self:T( { "DCSUnitsAlive:", self.DCSUnitsAlive } )
end end

View File

@ -10,12 +10,6 @@
-- * Unit types -- * Unit types
-- * Starting with certain prefix strings. -- * 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.
--
-- UNITSET construction methods: -- UNITSET construction methods:
-- ================================= -- =================================
-- Create a new UNITSET object with the @{#UNITSET.New} method: -- Create a new UNITSET object with the @{#UNITSET.New} method:
@ -56,16 +50,13 @@
-- * @{#UNITSET.ForEachUnitInGroup}: Calls a function for each group contained within the UNITSET. -- * @{#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. -- * @{#UNITSET.ForEachUnitInZone}: Calls a function for each unit within a certain zone contained within the UNITSET.
-- --
-- @module Set -- @module UnitSet
-- @author FlightControl -- @author FlightControl
Include.File( "Routines" ) Include.File( "Routines" )
Include.File( "Base" ) Include.File( "Base" )
Include.File( "Menu" )
Include.File( "Group" )
Include.File( "Unit" ) Include.File( "Unit" )
Include.File( "Event" ) Include.File( "Set" )
Include.File( "Client" )
--- UNITSET class --- UNITSET class
@ -97,21 +88,6 @@ UNITSET = {
}, },
} }
local _DATABASECoalition =
{
[1] = "Red",
[2] = "Blue",
}
local _DATABASECategory =
{
[Unit.Category.AIRPLANE] = "Plane",
[Unit.Category.HELICOPTER] = "Helicopter",
[Unit.Category.GROUND_UNIT] = "Vehicle",
[Unit.Category.SHIP] = "Ship",
[Unit.Category.STRUCTURE] = "Structure",
}
--- Creates a new UNITSET object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names. --- 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 -- @param #UNITSET self
@ -122,42 +98,25 @@ local _DATABASECategory =
function UNITSET:New() function UNITSET:New()
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, SET:New( _DATABASE.Units ) ) local self = BASE:Inherit( self, SET:New( _DATABASE.UNITS ) )
-- -- Follow alive players and clients
-- _EVENTDISPATCHER:OnPlayerEnterUnit( self._EventOnPlayerEnterUnit, self )
-- _EVENTDISPATCHER:OnPlayerLeaveUnit( self._EventOnPlayerLeaveUnit, self )
-- self:_RegisterPlayers()
return self return self
end end
--- Finds a Unit based on the Unit Name. --- Finds a Unit based on the Unit Name.
-- @param #UNITSET self -- @param #UNITSET self
-- @param #string UnitName -- @param #string UnitName
-- @return Unit#UNIT The found Unit. -- @return Unit#UNIT The found Unit.
function UNITSET:FindUnit( UnitName ) function UNITSET:FindUnit( UnitName )
local UnitFound = self.Units[UnitName] local UnitFound = self.Set[UnitName]
return UnitFound return UnitFound
end end
--- Finds a Unit based on the Unit Name.
-- @param #UNITSET self
-- @param Unit#UNIT UnitName
-- @param Unit#UNIT UnitData
-- @return Unit#UNIT The added Unit.
function UNITSET:_AddUnit( UnitName, UnitData )
self.Units[UnitName] = _DATABASE:FindUnit( UnitName )
end
--- Builds a set of units of coalitions.
--- Builds a set of units of coalitons.
-- Possible current coalitions are red, blue and neutral. -- Possible current coalitions are red, blue and neutral.
-- @param #UNITSET self -- @param #UNITSET self
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral". -- @param #string Coalitions Can take the following values: "red", "blue", "neutral".
@ -252,23 +211,6 @@ function UNITSET:FilterPrefixes( Prefixes )
end end
----- Builds a set of units of defined group prefixes.
---- All the units starting with the given group prefixes will be included within the set.
---- @param #UNITSET self
---- @param #string Prefixes The prefix of which the group name where the unit belongs to starts with.
---- @return #UNITSET self
--function UNITSET:FilterGroupPrefixes( 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. --- Starts the filtering.
@ -277,173 +219,78 @@ end
function UNITSET:FilterStart() function UNITSET:FilterStart()
if _DATABASE then if _DATABASE then
self:_FilterStart( self.DatabaseCollection ) self:_FilterStart()
end end
FollowEventBirth( )
_EVENTDISPATCHER:OnBirth( self._EventOnBirth, self )
_EVENTDISPATCHER:OnDead( self._EventOnDeadOrCrash, self )
_EVENTDISPATCHER:OnCrash( self._EventOnDeadOrCrash, self )
return self return self
end end
--- Events --- 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!
--- Handles the OnBirth event for the alive units set.
-- @param #UNITSET self -- @param #UNITSET self
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function UNITSET:_EventOnBirth( Event ) -- @return #string The name of the UNIT
self:F( { Event } ) -- @return #table The UNIT
function UNITSET:AddInDatabase( Event )
self:F3( { Event } )
if Event.IniDCSUnit then if not self.Database[Event.IniDCSUnitName] then
if self:_IsIncludeUnit( Event.IniDCSUnit ) then self.Database[Event.IniDCSUnitName] = UNIT:Register( Event.IniDCSUnitName )
self.DCSUnits[Event.IniDCSUnitName] = Event.IniDCSUnit self:T3( self.Database[Event.IniDCSUnitName] )
self.DCSUnitsAlive[Event.IniDCSUnitName] = Event.IniDCSUnit
self:_AddUnit( UNIT:Register( Event.IniDCSUnit ) )
--self.Units[Event.IniDCSUnitName] = UNIT:Register( Event.IniDCSUnit )
--if not self.DCSGroups[Event.IniDCSGroupName] then
-- self.DCSGroups[Event.IniDCSGroupName] = Event.IniDCSGroupName
-- self.DCSGroupsAlive[Event.IniDCSGroupName] = Event.IniDCSGroupName
-- self.Groups[Event.IniDCSGroupName] = GROUP:New( Event.IniDCSGroup )
--end
self:_EventOnPlayerEnterUnit( Event )
end
end end
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
end end
--- Handles the OnDead or OnCrash event for alive units set. --- 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 #UNITSET self
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function UNITSET:_EventOnDeadOrCrash( Event ) -- @return #string The name of the UNIT
self:F( { Event } ) -- @return #table The UNIT
function UNITSET:FindInDatabase( Event )
self:F3( { Event } )
if Event.IniDCSUnit then return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
if self.DCSUnitsAlive[Event.IniDCSUnitName] then
self.DCSUnits[Event.IniDCSUnitName] = nil
self.DCSUnitsAlive[Event.IniDCSUnitName] = nil
end
end
end end
--- Handles the OnPlayerEnterUnit event to fill the active players table (with the unit filter applied). --- Interate the UNITSET and call an interator function for each **alive** UNIT, providing the UNIT and optional parameters.
-- @param #UNITSET self -- @param #UNITSET self
-- @param Event#EVENTDATA Event -- @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.
function UNITSET:_EventOnPlayerEnterUnit( Event )
self:F( { Event } )
if Event.IniDCSUnit then
if self:_IsIncludeUnit( Event.IniDCSUnit ) then
if not self.PlayersAlive[Event.IniDCSUnitName] then
self:E( { "Add player for unit:", Event.IniDCSUnitName, Event.IniDCSUnit:getPlayerName() } )
self.PlayersAlive[Event.IniDCSUnitName] = Event.IniDCSUnit:getPlayerName()
self.ClientsAlive[Event.IniDCSUnitName] = _DATABASE.Clients[ Event.IniDCSUnitName ]
end
end
end
end
--- Handles the OnPlayerLeaveUnit event to clean the active players table.
-- @param #UNITSET self
-- @param Event#EVENTDATA Event
function UNITSET:_EventOnPlayerLeaveUnit( Event )
self:F( { Event } )
if Event.IniDCSUnit then
if self:_IsIncludeUnit( Event.IniDCSUnit ) then
if self.PlayersAlive[Event.IniDCSUnitName] then
self:E( { "Cleaning player for unit:", Event.IniDCSUnitName, Event.IniDCSUnit:getPlayerName() } )
self.PlayersAlive[Event.IniDCSUnitName] = nil
self.ClientsAlive[Event.IniDCSUnitName] = nil
end
end
end
end
--- Iterators
--- Interate the UNITSET and call an interator function for the given set, providing the Object for each element within the set and optional parameters.
-- @param #UNITSET self
-- @param #function IteratorFunction The function that will be called when there is an alive player in the UNITSET.
-- @return #UNITSET self -- @return #UNITSET self
function UNITSET:ForEach( IteratorFunction, arg, Set ) function UNITSET:ForEachUnit( IteratorFunction, ... )
self:F( arg ) self:F2( arg )
local function CoRoutine() self:ForEach( IteratorFunction, arg, self.Set )
local Count = 0
for ObjectID, Object in pairs( Set ) do
self:T2( Object )
IteratorFunction( Object, unpack( arg ) )
Count = Count + 1
if Count % 10 == 0 then
coroutine.yield( false )
end
end
return true
end
local co = coroutine.create( CoRoutine )
local function Schedule()
local status, res = coroutine.resume( co )
self:T( { status, res } )
if status == false then
error( res )
end
if res == false then
return true -- resume next time the loop
end
return false
end
local Scheduler = SCHEDULER:New( self, Schedule, {}, 0.001, 0.001, 0 )
return self return self
end end
--- Interate the UNITSET and call an interator function for each **alive** unit, providing the Unit and optional parameters. ----- 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 #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. ---- @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 ---- @return #UNITSET self
function UNITSET:ForEachDCSUnitAlive( IteratorFunction, ... ) --function UNITSET:ForEachPlayer( IteratorFunction, ... )
self:F( arg ) -- self:F2( arg )
--
self:ForEach( IteratorFunction, arg, self.DCSUnitsAlive ) -- self:ForEach( IteratorFunction, arg, self.PlayersAlive )
--
return self -- return self
end --end
--
--
--- Interate the UNITSET and call an interator function for each **alive** player, providing the Unit of the player and optional parameters. ----- Interate the UNITSET and call an interator function for each client, providing the Client to the function and optional parameters.
-- @param #UNITSET self ---- @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. ---- @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 ---- @return #UNITSET self
function UNITSET:ForEachPlayer( IteratorFunction, ... ) --function UNITSET:ForEachClient( IteratorFunction, ... )
self:F( arg ) -- self:F2( arg )
--
self:ForEach( IteratorFunction, arg, self.PlayersAlive ) -- self:ForEach( IteratorFunction, arg, self.Clients )
--
return self -- return self
end --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:F( arg )
self:ForEach( IteratorFunction, arg, self.Clients )
return self
end
--- ---
@ -451,13 +298,13 @@ end
-- @param Unit#UNIT MUnit -- @param Unit#UNIT MUnit
-- @return #UNITSET self -- @return #UNITSET self
function UNITSET:IsIncludeObject( MUnit ) function UNITSET:IsIncludeObject( MUnit )
self:F( MUnit ) self:F2( MUnit )
local MUnitInclude = true local MUnitInclude = true
if self.Filter.Coalitions then if self.Filter.Coalitions then
local MUnitCoalition = false local MUnitCoalition = false
for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do
self:T( { "Coalition:", MUnit:GetCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } ) self:T3( { "Coalition:", MUnit:GetCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } )
if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == MUnit:GetCoalition() then if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == MUnit:GetCoalition() then
MUnitCoalition = true MUnitCoalition = true
end end
@ -468,7 +315,7 @@ function UNITSET:IsIncludeObject( MUnit )
if self.Filter.Categories then if self.Filter.Categories then
local MUnitCategory = false local MUnitCategory = false
for CategoryID, CategoryName in pairs( self.Filter.Categories ) do for CategoryID, CategoryName in pairs( self.Filter.Categories ) do
self:T( { "Category:", MUnit:GetDesc().category, self.FilterMeta.Categories[CategoryName], CategoryName } ) 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 if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == MUnit:GetDesc().category then
MUnitCategory = true MUnitCategory = true
end end
@ -479,7 +326,7 @@ function UNITSET:IsIncludeObject( MUnit )
if self.Filter.Types then if self.Filter.Types then
local MUnitType = false local MUnitType = false
for TypeID, TypeName in pairs( self.Filter.Types ) do for TypeID, TypeName in pairs( self.Filter.Types ) do
self:T( { "Type:", MUnit:GetTypeName(), TypeName } ) self:T3( { "Type:", MUnit:GetTypeName(), TypeName } )
if TypeName == MUnit:GetTypeName() then if TypeName == MUnit:GetTypeName() then
MUnitType = true MUnitType = true
end end
@ -490,7 +337,7 @@ function UNITSET:IsIncludeObject( MUnit )
if self.Filter.Countries then if self.Filter.Countries then
local MUnitCountry = false local MUnitCountry = false
for CountryID, CountryName in pairs( self.Filter.Countries ) do for CountryID, CountryName in pairs( self.Filter.Countries ) do
self:T( { "Country:", MUnit:GetCountry(), CountryName } ) self:T3( { "Country:", MUnit:GetCountry(), CountryName } )
if country.id[CountryName] == MUnit:GetCountry() then if country.id[CountryName] == MUnit:GetCountry() then
MUnitCountry = true MUnitCountry = true
end end
@ -501,7 +348,7 @@ function UNITSET:IsIncludeObject( MUnit )
if self.Filter.UnitPrefixes then if self.Filter.UnitPrefixes then
local MUnitPrefix = false local MUnitPrefix = false
for UnitPrefixId, UnitPrefix in pairs( self.Filter.UnitPrefixes ) do for UnitPrefixId, UnitPrefix in pairs( self.Filter.UnitPrefixes ) do
self:T( { "Unit Prefix:", string.find( MUnit:GetName(), UnitPrefix, 1 ), UnitPrefix } ) self:T3( { "Prefix:", string.find( MUnit:GetName(), UnitPrefix, 1 ), UnitPrefix } )
if string.find( MUnit:GetName(), UnitPrefix, 1 ) then if string.find( MUnit:GetName(), UnitPrefix, 1 ) then
MUnitPrefix = true MUnitPrefix = true
end end
@ -509,7 +356,7 @@ function UNITSET:IsIncludeObject( MUnit )
MUnitInclude = MUnitInclude and MUnitPrefix MUnitInclude = MUnitInclude and MUnitPrefix
end end
self:T( MUnitInclude ) self:T2( MUnitInclude )
return MUnitInclude return MUnitInclude
end end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,39 +1,52 @@
Include.File( 'Database' )
Include.File( 'UnitSet' )
Include.File( 'GroupSet' )
Include.File( 'Spawn' ) Include.File( 'Spawn' )
DBBluePlanes = DATABASE:New() DBBluePlanes = UNITSET:New()
:FilterCoalitions( "blue" ) :FilterCoalitions( "blue" )
:FilterCategories( "plane" ) :FilterCategories( "plane" )
:FilterStart() :FilterStart()
DBRedVehicles = DATABASE:New() DBRedVehicles = UNITSET:New()
:FilterCoalitions( "red" ) :FilterCoalitions( "red" )
:FilterCategories( "ground" ) :FilterCategories( "ground" )
:FilterStart() :FilterStart()
DBShips = DATABASE:New() DBShips = UNITSET:New()
:FilterCategories( "ship" ) :FilterCategories( "ship" )
:FilterStart() :FilterStart()
DBBelgium = DATABASE:New() DBBelgium = UNITSET:New()
:FilterCategories( "helicopter" ) :FilterCategories( "helicopter" )
:FilterCountries( "BELGIUM" ) :FilterCountries( "BELGIUM" )
:FilterStart() :FilterStart()
DBNorthKorea = DATABASE:New() DBNorthKorea = UNITSET:New()
:FilterCountries( "NORTH_KOREA" ) :FilterCountries( "NORTH_KOREA" )
:FilterStart() :FilterStart()
DBKA50Vinson = DATABASE:New() DBKA50Vinson = UNITSET:New()
:FilterTypes( { "Ka-50", "VINSON" } ) :FilterTypes( { "Ka-50", "VINSON" } )
:FilterStart() :FilterStart()
DBBluePlanes:TraceDatabase() DBBluePlanesGroup = GROUPSET:New()
DBRedVehicles:TraceDatabase() :FilterCoalitions( "blue" )
DBShips:TraceDatabase() :FilterCategories( "plane" )
DBBelgium:TraceDatabase() :FilterStart()
DBNorthKorea:TraceDatabase()
DBKA50Vinson:TraceDatabase() DBNorthKoreaGroup = GROUPSET:New()
:FilterCountries( "NORTH_KOREA" )
:FilterStart()
DBBluePlanes:Flush()
DBRedVehicles:Flush()
DBShips:Flush()
DBBelgium:Flush()
DBNorthKorea:Flush()
DBKA50Vinson:Flush()
DBBluePlanesGroup:Flush()
DBNorthKoreaGroup:Flush()
SpawnUS_Plane = SPAWN:New( 'Database Spawn Test USA Plane') SpawnUS_Plane = SPAWN:New( 'Database Spawn Test USA Plane')
@ -54,21 +67,27 @@ GroupRU_Ship = SpawnRU_Ship:Spawn()
SpawnUS_AttackVehicle = SPAWN:New( 'Database Spawn Test USA Attack Vehicle' ) SpawnUS_AttackVehicle = SPAWN:New( 'Database Spawn Test USA Attack Vehicle' )
SpawnRU_AttackVehicle = SPAWN:New( 'Database Spawn Test RUSSIA Attack Vehicle' ) SpawnRU_AttackVehicle = SPAWN:New( 'Database Spawn Test RUSSIA Attack Vehicle' )
for i = 1, 10 do for i = 1, 2 do
GroupRU_AttackVehicle = SpawnRU_AttackVehicle:SpawnInZone( ZONE:New("Spawn Zone RU"), true) GroupRU_AttackVehicle = SpawnRU_AttackVehicle:SpawnInZone( ZONE:New("Spawn Zone RU"), true)
GroupUS_AttackVehicle = SpawnUS_AttackVehicle:SpawnInZone( ZONE:New("Spawn Zone US"), true) GroupUS_AttackVehicle = SpawnUS_AttackVehicle:SpawnInZone( ZONE:New("Spawn Zone US"), true)
end end
--DBBlue:TraceDatabase() --DBBlue:TraceDatabase()
routines.scheduleFunction( DBBluePlanes.TraceDatabase, { DBBluePlanes }, 1 ) SCHEDULER:New( DBBluePlanes, DBBluePlanes.Flush, { }, 1 )
routines.scheduleFunction( DBRedVehicles.TraceDatabase, { DBRedVehicles }, 1 ) SCHEDULER:New( DBRedVehicles, DBRedVehicles.Flush, { }, 1 )
routines.scheduleFunction( DBShips.TraceDatabase, { DBShips }, 1 ) SCHEDULER:New( DBShips, DBShips.Flush, { }, 1 )
routines.scheduleFunction( DBBelgium.TraceDatabase, { DBBelgium }, 1 ) SCHEDULER:New( DBBelgium, DBBelgium.Flush, { }, 1 )
routines.scheduleFunction( DBNorthKorea.TraceDatabase, { DBNorthKorea }, 1 ) SCHEDULER:New( DBNorthKorea, DBNorthKorea.Flush, { }, 1 )
routines.scheduleFunction( DBKA50Vinson.TraceDatabase, { DBKA50Vinson }, 1 ) SCHEDULER:New( DBKA50Vinson, DBKA50Vinson.Flush, { }, 1 )
SCHEDULER:New( DBBluePlanesGroup, DBBluePlanesGroup.Flush, { }, 1 )
SCHEDULER:New( DBNorthKoreaGroup, DBNorthKoreaGroup.Flush, { }, 1 )
DBRedVehicles DBRedVehicles
:ForEachAliveUnit( function( DCSUnit ) :ForEachUnit( function( MooseUnit )
DBRedVehicles:T( DCSUnit:getName() ) DBRedVehicles:T( MooseUnit:GetName() )
end ) end )