Skip to content

Creep Role Contribution

Carson edited this page Feb 16, 2023 · 8 revisions

This page is entirely out of date. Much of the information is based on an outdated version of the bot

Naming

First, add the role name to constants.roles, in the constants.ts file. Then in main.ts add the role name to the CreepRoles type

Foundation

Go to creepClasses.ts and create a class for the role. Export it, and assign it in the creepClasses object. For example, with hauler:

export class Hauler extends Creep {
     constructor(creepID: Id<Creep>) {
          super(creepID)
     }
}
creepClasses.hauler = Hauler

Create a file for the role logic, such as hauler.ts. Inside the file, export a function for managing the role. It should look like this:

import { Hauler } from '../../creepClasses'

export function haulerManager(room: Room, creepsOfRole: string[]) {

     for (const creepName of creepsOfRole) {

          const creep: Hauler = Game.creeps[creepName]
     }
}

Finally, go to creepRoleManagers.ts, import the role manager, and create a role reference for it in the managers object

const managers: Record<CreepRoles, Function> = {
     hauler: haulerManager,
}

Role logic

Now onto actually adding functionality. Basic code like function calls should go inside the role manager, while more complex code and functions should be attached as prototypes to the role's class. Back in creepClasses.ts we can add prototypes and properties to the role as types

export class Hauler extends Creep {

     property: string

     method?(): void

     constructor(creepID: Id<Creep>) {
          super(creepID)
     }
}
creepClasses.hauler = Hauler

Meanwhile, in the role's file - such as hauler.ts - we can attach the prototype:

Hauler.prototype.method = function () {
     
     this.say('It works')
}

And of course, reference it above in the manager

import { Hauler } from '../../creepClasses'

export function haulerManager(room: Room, creepsOfRole: string[]) {

     for (const creepName of creepsOfRole) {

          const creep: Hauler = Game.creeps[creepName]

          creep.property = 'yes'
          creep.method()
     }
}

If you have questions or require help, please ask them in the discord server

The International Wiki

Important

Features

Contribution

Design

Clone this wiki locally