Difference between revisions of "Useful Constants"

From Screeps Wiki
Jump to navigation Jump to search
 
(18 intermediate revisions by 4 users not shown)
Line 22: Line 22:
 
|Hits (Health/HitPoints) per-part of a creep
 
|Hits (Health/HitPoints) per-part of a creep
 
|100
 
|100
|<code>CREEP_HITS_PER_PART = 100;</code>
+
|<code>const CREEP_HITS_PER_PART = 100;</code>
  +
|-
  +
|Player username
  +
|The name of the account running the code
  +
|<code>const PLAYER_USERNAME = _.find({...Game.structures, ...Game.creeps, ...Game.constructionSites}).owner.username;</code>
 
|-
 
|-
 
|username for the Invader NPCs
 
|username for the Invader NPCs
 
|'Invader'
 
|'Invader'
|<code>INVADER_USERNAME = 'Invader';</code>
+
|<code>const INVADER_USERNAME = 'Invader';</code>
  +
|-
  +
|username for Source Keeper NPCs
  +
|'Source Keeper'
  +
|<code>const SOURCE_KEEPER_USERNAME = 'Source Keeper';</code>
  +
|-
  +
|username for the Caravan NPCs & unclaimed ruins
  +
|'Screeps'
  +
|<code>const CARAVAN_USERNAME = 'Screeps';</code>
 
|-
 
|-
 
|Rate at which energy (progress) is dropped from construction sties,
 
|Rate at which energy (progress) is dropped from construction sties,
 
when stomped (moved onto) by creeps.
 
when stomped (moved onto) by creeps.
 
|0.5
 
|0.5
|<code>CONSTRUCTION_SITE_STOMP_RATIO = 0.5;</code>
+
|<code>const CONSTRUCTION_SITE_STOMP_RATIO = 0.5;</code>
 
|-
 
|-
 
|Power of RANGED_MASS_ATTACK, dependent on range.
 
|Power of RANGED_MASS_ATTACK, dependent on range.
 
|{ 1: 10, 2: 4, 3: 1}
 
|{ 1: 10, 2: 4, 3: 1}
|<code>RANGED_MASS_ATTACK_POWER = { 1: 10, 2: 4, 3: 1};</code>
+
|<code>const RANGED_MASS_ATTACK_POWER = { 1: 10, 2: 4, 3: 1};</code>
  +
|-
  +
|The max amount of CPU that can be used in one game [[tick]], any
  +
CPU over the user's assigned amount comes out of the [[CPU|bucket]]
  +
|500
  +
|<code>const MAX_CPU_PER_TICK = 500;</code>
  +
|-
  +
|The ranges creeps have to be within to execute certain actions.
  +
|{ attack: 1, attackController: 1,
  +
build: 3, claimController: 1, dismantle: 1, generateSafeMode: 1,
  +
  +
harvest: 1, heal: 1, pickup: 1, pull: 1, rangedAttack: 3, rangedHeal: 3,
  +
  +
rangedMassAttack: 3, repair: 3, reserveController: 1, transfer: 1,
  +
  +
upgradeController: 3, withdraw: 1};
  +
|<code>const CREEP_ACTION_RANGES = { attack: 1, attackController: 1,</code>
  +
<code>build: 3, claimController: 1, dismantle: 1, generateSafeMode: 1,</code>
  +
  +
<code>harvest: 1, heal: 1, pickup: 1, pull: 1, rangedAttack: 3, rangedHeal: 3,</code>
  +
  +
<code>rangedMassAttack: 3, repair: 3, reserveController: 1, transfer: 1,</code>
  +
  +
<code>upgradeController: 3, withdraw: 1};</code>
  +
|-
  +
|Maximum size of the default memory (per shard) in characters
  +
|2097152
  +
|<code>const MEMORY_SIZE = 2097152;</code>
  +
|-
  +
|Maximum size of an intetershard memory (per shard) in characters
  +
|1024
  +
|<code>const MEMORY_INERSHARD_SIZE = 1024;</code>
  +
|-
  +
|Maximum size of a rawMemory segment (per shard) in characters
  +
|1024
  +
|<code>const MEMORY_RAW_SEGMENT_SIZE = 1024;</code>
  +
|-
  +
|Maximum size of a rawMemory total (per shard, 10 active segments)
  +
in characters
  +
|10240
  +
|<code>const MEMORY_RAW_TOTAL_SIZE = 10240;</code>
  +
