Skip to content

Fix for Deployed units (Nuke Cannon) - #3035

Open
CookieLandProjects wants to merge 1 commit into
TheSuperHackers:mainfrom
CookieLandProjects:feature/deployfix
Open

Fix for Deployed units (Nuke Cannon)#3035
CookieLandProjects wants to merge 1 commit into
TheSuperHackers:mainfrom
CookieLandProjects:feature/deployfix

Conversation

@CookieLandProjects

@CookieLandProjects CookieLandProjects commented Jul 31, 2026

Copy link
Copy Markdown

Deployable unit fixes!

This PR fixes:

Deployed unit redeploys after each kill when guarding. #377
Deployed unit redeploys when there are no targets nearby even though he is at the center of guard area.
Deployed unit fully deploys even though target exited the weapon range.

Instead it now:

Deployed unit doesn't redeploy after each kill, only when no enemies are in guard range.
Deployed unit stays deployed if he is already at the center of guard area.
Deployed unit reverses deploy animation if target exits weapon range.

Additionally, setting a deployed unit to guard right under its already deployed position will NOT make him redeploy, he will stay where he is.

#377 can be closed.

Videos:

This one was over 10MB ;p
https://youtu.be/Nu5hc7ALM0g?si=Vl2WK28kRuIlnkcw

2026-07-31.10-44-25.mp4

@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adjusts deployable-unit guard and deployment transitions.

  • Retains an active guard attack state when another enemy is immediately available.
  • Avoids issuing a return movement when the unit is already at the guard center.
  • Reverses an in-progress deployment when the current target leaves weapon range.

Confidence Score: 4/5

The deployment boundary-frame failure should be fixed before merging because a target can leave range while the unit still completes deployment.

The deploy timer is finalized before the new reversal condition, changing the state to READY_TO_ATTACK and preventing the reversal precisely when deployment expires.

Files Needing Attention: GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeployStyleAIUpdate.cpp

Important Files Changed

Filename Overview
GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp Reuses guard attack behavior across successive targets and skips unnecessary return movement when already near the guard center; no independently actionable defect was established.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeployStyleAIUpdate.cpp Adds out-of-range deploy reversal, but its placement after timer completion misses the final deployment frame.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Deploy update] --> B{Deploy timer expired?}
  B -- Yes --> C[State becomes READY_TO_ATTACK]
  B -- No --> D[State remains DEPLOY]
  C --> E{Trying to attack out of range<br/>and state is DEPLOY?}
  D --> E
  E -- Yes --> F[Reverse to UNDEPLOY]
  E -- No after timer expiry --> G[Remain fully deployed]
Loading
Prompt To Fix All With AI
### Issue 1
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeployStyleAIUpdate.cpp:149
**Deployment reversal misses expiry frame**

When the target leaves range on the update where the deployment timer expires, the preceding timer block changes `m_state` from `DEPLOY` to `READY_TO_ATTACK` before this condition runs. The `m_state == DEPLOY` check then prevents reversal, causing the unit to finish deploying despite its target already being out of range.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "Fix for Deployed units (Nuke Cannon)" | Re-trigger Greptile

// TheSuperHackers @bugfix CookieLandProjects 31/07/2026 - This keeps deployed units from fully deploying even though their target exited the range,
// instead reverse the deploy.
#if !RETAIL_COMPATIBLE_CRC
if (m_state == DEPLOY && isTryingToAttack && !isInRange)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Deployment reversal misses expiry frame

When the target leaves range on the update where the deployment timer expires, the preceding timer block changes m_state from DEPLOY to READY_TO_ATTACK before this condition runs. The m_state == DEPLOY check then prevents reversal, causing the unit to finish deploying despite its target already being out of range.

Knowledge Base Used: GameLogic simulation

Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeployStyleAIUpdate.cpp
Line: 149

Comment:
**Deployment reversal misses expiry frame**

When the target leaves range on the update where the deployment timer expires, the preceding timer block changes `m_state` from `DEPLOY` to `READY_TO_ATTACK` before this condition runs. The `m_state == DEPLOY` check then prevents reversal, causing the unit to finish deploying despite its target already being out of range.

**Knowledge Base Used:** [GameLogic simulation](https://app.greptile.com/thesuperhackers/-/custom-context/knowledge-base/thesuperhackers/generalsgamecode/-/docs/gamelogic-simulation.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@Skyaero42 Skyaero42 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.

PR title needs change too.

m_exitConditions.m_center = *targetToGuard->getPosition();
}

// TheSuperHackers @bugfix CookieLandProjects 31/07/2026 - This keeps deployed units from moving/undeploying immediately

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

a more concise comment would be easier to read and understand

// If attack finished successfully (target died), check instantly for another enemy in guard range.
if (ret == STATE_SUCCESS)
{
// If we find another enemy in guard range. Recreate the attack state and continue attacking.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

imperative mood is preferred over first person plural ("we")

StateReturnType enterRet = m_attackState->onEnter();
if (enterRet == STATE_CONTINUE)
return STATE_CONTINUE;
return enterRet;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add whiteline for readability.

// If attack finished successfully (target died), check instantly for another enemy in guard range.
if (ret == STATE_SUCCESS)
{
// If we find another enemy in guard range. Recreate the attack state and continue attacking.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't the cannon be deployed anyways in guard or stop mode,, even if there is no enemy?

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.

Yes. But on every kill the nuke cannon decides to redeploy then retarget. Check the mentioned issue for reference.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, I'm aware of that. But what if the nuke cannon has a kill, but there are no other targets in range. What I make up from your code is that it will still redeploy - as you only seem to stop the redeploy if there is another target. Or am I reading that wrong?

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.

The nuke cannon will ONLY redeploy if he is not near the guard center (expected behavior)
Since if u set to guard a specific area, he has to first clear out every enemy within that guard area before going to center and deploying for the last time, never to undeploy again (unless something gets in its MinimumAttackRange).

}
}

// TheSuperHackers @bugfix CookieLandProjects 31/07/2026 - This keeps deployed units from fully deploying even though their target exited the range,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The comment is confusing. "This keeps deployed units from fully deploying"

area->getCenterPoint(&m_goalPosition);
}

// TheSuperHackers @bugfix CookieLandProjects 31/07/2026 - This keeps deployed units from moving/undeploying even though we are already

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't understand the comment

{
if (m_frameToWaitForDeploy != 0)
{
// Reverse the deploy at its current frame so we dont finish deploying fully.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use imperative mood for comments

}
else
{
// No pending deploy timer? Make sure we transition to undeploy state.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use imperative mood for comments

@Caball009

Copy link
Copy Markdown

(Some of) these changes should probably be evaluated by the design committee.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants