forked from Garethp/ScreepsAutocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.js
439 lines (405 loc) · 14.8 KB
/
Game.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
/**
* The main global game object containing all the gameplay information.
*
* @class
*/
Game =
{
/**
* An object containing information about your CPU usage
*/
cpu:
{
/**
* Your CPU limit depending on your Global Control Level.
*
* @type {number}
*/
limit: 0,
/**
* An amount of available CPU time at the current game tick.
* It can be higher than Game.cpu.limit.
*
* @type {number}
*/
tickLimit: 0,
/**
* An amount of unused CPU accumulated in your bucket.
*
* @type {number}
*/
bucket: 0,
/**
* Get amount of CPU time used from the beginning of the current game tick.
* Always returns 0 in the Simulation mode.
*
* @type {function}
*
* @return {number}
*/
getUsed: function() { }
},
/**
* A hash containing all your construction sites with their id as hash keys.
*
* @type {Array<string, ConstructionSite>}
*/
constructionSites: {},
/**
* A hash containing all your creeps with creep names as hash keys.
*
* @type {Array<string, Creep>}
*/
creeps: {},
/**
* A hash containing all your flags with flag names as hash keys.
*
* @type {Array<string, Flag>}
*/
flags: {},
/**
* Your Global Control Level
*/
gcl:
{
/**
* The current level.
*
* @type {number}
*/
level: 0,
/**
* The current progress to the next level.
*
* @type {number}
*/
progress: 0,
/**
* The progress required to reach the next level.
*
* @type {number}
*/
progressTotal: 0
},
/**
* A global object representing world map.
*/
map:
{
/**
* List all exits available from the room with the given name.
*
* @type {function}
*
* @param {string} roomName The room name.
*
* @return {null|object} The exits information in the following format, or null if the room not found.
{
"1": "W8N4", // TOP
"3": "W7N3", // RIGHT
"5": "W8N2", // BOTTOM
"7": "W9N3" // LEFT
}
*/
describeExits: function(roomName) { },
/**
* Find the exit direction from the given room en route to another room.
*
* @type {function}
*
* @param {string|Room} fromRoom Start room name or room object.
* @param {string|Room} toRoom Finish room name or room object.
* @param {object} [opts] An object with the pathfinding options. See findRoute.
*
* @return {FIND_EXIT_TOP|FIND_EXIT_RIGHT|FIND_EXIT_BOTTOM|FIND_EXIT_LEFT|number|ERR_NO_PATH|ERR_INVALID_ARGS}
*/
findExit: function(fromRoom, toRoom, opts) { },
/**
* Find route from the given room to another room.
*
* @type {function}
*
* @param {string|Room} fromRoom Start room name or room object.
* @param {string|Room} toRoom Finish room name or room object.
* @param {object} [opts] An object with the pathfinding options.
* @param {function} [opts.routeCallback] This callback accepts two arguments: function(roomName, fromRoomName). It can be used to calculate the cost of entering that room. You can use this to do things like prioritize your own rooms, or avoid some rooms. You can return a floating point cost or Infinity to block the room.
*
* @return {Array|number|ERR_NO_PATH} The route array in the following format:
[
{ exit: FIND_EXIT_RIGHT, room: 'arena21' },
{ exit: FIND_EXIT_BOTTOM, room: 'arena22' }
]
*/
findRoute: function(fromRoom, toRoom, opts) { },
/**
* Get the linear distance (in rooms) between two rooms.
* You can use this function to estimate the energy cost of sending resources through terminals, or using observers and nukes.
*
* @type {function}
*
* @param {string} roomName1 The name of the first room.
* @param {string} roomName2 The name of the second room.
*
* @return {number} A number of rooms between the given two rooms.
*/
getRoomLinearDistance: function(roomName1, roomName2) { },
/**
* Get terrain type at the specified room position.
* This method works for any room in the world even if you have no access to it.
*
* @type {function}
*
* @param {number|RoomPosition} x X position in the room.
* @param {number} [y] Y position in the room.
* @param {string} [roomName] The room name.
*
* @note Alternative function: getTerrainAt(pos)
* @param {RoomPosition} pos The position object.
*
* @return {"plain"|"swamp"|"wall"}
*/
getTerrainAt: function(x, y, roomName) { },
/**
* Check if the room with the given name is protected by temporary "newbie" walls.
*
* @type {function}
*
* @param {string} roomName The room name.
*
* @return {boolean}
*/
isRoomProtected: function(roomName) { }
},
/**
* A global object representing the in-game market.
*/
market:
{
/**
* An array of the last 100 incoming transactions to your terminals with the following format:
[{
transactionId : "56dec546a180ce641dd65960",
time : 10390687,
sender : {username: "Sender"},
recipient : {username: "Me"},
resourceType : "U",
amount : 100,
from : "W0N0",
to : "W10N10",
description : "trade contract #1",
order: { // optional
id : "55c34a6b5be41a0a6e80c68b",
type : "sell",
price : 2.95
}
}]
* @type {Array}
*/
incomingTransactions: [],
/**
* An array of the last 100 outgoing transactions from your terminals with the following format:
[{
transactionId : "56dec546a180ce641dd65960",
time : 10390687,
sender : {username: "Me"},
recipient : {username: "Recipient"},
resourceType : "U",
amount : 100,
from : "W0N0",
to : "W10N10",
description : "trade contract #1",
order: { // optional
id : "55c34a6b5be41a0a6e80c68b",
type : "sell",
price : 2.95
}
}]
* @type {Array}
*/
outgoingTransactions: [],
/**
* This property is still under development.
* An array of your active and inactive buy/sell orders on the market, in the following format:
[
{
id : "55c34a6b5be41a0a6e80c68b",
active : true,
type : "sell"
resourceType : "OH",
roomName : "W1N1",
amount : 15821,
price : 2.95
}, {
id : "55c34a6b52411a0a6e80693a",
active : true,
type : "buy"
resourceType : "energy",
roomName : "W1N1",
amount : 94000,
price : 0.45
}, {
id : "55c34a6b5be41a0a6e80c123",
active : true,
type : "sell"
resourceType : "token",
amount : 3,
price : 50000
}
]
* @type {Array}
*/
myOrders: [],
/**
* This property is still under development.
* An array of all available buy/sell orders on the market.
* Only active orders are visible.
[
{
id : "55c34a6b5be41a0a6e80c68b",
type : "sell"
resourceType : "OH",
roomName : "W1N1",
amount : 15821,
price : 2.95
}, {
id : "55c34a6b52411a0a6e80693a",
type : "buy"
resourceType : "energy",
roomName : "W1N1",
amount : 94000,
price : 0.45
}, {
id : "55c34a6b5be41a0a6e80c123",
type : "sell"
resourceType : "token",
amount : 3,
price : 50000
}
]
* @type {Array}
*/
orders: [],
/**
* Estimate the energy transaction cost of StructureTerminal.send and Market.deal methods.
* The formula: Math.ceil( amount * ( Math.log( 0.1 * linearDistanceBetweenRooms + 0.9) + 0.1) )
*
* @type {function}
*
* @param {number} amount Amount of resources to be sent.
* @param {string} roomName1 The name of the first room.
* @param {string} roomName2 The name of the second room.
*
* @return {number} The amount of energy required to perform the transaction.
*/
calcTransactionCost: function(amount, roomName1, roomName2) { },
/**
* This method is still under development.
* Cancel a previously created order.
* If a buy order provided, then the reserved credits amount will be refunded in full.
* The 5% fee is not returned.
*
* @type {function}
*
* @param {string} orderId The order ID as provided in Game.market.myOrders.
*
* @return {number|OK|ERR_INVALID_ARGS}
*/
cancelOrder: function(orderId) { },
/**
* This method is still under development.
* Create a buy order in your terminal.
* You will be charged price*amount*0.05 credits when the order is placed, and the price*amount credits will be reserved.
* The maximum buy orders count is 50 per player.
* You can cancel an order to refund the reserved credits amount.
*
* @type {function}
*
* @param {string} resourceType Either one of the RESOURCE_* constants or GAMETIME_TOKEN.
* @param {number} price The price for one resource unit in credits. Can be a decimal number.
* @param {number} totalAmount The amount of resources to be bought in total.
* @param {string} [roomName] The room where your order will be created. You must have your own Terminal structure in this room, otherwise the created order will be temporary inactive. This argument is not used when resourceType equals to GAMETIME_TOKEN.
*
* @return {number|OK|ERR_NOT_ENOUGH_RESOURCES|ERR_FULL|ERR_INVALID_ARGS}
*/
createBuyOrder: function(resourceType, price, totalAmount, roomName) { },
/**
* This method is still under development.
* Create a sell order in your terminal.
* You will be charged price*amount*0.05 credits when the order is placed.
* The maximum sell orders count is 50 per player.
*
* @type {function}
*
* @param {string} resourceType Either one of the RESOURCE_* constants or GAMETIME_TOKEN. If your Terminal doesn't have the specified resource, the order will be temporary inactive.
* @param {number} price The price for one resource unit in credits. Can be a decimal number.
* @param {number} totalAmount The amount of resources to be sold in total. The Terminal doesn't have to contain all the given amount at the same time. If Infinity is provided, the order will remain active until the Terminal contains the specified resource.
* @param {string} [roomName] The room where your order will be created. You must have your own Terminal structure in this room, otherwise the created order will be temporary inactive. This argument is not used when resourceType equals to GAMETIME_TOKEN.
*
* @return {number|OK|ERR_NOT_ENOUGH_RESOURCES|ERR_FULL|ERR_INVALID_ARGS}
*/
createSellOrder: function(resourceType, price, totalAmount, roomName) { },
/**
* This method is still under development.
* Execute a trade deal from your Terminal to another player's Terminal using the specified buy/sell order.
* Your Terminal will be charged amount*linearDistanceBetweenRooms*0.1 energy units of transfer cost regardless of the order resource type.
* You can use Game.map.getRoomLinearDistance method to estimate it.
*
* @type {function}
*
* @param {string} orderId The order ID as provided in Game.market.orders.
* @param {string} targetRoomName The name of your room which has to contain an active Terminal with enough amount of energy.
* @param {number} amount The amount of resources to transfer.
*
* @return {number|OK|ERR_NOT_ENOUGH_RESOURCES|ERR_INVALID_ARGS}
*/
deal: function(orderId, targetRoomName, amount) { }
},
/**
* A hash containing all the rooms available to you with room names as hash keys.
*
* @type {Array<string, Room>}
*/
rooms: {},
/**
* A hash containing all your spawns with spawn names as hash keys.
*
* @type {Array<string, Spawn>}
*/
spawns: {},
/**
* A hash containing all your structures with structure id as hash keys.
*
* @type {Array<string, Structure>}
*/
structures: {},
/**
* System game tick counter. It is automatically incremented on every tick.
*
* @type {number}
*/
time: 0,
/**
* Get an object with the specified unique ID.
* It may be a game object of any type.
* Only objects from the rooms which are visible to you can be accessed.
*
* @type {function}
*
* @param {string} id The unique identificator.
*
* @return {object|null}
*/
getObjectById: function(id) { },
/**
* Send a custom message at your profile email.
* This way, you can set up notifications to yourself on any occasion within the game.
* You can schedule up to 20 notifications during one game tick.
* Not available in the Simulation Room.
*
* @param {string} message Custom text which will be sent in the message. Maximum length is 1000 characters.
* @param {number} [groupInterval] If set to 0 (default), the notification will be scheduled immediately. Otherwise, it will be grouped with other notifications and mailed out later using the specified time in minutes.
*
* @return {void}
*/
notify: function(message, groupInterval) { }
};