Skip to content

refactor(object): Replace explicit local player checks with Object::isLocallyControlled#2512

Merged
xezon merged 2 commits intoTheSuperHackers:mainfrom
Caball009:refactor_isLocallyControlled
Apr 1, 2026
Merged

refactor(object): Replace explicit local player checks with Object::isLocallyControlled#2512
xezon merged 2 commits intoTheSuperHackers:mainfrom
Caball009:refactor_isLocallyControlled

Conversation

@Caball009
Copy link
Copy Markdown

@Caball009 Caball009 commented Mar 30, 2026

Bool Object::isLocallyControlled() const
{
return getControllingPlayer() == ThePlayerList->getLocalPlayer();
}

This PR replaces a couple of checks such as
if (object->getControllingPlayer() == ThePlayerList->getLocalPlayer())
with
if (object->isLocallyControlled())

TODO:

  • Replicate in Generals.

@Caball009 Caball009 added Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing labels Mar 30, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 30, 2026

Greptile Summary

This PR refactors explicit local player ownership checks (getControllingPlayer() == ThePlayerList->getLocalPlayer()) across both the Generals and GeneralsMD codebases, replacing them with the cleaner Object::isLocallyControlled() helper method. The helper is a direct, semantically equivalent wrapper, so this is a pure readability refactoring with no behavioral change.

Key changes:

  • 9 files updated across Core/, Generals/, and GeneralsMD/ directories
  • All replacements are semantically equivalent — isLocallyControlled() is implemented as return getControllingPlayer() == ThePlayerList->getLocalPlayer()
  • Covers UI (ControlBar, SelectionInfo), game logic (Object damage/radar events, GameLogic cleanup), behavior (OverchargeBehavior), and contain (RiderChangeContain) systems
  • The PR description's TODO ("Replicate in Generals") has been completed in the HEAD commit — no remaining old-style checks found in either Generals/ or GeneralsMD/

Confidence Score: 5/5

Safe to merge — all changes are semantically equivalent refactoring with no behavioral delta.

Every substituted expression is an exact functional match to the isLocallyControlled() implementation. No null-safety regressions are introduced; the GeneralsMD attemptDamage path retains its existing getControllingPlayer() && guard before the bitset call. No remaining occurrences of the old pattern were found in either codebase after the change. This is a clean, complete refactor with no P0/P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameClient/SelectionInfo.cpp Replaces one getControllingPlayer() != ThePlayerList->getLocalPlayer() check with !isLocallyControlled() — semantically identical.
Generals/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp Two sanity-check comparisons (cancel construction and cancel production) updated to use isLocallyControlled() — no behavioral change.
Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/OverchargeBehavior.cpp UI notification guard for overcharge updated to isLocallyControlled() — equivalent replacement.
Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp Final condition in attemptDamage radar-event guard replaced with isLocallyControlled() — equivalent; pre-existing absence of a null-guard on getControllingPlayer() is unchanged by this PR.
GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp Same two sanity-check comparisons as the Generals counterpart updated to isLocallyControlled() — no behavioral change.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/OverchargeBehavior.cpp UI notification guard updated to isLocallyControlled() — equivalent to Generals counterpart.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/RiderChangeContain.cpp Selection message guard for rider dismount uses isLocallyControlled() — equivalent; no corresponding Generals file exists, so no mirror update needed.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp Final condition in attemptDamage radar-event guard replaced with isLocallyControlled(); the existing getControllingPlayer() && null-guard immediately preceding it remains intact.
GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp Control bar dirty-mark check in destroyObject updated to isLocallyControlled() — equivalent replacement.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Call site (e.g. attemptDamage, processCommandUI, etc.)"]
    B["obj->isLocallyControlled()"]
    C["getControllingPlayer()"]
    D["ThePlayerList->getLocalPlayer()"]
    E{"=="}
    F["Bool result"]

    A --> B
    B --> C
    B --> D
    C --> E
    D --> E
    E --> F

    style B fill:#d4edda,stroke:#28a745
    style A fill:#cce5ff,stroke:#004085
Loading

Reviews (3): Last reviewed commit: "Replicated in Generals (manually)." | Re-trigger Greptile

@Caball009 Caball009 force-pushed the refactor_isLocallyControlled branch from 2b3edd3 to 97806ac Compare March 30, 2026 23:37
@Caball009
Copy link
Copy Markdown
Author

Replicated in Generals.

@xezon xezon merged commit 2d13736 into TheSuperHackers:main Apr 1, 2026
23 checks passed
@Caball009 Caball009 deleted the refactor_isLocallyControlled branch April 1, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Minor Severity: Minor < Major < Critical < Blocker 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