forked from Garethp/ScreepsAutocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoomPosition.js
210 lines (194 loc) · 8.03 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
/**
* An object representing the specified position in the room.
* Every object in the room contains RoomPosition as the pos property.
*
* @note 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.
* @constructor
* @class
*/
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.
*
* @param {string|STRUCTURE_EXTENSION|STRUCTURE_RAMPART|STRUCTURE_ROAD|STRUCTURE_SPAWN|STRUCTURE_WALL|STRUCTURE_LINK} structureType
*
* @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.
*
* @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 is COLOR_WHITE.
*
* @return {string|ERR_NAME_EXISTS|ERR_INVALID_ARGS} The name of a new flag or an error constant.
*/
createFlag: function(name, color) { },
/**
* Find an object with the shortest path from the given position.
* Uses A* search algorithm and Dijkstra's algorithm.
*
*
* @param {number} type See {@link Room.find}
* @param {object} [opts] An object containing pathfinding options (see {@link Room.findPath}), or one of the following:
* @param {object|function|string} [opts.filter] Only the objects which pass the filter using the Lodash.filter method will be used.
* @param {string} [opts.filter] 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 Another variant of this function is findClosestByPath(objects, opts) where:
* @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.
*
* @param {number} type See {@link Room.find}
* @param {object} [opts] An object containing one of the following options:
* @param {object|function|string} [opts.filter] Only the objects which pass the filter using the Lodash.filter method will be used.
*
* @note Another variant of this function is findClosestByPath(objects, opts) where:
* @param {Array} objects An array of room's objects or RoomPosition objects that the search should be executed against.
*/
findClosestByRange: function(type, opts) { },
/**
* Find all objects in the specified linear range.
*
* @param {number} type See {@link Room.find}
* @param {number} range The range distance.
* @param {object} [opts] See {@link Room.find}
*
* @note Another variant of this function is findInRange(objects, range, opts) where:
* @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
*
* @param {number} x X position in the room.
* @param {number} y Y position in the room.
* @param {object} [opts] An object containing pathfinding options flags (see {@link Room.findPath} for more details).
*
* @note Another variant of this function is findPathTo(target, opts) where:
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @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 },
...
]
*/
findPathTo: function(x, y, opts) { },
/**
* Get linear direction to the specified position.
*
* @param {number} x X position in the room.
* @param {number} y Y position in the room.
*
* @note Another variant of this function is getDirectionTo(target) where:
* @param {object} target Can be a RoomPosition object or any object containing RoomPosition.
*
* @return {number} A number representing one of the direction constants.
*/
getDirectionTo: function(x, y) { },
/**
* Get linear range to the specified position.
*
* @param {number} x X position in the room.
* @param {number} y Y position in the room.
*
* @note Another variant of this function is getRangeTo(target) where:
* @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.
*
* @param {RoomPosition} toPos The target position.
* @param {number} range The range distance.
*
* @return {boolean}
*/
inRangeTo: function(toPos, range) { },
/**
* Check whether this position is the same as the specified position.
*
* @param {number} x X position in the room.
* @param {number} y Y position in the room.
*
* @note Another variant of this function is isEqualTo(target) where:
* @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).
*
* @param {number} x X position in the room.
* @param {number} y Y position in the room.
*
* @note Another variant of this function is isNearTo(target) where:
* @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.
*
* @return {object[]} 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.
*
* @param {string} type One of the following constants: constructionSite, creep, exit, flag, resource, source, structure, terrain
*
* @return {object[]} An array of objects of the given type at the specified position if found.
*/
lookFor: function(type) { }
};