From a36999fbb0c420d2244ee48cf04cbfcb8af0b20e Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Sun, 24 Jun 2018 16:36:49 +0700 Subject: [PATCH] [screeps] updated to v2.4.0 --- types/screeps/index.d.ts | 188 ++++++++++++++++++++++++++------- types/screeps/screeps-tests.ts | 111 +++++++++++++++++-- types/screeps/tsconfig.json | 2 +- 3 files changed, 249 insertions(+), 52 deletions(-) diff --git a/types/screeps/index.d.ts b/types/screeps/index.d.ts index d6153f8d64..c8aaa3ac8b 100644 --- a/types/screeps/index.d.ts +++ b/types/screeps/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Screeps 2.3 +// Type definitions for Screeps 2.4 // Project: https://github.com/screeps/screeps // Definitions by: Marko Sulamägi // Nhan Ho @@ -252,7 +252,7 @@ declare const RESOURCE_CATALYZED_GHODIUM_ACID: "XGH2O"; declare const RESOURCE_CATALYZED_GHODIUM_ALKALIDE: "XGHO2"; declare const RESOURCES_ALL: ResourceConstant[]; -declare const SUBSCRIPTION_TOKEN: string; +declare const SUBSCRIPTION_TOKEN: "token"; declare const CONTROLLER_LEVELS: {[level: number]: number}; declare const CONTROLLER_STRUCTURES: Record; @@ -795,7 +795,7 @@ interface Creep extends RoomObject { * @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: StructureController): CreepActionReturnCode | ERR_FULL | ERR_RCL_NOT_ENOUGH; + claimController(target: StructureController): CreepActionReturnCode | ERR_FULL | ERR_GCL_NOT_ENOUGH; /** * Dismantles any (even hostile) structure returning 50% of the energy spent on its repair. * @@ -1268,6 +1268,8 @@ type StoreDefinition = Partial> & { // energy: number; // } +type ExitsInformation = Partial>; + interface AllLookAtTypes { constructionSite: ConstructionSite; creep: Creep; @@ -1288,22 +1290,24 @@ type LookAtTypes = Partial; type LookAtResult = Pick & { type: K }; type LookAtResultWithPos = LookAtResult & { - x: number, - y: number, + x: number, + y: number, }; interface LookAtResultMatrix { - [coord: number]: LookAtResultMatrix | Array>; + [y: number]: { + [x: number]: Array>; + }; } interface LookForAtAreaResultMatrix { - [x: number]: { - [y: number]: Array>; - }; + [y: number]: { + [x: number]: Array>; + }; } type LookForAtAreaResult = {type: K} & { - [P in K]: T; + [P in K]: T; }; type LookForAtAreaResultWithPos = LookForAtAreaResult & {x: number, y: number}; @@ -1478,6 +1482,8 @@ interface _ConstructorById extends _Constructor { type Terrain = "plain" | "swamp" | "wall"; +type ExitKey = "1" | "3" | "5" | "7"; + // Return Codes type ScreepsReturnCode = @@ -1836,6 +1842,10 @@ type MineralConstant = RESOURCE_HYDROGEN | RESOURCE_CATALYST; +type MarketResourceConstant = + ResourceConstant | + SUBSCRIPTION_TOKEN; + type RESOURCE_ENERGY = "energy"; type RESOURCE_POWER = "power"; @@ -1884,6 +1894,8 @@ type RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE = "XZHO2"; type RESOURCE_CATALYZED_GHODIUM_ACID = "XGH2O"; type RESOURCE_CATALYZED_GHODIUM_ALKALIDE = "XGHO2"; +type SUBSCRIPTION_TOKEN = "token"; + type TOMBSTONE_DECAY_PER_PART = 5; /** * The options that can be accepted by `findRoute()` and friends. @@ -1901,7 +1913,7 @@ interface GameMap { * @param roomName The room name. * @returns The exits information or null if the room not found. */ - describeExits(roomName: string): {"1"?: string, "3"?: string, "5"?: string, "7"?: string}; + describeExits(roomName: string): ExitsInformation; /** * Find the exit direction from the given room en route to another room. * @param fromRoom Start room name or room object. @@ -1912,7 +1924,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): ScreepsReturnCode; + findExit(fromRoom: string|Room, toRoom: string|Room, opts?: RouteOptions): ExitConstant | ERR_NO_PATH | ERR_INVALID_ARGS; /** * Find route from the given room to another room. * @param fromRoom Start room name or room object. @@ -2013,7 +2025,7 @@ interface Market { * The maximum orders count is 50 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: ResourceConstant, price: number, totalAmount: number, roomName?: string): ScreepsReturnCode; + createOrder(type: string, resourceType: MarketResourceConstant, 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. * @@ -2051,7 +2063,7 @@ interface Transaction { time: number; sender?: { username: string }; recipient?: { username: string }; - resourceType: ResourceConstant; + resourceType: MarketResourceConstant; amount: number; from: string; to: string; @@ -2064,7 +2076,7 @@ interface Order { created: number; active?: boolean; type: string; - resourceType: ResourceConstant; + resourceType: MarketResourceConstant; roomName?: string; amount: number; remainingAmount: number; @@ -2082,7 +2094,7 @@ interface OrderFilter { id?: string; created?: number; type?: string; - resourceType?: ResourceConstant; + resourceType?: MarketResourceConstant; roomName?: string; amount?: number; remainingAmount?: number; @@ -2157,7 +2169,7 @@ interface Nuke extends RoomObject { timeToLand: number; } -interface NukeConstructor { +interface NukeConstructor extends _Constructor, _ConstructorById { new (id: string): Nuke; } @@ -2400,7 +2412,7 @@ interface Resource extends RoomOb resourceType: T; } -interface ResourceConstructor { +interface ResourceConstructor extends _Constructor, _ConstructorById { new (id: string): Resource; } @@ -2463,6 +2475,18 @@ interface RoomPosition { * * STRUCTURE_LINK */ createConstructionSite(structureType: BuildableStructureConstant): ScreepsReturnCode; + /** + * 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 + * @param name The name of the structure, for structures that support it (currently only spawns). + */ + createConstructionSite(structureType: STRUCTURE_SPAWN, name?: string): ScreepsReturnCode; /** * Create new Flag at the specified location. * @param name The name of a new flag. @@ -2478,31 +2502,31 @@ interface RoomPosition { * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm * @returns An instance of a RoomObject. */ - findClosestByPath(type: K, opts?: FindPathOpts & { filter?: FilterFunction, algorithm?: string }): FindTypes[K]; + findClosestByPath(type: K, opts?: FindPathOpts & { filter?: FilterFunction, algorithm?: string }): FindTypes[K] | null; findClosestByPath( type: FIND_STRUCTURES | FIND_MY_STRUCTURES | FIND_HOSTILE_STRUCTURES, opts?: FindPathOpts & { filter?: FilterFunction, algorithm?: string} - ): T; + ): T | null; /** * Find the object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm. * @param objects An array of RoomPositions or objects with a RoomPosition * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm * @returns One of the supplied objects */ - findClosestByPath(objects: T[], opts?: FindPathOpts & {filter?: any | string, algorithm?: string}): T; + findClosestByPath(objects: T[], opts?: FindPathOpts & {filter?: any | string, algorithm?: string}): T | null; /** * Find the object with the shortest linear distance from the given position. * @param type Any of the FIND_* constants. * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm */ - findClosestByRange(type: K, opts?: {filter: FilterFunction}): FindTypes[K]; - findClosestByRange(type: FIND_STRUCTURES | FIND_MY_STRUCTURES | FIND_HOSTILE_STRUCTURES, opts?: {filter: FilterFunction}): T; + findClosestByRange(type: K, opts?: {filter: FilterFunction}): FindTypes[K] | null; + findClosestByRange(type: FIND_STRUCTURES | FIND_MY_STRUCTURES | FIND_HOSTILE_STRUCTURES, opts?: {filter: FilterFunction}): T | null; /** * Find the object with the shortest linear distance from the given position. * @param objects An array of RoomPositions or objects with a RoomPosition. * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm */ - findClosestByRange(objects: T[], opts?: {filter: any | string}): T; + findClosestByRange(objects: T[], opts?: {filter: any | string}): T | null; /** * Find all objects in the specified linear range. * @param type Any of the FIND_* constants. @@ -2741,7 +2765,7 @@ interface LineStyle { /** * Either undefined (solid line), dashed, or dotted.Default is undefined. */ - lineStyle?: "dashed" | "dotted"; + lineStyle?: "dashed" | "dotted" | "solid"; } interface PolyStyle { @@ -2764,7 +2788,7 @@ interface PolyStyle { /** * Either undefined (solid line), dashed, or dotted.Default is undefined. */ - lineStyle?: "dashed" | "dotted"; + lineStyle?: "dashed" | "dotted" | "solid"; } interface CircleStyle extends PolyStyle { @@ -2871,6 +2895,23 @@ interface Room { * @returns Result Code: OK, ERR_INVALID_TARGET, ERR_INVALID_ARGS, ERR_RCL_NOT_ENOUGH */ createConstructionSite(pos: RoomPosition | _HasRoomPosition, structureType: StructureConstant): ScreepsReturnCode; + /** + * Create new ConstructionSite at the specified location. + * @param x The X position. + * @param y The Y position. + * @param structureType One of the following constants: STRUCTURE_EXTENSION, STRUCTURE_RAMPART, STRUCTURE_ROAD, STRUCTURE_SPAWN, STRUCTURE_WALL, STRUCTURE_LINK + * @param name The name of the structure, for structures that support it (currently only spawns). + * @returns Result Code: OK, ERR_INVALID_TARGET, ERR_INVALID_ARGS, ERR_RCL_NOT_ENOUGH + */ + createConstructionSite(x: number, y: number, structureType: STRUCTURE_SPAWN, name?: string): 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 + * @param name The name of the structure, for structures that support it (currently only spawns). + * @returns Result Code: OK, ERR_INVALID_TARGET, ERR_INVALID_ARGS, ERR_RCL_NOT_ENOUGH + */ + createConstructionSite(pos: RoomPosition | _HasRoomPosition, structureType: STRUCTURE_SPAWN, name?: string): ScreepsReturnCode; /** * Create new Flag at the specified location. * @param x The X position. @@ -2880,10 +2921,13 @@ interface Room { * 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. + * + * The maximum length is 60 characters. * @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. + * @returns The name of a new flag, or one of the following error codes: ERR_NAME_EXISTS, ERR_INVALID_ARGS */ - createFlag(x: number, y: number, name?: string, color?: ColorConstant, secondaryColor?: ColorConstant): ScreepsReturnCode; + createFlag(x: number, y: number, name?: string, color?: ColorConstant, secondaryColor?: ColorConstant): ERR_NAME_EXISTS | ERR_INVALID_ARGS | string; /** * Create new Flag at the specified location. * @param pos Can be a RoomPosition object or any object containing RoomPosition. @@ -2892,10 +2936,13 @@ interface Room { * 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. + * + * The maximum length is 60 characters. * @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. + * @returns The name of a new flag, or one of the following error codes: ERR_NAME_EXISTS, ERR_INVALID_ARGS */ - createFlag(pos: RoomPosition | { pos: RoomPosition }, name?: string, color?: ColorConstant, secondaryColor?: ColorConstant): ScreepsReturnCode; + createFlag(pos: RoomPosition | { pos: RoomPosition }, name?: string, color?: ColorConstant, secondaryColor?: ColorConstant): ERR_NAME_EXISTS | ERR_INVALID_ARGS | string; /** * Find all objects of the specified type in the room. * @param type One of the following constants: @@ -2929,7 +2976,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): ScreepsReturnCode | FIND_EXIT_TOP | FIND_EXIT_RIGHT | FIND_EXIT_BOTTOM | FIND_EXIT_LEFT; + findExitTo(room: string | Room): ExitConstant | ERR_NO_PATH | ERR_INVALID_ARGS; /** * Find an optimal path inside the room between fromPos and toPos using A* search algorithm. * @param fromPos The start position. @@ -2967,7 +3014,17 @@ interface Room { * @param asArray Set to true if you want to get the result as a plain array. * @returns An object with all the objects in the specified area */ - lookAtArea(top: number, left: number, bottom: number, right: number, asArray?: boolean): LookAtResultMatrix | LookAtResultWithPos[]; + lookAtArea(top: number, left: number, bottom: number, right: number, asArray?: false): LookAtResultMatrix; + /** + * Get the list of objects at the specified room area. This method is more CPU efficient in comparison to multiple lookAt calls. + * @param top The top Y boundary of the area. + * @param left The left X boundary of the area. + * @param bottom The bottom Y boundary of the area. + * @param right The right X boundary of the area. + * @param asArray Set to true if you want to get the result as a plain array. + * @returns An object with all the objects in the specified area + */ + lookAtArea(top: number, left: number, bottom: number, right: number, asArray: true): LookAtResultWithPos[]; /** * Get the objects at the given position. * @param type One of the LOOK_* constants. @@ -3033,7 +3090,7 @@ interface Room { */ } -interface RoomConstructor { +interface RoomConstructor extends _Constructor { new (id: string): Room; /** * Serialize a path array into a short string representation, which is suitable to store in memory. @@ -3167,7 +3224,7 @@ interface StructureSpawn extends OwnedStructure { * * TOUGH * * CLAIM * @param {string} name The name of a new creep. It must be a unique creep name, i.e. the Game.creeps object should not contain another creep with the same name (hash key). - * @param {{memory?: CreepMemory; energyStructures?: (StructureSpawn | StructureExtension)[]; dryRun?: boolean}} opts An object with additional options for the spawning process. + * @param {SpawnOptions} opts An object with additional options for the spawning process. * @returns {ScreepsReturnCode} One of the following codes: * ``` * OK 0 The operation has been scheduled successfully. @@ -3179,7 +3236,7 @@ interface StructureSpawn extends OwnedStructure { * ERR_RCL_NOT_ENOUGH -14 Your Room Controller level is insufficient to use this spawn. * ``` */ - spawnCreep(body: BodyPartConstant[], name: string, opts?: { memory?: CreepMemory, energyStructures?: Array<(StructureSpawn | StructureExtension)>, dryRun?: boolean }): ScreepsReturnCode; + spawnCreep(body: BodyPartConstant[], name: string, opts?: SpawnOptions): ScreepsReturnCode; /** * Destroy this spawn immediately. @@ -3263,6 +3320,30 @@ interface Spawning { setDirections(directions: DirectionConstant[]): ScreepsReturnCode & (OK | ERR_NOT_OWNER | ERR_INVALID_ARGS); } +/** + * An object with additional options for the spawning process. + */ +interface SpawnOptions { + /** + * Memory of the new creep. If provided, it will be immediately stored into Memory.creeps[name]. + */ + memory?: CreepMemory; + /** + * Array of spawns/extensions from which to draw energy for the spawning process. + * Structures will be used according to the array order. + */ + energyStructures?: Array; + /** + * If dryRun is true, the operation will only check if it is possible to create a creep. + */ + dryRun?: boolean; + /** + * Set desired directions where the creep should move when spawned. + * An array with the direction constants. + */ + directions?: DirectionConstant[]; +} + interface SpawningConstructor extends _Constructor, _ConstructorById { } /** @@ -3721,8 +3802,9 @@ interface StructureLab extends OwnedStructure { mineralAmount: number; /** * The type of minerals containing in the lab. Labs can contain only one mineral type at the same time. + * Null in case there is no mineral resource in the lab. */ - mineralType: _ResourceConstantSansEnergy | undefined; + mineralType: _ResourceConstantSansEnergy | null; /** * The total amount of minerals the lab can contain. */ @@ -3856,13 +3938,15 @@ declare const StructureNuker: StructureNukerConstructor; interface StructurePortal extends Structure { readonly prototype: StructurePortal; /** - * The position object in the destination room. + * If this is an inter-room portal, then this property contains a RoomPosition object leading to the point in the destination room. + * If this is an inter-shard portal, then this property contains an object with shard and room string properties. + * Exact coordinates are undetermined, the creep will appear at any free spot in the destination room. */ - destination: RoomPosition; + destination: RoomPosition | { shard: string, room: string }; /** * The amount of game ticks when the portal disappears, or undefined when the portal is stable. */ - ticksToDecay: number; + ticksToDecay: number | undefined; } interface StructurePortalConstructor extends _Constructor, _ConstructorById { @@ -3899,15 +3983,37 @@ type AnyStructure = StructurePortal | StructureRoad | StructureWall; +/** + * A remnant of dead creeps. This is a walkable structure. + *
    + *
  • Decay: 5 ticks per body part of the deceased creep
  • + *
