-
Notifications
You must be signed in to change notification settings - Fork 104
/
Room.js
469 lines (441 loc) · 19.8 KB
/
Room.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
/**
* 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.
*
* @class
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room}
*/
Room = {
/**
* Serialize a path array into a short string representation, which is suitable to store in memory.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#serializePath}
*
* @type {function}
*
* @param {Array} path A path array retrieved from Room.findPath.
*
* @return {string} A serialized string form of the given path.
*/
serializePath: function(path) { },
/**
* Deserialize a short string path representation into an array form.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#deserializePath}
*
* @type {function}
*
* @param {string} path A serialized path string.
*
* return {Array} A path array.
*/
deserializePath: function(path) { },
};
Room.prototype =
{
/**
* The Controller structure of this room, if present, otherwise undefined.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#controller}
*
* @type {undefined|StructureController}
*/
controller: null,
/**
* Total amount of energy available in all spawns and extensions in the room.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#energyAvailable}
*
* @type {number}
*/
energyAvailable: 0,
/**
* Total amount of energyCapacity of all spawns and extensions in the room.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#energyCapacityAvailable}
*
* @type {number}
*/
energyCapacityAvailable: 0,
/**
* A shorthand to Memory.rooms[room.name].
* You can use it for quick access the room’s specific memory data object.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#memory}
*
* @type {RoomMemory}
*/
memory: {},
/**
* The mode of the room
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#mode}
*
* @type {string|MODE_SIMULATION|MODE_SURVIVAL|MODE_WORLD|MODE_ARENA}
*/
mode: "",
/**
* The name of the room.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#name}
*
* @type {string}
*/
name: "",
/**
* The Storage structure of this room, if present, otherwise undefined.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#storage}
*
* @type {undefined|StructureStorage}
*/
storage: null,
/**
* The Terminal structure of this room, if present, otherwise undefined.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#terminal}
*
* @type {undefined|StructureTerminal}
*/
terminal: null,
/**
* A RoomVisual object for this room. You can use this object to draw simple shapes (lines, circles, text labels) in the room.
* @see {@link http://docs.screeps.com/api/#Room.visual}
*
* @type {RoomVisual}
*/
visual: null,
/**
* Create new ConstructionSite at the specified location.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#createConstructionSite}
*
* @type {function}
*
* @param {number|RoomPosition|RoomObject} x The X position.
* @param {number|string} [y] The Y position.
* @param {string} [structureType] One of the STRUCTURE_* constants.
*
* @note Alternative function: createConstructionSite(pos, structureType)
* @param {object} pos Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {number|OK|ERR_INVALID_TARGET|ERR_FULL|ERR_INVALID_ARGS|ERR_RCL_NOT_ENOUGH}
*/
createConstructionSite: function(x, y, structureType) { },
/**
* Create new Flag at the specified location.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#createFlag}
*
* @type {function}
*
* @param {number|RoomPosition|RoomObject} x The X position.
* @param {number|string} y The Y position.
* @param {string|string} [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 {string} [color] The color of a new flag. Should be one of the COLOR_* constants. The default value is COLOR_WHITE.
* @param {string} [secondaryColor] The secondary color of a new flag. Should be one of the COLOR_* constants. The default value is equal to color.
*
* @note Alternative function: createConstructionSite(pos, name, color, secondaryColor)
* @param {object} pos Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {number|ERR_NAME_EXISTS|ERR_INVALID_ARGS}
*/
createFlag: function(x, y, name, color, secondaryColor) { },
/**
* Find all objects of the specified type in the room.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#find}
*
* @type {function}
*
* @param {number} type One of the FIND_* constants.
* @param {object} [opts] An object with additional options
* @param {object|function|string} [opts.filter] The result list will be filtered using the Lodash.filter method.
*
* @return {Array} An array with the objects found.
*/
find: function(type, opts) { },
/**
* Find the exit direction en route to another room.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#findExitTo}
*
* @type {function}
*
* @param {string|Room} room Another room name or room object.
*
* @return {FIND_EXIT_TOP|FIND_EXIT_RIGHT|FIND_EXIT_BOTTOM|FIND_EXIT_LEFT|number|ERR_NO_PATH|ERR_INVALID_ARGS}
*/
findExitTo: function(room) { },
/**
* Find an optimal path inside the room between fromPos and toPos using A* search algorithm.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#findPath}
*
* @type {function}
*
* @param {RoomPosition} fromPos The start position.
* @param {RoomPosition} toPos The end position.
* @param {object} [opts] An object containing additonal pathfinding flags
* @param {boolean} [opts.ignoreCreeps] Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default value is false.
* @param {boolean} [opts.ignoreDestructibleStructures] Treat squares with destructible structures (constructed walls, ramparts, spawns, extensions) as walkable. Use this flag when you need to move through a territory blocked by hostile structures. If a creep with an ATTACK body part steps on such a square, it automatically attacks the structure. The default value is false.
* @param {boolean} [opts.ignoreRoads] Ignore road structures. Enabling this option can speed up the search. The default value is false. This is only used when the new PathFinder is enabled.
* @param {function(string, CostMatrix)} [opts.costCallback] You can use this callback to modify a CostMatrix for any room during the search. The callback accepts two arguments, roomName and costMatrix. Use the costMatrix instance to make changes to the positions costs. If you return a new matrix from this callback, it will be used instead of the built-in cached one. This option is only used when the new PathFinder is enabled.
* @param {Array} [opts.ignore] 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).
* @param {Array} [opts.avoid] 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).
* @param {number} [opts.maxOps] The maximum limit of possible pathfinding operations. You can limit CPU time used for the search based on ratio 1 op ~ 0.001 CPU. The default value is 2000.
* @param {number} [opts.heuristicWeight] Weight to apply to the heuristic in the A* formula F = G + weight * H. Use this option only if you understand the underlying A* algorithm mechanics! The default value is 1.2.
* @param {boolean} [opts.serialize] If true, the result path will be serialized using Room.serializePath. The default is false.
* @param {number} [opts.maxRooms] The maximum allowed rooms to search. The default (and maximum) is 16. This is only used when the new PathFinder is enabled.
* @param {number} [opts.range] Find a path to a position in specified linear range of target. The default is 0.
* @param {number} [opts.plainCost] Cost for walking on plain positions. The default is 1.
* @param {number} [opts.swampCost] Cost for walking on swamp positions. The default is 5.
*
* @return {Array} An array with path steps in the following format:
[
{ x: 10, y: 5, dx: 1, dy: 0, direction: RIGHT },
{ x: 10, y: 6, dx: 0, dy: 1, direction: BOTTOM },
{ x: 9, y: 7, dx: -1, dy: 1, direction: BOTTOM_LEFT },
...
]
*/
findPath: function(fromPos, toPos, opts) { },
/**
* Returns an array of events happened on the previous tick in this room.
*
* @see {@link https://docs.screeps.com/api/#Room.getEventLog}
*
* @type {function}
*
* @param {raw} [raw] If this parameter is false or undefined, the method returns an object parsed using JSON.parse which incurs some CPU cost on the first access (the return value is cached on subsequent calls). If raw is truthy, then raw JSON in string format is returned.
*
* @return An array of events. Each event represents some game action in the following format:
{
event: EVENT_ATTACK,
objectId: '54bff72ab32a10f73a57d017',
data: { ... }
}
*/
getEventLog: function(raw) { },
/**
* Creates a RoomPosition object at the specified location.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#getPositionAt}
*
* @type {function}
*
* @param {number} x The X position.
* @param {number} y The Y position.
*
* @return {null|RoomPosition}
*/
getPositionAt: function(x, y) { },
/**
* Get a Room.Terrain object which provides fast access to static terrain data. This method works for any room in the world even if you have no access to it.
*
* @see {@link https://docs.screeps.com/api/#Room.getTerrain}
*
* @type {function}
*
* @return {Room.Terrain} Returns new Room.Terrain object.
*/
getTerrain: function() {},
/**
* Get the list of objects at the specified room position.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#lookAt}
*
* @type {function}
*
* @param {number} x X position in the room.
* @param {number|RoomPosition|RoomObject} [y] Y position in the room.
*
* @note Alternative function: lookAt(target)
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {Array} An array with objects at the specified position in the following format:
[
{ type: 'creep', creep: {...} },
{ type: 'structure', structure: {...} },
...
{ type: 'terrain', terrain: 'swamp' }
]
*/
lookAt: function(x, y) { },
/**
* Get the list of objects at the specified room area.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#lookAtArea}
*
* @type {function}
*
* @param {number} top The top Y boundary of the area.
* @param {number} left The left X boundary of the area.
* @param {number} bottom The bottom Y boundary of the area.
* @param {number} right The right X boundary of the area.
* @param {boolean} [asArray] Set to true if you want to get the result as a plain array.
*
* @return {object} An object with all the objects in the specified area in the following format:
// 10,5,11,7
{
10 :
{
5 :
[
{
type : 'creep',
creep :
{
...
}
},
{
type : 'terrain',
terrain : 'swamp'
}
],
6 :
[
{
type : 'terrain',
terrain : 'swamp'
}
],
7 :
[
{
type : 'terrain',
terrain : 'swamp'
}
]
},
11 :
{
5 :
[
{
type : 'terrain',
terrain : 'normal'
}
],
6 :
[
{
type : 'structure',
structure :
{
...
}
},
{
type : 'terrain',
terrain : 'swamp'
}
],
7 :
[
{
type : 'terrain',
terrain : 'wall'
}
]
}
}
*/
lookAtArea: function(top, left, bottom, right, asArray) { },
/**
* Get an object with the given type at the specified room position.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#lookForAt}
*
* @type {function}
*
* @param {string} type One of the LOOK_* constants.
* @param {number|RoomPosition|RoomObject} x X position in the room.
* @param {number} [y] Y position in the room.
*
* @note Alternative function: lookForAt(type, target)
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {Array} An array of objects of the given type at the specified position if found.
*/
lookForAt: function(type, x, y) { },
/**
* Get the list of objects with the given type at the specified room area.
*
* @see {@link http://support.screeps.com/hc/en-us/articles/203079011-Room#lookForAtArea}
*
* @type {function}
*
* @param {string} type One of the LOOK_* constants.
* @param {number} top The top Y boundary of the area.
* @param {number} left The left X boundary of the area.
* @param {number} bottom The bottom Y boundary of the area.
* @param {number} right The right X boundary of the area.
* @param {boolean} [asArray] Set to true if you want to get the result as a plain array.
*
* @return {object} An object with all the objects of the given type in the specified area in the following format:
//10,5,11,7
{
10:
{
5: [{...}],
6: undefined,
7: undefined
},
11:
{
5: undefined,
6: [{...}, {...}],
7: undefined
}
}
*/
lookForAtArea: function(type, top, left, bottom, right, asArray) { },
};
/**
* An object which provides fast access to room terrain data. These objects can be constructed for any room in the world even if you have no access to it.
*
* Technically every Room.Terrain object is a very lightweight adapter to underlying static terrain buffers with corresponding minimal accessors.
*
* @param {string} roomName The room name.
*
* @class
* @constructor
*
* @see {@link https://docs.screeps.com/api/#Room-Terrain}
*/
Room.Terrain = function(roomName) {},
Room.Terrain.prototype = {
/**
* Get terrain type at the specified room position by (x,y) coordinates. Unlike the Game.map.getTerrainAt(...) method, this one doesn't perform any string operations and returns integer terrain type values (see below).
*
* @see {@link https://docs.screeps.com/api/#Room.Terrain.get}
*
* @type {function}
*
* @param {number} x X position in the room.
* @param {number} y Y position in the room.
*
* @return {0|TERRAIN_MASK_WALL|TERRAIN_MASK_SWAMP} An integer value. 0 if Plain.
*/
get: function(x, y) {},
/**
* Get copy of underlying static terrain buffer. Current underlying representation is Uint8Array.
*
* @note WARNING: this method relies on underlying representation of terrain data. This is the fastest way to obtain terrain data of the whole room (2500 tiles), but users should keep in mind that it can be marked as deprecated anytime in the future, or return value type can be changed due to underlying data representation changing.
*
* @see {@link https://docs.screeps.com/api/#Room.Terrain.getRawBuffer}
*
* @type {function}
*
* @param {Array} [destinationArray] A typed array view in which terrain will be copied to.
*
* @return {Array|ERR_INVALID_ARGS} Copy of underlying room terrain representations as a new Uint8Array typed array of size 2500.
Each element is an integer number, terrain type can be obtained by applying bitwise AND (&) operator with appropriate TERRAIN_MASK_* constant. Room tiles are stored row by row.
If destinationArray is specified, function returns reference to this filled destinationArray if coping succeeded, or error code otherwise:
*/
getRawBuffer: function(destinationArray) {},
};