├── .gitignore ├── Config └── SublimeCodeIntel.json ├── ConstructionSite.js ├── Creep.js ├── Deposit.js ├── Flag.js ├── Game.js ├── Global └── Constants.js ├── InterShardMemory.js ├── Memory.js ├── Mineral.js ├── Nuke.js ├── Order.js ├── OwnedStructure.js ├── PathFinder.js ├── PowerCreep.js ├── RawMemory.js ├── Readme.md ├── Resource.js ├── Room.js ├── RoomObject.js ├── RoomPosition.js ├── RoomVisual.js ├── Ruin.js ├── Source.js ├── Store.js ├── Structure.js ├── Structures ├── StructureContainer.js ├── StructureController.js ├── StructureExtension.js ├── StructureExtractor.js ├── StructureFactory.js ├── StructureInvaderCore.js ├── StructureKeeperLair.js ├── StructureLab.js ├── StructureLink.js ├── StructureNuker.js ├── StructureObserver.js ├── StructurePortal.js ├── StructurePowerBank.js ├── StructurePowerSpawn.js ├── StructureRampart.js ├── StructureRoad.js ├── StructureSpawn.js ├── StructureStorage.js ├── StructureTerminal.js ├── StructureTower.js └── StructureWall.js ├── TODO.md ├── Tombstone.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | atlassian-ide-plugin.xml 3 | .git/ 4 | node_modules 5 | -------------------------------------------------------------------------------- /Config/SublimeCodeIntel.json: -------------------------------------------------------------------------------- 1 | { 2 | /* 3 | Defines a configuration for each language. 4 | */ 5 | "codeintel_language_settings": { 6 | "JavaScript": { 7 | "codeintel_scan_extra_dir": [], 8 | "codeintel_scan_exclude_dir":["/build/", "/min/"], 9 | "codeintel_scan_files_in_project": true, 10 | "codeintel_max_recursive_dir_depth": 2, 11 | "codeintel_selected_catalogs": ["jQuery"] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ConstructionSite.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A site of a structure which is currently under construction. 3 | * A construction site can be created using the 'Construct' button at the left of the game field or the Room.createConstructionSite method. 4 | * To build a structure on the construction site, give a worker creep some amount of energy and perform Creep.build action. 5 | * 6 | * @class 7 | * @extends {RoomObject} 8 | * 9 | * @see {@link https://docs.screeps.com/api/#ConstructionSite} 10 | */ 11 | ConstructionSite = function() { }; 12 | 13 | ConstructionSite.prototype = 14 | { 15 | /** 16 | * A unique object identificator. 17 | * You can use Game.getObjectById method to retrieve an object instance by its id. 18 | * 19 | * @see {@link https://docs.screeps.com/api/#ConstructionSite.id} 20 | * 21 | * @type {string} 22 | */ 23 | id: "", 24 | 25 | /** 26 | * Whether this is your own construction site. 27 | * 28 | * @see {@link https://docs.screeps.com/api/#ConstructionSite.my} 29 | * 30 | * @type {boolean} 31 | */ 32 | my: true, 33 | 34 | /** 35 | * An object with the structure’s owner info 36 | * 37 | * @see {@link https://docs.screeps.com/api/#ConstructionSite.owner} 38 | * 39 | * @type {{username: string}} 40 | */ 41 | owner: 42 | { 43 | username: "" 44 | }, 45 | 46 | /** 47 | * The current construction progress. 48 | * 49 | * @see {@link https://docs.screeps.com/api/#ConstructionSite.progress} 50 | * 51 | * @type {number} 52 | */ 53 | progress: 0, 54 | 55 | /** 56 | * The total construction progress needed for the structure to be built. 57 | * 58 | * @see {@link https://docs.screeps.com/api/#ConstructionSite.progressTotal} 59 | * 60 | * @type {number} 61 | */ 62 | progressTotal: 0, 63 | 64 | /** 65 | * One of the STRUCTURE_* constants. 66 | * 67 | * @see {@link https://docs.screeps.com/api/#ConstructionSite.structureType} 68 | * 69 | * @type {string} 70 | */ 71 | structureType: "", 72 | 73 | /** 74 | * Remove the construction site. 75 | * 76 | * @see {@link https://docs.screeps.com/api/#ConstructionSite.remove} 77 | * 78 | * @type {function} 79 | * 80 | * @return {number|OK|ERR_NOT_OWNER} 81 | */ 82 | remove: function() { } 83 | }; 84 | -------------------------------------------------------------------------------- /Creep.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @class 4 | * @extends {RoomObject} 5 | * 6 | * @see {@link https://docs.screeps.com/api/#Creep} 7 | */ 8 | Creep = function() { }; 9 | 10 | Creep.prototype = 11 | { 12 | /** 13 | * An array describing the creep’s body. 14 | * 15 | * @see {@link https://docs.screeps.com/api/#Creep.body} 16 | * 17 | * @type {Array<{boost:string, type:string, hits:number}>} 18 | * 19 | * @note boost: If the body part is boosted, this property specifies the mineral type which is used for boosting. One of the RESOURCE_* constants. 20 | * @note type: One of the body part types constants. 21 | * @note hits: The remaining amount of hit points of this body part. 22 | * 23 | */ 24 | body: [], 25 | 26 | /** 27 | * @deprecated Since version 4.x, replaced by `.store`. 28 | * 29 | * An object with the creep's cargo contents. 30 | * Each object key is one of the RESOURCE_* constants, values are resources amounts. 31 | * Use _.sum(creep.carry) to get the total amount of contents. 32 | * 33 | * @see {@link https://docs.screeps.com/api/#Creep.carry} 34 | * 35 | * @type {object} 36 | */ 37 | carry: {}, 38 | 39 | /** 40 | * @deprecated Since version 4.x, replaced by `.store.getCapacity()`. 41 | * 42 | * The total amount of resources the creep can carry. 43 | * 44 | * @see {@link https://docs.screeps.com/api/#Creep.carryCapacity} 45 | * 46 | * @type {number} 47 | */ 48 | carryCapacity: 0, 49 | 50 | /** 51 | * The movement fatigue indicator. If it is greater than zero, the creep cannot move. 52 | * 53 | * @see {@link https://docs.screeps.com/api/#Creep.fatigue} 54 | * 55 | * @type {number} 56 | */ 57 | fatigue: 0, 58 | 59 | /** 60 | * The current amount of hit points of the creep. 61 | * 62 | * @see {@link https://docs.screeps.com/api/#Creep.hits} 63 | * 64 | * @type {number} 65 | */ 66 | hits: 0, 67 | 68 | /** 69 | * The maximum amount of hit points of the creep. 70 | * 71 | * @see {@link https://docs.screeps.com/api/#Creep.hitsMax} 72 | * 73 | * @type {number} 74 | */ 75 | hitsMax: 0, 76 | 77 | /** 78 | * A unique object identificator. 79 | * You can use Game.getObjectById method to retrieve an object instance by its id. 80 | * 81 | * @see {@link https://docs.screeps.com/api/#Creep.id} 82 | * 83 | * @type {string} 84 | */ 85 | id: "", 86 | 87 | /** 88 | * A shorthand to Memory.creeps[creep.name]. 89 | * You can use it for quick access the creep’s specific memory data object. 90 | * 91 | * @see {@link https://docs.screeps.com/api/#Creep.memory} 92 | * 93 | * @type {*} 94 | */ 95 | memory: {}, 96 | 97 | /** 98 | * Whether it is your creep or foe. 99 | * 100 | * @see {@link https://docs.screeps.com/api/#Creep.my} 101 | * 102 | * @type {boolean} 103 | */ 104 | my: true, 105 | 106 | /** 107 | * Creep’s name. 108 | * You can choose the name while creating a new creep, and it cannot be changed later. 109 | * This name is a hash key to access the creep via the Game.creeps object. 110 | * 111 | * @see {@link https://docs.screeps.com/api/#Creep.name} 112 | * 113 | * @type {string} 114 | */ 115 | name: "", 116 | 117 | /** 118 | * The text message that the creep was saying at the last tick. 119 | * 120 | * @see {@link https://docs.screeps.com/api/#Creep.saying} 121 | * 122 | * @type {string} 123 | */ 124 | saying: "", 125 | 126 | /** 127 | * An object with the creep’s owner info 128 | * 129 | * @see {@link https://docs.screeps.com/api/#Creep.owner} 130 | * 131 | * @type {{username:string}} 132 | */ 133 | owner: 134 | { 135 | username: "" 136 | }, 137 | 138 | /** 139 | * Whether this creep is still being spawned. 140 | * 141 | * @see {@link https://docs.screeps.com/api/#Creep.spawning} 142 | * 143 | * @type {boolean} 144 | */ 145 | spawning: false, 146 | 147 | /** 148 | * A Store object that contains cargo of this creep. 149 | * 150 | * @see {@link https://docs.screeps.com/api/#Creep.store} 151 | * 152 | * @type {Store} 153 | */ 154 | store: {}, 155 | 156 | /** 157 | * The remaining amount of game ticks after which the creep will die. 158 | * 159 | * @see {@link https://docs.screeps.com/api/#Creep.ticksToLive} 160 | * 161 | * @type {number} 162 | */ 163 | ticksToLive: 0, 164 | 165 | /** 166 | * Attack another creep, power creep, or structure in a short-ranged attack. 167 | * Requires the ATTACK body part. 168 | * If the target is inside a rampart, then the rampart is attacked instead. 169 | * The target has to be at adjacent square to the creep. 170 | * If the target is a creep with ATTACK body parts and is not inside a rampart, it will automatically hit back at the attacker. 171 | * 172 | * @see {@link https://docs.screeps.com/api/#Creep.attack} 173 | * 174 | * @type {function} 175 | * 176 | * @param {Creep|PowerCreep|Structure} target The target object to be attacked. 177 | * 178 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART} 179 | */ 180 | attack: function(target) { }, 181 | 182 | /** 183 | * Decreases the controller's downgrade timer by 300 ticks per every CLAIM body part, or reservation timer by 1 tick per every CLAIM body part. 184 | * If the controller under attack is owned, it cannot be upgraded or attacked again for the next 1,000 ticks. 185 | * The target has to be at adjacent square to the creep. 186 | * 187 | * @see {@link https://docs.screeps.com/api/#Creep.attackController} 188 | * 189 | * @type {function} 190 | * 191 | * @param {StructureController} target The target controller object. 192 | * 193 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_TIRED|ERR_NO_BODYPART} 194 | */ 195 | attackController: function(target) { }, 196 | 197 | /** 198 | * Build a structure at the target construction site using carried energy. 199 | * Requires WORK and CARRY body parts. 200 | * The target has to be within 3 squares range of the creep. 201 | * 202 | * @see {@link https://docs.screeps.com/api/#Creep.build} 203 | * 204 | * @type {function} 205 | * 206 | * @param {ConstructionSite} target The target construction site to be built. 207 | * 208 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART} 209 | */ 210 | build: function(target) { }, 211 | 212 | /** 213 | * Cancel the order given during the current game tick. 214 | * 215 | * @see {@link https://docs.screeps.com/api/#Creep.cancelOrder} 216 | * 217 | * @type {function} 218 | * 219 | * @param {string} methodName The name of a creep's method to be cancelled. 220 | * 221 | * @return {number|OK|ERR_NOT_FOUND} 222 | */ 223 | cancelOrder: function(methodName) { }, 224 | 225 | /** 226 | * Claims a neutral controller under your control. 227 | * Requires the CLAIM body part. 228 | * The target has to be at adjacent square to the creep. 229 | * 230 | * @see {@link https://docs.screeps.com/api/#Creep.claimController} 231 | * 232 | * @type {function} 233 | * 234 | * @param {StructureController} target The target controller object. 235 | * 236 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_NO_BODYPART|ERR_GCL_NOT_ENOUGH} 237 | */ 238 | claimController: function(target) { }, 239 | 240 | /** 241 | * Dismantles any structure that can be constructed (even hostile) returning 50% of the energy spent on its repair. 242 | * Requires the WORK body part. 243 | * If the creep has an empty CARRY body part, the energy is put into it; otherwise it is dropped on the ground. 244 | * The target has to be at adjacent square to the creep. 245 | * 246 | * @see {@link https://docs.screeps.com/api/#Creep.dismantle} 247 | * 248 | * @type {function} 249 | * 250 | * @param {Structure} target The target structure. 251 | * 252 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART} 253 | */ 254 | dismantle: function(target) { }, 255 | 256 | /** 257 | * Drop this resource on the ground. 258 | * 259 | * @see {@link https://docs.screeps.com/api/#Creep.drop} 260 | * 261 | * @type {function} 262 | * 263 | * @param {string} resourceType One of the RESOURCE_* constants. 264 | * @param {number} [amount] The amount of resource units to be dropped. If omitted, all the available carried amount is used. 265 | * 266 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_ARGS} 267 | */ 268 | drop: function(resourceType, amount) { }, 269 | 270 | /** 271 | * Add one more available safe mode activation to a room controller. 272 | * The creep has to be at adjacent square to the target room controller and have 1000 ghodium resource. 273 | * 274 | * @see {@link https://docs.screeps.com/api/#Creep.generateSafeMode} 275 | * 276 | * @type {function} 277 | * 278 | * @param {StructureController} target The target room controller. 279 | * 280 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE} 281 | */ 282 | generateSafeMode: function(target) { }, 283 | 284 | /** 285 | * Get the quantity of live body parts of the given type. 286 | * Fully damaged parts do not count. 287 | * 288 | * @see {@link https://docs.screeps.com/api/#Creep.getActiveBodyparts} 289 | * 290 | * @type {function} 291 | * 292 | * @param {string} type A body part type, one of the following body part constants: MOVE, WORK, CARRY, ATTACK, RANGED_ATTACK, HEAL, TOUGH 293 | * 294 | * @return {number} A number representing the quantity of body parts. 295 | */ 296 | getActiveBodyparts: function(type) { }, 297 | 298 | /** 299 | * Harvest energy from the source or resources from minerals and deposits. 300 | * Requires the WORK body part. 301 | * If the creep has an empty CARRY body part, the harvested resource is put into it; otherwise it is dropped on the ground. 302 | * The target has to be at an adjacent square to the creep. 303 | * 304 | * @see {@link https://docs.screeps.com/api/#Creep.harvest} 305 | * 306 | * @type {function} 307 | * 308 | * @param {Source|Mineral|Deposit} target The object to be harvested. 309 | * 310 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_FOUND|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_TIRED|ERR_NO_BODYPART} 311 | */ 312 | harvest: function(target) { }, 313 | 314 | /** 315 | * Heal self or another creep. 316 | * It will restore the target creep’s damaged body parts function and increase the hits counter. 317 | * Requires the HEAL body part. 318 | * The target has to be at adjacent square to the creep. 319 | * 320 | * @see {@link https://docs.screeps.com/api/#Creep.heal} 321 | * 322 | * @type {function} 323 | * 324 | * @param {Creep|PowerCreep} target The target creep object. 325 | * 326 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART} 327 | */ 328 | heal: function(target) { }, 329 | 330 | /** 331 | * Move the creep one square in the specified direction. 332 | * Requires the MOVE body part, or another creep nearby pulling the creep. 333 | * 334 | * @see {@link https://docs.screeps.com/api/#Creep.move} 335 | * 336 | * @type {function} 337 | * 338 | * @param {Creep|number} direction A creep nearby, or one of the following constants: TOP, TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM, BOTTOM_LEFT, LEFT, TOP_LEFT 339 | * 340 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS|ERR_TIRED|ERR_NO_BODYPART} 341 | */ 342 | move: function(direction) { }, 343 | 344 | /** 345 | * Move the creep using the specified predefined path. 346 | * Requires the MOVE body part. 347 | * 348 | * @see {@link https://docs.screeps.com/api/#Creep.moveByPath} 349 | * 350 | * @type {function} 351 | * 352 | * @param {Array|string} path A path value as returned from Room.findPath, RoomPosition.findPathTo, or PathFinder.search methods. Both array form and serialized string form are accepted. 353 | * 354 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_FOUND|ERR_INVALID_ARGS|ERR_TIRED|ERR_NO_BODYPART} 355 | */ 356 | moveByPath: function(path) { }, 357 | 358 | /** 359 | * Find the optimal path to the target within the same room and move to it. 360 | * A shorthand to consequent calls of pos.findPathTo() and move() methods. 361 | * If the target is in another room, then the corresponding exit will be used as a target. 362 | * Requires the MOVE body part. 363 | * 364 | * @see {@link https://docs.screeps.com/api/#Creep.moveTo} 365 | * 366 | * @type {function} 367 | * 368 | * @param {number|RoomPosition|RoomObject} x X position of the target in the same room. 369 | * @param {number} [y] Y position of the target in the same room. 370 | * @param {object} [opts] An object containing additional options 371 | * @param {number} [opts.reusePath] This option enables reusing the path found along multiple game ticks. It allows to save CPU time, but can result in a slightly slower creep reaction behavior. The path is stored into the creep's memory to the _move property. The reusePath value defines the amount of ticks which the path should be reused for. The default value is 5. Increase the amount to save more CPU, decrease to make the movement more consistent. Set to 0 if you want to disable path reusing. 372 | * @param {boolean} [opts.serializeMemory] If reusePath is enabled and this option is set to true, the path will be stored in memory in the short serialized form using Room.serializePath. The default value is true. 373 | * @param {boolean} [opts.noPathFinding] If this option is set to true, moveTo method will return ERR_NOT_FOUND if there is no memorized path to reuse. This can significantly save CPU time in some cases. The default value is false. 374 | * @param {object} [opts.visualizePathStyle] Draw a line along the creep’s path using RoomVisual.poly. You can provide either an empty object or custom style parameters. 375 | * @param {string} [opts.visualizePathStyle.fill] Fill color in any web format 376 | * @param {string} [opts.visualizePathStyle.stroke] Stroke color in any web format 377 | * @param {string} [opts.visualizePathStyle.lineStyle] Either undefined (solid line), dashed, or dotted 378 | * @param {number} [opts.visualizePathStyle.strokeWidth] Stroke line width 379 | * @param {number} [opts.visualizePathStyle.opacity] Opacity value 380 | * @param {boolean} [opts.ignoreCreeps] Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default value is false. 381 | * @param {boolean} [opts.ignoreDestructibleStructures] Treat squares with destructible structures (constructed walls, ramparts, spawns, extensions) as walkable. Use this flag when you need to move through a territory blocked by hostile structures. If a creep with an ATTACK body part steps on such a square, it automatically attacks the structure. The default value is false. 382 | * @param {boolean} [opts.ignoreRoads] Ignore road structures. Enabling this option can speed up the search. The default value is false. This is only used when the new PathFinder is enabled. 383 | * @param {function(string, CostMatrix)} [opts.costCallback] You can use this callback to modify a CostMatrix for any room during the search. The callback accepts two arguments, roomName and costMatrix. Use the costMatrix instance to make changes to the positions costs. If you return a new matrix from this callback, it will be used instead of the built-in cached one. This option is only used when the new PathFinder is enabled. 384 | * @param {Array} [opts.ignore] An array of the room's objects or RoomPosition objects which should be treated as walkable tiles during the search. This option cannot be used when the new PathFinder is enabled (use costCallback option instead). 385 | * @param {Array} [opts.avoid] An array of the room's objects or RoomPosition objects which should be treated as obstacles during the search. This option cannot be used when the new PathFinder is enabled (use costCallback option instead). 386 | * @param {number} [opts.maxOps] The maximum limit of possible pathfinding operations. You can limit CPU time used for the search based on ratio 1 op ~ 0.001 CPU. The default value is 2000. 387 | * @param {number} [opts.heuristicWeight] Weight to apply to the heuristic in the A* formula F = G + weight * H. Use this option only if you understand the underlying A* algorithm mechanics! The default value is 1.2. 388 | * @param {boolean} [opts.serialize] If true, the result path will be serialized using Room.serializePath. The default is false. 389 | * @param {number} [opts.maxRooms] The maximum allowed rooms to search. The default (and maximum) is 16. This is only used when the new PathFinder is enabled. 390 | * @param {number} [opts.range] Find a path to a position in specified linear range of target. The default is 0. 391 | * @param {number} [opts.plainCost] Cost for walking on plain positions. The default is 1. 392 | * @param {number} [opts.swampCost] Cost for walking on swamp positions. The default is 5. 393 | * 394 | * @alias moveTo(target, [opts]) 395 | * 396 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_TIRED|ERR_NO_BODYPART|ERR_INVALID_TARGET|ERR_NO_PATH|ERR_NOT_FOUND} 397 | */ 398 | moveTo: function(x, y, opts) { }, 399 | 400 | /** 401 | * Toggle auto notification when the creep is under attack. 402 | * The notification will be sent to your account email. 403 | * Turned on by default. 404 | * 405 | * @see {@link https://docs.screeps.com/api/#Creep.notifyWhenAttacked} 406 | * 407 | * @type {function} 408 | * 409 | * @param {boolean} enabled Whether to enable notification or disable. 410 | * 411 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_ARGS} 412 | */ 413 | notifyWhenAttacked: function(enabled) { }, 414 | 415 | /** 416 | * Pick up an item (a dropped piece of energy). 417 | * Requires the CARRY body part. 418 | * The target has to be at adjacent square to the creep or at the same square. 419 | * 420 | * @see {@link https://docs.screeps.com/api/#Creep.pickup} 421 | * 422 | * @type {function} 423 | * 424 | * @param {Resource} target The target object to be picked up. 425 | * 426 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE} 427 | */ 428 | pickup: function(target) { }, 429 | 430 | /** 431 | * Help another creep to follow this creep. 432 | * The fatigue generated for the target's move will be added to the creep instead of the target. Requires the MOVE body part. 433 | * The target has to be at adjacent square to the creep. The creep must move elsewhere, and the target must move towards the creep. 434 | * 435 | * @see {@link https://docs.screeps.com/api/#Creep.pull} 436 | * 437 | * @type {function} 438 | * 439 | * @param {Creep} target The target creep. 440 | * 441 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE} 442 | */ 443 | pull: function(target) { }, 444 | 445 | /** 446 | * A ranged attack against another creep or structure. 447 | * Requires the RANGED_ATTACK body part. 448 | * If the target is inside a rampart, the rampart is attacked instead. 449 | * The target has to be within 3 squares range of the creep. 450 | * 451 | * @see {@link https://docs.screeps.com/api/#Creep.rangedAttack} 452 | * 453 | * @type {function} 454 | * 455 | * @param {Creep|PowerCreep|Structure} target The target object to be attacked. 456 | * 457 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART} 458 | */ 459 | rangedAttack: function(target) { }, 460 | 461 | /** 462 | * Heal another creep at a distance. 463 | * It will restore the target creep’s damaged body parts function and increase the hits counter. 464 | * Requires the HEAL body part. 465 | * The target has to be within 3 squares range of the creep. 466 | * 467 | * @see {@link https://docs.screeps.com/api/#Creep.rangedHeal} 468 | * 469 | * @type {function} 470 | * 471 | * @param {Creep|PowerCreep} target The target creep object. 472 | * 473 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART} 474 | */ 475 | rangedHeal: function(target) { }, 476 | 477 | /** 478 | * A ranged attack against all hostile creeps or structures within 3 squares range. 479 | * Requires the RANGED_ATTACK body part. 480 | * The attack power depends on the range to each target. 481 | * Friendly units are not affected. 482 | * 483 | * @see {@link https://docs.screeps.com/api/#Creep.rangedMassAttack} 484 | * 485 | * @type {function} 486 | * 487 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NO_BODYPART} 488 | */ 489 | rangedMassAttack: function() { }, 490 | 491 | /** 492 | * Repair a damaged structure using carried energy. 493 | * Requires the WORK and CARRY body parts. 494 | * The target has to be within 3 squares range of the creep. 495 | * 496 | * @see {@link https://docs.screeps.com/api/#Creep.repair} 497 | * 498 | * @type {function} 499 | * 500 | * @param {Structure} target The target structure to be repaired. 501 | * 502 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART} 503 | */ 504 | repair: function(target) { }, 505 | 506 | /** 507 | * Temporarily block a neutral controller from claiming by other players and restore energy sources to their full capacity. 508 | * Each tick, this command increases the counter of the period during which the controller is unavailable by 1 tick per each CLAIM body part. 509 | * The maximum reservation period to maintain is 5,000 ticks. 510 | * The target has to be at adjacent square to the creep. 511 | * 512 | * @see {@link https://docs.screeps.com/api/#Creep.reserveController} 513 | * 514 | * @type {function} 515 | * 516 | * @param {StructureController} target The target controller object to be reserved. 517 | * 518 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART} 519 | */ 520 | reserveController: function(target) { }, 521 | 522 | /** 523 | * Display a visual speech balloon above the creep with the specified message. The message will be 524 | * available for one tick. You can read the last message using the saying property. 525 | * 526 | * @see {@link https://docs.screeps.com/api/#Creep.say} 527 | * 528 | * @type {function} 529 | * 530 | * @param {string} message The message to be displayed. Maximum length is 10 characters. 531 | * @param {boolean} [public] Set to true to allow other players to see this message. Default is false. 532 | * 533 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY} 534 | */ 535 | say: function(message, public) { }, 536 | 537 | /** 538 | * Sign a controller with an arbitrary text visible to all players. 539 | * This text will appear in the room UI, in the world map, and can be accessed via the API. 540 | * You can sign unowned and hostile controllers. The target has to be at adjacent square to the creep. 541 | * Pass an empty string to remove the sign. 542 | * 543 | * @see {@link https://docs.screeps.com/api/#Creep.signController} 544 | * 545 | * @type {function} 546 | * 547 | * @param {StructureController} target The target controller object to be signed. 548 | * @param {string} text The sign text. The string is cut off after 100 characters. 549 | * 550 | * @return {number|OK|ERR_INVALID_TARGET|ERR_BUSY|ERR_NOT_IN_RANGE} 551 | */ 552 | signController: function(target, text) { }, 553 | 554 | /** 555 | * Kill the creep immediately. 556 | * 557 | * @see {@link https://docs.screeps.com/api/#Creep.suicide} 558 | * 559 | * @type {function} 560 | * 561 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY} 562 | */ 563 | suicide: function() { }, 564 | 565 | /** 566 | * Transfer resource from the creep to another object. 567 | * The target has to be at adjacent square to the creep. 568 | * 569 | * @see {@link https://docs.screeps.com/api/#Creep.transfer} 570 | * 571 | * @type {function} 572 | * 573 | * @param {Creep|PowerCreep|Structure} target The target object. 574 | * @param {string} resourceType One of the RESOURCE_* constants. 575 | * @param {number|undefined|null} [amount] The amount of resources to be transferred. If omitted, all the available carried amount is used. 576 | * 577 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS} 578 | */ 579 | transfer: function(target, resourceType, amount) { }, 580 | 581 | /** 582 | * Upgrade your controller to the next level using carried energy. 583 | * Upgrading controllers raises your Global Control Level in parallel. 584 | * Requires WORK and CARRY body parts. 585 | * The target has to be within 3 squares range of the creep. 586 | * A fully upgraded level 8 controller can't be upgraded over 15 energy units per tick regardless of creeps abilities. 587 | * The cumulative effect of all the creeps performing upgradeController in the current tick is taken into account. 588 | * This limit can be increased by using ghodium mineral boost. 589 | * Upgrading the controller raises its ticksToDowngrade timer by 100. The timer must be full in order for controller to be levelled up. 590 | * 591 | * @see {@link https://docs.screeps.com/api/#Creep.upgradeController} 592 | * 593 | * @type {function} 594 | * 595 | * @param {StructureController} target The target controller object to be upgraded. 596 | * 597 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART} 598 | */ 599 | upgradeController: function(target) { }, 600 | 601 | /** 602 | * Withdraw resources from a structure or tombstone. 603 | * The target has to be at adjacent square to the creep. 604 | * Multiple creeps can withdraw from the same object in the same tick. 605 | * Your creeps can withdraw resources from hostile structures/tombstones as well, in case if there is no hostile rampart on top of it. 606 | * 607 | * @see {@link https://docs.screeps.com/api/#Creep.withdraw} 608 | * 609 | * @type {function} 610 | * 611 | * @param {Structure|Tombstone|Ruin} target The target object. 612 | * @param {string} resourceType One of the RESOURCE_* constants. 613 | * @param {number|undefined|null} [amount] The amount of resources to be transferred. If omitted, all the available amount is used. 614 | * 615 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS} 616 | */ 617 | withdraw: function(target, resourceType, amount) { } 618 | }; 619 | -------------------------------------------------------------------------------- /Deposit.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A rare resource deposit needed for producing commodities. Can be harvested by creeps with a WORK body part. Each 3 | * harvest operation triggers a cooldown period, which becomes longer and longer over time. 4 | * 5 | * @class 6 | * @extends {RoomObject} 7 | * 8 | * @see {@link https://docs.screeps.com/api/#Deposit} 9 | */ 10 | Deposit = function () { 11 | }; 12 | 13 | Deposit.prototype = { 14 | 15 | /** 16 | * The amount of game ticks until the next harvest action is possible. 17 | * 18 | * @see {@link https://docs.screeps.com/api/#Deposit.cooldown} 19 | * 20 | * @type {number} 21 | */ 22 | cooldown: 0, 23 | 24 | /** 25 | * The deposit type 26 | * @see {@link https://docs.screeps.com/api/#Deposit.depositType} 27 | * 28 | * @type {string|RESOURCE_MIST|RESOURCE_BIOMASS|RESOURCE_METAL|RESOURCE_SILICON} 29 | */ 30 | depositType: "", 31 | 32 | /** 33 | * A unique object identificator. You can use Game.getObjectById method to retrieve an object instance by its id. 34 | * @see {@link https://docs.screeps.com/api/#Deposit.id} 35 | * 36 | * @type {string} 37 | */ 38 | id: "", 39 | 40 | /** 41 | * The cooldown of the last harvest operation on this deposit. 42 | * 43 | * @see {@link https://docs.screeps.com/api/#Deposit.lastCooldown} 44 | * 45 | * @type {number} 46 | */ 47 | lastCooldown: 0, 48 | 49 | /** 50 | * The amount of game ticks when this deposit will disappear. 51 | * 52 | * @see {@link https://docs.screeps.com/api/#Deposit.ticksToDecay} 53 | * 54 | * @type {number} 55 | */ 56 | ticksToDecay: 0 57 | 58 | }; 59 | -------------------------------------------------------------------------------- /Flag.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A flag. 3 | * Flags can be used to mark particular spots in a room. 4 | * Flags are visible to their owners only. 5 | * 6 | * @see {@link https://docs.screeps.com/api/#Flag} 7 | * 8 | * @class 9 | * @extends {RoomObject} 10 | */ 11 | Flag = function() { }; 12 | 13 | Flag.prototype = 14 | { 15 | /** 16 | * Flag primary color. One of the COLOR_* constants. 17 | * 18 | * @see {@link https://docs.screeps.com/api/#Flag.color} 19 | * 20 | * @type {number} 21 | */ 22 | color: 0, 23 | 24 | /** 25 | * A shorthand to Memory.flags[flag.name]. 26 | * You can use it for quick access the flag's specific memory data object. 27 | * 28 | * @see {@link https://docs.screeps.com/api/#Flag.memory} 29 | * 30 | * @type {*} 31 | */ 32 | memory: {}, 33 | 34 | /** 35 | * Flag’s name. 36 | * You can choose the name while creating a new flag, and it cannot be changed later. 37 | * This name is a hash key to access the flag via the Game.flags object. 38 | * 39 | * @see {@link https://docs.screeps.com/api/#Flag.name} 40 | * 41 | * @type {string} 42 | */ 43 | name: "", 44 | 45 | /** 46 | * Flag secondary color. One of the COLOR_* constants. 47 | * 48 | * @see {@link https://docs.screeps.com/api/#Flag.secondaryColor} 49 | * 50 | * @type {number} 51 | */ 52 | secondaryColor: 0, 53 | 54 | /** 55 | * Remove the flag. 56 | * 57 | * @see {@link https://docs.screeps.com/api/#Flag.remove} 58 | * 59 | * @type {function} 60 | * 61 | * @return {number|OK} 62 | */ 63 | remove: function() { }, 64 | 65 | /** 66 | * Set new color of the flag. 67 | * 68 | * @see {@link https://docs.screeps.com/api/#Flag.setColor} 69 | * 70 | * @type {function} 71 | * 72 | * @param {string} color Primary color of the flag. One of the COLOR_* constants. 73 | * @param {string|undefined|null} [secondaryColor] Secondary color of the flag. One of the COLOR_* constants. 74 | * 75 | * @return {number|OK|ERR_INVALID_ARGS} 76 | */ 77 | setColor: function(color, secondaryColor) { }, 78 | 79 | /** 80 | * Set new position of the flag. 81 | * 82 | * @see {@link https://docs.screeps.com/api/#Flag.setPosition} 83 | * 84 | * @type {function} 85 | * 86 | * @param {number|RoomPosition|RoomObject} x The X position in the room. 87 | * @param {number} [y] The Y position in the room. 88 | * 89 | * @note Alternative function: setPosition(pos) 90 | * @param {object} pos Can be a RoomPosition object or any object containing RoomPosition. 91 | * 92 | * @return {number|OK|ERR_INVALID_TARGET} 93 | */ 94 | setPosition: function(x, y) { } 95 | }; 96 | -------------------------------------------------------------------------------- /Game.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The main global game object containing all the game play information. 3 | * 4 | * @see {@link https://docs.screeps.com/api/#Game} 5 | * 6 | * @class 7 | */ 8 | Game = { 9 | /** 10 | * A hash containing all your construction sites with their id as hash keys. 11 | * 12 | * @see {@link https://docs.screeps.com/api/#Game.constructionSites} 13 | * 14 | * @type {Object} 15 | */ 16 | constructionSites: {}, 17 | 18 | /** 19 | * An object containing information about your CPU usage 20 | * 21 | * @see {@link https://docs.screeps.com/api/#Game.cpu} 22 | */ 23 | cpu: { 24 | /** 25 | * Your assigned CPU limit for the current shard. 26 | * 27 | * @type {number} 28 | */ 29 | limit: 0, 30 | 31 | /** 32 | * An amount of available CPU time at the current game tick. 33 | * Usually it is higher than Game.cpu.limit. 34 | * 35 | * @type {number} 36 | */ 37 | tickLimit: 0, 38 | 39 | /** 40 | * An amount of unused CPU accumulated in your bucket. 41 | * 42 | * @type {number} 43 | */ 44 | bucket: 0, 45 | 46 | /** 47 | * An object with limits for each shard with shard names as keys. You can use setShardLimits method to re-assign them. 48 | * 49 | * @type {Object} 50 | */ 51 | shardLimits: {}, 52 | 53 | /** 54 | * Whether full CPU is currently unlocked for your account. 55 | * 56 | * @type {boolean} 57 | */ 58 | unlocked: false, 59 | 60 | /** 61 | * The time in milliseconds since UNIX epoch time until full CPU is unlocked for your account. 62 | * This property is not defined when full CPU is not unlocked for your account or it's unlocked with a subscription. 63 | * 64 | * @type {number} 65 | */ 66 | unlockedTime: 0, 67 | 68 | /** 69 | * This method is only available when Virtual machine is set to Isolated in your account runtime settings. 70 | * Use this method to get heap statistics for your virtual machine. The return value is almost identical to the Node.js function v8.getHeapStatistics(). 71 | * This function returns one additional property: externally_allocated_size which is the total amount of currently allocated memory which is not included in the v8 heap but counts against this isolate's memory limit. 72 | * ArrayBuffer instances over a certain size are externally allocated and will be counted here. 73 | * 74 | * @see {@link https://docs.screeps.com/api/#Game.cpu.getHeapStatistics} 75 | * 76 | * @type {function} 77 | * 78 | * @return {object} Returns an objects with heap statistics in the following format: 79 | * { 80 | "total_heap_size": 29085696, 81 | "total_heap_size_executable": 3670016, 82 | "total_physical_size": 26447928, 83 | "total_available_size": 319649520, 84 | "used_heap_size": 17493824, 85 | "heap_size_limit": 343932928, 86 | "malloced_memory": 8192, 87 | "peak_malloced_memory": 1060096, 88 | "does_zap_garbage": 0, 89 | "externally_allocated_size": 38430000 90 | } 91 | */ 92 | getHeapStatistics: function() {}, 93 | 94 | /** 95 | * Get amount of CPU time used from the beginning of the current game tick. Always returns 0 in the Simulation mode. 96 | * 97 | * @see {@link https://docs.screeps.com/api/#Game.cpu.getUsed} 98 | * 99 | * @type {function} 100 | * 101 | * @return {number} Returns currently used CPU time as a float number. 102 | */ 103 | getUsed: function () {}, 104 | 105 | /** 106 | * This method is only available when Virtual machine is set to Isolated in your account runtime settings. 107 | * Reset your runtime environment and wipe all data in heap memory. 108 | * 109 | * @see {@link https://docs.screeps.com/api/#Game.cpu.getHeapStatistics} 110 | * 111 | * @type {function} 112 | * 113 | * @return {void} 114 | */ 115 | halt: function() {}, 116 | 117 | /** 118 | * Allocate CPU limits to different shards. Total amount of CPU should remain equal to Game.cpu.shardLimits. This method can be used only once per 12 hours. 119 | * 120 | * @see {@link https://docs.screeps.com/api/#Game.cpu.setShardLimits} 121 | * 122 | * @type {function} 123 | * 124 | * @param {object} limits An object with CPU values for each shard in the same format as Game.cpu.shardLimits. 125 | * 126 | * @return {number|OK|ERR_BUSY|ERR_INVALID_ARGS} 127 | */ 128 | setShardLimits: function(limits) {}, 129 | 130 | /** 131 | * Unlock full CPU for your account for additional 24 hours. 132 | * This method will consume 1 CPU unlock bound to your account (See Game.resources). 133 | * 134 | * @see {@link https://docs.screeps.com/api/#Game.cpu.unlock} 135 | * 136 | * @type {function} 137 | * 138 | * @return {number|OK|ERR_NOT_ENOUGH_RESOURCES|ERR_FULL} 139 | */ 140 | unlock: function() {}, 141 | 142 | /** 143 | * Generate 1 pixel resource unit for 10000 CPU from your bucket. 144 | * 145 | * @see {@link https://docs.screeps.com/api/#Game.cpu.generatePixel} 146 | * 147 | * @type {function} 148 | * 149 | * @return {number|OK|ERR_NOT_ENOUGH_RESOURCES} 150 | */ 151 | generatePixel: function() {} 152 | }, 153 | 154 | /** 155 | * A hash containing all your creeps with creep names as hash keys. 156 | * 157 | * @see {@link https://docs.screeps.com/api/#Game.creeps} 158 | * @type {Object} 159 | * @example 160 | * for(var i in Game.creeps) { 161 | * Game.creeps[i].moveTo(flag); 162 | * } 163 | */ 164 | creeps: {}, 165 | 166 | /** 167 | * A hash containing all your power creeps with their names as hash keys. Even power creeps not spawned in the world can be accessed here. 168 | * 169 | * @see {@link https://docs.screeps.com/api/#Game.powerCreeps} 170 | * @type {Object} 171 | * @example 172 | * for(var i in Game.powerCreeps) { 173 | * Game.powerCreeps[i].moveTo(flag); 174 | * } 175 | */ 176 | powerCreeps: {}, 177 | 178 | /** 179 | * A hash containing all your flags with flag names as hash keys. 180 | * 181 | * @see {@link https://docs.screeps.com/api/#Game.flags} 182 | * @type {Object} 183 | * @example 184 | * creep.moveTo(Game.flags.Flag1); 185 | */ 186 | flags: {}, 187 | 188 | /** 189 | * Your Global Control Level 190 | * 191 | * @see {@link https://docs.screeps.com/control.html} 192 | * @see {@link https://docs.screeps.com/api/#Game.gcl} 193 | */ 194 | gcl: { 195 | /** 196 | * The current level. 197 | * 198 | * @type {number} 199 | */ 200 | level: 0, 201 | 202 | /** 203 | * The current progress to the next level. 204 | * 205 | * @type {number} 206 | */ 207 | progress: 0, 208 | 209 | /** 210 | * The progress required to reach the next level. 211 | * 212 | * @type {number} 213 | */ 214 | progressTotal: 0 215 | }, 216 | 217 | /** 218 | * Your Global Power Level, an object with the following properties : 219 | * 220 | * @see {@link https://docs.screeps.com/power.html} 221 | * @see {@link https://docs.screeps.com/api/#Game.gpl} 222 | */ 223 | gpl: { 224 | /** 225 | * The current level. 226 | * 227 | * @type {number} 228 | */ 229 | level: 0, 230 | 231 | /** 232 | * The current progress to the next level. 233 | * 234 | * @type {number} 235 | */ 236 | progress: 0, 237 | 238 | /** 239 | * The progress required to reach the next level. 240 | * 241 | * @type {number} 242 | */ 243 | progressTotal: 0 244 | }, 245 | 246 | /** 247 | * A global object representing world map. 248 | * 249 | * @see {@link https://docs.screeps.com/api/#Game.map} 250 | */ 251 | map: { 252 | /** 253 | * Gets availablity status of the room with the specified name. 254 | * 255 | * @see {@link https://docs.screeps.com/api/#Game.map.getRoomStatus} 256 | * 257 | * @type {function} 258 | * 259 | * @param {string} roomName The room name. 260 | * @return {{status: 'normal' | 'closed' | 'novice' | 'respawn', timestamp: number | null}} 261 | */ 262 | getRoomStatus: function (roomName) {}, 263 | 264 | /** 265 | * List all exits available from the room with the given name. 266 | * 267 | * @param {string} roomName The room name. 268 | * 269 | * @return {null|object} The exits information in the following format, or null if the room not found. 270 | { 271 | "1": "W8N4", // TOP 272 | "3": "W7N3", // RIGHT 273 | "5": "W8N2", // BOTTOM 274 | "7": "W9N3" // LEFT 275 | } 276 | * 277 | * @type {function} 278 | * @see {@link https://docs.screeps.com/api/#Game.map.describeExits} 279 | * @example 280 | * var exits = Game.map.describeExits('W8N3'); 281 | */ 282 | describeExits: function (roomName) {}, 283 | 284 | /** 285 | * Find the exit direction from the given room en route to another room. 286 | * 287 | * @param {string|Room} fromRoom Start room name or room object. 288 | * @param {string|Room} toRoom Finish room name or room object. 289 | * @param {object} [opts] An object with the pathfinding options. See findRoute. 290 | * 291 | * @return {number|FIND_EXIT_TOP|FIND_EXIT_RIGHT|FIND_EXIT_BOTTOM|FIND_EXIT_LEFT|ERR_NO_PATH|ERR_INVALID_ARGS} 292 | * @type {function} 293 | * 294 | * @see {@link https://docs.screeps.com/api/#Game.map.findExit} 295 | */ 296 | findExit: function (fromRoom, toRoom, opts) {}, 297 | 298 | /** 299 | * Find route from the given room to another room. 300 | * 301 | * @see {@link https://docs.screeps.com/api/#Game.map.findRoute} 302 | * 303 | * @type {function} 304 | * 305 | * @param {string|Room} fromRoom Start room name or room object. 306 | * @param {string|Room} toRoom Finish room name or room object. 307 | * @param {object} [opts] An object with the pathfinding options. 308 | * @param {function} [opts.routeCallback] This callback accepts two arguments: function(roomName, fromRoomName). It can be used to calculate the cost of entering that room. You can use this to do things like prioritize your own rooms, or avoid some rooms. You can return a floating point cost or Infinity to block the room. 309 | * 310 | * @return {Array|number|ERR_NO_PATH} The route array in the following format: 311 | [ 312 | { exit: FIND_EXIT_RIGHT, room: 'arena21' }, 313 | { exit: FIND_EXIT_BOTTOM, room: 'arena22' } 314 | ] 315 | */ 316 | findRoute: function (fromRoom, toRoom, opts) {}, 317 | 318 | /** 319 | * Get the linear distance (in rooms) between two rooms. 320 | * You can use this function to estimate the energy cost of sending resources through terminals, or using observers and nukes. 321 | * 322 | * @see {@link https://docs.screeps.com/api/#Game.map.getRoomLinearDistance} 323 | * 324 | * @type {function} 325 | * 326 | * @param {string} roomName1 The name of the first room. 327 | * @param {string} roomName2 The name of the second room. 328 | * @param {boolean} [continuous] Whether to treat the world map continuous on borders. Set to true if you want to calculate the trade or terminal send cost. Default is false. 329 | * 330 | * @return {number} A number of rooms between the given two rooms. 331 | */ 332 | getRoomLinearDistance: function (roomName1, roomName2, continuous) {}, 333 | 334 | /** 335 | * Get a Room.Terrain object which provides fast access to static terrain data. This method works for any room in the world even if you have no access to it. 336 | * 337 | * @see {@link https://docs.screeps.com/api/#Game.map.getRoomTerrain} 338 | * 339 | * @type {function} 340 | * 341 | * @param {string} roomName The room name. 342 | * 343 | * @return {Room.Terrain} Returns new Room.Terrain object. 344 | */ 345 | getRoomTerrain: function(roomName) {}, 346 | 347 | /** 348 | * Get terrain type at the specified room position. 349 | * This method works for any room in the world even if you have no access to it. 350 | * 351 | * @deprecated use Game.map.getRoomTerrain instead. 352 | * 353 | * @see {@link https://docs.screeps.com/api/#Game.map.getTerrainAt} 354 | * 355 | * @type {function} 356 | * 357 | * @param {number|RoomPosition} x X position in the room. 358 | * @param {number} [y] Y position in the room. 359 | * @param {string} [roomName] The room name. 360 | * 361 | * @note Alternative function: getTerrainAt(pos) 362 | * @param {RoomPosition} pos The position object. 363 | * 364 | * @return {"plain"|"swamp"|"wall"} 365 | */ 366 | getTerrainAt: function (x, y, roomName) {}, 367 | 368 | /** 369 | * Returns the world size as a number of rooms between world corners. 370 | * 371 | * @see {@link https://docs.screeps.com/api/#Game.map.getWorldSize} 372 | * 373 | * @type {function} 374 | * 375 | * @return {number} 376 | */ 377 | getWorldSize: function () {}, 378 | 379 | /** 380 | * Check if the room is available to move into. 381 | * 382 | * @see {@link https://docs.screeps.com/api/#Game.map.isRoomAvailable} 383 | * 384 | * @type {function} 385 | * 386 | * @param {string} roomName The room name. 387 | * 388 | * @return {boolean} 389 | */ 390 | isRoomAvailable: function (roomName) {}, 391 | 392 | /** 393 | * Map visuals provide a way to show various visual debug info on the game map. 394 | * @type {MapVisual} 395 | */ 396 | visual: {} 397 | }, 398 | 399 | /** 400 | * A global object representing the in-game market. 401 | * 402 | * @see {@link https://docs.screeps.com/api/#Game.market} 403 | * @see {@link https://docs.screeps.com/market.html} 404 | */ 405 | market: { 406 | /** 407 | * Your current credits balance. 408 | * 409 | * @see {@link https://docs.screeps.com/api/#Game.market.credits} 410 | * 411 | * @type {number} 412 | */ 413 | credits: 0, 414 | 415 | /** 416 | * An array of the last 100 incoming transactions to your terminals with the following format: 417 | [{ 418 | transactionId : "56dec546a180ce641dd65960", 419 | time : 10390687, 420 | sender : {username: "Sender"}, 421 | recipient : {username: "Me"}, 422 | resourceType : "U", 423 | amount : 100, 424 | from : "W0N0", 425 | to : "W10N10", 426 | description : "trade contract #1", 427 | order: { // optional 428 | id : "55c34a6b5be41a0a6e80c68b", 429 | type : "sell", 430 | price : 2.95 431 | } 432 | }] 433 | * @see {@link https://docs.screeps.com/api/#Game.market.incomingTransactions} 434 | * 435 | * @type {Array} 436 | */ 437 | incomingTransactions: [], 438 | 439 | /** 440 | * An array of the last 100 outgoing transactions from your terminals with the following format: 441 | [{ 442 | transactionId : "56dec546a180ce641dd65960", 443 | time : 10390687, 444 | sender : {username: "Me"}, 445 | recipient : {username: "Recipient"}, 446 | resourceType : "U", 447 | amount : 100, 448 | from : "W0N0", 449 | to : "W10N10", 450 | description : "trade contract #1", 451 | order: { // optional 452 | id : "55c34a6b5be41a0a6e80c68b", 453 | type : "sell", 454 | price : 2.95 455 | } 456 | }] 457 | * @see {@link https://docs.screeps.com/api/#Game.market.outgoingTransactions} 458 | * 459 | * @type {Array} 460 | */ 461 | outgoingTransactions: [], 462 | 463 | /** 464 | *An object with your active and inactive buy/sell orders on the market. 465 | * { 466 | "55c34a6b5be41a0a6e80c68b": { 467 | id : "55c34a6b5be41a0a6e80c68b", 468 | created : 13131117, 469 | active: true, 470 | type : "sell" 471 | resourceType : "OH", 472 | roomName : "W1N1", 473 | amount : 15821, 474 | remainingAmount : 30000, 475 | totalAmount : 50000, 476 | price : 2.95 477 | }, 478 | "55c34a6b52411a0a6e80693a": { 479 | id : "55c34a6b52411a0a6e80693a", 480 | created : 13134122, 481 | active: true, 482 | type : "buy" 483 | resourceType : "energy", 484 | roomName : "W1N1", 485 | amount : 94000, 486 | remainingAmount : 94000, 487 | totalAmount : 94000 488 | price : 0.45 489 | }, 490 | "55c34a6b5be41a0a6e80c123": { 491 | id : "55c34a6b5be41a0a6e80c123", 492 | created : 13105123, 493 | active: false, 494 | type : "sell" 495 | resourceType : "token", 496 | amount : 0, 497 | remainingAmount : 10, 498 | totalAmount : 10, 499 | price : 50000 500 | } 501 | } 502 | * @see {@link https://docs.screeps.com/api/#Game.market.orders} 503 | * 504 | * @type {Object} 505 | */ 506 | orders: {}, 507 | 508 | /** 509 | * Estimate the energy transaction cost of StructureTerminal.send and Game.market.deal methods. 510 | * The formula: Math.ceil( amount * ( 1 - Math.exp(-distanceBetweenRooms/30) ) ) 511 | * 512 | * @see {@link https://docs.screeps.com/api/#Game.market.calcTransactionCost} 513 | * 514 | * @type {function} 515 | * 516 | * @param {number} amount Amount of resources to be sent. 517 | * @param {string} roomName1 The name of the first room. 518 | * @param {string} roomName2 The name of the second room. 519 | * 520 | * @return {number} The amount of energy required to perform the transaction. 521 | */ 522 | calcTransactionCost: function (amount, roomName1, roomName2) { }, 523 | 524 | /** 525 | * Cancel a previously created order. 526 | * The 5% fee is not returned. 527 | * 528 | * @see {@link https://docs.screeps.com/api/#Game.market.cancelOrder} 529 | * 530 | * @type {function} 531 | * 532 | * @param {string} orderId The order ID as provided in Game.market.orders. 533 | * 534 | * @return {number|OK|ERR_INVALID_ARGS} 535 | */ 536 | cancelOrder: function (orderId) { }, 537 | 538 | /** 539 | * Change the price of an existing order. 540 | * If newPrice is greater than old price, you will be charged (newPrice-oldPrice)*remainingAmount*0.05 credits. 541 | * 542 | * @see {@link https://docs.screeps.com/api/#Game.market.changeOrderPrice} 543 | * 544 | * @type {function} 545 | * 546 | * @param {string} orderId The order ID as provided in Game.market.orders. 547 | * @param {number} newPrice The new order price. 548 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_ARGS} 549 | */ 550 | changeOrderPrice: function (orderId, newPrice) { }, 551 | 552 | /** 553 | * Create a market order in your terminal. 554 | * You will be charged price*amount*0.05 credits when the order is placed. 555 | * The maximum orders count is 300 per player. 556 | * You can create an order at any time with any amount, it will be automatically activated and deactivated depending on the resource/credits availability. 557 | * 558 | * @see {@link https://docs.screeps.com/api/#Game.market.createOrder} 559 | * 560 | * @type {function} 561 | * 562 | * @param {object} params 563 | * @param {string|ORDER_SELL|ORDER_BUY} params.type The order type, either ORDER_SELL or ORDER_BUY. 564 | * @param {string} params.resourceType Either one of the RESOURCE_* constants or SUBSCRIPTION_TOKEN. 565 | * @param {number} params.price The price for one resource unit in credits. Can be a decimal number. 566 | * @param {number} params.totalAmount The amount of resources to be traded in total. 567 | * @param {string} [params.roomName] The room where your order will be created. You must have your own Terminal structure in this room, otherwise the created order will be temporary inactive. This argument is not used when resourceType equals to GAMETIME_TOKEN. 568 | * 569 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_RESOURCES|ERR_FULL|ERR_INVALID_ARGS} 570 | */ 571 | createOrder: function (params) { }, 572 | 573 | /** 574 | * Execute a trade deal from your Terminal in yourRoomName to another player's Terminal using the specified buy/sell order. 575 | * Your Terminal will be charged energy units of transfer cost regardless of the order resource type. 576 | * You can use Game.market.calcTransactionCost method to estimate it. 577 | * When multiple players try to execute the same deal, the one with the shortest distance takes precedence. 578 | * You cannot execute more than 10 deals during one tick. 579 | * 580 | * @see {@link https://docs.screeps.com/api/#Game.market.deal} 581 | * 582 | * @type {function} 583 | * 584 | * @param {string} orderId The order ID as provided in Game.market.getAllOrders. 585 | * @param {number} amount The amount of resources to transfer. 586 | * @param {string} [yourRoomName] The name of your room which has to contain an active Terminal with enough amount of energy. This argument is not used when the order resource type is one of account-bound resources (See INTERSHARD_RESOURCES constant). 587 | * 588 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_RESOURCES|ERR_FULL|ERR_INVALID_ARGS|ERR_TIRED} 589 | */ 590 | deal: function (orderId, amount, yourRoomName) { }, 591 | 592 | /** 593 | * Add more capacity to an existing order. It will affect remainingAmount and totalAmount properties. You will 594 | * be charged price*addAmount*0.05 credits. 595 | * 596 | * @see {@link https://docs.screeps.com/api/#Game.market.extendOrder} 597 | * 598 | * @type {function} 599 | * 600 | * @param {string} orderId The order ID as provided in Game.market.orders. 601 | * @param {number} addAmount How much capacity to add. Cannot be a negative value. 602 | * 603 | * @return {number|OK|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_ARGS} 604 | */ 605 | extendOrder: function (orderId, addAmount) { }, 606 | 607 | /** 608 | * Get other players' orders currently active on the market. 609 | * 610 | * @see {@link https://docs.screeps.com/api/#Game.market.getAllOrders} 611 | * 612 | * @type {function} 613 | * 614 | * @param {object|function} [filter] An object or function that will filter the resulting list using the lodash.filter method. 615 | * 616 | * @return {Array} An array of Orders 617 | */ 618 | getAllOrders: function (filter) { }, 619 | 620 | /** 621 | * Get daily price history of the specified resource on the market for the last 14 days. 622 | * 623 | * @see {@link https://docs.screeps.com/api/#Game.market.getHistory} 624 | * 625 | * @type {function} 626 | * 627 | * @param {string} [resourceType] One of the RESOURCE_* constants. If undefined, returns history data for all resources. 628 | * 629 | * @return {Array<{resourceType:string, date:string, transactions:number, volume:number, avgPrice:number, stddevPrice:number}>} Returns an array of objects 630 | */ 631 | getHistory: function (resourceType) { }, 632 | 633 | /** 634 | * Retrieve info for specific market order. 635 | * 636 | * @see {@link https://docs.screeps.com/api/#Game.market.getOrderById} 637 | * 638 | * @type {function} 639 | * 640 | * @param {string} id The order ID. 641 | * 642 | * @return {Order} An object with the order info. 643 | */ 644 | getOrderById: function (id) { } 645 | }, 646 | 647 | /** 648 | * An object with your global resources that are bound to the account, like pixels or cpu unlocks. 649 | * Each object key is a resource constant, values are resources amounts. 650 | * 651 | * @see {@link https://docs.screeps.com/api/#Game.resources} 652 | * 653 | * @type {Object} 654 | */ 655 | resources: {}, 656 | 657 | /** 658 | * A hash containing all the rooms available to you with room names as hash keys. 659 | * A room is visible if you have a creep or an owned structure in it. 660 | * 661 | * @see {@link https://docs.screeps.com/api/#Game.rooms} 662 | * 663 | * @type {Object} 664 | */ 665 | rooms: {}, 666 | 667 | /** 668 | * An object describing the world shard where your script is currently being executed in. 669 | * 670 | * @see {@link https://docs.screeps.com/api/#Game.shard} 671 | * 672 | * @type {object} name - The name of the shard; type - Currently always equals to normal; ptr - Wether this shard belongs to the PTR. 673 | */ 674 | shard: {}, 675 | 676 | /** 677 | * A hash containing all your spawns with spawn names as hash keys. 678 | * 679 | * @see {@link https://docs.screeps.com/api/#Game.spawns} 680 | * 681 | * @type {Object} 682 | */ 683 | spawns: {}, 684 | 685 | /** 686 | * A hash containing all your structures with structure id as hash keys. 687 | * 688 | * @see {@link https://docs.screeps.com/api/#Game.structures} 689 | * 690 | * @type {Object} 691 | */ 692 | structures: {}, 693 | 694 | /** 695 | * System game tick counter. It is automatically incremented on every tick. 696 | * 697 | * @see {@link https://docs.screeps.com/api/#Game.time} 698 | * 699 | * @type {number} 700 | */ 701 | time: 0, 702 | 703 | /** 704 | * Get an object with the specified unique ID. 705 | * It may be a game object of any type. 706 | * Only objects from the rooms which are visible to you can be accessed. 707 | * 708 | * @see {@link https://docs.screeps.com/api/#Game.getObjectById} 709 | * 710 | * @type {function} 711 | * 712 | * @param {string} id The unique identificator. 713 | * 714 | * @return {object|null} Returns an object instance or null if it cannot be found. 715 | */ 716 | getObjectById: function (id) { }, 717 | 718 | /** 719 | * Send a custom message at your profile email. 720 | * This way, you can set up notifications to yourself on any occasion within the game. 721 | * You can schedule up to 20 notifications during one game tick. 722 | * Not available in the Simulation Room. 723 | * 724 | * @see {@link https://docs.screeps.com/api/#Game.notify} 725 | * 726 | * @type {function} 727 | * 728 | * @param {string} message Custom text which will be sent in the message. Maximum length is 1000 characters. 729 | * @param {number} [groupInterval] If set to 0 (default), the notification will be scheduled immediately. Otherwise, it will be grouped with other notifications and mailed out later using the specified time in minutes. 730 | * 731 | * @return {void} 732 | */ 733 | notify: function (message, groupInterval) { } 734 | }; 735 | 736 | /** 737 | * Map visuals provide a way to show various visual debug info on the game map. 738 | * 739 | * @class 740 | * @constructor 741 | * 742 | * @see {@link https://docs.screeps.com/api/#Game-map-visual} 743 | */ 744 | MapVisual = function() { }; 745 | MapVisual.prototype = { 746 | /** 747 | * Draw a line. 748 | * 749 | * @see {@link https://docs.screeps.com/api/#Game.map-visual.line} 750 | * 751 | * @type {function} 752 | * 753 | * @param {RoomPosition} pos1 The start position object. 754 | * @param {RoomPosition} pos2 The finish position object. 755 | * @param {Object} [style] Style object 756 | * 757 | * @return {MapVisual} The MapVisual object itself, so that you can chain calls. 758 | */ 759 | line: function(pos1, pos2, style) { }, 760 | 761 | /** 762 | * Draw a circle. 763 | * 764 | * @see {@link https://docs.screeps.com/api/#Game.map-visual.circle} 765 | * 766 | * @type {function} 767 | * 768 | * @param {RoomPosition} pos The position object of the center. 769 | * @param {Object} [style] Style object 770 | * 771 | * @return {MapVisual} The MapVisual object itself, so that you can chain calls. 772 | */ 773 | circle: function(pos, style) { }, 774 | 775 | /** 776 | * Draw a rectangle. 777 | * 778 | * @see {@link https://docs.screeps.com/api/#Game.map-visual.rect} 779 | * 780 | * @type {function} 781 | * 782 | * @param {RoomPosition} topLeftPos The position object of the top-left corner. 783 | * @param {number} width The width of the rectangle. 784 | * @param {number} height The height of the rectangle. 785 | * @param {Object} [style] Style object 786 | * 787 | * @return {MapVisual} The MapVisual object itself, so that you can chain calls. 788 | */ 789 | rect: function(topLeftPos, width, height, [style]) { }, 790 | 791 | /** 792 | * Draw a polyline. 793 | * 794 | * @see {@link https://docs.screeps.com/api/#Game.map-visual.poly} 795 | * 796 | * @type {function} 797 | * 798 | * @param {array} points An array of points. Every item should be a RoomPosition object. 799 | * @param {Object} [style] Style object 800 | * 801 | * @return {MapVisual} The MapVisual object itself, so that you can chain calls. 802 | */ 803 | poly: function(points, style) { }, 804 | 805 | /** 806 | * Draw a text label. You can use any valid Unicode characters, including emoji. 807 | * 808 | * @see {@link https://docs.screeps.com/api/#Game.map-visual.text} 809 | * 810 | * @type {function} 811 | * 812 | * @param {string} text The text message. 813 | * @param {RoomPosition} pos The position object of the label baseline. 814 | * @param {Object} [style] Style object 815 | * 816 | * @return {MapVisual} The MapVisual object itself, so that you can chain calls. 817 | */ 818 | text: function(text, pos, style) { }, 819 | 820 | /** 821 | * Remove all visuals from the map. 822 | * 823 | * @see {@link https://docs.screeps.com/api/#Game.map-visual.clear} 824 | * 825 | * @type {function} 826 | * 827 | * @return {MapVisual} The MapVisual object itself, so that you can chain calls. 828 | */ 829 | clear: function() { }, 830 | 831 | /** 832 | * Get the stored size of all visuals added on the map in the current tick. It must not exceed 1024,000 (1000 KB). 833 | * 834 | * @see {@link https://docs.screeps.com/api/#Game.map-visual.getSize} 835 | * 836 | * @type {function} 837 | * 838 | * @return {number} The size of the visuals in bytes. 839 | */ 840 | getSize: function() { }, 841 | 842 | /** 843 | * Returns a compact representation of all visuals added on the map in the current tick. 844 | * 845 | * @see {@link https://docs.screeps.com/api/#Game.map-visual.export} 846 | * 847 | * @type {function} 848 | * 849 | * @return {string} A string with visuals data. There's not much you can do with the string besides store them for later. 850 | */ 851 | export: function() { }, 852 | 853 | /** 854 | * Add previously exported (with Game.map.visual.export) map visuals to the map visual data of the current tick. 855 | * 856 | * @see {@link https://docs.screeps.com/api/#Game.map-visual.import} 857 | * 858 | * @type {function} 859 | * 860 | * @param {string} val The string returned from Game.map.visual.export. 861 | * @return {MapVisual} The MapVisual object itself, so that you can chain calls. 862 | */ 863 | import: function(val) { } 864 | 865 | } 866 | -------------------------------------------------------------------------------- /InterShardMemory.js: -------------------------------------------------------------------------------- 1 | /** 2 | * InterShardMemory object provides an interface for communicating between shards. 3 | * 4 | * @class 5 | * 6 | * @see {@link https://docs.screeps.com/api/#InterShardMemory} 7 | */ 8 | InterShardMemory = function() { }; 9 | 10 | InterShardMemory.prototype = 11 | { 12 | 13 | /** 14 | * Returns the string contents of the current shard's data. 15 | * 16 | * @see {@link https://docs.screeps.com/api/#InterShardMemory.getLocal} 17 | * 18 | * @type {function} 19 | * 20 | * @return {string} 21 | */ 22 | getLocal: function() { }, 23 | 24 | /** 25 | * Replace the current shard's data with the new value. 26 | * 27 | * @see {@link https://docs.screeps.com/api/#InterShardMemory.setLocal} 28 | * 29 | * @type {function} 30 | * 31 | * @param {string} value New data value in string format. 32 | * @return {void} 33 | */ 34 | setLocal: function(value) { }, 35 | 36 | /** 37 | * Returns the string contents of another shard's data. 38 | * 39 | * @see {@link https://docs.screeps.com/api/#InterShardMemory.getRemote} 40 | * 41 | * @type {function} 42 | * 43 | * @param {string} shard Shard name. 44 | * @return {string} 45 | */ 46 | getRemote: function(shard) { } 47 | }; 48 | -------------------------------------------------------------------------------- /Memory.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Memory - Used to store arbitrary memory entries in arbitrary keys. 3 | * @type {Object} 4 | */ 5 | Memory = {}; 6 | -------------------------------------------------------------------------------- /Mineral.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A mineral deposit. 3 | * Can be harvested by creeps with a WORK body part using the extractor structure. 4 | * 5 | * @class 6 | * @extends {RoomObject} 7 | * 8 | * @see {@link https://docs.screeps.com/api/#Mineral} 9 | */ 10 | Mineral = function() { }; 11 | 12 | Mineral.prototype = 13 | { 14 | /** 15 | * The density that this mineral deposit will be refilled to once ticksToRegeneration reaches 0. 16 | * This is one of the DENSITY_* constants. 17 | * 18 | * @see {@link https://docs.screeps.com/api/#Mineral.density} 19 | * 20 | * @type {number} 21 | */ 22 | density: 0, 23 | 24 | /** 25 | * The remaining amount of resources. 26 | * 27 | * @see {@link https://docs.screeps.com/api/#Mineral.mineralAmount} 28 | * 29 | * @type {number} 30 | */ 31 | mineralAmount: 0, 32 | 33 | /** 34 | * The resource type, one of the RESOURCE_* constants. 35 | * 36 | * @see {@link https://docs.screeps.com/api/#Mineral.mineralType} 37 | * 38 | * @type {string} 39 | */ 40 | mineralType: "", 41 | 42 | /** 43 | * A unique object identificator. 44 | * You can use Game.getObjectById method to retrieve an object instance by its id. 45 | * 46 | * @see {@link https://docs.screeps.com/api/#Mineral.id} 47 | * 48 | * @type {string} 49 | */ 50 | id: "", 51 | 52 | /** 53 | * The remaining time after which the deposit will be refilled. 54 | * 55 | * @see {@link https://docs.screeps.com/api/#Mineral.ticksToRegeneration} 56 | * 57 | * @type {number} 58 | */ 59 | ticksToRegeneration: 0 60 | }; 61 | -------------------------------------------------------------------------------- /Nuke.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A nuke landing position. 3 | * This object cannot be removed or modified. 4 | * You can find incoming nukes in the room using the FIND_NUKES constant. 5 | * @class 6 | * @extends {RoomObject} 7 | * 8 | * @see {@link https://docs.screeps.com/api/#Nuke} 9 | */ 10 | Nuke = function() { }; 11 | 12 | Nuke.prototype = 13 | { 14 | /** 15 | * A unique object identificator. 16 | * You can use Game.getObjectById method to retrieve an object instance by its id. 17 | * 18 | * @see {@link https://docs.screeps.com/api/#Nuke.id} 19 | * 20 | * @type {string} 21 | */ 22 | id: "", 23 | 24 | /** 25 | * The name of the room where this nuke has been launched from. 26 | * 27 | * @see {@link https://docs.screeps.com/api/#Nuke.launchRoomName} 28 | * 29 | * @type {string} 30 | */ 31 | launchRoomName: "", 32 | 33 | /** 34 | * The remaining landing time. 35 | * 36 | * @see {@link https://docs.screeps.com/api/#Nuke.timeToLand} 37 | * 38 | * @type {number} 39 | */ 40 | timeToLand: 0 41 | }; 42 | -------------------------------------------------------------------------------- /Order.js: -------------------------------------------------------------------------------- 1 | Order = { 2 | /** 3 | * The unique order ID. 4 | * 5 | * @type {string} 6 | */ 7 | id: "", 8 | 9 | /** 10 | * The order creation time in game ticks. 11 | * 12 | * @type {number} 13 | */ 14 | created: 0, 15 | 16 | /** 17 | * The order creation time in milliseconds since UNIX epoch time. 18 | * 19 | * @type {number} 20 | */ 21 | createdTimestamp: 0, 22 | 23 | /** 24 | * Whether this order is active and visible to other players. An order can become non-active when the terminal doesn't have enough resources to sell or you are out of credits to buy.Whether this order is active and visible to other players. An order can become non-active when the terminal doesn't have enough resources to sell or you are out of credits to buy. 25 | * 26 | * @type {boolean|undefined} 27 | */ 28 | active: true, 29 | 30 | /** 31 | * Either ORDER_SELL or ORDER_BUY. 32 | * 33 | * @type {string|ORDER_SELL|ORDER_BUY} 34 | */ 35 | type: 'sell', 36 | 37 | /** 38 | * Either one of the RESOURCE_* constants or one of account-bound resources. 39 | * 40 | * @type {string} 41 | */ 42 | resourceType: "", 43 | 44 | /** 45 | * The room where this order is placed. 46 | * @type {string} 47 | */ 48 | roomName: "", 49 | 50 | /** 51 | * Currently available amount to trade. 52 | * @type {number} 53 | */ 54 | amount: 0, 55 | 56 | /** 57 | * How many resources are left to trade via this order. 58 | * @type {number} 59 | */ 60 | remainingAmount: 0, 61 | 62 | /** 63 | * Initial order amount. 64 | * @type {number|undefined} 65 | */ 66 | totalAmount: 0, 67 | 68 | /** 69 | * The current price per unit. 70 | * @type {number} 71 | */ 72 | price: 0 73 | }; 74 | -------------------------------------------------------------------------------- /OwnedStructure.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base prototype for a structure that has an owner. 3 | * Such structures can be found using FIND_MY_STRUCTURES and FIND_HOSTILE_STRUCTURES constants. 4 | * 5 | * @class 6 | * @extends {Structure} 7 | * 8 | * @see {@link https://docs.screeps.com/api/#OwnedStructure} 9 | */ 10 | OwnedStructure = function() { }; 11 | 12 | OwnedStructure.prototype = 13 | { 14 | /** 15 | * Whether this is your own structure. 16 | * 17 | * @see {@link https://docs.screeps.com/api/#OwnedStructure.my} 18 | * 19 | * @type {boolean} 20 | */ 21 | my: true, 22 | 23 | /** 24 | * An object with the structure’s owner info 25 | * 26 | * @see {@link https://docs.screeps.com/api/#OwnedStructure.owner} 27 | * 28 | * @type {{username: string}} 29 | */ 30 | owner: 31 | { 32 | username: "" 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /PathFinder.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @class 4 | * 5 | * @see {@link https://docs.screeps.com/api/#PathFinder} 6 | */ 7 | PathFinder = 8 | { 9 | /** 10 | * Find an optimal path between origin and goal. 11 | * @static 12 | * 13 | * @see {@link https://docs.screeps.com/api/#PathFinder.search} 14 | * 15 | * @type {function} 16 | * 17 | * @param {RoomPosition} origin The start position. 18 | * @param {object} goal A goal or an array of goals. If more than one goal is supplied then the cheapest path found out of all the goals will be returned. A goal is either a RoomPosition or an object as defined below. 19 | Important: Please note that if your goal is not walkable (for instance, a source) then you should set range to at least 1 or else you will waste many CPU cycles searching for a target that you can't walk on. 20 | 21 | pos - RoomPosition - The target. 22 | range - number - Range to pos before goal is considered reached. The default is 0. 23 | * @param {object} [opts] An object containing additional pathfinding flags. 24 | * @param {function} [opts.roomCallback] Request from the pathfinder to generate a CostMatrix for a certain room. The callback accepts one argument, roomName. This callback will only be called once per room per search. If you are running multiple pathfinding operations in a single room and in a single tick you may consider caching your CostMatrix to speed up your code. Please read the CostMatrix documentation below for more information on CostMatrix. If you return false from the callback the requested room will not be searched, and it won't count against maxRooms 25 | * @param {number} [opts.plainCost] Cost for walking on plain positions. The default is 1. 26 | * @param {number} [opts.swampCost] Cost for walking on swamp positions. The default is 5. 27 | * @param {boolean} [opts.flee] Instead of searching for a path to the goals this will search for a path away from the goals. The cheapest path that is out of range of every goal will be returned. The default is false. 28 | * @param {number} [opts.maxOps] The maximum allowed pathfinding operations. You can limit CPU time used for the search based on ratio 1 op ~ 0.001 CPU. The default value is 2000. 29 | * @param {number} [opts.maxRooms] The maximum allowed rooms to search. The default is 16, maximum is 64. 30 | * @param {number} [opts.maxCost] The maximum allowed cost of the path returned. If at any point the pathfinder detects that it is impossible to find a path with a cost less than or equal to maxCost it will immediately halt the search. The default is Infinity. 31 | * @param {number} [opts.heuristicWeight] Weight to apply to the heuristic in the A* formula F = G + weight * H. Use this option only if you understand the underlying A* algorithm mechanics! The default value is 1.2. 32 | * 33 | * @return {{path:Array,opts:number,cost:number,incomplete:boolean}} An object containing: path - An array of RoomPosition objects; ops - Total number of operations performed before this path was calculated; cost - The total cost of the path as derived from plainCost, swampCost and any given CostMatrix instances; incomplete - If the pathfinder fails to find a complete path, this will be true. Note that path will still be populated with a partial path which represents the closest path it could find given the search parameters. 34 | */ 35 | search: function(origin, goal, opts) { }, 36 | 37 | /** 38 | * Specify whether to use this new experimental pathfinder in game objects methods. 39 | * This method should be invoked every tick. 40 | * @static 41 | * @deprecated 42 | * @note It affects the following methods behavior: Room.findPath, RoomPosition.findPathTo, RoomPosition.findClosestByPath, Creep.moveTo. 43 | * 44 | * @see {@link https://docs.screeps.com/api/#PathFinder.use} 45 | * 46 | * @type {function} 47 | * 48 | * @param {boolean} isEnabled Whether to activate the new pathfinder or deactivate. 49 | */ 50 | use: function(isEnabled) { } 51 | }; 52 | 53 | /** 54 | * Creates a new CostMatrix containing 0's for all positions. 55 | * 56 | * @constructor 57 | * @class 58 | * 59 | * @see {@link https://docs.screeps.com/api/#PathFinder-CostMatrix} 60 | */ 61 | PathFinder.CostMatrix = function() { }; 62 | 63 | /** 64 | * Static method which deserializes a new CostMatrix using the return value of serialize. 65 | * @static 66 | * 67 | * @see {@link https://docs.screeps.com/api/#PathFinder.CostMatrix.deserialize} 68 | * 69 | * @type {function} 70 | * 71 | * @param {object} val Whatever serialize returned 72 | * 73 | * @return {CostMatrix} Returns new CostMatrix instance. 74 | */ 75 | PathFinder.CostMatrix.deserialize = function(val) { }; 76 | 77 | PathFinder.CostMatrix.prototype = 78 | { 79 | /** 80 | * Set the cost of a position in this CostMatrix. 81 | * 82 | * @see {@link https://docs.screeps.com/api/#PathFinder.CostMatrix.set} 83 | * 84 | * @type {function} 85 | * 86 | * @param {number} x X position in the room. 87 | * @param {number} y Y position in the room. 88 | * @param {number} cost Cost of this position. Must be a whole number. A cost of 0 will use the terrain cost for that tile. A cost greater than or equal to 255 will be treated as unwalkable. 89 | */ 90 | set: function(x, y, cost) { }, 91 | 92 | /** 93 | * Get the cost of a position in this CostMatrix. 94 | * 95 | * @see {@link https://docs.screeps.com/api/#PathFinder.CostMatrix.get} 96 | * 97 | * @type {function} 98 | * 99 | * @param {number} x X position in the room. 100 | * @param {number} y Y position in the room. 101 | * 102 | * @return {number} 103 | */ 104 | get: function(x, y) { }, 105 | 106 | /** 107 | * Copy this CostMatrix into a new CostMatrix with the same data. 108 | * 109 | * @see {@link https://docs.screeps.com/api/#PathFinder.CostMatrix.clone} 110 | * 111 | * @type {function} 112 | * 113 | * @return {CostMatrix} A new CostMatrix instance. 114 | */ 115 | clone: function() { }, 116 | 117 | /** 118 | * Returns a compact representation of this CostMatrix which can be stored via JSON.stringify 119 | * 120 | * @see {@link https://docs.screeps.com/api/#PathFinder.CostMatrix.serialize} 121 | * 122 | * @type {function} 123 | * 124 | * @return {Array} An array of numbers. There's not much you can do with the numbers besides store them for later. 125 | */ 126 | serialize: function() { } 127 | }; 128 | -------------------------------------------------------------------------------- /PowerCreep.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @class 4 | * @extends {RoomObject} 5 | * 6 | * @see {@link https://docs.screeps.com/api/#PowerCreep} 7 | */ 8 | PowerCreep = function() { }; 9 | 10 | PowerCreep.prototype = 11 | { 12 | 13 | /** 14 | * A static method to create new Power Creep instance in your account. 15 | * It will be added in an unspawned state, use spawn method to spawn it in the world. 16 | * You need one free Power Level in your account to perform this action. 17 | * 18 | * @see {@link https://docs.screeps.com/api/#PowerCreep.create} 19 | * 20 | * @type {function} 21 | * 22 | * @param {string} name The name of the new power creep. 23 | * 24 | * @param {string} className The class of the new power creep, one of the POWER_CLASS constants. 25 | * 26 | * @return {number|OK|ERR_NAME_EXISTS|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_ARGS} 27 | */ 28 | create: function(name, className) { }, 29 | 30 | /** 31 | * @deprecated Since version 4.x, replaced by `.store`. 32 | * 33 | * An object with the PowerCreep's cargo contents. 34 | * Each object key is one of the RESOURCE_* constants, values are resources amounts. 35 | * Use _.sum(creep.carry) to get the total amount of contents. 36 | * 37 | * @see {@link https://docs.screeps.com/api/#PowerCreep.carry} 38 | * 39 | * @type {object} 40 | */ 41 | carry: {}, 42 | 43 | /** 44 | * @deprecated Since version 4.x, replaced by `.store.getCapacity()`. 45 | * 46 | * The total amount of resources the PowerCreep can carry. 47 | * 48 | * @see {@link https://docs.screeps.com/api/#PowerCreep.carryCapacity} 49 | * 50 | * @type {number} 51 | */ 52 | carryCapacity: 0, 53 | 54 | /** 55 | * The power creep's class, one of the POWER_CLASS constants. 56 | * 57 | * @see {@link https://docs.screeps.com/api/#PowerCreep.className} 58 | * 59 | * @type {string} 60 | */ 61 | className: "", 62 | 63 | 64 | /** 65 | * A timestamp when this creep is marked to be permanently deleted from the account, or undefined otherwise. 66 | * 67 | * @see {@link https://docs.screeps.com/api/#PowerCreep.deleteTime} 68 | * 69 | * @type {number} 70 | */ 71 | deleteTime: 0, 72 | 73 | /** 74 | * The current amount of hit points of the creep. 75 | * 76 | * @see {@link https://docs.screeps.com/api/#PowerCreep.hits} 77 | * 78 | * @type {number} 79 | */ 80 | hits: 0, 81 | 82 | /** 83 | * The maximum amount of hit points of the creep. 84 | * 85 | * @see {@link https://docs.screeps.com/api/#PowerCreep.hitsMax} 86 | * 87 | * @type {number} 88 | */ 89 | hitsMax: 0, 90 | 91 | /** 92 | * A unique object identificator. 93 | * You can use Game.getObjectById method to retrieve an object instance by its id. 94 | * 95 | * @see {@link https://docs.screeps.com/api/#PowerCreep.id} 96 | * 97 | * @type {string} 98 | */ 99 | id: "", 100 | 101 | /** 102 | * The power creep's level. 103 | * 104 | * @see {@link https://docs.screeps.com/api/#PowerCreep.level} 105 | * 106 | * @type {number} 107 | */ 108 | level: 0, 109 | 110 | /** 111 | * A shorthand to Memory.powerCreeps[creep.name]. 112 | * You can use it for quick access the creep’s specific memory data object. 113 | * 114 | * @see {@link https://docs.screeps.com/api/#PowerCreep.memory} 115 | * 116 | * @type {*} 117 | */ 118 | memory: {}, 119 | 120 | /** 121 | * Whether it is your creep or foe. 122 | * 123 | * @see {@link https://docs.screeps.com/api/#PowerCreep.my} 124 | * 125 | * @type {boolean} 126 | */ 127 | my: true, 128 | 129 | /** 130 | * Power creep’s name. 131 | * You can choose the name while creating a new power creep, and it cannot be changed later. 132 | * This name is a hash key to access the creep via the Game.powerCreeps object. 133 | * 134 | * @see {@link https://docs.screeps.com/api/#PowerCreep.name} 135 | * 136 | * @type {string} 137 | */ 138 | name: "", 139 | 140 | /** 141 | * The text message that the creep was saying at the last tick. 142 | * 143 | * @see {@link https://docs.screeps.com/api/#PowerCreep.saying} 144 | * 145 | * @type {string} 146 | */ 147 | saying: "", 148 | 149 | /** 150 | * An object with the creep’s owner info 151 | * 152 | * @see {@link https://docs.screeps.com/api/#PowerCreep.owner} 153 | * 154 | * @type {{username:string}} 155 | */ 156 | owner: 157 | { 158 | username: "" 159 | }, 160 | 161 | /** 162 | * A Store object that contains cargo of this creep. 163 | * 164 | * @see {@link https://docs.screeps.com/api/#PowerCreep.store} 165 | * 166 | * @type {Store} 167 | */ 168 | store: {}, 169 | 170 | /** 171 | * Available powers, an object with power ID as a key, and the following properties: 172 | * 173 | * @see {@link https://docs.screeps.com/api/#PowerCreep.powers} 174 | * 175 | * @type {object} 176 | */ 177 | powers: {}, 178 | 179 | /** 180 | * The name of the shard where the power creep is spawned, or undefined. 181 | * 182 | * @see {@link https://docs.screeps.com/api/#PowerCreep.shard} 183 | * 184 | * @type {string} 185 | */ 186 | shard: "", 187 | 188 | /** 189 | * The timestamp when spawning or deleting this creep will become available. Undefined if the power creep is spawned in the world. 190 | * 191 | * @see {@link https://docs.screeps.com/api/#PowerCreep.spawnCooldownTime} 192 | * 193 | * @type {number} 194 | */ 195 | spawnCooldownTime: 0, 196 | 197 | /** 198 | * The remaining amount of game ticks after which the creep will die and become unspawned. Undefined if the creep is not spawned in the world. 199 | * 200 | * @see {@link https://docs.screeps.com/api/#PowerCreep.ticksToLive} 201 | * 202 | * @type {number} 203 | */ 204 | ticksToLive: 0, 205 | 206 | /** 207 | * Cancel the order given during the current game tick. 208 | * 209 | * @see {@link https://docs.screeps.com/api/#PowerCreep.cancelOrder} 210 | * 211 | * @type {function} 212 | * 213 | * @param {string} methodName The name of a creep's method to be cancelled. 214 | * 215 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_FOUND} 216 | */ 217 | cancelOrder: function(methodName) { }, 218 | 219 | /** 220 | * Delete the power creep permanently from your account. It should NOT be spawned in the world. 221 | * The creep is not deleted immediately, but a 24-hours delete timer is started instead (see deleteTime). 222 | * You can cancel deletion by calling delete(true). 223 | * 224 | * @see {@link https://docs.screeps.com/api/#PowerCreep.delete} 225 | * 226 | * @type {function} 227 | * 228 | * @param {boolean} [cancel] Set this to true to cancel previously scheduled deletion. 229 | * 230 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY} 231 | */ 232 | delete: function([cancel]) { }, 233 | 234 | /** 235 | * Drop this resource on the ground. 236 | * 237 | * @see {@link https://docs.screeps.com/api/#PowerCreep.drop} 238 | * 239 | * @type {function} 240 | * 241 | * @param {string} resourceType One of the RESOURCE_* constants. 242 | * @param {number} [amount] The amount of resource units to be dropped. If omitted, all the available carried amount is used. 243 | * 244 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_ARGS} 245 | */ 246 | drop: function(resourceType, amount) { }, 247 | 248 | /** 249 | * Enable powers usage in this room. The room controller should be at adjacent tile. 250 | * 251 | * @see {@link https://docs.screeps.com/api/#PowerCreep.enableRoom} 252 | * 253 | * @type {function} 254 | * 255 | * @param {StructureController} controller The room controller. 256 | * 257 | * @return {number|OK|ERR_NOT_OWNER|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE} 258 | */ 259 | enableRoom: function(controller) { }, 260 | 261 | /** 262 | * Move the creep one square in the specified direction. 263 | * 264 | * @see {@link https://docs.screeps.com/api/#PowerCreep.move} 265 | * 266 | * @type {function} 267 | * 268 | * @param {Creep|number} direction A creep nearby, or one of the following constants: TOP, TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM, BOTTOM_LEFT, LEFT, TOP_LEFT 269 | * 270 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS|ERR_TIRED} 271 | */ 272 | move: function(direction) { }, 273 | 274 | /** 275 | * Move the creep using the specified predefined path. 276 | * 277 | * @see {@link https://docs.screeps.com/api/#PowerCreep.moveByPath} 278 | * 279 | * @type {function} 280 | * 281 | * @param {Array|string} path A path value as returned from Room.findPath, RoomPosition.findPathTo, or PathFinder.search methods. Both array form and serialized string form are accepted. 282 | * 283 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_FOUND|ERR_INVALID_ARGS|ERR_TIRED} 284 | */ 285 | moveByPath: function(path) { }, 286 | 287 | /** 288 | * Find the optimal path to the target within the same room and move to it. 289 | * A shorthand to consequent calls of pos.findPathTo() and move() methods. 290 | * If the target is in another room, then the corresponding exit will be used as a target. 291 | * 292 | * @see {@link https://docs.screeps.com/api/#PowerCreep.moveTo} 293 | * 294 | * @type {function} 295 | * 296 | * @param {number|RoomPosition|RoomObject} x X position of the target in the same room. 297 | * @param {number} [y] Y position of the target in the same room. 298 | * @param {object} [opts] An object containing additional options 299 | * @param {number} [opts.reusePath] This option enables reusing the path found along multiple game ticks. It allows to save CPU time, but can result in a slightly slower creep reaction behavior. The path is stored into the creep's memory to the _move property. The reusePath value defines the amount of ticks which the path should be reused for. The default value is 5. Increase the amount to save more CPU, decrease to make the movement more consistent. Set to 0 if you want to disable path reusing. 300 | * @param {boolean} [opts.serializeMemory] If reusePath is enabled and this option is set to true, the path will be stored in memory in the short serialized form using Room.serializePath. The default value is true. 301 | * @param {boolean} [opts.noPathFinding] If this option is set to true, moveTo method will return ERR_NOT_FOUND if there is no memorized path to reuse. This can significantly save CPU time in some cases. The default value is false. 302 | * @param {object} [opts.visualizePathStyle] Draw a line along the creep’s path using RoomVisual.poly. You can provide either an empty object or custom style parameters. 303 | * @param {string} [opts.visualizePathStyle.fill] Fill color in any web format 304 | * @param {string} [opts.visualizePathStyle.stroke] Stroke color in any web format 305 | * @param {string} [opts.visualizePathStyle.lineStyle] Either undefined (solid line), dashed, or dotted 306 | * @param {number} [opts.visualizePathStyle.strokeWidth] Stroke line width 307 | * @param {number} [opts.visualizePathStyle.opacity] Opacity value 308 | * @param {boolean} [opts.ignoreCreeps] Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default value is false. 309 | * @param {boolean} [opts.ignoreDestructibleStructures] Treat squares with destructible structures (constructed walls, ramparts, spawns, extensions) as walkable. Use this flag when you need to move through a territory blocked by hostile structures. If a creep with an ATTACK body part steps on such a square, it automatically attacks the structure. The default value is false. 310 | * @param {boolean} [opts.ignoreRoads] Ignore road structures. Enabling this option can speed up the search. The default value is false. This is only used when the new PathFinder is enabled. 311 | * @param {function(string, CostMatrix)} [opts.costCallback] You can use this callback to modify a CostMatrix for any room during the search. The callback accepts two arguments, roomName and costMatrix. Use the costMatrix instance to make changes to the positions costs. If you return a new matrix from this callback, it will be used instead of the built-in cached one. This option is only used when the new PathFinder is enabled. 312 | * @param {Array} [opts.ignore] An array of the room's objects or RoomPosition objects which should be treated as walkable tiles during the search. This option cannot be used when the new PathFinder is enabled (use costCallback option instead). 313 | * @param {Array} [opts.avoid] An array of the room's objects or RoomPosition objects which should be treated as obstacles during the search. This option cannot be used when the new PathFinder is enabled (use costCallback option instead). 314 | * @param {number} [opts.maxOps] The maximum limit of possible pathfinding operations. You can limit CPU time used for the search based on ratio 1 op ~ 0.001 CPU. The default value is 2000. 315 | * @param {number} [opts.heuristicWeight] Weight to apply to the heuristic in the A* formula F = G + weight * H. Use this option only if you understand the underlying A* algorithm mechanics! The default value is 1.2. 316 | * @param {boolean} [opts.serialize] If true, the result path will be serialized using Room.serializePath. The default is false. 317 | * @param {number} [opts.maxRooms] The maximum allowed rooms to search. The default (and maximum) is 16. This is only used when the new PathFinder is enabled. 318 | * @param {number} [opts.range] Find a path to a position in specified linear range of target. The default is 0. 319 | * @param {number} [opts.plainCost] Cost for walking on plain positions. The default is 1. 320 | * @param {number} [opts.swampCost] Cost for walking on swamp positions. The default is 5. 321 | * 322 | * @alias moveTo(target, [opts]) 323 | * 324 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_TIRED|ERR_NOT_FOUND|ERR_INVALID_TARGET|ERR_NO_PATH} 325 | */ 326 | moveTo: function(x, y, opts) { }, 327 | 328 | /** 329 | * Toggle auto notification when the creep is under attack. 330 | * The notification will be sent to your account email. 331 | * Turned on by default. 332 | * 333 | * @see {@link https://docs.screeps.com/api/#PowerCreep.notifyWhenAttacked} 334 | * 335 | * @type {function} 336 | * 337 | * @param {boolean} enabled Whether to enable notification or disable. 338 | * 339 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_ARGS} 340 | */ 341 | notifyWhenAttacked: function(enabled) { }, 342 | 343 | /** 344 | * Pick up an item (a dropped piece of energy). 345 | * The target has to be at adjacent square to the creep or at the same square. 346 | * 347 | * @see {@link https://docs.screeps.com/api/#PowerCreep.pickup} 348 | * 349 | * @type {function} 350 | * 351 | * @param {Resource} target The target object to be picked up. 352 | * 353 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE} 354 | */ 355 | pickup: function(target) { }, 356 | 357 | /** 358 | * Rename the power creep. It must not be spawned in the world. 359 | * 360 | * @see {@link https://docs.screeps.com/api/#PowerCreep.rename} 361 | * 362 | * @type {function} 363 | * 364 | * @param {string} name The new name of the power creep. 365 | * 366 | * @return {number|OK|ERR_NOT_OWNER|ERR_NAME_EXISTS|ERR_BUSY} 367 | */ 368 | rename: function(name) { }, 369 | 370 | /** 371 | * Instantly restore time to live to the maximum using a Power Spawn or a Power Bank nearby. It has to be at adjacent tile. 372 | * 373 | * @see {@link https://docs.screeps.com/api/#PowerCreep.renew} 374 | * 375 | * @type {function} 376 | * 377 | * @param {StructurePowerBank|StructurePowerSpawn} target The target structure. 378 | * 379 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE} 380 | */ 381 | renew: function(target) { }, 382 | 383 | /** 384 | * Display a visual speech balloon above the creep with the specified message. The message will be 385 | * available for one tick. You can read the last message using the saying property. 386 | * 387 | * @see {@link https://docs.screeps.com/api/#PowerCreep.say} 388 | * 389 | * @type {function} 390 | * 391 | * @param {string} message The message to be displayed. Maximum length is 10 characters. 392 | * @param {boolean} [public] Set to true to allow other players to see this message. Default is false. 393 | * 394 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY} 395 | */ 396 | say: function(message, public) { }, 397 | 398 | /** 399 | * Spawn this power creep in the specified Power Spawn. 400 | * 401 | * @see {@link https://docs.screeps.com/api/#PowerCreep.spawn} 402 | * 403 | * @type {function} 404 | * 405 | * @param {StructurePowerSpawn} powerSpawn Your Power Spawn structure. 406 | * 407 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_TIRED|ERR_RCL_NOT_ENOUGH} 408 | */ 409 | spawn: function(powerSpawn) { }, 410 | 411 | /** 412 | * Kill the power creep immediately. 413 | * It will not be destroyed permanently, but will become unspawned, so that you can spawn it again. 414 | * 415 | * @see {@link https://docs.screeps.com/api/#PowerCreep.suicide} 416 | * 417 | * @type {function} 418 | * 419 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY} 420 | */ 421 | suicide: function() { }, 422 | 423 | /** 424 | * Transfer resource from the creep to another object. 425 | * The target has to be at adjacent square to the creep. 426 | * 427 | * @see {@link https://docs.screeps.com/api/#PowerCreep.transfer} 428 | * 429 | * @type {function} 430 | * 431 | * @param {Creep|PowerCreep|Structure} target The target object. 432 | * @param {string} resourceType One of the RESOURCE_* constants. 433 | * @param {number|undefined|null} [amount] The amount of resources to be transferred. If omitted, all the available carried amount is used. 434 | * 435 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS} 436 | */ 437 | transfer: function(target, resourceType, amount) { }, 438 | 439 | /** 440 | * Upgrade the creep, adding a new power ability to it or increasing level of the existing power. 441 | * You need one free Power Level in your account to perform this action. 442 | * 443 | * @see {@link https://docs.screeps.com/api/#PowerCreep.upgrade} 444 | * 445 | * @type {function} 446 | * 447 | * @param {number} power The power ability to upgrade, one of the PWR_* constants. 448 | * 449 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_RESOURCES|ERR_FULL|ERR_INVALID_ARGS} 450 | */ 451 | upgrade: function(power) { }, 452 | 453 | /** 454 | * Apply one the creep's powers on the specified target. 455 | * You can only use powers in rooms either without a controller, or with a power-enabled controller. 456 | * Only one power can be used during the same tick, each usePower call will override the previous one. 457 | * If the target has the same effect of a lower or equal level, it is overridden. 458 | * If the existing effect level is higher, an error is returned. 459 | * 460 | * @see {@link https://docs.screeps.com/api/#PowerCreep.usePower} 461 | * 462 | * @type {function} 463 | * 464 | * @param {number} power The power ability to use, one of the PWR_* constants. 465 | * @param {RoomObject} [target] A target object in the room. 466 | * 467 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS|ERR_TIRED|ERR_NO_BODYPART} 468 | */ 469 | usePower: function(power, [target]) { }, 470 | 471 | /** 472 | * Withdraw resources from a structure or tombstone. 473 | * The target has to be at adjacent square to the creep. 474 | * Multiple creeps can withdraw from the same object in the same tick. 475 | * Your creeps can withdraw resources from hostile structures/tombstones as well, in case if there is no hostile rampart on top of it. 476 | * 477 | * @see {@link https://docs.screeps.com/api/#PowerCreep.withdraw} 478 | * 479 | * @type {function} 480 | * 481 | * @param {Structure|Tombstone|Ruin} target The target object. 482 | * @param {string} resourceType One of the RESOURCE_* constants. 483 | * @param {number|undefined|null} [amount] The amount of resources to be transferred. If omitted, all the available amount is used. 484 | * 485 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS} 486 | */ 487 | withdraw: function(target, resourceType, amount) { } 488 | }; 489 | -------------------------------------------------------------------------------- /RawMemory.js: -------------------------------------------------------------------------------- 1 | /** 2 | * RawMemory object allows to implement your own memory stringifier instead of built-in serializer based on JSON.stringify. 3 | * 4 | * @class 5 | * 6 | * @see {@link https://docs.screeps.com/api/#RawMemory} 7 | */ 8 | RawMemory = { 9 | /** 10 | * An object with asynchronous memory segments available on this tick. 11 | * Each object key is the segment ID with data in string values. 12 | * Use setActiveSegments to fetch segments on the next tick. 13 | * Segments data is saved automatically in the end of the tick. 14 | * The maximum size per segment is 100 KB. 15 | * 16 | * @see {@link https://docs.screeps.com/api/#RawMemory.segments} 17 | * 18 | * @type {object} 19 | */ 20 | segments: {}, 21 | 22 | /** 23 | * An object with a memory segment of another player available on this tick. 24 | * Use setActiveForeignSegment to fetch segments on the next tick. 25 | * 26 | * @see {@link https://docs.screeps.com/api/#RawMemory.foreignSegment} 27 | * 28 | * @type {object} 29 | */ 30 | foreignSegment: {}, 31 | 32 | /** 33 | * A string with a shared memory segment available on every world shard. Maximum string length is 100 KB. 34 | * 35 | * Warning: this segment is not safe for concurrent usage! 36 | * All shards have shared access to the same instance of data. 37 | * When the segment contents is changed by two shards simultaneously, 38 | * you may lose some data, since the segment string value is written all at once atomically. 39 | * You must implement your own system to determine when each shard is allowed to rewrite the inter-shard memory, e.g. based on mutual exclusions. 40 | * 41 | * @deprecated use InterShardMemory instead. 42 | * 43 | * @see {@link https://docs.screeps.com/api/#RawMemory.interShardSegment} 44 | * 45 | * @type {string} 46 | */ 47 | interShardSegment: "", 48 | 49 | /** 50 | * Get a raw string representation of the Memory object. 51 | * 52 | * @see {@link https://docs.screeps.com/api/#RawMemory.get} 53 | * 54 | * @type {function} 55 | * 56 | * @return {string} 57 | */ 58 | get: function() { }, 59 | 60 | /** 61 | * Set new Memory value. 62 | * 63 | * @see {@link https://docs.screeps.com/api/#RawMemory.set} 64 | * 65 | * @type {function} 66 | * 67 | * @param {string} value New memory value as a string. 68 | * 69 | * @return {void} 70 | */ 71 | set: function(value) { }, 72 | 73 | /** 74 | * Request memory segments using the list of their IDs. 75 | * Memory segments will become available on the next tick in segments object. 76 | * 77 | * @see {@link https://docs.screeps.com/api/#RawMemory.setActiveSegments} 78 | * 79 | * @type {function} 80 | * 81 | * @param {array} ids An array of segment IDs. 82 | * Each ID should be a number from 0 to 99. 83 | * Maximum 10 segments can be active at the same time. 84 | * Subsequent calls of setActiveSegments override previous ones. 85 | * 86 | * @return {void} 87 | */ 88 | setActiveSegments: function(ids) { }, 89 | 90 | /** 91 | * Request a memory segment of another user. 92 | * The segment should be marked by its owner as public using setPublicSegments. 93 | * The segment data will become available on the next tick in foreignSegment object. 94 | * You can only have access to one foreign segment at the same time. 95 | * 96 | * @see {@link https://docs.screeps.com/api/#RawMemory.setActiveForeignSegment} 97 | * 98 | * @type {function} 99 | * 100 | * @param {string|null} username The name of another user. Pass null to clear the foreign segment. 101 | * @param {number} [id] The ID of the requested segment from 0 to 99. 102 | * If undefined, the user's default public segment is requested as set by setDefaultPublicSegment. 103 | * 104 | * @return {void} 105 | */ 106 | setActiveForeignSegment: function(username, id) { }, 107 | 108 | /** 109 | * Set the specified segment as your default public segment. 110 | * It will be returned if no id parameter is passed to setActiveForeignSegment by another user. 111 | * 112 | * @see {@link https://docs.screeps.com/api/#RawMemory.setDefaultPublicSegment} 113 | * 114 | * @type {function} 115 | * 116 | * @param {number|null} id The ID of the memory segment from 0 to 99. Pass null to remove your default public segment. 117 | * 118 | * @return {void} 119 | */ 120 | setDefaultPublicSegment: function(id) { }, 121 | 122 | /** 123 | * Set specified segments as public. 124 | * Other users will be able to request access to them using setActiveForeignSegment. 125 | * 126 | * @see {@link https://docs.screeps.com/api/#RawMemory.setPublicSegments} 127 | * 128 | * @type {function} 129 | * 130 | * @param {array} ids An array of segment IDs. Each ID should be a number from 0 to 99. Subsequent calls of setPublicSegments override previous ones. 131 | * 132 | * @return {void} 133 | */ 134 | setPublicSegments: function(ids) { } 135 | }; 136 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | Screeps Autocomplete 2 | ==================== 3 | The purpose of this is to add screeps autocomplete to IDEs by creating a definition from the documents. People can then 4 | add this project as a library in their IDE, and their IDE should be able to start autocompleting their code. Tested 5 | somewhat in JetBrain's WebStorm 6 | 7 | ## How to Install 8 | 9 | #### Webstorm (Or Other Jetbrains IDE's) 10 | This can be done by quite simply copying the `ScreepsAutocomplete` folder in their project, and Webstorm should automatically 11 | detect it and add it to the autocompletion 12 | ###### Adding it as a library 13 | Instead of copying the `ScreepsAutocomplete` folder to each and every project folder, you can add it as a global library. 14 | 15 | * Create a new project in Webstorm if you don't already have one and open it. 16 | * In the menu bar at the top of the screen, navigate to `File` -> `Settings` -> `Languages & Frameworks` -> `JavaScript` -> `Libraries` 17 | * Click `Add`. 18 | * Name the Library whatever you want. 19 | * Set `Framework type` to custom, if it is not already so. `Version` can be left blank. 20 | * Change `Visibility` to `Global`. 21 | * Click the green plus sign to the right of the listbox below `Visibility`, then choose "Attach Directories...". 22 | * Navigate to the ScreepsAutocomplete folder, select the folder itself and click `OK`. 23 | * Click `OK` at the bottom of the "Edit Library" dialog. 24 | * Click the `Enabled` checkbox on the library you just created, make sure it's checked before continuing. 25 | * Click `OK` at the bottom of the "Settings" dialog. 26 | 27 | Webstorm should automatically detect the library and add it to the autocompletion. 28 | 29 | #### Visual Studio 30 | 1. Create a new empty web site (File -> New -> Web Site -> ASP.NET Empty Web Site) and set the location to the location of your program. 31 | 2. Copy the `ScreepsAutocomplete` folder into your project and create a new file called `_references.js` (right click in solution explorer -> Add New Item -> `_references.js`). 32 | 3. Right click within the empty file and select `Update JavaScript References` which will populate the file and make autocomplete avaliable. 33 | 34 | [Video](https://youtu.be/XgCBdF1BBdE?t=48s) 35 | 36 | #### Sublime Text 37 | There are two ways to enable Autocomplete in Sublime Text, both of them require installing a plugin through 38 | [`Package Control`](https://packagecontrol.io/installation), and copying `ScreepsAutocomplete` in to your project. 39 | 40 | * `TernJS` - Install `TernJS` through `Package Control`, restart Sublime Text and try `var room = new Room(); room.lookAt(x, y)` 41 | to see if Autocomplete is working. If not, try the next options 42 | 43 | * `SublimeCodeIntel` - Install `SublimeCodeIntel` through `Package Control`. Go to `Preferences > Package Settings > SublimeCodeIntel > Settings -- User` 44 | and copy the contents of `ScreepsAutocomplete/config/SublimeCodeIntel.json` in to the file that opens. Save and restart Sublime 45 | Text. After waiting for CodeIntel to process JavaScript, Autocomplete should be working 46 | 47 | #### Atom 48 | Integration with Atom is done through use of the [`atom-ternjs`](https://github.com/tststs/atom-ternjs) package. Here's the steps 49 | 50 | * Copy `ScreepsAutocomplete` in to your project folder 51 | * Install the `atom-ternjs` package 52 | * Put the following in your `.tern-project` file 53 | ```json 54 | { 55 | "ecmaVersion": 6, 56 | "libs": [], 57 | "loadEagerly": [ 58 | "ScreepsAutocomplete/**/*.js" 59 | ] 60 | } 61 | ``` 62 | * Restart and Enjoy 63 | -------------------------------------------------------------------------------- /Resource.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A dropped piece of resource. 3 | * It will decay after a while if not picked up. 4 | * Dropped resource pile decays for ceil(amount/1000) units per tick. 5 | * 6 | * @class 7 | * @extends {RoomObject} 8 | * 9 | * @see {@link https://docs.screeps.com/api/#Resource} 10 | */ 11 | Resource = function() { }; 12 | 13 | Resource.prototype = 14 | { 15 | /** 16 | * The amount of resource units containing. 17 | * 18 | * @see {@link https://docs.screeps.com/api/#Resource.amount} 19 | * 20 | * @type {number} 21 | */ 22 | amount: 0, 23 | 24 | /** 25 | * A unique object identificator. 26 | * You can use Game.getObjectById method to retrieve an object instance by its id. 27 | * 28 | * @see {@link https://docs.screeps.com/api/#Resource.id} 29 | * 30 | * @type {string} 31 | */ 32 | id: "", 33 | 34 | /** 35 | * One of the RESOURCE_* constants. 36 | * 37 | * @see {@link https://docs.screeps.com/api/#Resource.resourceType} 38 | * 39 | * @type {string} 40 | */ 41 | resourceType: "" 42 | }; 43 | -------------------------------------------------------------------------------- /Room.js: -------------------------------------------------------------------------------- 1 | /** 2 | * An object representing the room in which your units and structures are in. 3 | * It can be used to look around, find paths, etc. 4 | * Every RoomObject in the room contains its linked Room instance in the room property. 5 | * 6 | * @class 7 | * 8 | * @see {@link https://docs.screeps.com/api/#Room} 9 | */ 10 | Room = { 11 | /** 12 | * Serialize a path array into a short string representation, which is suitable to store in memory. 13 | * 14 | * @see {@link https://docs.screeps.com/api/#Room.serializePath} 15 | * 16 | * @type {function} 17 | * 18 | * @param {Array} path A path array retrieved from Room.findPath. 19 | * 20 | * @return {string} A serialized string form of the given path. 21 | */ 22 | serializePath: function(path) { }, 23 | 24 | /** 25 | * Deserialize a short string path representation into an array form. 26 | * 27 | * @see {@link https://docs.screeps.com/api/#Room.deserializePath} 28 | * 29 | * @type {function} 30 | * 31 | * @param {string} path A serialized path string. 32 | * 33 | * return {Array} A path array. 34 | */ 35 | deserializePath: function(path) { } 36 | }; 37 | 38 | Room.prototype = 39 | { 40 | /** 41 | * The Controller structure of this room, if present, otherwise undefined. 42 | * 43 | * @see {@link https://docs.screeps.com/api/#Room.controller} 44 | * 45 | * @type {undefined|StructureController} 46 | */ 47 | controller: null, 48 | 49 | /** 50 | * Total amount of energy available in all spawns and extensions in the room. 51 | * 52 | * @see {@link https://docs.screeps.com/api/#Room.energyAvailable} 53 | * 54 | * @type {number} 55 | */ 56 | energyAvailable: 0, 57 | 58 | /** 59 | * Total amount of energyCapacity of all spawns and extensions in the room. 60 | * 61 | * @see {@link https://docs.screeps.com/api/#Room.energyCapacityAvailable} 62 | * 63 | * @type {number} 64 | */ 65 | energyCapacityAvailable: 0, 66 | 67 | /** 68 | * A shorthand to Memory.rooms[room.name]. 69 | * You can use it for quick access the room’s specific memory data object. 70 | * 71 | * @see {@link https://docs.screeps.com/api/#Room.memory} 72 | * 73 | * @type {RoomMemory} 74 | */ 75 | memory: {}, 76 | 77 | /** 78 | * The name of the room. 79 | * 80 | * @see {@link https://docs.screeps.com/api/#Room.name} 81 | * 82 | * @type {string} 83 | */ 84 | name: "", 85 | 86 | /** 87 | * The Storage structure of this room, if present, otherwise undefined. 88 | * 89 | * @see {@link https://docs.screeps.com/api/#Room.storage} 90 | * 91 | * @type {undefined|StructureStorage} 92 | */ 93 | storage: null, 94 | 95 | /** 96 | * The Terminal structure of this room, if present, otherwise undefined. 97 | * 98 | * @see {@link https://docs.screeps.com/api/#Room.terminal} 99 | * 100 | * @type {undefined|StructureTerminal} 101 | */ 102 | terminal: null, 103 | 104 | /** 105 | * A RoomVisual object for this room. You can use this object to draw simple shapes (lines, circles, text labels) in the room. 106 | * @see {@link https://docs.screeps.com/api/#Room.visual} 107 | * 108 | * @type {RoomVisual} 109 | */ 110 | visual: null, 111 | 112 | /** 113 | * Create new ConstructionSite at the specified location. 114 | * 115 | * @see {@link https://docs.screeps.com/api/#Room.createConstructionSite} 116 | * 117 | * @type {function} 118 | * 119 | * @param {number|RoomPosition|RoomObject} x The X position. 120 | * @param {number|string} [y] The Y position. 121 | * @param {string} [structureType] One of the STRUCTURE_* constants. 122 | * @param {string} [name] The name of the structure, for structures that support it (currently only spawns). 123 | * 124 | * @note Alternative function: createConstructionSite(pos, structureType) 125 | * @param {object} pos Can be a RoomPosition object or any object containing RoomPosition. 126 | * 127 | * @return {number|OK|ERR_NOT_OWNER|ERR_INVALID_TARGET|ERR_FULL|ERR_INVALID_ARGS|ERR_RCL_NOT_ENOUGH} 128 | */ 129 | createConstructionSite: function(x, y, structureType, name) { }, 130 | 131 | /** 132 | * Create new Flag at the specified location. 133 | * 134 | * @see {@link https://docs.screeps.com/api/#Room.createFlag} 135 | * 136 | * @type {function} 137 | * 138 | * @param {number|RoomPosition|RoomObject} x The X position. 139 | * @param {number|string} y The Y position. 140 | * @param {string} [name] The name of a new flag. It should be unique, i.e. the Game.flags object should not contain another flag with the same name (hash key). If not defined, a random name will be generated. 141 | * @param {string} [color] The color of a new flag. Should be one of the COLOR_* constants. The default value is COLOR_WHITE. 142 | * @param {string} [secondaryColor] The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color. 143 | * 144 | * @note Alternative function: createConstructionSite(pos, name, color, secondaryColor) 145 | * @param {object} pos Can be a RoomPosition object or any object containing RoomPosition. 146 | * 147 | * @return {number|ERR_NAME_EXISTS|ERR_INVALID_ARGS|ERR_FULL} The name of a new flag, or one of the following error codes: ERR_NAME_EXISTS, ERR_INVALID_ARGS, ERR_FULL. 148 | */ 149 | createFlag: function(x, y, name, color, secondaryColor) { }, 150 | 151 | /** 152 | * Find all objects of the specified type in the room. 153 | * 154 | * @see {@link https://docs.screeps.com/api/#Room.find} 155 | * 156 | * @type {function} 157 | * 158 | * @param {number} type One of the FIND_* constants. 159 | * @param {object} [opts] An object with additional options 160 | * @param {object|function|string} [opts.filter] The result list will be filtered using the Lodash.filter method. 161 | * 162 | * @return {Array} An array with the objects found. 163 | */ 164 | find: function(type, opts) { }, 165 | 166 | /** 167 | * Find the exit direction en route to another room. 168 | * 169 | * @see {@link https://docs.screeps.com/api/#Room.findExitTo} 170 | * 171 | * @type {function} 172 | * 173 | * @param {string|Room} room Another room name or room object. 174 | * 175 | * @return {FIND_EXIT_TOP|FIND_EXIT_RIGHT|FIND_EXIT_BOTTOM|FIND_EXIT_LEFT|number|ERR_NO_PATH|ERR_INVALID_ARGS} 176 | */ 177 | findExitTo: function(room) { }, 178 | 179 | /** 180 | * Find an optimal path inside the room between fromPos and toPos using A* search algorithm. 181 | * 182 | * @see {@link https://docs.screeps.com/api/#Room.findPath} 183 | * 184 | * @type {function} 185 | * 186 | * @param {RoomPosition} fromPos The start position. 187 | * @param {RoomPosition} toPos The end position. 188 | * @param {object} [opts] An object containing additonal pathfinding flags 189 | * @param {boolean} [opts.ignoreCreeps] Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default value is false. 190 | * @param {boolean} [opts.ignoreDestructibleStructures] Treat squares with destructible structures (constructed walls, ramparts, spawns, extensions) as walkable. Use this flag when you need to move through a territory blocked by hostile structures. If a creep with an ATTACK body part steps on such a square, it automatically attacks the structure. The default value is false. 191 | * @param {boolean} [opts.ignoreRoads] Ignore road structures. Enabling this option can speed up the search. The default value is false. This is only used when the new PathFinder is enabled. 192 | * @param {function(string, CostMatrix)} [opts.costCallback] You can use this callback to modify a CostMatrix for any room during the search. The callback accepts two arguments, roomName and costMatrix. Use the costMatrix instance to make changes to the positions costs. If you return a new matrix from this callback, it will be used instead of the built-in cached one. This option is only used when the new PathFinder is enabled. 193 | * @param {Array} [opts.ignore] An array of the room's objects or RoomPosition objects which should be treated as walkable tiles during the search. This option cannot be used when the new PathFinder is enabled (use costCallback option instead). 194 | * @param {Array} [opts.avoid] An array of the room's objects or RoomPosition objects which should be treated as obstacles during the search. This option cannot be used when the new PathFinder is enabled (use costCallback option instead). 195 | * @param {number} [opts.maxOps] The maximum limit of possible pathfinding operations. You can limit CPU time used for the search based on ratio 1 op ~ 0.001 CPU. The default value is 2000. 196 | * @param {number} [opts.heuristicWeight] Weight to apply to the heuristic in the A* formula F = G + weight * H. Use this option only if you understand the underlying A* algorithm mechanics! The default value is 1.2. 197 | * @param {boolean} [opts.serialize] If true, the result path will be serialized using Room.serializePath. The default is false. 198 | * @param {number} [opts.maxRooms] The maximum allowed rooms to search. The default (and maximum) is 16. This is only used when the new PathFinder is enabled. 199 | * @param {number} [opts.range] Find a path to a position in specified linear range of target. The default is 0. 200 | * @param {number} [opts.plainCost] Cost for walking on plain positions. The default is 1. 201 | * @param {number} [opts.swampCost] Cost for walking on swamp positions. The default is 5. 202 | * 203 | * @return {Array} An array with path steps in the following format: 204 | [ 205 | { x: 10, y: 5, dx: 1, dy: 0, direction: RIGHT }, 206 | { x: 10, y: 6, dx: 0, dy: 1, direction: BOTTOM }, 207 | { x: 9, y: 7, dx: -1, dy: 1, direction: BOTTOM_LEFT }, 208 | ... 209 | ] 210 | 211 | */ 212 | findPath: function(fromPos, toPos, opts) { }, 213 | 214 | /** 215 | * Returns an array of events happened on the previous tick in this room. 216 | * 217 | * @see {@link https://docs.screeps.com/api/#Room.getEventLog} 218 | * 219 | * @type {function} 220 | * 221 | * @param {boolean} [raw] If this parameter is false or undefined, the method returns an object parsed using JSON.parse which incurs some CPU cost on the first access (the return value is cached on subsequent calls). If raw is truthy, then raw JSON in string format is returned. 222 | * 223 | * @return {Array} An array of events. Each event represents some game action in the following format: 224 | { 225 | event: EVENT_ATTACK, 226 | objectId: '54bff72ab32a10f73a57d017', 227 | data: { ... } 228 | } 229 | */ 230 | getEventLog: function(raw) { }, 231 | 232 | /** 233 | * Creates a RoomPosition object at the specified location. 234 | * 235 | * @see {@link https://docs.screeps.com/api/#Room.getPositionAt} 236 | * 237 | * @type {function} 238 | * 239 | * @param {number} x The X position. 240 | * @param {number} y The Y position. 241 | * 242 | * @return {null|RoomPosition} A RoomPosition object or null if it cannot be obtained. 243 | */ 244 | getPositionAt: function(x, y) { }, 245 | 246 | /** 247 | * Get a Room.Terrain object which provides fast access to static terrain data. This method works for any room in the world even if you have no access to it. 248 | * 249 | * @see {@link https://docs.screeps.com/api/#Room.getTerrain} 250 | * 251 | * @type {function} 252 | * 253 | * @return {Room.Terrain} Returns new Room.Terrain object. 254 | */ 255 | getTerrain: function() {}, 256 | 257 | /** 258 | * Get the list of objects at the specified room position. 259 | * 260 | * @see {@link https://docs.screeps.com/api/#Room.lookAt} 261 | * 262 | * @type {function} 263 | * 264 | * @param {number} x X position in the room. 265 | * @param {number|RoomPosition|RoomObject} [y] Y position in the room. 266 | * 267 | * @note Alternative function: lookAt(target) 268 | * @param {object} target Can be a RoomPosition object or any object containing RoomPosition. 269 | * 270 | * @return {Array} An array with objects at the specified position in the following format: 271 | [ 272 | { type: 'creep', creep: {...} }, 273 | { type: 'structure', structure: {...} }, 274 | ... 275 | { type: 'terrain', terrain: 'swamp' } 276 | ] 277 | */ 278 | lookAt: function(x, y) { }, 279 | 280 | /** 281 | * Get the list of objects at the specified room area. 282 | * 283 | * @see {@link https://docs.screeps.com/api/#Room.lookAtArea} 284 | * 285 | * @type {function} 286 | * 287 | * @param {number} top The top Y boundary of the area. 288 | * @param {number} left The left X boundary of the area. 289 | * @param {number} bottom The bottom Y boundary of the area. 290 | * @param {number} right The right X boundary of the area. 291 | * @param {boolean} [asArray] Set to true if you want to get the result as a plain array. 292 | * 293 | * @return {object|Array} An object with all the objects in the specified area in the following format: 294 | // 10,5,11,7 295 | { 296 | 10 : 297 | { 298 | 5 : 299 | [ 300 | { 301 | type : 'creep', 302 | creep : 303 | { 304 | ... 305 | } 306 | }, 307 | { 308 | type : 'terrain', 309 | terrain : 'swamp' 310 | } 311 | ], 312 | 6 : 313 | [ 314 | { 315 | type : 'terrain', 316 | terrain : 'swamp' 317 | } 318 | ], 319 | 7 : 320 | [ 321 | { 322 | type : 'terrain', 323 | terrain : 'swamp' 324 | } 325 | ] 326 | }, 327 | 11 : 328 | { 329 | 5 : 330 | [ 331 | { 332 | type : 'terrain', 333 | terrain : 'normal' 334 | } 335 | ], 336 | 6 : 337 | [ 338 | { 339 | type : 'structure', 340 | structure : 341 | { 342 | ... 343 | } 344 | }, 345 | { 346 | type : 'terrain', 347 | terrain : 'swamp' 348 | } 349 | ], 350 | 7 : 351 | [ 352 | { 353 | type : 'terrain', 354 | terrain : 'wall' 355 | } 356 | ] 357 | } 358 | } 359 | */ 360 | lookAtArea: function(top, left, bottom, right, asArray) { }, 361 | 362 | /** 363 | * Get an object with the given type at the specified room position. 364 | * 365 | * @see {@link https://docs.screeps.com/api/#Room.lookForAt} 366 | * 367 | * @type {function} 368 | * 369 | * @param {string} type One of the LOOK_* constants. 370 | * @param {number|RoomPosition|RoomObject} x X position in the room. 371 | * @param {number} [y] Y position in the room. 372 | * 373 | * @note Alternative function: lookForAt(type, target) 374 | * @param {object} target Can be a RoomPosition object or any object containing RoomPosition. 375 | * 376 | * @return {Array} An array of objects of the given type at the specified position if found. 377 | */ 378 | lookForAt: function(type, x, y) { }, 379 | 380 | /** 381 | * Get the list of objects with the given type at the specified room area. 382 | * 383 | * @see {@link https://docs.screeps.com/api/#Room.lookForAtArea} 384 | * 385 | * @type {function} 386 | * 387 | * @param {string} type One of the LOOK_* constants. 388 | * @param {number} top The top Y boundary of the area. 389 | * @param {number} left The left X boundary of the area. 390 | * @param {number} bottom The bottom Y boundary of the area. 391 | * @param {number} right The right X boundary of the area. 392 | * @param {boolean} [asArray] Set to true if you want to get the result as a plain array. 393 | * 394 | * @return {object|Array} An object with all the objects of the given type in the specified area in the following format: 395 | //10,5,11,7 396 | { 397 | 10: 398 | { 399 | 5: [{...}], 400 | 6: undefined, 401 | 7: undefined 402 | }, 403 | 11: 404 | { 405 | 5: undefined, 406 | 6: [{...}, {...}], 407 | 7: undefined 408 | } 409 | } 410 | */ 411 | lookForAtArea: function(type, top, left, bottom, right, asArray) { } 412 | }; 413 | 414 | /** 415 | * An object which provides fast access to room terrain data. These objects can be constructed for any room in the world even if you have no access to it. 416 | * 417 | * Technically every Room.Terrain object is a very lightweight adapter to underlying static terrain buffers with corresponding minimal accessors. 418 | * 419 | * @param {string} roomName The room name. 420 | * 421 | * @class 422 | * @constructor 423 | * 424 | * @see {@link https://docs.screeps.com/api/#Room-Terrain} 425 | */ 426 | Room.Terrain = function(roomName) {}; 427 | 428 | Room.Terrain.prototype = { 429 | /** 430 | * Get terrain type at the specified room position by (x,y) coordinates. Unlike the Game.map.getTerrainAt(...) method, this one doesn't perform any string operations and returns integer terrain type values (see below). 431 | * 432 | * @see {@link https://docs.screeps.com/api/#Room.Terrain.get} 433 | * 434 | * @type {function} 435 | * 436 | * @param {number} x X position in the room. 437 | * @param {number} y Y position in the room. 438 | * 439 | * @return {number|0|TERRAIN_MASK_WALL|TERRAIN_MASK_SWAMP} An integer value. 0 if Plain. 440 | */ 441 | get: function(x, y) {}, 442 | 443 | /** 444 | * Get copy of underlying static terrain buffer. Current underlying representation is Uint8Array. 445 | * 446 | * @note WARNING: this method relies on underlying representation of terrain data. This is the fastest way to obtain terrain data of the whole room (2500 tiles), but users should keep in mind that it can be marked as deprecated anytime in the future, or return value type can be changed due to underlying data representation changing. 447 | * 448 | * @see {@link https://docs.screeps.com/api/#Room.Terrain.getRawBuffer} 449 | * 450 | * @type {function} 451 | * 452 | * @param {Uint8Array} [destinationArray] A typed array view in which terrain will be copied to. 453 | * 454 | * @return {Uint8Array|number|ERR_INVALID_ARGS} Copy of underlying room terrain representations as a new Uint8Array typed array of size 2500. 455 | 456 | Each element is an integer number, terrain type can be obtained by applying bitwise AND (&) operator with appropriate TERRAIN_MASK_* constant. Room tiles are stored row by row. 457 | 458 | If destinationArray is specified, function returns reference to this filled destinationArray if coping succeeded, or error code otherwise: 459 | */ 460 | getRawBuffer: function(destinationArray) {} 461 | }; 462 | -------------------------------------------------------------------------------- /RoomObject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Any object with a position in a room. 3 | * Almost all game objects prototypes are derived from RoomObject. 4 | * @class 5 | * 6 | * @see {@link https://docs.screeps.com/api/#RoomObject} 7 | */ 8 | RoomObject = function() { }; 9 | 10 | RoomObject.prototype = 11 | { 12 | /** 13 | * Applied effects, an array of objects 14 | * 15 | * @see {@link https://docs.screeps.com/api/#RoomObject.effects} 16 | * 17 | * @type {Array<{effect:number, level:number, ticksRemaining:number}>} 18 | */ 19 | effects: null, 20 | 21 | /** 22 | * An object representing the position of this object in the room. 23 | * 24 | * @see {@link https://docs.screeps.com/api/#RoomObject.pos} 25 | * 26 | * @type {RoomPosition} 27 | */ 28 | pos: null, 29 | 30 | /** 31 | * The link to the Room object. 32 | * May be undefined in case if an object is a flag or a construction site and is placed in a room that is not visible to you. 33 | * 34 | * @see {@link https://docs.screeps.com/api/#RoomObject.room} 35 | * 36 | * @type {Room} 37 | */ 38 | room: null 39 | }; 40 | -------------------------------------------------------------------------------- /RoomPosition.js: -------------------------------------------------------------------------------- 1 | /** 2 | * An object representing the specified position in the room. 3 | * Every RoomObject in the room contains RoomPosition as the pos property. 4 | * The position object of a custom location can be obtained using the Room.getPositionAt() method or using the constructor. 5 | * 6 | * @param {number} x X position in the room. 7 | * @param {number} y Y position in the room. 8 | * @param {string} roomName The room name. 9 | * 10 | * @class 11 | * @constructor 12 | * 13 | * @see {@link https://docs.screeps.com/api/#RoomPosition} 14 | */ 15 | RoomPosition = function(x, y, roomName) { }; 16 | 17 | RoomPosition.prototype = 18 | { 19 | /** 20 | * The name of the room. 21 | * 22 | * @see {@link https://docs.screeps.com/api/#RoomPosition.roomName} 23 | * 24 | * @type {string} 25 | */ 26 | roomName: "", 27 | 28 | /** 29 | * X position in the room. 30 | * 31 | * @see {@link https://docs.screeps.com/api/#RoomPosition.x} 32 | * 33 | * @type {number} 34 | */ 35 | x: 0, 36 | 37 | /** 38 | * Y position in the room. 39 | * 40 | * @see {@link https://docs.screeps.com/api/#RoomPosition.y} 41 | * 42 | * @type {number} 43 | */ 44 | y: 0, 45 | 46 | /** 47 | * Create new ConstructionSite at the specified location. 48 | * 49 | * @see {@link https://docs.screeps.com/api/#RoomPosition.createConstructionSite} 50 | * 51 | * @type {function} 52 | * 53 | * @param {string} structureType One of the STRUCTURE_* constants. 54 | * @param {string} [name] The name of the structure, for structures that support it (currently only spawns). 55 | * 56 | * @return {number|OK|ERR_INVALID_TARGET|ERR_FULL|ERR_INVALID_ARGS|ERR_RCL_NOT_ENOUGH} 57 | */ 58 | createConstructionSite: function(structureType, name) { }, 59 | 60 | /** 61 | * Create new Flag at the specified location. 62 | * 63 | * @see {@link https://docs.screeps.com/api/#RoomPosition.createFlag} 64 | * 65 | * @type {function} 66 | * 67 | * @param {string} [name] The name of a new flag. It should be unique, i.e. the Game.flags object should not contain another flag with the same name (hash key). If not defined, a random name will be generated. 68 | * @param {string} [color] The color of a new flag. Should be one of the COLOR_* constants. The default value is COLOR_WHITE. 69 | * @param {string} [secondaryColor] The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color. 70 | * 71 | * @return {string|number|ERR_NAME_EXISTS|ERR_INVALID_ARGS} The name of a new flag, or one of the following error codes: ERR_NAME_EXISTS, ERR_INVALID_ARGS. 72 | */ 73 | createFlag: function(name, color, secondaryColor) { }, 74 | 75 | /** 76 | * Find an object with the shortest path from the given position. 77 | * Uses A* search algorithm and Dijkstra's algorithm. 78 | * 79 | * @see {@link https://docs.screeps.com/api/#RoomPosition.findClosestByPath} 80 | * 81 | * @type {function} 82 | * 83 | * @param {number|Array|Array} type See Room.find. 84 | * @param {object} [opts] An object containing pathfinding options (see Room.findPath) 85 | * @param {object|function|string} [opts.filter] Only the objects which pass the filter using the Lodash.filter method will be used. 86 | * @param {string} [opts.algorithm] One of the following constants: 87 | astar is faster when there are relatively few possible targets; 88 | dijkstra is faster when there are a lot of possible targets or when the closest target is nearby. 89 | The default value is determined automatically using heuristics. 90 | * @param {boolean} [opts.ignoreCreeps] Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default value is false. 91 | * @param {boolean} [opts.ignoreDestructibleStructures] Treat squares with destructible structures (constructed walls, ramparts, spawns, extensions) as walkable. Use this flag when you need to move through a territory blocked by hostile structures. If a creep with an ATTACK body part steps on such a square, it automatically attacks the structure. The default value is false. 92 | * @param {boolean} [opts.ignoreRoads] Ignore road structures. Enabling this option can speed up the search. The default value is false. This is only used when the new PathFinder is enabled. 93 | * @param {function(string, CostMatrix)} [opts.costCallback] You can use this callback to modify a CostMatrix for any room during the search. The callback accepts two arguments, roomName and costMatrix. Use the costMatrix instance to make changes to the positions costs. If you return a new matrix from this callback, it will be used instead of the built-in cached one. This option is only used when the new PathFinder is enabled. 94 | * @param {Array} [opts.ignore] An array of the room's objects or RoomPosition objects which should be treated as walkable tiles during the search. This option cannot be used when the new PathFinder is enabled (use costCallback option instead). 95 | * @param {Array} [opts.avoid] An array of the room's objects or RoomPosition objects which should be treated as obstacles during the search. This option cannot be used when the new PathFinder is enabled (use costCallback option instead). 96 | * @param {number} [opts.maxOps] The maximum limit of possible pathfinding operations. You can limit CPU time used for the search based on ratio 1 op ~ 0.001 CPU. The default value is 2000. 97 | * @param {number} [opts.heuristicWeight] Weight to apply to the heuristic in the A* formula F = G + weight * H. Use this option only if you understand the underlying A* algorithm mechanics! The default value is 1.2. 98 | * @param {boolean} [opts.serialize] If true, the result path will be serialized using Room.serializePath. The default is false. 99 | * @param {number} [opts.maxRooms] The maximum allowed rooms to search. The default (and maximum) is 16. This is only used when the new PathFinder is enabled. 100 | * @param {number} [opts.range] Find a path to a position in specified linear range of target. The default is 0. 101 | * @param {number} [opts.plainCost] Cost for walking on plain positions. The default is 1. 102 | * @param {number} [opts.swampCost] Cost for walking on swamp positions. The default is 5. 103 | 104 | * @note Alternative function: findClosestByPath: function(objects, opts) 105 | * @param {array} objects An array of room's objects or RoomPosition objects that the search should be executed against. 106 | 107 | * @return {object|null} The closest object if found, null otherwise. 108 | */ 109 | findClosestByPath: function(type, opts) { }, 110 | 111 | /** 112 | * Find an object with the shortest linear distance from the given position. 113 | * 114 | * @see {@link https://docs.screeps.com/api/#RoomPosition.findClosestByRange} 115 | * 116 | * @type {function} 117 | * 118 | * @param {number|Array|Array} type See Room.find. 119 | * @param {object} [opts] 120 | * @param {object|function|string} [opts.filter] Only the objects which pass the filter using the Lodash.filter method will be used. 121 | * 122 | * @note Alterative function: findClosestByRange: function(objects, opts) 123 | * @param {array} objects An array of room's objects or RoomPosition objects that the search should be executed against. 124 | * 125 | * @return {object|null} The closest object if found, null otherwise. 126 | */ 127 | findClosestByRange: function(type, opts) { }, 128 | 129 | /** 130 | * Find all objects in the specified linear range. 131 | * 132 | * @see {@link https://docs.screeps.com/api/#RoomPosition.findInRange} 133 | * 134 | * @type {function} 135 | * 136 | * @param {number|Array|Array} type See Room.find. 137 | * @param {number} range The range distance. 138 | * @param {object} [opts] See Room.find. 139 | * 140 | * @note Alternative function: findInRange(objects, range, opts) 141 | * @param {array} objects An array of room's objects or RoomPosition objects that the search should be executed against. 142 | * 143 | * @return {array} An array with the objects found. 144 | */ 145 | findInRange: function(type, range, opts) { }, 146 | 147 | /** 148 | * Find an optimal path to the specified position using A* search algorithm. 149 | * This method is a shorthand for Room.findPath. 150 | * If the target is in another room, then the corresponding exit will be used as a target. 151 | * 152 | * @see {@link https://docs.screeps.com/api/#RoomPosition.findPathTo} 153 | * 154 | * @type {function} 155 | * 156 | * @param {number|RoomPosition|RoomObject} x X position in the room. 157 | * @param {number} [y] Y position in the room. 158 | * @param {object} [opts] An object containing pathfinding options flags (see Room.findPath for more details). 159 | * @param {boolean} [opts.ignoreCreeps] Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default value is false. 160 | * @param {boolean} [opts.ignoreDestructibleStructures] Treat squares with destructible structures (constructed walls, ramparts, spawns, extensions) as walkable. Use this flag when you need to move through a territory blocked by hostile structures. If a creep with an ATTACK body part steps on such a square, it automatically attacks the structure. The default value is false. 161 | * @param {boolean} [opts.ignoreRoads] Ignore road structures. Enabling this option can speed up the search. The default value is false. This is only used when the new PathFinder is enabled. 162 | * @param {function(string, CostMatrix)} [opts.costCallback] You can use this callback to modify a CostMatrix for any room during the search. The callback accepts two arguments, roomName and costMatrix. Use the costMatrix instance to make changes to the positions costs. If you return a new matrix from this callback, it will be used instead of the built-in cached one. This option is only used when the new PathFinder is enabled. 163 | * @param {Array} [opts.ignore] An array of the room's objects or RoomPosition objects which should be treated as walkable tiles during the search. This option cannot be used when the new PathFinder is enabled (use costCallback option instead). 164 | * @param {Array} [opts.avoid] An array of the room's objects or RoomPosition objects which should be treated as obstacles during the search. This option cannot be used when the new PathFinder is enabled (use costCallback option instead). 165 | * @param {number} [opts.maxOps] The maximum limit of possible pathfinding operations. You can limit CPU time used for the search based on ratio 1 op ~ 0.001 CPU. The default value is 2000. 166 | * @param {number} [opts.heuristicWeight] Weight to apply to the heuristic in the A* formula F = G + weight * H. Use this option only if you understand the underlying A* algorithm mechanics! The default value is 1.2. 167 | * @param {boolean} [opts.serialize] If true, the result path will be serialized using Room.serializePath. The default is false. 168 | * @param {number} [opts.maxRooms] The maximum allowed rooms to search. The default (and maximum) is 16. This is only used when the new PathFinder is enabled. 169 | * @param {number} [opts.range] Find a path to a position in specified linear range of target. The default is 0. 170 | * @param {number} [opts.plainCost] Cost for walking on plain positions. The default is 1. 171 | * @param {number} [opts.swampCost] Cost for walking on swamp positions. The default is 5. 172 | * 173 | * @note Alternative function: findPathTo(target, opts) 174 | * @param {object} target Can be a RoomPosition object or any object containing RoomPosition. 175 | * 176 | * @return {array} An array with path steps in the following format: 177 | [ 178 | { x: 10, y: 5, dx: 1, dy: 0, direction: RIGHT }, 179 | { x: 10, y: 6, dx: 0, dy: 1, direction: BOTTOM }, 180 | { x: 9, y: 7, dx: -1, dy: 1, direction: BOTTOM_LEFT }, 181 | ... 182 | ] 183 | */ 184 | findPathTo: function(x, y, opts) { }, 185 | 186 | /** 187 | * Get linear direction to the specified position. 188 | * 189 | * @see {@link https://docs.screeps.com/api/#RoomPosition.getDirectionTo} 190 | * 191 | * @type {function} 192 | * 193 | * @param {number|RoomPosition|RoomObject} x X position in the room. 194 | * @param {number} [y] Y position in the room. 195 | * 196 | * @note Alternative function: getDirectionTo(target) 197 | * @param {object} target Can be a RoomPosition object or any object containing RoomPosition. 198 | * 199 | * @return {number|TOP|TOP_RIGHT|RIGHT|BOTTOM_RIGHT|BOTTOM|BOTTOM_LEFT|LEFT|TOP_LEFT} A number representing one of the direction constants. 200 | */ 201 | getDirectionTo: function(x, y) { }, 202 | 203 | /** 204 | * Get linear range to the specified position. 205 | * 206 | * @see {@link https://docs.screeps.com/api/#RoomPosition.getRangeTo} 207 | * 208 | * @type {function} 209 | * 210 | * @param {number|RoomPosition|RoomObject} x X position in the room. 211 | * @param {number} [y] Y position in the room. 212 | * 213 | * @note Alternative function: getRangeTo(target) 214 | * @param {object} target Can be a RoomPosition object or any object containing RoomPosition. 215 | * 216 | * @return {number} A number of squares to the given position. 217 | */ 218 | getRangeTo: function(x, y) { }, 219 | 220 | /** 221 | * Check whether this position is in the given range of another position. 222 | * 223 | * @see {@link https://docs.screeps.com/api/#RoomPosition.inRangeTo} 224 | * 225 | * @type {function} 226 | * 227 | * @param {number|RoomPosition|RoomObject} x X position in the room. 228 | * @param {number} [y] Y position in the room. 229 | * @param {number} range The range distance. 230 | * 231 | * 232 | * @note Alternative function: inRangeTo(target, range) 233 | * @param {RoomPosition} target The target position. 234 | * 235 | * @return {boolean} 236 | */ 237 | inRangeTo: function(x, y, range) { }, 238 | 239 | /** 240 | * Check whether this position is the same as the specified position. 241 | * 242 | * @see {@link https://docs.screeps.com/api/#RoomPosition.isEqualTo} 243 | * 244 | * @type {function} 245 | * 246 | * @param {number|RoomPosition|RoomObject} x X position in the room. 247 | * @param {number} [y] Y position in the room. 248 | * 249 | * @note Alternative function: isEqualTo(target) 250 | * @param {object} target Can be a RoomPosition object or any object containing RoomPosition. 251 | * 252 | * @return {boolean} 253 | */ 254 | isEqualTo: function(x, y) { }, 255 | 256 | /** 257 | * Check whether this position is on the adjacent square to the specified position. 258 | * The same as inRangeTo(target, 1) 259 | * 260 | * @see {@link https://docs.screeps.com/api/#RoomPosition.isNearTo} 261 | * 262 | * @type {function} 263 | * 264 | * @param {number|RoomPosition|RoomObject} x X position in the room. 265 | * @param {number} [y] Y position in the room. 266 | * 267 | * @note Alternative function: isNearTo(target) 268 | * @param {object} target Can be a RoomPosition object or any object containing RoomPosition. 269 | * 270 | * @return {boolean} 271 | */ 272 | isNearTo: function(x, y) { }, 273 | 274 | /** 275 | * Get the list of objects at the specified room position. 276 | * 277 | * @see {@link https://docs.screeps.com/api/#RoomPosition.look} 278 | * 279 | * @type {function} 280 | * 281 | * @return {Array} An array with objects at the specified position in the following format: 282 | [ 283 | { type: 'creep', creep: {...} }, 284 | { type: 'structure', structure: {...} }, 285 | ... 286 | { type: 'terrain', terrain: 'swamp' } 287 | ] 288 | */ 289 | look: function() { }, 290 | 291 | /** 292 | * Get an object with the given type at the specified room position. 293 | * 294 | * @see {@link https://docs.screeps.com/api/#RoomPosition.lookFor} 295 | * 296 | * @type {function} 297 | * 298 | * @param {string} type One of the LOOK_* constants. 299 | * 300 | * @return {array} An array of objects of the given type at the specified position if found. 301 | */ 302 | lookFor: function(type) { } 303 | }; 304 | 305 | /** 306 | * @typedef {Object} LookResultItem 307 | * @property {'creep' | 'structure' | 'terrain'} type 308 | * @property {Creep} [creep] 309 | * @property {Structure} [structure] 310 | * @property {string} [terrain] 311 | */ 312 | -------------------------------------------------------------------------------- /RoomVisual.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Room visuals provide a way to show various visual debug info in game rooms. 3 | * You can use the RoomVisual object to draw simple shapes that are visible only to you. 4 | * Every existing Room object already contains the visual property, but you also can create new RoomVisual objects for any room (even without visibility) using the constructor. 5 | * 6 | * Room visuals are not stored in the database, their only purpose is to display something in your browser. 7 | * All drawings will persist for one tick and will disappear if not updated. 8 | * All RoomVisual API calls have no added CPU cost (their cost is natural and mostly related to simple JSON.serialize calls). 9 | * However, there is a usage limit: you cannot post more than 500 KB of serialized data per one room (see getSize method). 10 | * 11 | * All draw coordinates are measured in game coordinates and centered to tile centers, i.e. (10,10) will point to the center of the creep at x:10; y:10 position. 12 | * Fractional coordinates are allowed. 13 | * 14 | * @param {string} [roomName] The room name. If undefined, visuals will be posted to all rooms simultaneously. 15 | * 16 | * @class 17 | * @constructor 18 | * 19 | * @see {@link https://docs.screeps.com/api/#RoomVisual} 20 | */ 21 | RoomVisual = function(roomName) { }; 22 | 23 | RoomVisual.prototype = 24 | { 25 | /** 26 | * The name of the room. 27 | * 28 | * @see {@link https://docs.screeps.com/api/#RoomVisual.roomName} 29 | * 30 | * @type {string} 31 | */ 32 | roomName: "", 33 | 34 | /** 35 | * Draw a line. 36 | * 37 | * @see {@link https://docs.screeps.com/api/#RoomVisual.line} 38 | * 39 | * @type {function} 40 | * 41 | * @param {number} x1 The start X coordinate. 42 | * @param {number} y1 The start Y coordinate. 43 | * @param {number} x2 The finish X coordinate. 44 | * @param {number} y2 The finish Y coordinate. 45 | * @param {Object} [style] Style object 46 | * 47 | * @return {RoomVisual} The RoomVisual object itself, so that you can chain calls. 48 | */ 49 | line: function(x1, y1, x2, y2, style) { }, 50 | 51 | /** 52 | * Draw a circle. 53 | * 54 | * @see {@link https://docs.screeps.com/api/#RoomVisual.circle} 55 | * 56 | * @type {function} 57 | * 58 | * @param {number|RoomPosition} x The X coordinate of the center. 59 | * @param {number} [y] The Y coordinate of the center. 60 | * @param {Object} [style] Style object 61 | * 62 | * @alias circle(pos, [style]) 63 | * 64 | * @return {RoomVisual} The RoomVisual object itself, so that you can chain calls. 65 | */ 66 | circle: function(x, y, style) { }, 67 | 68 | /** 69 | * Draw a rectangle. 70 | * 71 | * @see {@link https://docs.screeps.com/api/#RoomVisual.rect} 72 | * 73 | * @type {function} 74 | * 75 | * @param {number} x The X coordinate of the top-left corner. 76 | * @param {number} y The Y coordinate of the top-left corner. 77 | * @param {number} width The width of the rectangle. 78 | * @param {number} height The height of the rectangle. 79 | * @param {object} [style] Style object 80 | * 81 | * @alias rect(topLeftPos, width, height, [style]) 82 | * 83 | * @return {RoomVisual} The RoomVisual object itself, so that you can chain calls. 84 | */ 85 | rect: function(x, y, width, height, style) { }, 86 | 87 | /** 88 | * Draw a polyline. 89 | * 90 | * @see {@link https://docs.screeps.com/api/#RoomVisual.poly} 91 | * 92 | * @type {function} 93 | * 94 | * @param {Array>|Array} points An array of points. Every item should be either an array with 2 numbers (i.e. [10,15]), or a RoomPosition object. 95 | * @param {Object} [style] Style object 96 | * 97 | * @return {RoomVisual} The RoomVisual object itself, so that you can chain calls. 98 | */ 99 | poly: function(points, style) { }, 100 | 101 | /** 102 | * Draw a text label. You can use any valid Unicode characters, including emoji. 103 | * 104 | * @see {@link https://docs.screeps.com/api/#RoomVisual.text} 105 | * 106 | * @type {function} 107 | * 108 | * @param {string} text The text message. 109 | * @param {number} x The X coordinate of the label baseline point. 110 | * @param {number} y The Y coordinate of the label baseline point. 111 | * @param {object} [style] Style object 112 | * 113 | * @alias text(text, pos, [style]) 114 | * 115 | * @return {RoomVisual} The RoomVisual object itself, so that you can chain calls. 116 | */ 117 | text: function(text, x, y, style) { }, 118 | 119 | /** 120 | * Remove all visuals from the room. 121 | * 122 | * @see {@link https://docs.screeps.com/api/#RoomVisual.clear} 123 | * 124 | * @type {function} 125 | * 126 | * @return {RoomVisual} The RoomVisual object itself, so that you can chain calls. 127 | */ 128 | clear: function() { }, 129 | 130 | /** 131 | * Get the stored size of all visuals added in the room in the current tick. It must not exceed 512,000 (500 KB). 132 | * 133 | * @see {@link https://docs.screeps.com/api/#RoomVisual.getSize} 134 | * 135 | * @type {function} 136 | * 137 | * @return {number} The size of the visuals in bytes. 138 | */ 139 | getSize: function() { }, 140 | 141 | /** 142 | * Returns a compact representation of all visuals added in the room in the current tick. 143 | * 144 | * @see {@link https://docs.screeps.com/api/#RoomVisual.export} 145 | * 146 | * @type {function} 147 | * 148 | * @return {string} A string with visuals data. There's not much you can do with the string besides store them for later. 149 | */ 150 | export: function() { }, 151 | 152 | /** 153 | * Add previously exported (with RoomVisual.export) room visuals to the room visual data of the current tick. 154 | * 155 | * @see {@link https://docs.screeps.com/api/#RoomVisual.import} 156 | * 157 | * @type {function} 158 | * 159 | * @param {string} val The string returned from RoomVisual.export. 160 | * @return {RoomVisual} The RoomVisual object itself, so that you can chain calls. 161 | */ 162 | import: function(val) { } 163 | }; 164 | -------------------------------------------------------------------------------- /Ruin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A destroyed structure. This is a walkable object. 3 | * 4 | * @class 5 | * @extends {RoomObject} 6 | * 7 | * @see {@link https://docs.screeps.com/api/#Ruin} 8 | */ 9 | Ruin = function () { 10 | }; 11 | 12 | Ruin.prototype = { 13 | 14 | /** 15 | * The time when the structure has been destroyed. 16 | * 17 | * @see {@link https://docs.screeps.com/api/#Ruin.destroyTime} 18 | * 19 | * @type {number} 20 | */ 21 | destroyTime: 0, 22 | 23 | /** 24 | * A unique object identificator. You can use {@link Game.getObjectById()} method to retrieve an object instance by its id. 25 | * 26 | * @see {@link https://docs.screeps.com/api/#Ruin.id} 27 | * 28 | * @type {string} 29 | */ 30 | id: "", 31 | 32 | /** 33 | * A Store object that contains resources of this structure. 34 | * 35 | * @see {@link https://docs.screeps.com/api/#Ruin.store} 36 | * 37 | * @type {Store} 38 | */ 39 | store: {}, 40 | 41 | /** 42 | * An object containing basic data of the destroyed structure. 43 | * 44 | * @see {@link https://docs.screeps.com/api/#Ruin.structure} 45 | * 46 | * @type {Structure|OwnedStructure} 47 | */ 48 | structure: {}, 49 | 50 | /** 51 | * The amount of game ticks before this ruin decays. 52 | * 53 | * @see {@link https://docs.screeps.com/api/#Ruin.ticksToDecay} 54 | * 55 | * @type {number} 56 | */ 57 | ticksToDecay: 0 58 | }; 59 | -------------------------------------------------------------------------------- /Source.js: -------------------------------------------------------------------------------- 1 | /** 2 | * An energy source object. 3 | * Can be harvested by creeps with a WORK body part. 4 | * 5 | * @class 6 | * @extends {RoomObject} 7 | * 8 | * @see {@link https://docs.screeps.com/api/#Source} 9 | */ 10 | Source = function() { }; 11 | 12 | Source.prototype = 13 | { 14 | /** 15 | * The remaining amount of energy. 16 | * 17 | * @see {@link https://docs.screeps.com/api/#Source.energy} 18 | * 19 | * @type {number} 20 | */ 21 | energy: 0, 22 | 23 | /** 24 | * The total amount of energy in the source. 25 | * 26 | * @see {@link https://docs.screeps.com/api/#Source.energyCapacity} 27 | * 28 | * @type {number} 29 | */ 30 | energyCapacity: 0, 31 | 32 | /** 33 | * A unique object identificator. 34 | * You can use Game.getObjectById method to retrieve an object instance by its id. 35 | * 36 | * @see {@link https://docs.screeps.com/api/#Source.id} 37 | * 38 | * @type {string} 39 | */ 40 | id: "", 41 | 42 | /** 43 | * The remaining time after which the source will be refilled. 44 | * 45 | * @see {@link https://docs.screeps.com/api/#Source.ticksToRegeneration} 46 | * 47 | * @type {number} 48 | */ 49 | ticksToRegeneration: 0 50 | }; 51 | -------------------------------------------------------------------------------- /Store.js: -------------------------------------------------------------------------------- 1 | /** 2 | * An object that can contain resources in its cargo. 3 | * There are two types of stores in the game: general purpose stores and limited stores. 4 | * 5 | * - General purpose stores can contain any resource within its capacity (e.g. creeps, containers, storages, terminals). 6 | * - Limited stores can contain only a few types of resources needed for that particular object (e.g. spawns, extensions, labs, nukers). 7 | * 8 | * The Store prototype is the same for both types of stores, but they have different behavior depending on the resource argument in its methods. 9 | * You can get specific resources from the store by addressing them as object properties: 10 | * console.log(creep.store[RESOURCE_ENERGY]); 11 | * 12 | * @class 13 | * 14 | * @see {@link https://docs.screeps.com/api/#Store} 15 | */ 16 | Store = function() { }; 17 | 18 | Store.prototype = 19 | { 20 | /** 21 | * Returns capacity of this store for the specified resource. 22 | * For a general purpose store, it returns total capacity if resource is undefined. 23 | * 24 | * @see {@link https://docs.screeps.com/api/#Store.getCapacity} 25 | * 26 | * @type {function} 27 | * 28 | * @param {string} [resource] The type of the resource. One of the RESOURCE_* constants. 29 | * 30 | * @return {number|null} Returns capacity number, or null in case of an invalid resource for this store type. 31 | */ 32 | getCapacity: function(resource) { }, 33 | 34 | /** 35 | * Returns free capacity for the store. 36 | * For a limited store, it returns the capacity available for the specified resource if resource is defined and valid for this store. 37 | * 38 | * @see {@link https://docs.screeps.com/api/#Store.getFreeCapacity} 39 | * 40 | * @type {function} 41 | * 42 | * @param {string} [resource] The type of the resource. One of the RESOURCE_* constants. 43 | * 44 | * @return {number|null} Returns available capacity number, or null in case of an invalid resource for this store type. 45 | */ 46 | getFreeCapacity: function(resource) { }, 47 | 48 | /** 49 | * Returns the capacity used by the specified resource. 50 | * For a general purpose store, it returns total used capacity if resource is undefined. 51 | * 52 | * @see {@link https://docs.screeps.com/api/#Store.getUsedCapacity} 53 | * 54 | * @type {function} 55 | * 56 | * @param {string} [resource] The type of the resource. One of the RESOURCE_* constants. 57 | * 58 | * @return {number|null} Returns used capacity number, or null in case of a not valid resource for this store type. 59 | */ 60 | getUsedCapacity: function(resource) { } 61 | }; 62 | -------------------------------------------------------------------------------- /Structure.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base prototype object of all structures. 3 | * @class 4 | * @extends {RoomObject} 5 | * 6 | * @see {@link https://docs.screeps.com/api/#Structure} 7 | */ 8 | Structure = function() { }; 9 | 10 | Structure.prototype = 11 | { 12 | /** 13 | * The current amount of hit points of the structure. 14 | * 15 | * @see {@link https://docs.screeps.com/api/#Structure.hits} 16 | * 17 | * @type {number} 18 | */ 19 | hits: 0, 20 | 21 | /** 22 | * The total amount of hit points of the structure. 23 | * 24 | * @see {@link https://docs.screeps.com/api/#Structure.hitsMax} 25 | * 26 | * @type {number} 27 | */ 28 | hitsMax: 0, 29 | 30 | /** 31 | * A unique object identificator. 32 | * You can use Game.getObjectById method to retrieve an object instance by its id. 33 | * 34 | * @see {@link https://docs.screeps.com/api/#Structure.id} 35 | * 36 | * @type {string} 37 | */ 38 | id: "", 39 | 40 | /** 41 | * One of the STRUCTURE_* constants. 42 | * 43 | * @see {@link https://docs.screeps.com/api/#Structure.structureType} 44 | * 45 | * @type {string} 46 | */ 47 | structureType: "", 48 | 49 | /** 50 | * Destroy this structure immediately. 51 | * 52 | * @see {@link https://docs.screeps.com/api/#Structure.destroy} 53 | * 54 | * @type {function} 55 | * 56 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY} 57 | */ 58 | destroy: function() { }, 59 | 60 | /** 61 | * Check whether this structure can be used. 62 | * If room controller level is insufficient, 63 | * then this method will return false, and the structure will be highlighted with red in the game. 64 | * 65 | * @see {@link https://docs.screeps.com/api/#Structure.isActive} 66 | * 67 | * @type {function} 68 | * 69 | * @return {boolean} 70 | */ 71 | isActive: function() { }, 72 | 73 | /** 74 | * Toggle auto notification when the structure is under attack. 75 | * The notification will be sent to your account email. 76 | * Turned on by default. 77 | * 78 | * @see {@link https://docs.screeps.com/api/#Structure.notifyWhenAttacked} 79 | * 80 | * @type {function} 81 | * 82 | * @param {boolean} enabled Whether to enable notification or disable. 83 | * 84 | * @return {number|OK|ERR_NOT_OWNER|ERR_INVALID_ARGS} 85 | */ 86 | notifyWhenAttacked: function(enabled) { } 87 | }; 88 | -------------------------------------------------------------------------------- /Structures/StructureContainer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A small container that can be used to store resources. 3 | * This is a walkable structure. 4 | * All dropped resources automatically goes to the container at the same tile. 5 | * 6 | * @class 7 | * @extends {Structure} 8 | * 9 | * @see {@link https://docs.screeps.com/api/#StructureContainer} 10 | */ 11 | StructureContainer = function() { }; 12 | 13 | StructureContainer.prototype = 14 | { 15 | 16 | /** 17 | * A Store object that contains cargo of this structure. 18 | * 19 | * @see {@link https://docs.screeps.com/api/#StructureContainer.store} 20 | * 21 | * @type {Store} 22 | */ 23 | store: {}, 24 | 25 | /** 26 | * @deprecated Since version 4.x, replaced by `.store.getCapacity()`. 27 | * 28 | * The total amount of resources the structure can contain. 29 | * 30 | * @see {@link https://docs.screeps.com/api/#StructureContainer.storeCapacity} 31 | * 32 | * @type {number} 33 | */ 34 | storeCapacity: 0, 35 | 36 | /** 37 | * The amount of game ticks when this container will lose some hit points. 38 | * 39 | * @see {@link https://docs.screeps.com/api/#StructureContainer.ticksToDecay} 40 | * 41 | * @type {number} 42 | */ 43 | ticksToDecay: 0 44 | }; 45 | -------------------------------------------------------------------------------- /Structures/StructureController.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Claim this structure to take control over the room. 3 | * The controller structure cannot be damaged or destroyed. 4 | * It can be addressed by Room.controller property. 5 | * 6 | * @class 7 | * @extends {OwnedStructure} 8 | * 9 | * @see {@link https://docs.screeps.com/api/#StructureController} 10 | */ 11 | StructureController = function() { }; 12 | 13 | StructureController.prototype = 14 | { 15 | 16 | /** 17 | * During this period in ticks new safe mode activations will be blocked, undefined if cooldown is inactive. 18 | * 19 | * @see {@link https://docs.screeps.com/api/#StructureController.safeModeCooldown} 20 | * 21 | * @type {number} 22 | */ 23 | safeModeCooldown: 0, 24 | 25 | /** 26 | * Safe mode activations available to use. 27 | * 28 | * @see {@link https://docs.screeps.com/api/#StructureController.safeModeAvailable} 29 | * 30 | * @type {number} 31 | */ 32 | safeModeAvailable: 0, 33 | 34 | /** 35 | * How many ticks of safe mode remaining, or undefined. 36 | * 37 | * @see {@link https://docs.screeps.com/api/#StructureController.safeMode} 38 | * 39 | * @type {number|undefined} 40 | */ 41 | safeMode: 0, 42 | 43 | /** 44 | * Activate safe mode if available. 45 | * 46 | * @see {@link https://docs.screeps.com/api/#StructureController.activateSafeMode} 47 | * 48 | * @type {function} 49 | * 50 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_TIRED} 51 | */ 52 | activateSafeMode: function() {}, 53 | 54 | /** 55 | * Whether using power is enabled in this room. Use PowerCreep.enableRoom to turn powers on. 56 | * 57 | * @see {@link https://docs.screeps.com/api/#StructureController.isPowerEnabled} 58 | * 59 | * @type {boolean} 60 | */ 61 | isPowerEnabled: false, 62 | 63 | /** 64 | * Current controller level, from 0 to 8. 65 | * 66 | * @see {@link https://docs.screeps.com/api/#StructureController.level} 67 | * 68 | * @type {number} 69 | */ 70 | level: 0, 71 | 72 | /** 73 | * The current progress of upgrading the controller to the next level. 74 | * 75 | * @see {@link https://docs.screeps.com/api/#StructureController.progress} 76 | * 77 | * @type {number} 78 | */ 79 | progress: 0, 80 | 81 | /** 82 | * The progress needed to reach the next level. 83 | * 84 | * @see {@link https://docs.screeps.com/api/#StructureController.progressTotal} 85 | * 86 | * @type {number} 87 | */ 88 | progressTotal: 0, 89 | 90 | /** 91 | * An object with the controller reservation info if present 92 | * 93 | * @see {@link https://docs.screeps.com/api/#StructureController.reservation} 94 | * 95 | * @type {null|object} 96 | */ 97 | reservation: { 98 | 99 | /** 100 | * The name of a player who reserved this controller. 101 | * 102 | * @type {string} 103 | */ 104 | username: "", 105 | 106 | /** 107 | * The amount of game ticks when the reservation will end. 108 | * 109 | * @type {number} 110 | */ 111 | ticksToEnd: 0 112 | }, 113 | 114 | /** 115 | * An object with the controller sign info 116 | * 117 | * @see {@link https://docs.screeps.com/api/#StructureController.sign} 118 | * 119 | * @type {object|undefined} 120 | */ 121 | sign: { 122 | /** 123 | * The name of a player who signed this controller. 124 | * 125 | * @type {string} 126 | */ 127 | username: "", 128 | 129 | /** 130 | * The sign text. 131 | * 132 | * @type {string} 133 | */ 134 | text: "", 135 | 136 | /** 137 | * The sign time in game ticks. 138 | * 139 | * @type {number} 140 | */ 141 | time: 0, 142 | 143 | /** 144 | * The sign real date. 145 | * 146 | * @type {Date} 147 | */ 148 | datetime: "" 149 | }, 150 | 151 | /** 152 | * The amount of game ticks when this controller will lose one level. 153 | * This timer is set to 50% on level upgrade or downgrade, and it can be increased by using Creep.upgradeController. Must be full to upgrade the controller to the next level. 154 | * 155 | * @see {@link https://docs.screeps.com/api/#StructureController.ticksToDowngrade} 156 | * 157 | * @type {number} 158 | */ 159 | ticksToDowngrade: 0, 160 | 161 | /** 162 | * The amount of game ticks while this controller cannot be upgraded due to attack. 163 | * Safe mode is also unavailable during this period. 164 | * 165 | * @see {@link https://docs.screeps.com/api/#StructureController.upgradeBlocked} 166 | * 167 | * @type {number} 168 | */ 169 | upgradeBlocked: 0, 170 | 171 | /** 172 | * Make your claimed controller neutral again. 173 | * 174 | * @see {@link https://docs.screeps.com/api/#StructureController.unclaim} 175 | * 176 | * @type {function} 177 | * 178 | * @return {number|OK|ERR_NOT_OWNER} 179 | */ 180 | unclaim: function() { } 181 | }; 182 | -------------------------------------------------------------------------------- /Structures/StructureExtension.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains energy which can be spent on spawning bigger creeps. 3 | * Extensions can be placed anywhere in the room, any spawns will be able to use them regardless of distance. 4 | * 5 | * @class 6 | * @extends {OwnedStructure} 7 | * 8 | * @see {@link https://docs.screeps.com/api/#StructureExtension} 9 | */ 10 | StructureExtension = function() { }; 11 | 12 | StructureExtension.prototype = 13 | { 14 | /** 15 | * @deprecated Since version 4.x, replaced by `.store[RESOURCE_ENERGY]`. 16 | * 17 | * The amount of energy containing in the extension. 18 | * 19 | * @see {@link https://docs.screeps.com/api/#StructureExtension.energy} 20 | * 21 | * @type {number} 22 | */ 23 | energy: 0, 24 | 25 | /** 26 | * @deprecated Since version 4.x, replaced by `.store.getCapacity(RESOURCE_ENERGY)`. 27 | * 28 | * The total amount of energy the extension can contain. 29 | * 30 | * @see {@link https://docs.screeps.com/api/#StructureExtension.energyCapacity} 31 | * 32 | * @type {number} 33 | */ 34 | energyCapacity: 0, 35 | 36 | /** 37 | * A Store object that contains cargo of this structure. 38 | * 39 | * @see {@link https://docs.screeps.com/api/#StructureExtension.store} 40 | * 41 | * @type {Store} 42 | */ 43 | store: {} 44 | 45 | }; 46 | -------------------------------------------------------------------------------- /Structures/StructureExtractor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Allows to harvest a mineral deposit. 3 | * 4 | * @class 5 | * @extends {OwnedStructure} 6 | * 7 | * @see {@link https://docs.screeps.com/api/#StructureExtractor} 8 | */ 9 | StructureExtractor = function() { }; 10 | 11 | StructureExtractor.prototype = 12 | { 13 | /** 14 | * The amount of game ticks until the next harvest action is possible. 15 | * 16 | * @see {@link https://docs.screeps.com/api/#StructureExtractor.cooldown} 17 | * 18 | * @type {number} 19 | */ 20 | cooldown: 0 21 | }; 22 | -------------------------------------------------------------------------------- /Structures/StructureFactory.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Produces trade commodities from base minerals and other commodities. 3 | * 4 | * @class 5 | * @extends {OwnedStructure} 6 | * 7 | * @see {@link https://docs.screeps.com/api/#StructureFactory} 8 | */ 9 | StructureFactory = function () { 10 | }; 11 | 12 | StructureFactory.prototype = { 13 | /** 14 | * The amount of game ticks the factory has to wait until the next production is possible. 15 | * 16 | * @see {@link https://docs.screeps.com/api/#StructureFactory.cooldown} 17 | * 18 | * @type {number} 19 | */ 20 | cooldown: 0, 21 | 22 | /** 23 | * The factory's level. Can be set by applying the PWR_OPERATE_FACTORY power to a newly built factory. Once set, 24 | * the level cannot be changed. 25 | * 26 | * @see {@link https://docs.screeps.com/api/#StructureFactory.level} 27 | * 28 | * @type {number} 29 | */ 30 | level: 0, 31 | 32 | /** 33 | * A Store object that contains cargo of this structure. 34 | * 35 | * @see {@link https://docs.screeps.com/api/#StructureFactory.store} 36 | * 37 | * @type {Store} 38 | */ 39 | store: {}, 40 | 41 | /** 42 | * @deprecated An alias for .store.getCapacity(). 43 | * 44 | * @see {@link https://docs.screeps.com/api/#StructureFactory.storeCapacity} 45 | * 46 | * @type {number} 47 | */ 48 | storeCapacity: 0, 49 | 50 | /** 51 | * Produces the specified commodity. All ingredients should be available in the factory store. 52 | * 53 | * @see {@link https://docs.screeps.com/api/#StructureFactory.produce} 54 | * 55 | * @type {function} 56 | * 57 | * @param {string} resourceType One of the RESOURCE_* constants. 58 | * 59 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_INVALID_ARGS|ERR_TIRED|ERR_RCL_NOT_ENOUGH} 60 | */ 61 | produce: function (resourceType) { } 62 | }; 63 | -------------------------------------------------------------------------------- /Structures/StructureInvaderCore.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This NPC structure is a control center of NPC Strongholds, and also rules all invaders in the sector. It spawns NPC 3 | * defenders of the stronghold, refill towers, repairs structures. While it's alive, it will spawn invaders in all rooms 4 | * in the same sector. It also contains some valuable resources inside, which you can loot from its ruin if you destroy 5 | * the structure. 6 | * 7 | * @class 8 | * @extends {OwnedStructure} 9 | * 10 | * @see {@link https://docs.screeps.com/api/#StructureInvaderCore} 11 | */ 12 | StructureInvaderCore = function () { 13 | }; 14 | 15 | StructureInvaderCore.prototype = { 16 | 17 | /** 18 | * The level of the stronghold. The amount and quality of the loot depends on the level. 19 | * 20 | * @see {@link https://docs.screeps.com/api/#StructureInvaderCore.level} 21 | * 22 | * @return {number} 23 | */ 24 | level: 0, 25 | 26 | /** 27 | * Shows the timer for a not yet deployed stronghold, undefined otherwise. 28 | * 29 | * @see {@link https://docs.screeps.com/api/#StructureInvaderCore.ticksToDeploy} 30 | * 31 | * @return {number|undefined} 32 | */ 33 | ticksToDeploy: 0, 34 | 35 | /** 36 | * If the core is in process of spawning a new creep, this object will contain a StructureSpawn.Spawning object, or null otherwise. 37 | * 38 | * @see {@link https://docs.screeps.com/api/#StructureInvaderCore.spawning} 39 | * 40 | * @type {object|null} 41 | */ 42 | spawning: null 43 | }; 44 | -------------------------------------------------------------------------------- /Structures/StructureKeeperLair.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Non-player structure. 3 | * Spawns NPC Source Keepers that guards energy sources and minerals in some rooms. 4 | * This structure cannot be destroyed. 5 | * 6 | * @class 7 | * @extends {OwnedStructure} 8 | * 9 | * @see {@link https://docs.screeps.com/api/#StructureKeeperLair} 10 | */ 11 | StructureKeeperLair = function() { }; 12 | 13 | StructureKeeperLair.prototype = 14 | { 15 | /** 16 | * Time to spawning of the next Source Keeper. 17 | * 18 | * @see {@link https://docs.screeps.com/api/#StructureKeeperLair.ticksToSpawn} 19 | * 20 | * @type {number} 21 | */ 22 | ticksToSpawn: 0 23 | }; 24 | -------------------------------------------------------------------------------- /Structures/StructureLab.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Produces mineral compounds from base minerals, boosts and unboosts creeps. 3 | * 4 | * @class 5 | * @extends {OwnedStructure} 6 | * 7 | * @see {@link https://docs.screeps.com/api/#StructureLab} 8 | */ 9 | StructureLab = function() { }; 10 | 11 | StructureLab.prototype = 12 | { 13 | /** 14 | * The amount of game ticks the lab has to wait until the next reaction is possible. 15 | * 16 | * @see {@link https://docs.screeps.com/api/#StructureLab.cooldown} 17 | * 18 | * @type {number} 19 | */ 20 | cooldown: 0, 21 | 22 | /** 23 | * @deprecated Since version 4.x, replaced by `.store[RESOURCE_ENERGY]`. 24 | * 25 | * The amount of energy containing in the lab. Energy is used for boosting creeps. 26 | * 27 | * @see {@link https://docs.screeps.com/api/#StructureLab.energy} 28 | * 29 | * @type {number} 30 | */ 31 | energy: 0, 32 | 33 | /** 34 | * @deprecated Since version 4.x, replaced by `.store.getCapacity(RESOURCE_ENERGY)`. 35 | * 36 | * The total amount of energy the lab can contain. 37 | * 38 | * @see {@link https://docs.screeps.com/api/#StructureLab.energyCapacity} 39 | * 40 | * @type {number} 41 | */ 42 | energyCapacity: 0, 43 | 44 | /** 45 | * @deprecated Since version 4.x, replaced by `lab.store[lab.mineralType]`. 46 | * 47 | * The amount of mineral resources containing in the lab. 48 | * 49 | * @see {@link https://docs.screeps.com/api/#StructureLab.mineralAmount} 50 | * 51 | * @type {number} 52 | */ 53 | mineralAmount: 0, 54 | 55 | /** 56 | * The type of minerals containing in the lab. 57 | * Labs can contain only one mineral type at the same time. 58 | * 59 | * @see {@link https://docs.screeps.com/api/#StructureLab.mineralType} 60 | * 61 | * @type {string} 62 | */ 63 | mineralType: "", 64 | 65 | /** 66 | * @deprecated Since version 4.x, replaced by `lab.store.getCapacity(lab.mineralType || yourMineral)`. 67 | * 68 | * The total amount of minerals the lab can contain. 69 | * 70 | * @see {@link https://docs.screeps.com/api/#StructureLab.mineralCapacity} 71 | * 72 | * @type {number} 73 | */ 74 | mineralCapacity: 0, 75 | 76 | /** 77 | * A Store object that contains cargo of this structure. 78 | * 79 | * @see {@link https://docs.screeps.com/api/#StructureLab.store} 80 | * 81 | * @type {Store} 82 | */ 83 | store: {}, 84 | 85 | /** 86 | * Boosts creep body parts using the containing mineral compound. 87 | * The creep has to be at adjacent square to the lab. 88 | * 89 | * @see {@link https://docs.screeps.com/api/#StructureLab.boostCreep} 90 | * 91 | * @type {function} 92 | * 93 | * @param {Creep} creep The target creep. 94 | * @param {number|undefined|null} [bodyPartsCount] The number of body parts of the corresponding type to be boosted. Body parts are always counted left-to-right for TOUGH, and right-to-left for other types. If undefined, all the eligible body parts are boosted. 95 | * 96 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_FOUND|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_RCL_NOT_ENOUGH} 97 | */ 98 | boostCreep: function(creep, bodyPartsCount) { }, 99 | 100 | /** 101 | * Breaks mineral compounds back into reagents. 102 | * The same output labs can be used by many source labs. 103 | * 104 | * @see {@link https://docs.screeps.com/api/#StructureLab.reverseReaction} 105 | * 106 | * @type {function} 107 | * 108 | * @param {StructureLab} lab1 The first result lab. 109 | * @param {StructureLab} lab2 The second result lab. 110 | * 111 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS|ERR_TIRED|ERR_RCL_NOT_ENOUGH} 112 | */ 113 | reverseReaction: function(lab1, lab2) { }, 114 | 115 | /** 116 | * Immediately remove boosts from the creep and drop 50% of the mineral compounds used to boost it onto the ground regardless of the creep's remaining time to live. 117 | * The creep has to be at adjacent square to the lab. Unboosting requires cooldown time equal to the total sum of the reactions needed to produce all the compounds applied to the creep. 118 | * 119 | * @see {@link https://docs.screeps.com/api/#StructureLab.unboostCreep} 120 | * 121 | * @type {function} 122 | * 123 | * @param {Creep} creep The target creep. 124 | * 125 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_FOUND|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_TIRED|ERR_RCL_NOT_ENOUGH} 126 | */ 127 | unboostCreep: function(creep) { }, 128 | 129 | /** 130 | * Produce mineral compounds using reagents from two other labs. 131 | * The same input labs can be used by many output labs. 132 | * 133 | * @see {@link https://docs.screeps.com/api/#StructureLab.runReaction} 134 | * 135 | * @type {function} 136 | * 137 | * @param {StructureLab} lab1 The first source lab. 138 | * @param {StructureLab} lab2 The second source lab. 139 | * 140 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS|ERR_TIRED|ERR_RCL_NOT_ENOUGH} 141 | */ 142 | runReaction: function(lab1, lab2) { } 143 | 144 | }; 145 | -------------------------------------------------------------------------------- /Structures/StructureLink.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Remotely transfers energy to another Link in the same room. 3 | * 4 | * @class 5 | * @extends {OwnedStructure} 6 | * 7 | * @see {@link https://docs.screeps.com/api/#StructureLink} 8 | */ 9 | StructureLink = function() { }; 10 | 11 | StructureLink.prototype = 12 | { 13 | /** 14 | * The amount of game ticks the link has to wait until the next transfer is possible. 15 | * 16 | * @see {@link https://docs.screeps.com/api/#StructureLink.cooldown} 17 | * 18 | * @type {number} 19 | */ 20 | cooldown: 0, 21 | 22 | /** 23 | * @deprecated Since version 4.x, replaced by `.store[RESOURCE_ENERGY]`. 24 | * 25 | * The amount of energy containing in the link. 26 | * 27 | * @see {@link https://docs.screeps.com/api/#StructureLink.energy} 28 | * 29 | * @type {number} 30 | */ 31 | energy: 0, 32 | 33 | /** 34 | * @deprecated Since version 4.x, replaced by `.store.getCapacity(RESOURCE_ENERGY)`. 35 | * 36 | * The total amount of energy the link can contain. 37 | * 38 | * @see {@link https://docs.screeps.com/api/#StructureLink.energyCapacity} 39 | * 40 | * @type {number} 41 | */ 42 | energyCapacity: 0, 43 | 44 | /** 45 | * A Store object that contains cargo of this structure. 46 | * 47 | * @see {@link https://docs.screeps.com/api/#StructureLink.store} 48 | * 49 | * @type {Store} 50 | */ 51 | store: {}, 52 | 53 | /** 54 | * Remotely transfer energy to another link at any location in the same room. 55 | * 56 | * @see {@link https://docs.screeps.com/api/#StructureLink.transferEnergy} 57 | * 58 | * @type {function} 59 | * 60 | * @param {StructureLink} target The target object. 61 | * @param {number|undefined|null} [amount] The amount of energy to be transferred. If omitted, all the available energy is used. 62 | * 63 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS|ERR_TIRED|ERR_RCL_NOT_ENOUGH} 64 | */ 65 | transferEnergy: function(target, amount) { } 66 | }; 67 | -------------------------------------------------------------------------------- /Structures/StructureNuker.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Launches a nuke to another room dealing huge damage to the landing area. 3 | * Each launch has a cooldown and requires energy and ghodium resources. 4 | * Launching creates a Nuke object at the target room position which is visible to any player until it is landed. 5 | * Incoming nuke cannot be moved or cancelled. Nukes cannot be launched from or to novice rooms. 6 | * 7 | * @class 8 | * @extends {OwnedStructure} 9 | * 10 | * @see {@link https://docs.screeps.com/api/#StructureNuker} 11 | */ 12 | StructureNuker = function() { }; 13 | 14 | StructureNuker.prototype = 15 | { 16 | /** 17 | * @deprecated Since version 4.x, replaced by `.store[RESOURCE_ENERGY]`. 18 | * 19 | * The amount of energy containing in this structure. 20 | * 21 | * @see {@link https://docs.screeps.com/api/#StructureNuker.energy} 22 | * 23 | * @type {number} 24 | */ 25 | energy: 0, 26 | 27 | /** 28 | * @deprecated Since version 4.x, replaced by `.store.getCapacity(RESOURCE_ENERGY)`. 29 | * 30 | * The total amount of energy this structure can contain. 31 | * 32 | * @see {@link https://docs.screeps.com/api/#StructureNuker.energyCapacity} 33 | * 34 | * @type {number} 35 | */ 36 | energyCapacity: 0, 37 | 38 | /** 39 | * @deprecated Since version 4.x, replaced by `.store[RESOURCE_GHODIUM]`. 40 | * 41 | * The amount of ghodium containing in this structure. 42 | * 43 | * @see {@link https://docs.screeps.com/api/#StructureNuker.ghodium} 44 | * 45 | * @type {number} 46 | */ 47 | ghodium: 0, 48 | 49 | /** 50 | * @deprecated Since version 4.x, replaced by `.store.getCapacity(RESOURCE_GHODIUM)`. 51 | * 52 | * The total amount of ghodium this structure can contain. 53 | * 54 | * @see {@link https://docs.screeps.com/api/#StructureNuker.ghodiumCapacity} 55 | * 56 | * @type {number} 57 | */ 58 | ghodiumCapacity: 0, 59 | 60 | /** 61 | * The amount of game ticks until the next launch is possible. 62 | * 63 | * @see {@link https://docs.screeps.com/api/#StructureNuker.cooldown} 64 | * 65 | * @type {number} 66 | */ 67 | cooldown: 0, 68 | 69 | /** 70 | * A Store object that contains cargo of this structure. 71 | * 72 | * @see {@link https://docs.screeps.com/api/#StructureNuker.store} 73 | * 74 | * @type {Store} 75 | */ 76 | store: {}, 77 | 78 | /** 79 | * Launch a nuke to the specified position. 80 | * 81 | * @see {@link https://docs.screeps.com/api/#StructureNuker.launchNuke} 82 | * 83 | * @type {function} 84 | * 85 | * @param {RoomPosition} pos The target room position. 86 | * 87 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_ARGS|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_TIRED|ERR_RCL_NOT_ENOUGH} 88 | */ 89 | launchNuke: function(pos) { } 90 | }; 91 | -------------------------------------------------------------------------------- /Structures/StructureObserver.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides visibility into a distant room from your script. 3 | * 4 | * @class 5 | * @extends {OwnedStructure} 6 | * 7 | * @see {@link https://docs.screeps.com/api/#StructureObserver} 8 | */ 9 | StructureObserver = function() { }; 10 | 11 | StructureObserver.prototype = 12 | { 13 | /** 14 | * Provide visibility into a distant room from your script. 15 | * The target room object will be available on the next tick. 16 | * 17 | * @see {@link https://docs.screeps.com/api/#StructureObserver.observeRoom} 18 | * 19 | * @type {function} 20 | * 21 | * @param {string} roomName The name of the target room. 22 | * 23 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS|ERR_RCL_NOT_ENOUGH} 24 | */ 25 | observeRoom: function(roomName) { } 26 | }; 27 | -------------------------------------------------------------------------------- /Structures/StructurePortal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A non-player structure. 3 | * Instantly teleports your creeps to a distant room acting as a room exit tile. 4 | * Portals appear randomly in the central room of each sector. 5 | * 6 | * @class 7 | * @extends {Structure} 8 | * 9 | * @see {@link https://docs.screeps.com/api/#StructurePortal} 10 | */ 11 | StructurePortal = function() { }; 12 | 13 | StructurePortal.prototype = 14 | { 15 | /** 16 | * If this is an inter-room portal, then this property contains a RoomPosition object leading to the point in the destination room. 17 | * If this is an inter-shard portal, then this property contains an object with shard and room string properties. 18 | * 19 | * @see {@link https://docs.screeps.com/api/#StructurePortal.destination} 20 | * 21 | * @type {RoomPosition|object} 22 | */ 23 | destination: null, 24 | 25 | /** 26 | * The amount of game ticks when the portal disappears, or undefined when the portal is stable. 27 | * 28 | * @see {@link https://docs.screeps.com/api/#StructurePortal.ticksToDecay} 29 | * 30 | * @type {undefined|number} 31 | */ 32 | ticksToDecay: 0 33 | }; 34 | -------------------------------------------------------------------------------- /Structures/StructurePowerBank.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Non-player structure. 3 | * Contains power resource which can be obtained by destroying the structure. 4 | * Hits the attacker creep back on each attack. 5 | * 6 | * @class 7 | * @extends {OwnedStructure} 8 | * 9 | * @see {@link https://docs.screeps.com/api/#StructurePowerBank} 10 | */ 11 | StructurePowerBank = function() { }; 12 | 13 | StructurePowerBank.prototype = 14 | { 15 | /** 16 | * The amount of power containing. 17 | * 18 | * @see {@link https://docs.screeps.com/api/#StructurePowerBank.power} 19 | * 20 | * @type {number} 21 | */ 22 | power: 0, 23 | 24 | /** 25 | * The amount of game ticks when this structure will disappear. 26 | * 27 | * @see {@link https://docs.screeps.com/api/#StructurePowerBank.ticksToDecay} 28 | * 29 | * @type {number} 30 | */ 31 | ticksToDecay: 0 32 | }; 33 | -------------------------------------------------------------------------------- /Structures/StructurePowerSpawn.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Processes power into your account, and spawns power creeps with special unique powers (in development). 3 | * 4 | * @class 5 | * @extends {OwnedStructure} 6 | * 7 | * @see {@link https://docs.screeps.com/api/#StructurePowerSpawn} 8 | */ 9 | StructurePowerSpawn = function() { }; 10 | 11 | StructurePowerSpawn.prototype = 12 | { 13 | /** 14 | * @deprecated Since version 4.x, replaced by `.store[RESOURCE_ENERGY]`. 15 | * 16 | * The amount of energy containing in this structure. 17 | * 18 | * @see {@link https://docs.screeps.com/api/#StructurePowerSpawn.energy} 19 | * 20 | * @type {number} 21 | */ 22 | energy: 0, 23 | 24 | /** 25 | * @deprecated Since version 4.x, replaced by `.store.getCapacity(RESOURCE_ENERGY)`. 26 | * 27 | * The total amount of energy this structure can contain. 28 | * 29 | * @see {@link https://docs.screeps.com/api/#StructurePowerSpawn.energyCapacity} 30 | * 31 | * @type {number} 32 | */ 33 | energyCapacity: 0, 34 | 35 | /** 36 | * @deprecated Since version 4.x, replaced by `.store[RESOURCE_POWER]`. 37 | * 38 | * The amount of power containing in this structure. 39 | * 40 | * @see {@link https://docs.screeps.com/api/#StructurePowerSpawn.power} 41 | * 42 | * @type {number} 43 | */ 44 | power: 0, 45 | 46 | /** 47 | * @deprecated Since version 4.x, replaced by `.store.getCapacity(RESOURCE_POWER)`. 48 | * 49 | * The total amount of power this structure can contain. 50 | * 51 | * @see {@link https://docs.screeps.com/api/#StructurePowerSpawn.powerCapacity} 52 | * 53 | * @type {number} 54 | */ 55 | powerCapacity: 0, 56 | 57 | /** 58 | * A Store object that contains cargo of this structure. 59 | * 60 | * @see {@link https://docs.screeps.com/api/#StructurePowerSpawn.store} 61 | * 62 | * @type {Store} 63 | */ 64 | store: {}, 65 | 66 | /** 67 | * Register power resource units into your account. 68 | * Registered power allows to develop power creeps skills. 69 | * 70 | * @see {@link https://docs.screeps.com/api/#StructurePowerSpawn.processPower} 71 | * 72 | * @type {function} 73 | * 74 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_RESOURCES|ERR_RCL_NOT_ENOUGH} 75 | */ 76 | processPower: function() { } 77 | 78 | }; 79 | -------------------------------------------------------------------------------- /Structures/StructureRampart.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Blocks movement of hostile creeps, and defends your creeps and structures on the same tile. 3 | * Can be used as a controllable gate. 4 | * 5 | * @class 6 | * @extends {OwnedStructure} 7 | * 8 | * @see {@link https://docs.screeps.com/api/#StructureRampart} 9 | */ 10 | StructureRampart = function() { }; 11 | 12 | StructureRampart.prototype = 13 | { 14 | /** 15 | * If false (default), only your creeps can step on the same square. If true, any hostile creeps can pass through. 16 | * 17 | * @see {@link https://docs.screeps.com/api/#StructureRampart.isPublic} 18 | * 19 | * @type {boolean} 20 | */ 21 | isPublic: false, 22 | 23 | /** 24 | * The amount of game ticks when this rampart will lose some hit points. 25 | * 26 | * @see {@link https://docs.screeps.com/api/#StructureRampart.ticksToDecay} 27 | * 28 | * @type {number} 29 | */ 30 | ticksToDecay: 0, 31 | 32 | /** 33 | * Make this rampart public to allow other players' creeps to pass through. 34 | * 35 | * @see {@link https://docs.screeps.com/api/#StructureRampart.setPublic} 36 | * 37 | * @type {function} 38 | * 39 | * @param {boolean} isPublic Whether this rampart should be public or non-public. 40 | * 41 | * @return {number|OK|ERR_NOT_OWNER} 42 | */ 43 | setPublic: function(isPublic) { } 44 | }; 45 | -------------------------------------------------------------------------------- /Structures/StructureRoad.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Decreases movement cost to 1. 3 | * Using roads allows creating creeps with less MOVE body parts. 4 | * You can also build roads on top of natural terrain walls which are otherwise impassable. 5 | * 6 | * @class 7 | * @extends {Structure} 8 | * 9 | * @see {@link https://docs.screeps.com/api/#StructureRoad} 10 | */ 11 | StructureRoad = function() { }; 12 | 13 | StructureRoad.prototype = 14 | { 15 | /** 16 | * The amount of game ticks when this road will lose some hit points. 17 | * 18 | * @see {@link https://docs.screeps.com/api/#StructureRoad.ticksToDecay} 19 | * 20 | * @type {number} 21 | */ 22 | ticksToDecay: 0 23 | }; 24 | -------------------------------------------------------------------------------- /Structures/StructureSpawn.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Spawn is your colony center. 3 | * This structure can create, renew, and recycle creeps. 4 | * All your spawns are accessible through Game.spawns hash list. 5 | * 6 | * @class 7 | * @extends {OwnedStructure} 8 | * 9 | * @see {@link https://docs.screeps.com/api/#StructureSpawn} 10 | */ 11 | StructureSpawn = function() { }; 12 | 13 | /** 14 | * 15 | * @class 16 | * @extends {OwnedStructure} 17 | * 18 | * @see {@link https://docs.screeps.com/api/#StructureSpawn} 19 | */ 20 | Spawn = StructureSpawn; 21 | Spawn.prototype = StructureSpawn.prototype; 22 | 23 | StructureSpawn.prototype = 24 | { 25 | /** 26 | * @deprecated Since version 4.x, replaced by `.store[RESOURCE_ENERGY]`. 27 | * 28 | * The amount of energy containing in the spawn. 29 | * 30 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.energy} 31 | * 32 | * @type {number} 33 | */ 34 | energy: 0, 35 | 36 | /** 37 | * @deprecated Since version 4.x, replaced by `.store.getCapacity(RESOURCE_ENERGY)`. 38 | * 39 | * The total amount of energy the spawn can contain 40 | * 41 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.energyCapacity} 42 | * 43 | * @type {number} 44 | */ 45 | energyCapacity: 0, 46 | 47 | /** 48 | * A shorthand to Memory.spawns[spawn.name]. 49 | * You can use it for quick access the spawn’s specific memory data object. 50 | * 51 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.memory} 52 | * 53 | * @type {*} 54 | */ 55 | memory: {}, 56 | 57 | /** 58 | * Spawn’s name. 59 | * You choose the name upon creating a new spawn, and it cannot be changed later. 60 | * This name is a hash key to access the spawn via the Game.spawns object. 61 | * 62 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.name} 63 | * 64 | * @type {string} 65 | */ 66 | name: "", 67 | 68 | /** 69 | * If the spawn is in process of spawning a new creep, this object will contain a StructureSpawn.Spawning object, or null otherwise. 70 | * 71 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.spawning} 72 | * 73 | * @type {object|null} 74 | */ 75 | spawning: null, 76 | 77 | /** 78 | * A Store object that contains cargo of this structure. 79 | * 80 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.store} 81 | * 82 | * @type {Store} 83 | */ 84 | store: {}, 85 | 86 | /** 87 | * @deprecated This method is deprecated and will be removed soon. Please use StructureSpawn.spawnCreep with dryRun flag instead. 88 | * 89 | * Check if a creep can be created. 90 | * 91 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.canCreateCreep} 92 | * 93 | * @type {function} 94 | * 95 | * @param {Array} body An array describing the new creep’s body. Should contain 1 to 50 elements. 96 | * @param {string|undefined|null} [name] The name of a new creep. It should be unique creep name, i.e. the Game.creeps object should not contain another creep with the same name (hash key). If not defined, a random name will be generated. 97 | * 98 | * 99 | * @return {number|OK|ERR_NOT_OWNER|ERR_NAME_EXISTS|ERR_BUSY|ERR_NOT_ENOUGH_ENERGY|ERR_INVALID_ARGS|ERR_RCL_NOT_ENOUGH} 100 | */ 101 | canCreateCreep: function(body, name) { }, 102 | 103 | /** 104 | * @deprecated This method is deprecated and will be removed soon. Please use StructureSpawn.spawnCreep instead. 105 | * 106 | * Start the creep spawning process. 107 | * 108 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.createCreep} 109 | * 110 | * @type {function} 111 | * 112 | * @param {Array} body An array describing the new creep’s body. Should contain 1 to 50 elements. 113 | * @param {string|undefined|null} [name] The name of a new creep. It should be unique creep name, i.e. the Game.creeps object should not contain another creep with the same name (hash key). If not defined, a random name will be generated. 114 | * @param {*} [memory] The memory of a new creep. If provided, it will be immediately stored into Memory.creeps[name]. 115 | * 116 | * @return {string|number|ERR_NOT_OWNER|ERR_NAME_EXISTS|ERR_BUSY|ERR_NOT_ENOUGH_ENERGY|ERR_INVALID_ARGS|ERR_RCL_NOT_ENOUGH} 117 | */ 118 | createCreep: function(body, name, memory) { }, 119 | 120 | /** 121 | * Start the creep spawning process. The required energy amount can be withdrawn from all spawns and extensions in the room. 122 | * 123 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.spawnCreep} 124 | * 125 | * @type {function} 126 | * 127 | * @param {Array} body An array describing the new creep’s body. Should contain 1 to 50 elements. 128 | * @param {string} name The name of a new creep. It must be a unique creep name, i.e. the Game.creeps object should not contain another creep with the same name (hash key). 129 | * @param {Object} [opts] An object with additional options for the spawning process. 130 | * @param {*} [opts.memory] Memory of the new creep. If provided, it will be immediately stored into Memory.creeps[name]. 131 | * @param {Array} [opts.energyStructures] Array of spawns/extensions from which to draw energy for the spawning process. Structures will be used according to the array order. 132 | * @param {boolean} [opts.dryRun] If dryRun is true, the operation will only check if it is possible to create a creep. 133 | * @param {Array} [opts.directions] Set desired directions where the creep should move when spawned. 134 | * 135 | * @return {number|OK|ERR_NOT_OWNER|ERR_NAME_EXISTS|ERR_BUSY|ERR_NOT_ENOUGH_ENERGY|ERR_INVALID_ARGS|ERR_RCL_NOT_ENOUGH} 136 | */ 137 | spawnCreep: function(body, name, opts) { }, 138 | 139 | /** 140 | * Kill the creep and drop up to 100% of resources spent on its spawning and boosting depending on remaining life time. 141 | * The target should be at adjacent square. 142 | * Energy return is limited to 125 units per body part. 143 | * 144 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.recycleCreep} 145 | * 146 | * @type {function} 147 | * 148 | * @param {Creep} target The target creep object. 149 | * 150 | * @return {number|OK|ERR_NOT_OWNER|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_RCL_NOT_ENOUGH} 151 | */ 152 | recycleCreep: function(target) { }, 153 | 154 | /** 155 | * Increase the remaining time to live of the target creep. 156 | * The target should be at adjacent square. 157 | * The target should not have CLAIM body parts. 158 | * The spawn should not be busy with the spawning process. 159 | * Each execution increases the creep's timer by amount of ticks according to this formula: floor(600/body_size). 160 | * Energy required for each execution is determined using this formula: ceil(creep_cost/2.5/body_size). 161 | * Renewing a creep removes all of its boosts. 162 | * 163 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.renewCreep} 164 | * 165 | * @type {function} 166 | * 167 | * @param {Creep} target The target creep object. 168 | * 169 | * @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_ENERGY|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_RCL_NOT_ENOUGH} 170 | */ 171 | renewCreep: function(target) { } 172 | 173 | }; 174 | 175 | /** 176 | * Details of the creep being spawned currently that can be addressed by the StructureSpawn.spawning property. 177 | * 178 | * @class 179 | * 180 | * @see {@link https://docs.screeps.com/api/#StructureSpawn-Spawning} 181 | */ 182 | StructureSpawn.Spawning = function () { }; 183 | 184 | StructureSpawn.Spawning.prototype = { 185 | 186 | /** 187 | * An array with the spawn directions 188 | * 189 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.Spawning.directions} 190 | * 191 | * @type {Array} 192 | */ 193 | directions: [], 194 | 195 | /** 196 | * The name of a new creep. 197 | * 198 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.Spawning.name} 199 | * 200 | * @type {string} 201 | */ 202 | name: "", 203 | 204 | /** 205 | * Time needed in total to complete the spawning. 206 | * 207 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.Spawning.needTime} 208 | * 209 | * @type {number} 210 | */ 211 | needTime: 0, 212 | 213 | /** 214 | * Remaining time to go. 215 | * 216 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.Spawning.remainingTime} 217 | * 218 | * @type {number} 219 | */ 220 | remainingTime: 0, 221 | 222 | /** 223 | * A link to the spawn. 224 | * 225 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.Spawning.spawn} 226 | * 227 | * @type {StructureSpawn} 228 | */ 229 | spawn: {}, 230 | 231 | /** 232 | * Cancel spawning immediately. Energy spent on spawning is not returned. 233 | * 234 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.Spawning.cancel} 235 | * 236 | * @type {function} 237 | * 238 | * @return {number|OK|ERR_NOT_OWNER} 239 | */ 240 | cancel: function() { }, 241 | 242 | /** 243 | * Set desired directions where the creep should move when spawned. 244 | * 245 | * @see {@link https://docs.screeps.com/api/#StructureSpawn.Spawning.setDirections} 246 | * 247 | * @type {function} 248 | * 249 | * @param {Array} directions An array with the direction constants: TOP, TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM, BOTTOM_LEFT, LEFT, TOP_LEFT 250 | * 251 | * @return {number|OK|ERR_NOT_OWNER|ERR_INVALID_ARGS} 252 | */ 253 | setDirections: function(directions) { } 254 | }; 255 | -------------------------------------------------------------------------------- /Structures/StructureStorage.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A structure that can store huge amount of resource units. 3 | * Only one structure per room is allowed that can be addressed by Room.storage property. 4 | * 5 | * @class 6 | * @extends {OwnedStructure} 7 | * 8 | * @see {@link https://docs.screeps.com/api/#StructureStorage} 9 | */ 10 | StructureStorage = function() { }; 11 | 12 | StructureStorage.prototype = 13 | { 14 | /** 15 | * A Store object that contains cargo of this structure. 16 | * 17 | * @see {@link https://docs.screeps.com/api/#StructureStorage.store} 18 | * 19 | * @type {Store} 20 | */ 21 | store: {}, 22 | 23 | /** 24 | * @deprecated Since version 4.x, replaced by `.store.getCapacity()`. 25 | * 26 | * The total amount of resources the storage can contain. 27 | * 28 | * @see {@link https://docs.screeps.com/api/#StructureStorage.storeCapacity} 29 | * 30 | * @type {number} 31 | */ 32 | storeCapacity: 0 33 | 34 | }; 35 | -------------------------------------------------------------------------------- /Structures/StructureTerminal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sends any resources to a Terminal in another room. 3 | * The destination Terminal can belong to any player. 4 | * Each transaction requires additional energy (regardless of the transfer resource type) that can be calculated using Game.market.calcTransactionCost method. 5 | * For example, sending 1000 mineral units from W0N0 to W10N5 will consume 742 energy units. 6 | * You can track your incoming and outgoing transactions using the Game.market object. 7 | * Only one Terminal per room is allowed that can be addressed by Room.terminal property. 8 | * 9 | * @class 10 | * @extends {OwnedStructure} 11 | * 12 | * @see {@link https://docs.screeps.com/api/#StructureTerminal} 13 | */ 14 | StructureTerminal = function() { }; 15 | 16 | StructureTerminal.prototype = 17 | { 18 | /** 19 | * A Store object that contains cargo of this structure. 20 | * 21 | * @see {@link https://docs.screeps.com/api/#StructureTerminal.store} 22 | * 23 | * @type {Store} 24 | */ 25 | store: {}, 26 | 27 | /** 28 | * @deprecated Since version 4.x, replaced by `.store.getCapacity()`. 29 | * 30 | * The total amount of resources the storage can contain. 31 | * 32 | * @see {@link https://docs.screeps.com/api/#StructureTerminal.storeCapacity} 33 | * 34 | * @type {number} 35 | */ 36 | storeCapacity: 0, 37 | 38 | /** 39 | * The remaining amount of ticks while this terminal cannot be used to make StructureTerminal.send or Game.market.deal calls. 40 | * 41 | * @see {@link https://docs.screeps.com/api/#StructureTerminal.cooldown} 42 | * 43 | * @type {number} 44 | */ 45 | cooldown: 0, 46 | 47 | /** 48 | * Sends resource to a Terminal in another room with the specified name. 49 | * 50 | * @see {@link https://docs.screeps.com/api/#StructureTerminal.send} 51 | * 52 | * @type {function} 53 | * 54 | * @param {string} resourceType One of the RESOURCE_* constants. 55 | * @param {number} amount The amount of resources to be sent. 56 | * @param {string} destination The name of the target room. You don't have to gain visibility in this room. 57 | * @param {string|undefined|null} [description] The description of the transaction. It is visible to the recipient. The maximum length is 100 characters. 58 | * 59 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_ARGS|ERR_TIRED} 60 | */ 61 | send: function(resourceType, amount, destination, description) { } 62 | 63 | }; 64 | -------------------------------------------------------------------------------- /Structures/StructureTower.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Remotely attacks or heals creeps, or repairs structures. 3 | * Can be targeted to any object in the room. 4 | * However, its effectiveness linearly depends on the distance. 5 | * Each action consumes energy. 6 | * 7 | * @class 8 | * @extends {OwnedStructure} 9 | * 10 | * @see {@link https://docs.screeps.com/api/#StructureTower} 11 | */ 12 | StructureTower = function() { }; 13 | 14 | StructureTower.prototype = 15 | { 16 | /** 17 | * @deprecated Since version 4.x, replaced by `.store[RESOURCE_ENERGY]`. 18 | * 19 | * @see {@link https://docs.screeps.com/api/#StructureTower.energy} 20 | * 21 | * @type {number} 22 | */ 23 | energy: 0, 24 | 25 | /** 26 | * @deprecated Since version 4.x, replaced by `.store.getCapacity(RESOURCE_ENERGY)`. 27 | * 28 | * @see {@link https://docs.screeps.com/api/#StructureTower.energyCapacity} 29 | * 30 | * @type {number} 31 | */ 32 | energyCapacity: 0, 33 | 34 | /** 35 | * A Store object that contains cargo of this structure. 36 | * 37 | * @see {@link https://docs.screeps.com/api/#StructureTower.store} 38 | * 39 | * @type {Store} 40 | */ 41 | store: {}, 42 | 43 | /** 44 | * Remotely attack any creep, power creep or structure in the room. 45 | * 46 | * @see {@link https://docs.screeps.com/api/#StructureTower.attack} 47 | * 48 | * @type {function} 49 | * 50 | * @param {Creep|PowerCreep|Structure} target The target creep. 51 | * 52 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_ENERGY|ERR_INVALID_TARGET|ERR_RCL_NOT_ENOUGH} 53 | */ 54 | attack: function(target) { }, 55 | 56 | /** 57 | * Remotely heal any creep or power creep in the room. 58 | * 59 | * @see {@link https://docs.screeps.com/api/#StructureTower.heal} 60 | * 61 | * @type {function} 62 | * 63 | * @param {Creep|PowerCreep} target The target creep. 64 | * 65 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_ENERGY|ERR_INVALID_TARGET|ERR_RCL_NOT_ENOUGH} 66 | */ 67 | heal: function(target) { }, 68 | 69 | /** 70 | * Remotely repair any structure in the room. 71 | * 72 | * @see {@link https://docs.screeps.com/api/#StructureTower.repair} 73 | * 74 | * @type {function} 75 | * 76 | * @param {Structure} target The target structure. 77 | * 78 | * @return {number|OK|ERR_NOT_OWNER|ERR_NOT_ENOUGH_ENERGY|ERR_INVALID_TARGET|ERR_RCL_NOT_ENOUGH} 79 | */ 80 | repair: function(target) { } 81 | }; 82 | -------------------------------------------------------------------------------- /Structures/StructureWall.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Blocks movement of all creeps. 3 | * 4 | * @class 5 | * @extends {Structure} 6 | * 7 | * @see {@link https://docs.screeps.com/api/#StructureWall} 8 | */ 9 | StructureWall = function() { }; 10 | 11 | StructureWall.prototype = 12 | { 13 | 14 | }; 15 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | ## TODO 2 | * Continue updating Documentation 3 | * Progress so far: Completed Game.js 4 | * Find a way to auto-generate constants 5 | 6 | 7 | ## Screeps 4.x.x 8 | Screeps got updated on 10/14/2019 to 4.x.x 9 | (see https://screeps.com/forum/topic/2814/factories-new-resources-npc-strongholds). 10 | 11 | The following could cause some problems / need to be updated in the autocomplete 12 | 13 | ### API Changes 14 | * POSSIBLY BREAKING CHANGE: Implemented new global Store prototype. All structures and creeps now use this prototype as 15 | their store property. Old style properties are now considered deprecated. See documentation for more details, and also 16 | this previous discussion. 17 | 18 | If you have any troubles because of this change, it most likely falls into one of these categories: 19 | 20 | You're checking for structure.store presence to distinguish storages and containers from spawns and extensions. Use 21 | structure.structureType check instead, or structure.store.getCapacity(RESOURCE_ENERGY) !== null. 22 | 23 | You're comparing .store[resource] === undefined. Now all absent resources are equal to 0. 24 | 25 | You're trying to redefine store property, which is now non-configurable. 26 | 27 | * A lot of new constants. 28 | 29 | * PWR_OPERATE_FACTORY power is now operational. 30 | 31 | * RoomObject.effects elements now have effect property instead of power. Property power remains for backward 32 | compatibility, but is not documented and will be removed in the future. 33 | 34 | * Added new method Game.market.getHistory, which contains historical price data for all resources. 35 | 36 | * Increased per-player market orders limit from 50 to 300. 37 | 38 | * Added expiration period to market orders. An order expires in 30 days after its creation, and the remaining market fee 39 | is returned. Extending the order doesn't update its expiration time. 40 | 41 | * Game.market.createOrder now accepts parameters in an object notation in order to minimize mistakes caused by wrong 42 | order of parameters: 43 | 44 | ``` 45 | Game.market.createOrder({ 46 | type: ORDER_BUY, 47 | resourceType: RESOURCE_ENERGY, 48 | price: 0.01, 49 | totalAmount: 100000, 50 | roomName: 'W1N1' 51 | }); 52 | ``` 53 | 54 | * Removed minimal limit for StructureTerminal.send. 55 | -------------------------------------------------------------------------------- /Tombstone.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A remnant of dead creeps. This is a walkable object. 3 | * 4 | * @class 5 | * @extends {RoomObject} 6 | * 7 | * @see {@link https://docs.screeps.com/api/#Tombstone} 8 | */ 9 | Tombstone = function() { }; 10 | 11 | Tombstone.prototype = 12 | { 13 | /** 14 | * An object containing the deceased creep or power creep. 15 | * 16 | * @see {@link https://docs.screeps.com/api/#Tombstone.creep} 17 | * 18 | * @type {Creep|PowerCreep} 19 | */ 20 | creep: { }, 21 | 22 | /** 23 | * Time of death. 24 | * 25 | * @see {@link https://docs.screeps.com/api/#Tombstone.deathTime} 26 | * 27 | * @type {number} 28 | */ 29 | deathTime: 0, 30 | 31 | /** 32 | * A unique object identificator. You can use Game.getObjectById method to retrieve an object instance by its id. 33 | * 34 | * @see {@link https://docs.screeps.com/api/#Tombstone.id} 35 | * 36 | * @type {string} 37 | */ 38 | id: "", 39 | 40 | /** 41 | * A Store object that contains cargo of this structure. 42 | * 43 | * @see {@link https://docs.screeps.com/api/#Tombstone.store} 44 | * 45 | * @type {Store} 46 | */ 47 | store: { }, 48 | 49 | /** 50 | * The amount of game ticks before this tombstone decays. 51 | * 52 | * @see {@link https://docs.screeps.com/api/#Tombstone.ticksToDecay} 53 | * 54 | * @type {number} 55 | */ 56 | ticksToDecay: 0 57 | }; 58 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ScreepsAutocomplete", 3 | "version": "1.0.0", 4 | "description": "IDE Autocomplete for Screeps", 5 | "dependencies": { 6 | }, 7 | "devDependencies": {}, 8 | "scripts": { 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/Garethp/ScreepsAutocomplete.git" 14 | }, 15 | "keywords": [ 16 | "game", 17 | "screeps" 18 | ], 19 | "author": "Garethp", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/Garethp/ScreepsAutocomplete/issues" 23 | }, 24 | "homepage": "https://github.com/Garethp/ScreepsAutocomplete#readme" 25 | } 26 | --------------------------------------------------------------------------------