Skip to content

The Fat Cow tests for the ground with raw unit:inAir(), the exact case (CH-47) ctld.utils.inAir exists for #295

Closed

Description

@davidp57

Found by an automated review of develop at commit 1b61b10. The code has moved since: at commit dba0410, src/CTLD_fatCow.lua:252 (deploy) and :1225 (orderLandHere).

What is wrong

src/CTLD_fatCow.lua:275, in CTLDFatCowManager:deploy (:272):

function CTLDFatCowManager:deploy(unit)
    local cow = self._cows[unit:getName()]
    if not cow then return false, "unknown" end
    if unit:inAir() then return false, "airborne" end   -- 275

and src/CTLD_fatCow.lua:1080, in CTLDFatCowManager:orderLandHere (:1075):

    if not u:inAir() then
        trigger.action.outTextForGroup(..., ctld.tr("The Fat Cow is already on the ground."), 10)
        return
    end

Both call DCS's native inAir().
The repository has a replacement for exactly this, ctld.utils.inAir (src/CTLD_utils.lua:2225), whose header comment (:2173-2178) says:

Secondary check: if inAir()=true but the unit is below groundAglThreshold (config) AND nearly stationary (speed < 0.5 m/s), it is treated as on the ground.
This handles high-chassis aircraft (e.g. CH-47) whose fuselage centre sits above DCS's internal inAir threshold even when fully at rest on the ground.

The aircraft named in this comment is the one the whole feature relies on: fatCowTypes: [CH-47Fbl1] and fatCowAIType: CH-47Fbl1 (src/CTLD_config.yaml:280,420-421).
The rest of src/ goes through the helper everywhere; the only two other raw :inAir() calls are in src/scenes/CTLD_mineFieldScene.lua and predate this batch.

What can follow

AI cow — the FARP never opens, silently. onLand (:996) arms a timer which, after fatCowDeployDelay (60 s by default), calls mgr:deploy(u) on a cow that has landed and is stationary.
This is the textbook case ctld.utils.inAir was written to catch: deploy answers false, "airborne", the return value is not read (:1016), and there is neither a message to the flight nor a log line.
The flight waits for a FARP that will not open, and the only remedy visible on the player side (Take off then Land here) runs into the same refusal.

Piloted cow — the wrong message. deployFromHold (:632) first filters with ctld.utils.inAir(t) and so lets a landed CH-47 through; deploy then rejects it with "airborne", which deployFromHold does not distinguish and translates into the catch-all message "The Fat Cow FARP could not be deployed." (:650).
The pilot is on the ground, has his crates in the hold, and reads that the deployment failed — without ever learning that DCS thinks he is airborne.

orderLandHere. The same bias disarms the guard: a landed CH-47 reads inAir() == true, so "The Fat Cow is already on the ground." never goes out and the cow is re-tasked to land while it is already on the ground.

What makes the finding invisible to the tests

The suite is extensive (fatcow_core_spec.lua, fatcow_ai_spec.lua, fatcow_piloted_spec.lua), but it stubs both forms on the same flag, which makes them indistinguishable:

-- tests/ci/unit/fatcow_ai_spec.lua:24 and :90
function u:inAir() return self.airborne end
ctld.utils.inAir = function(u) return u.airborne end

So no test can see the divergence: it would take a mock where unit:inAir() returns true and ctld.utils.inAir returns false — the CH-47 at rest.

Proposed fix

-- :275
if ctld.utils.inAir(unit) then return false, "airborne" end

-- :1080
if not ctld.utils.inAir(u) then

and a test case that pins the distinction, for example in fatcow_ai_spec.lua: a cow whose u:inAir() returns true and ctld.utils.inAir returns false must deploy its FARP when the delay expires.

Activity

  1. FullGas1 commented on Nov 18, 2026

    @FullGas1
    Collaborator

    Fixed in #320, merged into develop. It will be in the next release, and in the floating dev pre-release meanwhile.

    The analysis held, with one more place than the issue lists. The Fat Cow called DCS's raw inAir() at three places, and all three now ask ctld.utils.inAir:

    • deploy: a landed cow is no longer refused as "airborne". An AI cow's FARP opens when the delay runs out, and a piloted cow's pilot, on the ground with his crates in the hold, no longer reads "The Fat Cow FARP could not be deployed.". A cow really in the air is still refused with the reason "airborne".
    • orderLandHere: "The Fat Cow is already on the ground." fires again for a landed cow, which is not re-tasked. A cow really in the air is still sent to land.
    • freeAICow (not in the issue): with the raw call, a landed cow was taken for an airborne one and given an orbit task on Release the Fat Cow, so it lifted off from its open FARP and left it behind, against the pilot guide. A landed cow now stays where it is with its FARP open; a cow really in the air still orbits where it stands.

    The two raw calls of the mine field scene are untouched: another component, not analysed here, and older than this batch. If they matter they deserve a lot of their own.

    The specs stubbed the raw form and the helper on the same flag, so they could not tell them apart. The new cases use a unit that disagrees with itself, the CH-47 at rest (raw inAir() says "in the air", the helper says "on the ground"): four were red before the change (the AI cow's FARP not deployed, no "already on the ground", an orbit task given to a landed cow, the piloted FARP not opened), and controls with a cow really in the air pass before and after. A core-spec case also exercises the real helper with a landed CH-47, and one existing mock that lacked a velocity was completed now that the deployment reads it.

    I did not re-measure DCS's raw answer for a landed CH-47 on the current version, and I did not check this in a live mission. The helper's own documentation (inherited from v1) is the premise, and the fix is right whether or not DCS still misreports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions