forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.lua
556 lines (466 loc) · 13 KB
/
Core.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
---@meta
---@diagnostic disable: lowercase-global
---@class Quaternion
---@field [1] number
---@field [2] number
---@field [3] number
---@field [4] number
---@class Vector
---@field [1] number
---@field [2] number
---@field [3] number
---@class Vector2
---@field [1] number
---@field [2] number
---@class Rectangle # A point-to-point based rectangle, where the first point is usually in the top left corner
---@field x0 number
---@field y0 number
---@field x1 number
---@field y1 number
---@alias Color string `EnumColor` or hexcode like `'RrGgBb'`, or `'AaRrGgBb'` with transparency
---@alias Bone string | number
---@alias Army string | number
---@alias Language "cn" | "cz" | "de" | "es" | "fr" | "it" | "pl" | "ru" | "tw" | "tzm" | "us"
---@unknown
function AITarget()
end
--- Set the audio language
---@param language Language
function AudioSetLanguage(language)
end
--- Returns the last component of a path
---@param fullPath string
---@param stripExtension boolean?
function Basename(fullPath, stripExtension)
end
--- Likely used for debugging, but the use is unknown
---@unknown
function BeginLoggingStats()
end
--- Called during blueprint loading to update the loading animation
function BlueprintLoaderUpdateProgress()
end
--- Create an empty prefetch set
---@return moho.CPrefetchSet
function CreatePrefetchSet()
end
--- Returns the current running thread
---@return thread?
function CurrentThread()
end
--- Returns the directory name
---@param fullPath FileName
---@return string
function Dirname(fullPath)
end
--- Returns all files in the directory that matches the pattern
---@param directory FileName
---@param pattern string
---@return FileName[]
function DiskFindFiles(directory, pattern)
end
--- Returns a table of information for the given file, or false if the file doesn't exist
---@param filename FileName
---@return table | false
function DiskGetFileInfo(filename)
end
--- Converts a system path to a local path (based on the init file directories), returns the path if it is already local
---@param SysOrLocalPath FileName
---@return FileName
function DiskToLocal(SysOrLocalPath)
end
---End logging stats and optionally exit app
---@param exit boolean
function EndLoggingStats(exit)
end
--- Return true if a unit category contains this unit
---@param category EntityCategory
---@param unit Unit | UserUnit
function EntityCategoryContains(category, unit)
end
--- Checks for the empty category
---@param category EntityCategory
---@return boolean
function EntityCategoryEmpty(category)
end
---@overload fun(units: UserUnit[]): UserUnit[]
--- Filter a list of units to only those found in the category
---@param category EntityCategory
---@param units Unit[]
---@return Unit[]
function EntityCategoryFilterDown(category, units)
end
--- Computes a list of unit blueprint names that match the categories
---@param category EntityCategory
---@return string[]
function EntityCategoryGetUnitList(category)
end
--- Returns an ordered list of named colors available for a `Color` instead of using a hexcode
---@return EnumColor[]
function EnumColorNames()
end
--- Converts euler angles to a quaternion
---@param roll number
---@param pitch number
---@param yaw number
---@return Quaternion
function EulerToQuaternion(roll, pitch, yaw)
end
--- Collapse all intermediate `/./` or `/../` directory names from a path
---@param fullPath FileName
---@return FileName
function FileCollapsePath(fullPath)
end
--- Creates a new thread, passing all additional arguments to the callback
---@param callback function
---@param ... any
---@return thread
function ForkThread(callback, ...)
end
--- Get the blueprint of an object
---@overload fun(entity: Entity): EntityBlueprint
---@overload fun(mesh: Mesh): MeshBlueprint
---@overload fun(effect: moho.IEffect): EffectBlueprint
---@overload fun(projectile: Projectile): ProjectileBlueprint
---@overload fun(prop: Prop): PropBlueprint
---@overload fun(unit: UserUnit | Unit): UnitBlueprint
---@overload fun(weapon: Weapon): WeaponBlueprint
function GetBlueprint(object)
end
--- Retrieves the cue and bank of a sound table
---@param sound SoundHandle
---@return string cue
---@return string bank
function GetCueBank(sound)
end
--- The current army number that the player has focused, or `-1` for none (i.e. observer)
---@return number
function GetFocusArmy()
end
--- Return game time in seconds
---@return number
function GetGameTimeSeconds()
end
--- Retrieves the movie duration
---@param localFileName FileName
---@return number
function GetMovieDuration(localFileName)
end
---
---@param id UnitId
---@return UserUnit | Unit
function GetUnitById(id)
end
--- Retrieves the game version, as set by `version.lua`
---@return VERSION
function GetVersion()
end
---
---@param language Language
function HasLocalizedVO(language)
end
---
---@param army1 number
---@param army2 number
---@return boolean
function IsAlly(army1, army2)
end
--- Checks if the C-side of an object is destroyed / de-allocated
---@param entity? InternalObject
---@return boolean
function IsDestroyed(entity)
end
---
---@param army1 number
---@param army2 number
---@return boolean
function IsEnemy(army1, army2)
end
---
---@param army1 number
---@param army2 number
---@return boolean
function IsNeutral(army1, army2)
end
--- Destroys the c-side of a thread
---@param thread thread
function KillThread(thread)
end
--- Rounds a number to the nearest integer using the half-round-even rounding (banker's rules)
--- This means that it returns the closest integer and tie-breaks towards even numbers
--- (since a bias towards even numbers is less detrimental than an upward bias).
---@param number number
---@return integer
function MATH_IRound(number)
end
--- Applies linear interpolation between two values `a` and `b`
---@param s number Usually between 0 (returns `a`) and 1 (returns `b`)
---@param a number
---@param b number
---@return number
function MATH_Lerp(s, a, b)
end
--- Applies linear interpolation between two quaternions `L` and `R`
---@param alpha number
---@param L Quaternion
---@param R Quaternion
---@return Quaternion
function MinLerp(alpha, L, R)
end
--- Applies spherical linear interpolation between two quaternions `L` and `R`
---@param alpha number
---@param L Quaternion
---@param R Quaternion
---@return Quaternion
function MinSlerp(alpha, L, R)
end
--- Converts an orientation to a quaternion
---@param vector Vector
---@return Quaternion
function OrientFromDir(vector)
end
--- Parse a string to generate a new entity category
---@param cat UnparsedCategory
---@return EntityCategory
function ParseEntityCategory(cat)
end
--- Creates a point vector
---@alternative Not used, better off allocating a separate position and vector
---@param px number
---@param py number
---@param pz number
---@param vx number
---@param vy number
---@param vz number
---@return Vector position
---@return Vector velocity
function PointVector(px, py, pz, vx, vy, vz)
end
--- Generate a random number between `min` and `max`
---@param min number defaults to `0`
---@param max number defaults to `1`
---@return number
---@overload fun(max: number): number
---@overload fun(): number
function Random(min, max)
end
--- Make a sound parameters object. Note that this does not
--- take the same parameter that `Sound` does, this requires lowercase fields.
---@param sound {cue: string, bank: string, cutoff: number}
function RPCSound(sound)
end
--- Constructs a rectangle, usually the first point is in the top-left corner and the second is in the bottom-right corner
---@param x0 number
---@param y0 number
---@param x1 number
---@param y1 number
---@return Rectangle
function Rect(x0, y0, x1, y1)
end
--- Define a beam effect, only works in `blueprints.lua`
---@param spec BeamBlueprint
function RegisterBeamBlueprint(spec)
end
--- Define a particle emitter, only works in `blueprints.lua`
---@param spec EmitterBlueprint
function RegisterEmitterBlueprint(spec)
end
--- Define mesh properties, only works in `blueprints.lua`
---@param spec MeshBlueprint
function RegisterMeshBlueprint(spec)
end
--- Define a projectile, only works in `blueprints.lua`
---@param spec ProjectileBlueprint
function RegisterProjectileBlueprint(spec)
end
--- Define a prop, only works in `blueprints.lua`
---@param spec PropBlueprint
function RegisterPropBlueprint(spec)
end
--- Defile a poly trail emitter, only works in `blueprints.lua`
---@param spec TrailBlueprint
function RegisterTrailEmitterBlueprint(spec)
end
--- Define a unit, only works in `blueprints.lua`
---@param spec UnitBlueprint
function RegisterUnitBlueprint(spec)
end
--- Resumes the thread after suspending it, does nothing if the thread wasn't suspended
---@see # Counterpart of SuspendCurrentThread
---@param thread thread
function ResumeThread(thread)
end
--- Returns how many seconds in a tick
---@return number
function SecondsPerTick()
end
--- Return true iff the active session is a replay session
---@return boolean
function SessionIsReplay()
end
---
---@param armyIndex number index or -1
function SetFocusArmy(armyIndex)
end
--- Prints a debug message to the moholog, this shouldn't be used in production code
---@param out any
---@param ... any
function SPEW(out, ...)
end
--- Splits the string on the delimiter, returning several smaller strings
---@param string string
---@param delimiter string
---@return string[]
function STR_GetTokens(string, delimiter)
end
--- Returns the number of characters in a UTF-8 string
---@param string string
---@return number
function STR_Utf8Len(string)
end
--- Returns a substring from start to count
---@param string string
---@param start number
---@param count number
---@return string
function STR_Utf8SubString(string, start, count)
end
--- Converts an integer into a hexidecimal string
---@param int number
---@return string
function STR_itox(int)
end
--- Converts a hexidecimal string to an integer
---@param string string
---@return number
function STR_xtoi(string)
end
--- Sound({cue,bank,cutoff}) - Make a sound parameters object
---@param sound SoundBlueprint
---@return SoundHandle
function Sound(sound)
end
--- Define the footprint types for pathfinding, only works in `blueprints.lua`
---@param specs FootprintSpec[]
function SpecFootprints(specs)
end
--- Suspends the current thread indefinitely; only a call to `ResumeThread(thread)` can resume it
---@see ResumeThread
function SuspendCurrentThread()
end
--- Turns tracing on / off
---@param enable boolean
function Trace(enable)
end
--- Adds vector `b` to vector `a`
---@param a Vector
---@param b Vector
---@return Vector
function VAdd(a, b)
end
--- Subtracts vector `b` from vector `a`
---@param a Vector
---@param b Vector
---@return Vector
function VDiff(a, b)
end
--- Computes the distance between two points
---@param x1 number
---@param y1 number
---@param x2 number
---@param y2 number
---@return number
function VDist2(x1, y1, x2, y2)
end
--- Computes the squared distance between two points
---@param x1 number
---@param y1 number
---@param x2 number
---@param y2 number
---@return number
function VDist2Sq(x1, y1, x2, y2)
end
--- Computes the distance between the vectors `a` and `b`
---@param a Vector
---@param b Vector
---@return number
function VDist3(a, b)
end
--- Computes the squared distance between the vectors `a` and `b`
---@deprecated It is faster to compute it in Lua
---@param a Vector
---@param b Vector
---@return number
function VDist3Sq(a, b)
end
--- Computes the dot product between the vectors `a` and `b`
---@param a Vector
---@param b Vector
---@return number
function VDot(a, b)
end
--- Scales the vector `v` with the scalar `s`
---@param v Vector
---@param s number
---@return Vector
function VMult(v, s)
end
--- Computes the vector perpendicular to the plane described by the vectors `a` and `b`
---@param a Vector
---@param b Vector
---@return Vector
function VPerpDot(a, b)
end
--- Populates a new table with the corresponding meta table
---@param x number
---@param y number
---@param z number
---@return Vector
function Vector(x, y, z)
end
--- Populates a new table with the corresponding meta table
---@param x number
---@param y number
---@return Vector2
function Vector2(x, y)
end
--- Print a warning message to the moholog, this shouldn't be used in production code
---@param out any
---@param ... any
function WARN(out, ...)
end
--- Suspends the thread until the manipulator reaches its goal
---@param manipulator moho.manipulator_methods | EconomyEvent
function WaitFor(manipulator)
end
--- Run another script. The environment table, if given, will be used for the script's global variables.
---@param script string
---@param env? table
function doscript(script, env)
end
--- Returns if the given resource file exists
---@param name FileName
function exists(name)
end
------
-- New functions from engine patch:
------
---@alias PatchedDepositType
---| 0 #all
---| 1 #mass
---| 2 #hydrocarbon
---@class PatchedDepositResult
---@field X1 number
---@field X2 number
---@field Z1 number
---@field Z2 number
---@field Type PatchedDepositType
---@field Dist number
--- Return list of deposits around a point of type
---@param x number
---@param z number
---@param radius number
---@param type PatchedDepositType
---@return PatchedDepositResult[]
function GetDepositsAroundPoint(x, z, radius, type)
end