Screeps Wiki
(→‎Properties: Add link for the Memory object)
Tags: Visual edit apiedit
(→‎Properties: Clarify use cases for properties)
Tags: Visual edit apiedit
Line 6: Line 6:
 
* [[Game (object)|Game]]
 
* [[Game (object)|Game]]
 
* [[Memory]]
 
* [[Memory]]
* console
+
* console (to call console.log)
  +
* module (to export javascript code using module.exports)
 
* require
 
* require
 
* _
 
* _

Revision as of 15:25, 11 May 2015

This wiki page will list fresh global scope of a screeps ai. Note that changes in the global scope are reset after each turn.

API

Properties

  • Game
  • Memory
  • console (to call console.log)
  • module (to export javascript code using module.exports)
  • require
  • _

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  -13

Filter constants

Used to for some search functions to filter by type.

FIND_CREEPS              101
FIND_MY_CREEPS           102
FIND_HOSTILE_CREEPS      103
FIND_SOURCES_ACTIVE      104
FIND_SOURCES             105
FIND_DROPPED_ENERGY      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_EXIT_TOP              1
FIND_EXIT_RIGHT            3
FIND_EXIT_BOTTOM           5
FIND_EXIT_LEFT             7

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"

(undocumented in api documentation)

BODYPART_COST {
    move:           50,
    work:           20,
    attack:         80,
    carry:          50,
    heal:          200,
    ranged_attack: 150,
    tough:          20
}

(undocumented in api documentation)

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

Properties (undocumented in api documentation)

CARRY_CAPACITY      50
HARVEST_POWER        2
REPAIR_POWER        20
BUILD_POWER          5
ATTACK_POWER        30
RANGED_ATTACK_POWER 10
HEAL_POWER          12
RANGED_HEAL_POWER    4

Structure Types

STRUCTURE_EXTENSION   "extension"
STRUCTURE_KEEPER_LAIR "keeperLair"
STRUCTURE_PORTAL      "portal"
STRUCTURE_RAMPART     "rampart"
STRUCTURE_ROAD        "road"
STRUCTURE_SPAWN       "spawn"
STRUCTURE_WALL        "constructedWall"

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   1800   // Lifetime of a creep
CREEP_CORPSE_RATE    0.2 // Use unknown

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

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

Energy constants (undocumented in api documentation)

ENERGY_REGEN_TIME    300   // Time untill source regenerates new energy since first harvested energy
ENERGY_REGEN_AMOUNT 3000   // Use unknown
ENERGY_DECAY           1   // Rate of vanished energy from dropped energy per tick
REPAIR_COST            0.1 // Use unknown

Rampart constants (undocumented in api documentation)

RAMPART_DECAY_AMOUNT  1 // Vanishing health from rampart per cycle
RAMPART_DECAY_TIME   30 // Ticks per cycle?
RAMPART_HITS       1500 // Full health of a rampart

Spawn constants (undocumented in api documentation)

SPAWN_HITS            5000 // Full health of a spawn
SPAWN_ENERGY_START    1000 // Amount of energy a spawn starts with when not doing custon mode
SPAWN_ENERGY_CAPACITY 6000 // 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    300 // Full health of a road
ROAD_WEAROUT   1 // The amount of health a road looses each use
CONSTRUCTION_COST_ROAD_SWAMP_RATIO 5 // Use unknown

Wall constants (undocumented in api documentation)

WALL_HITS 6000 // Full health of a wall

Extension constants (undocumented in api documentation)

EXTENSION_HITS           1000 // Full health of an extension
EXTENSION_ENERGY_CAPACITY 200 // Maximum capacity of energy storage of an extension
EXTENSION_ENERGY_COST     200 // Use unknown

costs (undocumented in api documentation)

CONSTRUCTION_COST {
    spawn          5000
    extension      3000
    road            300
    constructedWall 500
    rampart        2000
}

Terrain types (undocumented in api documentation)

TERRAIN_MASK_WALL   1
TERRAIN_MASK_SWAMP  2
TERRAIN_MASK_LAVA   4