├── .gitignore ├── README.md ├── dist └── screeps.d.ts ├── package.json ├── src ├── constants.ts ├── construction-site.ts ├── core.ts ├── creep.ts ├── flag.ts ├── game.ts ├── helpers.ts ├── map.ts ├── market.ts ├── memory.ts ├── mineral.ts ├── nuke.ts ├── path-finder.ts ├── raw-memory.ts ├── resource.ts ├── room-object.ts ├── room-position.ts ├── room-visual.ts ├── room.ts ├── source.ts ├── spawn.ts └── structure.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | dist/screeps.ts 4 | npm-debug.log 5 | *.*~ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Screeps Typescript Declarations 2 | 3 | > The repository for *Screep's* TypeScript type definitions. https://screeps.com/ 4 | 5 | Discussion in [screep's community forum](http://support.screeps.com/hc/en-us/community/posts/207116485-Writing-Screep-bots-with-Typescript?page=1#) 6 | 7 | # Installation 8 | 9 | Using [typings](https://github.com/typings/typings), add this to your typings.json: 10 | ```json 11 | { 12 | "globalDependencies": { 13 | "screeps": "github:screepers/Screeps-Typescript-Declarations/dist/screeps.d.ts" 14 | } 15 | } 16 | ``` 17 | 18 | # Usage 19 | 20 | Note: When using this API, you can't access creeps in manner suggested in Screeps' tutorial: 21 | 22 | ``` 23 | Game.creeps.Worker1 // This is not allowed by TypeScript compiler 24 | ``` 25 | 26 | Instead, you have to use 27 | 28 | ``` 29 | Game.creeps['Worker1'] 30 | ``` 31 | 32 | # Contribute 33 | 34 | This library will stay up to date only with the help of you! If active players don't update it, it'll get lost. 35 | 36 | To update the declarations, edit the files in ./src folder. 37 | 38 | To compile the declarations, run: 39 | 40 | ``` 41 | npm run compile 42 | ``` 43 | 44 | # Changelog 45 | 46 | ### v4.2.1 2016-07-25 [ChangeLog](http://support.screeps.com/hc/en-us/articles/210048285-Changelog-2016-07-22) 47 | - Added new toPublic option to `Creep.say` 48 | - Fixed some issue with using `instanceof` with `StructureSpawn`, `Source`, `StructureLink` 49 | 50 | ### v4.2.0 51 | - New Creep.withdraw 52 | - Added and fixed a lot of constants 53 | 54 | ### v4.0.1 55 | - Fixed issues with REACTIONS and LOOK_* constants 56 | 57 | ### v4.0.0 58 | - Changed `Map` to `GameMap` to avoid conflict with new ES6 Map type 59 | - Removed Energy Interface and replace it with Resource. This could potentially break your code. Please change all reference of Energy to Resource and it should fix the issue. 60 | - Spawn will now extends OwnStructure, and StructureContainer will extends Structure. 61 | - Fixed createCreep return type to `number | string`. 62 | - Updated new options for findPath 63 | - Added string as an acceptable params to moveByPath. 64 | 65 | ### v3.0.0 Change all usage of interface to class. 66 | Please raise an issue if this break your code! 67 | 68 | ### v2.1.0 2016-06-23 [ChangeLog](http://support.screeps.com/hc/en-us/articles/209164605-Changelog-2016-06-17) 69 | - Added new method StructureRampart.setPublic. 70 | - Added new property StructureRamprt.isPublic. 71 | - Added new global property Game.constructionSites. 72 | - Added new argument asArray to methods Room.lookAtArea and Room.lookForAtArea 73 | - Method Creep.moveByPath now accepts paths returned from PathFinder.search. 74 | 75 | ### v1.5.4 2016-04-04 [Bug](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/12) 76 | - Missing constants 77 | 78 | Thanks [Strategic-Link-Consulting](https://github.com/Strategic-Link-Consulting) 79 | 80 | ### v1.5.3 2016-03-31 [Bug](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/11) 81 | - Problem with the Game arrays. 82 | 83 | ### v1.5.2 2016-03-19 [Bug](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/10) 84 | - RoomPosition opts fix. Filter and algorithm are optional. 85 | 86 | ### v1.5.1 2016-03-18 [ChangeLog](http://support.screeps.com/hc/en-us/articles/208013255) 87 | - Added new STRUCTURE_CONTAINER constant 88 | - New structure: Container 89 | - Added Game.map.getRoomLinearDistance method. 90 | 91 | ### v1.4.3 2016-03-18 Commited by NhanHo 92 | - Added typings for various list of global objects in Game 93 | - Add serializePath and deserializePath to Room 94 | - Allow optional argument and properties in transferEnergy and PathFinderOps 95 | 96 | ### v1.4.2 2016-03-10 97 | - Fix for CostMatrix 98 | 99 | ### v1.4.1 2016-03-10 [ChangeLog](http://support.screeps.com/hc/en-us/articles/207929925) 100 | - Added Extractor, Lab, Terminal, Market, Mineral objects 101 | - New constants 102 | - Read more from docs 103 | 104 | ### v1.3.2 2016-03-10 [ChangeLog](http://support.screeps.com/hc/en-us/articles/207023879-PathFinder) 105 | - Updated all interfaces from 19.02 changelog and added docs to PathFinder [ChangeLog](http://support.screeps.com/hc/en-us/articles/207728995-Changelog-2016-02-19). 106 | 107 | ### v1.3.1 2016-02-25 [PathFinder](http://support.screeps.com/hc/en-us/articles/207023879-PathFinder) 108 | - NhanHo added new PathFinder interface [ChangeLog](http://support.screeps.com/hc/en-us/articles/207728995-Changelog-2016-02-19). 109 | Unfortunately other changes in that changelog are not added yet. We're working on it 110 | 111 | ### v1.2.2 2016-02-08 [ChangeLog](http://support.screeps.com/hc/en-us/articles/206897739-Changelog-2016-02-08) 112 | - New body part (CLAIM) 113 | - Documentation updates to support claim 114 | - Added Creep.dismantle() 115 | 116 | - Fixed missing NOT_ENOUGH_ENERGY constant 117 | 118 | ### v1.1.7 2016-02-08 119 | - Change room.controller and room.storage to correct type 120 | 121 | ### v1.1.5 2016-02-07 122 | - Updated RoomPosition declarations [#1](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/1) 123 | - Removed HashMap from Game interface. It caused migration issues from JS to TS. [#2](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/2) 124 | - Declare construction site variable (to fix instanceof problem) 125 | 126 | ### v1.1.3 2016-02-06 127 | - Removed empty memory interfaces 128 | - Fixed createScreep() method return type 129 | - Updated all declarations. Everything should be quite close to Screep's API (with minor exceptions if I missed something accidentally) 130 | 131 | ## Authors 132 | 133 | * **Nhan Ho** - *Current maintainer* - [NhanHo](https://github.com/NhanHo) 134 | * **Marko Sulamägi** - *Converted Cameron's work to quickly installable TS skeleton app.* - [MarkoSulamagi](https://github.com/MarkoSulamagi) 135 | * **vanhouc** - *Screep project with TS functionality. His gulpfile and screep.d.ts was very useful.* - [vanhouc](https://github.com/vanhouc) 136 | 137 | 138 | See also the list of [contributors](https://github.com/screepers/Screeps-Typescript-Declarations/contributors) who participated in this project. 139 | 140 | ## License 141 | 142 | This project is licensed under the MIT license. 143 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "screeps-typescript-declarations", 3 | "version": "4.3.1", 4 | "description": "Typescript declarations for Screeps API. To enable autocomplete and help with compilation", 5 | "repository": "screepers/Screeps-Typescript-Declarations", 6 | "typings": "./dist/screeps.d.ts", 7 | "scripts": { 8 | "compile": "node_modules/.bin/tsc" 9 | }, 10 | "keywords": [ 11 | "Screeps", 12 | "API", 13 | "Typescript", 14 | "Autocomplete" 15 | ], 16 | "author": "Marko Sulamagi ", 17 | "license": "MIT", 18 | "devDependencies": { 19 | "typescript": "^2.1.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/constants.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is Screeps API description file. 3 | * This might need some updates when Screeps publishes new features or changes it's existing API 4 | */ 5 | 6 | declare const OK: 0; 7 | declare const ERR_NOT_OWNER: -1; 8 | declare const ERR_NO_PATH: -2; 9 | declare const ERR_NAME_EXISTS: -3; 10 | declare const ERR_BUSY: -4; 11 | declare const ERR_NOT_FOUND: -5; 12 | declare const ERR_NOT_ENOUGH_RESOURCES: -6; 13 | declare const ERR_NOT_ENOUGH_ENERGY: -6; 14 | declare const ERR_INVALID_TARGET: -7; 15 | declare const ERR_FULL: -8; 16 | declare const ERR_NOT_IN_RANGE: -9; 17 | declare const ERR_INVALID_ARGS: -10; 18 | declare const ERR_TIRED: -11; 19 | declare const ERR_NO_BODYPART: -12; 20 | declare const ERR_NOT_ENOUGH_EXTENSIONS: -6; 21 | declare const ERR_RCL_NOT_ENOUGH: -14; 22 | declare const ERR_GCL_NOT_ENOUGH: -15; 23 | 24 | declare const FIND_EXIT_TOP: 1; 25 | declare const FIND_EXIT_RIGHT: 3; 26 | declare const FIND_EXIT_BOTTOM: 5; 27 | declare const FIND_EXIT_LEFT: 7; 28 | declare const FIND_EXIT: 10; 29 | declare const FIND_CREEPS: 101; 30 | declare const FIND_MY_CREEPS: 102; 31 | declare const FIND_HOSTILE_CREEPS: 103; 32 | declare const FIND_SOURCES_ACTIVE: 104; 33 | declare const FIND_SOURCES: 105; 34 | declare const FIND_DROPPED_RESOURCES: 106; 35 | declare const FIND_DROPPED_ENERGY: 106; // Yup, it's 106. 36 | declare const FIND_STRUCTURES: 107; 37 | declare const FIND_MY_STRUCTURES: 108; 38 | declare const FIND_HOSTILE_STRUCTURES: 109; 39 | declare const FIND_FLAGS: 110; 40 | declare const FIND_CONSTRUCTION_SITES: 111; 41 | declare const FIND_MY_SPAWNS: 112; 42 | declare const FIND_HOSTILE_SPAWNS: 113; 43 | declare const FIND_MY_CONSTRUCTION_SITES: 114; 44 | declare const FIND_HOSTILE_CONSTRUCTION_SITES: 115; 45 | declare const FIND_MINERALS: 116; 46 | declare const FIND_NUKES: 117; 47 | 48 | declare const TOP: 1; 49 | declare const TOP_RIGHT: 2; 50 | declare const RIGHT: 3; 51 | declare const BOTTOM_RIGHT: 4; 52 | declare const BOTTOM: 5; 53 | declare const BOTTOM_LEFT: 6; 54 | declare const LEFT: 7; 55 | declare const TOP_LEFT: 8; 56 | 57 | declare const COLOR_RED: 1; 58 | declare const COLOR_PURPLE: 2; 59 | declare const COLOR_BLUE: 3; 60 | declare const COLOR_CYAN: 4; 61 | declare const COLOR_GREEN: 5; 62 | declare const COLOR_YELLOW: 6; 63 | declare const COLOR_ORANGE: 7; 64 | declare const COLOR_BROWN: 8; 65 | declare const COLOR_GREY: 9; 66 | declare const COLOR_WHITE: 10; 67 | declare const COLORS_ALL: number[]; 68 | 69 | declare const CREEP_SPAWN_TIME: 3; 70 | declare const CREEP_LIFE_TIME: 1500; 71 | declare const CREEP_CLAIM_LIFE_TIME: 500; 72 | declare const CREEP_CORPSE_RATE: 0.2; 73 | 74 | declare const OBSTACLE_OBJECT_TYPES: string[]; 75 | 76 | declare const ENERGY_REGEN_TIME: 300; 77 | declare const ENERGY_DECAY: 1000; 78 | 79 | declare const REPAIR_COST: 0.01; 80 | 81 | declare const RAMPART_DECAY_AMOUNT: 300; 82 | declare const RAMPART_DECAY_TIME: 100; 83 | declare const RAMPART_HITS: 1; 84 | declare const RAMPART_HITS_MAX: { 85 | 2: 300000, 86 | 3: 1000000, 87 | 4: 3000000, 88 | 5: 10000000, 89 | 6: 30000000, 90 | 7: 100000000, 91 | 8: 300000000 92 | }; 93 | 94 | declare const SPAWN_HITS: 5000; 95 | declare const SPAWN_ENERGY_START: 300; 96 | declare const SPAWN_ENERGY_CAPACITY: 300; 97 | 98 | declare const SOURCE_ENERGY_CAPACITY: 3000; 99 | declare const SOURCE_ENERGY_NEUTRAL_CAPACITY: 1500; 100 | declare const SOURCE_ENERGY_KEEPER_CAPACITY: 4000; 101 | 102 | declare const WALL_HITS: 1; 103 | declare const WALL_HITS_MAX: 300000000; 104 | 105 | declare const EXTENSION_HITS: 1000; 106 | declare const EXTENSION_ENERGY_CAPACITY: { 107 | 0: 50, 108 | 1: 50, 109 | 2: 50, 110 | 3: 50, 111 | 4: 50, 112 | 5: 50, 113 | 6: 50, 114 | 7: 100, 115 | 8: 200 116 | }; 117 | 118 | declare const ROAD_HITS: 5000; 119 | declare const ROAD_WEAROUT: 1; 120 | declare const ROAD_DECAY_AMOUNT: 100; 121 | declare const ROAD_DECAY_TIME: 1000; 122 | 123 | declare const LINK_HITS: 1000; 124 | declare const LINK_HITS_MAX: 1000; 125 | declare const LINK_CAPACITY: 800; 126 | declare const LINK_COOLDOWN: 1; 127 | declare const LINK_LOSS_RATIO: 0.03; 128 | 129 | declare const STORAGE_CAPACITY: 1000000; 130 | declare const STORAGE_HITS: 10000; 131 | 132 | declare const BODYPART_COST: { 133 | [part: string]: number; 134 | move: 50; 135 | work: 100; 136 | attack: 80; 137 | carry: 50; 138 | heal: 250; 139 | ranged_attack: 150; 140 | tough: 10; 141 | claim: 600; 142 | }; 143 | declare const BODYPARTS_ALL: string[]; 144 | 145 | 146 | declare const CARRY_CAPACITY: 50; 147 | declare const HARVEST_POWER: 2; 148 | declare const HARVEST_MINERAL_POWER: 1; 149 | declare const REPAIR_POWER: 100; 150 | declare const DISMANTLE_POWER: 50; 151 | declare const BUILD_POWER: 5; 152 | declare const ATTACK_POWER: 30; 153 | declare const UPGRADE_CONTROLLER_POWER: 1; 154 | declare const RANGED_ATTACK_POWER: 10; 155 | declare const HEAL_POWER: 12; 156 | declare const RANGED_HEAL_POWER: 4; 157 | declare const DISMANTLE_COST: 0.005; 158 | 159 | declare const MOVE: "move"; 160 | declare const WORK: "work"; 161 | declare const CARRY: "carry"; 162 | declare const ATTACK: "attack"; 163 | declare const RANGED_ATTACK: "ranged_attack"; 164 | declare const TOUGH: "tough"; 165 | declare const HEAL: "heal"; 166 | declare const CLAIM: "claim"; 167 | 168 | declare const CONSTRUCTION_COST: { 169 | spawn: 15000, 170 | extension: 3000, 171 | road: 300, 172 | constructedWall: 1, 173 | rampart: 1, 174 | link: 5000, 175 | storage: 30000, 176 | tower: 5000, 177 | observer: 8000, 178 | powerSpawn: 100000, 179 | extractor: 5000, 180 | lab: 50000, 181 | terminal: 100000, 182 | container: 5000, 183 | nuker: 100000 184 | }; 185 | 186 | declare const CONSTRUCTION_COST_ROAD_SWAMP_RATIO: 5; 187 | 188 | declare const STRUCTURE_EXTENSION: "extension"; 189 | declare const STRUCTURE_RAMPART: "rampart"; 190 | declare const STRUCTURE_ROAD: "road"; 191 | declare const STRUCTURE_SPAWN: "spawn"; 192 | declare const STRUCTURE_LINK: "link"; 193 | declare const STRUCTURE_WALL: "wall"; 194 | declare const STRUCTURE_KEEPER_LAIR: "keeperLair"; 195 | declare const STRUCTURE_CONTROLLER: "controller"; 196 | declare const STRUCTURE_STORAGE: "storage"; 197 | declare const STRUCTURE_TOWER: "tower"; 198 | declare const STRUCTURE_OBSERVER: "observer"; 199 | declare const STRUCTURE_POWER_BANK: "powerBank"; 200 | declare const STRUCTURE_POWER_SPAWN: "powerSpawn"; 201 | declare const STRUCTURE_EXTRACTOR: "extractor"; 202 | declare const STRUCTURE_LAB: "lab"; 203 | declare const STRUCTURE_TERMINAL: "terminal"; 204 | declare const STRUCTURE_CONTAINER: "container"; 205 | declare const STRUCTURE_NUKER: "nuker"; 206 | declare const STRUCTURE_PORTAL: "portal"; 207 | 208 | declare const RESOURCE_ENERGY: "energy"; 209 | declare const RESOURCE_POWER: "power"; 210 | declare const RESOURCE_UTRIUM: "U"; 211 | declare const RESOURCE_LEMERGIUM: "L"; 212 | declare const RESOURCE_KEANIUM: "K"; 213 | declare const RESOURCE_GHODIUM: "G"; 214 | declare const RESOURCE_ZYNTHIUM: "Z"; 215 | declare const RESOURCE_OXYGEN: "O"; 216 | declare const RESOURCE_HYDROGEN: "H"; 217 | declare const RESOURCE_CATALYST: "X"; 218 | declare const RESOURCE_HYDROXIDE: "OH"; 219 | declare const RESOURCE_ZYNTHIUM_KEANITE: "ZK"; 220 | declare const RESOURCE_UTRIUM_LEMERGITE: "UL"; 221 | declare const RESOURCE_UTRIUM_HYDRIDE: "UH"; 222 | declare const RESOURCE_UTRIUM_OXIDE: "UO"; 223 | declare const RESOURCE_KEANIUM_HYDRIDE: "KH"; 224 | declare const RESOURCE_KEANIUM_OXIDE: "KO"; 225 | declare const RESOURCE_LEMERGIUM_HYDRIDE: "LH"; 226 | declare const RESOURCE_LEMERGIUM_OXIDE: "LO"; 227 | declare const RESOURCE_ZYNTHIUM_HYDRIDE: "ZH"; 228 | declare const RESOURCE_ZYNTHIUM_OXIDE: "ZO"; 229 | declare const RESOURCE_GHODIUM_HYDRIDE: "GH"; 230 | declare const RESOURCE_GHODIUM_OXIDE: "GO"; 231 | declare const RESOURCE_UTRIUM_ACID: "UH2O"; 232 | declare const RESOURCE_UTRIUM_ALKALIDE: "UHO2"; 233 | declare const RESOURCE_KEANIUM_ACID: "KH2O"; 234 | declare const RESOURCE_KEANIUM_ALKALIDE: "KHO2"; 235 | declare const RESOURCE_LEMERGIUM_ACID: "LH2O"; 236 | declare const RESOURCE_LEMERGIUM_ALKALIDE: "LHO2"; 237 | declare const RESOURCE_ZYNTHIUM_ACID: "ZH2O"; 238 | declare const RESOURCE_ZYNTHIUM_ALKALIDE: "ZHO2"; 239 | declare const RESOURCE_GHODIUM_ACID: "GH2O"; 240 | declare const RESOURCE_GHODIUM_ALKALIDE: "GHO2"; 241 | declare const RESOURCE_CATALYZED_UTRIUM_ACID: "XUH2O"; 242 | declare const RESOURCE_CATALYZED_UTRIUM_ALKALIDE: "XUHO2"; 243 | declare const RESOURCE_CATALYZED_KEANIUM_ACID: "XKH2O"; 244 | declare const RESOURCE_CATALYZED_KEANIUM_ALKALIDE: "XKHO2"; 245 | declare const RESOURCE_CATALYZED_LEMERGIUM_ACID: "XLH2O"; 246 | declare const RESOURCE_CATALYZED_LEMERGIUM_ALKALIDE: "XLHO2"; 247 | declare const RESOURCE_CATALYZED_ZYNTHIUM_ACID: "XZH2O"; 248 | declare const RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE: "ZXHO2"; 249 | declare const RESOURCE_CATALYZED_GHODIUM_ACID: "XGH2O"; 250 | declare const RESOURCE_CATALYZED_GHODIUM_ALKALIDE: "XGHO2"; 251 | declare const RESOURCES_ALL: string[]; 252 | 253 | declare const SUBSCRIPTION_TOKEN: string; 254 | 255 | declare const CONTROLLER_LEVELS: {[level: number]: number}; 256 | declare const CONTROLLER_STRUCTURES: {[structure: string]: {[level: number]: number}}; 257 | declare const CONTROLLER_DOWNGRADE: {[level: number]: number}; 258 | declare const CONTROLLER_CLAIM_DOWNGRADE: number; 259 | declare const CONTROLLER_RESERVE: number; 260 | declare const CONTROLLER_RESERVE_MAX: number; 261 | declare const CONTROLLER_MAX_UPGRADE_PER_TICK: number; 262 | declare const CONTROLLER_ATTACK_BLOCKED_UPGRADE: number; 263 | 264 | declare const TOWER_HITS: number; 265 | declare const TOWER_CAPACITY: number; 266 | declare const TOWER_ENERGY_COST: number; 267 | declare const TOWER_POWER_ATTACK: number; 268 | declare const TOWER_POWER_HEAL: number; 269 | declare const TOWER_POWER_REPAIR: number; 270 | declare const TOWER_OPTIMAL_RANGE: number; 271 | declare const TOWER_FALLOFF_RANGE: number; 272 | declare const TOWER_FALLOFF: number; 273 | 274 | declare const OBSERVER_HITS: number; 275 | declare const OBSERVER_RANGE: number; 276 | 277 | declare const POWER_BANK_HITS: number; 278 | declare const POWER_BANK_CAPACITY_MAX: number; 279 | declare const POWER_BANK_CAPACITY_MIN: number; 280 | declare const POWER_BANK_CAPACITY_CRIT: number; 281 | declare const POWER_BANK_DECAY: number; 282 | declare const POWER_BANK_HIT_BACK: number; 283 | 284 | declare const POWER_SPAWN_HITS: number; 285 | declare const POWER_SPAWN_ENERGY_CAPACITY: number; 286 | declare const POWER_SPAWN_POWER_CAPACITY: number; 287 | declare const POWER_SPAWN_ENERGY_RATIO: number; 288 | 289 | declare const EXTRACTOR_HITS: number; 290 | 291 | declare const LAB_HITS: number; 292 | declare const LAB_MINERAL_CAPACITY: number; 293 | declare const LAB_ENERGY_CAPACITY: number; 294 | declare const LAB_BOOST_ENERGY: number; 295 | declare const LAB_BOOST_MINERAL: number; 296 | declare const LAB_COOLDOWN: number; 297 | declare const LAB_REACTION_AMOUNT: number; 298 | 299 | declare const GCL_POW: number; 300 | declare const GCL_MULTIPLY: number; 301 | declare const GCL_NOVICE: number; 302 | 303 | declare const MODE_SIMULATION: string; 304 | declare const MODE_SURVIVAL: string; 305 | declare const MODE_WORLD: string; 306 | declare const MODE_ARENA: string; 307 | 308 | declare const TERRAIN_MASK_WALL: number; 309 | declare const TERRAIN_MASK_SWAMP: number; 310 | declare const TERRAIN_MASK_LAVA: number; 311 | 312 | declare const MAX_CONSTRUCTION_SITES: number; 313 | declare const MAX_CREEP_SIZE: number; 314 | 315 | declare const MINERAL_REGEN_TIME: number; 316 | declare const MINERAL_MIN_AMOUNT: { 317 | H: number, 318 | O: number, 319 | L: number, 320 | K: number, 321 | Z: number, 322 | U: number, 323 | X: number 324 | } 325 | declare const MINERAL_RANDOM_FACTOR: number; 326 | 327 | 328 | declare const MINERAL_DENSITY: { 329 | 1: number, 330 | 2: number, 331 | 3: number, 332 | 4: number 333 | } 334 | declare const MINERAL_DENSITY_PROBABILITY: { 335 | 1: number, 336 | 2: number, 337 | 3: number, 338 | 4: number 339 | } 340 | declare const MINERAL_DENSITY_CHANGE: number; 341 | 342 | declare const DENSITY_LOW: number; 343 | declare const DENSITY_MODERATE: number; 344 | declare const DENSITY_HIGH: number; 345 | declare const DENSITY_ULTRA: number; 346 | 347 | declare const TERMINAL_CAPACITY: number; 348 | declare const TERMINAL_HITS: number; 349 | declare const TERMINAL_SEND_COST: number; 350 | declare const TERMINAL_MIN_SEND: number; 351 | declare const TERMINAL_COOLDOWN: number; 352 | 353 | declare const CONTAINER_HITS: number; 354 | declare const CONTAINER_CAPACITY: number; 355 | declare const CONTAINER_DECAY: number; 356 | declare const CONTAINER_DECAY_TIME: number; 357 | declare const CONTAINER_DECAY_TIME_OWNED: number; 358 | 359 | declare const NUKER_HITS: number; 360 | declare const NUKER_COOLDOWN: number; 361 | declare const NUKER_ENERGY_CAPACITY: number; 362 | declare const NUKER_GHODIUM_CAPACITY: number; 363 | declare const NUKE_LAND_TIME: number; 364 | declare const NUKE_RANGE: number; 365 | declare const NUKE_DAMAGE: { 366 | 0: number, 367 | 1: number, 368 | 4: number 369 | } 370 | 371 | declare const REACTIONS: { 372 | [reagent: string]: { 373 | [reagent: string]: string 374 | } 375 | } 376 | 377 | declare const BOOSTS: { 378 | [part: string]: { 379 | [boost: string]: { 380 | [action: string]: number 381 | } 382 | } 383 | } 384 | 385 | declare const LOOK_CREEPS: "creep"; 386 | declare const LOOK_ENERGY: "energy"; 387 | declare const LOOK_RESOURCES: "resource"; 388 | declare const LOOK_SOURCES: "source"; 389 | declare const LOOK_MINERALS: "mineral"; 390 | declare const LOOK_STRUCTURES: "structure"; 391 | declare const LOOK_FLAGS: "flag"; 392 | declare const LOOK_CONSTRUCTION_SITES: "constructionSite"; 393 | declare const LOOK_NUKES: "nuke"; 394 | declare const LOOK_TERRAIN: "terrain"; 395 | 396 | declare const ORDER_SELL: "sell"; 397 | declare const ORDER_BUY: "buy"; 398 | -------------------------------------------------------------------------------- /src/construction-site.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A site of a structure which is currently under construction. 3 | */ 4 | interface ConstructionSite extends RoomObject { 5 | readonly prototype: ConstructionSite; 6 | /** 7 | * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. 8 | */ 9 | id: string; 10 | /** 11 | * Whether this is your own construction site. 12 | */ 13 | my: boolean; 14 | /** 15 | * An object with the structure’s owner info 16 | */ 17 | owner: Owner; 18 | /** 19 | * The current construction progress. 20 | */ 21 | progress: number; 22 | /** 23 | * The total construction progress needed for the structure to be built. 24 | */ 25 | progressTotal: number; 26 | /** 27 | * One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK 28 | */ 29 | structureType: string; 30 | /** 31 | * Remove the construction site. 32 | * @returns Result Code: OK, ERR_NOT_OWNER 33 | */ 34 | remove(): number; 35 | } 36 | 37 | interface ConstructionSiteConstructor extends _Constructor, _ConstructorById { 38 | } 39 | 40 | declare const ConstructionSite: ConstructionSiteConstructor; 41 | -------------------------------------------------------------------------------- /src/core.ts: -------------------------------------------------------------------------------- 1 | declare var Memory: Memory; 2 | declare var RawMemory: RawMemory; 3 | declare var Game:Game; 4 | declare var PathFinder: PathFinder; 5 | declare function gc(): void; 6 | type Controller= StructureController; 7 | type Extension = StructureExtension; 8 | type KeeperLair = StructureKeeperLair; 9 | type Lab = StructureLab; 10 | type Link = StructureLink; 11 | type Observer = StructureObserver; 12 | type PowerBank = StructurePowerBank; 13 | type PowerSpawn = StructurePowerSpawn; 14 | type Rampart = StructureRampart; 15 | type Terminal = StructureTerminal; 16 | type Container = StructureContainer; 17 | type Tower = StructureTower; 18 | type Spawn = StructureSpawn;//Legacy Alias 19 | declare const Spawn: StructureSpawnConstructor; 20 | interface Storage extends StructureStorage { }//Legacy Alias 21 | -------------------------------------------------------------------------------- /src/creep.ts: -------------------------------------------------------------------------------- 1 | // Updated 2016-02-05 2 | /** 3 | * Creeps are your units. Creeps can move, harvest energy, construct structures, attack another creeps, and perform other actions. Each creep consists of up to 50 body parts with the following possible types: 4 | */ 5 | interface Creep extends RoomObject { 6 | readonly prototype: Creep; 7 | 8 | /** 9 | * An array describing the creep’s body. Each element contains the following properties: 10 | * type: string 11 | * body part constant 12 | * hits: number 13 | * The remaining amount of hit points of this body part. 14 | */ 15 | body: BodyPartDefinition[]; 16 | /** 17 | * An object with the creep's cargo contents: 18 | * energy: number 19 | * The current amount of energy the creep is carrying. 20 | */ 21 | carry: StoreDefinition; 22 | /** 23 | * The total amount of resources the creep can carry. 24 | */ 25 | carryCapacity: number; 26 | /** 27 | * The movement fatigue indicator. If it is greater than zero, the creep cannot move. 28 | */ 29 | fatigue: number; 30 | /** 31 | * The current amount of hit points of the creep. 32 | */ 33 | hits: number; 34 | /** 35 | * The maximum amount of hit points of the creep. 36 | */ 37 | hitsMax: number; 38 | /** 39 | * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. 40 | */ 41 | id: string; 42 | /** 43 | * A shorthand to Memory.creeps[creep.name]. You can use it for quick access the creep’s specific memory data object. 44 | */ 45 | memory: any; 46 | /** 47 | * Whether it is your creep or foe. 48 | */ 49 | my: boolean; 50 | /** 51 | * Creep’s name. You can choose the name while creating a new creep, and it cannot be changed later. This name is a hash key to access the creep via the Game.creeps object. 52 | */ 53 | name: string; 54 | /** 55 | * An object with the creep’s owner info 56 | */ 57 | owner: Owner; 58 | /** 59 | * The link to the Room object. Always defined because creeps give visibility into the room they're in. 60 | */ 61 | room: Room; 62 | /** 63 | * Whether this creep is still being spawned. 64 | */ 65 | spawning: boolean; 66 | /** 67 | * The text message that the creep was saying at the last tick. 68 | */ 69 | saying: string; 70 | /** 71 | * The remaining amount of game ticks after which the creep will die. 72 | */ 73 | ticksToLive: number; 74 | /** 75 | * Attack another creep or structure in a short-ranged attack. Needs the ATTACK body part. If the target is inside a rampart, then the rampart is attacked instead. The target has to be at adjacent square to the creep. If the target is a creep with ATTACK body parts and is not inside a rampart, it will automatically hit back at the attacker. 76 | * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART 77 | */ 78 | attack(target: Creep|Structure): number; 79 | /** 80 | * Decreases the controller's downgrade or reservation timer for 1 tick per every 5 CLAIM body parts (so the creep must have at least 5xCLAIM). The controller under attack cannot be upgraded for the next 1,000 ticks. The target has to be at adjacent square to the creep. 81 | * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART 82 | */ 83 | attackController(target: Controller): number; 84 | /** 85 | * Build a structure at the target construction site using carried energy. Needs WORK and CARRY body parts. The target has to be within 3 squares range of the creep. 86 | * @param target The target object to be attacked. 87 | * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART, ERR_RCL_NOT_ENOUGH 88 | */ 89 | build(target: ConstructionSite): number; 90 | /** 91 | * Cancel the order given during the current game tick. 92 | * @param methodName The name of a creep's method to be cancelled. 93 | * @returns Result Code: OK, ERR_NOT_FOUND 94 | */ 95 | cancelOrder(methodName: string): number; 96 | /** 97 | * Requires the CLAIM body part. If applied to a neutral controller, claims it under your control. If applied to a hostile controller, decreases its downgrade or reservation timer depending on the CLAIM body parts count. The target has to be at adjacent square to the creep. 98 | * @param target The target controller object. 99 | * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_FULL, ERR_NOT_IN_RANGE, ERR_NO_BODYPART, ERR_GCL_NOT_ENOUGH 100 | */ 101 | claimController(target: Controller): number; 102 | /** 103 | * Dismantles any (even hostile) structure returning 50% of the energy spent on its repair. Requires the WORK body part. If the creep has an empty CARRY body part, the energy is put into it; otherwise it is dropped on the ground. The target has to be at adjacent square to the creep. 104 | * @param target The target structure. 105 | */ 106 | dismantle(target: Structure): number; 107 | /** 108 | * Drop this resource on the ground. 109 | * @param resourceType One of the RESOURCE_* constants. 110 | * @param amount The amount of resource units to be dropped. If omitted, all the available carried amount is used. 111 | */ 112 | drop(resourceType: string, amount?: number): number; 113 | /** 114 | * Add one more available safe mode activation to a room controller. The creep has to be at adjacent square to the target room controller and have 1000 ghodium resource. 115 | * @param target The target room controller. 116 | * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE 117 | */ 118 | generateSafeMode(target: Controller): number; 119 | /** 120 | * Get the quantity of live body parts of the given type. Fully damaged parts do not count. 121 | * @param type A body part type, one of the following body part constants: MOVE, WORK, CARRY, ATTACK, RANGED_ATTACK, HEAL, TOUGH, CLAIM 122 | */ 123 | getActiveBodyparts(type: string): number; 124 | /** 125 | * Harvest energy from the source. Needs the WORK body part. If the creep has an empty CARRY body part, the harvested energy is put into it; otherwise it is dropped on the ground. The target has to be at an adjacent square to the creep. 126 | * @param target The source object to be harvested. 127 | */ 128 | harvest(target: Source | Mineral): number; 129 | /** 130 | * Heal self or another creep. It will restore the target creep’s damaged body parts function and increase the hits counter. Needs the HEAL body part. The target has to be at adjacent square to the creep. 131 | * @param target The target creep object. 132 | */ 133 | heal(target: Creep): number; 134 | /** 135 | * Move the creep one square in the specified direction. Needs the MOVE body part. 136 | * @param direction 137 | */ 138 | move(direction: number) : number; 139 | /** 140 | * Move the creep using the specified predefined path. Needs the MOVE body part. 141 | * @param path A path value as returned from Room.findPath or RoomPosition.findPathTo methods. Both array form and serialized string form are accepted. 142 | */ 143 | moveByPath(path: PathStep[] | RoomPosition[] | string): number; 144 | /** 145 | * Find the optimal path to the target within the same room and move to it. A shorthand to consequent calls of pos.findPathTo() and move() methods. If the target is in another room, then the corresponding exit will be used as a target. Needs the MOVE body part. 146 | * @param x X position of the target in the room. 147 | * @param y Y position of the target in the room. 148 | * @param opts An object containing pathfinding options flags (see Room.findPath for more info) or one of the following: reusePath, serializeMemory, noPathFinding 149 | */ 150 | moveTo(x: number, y: number, opts?: MoveToOpts): number; 151 | /** 152 | * Find the optimal path to the target within the same room and move to it. A shorthand to consequent calls of pos.findPathTo() and move() methods. If the target is in another room, then the corresponding exit will be used as a target. Needs the MOVE body part. 153 | * @param target Can be a RoomPosition object or any object containing RoomPosition. 154 | * @param opts An object containing pathfinding options flags (see Room.findPath for more info) or one of the following: reusePath, serializeMemory, noPathFinding 155 | */ 156 | moveTo(target: RoomPosition|{pos: RoomPosition}, opts?: MoveToOpts): number; 157 | /** 158 | * Toggle auto notification when the creep is under attack. The notification will be sent to your account email. Turned on by default. 159 | * @param enabled Whether to enable notification or disable. 160 | */ 161 | notifyWhenAttacked(enabled: boolean): number; 162 | /** 163 | * Pick up an item (a dropped piece of energy). Needs the CARRY body part. The target has to be at adjacent square to the creep or at the same square. 164 | * @param target The target object to be picked up. 165 | */ 166 | pickup(target: Resource): number; 167 | /** 168 | * A ranged attack against another creep or structure. Needs the RANGED_ATTACK body part. If the target is inside a rampart, the rampart is attacked instead. The target has to be within 3 squares range of the creep. 169 | * @param target The target object to be attacked. 170 | */ 171 | rangedAttack(target: Creep|Structure): number; 172 | /** 173 | * Heal another creep at a distance. It will restore the target creep’s damaged body parts function and increase the hits counter. Needs the HEAL body part. The target has to be within 3 squares range of the creep. 174 | * @param target The target creep object. 175 | */ 176 | rangedHeal(target: Creep): number; 177 | /** 178 | * A ranged attack against all hostile creeps or structures within 3 squares range. Needs the RANGED_ATTACK body part. The attack power depends on the range to each target. Friendly units are not affected. 179 | */ 180 | rangedMassAttack(): number; 181 | /** 182 | * Repair a damaged structure using carried energy. Needs the WORK and CARRY body parts. The target has to be within 3 squares range of the creep. 183 | * @param target he target structure to be repaired. 184 | */ 185 | repair(target: Structure): number; 186 | /** 187 | * Temporarily block a neutral controller from claiming by other players. Each tick, this command increases the counter of the period during which the controller is unavailable by 1 tick per each CLAIM body part. The maximum reservation period to maintain is 5,000 ticks. The target has to be at adjacent square to the creep.... 188 | * @param target The target controller object to be reserved. 189 | * @return Result code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART 190 | */ 191 | reserveController(target: Controller): number; 192 | /** 193 | * Display a visual speech balloon above the creep with the specified message. The message will disappear after a few seconds. Useful for debugging purposes. Only the creep's owner can see the speech message. 194 | * @param message The message to be displayed. Maximum length is 10 characters. 195 | * @param set to 'true' to allow other players to see this message. Default is 'false'. 196 | */ 197 | say(message: string, toPublic?: boolean): number; 198 | /** 199 | * Sign a controller with a random text visible to all players. This text will appear in the room UI, in the world map, and can be accessed via the API. 200 | * You can sign unowned and hostile controllers. The target has to be at adjacent square to the creep. Pass an empty string to remove the sign. 201 | * @param target The target controller object to be signed. 202 | * @param text The sign text. The maximum text length is 100 characters. 203 | * @returns Result Code: OK, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE 204 | */ 205 | signController(target:Controller, text:string): number; 206 | /** 207 | * Kill the creep immediately. 208 | */ 209 | suicide(): number; 210 | /** 211 | * Transfer resource from the creep to another object. The target has to be at adjacent square to the creep. 212 | * @param target The target object. 213 | * @param resourceType One of the RESOURCE_* constants 214 | * @param amount The amount of resources to be transferred. If omitted, all the available carried amount is used. 215 | */ 216 | transfer(target: Creep|Structure, resourceType: string, amount?: number): number; 217 | /** 218 | * Upgrade your controller to the next level using carried energy. Upgrading controllers raises your Global Control Level in parallel. Needs WORK and CARRY body parts. The target has to be at adjacent square to the creep. A fully upgraded level 8 controller can't be upgraded with the power over 15 energy units per tick regardless of creeps power. The cumulative effect of all the creeps performing upgradeController in the current tick is taken into account. 219 | * @param target The target controller object to be upgraded. 220 | */ 221 | upgradeController(target: Controller): number; 222 | /** 223 | * Withdraw resources from a structure. The target has to be at adjacent square to the creep. Multiple creeps can withdraw from the same structure in the same tick. Your creeps can withdraw resources from hostile structures as well, in case if there is no hostile rampart on top of it. 224 | * @param target The target object. 225 | * @param resourceType The target One of the RESOURCE_* constants.. 226 | * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. 227 | */ 228 | withdraw(target: Structure, resourceType: string, amount?: number): number; 229 | } 230 | 231 | interface CreepConstructor extends _Constructor, _ConstructorById { 232 | } 233 | 234 | declare const Creep: CreepConstructor; 235 | -------------------------------------------------------------------------------- /src/flag.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A flag. Flags can be used to mark particular spots in a room. Flags are visible to their owners only. 3 | */ 4 | interface Flag extends RoomObject { 5 | readonly prototype: Flag; 6 | 7 | /** 8 | * Flag color. One of the following constants: COLOR_WHITE, COLOR_GREY, COLOR_RED, COLOR_PURPLE, COLOR_BLUE, COLOR_CYAN, COLOR_GREEN, COLOR_YELLOW, COLOR_ORANGE, COLOR_BROWN 9 | */ 10 | color: number; 11 | /** 12 | * A shorthand to Memory.flags[flag.name]. You can use it for quick access the flag's specific memory data object. 13 | */ 14 | memory: any; 15 | /** 16 | * Flag’s name. You can choose the name while creating a new flag, and it cannot be changed later. This name is a hash key to access the spawn via the Game.flags object. 17 | */ 18 | name: string; 19 | /** 20 | * Flag secondary color. One of the COLOR_* constants. 21 | */ 22 | secondaryColor: number; 23 | /** 24 | * Remove the flag. 25 | * @returns Result Code: OK 26 | */ 27 | remove(): number; 28 | /** 29 | * Set new color of the flag. 30 | * @param color One of the following constants: COLOR_WHITE, COLOR_GREY, COLOR_RED, COLOR_PURPLE, COLOR_BLUE, COLOR_CYAN, COLOR_GREEN, COLOR_YELLOW, COLOR_ORANGE, COLOR_BROWN 31 | * @parma secondaryColor Secondary color of the flag. One of the COLOR_* constants. 32 | * @returns Result Code: OK, ERR_INVALID_ARGS 33 | */ 34 | setColor(color: number, secondaryColor?: number): number; 35 | /** 36 | * Set new position of the flag. 37 | * @param x The X position in the room. 38 | * @param y The Y position in the room. 39 | * @returns Result Code: OK, ERR_INVALID_TARGET 40 | */ 41 | setPosition(x: number,y: number): number; 42 | /** 43 | * Set new position of the flag. 44 | * @param pos Can be a RoomPosition object or any object containing RoomPosition. 45 | * @returns Result Code: OK, ERR_INVALID_TARGET 46 | */ 47 | setPosition(pos: RoomPosition|{pos: RoomPosition}): number; 48 | } 49 | 50 | interface FlagConstructor extends _Constructor { 51 | new (name: string, color: number, secondaryColor: number, roomName: string, x: number, y: number): Flag; 52 | (name: string, color: number, secondaryColor: number, roomName: string, x: number, y: number): Flag; 53 | } 54 | 55 | declare const Flag: FlagConstructor; 56 | -------------------------------------------------------------------------------- /src/game.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The main global game object containing all the gameplay information. 3 | */ 4 | interface Game { 5 | /** 6 | * An object containing information about your CPU usage with the following properties: 7 | */ 8 | cpu: CPU; 9 | /** 10 | * A hash containing all your creeps with creep names as hash keys. 11 | */ 12 | creeps: {[creepName: string]: Creep}; 13 | /** 14 | * A hash containing all your flags with flag names as hash keys. 15 | */ 16 | flags: {[flagName: string]: Flag}; 17 | /** 18 | * Your Global Control Level, an object with the following properties : 19 | */ 20 | gcl: GlobalControlLevel; 21 | /** 22 | * A global object representing world GameMap. 23 | */ 24 | map: GameMap; 25 | /** 26 | * A global object representing the in-game market. 27 | */ 28 | market: Market; 29 | /** 30 | * A hash containing all the rooms available to you with room names as hash keys. 31 | */ 32 | rooms: {[roomName: string]: Room}; 33 | /** 34 | * A hash containing all your spawns with spawn names as hash keys. 35 | */ 36 | spawns: {[spawnName: string]: Spawn}; 37 | /** 38 | * A hash containing all your structures with structure id as hash keys. 39 | */ 40 | structures: {[structureId: string]: Structure}; 41 | 42 | /** 43 | * A hash containing all your construction sites with their id as hash keys. 44 | */ 45 | constructionSites: {[constructionSiteId: string]: ConstructionSite}; 46 | /** 47 | * System game tick counter. It is automatically incremented on every tick. 48 | */ 49 | time: number; 50 | 51 | /** 52 | * Get an object with the specified unique ID. It may be a game object of any type. Only objects from the rooms which are visible to you can be accessed. 53 | * @param id The unique identifier. 54 | * @returns an object instance or null if it cannot be found. 55 | */ 56 | getObjectById(id: string | undefined): T | null; 57 | /** 58 | * Send a custom message at your profile email. This way, you can set up notifications to yourself on any occasion within the game. You can schedule up to 20 notifications during one game tick. Not available in the Simulation Room. 59 | * @param message Custom text which will be sent in the message. Maximum length is 1000 characters. 60 | * @param 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. 61 | */ 62 | notify(message: string, groupInterval?: number): void; 63 | } 64 | -------------------------------------------------------------------------------- /src/helpers.ts: -------------------------------------------------------------------------------- 1 | interface GlobalControlLevel { 2 | level: number; 3 | progress: number; 4 | progressTotal: number; 5 | } 6 | 7 | interface HeapStatistics { 8 | total_heap_size: number, 9 | total_heap_size_executable: number, 10 | total_physical_size: number, 11 | total_available_size: number, 12 | used_heap_size: number, 13 | heap_size_limit: number, 14 | malloced_memory: number, 15 | peak_malloced_memory: number, 16 | does_zap_garbage: 0 | 1, 17 | externally_allocated_size: number 18 | } 19 | 20 | interface CPU { 21 | limit: number; 22 | tickLimit: number; 23 | bucket: number; 24 | 25 | /** 26 | * Get amount of CPU time used from the beginning of the current game tick. Always returns 0 in the Simulation mode. 27 | */ 28 | getUsed(): number; 29 | getHeapStatistics() : HeapStatistics; 30 | } 31 | 32 | /** 33 | * An array describing the creep’s body. Each element contains the following properties: 34 | */ 35 | interface BodyPartDefinition { 36 | /** 37 | * If the body part is boosted, this property specifies the mineral type which is used for boosting. One of the RESOURCE_* constants. 38 | */ 39 | boost: string; 40 | /** 41 | * One of the body part types constants. 42 | */ 43 | type: string; 44 | /** 45 | * The remaining amount of hit points of this body part. 46 | */ 47 | hits: number; 48 | } 49 | interface Owner { 50 | username: string; 51 | } 52 | interface ReservationDefinition { 53 | username: string, 54 | ticksToEnd: number 55 | } 56 | interface SignDefinition { 57 | username: string; 58 | text: string; 59 | time: number, 60 | datetime: Date; 61 | } 62 | interface StoreDefinition { 63 | [resource: string]: number | undefined; 64 | energy?: number; 65 | power?: number; 66 | } 67 | 68 | interface LookAtResultWithPos { 69 | x: number; 70 | y: number; 71 | type: string; 72 | constructionSite?: ConstructionSite; 73 | creep?: Creep; 74 | terrain?: string; 75 | structure?: Structure; 76 | flag?: Flag; 77 | energy?: Resource; 78 | exit?: any; 79 | source?: Source; 80 | mineral?: Mineral; 81 | resource? : Resource; 82 | } 83 | interface LookAtResult { 84 | type: string; 85 | constructionSite?: ConstructionSite; 86 | creep?: Creep; 87 | energy?: Resource; 88 | exit?: any; 89 | flag?: Flag; 90 | source?: Source; 91 | structure?: Structure; 92 | terrain?: string; 93 | mineral?: Mineral; 94 | resource?: Resource; 95 | } 96 | 97 | 98 | interface LookAtResultMatrix { 99 | [coord: number]: LookAtResultMatrix|LookAtResult[] 100 | } 101 | 102 | interface FindPathOpts { 103 | /** 104 | * Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default 105 | * value is false. 106 | */ 107 | ignoreCreeps?: boolean; 108 | 109 | /** 110 | * Treat squares with destructible structures (constructed walls, ramparts, spawns, extensions) as walkable. Use this flag when 111 | * you need to move through a territory blocked by hostile structures. If a creep with an ATTACK body part steps on such a square, 112 | * it automatically attacks the structure. The default value is false. 113 | */ 114 | ignoreDestructibleStructures?: boolean; 115 | 116 | /** 117 | * Ignore road structures. Enabling this option can speed up the search. The default value is false. This is only used when the 118 | * new PathFinder is enabled. 119 | */ 120 | ignoreRoads?: boolean; 121 | 122 | /** 123 | * You can use this callback to modify a CostMatrix for any room during the search. The callback accepts two arguments, roomName 124 | * and costMatrix. Use the costMatrix instance to make changes to the positions costs. If you return a new matrix from this callback, 125 | * it will be used instead of the built-in cached one. This option is only used when the new PathFinder is enabled. 126 | * 127 | * @param roomName The name of the room. 128 | * @param costMatrix The current CostMatrix 129 | * @returns The new CostMatrix to use 130 | */ 131 | costCallback?(roomName: string, costMatrix: CostMatrix): boolean | CostMatrix; 132 | 133 | /** 134 | * An array of the room's objects or RoomPosition objects which should be treated as walkable tiles during the search. This option 135 | * cannot be used when the new PathFinder is enabled (use costCallback option instead). 136 | */ 137 | ignore?: any[]|RoomPosition[]; 138 | 139 | /** 140 | * An array of the room's objects or RoomPosition objects which should be treated as obstacles during the search. This option cannot 141 | * be used when the new PathFinder is enabled (use costCallback option instead). 142 | */ 143 | avoid?: any[]|RoomPosition[]; 144 | 145 | /** 146 | * The maximum limit of possible pathfinding operations. You can limit CPU time used for the search based on ratio 1 op ~ 0.001 CPU. 147 | * The default value is 2000. 148 | */ 149 | maxOps?: number; 150 | 151 | /** 152 | * Weight to apply to the heuristic in the A* formula F = G + weight * H. Use this option only if you understand the underlying 153 | * A* algorithm mechanics! The default value is 1.2. 154 | */ 155 | heuristicWeight?: number; 156 | 157 | /** 158 | * If true, the result path will be serialized using Room.serializePath. The default is false. 159 | */ 160 | serialize?: boolean; 161 | 162 | /** 163 | * The maximum allowed rooms to search. The default (and maximum) is 16. This is only used when the new PathFinder is enabled. 164 | */ 165 | maxRooms?: number; 166 | 167 | /** 168 | * Path to within (range) tiles of target tile. The default is to path to the tile that the target is on (0). 169 | */ 170 | range?: number; 171 | } 172 | 173 | interface MoveToOpts extends FindPathOpts { 174 | /** 175 | * This option enables reusing the path found along multiple game ticks. It allows to save CPU time, but can result in a slightly 176 | * slower creep reaction behavior. The path is stored into the creep's memory to the _move property. The reusePath value defines 177 | * the amount of ticks which the path should be reused for. The default value is 5. Increase the amount to save more CPU, decrease 178 | * to make the movement more consistent. Set to 0 if you want to disable path reusing. 179 | */ 180 | reusePath?: number; 181 | 182 | /** 183 | * If reusePath is enabled and this option is set to true, the path will be stored in memory in the short serialized form using 184 | * Room.serializePath. The default value is true. 185 | */ 186 | serializeMemory?: boolean; 187 | 188 | /** 189 | * If this option is set to true, moveTo method will return ERR_NOT_FOUND if there is no memorized path to reuse. This can 190 | * significantly save CPU time in some cases. The default value is false. 191 | */ 192 | noPathFinding?: boolean; 193 | 194 | /** 195 | * Draw a line along the creep’s path using RoomVisual.poly. You can provide either an empty object or custom style parameters. 196 | */ 197 | visualizePathStyle?: PolyStyle; 198 | }; 199 | 200 | interface PathStep { 201 | x: number; 202 | dx: number; 203 | y: number; 204 | dy: number; 205 | direction: number; 206 | } 207 | 208 | /** 209 | * An object with survival game info 210 | */ 211 | interface SurvivalGameInfo { 212 | /** 213 | * Current score. 214 | */ 215 | score: number; 216 | /** 217 | * Time to the next wave of invaders. 218 | */ 219 | timeToWave: number; 220 | /** 221 | * The number of the next wave. 222 | */ 223 | wave: number; 224 | } 225 | 226 | interface _Constructor { 227 | readonly prototype: T; 228 | } 229 | 230 | interface _ConstructorById extends _Constructor { 231 | new (id: string): T; 232 | (id: string): T; 233 | } 234 | -------------------------------------------------------------------------------- /src/map.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The options that can be accepted by `findRoute()` and friends. 3 | */ 4 | interface RouteOptions { 5 | routeCallback: { 6 | (roomName: string, fromRoomName: string): any 7 | } 8 | } 9 | 10 | /** 11 | * A global object representing world map. Use it to navigate between rooms. The object is accessible via Game.map property. 12 | */ 13 | interface GameMap { 14 | /** 15 | * List all exits available from the room with the given name. 16 | * @param roomName The room name. 17 | * @returns The exits information or null if the room not found. 18 | */ 19 | describeExits(roomName: string): {"1"?: string, "3"?: string, "5"?: string, "7"?: string}; 20 | /** 21 | * Find the exit direction from the given room en route to another room. 22 | * @param fromRoom Start room name or room object. 23 | * @param toRoom Finish room name or room object. 24 | * @param opts (optional) An object with the pathfinding options. 25 | * @return The room direction constant, one of the following: 26 | * FIND_EXIT_TOP, FIND_EXIT_RIGHT, FIND_EXIT_BOTTOM, FIND_EXIT_LEFT 27 | * Or one of the following Result codes: 28 | * ERR_NO_PATH, ERR_INVALID_ARGS 29 | */ 30 | findExit(fromRoom: string|Room, toRoom: string|Room, opts?: RouteOptions): number; 31 | /** 32 | * Find route from the given room to another room. 33 | * @param fromRoom Start room name or room object. 34 | * @param toRoom Finish room name or room object. 35 | * @param opts (optional) An object with the pathfinding options. 36 | * @returns the route array or ERR_NO_PATH code 37 | */ 38 | findRoute(fromRoom: string | Room, toRoom: string | Room, opts?: RouteOptions): { 39 | exit: number; 40 | room: string; 41 | }[] | number; 42 | /** 43 | * Get the linear distance (in rooms) between two rooms. You can use this function to estimate the energy cost of 44 | * sending resources through terminals, or using observers and nukes. 45 | * @param roomName1 The name of the first room. 46 | * @param roomName2 The name of the second room. 47 | * @param continuous Whether to treat the world map continuous on borders. Set to true if you 48 | * want to calculate the trade or terminal send cost. Default is false. 49 | */ 50 | getRoomLinearDistance(roomName1: string, roomName2: string, continuous?: boolean): number; 51 | /** 52 | * Get terrain type at the specified room position. This method works for any room in the world even if you have no access to it. 53 | * @param x X position in the room. 54 | * @param y Y position in the room. 55 | * @param roomName The room name. 56 | */ 57 | getTerrainAt(x: number, y: number, roomName: string): string; 58 | /** 59 | * Get terrain type at the specified room position. This method works for any room in the world even if you have no access to it. 60 | * @param pos The position object. 61 | */ 62 | getTerrainAt(pos: RoomPosition): string; 63 | 64 | /** 65 | * Check if the room is available to move into. 66 | * @param roomName The room name. 67 | * @returns A boolean value. 68 | */ 69 | isRoomAvailable(roomName: string): boolean; 70 | } 71 | 72 | //No static is available 73 | -------------------------------------------------------------------------------- /src/market.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A global object representing the in-game market. You can use this object to track resource transactions to/from your 3 | * terminals, and your buy/sell orders. The object is accessible via the singleton Game.market property. 4 | */ 5 | interface Market { 6 | /** 7 | * Your current credits balance. 8 | */ 9 | credits: number; 10 | /** 11 | * An array of the last 100 incoming transactions to your terminals 12 | */ 13 | incomingTransactions: Transaction[]; 14 | /** 15 | * An object with your active and inactive buy/sell orders on the market. 16 | */ 17 | orders: { [key: string]: Order }; 18 | /** 19 | * An array of the last 100 outgoing transactions from your terminals 20 | */ 21 | outgoingTransactions: Transaction[]; 22 | /** 23 | * Estimate the energy transaction cost of StructureTerminal.send and Market.deal methods. The formula: Math.ceil( amount * (Math.log(0.1*linearDistanceBetweenRooms + 0.9) + 0.1) ) 24 | * @param amount Amount of resources to be sent. 25 | * @param roomName1 The name of the first room. 26 | * @param roomName2 The name of the second room. 27 | * @returns The amount of energy required to perform the transaction. 28 | */ 29 | calcTransactionCost(amount: number, roomName1: string, roomName2: string): number; 30 | /** 31 | * Cancel a previously created order. The 5% fee is not returned. 32 | * @param orderId The order ID as provided in Game.market.orders 33 | * @returns Result Code: OK, ERR_INVALID_ARGS 34 | */ 35 | cancelOrder(orderId: string): number; 36 | /** 37 | * Change the price of an existing order. If newPrice is greater than old price, you will be charged (newPrice-oldPrice)*remainingAmount*0.05 credits. 38 | * @param orderId The order ID as provided in Game.market.orders 39 | * @param newPrice The new order price. 40 | * @returns Result Code: OK, ERR_NOT_OWNER, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_ARGS 41 | */ 42 | changeOrderPrice(orderId: string, newPrice: number): number; 43 | /** 44 | * Create a market order in your terminal. You will be charged price*amount*0.05 credits when the order is placed. 45 | * The maximum orders count is 20 per player. You can create an order at any time with any amount, 46 | * it will be automatically activated and deactivated depending on the resource/credits availability. 47 | */ 48 | createOrder(type: string, resourceType: string, price: number, totalAmount: number, roomName?: string): number; 49 | /** 50 | * Execute a trade deal from your Terminal to another player's Terminal using the specified buy/sell order. 51 | * Your Terminal will be charged energy units of transfer cost regardless of the order resource type. 52 | * You can use Game.market.calcTransactionCost method to estimate it. 53 | * When multiple players try to execute the same deal, the one with the shortest distance takes precedence. 54 | */ 55 | deal(orderId: string, amount: number, targetRoomName?: string): number; 56 | /** 57 | * Add more capacity to an existing order. It will affect remainingAmount and totalAmount properties. You will be charged price*addAmount*0.05 credits. 58 | * @param orderId The order ID as provided in Game.market.orders 59 | * @param addAmount How much capacity to add. Cannot be a negative value. 60 | * @returns Result Code: OK, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_ARGS 61 | */ 62 | extendOrder(orderId: string, addAmount: number): number; 63 | /** 64 | * Get other players' orders currently active on the market. 65 | * @param filter (optional) An object or function that will filter the resulting list using the lodash.filter method. 66 | * @returns An array of objects containing order information. 67 | */ 68 | getAllOrders(filter?: OrderFilter | ((o: Order) => boolean)): Order[]; 69 | /** 70 | * Retrieve info for specific market order. 71 | * @param orderId The order ID 72 | * @returns An object with the order info. See getAllOrders for properties explanation. 73 | */ 74 | getOrderById(id: string): Order | null; 75 | } 76 | 77 | //No static is available 78 | 79 | interface Transaction { 80 | transactionId: string; 81 | time: number; 82 | sender?: { username: string }; 83 | recipient?: { username: string }; 84 | resourceType: string; 85 | amount: number; 86 | from: string; 87 | to: string; 88 | description: string; 89 | } 90 | 91 | interface Order { 92 | id: string; 93 | created: number; 94 | active?: boolean; 95 | type: string; 96 | resourceType: string; 97 | roomName?: string; 98 | amount: number; 99 | remainingAmount: number; 100 | totalAmount?: number; 101 | price: number; 102 | } 103 | 104 | interface OrderFilter { 105 | id?: string; 106 | created?: number; 107 | type?: string; 108 | resourceType?: string; 109 | roomName?: string; 110 | amount?: number; 111 | remainingAmount?: number; 112 | price?: number; 113 | } 114 | -------------------------------------------------------------------------------- /src/memory.ts: -------------------------------------------------------------------------------- 1 | interface Memory { 2 | [name: string]: any; 3 | creeps: {[name: string]: any}; 4 | flags: {[name: string]: any}; 5 | rooms: {[name: string]: any}; 6 | spawns: {[name: string]: any}; 7 | } 8 | -------------------------------------------------------------------------------- /src/mineral.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A mineral deposit object. Can be harvested by creeps with a WORK body part using the extractor structure. 3 | */ 4 | interface Mineral extends RoomObject { 5 | /** 6 | * The prototype is stored in the Mineral.prototype global object. You can use it to extend game objects behaviour globally. 7 | */ 8 | readonly prototype: Mineral; 9 | /** 10 | * The density of this mineral deposit, one of the DENSITY_* constants. 11 | */ 12 | density: number; 13 | /** 14 | * The remaining amount of resources. 15 | */ 16 | mineralAmount: number; 17 | /** 18 | * The resource type, one of the RESOURCE_* constants. 19 | */ 20 | mineralType: string; 21 | /** 22 | * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. 23 | */ 24 | id: string; 25 | /** 26 | * The remaining time after which the deposit will be refilled. 27 | */ 28 | ticksToRegeneration: number; 29 | 30 | } 31 | 32 | interface MineralConstructor extends _Constructor, _ConstructorById { 33 | } 34 | 35 | declare const Mineral: MineralConstructor; 36 | -------------------------------------------------------------------------------- /src/nuke.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A nuke landing position. This object cannot be removed or modified. You can find incoming nukes in the room using the FIND_NUKES constant. 3 | */ 4 | interface Nuke extends RoomObject { 5 | readonly prototype: Nuke; 6 | 7 | /** 8 | * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. 9 | */ 10 | id: string; 11 | /** 12 | * The name of the room where this nuke has been launched from. 13 | */ 14 | launchRoomName: string; 15 | /** 16 | * The remaining landing time. 17 | */ 18 | timeToLand: number; 19 | } 20 | 21 | interface NukeConstructor { 22 | new (id: string): Nuke; 23 | } 24 | 25 | declare const Nuke: NukeConstructor; 26 | -------------------------------------------------------------------------------- /src/path-finder.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains powerful methods for pathfinding in the game world. Support exists for custom navigation costs and paths which span multiple rooms. 3 | * Additionally PathFinder can search for paths through rooms you can't see, although you won't be able to detect any dynamic obstacles like creeps or buildings. 4 | */ 5 | interface PathFinder { 6 | /** 7 | * Container for custom navigation cost data. 8 | */ 9 | CostMatrix: CostMatrix; 10 | 11 | /** 12 | * Find an optimal path between origin and goal. 13 | * 14 | * @param origin The start position. 15 | * @param goal goal A RoomPosition or an object containing a RoomPosition and range 16 | * @param opts An object containing additional pathfinding flags. 17 | */ 18 | search(origin: RoomPosition, goal: RoomPosition|{pos: RoomPosition, range: number}, opts?: PathFinderOpts): PathFinderPath; 19 | /** 20 | * Find an optimal path between origin and goal. 21 | * 22 | * @param origin The start position. 23 | * @param goal an array of goals, the cheapest path found out of all the goals will be returned. 24 | * @param opts An object containing additional pathfinding flags. 25 | */ 26 | search(origin: RoomPosition, goal: RoomPosition[]|{pos: RoomPosition, range: number}[], opts?: PathFinderOpts): PathFinderPath; 27 | /** 28 | * Specify whether to use this new experimental pathfinder in game objects methods. 29 | * This method should be invoked every tick. It affects the following methods behavior: 30 | * Room.findPath, RoomPosition.findPathTo, RoomPosition.findClosestByPath, Creep.moveTo.... 31 | * 32 | * @param isEnabled Whether to activate the new pathfinder or deactivate. 33 | */ 34 | use(isEnabled: boolean): void; 35 | } 36 | 37 | /** 38 | * An object containing: 39 | * path - An array of RoomPosition objects. 40 | * ops - Total number of operations performed before this path was calculated. 41 | * cost - The total cost of the path as derived from `plainCost`, `swampCost` and any given CostMatrix instances. 42 | * incomplete - If the pathfinder fails to find a complete path, this will be true. 43 | * Note that `path` will still be populated with a partial path which represents the closest path it could find given the search parameters. 44 | */ 45 | interface PathFinderPath { 46 | path: RoomPosition[]; 47 | ops: number; 48 | cost: number; 49 | incomplete: boolean; 50 | } 51 | 52 | /** 53 | * An object containing additional pathfinding flags. 54 | */ 55 | interface PathFinderOpts { 56 | /** 57 | * Cost for walking on plain positions. The default is 1. 58 | */ 59 | plainCost?: number; 60 | /** 61 | * Cost for walking on swamp positions. The default is 5. 62 | */ 63 | swampCost?: number; 64 | /** 65 | * Instead of searching for a path to the goals this will search for a path away from the goals. 66 | * The cheapest path that is out of range of every goal will be returned. The default is false. 67 | */ 68 | flee?: boolean; 69 | /** 70 | * 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. 71 | */ 72 | maxOps?: number; 73 | /** 74 | * The maximum allowed rooms to search. The default (and maximum) is 16. 75 | */ 76 | maxRooms?: number; 77 | /** 78 | * Weight to apply to the heuristic in the A* formula F = G + weight * H. Use this option only if you understand 79 | * the underlying A* algorithm mechanics! The default value is 1. 80 | */ 81 | heuristicWeight?: number; 82 | 83 | /** 84 | * Request from the pathfinder to generate a CostMatrix for a certain room. The callback accepts one argument, roomName. 85 | * This callback will only be called once per room per search. If you are running multiple pathfinding operations in a 86 | * single room and in a single tick you may consider caching your CostMatrix to speed up your code. Please read the 87 | * CostMatrix documentation below for more information on CostMatrix. 88 | * 89 | * @param roomName 90 | */ 91 | roomCallback?(roomName: string): boolean | CostMatrix; 92 | } 93 | 94 | /** 95 | * Container for custom navigation cost data. 96 | */ 97 | interface CostMatrix { 98 | /** 99 | * Creates a new CostMatrix containing 0's for all positions. 100 | * @constructor 101 | */ 102 | new(): CostMatrix; 103 | /** 104 | * Set the cost of a position in this CostMatrix. 105 | * @param x X position in the room. 106 | * @param y Y position in the room. 107 | * @param 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. 108 | */ 109 | set(x: number, y: number, cost: number): void; 110 | /** 111 | * Get the cost of a position in this CostMatrix. 112 | * @param x X position in the room. 113 | * @param y Y position in the room. 114 | */ 115 | get(x: number, y: number): number; 116 | /** 117 | * Copy this CostMatrix into a new CostMatrix with the same data. 118 | */ 119 | clone(): CostMatrix; 120 | /** 121 | * Returns a compact representation of this CostMatrix which can be stored via JSON.stringify. 122 | */ 123 | serialize(): number[]; 124 | /** 125 | * Static method which deserializes a new CostMatrix using the return value of serialize. 126 | * @param val Whatever serialize returned 127 | */ 128 | deserialize(val: number[]): CostMatrix; 129 | } 130 | -------------------------------------------------------------------------------- /src/raw-memory.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * RawMemory object allows to implement your own memory stringifier instead of built-in serializer based on JSON.stringify. 3 | */ 4 | interface RawMemory { 5 | 6 | /** 7 | * An object with asynchronous memory segments available on this tick. Each object key is the segment ID with data in string values. 8 | * Use RawMemory.setActiveSegments to fetch segments on the next tick. Segments data is saved automatically in the end of the tick. 9 | */ 10 | segments: string[]; 11 | /** 12 | * An object with a memory segment of another player available on this tick. 13 | * Use setActiveForeignSegment to fetch segments on the next tick. The object consists of the following properties: 14 | * @type {ForeignMemorySegment} 15 | */ 16 | foreignSegment: ForeignMemorySegment; 17 | /** 18 | * Get a raw string representation of the Memory object. 19 | */ 20 | get(): string; 21 | /** 22 | * Set new memory value. 23 | * @param value New memory value as a string. 24 | */ 25 | set(value: string): void; 26 | /** 27 | * Request memory segments using the list of their IDs. Memory segments will become available on the next tick in RawMemory.segments object. 28 | * @param ids An array of segment IDs. Each ID should be a number from 0 to 99. Maximum 10 segments can be active at the same time. Subsequent calls of setActiveSegments override previous ones. 29 | */ 30 | setActiveSegments(ids: number[]): void; 31 | /** 32 | * Request a memory segment of another user. 33 | * The segment should be marked by its owner as public using setPublicSegments. 34 | * The segment data will become available on the next tick in foreignSegment object. 35 | * You can only have access to one foreign segment at the same time. 36 | * @param {(string | null)} username The name of another user. Pass null to clear the foreign segment. 37 | * @param {number} [id] The ID of the requested segment from 0 to 99. If undefined, the user's default public segment is requested as set by setDefaultPublicSegment. 38 | */ 39 | setActiveForeignSegment(username: string | null, id?: number): void; 40 | /** 41 | * Set the specified segment as your default public segment. 42 | * It will be returned if no id parameter is passed to setActiveForeignSegment by another user. 43 | * @param {(number | null)} id The ID of the memory segment from 0 to 99. Pass null to remove your default public segment. 44 | */ 45 | setDefaultPublicSegment(id: number | null): void; 46 | /** 47 | * Set specified segments as public. Other users will be able to request access to them using setActiveForeignSegment. 48 | * @param {number[]} ids An array of segment IDs. Each ID should be a number from 0 to 99. Subsequent calls of setPublicSegments override previous ones. 49 | */ 50 | setPublicSegments(ids: number[]): void; 51 | } 52 | 53 | interface ForeignMemorySegment { 54 | username: string, 55 | id: number, 56 | data: string 57 | } -------------------------------------------------------------------------------- /src/resource.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A dropped piece of resource. It will decay after a while if not picked up. Dropped resource pile decays for ceil(amount/1000) units per tick. 3 | */ 4 | 5 | interface Resource extends RoomObject { 6 | readonly prototype: Resource; 7 | 8 | /** 9 | * The amount of resource units containing. 10 | */ 11 | amount: number; 12 | /** 13 | * A unique object identifier. You can use `Game.getObjectById` method to retrieve an object instance by its `id`. 14 | */ 15 | id: string; 16 | /** 17 | * One of the `RESOURCE_*` constants. 18 | */ 19 | resourceType: string; 20 | } 21 | 22 | interface ResourceConstructor { 23 | new (id: string): Resource; 24 | } 25 | 26 | declare const Resource: ResourceConstructor; 27 | -------------------------------------------------------------------------------- /src/room-object.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Any object with a position in a room. Almost all game objects prototypes 3 | * are derived from RoomObject. 4 | */ 5 | 6 | interface RoomObject { 7 | readonly prototype: RoomObject; 8 | /** 9 | * An object representing the position of this object in the room. 10 | */ 11 | pos: RoomPosition; 12 | /** 13 | * The link to the Room object. May be undefined in case if an object is a 14 | * flag or a construction site and is placed in a room that is not visible 15 | * to you. 16 | */ 17 | room: Room | undefined; 18 | } 19 | 20 | interface RoomObjectConstructor extends _Constructor { 21 | new (x: number, y: number, roomName: string): RoomObject; 22 | (x: number, y: number, roomName: string): RoomObject; 23 | } 24 | 25 | declare const RoomObject: RoomObjectConstructor; 26 | -------------------------------------------------------------------------------- /src/room-position.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * An object representing the specified position in the room. Every object in the room contains RoomPosition as the pos property. The position object of a custom location can be obtained using the Room.getPositionAt() method or using the constructor. 3 | */ 4 | interface RoomPosition { 5 | readonly prototype: RoomPosition; 6 | 7 | /** 8 | * The name of the room. 9 | */ 10 | roomName: string; 11 | /** 12 | * X position in the room. 13 | */ 14 | x: number; 15 | /** 16 | * Y position in the room. 17 | */ 18 | y: number; 19 | /** 20 | * Create new ConstructionSite at the specified location. 21 | * @param structureType One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK 22 | */ 23 | createConstructionSite(structureType: string): number; 24 | /** 25 | * Create new Flag at the specified location. 26 | * @param 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. 27 | * @param color The color of a new flag. Should be one of the COLOR_* constants 28 | * @param secondaryColor The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color. 29 | */ 30 | createFlag(name?: string, color?: number, secondaryColor?: number): number; 31 | /** 32 | * Find an object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm. 33 | * @param type See Room.find 34 | * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm 35 | */ 36 | findClosestByPath(type: number, opts?: FindPathOpts & { filter?: any | string, algorithm?: string }): T; 37 | /** 38 | * Find an object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm. 39 | * @param objects An array of room's objects or RoomPosition objects that the search should be executed against. 40 | * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm 41 | */ 42 | findClosestByPath(objects: T[] | RoomPosition[], opts?: FindPathOpts & { filter?: any | string, algorithm?: string }): T; 43 | /** 44 | * Find an object with the shortest linear distance from the given position. 45 | * @param type See Room.find. 46 | * @param opts 47 | */ 48 | findClosestByRange(type: number, opts?: { filter: any | string }): T; 49 | /** 50 | * Find an object with the shortest linear distance from the given position. 51 | * @param objects An array of room's objects or RoomPosition objects that the search should be executed against. 52 | * @param opts An object containing one of the following options: filter 53 | */ 54 | findClosestByRange(objects: T[] | RoomPosition[], opts?: { filter: any | string }): T; 55 | /** 56 | * Find all objects in the specified linear range. 57 | * @param type See Room.find. 58 | * @param range The range distance. 59 | * @param opts See Room.find. 60 | */ 61 | findInRange(type: number, range: number, opts?: { filter?: any | string }): T[]; 62 | /** 63 | * Find all objects in the specified linear range. 64 | * @param objects An array of room's objects or RoomPosition objects that the search should be executed against. 65 | * @param range The range distance. 66 | * @param opts See Room.find. 67 | */ 68 | findInRange(objects: T[] | RoomPosition[], range: number, opts?: { filter?: any | string }): T[]; 69 | /** 70 | * Find an optimal path to the specified position using A* search algorithm. This method is a shorthand for Room.findPath. If the target is in another room, then the corresponding exit will be used as a target. 71 | * @param x X position in the room. 72 | * @param y Y position in the room. 73 | * @param opts An object containing pathfinding options flags (see Room.findPath for more details). 74 | */ 75 | findPathTo(x: number, y: number, opts?: FindPathOpts): PathStep[]; 76 | /** 77 | * Find an optimal path to the specified position using A* search algorithm. This method is a shorthand for Room.findPath. If the target is in another room, then the corresponding exit will be used as a target. 78 | * @param target Can be a RoomPosition object or any object containing RoomPosition. 79 | * @param opts An object containing pathfinding options flags (see Room.findPath for more details). 80 | */ 81 | findPathTo(target: RoomPosition | { pos: RoomPosition }, opts?: FindPathOpts): PathStep[]; 82 | /** 83 | * Get linear direction to the specified position. 84 | * @param x X position in the room. 85 | * @param y Y position in the room. 86 | */ 87 | getDirectionTo(x: number, y: number): number; 88 | /** 89 | * Get linear direction to the specified position. 90 | * @param target Can be a RoomPosition object or any object containing RoomPosition. 91 | */ 92 | getDirectionTo(target: RoomPosition | { pos: RoomPosition }): number; 93 | /** 94 | * Get linear range to the specified position. 95 | * @param x X position in the room. 96 | * @param y Y position in the room. 97 | */ 98 | getRangeTo(x: number, y: number): number; 99 | /** 100 | * Get linear range to the specified position. 101 | * @param target Can be a RoomPosition object or any object containing RoomPosition. 102 | */ 103 | getRangeTo(target: RoomPosition | { pos: RoomPosition }): number; 104 | /** 105 | * Check whether this position is in the given range of another position. 106 | * @param toPos The target position. 107 | * @param range The range distance. 108 | */ 109 | inRangeTo(target: RoomPosition|{pos: RoomPosition}, range: number): boolean; 110 | /** 111 | * Check whether this position is the same as the specified position. 112 | * @param x X position in the room. 113 | * @param y Y position in the room. 114 | */ 115 | isEqualTo(x: number, y: number): boolean; 116 | /** 117 | * Check whether this position is the same as the specified position. 118 | * @param target Can be a RoomPosition object or any object containing RoomPosition. 119 | */ 120 | isEqualTo(target: RoomPosition | { pos: RoomPosition }): boolean; 121 | /** 122 | * Check whether this position is on the adjacent square to the specified position. The same as inRangeTo(target, 1). 123 | * @param x X position in the room. 124 | * @param y Y position in the room. 125 | */ 126 | isNearTo(x: number, y: number): boolean; 127 | /** 128 | * Check whether this position is on the adjacent square to the specified position. The same as inRangeTo(target, 1). 129 | * @param target Can be a RoomPosition object or any object containing RoomPosition. 130 | */ 131 | isNearTo(target: RoomPosition | { pos: RoomPosition }): boolean; 132 | /** 133 | * Get the list of objects at the specified room position. 134 | */ 135 | look(): LookAtResult[]; 136 | /** 137 | * Get an object with the given type at the specified room position. 138 | * @param type One of the following string constants: constructionSite, creep, exit, flag, resource, source, structure, terrain 139 | */ 140 | lookFor(type: string): T[]; 141 | } 142 | 143 | interface RoomPositionConstructor extends _Constructor { 144 | /** 145 | * You can create new RoomPosition object using its constructor. 146 | * @param x X position in the room. 147 | * @param y Y position in the room. 148 | * @param roomName The room name. 149 | */ 150 | new (x: number, y: number, roomName: string): RoomPosition; 151 | (x: number, y: number, roomName: string): RoomPosition; 152 | } 153 | 154 | declare const RoomPosition: RoomPositionConstructor; 155 | -------------------------------------------------------------------------------- /src/room-visual.ts: -------------------------------------------------------------------------------- 1 | declare class RoomVisual { 2 | /** The name of the room. */ 3 | roomName: string; 4 | 5 | /** 6 | * You can directly create new RoomVisual object in any room, even if it's invisible to your script. 7 | * @param roomName The room name. 8 | */ 9 | constructor(roomName: string); 10 | 11 | /** 12 | * Draw a line. 13 | * @param x1 The start X coordinate. 14 | * @param y1 The start Y coordinate. 15 | * @param x2 The finish X coordinate. 16 | * @param y2 The finish Y coordinate. 17 | * @param style The (optional) style. 18 | * @returns The RoomVisual object, for chaining. 19 | */ 20 | line(x1: number, y1: number, x2: number, y2: number, style?: LineStyle): RoomVisual; 21 | 22 | /** 23 | * Draw a line. 24 | * @param pos1 The start position object. 25 | * @param pos2 The finish position object. 26 | * @param style The (optional) style. 27 | * @returns The RoomVisual object, for chaining. 28 | */ 29 | line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyle): RoomVisual; 30 | 31 | /** 32 | * Draw a circle. 33 | * @param x The X coordinate of the center. 34 | * @param y The Y coordinate of the center. 35 | * @param style The (optional) style. 36 | * @returns The RoomVisual object, for chaining. 37 | */ 38 | circle(x: number, y: number, style?: CircleStyle): RoomVisual; 39 | 40 | /** 41 | * Draw a circle. 42 | * @param pos The position object of the center. 43 | * @param style The (optional) style. 44 | * @returns The RoomVisual object, for chaining. 45 | */ 46 | circle(pos: RoomPosition, style?: CircleStyle): RoomVisual; 47 | 48 | /** 49 | * Draw a rectangle. 50 | * @param x The X coordinate of the top-left corner. 51 | * @param y The Y coordinate of the top-left corner. 52 | * @param width The width of the rectangle. 53 | * @param height The height of the rectangle. 54 | * @param style The (optional) style. 55 | * @returns The RoomVisual object, for chaining. 56 | */ 57 | rect(x: number, y: number, width: number, height: number, style?: PolyStyle): RoomVisual; 58 | 59 | /** 60 | * Draw a rectangle. 61 | * @param topLeftPos The position object of the top-left corner. 62 | * @param width The width of the rectangle. 63 | * @param height The height of the rectangle. 64 | * @param style The (optional) style. 65 | * @returns The RoomVisual object, for chaining. 66 | */ 67 | rect(topLeftPos: RoomPosition, width: number, height: number, style?: PolyStyle): RoomVisual; 68 | 69 | /** 70 | * Draw a polygon. 71 | * @param points An array of point coordinate arrays, i.e. [[0,0], [5,5], [5,10]]. 72 | * @param style The (optional) style. 73 | * @returns The RoomVisual object, for chaining. 74 | */ 75 | poly(points: [number, number][], style?: PolyStyle): RoomVisual; 76 | 77 | /** 78 | * Draw a text label. 79 | * @param text The text message. 80 | * @param pos The position object of the label baseline. 81 | * @param style The (optional) text style. 82 | * @returns The RoomVisual object, for chaining. 83 | */ 84 | text(text: string, x: number, y: number, style?: TextStyle): RoomVisual; 85 | 86 | /** 87 | * Draw a text label. 88 | * @param text The text message. 89 | * @param x The X coordinate of the label baseline center point. 90 | * @param y The Y coordinate of the label baseline center point. 91 | * @param style The (optional) text style. 92 | * @returns The RoomVisual object, for chaining. 93 | */ 94 | text(text: string, pos: RoomPosition, style?: TextStyle): RoomVisual; 95 | 96 | /** 97 | * Remove all visuals from the room. 98 | * @returns The RoomVisual object, for chaining. 99 | */ 100 | clear(): RoomVisual; 101 | 102 | /** 103 | * Get the stored size of all visuals added in the room in the current tick. 104 | * It must not exceed 512,000 (500 KB). 105 | * @returns The size of the visuals in bytes. 106 | */ 107 | getSize(): number; 108 | } 109 | 110 | interface LineStyle { 111 | width?: number; 112 | color?: string; 113 | opacity?: number; 114 | lineStyle?: "dashed" | "dotted"; 115 | } 116 | 117 | interface PolyStyle { 118 | fill?: string; 119 | opacity?: number; 120 | stroke?: string | undefined; 121 | strokeWidth?: number; 122 | lineStyle?: "dashed" | "dotted"; 123 | } 124 | 125 | interface CircleStyle extends PolyStyle { 126 | radius?: number; 127 | } 128 | 129 | interface TextStyle { 130 | color?: string; 131 | size?: number; 132 | align?: "center" | "left" | "right"; 133 | opacity?: number; 134 | } 135 | -------------------------------------------------------------------------------- /src/room.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * An object representing the room in which your units and structures are in. It can be used to look around, find paths, etc. Every object in the room contains its linked Room instance in the room property. 3 | */ 4 | interface Room { 5 | readonly prototype: Room; 6 | 7 | /** 8 | * The Controller structure of this room, if present, otherwise undefined. 9 | */ 10 | controller: Controller | undefined; 11 | /** 12 | * Total amount of energy available in all spawns and extensions in the room. 13 | */ 14 | energyAvailable: number; 15 | /** 16 | * Total amount of energyCapacity of all spawns and extensions in the room. 17 | */ 18 | energyCapacityAvailable: number; 19 | /** 20 | * A shorthand to Memory.rooms[room.name]. You can use it for quick access the room’s specific memory data object. 21 | */ 22 | memory: any; 23 | /** 24 | * One of the following constants: 25 | * MODE_SIMULATION, MODE_SURVIVAL, MODE_WORLD, MODE_ARENA 26 | */ 27 | mode: string; 28 | /** 29 | * The name of the room. 30 | */ 31 | name: string; 32 | /** 33 | * The Storage structure of this room, if present, otherwise undefined. 34 | */ 35 | storage: StructureStorage | undefined; 36 | /** 37 | * The Terminal structure of this room, if present, otherwise undefined. 38 | */ 39 | terminal: Terminal | undefined; 40 | /** 41 | * The RoomVisual object for this room. 42 | */ 43 | visual: RoomVisual; 44 | /** 45 | * Create new ConstructionSite at the specified location. 46 | * @param x The X position. 47 | * @param y The Y position. 48 | * @param structureType One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK 49 | * @returns Result Code: OK, ERR_INVALID_TARGET, ERR_INVALID_ARGS, ERR_RCL_NOT_ENOUGH 50 | */ 51 | createConstructionSite(x: number, y: number, structureType: string): number; 52 | /** 53 | * Create new ConstructionSite at the specified location. 54 | * @param pos Can be a RoomPosition object or any object containing RoomPosition. 55 | * @param structureType One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK 56 | * @returns Result Code: OK, ERR_INVALID_TARGET, ERR_INVALID_ARGS, ERR_RCL_NOT_ENOUGH 57 | */ 58 | createConstructionSite(pos: RoomPosition | { pos: RoomPosition }, structureType: string): number; 59 | /** 60 | * Create new Flag at the specified location. 61 | * @param x The X position. 62 | * @param y The Y position. 63 | * @param name (optional) 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. 64 | * @param color The color of a new flag. Should be one of the COLOR_* constants. The default value is COLOR_WHITE. 65 | * @param secondaryColor The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color. 66 | */ 67 | createFlag(x: number, y: number, name?: string, color?: number, secondaryColor?: number): number; 68 | /** 69 | * Create new Flag at the specified location. 70 | * @param pos Can be a RoomPosition object or any object containing RoomPosition. 71 | * @param name (optional) 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. 72 | * @param color The color of a new flag. Should be one of the COLOR_* constants. The default value is COLOR_WHITE. 73 | * @param secondaryColor The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color. 74 | */ 75 | createFlag(pos: RoomPosition | { pos: RoomPosition }, name?: string, color?: number, secondaryColor?: number): number; 76 | /** 77 | * Find all objects of the specified type in the room. 78 | * @param type One of the following constants:FIND_CREEPS, FIND_MY_CREEPS, FIND_HOSTILE_CREEPS, FIND_MY_SPAWNS, FIND_HOSTILE_SPAWNS, FIND_SOURCES, FIND_SOURCES_ACTIVE, FIND_DROPPED_RESOURCES, FIND_DROPPED_ENERGY, FIND_STRUCTURES, FIND_MY_STRUCTURES, FIND_HOSTILE_STRUCTURES, FIND_FLAGS, FIND_CONSTRUCTION_SITES, FIND_EXIT_TOP, FIND_EXIT_RIGHT, FIND_EXIT_BOTTOM, FIND_EXIT_LEFT, FIND_EXIT 79 | * @param opts An object with additional options 80 | * @returns An array with the objects found. 81 | */ 82 | find(type: number, opts?: { filter: Object | Function | string }): T[]; 83 | /** 84 | * Find the exit direction en route to another room. 85 | * @param room Another room name or room object. 86 | * @returns The room direction constant, one of the following: FIND_EXIT_TOP, FIND_EXIT_RIGHT, FIND_EXIT_BOTTOM, FIND_EXIT_LEFT 87 | * Or one of the following error codes: ERR_NO_PATH, ERR_INVALID_ARGS 88 | */ 89 | findExitTo(room: string | Room): number; 90 | /** 91 | * Find an optimal path inside the room between fromPos and toPos using A* search algorithm. 92 | * @param fromPos The start position. 93 | * @param toPos The end position. 94 | * @param opts (optional) An object containing additonal pathfinding flags 95 | * @returns An array with path steps 96 | */ 97 | findPath(fromPos: RoomPosition, toPos: RoomPosition, opts?: FindPathOpts): PathStep[]; 98 | /** 99 | * Creates a RoomPosition object at the specified location. 100 | * @param x The X position. 101 | * @param y The Y position. 102 | * @returns A RoomPosition object or null if it cannot be obtained. 103 | */ 104 | getPositionAt(x: number, y: number): RoomPosition | null; 105 | /** 106 | * Get the list of objects at the specified room position. 107 | * @param x The X position. 108 | * @param y The Y position. 109 | * @returns An array with objects at the specified position 110 | */ 111 | lookAt(x: number, y: number): LookAtResult[]; 112 | /** 113 | * Get the list of objects at the specified room position. 114 | * @param target Can be a RoomPosition object or any object containing RoomPosition. 115 | * @returns An array with objects at the specified position 116 | */ 117 | lookAt(target: RoomPosition | { pos: RoomPosition }): LookAtResult[]; 118 | /** 119 | * Get the list of objects at the specified room area. This method is more CPU efficient in comparison to multiple lookAt calls. 120 | * @param top The top Y boundary of the area. 121 | * @param left The left X boundary of the area. 122 | * @param bottom The bottom Y boundary of the area. 123 | * @param right The right X boundary of the area. 124 | * @param asArray Set to true if you want to get the result as a plain array. 125 | * @returns An object with all the objects in the specified area 126 | */ 127 | lookAtArea(top: number, left: number, bottom: number, right: number, asArray?: boolean): LookAtResultMatrix | LookAtResultWithPos[]; 128 | /** 129 | * Get an object with the given type at the specified room position. 130 | * @param type One of the following string constants: constructionSite, creep, energy, exit, flag, source, structure, terrain 131 | * @param x The X position. 132 | * @param y The Y position. 133 | * @returns An array of objects of the given type at the specified position if found. 134 | */ 135 | lookForAt(type: string, x: number, y: number): T[]; 136 | /** 137 | * Get an object with the given type at the specified room position. 138 | * @param type One of the following string constants: constructionSite, creep, energy, exit, flag, source, structure, terrain 139 | * @param target Can be a RoomPosition object or any object containing RoomPosition. 140 | * @returns An array of objects of the given type at the specified position if found. 141 | */ 142 | lookForAt(type: string, target: RoomPosition | { pos: RoomPosition }): T[]; 143 | /** 144 | * Get the list of objects with the given type at the specified room area. This method is more CPU efficient in comparison to multiple lookForAt calls. 145 | * @param type One of the following string constants: constructionSite, creep, energy, exit, flag, source, structure, terrain 146 | * @param top The top Y boundary of the area. 147 | * @param left The left X boundary of the area. 148 | * @param bottom The bottom Y boundary of the area. 149 | * @param right The right X boundary of the area. 150 | * @returns An object with all the objects of the given type in the specified area 151 | */ 152 | lookForAtArea(type: string, top: number, left: number, bottom: number, right: number, asArray?: boolean): LookAtResultMatrix | LookAtResultWithPos[]; 153 | 154 | /** 155 | * Serialize a path array into a short string representation, which is suitable to store in memory. 156 | * @param path A path array retrieved from Room.findPath. 157 | * @returns A serialized string form of the given path. 158 | */ 159 | 160 | /** 161 | * Deserialize a short string path representation into an array form. 162 | * @param path A serialized path string. 163 | * @returns A path array. 164 | */ 165 | } 166 | 167 | interface RoomConstructor { 168 | new (id: string): Room; 169 | serializePath(path: PathStep[]): string; 170 | deserializePath(path: string): PathStep[]; 171 | } 172 | 173 | declare const Room: RoomConstructor; 174 | -------------------------------------------------------------------------------- /src/source.ts: -------------------------------------------------------------------------------- 1 | // Updated 2016-02-05 2 | /** 3 | * An energy source object. Can be harvested by creeps with a WORK body part. 4 | */ 5 | interface Source extends RoomObject { 6 | /** 7 | * The prototype is stored in the Source.prototype global object. You can use it to extend game objects behaviour globally: 8 | */ 9 | readonly prototype: Source; 10 | /** 11 | * The remaining amount of energy. 12 | */ 13 | energy: number; 14 | /** 15 | * The total amount of energy in the source. Equals to 3000 in most cases. 16 | */ 17 | energyCapacity: number; 18 | /** 19 | * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. 20 | */ 21 | id: string; 22 | /** 23 | * If you can get an instance of Source, you can see it. 24 | * If you can see a Source, you can see the room it's in. 25 | */ 26 | room: Room; 27 | /** 28 | * The remaining time after which the source will be refilled. 29 | */ 30 | ticksToRegeneration: number; 31 | } 32 | 33 | interface SourceConstructor extends _Constructor, _ConstructorById { 34 | } 35 | 36 | declare const Source: SourceConstructor; 37 | -------------------------------------------------------------------------------- /src/spawn.ts: -------------------------------------------------------------------------------- 1 | // Updated 2016-02-05 2 | 3 | /** 4 | * An object containing creep spawning options 5 | */ 6 | interface SpawnOpts { 7 | /** 8 | * Memory of the new creep. If provided, it will be immediately stored into Memory.creeps[name]. 9 | */ 10 | memory?: any; 11 | /** 12 | * Array of spawns/extensions from which to draw energy for the spawning process. Structures will be used according to the array order. 13 | */ 14 | energyStructures?: Array; 15 | /** 16 | * If dryRun is true, the operation will only check if it is possible to create a creep. 17 | */ 18 | dryRun?: boolean; 19 | } 20 | /** 21 | * Spawns are your colony centers. You can transfer energy into it and create new creeps using createCreep() method. 22 | */ 23 | interface StructureSpawn extends OwnedStructure { 24 | readonly prototype: StructureSpawn; 25 | /** 26 | * The amount of energy containing in the spawn. 27 | */ 28 | energy: number; 29 | /** 30 | * The total amount of energy the spawn can contain 31 | */ 32 | energyCapacity: number; 33 | /** 34 | * A shorthand to Memory.spawns[spawn.name]. You can use it for quick access the spawn’s specific memory data object. 35 | */ 36 | memory: any; 37 | /** 38 | * Spawn’s name. You choose the name upon creating a new spawn, and it cannot be changed later. This name is a hash key to access the spawn via the Game.spawns object. 39 | */ 40 | name: string; 41 | /** 42 | * If the spawn is in process of spawning a new creep, this object will contain the new creep’s information, or null otherwise. 43 | * @param name The name of a new creep. 44 | * @param needTime Time needed in total to complete the spawning. 45 | * @param remainingTime Remaining time to go. 46 | */ 47 | spawning: { name: string, needTime: number, remainingTime: number }; 48 | 49 | /** 50 | * @deprecated 51 | * Check if a creep can be created. 52 | * @param body An array describing the new creep’s body. Should contain 1 to 50 elements with one of these constants: WORK, MOVE, CARRY, ATTACK, RANGED_ATTACK, HEAL, TOUGH, CLAIM 53 | * @param 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. 54 | */ 55 | canCreateCreep(body: string[], name?: string): number; 56 | /** 57 | * @deprecated 58 | * Start the creep spawning process. 59 | * The name of a new creep or one of these error codes 60 | * ERR_NOT_OWNER -1 You are not the owner of this spawn. 61 | * ERR_NAME_EXISTS -3 There is a creep with the same name already. 62 | * ERR_BUSY -4 The spawn is already in process of spawning another creep. 63 | * ERR_NOT_ENOUGH_ENERGY -6 The spawn and its extensions contain not enough energy to create a creep with the given body. 64 | * ERR_INVALID_ARGS -10 Body is not properly described. 65 | * ERR_RCL_NOT_ENOUGH -14 Your Room Controller level is not enough to use this spawn. 66 | * @param body An array describing the new creep’s body. Should contain 1 to 50 elements with one of these constants: WORK, MOVE, CARRY, ATTACK, RANGED_ATTACK, HEAL, TOUGH, CLAIM 67 | * @param 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. 68 | * @param memory The memory of a new creep. If provided, it will be immediately stored into Memory.creeps[name]. 69 | */ 70 | createCreep(body: string[], name?: string, memory?: any): number | string; 71 | 72 | /** 73 | * Start the creep spawning process. The required energy amount can be withdrawn from all spawns and extensions in the room. 74 | * @param body An array describing the new creep’s body. Should contain 1 to 50 elements with one of these constants: WORK, MOVE, CARRY, ATTACK, RANGED_ATTACK, HEAL, TOUGH, CLAIM 75 | * @param 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. 76 | * @param opts An object with additional options for the spawning process. 77 | * @returns One of the following codes: 78 | * OK 0 The operation has been scheduled successfully. 79 | * ERR_NOT_OWNER -1 You are not the owner of this spawn. 80 | * ERR_NAME_EXISTS -3 There is a creep with the same name already. 81 | * ERR_BUSY -4 The spawn is already in process of spawning another creep. 82 | * ERR_NOT_ENOUGH_ENERGY -6 The spawn and its extensions contain not enough energy to create a creep with the given body. 83 | * ERR_INVALID_ARGS -10 Body is not properly described or name was not provided. 84 | * ERR_RCL_NOT_ENOUGH -14 Your Room Controller level is insufficient to use this spawn. 85 | */ 86 | spawnCreep(body: string[], name: string, opts? : SpawnOpts): number; 87 | /** 88 | * Destroy this spawn immediately. 89 | */ 90 | destroy(): number; 91 | /** 92 | * Check whether this structure can be used. If the room controller level is not enough, then this method will return false, and the structure will be highlighted with red in the game. 93 | */ 94 | isActive(): boolean; 95 | /** 96 | * Toggle auto notification when the spawn is under attack. The notification will be sent to your account email. Turned on by default. 97 | * @param enabled Whether to enable notification or disable. 98 | */ 99 | notifyWhenAttacked(enabled: boolean): number; 100 | /** 101 | * Increase the remaining time to live of the target creep. The target should be at adjacent square. The spawn should not be busy with the spawning process. Each execution increases the creep's timer by amount of ticks according to this formula: floor(500/body_size). Energy required for each execution is determined using this formula: ceil(creep_cost/3/body_size). 102 | * @param target The target creep object. 103 | */ 104 | renewCreep(target: Creep): number; 105 | /** 106 | * Kill the creep and drop up to 100% of resources spent on its spawning and boosting depending on remaining life time. The target should be at adjacent square. 107 | * @param target The target creep object. 108 | */ 109 | recycleCreep(target: Creep): number; 110 | /** 111 | * @deprecated 112 | * Transfer the energy from the spawn to a creep. 113 | * @param target The creep object which energy should be transferred to. 114 | * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. 115 | */ 116 | transferEnergy(target: Creep, amount?: number): number; 117 | } 118 | 119 | 120 | interface StructureSpawnConstructor extends _Constructor, _ConstructorById { 121 | } 122 | 123 | declare const StructureSpawn: StructureSpawnConstructor; 124 | -------------------------------------------------------------------------------- /src/structure.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Parent object for structure classes 3 | */ 4 | 5 | interface Structure extends RoomObject { 6 | readonly prototype: Structure; 7 | 8 | /** 9 | * The current amount of hit points of the structure. 10 | */ 11 | hits: number; 12 | /** 13 | * The total amount of hit points of the structure. 14 | */ 15 | hitsMax: number; 16 | /** 17 | * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. 18 | */ 19 | id: string; 20 | /** 21 | * If you can get an instance of a Structure, you can see it. 22 | * If you can see the Structure, you can see the room it's in. 23 | */ 24 | room: Room; 25 | /** 26 | * One of the STRUCTURE_* constants. 27 | */ 28 | structureType: string; 29 | /** 30 | * Destroy this structure immediately. 31 | */ 32 | destroy(): number; 33 | /** 34 | * Check whether this structure can be used. If the room controller level is not enough, then this method will return false, and the structure will be highlighted with red in the game. 35 | */ 36 | isActive(): boolean; 37 | /** 38 | * Toggle auto notification when the structure is under attack. The notification will be sent to your account email. Turned on by default. 39 | * @param enabled Whether to enable notification or disable. 40 | */ 41 | notifyWhenAttacked(enabled: boolean): number; 42 | } 43 | 44 | interface StructureConstructor extends _Constructor, _ConstructorById { 45 | } 46 | 47 | declare const Structure: StructureConstructor; 48 | 49 | /** 50 | * The base prototype for a structure that has an owner. Such structures can be 51 | * found using `FIND_MY_STRUCTURES` and `FIND_HOSTILE_STRUCTURES` constants. 52 | */ 53 | interface OwnedStructure extends Structure { 54 | readonly prototype: OwnedStructure; 55 | 56 | /** 57 | * Whether this is your own structure. Walls and roads don't have this property as they are considered neutral structures. 58 | */ 59 | my: boolean; 60 | /** 61 | * An object with the structure’s owner info (if present) containing the following properties: username 62 | */ 63 | owner: Owner; 64 | /** 65 | * The link to the Room object. Is always present because owned structures give visibility. 66 | */ 67 | room: Room; 68 | 69 | } 70 | 71 | interface OwnedStructureConstructor extends _Constructor, _ConstructorById { 72 | } 73 | 74 | declare const OwnedStructure: OwnedStructureConstructor; 75 | 76 | /** 77 | * Claim this structure to take control over the room. The controller structure 78 | * cannot be damaged or destroyed. It can be addressed by `Room.controller` 79 | * property. 80 | */ 81 | interface StructureController extends OwnedStructure { 82 | readonly prototype: StructureController; 83 | 84 | /** 85 | * Current controller level, from 0 to 8. 86 | */ 87 | level: number; 88 | /** 89 | * The current progress of upgrading the controller to the next level. 90 | */ 91 | progress: number; 92 | /** 93 | * The progress needed to reach the next level. 94 | */ 95 | progressTotal: number; 96 | /** 97 | * An object with the controller reservation info if present: username, ticksToEnd 98 | */ 99 | reservation: ReservationDefinition; 100 | /** 101 | * How many ticks of safe mode are remaining, or undefined. 102 | */ 103 | safeMode: number | undefined; 104 | /** 105 | * Safe mode activations available to use. 106 | */ 107 | safeModeAvailable: number; 108 | /** 109 | * During this period in ticks new safe mode activations will be blocked, undefined if cooldown is inactive. 110 | */ 111 | safeModeCooldown: number | undefined; 112 | /** 113 | * An object with the controller sign info if present 114 | */ 115 | sign: SignDefinition; 116 | /** 117 | * The amount of game ticks when this controller will lose one level. This timer can be reset by using Creep.upgradeController. 118 | */ 119 | ticksToDowngrade: number; 120 | /** 121 | * The amount of game ticks while this controller cannot be upgraded due to attack. 122 | */ 123 | upgradeBlocked: number; 124 | /** 125 | * Activate safe mode if available. 126 | * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_NOT_ENOUGH_RESOURCES, ERR_TIRED 127 | */ 128 | activateSafeMode(): number; 129 | /** 130 | * Make your claimed controller neutral again. 131 | */ 132 | unclaim(): number; 133 | } 134 | 135 | interface StructureControllerConstructor extends _Constructor, _ConstructorById { 136 | } 137 | 138 | declare const StructureController: StructureControllerConstructor; 139 | 140 | /** 141 | * Contains energy which can be spent on spawning bigger creeps. Extensions can 142 | * be placed anywhere in the room, any spawns will be able to use them regardless 143 | * of distance. 144 | */ 145 | interface StructureExtension extends OwnedStructure { 146 | readonly prototype: StructureExtension; 147 | 148 | /** 149 | * The amount of energy containing in the extension. 150 | */ 151 | energy: number; 152 | /** 153 | * The total amount of energy the extension can contain. 154 | */ 155 | energyCapacity: number; 156 | /** 157 | * @deprecated 158 | * Transfer the energy from the extension to a creep. 159 | * @param target The creep object which energy should be transferred to. 160 | * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. 161 | */ 162 | transferEnergy(target: Creep, amount?: number): number; 163 | } 164 | 165 | interface StructureExtensionConstructor extends _Constructor, _ConstructorById { 166 | } 167 | 168 | declare const StructureExtension: StructureExtensionConstructor; 169 | 170 | /** 171 | * Remotely transfers energy to another Link in the same room. 172 | */ 173 | interface StructureLink extends OwnedStructure { 174 | readonly prototype: StructureLink; 175 | 176 | /** 177 | * The amount of game ticks the link has to wait until the next transfer is possible. 178 | */ 179 | cooldown: number; 180 | /** 181 | * The amount of energy containing in the link. 182 | */ 183 | energy: number; 184 | /** 185 | * The total amount of energy the link can contain. 186 | */ 187 | energyCapacity: number; 188 | /** 189 | * Transfer energy from the link to another link or a creep. If the target is a creep, it has to be at adjacent square to the link. If the target is a link, it can be at any location in the same room. Remote transfer process implies 3% energy loss and cooldown delay depending on the distance. 190 | * @param target The target object. 191 | * @param amount The amount of energy to be transferred. If omitted, all the available energy is used. 192 | */ 193 | transferEnergy(target: Creep | StructureLink, amount?: number): number; 194 | } 195 | 196 | interface StructureLinkConstructor extends _Constructor, _ConstructorById { 197 | } 198 | 199 | declare const StructureLink: StructureLinkConstructor; 200 | 201 | /** 202 | * Non-player structure. Spawns NPC Source Keepers that guards energy sources 203 | * and minerals in some rooms. This structure cannot be destroyed. 204 | */ 205 | interface StructureKeeperLair extends OwnedStructure { 206 | readonly prototype: StructureKeeperLair; 207 | 208 | /** 209 | * Time to spawning of the next Source Keeper. 210 | */ 211 | ticksToSpawn: number | undefined; 212 | } 213 | 214 | interface StructureKeeperLairConstructor extends _Constructor, _ConstructorById { 215 | } 216 | 217 | declare const StructureKeeperLair: StructureKeeperLairConstructor; 218 | 219 | /** 220 | * Provides visibility into a distant room from your script. 221 | */ 222 | interface StructureObserver extends OwnedStructure { 223 | readonly prototype: StructureObserver; 224 | 225 | /** 226 | * Provide visibility into a distant room from your script. The target room object will be available on the next tick. The maximum range is 5 rooms. 227 | * @param roomName 228 | */ 229 | observeRoom(roomName: string): number; 230 | } 231 | 232 | interface StructureObserverConstructor extends _Constructor, _ConstructorById { 233 | } 234 | 235 | declare const StructureObserver: StructureObserverConstructor; 236 | 237 | /** 238 | * 239 | */ 240 | interface StructurePowerBank extends OwnedStructure { 241 | readonly prototype: StructurePowerBank; 242 | 243 | /** 244 | * The amount of power containing. 245 | */ 246 | power: number; 247 | /** 248 | * The amount of game ticks when this structure will disappear. 249 | */ 250 | ticksToDecay: number; 251 | } 252 | 253 | interface StructurePowerBankConstructor extends _Constructor, _ConstructorById { 254 | } 255 | 256 | declare const StructurePowerBank: StructurePowerBankConstructor; 257 | 258 | /** 259 | * Non-player structure. Contains power resource which can be obtained by 260 | * destroying the structure. Hits the attacker creep back on each attack. 261 | */ 262 | interface StructurePowerSpawn extends OwnedStructure { 263 | readonly prototype: StructurePowerSpawn; 264 | /** 265 | * The amount of energy containing in this structure. 266 | */ 267 | energy: number; 268 | /** 269 | * The total amount of energy this structure can contain. 270 | */ 271 | energyCapacity: number; 272 | /** 273 | * The amount of power containing in this structure. 274 | */ 275 | power: number; 276 | /** 277 | * The total amount of power this structure can contain. 278 | */ 279 | powerCapacity: number; 280 | 281 | /** 282 | * Create a power creep. Currently in development 283 | * @param name The name of the power creep. 284 | */ 285 | createPowerCreep(name: string): number; 286 | /** 287 | * Register power resource units into your account. Registered power allows to develop power creeps skills. Consumes 1 power resource unit and 50 energy resource units. 288 | */ 289 | processPower(): number; 290 | /** 291 | * @deprecated 292 | * Transfer the energy from this structure to a creep. 293 | * @param target The creep object which energy should be transferred to. 294 | * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. 295 | */ 296 | transferEnergy(target: Creep, amount?: number): number; 297 | 298 | } 299 | 300 | interface StructurePowerSpawnConstructor extends _Constructor, _ConstructorById { 301 | } 302 | 303 | declare const StructurePowerSpawn: StructurePowerSpawnConstructor; 304 | 305 | /** 306 | * Blocks movement of hostile creeps, and defends your creeps and structures on 307 | * the same tile. Can be used as a controllable gate. 308 | */ 309 | interface StructureRampart extends OwnedStructure { 310 | readonly prototype: StructureRampart; 311 | 312 | /** 313 | * The amount of game ticks when this rampart will lose some hit points. 314 | */ 315 | ticksToDecay: number; 316 | 317 | /** 318 | * If false (default), only your creeps can step on the same square. If true, any hostile creeps can pass through. 319 | */ 320 | isPublic: boolean; 321 | 322 | /** 323 | * Make this rampart public to allow other players' creeps to pass through. 324 | * @param isPublic Whether this rampart should be public or non-public 325 | */ 326 | setPublic(isPublic: boolean): void; 327 | } 328 | 329 | interface StructureRampartConstructor extends _Constructor, _ConstructorById { 330 | } 331 | 332 | declare const StructureRampart: StructureRampartConstructor; 333 | 334 | /** 335 | * Decreases movement cost to 1. Using roads allows creating creeps with less 336 | * `MOVE` body parts. 337 | */ 338 | interface StructureRoad extends Structure { 339 | readonly prototype: StructureRoad; 340 | 341 | /** 342 | * The amount of game ticks when this road will lose some hit points. 343 | */ 344 | ticksToDecay: number; 345 | } 346 | 347 | interface StructureRoadConstructor extends _Constructor, _ConstructorById { 348 | } 349 | 350 | declare const StructureRoad: StructureRoadConstructor; 351 | 352 | /** 353 | * A structure that can store huge amount of resource units. Only one structure 354 | * per room is allowed that can be addressed by `Room.storage` property. 355 | */ 356 | interface StructureStorage extends OwnedStructure { 357 | readonly prototype: StructureStorage; 358 | 359 | /** 360 | * An object with the storage contents. 361 | */ 362 | store: StoreDefinition; 363 | /** 364 | * The total amount of resources the storage can contain. 365 | */ 366 | storeCapacity: number; 367 | 368 | /** 369 | * Transfer resource from this storage to a creep. The target has to be at adjacent square. 370 | * @param target The target object. 371 | * @param resourceType One of the RESOURCE_* constants. 372 | * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. 373 | */ 374 | transfer(target: Creep, resourceType: string, amount?: number): number; 375 | /** 376 | * @deprecated 377 | * An alias for storage.transfer(target, RESOURCE_ENERGY, amount). 378 | * @param target The target object. 379 | * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. 380 | * @deprecated 381 | */ 382 | transferEnergy(target: Creep, amount?: number): number; 383 | } 384 | 385 | interface StructureStorageConstructor extends _Constructor, _ConstructorById { 386 | } 387 | 388 | declare const StructureStorage: StructureStorageConstructor; 389 | 390 | /** 391 | * Remotely attacks or heals creeps, or repairs structures. Can be targeted to 392 | * any object in the room. However, its effectiveness highly depends on the 393 | * distance. Each action consumes energy. 394 | */ 395 | interface StructureTower extends OwnedStructure { 396 | readonly prototype: StructureTower; 397 | 398 | /** 399 | * The amount of energy containing in this structure. 400 | */ 401 | energy: number; 402 | /** 403 | * The total amount of energy this structure can contain. 404 | */ 405 | energyCapacity: number; 406 | 407 | /** 408 | * Remotely attack any creep in the room. Consumes 10 energy units per tick. Attack power depends on the distance to the target: from 600 hits at range 10 to 300 hits at range 40. 409 | * @param target The target creep. 410 | */ 411 | attack(target: Creep): number; 412 | /** 413 | * Remotely heal any creep in the room. Consumes 10 energy units per tick. Heal power depends on the distance to the target: from 400 hits at range 10 to 200 hits at range 40. 414 | * @param target The target creep. 415 | */ 416 | heal(target: Creep): number; 417 | /** 418 | * Remotely repair any structure in the room. Consumes 10 energy units per tick. Repair power depends on the distance to the target: from 600 hits at range 10 to 300 hits at range 40. 419 | * @param target The target structure. 420 | */ 421 | repair(target: Spawn | Structure): number; 422 | /** 423 | * @deprecated 424 | * @param target The creep object which energy should be transferred to. 425 | * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. 426 | */ 427 | transferEnergy(target: Creep, amount?: number): number; 428 | } 429 | 430 | interface StructureTowerConstructor extends _Constructor, _ConstructorById { 431 | } 432 | 433 | declare const StructureTower: StructureTowerConstructor; 434 | 435 | /** 436 | * Blocks movement of all creeps. 437 | */ 438 | interface StructureWall extends Structure { 439 | readonly prototype: StructureWall; 440 | /** 441 | * The amount of game ticks when the wall will disappear (only for automatically placed border walls at the start of the game). 442 | */ 443 | ticksToLive: number; 444 | } 445 | 446 | interface StructureWallConstructor extends _Constructor, _ConstructorById { 447 | } 448 | 449 | declare const StructureWall: StructureWallConstructor; 450 | 451 | /** 452 | * Allows to harvest mineral deposits. 453 | */ 454 | interface StructureExtractor extends OwnedStructure { 455 | readonly prototype: StructureExtractor; 456 | /** 457 | * The amount of game ticks until the next harvest action is possible. 458 | */ 459 | cooldown: number; 460 | } 461 | 462 | interface StructureExtractorConstructor extends _Constructor, _ConstructorById { 463 | } 464 | 465 | declare const StructureExtractor: StructureExtractorConstructor; 466 | 467 | /** 468 | * Produces mineral compounds from base minerals and boosts creeps. 469 | */ 470 | interface StructureLab extends OwnedStructure { 471 | readonly prototype: StructureLab; 472 | /** 473 | * The amount of game ticks the lab has to wait until the next reaction is possible. 474 | */ 475 | cooldown: number; 476 | /** 477 | * The amount of energy containing in the lab. Energy is used for boosting creeps. 478 | */ 479 | energy: number; 480 | /** 481 | * The total amount of energy the lab can contain. 482 | */ 483 | energyCapacity: number; 484 | /** 485 | * The amount of mineral resources containing in the lab. 486 | */ 487 | mineralAmount: number; 488 | /** 489 | * The type of minerals containing in the lab. Labs can contain only one mineral type at the same time. 490 | */ 491 | mineralType: string; 492 | /** 493 | * The total amount of minerals the lab can contain. 494 | */ 495 | mineralCapacity: number; 496 | /** 497 | * Boosts creep body part using the containing mineral compound. The creep has to be at adjacent square to the lab. Boosting one body part consumes 30 mineral units and 20 energy units. 498 | * @param creep The target creep. 499 | * @param 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. 500 | */ 501 | boostCreep(creep: Creep, bodyPartsCount?: number): number; 502 | /** 503 | * Produce mineral compounds using reagents from two another labs. Each lab has to be within 2 squares range. The same input labs can be used by many output labs 504 | * @param lab1 The first source lab. 505 | * @param lab2 The second source lab. 506 | */ 507 | runReaction(lab1: StructureLab, lab2: StructureLab): number; 508 | /** 509 | * Transfer resource from this structure to a creep. The target has to be at adjacent square. 510 | * @param target The target object. 511 | * @param resourceType One of the RESOURCE_* constants. 512 | * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. 513 | */ 514 | transfer(target: Creep, resourceType: string, amount?: number): number; 515 | } 516 | 517 | interface StructureLabConstructor extends _Constructor, _ConstructorById { 518 | } 519 | 520 | declare const StructureLab: StructureLabConstructor; 521 | 522 | /** 523 | * Sends any resources to a Terminal in another room. 524 | */ 525 | interface StructureTerminal extends OwnedStructure { 526 | readonly prototype: StructureTerminal; 527 | /** 528 | * The remaining amount of ticks while this terminal cannot be used to make StructureTerminal.send or Game.market.deal calls. 529 | */ 530 | cooldown: number; 531 | /** 532 | * An object with the storage contents. Each object key is one of the RESOURCE_* constants, values are resources amounts. 533 | */ 534 | store: any; 535 | /** 536 | * The total amount of resources the storage can contain. 537 | */ 538 | storeCapacity: number; 539 | /** 540 | * Sends resource to a Terminal in another room with the specified name. 541 | * @param resourceType One of the RESOURCE_* constants. 542 | * @param amount The amount of resources to be sent. The minimum amount is 100. 543 | * @param destination The name of the target room. You don't have to gain visibility in this room. 544 | * @param description The description of the transaction. It is visible to the recipient. The maximum length is 100 characters. 545 | */ 546 | send(resourceType: string, amount: number, destination: string, description?: string): number; 547 | /** 548 | * Transfer resource from this terminal to a creep. The target has to be at adjacent square. 549 | * @param target The target object. 550 | * @param resourceType One of the RESOURCE_* constants. 551 | * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. 552 | */ 553 | transfer(target: Creep, resourceType: string, amount?: number): number; 554 | } 555 | 556 | interface StructureTerminalConstructor extends _Constructor, _ConstructorById { 557 | } 558 | 559 | declare const StructureTerminal: StructureTerminalConstructor; 560 | 561 | /** 562 | * Contains up to 2,000 resource units. Can be constructed in neutral rooms. Decays for 5,000 hits per 100 ticks. 563 | */ 564 | interface StructureContainer extends Structure { 565 | readonly prototype: StructureContainer; 566 | /** 567 | * An object with the structure contents. Each object key is one of the RESOURCE_* constants, values are resources 568 | * amounts. Use _.sum(structure.store) to get the total amount of contents 569 | */ 570 | store: any; 571 | /** 572 | * The total amount of resources the structure can contain. 573 | */ 574 | storeCapacity: number; 575 | /** 576 | * The amount of game ticks when this container will lose some hit points. 577 | */ 578 | ticksToDecay: number; 579 | /** 580 | * Transfer resource from this structure to a creep. The target has to be at adjacent square. 581 | * @param target The target object. 582 | * @param resourceType One of the RESOURCE_* constants. 583 | * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. 584 | */ 585 | transfer(target: Creep, resourceType: string, amount?: number): number; 586 | } 587 | 588 | interface StructureContainerConstructor extends _Constructor, _ConstructorById { 589 | } 590 | 591 | declare const StructureContainer: StructureContainerConstructor; 592 | 593 | /** 594 | * Launches a nuke to another room dealing huge damage to the landing area. 595 | * Each launch has a cooldown and requires energy and ghodium resources. Launching 596 | * creates a Nuke object at the target room position which is visible to any player 597 | * until it is landed. Incoming nuke cannot be moved or cancelled. Nukes cannot 598 | * be launched from or to novice rooms. 599 | */ 600 | interface StructureNuker extends OwnedStructure { 601 | readonly prototype: StructureNuker; 602 | /** 603 | * The amount of energy contained in this structure. 604 | */ 605 | energy: number; 606 | /** 607 | * The total amount of energy this structure can contain. 608 | */ 609 | energyCapacity: number; 610 | /** 611 | * The amount of ghodium contained in this structure. 612 | */ 613 | ghodium: number; 614 | /** 615 | * The total amount of ghodium this structure can contain. 616 | */ 617 | ghodiumCapacity: number; 618 | /** 619 | * The amount of game ticks the nuker has to wait until the next launch is possible. 620 | */ 621 | cooldown: number; 622 | /** 623 | * Launch a nuke to the specified position. 624 | * @param pos The target room position. 625 | */ 626 | launchNuke(pos: RoomPosition): number; 627 | } 628 | 629 | interface StructureNukerConstructor extends _Constructor, _ConstructorById { 630 | } 631 | 632 | declare const StructureNuker: StructureNukerConstructor; 633 | 634 | /** 635 | * A non-player structure. 636 | * Instantly teleports your creeps to a distant room acting as a room exit tile. 637 | * Portals appear randomly in the central room of each sector. 638 | */ 639 | interface StructurePortal extends Structure { 640 | readonly prototype: StructurePortal; 641 | /** 642 | * The position object in the destination room. 643 | */ 644 | destination: RoomPosition; 645 | /** 646 | * The amount of game ticks when the portal disappears, or undefined when the portal is stable. 647 | */ 648 | ticksToDecay: number; 649 | } 650 | 651 | interface StructurePortalConstructor extends _Constructor, _ConstructorById { 652 | } 653 | 654 | declare const StructurePortal: StructurePortalConstructor; 655 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "system", 4 | "target": "es6", 5 | "sourceMap": false, 6 | "declaration": true, 7 | "noImplicitAny": true, 8 | "strictNullChecks": true, 9 | "outFile": "./dist/screeps.ts", 10 | "newLine": "LF" 11 | }, 12 | "include": ["./src/**/*.ts"], 13 | "exclude": ["node_modules", "dist"] 14 | } 15 | --------------------------------------------------------------------------------