Fixes to resolve exceptions in multi player situations

This commit is contained in:
FlightControl 2017-07-08 05:54:33 +02:00
parent 367c4d74af
commit 8e2aef17e7
3 changed files with 117 additions and 109 deletions

View File

@ -1724,14 +1724,16 @@ do -- AI_A2A_DISPATCHER
self:E( { DefenderSquadron } ) self:E( { DefenderSquadron } )
local SpawnCoord = DefenderSquadron.Airbase:GetCoordinate() -- Core.Point#COORDINATE local SpawnCoord = DefenderSquadron.Airbase:GetCoordinate() -- Core.Point#COORDINATE
local TargetCoord = Target.Set:GetFirst():GetCoordinate() local TargetCoord = Target.Set:GetFirst():GetCoordinate()
local Distance = SpawnCoord:Get2DDistance( TargetCoord ) if TargetCoord then
local Distance = SpawnCoord:Get2DDistance( TargetCoord )
if ClosestDistance == 0 or Distance < ClosestDistance then
-- Only intercept if the distance to target is smaller or equal to the GciRadius limit. if ClosestDistance == 0 or Distance < ClosestDistance then
if Distance <= self.GciRadius then
ClosestDistance = Distance -- Only intercept if the distance to target is smaller or equal to the GciRadius limit.
ClosestDefenderSquadronName = SquadronName if Distance <= self.GciRadius then
ClosestDistance = Distance
ClosestDefenderSquadronName = SquadronName
end
end end
end end
end end

View File

@ -1170,7 +1170,7 @@ do -- Players
-- @return #nil The group has no players -- @return #nil The group has no players
function GROUP:GetPlayerNames() function GROUP:GetPlayerNames()
local PlayerNames = nil local PlayerNames = {}
local Units = self:GetUnits() local Units = self:GetUnits()
for UnitID, UnitData in pairs( Units ) do for UnitID, UnitData in pairs( Units ) do

View File

