Skip to content
Robert Hafner edited this page Oct 19, 2017 · 1 revision

Quorum has two main systems for managing creeps- Clusters and the Creep Program- both of which rely on Roles (just to differing extents.

Creep Builds using Roles

Each role contains a getBuild function that is used to by the spawn to generate the body parts needed on the creep. It takes two parameters- the options sent to the initial spawn queue and the room that the creep will be built in. Internally each getBuild function can take advantage of some helper functions when generating the build.

For example the Claimer creep role could look like this-

const MetaRole = require('roles_meta')

class Claimer extends MetaRole {
  constructor () {
    super()
    this.defaultEnergy = 850
  }

  getBuild (room, options) {
    this.setBuildDefaults(room, options)
    return Creep.buildFromTemplate([MOVE, CLAIM, MOVE, MOVE, MOVE, MOVE], options.energy)
  }
}

module.exports = Claimer

Creep Program

When a role has the manageCreep function defined then the Creep program can be used to launch a single stand alone creep. The program will wait for the creep to spawn, run it through the role's manageCreep function, and then close once the creep has died. In addition the Creep program will set its priority to whatever the role's getPriority function returns.

class Upgrader extends MetaRole {
  getBuild (room, options) {
    this.setBuildDefaults(room, options)
    return Creep.buildFromTemplate([MOVE, CARRY, WORK], options.energy)
  }

  getPriority (creep) {
    return PRIORITIES_CREEP_UPGRADER
  }

  manageCreep (creep) {
    if (creep.recharge()) {
      return
    }
    if (!creep.pos.inRangeTo(creep.room.controller, 2)) {
      creep.travelTo(creep.room.controller)
    }
    if (creep.pos.inRangeTo(creep.room.controller, 3)) {
      creep.upgradeController(creep.room.controller)
    }
  }
}

Launching creep processes from inside of a program is simple. It takes a label (just like processes), the role name, the spawn room, quantity, and any build options (memory, energy, or any role specific options).

this.launchCreepProcess('fillers', 'filler', this.data.room, 2, {'energy': 1600})

Clusters

Clusters are the best way to manage groups of creeps. Each Cluster has a unique name (generated for you if you use the getCluster helper function inside of your programs), the ability to "size" the cluster with a specific role and quantity, helper functions such as getCreeps and getClusterSize, and the forEach function.

The forEach function will run the callback function sent to it on each spawned creep in the cluster. Unlike the Creep Program, this allows calculations to occur before the function is created so that those calculations don't have to occur for each creep. It is also easier to switch between behaviors by changing the callback function used, or two coordinate actions between two different creep clusters in the same program.

class SimpleDefense extends kernel.process {
  main () {
    const hostiles = Game.rooms[this.data.room].find(FIND_HOSTILE_CREEPS)
    if (hostiles.length <= 0) {
      return
    }
    const hostile = hostiles[0]
    const attackers = this.getCluster('attackers')
    attackers.sizeCluster('attackers', 3)
    attackers.forEach(function (creep) {
      if (creep.pos.isNearTo(hostile)) {
        creep.attack(hostile)
      } else {
        creep.travelTo(hostile)
      }
    })
  }
}

module.exports = SimpleDefense
Clone this wiki locally