Skip to content

bugfix(ai): Prevent units from deploying when moving - #3016

Open
Caball009 wants to merge 1 commit into
TheSuperHackers:mainfrom
Caball009:fix_object_deployment
Open

bugfix(ai): Prevent units from deploying when moving#3016
Caball009 wants to merge 1 commit into
TheSuperHackers:mainfrom
Caball009:fix_object_deployment

Conversation

@Caball009

@Caball009 Caball009 commented Jul 26, 2026

Copy link
Copy Markdown

This PR prevents units from deploying when they're still moving. The issue is most notable with the Nuke Cannon, which deploys and fires just ahead reaching its goal position (see issue).

The pathfinding code uses Weapon::isGoalPosWithinAttackRange, while the deployment code uses isWithinAttackRange. The former uses a smaller range than strictly necessary, so that attacks don't fail all the time on moving targets. That's why units deploy just ahead of reaching their goal position.

#176 (comment)

Notes:

  • This is probably a very minor nerf because the attack range has been reduced a tiny bit.
  • This change assumes that unit movement and deployment are always mutually exclusive.

@Caball009 Caball009 added AI Is AI related Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour NoRetail This fix or change is not applicable with Retail game compatibility labels Jul 26, 2026
@Caball009
Caball009 force-pushed the fix_object_deployment branch 2 times, most recently from e3a6993 to 7a918c9 Compare July 27, 2026 11:15
@Caball009

Caball009 commented Jul 29, 2026

Copy link
Copy Markdown
Author

I tried using isGoalPosWithinAttackRange for deployment as well, but that had mixed results because sometimes the Nuke Cannon wouldn't deploy at all.

Even if fixed, an isMoving check is still necessary because units might get a range bonus after receiving an attack order but before reaching their goal position; without it, units could still deploy too early.

@Caball009
Caball009 marked this pull request as ready for review July 29, 2026 12:38
@greptile-apps

greptile-apps Bot commented Jul 29, 2026

Copy link
Copy Markdown

Greptile Summary

Prevents deploy-style Zero Hour units from deploying while their AI reports active movement.

  • Preserves original behavior for retail-compatible CRC builds.
  • Adds a movement check before range-triggered deployment in non-retail builds.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code regression identified.

The new condition blocks range-triggered deployment while movement is active, while existing move handling still transitions deployed or deploying units toward undeployment.

Important Files Changed

Filename Overview
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeployStyleAIUpdate.cpp Adds a non-retail movement guard to range-triggered deployment without changing guard-idle or retail-compatible behavior.

Reviews (1): Last reviewed commit: "bugfix(ai): Prevent units from deploying..." | Re-trigger Greptile

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be replicated to Generals?

#if RETAIL_COMPATIBLE_CRC
if( isInRange || isInGuardIdleState )
#else
if( (isInRange && !ai->isMoving()) || isInGuardIdleState )

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the isTryingToMove and ai->isMoving() should be consolidated. Do both of them try to conclude the same condition?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll have a look.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that works; changed.

@xezon

xezon commented Aug 1, 2026

Copy link
Copy Markdown

I tested this branch and it does not fix the Nuke Cannon deployment bug. Tested on map https://github.com/TheSuperHackers/GeneralsGamePatch/tree/main/Maps/Any/!TestAllFactionsBuildingsUnitsPromo

@Stubbjax

Stubbjax commented Aug 1, 2026

Copy link
Copy Markdown

I tested this branch and it does not fix the Nuke Cannon deployment bug. Tested on map https://github.com/TheSuperHackers/GeneralsGamePatch/tree/main/Maps/Any/!TestAllFactionsBuildingsUnitsPromo

It does appear to fix TheSuperHackers/GeneralsGamePatch#269 though.

@xezon

xezon commented Aug 1, 2026

Copy link
Copy Markdown

Accidental fix )

@Caball009

Caball009 commented Aug 1, 2026

Copy link
Copy Markdown
Author

I tested this branch and it does not fix the Nuke Cannon deployment bug. Tested on map https://github.com/TheSuperHackers/GeneralsGamePatch/tree/main/Maps/Any/!TestAllFactionsBuildingsUnitsPromo

Can you share a VS22 replay of this?

@xezon

xezon commented Aug 1, 2026

Copy link
Copy Markdown

Repro: Put Guard Mode behind a blob of units on this test map.

@Caball009

Caball009 commented Aug 1, 2026

Copy link
Copy Markdown
Author

I suspect you're seeing other yet unfixed issues with the Nuke Cannon. With the fix in place, I cannot reproduce the issue shown in the video here #176 (comment). Would like to see a VS22 replay still.

@Stubbjax

Stubbjax commented Aug 1, 2026

Copy link
Copy Markdown

Repro: Put Guard Mode behind a blob of units on this test map.

Try attacking a target outside the Nuke Cannon's range and observe whether it creeps forward after deployment.

@Caball009
Caball009 force-pushed the fix_object_deployment branch from 7a918c9 to 9b29c05 Compare August 1, 2026 18:04
@Caball009

Copy link
Copy Markdown
Author

Needs to be replicated to Generals?

I haven't verified this, but the posts in the issue suggest this is not an issue for Generals. Function DeployStyleAIUpdate::update is quite different there.

@xezon

xezon commented Aug 1, 2026

Copy link
Copy Markdown

Here is replay with this branch in RTS_DEBUG vs22 build.

nuke_cannon_bug.zip

@Caball009

Copy link
Copy Markdown
Author

The fix is non-retail. It seems like you're testing without removing the retail compatibility guard.

@xezon

xezon commented Aug 1, 2026

Copy link
Copy Markdown

Ohhhhhhhhhhhhhhhhhhhh silly me......

time to go to sleep

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

Labels

AI Is AI related Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker NoRetail This fix or change is not applicable with Retail game compatibility ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

China Nuke Cannon can creep forward after firing

3 participants