forked from Dimencia/DU-Orbital-Hud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flying_construct_FULL_HUD.conf
2317 lines (2235 loc) · 133 KB
/
flying_construct_FULL_HUD.conf
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
# This is a file describing a standard autoconfiguration, do not edit.
# See custom/sample.conf for a more generic template and explanation on the syntax.
name: D's Flying Construct - Full Archaego HUD
slots:
core:
class: CoreUnit
antigrav:
class: AntiGravityGeneratorUnit
warpdrive:
class: WarpDriveUnit
atmofueltank:
class: AtmoFuelContainer
select: all
spacefueltank:
class: SpaceFuelContainer
select: all
rocketfueltank:
class: RocketFuelContainer
select: all
gyro:
class: GyroUnit
weapon:
class: WeaponUnit
select: manual
radar:
class: RadarPVPUnit
select: manual
handlers:
unit:
start:
lua: |
Nav = Navigator.new(system, core, unit)
Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal, {1000, 5000, 10000, 20000, 30000})
Nav.axisCommandManager:setTargetGroundAltitude(4)
-- element widgets
-- For now we have to alternate between PVP and non-PVP widgets to have them on the same side.
_autoconf.displayCategoryPanel(weapon, weapon_size, L_TEXT("ui_lua_widget_weapon", "Weapons"), "weapon", true)
core.show()
_autoconf.displayCategoryPanel(radar, radar_size, L_TEXT("ui_lua_widget_periscope", "Periscope"), "periscope")
placeRadar = true
if atmofueltank_size > 0 then
_autoconf.displayCategoryPanel(atmofueltank, atmofueltank_size, L_TEXT("ui_lua_widget_atmofuel", "Atmo Fuel"), "fuel_container")
if placeRadar then
_autoconf.displayCategoryPanel(radar, radar_size, L_TEXT("ui_lua_widget_radar", "Radar"), "radar")
placeRadar = false
end
end
if spacefueltank_size > 0 then
_autoconf.displayCategoryPanel(spacefueltank, spacefueltank_size, L_TEXT("ui_lua_widget_spacefuel", "Space Fuel"), "fuel_container")
if placeRadar then
_autoconf.displayCategoryPanel(radar, radar_size, L_TEXT("ui_lua_widget_radar", "Radar"), "radar")
placeRadar = false
end
end
_autoconf.displayCategoryPanel(rocketfueltank, rocketfueltank_size, L_TEXT("ui_lua_widget_rocketfuel", "Rocket Fuel"), "fuel_container")
if placeRadar then -- We either have only rockets or no fuel tanks at all, uncommon for usual vessels
_autoconf.displayCategoryPanel(radar, radar_size, L_TEXT("ui_lua_widget_radar", "Radar"), "radar")
placeRadar = false
end
if antigrav ~= nil then antigrav.show() end
if warpdrive ~= nil then warpdrive.show() end
--if gyro ~= nil then gyro.show() end
-- freeze the player in he is remote controlling the construct
if Nav.control.isRemoteControlled() == 1 then
system.freeze(1)
end
-- landing gear
-- make sure every gears are synchonized with the first
gearExtended = (Nav.control.isAnyLandingGearExtended() == 1) -- make sure it's a lua boolean
if gearExtended then
Nav.control.extendLandingGears()
else
Nav.control.retractLandingGears()
end
unit.setTimer("apTick", 1/30)
stop:
lua: |
_autoconf.hideCategoryPanels()
if antigrav ~= nil then antigrav.hide() end
if warpdrive ~= nil then warpdrive.hide() end
if gyro ~= nil then gyro.hide() end
core.hide()
Nav.control.switchOffHeadlights()
tick:
args: ["apTick"]
lua: |
yawInput2 = 0
rollInput2 = 0
pitchInput2 = 0
local velocity = core.getWorldVelocity()
local velMag = vec3(velocity):len()
local sys = galaxyReference[0]
local planet = sys:closestBody(core.getConstructWorldPos())
local kepPlanet = Keplers()(planet)
orbit = kepPlanet:orbitalParameters(core.getConstructWorldPos(), velocity)
if orbit ~= nil then
ShowOrbitPanel()
system.updateData(orbitHeaderText,'{"label": "Planet", "value": "' .. planet.name .. '", "unit":""}')
if orbit.apoapsis == nil then
system.updateData(widgetApoapsisText, '{"label": "Apoapsis", "value": "N/A", "unit":""}')
else
system.updateData(widgetApoapsisText, '{"label": "Apoapsis", "value": "' .. getDistanceDisplayString(orbit.apoapsis.altitude) .. '", "unit":""}')
end
system.updateData(widgetPeriapsisText, '{"label": "Periapsis", "value": "' .. getDistanceDisplayString(orbit.periapsis.altitude) .. '", "unit":""}')
if orbit.apoapsis == nil then
system.updateData(widgetMinSpeedText, '{"label": "Min Speed", "value": "N/A", "unit":""}')
else
system.updateData(widgetMinSpeedText, '{"label": "Min Speed", "value": "' .. getSpeedDisplayString(orbit.apoapsis.speed) .. '", "unit":""}')
end
if orbit.periapsis.speed < MaxGameVelocity then
system.updateData(widgetMaxSpeedText, '{"label": "Max Speed", "value": "' .. getSpeedDisplayString(orbit.periapsis.speed) .. '", "unit":""}')
elseif orbit.apoapsis ~= nil then
system.updateData(widgetMaxSpeedText, '{"label": "Max Speed", "value": "' .. getSpeedDisplayString(orbit.apoapsis.speed) .. '", "unit":""}')
else
system.updateData(widgetMaxSpeedText, '{"label": "Max Speed", "value": "N/A", "unit":""}')
end
system.updateData(widgetEccentricityText, '{"label": "Eccentricity", "value": "' .. round(orbit.eccentricity,2) .. '", "unit":""}')
else
HideOrbitPanel()
end
if AutopilotTargetName ~= "None" then
ShowInterplanetaryPanel()
system.updateData(interplanetaryHeaderText, '{"label": "Target", "value": "' .. AutopilotTargetName .. '", "unit":""}')
travelTime = GetAutopilotTravelTime() -- This also sets AutopilotDistance so we don't have to calc it again
distance = AutopilotDistance
if not TurnBurn then
brakeDistance, brakeTime = GetAutopilotBrakeDistanceAndTime(velMag)
maxBrakeDistance, maxBrakeTime = GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)
else
brakeDistance, brakeTime = GetAutopilotTBBrakeDistanceAndTime(velMag)
maxBrakeDistance, maxBrakeTime = GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)
end
system.updateData(widgetDistanceText, '{"label": "Distance", "value": "' .. getDistanceDisplayString(distance) .. '", "unit":""}')
system.updateData(widgetTravelTimeText, '{"label": "Travel Time", "value": "' .. FormatTimeString(travelTime) .. '", "unit":""}')
system.updateData(widgetCurBrakeDistanceText, '{"label": "Cur Brake Distance", "value": "' .. getDistanceDisplayString(brakeDistance) .. '", "unit":""}')
system.updateData(widgetCurBrakeTimeText, '{"label": "Cur Brake Time", "value": "' .. FormatTimeString(brakeTime) .. '", "unit":""}')
system.updateData(widgetMaxBrakeDistanceText, '{"label": "Max Brake Distance", "value": "' .. getDistanceDisplayString(maxBrakeDistance) .. '", "unit":""}')
system.updateData(widgetMaxBrakeTimeText, '{"label": "Max Brake Time", "value": "' .. FormatTimeString(maxBrakeTime) .. '", "unit":""}')
else
HideInterplanetaryPanel()
end
updateHud()
if AutoBrake and AutopilotTargetPlanetName ~= "None" and distance <= maxBrakeDistance then
brakeInput = 1
if planet.name == AutopilotTargetPlanet.name and orbit.apoapsis ~= nil and orbit.eccentricity < 1 then
if LastEccentricity < orbit.eccentricity then
-- We're increasing eccentricity by braking, time to stop
brakeInput = 0
AutoBrake = false
end
end
end
if Autopilot and unit.getAtmosphereDensity() == 0 then
-- Planetary autopilot engaged, we are out of atmo, and it has a target
-- Do it.
-- If we're here, sadly, we really need to calc the distance every update (or tick)
AutopilotDistance = (vec3(AutopilotTargetCoords) - vec3(core.getConstructWorldPos())):len()
-- And tbh we should calc the brakeDistance live too, and of course it's also in meters
local brakeDistance, brakeTime = GetAutopilotBrakeDistanceAndTime(velMag)
--system.print(brakeDistance)
brakeDistance = brakeDistance -- * 1.05
brakeTime = brakeTime -- * 1.05 -- Padding?
-- Maybe instead of pointing at our vector, we point at our vector + how far off our velocity vector is
-- This is gonna be hard to get the negatives right.
-- If we're still in orbit, don't do anything, that velocity will suck
local targetCoords = AutopilotTargetCoords
if orbit.apoapsis == nil and velMag > 55 then
-- travelTime is inaccurate for this, but it'll work for our purposes.
-- velocity * time is distance, so get position from that
local estimatedPosition = (vec3(core.getWorldVelocity()) * travelTime)-vec3(core.getConstructWorldPos())
-- Now get the difference between this and the target position, not normalized,
local posDiff = estimatedPosition - AutopilotTargetCoords
-- And apply that difference directly to the TargetCoords... adding so it's in the same direction as it was
targetCoords = targetCoords + posDiff
end
local aligned = true -- It shouldn't be used if the following condition isn't met, but just in case
if not AutopilotCruising and not AutopilotBraking then
aligned = AlignToWorldVector((AutopilotTargetCoords-vec3(core.getConstructWorldPos())):normalize())
elseif TurnBurn then
aligned = AlignToWorldVector(-vec3(velocity):normalize())
end
if AutopilotAccelerating then
Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 100)
if vec3(core.getVelocity()):len() >= MaxGameVelocity then -- This is 29999 kph
AutopilotAccelerating = false
AutopilotStatus = "Cruising"
AutopilotCruising = true
Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 0)
end
-- Check if accel needs to stop for braking
if AutopilotDistance < brakeDistance then
AutopilotAccelerating = false
AutopilotStatus = "Braking"
AutopilotBraking = true
Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 0)
end
elseif AutopilotBraking then
if TurnBurn then
Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 100)
end -- Really hope it managed to align, I can't use those thresholds for this or it might not turnburn
brakeInput = 1 -- We'll do this every update that's ok, don't let them override without turning it off
-- Check if an orbit has been established and cut brakes and disable autopilot if so
-- We'll try <0.9 instead of <1 so that we don't end up in a barely-orbit where touching the controls will make it an escape orbit
-- Though we could probably keep going until it starts getting more eccentric, so we'd maybe have a circular orbit
if orbit ~= nil and orbit.eccentricity < 1 then
AutopilotStatus = "Circularizing Orbit"
if orbit.periapsis ~= nil and orbit.periapsis.altitude < ((vec3(planet.center) - vec3(core.getConstructWorldPos())):len() - planet.radius) then
AutopilotBraking = false
Autopilot = false
AutopilotStatus = "Aligning" -- Disable autopilot and reset
system.print("Autopilot completed, orbit established")
brakeInput = 0
Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 0)
end
end
elseif AutopilotCruising then
if AutopilotDistance < brakeDistance then
AutopilotAccelerating = false
AutopilotStatus = "Braking"
AutopilotBraking = true
end
else
-- It's engaged but hasn't started accelerating yet.
if aligned then
-- Re-align to 200km from our aligned right
if not AutopilotRealigned then
AutopilotTargetCoords = vec3(AutopilotTargetPlanet.center) + AutopilotTargetPlanet.radius * vec3(core.getConstructWorldOrientationRight()) + (vec3(core.getConstructWorldOrientationRight()) * 200000)
AutopilotRealigned = true
elseif aligned then
AutopilotAccelerating = true
AutopilotStatus = "Accelerating"
-- Set throttle to max
Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 100) -- 100?
end
end
-- If it's not aligned yet, don't try to burn yet.
end
end
LastEccentricity = orbit.eccentricity
system:
start:
lua: |
pitchInput = 0
rollInput = 0
yawInput = 0
pitchInput2 = 0
rollInput2 = 0
yawInput2 = 0
if unit.getAtmosphereDensity() > 0 then
brakeInput = 1
else
brakeInput = 0
end
-- Written by Dimencia. Linked sources where appropriate, most have been modified
AutoBrake = false
Autopilot = false
TurnBurn = false
AutopilotAccelerating = false
AutopilotBraking = false
AutopilotCruising = false
AutopilotRealigned = false
AutopilotStrength = 1 --export: How strongly autopilot tries to point at a target
DampingMultiplier = 40 --export: How strongly it dampens when nearing the correct orientation
alignmentTolerance = 0.001 --export: How closely it must align to a planet before accelerating to it
travelTime = 0
distance = 0
brakeDistance, brakeTime = 0
maxBrakeDistance, maxBrakeTime = 0
AutopilotStatus = "Aligning"
PreviousYawAmount = 0
PreviousPitchAmount = 0
PreviousRollAmount = 0
lastEccentricity = 0
local warmup = 32 --export: How long it takes your engines to warmup. Basic Space Engines, from XS to XL: 0.25,1,4,16,32
PrimaryR = 124 --export: Primary HUD color
PrimaryG = 252 --export: Primary HUD color
PrimaryB = 0 --export: Primary HUD color
function ShowOrbitPanel()
-- Orbit info
if panelOrbit == nil then
panelOrbit = system.createWidgetPanel("Orbital Information")
orbitHeader = system.createWidget(panelOrbit, "value")
orbitHeaderText = system.createData('{"label": "Planet", "value": "N/A", "unit":""}')
system.addDataToWidget(orbitHeaderText, orbitHeader)
widgetApoapsis = system.createWidget(panelOrbit, "value")
widgetApoapsisText = system.createData('{"label": "Apoapsis", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetApoapsisText, widgetApoapsis)
widgetPeriapsis = system.createWidget(panelOrbit, "value")
widgetPeriapsisText = system.createData('{"label": "Periapsis", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetPeriapsisText, widgetPeriapsis)
widgetMinSpeed = system.createWidget(panelOrbit, "value")
widgetMinSpeedText = system.createData('{"label": "Min Speed", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetMinSpeedText, widgetMinSpeed)
widgetMaxSpeed = system.createWidget(panelOrbit, "value")
widgetMaxSpeedText = system.createData('{"label": "Max Speed", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetMaxSpeedText, widgetMaxSpeed)
widgetEccentricity = system.createWidget(panelOrbit, "value")
widgetEccentricityText = system.createData('{"label": "Eccentricity", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetEccentricityText, widgetEccentricity)
end
end
function ShowInterplanetaryPanel()
-- Interplanetary helper
if panelInterplanetary == nil then
panelInterplanetary = system.createWidgetPanel("Interplanetary Helper")
interplanetaryHeader = system.createWidget(panelInterplanetary, "value")
interplanetaryHeaderText = system.createData('{"label": "Target Planet", "value": "N/A", "unit":""}')
system.addDataToWidget(interplanetaryHeaderText, interplanetaryHeader)
widgetDistance = system.createWidget(panelInterplanetary, "value")
widgetDistanceText = system.createData('{"label": "Distance", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetDistanceText, widgetDistance)
widgetTravelTime = system.createWidget(panelInterplanetary, "value")
widgetTravelTimeText = system.createData('{"label": "Travel Time", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetTravelTimeText, widgetTravelTime)
widgetCurBrakeDistance = system.createWidget(panelInterplanetary, "value")
widgetCurBrakeDistanceText = system.createData('{"label": "Cur Brake Distance", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetCurBrakeDistanceText, widgetCurBrakeDistance)
widgetCurBrakeTime = system.createWidget(panelInterplanetary, "value")
widgetCurBrakeTimeText = system.createData('{"label": "Cur Brake Time", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetCurBrakeTimeText, widgetCurBrakeTime)
widgetMaxBrakeDistance = system.createWidget(panelInterplanetary, "value")
widgetMaxBrakeDistanceText = system.createData('{"label": "Max Brake Distance", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetMaxBrakeDistanceText, widgetMaxBrakeDistance)
widgetMaxBrakeTime = system.createWidget(panelInterplanetary, "value")
widgetMaxBrakeTimeText = system.createData('{"label": "Max Brake Time", "value": "N/A", "unit":""}')
system.addDataToWidget(widgetMaxBrakeTimeText, widgetMaxBrakeTime)
end
end
function HideOrbitPanel()
system.destroyWidgetPanel(panelOrbit)
panelOrbit = nil
end
function HideInterplanetaryPanel()
system.destroyWidgetPanel(panelInterplanetary)
panelInterplanetary = nil
end
function ToggleAutoBrake()
if AutopilotTargetPlanetName ~= "None" and brakeInput == 0 and not AutoBrake then
AutoBrake = true
Autopilot = false
else
AutoBrake = false
end
end
function ToggleAutoPilot()
if AutopilotTargetPlanetName ~= "None" and brakeInput == 0 and unit.getAtmosphereDensity() == 0 and not Autopilot then
Autopilot = true
AutoBrake = false
else
Autopilot = false
end
end
function ToggleTurnBurn()
TurnBurn = not TurnBurn
end
system.showScreen(1)
function getRelativePitch(velocity)
velocity = vec3(velocity)
local pitch = -math.deg(math.atan(velocity.y, velocity.z)) + 180
-- This is 0-360 where 0 is straight up
pitch = pitch - 90
-- So now 0 is straight, but we can now get angles up to 420
if pitch < 0 then
pitch = 360 + pitch
end
-- Now, if it's greater than 180, say 190, make it go to like -170
if pitch > 180 then
pitch = -180 + (pitch-180)
end
-- And it's backwards.
return -pitch
end
function getRelativeYaw(velocity)
velocity = vec3(velocity)
return math.deg(math.atan(velocity.y, velocity.x)) - 90
end
function AlignToWorldVector(vector)
-- Sets inputs to attempt to point at the autopilot target
-- Meant to be called from Update or Tick repeatedly
vector = vec3(vector):normalize()
local targetVec = (vec3(core.getConstructWorldOrientationForward()) - vector)
local yawAmount = -getMagnitudeInDirection(targetVec, core.getConstructWorldOrientationRight()) * AutopilotStrength
local pitchAmount = -getMagnitudeInDirection(targetVec, core.getConstructWorldOrientationUp()) * AutopilotStrength
yawInput2 = yawInput2 - (yawAmount + (yawAmount - PreviousYawAmount) * DampingMultiplier)
pitchInput2 = pitchInput2 + (pitchAmount + (pitchAmount - PreviousPitchAmount) * DampingMultiplier)
PreviousYawAmount = yawAmount
PreviousPitchAmount = pitchAmount
-- Return true or false depending on whether or not we're aligned
if math.abs(yawAmount) < alignmentTolerance and math.abs(pitchAmount) < alignmentTolerance then
return true
end
return false
end
-- HUD - https://github.com/Rezoix/DU-hud with modifications
function updateHud()
local altitude = core.getAltitude()
local velocity = core.getVelocity()
local speed = vec3(velocity):len()
local worldV = vec3(core.getWorldVertical())
local constrF = vec3(core.getConstructWorldOrientationForward())
local constrR = vec3(core.getConstructWorldOrientationRight())
local constrV = vec3(core.getConstructWorldOrientationUp())
local pitch = getPitch(worldV, constrF, constrR)--180 - getRoll(worldV, constrR, constrF)
local roll = getRoll(worldV, constrF, constrR) --getRoll(worldV, constrF, constrR)
local bottomText = "ROLL"
local throt = math.floor(unit.getThrottle())
local spd = speed*3.6
local mode = 0
local primR = math.floor(PrimaryR *0.9 + 0.5)
local primG = math.floor(PrimaryG *0.9 + 0.5)
local primB = math.floor(PrimaryB *0.9 + 0.5)
if (unit.getAtmosphereDensity() == 0) then
mode = 1
else
mode = 0
end
if (mode == 1) then
if (speed > 5) then
pitch = getRelativePitch(velocity)
roll = getRelativeYaw(velocity)
else
pitch = 0
roll = 0
end
bottomText = "YAW"
end
local content = [[
<head>
<style>
body {margin: 0}
svg {display:block; position:absolute; top:0; left:0}
.majorLine {stroke:rgb(]] .. math.floor(PrimaryR *0.8 + 0.5) .. "," .. math.floor(PrimaryG * 0.8 + 0.5) .. "," .. math.floor(PrimaryB * 0.8 + 0.5) .. [[);opacity:0.7;stroke-width:3;fill-opacity:0;}
.minorLine {stroke:rgb(]] .. math.floor(PrimaryR *0.8 + 0.5) .. "," .. math.floor(PrimaryG * 0.8 + 0.5) .. "," .. math.floor(PrimaryB * 0.8 + 0.5) .. [[);opacity:0.3;stroke-width:3;fill-opacity:0;}
.text {fill:rgb(]] .. math.floor(PrimaryR *0.8 + 0.5) .. "," .. math.floor(PrimaryG * 0.8 + 0.5) .. "," .. math.floor(PrimaryB * 0.8 + 0.5) .. [[);font-family:Montserrat;font-weight:bold}
#space {}
#ecu {}
#atmos {}
</style>
</head>
<body>
<svg height="100%" width="100%" viewBox="0 0 1920 1080">
<g class="majorLine">
<line x1="939" y1="537" x2="957" y2="519"/>
<line x1="939" y1="543" x2="957" y2="561"/>
<line x1="981" y1="537" x2="963" y2="519"/>
<line x1="981" y1="543" x2="963" y2="561"/>
<line x1="932" y1="540" x2="945" y2="540"/>
<line x1="988" y1="540" x2="975" y2="540"/>
<line x1="960" y1="512" x2="960" y2="525"/>
<line x1="960" y1="568" x2="960" y2="555"/>
<g style="opacity:0.2">
<line x1="920" y1="540" x2="840" y2="540"/>
<line x1="1000" y1="540" x2="1080" y2="540"/>
<line x1="960" y1="500" x2="960" y2="470"/>
<line x1="960" y1="580" x2="960" y2="610"/>
</g>
<path d="M 700 0 L 740 35 Q 960 55 1180 35 L 1220 0"/>
<path d="M 792 550 L 785 550 L 785 650 L 792 650"/>
</g>
<g>
<polygon points="782,540 800,535 800,545" style="fill:rgb(]] .. PrimaryR .. "," .. PrimaryG .. "," .. PrimaryB .. [[);opacity:0.7"/>
<polygon points="1138,540 1120,535 1120,545" style="fill:rgb(]] .. PrimaryR .. "," .. PrimaryG .. "," .. PrimaryB .. [[);opacity:0.7"/>
<polygon points="960,725 955,707 965,707" style="fill:rgb(]] .. PrimaryR .. "," .. PrimaryG .. "," .. PrimaryB .. [[);opacity:0.7"/>
</g>
<g class="text">
<g font-size=10>
<text x="960" y="688" text-anchor="middle">]]..bottomText..[[</text>
<text x="960" y="698" text-anchor="middle">]]..math.floor(roll)..[[ deg</text>
<text x="945" y="580" text-anchor="start">PITCH</text>
<text x="945" y="590" text-anchor="start">]]..math.floor(pitch)..[[ deg</text>
<text x="1180" y="690" text-anchor="end">SPEED</text>
<text x="1180" y="700" text-anchor="end">]]..math.floor(spd)..[[ km/h</text>
<text x="790" y="660" text-anchor="start">THROT</text>
<text x="790" y="670" text-anchor="start">]]..throt..[[%</text>
</g>
<g font-size=15>
<text x="1020" y="33" text-anchor="middle" id="space">SPACE</text>
<text x="900" y="33" text-anchor="middle" id="atmos">ATMOS</text>
<text x="960" y="35" text-anchor="middle" id="ecu">ECU</text>
</g>
</g>]]
pitchC = math.floor(pitch)
for i = pitchC-25,pitchC+25 do
if (i%10==0) then
num = i
if (num > 180) then
num = -180 + (num-180)
elseif (num < -180) then
num = 180 + (num+180)
end
content = content..[[<g transform="translate(0 ]]..(-i*5 + pitch*5 + 5)..[[)">
<text x="845" y="540" style="fill:rgb(]] .. primR .. "," .. primG .. "," .. primB .. [[);text-anchor:end;font-size:12;font-family:Montserrat;font-weight:bold">]]..num..[[</text>
<text x="1075" y="540" style="fill:rgb(]] .. primR .. "," .. primG .. "," .. primB .. [[);text-anchor:start;font-size:12;font-family:Montserrat;font-weight:bold">]]..num..[[</text></g>]]
end
len = 5
if (i%10==0) then
len = 30
elseif (i%5==0) then
len = 15
end
content = content..[[
<g transform="translate(0 ]]..(-i*5 + pitch*5)..[[)">
<line x1="]]..(880-len)..[[" y1="540" x2="880" y2="540"style="stroke:rgb(]] .. primR .. "," .. primG .. "," .. primB .. [[);opacity:0.3;stroke-width:3"/>
<line x1="]]..(1040+len)..[[" y1="540" x2="1040" y2="540"style="stroke:rgb(]] .. primR .. "," .. primG .. "," .. primB .. [[);opacity:0.3;stroke-width:3"/></g>]]
end
rollC = math.floor(roll)
for i = rollC-35,rollC+35 do
if (i%10==0) then
local sign = i/math.abs(i)
if i == 0 then
sign = 0
end
num = math.abs(i)
if (num > 180) then
num = 180 + (180-num)
end
content = content..[[<g transform="rotate(]]..(i - roll)..[[,960,460)">
<text x="960" y="760" style="fill:rgb(]] .. primR .. "," .. primG .. "," .. primB .. [[);text-anchor:middle;font-size:12;font-family:Montserrat;font-weight:bold">]]..math.floor(sign*num+0.5)..[[</text></g>]]
end
len = 5
if (i%10==0) then
len = 15
elseif (i%5==0) then
len = 10
end
content = content..[[<g transform="rotate(]]..(i - roll)..[[,960,460)">
<line x1="960" y1="730" x2="960" y2="]]..(730+len)..[[" style="stroke:rgb(]] .. primR .. "," .. primG .. "," .. primB .. [[);opacity:0.3;stroke-width:2"/></g>]]
end
speedC=math.floor(spd)
for i = speedC-25,speedC+25 do
if (i%10==0) then
num = i
if spd > 1 then
content = content..[[<g transform="translate(0 ]]..(-i*5 + round(spd*5,0))..[[)">
<text x="1175" y="540" style="fill:rgb(]].. primR .. "," .. primG .. "," .. primB ..[[);text-anchor:end;font-size:12;font-family:Montserrat;font-weight:bold">]]..num..[[</text></g>]]
else
content = content..[[<g transform="translate(0 ]]..(-i*5)..[[)">
<text x="1175" y="540" style="fill:rgb(]].. primR .. "," .. primG .. "," .. primB ..[[);text-anchor:end;font-size:12;font-family:Montserrat;font-weight:bold">]]..num..[[</text></g>]]
end
end
len = 5
if (i%50==0) then
len = 30
elseif (i%25==0) then
len = 15
end
content = content..[[
<g transform="translate(0 ]]..(-i*5 + spd*5)..[[)">
<line x1="]]..(1140-len)..[[" y1="540" x2="1140 y2="540"style="stroke:rgb(1, 165, 177);opacity:0.3;stroke-width:3"/></g>]]
end
if mode == 0 then
content = content..[[
<g class="text">
<g font-size=10>
<text x="770" y="690" text-anchor="end">ALTITUDE</text>
<text x="770" y="700" text-anchor="end">]]..math.floor(altitude)..[[ m</text>
</g>
</g>]]
altC = math.floor(altitude)
for i = altC-25,altC+25 do
if (i%10==0) then
num = i
if (num < 0) then
num = 0
end
content = content..[[<g transform="translate(0 ]]..(-i*5 + altitude*5)..[[)">
<text x="745" y="540" style="fill:rgb(]] .. primR .. "," .. primG .. "," .. primB .. [[);text-anchor:end;font-size:12;font-family:Montserrat;font-weight:bold">]]..num..[[</text></g>]]
end
len = 5
if (i%50==0) then
len = 30
elseif (i%25==0) then
len = 15
end
content = content..[[
<g transform="translate(0 ]]..(-i*5 + altitude*5)..[[)">
<line x1="]]..(780-len)..[[" y1="540" x2="780" y2="540"style="stroke:rgb(1, 165, 177);opacity:0.3;stroke-width:3"/></g>]]
end
end
content = content..[[<g transform="translate(0 ]]..(1-throt)..[[)">
<polygon points="788,650 800,647 800,653" style="fill:rgb(]] .. primR .. "," .. primG .. "," .. primB .. [[);opacity:0.7"/>
</g>]]
if brakeInput == 1 then
content = content .. "<text x='960' y='900' font-size='20' fill='red' text-anchor='middle' font-family='Montserrat'>Brake Engaged</text>"
end
if AutoBrake and AutopilotTargetPlanetName ~= "None" then
if brakeInput == 0 then
content = content .. "<text x='960' y='225' font-size='20' fill='orange' text-anchor='middle' font-family='Montserrat'>Auto-Braking when within " .. getDistanceDisplayString(maxBrakeDistance) .. " of " .. AutopilotTargetPlanet.name .. "</text>"
else
content = content .. "<text x='960' y='225' font-size='20' fill='orange' text-anchor='middle' font-family='Montserrat'>Auto-Braking until eccentricity:" .. round(orbit.eccentricity,2) .. " begins to increase</text>"
end
elseif Autopilot and AutopilotTargetPlanetName ~= "None" then
content = content .. "<text x='960' y='225' font-size='20' fill='orange' text-anchor='middle' font-family='Montserrat'>Autopilot Engaged - " .. AutopilotStatus .. "</text>"
end
if TurnBurn then
content = content .. "<text x='960' y='150' font-size='20' fill='darkred' text-anchor='middle' font-family='Montserrat'>Turn & Burn Braking</text>"
end
content = content..[[</svg>]]
system.setScreen(content)
end
function getPitch(gravityDirection, forward, right)
local horizontalForward = gravityDirection:cross(right):normalize_inplace() -- Cross forward?
local pitch = math.acos(utils.clamp(horizontalForward:dot(-forward), -1, 1)) * constants.rad2deg -- acos?
if horizontalForward:cross(-forward):dot(right) < 0 then pitch = -pitch end -- Cross right dot forward?
return pitch
end
-- Planet Info - https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom with minor modifications
function Atlas()
return {
[0] = {
[1]={
GM=6930729684,
bodyId=1,
center={x=17465536.000,y=22665536.000,z=-34464.000},
name='Madis',
planetarySystemId=0,
radius=44300
},
[2]={
GM=157470826617,
bodyId=2,
center={x=-8.000,y=-8.000,z=-126303.000},
name='Alioth',
planetarySystemId=0,
radius=126068
},
[3]={
GM=11776905000,
bodyId=3,
center={x=29165536.000,y=10865536.000,z=65536.000},
name='Thades',
planetarySystemId=0,
radius=49000
},
[4]={
GM=14893847582,
bodyId=4,
center={x=-13234464.000,y=55765536.000,z=465536.000},
name='Talemai',
planetarySystemId=0,
radius=57450
},
[5]={
GM=16951680000,
bodyId=5,
center={x=-43534464.000,y=22565536.000,z=-48934464.000},
name='Feli',
planetarySystemId=0,
radius=60000
},
[6]={
GM=10502547741,
bodyId=6,
center={x=52765536.000,y=27165538.000,z=52065535.000},
name='Sicari',
planetarySystemId=0,
radius=51100
},
[7]={
GM=13033380591,
bodyId=7,
center={x=58665538.000,y=29665535.000,z=58165535.000},
name='Sinnen',
planetarySystemId=0,
radius=54950
},
[8]={
GM=18477723600,
bodyId=8,
center={x=80865538.000,y=54665536.000,z=-934463.940},
name='Teoma',
planetarySystemId=0,
radius=62000
},
[9]={
GM=18606274330,
bodyId=9,
center={x=-94134462.000,y=12765534.000,z=-3634464.000},
name='Jago',
planetarySystemId=0,
radius=61590
},
[10]={
GM=78480000,
bodyId=10,
center={x=17448118.224,y=22966846.286,z=143078.820},
name='Madis Moon 1',
planetarySystemId=0,
radius=10000
},
[11]={
GM=237402000,
bodyId=11,
center={x=17194626.000,y=22243633.880,z=-214962.810},
name='Madis Moon 2',
planetarySystemId=0,
radius=11000
},
[12]={
GM=265046609,
bodyId=12,
center={x=17520614.000,y=22184730.000,z=-309989.990},
name='Madis Moon 3',
planetarySystemId=0,
radius=15005
},
[21]={
GM=2118960000,
bodyId=21,
center={x=457933.000,y=-1509011.000,z=115524.000},
name='Alioth Moon 1',
planetarySystemId=0,
radius=30000
},
[22]={
GM=2165833514,
bodyId=22,
center={x=-1692694.000,y=729681.000,z=-411464.000},
name='Alioth Moon 4',
planetarySystemId=0,
radius=30330
},
[26]={
GM=68234043600,
bodyId=26,
center={x=-1404835.000,y=562655.000,z=-285074.000},
name='Sanctuary',
planetarySystemId=0,
radius=83400
},
[30]={
GM=211564034,
bodyId=30,
center={x=29214402.000,y=10907080.695,z=433858.200},
name='Thades Moon 1',
planetarySystemId=0,
radius=14002
},
[31]={
GM=264870000,
bodyId=31,
center={x=29404193.000,y=10432768.000,z=19554.131},
name='Thades Moon 2',
planetarySystemId=0,
radius=15000
},
[40]={
GM=141264000,
bodyId=40,
center={x=-13503090.000,y=55594325.000,z=769838.640},
name='Talemai Moon 2',
planetarySystemId=0,
radius=12000
},
[41]={
GM=106830900,
bodyId=41,
center={x=-12800515.000,y=55700259.000,z=325207.840},
name='Talemai Moon 3',
planetarySystemId=0,
radius=11000
},
[42]={
GM=264870000,
bodyId=42,
center={x=-13058408.000,y=55781856.000,z=740177.760},
name='Talemai Moon 1',
planetarySystemId=0,
radius=15000
},
[50]={
GM=499917600,
bodyId=50,
center={x=-43902841.780,y=22261034.700,z=-48862386.000},
name='Feli Moon 1',
planetarySystemId=0,
radius=14000
},
[70]={
GM=396912600,
bodyId=70,
center={x=58969616.000,y=29797945.000,z=57969449.000},
name='Sinnen Moon 1',
planetarySystemId=0,
radius=17000
},
[100]={
GM=13975172474,
bodyId=100,
center={x=98865536.000,y=-13534464.000,z=-934461.990},
name='Lacobus',
planetarySystemId=0,
radius=55650
},
[101]={
GM=264870000,
bodyId=101,
center={x=98905288.170,y=-13950921.100,z=-647589.530},
name='Lacobus Moon 3',
planetarySystemId=0,
radius=15000
},
[102]={
GM=444981600,
bodyId=102,
center={x=99180968.000,y=-13783862.000,z=-926156.400},
name='Lacobus Moon 1',
planetarySystemId=0,
radius=18000
},
[103]={
GM=211503600,
bodyId=103,
center={x=99250052.000,y=-13629215.000,z=-1059341.400},
name='Lacobus Moon 2',
planetarySystemId=0,
radius=14000
},
[110]={
GM=9204742375,
bodyId=110,
center={x=14165536.000,y=-85634465.000,z=-934464.300},
name='Symeon',
planetarySystemId=0,
radius=49050
},
[120]={
GM=7135606629,
bodyId=120,
center={x=2865536.700,y=-99034464.000,z=-934462.020},
name='Ion',
planetarySystemId=0,
radius=44950
},
[121]={
GM=106830900,
bodyId=121,
center={x=2472916.800,y=-99133747.000,z=-1133582.800},
name='Ion Moon 1',
planetarySystemId=0,
radius=11000
},
[122]={
GM=176580000,
bodyId=122,
center={x=2995424.500,y=-99275010.000,z=-1378480.700},
name='Ion Moon 2',
planetarySystemId=0,
radius=15000
}
}
}
end
function PlanetRef()
--[[
Provide coordinate transforms and access to kinematic related parameters
Author: JayleBreak
Usage (unit.start):
PlanetaryReference = require('planetref')
galaxyReference = PlanetaryReference(referenceTableSource)
helios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance
alioth = helios[2] -- PlanetaryReference.BodyParameters instance
Methods:
PlanetaryReference:getPlanetarySystem - based on planetary system ID.
PlanetaryReference.isMapPosition - 'true' if an instance of 'MapPosition'
PlanetaryReference.createBodyParameters - for entry into reference table
PlanetaryReference.BodyParameters - a class containing a body's information.
PlanetaryReference.MapPosition - a class for map coordinates
PlanetaryReference.PlanetarySystem - a container for planetary system info.
PlanetarySystem:castIntersections - from a position in a given direction.
PlanetarySystem:closestBody - to the specified coordinates.
PlanetarySystem:convertToBodyIdAndWorldCoordinates - from map coordinates.
PlanetarySystem:getBodyParameters - from reference table.
PlanetarySystem:getPlanetarySystemId - for the instance.
BodyParameters:convertToWorldCoordinates - from map coordinates
BodyParameters:convertToMapPosition - from world coordinates
BodyParameters:getAltitude - of world coordinates
BodyParameters:getDistance - from center to world coordinates
BodyParameters:getGravity - at a given position in world coordinates.
Description
An instance of the 'PlanetaryReference' "class" can contain transform and
kinematic reference information for all planetary systems in DualUniverse.
Each planetary system is identified by a numeric identifier. Currently,
the only planetary system, Helios, has the identifier: zero. This "class"
supports the indexing ('[]') operation which is equivalent to the
use of the 'getPlanetarySystem' method. It also supports the 'pairs()'
method for iterating over planetary systems.
An instance of the 'PlanetarySystem' "class" contains all reference
information for a specific system. It supports the indexing ('[]') and
'pairs()' functions which allows iteration over each "body" in the
system where the key is the numeric body ID. It also supports the
'tostring()' method.
An instance of the 'BodyParameters' "class" contains all reference
information for a single celestial "body" (a moon or planet). It supports
the 'tostring()' method, and contains the data members:
planetarySystemId - numeric planetary system ID
bodyId - numeric body ID
radius - radius of the body in meters (zero altitude)
center - world coordinates of the body's center position
GM - the gravitation parameter (g = GM/radius^2)
Note that the user is allowed to add custom fields (e.g. body name), but
should insure that complex table values have the '__tostring' metamethod
implemented.
Transform and Kinematics:
"World" coordinates is a cartesian coordinate system with an origin at an
arbitrary fixed point in a planetary system and with distances measured in
meters. The coordinates are expressible either as a simple table of 3 values
or an instance of the 'vec3' class. In either case, the planetary system
identity is implicit.
"Map" coordinates is a geographic coordinate system with an origin at the
center of an identified (by a numeric value) celestial body which is a
member of an identified (also a numeric value) planetary system. Note that
the convention that latitude, longitude, and altitude values will be the
position's x, y, and z world coordinates in the special case of body ID 0.
The kinematic parameters in the reference data permit calculations of the
gravitational attraction of the celestial body on other objects.
Reference Data:
This is an example of reference data with a single entry assigned to
planetary system ID 0, and body ID 2 ('Alioth'):
referenceTable = {
[0] = { [2] = { planetarySystemId = 0,
bodyId = 2,
radius = 126068,
center = vec3({x=-8, y=-8, z=-126303}),
GM = 1.572199+11 } -- as in F=-GMm/r^2
}
}
ref=PlanetaryReference(referenceTable)
Collecting Reference Data:
A combination of information from the "Map" screen in the DU user interface,
and values reported by the DU Lua API can be the source of the reference
table's data (planetarySystemId, bodyId, and surfaceArea is from the user
interface):
referenceTable = {}
referenceTable[planetarySystemId][bodyId] =
PlanetaryReference.createBodyParameters(planetarySystemId,
bodyId,
surfaceArea,
core.getConstructWorldPos(),
core.getWorldVertical(),
core.getAltitude(),
core.g())
Adapting Data Sources:
Other sources of data can be adapted or converted. An example of adapting a
table, defined in the file: 'planets.lua', containing information on a single
planetary system and using celestial body name as the key follows (note that
a 'name' field is added to the BodyParameters instance transparently after
construction, and the '__pairs' meta function is required to support the
'closestBody' and '__tostring' methods):
ref=PlanetaryReference(
{[0] = setmetatable(require('planets'),
{ __index = function(bodies, bodyId)
for _,v in pairs(bodies) do
if v and v.bodyId == bodyId then return v end
end
return nil
end,
__pairs = function(bodies)