-
Notifications
You must be signed in to change notification settings - Fork 41
/
mist.lua
9556 lines (8442 loc) · 321 KB
/
mist.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
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
--[[--
MIST Mission Scripting Tools.
## Description:
MIssion Scripting Tools (MIST) is a collection of Lua functions
and databases that is intended to be a supplement to the standard
Lua functions included in the simulator scripting engine.
MIST functions and databases provide ready-made solutions to many common
scripting tasks and challenges, enabling easier scripting and saving
mission scripters time. The table mist.flagFuncs contains a set of
Lua functions (that are similar to Slmod functions) that do not
require detailed Lua knowledge to use.
However, the majority of MIST does require knowledge of the Lua language,
and, if you are going to utilize these components of MIST, it is necessary
that you read the Simulator Scripting Engine guide on the official ED wiki.
## Links:
ED Forum Thread: <http://forums.eagle.ru/showthread.php?t=98616>
##Github:
Development <https://github.com/mrSkortch/MissionScriptingTools>
Official Releases <https://github.com/mrSkortch/MissionScriptingTools/tree/master>
@script MIST
@author Speed
@author Grimes
@author lukrop
]]
mist = {}
-- don't change these
mist.majorVersion = 4
mist.minorVersion = 5
mist.build = 127
-- forward declaration of log shorthand
local log
local dbLog
local mistSettings = {
errorPopup = false, -- errors printed by mist logger will create popup warning you
warnPopup = false,
infoPopup = false,
logLevel = 'warn',
dbLog = 'warn',
}
do -- the main scope
local coroutines = {}
local tempSpawnedUnits = {} -- birth events added here
local tempSpawnedGroups = {}
local tempSpawnGroupsCounter = 0
local mistAddedObjects = {} -- mist.dynAdd unit data added here
local mistAddedGroups = {} -- mist.dynAdd groupdata added here
local writeGroups = {}
local lastUpdateTime = 0
local updateAliveUnitsCounter = 0
local updateTenthSecond = 0
local mistGpId = 70000
local mistUnitId = 70000
local mistDynAddIndex = {[' air '] = 0, [' hel '] = 0, [' gnd '] = 0, [' bld '] = 0, [' static '] = 0, [' shp '] = 0}
local scheduledTasks = {}
local taskId = 0
local idNum = 0
mist.nextGroupId = 1
mist.nextUnitId = 1
local function initDBs() -- mist.DBs scope
mist.DBs = {}
mist.DBs.markList = {}
mist.DBs.missionData = {}
if env.mission then
mist.DBs.missionData.startTime = env.mission.start_time
mist.DBs.missionData.theatre = env.mission.theatre
mist.DBs.missionData.version = env.mission.version
mist.DBs.missionData.files = {}
if type(env.mission.resourceCounter) == 'table' then
for fIndex, fData in pairs (env.mission.resourceCounter) do
mist.DBs.missionData.files[#mist.DBs.missionData.files + 1] = mist.utils.deepCopy(fIndex)
end
end
-- if we add more coalition specific data then bullseye should be categorized by coaliton. For now its just the bullseye table
mist.DBs.missionData.bullseye = {}
mist.DBs.missionData.countries = {}
end
mist.DBs.drawingByName = {}
mist.DBs.drawingIndexed = {}
if env.mission.drawings and env.mission.drawings.layers then
for i = 1, #env.mission.drawings.layers do
local l = env.mission.drawings.layers[i]
for j = 1, #l.objects do
local copy = mist.utils.deepCopy(l.objects[j])
--log:warn(copy)
local doOffset = false
copy.layer = l.name
local theta = copy.angle or 0
theta = math.rad(theta)
if copy.primitiveType == "Polygon" then
if copy.polygonMode == 'rect' then
local h, w = copy.height, copy.width
copy.points = {}
copy.points[1] = {x = h/2, y = w/2}
copy.points[2] = {x = -h/2, y = w/2}
copy.points[3] = {x = -h/2, y = -w/2}
copy.points[4] = {x = h/2, y = -w/2}
doOffset = true
elseif copy.polygonMode == "circle" then
copy.points = {x = copy.mapX, y = copy.mapY}
elseif copy.polygonMode == 'oval' then
copy.points = {}
local numPoints = 24
local angleStep = (math.pi*2)/numPoints
doOffset = true
for v = 1, numPoints do
local pointAngle = v * angleStep
local x = copy.r1 * math.cos(pointAngle)
local y = copy.r2 * math.sin(pointAngle)
table.insert(copy.points,{x=x,y=y})
end
elseif copy.polygonMode == "arrow" then
doOffset = true
end
if theta ~= 0 and copy.points and doOffset == true then
--log:warn('offsetting Values')
for p = 1, #copy.points do
local offset = mist.vec.rotateVec2(copy.points[p], theta)
copy.points[p] = offset
end
--log:warn(copy.points[1])
end
elseif copy.primitiveType == "Line" and copy.closed == true then
table.insert(copy.points, mist.utils.deepCopy(copy.points[1]))
end
if copy.points and #copy.points > 1 then
for u = 1, #copy.points do
copy.points[u].x = mist.utils.round(copy.points[u].x + copy.mapX, 2)
copy.points[u].y = mist.utils.round(copy.points[u].y + copy.mapY, 2)
end
end
if mist.DBs.drawingByName[copy.name] then
log:warn("Drawing by the name of [ $1 ] already exists in DB. Failed to add to mist.DBs.drawingByName.", copy.name)
else
mist.DBs.drawingByName[copy.name] = copy
end
table.insert(mist.DBs.drawingIndexed, copy)
end
end
end
local abRef = {units = {}, airbase = {}}
for ind, val in pairs(world.getAirbases()) do
local cat = "airbase"
if Airbase.getDesc(val).category > 0 then
cat = "units"
end
abRef[cat][tonumber(val:getID())] = {name = val:getName()}
end
mist.DBs.navPoints = {}
mist.DBs.units = {}
--Build mist.db.units and mist.DBs.navPoints
for coa_name_miz, coa_data in pairs(env.mission.coalition) do
local coa_name = coa_name_miz
if string.lower(coa_name_miz) == 'neutrals' then
coa_name = 'neutral'
end
local coaEnum = coalition.side[string.upper(coa_name)]
if type(coa_data) == 'table' then
mist.DBs.units[coa_name] = {}
if coa_data.bullseye then
mist.DBs.missionData.bullseye[coa_name] = {}
mist.DBs.missionData.bullseye[coa_name].x = coa_data.bullseye.x
mist.DBs.missionData.bullseye[coa_name].y = coa_data.bullseye.y
end
-- build nav points DB
mist.DBs.navPoints[coa_name] = {}
if coa_data.nav_points then --navpoints
--mist.debug.writeData (mist.utils.serialize,{'NavPoints',coa_data.nav_points}, 'NavPoints.txt')
for nav_ind, nav_data in pairs(coa_data.nav_points) do
if type(nav_data) == 'table' then
mist.DBs.navPoints[coa_name][nav_ind] = mist.utils.deepCopy(nav_data)
mist.DBs.navPoints[coa_name][nav_ind].name = nav_data.callsignStr -- name is a little bit more self-explanatory.
mist.DBs.navPoints[coa_name][nav_ind].point = {} -- point is used by SSE, support it.
mist.DBs.navPoints[coa_name][nav_ind].point.x = nav_data.x
mist.DBs.navPoints[coa_name][nav_ind].point.y = 0
mist.DBs.navPoints[coa_name][nav_ind].point.z = nav_data.y
end
end
end
if coa_data.country then --there is a country table
for cntry_id, cntry_data in pairs(coa_data.country) do
local countryName = string.lower(cntry_data.name)
if cntry_data.id and country.names[cntry_data.id] then
countryName = string.lower(country.names[cntry_data.id])
end
mist.DBs.missionData.countries[countryName] = coa_name
mist.DBs.units[coa_name][countryName] = {}
mist.DBs.units[coa_name][countryName].countryId = cntry_data.id
if type(cntry_data) == 'table' then --just making sure
for obj_cat_name, obj_cat_data in pairs(cntry_data) do
if obj_cat_name == "helicopter" or obj_cat_name == "ship" or obj_cat_name == "plane" or obj_cat_name == "vehicle" or obj_cat_name == "static" then --should be an unncessary check
local category = obj_cat_name
if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then --there's a group!
mist.DBs.units[coa_name][countryName][category] = {}
for group_num, group_data in pairs(obj_cat_data.group) do
local helipadId
local airdromeId
if group_data.route and group_data.route.points and group_data.route.points[1] then
if group_data.route.points[1].airdromeId then
airdromeId = group_data.route.points[1].airdromeId
--table.insert(abRef.airbase[group_data.route.points[1].airdromeId], group_data.groupId)
elseif group_data.route.points[1].helipadId then
helipadId = group_data.route.points[1].helipadId
--table.insert(abRef.units[group_data.route.points[1].helipadId], group_data.groupId)
end
end
if group_data and group_data.units and type(group_data.units) == 'table' then --making sure again- this is a valid group
mist.DBs.units[coa_name][countryName][category][group_num] = {}
local groupName = group_data.name
if env.mission.version > 7 and env.mission.version < 19 then
groupName = env.getValueDictByKey(groupName)
end
mist.DBs.units[coa_name][countryName][category][group_num].groupName = groupName
mist.DBs.units[coa_name][countryName][category][group_num].groupId = group_data.groupId
mist.DBs.units[coa_name][countryName][category][group_num].category = category
mist.DBs.units[coa_name][countryName][category][group_num].coalition = coa_name
mist.DBs.units[coa_name][countryName][category][group_num].coalitionId = coaEnum
mist.DBs.units[coa_name][countryName][category][group_num].country = countryName
mist.DBs.units[coa_name][countryName][category][group_num].countryId = cntry_data.id
mist.DBs.units[coa_name][countryName][category][group_num].startTime = group_data.start_time
mist.DBs.units[coa_name][countryName][category][group_num].task = group_data.task
mist.DBs.units[coa_name][countryName][category][group_num].hidden = group_data.hidden
mist.DBs.units[coa_name][countryName][category][group_num].units = {}
mist.DBs.units[coa_name][countryName][category][group_num].radioSet = group_data.radioSet
mist.DBs.units[coa_name][countryName][category][group_num].uncontrolled = group_data.uncontrolled
mist.DBs.units[coa_name][countryName][category][group_num].frequency = group_data.frequency
mist.DBs.units[coa_name][countryName][category][group_num].modulation = group_data.modulation
for unit_num, unit_data in pairs(group_data.units) do
local units_tbl = mist.DBs.units[coa_name][countryName][category][group_num].units --pointer to the units table for this group
units_tbl[unit_num] = {}
if env.mission.version > 7 and env.mission.version < 19 then
units_tbl[unit_num].unitName = env.getValueDictByKey(unit_data.name)
else
units_tbl[unit_num].unitName = unit_data.name
end
units_tbl[unit_num].type = unit_data.type
units_tbl[unit_num].skill = unit_data.skill --will be nil for statics
units_tbl[unit_num].unitId = unit_data.unitId
units_tbl[unit_num].category = category
units_tbl[unit_num].coalition = coa_name
units_tbl[unit_num].coalitionId = coaEnum
units_tbl[unit_num].country = countryName
units_tbl[unit_num].countryId = cntry_data.id
units_tbl[unit_num].heading = unit_data.heading
units_tbl[unit_num].playerCanDrive = unit_data.playerCanDrive
units_tbl[unit_num].alt = unit_data.alt
units_tbl[unit_num].alt_type = unit_data.alt_type
units_tbl[unit_num].speed = unit_data.speed
units_tbl[unit_num].livery_id = unit_data.livery_id
if unit_data.point then --ME currently does not work like this, but it might one day
units_tbl[unit_num].point = unit_data.point
else
units_tbl[unit_num].point = {}
units_tbl[unit_num].point.x = unit_data.x
units_tbl[unit_num].point.y = unit_data.y
end
units_tbl[unit_num].x = unit_data.x
units_tbl[unit_num].y = unit_data.y
units_tbl[unit_num].callsign = unit_data.callsign
units_tbl[unit_num].onboard_num = unit_data.onboard_num
units_tbl[unit_num].hardpoint_racks = unit_data.hardpoint_racks
units_tbl[unit_num].psi = unit_data.psi
if helipadId then
units_tbl[unit_num].helipadId = mist.utils.deepCopy(helipadId)
end
if airdromeId then
units_tbl[unit_num].airdromeId = mist.utils.deepCopy(airdromeId)
end
units_tbl[unit_num].groupName = groupName
units_tbl[unit_num].groupId = group_data.groupId
units_tbl[unit_num].linkUnit = unit_data.linkUnit
if unit_data.AddPropAircraft then
units_tbl[unit_num].AddPropAircraft = unit_data.AddPropAircraft
end
if category == 'static' then
units_tbl[unit_num].categoryStatic = unit_data.category
units_tbl[unit_num].shape_name = unit_data.shape_name
if group_data.linkOffset then
if group_data.route and group_data.route.points and group_data.route.points[1] and group_data.route.points[1].linkUnit then
units_tbl[unit_num].linkUnit = group_data.route.points[1].linkUnit
end
units_tbl[unit_num].offset = unit_data.offsets
end
if unit_data.mass then
units_tbl[unit_num].mass = unit_data.mass
end
if unit_data.canCargo then
units_tbl[unit_num].canCargo = unit_data.canCargo
end
if unit_data.category == "Heliports" then
if not abRef.units[unit_data.unitId] then
abRef.units[unit_data.unitId] = {name = unit_data.name}
end
end
end
end --for unit_num, unit_data in pairs(group_data.units) do
end --if group_data and group_data.units then
end --for group_num, group_data in pairs(obj_cat_data.group) do
end --if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then
end --if obj_cat_name == "helicopter" or obj_cat_name == "ship" or obj_cat_name == "plane" or obj_cat_name == "vehicle" or obj_cat_name == "static" then
end --for obj_cat_name, obj_cat_data in pairs(cntry_data) do
end --if type(cntry_data) == 'table' then
end --for cntry_id, cntry_data in pairs(coa_data.country) do
end --if coa_data.country then --there is a country table
end --if coa_name == 'red' or coa_name == 'blue' and type(coa_data) == 'table' then
end --for coa_name, coa_data in pairs(mission.coalition) do
mist.DBs.unitsByName = {}
mist.DBs.unitsById = {}
mist.DBs.unitsByCat = {}
mist.DBs.unitsByCat.helicopter = {} -- adding default categories
mist.DBs.unitsByCat.plane = {}
mist.DBs.unitsByCat.ship = {}
mist.DBs.unitsByCat.static = {}
mist.DBs.unitsByCat.vehicle = {}
mist.DBs.unitsByNum = {}
mist.DBs.groupsByName = {}
mist.DBs.groupsById = {}
mist.DBs.humansByName = {}
mist.DBs.humansById = {}
mist.DBs.dynGroupsAdded = {} -- will be filled by mist.dbUpdate from dynamically spawned groups
mist.DBs.activeHumans = {}
mist.DBs.aliveUnits = {} -- will be filled in by the "updateAliveUnits" coroutine in mist.main.
mist.DBs.removedAliveUnits = {} -- will be filled in by the "updateAliveUnits" coroutine in mist.main.
mist.DBs.const = {}
mist.DBs.const.nato = {
a = "alpha",
b = "bravo",
c = "charlie",
d = "delta",
e = "echo",
f = "foxtrot",
g = "golf",
h = "hotel",
i = "india",
j = "juliett",
k = "kilo",
l = "lima",
m = "mike",
n = "november",
o = "oscar",
p = "papa",
q = "quebec",
r = "romeo",
s = "sierra",
t = "tango",
u = "uniform",
v = "victor",
w = "whiskey",
x = "xray",
y = "yankee",
z = "zulu",
}
-- not accessible by SSE, must use static list :-/
mist.DBs.const.callsigns = {
['NATO'] = {
['rules'] = {
['groupLimit'] = 9,
},
['AWACS'] = {
['Overlord'] = 1,
['Magic'] = 2,
['Wizard'] = 3,
['Focus'] = 4,
['Darkstar'] = 5,
},
['TANKER'] = {
['Texaco'] = 1,
['Arco'] = 2,
['Shell'] = 3,
},
['TRANSPORT'] = {
['Heavy'] = 9,
['Trash'] = 10,
['Cargo'] = 11,
['Ascot'] = 12,
['JTAC'] = {
['Axeman'] = 1,
['Darknight'] = 2,
['Warrior'] = 3,
['Pointer'] = 4,
['Eyeball'] = 5,
['Moonbeam'] = 6,
['Whiplash'] = 7,
['Finger'] = 8,
['Pinpoint'] = 9,
['Ferret'] = 10,
['Shaba'] = 11,
['Playboy'] = 12,
['Hammer'] = 13,
['Jaguar'] = 14,
['Deathstar'] = 15,
['Anvil'] = 16,
['Firefly'] = 17,
['Mantis'] = 18,
['Badger'] = 19,
},
['aircraft'] = {
['Enfield'] = 1,
['Springfield'] = 2,
['Uzi'] = 3,
['Colt'] = 4,
['Dodge'] = 5,
['Ford'] = 6,
['Chevy'] = 7,
['Pontiac'] = 8,
},
['unique'] = {
['A10'] = {
['Hawg'] = 9,
['Boar'] = 10,
['Pig'] = 11,
['Tusk'] = 12,
['rules'] = {
['canUseAircraft'] = true,
['appliesTo'] = {
'A-10C_2',
'A-10C',
'A-10A',
},
},
},
['f16'] = {
Viper = 9,
Venom = 10,
Lobo = 11,
Cowboy = 12,
Python = 13,
Rattler =14,
Panther = 15,
Wolf = 16,
Weasel = 17,
Wild = 18,
Ninja = 19,
Jedi = 20,
rules = {
['canUseAircraft'] = true,
['appliesTo'] = {
'F-16C_50',
'F-16C bl.52d',
'F-16C bl.50',
'F-16A MLU',
'F-16A',
},
},
},
['f18'] = {
['Hornet'] = 9,
['Squid'] = 10,
['Ragin'] = 11,
['Roman'] = 12,
Sting = 13,
Jury =14,
Jokey = 15,
Ram = 16,
Hawk = 17,
Devil = 18,
Check = 19,
Snake = 20,
['rules'] = {
['canUseAircraft'] = true,
['appliesTo'] = {
"FA-18C_hornet",
'F/A-18C',
},
},
},
['b1'] = {
['Bone'] = 9,
['Dark'] = 10,
['Vader'] = 11,
['rules'] = {
['canUseAircraft'] = true,
['appliesTo'] = {
'B-1B',
},
},
},
['b52'] = {
['Buff'] = 9,
['Dump'] = 10,
['Kenworth'] = 11,
['rules'] = {
['canUseAircraft'] = true,
['appliesTo'] = {
'B-52H',
},
},
},
['f15e'] = {
['Dude'] = 9,
['Thud'] = 10,
['Gunny'] = 11,
['Trek'] = 12,
Sniper = 13,
Sled =14,
Best = 15,
Jazz = 16,
Rage = 17,
Tahoe = 18,
['rules'] = {
['canUseAircraft'] = true,
['appliesTo'] = {
'F-15E',
--'F-15ERAZBAM',
},
},
},
},
},
},
}
mist.DBs.const.shapeNames = {
["Landmine"] = "landmine",
["FARP CP Blindage"] = "kp_ug",
["Subsidiary structure C"] = "saray-c",
["Barracks 2"] = "kazarma2",
["Small house 2C"] = "dom2c",
["Military staff"] = "aviashtab",
["Tech hangar A"] = "ceh_ang_a",
["Oil derrick"] = "neftevyshka",
["Tech combine"] = "kombinat",
["Garage B"] = "garage_b",
["Airshow_Crowd"] = "Crowd1",
["Hangar A"] = "angar_a",
["Repair workshop"] = "tech",
["Subsidiary structure D"] = "saray-d",
["FARP Ammo Dump Coating"] = "SetkaKP",
["Small house 1C area"] = "dom2c-all",
["Tank 2"] = "airbase_tbilisi_tank_01",
["Boiler-house A"] = "kotelnaya_a",
["Workshop A"] = "tec_a",
["Small werehouse 1"] = "s1",
["Garage small B"] = "garagh-small-b",
["Small werehouse 4"] = "s4",
["Shop"] = "magazin",
["Subsidiary structure B"] = "saray-b",
["FARP Fuel Depot"] = "GSM Rus",
["Coach cargo"] = "wagon-gruz",
["Electric power box"] = "tr_budka",
["Tank 3"] = "airbase_tbilisi_tank_02",
["Red_Flag"] = "H-flag_R",
["Container red 3"] = "konteiner_red3",
["Garage A"] = "garage_a",
["Hangar B"] = "angar_b",
["Black_Tyre"] = "H-tyre_B",
["Cafe"] = "stolovaya",
["Restaurant 1"] = "restoran1",
["Subsidiary structure A"] = "saray-a",
["Container white"] = "konteiner_white",
["Warehouse"] = "sklad",
["Tank"] = "bak",
["Railway crossing B"] = "pereezd_small",
["Subsidiary structure F"] = "saray-f",
["Farm A"] = "ferma_a",
["Small werehouse 3"] = "s3",
["Water tower A"] = "wodokachka_a",
["Railway station"] = "r_vok_sd",
["Coach a tank blue"] = "wagon-cisterna_blue",
["Supermarket A"] = "uniwersam_a",
["Coach a platform"] = "wagon-platforma",
["Garage small A"] = "garagh-small-a",
["TV tower"] = "tele_bash",
["Comms tower M"] = "tele_bash_m",
["Small house 1A"] = "domik1a",
["Farm B"] = "ferma_b",
["GeneratorF"] = "GeneratorF",
["Cargo1"] = "ab-212_cargo",
["Container red 2"] = "konteiner_red2",
["Subsidiary structure E"] = "saray-e",
["Coach a passenger"] = "wagon-pass",
["Black_Tyre_WF"] = "H-tyre_B_WF",
["Electric locomotive"] = "elektrowoz",
["Shelter"] = "ukrytie",
["Coach a tank yellow"] = "wagon-cisterna_yellow",
["Railway crossing A"] = "pereezd_big",
[".Ammunition depot"] = "SkladC",
["Small werehouse 2"] = "s2",
["Windsock"] = "H-Windsock_RW",
["Shelter B"] = "ukrytie_b",
["Fuel tank"] = "toplivo-bak",
["Locomotive"] = "teplowoz",
[".Command Center"] = "ComCenter",
["Pump station"] = "nasos",
["Black_Tyre_RF"] = "H-tyre_B_RF",
["Coach cargo open"] = "wagon-gruz-otkr",
["Subsidiary structure 3"] = "hozdomik3",
["FARP Tent"] = "PalatkaB",
["White_Tyre"] = "H-tyre_W",
["Subsidiary structure G"] = "saray-g",
["Container red 1"] = "konteiner_red1",
["Small house 1B area"] = "domik1b-all",
["Subsidiary structure 1"] = "hozdomik1",
["Container brown"] = "konteiner_brown",
["Small house 1B"] = "domik1b",
["Subsidiary structure 2"] = "hozdomik2",
["Chemical tank A"] = "him_bak_a",
["WC"] = "WC",
["Small house 1A area"] = "domik1a-all",
["White_Flag"] = "H-Flag_W",
["Airshow_Cone"] = "Comp_cone",
["Bulk Cargo Ship Ivanov"] = "barge-1",
["Bulk Cargo Ship Yakushev"] = "barge-2",
["Outpost"]="block",
["Road outpost"]="block-onroad",
["Container camo"] = "bw_container_cargo",
["Tech Hangar A"] = "ceh_ang_a",
["Bunker 1"] = "dot",
["Bunker 2"] = "dot2",
["Tanker Elnya 160"] = "elnya",
["F-shape barrier"] = "f_bar_cargo",
["Helipad Single"] = "farp",
["FARP"] = "farps",
["Fueltank"] = "fueltank_cargo",
["Gate"] = "gate",
["Armed house"] = "home1_a",
["FARP Command Post"] = "kp-ug",
["Watch Tower Armed"] = "ohr-vyshka",
["Oiltank"] = "oiltank_cargo",
["Pipes small"] = "pipes_small_cargo",
["Pipes big"] = "pipes_big_cargo",
["Oil platform"] = "plavbaza",
["Tetrapod"] = "tetrapod_cargo",
["Trunks long"] = "trunks_long_cargo",
["Trunks small"] = "trunks_small_cargo",
["Passenger liner"] = "yastrebow",
["Passenger boat"] = "zwezdny",
["Oil rig"] = "oil_platform",
["Gas platform"] = "gas_platform",
["Container 20ft"] = "container_20ft",
["Container 40ft"] = "container_40ft",
["Downed pilot"] = "cadaver",
["Parachute"] = "parash",
["Pilot F15 Parachute"] = "pilot_f15_parachute",
["Pilot standing"] = "pilot_parashut",
}
-- create mist.DBs.oldAliveUnits
-- do
-- local intermediate_alive_units = {} -- between 0 and 0.5 secs old
-- local function make_old_alive_units() -- called every 0.5 secs, makes the old_alive_units DB which is just a copy of alive_units that is 0.5 to 1 sec old
-- if intermediate_alive_units then
-- mist.DBs.oldAliveUnits = mist.utils.deepCopy(intermediate_alive_units)
-- end
-- intermediate_alive_units = mist.utils.deepCopy(mist.DBs.aliveUnits)
-- timer.scheduleFunction(make_old_alive_units, nil, timer.getTime() + 0.5)
-- end
-- make_old_alive_units()
-- end
--Build DBs
--dbLog:echo(abRef)
mist.DBs.spawnsByBase = {}
for coa_name, coa_data in pairs(mist.DBs.units) do
for cntry_name, cntry_data in pairs(coa_data) do
for category_name, category_data in pairs(cntry_data) do
if type(category_data) == 'table' then
for group_ind, group_data in pairs(category_data) do
if type(group_data) == 'table' and group_data.units and type(group_data.units) == 'table' and #group_data.units > 0 then -- OCD paradigm programming
mist.DBs.groupsByName[group_data.groupName] = mist.utils.deepCopy(group_data)
mist.DBs.groupsById[group_data.groupId] = mist.utils.deepCopy(group_data)
for unit_ind, unit_data in pairs(group_data.units) do
local copy = mist.utils.deepCopy(unit_data)
local num = #mist.DBs.unitsByNum + 1
copy.dbNum = num
mist.DBs.unitsByName[unit_data.unitName] = mist.utils.deepCopy(copy)
mist.DBs.unitsById[unit_data.unitId] = mist.utils.deepCopy(copy)
mist.DBs.unitsByCat[unit_data.category] = mist.DBs.unitsByCat[unit_data.category] or {} -- future-proofing against new categories...
table.insert(mist.DBs.unitsByCat[unit_data.category], mist.utils.deepCopy(copy))
--dbLog:info('inserting $1', unit_data.unitName)
table.insert(mist.DBs.unitsByNum, mist.utils.deepCopy(copy))
if unit_data.skill and (unit_data.skill == "Client" or unit_data.skill == "Player") then
mist.DBs.humansByName[unit_data.unitName] = mist.utils.deepCopy(copy)
mist.DBs.humansById[unit_data.unitId] = mist.utils.deepCopy(copy)
--if Unit.getByName(unit_data.unitName) then
-- mist.DBs.activeHumans[unit_data.unitName] = mist.utils.deepCopy(unit_data)
-- mist.DBs.activeHumans[unit_data.unitName].playerName = Unit.getByName(unit_data.unitName):getPlayerName()
--end
end
if unit_data.airdromeId then
--log:echo(unit_data.airdromeId)
--log:echo(abRef.airbase[unit_data.airdromeId])
if not mist.DBs.spawnsByBase[abRef.airbase[unit_data.airdromeId].name] then
mist.DBs.spawnsByBase[abRef.airbase[unit_data.airdromeId].name] = {}
end
table.insert(mist.DBs.spawnsByBase[abRef.airbase[unit_data.airdromeId].name], unit_data.unitName)
end
if unit_data.helipadId and abRef.units[unit_data.helipadId] and abRef.units[unit_data.helipadId].name then
if not mist.DBs.spawnsByBase[abRef.units[unit_data.helipadId].name] then
mist.DBs.spawnsByBase[abRef.units[unit_data.helipadId].name] = {}
end
table.insert(mist.DBs.spawnsByBase[abRef.units[unit_data.helipadId].name], unit_data.unitName)
end
end
end
end
end
end
end
end
mist.DBs.zonesByName = {}
mist.DBs.zonesByNum = {}
if env.mission.triggers and env.mission.triggers.zones then
for zone_ind, zone_data in pairs(env.mission.triggers.zones) do
if type(zone_data) == 'table' then
local zone = mist.utils.deepCopy(zone_data)
--log:warn(zone)
zone.point = {} -- point is used by SSE
zone.point.x = zone_data.x
zone.point.y = land.getHeight({x = zone_data.x, y = zone_data.y})
zone.point.z = zone_data.y
zone.properties = {}
if zone_data.properties then
for propInd, prop in pairs(zone_data.properties) do
if prop.value and tostring(prop.value) ~= "" then
zone.properties[prop.key] = prop.value
end
end
end
if zone.verticies then -- trust but verify
local r = 0
for i = 1, #zone.verticies do
local dist = mist.utils.get2DDist(zone.point, zone.verticies[i])
if dist > r then
r = mist.utils.deepCopy(dist)
end
end
zone.radius = r
end
if zone.linkUnit then
local uRef = mist.DBs.unitsByName[zone.linkUnit]
if uRef then
if zone.verticies then
local offset = {}
for i = 1, #zone.verticies do
table.insert(offset, {dist = mist.utils.get2DDist(uRef.point, zone.verticies[i]), heading = mist.getHeadingPoints(uRef.point, zone.verticies[i]) + uRef.heading})
end
zone.offset = offset
else
zone.offset = {dist = mist.utils.get2DDist(uRef.point, zone.point), heading = mist.getHeadingPoints(uRef.point, zone.point) + uRef.heading}
end
end
end
mist.DBs.zonesByName[zone_data.name] = zone
mist.DBs.zonesByNum[#mist.DBs.zonesByNum + 1] = mist.utils.deepCopy(zone) --[[deepcopy so that the zone in zones_by_name and the zone in
zones_by_num se are different objects.. don't want them linked.]]
end
end
end
--DynDBs
mist.DBs.MEunits = mist.utils.deepCopy(mist.DBs.units)
mist.DBs.MEunitsByName = mist.utils.deepCopy(mist.DBs.unitsByName)
mist.DBs.MEunitsById = mist.utils.deepCopy(mist.DBs.unitsById)
mist.DBs.MEunitsByCat = mist.utils.deepCopy(mist.DBs.unitsByCat)
mist.DBs.MEunitsByNum = mist.utils.deepCopy(mist.DBs.unitsByNum)
mist.DBs.MEgroupsByName = mist.utils.deepCopy(mist.DBs.groupsByName)
mist.DBs.MEgroupsById = mist.utils.deepCopy(mist.DBs.groupsById)
mist.DBs.deadObjects = {}
do
local mt = {}
function mt.__newindex(t, key, val)
local original_key = key --only for duplicate runtime IDs.
local key_ind = 1
while mist.DBs.deadObjects[key] do
--dbLog:warn('duplicate runtime id of previously dead object key: $1', key)
key = tostring(original_key) .. ' #' .. tostring(key_ind)
key_ind = key_ind + 1
end
if mist.DBs.aliveUnits and mist.DBs.aliveUnits[val.object.id_] then
----dbLog:info('object found in alive_units')
val.objectData = mist.utils.deepCopy(mist.DBs.aliveUnits[val.object.id_])
local pos = Object.getPosition(val.object)
if pos then
val.objectPos = pos.p
end
val.objectType = mist.DBs.aliveUnits[val.object.id_].category
elseif mist.DBs.removedAliveUnits and mist.DBs.removedAliveUnits[val.object.id_] then -- it didn't exist in alive_units, check old_alive_units
----dbLog:info('object found in old_alive_units')
val.objectData = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
local pos = Object.getPosition(val.object)
if pos then
val.objectPos = pos.p
end
val.objectType = mist.DBs.removedAliveUnits[val.object.id_].category
else --attempt to determine if static object...
----dbLog:info('object not found in alive units or old alive units')
local pos = Object.getPosition(val.object)
if pos then
local static_found = false
for ind, static in pairs(mist.DBs.unitsByCat.static) do
if ((pos.p.x - static.point.x)^2 + (pos.p.z - static.point.y)^2)^0.5 < 0.1 then --really, it should be zero...
--dbLog:info('correlated dead static object to position')
val.objectData = static
val.objectPos = pos.p
val.objectType = 'static'
static_found = true
break
end
end
if not static_found then
val.objectPos = pos.p
val.objectType = 'building'
val.typeName = Object.getTypeName(val.object)
end
else
val.objectType = 'unknown'
end
end
rawset(t, key, val)
end
setmetatable(mist.DBs.deadObjects, mt)
end
do -- mist unitID funcs
for id, idData in pairs(mist.DBs.unitsById) do
if idData.unitId > mist.nextUnitId then
mist.nextUnitId = mist.utils.deepCopy(idData.unitId)
end
if idData.groupId > mist.nextGroupId then
mist.nextGroupId = mist.utils.deepCopy(idData.groupId)
end
end
end
end
local function updateAliveUnits() -- coroutine function
--log:warn("updateALiveUnits")
local lalive_units = mist.DBs.aliveUnits -- local references for faster execution
local lunits = mist.DBs.unitsByNum
local ldeepcopy = mist.utils.deepCopy
local lUnit = Unit
local lremovedAliveUnits = mist.DBs.removedAliveUnits
local updatedUnits = {}
if #lunits > 0 then
local units_per_run = math.ceil(#lunits/20)
if units_per_run < 5 then
units_per_run = 5
end
for i = 1, #lunits do
if lunits[i].category ~= 'static' then -- can't get statics with Unit.getByName :(
local unit = lUnit.getByName(lunits[i].unitName)
if unit and unit:isExist() == true then
----dbLog:info("unit named $1 alive!", lunits[i].unitName) -- spammy
local pos = unit:getPosition()
local newtbl = ldeepcopy(lunits[i])
if pos then
newtbl.pos = pos.p
end
newtbl.unit = unit
--newtbl.rt_id = unit.id_
lalive_units[unit.id_] = newtbl
updatedUnits[unit.id_] = true
end
end
if i%units_per_run == 0 then
--log:warn("yield: $1", i)
coroutine.yield()
end
end
-- All units updated, remove any "alive" units that were not updated- they are dead!
for unit_id, unit in pairs(lalive_units) do
if not updatedUnits[unit_id] then
lremovedAliveUnits[unit_id] = unit
lalive_units[unit_id] = nil
end
end
end
end
local function dbUpdate(event, oType, origGroupName)
--dbLog:info('dbUpdate: $1', event)
local newTable = {}
local objType = oType
newTable.startTime = 0
if type(event) == 'string' then -- if name of an object.
local newObject
if Group.getByName(event) then
newObject = Group.getByName(event)
elseif StaticObject.getByName(event) then
newObject = StaticObject.getByName(event)
objType = "static"
-- log:info('its static')
else
log:warn('$1 is not a Group or Static Object. This should not be possible. Sent category is: $2', event, objType)
return false
end
local objName = newObject:getName()
newTable.name = origGroupName or objName
newTable.groupId = tonumber(newObject:getID())
newTable.groupName = origGroupName or objName
local unitOneRef
if objType == 'static' then
unitOneRef = newObject
newTable.countryId = tonumber(newObject:getCountry())