fa icon indicating copy to clipboard operation
fa copied to clipboard

Logic flaw in AirStagingThread function

Open relent0r opened this issue 3 years ago • 1 comments

note : I'm going to rewrite this function for my AI so once I've got it reliable I'll push it in to replace the faf equivalents. This is just for tracking.

Function location : \lua\ai\aibehaviors.lua

Issue exist in both AirStagingThread and AirStagingThreadSorian I believe. I've seen this issue crop up sporadically during testing and finally got sick of it so investigated the cause.

Issue : When the refuelling behaviour is applied to air units they will periodically check if they are below a certain threashold. If so they will find the closest air staging platform with 400 units and add themselves to the platforms Refueling table. When the AI has an air staging thread running for an air staging platform it performs this loop which dictates if refuelled units will go back into combat.

for _, v in unit.Refueling do
     if not v.Dead and (v:GetFuelRatio() < 0.9 or v:GetHealthPercent() < 0.9) then
          ready = false
     elseif not v.Dead then
          numUnits = numUnits + 1
     end
end
if ready and numUnits > 0 then
    *do post refuel stuff here
end

The issue is that if ANY unit in the unit.Refueling table does not having full fuel or health then no air units will get reassigned to a platoon. The will result in air units staying on the ground for prolonged periods of time after the first air staging platform comes up and multiple air units return to refuel from across the map. Also if an air unit is assigned to the Refueling table and never actually comes to refuel and v.Dead is not true then all refuelled units will remain at the air staging platform until it dies. I've seen this happen when an air platoon has multiple air units and they all trigger a refuel but not all actually return and attach, unsure the cause but it highlights the issue.

The expectation is that as soon as the units are refuelled they will be assigned to a new platoon and put back into service. A clear and concise description of what you expected to happen.

My initial thoughts on correcting this is to insert refueled air units into a new table if they are above 0.9 fuel/health and remove the 'ready' bool, if numUnits is > 0 then it will loop through the new table to assign units to platoons from there. I just need to proof it and make sure it doesn't have obvious flaws. image

relent0r avatar Jul 31 '22 02:07 relent0r

Sounds like an exciting bug - looking forward to the pull request

Garanas avatar Jul 31 '22 04:07 Garanas