Code Monkey home page Code Monkey logo

screeps's Introduction

Screeps codebase

This is my code for running Screeps - an open-source sandbox MMO RTS game for programmers.

Code is written in TypeScript and was based on Screeps Typescript Starter.

Usage

To upload the code onto Screeps account you should:

  1. Copy screeps.sample.json file and rename it to screeps.json.
  2. Replace value of token property inside the file to the value of your Screeps token.
  3. Execute npm run push-main or npm run push-test to upload code into Screeps main or test branch respectively.
  4. Switch to the branch in Screeps.

Organization

Main code loop consists of executing 4 modules:

  • Tower commanding

    Detects enemy creeps in occupied room and commands towers to attack them. If no enemies detected, repairs damaged structures

  • Creep commanding

    Issues creeps commands based on their role and active task.

  • Creep spawning

    Decides creeps of which roles should be spawned based on set targets and current creep counts.

  • Memory cleanup

    Removes data from memory that is not needed any more.

Creep commanding

Creeps are organized in roles and tasks.

Role is assigned to a creep upon spawning. Role is used to decide on what task the creep should work on.

Task is used to decide what creep should do. When task is assigned to a creep it finds its target and saves it to the creep memory. Each tick it works on the task and checks finish condition. If tasks is finished, new one will be assigned by the role.

The existing roles are:

Worker [300]

Starter role. Will harvest energy from source and fill spawn, build, fill extensions and upgrade controller.

Builder [300]

Used to build and maintain constructions. Will pick up energy from storage, build new constructions and then repair existing ones. Requires: storage or containers

Energy Distributor [300]

Will pick up energy from from storage and distribute it to spawns, extensions, towers and upgraders. Requires: storage or containers

Hauler [300]

Will move resources from containers, tombstones and dropped to storage. Requires: storage and containers

Idler

Does nothing. Fallback role used in case of errors.

Miner [50 + 100*n] (max 550)

Will find mine flag without miner creep occupying the position and move to it. Then it will mine adjacent source and drop the energy into a container.

Requires mine flag (containing mine keyword) on a position adjacent to the source. Flag should have saved in memory the source id in source property. A container should be present in the position.

Upgrader [200 * n]

Will look for empty position with upgrade flag and move to it. Then it will upgrade the controller. The role relies on Energy Distributor to be given energy.

Requires: upgrade flag (containing upg keyword) on a position in range of controller upgrading.

Remote Miner [450]

Will occupy remote mine flag location, build a container and mine nearby source

Requires flag with remote-mine prefix in range 1 of source

Remote Hauler [300]

Will transfer energy from remote mine container to storage

Requires: storage and container in remote mine location

Creep Spawning

Creep spawning mechanism is based on the value of spawn-order parameter defined in spawn memory. The value should be an array of single key-value pair objects, where key is the role name and value is the target creep count.

E.g. [{ harvester: 1 }, { builder: 1 }, { harvester: 3 }]

  • if there is no harvesters it will spawn one
  • if there is at least one harvester but no builders will spawn a builder
  • if there is at least one builder but less then 3 harvesters will spawn a harvester

screeps's People

Contributors

piotrgajow avatar

Stargazers

 avatar

Watchers

 avatar  avatar

screeps's Issues

Scavenge resources

Scavenging should pick up all kinds of resources and deposit them in the storage

Add upgrader creep

  • Add upgrader creep role
  • Moves to empty upgrade flag
  • upgrades controller
  • extend energy-distributor to give energy to upgrader
  • add spawning upgrader creeps

Hauler

  • Should ignore containers with less energy than its capacity

Add Miner creep

  • Add miner role moving to mine (empty location with flag & container) and extracting energy
  • Add spawning miners with 5 * WORK & 1 * MOVE
  • Create pick-up-energy task picking up energy from container
  • Rework existing roles using extract-energy to use pick-up-energy

Improve flag management

  • Set in the flag memory assigned creep
  • Use flags assigned creep to determine if flag is not occupied
  • If assigned creep dies, remove it from flag memory

Add hauler creep

Should move energy from containers to storage

  • Extend pick-up-energy to first use storage
  • Add task for picking up energy from container
  • Add task for storing energy in storage
  • Add hauler creep spawning

Refactor tasks code

  • Extract target setting to base class, calling abstract findTarget method
  • executeTask does not return anything, isTask finished uses memory

Add distributor creep

Should distribute energy from storage to spawn and extensions

  • Extend pick-up-energy task to first target storage
  • Create distributor role picking up energy and transfering it to spawn and extensions
  • Add spawning of distributor creeps
  • Create task for transferring energy to towers

Add target to creep tasks

  • Add target to creep memory
  • extract-energy finds source, and places it in the target and uses it later

Add remote mining possibilities

  • RemoteMiner
    • Find an unoccupied remote flag
    • If no energy -> harvest source
    • If energy and has container - drop to the container
    • if energy and no container - build container
  • RemoteHauler
    • Take energy from remote source
    • Put it into storage

Add second miner

  • Extend miner code to choose free mine node
  • Store mine name as target for mining
  • Rework mine task to use flag position and flag property pointing for source
  • Add spawning second miner

Creep spawning priority

Rework priority queue:

Checking alternating counts e.g. [{miner: 1}, {hauler: 1}, {distributor: 1}, {miner: 3} ... ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.