Commit ee79bc3
committed
fix: prevent mineral and squad infinite loops
This fix addresses two critical infinite loop issues that waste CPU:
1. Mineral Creep Infinite Loop
----------------------------
Mineral creeps would infinitely loop trying to transfer resources from
the terminal when insufficient amounts (1-4 units) were available.
Changes:
- Update validation threshold from === 0 to < LAB_REACTION_AMOUNT (5)
in both setStatePrepareReactionLab1WithResource and
setStatePrepareReactionLab2WithResource to match room cleanup logic
- Add reaction cleanup in handleWithdrawFromSource to delete
room.memory.reaction when resources are insufficient, preventing
immediate re-setting of the same failed state
- Enhance validation check to also verify resource amount meets
LAB_REACTION_AMOUNT threshold during withdrawal
2. Squad Bouncing at Room Borders
--------------------------------
Squad creeps (both siege and heal) would bounce infinitely between
room exits, logging "Reached end of handling() why?" every tick.
Root cause: When creeps reached target room border, they would:
- Enter target room -> set routing.reached = true
- Move back across border due to border tile instability
- Delete routing.reached flag (not in target room anymore)
- Routing system restarts -> creep moves forward again
- Infinite loop continues
Changes:
- Add explicit if/else logic in squadsiege.action to separate
traveling vs in-target-room behavior
- Add border protection: only reset routing.reached if not at border
tile (using isBorder check) to prevent bouncing
- Don't execute siege() when traveling (not in target room)
- Apply same fix to squadheal.action for consistency
Both fixes ensure consistent validation across code paths and make
the systems self-healing by clearing invalid states immediately.1 parent 686d315 commit ee79bc3
3 files changed
+18
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
| 351 | + | |
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| |||
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
381 | | - | |
| 381 | + | |
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
495 | | - | |
496 | | - | |
| 495 | + | |
| 496 | + | |
497 | 497 | | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
498 | 502 | | |
499 | 503 | | |
500 | 504 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
| 53 | + | |
55 | 54 | | |
56 | 55 | | |
57 | | - | |
58 | | - | |
| 56 | + | |
| 57 | + | |
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | 79 | | |
81 | 80 | | |
| 81 | + | |
82 | 82 | | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | | - | |
| 86 | + | |
| 87 | + | |
86 | 88 | | |
87 | 89 | | |
| 90 | + | |
88 | 91 | | |
| 92 | + | |
| 93 | + | |
89 | 94 | | |
90 | 95 | | |
0 commit comments