Skip to content

Added Game.shard interface #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 92 additions & 21 deletions dist/screeps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ 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;
/** @deprecated FIND_DROPPED_ENERGY constant is considered deprecated and will be removed soon. Please use FIND_DROPPED_RESOURCES instead. */
declare const FIND_DROPPED_ENERGY: typeof FIND_DROPPED_RESOURCES;
declare const FIND_STRUCTURES: 107;
declare const FIND_MY_STRUCTURES: 108;
declare const FIND_HOSTILE_STRUCTURES: 109;
Expand Down Expand Up @@ -356,6 +357,17 @@ declare const LOOK_NUKES: "nuke";
declare const LOOK_TERRAIN: "terrain";
declare const ORDER_SELL: "sell";
declare const ORDER_BUY: "buy";
declare const PORTAL_UNSTABLE: number;
declare const PORTAL_MIN_TIMEOUT: number;
declare const PORTAL_MAX_TIMEOUT: number;
declare const POWER_BANK_RESPAWN_TIME: number;
declare const INVADERS_ENERGY_GOAL: number;
declare const SYSTEM_USERNAME: 'Screeps';
declare const SIGN_NOVICE_AREA: 'A new Novice Area is being planned somewhere in this sector. Please make sure all important rooms are reserved.';
declare const SIGN_RESPAWN_AREA: 'A new Respawn Area is being planned somewhere in this sector. Please make sure all important rooms are reserved.';
declare const PORTAL_DECAY: number;
declare const MARKET_FEE: number;
declare const FLAGS_LIMIT: number;
/**
* A site of a structure which is currently under construction.
*/
Expand Down Expand Up @@ -738,6 +750,10 @@ interface Game {
rooms: {
[roomName: string]: Room;
};
/**
* An object describing the world shard where your script is currently being executed in.
*/
shard: Shard;
/**
* A hash containing all your spawns with spawn names as hash keys.
*/
Expand Down Expand Up @@ -819,7 +835,7 @@ interface SignDefinition {
}
interface StoreDefinition {
[resource: string]: number | undefined;
energy?: number;
energy: number;
power?: number;
}
interface LookAtResultWithPos {
Expand Down Expand Up @@ -853,6 +869,39 @@ interface LookAtResult {
interface LookAtResultMatrix {
[coord: number]: LookAtResultMatrix | LookAtResult[];
}
interface PointLike {
x: number;
y: number;
}
interface RoomPositionLike extends PointLike {
roomName: string;
}
interface RoomObjectLike {
pos: RoomPositionLike;
}
interface Shard {
/**
* The name of the shard.
*
* @type {string}
* @memberof Shard
*/
name: string;
/**
* Currently always equals to `normal`.
*
* @type {"normal"}
* @memberof Shard
*/
type: "normal";
/**
* Whether this shard belongs to the PTR.
*
* @type {boolean}
* @memberof Shard
*/
ptr: boolean;
}
interface FindPathOpts {
/**
* Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default
Expand Down Expand Up @@ -1154,19 +1203,27 @@ interface OrderFilter {
remainingAmount?: number;
price?: number;
}
interface RoomMemory {
}
interface FlagMemory {
}
interface SpawnMemory {
}
interface CreepMemory {
}
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;
};
}
/**
Expand Down Expand Up @@ -1361,7 +1418,9 @@ interface RawMemory {
* An object with asynchronous memory segments available on this tick. Each object key is the segment ID with data in string values.
* Use RawMemory.setActiveSegments to fetch segments on the next tick. Segments data is saved automatically in the end of the tick.
*/
segments: string[];
segments: {
[id: number]: string;
};
/**
* An object with a memory segment of another player available on this tick.
* Use setActiveForeignSegment to fetch segments on the next tick. The object consists of the following properties:
Expand Down Expand Up @@ -1629,14 +1688,10 @@ interface RoomPositionConstructor extends _Constructor<RoomPosition> {
(x: number, y: number, roomName: string): RoomPosition;
}
declare const RoomPosition: RoomPositionConstructor;
declare class RoomVisual {
interface 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.
*/
constructor(roomName: string);
/** Undefined when this instance is not specific to any one room */
roomName?: string;
/**
* Draw a line.
* @param x1 The start X coordinate.
Expand All @@ -1654,7 +1709,7 @@ declare class RoomVisual {
* @param style The (optional) style.
* @returns The RoomVisual object, for chaining.
*/
line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyle): RoomVisual;
line(pos1: PointLike, pos2: PointLike, style?: LineStyle): RoomVisual;
/**
* Draw a circle.
* @param x The X coordinate of the center.
Expand All @@ -1669,7 +1724,7 @@ declare class RoomVisual {
* @param style The (optional) style.
* @returns The RoomVisual object, for chaining.
*/
circle(pos: RoomPosition, style?: CircleStyle): RoomVisual;
circle(pos: PointLike, style?: CircleStyle): RoomVisual;
/**
* Draw a rectangle.
* @param x The X coordinate of the top-left corner.
Expand All @@ -1688,14 +1743,14 @@ declare class RoomVisual {
* @param style The (optional) style.
* @returns The RoomVisual object, for chaining.
*/
rect(topLeftPos: RoomPosition, width: number, height: number, style?: PolyStyle): RoomVisual;
rect(topLeftPos: PointLike, 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 style The (optional) style.
* @returns The RoomVisual object, for chaining.
*/
poly(points: [number, number][], style?: PolyStyle): RoomVisual;
poly(points: Array<[number, number] | PointLike>, style?: PolyStyle): RoomVisual;
/**
* Draw a text label.
* @param text The text message.
Expand All @@ -1712,7 +1767,7 @@ declare class RoomVisual {
* @param style The (optional) text style.
* @returns The RoomVisual object, for chaining.
*/
text(text: string, pos: RoomPosition, style?: TextStyle): RoomVisual;
text(text: string, pos: PointLike, style?: TextStyle): RoomVisual;
/**
* Remove all visuals from the room.
* @returns The RoomVisual object, for chaining.
Expand All @@ -1725,6 +1780,12 @@ declare class RoomVisual {
*/
getSize(): number;
}
interface GlobalRoomVisual extends RoomVisual {
roomName: undefined;
}
interface RoomSpecificRoomVisual<TRoomName extends string> extends RoomVisual {
roomName: TRoomName;
}
interface LineStyle {
width?: number;
color?: string;
Expand All @@ -1747,6 +1808,16 @@ interface TextStyle {
align?: "center" | "left" | "right";
opacity?: number;
}
interface RoomVisualConstructor {
/**
* You can directly create new RoomVisual object in any room, even if it's invisible to your script.
* @param roomName The room name.
*/
new (roomName: string): RoomSpecificRoomVisual<typeof roomName>;
/** Create a new global RoomVisual instance */
new (): GlobalRoomVisual;
}
declare const RoomVisual: RoomVisualConstructor;
/**
* 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.
*/
Expand Down Expand Up @@ -2533,7 +2604,7 @@ interface StructureTerminal extends OwnedStructure {
/**
* 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.
*/
Expand Down Expand Up @@ -2566,7 +2637,7 @@ interface StructureContainer extends Structure {
* 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.
*/
Expand Down
19 changes: 18 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ 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.

/** @deprecated FIND_DROPPED_ENERGY constant is considered deprecated and will be removed soon. Please use FIND_DROPPED_RESOURCES instead. */
declare const FIND_DROPPED_ENERGY: typeof FIND_DROPPED_RESOURCES;

declare const FIND_STRUCTURES: 107;
declare const FIND_MY_STRUCTURES: 108;
declare const FIND_HOSTILE_STRUCTURES: 109;
Expand Down Expand Up @@ -395,3 +398,17 @@ declare const LOOK_TERRAIN: "terrain";

declare const ORDER_SELL: "sell";
declare const ORDER_BUY: "buy";

declare const PORTAL_UNSTABLE: number;
declare const PORTAL_MIN_TIMEOUT: number;
declare const PORTAL_MAX_TIMEOUT: number;
declare const POWER_BANK_RESPAWN_TIME: number;
declare const INVADERS_ENERGY_GOAL: number;
declare const SYSTEM_USERNAME: 'Screeps';
declare const SIGN_NOVICE_AREA: 'A new Novice Area is being planned somewhere in this sector. Please make sure all important rooms are reserved.';
declare const SIGN_RESPAWN_AREA: 'A new Respawn Area is being planned somewhere in this sector. Please make sure all important rooms are reserved.';


declare const PORTAL_DECAY: number;
declare const MARKET_FEE: number;
declare const FLAGS_LIMIT: number;
4 changes: 4 additions & 0 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ interface Game {
* A hash containing all the rooms available to you with room names as hash keys.
*/
rooms: {[roomName: string]: Room};
/**
* An object describing the world shard where your script is currently being executed in.
*/
shard: Shard;
/**
* A hash containing all your spawns with spawn names as hash keys.
*/
Expand Down
39 changes: 38 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface SignDefinition {
}
interface StoreDefinition {
[resource: string]: number | undefined;
energy?: number;
energy: number;
power?: number;
}

Expand Down Expand Up @@ -85,6 +85,43 @@ interface LookAtResultMatrix {
[coord: number]: LookAtResultMatrix|LookAtResult[]
}


interface PointLike {
x: number;
y: number;
}

interface RoomPositionLike extends PointLike {
roomName: string;
}

interface RoomObjectLike {
pos: RoomPositionLike;
}
interface Shard {
/**
* The name of the shard.
*
* @type {string}
* @memberof Shard
*/
name: string;
/**
* Currently always equals to `normal`.
*
* @type {"normal"}
* @memberof Shard
*/
type: "normal";
/**
* Whether this shard belongs to the PTR.
*
* @type {boolean}
* @memberof Shard
*/
ptr: boolean;
}

interface FindPathOpts {
/**
* Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default
Expand Down
26 changes: 21 additions & 5 deletions src/memory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
interface RoomMemory {

}

interface FlagMemory {

}

interface SpawnMemory {

}

interface CreepMemory {

}

interface Memory {
[name: string]: any;
creeps: {[name: string]: any};
flags: {[name: string]: any};
rooms: {[name: string]: any};
spawns: {[name: string]: any};
[name: string]: any;
creeps: {[name: string]: CreepMemory};
flags: {[name: string]: FlagMemory};
rooms: {[name: string]: RoomMemory};
spawns: {[name: string]: SpawnMemory};
}
2 changes: 1 addition & 1 deletion src/raw-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface RawMemory {
* An object with asynchronous memory segments available on this tick. Each object key is the segment ID with data in string values.
* Use RawMemory.setActiveSegments to fetch segments on the next tick. Segments data is saved automatically in the end of the tick.
*/
segments: string[];
segments: { [id: number]: string };
/**
* An object with a memory segment of another player available on this tick.
* Use setActiveForeignSegment to fetch segments on the next tick. The object consists of the following properties:
Expand Down
Loading