Implement Structure.isActive() and ERR_RCL_NOT_ENOUGH checks - #110
Conversation
545141a to
3953166
Compare
|
Pushed an additional commit (misterwise/xxscreeps@806799c) that gates This closes the remaining gap from #33: the prior commits fixed Tests included and validated against unfixed code to confirm they catch the bug. |
laverdet
left a comment
There was a problem hiding this comment.
#active flag should be stored on relevant buildings.
|
Come to think of it the event would also need to run on destruction of other buildings. The point stands that this function should run in constant time. |
|
Also, it might be worth considering something like this, which fixes the issue of |
|
Thanks for the thorough review — pushed a rework addressing all the feedback. I now understand the rationale for inactive buildings. They work as stores without needing to be active (withdraw, transfer), but the source labs for a reaction was the biggest surprised to me. All integratd in alignment with vanilla now. Core architecture: cached Reworked per your guidance.
For destruction: Vanilla-correctness fixes
Style/lint fixes
|
laverdet
left a comment
There was a problem hiding this comment.
Just some minor nitpicks for now.
There's some other things which would be better for later. I think what I want would require a more significant lifecycle hook adjustment so it's fine to put a pin in that.
Replace the stubbed isActive() with a proper implementation that checks CONTROLLER_STRUCTURES for the current RCL level, including excess-structure handling for RCL downgrades (sorted by id, matching official engine). Add checkIsActive guard to all structure action chains (tower, spawn, lab, link, terminal, mineral extractor) immediately after ownership checks. Filter inactive structures from energyAvailable/energyCapacityAvailable and spawn energy consumption. Remove now-redundant isActive overrides from observer and spawn. 7 new tests covering inactive structures, ERR_RCL_NOT_ENOUGH returns, destroyability of inactive structures, and energy accounting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Official engine does not validate extractor isActive during harvest — ERR_RCL_NOT_ENOUGH is not a documented return code for Creep.harvest(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move the inline isActive check from checkObserveRoom into the chainIntentChecks chain via checkIsActive, matching the consistent pattern used by all other structures: checkMyStructure → checkIsActive → method-specific checks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…controller owner check - Use Chebyshev distance to controller (with ID tiebreaker) instead of ID-only sort when determining which excess structures remain active - Return false when structure owner differs from controller owner (e.g. after room conquest) - Add missing extractor isActive check to mineral harvest Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ests - Use FIND_STRUCTURES filtered by structure owner instead of FIND_MY_STRUCTURES in isActive(), which was context-dependent on the calling player - Match official check ordering: tower checks energy before RCL, lab runReaction/reverseReaction check cooldown before RCL - Add tests for controller owner mismatch, distance-based tiebreaker, and extractor harvest with inactive extractor Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Skip the excess-structure scan for types that only ever allow one (storage, terminal, observer, etc.) — if maxCount > 0 and max at RCL 8 is 1, the structure is always active. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Drop redundant "active at sufficient RCL" test (covered by spawn isActive tests). Clarify that the remaining test gives the tower energy so ERR_RCL_NOT_ENOUGH specifically exercises the checkIsActive placement in the intent chain. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… gate, test reorganization - Split no-controller into separate `return true` guard matching official engine - Add checkIsActive on input labs (runReaction, reverseReaction) and link target - Gate spawn energy regen on isActive to prevent energyAvailable drift - Remove unused checkIsActive import from mineral.ts - Move generic isActive tests to structure/test.ts, observer tests stay in observer/test.ts - Register structure mod test in manifest - Rename spawn describe block and remove redundant assertion Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ccess Closes the remaining gap from issue laverdet#33: creep.transfer() and creep.withdraw() now return ERR_RCL_NOT_ENOUGH for inactive structures (e.g. extensions after RCL downgrade). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add '#active' to OwnedStructure schema, computed by checkActiveStructures - Batch approach matching official engine PR laverdet#150: group structures by type, sort each group by distance to controller, mark closest N active - checkActiveStructures called from updateRoomStatus on level/owner changes - OwnedStructure.#destroy invalidates same-type '#active' flags so the lazy fallback recomputes correctly after the destroyed structure is flushed - isActive() returns cached value in constant time; lazy-computes on first access when unset (test setup, new construction) - Remove non-vanilla isActive checks: source labs, link targets, transfer, withdraw — stores on inactive buildings still work - Fix id-length, line breaks, level-8 extensions in level-1 test rooms Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…dundant ternary, add TODOs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0ee1e9b to
6e87a53
Compare
Summary
Structure.isActive()with distance-based tiebreaking for excess structures on RCL downgradecheckIsActiveto all structure intent chains (spawn, tower, lab, link, terminal, observer, extractor harvest)energyAvailable,energyCapacityAvailable, energy drain, and spawn regenisActive()overrides on StructureSpawn and StructureObserverVerification
🤖 Generated with Claude Code