@ -598,122 +598,128 @@ end
-- @param #UNIT self -- @param #UNIT self
function UNIT:GetThreatLevel() function UNIT:GetThreatLevel()
local Attributes = self:GetDesc().attributes
self:T( Attributes )
local ThreatLevel = 0 local ThreatLevel = 0
local ThreatText = "" local ThreatText = ""
if self:IsGround() then local Descriptor = self:GetDesc()
self:T( "Ground" ) if Descriptor then
local ThreatLevels = { local Attributes = Descriptor.attributes
"Unarmed", self:T( Attributes )
"Infantry",
"Old Tanks & APCs", if self:IsGround() then
"Tanks & IFVs without ATGM",
"Tanks & IFV with ATGM",
"Modern Tanks",
"AAA",
"IR Guided SAMs",
"SR SAMs",
"MR SAMs",
"LR SAMs"
}
self:T( "Ground" )
if Attributes["LR SAM"] then ThreatLevel = 10 local ThreatLevels = {
elseif Attributes["MR SAM"] then ThreatLevel = 9 "Unarmed",
elseif Attributes["SR SAM"] and "Infantry",
not Attributes["IR Guided SAM"] then ThreatLevel = 8 "Old Tanks & APCs",
elseif ( Attributes["SR SAM"] or Attributes["MANPADS"] ) and "Tanks & IFVs without ATGM",
Attributes["IR Guided SAM"] then ThreatLevel = 7 "Tanks & IFV with ATGM",
elseif Attributes["AAA"] then ThreatLevel = 6 "Modern Tanks",
elseif Attributes["Modern Tanks"] then ThreatLevel = 5 "AAA",
elseif ( Attributes["Tanks"] or Attributes["IFV"] ) and "IR Guided SAMs",
Attributes["ATGM"] then ThreatLevel = 4 "SR SAMs",
elseif ( Attributes["Tanks"] or Attributes["IFV"] ) and "MR SAMs",
not Attributes["ATGM"] then ThreatLevel = 3 "LR SAMs"
elseif Attributes["Old Tanks"] or Attributes["APC"] or Attributes["Artillery"] then ThreatLevel = 2 }
elseif Attributes["Infantry"] then ThreatLevel = 1
if Attributes["LR SAM"] then ThreatLevel = 10
elseif Attributes["MR SAM"] then ThreatLevel = 9
elseif Attributes["SR SAM"] and
not Attributes["IR Guided SAM"] then ThreatLevel = 8
elseif ( Attributes["SR SAM"] or Attributes["MANPADS"] ) and
Attributes["IR Guided SAM"] then ThreatLevel = 7
elseif Attributes["AAA"] then ThreatLevel = 6
elseif Attributes["Modern Tanks"] then ThreatLevel = 5
elseif ( Attributes["Tanks"] or Attributes["IFV"] ) and
Attributes["ATGM"] then ThreatLevel = 4
elseif ( Attributes["Tanks"] or Attributes["IFV"] ) and
not Attributes["ATGM"] then ThreatLevel = 3
elseif Attributes["Old Tanks"] or Attributes["APC"] or Attributes["Artillery"] then ThreatLevel = 2
elseif Attributes["Infantry"] then ThreatLevel = 1
end
ThreatText = ThreatLevels[ThreatLevel+1]
end end
ThreatText = ThreatLevels[ThreatLevel+1] if self:IsAir() then
end
if self:IsAir() then
self:T( "Air" )
local ThreatLevels = {
"Unarmed",
"Tanker",
"AWACS",
"Transport Helicopter",
"UAV",
"Bomber",
"Strategic Bomber",
"Attack Helicopter",
"Battleplane",
"Multirole Fighter",
"Fighter"
}
self:T( "Air" )
if Attributes["Fighters"] then ThreatLevel = 10
elseif Attributes["Multirole fighters"] then ThreatLevel = 9 local ThreatLevels = {
elseif Attributes["Battleplanes"] then ThreatLevel = 8 "Unarmed",
elseif Attributes["Attack helicopters"] then ThreatLevel = 7 "Tanker",
elseif Attributes["Strategic bombers"] then ThreatLevel = 6 "AWACS",
elseif Attributes["Bombers"] then ThreatLevel = 5 "Transport Helicopter",
elseif Attributes["UAVs"] then ThreatLevel = 4 "UAV",
elseif Attributes["Transport helicopters"] then ThreatLevel = 3 "Bomber",
elseif Attributes["AWACS"] then ThreatLevel = 2 "Strategic Bomber",
elseif Attributes["Tankers"] then ThreatLevel = 1 "Attack Helicopter",
"Battleplane",
"Multirole Fighter",
"Fighter"
}
if Attributes["Fighters"] then ThreatLevel = 10
elseif Attributes["Multirole fighters"] then ThreatLevel = 9
elseif Attributes["Battleplanes"] then ThreatLevel = 8
elseif Attributes["Attack helicopters"] then ThreatLevel = 7
elseif Attributes["Strategic bombers"] then ThreatLevel = 6
elseif Attributes["Bombers"] then ThreatLevel = 5
elseif Attributes["UAVs"] then ThreatLevel = 4
elseif Attributes["Transport helicopters"] then ThreatLevel = 3
elseif Attributes["AWACS"] then ThreatLevel = 2
elseif Attributes["Tankers"] then ThreatLevel = 1
end
ThreatText = ThreatLevels[ThreatLevel+1]
end end
ThreatText = ThreatLevels[ThreatLevel+1]
end
if self:IsShip() then
self:T( "Ship" )
--["Aircraft Carriers"] = {"Heavy armed ships",},
--["Cruisers"] = {"Heavy armed ships",},
--["Destroyers"] = {"Heavy armed ships",},
--["Frigates"] = {"Heavy armed ships",},
--["Corvettes"] = {"Heavy armed ships",},
--["Heavy armed ships"] = {"Armed ships", "Armed Air Defence", "HeavyArmoredUnits",},
--["Light armed ships"] = {"Armed ships","NonArmoredUnits"},
--["Armed ships"] = {"Ships"},
--["Unarmed ships"] = {"Ships","HeavyArmoredUnits",},
local ThreatLevels = {
"Unarmed ship",
"Light armed ships",
"Corvettes",
"",
"Frigates",
"",
"Cruiser",
"",
"Destroyer",
"",
"Aircraft Carrier"
}
if self:IsShip() then
self:T( "Ship" )
--["Aircraft Carriers"] = {"Heavy armed ships",},
--["Cruisers"] = {"Heavy armed ships",},
--["Destroyers"] = {"Heavy armed ships",},
--["Frigates"] = {"Heavy armed ships",},
--["Corvettes"] = {"Heavy armed ships",},
--["Heavy armed ships"] = {"Armed ships", "Armed Air Defence", "HeavyArmoredUnits",},
--["Light armed ships"] = {"Armed ships","NonArmoredUnits"},
--["Armed ships"] = {"Ships"},
--["Unarmed ships"] = {"Ships","HeavyArmoredUnits",},
if Attributes["Aircraft Carriers"] then ThreatLevel = 10 local ThreatLevels = {
elseif Attributes["Destroyers"] then ThreatLevel = 8 "Unarmed ship",
elseif Attributes["Cruisers"] then ThreatLevel = 6 "Light armed ships",
elseif Attributes["Frigates"] then ThreatLevel = 4 "Corvettes",
elseif Attributes["Corvettes"] then ThreatLevel = 2 "",
elseif Attributes["Light armed ships"] then ThreatLevel = 1 "Frigates",
"",
"Cruiser",
"",
"Destroyer",
"",
"Aircraft Carrier"
}
if Attributes["Aircraft Carriers"] then ThreatLevel = 10
elseif Attributes["Destroyers"] then ThreatLevel = 8
elseif Attributes["Cruisers"] then ThreatLevel = 6
elseif Attributes["Frigates"] then ThreatLevel = 4
elseif Attributes["Corvettes"] then ThreatLevel = 2
elseif Attributes["Light armed ships"] then ThreatLevel = 1
end
ThreatText = ThreatLevels[ThreatLevel+1]
end end
ThreatText = ThreatLevels[ThreatLevel+1]
end end
self:T2( ThreatLevel ) self:T2( ThreatLevel )