mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Static
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
|
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
|
||||||
env.info( 'Moose Generation Timestamp: 20170629_1459' )
|
env.info( 'Moose Generation Timestamp: 20170630_1038' )
|
||||||
|
|
||||||
--- Various routines
|
--- Various routines
|
||||||
-- @module routines
|
-- @module routines
|
||||||
@@ -2824,10 +2824,6 @@ end
|
|||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
-- The @{#BASE} class is the core root class from where every other class in moose is derived.
|
|
||||||
--
|
|
||||||
-- ===
|
|
||||||
--
|
|
||||||
-- ### Author: **Sven Van de Velde (FlightControl)**
|
-- ### Author: **Sven Van de Velde (FlightControl)**
|
||||||
-- ### Contributions:
|
-- ### Contributions:
|
||||||
--
|
--
|
||||||
@@ -8216,7 +8212,12 @@ function DATABASE:Spawn( SpawnTemplate )
|
|||||||
SpawnTemplate.CountryID = SpawnCountryID
|
SpawnTemplate.CountryID = SpawnCountryID
|
||||||
SpawnTemplate.CategoryID = SpawnCategoryID
|
SpawnTemplate.CategoryID = SpawnCategoryID
|
||||||
|
|
||||||
|
-- Ensure that for the spawned group and its units, there are GROUP and UNIT objects created in the DATABASE.
|
||||||
local SpawnGroup = self:AddGroup( SpawnTemplate.name )
|
local SpawnGroup = self:AddGroup( SpawnTemplate.name )
|
||||||
|
for UnitID, UnitData in pairs( SpawnTemplate.units ) do
|
||||||
|
self:AddUnit( UnitData.name )
|
||||||
|
end
|
||||||
|
|
||||||
return SpawnGroup
|
return SpawnGroup
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -12189,6 +12190,14 @@ do -- COORDINATE
|
|||||||
return RandomVec3
|
return RandomVec3
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Return the height of the land at the coordinate.
|
||||||
|
-- @param #COORDINATE self
|
||||||
|
-- @return #number
|
||||||
|
function COORDINATE:GetLandHeight()
|
||||||
|
local Vec2 = { x = self.x, y = self.z }
|
||||||
|
return land.getHeight( Vec2 )
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function COORDINATE:SetHeading( Heading )
|
function COORDINATE:SetHeading( Heading )
|
||||||
self.Heading = Heading
|
self.Heading = Heading
|
||||||
@@ -23403,6 +23412,7 @@ function AIRBASE:Register( AirbaseName )
|
|||||||
|
|
||||||
local self = BASE:Inherit( self, POSITIONABLE:New( AirbaseName ) )
|
local self = BASE:Inherit( self, POSITIONABLE:New( AirbaseName ) )
|
||||||
self.AirbaseName = AirbaseName
|
self.AirbaseName = AirbaseName
|
||||||
|
self.AirbaseZone = ZONE_RADIUS:New( AirbaseName, self:GetVec2(), 8000 )
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -23439,6 +23449,13 @@ function AIRBASE:GetDCSObject()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get the airbase zone.
|
||||||
|
-- @param #AIRBASE self
|
||||||
|
-- @return Core.Zone#ZONE_RADIUS The zone radius of the airbase.
|
||||||
|
function AIRBASE:GetZone()
|
||||||
|
return self.AirbaseZone
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- **Wrapper** -- SCENERY models scenery within the DCS simulator.
|
--- **Wrapper** -- SCENERY models scenery within the DCS simulator.
|
||||||
@@ -25264,57 +25281,100 @@ end
|
|||||||
|
|
||||||
--- **Functional** -- The CLEANUP class keeps an area clean of crashing or colliding airplanes. It also prevents airplanes from firing within this area.
|
--- **Functional** -- The CLEANUP class keeps an area clean of crashing or colliding airplanes. It also prevents airplanes from firing within this area.
|
||||||
--
|
--
|
||||||
|
-- 
|
||||||
|
--
|
||||||
|
-- ===
|
||||||
|
--
|
||||||
|
-- ### Author: **Sven Van de Velde (FlightControl)**
|
||||||
|
-- ### Contributions:
|
||||||
|
--
|
||||||
-- ====
|
-- ====
|
||||||
|
--
|
||||||
-- @module CleanUp
|
-- @module CleanUp
|
||||||
|
|
||||||
|
|
||||||
|
--- @type CLEANUP
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- The CLEANUP class.
|
|
||||||
-- @type CLEANUP
|
|
||||||
-- @extends Core.Base#BASE
|
-- @extends Core.Base#BASE
|
||||||
|
-- @field #map<#string,Wrapper.Airbase#AIRBASE> Airbases Map of Airbases.
|
||||||
|
|
||||||
|
--- # CLEANUP, extends @{Base#BASE}
|
||||||
|
--
|
||||||
|
-- The CLEANUP class keeps airbases clean, and tries to guarantee continuous airbase operations, even under combat.
|
||||||
|
--
|
||||||
|
-- @field #CLEANUP
|
||||||
CLEANUP = {
|
CLEANUP = {
|
||||||
ClassName = "CLEANUP",
|
ClassName = "CLEANUP",
|
||||||
ZoneNames = {},
|
TimeInterval = 0.2,
|
||||||
TimeInterval = 300,
|
|
||||||
CleanUpList = {},
|
CleanUpList = {},
|
||||||
|
Airbases = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Creates the main object which is handling the cleaning of the debris within the given Zone Names.
|
--- Creates the main object which is handling the cleaning of the debris within the given Zone Names.
|
||||||
-- @param #CLEANUP self
|
-- @param #CLEANUP self
|
||||||
-- @param #table ZoneNames Is a table of zone names where the debris should be cleaned. Also a single string can be passed with one zone name.
|
-- @param #list<#string> AirbaseNames Is a table of airbase names where the debris should be cleaned. Also a single string can be passed with one airbase name.
|
||||||
-- @param #number TimeInterval The interval in seconds when the clean activity takes place. The default is 300 seconds, thus every 5 minutes.
|
|
||||||
-- @return #CLEANUP
|
-- @return #CLEANUP
|
||||||
-- @usage
|
-- @usage
|
||||||
-- -- Clean these Zones.
|
-- -- Clean these Zones.
|
||||||
-- CleanUpAirports = CLEANUP:New( { 'CLEAN Tbilisi', 'CLEAN Kutaisi' }, 150 )
|
-- CleanUpAirports = CLEANUP:New( { AIRBASE.Caucasus.Tbilisi, AIRBASE.Caucasus.Kutaisi )
|
||||||
-- or
|
-- or
|
||||||
-- CleanUpTbilisi = CLEANUP:New( 'CLEAN Tbilisi', 150 )
|
-- CleanUpTbilisi = CLEANUP:New( AIRBASE.Caucasus.Tbilisi )
|
||||||
-- CleanUpKutaisi = CLEANUP:New( 'CLEAN Kutaisi', 600 )
|
-- CleanUpKutaisi = CLEANUP:New( AIRBASE.Caucasus.Kutaisi )
|
||||||
function CLEANUP:New( ZoneNames, TimeInterval )
|
function CLEANUP:New( AirbaseNames )
|
||||||
|
|
||||||
local self = BASE:Inherit( self, BASE:New() ) -- #CLEANUP
|
local self = BASE:Inherit( self, BASE:New() ) -- #CLEANUP
|
||||||
self:F( { ZoneNames, TimeInterval } )
|
self:F( { AirbaseNames } )
|
||||||
|
|
||||||
if type( ZoneNames ) == 'table' then
|
if type( AirbaseNames ) == 'table' then
|
||||||
self.ZoneNames = ZoneNames
|
for AirbaseID, AirbaseName in pairs( AirbaseNames ) do
|
||||||
|
self:AddAirbase( AirbaseName )
|
||||||
|
end
|
||||||
else
|
else
|
||||||
self.ZoneNames = { ZoneNames }
|
local AirbaseName = AirbaseNames
|
||||||
end
|
self:AddAirbase( AirbaseName )
|
||||||
if TimeInterval then
|
|
||||||
self.TimeInterval = TimeInterval
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self:HandleEvent( EVENTS.Birth )
|
self:HandleEvent( EVENTS.Birth )
|
||||||
|
|
||||||
self.CleanUpScheduler = SCHEDULER:New( self, self._CleanUpScheduler, {}, 1, TimeInterval )
|
self.CleanUpScheduler = SCHEDULER:New( self, self._CleanUpScheduler, {}, 1, self.TimeInterval )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Adds an airbase to the airbase validation list.
|
||||||
|
-- @param #CLEANUP self
|
||||||
|
-- @param #string AirbaseName
|
||||||
|
-- @return #CLEANUP
|
||||||
|
function CLEANUP:AddAirbase( AirbaseName )
|
||||||
|
self.Airbases[AirbaseName] = AIRBASE:FindByName( AirbaseName )
|
||||||
|
self:F({"Airbase:", AirbaseName, self.Airbases[AirbaseName]:GetDesc()})
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Removes an airbase from the airbase validation list.
|
||||||
|
-- @param #CLEANUP self
|
||||||
|
-- @param #string AirbaseName
|
||||||
|
-- @return #CLEANUP
|
||||||
|
function CLEANUP:RemoveAirbase( AirbaseName )
|
||||||
|
self.Airbases[AirbaseName] = nil
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function CLEANUP:IsInAirbase( Vec2 )
|
||||||
|
|
||||||
|
local InAirbase = false
|
||||||
|
for AirbaseName, Airbase in pairs( self.Airbases ) do
|
||||||
|
local Airbase = Airbase -- Wrapper.Airbase#AIRBASE
|
||||||
|
if Airbase:GetZone():IsVec2InZone( Vec2 ) then
|
||||||
|
InAirbase = true
|
||||||
|
break;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return InAirbase
|
||||||
|
end
|
||||||
|
|
||||||
--- Destroys a group from the simulator, but checks first if it is still existing!
|
--- Destroys a group from the simulator, but checks first if it is still existing!
|
||||||
-- @param #CLEANUP self
|
-- @param #CLEANUP self
|
||||||
@@ -25329,29 +25389,25 @@ function CLEANUP:_DestroyGroup( GroupObject, CleanUpGroupName )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Destroys a @{DCSWrapper.Unit#Unit} from the simulator, but checks first if it is still existing!
|
--- Destroys a @{Unit} from the simulator, but checks first if it is still existing!
|
||||||
-- @param #CLEANUP self
|
-- @param #CLEANUP self
|
||||||
-- @param Dcs.DCSWrapper.Unit#Unit CleanUpUnit The object to be destroyed.
|
-- @param Wrapper.Unit#UNIT CleanUpUnit The object to be destroyed.
|
||||||
-- @param #string CleanUpUnitName The Unit name ...
|
function CLEANUP:_DestroyUnit( CleanUpUnit )
|
||||||
function CLEANUP:_DestroyUnit( CleanUpUnit, CleanUpUnitName )
|
self:F( { CleanUpUnit } )
|
||||||
self:F( { CleanUpUnit, CleanUpUnitName } )
|
|
||||||
|
|
||||||
if CleanUpUnit then
|
if CleanUpUnit then
|
||||||
local CleanUpGroup = Unit.getGroup(CleanUpUnit)
|
local CleanUpUnitName = CleanUpUnit:GetName()
|
||||||
|
local CleanUpGroup = CleanUpUnit:GetGroup()
|
||||||
-- TODO Client bug in 1.5.3
|
-- TODO Client bug in 1.5.3
|
||||||
if CleanUpGroup and CleanUpGroup:isExist() then
|
if CleanUpGroup:IsAlive() then
|
||||||
local CleanUpGroupUnits = CleanUpGroup:getUnits()
|
local CleanUpGroupUnits = CleanUpGroup:GetUnits()
|
||||||
if #CleanUpGroupUnits == 1 then
|
if #CleanUpGroupUnits == 1 then
|
||||||
local CleanUpGroupName = CleanUpGroup:getName()
|
local CleanUpGroupName = CleanUpGroup:GetName()
|
||||||
--self:CreateEventCrash( timer.getTime(), CleanUpUnit )
|
CleanUpGroup:Destroy()
|
||||||
CleanUpGroup:destroy()
|
|
||||||
self:T( { "Destroyed Group:", CleanUpGroupName } )
|
|
||||||
else
|
else
|
||||||
CleanUpUnit:destroy()
|
CleanUpUnit:Destroy()
|
||||||
self:T( { "Destroyed Unit:", CleanUpUnitName } )
|
|
||||||
end
|
end
|
||||||
self.CleanUpList[CleanUpUnitName] = nil -- Cleaning from the list
|
self.CleanUpList[CleanUpUnitName] = nil
|
||||||
CleanUpUnit = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -25371,7 +25427,7 @@ end
|
|||||||
|
|
||||||
--- @param #CLEANUP self
|
--- @param #CLEANUP self
|
||||||
-- @param Core.Event#EVENTDATA EventData
|
-- @param Core.Event#EVENTDATA EventData
|
||||||
function CLEANUP:_OnEventBirth( EventData )
|
function CLEANUP:OnEventBirth( EventData )
|
||||||
self:F( { EventData } )
|
self:F( { EventData } )
|
||||||
|
|
||||||
self.CleanUpList[EventData.IniDCSUnitName] = {}
|
self.CleanUpList[EventData.IniDCSUnitName] = {}
|
||||||
@@ -25380,13 +25436,13 @@ function CLEANUP:_OnEventBirth( EventData )
|
|||||||
self.CleanUpList[EventData.IniDCSUnitName].CleanUpGroupName = EventData.IniDCSGroupName
|
self.CleanUpList[EventData.IniDCSUnitName].CleanUpGroupName = EventData.IniDCSGroupName
|
||||||
self.CleanUpList[EventData.IniDCSUnitName].CleanUpUnitName = EventData.IniDCSUnitName
|
self.CleanUpList[EventData.IniDCSUnitName].CleanUpUnitName = EventData.IniDCSUnitName
|
||||||
|
|
||||||
EventData.IniUnit:HandleEvent( EVENTS.EngineShutdown , self._EventAddForCleanUp )
|
self:HandleEvent( EVENTS.EngineShutdown , self._EventAddForCleanUp )
|
||||||
EventData.IniUnit:HandleEvent( EVENTS.EngineStartup, self._EventAddForCleanUp )
|
self:HandleEvent( EVENTS.EngineStartup, self._EventAddForCleanUp )
|
||||||
EventData.IniUnit:HandleEvent( EVENTS.Hit, self._EventAddForCleanUp )
|
self:HandleEvent( EVENTS.Hit, self._EventAddForCleanUp )
|
||||||
EventData.IniUnit:HandleEvent( EVENTS.PilotDead, self._EventCrash )
|
self:HandleEvent( EVENTS.PilotDead, self.OnEventCrash )
|
||||||
EventData.IniUnit:HandleEvent( EVENTS.Dead, self._EventCrash )
|
self:HandleEvent( EVENTS.Dead, self.OnEventCrash )
|
||||||
EventData.IniUnit:HandleEvent( EVENTS.Crash, self._EventCrash )
|
self:HandleEvent( EVENTS.Crash, self.OnEventCrash )
|
||||||
EventData.IniUnit:HandleEvent( EVENTS.Shot, self._EventShot )
|
self:HandleEvent( EVENTS.Shot, self.OnEventShot )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -25394,7 +25450,7 @@ end
|
|||||||
-- Crashed units go into a CleanUpList for removal.
|
-- Crashed units go into a CleanUpList for removal.
|
||||||
-- @param #CLEANUP self
|
-- @param #CLEANUP self
|
||||||
-- @param Dcs.DCSTypes#Event event
|
-- @param Dcs.DCSTypes#Event event
|
||||||
function CLEANUP:_EventCrash( Event )
|
function CLEANUP:OnEventCrash( Event )
|
||||||
self:F( { Event } )
|
self:F( { Event } )
|
||||||
|
|
||||||
--TODO: This stuff is not working due to a DCS bug. Burning units cannot be destroyed.
|
--TODO: This stuff is not working due to a DCS bug. Burning units cannot be destroyed.
|
||||||
@@ -25405,54 +25461,53 @@ function CLEANUP:_EventCrash( Event )
|
|||||||
-- self:T("after deactivateGroup")
|
-- self:T("after deactivateGroup")
|
||||||
-- event.initiator:destroy()
|
-- event.initiator:destroy()
|
||||||
|
|
||||||
self.CleanUpList[Event.IniDCSUnitName] = {}
|
if Event.IniDCSUnitName then
|
||||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpUnit = Event.IniDCSUnit
|
self.CleanUpList[Event.IniDCSUnitName] = {}
|
||||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpGroup = Event.IniDCSGroup
|
self.CleanUpList[Event.IniDCSUnitName].CleanUpUnit = Event.IniDCSUnit
|
||||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpGroupName = Event.IniDCSGroupName
|
self.CleanUpList[Event.IniDCSUnitName].CleanUpGroup = Event.IniDCSGroup
|
||||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpUnitName = Event.IniDCSUnitName
|
self.CleanUpList[Event.IniDCSUnitName].CleanUpGroupName = Event.IniDCSGroupName
|
||||||
|
self.CleanUpList[Event.IniDCSUnitName].CleanUpUnitName = Event.IniDCSUnitName
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Detects if a unit shoots a missile.
|
--- Detects if a unit shoots a missile.
|
||||||
-- If this occurs within one of the zones, then the weapon used must be destroyed.
|
-- If this occurs within one of the airbases, then the weapon used must be destroyed.
|
||||||
-- @param #CLEANUP self
|
-- @param #CLEANUP self
|
||||||
-- @param Dcs.DCSTypes#Event event
|
-- @param Core.Event#EVENTDATA Event
|
||||||
function CLEANUP:_EventShot( Event )
|
function CLEANUP:OnEventShot( Event )
|
||||||
self:F( { Event } )
|
self:F( { Event } )
|
||||||
|
|
||||||
-- Test if the missile was fired within one of the CLEANUP.ZoneNames.
|
-- Test if the missile was fired within one of the CLEANUP.AirbaseNames.
|
||||||
local CurrentLandingZoneID = 0
|
if self:IsInAirbase( Event.IniUnit:GetVec2() ) then
|
||||||
CurrentLandingZoneID = routines.IsUnitInZones( Event.IniDCSUnit, self.ZoneNames )
|
-- Okay, the missile was fired within the CLEANUP.AirbaseNames, destroy the fired weapon.
|
||||||
if ( CurrentLandingZoneID ) then
|
self:_DestroyMissile( Event.Weapon )
|
||||||
-- Okay, the missile was fired within the CLEANUP.ZoneNames, destroy the fired weapon.
|
|
||||||
--_SEADmissile:destroy()
|
|
||||||
SCHEDULER:New( self, CLEANUP._DestroyMissile, { Event.Weapon }, 0.1 )
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Detects if the Unit has an S_EVENT_HIT within the given ZoneNames. If this is the case, destroy the unit.
|
--- Detects if the Unit has an S_EVENT_HIT within the given AirbaseNames. If this is the case, destroy the unit.
|
||||||
-- @param #CLEANUP self
|
-- @param #CLEANUP self
|
||||||
-- @param Dcs.DCSTypes#Event event
|
-- @param Core.Event#EVENTDATA Event
|
||||||
function CLEANUP:_EventHitCleanUp( Event )
|
function CLEANUP:OnEventHit( Event )
|
||||||
self:F( { Event } )
|
self:F( { Event } )
|
||||||
|
|
||||||
if Event.IniDCSUnit then
|
if Event.IniUnit then
|
||||||
if routines.IsUnitInZones( Event.IniDCSUnit, self.ZoneNames ) ~= nil then
|
if self:IsInAirbase( Event.IniUnit:GetVec2() ) then
|
||||||
self:T( { "Life: ", Event.IniDCSUnitName, ' = ', Event.IniDCSUnit:getLife(), "/", Event.IniDCSUnit:getLife0() } )
|
self:T( { "Life: ", Event.IniDCSUnitName, ' = ', Event.IniDCSUnit:getLife(), "/", Event.IniDCSUnit:getLife0() } )
|
||||||
if Event.IniDCSUnit:getLife() < Event.IniDCSUnit:getLife0() then
|
if Event.IniDCSUnit:getLife() < Event.IniDCSUnit:getLife0() then
|
||||||
self:T( "CleanUp: Destroy: " .. Event.IniDCSUnitName )
|
self:T( "CleanUp: Destroy: " .. Event.IniDCSUnitName )
|
||||||
SCHEDULER:New( self, CLEANUP._DestroyUnit, { Event.IniDCSUnit }, 0.1 )
|
CLEANUP:_DestroyUnit( Event.IniUnit )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if Event.TgtDCSUnit then
|
if Event.TgtUnit then
|
||||||
if routines.IsUnitInZones( Event.TgtDCSUnit, self.ZoneNames ) ~= nil then
|
if self:IsInAirbase( Event.TgtUnit:GetVec2() ) then
|
||||||
self:T( { "Life: ", Event.TgtDCSUnitName, ' = ', Event.TgtDCSUnit:getLife(), "/", Event.TgtDCSUnit:getLife0() } )
|
self:T( { "Life: ", Event.TgtDCSUnitName, ' = ', Event.TgtDCSUnit:getLife(), "/", Event.TgtDCSUnit:getLife0() } )
|
||||||
if Event.TgtDCSUnit:getLife() < Event.TgtDCSUnit:getLife0() then
|
if Event.TgtDCSUnit:getLife() < Event.TgtDCSUnit:getLife0() then
|
||||||
self:T( "CleanUp: Destroy: " .. Event.TgtDCSUnitName )
|
self:T( "CleanUp: Destroy: " .. Event.TgtDCSUnitName )
|
||||||
SCHEDULER:New( self, CLEANUP._DestroyUnit, { Event.TgtDCSUnit }, 0.1 )
|
CLEANUP:_DestroyUnit( Event.TgtUnit )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -25474,14 +25529,16 @@ function CLEANUP:_AddForCleanUp( CleanUpUnit, CleanUpUnitName )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Detects if the Unit has an S_EVENT_ENGINE_SHUTDOWN or an S_EVENT_HIT within the given ZoneNames. If this is the case, add the Group to the CLEANUP List.
|
--- Detects if the Unit has an S_EVENT_ENGINE_SHUTDOWN or an S_EVENT_HIT within the given AirbaseNames. If this is the case, add the Group to the CLEANUP List.
|
||||||
-- @param #CLEANUP self
|
-- @param #CLEANUP self
|
||||||
-- @param Dcs.DCSTypes#Event event
|
-- @param Core.Event#EVENTDATA Event
|
||||||
function CLEANUP:_EventAddForCleanUp( Event )
|
function CLEANUP:_EventAddForCleanUp( Event )
|
||||||
|
|
||||||
|
self:F({Event})
|
||||||
|
|
||||||
if Event.IniDCSUnit then
|
if Event.IniDCSUnit then
|
||||||
if self.CleanUpList[Event.IniDCSUnitName] == nil then
|
if self.CleanUpList[Event.IniDCSUnitName] == nil then
|
||||||
if routines.IsUnitInZones( Event.IniDCSUnit, self.ZoneNames ) ~= nil then
|
if self:IsInAirbase( Event.IniUnit:GetVec2() ) then
|
||||||
self:_AddForCleanUp( Event.IniDCSUnit, Event.IniDCSUnitName )
|
self:_AddForCleanUp( Event.IniDCSUnit, Event.IniDCSUnitName )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -25489,7 +25546,7 @@ function CLEANUP:_EventAddForCleanUp( Event )
|
|||||||
|
|
||||||
if Event.TgtDCSUnit then
|
if Event.TgtDCSUnit then
|
||||||
if self.CleanUpList[Event.TgtDCSUnitName] == nil then
|
if self.CleanUpList[Event.TgtDCSUnitName] == nil then
|
||||||
if routines.IsUnitInZones( Event.TgtDCSUnit, self.ZoneNames ) ~= nil then
|
if self:IsInAirbase( Event.TgtUnit:GetVec2() ) then
|
||||||
self:_AddForCleanUp( Event.TgtDCSUnit, Event.TgtDCSUnitName )
|
self:_AddForCleanUp( Event.TgtDCSUnit, Event.TgtDCSUnitName )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -25497,64 +25554,50 @@ function CLEANUP:_EventAddForCleanUp( Event )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local CleanUpSurfaceTypeText = {
|
|
||||||
"LAND",
|
|
||||||
"SHALLOW_WATER",
|
|
||||||
"WATER",
|
|
||||||
"ROAD",
|
|
||||||
"RUNWAY"
|
|
||||||
}
|
|
||||||
|
|
||||||
--- At the defined time interval, CleanUp the Groups within the CleanUpList.
|
--- At the defined time interval, CleanUp the Groups within the CleanUpList.
|
||||||
-- @param #CLEANUP self
|
-- @param #CLEANUP self
|
||||||
function CLEANUP:_CleanUpScheduler()
|
function CLEANUP:_CleanUpScheduler()
|
||||||
self:F( { "CleanUp Scheduler" } )
|
|
||||||
|
|
||||||
local CleanUpCount = 0
|
local CleanUpCount = 0
|
||||||
for CleanUpUnitName, UnitData in pairs( self.CleanUpList ) do
|
for CleanUpUnitName, UnitData in pairs( self.CleanUpList ) do
|
||||||
CleanUpCount = CleanUpCount + 1
|
CleanUpCount = CleanUpCount + 1
|
||||||
|
|
||||||
self:T( { CleanUpUnitName, UnitData } )
|
local CleanUpUnit = UNIT:FindByName( CleanUpUnitName )
|
||||||
local CleanUpUnit = Unit.getByName(UnitData.CleanUpUnitName)
|
local CleanUpDCSUnit = Unit.getByName( CleanUpUnitName )
|
||||||
local CleanUpGroupName = UnitData.CleanUpGroupName
|
local CleanUpGroupName = UnitData.CleanUpGroupName
|
||||||
local CleanUpUnitName = UnitData.CleanUpUnitName
|
|
||||||
if CleanUpUnit then
|
|
||||||
self:T( { "CleanUp Scheduler", "Checking:", CleanUpUnitName } )
|
|
||||||
if _DATABASE:GetStatusGroup( CleanUpGroupName ) ~= "ReSpawn" then
|
|
||||||
local CleanUpUnitVec3 = CleanUpUnit:getPoint()
|
|
||||||
--self:T( CleanUpUnitVec3 )
|
|
||||||
local CleanUpUnitVec2 = {}
|
|
||||||
CleanUpUnitVec2.x = CleanUpUnitVec3.x
|
|
||||||
CleanUpUnitVec2.y = CleanUpUnitVec3.z
|
|
||||||
--self:T( CleanUpUnitVec2 )
|
|
||||||
local CleanUpSurfaceType = land.getSurfaceType(CleanUpUnitVec2)
|
|
||||||
--self:T( CleanUpSurfaceType )
|
|
||||||
|
|
||||||
if CleanUpUnit and CleanUpUnit:getLife() <= CleanUpUnit:getLife0() * 0.95 then
|
if CleanUpUnit then
|
||||||
if CleanUpSurfaceType == land.SurfaceType.RUNWAY then
|
|
||||||
if CleanUpUnit:inAir() then
|
if _DATABASE:GetStatusGroup( CleanUpGroupName ) ~= "ReSpawn" then
|
||||||
local CleanUpLandHeight = land.getHeight(CleanUpUnitVec2)
|
|
||||||
local CleanUpUnitHeight = CleanUpUnitVec3.y - CleanUpLandHeight
|
local CleanUpCoordinate = CleanUpUnit:GetCoordinate()
|
||||||
self:T( { "CleanUp Scheduler", "Height = " .. CleanUpUnitHeight } )
|
|
||||||
|
if CleanUpDCSUnit and CleanUpDCSUnit:getLife() <= CleanUpDCSUnit:getLife0() * 0.95 then
|
||||||
|
if CleanUpUnit:IsAboveRunway() then
|
||||||
|
if CleanUpUnit:InAir() then
|
||||||
|
|
||||||
|
local CleanUpLandHeight = CleanUpCoordinate:GetLandHeight()
|
||||||
|
local CleanUpUnitHeight = CleanUpCoordinate.y - CleanUpLandHeight
|
||||||
|
|
||||||
if CleanUpUnitHeight < 30 then
|
if CleanUpUnitHeight < 30 then
|
||||||
self:T( { "CleanUp Scheduler", "Destroy " .. CleanUpUnitName .. " because below safe height and damaged." } )
|
self:T( { "CleanUp Scheduler", "Destroy " .. CleanUpUnitName .. " because below safe height and damaged." } )
|
||||||
self:_DestroyUnit(CleanUpUnit, CleanUpUnitName)
|
self:_DestroyUnit( CleanUpUnit )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self:T( { "CleanUp Scheduler", "Destroy " .. CleanUpUnitName .. " because on runway and damaged." } )
|
self:T( { "CleanUp Scheduler", "Destroy " .. CleanUpUnitName .. " because on runway and damaged." } )
|
||||||
self:_DestroyUnit(CleanUpUnit, CleanUpUnitName)
|
self:_DestroyUnit(CleanUpUnit )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Clean Units which are waiting for a very long time in the CleanUpZone.
|
-- Clean Units which are waiting for a very long time in the CleanUpZone.
|
||||||
if CleanUpUnit then
|
if CleanUpUnit then
|
||||||
local CleanUpUnitVelocity = CleanUpUnit:getVelocity()
|
local CleanUpUnitVelocity = CleanUpUnit:GetVelocityKMH()
|
||||||
local CleanUpUnitVelocityTotal = math.abs(CleanUpUnitVelocity.x) + math.abs(CleanUpUnitVelocity.y) + math.abs(CleanUpUnitVelocity.z)
|
if CleanUpUnitVelocity < 1 then
|
||||||
if CleanUpUnitVelocityTotal < 1 then
|
|
||||||
if UnitData.CleanUpMoved then
|
if UnitData.CleanUpMoved then
|
||||||
if UnitData.CleanUpTime + 180 <= timer.getTime() then
|
if UnitData.CleanUpTime + 180 <= timer.getTime() then
|
||||||
self:T( { "CleanUp Scheduler", "Destroy due to not moving anymore " .. CleanUpUnitName } )
|
self:T( { "CleanUp Scheduler", "Destroy due to not moving anymore " .. CleanUpUnitName } )
|
||||||
self:_DestroyUnit(CleanUpUnit, CleanUpUnitName)
|
self:_DestroyUnit( CleanUpUnit )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -25565,11 +25608,11 @@ function CLEANUP:_CleanUpScheduler()
|
|||||||
|
|
||||||
else
|
else
|
||||||
-- Do nothing ...
|
-- Do nothing ...
|
||||||
self.CleanUpList[CleanUpUnitName] = nil -- Not anymore in the DCSRTE
|
self.CleanUpList[CleanUpUnitName] = nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self:T( "CleanUp: Group " .. CleanUpUnitName .. " cannot be found in DCS RTE, removing ..." )
|
self:T( "CleanUp: Group " .. CleanUpUnitName .. " cannot be found in DCS RTE, removing ..." )
|
||||||
self.CleanUpList[CleanUpUnitName] = nil -- Not anymore in the DCSRTE
|
self.CleanUpList[CleanUpUnitName] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:T(CleanUpCount)
|
self:T(CleanUpCount)
|
||||||
|
|||||||
Reference in New Issue
Block a user