forked from Garethp/ScreepsAutocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoom.js
292 lines (269 loc) · 11.1 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
/**
* 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
* @constructor
*/
Room = function() { };
Room.prototype = {
/**
* The Controller structure of this room, if present, otherwise undefined.
*
* @type {Structure}
*/
controller: null,
/**
* Total amount of energy available in all spawns and extensions in the room.
*
* @type {number}
*/
energyAvailable: 0,
/**
* Total amount of energyCapacity of all spawns and extensions in the room.
*
* @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.
*
* @type {object}
*/
memory: null,
/**
* The current gamemode.
*
* @type {string|MODE_SIMULATION|MODE_SURVIVAL|MODE_WORLD|MODE_ARENA}
*/
mode: "",
/**
* The name of the room.
*
* @type {string}
*/
name: "",
/**
* The Storage structure of this room, if present, otherwise undefined.
*
* @type {Structure}
*/
storage: null,
/**
* An object with survival game info.
*
* @type {object}
*/
survivalInfo: {
/**
* Current score.
*
* @type {number}
*/
score: 0,
/**
* Time to the next wave of invaders.
*
* @type {number}
*/
timeToWave: 0,
/**
* The number of the next wave.
*
* @type {number}
*/
wave: 0
},
/**
* Serialize a path array into a short string representation, which is suitable to store in memory.
* @static
*
* @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.
* @static
*
* @param {string} path A serialized path string.
*
* @return {Array} A path array.
*/
deserializePath: function(path) { },
/**
* Create new ConstructionSite at the specified location.
*
* @param {number} x The X position.
* @param {number} y The Y position.
* @param {string|STRUCTURE_EXTENSION|STRUCTURE_RAMPART|STRUCTURE_ROAD|STRUCTURE_SPAWN|STRUCTURE_WALL|STRUCTURE_LINK} structureType
*
* @note Another variant of this function is createConstructionSite(pos, structureType) where:
* @param {object} pos Can be a RoomPosition object or any object containing RoomPosition.
*
* @note A maximum of 100 construction sites per player.
*
* @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.
*
* @param {number} x The X position.
* @param {number} y The Y position.
* @param {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_WHITE|COLOR_GREY|COLOR_RED|COLOR_PURPLE|COLOR_BLUE|COLOR_CYAN|COLOR_GREEN|COLOR_YELLOW|COLOR_ORANGE|COLOR_BROWN} [color] The color of a new flag. Default value is COLOR_WHITE.
*
* @note Another variant of the function is createFlag(pos, name, color) where:
* @param {object} pos Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {string|number|ERR_NAME_EXISTS|ERR_INVALID_ARGS} The name of the new flag or an error constant.
*/
createFlag: function(x, y, name, color) { },
/**
* Find all objects of the specified type in the room.
*
* @param {number|FIND_CREEPS|FIND_MY_CREEPS|FIND_HOSTILE_CREEPS|FIND_MY_SPAWNS|FIND_HOSTILE_SPAWNS|FIND_SOURCES|FIND_SOURCES_ACTIVE|FIND_DROPPED_RESOURCES|
* FIND_STRUCTURES|FIND_MY_STRUCTURES|FIND_HOSTILE_STRUCTURES|FIND_FLAGS|FIND_CONSTRUCTION_SITES|FIND_MY_CONSTRUCTION_SITES|FIND_EXIT_TOP|FIND_EXIT_RIGHT|
* FIND_EXIT_BOTTOM|FIND_EXIT_LEFT|FIND_EXIT} type
* @param {object} [opts]
* @param {object|function|string} [opts.filter] The result list will be filtered using the Lodash.filter method.
*
* @return {object[]}
*/
find: function(type, opts) { },
/**
* Find the exit direction en route to another room.
*
* @param {string|Room} room Another room name or room object.
*
* @return {number|FIND_EXIT_TOP|FIND_EXIT_RIGHT|FIND_EXIT_BOTTOM|FIND_EXIT_LEFT|ERR_NO_PATH|ERR_INVALID_ARGS} A room direction constant or an error constant.
*/
findExitTo: function(room) { },
/**
* Find an optimal path inside the room between fromPos and toPos using A* search algorithm.
*
* @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 {Array} [opts.ignore] An array of the room's objects or RoomPosition objects which should be treated as walkable tiles during the search.
* @param {Array} [opts.avoid] An array of the room's objects or RoomPosition objects which should be treated as obstacles during the search.
* @param {number} [opts.maxOps] The maximum limit of possible pathfinding operations. The greater the value, the more accurate path will be found, but more CPU time could be used.
* The default value is 2000.
* @param {number} [opts.heuristicWeight] Weight to apply to the heuristic to allow for suboptimal paths (for example, not using the roads or going through swamps),
* in order to speed up the search. Set any large value (say, 1000) in order to ignore terrain costs.
* The default value is 1.
* @param {boolean} [opts.serialize] If true, the result path will be serialized using Room.serializePath. The default is false.
*
* @return {object[]} 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) { },
/**
* Creates a RoomPosition object at the specified location.
*
* @param {number} x The X position.
* @param {number} y The Y position.
*
* @return {RoomPosition|null} A RoomPosition object or null if it cannot be obtained.
*/
getPositionAt: function(x, y) { },
/**
* Get the list of objects at the specified room position.
*
* @param {number} x X position in the room.
* @param {number} y Y position in the room.
*
* @note Another variant of the function is lookAt(target) where:
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {object[]} 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.
*
* @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.
*
* @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) { },
/**
* Get an object with the given type at the specified room position.
*
* @param {string} type One of the following string constants: constructionSite, creep, exit, flag, resource, source, structure, terrain
* @param {number} x X position in the room.
* @param {number} y Y position in the room.
*
* @note Another variant of the function is lookForAt(type, target) where:
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {object[]} 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.
*
* @param {string} type One of the following string constants: constructionSite, creep, exit, flag, resource, source, structure, terrain
* @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.
*
* @return {object} An object with all the objects of the given type in the specified area in the following format:
*
*<pre>// 10,5,11,7
*{
* 10: {
* 5: [{...}],
* 6: undefined,
* 7: undefined
* },
* 11: {
* 5: undefined,
* 6: [{...}, {...}],
* 7: undefined
* }
*}</pre>
*/
lookForAtArea: function(type, top, left, bottom, right) { }
};