Options
All
  • Public
  • Public/Protected
  • All
Menu

screeps-spawn

Index

Functions

generateBody

  • generateBody(room: Room, segment: string[], options?: GenerateBodyOptions): string[]
  • Generate a body given a room to spawn from and a segment to repeat. By default it generate as big a creep as it can. Set maxCost and maxSize options to configure this.

    interface GenerateBodyOptions {
     maxCost?: number;
     maxSize?: number;
     moveShield?: boolean;           // Place move parts at the front.
     additionalSegment?: string[];   // An additional not repeated segment.
     sortOrder?: {                   // Override the default sorting
         [partConstant: string]: number;
         other: number;
     };
    }
    

    Parameters

    • room: Room
    • segment: string[]
    • Default value options: GenerateBodyOptions = {}

    Returns string[]

getCreepCount

  • getCreepCount(id: string): number
  • Get the total creep count (including spawning creeps) for a spawn request.

    Parameters

    • id: string

    Returns number

getCreeps

  • getCreeps(id: string, includeSpawning?: boolean): Creep[]
  • Get the creeps that are assigned to the spawn request. By default spawning creeps are excluded.

    Parameters

    • id: string
    • Default value includeSpawning: boolean = false

    Returns Creep[]

hasCreeps

  • hasCreeps(id: string): boolean
  • Check if a spawn request has at least one creep spawning or alive.

    Parameters

    • id: string

    Returns boolean

processSpawnRequests

  • processSpawnRequests(): void
  • Process all spawn requests. Must be called in your code after spawn requests have been registered.

    Returns void

registerSpawnRequest

  • registerSpawnRequest(id: string, room: Room, spawnRequest: SpawnRequester): void
  • Register a spawn request. Requies a unique id, room to spawn from and a SpawnRequester object.

    interface SpawnRequester {
     shouldSpawn: () => boolean;
     canSpawn: () => boolean;
     generateSpawnRequest: () => SpawnRequest;
    }
    
    interface SpawnRequest {
     body: string[];
     memory?: any;
     name?: string;
     onSuccess?: (id: string, name: string) => void;
    }
    

    Parameters

    • id: string
    • room: Room
    • spawnRequest: SpawnRequester

    Returns void

setTimer

  • setTimer(spawnId: string, ticks: number): void
  • Sets the spawn timer to N ticks in the future Game.time + ticks.

    Parameters

    • spawnId: string
    • ticks: number

    Returns void

setTimerCycle

  • setTimerCycle(spawnId: string, cycleModifier?: number): void
  • Sets the spawn timer to Game.time + (CREEP_LIFE_TIME / cycleModifier). (default 1)

    Parameters

    • spawnId: string
    • Default value cycleModifier: number = 1

    Returns void

spawnTimerCheck

  • spawnTimerCheck(spawnId: string): boolean
  • Check the spawn timer to see if it has passed.

    Parameters

    • spawnId: string

    Returns boolean

Generated using TypeDoc