|-
  +
|Hits (Health/HitPoints) per power creep level
  +
|1000
  +
|<code>const POWER_CREEP_HITS_PER_LEVEL = 1000;</code>
  +
|-
  +
|'value' of plains terrain (Note: absence of value could always be
  +
considered a 'plains' since its 0)
  +
|0
  +
|<code>const TERRAIN_MASK_PLAIN = 0;</code>
  +
|-
  +
|
  +
|3
  +
|<code>const CREEP_BUILD_RANGE = 3;</code>
  +
|-
  +
|
  +
|3
  +
|<code>const CREEP_RANGED_ATTACK_RANGE = 3;</code>
  +
|-
  +
|
  +
|3
  +
|<code>const CREEP_UPGRADE_RANGE = 3;</code>
  +
|-
  +
|
  +
|3
  +
|<code>const CREEP_REPAIR_RANGE = 3;</code>
  +
|-
  +
|
  +
|3
  +
|<code>const CREEP_RANGED_HEAL_RANGE = 3;</code>
  +
|-
  +
|
  +
|1
  +
|<code>const CREEP_HARVEST_RANGE = 1;</code>
  +
|-
  +
|
  +
|1
  +
|<code>const CREEP_WITHDRAW_RANGE = 1;</code>
  +
|-
  +
|Base cost of any successful action that changes game state
  +
|0.2
  +
|<code>const CONST_COST = 0.2;</code>
  +
|-
  +
|The distance labs need to be within to beable to <code>runReaction()</code> or
  +
<code>reverseReaction()</code>
  +
|2
  +
|<code>const LAB_REACT_RANGE = 2;</code>
  +
|-
  +
|The distance a creep and a lab need to be to <code>boostCreep()</code> or
  +
<code>unboostCreep()</code>
  +
|1
  +
|<code>const LAB_BOOST_RANGE = 1;</code>
  +
|-
  +
|The maximum amount of deals that can be done on the market in
  +
one tick.
  +
|10
  +
|<code>const MARKET_MAX_DEALS_PER_TICK = 10;</code>
  +
|-
  +
|The maximum amount of characters a controller sign can have.
  +
|100
  +
|<code>const CONTROLLER_SIGN_MAX_LENGTH = 100;</code>
  +
|-
  +
|The maximum amount of characters a creep name can have.
  +
|100
  +
|<code>const CREEP_NAME_MAX_LENGTH = 100;</code>
  +
|-
  +
|The maximum amount of characters a power-creep name can have.
  +
|100
  +
|<code>const POWER_CREEP_NAME_MAX_LENGTH = 100;</code>
  +
|-
  +
|The maximum amount of characters a flag name can have.
  +
|60
  +
|<code>const FLAG_NAME_MAX_LENGTH = 60;</code>
  +
|-
  +
|The maximum amount of characters a spawn name can have.
  +
|100
  +
|<code>const SPAWN_NAME_MAX_LENGTH = 100;</code>
  +
|-
  +
|The maximum amount of characters a creep can <code>say()</code>
  +
|10
  +
|<code>const SAY_MAX_LENGTH = 10;</code>
  +
|-
  +
|The fatigue reduction of a move part per tick when hits > 0
  +
|2
  +
|<code>const MOVE_POWER = 2;</code>
  +
|-
  +
|The maximum amount of RoomVisuals per room (in bytes)
  +
|512000
  +
|<code>const ROOM_VIS_MAX_SIZE = 512000;</code>
  +
|-
  +
|The maximum amount of MapVisuals allowed (in bytes)
  +
|1024000
  +
|<code>const MAP_VIS_MAX_SIZE = 1024000;</code>
  +
|-
  +
|The maximum & minimum values for a room's possible positions
  +
|{minX: 0, minY: 0, maxX:49, maxY:49}
  +
|<code>const ROOM_BOUNDRY_VALUES = {minX: 0, minY: 0, maxX:49, maxY:49}</code>
  +
|}
  +
  +
