mlogjs 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +2 -2
  2. package/dist/{index.cjs → Compiler-7GMG4MDr.js} +1746 -452
  3. package/dist/Compiler.d.ts +8 -12
  4. package/dist/CompilerError.d.ts +13 -3
  5. package/dist/Scope.d.ts +8 -8
  6. package/dist/bin/files.d.ts +18 -0
  7. package/dist/bin.mjs +170 -0
  8. package/dist/handlers/Import.d.ts +5 -0
  9. package/dist/handlers/Literal.d.ts +2 -2
  10. package/dist/handlers/Typescript.d.ts +2 -2
  11. package/dist/handlers/index.d.ts +1 -0
  12. package/dist/index.mjs +3 -4267
  13. package/dist/instructions/AddressResolver.d.ts +4 -4
  14. package/dist/instructions/ControlInstructions.d.ts +3 -3
  15. package/dist/instructions/InstructionBase.d.ts +1 -0
  16. package/dist/instructions/JumpInstruction.d.ts +5 -5
  17. package/dist/instructions/index.d.ts +0 -1
  18. package/dist/macros/DynamicArray.d.ts +4 -4
  19. package/dist/macros/Function.d.ts +2 -2
  20. package/dist/macros/GetBuildings.d.ts +4 -0
  21. package/dist/macros/GetColor.d.ts +4 -0
  22. package/dist/macros/Marker.d.ts +4 -0
  23. package/dist/macros/Namespace.d.ts +16 -0
  24. package/dist/macros/Queries.d.ts +10 -0
  25. package/dist/macros/StringView.d.ts +4 -0
  26. package/dist/macros/commands/Effect.d.ts +4 -0
  27. package/dist/macros/commands/Format.d.ts +4 -0
  28. package/dist/macros/commands/LocalePrint.d.ts +4 -0
  29. package/dist/macros/commands/PlayMusic.d.ts +4 -0
  30. package/dist/macros/commands/PlaySound.d.ts +4 -0
  31. package/dist/macros/commands/PrintChar.d.ts +4 -0
  32. package/dist/macros/commands/Query.d.ts +4 -0
  33. package/dist/macros/commands/SetProp.d.ts +4 -0
  34. package/dist/macros/commands/SpawnBullet.d.ts +4 -0
  35. package/dist/macros/commands/Sync.d.ts +6 -0
  36. package/dist/macros/commands/UnpackColor.d.ts +4 -0
  37. package/dist/macros/commands/WeatherSense.d.ts +4 -0
  38. package/dist/macros/commands/WeatherSet.d.ts +4 -0
  39. package/dist/macros/commands/index.d.ts +13 -0
  40. package/dist/macros/index.d.ts +7 -1
  41. package/dist/macros/util.d.ts +5 -2
  42. package/dist/modules.d.ts +8 -0
  43. package/dist/operators.d.ts +1 -1
  44. package/dist/types.d.ts +84 -59
  45. package/dist/utils/constants.d.ts +9 -4
  46. package/dist/utils/general.d.ts +8 -9
  47. package/dist/utils/instruction.d.ts +5 -1
  48. package/dist/utils/value.d.ts +14 -5
  49. package/dist/values/AssignmentValue.d.ts +1 -1
  50. package/dist/values/BaseValue.d.ts +4 -2
  51. package/dist/values/DestructuringValue.d.ts +5 -7
  52. package/dist/values/FunctionValue.d.ts +8 -6
  53. package/dist/values/JumpOutValue.d.ts +4 -4
  54. package/dist/values/LazyValue.d.ts +3 -3
  55. package/dist/values/LiteralValue.d.ts +2 -3
  56. package/dist/values/ObjectValue.d.ts +6 -11
  57. package/dist/values/StoreValue.d.ts +10 -5
  58. package/dist/values/VoidValue.d.ts +2 -1
  59. package/dist/values/index.d.ts +0 -1
  60. package/lib/commands.d.ts +777 -729
  61. package/lib/eslib/lib.es2015.collection.d.ts +50 -39
  62. package/lib/eslib/lib.es2015.core.d.ts +59 -0
  63. package/lib/eslib/lib.es2015.d.ts +0 -3
  64. package/lib/eslib/lib.es2015.generator.d.ts +54 -53
  65. package/lib/eslib/lib.es2015.iterable.d.ts +9 -6
  66. package/lib/eslib/lib.es5.d.ts +53 -6
  67. package/lib/globals.d.ts +309 -18
  68. package/lib/helpers.d.ts +86 -52
  69. package/lib/kinds.d.ts +42 -7
  70. package/lib/macros.d.ts +53 -18
  71. package/lib/traits.d.ts +308 -146
  72. package/lib/util.d.ts +144 -48
  73. package/lib/world.d.ts +1197 -0
  74. package/package.json +27 -35
  75. package/dist/bin.cjs +0 -111
  76. package/dist/initScope.d.ts +0 -5
  77. package/dist/instructions/ZeroSpaceInstruction.d.ts +0 -4
  78. package/dist/values/SenseableValue.d.ts +0 -24
  79. /package/dist/{bin.d.ts → bin/index.d.ts} +0 -0
