Merge branch 'develop' into FF/Ops

This commit is contained in:
Frank
2023-12-16 09:32:14 +01:00
19 changed files with 993 additions and 397 deletions

View File

@@ -24,7 +24,7 @@
-- @module Ops.CTLD
-- @image OPS_CTLD.jpg
-- Last Update November 2023
-- Last Update December 2023
do
@@ -1228,7 +1228,7 @@ CTLD.UnitTypeCapabilities = {
--- CTLD class version.
-- @field #string version
CTLD.version="1.0.43"
CTLD.version="1.0.44"
--- Instantiate a new CTLD.
-- @param #CTLD self
@@ -2561,6 +2561,40 @@ function CTLD:_ListCratesNearby( _group, _unit)
return self
end
-- (Internal) Function to find and Remove nearby crates.
-- @param #CTLD self
-- @param Wrapper.Group#GROUP Group
-- @param Wrapper.Unit#UNIT Unit
-- @return #CTLD self
function CTLD:_RemoveCratesNearby( _group, _unit)
self:T(self.lid .. " _RemoveCratesNearby")
local finddist = self.CrateDistance or 35
local crates,number = self:_FindCratesNearby(_group,_unit, finddist,true) -- #table
if number > 0 then
local text = REPORT:New("Removing Crates Found Nearby:")
text:Add("------------------------------------------------------------")
for _,_entry in pairs (crates) do
local entry = _entry -- #CTLD_CARGO
local name = entry:GetName() --#string
local dropped = entry:WasDropped()
if dropped then
text:Add(string.format("Crate for %s, %dkg removed",name, entry.PerCrateMass))
else
text:Add(string.format("Crate for %s, %dkg removed",name, entry.PerCrateMass))
end
entry:GetPositionable():Destroy(false)
end
if text:GetCount() == 1 then
text:Add(" N O N E")
end
text:Add("------------------------------------------------------------")
self:_SendMessage(text:Text(), 30, true, _group)
else
self:_SendMessage(string.format("No (loadable) crates within %d meters!",finddist), 10, false, _group)
end
return self
end
--- (Internal) Return distance in meters between two coordinates.
-- @param #CTLD self
-- @param Core.Point#COORDINATE _point1 Coordinate one
@@ -2976,6 +3010,35 @@ function CTLD:IsHercules(Unit)
end
end
--- (Internal) Function to set troops positions of a template to a nice circle
-- @param #CTLD self
-- @param Core.Point#COORDINATE Coordinate Start coordinate to use
-- @param #number Radius Radius to be used
-- @param #number Heading Heading starting with
-- @param #string Template The group template name
-- @return #table Positions The positions table
function CTLD:_GetUnitPositions(Coordinate,Radius,Heading,Template)
local Positions = {}
local template = _DATABASE:GetGroupTemplate(Template)
UTILS.PrintTableToLog(template)
local numbertroops = #template.units
local newcenter = Coordinate:Translate(Radius,((Heading+270)%360))
for i=1,360,math.floor(360/numbertroops) do
local phead = ((Heading+270+i)%360)
local post = newcenter:Translate(Radius,phead)
local pos1 = post:GetVec2()
local p1t = {
x = pos1.x,
y = pos1.y,
heading = phead,
}
table.insert(Positions,p1t)
end
UTILS.PrintTableToLog(Positions)
return Positions
end
--- (Internal) Function to unload troops from heli.
-- @param #CTLD self
-- @param Wrapper.Group#GROUP Group
@@ -3027,14 +3090,29 @@ function CTLD:_UnloadTroops(Group, Unit)
zoneradius = Unit:GetVelocityMPS() or 100
end
local zone = ZONE_GROUP:New(string.format("Unload zone-%s",unitname),Group,zoneradius*factor)
local randomcoord = zone:GetRandomCoordinate(10,30*factor):GetVec2()
local randomcoord = zone:GetRandomCoordinate(10,30*factor) --:GetVec2()
local heading = Group:GetHeading() or 0
-- Spawn troops left from us, closer when hovering, further off when landed
if hoverunload or grounded then
randomcoord = Group:GetCoordinate()
-- slightly left from us
local Angle = (heading+270)%360
local offset = hoverunload and 1.5 or 5
randomcoord:Translate(offset,Angle,nil,true)
end
local tempcount = 0
for _,_template in pairs(temptable) do
self.TroopCounter = self.TroopCounter + 1
tempcount = tempcount+1
local alias = string.format("%s-%d", _template, math.random(1,100000))
local rad = 2.5+tempcount
local Positions = self:_GetUnitPositions(randomcoord,rad,heading,_template)
self.DroppedTroops[self.TroopCounter] = SPAWN:NewWithAlias(_template,alias)
:InitRandomizeUnits(true,20,2)
--:InitRandomizeUnits(true,20,2)
--:InitHeading(heading)
:InitDelayOff()
:SpawnFromVec2(randomcoord)
:InitSetUnitAbsolutePositions(Positions)
:SpawnFromVec2(randomcoord:GetVec2())
self:__TroopsDeployed(1, Group, Unit, self.DroppedTroops[self.TroopCounter],type)
end -- template loop
cargo:SetWasDropped(true)
@@ -3637,6 +3715,7 @@ function CTLD:_RefreshF10Menus()
local loadmenu = MENU_GROUP_COMMAND:New(_group,"Load crates",topcrates, self._LoadCratesNearby, self, _group, _unit)
local cratesmenu = MENU_GROUP:New(_group,"Get Crates",topcrates)
local packmenu = MENU_GROUP_COMMAND:New(_group, "Pack crates", topcrates, self._PackCratesNearby, self, _group, _unit)
local removecratesmenu = MENU_GROUP:New(_group, "Remove crates", topcrates)
if self.usesubcats then
local subcatmenus = {}
@@ -3672,6 +3751,7 @@ function CTLD:_RefreshF10Menus()
end
end
listmenu = MENU_GROUP_COMMAND:New(_group,"List crates nearby",topcrates, self._ListCratesNearby, self, _group, _unit)
removecrates = MENU_GROUP_COMMAND:New(_group,"Remove crates nearby",removecratesmenu, self._RemoveCratesNearby, self, _group, _unit)
local unloadmenu = MENU_GROUP_COMMAND:New(_group,"Drop crates",topcrates, self._UnloadCrates, self, _group, _unit)
if not self.nobuildmenu then
local buildmenu = MENU_GROUP_COMMAND:New(_group,"Build crates",topcrates, self._BuildCrates, self, _group, _unit)

View File

@@ -26,6 +26,7 @@
-- @field #table filterCategoryGroup Filter for group categories.
-- @field Core.Set#SET_ZONE acceptzoneset Set of accept zones. If defined, only contacts in these zones are considered.
-- @field Core.Set#SET_ZONE rejectzoneset Set of reject zones. Contacts in these zones are not considered, even if they are in accept zones.
-- @field Core.Set#SET_ZONE conflictzoneset Set of conflict zones. Contacts in these zones are considered, even if they are not in accept zones or if they are in reject zones.
-- @field #table Contacts Table of detected items.
-- @field #table ContactsLost Table of lost detected items.
-- @field #table ContactsUnknown Table of new detected items.
@@ -159,13 +160,12 @@ INTEL.Ctype={
--- INTEL class version.
-- @field #string version
INTEL.version="0.3.5"
INTEL.version="0.3.6"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- ToDo list
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Make forget times user input. Currently these are hard coded.
-- TODO: Add min cluster size. Only create new clusters if they have a certain group size.
-- TODO: process detected set asynchroniously for better performance.
-- DONE: Add statics.
@@ -266,6 +266,7 @@ function INTEL:New(DetectionSet, Coalition, Alias)
self:SetForgetTime()
self:SetAcceptZones()
self:SetRejectZones()
self:SetConflictZones()
------------------------
--- Pseudo Functions ---
@@ -416,7 +417,7 @@ function INTEL:RemoveAcceptZone(AcceptZone)
end
--- Set reject zones. Contacts detected in this/these zone(s) are rejected and not reported by the detection.
-- Note that reject zones overrule accept zones, i.e. if a unit is inside and accept zone and inside a reject zone, it is rejected.
-- Note that reject zones overrule accept zones, i.e. if a unit is inside an accept zone and inside a reject zone, it is rejected.
-- @param #INTEL self
-- @param Core.Set#SET_ZONE RejectZoneSet Set of reject zone(s).
-- @return #INTEL self
@@ -426,7 +427,7 @@ function INTEL:SetRejectZones(RejectZoneSet)
end
--- Add a reject zone. Contacts detected in this zone are rejected and not reported by the detection.
-- Note that reject zones overrule accept zones, i.e. if a unit is inside and accept zone and inside a reject zone, it is rejected.
-- Note that reject zones overrule accept zones, i.e. if a unit is inside an accept zone and inside a reject zone, it is rejected.
-- @param #INTEL self
-- @param Core.Zone#ZONE RejectZone Add a zone to the reject zone set.
-- @return #INTEL self
@@ -444,6 +445,36 @@ function INTEL:RemoveRejectZone(RejectZone)
return self
end
--- Set conflict zones. Contacts detected in this/these zone(s) are reported by the detection.
-- Note that conflict zones overrule all other zones, i.e. if a unit is outside of an accept zone and inside a reject zone, it is still reported if inside a conflict zone.
-- @param #INTEL self
-- @param Core.Set#SET_ZONE ConflictZoneSet Set of conflict zone(s).
-- @return #INTEL self
function INTEL:SetConflictZones(ConflictZoneSet)
self.conflictzoneset=ConflictZoneSet or SET_ZONE:New()
return self
end
--- Add a conflict zone. Contacts detected in this zone are conflicted and not reported by the detection.
-- Note that conflict zones overrule all other zones, i.e. if a unit is outside of an accept zone and inside a reject zone, it is still reported if inside a conflict zone.
-- @param #INTEL self
-- @param Core.Zone#ZONE ConflictZone Add a zone to the conflict zone set.
-- @return #INTEL self
function INTEL:AddConflictZone(ConflictZone)
self.conflictzoneset:AddZone(ConflictZone)
return self
end
--- Remove a conflict zone from the conflict zone set.
-- Note that conflict zones overrule all other zones, i.e. if a unit is outside of an accept zone and inside a reject zone, it is still reported if inside a conflict zone.
-- @param #INTEL self
-- @param Core.Zone#ZONE ConflictZone Remove a zone from the conflict zone set.
-- @return #INTEL self
function INTEL:RemoveConflictZone(ConflictZone)
self.conflictzoneset:Remove(ConflictZone:GetName(), true)
return self
end
--- **OBSOLETE, will be removed in next version!** Set forget contacts time interval.
-- Previously known contacts that are not detected any more, are "lost" after this time.
-- This avoids fast oscillations between a contact being detected and undetected.
@@ -481,6 +512,33 @@ function INTEL:SetFilterCategory(Categories)
return self
end
--- Method to make the radar detection less accurate, e.g. for WWII scenarios.
-- @param #INTEL self
-- @param #number minheight Minimum flight height to be detected, in meters AGL (above ground)
-- @param #number thresheight Threshold to escape the radar if flying below minheight, defaults to 90 (90% escape chance)
-- @param #number thresblur Threshold to be detected by the radar overall, defaults to 85 (85% chance to be found)
-- @param #number closing Closing-in in km - the limit of km from which on it becomes increasingly difficult to escape radar detection if flying towards the radar position. Should be about 1/3 of the radar detection radius in kilometers, defaults to 20.
-- @return #INTEL self
function INTEL:SetRadarBlur(minheight,thresheight,thresblur,closing)
self.RadarBlur = true
self.RadarBlurMinHeight = minheight or 250 -- meters
self.RadarBlurThresHeight = thresheight or 90 -- 10% chance to find a low flying group
self.RadarBlurThresBlur = thresblur or 85 -- 25% chance to escape the radar overall
self.RadarBlurClosing = closing or 20 -- 20km
self.RadarBlurClosingSquare = self.RadarBlurClosing * self.RadarBlurClosing
return self
end
--- Set the accept range in kilometers from each of the recce. Only object closer than this range will be detected.
-- @param #INTEL self
-- @param #number Range Range in kilometers
-- @return #INTEL self
function INTEL:SetAcceptRange(Range)
self.RadarAcceptRange = true
self.RadarAcceptRangeKilometers = Range or 75
return self
end
--- Filter group categories. Valid categories are:
--
-- * Group.Category.AIRPLANE
@@ -780,7 +838,19 @@ function INTEL:UpdateIntel()
local remove={}
for unitname,_unit in pairs(DetectedUnits) do
local unit=_unit --Wrapper.Unit#UNIT
local inconflictzone=false
-- Check if unit is in any of the conflict zones.
if self.conflictzoneset:Count()>0 then
for _,_zone in pairs(self.conflictzoneset.Set) do
local zone=_zone --Core.Zone#ZONE
if unit:IsInZone(zone) then
inconflictzone=true
break
end
end
end
-- Check if unit is in any of the accept zones.
if self.acceptzoneset:Count()>0 then
local inzone=false
@@ -793,7 +863,7 @@ function INTEL:UpdateIntel()
end
-- Unit is not in accept zone ==> remove!
if not inzone then
if (not inzone) and (not inconflictzone) then
table.insert(remove, unitname)
end
end
@@ -810,7 +880,7 @@ function INTEL:UpdateIntel()
end
-- Unit is inside a reject zone ==> remove!
if inzone then
if inzone and (not inconflictzone) then
table.insert(remove, unitname)
end
end
@@ -1037,7 +1107,7 @@ function INTEL:CreateDetectedItems(DetectedGroups, DetectedStatics, RecceDetecti
end
--- (Internal) Return the detected target groups of the controllable as a @{SET_GROUP}.
-- The optional parametes specify the detection methods that can be applied.
-- The optional parameters specify the detection methods that can be applied.
-- If no detection method is given, the detection will use all the available methods by default.
-- @param #INTEL self
-- @param Wrapper.Unit#UNIT Unit The unit detecting.
@@ -1053,6 +1123,7 @@ function INTEL:GetDetectedUnits(Unit, DetectedUnits, RecceDetecting, DetectVisua
-- Get detected DCS units.
local reccename = Unit:GetName()
local detectedtargets=Unit:GetDetectedTargets(DetectVisual, DetectOptical, DetectRadar, DetectIRST, DetectRWR, DetectDLINK)
for DetectionObjectID, Detection in pairs(detectedtargets or {}) do
@@ -1071,11 +1142,47 @@ function INTEL:GetDetectedUnits(Unit, DetectedUnits, RecceDetecting, DetectVisua
if status then
local unit=UNIT:FindByName(name)
if unit and unit:IsAlive() then
DetectedUnits[name]=unit
RecceDetecting[name]=reccename
self:T(string.format("Unit %s detect by %s", name, reccename))
local DetectionAccepted = true
if self.RadarAcceptRange then
local reccecoord = Unit:GetCoordinate()
local coord = unit:GetCoordinate()
local dist = math.floor(coord:Get2DDistance(reccecoord)/1000) -- km
if dist > self.RadarAcceptRangeKilometers then DetectionAccepted = false end
end
if self.RadarBlur then
local reccecoord = Unit:GetCoordinate()
local coord = unit:GetCoordinate()
local dist = math.floor(coord:Get2DDistance(reccecoord)/1000) -- km
local AGL = unit:GetAltitude(true)
local minheight = self.RadarBlurMinHeight or 250 -- meters
local thresheight = self.RadarBlurThresHeight or 90 -- 10% chance to find a low flying group
local thresblur = self.RadarBlurThresBlur or 85 -- 25% chance to escape the radar overall
--local dist = math.floor(Distance)
if dist <= self.RadarBlurClosing then
thresheight = (((dist*dist)/self.RadarBlurClosingSquare)*thresheight)
thresblur = (((dist*dist)/self.RadarBlurClosingSquare)*thresblur)
end
local fheight = math.floor(math.random(1,10000)/100)
local fblur = math.floor(math.random(1,10000)/100)
if fblur > thresblur then DetectionAccepted = false end
if AGL <= minheight and fheight < thresheight then DetectionAccepted = false end
if self.debug or self.verbose > 1 then
MESSAGE:New("Radar Blur",10):ToLogIf(self.debug):ToAllIf(self.verbose>1)
MESSAGE:New("Unit "..name.." is at "..math.floor(AGL).."m. Distance "..math.floor(dist).."km.",10):ToLogIf(self.debug):ToAllIf(self.verbose>1)
MESSAGE:New(string.format("fheight = %d/%d | fblur = %d/%d",fheight,thresheight,fblur,thresblur),10):ToLogIf(self.debug):ToAllIf(self.verbose>1)
MESSAGE:New("Detection Accepted = "..tostring(DetectionAccepted),10):ToLogIf(self.debug):ToAllIf(self.verbose>1)
end
end
if DetectionAccepted then
DetectedUnits[name]=unit
RecceDetecting[name]=reccename
self:T(string.format("Unit %s detect by %s", name, reccename))
end
else
if self.detectStatics then
local static=STATIC:FindByName(name, false)
@@ -1093,7 +1200,6 @@ function INTEL:GetDetectedUnits(Unit, DetectedUnits, RecceDetecting, DetectVisua
end
end
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@@ -3474,10 +3474,9 @@ function OPSGROUP:RemoveWaypoint(wpindex)
-- Could be that the waypoint we are currently moving to was the LAST waypoint. Then we now passed the final waypoint.
if (self.adinfinitum or istemp) then
self:_PassedFinalWaypoint(false, "Removed PASSED temporary waypoint ")
end
self:_PassedFinalWaypoint(false, "Removed PASSED temporary waypoint")
end
end
end
@@ -5805,6 +5804,27 @@ function OPSGROUP:onafterMissionDone(From, Event, To, Mission)
end
end
if self.legion and self.legionReturn==false and self.waypoints and #self.waypoints==1 then
---
-- This is the case where a group was send on a mission (which is over now), has no addional
-- waypoints or tasks and should NOT return to its legion.
-- We create a new waypoint at the current position and let it hold here.
---
local Coordinate=self:GetCoordinate()
if self.isArmygroup then
ARMYGROUP.AddWaypoint(self, Coordinate, 0, nil, nil, false)
elseif self.isNavygroup then
NAVYGROUP.AddWaypoint(self,Coordinate, 0, nil, nil, false)
end
-- Remove original waypoint.
self:RemoveWaypoint(1)
self:_PassedFinalWaypoint(true, "Passed final waypoint as group is done with mission but should NOT return to its legion")
end
-- Check if group is done.
self:_CheckGroupDone(delay)

View File

@@ -97,7 +97,7 @@ OPSZONE.ZoneType={
--- OPSZONE class version.
-- @field #string version
OPSZONE.version="0.6.0"
OPSZONE.version="0.6.1"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- ToDo list
@@ -1277,7 +1277,7 @@ function OPSZONE:EvaluateZone()
if Nblu>0 then
if not self:IsAttacked() then
if not self:IsAttacked() and self.Tnut>=self.threatlevelCapture then
self:Attacked(coalition.side.BLUE)
end
@@ -1329,7 +1329,7 @@ function OPSZONE:EvaluateZone()
if Nred>0 then
if not self:IsAttacked() then
if not self:IsAttacked() and self.Tnut>=self.threatlevelCapture then
-- Red is attacking blue zone.
self:Attacked(coalition.side.RED)
end

View File

@@ -79,6 +79,7 @@
-- @field Utilities.FiFo#FIFO TargetCache
-- @field #boolean smokeownposition
-- @field #table SmokeOwn
-- @field #boolean smokeaveragetargetpos
-- @extends Core.Fsm#FSM
---
@@ -104,7 +105,7 @@ PLAYERRECCE = {
ClassName = "PLAYERRECCE",
verbose = true,
lid = nil,
version = "0.0.22",
version = "0.1.23",
ViewZone = {},
ViewZoneVisual = {},
ViewZoneLaser = {},
@@ -130,8 +131,9 @@ PLAYERRECCE = {
ReferencePoint = nil,
TForget = 600,
TargetCache = nil,
smokeownposition = true,
smokeownposition = false,
SmokeOwn = {},
smokeaveragetargetpos = false,
}
---
@@ -1109,9 +1111,8 @@ function PLAYERRECCE:_SmokeTargets(client,group,playername)
self:T(self.lid.."_SmokeTargets")
local cameraset = self:_GetTargetSet(client,true) -- Core.Set#SET_UNIT
local visualset = self:_GetTargetSet(client,false) -- Core.Set#SET_UNIT
cameraset:AddSet(visualset)
if cameraset:CountAlive() > 0 then
if cameraset:CountAlive() > 0 or visualset:CountAlive() > 0 then
self:__TargetsSmoked(-1,client,playername,cameraset)
else
return self
@@ -1126,29 +1127,31 @@ function PLAYERRECCE:_SmokeTargets(client,group,playername)
-- laser targer gets extra smoke
if laser and laser.Target and laser.Target:IsAlive() then
laser.Target:GetCoordinate():Smoke(lasersmoke)
if cameraset:IsInSet(laser.Target) then
cameraset:Remove(laser.Target:GetName(),true)
end
local coord = visualset:GetCoordinate()
if coord and self.smokeaveragetargetpos then
coord:SetAtLandheight()
coord:Smoke(medsmoke)
else
-- smoke everything
for _,_unit in pairs(visualset.Set) do
local unit = _unit --Wrapper.Unit#UNIT
if unit and unit:IsAlive() then
local coord = unit:GetCoordinate()
local threat = unit:GetThreatLevel()
if coord then
local color = lowsmoke
if threat > 7 then
color = highsmoke
elseif threat > 2 then
color = medsmoke
end
coord:Smoke(color)
end
end
end
end
local coordinate = nil
local setthreat = 0
-- smoke everything else
if cameraset:CountAlive() > 1 then
local coordinate = cameraset:GetCoordinate()
local setthreat = cameraset:CalculateThreatLevelA2G()
end
if coordinate then
local color = lowsmoke
if setthreat > 7 then
color = medsmoke
elseif setthreat > 2 then
color = lowsmoke
end
coordinate:Smoke(color)
end
if self.SmokeOwn[playername] then
local cc = client:GetVec2()
-- don't smoke mid-air
@@ -1189,15 +1192,15 @@ function PLAYERRECCE:_FlareTargets(client,group,playername)
-- smoke everything else
for _,_unit in pairs(cameraset.Set) do
local unit = _unit --Wrapper.Unit#UNIT
if unit then
if unit and unit:IsAlive() then
local coord = unit:GetCoordinate()
local threat = unit:GetThreatLevel()
if coord then
local color = lowsmoke
if threat > 7 then
color = medsmoke
color = highsmoke
elseif threat > 2 then
color = lowsmoke
color = medsmoke
end
coord:Flare(color)
end
@@ -1546,7 +1549,7 @@ end
-- @param #PLAYERRECCE self
-- @return #PLAYERRECCE self
function PLAYERRECCE:EnableSmokeOwnPosition()
self:T(self.lid.."ENableSmokeOwnPosition")
self:T(self.lid.."EnableSmokeOwnPosition")
self.smokeownposition = true
return self
end
@@ -1560,6 +1563,24 @@ function PLAYERRECCE:DisableSmokeOwnPosition()
return self
end
--- [User] Enable smoking of average target positions, instead of all targets visible. Loses smoke per threatlevel -- each is med threat. Default is - smoke all positions.
-- @param #PLAYERRECCE self
-- @return #PLAYERRECCE self
function PLAYERRECCE:EnableSmokeAverageTargetPosition()
self:T(self.lid.."ENableSmokeOwnPosition")
self.smokeaveragetargetpos = true
return self
end
--- [User] Disable smoking of average target positions, instead of all targets visible. Default is - smoke all positions.
-- @param #PLAYERRECCE self
-- @return #PLAYERRECCE
function PLAYERRECCE:DisableSmokeAverageTargetPosition()
self:T(self.lid.."DisableSmokeAverageTargetPosition")
self.smokeaveragetargetpos = false
return self
end
--- [Internal] Get text for text-to-speech.
-- Numbers are spaced out, e.g. "Heading 180" becomes "Heading 1 8 0 ".
-- @param #PLAYERRECCE self