mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Improved the CleanUp
CleanUp now works detecting if units are floating above airport runways, and if they do, they will be destroyed.
This commit is contained in:
parent
921a9999cb
commit
92c9b27b71
6
Base.lua
6
Base.lua
@ -143,6 +143,12 @@ function BASE:onEvent(event)
|
|||||||
--env.info( 'onEvent EventObject.Event = ' .. tostring(EventObject.Event) )
|
--env.info( 'onEvent EventObject.Event = ' .. tostring(EventObject.Event) )
|
||||||
if event.id == EventObject.Event then
|
if event.id == EventObject.Event then
|
||||||
if self == EventObject.Self then
|
if self == EventObject.Self then
|
||||||
|
if event.initiator and event.initiator:isExist() then
|
||||||
|
event.IniUnitName = event.initiator:getName()
|
||||||
|
end
|
||||||
|
if event.target and event.target:isExist() then
|
||||||
|
event.TgtUnitName = event.target:getName()
|
||||||
|
end
|
||||||
trace.i( self.ClassName, { BaseEventCodes[event.id], event } )
|
trace.i( self.ClassName, { BaseEventCodes[event.id], event } )
|
||||||
EventObject.EventFunction( self, event )
|
EventObject.EventFunction( self, event )
|
||||||
end
|
end
|
||||||
|
|||||||
147
CleanUp.lua
147
CleanUp.lua
@ -59,7 +59,7 @@ function CLEANUP:_DestroyGroup( GroupObject, CleanUpGroupName )
|
|||||||
trace.f( self.ClassName )
|
trace.f( self.ClassName )
|
||||||
|
|
||||||
if GroupObject then -- and GroupObject:isExist() then
|
if GroupObject then -- and GroupObject:isExist() then
|
||||||
MESSAGE:New( "Destroy " .. CleanUpGroupName, CleanUpGroupName, 10, CleanUpGroupName ):ToAll()
|
MESSAGE:New( "Destroy Group " .. CleanUpGroupName, CleanUpGroupName, 1, CleanUpGroupName ):ToAll()
|
||||||
trigger.action.deactivateGroup(GroupObject)
|
trigger.action.deactivateGroup(GroupObject)
|
||||||
trace.i(self.ClassName, "GroupObject Destroyed")
|
trace.i(self.ClassName, "GroupObject Destroyed")
|
||||||
end
|
end
|
||||||
@ -67,13 +67,13 @@ end
|
|||||||
|
|
||||||
--- Destroys a 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!
|
||||||
-- @see CLEANUP
|
-- @see CLEANUP
|
||||||
function CLEANUP:_DestroyUnit( CleanUpUnitObject, CleanUpUnitName )
|
function CLEANUP:_DestroyUnit( CleanUpUnit, CleanUpUnitName )
|
||||||
trace.f( self.ClassName )
|
trace.f( self.ClassName )
|
||||||
|
|
||||||
if CleanUpUnitObject then
|
if CleanUpUnit then
|
||||||
MESSAGE:New( "Destroy " .. CleanUpUnitName, CleanUpUnitName, 10, CleanUpUnitName ):ToAll()
|
MESSAGE:New( "Destroy " .. CleanUpUnitName, CleanUpUnitName, 1, CleanUpUnitName ):ToAll()
|
||||||
CleanUpUnitObject:destroy()
|
CleanUpUnit:destroy()
|
||||||
trace.i(self.ClassName, "UnitObject Destroyed")
|
trace.i(self.ClassName, "Destroyed " .. CleanUpUnitName )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -216,6 +216,7 @@ trace.f( self.ClassName )
|
|||||||
--]]
|
--]]
|
||||||
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 ZoneNames. If this is the case, destroy the unit.
|
||||||
function CLEANUP:_EventHitCleanUp( event )
|
function CLEANUP:_EventHitCleanUp( event )
|
||||||
trace.f( self.ClassName )
|
trace.f( self.ClassName )
|
||||||
@ -253,47 +254,37 @@ trace.f( self.ClassName )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CLEANUP:_AddForCleanUp( CleanUpUnit, CleanUpUnitName )
|
||||||
|
|
||||||
|
self.CleanUpList[CleanUpUnitName] = {}
|
||||||
|
self.CleanUpList[CleanUpUnitName].CleanUpUnit = CleanUpUnit
|
||||||
|
self.CleanUpList[CleanUpUnitName].CleanUpUnitName = CleanUpUnitName
|
||||||
|
self.CleanUpList[CleanUpUnitName].CleanUpGroup = Unit.getGroup(CleanUpUnit)
|
||||||
|
self.CleanUpList[CleanUpUnitName].CleanUpGroupName = Unit.getGroup(CleanUpUnit):getName()
|
||||||
|
|
||||||
|
trace.i( self.ClassName, "CleanUp: Add to CleanUpList: " .. Unit.getGroup(CleanUpUnit):getName() .. " / " .. CleanUpUnitName )
|
||||||
|
|
||||||
|
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 ZoneNames. If this is the case, add the Group to the CLEANUP List.
|
||||||
function CLEANUP:_EventAddForCleanUp( event )
|
function CLEANUP:_EventAddForCleanUp( event )
|
||||||
trace.f( self.ClassName, { event } )
|
|
||||||
|
|
||||||
if event.initiator and Object.getCategory(event.initiator) == Object.Category.UNIT then
|
local CleanUpUnit = event.initiator -- the Unit
|
||||||
local CleanUpUnit = event.initiator -- the Unit
|
if CleanUpUnit and Object.getCategory(CleanUpUnit) == Object.Category.UNIT then
|
||||||
local CleanUpUnitName = event.initiator:getName() -- return the name of the Unit
|
local CleanUpUnitName = CleanUpUnit:getName() -- return the name of the Unit
|
||||||
local CleanUpGroup = Unit.getGroup(event.initiator)-- Identify the Group
|
if self.CleanUpList[CleanUpUnitName] == nil then
|
||||||
local CleanUpGroupName = CleanUpGroup:getName() -- return the name of the Group
|
|
||||||
if not self.CleanUpList[CleanUpGroupName] then
|
|
||||||
local AddForCleanUp = false
|
|
||||||
if routines.IsUnitInZones( CleanUpUnit, self.ZoneNames ) ~= nil then
|
if routines.IsUnitInZones( CleanUpUnit, self.ZoneNames ) ~= nil then
|
||||||
AddForCleanUp = true
|
self:_AddForCleanUp( CleanUpUnit, CleanUpUnitName )
|
||||||
end
|
|
||||||
if AddForCleanUp == true then
|
|
||||||
trace.i( self.ClassName, "CleanUp: Add for CleanUp: " .. CleanUpGroupName .. "/" .. CleanUpUnitName )
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if event.target and Object.getCategory(event.target) == Object.Category.UNIT then
|
local CleanUpTgtUnit = event.target -- the target Unit
|
||||||
|
if CleanUpTgtUnit and Object.getCategory(CleanUpTgtUnit) == Object.Category.UNIT then
|
||||||
local CleanUpTgtUnit = event.target -- the target Unit
|
local CleanUpTgtUnitName = CleanUpTgtUnit:getName() -- return the name of the target Unit
|
||||||
if CleanUpTgtUnit then
|
if self.CleanUpList[CleanUpTgtUnitName] == nil then
|
||||||
local CleanUpTgtUnitName = event.target:getName() -- return the name of the target Unit
|
if routines.IsUnitInZones( CleanUpTgtUnit, self.ZoneNames ) ~= nil then
|
||||||
local CleanUpTgtGroup = Unit.getGroup(event.target)-- Identify the target Group
|
self:_AddForCleanUp( CleanUpTgtUnit, CleanUpTgtUnitName )
|
||||||
local CleanUpTgtGroupName = CleanUpTgtGroup:getName() -- return the name of the target Group
|
|
||||||
if not self.CleanUpList[CleanUpTgtUnitName] then
|
|
||||||
local AddForCleanUp = false
|
|
||||||
if routines.IsUnitInZones( CleanUpTgtUnit, self.ZoneNames ) ~= nil then
|
|
||||||
AddForCleanUp = true
|
|
||||||
--env.info( "CleanUp:" .. CleanUpTgtGroupName .. "/" .. CleanUpTgtUnitName )
|
|
||||||
end
|
|
||||||
if AddForCleanUp == true then
|
|
||||||
trace.i( self.ClassName, "CleanUp: Add for CleanUp: " .. CleanUpTgtGroupName .. "/" .. CleanUpTgtUnitName )
|
|
||||||
self.CleanUpList[CleanUpTgtUnitName] = {}
|
|
||||||
self.CleanUpList[CleanUpTgtUnitName].CleanUpUnit = CleanUpTgtUnit
|
|
||||||
self.CleanUpList[CleanUpTgtUnitName].CleanUpGroup = CleanUpTgtGroup
|
|
||||||
self.CleanUpList[CleanUpTgtUnitName].CleanUpGroupName = CleanUpTgtGroupName
|
|
||||||
self.CleanUpList[CleanUpTgtUnitName].CleanUpUnitName = CleanUpTgtUnitName
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -312,59 +303,59 @@ CleanUpSurfaceTypeText = {
|
|||||||
function CLEANUP:_Scheduler()
|
function CLEANUP:_Scheduler()
|
||||||
|
|
||||||
for CleanUpUnitName, UnitData in pairs( self.CleanUpList ) do
|
for CleanUpUnitName, UnitData in pairs( self.CleanUpList ) do
|
||||||
--env.info( "CleanUp: GroupName = " .. GroupName .. " UnitName = " .. ListData )
|
trace.i( self.ClassName, { CleanUpUnitName, UnitData } )
|
||||||
local CleanUpGroup = Group.getByName(UnitData.CleanUpGroupName)
|
local CleanUpGroup = Group.getByName(UnitData.CleanUpGroupName)
|
||||||
local CleanUpUnit = Unit.getByName(UnitData.CleanUpUnitName)
|
local CleanUpUnit = Unit.getByName(UnitData.CleanUpUnitName)
|
||||||
local CleanUpGroupName = UnitData.CleanUpGroupName
|
local CleanUpGroupName = UnitData.CleanUpGroupName
|
||||||
local CleanUpUnitName = UnitData.CleanUpUnitName
|
local CleanUpUnitName = UnitData.CleanUpUnitName
|
||||||
if CleanUpGroup and CleanUpUnit then
|
if CleanUpUnit then
|
||||||
trace.i( self.ClassName, "CleanUp: " .. CleanUpGroupName )
|
trace.i( self.ClassName, "Checking " .. CleanUpUnitName )
|
||||||
if CleanUpGroup:isExist() and CleanUpUnit:isExist() then
|
if _Database:GetStatusGroup( CleanUpGroupName ) ~= "ReSpawn" then
|
||||||
if _Database:GetStatusGroup( CleanUpGroupName ) ~= "ReSpawn" then
|
local CleanUpUnitVec3 = CleanUpUnit:getPoint()
|
||||||
local CleanUpUnitVec3 = CleanUpUnit:getPoint()
|
trace.i( self.ClassName, CleanUpUnitVec3 )
|
||||||
trace.i( self.ClassName, CleanUpUnitVec3 )
|
local CleanUpUnitVec2 = {}
|
||||||
local CleanUpUnitVec2 = {}
|
CleanUpUnitVec2.x = CleanUpUnitVec3.x
|
||||||
CleanUpUnitVec2.x = CleanUpUnitVec3.x
|
CleanUpUnitVec2.y = CleanUpUnitVec3.z
|
||||||
CleanUpUnitVec2.y = CleanUpUnitVec3.z
|
trace.i( self.ClassName, CleanUpUnitVec2 )
|
||||||
trace.i( self.ClassName, CleanUpUnitVec2 )
|
local CleanUpSurfaceType = land.getSurfaceType(CleanUpUnitVec2)
|
||||||
local CleanUpSurfaceType = land.getSurfaceType(CleanUpUnitVec2)
|
trace.i( self.ClassName, CleanUpSurfaceType )
|
||||||
trace.i( self.ClassName, CleanUpSurfaceType )
|
MESSAGE:New( "Surface " .. CleanUpUnitName .. " = " .. CleanUpSurfaceTypeText[CleanUpSurfaceType], CleanUpUnitName, 10, CleanUpUnitName ):ToAll()
|
||||||
MESSAGE:New( "Surface " .. CleanUpUnitName .. " = " .. CleanUpSurfaceTypeText[CleanUpSurfaceType], CleanUpUnitName, 10, CleanUpUnitName ):ToAll()
|
|
||||||
|
if CleanUpUnit:getLife() <= CleanUpUnit:getLife0() * 0.95 then
|
||||||
if CleanUpUnit:getLife() <= CleanUpUnit:getLife0() * 0.95 then
|
if CleanUpSurfaceType == land.SurfaceType.RUNWAY then
|
||||||
if CleanUpSurfaceType == land.SurfaceType.RUNWAY then
|
trace.i( self.ClassName, "Destroy " .. CleanUpUnitName .. " because above runway and damaged." )
|
||||||
trace.i( self.ClassName, "CleanUp: Destroy " .. CleanUpGroupName .. " because above runway and damaged." )
|
self:_DestroyUnit(CleanUpUnit, CleanUpUnitName)
|
||||||
self:_DestroyUnit(CleanUpUnit, CleanUpUnitName)
|
self.CleanUpList[CleanUpUnitName] = nil -- Not anymore in the DCSRTE
|
||||||
UnitData = nil
|
else
|
||||||
end
|
|
||||||
if CleanUpUnit:inAir() then
|
if CleanUpUnit:inAir() then
|
||||||
if CleanUpUnit.getHeight(CleanUpUnitVec2) < 20 then
|
local CleanUpLandHeight = land.getHeight(CleanUpUnitVec2)
|
||||||
trace.i( self.ClassName, "CleanUp: Destroy " .. CleanUpGroupName .. " because below safe height and damaged." )
|
local CleanUpUnitHeight = CleanUpUnitVec3.y - CleanUpLandHeight
|
||||||
|
trace.i( self.ClassName, "In and height = " .. CleanUpUnitHeight )
|
||||||
|
--if CleanUpUnitHeight < 20 then
|
||||||
|
-- trace.i( self.ClassName, "Destroy " .. CleanUpUnitName .. " because below safe height and damaged." )
|
||||||
|
-- self:_DestroyUnit(CleanUpUnit, CleanUpUnitName)
|
||||||
|
-- self.CleanUpList[CleanUpUnitName] = nil -- Not anymore in the DCSRTE
|
||||||
|
--end
|
||||||
|
else
|
||||||
|
local CleanUpUnitVelocity = CleanUpUnit:getVelocity()
|
||||||
|
local CleanUpUnitVelocityTotal = math.abs(CleanUpUnitVelocity.x) + math.abs(CleanUpUnitVelocity.y) + math.abs(CleanUpUnitVelocity.z)
|
||||||
|
if CleanUpUnitVelocityTotal < 1 then
|
||||||
|
trace.i( self.ClassName, "Destroy: " .. CleanUpGroupName )
|
||||||
self:_DestroyUnit(CleanUpUnit, CleanUpUnitName)
|
self:_DestroyUnit(CleanUpUnit, CleanUpUnitName)
|
||||||
UnitData = nil
|
self.CleanUpList[CleanUpUnitName] = nil -- Not anymore in the DCSRTE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local CleanUpUnitVelocity = CleanUpUnit:getVelocity()
|
|
||||||
local CleanUpUnitVelocityTotal = math.abs(CleanUpUnitVelocity.x) + math.abs(CleanUpUnitVelocity.y) + math.abs(CleanUpUnitVelocity.z)
|
|
||||||
if CleanUpUnitVelocityTotal < 1 then
|
|
||||||
trace.i( self.ClassName, "CleanUp: Destroy: " .. CleanUpGroupName )
|
|
||||||
self:_DestroyUnit(CleanUpUnit, CleanUpUnitName)
|
|
||||||
UnitData = nil
|
|
||||||
end
|
|
||||||
else
|
|
||||||
-- Do nothing ...
|
|
||||||
UnitData = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
else
|
else
|
||||||
trace.i( self.ClassName, "CleanUp: Group " .. CleanUpGroupName .. " does not exist anymore in CleanUpList, Removing ..." )
|
-- Do nothing ...
|
||||||
UnitData = nil
|
self.CleanUpList[CleanUpUnitName] = nil -- Not anymore in the DCSRTE
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
trace.i( self.ClassName, "CleanUp: Group " .. CleanUpGroupName .. " cannot be found in DCS RTE, removing ..." )
|
trace.i( self.ClassName, "CleanUp: Group " .. CleanUpGroupName .. " cannot be found in DCS RTE, removing ..." )
|
||||||
UnitData = nil -- Not anymore in the DCSRTE
|
self.CleanUpList[CleanUpUnitName] = nil -- Not anymore in the DCSRTE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -16,7 +16,7 @@ Include.File = function( IncludeFile )
|
|||||||
end
|
end
|
||||||
|
|
||||||
Include.File( "Database" )
|
Include.File( "Database" )
|
||||||
Include.File( "StatHandler" )
|
--Include.File( "StatHandler" )
|
||||||
|
|
||||||
--Sanitize Mission Scripting environment
|
--Sanitize Mission Scripting environment
|
||||||
--This makes unavailable some unsecure functions.
|
--This makes unavailable some unsecure functions.
|
||||||
|
|||||||
16
Routines.lua
16
Routines.lua
@ -2388,6 +2388,22 @@ trace.f()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function GetUnitHeight( CheckUnit )
|
||||||
|
trace.f()
|
||||||
|
|
||||||
|
local UnitPoint = CheckUnit:getPoint()
|
||||||
|
local UnitPosition = { x = CurrentPoint.x, y = CurrentPoint.z }
|
||||||
|
local UnitHeight = CurrentPoint.y
|
||||||
|
|
||||||
|
local LandHeight = land.getHeight( CurrentPosition )
|
||||||
|
|
||||||
|
--env.info(( 'CarrierHeight: LandHeight = ' .. LandHeight .. ' CarrierHeight = ' .. CarrierHeight ))
|
||||||
|
|
||||||
|
return CarrierHeight - LandHeight
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
_MusicTable = {}
|
_MusicTable = {}
|
||||||
_MusicTable.Files = {}
|
_MusicTable.Files = {}
|
||||||
_MusicTable.Queue = {}
|
_MusicTable.Queue = {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user