[][src]Module screeps::constants

Constants, most copied from the game constants.

Last updated on 2019-07-13, 068343753adf090fd1991944d2292be9e236b7dd from https://github.com/screeps/common/commits/master/lib/constants.js.

Currently missing:

  • FIND_DROPPED_ENERGY (deprecated in Screeps)
  • OBSTACLE_OBJECT_TYPES
  • WORLD_WIDTH / WORLD_HEIGHT (deprecated in Screeps)
  • CONTROLLER_STRUCTURES
  • REACTIONS
  • BOOSTS
  • POWER_INFO

Notes on Deserialization

There are two general types of enum constants in this file. Some are represented by integers in the game - and those are represented by integers in screeps. Their serde::Deserialize, TryFrom<Value> and num_traits::FromPrimitive implementations will convert from these integers.

The other type is enums represented by strings in the game, but integers in this repository. This change in representation is done for efficiency, as transferring strings from JavaScript to Rust is much slower than a single integer.

This second type of enum will also implement serde::Deserialize, TryFrom<Value>, but these will not convert from the made-up integer values, and will fail converting from the constant strings from the game.

To convert from constant strings, you have two options, depending on the context.

If you need to manually consume from a value in JavaScript, there are two utility JavaScript functions per enum. They generally take the form __TYPE_num_to_str and __TYPE_str_to_num. For example, __structure_type_num_to_str and __structure_type_str_to_num convert between StructureType integer representations and string representations. See documentation on enums for more conversion functions.

To use these, call the functions in JavaScript, like so:

use screeps::{game, traits::TryInto, StructureType};
use stdweb::js;

let spawns = game::spawns::values();
let r: StructureType = (js! {
    return __structure_type_str_to_num(@{spawns[0].as_ref()}.structureType);
})
.try_into()
.expect("expected structure type to convert successfully");

If you need to consume strings already in Rust, use either the FromStr trait, or one of the deserialize_from_str functions on each of these constants.

Re-exports

pub use self::find::FindConstant;

Modules

find

Constants for use with the Room::find function.

look

Structs

DensityEnumIterator

Iterator over the variants of Density

Enums

Color
Density

Translates the DENSITY_* constants.

Direction
ExitDirection

Type used for when the game returns a direction to an exit.

IntershardResourceType

Translates SUBSCRIPTION_TOKEN and INTERSHARD_RESOURCES constants.

Part

Creep part types.

PowerClass
PowerType

Traslates the PWR_* constants.

ResourceType

Resource type constant for all possible types of resources.

ReturnCode
StructureType

Translates STRUCTURE_* constants.

Terrain

Terrain constant.

Constants

