diff --git a/Moose Development/Moose/Functional/Autolase.lua b/Moose Development/Moose/Functional/Autolase.lua index 1969fcbf9..7fb980ba8 100644 --- a/Moose Development/Moose/Functional/Autolase.lua +++ b/Moose Development/Moose/Functional/Autolase.lua @@ -91,6 +91,7 @@ -- @field #boolean threatmenu -- @field #number RoundingPrecision -- @field #table smokeoffset +-- @field #boolean increasegroundawareness -- @extends Ops.Intel#INTEL --- @@ -103,6 +104,7 @@ AUTOLASE = { debug = false, smokemenu = true, RoundingPrecision = 0, + increasegroundawareness = true, } --- Laser spot info @@ -121,7 +123,7 @@ AUTOLASE = { --- AUTOLASE class version. -- @field #string version -AUTOLASE.version = "0.1.28" +AUTOLASE.version = "0.1.29" ------------------------------------------------------------------- -- Begin Functional.Autolase.lua @@ -212,6 +214,7 @@ function AUTOLASE:New(RecceSet, Coalition, Alias, PilotSet) self.smokemenu = true self.threatmenu = true self.RoundingPrecision = 0 + self.increasegroundawareness = true self:EnableSmokeMenu({Angle=math.random(0,359),Distance=math.random(10,20)}) @@ -326,6 +329,22 @@ function AUTOLASE:SetLaserCodes( LaserCodes ) return self end +--- [User] Improve ground unit detection by using a zone scan and LOS check. +-- @param #AUTOLASE self +-- @return #AUTOLASE self +function AUTOLASE:EnableImproveGroundUnitsDetection() + self.increasegroundawareness = true + return self +end + +--- [User] Do not improve ground unit detection by using a zone scan and LOS check. +-- @param #AUTOLASE self +-- @return #AUTOLASE self +function AUTOLASE:DisableImproveGroundUnitsDetection() + self.increasegroundawareness = false + return self +end + --- (Internal) Function to set pilot menu. -- @param #AUTOLASE self -- @return #AUTOLASE self @@ -694,7 +713,8 @@ function AUTOLASE:CleanCurrentLasing() local unit = recce:GetUnit(1) local name = unit:GetName() if not self.RecceUnits[name] then - self.RecceUnits[name] = { name=name, unit=unit, cooldown = false, timestamp = timer.getAbsTime() } + local isground = (unit and unit.IsGround) and unit:IsGround() or false + self.RecceUnits[name] = { name=name, unit=unit, cooldown = false, timestamp = timer.getAbsTime(), isground=isground } end end end @@ -944,6 +964,63 @@ function AUTOLASE:CanLase(Recce,Unit) return canlase end +--- (Internal) Function to do a zone check per ground Recce and make found units and statics "known". +-- @param #AUTOLASE self +-- @return #AUTOLASE self +function AUTOLASE:_Prescient() + -- self.RecceUnits[name] = { name=name, unit=unit, cooldown = false, timestamp = timer.getAbsTime(), isground=isground } + for _,_data in pairs(self.RecceUnits) do + -- ground units only + if _data.isground and _data.unit and _data.unit:IsAlive() then + local unit = _data.unit -- Wrapper.Unit#UNIT + local position = unit:GetCoordinate() -- Core.Point#COORDINATE + local needsinit = false + if position then + local lastposition = unit:GetProperty("lastposition") + -- property initiated? + if not lastposition then + unit:SetProperty("lastposition",position) + lastposition = position + needsinit = true + end + -- has moved? + local dist = position:Get2DDistance(lastposition) + -- refresh? + local TNow = timer.getAbsTime() + -- check + if dist > 10 or needsinit==true or TNow - _data.timestamp > 29 then + -- init scan objects + local hasunits,hasstatics,_,Units,Statics = position:ScanObjects(self.LaseDistance,true,true,false) + -- loop found units + if hasunits then + self:T(self.lid.."Checking possibly visible UNITs for Recce "..unit:GetName()) + for _,_target in pairs(Units) do -- _, Wrapper.Unit#UNIT + if _target:GetCoalition() ~= self.coalition then + if unit:IsLOS(_target) and (not _target:IsUnitDetected(unit))then + unit:KnowUnit(_target,true,true) + end + end + end + end + -- loop found statics + if hasstatics then + self:T(self.lid.."Checking possibly visible STATICs for Recce "..unit:GetName()) + for _,_static in pairs(Statics) do -- _, Wrapper.Unit#UNIT + if _static:GetCoalition() ~= self.coalition then + local IsLOS = position:IsLOS(_static:GetCoordinate()) + if IsLOS then + unit:KnowUnit(_static,true,true) + end + end + end + end + end + end + end + end + return self +end + ------------------------------------------------------------------- -- FSM Functions ------------------------------------------------------------------- @@ -956,6 +1033,9 @@ end -- @return #AUTOLASE self function AUTOLASE:onbeforeMonitor(From, Event, To) self:T({From, Event, To}) + if self.increasegroundawareness then + self:_Prescient() + end -- Check if group has detected any units. self:UpdateIntel() return self @@ -984,7 +1064,7 @@ function AUTOLASE:onafterMonitor(From, Event, To) local grp = contact.group local coord = contact.position local reccename = contact.recce or "none" - local threat = contact.threatlevel or 0 + local threat = contact.threatlevel or 0 local reccegrp = UNIT:FindByName(reccename) if reccegrp then local reccecoord = reccegrp:GetCoordinate()