Skip to content

bugfix(supply): Implement proportional supply bonus scaling#2431

Open
tintinhamans wants to merge 1 commit intoTheSuperHackers:mainfrom
tintinhamans:arctic/propo-supply-bonus
Open

bugfix(supply): Implement proportional supply bonus scaling#2431
tintinhamans wants to merge 1 commit intoTheSuperHackers:mainfrom
tintinhamans:arctic/propo-supply-bonus

Conversation

@tintinhamans
Copy link

  • Added a new getMaxBoxes() method to SupplyTruckAIInterface and implemented it in both SupplyTruckAIUpdate and WorkerAIUpdate to expose the configured maximum box capacity.

  • Updated SupplyCenterDockUpdate::action to snapshot the box count before unloading and scale the upgrade bonus proportionally to the delivered cargo.

Closes #132

@greptile-apps
Copy link

greptile-apps bot commented Mar 9, 2026

Greptile Summary

This PR introduces proportional supply-upgrade bonus scaling: rather than always granting a flat UpgradedSupplyBoost when a truck docks, the bonus is now scaled by deliveredBoxes / maxBoxes so that a partially-loaded truck receives only a proportional reward. The change is gated behind #if !RETAIL_COMPATIBLE_CRC to preserve CRC parity for multiplayer/replay builds. The implementation is clean and well-scoped.

Key changes:

  • getMaxBoxes() added as a pure virtual to SupplyTruckAIInterface and implemented inline in both SupplyTruckAIUpdate (from m_maxBoxesData) and WorkerAIUpdate (from its own module data). ChinookAIUpdate inherits the implementation correctly from SupplyTruckAIUpdate.
  • A new getUpgradedSupplyBoostValue() static helper in SupplyCenterDockUpdate.cpp snapshots the box count before loseOneBox() is called, which correctly captures the delivered quantity and prevents empty trucks from receiving any bonus.
  • The maxBoxes > 0 guard in the non-retail path prevents a division-by-zero crash for units whose MaxBoxes INI field is unset, returning 0 in that case. Note that this is a silent behaviour change for any hypothetical unit with UpgradedSupplyBoost > 0 but no MaxBoxes configured — the team has already accepted this trade-off in prior review discussion.

Confidence Score: 4/5

  • Safe to merge; the fix is logically correct and all previously raised concerns have been addressed or accepted.
  • All concrete implementors of SupplyTruckAIInterface (SupplyTruckAIUpdate, WorkerAIUpdate, ChinookAIUpdate) correctly satisfy the new getMaxBoxes() pure virtual. The proportional calculation is mathematically sound for normal in-game inputs, division-by-zero is guarded, and empty-truck zero-bonus is correctly handled by reading getNumberBoxes() before unloading. The one point held back is the silent drop-to-zero when MaxBoxes is unconfigured for an upgraded unit, which is an accepted limitation from prior review discussion.
  • No files require special attention beyond the already-discussed maxBoxes == 0 fallback in SupplyCenterDockUpdate.cpp.

Important Files Changed

Filename Overview
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h Adds getMaxBoxes() as a pure virtual method to SupplyTruckAIInterface and provides an inline implementation in SupplyTruckAIUpdate returning m_maxBoxesData. ChinookAIUpdate, which extends SupplyTruckAIUpdate, inherits the implementation correctly via its SupplyTruckAIUpdateModuleData base. No issues.
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h Adds the getMaxBoxes() override to WorkerAIUpdate, delegating to m_maxBoxesData on its own module data. Consistent with the SupplyTruckAIUpdate implementation. No issues.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp Introduces getUpgradedSupplyBoostValue() helper that correctly snapshots box count before unloading and computes proportional bonus. The maxBoxes > 0 guard prevents division by zero. However, when maxBoxes == 0 and upgradedSupplyBoost > 0, the bonus is silently dropped to 0 (regression vs. unconfigured units), though this case was accepted by the team in prior review threads.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["SupplyCenterDockUpdate::action()"] --> B["getUpgradedSupplyBoostValue(supplyTruckAI)"]
    B --> C{RETAIL_COMPATIBLE_CRC?}
    C -- Yes --> D["return getUpgradedSupplyBoost()  (full flat bonus)"]
    C -- No --> E["maxBoxes = getMaxBoxes()"]
    E --> F{maxBoxes > 0?}
    F -- No --> G["return 0"]
    F -- Yes --> H["upgradedSupplyBoost = getUpgradedSupplyBoost()
deliveredBoxes = getNumberBoxes()"]
    H --> I["return (upgradedSupplyBoost × deliveredBoxes) / maxBoxes"]
    D --> J["value += boost"]
    G --> J
    I --> J
    J --> K["while loseOneBox(): value += getSupplyBoxValue()"]
    K --> L{value > 0?}
    L -- Yes --> M["deposit(value) + floating text"]
    L -- No --> N["return FALSE"]
    M --> N
Loading

Last reviewed commit: 67212ba

@tintinhamans tintinhamans marked this pull request as draft March 9, 2026 19:15
@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch 3 times, most recently from 7bfc70d to 0f2e2bf Compare March 9, 2026 22:02
@tintinhamans tintinhamans marked this pull request as ready for review March 9, 2026 22:02
Int maxBoxes = supplyTruckAI->getMaxBoxes();
if( maxBoxes > 0 )
{
value += upgradedSupplyBoost * deliveredBoxes / maxBoxes; // Intentional integer truncation.
Copy link

Choose a reason for hiding this comment

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

Is the idea that the supply boost is only applied up to maxBoxes?

So if we have a limit of 5 boxes but we deliver 7? we should only be applying the boost to 5 boxes?

Since the above will be under valuing the bonus if so.

Copy link

Choose a reason for hiding this comment

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

Nvm i misunderstood what it was doing.

But if max boxes is zero then should we be giving any kind of bonus since shouldn't it technically not be able to carry anything?

Copy link
Author

Choose a reason for hiding this comment

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

Good point - units with maxBoxes 0 have no business docking supplies anyways.

@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch from 0f2e2bf to b87de30 Compare March 10, 2026 13:55
@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch 2 times, most recently from e3eadf6 to bab6097 Compare March 10, 2026 14:34
@xezon xezon added Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour labels Mar 10, 2026
@xezon
Copy link

xezon commented Mar 10, 2026

Is this Zero Hour only?

@tintinhamans
Copy link
Author

Is this Zero Hour only?

No Supply Lines upgrade in Generals, only in ZH.

@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch 2 times, most recently from 824e79e to bb5a635 Compare March 12, 2026 00:33
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Code is looking good.

Signed-off-by: tintinhamans <5984296+tintinhamans@users.noreply.github.com>
@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch from bb5a635 to 67212ba Compare March 13, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

USA Chinook extra money drop is always 60$ no matter how big the base money load is

3 participants