bugfix(ai): Do not rebuild the locomotor set of a dead aircraft - #3072
Open
wh1ter0se69 wants to merge 2 commits into
Open
bugfix(ai): Do not rebuild the locomotor set of a dead aircraft#3072wh1ter0se69 wants to merge 2 commits into
wh1ter0se69 wants to merge 2 commits into
Conversation
A slow death module disables flight by mutating the current Locomotor instance - JetSlowDeathBehavior applies a negative maxLift and a zero maxTurnRate. A dead aircraft's AI keeps running, and when it changes locomotor set, chooseLocomotorSetExplicit() clears the set (deleting every Locomotor) and rebuilds from template, whose constructor resets both back to BIGNUM. The wreck regains full lift and turn rate and circles forever, since DestructionDelay is effectively infinite. This lives in AIUpdateInterface because every aircraft reaches it, which is why the issue is reported for jets and helicopters alike. Verified on a VC6 release build: the captured wreck falls to the ground in ~3 seconds instead of circling, and the 10-replay 1.04 corpus still completes 10/10 with zero CRC errors, byte-identical to the unfixed run.
This changes simulation behaviour, so per the policy in GameDefines.h it must not be active in a retail compatible build. It is compiled out by default and becomes live when the project flips RETAIL_COMPATIBLE_CRC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What happens
JetSlowDeathBehavior::beginSlowDeath()grounds a dying aircraft by mutating the currentLocomotorinstance:A dead aircraft's AI keeps running - there is no death guard in
AIUpdateInterface::update()-and when it changes locomotor set,
chooseLocomotorSetExplicit()throws that instance away:and
Locomotor::Locomotor(const LocomotorTemplate*)starts fresh:So the wreck silently regains full lift and full turn rate. It is no longer falling - it is a
flying aircraft with no pilot, and
DestructionDelay = 99999999means nothing removes it. Itcircles until the match ends.
The fix refuses the rebuild for an effectively-dead aircraft, so the slow-death locomotor
survives and the wreck falls.
Why this file
The bug is in
AIUpdateInterface, not in a slow-death module. Every aircraft reacheschooseLocomotorSetExplicit(), which is why the issue reports jets and helicopters - Aurora,Raptor, Chinook, Comanche, MIG, Helix. A fix in
JetSlowDeathBehaviorcould never have coveredthe helicopters.
Refinement of the 2023 hypothesis
The guess in the issue thread was "if plane dies while it changes state to return to airfield".
Right shape, wrong specific. The captured trigger was
LOCOMOTORSET_SLUGGISH, reached from aGuard order - not the return-to-airfield path. A fix targeting only that path would have
missed it.
Evidence
Measured on a VC6 Release build (
RTS_BUILD_OPTION_DEBUG=OFF), with a temporary probelogging any locomotor-set rebuild on an effectively-dead aircraft.
Reproduction, captured live (USA Superweapon, Auroras guarded then killed airborne):
newset=7isLOCOMOTORSET_SLUGGISH;hadLoco=1confirms the slow-death locomotor was presentand was about to be discarded;
airborne=1confirms it was still in the air.A/B on that recording, same binary, fix toggled by env var so playback is identical up to the
first block:
airborne=1, circles indefinitelyairborne=0at frame 18894 - falls in ~3 secondsThe CRC mismatch that follows in the fixed run is expected: the wreck now hits the ground, so the
simulation legitimately diverges from a recording of the broken behaviour.
No regression, against the full
GeneralsReplays/GeneralsZH/1.04CI corpus - 10 replays,roughly four hours of game time:
Both passes produced byte-identical stdout. The replay corpus still passes with this fix
enabled, so it does not need to be gated behind a retail-compatibility macro - the guard only
engages on an already-dead aircraft, a state the corpus never reaches.
Known limits
Stated plainly rather than left for review to find:
from code structure - both the bug and the fix are in code every aircraft executes - not from
measuring each aircraft. Only the Aurora path was reproduced end to end.
JetAIUpdatecallssetMaxLift()directly in several places for landing/takeoff sequencing.Those bypass the locomotor set change entirely, so this fix does not intercept them. Whether
they are reachable on a dead jet is not established here.
capture above). Harmless and cheap, but it indicates the state machine is spinning on a
transition it can never complete. A broader fix - not driving a dead aircraft's AI at all -
may be the better long-term shape, and is a bigger behavioural change than this one.