Skip to content

refactor: Add override keyword to virtual function overrides in Zero Hour code (2)#2605

Open
Caball009 wants to merge 6 commits intoTheSuperHackers:mainfrom
Caball009:override_keyword_zh
Open

refactor: Add override keyword to virtual function overrides in Zero Hour code (2)#2605
Caball009 wants to merge 6 commits intoTheSuperHackers:mainfrom
Caball009:override_keyword_zh

Conversation

@Caball009
Copy link
Copy Markdown

@Caball009 Caball009 commented Apr 15, 2026

This PR adds the keyword override to a number of virtual functions in the Zero Hour code that were missed in the previous round of refactoring.

Check out the commits as they separate different types of changes.

Related PRs:
#2603
#2604

@Caball009 Caball009 added the Refactor Edits the code with insignificant behavior changes, is never user facing label Apr 15, 2026
@Caball009 Caball009 marked this pull request as ready for review April 15, 2026 21:09
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 15, 2026

Greptile Summary

This PR continues the override keyword refactoring from PR #2101, adding override to virtual function overrides that were missed in the Zero Hour codebase. In addition to the pure mechanical keyword additions, several abstract module classes have redundant pure-virtual re-declarations removed (since those methods are already declared pure-virtual in their base interfaces — e.g., SubsystemInterface, UpgradeMux, Snapshot), and two methods gain a missing const qualifier (FlightDeckBehavior::getNaturalRallyPoint, OverlordContain::isBustable) which corrects them so they actually override their base-class const variants rather than silently shadowing them.

Confidence Score: 5/5

Safe to merge — purely a compile-time-verified refactoring with no behavioral changes

All changes add the override keyword (compile-time checked by the compiler), remove redundant pure-virtual redeclarations already enforced by base interfaces, and fix two const-correctness shadow bugs. No logic changes, and any incorrect override would have produced a compile error. All P2 or lower.

No files require special attention

Important Files Changed

Filename Overview
GeneralsMD/Code/GameEngine/Include/Common/Module.h Adds override to crc/xfer/loadPostProcess in both MAKE_STANDARD_MODULE_MACRO and MAKE_STANDARD_MODULE_MACRO_ABC macros, providing compile-time verification for all consuming classes
GeneralsMD/Code/GameEngine/Include/Common/StateMachine.h Removes redundant pure-virtual redeclarations of crc/xfer/loadPostProcess from State — these are already inherited as pure virtuals from the Snapshot base class
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/FlightDeckBehavior.h Adds const and override to getNaturalRallyPoint — previously missing const meant it silently shadowed the base class const version rather than overriding it; also adds override to getTaxiLocations and getCreationLocations
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/OverlordContain.h Adds const override to isBustable — the missing const meant it shadowed OpenContain::isBustable() const rather than overriding it; also adds override to addToContainList
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/BodyModule.h Removes redundant pure-virtual redeclarations (attemptDamage, attemptHealing, getHealth, getDamageState, etc.) already declared in BodyModuleInterface
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SpecialPowerUpdateModule.h Removes redundant pure-virtual redeclarations already present in SpecialPowerUpdateInterface
GeneralsMD/Code/GameEngine/Include/GameLogic/ScriptActions.h Removes redundant init/reset/update pure-virtual redeclarations already present in SubsystemInterface base class
GeneralsMD/Code/GameEngine/Include/GameLogic/ScriptConditions.h Removes redundant init/reset/update pure-virtual redeclarations already present in SubsystemInterface base class
GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h Adds override to all debugGetName() implementations across ~20 PartitionFilter subclasses; purely mechanical but comprehensive
GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h Adds override to draw() = 0 — valid C++11 syntax correctly indicating InGameUI inherits a virtual draw() and re-declares it pure virtual for its own subclasses
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpgradeModule.h Removes isSubObjectsUpgrade() = 0 — already declared pure-virtual in both UpgradeMux and UpgradeModuleInterface, making the UpgradeModule redeclaration redundant
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h Removes redundant update() = 0 redeclaration from UpdateModule, already in UpdateModuleInterface
GeneralsMD/Code/GameEngine/Include/GameLogic/AIStateMachine.h Adds override to 9 getName() / getCurrentStateName() declarations gated behind STATE_MACHINE_DEBUG; purely mechanical

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    class Snapshot {
        +crc(xfer) virtual=0
        +xfer(xfer) virtual=0
        +loadPostProcess() virtual=0
    }
    class State {
        <<abstract>>
        note: pure-virtual redecls removed
    }
    class StateMachine {
        +crc(xfer) override
        +xfer(xfer) override
        +loadPostProcess() override
    }
    class Module {
        <<macro MAKE_STANDARD_MODULE_MACRO>>
        +crc(xfer) override
        +xfer(xfer) override
        +loadPostProcess() override
    }
    class OpenContain {
        +isBustable() const override
        +addToContainList(obj) override
        +getNaturalRallyPoint(...) const override
    }
    class OverlordContain {
        +isBustable() const override
        note: const added — now correctly overrides
    }
    class FlightDeckBehavior {
        +getNaturalRallyPoint(...) const override
        note: const added — now correctly overrides
        +getTaxiLocations(id) const override
        +getCreationLocations(id) const override
    }
    Snapshot <|-- State
    Snapshot <|-- StateMachine
    Snapshot <|-- Module
    OpenContain <|-- OverlordContain
    OpenContain <|-- FlightDeckBehavior
Loading

Reviews (2): Last reviewed commit: "Restored 'override' on destructor of 'Sc..." | Re-trigger Greptile

@xezon xezon changed the title refactor: Add override keyword to virtual function overrides in Zero Hour code refactor: Add override keyword to virtual function overrides in Zero Hour code (2) Apr 16, 2026

virtual void preDraw(); ///< Logic which needs to occur before the UI renders
virtual void draw() = 0; ///< Render the in-game user interface
virtual void draw() override = 0; ///< Render the in-game user interface
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens if this is omitted?

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.

Nothing. It's just to acknowledge that the base class also has this exact function, but it's not pure virtual. If that were removed that would lead to a compilation error here, which seems desirable.

virtual void exitObjectByBudding( Object *newObj, Object *budHost ) override { return; }
virtual Bool getExitPosition( Coord3D& rallyPoint ) const override { return FALSE; }
virtual Bool getNaturalRallyPoint( Coord3D& rallyPoint, Bool offset = TRUE ) { return FALSE; }
virtual Bool getNaturalRallyPoint( Coord3D& rallyPoint, Bool offset = TRUE ) const override { return FALSE; }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this fix a bug?

virtual OpenContain *asOpenContain() override { return this; } ///< treat as open container
virtual Bool isGarrisonable() const override; ///< can this unit be Garrisoned? (ick)
virtual Bool isBustable() { return false;}; ///< can this container get busted by bunkerbuster? (ick)
virtual Bool isBustable() const override { return false;}; ///< can this container get busted by bunkerbuster? (ick)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this fix a bug?

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

Labels

Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants