Skip to content

unify: Parse template references in the AssistedTargetingUpdate module by name#2809

Open
Stubbjax wants to merge 5 commits into
TheSuperHackers:mainfrom
Stubbjax:unify-assisted-targeting-update-module-template-parsing
Open

unify: Parse template references in the AssistedTargetingUpdate module by name#2809
Stubbjax wants to merge 5 commits into
TheSuperHackers:mainfrom
Stubbjax:unify-assisted-targeting-update-module-template-parsing

Conversation

@Stubbjax

@Stubbjax Stubbjax commented Jun 19, 2026

Copy link
Copy Markdown

This change improves the way in which the AssistedTargetingUpdate module parses template reference fields in Generals by standardising the logic with Zero Hour.

As a result, the respective objects can be defined in any order, whereas previously e.g. the PatriotBinaryDataStream would have to be defined before any reference within an AssistedTargetingUpdate module (otherwise the LaserFromAssisted and LaserToTarget fields would be left unassigned).

This change also corrects an inconsequential copy-and-paste error where the LaserToTarget was always assigned to the LaserFromAssisted value.

Before

✅ Valid

Object PatriotBinaryDataStream
  ; ...
End

Object AmericaPatriotBattery
  Behavior = AssistedTargetingUpdate ModuleTag_XX
    LaserFromAssisted = PatriotBinaryDataStream
    LaserToTarget = PatriotBinaryDataStream
  End
End

❌ Invalid

Object AmericaPatriotBattery
  Behavior = AssistedTargetingUpdate ModuleTag_XX
    LaserFromAssisted = PatriotBinaryDataStream
    LaserToTarget = PatriotBinaryDataStream
  End
End

Object PatriotBinaryDataStream
  ; ...
End

After

✅ Valid

Object PatriotBinaryDataStream
  ; ...
End

Object AmericaPatriotBattery
  Behavior = AssistedTargetingUpdate ModuleTag_XX
    LaserFromAssisted = PatriotBinaryDataStream
    LaserToTarget = PatriotBinaryDataStream
  End
End

✅ Valid

Object AmericaPatriotBattery
  Behavior = AssistedTargetingUpdate ModuleTag_XX
    LaserFromAssisted = PatriotBinaryDataStream
    LaserToTarget = PatriotBinaryDataStream
  End
End

Object PatriotBinaryDataStream
  ; ...
End

@Stubbjax Stubbjax self-assigned this Jun 19, 2026
@Stubbjax Stubbjax added Gen Relates to Generals Fix Is fixing something, but is not user facing Unify Unifies code between Generals and Zero Hour labels Jun 19, 2026
@greptile-apps

greptile-apps Bot commented Jun 19, 2026

Copy link
Copy Markdown

Greptile Summary

This PR ports the deferred-resolution pattern from Zero Hour (GeneralsMD) to vanilla Generals for AssistedTargetingUpdate, storing LaserFromAssisted and LaserToTarget as name strings during INI parsing and resolving them to ThingTemplate* pointers on the first update tick and on save-load, removing the strict INI definition-order requirement. It also fixes the pre-existing copy-paste bug in GeneralsMD where m_laserToTarget was being resolved from m_laserFromAssistedName in both update() and loadPostProcess().

  • Generals: ThingTemplate* fields are removed from AssistedTargetingUpdateModuleData and re-added as instance members on AssistedTargetingUpdate; buildFieldParse switches from parseThingTemplate to parseAsciiString; constructor initialises pointers to nullptr; update() and loadPostProcess() perform the findTemplate lookup.
  • GeneralsMD: update() and loadPostProcess() now correctly resolve m_laserToTarget from m_laserToTargetName instead of the wrong m_laserFromAssistedName, fixing the long-standing copy-paste bug flagged in a previous review.

Confidence Score: 5/5

Safe to merge — the logic is correct in all four files, and the two previously flagged copy-paste bugs in GeneralsMD have been resolved.

The Generals implementation correctly mirrors the established Zero Hour pattern. Template pointers are initialised to nullptr in the constructor, resolved once on the first update tick, and re-resolved on save-load via loadPostProcess. The only new issues introduced are minor indentation inconsistencies that carry no runtime risk.

No files require special attention; the Generals header has a minor indentation inconsistency but no logic concerns.

Important Files Changed

