diff --git a/README.md b/README.md index defe914..5de471d 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,71 @@ -# Screeps Typescript Declarations +** This repo has been moved to [typed-screeps](https://github.com/bryanbecker/typed-screeps) ** -> The repository for *Screep's* TypeScript type definitions. https://screeps.com/ +# Typed-Screeps -Discussion in [screep's community forum](http://support.screeps.com/hc/en-us/community/posts/207116485-Writing-Screep-bots-with-Typescript?page=1#) +> The forked repository for **strong** *Screep's* TypeScript type definitions. https://screeps.com/ # Installation Using [typings](https://github.com/typings/typings), add this to your typings.json: -```json -{ - "globalDependencies": { - "screeps": "github:screepers/Screeps-Typescript-Declarations/dist/screeps.d.ts#TS2" - } -} +```bash +typings install github:resir014/typed-screeps/dist/screeps.d.ts#master -SG ``` +# Differences from **[Screeps-Typescript-Declarations](https://github.com/screepers/Screeps-Typescript-Declarations)**: +### Breaking Changes: +- `Memory` is typed by default. The added typings are: + - `CreepMemory` + - `FlagMemory` + - `SpawnMemory` + - `RoomMemory` + + If you like the idea of typed memory, but aren't ready to just fully in, just make sure you define an interface for the above four types. Then you can extend them at a later time. Example: + ```TypeScript + interface CreepMemory { [name: string]: any }; + interface FlagMemory { [name: string]: any }; + interface SpawnMemory { [name: string]: any }; + interface RoomMemory { [name: string]: any }; + ``` + +- Any place in code that uses a constant (ex `STRUCTURE_EXTENSION` or `FIND_MY_SPAWNS` is now constrained to use literal types. Here is the list of the new types: + ``` + BodyPartConstant + StructureConstant + FindConstant + LookConstant + DirectionConstant + ResourceConstant + MineralConstant (this is a subset of ResourceConstant) + ColorConstant + ScreepsReturnCode + ``` + + To update your code, you just need to change any `string` types to match one of the above. For example, if your code had: + ```TypeScript + function getBody(): string[] { + return [ WORK, MOVE, CARRY ]; + } + ``` + Change it to: + ```TypeScript + function getBody(): BodyPartConstant[] { // this line changed + return [ WORK, MOVE, CARRY ]; + } + ``` +- Some original functions were incorrectly typed to not include `null` as a possible return. You may need to update your code to reflect this update (ex. `findClosestByPath` or `findClosestByRange`) + +### Additional (non-breaking) Features: +- `ConstructionSite` can be optionally constrained by a structure type (ex. `ConstructionSite`). TypeScript will enforce that the `type` property of the `ConstructionSite` appropriately matches +- `Resource` can optionally be constrained (ex. `Resource`) +- `Mineral` can optionally be constrained by `MineralConstant` (ex. `Mineral`) +- `Structure` can optionally be constrained (ex `Structure`) +- Screeps classes derived from `Structure` (ex `StructureContainer`) have their `type` property correspondingly constrained +- `LookAt` results are now constrained to the type looked for +- Results from `Find`-type functions are now constrained to have a `RoomPosition` + + + + # Usage Note: When using this API, you can't access creeps in manner suggested in Screeps' tutorial: @@ -41,102 +92,3 @@ To compile the declarations, run: npm run compile ``` -# Changelog - -### v4.2.1 2016-07-25 [ChangeLog](http://support.screeps.com/hc/en-us/articles/210048285-Changelog-2016-07-22) -- Added new toPublic option to `Creep.say` -- Fixed some issue with using `instanceof` with `StructureSpawn`, `Source`, `StructureLink` - -### v4.2.0 -- New Creep.withdraw -- Added and fixed a lot of constants - -### v4.0.1 -- Fixed issues with REACTIONS and LOOK_* constants - -### v4.0.0 -- Changed `Map` to `GameMap` to avoid conflict with new ES6 Map type -- 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. -- Spawn will now extends OwnStructure, and StructureContainer will extends Structure. -- Fixed createCreep return type to `number | string`. -- Updated new options for findPath -- Added string as an acceptable params to moveByPath. - -### v3.0.0 Change all usage of interface to class. -Please raise an issue if this break your code! - -### v2.1.0 2016-06-23 [ChangeLog](http://support.screeps.com/hc/en-us/articles/209164605-Changelog-2016-06-17) -- Added new method StructureRampart.setPublic. -- Added new property StructureRamprt.isPublic. -- Added new global property Game.constructionSites. -- Added new argument asArray to methods Room.lookAtArea and Room.lookForAtArea -- Method Creep.moveByPath now accepts paths returned from PathFinder.search. - -### v1.5.4 2016-04-04 [Bug](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/12) -- Missing constants - -Thanks [Strategic-Link-Consulting](https://github.com/Strategic-Link-Consulting) - -### v1.5.3 2016-03-31 [Bug](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/11) -- Problem with the Game arrays. - -### v1.5.2 2016-03-19 [Bug](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/10) -- RoomPosition opts fix. Filter and algorithm are optional. - -### v1.5.1 2016-03-18 [ChangeLog](http://support.screeps.com/hc/en-us/articles/208013255) -- Added new STRUCTURE_CONTAINER constant -- New structure: Container -- Added Game.map.getRoomLinearDistance method. - -### v1.4.3 2016-03-18 Commited by NhanHo -- Added typings for various list of global objects in Game -- Add serializePath and deserializePath to Room -- Allow optional argument and properties in transferEnergy and PathFinderOps - -### v1.4.2 2016-03-10 -- Fix for CostMatrix - -### v1.4.1 2016-03-10 [ChangeLog](http://support.screeps.com/hc/en-us/articles/207929925) -- Added Extractor, Lab, Terminal, Market, Mineral objects -- New constants -- Read more from docs - -### v1.3.2 2016-03-10 [ChangeLog](http://support.screeps.com/hc/en-us/articles/207023879-PathFinder) -- 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). - -### v1.3.1 2016-02-25 [PathFinder](http://support.screeps.com/hc/en-us/articles/207023879-PathFinder) -- NhanHo added new PathFinder interface [ChangeLog](http://support.screeps.com/hc/en-us/articles/207728995-Changelog-2016-02-19). -Unfortunately other changes in that changelog are not added yet. We're working on it - -### v1.2.2 2016-02-08 [ChangeLog](http://support.screeps.com/hc/en-us/articles/206897739-Changelog-2016-02-08) -- New body part (CLAIM) -- Documentation updates to support claim -- Added Creep.dismantle() - -- Fixed missing NOT_ENOUGH_ENERGY constant - -### v1.1.7 2016-02-08 -- Change room.controller and room.storage to correct type - -### v1.1.5 2016-02-07 -- Updated RoomPosition declarations [#1](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/1) -- Removed HashMap from Game interface. It caused migration issues from JS to TS. [#2](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/2) -- Declare construction site variable (to fix instanceof problem) - -### v1.1.3 2016-02-06 -- Removed empty memory interfaces -- Fixed createScreep() method return type -- Updated all declarations. Everything should be quite close to Screep's API (with minor exceptions if I missed something accidentally) - -## Authors - -* **Nhan Ho** - *Current maintainer* - [NhanHo](https://github.com/NhanHo) -* **Marko Sulamägi** - *Converted Cameron's work to quickly installable TS skeleton app.* - [MarkoSulamagi](https://github.com/MarkoSulamagi) -* **vanhouc** - *Screep project with TS functionality. His gulpfile and screep.d.ts was very useful.* - [vanhouc](https://github.com/vanhouc) - - -See also the list of [contributors](https://github.com/screepers/Screeps-Typescript-Declarations/contributors) who participated in this project. - -## License - -This project is licensed under the MIT license. diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index c1cbdff..90dfcb1 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -30,7 +30,6 @@ declare const FIND_HOSTILE_CREEPS: 103; declare const FIND_SOURCES_ACTIVE: 104; declare const FIND_SOURCES: 105; declare const FIND_DROPPED_RESOURCES: 106; -declare const FIND_DROPPED_ENERGY: 106; declare const FIND_STRUCTURES: 107; declare const FIND_MY_STRUCTURES: 108; declare const FIND_HOSTILE_STRUCTURES: 109; @@ -60,7 +59,7 @@ declare const COLOR_ORANGE: 7; declare const COLOR_BROWN: 8; declare const COLOR_GREY: 9; declare const COLOR_WHITE: 10; -declare const COLORS_ALL: number[]; +declare const COLORS_ALL: ColorConstant[]; declare const CREEP_SPAWN_TIME: 3; declare const CREEP_LIFE_TIME: 1500; declare const CREEP_CLAIM_LIFE_TIME: 500; @@ -112,18 +111,8 @@ declare const LINK_COOLDOWN: 1; declare const LINK_LOSS_RATIO: 0.03; declare const STORAGE_CAPACITY: 1000000; declare const STORAGE_HITS: 10000; -declare const BODYPART_COST: { - [part: string]: number; - move: 50; - work: 100; - attack: 80; - carry: 50; - heal: 250; - ranged_attack: 150; - tough: 10; - claim: 600; -}; -declare const BODYPARTS_ALL: string[]; +declare const BODYPART_COST: Record; +declare const BODYPARTS_ALL: BodyPartConstant[]; declare const CARRY_CAPACITY: 50; declare const HARVEST_POWER: 2; declare const HARVEST_MINERAL_POWER: 1; @@ -144,23 +133,7 @@ declare const RANGED_ATTACK: "ranged_attack"; declare const TOUGH: "tough"; declare const HEAL: "heal"; declare const CLAIM: "claim"; -declare const CONSTRUCTION_COST: { - spawn: 15000; - extension: 3000; - road: 300; - constructedWall: 1; - rampart: 1; - link: 5000; - storage: 30000; - tower: 5000; - observer: 8000; - powerSpawn: 100000; - extractor: 5000; - lab: 50000; - terminal: 100000; - container: 5000; - nuker: 100000; -}; +declare const CONSTRUCTION_COST: Record; declare const CONSTRUCTION_COST_ROAD_SWAMP_RATIO: 5; declare const STRUCTURE_EXTENSION: "extension"; declare const STRUCTURE_RAMPART: "rampart"; @@ -224,16 +197,14 @@ declare const RESOURCE_CATALYZED_ZYNTHIUM_ACID: "XZH2O"; declare const RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE: "ZXHO2"; declare const RESOURCE_CATALYZED_GHODIUM_ACID: "XGH2O"; declare const RESOURCE_CATALYZED_GHODIUM_ALKALIDE: "XGHO2"; -declare const RESOURCES_ALL: string[]; +declare const RESOURCES_ALL: ResourceConstant[]; declare const SUBSCRIPTION_TOKEN: string; declare const CONTROLLER_LEVELS: { [level: number]: number; }; -declare const CONTROLLER_STRUCTURES: { - [structure: string]: { - [level: number]: number; - }; -}; +declare const CONTROLLER_STRUCTURES: Record; declare const CONTROLLER_DOWNGRADE: { [level: number]: number; }; @@ -283,15 +254,7 @@ declare const TERRAIN_MASK_LAVA: number; declare const MAX_CONSTRUCTION_SITES: number; declare const MAX_CREEP_SIZE: number; declare const MINERAL_REGEN_TIME: number; -declare const MINERAL_MIN_AMOUNT: { - H: number; - O: number; - L: number; - K: number; - Z: number; - U: number; - X: number; -}; +declare const MINERAL_MIN_AMOUNT: Record; declare const MINERAL_RANDOM_FACTOR: number; declare const MINERAL_DENSITY: { 1: number; @@ -331,13 +294,13 @@ declare const NUKE_DAMAGE: { 4: number; }; declare const REACTIONS: { - [reagent: string]: { - [reagent: string]: string; + [T in ResourceConstant]: { + [P in ResourceConstant]: ResourceConstant; }; }; declare const BOOSTS: { - [part: string]: { - [boost: string]: { + [P in BodyPartConstant]: { + [T in ResourceConstant]: { [action: string]: number; }; }; @@ -357,7 +320,7 @@ declare const ORDER_BUY: "buy"; /** * A site of a structure which is currently under construction. */ -interface ConstructionSite extends RoomObject { +interface ConstructionSite extends RoomObject { readonly prototype: ConstructionSite; /** * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. @@ -382,7 +345,7 @@ interface ConstructionSite extends RoomObject { /** * One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK */ - structureType: string; + structureType: T; /** * Remove the construction site. * @returns Result Code: OK, ERR_NOT_OWNER @@ -454,7 +417,7 @@ interface Creep extends RoomObject { /** * A shorthand to Memory.creeps[creep.name]. You can use it for quick access the creep’s specific memory data object. */ - memory: any; + memory: CreepMemory; /** * Whether it is your creep or foe. */ @@ -487,79 +450,79 @@ interface Creep extends RoomObject { * 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. * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART */ - attack(target: Creep | Structure): number; + attack(target: Creep | Structure): CreepActionReturnCode; /** * 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. * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART */ - attackController(target: Controller): number; + attackController(target: Controller): CreepActionReturnCode; /** * 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. * @param target The target object to be attacked. * @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 */ - build(target: ConstructionSite): number; + build(target: ConstructionSite): CreepActionReturnCode | ERR_RCL_NOT_ENOUGH; /** * Cancel the order given during the current game tick. * @param methodName The name of a creep's method to be cancelled. * @returns Result Code: OK, ERR_NOT_FOUND */ - cancelOrder(methodName: string): number; + cancelOrder(methodName: string): OK | ERR_NOT_FOUND; /** * 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. * @param target The target controller object. * @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 */ - claimController(target: Controller): number; + claimController(target: Controller): CreepActionReturnCode | ERR_FULL | ERR_RCL_NOT_ENOUGH; /** * 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. * @param target The target structure. */ - dismantle(target: Structure): number; + dismantle(target: Structure): CreepActionReturnCode; /** * Drop this resource on the ground. * @param resourceType One of the RESOURCE_* constants. * @param amount The amount of resource units to be dropped. If omitted, all the available carried amount is used. */ - drop(resourceType: string, amount?: number): number; + drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES; /** * 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. * @param target The target room controller. * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE */ - generateSafeMode(target: Controller): number; + generateSafeMode(target: Controller): CreepActionReturnCode; /** * Get the quantity of live body parts of the given type. Fully damaged parts do not count. * @param type A body part type, one of the following body part constants: MOVE, WORK, CARRY, ATTACK, RANGED_ATTACK, HEAL, TOUGH, CLAIM */ - getActiveBodyparts(type: string): number; + getActiveBodyparts(type: BodyPartConstant): number; /** * 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. * @param target The source object to be harvested. */ - harvest(target: Source | Mineral): number; + harvest(target: Source | Mineral): CreepActionReturnCode | ERR_NOT_FOUND | ERR_NOT_ENOUGH_RESOURCES; /** * 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. * @param target The target creep object. */ - heal(target: Creep): number; + heal(target: Creep): CreepActionReturnCode; /** * Move the creep one square in the specified direction. Needs the MOVE body part. * @param direction */ - move(direction: number): number; + move(direction: DirectionConstant): CreepMoveReturnCode; /** * Move the creep using the specified predefined path. Needs the MOVE body part. * @param path A path value as returned from Room.findPath or RoomPosition.findPathTo methods. Both array form and serialized string form are accepted. */ - moveByPath(path: PathStep[] | RoomPosition[] | string): number; + moveByPath(path: PathStep[] | RoomPosition[] | string): CreepMoveReturnCode | ERR_NOT_FOUND | ERR_INVALID_ARGS; /** * 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. * @param x X position of the target in the room. * @param y Y position of the target in the room. * @param opts An object containing pathfinding options flags (see Room.findPath for more info) or one of the following: reusePath, serializeMemory, noPathFinding */ - moveTo(x: number, y: number, opts?: MoveToOpts): number; + moveTo(x: number, y: number, opts?: MoveToOpts): CreepMoveReturnCode | ERR_NO_PATH | ERR_INVALID_TARGET; /** * 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. * @param target Can be a RoomPosition object or any object containing RoomPosition. @@ -567,48 +530,48 @@ interface Creep extends RoomObject { */ moveTo(target: RoomPosition | { pos: RoomPosition; - }, opts?: MoveToOpts): number; + }, opts?: MoveToOpts): CreepMoveReturnCode | ERR_NO_PATH | ERR_INVALID_TARGET; /** * Toggle auto notification when the creep is under attack. The notification will be sent to your account email. Turned on by default. * @param enabled Whether to enable notification or disable. */ - notifyWhenAttacked(enabled: boolean): number; + notifyWhenAttacked(enabled: boolean): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_ARGS; /** * 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. * @param target The target object to be picked up. */ - pickup(target: Resource): number; + pickup(target: Resource): CreepActionReturnCode | ERR_FULL; /** * 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. * @param target The target object to be attacked. */ - rangedAttack(target: Creep | Structure): number; + rangedAttack(target: Creep | Structure): CreepActionReturnCode; /** * 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. * @param target The target creep object. */ - rangedHeal(target: Creep): number; + rangedHeal(target: Creep): CreepActionReturnCode; /** * 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. */ - rangedMassAttack(): number; + rangedMassAttack(): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NO_BODYPART; /** * 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. * @param target he target structure to be repaired. */ - repair(target: Structure): number; + repair(target: Structure): CreepActionReturnCode | ERR_NOT_ENOUGH_RESOURCES; /** * 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.... * @param target The target controller object to be reserved. * @return Result code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART */ - reserveController(target: Controller): number; + reserveController(target: Controller): CreepActionReturnCode; /** * 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. * @param message The message to be displayed. Maximum length is 10 characters. * @param set to 'true' to allow other players to see this message. Default is 'false'. */ - say(message: string, toPublic?: boolean): number; + say(message: string, toPublic?: boolean): OK | ERR_NOT_OWNER | ERR_BUSY; /** * 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. * 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. @@ -616,30 +579,30 @@ interface Creep extends RoomObject { * @param text The sign text. The maximum text length is 100 characters. * @returns Result Code: OK, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE */ - signController(target: Controller, text: string): number; + signController(target: Controller, text: string): OK | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE; /** * Kill the creep immediately. */ - suicide(): number; + suicide(): OK | ERR_NOT_OWNER | ERR_BUSY; /** * Transfer resource from the creep to another object. The target has to be at adjacent square to the creep. * @param target The target object. * @param resourceType One of the RESOURCE_* constants * @param amount The amount of resources to be transferred. If omitted, all the available carried amount is used. */ - transfer(target: Creep | Structure, resourceType: string, amount?: number): number; + transfer(target: Creep | Structure, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode; /** * 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. * @param target The target controller object to be upgraded. */ - upgradeController(target: Controller): number; + upgradeController(target: Controller): ScreepsReturnCode; /** * 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. * @param target The target object. * @param resourceType The target One of the RESOURCE_* constants.. * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. */ - withdraw(target: Structure, resourceType: string, amount?: number): number; + withdraw(target: Structure, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode; } interface CreepConstructor extends _Constructor, _ConstructorById { } @@ -652,11 +615,11 @@ interface Flag extends RoomObject { /** * 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 */ - color: number; + color: ColorConstant; /** * A shorthand to Memory.flags[flag.name]. You can use it for quick access the flag's specific memory data object. */ - memory: any; + memory: FlagMemory; /** * 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. */ @@ -664,26 +627,26 @@ interface Flag extends RoomObject { /** * Flag secondary color. One of the COLOR_* constants. */ - secondaryColor: number; + secondaryColor: ColorConstant; /** * Remove the flag. * @returns Result Code: OK */ - remove(): number; + remove(): OK; /** * Set new color of the flag. * @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 * @parma secondaryColor Secondary color of the flag. One of the COLOR_* constants. * @returns Result Code: OK, ERR_INVALID_ARGS */ - setColor(color: number, secondaryColor?: number): number; + setColor(color: ColorConstant, secondaryColor?: ColorConstant): OK | ERR_INVALID_ARGS; /** * Set new position of the flag. * @param x The X position in the room. * @param y The Y position in the room. * @returns Result Code: OK, ERR_INVALID_TARGET */ - setPosition(x: number, y: number): number; + setPosition(x: number, y: number): OK | ERR_INVALID_ARGS; /** * Set new position of the flag. * @param pos Can be a RoomPosition object or any object containing RoomPosition. @@ -691,11 +654,11 @@ interface Flag extends RoomObject { */ setPosition(pos: RoomPosition | { pos: RoomPosition; - }): number; + }): OK | ERR_INVALID_ARGS; } interface FlagConstructor extends _Constructor { - new (name: string, color: number, secondaryColor: number, roomName: string, x: number, y: number): Flag; - (name: string, color: number, secondaryColor: number, roomName: string, x: number, y: number): Flag; + new (name: string, color: ColorConstant, secondaryColor: ColorConstant, roomName: string, x: number, y: number): Flag; + (name: string, color: ColorConstant, secondaryColor: ColorConstant, roomName: string, x: number, y: number): Flag; } declare const Flag: FlagConstructor; /** @@ -771,6 +734,9 @@ interface Game { */ notify(message: string, groupInterval?: number): void; } +declare type _HasRoomPosition = { + pos: RoomPosition; +}; interface GlobalControlLevel { level: number; progress: number; @@ -792,11 +758,11 @@ interface BodyPartDefinition { /** * If the body part is boosted, this property specifies the mineral type which is used for boosting. One of the RESOURCE_* constants. */ - boost: string; + boost?: ResourceConstant; /** * One of the body part types constants. */ - type: string; + type: BodyPartConstant; /** * The remaining amount of hit points of this body part. */ @@ -815,41 +781,31 @@ interface SignDefinition { time: number; datetime: Date; } -interface StoreDefinition { - [resource: string]: number | undefined; - energy?: number; - power?: number; -} -interface LookAtResultWithPos { - x: number; - y: number; - type: string; +declare type StoreDefinition = Record & { + energy: number; +}; +interface LookAtTypes { constructionSite?: ConstructionSite; creep?: Creep; - terrain?: string; - structure?: Structure; - flag?: Flag; - energy?: Resource; + energy?: Resource; exit?: any; - source?: Source; + flag?: Flag; mineral?: Mineral; + nuke?: Nuke; resource?: Resource; -} -interface LookAtResult { - type: string; - constructionSite?: ConstructionSite; - creep?: Creep; - energy?: Resource; - exit?: any; - flag?: Flag; source?: Source; structure?: Structure; - terrain?: string; - mineral?: Mineral; - resource?: Resource; + terrain?: Terrain; } -interface LookAtResultMatrix { - [coord: number]: LookAtResultMatrix | LookAtResult[]; +declare type LookAtResult = Pick & { + type: K; +}; +declare type LookAtResultWithPos = LookAtResult & { + x: number; + y: number; +}; +interface LookAtResultMatrix { + [coord: number]: LookAtResultMatrix | LookAtResult[]; } interface FindPathOpts { /** @@ -939,7 +895,7 @@ interface PathStep { dx: number; y: number; dy: number; - direction: number; + direction: DirectionConstant; } /** * An object with survival game info @@ -965,6 +921,160 @@ interface _ConstructorById extends _Constructor { new (id: string): T; (id: string): T; } +/** + * This file creates literal versions of many of the constants + * It should be kept in sync with constants.ts + */ +declare type Terrain = "plain" | "swamp" | "wall"; +declare type ScreepsReturnCode = OK | ERR_NOT_OWNER | ERR_NO_PATH | ERR_BUSY | ERR_NOT_FOUND | ERR_NOT_ENOUGH_RESOURCES | ERR_NOT_ENOUGH_ENERGY | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS | ERR_TIRED | ERR_NO_BODYPART | ERR_NOT_ENOUGH_EXTENSIONS | ERR_RCL_NOT_ENOUGH | ERR_GCL_NOT_ENOUGH; +declare type OK = 0; +declare type ERR_NOT_OWNER = -1; +declare type ERR_NO_PATH = -2; +declare type ERR_NAME_EXISTS = -3; +declare type ERR_BUSY = -4; +declare type ERR_NOT_FOUND = -5; +declare type ERR_NOT_ENOUGH_RESOURCES = -6; +declare type ERR_NOT_ENOUGH_ENERGY = -6; +declare type ERR_INVALID_TARGET = -7; +declare type ERR_FULL = -8; +declare type ERR_NOT_IN_RANGE = -9; +declare type ERR_INVALID_ARGS = -10; +declare type ERR_TIRED = -11; +declare type ERR_NO_BODYPART = -12; +declare type ERR_NOT_ENOUGH_EXTENSIONS = -6; +declare type ERR_RCL_NOT_ENOUGH = -14; +declare type ERR_GCL_NOT_ENOUGH = -15; +declare type CreepActionReturnCode = OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART; +declare type CreepMoveReturnCode = OK | ERR_NOT_OWNER | ERR_BUSY | ERR_TIRED | ERR_NO_BODYPART; +declare type FindConstant = FIND_EXIT_TOP | FIND_EXIT_RIGHT | FIND_EXIT_BOTTOM | FIND_EXIT_LEFT | FIND_EXIT | FIND_CREEPS | FIND_MY_CREEPS | FIND_HOSTILE_CREEPS | FIND_SOURCES_ACTIVE | FIND_SOURCES | FIND_DROPPED_RESOURCES | FIND_STRUCTURES | FIND_MY_STRUCTURES | FIND_HOSTILE_STRUCTURES | FIND_FLAGS | FIND_CONSTRUCTION_SITES | FIND_MY_SPAWNS | FIND_HOSTILE_SPAWNS | FIND_MY_CONSTRUCTION_SITES | FIND_HOSTILE_CONSTRUCTION_SITES | FIND_MINERALS | FIND_NUKES; +declare type ExitConstant = FIND_EXIT_TOP | FIND_EXIT_RIGHT | FIND_EXIT_BOTTOM | FIND_EXIT_LEFT; +declare type FIND_EXIT_TOP = 1; +declare type FIND_EXIT_RIGHT = 3; +declare type FIND_EXIT_BOTTOM = 5; +declare type FIND_EXIT_LEFT = 7; +declare type FIND_EXIT = 10; +declare type FIND_CREEPS = 101; +declare type FIND_MY_CREEPS = 102; +declare type FIND_HOSTILE_CREEPS = 103; +declare type FIND_SOURCES_ACTIVE = 104; +declare type FIND_SOURCES = 105; +declare type FIND_DROPPED_RESOURCES = 106; +declare type FIND_STRUCTURES = 107; +declare type FIND_MY_STRUCTURES = 108; +declare type FIND_HOSTILE_STRUCTURES = 109; +declare type FIND_FLAGS = 110; +declare type FIND_CONSTRUCTION_SITES = 111; +declare type FIND_MY_SPAWNS = 112; +declare type FIND_HOSTILE_SPAWNS = 113; +declare type FIND_MY_CONSTRUCTION_SITES = 114; +declare type FIND_HOSTILE_CONSTRUCTION_SITES = 115; +declare type FIND_MINERALS = 116; +declare type FIND_NUKES = 117; +declare type BodyPartConstant = MOVE | WORK | CARRY | ATTACK | RANGED_ATTACK | TOUGH | HEAL | CLAIM; +declare type MOVE = "move"; +declare type WORK = "work"; +declare type CARRY = "carry"; +declare type ATTACK = "attack"; +declare type RANGED_ATTACK = "ranged_attack"; +declare type TOUGH = "tough"; +declare type HEAL = "heal"; +declare type CLAIM = "claim"; +declare type LookConstant = LOOK_CREEPS | LOOK_ENERGY | LOOK_RESOURCES | LOOK_SOURCES | LOOK_MINERALS | LOOK_STRUCTURES | LOOK_FLAGS | LOOK_CONSTRUCTION_SITES | LOOK_NUKES | LOOK_TERRAIN; +declare type LOOK_CONSTRUCTION_SITES = "constructionSite"; +declare type LOOK_CREEPS = "creep"; +declare type LOOK_ENERGY = "energy"; +declare type LOOK_FLAGS = "flag"; +declare type LOOK_MINERALS = "mineral"; +declare type LOOK_NUKES = "nuke"; +declare type LOOK_RESOURCES = "resource"; +declare type LOOK_SOURCES = "source"; +declare type LOOK_STRUCTURES = "structure"; +declare type LOOK_TERRAIN = "terrain"; +declare type DirectionConstant = TOP | TOP_RIGHT | RIGHT | BOTTOM_RIGHT | BOTTOM | BOTTOM_LEFT | LEFT | TOP_LEFT; +declare type TOP = 1; +declare type TOP_RIGHT = 2; +declare type RIGHT = 3; +declare type BOTTOM_RIGHT = 4; +declare type BOTTOM = 5; +declare type BOTTOM_LEFT = 6; +declare type LEFT = 7; +declare type TOP_LEFT = 8; +declare type ColorConstant = COLOR_RED | COLOR_PURPLE | COLOR_BLUE | COLOR_CYAN | COLOR_GREEN | COLOR_YELLOW | COLOR_ORANGE | COLOR_BROWN | COLOR_GREY | COLOR_WHITE; +declare type COLOR_RED = 1; +declare type COLOR_PURPLE = 2; +declare type COLOR_BLUE = 3; +declare type COLOR_CYAN = 4; +declare type COLOR_GREEN = 5; +declare type COLOR_YELLOW = 6; +declare type COLOR_ORANGE = 7; +declare type COLOR_BROWN = 8; +declare type COLOR_GREY = 9; +declare type COLOR_WHITE = 10; +declare type StructureConstant = STRUCTURE_EXTENSION | STRUCTURE_RAMPART | STRUCTURE_ROAD | STRUCTURE_SPAWN | STRUCTURE_LINK | STRUCTURE_WALL | STRUCTURE_KEEPER_LAIR | STRUCTURE_CONTROLLER | STRUCTURE_STORAGE | STRUCTURE_TOWER | STRUCTURE_OBSERVER | STRUCTURE_POWER_BANK | STRUCTURE_POWER_SPAWN | STRUCTURE_EXTRACTOR | STRUCTURE_LAB | STRUCTURE_TERMINAL | STRUCTURE_CONTAINER | STRUCTURE_NUKER | STRUCTURE_PORTAL; +declare type STRUCTURE_EXTENSION = "extension"; +declare type STRUCTURE_RAMPART = "rampart"; +declare type STRUCTURE_ROAD = "road"; +declare type STRUCTURE_SPAWN = "spawn"; +declare type STRUCTURE_LINK = "link"; +declare type STRUCTURE_WALL = "wall"; +declare type STRUCTURE_KEEPER_LAIR = "keeperLair"; +declare type STRUCTURE_CONTROLLER = "controller"; +declare type STRUCTURE_STORAGE = "storage"; +declare type STRUCTURE_TOWER = "tower"; +declare type STRUCTURE_OBSERVER = "observer"; +declare type STRUCTURE_POWER_BANK = "powerBank"; +declare type STRUCTURE_POWER_SPAWN = "powerSpawn"; +declare type STRUCTURE_EXTRACTOR = "extractor"; +declare type STRUCTURE_LAB = "lab"; +declare type STRUCTURE_TERMINAL = "terminal"; +declare type STRUCTURE_CONTAINER = "container"; +declare type STRUCTURE_NUKER = "nuker"; +declare type STRUCTURE_PORTAL = "portal"; +declare type ResourceConstant = RESOURCE_ENERGY | RESOURCE_POWER | RESOURCE_UTRIUM | RESOURCE_LEMERGIUM | RESOURCE_KEANIUM | RESOURCE_GHODIUM | RESOURCE_ZYNTHIUM | RESOURCE_OXYGEN | RESOURCE_HYDROGEN | RESOURCE_CATALYST | RESOURCE_HYDROXIDE | RESOURCE_ZYNTHIUM_KEANITE | RESOURCE_UTRIUM_LEMERGITE | RESOURCE_UTRIUM_HYDRIDE | RESOURCE_UTRIUM_OXIDE | RESOURCE_KEANIUM_HYDRIDE | RESOURCE_KEANIUM_OXIDE | RESOURCE_LEMERGIUM_HYDRIDE | RESOURCE_LEMERGIUM_OXIDE | RESOURCE_ZYNTHIUM_HYDRIDE | RESOURCE_ZYNTHIUM_OXIDE | RESOURCE_GHODIUM_HYDRIDE | RESOURCE_GHODIUM_OXIDE | RESOURCE_UTRIUM_ACID | RESOURCE_UTRIUM_ALKALIDE | RESOURCE_KEANIUM_ACID | RESOURCE_KEANIUM_ALKALIDE | RESOURCE_LEMERGIUM_ACID | RESOURCE_LEMERGIUM_ALKALIDE | RESOURCE_ZYNTHIUM_ACID | RESOURCE_ZYNTHIUM_ALKALIDE | RESOURCE_GHODIUM_ACID | RESOURCE_GHODIUM_ALKALIDE | RESOURCE_CATALYZED_UTRIUM_ACID | RESOURCE_CATALYZED_UTRIUM_ALKALIDE | RESOURCE_CATALYZED_KEANIUM_ACID | RESOURCE_CATALYZED_KEANIUM_ALKALIDE | RESOURCE_CATALYZED_LEMERGIUM_ACID | RESOURCE_CATALYZED_LEMERGIUM_ALKALIDE | RESOURCE_CATALYZED_ZYNTHIUM_ACID | RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE | RESOURCE_CATALYZED_GHODIUM_ACID | RESOURCE_CATALYZED_GHODIUM_ALKALIDE; +declare type MineralConstant = RESOURCE_UTRIUM | RESOURCE_LEMERGIUM | RESOURCE_KEANIUM | RESOURCE_GHODIUM | RESOURCE_ZYNTHIUM | RESOURCE_OXYGEN | RESOURCE_HYDROGEN | RESOURCE_CATALYST; +declare type RESOURCE_ENERGY = "energy"; +declare type RESOURCE_POWER = "power"; +declare type RESOURCE_UTRIUM = "U"; +declare type RESOURCE_LEMERGIUM = "L"; +declare type RESOURCE_KEANIUM = "K"; +declare type RESOURCE_GHODIUM = "G"; +declare type RESOURCE_ZYNTHIUM = "Z"; +declare type RESOURCE_OXYGEN = "O"; +declare type RESOURCE_HYDROGEN = "H"; +declare type RESOURCE_CATALYST = "X"; +declare type RESOURCE_HYDROXIDE = "OH"; +declare type RESOURCE_ZYNTHIUM_KEANITE = "ZK"; +declare type RESOURCE_UTRIUM_LEMERGITE = "UL"; +declare type RESOURCE_UTRIUM_HYDRIDE = "UH"; +declare type RESOURCE_UTRIUM_OXIDE = "UO"; +declare type RESOURCE_KEANIUM_HYDRIDE = "KH"; +declare type RESOURCE_KEANIUM_OXIDE = "KO"; +declare type RESOURCE_LEMERGIUM_HYDRIDE = "LH"; +declare type RESOURCE_LEMERGIUM_OXIDE = "LO"; +declare type RESOURCE_ZYNTHIUM_HYDRIDE = "ZH"; +declare type RESOURCE_ZYNTHIUM_OXIDE = "ZO"; +declare type RESOURCE_GHODIUM_HYDRIDE = "GH"; +declare type RESOURCE_GHODIUM_OXIDE = "GO"; +declare type RESOURCE_UTRIUM_ACID = "UH2O"; +declare type RESOURCE_UTRIUM_ALKALIDE = "UHO2"; +declare type RESOURCE_KEANIUM_ACID = "KH2O"; +declare type RESOURCE_KEANIUM_ALKALIDE = "KHO2"; +declare type RESOURCE_LEMERGIUM_ACID = "LH2O"; +declare type RESOURCE_LEMERGIUM_ALKALIDE = "LHO2"; +declare type RESOURCE_ZYNTHIUM_ACID = "ZH2O"; +declare type RESOURCE_ZYNTHIUM_ALKALIDE = "ZHO2"; +declare type RESOURCE_GHODIUM_ACID = "GH2O"; +declare type RESOURCE_GHODIUM_ALKALIDE = "GHO2"; +declare type RESOURCE_CATALYZED_UTRIUM_ACID = "XUH2O"; +declare type RESOURCE_CATALYZED_UTRIUM_ALKALIDE = "XUHO2"; +declare type RESOURCE_CATALYZED_KEANIUM_ACID = "XKH2O"; +declare type RESOURCE_CATALYZED_KEANIUM_ALKALIDE = "XKHO2"; +declare type RESOURCE_CATALYZED_LEMERGIUM_ACID = "XLH2O"; +declare type RESOURCE_CATALYZED_LEMERGIUM_ALKALIDE = "XLHO2"; +declare type RESOURCE_CATALYZED_ZYNTHIUM_ACID = "XZH2O"; +declare type RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE = "ZXHO2"; +declare type RESOURCE_CATALYZED_GHODIUM_ACID = "XGH2O"; +declare type RESOURCE_CATALYZED_GHODIUM_ALKALIDE = "XGHO2"; /** * The options that can be accepted by `findRoute()` and friends. */ @@ -998,7 +1108,7 @@ interface GameMap { * Or one of the following Result codes: * ERR_NO_PATH, ERR_INVALID_ARGS */ - findExit(fromRoom: string | Room, toRoom: string | Room, opts?: RouteOptions): number; + findExit(fromRoom: string | Room, toRoom: string | Room, opts?: RouteOptions): ScreepsReturnCode; /** * Find route from the given room to another room. * @param fromRoom Start room name or room object. @@ -1007,9 +1117,9 @@ interface GameMap { * @returns the route array or ERR_NO_PATH code */ findRoute(fromRoom: string | Room, toRoom: string | Room, opts?: RouteOptions): { - exit: number; + exit: ExitConstant; room: string; - }[] | number; + }[] | ERR_NO_PATH; /** * Get the linear distance (in rooms) between two rooms. You can use this function to estimate the energy cost of * sending resources through terminals, or using observers and nukes. @@ -1025,12 +1135,12 @@ interface GameMap { * @param y Y position in the room. * @param roomName The room name. */ - getTerrainAt(x: number, y: number, roomName: string): string; + getTerrainAt(x: number, y: number, roomName: string): Terrain; /** * 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. * @param pos The position object. */ - getTerrainAt(pos: RoomPosition): string; + getTerrainAt(pos: RoomPosition): Terrain; /** * Check if the room is available to move into. * @param roomName The room name. @@ -1074,34 +1184,34 @@ interface Market { * @param orderId The order ID as provided in Game.market.orders * @returns Result Code: OK, ERR_INVALID_ARGS */ - cancelOrder(orderId: string): number; + cancelOrder(orderId: string): ScreepsReturnCode; /** * Change the price of an existing order. If newPrice is greater than old price, you will be charged (newPrice-oldPrice)*remainingAmount*0.05 credits. * @param orderId The order ID as provided in Game.market.orders * @param newPrice The new order price. * @returns Result Code: OK, ERR_NOT_OWNER, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_ARGS */ - changeOrderPrice(orderId: string, newPrice: number): number; + changeOrderPrice(orderId: string, newPrice: number): ScreepsReturnCode; /** * Create a market order in your terminal. You will be charged price*amount*0.05 credits when the order is placed. * The maximum orders count is 20 per player. You can create an order at any time with any amount, * it will be automatically activated and deactivated depending on the resource/credits availability. */ - createOrder(type: string, resourceType: string, price: number, totalAmount: number, roomName?: string): number; + createOrder(type: string, resourceType: ResourceConstant, price: number, totalAmount: number, roomName?: string): ScreepsReturnCode; /** * Execute a trade deal from your Terminal to another player's Terminal using the specified buy/sell order. * Your Terminal will be charged energy units of transfer cost regardless of the order resource type. * You can use Game.market.calcTransactionCost method to estimate it. * When multiple players try to execute the same deal, the one with the shortest distance takes precedence. */ - deal(orderId: string, amount: number, targetRoomName?: string): number; + deal(orderId: string, amount: number, targetRoomName?: string): ScreepsReturnCode; /** * Add more capacity to an existing order. It will affect remainingAmount and totalAmount properties. You will be charged price*addAmount*0.05 credits. * @param orderId The order ID as provided in Game.market.orders * @param addAmount How much capacity to add. Cannot be a negative value. * @returns Result Code: OK, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_ARGS */ - extendOrder(orderId: string, addAmount: number): number; + extendOrder(orderId: string, addAmount: number): ScreepsReturnCode; /** * Get other players' orders currently active on the market. * @param filter (optional) An object or function that will filter the resulting list using the lodash.filter method. @@ -1124,7 +1234,7 @@ interface Transaction { recipient?: { username: string; }; - resourceType: string; + resourceType: ResourceConstant; amount: number; from: string; to: string; @@ -1135,7 +1245,7 @@ interface Order { created: number; active?: boolean; type: string; - resourceType: string; + resourceType: ResourceConstant; roomName?: string; amount: number; remainingAmount: number; @@ -1146,7 +1256,7 @@ interface OrderFilter { id?: string; created?: number; type?: string; - resourceType?: string; + resourceType?: ResourceConstant; roomName?: string; amount?: number; remainingAmount?: number; @@ -1155,22 +1265,30 @@ interface OrderFilter { interface Memory { [name: string]: any; creeps: { - [name: string]: any; + [name: string]: CreepMemory; }; flags: { - [name: string]: any; + [name: string]: FlagMemory; }; rooms: { - [name: string]: any; + [name: string]: RoomMemory; }; spawns: { - [name: string]: any; + [name: string]: SpawnMemory; }; } +interface CreepMemory { +} +interface FlagMemory { +} +interface RoomMemory { +} +interface SpawnMemory { +} /** * A mineral deposit object. Can be harvested by creeps with a WORK body part using the extractor structure. */ -interface Mineral extends RoomObject { +interface Mineral extends RoomObject { /** * The prototype is stored in the Mineral.prototype global object. You can use it to extend game objects behaviour globally. */ @@ -1186,7 +1304,7 @@ interface Mineral extends RoomObject { /** * The resource type, one of the RESOURCE_* constants. */ - mineralType: string; + mineralType: T; /** * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. */ @@ -1378,7 +1496,7 @@ interface RawMemory { /** * 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. */ -interface Resource extends RoomObject { +interface Resource extends RoomObject { readonly prototype: Resource; /** * The amount of resource units containing. @@ -1391,7 +1509,7 @@ interface Resource extends RoomObject { /** * One of the `RESOURCE_*` constants. */ - resourceType: string; + resourceType: T; } interface ResourceConstructor { new (id: string): Resource; @@ -1440,29 +1558,29 @@ interface RoomPosition { * Create new ConstructionSite at the specified location. * @param structureType One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK */ - createConstructionSite(structureType: string): number; + createConstructionSite(structureType: StructureConstant): ScreepsReturnCode; /** * Create new Flag at the specified location. * @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. * @param color The color of a new flag. Should be one of the COLOR_* constants * @param secondaryColor The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color. */ - createFlag(name?: string, color?: number, secondaryColor?: number): number; + createFlag(name?: string, color?: ColorConstant, secondaryColor?: ColorConstant): ScreepsReturnCode; /** * Find an object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm. * @param type See Room.find * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm */ - findClosestByPath(type: number, opts?: FindPathOpts & { + findClosestByPath(type: FindConstant, opts?: FindPathOpts & { filter?: any | string; algorithm?: string; - }): T; + }): T | null; /** * Find an object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm. * @param objects An array of room's objects or RoomPosition objects that the search should be executed against. * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm */ - findClosestByPath(objects: T[] | RoomPosition[], opts?: FindPathOpts & { + findClosestByPath(objects: T[], opts?: FindPathOpts & { filter?: any | string; algorithm?: string; }): T; @@ -1471,15 +1589,15 @@ interface RoomPosition { * @param type See Room.find. * @param opts */ - findClosestByRange(type: number, opts?: { + findClosestByRange(type: FindConstant, opts?: { filter: any | string; - }): T; + }): T | null; /** * Find an object with the shortest linear distance from the given position. * @param objects An array of room's objects or RoomPosition objects that the search should be executed against. * @param opts An object containing one of the following options: filter */ - findClosestByRange(objects: T[] | RoomPosition[], opts?: { + findClosestByRange(objects: T[], opts?: { filter: any | string; }): T; /** @@ -1488,7 +1606,7 @@ interface RoomPosition { * @param range The range distance. * @param opts See Room.find. */ - findInRange(type: number, range: number, opts?: { + findInRange(type: FindConstant, range: number, opts?: { filter?: any | string; }): T[]; /** @@ -1497,7 +1615,7 @@ interface RoomPosition { * @param range The range distance. * @param opts See Room.find. */ - findInRange(objects: T[] | RoomPosition[], range: number, opts?: { + findInRange(objects: T[], range: number, opts?: { filter?: any | string; }): T[]; /** @@ -1512,22 +1630,18 @@ interface RoomPosition { * @param target Can be a RoomPosition object or any object containing RoomPosition. * @param opts An object containing pathfinding options flags (see Room.findPath for more details). */ - findPathTo(target: RoomPosition | { - pos: RoomPosition; - }, opts?: FindPathOpts): PathStep[]; + findPathTo(target: RoomPosition | _HasRoomPosition, opts?: FindPathOpts): PathStep[]; /** * Get linear direction to the specified position. * @param x X position in the room. * @param y Y position in the room. */ - getDirectionTo(x: number, y: number): number; + getDirectionTo(x: number, y: number): DirectionConstant; /** * Get linear direction to the specified position. * @param target Can be a RoomPosition object or any object containing RoomPosition. */ - getDirectionTo(target: RoomPosition | { - pos: RoomPosition; - }): number; + getDirectionTo(target: RoomPosition | _HasRoomPosition): number; /** * Get linear range to the specified position. * @param x X position in the room. @@ -1583,7 +1697,7 @@ interface RoomPosition { * Get an object with the given type at the specified room position. * @param type One of the following string constants: constructionSite, creep, exit, flag, resource, source, structure, terrain */ - lookFor(type: string): T[]; + lookFor(type: LookConstant): T[]; } interface RoomPositionConstructor extends _Constructor { /** @@ -1597,13 +1711,15 @@ interface RoomPositionConstructor extends _Constructor { } declare const RoomPosition: RoomPositionConstructor; declare class RoomVisual { - /** The name of the room. */ - roomName: string; /** - * You can directly create new RoomVisual object in any room, even if it's invisible to your script. - * @param roomName The room name. + * You can create new RoomVisual object using its constructor. + * @param roomName The room name. If undefined, visuals will be posted to all rooms simultaneously. + */ + constructor(roomName?: string); + /** + * The name of the room. */ - constructor(roomName: string); + roomName: string; /** * Draw a line. * @param x1 The start X coordinate. @@ -1614,6 +1730,14 @@ declare class RoomVisual { * @returns The RoomVisual object, for chaining. */ line(x1: number, y1: number, x2: number, y2: number, style?: LineStyle): RoomVisual; + /** + * Draw a line. + * @param pos1 The start position object. + * @param pos2 The finish position object. + * @param style The (optional) style. + * @returns The RoomVisual object, for chaining. + */ + line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyle): RoomVisual; /** * Draw a circle. * @param x The X coordinate of the center. @@ -1622,6 +1746,13 @@ declare class RoomVisual { * @returns The RoomVisual object, for chaining. */ circle(x: number, y: number, style?: CircleStyle): RoomVisual; + /** + * Draw a circle. + * @param pos The position object of the center. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + circle(pos: RoomPosition, style?: CircleStyle): RoomVisual; /** * Draw a rectangle. * @param x The X coordinate of the top-left corner. @@ -1632,13 +1763,22 @@ declare class RoomVisual { * @returns The RoomVisual object, for chaining. */ rect(x: number, y: number, w: number, h: number, style?: PolyStyle): RoomVisual; + /** + * Draw a line. + * @param topLeftPos The position object of the top-left corner. + * @param width The width of the rectangle. + * @param height The height of the rectangle. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + rect(topLeftPos: RoomPosition, width: number, height: number, style?: PolyStyle): RoomVisual; /** * Draw a polygon. - * @param points An array of point coordinate arrays, i.e. [[0,0], [5,5], [5,10]]. + * @param points An array of points. Every array item should be either an array with 2 numbers (i.e. [10,15]), or a RoomPosition object. * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - poly(points: [number, number][], style?: PolyStyle): RoomVisual; + poly(points: Array<[number, number] | RoomPosition>, style?: PolyStyle): RoomVisual; /** * Draw a text label. * @param text The text message. @@ -1648,6 +1788,14 @@ declare class RoomVisual { * @returns The RoomVisual object, for chaining. */ text(text: string, x: number, y: number, style?: TextStyle): RoomVisual; + /** + * Draw a text label. You can use any valid Unicode characters, including emoji. + * @param text The text message. + * @param pos The position object of the center. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + text(text: string, pos: RoomPosition, style?: TextStyle): RoomVisual; /** * Remove all visuals from the room. * @returns The RoomVisual object, for chaining. @@ -1661,25 +1809,84 @@ declare class RoomVisual { getSize(): number; } interface LineStyle { + /** + * Line width, default is 0.1. + */ width?: number; + /** + * Line color in any web format, default is #ffffff(white). + */ color?: string; + /** + * Opacity value, default is 0.5. + */ opacity?: number; + /** + * Either undefined (solid line), dashed, or dotted.Default is undefined. + */ lineStyle?: "dashed" | "dotted"; } interface PolyStyle { + /** + * Fill color in any web format, default is #ffffff(white). + */ fill?: string; + /** + * Opacity value, default is 0.5. + */ opacity?: number; + /** + * Stroke color in any web format, default is undefined (no stroke). + */ stroke?: string | undefined; + /** + * Stroke line width, default is 0.1. + */ strokeWidth?: number; + /** + * Either undefined (solid line), dashed, or dotted.Default is undefined. + */ lineStyle?: "dashed" | "dotted"; } interface CircleStyle extends PolyStyle { + /** + * Circle radius, default is 0.15. + */ radius?: number; } interface TextStyle { + /** + * Font color in any web format, default is #ffffff(white). + */ color?: string; - size?: number; + /** + * Either a number or a string in one of the following forms: + * 0.7 - relative size in game coordinates + * 20px - absolute size in pixels + * 0.7 serif + * bold italic 1.5 Times New Roman + */ + font?: number | string; + /** + * Stroke color in any web format, default is undefined (no stroke). + */ + stroke?: string; + /** + * Stroke width, default is 0.15. + */ + strokeWidth?: number; + /** + * Background color in any web format, default is undefined (no background).When background is enabled, text vertical align is set to middle (default is baseline). + */ + backgroundColor?: string; + /** + * Background rectangle padding, default is 0.3. + */ + backgroundPadding?: number; align?: "center" | "left" | "right"; + /** + * Opacity value, default is 1.0. + */ opacity?: number; } /** @@ -1690,7 +1897,7 @@ interface Room { /** * The Controller structure of this room, if present, otherwise undefined. */ - controller: Controller | undefined; + controller?: Controller; /** * Total amount of energy available in all spawns and extensions in the room. */ @@ -1702,7 +1909,7 @@ interface Room { /** * A shorthand to Memory.rooms[room.name]. You can use it for quick access the room’s specific memory data object. */ - memory: any; + memory: RoomMemory; /** * One of the following constants: * MODE_SIMULATION, MODE_SURVIVAL, MODE_WORLD, MODE_ARENA @@ -1715,13 +1922,13 @@ interface Room { /** * The Storage structure of this room, if present, otherwise undefined. */ - storage: StructureStorage | undefined; + storage?: StructureStorage; /** * The Terminal structure of this room, if present, otherwise undefined. */ - terminal: Terminal | undefined; + terminal?: Terminal; /** - * The RoomVisual object for this room. + * A RoomVisual object for this room. You can use this object to draw simple shapes (lines, circles, text labels) in the room. */ visual: RoomVisual; /** @@ -1731,16 +1938,14 @@ interface Room { * @param structureType One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK * @returns Result Code: OK, ERR_INVALID_TARGET, ERR_INVALID_ARGS, ERR_RCL_NOT_ENOUGH */ - createConstructionSite(x: number, y: number, structureType: string): number; + createConstructionSite(x: number, y: number, structureType: StructureConstant): ScreepsReturnCode; /** * Create new ConstructionSite at the specified location. * @param pos Can be a RoomPosition object or any object containing RoomPosition. * @param structureType One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK * @returns Result Code: OK, ERR_INVALID_TARGET, ERR_INVALID_ARGS, ERR_RCL_NOT_ENOUGH */ - createConstructionSite(pos: RoomPosition | { - pos: RoomPosition; - }, structureType: string): number; + createConstructionSite(pos: RoomPosition | _HasRoomPosition, structureType: StructureConstant): ScreepsReturnCode; /** * Create new Flag at the specified location. * @param x The X position. @@ -1749,7 +1954,7 @@ interface Room { * @param color The color of a new flag. Should be one of the COLOR_* constants. The default value is COLOR_WHITE. * @param secondaryColor The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color. */ - createFlag(x: number, y: number, name?: string, color?: number, secondaryColor?: number): number; + createFlag(x: number, y: number, name?: string, color?: ColorConstant, secondaryColor?: ColorConstant): ScreepsReturnCode; /** * Create new Flag at the specified location. * @param pos Can be a RoomPosition object or any object containing RoomPosition. @@ -1759,14 +1964,14 @@ interface Room { */ createFlag(pos: RoomPosition | { pos: RoomPosition; - }, name?: string, color?: number, secondaryColor?: number): number; + }, name?: string, color?: ColorConstant, secondaryColor?: ColorConstant): ScreepsReturnCode; /** * Find all objects of the specified type in the room. * @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 * @param opts An object with additional options * @returns An array with the objects found. */ - find(type: number, opts?: { + find(type: FindConstant, opts?: { filter: Object | Function | string; }): T[]; /** @@ -1775,7 +1980,7 @@ interface Room { * @returns The room direction constant, one of the following: FIND_EXIT_TOP, FIND_EXIT_RIGHT, FIND_EXIT_BOTTOM, FIND_EXIT_LEFT * Or one of the following error codes: ERR_NO_PATH, ERR_INVALID_ARGS */ - findExitTo(room: string | Room): number; + findExitTo(room: string | Room): ScreepsReturnCode | FIND_EXIT_TOP | FIND_EXIT_RIGHT | FIND_EXIT_BOTTOM | FIND_EXIT_LEFT; /** * Find an optimal path inside the room between fromPos and toPos using A* search algorithm. * @param fromPos The start position. @@ -1823,14 +2028,14 @@ interface Room { * @param y The Y position. * @returns An array of objects of the given type at the specified position if found. */ - lookForAt(type: string, x: number, y: number): T[]; + lookForAt(type: LookConstant, x: number, y: number): T[]; /** * Get an object with the given type at the specified room position. * @param type One of the following string constants: constructionSite, creep, energy, exit, flag, source, structure, terrain * @param target Can be a RoomPosition object or any object containing RoomPosition. * @returns An array of objects of the given type at the specified position if found. */ - lookForAt(type: string, target: RoomPosition | { + lookForAt(type: LookConstant, target: RoomPosition | { pos: RoomPosition; }): T[]; /** @@ -1842,7 +2047,7 @@ interface Room { * @param right The right X boundary of the area. * @returns An object with all the objects of the given type in the specified area */ - lookForAtArea(type: string, top: number, left: number, bottom: number, right: number, asArray?: boolean): LookAtResultMatrix | LookAtResultWithPos[]; + lookForAtArea(type: T, top: number, left: number, bottom: number, right: number, asArray?: boolean): LookAtResultMatrix | LookAtResultWithPos[]; } interface RoomConstructor { new (id: string): Room; @@ -1886,7 +2091,7 @@ declare const Source: SourceConstructor; /** * Spawns are your colony centers. You can transfer energy into it and create new creeps using createCreep() method. */ -interface StructureSpawn extends OwnedStructure { +interface StructureSpawn extends OwnedStructure { readonly prototype: StructureSpawn; /** * The amount of energy containing in the spawn. @@ -1899,7 +2104,7 @@ interface StructureSpawn extends OwnedStructure { /** * A shorthand to Memory.spawns[spawn.name]. You can use it for quick access the spawn’s specific memory data object. */ - memory: any; + memory: SpawnMemory; /** * 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. */ @@ -1920,7 +2125,7 @@ interface StructureSpawn extends OwnedStructure { * @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 * @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. */ - canCreateCreep(body: string[], name?: string): number; + canCreateCreep(body: BodyPartConstant[], name?: string): ScreepsReturnCode; /** * Start the creep spawning process. * The name of a new creep or one of these error codes @@ -1934,11 +2139,11 @@ interface StructureSpawn extends OwnedStructure { * @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. * @param memory The memory of a new creep. If provided, it will be immediately stored into Memory.creeps[name]. */ - createCreep(body: string[], name?: string, memory?: any): number | string; + createCreep(body: BodyPartConstant[], name?: string, memory?: CreepMemory): ScreepsReturnCode | string; /** * Destroy this spawn immediately. */ - destroy(): number; + destroy(): ScreepsReturnCode; /** * 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. */ @@ -1947,24 +2152,17 @@ interface StructureSpawn extends OwnedStructure { * Toggle auto notification when the spawn is under attack. The notification will be sent to your account email. Turned on by default. * @param enabled Whether to enable notification or disable. */ - notifyWhenAttacked(enabled: boolean): number; + notifyWhenAttacked(enabled: boolean): ScreepsReturnCode; /** * 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). * @param target The target creep object. */ - renewCreep(target: Creep): number; + renewCreep(target: Creep): ScreepsReturnCode; /** * 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. * @param target The target creep object. */ - recycleCreep(target: Creep): number; - /** - * @deprecated - * Transfer the energy from the spawn to a creep. - * @param target The creep object which energy should be transferred to. - * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. - */ - transferEnergy(target: Creep, amount?: number): number; + recycleCreep(target: Creep): ScreepsReturnCode; } interface StructureSpawnConstructor extends _Constructor, _ConstructorById { } @@ -1972,7 +2170,7 @@ declare const StructureSpawn: StructureSpawnConstructor; /** * Parent object for structure classes */ -interface Structure extends RoomObject { +interface Structure extends RoomObject { readonly prototype: Structure; /** * The current amount of hit points of the structure. @@ -1994,11 +2192,11 @@ interface Structure extends RoomObject { /** * One of the STRUCTURE_* constants. */ - structureType: string; + structureType: T; /** * Destroy this structure immediately. */ - destroy(): number; + destroy(): ScreepsReturnCode; /** * 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. */ @@ -2007,7 +2205,7 @@ interface Structure extends RoomObject { * Toggle auto notification when the structure is under attack. The notification will be sent to your account email. Turned on by default. * @param enabled Whether to enable notification or disable. */ - notifyWhenAttacked(enabled: boolean): number; + notifyWhenAttacked(enabled: boolean): ScreepsReturnCode; } interface StructureConstructor extends _Constructor, _ConstructorById { } @@ -2016,7 +2214,7 @@ declare const Structure: StructureConstructor; * The base prototype for a structure that has an owner. Such structures can be * found using `FIND_MY_STRUCTURES` and `FIND_HOSTILE_STRUCTURES` constants. */ -interface OwnedStructure extends Structure { +interface OwnedStructure extends Structure { readonly prototype: OwnedStructure; /** * Whether this is your own structure. Walls and roads don't have this property as they are considered neutral structures. @@ -2039,7 +2237,7 @@ declare const OwnedStructure: OwnedStructureConstructor; * cannot be damaged or destroyed. It can be addressed by `Room.controller` * property. */ -interface StructureController extends OwnedStructure { +interface StructureController extends OwnedStructure { readonly prototype: StructureController; /** * Current controller level, from 0 to 8. @@ -2060,7 +2258,7 @@ interface StructureController extends OwnedStructure { /** * How many ticks of safe mode are remaining, or undefined. */ - safeMode: number | undefined; + safeMode?: number; /** * Safe mode activations available to use. */ @@ -2068,7 +2266,7 @@ interface StructureController extends OwnedStructure { /** * During this period in ticks new safe mode activations will be blocked, undefined if cooldown is inactive. */ - safeModeCooldown: number | undefined; + safeModeCooldown?: number; /** * An object with the controller sign info if present */ @@ -2085,11 +2283,11 @@ interface StructureController extends OwnedStructure { * Activate safe mode if available. * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_NOT_ENOUGH_RESOURCES, ERR_TIRED */ - activateSafeMode(): number; + activateSafeMode(): ScreepsReturnCode; /** * Make your claimed controller neutral again. */ - unclaim(): number; + unclaim(): ScreepsReturnCode; } interface StructureControllerConstructor extends _Constructor, _ConstructorById { } @@ -2099,7 +2297,7 @@ declare const StructureController: StructureControllerConstructor; * be placed anywhere in the room, any spawns will be able to use them regardless * of distance. */ -interface StructureExtension extends OwnedStructure { +interface StructureExtension extends OwnedStructure { readonly prototype: StructureExtension; /** * The amount of energy containing in the extension. @@ -2109,13 +2307,6 @@ interface StructureExtension extends OwnedStructure { * The total amount of energy the extension can contain. */ energyCapacity: number; - /** - * @deprecated - * Transfer the energy from the extension to a creep. - * @param target The creep object which energy should be transferred to. - * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. - */ - transferEnergy(target: Creep, amount?: number): number; } interface StructureExtensionConstructor extends _Constructor, _ConstructorById { } @@ -2123,7 +2314,7 @@ declare const StructureExtension: StructureExtensionConstructor; /** * Remotely transfers energy to another Link in the same room. */ -interface StructureLink extends OwnedStructure { +interface StructureLink extends OwnedStructure { readonly prototype: StructureLink; /** * The amount of game ticks the link has to wait until the next transfer is possible. @@ -2142,7 +2333,7 @@ interface StructureLink extends OwnedStructure { * @param target The target object. * @param amount The amount of energy to be transferred. If omitted, all the available energy is used. */ - transferEnergy(target: Creep | StructureLink, amount?: number): number; + transferEnergy(target: Creep | StructureLink, amount?: number): ScreepsReturnCode; } interface StructureLinkConstructor extends _Constructor, _ConstructorById { } @@ -2151,12 +2342,12 @@ declare const StructureLink: StructureLinkConstructor; * Non-player structure. Spawns NPC Source Keepers that guards energy sources * and minerals in some rooms. This structure cannot be destroyed. */ -interface StructureKeeperLair extends OwnedStructure { +interface StructureKeeperLair extends OwnedStructure { readonly prototype: StructureKeeperLair; /** * Time to spawning of the next Source Keeper. */ - ticksToSpawn: number | undefined; + ticksToSpawn?: number; } interface StructureKeeperLairConstructor extends _Constructor, _ConstructorById { } @@ -2164,13 +2355,13 @@ declare const StructureKeeperLair: StructureKeeperLairConstructor; /** * Provides visibility into a distant room from your script. */ -interface StructureObserver extends OwnedStructure { +interface StructureObserver extends OwnedStructure { readonly prototype: StructureObserver; /** * 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. * @param roomName */ - observeRoom(roomName: string): number; + observeRoom(roomName: string): ScreepsReturnCode; } interface StructureObserverConstructor extends _Constructor, _ConstructorById { } @@ -2178,7 +2369,7 @@ declare const StructureObserver: StructureObserverConstructor; /** * */ -interface StructurePowerBank extends OwnedStructure { +interface StructurePowerBank extends OwnedStructure { readonly prototype: StructurePowerBank; /** * The amount of power containing. @@ -2196,7 +2387,7 @@ declare const StructurePowerBank: StructurePowerBankConstructor; * Non-player structure. Contains power resource which can be obtained by * destroying the structure. Hits the attacker creep back on each attack. */ -interface StructurePowerSpawn extends OwnedStructure { +interface StructurePowerSpawn extends OwnedStructure { readonly prototype: StructurePowerSpawn; /** * The amount of energy containing in this structure. @@ -2218,18 +2409,11 @@ interface StructurePowerSpawn extends OwnedStructure { * Create a power creep. Currently in development * @param name The name of the power creep. */ - createPowerCreep(name: string): number; + createPowerCreep(name: string): ScreepsReturnCode; /** * 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. */ - processPower(): number; - /** - * @deprecated - * Transfer the energy from this structure to a creep. - * @param target The creep object which energy should be transferred to. - * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. - */ - transferEnergy(target: Creep, amount?: number): number; + processPower(): ScreepsReturnCode; } interface StructurePowerSpawnConstructor extends _Constructor, _ConstructorById { } @@ -2238,7 +2422,7 @@ declare const StructurePowerSpawn: StructurePowerSpawnConstructor; * Blocks movement of hostile creeps, and defends your creeps and structures on * the same tile. Can be used as a controllable gate. */ -interface StructureRampart extends OwnedStructure { +interface StructureRampart extends OwnedStructure { readonly prototype: StructureRampart; /** * The amount of game ticks when this rampart will lose some hit points. @@ -2261,7 +2445,7 @@ declare const StructureRampart: StructureRampartConstructor; * Decreases movement cost to 1. Using roads allows creating creeps with less * `MOVE` body parts. */ -interface StructureRoad extends Structure { +interface StructureRoad extends Structure { readonly prototype: StructureRoad; /** * The amount of game ticks when this road will lose some hit points. @@ -2275,7 +2459,7 @@ declare const StructureRoad: StructureRoadConstructor; * A structure that can store huge amount of resource units. Only one structure * per room is allowed that can be addressed by `Room.storage` property. */ -interface StructureStorage extends OwnedStructure { +interface StructureStorage extends OwnedStructure { readonly prototype: StructureStorage; /** * An object with the storage contents. @@ -2285,21 +2469,6 @@ interface StructureStorage extends OwnedStructure { * The total amount of resources the storage can contain. */ storeCapacity: number; - /** - * Transfer resource from this storage to a creep. The target has to be at adjacent square. - * @param target The target object. - * @param resourceType One of the RESOURCE_* constants. - * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. - */ - transfer(target: Creep, resourceType: string, amount?: number): number; - /** - * @deprecated - * An alias for storage.transfer(target, RESOURCE_ENERGY, amount). - * @param target The target object. - * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. - * @deprecated - */ - transferEnergy(target: Creep, amount?: number): number; } interface StructureStorageConstructor extends _Constructor, _ConstructorById { } @@ -2309,7 +2478,7 @@ declare const StructureStorage: StructureStorageConstructor; * any object in the room. However, its effectiveness highly depends on the * distance. Each action consumes energy. */ -interface StructureTower extends OwnedStructure { +interface StructureTower extends OwnedStructure { readonly prototype: StructureTower; /** * The amount of energy containing in this structure. @@ -2323,23 +2492,17 @@ interface StructureTower extends OwnedStructure { * 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. * @param target The target creep. */ - attack(target: Creep): number; + attack(target: Creep): ScreepsReturnCode; /** * 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. * @param target The target creep. */ - heal(target: Creep): number; + heal(target: Creep): ScreepsReturnCode; /** * 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. * @param target The target structure. */ - repair(target: Spawn | Structure): number; - /** - * @deprecated - * @param target The creep object which energy should be transferred to. - * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. - */ - transferEnergy(target: Creep, amount?: number): number; + repair(target: Structure): ScreepsReturnCode; } interface StructureTowerConstructor extends _Constructor, _ConstructorById { } @@ -2347,7 +2510,7 @@ declare const StructureTower: StructureTowerConstructor; /** * Blocks movement of all creeps. */ -interface StructureWall extends Structure { +interface StructureWall extends Structure { readonly prototype: StructureWall; /** * The amount of game ticks when the wall will disappear (only for automatically placed border walls at the start of the game). @@ -2360,7 +2523,7 @@ declare const StructureWall: StructureWallConstructor; /** * Allows to harvest mineral deposits. */ -interface StructureExtractor extends OwnedStructure { +interface StructureExtractor extends OwnedStructure { readonly prototype: StructureExtractor; /** * The amount of game ticks until the next harvest action is possible. @@ -2373,7 +2536,7 @@ declare const StructureExtractor: StructureExtractorConstructor; /** * Produces mineral compounds from base minerals and boosts creeps. */ -interface StructureLab extends OwnedStructure { +interface StructureLab extends OwnedStructure { readonly prototype: StructureLab; /** * The amount of game ticks the lab has to wait until the next reaction is possible. @@ -2394,7 +2557,7 @@ interface StructureLab extends OwnedStructure { /** * The type of minerals containing in the lab. Labs can contain only one mineral type at the same time. */ - mineralType: string; + mineralType: MineralConstant; /** * The total amount of minerals the lab can contain. */ @@ -2404,20 +2567,13 @@ interface StructureLab extends OwnedStructure { * @param creep The target creep. * @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. */ - boostCreep(creep: Creep, bodyPartsCount?: number): number; + boostCreep(creep: Creep, bodyPartsCount?: number): ScreepsReturnCode; /** * 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 * @param lab1 The first source lab. * @param lab2 The second source lab. */ - runReaction(lab1: StructureLab, lab2: StructureLab): number; - /** - * Transfer resource from this structure to a creep. The target has to be at adjacent square. - * @param target The target object. - * @param resourceType One of the RESOURCE_* constants. - * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. - */ - transfer(target: Creep, resourceType: string, amount?: number): number; + runReaction(lab1: StructureLab, lab2: StructureLab): ScreepsReturnCode; } interface StructureLabConstructor extends _Constructor, _ConstructorById { } @@ -2425,12 +2581,12 @@ declare const StructureLab: StructureLabConstructor; /** * Sends any resources to a Terminal in another room. */ -interface StructureTerminal extends OwnedStructure { +interface StructureTerminal extends OwnedStructure { readonly prototype: StructureTerminal; /** * An object with the storage contents. Each object key is one of the RESOURCE_* constants, values are resources amounts. */ - store: any; + store: StoreDefinition; /** * The total amount of resources the storage can contain. */ @@ -2442,14 +2598,7 @@ interface StructureTerminal extends OwnedStructure { * @param destination The name of the target room. You don't have to gain visibility in this room. * @param description The description of the transaction. It is visible to the recipient. The maximum length is 100 characters. */ - send(resourceType: string, amount: number, destination: string, description?: string): number; - /** - * Transfer resource from this terminal to a creep. The target has to be at adjacent square. - * @param target The target object. - * @param resourceType One of the RESOURCE_* constants. - * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. - */ - transfer(target: Creep, resourceType: string, amount?: number): number; + send(resourceType: ResourceConstant, amount: number, destination: string, description?: string): ScreepsReturnCode; } interface StructureTerminalConstructor extends _Constructor, _ConstructorById { } @@ -2457,13 +2606,13 @@ declare const StructureTerminal: StructureTerminalConstructor; /** * Contains up to 2,000 resource units. Can be constructed in neutral rooms. Decays for 5,000 hits per 100 ticks. */ -interface StructureContainer extends Structure { +interface StructureContainer extends Structure { readonly prototype: StructureContainer; /** * An object with the structure contents. Each object key is one of the RESOURCE_* constants, values are resources * amounts. Use _.sum(structure.store) to get the total amount of contents */ - store: any; + store: StoreDefinition; /** * The total amount of resources the structure can contain. */ @@ -2472,13 +2621,6 @@ interface StructureContainer extends Structure { * The amount of game ticks when this container will lose some hit points. */ ticksToDecay: number; - /** - * Transfer resource from this structure to a creep. The target has to be at adjacent square. - * @param target The target object. - * @param resourceType One of the RESOURCE_* constants. - * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. - */ - transfer(target: Creep, resourceType: string, amount?: number): number; } interface StructureContainerConstructor extends _Constructor, _ConstructorById { } @@ -2490,7 +2632,7 @@ declare const StructureContainer: StructureContainerConstructor; * until it is landed. Incoming nuke cannot be moved or cancelled. Nukes cannot * be launched from or to novice rooms. */ -interface StructureNuker extends OwnedStructure { +interface StructureNuker extends OwnedStructure { readonly prototype: StructureNuker; /** * The amount of energy contained in this structure. @@ -2516,7 +2658,7 @@ interface StructureNuker extends OwnedStructure { * Launch a nuke to the specified position. * @param pos The target room position. */ - launchNuke(pos: RoomPosition): number; + launchNuke(pos: RoomPosition): ScreepsReturnCode; } interface StructureNukerConstructor extends _Constructor, _ConstructorById { } @@ -2526,7 +2668,7 @@ declare const StructureNuker: StructureNukerConstructor; * Instantly teleports your creeps to a distant room acting as a room exit tile. * Portals appear randomly in the central room of each sector. */ -interface StructurePortal extends Structure { +interface StructurePortal extends Structure { readonly prototype: StructurePortal; /** * The position object in the destination room. diff --git a/package.json b/package.json index 9052905..bb4c7ca 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "screeps-typescript-declarations", - "version": "4.3.1", + "name": "typed-screeps", + "version": "1.0.0", "description": "Typescript declarations for Screeps API. To enable autocomplete and help with compilation", - "repository": "screepers/Screeps-Typescript-Declarations", + "repository": "resir014/typed-screeps", "typings": "./dist/screeps.d.ts", "scripts": { "compile": "node_modules/.bin/tsc" diff --git a/src/constants.ts b/src/constants.ts index 576096e..5a1e905 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -32,7 +32,6 @@ declare const FIND_HOSTILE_CREEPS: 103; declare const FIND_SOURCES_ACTIVE: 104; declare const FIND_SOURCES: 105; declare const FIND_DROPPED_RESOURCES: 106; -declare const FIND_DROPPED_ENERGY: 106; // Yup, it's 106. declare const FIND_STRUCTURES: 107; declare const FIND_MY_STRUCTURES: 108; declare const FIND_HOSTILE_STRUCTURES: 109; @@ -64,13 +63,15 @@ declare const COLOR_ORANGE: 7; declare const COLOR_BROWN: 8; declare const COLOR_GREY: 9; declare const COLOR_WHITE: 10; -declare const COLORS_ALL: number[]; +declare const COLORS_ALL: ColorConstant[]; declare const CREEP_SPAWN_TIME: 3; declare const CREEP_LIFE_TIME: 1500; declare const CREEP_CLAIM_LIFE_TIME: 500; declare const CREEP_CORPSE_RATE: 0.2; +// TODO figure out best way to type this next line +// because it includes "creep" declare const OBSTACLE_OBJECT_TYPES: string[]; declare const ENERGY_REGEN_TIME: 300; @@ -129,18 +130,9 @@ declare const LINK_LOSS_RATIO: 0.03; declare const STORAGE_CAPACITY: 1000000; declare const STORAGE_HITS: 10000; -declare const BODYPART_COST: { - [part: string]: number; - move: 50; - work: 100; - attack: 80; - carry: 50; - heal: 250; - ranged_attack: 150; - tough: 10; - claim: 600; -}; -declare const BODYPARTS_ALL: string[]; +declare const BODYPART_COST: Record; + +declare const BODYPARTS_ALL: BodyPartConstant[]; declare const CARRY_CAPACITY: 50; @@ -165,23 +157,8 @@ declare const TOUGH: "tough"; declare const HEAL: "heal"; declare const CLAIM: "claim"; -declare const CONSTRUCTION_COST: { - spawn: 15000, - extension: 3000, - road: 300, - constructedWall: 1, - rampart: 1, - link: 5000, - storage: 30000, - tower: 5000, - observer: 8000, - powerSpawn: 100000, - extractor: 5000, - lab: 50000, - terminal: 100000, - container: 5000, - nuker: 100000 -}; +// TODO do we care that some structure constants aren't buildable? +declare const CONSTRUCTION_COST: Record; declare const CONSTRUCTION_COST_ROAD_SWAMP_RATIO: 5; @@ -248,12 +225,13 @@ declare const RESOURCE_CATALYZED_ZYNTHIUM_ACID: "XZH2O"; declare const RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE: "ZXHO2"; declare const RESOURCE_CATALYZED_GHODIUM_ACID: "XGH2O"; declare const RESOURCE_CATALYZED_GHODIUM_ALKALIDE: "XGHO2"; -declare const RESOURCES_ALL: string[]; +declare const RESOURCES_ALL: ResourceConstant[]; declare const SUBSCRIPTION_TOKEN: string; declare const CONTROLLER_LEVELS: {[level: number]: number}; -declare const CONTROLLER_STRUCTURES: {[structure: string]: {[level: number]: number}}; +declare const CONTROLLER_STRUCTURES: Record; + declare const CONTROLLER_DOWNGRADE: {[level: number]: number}; declare const CONTROLLER_CLAIM_DOWNGRADE: number; declare const CONTROLLER_RESERVE: number; @@ -312,15 +290,7 @@ declare const MAX_CONSTRUCTION_SITES: number; declare const MAX_CREEP_SIZE: number; declare const MINERAL_REGEN_TIME: number; -declare const MINERAL_MIN_AMOUNT: { - H: number, - O: number, - L: number, - K: number, - Z: number, - U: number, - X: number -} +declare const MINERAL_MIN_AMOUNT: Record; declare const MINERAL_RANDOM_FACTOR: number; @@ -366,15 +336,17 @@ declare const NUKE_DAMAGE: { 4: number } +// TODO make this more strongly typed declare const REACTIONS: { - [reagent: string]: { - [reagent: string]: string + [T in ResourceConstant]: { + [P in ResourceConstant]: ResourceConstant } } +// TODO type "action" declare const BOOSTS: { - [part: string]: { - [boost: string]: { + [P in BodyPartConstant]: { + [T in ResourceConstant]: { [action: string]: number } } diff --git a/src/construction-site.ts b/src/construction-site.ts index 321b396..613e7a9 100644 --- a/src/construction-site.ts +++ b/src/construction-site.ts @@ -1,7 +1,7 @@ /** * A site of a structure which is currently under construction. */ -interface ConstructionSite extends RoomObject { +interface ConstructionSite extends RoomObject { readonly prototype: ConstructionSite; /** * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. @@ -26,7 +26,7 @@ interface ConstructionSite extends RoomObject { /** * One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK */ - structureType: string; + structureType: T; /** * Remove the construction site. * @returns Result Code: OK, ERR_NOT_OWNER diff --git a/src/creep.ts b/src/creep.ts index c5adecb..602866b 100644 --- a/src/creep.ts +++ b/src/creep.ts @@ -4,7 +4,7 @@ */ interface Creep extends RoomObject { readonly prototype: Creep; - + /** * An array describing the creep’s body. Each element contains the following properties: * type: string @@ -42,7 +42,7 @@ interface Creep extends RoomObject { /** * A shorthand to Memory.creeps[creep.name]. You can use it for quick access the creep’s specific memory data object. */ - memory: any; + memory: CreepMemory; /** * Whether it is your creep or foe. */ @@ -75,126 +75,126 @@ interface Creep extends RoomObject { * 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. * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART */ - attack(target: Creep|Structure): number; + attack(target: Creep|Structure): CreepActionReturnCode; /** * 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. * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART */ - attackController(target: Controller): number; + attackController(target: Controller): CreepActionReturnCode; /** * 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. * @param target The target object to be attacked. * @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 */ - build(target: ConstructionSite): number; + build(target: ConstructionSite): CreepActionReturnCode | ERR_RCL_NOT_ENOUGH; /** * Cancel the order given during the current game tick. * @param methodName The name of a creep's method to be cancelled. * @returns Result Code: OK, ERR_NOT_FOUND */ - cancelOrder(methodName: string): number; + cancelOrder(methodName: string): OK | ERR_NOT_FOUND; /** * 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. * @param target The target controller object. * @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 */ - claimController(target: Controller): number; + claimController(target: Controller): CreepActionReturnCode | ERR_FULL | ERR_RCL_NOT_ENOUGH; /** * 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. * @param target The target structure. */ - dismantle(target: Structure): number; + dismantle(target: Structure): CreepActionReturnCode; /** * Drop this resource on the ground. * @param resourceType One of the RESOURCE_* constants. * @param amount The amount of resource units to be dropped. If omitted, all the available carried amount is used. */ - drop(resourceType: string, amount?: number): number; + drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES; /** * 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. * @param target The target room controller. * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE */ - generateSafeMode(target: Controller): number; + generateSafeMode(target: Controller): CreepActionReturnCode; /** * Get the quantity of live body parts of the given type. Fully damaged parts do not count. * @param type A body part type, one of the following body part constants: MOVE, WORK, CARRY, ATTACK, RANGED_ATTACK, HEAL, TOUGH, CLAIM */ - getActiveBodyparts(type: string): number; + getActiveBodyparts(type: BodyPartConstant): number; /** * 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. * @param target The source object to be harvested. */ - harvest(target: Source | Mineral): number; + harvest(target: Source | Mineral): CreepActionReturnCode | ERR_NOT_FOUND | ERR_NOT_ENOUGH_RESOURCES; /** * 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. * @param target The target creep object. */ - heal(target: Creep): number; + heal(target: Creep): CreepActionReturnCode; /** * Move the creep one square in the specified direction. Needs the MOVE body part. * @param direction */ - move(direction: number) : number; + move(direction: DirectionConstant): CreepMoveReturnCode; /** * Move the creep using the specified predefined path. Needs the MOVE body part. * @param path A path value as returned from Room.findPath or RoomPosition.findPathTo methods. Both array form and serialized string form are accepted. */ - moveByPath(path: PathStep[] | RoomPosition[] | string): number; + moveByPath(path: PathStep[] | RoomPosition[] | string): CreepMoveReturnCode | ERR_NOT_FOUND | ERR_INVALID_ARGS; /** * 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. * @param x X position of the target in the room. * @param y Y position of the target in the room. * @param opts An object containing pathfinding options flags (see Room.findPath for more info) or one of the following: reusePath, serializeMemory, noPathFinding */ - moveTo(x: number, y: number, opts?: MoveToOpts): number; + moveTo(x: number, y: number, opts?: MoveToOpts): CreepMoveReturnCode | ERR_NO_PATH | ERR_INVALID_TARGET; /** * 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. * @param target Can be a RoomPosition object or any object containing RoomPosition. * @param opts An object containing pathfinding options flags (see Room.findPath for more info) or one of the following: reusePath, serializeMemory, noPathFinding */ - moveTo(target: RoomPosition|{pos: RoomPosition}, opts?: MoveToOpts): number; + moveTo(target: RoomPosition|{pos: RoomPosition}, opts?: MoveToOpts): CreepMoveReturnCode | ERR_NO_PATH | ERR_INVALID_TARGET; /** * Toggle auto notification when the creep is under attack. The notification will be sent to your account email. Turned on by default. * @param enabled Whether to enable notification or disable. */ - notifyWhenAttacked(enabled: boolean): number; + notifyWhenAttacked(enabled: boolean): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_ARGS; /** * 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. * @param target The target object to be picked up. */ - pickup(target: Resource): number; + pickup(target: Resource): CreepActionReturnCode | ERR_FULL; /** * 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. * @param target The target object to be attacked. */ - rangedAttack(target: Creep|Structure): number; + rangedAttack(target: Creep|Structure): CreepActionReturnCode; /** * 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. * @param target The target creep object. */ - rangedHeal(target: Creep): number; + rangedHeal(target: Creep): CreepActionReturnCode; /** * 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. */ - rangedMassAttack(): number; + rangedMassAttack(): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NO_BODYPART; /** * 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. * @param target he target structure to be repaired. */ - repair(target: Structure): number; + repair(target: Structure): CreepActionReturnCode | ERR_NOT_ENOUGH_RESOURCES; /** * 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.... * @param target The target controller object to be reserved. * @return Result code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART */ - reserveController(target: Controller): number; + reserveController(target: Controller): CreepActionReturnCode; /** * 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. * @param message The message to be displayed. Maximum length is 10 characters. * @param set to 'true' to allow other players to see this message. Default is 'false'. */ - say(message: string, toPublic?: boolean): number; + say(message: string, toPublic?: boolean): OK | ERR_NOT_OWNER | ERR_BUSY; /** * 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. * 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. @@ -202,30 +202,30 @@ interface Creep extends RoomObject { * @param text The sign text. The maximum text length is 100 characters. * @returns Result Code: OK, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE */ - signController(target:Controller, text:string): number; + signController(target: Controller, text: string): OK | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE; /** * Kill the creep immediately. */ - suicide(): number; + suicide(): OK | ERR_NOT_OWNER | ERR_BUSY; /** * Transfer resource from the creep to another object. The target has to be at adjacent square to the creep. * @param target The target object. * @param resourceType One of the RESOURCE_* constants * @param amount The amount of resources to be transferred. If omitted, all the available carried amount is used. */ - transfer(target: Creep|Structure, resourceType: string, amount?: number): number; + transfer(target: Creep|Structure, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode; /** * 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. * @param target The target controller object to be upgraded. */ - upgradeController(target: Controller): number; + upgradeController(target: Controller): ScreepsReturnCode; /** * 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. * @param target The target object. * @param resourceType The target One of the RESOURCE_* constants.. * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. */ - withdraw(target: Structure, resourceType: string, amount?: number): number; + withdraw(target: Structure, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode; } interface CreepConstructor extends _Constructor, _ConstructorById { diff --git a/src/flag.ts b/src/flag.ts index a3805e3..2b06053 100644 --- a/src/flag.ts +++ b/src/flag.ts @@ -3,15 +3,15 @@ */ interface Flag extends RoomObject { readonly prototype: Flag; - + /** * 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 */ - color: number; + color: ColorConstant; /** * A shorthand to Memory.flags[flag.name]. You can use it for quick access the flag's specific memory data object. */ - memory: any; + memory: FlagMemory; /** * 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. */ @@ -19,37 +19,37 @@ interface Flag extends RoomObject { /** * Flag secondary color. One of the COLOR_* constants. */ - secondaryColor: number; + secondaryColor: ColorConstant; /** * Remove the flag. * @returns Result Code: OK */ - remove(): number; + remove(): OK; /** * Set new color of the flag. * @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 * @parma secondaryColor Secondary color of the flag. One of the COLOR_* constants. * @returns Result Code: OK, ERR_INVALID_ARGS */ - setColor(color: number, secondaryColor?: number): number; + setColor(color: ColorConstant, secondaryColor?: ColorConstant): OK | ERR_INVALID_ARGS; /** * Set new position of the flag. * @param x The X position in the room. * @param y The Y position in the room. * @returns Result Code: OK, ERR_INVALID_TARGET */ - setPosition(x: number,y: number): number; + setPosition(x: number,y: number): OK | ERR_INVALID_ARGS; /** * Set new position of the flag. * @param pos Can be a RoomPosition object or any object containing RoomPosition. * @returns Result Code: OK, ERR_INVALID_TARGET */ - setPosition(pos: RoomPosition|{pos: RoomPosition}): number; + setPosition(pos: RoomPosition|{pos: RoomPosition}): OK | ERR_INVALID_ARGS; } interface FlagConstructor extends _Constructor { - new (name: string, color: number, secondaryColor: number, roomName: string, x: number, y: number): Flag; - (name: string, color: number, secondaryColor: number, roomName: string, x: number, y: number): Flag; + new (name: string, color: ColorConstant, secondaryColor: ColorConstant, roomName: string, x: number, y: number): Flag; + (name: string, color: ColorConstant, secondaryColor: ColorConstant, roomName: string, x: number, y: number): Flag; } declare const Flag: FlagConstructor; diff --git a/src/helpers.ts b/src/helpers.ts index dc7cc53..c46c84f 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,3 +1,5 @@ +type _HasRoomPosition = { pos: RoomPosition } + interface GlobalControlLevel { level: number; progress: number; @@ -22,11 +24,11 @@ interface BodyPartDefinition { /** * If the body part is boosted, this property specifies the mineral type which is used for boosting. One of the RESOURCE_* constants. */ - boost: string; + boost?: ResourceConstant; /** * One of the body part types constants. */ - type: string; + type: BodyPartConstant; /** * The remaining amount of hit points of this body part. */ @@ -45,44 +47,32 @@ interface SignDefinition { time: number, datetime: Date; } -interface StoreDefinition { - [resource: string]: number | undefined; - energy?: number; - power?: number; -} -interface LookAtResultWithPos { - x: number; - y: number; - type: string; +type StoreDefinition = Record & { energy: number }; + +interface LookAtTypes { constructionSite?: ConstructionSite; creep?: Creep; - terrain?: string; - structure?: Structure; + energy?: Resource; + exit?: any; // TODO what type is this? flag?: Flag; - energy?: Resource; - exit?: any; - source?: Source; mineral?: Mineral; + nuke?: Nuke; resource? : Resource; -} -interface LookAtResult { - type: string; - constructionSite?: ConstructionSite; - creep?: Creep; - energy?: Resource; - exit?: any; - flag?: Flag; source?: Source; structure?: Structure; - terrain?: string; - mineral?: Mineral; - resource?: Resource; + terrain?: Terrain; } +type LookAtResult = Pick & { type: K } + +type LookAtResultWithPos = LookAtResult & { + x: number, + y: number, +} -interface LookAtResultMatrix { - [coord: number]: LookAtResultMatrix|LookAtResult[] +interface LookAtResultMatrix { + [coord: number]: LookAtResultMatrix | LookAtResult[] } interface FindPathOpts { @@ -120,13 +110,13 @@ interface FindPathOpts { * An array of the room's objects or RoomPosition objects which should be treated as walkable tiles during the search. This option * cannot be used when the new PathFinder is enabled (use costCallback option instead). */ - ignore?: any[]|RoomPosition[]; + ignore?: any[] | RoomPosition[]; /** * An array of the room's objects or RoomPosition objects which should be treated as obstacles during the search. This option cannot * be used when the new PathFinder is enabled (use costCallback option instead). */ - avoid?: any[]|RoomPosition[]; + avoid?: any[] | RoomPosition[]; /** * The maximum limit of possible pathfinding operations. You can limit CPU time used for the search based on ratio 1 op ~ 0.001 CPU. @@ -188,7 +178,7 @@ interface PathStep { dx: number; y: number; dy: number; - direction: number; + direction: DirectionConstant; } /** diff --git a/src/literals.ts b/src/literals.ts new file mode 100644 index 0000000..2c58b4c --- /dev/null +++ b/src/literals.ts @@ -0,0 +1,365 @@ +/** + * This file creates literal versions of many of the constants + * It should be kept in sync with constants.ts + */ + +//// Extras + +type Terrain = "plain" | "swamp" | "wall"; + +//////// +// Return Codes + +type ScreepsReturnCode = + OK | + ERR_NOT_OWNER | + ERR_NO_PATH | + ERR_BUSY | + ERR_NOT_FOUND | + ERR_NOT_ENOUGH_RESOURCES | + ERR_NOT_ENOUGH_ENERGY | + ERR_INVALID_TARGET | + ERR_FULL | + ERR_NOT_IN_RANGE | + ERR_INVALID_ARGS | + ERR_TIRED | + ERR_NO_BODYPART | + ERR_NOT_ENOUGH_EXTENSIONS | + ERR_RCL_NOT_ENOUGH | + ERR_GCL_NOT_ENOUGH + +type OK = 0; +type ERR_NOT_OWNER = -1; +type ERR_NO_PATH = -2; +type ERR_NAME_EXISTS = -3; +type ERR_BUSY = -4; +type ERR_NOT_FOUND = -5; +type ERR_NOT_ENOUGH_RESOURCES = -6; +type ERR_NOT_ENOUGH_ENERGY = -6; +type ERR_INVALID_TARGET = -7; +type ERR_FULL = -8; +type ERR_NOT_IN_RANGE = -9; +type ERR_INVALID_ARGS = -10; +type ERR_TIRED = -11; +type ERR_NO_BODYPART = -12; +type ERR_NOT_ENOUGH_EXTENSIONS = -6; +type ERR_RCL_NOT_ENOUGH = -14; +type ERR_GCL_NOT_ENOUGH = -15; + +type CreepActionReturnCode = + OK | + ERR_NOT_OWNER | + ERR_BUSY | + ERR_INVALID_TARGET | + ERR_NOT_IN_RANGE | + ERR_NO_BODYPART + +type CreepMoveReturnCode = + OK | + ERR_NOT_OWNER | + ERR_BUSY | + ERR_TIRED | + ERR_NO_BODYPART + +//////// +// Find Constants + +type ExitConstant = + FIND_EXIT_TOP | + FIND_EXIT_RIGHT | + FIND_EXIT_BOTTOM | + FIND_EXIT_LEFT + +type FindConstant = + FIND_EXIT_TOP | + FIND_EXIT_RIGHT | + FIND_EXIT_BOTTOM | + FIND_EXIT_LEFT | + FIND_EXIT | + FIND_CREEPS | + FIND_MY_CREEPS | + FIND_HOSTILE_CREEPS | + FIND_SOURCES_ACTIVE | + FIND_SOURCES | + FIND_DROPPED_RESOURCES | + FIND_STRUCTURES | + FIND_MY_STRUCTURES | + FIND_HOSTILE_STRUCTURES | + FIND_FLAGS | + FIND_CONSTRUCTION_SITES | + FIND_MY_SPAWNS | + FIND_HOSTILE_SPAWNS | + FIND_MY_CONSTRUCTION_SITES | + FIND_HOSTILE_CONSTRUCTION_SITES | + FIND_MINERALS | + FIND_NUKES + +type FIND_EXIT_TOP = 1; +type FIND_EXIT_RIGHT = 3; +type FIND_EXIT_BOTTOM = 5; +type FIND_EXIT_LEFT = 7; +type FIND_EXIT = 10; +type FIND_CREEPS = 101; +type FIND_MY_CREEPS = 102; +type FIND_HOSTILE_CREEPS = 103; +type FIND_SOURCES_ACTIVE = 104; +type FIND_SOURCES = 105; +type FIND_DROPPED_RESOURCES = 106; +type FIND_STRUCTURES = 107; +type FIND_MY_STRUCTURES = 108; +type FIND_HOSTILE_STRUCTURES = 109; +type FIND_FLAGS = 110; +type FIND_CONSTRUCTION_SITES = 111; +type FIND_MY_SPAWNS = 112; +type FIND_HOSTILE_SPAWNS = 113; +type FIND_MY_CONSTRUCTION_SITES = 114; +type FIND_HOSTILE_CONSTRUCTION_SITES = 115; +type FIND_MINERALS = 116; +type FIND_NUKES = 117; + +//////// +// Body Part Constants + +type BodyPartConstant = + MOVE | + WORK | + CARRY | + ATTACK | + RANGED_ATTACK | + TOUGH | + HEAL | + CLAIM + +type MOVE = "move"; +type WORK = "work"; +type CARRY = "carry"; +type ATTACK = "attack"; +type RANGED_ATTACK = "ranged_attack"; +type TOUGH = "tough"; +type HEAL = "heal"; +type CLAIM = "claim"; + +//////// +// Look Constants + +type LookConstant = + LOOK_CREEPS | + LOOK_ENERGY | + LOOK_RESOURCES | + LOOK_SOURCES | + LOOK_MINERALS | + LOOK_STRUCTURES | + LOOK_FLAGS | + LOOK_CONSTRUCTION_SITES | + LOOK_NUKES | + LOOK_TERRAIN + +type LOOK_CONSTRUCTION_SITES = "constructionSite"; +type LOOK_CREEPS = "creep"; +type LOOK_ENERGY = "energy"; +type LOOK_FLAGS = "flag"; +type LOOK_MINERALS = "mineral"; +type LOOK_NUKES = "nuke"; +type LOOK_RESOURCES = "resource"; +type LOOK_SOURCES = "source"; +type LOOK_STRUCTURES = "structure"; +type LOOK_TERRAIN = "terrain"; + +//////// +// Direction Constants + +type DirectionConstant = + TOP | + TOP_RIGHT | + RIGHT | + BOTTOM_RIGHT | + BOTTOM | + BOTTOM_LEFT | + LEFT | + TOP_LEFT; + +type TOP = 1; +type TOP_RIGHT = 2; +type RIGHT = 3; +type BOTTOM_RIGHT = 4; +type BOTTOM = 5; +type BOTTOM_LEFT = 6; +type LEFT = 7; +type TOP_LEFT = 8; + +//////// +// Color Constants + +type ColorConstant = + COLOR_RED | + COLOR_PURPLE | + COLOR_BLUE | + COLOR_CYAN | + COLOR_GREEN | + COLOR_YELLOW | + COLOR_ORANGE | + COLOR_BROWN | + COLOR_GREY | + COLOR_WHITE + +type COLOR_RED = 1; +type COLOR_PURPLE = 2; +type COLOR_BLUE = 3; +type COLOR_CYAN = 4; +type COLOR_GREEN = 5; +type COLOR_YELLOW = 6; +type COLOR_ORANGE = 7; +type COLOR_BROWN = 8; +type COLOR_GREY = 9; +type COLOR_WHITE = 10; + +//////// +// Structure Constants + +type StructureConstant = + STRUCTURE_EXTENSION | + STRUCTURE_RAMPART | + STRUCTURE_ROAD | + STRUCTURE_SPAWN | + STRUCTURE_LINK | + STRUCTURE_WALL | + STRUCTURE_KEEPER_LAIR | + STRUCTURE_CONTROLLER | + STRUCTURE_STORAGE | + STRUCTURE_TOWER | + STRUCTURE_OBSERVER | + STRUCTURE_POWER_BANK | + STRUCTURE_POWER_SPAWN | + STRUCTURE_EXTRACTOR | + STRUCTURE_LAB | + STRUCTURE_TERMINAL | + STRUCTURE_CONTAINER | + STRUCTURE_NUKER | + STRUCTURE_PORTAL; + +type STRUCTURE_EXTENSION = "extension"; +type STRUCTURE_RAMPART = "rampart"; +type STRUCTURE_ROAD = "road"; +type STRUCTURE_SPAWN = "spawn"; +type STRUCTURE_LINK = "link"; +type STRUCTURE_WALL = "wall"; +type STRUCTURE_KEEPER_LAIR = "keeperLair"; +type STRUCTURE_CONTROLLER = "controller"; +type STRUCTURE_STORAGE = "storage"; +type STRUCTURE_TOWER = "tower"; +type STRUCTURE_OBSERVER = "observer"; +type STRUCTURE_POWER_BANK = "powerBank"; +type STRUCTURE_POWER_SPAWN = "powerSpawn"; +type STRUCTURE_EXTRACTOR = "extractor"; +type STRUCTURE_LAB = "lab"; +type STRUCTURE_TERMINAL = "terminal"; +type STRUCTURE_CONTAINER = "container"; +type STRUCTURE_NUKER = "nuker"; +type STRUCTURE_PORTAL = "portal"; + +//////// +// Resource Constants + +type ResourceConstant = + RESOURCE_ENERGY | + RESOURCE_POWER | + RESOURCE_UTRIUM | + RESOURCE_LEMERGIUM | + RESOURCE_KEANIUM | + RESOURCE_GHODIUM | + RESOURCE_ZYNTHIUM | + RESOURCE_OXYGEN | + RESOURCE_HYDROGEN | + RESOURCE_CATALYST | + RESOURCE_HYDROXIDE | + RESOURCE_ZYNTHIUM_KEANITE | + RESOURCE_UTRIUM_LEMERGITE | + RESOURCE_UTRIUM_HYDRIDE | + RESOURCE_UTRIUM_OXIDE | + RESOURCE_KEANIUM_HYDRIDE | + RESOURCE_KEANIUM_OXIDE | + RESOURCE_LEMERGIUM_HYDRIDE | + RESOURCE_LEMERGIUM_OXIDE | + RESOURCE_ZYNTHIUM_HYDRIDE | + RESOURCE_ZYNTHIUM_OXIDE | + RESOURCE_GHODIUM_HYDRIDE | + RESOURCE_GHODIUM_OXIDE | + RESOURCE_UTRIUM_ACID | + RESOURCE_UTRIUM_ALKALIDE | + RESOURCE_KEANIUM_ACID | + RESOURCE_KEANIUM_ALKALIDE | + RESOURCE_LEMERGIUM_ACID | + RESOURCE_LEMERGIUM_ALKALIDE | + RESOURCE_ZYNTHIUM_ACID | + RESOURCE_ZYNTHIUM_ALKALIDE | + RESOURCE_GHODIUM_ACID | + RESOURCE_GHODIUM_ALKALIDE | + RESOURCE_CATALYZED_UTRIUM_ACID | + RESOURCE_CATALYZED_UTRIUM_ALKALIDE | + RESOURCE_CATALYZED_KEANIUM_ACID | + RESOURCE_CATALYZED_KEANIUM_ALKALIDE | + RESOURCE_CATALYZED_LEMERGIUM_ACID | + RESOURCE_CATALYZED_LEMERGIUM_ALKALIDE | + RESOURCE_CATALYZED_ZYNTHIUM_ACID | + RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE | + RESOURCE_CATALYZED_GHODIUM_ACID | + RESOURCE_CATALYZED_GHODIUM_ALKALIDE + +type MineralConstant = + RESOURCE_UTRIUM | + RESOURCE_LEMERGIUM | + RESOURCE_KEANIUM | + RESOURCE_GHODIUM | + RESOURCE_ZYNTHIUM | + RESOURCE_OXYGEN | + RESOURCE_HYDROGEN | + RESOURCE_CATALYST + +type RESOURCE_ENERGY = "energy"; +type RESOURCE_POWER = "power"; + +type RESOURCE_UTRIUM = "U"; +type RESOURCE_LEMERGIUM = "L"; +type RESOURCE_KEANIUM = "K"; +type RESOURCE_GHODIUM = "G"; +type RESOURCE_ZYNTHIUM = "Z"; +type RESOURCE_OXYGEN = "O"; +type RESOURCE_HYDROGEN = "H"; +type RESOURCE_CATALYST = "X"; + +type RESOURCE_HYDROXIDE = "OH"; +type RESOURCE_ZYNTHIUM_KEANITE = "ZK"; +type RESOURCE_UTRIUM_LEMERGITE = "UL"; +type RESOURCE_UTRIUM_HYDRIDE = "UH"; +type RESOURCE_UTRIUM_OXIDE = "UO"; +type RESOURCE_KEANIUM_HYDRIDE = "KH"; +type RESOURCE_KEANIUM_OXIDE = "KO"; +type RESOURCE_LEMERGIUM_HYDRIDE = "LH"; +type RESOURCE_LEMERGIUM_OXIDE = "LO"; +type RESOURCE_ZYNTHIUM_HYDRIDE = "ZH"; +type RESOURCE_ZYNTHIUM_OXIDE = "ZO"; +type RESOURCE_GHODIUM_HYDRIDE = "GH"; +type RESOURCE_GHODIUM_OXIDE = "GO"; + +type RESOURCE_UTRIUM_ACID = "UH2O"; +type RESOURCE_UTRIUM_ALKALIDE = "UHO2"; +type RESOURCE_KEANIUM_ACID = "KH2O"; +type RESOURCE_KEANIUM_ALKALIDE = "KHO2"; +type RESOURCE_LEMERGIUM_ACID = "LH2O"; +type RESOURCE_LEMERGIUM_ALKALIDE = "LHO2"; +type RESOURCE_ZYNTHIUM_ACID = "ZH2O"; +type RESOURCE_ZYNTHIUM_ALKALIDE = "ZHO2"; +type RESOURCE_GHODIUM_ACID = "GH2O"; +type RESOURCE_GHODIUM_ALKALIDE = "GHO2"; + +type RESOURCE_CATALYZED_UTRIUM_ACID = "XUH2O"; +type RESOURCE_CATALYZED_UTRIUM_ALKALIDE = "XUHO2"; +type RESOURCE_CATALYZED_KEANIUM_ACID = "XKH2O"; +type RESOURCE_CATALYZED_KEANIUM_ALKALIDE = "XKHO2"; +type RESOURCE_CATALYZED_LEMERGIUM_ACID = "XLH2O"; +type RESOURCE_CATALYZED_LEMERGIUM_ALKALIDE = "XLHO2"; +type RESOURCE_CATALYZED_ZYNTHIUM_ACID = "XZH2O"; +type RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE = "ZXHO2"; +type RESOURCE_CATALYZED_GHODIUM_ACID = "XGH2O"; +type RESOURCE_CATALYZED_GHODIUM_ALKALIDE = "XGHO2"; + diff --git a/src/map.ts b/src/map.ts index e67c933..c89df93 100644 --- a/src/map.ts +++ b/src/map.ts @@ -27,7 +27,7 @@ interface GameMap { * Or one of the following Result codes: * ERR_NO_PATH, ERR_INVALID_ARGS */ - findExit(fromRoom: string|Room, toRoom: string|Room, opts?: RouteOptions): number; + findExit(fromRoom: string|Room, toRoom: string|Room, opts?: RouteOptions): ScreepsReturnCode; /** * Find route from the given room to another room. * @param fromRoom Start room name or room object. @@ -36,9 +36,9 @@ interface GameMap { * @returns the route array or ERR_NO_PATH code */ findRoute(fromRoom: string | Room, toRoom: string | Room, opts?: RouteOptions): { - exit: number; + exit: ExitConstant; room: string; - }[] | number; + }[] | ERR_NO_PATH; /** * Get the linear distance (in rooms) between two rooms. You can use this function to estimate the energy cost of * sending resources through terminals, or using observers and nukes. @@ -54,13 +54,13 @@ interface GameMap { * @param y Y position in the room. * @param roomName The room name. */ - getTerrainAt(x: number, y: number, roomName: string): string; + getTerrainAt(x: number, y: number, roomName: string): Terrain; /** * 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. * @param pos The position object. */ - getTerrainAt(pos: RoomPosition): string; - + getTerrainAt(pos: RoomPosition): Terrain; + /** * Check if the room is available to move into. * @param roomName The room name. diff --git a/src/market.ts b/src/market.ts index 8cfcd38..8af0d9d 100644 --- a/src/market.ts +++ b/src/market.ts @@ -32,34 +32,34 @@ interface Market { * @param orderId The order ID as provided in Game.market.orders * @returns Result Code: OK, ERR_INVALID_ARGS */ - cancelOrder(orderId: string): number; + cancelOrder(orderId: string): ScreepsReturnCode; /** * Change the price of an existing order. If newPrice is greater than old price, you will be charged (newPrice-oldPrice)*remainingAmount*0.05 credits. * @param orderId The order ID as provided in Game.market.orders * @param newPrice The new order price. * @returns Result Code: OK, ERR_NOT_OWNER, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_ARGS */ - changeOrderPrice(orderId: string, newPrice: number): number; + changeOrderPrice(orderId: string, newPrice: number): ScreepsReturnCode; /** * Create a market order in your terminal. You will be charged price*amount*0.05 credits when the order is placed. * The maximum orders count is 20 per player. You can create an order at any time with any amount, * it will be automatically activated and deactivated depending on the resource/credits availability. */ - createOrder(type: string, resourceType: string, price: number, totalAmount: number, roomName?: string): number; + createOrder(type: string, resourceType: ResourceConstant, price: number, totalAmount: number, roomName?: string): ScreepsReturnCode; /** * Execute a trade deal from your Terminal to another player's Terminal using the specified buy/sell order. * Your Terminal will be charged energy units of transfer cost regardless of the order resource type. * You can use Game.market.calcTransactionCost method to estimate it. * When multiple players try to execute the same deal, the one with the shortest distance takes precedence. */ - deal(orderId: string, amount: number, targetRoomName?: string): number; + deal(orderId: string, amount: number, targetRoomName?: string): ScreepsReturnCode; /** * Add more capacity to an existing order. It will affect remainingAmount and totalAmount properties. You will be charged price*addAmount*0.05 credits. * @param orderId The order ID as provided in Game.market.orders * @param addAmount How much capacity to add. Cannot be a negative value. * @returns Result Code: OK, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_ARGS */ - extendOrder(orderId: string, addAmount: number): number; + extendOrder(orderId: string, addAmount: number): ScreepsReturnCode; /** * Get other players' orders currently active on the market. * @param filter (optional) An object or function that will filter the resulting list using the lodash.filter method. @@ -81,7 +81,7 @@ interface Transaction { time: number; sender?: { username: string }; recipient?: { username: string }; - resourceType: string; + resourceType: ResourceConstant; amount: number; from: string; to: string; @@ -93,7 +93,7 @@ interface Order { created: number; active?: boolean; type: string; - resourceType: string; + resourceType: ResourceConstant; roomName?: string; amount: number; remainingAmount: number; @@ -105,7 +105,7 @@ interface OrderFilter { id?: string; created?: number; type?: string; - resourceType?: string; + resourceType?: ResourceConstant; roomName?: string; amount?: number; remainingAmount?: number; diff --git a/src/memory.ts b/src/memory.ts index 234e2ac..73823f4 100644 --- a/src/memory.ts +++ b/src/memory.ts @@ -1,7 +1,12 @@ interface Memory { [name: string]: any; - creeps: {[name: string]: any}; - flags: {[name: string]: any}; - rooms: {[name: string]: any}; - spawns: {[name: string]: any}; + creeps: {[name: string]: CreepMemory}; + flags: {[name: string]: FlagMemory}; + rooms: {[name: string]: RoomMemory}; + spawns: {[name: string]: SpawnMemory}; } + +interface CreepMemory {} +interface FlagMemory {} +interface RoomMemory {} +interface SpawnMemory {} diff --git a/src/mineral.ts b/src/mineral.ts index 4dc6cf1..fd52e5a 100644 --- a/src/mineral.ts +++ b/src/mineral.ts @@ -1,7 +1,7 @@ /** * A mineral deposit object. Can be harvested by creeps with a WORK body part using the extractor structure. */ -interface Mineral extends RoomObject { +interface Mineral extends RoomObject { /** * The prototype is stored in the Mineral.prototype global object. You can use it to extend game objects behaviour globally. */ @@ -17,7 +17,7 @@ interface Mineral extends RoomObject { /** * The resource type, one of the RESOURCE_* constants. */ - mineralType: string; + mineralType: T; /** * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. */ diff --git a/src/nuke.ts b/src/nuke.ts index f4f3d66..9751f8d 100644 --- a/src/nuke.ts +++ b/src/nuke.ts @@ -3,7 +3,7 @@ */ interface Nuke extends RoomObject { readonly prototype: Nuke; - + /** * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. */ diff --git a/src/path-finder.ts b/src/path-finder.ts index a4306b5..be729f5 100644 --- a/src/path-finder.ts +++ b/src/path-finder.ts @@ -15,7 +15,7 @@ interface PathFinder { * @param goal goal A RoomPosition or an object containing a RoomPosition and range * @param opts An object containing additional pathfinding flags. */ - search(origin: RoomPosition, goal: RoomPosition|{pos: RoomPosition, range: number}, opts?: PathFinderOpts): PathFinderPath; + search(origin: RoomPosition, goal: RoomPosition | { pos: RoomPosition, range: number }, opts?: PathFinderOpts): PathFinderPath; /** * Find an optimal path between origin and goal. * @@ -23,7 +23,7 @@ interface PathFinder { * @param goal an array of goals, the cheapest path found out of all the goals will be returned. * @param opts An object containing additional pathfinding flags. */ - search(origin: RoomPosition, goal: RoomPosition[]|{pos: RoomPosition, range: number}[], opts?: PathFinderOpts): PathFinderPath; + search(origin: RoomPosition, goal: RoomPosition[] | { pos: RoomPosition, range: number }[], opts?: PathFinderOpts): PathFinderPath; /** * Specify whether to use this new experimental pathfinder in game objects methods. * This method should be invoked every tick. It affects the following methods behavior: diff --git a/src/resource.ts b/src/resource.ts index 412dde7..f6822ee 100644 --- a/src/resource.ts +++ b/src/resource.ts @@ -2,9 +2,9 @@ * 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. */ -interface Resource extends RoomObject { +interface Resource extends RoomObject { readonly prototype: Resource; - + /** * The amount of resource units containing. */ @@ -16,7 +16,7 @@ interface Resource extends RoomObject { /** * One of the `RESOURCE_*` constants. */ - resourceType: string; + resourceType: T; } interface ResourceConstructor { diff --git a/src/room-position.ts b/src/room-position.ts index eb581ec..28a6f8d 100644 --- a/src/room-position.ts +++ b/src/room-position.ts @@ -20,52 +20,52 @@ interface RoomPosition { * Create new ConstructionSite at the specified location. * @param structureType One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK */ - createConstructionSite(structureType: string): number; + createConstructionSite(structureType: StructureConstant): ScreepsReturnCode; /** * Create new Flag at the specified location. * @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. * @param color The color of a new flag. Should be one of the COLOR_* constants * @param secondaryColor The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color. */ - createFlag(name?: string, color?: number, secondaryColor?: number): number; + createFlag(name?: string, color?: ColorConstant, secondaryColor?: ColorConstant): ScreepsReturnCode; /** * Find an object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm. * @param type See Room.find * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm */ - findClosestByPath(type: number, opts?: FindPathOpts & { filter?: any | string, algorithm?: string }): T; + findClosestByPath(type: FindConstant, opts?: FindPathOpts & { filter?: any | string, algorithm?: string }): T | null; /** * Find an object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm. * @param objects An array of room's objects or RoomPosition objects that the search should be executed against. * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm */ - findClosestByPath(objects: T[] | RoomPosition[], opts?: FindPathOpts & { filter?: any | string, algorithm?: string }): T; + findClosestByPath(objects: T[], opts?: FindPathOpts & { filter?: any | string, algorithm?: string }): T; /** * Find an object with the shortest linear distance from the given position. * @param type See Room.find. * @param opts */ - findClosestByRange(type: number, opts?: { filter: any | string }): T; + findClosestByRange(type: FindConstant, opts?: { filter: any | string }): T | null; /** * Find an object with the shortest linear distance from the given position. * @param objects An array of room's objects or RoomPosition objects that the search should be executed against. * @param opts An object containing one of the following options: filter */ - findClosestByRange(objects: T[] | RoomPosition[], opts?: { filter: any | string }): T; + findClosestByRange(objects: T[], opts?: { filter: any | string }): T; /** * Find all objects in the specified linear range. * @param type See Room.find. * @param range The range distance. * @param opts See Room.find. */ - findInRange(type: number, range: number, opts?: { filter?: any | string }): T[]; + findInRange(type: FindConstant, range: number, opts?: { filter?: any | string }): T[]; /** * Find all objects in the specified linear range. * @param objects An array of room's objects or RoomPosition objects that the search should be executed against. * @param range The range distance. * @param opts See Room.find. */ - findInRange(objects: T[] | RoomPosition[], range: number, opts?: { filter?: any | string }): T[]; + findInRange(objects: T[], range: number, opts?: { filter?: any | string }): T[]; /** * 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. * @param x X position in the room. @@ -78,18 +78,18 @@ interface RoomPosition { * @param target Can be a RoomPosition object or any object containing RoomPosition. * @param opts An object containing pathfinding options flags (see Room.findPath for more details). */ - findPathTo(target: RoomPosition | { pos: RoomPosition }, opts?: FindPathOpts): PathStep[]; + findPathTo(target: RoomPosition | _HasRoomPosition, opts?: FindPathOpts): PathStep[]; /** * Get linear direction to the specified position. * @param x X position in the room. * @param y Y position in the room. */ - getDirectionTo(x: number, y: number): number; + getDirectionTo(x: number, y: number): DirectionConstant; /** * Get linear direction to the specified position. * @param target Can be a RoomPosition object or any object containing RoomPosition. */ - getDirectionTo(target: RoomPosition | { pos: RoomPosition }): number; + getDirectionTo(target: RoomPosition | _HasRoomPosition): number; /** * Get linear range to the specified position. * @param x X position in the room. @@ -137,7 +137,7 @@ interface RoomPosition { * Get an object with the given type at the specified room position. * @param type One of the following string constants: constructionSite, creep, exit, flag, resource, source, structure, terrain */ - lookFor(type: string): T[]; + lookFor(type: LookConstant): T[]; } interface RoomPositionConstructor extends _Constructor { diff --git a/src/room-visual.ts b/src/room-visual.ts index c359224..38cc8ac 100644 --- a/src/room-visual.ts +++ b/src/room-visual.ts @@ -1,12 +1,14 @@ declare class RoomVisual { - /** The name of the room. */ - roomName: string; + /** + * You can create new RoomVisual object using its constructor. + * @param roomName The room name. If undefined, visuals will be posted to all rooms simultaneously. + */ + constructor(roomName?: string); /** - * You can directly create new RoomVisual object in any room, even if it's invisible to your script. - * @param roomName The room name. + * The name of the room. */ - constructor(roomName: string); + roomName: string; /** * Draw a line. @@ -19,6 +21,15 @@ declare class RoomVisual { */ line(x1: number, y1: number, x2: number, y2: number, style?: LineStyle): RoomVisual; + /** + * Draw a line. + * @param pos1 The start position object. + * @param pos2 The finish position object. + * @param style The (optional) style. + * @returns The RoomVisual object, for chaining. + */ + line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyle): RoomVisual; + /** * Draw a circle. * @param x The X coordinate of the center. @@ -28,6 +39,14 @@ declare class RoomVisual { */ circle(x: number, y: number, style?: CircleStyle): RoomVisual; + /** + * Draw a circle. + * @param pos The position object of the center. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + circle(pos: RoomPosition, style?: CircleStyle): RoomVisual; + /** * Draw a rectangle. * @param x The X coordinate of the top-left corner. @@ -39,13 +58,22 @@ declare class RoomVisual { */ rect(x: number, y: number, w: number, h: number, style?: PolyStyle): RoomVisual; + /** + * Draw a line. + * @param topLeftPos The position object of the top-left corner. + * @param width The width of the rectangle. + * @param height The height of the rectangle. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + rect(topLeftPos: RoomPosition, width: number, height: number, style?: PolyStyle): RoomVisual; /** * Draw a polygon. - * @param points An array of point coordinate arrays, i.e. [[0,0], [5,5], [5,10]]. + * @param points An array of points. Every array item should be either an array with 2 numbers (i.e. [10,15]), or a RoomPosition object. * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - poly(points: [number, number][], style?: PolyStyle): RoomVisual; + poly(points: Array<[number, number] | RoomPosition>, style?: PolyStyle): RoomVisual; /** * Draw a text label. @@ -57,6 +85,15 @@ declare class RoomVisual { */ text(text: string, x: number, y: number, style?: TextStyle): RoomVisual; + /** + * Draw a text label. You can use any valid Unicode characters, including emoji. + * @param text The text message. + * @param pos The position object of the center. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + text(text: string, pos: RoomPosition, style?: TextStyle): RoomVisual; + /** * Remove all visuals from the room. * @returns The RoomVisual object, for chaining. @@ -72,27 +109,87 @@ declare class RoomVisual { } interface LineStyle { + /** + * Line width, default is 0.1. + */ width?: number; + /** + * Line color in any web format, default is #ffffff(white). + */ color?: string; + /** + * Opacity value, default is 0.5. + */ opacity?: number; + /** + * Either undefined (solid line), dashed, or dotted.Default is undefined. + */ lineStyle?: "dashed" | "dotted"; } interface PolyStyle { + /** + * Fill color in any web format, default is #ffffff(white). + */ fill?: string; + /** + * Opacity value, default is 0.5. + */ opacity?: number; + /** + * Stroke color in any web format, default is undefined (no stroke). + */ stroke?: string | undefined; + /** + * Stroke line width, default is 0.1. + */ strokeWidth?: number; + /** + * Either undefined (solid line), dashed, or dotted.Default is undefined. + */ lineStyle?: "dashed" | "dotted"; } interface CircleStyle extends PolyStyle { + /** + * Circle radius, default is 0.15. + */ radius?: number; } interface TextStyle { + /** + * Font color in any web format, default is #ffffff(white). + */ color?: string; - size?: number; + /** + * Either a number or a string in one of the following forms: + * 0.7 - relative size in game coordinates + * 20px - absolute size in pixels + * 0.7 serif + * bold italic 1.5 Times New Roman + */ + font?: number | string; + /** + * Stroke color in any web format, default is undefined (no stroke). + */ + stroke?: string; + /** + * Stroke width, default is 0.15. + */ + strokeWidth?: number; + /** + * Background color in any web format, default is undefined (no background).When background is enabled, text vertical align is set to middle (default is baseline). + */ + backgroundColor?: string; + + /** + * Background rectangle padding, default is 0.3. + */ + backgroundPadding?: number; align?: "center" | "left" | "right"; + /** + * Opacity value, default is 1.0. + */ opacity?: number; } diff --git a/src/room.ts b/src/room.ts index 287afe1..4ad9b94 100644 --- a/src/room.ts +++ b/src/room.ts @@ -3,11 +3,11 @@ */ interface Room { readonly prototype: Room; - + /** * The Controller structure of this room, if present, otherwise undefined. */ - controller: Controller | undefined; + controller?: Controller; /** * Total amount of energy available in all spawns and extensions in the room. */ @@ -19,7 +19,7 @@ interface Room { /** * A shorthand to Memory.rooms[room.name]. You can use it for quick access the room’s specific memory data object. */ - memory: any; + memory: RoomMemory; /** * One of the following constants: * MODE_SIMULATION, MODE_SURVIVAL, MODE_WORLD, MODE_ARENA @@ -32,13 +32,13 @@ interface Room { /** * The Storage structure of this room, if present, otherwise undefined. */ - storage: StructureStorage | undefined; + storage?: StructureStorage; /** * The Terminal structure of this room, if present, otherwise undefined. */ - terminal: Terminal | undefined; + terminal?: Terminal; /** - * The RoomVisual object for this room. + * A RoomVisual object for this room. You can use this object to draw simple shapes (lines, circles, text labels) in the room. */ visual: RoomVisual; /** @@ -48,14 +48,14 @@ interface Room { * @param structureType One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK * @returns Result Code: OK, ERR_INVALID_TARGET, ERR_INVALID_ARGS, ERR_RCL_NOT_ENOUGH */ - createConstructionSite(x: number, y: number, structureType: string): number; + createConstructionSite(x: number, y: number, structureType: StructureConstant): ScreepsReturnCode; /** * Create new ConstructionSite at the specified location. * @param pos Can be a RoomPosition object or any object containing RoomPosition. * @param structureType One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK * @returns Result Code: OK, ERR_INVALID_TARGET, ERR_INVALID_ARGS, ERR_RCL_NOT_ENOUGH */ - createConstructionSite(pos: RoomPosition | { pos: RoomPosition }, structureType: string): number; + createConstructionSite(pos: RoomPosition | _HasRoomPosition, structureType: StructureConstant): ScreepsReturnCode; /** * Create new Flag at the specified location. * @param x The X position. @@ -64,7 +64,7 @@ interface Room { * @param color The color of a new flag. Should be one of the COLOR_* constants. The default value is COLOR_WHITE. * @param secondaryColor The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color. */ - createFlag(x: number, y: number, name?: string, color?: number, secondaryColor?: number): number; + createFlag(x: number, y: number, name?: string, color?: ColorConstant, secondaryColor?: ColorConstant): ScreepsReturnCode; /** * Create new Flag at the specified location. * @param pos Can be a RoomPosition object or any object containing RoomPosition. @@ -72,21 +72,21 @@ interface Room { * @param color The color of a new flag. Should be one of the COLOR_* constants. The default value is COLOR_WHITE. * @param secondaryColor The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color. */ - createFlag(pos: RoomPosition | { pos: RoomPosition }, name?: string, color?: number, secondaryColor?: number): number; + createFlag(pos: RoomPosition | { pos: RoomPosition }, name?: string, color?: ColorConstant, secondaryColor?: ColorConstant): ScreepsReturnCode; /** * Find all objects of the specified type in the room. * @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 * @param opts An object with additional options * @returns An array with the objects found. */ - find(type: number, opts?: { filter: Object | Function | string }): T[]; + find(type: FindConstant, opts?: { filter: Object | Function | string }): T[]; /** * Find the exit direction en route to another room. * @param room Another room name or room object. * @returns The room direction constant, one of the following: FIND_EXIT_TOP, FIND_EXIT_RIGHT, FIND_EXIT_BOTTOM, FIND_EXIT_LEFT * Or one of the following error codes: ERR_NO_PATH, ERR_INVALID_ARGS */ - findExitTo(room: string | Room): number; + findExitTo(room: string | Room): ScreepsReturnCode | FIND_EXIT_TOP | FIND_EXIT_RIGHT | FIND_EXIT_BOTTOM | FIND_EXIT_LEFT; /** * Find an optimal path inside the room between fromPos and toPos using A* search algorithm. * @param fromPos The start position. @@ -132,14 +132,14 @@ interface Room { * @param y The Y position. * @returns An array of objects of the given type at the specified position if found. */ - lookForAt(type: string, x: number, y: number): T[]; + lookForAt(type: LookConstant, x: number, y: number): T[]; /** * Get an object with the given type at the specified room position. * @param type One of the following string constants: constructionSite, creep, energy, exit, flag, source, structure, terrain * @param target Can be a RoomPosition object or any object containing RoomPosition. * @returns An array of objects of the given type at the specified position if found. */ - lookForAt(type: string, target: RoomPosition | { pos: RoomPosition }): T[]; + lookForAt(type: LookConstant, target: RoomPosition | { pos: RoomPosition }): T[]; /** * 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. * @param type One of the following string constants: constructionSite, creep, energy, exit, flag, source, structure, terrain @@ -149,7 +149,7 @@ interface Room { * @param right The right X boundary of the area. * @returns An object with all the objects of the given type in the specified area */ - lookForAtArea(type: string, top: number, left: number, bottom: number, right: number, asArray?: boolean): LookAtResultMatrix | LookAtResultWithPos[]; + lookForAtArea(type: T, top: number, left: number, bottom: number, right: number, asArray?: boolean): LookAtResultMatrix | LookAtResultWithPos[]; /** * Serialize a path array into a short string representation, which is suitable to store in memory. diff --git a/src/spawn.ts b/src/spawn.ts index 909f079..8fbb909 100644 --- a/src/spawn.ts +++ b/src/spawn.ts @@ -2,7 +2,7 @@ /** * Spawns are your colony centers. You can transfer energy into it and create new creeps using createCreep() method. */ -interface StructureSpawn extends OwnedStructure { +interface StructureSpawn extends OwnedStructure { readonly prototype: StructureSpawn; /** * The amount of energy containing in the spawn. @@ -15,7 +15,7 @@ interface StructureSpawn extends OwnedStructure { /** * A shorthand to Memory.spawns[spawn.name]. You can use it for quick access the spawn’s specific memory data object. */ - memory: any; + memory: SpawnMemory; /** * 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. */ @@ -33,7 +33,7 @@ interface StructureSpawn extends OwnedStructure { * @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 * @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. */ - canCreateCreep(body: string[], name?: string): number; + canCreateCreep(body: BodyPartConstant[], name?: string): ScreepsReturnCode; /** * Start the creep spawning process. * The name of a new creep or one of these error codes @@ -47,11 +47,11 @@ interface StructureSpawn extends OwnedStructure { * @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. * @param memory The memory of a new creep. If provided, it will be immediately stored into Memory.creeps[name]. */ - createCreep(body: string[], name?: string, memory?: any): number | string; + createCreep(body: BodyPartConstant[], name?: string, memory?: CreepMemory): ScreepsReturnCode | string; /** * Destroy this spawn immediately. */ - destroy(): number; + destroy(): ScreepsReturnCode; /** * 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. */ @@ -60,24 +60,17 @@ interface StructureSpawn extends OwnedStructure { * Toggle auto notification when the spawn is under attack. The notification will be sent to your account email. Turned on by default. * @param enabled Whether to enable notification or disable. */ - notifyWhenAttacked(enabled: boolean): number; + notifyWhenAttacked(enabled: boolean): ScreepsReturnCode; /** * 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). * @param target The target creep object. */ - renewCreep(target: Creep): number; + renewCreep(target: Creep): ScreepsReturnCode; /** * 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. * @param target The target creep object. */ - recycleCreep(target: Creep): number; - /** - * @deprecated - * Transfer the energy from the spawn to a creep. - * @param target The creep object which energy should be transferred to. - * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. - */ - transferEnergy(target: Creep, amount?: number): number; + recycleCreep(target: Creep): ScreepsReturnCode; } diff --git a/src/structure.ts b/src/structure.ts index 0d06f6f..929c3d3 100644 --- a/src/structure.ts +++ b/src/structure.ts @@ -2,7 +2,7 @@ * Parent object for structure classes */ -interface Structure extends RoomObject { +interface Structure extends RoomObject { readonly prototype: Structure; /** @@ -25,11 +25,11 @@ interface Structure extends RoomObject { /** * One of the STRUCTURE_* constants. */ - structureType: string; + structureType: T; /** * Destroy this structure immediately. */ - destroy(): number; + destroy(): ScreepsReturnCode; /** * 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. */ @@ -38,7 +38,7 @@ interface Structure extends RoomObject { * Toggle auto notification when the structure is under attack. The notification will be sent to your account email. Turned on by default. * @param enabled Whether to enable notification or disable. */ - notifyWhenAttacked(enabled: boolean): number; + notifyWhenAttacked(enabled: boolean): ScreepsReturnCode; } interface StructureConstructor extends _Constructor, _ConstructorById { @@ -50,7 +50,7 @@ declare const Structure: StructureConstructor; * The base prototype for a structure that has an owner. Such structures can be * found using `FIND_MY_STRUCTURES` and `FIND_HOSTILE_STRUCTURES` constants. */ -interface OwnedStructure extends Structure { +interface OwnedStructure extends Structure { readonly prototype: OwnedStructure; /** @@ -78,7 +78,7 @@ declare const OwnedStructure: OwnedStructureConstructor; * cannot be damaged or destroyed. It can be addressed by `Room.controller` * property. */ -interface StructureController extends OwnedStructure { +interface StructureController extends OwnedStructure { readonly prototype: StructureController; /** @@ -100,7 +100,7 @@ interface StructureController extends OwnedStructure { /** * How many ticks of safe mode are remaining, or undefined. */ - safeMode: number | undefined; + safeMode?: number; /** * Safe mode activations available to use. */ @@ -108,7 +108,7 @@ interface StructureController extends OwnedStructure { /** * During this period in ticks new safe mode activations will be blocked, undefined if cooldown is inactive. */ - safeModeCooldown: number | undefined; + safeModeCooldown?: number; /** * An object with the controller sign info if present */ @@ -125,11 +125,11 @@ interface StructureController extends OwnedStructure { * Activate safe mode if available. * @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_NOT_ENOUGH_RESOURCES, ERR_TIRED */ - activateSafeMode(): number; + activateSafeMode(): ScreepsReturnCode; /** * Make your claimed controller neutral again. */ - unclaim(): number; + unclaim(): ScreepsReturnCode; } interface StructureControllerConstructor extends _Constructor, _ConstructorById { @@ -142,7 +142,7 @@ declare const StructureController: StructureControllerConstructor; * be placed anywhere in the room, any spawns will be able to use them regardless * of distance. */ -interface StructureExtension extends OwnedStructure { +interface StructureExtension extends OwnedStructure { readonly prototype: StructureExtension; /** @@ -153,13 +153,6 @@ interface StructureExtension extends OwnedStructure { * The total amount of energy the extension can contain. */ energyCapacity: number; - /** - * @deprecated - * Transfer the energy from the extension to a creep. - * @param target The creep object which energy should be transferred to. - * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. - */ - transferEnergy(target: Creep, amount?: number): number; } interface StructureExtensionConstructor extends _Constructor, _ConstructorById { @@ -170,7 +163,7 @@ declare const StructureExtension: StructureExtensionConstructor; /** * Remotely transfers energy to another Link in the same room. */ -interface StructureLink extends OwnedStructure { +interface StructureLink extends OwnedStructure { readonly prototype: StructureLink; /** @@ -190,7 +183,7 @@ interface StructureLink extends OwnedStructure { * @param target The target object. * @param amount The amount of energy to be transferred. If omitted, all the available energy is used. */ - transferEnergy(target: Creep | StructureLink, amount?: number): number; + transferEnergy(target: Creep | StructureLink, amount?: number): ScreepsReturnCode; } interface StructureLinkConstructor extends _Constructor, _ConstructorById { @@ -202,13 +195,13 @@ declare const StructureLink: StructureLinkConstructor; * Non-player structure. Spawns NPC Source Keepers that guards energy sources * and minerals in some rooms. This structure cannot be destroyed. */ -interface StructureKeeperLair extends OwnedStructure { +interface StructureKeeperLair extends OwnedStructure { readonly prototype: StructureKeeperLair; /** * Time to spawning of the next Source Keeper. */ - ticksToSpawn: number | undefined; + ticksToSpawn?: number; } interface StructureKeeperLairConstructor extends _Constructor, _ConstructorById { @@ -219,14 +212,14 @@ declare const StructureKeeperLair: StructureKeeperLairConstructor; /** * Provides visibility into a distant room from your script. */ -interface StructureObserver extends OwnedStructure { +interface StructureObserver extends OwnedStructure { readonly prototype: StructureObserver; /** * 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. * @param roomName */ - observeRoom(roomName: string): number; + observeRoom(roomName: string): ScreepsReturnCode; } interface StructureObserverConstructor extends _Constructor, _ConstructorById { @@ -237,7 +230,7 @@ declare const StructureObserver: StructureObserverConstructor; /** * */ -interface StructurePowerBank extends OwnedStructure { +interface StructurePowerBank extends OwnedStructure { readonly prototype: StructurePowerBank; /** @@ -259,7 +252,7 @@ declare const StructurePowerBank: StructurePowerBankConstructor; * Non-player structure. Contains power resource which can be obtained by * destroying the structure. Hits the attacker creep back on each attack. */ -interface StructurePowerSpawn extends OwnedStructure { +interface StructurePowerSpawn extends OwnedStructure { readonly prototype: StructurePowerSpawn; /** * The amount of energy containing in this structure. @@ -282,19 +275,11 @@ interface StructurePowerSpawn extends OwnedStructure { * Create a power creep. Currently in development * @param name The name of the power creep. */ - createPowerCreep(name: string): number; + createPowerCreep(name: string): ScreepsReturnCode; /** * 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. */ - processPower(): number; - /** - * @deprecated - * Transfer the energy from this structure to a creep. - * @param target The creep object which energy should be transferred to. - * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. - */ - transferEnergy(target: Creep, amount?: number): number; - + processPower(): ScreepsReturnCode; } interface StructurePowerSpawnConstructor extends _Constructor, _ConstructorById { @@ -306,7 +291,7 @@ declare const StructurePowerSpawn: StructurePowerSpawnConstructor; * Blocks movement of hostile creeps, and defends your creeps and structures on * the same tile. Can be used as a controllable gate. */ -interface StructureRampart extends OwnedStructure { +interface StructureRampart extends OwnedStructure { readonly prototype: StructureRampart; /** @@ -335,7 +320,7 @@ declare const StructureRampart: StructureRampartConstructor; * Decreases movement cost to 1. Using roads allows creating creeps with less * `MOVE` body parts. */ -interface StructureRoad extends Structure { +interface StructureRoad extends Structure { readonly prototype: StructureRoad; /** @@ -353,7 +338,7 @@ declare const StructureRoad: StructureRoadConstructor; * A structure that can store huge amount of resource units. Only one structure * per room is allowed that can be addressed by `Room.storage` property. */ -interface StructureStorage extends OwnedStructure { +interface StructureStorage extends OwnedStructure { readonly prototype: StructureStorage; /** @@ -364,22 +349,6 @@ interface StructureStorage extends OwnedStructure { * The total amount of resources the storage can contain. */ storeCapacity: number; - - /** - * Transfer resource from this storage to a creep. The target has to be at adjacent square. - * @param target The target object. - * @param resourceType One of the RESOURCE_* constants. - * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. - */ - transfer(target: Creep, resourceType: string, amount?: number): number; - /** - * @deprecated - * An alias for storage.transfer(target, RESOURCE_ENERGY, amount). - * @param target The target object. - * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. - * @deprecated - */ - transferEnergy(target: Creep, amount?: number): number; } interface StructureStorageConstructor extends _Constructor, _ConstructorById { @@ -392,7 +361,7 @@ declare const StructureStorage: StructureStorageConstructor; * any object in the room. However, its effectiveness highly depends on the * distance. Each action consumes energy. */ -interface StructureTower extends OwnedStructure { +interface StructureTower extends OwnedStructure { readonly prototype: StructureTower; /** @@ -408,23 +377,17 @@ interface StructureTower extends OwnedStructure { * 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. * @param target The target creep. */ - attack(target: Creep): number; + attack(target: Creep): ScreepsReturnCode; /** * 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. * @param target The target creep. */ - heal(target: Creep): number; + heal(target: Creep): ScreepsReturnCode; /** * 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. * @param target The target structure. */ - repair(target: Spawn | Structure): number; - /** - * @deprecated - * @param target The creep object which energy should be transferred to. - * @param amount The amount of energy to be transferred. If omitted, all the remaining amount of energy will be used. - */ - transferEnergy(target: Creep, amount?: number): number; + repair(target: Structure): ScreepsReturnCode; } interface StructureTowerConstructor extends _Constructor, _ConstructorById { @@ -435,7 +398,7 @@ declare const StructureTower: StructureTowerConstructor; /** * Blocks movement of all creeps. */ -interface StructureWall extends Structure { +interface StructureWall extends Structure { readonly prototype: StructureWall; /** * The amount of game ticks when the wall will disappear (only for automatically placed border walls at the start of the game). @@ -451,7 +414,7 @@ declare const StructureWall: StructureWallConstructor; /** * Allows to harvest mineral deposits. */ -interface StructureExtractor extends OwnedStructure { +interface StructureExtractor extends OwnedStructure { readonly prototype: StructureExtractor; /** * The amount of game ticks until the next harvest action is possible. @@ -467,7 +430,7 @@ declare const StructureExtractor: StructureExtractorConstructor; /** * Produces mineral compounds from base minerals and boosts creeps. */ -interface StructureLab extends OwnedStructure { +interface StructureLab extends OwnedStructure { readonly prototype: StructureLab; /** * The amount of game ticks the lab has to wait until the next reaction is possible. @@ -488,7 +451,7 @@ interface StructureLab extends OwnedStructure { /** * The type of minerals containing in the lab. Labs can contain only one mineral type at the same time. */ - mineralType: string; + mineralType: MineralConstant; /** * The total amount of minerals the lab can contain. */ @@ -498,20 +461,13 @@ interface StructureLab extends OwnedStructure { * @param creep The target creep. * @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. */ - boostCreep(creep: Creep, bodyPartsCount?: number): number; + boostCreep(creep: Creep, bodyPartsCount?: number): ScreepsReturnCode; /** * 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 * @param lab1 The first source lab. * @param lab2 The second source lab. */ - runReaction(lab1: StructureLab, lab2: StructureLab): number; - /** - * Transfer resource from this structure to a creep. The target has to be at adjacent square. - * @param target The target object. - * @param resourceType One of the RESOURCE_* constants. - * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. - */ - transfer(target: Creep, resourceType: string, amount?: number): number; + runReaction(lab1: StructureLab, lab2: StructureLab): ScreepsReturnCode; } interface StructureLabConstructor extends _Constructor, _ConstructorById { @@ -522,12 +478,12 @@ declare const StructureLab: StructureLabConstructor; /** * Sends any resources to a Terminal in another room. */ -interface StructureTerminal extends OwnedStructure { +interface StructureTerminal extends OwnedStructure { readonly prototype: StructureTerminal; /** * An object with the storage contents. Each object key is one of the RESOURCE_* constants, values are resources amounts. */ - store: any; + store: StoreDefinition; /** * The total amount of resources the storage can contain. */ @@ -539,14 +495,7 @@ interface StructureTerminal extends OwnedStructure { * @param destination The name of the target room. You don't have to gain visibility in this room. * @param description The description of the transaction. It is visible to the recipient. The maximum length is 100 characters. */ - send(resourceType: string, amount: number, destination: string, description?: string): number; - /** - * Transfer resource from this terminal to a creep. The target has to be at adjacent square. - * @param target The target object. - * @param resourceType One of the RESOURCE_* constants. - * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. - */ - transfer(target: Creep, resourceType: string, amount?: number): number; + send(resourceType: ResourceConstant, amount: number, destination: string, description?: string): ScreepsReturnCode; } interface StructureTerminalConstructor extends _Constructor, _ConstructorById { @@ -557,13 +506,13 @@ declare const StructureTerminal: StructureTerminalConstructor; /** * Contains up to 2,000 resource units. Can be constructed in neutral rooms. Decays for 5,000 hits per 100 ticks. */ -interface StructureContainer extends Structure { +interface StructureContainer extends Structure { readonly prototype: StructureContainer; /** * An object with the structure contents. Each object key is one of the RESOURCE_* constants, values are resources * amounts. Use _.sum(structure.store) to get the total amount of contents */ - store: any; + store: StoreDefinition; /** * The total amount of resources the structure can contain. */ @@ -572,13 +521,6 @@ interface StructureContainer extends Structure { * The amount of game ticks when this container will lose some hit points. */ ticksToDecay: number; - /** - * Transfer resource from this structure to a creep. The target has to be at adjacent square. - * @param target The target object. - * @param resourceType One of the RESOURCE_* constants. - * @param amount The amount of resources to be transferred. If omitted, all the available amount is used. - */ - transfer(target: Creep, resourceType: string, amount?: number): number; } interface StructureContainerConstructor extends _Constructor, _ConstructorById { @@ -593,7 +535,7 @@ declare const StructureContainer: StructureContainerConstructor; * until it is landed. Incoming nuke cannot be moved or cancelled. Nukes cannot * be launched from or to novice rooms. */ -interface StructureNuker extends OwnedStructure { +interface StructureNuker extends OwnedStructure { readonly prototype: StructureNuker; /** * The amount of energy contained in this structure. @@ -619,7 +561,7 @@ interface StructureNuker extends OwnedStructure { * Launch a nuke to the specified position. * @param pos The target room position. */ - launchNuke(pos: RoomPosition): number; + launchNuke(pos: RoomPosition): ScreepsReturnCode; } interface StructureNukerConstructor extends _Constructor, _ConstructorById { @@ -632,7 +574,7 @@ declare const StructureNuker: StructureNukerConstructor; * Instantly teleports your creeps to a distant room acting as a room exit tile. * Portals appear randomly in the central room of each sector. */ -interface StructurePortal extends Structure { +interface StructurePortal extends Structure { readonly prototype: StructurePortal; /** * The position object in the destination room.