fix: prevent mineral and squad infinite loops #746
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.




Summary
This PR fixes two critical infinite loop issues that were wasting CPU every tick:
Problem 1: Mineral Creep Infinite Loop
Issue
After PR #745, mineral creeps were still experiencing infinite loops when:
setStatevalidation checks for=== 0(passes with 1-4 units)LAB_REACTION_AMOUNT(5)Example log spam:
Root Cause
setStatefunctions checked for=== 0while room cleanup logic checked for< LAB_REACTION_AMOUNTChanges (role_mineral.js)
Fix validation thresholds in
setStatePrepareReactionLab1WithResource()andsetStatePrepareReactionLab2WithResource():=== 0to< LAB_REACTION_AMOUNTAdd self-healing cleanup in
handleWithdrawFromSource():room.memory.reactionLAB_REACTION_AMOUNTProblem 2: Squad Bouncing at Room Borders
Issue
Squad creeps (both
squadsiegeandsquadheal) would bounce infinitely between room exits:routing.reached = truebut they keep moving back and forthRoot Cause - The Bouncing Cycle
routing.reached = truerouting.reachedflagThe bug was in the action functions:
Problems:
siege()regardless of room locationChanges (role_squadsiege.js and role_squadheal.js)
Add explicit if/else logic to separate traveling vs in-target-room behavior:
Add border protection using
isBorder()check:routing.reachedif not at border tileDon't execute siege/heal when traveling:
Impact
Before Fix
After Fix
Testing
Files Changed
src/role_mineral.js- Mineral creep validation and cleanupsrc/role_squadsiege.js- Squad siege action logic with border protectionsrc/role_squadheal.js- Squad heal action logic with border protection