Updates to decision engine of the AI_A2G_DISPATCHER

This commit is contained in:
FlightControl 2019-03-09 10:09:03 +01:00
parent d72e89d52b
commit 10b96f6cce
3 changed files with 3325 additions and 3 deletions

View File

@ -1143,7 +1143,9 @@ do -- AI_A2G_DISPATCHER
for Resource = 1, DefenderSquadron.ResourceCount or 0 do
self:ResourcePark( DefenderSquadron )
end
self:I( "Parked resources for squadron " .. DefenderSquadron.Name )
end
end
@ -3771,7 +3773,7 @@ do -- AI_A2G_DISPATCHER
self:F( { DefenderSquadrons = self.DefenderSquadrons } )
for SquadronName, DefenderSquadron in pairs( self.DefenderSquadrons or {} ) do
for SquadronName, DefenderSquadron in UTILS.rpairs( self.DefenderSquadrons or {} ) do
if DefenderSquadron[DefenseTaskType] then
@ -3792,8 +3794,12 @@ do -- AI_A2G_DISPATCHER
-- Check if there is a defense line...
local HasDefenseLine = self:HasDefenseLine( AirbaseCoordinate, DetectedItem )
if HasDefenseLine == true then
ClosestDistance = InterceptDistance
ClosestDefenderSquadronName = SquadronName
local ProbabilityRange = ( self.DefenseRadius - InterceptDistance ) / self.DefenseRadius
local Probability = math.random()
if Probability > ProbabilityRange then
ClosestDistance = InterceptDistance
ClosestDefenderSquadronName = SquadronName
end
end
end
end

File diff suppressed because it is too large Load Diff

View File

@ -519,6 +519,31 @@ function UTILS.spairs( t, order )
end
end
-- Here is a customized version of pairs, which I called rpairs because it iterates over the table in a random order.
function UTILS.rpairs( t )
-- collect the keys
local keys = {}
for k in pairs(t) do keys[#keys+1] = k end
local random = {}
local j = #keys
for i = 1, j do
local k = math.random( 1, #keys )
random[i] = keys[k]
table.remove( keys, k )
end
-- return the iterator function
local i = 0
return function()
i = i + 1
if random[i] then
return random[i], t[random[i]]
end
end
end
-- get a new mark ID for markings
function UTILS.GetMarkID()