bugfix(ai): Fix bugged unit behavior when attacked during guard mode#2197
Conversation
|
| Filename | Overview |
|---|---|
| Generals/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp | Wraps AI_GUARD_RETURN state definition with #if RETAIL_COMPATIBLE_CRC to remove the attackAggressors handler on the fix path; AI_GUARD_INNER already had no such handler in the Generals codebase. |
| GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp | Both AI_GUARD_INNER and AI_GUARD_RETURN are wrapped; the attackAggressors handler is stripped from both states on the fix path, matching the ZH-specific retail behavior described in the PR. |
| GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuardRetaliate.cpp | Only AI_GUARD_RETALIATE_RETURN is wrapped; AI_GUARD_RETALIATE_INNER already had no attackAggressors in the original code, so the fix is correctly scoped. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
subgraph RETAIL["RETAIL_COMPATIBLE_CRC = 1 (original retail)"]
R1[AI_GUARD_RETURN + attackAggressors] -->|success| R2[AI_GUARD_IDLE + attackAggressors]
R1 -->|attacked| R_ATK[AI_GUARD_ATTACK_AGGRESSOR]
R2 -->|enemy in range| R3[AI_GUARD_INNER + attackAggressors]
R3 -->|attacked| R_ATK
R_ATK --> R1
end
subgraph FIX["RETAIL_COMPATIBLE_CRC = 0 (fix)"]
F1[AI_GUARD_RETURN - no attackAggressors] -->|success| F2[AI_GUARD_IDLE + attackAggressors]
F2 -->|enemy in range| F3[AI_GUARD_INNER - no attackAggressors]
F2 -->|attacked| F_ATK[AI_GUARD_ATTACK_AGGRESSOR]
F_ATK --> F1
end
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
subgraph RETAIL["RETAIL_COMPATIBLE_CRC = 1 (original retail)"]
R1[AI_GUARD_RETURN + attackAggressors] -->|success| R2[AI_GUARD_IDLE + attackAggressors]
R1 -->|attacked| R_ATK[AI_GUARD_ATTACK_AGGRESSOR]
R2 -->|enemy in range| R3[AI_GUARD_INNER + attackAggressors]
R3 -->|attacked| R_ATK
R_ATK --> R1
end
subgraph FIX["RETAIL_COMPATIBLE_CRC = 0 (fix)"]
F1[AI_GUARD_RETURN - no attackAggressors] -->|success| F2[AI_GUARD_IDLE + attackAggressors]
F2 -->|enemy in range| F3[AI_GUARD_INNER - no attackAggressors]
F2 -->|attacked| F_ATK[AI_GUARD_ATTACK_AGGRESSOR]
F_ATK --> F1
end
Reviews (7): Last reviewed commit: "Fixed guard (retaliation) states." | Re-trigger Greptile
|
This needs more work. Can you explain in more technical detail why and how this change is correcting the bug? |
|
@CookieLandProjects We don't include issue links or ids (anymore). I think the comments can be reduced to something much more terse: // TheSuperHackers @bugfix 09/04/2026 This fixes the conflicting movement and fire behavior in Guard mode when the unit is under attack.
defineState(AI_GUARD_INNER, newInstance(AIGuardInnerState)(this), AI_GUARD_OUTER, AI_GUARD_OUTER);
defineState(AI_GUARD_RETURN, newInstance(AIGuardReturnState)(this), AI_GUARD_IDLE, AI_GUARD_INNER);
...
// TheSuperHackers @bugfix 09/04/2026 This fixes the conflicting movement and fire behavior in Guard mode when the unit is under attack.
defineState(AI_GUARD_RETALIATE_RETURN, newInstance(AIGuardRetaliateReturnState)(this), AI_GUARD_RETALIATE_IDLE, AI_GUARD_RETALIATE_INNER);and then put the rest of the explanation in a comment here and / or the first post. Please also rebase so this can be tested with the latest main branch. |
xezon
left a comment
There was a problem hiding this comment.
Comment text can be polished.
Pull title needs polishing.
Needs replication to Generals.
|
I took the liberty of making changes to the code comments, so that this PR can move forward. I think the only thing that remains is testing, and I'll ask around if testers can do that. |
|
I have tested the issue before and after the fix and tested it for air, tank and infantry units and the bug seem to be fully fixed for all unit types with guardmode. No conflicting behavior is being seen after the fix. |
Made Guard do what its supposed to instead of retaliating when its not supposed to.
EDIT: Most of the bug description was moved from the code to here: