- Laser
This commit is contained in:
Frank 2020-10-26 08:01:56 +01:00
parent ab0e7e735a
commit 2d6653c14a
6 changed files with 471 additions and 87 deletions

View File

@ -284,6 +284,12 @@ do -- COORDINATE
return self return self
end end
--- Return the coordinates itself. Sounds stupid but can be useful for compatibility.
-- @param #COORDINATE self
-- @return #COORDINATE self
function COORDINATE:GetCoordinate()
return self
end
--- Return the coordinates of the COORDINATE in Vec3 format. --- Return the coordinates of the COORDINATE in Vec3 format.
-- @param #COORDINATE self -- @param #COORDINATE self
@ -733,6 +739,13 @@ do -- COORDINATE
return Velocity or 0 return Velocity or 0
end end
--- Return the "name" of the COORDINATE. Obviously, a coordinate does not have a name like a unit, static or group. So here we take the MGRS coordinates of the position.
-- @param #COORDINATE self
-- @return #string MGRS coordinates.
function COORDINATE:GetName()
local name=self:ToStringMGRS()
return rname
end
--- Return velocity text of the COORDINATE. --- Return velocity text of the COORDINATE.
-- @param #COORDINATE self -- @param #COORDINATE self

View File

@ -7049,7 +7049,7 @@ function WAREHOUSE:_CheckRequestNow(request)
-- If no transport is requested, assets need to be mobile unless it is a self request. -- If no transport is requested, assets need to be mobile unless it is a self request.
local onlymobile=false local onlymobile=false
if type(request.transport)=="number" and request.ntransport==0 and not request.toself then if type(request.ntransport)=="number" and request.ntransport==0 and not request.toself then
onlymobile=true onlymobile=true
end end

View File

@ -132,6 +132,8 @@ function ARMYGROUP:New(Group)
self:HandleEvent(EVENTS.Dead, self.OnEventDead) self:HandleEvent(EVENTS.Dead, self.OnEventDead)
self:HandleEvent(EVENTS.RemoveUnit, self.OnEventRemoveUnit) self:HandleEvent(EVENTS.RemoveUnit, self.OnEventRemoveUnit)
--self:HandleEvent(EVENTS.Hit, self.OnEventHit)
-- Start the status monitoring. -- Start the status monitoring.
self:__Status(-1) self:__Status(-1)
@ -545,7 +547,7 @@ function ARMYGROUP:onafterGotoWaypoint(From, Event, To, UID, Speed, Formation)
local tasks=self:GetTasksWaypoint(n) local tasks=self:GetTasksWaypoint(n)
for _,_task in pairs(tasks) do for _,_task in pairs(tasks) do
local task=_task --#OPSGROUP.Task local task=_task --Ops.OpsGroup#OPSGROUP.Task
task.status=OPSGROUP.TaskStatus.SCHEDULED task.status=OPSGROUP.TaskStatus.SCHEDULED
end end
@ -762,7 +764,7 @@ function ARMYGROUP:OnEventDead(EventData)
end end
--- Event function handling the crash of a unit. --- Event function handling when a unit is removed from the game.
-- @param #ARMYGROUP self -- @param #ARMYGROUP self
-- @param Core.Event#EVENTDATA EventData Event data. -- @param Core.Event#EVENTDATA EventData Event data.
function ARMYGROUP:OnEventRemoveUnit(EventData) function ARMYGROUP:OnEventRemoveUnit(EventData)
@ -785,6 +787,22 @@ function ARMYGROUP:OnEventRemoveUnit(EventData)
end end
--- Event function handling when a unit is hit.
-- @param #ARMYGROUP self
-- @param Core.Event#EVENTDATA EventData Event data.
function ARMYGROUP:OnEventHit(EventData)
-- Check that this is the right group.
if EventData and EventData.IniGroup and EventData.IniUnit and EventData.IniGroupName and EventData.IniGroupName==self.groupname then
local unit=EventData.IniUnit
local group=EventData.IniGroup
local unitname=EventData.IniUnitName
-- TODO: suppression
end
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Routing -- Routing
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -720,7 +720,7 @@ end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---- Update status. ---- Update status.
-- @param #FLIHGTGROUP self -- @param #FLIGHTGROUP self
function FLIGHTGROUP:onbeforeStatus(From, Event, To) function FLIGHTGROUP:onbeforeStatus(From, Event, To)
-- First we check if elements are still alive. Could be that they were despawned without notice, e.g. when landing on a too small airbase. -- First we check if elements are still alive. Could be that they were despawned without notice, e.g. when landing on a too small airbase.