ATTACK_POWER
BUILD_POWER
CARRY_CAPACITY
CONSTRUCTION_COST_ROAD_SWAMP_RATIO
CONSTRUCTION_COST_ROAD_WALL_RATIO
CONTAINER_CAPACITY
CONTAINER_DECAY
CONTAINER_DECAY_TIME
CONTAINER_DECAY_TIME_OWNED
CONTAINER_HITS
CONTROLLER_ATTACK_BLOCKED_UPGRADE
CONTROLLER_CLAIM_DOWNGRADE
CONTROLLER_DOWNGRADE_RESTORE
CONTROLLER_DOWNGRADE_SAFEMODE_THRESHOLD
CONTROLLER_MAX_UPGRADE_PER_TICK
CONTROLLER_NUKE_BLOCKED_UPGRADE
CONTROLLER_RESERVE
CONTROLLER_RESERVE_MAX
CREEP_CLAIM_LIFE_TIME
CREEP_CORPSE_RATE
CREEP_LIFE_TIME
CREEP_PART_MAX_ENERGY
CREEP_SPAWN_TIME
DISMANTLE_COST
DISMANTLE_POWER
ENERGY_DECAY
ENERGY_REGEN_TIME
EXTENSION_HITS
EXTRACTOR_COOLDOWN
EXTRACTOR_HITS
FLAGS_LIMIT
GCL_MULTIPLY
GCL_NOVICE
GCL_POW
HARVEST_MINERAL_POWER
HARVEST_POWER
HEAL_POWER
INVADERS_ENERGY_GOAL
LAB_BOOST_ENERGY
LAB_BOOST_MINERAL
LAB_ENERGY_CAPACITY
LAB_HITS
LAB_MINERAL_CAPACITY
LAB_REACTION_AMOUNT
LAB_UNBOOST_ENERGY
LAB_UNBOOST_MINERAL
LINK_CAPACITY
LINK_COOLDOWN
LINK_HITS
LINK_LOSS_RATION
MARKET_FEE
MAX_CONSTRUCTION_SITES
MAX_CREEP_SIZE
MINERAL_DENSITY_CHANGE
MINERAL_RANDOM_FACTOR
MINERAL_REGEN_TIME
NUKER_COOLDOWN
NUKER_ENERGY_CAPACITY
NUKER_GHODIUM_CAPACITY
NUKER_HITS
NUKE_DAMAGE_RANGE_0
NUKE_DAMAGE_RANGE_2
NUKE_LAND_TIME
NUKE_RANGE
OBSERVER_HITS
OBSERVER_RANGE
PORTAL_DECAY
PORTAL_MAX_TIMEOUT
PORTAL_MIN_TIMEOUT
PORTAL_UNSTABLE
POWER_BANK_CAPACITY_CRIT
POWER_BANK_CAPACITY_MAX
POWER_BANK_CAPACITY_MIN
POWER_BANK_DECAY
POWER_BANK_HITS
POWER_BANK_HIT_BACK
POWER_BANK_RESPAWN_TIME
POWER_CREEP_DELETE_COOLDOWN
POWER_CREEP_LIFE_TIME
POWER_CREEP_MAX_LEVEL
POWER_CREEP_SPAWN_COOLDOWN
POWER_LEVEL_MULTIPLY
POWER_LEVEL_POW
POWER_SPAWN_ENERGY_CAPACITY
POWER_SPAWN_ENERGY_RATIO
POWER_SPAWN_HITS
POWER_SPAWN_POWER_CAPACITY
RAMPART_DECAY_AMOUNT
RAMPART_DECAY_TIME
RAMPART_HITS
RAMPART_HITS_MAX_RCL2
RAMPART_HITS_MAX_RCL3
RAMPART_HITS_MAX_RCL4
RAMPART_HITS_MAX_RCL5
RAMPART_HITS_MAX_RCL6
RAMPART_HITS_MAX_RCL7
RAMPART_HITS_MAX_RCL8
RANGED_ATTACK_POWER
RANGED_HEAL_POWER
REPAIR_COST
REPAIR_POWER
ROAD_DECAY_AMOUNT
ROAD_DECAY_TIME
ROAD_HITS
ROAD_WEAROUT
ROAD_WEAROUT_POWER_CREEP
SAFE_MODE_COOLDOWN
SAFE_MODE_COST
SAFE_MODE_DURATION
SIGN_PLANNED_AREA
SOURCE_ENERGY_CAPACITY
SOURCE_ENERGY_KEEPER_CAPACITY
SOURCE_ENERGY_NEUTRAL_CAPACITY
SPAWN_ENERGY_CAPACITY
SPAWN_ENERGY_START
SPAWN_HITS
SPAWN_RENEW_RATION
STORAGE_CAPACITY
STORAGE_HITS
SYSTEM_USERNAME
TERMINAL_CAPACITY
TERMINAL_COOLDOWN
TERMINAL_HITS
TERMINAL_MIN_SEND
TERMINAL_SEND_COST
TERRAIN_MASK_LAVA
TERRAIN_MASK_SWAMP
TERRAIN_MASK_WALL
TOMBSTONE_DECAY_PER_PART
TOMBSTONE_DECAY_POWER_CREEP
TOWER_CAPACITY
TOWER_ENERGY_COST
TOWER_FALLOFF
TOWER_FALLOFF_RANGE
TOWER_HITS
TOWER_OPTIMAL_RANGE
TOWER_POWER_ATTACK
TOWER_POWER_HEAL
TOWER_POWER_REPAIR
UPGRADE_CONTROLLER_POWER
WALL_HITS
WALL_HITS_MAX

Traits

LookConstant

Functions

controller_downgrade

Translates the CONTROLLER_DOWNGRADE constant.

controller_levels

Translates the CONTROLLER_LEVELS constant.

extension_energy_capacity

Translates the EXTENSION_ENERGY_CAPACITY constant.

mineral_min_amount

Translates the MINERAL_MIN_AMOUNT constant.

rampart_hits_max

Translates the RAMPART_HITS_MAX constant