Filename Overview
Generals/Code/GameEngine/Include/GameLogic/Module/AssistedTargetingUpdate.h Moves ThingTemplate pointers from ModuleData to the instance class and adds AsciiString name fields; new fields use spaces instead of tabs, inconsistent with the rest of the file.
Generals/Code/GameEngine/Source/GameLogic/Object/Update/AssistedTargetingUpdate.cpp Switches INI parsing to AsciiString, initialises pointers in the constructor, and resolves templates by name in both update() and loadPostProcess(); logic is correct and mirrors the Zero Hour implementation.
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssistedTargetingUpdate.h Trivial whitespace-only change (removes two trailing blank lines); no functional change.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AssistedTargetingUpdate.cpp Fixes the previous copy-paste bug in both update() and loadPostProcess() where m_laserToTarget was incorrectly resolved from m_laserFromAssistedName; both lookups now use the correct name fields.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant INI as INI Parser
    participant MD as AssistedTargetingUpdateModuleData
    participant ATU as AssistedTargetingUpdate
    participant TF as TheThingFactory

    INI->>MD: parseAsciiString to m_laserFromAssistedName
    INI->>MD: parseAsciiString to m_laserToTargetName

    Note over ATU: Constructor
    ATU->>ATU: "m_laserFromAssisted = nullptr"
    ATU->>ATU: "m_laserToTarget = nullptr"

    Note over ATU: First update() tick
    ATU->>TF: findTemplate(m_laserFromAssistedName)
    TF-->>ATU: m_laserFromAssisted
    ATU->>TF: findTemplate(m_laserToTargetName)
    TF-->>ATU: m_laserToTarget
    ATU-->>ATU: return UPDATE_SLEEP_FOREVER

    Note over ATU: On save/load
    ATU->>TF: findTemplate(m_laserFromAssistedName)
    TF-->>ATU: m_laserFromAssisted
    ATU->>TF: findTemplate(m_laserToTargetName)
    TF-->>ATU: m_laserToTarget

    Note over ATU: assistAttack()
    ATU->>ATU: makeFeedbackLaser(m_laserFromAssisted)
    ATU->>ATU: makeFeedbackLaser(m_laserToTarget)
Loading
%%{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"}}}%%
sequenceDiagram
    participant INI as INI Parser
    participant MD as AssistedTargetingUpdateModuleData
    participant ATU as AssistedTargetingUpdate
    participant TF as TheThingFactory

    INI->>MD: parseAsciiString to m_laserFromAssistedName
    INI->>MD: parseAsciiString to m_laserToTargetName

    Note over ATU: Constructor
    ATU->>ATU: "m_laserFromAssisted = nullptr"
    ATU->>ATU: "m_laserToTarget = nullptr"

    Note over ATU: First update() tick
    ATU->>TF: findTemplate(m_laserFromAssistedName)
    TF-->>ATU: m_laserFromAssisted
    ATU->>TF: findTemplate(m_laserToTargetName)
    TF-->>ATU: m_laserToTarget
    ATU-->>ATU: return UPDATE_SLEEP_FOREVER

    Note over ATU: On save/load
    ATU->>TF: findTemplate(m_laserFromAssistedName)
    TF-->>ATU: m_laserFromAssisted
    ATU->>TF: findTemplate(m_laserToTargetName)
    TF-->>ATU: m_laserToTarget

    Note over ATU: assistAttack()
    ATU->>ATU: makeFeedbackLaser(m_laserFromAssisted)
    ATU->>ATU: makeFeedbackLaser(m_laserToTarget)
Loading
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
Generals/Code/GameEngine/Include/GameLogic/Module/AssistedTargetingUpdate.h:42-51
Mixed indentation in the new fields: the two `AsciiString` members use 2-space indentation while every other member in the class uses a tab, and the constructor initializers use 4-space indentation while the existing initializers use two tabs. This creates visible inconsistency in the same file.

```suggestion
	AsciiString m_laserFromAssistedName;
	AsciiString m_laserToTargetName;

	AssistedTargetingUpdateModuleData()
	{
		m_clipSize = 1;
		m_weaponSlot = PRIMARY_WEAPON;
		m_laserFromAssistedName.clear();
		m_laserToTargetName.clear();
	}
```

### Issue 2 of 2
Generals/Code/GameEngine/Source/GameLogic/Object/Update/AssistedTargetingUpdate.cpp:140-148
Same indentation inconsistency in `update()` and `loadPostProcess()`: the `const AssistedTargetingUpdateModuleData *d` line uses 2-space indentation while all other statements in the function body use tabs. This matches the GeneralsMD copy, but is still inconsistent with the rest of the file.

```suggestion
UpdateSleepTime AssistedTargetingUpdate::update()
{
	const AssistedTargetingUpdateModuleData *d = getAssistedTargetingUpdateModuleData();

	m_laserFromAssisted = TheThingFactory->findTemplate( d->m_laserFromAssistedName );
	m_laserToTarget = TheThingFactory->findTemplate( d->m_laserToTargetName );

	return UPDATE_SLEEP_FOREVER;
}
```

Reviews (2): Last reviewed commit: "unity: Init instance members" | Re-trigger Greptile

@Stubbjax Stubbjax force-pushed the unify-assisted-targeting-update-module-template-parsing branch from 7913420 to 13b1161 Compare June 19, 2026 07:39
@Stubbjax Stubbjax force-pushed the unify-assisted-targeting-update-module-template-parsing branch from 8e0db49 to 818dfe9 Compare June 19, 2026 07:43
Comment thread Generals/Code/GameEngine/Include/GameLogic/Module/AssistedTargetingUpdate.h Outdated
@greptile-apps

greptile-apps Bot commented Jun 19, 2026

Copy link
Copy Markdown

Greptile encountered an error while reviewing this PR. Please reach out to support@greptile.com for assistance.

@Stubbjax Stubbjax added ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing labels Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Gen Relates to Generals Refactor Edits the code with insignificant behavior changes, is never user facing Unify Unifies code between Generals and Zero Hour ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants