From 10b9a32f298e055033d84e39911019093ae14744 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 12 Jul 2023 17:54:17 +0200 Subject: [PATCH] #SPOT * Fix for switching laser off and on again not follwing unit any more --- Moose Development/Moose/Core/Spot.lua | 71 ++++++++++++++++----------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/Moose Development/Moose/Core/Spot.lua b/Moose Development/Moose/Core/Spot.lua index d87606937..9a12fdf35 100644 --- a/Moose Development/Moose/Core/Spot.lua +++ b/Moose Development/Moose/Core/Spot.lua @@ -33,7 +33,8 @@ do - --- @type SPOT + --- + -- @type SPOT -- @extends Core.Fsm#FSM @@ -228,7 +229,8 @@ do -- @param #number LaserCode Laser code. -- @param #number Duration Duration of lasing in seconds. function SPOT:onafterLaseOn( From, Event, To, Target, LaserCode, Duration ) - self:F( { "LaseOn", Target, LaserCode, Duration } ) + self:T({From, Event, To}) + self:T2( { "LaseOn", Target, LaserCode, Duration } ) local function StopLase( self ) self:LaseOff() @@ -256,6 +258,8 @@ do self:HandleEvent( EVENTS.Dead ) self:__Lasing( -1 ) + + return self end @@ -268,7 +272,7 @@ do -- @param #number LaserCode Laser code. -- @param #number Duration Duration of lasing in seconds. function SPOT:onafterLaseOnCoordinate(From, Event, To, Coordinate, LaserCode, Duration) - self:F( { "LaseOnCoordinate", Coordinate, LaserCode, Duration } ) + self:T2( { "LaseOnCoordinate", Coordinate, LaserCode, Duration } ) local function StopLase( self ) self:LaseOff() @@ -290,12 +294,14 @@ do end self:__Lasing(-1) + return self end - - --- @param #SPOT self + + --- + -- @param #SPOT self -- @param Core.Event#EVENTDATA EventData function SPOT:OnEventDead(EventData) - self:F( { Dead = EventData.IniDCSUnitName, Target = self.Target } ) + self:T2( { Dead = EventData.IniDCSUnitName, Target = self.Target } ) if self.Target then if EventData.IniDCSUnitName == self.TargetName then self:F( {"Target dead ", self.TargetName } ) @@ -309,42 +315,51 @@ do self:LaseOff() end end + return self end - --- @param #SPOT self + --- + -- @param #SPOT self -- @param From -- @param Event -- @param To function SPOT:onafterLasing( From, Event, To ) - - if self.Target and self.Target:IsAlive() then - self.SpotIR:setPoint( self.Target:GetPointVec3():AddY(1):AddY(math.random(-100,100)/100):AddX(math.random(-100,100)/100):GetVec3() ) - self.SpotLaser:setPoint( self.Target:GetPointVec3():AddY(1):GetVec3() ) - self:__Lasing( -0.2 ) - elseif self.TargetCoord then + self:T({From, Event, To}) - -- Wiggle the IR spot a bit. - local irvec3={x=self.TargetCoord.x+math.random(-100,100)/100, y=self.TargetCoord.y+math.random(-100,100)/100, z=self.TargetCoord.z} --#DCS.Vec3 - local lsvec3={x=self.TargetCoord.x, y=self.TargetCoord.y, z=self.TargetCoord.z} --#DCS.Vec3 + if self.Lasing then + if self.Target and self.Target:IsAlive() then + + self.SpotIR:setPoint( self.Target:GetPointVec3():AddY(1):AddY(math.random(-100,100)/100):AddX(math.random(-100,100)/100):GetVec3() ) + self.SpotLaser:setPoint( self.Target:GetPointVec3():AddY(1):GetVec3() ) + + self:__Lasing(0.2) + elseif self.TargetCoord then - self.SpotIR:setPoint(irvec3) - self.SpotLaser:setPoint(lsvec3) - - self:__Lasing(-0.25) - else - self:F( { "Target is not alive", self.Target:IsAlive() } ) + -- Wiggle the IR spot a bit. + local irvec3={x=self.TargetCoord.x+math.random(-100,100)/100, y=self.TargetCoord.y+math.random(-100,100)/100, z=self.TargetCoord.z} --#DCS.Vec3 + local lsvec3={x=self.TargetCoord.x, y=self.TargetCoord.y, z=self.TargetCoord.z} --#DCS.Vec3 + + self.SpotIR:setPoint(irvec3) + self.SpotLaser:setPoint(lsvec3) + + self:__Lasing(0.2) + else + self:F( { "Target is not alive", self.Target:IsAlive() } ) + end end - + return self end - - --- @param #SPOT self + + --- + -- @param #SPOT self -- @param From -- @param Event -- @param To -- @return #SPOT function SPOT:onafterLaseOff( From, Event, To ) - - self:F( {"Stopped lasing for ", self.Target and self.Target:GetName() or "coord", SpotIR = self.SportIR, SpotLaser = self.SpotLaser } ) + self:t({From, Event, To}) + + self:T2( {"Stopped lasing for ", self.Target and self.Target:GetName() or "coord", SpotIR = self.SportIR, SpotLaser = self.SpotLaser } ) self.Lasing = false @@ -383,4 +398,4 @@ do return self end -end \ No newline at end of file +end