View File

@ -39,6 +39,7 @@
-- @field #table missionqueue Queue of missions. -- @field #table missionqueue Queue of missions.
-- @field #number currentmission The ID (auftragsnummer) of the currently assigned AUFTRAG. -- @field #number currentmission The ID (auftragsnummer) of the currently assigned AUFTRAG.
-- @field Core.Set#SET_UNIT detectedunits Set of detected units. -- @field Core.Set#SET_UNIT detectedunits Set of detected units.
-- @field Core.Set#SET_GROUP detectedgroups Set of detected groups.
-- @field #string attribute Generalized attribute. -- @field #string attribute Generalized attribute.
-- @field #number speedMax Max speed in km/h. -- @field #number speedMax Max speed in km/h.
-- @field #number speedCruise Cruising speed in km/h. -- @field #number speedCruise Cruising speed in km/h.
@ -127,6 +128,7 @@ OPSGROUP = {
missionqueue = {}, missionqueue = {},
currentmission = nil, currentmission = nil,
detectedunits = {}, detectedunits = {},
detectedgroups = {},
attribute = nil, attribute = nil,
checkzones = nil, checkzones = nil,
inzones = nil, inzones = nil,
@ -271,9 +273,11 @@ OPSGROUP.TaskType={
-- @field Wrapper.Group#GROUP TargetGroup The target group. -- @field Wrapper.Group#GROUP TargetGroup The target group.
-- @field Wrapper.Positionable#POSITIONABLE TargetUnit The current target unit. -- @field Wrapper.Positionable#POSITIONABLE TargetUnit The current target unit.
-- @field Core.Point#COORDINATE Coordinate where the spot is pointing. -- @field Core.Point#COORDINATE Coordinate where the spot is pointing.
-- @field #number TargetType Type of target: 0=coordinate, 1=static, 2=unit, 3=group.
-- @field #boolean On If true, the laser is on. -- @field #boolean On If true, the laser is on.
-- @field #OPSGROUP.Element element The element of the group that is lasing. -- @field #OPSGROUP.Element element The element of the group that is lasing.
-- @field DCS#Vec3 vec3 The 3D positon vector of the laser (and IR) spot. -- @field DCS#Vec3 vec3 The 3D positon vector of the laser (and IR) spot.
-- @field DCS#Vec3 offset Local offset of the laser source.
-- @field Core.Timer#TIMER timer Spot timer. -- @field Core.Timer#TIMER timer Spot timer.
--- Ammo data. --- Ammo data.
@ -352,14 +356,17 @@ function OPSGROUP:New(Group)
-- Init set of detected units. -- Init set of detected units.
self.detectedunits=SET_UNIT:New() self.detectedunits=SET_UNIT:New()
-- Init set of detected groups.
self.detectedgroups=SET_GROUP:New()
-- Init inzone set. -- Init inzone set.
self.inzones=SET_ZONE:New() self.inzones=SET_ZONE:New()
-- Laser. -- Laser.
self.spot={} self.spot={}
self.spot.On=false self.spot.On=false
self.spot.timer=TIMER:New(OPSGROUP._UpdateLaser, self) self.spot.timer=TIMER:New(self._UpdateLaser, self)
self:SetLaser() self:SetLaser(1688, true, false, 0.5)
-- Init task counter. -- Init task counter.
self.taskcurrent=0 self.taskcurrent=0
@ -380,11 +387,16 @@ function OPSGROUP:New(Group)
self:AddTransition("*", "Respawn", "*") -- Respawn group. self:AddTransition("*", "Respawn", "*") -- Respawn group.
self:AddTransition("*", "PassingWaypoint", "*") -- Passing waypoint. self:AddTransition("*", "PassingWaypoint", "*") -- Passing waypoint.
self:AddTransition("*", "DetectedUnit", "*") -- Add a newly detected unit to the detected units set. self:AddTransition("*", "DetectedUnit", "*") -- Unit was detected (again) in this detection cycle.
self:AddTransition("*", "DetectedUnitNew", "*") -- Add a newly detected unit to the detected units set. self:AddTransition("*", "DetectedUnitNew", "*") -- Add a newly detected unit to the detected units set.
self:AddTransition("*", "DetectedUnitKnown", "*") -- Add a newly detected unit to the detected units set. self:AddTransition("*", "DetectedUnitKnown", "*") -- A known unit is still detected.
self:AddTransition("*", "DetectedUnitLost", "*") -- Group lost a detected target. self:AddTransition("*", "DetectedUnitLost", "*") -- Group lost a detected target.
self:AddTransition("*", "DetectedGroup", "*") -- Unit was detected (again) in this detection cycle.
self:AddTransition("*", "DetectedGroupNew", "*") -- Add a newly detected unit to the detected units set.
self:AddTransition("*", "DetectedGroupKnown", "*") -- A known unit is still detected.
self:AddTransition("*", "DetectedGroupLost", "*") -- Group lost a detected target group.
self:AddTransition("*", "PassingWaypoint", "*") -- Group passed a waypoint. self:AddTransition("*", "PassingWaypoint", "*") -- Group passed a waypoint.
self:AddTransition("*", "GotoWaypoint", "*") -- Group switches to a specific waypoint. self:AddTransition("*", "GotoWaypoint", "*") -- Group switches to a specific waypoint.
@ -400,6 +412,9 @@ function OPSGROUP:New(Group)
self:AddTransition("*", "LaserOn", "*") -- Turn laser on. self:AddTransition("*", "LaserOn", "*") -- Turn laser on.
self:AddTransition("*", "LaserOff", "*") -- Turn laser off. self:AddTransition("*", "LaserOff", "*") -- Turn laser off.
self:AddTransition("*", "LaserCode", "*") -- Switch laser code. self:AddTransition("*", "LaserCode", "*") -- Switch laser code.
self:AddTransition("*", "LaserPause", "*") -- Turn laser off temporarily.
self:AddTransition("*", "LaserLostLOS", "*") -- Lasing element lost line of sight.
self:AddTransition("*", "LaserGotLOS", "*") -- Lasing element got line of sight.
self:AddTransition("*", "TaskExecute", "*") -- Group will execute a task. self:AddTransition("*", "TaskExecute", "*") -- Group will execute a task.
self:AddTransition("*", "TaskPause", "*") -- Pause current task. Not implemented yet! self:AddTransition("*", "TaskPause", "*") -- Pause current task. Not implemented yet!
@ -603,7 +618,14 @@ end
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @return Core.Set#SET_UNIT Set of detected units. -- @return Core.Set#SET_UNIT Set of detected units.
function OPSGROUP:GetDetectedUnits() function OPSGROUP:GetDetectedUnits()
return self.detectedunits return self.detectedunits or {}
end
--- Get set of detected groups.
-- @param #OPSGROUP self
-- @return Core.Set#SET_GROUP Set of detected groups.
function OPSGROUP:GetDetectedGroups()
return self.detectedgroups or {}
end end
--- Get inital amount of ammunition. --- Get inital amount of ammunition.
@ -1128,6 +1150,13 @@ function OPSGROUP:IsRearming()
return rearming return rearming
end end
--- Check if the group has currently switched a LASER on.
-- @param #OPSGROUP self
-- @return #boolean If true, LASER of the group is on.
function OPSGROUP:IsLasing()
return self.spot.On
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Waypoint Functions -- Waypoint Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -2934,7 +2963,7 @@ function OPSGROUP:onafterGotoWaypoint(From, Event, To, UID)
end end
--- On after "DetectedUnit" event. Add newly detected unit to detected units set. --- On after "DetectedUnit" event.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
-- @param #string Event Event. -- @param #string Event Event.
@ -2959,7 +2988,7 @@ function OPSGROUP:onafterDetectedUnit(From, Event, To, Unit)
end end
--- On after "DetectedUnitNew" event. --- On after "DetectedUnitNew" event. Add newly detected unit to detected unit set.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
-- @param #string Event Event. -- @param #string Event Event.
@ -2972,6 +3001,44 @@ function OPSGROUP:onafterDetectedUnitNew(From, Event, To, Unit)
self.detectedunits:AddUnit(Unit) self.detectedunits:AddUnit(Unit)
end end
--- On after "DetectedGroup" event.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Wrapper.Group#GROUP Group The detected Group.
function OPSGROUP:onafterDetectedGroup(From, Event, To, Group)
-- Get group name.
local groupname=Group and Group:GetName() or "unknown"
-- Debug.
self:I(self.lid..string.format("Detected group %s", groupname))
if self.detectedgroups:FindGroup(groupname) then
-- Group is already in the detected set ==> Trigger "DetectedGroupKnown" event.
self:DetectedGroupKnown(Group)
else
-- Group is was not detected ==> Trigger "DetectedGroupNew" event.
self:DetectedGroupNew(Group)
end
end
--- On after "DetectedGroupNew" event. Add newly detected group to detected group set.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Wrapper.Group#GROUP Group The detected group.
function OPSGROUP:onafterDetectedGroupNew(From, Event, To, Group)
self:I(self.lid..string.format("Detected New group %s", Group:GetName()))
-- Add unit to detected unit set.
self.detectedgroups:AddGroup(Group)
end
--- On after "EnterZone" event. Sets self.inzones[zonename]=true. --- On after "EnterZone" event. Sets self.inzones[zonename]=true.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
@ -2996,6 +3063,77 @@ function OPSGROUP:onafterLeaveZone(From, Event, To, Zone)
self.inzones:Remove(zonename, true) self.inzones:Remove(zonename, true)
end end
--- On before "LaserOn" event.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Core.Point#COORDINATE Target Target Coordinate. Target can also be any POSITIONABLE from which we can obtain its coordinates.
function OPSGROUP:onbeforeLaserOn(From, Event, To, Target)
-- Check if LASER is already on.
if self.spot.On then
return false
end
if Target then
-- Target specified ==> set target.
self:SetLaserTarget(Target)
else
-- No target specified.
--TODO: error message
return false
end
-- Get the first element alive.
local element=self:GetElementAlive()
if element then
-- Set element.
self.spot.element=element
-- Vec3.
self.spot.vec3=self.spot.Coordinate:GetVec3()
-- Height offset. No offset for aircraft. We take the height for ground or naval.
local offsetY=0
if self.isGround or self.isNaval then
offsetY=element.height
end
-- Local offset of the LASER source.
self.spot.offset={x=0, y=offsetY, z=0}
-- Check LOS.
if self.spot.CheckLOS then
-- Check LOS.
self.spot.LOS=self:HasLoS(self.spot.Coordinate, self.spot.element, self.spot.offset)
env.info(string.format("FF LOS=%s", tostring(self.spot.LOS)))
if self.spot.LOS then
self:LaserGotLOS()
else
-- Try to switch laser on again in 10 sec.
env.info("FF no LOS currently. Trying to switch the laser on again in 10 sec.")
self:__LaserOn(-10, Target)
return false
end
end
else
self:E(self.lid.."ERROR: No element alive for lasing")
return false
end
return true
end
--- On after "LaserOn" event. --- On after "LaserOn" event.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
@ -3004,67 +3142,33 @@ end
-- @param Core.Point#COORDINATE Target Target Coordinate. Target can also be any POSITIONABLE from which we can obtain its coordinates. -- @param Core.Point#COORDINATE Target Target Coordinate. Target can also be any POSITIONABLE from which we can obtain its coordinates.
function OPSGROUP:onafterLaserOn(From, Event, To, Target) function OPSGROUP:onafterLaserOn(From, Event, To, Target)
-- Assume we got a coordinate.
local coord=Target
-- Check if we have a POSITIONABLE.
if Target:IsInstanceOf("POSITIONABLE") then
local target=Target --Wrapper.Positionable#POSITIONABLE
if target:IsAlive() then
if target:IsInstanceOf("GROUP") then
self.spot.TargetGroup=target
self.spot.TargetUnit=target:GetHighestThreat()
else
self.spot.TargetUnit=target
end
-- Current coordinate
coord=self.spot.TargetUnit:GetCoordinate()
else
self:E("WARNING: LASER target is not alive!")
return
end
end
-- Set coordinate.
self.spot.Coordinate=coord
-- Get the first element alive.
local element=self:GetElementAlive()
if element then
-- Debug message. -- Debug message.
self:I(self.lid.."Switching LASER on") self:I(self.lid.."Switching LASER on")
-- Start timer that calls the update twice per sec. -- Start timer that calls the update twice per sec by default.
self.spot.timer:Start(nil, 0.5) self.spot.timer:Start(nil, self.spot.dt)
-- Set element.
self.spot.element=element
-- Get DCS unit. -- Get DCS unit.
local DCSunit=self.spot.element.unit:GetDCSObject() local DCSunit=self.spot.element.unit:GetDCSObject()
-- Vec3.
self.spot.vec3=coord:GetVec3()
-- Height offset.
local offsetY=element.height
-- Create laser and IR beams. -- Create laser and IR beams.
self.spot.Laser=Spot.createLaser(DCSunit, {x=0, y=offsetY, z=0}, self.spot.vec3, self.spot.Code or 1688) self.spot.Laser=Spot.createLaser(DCSunit, self.spot.offset, self.spot.vec3, self.spot.Code or 1688)
if self.spot.IRon then if self.spot.IRon then
self.spot.IR=Spot.createInfraRed(DCSunit, {x=0, y=offsetY, z=0}, self.spot.vec3) self.spot.IR=Spot.createInfraRed(DCSunit, self.spot.offset, self.spot.vec3)
end end
-- Laser is on. -- Laser is on.
self.spot.On=true self.spot.On=true
end end
--- On before "LaserOff" event. Check if LASER is on.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function OPSGROUP:onbeforeLaserOff(From, Event, To)
return self.spot.On
end end
--- On after "LaserOff" event. --- On after "LaserOff" event.
@ -3075,7 +3179,34 @@ end
function OPSGROUP:onafterLaserOff(From, Event, To) function OPSGROUP:onafterLaserOff(From, Event, To)
-- Debug message. -- Debug message.
self:T(self.lid.."Switching LASER off") self:I(self.lid.."Switching LASER off")
-- "Destroy" the laser beam.
self.spot.Laser:destroy()
self.spot.IR:destroy()
-- Stop update timer.
self.spot.timer:Stop()
-- Set to nil.
self.spot.Laser=nil
self.spot.IR=nil
self.spot.TargetUnit=nil
-- Laser is off.
self.spot.On=false
end
--- On after "LaserPause" event.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function OPSGROUP:onafterLaserPause(From, Event, To)
-- Debug message.
self:I(self.lid.."Switching LASER off temporarily.")
-- "Destroy" the laser beam. -- "Destroy" the laser beam.
self.spot.Laser:destroy() self.spot.Laser:destroy()
@ -3102,12 +3233,12 @@ function OPSGROUP:onafterLaserCode(From, Event, To, Code)
self.spot.Code=Code or 1688 self.spot.Code=Code or 1688
-- Debug message. -- Debug message.
self:T(self.lid..string.format("Setting LASER Code to %d", self.spot.Code)) self:T2(self.lid..string.format("Setting LASER Code to %d", self.spot.Code))
if self.spot.On then if self.spot.On then
-- Debug info. -- Debug info.
self:T(self.lid..string.format("Updating LASER Code to %d", self.spot.Code)) self:T(self.lid..string.format("New LASER Code is %d", self.spot.Code))
-- Set LASER code. -- Set LASER code.
self.spot.Laser:setCode(self.spot.Code) self.spot.Laser:setCode(self.spot.Code)
@ -3115,6 +3246,143 @@ function OPSGROUP:onafterLaserCode(From, Event, To, Code)
end end
--- On after "LaserLostLOS" event.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function OPSGROUP:onafterLaserLostLOS(From, Event, To)
-- Lost line of sight.
self.spot.LOS=false
if self.spot.On then
-- Switch laser off.
self:LaserPause()
end
end
--- On after "LaserGotLOS" event.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function OPSGROUP:onafterLaserGotLOS(From, Event, To)
-- Lost line of sight.
self.spot.LOS=true
if not self.spot.On then
local target=nil
if self.spot.TargetType==0 then
target=self.spot.Coordinate
elseif self.spot.TargetType==1 or self.spot.TargetType==2 then
target=self.spot.TargetUnit
elseif self.spot.TargetType==3 then
target=self.spot.TargetGroup
end
-- Switch laser back on.
if target then
self:__LaserOn(-1, target)
end
end
end
--- Set LASER target.
-- @param #OPSGROUP self
-- @param Wrapper.Positionable#POSITIONABLE Target The target to lase. Can also be a COORDINATE object.
function OPSGROUP:SetLaserTarget(Target)
if Target then
-- Check if we have a POSITIONABLE.
if Target:IsInstanceOf("POSITIONABLE") then
local target=Target --Wrapper.Positionable#POSITIONABLE
if target:IsAlive() then
if target:IsInstanceOf("GROUP") then
-- We got a GROUP as target.
self.spot.TargetGroup=target
self.spot.TargetUnit=target:GetHighestThreat()
self.spot.TargetType=3
else
-- We got a UNIT or STATIC as target.
self.spot.TargetUnit=target
if target:IsInstanceOf("STATIC") then
self.spot.TargetType=1
elseif target:IsInstanceOf("UNIT") then
self.spot.TargetType=2
end
end
else
self:E("WARNING: LASER target is not alive!")
return
end
elseif Target:IsInstanceOf("COORDINATE") then
-- Coordinate as target.
self.spot.TargetType=0
else
self:E(self.lid.."ERROR: LASER target should be a POSITIONABLE (GROUP, UNIT or STATIC) or a COORDINATE object!")
return
end
-- Set coordinate.
self.spot.Coordinate=Target:GetCoordinate()
end
end
--- Check if an element of the group has line of sight to a coordinate.
-- @param #OPSGROUP self
-- @param Core.Point#COORDINATE Coordinate The position to which we check the LoS.
-- @param #OPSGROUP.Element Element The (optinal) element. If not given, all elements are checked.
-- @param DCS#Vec3 Offset Offset vector of the element.
-- @return #boolean If `true`, there is line of sight to the specified coordinate.
function OPSGROUP:HasLoS(Coordinate, Element, Offset)
-- Target vector.
local Vec3=Coordinate:GetVec3()
--- Function to check LoS for an element of the group.
local function checklos(element)
local vec3=Element.unit:GetVec3()
if Offset then
vec3=UTILS.VecAdd(vec3, Offset)
end
local _los=land.isVisible(vec3, Vec3)
return _los
end
if Element then
local los=checklos(Element)
return los
else
for _,element in pairs(self.elements) do
-- Get LoS of this element.
local los=checklos(element)
if los then
return true
end
end
return false
end
return nil
end
--- Update laser point. --- Update laser point.
-- @param #OPSGROUP self -- @param #OPSGROUP self
function OPSGROUP:_UpdateLaser() function OPSGROUP:_UpdateLaser()
@ -3124,7 +3392,7 @@ function OPSGROUP:_UpdateLaser()
--- ---
-- LASER is ON -- LASER is ON
--´- ---
-- Check if we have a POSITIONABLE to lase. -- Check if we have a POSITIONABLE to lase.
if self.spot.TargetUnit then if self.spot.TargetUnit then
@ -3166,25 +3434,51 @@ function OPSGROUP:_UpdateLaser()
local unit=self.spot.TargetGroup:GetHighestThreat() local unit=self.spot.TargetGroup:GetHighestThreat()
if unit then if unit then
self:I(self.lid.."Switching to target other target unit in the group") self:I(self.lid..string.format("Switching to target unit %s in the group", unit:GetName()))
self.spot.TargetUnit=unit self.spot.TargetUnit=unit
else else
-- Switch laser off. -- Switch laser off.
self:T(self.lid.."Target is not alive any more ==> switching LASER off") self:I(self.lid.."Target is not alive any more ==> switching LASER off")
self:LaserOff() self:LaserOff()
return
end end
else else
-- Switch laser off. -- Switch laser off.
self:T(self.lid.."Target is not alive any more ==> switching LASER off") self:I(self.lid.."Target is not alive any more ==> switching LASER off")
self:LaserOff() self:LaserOff()
return
end end
end end
end end
end end
-- Check LOS.
if self.spot.CheckLOS then
-- Check current LOS.
local los=self:HasLoS(self.spot.Coordinate, self.spot.element, self.spot.offset)
env.info(string.format("FF check LOS=%s", tostring(los)))
if los then
-- Got LOS
if not self.spot.LOS then
self:LaserGotLOS()
end
else
-- No LOS currently
if self.spot.LOS then
self:LaserLostLOS()
end
end
end
end end
@ -3233,7 +3527,29 @@ function OPSGROUP:onafterElementDead(From, Event, To, Element)
-- If there is another element alive, switch laser on again. -- If there is another element alive, switch laser on again.
if self:GetNelements()>0 then if self:GetNelements()>0 then
self:__LaserOn(-1, self.spot.Target or self.spot.Coordinate)
-- New target if any.
local target=nil
if self.spot.TargetType==0 then
-- Coordinate
target=self.spot.Coordinate
elseif self.spot.TargetType==1 or self.spot.TargetType==2 then
-- Static or unit
if self.spot.TargetUnit and self.spot.TargetUnit:IsAlive() then
target=self.spot.TargetUnit
end
elseif self.spot.TargetType==3 then
-- Group
if self.spot.TargetGroup and self.spot.TargetGroup:IsAlive() then
target=self.spot.TargetGroup
end
end
-- Switch laser on again.
if target then
self:__LaserOn(-1, target)
end
end end
end end
@ -3356,6 +3672,7 @@ function OPSGROUP:_CheckDetectedUnits()
local detectedtargets=self.group:GetDetectedTargets() local detectedtargets=self.group:GetDetectedTargets()
local detected={} local detected={}
local groups={}
for DetectionObjectID, Detection in pairs(detectedtargets or {}) do for DetectionObjectID, Detection in pairs(detectedtargets or {}) do
local DetectedObject=Detection.object -- DCS#Object local DetectedObject=Detection.object -- DCS#Object
@ -3375,10 +3692,23 @@ function OPSGROUP:_CheckDetectedUnits()
-- Trigger detected unit event ==> This also triggers the DetectedUnitNew and DetectedUnitKnown events. -- Trigger detected unit event ==> This also triggers the DetectedUnitNew and DetectedUnitKnown events.
self:DetectedUnit(unit) self:DetectedUnit(unit)
-- Get group of unit.
local group=unit:GetGroup()
-- Add group to table.
if group then
groups[group:GetName()]=group
end
end end
end end
end end
-- Call detected group event.
for groupname, group in pairs(groups) do
self:DetectedGroup(group)
end
-- Loop over units in detected set. -- Loop over units in detected set.
local lost={} local lost={}
for _,_unit in pairs(self.detectedunits:GetSet()) do for _,_unit in pairs(self.detectedunits:GetSet()) do
@ -3403,8 +3733,32 @@ function OPSGROUP:_CheckDetectedUnits()
-- Remove lost units from detected set. -- Remove lost units from detected set.
self.detectedunits:RemoveUnitsByName(lost) self.detectedunits:RemoveUnitsByName(lost)
-- Loop over groups in detected set.
local lost={}
for _,_group in pairs(self.detectedgroups:GetSet()) do
local group=_group --Wrapper.Group#GROUP
-- Loop over detected units
local gotit=false
for _,_du in pairs(groups) do
local du=_du --Wrapper.Group#GROUP
if group:GetName()==du:GetName() then
gotit=true
end
end end
if not gotit then
table.insert(lost, group:GetName())
self:DetectedGroupLost(group)
end
end
-- Remove lost units from detected set.
self.detectedgroups:RemoveGroupsByName(lost)
end
end end

View File

@ -492,8 +492,7 @@ end
--- Returns the unit's group if it exist and nil otherwise. --- Returns the unit's group if it exist and nil otherwise.
-- @param Wrapper.Unit#UNIT self -- @param Wrapper.Unit#UNIT self
-- @return Wrapper.Group#GROUP The Group of the Unit. -- @return Wrapper.Group#GROUP The Group of the Unit or `nil` if the unit does not exist.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetGroup() function UNIT:GetGroup()
self:F2( self.UnitName ) self:F2( self.UnitName )