Skip to content

honcoops/screeps

Repository files navigation

Screeps Advanced Codebase

This is an advanced, production-ready codebase for Screeps featuring static harvesting, link networks, mineral mining, market trading, lab reactions, and much more. Scales from RCL 1 through RCL 8 with optimized energy management and CPU efficiency.

What is Screeps?

Screeps is an MMO strategy game where you control your colony by writing JavaScript code. Your units (called "creeps") operate autonomously based on the AI you program, even when you're offline.

Files Included

Core System

  1. main.js - Main game loop with CPU tracking and creep recycling
  2. manager.memory.js - Memory management and cleanup
  3. manager.spawn.js - Intelligent spawning with dynamic body sizing
  4. manager.room.js - Room-level operations (towers, defense, infrastructure)
  5. manager.links.js - Link network management (RCL 5+)
  6. manager.terminal.js - Terminal operations and market trading (RCL 6+)
  7. manager.labs.js - Lab reactions and compound production (RCL 6+)

Creep Roles

  1. role.harvester.js - Basic harvester (emergency fallback only)
  2. role.miner.js - Static miners that stay at sources
  3. role.hauler.js - Transport creeps with optimized carry capacity
  4. role.upgrader.js - Controller upgraders with link support
  5. role.builder.js - Construction workers with priority building
  6. role.mineralMiner.js - Mineral extraction (RCL 6+)

How to Use This Code

In the Screeps Tutorial/Simulator:

  1. Go to https://screeps.com/a/#!/sim/tutorial
  2. Open the Script tab
  3. Create new modules for each role file (role.harvester, role.upgrader, role.builder)
  4. Copy the respective code into each module
  5. Replace the main module code with the content from main.js
  6. The code will start running automatically

In the Live Game:

  1. Copy each file's contents into the corresponding module in the Screeps editor
  2. Make sure your spawn is named "Spawn1" (or update the code to match your spawn name)
  3. The code will automatically start spawning and managing creeps

Key Features

Advanced Architecture (All RCLs)

  • Static Harvesting: Dedicated miners stay at sources, haulers transport energy
  • Path Caching: Serialized paths reduce CPU usage dramatically
  • Dynamic Spawning: Creep bodies scale with available energy and RCL
  • Creep Recycling: Old creeps return to spawn to be recycled for energy
  • Automated Roads: Intelligent road placement on frequently traveled paths
  • Tower Defense: Multi-priority tower system (attack, heal, repair, maintain walls)

Energy Network (RCL 5+)

  • Link Network: Automatic link configuration and energy transfer
    • Source links at mining positions
    • Controller link for upgraders
    • Hub link near storage for distribution
  • Instant Transfer: Energy moves from sources to controller/storage instantly

Economic Systems (RCL 6+)

  • Mineral Mining: Automated extractor operations with terminal/storage delivery
  • Terminal Operations:
    • Auto-balances energy levels
    • Maintains optimal resource stockpiles
    • Inter-room resource transfers
  • Market Trading:
    • Automatic sell orders for excess minerals
    • Automatic buy orders for needed resources
    • Price optimization based on market conditions
  • Lab Reactions: Automated compound production with input/output lab management

Late Game (RCL 8)

  • Power Processing: Automatic power spawn operation
  • Observer Support: Room scouting capabilities
  • Maximum Efficiency: Full link network reduces hauler workload by 60%+

CPU Optimization

  • Cached Pathfinding: Paths serialized and reused for multiple ticks
  • Global Caching: Short-term cache for expensive operations
  • Memory Cleanup: Automatic cleanup of dead creeps, old paths, and stale room data
  • Error Handling: Try-catch blocks prevent cascading failures

Progression by RCL

RCL 1-2: Bootstrap Phase

  • Basic miners and haulers establish energy flow
  • Harvesters used as emergency backup
  • Containers placed at sources
  • Essential roads begin construction

RCL 3-4: Growth Phase

  • Increased creep sizes (haulers up to 400 capacity)
  • Full road network between spawn, sources, and controller
  • Tower defense online
  • Builder creeps construct infrastructure

RCL 5: Link Phase

  • Link network activated
  • Source links reduce hauler workload
  • Controller link enables efficient upgrading
  • Energy efficiency increases 40%+

