mlogjs 0.2.0 → 0.3.0-beta.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 (264) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +68 -18
  3. package/build/Compiler.js +32 -47
  4. package/build/Compiler.js.map +1 -1
  5. package/build/CompilerError.js +11 -0
  6. package/build/CompilerError.js.map +1 -0
  7. package/build/Scope.js +17 -7
  8. package/build/Scope.js.map +1 -1
  9. package/build/bin.js +45 -12
  10. package/build/bin.js.map +1 -1
  11. package/build/handlers/BlockStatement.js.map +1 -1
  12. package/build/handlers/CallExpression.js.map +1 -1
  13. package/build/handlers/File.js +9 -0
  14. package/build/handlers/File.js.map +1 -0
  15. package/build/handlers/ForStatement.js.map +1 -1
  16. package/build/handlers/Function.js +20 -9
  17. package/build/handlers/Function.js.map +1 -1
  18. package/build/handlers/IfStatement.js.map +1 -1
  19. package/build/handlers/Literal.js +11 -14
  20. package/build/handlers/Literal.js.map +1 -1
  21. package/build/handlers/Object.js +16 -5
  22. package/build/handlers/Object.js.map +1 -1
  23. package/build/handlers/OperationExpressions.js +6 -1
  24. package/build/handlers/OperationExpressions.js.map +1 -1
  25. package/build/handlers/Program.js +1 -1
  26. package/build/handlers/Program.js.map +1 -1
  27. package/build/handlers/Statements.js.map +1 -1
  28. package/build/handlers/TemplateExpression.js.map +1 -1
  29. package/build/handlers/VariableDeclaration.js +25 -9
  30. package/build/handlers/VariableDeclaration.js.map +1 -1
  31. package/build/handlers/WhileStatement.js.map +1 -1
  32. package/build/handlers/index.js +1 -0
  33. package/build/handlers/index.js.map +1 -1
  34. package/build/index.js +5 -5
  35. package/build/index.js.map +1 -1
  36. package/build/initScope.js +40 -0
  37. package/build/initScope.js.map +1 -0
  38. package/build/instructions/InstructionBase.js +1 -1
  39. package/build/instructions/InstructionBase.js.map +1 -1
  40. package/build/instructions/JumpInstruction.js +1 -1
  41. package/build/instructions/JumpInstruction.js.map +1 -1
  42. package/build/instructions/OperationInstruction.js.map +1 -1
  43. package/build/macros/Building.js +16 -8
  44. package/build/macros/Building.js.map +1 -1
  45. package/build/macros/Function.js +1 -1
  46. package/build/macros/Function.js.map +1 -1
  47. package/build/macros/Math.js +13 -8
  48. package/build/macros/Math.js.map +1 -1
  49. package/build/macros/Memory.js +7 -5
  50. package/build/macros/Memory.js.map +1 -1
  51. package/build/macros/Namespace.js +24 -11
  52. package/build/macros/Namespace.js.map +1 -1
  53. package/build/macros/Other.js +2 -1
  54. package/build/macros/Other.js.map +1 -1
  55. package/build/macros/RawValue.js +2 -1
  56. package/build/macros/RawValue.js.map +1 -1
  57. package/build/macros/commands/{control.js → Control.js} +4 -3
  58. package/build/macros/commands/Control.js.map +1 -0
  59. package/build/macros/commands/Draw.js +4 -3
  60. package/build/macros/commands/Draw.js.map +1 -1
  61. package/build/macros/commands/DrawFlush.js +2 -1
  62. package/build/macros/commands/DrawFlush.js.map +1 -1
  63. package/build/macros/commands/GetLink.js +8 -4
  64. package/build/macros/commands/GetLink.js.map +1 -1
  65. package/build/macros/commands/Lookup.js +5 -4
  66. package/build/macros/commands/Lookup.js.map +1 -1
  67. package/build/macros/commands/Print.js +5 -1
  68. package/build/macros/commands/Print.js.map +1 -1
  69. package/build/macros/commands/PrintFlush.js +2 -1
  70. package/build/macros/commands/PrintFlush.js.map +1 -1
  71. package/build/macros/commands/Radar.js +16 -12
  72. package/build/macros/commands/Radar.js.map +1 -1
  73. package/build/macros/commands/Sensor.js +4 -3
  74. package/build/macros/commands/Sensor.js.map +1 -1
  75. package/build/macros/commands/UnitBind.js +2 -1
  76. package/build/macros/commands/UnitBind.js.map +1 -1
  77. package/build/macros/commands/UnitControl.js +13 -8
  78. package/build/macros/commands/UnitControl.js.map +1 -1
  79. package/build/macros/commands/UnitLocate.js +29 -8
  80. package/build/macros/commands/UnitLocate.js.map +1 -1
  81. package/build/macros/commands/UnitRadar.js +17 -10
  82. package/build/macros/commands/UnitRadar.js.map +1 -1
  83. package/build/macros/commands/Wait.js +2 -1
  84. package/build/macros/commands/Wait.js.map +1 -1
  85. package/build/operators.js.map +1 -1
  86. package/build/types.js +1 -1
  87. package/build/types.js.map +1 -1
  88. package/build/utils.js +7 -2
  89. package/build/utils.js.map +1 -1
  90. package/build/values/BaseValue.js +5 -5
  91. package/build/values/BaseValue.js.map +1 -1
  92. package/build/values/FunctionValue.js +25 -13
  93. package/build/values/FunctionValue.js.map +1 -1
  94. package/build/values/LiteralValue.js +5 -4
  95. package/build/values/LiteralValue.js.map +1 -1
  96. package/build/values/ObjectValue.js +11 -6
  97. package/build/values/ObjectValue.js.map +1 -1
  98. package/build/values/StoreValue.js +3 -2
  99. package/build/values/StoreValue.js.map +1 -1
  100. package/build/values/TempValue.js +18 -7
  101. package/build/values/TempValue.js.map +1 -1
  102. package/build/values/VoidValue.js +8 -7
  103. package/build/values/VoidValue.js.map +1 -1
  104. package/dist/bin.cjs +82 -0
  105. package/dist/bin.cjs.map +1 -0
  106. package/dist/index.cjs +2187 -0
  107. package/dist/index.cjs.map +1 -0
  108. package/dist/index.mjs +2162 -0
  109. package/dist/index.mjs.map +1 -0
  110. package/dist/types/Compiler.d.ts +26 -0
  111. package/dist/types/CompilerError.d.ts +9 -0
  112. package/dist/types/Scope.d.ts +24 -0
  113. package/dist/types/bin.d.ts +1 -0
  114. package/dist/types/handlers/BlockStatement.d.ts +2 -0
  115. package/dist/types/handlers/CallExpression.d.ts +3 -0
  116. package/dist/types/handlers/File.d.ts +2 -0
  117. package/dist/types/handlers/ForStatement.d.ts +2 -0
  118. package/{build → dist/types}/handlers/Function.d.ts +1 -0
  119. package/{build → dist/types}/handlers/Identifier.d.ts +0 -0
  120. package/dist/types/handlers/IfStatement.d.ts +2 -0
  121. package/dist/types/handlers/Literal.d.ts +5 -0
  122. package/{build → dist/types}/handlers/Object.d.ts +2 -0
  123. package/{build → dist/types}/handlers/OperationExpressions.d.ts +1 -0
  124. package/dist/types/handlers/Program.d.ts +2 -0
  125. package/dist/types/handlers/Statements.d.ts +5 -0
  126. package/dist/types/handlers/TemplateExpression.d.ts +2 -0
  127. package/dist/types/handlers/Typescript.d.ts +7 -0
  128. package/dist/types/handlers/VariableDeclaration.d.ts +3 -0
  129. package/dist/types/handlers/WhileStatement.d.ts +3 -0
  130. package/{build → dist/types}/handlers/index.d.ts +2 -0
  131. package/dist/types/index.d.ts +2 -0
  132. package/dist/types/initScope.d.ts +5 -0
  133. package/{build → dist/types}/instructions/AddressResolver.d.ts +1 -1
  134. package/{build → dist/types}/instructions/ControlInstructions.d.ts +0 -3
  135. package/{build → dist/types}/instructions/EndInstruction.d.ts +0 -0
  136. package/{build → dist/types}/instructions/InstructionBase.d.ts +4 -4
  137. package/{build → dist/types}/instructions/JumpInstruction.d.ts +1 -1
  138. package/{build → dist/types}/instructions/OperationInstruction.d.ts +1 -1
  139. package/{build → dist/types}/instructions/SetCounterInstruction.d.ts +0 -0
  140. package/{build → dist/types}/instructions/SetInstruction.d.ts +1 -0
  141. package/{build → dist/types}/instructions/ZeroSpaceInstruction.d.ts +0 -0
  142. package/{build → dist/types}/instructions/index.d.ts +0 -0
  143. package/{build → dist/types}/macros/Building.d.ts +1 -2
  144. package/dist/types/macros/Entities.d.ts +11 -0
  145. package/dist/types/macros/Function.d.ts +13 -0
  146. package/{build/macros/Draw.d.ts → dist/types/macros/GetGlobal.d.ts} +1 -1
  147. package/{build → dist/types}/macros/Math.d.ts +0 -0
  148. package/{build → dist/types}/macros/Memory.d.ts +0 -0
  149. package/{build → dist/types}/macros/Namespace.d.ts +0 -5
  150. package/{build → dist/types}/macros/Other.d.ts +0 -0
  151. package/{build → dist/types}/macros/RawValue.d.ts +0 -0
  152. package/{build/macros/commands/Asm.d.ts → dist/types/macros/commands/Control.d.ts} +1 -1
  153. package/{build/macros/helpers/GetVar.d.ts → dist/types/macros/commands/Draw.d.ts} +1 -1
  154. package/{build → dist/types}/macros/commands/DrawFlush.d.ts +1 -1
  155. package/{build/macros/commands/Draw.d.ts → dist/types/macros/commands/End.d.ts} +1 -1
  156. package/{build → dist/types}/macros/commands/GetLink.d.ts +0 -0
  157. package/{build → dist/types}/macros/commands/Lookup.d.ts +0 -0
  158. package/{build → dist/types}/macros/commands/Print.d.ts +1 -1
  159. package/{build → dist/types}/macros/commands/PrintFlush.d.ts +1 -1
  160. package/{build → dist/types}/macros/commands/Radar.d.ts +0 -0
  161. package/{build → dist/types}/macros/commands/Sensor.d.ts +0 -0
  162. package/{build → dist/types}/macros/commands/UnitBind.d.ts +1 -1
  163. package/dist/types/macros/commands/UnitControl.d.ts +5 -0
  164. package/{build → dist/types}/macros/commands/UnitLocate.d.ts +0 -0
  165. package/{build → dist/types}/macros/commands/UnitRadar.d.ts +0 -0
  166. package/{build → dist/types}/macros/commands/Wait.d.ts +1 -1
  167. package/{build → dist/types}/macros/commands/index.d.ts +1 -0
  168. package/{build → dist/types}/macros/index.d.ts +0 -1
  169. package/{build → dist/types}/operators.d.ts +1 -1
  170. package/dist/types/types.d.ts +209 -0
  171. package/dist/types/utils.d.ts +24 -0
  172. package/dist/types/values/BaseValue.d.ts +7 -0
  173. package/dist/types/values/DestructuringValue.d.ts +17 -0
  174. package/{build → dist/types}/values/FunctionValue.d.ts +21 -8
  175. package/{build → dist/types}/values/LiteralValue.d.ts +2 -1
  176. package/dist/types/values/ObjectValue.d.ts +23 -0
  177. package/dist/types/values/SenseableValue.d.ts +23 -0
  178. package/dist/types/values/StackValue.d.ts +16 -0
  179. package/{build → dist/types}/values/StoreValue.d.ts +7 -3
  180. package/{build → dist/types}/values/TempValue.d.ts +9 -2
  181. package/dist/types/values/ValueOwner.d.ts +27 -0
  182. package/dist/types/values/VoidValue.d.ts +16 -0
  183. package/{build → dist/types}/values/index.d.ts +2 -1
  184. package/lib/commands.d.ts +532 -326
  185. package/lib/eslib/index.d.ts +3 -3
  186. package/lib/eslib/lib.d.ts +9 -9
  187. package/lib/eslib/lib.es2015.collection.d.ts +89 -89
  188. package/lib/eslib/lib.es2015.core.d.ts +16 -16
  189. package/lib/eslib/lib.es2015.d.ts +30 -30
  190. package/lib/eslib/lib.es2015.generator.d.ts +79 -79
  191. package/lib/eslib/lib.es2015.iterable.d.ts +70 -70
  192. package/lib/eslib/lib.es5.d.ts +295 -295
  193. package/lib/eslib/lib.es6.d.ts +18 -18
  194. package/lib/globals.d.ts +341 -328
  195. package/lib/helpers.d.ts +23 -23
  196. package/lib/index.d.ts +7 -7
  197. package/lib/kinds.d.ts +36 -36
  198. package/lib/memory.d.ts +17 -17
  199. package/lib/traits.d.ts +141 -121
  200. package/lib/util.d.ts +32 -32
  201. package/package.json +68 -48
  202. package/build/Compiler.d.ts +0 -18
  203. package/build/Scope.d.ts +0 -26
  204. package/build/bin.d.ts +0 -2
  205. package/build/handlers/BlockStatement.d.ts +0 -2
  206. package/build/handlers/CallExpression.d.ts +0 -3
  207. package/build/handlers/ForStatement.d.ts +0 -2
  208. package/build/handlers/IfStatement.d.ts +0 -2
  209. package/build/handlers/Literal.d.ts +0 -2
  210. package/build/handlers/Program.d.ts +0 -2
  211. package/build/handlers/Statements.d.ts +0 -5
  212. package/build/handlers/TemplateExpression.d.ts +0 -2
  213. package/build/handlers/VariableDeclaration.d.ts +0 -3
  214. package/build/handlers/WhileStatement.d.ts +0 -2
  215. package/build/index.d.ts +0 -1
  216. package/build/macros/Blocks.d.ts +0 -5
  217. package/build/macros/Blocks.js +0 -143
  218. package/build/macros/Blocks.js.map +0 -1
  219. package/build/macros/Draw.js +0 -39
  220. package/build/macros/Draw.js.map +0 -1
  221. package/build/macros/Function.d.ts +0 -12
  222. package/build/macros/Items.d.ts +0 -5
  223. package/build/macros/Items.js +0 -20
  224. package/build/macros/Items.js.map +0 -1
  225. package/build/macros/Liquids.d.ts +0 -5
  226. package/build/macros/Liquids.js +0 -18
  227. package/build/macros/Liquids.js.map +0 -1
  228. package/build/macros/Symbol.d.ts +0 -0
  229. package/build/macros/Symbol.js +0 -1
  230. package/build/macros/Symbol.js.map +0 -1
  231. package/build/macros/SymbolNamespace.d.ts +0 -0
  232. package/build/macros/SymbolNamespace.js +0 -1
  233. package/build/macros/SymbolNamespace.js.map +0 -1
  234. package/build/macros/TypeFactory.d.ts +0 -8
  235. package/build/macros/TypeFactory.js +0 -22
  236. package/build/macros/TypeFactory.js.map +0 -1
  237. package/build/macros/Units.d.ts +0 -5
  238. package/build/macros/Units.js +0 -18
  239. package/build/macros/Units.js.map +0 -1
  240. package/build/macros/Vars.d.ts +0 -5
  241. package/build/macros/Vars.js +0 -18
  242. package/build/macros/Vars.js.map +0 -1
  243. package/build/macros/commands/Asm.js +0 -21
  244. package/build/macros/commands/Asm.js.map +0 -1
  245. package/build/macros/commands/UnitControl.d.ts +0 -5
  246. package/build/macros/commands/control.d.ts +0 -5
  247. package/build/macros/commands/control.js.map +0 -1
  248. package/build/macros/commands/io.d.ts +0 -8
  249. package/build/macros/commands/io.js +0 -47
  250. package/build/macros/commands/io.js.map +0 -1
  251. package/build/macros/helpers/GetBuilding.d.ts +0 -5
  252. package/build/macros/helpers/GetBuilding.js +0 -16
  253. package/build/macros/helpers/GetBuilding.js.map +0 -1
  254. package/build/macros/helpers/GetVar.js +0 -16
  255. package/build/macros/helpers/GetVar.js.map +0 -1
  256. package/build/macros/helpers/index.d.ts +0 -2
  257. package/build/macros/helpers/index.js +0 -15
  258. package/build/macros/helpers/index.js.map +0 -1
  259. package/build/types.d.ts +0 -49
  260. package/build/utils.d.ts +0 -3
  261. package/build/values/BaseValue.d.ts +0 -5
  262. package/build/values/ObjectValue.d.ts +0 -17
  263. package/build/values/VoidValue.d.ts +0 -11
  264. package/dist/bundle.js +0 -1