== Other beneficial constants ==
  +
{| class="wikitable"
  +
|+
  +
!Description
  +
!Value
  +
!Code Sample
  +
|-
  +
|Energy-per-tick income for a given source
  +
|10*
  +
|<code>const SOURCE_GOAL_OWNED = SOURCE_ENERGY_CAPACITY / ENERGY_REGEN_TIME;</code>
  +
|-
  +
|
  +
|5*
  +
|<code>const SOURCE_GOAL_NEUTRAL = SOURCE_ENERGY_NEUTRAL_CAPACITY / ENERGY_REGEN_TIME;</code>
  +
|-
  +
|
  +
|13.3334*
  +
|<code>const SOURCE_GOAL_KEEPER = SOURCE_ENERGY_KEEPER_CAPACITY / ENERGY_REGEN_TIME;</code>
  +
|-
  +
|Optimal number of work parts
  +
|5*
  +
|<code>const SOURCE_HARVEST_PARTS = SOURCE_ENERGY_CAPACITY / HARVEST_POWER / ENERGY_REGEN_TIME;</code>
  +
|-
  +
|
  +
|2.5*
  +
|<code>const SOURCE_HARVEST_PARTS_NEUTRAL = SOURCE_ENERGY_NEUTRAL_CAPACITY / HARVEST_POWER / ENERGY_REGEN_TIME;</code>
  +
|-
  +
|
  +
|6.6667*
  +
|<code>const SOURCE_HARVEST_PARTS_KEEPER = SOURCE_ENERGY_KEEPER_CAPACITY / HARVEST_POWER / ENERGY_REGEN_TIME;</code>
  +
|-
  +
|Optimal number of carry parts
  +
|0.2*
  +
|<code>const SOURCE_CARRY_PARTS_PER_DISTANCE_OWNED = SOURCE_GOAL_OWNED / CARRY_CAPACITY;</code>
  +
|-
  +
|
  +
|0.1*
  +
|<code>const SOURCE_CARRY_PARTS_PER_DISTANCE_NEUTRAL = SOURCE_GOAL_NEUTRAL / CARRY_CAPACITY;</code>
  +
|-
  +
|
  +
|0.26667*
  +
|<code>const SOURCE_CARRY_PARTS_PER_DISTANCE_KEEPER = SOURCE_GOAL_KEEPER / CARRY_CAPACITY;</code>
  +
|-
  +
|Average energy per tick upkeep cost
  +
|0.03*
  +
|<code>const RAMPART_UPKEEP = RAMPART_DECAY_AMOUNT / REPAIR_POWER / RAMPART_DECAY_TIME;</code>
  +
|-
  +
|
  +
|0.001*
  +
|<code>const ROAD_UPKEEP = ROAD_DECAY_AMOUNT / REPAIR_POWER / ROAD_DECAY_TIME;</code>
  +
|-
  +
|
  +
|0.005*
  +
|<code>const ROAD_UPKEEP_SWAMP = (ROAD_DECAY_AMOUNT * CONSTRUCTION_COST_ROAD_SWAMP_RATIO) / REPAIR_POWER / ROAD_DECAY_TIME;</code>
  +
|-
  +
|
  +
|0.15*
  +
|<code>const ROAD_UPKEEP_TUNNEL = (ROAD_DECAY_AMOUNT * CONSTRUCTION_COST_ROAD_WALL_RATIO) / REPAIR_POWER / ROAD_DECAY_TIME;</code>
  +
|-
  +
|
  +
|0.1*
  +
|<code>const CONTAINER_UPKEEP = CONTAINER_DECAY / REPAIR_POWER / CONTAINER_DECAY_TIME_OWNED;</code>
  +
|-
  +
|
  +
|0.5*
  +
|<code>const REMOTE_CONTAINER_UPKEEP = CONTAINER_DECAY / REPAIR_POWER / CONTAINER_DECAY_TIME;</code>
  +
|-
  +
|Boolean indicator of world type
  +
|false
  +
|<code>const IS_PTR = !!(Game.shard && Game.shard.ptr);</code>
  +
|-
  +
|
  +
|false
  +
|<code>const IS_SIM = !!Game.rooms['sim'];</code>
  +
|-
  +
|
  +
|true
  +
|<code>const IS_MMO = !!(Game.shard && Game.shard.name && Game.shard.name.startsWith('shard'));</code>
 
|}
 
|}
  +
<nowiki>*</nowiki> values marked with the asterisk are just examples and subject to change should the underlying constants change
 
[[Category:Development]]
 
[[Category:Development]]

Latest revision as of 17:57, 11 January 2022

This article is a stub. You can help Screeps Wiki by editing to add more information.

This page will list constants either useful because they are missing from the official constants or because they might be interesting to know when solving certain ingame problems.

