-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathButtonHUD.conf
445 lines (431 loc) · 185 KB
/
ButtonHUD.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
name: ButtonsHud - Dimencia and Archaegeo v5.453 (Minified)
slots:
core:
class: CoreUnit
radar:
class: RadarPVPUnit
select: manual
antigrav:
class: AntiGravityGeneratorUnit
warpdrive:
class: WarpDriveUnit
gyro:
class: GyroUnit
weapon:
class: WeaponUnit
select: manual
dbHud:
class: databank
select: manual
telemeter:
class: TelemeterUnit
select: manual
vBooster:
class: VerticalBooster
hover:
class: Hovercraft
door:
class: DoorUnit
select: manual
switch:
class: ManualSwitchUnit
select: manual
forcefield:
class: ForceFieldUnit
select: manual
atmofueltank:
class: AtmoFuelContainer
select: manual
spacefueltank:
class: SpaceFuelContainer
select: manual
rocketfueltank:
class: RocketFuelContainer
select: manual
handlers:
unit:
start:
lua: |
-- error handling code added by wrap.lua
__wrap_lua__stopped = false
__wrap_lua__stopOnError = false
__wrap_lua__rethrowErrorAlways = false
__wrap_lua__rethrowErrorIfStopped = true
__wrap_lua__printError = true
__wrap_lua__showErrorOnScreens = true
function __wrap_lua__error (message)
if __wrap_lua__stopped then return end
-- make the traceback more readable and escape HTML syntax characters
message = tostring(message):gsub('"%-%- |STDERROR%-EVENTHANDLER[^"]*"', 'chunk'):gsub("&", "&"):gsub("<", "<"):gsub(">", ">")
local unit = unit or self or {}
if __wrap_lua__showErrorOnScreens then
for _, value in pairs(unit) do
if type(value) == "table" and value.setCenteredText and value.setHTML then -- value is a screen
if message:match("\n") then
value.setHTML([[
<pre style="color: white; background-color: black; font-family: Consolas,monospace; font-size: 4vh; white-space: pre-wrap; margin: 1em">
Error: ]] .. message .. [[
</pre>]])
else
value.setCenteredText(message)
end
end
end
end
if __wrap_lua__printError and system and system.print then
system.print("Error: " .. message:gsub("\n", "<br>"))
end
if __wrap_lua__stopOnError then
__wrap_lua__stopped = true
end
if __wrap_lua__stopped and unit and unit.exit then
unit.exit()
end
if __wrap_lua__rethrowErrorAlways or (__wrap_lua__stopped and __wrap_lua__rethrowErrorIfStopped) then
error(message)
end
end
-- in case traceback is removed or renamed
__wrap_lua__traceback = traceback or (debug and debug.traceback) or function (arg1, arg2) return arg2 or arg1 end
local ok, message = xpcall(function ()
-- script code
useTheseSettings = false --export: (Default: false) Toggle on to use the below preferences. Toggle off to use saved preferences. Preferences will save regardless when exiting seat.
freeLookToggle = true --export: (Default: true)
BrakeToggleDefault = true --export: (Default: true)
RemoteFreeze = false --export: (Default: false)
RemoteHud = false --export: (Default: false)
brightHud = false --export: (Default: false)
VanillaRockets = false --export: (Default: false)
InvertMouse = false --export: (Default: false)
userControlScheme = "virtual joystick" --export: (Default: "virtual joystick") Set to "virtual joystick", "mouse", or "keyboard"
ResolutionX = 1920 --export: (Default: 1920)
ResolutionY = 1080 --export: (Default: 1080)
SafeR = 130 --export: (Default: 130)
SafeG = 224 --export: (Default: 224)
SafeB = 255 --export: (Default: 255)
PvPR = 255 --export: (Default: 255)
PvPG = 0 --export: (Default: 0)
PvPB = 0 --export: (Default: 0)
centerX = 960 --export: (Default: 960)
centerY = 540 --export: (Default: 540)
throtPosX = 1300 --export: (Default: 1300)
throtPosY = 540 --export: (Default: 540)
vSpdMeterX = 1525 --export: (Default: 1525)
vSpdMeterY = 325 --export: (Default: 325)
altMeterX = 550 --export: (Default: 550)
altMeterY = 540 --export: (Default: 540)
fuelX = 100 --export: (Default: 100)
fuelY = 350 --export: (Default: 350)
circleRad = 400 --export: (Default: 400)
DeadZone = 50 --export: (Default: 50)
DisplayOrbit = true --export: (Default: true)
OrbitMapSize = 250 --export: (Default: 250)
OrbitMapX = 75 --export: (Default: 75)
OrbitMapY = 0 --export: (Default: 0)
showHud = true --export: (Default: true)
ShowOdometer = true --export: (Default: true)
hideHudOnToggleWidgets = true --export: (Default: true)
ShiftShowsRemoteButtons = true --export: (Default: true)
YawStallAngle = 35 --export: (Default: 35)
PitchStallAngle = 35 --export: (Default: 35)
speedChangeLarge = 5 --export: (Default: 5)
speedChangeSmall = 1 --export: (Default: 1)
brakeLandingRate = 30 --export: (Default: 30)
MaxPitch = 30 --export: (Default: 30)
ReentrySpeed = 1050 --export: (Default: 1050)
AtmoSpeedLimit = 1050 --export: (Default: 1050)
SpaceSpeedLimit = 30000 --export: (Default: 30000).
ReentryAltitude = 2500 --export: (Default: 2500)
AutoTakeoffAltitude = 1000 --export: (Default: 1000)
TargetHoverHeight = 50 --export: (Default: 50)
LandingGearGroundHeight = 0 --export: (Default: 0)
MaxGameVelocity = 8333.00 --export: (Default: 8333.00)
TargetOrbitRadius = 1.4 --export: (Default: 1.4)
AutopilotInterplanetaryThrottle = 1.0 --export: (Default: 1.0)
warmup = 32 --export: (Default: 32)
MouseYSensitivity = 0.003 --export: (Default: 0.003)
MouseXSensitivity = 0.003 --export: (Default: 0.003)
autoRollPreference = false --export: (Default: false)
autoRollFactor = 2 --export: (Default: 2)
rollSpeedFactor = 1.5 --export: (Default: 1.5)
turnAssist = true --export: (Default: true)
turnAssistFactor = 2 --export: (Default: 2)
TrajectoryAlignmentStrength = 0.002 --export: (Default: 0.002)
torqueFactor = 2 --export: (Default: 2)
pitchSpeedFactor = 0.8 --export: (Default: 0.8)
yawSpeedFactor = 1 --export: (Default: 1)
brakeSpeedFactor = 3 --export: (Default: 3)
brakeFlatFactor = 1 --export: (Default: 1)
DampingMultiplier = 40 --export: (Default: 40)
fuelTankHandlingAtmo = 0 --export: (Default: 0)
fuelTankHandlingSpace = 0 --export: (Default: 0)
fuelTankHandlingRocket = 0 --export: (Default: 0)
ContainerOptimization = 0 --export: (Default: 0)
FuelTankOptimization = 0 --export: (Default: 0)
ExtraLongitudeTags = "none" --export: (Default: "none")
ExtraLateralTags = "none" --export: (Default: "none")
ExtraVerticalTags = "none" --export: (Default: "none")
ExternalAGG = false --export: (Default: false)
UseSatNav = false --export: (Default: false)
apTickRate = 0.0166667 --export: (Default: 0.0166667)
hudTickRate = 0.0666667 --export: (Default: 0.0666667)
ShouldCheckDamage = true --export: (Default: true)
CalculateBrakeLandingSpeed = false --export: (Default: false)
autoRollRollThreshold = 0 --export: (Default: 0)
AtmoSpeedAssist = true --export: (Default: true)
ForceAlignment = false --export: (Default: false)
minRollVelocity = 150 --export: (Default: 150)
VertTakeOffEngine = false --export: (Default: false)
DisplayDeadZone = true --export: (Default: true)
OrbitDefaultAltitude = 2000 --export: (Default: 2000)
Nav=Navigator.new(system,core,unit)script={}BrakeToggleStatus=BrakeToggleDefault;BrakeIsOn=false;RetrogradeIsOn=false;ProgradeIsOn=false;Autopilot=false;TurnBurn=false;AltitudeHold=false;BrakeLanding=false;AutoTakeoff=false;Reentry=false;VertTakeOff=false;HoldAltitude=1000;AutopilotAccelerating=false;AutopilotRealigned=false;AutopilotBraking=false;AutopilotCruising=false;AutopilotEndSpeed=0;AutopilotStatus="Aligning"AutopilotPlanetGravity=0;PrevViewLock=1;AutopilotTargetName="None"AutopilotTargetCoords=nil;AutopilotTargetIndex=0;GearExtended=nil;TotalDistanceTravelled=0.0;TotalFlightTime=0;SavedLocations={}VectorToTarget=false;LocationIndex=0;LastMaxBrake=0;LockPitch=nil;LastMaxBrakeInAtmo=0;AntigravTargetAltitude=core.getAltitude()LastStartTime=0;SpaceTarget=false;LeftAmount=0;IntoOrbit=false;local a={"userControlScheme","TargetOrbitRadius","apTickRate","freeLookToggle","turnAssist","SafeR","SafeG","SafeB","warmup","DeadZone","circleRad","MouseXSensitivity","MouseYSensitivity","MaxGameVelocity","showHud","autoRollPreference","InvertMouse","pitchSpeedFactor","yawSpeedFactor","rollSpeedFactor","brakeSpeedFactor","brakeFlatFactor","autoRollFactor","turnAssistFactor","torqueFactor","AutoTakeoffAltitude","TargetHoverHeight","AutopilotInterplanetaryThrottle","hideHudOnToggleWidgets","DampingMultiplier","fuelTankHandlingAtmo","ExternalAGG","ShouldCheckDamage","fuelTankHandlingSpace","fuelTankHandlingRocket","RemoteFreeze","hudTickRate","speedChangeLarge","speedChangeSmall","brightHud","brakeLandingRate","MaxPitch","ReentrySpeed","AtmoSpeedLimit","ReentryAltitude","centerX","centerY","SpaceSpeedLimit","AtmoSpeedAssist","vSpdMeterX","vSpdMeterY","altMeterX","altMeterY","fuelX","fuelY","LandingGearGroundHeight","TrajectoryAlignmentStrength","RemoteHud","YawStallAngle","PitchStallAngle","ResolutionX","ResolutionY","UseSatNav","FuelTankOptimization","ContainerOptimization","ExtraLongitudeTags","ExtraLateralTags","ExtraVerticalTags","OrbitMapSize","OrbitMapX","OrbitMapY","DisplayOrbit","CalculateBrakeLandingSpeed","ForceAlignment","autoRollRollThreshold","minRollVelocity","VertTakeOffEngine","PvPR","PvPG","PvPB","DisplayDeadZone"}local b={"SpaceTarget","BrakeToggleStatus","BrakeIsOn","RetrogradeIsOn","ProgradeIsOn","Autopilot","TurnBurn","AltitudeHold","BrakeLanding","Reentry","AutoTakeoff","HoldAltitude","AutopilotAccelerating","AutopilotBraking","AutopilotCruising","AutopilotRealigned","AutopilotEndSpeed","AutopilotStatus","AutopilotPlanetGravity","PrevViewLock","AutopilotTargetName","AutopilotTargetCoords","AutopilotTargetIndex","TotalDistanceTravelled","TotalFlightTime","SavedLocations","VectorToTarget","LocationIndex","LastMaxBrake","LockPitch","LastMaxBrakeInAtmo","AntigravTargetAltitude","LastStartTime"}local c=system.print;local d=math.floor;local e=string.format;local f=json.decode;local g=json.encode;local h=core.getElementMaxHitPointsById;local j=unit.getAtmosphereDensity;local k=core.getElementHitPointsById;local l=core.getElementTypeById;local m=core.getElementMassById;local n=core.getConstructMass;local o=Nav.control.isRemoteControlled;local p=math.atan;function round(q,r)local s=10^(r or 0)return d(q*s+0.5)/s end;local t=SafeR;local u=SafeB;local v=SafeG;local w=false;local x=0;local y=""local z=0;local A=0;local B=false;local C=0;local D=false;local E=round(ResolutionX/2,0)local F=round(ResolutionY/2,0)local G=false;local H=true;local I=55;local J=false;local K=1;local L=1;local M=false;local N=0;local O=0;local P=0;local Q=0;local R=0;local S=0;local T=0;local U=false;local V=false;local W="empty"local X=5;local Y=5;local Z=X;local a0=Y;local a1=false;local a2,a3=0;local a4,a5=0;local a6=nil;local a7=0;local a8=0;local a9=false;local aa=0;local ab=0;local ac=0;local ad=3;local ae=0;local af=""local ag=""local ah=0;local ai=false;local aj=false;local ak=false;local al=-1;local am=false;local an=""local ao=j()>0;local ap=core.getAltitude()local aq=core.getElementIdList()local ar=system.getTime()local as=nil;local at=false;local au=[[rgb(]]..d(t+0.5)..","..d(v+0.5)..","..d(u+0.5)..[[)]]local av=[[rgb(]]..d(t*0.9+0.5)..","..d(v*0.9+0.5)..","..d(u*0.9+0.5)..[[)]]local aw={}local ax=0;local ay=0;local az=""local aA=true;local aB={}local aC=1;local aD=0.001;local aE=ResolutionX;local aF=ResolutionY;local aG=nil;local aH=nil;local aI=nil;local aJ=nil;local aK=false;local aL=false;local aM=0;local aN=nil;local aO={}local aP={}local aQ={}local aR=0;local aS=false;local aT={}local aU={}local aV=d(1/apTickRate)*2;local aW={}local aX={}local aY={}local aZ={}local a_=false;local b0=16;local b1=0;local b2=nil;local b3=""local b4=nil;local b5=nil;local b6=nil;local b7=nil;local b8=nil;local b9=nil;local ba=nil;local bb=nil;local bc=false;local bd=false;local be=autoRollPreference;local bf=vec3(core.getWorldVelocity())local bg=vec3(bf):len()local bh=LandingGearGroundHeight;local bi=system.getMouseDeltaX()local bj=system.getMouseDeltaY()local bk=false;local bl=system.getTime()local bm=0;local bn=0;local bo=0;local bp=AtmoSpeedLimit;local bq=0;local br=nil;local bs=0;local bt=0;local bu=false;local bv=false;local bw={VectorToTarget,AutopilotAlign}local bx=false;local by=0;local bz=nil;local bA=false;local bB=false;local bC=false;local bD=false;local bE=0;function LoadVariables()if dbHud_1 then local bF=dbHud_1.hasKey;if not useTheseSettings then for bG,bH in pairs(a)do if bF(bH)then local bI=f(dbHud_1.getStringValue(bH))if bI~=nil then c(bH.." "..dbHud_1.getStringValue(bH))_G[bH]=bI;aK=true end end end end;coroutine.yield()for bG,bH in pairs(b)do if bF(bH)then local bI=f(dbHud_1.getStringValue(bH))if bI~=nil then c(bH.." "..dbHud_1.getStringValue(bH))_G[bH]=bI;aK=true end end end;if useTheseSettings then W="Updated user preferences used. Will be saved when you exit seat.\nToggle off useTheseSettings to use saved values"ad=5 elseif aK then W="Loaded Saved Variables (see Lua Chat Tab for list)"else W="No Saved Variables Found - Stand up / leave remote to save settings"end else W="No databank found, install one anywhere and rerun the autoconfigure to save variables"end;local bJ=system.getTime()if LastStartTime+180<bJ then LastMaxBrakeInAtmo=0 end;if aK then E=round(ResolutionX/2,0)F=round(ResolutionY/2,0)aE=ResolutionX;aF=ResolutionY;BrakeToggleStatus=BrakeToggleDefault;userControlScheme=string.lower(userControlScheme)be=autoRollPreference end;LastStartTime=bJ;if string.find("keyboard virtual joystick mouse",userControlScheme)==nil then W="Invalid User Control Scheme selected. Change userControlScheme in Lua Parameters to keyboard, mouse, or virtual joystick\nOr use shift and button in screen"ad=5 end;if antigrav and not ExternalAGG then if AntigravTargetAltitude==nil then AntigravTargetAltitude=ap end;antigrav.setBaseAltitude(AntigravTargetAltitude)end;au=[[rgb(]]..d(t+0.5)..","..d(v+0.5)..","..d(u+0.5)..[[)]]av=[[rgb(]]..d(t*0.9+0.5)..","..d(v*0.9+0.5)..","..d(u*0.9+0.5)..[[)]]bp=AtmoSpeedLimit end;function CalculateFuelVolume(bK,bL)if bK>bL then bL=bK end;if ContainerOptimization>0 then bL=bL-bL*ContainerOptimization*0.05 end;if FuelTankOptimization>0 then bL=bL-bL*FuelTankOptimization*0.05 end;return bL end;function ProcessElements()local bM=fuelX~=0 and fuelY~=0;for bG in pairs(aq)do local type=l(aq[bG])if string.match(type,'^.*Space Engine$')then bD=true;if string.match(tostring(core.getElementTagsById(aq[bG])),'^.*vertical.*$')then local bN=core.getElementRotationById(aq[bG])if bN[4]<0 then if utils.round(-bN[4],0.1)==0.5 then bB=true;system.print("Space Engine Up detected")end else if utils.round(bN[4],0.1)==0.5 then bC=true;system.print("Space Engine Down detected")end end end end;if type=="Landing Gear"then M=true end;if type=="Dynamic Core Unit"then local bO=h(aq[bG])if bO>10000 then b0=128 elseif bO>1000 then b0=64 elseif bO>150 then b0=32 end end;aR=aR+h(aq[bG])if bM and(type=="Atmospheric Fuel Tank"or type=="Space Fuel Tank"or type=="Rocket Fuel Tank")then local bO=h(aq[bG])local bP=m(aq[bG])local bK=0;local bQ=system.getTime()if type=="Atmospheric Fuel Tank"then local bL=400;local bR=35.03;if bO>10000 then bL=51200;bR=5480 elseif bO>1300 then bL=6400;bR=988.67 elseif bO>150 then bL=1600;bR=182.67 end;bK=bP-bR;if fuelTankHandlingAtmo>0 then bL=bL+bL*fuelTankHandlingAtmo*0.2 end;bL=CalculateFuelVolume(bK,bL)aO[#aO+1]={aq[bG],core.getElementNameById(aq[bG]),bL,bR,bK,bQ}end;if type=="Rocket Fuel Tank"then local bL=320;local bR=173.42;if bO>65000 then bL=40000;bR=25740 elseif bO>6000 then bL=5120;bR=4720 elseif bO>700 then bL=640;bR=886.72 end;bK=bP-bR;if fuelTankHandlingRocket>0 then bL=bL+bL*fuelTankHandlingRocket*0.1 end;bL=CalculateFuelVolume(bK,bL)aQ[#aQ+1]={aq[bG],core.getElementNameById(aq[bG]),bL,bR,bK,bQ}end;if type=="Space Fuel Tank"then local bL=2400;local bR=182.67;if bO>10000 then bL=76800;bR=5480 elseif bO>1300 then bL=9600;bR=988.67 end;bK=bP-bR;if fuelTankHandlingSpace>0 then bL=bL+bL*fuelTankHandlingSpace*0.2 end;bL=CalculateFuelVolume(bK,bL)aP[#aP+1]={aq[bG],core.getElementNameById(aq[bG]),bL,bR,bK,bQ}end end end end;function SetupChecks()if gyro~=nil then as=gyro.getState()==1 end;if userControlScheme~="keyboard"then system.lockView(1)else system.lockView(0)end;local bS=j()if door and(bS>0 or bS==0 and ap<10000)then for _,bH in pairs(door)do bH.toggle()end end;if switch then for _,bH in pairs(switch)do bH.toggle()end end;if forcefield and(bS>0 or bS==0 and ap<10000)then for _,bH in pairs(forcefield)do bH.toggle()end end;if antigrav~=nil and not ExternalAGG then if antigrav.getState()==1 then antigrav.show()end end;if o()==1 and RemoteFreeze then system.freeze(1)else system.freeze(0)end;if M then GearExtended=Nav.control.isAnyLandingGearExtended()==1;if GearExtended then Nav.control.extendLandingGears()else Nav.control.retractLandingGears()end end;local bT=AboveGroundLevel()if bT~=-1 or not ao and vec3(core.getVelocity()):len()<50 then BrakeIsOn=true;if not M then GearExtended=true end else BrakeIsOn=false end;if bh~=nil then Nav.axisCommandManager:setTargetGroundAltitude(bh)if bh==0 and not M then GearExtended=true;BrakeIsOn=true end else bh=Nav:getTargetGroundAltitude()if GearExtended then Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)else Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end end;if ao and bT~=-1 then ba=core.getMaxKinematicsParametersAlongAxis("ground",core.getConstructOrientationUp())[1]end;userControlScheme=string.lower(userControlScheme)WasInAtmo=ao end;function ConvertResolutionX(bH)if ResolutionX==1920 then return bH else return round(ResolutionX*bH/1920,0)end end;function ConvertResolutionY(bH)if ResolutionY==1080 then return bH else return round(ResolutionY*bH/1080,0)end end;function RefreshLastMaxBrake(bU,bV)if bU==nil then bU=core.g()end;bU=round(bU,5)local bW=j()if bV~=nil and bV or(aN==nil or aN~=bU)then local bf=core.getVelocity()local bX=vec3(bf):len()local bY=f(unit.getData()).maxBrake;if bY~=nil and bY>0 and ao then bY=bY/utils.clamp(bX/100,0.1,1)bY=bY/bW;if bW>0.10 then if LastMaxBrakeInAtmo then LastMaxBrakeInAtmo=(LastMaxBrakeInAtmo+bY)/2 else LastMaxBrakeInAtmo=bY end end end;if bY~=nil and bY>0 then LastMaxBrake=bY end;aN=bU end end;function MakeButton(bZ,b_,c0,c1,c2,c3,c4,c5,c6)local c7={enableName=bZ,disableName=b_,width=c0,height=c1,x=c2,y=c3,toggleVar=c4,toggleFunction=c5,drawCondition=c6,hovered=false}table.insert(aB,c7)return c7 end;function UpdateAtlasLocationsList()AtlasOrdered={}for bG,bH in pairs(b2[0])do table.insert(AtlasOrdered,{name=bH.name,index=bG})end;local function c8(c9,ca)return c9.name<ca.name end;table.sort(AtlasOrdered,c8)end;function AddLocationsToAtlas()for bG,bH in pairs(SavedLocations)do table.insert(b2[0],bH)end;UpdateAtlasLocationsList()end;function float_eq(cb,cc)if cb==0 then return math.abs(cc)<1e-09 end;if cc==0 then return math.abs(cb)<1e-09 end;return math.abs(cb-cc)<math.max(math.abs(cb),math.abs(cc))*epsilon end;function zeroConvertToMapPosition(cd,ce)local cf=vec3(ce)if cd.bodyId==0 then return setmetatable({latitude=cf.x,longitude=cf.y,altitude=cf.z,bodyId=0,systemId=cd.planetarySystemId},MapPosition)end;local cg=cf-cd.center;local ae=cg:len()local ch=ae-cd.radius;local ci=0;local cj=0;if not float_eq(ae,0)then local ck=math.atan(cg.y,cg.x)cj=ck>=0 and ck or 2*math.pi+ck;ci=math.pi/2-math.acos(cg.z/ae)end;return setmetatable({latitude=math.deg(ci),longitude=math.deg(cj),altitude=ch,bodyId=cd.bodyId,systemId=cd.planetarySystemId},MapPosition)end;function zeroConvertToWorldCoordinates(cl)local q=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local cm='::pos{'..q..','..q..','..q..','..q..','..q..'}'local cn,co,ci,cj,ch=string.match(cl,cm)if cn=="0"and co=="0"then return vec3(tonumber(ci),tonumber(cj),tonumber(ch))end;cj=math.rad(cj)ci=math.rad(ci)local planet=b2[tonumber(cn)][tonumber(co)]local cp=math.cos(ci)local cq=vec3(cp*math.cos(cj),cp*math.sin(cj),math.sin(ci))return planet.center+(planet.radius+ch)*cq end;function AddNewLocationByWaypoint(cr,planet,cl)if dbHud_1 then local cs={}local position=zeroConvertToWorldCoordinates(cl)if planet.name=="Space"then cs={position=position,name=cr,atmosphere=false,planetname=planet.name,gravity=planet.gravity}else local bS=false;if planet.hasAtmosphere then bS=true else bS=false end;cs={position=position,name=cr,atmosphere=bS,planetname=planet.name,gravity=planet.gravity}end;SavedLocations[#SavedLocations+1]=cs;table.insert(b2[0],cs)UpdateAtlasLocationsList()else W="Databank must be installed to save locations"end end;function AddNewLocation()if dbHud_1 then local position=vec3(core.getConstructWorldPos())local ct=planet.name..". "..#SavedLocations;if radar_1 then local cu,_=radar_1.getData():match('"constructId":"([0-9]*)","distance":([%d%.]*)')if cu~=nil and cu~=""then ct=ct.." "..radar_1.getConstructName(cu)end end;local cs={}local bS=false;if planet.hasAtmosphere then bS=true end;cs={position=position,name=ct,atmosphere=bS,planetname=planet.name,gravity=planet.gravity,safe=true}SavedLocations[#SavedLocations+1]=cs;table.insert(b2[0],cs)UpdateAtlasLocationsList()W="Location saved as "..ct else W="Databank must be installed to save locations"end end;function UpdatePosition(cv)local cw=-1;local cs;for bG,bH in pairs(SavedLocations)do if bH.name and bH.name==CustomTarget.name then cw=bG;break end end;if cw~=-1 then local cx;if cv~=nil then cs={position=SavedLocations[cw].position,name=cv,atmosphere=SavedLocations[cw].atmosphere,planetname=SavedLocations[cw].planetname,gravity=SavedLocations[cw].gravity}else cs={position=vec3(core.getConstructWorldPos()),name=SavedLocations[cw].name,atmosphere=j(),planetname=planet.name,gravity=unit.getClosestPlanetInfluence(),safe=true}end;SavedLocations[cw]=cs;cw=-1;for bG,bH in pairs(b2[0])do if bH.name and bH.name==CustomTarget.name then cw=bG end end;if cw>-1 then b2[0][cw]=cs end;UpdateAtlasLocationsList()W=CustomTarget.name.." position updated"AutopilotTargetIndex=0;UpdateAutopilotTarget()else W="Name Not Found"end end;function ClearCurrentPosition()local cw=-1;for bG,bH in pairs(b2[0])do if bH.name and bH.name==CustomTarget.name then cw=bG end end;if cw>-1 then table.remove(b2[0],cw)end;cw=-1;for bG,bH in pairs(SavedLocations)do if bH.name and bH.name==CustomTarget.name then W=bH.name.." saved location cleared"cw=bG;break end end;if cw~=-1 then table.remove(SavedLocations,cw)end;DecrementAutopilotTargetIndex()UpdateAtlasLocationsList()end;function DrawDeadZone(cy)cy[#cy+1]=e([[<circle class="dim line" style="fill:none" cx="50%%" cy="50%%" r="%d"/>]],DeadZone)end;function ToggleRadarPanel()if radarPanelID~=nil and ah==0 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;if perisPanelID~=nil then system.destroyWidgetPanel(perisPanelID)perisPanelID=nil end else if ah==1 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;_autoconf.displayCategoryPanel(radar,radar_size,L_TEXT("ui_lua_widget_periscope", "Periscope"),"periscope")perisPanelID=_autoconf.panels[_autoconf.panels_size]end;placeRadar=true;if radarPanelID==nil and placeRadar then _autoconf.displayCategoryPanel(radar,radar_size,L_TEXT("ui_lua_widget_radar", "Radar"),"radar")radarPanelID=_autoconf.panels[_autoconf.panels_size]placeRadar=false end;ah=0 end end;function ToggleWidgets()if aA then unit.show()core.show()if atmofueltank_size>0 then _autoconf.displayCategoryPanel(atmofueltank,atmofueltank_size,L_TEXT("ui_lua_widget_atmofuel", "Atmo Fuel"),"fuel_container")fuelPanelID=_autoconf.panels[_autoconf.panels_size]end;if spacefueltank_size>0 then _autoconf.displayCategoryPanel(spacefueltank,spacefueltank_size,L_TEXT("ui_lua_widget_spacefuel", "Space Fuel"),"fuel_container")spacefuelPanelID=_autoconf.panels[_autoconf.panels_size]end;if rocketfueltank_size>0 then _autoconf.displayCategoryPanel(rocketfueltank,rocketfueltank_size,L_TEXT("ui_lua_widget_rocketfuel", "Rocket Fuel"),"fuel_container")rocketfuelPanelID=_autoconf.panels[_autoconf.panels_size]end;aA=false else unit.hide()core.hide()if fuelPanelID~=nil then system.destroyWidgetPanel(fuelPanelID)fuelPanelID=nil end;if spacefuelPanelID~=nil then system.destroyWidgetPanel(spacefuelPanelID)spacefuelPanelID=nil end;if rocketfuelPanelID~=nil then system.destroyWidgetPanel(rocketfuelPanelID)rocketfuelPanelID=nil end;aA=true end end;function SetupInterplanetaryPanel()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)widgetMaxMass=system.createWidget(panelInterplanetary,"value")widgetMaxMassText=system.createData('{"label": "Maximum Mass", "value": "N/A", "unit":""}')system.addDataToWidget(widgetMaxMassText,widgetMaxMass)widgetCurBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetCurBrakeDistanceText=system.createData('{"label": "Cur Brake distance", "value": "N/A", "unit":""}')if not ao then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;widgetCurBrakeTime=system.createWidget(panelInterplanetary,"value")widgetCurBrakeTimeText=system.createData('{"label": "Cur Brake Time", "value": "N/A", "unit":""}')if not ao then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;widgetMaxBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeDistanceText=system.createData('{"label": "Max Brake distance", "value": "N/A", "unit":""}')if not ao then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;widgetMaxBrakeTime=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeTimeText=system.createData('{"label": "Max Brake Time", "value": "N/A", "unit":""}')if not ao then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;widgetTrajectoryAltitude=system.createWidget(panelInterplanetary,"value")widgetTrajectoryAltitudeText=system.createData('{"label": "Projected Altitude", "value": "N/A", "unit":""}')if not ao then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end;widgetTargetOrbit=system.createWidget(panelInterplanetary,"value")widgetTargetOrbitText=system.createData('{"label": "Target Altitude", "value": "N/A", "unit":""}')system.addDataToWidget(widgetTargetOrbitText,widgetTargetOrbit)end;function Contains(cz,cA,c2,c3,c0,c1)if cz>c2 and cz<c2+c0 and cA>c3 and cA<c3+c1 then return true else return false end end;function ToggleTurnBurn()TurnBurn=not TurnBurn end;function ToggleVectorToTarget(SpaceTarget)VectorToTarget=not VectorToTarget;if VectorToTarget then TurnBurn=false;if not AltitudeHold and not SpaceTarget then ToggleAltitudeHold()end end;VectorStatus="Proceeding to Waypoint"end;function ToggleAutoLanding()if BrakeLanding then BrakeLanding=false else StrongBrakes=planet.gravity*9.80665*n()<LastMaxBrake;AltitudeHold=false;AutoTakeoff=false;LockPitch=nil;BrakeLanding=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)z=0 end end;function ToggleAutoTakeoff()if AutoTakeoff then AutoTakeoff=false;if AltitudeHold then ToggleAltitudeHold()end elseif VertTakeOff then BrakeLanding=true;VertTakeOff=false;AltitudeHold=false else if VertTakeOffEngine then VertTakeOff=true;AltitudeHold=false else if not AltitudeHold then ToggleAltitudeHold()end;AutoTakeoff=true;HoldAltitude=ap+AutoTakeoffAltitude end;bA=false;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end end;function ToggleIntoOrbit()if j()==0 then if IntoOrbit then bA=false;IntoOrbit=false;bu=false;bs=nil;bt=nil;bz=nil;bE=0;be=autoRollPreference;if AltitudeHold then AltitudeHold=false;AutoTakeoff=false end;bw.VectorToTarget=false;bw.AutopilotAlign=false;bx=false elseif unit.getClosestPlanetInfluence()>0 then IntoOrbit=true;be=true;bA=false;bs=nil;bt=nil;bE=0;if bz==nil then bz=planet end;if AltitudeHold then AltitudeHold=false;AutoTakeoff=false end else W="Unable to engage orbiting, not near planet"end else bA=false;IntoOrbit=false;bu=false;bs=nil;bt=nil;bz=nil;bE=0;be=autoRollPreference;if AltitudeHold then ToggleAltitudeHold()end;bw.VectorToTarget=false;bw.AutopilotAlign=false;bx=false end end;function ToggleLockPitch()if LockPitch==nil then local cB=vec3(core.getConstructWorldOrientationForward())local cC=vec3(core.getConstructWorldOrientationRight())local cD=vec3(core.getWorldVertical())local cE=getPitch(cD,cB,cC)LockPitch=cE;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=false else LockPitch=nil end end;function ToggleAltitudeHold()local bJ=system.getTime()if bJ-bn<1.5 then local cF=false;if planet.hasAtmosphere and(j()>0 and HoldAltitude==planet.spaceEngineMinAltitude-50)then cF=true;if IntoOrbit then ToggleIntoOrbit()end;bn=0;return end;if planet.hasAtmosphere and not cF then if j()>0 then HoldAltitude=planet.spaceEngineMinAltitude-50 else if unit.getClosestPlanetInfluence()>0 then HoldAltitude=planet.noAtmosphericDensityAltitude+OrbitDefaultAltitude;by=HoldAltitude;bx=true;if not IntoOrbit then ToggleIntoOrbit()end;bu=true end end;bn=-1;if AltitudeHold or IntoOrbit then return end end else bn=bJ end;if unit.getClosestPlanetInfluence()>0 and j()==0 then by=ap;bx=true;bu=true;ToggleIntoOrbit()if IntoOrbit then bn=bJ else bn=0 end;return end;AltitudeHold=not AltitudeHold;if AltitudeHold then Autopilot=false;ProgradeIsOn=false;RetrogradeIsOn=false;U=false;BrakeLanding=false;Reentry=false;be=true;LockPitch=nil;bA=false;if hoverDetectGround()==-1 or not ao then AutoTakeoff=false;if not aj and Nav.axisCommandManager:getAxisCommandType(0)==0 and not AtmoSpeedAssist then Nav.control.cancelCurrentControlMasterMode()end;if bn>-1 then HoldAltitude=ap end else AutoTakeoff=true;if bn>-1 then HoldAltitude=ap+AutoTakeoffAltitude end;GearExtended=false;Nav.control.retractLandingGears()BrakeIsOn=true;Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end;if aj then HoldAltitude=100000 end;bn=bJ else be=autoRollPreference;AutoTakeoff=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;VectorToTarget=false;if IntoOrbit then ToggleIntoOrbit()end;bn=0 end end;function ToggleFollowMode()if o()==1 then U=not U;if U then Autopilot=false;RetrogradeIsOn=false;ProgradeIsOn=false;AltitudeHold=false;Reentry=false;BrakeLanding=false;AutoTakeoff=false;OldGearExtended=GearExtended;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)else BrakeIsOn=true;be=autoRollPreference;GearExtended=OldGearExtended;if GearExtended then Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end end else W="Follow Mode only works with Remote controller"U=false end end;function ToggleAutopilot()local bJ=system.getTime()if bJ-bo<1.5 and ao then if not bD then W="No space engines detected, Orbital Hop not supported"return end;if planet.hasAtmosphere then if j()>0 then HoldAltitude=planet.noAtmosphericDensityAltitude+OrbitDefaultAltitude end;bo=-1;if Autopilot or VectorToTarget then return end end else bo=bJ end;TargetSet=false;if AutopilotTargetIndex>0 and not Autopilot and not VectorToTarget and not aj then UpdateAutopilotTarget()local cG=zeroConvertToMapPosition(a6,AutopilotTargetCoords)cG="::pos{"..cG.systemId..","..cG.bodyId..","..cG.latitude..","..cG.longitude..","..cG.altitude.."}"system.setWaypoint(cG)if CustomTarget~=nil then LockPitch=nil;SpaceTarget=CustomTarget.planetname=="Space"if SpaceTarget then if j()~=0 then aj=true;ToggleAltitudeHold()else Autopilot=true end elseif planet.name==CustomTarget.planetname then StrongBrakes=true;if j()>0 then if bo==-1 then bn=0 end;if not VectorToTarget then ToggleVectorToTarget(SpaceTarget)end else if ap>100000 or ap==0 then bA=false;Autopilot=true elseif ap<=100000 then if IntoOrbit then ToggleIntoOrbit()end;by=planet.noAtmosphericDensityAltitude+OrbitDefaultAltitude;bx=true;bw.AutopilotAlign=true;bw.VectorToTarget=true;bu=false;if not IntoOrbit then ToggleIntoOrbit()end end end else RetrogradeIsOn=false;ProgradeIsOn=false;if j()~=0 then aj=true;ToggleAltitudeHold()else Autopilot=true end end elseif j()==0 then local cH=unit.getClosestPlanetInfluence()>0;if CustomTarget==nil and(a6.name==planet.name and cH)and not IntoOrbit then bA=false;bu=false;ToggleIntoOrbit()else Autopilot=true;RetrogradeIsOn=false;ProgradeIsOn=false;AutopilotRealigned=false;U=false;AltitudeHold=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;G=false;LockPitch=nil;WaypointSet=false end else aj=true;ToggleAltitudeHold()end else aj=false;Autopilot=false;AutopilotRealigned=false;VectorToTarget=false;G=false;AutoTakeoff=false;AltitudeHold=false;VectorToTarget=false;HoldAltitude=ap;TargetSet=false;Reentry=false;if IntoOrbit then ToggleIntoOrbit()end end;bo=bJ end;function ProgradeToggle()ProgradeIsOn=not ProgradeIsOn;RetrogradeIsOn=false;Autopilot=false;AltitudeHold=false;U=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function RetrogradeToggle()RetrogradeIsOn=not RetrogradeIsOn;ProgradeIsOn=false;Autopilot=false;AltitudeHold=false;U=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function BrakeToggle()BrakeIsOn=not BrakeIsOn;if BrakeLanding then BrakeLanding=false;be=autoRollPreference end;if BrakeIsOn then AltitudeHold=false;VectorToTarget=false;AutoTakeoff=false;VertTakeOff=false;Reentry=false;ProgradeIsOn=false;BrakeLanding=false;AutoLanding=false;AltitudeHold=false;if IntoOrbit then ToggleIntoOrbit()end;LockPitch=nil;be=autoRollPreference;ai=false;ak=false;aa=0 end end;function CheckDamage(cy)local cI=0;az=""local cJ=aR;local cK=0;local cL=0;local cM=0;local cN=0;local cO=""for bG in pairs(aq)do local bO=0;local cP=0;cP=h(aq[bG])bO=k(aq[bG])cK=cK+bO;if bO<cP then if bO==0 then cM=cM+1 else cL=cL+1 end;if aS and#aw==0 then position=vec3(core.getElementPositionById(aq[bG]))local c2=position.x-b0;local c3=position.y-b0;local cQ=position.z-b0;table.insert(aw,core.spawnArrowSticker(c2,c3,cQ+1,"down"))table.insert(aw,core.spawnArrowSticker(c2,c3,cQ+1,"down"))core.rotateSticker(aw[2],0,0,90)table.insert(aw,core.spawnArrowSticker(c2+1,c3,cQ,"north"))table.insert(aw,core.spawnArrowSticker(c2+1,c3,cQ,"north"))core.rotateSticker(aw[4],90,90,0)table.insert(aw,core.spawnArrowSticker(c2-1,c3,cQ,"south"))table.insert(aw,core.spawnArrowSticker(c2-1,c3,cQ,"south"))core.rotateSticker(aw[6],90,-90,0)table.insert(aw,core.spawnArrowSticker(c2,c3-1,cQ,"east"))table.insert(aw,core.spawnArrowSticker(c2,c3-1,cQ,"east"))core.rotateSticker(aw[8],90,0,90)table.insert(aw,core.spawnArrowSticker(c2,c3+1,cQ,"west"))table.insert(aw,core.spawnArrowSticker(c2,c3+1,cQ,"west"))core.rotateSticker(aw[10],-90,0,90)table.insert(aw,aq[bG])end elseif aS and#aw>0 and aw[11]==aq[bG]then for cR in pairs(aw)do core.deleteSticker(aw[cR])end;aw={}end end;cI=d(cK/cJ*100)if cI<100 then cy[#cy+1]=[[<g class="pbright txt">]]cN=d(cI*2.55)cO=e("rgb(%d,%d,%d)",255-cN,cN,0)if cI<100 then cy[#cy+1]=e([[<text class="txtbig txtmid" x=50%% y="1035" style="fill:%s">Elemental Integrity: %i %%</text>]],cO,cI)if cM>0 then cy[#cy+1]=e([[<text class="txtbig txtmid" x=50%% y="1055" style="fill:%s">Disabled Modules: %i Damaged Modules: %i</text>]],cO,cM,cL)elseif cL>0 then cy[#cy+1]=e([[<text class="txtbig txtmid" x=50%% y="1055"style="fill:%s">Damaged Modules: %i</text>]],cO,cL)end end;cy[#cy+1]=[[<\g>]]end end;function DrawCursorLine(cy)local cS=d(utils.clamp(ae/(aE/4)*255,0,255))cy[#cy+1]=e("<line x1='0' y1='0' x2='%fpx' y2='%fpx' style='stroke:rgb(%d,%d,%d);stroke-width:2;transform:translate(50%%, 50%%)' />",ab,ac,d(t+0.5)+cS,d(v+0.5)-cS,d(u+0.5)-cS)end;function getPitch(cT,cU,ca)local cV=cT:cross(ca):normalize_inplace()local cE=math.acos(utils.clamp(cV:dot(-cU),-1,1))*constants.rad2deg;if cV:cross(-cU):dot(ca)<0 then cE=-cE end;return cE end;local function cW(cX,cY,cZ)cY=cY:project_on_plane(cX)cZ=cZ:project_on_plane(cX)return p(cY:cross(cZ):dot(cX),cY:dot(cZ))end;function clearAll()if am then am=false;AutopilotAccelerating=false;AutopilotBraking=false;AutopilotCruising=false;Autopilot=false;AutopilotRealigned=false;AutopilotStatus="Aligning"RetrogradeIsOn=false;ProgradeIsOn=false;AltitudeHold=false;Reentry=false;BrakeLanding=false;BrakeIsOn=false;AutoTakeoff=false;VertTakeOff=false;U=false;G=false;ai=false;aj=false;J=false;be=autoRollPreference;VectorToTarget=false;TurnBurn=false;as=false;LockPitch=nil else am=true end end;function wipeSaveVariables()if not dbHud_1 then W="No Databank Found, unable to wipe. \nYou must have a Databank attached to ship prior to running the HUD autoconfigure"ad=5 else if aL then for bG,bH in pairs(a)do dbHud_1.setStringValue(bH,g(nil))end;for bG,bH in pairs(b)do if bH~="SavedLocations"then dbHud_1.setStringValue(bH,g(nil))end end;W="Databank wiped. New variables will save after re-enter seat and exit"ad=5;aL=false;aK=false;a9=true else W="Press ALT-7 again to confirm wipe of ALL data"aL=true end end end;function CheckButtons()for _,bH in pairs(aB)do if bH.hovered then if not bH.drawCondition or bH.drawCondition()then bH.toggleFunction()end;bH.hovered=false end end end;function SetButtonContains()local c2=ab+aE/2;local c3=ac+aF/2;for _,bH in pairs(aB)do bH.hovered=Contains(c2,c3,bH.x,bH.y,bH.width,bH.height)end end;function DrawButton(cy,c_,hover,c2,c3,d0,d1,d2,d3,d4,d5)if type(d4)=="function"then d4=d4()end;if type(d5)=="function"then d5=d5()end;cy[#cy+1]=e("<rect x='%f' y='%f' width='%f' height='%f' fill='",c2,c3,d0,d1)if c_ then cy[#cy+1]=e("%s'",d2)else cy[#cy+1]=d3 end;if hover then cy[#cy+1]=" style='stroke:white; stroke-width:2'"else cy[#cy+1]=" style='stroke:black; stroke-width:1'"end;cy[#cy+1]="></rect>"cy[#cy+1]=e("<text x='%f' y='%f' font-size='24' fill='",c2+d0/2,c3+d1/2+5)if c_ then cy[#cy+1]="black"else cy[#cy+1]="white"end;cy[#cy+1]="' text-anchor='middle' font-family='Montserrat'>"if c_ then cy[#cy+1]=e("%s</text>",d4)else cy[#cy+1]=e("%s</text>",d5)end end;function DrawButtons(cy)local d6="rgb(50,50,50)'"local d7="rgb(210,200,200)"local d8=DrawButton;for _,bH in pairs(aB)do local b_=bH.disableName;local bZ=bH.enableName;if type(b_)=="function"then b_=b_()end;if type(bZ)=="function"then bZ=bZ()end;if not bH.drawCondition or bH.drawCondition()then d8(cy,bH.toggleVar(),bH.hovered,bH.x,bH.y,bH.width,bH.height,d7,d6,b_,bZ)end end end;function DrawTank(cy,a_,c2,d9,da,db,dc,dd)local de=1;local df=2;local dg=3;local dh=4;local di=5;local dj=6;local dk=""local dl=0;local dm=fuelY;local dn=fuelY+10;if o()==1 and not RemoteHud then dm=dm-50;dn=dn-50 end;cy[#cy+1]=[[<g class="pdim txtfuel">]]if da=="ATMO"then dk="atmofueltank"elseif da=="SPACE"then dk="spacefueltank"else dk="rocketfueltank"end;dl=_G[dk.."_size"]if#db>0 then for i=1,#db do local ct=string.sub(db[i][df],1,12)local dp=0;for cR=1,dl do if db[i][df]==f(unit[dk.."_"..cR].getData()).name then dp=cR;break end end;if a_ or dc[i]==nil or dd[i]==nil then local dq=0;local dr=0;local ds=0;local dt=0;local bQ=system.getTime()if dp~=0 then dd[i]=f(unit[dk.."_"..dp].getData()).percentage;dc[i]=f(unit[dk.."_"..dp].getData()).timeLeft;if dc[i]=="n/a"then dc[i]=0 end else ds=m(db[i][de])-db[i][dh]dq=db[i][dg]dd[i]=d(0.5+ds*100/dq)dr=db[i][di]dt=db[i][dj]if dr<=ds then dc[i]=0 else dc[i]=d(0.5+ds/((dr-ds)/(bQ-dt)))end;db[i][di]=ds;db[i][dj]=bQ end end;if ct==d9 then ct=e("%s %d",da,i)end;if dp==0 then ct=ct.." *"end;local du;if dc[i]==0 then du="n/a"else du=FormatTimeString(dc[i])end;if dd[i]~=nil then local cN=d(dd[i]*2.55)local cO=e("rgb(%d,%d,%d)",255-cN,cN,0)local dv=""if du~="n/a"and dc[i]<120 or dd[i]<5 then if a_ then dv=[[class="red"]]end end;cy[#cy+1]=e([[
<text x=%d y="%d" %s>%s</text>
<text x=%d y="%d" style="fill:%s">%d%% %s</text>
]],c2,dm,dv,ct,c2,dn,cO,dd[i],du)dm=dm+30;dn=dn+30 end end end;cy[#cy+1]="</g>"end;function HideInterplanetaryPanel()system.destroyWidgetPanel(panelInterplanetary)panelInterplanetary=nil end;function getRelativePitch(bf)bf=vec3(bf)local cE=-math.deg(math.atan(bf.y,bf.z))+180;cE=cE-90;if cE<0 then cE=360+cE end;if cE>180 then cE=-180+cE-180 end;return-cE end;function getRelativeYaw(bf)bf=vec3(bf)local dw=math.deg(math.atan(bf.y,bf.x))-90;if dw<-180 then dw=360+dw end;return dw end;function AlignToWorldVector(dx,dy,dz)if not ao or not bk or al~=-1 or bg<I then local dA=dz;if dA==nil then dA=DampingMultiplier end;if dy==nil then dy=aD end;dx=vec3(dx):normalize()local dB=vec3(core.getConstructWorldOrientationForward())-dx;local dC=-getMagnitudeInDirection(dB,core.getConstructWorldOrientationRight())*aC;local dD=-getMagnitudeInDirection(dB,core.getConstructWorldOrientationUp())*aC;if ax==0 then ax=dC/2 end;if ay==0 then ay=dD/2 end;if math.abs(dC)<0.1 then P=P-dC*2 else P=P-(dC+(dC-ax)*dA)end;if math.abs(dD)<0.1 then O=O+dD*2 else O=O+dD+(dD-ay)*dA end;ax=dC;ay=dD;if math.abs(dC)<dy and math.abs(dD)<dy then return true end;return false elseif bk and al==-1 then dx=vec3(core.getWorldVelocity())local dA=dz;if dA==nil then dA=DampingMultiplier end;if dy==nil then dy=aD end;dx=vec3(dx):normalize()local dB=vec3(core.getConstructWorldOrientationForward())-dx;local dC=-getMagnitudeInDirection(dB,core.getConstructWorldOrientationRight())*aC;local dD=-getMagnitudeInDirection(dB,core.getConstructWorldOrientationUp())*aC;if ax==0 then ax=dC/2 end;if ay==0 then ay=dD/2 end;if math.abs(dC)<0.1 then P=P-dC*5 else P=P-(dC+(dC-ax)*dA)end;if math.abs(dD)<0.1 then O=O+dD*5 else O=O+dD+(dD-ay)*dA end;ax=dC;ay=dD;if math.abs(dC)<dy and math.abs(dD)<dy then return true end;return false end end;function getAPEnableName()local ct=AutopilotTargetName;if ct==nil then local dE,dF=getDistanceDisplayString((vec3(core.getConstructWorldPos())-CustomTarget.position):len())ct=CustomTarget.name.." "..dE..dF end;if ct==nil then ct="None"end;return"Engage Autopilot: "..ct end;function getAPDisableName()local ct=AutopilotTargetName;if ct==nil then ct=CustomTarget.name end;if ct==nil then ct="None"end;return"Disable Autopilot: "..ct end;function ToggleAntigrav()if antigrav and not ExternalAGG then if antigrav.getState()==1 then antigrav.deactivate()antigrav.hide()else if AntigravTargetAltitude==nil then AntigravTargetAltitude=ap end;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;antigrav.activate()antigrav.show()end end end;function BeginReentry()if Reentry then W="Re-Entry cancelled"Reentry=false;be=autoRollPreference;AltitudeHold=false elseif not planet.hasAtmosphere then W="Re-Entry requirements not met: you must start out of atmosphere\n and within a planets gravity well over a planet with atmosphere"ad=5 elseif not J then StrongBrakes=planet.gravity*9.80665*n()<LastMaxBrakeInAtmo;if not StrongBrakes then W="WARNING: Insufficient Brakes for Parachute Re-Entry"else Reentry=true;if Nav.axisCommandManager:getAxisCommandType(0)~=controlMasterModeId.cruise then Nav.control.cancelCurrentControlMasterMode()end;be=true;BrakeIsOn=false;W="Beginning Parachute Re-Entry - Strap In. Target speed: "..ReentrySpeed end else Reentry=true;AltitudeHold=true;be=true;BrakeIsOn=false;HoldAltitude=planet.spaceEngineMinAltitude-50;local dG,dH=getDistanceDisplayString(HoldAltitude)W="Beginning Re-entry. Target speed: "..bp.." Target Altitude: "..dG..dH;cmdCruise(math.floor(bp))end;AutoTakeoff=false end;function SetupButtons()local dI=50;local dJ=260;local dK=MakeButton("Enable Brake Toggle","Disable Brake Toggle",dJ,dI,aE/2-dJ/2,aF/2+350,function()return BrakeToggleStatus end,function()BrakeToggleStatus=not BrakeToggleStatus;if BrakeToggleStatus then W="Brakes in Toggle Mode"else W="Brakes in Default Mode"end end)MakeButton("Align Prograde","Disable Prograde",dJ,dI,aE/2-dJ/2-50-dK.width,aF/2-dI+380,function()return ProgradeIsOn end,ProgradeToggle)MakeButton("Align Retrograde","Disable Retrograde",dJ,dI,aE/2-dJ/2+dK.width+50,aF/2-dI+380,function()return RetrogradeIsOn end,RetrogradeToggle,function()return j()==0 end)local dL=MakeButton(getAPEnableName,getAPDisableName,600,60,aE/2-600/2,aF/2-60/2-400,function()return Autopilot end,ToggleAutopilot)MakeButton("Save Position","Save Position",200,dL.height,dL.x+dL.width+30,dL.y,function()return false end,AddNewLocation,function()return AutopilotTargetIndex==0 or CustomTarget==nil end)MakeButton("Update Position","Update Position",200,dL.height,dL.x+dL.width+30,dL.y,function()return false end,UpdatePosition,function()return AutopilotTargetIndex>0 and CustomTarget~=nil end)MakeButton("Clear Position","Clear Position",200,dL.height,dL.x-200-30,dL.y,function()return true end,ClearCurrentPosition,function()return AutopilotTargetIndex>0 and CustomTarget~=nil end)dI=60;dJ=300;local c2=10;local c3=aF/2-300;MakeButton("Enable Turn and Burn","Disable Turn and Burn",dJ,dI,c2,c3,function()return TurnBurn end,ToggleTurnBurn)MakeButton("Engage Altitude Hold","Disable Altitude Hold",dJ,dI,c2+dJ+20,c3,function()return AltitudeHold end,ToggleAltitudeHold)c3=c3+dI+20;MakeButton("Engage Autoland","Disable Autoland",dJ,dI,c2,c3,function()return AutoLanding end,ToggleAutoLanding)local dM,dN,dO;if VertTakeOffEngine then dM="Engage Vertical Takeoff"dN="Disable Vertical Takeoff"dO=VertTakeOff else dM="Engage Auto Takeoff"dN="Disable Auto Takeoff"dO=AutoTakeoff end;MakeButton(dM,dN,dJ,dI,c2+dJ+20,c3,function()return dO end,ToggleAutoTakeoff)c3=c3+dI+20;MakeButton("Show Orbit Display","Hide Orbit Display",dJ,dI,c2,c3,function()return DisplayOrbit end,function()DisplayOrbit=not DisplayOrbit;if DisplayOrbit then W="Orbit Display Enabled"else W="Orbit Display Disabled"end end)MakeButton("Engage Orbiting","Cancel Orbiting",dJ,dI,c2+dJ+20,c3,function()return IntoOrbit end,ToggleIntoOrbit,function()return j()==0 and unit.getClosestPlanetInfluence()>0 end)c3=c3+dI+20;MakeButton("Glide Re-Entry","Cancel Glide Re-Entry",dJ,dI,c2,c3,function()return Reentry end,function()ai=true;ProgradeToggle()end,function()return ap>ReentryAltitude end)MakeButton("Parachute Re-Entry","Cancel Parachute Re-Entry",dJ,dI,c2+dJ+20,c3,function()return Reentry end,BeginReentry,function()return ap>ReentryAltitude end)c3=c3+dI+20;MakeButton("Engage Follow Mode","Disable Follow Mode",dJ,dI,c2,c3,function()return U end,ToggleFollowMode,function()return o()==1 end)MakeButton("Enable Repair Arrows","Disable Repair Arrows",dJ,dI,c2+dJ+20,c3,function()return aS end,function()aS=not aS;if aS then W="Repair Arrows Enabled"else W="Repair Arrows Diabled"end end,function()return o()==1 end)c3=c3+dI+20;if not ExternalAGG then MakeButton("Enable AGG","Disable AGG",dJ,dI,c2,c3,function()return antigrav.getState()==1 end,ToggleAntigrav,function()return antigrav~=nil end)end;c3=c3+dI+20;MakeButton(function()return e("Toggle Control Scheme - Current: %s",userControlScheme)end,function()return e("Control Scheme: %s",userControlScheme)end,dJ*2,dI,c2,c3,function()return false end,function()if userControlScheme=="keyboard"then userControlScheme="mouse"elseif userControlScheme=="mouse"then userControlScheme="virtual joystick"else userControlScheme="keyboard"end end)end;function GetFlightStyle()local dP=Nav.axisCommandManager:getAxisCommandType(0)local dQ="TRAVEL"if dP==1 then dQ="CRUISE"end;if Autopilot then dQ="AUTOPILOT"end;return dQ end;function UpdateHud(cy)local ch=ap;local bf=core.getVelocity()local bX=vec3(bf):len()local cD=vec3(core.getWorldVertical())local cB=vec3(core.getConstructWorldOrientationForward())local cC=vec3(core.getConstructWorldOrientationRight())local dR=vec3(core.getConstructWorldOrientationUp())local dS=getRoll(cD,cB,cC)local dT=dS/180*math.pi;local dU=math.cos(dT)local dV=math.sin(dT)local cE=getPitch(cD,cB,cC*dU+dR*dV)local dW=dS;local dX=cE;local dY=j()local dZ=d(unit.getThrottle())local d_=bX*3.6;local e0=unit.getAxisCommandValue(0)local e1=ConvertResolutionX(1770)local e2=ConvertResolutionY(310)if AtmoSpeedAssist and Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle then e0=z;dZ=z*100 end;local dQ=GetFlightStyle()local e3="ROLL"local cH=unit.getClosestPlanetInfluence()>0;if dZ==nil then dZ=0 end;if not cH then if bX>5 then cE=getRelativePitch(bf)dS=getRelativeYaw(bf)else cE=0;dS=0 end;e3="YAW"end;if x>50000 and not ao then local e4;if x>200000 then e4=round(x/200000,2).." su"else e4=round(x/1000,1).." km"end;cy[#cy+1]=e([[<text class="pbright txtbig txtmid" x="%d" y="%d">PvP Boundary: %s</text>]],e1,e2,e4)end;cy[#cy+1]=ag;cy[#cy+1]=az;cy[#cy+1]=af;if b1%aV==0 then a_=true end;if fuelX~=0 and fuelY~=0 then DrawTank(cy,a_,fuelX,"Atmospheric ","ATMO",aO,aY,aZ)DrawTank(cy,a_,fuelX+100,"Space fuel t","SPACE",aP,aW,aX)DrawTank(cy,a_,fuelX+200,"Rocket fuel ","ROCKET",aQ,aT,aU)end;if a_ then a_=false;b1=0 end;b1=b1+1;DrawVerticalSpeed(cy,ch)if o()==0 or RemoteHud then if not IsInFreeLook()or brightHud then if cH then DrawRollLines(cy,centerX,centerY,dW,e3,cH)DrawArtificialHorizon(cy,dX,dW,centerX,centerY,cH,d(getRelativeYaw(bf)),bX)else DrawRollLines(cy,centerX,centerY,dS,e3,cH)DrawArtificialHorizon(cy,cE,dS,centerX,centerY,cH,d(dS),bX)end;DrawAltitudeDisplay(cy,ch,cH)DrawPrograde(cy,bf,bX,centerX,centerY)end end;DrawThrottle(cy,dQ,dZ,e0)DrawSpeed(cy,d_)DrawWarnings(cy)DisplayOrbitScreen(cy)if screen_2 then local cl=vec3(core.getConstructWorldPos())local c2=960+cl.x/b4;local c3=450+cl.y/b5;screen_2.moveContent(b6,(c2-80)/19.2,(c3-80)/10.8)end end;function IsInFreeLook()return system.isViewLocked()==0 and userControlScheme~="keyboard"and o()==0 end;function HUDPrologue(cy)if not w then t=PvPR;v=PvPG;u=PvPB else t=SafeR;v=SafeG;u=SafeB end;au=[[rgb(]]..d(t+0.5)..","..d(v+0.5)..","..d(u+0.5)..[[)]]av=[[rgb(]]..d(t*0.9+0.5)..","..d(v*0.9+0.5)..","..d(u*0.9+0.5)..[[)]]local e5=au;local e6=av;local e7=au;local e8=av;if IsInFreeLook()and not brightHud then e5=[[rgb(]]..d(t*0.4+0.5)..","..d(v*0.4+0.5)..","..d(u*0.3+0.5)..[[)]]e6=[[rgb(]]..d(t*0.3+0.5)..","..d(v*0.3+0.5)..","..d(u*0.2+0.5)..[[)]]end;cy[#cy+1]=e([[
<head>
<style>
body {margin: 0}
svg {position:absolute;top:0;left:0;font-family:Montserrat;}
.txt {font-size:10px;font-weight:bold;}
.txttick {font-size:12px;font-weight:bold;}
.txtbig {font-size:14px;font-weight:bold;}
.altsm {font-size:16px;font-weight:normal;}
.altbig {font-size:21px;font-weight:normal;}
.line {stroke-width:2px;fill:none}
.linethick {stroke-width:3px;fill:none}
.warnings {font-size:26px;fill:red;text-anchor:middle;font-family:Bank}
.warn {fill:orange;font-size:24px}
.crit {fill:darkred;font-size:28px}
.bright {fill:%s;stroke:%s}
.pbright {fill:%s;stroke:%s}
.dim {fill:%s;stroke:%s}
.pdim {fill:%s;stroke:%s}
.red {fill:red;stroke:red}
.redout {fill:none;stroke:red}
.op30 {opacity:0.3}
.op10 {opacity:0.1}
.txtstart {text-anchor:start}
.txtend {text-anchor:end}
.txtmid {text-anchor:middle}
.txtvspd {font-family:sans-serif;font-weight:normal}
.txtvspdval {font-size:20px}
.txtfuel {font-size:11px;font-weight:bold}
.txtorb {font-size:12px}
.txtorbbig {font-size:18px}
.hudver {font-size:10px;font-weight:bold;fill:red;text-anchor:end;font-family:Bank}
.msg {font-size:40px;fill:red;text-anchor:middle;font-weight:normal}
.cursor {stroke:white}
</style>
</head>
<body>
<svg height="100%%" width="100%%" viewBox="0 0 %d %d">
]],e5,e5,e7,e7,e6,e6,e8,e8,ResolutionX,ResolutionY)end;function HUDEpilogue(cy)cy[#cy+1]="</svg>"end;function DrawSpeed(cy,d_)local e9=throtPosY-10;local ea=throtPosX+10;cy[#cy+1]=[[<g class="pdim txt txtend">]]if o()==1 and not RemoteHud then e9=75 end;cy[#cy+1]=e([[
<g class="pbright txtstart">
<text class="txtbig" x="%d" y="%d">%d km/h</text>
</g>
</g>]],ea,e9,d(d_))end;function DrawOdometer(cy,a7,TotalDistanceTravelled,dQ,a8,dY)local eb=ConvertResolutionX(1240)local ec=ConvertResolutionY(55)local ed=ec+10;local dY=j()local bU=core.g()local ee=0;local ef=0;local eg=0;RefreshLastMaxBrake(bU)if ao then eg=LastMaxBrakeInAtmo else eg=LastMaxBrake end;maxThrust=Nav:maxForceForward()aM=n()if not ShowOdometer then return end;local eh=vec3(core.getWorldAcceleration()):len()/9.80665;if bU>0.1 then ef=aM*bU;ee=maxThrust/bU end;cy[#cy+1]=[[<g class="pdim txt txtend">]]if o()==1 and not RemoteHud then eb=ConvertResolutionX(1120)ec=ConvertResolutionY(55)ed=ec+10 elseif ao then local ei=ConvertResolutionX(770)cy[#cy+1]=e([[
<text x="%d" y="%d">ATMOSPHERE</text>
<text x="%d" y="%d">%.2f</text>
]],ei,ec,ei,ed,dY)end;cy[#cy+1]=e([[
<g class="pbright txtend">
</g>
<text x="%d" y="%d">GRAVITY</text>
<text x="%d" y="%d">%.2f g</text>
<text x="%d" y="%d">ACCEL</text>
<text x="%d" y="%d">%.2f g</text>
]],eb,ec,eb,ed,bU/9.80665,eb,ec+20,eb,ed+20,eh)cy[#cy+1]=e([[
<g class="pbright txt">
<path class="linethick" d="M %d 0 L %d %d Q %d %d %d %d L %d 0"/>]],ConvertResolutionX(660),ConvertResolutionX(700),ConvertResolutionY(35),ConvertResolutionX(960),ConvertResolutionY(55),ConvertResolutionX(1240),ConvertResolutionY(35),ConvertResolutionX(1280))if o()==0 or RemoteHud then cy[#cy+1]=e([[
<text class="txtstart" x="%d" y="%d" >Trip: %.2f km</text>
<text class="txtstart" x="%d" y="%d">Lifetime: %.2f Mm</text>
<text class="txtstart" x="%d" y="%d">Trip Time: %s</text>
<text class="txtstart" x="%d" y="%d">Total Time: %s</text>
<text class="txtstart" x="%d" y="%d">Mass: %.2f Tons</text>
<text class="txtend" x="%d" y="%d">Max Brake: %.2f kN</text>
<text class="txtend" x="%d" y="%d">Max Thrust: %.2f kN</text>
<text class="txtbig txtmid" x="%d" y="%d">%s</text>]],ConvertResolutionX(700),ConvertResolutionY(20),a7,ConvertResolutionX(700),ConvertResolutionY(30),TotalDistanceTravelled/1000,ConvertResolutionX(830),ConvertResolutionY(20),FormatTimeString(a8),ConvertResolutionX(830),ConvertResolutionY(30),FormatTimeString(TotalFlightTime),ConvertResolutionX(970),ConvertResolutionY(20),aM/1000,ConvertResolutionX(1240),ConvertResolutionY(10),eg/1000,ConvertResolutionX(1240),ConvertResolutionY(30),maxThrust/1000,ConvertResolutionX(960),ConvertResolutionY(180),dQ)if bU>0.1 then cy[#cy+1]=e([[
<text class="txtstart" x="%d" y="%d">Max Mass: %.2f Tons</text>
<text class="txtend" x="%d" y="%d">Req Thrust: %.2f kN</text>
]],ConvertResolutionX(970),ConvertResolutionY(30),ee/1000,ConvertResolutionX(1240),ConvertResolutionY(20),ef/1000)else cy[#cy+1]=e([[
<text class="txtstart" x="%d" y="%d" text-anchor="start">Max Mass: n/a</text>
<text class="txtend" x="%d" y="%d" text-anchor="end">Req Thrust: n/a</text>
]],ConvertResolutionX(970),ConvertResolutionY(30),ConvertResolutionX(1240),ConvertResolutionY(20))end else cy[#cy+1]=e([[<text class="txtbig txtmid" x="960" y="33">%s</text>]],ConvertResolutionX(960),ConvertResolutionY(33),dQ)end;cy[#cy+1]="</g>"end;function DrawThrottle(cy,dQ,dZ,e0)dZ=math.floor(dZ+0.5)local dm=throtPosY+10;local dn=throtPosY+20;if o()==1 and not RemoteHud then dm=55;dn=65 end;local ej="CRUISE"local unit="km/h"local ek=e0;if dQ=="TRAVEL"or dQ=="AUTOPILOT"then ej="THROT"unit="%"ek=dZ;local el="dim"if dZ<0 then el="red"end;cy[#cy+1]=e([[<g class="%s">
<path class="linethick" d="M %d %d L %d %d L %d %d L %d %d"/>
<g transform="translate(0 %.0f)">
<polygon points="%d,%d %d,%d %d,%d"/>
</g>]],el,throtPosX-7,throtPosY-50,throtPosX,throtPosY-50,throtPosX,throtPosY+50,throtPosX-7,throtPosY+50,1-math.abs(dZ),throtPosX-10,throtPosY+50,throtPosX-15,throtPosY+53,throtPosX-15,throtPosY+47)end;cy[#cy+1]=e([[
<g class="pbright txtstart">
<text x="%s" y="%s">%s</text>
<text x="%s" y="%s">%.0f %s</text>
</g>
</g>]],throtPosX+10,dm,ej,throtPosX+10,dn,ek,unit)if ao and AtmoSpeedAssist and Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle and B then dZ=math.floor(C*100+0.5)local el="red"if dZ<0 then el="red"end;cy[#cy+1]=e([[<g class="%s">
<g transform="translate(0 %d)">
<polygon points="%d,%d %d,%d %d,%d"/>
</g></g>]],el,1-math.abs(dZ),throtPosX-10,throtPosY+50,throtPosX-15,throtPosY+53,throtPosX-15,throtPosY+47)cy[#cy+1]=e([[
<g class="pbright txtstart">
<text x="%s" y="%s">%s</text>
<text x="%s" y="%s">%d %s</text>
</g>]],throtPosX+10,dm+40,"LIMIT",throtPosX+10,dn+40,dZ,"%")end;if ao and AtmoSpeedAssist or Reentry then cy[#cy+1]=e([[
<g class="dim txtstart">
<text x="%s" y="%s">%s %s</text>
</g>
]],throtPosX+10,dm-40,"LIMIT: ",bp.." km/h")elseif not ao and Autopilot then cy[#cy+1]=e([[
<g class="dim txtstart">
<text x="%s" y="%s">%s %s</text>
</g>
]],throtPosX+10,dm-40,"LIMIT: ",math.floor(MaxGameVelocity*3.6+0.5).." km/h")end end;function DrawVerticalSpeed(cy,ch)if ch<200000 and not ao or ch and ao then local em=-vec3(core.getWorldVertical()):dot(vec3(core.getWorldVelocity()))local en=0;if math.abs(em)>1 then en=45*math.log(math.abs(em),10)if em<0 then en=-en end end;cy[#cy+1]=e([[
<g class="pbright txt txtvspd" transform="translate(%d %d) scale(0.6)">
<text x="31" y="-41">1000</text>
<text x="-10" y="-65">100</text>
<text x="-54" y="-45">10</text>
<text x="-73" y="3">O</text>
<text x="-56" y="52">-10</text>
<text x="-14" y="72">-100</text>
<text x="29" y="50">-1000</text>
<text x="85" y="0" class="txtvspdval txtend">%d m/s</text>
<g class="linethick">
<path d="m-41 75 2.5-4.4m17 12 1.2-4.9m20 7.5v-10m-75-34 4.4-2.5m-12-17 4.9-1.2m17 40 7-7m-32-53h10m34-75 2.5 4.4m17-12 1.2 4.9m20-7.5v10m-75 34 4.4 2.5m-12 17 4.9 1.2m17-40 7 7m-32 53h10m116 75-2.5-4.4m-17 12-1.2-4.9m40-17-7-7m-12-128-2.5 4.4m-17-12-1.2 4.9m40 17-7 7"/>
<circle r="90" />
</g>
<path transform="rotate(%d)" d="m-0.094-7c-22 2.2-45 4.8-67 7 23 1.7 45 5.6 67 7 4.4-0.068 7.8-4.9 6.3-9.1-0.86-2.9-3.7-5-6.8-4.9z" />
</g>
]],vSpdMeterX,vSpdMeterY,d(em),d(en))end end;function getHeading(cU)local eo=-vec3(core.getWorldVertical())cU=cU-cU:project_on(eo)local ep=vec3(0,0,1)ep=ep-ep:project_on(eo)local eq=ep:cross(eo)local en=ep:angle_between(cU)*constants.rad2deg;if cU:dot(eq)<0 then en=360-en end;return en end;function DrawRollLines(cy,centerX,centerY,dW,e3,cH)local er=circleRad;local es=20;es=d(es)local et=d(dW)if cH then for i=-45,45,5 do local eu=i;cy[#cy+1]=e([[<g transform="rotate(%f,%d,%d)">]],eu,centerX,centerY)len=5;if i%15==0 then len=15 elseif i%10==0 then len=10 end;cy[#cy+1]=e([[<line x1=%d y1=%d x2=%d y2="%d"/></g>]],centerX,centerY+er+es-len,centerX,centerY+er+es)end;cy[#cy+1]=e([["
<g class="pdim txt txtmid">
<text x="%d" y="%d">%s</text>
<text x="%d" y="%d">%d deg</text>
</g>
]],centerX,centerY+er+es-35,e3,centerX,centerY+er+es-25,et)cy[#cy+1]=e([[<g transform="rotate(%f,%d,%d)">]],-dW,centerX,centerY)cy[#cy+1]=e([[<<polygon points="%d,%d %d,%d %d,%d"/>]],centerX-5,centerY+er+es-20,centerX+5,centerY+er+es-20,centerX,centerY+er+es-15)cy[#cy+1]="</g>"end;local dw=et;if cH then dw=getHeading(vec3(core.getConstructWorldOrientationForward()))end;local ev=20;local ew=d(dw)local ex=0;local ey=centerY+er+es+20;local ez=centerX;if e3~="YAW"then ey=ConvertResolutionY(130)ez=ConvertResolutionX(960)end;local eA=[[<path class="txttick line" d="]]for i=d(ew-(ev+10)-ew%5+0.5),d(ew+ev+10+ew%5+0.5),5 do local c2=ez+-i*5+dw*5;if i%10==0 then ex=10;local q=i;if q==360 then q=0 elseif q>360 then q=q-360 elseif q<0 then q=q+360 end;cy[#cy+1]=e([[
<text x="%f" y="%f">%d</text>]],c2+5,ey-12,q)elseif i%5==0 then ex=5 end;if ex==10 then eA=e([[%s M %f %f v %d]],eA,c2,ey-5,ex)else eA=e([[%s M %f %f v %d]],eA,c2,ey-2.5,ex)end end;cy[#cy+1]=eA..[["/>]]cy[#cy+1]=e([[<<polygon points="%d,%d %d,%d %d,%d"/>]],ez-5,ey+10,ez+5,ey+10,ez,ey+5)if cH then e3="HDG"end;cy[#cy+1]=e([["
<g class="pdim txt txtmid">
<text x="%d" y="%d">%d deg</text>
<text x="%d" y="%d">%s</text>
</g>
]],ez,ey+25,ew,ez,ey+35,e3)end;function DrawArtificialHorizon(cy,dX,dW,centerX,centerY,cH,eB,bX)local er=circleRad;local eC=d(er*3/5)if er>0 then local eD=d(dX)local len=0;local eA=e([[<path transform="rotate(%f,%d,%d)" class="dim line" d="]],-1*dW,centerX,centerY)if not ao then eA=e([[<path transform="rotate(0,%d,%d)" class="dim line" d="]],centerX,centerY)end;cy[#cy+1]=e([[<clipPath id="cut"><circle r="%f" cx="%d" cy="%d"/></clipPath>]],er-1,centerX,centerY)cy[#cy+1]=[[<g class="dim txttick" clip-path="url(#cut)">]]for i=d(eD-30-eD%5+0.5),d(eD+30+eD%5+0.5),5 do if i%10==0 then len=30 elseif i%5==0 then len=20 end;local c3=centerY+-i*5+dX*5;if len==30 then eA=e([[%s M %d %f h %d]],eA,centerX-eC-len,c3,len)if ao then cy[#cy+1]=e([[<g path transform="rotate(%f,%d,%d)" class="pdim txt txtmid"><text x="%d" y="%f">%d</text></g>]],-1*dW,centerX,centerY,centerX-eC+10,c3,i)cy[#cy+1]=e([[<g path transform="rotate(%f,%d,%d)" class="pdim txt txtmid"><text x="%d" y="%f">%d</text></g>]],-1*dW,centerX,centerY,centerX+eC-10,c3,i)if i==0 or i==180 or i==-180 then cy[#cy+1]=e([[<path transform="rotate(%f,%d,%d)" d="m %d,%f %d,0" stroke-width="1" style="fill:none;stroke:#F5B800;" />]],-1*dW,centerX,centerY,centerX-eC+20,c3,eC*2-40)end else cy[#cy+1]=e([[<g class="pdim txt txtmid"><text x="%d" y="%f">%d</text></g>]],centerX-eC+10,c3,i)cy[#cy+1]=e([[<g class="pdim txt txtmid"><text x="%d" y="%f">%d</text></g>]],centerX+eC-10,c3,i)end;eA=e([[%s M %d %f h %d]],eA,centerX+eC,c3,len)else eA=e([[%s M %d %f h %d]],eA,centerX-eC-len,c3,len)eA=e([[%s M %d %f h %d]],eA,centerX+eC,c3,len)end end;cy[#cy+1]=eA..[["/>]]local eE="PITCH"if not cH then eE="REL PITCH"end;if dX>90 and not ao then dX=90-(dX-90)elseif dX<-90 and not ao then dX=-90-(dX+90)end;if er>200 then if ao then if bX>I then cy[#cy+1]=e([["
<g class="pdim txt txtmid">
<text x="%d" y="%d">%s</text>
<text x="%d" y="%d">%d deg</text>
</g>
]],centerX,centerY-15,"Yaw",centerX,centerY+20,eB)end;cy[#cy+1]=e([[<g transform="rotate(%f,%d,%d)">]],-dW,centerX,centerY)else cy[#cy+1]=e([[<g transform="rotate(0,%d,%d)">]],centerX,centerY)end;cy[#cy+1]=e([[<<polygon points="%d,%d %d,%d %d,%d"/> class="pdim txtend"><text x="%d" y="%f">%d</text>]],centerX-eC+25,centerY-5,centerX-eC+20,centerY,centerX-eC+25,centerY+5,centerX-eC+50,centerY+4,eD)cy[#cy+1]=e([[<<polygon points="%d,%d %d,%d %d,%d"/> class="pdim txtend"><text x="%d" y="%f">%d</text>]],centerX+eC-25,centerY-5,centerX+eC-20,centerY,centerX+eC-25,centerY+5,centerX+eC-30,centerY+4,eD)cy[#cy+1]="</g>"end;local eF=d(er/3)cy[#cy+1]=e([[<path d="m %d,%d %d,0" stroke-width="2" style="fill:none;stroke:#F5B800;" />]],centerX-eF,centerY,er-eF)if not ao and cH then cy[#cy+1]=e([[<path transform="rotate(%f,%d,%d)" d="m %d,%f %d,0" stroke-width="1" style="fill:none;stroke:#F5B800;" />]],-1*dW,centerX,centerY,centerX-eC+10,centerY,eC*2-20)end;cy[#cy+1]="</g>"if er<200 then if ao and bX>I then cy[#cy+1]=e([["
<g class="pdim txt txtmid">
<text x="%d" y="%d">%s</text>
<text x="%d" y="%d">%d deg</text>
<text x="%d" y="%d">%s</text>
<text x="%d" y="%d">%d deg</text>
</g>
]],centerX,centerY-er,eE,centerX,centerY-er+10,eD,centerX,centerY-15,"Yaw",centerX,centerY+20,eB)else cy[#cy+1]=e([["
<g class="pdim txt txtmid">
<text x="%d" y="%d">%s</text>
<text x="%d" y="%d">%d deg</text>
</g>
]],centerX,centerY-er,eE,centerX,centerY-er+15,eD)end end end end;function DrawAltitudeDisplay(cy,ch,cH)local eG=altMeterX;local eH=altMeterY;local eI=78;local eJ=19;local eK=AboveGroundLevel()if eK~=-1 then table.insert(cy,e([[
<g class="pdim altsm txtend">
<text x="%d" y="%d">AGL: %.1fm</text>
</g>
]],eG+eI,eH+eJ+20,eK))end;if cH and(ch<200000 and not ao or ch and ao)then table.insert(cy,e([[
<g class="pdim">
<rect class="line" x="%d" y="%d" width="%d" height="%d"/>
<clipPath id="alt"><rect class="line" x="%d" y="%d" width="%d" height="%d"/></clipPath>
<g clip-path="url(#alt)">]],eG-1,eH-4,eI+2,eJ+6,eG+1,eH-1,eI-4,eJ))local cw=0;local eL=1;local eM=0;local eN=ch<0;local eO=9;if eN then eO=0 end;local ch=math.abs(ch)while cw<6 do local eP=11;local eQ=16;local eR=9;local eS=14;local dv="altsm"if cw>2 then eQ=eQ+3;eP=eP+2;eS=eS+2;eR=eR-6;dv="altbig"end;if eN then dv=dv.." red"end;local eT=ch/eL%10;local eU=d(eT)local eV=d((eU+1)%10)local eW=eM;if cw==0 then eW=eT-eU;if eN then eW=1-eW end end;if eN and(cw==0 or eM~=0)then local eX=eV;eV=eU;eU=eX end;local eY=eQ*(eW-1)local eZ=eY+eQ;local c2=eG+eR+(6-cw)*eP;local c3=eH+eS;table.insert(cy,e([[
<g class="%s">
<text x="%d" y="%f">%d</text>
<text x="%d" y="%f">%d</text>
</g>
]],dv,c2,c3+eY,eV,c2,c3+eZ,eU))cw=cw+1;eL=eL*10;if eU==eO then eM=eW else eM=0 end end;table.insert(cy,[[</g></g>]])end end;function DrawPrograde(cy,bf,bX,centerX,centerY)if bX>5 and not ao or bX>I then local er=circleRad;local e_=20;local f0=20;local f1=vec3(bf)local f2=getRelativePitch(f1)local f3=getRelativeYaw(f1)local f4=14;local f5=f4/2;local f6=-f3/f0*er;local f7=f2/e_*er;local c2=centerX+f6;local c3=centerY+f7;local ae=math.sqrt(f6^2+f7^2)local f8=[[<circle
cx="]]..c2 ..[["
cy="]]..c3 ..[["
r="]]..f5/f4 ..[["
style="fill:#d7fe00;stroke:none;fill-opacity:1"/>
<circle
cx="]]..c2 ..[["
cy="]]..c3 ..[["
r="]]..f5 ..[["
style="stroke:#d7fe00;stroke-opacity:1;fill:none" />
<path
d="M ]]..c2-f4 ..[[,]]..c3 ..[[ h ]]..f5 ..[["
style="stroke:#d7fe00;stroke-opacity:1" />
<path
d="M ]]..c2+f5 ..[[,]]..c3 ..[[ h ]]..f5 ..[["
style="stroke:#d7fe00;stroke-opacity:1" />
<path
d="M ]]..c2 ..[[,]]..c3-f4 ..[[ v ]]..f5 ..[["
style="stroke:#d7fe00;stroke-opacity:1" />]]if ae<er then cy[#cy+1]=f8 else local en=math.atan(f7,f6)local f9=4;local fa=centerX+er*math.cos(en)local fb=centerY+er*math.sin(en)cy[#cy+1]=e('<g transform="rotate(%f %f %f)"><rect x="%f" y="%f" width="%f" height="%f" stroke="#d7fe00" fill="#d7fe00" /><path d="M %f %f l %f %f l %f %f z" fill="#d7fe00" stroke="#d7fe00"></g>',en*180/math.pi,fa,fb,fa-f9,fb-f9/2,f9*2,f9,fa+f9,fb-f9,f9,f9,-f9,f9)end;if not ao then f2=getRelativePitch(-f1)f3=getRelativeYaw(-f1)f6=-f3/f0*er;f7=f2/e_*er;c2=centerX+f6;c3=centerY+f7;ae=math.sqrt(f6^2+f7^2)if ae<er then local fc=[[<circle
cx="]]..c2 ..[["
cy="]]..c3 ..[["
r="]]..f5 ..[["
style="stroke:#d7fe00;stroke-opacity:1;fill:none" />
<path
d="M ]]..c2 ..[[,]]..c3-f4 ..[[ v ]]..f5 ..[["
style="stroke:#d7fe00;stroke-opacity:1" id="l"/>
<use
xlink:href="#l"
transform="rotate(120,]]..c2 ..[[,]]..c3 ..[[)" />
<use
xlink:href="#l"
transform="rotate(-120,]]..c2 ..[[,]]..c3 ..[[)" />
<path
d="M ]]..c2-f5 ..[[,]]..c3 ..[[ h ]]..f4 ..[["
style="stroke-width:0.5;stroke:#d7fe00;stroke-opacity:1"
transform="rotate(-45,]]..c2 ..[[,]]..c3 ..[[)" id="c"/>
<use
xlink:href="#c"
transform="rotate(-90,]]..c2 ..[[,]]..c3 ..[[)"/>]]cy[#cy+1]=fc end end end end;function DrawWarnings(cy)cy[#cy+1]=e([[<text class="hudver" x="%d" y="%d">DU Hud Version: %.3f</text>]],ConvertResolutionX(1900),ConvertResolutionY(1070),VERSION_NUMBER)cy[#cy+1]=[[<g class="warnings">]]if unit.isMouseControlActivated()==1 then cy[#cy+1]=e([[
<text x="%d" y="%d">Warning: Invalid Control Scheme Detected</text>]],ConvertResolutionX(960),ConvertResolutionY(550))cy[#cy+1]=e([[
<text x="%d" y="%d">Keyboard Scheme must be selected</text>]],ConvertResolutionX(960),ConvertResolutionY(600))cy[#cy+1]=e([[
<text x="%d" y="%d">Set your preferred scheme in Lua Parameters instead</text>]],ConvertResolutionX(960),ConvertResolutionY(650))end;local fd=ConvertResolutionX(960)local fe=ConvertResolutionY(860)local ff=ConvertResolutionY(880)local fg=ConvertResolutionY(900)local fh=ConvertResolutionY(960)local fi=ConvertResolutionY(200)local fj=ConvertResolutionY(150)local fk=ConvertResolutionY(960)if o()==1 and not RemoteHud then fe=ConvertResolutionY(135)ff=ConvertResolutionY(155)fg=ConvertResolutionY(175)fi=ConvertResolutionY(115)fj=ConvertResolutionY(95)end;if BrakeIsOn then cy[#cy+1]=e([[<text x="%d" y="%d">Brake Engaged</text>]],fd,fe)elseif A>0 then cy[#cy+1]=e([[<text x="%d" y="%d" style="opacity:%s">Auto-Brake Engaged</text>]],fd,fe,A)end;if ao and bk and hoverDetectGround()==-1 then cy[#cy+1]=e([[<text x="%d" y="%d">** STALL WARNING **</text>]],fd,fi+50)end;if as then cy[#cy+1]=e([[<text x="%d" y="%d">Gyro Enabled</text>]],fd,fk)end;if GearExtended then if M then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">Gear Extended</text>]],fd,ff)else cy[#cy+1]=e([[<text x="%d" y="%d">Landed (G: Takeoff)</text>]],fd,ff)end;local dE,dF=getDistanceDisplayString(Nav:getTargetGroundAltitude())cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">Hover Height: %s</text>]],fd,fg,dE..dF)end;if a1 then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">ROCKET BOOST ENABLED</text>]],fd,fh+20)end;if antigrav and not ExternalAGG and antigrav.getState()==1 and AntigravTargetAltitude~=nil then if math.abs(ap-antigrav.getBaseAltitude())<501 then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">AGG On - Target Altitude: %d Singluarity Altitude: %d</text>]],fd,fi+20,d(AntigravTargetAltitude),d(antigrav.getBaseAltitude()))else cy[#cy+1]=e([[<text x="%d" y="%d">AGG On - Target Altitude: %d Singluarity Altitude: %d</text>]],fd,fi+20,d(AntigravTargetAltitude),d(antigrav.getBaseAltitude()))end elseif Autopilot and AutopilotTargetName~="None"then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">Autopilot %s</text>]],fd,fi+20,AutopilotStatus)elseif LockPitch~=nil then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">LockedPitch: %d</text>]],fd,fi+20,d(LockPitch))elseif U then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">Follow Mode Engaged</text>]],fd,fi+20)elseif Reentry then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">Re-entry in Progress</text>]],fd,fi+20)end;local fl,fm,fn=b8:getPlanetarySystem(0):castIntersections(vec3(core.getConstructWorldPos()),bf:normalize(),function(fo)if fo.noAtmosphericDensityAltitude>0 then return fo.radius+fo.noAtmosphericDensityAltitude else return fo.radius+fo.surfaceMaxAltitude*1.5 end end)local fp=fm;if fn~=nil and fm~=nil then fp=math.min(fn,fm)end;if AltitudeHold then if AutoTakeoff and not IntoOrbit then local dE,dF=getDistanceDisplayString(HoldAltitude)cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">Ascent to %s</text>]],fd,fi,dE..dF)if BrakeIsOn then cy[#cy+1]=e([[<text class="crit" x="%d" y="%d">Throttle Up and Disengage Brake For Takeoff</text>]],fd,fi+50)end else local dE,dF=getDistanceDisplayString2(HoldAltitude)cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">Altitude Hold: %s</text>]],fd,fi,dE..dF)end end;if VertTakeOff and(antigrav~=nil and antigrav)then if j()>0.1 then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">Beginning ascent</text>]],fd,fi)elseif j()<0.09 and j()>0.05 then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">Aligning trajectory</text>]],fd,fi)elseif j()<0.05 then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">Leaving atmosphere</text>]],fd,fi)end end;if IntoOrbit then if br~=nil then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">%s</text>]],fd,fi,br)end end;if BrakeLanding then if StrongBrakes then cy[#cy+1]=e([[<text x="%d" y="%d">Brake-Landing</text>]],fd,fi)else cy[#cy+1]=e([[<text x="%d" y="%d">Coast-Landing</text>]],fd,fi)end end;if ProgradeIsOn then cy[#cy+1]=e([[<text class="crit" x="%d" y="%d">Prograde Alignment</text>]],fd,fi)end;if RetrogradeIsOn then cy[#cy+1]=e([[<text class="crit" x="%d" y="%d">Retrograde Alignment</text>]],fd,fi)end;if TurnBurn then cy[#cy+1]=e([[<text class="crit" x="%d" y="%d">Turn & Burn Braking</text>]],fd,fj)elseif fp~=nil and j()==0 then local dE,dF=getDistanceDisplayString(fp)local travelTime=b9.computeTravelTime(bg,0,fp)local fq="Collision"if fl.noAtmosphericDensityAltitude>0 then fq="Atmosphere"end;cy[#cy+1]=e([[<text class="crit" x="%d" y="%d">%s %s In %s (%s)</text>]],fd,fj,fl.name,fq,FormatTimeString(travelTime),dE..dF)end;if VectorToTarget and not IntoOrbit then cy[#cy+1]=e([[<text class="warn" x="%d" y="%d">%s</text>]],fd,fi+30,VectorStatus)end;cy[#cy+1]="</g>"end;function DisplayOrbitScreen(cy)if orbit~=nil and j()<0.2 and planet~=nil and orbit.apoapsis~=nil and orbit.periapsis~=nil and orbit.period~=nil and orbit.apoapsis.speed>5 and DisplayOrbit then local fr=OrbitMapX;local fs=OrbitMapY;local ft=OrbitMapSize;local fu=4;fs=fs+fu;local fv=15;local c2=fr+ft+fr/2+fu;local c3=fs+ft/2+5+fu;local fw,fx,fy,fz;fw=ft/4;fz=0;cy[#cy+1]=[[<g class="pbright txtorb txtmid">]]cy[#cy+1]=e('<rect width="%f" height="%d" rx="10" ry="10" x="%d" y="%d" style="fill:rgb(0,0,100);stroke-width:4;stroke:white;fill-opacity:0.3;" />',ft+fr*2,ft+fs,fu,fu)if orbit.periapsis~=nil and orbit.apoapsis~=nil then fy=(orbit.apoapsis.altitude+orbit.periapsis.altitude+planet.radius*2)/(fw*2)fx=(planet.radius+orbit.periapsis.altitude+(orbit.apoapsis.altitude-orbit.periapsis.altitude)/2)/fy*(1-orbit.eccentricity)fz=fw-orbit.periapsis.altitude/fy-planet.radius/fy;local fA=""if orbit.periapsis.altitude<=0 then fA='redout'end;cy[#cy+1]=e([[<ellipse class="%s line" cx="%f" cy="%f" rx="%f" ry="%f"/>]],fA,fr+ft/2+fz+fu,fs+ft/2+fu,fw,fx)cy[#cy+1]=e('<circle cx="%f" cy="%f" r="%f" stroke="white" stroke-width="3" fill="blue" />',fr+ft/2+fu,fs+ft/2+fu,planet.radius/fy)end;if orbit.apoapsis~=nil and orbit.apoapsis.speed<MaxGameVelocity and orbit.apoapsis.speed>1 then cy[#cy+1]=e([[<line class="pdim op30 linethick" x1="%f" y1="%f" x2="%f" y2="%f"/>]],c2-35,c3-5,fr+ft/2+fw+fz,c3-5)cy[#cy+1]=e([[<text x="%f" y="%f">Apoapsis</text>]],c2,c3)c3=c3+fv;local dE,dF=getDistanceDisplayString(orbit.apoapsis.altitude)cy[#cy+1]=e([[<text x="%f" y="%f">%s</text>]],c2,c3,dE..dF)c3=c3+fv;cy[#cy+1]=e([[<text x="%f" y="%f">%s</text>]],c2,c3,FormatTimeString(orbit.timeToApoapsis))c3=c3+fv;cy[#cy+1]=e([[<text x="%f" y="%f">%s</text>]],c2,c3,getSpeedDisplayString(orbit.apoapsis.speed))end;c3=fs+ft/2+5+fu;c2=fr-fr/2+10+fu;if orbit.periapsis~=nil and orbit.periapsis.speed<MaxGameVelocity and orbit.periapsis.speed>1 then cy[#cy+1]=e([[<line class="pdim op30 linethick" x1="%f" y1="%f" x2="%f" y2="%f"/>]],c2+35,c3-5,fr+ft/2-fw+fz,c3-5)cy[#cy+1]=e([[<text x="%f" y="%f">Periapsis</text>]],c2,c3)c3=c3+fv;local dE,dF=getDistanceDisplayString(orbit.periapsis.altitude)cy[#cy+1]=e([[<text x="%f" y="%f">%s</text>]],c2,c3,dE..dF)c3=c3+fv;cy[#cy+1]=e([[<text x="%f" y="%f">%s</text>]],c2,c3,FormatTimeString(orbit.timeToPeriapsis))c3=c3+fv;cy[#cy+1]=e([[<text x="%f" y="%f">%s</text>]],c2,c3,getSpeedDisplayString(orbit.periapsis.speed))end;cy[#cy+1]=e([[<text class="txtorbbig" x="%f" y="%d">%s</text>]],fr+ft/2+fu,20+fu,planet.name)if orbit.period~=nil and orbit.periapsis~=nil and orbit.apoapsis~=nil and orbit.apoapsis.speed>1 then local fB=orbit.timeToApoapsis/orbit.period*2*math.pi;local fC=fw*math.cos(fB)local fD=fx*math.sin(fB)cy[#cy+1]=e('<circle cx="%f" cy="%f" r="5" stroke="white" stroke-width="3" fill="white" />',fr+ft/2+fC+fz+fu,fs+ft/2+fD+fu)end;cy[#cy+1]=[[</g>]]end end;function getDistanceDisplayString(ae)local fE=ae>100000;local bI,dF=""if fE then bI,dF=round(ae/1000/200,1),"SU"elseif ae<1000 then bI,dF=round(ae,1),"m"else bI,dF=round(ae/1000,1),"Km"end;return bI,dF end;function getDistanceDisplayString2(ae)local fE=ae>100000;local bI,dF=""if fE then bI,dF=round(ae/1000/200,2)," SU"elseif ae<1000 then bI,dF=round(ae,2)," M"else bI,dF=round(ae/1000,2)," KM"end;return bI,dF end;function getSpeedDisplayString(bX)return d(round(bX*3.6,0)+0.5).." km/h"end;function FormatTimeString(fF)local fG=0;local fH=0;local fI=0;if fF<60 then fF=d(fF)elseif fF<3600 then fG=d(fF/60)fF=d(fF%60)elseif fF<86400 then fH=d(fF/3600)fG=d(fF%3600/60)else fI=d(fF/86400)fH=d(fF%86400/3600)end;if fI>0 then return fI.."d "..fH.."h "elseif fH>0 then return fH.."h "..fG.."m "elseif fG>0 then return fG.."m "..fF.."s"elseif fF>0 then return fF.."s"else return"0s"end end;function getMagnitudeInDirection(dx,fJ)dx=vec3(dx)fJ=vec3(fJ):normalize()local bI=dx*fJ;return bI.x+bI.y+bI.z end;function UpdateAutopilotTarget()if AutopilotTargetIndex==0 then AutopilotTargetName="None"a6=nil;CustomTarget=nil;return true end;local fK=AtlasOrdered[AutopilotTargetIndex].index;local fL=b2[0][fK]if fL.center then AutopilotTargetName=fL.name;a6=b8[0][fK]if CustomTarget~=nil then if j()==0 then if system.updateData(widgetMaxBrakeTimeText,widgetMaxBrakeTime)~=1 then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;if system.updateData(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)~=1 then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;if system.updateData(widgetCurBrakeTimeText,widgetCurBrakeTime)~=1 then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;if system.updateData(widgetCurBrakeDistanceText,widgetCurBrakeDistance)~=1 then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;if system.updateData(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)~=1 then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;if system.updateData(widgetMaxMassText,widgetMaxMass)~=1 then system.addDataToWidget(widgetMaxMassText,widgetMaxMass)end;if system.updateData(widgetTravelTimeText,widgetTravelTime)~=1 then system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)end;if system.updateData(widgetTargetOrbitText,widgetTargetOrbit)~=1 then system.addDataToWidget(widgetTargetOrbitText,widgetTargetOrbit)end end;CustomTarget=nil else CustomTarget=fL;for _,bH in pairs(b8[0])do if bH.name==CustomTarget.planetname then a6=bH;AutopilotTargetName=CustomTarget.name;break end end;if system.updateData(widgetMaxMassText,widgetMaxMass)~=1 then system.addDataToWidget(widgetMaxMassText,widgetMaxMass)end;if system.updateData(widgetTravelTimeText,widgetTravelTime)~=1 then system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)end end;if CustomTarget==nil then AutopilotTargetCoords=vec3(a6.center)else AutopilotTargetCoords=CustomTarget.position end;if a6.planetname~="Space"then if a6.hasAtmosphere then AutopilotTargetOrbit=math.floor(a6.radius*(TargetOrbitRadius-1)+a6.noAtmosphericDensityAltitude)else AutopilotTargetOrbit=math.floor(a6.radius*(TargetOrbitRadius-1)+a6.surfaceMaxAltitude)end else AutopilotTargetOrbit=1000 end;if CustomTarget~=nil and CustomTarget.planetname=="Space"then AutopilotEndSpeed=0 else _,AutopilotEndSpeed=bb(a6):escapeAndOrbitalSpeed(AutopilotTargetOrbit)end;AutopilotPlanetGravity=0;AutopilotAccelerating=false;AutopilotBraking=false;AutopilotCruising=false;Autopilot=false;AutopilotRealigned=false;AutopilotStatus="Aligning"return true end;function IncrementAutopilotTargetIndex()AutopilotTargetIndex=AutopilotTargetIndex+1;if AutopilotTargetIndex>#AtlasOrdered then AutopilotTargetIndex=0 end;if AutopilotTargetIndex==0 then UpdateAutopilotTarget()else local fK=AtlasOrdered[AutopilotTargetIndex].index;local fL=b2[0][fK]if fL.name=="Space"then IncrementAutopilotTargetIndex()else UpdateAutopilotTarget()end end end;function DecrementAutopilotTargetIndex()AutopilotTargetIndex=AutopilotTargetIndex-1;if AutopilotTargetIndex<0 then AutopilotTargetIndex=#AtlasOrdered end;if AutopilotTargetIndex==0 then UpdateAutopilotTarget()else local fK=AtlasOrdered[AutopilotTargetIndex].index;local fL=b2[0][fK]if fL.name=="Space"then DecrementAutopilotTargetIndex()else UpdateAutopilotTarget()end end end;function GetAutopilotMaxMass()local fM=LastMaxBrakeInAtmo/a6:getGravity(a6.center+vec3(0,0,1)*a6.radius):len()return fM end;function GetAutopilotTravelTime()if not Autopilot then if CustomTarget==nil or CustomTarget.planetname~=planet.name then AutopilotDistance=(a6.center-vec3(core.getConstructWorldPos())):len()else AutopilotDistance=(CustomTarget.position-vec3(core.getConstructWorldPos())):len()end end;local bf=core.getWorldVelocity()local bX=vec3(bf):len()local fN=unit.getThrottle()/100;if AtmoSpeedAssist then fN=z end;local fO,fP=b9.computeDistanceAndTime(vec3(bf):len(),MaxGameVelocity,n(),Nav:maxForceForward()*fN,warmup,0)local a2,a3;if not TurnBurn then a2,a3=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else a2,a3=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;local _,fQ;if not TurnBurn and bX>0 then _,fQ=GetAutopilotBrakeDistanceAndTime(bX)else _,fQ=GetAutopilotTBBrakeDistanceAndTime(bX)end;local fR=0;local fS=0;if AutopilotCruising or not Autopilot and bX>5 then fS=b9.computeTravelTime(bX,0,AutopilotDistance)elseif a2+fO<AutopilotDistance then fR=AutopilotDistance-(a2+fO)fS=b9.computeTravelTime(8333.0556,0,fR)else local fT=(AutopilotDistance-a2)/fO;fO=AutopilotDistance-a2;fP=fP*fT end;if CustomTarget~=nil and CustomTarget.planetname==planet.name and not Autopilot then return fS elseif AutopilotBraking then return fQ elseif AutopilotCruising then return fS+fQ else return fP+a3+fS end end;function GetAutopilotBrakeDistanceAndTime(bX)if not ao then RefreshLastMaxBrake()return b9.computeDistanceAndTime(bX,AutopilotEndSpeed,n(),0,0,LastMaxBrake-AutopilotPlanetGravity*n())else if LastMaxBrakeInAtmo and LastMaxBrakeInAtmo>0 then return b9.computeDistanceAndTime(bX,AutopilotEndSpeed,n(),0,0,LastMaxBrakeInAtmo-AutopilotPlanetGravity*n())else return 0,0 end end end;function GetAutopilotTBBrakeDistanceAndTime(bX)RefreshLastMaxBrake()return b9.computeDistanceAndTime(bX,AutopilotEndSpeed,n(),Nav:maxForceForward(),warmup,LastMaxBrake-AutopilotPlanetGravity*n())end;function hoverDetectGround()local fU=-1;local fV=-1;if vBooster then fU=vBooster.distance()end;if hover then fV=hover.distance()end;if fU~=-1 and fV~=-1 then if fU<fV then return fU else return fV end elseif fU~=-1 then return fU elseif fV~=-1 then return fV else return-1 end end;function AboveGroundLevel()local fW=-1;local fX=hoverDetectGround()if telemeter_1 then fW=telemeter_1.getDistance()end;if fX~=-1 and fW~=-1 then if fX<fW then return fX else return fW end elseif fX~=-1 then return fX else return fW end end;function tablelength(fY)local fZ=0;for _ in pairs(fY)do fZ=fZ+1 end;return fZ end;function BeginProfile(f_)ProfileTimeStart=system.getTime()end;function EndProfile(f_)local g0=system.getTime()-ProfileTimeStart;ProfileTimeSum=ProfileTimeSum+g0;ProfileCount=ProfileCount+1;if g0>ProfileTimeMax then ProfileTimeMax=g0 end;if g0<ProfileTimeMin then ProfileTimeMin=g0 end end;function ResetProfiles()ProfileTimeMin=9999;ProfileTimeMax=0;ProfileCount=0;ProfileTimeSum=0 end;function ReportProfiling()local g1=ProfileTimeSum;local g2=ProfileTimeSum/ProfileCount;local g3=ProfileTimeMin;local g4=ProfileTimeMax;local g5=ProfileCount;c(e("SUM: %.4f AVG: %.4f MIN: %.4f MAX: %.4f CNT: %d",g1,g2,g3,g4,g5))end;function updateWeapons()if weapon then if WeaponPanelID==nil and(radarPanelID~=nil or GearExtended)then _autoconf.displayCategoryPanel(weapon,weapon_size,L_TEXT("ui_lua_widget_weapon", "Weapons"),"weapon",true)WeaponPanelID=_autoconf.panels[_autoconf.panels_size]elseif WeaponPanelID~=nil and radarPanelID==nil and not GearExtended then system.destroyWidgetPanel(WeaponPanelID)WeaponPanelID=nil end end end;function updateRadar()if radar_1 then local g6=radar_1.getEntries()local g7=radar_1.getData()local g8=ConvertResolutionX(1770)local g9=ConvertResolutionY(330)if#g6>0 then local ga=g7:find('identifiedConstructs":%[%]')if ga==nil and perisPanelID==nil then ah=1;ToggleRadarPanel()end;if ga~=nil and perisPanelID~=nil then ToggleRadarPanel()end;if radarPanelID==nil then ToggleRadarPanel()end;af=e([[<text class="pbright txtbig txtmid" x="%d" y="%d">Radar: %i contacts</text>]],g8,g9,#g6)local gb={}for bG,bH in pairs(g6)do if radar_1.hasMatchingTransponder(bH)==1 then table.insert(gb,bH)end end;if#gb>0 then local c3=ConvertResolutionY(15)local c2=ConvertResolutionX(1370)af=e([[%s<text class="pbright txtbig txtmid" x="%d" y="%d">Friendlies In Range</text>]],af,c2,c3)for bG,bH in pairs(gb)do c3=c3+20;af=e([[%s<text class="pdim txtmid" x="%d" y="%d">%s</text>]],af,c2,c3,radar_1.getConstructName(bH))end end else local gc;gc=g7:find('worksInEnvironment":false')if gc then af=e([[
<text class="pbright txtbig txtmid" x="%d" y="%d">Radar: Jammed</text>]],g8,g9)else af=e([[
<text class="pbright txtbig txtmid" x="%d" y="%d">Radar: No Contacts</text>]],g8,g9)end;if radarPanelID~=nil then ah=0;ToggleRadarPanel()end end end end;function DisplayMessage(cy,dE)if dE~="empty"then cy[#cy+1]=[[<text class="msg" x="50%%" y="310" >]]for gd in string.gmatch(dE,"([^\n]+)")do cy[#cy+1]=e([[<tspan x="50%%" dy="35">%s</tspan>]],gd)end;cy[#cy+1]=[[</text>]]end;if ad~=0 then unit.setTimer("msgTick",ad)ad=0 end end;function updateDistance()local bQ=system.getTime()local bf=vec3(core.getWorldVelocity())local d_=vec3(bf):len()local ge=bQ-ar;if d_>1.38889 then d_=d_/1000;local gf=d_*(bQ-ar)TotalDistanceTravelled=TotalDistanceTravelled+gf;a7=a7+gf end;a8=a8+ge;TotalFlightTime=TotalFlightTime+ge;ar=bQ end;function composeAxisAccelerationFromTargetSpeedV(gg,gh)local gi=vec3()local gj=vec3()if gg==axisCommandId.longitudinal then gi=vec3(core.getConstructOrientationForward())gj=vec3(core.getConstructWorldOrientationForward())elseif gg==axisCommandId.vertical then gi=vec3(core.getConstructOrientationUp())gj=vec3(core.getConstructWorldOrientationUp())elseif gg==axisCommandId.lateral then gi=vec3(core.getConstructOrientationRight())gj=vec3(core.getConstructWorldOrientationRight())else return vec3()end;local gk=vec3(core.getWorldGravity())local gl=gk:dot(gj)local gm=vec3(core.getWorldAirFrictionAcceleration())local gn=gm:dot(gj)local go=vec3(core.getVelocity())local gp=go:dot(gi)local gq=gh*constants.kph2m;if targetSpeedPID2==nil then targetSpeedPID2=pid.new(10,0,10.0)end;targetSpeedPID2:inject(gq-gp)local gr=targetSpeedPID2:get()local gs=(gr-gn-gl)*gj;return gs end;function composeAxisAccelerationFromTargetSpeed(gg,gh)local gi=vec3()local gj=vec3()if gg==axisCommandId.longitudinal then gi=vec3(core.getConstructOrientationForward())gj=vec3(core.getConstructWorldOrientationForward())elseif gg==axisCommandId.vertical then gi=vec3(core.getConstructOrientationUp())gj=vec3(core.getConstructWorldOrientationUp())elseif gg==axisCommandId.lateral then gi=vec3(core.getConstructOrientationRight())gj=vec3(core.getConstructWorldOrientationRight())else return vec3()end;local gk=vec3(core.getWorldGravity())local gl=gk:dot(gj)local gm=vec3(core.getWorldAirFrictionAcceleration())local gn=gm:dot(gj)local go=vec3(core.getVelocity())local gp=go:dot(gi)local gq=gh*constants.kph2m;if targetSpeedPID==nil then targetSpeedPID=pid.new(10,0,10.0)end;targetSpeedPID:inject(gq-gp)local gr=targetSpeedPID:get()local gs=(gr-gn-gl)*gj;return gs end;function Atlas()return{[0]={[0]={GM=0,bodyId=0,center={x=0,y=0,z=0},name='Space',planetarySystemId=0,radius=0,hasAtmosphere=false,gravity=0,noAtmosphericDensityAltitude=0,surfaceMaxAltitude=0},[2]={name="Alioth",description="Alioth is the planet selected by the arkship for landfall; it is a typical goldilocks planet where humanity may rebuild in the coming decades. The arkship geological survey reports mountainous regions alongside deep seas and lush forests. This is where it all starts.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9401,atmosphericEngineMaxAltitude=5580,biosphere="Forest",classification="Mesoplanet",bodyId=2,GM=157470826617,gravity=1.0082568597356114,fullAtmosphericDensityMaxAltitude=-10,habitability="High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=6272,numSatellites=2,positionFromSun=2,center={x=-8,y=-8,z=-126303},radius=126067.8984375,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=3410,surfaceArea=199718780928,surfaceAverageAltitude=200,surfaceMaxAltitude=1100,surfaceMinAltitude=-330,systemZone="High",territories=259472,type="Planet",waterLevel=0,planetarySystemId=0},[21]={name="Alioth Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=21,GM=2118960000,gravity=0.24006116402380084,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=457933,y=-1509011,z=115524},radius=30000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=11309733888,surfaceAverageAltitude=140,surfaceMaxAltitude=200,surfaceMinAltitude=10,systemZone=nil,territories=14522,type="",waterLevel=nil,planetarySystemId=0},[22]={name="Alioth Moon 4",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=22,GM=2165833514,gravity=0.2427018259886451,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-1692694,y=729681,z=-411464},radius=30330,safeAreaEdgeAltitude=500000,size="L",spaceEngineMinAltitude=0,surfaceArea=11559916544,surfaceAverageAltitude=-15,surfaceMaxAltitude=-5,surfaceMinAltitude=-50,systemZone=nil,territories=14522,type="",waterLevel=nil,planetarySystemId=0},[5]={name="Feli",description="Feli is easily identified by its massive and deep crater. Outside of the crater, the arkship geological survey reports a fairly bland and uniform planet, it also cannot explain the existence of the crater. Feli is particular for having an extremely small atmosphere, allowing life to develop in the deeper areas of its crater but limiting it drastically on the actual surface.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.5488,atmosphericEngineMaxAltitude=66725,biosphere="Barren",classification="Mesoplanet",bodyId=5,GM=16951680000,gravity=0.4801223280476017,fullAtmosphericDensityMaxAltitude=30,habitability="Low",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=78500,numSatellites=1,positionFromSun=5,center={x=-43534464,y=22565536,z=-48934464},radius=41800,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=42800,surfaceArea=21956466688,surfaceAverageAltitude=18300,surfaceMaxAltitude=18500,surfaceMinAltitude=46,systemZone="Low",territories=27002,type="Planet",waterLevel=nil,planetarySystemId=0},[50]={name="Feli Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=50,GM=499917600,gravity=0.11202853997062348,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-43902841.78,y=22261034.7,z=-48862386},radius=14000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=2463008768,surfaceAverageAltitude=800,surfaceMaxAltitude=900,surfaceMinAltitude=0,systemZone=nil,territories=3002,type="",waterLevel=nil,planetarySystemId=0},[120]={name="Ion",description="Ion is nothing more than an oversized ice cube frozen through and through. It is a largely inhospitable planet due to its extremely low temperatures. The arkship geological survey reports extremely rough mountainous terrain with little habitable land.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9522,atmosphericEngineMaxAltitude=10480,biosphere="Ice",classification="Hypopsychroplanet",bodyId=120,GM=7135606629,gravity=0.36009174603570127,fullAtmosphericDensityMaxAltitude=-30,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=17700,numSatellites=2,positionFromSun=12,center={x=2865536.7,y=-99034464,z=-934462.02},radius=44950,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=6410,surfaceArea=25390383104,surfaceAverageAltitude=500,surfaceMaxAltitude=1300,surfaceMinAltitude=250,systemZone="Average",territories=32672,type="Planet",waterLevel=nil,planetarySystemId=0},[121]={name="Ion Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=121,GM=106830900,gravity=0.08802242599860607,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=2472916.8,y=-99133747,z=-1133582.8},radius=11000,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=0,surfaceArea=1520530944,surfaceAverageAltitude=100,surfaceMaxAltitude=200,surfaceMinAltitude=3,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[122]={name="Ion Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=122,GM=176580000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=2995424.5,y=-99275010,z=-1378480.7},radius=15000,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=-1900,surfaceMaxAltitude=-1400,surfaceMinAltitude=-2100,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[9]={name="Jago",description="Jago is a water planet. The large majority of the planet's surface is covered by large oceans dotted by small areas of landmass across the planet. The arkship geological survey reports deep seas across the majority of the planet with sub 15 percent coverage of solid ground.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9835,atmosphericEngineMaxAltitude=9695,biosphere="Water",classification="Mesoplanet",bodyId=9,GM=18606274330,gravity=0.5041284298678057,fullAtmosphericDensityMaxAltitude=-90,habitability="Very High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=10900,numSatellites=0,positionFromSun=9,center={x=-94134462,y=12765534,z=-3634464},radius=61590,safeAreaEdgeAltitude=500000,size="XL",spaceEngineMinAltitude=5900,surfaceArea=47668367360,surfaceAverageAltitude=0,surfaceMaxAltitude=1200,surfaceMinAltitude=-500,systemZone="Very High",territories=60752,type="Planet",waterLevel=0,planetarySystemId=0},[100]={name="Lacobus",description="Lacobus is an ice planet that also features large bodies of water. The arkship geological survey reports deep oceans alongside a frozen and rough mountainous environment. Lacobus seems to feature regional geothermal activity allowing for the presence of water on the surface.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.7571,atmosphericEngineMaxAltitude=11120,biosphere="Ice",classification="Psychroplanet",bodyId=100,GM=13975172474,gravity=0.45611622622739767,fullAtmosphericDensityMaxAltitude=-20,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=12510,numSatellites=3,positionFromSun=10,center={x=98865536,y=-13534464,z=-934461.99},radius=55650,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=6790,surfaceArea=38917074944,surfaceAverageAltitude=800,surfaceMaxAltitude=1660,surfaceMinAltitude=250,systemZone="Average",territories=50432,type="Planet",waterLevel=0,planetarySystemId=0},[102]={name="Lacobus Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=102,GM=444981600,gravity=0.14403669598391783,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=99180968,y=-13783862,z=-926156.4},radius=18000,safeAreaEdgeAltitude=500000,size="XL",spaceEngineMinAltitude=0,surfaceArea=4071504128,surfaceAverageAltitude=150,surfaceMaxAltitude=300,surfaceMinAltitude=10,systemZone=nil,territories=5072,type="",waterLevel=nil,planetarySystemId=0},[103]={name="Lacobus Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=103,GM=211503600,gravity=0.11202853997062348,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=99250052,y=-13629215,z=-1059341.4},radius=14000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2463008768,surfaceAverageAltitude=-1380,surfaceMaxAltitude=-1280,surfaceMinAltitude=-1880,systemZone=nil,territories=3002,type="",waterLevel=nil,planetarySystemId=0},[101]={name="Lacobus Moon 3",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=101,GM=264870000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=98905288.17,y=-13950921.1,z=-647589.53},radius=15000,safeAreaEdgeAltitude=500000,size="L",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=500,surfaceMaxAltitude=820,surfaceMinAltitude=3,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[1]={name="Madis",description="Madis is a barren wasteland of a rock; it sits closest to the sun and temperatures reach extreme highs during the day. The arkship geological survey reports long rocky valleys intermittently separated by small ravines.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.8629,atmosphericEngineMaxAltitude=7165,biosphere="Barren",classification="hyperthermoplanet",bodyId=1,GM=6930729684,gravity=0.36009174603570127,fullAtmosphericDensityMaxAltitude=220,habitability="Low",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=8050,numSatellites=3,positionFromSun=1,center={x=17465536,y=22665536,z=-34464},radius=44300,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=4480,surfaceArea=24661377024,surfaceAverageAltitude=750,surfaceMaxAltitude=850,surfaceMinAltitude=670,systemZone="Low",territories=30722,type="Planet",waterLevel=nil,planetarySystemId=0},[10]={name="Madis Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=10,GM=78480000,gravity=0.08002039003323584,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=17448118.224,y=22966846.286,z=143078.82},radius=10000,safeAreaEdgeAltitude=500000,size="XL",spaceEngineMinAltitude=0,surfaceArea=1256637056,surfaceAverageAltitude=210,surfaceMaxAltitude=420,surfaceMinAltitude=0,systemZone=nil,territories=1472,type="",waterLevel=nil,planetarySystemId=0},[11]={name="Madis Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=11,GM=237402000,gravity=0.09602446196397631,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=17194626,y=22243633.88,z=-214962.81},radius=12000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=1809557376,surfaceAverageAltitude=-700,surfaceMaxAltitude=300,surfaceMinAltitude=-2900,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[12]={name="Madis Moon 3",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=12,GM=265046609,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=17520614,y=22184730,z=-309989.99},radius=15000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=700,surfaceMaxAltitude=1100,surfaceMinAltitude=0,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[26]={name="Sanctuary",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9666,atmosphericEngineMaxAltitude=6935,biosphere="",classification="",bodyId=26,GM=68234043600,gravity=1.0000000427743831,fullAtmosphericDensityMaxAltitude=-30,habitability="",hasAtmosphere=true,isSanctuary=true,noAtmosphericDensityAltitude=7800,numSatellites=0,positionFromSun=0,center={x=-1404835,y=562655,z=-285074},radius=83400,safeAreaEdgeAltitude=0,size="L",spaceEngineMinAltitude=4230,surfaceArea=87406149632,surfaceAverageAltitude=80,surfaceMaxAltitude=500,surfaceMinAltitude=-60,systemZone=nil,territories=111632,type="",waterLevel=0,planetarySystemId=0},[6]={name="Sicari",description="Sicari is a typical desert planet; it has survived for millenniums and will continue to endure. While not the most habitable of environments it remains a relatively untouched and livable planet of the Alioth sector. The arkship geological survey reports large flatlands alongside steep plateaus.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.897,atmosphericEngineMaxAltitude=7725,biosphere="Desert",classification="Mesoplanet",bodyId=6,GM=10502547741,gravity=0.4081039739797361,fullAtmosphericDensityMaxAltitude=-625,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=8770,numSatellites=0,positionFromSun=6,center={x=52765536,y=27165538,z=52065535},radius=51100,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=4480,surfaceArea=32813432832,surfaceAverageAltitude=130,surfaceMaxAltitude=220,surfaceMinAltitude=50,systemZone="Average",territories=41072,type="Planet",waterLevel=nil,planetarySystemId=0},[7]={name="Sinnen",description="Sinnen is a an empty and rocky hell. With no atmosphere to speak of it is one of the least hospitable planets in the sector. The arkship geological survey reports mostly flatlands alongside deep ravines which look to have once been riverbeds. This planet simply looks to have dried up and died, likely from solar winds.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9226,atmosphericEngineMaxAltitude=10335,biosphere="Desert",classification="Mesoplanet",bodyId=7,GM=13033380591,gravity=0.4401121421448438,fullAtmosphericDensityMaxAltitude=-120,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=11620,numSatellites=1,positionFromSun=7,center={x=58665538,y=29665535,z=58165535},radius=54950,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=6270,surfaceArea=37944188928,surfaceAverageAltitude=317,surfaceMaxAltitude=360,surfaceMinAltitude=23,systemZone="Average",territories=48002,type="Planet",waterLevel=nil,planetarySystemId=0},[70]={name="Sinnen Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=70,GM=396912600,gravity=0.1360346539426409,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=58969616,y=29797945,z=57969449},radius=17000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=3631681280,surfaceAverageAltitude=-2050,surfaceMaxAltitude=-1950,surfaceMinAltitude=-2150,systemZone=nil,territories=4322,type="",waterLevel=nil,planetarySystemId=0},[110]={name="Symeon",description="Symeon is an ice planet mysteriously split at the equator by a band of solid desert. Exactly how this phenomenon is possible is unclear but some sort of weather anomaly may be responsible. The arkship geological survey reports a fairly diverse mix of flat-lands alongside mountainous formations.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9559,atmosphericEngineMaxAltitude=6920,biosphere="Ice, Desert",classification="Hybrid",bodyId=110,GM=9204742375,gravity=0.3920998898971822,fullAtmosphericDensityMaxAltitude=-30,habitability="High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=7800,numSatellites=0,positionFromSun=11,center={x=14165536,y=-85634465,z=-934464.3},radius=49050,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=4230,surfaceArea=30233462784,surfaceAverageAltitude=39,surfaceMaxAltitude=450,surfaceMinAltitude=126,systemZone="High",territories=38882,type="Planet",waterLevel=nil,planetarySystemId=0},[4]={name="Talemai",description="Talemai is a planet in the final stages of an Ice Age. It seems likely that the planet was thrown into tumult by a cataclysmic volcanic event which resulted in its current state. The arkship geological survey reports large mountainous regions across the entire planet.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.8776,atmosphericEngineMaxAltitude=9685,biosphere="Barren",classification="Psychroplanet",bodyId=4,GM=14893847582,gravity=0.4641182439650478,fullAtmosphericDensityMaxAltitude=-78,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=10890,numSatellites=3,positionFromSun=4,center={x=-13234464,y=55765536,z=465536},radius=57500,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=5890,surfaceArea=41547563008,surfaceAverageAltitude=580,surfaceMaxAltitude=610,surfaceMinAltitude=520,systemZone="Average",territories=52922,type="Planet",waterLevel=nil,planetarySystemId=0},[42]={name="Talemai Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=42,GM=264870000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-13058408,y=55781856,z=740177.76},radius=15000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=720,surfaceMaxAltitude=850,surfaceMinAltitude=0,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[40]={name="Talemai Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=40,GM=141264000,gravity=0.09602446196397631,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-13503090,y=55594325,z=769838.64},radius=12000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=1809557376,surfaceAverageAltitude=250,surfaceMaxAltitude=450,surfaceMinAltitude=0,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[41]={name="Talemai Moon 3",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=41,GM=106830900,gravity=0.08802242599860607,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-12800515,y=55700259,z=325207.84},radius=11000,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=0,surfaceArea=1520530944,surfaceAverageAltitude=190,surfaceMaxAltitude=400,surfaceMinAltitude=0,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[8]={name="Teoma",description="[REDACTED] The arkship geological survey [REDACTED]. This planet should not be here.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.7834,atmosphericEngineMaxAltitude=5580,biosphere="Forest",classification="Mesoplanet",bodyId=8,GM=18477723600,gravity=0.48812434578525177,fullAtmosphericDensityMaxAltitude=15,habitability="High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=6280,numSatellites=0,positionFromSun=8,center={x=80865538,y=54665536,z=-934463.94},radius=62000,safeAreaEdgeAltitude=500000,size="L",spaceEngineMinAltitude=3420,surfaceArea=48305131520,surfaceAverageAltitude=700,surfaceMaxAltitude=1100,surfaceMinAltitude=-200,systemZone="High",territories=60752,type="Planet",waterLevel=0,planetarySystemId=0},[3]={name="Thades",description="Thades is a scorched desert planet. Perhaps it was once teaming with life but now all that remains is ash and dust. The arkship geological survey reports a rocky mountainous planet bisected by a massive unnatural ravine; something happened to this planet.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.03552,atmosphericEngineMaxAltitude=32180,biosphere="Desert",classification="Thermoplanet",bodyId=3,GM=11776905000,gravity=0.49612641213015557,fullAtmosphericDensityMaxAltitude=150,habitability="Low",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=32800,numSatellites=2,positionFromSun=3,center={x=29165536,y=10865536,z=65536},radius=49000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=21400,surfaceArea=30171856896,surfaceAverageAltitude=13640,surfaceMaxAltitude=13690,surfaceMinAltitude=370,systemZone="Low",territories=38882,type="Planet",waterLevel=nil,planetarySystemId=0},[30]={name="Thades Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=30,GM=211564034,gravity=0.11202853997062348,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=29214402,y=10907080.695,z=433858.2},radius=14000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2463008768,surfaceAverageAltitude=60,surfaceMaxAltitude=300,surfaceMinAltitude=0,systemZone=nil,territories=3002,type="",waterLevel=nil,planetarySystemId=0},[31]={name="Thades Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=31,GM=264870000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=29404193,y=10432768,z=19554.131},radius=15000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=70,surfaceMaxAltitude=350,surfaceMinAltitude=0,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0}}}end;function SetupAtlas()b2=Atlas()for bG,bH in pairs(b2[0])do if aG==nil or bH.center.x<aG then aG=bH.center.x end;if aH==nil or bH.center.x>aH then aH=bH.center.x end;if aI==nil or bH.center.y<aI then aI=bH.center.y end;if aJ==nil or bH.center.y>aJ then aJ=bH.center.y end end;b3=""local gt=1.1*(aH-aG)/1920;local gu=1.4*(aJ-aI)/1080;for bG,bH in pairs(b2[0])do local c2=960+bH.center.x/gt;local c3=540+bH.center.y/gu;b3=b3 ..'<circle cx="'..c2 ..'" cy="'..c3 ..'" r="'..bH.radius/gt*30 ..'" stroke="white" stroke-width="3" fill="blue" />'if not string.match(bH.name,"Moon")and not string.match(bH.name,"Sanctuary")and not string.match(bH.name,"Space")then b3=b3 .."<text x='"..c2 .."' y='"..c3+bH.radius/gt*30+20 .."' font-size='28' fill="..au.." text-anchor='middle' font-family='Montserrat'>"..bH.name.."</text>"end end;local cl=vec3(core.getConstructWorldPos())local c2=960+cl.x/gt;local c3=540+cl.y/gu;b3=b3 ..'<circle cx="'..c2 ..'" cy="'..c3 ..'" r="5" stroke="white" stroke-width="3" fill="red"/>'b3=b3 .."<text x='"..c2 .."' y='"..c3-50 .."' font-size='36' fill='darkred' text-anchor='middle' font-family='Bank' font-weight='bold'>You Are Here</text>"b3=b3 ..[[</svg>]]b4=gt;b5=gu;if screen_2 then screen_2.setHTML('<svg width="100%" height="100%" viewBox="0 0 1920 1080">'..b3)local cl=vec3(core.getConstructWorldPos())local c2=960+cl.x/gt;local c3=540+cl.y/gu;b3='<svg><circle cx="80" cy="80" r="5" stroke="white" stroke-width="3" fill="red"/>'b3=b3 .."<text x='80' y='105' font-size='18' fill="..au.." text-anchor='middle' font-family='Montserrat''>You Are Here</text></svg>"b6=screen_2.addContent((c2-80)/19.20,(c3-80)/10.80,b3)end end;function PlanetRef()local function gv(gw)return type(gw)=='number'end;local function gx(gw)return type(tonumber(gw))=='number'end;local function gy(gz)return type(gz)=='table'end;local function gA(gB)return type(gB)=='string'end;local function gC(bH)return gy(bH)and gv(bH.x and bH.y and bH.z)end;local function gD(gE)return gy(gE)and gv(gE.latitude and gE.longitude and gE.altitude and gE.bodyId and gE.systemId)end;local gF=math.pi/180;local gG=180/math.pi;local epsilon=1e-10;local q=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local cm='::pos{'..q..','..q..','..q..','..q..','..q..'}'local utils=require('cpml.utils')local vec3=require('cpml.vec3')local gH=utils.clamp;local function float_eq(cb,cc)if cb==0 then return math.abs(cc)<1e-09 end;if cc==0 then return math.abs(cb)<1e-09 end;return math.abs(cb-cc)<math.max(math.abs(cb),math.abs(cc))*epsilon end;local function gI(gw)local bI=string.gsub(string.reverse(e('%.4f',gw)),'^0*%.?','')return bI==''and'0'or string.reverse(bI)end;local function gJ(gK)if gC(gK)then return e('{x=%.3f,y=%.3f,z=%.3f}',gK.x,gK.y,gK.z)end;if gy(gK)and not getmetatable(gK)then local gL={}local gM=next(gK)if type(gM)=='nil'or gM==1 then gL=gK else for bG,bH in pairs(gK)do local ek=gJ(bH)if type(bG)=='number'then table.insert(gL,e('[%s]=%s',bG,ek))else table.insert(gL,e('%s=%s',bG,ek))end end end;return e('{%s}',table.concat(gL,','))end;if gA(gK)then return e("'%s'",gK:gsub("'",[[\']]))end;return tostring(gK)end;local gN={}gN.__index=gN;gN.__tostring=function(gK,gO)local gP={}for bG in pairs(gK)do table.insert(gP,bG)end;table.sort(gP)local gL={}for _,bG in ipairs(gP)do local ek=gJ(gK[bG])if type(bG)=='number'then table.insert(gL,e('[%s]=%s',bG,ek))else table.insert(gL,e('%s=%s',bG,ek))end end;if gO then return e('%s%s',gO,table.concat(gL,',\n'..gO))end;return e('{%s}',table.concat(gL,','))end;gN.__eq=function(gQ,gR)return gQ.planetarySystemId==gR.planetarySystemId and gQ.bodyId==gR.bodyId and float_eq(gQ.radius,gR.radius)and float_eq(gQ.center.x,gR.center.x)and float_eq(gQ.center.y,gR.center.y)and float_eq(gQ.center.z,gR.center.z)and float_eq(gQ.GM,gR.GM)end;local function gS(cn,co,gT,ce,gU)assert(gx(cn),'Argument 1 (planetarySystemId) must be a number:'..type(cn))assert(gx(co),'Argument 2 (bodyId) must be a number:'..type(co))assert(gx(gT),'Argument 3 (radius) must be a number:'..type(gT))assert(gy(ce),'Argument 4 (worldCoordinates) must be a array or vec3.'..type(ce))assert(gx(gU),'Argument 5 (GM) must be a number:'..type(gU))return setmetatable({planetarySystemId=tonumber(cn),bodyId=tonumber(co),radius=tonumber(gT),center=vec3(ce),GM=tonumber(gU)},gN)end;local MapPosition={}MapPosition.__index=MapPosition;MapPosition.__tostring=function(gV)return e('::pos{%d,%d,%s,%s,%s}',gV.systemId,gV.bodyId,gI(gV.latitude*gG),gI(gV.longitude*gG),gI(gV.altitude))end;MapPosition.__eq=function(gQ,gR)return gQ.bodyId==gR.bodyId and gQ.systemId==gR.systemId and float_eq(gQ.latitude,gR.latitude)and float_eq(gQ.altitude,gR.altitude)and(float_eq(gQ.longitude,gR.longitude)or float_eq(gQ.latitude,math.pi/2)or float_eq(gQ.latitude,-math.pi/2))end;local function gW(gX,co,ci,cj,ch)local cn=gX;if gA(gX)and not cj and not ch and not co and not ci then cn,co,ci,cj,ch=string.match(gX,cm)assert(cn,'Argument 1 (position string) is malformed.')else assert(gx(cn),'Argument 1 (systemId) must be a number:'..type(cn))assert(gx(co),'Argument 2 (bodyId) must be a number:'..type(co))assert(gx(ci),'Argument 3 (latitude) must be in degrees:'..type(ci))assert(gx(cj),'Argument 4 (longitude) must be in degrees:'..type(cj))assert(gx(ch),'Argument 5 (altitude) must be in meters:'..type(ch))end;cn=tonumber(cn)co=tonumber(co)ci=tonumber(ci)cj=tonumber(cj)ch=tonumber(ch)if co==0 then return setmetatable({latitude=ci,longitude=cj,altitude=ch,bodyId=co,systemId=cn},MapPosition)end;return setmetatable({latitude=gF*gH(ci,-90,90),longitude=gF*(cj%360),altitude=ch,bodyId=co,systemId=cn},MapPosition)end;local gY={}gY.__index=gY;gY.__tostring=function(gK,gO)local gZ=gO and gO..' 'local g_={}local gP={}for bG in pairs(gK)do table.insert(gP,bG)end;table.sort(gP)for _,h0 in ipairs(gP)do bdy=gK[h0]local h1=gN.__tostring(bdy,gZ)if gO then table.insert(g_,e('[%s]={\n%s\n%s}',h0,h1,gO))else table.insert(g_,e(' [%s]=%s',h0,h1))end end;if gO then return e('\n%s%s%s',gO,table.concat(g_,',\n'..gO),gO)end;return e('{\n%s\n}',table.concat(g_,',\n'))end;local function h2(h3)local b2={}local pid;for _,bH in pairs(h3)do local cu=bH.planetarySystemId;if type(cu)~='number'then error('Invalid planetary system ID: '..tostring(cu))elseif pid and cu~=pid then error('Mismatch planetary system IDs: '..cu..' and '..pid)end;local h4=bH.bodyId;if type(h4)~='number'then error('Invalid body ID: '..tostring(h4))elseif b2[h4]then error('Duplicate body ID: '..tostring(h4))end;setmetatable(bH.center,getmetatable(vec3.unit_x))b2[h4]=setmetatable(bH,gN)pid=cu end;return setmetatable(b2,gY)end;b7={}local function h5(h3)return setmetatable({galaxyAtlas=h3 or{}},b7)end;b7.__index=function(gz,i)if type(i)=='number'then local system=gz.galaxyAtlas[i]return h2(system)end;return rawget(b7,i)end;b7.__pairs=function(gK)return function(gz,bG)local h6,nv=next(gz,bG)return h6,nv and h2(nv)end,gK.galaxyAtlas,nil end;b7.__tostring=function(gK)local h7={}for _,h8 in pairs(gK or{})do local h9=h8:getPlanetarySystemId()local ha=gY.__tostring(h8,' ')table.insert(h7,e(' [%s]={%s\n }',h9,ha))end;return e('{\n%s\n}\n',table.concat(h7,',\n'))end;b7.BodyParameters=gS;b7.MapPosition=gW;b7.PlanetarySystem=h2;function b7.createBodyParameters(hb,co,hc,hd,he,hf,hg)assert(gx(hb),'Argument 1 (planetarySystemId) must be a number:'..type(hb))assert(gx(co),'Argument 2 (bodyId) must be a number:'..type(co))assert(gx(hc),'Argument 3 (surfaceArea) must be a number:'..type(hc))assert(gy(hd),'Argument 4 (aPosition) must be an array or vec3:'..type(hd))assert(gy(he),'Argument 5 (verticalAtPosition) must be an array or vec3:'..type(he))assert(gx(hf),'Argument 6 (altitude) must be in meters:'..type(hf))assert(gx(hg),'Argument 7 (gravityAtPosition) must be number:'..type(hg))local gT=math.sqrt(hc/4/math.pi)local ae=gT+hf;local hh=vec3(hd)+ae*vec3(he)local gU=hg*ae*ae;return gS(hb,co,gT,hh,gU)end;b7.isMapPosition=gD;function b7:getPlanetarySystem(gX)if i==nil then i=0 end;if nv==nil then nv=0 end;local hb=gX;if gD(gX)then hb=gX.systemId end;if type(hb)=='number'then local system=self.galaxyAtlas[i]if system then if getmetatable(nv)~=gY then system=h2(system)end;return system end end end;function gY:castIntersections(hi,fJ,hj,hk)local hj=hj or function(fo)return 1.05*fo.radius end;local hl={}if hk then for _,i in ipairs(hk)do hl[i]=self[i]end else hk={}for bG,fo in pairs(self)do table.insert(hk,bG)hl[bG]=fo end end;local function hm(hn,ho)local hp=hl[hn].center-hi;local hq=hl[ho].center-hi;return hp:len()<hq:len()end;table.sort(hk,hm)local hr=fJ:normalize()for i,cu in ipairs(hk)do local fo=hl[cu]local hs=fo.center-hi;local gT=hj(fo)local ht=hs:dot(hr)local hu=ht^2-(hs:len2()-gT^2)if hu>=0 then local hv=math.sqrt(hu)local fm=ht+hv;local fn=ht-hv;if fn>0 then return fo,fm,fn elseif fm>0 then return fo,fm,nil end end end;return nil,nil,nil end;function gY:closestBody(hw)assert(type(hw)=='table','Invalid coordinates.')local hx,fo;local hy=vec3(hw)for _,hz in pairs(self)do local hA=(hz.center-hy):len2()if(not fo or hA<hx)and hz.name~="Space"then fo=hz;hx=hA end end;return fo end;function gY:convertToBodyIdAndWorldCoordinates(gX)local hB=gX;if gA(gX)then hB=gW(gX)end;if hB.bodyId==0 then return 0,vec3(hB.latitude,hB.longitude,hB.altitude)end;local hz=self:getBodyParameters(hB)if hz then return hB.bodyId,hz:convertToWorldCoordinates(hB)end end;function gY:getBodyParameters(gX)local co=gX;if gD(gX)then co=gX.bodyId end;assert(gx(co),'Argument 1 (bodyId) must be a number:'..type(co))return self[co]end;function gY:getPlanetarySystemId()local _,bH=next(self)return bH and bH.planetarySystemId end;function gN:convertToMapPosition(ce)assert(gy(ce),'Argument 1 (worldCoordinates) must be an array or vec3:'..type(ce))local cf=vec3(ce)if self.bodyId==0 then return setmetatable({latitude=cf.x,longitude=cf.y,altitude=cf.z,bodyId=0,systemId=self.planetarySystemId},MapPosition)end;local cg=cf-self.center;local ae=cg:len()local ch=ae-self.radius;local ci=0;local cj=0;if not float_eq(ae,0)then local ck=math.atan(cg.y,cg.x)cj=ck>=0 and ck or 2*math.pi+ck;ci=math.pi/2-math.acos(cg.z/ae)end;return setmetatable({latitude=ci,longitude=cj,altitude=ch,bodyId=self.bodyId,systemId=self.planetarySystemId},MapPosition)end;function gN:convertToWorldCoordinates(gX)local hB=gA(gX)and gW(gX)or gX;if hB.bodyId==0 then return vec3(hB.latitude,hB.longitude,hB.altitude)end;assert(gD(hB),'Argument 1 (mapPosition) is not an instance of "MapPosition".')assert(hB.systemId==self.planetarySystemId,'Argument 1 (mapPosition) has a different planetary system ID.')assert(hB.bodyId==self.bodyId,'Argument 1 (mapPosition) has a different planetary body ID.')local cp=math.cos(hB.latitude)return self.center+(self.radius+hB.altitude)*vec3(cp*math.cos(hB.longitude),cp*math.sin(hB.longitude),math.sin(hB.latitude))end;function gN:getAltitude(ce)return(vec3(ce)-self.center):len()-self.radius end;function gN:getDistance(ce)return(vec3(ce)-self.center):len()end;function gN:getGravity(ce)local hC=self.center-vec3(ce)local hD=hC:len2()return self.GM/hD*hC/math.sqrt(hD)end;return setmetatable(b7,{__call=function(_,...)return h5(...)end})end;function Keplers()local vec3=require('cpml.vec3')local PlanetRef=PlanetRef()local function gA(gB)return type(gB)=='string'end;local function gy(gz)return type(gz)=='table'end;local function float_eq(cb,cc)if cb==0 then return math.abs(cc)<1e-09 end;if cc==0 then return math.abs(cb)<1e-09 end;return math.abs(cb-cc)<math.max(math.abs(cb),math.abs(cc))*constants.epsilon end;Kepler={}Kepler.__index=Kepler;function Kepler:escapeAndOrbitalSpeed(ch)assert(self.body)local ae=ch+self.body.radius;if not float_eq(ae,0)then local orbit=math.sqrt(self.body.GM/ae)return math.sqrt(2)*orbit,orbit end;return nil,nil end;function Kepler:orbitalParameters(gX,bf)assert(self.body)assert(gy(gX)or gA(gX))assert(gy(bf))local cl=(gA(gX)or PlanetRef.isMapPosition(gX))and self.body:convertToWorldCoordinates(gX)or vec3(gX)local bH=vec3(bf)local hE=cl-self.body.center;local hq=bH:len2()local hF=hE:len()local hG=self.body.GM;local hH=((hq-hG/hF)*hE-hE:dot(bH)*bH)/hG;local cb=hG/(2*hG/hF-hq)local hI=hH:len()local hr=hH:normalize()local hJ=cb*(1-hI)local hK=cb*(1+hI)local hL=hJ*hr+self.body.center;local hM=hI<=1 and-hK*hr+self.body.center or nil;local hN=math.sqrt(cb*hG*(1-hI*hI))local hO=hM and 2*math.pi*math.sqrt(cb^3/hG)local hP=math.acos(hH:dot(hE)/(hI*hF))if hE:dot(bH)<0 then hP=-(hP-2*math.pi)end;local hQ=math.acos((math.cos(hP)+hI)/(1+hI*math.cos(hP)))local hR=hQ;if hR<0 then hR=hR+2*math.pi end;local hS=hR-hI*math.sin(hR)local hT=0;local hU=0;local hV=0;if hO~=nil then hT=hS/(2*math.pi/hO)hU=hO-hT;hV=hU+hO/2;if hP-math.pi>0 then hU=hT;hV=hU+hO/2 end;if hV>hO then hV=hV-hO end end;return{periapsis={position=hL,speed=hN/hJ,circularOrbitSpeed=math.sqrt(hG/hJ),altitude=hJ-self.body.radius},apoapsis=hM and{position=hM,speed=hN/hK,circularOrbitSpeed=math.sqrt(hG/hK),altitude=hK-self.body.radius},currentVelocity=bH,currentPosition=cl,eccentricity=hI,period=hO,eccentricAnomaly=hQ,meanAnomaly=hS,timeToPeriapsis=hU,timeToApoapsis=hV}end;local function hW(hX)local hz=PlanetRef.BodyParameters(hX.planetarySystemId,hX.bodyId,hX.radius,hX.center,hX.GM)return setmetatable({body=hz},Kepler)end;return setmetatable(Kepler,{__call=function(_,...)return hW(...)end})end;function Kinematics()local b9={}local hY=30000000/3600;local hZ=hY*hY;local h_=100;local function i0(bH)return 1/math.sqrt(1-bH*bH/hZ)end;function b9.computeAccelerationTime(i1,i2,i3)local i4=hY*math.asin(i1/hY)return(hY*math.asin(i3/hY)-i4)/i2 end;function b9.computeDistanceAndTime(i1,i3,i5,i6,i7,i8)i7=i7 or 0;i8=i8 or 0;local i9=i1<=i3;local ia=i6*(i9 and 1 or-1)/i5;local ib=-i8/i5;local ic=ia+ib;if i9 and ic<=0 or not i9 and ic>=0 then return-1,-1 end;local id,ie=0,0;if ia~=0 and i7>0 then local i4=math.asin(i1/hY)local ig=math.pi*(ia/2+ib)local ih=ia*i7;local ii=hY*math.pi;local bH=function(gz)local d0=(ig*gz-ih*math.sin(math.pi*gz/2/i7)+ii*i4)/ii;local ij=math.tan(d0)return hY*ij/math.sqrt(ij*ij+1)end;local ik=i9 and function(gB)return gB>=i3 end or function(gB)return gB<=i3 end;ie=2*i7;if ik(bH(ie))then local il=0;while math.abs(ie-il)>0.5 do local gz=(ie+il)/2;if ik(bH(gz))then ie=gz else il=gz end end end;local im=i1;local io=ie/h_;for ip=1,h_ do local bX=bH(ip*io)id=id+(bX+im)*io/2;im=bX end;if ie<2*i7 then return id,ie end;i1=im end;local i4=hY*math.asin(i1/hY)local bJ=(hY*math.asin(i3/hY)-i4)/ic;local iq=hZ*math.cos(i4/hY)/ic;local ae=iq-hZ*math.cos((ic*bJ+i4)/hY)/ic;return ae+id,bJ+ie end;function b9.computeTravelTime(i1,i2,ae)if ae==0 then return 0 end;if i2>0 then local i4=hY*math.asin(i1/hY)local iq=hZ*math.cos(i4/hY)/i2;return(hY*math.acos(i2*(iq-ae)/hZ)-i4)/i2 end;if i1==0 then return-1 end;assert(i1>0,'Acceleration and initial speed are both zero.')return ae/i1 end;function b9.lorentz(bH)return i0(bH)end;return b9 end;function safeZone(ir)local gT=500000;local is,it,iu=math.huge;local iv=false;local iw=vec3({13771471,7435803,-128971})local ix=18000000;is=vec3(ir):dist(iw)if is<ix then return true,math.abs(is-ix),"Safe Zone",0 end;it=vec3(ir):dist(vec3(planet.center))if it<gT then iv=true end;if math.abs(it-gT)<math.abs(is-ix)then return iv,math.abs(it-gT),planet.name,planet.bodyId else return iv,math.abs(is-ix),"Safe Zone",0 end end;function cmdThrottle(ek,iy)if iy==nil then iy=false end;if Nav.axisCommandManager:getAxisCommandType(0)~=axisCommandType.byThrottle and not iy then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,ek)z=round(ek*100,0)end;function cmdCruise(ek,iy)if Nav.axisCommandManager:getAxisCommandType(0)~=axisCommandType.byTargetSpeed and not iy then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,ek)end;function SaveDataBank(iz)if dbHud_1 then if not a9 then for bG,bH in pairs(b)do dbHud_1.setStringValue(bH,g(_G[bH]))if iz and dbHud_2 then dbHud_2.setStringValue(bH,g(_G[bH]))end end;for bG,bH in pairs(a)do dbHud_1.setStringValue(bH,g(_G[bH]))if iz and dbHud_2 then dbHud_2.setStringValue(bH,g(_G[bH]))end end;c("Saved Variables to Datacore")if iz and dbHud_2 then W="Databank copied. Remove copy when ready."end end end end;function script.onStart()VERSION_NUMBER=5.453;SetupComplete=false;beginSetup=coroutine.create(function()Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal,{1000,5000,10000,20000,30000})LoadVariables()coroutine.yield()ProcessElements()coroutine.yield()SetupChecks()SetupButtons()coroutine.yield()SetupAtlas()b7=PlanetRef()b8=b7(Atlas())b9=Kinematics()bb=Keplers()AddLocationsToAtlas()UpdateAtlasLocationsList()UpdateAutopilotTarget()coroutine.yield()unit.hide()system.showScreen(1)collectgarbage("collect")coroutine.yield()unit.setTimer("apTick",apTickRate)unit.setTimer("hudTick",hudTickRate)unit.setTimer("oneSecond",1)unit.setTimer("tenthSecond",1/10)if UseSatNav then unit.setTimer("fiveSecond",5)end end)end;function script.onStop()_autoconf.hideCategoryPanels()if antigrav~=nil and not ExternalAGG then antigrav.hide()end;if warpdrive~=nil then warpdrive.hide()end;core.hide()Nav.control.switchOffHeadlights()local bS=j()if door and(bS>0 or bS==0 and ap<10000)then for _,bH in pairs(door)do bH.toggle()end end;if switch then for _,bH in pairs(switch)do bH.toggle()end end;if forcefield and(bS>0 or bS==0 and ap<10000)then for _,bH in pairs(forcefield)do bH.toggle()end end;SaveDataBank()if button then button.activate()end end;function script.onTick(iA)if iA=="tenthSecond"then if j()>0 and not WasInAtmo then if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and AtmoSpeedAssist and(AltitudeHold or Reentry)then z=1;Nav.control.cancelCurrentControlMasterMode()D=false end end;if AutopilotTargetName~="None"then if panelInterplanetary==nil then SetupInterplanetaryPanel()end;if AutopilotTargetName~=nil then local iB=CustomTarget~=nil;planetMaxMass=GetAutopilotMaxMass()system.updateData(interplanetaryHeaderText,'{"label": "Target", "value": "'..AutopilotTargetName..'", "unit":""}')travelTime=GetAutopilotTravelTime()if iB and not Autopilot then ae=(vec3(core.getConstructWorldPos())-CustomTarget.position):len()else ae=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()end;if not TurnBurn then a2,a3=GetAutopilotBrakeDistanceAndTime(bg)a4,a5=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else a2,a3=GetAutopilotTBBrakeDistanceAndTime(bg)a4,a5=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;local dE,dF=getDistanceDisplayString(ae)system.updateData(widgetDistanceText,'{"label": "distance", "value": "'..dE..'", "unit":"'..dF..'"}')system.updateData(widgetTravelTimeText,'{"label": "Travel Time", "value": "'..FormatTimeString(travelTime)..'", "unit":""}')dE,dF=getDistanceDisplayString(a2)system.updateData(widgetCurBrakeDistanceText,'{"label": "Cur Brake distance", "value": "'..dE..'", "unit":"'..dF..'"}')system.updateData(widgetCurBrakeTimeText,'{"label": "Cur Brake Time", "value": "'..FormatTimeString(a3)..'", "unit":""}')dE,dF=getDistanceDisplayString(a4)system.updateData(widgetMaxBrakeDistanceText,'{"label": "Max Brake distance", "value": "'..dE..'", "unit":"'..dF..'"}')system.updateData(widgetMaxBrakeTimeText,'{"label": "Max Brake Time", "value": "'..FormatTimeString(a5)..'", "unit":""}')system.updateData(widgetMaxMassText,'{"label": "Maximum Mass", "value": "'..e("%.2f",planetMaxMass/1000)..'", "unit":" Tons"}')dE,dF=getDistanceDisplayString(AutopilotTargetOrbit)system.updateData(widgetTargetOrbitText,'{"label": "Target Orbit", "value": "'..e("%.2f",dE)..'", "unit":"'..dF..'"}')if j()>0 and not WasInAtmo then system.removeDataFromWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)system.removeDataFromWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)system.removeDataFromWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)system.removeDataFromWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)system.removeDataFromWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)WasInAtmo=true end;if j()==0 and WasInAtmo then if system.updateData(widgetMaxBrakeTimeText,widgetMaxBrakeTime)==1 then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;if system.updateData(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)==1 then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;if system.updateData(widgetCurBrakeTimeText,widgetCurBrakeTime)==1 then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;if system.updateData(widgetCurBrakeDistanceText,widgetCurBrakeDistance)==1 then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;if system.updateData(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)==1 then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end;WasInAtmo=false end end else HideInterplanetaryPanel()end;if warpdrive~=nil then if f(warpdrive.getData()).destination~="Unknown"and f(warpdrive.getData()).distance>400000 then warpdrive.show()showWarpWidget=true else warpdrive.hide()showWarpWidget=false end end elseif iA=="oneSecond"then am=false;RefreshLastMaxBrake(nil,true)updateDistance()updateRadar()updateWeapons()local cy={}local dQ=GetFlightStyle()DrawOdometer(cy,a7,TotalDistanceTravelled,dQ,a8)if ShouldCheckDamage then CheckDamage(cy)end;ag=table.concat(cy,"")collectgarbage("collect")elseif iA=="fiveSecond"then an=dbHud_1.getStringValue("SPBAutopilotTargetName")if an~=nil and an~=""and an~="SatNavNotChanged"then local bI=json.decode(dbHud_1.getStringValue("SavedLocations"))if bI~=nil then _G["SavedLocations"]=bI;local cw=-1;local cs;for bG,bH in pairs(SavedLocations)do if bH.name and bH.name=="SatNav Location"then cw=bG;break end end;if cw~=-1 then cs=SavedLocations[cw]cw=-1;for bG,bH in pairs(b2[0])do if bH.name and bH.name=="SatNav Location"then cw=bG;break end end;if cw>-1 then b2[0][cw]=cs end;UpdateAtlasLocationsList()W=cs.name.." position updated"end end;for i=1,#AtlasOrdered do if AtlasOrdered[i].name==an then AutopilotTargetIndex=i;system.print("Index = "..AutopilotTargetIndex.." "..AtlasOrdered[i].name)UpdateAutopilotTarget()dbHud_1.setStringValue("SPBAutopilotTargetName","SatNavNotChanged")break end end end elseif iA=="msgTick"then local cy={}DisplayMessage(cy,"empty")W="empty"unit.stopTimer("msgTick")ad=3 elseif iA=="animateTick"then bd=true;bc=false;ab=0;ac=0;unit.stopTimer("animateTick")elseif iA=="hudTick"then local cy={}HUDPrologue(cy)if showHud then UpdateHud(cy)else DisplayOrbitScreen(cy)DrawWarnings(cy)end;HUDEpilogue(cy)cy[#cy+1]=e([[<svg width="100%%" height="100%%" style="position:absolute;top:0;left:0" viewBox="0 0 %d %d">]],ResolutionX,ResolutionY)if W~="empty"then DisplayMessage(cy,W)end;if o()==0 and userControlScheme=="virtual joystick"then if DisplayDeadZone then DrawDeadZone(cy)end end;if o()==1 and screen_1 and screen_1.getMouseY()~=-1 then SetButtonContains()DrawButtons(cy)if screen_1.getMouseState()==1 then CheckButtons()end;cy[#cy+1]=e([[<g transform="translate(%d %d)"><circle class="cursor" cx="%fpx" cy="%fpx" r="5"/></g>]],E,F,ab,ac)elseif system.isViewLocked()==0 then if o()==1 and V then SetButtonContains()DrawButtons(cy)if not bc and not bd then local iC=table.concat(cy,"")cy={}cy[#cy+1]=e("<style>@keyframes test { from { opacity: 0; } to { opacity: 1; } } body { animation-name: test; animation-duration: 0.5s; }</style><body><svg width='100%%' height='100%%' position='absolute' top='0' left='0'><rect width='100%%' height='100%%' x='0' y='0' position='absolute' style='fill:rgb(6,5,26);'/></svg><svg width='50%%' height='50%%' style='position:absolute;top:30%%;left:25%%' viewbox='0 0 %d %d'>",ResolutionX,ResolutionY)cy[#cy+1]=b3;cy[#cy+1]=iC;cy[#cy+1]="</body>"bc=true;cy[#cy+1]=[[</svg></body>]]unit.setTimer("animateTick",0.5)local content=table.concat(cy,"")system.setScreen(content)elseif bd then local iC=table.concat(cy,"")cy={}cy[#cy+1]=e("<body style='background-color:rgb(6,5,26)'><svg width='50%%' height='50%%' style='position:absolute;top:30%%;left:25%%' viewbox='0 0 %d %d'>",ResolutionX,ResolutionY)cy[#cy+1]=b3;cy[#cy+1]=iC;cy[#cy+1]="</body>"end;if not bc then cy[#cy+1]=e([[<g transform="translate(%d %d)"><circle class="cursor" cx="%fpx" cy="%fpx" r="5"/></g>]],E,F,ab,ac)end else CheckButtons()end else if not V and o()==0 then CheckButtons()if ae>DeadZone then if DisplayDeadZone then DrawCursorLine(cy)end end else SetButtonContains()DrawButtons(cy)end;cy[#cy+1]=e([[<g transform="translate(%d %d)"><circle class="cursor" cx="%fpx" cy="%fpx" r="5"/></g>]],E,F,ab,ac)end;cy[#cy+1]=[[</svg></body>]]content=table.concat(cy,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end elseif iA=="apTick"then ao=j()>0;local bJ=system.getTime()local iD=bJ-bl;bl=bJ;local cB=vec3(core.getConstructWorldOrientationForward())local cC=vec3(core.getConstructWorldOrientationRight())local iE=vec3(core.getConstructWorldOrientationUp())local cD=vec3(core.getWorldVertical())local iF=vec3(core.getConstructWorldPos())local dS=getRoll(cD,cB,cC)local dT=dS/180*math.pi;local dU=math.cos(dT)local dV=math.sin(dT)local cE=getPitch(cD,cB,cC)local iG=getPitch(cD,cB,cC*dU+iE*dV)local iH=-math.deg(cW(iE,bf,cB))local iI=math.deg(cW(cC,bf,cB))bk=ao and iH<-YawStallAngle or iH>YawStallAngle or iI<-PitchStallAngle or iI>PitchStallAngle;bi=system.getMouseDeltaX()bj=system.getMouseDeltaY()if InvertMouse and not V then bj=-bj end;P=0;T=0;O=0;bf=vec3(core.getWorldVelocity())bg=vec3(bf):len()sys=b8[0]planet=sys:closestBody(core.getConstructWorldPos())kepPlanet=bb(planet)orbit=kepPlanet:orbitalParameters(core.getConstructWorldPos(),bf)al=hoverDetectGround()local bU=planet:getGravity(core.getConstructWorldPos()):len()*n()bm=0;ba=core.getMaxKinematicsParametersAlongAxis("ground",core.getConstructOrientationUp())[1]w,x,y,_=safeZone(iF)if o()==1 and screen_1 and screen_1.getMouseY()~=-1 then ab=screen_1.getMouseX()*ResolutionX;ac=screen_1.getMouseY()*ResolutionY elseif system.isViewLocked()==0 then if o()==1 and V then if not bc then ab=ab+bi;ac=ac+bj end else ab=0;ac=0 end else ab=ab+bi;ac=ac+bj;ae=math.sqrt(ab*ab+ac*ac)if not V and o()==0 then if userControlScheme=="virtual joystick"then if ab>0 and ab>DeadZone then P=P-(ab-DeadZone)*MouseXSensitivity elseif ab<0 and ab<DeadZone*-1 then P=P-(ab+DeadZone)*MouseXSensitivity else P=0 end;if ac>0 and ac>DeadZone then O=O-(ac-DeadZone)*MouseYSensitivity elseif ac<0 and ac<DeadZone*-1 then O=O-(ac+DeadZone)*MouseYSensitivity else O=0 end elseif userControlScheme=="mouse"then ab=0;ac=0;O=(-utils.smoothstep(bj,-100,100)+0.5)*2*K;P=(-utils.smoothstep(bi,-100,100)+0.5)*2*L else ab=0;ac=0 end end end;local iJ=bg>8334;if bg>SpaceSpeedLimit/3.6 and not ao and not Autopilot and not iJ then W="Space Speed Engine Shutoff reached"if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)z=0 end;if not iJ and LastIsWarping then if not BrakeIsOn then BrakeToggle()end;if Autopilot then ToggleAutopilot()end end;LastIsWarping=iJ;if ao and j()>0.09 then if bg>bp/3.6 and not AtmoSpeedAssist and not at then BrakeIsOn=true;at=true elseif not AtmoSpeedAssist and at then if bg<bp/3.6 then BrakeIsOn=false;at=false end end end;if BrakeIsOn then S=1 else S=0 end;ap=core.getAltitude()if ap==0 then ap=(vec3(core.getConstructWorldPos())-planet.center):len()-planet.radius end;if ProgradeIsOn then if ai then BrakeIsOn=false;local iK=false;if CustomTarget~=nil then iK=AlignToWorldVector(CustomTarget.position-iF,0.01)else iK=AlignToWorldVector(vec3(bf),0.01)end;be=true;if iK and(math.abs(dS)<2 or math.abs(iG)>85)and bg>=bp/3.6-1 then BrakeIsOn=false;ProgradeIsOn=false;J=true;ai=false;ak=true;Autopilot=false;BeginReentry()elseif ao and AtmoSpeedAssist then cmdThrottle(1)else cmdCruise(math.floor(bp))z=0 end elseif bg>I then AlignToWorldVector(vec3(bf),0.01)end end;if RetrogradeIsOn then if ao then RetrogradeIsOn=false elseif bg>I then AlignToWorldVector(-vec3(bf))end end;if not ProgradeIsOn and ai then if j()==0 then J=true;BeginReentry()ai=false;ak=true else ai=false;ToggleAutopilot()end end;local eo=vec3(core.getWorldVertical())*-1;local em=bf.x*eo.x+bf.y*eo.y+bf.z*eo.z;if ak and CustomTarget~=nil and(ap<HoldAltitude+200 and ap>HoldAltitude-200)and bg*3.6>bp-100 and math.abs(em)<20 and j()>=0.1 and(CustomTarget.position-iF):len()>2000+ap then ToggleAutopilot()ak=false end;if VertTakeOff then be=true;if em<-30 then W="Unable to achieve lift. Safety Landing."aa=0;be=autoRollPreference;VertTakeOff=false;BrakeLanding=true elseif antigrav and not ExternalAGG and antigrav.getState()==1 then if ap<antigrav.getBaseAltitude()-100 then bq=0;aa=15;BrakeIsOn=false elseif em>0 then BrakeIsOn=true;aa=0 elseif em<-30 then BrakeIsOn=true;aa=15 elseif ap>=antigrav.getBaseAltitude()then BrakeIsOn=true;aa=0;VertTakeOff=false;W="Takeoff complete. Singularity engaged"end else if j()>0.08 then bq=0;BrakeIsOn=false;aa=20 elseif j()<0.08 and j()>0 then BrakeIsOn=false;if bC then bq=0;aa=20 else aa=0;bq=36;cmdCruise(3500)end else be=autoRollPreference;if not IntoOrbit then bu=true;ToggleIntoOrbit()end;VertTakeOff=false end end;if bq~=nil then if vTpitchPID==nil then vTpitchPID=pid.new(2*0.01,0,2*0.1)end;local iL=utils.clamp(bq-iG,-PitchStallAngle*0.85,PitchStallAngle*0.85)vTpitchPID:inject(iL)local iM=utils.clamp(vTpitchPID:get(),-1,1)O=iM end end;if IntoOrbit then if bz==nil then if VectorToTarget then bz=a6 else bz=planet end end;if not bx then if bz.hasAtmosphere then by=math.floor(bz.radius+bz.noAtmosphericDensityAltitude+OrbitDefaultAltitude)else by=math.floor(bz.radius+bz.surfaceMaxAltitude+OrbitDefaultAltitude)end;bx=true end;local dB;local iN=false;local iO,iP=getDistanceDisplayString2(by)local iQ=iO..iP;if bw.VectorToTarget then dB=CustomTarget.position-iF end;local iR,iS=bb(bz):escapeAndOrbitalSpeed((vec3(core.getConstructWorldPos())-bz.center):len()-bz.radius)local iT=dS;if not bu then cmdThrottle(0)bt=0;br="Aligning to orbital path - OrbitHeight: "..iQ;local iU=false;local iV=false;if bw.VectorToTarget then AlignToWorldVector(dB:normalize():project_on_plane(cD))iN=cB:dot(dB:project_on_plane(iE):normalize())>0.95 else AlignToWorldVector(bf)iN=iH<0.5;if bg<150 then iN=true end end;O=0;bs=0;if iG<=bs+1 and iG>=bs-1 then iU=true else iU=false end;if iT<=bt+1 and iT>=bt-1 then iV=true else iV=false end;if iU and iV and iN then bs=nil;bt=nil;bu=true end else if bw.VectorToTarget then AlignToWorldVector(dB:normalize():project_on_plane(cD))elseif bg>150 then AlignToWorldVector(bf)end;O=0;if bw.VectorToTarget then local a2,_=b9.computeDistanceAndTime(bg,bp/3.6,n(),0,0,LastMaxBrake)if bA and dB:len()>15000+a2+ap then br="Orbiting to Target"elseif bA or dB:len()<15000+a2+ap then W="Orbit complete, proceeding with reentry"AutopilotTargetCoords=CustomTarget.position;J=true;ak=true;bw.VectorToTarget,bw.AutopilotAlign=false,false;ToggleIntoOrbit()BeginReentry()end end;if orbit.periapsis~=nil and orbit.apoapsis~=nil and orbit.eccentricity<1 and ap>by*0.9 and ap<by*1.4 then if orbit.apoapsis~=nil then if orbit.periapsis.altitude>=by*0.99 and orbit.apoapsis.altitude>=by*0.99 and orbit.periapsis.altitude<orbit.apoapsis.altitude and orbit.periapsis.altitude*1.05>=orbit.apoapsis.altitude or bA then if bA then BrakeIsOn=false;z=0;cmdThrottle(0)bA=true;bs=0;if not bw.VectorToTarget then W="Orbit complete"ToggleIntoOrbit()end else bE=bE+1;if bE>=2 then bA=true end end else br="Adjusting Orbit - OrbitHeight: "..iQ;bv=true;cmdCruise(iS*3.6+1)if VSpdPID==nil then VSpdPID=pid.new(0.5,0,10*0.1)end;local iW=em;local iX=ap-by;local iY=math.abs(iX)if em<10 and math.abs(iG)<10 and iY<100 then iW=em*2 end;if iW<10 and math.abs(iG)<10 and iY<100 then iW=iW*2 end;if iW<5 and math.abs(iG)<5 and iY<100 then iW=iW*4 end;VSpdPID:inject(iW)bs=utils.clamp(-VSpdPID:get(),-90,90)if OrbitAltPID==nil then OrbitAltPID=pid.new(0.15,0,5*0.1)end;OrbitAltPID:inject(iX)bs=utils.clamp(bs-utils.clamp(OrbitAltPID:get(),-15,15),-90,90)end end else local iZ=2.75;local i_=math.abs(utils.round(iR*iZ))local j0=i_%50;if j0>0 then i_=i_-j0+50 end;BrakeIsOn=false;if ap<by*0.8 then br="Escaping planet gravity - OrbitHeight: "..iQ;bs=utils.map(em,200,0,-15,80)elseif ap>=by*0.8 and ap<by*1.15 then br="Approaching orbital corridor - OrbitHeight: "..iQ;i_=i_*0.75;bs=utils.map(em,100,-100,-15,65)elseif ap>=by*1.15 and ap<by*1.5 then br="Approaching orbital corridor - OrbitHeight: "..iQ;i_=i_*0.75;if em<0 or bv then bs=utils.map(ap,by*1.5,by*1.01,-30,0)else bs=utils.map(ap,by*0.99,by*1.5,0,30)end elseif ap>by*1.5 then br="Reentering orbital corridor - OrbitHeight: "..iQ;bs=-85;local j1=utils.map(em,-150,-400,1,0.55)i_=i_*j1 end;cmdCruise(math.floor(i_))end end;if bs~=nil then if OrbitPitchPID==nil then OrbitPitchPID=pid.new(1*0.01,0,5*0.1)end;local j2=bs-iG;OrbitPitchPID:inject(j2)local j3=utils.clamp(OrbitPitchPID:get(),-0.5,0.5)O=j3 end end;if Autopilot and j()==0 and not ai then local j4,j5=AutopilotTargetCoords,false;if CustomTarget~=nil and CustomTarget.planetname~="Space"then AutopilotRealigned=true;if not TargetSet then local j6=(CustomTarget.position-a6.center):normalize()local j7=j6:project_on_plane((a6.center-iF):normalize()):normalize()local j8=a6.center+j7*(a6.radius+AutopilotTargetOrbit)local j9=CustomTarget.position+(CustomTarget.position-a6.center):normalize()*(AutopilotTargetOrbit-a6:getAltitude(CustomTarget.position))if(iF-j8):len()<(iF-j9):len()then j4=j8;AutopilotTargetCoords=j4 else j4=CustomTarget.position+(CustomTarget.position-a6.center):normalize()*(AutopilotTargetOrbit-a6:getAltitude(CustomTarget.position))AutopilotTargetCoords=j4 end;local cG=zeroConvertToMapPosition(a6,AutopilotTargetCoords)cG="::pos{"..cG.systemId..","..cG.bodyId..","..cG.latitude..","..cG.longitude..","..cG.altitude.."}"system.setWaypoint(cG)j5=true;TargetSet=true end;AutopilotPlanetGravity=0 elseif CustomTarget~=nil and CustomTarget.planetname=="Space"then AutopilotPlanetGravity=0;j5=true;TargetSet=true;AutopilotRealigned=true;j4=CustomTarget.position+(iF-CustomTarget.position)*AutopilotTargetOrbit elseif CustomTarget==nil then AutopilotPlanetGravity=0;if not TargetSet then local j6=(iF+bf*100000-a6.center):normalize()local j7=j6:project_on_plane((a6.center-iF):normalize()):normalize()if j7:len()<1 then j6=(iF+vec3(core.getConstructWorldOrientationForward())*100000-a6.center):normalize()j7=j6:project_on_plane((a6.center-iF):normalize()):normalize()end;j4=a6.center+j7*(a6.radius+AutopilotTargetOrbit)AutopilotTargetCoords=j4;TargetSet=true;j5=true;AutopilotRealigned=true;local cG=zeroConvertToMapPosition(a6,AutopilotTargetCoords)cG="::pos{"..cG.systemId..","..cG.bodyId..","..cG.latitude..","..cG.longitude..","..cG.altitude.."}"system.setWaypoint(cG)end end;AutopilotDistance=(vec3(j4)-vec3(core.getConstructWorldPos())):len()local fl,fm,fn=b8:getPlanetarySystem(0):castIntersections(iF,bf:normalize(),function(fo)if fo.noAtmosphericDensityAltitude>0 then return fo.radius+fo.noAtmosphericDensityAltitude else return fo.radius+fo.surfaceMaxAltitude*1.5 end end)local fp=fm;if fn~=nil and fm~=nil then fp=math.min(fn,fm)end;if fp~=nil and fp<AutopilotDistance and fl.name==a6.name then AutopilotDistance=fp end;local iK=true;local ja=(a6.center-(vec3(core.getConstructWorldPos())+vec3(bf):normalize()*AutopilotDistance)):len()-a6.radius;local dE,dF=getDistanceDisplayString(ja)system.updateData(widgetTrajectoryAltitudeText,'{"label": "Projected Altitude", "value": "'..dE..'", "unit":"'..dF..'"}')local a2,a3;if not TurnBurn then a2,a3=GetAutopilotBrakeDistanceAndTime(bg)else a2,a3=GetAutopilotTBBrakeDistanceAndTime(bg)end;if bg>300 and AutopilotAccelerating then local dB=vec3(j4)-vec3(core.getConstructWorldPos())local jb=utils.clamp(math.deg(cW(iE,bf:normalize(),dB:normalize()))*bg/500,-90,90)local jc=utils.clamp(math.deg(cW(cC,bf:normalize(),dB:normalize()))*bg/500,-90,90)if math.abs(jb)<20 and math.abs(jc)<20 then jb=jb*2;jc=jc*2 end;if math.abs(jb)<2 and math.abs(jc)<2 then jb=jb*2;jc=jc*2 end;local iH=-math.deg(cW(iE,cB,bf:normalize()))local iI=-math.deg(cW(cC,cB,bf:normalize()))if apPitchPID==nil then apPitchPID=pid.new(2*0.01,0,2*0.1)end;apPitchPID:inject(jc-iI)local jd=utils.clamp(apPitchPID:get(),-1,1)O=O+jd;if apYawPID==nil then apYawPID=pid.new(2*0.01,0,2*0.1)end;apYawPID:inject(jb-iH)local je=utils.clamp(apYawPID:get(),-1,1)P=P+je;j5=true;if math.abs(jb)>2 or math.abs(jc)>2 then AutopilotStatus="Adjusting Trajectory"else AutopilotStatus="Accelerating"end end;if ja<AutopilotTargetOrbit*1.5 then if CustomTarget~=nil and CustomTarget.planetname=="Space"then AutopilotEndSpeed=0 elseif CustomTarget==nil then _,AutopilotEndSpeed=bb(a6):escapeAndOrbitalSpeed(ja)end end;if not AutopilotCruising and not AutopilotBraking and not j5 then iK=AlignToWorldVector((j4-vec3(core.getConstructWorldPos())):normalize())elseif TurnBurn then iK=AlignToWorldVector(-vec3(bf):normalize())end;if AutopilotAccelerating then if not G then BrakeIsOn=false;cmdThrottle(AutopilotInterplanetaryThrottle)z=round(AutopilotInterplanetaryThrottle,2)G=true end;local fN=unit.getThrottle()if AtmoSpeedAssist then fN=z end;if vec3(core.getVelocity()):len()>=MaxGameVelocity or fN==0 and G then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;cmdThrottle(0)z=0 end;if AutopilotDistance<=a2 then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;cmdThrottle(0)z=0;G=false end elseif AutopilotBraking then if AutopilotStatus~="Orbiting to Target"then BrakeIsOn=true;S=1 end;if TurnBurn then cmdThrottle(100,true)z=1 end;local _,iS=bb(a6):escapeAndOrbitalSpeed((vec3(core.getConstructWorldPos())-planet.center):len()-planet.radius)local dB;if CustomTarget~=nil then dB=CustomTarget.position-iF end;if CustomTarget~=nil and CustomTarget.planetname=="Space"and bg<50 then W="Autopilot complete, arrived at space location"AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"elseif CustomTarget~=nil and CustomTarget.planetname~="Space"and bg<=iS and(orbit.apoapsis==nil or orbit.periapsis==nil or orbit.apoapsis.altitude<=0 or orbit.periapsis.altitude<=0)then W="Autopilot complete, proceeding with reentry"AutopilotTargetCoords=CustomTarget.position;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"cmdThrottle(0)z=0;G=false;ProgradeIsOn=true;ai=true;local cG=zeroConvertToMapPosition(a6,AutopilotTargetCoords)cG="::pos{"..cG.systemId..","..cG.bodyId..","..cG.latitude..","..cG.longitude..","..cG.altitude.."}"system.setWaypoint(cG)elseif orbit.periapsis~=nil and orbit.periapsis.altitude>0 and orbit.eccentricity<1 then AutopilotStatus="Circularizing"local _,iS=bb(a6):escapeAndOrbitalSpeed((vec3(core.getConstructWorldPos())-planet.center):len()-planet.radius)if bg<=iS then if CustomTarget~=nil then if bf:normalize():dot(dB:normalize())>0.4 then AutopilotStatus="Orbiting to Target"if not WaypointSet then BrakeIsOn=false;local cG=zeroConvertToMapPosition(a6,CustomTarget.position)cG="::pos{"..cG.systemId..","..cG.bodyId..","..cG.latitude..","..cG.longitude..","..cG.altitude.."}"system.setWaypoint(cG)WaypointSet=true end else W="Autopilot complete, proceeding with reentry"AutopilotTargetCoords=CustomTarget.position;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"cmdThrottle(0)z=0;G=false;ProgradeIsOn=true;ai=true;BrakeIsOn=false;local cG=zeroConvertToMapPosition(a6,CustomTarget.position)cG="::pos{"..cG.systemId..","..cG.bodyId..","..cG.latitude..","..cG.longitude..","..cG.altitude.."}"system.setWaypoint(cG)WaypointSet=false end else BrakeIsOn=false;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"W="Autopilot completed, orbit established"S=0;z=0;G=false;if CustomTarget~=nil and CustomTarget.planetname~="Space"then ProgradeIsOn=true;ai=true end end end end elseif AutopilotCruising then if AutopilotDistance<=a2 then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true end;local fN=unit.getThrottle()if AtmoSpeedAssist then fN=z end;if fN>0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if iK then if not AutopilotRealigned and CustomTarget==nil or not AutopilotRealigned and CustomTarget~=nil and CustomTarget.planetname~="Space"then if not ai then AutopilotTargetCoords=vec3(a6.center)+(AutopilotTargetOrbit+a6.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()end;AutopilotRealigned=true elseif iK then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not G then cmdThrottle(AutopilotInterplanetaryThrottle,true)z=round(AutopilotInterplanetaryThrottle,2)G=true;BrakeIsOn=false end end end end elseif Autopilot and(CustomTarget~=nil and CustomTarget.planetname~="Space"and j()>0)then W="Autopilot complete, proceeding with reentry"AutopilotTargetCoords=CustomTarget.position;BrakeIsOn=false;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"S=0;cmdThrottle(0)z=0;G=false;ProgradeIsOn=true;ai=true;local cG=zeroConvertToMapPosition(a6,CustomTarget.position)cG="::pos{"..cG.systemId..","..cG.bodyId..","..cG.latitude..","..cG.longitude..","..cG.altitude.."}"system.setWaypoint(cG)end;if U then be=true;local jc=0;local cl=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local jf=cl-vec3(core.getConstructWorldPos())local jg=vec3(jf):project_on(vec3(core.getConstructWorldOrientationForward())):len()local jh=vec3(jf):project_on(vec3(core.getConstructWorldOrientationRight())):len()local ae=math.sqrt(jg*jg+jh*jh)AlignToWorldVector(jf:normalize())local ji=40;local jj=ae<ji;local jk=100;local gh=utils.clamp((ae-ji)/2,10,jk)O=0;local iK=math.abs(P)<0.1;if iK and bg<gh and not jj then BrakeIsOn=false;jc=-20 else BrakeIsOn=true;jc=0 end;local jl=0;if math.abs(jc-cE)>jl then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(jc-cE)local jd=pitchPID:get()O=jd end end;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget or LockPitch~=nil then local cH=unit.getClosestPlanetInfluence()>0;local jm=HoldAltitude-ap;local jn=500+bg;local jo=1;if AutoTakeoff then jo=utils.clamp(bg/100,0.1,1)end;local jc=(utils.smoothstep(jm,-jn,jn)-0.5)*2*MaxPitch*jo;if not Reentry and not ai and not VectorToTarget and cB:dot(bf:normalize())<0.99 then jc=(utils.smoothstep(jm,-jn*utils.clamp(20-19*j()*10,1,20),jn*utils.clamp(20-19*j()*10,1,20))-0.5)*2*MaxPitch*utils.clamp(2-j()*10,1,2)*jo end;if not AltitudeHold then jc=0 end;if LockPitch~=nil then if cH and not IntoOrbit then jc=LockPitch else LockPitch=nil end end;be=true;local jp=O;if Reentry then local ReentrySpeed=math.floor(bp)local jq,jr=b9.computeDistanceAndTime(bg,ReentrySpeed/3.6,n(),0,0,LastMaxBrake-planet.gravity*9.8*n())local js=ap-(planet.noAtmosphericDensityAltitude+5000)if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and ap>planet.noAtmosphericDensityAltitude+5000 and bg<=ReentrySpeed/3.6 and bg>ReentrySpeed/3.6-10 and math.abs(bf:normalize():dot(cB))>0.9 then Nav.control.cancelCurrentControlMasterMode()z=0 elseif Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle and(jq>-1 and js<=jq or ap<=planet.noAtmosphericDensityAltitude+5000)then BrakeIsOn=true else BrakeIsOn=false end;cmdCruise(ReentrySpeed,true)if not J then jc=-80;if j()>0.02 then W="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;jc=0;be=autoRollPreference end elseif planet.noAtmosphericDensityAltitude>0 and ap>planet.noAtmosphericDensityAltitude+5000 then be=true elseif ap<=planet.noAtmosphericDensityAltitude+5000 then cmdCruise(ReentrySpeed)jc=0;if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==bp and bg<bp/3.6+1 then J=false;Reentry=false;be=true end end end;if bg>I and not aj and not VectorToTarget and not BrakeLanding and ForceAlignment then AlignToWorldVector(vec3(bf))end;if(VectorToTarget or aj)and AutopilotTargetIndex>0 and j()>0.01 then local dB;if CustomTarget~=nil then dB=CustomTarget.position-vec3(core.getConstructWorldPos())else dB=a6.center-iF end;local jb=math.deg(cW(cD:normalize(),bf,dB))*2;local jt=math.rad(math.abs(dS))if bg>minRollVelocity and j()>0.01 then local ju=utils.clamp(90-jc*2,-90,90)bm=utils.clamp(jb*2,-ju,ju)local jv=jb;jb=utils.clamp(utils.clamp(jb,-YawStallAngle*0.85,YawStallAngle*0.85)*math.cos(jt)+4*(iG-jc)*math.sin(math.rad(dS)),-YawStallAngle*0.85,YawStallAngle*0.85)jc=utils.clamp(utils.clamp(jc*math.cos(jt),-PitchStallAngle*0.85,PitchStallAngle*0.85)+math.abs(utils.clamp(math.abs(jv)*math.sin(jt),-PitchStallAngle*0.85,PitchStallAngle*0.85)),-PitchStallAngle*0.85,PitchStallAngle*0.85)else bm=0;jb=utils.clamp(jb,-YawStallAngle*0.85,YawStallAngle*0.85)end;local jw=iH-jb;if not bk and bg>minRollVelocity and j()>0.01 then if yawPID==nil then yawPID=pid.new(2*0.01,0,2*0.1)end;yawPID:inject(jw)local je=utils.clamp(yawPID:get(),-1,1)P=P+je elseif ao and al>-1 or bg<minRollVelocity then AlignToWorldVector(dB)elseif bk and j()>0.01 then if(iH<-YawStallAngle or iH>YawStallAngle)and j()>0.01 then AlignToWorldVector(bf)end;if(iI<-PitchStallAngle or iI>PitchStallAngle)and j()>0.01 then jc=utils.clamp(iG-iI,iG-PitchStallAngle*0.85,iG+PitchStallAngle*0.85)end end;if CustomTarget~=nil and not aj then local jx=planet:getAltitude(CustomTarget.position)local js=math.sqrt(dB:len()^2-(ap-jx)^2)local jy=LastMaxBrakeInAtmo;if jy then jy=jy*utils.clamp(bg/100,0.1,1)*j()else jy=LastMaxBrake end;if j()<0.01 then jy=LastMaxBrake end;local jz=bf:len()-math.abs(em)local jA=vec3(core.getWorldAirFrictionAcceleration())local jB=math.sqrt(jA:len()-jA:project_on(eo):len())*n()if bg>100 then a2,a3=b9.computeDistanceAndTime(bg,100,n(),0,0,jy+jB)local jC,jD=b9.computeDistanceAndTime(100,0,n(),0,0,jy/2)a2=a2+jC else a2,a3=b9.computeDistanceAndTime(bg,0,n(),0,0,jy/2)end;StrongBrakes=true;if not aj and not Reentry and js<=a2+bg*iD/2 and(bf:project_on_plane(cD):normalize():dot(dB:project_on_plane(cD):normalize())>0.99 or VectorStatus=="Finalizing Approach")then VectorStatus="Finalizing Approach"cmdThrottle(0)z=0;if AltitudeHold then ToggleAltitudeHold()VectorToTarget=true end;BrakeIsOn=true elseif not AutoTakeoff then BrakeIsOn=false end;if VectorStatus=="Finalizing Approach"and(jz<0.1 or js<0.1 or LastDistanceToTarget~=nil and LastDistanceToTarget<js)then BrakeLanding=true;VectorToTarget=false;VectorStatus="Proceeding to Waypoint"end;LastDistanceToTarget=js end elseif VectorToTarget and j()==0 and HoldAltitude>planet.noAtmosphericDensityAltitude and not(aj or Reentry or IntoOrbit)then if CustomTarget~=nil and a6.name==planet.name then local dB=CustomTarget.position-vec3(core.getConstructWorldPos())local jx=planet:getAltitude(CustomTarget.position)local js=math.sqrt(dB:len()^2-(ap-jx)^2)local jy=LastMaxBrakeInAtmo;if jy then a2,a3=b9.computeDistanceAndTime(bg,0,n(),0,0,jy/2)StrongBrakes=true;if js<=a2+bg*iD/2 and bf:project_on_plane(cD):normalize():dot(dB:project_on_plane(cD):normalize())>0.99 then if planet.hasAtmosphere then BrakeIsOn=false;ProgradeIsOn=false;J=true;ai=false;ak=true;Autopilot=false;BeginReentry()end end end;LastDistanceToTarget=js end end;if j()==0 and(AltitudeHold and HoldAltitude>planet.noAtmosphericDensityAltitude)and not(aj or IntoOrbit or Reentry)then if not bA and not IntoOrbit then by=HoldAltitude;bx=true;if VectorToTarget then bw.VectorToTarget=true end;ToggleIntoOrbit()VectorToTarget=false;bu=true end end;if bk and j()>0.01 and al==-1 and bg>minRollVelocity and VectorStatus~="Finalizing Approach"then AlignToWorldVector(bf)jc=utils.clamp(iG-iI,iG-PitchStallAngle*0.85,iG+PitchStallAngle*0.85)end;O=jp;local fW=-1;if BrakeLanding then jc=0;local jE=false;local jF=30;if ba~=nil and ba>0 then local jB=0;local dY=utils.clamp(j(),0.4,2)local jy=LastMaxBrakeInAtmo*utils.clamp(bg/100,0.1,1)*dY;local jG=ba*dY+jy+jB-bU;local jH=jy/2+jB-bU;local jI=bg-math.sqrt(math.abs(jH/2)*20/(0.5*n()))*utils.sign(jH)if jI<0 then jI=0 end;local jJ;if bg>100 then local jK,_=b9.computeDistanceAndTime(bg,100,n(),0,0,jy)local jL,_=b9.computeDistanceAndTime(100,0,n(),0,0,math.sqrt(jy))jJ=jK+jL else jJ=b9.computeDistanceAndTime(bg,0,n(),0,0,math.sqrt(jy))end;if jJ<20 then BrakeIsOn=false else local jM=0;if jI>100 then local jN,_=b9.computeDistanceAndTime(jI,100,n(),0,0,jG)local jO,_=b9.computeDistanceAndTime(100,0,n(),0,0,ba*dY+math.sqrt(jy)+jB-bU)jM=jN+jO else jM,_=b9.computeDistanceAndTime(jI,0,n(),0,0,ba*dY+math.sqrt(jy)+jB-bU)end;jM=(jM+15+bg*iD)*1.1;local jP=CustomTarget~=nil and planet:getAltitude(CustomTarget.position)>0 and CustomTarget.safe;if jP then local jx=planet:getAltitude(CustomTarget.position)local jQ=ap-jx-100;local dB=CustomTarget.position-vec3(core.getConstructWorldPos())local jR=math.sqrt(dB:len()^2-(ap-jx)^2)if jR>100 then jP=false elseif jQ<=jM or jM==-1 then BrakeIsOn=true;jE=true else BrakeIsOn=false;jE=true end end;if not jP and CalculateBrakeLandingSpeed then if jM>=jF then BrakeIsOn=true else BrakeIsOn=false end;jE=true end end end;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)fW=al;if fW>-1 then be=autoRollPreference;if bg<1 or bf:normalize():dot(cD)<0 then BrakeLanding=false;AltitudeHold=false;GearExtended=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)aa=0;BrakeIsOn=true else BrakeIsOn=true end elseif StrongBrakes and bf:normalize():dot(-eo)<0.999 then BrakeIsOn=true elseif em<-brakeLandingRate and not jE then BrakeIsOn=true elseif not jE then BrakeIsOn=false end end;if AutoTakeoff or aj then local fl,fn,fm;if AutopilotTargetCoords~=nil then fl,fn,fm=b8:getPlanetarySystem(0):castIntersections(iF,(AutopilotTargetCoords-iF):normalize(),function(fo)return fo.radius+fo.noAtmosphericDensityAltitude end)end;if antigrav and antigrav.getState()==1 then if ap>=HoldAltitude-50 then AutoTakeoff=false;BrakeIsOn=true;cmdThrottle(0)z=0 else HoldAltitude=antigrav.getBaseAltitude()end elseif math.abs(jc)<15 and ap/HoldAltitude>0.75 then AutoTakeoff=false;if not aj then if Nav.axisCommandManager:getAxisCommandType(0)==0 and not AtmoSpeedAssist then Nav.control.cancelCurrentControlMasterMode()end elseif aj and bg<I then Autopilot=true;aj=false;AltitudeHold=false;AutoTakeoff=false;cmdThrottle(0)z=0 elseif aj then cmdThrottle(0)z=0;BrakeIsOn=true end elseif aj and j()==0 and a6~=nil and(fl==nil or fl.name==a6.name)then Autopilot=true;aj=false;AltitudeHold=false;AutoTakeoff=false;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;AutopilotAccelerating=true end end;local jS=hoverDetectGround()>-1;local jT=cE;if(VectorToTarget or aj)and not jS and bg>minRollVelocity and j()>0.01 then local jt=math.rad(math.abs(dS))jT=cE*math.abs(math.cos(jt))+iI*math.sin(jt)end;local jU=utils.clamp(jc-jT,-PitchStallAngle*0.85,PitchStallAngle*0.85)if j()<0.01 and VectorToTarget then jU=utils.clamp(jc-jT,-85,MaxPitch)elseif j()<0.01 then jU=utils.clamp(jc-jT,-MaxPitch,MaxPitch)end;if math.abs(dS)<5 or VectorToTarget or BrakeLanding or jS or AltitudeHold then if pitchPID==nil then pitchPID=pid.new(5*0.01,0,5*0.1)end;pitchPID:inject(jU)local jd=pitchPID:get()O=O+jd end end;if antigrav~=nil and(antigrav and not ExternalAGG and ap<200000)then if AntigravTargetAltitude==nil or AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end end end end;function script.onFlush()if antigrav~=nil and(antigrav and not ExternalAGG)then if antigrav.getState()==0 and antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(AntigravTargetAltitude)end end;if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle and D then z=0;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,z)D=false elseif Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and not D then z=0;D=true end;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)torqueFactor=math.max(torqueFactor,0.01)brakeSpeedFactor=math.max(brakeSpeedFactor,0.01)brakeFlatFactor=math.max(brakeFlatFactor,0.01)autoRollFactor=math.max(autoRollFactor,0.01)turnAssistFactor=math.max(turnAssistFactor,0.01)local jV=utils.clamp(N+O+system.getControlDeviceForwardInput(),-1,1)local jW=utils.clamp(Q+T+system.getControlDeviceYawInput(),-1,1)local jX=utils.clamp(R+P-system.getControlDeviceLeftRightInput(),-1,1)local jY=S;local jZ=vec3(core.getWorldVertical())if jZ==nil or jZ:len()==0 then jZ=(planet.center-vec3(core.getConstructWorldPos())):normalize()end;local j_=vec3(core.getConstructWorldOrientationUp())local k0=vec3(core.getConstructWorldOrientationForward())local k1=vec3(core.getConstructWorldOrientationRight())local k2=vec3(core.getWorldVelocity())local k3=vec3(core.getWorldVelocity()):normalize()local k4=getRoll(jZ,k0,k1)local k5=math.abs(k4)local k6=utils.sign(k4)local j=j()local k7=vec3(core.getWorldAngularVelocity())local k8=jV*pitchSpeedFactor*k1+jW*rollSpeedFactor*k0+jX*yawSpeedFactor*j_;if jZ:len()>0.01 and(j>0.0 or ProgradeIsOn or Reentry or ai or AltitudeHold or IntoOrbit)then local dS=getRoll(jZ,k0,k1)local dT=dS/180*math.pi;local dU=math.cos(dT)local dV=math.sin(dT)local iG=getPitch(jZ,k0,k1*dU+j_*dV)if be==true and math.abs(bm-k4)>autoRollRollThreshold and jW==0 and math.abs(iG)<80 then local k9=bm;local ka=autoRollFactor;if j==0 then ka=ka/4;bm=0;k9=0 end;if rollPID==nil then rollPID=pid.new(ka*0.01,0,ka*0.1)end;rollPID:inject(k9-k4)local kb=rollPID:get()k8=k8+kb*k0 end end;if jZ:len()>0.01 and j>0.0 then local kc=20.0;if turnAssist==true and k5>kc and jV==0 and jX==0 then local kd=turnAssistFactor*0.1;local ke=turnAssistFactor*0.025;local kf=(k5-kc)/(180-kc)*180;local kg=0;if kf<90 then kg=kf/90 elseif kf<180 then kg=(180-kf)/90 end;kg=kg*kg;local kh=-k6*ke*(1.0-kg)local ki=kd*kg;k8=k8+ki*k1+kh*j_ end end;local kj=1;local kk=0;local kl=1;if system.getMouseWheel()>0 then if AltIsOn then if j>0 or Reentry then bp=utils.clamp(bp+speedChangeLarge,0,AtmoSpeedLimit)elseif Autopilot then MaxGameVelocity=utils.clamp(MaxGameVelocity+speedChangeLarge/3.6*100,0,8333.00)end;H=false else z=round(utils.clamp(z+speedChangeLarge/100,-1,1),2)end elseif system.getMouseWheel()<0 then if AltIsOn then if j>0 or Reentry then bp=utils.clamp(bp-speedChangeLarge,0,AtmoSpeedLimit)elseif Autopilot then MaxGameVelocity=utils.clamp(MaxGameVelocity-speedChangeLarge/3.6*100,0,8333.00)end;H=false else z=round(utils.clamp(z-speedChangeLarge/100,-1,1),2)end end;A=0;local em=-jZ:dot(k2)if ao and AtmoSpeedAssist and Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle then if throttlePID==nil then throttlePID=pid.new(0.5,0,1)end;throttlePID:inject(bp/3.6-k2:dot(k0))local km=throttlePID:get()C=utils.clamp(km,-1,1)if C<z and j>0.005 then B=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,utils.clamp(C,0.01,1))else B=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,z)end;if brakePID==nil then brakePID=pid.new(1*0.01,0,1*0.1)end;brakePID:inject(k2:len()-bp/3.6)local kn=utils.clamp(brakePID:get(),0,1)if j>0 and em<-80 or j>0.005 then A=kn end;if A>0 then if B and C==0.01 then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)end else C=utils.clamp(C,0.01,1)end;local ko=''local kp=vec3()local kq=composeAxisAccelerationFromTargetSpeedV(axisCommandId.vertical,aa*1000)Nav:setEngineForceCommand("vertical airfoil , vertical ground ",kq,kk)local kr='thrust analog longitudinal 'if ExtraLongitudeTags~="none"then kr=kr..ExtraLongitudeTags end;local ks=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)local kt=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(kr,axisCommandId.longitudinal)local ku=composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral,LeftAmount*1000)ko=ko..' , '.."lateral airfoil , lateral ground "kp=kp+ku;if kp:len()>constants.epsilon then Nav:setEngineForceCommand(ko,kp,kk,'','','',kl)end;Nav:setEngineForceCommand(kr,kt,kj)local kv='thrust analog vertical fueled 'local kw='thrust analog lateral fueled 'if ExtraLateralTags~="none"then kw=kw..ExtraLateralTags end;if ExtraVerticalTags~="none"then kv=kv..ExtraVerticalTags end;if aa~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(kv,kq,kj)else Nav:setEngineForceCommand(kv,vec3(),kj)end;if LeftAmount~=0 then Nav:setEngineForceCommand(kw,ku,kj)else Nav:setEngineForceCommand(kw,vec3(),kj)end;if jY==0 then jY=A end;local kx=-jY*(brakeSpeedFactor*k2+brakeFlatFactor*k3)Nav:setEngineForceCommand('brake',kx)else if AtmoSpeedAssist then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,z)end;local gh=unit.getAxisCommandValue(0)if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed then if brakePID==nil then brakePID=pid.new(10*0.1,0,10*0.1)end;brakePID:inject(k2:len()-gh/3.6)local kn=utils.clamp(brakePID:get(),0,1)jY=utils.clamp(jY+kn,0,1)end;local kx=-jY*(brakeSpeedFactor*k2+brakeFlatFactor*k3)Nav:setEngineForceCommand('brake',kx)local ko=''local kp=vec3()local ky=false;local kr='thrust analog longitudinal 'if ExtraLongitudeTags~="none"then kr=kr..ExtraLongitudeTags end;local ks=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if ks==axisCommandType.byThrottle then local kt=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(kr,axisCommandId.longitudinal)Nav:setEngineForceCommand(kr,kt,kj)elseif ks==axisCommandType.byTargetSpeed then local kt=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)ko=ko..' , '..kr;kp=kp+kt;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then ky=true end end;local kw='thrust analog lateral 'if ExtraLateralTags~="none"then kw=kw..ExtraLateralTags end;local kz=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if kz==axisCommandType.byThrottle then local kA=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(kw,axisCommandId.lateral)Nav:setEngineForceCommand(kw,kA,kj)elseif kz==axisCommandType.byTargetSpeed then local ku=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)ko=ko..' , '..kw;kp=kp+ku end;local kv='thrust analog vertical 'if ExtraVerticalTags~="none"then kv=kv..ExtraVerticalTags end;local kB=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if kB==axisCommandType.byThrottle then local kq=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(kv,axisCommandId.vertical)if aa~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(kv,kq,kj,'airfoil','ground','',kl)else Nav:setEngineForceCommand(kv,vec3(),kj)Nav:setEngineForceCommand('airfoil vertical',kq,kj,'airfoil','','',kl)Nav:setEngineForceCommand('ground vertical',kq,kj,'ground','','',kl)end elseif kB==axisCommandType.byTargetSpeed then if aa<0 then Nav:setEngineForceCommand('hover',vec3(),kj)end;local kC=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)ko=ko..' , '..kv;kp=kp+kC end;if kp:len()>constants.epsilon then if S~=0 or ky or k3:dot(k0)<0.8 then ko=ko..', brake'end;Nav:setEngineForceCommand(ko,kp,kk,'','','',kl)end end;local kD=torqueFactor*(k8-k7)local kE=vec3(core.getWorldAirFrictionAngularAcceleration())kD=kD-kE;Nav:setEngineTorqueCommand('torque',kD,kj,'airfoil','','',kl)Nav:setBoosterCommand('rocket_engine')if a1 and not VanillaRockets then local bX=vec3(core.getVelocity()):len()local kF=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local kG=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if bX*3.6>kG*(1-kF)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bX*3.6<kG*(1-kF)and not IsRocketOn then IsRocketOn=true;Nav:toggleBoosters()end else local fN=unit.getThrottle()if AtmoSpeedAssist then fN=z*100 end;local gh=fN/100;if j==0 then gh=gh*MaxGameVelocity;if bX>=gh*(1-kF)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bX<gh*(1-kF)and not IsRocketOn then IsRocketOn=true;Nav:toggleBoosters()end else gh=gh*ReentrySpeed/3.6;if bX>=gh*(1-kF)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bX<gh*(1-kF)and not IsRocketOn then IsRocketOn=true;Nav:toggleBoosters()end end end end end;function script.onUpdate()if not SetupComplete then local _,bI=coroutine.resume(beginSetup)if bI then SetupComplete=true end else Nav:update()if not bc and content~=LastContent then system.setScreen(content)end;LastContent=content end end;function script.onActionStart(kH)if kH=="gear"then GearExtended=not GearExtended;if GearExtended then VectorToTarget=false;LockPitch=nil;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)z=0;if(vBooster or hover)and al==-1 and(j()>0 or ap<ReentryAltitude)then StrongBrakes=true;Reentry=false;AutoTakeoff=false;VertTakeOff=false;AltitudeHold=false;BrakeLanding=true;be=true;GearExtended=false else BrakeIsOn=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end;if M and not BrakeLanding then Nav.control.extendLandingGears()end else if M then Nav.control.retractLandingGears()end;Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end elseif kH=="light"then if Nav.control.isAnyHeadlightSwitchedOn()==1 then Nav.control.switchOffHeadlights()else Nav.control.switchOnHeadlights()end elseif kH=="forward"then N=N-1 elseif kH=="backward"then N=N+1 elseif kH=="left"then Q=Q-1 elseif kH=="right"then Q=Q+1 elseif kH=="yawright"then R=R-1 elseif kH=="yawleft"then R=R+1 elseif kH=="straferight"then H=false;Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,1.0)LeftAmount=1 elseif kH=="strafeleft"then H=false;Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,-1.0)LeftAmount=-1 elseif kH=="up"then aa=aa+1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,1.0)elseif kH=="down"then aa=aa-1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,-1.0)elseif kH=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitude<HoldAltitude+10 and AntigravTargetAltitude>HoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+Y;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+Y end else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+X elseif IntoOrbit then by=by+X else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif kH=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitude<HoldAltitude+10 and AntigravTargetAltitude>HoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-Y;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-Y;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-X elseif IntoOrbit then by=by-X;if by<planet.noAtmosphericDensityAltitude+100 then by=planet.noAtmosphericDensityAltitude+100 end else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif kH=="option1"then if not Autopilot then IncrementAutopilotTargetIndex()H=false end elseif kH=="option2"then if not Autopilot then DecrementAutopilotTargetIndex()H=false end elseif kH=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;H=false;ToggleWidgets()elseif kH=="option4"then ToggleAutopilot()H=false elseif kH=="option5"then ToggleLockPitch()H=false elseif kH=="option6"then ToggleAltitudeHold()H=false elseif kH=="option7"then wipeSaveVariables()H=false elseif kH=="option8"then ToggleFollowMode()H=false elseif kH=="option9"then if gyro~=nil then gyro.toggle()as=gyro.getState()==1 end;H=false elseif kH=="lshift"then if system.isViewLocked()==1 then V=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif o()==1 and ShiftShowsRemoteButtons then V=true;bd=false;bc=false end elseif kH=="brake"then if BrakeToggleStatus then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif kH=="lalt"then AltIsOn=true;if o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif kH=="booster"then if VanillaRockets then Nav:toggleBoosters()elseif not a1 then if not IsRocketOn then Nav:toggleBoosters()IsRocketOn=true end;a1=true else if IsRocketOn then Nav:toggleBoosters()IsRocketOn=false end;a1=false end elseif kH=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)clearAll()z=0 elseif kH=="speedup"then if not V then if AtmoSpeedAssist and not AltIsOn then z=utils.clamp(z+speedChangeLarge/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)end else IncrementAutopilotTargetIndex()end elseif kH=="speeddown"then if not V then if AtmoSpeedAssist and not AltIsOn then z=utils.clamp(z-speedChangeLarge/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)end else DecrementAutopilotTargetIndex()end elseif kH=="antigravity"and not ExternalAGG then if antigrav~=nil then ToggleAntigrav()end end end;function script.onActionStop(kH)if kH=="forward"then N=0 elseif kH=="backward"then N=0 elseif kH=="left"then Q=0 elseif kH=="right"then Q=0 elseif kH=="yawright"then R=0 elseif kH=="yawleft"then R=0 elseif kH=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)LeftAmount=0 elseif kH=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)LeftAmount=0 elseif kH=="up"then aa=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif kH=="down"then aa=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif kH=="groundaltitudeup"then a0=Y;Z=X;H=false elseif kH=="groundaltitudedown"then a0=Y;Z=X;H=false elseif kH=="lshift"then if system.isViewLocked()==1 then V=false;ab=0;ac=0;system.lockView(PrevViewLock)elseif o()==1 and ShiftShowsRemoteButtons then V=false;bd=false;bc=false end elseif kH=="brake"then if not BrakeToggleStatus then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif kH=="lalt"then if o()==0 and freeLookToggle then if H then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else H=true end elseif o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end;AltIsOn=false end end;function script.onActionLoop(kH)if kH=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitude<HoldAltitude+10 and AntigravTargetAltitude>HoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+a0;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+a0 end;a0=a0*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+Z;Z=Z*1.05 elseif IntoOrbit then by=by+Z;Z=Z*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif kH=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitude<HoldAltitude+10 and AntigravTargetAltitude>HoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-a0;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-a0;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end;a0=a0*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-Z;Z=Z*1.05 elseif IntoOrbit then by=by-Z;if by<planet.noAtmosphericDensityAltitude+100 then by=planet.noAtmosphericDensityAltitude+100 end;Z=Z*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif kH=="speedup"then if not V then if AtmoSpeedAssist and not AltIsOn then z=utils.clamp(z+speedChangeSmall/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end end elseif kH=="speeddown"then if not V then if AtmoSpeedAssist and not AltIsOn then z=utils.clamp(z-speedChangeSmall/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end end;function script.onInputText(dG)local i;local kI="/commands /setname /G /agg /addlocation /copydatabank"local kJ,kK=nil,nil;local kL="Command List:\n/commands \n/setname <newname> - Updates current selected saved position name\n/G VariableName newValue - Updates global variable to new value\n".."/G dump - shows all updatable variables with /G\n/agg <targetheight> - Manually set agg target height\n".."/addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572} - adds a saved location by waypoint, not as accurate as making one at location\n".."/copydatabank - copies dbHud databank to a blank databank"i=string.find(dG," ")kJ=dG;if i~=nil then kJ=string.sub(dG,0,i-1)kK=string.sub(dG,i+1)elseif not string.find(kI,kJ)then for gd in string.gmatch(kL,"([^\n]+)")do c(gd)end;return end;if kJ=="/setname"then if kK==nil or kK==""then W="Usage: /setname Newname"return end;if AutopilotTargetIndex>0 and CustomTarget~=nil then UpdatePosition(kK)else W="Select a saved target to rename first"end elseif kJ=="/addlocation"then if kK==nil or kK==""or string.find(kK,"::")==nil then W="Usage: /addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572}"return end;i=string.find(kK,"::")local cr=string.sub(kK,1,i-2)local cl=string.sub(kK,i)local q=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local cm='::pos{'..q..','..q..','..q..','..q..','..q..'}'local cn,co,ci,cj,ch=string.match(cl,cm)local planet=b2[tonumber(cn)][tonumber(co)]AddNewLocationByWaypoint(cr,planet,cl)W="Added "..cr.." to saved locations,\nplanet "..planet.name.." at "..cl;ad=5 elseif kJ=="/agg"then if kK==nil or kK==""then W="Usage: /agg targetheight"return end;kK=tonumber(kK)if kK<1000 then kK=1000 end;AntigravTargetAltitude=kK;W="AGG Target Height set to "..kK elseif kJ=="/G"then if kK==nil or kK==""then W="Usage: /G VariableName variablevalue\n/G dump - shows all variables"return end;if kK=="dump"then for bG,bH in pairs(a)do if type(_G[bH])=="boolean"then if _G[bH]==true then c(bH.." true")else c(bH.." false")end elseif _G[bH]==nil then c(bH.." nil")else c(bH.." ".._G[bH])end end;return end;i=string.find(kK," ")local kM=string.sub(kK,0,i-1)local kN=string.sub(kK,i+1)for bG,bH in pairs(a)do if bH==kM then W="Variable "..kM.." changed to "..kN;local kO=type(_G[bH])if kO=="number"then kN=tonumber(kN)elseif kO=="boolean"then if string.lower(kN)=="true"then kN=true else kN=false end end;_G[bH]=kN;return end end;W="No such global variable: "..kM elseif kJ=="/copydatabank"then if dbHud_2 then SaveDataBank(true)else W="Databank required to copy databank"end end end;script.onStart()
-- error handling code added by wrap.lua
end, __wrap_lua__traceback)
if not ok then
__wrap_lua__error(message)
if not script then script = {} end
end
stop:
lua: |
if not __wrap_lua__stopped and script.onStop then
local ok, message = xpcall(script.onStop,__wrap_lua__traceback,unit)
if not ok then __wrap_lua__error(message) end
end
tick(timerId):
lua: |
if not __wrap_lua__stopped and script.onTick then
local ok, message = xpcall(script.onTick,__wrap_lua__traceback,timerId,unit)
if not ok then __wrap_lua__error(message) end
end
system:
actionStart(action):
lua: |
if not __wrap_lua__stopped and script.onActionStart then
local ok, message = xpcall(script.onActionStart,__wrap_lua__traceback,action,system)
if not ok then __wrap_lua__error(message) end
end
actionStop(action):
lua: |
if not __wrap_lua__stopped and script.onActionStop then
local ok, message = xpcall(script.onActionStop,__wrap_lua__traceback,action,system)
if not ok then __wrap_lua__error(message) end
end
actionLoop(action):
lua: |
if not __wrap_lua__stopped and script.onActionLoop then
local ok, message = xpcall(script.onActionLoop,__wrap_lua__traceback,action,system)
if not ok then __wrap_lua__error(message) end
end
update:
lua: |
if not __wrap_lua__stopped and script.onUpdate then
local ok, message = xpcall(script.onUpdate,__wrap_lua__traceback,system)
if not ok then __wrap_lua__error(message) end
end
flush:
lua: |
if not __wrap_lua__stopped and script.onFlush then
local ok, message = xpcall(script.onFlush,__wrap_lua__traceback,system)
if not ok then __wrap_lua__error(message) end
end
inputText(text):
lua: |
if not __wrap_lua__stopped and script.onInputText then
local ok, message = xpcall(script.onInputText,__wrap_lua__traceback,text,system)
if not ok then __wrap_lua__error(message) end
end