Merge remote-tracking branch 'origin/master' into branch

This commit is contained in:
Applevangelist 2025-05-30 19:39:49 +02:00
commit 40d4dc14ab
2 changed files with 67 additions and 27 deletions

View File

@ -263,6 +263,7 @@ CSAR = {
rescuedpilots = 0, rescuedpilots = 0,
limitmaxdownedpilots = true, limitmaxdownedpilots = true,
maxdownedpilots = 10, maxdownedpilots = 10,
useFIFOLimitReplacement = false, -- If true, it will remove the oldest downed pilot when a new one is added, if the limit is reached.
allheligroupset = nil, allheligroupset = nil,
topmenuname = "CSAR", topmenuname = "CSAR",
ADFRadioPwr = 1000, ADFRadioPwr = 1000,
@ -1145,17 +1146,6 @@ function CSAR:_EventHandler(EventData)
return self return self
end end
-- limit no of pilots in the field.
if self.limitmaxdownedpilots and self:_ReachedPilotLimit() then
self:T("Maxed Downed Pilot!")
return self
end
-- TODO: Over water check --- EVENTS.LandingAfterEjection NOT triggered by DCS, so handle csarUsePara = true case
-- might create dual pilots in edge cases
local wetfeet = false
local initdcscoord = nil local initdcscoord = nil
local initcoord = nil local initcoord = nil
@ -1169,6 +1159,36 @@ function CSAR:_EventHandler(EventData)
self:T({initdcscoord}) self:T({initdcscoord})
end end
-- Remove downed pilot if already exists to replace with new one.
if _event.IniPlayerName then
local PilotTable = self.downedPilots --#CSAR.DownedPilot
local _foundPilot = nil
for _,_pilot in pairs(PilotTable) do
if _pilot.player == _event.IniPlayerName and _pilot.alive == true then
_foundPilot = _pilot
break
end
end
if _foundPilot then
self:T("Downed pilot already exists!")
_foundPilot.group:Destroy(false)
self:_RemoveNameFromDownedPilots(_foundPilot.name)
self:_CheckDownedPilotTable()
end
end
-- limit no of pilots in the field.
if self.limitmaxdownedpilots and self:_ReachedPilotLimit() then
self:T("Maxed Downed Pilot!")
return self
end
-- TODO: Over water check --- EVENTS.LandingAfterEjection NOT triggered by DCS, so handle csarUsePara = true case
-- might create dual pilots in edge cases
local wetfeet = false
--local surface = _unit:GetCoordinate():GetSurfaceType() --local surface = _unit:GetCoordinate():GetSurfaceType()
local surface = initcoord:GetSurfaceType() local surface = initcoord:GetSurfaceType()
@ -2402,6 +2422,21 @@ function CSAR:_ReachedPilotLimit()
local islimited = self.limitmaxdownedpilots local islimited = self.limitmaxdownedpilots
local count = self:_CountActiveDownedPilots() local count = self:_CountActiveDownedPilots()
if islimited and (count >= limit) then if islimited and (count >= limit) then
if self.useFIFOLimitReplacement then
local oldIndex = -1
local oldDownedPilot = nil
for _index, _downedpilot in pairs(self.downedPilots) do
oldIndex = _index
oldDownedPilot = _downedpilot
break
end
if oldDownedPilot then
oldDownedPilot.group:Destroy(false)
oldDownedPilot.alive = false
self:_CheckDownedPilotTable()
return false
end
end
return true return true
else else
return false return false

View File

@ -912,15 +912,18 @@ function GROUP:GetVelocityVec3()
if DCSGroup and DCSGroup:isExist() then if DCSGroup and DCSGroup:isExist() then
local GroupUnits = DCSGroup:getUnits() local GroupUnits = DCSGroup:getUnits()
local GroupCount = #GroupUnits local GroupCount = 0
local VelocityVec3 = { x = 0, y = 0, z = 0 } local VelocityVec3 = { x = 0, y = 0, z = 0 }
for _, DCSUnit in pairs( GroupUnits ) do for _, DCSUnit in pairs( GroupUnits ) do
if DCSUnit:isExist() and DCSUnit:isActive() then
local UnitVelocityVec3 = DCSUnit:getVelocity() local UnitVelocityVec3 = DCSUnit:getVelocity()
VelocityVec3.x = VelocityVec3.x + UnitVelocityVec3.x VelocityVec3.x = VelocityVec3.x + UnitVelocityVec3.x
VelocityVec3.y = VelocityVec3.y + UnitVelocityVec3.y VelocityVec3.y = VelocityVec3.y + UnitVelocityVec3.y
VelocityVec3.z = VelocityVec3.z + UnitVelocityVec3.z VelocityVec3.z = VelocityVec3.z + UnitVelocityVec3.z
GroupCount = GroupCount + 1
end
end end
VelocityVec3.x = VelocityVec3.x / GroupCount VelocityVec3.x = VelocityVec3.x / GroupCount
@ -1754,6 +1757,7 @@ function GROUP:GetMaxVelocity()
for Index, UnitData in pairs( DCSGroup:getUnits() ) do for Index, UnitData in pairs( DCSGroup:getUnits() ) do
if UnitData:isExist() and UnitData:isActive() then
local UnitVelocityVec3 = UnitData:getVelocity() local UnitVelocityVec3 = UnitData:getVelocity()
local UnitVelocity = math.abs( UnitVelocityVec3.x ) + math.abs( UnitVelocityVec3.y ) + math.abs( UnitVelocityVec3.z ) local UnitVelocity = math.abs( UnitVelocityVec3.x ) + math.abs( UnitVelocityVec3.y ) + math.abs( UnitVelocityVec3.z )
@ -1761,6 +1765,7 @@ function GROUP:GetMaxVelocity()
GroupVelocityMax = UnitVelocity GroupVelocityMax = UnitVelocity
end end
end end
end
return GroupVelocityMax return GroupVelocityMax
end end