mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
GROUPSET and UNITSET are working now !!
- GROUPSET and UNITSET inherit SET - DATABASE optimized - Tracing levels tuned.
This commit is contained in:
@@ -226,9 +226,9 @@ end
|
||||
-- @param #table SpawnTemplate
|
||||
-- @return #DATABASE self
|
||||
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.
|
||||
local SpawnCoalitionID = SpawnTemplate.SpawnCoalitionID
|
||||
@@ -240,7 +240,7 @@ function DATABASE:Spawn( SpawnTemplate )
|
||||
SpawnTemplate.SpawnCountryID = nil
|
||||
SpawnTemplate.SpawnCategoryID = nil
|
||||
|
||||
self:_RegisterGroup( SpawnTemplate )
|
||||
self:_RegisterTemplate( SpawnTemplate )
|
||||
coalition.addGroup( SpawnCountryID, SpawnCategoryID, SpawnTemplate )
|
||||
|
||||
-- Restore
|
||||
@@ -256,7 +256,7 @@ end
|
||||
|
||||
--- Set a status to a Group within the Database, this to check crossing events for example.
|
||||
function DATABASE:SetStatusGroup( GroupName, Status )
|
||||
self:F( Status )
|
||||
self:F2( Status )
|
||||
|
||||
self.Templates.Groups[GroupName].Status = Status
|
||||
end
|
||||
@@ -264,7 +264,7 @@ end
|
||||
|
||||
--- Get a status to a Group within the Database, this to check crossing events for example.
|
||||
function DATABASE:GetStatusGroup( GroupName )
|
||||
self:F( Status )
|
||||
self:F2( Status )
|
||||
|
||||
if self.Templates.Groups[GroupName] then
|
||||
return self.Templates.Groups[GroupName].Status
|
||||
@@ -277,7 +277,7 @@ end
|
||||
-- @param #DATABASE self
|
||||
-- @param #table GroupTemplate
|
||||
-- @return #DATABASE self
|
||||
function DATABASE:_RegisterGroup( GroupTemplate )
|
||||
function DATABASE:_RegisterTemplate( GroupTemplate )
|
||||
|
||||
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].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
|
||||
|
||||
@@ -381,7 +381,7 @@ end
|
||||
-- @param #DATABASE self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function DATABASE:_EventOnBirth( Event )
|
||||
self:F( { Event } )
|
||||
self:F2( { Event } )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
|
||||
@@ -396,7 +396,7 @@ end
|
||||
-- @param #DATABASE self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function DATABASE:_EventOnDeadOrCrash( Event )
|
||||
self:F( { Event } )
|
||||
self:F2( { Event } )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
if self.DCSUnits[Event.IniDCSUnitName] then
|
||||
@@ -410,7 +410,7 @@ end
|
||||
-- @param #DATABASE self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function DATABASE:_EventOnPlayerEnterUnit( Event )
|
||||
self:F( { Event } )
|
||||
self:F2( { Event } )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
|
||||
@@ -427,7 +427,7 @@ end
|
||||
-- @param #DATABASE self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function DATABASE:_EventOnPlayerLeaveUnit( Event )
|
||||
self:F( { Event } )
|
||||
self:F2( { Event } )
|
||||
|
||||
if 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.
|
||||
-- @return #DATABASE self
|
||||
function DATABASE:ForEach( IteratorFunction, arg, Set )
|
||||
self:F( arg )
|
||||
self:F2( arg )
|
||||
|
||||
local function CoRoutine()
|
||||
local Count = 0
|
||||
@@ -467,7 +467,7 @@ function DATABASE:ForEach( IteratorFunction, arg, Set )
|
||||
local function Schedule()
|
||||
|
||||
local status, res = coroutine.resume( co )
|
||||
self:T( { status, res } )
|
||||
self:T2( { status, res } )
|
||||
|
||||
if status == false then
|
||||
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.
|
||||
-- @return #DATABASE self
|
||||
function DATABASE:ForEachDCSUnit( IteratorFunction, ... )
|
||||
self:F( arg )
|
||||
self:F2( arg )
|
||||
|
||||
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.
|
||||
-- @return #DATABASE self
|
||||
function DATABASE:ForEachPlayer( IteratorFunction, ... )
|
||||
self:F( arg )
|
||||
self:F2( arg )
|
||||
|
||||
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.
|
||||
-- @return #DATABASE self
|
||||
function DATABASE:ForEachClient( IteratorFunction, ... )
|
||||
self:F( arg )
|
||||
self:F2( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self.CLIENTS )
|
||||
|
||||
@@ -524,7 +524,7 @@ end
|
||||
|
||||
|
||||
function DATABASE:ScanEnvironment()
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
self.Navpoints = {}
|
||||
self.UNITS = {}
|
||||
@@ -574,7 +574,7 @@ function DATABASE:ScanEnvironment()
|
||||
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
|
||||
self:_RegisterGroup( GroupTemplate )
|
||||
self:_RegisterTemplate( GroupTemplate )
|
||||
end --if GroupTemplate and GroupTemplate.units then
|
||||
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
|
||||
@@ -598,13 +598,13 @@ end
|
||||
-- @param DCSUnit#Unit DCSUnit
|
||||
-- @return #DATABASE self
|
||||
function DATABASE:_IsIncludeDCSUnit( DCSUnit )
|
||||
self:F( DCSUnit )
|
||||
self:F2( DCSUnit )
|
||||
local DCSUnitInclude = true
|
||||
|
||||
if self.Filter.Coalitions then
|
||||
local DCSUnitCoalition = false
|
||||
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
|
||||
DCSUnitCoalition = true
|
||||
end
|
||||
@@ -615,7 +615,7 @@ function DATABASE:_IsIncludeDCSUnit( DCSUnit )
|
||||
if self.Filter.Categories then
|
||||
local DCSUnitCategory = false
|
||||
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
|
||||
DCSUnitCategory = true
|
||||
end
|
||||
@@ -626,7 +626,7 @@ function DATABASE:_IsIncludeDCSUnit( DCSUnit )
|
||||
if self.Filter.Types then
|
||||
local DCSUnitType = false
|
||||
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
|
||||
DCSUnitType = true
|
||||
end
|
||||
@@ -637,7 +637,7 @@ function DATABASE:_IsIncludeDCSUnit( DCSUnit )
|
||||
if self.Filter.Countries then
|
||||
local DCSUnitCountry = false
|
||||
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
|
||||
DCSUnitCountry = true
|
||||
end
|
||||
@@ -648,7 +648,7 @@ function DATABASE:_IsIncludeDCSUnit( DCSUnit )
|
||||
if self.Filter.UnitPrefixes then
|
||||
local DCSUnitPrefix = false
|
||||
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
|
||||
DCSUnitPrefix = true
|
||||
end
|
||||
@@ -656,7 +656,7 @@ function DATABASE:_IsIncludeDCSUnit( DCSUnit )
|
||||
DCSUnitInclude = DCSUnitInclude and DCSUnitPrefix
|
||||
end
|
||||
|
||||
self:T( DCSUnitInclude )
|
||||
self:T2( DCSUnitInclude )
|
||||
return DCSUnitInclude
|
||||
end
|
||||
|
||||
@@ -665,14 +665,14 @@ end
|
||||
-- @param DCSUnit#Unit DCSUnit
|
||||
-- @return #DATABASE self
|
||||
function DATABASE:_IsAliveDCSUnit( DCSUnit )
|
||||
self:F( DCSUnit )
|
||||
self:F2( DCSUnit )
|
||||
local DCSUnitAlive = false
|
||||
if DCSUnit and DCSUnit:isExist() and DCSUnit:isActive() then
|
||||
if self.DCSUnits[DCSUnit:getName()] then
|
||||
DCSUnitAlive = true
|
||||
end
|
||||
end
|
||||
self:T( DCSUnitAlive )
|
||||
self:T2( DCSUnitAlive )
|
||||
return DCSUnitAlive
|
||||
end
|
||||
|
||||
@@ -681,25 +681,15 @@ end
|
||||
-- @param DCSGroup#Group DCSGroup
|
||||
-- @return #DATABASE self
|
||||
function DATABASE:_IsAliveDCSGroup( DCSGroup )
|
||||
self:F( DCSGroup )
|
||||
self:F2( DCSGroup )
|
||||
local DCSGroupAlive = false
|
||||
if DCSGroup and DCSGroup:isExist() then
|
||||
if self.DCSGroups[DCSGroup:getName()] then
|
||||
DCSGroupAlive = true
|
||||
end
|
||||
end
|
||||
self:T( DCSGroupAlive )
|
||||
self:T2( DCSGroupAlive )
|
||||
return DCSGroupAlive
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ local _EVENTCODES = {
|
||||
|
||||
function EVENT:New()
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
self:F()
|
||||
self:F2()
|
||||
self.EventHandler = world.addEventHandler( self )
|
||||
return self
|
||||
end
|
||||
@@ -154,7 +154,7 @@ end
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnBirthForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
self:F2( EventTemplate.name )
|
||||
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnBirthForUnit )
|
||||
|
||||
@@ -167,7 +167,7 @@ end
|
||||
-- @param Base#BASE EventSelf
|
||||
-- @return #EVENT
|
||||
function EVENT:OnBirth( EventFunction, EventSelf )
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_BIRTH )
|
||||
|
||||
@@ -181,7 +181,7 @@ end
|
||||
-- @param Base#BASE EventSelf
|
||||
-- @return #EVENT
|
||||
function EVENT:OnBirthForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnCrashForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
self:F2( EventTemplate.name )
|
||||
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnCrashForUnit )
|
||||
|
||||
@@ -208,7 +208,7 @@ end
|
||||
-- @param Base#BASE EventSelf
|
||||
-- @return #EVENT
|
||||
function EVENT:OnCrash( EventFunction, EventSelf )
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnCrashForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnDeadForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
self:F2( EventTemplate.name )
|
||||
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnDeadForUnit )
|
||||
|
||||
@@ -249,7 +249,7 @@ end
|
||||
-- @param Base#BASE EventSelf
|
||||
-- @return #EVENT
|
||||
function EVENT:OnDead( EventFunction, EventSelf )
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnDeadForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnPilotDeadForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnLandForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
self:F2( EventTemplate.name )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnLandForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnTakeOffForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
self:F2( EventTemplate.name )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnTakeOffForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEngineShutDownForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
self:F2( EventTemplate.name )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEngineShutDownForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEngineStartUpForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnShot( EventFunction, EventSelf )
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnShotForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnHit( EventFunction, EventSelf )
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnHitForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnPlayerEnterUnit( EventFunction, EventSelf )
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
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.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnPlayerLeaveUnit( EventFunction, EventSelf )
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_PLAYER_LEAVE_UNIT )
|
||||
|
||||
@@ -466,7 +466,7 @@ end
|
||||
|
||||
|
||||
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 Event.initiator and Event.initiator:getCategory() == Object.Category.UNIT then
|
||||
|
||||
@@ -198,6 +198,23 @@ function GROUP:GetCoalition()
|
||||
return nil
|
||||
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.
|
||||
-- @param #GROUP self
|
||||
-- @return #string The DCS Group name.
|
||||
|
||||
327
Moose Development/Moose/GroupSet.lua
Normal file
327
Moose Development/Moose/GroupSet.lua
Normal 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
|
||||
|
||||
|
||||
@@ -75,66 +75,10 @@ Include.File( "Client" )
|
||||
-- @extends Base#BASE
|
||||
SET = {
|
||||
ClassName = "SET",
|
||||
Templates = {
|
||||
Units = {},
|
||||
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,
|
||||
},
|
||||
},
|
||||
Set = {},
|
||||
Database = {},
|
||||
}
|
||||
|
||||
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.
|
||||
-- @param #SET self
|
||||
-- @return #SET
|
||||
@@ -146,21 +90,7 @@ function SET:New( Database )
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
|
||||
_EVENTDISPATCHER:OnBirth( self._EventOnBirth, self )
|
||||
_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()
|
||||
self.Database = Database
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -190,7 +120,7 @@ end
|
||||
-- @return #SET self
|
||||
function SET:_FilterStart()
|
||||
|
||||
for ObjectName, Object in pairs( self.Collection ) do
|
||||
for ObjectName, Object in pairs( self.Database ) do
|
||||
|
||||
if self:IsIncludeObject( Object ) then
|
||||
self:E( { "Adding Object:", ObjectName } )
|
||||
@@ -198,43 +128,53 @@ function SET:_FilterStart()
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Private method that registers all alive players in the mission.
|
||||
-- @param #SET self
|
||||
-- @return #SET self
|
||||
function SET:_RegisterPlayers()
|
||||
|
||||
local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) }
|
||||
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
|
||||
for UnitId, UnitData in pairs( CoalitionData ) do
|
||||
self:T3( { "UnitData:", UnitData } )
|
||||
if UnitData and UnitData:isExist() then
|
||||
local UnitName = UnitData:getName()
|
||||
if not self.PlayersAlive[UnitName] then
|
||||
self:E( { "Add player for unit:", UnitName, UnitData:getPlayerName() } )
|
||||
self.PlayersAlive[UnitName] = UnitData:getPlayerName()
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
|
||||
----- Private method that registers all alive players in the mission.
|
||||
---- @param #SET self
|
||||
---- @return #SET self
|
||||
--function SET:_RegisterPlayers()
|
||||
--
|
||||
-- local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) }
|
||||
-- for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
|
||||
-- for UnitId, UnitData in pairs( CoalitionData ) do
|
||||
-- self:T3( { "UnitData:", UnitData } )
|
||||
-- if UnitData and UnitData:isExist() then
|
||||
-- local UnitName = UnitData:getName()
|
||||
-- if not self.PlayersAlive[UnitName] then
|
||||
-- self:E( { "Add player for unit:", UnitName, UnitData:getPlayerName() } )
|
||||
-- self.PlayersAlive[UnitName] = UnitData:getPlayerName()
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
-- return self
|
||||
--end
|
||||
|
||||
--- Events
|
||||
|
||||
--- Handles the OnBirth event for the Set.
|
||||
-- @param #SET self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function SET:_EventOnBirth( Event )
|
||||
self:F( { Event } )
|
||||
self:F3( { Event } )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
local ObjectName, Object = self:AddInDatabase( Event )
|
||||
self:T3( ObjectName, Object )
|
||||
if self:IsIncludeObject( Object ) then
|
||||
self:_Add( ObjectName, Object )
|
||||
--self:_EventOnPlayerEnterUnit( Event )
|
||||
@@ -246,7 +186,7 @@ end
|
||||
-- @param #SET self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function SET:_EventOnDeadOrCrash( Event )
|
||||
self:F( { Event } )
|
||||
self:F3( { Event } )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
local ObjectName, Object = self:FindInDatabase( Event )
|
||||
@@ -260,7 +200,7 @@ end
|
||||
---- @param #SET self
|
||||
---- @param Event#EVENTDATA Event
|
||||
--function SET:_EventOnPlayerEnterUnit( Event )
|
||||
-- self:F( { Event } )
|
||||
-- self:F3( { Event } )
|
||||
--
|
||||
-- if Event.IniDCSUnit then
|
||||
-- if self:IsIncludeObject( Event.IniDCSUnit ) then
|
||||
@@ -277,7 +217,7 @@ end
|
||||
---- @param #SET self
|
||||
---- @param Event#EVENTDATA Event
|
||||
--function SET:_EventOnPlayerLeaveUnit( Event )
|
||||
-- self:F( { Event } )
|
||||
-- self:F3( { Event } )
|
||||
--
|
||||
-- if 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.
|
||||
-- @return #SET self
|
||||
function SET:ForEach( IteratorFunction, arg, Set )
|
||||
self:F( arg )
|
||||
self:F3( arg )
|
||||
|
||||
local function CoRoutine()
|
||||
local Count = 0
|
||||
@@ -317,7 +257,7 @@ function SET:ForEach( IteratorFunction, arg, Set )
|
||||
local function Schedule()
|
||||
|
||||
local status, res = coroutine.resume( co )
|
||||
self:T( { status, res } )
|
||||
self:T3( { status, res } )
|
||||
|
||||
if status == false then
|
||||
error( res )
|
||||
@@ -335,42 +275,42 @@ function SET:ForEach( IteratorFunction, arg, Set )
|
||||
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, ... )
|
||||
self:F( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self.DCSUnitsAlive )
|
||||
|
||||
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, ... )
|
||||
self:F( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self.PlayersAlive )
|
||||
|
||||
return self
|
||||
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, ... )
|
||||
self:F( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self.Clients )
|
||||
|
||||
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, ... )
|
||||
-- self:F3( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.DCSUnitsAlive )
|
||||
--
|
||||
-- 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, ... )
|
||||
-- self:F3( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.PlayersAlive )
|
||||
--
|
||||
-- return self
|
||||
--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, ... )
|
||||
-- self:F3( arg )
|
||||
--
|
||||
-- self:ForEach( IteratorFunction, arg, self.Clients )
|
||||
--
|
||||
-- return self
|
||||
--end
|
||||
|
||||
|
||||
--- Decides whether to include the Object
|
||||
@@ -378,53 +318,22 @@ end
|
||||
-- @param #table Object
|
||||
-- @return #SET self
|
||||
function SET:IsIncludeObject( Object )
|
||||
self:F( Object )
|
||||
self:F3( Object )
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
--- Flushes the current SET contents in the log ... (for debug reasons).
|
||||
-- @param #SET self
|
||||
-- @param DCSUnit#Unit DCSUnit
|
||||
-- @return #SET self
|
||||
function SET:_IsAliveDCSUnit( DCSUnit )
|
||||
self:F( DCSUnit )
|
||||
local DCSUnitAlive = false
|
||||
if DCSUnit and DCSUnit:isExist() and DCSUnit:isActive() then
|
||||
if self.DCSUnits[DCSUnit:getName()] then
|
||||
DCSUnitAlive = true
|
||||
end
|
||||
function SET:Flush()
|
||||
self:F3()
|
||||
|
||||
local ObjectNames = ""
|
||||
for ObjectName, Object in pairs( self.Set ) do
|
||||
ObjectNames = ObjectNames .. ObjectName .. ", "
|
||||
end
|
||||
self:T( DCSUnitAlive )
|
||||
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 } )
|
||||
self:T( { "Objects in Set:", ObjectNames } )
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -10,12 +10,6 @@
|
||||
-- * 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.
|
||||
--
|
||||
-- UNITSET construction methods:
|
||||
-- =================================
|
||||
-- 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.ForEachUnitInZone}: Calls a function for each unit within a certain zone contained within the UNITSET.
|
||||
--
|
||||
-- @module Set
|
||||
-- @module UnitSet
|
||||
-- @author FlightControl
|
||||
|
||||
Include.File( "Routines" )
|
||||
Include.File( "Base" )
|
||||
Include.File( "Menu" )
|
||||
Include.File( "Group" )
|
||||
Include.File( "Unit" )
|
||||
Include.File( "Event" )
|
||||
Include.File( "Client" )
|
||||
Include.File( "Set" )
|
||||
|
||||
|
||||
--- 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.
|
||||
-- @param #UNITSET self
|
||||
@@ -122,42 +98,25 @@ local _DATABASECategory =
|
||||
function UNITSET:New()
|
||||
|
||||
-- Inherits from BASE
|
||||
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()
|
||||
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.Units[UnitName]
|
||||
local UnitFound = self.Set[UnitName]
|
||||
return UnitFound
|
||||
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 coalitons.
|
||||
--- 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".
|
||||
@@ -252,23 +211,6 @@ function UNITSET:FilterPrefixes( Prefixes )
|
||||
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.
|
||||
@@ -277,173 +219,78 @@ end
|
||||
function UNITSET:FilterStart()
|
||||
|
||||
if _DATABASE then
|
||||
self:_FilterStart( self.DatabaseCollection )
|
||||
self:_FilterStart()
|
||||
end
|
||||
|
||||
FollowEventBirth( )
|
||||
|
||||
_EVENTDISPATCHER:OnBirth( self._EventOnBirth, self )
|
||||
_EVENTDISPATCHER:OnDead( self._EventOnDeadOrCrash, self )
|
||||
_EVENTDISPATCHER:OnCrash( self._EventOnDeadOrCrash, self )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Events
|
||||
|
||||
--- Handles the OnBirth event for the alive units set.
|
||||
--- 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
|
||||
function UNITSET:_EventOnBirth( Event )
|
||||
self:F( { Event } )
|
||||
-- @return #string The name of the UNIT
|
||||
-- @return #table The UNIT
|
||||
function UNITSET:AddInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
if self:_IsIncludeUnit( Event.IniDCSUnit ) then
|
||||
self.DCSUnits[Event.IniDCSUnitName] = Event.IniDCSUnit
|
||||
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
|
||||
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 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 Event#EVENTDATA Event
|
||||
function UNITSET:_EventOnDeadOrCrash( Event )
|
||||
self:F( { Event } )
|
||||
-- @return #string The name of the UNIT
|
||||
-- @return #table The UNIT
|
||||
function UNITSET:FindInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
if self.DCSUnitsAlive[Event.IniDCSUnitName] then
|
||||
self.DCSUnits[Event.IniDCSUnitName] = nil
|
||||
self.DCSUnitsAlive[Event.IniDCSUnitName] = nil
|
||||
end
|
||||
end
|
||||
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
|
||||
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 Event#EVENTDATA Event
|
||||
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.
|
||||
-- @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:ForEach( IteratorFunction, arg, Set )
|
||||
self:F( arg )
|
||||
function UNITSET:ForEachUnit( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
local function CoRoutine()
|
||||
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
|
||||
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:ForEachDCSUnitAlive( IteratorFunction, ... )
|
||||
self:F( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self.DCSUnitsAlive )
|
||||
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:F( 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:F( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self.Clients )
|
||||
|
||||
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
|
||||
|
||||
|
||||
---
|
||||
@@ -451,13 +298,13 @@ end
|
||||
-- @param Unit#UNIT MUnit
|
||||
-- @return #UNITSET self
|
||||
function UNITSET:IsIncludeObject( MUnit )
|
||||
self:F( 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: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
|
||||
MUnitCoalition = true
|
||||
end
|
||||
@@ -468,7 +315,7 @@ function UNITSET:IsIncludeObject( MUnit )
|
||||
if self.Filter.Categories then
|
||||
local MUnitCategory = false
|
||||
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
|
||||
MUnitCategory = true
|
||||
end
|
||||
@@ -479,7 +326,7 @@ function UNITSET:IsIncludeObject( MUnit )
|
||||
if self.Filter.Types then
|
||||
local MUnitType = false
|
||||
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
|
||||
MUnitType = true
|
||||
end
|
||||
@@ -490,7 +337,7 @@ function UNITSET:IsIncludeObject( MUnit )
|
||||
if self.Filter.Countries then
|
||||
local MUnitCountry = false
|
||||
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
|
||||
MUnitCountry = true
|
||||
end
|
||||
@@ -501,7 +348,7 @@ function UNITSET:IsIncludeObject( MUnit )
|
||||
if self.Filter.UnitPrefixes then
|
||||
local MUnitPrefix = false
|
||||
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
|
||||
MUnitPrefix = true
|
||||
end
|
||||
@@ -509,7 +356,7 @@ function UNITSET:IsIncludeObject( MUnit )
|
||||
MUnitInclude = MUnitInclude and MUnitPrefix
|
||||
end
|
||||
|
||||
self:T( MUnitInclude )
|
||||
self:T2( MUnitInclude )
|
||||
return MUnitInclude
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user