package/lib/commands.d.ts CHANGED
@@ -1,45 +1,79 @@
1
- import "./kind";
1
+ import "./kinds";
2
2
  import {
3
3
  TRadarFilter,
4
4
  TRadarSort,
5
- TUnitEffect,
6
5
  TUnitLocateBuildingGroup,
7
- } from "./util";
6
+ } from "mlogjs:types";
7
+
8
8
  declare global {
9
9
  /**
10
- * Appends the items to the print buffer, calling this function
11
- * on its own will not print any contents to a message block.
10
+ * Appends the items to the global text buffer, calling this function on its
11
+ * own will not print any contents to a message block.
12
+ *
13
+ * To print the contents of the global text buffer and empty it, call
14
+ * `printFlush`.
15
+ *
16
+ * @param items The items to be added to the global text buffer.
17
+ *
18
+ * ```js
19
+ * const a = Math.floor(Math.rand(10));
20
+ * const b = Math.floor(Math.rand(10));
12
21
  *
13
- * To print the contents of the print buffer and empty it call, `printFlush`.
22
+ * // call normally
23
+ * print("a + b = ", a, " + ", b, " = ", a + b, "\n");
14
24
  *
15
- * @param items The items to be added to the print buffer.
25
+ * // call with tagged string templates
26
+ * print`a + b = ${a} + ${b} = ${a + b}\n`;
27
+ *
28
+ * printFlush();
29
+ * ```
30
+ */
31
+ function print(...items: unknown[]): void;
32
+
33
+ /**
34
+ * Replaces the first placeholder with lowest value in the global text buffer.
16
35
  *
17
36
  * ```js
18
- * // call normally
19
- * print("a + b = ", left, " + ", right, " = ", left + right)
37
+ * print("{1} {0}");
38
+ * format("world!");
39
+ * format("Hello");
40
+ * printFlush(); // prints "Hello world!"
41
+ * ```
42
+ */
43
+ function format(value: unknown): void;
44
+
45
+ /**
46
+ * Adds a character to the global text buffer using the provided using the
47
+ * provided UTF-16 code unit or the icon of the provided game content type.
20
48
  *
21
- * // call with tagged string templates
22
- * print`a + b = ${left} + ${right} = ${left + right}`
49
+ * ```js
50
+ * printChar(128073); // "👉" emoji
51
+ * printChar(Blocks.router);
52
+ * printFlush();
23
53
  * ```
24
54
  */
25
- function print(...items: unknown[]): void;
55
+ function printChar(character: number | symbol): void;
26
56
 
27
57
  /** Contains the multiple variants of the `draw` instruction */
28
58
  namespace draw {
29
59
  /**
30
60
  * Fills the screen with a color.
31
61
  *
62
+ * ```js
63
+ * draw.clear(0, 0, 0); // black screen
64
+ * ```
65
+ *
32
66
  * Warning: nothing is drawn until `drawFlush` is called.
33
67
  */
34
68
  function clear(r: number, g: number, b: number): void;
35
69
  /**
36
70
  * Sets the color for the next drawing operations.
37
71
  *
38
- * Each parameter must be within range: [0, 255].
72
+ * Each parameter must be within range: [0, 255].
39
73
  *
40
- * ```js
41
- * draw.color(255, 255, 255, 128);
42
- * ```
74
+ * ```js
75
+ * draw.color(255, 255, 255, 128);
76
+ * ```
43
77
  *
44
78
  * Warning: nothing is drawn until `drawFlush` is called.
45
79
  */
@@ -53,16 +87,15 @@ declare global {
53
87
  * ```js
54
88
  * draw.col(packColor(1, 1, 1, 1));
55
89
  * ```
56
- *
57
90
  */
58
91
  function col(rgbaData: number): void;
59
92
 
60
93
  /**
61
94
  * Sets the width of the next lines to be drawn.
62
95
  *
63
- * ```js
64
- * draw.stroke(15);
65
- * ```
96
+ * ```js
97
+ * draw.stroke(15);
98
+ * ```
66
99
  *
67
100
  * Warning: nothing is drawn until `drawFlush` is called.
68
101
  */
@@ -71,9 +104,9 @@ declare global {
71
104
  /**
72
105
  * Draws a line between two points.
73
106
  *
74
- * ```js
75
- * draw.line({ x: 5, y: 5, x2: 50, y2: 50 });
76
- * ```
107
+ * ```js
108
+ * draw.line({ x: 5, y: 5, x2: 50, y2: 50 });
109
+ * ```
77
110
  *
78
111
  * Warning: nothing is drawn until `drawFlush` is called.
79
112
  */
@@ -86,14 +119,15 @@ declare global {
86
119
 
87
120
  /**
88
121
  * Draws a filled rectangle.
89
- * ```js
90
- * draw.rect({
91
- * x: 10,
92
- * y: 15,
93
- * height: 60,
94
- * width: 40,
95
- * });
96
- * ```
122
+ *
123
+ * ```js
124
+ * draw.rect({
125
+ * x: 10,
126
+ * y: 15,
127
+ * height: 60,
128
+ * width: 40,
129
+ * });
130
+ * ```
97
131
  *
98
132
  * Warning: nothing is drawn until `drawFlush` is called.
99
133
  */
@@ -107,6 +141,15 @@ declare global {
107
141
  /**
108
142
  * Draws a rectangle outline.
109
143
  *
144
+ * ```js
145
+ * draw.lineRect({
146
+ * x: 10,
147
+ * y: 15,
148
+ * height: 60,
149
+ * width: 40,
150
+ * });
151
+ * ```
152
+ *
110
153
  * Warning: nothing is drawn until `drawFlush` is called.
111
154
  */
112
155
  function lineRect(options: {
@@ -118,21 +161,23 @@ declare global {
118
161
 
119
162
  /**
120
163
  * Draws a filled, regular polygon.
164
+ *
121
165
  * @param options.sides The number of sides the polygon should have
122
- * @param options.radius The smallest distance between a line and the center of the polygon
166
+ * @param options.radius The smallest distance between a line and the center
167
+ * of the polygon
123
168
  * @param options.rotation The rotation of the polygon in degrees
124
169
  *
125
- * ```js
126
- * draw.poly({
127
- * radius: 10,
128
- * rotation: 0,
129
- * sides: 10,
130
- * x: 25,
131
- * y: 25,
132
- * });
133
- * ```
134
- *
135
- * Warning: nothing is drawn until `drawFlush` is called.
170
+ * ```js
171
+ * draw.poly({
172
+ * radius: 10,
173
+ * rotation: 0,
174
+ * sides: 10,
175
+ * x: 25,
176
+ * y: 25,
177
+ * });
178
+ * ```
179
+ *
180
+ * Warning: nothing is drawn until `drawFlush` is called.
136
181
  */
137
182
  function poly(options: {
138
183
  x: number;
@@ -147,21 +192,23 @@ declare global {
147
192
 
148
193
  /**
149
194
  * Draws the outline of a regular polygon.
195
+ *
150
196
  * @param options.sides The number of sides the polygon should have
151
- * @param options.radius The smallest distance between a line and the center of the polygon
197
+ * @param options.radius The smallest distance between a line and the center
198
+ * of the polygon
152
199
  * @param options.rotation The rotation of the polygon in degrees
153
200
  *
154
- * ```js
155
- * draw.linePoly({
156
- * radius: 10,
157
- * rotation: 0,
158
- * sides: 10,
159
- * x: 25,
160
- * y: 25,
161
- * });
162
- * ```
163
- *
164
- * Warning: nothing is drawn until `drawFlush` is called.
201
+ * ```js
202
+ * draw.linePoly({
203
+ * radius: 10,
204
+ * rotation: 0,
205
+ * sides: 10,
206
+ * x: 25,
207
+ * y: 25,
208
+ * });
209
+ * ```
210
+ *
211
+ * Warning: nothing is drawn until `drawFlush` is called.
165
212
  */
166
213
  function linePoly(options: {
167
214
  x: number;
@@ -177,16 +224,16 @@ declare global {
177
224
  /**
178
225
  * Draws a filled triangle.
179
226
  *
180
- * ```js
181
- * draw.triangle({
182
- * x: 10,
183
- * y: 10,
184
- * x2: 20,
185
- * y2: 20,
186
- * x3: 30,
187
- * y3: 10,
188
- * });
189
- * ```
227
+ * ```js
228
+ * draw.triangle({
229
+ * x: 10,
230
+ * y: 10,
231
+ * x2: 20,
232
+ * y2: 20,
233
+ * x3: 30,
234
+ * y3: 10,
235
+ * });
236
+ * ```
190
237
  *
191
238
  * Warning: nothing is drawn until `drawFlush` is called.
192
239
  */
@@ -200,34 +247,35 @@ declare global {
200
247
  }): void;
201
248
 
202
249
  /**
203
- * Draws an image of the respective content. (like `Units.dagger` and `Blocks.router`)
250
+ * Draws an image of the respective content. (like `Units.dagger` and
251
+ * `Blocks.router`)
204
252
  *
205
253
  * Warning: nothing is drawn until `drawFlush` is called.
254
+ *
206
255
  * @param options.image The symbol for the image to be drawn.
207
256
  * @param options.rotation The rotation of the image in degrees.
208
257
  *
209
- * Example:
210
- * ```js
211
- * // draw a router
212
- * draw({
213
- * mode: "image",
214
- * x: 30,
215
- * y: 30,
216
- * image: Blocks.router,
217
- * size: 15,
218
- * rotation: 0
219
- * });
220
- *
221
- * // draw the unit bound to the processor
222
- * draw({
223
- * mode: "image",
224
- * x: 60,
225
- * y: 60,
226
- * image: Vars.unit.type,
227
- * size: 15,
228
- * rotation: 0
229
- * });
230
- * ```
258
+ * Example:
259
+ *
260
+ * ```js
261
+ * // draw a router
262
+ * draw.image({
263
+ * x: 30,
264
+ * y: 30,
265
+ * image: Blocks.router,
266
+ * size: 15,
267
+ * rotation: 0,
268
+ * });
269
+ *
270
+ * // draw the unit bound to the processor
271
+ * draw.image({
272
+ * x: 60,
273
+ * y: 60,
274
+ * image: Vars.unit.type,
275
+ * size: 15,
276
+ * rotation: 0,
277
+ * });
278
+ * ```
231
279
  */
232
280
  function image(options: {
233
281
  x: number;
@@ -238,39 +286,102 @@ declare global {
238
286
  /** The rotation of the image in degrees. */
239
287
  rotation: number;
240
288
  }): void;
289
+
290
+ /**
291
+ * Draws text from the global text buffer, clearing it afterwards.
292
+ *
293
+ * Only ASCII characters are supported.
294
+ *
295
+ * ```js
296
+ * draw.print({
297
+ * x: 10,
298
+ * y: 10,
299
+ * align: Align.topLeft,
300
+ * });
301
+ * ```
302
+ *
303
+ * Warning: nothing is drawn until `drawFlush` is called.
304
+ */
305
+ function print(options: { x: number; y: number; align: Align }): void;
306
+
307
+ /**
308
+ * Applies a translation to the next drawing operations.
309
+ *
310
+ * ```js
311
+ * draw.translate(10, 20);
312
+ * ```
313
+ */
314
+ function translate(x: number, y: number): void;
315
+
316
+ /** Applies a scaling to the next drawing operations. */
317
+ function scale(x: number, y: number): void;
318
+
319
+ /** Applies a rotation to the next drawing operations. */
320
+ function rotate(degrees: number): void;
321
+
322
+ /** Removes all applied transformations. */
323
+ function reset(): void;
241
324
  }
242
325
 
243
326
  /**
244
- * Writes the contents of the print buffer into the target message
245
- * and clears the buffer afterwards.
246
- * @param target The message building to write to. Writes to `message1` by default.
327
+ * Writes the contents of the global text buffer into the target message and
328
+ * clears the buffer afterwards.
329
+ *
330
+ * @param target The message building to write to. Writes to `message1` by
331
+ * default.
247
332
  *
248
- * Note that the default value only applies if you don't pass any parameter to this function.
333
+ * Note that the default value only applies if you don't pass any parameter to
334
+ * this function.
335
+ *
336
+ * If `target` is `undefined`, the contents of the global text buffer will be
337
+ * discarded.
338
+ *
339
+ * ```js
340
+ * const { message2 } = getBuildings();
341
+ * printFlush(message2);
342
+ *
343
+ * printFlush(); // defaults to message1
344
+ * ```
249
345
  */
250
- function printFlush(target?: BasicBuilding): void;
346
+ function printFlush(target: BasicBuilding | undefined): void;
347
+ function printFlush(): void;
251
348
 
252
349
  /**
253
- * Writes the contents of the draw buffer into the target display
254
- * and clears the buffer afterwards.
255
- * @param target The display building to write to. Writes to `display1` by default.
350
+ * Writes the contents of the draw buffer into the target display and clears
351
+ * the buffer afterwards.
352
+ *
353
+ * @param target The display building to write to. Writes to `display1` by
354
+ * default.
355
+ *
356
+ * Note that the default value only applies if you don't pass any parameter to
357
+ * this function.
358
+ *
359
+ * ```js
360
+ * const { display2 } = getBuildings();
361
+ * printFlush(display2);
256
362
  *
257
- * Note that the default value only applies if you don't pass any parameter to this function.
363
+ * printFlush(); // defaults to display1
364
+ * ```
258
365
  */
259
- function drawFlush(target?: BasicBuilding): void;
366
+ function drawFlush(target: BasicBuilding): void;
367
+ function drawFlush(): void;
260
368
 
261
369
  /**
262
370
  * Gets a block link by its index.
263
371
  *
264
- * To make safe queries it is recommended to check an index
265
- * before trying to get a link. This can be done by using `Vars.links`.
266
- * @param index
372
+ * To make safe queries it is recommended to check an index before trying to
373
+ * get a link. This can be done by using `Vars.links`.
267
374
  *
268
375
  * Example:
376
+ *
269
377
  * ```js
270
- * if(index < Vars.links) {
271
- * const myBlock = getLink(index)
272
- * // ...
378
+ * for (let i = 0; i < Vars.links; i++) {
379
+ * const building = getLink(i);
380
+ * const { x, y } = building;
381
+ * print`${building}: (${x}, ${y})\n`;
273
382
  * }
383
+ *
384
+ * printFlush();
274
385
  * ```
275
386
  */
276
387
  function getLink<T extends BasicBuilding = AnyBuilding>(index: number): T;
@@ -280,26 +391,30 @@ declare global {
280
391
  /**
281
392
  * Sets whether the building is enabled or disabled.
282
393
  *
283
- * ```js
284
- * const conveyor = getBuilding("conveyor1");
285
- * control.enabled(conveyor, false);
286
- * ```
394
+ * ```js
395
+ * const { conveyor1 } = getBuildings();
396
+ *
397
+ * control.enabled(conveyor1, false);
398
+ * ```
287
399
  */
288
400
  function enabled(building: BasicBuilding, value: boolean): void;
289
401
 
290
402
  /**
291
403
  * Makes the building shoot or aim at the given position
404
+ *
292
405
  * @param options.building The shooting building
293
406
  * @param options.shoot `true` to shoot, `false` to just aim at the position
294
407
  *
295
- * ```js
296
- * control.shoot({
297
- * building: getBuilding("cyclone1"),
298
- * shoot: true,
299
- * x: Vars.thisx,
300
- * y: Vars.thisy,
301
- * });
302
- * ```
408
+ * ```js
409
+ * const { cyclone1 } = getBuildings();
410
+ *
411
+ * control.shoot({
412
+ * building: cyclone1,
413
+ * shoot: true,
414
+ * x: Vars.thisx,
415
+ * y: Vars.thisy,
416
+ * });
417
+ * ```
303
418
  */
304
419
  function shoot(options: {
305
420
  /** The shooting building */
@@ -312,26 +427,27 @@ declare global {
312
427
 
313
428
  /**
314
429
  * Shoot at an unit with velocity prediction
430
+ *
315
431
  * @param options.building The shooting building
316
432
  * @param options.unit The target unit
317
433
  * @param options.shoot `true` to shoot, `false` to just aim
318
434
  *
319
- * ```js
320
- * const turret = getBuilding("cyclone1");
321
- *
322
- * const player = radar({
323
- * building: turret,
324
- * filters: ["player", "any", "any"],
325
- * order: true,
326
- * sort: "distance",
327
- * });
328
- *
329
- * control.shootp({
330
- * building: turret,
331
- * unit: player,
332
- * shoot: true,
333
- * });
334
- * ```
435
+ * ```js
436
+ * const { cyclone1 } = getBuildings();
437
+ *
438
+ * const player = radar({
439
+ * building: cyclone1,
440
+ * filters: ["player", "any", "any"],
441
+ * order: true,
442
+ * sort: "distance",
443
+ * });
444
+ *
445
+ * control.shootp({
446
+ * building: cyclone1,
447
+ * unit: player,
448
+ * shoot: true,
449
+ * });
450
+ * ```
335
451
  */
336
452
  function shootp(options: {
337
453
  /** The shooting building */
@@ -343,46 +459,64 @@ declare global {
343
459
  }): void;
344
460
 
345
461
  /**
346
- * Sets the config of a block (like the item of a sorter)
462
+ * Sets the config of a block (like the item of a sorter).
463
+ *
464
+ * In privileged (world) processors, this can also be used to:
347
465
  *
348
- * ```js
349
- * const sorter = getBuilding("sorter1");
466
+ * - Configure the target block of a mass driver.
467
+ * - Configure the target block of a bridge.
468
+ * - Toggle whether a block is connected to a power node.
350
469
  *
351
- * control.config(sorter, Items.copper);
352
- * ```
470
+ * ```js
471
+ * const { sorter1, driver1, driver2, node1, factory1 } =
472
+ * getBuildings();
473
+ *
474
+ * control.config(sorter1, Items.copper);
475
+ * // World processor only:
476
+ * control.config(driver1, driver2);
477
+ * control.config(node1, factory1);
478
+ * ```
353
479
  */
354
- function config(building: BasicBuilding, value: symbol): void;
480
+ function config(
481
+ building: BasicBuilding,
482
+ value: symbol | BasicBuilding,
483
+ ): void;
355
484
 
356
485
  /**
357
486
  * Sets the color of an illuminator.
358
487
  *
359
- * ```js
360
- * const illuminator = getBuilding("illuminator1");
488
+ * ```js
489
+ * const { illuminator1 } = getBuildings();
361
490
  *
362
- * control.color(illuminator, packColor(0.2, 0.65, 1, 1));
363
- * ```
491
+ * control.color(illuminator1, packColor(0.2, 0.65, 1, 1));
492
+ * ```
364
493
  */
365
494
  function color(building: BasicBuilding, rgbaData: number): void;
366
495
  }
367
496
 
368
497
  /**
369
498
  * Detects an unit nearby this `building`.
499
+ *
370
500
  * @param options.building The building used to detect potential targets
371
- * @param options.filters The filters for selecting a target. Use "any" for any target.
372
- * @param options.order `true` to get the first result, `false` to get the last result.
501
+ * @param options.filters The filters for selecting a target. Use "any" for
502
+ * any target.
503
+ * @param options.order `true` to get the first result, `false` to get the
504
+ * last result.
373
505
  * @param options.sort The method on which the results should be sorted
374
506
  *
375
- * Example:
376
- * ```js
377
- * const turret = getBuilding("cyclone1")
378
- * // returns the furthest enemy unit
379
- * const result = radar({
380
- * building: turret,
381
- * filters: ["enemy", "any", "any"],
382
- * order: false,
383
- * sort: "distance"
384
- * });
385
- * ```
507
+ * Example:
508
+ *
509
+ * ```js
510
+ * const { cyclone1 } = getBuildings();
511
+ *
512
+ * // returns the furthest enemy unit
513
+ * const result = radar({
514
+ * building: cyclone1,
515
+ * filters: ["enemy", "any", "any"],
516
+ * order: false,
517
+ * sort: "distance",
518
+ * });
519
+ * ```
386
520
  */
387
521
  function radar<T extends BasicUnit = AnyUnit>(options: {
388
522
  /** The building used to detect potential targets */
@@ -398,36 +532,54 @@ declare global {
398
532
  /**
399
533
  * Alternate way to access special properties on objects.
400
534
  *
401
- * This method allows you to use customly created symbols
402
- * and sensor them on buildings.
535
+ * This method allows you to use customly created symbols and sensor them on
536
+ * buildings.
537
+ *
403
538
  * @param property The property to be sensed on the building
404
539
  * @param target The object that will be "sensed"
405
540
  *
406
- * Example:
407
- * ```ts
408
- * const myBuilding = getBuilding("container1");
541
+ * Example:
542
+ *
543
+ * ```ts
544
+ * const myBuilding = getBuilding("container1");
409
545
  *
410
- * // typescript annotation, you can use jsdoc comments on
411
- * // regular javascript
412
- * const myCustomSymbol = getVar<symbol>("@custom-symbol"); // problably defined by a mod
413
- * const result = sensor(myCustomSymbol, myBuilding);
414
- * ```
546
+ * // typescript annotation, you can use jsdoc comments on
547
+ * // regular javascript
548
+ * const myCustomSymbol = getVar<symbol>("@custom-symbol"); // problably defined by a mod
549
+ * const result = sensor(myCustomSymbol, myBuilding);
550
+ * ```
415
551
  */
416
- function sensor<T>(property: symbol, target: BasicBuilding | BasicUnit): T;
552
+ function sensor(property: BasicBuilding, target: BasicBuilding): boolean;
553
+ function sensor<T>(
554
+ property: symbol,
555
+ target: BasicBuilding | BasicUnit | Bullet,
556
+ ): T;
417
557
 
418
558
  /**
419
- * Stops the execution for the given amount of
420
- * ```js
421
- * print("before");
422
- * printFlush();
423
- * wait(3.5);
424
- * print("after");
425
- * printFlush();
426
- * ```
559
+ * Stops the execution for the given amount of seconds
560
+ *
561
+ * ```js
562
+ * print("before");
563
+ * printFlush();
564
+ * wait(3.5);
565
+ * print("after");
566
+ * printFlush();
567
+ * ```
427
568
  */
428
569
  function wait(seconds: number): void;
429
570
 
430
- /** Looks up content symbols by their index. */
571
+ /**
572
+ * Looks up content symbols by their index.
573
+ *
574
+ * For the inverse of this operation, you can sense the `id` of a symbol:
575
+ *
576
+ * ```js
577
+ * const { type } = getLink(0);
578
+ *
579
+ * print(type === lookup.block(type.id));
580
+ * printFlush(); // prints "1"
581
+ * ```
582
+ */
431
583
  namespace lookup {
432
584
  /**
433
585
  * Looks up a block symbol by it's index on the content registry.
@@ -435,24 +587,37 @@ declare global {
435
587
  * Use `Vars.blockCount` to check the maximum index allowed.
436
588
  *
437
589
  * Example:
590
+ *
438
591
  * ```js
439
- * if(index < Vars.blockCount) {
440
- * const blockKind = lookup.block(index);
441
- * }
592
+ * const first = lookup.block(0);
593
+ * const last = lookup.block(Vars.blockCount - 1);
594
+ *
595
+ * print`
596
+ * first block type: ${first}
597
+ * last block type: ${last}`;
598
+ *
599
+ * printFlush();
442
600
  * ```
443
601
  */
444
- function block(index: number): BlockSymbol;
602
+ function block(index: number): BlockSymbol | undefined;
445
603
 
446
604
  /**
447
605
  * Looks up an unit symbol by it's index on the content registry.
448
606
  *
449
- * Use `Vars.unitCount` to check the maximum index allowed.
607
+ * `index` must an integer that satisfies the following range `index <
608
+ * Vars.unitCount`
450
609
  *
451
610
  * Example:
611
+ *
452
612
  * ```js
453
- * if(index < Vars.unitCount) {
454
- * const unitKind = lookup.unit(index);
455
- * }
613
+ * const first = lookup.unit(0);
614
+ * const last = lookup.unit(Vars.unitCount - 1);
615
+ *
616
+ * print`
617
+ * first unit type: ${first}
618
+ * last unit type: ${last}`;
619
+ *
620
+ * printFlush();
456
621
  * ```
457
622
  */
458
623
  function unit(index: number): UnitSymbol | undefined;
@@ -463,10 +628,16 @@ declare global {
463
628
  * Use `Vars.itemCount` to check the maximum index allowed.
464
629
  *
465
630
  * Example:
631
+ *
466
632
  * ```js
467
- * if(index < Vars.itemCount) {
468
- * const itemKind = lookup.item(index);
469
- * }
633
+ * const first = lookup.item(0);
634
+ * const last = lookup.item(Vars.itemCount - 1);
635
+ *
636
+ * print`
637
+ * first item type: ${first}
638
+ * last item type: ${last}`;
639
+ *
640
+ * printFlush();
470
641
  * ```
471
642
  */
472
643
  function item(index: number): ItemSymbol | undefined;
@@ -477,13 +648,34 @@ declare global {
477
648
  * Use `Vars.liquidCount` to check the maximum index allowed.
478
649
  *
479
650
  * Example:
651
+ *
480
652
  * ```js
481
- * if(index < Vars.liquidCount) {
482
- * const liquidKind = lookup.liquid(index);
483
- * }
653
+ * const first = lookup.liquid(0);
654
+ * const last = lookup.liquid(Vars.liquidCount - 1);
655
+ *
656
+ * print`
657
+ * first liquid type: ${first}
658
+ * last liquid type: ${last}`;
659
+ *
660
+ * printFlush();
484
661
  * ```
485
662
  */
486
663
  function liquid(index: number): LiquidSymbol | undefined;
664
+
665
+ /**
666
+ * Looks up a team symbol by its index on the content registry.
667
+ *
668
+ * Example:
669
+ *
670
+ * ```js
671
+ * const first = lookup.team(0);
672
+ *
673
+ * print`first team type: ${first}`;
674
+ *
675
+ * printFlush();
676
+ * ```
677
+ */
678
+ function team(index: number): TeamSymbol | undefined;
487
679
  }
488
680
 
489
681
  /**
@@ -491,60 +683,106 @@ declare global {
491
683
  *
492
684
  * Each paremeter must range from `0` to `1`.
493
685
  *
686
+ * ```js
687
+ * const colorData = packColor(0.1, 0.6, 0.8, 0.1);
494
688
  *
495
- * ```js
496
- * const colorData = packColor(0.1, 0.6, 0.8, 0.1);
497
- *
498
- * // world processor only
499
- * // sets the color of the ambient light
500
- * setRule.ambientLight(colorData);
689
+ * // world processor only
690
+ * // sets the color of the ambient light
691
+ * setRule.ambientLight(colorData);
501
692
  *
502
- * // set color of illuminator
503
- * const illuminator = getBuilding("illuminator1");
504
- * control.color(illuminator, packColor(0.2, 0.65, 1, 1));
505
- * ```
693
+ * // set color of illuminator
694
+ * const { illuminator1 } = getBuildings();
695
+ * control.color(illuminator1, packColor(0.2, 0.65, 1, 1));
696
+ * ```
506
697
  */
507
698
  function packColor(r: number, g: number, b: number, a: number): number;
508
699
 
700
+ /**
701
+ * Unpacks RGBA color information from a color.
702
+ *
703
+ * ```js
704
+ * const colorData = packColor(0.1, 0.6, 0.8, 0.1);
705
+ *
706
+ * const { r, g, b, a } = unpackColor(colorData);
707
+ *
708
+ * print`r: ${r}, g: ${g}, b: ${b}, a: ${a}`;
709
+ * printFlush();
710
+ * ```
711
+ */
712
+ function unpackColor(color: number): {
713
+ r: number;
714
+ g: number;
715
+ b: number;
716
+ a: number;
717
+ };
718
+
509
719
  /**
510
720
  * Binds an unit to the this processor. The unit is accessible at `Vars.unit`.
511
721
  *
512
- * If an unit symbol is received, the processor will pick an
513
- * unit of the given type.
722
+ * If an unit symbol is received, the processor will pick an unit of the given
723
+ * type.
514
724
  *
515
725
  * If an unit object is received, the processor will bind to the unit.
516
726
  *
517
- * ```js
518
- * unitBind(Units.flare);
727
+ * ```js
728
+ * unitBind(Units.flare);
519
729
  *
520
- * const { x, y } = Vars.unit;
730
+ * const { x, y } = Vars.unit;
521
731
  *
522
- * print`x: ${x} y: ${y}`;
523
- * printFlush();
524
- * ```
732
+ * print`x: ${x} y: ${y}`;
733
+ * printFlush();
734
+ * ```
525
735
  */
526
736
  function unitBind(unit: UnitSymbol | BasicUnit): void;
527
737
 
528
738
  namespace unitControl {
529
739
  /**
530
- * Makes the unit bound to this processor stop moving but
531
- * allows it to keep doing it's action (like mining or building)
740
+ * Makes the unit bound to this processor stop moving but allows it to keep
741
+ * doing it's action (like mining or building)
742
+ *
743
+ * ```js
744
+ * unitControl.idle();
745
+ * ```
532
746
  */
533
747
  function idle(): void;
534
748
 
535
749
  /**
536
750
  * Makes the unit bound to this processor stop mining, building and moving
751
+ *
752
+ * ```js
753
+ * unitControl.stop();
754
+ * ```
537
755
  */
538
756
  function stop(): void;
539
757
 
540
758
  /**
541
- * Makes the unit bound to this processor move to the given position
759
+ * Makes the unit bound to this processor move to the given position.
760
+ *
761
+ * The unit tends to move in a straight line to the target location, which
762
+ * doesn't work in situations where the unit encounters an obstacle (such as
763
+ * a dagger trying to get past a wall).
764
+ *
765
+ * For those scenarios it's better to use `unitControl.pathfind`.
766
+ *
767
+ * ```js
768
+ * unitControl.move(10, 20);
769
+ * ```
542
770
  */
543
771
  function move(x: number, y: number): void;
544
772
 
545
773
  /**
546
- * Makes the unit bound to this processor approach the given position at the given radius
774
+ * Makes the unit bound to this processor approach the given position at the
775
+ * given radius
776
+ *
547
777
  * @param options.radius How distant to the position the unit can be
778
+ *
779
+ * ```js
780
+ * unitControl.approach({
781
+ * x: 15,
782
+ * y: 30,
783
+ * radius: 5,
784
+ * });
785
+ * ```
548
786
  */
549
787
  function approach(options: {
550
788
  x: number;
@@ -554,18 +792,62 @@ declare global {
554
792
  }): void;
555
793
 
556
794
  /**
557
- * Whether the unit bound to this processor should be boosted (floating)
795
+ * Makes the unit bound to this processor move to the given location.
796
+ *
797
+ * Uses the unit's pathfinding algorithm to decide how to reach the desired
798
+ * location instead of blidly going in a straight line.
799
+ *
800
+ * ```js
801
+ * // makes flares follow the player's cursor
802
+ * const { foreshadow1 } = getBuildings();
803
+ *
804
+ * const player = radar({
805
+ * building: foreshadow1,
806
+ * filters: ["player", "any", "any"],
807
+ * order: true,
808
+ * sort: "distance",
809
+ * });
810
+ *
811
+ * unitBind(Units.flare);
812
+ *
813
+ * unitControl.pathfind(player.shootX, player.shootY);
814
+ * ```
558
815
  */
559
- function boost(enable: boolean): void;
816
+ function pathfind(x: number, y: number): void;
560
817
 
561
818
  /**
562
- * Makes the unit bound to this processor move to the enemy spawn
819
+ * Makes the unit bound to this processor automatically pathfind to the
820
+ * nearest enemy core or drop point.
821
+ *
822
+ * Is the same as standard wave enemy pathfinding.
823
+ *
824
+ * ```js
825
+ * unitControl.autoPathfind();
826
+ * ```
563
827
  */
564
- function pathfind(): void;
828
+ function autoPathfind(): void;
829
+
830
+ /**
831
+ * Whether the unit bound to this processor should be boosted (floating)
832
+ *
833
+ * ```js
834
+ * unitControl.boost(true);
835
+ * ```
836
+ */
837
+ function boost(enable: boolean): void;
565
838
 
566
839
  /**
567
840
  * Makes the unit bound to this processor shoot/aim at the given position
841
+ *
568
842
  * @param options.shoot `true` to shoot, `false` to just aim
843
+ *
844
+ * ```js
845
+ * unitControl.target({
846
+ * x: 15,
847
+ * y: 30,
848
+ * shoot: true,
849
+ * });
850
+ * ```
569
851
  */
570
852
  function target(options: {
571
853
  x: number;
@@ -575,22 +857,26 @@ declare global {
575
857
  }): void;
576
858
 
577
859
  /**
578
- * Makes the unit bound to this processor target an unit with velocity prediction
860
+ * Makes the unit bound to this processor target an unit with velocity
861
+ * prediction
862
+ *
579
863
  * @param options.unit The shoot target
580
864
  * @param options.shoot `true` to shoot, `false` to just aim
581
865
  *
582
- * ```js
583
- * const player = unitRadar({
584
- * filters: ["player", "any", "any"],
585
- * order: true,
586
- * sort: "distance",
587
- * });
588
- *
589
- * unitControl.targetp({
590
- * shoot: true,
591
- * unit: player,
592
- * });
593
- * ```
866
+ * ```js
867
+ * unitBind(Units.flare);
868
+ *
869
+ * const player = unitRadar({
870
+ * filters: ["player", "any", "any"],
871
+ * order: true,
872
+ * sort: "distance",
873
+ * });
874
+ *
875
+ * unitControl.targetp({
876
+ * unit: player,
877
+ * shoot: true,
878
+ * });
879
+ * ```
594
880
  */
595
881
  function targetp(options: {
596
882
  /** The shoot target */
@@ -600,59 +886,94 @@ declare global {
600
886
  }): void;
601
887
 
602
888
  /**
603
- * Makes the unit bound to this processor drop it's held items onto the given target
604
- * @param target Where to drop the items, if `Blocks.air`, the unit will throw it's items away
889
+ * Makes the unit bound to this processor drop it's held items onto the
890
+ * given target
891
+ *
892
+ * Using this command sets the unit's action timeout.
893
+ *
894
+ * This command will be on cooldown for 1.5 seconds after the timeout has
895
+ * been set.
896
+ *
897
+ * @param target Where to drop the items, if `Blocks.air`, the unit will
898
+ * throw it's items away
605
899
  * @param amount How many items should be dropped
606
900
  *
607
- * ```js
608
- * const container = getBuilding("container1");
901
+ * ```js
902
+ * const { container1 } = getBuildings();
609
903
  *
610
- * // ...
904
+ * // ...
611
905
  *
612
- * // drop 40 items on the container
613
- * unitControl.itemDrop(container, 40);
906
+ * // drop 40 items on the container
907
+ * unitControl.itemDrop(container1, 40);
614
908
  *
615
- * // ...
909
+ * // ...
616
910
  *
617
- * // discard 10 items from the current unit
618
- * unitControl.itemDrop(Blocks.air, 10);
619
- * ```
911
+ * // discard 10 items from the current unit
912
+ * unitControl.itemDrop(Blocks.air, 10);
913
+ * ```
620
914
  */
621
915
  function itemDrop(
622
916
  target: BasicBuilding | typeof Blocks.air,
623
- amount: number
917
+ amount: number,
624
918
  ): void;
625
919
 
626
920
  /**
627
921
  * Makes the unit bound to this processor take items from a building
922
+ *
923
+ * Using this command sets the unit's action timeout.
924
+ *
925
+ * This command will be on cooldown for 1.5 seconds after the timeout has
926
+ * been set.
927
+ *
628
928
  * @param target The building that will have it's items taken
629
929
  * @param item The kind of item to take
630
930
  * @param amount How many items should be taken
631
931
  *
632
- * ```js
633
- * const vault = getBuilding("vault1");
932
+ * ```js
933
+ * const { vault1 } = getBuildings();
634
934
  *
635
- * // bind unit and move to the valult...
935
+ * // bind unit and move to the valult...
636
936
  *
637
- * unitControl.itemTake(vault, Items.graphite, 50);
937
+ * unitControl.itemTake(vault1, Items.graphite, 50);
638
938
  *
639
- * // do something with the graphite...
640
- * ```
939
+ * // do something with the graphite...
940
+ * ```
641
941
  */
642
942
  function itemTake(
643
943
  target: BasicBuilding,
644
944
  item: ItemSymbol,
645
- amount: number
945
+ amount: number,
646
946
  ): void;
647
947
 
648
948
  /**
649
949
  * Makes the unit bound to this processor drop one entity from it's payload
950
+ *
951
+ * Using this command sets the unit's action timeout.
952
+ *
953
+ * This command will be on cooldown for 1.5 seconds after the timeout has
954
+ * been set.
955
+ *
956
+ * ```js
957
+ * unitControl.payDrop();
958
+ * ```
650
959
  */
651
960
  function payDrop(): void;
652
961
 
653
962
  /**
654
963
  * Makes the unit bound to this processor take an entity into it's payload
964
+ *
965
+ * Using this command sets the unit's action timeout.
966
+ *
967
+ * This command will be on cooldown for 1.5 seconds after the timeout has
968
+ * been set.
969
+ *
655
970
  * @param options.takeUnits Whether to take units or buildings
971
+ *
972
+ * ```js
973
+ * unitControl.payTake({
974
+ * takeUnits: true,
975
+ * });
976
+ * ```
656
977
  */
657
978
  function payTake(options: {
658
979
  /** Whether to take units or buildings */
@@ -660,37 +981,54 @@ declare global {
660
981
  }): void;
661
982
 
662
983
  /**
663
- * Makes the unit bound to this processor enter/land on the
664
- * payload block the unit is on
984
+ * Makes the unit bound to this processor enter/land on the payload block
985
+ * the unit is on
986
+ *
987
+ * ```js
988
+ * unitControl.payEnter();
989
+ * ```
665
990
  */
666
991
  function payEnter(): void;
667
992
 
668
993
  /**
669
994
  * Makes the unit bound to this processor mine at the given position
995
+ *
996
+ * ```js
997
+ * unitControl.mine(10, 20);
998
+ * ```
670
999
  */
671
1000
  function mine(x: number, y: number): void;
672
1001
 
673
1002
  /**
674
1003
  * Sets the numeric flag of the unit bound to this processor
1004
+ *
1005
+ * ```js
1006
+ * // a unique id based on the coordinates of this processor
1007
+ * const processorId = Vars.thisx * Vars.mapw + Vars.thisy;
1008
+ *
1009
+ * unitControl.flag(processorId);
1010
+ * ```
675
1011
  */
676
1012
  function flag(value: number): void;
677
1013
 
678
1014
  /**
679
- * Makes the unit bound to this processor build a building with the
680
- * given properties
1015
+ * Makes the unit bound to this processor build a building with the given
1016
+ * properties
1017
+ *
681
1018
  * @param options.block The kind of building to build
682
1019
  * @param options.rotation The rotation of the building, ranges from 0 to 3
683
- * @param options.config The config of the building
684
- *
685
- * ```js
686
- * unitControl.build({
687
- * x: 10,
688
- * y: 20,
689
- * block: Blocks.sorter,
690
- * rotation: 1,
691
- * config: Items.silicon,
692
- * });
693
- * ```
1020
+ * @param options.config The configuration value to use, or a building from
1021
+ * which the configuration value will be copied.
1022
+ *
1023
+ * ```js
1024
+ * unitControl.build({
1025
+ * x: 10,
1026
+ * y: 20,
1027
+ * block: Blocks.sorter,
1028
+ * rotation: 1,
1029
+ * config: Items.silicon,
1030
+ * });
1031
+ * ```
694
1032
  */
695
1033
  function build(options: {
696
1034
  x: number;
@@ -699,51 +1037,116 @@ declare global {
699
1037
  block: BuildingSymbol;
700
1038
  /** The rotation of the building, ranges from 0 to 3 */
701
1039
  rotation: number;
702
- /** The config of the building */
703
- config?: unknown;
1040
+ /**
1041
+ * The configuration value to use, or a building from which the
1042
+ * configuration value will be copied.
1043
+ */
1044
+ config?: symbol | BasicBuilding;
704
1045
  }): void;
705
1046
 
706
1047
  /**
707
- * Makes the unit bound to this processor get data about a block at the given position
1048
+ * Makes the unit bound to this processor deconstruct the building at the
1049
+ * given position.
1050
+ *
1051
+ * ```js
1052
+ * unitControl.deconstruct(10, 20);
1053
+ * ```
1054
+ */
1055
+ function deconstruct(x: number, y: number): void;
1056
+
1057
+ /**
1058
+ * Makes the unit bound to this processor get data about a block at the
1059
+ * given position.
1060
+ *
1061
+ * ```js
1062
+ * // prints info about the block the player is pointing at
1063
+ * unitBind(Units.flare);
1064
+ *
1065
+ * const player = unitRadar({
1066
+ * filters: ["player", "any", "any"],
1067
+ * sort: "distance",
1068
+ * order: true,
1069
+ * });
1070
+ *
1071
+ * const { shootX, shootY } = player;
1072
+ * const [type, building, floor] = unitControl.getBlock(shootX, shootY);
1073
+ *
1074
+ * print`
1075
+ * block: ${type}
1076
+ * floor: ${floor}
1077
+ * size: ${building.size ?? 1}
1078
+ * `;
1079
+ * printFlush();
1080
+ * ```
708
1081
  */
709
1082
  function getBlock<T extends BasicBuilding = AnyBuilding>(
710
1083
  x: number,
711
- y: number
1084
+ y: number,
712
1085
  ): [
713
1086
  type: BlockSymbol | undefined,
714
1087
  building: T | undefined,
715
- floor: EnvBlockSymbol | OreSymbol | undefined
1088
+ floor: EnvBlockSymbol | OreSymbol | undefined,
716
1089
  ];
717
1090
 
718
1091
  /**
719
- * Checks if the unit bound to this processor is within a radius of a given position.
1092
+ * Checks if the unit bound to this processor is within a radius of a given
1093
+ * position.
1094
+ *
1095
+ * ```js
1096
+ * if (Vars.unit == undefined) {
1097
+ * unitBind(Units.flare);
1098
+ * }
1099
+ *
1100
+ * const player = unitRadar({
1101
+ * filters: ["player", "any", "any"],
1102
+ * sort: "distance",
1103
+ * order: true,
1104
+ * });
1105
+ *
1106
+ * const nearby = unitControl.within({
1107
+ * x: player.x,
1108
+ * y: player.y,
1109
+ * radius: 5,
1110
+ * });
1111
+ *
1112
+ * print`nearby: ${nearby}`;
1113
+ * printFlush();
1114
+ * ```
720
1115
  */
721
1116
  function within(options: { x: number; y: number; radius: number }): boolean;
722
1117
 
723
1118
  /**
724
1119
  * Resets the AI of the unit.
725
1120
  *
726
- * Calling `unbind` does not actually unbind the unit from the processor,
727
- * it just makes the unit resume its natural behavior.
1121
+ * Calling `unbind` does not actually unbind the unit from the processor, it
1122
+ * just makes the unit resume its natural behavior.
1123
+ *
1124
+ * ```js
1125
+ * unitControl.unbind();
1126
+ * ```
728
1127
  */
729
1128
  function unbind(): void;
730
1129
  }
731
1130
 
732
1131
  /**
733
1132
  * Finds an unit near the unit bound to this processor
734
- * @param options.filters The filters for selecting a target. Use "any" for any target.
735
- * @param options.order `true` to get the first result, `false` to get the last result.
1133
+ *
1134
+ * @param options.filters The filters for selecting a target. Use "any" for
1135
+ * any target.
1136
+ * @param options.order `true` to get the first result, `false` to get the
1137
+ * last result.
736
1138
  * @param options.sort The method on which the results should be sorted
737
1139
  *
738
- * Example:
739
- * ```js
740
- * // returns the furthest enemy unit
741
- * const result = unitRadar({
742
- * filters: ["enemy", "any", "any"],
743
- * order: false,
744
- * sort: "distance",
745
- * });
746
- * ```
1140
+ * Example:
1141
+ *
1142
+ * ```js
1143
+ * // returns the furthest enemy unit
1144
+ * const result = unitRadar({
1145
+ * filters: ["enemy", "any", "any"],
1146
+ * order: false,
1147
+ * sort: "distance",
1148
+ * });
1149
+ * ```
747
1150
  */
748
1151
  function unitRadar<T extends BasicUnit = AnyUnit>(options: {
749
1152
  /** The filters for selecting a target. Use "any" for any target. */
@@ -757,61 +1160,66 @@ declare global {
757
1160
  /** Uses the unit bound to this processor to find specific types of blocks */
758
1161
  namespace unitLocate {
759
1162
  /**
760
- * Uses the unit bound to this processor to find an ore vein anywhere on the map
1163
+ * Uses the unit bound to this processor to find an ore vein anywhere on the
1164
+ * map
1165
+ *
761
1166
  * @param ore The kind of item the ore should contain
762
1167
  *
763
- * ```js
764
- * const [found, x, y] = unitLocate.ore(Items.copper);
1168
+ * ```js
1169
+ * const [found, x, y] = unitLocate.ore(Items.copper);
765
1170
  *
766
- * if (found) {
767
- * unitControl.approach({ x, y, radius: 5 });
768
- * }
769
- * ```
1171
+ * if (found) {
1172
+ * unitControl.approach({ x, y, radius: 5 });
1173
+ * }
1174
+ * ```
770
1175
  */
771
1176
  function ore(
772
- ore: ItemSymbol
1177
+ ore: ItemSymbol,
773
1178
  ): [found: false] | [found: true, x: number, y: number];
774
1179
 
775
1180
  /**
776
- * Uses the unit bound to this processor to find a building anywhere on the map
1181
+ * Uses the unit bound to this processor to find a building anywhere on the
1182
+ * map
1183
+ *
777
1184
  * @param options.group The group that the building belongs to
778
- * @param options.enemy Whether it should be an enemy building or an ally one
779
- *
780
- * ```js
781
- * const vault = getBuilding("vault1");
782
- * const takeAmount = 100;
783
- *
784
- * unitBind(Units.mega);
785
- *
786
- * // we don't use the `found` variable
787
- * // because we always have our own core
788
- * const [, x, y, core] = unitLocate.building({
789
- * group: "core",
790
- * enemy: false,
791
- * });
792
- *
793
- * const location = {
794
- * x,
795
- * y,
796
- * radius: 5,
797
- * };
798
- *
799
- * if (!unitControl.within(location) && Vars.unit.totalItems == 0) {
800
- * // if the unit has no items and it is not near
801
- * // the core, move it to the core
802
- * // and take 100 copper
803
- * unitControl.approach(location);
804
- * unitControl.itemTake(core, Items.copper, takeAmount);
805
- * } else {
806
- * // else, approach the vault and drop the items on it
807
- * unitControl.approach({
808
- * x: vault.x,
809
- * y: vault.y,
810
- * radius: 5,
811
- * });
812
- * unitControl.itemDrop(vault, takeAmount);
813
- * }
814
- * ```
1185
+ * @param options.enemy Whether it should be an enemy building or an ally
1186
+ * one
1187
+ *
1188
+ * ```js
1189
+ * const vault = getBuilding("vault1");
1190
+ * const takeAmount = 100;
1191
+ *
1192
+ * unitBind(Units.mega);
1193
+ *
1194
+ * // we don't use the `found` variable
1195
+ * // because we always have our own core
1196
+ * const [, x, y, core] = unitLocate.building({
1197
+ * group: "core",
1198
+ * enemy: false,
1199
+ * });
1200
+ *
1201
+ * const location = {
1202
+ * x,
1203
+ * y,
1204
+ * radius: 5,
1205
+ * };
1206
+ *
1207
+ * if (!unitControl.within(location) && Vars.unit.totalItems == 0) {
1208
+ * // if the unit has no items and it is not near
1209
+ * // the core, move it to the core
1210
+ * // and take 100 copper
1211
+ * unitControl.approach(location);
1212
+ * unitControl.itemTake(core, Items.copper, takeAmount);
1213
+ * } else {
1214
+ * // else, approach the vault and drop the items on it
1215
+ * unitControl.approach({
1216
+ * x: vault.x,
1217
+ * y: vault.y,
1218
+ * radius: 5,
1219
+ * });
1220
+ * unitControl.itemDrop(vault, takeAmount);
1221
+ * }
1222
+ * ```
815
1223
  */
816
1224
  function building<T extends BasicBuilding = AnyBuilding>(options: {
817
1225
  /** The group that the building belongs to */
@@ -821,436 +1229,76 @@ declare global {
821
1229
  }): [found: false] | [found: true, x: number, y: number, building: T];
822
1230
 
823
1231
  /**
824
- * Uses the unit bound to this processor to find an enemy spawn anywhere on the map.
1232
+ * Uses the unit bound to this processor to find an enemy spawn anywhere on
1233
+ * the map.
825
1234
  *
826
1235
  * Returns the enemy spawn point or its core, if it exists.
827
1236
  *
828
- * ```js
829
- * const [found, x, y, core] = unitLocate.spawn();
830
- *
831
- * if (!found) {
832
- * print("No enemy core found");
833
- * } else if (core) {
834
- * print`core location at (${x}, ${y})`;
835
- * } else {
836
- * print`enemy spawn at (${x}, ${y})`;
837
- * }
1237
+ * ```js
1238
+ * const [found, x, y, core] = unitLocate.spawn();
1239
+ *
1240
+ * if (!found) {
1241
+ * print("No enemy core found");
1242
+ * } else if (core) {
1243
+ * print`core location at (${x}, ${y})`;
1244
+ * } else {
1245
+ * print`enemy spawn at (${x}, ${y})`;
1246
+ * }
838
1247
  *
839
- * printFlush();
840
- * ```
1248
+ * printFlush();
1249
+ * ```
841
1250
  */
842
1251
  function spawn<T extends BasicBuilding = AnyBuilding>():
843
- | [found: false]
844
- | [found: true, x: number, y: number, building: T];
1252
+ [found: false] | [found: true, x: number, y: number, building: T];
845
1253
 
846
1254
  /**
847
- * Uses the unit bound to this processor to find a damaged ally building anywhere on the map
848
- *
849
- * ```js
850
- * const [found, x, y, building] = unitLocate.damaged();
851
- *
852
- * if (found) {
853
- * print`go fix a ${building} at (${x}, ${y})`;
854
- * } else {
855
- * print("No damaged building found");
856
- * }
857
- * printFlush();
858
- * ```
1255
+ * Uses the unit bound to this processor to find a damaged ally building
1256
+ * anywhere on the map
1257
+ *
1258
+ * ```js
1259
+ * const [found, x, y, building] = unitLocate.damaged();
1260
+ *
1261
+ * if (found) {
1262
+ * print`go fix a ${building} at (${x}, ${y})`;
1263
+ * } else {
1264
+ * print("No damaged building found");
1265
+ * }
1266
+ * printFlush();
1267
+ * ```
859
1268
  */
860
1269
  function damaged<T extends BasicBuilding = AnyBuilding>():
861
- | [found: false]
862
- | [found: true, x: number, y: number, building: T];
1270
+ [found: false] | [found: true, x: number, y: number, building: T];
863
1271
  }
864
1272
 
865
1273
  /**
866
1274
  * Jumps to the top of the instruction stack.
867
1275
  *
868
- * ```js
869
- * const { enabled } = getBuilding("switch1");
1276
+ * ```js
1277
+ * const { switch1 } = getBuildings();
870
1278
  *
871
- * if (!enabled) endScript();
872
- * // do something when the switch is enabled
873
- * ```
1279
+ * if (!switch1.enabled) endScript();
1280
+ * // do something when the switch is enabled
1281
+ * ```
874
1282
  */
875
1283
  function endScript(): never;
876
1284
 
877
1285
  /**
878
- * Halts the execution of this processor. Can be used to debug
879
- * code and analyze the processor registers.
1286
+ * Halts the execution of this processor. Can be used to debug code and
1287
+ * analyze the processor registers.
880
1288
  *
881
- * ```js
882
- * // stop the processor to debug variables
883
- * stopScript();
884
- * ```
1289
+ * ```js
1290
+ * // stop the processor to debug variables
1291
+ * stopScript();
1292
+ * ```
885
1293
  */
886
1294
  function stopScript(): never;
887
1295
 
888
- /** Gets block data from the map. Available ONLY for world processors. */
889
- namespace getBlock {
890
- /** Gets the floor type on the given location */
891
- function floor(x: number, y: number): EnvBlockSymbol;
892
-
893
- /** Gets the ore type on the given location. `Blocks.air` if there is no ore */
894
- function ore(x: number, y: number): OreSymbol | typeof Blocks.air;
895
-
896
- /** Gets the block type on the give location. `Blocks.air` if there is no block. */
897
- function block(x: number, y: number): BlockSymbol;
898
-
899
- /** Gets the building on the given location. `undefined` if there is no building. */
900
- function building<T extends BasicBuilding = AnyBuilding>(
901
- x: number,
902
- y: number
903
- ): T | undefined;
904
- }
905
-
906
- /** Sets block data on a given location. World processor ONLY. */
907
- namespace setBlock {
908
- // TODO: maybe have a separate floor symbol type?
909
- /** Sets the floor of the tile at the given location. */
910
- function floor(x: number, y: number, to: EnvBlockSymbol): void;
911
-
912
- /** Sets the ore at the given location. Use `Blocks.air` to remove any ore. */
913
- function ore(x: number, y: number, to: OreSymbol | typeof Blocks.air): void;
914
-
915
- /** Sets the block at a given location, it can be a regular building or an environment block. */
916
- function block(options: {
917
- x: number;
918
- y: number;
919
- to: EnvBlockSymbol | BuildingSymbol;
920
- team: TeamSymbol;
921
- rotation: number;
922
- }): void;
923
- }
924
-
925
1296
  /**
926
- * Spawns an unit at the given location. World processor ONLY.
927
- *
928
- * @param options.rotation The initial rotation of the unit in degrees.
929
- */
930
- function spawnUnit<T extends BasicUnit = AnyUnit>(options: {
931
- type: UnitSymbol;
932
- x: number;
933
- y: number;
934
- team: TeamSymbol;
935
- /** The initial rotation of the unit in degrees. */
936
- rotation?: number;
937
- }): T;
938
-
939
- /** Contains the variants for the `applyStatus` instruction. World processor ONLY. */
940
- namespace applyStatus {
941
- /**
942
- * Applies a status effect to the given unit.
943
- *
944
- * The only status effects that don't require a duration are `overdrive` and `boss`.
945
- */
946
- function apply(
947
- status: Exclude<TUnitEffect, "overdrive" | "boss">,
948
- unit: BasicUnit,
949
- duration: number
950
- ): void;
951
-
952
- function apply(status: "overdrive" | "boss", unit: BasicUnit): void;
953
-
954
- /**
955
- * Removes a status effect to the given unit.
956
- */
957
- function clear(status: TUnitEffect, unit: BasicUnit): void;
958
- }
959
-
960
- /**
961
- * Spawns an enemy wave, can be used even if there is an already active wave.
962
- *
963
- * World processor ONLY.
964
- */
965
- function spawnWave(natural: true): void;
966
- function spawnWave(natural: false, x: number, y: number): void;
967
-
968
- /** Contains the multiple variants of the `set rule` instruction. World processor ONLY. */
969
- namespace setRule {
970
- /** Sets the wave countdown in seconds. */
971
- function currentWaveTime(seconds: number): void;
972
-
973
- /** Enables/disables the wave timer. */
974
- function waveTimer(enabled: boolean): void;
975
-
976
- /** Allows or prevents waves from spawning. */
977
- function waves(enabled: boolean): void;
978
-
979
- /** Sets the current wave number. */
980
- function wave(number: number): void;
981
-
982
- /** Sets the time between waves in seconds. */
983
- function waveSpacing(seconds: number): void;
984
-
985
- /** Sets wether waves can be manually summoned by pressing the play button. */
986
- function waveSending(enabled: boolean): void;
987
-
988
- /** Sets wether the gamemode is the attack mode */
989
- function attackMode(enabled: boolean): void;
990
-
991
- /** Sets the radius of the no-build zone around enemy cores. */
992
- function enemyCoreBuildRadius(radius: number): void;
993
-
994
- /** Sets the radius around enemy wave drop zones. */
995
- function dropZoneRadius(radius: number): void;
996
-
997
- /** Sets the base unit cap. */
998
- function unitCap(cap: number): void;
999
-
1000
- /** Sets the playable map area. Blocks that are out of the new bounds will be removed. */
1001
- function mapArea(options: {
1002
- x: number;
1003
- y: number;
1004
- width: number;
1005
- height: number;
1006
- }): void;
1007
-
1008
- /** Sets wether ambient lighting is enabled */
1009
- function lighting(enabled: boolean): void;
1010
-
1011
- /**
1012
- * Sets the ambient light color.
1013
- *
1014
- * `packColor` can be used to get the rgba data recevied by this function.
1015
- *
1016
- *
1017
- * ```js
1018
- * // enables lighting and sets the color to gray
1019
- * setRule.lighting(true);
1020
- * setRule.ambientLight(packColor(0.5, 0.5, 0.5, 1));
1021
- * ```
1022
- */
1023
- function ambientLight(rgbaData: number): void;
1024
-
1025
- /** Sets the multiplier for the energy output of solar panels. */
1026
- function solarMultiplier(multiplier: number): void;
1027
-
1028
- /**
1029
- * Sets the build speed multiplier of a team.
1030
- * The multiplier will always be clamped between `0.001` and `50`.
1031
- */
1032
- function buildSpeed(team: TeamSymbol, multiplier: number): void;
1033
-
1034
- /**
1035
- * Sets the speed multiplier for unit factories.
1036
- * The multiplier will always be clamped between `0` and `50`.
1037
- */
1038
- function unitBuildSpeed(team: TeamSymbol, multiplier: number): void;
1039
-
1040
- /** Sets the build cost multiplier for constructing units. */
1041
- function unitCost(team: TeamSymbol, multiplier: number): void;
1042
-
1043
- /** Sets the damage multiplier for units on a given team. */
1044
- function unitDamage(team: TeamSymbol, multiplier: number): void;
1045
-
1046
- /** Sets the block health multiplier for a given team. */
1047
- function blockHealth(team: TeamSymbol, multiplier: number): void;
1048
-
1049
- /** Sets the block damage multiplier for a given team. */
1050
- function blockDamage(team: TeamSymbol, multiplier: number): void;
1051
-
1052
- /**
1053
- * Sets the Real Time Strategy minimum weight for a team.
1054
- *
1055
- * In other words it, sets the minimum "advantage" needed for a squad to attack.
1056
- * The higher the value, the more cautious the squad is.
1057
- */
1058
-
1059
- function rtsMinWeight(team: TeamSymbol, value: number): void;
1060
-
1061
- /**
1062
- * Sets the Real Time Strategy minimum size of attack squads of a team.
1063
- *
1064
- * The higher the value, the more units are required before a squad attacks.
1065
- */
1066
- function rtsMinSquad(team: TeamSymbol, value: number): void;
1067
- }
1068
-
1069
- /**
1070
- * Writes the contents of the print buffer in the selected mode
1071
- * and clears the buffer afterwards. World processor ONLY.
1297
+ * Sets the execution rate of the current processor in instructions per tick.
1072
1298
  *
1073
1299
  * ```js
1074
- * print("Hello");
1075
- * flushMessage.announce(4); // lasts 4 seconds
1076
- * wait(5);
1077
- * print("World");
1078
- * flushMessage.toast(4);
1079
- * wait(5);
1300
+ * setRate(1000);
1080
1301
  * ```
1081
1302
  */
1082
- namespace flushMessage {
1083
- /** Shows a nofication at the top of the screen */
1084
- function notify(): void;
1085
- /** Puts the content on the top left corner of the screen */
1086
- function mission(): void;
1087
- /**
1088
- * Puts the content on the middle of the screen
1089
- *
1090
- * @param duration The duration, in seconds
1091
- */
1092
- function announce(duration: number): void;
1093
- /**
1094
- * Puts the content on the middle top of the screen
1095
- *
1096
- * @param duration The duration, in seconds
1097
- */
1098
- function toast(duration: number): void;
1099
- }
1100
-
1101
- /** Controls the player camera. World processor ONLY. */
1102
- namespace cutscene {
1103
- /** Moves the player's camera to the given location. */
1104
- function pan(options: { x: number; y: number; speed: number }): void;
1105
- /** Zooms the player camera to the desired level */
1106
- function zoom(level: number): void;
1107
- /** Gives the camera control back to the player */
1108
- function stop(): void;
1109
- }
1110
-
1111
- /** Creates an explosion. World processor ONLY. */
1112
- function explosion(options: {
1113
- team: TeamSymbol;
1114
- x: number;
1115
- y: number;
1116
- radius: number;
1117
- damage: number;
1118
- air: boolean;
1119
- ground: boolean;
1120
- pierce: boolean;
1121
- }): void;
1122
-
1123
- /** Sets the speed of this world processor in instructions per tick. World processor ONLY. */
1124
1303
  function setRate(ipt: number): void;
1125
-
1126
- /** Contains the variants of the `fetch` instruction. World processor ONLY. */
1127
- namespace fetch {
1128
- /**
1129
- * Gets an unit from the given team
1130
- *
1131
- * The index starts at 0.
1132
- *
1133
- * ```js
1134
- * const count = fetch.unitCount(Teams.sharded);
1135
- * for(let i = 0; i < count; i++) {
1136
- * const unit = fetch.unit(Teams.sharded, i);
1137
- * print`x: ${unit.x}, y: ${unit.y}\n`;
1138
- * }
1139
- * printFlush();
1140
- * ```
1141
- */
1142
- function unit<T extends BasicUnit = AnyUnit>(
1143
- team: TeamSymbol,
1144
- index: number
1145
- ): T;
1146
- /**
1147
- * Gets the amount of units existing on a given team.
1148
- *
1149
- * ```js
1150
- * const count = fetch.unitCount(Teams.sharded);
1151
- * for(let i = 0; i < count; i++) {
1152
- * const unit = fetch.unit(Teams.sharded, i);
1153
- * print`x: ${unit.x}, y: ${unit.y}\n`;
1154
- * }
1155
- * printFlush();
1156
- * ```
1157
- */
1158
- function unitCount(team: TeamSymbol): number;
1159
- /**
1160
- * Gets a player from a team.
1161
- *
1162
- * The index starts at 0.
1163
- *
1164
- * ```js
1165
- * const count = fetch.playerCount(Teams.sharded);
1166
- * for(let i = 0; i < count; i++) {
1167
- * const player = fetch.player(Teams.sharded, i);
1168
- * print`x: ${player.x}, y: ${player.y}\n`;
1169
- * }
1170
- * printFlush();
1171
- * ```
1172
- */
1173
- function player<T extends BasicUnit = AnyUnit>(
1174
- team: TeamSymbol,
1175
- index: number
1176
- ): T;
1177
- /**
1178
- * Gets the amount of players existing on a given team.
1179
- *
1180
- * ```js
1181
- * const count = fetch.playerCount(Teams.sharded);
1182
- * for(let i = 0; i < count; i++) {
1183
- * const player = fetch.player(Teams.sharded, i);
1184
- * print`x: ${player.x}, y: ${player.y}\n`;
1185
- * }
1186
- * printFlush();
1187
- * ```
1188
- */
1189
- function playerCount(team: TeamSymbol): number;
1190
- /**
1191
- * Gets a core from a team.
1192
- *
1193
- * The index of the starts at 0.
1194
- *
1195
- * ```js
1196
- * const count = fetch.coreCount(Teams.sharded);
1197
- * for(let i = 0; i < count; i++) {
1198
- * const core = fetch.core(Teams.sharded, i);
1199
- * print`x: ${core.x}, y: ${core.y}\n`;
1200
- * }
1201
- * printFlush();
1202
- * ```
1203
- */
1204
- function core(team: TeamSymbol, index: number): AnyBuilding;
1205
- /**
1206
- * Gets the amount of cores existing on a given team.
1207
- * ```js
1208
- * const count = fetch.coreCount(Teams.sharded);
1209
- * for(let i = 0; i < count; i++) {
1210
- * const core = fetch.core(Teams.sharded, i);
1211
- * print`x: ${core.x}, y: ${core.y}\n`;
1212
- * }
1213
- * printFlush();
1214
- * ```
1215
- */
1216
- function coreCount(team: TeamSymbol): number;
1217
- /**
1218
- * Gets a building from a team.
1219
- *
1220
- * The index starts at 0.
1221
- *
1222
- * ```js
1223
- * const count = fetch.buildCount(Teams.sharded, Blocks.router);
1224
- * for(let i = 0; i < count; i++) {
1225
- * const router = fetch.build(Teams.sharded, i, Blocks.router);
1226
- * print`x: ${router.x}, y: ${router.y}\n`;
1227
- * }
1228
- * printFlush();
1229
- * ```
1230
- */
1231
- function build<T extends BasicBuilding = AnyBuilding>(
1232
- team: TeamSymbol,
1233
- index: number,
1234
- block: BuildingSymbol
1235
- ): T;
1236
- /**
1237
- * Gets the amount of buildings existing on a given team.
1238
- *
1239
- * ```js
1240
- * const count = fetch.buildCount(Teams.sharded, Blocks.router);
1241
- * for(let i = 0; i < count; i++) {
1242
- * const router = fetch.build(Teams.sharded, i, Blocks.router)
1243
- * print`x: ${router.x}, y: ${router.y}\n`
1244
- * }
1245
- * printFlush()
1246
- * ```
1247
- */
1248
- function buildCount(team: TeamSymbol, block: BuildingSymbol): number;
1249
- }
1250
-
1251
- /** Checks if a global flag is set. World processor ONLY. */
1252
- function getFlag(flag: string): boolean;
1253
-
1254
- /** Sets a global flag. World processor ONLY. */
1255
- function setFlag(flag: string, value: boolean): void;
1256
1304
  }