Missing constants (hardcoded in engine)[edit | edit source]

Knowing "constant worthy" values that do not have a constant set up in the engine yet is important especially now that private servers get more and more modifiable. This list will be useful to users since they can just use values without having to look them up in the engine code, but it might also help request missing constants from the devs (in case changing these currently hardcoded values might make the game more moddable).

Description Value Code sample
Creep fatigue removal multiplier. It works like this in the engine:

newFatigue = Math.max(0, oldFatigue - ( MOVEparts * multiplier))

-2 const MULT_CREEP_FATIGUE_REDUCTION = -2;
Max bucket value. The CPU bucket fills up to 10000 10000 const MAX_BUCKET = 10000;
Hits (Health/HitPoints) per-part of a creep 100 const CREEP_HITS_PER_PART = 100;
Player username The name of the account running the code const PLAYER_USERNAME = _.find({...Game.structures, ...Game.creeps, ...Game.constructionSites}).owner.username;
username for the Invader NPCs 'Invader' const INVADER_USERNAME = 'Invader';
username for Source Keeper NPCs 'Source Keeper' const SOURCE_KEEPER_USERNAME = 'Source Keeper';
username for the Caravan NPCs & unclaimed ruins 'Screeps' const CARAVAN_USERNAME = 'Screeps';
Rate at which energy (progress) is dropped from construction sties,

when stomped (moved onto) by creeps.

0.5 const CONSTRUCTION_SITE_STOMP_RATIO = 0.5;
Power of RANGED_MASS_ATTACK, dependent on range. { 1: 10, 2: 4, 3: 1} const RANGED_MASS_ATTACK_POWER = { 1: 10, 2: 4, 3: 1};
The max amount of CPU that can be used in one game tick, any

CPU over the user's assigned amount comes out of the bucket

500 const MAX_CPU_PER_TICK = 500;
The ranges creeps have to be within to execute certain actions. { attack: 1, attackController: 1,

build: 3, claimController: 1, dismantle: 1, generateSafeMode: 1,

harvest: 1, heal: 1, pickup: 1, pull: 1, rangedAttack: 3, rangedHeal: 3,

rangedMassAttack: 3, repair: 3, reserveController: 1, transfer: 1,

upgradeController: 3, withdraw: 1};

const CREEP_ACTION_RANGES = { attack: 1, attackController: 1,

build: 3, claimController: 1, dismantle: 1, generateSafeMode: 1,

harvest: 1, heal: 1, pickup: 1, pull: 1, rangedAttack: 3, rangedHeal: 3,

rangedMassAttack: 3, repair: 3, reserveController: 1, transfer: 1,

upgradeController: 3, withdraw: 1};

Maximum size of the default memory (per shard) in characters 2097152 const MEMORY_SIZE = 2097152;
Maximum size of an intetershard memory (per shard) in characters 1024 const MEMORY_INERSHARD_SIZE = 1024;
Maximum size of a rawMemory segment (per shard) in characters 1024 const MEMORY_RAW_SEGMENT_SIZE = 1024;
Maximum size of a rawMemory total (per shard, 10 active segments)

in characters

10240 const MEMORY_RAW_TOTAL_SIZE = 10240;
Hits (Health/HitPoints) per power creep level 1000 const POWER_CREEP_HITS_PER_LEVEL = 1000;
'value' of plains terrain (Note: absence of value could always be

considered a 'plains' since its 0)

0 const TERRAIN_MASK_PLAIN = 0;
3 const CREEP_BUILD_RANGE = 3;
3 const CREEP_RANGED_ATTACK_RANGE = 3;
3 const CREEP_UPGRADE_RANGE = 3;
3 const CREEP_REPAIR_RANGE = 3;
3 const CREEP_RANGED_HEAL_RANGE = 3;
1 const CREEP_HARVEST_RANGE = 1;
1 const CREEP_WITHDRAW_RANGE = 1;
Base cost of any successful action that changes game state 0.2 const CONST_COST = 0.2;
The distance labs need to be within to beable to runReaction() or

reverseReaction()

2 const LAB_REACT_RANGE = 2;
The distance a creep and a lab need to be to boostCreep() or

unboostCreep()

1 const LAB_BOOST_RANGE = 1;
The maximum amount of deals that can be done on the market in

one tick.

