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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
# Global reference


## AddCustomGameNotification

Display a custom on-screen notification.


void **AddCustomGameNotification**(string id, string title, string text, string image, function callback, table params)
string id
: unique identifier of the notification.

string title
: title of the notification.

string text
: body text of the notification.

string image
: path to the notification icon.

function callback
: optional. Function called when the user clicks the notification.

table params
: optional. additional parameters.

Additional parameters are supplied to the translatable texts, but can also be used to tweak the functionality of the notification:

- _'cycle_objs'_ will cause the camera to cycle through a list of _GameObjects_ or _points_ when the user clicks the notification.

- _'priority'_ changes the priority of the notification (choose between _"Normal"_, _"Important"_ and _"Critical"_; default=_"Normal"_).

- _'dismissable'_ dictates the dismissability of the notification (default=_true_)

- _'close_on_read'_ will cause the notification to disappear when the user clicks on it (default=_false_).

- _'expiration'_ is the amount of time (in _milliseconds_) that the notification will stay on the screen (default=_0_).

- _'game_time'_ decides if the expiration countdown is done in _RealTime_ or _GameTime_ (default=_false_).


## AsyncCompress

Compresses a string using LZ4 or ZSTD compression.

Use [AsyncDecompress](#AsyncDecompress) to get back the original vlaue.


string compressed_data **AsyncCompress**(string original_data, bool pstr, string compression_algo)
original_data
: string to be compressed.

pstr
: if the result should be returned as a *pstr* string.

compression_algo
: the compression algorithm to be used - either *"lz4"* or *"zstd"*.

_returns_ compressed_data
: the compressed data as a string.


## AsyncDecompress

Decompresses a string generated using [AsyncCompress](#AsyncCompress) and returns the original value.


string original_data **AsyncDecompress**(string compressed_data, bool pstr)
compressed_data
: string to be decompressed.

_returns_ original_data
: the decompressed data as a string.


## AsyncWebSocketConnect

Creates a WebSocket connection to the specified URL.


string err, WebSocket connection **AsyncWebSocketConnect**(string url)
string url
: the URL to connect to

_returns_ string err
: nil if no error occurred, string explaining the system error or HTTP status code.

_returns_ string connection
: WebSocket object.


## CalcTimeToReach

Returns the time when the object will reach the sphere, but only within a maximum time.


int **CalcTimeToReach**(obj, center, radius, max_time)
CObject object
: Object or source position.

Point center
: Center of the sphere.

int radius
: Radius of the sphere - if the object doesn't reach this range, the function will return nil.

int max_time
: Maximum time whitin which the object must reach the sphere. Otherwise returns nil.


## Compress

Compresses a string using LZ4 compression.

Use [Decompress](#Decompress) to get back the original vlaue.


string compressed_data **Compress**(original_data, str compression = config.SerializeCompressAlgo)
original_data
: string to be compressed.

_returns_ compressed_data
: the compressed data as a string.


## ConnectivityCheck

Check if there is any path between a source position and a list of destinations.


bool **ConnectivityCheck**(src, dest, pfclass = 0, pass_search_dist = 0)
point src
: Point or object indicating the source position.

table dest
: List of points/objects or a single point/object, indicating the destination(s).

int pfclass
: PF class to be used. If *nil* is provided, it will be taken from the src object. If no object is provided, then the default is 0.

int pass_search_dist
: If the source is on impassable, the max distance to search for passable. Optional, with default value of 0.

_returns_ bool connectivity
: True if there is connectivity to any of the destination points.


## CreateActivityObject

Creates an activity object of class and attaches it to target. Every activity object must be created using this function!


object **CreateActivityObject**(class, luaobj, target, attach_offset, ...)
table luaobj
: - table used to create the object

object target
: - the target object, to which the activity will be attached or point to use as position

point attach_offset
: - optional attach offset when target is an object

...
: - optional values to pass to ActivityObject:SetParams

@return object


## DecodeURL

Decodes a given URL. Compatible with the RFC 3986 standart.


decodedUrl **DecodeURL**(url)

## Decompress

Decompresses a string generated using [Compress](#Compress) and returns the original value.


string original_data **Decompress**(compressed_data, int offset = 0, int max_decompressed_size = 140MB)
compressed_data
: string to be decompressed.

offset
: 1 based offset in the string to begin decompressing from.

max_decompressed_size
: maximum size of buffer to decompress into, to prevent huge allocation if data is uncompressed or invalid format.

_returns_ original_data, error
: the decompressed data as a string, or nil and a string error.


## DivRound

DivRound - short for Divide, Round.


ret **DivRound**(value, divisor)
int numerator
: numerator used for the calculation.

int denominator
: denominator used for the calculation.

_returns_ 
: the result from the division, rounded to the nearest integer.


## DumpDiff

A tool for finding differences between files. Work with extremely large files (> 200 MB)

The resulting differences are stored into two files with suffix "_diff" to the original filename.

A typical usage is to find Lua leakes between sessions:

1. Start the game in the main menu, without loading a map

2. Dump the Lua state using DumpAll("dump1.lua")

3. Load a map and perform all typicial actions

4. Return to the main menu

5. Dump the Lua state again using DumpAll("dump2.lua")

6. Run the diff tool DumpDiff("dump1.lua", "dump2.lua")

7. Any Lua leaks will be present in "dump2_diff.lua"


void **DumpDiff**(file1, file2)

## EncodeURL

Encodes a given URL. Compatible with the RFC 3986 standart.


encodedUrl **EncodeURL**(url)

## EndAllBanter

Stop all banter.


void **EndAllBanter**()

## EndBanter

Find banters associated with the specified unit and end them.

Optionally one banter can be excluded from the search.

Optionally the unit can be matched by the string in the banter line which led to this unit being picked.


void **EndBanter**(Unit unit, BanterPlayer exclude, String actor_string)

## ExecuteProcess

Execute a routine from a named process. If the process is currently suspended, the call will be registered in ordered to be executed once the process is resumed. Multiple calls with the same context will be registered as one.


void **ExecuteProcess**(string process, function func, table obj)
string process
: the name of the process, which routines should be suspended.

function func
: the function to be executed.

table obj
: optional function context.


## FindNearestObject

Finds the nearest object from the given object list to the given point.


object **FindNearestObject**(table ol, point pt[, function filter])
table ol
: the object list to search in.

point pt
: the point or object to which distance is measured; if the point is with invalid Z the measured distances are 2D, otherwise they are 3D.

function filter
: optional object filter function.


## FlightFindClosestAbove

Search for a landing position around a center location. A landing position is a passable position exactly at the flight height.


int **FlightFindClosestAbove**(grid, clip, pos, max_dist, min_dist, filter, ...)
grid grid
: flight map.

box clip
: flight area.

point pos
: center location.

int pfclass
: pf class to check for passability.

function filter
: filter to check position with args (x, y, z, h).


## FlightFindLanding

Search for a landing position around a center location. A landing position is a passable position exactly at the flight height.


int **FlightFindLanding**(grid, pos, pfclass, filter, ...)
grid grid
: flight map.

point pos
: center location.

int pfclass
: pf class to check for passability.

function filter
: filter to check position with args (x, y, z, h).


## FlightGetHeight

Returns the max between the flight height and the terrain height at given position. Returns 'nil' if the flight height is infinite.


int **FlightGetHeight**(grid, pos)
point pos
: position to check.


## GetClosestVolume

Gets the closest volume to the target position.


volume **GetClosestVolume**(pos, max_dist, volumes, efAnd)
pos point
: - target position

max_dist int
: - max distance a volume can be from the target position(optional).

volumes table
: - volumes to search, if not passed will go through all volumes(optional).

efAnd int
: - filter volumes using bitwise and with this enum flag(optional).

@return volume


## GetMinMaxVoxelHeight

Gets the min/max terrain height for points aligned to the voxel grid.


int, int **GetMinMaxVoxelHeight**(x, y, round)

int, int **GetMinMaxVoxelHeight**(pt, round)

## GetPassablePointNearby

Searches around and returns the nearest passable/walkable point.


point **GetPassablePointNearby**(point pt)
point pt
: original point.

_returns_ point
: nearest passable point or an *invalid* point, if none was found.


## GetPosHash

Returns a position hash


int **GetPosHash**(point pt [, int seed])

int **GetPosHash**(object obj [, int seed])

int **GetPosHash**(int x, int y [, int z, int seed])
_returns_ int
: position hash


## GetUniqueGridValues

Given a HSL::Grid, a tile size and the maximum amount of unique values finds the unique values in the grid and returns a vector with them.

Memory Limitation: max_values <= 65536




void **GetUniqueGridValues**(pGrid, nTileSize, max_values)
HSL::Grid pGrid
: HSL::Grid compliant grid

HSL::Coord nTileSize
: the grid tile size

HSL::data_t max_values
: the maximum amount of unique values

_returns_ std::vector<HSL::data_t> unique_values
: the unique values in the grid


## GetVoxelHeight

Gets the terrain height for points aligned to the voxel grid.


int **GetVoxelHeight**(x, y, round)

int **GetVoxelHeight**(pt, round)

## GridWaterArea

Computes the water surface based on a water level


int **GridWaterArea**(Grid *gSrc, Grid *gDst, HSL::Point pt)

int **GridWaterArea**(Grid *gSrc, Grid *gDst, HGE::GameObject pObj)

int **GridWaterArea**(Grid *gSrc, Grid *gDst, int x, int y, int z)
Grid *gSrc
: height grid

Grid *gDst
: resulting water mask

HSL::Point pt
: map position

HGE::GameObject pObj
: game object on the map

int x, y
: grid coordinates (not map!)

int z
: height level (not scaled!)

_returns_ int
: computed water surface area (water grid tiles)


## GridWaterLevel

Computes the water level based on a water surface area (in water tiles)


int **GridWaterLevel**(Grid *gSrc, Grid *gDst, HSL::Point pt, int nArea[, int nErrPct])

int **GridWaterLevel**(Grid *gSrc, Grid *gDst, HGE::GameObject pObj, int nArea[, int nErrPct])

int **GridWaterLevel**(Grid *gSrc, Grid *gDst, int x, int y, int nArea[, int nErrPct])
Grid *gSrc
: height grid

Grid *gDst
: resulting water mask

HSL::Point pt
: map position

HGE::GameObject pObj
: game object on the map

int x, y
: grid coordinates (not map!)

int nArea
: water surface area to match  (grid tiles)

int nErrPct
: water surface area error tolerance  (int percents)

_returns_ int
: computed water surface level (scaled in meters)


## IntersectObjWithBox

Check for intersection between a box and the object's collision mesh.

Performs a rough estimate - could return false positive results


intersect **IntersectObjWithBox**(obj, box)

## IsDlcAvailable

Returns if the player has a specific DLC installed.


bool **IsDlcAvailable**(string dlc)
dlc
: The ID of a DLC.

_returns_ bool
: If the DLC is available and loaded.


## IsProcessingSuspended

Checks if the processing of routines from a named process is currently suspended


bool **IsProcessingSuspended**(string process)

## IsValidPos

Checks if a position is on the map


bool **IsValidPos**(object obj)

bool **IsValidPos**(point pos)

bool **IsValidPos**(int x, int y, int z)
_returns_ bool
: returns true, if a position is on the map.


## IsValidZ

Checks if a position has a valid Z coordinate (not on the terrain)


bool **IsValidZ**(object obj)

bool **IsValidZ**(point pos)

bool **IsValidZ**(box bx)
_returns_ bool
: returns true, if the position has a valid Z coordinate.


## LuaCodeToTuple

Evaluates a string generated using [TupleToLuaCode](#TupleToLuaCode) and returns the original values.


error, values **LuaCodeToTuple**(string code, table env)
string code
: code to be evaluated.

table env
: evaluation environment.

_returns_ error, values
: error string (or nil, if none) and the evaluated tuple.


## MulDivAdd

MulDivAdd - short for Multiply, Divide, Add.


ret **MulDivAdd**(value, numerator, denominator, addend)
int value
: value used for the calculation.

int numerator
: numberator used for the calculation.

int denominator
: denominator used for the calculation.

int addend
: addend used for the calculation.

_returns_ 
: the integer calculation (value*numerator + addend)/denominator.


## MulDivRound

MulDivRound - short for Multiply, Divide, Round.


ret **MulDivRound**(value, numerator, denominator)
value
: value used for the calculation. Both number, point or box values are allowed.

int numerator
: multiplier used for the calculation.

int denominator
: divisor used for the calculation.

_returns_ 
: the result from (value*numerator)/denominator, rounded to the nearest integer.


## MulDivTrunc

MulDivTrunc - short for Multiply, Divide, Truncate.


ret **MulDivTrunc**(value, numerator, denominator)
value
: value used for the calculation. Both number, point or box values are allowed.

int numerator
: multiplier used for the calculation.

int denominator
: divisor used for the calculation.

_returns_ 
: the integer calculation (value*numerator)/denominator.


## Normalize

Returns a point with a vector direction defined by the given two or three coordinates, but with vector length 4096. If only two coordinates are given, returns a 2D point with z = InvalidZ.


point **Normalize**(int x, int y, [int z])
int x, y, z
: two or three coordinates specifying a vector direction.

_returns_ point n
: a point with length 4096 with the same direction as specified with x/y/z.


## PlaneFromHeight

Compute the plane that fits the terrain around an object (e.g. in order to cut the object below the terrain)


int **PlaneFromHeight**(object obj, int flags = 0, ...)
object obj
: the object to be considered

int flags
: various flags changing the default computing behavior

-- const.pfhLocal

The resulted plane is computed in the object's local space.



-- const.pfhBox

Uses the object's box to detect the terrain intersection. Otherwise it's collision mesh would be used.



-- const.pfhAbove

Adjusts the plane above the highest detected terrain.



-- const.pfhBelow

Adjusts the plane above the lowest detected terrain.



-- const.pfhOffset

Moves up or down the matched plane. Expect an additional *offset* parameter (int).



-- const.pfhTime

Moves the object's time. Expect an additional *delta* parameter (int).



-- const.pfhNegative

Changes the orientation of the plane.

_returns_ int
: packed plane


## PlayAndWaitBanter

Play a banter and wait for it to finish.


BanterPlayer **PlayAndWaitBanter**(string banter_preset_id, array associated_units, Unit fallback_actor)
string banter_preset_id
: Banter to play.

array associated_units
: Units to assign as banter actors.

Unit fallback_actor
: Unit to use if the actor cannot be found within the associated_units.

@returns BanterPlayer - object responsible for playing the banter.


## PlayBanter

Create a banter player which shows the banter text and plays the sounds.


BanterPlayer **PlayBanter**(string banter_preset_id, array associated_units, Unit fallback_actor, string any_actor_override)
string banter_preset_id
: Banter to play.

array associated_units
: Units to assign as banter actors.

Unit fallback_actor
: Unit to use if the actor cannot be found within the associated_units.

string any_actor_override
: Banter lines with actor "any" will be played by the first /object/ from this group.

bool wait_setpiece_end
: The banter will wait for any current setpiece to end before playing

@returns BanterPlayer - object responsible for playing the banter.


## PlayFX

Triggers a global event that activates various game effects. These effects are specified by FX presets. All FX presets that match the combo **action - moment - actor - target** will be activated.

Normally the FX-s are one-time events, but they can also be continuous effects. To stop continuous FX, another PlayFX call is made, with different *moment*. The ending moment is specified in the FX preset, with "end" as default.


void **PlayFX**(string action, string moment, object actor, object target, point pos, point dir)
string action
: The name of the FX action.

string moment
: The action's moment. Normally an FX has a *start* and an *end*, but may have various moments in-between.

object actor
: Used to give context to the FX. Can be a string or an object. If object is provided, then it's member *fx_actor_class* is used, or its class if no such member is available. The object can be used for many purposes by the FX (e.g. attaching effects to it)

object target
: Similar to the **actor** argument. Used to give additional context to the FX.

point pos
: Optional FX position. Normally the position of the FX is determined by rules in the FX preset, based on the actor or the target.

point dir
: Optional FX direction. Normally the direction of the FX is determined by rules in the FX preset, based on the actor or the target.


## PlaySound

Associates a sound to be played from this object.


int, string **PlaySound**(string sound, [string type, int volume, int crossfade, bool looping, point pos_or_obj, int loud_dist, int time_offset])
string sound
: a sound name (sound bank) or a sound filename

string type
: a sound type name to be used. Will override the type of the bank (if bank is provided as first argument). 

int volume
: forces the volume of the sound between 0 and 1000 (the sound bank volume is used by default).

int crossfade
: optional cross-fade time if changing the sound state.

bool looping
: forces sound looping.

point pos_or_obj
: point or object as sound position.

int loud_dist
: custom loud distance.

int time_offset
: initial time offset in teh sound.

_returns_ int handle
: the sound handle if successful.

_returns_ string error
: error if any (picking a silence sample from a bank would result in a missing handle but no error result).


## RGB

Represent an RGB color in integer format.


int **RGB**(int red, int green, int blue)
int red
: red componnent, ranging from 0 to 255

int green
: green componnent, ranging from 0 to 255

int blue
: blue componnent, ranging from 0 to 255

_returns_ int
: RGB color represented by an integer.


## RGBA

Represent an RGBA color in integer format.


int **RGBA**(int red, int green, int blue, int alpha)
int red
: red componnent, ranging from 0 to 255

int green
: green componnent, ranging from 0 to 255

int blue
: blue componnent, ranging from 0 to 255

int alpha
: alpha componnent (opacity), ranging from 0 to 255

_returns_ int
: RGB color represented by an integer


## ReadModPersistentData

Reads data from a persistent storage, that can be accessed between different game sessions.

This storage is not shared, but is per mod. Anything read here has been previously stored only by the same mod using [WriteModPersistentData](#WriteModPersistentData).


err, data **ReadModPersistentData**()
_returns_ err
: error message or nil, if successful.

_returns_ data
: data previously stored or nil.

See also: [LuaCodeToTuple](#LuaCodeToTuple), [Decompress](#Decompress), [AsyncDecompress](#AsyncDecompress);


## ResolveInteractableObject

Resolves the interactable in a collection.

An interactable can be in a collection with other objects.

One is the interactable and the rest are considered visuals.


object **ResolveInteractableObject**(obj)
obj
: An object in the collection.


## ResolvePos

Returns a position from different argument variants


point **ResolvePos**(point pt)

point **ResolvePos**(object obj)

point **ResolvePos**(int x, int y [, int z])
_returns_ point
: position


## ResolvePosXYZ

Returns the coordinates of a position from different argument variants


int, int, int **ResolvePosXYZ**(point pt)

int, int, int **ResolvePosXYZ**(object obj)

int, int, int **ResolvePosXYZ**(int x, int y [, int z])
_returns_ int
: x coordinate

_returns_ int
: x coordinate

_returns_ int
: z coordinate, only returned if valid


## ResolveVisualPos

Returns a visual position from different argument variants


point **ResolveVisualPos**(point pt)

point **ResolveVisualPos**(object obj)

point **ResolveVisualPos**(int x, int y [, int z])
_returns_ point
: position


## ResolveVisualPosXYZ

Returns the coordinates of a visual position from different argument variants


int, int, int **ResolveVisualPosXYZ**(point pt)

int, int, int **ResolveVisualPosXYZ**(object obj)

int, int, int **ResolveVisualPosXYZ**(int x, int y [, int z])
_returns_ int
: x coordinate

_returns_ int
: x coordinate

_returns_ int
: z coordinate, only returned if valid


## ResumeProcessing

Resumes the processing of routines from a named process. Resuming an already resumed process, or resuming it with time delay, would lead to an error.


void **ResumeProcessing**(string process, type reason, bool ignore_errors)
string process
: the name of the process, which routines should be suspended.

type reason
: the reason to be used in order to resume the processing later. Could be any type.

bool ignore_errors
: ignore resume errors (e.g. process already resumed).


## StateIdx

Gets the index of a state (animation) by its name.


int **StateIdx**(int state)
_returns_ int
: state index or -1 if not found.


## StateName

Gets the name of a state (animation) by its index.


string **StateName**(int state)
_returns_ string
: state name or an invalid name if not found.


## SuspendProcessing

Suspends the processing of routines from a named process. Multiple suspending with the same reason would lead to an error.


void **SuspendProcessing**(string process, type reason, bool ignore_errors)
string process
: the name of the process, which routines should be suspended.

type reason
: the reason to be used in order to resume the processing later. Could be any type.

bool ignore_errors
: ignore suspending errors (e.g. process already suspended).


## Transform

Transform a point by rotation, translation and scaling


point **Transform**(pos, angle, offset = point30, axis = axis_z, scale = 100, inverse = false)

point **Transform**(x, y, z, angle, offset = point30, axis = axis_z, scale = 100, inverse = false)
point pos
: pos to be transformed.

int x, y, z
: pos given as coordinates to be transformed.

int angle
: rotation angle.

point offset
: translation offset.

point axis
: rotation axis.

int scale
: scaling percents.

bool inverse
: perform the inverse transformation.

_returns_ point
: the transformed point.



Transform a box by rotation, translation and scaling


box **Transform**(bx, angle, offset = point30, axis = axis_z, scale = 100)
box bx
: bx to be transformed.

int angle
: rotation angle.

point offset
: translation offset.

point axis
: rotation axis.

int scale
: scaling percents.

_returns_ box
: the transformed box.


## TupleToLuaCode

Converts a tuple of values to an executable Lua expression.

Use [LuaCodeToTuple](#LuaCodeToTuple) for evaluating the Lua expression.


string code **TupleToLuaCode**(values...)
values...
: tuple of values to be converted to executable code string.

_returns_ string code
: the supplied tuple, converted to Lua code.


## ValueToLuaCode

Converts a value to an executable Lua expresion.

Use _'LuaCodeToTuple()'_ for evaluating the Lua expression.


string code **ValueToLuaCode**(value, int indent)
value
: value to be converted.

int indent
: initial number of indentations.

pstr pstr
: pstr string to serialize into.

table injected_props
: table with metadata of properties injected from parent objects.

_returns_ string code
: the supplied value, converted to Lua code.


## WaitCustomPopup

Displays a custom popup and waits for the players response.

This function should always be called from within a GameTime thread.


int choice **WaitCustomPopup**(string title, string text, table choices, window parent)
string title
: title of the popup.

string text
: body text of the popup.

table choices
: array of up to four choices for the user.

window parent
: parent window (this is optional only ingame).

_returns_ int choice
: The users choice.


## WriteModPersistentData

Writes data into a persistent storage, that can be accessed between different game sessions.

The data must be a string, no longer than *const.MaxModDataSize* - make sure to always check if you're exceeding this size.

This storage is not shared, but is per mod. Anything stored here can only be read by the same mod using [ReadModPersistentData](#ReadModPersistentData).


err **WriteModPersistentData**(data)
data
: the data to be stored (as a string).

_returns_ err
: error message or nil, if successful.

See also: [TupleToLuaCode](#TupleToLuaCode), [Compress](#Compress), [AsyncCompress](#AsyncCompress);


## WriteModPersistentStorageTable

Writes `CurrentModStorageTable` into a persistent storage, that can be accessed between different game sessions.

This is an ease-of-use function for the most common use case of persistent storage - when storing data in a table.

It uses [WriteModPersistentData](#WriteModPersistentData) internally, thus the *const.MaxModDataSize* limit applies.


err **WriteModPersistentStorageTable**()
_returns_ err
: error message or nil, if successful.


## array_set

A set that preserves the order in which keys were inserted.

Can be iterated like an array.

Insertion is O(1).

Removal is O(n).




array_set **array_set**(...)
values...
: key/value pairs to be inserted into the array_set



Example:

~~~~ Lua
	local set = array_set()
	set:insert("foo")
	set:insert("bar")
	set:insert("baz", "123")
	set:insert("bag", "456")
	for i, obj in ipairs(set) do
		print(i, obj, set[obj])
	end
	-- 1 foo true
	-- 2 bar true
	-- 3 baz 123
	-- 4 bag 456
	set:remove("foo") -- can remove by value
	set:remove("baz", 2) -- can specify the index for removal
	for i, obj in ipairs(set) do
		print(i, obj, set[obj])
	end
	-- 1 bar true
	-- 2 bag 45
~~~~

## ripairs

Reverse array iterator. It is safe to remove from the array the elements already returned including the current one.


... **ripairs**(array)
array table
: the array to reverse-iterate.


## sync_set

An unordered set that can be iterated like an array.

Unlike the regular set, iteration is synchronous.

Insertion is O(1).

Removal is O(1).

It is implemented by putting the last element of the array part of the set into the index of the removed element.




sync_set **sync_set**(...)
values...
: objects to be inserted into the sync_set



Example:

~~~~ Lua
	local set = sync_set()
	set:insert("foo")
	set:insert("bar")
	set:insert("baz")
	for i, obj in ipairs(set) do
		print(i, obj)
	end
	-- 1 foo
	-- 2 bar
	-- 3 baz
	set:remove("foo")
	for i, obj in ipairs(set) do
		print(i, obj)
	end
	-- 1 baz
	-- 2 bar
~~~~

## xxhash

Calculates a hash of all its parameters. Uses [xxhash64](http://cyan4973.github.io/xxHash/).

No bitshifting or XOR magic, xxhash functions only.


number **xxhash**(...)
...
: arbitrary number of params of type string, number, bool, nil, grid, userdata

_returns_ number
: hash of the concatenated byte content of all the parameters.





(insert footer.md.html here)
<link rel="stylesheet" type="text/css" href="Style.css" />
<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>