+ */ interface Tombstone extends RoomObject { - /** The tombstones game objects id. */ + /** + * A unique object identificator. + * You can use {@link Game.getObjectById} method to retrieve an object instance by its id. + */ id: string; - /** The tick that the creep died. */ + /** + * Time of death. + */ deathTime: number; + /** + * An object with the tombstone contents. + * Each object key is one of the RESOURCE_* constants, values are resources amounts. + * RESOURCE_ENERGY is always defined and equals to 0 when empty, + * other resources are undefined when empty. + * You can use lodash.sum to get the total amount of contents. + */ store: StoreDefinition; - /** How many ticks until this tombstone decays */ + /** + * The amount of game ticks before this tombstone decays. + */ ticksToDecay: number; - /** The creep that died to create this tombstone */ + /** + * An object containing the deceased creep. + */ creep: Creep; } diff --git a/types/screeps/screeps-tests.ts b/types/screeps/screeps-tests.ts index a8700a853b..d837a510e3 100644 --- a/types/screeps/screeps-tests.ts +++ b/types/screeps/screeps-tests.ts @@ -24,6 +24,15 @@ interface CreepMemory { lastHits: number; } +// Typescript always uses 'string' as the type of a key inside 'for in' loops. +// In case of objects with a restricted set of properties (e.g. ResourceConstant as key in StoreDefinition) +// the type of the key should be narrowed down in order to prevent casting (key as ResourceConstant). +// This helper function provides strongly typed keys for such objects. +// See discussion (https://github.com/Microsoft/TypeScript/pull/12253) why Object.keys does not return typed keys. +function keys(o: T): Array { + return Object.keys(o) as Array; +} + // Game.creeps { @@ -95,7 +104,7 @@ interface CreepMemory { // Game.getObjectById(id) { - creep.memory.sourceId = creep.pos.findClosestByRange(FIND_SOURCES).id; + creep.memory.sourceId = creep.pos.findClosestByRange(FIND_SOURCES)!.id; const source = Game.getObjectById(creep.memory.sourceId); } @@ -121,6 +130,13 @@ interface CreepMemory { { const exits = Game.map.describeExits("W8N3"); + keys(exits) + .map((exitKey) => { + const nextRoom = exits[exitKey]; + const exitDir = +exitKey as ExitConstant; + const exitPos = creep.pos.findClosestByRange(exitDir); + return {nextRoom, exitPos}; + }); } // Game.map.findExit() @@ -128,8 +144,12 @@ interface CreepMemory { { if (creep.room !== anotherRoomName) { const exitDir = Game.map.findExit(creep.room, anotherRoomName); - const exit = creep.pos.findClosestByRange(exitDir as FindConstant); - creep.moveTo(exit); + if (exitDir !== ERR_NO_PATH && exitDir !== ERR_INVALID_ARGS) { + const exit = creep.pos.findClosestByRange(exitDir); + if (exit !== null) { + creep.moveTo(exit); + } + } } else { // go to some place in another room } @@ -146,7 +166,9 @@ interface CreepMemory { if (route !== ERR_NO_PATH && route.length > 0) { const exit = creep.pos.findClosestByRange(route[0].exit); - creep.moveTo(exit); + if (exit !== null) { + creep.moveTo(exit); + } } } @@ -283,6 +305,10 @@ interface CreepMemory { // Game.market.getOrderById(id) const order = Game.market.getOrderById("55c34a6b5be41a0a6e80c123"); + + // Subscription tokens + Game.market.getAllOrders({ type: ORDER_SELL, resourceType: SUBSCRIPTION_TOKEN }); + Game.market.createOrder(ORDER_BUY, SUBSCRIPTION_TOKEN, 10000000, 1); } // PathFinder @@ -440,24 +466,27 @@ interface CreepMemory { { // Should have type Creep const hostileCreep = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS); - - creep.say(hostileCreep.name); + if (hostileCreep !== null) { + creep.say(hostileCreep.name); + } const tower = creep.pos.findClosestByPath(FIND_HOSTILE_STRUCTURES, { filter: (structure) => { return structure.structureType === STRUCTURE_TOWER; } }); - - tower.attack(creep); + if (tower !== null) { + tower.attack(creep); + } const rampart = creep.pos.findClosestByRange(FIND_HOSTILE_STRUCTURES, { filter: (structure) => { return structure.structureType === STRUCTURE_RAMPART; } }); - - rampart.isPublic; + if (rampart !== null) { + rampart.isPublic; + } // Should have type Creep[] const hostileCreeps = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 10); @@ -475,6 +504,18 @@ interface CreepMemory { // LookAt Finds { + const matrix = room.lookAtArea(10, 10, 20, 20, false); + for (const y in matrix) { + const row = matrix[y]; + for (const x in row) { + const pos = new RoomPosition(+x, +y, room.name); + const objects = row[x]; + if (objects.length > 0) { + objects.map((o) => o.type); + } + } + } + const nukes = room.lookForAt(LOOK_NUKES, creep.pos); nukes[0].launchRoomName; @@ -493,6 +534,15 @@ interface CreepMemory { creeps[0].creep.move(TOP); } +// StoreDefinition + +{ + for (const resourceType of keys(creep.carry)) { + const amount = creep.carry[resourceType]; + creep.drop(resourceType, amount); + } +} + // Advanced Structure types { const owned = Game.getObjectById("blah"); @@ -554,3 +604,44 @@ interface CreepMemory { heap.total_heap_size; } } + +// StructurePortal + +{ + const portals = room.find(FIND_STRUCTURES, {filter: (s) => s.structureType === STRUCTURE_PORTAL}); + portals.forEach((p: StructurePortal) => { + const state = p.ticksToDecay === undefined ? 'stable' : 'unstable'; + if (p.destination instanceof RoomPosition) { + Game.notify(`Found ${state} inter-room portal to ${p.destination}`); + } else { + Game.notify(`Found ${state} inter-shard portal to ${p.destination.shard} ${p.destination.room}`); + } + }); +} + +// ConstructionSite + +{ + room.createConstructionSite(10, 10, STRUCTURE_EXTENSION); + room.createConstructionSite(10, 11, STRUCTURE_SPAWN, "mySpawn"); + + const pos = new RoomPosition(10, 10, room.name); + room.createConstructionSite(pos, STRUCTURE_EXTENSION); + room.createConstructionSite(pos, STRUCTURE_SPAWN, "mySpawn"); + pos.createConstructionSite(STRUCTURE_EXTENSION); + pos.createConstructionSite(STRUCTURE_SPAWN, "mySpawn"); +} + +// StructureLab + +{ + const lab0 = Game.getObjectById("lab0"); + const lab1 = Game.getObjectById("lab1"); + const lab2 = Game.getObjectById("lab2"); + if (lab0 !== null && lab1 !== null && lab2 !== null) { + if (lab1.mineralAmount >= LAB_REACTION_AMOUNT && lab2.mineralAmount >= LAB_REACTION_AMOUNT && + lab0.mineralType === null) { + lab0.runReaction(lab1, lab2); + } + } +} diff --git a/types/screeps/tsconfig.json b/types/screeps/tsconfig.json index 110537a00d..8dcc302c5c 100644 --- a/types/screeps/tsconfig.json +++ b/types/screeps/tsconfig.json @@ -20,4 +20,4 @@ "index.d.ts", "screeps-tests.ts" ] -} \ No newline at end of file +}