package/lib/commands.d.ts CHANGED
@@ -1,326 +1,532 @@
1
- import "./kind";
2
- import { TRadarFilter, TRadarSort, TUnitLocateBuildingGroup } from "./util";
3
- declare global {
4
- /**
5
- * Appends the items to the print buffer, calling this function
6
- * on its own will not print any contents to a message block.
7
- *
8
- * To print the contents of the print buffer and empty it call `printFlush`.
9
- *
10
- * @param items The items to be added to the print buffer.
11
- */
12
- function print(...items: unknown[]): void;
13
-
14
- /**
15
- * Appends draw contents to the draw buffer.
16
- *
17
- * Warning: these methods only append data to the draw buffer,
18
- * which is used by `drawFlush` to actually draw content on a display.
19
- */
20
- function draw(mode: "clear", r: number, g: number, b: number): void;
21
-
22
- /**
23
- * Appends draw contents to the draw buffer.
24
- *
25
- * Warning: these methods only append data to the draw buffer,
26
- * which is used by `drawFlush` to actually draw content on a display.
27
- */
28
- function draw(
29
- mode: "color",
30
- r: number,
31
- g: number,
32
- b: number,
33
- a: number
34
- ): void;
35
-
36
- /**
37
- * Appends draw contents to the draw buffer.
38
- *
39
- * Warning: these methods only append data to the draw buffer,
40
- * which is used by `drawFlush` to actually draw content on a display.
41
- */
42
- function draw(mode: "stroke", width: number): void;
43
-
44
- /**
45
- * Appends draw contents to the draw buffer.
46
- *
47
- * Warning: these methods only append data to the draw buffer,
48
- * which is used by `drawFlush` to actually draw content on a display.
49
- */
50
- function draw(
51
- mode: "line",
52
- x1: number,
53
- y1: number,
54
- x2: number,
55
- y2: number
56
- ): void;
57
-
58
- /**
59
- * Appends draw contents to the draw buffer.
60
- *
61
- * Warning: these methods only append data to the draw buffer,
62
- * which is used by `drawFlush` to actually draw content on a display.
63
- */
64
- function draw(
65
- mode: "rect",
66
- x: number,
67
- y: number,
68
- width: number,
69
- height: number
70
- ): void;
71
-
72
- /**
73
- * Appends draw contents to the draw buffer.
74
- *
75
- * Warning: these methods only append data to the draw buffer,
76
- * which is used by `drawFlush` to actually draw content on a display.
77
- */
78
- function draw(
79
- mode: "lineRect",
80
- x: number,
81
- y: number,
82
- width: number,
83
- height: number
84
- ): void;
85
-
86
- /**
87
- * Appends draw contents to the draw buffer.
88
- *
89
- * Warning: these methods only append data to the draw buffer,
90
- * which is used by `drawFlush` to actually draw content on a display.
91
- */
92
- function draw(
93
- mode: "poly",
94
- x: number,
95
- y: number,
96
- sides: number,
97
- radius: number,
98
- rotation: number
99
- ): void;
100
-
101
- /**
102
- * Appends draw contents to the draw buffer.
103
- *
104
- * Warning: these methods only append data to the draw buffer,
105
- * which is used by `drawFlush` to actually draw content on a display.
106
- */
107
- function draw(
108
- mode: "linePoly",
109
- x: number,
110
- y: number,
111
- sides: number,
112
- radius: number,
113
- rotation: number
114
- ): void;
115
-
116
- /**
117
- * Appends draw contents to the draw buffer.
118
- *
119
- * Warning: these methods only append data to the draw buffer,
120
- * which is used by `drawFlush` to actually draw content on a display.
121
- */
122
- function draw(
123
- mode: "triangle",
124
- x: number,
125
- y: number,
126
- x2: number,
127
- y2: number,
128
- x3: number,
129
- y3: number
130
- ): void;
131
-
132
- /**
133
- * Appends draw contents to the draw buffer.
134
- *
135
- * Warning: these methods only append data to the draw buffer,
136
- * which is used by `drawFlush` to actually draw content on a display.
137
- */
138
- function draw(
139
- mode: "image",
140
- x: number,
141
- y: number,
142
- image: symbol,
143
- size: number,
144
- rotation: number
145
- ): void;
146
-
147
- /**
148
- * Writes the contents of the print buffer into the target message
149
- * and clears the buffer afterwards.
150
- * @param target
151
- */
152
- function printFlush(target: BasicBuilding): void;
153
-
154
- /**
155
- * Writes the contents of the draw buffer into the target display
156
- * and clears the buffer afterwards.
157
- * @param target
158
- */
159
- function drawFlush(target: BasicBuilding): void;
160
-
161
- /**
162
- * Gets a block link by its index.
163
- * @param index
164
- */
165
- function getLink<T extends BasicBuilding = AnyBuilding>(index: number): T;
166
-
167
- function control(
168
- kind: "enabled",
169
- building: BasicBuilding,
170
- value: boolean
171
- ): void;
172
-
173
- function control(
174
- kind: "shoot",
175
- building: BasicBuilding & Shooting,
176
- x: number,
177
- y: number,
178
- shoot: boolean
179
- ): void;
180
-
181
- function control(
182
- kind: "shootp",
183
- building: BasicBuilding & Shooting,
184
- unit: BasicUnit,
185
- shoot: boolean
186
- ): void;
187
-
188
- function control(
189
- kind: "config",
190
- building: BasicBuilding,
191
- value: symbol
192
- ): void;
193
-
194
- function control(
195
- kind: "color",
196
- building: BasicBuilding,
197
- r: number,
198
- g: number,
199
- b: number
200
- ): void;
201
-
202
- /**
203
- * Detects an unit nearby this `building`.
204
- * @param building The building used to detect potential targets
205
- * @param filter1 First filter for selecting a target. Setting it to "any" ignores it
206
- * @param filter2 Second filter for selecting a target. Setting it to "any" ignores it
207
- * @param filter3 Third filter for selecting a target. Setting it to "any" ignores it
208
- * @param order The n th unit that fits these requirements based on the sorting method
209
- * (1 => first unit, 2 => second unit and so on)
210
- * @param sort The method on which the results should be sorted
211
- *
212
- * @example
213
- * const turret = getBuilding("cyclone1")
214
- * // returns the second nearest enemy unit
215
- * const result = radar(turret, "enemy", "any", "any", 2, "distance")
216
- */
217
- function radar<T extends BasicUnit = AnyUnit>(
218
- building: BasicBuilding,
219
- filter1: TRadarFilter,
220
- filter2: TRadarFilter,
221
- filter3: TRadarFilter,
222
- order: number,
223
- sort: TRadarSort
224
- ): T;
225
-
226
- /**
227
- * Alternate way to access special properties on objects.
228
- *
229
- * This method allows you to use customly created symbols
230
- * and sensor them on buildings.
231
- * @param property The property to be sensed on the building
232
- * @param target
233
- *
234
- * @example
235
- * let myBuilding = getBuilding("container1")
236
- * // jsdoc doesn't allow me to type this
237
- * // variable, but you should type it as a symbol in this case
238
- * let myCustomSymbol = getVar("@custom-symbol") // problably defined by a mod
239
- * let result = sensor(myCustomSymbol, myBuilding)
240
- */
241
- function sensor<T>(property: symbol, target: BasicBuilding | BasicUnit): T;
242
-
243
- function wait(seconds: number): void;
244
-
245
- function lookup(kind: "block", index: number): BlockSymbol | null;
246
- function lookup(kind: "unit", index: number): UnitSymbol | null;
247
- function lookup(kind: "item", index: number): ItemSymbol | null;
248
- function lookup(kind: "liquid", index: number): LiquidSymbol | null;
249
-
250
- function unitBind(type: UnitSymbol): void;
251
-
252
- function unitControl(mode: "idle"): void;
253
- function unitControl(mode: "stop"): void;
254
- function unitControl(mode: "move", x: number, y: number): void;
255
- function unitControl(
256
- mode: "approach",
257
- x: number,
258
- y: number,
259
- radius: number
260
- ): void;
261
- function unitControl(mode: "boost", enable: boolean): void;
262
- function unitControl(mode: "pathfind"): void;
263
- function unitControl(
264
- mode: "target",
265
- x: number,
266
- y: number,
267
- shoot: boolean
268
- ): void;
269
- function unitControl(mode: "targetp", unit: BasicUnit, shoot: boolean): void;
270
- function unitControl(
271
- mode: "itemDrop",
272
- target: BasicBuilding | typeof Blocks.air,
273
- amount: number
274
- ): void;
275
- function unitControl(
276
- mode: "itemTake",
277
- target: BasicBuilding,
278
- item: ItemSymbol,
279
- amount: number
280
- ): void;
281
- function unitControl(mode: "payDrop"): void;
282
- function unitControl(mode: "payTake", takeUnits: boolean): void;
283
- function unitControl(mode: "payEnter"): void;
284
- function unitControl(mode: "mine", x: number, y: number): void;
285
- function unitControl(mode: "flag", value: number): void;
286
- function unitControl(
287
- mode: "build",
288
- x: number,
289
- y: number,
290
- block: BlockSymbol,
291
- rotation: number,
292
- config: unknown
293
- ): void;
294
- function unitControl<T extends BasicBuilding = AnyBuilding>(
295
- mode: "getBlock",
296
- x: number,
297
- y: number
298
- ): [type: BlockSymbol | null, building: T | null];
299
- function unitControl(
300
- mode: "within",
301
- x: number,
302
- y: number,
303
- radius: number
304
- ): boolean;
305
-
306
- function unitRadar<T extends BasicUnit>(
307
- filter1: TRadarFilter,
308
- filter2: TRadarFilter,
309
- filter3: TRadarFilter,
310
- order: number,
311
- sort: TRadarSort
312
- ): T;
313
-
314
- function unitLocate(
315
- find: "ore",
316
- ore: ItemSymbol
317
- ): [found: false] | [found: true, x: number, y: number];
318
- function unitLocate<T extends BasicBuilding = AnyBuilding>(
319
- find: "building",
320
- group: TUnitLocateBuildingGroup,
321
- enemy: boolean
322
- ): [found: false] | [found: true, x: number, y: number, building: T];
323
- function unitLocate<T extends BasicBuilding = AnyBuilding>(
324
- find: "spawn" | "damaged"
325
- ): [found: false] | [found: true, x: number, y: number, building: T];
326
- }
1
+ import "./kind";
2
+ import { TRadarFilter, TRadarSort, TUnitLocateBuildingGroup } from "./util";
3
+ declare global {
4
+ /**
5
+ * Appends the items to the print buffer, calling this function
6
+ * on its own will not print any contents to a message block.
7
+ *
8
+ * To print the contents of the print buffer and empty it call `printFlush`.
9
+ *
10
+ * @param items The items to be added to the print buffer.
11
+ */
12
+ function print(...items: unknown[]): void;
13
+
14
+ /**
15
+ * Fills the screen with a color.
16
+ *
17
+ * Warning: nothing is drawn until `drawFlush` is called.
18
+ */
19
+ function draw(mode: "clear", r: number, g: number, b: number): void;
20
+
21
+ /**
22
+ * Sets the color for the next drawing operations.
23
+ *
24
+ * Warning: nothing is drawn until `drawFlush` is called.
25
+ */
26
+ function draw(
27
+ mode: "color",
28
+ r: number,
29
+ g: number,
30
+ b: number,
31
+ a?: number
32
+ ): void;
33
+
34
+ /**
35
+ * Sets the width of the next lines to be drawn.
36
+ *
37
+ * Warning: nothing is drawn until `drawFlush` is called.
38
+ */
39
+ function draw(mode: "stroke", width: number): void;
40
+
41
+ /**
42
+ * Draws a line between two points.
43
+ *
44
+ * Warning: nothing is drawn until `drawFlush` is called.
45
+ */
46
+ function draw(
47
+ mode: "line",
48
+ x1: number,
49
+ y1: number,
50
+ x2: number,
51
+ y2: number
52
+ ): void;
53
+
54
+ /**
55
+ * Draws a filled rectangle.
56
+ *
57
+ * Warning: nothing is drawn until `drawFlush` is called.
58
+ */
59
+ function draw(
60
+ mode: "rect",
61
+ x: number,
62
+ y: number,
63
+ width: number,
64
+ height: number
65
+ ): void;
66
+
67
+ /**
68
+ * Draws a rectangle outline.
69
+ *
70
+ * Warning: nothing is drawn until `drawFlush` is called.
71
+ */
72
+ function draw(
73
+ mode: "lineRect",
74
+ x: number,
75
+ y: number,
76
+ width: number,
77
+ height: number
78
+ ): void;
79
+
80
+ /**
81
+ * Draws a filled, regular polygon.
82
+ * @param sides The number of sides the polygon should have
83
+ * @param radius The smallest distance between a line and the center of the polygon
84
+ * @param rotation The rotation of the polygon in degrees
85
+ *
86
+ * Warning: nothing is drawn until `drawFlush` is called.
87
+ */
88
+ function draw(
89
+ mode: "poly",
90
+ x: number,
91
+ y: number,
92
+ sides: number,
93
+ radius: number,
94
+ rotation: number
95
+ ): void;
96
+
97
+ /**
98
+ * Draws the outline of a regular polygon.
99
+ * @param sides The number of sides the polygon should have
100
+ * @param radius The smallest distance between a line and the center of the polygon
101
+ * @param rotation The rotation of the polygon in degrees
102
+ *
103
+ *
104
+ * Warning: nothing is drawn until `drawFlush` is called.
105
+ */
106
+ function draw(
107
+ mode: "linePoly",
108
+ x: number,
109
+ y: number,
110
+ sides: number,
111
+ radius: number,
112
+ rotation: number
113
+ ): void;
114
+
115
+ /**
116
+ * Draws a filled triangle.
117
+ *
118
+ * Warning: nothing is drawn until `drawFlush` is called.
119
+ */
120
+ function draw(
121
+ mode: "triangle",
122
+ x: number,
123
+ y: number,
124
+ x2: number,
125
+ y2: number,
126
+ x3: number,
127
+ y3: number
128
+ ): void;
129
+
130
+ /**
131
+ * Draws an image of the respective content. (like `Units.dagger` and `Blocks.router`)
132
+ *
133
+ * Warning: nothing is drawn until `drawFlush` is called.
134
+ * @param image The symbol for the image to be drawn.
135
+ * @param rotation The rotation of the image in degrees.
136
+ *
137
+ * Example:
138
+ * ```js
139
+ * // draw a router
140
+ * draw("image", 30, 30, Blocks.router, 15, 0);
141
+ *
142
+ * // draw the unit bound to the processor
143
+ * draw("image", 60, 60, Vars.unit.type, 15, 0);
144
+ * ```
145
+ */
146
+ function draw(
147
+ mode: "image",
148
+ x: number,
149
+ y: number,
150
+ image: symbol,
151
+ size: number,
152
+ rotation: number
153
+ ): void;
154
+
155
+ /**
156
+ * Writes the contents of the print buffer into the target message
157
+ * and clears the buffer afterwards.
158
+ * @param target
159
+ */
160
+ function printFlush(target: BasicBuilding): void;
161
+
162
+ /**
163
+ * Writes the contents of the draw buffer into the target display
164
+ * and clears the buffer afterwards.
165
+ * @param target
166
+ */
167
+ function drawFlush(target: BasicBuilding): void;
168
+
169
+ /**
170
+ * Gets a block link by its index.
171
+ *
172
+ * To make safe queries it is recommended to check an index
173
+ * before trying to get a link. This can be done by using `Vars.links`.
174
+ * @param index
175
+ *
176
+ * Example:
177
+ * ```js
178
+ * if(index < Vars.links) {
179
+ * myBlock = getLink(index)
180
+ * }
181
+ * ```
182
+ */
183
+ function getLink<T extends BasicBuilding = AnyBuilding>(index: number): T;
184
+
185
+ /**
186
+ * Sets whether the building is enabled or disabled.
187
+ */
188
+ function control(
189
+ kind: "enabled",
190
+ building: BasicBuilding,
191
+ value: boolean
192
+ ): void;
193
+
194
+ /**
195
+ * Makes the building shoot or aim at the given position
196
+ * @param building The shooting building
197
+ * @param shoot `true` to shoot, `false` to just aim at the position
198
+ */
199
+ function control(
200
+ kind: "shoot",
201
+ building: BasicBuilding & Shooting,
202
+ x: number,
203
+ y: number,
204
+ shoot: boolean
205
+ ): void;
206
+
207
+ /**
208
+ * Shoot at an unit with velocity prediction
209
+ * @param building The shooting building
210
+ * @param unit The target unit
211
+ * @param shoot `true` to shoot, `false` to just aim
212
+ */
213
+ function control(
214
+ kind: "shootp",
215
+ building: BasicBuilding & Shooting,
216
+ unit: BasicUnit,
217
+ shoot: boolean
218
+ ): void;
219
+
220
+ /**
221
+ * Sets the config of a block (like the item of a sorter)
222
+ */
223
+ function control(
224
+ kind: "config",
225
+ building: BasicBuilding,
226
+ value: symbol
227
+ ): void;
228
+
229
+ /**
230
+ * Sets the color of an illuminator
231
+ */
232
+ function control(
233
+ kind: "color",
234
+ building: BasicBuilding,
235
+ r: number,
236
+ g: number,
237
+ b: number
238
+ ): void;
239
+
240
+ /**
241
+ * Detects an unit nearby this `building`.
242
+ * @param building The building used to detect potential targets
243
+ * @param filter1 First filter for selecting a target. Setting it to "any" ignores it
244
+ * @param filter2 Second filter for selecting a target. Setting it to "any" ignores it
245
+ * @param filter3 Third filter for selecting a target. Setting it to "any" ignores it
246
+ * @param order The n th unit that fits these requirements based on the sorting method
247
+ * (1 => first unit, 2 => second unit and so on)
248
+ * @param sort The method on which the results should be sorted
249
+ *
250
+ * Example:
251
+ * ```js
252
+ * const turret = getBuilding("cyclone1")
253
+ * // returns the second nearest enemy unit
254
+ * const result = radar(turret, "enemy", "any", "any", 2, "distance")
255
+ * ```
256
+ */
257
+ function radar<T extends BasicUnit = AnyUnit>(
258
+ building: BasicBuilding,
259
+ filter1: TRadarFilter,
260
+ filter2: TRadarFilter,
261
+ filter3: TRadarFilter,
262
+ order: number,
263
+ sort: TRadarSort
264
+ ): T;
265
+
266
+ /**
267
+ * Alternate way to access special properties on objects.
268
+ *
269
+ * This method allows you to use customly created symbols
270
+ * and sensor them on buildings.
271
+ * @param property The property to be sensed on the building
272
+ * @param target
273
+ *
274
+ * Example:
275
+ * ```js
276
+ * let myBuilding = getBuilding("container1")
277
+ * // jsdoc doesn't allow me to type this
278
+ * // variable, but you should type it as a symbol in this case
279
+ * let myCustomSymbol = getVar("@custom-symbol") // problably defined by a mod
280
+ * let result = sensor(myCustomSymbol, myBuilding)
281
+ * ```
282
+ */
283
+ function sensor<T>(property: symbol, target: BasicBuilding | BasicUnit): T;
284
+
285
+ /**
286
+ * Stops the execution for the given amount of seconds
287
+ */
288
+ function wait(seconds: number): void;
289
+
290
+ /**
291
+ * Looks up a block symbol by it's index on the content registry.
292
+ *
293
+ * Use `Vars.blockCount` to check the maximum index allowed.
294
+ *
295
+ * Example:
296
+ * ```js
297
+ * if(index < Vars.blockCount) {
298
+ * let blockKind = lookup("block", index);
299
+ * }
300
+ * ```
301
+ */
302
+ function lookup(kind: "block", index: number): BlockSymbol;
303
+ /**
304
+ * Looks up an unit symbol by it's index on the content registry.
305
+ *
306
+ * Use `Vars.unitCount` to check the maximum index allowed.
307
+ *
308
+ * Example:
309
+ * ```js
310
+ * if(index < Vars.unitCount) {
311
+ * let unitKind = lookup("unit", index);
312
+ * }
313
+ * ```
314
+ */
315
+ function lookup(kind: "unit", index: number): UnitSymbol | null;
316
+ /**
317
+ * Looks up an item symbol by it's index on the content registry.
318
+ *
319
+ * Use `Vars.itemCount` to check the maximum index allowed.
320
+ *
321
+ * Example:
322
+ * ```js
323
+ * if(index < Vars.itemCount) {
324
+ * let itemKind = lookup("item", index);
325
+ * }
326
+ * ```
327
+ */
328
+ function lookup(kind: "item", index: number): ItemSymbol | null;
329
+ /**
330
+ * Looks up a liquid symbol by it's index on the content registry.
331
+ *
332
+ * Use `Vars.liquidCount` to check the maximum index allowed.
333
+ *
334
+ * Example:
335
+ * ```js
336
+ * if(index < Vars.liquidCount) {
337
+ * let liquidKind = lookup("liquid", index);
338
+ * }
339
+ * ```
340
+ */
341
+ function lookup(kind: "liquid", index: number): LiquidSymbol | null;
342
+
343
+ /**
344
+ * Binds an unit to the this processor. The unit is accessible at `Vars.unit`
345
+ */
346
+ function unitBind(type: UnitSymbol): void;
347
+
348
+ /**
349
+ * Makes the unit bound to this processor stop moving but
350
+ * allows it to keep doing it's action (like mining or building)
351
+ */
352
+ function unitControl(mode: "idle"): void;
353
+ /**
354
+ * Makes the unit bound to this processor stop mining, building and moving
355
+ */
356
+ function unitControl(mode: "stop"): void;
357
+ /**
358
+ * Makes the unit bound to this processor move to the given position
359
+ */
360
+ function unitControl(mode: "move", x: number, y: number): void;
361
+ /**
362
+ * Makes the unit bound to this processor approach the given position at the given radius
363
+ * @param radius How distant to the position the unit can be
364
+ */
365
+ function unitControl(
366
+ mode: "approach",
367
+ x: number,
368
+ y: number,
369
+ radius: number
370
+ ): void;
371
+ /**
372
+ * Whether the unit bound to this processor should be boosted (floating)
373
+ */
374
+ function unitControl(mode: "boost", enable: boolean): void;
375
+ /**
376
+ * Makes the unit bound to this processor move to the enemy spawn
377
+ */
378
+ function unitControl(mode: "pathfind"): void;
379
+ /**
380
+ * Makes the unit bound to this processor shoot/aim at the given position
381
+ * @param shoot `true` to shoot, `false` to just aim
382
+ */
383
+ function unitControl(
384
+ mode: "target",
385
+ x: number,
386
+ y: number,
387
+ shoot: boolean
388
+ ): void;
389
+ /**
390
+ * Makes the unit bound to this processor target an unit with velocity prediction
391
+ * @param unit The shoot target
392
+ * @param shoot `true` to shoot, `false` to just aim
393
+ */
394
+ function unitControl(mode: "targetp", unit: BasicUnit, shoot: boolean): void;
395
+ /**
396
+ * Makes the unit bound to this processor drop it's held items onto the given target
397
+ * @param target Where to drop the items, if `Blocks.air`, the unit will throw it's items away
398
+ * @param amount How many items should be dropped
399
+ */
400
+ function unitControl(
401
+ mode: "itemDrop",
402
+ target: BasicBuilding | typeof Blocks.air,
403
+ amount: number
404
+ ): void;
405
+ /**
406
+ * Makes the unit bound to this processor take items from a building
407
+ * @param target The building that will have it's items taken
408
+ * @param item The kind of item to take
409
+ * @param amount How many items should be taken
410
+ */
411
+ function unitControl(
412
+ mode: "itemTake",
413
+ target: BasicBuilding,
414
+ item: ItemSymbol,
415
+ amount: number
416
+ ): void;
417
+ /**
418
+ * Makes the unit bound to this processor drop one entity from it's payload
419
+ */
420
+ function unitControl(mode: "payDrop"): void;
421
+ /**
422
+ * Makes the unit bound to this processor take an entity into it's payload
423
+ * @param takeUnits Whether to take units or buildings
424
+ */
425
+ function unitControl(mode: "payTake", takeUnits: boolean): void;
426
+ /**
427
+ * Makes the unit bound to this processor enter/land on the
428
+ * payload block the unit is on
429
+ */
430
+ function unitControl(mode: "payEnter"): void;
431
+ /**
432
+ * Makes the unit bound to this processor mine at the given position
433
+ */
434
+ function unitControl(mode: "mine", x: number, y: number): void;
435
+ /**
436
+ * Sets the numeric flag of the unit bound to this processor
437
+ */
438
+ function unitControl(mode: "flag", value: number): void;
439
+ /**
440
+ * Makes the unit bound to this processor build a building with the
441
+ * given properties
442
+ * @param block The kind of building to build
443
+ * @param rotation The rotation of the building, ranges from 0 to 3
444
+ * @param config The config of the building
445
+ */
446
+ function unitControl(
447
+ mode: "build",
448
+ x: number,
449
+ y: number,
450
+ block: BlockSymbol,
451
+ rotation: number,
452
+ config: unknown
453
+ ): void;
454
+ /**
455
+ * Makes the unit bound to this processor data about a block at the given position
456
+ */
457
+ function unitControl<T extends BasicBuilding = AnyBuilding>(
458
+ mode: "getBlock",
459
+ x: number,
460
+ y: number
461
+ ): [type: BlockSymbol | null, building: T | null];
462
+ /**
463
+ * Checks if the unit bound to this processor is within a radius of a given position.
464
+ */
465
+ function unitControl(
466
+ mode: "within",
467
+ x: number,
468
+ y: number,
469
+ radius: number
470
+ ): boolean;
471
+
472
+ /**
473
+ * Finds an unit near the unit bound to this processor
474
+ * @param filter1 First filter for selecting a target. Setting it to "any" ignores it
475
+ * @param filter2 Second filter for selecting a target. Setting it to "any" ignores it
476
+ * @param filter3 Third filter for selecting a target. Setting it to "any" ignores it
477
+ * @param order The n th unit that fits these requirements based on the sorting method
478
+ * (1 => first unit, 2 => second unit and so on)
479
+ * @param sort The method on which the results should be sorted
480
+ *
481
+ * Example:
482
+ * ```js
483
+ * // returns the second nearest enemy unit
484
+ * const result = unitRadar("enemy", "any", "any", 2, "distance")
485
+ * ```
486
+ */
487
+ function unitRadar<T extends BasicUnit = AnyUnit>(
488
+ filter1: TRadarFilter,
489
+ filter2: TRadarFilter,
490
+ filter3: TRadarFilter,
491
+ order: number,
492
+ sort: TRadarSort
493
+ ): T;
494
+
495
+ /**
496
+ * Uses the unit bound to this processor to find an ore vein anywhere on the map
497
+ * @param ore The kind of item the ore should contain
498
+ */
499
+ function unitLocate(
500
+ find: "ore",
501
+ ore: ItemSymbol
502
+ ): [found: false] | [found: true, x: number, y: number];
503
+ /**
504
+ * Uses the unit bound to this processor to find a building anywhere on the map
505
+ * @param group The group that the building belongs to
506
+ * @param enemy Whether it should be an enemy building or an ally one
507
+ */
508
+ function unitLocate<T extends BasicBuilding = AnyBuilding>(
509
+ find: "building",
510
+ group: TUnitLocateBuildingGroup,
511
+ enemy: boolean
512
+ ): [found: false] | [found: true, x: number, y: number, building: T];
513
+ /**
514
+ * Uses the unit bound to this processor to find an enemy spawn anywhere on the map.
515
+ *
516
+ * May return a building (a core) or a position
517
+ * @param find
518
+ */
519
+ function unitLocate<T extends BasicBuilding = AnyBuilding>(
520
+ find: "spawn"
521
+ ): [found: false] | [found: true, x: number, y: number, building: T];
522
+ /**
523
+ * Uses the unit bound to this processor to find a damaged ally buildings anywhere on the map
524
+ * @param find
525
+ */
526
+ function unitLocate<T extends BasicBuilding = AnyBuilding>(
527
+ find: "damaged"
528
+ ): [found: false] | [found: true, x: number, y: number, building: T];
529
+
530
+ /** Ends the execution of this script */
531
+ function endScript(): never;
532
+ }