screeps/constants/
extra.rs

1//! Additional constants representing internal game mechanics that aren't
2//! included in the game's constants
3
4/// Percentage of energy spent on construction that is left in a [`Resource`] if
5/// the construction site is destroyed by [`ConstructionSite::remove`], or from
6/// being stepped on by a hostile creep
7///
8/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/intents/room/remove-construction-site.js#L18)
9///
10/// [`Resource`]: crate::objects::Resource
11/// [`ConstructionSite::remove`]: crate::objects::ConstructionSite::remove
12pub const CONSTRUCTION_SITE_DROP_RATIO: f32 = 0.5;
13
14/// Maximum length (in UTF-16 units) of input to [`Creep::sign_controller`]
15///
16/// [Code reference](https://github.com/screeps/common/blob/e3e283ffa5d34f9f4e8d474d998065c26025d4bb/lib/system.js#L74)
17///
18/// [`Creep::sign_controller`]: crate::objects::Creep::sign_controller
19pub const CONTROLLER_SIGN_MAX_LENGTH: u32 = 100;
20
21/// Percentage of progress toward next level controllers retain when downgraded
22///
23/// After a downgrade, the controller loses its previous progress toward the
24/// next level, and has its progress set to 90% of the amount needed to upgrade
25/// back to the level that it just downgraded from.
26///
27/// [Code reference](https://github.com/screeps/engine/blob/97c9d12385fed686655c13b09f5f2457dd83a2bf/src/processor/intents/controllers/tick.js#L66)
28pub const CONTROLLER_DOWNGRADE_PROGRESS_RATIO: f32 = 0.9;
29
30/// Maximum amount of CPU that can be accumulated in [`game::cpu::bucket`] per
31/// shard
32///
33/// [Code reference](https://github.com/screeps/driver/blob/97a9e51d124c7170429caa1621096f0f4d888d72/lib/index.js#L26)
34///
35/// [`game::cpu::bucket`]: crate::game::cpu::bucket
36pub const CPU_BUCKET_MAX: u32 = 10_000;
37
38/// Time (in milliseconds) that the [`cpu::set_shard_limits`] function needs to
39/// cool down between calls
40///
41/// [Documentation reference](https://github.com/screeps/docs/blob/06a2a1dfbab14b9c4fdffe7a70ee2f55ea6b430c/api/source/Game.md?plain=1#L262)
42/// (code is closed-source)
43///
44/// [`cpu::set_shard_limits`]: crate::game::cpu::set_shard_limits
45pub const CPU_SET_SHARD_LIMITS_COOLDOWN: u32 = 12 * 3600 * 1000;
46
47/// Maximum value of [`cpu::tick_limit`], the amount of CPU time (in
48/// milliseconds) available this tick, including available time from the bucket
49/// ([`game::cpu::bucket`])
50///
51/// [Code reference](https://github.com/screeps/driver/blob/97a9e51d124c7170429caa1621096f0f4d888d72/lib/index.js#L25)
52///
53/// [`cpu::tick_limit`]: crate::game::cpu::tick_limit
54/// [`game::cpu::bucket`]: crate::game::cpu::bucket
55pub const CPU_TICK_LIMIT_MAX: u32 = 500;
56
57/// [`Creep::hits_max`] gained for each [`Part`] in a given creep's
58/// [`Creep::body`]
59///
60/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/intents/spawns/create-creep.js#L89)
61///
62/// [`Creep::hits_max`]: crate::objects::Creep::hits_max
63/// [`Part`]: crate::constants::Part
64/// [`Creep::body`]: crate::objects::Creep::body
65pub const CREEP_HITS_PER_PART: u32 = 100;
66
67/// Maximum length (in UTF-16 units) of the string input to
68/// [`StuctureSpawn::spawn_creep`] for the name of a [`Creep`]
69///
70/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/game/structures.js#L1069)
71///
72/// [`StuctureSpawn::spawn_creep`]: crate::objects::StructureSpawn::spawn_creep
73/// [`Creep`]: crate::objects::Creep
74pub const CREEP_NAME_MAX_LENGTH: u32 = 100;
75
76/// Maximum length (in UTF-16 units) of string input to [`Creep::say`] and
77/// [`PowerCreep::say`]
78///
79/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/intents/creeps/say.js#L19)
80///
81/// [`Creep::say`]: crate::objects::Creep::say
82/// [`PowerCreep::say`]: crate::objects::PowerCreep::say
83pub const CREEP_SAY_MAX_LENGTH: u32 = 10;
84
85/// Maximum length (in UTF-16 units) of names of [`Flag`] objects
86///
87/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/game/rooms.js#L1015)
88///
89/// [`Flag`]: crate::objects::Flag
90pub const FLAG_NAME_MAX_LENGTH: u32 = 100;
91
92/// The cost of a single 'intent' in CPU time, charged for all successful
93/// changes to game state.
94///
95/// API calls which change the game state ([`Creep::pull`], [`Creep::say`], and
96/// [`PowerCreep::say`] are excepted) will add this amount to your used CPU for
97/// the tick each time they're successful.
98///
99/// [Code reference](https://github.com/screeps/driver/blob/97a9e51d124c7170429caa1621096f0f4d888d72/lib/runtime/runtime.js#L52)
100///
101/// [`Creep::pull`]: crate::objects::Creep::pull
102/// [`Creep::say`]: crate::objects::Creep::say
103/// [`PowerCreep::say`]: crate::objects::PowerCreep::say
104pub const INTENT_CPU_COST: f64 = 0.2;
105
106/// Maximum size (in UTF-16 units) of data input to
107/// [`inter_shard_memory::set_local`]
108///
109/// [Documentation reference](https://github.com/screeps/docs/blob/06a2a1dfbab14b9c4fdffe7a70ee2f55ea6b430c/api/source/InterShardMemory.md?plain=1#L7)
110/// (code is closed-source)
111///
112/// [`inter_shard_memory::set_local`]: crate::inter_shard_memory::set_local
113pub const INTER_SHARD_MEMORY_SIZE_LIMIT: u32 = 100 * 1024;
114
115/// The [`Owner::username`] of hostile non-player structures and creeps which
116/// create strongholds and spawn to attack rooms due to energy harvesting
117/// activity
118///
119/// [`Owner::username`]: crate::objects::Owner::username
120pub const INVADER_USERNAME: &str = "Invader";
121
122/// Maximum range between interacting [`StructureLab`] strucures for
123/// [`StructureLab::run_reaction`] or [`StructureLab::reverse_reaction`]
124///
125/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/intents/labs/run-reaction.js#L26)
126///
127/// [`StructureLab`]: crate::objects::StructureLab
128/// [`StructureLab::run_reaction`]: crate::objects::StructureLab::run_reaction
129/// [`StructureLab::reverse_reaction`]: crate::objects::StructureLab::reverse_reaction
130pub const LAB_REACTION_RANGE: u32 = 2;
131
132/// The maximum size (in UTF-16 units) of the serialized [`MapVisual`] data
133///
134/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/game/console.js#L42-L45)
135///
136/// [`MapVisual`]: crate::objects::MapVisual
137pub const MAP_VISUAL_SIZE_LIMIT: u32 = 1000 * 1024;
138
139/// The maximum number of times that you can use [`game::market::deal`] in a
140/// tick
141///
142/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/game/market.js#L149)
143///
144/// [`game::market::deal`]: crate::game::market::deal
145pub const MARKET_MAX_DEALS_PER_TICK: u32 = 10;
146
147/// Maximum size (in UTF-16 units) of the string contents allowed in
148/// [`raw_memory::segments`]
149///
150/// [Code reference](https://github.com/screeps/driver/blob/97a9e51d124c7170429caa1621096f0f4d888d72/lib/runtime/runtime.js#L255)
151///
152/// [`raw_memory::segments`]: crate::raw_memory::segments
153pub const MEMORY_SEGMENT_SIZE_LIMIT: u32 = 100 * 1024;
154
155/// Maximum active memory segments to be readable next tick allowed in
156/// [`raw_memory::set_active_segments`]
157///
158/// [Code reference](https://github.com/screeps/driver/blob/97a9e51d124c7170429caa1621096f0f4d888d72/lib/runtime/runtime.js#L125)
159///
160/// [`raw_memory::set_active_segments`]: crate::raw_memory::set_active_segments
161pub const MEMORY_SEGMENT_ACTIVE_LIMIT: u32 = 10;
162
163/// Maximum size (in UTF-16 units) of the string contents allowed in serialized
164/// memory or [`raw_memory::set`]
165///
166/// [Code reference](https://github.com/screeps/driver/blob/97a9e51d124c7170429caa1621096f0f4d888d72/lib/runtime/runtime.js#L104)
167///
168/// [`raw_memory::set`]: crate::raw_memory::set
169pub const MEMORY_SIZE_LIMIT: u32 = 2 * 1024 * 1024;
170
171/// Fatigue points added for each body part that generates fatigue when stepping
172/// onto a tile with a [`StructureRoad`]
173///
174/// [`StructureRoad`]: crate::objects::StructureRoad
175pub const MOVE_COST_ROAD: u32 = 1;
176
177/// Fatigue points added for each body part that generates fatigue when stepping
178/// onto a tile with [`Terrain::Plain`]
179///
180/// [`Terrain::Plain`]: crate::constants::Terrain::Plain
181pub const MOVE_COST_PLAIN: u32 = 2;
182
183/// Fatigue points added for each body part that generates fatigue when stepping
184/// onto a tile with [`Terrain::Swamp`]
185///
186/// [`Terrain::Swamp`]: crate::constants::Terrain::Swamp
187pub const MOVE_COST_SWAMP: u32 = 10;
188
189/// Fatigue points removed per effective [`Part::Move`] per tick
190///
191/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/intents/movement.js#L204)
192///
193/// [`Part::Move`]: crate::constants::Part::Move
194pub const MOVE_POWER: u32 = 2;
195
196/// Maximum length (in UTF-16 units) of message content sent to
197/// [`game::notify`].
198///
199/// Note that the official documentation reflects a limit of 1000, but a limit
200/// of 500 is enforced in the driver (truncating to that length if a longer
201/// string is input).
202///
203/// [Code reference](https://github.com/screeps/driver/blob/e691bd3ee843cb12ac4bedc68397b2b92709f622/lib/index.js#L208)
204///
205/// [`game::notify`]: crate::game::notify
206pub const NOTIFY_MAX_LENGTH: u32 = 500;
207
208/// Maximum carry capacity of a [`PowerCreep`] per level
209///
210/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/global-intents/power/upgradePowerCreep.js#L46)
211///
212/// [`PowerCreep`]: crate::objects::PowerCreep
213pub const POWER_CREEP_CARRY_CAPACITY_PER_LEVEL: u32 = 100;
214
215/// Maximum hits of a [`PowerCreep`] per level
216///
217/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/global-intents/power/upgradePowerCreep.js#L47)
218///
219/// [`PowerCreep`]: crate::objects::PowerCreep
220pub const POWER_CREEP_HITS_PER_LEVEL: u32 = 1000;
221
222/// Maximum length (in UTF-16 units) of names input to [`PowerCreep::create`] or
223/// [`AccountPowerCreep::rename`]
224///
225/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/game/power-creeps.js#L396)
226///
227/// [`PowerCreep::create`]: crate::objects::PowerCreep::create
228/// [`AccountPowerCreep::rename`]: crate::objects::AccountPowerCreep::rename
229pub const POWER_CREEP_NAME_MAX_LENGTH: u32 = 100;
230
231/// The range of all ranged actions of [`Creep`] objects
232///
233/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/intents/creeps/rangedAttack.js#L21)
234///
235/// [`Creep`]: crate::objects::Creep
236pub const CREEP_RANGED_ACTION_RANGE: u8 = 3;
237
238/// Hits of damage per effective ranged attack part per
239/// [`Creep::ranged_mass_attack`] action at range 1
240///
241/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/intents/creeps/rangedMassAttack.js#L32)
242///
243/// [`Creep::ranged_mass_attack`]: crate::objects::Creep::ranged_mass_attack
244pub const RANGED_MASS_ATTACK_POWER_RANGE_1: u32 = 10;
245/// Hits of damage per effective ranged attack part per
246/// [`Creep::ranged_mass_attack`] action at range 2
247///
248/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/intents/creeps/rangedMassAttack.js#L32)
249///
250/// [`Creep::ranged_mass_attack`]: crate::objects::Creep::ranged_mass_attack
251pub const RANGED_MASS_ATTACK_POWER_RANGE_2: u32 = 4;
252/// Hits of damage per effective ranged attack part per
253/// [`Creep::ranged_mass_attack`] action at range 3
254///
255/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/processor/intents/creeps/rangedMassAttack.js#L32)
256///
257/// [`Creep::ranged_mass_attack`]: crate::objects::Creep::ranged_mass_attack
258pub const RANGED_MASS_ATTACK_POWER_RANGE_3: u32 = 1;
259
260/// The maximum size (500 KiB) of the serialized [`RoomVisual`] data for each
261/// room
262///
263/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/game/console.js#L42-L45)
264///
265/// [`RoomVisual`]: crate::objects::RoomVisual
266pub const ROOM_VISUAL_PER_ROOM_SIZE_LIMIT: u32 = 500 * 1024;
267
268/// The maximum height/width of a [`Room`] in the game
269///
270/// [`Room`]: crate::objects::Room
271pub const ROOM_SIZE: u8 = 50;
272
273/// ['ROOM_SIZE'] cast into a `usize`, for indexing convenience.
274///
275/// ['ROOM_SIZE']: self::ROOM_SIZE
276pub const ROOM_USIZE: usize = ROOM_SIZE as usize;
277
278/// The number of total tiles in each [`Room`] in the game
279///
280/// [`Room`]: crate::objects::Room
281pub const ROOM_AREA: usize = ROOM_USIZE * ROOM_USIZE;
282
283/// Owner username of hostile non-player structures and creeps which occupy
284/// sector center rooms.
285pub const SOURCE_KEEPER_USERNAME: &str = "Source Keeper";
286
287/// Maximum length (in UTF-16 units) of the name of a [`StructureSpawn`], set
288/// via the optional name parameter when creating a [`ConstructionSite`]
289///
290/// [Code reference](https://github.com/screeps/engine/blob/c6c4fc9e656f160e0e0174b0dd9a817d2dd18976/src/game/rooms.js#L1042)
291///
292/// [`StructureSpawn`]: crate::objects::StructureSpawn
293/// [`ConstructionSite`]: crate::objects::ConstructionSite
294pub const SPAWN_NAME_MAX_LENGTH: u32 = 100;
295
296/// Exponential scaling rate for [`StructureTerminal`] energy costs
297///
298/// Energy cost to send resources with a terminal is determined by the formula:
299///
300/// ```js
301/// Math.ceil(resource_amount * (1 - Math.exp(-range / 30)))
302/// ```
303///
304/// [Code reference](https://github.com/screeps/engine/blob/c682c00b058de21e927c3a6c42fadb34c9745767/src/utils.js#L658)
305///
306/// [`StructureTerminal`]: crate::objects::StructureTerminal
307pub const TERMINAL_SEND_COST_SCALE: u32 = 30;