10 const MARKET_MAX_DEALS_PER_TICK = 10;
The maximum amount of characters a controller sign can have. 100 const CONTROLLER_SIGN_MAX_LENGTH = 100;
The maximum amount of characters a creep name can have. 100 const CREEP_NAME_MAX_LENGTH = 100;
The maximum amount of characters a power-creep name can have. 100 const POWER_CREEP_NAME_MAX_LENGTH = 100;
The maximum amount of characters a flag name can have. 60 const FLAG_NAME_MAX_LENGTH = 60;
The maximum amount of characters a spawn name can have. 100 const SPAWN_NAME_MAX_LENGTH = 100;
The maximum amount of characters a creep can say() 10 const SAY_MAX_LENGTH = 10;
The fatigue reduction of a move part per tick when hits > 0 2 const MOVE_POWER = 2;
The maximum amount of RoomVisuals per room (in bytes) 512000 const ROOM_VIS_MAX_SIZE = 512000;
The maximum amount of MapVisuals allowed (in bytes) 1024000 const MAP_VIS_MAX_SIZE = 1024000;
The maximum & minimum values for a room's possible positions {minX: 0, minY: 0, maxX:49, maxY:49} const ROOM_BOUNDRY_VALUES = {minX: 0, minY: 0, maxX:49, maxY:49}

Other beneficial constants[edit | edit source]

Description Value Code Sample
Energy-per-tick income for a given source 10* const SOURCE_GOAL_OWNED = SOURCE_ENERGY_CAPACITY / ENERGY_REGEN_TIME;
5* const SOURCE_GOAL_NEUTRAL = SOURCE_ENERGY_NEUTRAL_CAPACITY / ENERGY_REGEN_TIME;
13.3334* const SOURCE_GOAL_KEEPER = SOURCE_ENERGY_KEEPER_CAPACITY / ENERGY_REGEN_TIME;
Optimal number of work parts 5* const SOURCE_HARVEST_PARTS = SOURCE_ENERGY_CAPACITY / HARVEST_POWER / ENERGY_REGEN_TIME;
2.5* const SOURCE_HARVEST_PARTS_NEUTRAL = SOURCE_ENERGY_NEUTRAL_CAPACITY / HARVEST_POWER / ENERGY_REGEN_TIME;
6.6667* const SOURCE_HARVEST_PARTS_KEEPER = SOURCE_ENERGY_KEEPER_CAPACITY / HARVEST_POWER / ENERGY_REGEN_TIME;
Optimal number of carry parts 0.2* const SOURCE_CARRY_PARTS_PER_DISTANCE_OWNED = SOURCE_GOAL_OWNED / CARRY_CAPACITY;
0.1* const SOURCE_CARRY_PARTS_PER_DISTANCE_NEUTRAL = SOURCE_GOAL_NEUTRAL / CARRY_CAPACITY;
0.26667* const SOURCE_CARRY_PARTS_PER_DISTANCE_KEEPER = SOURCE_GOAL_KEEPER / CARRY_CAPACITY;
Average energy per tick upkeep cost 0.03* const RAMPART_UPKEEP = RAMPART_DECAY_AMOUNT / REPAIR_POWER / RAMPART_DECAY_TIME;
0.001* const ROAD_UPKEEP = ROAD_DECAY_AMOUNT / REPAIR_POWER / ROAD_DECAY_TIME;
0.005* const ROAD_UPKEEP_SWAMP = (ROAD_DECAY_AMOUNT * CONSTRUCTION_COST_ROAD_SWAMP_RATIO) / REPAIR_POWER / ROAD_DECAY_TIME;
0.15* const ROAD_UPKEEP_TUNNEL = (ROAD_DECAY_AMOUNT * CONSTRUCTION_COST_ROAD_WALL_RATIO) / REPAIR_POWER / ROAD_DECAY_TIME;
0.1* const CONTAINER_UPKEEP = CONTAINER_DECAY / REPAIR_POWER / CONTAINER_DECAY_TIME_OWNED;
0.5* const REMOTE_CONTAINER_UPKEEP = CONTAINER_DECAY / REPAIR_POWER / CONTAINER_DECAY_TIME;
Boolean indicator of world type false const IS_PTR = !!(Game.shard && Game.shard.ptr);
false const IS_SIM = !!Game.rooms['sim'];
true const IS_MMO = !!(Game.shard && Game.shard.name && Game.shard.name.startsWith('shard'));

* values marked with the asterisk are just examples and subject to change should the underlying constants change