forked from Garethp/ScreepsAutocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Creep.js
460 lines (421 loc) · 16.3 KB
/
Creep.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
/**
*
* @class
* @extends {RoomObject}
*/
Creep = function() { };
Creep.prototype =
{
/**
* An array describing the creep’s body
*
* @type {Array<{boost:string, type:string, hits:number}>}
*
* @note boost: If the body part is boosted, this property specifies the mineral type which is used for boosting. One of the RESOURCE_* constants.
* @note type: One of the body part types constants.
* @note hits: The remaining amount of hit points of this body part.
*
*/
body: [],
/**
* An object with the creep's cargo contents.
* Each object key is one of the RESOURCE_* constants, values are resources amounts.
* Use _.sum(creep.carry) to get the total amount of contents.
*
* @type {object<string, number>}
*/
carry: {},
/**
* The total amount of resources the creep can carry.
*
* @type {number}
*/
carryCapacity: 0,
/**
* The movement fatigue indicator. If it is greater than zero, the creep cannot move.
*
* @type {number}
*/
fatigue: 0,
/**
* The current amount of hit points of the creep.
*
* @type {number}
*/
hits: 0,
/**
* The maximum amount of hit points of the creep.
*
* @type {number}
*/
hitsMax: 0,
/**
* A unique object identificator.
* You can use Game.getObjectById method to retrieve an object instance by its id.
*
* @type {string}
*/
id: "",
/**
* A shorthand to Memory.creeps[creep.name].
* You can use it for quick access the creep’s specific memory data object.
*
* @type {*}
*/
memory: {},
/**
* Whether it is your creep or foe.
*
* @type {boolean}
*/
my: true,
/**
* Creep’s name.
* You can choose the name while creating a new creep, and it cannot be changed later.
* This name is a hash key to access the creep via the Game.creeps object.
*
* @type {string}
*/
name: "",
/**
* The text message that the creep was saying at the last tick.
*
* @type {string}
*/
saying: "",
/**
* An object with the creep’s owner info
*
* @type {{username:string}}
*/
owner:
{
username: ""
},
/**
* Whether this creep is still being spawned.
*
* @type {boolean}
*/
spawning: false,
/**
* The remaining amount of game ticks after which the creep will die.
*
* @type {number}
*/
ticksToLive: 0,
/**
* Attack another creep or structure in a short-ranged attack.
* Requires the ATTACK body part.
* If the target is inside a rampart, then the rampart is attacked instead.
* The target has to be at adjacent square to the creep.
* If the target is a creep with ATTACK body parts and is not inside a rampart, it will automatically hit back at the attacker.
*
* @type {function}
*
* @param {Creep|Spawn|Structure} target The target object to be attacked.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART}
*/
attack: function(target) { },
/**
* Decreases the controller's downgrade or reservation timer for 1 tick per every 5 CLAIM body parts (so the creep must have at least 5xCLAIM).
* The controller under attack cannot be upgraded for the next 1,000 ticks.
* The target has to be at adjacent square to the creep.
*
* @type {function}
*
* @param {StructureController} target The target controller object.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART}
*/
attackController: function(target) { },
/**
* Build a structure at the target construction site using carried energy.
* Requires WORK and CARRY body parts.
* The target has to be within 3 squares range of the creep.
*
* @type {function}
*
* @param {ConstructionSite} target The target construction site to be built.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART|ERR_RCL_NOT_ENOUGH}
*/
build: function(target) { },
/**
* Cancel the order given during the current game tick.
*
* @type {function}
*
* @param {string} methodName The name of a creep's method to be cancelled.
*
* @return {number|OK|ERR_NOT_FOUND}
*/
cancelOrder: function(methodName) { },
/**
* Claims a neutral controller under your control.
* Requires the CLAIM body part.
* The target has to be at adjacent square to the creep.
*
* @type {function}
*
* @param {StructureController} target The target controller object.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_NO_BODYPART|ERR_GCL_NOT_ENOUGH}
*/
claimController: function(target) { },
/**
* Dismantles any (even hostile) structure returning 50% of the energy spent on its repair.
* Requires the WORK body part.
* If the creep has an empty CARRY body part, the energy is put into it; otherwise it is dropped on the ground.
* The target has to be at adjacent square to the creep.
*
* @type {function}
*
* @param {Spawn|Structure} target The target structure.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART}
*/
dismantle: function(target) { },
/**
* Drop this resource on the ground.
*
* @type {function}
*
* @param {string} resourceType One of the RESOURCE_* constants.
* @param {number} [amount] The amount of resource units to be dropped. If omitted, all the available carried amount is used.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES}
*/
drop: function(resourceType, amount) { },
/**
* Get the quantity of live body parts of the given type.
* Fully damaged parts do not count.
*
* @type {function}
*
* @param {string} type A body part type, one of the following body part constants: MOVE, WORK, CARRY, ATTACK, RANGED_ATTACK, HEAL, TOUGH
*
* @return {number} A number representing the quantity of body parts.
*/
getActiveBodyParts: function(type) { },
/**
* Harvest energy from the source or minerals from the mineral deposit.
* Requires the WORK body part.
* If the creep has an empty CARRY body part, the harvested resource is put into it; otherwise it is dropped on the ground.
* The target has to be at an adjacent square to the creep.
*
* @type {function}
*
* @param {Source|Mineral} target The object to be harvested.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_FOUND|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART}
*/
harvest: function(target) { },
/**
* Heal self or another creep.
* It will restore the target creep’s damaged body parts function and increase the hits counter.
* Requires the HEAL body part.
* The target has to be at adjacent square to the creep.
*
* @type {function}
*
* @param {Creep} target The target creep object.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART}
*/
heal: function(target) { },
/**
* Move the creep one square in the specified direction.
* Requires the MOVE body part.
*
* @type {function}
*
* @param {number} direction One of the following constants: TOP, TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM, BOTTOM_LEFT, LEFT, TOP_LEFT
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_TIRED|ERR_NO_BODYPART}
*/
move: function(direction) { },
/**
* Move the creep using the specified predefined path.
* Requires the MOVE body part.
*
* @type {function}
*
* @param {Array|string} path A path value as returned from Room.findPath or RoomPosition.findPathTo methods. Both array form and serialized string form are accepted.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_FOUND|ERR_INVALID_ARGS|ERR_TIRED|ERR_NO_BODYPART}
*/
moveByPath: function(path) { },
/**
* Find the optimal path to the target within the same room and move to it.
* A shorthand to consequent calls of pos.findPathTo() and move() methods.
* If the target is in another room, then the corresponding exit will be used as a target.
* Requires the MOVE body part.
*
* @type {function}
*
* @param {number} x X position of the target in the same room.
* @param {number} [y] Y position of the target in the same room.
* @param {object} [opts] An object containing additional options
* @param {number} [opts.reusePath] This option enables reusing the path found along multiple game ticks. It allows to save CPU time, but can result in a slightly slower creep reaction behavior. The path is stored into the creep's memory to the _move property. The reusePath value defines the amount of ticks which the path should be reused for. The default value is 5. Increase the amount to save more CPU, decrease to make the movement more consistent. Set to 0 if you want to disable path reusing.
* @param {boolean} [opts.serializeMemory] If reusePath is enabled and this option is set to true, the path will be stored in memory in the short serialized form using Room.serializePath. The default value is true.
* @param {boolean} [opts.noPathFinding] If this option is set to true, moveTo method will return ERR_NOT_FOUND if there is no memorized path to reuse. This can significantly save CPU time in some cases. The default value is false.
* @note opts also supports any method from the Room.findPath options.
*
* @alias moveTo(target, [opts])
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_TIRED|ERR_NO_BODYPART|ERR_INVALID_TARGET|ERR_NO_PATH}
*/
moveTo: function(x, y, opts) { },
/**
* Toggle auto notification when the creep is under attack.
* The notification will be sent to your account email.
* Turned on by default.
*
* @type {function}
*
* @param {boolean} enabled Whether to enable notification or disable.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_INVALID_ARGS}
*/
notifyWhenAttacked: function(enabled) { },
/**
* Pick up an item (a dropped piece of energy).
* Requires the CARRY body part.
* The target has to be at adjacent square to the creep or at the same square.
*
* @type {function}
*
* @param {Resource} target The target object to be picked up.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE}
*/
pickup: function(target) { },
/**
* A ranged attack against another creep or structure.
* Requires the RANGED_ATTACK body part.
* If the target is inside a rampart, the rampart is attacked instead.
* The target has to be within 3 squares range of the creep.
*
* @type {function}
*
* @param {Creep|Spawn|Structure} target The target object to be attacked.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART}
*/
rangedAttack: function(target) { },
/**
* Heal another creep at a distance.
* It will restore the target creep’s damaged body parts function and increase the hits counter.
* Requires the HEAL body part.
* The target has to be within 3 squares range of the creep.
*
* @type {function}
*
* @param {Creep} target The target creep object.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART}
*/
rangedHeal: function(target) { },
/**
* A ranged attack against all hostile creeps or structures within 3 squares range.
* Requires the RANGED_ATTACK body part.
* The attack power depends on the range to each target.
* Friendly units are not affected.
*
* @type {function}
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NO_BODYPART}
*/
rangedMassAttack: function() { },
/**
* Repair a damaged structure using carried energy.
* Requires the WORK and CARRY body parts.
* The target has to be within 3 squares range of the creep.
*
* @type {function}
*
* @param {Spawn|Structure} target The target structure to be repaired.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART}
*/
repair: function(target) { },
/**
* Temporarily block a neutral controller from claiming by other players.
* Each tick, this command increases the counter of the period during which the controller is unavailable by 1 tick per each CLAIM body part.
* The maximum reservation period to maintain is 5,000 ticks.
* The target has to be at adjacent square to the creep.
*
* @type {function}
*
* @param {StructureController} target The target controller object to be reserved.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART}
*/
reserveController: function(target) { },
/**
* Display a visual speech balloon above the creep with the specified message. The message will be
* available for one tick. You can read the last message using the saying property.
*
* @type {function}
*
* @param {string} message The message to be displayed. Maximum length is 10 characters.
* @param {boolean} [public] Set to true to allow other players to see this message. Default is false.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY}
*/
say: function(message, public) { },
/**
* Kill the creep immediately.
*
* @type {function}
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY}
*/
suicide: function() { },
/**
* Transfer resource from the creep to another object.
* The target has to be at adjacent square to the creep.
*
* @type {function}
*
* @param {Creep|Spawn|Structure} target The target object.
* @param {string} resourceType One of the RESOURCE_* constants.
* @param {number|undefined|null} [amount] The amount of resources to be transferred. If omitted, all the available carried amount is used.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS}
*/
transfer: function(target, resourceType, amount) { },
/**
* Upgrade your controller to the next level using carried energy.
* Upgrading controllers raises your Global Control Level in parallel.
* Requires WORK and CARRY body parts.
* The target has to be within 3 squares range of the creep.
* A fully upgraded level 8 controller can't be upgraded with the power over 15 energy units per tick regardless of creeps power.
* The cumulative effect of all the creeps performing upgradeController in the current tick is taken into account.
* The effect can be boosted by ghodium mineral compounds (including limit increase).
*
* @type {function}
*
* @param {StructureController} target The target controller object to be upgraded.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_NOT_IN_RANGE|ERR_NO_BODYPART}
*/
upgradeController: function(target) { },
/**
* Withdraw resources from a structure.
* The target has to be at adjacent square to the creep.
* Multiple creeps can withdraw from the same structure in the same tick.
* Your creeps can withdraw resources from hostile structures as well, in case if there is no hostile rampart on top of it.
*
* @type {function}
*
* @param {Structure} target The target object.
* @param {string} resourceType One of the RESOURCE_* constants.
* @param {number|undefined|null} [amount] The amount of resources to be transferred. If omitted, all the available carried amount is used.
*
* @return {number|OK|ERR_NOT_OWNER|ERR_BUSY|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_TARGET|ERR_FULL|ERR_NOT_IN_RANGE|ERR_INVALID_ARGS}
*/
withdraw: function(target, resourceType, amount) { }
};