From 4c38745c3a1a6b0908b35ccc7f8a25e575f3ffce Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 09:21:55 +0200 Subject: [PATCH 01/40] Added optional visualizePathStyle to MoveToOpts interface in order to support new feature added 2017-02-06. Added PolyOpts interface to support visualizePathStyle. --- dist/screeps.d.ts | 26 ++++++++++++++++++++++++++ src/helpers.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index b3c248c..4269f5a 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -893,6 +893,32 @@ interface MoveToOpts { * significantly save CPU time in some cases. The default value is false. */ noPathFinding?: boolean; + /** + * Draws a line along the creep’s path using RoomVisual.poly. + */ + visualizePathStyle?: PolyOpts; +} +interface PolyOpts { + /** + * Fill color in any web format, default is undefined (no fill). + */ + fill?: string; + /** + * Stroke color in any web format, default is #ffffff (white). + */ + stroke?: string; + /** + * Either undefined (solid line), dashed, or dotted. Default is undefined. + */ + lineStyle?: string; + /** + * Stroke line width, default is 0.1. + */ + strokeWidth?: number; + /** + * Opacity value, default is 0.5. + */ + opacity?: number; } interface PathStep { x: number; diff --git a/src/helpers.ts b/src/helpers.ts index f9d904d..b694f8e 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -171,6 +171,38 @@ interface MoveToOpts { * significantly save CPU time in some cases. The default value is false. */ noPathFinding?: boolean; + + /** + * Draws a line along the creep’s path using RoomVisual.poly. + */ + visualizePathStyle?: PolyOpts; +} + +interface PolyOpts { + /** + * Fill color in any web format, default is undefined (no fill). + */ + fill?: string, + + /** + * Stroke color in any web format, default is #ffffff (white). + */ + stroke?: string; + + /** + * Either undefined (solid line), dashed, or dotted. Default is undefined. + */ + lineStyle?: string; + + /** + * Stroke line width, default is 0.1. + */ + strokeWidth?: number; + + /** + * Opacity value, default is 0.5. + */ + opacity?: number; } interface PathStep { From 30fb291b1884294fd87ca15dd8ee46f534a84bce Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 09:24:42 +0200 Subject: [PATCH 02/40] Added visual studio files to .gitignore. --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3a82a32..81febcc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ node_modules dist/screeps.ts npm-debug.log -*.*~ \ No newline at end of file +*.*~ +.vs +*.sln \ No newline at end of file From 77932390c1039de26add1705b708e48ca5e3782e Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 09:40:01 +0200 Subject: [PATCH 03/40] Added dependency on ntypescript for compilation. --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index e415897..6b840a5 100644 --- a/package.json +++ b/package.json @@ -17,5 +17,8 @@ "license": "MIT", "devDependencies": { "typescript": "^2.0.0" + }, + "dependencies": { + "ntypescript": "^1.201609302242.1" } } From b88dfdcc72837380365a5d8d53ce14a9f77ef313 Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 09:56:10 +0200 Subject: [PATCH 04/40] Added class declaration for RoomVisual. Moved PolyOpts to room-visual.ts Renamed PolyOpts to PolyStyleOpts. Added line method on RoomVisual class. Added LineStyleOpts interface. --- src/helpers.ts | 29 +---------------- src/room-visual.ts | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 src/room-visual.ts diff --git a/src/helpers.ts b/src/helpers.ts index b694f8e..c430b14 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -175,34 +175,7 @@ interface MoveToOpts { /** * Draws a line along the creep’s path using RoomVisual.poly. */ - visualizePathStyle?: PolyOpts; -} - -interface PolyOpts { - /** - * Fill color in any web format, default is undefined (no fill). - */ - fill?: string, - - /** - * Stroke color in any web format, default is #ffffff (white). - */ - stroke?: string; - - /** - * Either undefined (solid line), dashed, or dotted. Default is undefined. - */ - lineStyle?: string; - - /** - * Stroke line width, default is 0.1. - */ - strokeWidth?: number; - - /** - * Opacity value, default is 0.5. - */ - opacity?: number; + visualizePathStyle?: PolyStyleOpts; } interface PathStep { diff --git a/src/room-visual.ts b/src/room-visual.ts new file mode 100644 index 0000000..6caac73 --- /dev/null +++ b/src/room-visual.ts @@ -0,0 +1,77 @@ +declare class RoomVisual { + /** + * 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. + */ + roomName: string; + + /** + * Draw a line. + * @param x1 The start X coordinate. + * @param y1 The start Y coordinate. + * @param x2 The finish X coordinate. + * @param y2 The finish Y coordinate. + */ + line(x1: number, y1: number, x2: number, y2: number, style?: LineStyleOpts) : RoomVisual; + + /** + * Draw a line. + * @param pos1 The start position object. + * @param pos2 The finish position object. + */ + line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyleOpts): RoomVisual; +} + +interface LineStyleOpts { + /** + * 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: string; +} + +interface PolyStyleOpts { + /** + * Fill color in any web format, default is undefined (no fill). + */ + fill?: string, + + /** + * Stroke color in any web format, default is #ffffff (white). + */ + stroke?: string; + + /** + * Either undefined (solid line), dashed, or dotted. Default is undefined. + */ + lineStyle?: string; + + /** + * Stroke line width, default is 0.1. + */ + strokeWidth?: number; + + /** + * Opacity value, default is 0.5. + */ + opacity?: number; +} \ No newline at end of file From 2ebc7f2a7df9d9190cecf6835d69903087663c30 Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 10:16:47 +0200 Subject: [PATCH 05/40] Completed declaration of RoomVisual. --- src/room-visual.ts | 190 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 188 insertions(+), 2 deletions(-) diff --git a/src/room-visual.ts b/src/room-visual.ts index 6caac73..fc73c72 100644 --- a/src/room-visual.ts +++ b/src/room-visual.ts @@ -16,15 +16,96 @@ declare class RoomVisual { * @param y1 The start Y coordinate. * @param x2 The finish X coordinate. * @param y2 The finish Y coordinate. - */ - line(x1: number, y1: number, x2: number, y2: number, style?: LineStyleOpts) : RoomVisual; + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + line(x1: number, y1: number, x2: number, y2: number, style?: LineStyleOpts): RoomVisual; /** * Draw a line. * @param pos1 The start position object. * @param pos2 The finish position object. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. */ line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyleOpts): RoomVisual; + + /** + * Draw a circle. + * @param x The X coordinate of the center. + * @param y The Y coordinate of the center. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + circle(x: number, y: number, style?: CircleStyleOpts): 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?: CircleStyleOpts): RoomVisual; + + /** + * Draw a line. + * @param x The X coordinate of the top-left corner. + * @param y The Y coordinate 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(x: number, y: number, width: number, height: number, style?: RectStyleOpts): 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?: RectStyleOpts): RoomVisual; + + /** + * Draw a line. + * @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 An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + poly(points: (number[] | RoomPosition)[], style?: PolyStyleOpts): RoomVisual; + + /** + * Draw a text label. You can use any valid Unicode characters, including emoji. + * @param text The text message. + * @param x The X coordinate of the center. + * @param y The Y coordinate of the center. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + text(text: string, x: number, y: number, style?: TextStyleOpts): 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?: TextStyleOpts): RoomVisual; + + /** + * Remove all visuals from the room. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + clear(): RoomVisual; + + /** + * Get the stored size of all visuals added in the room in the current tick. It must not exceed 512,000 (500 KB). + * @returns The size of the visuals in bytes. + */ + getSize(): number; } interface LineStyleOpts { @@ -49,6 +130,65 @@ interface LineStyleOpts { lineStyle: string; } +interface CircleStyleOpts { + /** + * Circle radius, default is 0.15. + */ + radius: number; + + /** + * 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; + + /** + * Stroke line width, default is 0.1. + */ + strokeWidth: number; + + /** + * Either undefined (solid line), dashed, or dotted.Default is undefined. + */ + lineStyle: string; +} + +interface RectStyleOpts { + /** + * 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; + + /** + * Stroke line width, default is 0.1. + */ + strokeWidth: number; + + /** + * Either undefined (solid line), dashed, or dotted.Default is undefined. + */ + lineStyle: string; +} + interface PolyStyleOpts { /** * Fill color in any web format, default is undefined (no fill). @@ -74,4 +214,50 @@ interface PolyStyleOpts { * Opacity value, default is 0.5. */ opacity?: number; +} + +interface TextStyleOpts { + /** + * Font color in any web format, default is #ffffff(white). + */ + color: string; + + /** + * 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). + */ + background: string; + + /** + * Background rectangle padding, default is 0.3. + */ + backgroundPadding: number; + + /** + * Text align, either center, left, or right.Default is center. + */ + align: string; + + /** + * Opacity value, default is 1.0. + */ + opacity: number; } \ No newline at end of file From 11fa54568c64cbe5748806d2ff7ffc07d3e7339c Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 10:18:19 +0200 Subject: [PATCH 06/40] Added visual property to Room class declaration. --- src/room.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/room.ts b/src/room.ts index 4afac14..647ec39 100644 --- a/src/room.ts +++ b/src/room.ts @@ -40,7 +40,11 @@ declare class Room { /** * The Terminal structure of this room, if present, otherwise undefined. */ - terminal: Terminal | undefined; + terminal: Terminal | undefined; + /** + * A RoomVisual object for this room. You can use this object to draw simple shapes (lines, circles, text labels) in the room. + */ + visual: RoomVisual; /** * Create new ConstructionSite at the specified location. * @param x The X position. From 42d1971809fca2c9501b32f08b95844f225c4da9 Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 10:20:34 +0200 Subject: [PATCH 07/40] Updated dist file to include all changes. --- dist/screeps.d.ts | 251 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 228 insertions(+), 23 deletions(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index 4269f5a..a158f6b 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -896,29 +896,7 @@ interface MoveToOpts { /** * Draws a line along the creep’s path using RoomVisual.poly. */ - visualizePathStyle?: PolyOpts; -} -interface PolyOpts { - /** - * Fill color in any web format, default is undefined (no fill). - */ - fill?: string; - /** - * Stroke color in any web format, default is #ffffff (white). - */ - stroke?: string; - /** - * Either undefined (solid line), dashed, or dotted. Default is undefined. - */ - lineStyle?: string; - /** - * Stroke line width, default is 0.1. - */ - strokeWidth?: number; - /** - * Opacity value, default is 0.5. - */ - opacity?: number; + visualizePathStyle?: PolyStyleOpts; } interface PathStep { x: number; @@ -1539,6 +1517,229 @@ declare class RoomPosition { */ lookFor(type: string): T[]; } +declare class RoomVisual { + /** + * 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. + */ + roomName: string; + /** + * Draw a line. + * @param x1 The start X coordinate. + * @param y1 The start Y coordinate. + * @param x2 The finish X coordinate. + * @param y2 The finish Y coordinate. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + line(x1: number, y1: number, x2: number, y2: number, style?: LineStyleOpts): RoomVisual; + /** + * Draw a line. + * @param pos1 The start position object. + * @param pos2 The finish position object. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyleOpts): RoomVisual; + /** + * Draw a circle. + * @param x The X coordinate of the center. + * @param y The Y coordinate of the center. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + circle(x: number, y: number, style?: CircleStyleOpts): 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?: CircleStyleOpts): RoomVisual; + /** + * Draw a line. + * @param x The X coordinate of the top-left corner. + * @param y The Y coordinate 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(x: number, y: number, width: number, height: number, style?: RectStyleOpts): 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?: RectStyleOpts): RoomVisual; + /** + * Draw a line. + * @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 An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + poly(points: (number[] | RoomPosition)[], style?: PolyStyleOpts): RoomVisual; + /** + * Draw a text label. You can use any valid Unicode characters, including emoji. + * @param text The text message. + * @param x The X coordinate of the center. + * @param y The Y coordinate of the center. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + text(text: string, x: number, y: number, style?: TextStyleOpts): 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?: TextStyleOpts): RoomVisual; + /** + * Remove all visuals from the room. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + clear(): RoomVisual; + /** + * Get the stored size of all visuals added in the room in the current tick. It must not exceed 512,000 (500 KB). + * @returns The size of the visuals in bytes. + */ + getSize(): number; +} +interface LineStyleOpts { + /** + * 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: string; +} +interface CircleStyleOpts { + /** + * Circle radius, default is 0.15. + */ + radius: number; + /** + * 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; + /** + * Stroke line width, default is 0.1. + */ + strokeWidth: number; + /** + * Either undefined (solid line), dashed, or dotted.Default is undefined. + */ + lineStyle: string; +} +interface RectStyleOpts { + /** + * 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; + /** + * Stroke line width, default is 0.1. + */ + strokeWidth: number; + /** + * Either undefined (solid line), dashed, or dotted.Default is undefined. + */ + lineStyle: string; +} +interface PolyStyleOpts { + /** + * Fill color in any web format, default is undefined (no fill). + */ + fill?: string; + /** + * Stroke color in any web format, default is #ffffff (white). + */ + stroke?: string; + /** + * Either undefined (solid line), dashed, or dotted. Default is undefined. + */ + lineStyle?: string; + /** + * Stroke line width, default is 0.1. + */ + strokeWidth?: number; + /** + * Opacity value, default is 0.5. + */ + opacity?: number; +} +interface TextStyleOpts { + /** + * Font color in any web format, default is #ffffff(white). + */ + color: string; + /** + * 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). + */ + background: string; + /** + * Background rectangle padding, default is 0.3. + */ + backgroundPadding: number; + /** + * Text align, either center, left, or right.Default is center. + */ + align: string; + /** + * Opacity value, default is 1.0. + */ + opacity: number; +} /** * An object representing the room in which your units and structures are in. It can be used to look around, find paths, etc. Every object in the room contains its linked Room instance in the room property. */ @@ -1580,6 +1781,10 @@ declare class Room { * The Terminal structure of this room, if present, otherwise undefined. */ terminal: Terminal | undefined; + /** + * A RoomVisual object for this room. You can use this object to draw simple shapes (lines, circles, text labels) in the room. + */ + visual: RoomVisual; /** * Create new ConstructionSite at the specified location. * @param x The X position. From db62d9d5456afcde4954928c9bc2f94800bcf9e8 Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 10:24:46 +0200 Subject: [PATCH 08/40] Replaced my tabs with their spaces. --- src/room-visual.ts | 138 ++++++++++++++++++++++----------------------- src/room.ts | 4 +- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/src/room-visual.ts b/src/room-visual.ts index fc73c72..e612dca 100644 --- a/src/room-visual.ts +++ b/src/room-visual.ts @@ -1,14 +1,14 @@ declare class RoomVisual { - /** - * 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 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. */ - roomName: string; + roomName: string; /** * Draw a line. @@ -18,17 +18,17 @@ declare class RoomVisual { * @param y2 The finish Y coordinate. * @param style An object describing the style. * @returns The RoomVisual object itself, so that you can chain calls. - */ - line(x1: number, y1: number, x2: number, y2: number, style?: LineStyleOpts): RoomVisual; + */ + line(x1: number, y1: number, x2: number, y2: number, style?: LineStyleOpts): RoomVisual; - /** + /** * Draw a line. * @param pos1 The start position object. * @param pos2 The finish position object. * @param style An object describing the style. * @returns The RoomVisual object itself, so that you can chain calls. */ - line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyleOpts): RoomVisual; + line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyleOpts): RoomVisual; /** * Draw a circle. @@ -37,15 +37,15 @@ declare class RoomVisual { * @param style An object describing the style. * @returns The RoomVisual object itself, so that you can chain calls. */ - circle(x: number, y: number, style?: CircleStyleOpts): RoomVisual; + circle(x: number, y: number, style?: CircleStyleOpts): 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?: CircleStyleOpts): RoomVisual; + circle(pos: RoomPosition, style?: CircleStyleOpts): RoomVisual; /** * Draw a line. @@ -55,10 +55,10 @@ declare class RoomVisual { * @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(x: number, y: number, width: number, height: number, style?: RectStyleOpts): RoomVisual; + */ + rect(x: number, y: number, width: number, height: number, style?: RectStyleOpts): RoomVisual; - /** + /** * Draw a line. * @param topLeftPos The position object of the top-left corner. * @param width The width of the rectangle. @@ -66,161 +66,161 @@ declare class RoomVisual { * @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?: RectStyleOpts): RoomVisual; + rect(topLeftPos: RoomPosition, width: number, height: number, style?: RectStyleOpts): RoomVisual; - /** + /** * Draw a line. * @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 An object describing the style. * @returns The RoomVisual object itself, so that you can chain calls. */ - poly(points: (number[] | RoomPosition)[], style?: PolyStyleOpts): RoomVisual; + poly(points: (number[] | RoomPosition)[], style?: PolyStyleOpts): RoomVisual; - /** - * Draw a text label. You can use any valid Unicode characters, including emoji. - * @param text The text message. - * @param x The X coordinate of the center. - * @param y The Y coordinate of the center. - * @param style An object describing the style. - * @returns The RoomVisual object itself, so that you can chain calls. - */ - text(text: string, x: number, y: number, style?: TextStyleOpts): RoomVisual; + /** + * Draw a text label. You can use any valid Unicode characters, including emoji. + * @param text The text message. + * @param x The X coordinate of the center. + * @param y The Y coordinate of the center. + * @param style An object describing the style. + * @returns The RoomVisual object itself, so that you can chain calls. + */ + text(text: string, x: number, y: number, style?: TextStyleOpts): RoomVisual; - /** + /** * Draw a text label. You can use any valid Unicode characters, including emoji. - * @param text The text message. + * @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?: TextStyleOpts): RoomVisual; + text(text: string, pos: RoomPosition, style?: TextStyleOpts): RoomVisual; - /** + /** * Remove all visuals from the room. * @returns The RoomVisual object itself, so that you can chain calls. */ - clear(): RoomVisual; + clear(): RoomVisual; - /** + /** * Get the stored size of all visuals added in the room in the current tick. It must not exceed 512,000 (500 KB). - * @returns The size of the visuals in bytes. + * @returns The RoomVisual object itself, so that you can chain calls. */ - getSize(): number; + getSize(): number; } interface LineStyleOpts { /** * Line width, default is 0.1. */ - width: number; + width: number; /** * Line color in any web format, default is #ffffff(white). */ - color: string; + color: string; /** * Opacity value, default is 0.5. */ - opacity: number; + opacity: number; /** * Either undefined (solid line), dashed, or dotted.Default is undefined. */ - lineStyle: string; + lineStyle: string; } interface CircleStyleOpts { /** * Circle radius, default is 0.15. */ - radius: number; + radius: number; /** * Fill color in any web format, default is #ffffff(white). */ - fill: string; + fill: string; /** * Opacity value, default is 0.5. */ - opacity: number; + opacity: number; /** * Stroke color in any web format, default is undefined (no stroke). */ - stroke: string; + stroke: string; /** * Stroke line width, default is 0.1. */ - strokeWidth: number; + strokeWidth: number; /** * Either undefined (solid line), dashed, or dotted.Default is undefined. */ - lineStyle: string; + lineStyle: string; } interface RectStyleOpts { - /** + /** * Fill color in any web format, default is #ffffff(white). */ - fill: string; + fill: string; - /** + /** * Opacity value, default is 0.5. */ - opacity: number; + opacity: number; - /** + /** * Stroke color in any web format, default is undefined (no stroke). */ - stroke: string; + stroke: string; - /** + /** * Stroke line width, default is 0.1. */ - strokeWidth: number; + strokeWidth: number; - /** + /** * Either undefined (solid line), dashed, or dotted.Default is undefined. */ - lineStyle: string; + lineStyle: string; } interface PolyStyleOpts { /** * Fill color in any web format, default is undefined (no fill). */ - fill?: string, + fill?: string, /** * Stroke color in any web format, default is #ffffff (white). */ - stroke?: string; + stroke?: string; /** * Either undefined (solid line), dashed, or dotted. Default is undefined. */ - lineStyle?: string; + lineStyle?: string; /** * Stroke line width, default is 0.1. */ - strokeWidth?: number; + strokeWidth?: number; /** * Opacity value, default is 0.5. */ - opacity?: number; + opacity?: number; } interface TextStyleOpts { /** * Font color in any web format, default is #ffffff(white). */ - color: string; + color: string; /** * Either a number or a string in one of the following forms: @@ -229,35 +229,35 @@ interface TextStyleOpts { * 0.7 serif * bold italic 1.5 Times New Roman */ - font: number | string; + font: number | string; /** * Stroke color in any web format, default is undefined (no stroke). */ - stroke: string; + stroke: string; /** * Stroke width, default is 0.15. */ - strokeWidth: number; + 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). */ - background: string; + background: string; /** * Background rectangle padding, default is 0.3. */ - backgroundPadding: number; + backgroundPadding: number; /** * Text align, either center, left, or right.Default is center. */ - align: string; + align: string; /** * Opacity value, default is 1.0. */ - opacity: number; + opacity: number; } \ No newline at end of file diff --git a/src/room.ts b/src/room.ts index 647ec39..009f444 100644 --- a/src/room.ts +++ b/src/room.ts @@ -40,11 +40,11 @@ declare class Room { /** * The Terminal structure of this room, if present, otherwise undefined. */ - terminal: Terminal | undefined; + terminal: Terminal | undefined; /** * A RoomVisual object for this room. You can use this object to draw simple shapes (lines, circles, text labels) in the room. */ - visual: RoomVisual; + visual: RoomVisual; /** * Create new ConstructionSite at the specified location. * @param x The X position. From 6466db08fc513c3a92a0c76fef4cbbe6a9409f7d Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 10:26:38 +0200 Subject: [PATCH 09/40] Adjusted a comment. --- src/room-visual.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/room-visual.ts b/src/room-visual.ts index e612dca..4e51dd3 100644 --- a/src/room-visual.ts +++ b/src/room-visual.ts @@ -103,7 +103,7 @@ declare class RoomVisual { /** * Get the stored size of all visuals added in the room in the current tick. It must not exceed 512,000 (500 KB). - * @returns The RoomVisual object itself, so that you can chain calls. + * @returns The size of the visuals in bytes. */ getSize(): number; } From db8ba79072f86448d1fad580939b5879d9420205 Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 11:21:48 +0200 Subject: [PATCH 10/40] removed unnecessary change to .gitignore. --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 81febcc..3a82a32 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,4 @@ node_modules dist/screeps.ts npm-debug.log -*.*~ -.vs -*.sln \ No newline at end of file +*.*~ \ No newline at end of file From 398bd281652edc2fa59e12b5775fa4b5bde1def6 Mon Sep 17 00:00:00 2001 From: James Yarbro Date: Tue, 2 May 2017 11:47:03 +0200 Subject: [PATCH 11/40] removed addition of ntypescript dependency as it's outside the scope of this pull request. --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index 6b840a5..e415897 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,5 @@ "license": "MIT", "devDependencies": { "typescript": "^2.0.0" - }, - "dependencies": { - "ntypescript": "^1.201609302242.1" } } From 44ab926d883ace2f83a77b362fa2a020cdf03f85 Mon Sep 17 00:00:00 2001 From: Bryan Date: Sun, 14 May 2017 12:28:58 +0800 Subject: [PATCH 12/40] Fix Memory interface so that's it's extensible The previous declaration was not extensible, meaning we couldn't type our own memory. This abstracts Creep, Flag, Room, and Memory into empty interfaces that can then be extended by the user --- src/memory.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 {} From 82298b4711c51926dac5541708836728ca09e7be Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Tue, 16 May 2017 13:28:28 +0800 Subject: [PATCH 13/40] Change Creep, Spawn, Flag, and Room memory to match Memory object --- src/creep.ts | 2 +- src/flag.ts | 2 +- src/room.ts | 2 +- src/spawn.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/creep.ts b/src/creep.ts index c5adecb..bc84e37 100644 --- a/src/creep.ts +++ b/src/creep.ts @@ -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. */ diff --git a/src/flag.ts b/src/flag.ts index a3805e3..ce5d0eb 100644 --- a/src/flag.ts +++ b/src/flag.ts @@ -11,7 +11,7 @@ interface Flag extends RoomObject { /** * 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. */ diff --git a/src/room.ts b/src/room.ts index 287afe1..7e82f62 100644 --- a/src/room.ts +++ b/src/room.ts @@ -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 diff --git a/src/spawn.ts b/src/spawn.ts index 909f079..cc279d2 100644 --- a/src/spawn.ts +++ b/src/spawn.ts @@ -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. */ From dc9983fca00c6934681b74fca6233c3732a5221c Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Fri, 19 May 2017 15:00:40 +0800 Subject: [PATCH 14/40] Compile changes to memory --- dist/screeps.d.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index c1cbdff..6e2b742 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -454,7 +454,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. */ @@ -656,7 +656,7 @@ interface Flag extends RoomObject { /** * 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. */ @@ -1155,18 +1155,26 @@ 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. */ @@ -1702,7 +1710,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 @@ -1899,7 +1907,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. */ From ffe937744b2275d128342455b2a18d93dc12edca Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 10:34:43 +0800 Subject: [PATCH 15/40] Return code and find literals added --- src/literals.ts | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/literals.ts diff --git a/src/literals.ts b/src/literals.ts new file mode 100644 index 0000000..4a02490 --- /dev/null +++ b/src/literals.ts @@ -0,0 +1,93 @@ +/** + * This file creates literal versions of many of the constants + * It should be kept in sync with constants.ts + */ + +// 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; + +// Find Constants + +type ScreepsFindConstant = + 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_DROPPED_ENERGY | + 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_DROPPED_ENERGY = 106; // Yup, it's 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; From 89238114848a1493b7793a1ce95c6eeff32f10e5 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 11:18:57 +0800 Subject: [PATCH 16/40] Re add major constants as literal types --- src/literals.ts | 191 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 189 insertions(+), 2 deletions(-) diff --git a/src/literals.ts b/src/literals.ts index 4a02490..33bb95c 100644 --- a/src/literals.ts +++ b/src/literals.ts @@ -3,7 +3,8 @@ * It should be kept in sync with constants.ts */ -// return codes +//////// +// Return Codes type ScreepsReturnCode = OK | @@ -41,9 +42,10 @@ type ERR_NOT_ENOUGH_EXTENSIONS = -6; type ERR_RCL_NOT_ENOUGH = -14; type ERR_GCL_NOT_ENOUGH = -15; +//////// // Find Constants -type ScreepsFindConstant = +type FindConstant = FIND_EXIT_TOP | FIND_EXIT_RIGHT | FIND_EXIT_BOTTOM | @@ -91,3 +93,188 @@ type FIND_MY_CONSTRUCTION_SITES = 114; type FIND_HOSTILE_CONSTRUCTION_SITES = 115; type FIND_MINERALS = 116; type FIND_NUKES = 117; + +//////// +// 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_CREEPS = "creep"; +type LOOK_ENERGY = "energy"; +type LOOK_RESOURCES = "resource"; +type LOOK_SOURCES = "source"; +type LOOK_MINERALS = "mineral"; +type LOOK_STRUCTURES = "structure"; +type LOOK_FLAGS = "flag"; +type LOOK_CONSTRUCTION_SITES = "constructionSite"; +type LOOK_NUKES = "nuke"; +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; + +//////// +// Structure Constants + +type StructureConstant = + 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 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"; + +// type RESOURCES_ALL: string[]; From 185003c4947fddbf3acc1c80f120961492a5cf41 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 11:30:00 +0800 Subject: [PATCH 17/40] BodyPart constants --- src/literals.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/literals.ts b/src/literals.ts index 33bb95c..12ea994 100644 --- a/src/literals.ts +++ b/src/literals.ts @@ -94,6 +94,28 @@ 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 From 9eb36d7b61dd3d3bf10353cfcb7726907df20388 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 11:41:20 +0800 Subject: [PATCH 18/40] Color constants --- src/literals.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/literals.ts b/src/literals.ts index 12ea994..3e411a7 100644 --- a/src/literals.ts +++ b/src/literals.ts @@ -164,6 +164,32 @@ 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 From 1e71b1b91497960d83c3e81431e08bcba2e12fde Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 11:53:55 +0800 Subject: [PATCH 19/40] Mineral Literals added; Narrow typings of some Constants --- src/constants.ts | 62 +++++++++++++----------------------------------- src/literals.ts | 15 +++++++++++- 2 files changed, 31 insertions(+), 46 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 576096e..2a43820 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -64,13 +64,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 +131,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: {[T in BodyPartConstant]: number}; + +declare const BODYPARTS_ALL: BodyPartConstant[]; declare const CARRY_CAPACITY: 50; @@ -165,23 +158,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: {[T in StructureConstant]: number}; declare const CONSTRUCTION_COST_ROAD_SWAMP_RATIO: 5; @@ -248,12 +226,12 @@ 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: {[T in StructureConstant]: {[level: number]: number}}; 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: {[T in MineralConstant]: number}; 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/literals.ts b/src/literals.ts index 3e411a7..4480642 100644 --- a/src/literals.ts +++ b/src/literals.ts @@ -281,8 +281,19 @@ type ResourceConstant = 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"; @@ -291,6 +302,7 @@ 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"; @@ -304,6 +316,7 @@ 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"; @@ -314,6 +327,7 @@ 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"; @@ -325,4 +339,3 @@ type RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE = "ZXHO2"; type RESOURCE_CATALYZED_GHODIUM_ACID = "XGH2O"; type RESOURCE_CATALYZED_GHODIUM_ALKALIDE = "XGHO2"; -// type RESOURCES_ALL: string[]; From 88e9f75579c64c18cfae34e61120c476a83718f9 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 11:56:24 +0800 Subject: [PATCH 20/40] Construct Site generified --- src/construction-site.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 64927505926e6bfe0ffca6fd3906b3ce7c815b24 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 12:18:34 +0800 Subject: [PATCH 21/40] Change to use native `Record` type --- src/constants.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 2a43820..6844894 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -131,7 +131,7 @@ declare const LINK_LOSS_RATIO: 0.03; declare const STORAGE_CAPACITY: 1000000; declare const STORAGE_HITS: 10000; -declare const BODYPART_COST: {[T in BodyPartConstant]: number}; +declare const BODYPART_COST: Record; declare const BODYPARTS_ALL: BodyPartConstant[]; @@ -159,7 +159,7 @@ declare const HEAL: "heal"; declare const CLAIM: "claim"; // TODO do we care that some structure constants aren't buildable? -declare const CONSTRUCTION_COST: {[T in StructureConstant]: number}; +declare const CONSTRUCTION_COST: Record; declare const CONSTRUCTION_COST_ROAD_SWAMP_RATIO: 5; @@ -231,7 +231,8 @@ declare const RESOURCES_ALL: ResourceConstant[]; declare const SUBSCRIPTION_TOKEN: string; declare const CONTROLLER_LEVELS: {[level: number]: number}; -declare const CONTROLLER_STRUCTURES: {[T in StructureConstant]: {[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; @@ -290,7 +291,7 @@ declare const MAX_CONSTRUCTION_SITES: number; declare const MAX_CREEP_SIZE: number; declare const MINERAL_REGEN_TIME: number; -declare const MINERAL_MIN_AMOUNT: {[T in MineralConstant]: number}; +declare const MINERAL_MIN_AMOUNT: Record; declare const MINERAL_RANDOM_FACTOR: number; From e29ee19deca7f9f72f9233f6fa4483cd1c3a0929 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 12:51:41 +0800 Subject: [PATCH 22/40] Creep typings updated; NOTE: Return codes aren't narrowed completely --- src/creep.ts | 58 ++++++++++++++++++++++++------------------------- src/helpers.ts | 17 +++++++++------ src/literals.ts | 15 +++++++++++++ 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/creep.ts b/src/creep.ts index bc84e37..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 @@ -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/helpers.ts b/src/helpers.ts index dc7cc53..f93cd82 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -22,11 +22,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,11 +45,14 @@ interface SignDefinition { time: number, datetime: Date; } -interface StoreDefinition { - [resource: string]: number | undefined; - energy?: number; - power?: number; -} + +// TODO make sure this workes +type StoreDefinition = Record; +// interface StoreDefinition { + // [resource: string]: number | undefined; + // energy?: number; + // power?: number; +// } interface LookAtResultWithPos { x: number; diff --git a/src/literals.ts b/src/literals.ts index 4480642..4c34136 100644 --- a/src/literals.ts +++ b/src/literals.ts @@ -42,6 +42,21 @@ 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 From 78c64175e4f5cbb159e05576ca3d4c3a3ec047b5 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 12:59:01 +0800 Subject: [PATCH 23/40] Flag typings finished --- src/flag.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/flag.ts b/src/flag.ts index ce5d0eb..2b06053 100644 --- a/src/flag.ts +++ b/src/flag.ts @@ -3,11 +3,11 @@ */ 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. */ @@ -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; From d0e310c3467ef56af0d552175162751590bc1925 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 15:23:10 +0800 Subject: [PATCH 24/40] All structures finished --- src/helpers.ts | 6 +- src/literals.ts | 1 + src/market.ts | 16 ++--- src/mineral.ts | 2 +- src/nuke.ts | 2 +- src/resource.ts | 4 +- src/room-position.ts | 22 +++---- src/room.ts | 26 ++++---- src/spawn.ts | 21 +++---- src/structure.ts | 142 +++++++++++++------------------------------ 10 files changed, 90 insertions(+), 152 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index f93cd82..7c35517 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,3 +1,5 @@ +type _HasRoomPosition = { pos: RoomPosition } + interface GlobalControlLevel { level: number; progress: number; @@ -123,13 +125,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. diff --git a/src/literals.ts b/src/literals.ts index 4c34136..7618bf0 100644 --- a/src/literals.ts +++ b/src/literals.ts @@ -209,6 +209,7 @@ type COLOR_WHITE = 10; // Structure Constants type StructureConstant = + STRUCTURE_EXTENSION | STRUCTURE_RAMPART | STRUCTURE_ROAD | STRUCTURE_SPAWN | 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/mineral.ts b/src/mineral.ts index 4dc6cf1..b2c716e 100644 --- a/src/mineral.ts +++ b/src/mineral.ts @@ -17,7 +17,7 @@ interface Mineral extends RoomObject { /** * The resource type, one of the RESOURCE_* constants. */ - mineralType: string; + mineralType: MineralConstant; /** * 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/resource.ts b/src/resource.ts index 412dde7..f22126e 100644 --- a/src/resource.ts +++ b/src/resource.ts @@ -4,7 +4,7 @@ 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: ResourceConstant; } interface ResourceConstructor { diff --git a/src/room-position.ts b/src/room-position.ts index eb581ec..3be298d 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,7 +78,7 @@ 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. @@ -89,7 +89,7 @@ interface RoomPosition { * 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.ts b/src/room.ts index 7e82f62..36a9b36 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. */ @@ -32,11 +32,11 @@ 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. */ @@ -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: LookConstant, 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 cc279d2..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. @@ -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. From 70848b4d1ac538f7ff1696e8c0180b47b3434f0d Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 15:36:16 +0800 Subject: [PATCH 25/40] Add type to Resource --- src/resource.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resource.ts b/src/resource.ts index f22126e..f6822ee 100644 --- a/src/resource.ts +++ b/src/resource.ts @@ -2,7 +2,7 @@ * 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; /** @@ -16,7 +16,7 @@ interface Resource extends RoomObject { /** * One of the `RESOURCE_*` constants. */ - resourceType: ResourceConstant; + resourceType: T; } interface ResourceConstructor { From 8a137ca6bca977c671b8e04d15945c70356c95d4 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 15:48:08 +0800 Subject: [PATCH 26/40] Typed LookAt results --- src/helpers.ts | 33 +++++++++++---------------------- src/literals.ts | 4 ++++ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 7c35517..4fa516f 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -55,39 +55,28 @@ type StoreDefinition = Record; // energy?: number; // power?: number; // } - -interface LookAtResultWithPos { - x: number; - y: number; - type: string; +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; 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[] + [coord: number]: LookAtResultMatrix | LookAtResult[] } interface FindPathOpts { diff --git a/src/literals.ts b/src/literals.ts index 7618bf0..5e996e0 100644 --- a/src/literals.ts +++ b/src/literals.ts @@ -3,6 +3,10 @@ * It should be kept in sync with constants.ts */ +//// Extras + +type Terrain = "plain" | "swamp" | "wall"; + //////// // Return Codes From c666dee38908989563ddc0be8bff6b56a6be7689 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 15:53:43 +0800 Subject: [PATCH 27/40] Generify minerals --- src/helpers.ts | 2 +- src/mineral.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 4fa516f..f42e3ab 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -182,7 +182,7 @@ interface PathStep { dx: number; y: number; dy: number; - direction: number; + direction: DirectionConstant; } /** diff --git a/src/mineral.ts b/src/mineral.ts index b2c716e..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: MineralConstant; + mineralType: T; /** * A unique object identifier. You can use Game.getObjectById method to retrieve an object instance by its id. */ From 547d7ad60bb27af9706fd1d985625b4e0516c19c Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 16:02:00 +0800 Subject: [PATCH 28/40] Add nukes to types --- src/helpers.ts | 5 +++-- src/literals.ts | 8 ++++---- src/room.ts | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index f42e3ab..37a7af3 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -62,6 +62,7 @@ interface LookAtTypes { exit?: any; // TODO what type is this? flag?: Flag; mineral?: Mineral; + nuke?: Nuke; resource? : Resource; source?: Source; structure?: Structure; @@ -75,8 +76,8 @@ type LookAtResultWithPos = Look y: number, } -interface LookAtResultMatrix { - [coord: number]: LookAtResultMatrix | LookAtResult[] +interface LookAtResultMatrix { + [coord: number]: LookAtResultMatrix | LookAtResult[] } interface FindPathOpts { diff --git a/src/literals.ts b/src/literals.ts index 5e996e0..897e3db 100644 --- a/src/literals.ts +++ b/src/literals.ts @@ -150,15 +150,15 @@ type LookConstant = 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_MINERALS = "mineral"; type LOOK_STRUCTURES = "structure"; -type LOOK_FLAGS = "flag"; -type LOOK_CONSTRUCTION_SITES = "constructionSite"; -type LOOK_NUKES = "nuke"; type LOOK_TERRAIN = "terrain"; //////// diff --git a/src/room.ts b/src/room.ts index 36a9b36..bb05741 100644 --- a/src/room.ts +++ b/src/room.ts @@ -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: LookConstant, 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. From f6006111d7b1cb932082a2ef2644def47eb47c84 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 16:03:02 +0800 Subject: [PATCH 29/40] Compiled changes --- dist/screeps.d.ts | 584 +++++++++++++++++++++++++--------------------- 1 file changed, 312 insertions(+), 272 deletions(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index 6e2b742..bdb5740 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -60,7 +60,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 +112,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 +134,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 +198,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 +255,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 +295,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 +321,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 +346,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 @@ -487,79 +451,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 +531,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 +580,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,7 +616,7 @@ 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. */ @@ -664,26 +628,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 +655,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 +735,9 @@ interface Game { */ notify(message: string, groupInterval?: number): void; } +declare type _HasRoomPosition = { + pos: RoomPosition; +}; interface GlobalControlLevel { level: number; progress: number; @@ -792,11 +759,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 +782,29 @@ 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; +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 +894,7 @@ interface PathStep { dx: number; y: number; dy: number; - direction: number; + direction: DirectionConstant; } /** * An object with survival game info @@ -965,6 +920,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_DROPPED_ENERGY | 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 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_DROPPED_ENERGY = 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. */ @@ -1074,34 +1183,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 +1233,7 @@ interface Transaction { recipient?: { username: string; }; - resourceType: string; + resourceType: ResourceConstant; amount: number; from: string; to: string; @@ -1135,7 +1244,7 @@ interface Order { created: number; active?: boolean; type: string; - resourceType: string; + resourceType: ResourceConstant; roomName?: string; amount: number; remainingAmount: number; @@ -1146,7 +1255,7 @@ interface OrderFilter { id?: string; created?: number; type?: string; - resourceType?: string; + resourceType?: ResourceConstant; roomName?: string; amount?: number; remainingAmount?: number; @@ -1178,7 +1287,7 @@ 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. */ @@ -1194,7 +1303,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. */ @@ -1386,7 +1495,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. @@ -1399,7 +1508,7 @@ interface Resource extends RoomObject { /** * One of the `RESOURCE_*` constants. */ - resourceType: string; + resourceType: T; } interface ResourceConstructor { new (id: string): Resource; @@ -1448,29 +1557,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; @@ -1479,15 +1588,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; /** @@ -1496,7 +1605,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[]; /** @@ -1505,7 +1614,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[]; /** @@ -1520,9 +1629,7 @@ 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. @@ -1533,9 +1640,7 @@ interface RoomPosition { * 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. @@ -1591,7 +1696,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 { /** @@ -1698,7 +1803,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. */ @@ -1723,11 +1828,11 @@ 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. */ @@ -1739,16 +1844,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. @@ -1757,7 +1860,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. @@ -1767,14 +1870,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[]; /** @@ -1783,7 +1886,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. @@ -1831,14 +1934,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[]; /** @@ -1850,7 +1953,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; @@ -1894,7 +1997,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. @@ -1928,7 +2031,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 @@ -1942,11 +2045,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. */ @@ -1955,24 +2058,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 { } @@ -1980,7 +2076,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. @@ -2002,11 +2098,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. */ @@ -2015,7 +2111,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 { } @@ -2024,7 +2120,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. @@ -2047,7 +2143,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. @@ -2068,7 +2164,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. */ @@ -2076,7 +2172,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 */ @@ -2093,11 +2189,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 { } @@ -2107,7 +2203,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. @@ -2117,13 +2213,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 { } @@ -2131,7 +2220,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. @@ -2150,7 +2239,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 { } @@ -2159,12 +2248,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 { } @@ -2172,13 +2261,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 { } @@ -2186,7 +2275,7 @@ declare const StructureObserver: StructureObserverConstructor; /** * */ -interface StructurePowerBank extends OwnedStructure { +interface StructurePowerBank extends OwnedStructure { readonly prototype: StructurePowerBank; /** * The amount of power containing. @@ -2204,7 +2293,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. @@ -2226,18 +2315,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 { } @@ -2246,7 +2328,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. @@ -2269,7 +2351,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. @@ -2283,7 +2365,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. @@ -2293,21 +2375,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 { } @@ -2317,7 +2384,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. @@ -2331,23 +2398,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 { } @@ -2355,7 +2416,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). @@ -2368,7 +2429,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. @@ -2381,7 +2442,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. @@ -2402,7 +2463,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. */ @@ -2412,20 +2473,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 { } @@ -2433,12 +2487,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. */ @@ -2450,14 +2504,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 { } @@ -2465,13 +2512,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. */ @@ -2480,13 +2527,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 { } @@ -2498,7 +2538,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. @@ -2524,7 +2564,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 { } @@ -2534,7 +2574,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. From 55003ff519734b298b7f05f21e41c6f62c9df561 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 16:21:57 +0800 Subject: [PATCH 30/40] Energy constant gauranteed on Store --- dist/screeps.d.ts | 4 +++- src/helpers.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index bdb5740..a77269b 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -782,7 +782,9 @@ interface SignDefinition { time: number; datetime: Date; } -declare type StoreDefinition = Record; +declare type StoreDefinition = Record & { + energy: number; +}; interface LookAtTypes { constructionSite?: ConstructionSite; creep?: Creep; diff --git a/src/helpers.ts b/src/helpers.ts index 37a7af3..26fc1fd 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -49,7 +49,7 @@ interface SignDefinition { } // TODO make sure this workes -type StoreDefinition = Record; +type StoreDefinition = Record & { energy: number }; // interface StoreDefinition { // [resource: string]: number | undefined; // energy?: number; From cd7f16c0dae142d832be3be7b198fdc400485e85 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 16:52:39 +0800 Subject: [PATCH 31/40] `find` functions can also return RoomPositions --- dist/screeps.d.ts | 10 +++++----- src/room-position.ts | 8 ++++---- src/room.ts | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index a77269b..2b8fac5 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -1572,7 +1572,7 @@ interface RoomPosition { * @param type See Room.find * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm */ - findClosestByPath(type: FindConstant, opts?: FindPathOpts & { + findClosestByPath(type: FindConstant, opts?: FindPathOpts & { filter?: any | string; algorithm?: string; }): T | null; @@ -1590,7 +1590,7 @@ interface RoomPosition { * @param type See Room.find. * @param opts */ - findClosestByRange(type: FindConstant, opts?: { + findClosestByRange(type: FindConstant, opts?: { filter: any | string; }): T | null; /** @@ -1607,7 +1607,7 @@ interface RoomPosition { * @param range The range distance. * @param opts See Room.find. */ - findInRange(type: FindConstant, range: number, opts?: { + findInRange(type: FindConstant, range: number, opts?: { filter?: any | string; }): T[]; /** @@ -1616,7 +1616,7 @@ interface RoomPosition { * @param range The range distance. * @param opts See Room.find. */ - findInRange(objects: T[], range: number, opts?: { + findInRange(objects: T[], range: number, opts?: { filter?: any | string; }): T[]; /** @@ -1879,7 +1879,7 @@ interface Room { * @param opts An object with additional options * @returns An array with the objects found. */ - find(type: FindConstant, opts?: { + find(type: FindConstant, opts?: { filter: Object | Function | string; }): T[]; /** diff --git a/src/room-position.ts b/src/room-position.ts index 3be298d..2a4b468 100644 --- a/src/room-position.ts +++ b/src/room-position.ts @@ -33,7 +33,7 @@ interface RoomPosition { * @param type See Room.find * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm */ - findClosestByPath(type: FindConstant, opts?: FindPathOpts & { filter?: any | string, algorithm?: string }): T | null; + 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. @@ -45,7 +45,7 @@ interface RoomPosition { * @param type See Room.find. * @param opts */ - findClosestByRange(type: FindConstant, opts?: { filter: any | string }): T | null; + 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. @@ -58,14 +58,14 @@ interface RoomPosition { * @param range The range distance. * @param opts See Room.find. */ - findInRange(type: FindConstant, 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[], 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. diff --git a/src/room.ts b/src/room.ts index bb05741..b8a1750 100644 --- a/src/room.ts +++ b/src/room.ts @@ -79,7 +79,7 @@ interface Room { * @param opts An object with additional options * @returns An array with the objects found. */ - find(type: FindConstant, 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. From ab047ae8710dd2dcc5198a22c08c5fabccca1f2c Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 18:10:27 +0800 Subject: [PATCH 32/40] Delete comments; Add missing direction constant return value --- dist/screeps.d.ts | 2 +- src/helpers.ts | 7 +------ src/room-position.ts | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index 2b8fac5..5614b98 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -1637,7 +1637,7 @@ interface RoomPosition { * @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. diff --git a/src/helpers.ts b/src/helpers.ts index 26fc1fd..c46c84f 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -48,13 +48,8 @@ interface SignDefinition { datetime: Date; } -// TODO make sure this workes type StoreDefinition = Record & { energy: number }; -// interface StoreDefinition { - // [resource: string]: number | undefined; - // energy?: number; - // power?: number; -// } + interface LookAtTypes { constructionSite?: ConstructionSite; creep?: Creep; diff --git a/src/room-position.ts b/src/room-position.ts index 2a4b468..28a6f8d 100644 --- a/src/room-position.ts +++ b/src/room-position.ts @@ -84,7 +84,7 @@ interface RoomPosition { * @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. From ab8326f307c6ca6df680126a45d1ee0df21ff1a2 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 18:45:03 +0800 Subject: [PATCH 33/40] Update Readme and package.json --- README.md | 168 ++++++++++++++++++--------------------------------- package.json | 6 +- 2 files changed, 62 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index defe914..4887512 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,69 @@ -# Screeps Typescript Declarations +# Typed-Screeps -> The repository for *Screep's* TypeScript type definitions. https://screeps.com/ - -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 +90,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/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" From e64ac07a300c5ab79fcb9912bf7ca65b38a087e3 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 20:49:34 +0800 Subject: [PATCH 34/40] Fix tuple / array ambiguity --- src/room-visual.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/room-visual.ts b/src/room-visual.ts index b974262..38cc8ac 100644 --- a/src/room-visual.ts +++ b/src/room-visual.ts @@ -73,7 +73,7 @@ declare class RoomVisual { * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - poly(points: [number, number | RoomPosition][], style?: PolyStyle): RoomVisual; + poly(points: Array<[number, number] | RoomPosition>, style?: PolyStyle): RoomVisual; /** * Draw a text label. From 273a9cd9e38d7a1d0f2315da42aaa97f46fe1d91 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 20:59:21 +0800 Subject: [PATCH 35/40] Compiled visuals changes --- dist/screeps.d.ts | 111 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 102 insertions(+), 9 deletions(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index 5614b98..fd81488 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -1712,13 +1712,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); + constructor(roomName?: string); + /** + * The name of the room. + */ + roomName: string; /** * Draw a line. * @param x1 The start X coordinate. @@ -1729,6 +1731,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. @@ -1737,6 +1747,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. @@ -1747,13 +1764,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. @@ -1763,6 +1789,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. @@ -1776,25 +1810,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; } /** @@ -1836,7 +1929,7 @@ interface Room { */ 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; /** From 4618f93b1bae518b6d5e0104586b115ae6943cd5 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 21:19:13 +0800 Subject: [PATCH 36/40] Map is typed --- dist/screeps.d.ts | 11 ++++++----- src/literals.ts | 6 ++++++ src/map.ts | 12 ++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index fd81488..437810f 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -947,6 +947,7 @@ 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 ExitConstant = FIND_EXIT_TOP | FIND_EXIT_RIGHT | FIND_EXIT_BOTTOM | FIND_EXIT_LEFT; 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_DROPPED_ENERGY | 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 FIND_EXIT_TOP = 1; declare type FIND_EXIT_RIGHT = 3; @@ -1109,7 +1110,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. @@ -1118,9 +1119,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. @@ -1136,12 +1137,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. diff --git a/src/literals.ts b/src/literals.ts index 897e3db..de1ea03 100644 --- a/src/literals.ts +++ b/src/literals.ts @@ -64,6 +64,12 @@ type CreepMoveReturnCode = //////// // Find Constants +type ExitConstant = + FIND_EXIT_TOP | + FIND_EXIT_RIGHT | + FIND_EXIT_BOTTOM | + FIND_EXIT_LEFT + type FindConstant = FIND_EXIT_TOP | FIND_EXIT_RIGHT | 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. From fff267177e585a1d81ba498e8d0462160d3c4051 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Thu, 25 May 2017 21:24:43 +0800 Subject: [PATCH 37/40] Make spacing more standard --- src/path-finder.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: From f180ac09f8566f71d58c5470d3bc3387d9eb7633 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Sat, 27 May 2017 08:44:26 +0800 Subject: [PATCH 38/40] Deprecate FIND_DROPPED_ENERGY --- src/constants.ts | 1 - src/literals.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 6844894..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; diff --git a/src/literals.ts b/src/literals.ts index 897e3db..a695378 100644 --- a/src/literals.ts +++ b/src/literals.ts @@ -76,7 +76,6 @@ type FindConstant = FIND_SOURCES_ACTIVE | FIND_SOURCES | FIND_DROPPED_RESOURCES | - FIND_DROPPED_ENERGY | FIND_STRUCTURES | FIND_MY_STRUCTURES | FIND_HOSTILE_STRUCTURES | @@ -100,7 +99,6 @@ type FIND_HOSTILE_CREEPS = 103; type FIND_SOURCES_ACTIVE = 104; type FIND_SOURCES = 105; type FIND_DROPPED_RESOURCES = 106; -type FIND_DROPPED_ENERGY = 106; // Yup, it's 106. type FIND_STRUCTURES = 107; type FIND_MY_STRUCTURES = 108; type FIND_HOSTILE_STRUCTURES = 109; From 0375365fdc28a2b7d37d041ab2a28eb9cc360242 Mon Sep 17 00:00:00 2001 From: Bryan Becker Date: Sat, 27 May 2017 08:47:02 +0800 Subject: [PATCH 39/40] Compile changes --- dist/screeps.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index fd81488..76398d2 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; @@ -947,7 +946,7 @@ 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_DROPPED_ENERGY | 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 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 FIND_EXIT_TOP = 1; declare type FIND_EXIT_RIGHT = 3; declare type FIND_EXIT_BOTTOM = 5; @@ -959,7 +958,6 @@ 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_DROPPED_ENERGY = 106; declare type FIND_STRUCTURES = 107; declare type FIND_MY_STRUCTURES = 108; declare type FIND_HOSTILE_STRUCTURES = 109; From 3830511900b585d2b31a86dbbb7780014cf25259 Mon Sep 17 00:00:00 2001 From: Bryan Date: Sun, 28 May 2017 10:25:54 +0800 Subject: [PATCH 40/40] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4887512..5de471d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +** This repo has been moved to [typed-screeps](https://github.com/bryanbecker/typed-screeps) ** + # Typed-Screeps > The forked repository for **strong** *Screep's* TypeScript type definitions. https://screeps.com/