Screeps Wiki
Advertisement

This wiki page will list fresh global scope of a Screeps AI. Note that changes in the global scope can change between each turn, as your code will move between servers sporadically, and each server has its own global.

Global variables can also be found here.

API[]

Note: the global object itself should be assumed non-existing. `global` and `globals` are available in the sandbox, but none of them are defined when scripts are run server side.

Properties[]

Following are object prototypes of ingame objects, any added property to its prototype will be available to its instances.

Constants[]

Result codes[]

Used by functions sending commands to the screeps engine.

OK                           0
ERR_NOT_OWNER               -1
ERR_NO_PATH                 -2
ERR_NAME_EXISTS             -3
ERR_BUSY                    -4
ERR_NOT_FOUND               -5
ERR_NOT_ENOUGH_ENERGY       -6
ERR_INVALID_TARGET          -7
ERR_FULL                    -8
ERR_NOT_IN_RANGE            -9
ERR_INVALID_ARGS           -10
ERR_TIRED                  -11
ERR_NO_BODYPART            -12
ERR_NOT_ENOUGH_EXTENSIONS  -6
ERR_RCL_NOT_ENOUGH         -14
ERR_GCL_NOT_ENOUGH         -15


Filter constants[]

Used to for some search functions to filter by type.

FIND_EXIT_TOP                     1
FIND_EXIT_RIGHT                   3
FIND_EXIT_BOTTOM                  5
FIND_EXIT_LEFT                    7
FIND_EXIT                        10
FIND_CREEPS                     101
FIND_MY_CREEPS                  102
FIND_HOSTILE_CREEPS             103
FIND_SOURCES_ACTIVE             104
FIND_SOURCES                    105
FIND_DROPPED_ENERGY             106
FIND_DROPPED_RESOURCES          106
FIND_STRUCTURES                 107
FIND_MY_STRUCTURES              108
FIND_HOSTILE_STRUCTURES         109
FIND_FLAGS                      110
FIND_CONSTRUCTION_SITES         111
FIND_MY_SPAWNS                  112
FIND_HOSTILE_SPAWNS             113
FIND_MY_CONSTRUCTION_SITES      114
FIND_HOSTILE_CONSTRUCTION_SITES 115
FIND_MINERALS                   116

Look constants[]

Used in results when finding objects at a position

LOOK_ENERGY             "energy"
LOOK_TERRAIN            "terrain"
LOOK_CONSTRUCTION_SITES "constructionSite"
LOOK_FLAGS              "flag"
LOOK_STRUCTURES         "structure"
LOOK_MINERALS           "mineral"
LOOK_SOURCES            "source"
LOOK_RESOURCES          "resource"
LOOK_NUKES              "nuke"
LOOK_CREEPS             "creep"

Direction constants[]

TOP            1
TOP_RIGHT      2
RIGHT          3
BOTTOM_RIGHT   4
BOTTOM         5
BOTTOM_LEFT    6
LEFT           7
TOP_LEFT       8

Body parts[]

MOVE           "move"
WORK           "work"
CARRY          "carry"
ATTACK         "attack"
RANGED_ATTACK  "ranged_attack"
TOUGH          "tough"
HEAL           "heal"
CLAIM          "claim"

(undocumented in api documentation)

BODYPART_COST {
    move:           50,
    work:          100,
    attack:         80,
    carry:          50,
    heal:          250,
    ranged_attack: 150,
    tough:          10,
    claim:         600
}

(undocumented in api documentation)

BODYPARTS_ALL [
    MOVE,
    WORK,
    CARRY,
    ATTACK,
    RANGED_ATTACK,
    TOUGH,
    HEAL,
    CLAIM
]

Properties (undocumented in api documentation)

   CARRY_CAPACITY: 50,
   HARVEST_POWER: 2,
   HARVEST_MINERAL_POWER: 1,
   REPAIR_POWER: 100,
   DISMANTLE_POWER: 50,
   BUILD_POWER: 5,
   ATTACK_POWER: 30,
   UPGRADE_CONTROLLER_POWER: 1,
   RANGED_ATTACK_POWER: 10,
   HEAL_POWER: 12,
   RANGED_HEAL_POWER: 4

Structure Types[]

STRUCTURE_SPAWN       "spawn"
STRUCTURE_EXTENSION   "extension"
STRUCTURE_ROAD        "road"
STRUCTURE_WALL        "constructedWall"
STRUCTURE_RAMPART     "rampart"
STRUCTURE_KEEPER_LAIR "keeperLair"
STRUCTURE_PORTAL      "portal"
STRUCTURE_CONTROLLER  "controller"
STRUCTURE_LINK        "link"
STRUCTURE_STORAGE     "storage"
STRUCTURE_TOWER       "tower"
STRUCTURE_OBSERVER    'observer'
STRUCTURE_POWER_BANK  'powerBank'
STRUCTURE_POWER_SPAWN 'powerSpawn'
STRUCTURE_EXTRACTOR   'extractor'
STRUCTURE_LAB         'lab'
STRUCTURE_TERMINAL    'terminal'
STRUCTURE_CONTAINER   'container'

