Fix transfer of manually built enhancements#7162
Conversation
Was checking [1] but the table is keyed with slot name strings. Also was creating the table and then checking afterwards instead of checking if its empty first.
Although it was never used, `return false` is from gpg so I kept it for backwards mod compatibility. True is now returned so there's a more legitimate way to identify the failure.
|
Warning Review limit reached
Next review available in: 51 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR defers preset enhancement creation during unit transfer, tracks the deferred thread on the unit, updates transfer-time enhancement harvesting, adds engine callback fields, guards intel recharge against destroyed units, and records the fix in the changelog. ChangesManual enhancement transfer fix
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant TransferUnitsOwnership
participant NewUnit
participant DeferredThread
participant CreateEnhancement
TransferUnitsOwnership->>TransferUnitsOwnership: inspect unit enhancements with TableEmpty
TransferUnitsOwnership->>NewUnit: transfer ownership
TransferUnitsOwnership->>NewUnit: kill existing enhancement thread
TransferUnitsOwnership->>DeferredThread: fork deferred enhancement creation
DeferredThread->>CreateEnhancement: create each enhancement
CreateEnhancement-->>DeferredThread: returns true
DeferredThread->>NewUnit: clear OnStopBeingBuiltEnhancementsThread
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@engine/Sim/CAiBrain.lua`:
- Around line 549-551: Update the callback annotation for
CAiBrain.OnUnitCapLimitReached so its receiver type matches a brain callback
instead of Unit; use the same self type pattern as OnFailedUnitTransfer in
CAiBrain.lua, and adjust the `@type` fun(self: ...) signature to the correct brain
object type.
In `@lua/SimUtils.lua`:
- Around line 329-334: The preset replay logic in SimUtils.lua only cancels the
preset thread when activeEnhancements exists, so units with no active
enhancements can still have presets re-applied. Update the preset handling path
around the activeEnhancements build and the thread cancellation check to cancel
the preset replay for preset units even when unitEnh is empty, using the preset
thread logic near the activeEnhancements/preset thread code path. Ensure the
condition depends on preset state, not on activeEnhancements being truthy.
- Around line 424-428: The delayed enhancement replay in
newUnit.OnStopBeingBuiltEnhancementsThread can run after the unit has been
destroyed, so add the same dead-unit guard used by
Unit.CreatePresetEnhancementsThread before iterating activeEnhancements and
calling newUnit:CreateEnhancement. Recheck newUnit after WaitTicks(1), and exit
early if the unit is no longer valid/alive to avoid touching bones or UI on a
dead unit.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 373db206-d547-45e6-82bd-e2ef23a7567f
📒 Files selected for processing (5)
changelog/snippets/fix.7162.mdengine/Sim/CAiBrain.lualua/SimUtils.lualua/defaultcomponents.lualua/sim/Unit.lua
Description of the proposed changes
Fixes #5233
The system was broken in 3 parts:
Testing done on the proposed changes
This test works the same for ACU, except ACU has no conflict with presets to check.
Checklist
Summary by CodeRabbit