RCL 6: Economic Phase

  • Terminal unlocked - market trading begins
  • Mineral mining starts
  • Labs begin producing basic compounds
  • Storage becomes central hub
  • Auto-sell excess minerals, auto-buy needed resources

RCL 7: Optimization Phase

  • Larger creep bodies (upgraders with 6 WORK parts)
  • Advanced lab reactions
  • Maximum road coverage
  • Refined market strategies

RCL 8: End Game

  • Power spawn processing
  • Observer for scouting
  • Maximum energy efficiency
  • Focus shifts to expansion and defense

Configuration

Spawn Manager (manager.spawn.js)

Creep counts are automatically determined based on:

  • Number of sources in room
  • Current RCL
  • Existing construction sites
  • Container fill levels

You can adjust spawn priorities in getSpawnPriority():

  1. Miners (one per source)
  2. Haulers (scales with sources and room size)
  3. Upgraders (2 at low RCL, 1 at RCL 8)
  4. Builders (spawned as needed for construction)
  5. Mineral Miners (RCL 6+, one per mineral)

Terminal Trading (manager.terminal.js)

Adjust sell thresholds in sellExcessResources():

var sellThresholds = {
    [RESOURCE_HYDROGEN]: 5000,  // Sell when above 5000
    [RESOURCE_OXYGEN]: 5000,
    // ... etc
};

Link Configuration

Links auto-configure based on proximity:

  • Source links: Within 2 tiles of a source
  • Controller link: Within 3 tiles of controller
  • Hub link: Within 2 tiles of storage

Road Planning

Roads automatically build along frequently traveled paths:

  • Spawn ↔ Sources
  • Spawn ↔ Controller
  • Sources ↔ Controller
  • Storage connections (when available)

Advanced Features to Add

This codebase provides a solid foundation. Consider adding:

  1. Remote Mining: Harvest from adjacent unclaimed rooms
  2. Defense Creeps: Dedicated defenders and healers for PvP
  3. Boost Production: Automated boost crafting for powered creeps
  4. Multi-Room Expansion: Automated claiming and development of new rooms
  5. Power Creeps: Integration with the Power Creep system
  6. Advanced Layouts: Bunker or stamp-based room layouts
  7. Combat Logic: Coordinated attack and defense strategies
  8. Nuker Support: Automated nuclear missile launches (requires RCL 8)

Resources

Troubleshooting

High CPU Usage

  • Check CPU usage with the built-in tracker (logged every 100 ticks)
  • Path caching reduces pathfinding CPU by 60%+
  • Consider reducing creep counts if consistently hitting limits
  • Use the global cache for expensive operations

Energy Shortages

  • Ensure miners are at all sources
  • Check that haulers aren't bottlenecked
  • Verify containers are being built at sources
  • At RCL 5+, ensure links are configured

Links Not Working

  • Verify RCL is 5 or higher
  • Check link placement (source links within 2 tiles of source)
  • Links auto-configure every 500 ticks
  • Check room.memory.links for configuration

Terminal Not Trading

  • Requires RCL 6+ and terminal structure
  • Needs minimum 1000 credits to create orders
  • Check Game.market.credits for available funds
  • Trading happens every 100-500 ticks

Minerals Not Being Mined

  • Requires RCL 6+ for extractor
  • Verify extractor is built on mineral deposit
  • Check that mineral hasn't depleted (regenerates every 50,000 ticks)
  • Mineral miner only spawns if extractor exists

Performance Metrics

Expected CPU usage (per room):

  • RCL 1-3: 5-10 CPU/tick
  • RCL 4-5: 10-15 CPU/tick (links reduce this)
  • RCL 6-7: 15-25 CPU/tick (terminal/labs add overhead)
  • RCL 8: 20-30 CPU/tick (full features)

Expected creep counts:

  • Miners: 1 per source (typically 2)
  • Haulers: 2-4 depending on room layout and links
  • Upgraders: 1-2 depending on RCL
  • Builders: 0-2 as needed
  • Mineral Miner: 0-1 (RCL 6+ only)

Credits

Built using Screeps documentation and community best practices. Optimized for:

  • CPU efficiency through caching
  • Energy efficiency through links
  • Economic efficiency through market automation
  • Scalability from RCL 1 to RCL 8

Good luck conquering the world!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •