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 if ClosestDistance == 0 or Distance < ClosestDistance then
-- Only intercept if the distance to target is smaller or equal to the GciRadius limit. -- Only intercept if the distance to target is smaller or equal to the GciRadius limit.
if Distance <= self.GciRadius then if Distance <= self.GciRadius then
ClosestDistance = Distance ClosestDistance = Distance
ClosestDefenderSquadronName = SquadronName 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", self:T( "Ground" )
"Modern Tanks",
"AAA", local ThreatLevels = {
"IR Guided SAMs", "Unarmed",
"SR SAMs", "Infantry",
"MR SAMs", "Old Tanks & APCs",
"LR SAMs" "Tanks & IFVs without ATGM",
} "Tanks & IFV with ATGM",
"Modern Tanks",
"AAA",
"IR Guided SAMs",
"SR SAMs",
"MR SAMs",
"LR SAMs"
}
if Attributes["LR SAM"] then ThreatLevel = 10 if Attributes["LR SAM"] then ThreatLevel = 10
elseif Attributes["MR SAM"] then ThreatLevel = 9 elseif Attributes["MR SAM"] then ThreatLevel = 9
elseif Attributes["SR SAM"] and elseif Attributes["SR SAM"] and
not Attributes["IR Guided SAM"] then ThreatLevel = 8 not Attributes["IR Guided SAM"] then ThreatLevel = 8
elseif ( Attributes["SR SAM"] or Attributes["MANPADS"] ) and elseif ( Attributes["SR SAM"] or Attributes["MANPADS"] ) and
Attributes["IR Guided SAM"] then ThreatLevel = 7 Attributes["IR Guided SAM"] then ThreatLevel = 7
elseif Attributes["AAA"] then ThreatLevel = 6 elseif Attributes["AAA"] then ThreatLevel = 6
elseif Attributes["Modern Tanks"] then ThreatLevel = 5 elseif Attributes["Modern Tanks"] then ThreatLevel = 5
elseif ( Attributes["Tanks"] or Attributes["IFV"] ) and elseif ( Attributes["Tanks"] or Attributes["IFV"] ) and
Attributes["ATGM"] then ThreatLevel = 4 Attributes["ATGM"] then ThreatLevel = 4
elseif ( Attributes["Tanks"] or Attributes["IFV"] ) and elseif ( Attributes["Tanks"] or Attributes["IFV"] ) and
not Attributes["ATGM"] then ThreatLevel = 3 not Attributes["ATGM"] then ThreatLevel = 3
elseif Attributes["Old Tanks"] or Attributes["APC"] or Attributes["Artillery"] then ThreatLevel = 2 elseif Attributes["Old Tanks"] or Attributes["APC"] or Attributes["Artillery"] then ThreatLevel = 2
elseif Attributes["Infantry"] then ThreatLevel = 1 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" )
self:T( "Air" ) local ThreatLevels = {
"Unarmed",
local ThreatLevels = { "Tanker",
"Unarmed", "AWACS",
"Tanker", "Transport Helicopter",
"AWACS", "UAV",
"Transport Helicopter", "Bomber",
"UAV", "Strategic Bomber",
"Bomber", "Attack Helicopter",
"Strategic Bomber", "Battleplane",
"Attack Helicopter", "Multirole Fighter",
"Battleplane", "Fighter"
"Multirole Fighter", }
"Fighter"
}
if Attributes["Fighters"] then ThreatLevel = 10 if Attributes["Fighters"] then ThreatLevel = 10
elseif Attributes["Multirole fighters"] then ThreatLevel = 9 elseif Attributes["Multirole fighters"] then ThreatLevel = 9
elseif Attributes["Battleplanes"] then ThreatLevel = 8 elseif Attributes["Battleplanes"] then ThreatLevel = 8
elseif Attributes["Attack helicopters"] then ThreatLevel = 7 elseif Attributes["Attack helicopters"] then ThreatLevel = 7
elseif Attributes["Strategic bombers"] then ThreatLevel = 6 elseif Attributes["Strategic bombers"] then ThreatLevel = 6
elseif Attributes["Bombers"] then ThreatLevel = 5 elseif Attributes["Bombers"] then ThreatLevel = 5
elseif Attributes["UAVs"] then ThreatLevel = 4 elseif Attributes["UAVs"] then ThreatLevel = 4
elseif Attributes["Transport helicopters"] then ThreatLevel = 3 elseif Attributes["Transport helicopters"] then ThreatLevel = 3
elseif Attributes["AWACS"] then ThreatLevel = 2 elseif Attributes["AWACS"] then ThreatLevel = 2
elseif Attributes["Tankers"] then ThreatLevel = 1 elseif Attributes["Tankers"] then ThreatLevel = 1
end
ThreatText = ThreatLevels[ThreatLevel+1]
end end
ThreatText = ThreatLevels[ThreatLevel+1] if self:IsShip() then
end
if self:IsShip() then self:T( "Ship" )
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",},
--["Aircraft Carriers"] = {"Heavy armed ships",}, local ThreatLevels = {
--["Cruisers"] = {"Heavy armed ships",}, "Unarmed ship",
--["Destroyers"] = {"Heavy armed ships",}, "Light armed ships",
--["Frigates"] = {"Heavy armed ships",}, "Corvettes",
--["Corvettes"] = {"Heavy armed ships",}, "",
--["Heavy armed ships"] = {"Armed ships", "Armed Air Defence", "HeavyArmoredUnits",}, "Frigates",
--["Light armed ships"] = {"Armed ships","NonArmoredUnits"}, "",
--["Armed ships"] = {"Ships"}, "Cruiser",
--["Unarmed ships"] = {"Ships","HeavyArmoredUnits",}, "",
"Destroyer",
local ThreatLevels = { "",
"Unarmed ship", "Aircraft Carrier"
"Light armed ships", }
"Corvettes",
"",
"Frigates",
"",
"Cruiser",
"",
"Destroyer",
"",
"Aircraft Carrier"
}
if Attributes["Aircraft Carriers"] then ThreatLevel = 10 if Attributes["Aircraft Carriers"] then ThreatLevel = 10
elseif Attributes["Destroyers"] then ThreatLevel = 8 elseif Attributes["Destroyers"] then ThreatLevel = 8
elseif Attributes["Cruisers"] then ThreatLevel = 6 elseif Attributes["Cruisers"] then ThreatLevel = 6
elseif Attributes["Frigates"] then ThreatLevel = 4 elseif Attributes["Frigates"] then ThreatLevel = 4
elseif Attributes["Corvettes"] then ThreatLevel = 2 elseif Attributes["Corvettes"] then ThreatLevel = 2
elseif Attributes["Light armed ships"] then ThreatLevel = 1 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 )