forked from Garethp/ScreepsAutocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoomPosition.js
242 lines (224 loc) · 8.78 KB
/
RoomPosition.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
/**
* An object representing the specified position in the room.
* Every object in the room contains RoomPosition as the pos property.
* The position object of a custom location can be obtained using the Room.getPositionAt() method or using the constructor.
*
* @param {number} x X position in the room.
* @param {number} y Y position in the room.
* @param {string} roomName The room name.
*
* @class
* @constructor
*/
RoomPosition = function(x, y, roomName) { };
RoomPosition.prototype =
{
/**
* The name of the room.
*
* @type {string}
*/
roomName: "",
/**
* X position in the room.
*
* @type {number}
*/
x: 0,
/**
* Y position in the room.
*
* @type {number}
*/
y: 0,
/**
* Create new ConstructionSite at the specified location.
*
* @type {function}
*
* @param {string} structureType One of the STRUCTURE_* constants.
*
* @return {number|OK|ERR_INVALID_TARGET|ERR_FULL|ERR_INVALID_ARGS|ERR_RCL_NOT_ENOUGH}
*/
createConstructionSite: function(structureType) { },
/**
* Create new Flag at the specified location.
*
* @type {function}
*
* @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] 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.
*
* @return {string|number|ERR_NAME_EXISTS|ERR_INVALID_ARGS}
*/
createFlag: function(name, color, secondaryColor) { },
/**
* Find an object with the shortest path from the given position.
* Uses A* search algorithm and Dijkstra's algorithm.
*
* @type {function}
*
* @param {number|Array<RoomPosition>|Array<RoomObject>} type See Room.find.
* @param {object} [opts] An object containing pathfinding options (see Room.findPath)
* @param {object|function|string} [opts.filter] Only the objects which pass the filter using the Lodash.filter method will be used.
* @param {string} [opts.algorithm] One of the following constants:
astar is faster when there are relatively few possible targets;
dijkstra is faster when there are a lot of possible targets or when the closest target is nearby.
The default value is determined automatically using heuristics.
* @note Alternative function: findClosestByPath: function(objects, opts)
* @param {array} objects An array of room's objects or RoomPosition objects that the search should be executed against.
* @return {object|null} The closest object if found, null otherwise.
*/
findClosestByPath: function(type, opts) { },
/**
* Find an object with the shortest linear distance from the given position.
*
* @type {function}
*
* @param {number|Array<RoomPosition>|Array<RoomObject>} type See Room.find.
* @param {object} [opts]
* @param {object|function|string} [opts.filter] Only the objects which pass the filter using the Lodash.filter method will be used.
*
* @note Alterative function: findClosestByRange: function(objects, opts)
* @param {array} objects An array of room's objects or RoomPosition objects that the search should be executed against.
*
* @return {object|null} The closest object if found, null otherwise.
*/
findClosestByRange: function(type, opts) { },
/**
* Find all objects in the specified linear range.
*
* @type {function}
*
* @param {number|Array<RoomPosition>|Array<RoomObject>} type See Room.find.
* @param {number} range The range distance.
* @param {object} [opts] See Room.find.
*
* @note Alternative function: findInRange(objects, range, opts)
* @param {array} objects An array of room's objects or RoomPosition objects that the search should be executed against.
*
* @return {array} An array with the objects found.
*/
findInRange: function(type, range, opts) { },
/**
* 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.
*
* @type {function}
*
* @param {number|RoomPosition|RoomObject} x X position in the room.
* @param {number} [y] Y position in the room.
* @param {object} [opts] An object containing pathfinding options flags (see Room.findPath for more details).
*
* @note Alternative function: findPathTo(target, opts)
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @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 },
...
]
*/
findPathTo: function(x, y, opts) { },
/**
* Get linear direction to the specified position.
*
* @type {function}
*
* @param {number|RoomPosition|RoomObject} x X position in the room.
* @param {number} [y] Y position in the room.
*
* @note Alternative function: getDirectionTo(target)
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {number|TOP|TOP_RIGHT|RIGHT|BOTTOM_RIGHT|BOTTOM|BOTTOM_LEFT|LEFT|TOP_LEFT} A number representing one of the direction constants.
*/
getDirectionTo: function(x, y) { },
/**
* Get linear range to the specified position.
*
* @type {function}
*
* @param {number|RoomPosition|RoomObject} x X position in the room.
* @param {number} [y] Y position in the room.
*
* @note Alternative function: getRangeTo(target)
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {number} A number of squares to the given position.
*/
getRangeTo: function(x, y) { },
/**
* Check whether this position is in the given range of another position.
*
* @type {function}
*
* @param {number|RoomPosition|RoomObject} x X position in the room.
* @param {number} [y] Y position in the room.
* @param {number} range The range distance.
*
*
* @note Alternative function: inRangeTo(target, range)
* @param {RoomPosition} target The target position.
*
* @return {boolean}
*/
inRangeTo: function(x, y, range) { },
/**
* Check whether this position is the same as the specified position.
*
* @type {function}
*
* @param {number|RoomPosition|RoomObject} x X position in the room.
* @param {number} [y] Y position in the room.
*
* @note Alternative function: isEqualTo(target)
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {boolean}
*/
isEqualTo: function(x, y) { },
/**
* Check whether this position is on the adjacent square to the specified position.
* The same as inRangeTo(target, 1)
*
* @type {function}
*
* @param {number|RoomPosition|RoomObject} x X position in the room.
* @param {number} [y] Y position in the room.
*
* @note Alternative function: isNearTo(target)
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {boolean}
*/
isNearTo: function(x, y) { },
/**
* Get the list of objects at the specified room position.
*
* @type {function}
*
* @return {array} An array with objects at the specified position in the following format:
[
{ type: 'creep', creep: {...} },
{ type: 'structure', structure: {...} },
...
{ type: 'terrain', terrain: 'swamp' }
]
*/
look: function() { },
/**
* Get an object with the given type at the specified room position.
*
* @type {function}
*
* @param {string} type One of the LOOK_* constants.
*
* @return {array} An array of objects of the given type at the specified position if found.
*/
lookFor: function(type) { }
};