Colors[]

COLOR_RED    "red"
COLOR_PURPLE "purple"
COLOR_BLUE   "blue"
COLOR_CYAN   "cyan"
COLOR_GREEN  "green"
COLOR_YELLOW "yellow"
COLOR_ORANGE "orange"
COLOR_BROWN  "brown"
COLOR_GREY   "grey"
COLOR_WHITE  "white"

Game modes[]

MODE_ARENA      "arena"
MODE_SIMULATION "simulation"
MODE_SURVIVAL   "survival"
MODE_WORLD      "world"

Creeps constants (undocumented in api documentation)[]

CREEP_SPAWN_TIME     3   // Base spawn time
CREEP_LIFE_TIME   1500   // Lifetime of a creep
CREEP_CORPSE_RATE    0.2 // Portion of remaining creep value that is dropped upon death

Obstacle objects types list (undocumented in api documentation, probably used for pathfinder)[]

OBSTACLE_OBJECT_TYPES [
    'spawn',
    'creep',
    'wall',
    'source',
    'constructedWall',
    'extension',
    'link',
    'storage',
]

Energy constants (undocumented in api documentation)[]

ENERGY_REGEN_TIME    300   // Time untill source regenerates new energy since first harvested energy
ENERGY_REGEN_AMOUNT 3000   // Amount of energy a source has once it respawns
ENERGY_DECAY        1000   // Rate of vanished energy from dropped energy per tick
REPAIR_COST            0.01 // Cost for repairing 1 damage

Rampart constants (undocumented in api documentation)[]

RAMPART_DECAY_AMOUNT 300 // Vanishing health from rampart per cycle
RAMPART_DECAY_TIME   100 // Ticks per decay cycle
RAMPART_HITS           1 // Full health of a rampart
RAMPART_HITS_MAX: {      // Maximum health of a rampart
    2: 300000,
    3: 1000000,
    4: 3000000,
    5: 10000000,
    6: 30000000,
    7: 100000000,
    8: 300000000
}

Spawn constants (undocumented in api documentation)[]

SPAWN_HITS            5000 // Full health of a spawn
SPAWN_ENERGY_START     300 // Amount of energy a spawn starts with when not doing custon mode
SPAWN_ENERGY_CAPACITY 300 // Maximum capacity of energy storage of a spawn

Source constants (undocumented in api documentation)[]

SOURCE_ENERGY_CAPACITY 3000 // Maximum capacity of a source

Road constants (undocumented in api documentation)[]

ROAD_HITS        5000 // Full health of a road
ROAD_WEAROUT        1 // The amount of health a road looses each use
ROAD_DECAY_AMOUNT 100 // How much a road decays per decay event
ROAD_DECAY_TIME  1000 // Time between decay events
CONSTRUCTION_COST_ROAD_SWAMP_RATIO 5 // Cost increase factor when building on swamps

Wall constants (undocumented in api documentation)[]

WALL_HITS             1 // Full health of a wall
WALL_HITS_MAX 300000000 // Maximum health of a wall

Extension constants (undocumented in api documentation)[]

EXTENSION_HITS           1000 // Full health of an extension
EXTENSION_ENERGY_CAPACITY  50 // Maximum capacity of energy storage of an extension

Link constants (undocumented in api documentation)[]

LINK_HITS     1000    // Hits a link gets when constructed
LINK_HITS_MAX 1000    // Maximum hits a link can get
LINK_CAPACITY  500    // Capacity of a link structure
LINK_COOLDOWN    1    // Amount of cooldown after sending energy to another link structure
LINK_LOSS_RATIO  0.03 // Transfer loss while sending energy to another link structure

Storage constants (undocumented in api documentation)[]

STORAGE_CAPACITY 500000 // Amount of energy a storage structure can store
STORAGE_HITS      10000 // Amount of maximum hits a storage structure has, also the amount of hits when constructed

costs (undocumented in api documentation)[]

   CONSTRUCTION_COST: {
       spawn: 15000,
       extension: 3000,
       road: 300,
       constructedWall: 1,
       rampart: 1,
       link: 5000,
       storage: 30000,
       tower: 5000,
       observer: 8000,
       powerSpawn: 100000,
       extractor: 5000,
       lab: 50000,
       terminal: 100000,
       container: 5000
   },
   CONSTRUCTION_COST_ROAD_SWAMP_RATIO: 5,

Terrain types (undocumented in api documentation)[]

TERRAIN_MASK_WALL   1
TERRAIN_MASK_SWAMP  2
TERRAIN_MASK_LAVA   4

