This commit is contained in:
Applevangelist 2023-12-07 11:20:20 +01:00
parent 69c20e78fb
commit e8c7e62900
2 changed files with 73 additions and 47 deletions

View File

@ -419,7 +419,11 @@ do -- SET_BASE
-- @param #SET_BASE self -- @param #SET_BASE self
-- @return Core.Base#BASE -- @return Core.Base#BASE
function SET_BASE:GetRandom() function SET_BASE:GetRandom()
local tablemax = table.maxn(self.Index) local tablemax = 0
for _,_ind in pairs(self.Index) do
tablemax = tablemax + 1
end
--local tablemax = table.maxn(self.Index)
local RandomItem = self.Set[self.Index[math.random(1,tablemax)]] local RandomItem = self.Set[self.Index[math.random(1,tablemax)]]
self:T3( { RandomItem } ) self:T3( { RandomItem } )
return RandomItem return RandomItem
@ -561,10 +565,12 @@ do -- SET_BASE
return self return self
end end
--- Iterate the SET_BASE while identifying the nearest object from a @{Core.Point#POINT_VEC2}. --- Iterate the SET_BASE while identifying the nearest object in the set from a @{Core.Point#POINT_VEC2}.
-- @param #SET_BASE self -- @param #SET_BASE self
-- @param Core.Point#POINT_VEC2 PointVec2 A @{Core.Point#POINT_VEC2} object from where to evaluate the closest object in the set. -- @param Core.Point#POINT_VEC2 PointVec2 A @{Core.Point#COORDINATE} or @{Core.Point#POINT_VEC2} object (but **not** a simple DCS#Vec2!) from where to evaluate the closest object in the set.
-- @return Core.Base#BASE The closest object. -- @return Core.Base#BASE The closest object.
-- @usage
-- myset:FindNearestObjectFromPointVec2( ZONE:New("Test Zone"):GetCoordinate() )
function SET_BASE:FindNearestObjectFromPointVec2( PointVec2 ) function SET_BASE:FindNearestObjectFromPointVec2( PointVec2 )
self:F2( PointVec2 ) self:F2( PointVec2 )
@ -2849,15 +2855,14 @@ do -- SET_UNIT
function SET_UNIT:GetCoordinate() function SET_UNIT:GetCoordinate()
local Coordinate = nil local Coordinate = nil
local unit = self:GetRandom() local unit = self:GetFirst()
if self:Count() == 1 and unit then if self:Count() == 1 and unit then
return unit:GetCoordinate() return unit:GetCoordinate()
end end
if unit then if unit then
local Coordinate = unit:GetCoordinate() Coordinate = unit:GetCoordinate()
--self:F({Coordinate:GetVec3()}) self:T2(UTILS.PrintTableToLog(Coordinate:GetVec3()))
local x1 = Coordinate.x local x1 = Coordinate.x
local x2 = Coordinate.x local x2 = Coordinate.x
local y1 = Coordinate.y local y1 = Coordinate.y
@ -2868,19 +2873,19 @@ do -- SET_UNIT
local AvgHeading = nil local AvgHeading = nil
local MovingCount = 0 local MovingCount = 0
for UnitName, UnitData in pairs( self:GetAliveSet() ) do for UnitName, UnitData in pairs( self.Set) do
local Unit = UnitData -- Wrapper.Unit#UNIT local Unit = UnitData -- Wrapper.Unit#UNIT
local Coordinate = Unit:GetCoordinate() local Coord = Unit:GetCoordinate()
x1 = (Coordinate.x < x1) and Coordinate.x or x1 x1 = (Coord.x < x1) and Coord.x or x1
x2 = (Coordinate.x > x2) and Coordinate.x or x2 x2 = (Coord.x > x2) and Coord.x or x2
y1 = (Coordinate.y < y1) and Coordinate.y or y1 y1 = (Coord.y < y1) and Coord.y or y1
y2 = (Coordinate.y > y2) and Coordinate.y or y2 y2 = (Coord.y > y2) and Coord.y or y2
z1 = (Coordinate.y < z1) and Coordinate.z or z1 z1 = (Coord.y < z1) and Coord.z or z1
z2 = (Coordinate.y > z2) and Coordinate.z or z2 z2 = (Coord.y > z2) and Coord.z or z2
local Velocity = Coordinate:GetVelocity() local Velocity = Coord:GetVelocity()
if Velocity ~= 0 then if Velocity ~= 0 then
MaxVelocity = (MaxVelocity < Velocity) and Velocity or MaxVelocity MaxVelocity = (MaxVelocity < Velocity) and Velocity or MaxVelocity
local Heading = Coordinate:GetHeading() local Heading = Coordinate:GetHeading()
@ -2897,7 +2902,7 @@ do -- SET_UNIT
Coordinate:SetHeading( AvgHeading ) Coordinate:SetHeading( AvgHeading )
Coordinate:SetVelocity( MaxVelocity ) Coordinate:SetVelocity( MaxVelocity )
self:F( { Coordinate = Coordinate } ) self:T2(UTILS.PrintTableToLog(Coordinate:GetVec3()))
end end
return Coordinate return Coordinate

View File

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