Controller structures[]

CONTROLLER_STRUCTURES: {
    spawn: { 0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 2, 8: 3 },
       extension: { 0: 0, 1: 0, 2: 5, 3: 10, 4: 20, 5: 30, 6: 40, 7: 50, 8: 60 },
       link: { 1: 0, 2: 0, 3: 0, 4: 0, 5: 2, 6: 3, 7: 4, 8: 6 },
       road: { 0: 2500, 1: 2500, 2: 2500, 3: 2500, 4: 2500, 5: 2500, 6: 2500, 7: 2500, 8: 2500 },
       constructedWall: { 1: 0, 2: 2500, 3: 2500, 4: 2500, 5: 2500, 6: 2500, 7: 2500, 8: 2500 },
       rampart: { 1: 0, 2: 2500, 3: 2500, 4: 2500, 5: 2500, 6: 2500, 7: 2500, 8: 2500 },
       storage: { 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1 },
       tower: { 1: 0, 2: 0, 3: 1, 4: 1, 5: 1, 6: 2, 7: 2, 8: 4 },
       observer: { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 1 },
       powerSpawn: { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 1 },
       extractor: { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 1, 7: 1, 8: 1 },
       terminal: { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 1, 7: 1, 8: 1 },
       lab: { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 3, 7: 6, 8: 10 },
       container: { 0: 5, 1: 5, 2: 5, 3: 5, 4: 5, 5: 5, 6: 5, 7: 5, 8: 5 }
}

GCL leveling[]

GCL_POW:          2.2 // Multiplication rate per level?
GCL_MULTIPLY  1000000 // Base level amount?
GCL_NOVICE          3 // Limit for novice area?

Resource Types[]

   RESOURCE_ENERGY: 'energy'
   RESOURCE_POWER: 'power'
   RESOURCE_HYDROGEN: 'H'
   RESOURCE_OXYGEN: 'O'
   RESOURCE_UTRIUM: 'U'
   RESOURCE_LEMERGIUM: 'L'
   RESOURCE_KEANIUM: 'K'
   RESOURCE_ZYNTHIUM: 'Z'
   RESOURCE_CATALYST: 'X'
   RESOURCE_GHODIUM: 'G'
   RESOURCE_HYDROXIDE: 'OH'
   RESOURCE_ZYNTHIUM_KEANITE: 'ZK'
   RESOURCE_UTRIUM_LEMERGITE: 'UL'
   RESOURCE_UTRIUM_HYDRIDE: 'UH'
   RESOURCE_UTRIUM_OXIDE: 'UO'
   RESOURCE_KEANIUM_HYDRIDE: 'KH'
   RESOURCE_KEANIUM_OXIDE: 'KO'
   RESOURCE_LEMERGIUM_HYDRIDE: 'LH'
   RESOURCE_LEMERGIUM_OXIDE: 'LO'
   RESOURCE_ZYNTHIUM_HYDRIDE: 'ZH'
   RESOURCE_ZYNTHIUM_OXIDE: 'ZO'
   RESOURCE_GHODIUM_HYDRIDE: 'GH'
   RESOURCE_GHODIUM_OXIDE: 'GO'
   RESOURCE_UTRIUM_ACID: 'UH2O'
   RESOURCE_UTRIUM_ALKALIDE: 'UHO2'
   RESOURCE_KEANIUM_ACID: 'KH2O'
   RESOURCE_KEANIUM_ALKALIDE: 'KHO2'
   RESOURCE_LEMERGIUM_ACID: 'LH2O'
   RESOURCE_LEMERGIUM_ALKALIDE: 'LHO2'
   RESOURCE_ZYNTHIUM_ACID: 'ZH2O'
   RESOURCE_ZYNTHIUM_ALKALIDE: 'ZHO2'
   RESOURCE_GHODIUM_ACID: 'GH2O'
   RESOURCE_GHODIUM_ALKALIDE: 'GHO2'
   RESOURCE_CATALYZED_UTRIUM_ACID: 'XUH2O'
   RESOURCE_CATALYZED_UTRIUM_ALKALIDE: 'XUHO2'
   RESOURCE_CATALYZED_KEANIUM_ACID: 'XKH2O'
   RESOURCE_CATALYZED_KEANIUM_ALKALIDE: 'XKHO2'
   RESOURCE_CATALYZED_LEMERGIUM_ACID: 'XLH2O'
   RESOURCE_CATALYZED_LEMERGIUM_ALKALIDE: 'XLHO2'
   RESOURCE_CATALYZED_ZYNTHIUM_ACID: 'XZH2O'
   RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE: 'XZHO2'
   RESOURCE_CATALYZED_GHODIUM_ACID: 'XGH2O'
   RESOURCE_CATALYZED_GHODIUM_ALKALIDE: 'XGHO2'
Advertisement