diff --git a/ButtonHUD.conf b/ButtonHUD.conf index 6ff5263..203b2bd 100644 --- a/ButtonHUD.conf +++ b/ButtonHUD.conf @@ -1,4 +1,4 @@ -name: ButtonsHud - Dimencia and Archaegeo v4.835 (Minified) +name: ButtonsHud - Dimencia and Archaegeo v4.836 (Minified) slots: core: class: CoreUnit @@ -117,6 +117,7 @@ handlers: circleRad = 400 --export: The size of the artifical horizon circle, recommended minimum 100, maximum 400. Looks different > 200. Set to 0 to remove. DeadZone = 50 --export: Number of pixels of deadzone at the center of the screen showHud = true --export: Uncheck to hide the HUD and only use autopilot features via ALT+# keys. + ShowOdometer = true --export: Uncheck to hide the odometer panel up top. hideHudOnToggleWidgets = true --export: Uncheck to keep showing HUD when you toggle on the widgets via ALT+3. ShiftShowsRemoteButtons = true --export: Whether or not pressing Shift in remote controller mode shows you the buttons (otherwise no access to them) StallAngle = 35 --export: Determines how much Autopilot is allowed to make you yaw/pitch in atmosphere. Also gives a stall warning when not autopilot. (default 35, higher = more tolerance for yaw/pitch/roll) @@ -153,10 +154,10 @@ handlers: fuelTankHandlingSpace = 0 --export: For accurate estimates, set this to the fuel tank handling level of the person who placed the element. Ignored for slotted tanks. fuelTankHandlingRocket = 0 --export: For accurate estimates, set this to the fuel tank handling level of the person who placed the element. Ignored for slotted tanks. apTickRate = 0.0166667 --export: Set the Tick Rate for your HUD. 0.016667 is effectively 60 fps and the default value. 0.03333333 is 30 fps. The bigger the number the less often the autopilot and hud updates but may help peformance on slower machings. - script={}function script.onStart()SetupComplete=false;beginSetup=coroutine.create(function()Nav=Navigator.new(system,core,unit)Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal,{1000,5000,10000,20000,30000})VERSION_NUMBER=4.835;local a=math.floor;local b=string.format;local c=json.decode;local d=json.encode;local e=core.getElementMaxHitPointsById;local f=unit.getAtmosphereDensity;local g=core.getElementHitPointsById;local h=core.getElementTypeById;local j=core.getElementMassById;local k=core.getConstructMass;local l=Nav.control.isRemoteControlled;APThrottleSet=false;ToggleView=true;MinAutopilotSpeed=55;LastMaxBrake=0;LastMaxBrakeInAtmo=0;EmergencyWarp=false;ReentryMode=false;MousePitchFactor=1;MouseYawFactor=1;HasGear=false;PitchInput=0;PitchInput2=0;YawInput2=0;RollInput=0;YawInput=0;BrakeInput=0;RollInput2=0;RetrogradeIsOn=false;ProgradeIsOn=false;Reentry=false;FollowMode=false;TurnBurn=false;AutopilotAccelerating=false;AutopilotRealigned=false;HoldingCtrl=false;PrevViewLock=1;MsgText="empty"LastEccentricity=1;HoldAltitudeButtonModifier=5;AntiGravButtonModifier=5;IsBoosting=false;BrakeDistance,BrakeTime=0;MaxBrakeDistance,MaxBrakeTime=0;HasSpaceRadar=false;HasAtmoRadar=false;AutopilotTargetIndex=0;AutopilotTargetName="None"AutopilotTargetPlanet=nil;TotalDistanceTravelled=0.0;TotalDistanceTrip=0;InEmergencyWarp=false;NotTriedEmergencyWarp=true;FlightTime=0;WipedDatabank=false;LocationIndex=0;UpAmount=0;BrakeIsOn=false;Autopilot=false;AltitudeHold=false;BrakeLanding=false;AutoTakeoff=false;HoldAltitude=1000;AutopilotBraking=false;AutopilotCruising=false;VectorToTarget=false;SimulatedX=0;SimulatedY=0;AutopilotStatus="Aligning"MsgTimer=3;TargetGroundAltitude=nil;GearExtended=nil;Distance=0;RadarMessage=""LastOdometerOutput=""Peris=0;CoreAltitude=core.getAltitude()AntigravTargetAltitude=CoreAltitude;ElementsID=core.getElementIdList()LastTravelTime=system.getTime()TotalFlightTime=0;HasGear=false;AutopilotPlanetGravity=0;DisplayOrbit=true;AutopilotEndSpeed=0;SavedLocations={}LandingGearGroundHeight=0;SpaceLand=false;SpaceLaunch=false;FinalLand=false;HovGndDet=-1;local m={}local n=0;local o=0;local p=""local q=true;local r={}local s=1;local t=0.001;local u=2560;local v=1440;local w=nil;local x=nil;local y=nil;local z=nil;local A=false;local B=false;local C=0;local D=nil;local E={}local F={}local G={}local H=0;local I=false;local J={}local K={}local L=a(1/apTickRate)*2;local M={}local N={}local O={}local P={}local Q=false;local R=16;local S=0;SaveableVariables={"userControlScheme","AutopilotTargetOrbit","apTickRate","freeLookToggle","turnAssist","PrimaryR","PrimaryG","PrimaryB","warmup","DeadZone","circleRad","MouseXSensitivity","MouseYSensitivity","MaxGameVelocity","showHud","autoRollPreference","pitchSpeedFactor","yawSpeedFactor","rollSpeedFactor","brakeSpeedFactor","brakeFlatFactor","autoRollFactor","turnAssistFactor","torqueFactor","AutoTakeoffAltitude","TargetHoverHeight","AutopilotInterplanetaryThrottle","hideHudOnToggleWidgets","DampingMultiplier","fuelTankHandlingAtmo","fuelTankHandlingSpace","fuelTankHandlingRocket","RemoteFreeze","speedChangeLarge","speedChangeSmall","brightHud","brakeLandingRate","MaxPitch","ReentrySpeed","ReentryAltitude","EmergencyWarpDistance","centerX","centerY","vSpdMeterX","vSpdMeterY","altMeterX","altMeterY","fuelX","fuelY","LandingGearGroundHeight","TrajectoryAlignmentStrength","RemoteHud","RequireLock","StallAngle"}AutoVariables={"EmergencyWarp","brakeToggle","BrakeIsOn","RetrogradeIsOn","ProgradeIsOn","Autopilot","TurnBurn","AltitudeHold","DisplayOrbit","BrakeLanding","Reentry","AutoTakeoff","HoldAltitude","AutopilotAccelerating","AutopilotBraking","AutopilotCruising","AutopilotRealigned","AutopilotEndSpeed","AutopilotStatus","AutopilotPlanetGravity","PrevViewLock","AutopilotTargetName","AutopilotTargetCoords","AutopilotTargetIndex","GearExtended","TargetGroundAltitude","TotalDistanceTravelled","TotalFlightTime","SavedLocations","VectorToTarget","LocationIndex","LastMaxBrake","LastMaxBrakeInAtmo","AntigravTargetAltitude"}if dbHud then local T=dbHud.hasKey;if not useTheseSettings then for U,V in pairs(SaveableVariables)do if T(V)then local W=c(dbHud.getStringValue(V))if W~=nil then system.print(V.." "..dbHud.getStringValue(V))_G[V]=W;A=true end end end end;for U,V in pairs(AutoVariables)do if T(V)then local W=c(dbHud.getStringValue(V))if W~=nil then system.print(V.." "..dbHud.getStringValue(V))_G[V]=W;A=true end end end;if useTheseSettings then MsgText="Updated user preferences used. Will be saved when you exit seat. Toggle off useTheseSettings to use saved values"elseif A then MsgText="Loaded Saved Variables (see Lua Chat Tab for list)"else MsgText="No Saved Variables Found - Stand up / leave remote to save settings"end else MsgText="No databank found, install one anywhere and rerun the autoconfigure to save variables"end;brakeToggle=BrakeToggleDefault;userControlScheme=string.lower(userControlScheme)if string.find("keyboard virtual joystick mouse",userControlScheme)==nil then MsgText="Invalid User Control Scheme selected. Change userControlScheme in Lua Parameters to keyboard, mouse, or virtual joystick"end;MinimumRateOfChange=math.cos(StallAngle*constants.deg2rad)autoRoll=autoRollPreference;if antigrav then if AntigravTargetAltitude==nil then AntigravTargetAltitude=CoreAltitude end;antigrav.setBaseAltitude(AntigravTargetAltitude)end;rgb=[[rgb(]]..a(PrimaryR+0.5)..","..a(PrimaryG+0.5)..","..a(PrimaryB+0.5)..[[)]]local X=[[rgb(]]..a(PrimaryR*0.9+0.5)..","..a(PrimaryG*0.9+0.5)..","..a(PrimaryB*0.9+0.5)..[[)]]coroutine.yield()for U in pairs(ElementsID)do local type=h(ElementsID[U])if type=="landing gear"then HasGear=true end;if type=="dynamic core"then local Y=e(ElementsID[U])if Y>10000 then R=128 elseif Y>1000 then R=64 elseif Y>150 then R=32 end end;H=H+e(ElementsID[U])if fuelX~=0 and fuelY~=0 then if type=="atmospheric fuel-tank"or type=="space fuel-tank"or type=="rocket fuel-tank"then local Y=e(ElementsID[U])local Z=j(ElementsID[U])local a0=0;local a1=system.getTime()if type=="atmospheric fuel-tank"then local a2=400;local a3=35.03;if Y>10000 then a2=51200;a3=5480 elseif Y>1300 then a2=6400;a3=988.67 elseif Y>150 then a2=1600;a3=182.67 end;a0=Z-a3;if fuelTankHandlingAtmo>0 then a2=a2+a2*fuelTankHandlingAtmo*0.2 end;if a0>a2 then a2=a0 end;E[#E+1]={ElementsID[U],core.getElementNameById(ElementsID[U]),a2,a3,a0,a1}end;if type=="rocket fuel-tank"then local a2=320;local a3=173.42;if Y>65000 then a2=40000;a3=25740 elseif Y>6000 then a2=5120;a3=4720 elseif Y>700 then a2=640;a3=886.72 end;a0=Z-a3;if fuelTankHandlingRocket>0 then a2=a2+a2*fuelTankHandlingRocket*0.2 end;if a0>a2 then a2=a0 end;G[#G+1]={ElementsID[U],core.getElementNameById(ElementsID[U]),a2,a3,a0,a1}end;if type=="space fuel-tank"then local a2=2400;local a3=182.67;if Y>10000 then a2=76800;a3=5480 elseif Y>1300 then a2=9600;a3=988.67 end;a0=Z-a3;if fuelTankHandlingSpace>0 then a2=a2+a2*fuelTankHandlingSpace*0.2 end;if a0>a2 then a2=a0 end;F[#F+1]={ElementsID[U],core.getElementNameById(ElementsID[U]),a2,a3,a0,a1}end end end end;if gyro~=nil then GyroIsOn=gyro.getState()==1 end;if userControlScheme~="keyboard"then system.lockView(1)else system.lockView(0)end;if f()>0 then BrakeIsOn=true end;if radar_1 then if h(radar_1.getId())=="Space Radar"then HasSpaceRadar=true else HasAtmoRadar=true end end;if door then for _,V in pairs(door)do V.deactivate()end end;if forcefield then for _,V in pairs(forcefield)do V.deactivate()end end;if antigrav~=nil then if antigrav.getState()==1 then antigrav.show()end end;if l()==1 and RemoteFreeze then system.freeze(1)else system.freeze(0)end;if HasGear then GearExtended=Nav.control.isAnyLandingGearExtended()==1;if GearExtended then Nav.control.extendLandingGears()else Nav.control.retractLandingGears()end end;if TargetGroundAltitude~=nil then Nav.axisCommandManager:setTargetGroundAltitude(TargetGroundAltitude)if TargetGroundAltitude==0 and not HasGear then GearExtended=true end else if GearExtended or not HasGear then Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)GearExtended=true else Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end end;if f()>0 and not dbHud and(GearExtended or not HasGear)then BrakeIsOn=true end;WasInAtmo=f()>0;unit.hide()function refreshLastMaxBrake(a4,a5)if a4==nil then a4=core.g()end;a4=round(a4,5)if a5~=nil and a5 or(D==nil or D~=a4)then local a6=c(unit.getData()).maxBrake;if a6~=nil then LastMaxBrake=a6 end;if f()>0 then LastMaxBrakeInAtmo=a6 end;D=a4 end end;function MakeButton(a7,a8,a9,aa,ab,ac,ad,ae,af)local ag={enableName=a7,disableName=a8,width=a9,height=aa,x=ab,y=ac,toggleVar=ad,toggleFunction=ae,drawCondition=af,hovered=false}table.insert(r,ag)return ag end;function UpdateAtlasLocationsList()AtlasOrdered={}for U,V in pairs(atlas[0])do table.insert(AtlasOrdered,{name=V.name,index=U})end;local function ah(ai,aj)return ai.name-1 then atlas[0][an]=am end;UpdateAtlasLocationsList()MsgText=CustomTarget.name.." position updated"end end;function ClearCurrentPosition()local an=-1;for U,V in pairs(atlas[0])do if V.name and V.name==CustomTarget.name then an=U end end;if an>-1 then table.remove(atlas[0],an)end;an=-1;for U,V in pairs(SavedLocations)do if V.name and V.name==CustomTarget.name then MsgText=V.name.." saved location cleared"an=U;break end end;if an~=-1 then table.remove(SavedLocations,an)end;DecrementAutopilotTargetIndex()UpdateAtlasLocationsList()end;function DrawDeadZone(ao)ao[#ao+1]=b([[]],DeadZone)end;function ToggleRadarPanel()if radarPanelID~=nil and Peris==0 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;if perisPanelID~=nil then system.destroyWidgetPanel(perisPanelID)perisPanelID=nil end else if Peris==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;Peris=0 end end;function ToggleWidgets()if q 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;q=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;q=true end end;function SetupInterplanetaryPanel()InAtmo=f()>0;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 InAtmo then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;widgetCurBrakeTime=system.createWidget(panelInterplanetary,"value")widgetCurBrakeTimeText=system.createData('{"label": "Cur Brake Time", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;widgetMaxBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeDistanceText=system.createData('{"label": "Max Brake Distance", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;widgetMaxBrakeTime=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeTimeText=system.createData('{"label": "Max Brake Time", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;widgetTrajectoryAltitude=system.createWidget(panelInterplanetary,"value")widgetTrajectoryAltitudeText=system.createData('{"label": "Projected Altitude", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;function Contains(ap,aq,ab,ac,a9,aa)if ap>ab and apac and aqMinAutopilotSpeed then MsgText="WARNING: Insufficient Brakes - Attempting coast landing, beware obstacles"end;if not AltitudeHold then ToggleAltitudeHold()end;AutoTakeoff=false;BrakeLanding=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)end end;function ToggleAutoTakeoff()if AutoTakeoff then AutoTakeoff=false;if AltitudeHold then ToggleAltitudeHold()end else if not AltitudeHold then ToggleAltitudeHold()end;AutoTakeoff=true;HoldAltitude=CoreAltitude+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end end;function ToggleAltitudeHold()AltitudeHold=not AltitudeHold;if AltitudeHold then Autopilot=false;ProgradeIsOn=false;RetrogradeIsOn=false;FollowMode=false;BrakeLanding=false;Reentry=false;autoRoll=true;if not GearExtended and not BrakeIsOn or f()==0 then AutoTakeoff=false;HoldAltitude=CoreAltitude;if not SpaceLaunch and Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end else AutoTakeoff=true;HoldAltitude=CoreAltitude+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end;if SpaceLaunch then HoldAltitude=100000 end else autoRoll=autoRollPreference;AutoTakeoff=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;VectorToTarget=false end end;function ToggleFollowMode()if l()==1 then FollowMode=not FollowMode;if FollowMode 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;autoRoll=autoRollPreference;GearExtended=OldGearExtended;if GearExtended then Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end end else MsgText="Follow Mode only works with Remote controller"FollowMode=false end end;function ToggleAutopilot()if AutopilotTargetIndex>0 and not Autopilot then if CustomTarget~=nil then if planet.name==CustomTarget.planetname then StrongBrakes=planet.gravity*9.80665*core.getConstructMass()MinAutopilotSpeed then MsgText="Insufficient Brake Force\nCoast landing will be inaccurate"end;if unit.getAtmosphereDensity()>0 then if not AltitudeHold then if not VectorToTarget then ToggleVectorToTarget()end else if not VectorToTarget then ToggleVectorToTarget()end end else SpaceLand=true end else SpaceLaunch=true;if unit.getAtmosphereDensity()~=0 then ToggleAltitudeHold()else Autopilot=true end end elseif unit.getAtmosphereDensity()==0 then Autopilot=true;RetrogradeIsOn=false;ProgradeIsOn=false;AutopilotRealigned=false;FollowMode=false;AltitudeHold=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;APThrottleSet=false else SpaceLaunch=true;ToggleAltitudeHold()end else Autopilot=false;AutopilotRealigned=false;VectorToTarget=false;APThrottleSet=false end end;function ProgradeToggle()ProgradeIsOn=not ProgradeIsOn;RetrogradeIsOn=false;Autopilot=false;AltitudeHold=false;FollowMode=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false end;function RetrogradeToggle()RetrogradeIsOn=not RetrogradeIsOn;ProgradeIsOn=false;Autopilot=false;AltitudeHold=false;FollowMode=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false end;function BrakeToggle()BrakeIsOn=not BrakeIsOn;if BrakeLanding then BrakeLanding=false;autoRoll=autoRollPreference end;if BrakeIsOn then AltitudeHold=false;VectorToTarget=false;AutoTakeoff=false;Reentry=false;ProgradeIsOn=false;BrakeLanding=false;AutoLanding=false;AltitudeHold=false;autoRoll=autoRollPreference end end;function checkDamage(ao)local ar=0;p=""local as=H;local at=0;local au=0;local av=0;local aw=0;local ax=""for U in pairs(ElementsID)do local Y=0;local ay=0;ay=e(ElementsID[U])Y=g(ElementsID[U])at=at+Y;if Y0 and m[11]==ElementsID[U]then for aA in pairs(m)do core.deleteSticker(m[aA])end;m={}end end;ar=a(at/as*100)if ar<100 then ao[#ao+1]=[[]]aw=a(ar*2.55)ax=b("rgb(%d,%d,%d)",255-aw,aw,0)if ar<100 then ao[#ao+1]=b([[Elemental Integrity: %i %%]],ax,ar)if av>0 then ao[#ao+1]=b([[Disabled Modules: %i Damaged Modules: %i]],ax,av,au)elseif au>0 then ao[#ao+1]=b([[Damaged Modules: %i]],ax,au)end end;ao[#ao+1]=[[<\g>]]end end;function DrawCursorLine(ao)local aB=a(utils.clamp(Distance/(u/4)*255,0,255))ao[#ao+1]=b("",SimulatedX,SimulatedY,a(PrimaryR+0.5)+aB,a(PrimaryG+0.5)-aB,a(PrimaryB+0.5)-aB)end;function getPitch(aC,aD,aj)local aE=aC:cross(aj):normalize_inplace()local aF=math.acos(utils.clamp(aE:dot(-aD),-1,1))*constants.rad2deg;if aE:cross(-aD):dot(aj)<0 then aF=-aF end;return aF end;function wipeSaveVariables()if not dbHud then MsgText="No Databank Found, unable to wipe. \nYou must have a Databank attached to ship prior to running the HUD autoconfigure"MsgTimer=5 else if B then for U,V in pairs(SaveableVariables)do dbHud.setStringValue(V,d(nil))end;for U,V in pairs(AutoVariables)do if V~="SavedLocations"then dbHud.setStringValue(V,d(nil))end end;MsgText="Databank wiped. New variables will save after re-enter seat and exit"MsgTimer=5;B=false;A=false;WipedDatabank=true else MsgText="Press ALT-7 again to confirm wipe of ALL data"B=true end end end;function CheckButtons()for _,V in pairs(r)do if V.hovered then if not V.drawCondition or V.drawCondition()then V.toggleFunction()end;V.hovered=false end end end;function SetButtonContains()local ab=SimulatedX+u/2;local ac=SimulatedY+v/2;for _,V in pairs(r)do V.hovered=Contains(ab,ac,V.x,V.y,V.width,V.height)end end;function DrawButton(ao,aG,hover,ab,ac,aH,aI,aJ,aK,aL,aM)if type(aL)=="function"then aL=aL()end;if type(aM)=="function"then aM=aM()end;ao[#ao+1]=b(""if aG then ao[#ao+1]=b("%s",aL)else ao[#ao+1]=b("%s",aM)end end;function DrawButtons(ao)local aN="rgb(50,50,50)'"local aO="rgb(210,200,200)"local aP=DrawButton;for _,V in pairs(r)do local a8=V.disableName;local a7=V.enableName;if type(a8)=="function"then a8=a8()end;if type(a7)=="function"then a7=a7()end;if not V.drawCondition or V.drawCondition()then aP(ao,V.toggleVar(),V.hovered,V.x,V.y,V.width,V.height,aO,aN,a8,a7)end end end;function DrawTank(ao,Q,ab,aQ,aR,aS,aT,aU)local aV=1;local aW=2;local aX=3;local aY=4;local aZ=5;local a_=6;local b0=""local b1=0;local b2=fuelY;local b3=fuelY+10;if l()==1 and not RemoteHud then b2=b2-50;b3=b3-50 end;ao[#ao+1]=[[]]if aR=="ATMO"then b0="atmofueltank"elseif aR=="SPACE"then b0="spacefueltank"else b0="rocketfueltank"end;b1=_G[b0 .."_size"]if#aS>0 then for i=1,#aS do local ak=string.sub(aS[i][aW],1,12)local b4=0;for aA=1,b1 do if aS[i][aW]==json.decode(unit[b0 .."_"..aA].getData()).name then b4=aA;break end end;if Q or aT[i]==nil or aU[i]==nil then local b5=0;local b6=0;local b7=0;local b8=0;local a1=system.getTime()if b4~=0 then aU[i]=json.decode(unit[b0 .."_"..b4].getData()).percentage;aT[i]=json.decode(unit[b0 .."_"..b4].getData()).timeLeft;if aT[i]=="n/a"then aT[i]=0 end else b7=j(aS[i][aV])-aS[i][aY]b5=aS[i][aX]aU[i]=a(0.5+b7*100/b5)b6=aS[i][aZ]b8=aS[i][a_]if b6<=b7 then aT[i]=0 else aT[i]=a(0.5+b7/((b6-b7)/(a1-b8)))end;aS[i][aZ]=b7;aS[i][a_]=a1 end end;if ak==aQ then ak=b("%s %d",aR,i)end;if b4==0 then ak=ak.." *"end;local b9;if aT[i]==0 then b9="n/a"else b9=FormatTimeString(aT[i])end;if aU[i]~=nil then local aw=a(aU[i]*2.55)local ax=b("rgb(%d,%d,%d)",255-aw,aw,0)local ba=""if b9~="n/a"and aT[i]<120 or aU[i]<5 then if Q then ba=[[class="red"]]end end;ao[#ao+1]=b([[ + script={}function script.onStart()SetupComplete=false;beginSetup=coroutine.create(function()Nav=Navigator.new(system,core,unit)Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal,{1000,5000,10000,20000,30000})VERSION_NUMBER=4.836;local a=math.floor;local b=string.format;local c=json.decode;local d=json.encode;local e=core.getElementMaxHitPointsById;local f=unit.getAtmosphereDensity;local g=core.getElementHitPointsById;local h=core.getElementTypeById;local j=core.getElementMassById;local k=core.getConstructMass;local l=Nav.control.isRemoteControlled;APThrottleSet=false;ToggleView=true;MinAutopilotSpeed=55;LastMaxBrake=0;LastMaxBrakeInAtmo=0;EmergencyWarp=false;ReentryMode=false;MousePitchFactor=1;MouseYawFactor=1;HasGear=false;PitchInput=0;PitchInput2=0;YawInput2=0;RollInput=0;YawInput=0;BrakeInput=0;RollInput2=0;RetrogradeIsOn=false;ProgradeIsOn=false;Reentry=false;FollowMode=false;TurnBurn=false;AutopilotAccelerating=false;AutopilotRealigned=false;HoldingCtrl=false;PrevViewLock=1;MsgText="empty"LastEccentricity=1;HoldAltitudeButtonModifier=5;AntiGravButtonModifier=5;IsBoosting=false;BrakeDistance,BrakeTime=0;MaxBrakeDistance,MaxBrakeTime=0;HasSpaceRadar=false;HasAtmoRadar=false;AutopilotTargetIndex=0;AutopilotTargetName="None"AutopilotTargetPlanet=nil;TotalDistanceTravelled=0.0;TotalDistanceTrip=0;InEmergencyWarp=false;NotTriedEmergencyWarp=true;FlightTime=0;WipedDatabank=false;LocationIndex=0;UpAmount=0;BrakeIsOn=false;Autopilot=false;AltitudeHold=false;BrakeLanding=false;AutoTakeoff=false;HoldAltitude=1000;AutopilotBraking=false;AutopilotCruising=false;VectorToTarget=false;SimulatedX=0;SimulatedY=0;AutopilotStatus="Aligning"MsgTimer=3;TargetGroundAltitude=nil;GearExtended=nil;Distance=0;RadarMessage=""LastOdometerOutput=""Peris=0;CoreAltitude=core.getAltitude()AntigravTargetAltitude=CoreAltitude;ElementsID=core.getElementIdList()LastTravelTime=system.getTime()TotalFlightTime=0;HasGear=false;AutopilotPlanetGravity=0;DisplayOrbit=true;AutopilotEndSpeed=0;SavedLocations={}LandingGearGroundHeight=0;SpaceLand=false;SpaceLaunch=false;FinalLand=false;HovGndDet=-1;local m={}local n=0;local o=0;local p=""local q=true;local r={}local s=1;local t=0.001;local u=2560;local v=1440;local w=nil;local x=nil;local y=nil;local z=nil;local A=false;local B=false;local C=0;local D=nil;local E={}local F={}local G={}local H=0;local I=false;local J={}local K={}local L=a(1/apTickRate)*2;local M={}local N={}local O={}local P={}local Q=false;local R=16;local S=0;SaveableVariables={"userControlScheme","AutopilotTargetOrbit","apTickRate","freeLookToggle","turnAssist","PrimaryR","PrimaryG","PrimaryB","warmup","DeadZone","circleRad","MouseXSensitivity","MouseYSensitivity","MaxGameVelocity","showHud","autoRollPreference","pitchSpeedFactor","yawSpeedFactor","rollSpeedFactor","brakeSpeedFactor","brakeFlatFactor","autoRollFactor","turnAssistFactor","torqueFactor","AutoTakeoffAltitude","TargetHoverHeight","AutopilotInterplanetaryThrottle","hideHudOnToggleWidgets","DampingMultiplier","fuelTankHandlingAtmo","fuelTankHandlingSpace","fuelTankHandlingRocket","RemoteFreeze","speedChangeLarge","speedChangeSmall","brightHud","brakeLandingRate","MaxPitch","ReentrySpeed","ReentryAltitude","EmergencyWarpDistance","centerX","centerY","vSpdMeterX","vSpdMeterY","altMeterX","altMeterY","fuelX","fuelY","LandingGearGroundHeight","TrajectoryAlignmentStrength","RemoteHud","RequireLock","StallAngle"}AutoVariables={"EmergencyWarp","brakeToggle","BrakeIsOn","RetrogradeIsOn","ProgradeIsOn","Autopilot","TurnBurn","AltitudeHold","DisplayOrbit","BrakeLanding","Reentry","AutoTakeoff","HoldAltitude","AutopilotAccelerating","AutopilotBraking","AutopilotCruising","AutopilotRealigned","AutopilotEndSpeed","AutopilotStatus","AutopilotPlanetGravity","PrevViewLock","AutopilotTargetName","AutopilotTargetCoords","AutopilotTargetIndex","GearExtended","TargetGroundAltitude","TotalDistanceTravelled","TotalFlightTime","SavedLocations","VectorToTarget","LocationIndex","LastMaxBrake","LastMaxBrakeInAtmo","AntigravTargetAltitude"}if dbHud then local T=dbHud.hasKey;if not useTheseSettings then for U,V in pairs(SaveableVariables)do if T(V)then local W=c(dbHud.getStringValue(V))if W~=nil then system.print(V.." "..dbHud.getStringValue(V))_G[V]=W;A=true end end end end;for U,V in pairs(AutoVariables)do if T(V)then local W=c(dbHud.getStringValue(V))if W~=nil then system.print(V.." "..dbHud.getStringValue(V))_G[V]=W;A=true end end end;if useTheseSettings then MsgText="Updated user preferences used. Will be saved when you exit seat. Toggle off useTheseSettings to use saved values"elseif A then MsgText="Loaded Saved Variables (see Lua Chat Tab for list)"else MsgText="No Saved Variables Found - Stand up / leave remote to save settings"end else MsgText="No databank found, install one anywhere and rerun the autoconfigure to save variables"end;brakeToggle=BrakeToggleDefault;userControlScheme=string.lower(userControlScheme)if string.find("keyboard virtual joystick mouse",userControlScheme)==nil then MsgText="Invalid User Control Scheme selected. Change userControlScheme in Lua Parameters to keyboard, mouse, or virtual joystick"end;MinimumRateOfChange=math.cos(StallAngle*constants.deg2rad)autoRoll=autoRollPreference;if antigrav then if AntigravTargetAltitude==nil then AntigravTargetAltitude=CoreAltitude end;antigrav.setBaseAltitude(AntigravTargetAltitude)end;rgb=[[rgb(]]..a(PrimaryR+0.5)..","..a(PrimaryG+0.5)..","..a(PrimaryB+0.5)..[[)]]local X=[[rgb(]]..a(PrimaryR*0.9+0.5)..","..a(PrimaryG*0.9+0.5)..","..a(PrimaryB*0.9+0.5)..[[)]]coroutine.yield()for U in pairs(ElementsID)do local type=h(ElementsID[U])if type=="landing gear"then HasGear=true end;if type=="dynamic core"then local Y=e(ElementsID[U])if Y>10000 then R=128 elseif Y>1000 then R=64 elseif Y>150 then R=32 end end;H=H+e(ElementsID[U])if fuelX~=0 and fuelY~=0 then if type=="atmospheric fuel-tank"or type=="space fuel-tank"or type=="rocket fuel-tank"then local Y=e(ElementsID[U])local Z=j(ElementsID[U])local a0=0;local a1=system.getTime()if type=="atmospheric fuel-tank"then local a2=400;local a3=35.03;if Y>10000 then a2=51200;a3=5480 elseif Y>1300 then a2=6400;a3=988.67 elseif Y>150 then a2=1600;a3=182.67 end;a0=Z-a3;if fuelTankHandlingAtmo>0 then a2=a2+a2*fuelTankHandlingAtmo*0.2 end;if a0>a2 then a2=a0 end;E[#E+1]={ElementsID[U],core.getElementNameById(ElementsID[U]),a2,a3,a0,a1}end;if type=="rocket fuel-tank"then local a2=320;local a3=173.42;if Y>65000 then a2=40000;a3=25740 elseif Y>6000 then a2=5120;a3=4720 elseif Y>700 then a2=640;a3=886.72 end;a0=Z-a3;if fuelTankHandlingRocket>0 then a2=a2+a2*fuelTankHandlingRocket*0.2 end;if a0>a2 then a2=a0 end;G[#G+1]={ElementsID[U],core.getElementNameById(ElementsID[U]),a2,a3,a0,a1}end;if type=="space fuel-tank"then local a2=2400;local a3=182.67;if Y>10000 then a2=76800;a3=5480 elseif Y>1300 then a2=9600;a3=988.67 end;a0=Z-a3;if fuelTankHandlingSpace>0 then a2=a2+a2*fuelTankHandlingSpace*0.2 end;if a0>a2 then a2=a0 end;F[#F+1]={ElementsID[U],core.getElementNameById(ElementsID[U]),a2,a3,a0,a1}end end end end;if gyro~=nil then GyroIsOn=gyro.getState()==1 end;if userControlScheme~="keyboard"then system.lockView(1)else system.lockView(0)end;if f()>0 then BrakeIsOn=true end;if radar_1 then if h(radar_1.getId())=="Space Radar"then HasSpaceRadar=true else HasAtmoRadar=true end end;if door then for _,V in pairs(door)do V.deactivate()end end;if forcefield then for _,V in pairs(forcefield)do V.deactivate()end end;if antigrav~=nil then if antigrav.getState()==1 then antigrav.show()end end;if l()==1 and RemoteFreeze then system.freeze(1)else system.freeze(0)end;if HasGear then GearExtended=Nav.control.isAnyLandingGearExtended()==1;if GearExtended then Nav.control.extendLandingGears()else Nav.control.retractLandingGears()end end;if TargetGroundAltitude~=nil then Nav.axisCommandManager:setTargetGroundAltitude(TargetGroundAltitude)if TargetGroundAltitude==0 and not HasGear then GearExtended=true end else if GearExtended or not HasGear then Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)GearExtended=true else Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end end;if f()>0 and not dbHud and(GearExtended or not HasGear)then BrakeIsOn=true end;WasInAtmo=f()>0;unit.hide()function refreshLastMaxBrake(a4,a5)if a4==nil then a4=core.g()end;a4=round(a4,5)if a5~=nil and a5 or(D==nil or D~=a4)then local a6=c(unit.getData()).maxBrake;if a6~=nil then LastMaxBrake=a6 end;if f()>0 then LastMaxBrakeInAtmo=a6 end;D=a4 end end;function MakeButton(a7,a8,a9,aa,ab,ac,ad,ae,af)local ag={enableName=a7,disableName=a8,width=a9,height=aa,x=ab,y=ac,toggleVar=ad,toggleFunction=ae,drawCondition=af,hovered=false}table.insert(r,ag)return ag end;function UpdateAtlasLocationsList()AtlasOrdered={}for U,V in pairs(atlas[0])do table.insert(AtlasOrdered,{name=V.name,index=U})end;local function ah(ai,aj)return ai.name-1 then atlas[0][an]=am end;UpdateAtlasLocationsList()MsgText=CustomTarget.name.." position updated"end end;function ClearCurrentPosition()local an=-1;for U,V in pairs(atlas[0])do if V.name and V.name==CustomTarget.name then an=U end end;if an>-1 then table.remove(atlas[0],an)end;an=-1;for U,V in pairs(SavedLocations)do if V.name and V.name==CustomTarget.name then MsgText=V.name.." saved location cleared"an=U;break end end;if an~=-1 then table.remove(SavedLocations,an)end;DecrementAutopilotTargetIndex()UpdateAtlasLocationsList()end;function DrawDeadZone(ao)ao[#ao+1]=b([[]],DeadZone)end;function ToggleRadarPanel()if radarPanelID~=nil and Peris==0 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;if perisPanelID~=nil then system.destroyWidgetPanel(perisPanelID)perisPanelID=nil end else if Peris==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;Peris=0 end end;function ToggleWidgets()if q 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;q=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;q=true end end;function SetupInterplanetaryPanel()InAtmo=f()>0;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 InAtmo then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;widgetCurBrakeTime=system.createWidget(panelInterplanetary,"value")widgetCurBrakeTimeText=system.createData('{"label": "Cur Brake Time", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;widgetMaxBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeDistanceText=system.createData('{"label": "Max Brake Distance", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;widgetMaxBrakeTime=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeTimeText=system.createData('{"label": "Max Brake Time", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;widgetTrajectoryAltitude=system.createWidget(panelInterplanetary,"value")widgetTrajectoryAltitudeText=system.createData('{"label": "Projected Altitude", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;function Contains(ap,aq,ab,ac,a9,aa)if ap>ab and apac and aqMinAutopilotSpeed then MsgText="WARNING: Insufficient Brakes - Attempting coast landing, beware obstacles"end;if not AltitudeHold then ToggleAltitudeHold()end;AutoTakeoff=false;BrakeLanding=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)end end;function ToggleAutoTakeoff()if AutoTakeoff then AutoTakeoff=false;if AltitudeHold then ToggleAltitudeHold()end else if not AltitudeHold then ToggleAltitudeHold()end;AutoTakeoff=true;HoldAltitude=CoreAltitude+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end end;function ToggleAltitudeHold()AltitudeHold=not AltitudeHold;if AltitudeHold then Autopilot=false;ProgradeIsOn=false;RetrogradeIsOn=false;FollowMode=false;BrakeLanding=false;Reentry=false;autoRoll=true;if not GearExtended and not BrakeIsOn or f()==0 then AutoTakeoff=false;HoldAltitude=CoreAltitude;if not SpaceLaunch and Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end else AutoTakeoff=true;HoldAltitude=CoreAltitude+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end;if SpaceLaunch then HoldAltitude=100000 end else autoRoll=autoRollPreference;AutoTakeoff=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;VectorToTarget=false end end;function ToggleFollowMode()if l()==1 then FollowMode=not FollowMode;if FollowMode 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;autoRoll=autoRollPreference;GearExtended=OldGearExtended;if GearExtended then Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end end else MsgText="Follow Mode only works with Remote controller"FollowMode=false end end;function ToggleAutopilot()if AutopilotTargetIndex>0 and not Autopilot then if CustomTarget~=nil then if planet.name==CustomTarget.planetname then StrongBrakes=planet.gravity*9.80665*core.getConstructMass()MinAutopilotSpeed then MsgText="Insufficient Brake Force\nCoast landing will be inaccurate"end;if unit.getAtmosphereDensity()>0 then if not AltitudeHold then if not VectorToTarget then ToggleVectorToTarget()end else if not VectorToTarget then ToggleVectorToTarget()end end else SpaceLand=true end else SpaceLaunch=true;if unit.getAtmosphereDensity()~=0 then ToggleAltitudeHold()else Autopilot=true end end elseif unit.getAtmosphereDensity()==0 then Autopilot=true;RetrogradeIsOn=false;ProgradeIsOn=false;AutopilotRealigned=false;FollowMode=false;AltitudeHold=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;APThrottleSet=false else SpaceLaunch=true;ToggleAltitudeHold()end else Autopilot=false;AutopilotRealigned=false;VectorToTarget=false;APThrottleSet=false end end;function ProgradeToggle()ProgradeIsOn=not ProgradeIsOn;RetrogradeIsOn=false;Autopilot=false;AltitudeHold=false;FollowMode=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false end;function RetrogradeToggle()RetrogradeIsOn=not RetrogradeIsOn;ProgradeIsOn=false;Autopilot=false;AltitudeHold=false;FollowMode=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false end;function BrakeToggle()BrakeIsOn=not BrakeIsOn;if BrakeLanding then BrakeLanding=false;autoRoll=autoRollPreference end;if BrakeIsOn then AltitudeHold=false;VectorToTarget=false;AutoTakeoff=false;Reentry=false;ProgradeIsOn=false;BrakeLanding=false;AutoLanding=false;AltitudeHold=false;autoRoll=autoRollPreference end end;function checkDamage(ao)local ar=0;p=""local as=H;local at=0;local au=0;local av=0;local aw=0;local ax=""for U in pairs(ElementsID)do local Y=0;local ay=0;ay=e(ElementsID[U])Y=g(ElementsID[U])at=at+Y;if Y0 and m[11]==ElementsID[U]then for aA in pairs(m)do core.deleteSticker(m[aA])end;m={}end end;ar=a(at/as*100)if ar<100 then ao[#ao+1]=[[]]aw=a(ar*2.55)ax=b("rgb(%d,%d,%d)",255-aw,aw,0)if ar<100 then ao[#ao+1]=b([[Elemental Integrity: %i %%]],ax,ar)if av>0 then ao[#ao+1]=b([[Disabled Modules: %i Damaged Modules: %i]],ax,av,au)elseif au>0 then ao[#ao+1]=b([[Damaged Modules: %i]],ax,au)end end;ao[#ao+1]=[[<\g>]]end end;function DrawCursorLine(ao)local aB=a(utils.clamp(Distance/(u/4)*255,0,255))ao[#ao+1]=b("",SimulatedX,SimulatedY,a(PrimaryR+0.5)+aB,a(PrimaryG+0.5)-aB,a(PrimaryB+0.5)-aB)end;function getPitch(aC,aD,aj)local aE=aC:cross(aj):normalize_inplace()local aF=math.acos(utils.clamp(aE:dot(-aD),-1,1))*constants.rad2deg;if aE:cross(-aD):dot(aj)<0 then aF=-aF end;return aF end;function wipeSaveVariables()if not dbHud then MsgText="No Databank Found, unable to wipe. \nYou must have a Databank attached to ship prior to running the HUD autoconfigure"MsgTimer=5 else if B then for U,V in pairs(SaveableVariables)do dbHud.setStringValue(V,d(nil))end;for U,V in pairs(AutoVariables)do if V~="SavedLocations"then dbHud.setStringValue(V,d(nil))end end;MsgText="Databank wiped. New variables will save after re-enter seat and exit"MsgTimer=5;B=false;A=false;WipedDatabank=true else MsgText="Press ALT-7 again to confirm wipe of ALL data"B=true end end end;function CheckButtons()for _,V in pairs(r)do if V.hovered then if not V.drawCondition or V.drawCondition()then V.toggleFunction()end;V.hovered=false end end end;function SetButtonContains()local ab=SimulatedX+u/2;local ac=SimulatedY+v/2;for _,V in pairs(r)do V.hovered=Contains(ab,ac,V.x,V.y,V.width,V.height)end end;function DrawButton(ao,aG,hover,ab,ac,aH,aI,aJ,aK,aL,aM)if type(aL)=="function"then aL=aL()end;if type(aM)=="function"then aM=aM()end;ao[#ao+1]=b(""if aG then ao[#ao+1]=b("%s",aL)else ao[#ao+1]=b("%s",aM)end end;function DrawButtons(ao)local aN="rgb(50,50,50)'"local aO="rgb(210,200,200)"local aP=DrawButton;for _,V in pairs(r)do local a8=V.disableName;local a7=V.enableName;if type(a8)=="function"then a8=a8()end;if type(a7)=="function"then a7=a7()end;if not V.drawCondition or V.drawCondition()then aP(ao,V.toggleVar(),V.hovered,V.x,V.y,V.width,V.height,aO,aN,a8,a7)end end end;function DrawTank(ao,Q,ab,aQ,aR,aS,aT,aU)local aV=1;local aW=2;local aX=3;local aY=4;local aZ=5;local a_=6;local b0=""local b1=0;local b2=fuelY;local b3=fuelY+10;if l()==1 and not RemoteHud then b2=b2-50;b3=b3-50 end;ao[#ao+1]=[[]]if aR=="ATMO"then b0="atmofueltank"elseif aR=="SPACE"then b0="spacefueltank"else b0="rocketfueltank"end;b1=_G[b0 .."_size"]if#aS>0 then for i=1,#aS do local ak=string.sub(aS[i][aW],1,12)local b4=0;for aA=1,b1 do if aS[i][aW]==json.decode(unit[b0 .."_"..aA].getData()).name then b4=aA;break end end;if Q or aT[i]==nil or aU[i]==nil then local b5=0;local b6=0;local b7=0;local b8=0;local a1=system.getTime()if b4~=0 then aU[i]=json.decode(unit[b0 .."_"..b4].getData()).percentage;aT[i]=json.decode(unit[b0 .."_"..b4].getData()).timeLeft;if aT[i]=="n/a"then aT[i]=0 end else b7=j(aS[i][aV])-aS[i][aY]b5=aS[i][aX]aU[i]=a(0.5+b7*100/b5)b6=aS[i][aZ]b8=aS[i][a_]if b6<=b7 then aT[i]=0 else aT[i]=a(0.5+b7/((b6-b7)/(a1-b8)))end;aS[i][aZ]=b7;aS[i][a_]=a1 end end;if ak==aQ then ak=b("%s %d",aR,i)end;if b4==0 then ak=ak.." *"end;local b9;if aT[i]==0 then b9="n/a"else b9=FormatTimeString(aT[i])end;if aU[i]~=nil then local aw=a(aU[i]*2.55)local ax=b("rgb(%d,%d,%d)",255-aw,aw,0)local ba=""if b9~="n/a"and aT[i]<120 or aU[i]<5 then if Q then ba=[[class="red"]]end end;ao[#ao+1]=b([[ %s %d%% %s - ]],ab,b2,ba,ak,ab,b3,ax,aU[i],b9)b2=b2+30;b3=b3+30 end end end;ao[#ao+1]=""end;function HideInterplanetaryPanel()system.destroyWidgetPanel(panelInterplanetary)panelInterplanetary=nil end;system.showScreen(1)function getRelativePitch(velocity)velocity=vec3(velocity)local aF=-math.deg(math.atan(velocity.y,velocity.z))+180;aF=aF-90;if aF<0 then aF=360+aF end;if aF>180 then aF=-180+aF-180 end;return-aF end;function getRelativeYaw(velocity)velocity=vec3(velocity)local bb=math.deg(math.atan(velocity.y,velocity.x))-90;if bb<-180 then bb=360+bb end;return bb end;function AlignToWorldVector(bc,bd)if f()==0 or RateOfChange>MinimumRateOfChange+0.08 then if bd==nil then bd=t end;bc=vec3(bc):normalize()local be=vec3(core.getConstructWorldOrientationForward())-bc;local bf=-getMagnitudeInDirection(be,core.getConstructWorldOrientationRight())*s;local bg=-getMagnitudeInDirection(be,core.getConstructWorldOrientationUp())*s;if n==0 then n=bf/2 end;if o==0 then o=bg/2 end;YawInput2=YawInput2-(bf+(bf-n)*DampingMultiplier)PitchInput2=PitchInput2+bg+(bg-o)*DampingMultiplier;n=bf;o=bg;if math.abs(bf)0 and CustomTarget~=nil end)MakeButton("Clear Position","Clear Position",200,bk.height,bk.x-200-30,bk.y,function()return true end,ClearCurrentPosition,function()return AutopilotTargetIndex>0 and CustomTarget~=nil end)bh=60;bi=300;local ab=10;local ac=v/2-300;MakeButton("Enable Turn and Burn","Disable Turn and Burn",bi,bh,ab,ac,function()return TurnBurn end,ToggleTurnBurn)MakeButton("Engage Altitude Hold","Disable Altitude Hold",bi,bh,ab+bi+20,ac,function()return AltitudeHold end,ToggleAltitudeHold)ac=ac+bh+20;MakeButton("Engage Autoland","Disable Autoland",bi,bh,ab,ac,function()return AutoLanding end,ToggleAutoLanding)MakeButton("Engage Auto Takeoff","Disable Auto Takeoff",bi,bh,ab+bi+20,ac,function()return AutoTakeoff end,ToggleAutoTakeoff)ac=ac+bh+20;MakeButton("Show Orbit Display","Hide Orbit Display",bi,bh,ab,ac,function()return DisplayOrbit end,function()DisplayOrbit=not DisplayOrbit;if DisplayOrbit then MsgText="Orbit Display Enabled"else MsgText="Orbit Display Disabled"end end)MakeButton("Enable Emergency Warp","Disable Emergency Warp",bi,bh,ab+bi+20,ac,function()return EmergencyWarp end,function()EmergencyWarp=not EmergencyWarp;if EmergencyWarp then MsgText="Emergency Warp Enabled"else MsgText="Emergency Warp Disabled"end end,function()return warpdrive~=nil end)ac=ac+bh+20;MakeButton("Glide Re-Entry","Cancel Glide Re-Entry",bi,bh,ab,ac,function()return Reentry end,function()ReentryMode=true;BeginReentry()end,function()return CoreAltitude>ReentryAltitude end)MakeButton("Parachute Re-Entry","Cancel Parachute Re-Entry",bi,bh,ab+bi+20,ac,function()return Reentry end,BeginReentry,function()return CoreAltitude>ReentryAltitude end)ac=ac+bh+20;MakeButton("Engage Follow Mode","Disable Follow Mode",bi,bh,ab,ac,function()return FollowMode end,ToggleFollowMode,function()return l()==1 end)MakeButton("Enable Repair Arrows","Disable Repair Arrows",bi,bh,ab+bi+20,ac,function()return I end,function()I=not I;if I then MsgText="Repair Arrows Enabled"else MsgText="Repair Arrows Diabled"end end,function()return l()==1 end)ac=ac+bh+20;MakeButton("Enable AGG","Disable AGG",bi,bh,ab,ac,function()return antigrav.getState()==1 end,ToggleAntigrav,function()return antigrav~=nil end)ac=ac+bh+20;MakeButton(function()return string.format("Toggle Control Scheme - Current: %s",userControlScheme)end,function()return string.format("Control Scheme: %s",userControlScheme)end,bi*2,bh,ab,ac,function()return false end,function()if userControlScheme=="keyboard"then userControlScheme="mouse"elseif userControlScheme=="mouse"then userControlScheme="virtual joystick"else userControlScheme="keyboard"end end)coroutine.yield()function updateHud(ao)local bl=CoreAltitude;local velocity=core.getVelocity()local bm=vec3(velocity):len()local bn=vec3(core.getWorldVertical())local bo=vec3(core.getConstructWorldOrientationForward())local bp=vec3(core.getConstructWorldOrientationRight())local aF=getPitch(bn,bo,bp)local bq=getRoll(bn,bo,bp)local br=bq;local bs=aF;local bt=f()local bu=a(unit.getThrottle())local bv=bm*3.6;local bw=unit.getAxisCommandValue(0)local bx=GetFlightStyle()local by="ROLL"local bz=unit.getClosestPlanetInfluence()>0;if bu==nil then bu=0 end;if not bz then if bm>5 then aF=getRelativePitch(velocity)bq=getRelativeYaw(velocity)else aF=0;bq=0 end;by="YAW"end;ao[#ao+1]=LastOdometerOutput;ao[#ao+1]=p;ao[#ao+1]=RadarMessage;if S%L==0 then Q=true end;if fuelX~=0 and fuelY~=0 then DrawTank(ao,Q,fuelX,"Atmospheric ","ATMO",E,O,P)DrawTank(ao,Q,fuelX+100,"Space fuel t","SPACE",F,M,N)DrawTank(ao,Q,fuelX+200,"Rocket fuel ","ROCKET",G,J,K)end;if Q then Q=false;S=0 end;S=S+1;DrawVerticalSpeed(ao,bl,bt)if l()==0 or RemoteHud then if not IsInFreeLook()or brightHud then if bz then DrawRollLines(ao,centerX,centerY,br,by,bz)DrawArtificialHorizon(ao,bs,br,bt,centerX,centerY,bz)DrawAltitudeDisplay(ao,bl,bt)else DrawRollLines(ao,centerX,centerY,bq,by,bz)DrawArtificialHorizon(ao,aF,bq,bt,centerX,centerY,bz)end;DrawPrograde(ao,bt,velocity,bm,centerX,centerY)end end;DrawThrottle(ao,bx,bu,bw)DrawSpeed(ao,bv)DrawWarnings(ao)DisplayOrbitScreen(ao)if screen_2 then local bA=vec3(core.getConstructWorldPos())local ab=960+bA.x/MapXRatio;local ac=450+bA.y/MapYRatio;screen_2.moveContent(YouAreHere,(ab-80)/19.2,(ac-80)/10.8)end end;function IsInFreeLook()return system.isViewLocked()==0 and userControlScheme~="keyboard"and l()==0 end;function HUDPrologue(ao)local bB=rgb;local bC=X;local bD=rgb;local bE=X;if IsInFreeLook()and not brightHud then bB=[[rgb(]]..a(PrimaryR*0.4+0.5)..","..a(PrimaryG*0.4+0.5)..","..a(PrimaryB*0.3+0.5)..[[)]]bC=[[rgb(]]..a(PrimaryR*0.3+0.5)..","..a(PrimaryG*0.3+0.5)..","..a(PrimaryB*0.2+0.5)..[[)]]end;ao[#ao+1]=b([[ + ]],ab,b2,ba,ak,ab,b3,ax,aU[i],b9)b2=b2+30;b3=b3+30 end end end;ao[#ao+1]=""end;function HideInterplanetaryPanel()system.destroyWidgetPanel(panelInterplanetary)panelInterplanetary=nil end;system.showScreen(1)function getRelativePitch(velocity)velocity=vec3(velocity)local aF=-math.deg(math.atan(velocity.y,velocity.z))+180;aF=aF-90;if aF<0 then aF=360+aF end;if aF>180 then aF=-180+aF-180 end;return-aF end;function getRelativeYaw(velocity)velocity=vec3(velocity)local bb=math.deg(math.atan(velocity.y,velocity.x))-90;if bb<-180 then bb=360+bb end;return bb end;function AlignToWorldVector(bc,bd)if f()==0 or RateOfChange>MinimumRateOfChange+0.08 then if bd==nil then bd=t end;bc=vec3(bc):normalize()local be=vec3(core.getConstructWorldOrientationForward())-bc;local bf=-getMagnitudeInDirection(be,core.getConstructWorldOrientationRight())*s;local bg=-getMagnitudeInDirection(be,core.getConstructWorldOrientationUp())*s;if n==0 then n=bf/2 end;if o==0 then o=bg/2 end;YawInput2=YawInput2-(bf+(bf-n)*DampingMultiplier)PitchInput2=PitchInput2+bg+(bg-o)*DampingMultiplier;n=bf;o=bg;if math.abs(bf)0 and CustomTarget~=nil end)MakeButton("Clear Position","Clear Position",200,bk.height,bk.x-200-30,bk.y,function()return true end,ClearCurrentPosition,function()return AutopilotTargetIndex>0 and CustomTarget~=nil end)bh=60;bi=300;local ab=10;local ac=v/2-300;MakeButton("Enable Turn and Burn","Disable Turn and Burn",bi,bh,ab,ac,function()return TurnBurn end,ToggleTurnBurn)MakeButton("Engage Altitude Hold","Disable Altitude Hold",bi,bh,ab+bi+20,ac,function()return AltitudeHold end,ToggleAltitudeHold)ac=ac+bh+20;MakeButton("Engage Autoland","Disable Autoland",bi,bh,ab,ac,function()return AutoLanding end,ToggleAutoLanding)MakeButton("Engage Auto Takeoff","Disable Auto Takeoff",bi,bh,ab+bi+20,ac,function()return AutoTakeoff end,ToggleAutoTakeoff)ac=ac+bh+20;MakeButton("Show Orbit Display","Hide Orbit Display",bi,bh,ab,ac,function()return DisplayOrbit end,function()DisplayOrbit=not DisplayOrbit;if DisplayOrbit then MsgText="Orbit Display Enabled"else MsgText="Orbit Display Disabled"end end)MakeButton("Enable Emergency Warp","Disable Emergency Warp",bi,bh,ab+bi+20,ac,function()return EmergencyWarp end,function()EmergencyWarp=not EmergencyWarp;if EmergencyWarp then MsgText="Emergency Warp Enabled"else MsgText="Emergency Warp Disabled"end end,function()return warpdrive~=nil end)ac=ac+bh+20;MakeButton("Glide Re-Entry","Cancel Glide Re-Entry",bi,bh,ab,ac,function()return Reentry end,function()ReentryMode=true;BeginReentry()end,function()return CoreAltitude>ReentryAltitude end)MakeButton("Parachute Re-Entry","Cancel Parachute Re-Entry",bi,bh,ab+bi+20,ac,function()return Reentry end,BeginReentry,function()return CoreAltitude>ReentryAltitude end)ac=ac+bh+20;MakeButton("Engage Follow Mode","Disable Follow Mode",bi,bh,ab,ac,function()return FollowMode end,ToggleFollowMode,function()return l()==1 end)MakeButton("Enable Repair Arrows","Disable Repair Arrows",bi,bh,ab+bi+20,ac,function()return I end,function()I=not I;if I then MsgText="Repair Arrows Enabled"else MsgText="Repair Arrows Diabled"end end,function()return l()==1 end)ac=ac+bh+20;MakeButton("Enable AGG","Disable AGG",bi,bh,ab,ac,function()return antigrav.getState()==1 end,ToggleAntigrav,function()return antigrav~=nil end)ac=ac+bh+20;MakeButton(function()return string.format("Toggle Control Scheme - Current: %s",userControlScheme)end,function()return string.format("Control Scheme: %s",userControlScheme)end,bi*2,bh,ab,ac,function()return false end,function()if userControlScheme=="keyboard"then userControlScheme="mouse"elseif userControlScheme=="mouse"then userControlScheme="virtual joystick"else userControlScheme="keyboard"end end)coroutine.yield()function updateHud(ao)local bl=CoreAltitude;local velocity=core.getVelocity()local bm=vec3(velocity):len()local bn=vec3(core.getWorldVertical())local bo=vec3(core.getConstructWorldOrientationForward())local bp=vec3(core.getConstructWorldOrientationRight())local aF=getPitch(bn,bo,bp)local bq=getRoll(bn,bo,bp)local br=bq;local bs=aF;local bt=f()local bu=a(unit.getThrottle())local bv=bm*3.6;local bw=unit.getAxisCommandValue(0)local bx=GetFlightStyle()local by="ROLL"local bz=unit.getClosestPlanetInfluence()>0;if bu==nil then bu=0 end;if not bz then if bm>5 then aF=getRelativePitch(velocity)bq=getRelativeYaw(velocity)else aF=0;bq=0 end;by="YAW"end;ao[#ao+1]=LastOdometerOutput;ao[#ao+1]=p;ao[#ao+1]=RadarMessage;if S%L==0 then Q=true end;if fuelX~=0 and fuelY~=0 then DrawTank(ao,Q,fuelX,"Atmospheric ","ATMO",E,O,P)DrawTank(ao,Q,fuelX+100,"Space fuel t","SPACE",F,M,N)DrawTank(ao,Q,fuelX+200,"Rocket fuel ","ROCKET",G,J,K)end;if Q then Q=false;S=0 end;S=S+1;DrawVerticalSpeed(ao,bl,bt)if l()==0 or RemoteHud then if not IsInFreeLook()or brightHud then if bz then DrawRollLines(ao,centerX,centerY,br,by,bz)DrawArtificialHorizon(ao,bs,br,bt,centerX,centerY,bz,a(getRelativeYaw(velocity)),bm)DrawAltitudeDisplay(ao,bl,bt)else DrawRollLines(ao,centerX,centerY,bq,by,bz)DrawArtificialHorizon(ao,aF,bq,bt,centerX,centerY,bz)end;DrawPrograde(ao,bt,velocity,bm,centerX,centerY)end end;DrawThrottle(ao,bx,bu,bw)DrawSpeed(ao,bv)DrawWarnings(ao)DisplayOrbitScreen(ao)if screen_2 then local bA=vec3(core.getConstructWorldPos())local ab=960+bA.x/MapXRatio;local ac=450+bA.y/MapYRatio;screen_2.moveContent(YouAreHere,(ab-80)/19.2,(ac-80)/10.8)end end;function IsInFreeLook()return system.isViewLocked()==0 and userControlScheme~="keyboard"and l()==0 end;function HUDPrologue(ao)local bB=rgb;local bC=X;local bD=rgb;local bE=X;if IsInFreeLook()and not brightHud then bB=[[rgb(]]..a(PrimaryR*0.4+0.5)..","..a(PrimaryG*0.4+0.5)..","..a(PrimaryB*0.3+0.5)..[[)]]bC=[[rgb(]]..a(PrimaryR*0.3+0.5)..","..a(PrimaryG*0.3+0.5)..","..a(PrimaryB*0.2+0.5)..[[)]]end;ao[#ao+1]=b([[ "ao[#ao+1]=GalaxyMapHTML;ao[#ao+1]=fQ;ao[#ao+1]=""Animating=true;ao[#ao+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(ao,"")system.setScreen(content)elseif Animated then local fQ=table.concat(ao,"")ao={}ao[#ao+1]=""ao[#ao+1]=GalaxyMapHTML;ao[#ao+1]=fQ;ao[#ao+1]=""end;if not Animating then ao[#ao+1]=string.format([[]],SimulatedX,SimulatedY)end else CheckButtons()SimulatedX=0;SimulatedY=0 end else SimulatedX=SimulatedX+fN;SimulatedY=SimulatedY+fO;Distance=math.sqrt(SimulatedX*SimulatedX+SimulatedY*SimulatedY)if not HoldingCtrl and l()==0 then if userControlScheme=="virtual joystick"then if SimulatedX>0 and SimulatedX>DeadZone then YawInput2=YawInput2-(SimulatedX-DeadZone)*MouseXSensitivity elseif SimulatedX<0 and SimulatedX0 and SimulatedY>DeadZone then PitchInput2=PitchInput2-(SimulatedY-DeadZone)*MouseYSensitivity elseif SimulatedY<0 and SimulatedYDeadZone then DrawCursorLine(ao)end else SetButtonContains()DrawButtons(ao)end;ao[#ao+1]=string.format([[]],SimulatedX,SimulatedY)end;ao[#ao+1]=[[]]content=table.concat(ao,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end;if ProgradeIsOn then if velMag>MinAutopilotSpeed then local fR=AlignToWorldVector(vec3(velocity),0.01)if SpaceLand then autoRoll=true;if fR then ProgradeIsOn=false;ReentryMode=true;BeginReentry()SpaceLand=false;FinalLand=true;autoRoll=autoRollPreference end end end end;if RetrogradeIsOn then if velMag>MinAutopilotSpeed then AlignToWorldVector(-vec3(velocity))end end;if not ProgradeIsOn and SpaceLand then if unit.getAtmosphereDensity()==0 then ReentryMode=true;BeginReentry()SpaceLand=false;FinalLand=true else SpaceLand=false;ToggleAutopilot()end end;if FinalLand and CoreAltitudeReentrySpeed-100 then ToggleAutopilot()FinalLand=false end;if Autopilot and unit.getAtmosphereDensity()==0 then local fn,fo;if not TurnBurn then fn,fo=GetAutopilotBrakeDistanceAndTime(velMag)else fn,fo=GetAutopilotTBBrakeDistanceAndTime(velMag)end;fn=fn;fo=fo;local fS=AutopilotTargetCoords;if orbit.apoapsis==nil and velMag>300 and AutopilotAccelerating then local fT=(vec3(AutopilotTargetCoords)-vec3(core.getConstructWorldPos())):normalize()-vec3(velocity):normalize()local fU=getMagnitudeInDirection(fT,AutopilotShipUp)local fV=getMagnitudeInDirection(fT,AutopilotShipRight)local fW=-fV*AutopilotDistance*velMag*TrajectoryAlignmentStrength;local fX=-fU*AutopilotDistance*velMag*TrajectoryAlignmentStrength;fS=AutopilotTargetCoords+-fW*vec3(AutopilotShipRight)+-fX*vec3(AutopilotShipUp)end;AutopilotDistance=(vec3(fS)-vec3(core.getConstructWorldPos())):len()local fY=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()system.updateData(widgetDistanceText,'{"label": "Distance", "value": "'..getDistanceDisplayString(fY)..'", "unit":""}')local fZ=true;local f_=(AutopilotTargetPlanet.center-(vec3(core.getConstructWorldPos())+vec3(velocity):normalize()*AutopilotDistance)):len()-AutopilotTargetPlanet.radius;system.updateData(widgetTrajectoryAltitudeText,'{"label": "Projected Altitude", "value": "'..getDistanceDisplayString(f_)..'", "unit":""}')if not AutopilotCruising and not AutopilotBraking then fZ=AlignToWorldVector((fS-vec3(core.getConstructWorldPos())):normalize())elseif TurnBurn then fZ=AlignToWorldVector(-vec3(velocity):normalize())end;if AutopilotAccelerating then if not fZ or BrakeIsOn then AutopilotStatus="Adjusting Trajectory"else AutopilotStatus="Accelerating"end;if vec3(core.getConstructWorldOrientationForward()):dot(velocity)<0 and velMag>300 then BrakeIsOn=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false elseif not APThrottleSet then BrakeIsOn=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)APThrottleSet=true end;if vec3(core.getVelocity()):len()>=MaxGameVelocity and math.abs(f_-AutopilotTargetOrbit)<1000 or unit.getThrottle()==0 and APThrottleSet then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false end;if AutopilotDistance<=fn then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false end elseif AutopilotBraking then BrakeIsOn=true;BrakeInput=1;if TurnBurn then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,100)end;if orbit.periapsis~=nil and orbit.eccentricity<1 then AutopilotStatus="Circularizing"if orbit.eccentricity>LastEccentricity or orbit.apoapsis.altitude0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if fZ then if not AutopilotRealigned then AutopilotTargetCoords=vec3(AutopilotTargetPlanet.center)+(AutopilotTargetOrbit+AutopilotTargetPlanet.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotRealigned=true;AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()elseif fZ then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not APThrottleSet then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)APThrottleSet=true;BrakeIsOn=false end end end end end;if FollowMode then autoRoll=true;local g0=0;local bA=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local g1=bA-vec3(core.getConstructWorldPos())local g2=vec3(g1):project_on(vec3(core.getConstructWorldOrientationForward())):len()local g3=vec3(g1):project_on(vec3(core.getConstructWorldOrientationRight())):len()local cz=math.sqrt(g2*g2+g3*g3)AlignToWorldVector(g1:normalize())local g4=40;local g5=czg8 then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(g0-aF)local g9=pitchPID:get()PitchInput2=g9 end end;local bT=vec3(core.getWorldVertical())*-1;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget then local bl=CoreAltitude;local ga=HoldAltitude-bl;local gb=500+velMag;local g0=(utils.smoothstep(ga,-gb,gb)-0.5)*2*MaxPitch;if not AltitudeHold then g0=0 end;autoRoll=true;if Reentry then local gc=ReentrySpeed;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=gc then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,gc)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if not ReentryMode then g0=-80;if unit.getAtmosphereDensity()>0.02 then MsgText="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;g0=0;autoRoll=autoRollPreference end elseif Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==ReentrySpeed then ReentryMode=false;Reentry=false;autoRoll=autoRollPreference end end;local gd=PitchInput2;if velMag>MinAutopilotSpeed then AlignToWorldVector(vec3(velocity))end;if VectorToTarget and CustomTarget~=nil and AutopilotTargetIndex>0 then local be=CustomTarget.position-vec3(core.getConstructWorldPos())AlignToWorldVector(be)local ge=be:len()-be:project_on(bT):len()local a6=json.decode(unit.getData()).maxBrake;local bR=velocity.x*bT.x+velocity.y*bT.y+velocity.z*bT.z;local gf=velocity:len()-math.abs(bR)local gg=vec3(core.getWorldAirFrictionAcceleration())if a6~=nil then LastMaxBrake=a6;BrakeDistance,BrakeTime=Kinematic.computeDistanceAndTime(gf,0,core.getConstructMass(),0,0,a6+(gg:len()-gg:project_on(bT):len())*core.getConstructMass())else BrakeDistance,BrakeTime=Kinematic.computeDistanceAndTime(gf,0,core.getConstructMass(),0,0,LastMaxBrake+vec3(core.getWorldAirFrictionAcceleration()):len()*core.getConstructMass())end;StrongBrakes=planet.gravity*9.80665*core.getConstructMass()LastTargetDistance and not AltitudeHold and not AutoTakeoff then BrakeLanding=true;VectorToTarget=false end;LastTargetDistance=ge end;PitchInput2=gd;local bo=vec3(core.getConstructWorldOrientationForward())local bp=vec3(core.getConstructWorldOrientationRight())local bn=vec3(core.getWorldVertical())local fu=-1;local aF=getPitch(bn,bo,bp)local g8=0.1;if BrakeLanding then g0=0;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)local bR=velocity.x*bT.x+velocity.y*bT.y+velocity.z*bT.z;fu=HovGndDet;if fu>-1 then if math.abs(g0-aF)50000 then if Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=5000 then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,5000)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end end end;if math.abs(g0-aF)>g8 then if pitchPID==nil then pitchPID=pid.new(8*0.01,0,8*0.1)end;pitchPID:inject(g0-aF)local g9=pitchPID:get()PitchInput2=PitchInput2+g9 end end;LastEccentricity=orbit.eccentricity;if antigrav and CoreAltitude<200000 then if antigrav.getState()==1 then local velocity=vec3(core.getWorldVelocity())local bT=vec3(core.getWorldVertical())*-1;local bR=velocity.x*bT.x+velocity.y*bT.y+velocity.z*bT.z;local gh=antigrav.getBaseAltitude()if AntigravTargetAltitude==nil then AntigravTargetAltitude=1000 end;local gi=unit.getThrottle()if Nav.axisCommandManager:getAxisCommandType(0)==1 then gi=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)end;local gj=math.abs(CoreAltitude-gh)if gi>-1 and gi<1 and gj>10 and gj<501 and unit.getAtmosphereDensity()<0.01 then if CoreAltitude>antigrav.getBaseAltitude()and AntigravTargetAltitude>CoreAltitude and bR<0 or CoreAltitude0 then BrakeIsOn=true else BrakeIsOn=false end end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end else if AntigravTargetAltitude==nil then desiredBaseAltitude=CoreAltitude else desiredBaseAltitude=AntigravTargetAltitude end end end end end;function script.onFlush()if antigrav then if antigrav.getState()==0 and antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(AntigravTargetAltitude)end end;local gk=2;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)gk=math.max(gk,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 gl=utils.clamp(PitchInput+PitchInput2+system.getControlDeviceForwardInput(),-1,1)local gm=utils.clamp(RollInput+RollInput2+system.getControlDeviceYawInput(),-1,1)local gn=utils.clamp(YawInput+YawInput2-system.getControlDeviceLeftRightInput(),-1,1)local go=BrakeInput;local gp=vec3(core.getWorldVertical())local gq=vec3(core.getConstructWorldOrientationUp())local gr=vec3(core.getConstructWorldOrientationForward())local gs=vec3(core.getConstructWorldOrientationRight())local gt=vec3(core.getWorldVelocity())local gu=vec3(core.getWorldVelocity()):normalize()local gv=getRoll(gp,gr,gs)local gw=math.abs(gv)local gx=utils.sign(gv)local f=unit.getAtmosphereDensity()local gy=vec3(core.getWorldAngularVelocity())local gz=gl*pitchSpeedFactor*gs+gm*rollSpeedFactor*gr+gn*yawSpeedFactor*gq;if gp:len()>0.01 and f>0.0 or ProgradeIsOn then local gA=1.0;if autoRoll==true and gw>gA and gm==0 then local gB=utils.clamp(0,gw-30,gw+30)if rollPID==nil then rollPID=pid.new(autoRollFactor*0.01,0,autoRollFactor*0.1)end;rollPID:inject(gB-gv)local gC=rollPID:get()gz=gz+gC*gr end end;if gp:len()>0.01 and f>0.0 then local gD=20.0;if turnAssist==true and gw>gD and gl==0 and gn==0 then local gE=turnAssistFactor*0.1;local gF=turnAssistFactor*0.025;local gG=(gw-gD)/(180-gD)*180;local gH=0;if gG<90 then gH=gG/90 elseif gG<180 then gH=(180-gG)/90 end;gH=gH*gH;local gI=-gx*gF*(1.0-gH)local gJ=gE*gH;gz=gz+gJ*gs+gI*gq end end;local gK=1;local gL=0;local gM=1;local gN=gk*(gz-gy)local gO=vec3(core.getWorldAirFrictionAngularAcceleration())gN=gN-gO;Nav:setEngineTorqueCommand('torque',gN,gK,'airfoil','','',gM)local gP=-go*(brakeSpeedFactor*gt+brakeFlatFactor*gu)Nav:setEngineForceCommand('brake',gP)local gQ=''local gR=vec3()local gS=false;local gT='thrust analog longitudinal'local gU=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if gU==axisCommandType.byThrottle then local gV=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(gT,axisCommandId.longitudinal)Nav:setEngineForceCommand(gT,gV,gK)elseif gU==axisCommandType.byTargetSpeed then local gV=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)gQ=gQ..' , '..gT;gR=gR+gV;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then gS=true end end;local gW='thrust analog lateral'local gX=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if gX==axisCommandType.byThrottle then local gY=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(gW,axisCommandId.lateral)Nav:setEngineForceCommand(gW,gY,gK)elseif gX==axisCommandType.byTargetSpeed then local gZ=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)gQ=gQ..' , '..gW;gR=gR+gZ end;local g_='thrust analog vertical'local h0=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if h0==axisCommandType.byThrottle then local h1=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(g_,axisCommandId.vertical)if UpAmount~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(g_,h1,gK,'airfoil','ground','',gM)else Nav:setEngineForceCommand(g_,vec3(),gK)Nav:setEngineForceCommand('airfoil vertical',h1,gK,'airfoil','','',gM)Nav:setEngineForceCommand('ground vertical',h1,gK,'ground','','',gM)end elseif h0==axisCommandType.byTargetSpeed then if UpAmount==0 then Nav:setEngineForceCommand('hover',vec3(),gK)end;local h2=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)gQ=gQ..' , '..g_;gR=gR+h2 end;if gR:len()>constants.epsilon then if BrakeInput~=0 or gS or math.abs(gu:dot(gr))<0.95 then gQ=gQ..', brake'end;Nav:setEngineForceCommand(gQ,gR,gL,'','','',gM)end;Nav:setBoosterCommand('rocket_engine')if IsBoosting then local bm=vec3(core.getVelocity()):len()local h3=unit.setEngineThrust;local h4=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local gi=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if bm*3.6>gi*(1-h4)then h3('rocket_engine',0)elseif IsBoosting then h3('rocket_engine',1)end else local h5=unit.getThrottle()local g7=h5/100;if f==0 then g7=g7*MaxGameVelocity;if bm>=g7*(1-h4)then h3('rocket_engine',0)elseif IsBoosting then h3('rocket_engine',1)end else g7=g7*1050/3.6;if bm>=g7*(1-h4)then h3('rocket_engine',0)elseif IsBoosting then h3('rocket_engine',1)end end end end end;function script.onUpdate()if not SetupComplete then local _,W=coroutine.resume(beginSetup)if W then SetupComplete=true end else Nav:update()if not Animating and content~=LastContent then system.setScreen(content)end;LastContent=content end end;function script.onActionStart(h6)if h6=="gear"then GearExtended=not GearExtended;if GearExtended then VectorToTarget=false;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)if(vBooster or hover)and HovGndDet==-1 and(unit.getAtmosphereDensity()>0 or CoreAltitudeMinAutopilotSpeed then MsgText="WARNING: Insufficient Brakes - Attempting landing anyway"end;Reentry=false;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=true;autoRoll=true;GearExtended=false else BrakeIsOn=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end else Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end elseif h6=="light"then if Nav.control.isAnyHeadlightSwitchedOn()==1 then Nav.control.switchOffHeadlights()else Nav.control.switchOnHeadlights()end elseif h6=="forward"then PitchInput=PitchInput-1 elseif h6=="backward"then PitchInput=PitchInput+1 elseif h6=="left"then RollInput=RollInput-1 elseif h6=="right"then RollInput=RollInput+1 elseif h6=="yawright"then YawInput=YawInput-1 elseif h6=="yawleft"then YawInput=YawInput+1 elseif h6=="straferight"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,1.0)elseif h6=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,-1.0)elseif h6=="up"then UpAmount=UpAmount+1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,1.0)elseif h6=="down"then UpAmount=UpAmount-1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,-1.0)elseif h6=="groundaltitudeup"then OldButtonMod=HoldAltitudeButtonModifier;OldAntiMod=AntiGravButtonModifier;if antigrav and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude+AntiGravButtonModifier else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+HoldAltitudeButtonModifier else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif h6=="groundaltitudedown"then OldButtonMod=HoldAltitudeButtonModifier;OldAntiMod=AntiGravButtonModifier;if antigrav and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude-AntiGravButtonModifier;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-HoldAltitudeButtonModifier else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif h6=="option1"then IncrementAutopilotTargetIndex()ToggleView=false elseif h6=="option2"then DecrementAutopilotTargetIndex()ToggleView=false elseif h6=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;ToggleView=false;ToggleWidgets()elseif h6=="option4"then ToggleAutopilot()ToggleView=false elseif h6=="option5"then ToggleTurnBurn()ToggleView=false elseif h6=="option6"then ToggleAltitudeHold()ToggleView=false elseif h6=="option7"then wipeSaveVariables()ToggleView=false elseif h6=="option8"then ToggleFollowMode()ToggleView=false elseif h6=="option9"then if gyro~=nil then gyro.toggle()GyroIsOn=gyro.getState()==1 end;ToggleView=false elseif h6=="lshift"then if system.isViewLocked()==1 then HoldingCtrl=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif Nav.control.isRemoteControlled()==1 and ShiftShowsRemoteButtons then HoldingCtrl=true;Animated=false;Animating=false end elseif h6=="brake"then if brakeToggle then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif h6=="lalt"then if Nav.control.isRemoteControlled()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif h6=="booster"then IsBoosting=not IsBoosting;if IsBoosting then unit.setEngineThrust('rocket_engine',1)else unit.setEngineThrust('rocket_engine',0)end elseif h6=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)elseif h6=="speedup"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)else IncrementAutopilotTargetIndex()end elseif h6=="speeddown"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)else DecrementAutopilotTargetIndex()end elseif h6=="antigravity"then if antigrav~=nil then ToggleAntigrav()end elseif h6=="warp"then if warpdrive~=nil then if not InEmergencyWarp then if showWarpWidget then warpdrive.hide()showWarpWidget=false else warpdrive.show()showWarpWidget=true end;if json.decode(warpdrive.getData()).buttonMsg=="CANNOT WARP"then MsgText=json.decode(warpdrive.getData()).errorMsg else warpdrive.activateWarp()warpdrive.show()showWarpWidget=true end else InEmergencyWarp=false;EmergencyWarp=false;MsgText="Emergency Warp Cancelled"end end end end;function script.onActionStop(h6)if h6=="forward"then PitchInput=0 elseif h6=="backward"then PitchInput=0 elseif h6=="left"then RollInput=0 elseif h6=="right"then RollInput=0 elseif h6=="yawright"then YawInput=0 elseif h6=="yawleft"then YawInput=0 elseif h6=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)elseif h6=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)elseif h6=="up"then UpAmount=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif h6=="down"then UpAmount=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif h6=="groundaltitudeup"then if antigrav and antigrav.getState()==1 then AntiGravButtonModifier=OldAntiMod elseif AltitudeHold then HoldAltitudeButtonModifier=OldButtonMod end;ToggleView=false elseif h6=="groundaltitudedown"then if antigrav and antigrav.getState()==1 then AntiGravButtonModifier=OldAntiMod elseif AltitudeHold then HoldAltitudeButtonModifier=OldButtonMod end;ToggleView=false elseif h6=="lshift"then if system.isViewLocked()==1 then HoldingCtrl=false;SimulatedX=0;SimulatedY=0;system.lockView(PrevViewLock)elseif Nav.control.isRemoteControlled()==1 and ShiftShowsRemoteButtons then HoldingCtrl=false;Animated=false;Animating=false end elseif h6=="brake"then if not brakeToggle then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif h6=="lalt"then if Nav.control.isRemoteControlled()==0 and freeLookToggle then if ToggleView then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else ToggleView=true end elseif Nav.control.isRemoteControlled()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end end end;function script.onActionLoop(h6)if h6=="groundaltitudeup"then if antigrav and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude+AntiGravButtonModifier;AntiGravButtonModifier=AntiGravButtonModifier*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+HoldAltitudeButtonModifier;HoldAltitudeButtonModifier=HoldAltitudeButtonModifier*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif h6=="groundaltitudedown"then if antigrav and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude-AntiGravButtonModifier;AntiGravButtonModifier=AntiGravButtonModifier*1.05;BrakeIsOn=false;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-HoldAltitudeButtonModifier;HoldAltitudeButtonModifier=HoldAltitudeButtonModifier*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif h6=="speedup"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end elseif h6=="speeddown"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end;function DisplayMessage(ao,h7)if h7~="empty"then ao[#ao+1]=[[]]for h8 in string.gmatch(h7,"([^\n]+)")do ao[#ao+1]=string.format([[%s]],h8)end;ao[#ao+1]=[[]]end;if MsgTimer~=0 then unit.setTimer("msgTick",MsgTimer)MsgTimer=0 end end;function updateDistance()local a1=system.getTime()local velocity=vec3(core.getWorldVelocity())local bv=vec3(velocity):len()local h9=a1-LastTravelTime;if bv>1.38889 then bv=bv/1000;local ha=bv*(a1-LastTravelTime)TotalDistanceTravelled=TotalDistanceTravelled+ha;TotalDistanceTrip=TotalDistanceTrip+ha end;FlightTime=FlightTime+h9;TotalFlightTime=TotalFlightTime+h9;LastTravelTime=a1 end;script.onStart() + ]],ba,ab,ac+cr,co,ab,ac+cs,cn))an=an+1;ce=ce*10;if cn==ch then cf=cp else cf=0 end end;table.insert(ao,[[]])end end;function DrawPrograde(ao,bt,velocity,bm,centerX,centerY)if bm>5 and bt==0 or bm>MinAutopilotSpeed then local bW=circleRad;local ct=20;local cu=20;local cv=vec3(velocity)local cw=getRelativePitch(cv)local cx=getRelativeYaw(cv)local cy=-cx/cu*bW;local cz=cw/ct*bW;local ab=centerX+cy;local ac=centerY+cz;local cA=math.sqrt(cy^2+cz^2)if cA',ab,ac)else local bS=math.atan(cz,cy)local cB=centerX+bW*math.cos(bS)local cC=centerY+bW*math.sin(bS)ao[#ao+1]=b('',cB,cC)end;cw=getRelativePitch(-cv)cx=getRelativeYaw(-cv)cy=-cx/cu*bW;cz=cw/ct*bW;ab=centerX+cy;ac=centerY+cz;cA=math.sqrt(cy^2+cz^2)if bt==0 then if cA',ab,ac)else local bS=math.atan(cz,cy)local cB=centerX+bW*math.cos(bS)local cC=centerY+bW*math.sin(bS)ao[#ao+1]=b('',cB,cC)end end end end;function DrawWarnings(ao)ao[#ao+1]=b([[DU Hud Version: %.3f]],VERSION_NUMBER)ao[#ao+1]=[[]]if unit.isMouseControlActivated()==1 then ao[#ao+1]=[[Warning: Invalid Control Scheme Detected]]ao[#ao+1]=[[Keyboard Scheme must be selected]]ao[#ao+1]=[[Set your preferred scheme in Lua Parameters instead]]end;local cD=960;local cE=860;local cF=880;local cG=900;local cH=960;local cI=200;local cJ=150;local cK=960;if l()==1 and not RemoteHud then cE=135;cF=155;cG=175;cI=115;cJ=95 end;if BrakeIsOn then ao[#ao+1]=b([[Brake Engaged]],cD,cE)end;if f()~=0 and RateOfChangebrakeLandingRate+5 then ao[#ao+1]=b([[** STALL WARNING **]],cD,cI+25)end;if GyroIsOn then ao[#ao+1]=b([[Gyro Enabled]],cD,cK)end;if GearExtended then if HasGear then ao[#ao+1]=b([[Gear Extended]],cD,cF)else ao[#ao+1]=b([[Landed (G: Takeoff)]],cD,cF)end;ao[#ao+1]=b([[Hover Height: %s]],cD,cG,getDistanceDisplayString(Nav:getTargetGroundAltitude()))end;if EmergencyWarp then ao[#ao+1]=b([[E-WARP ENGAGED]],cD,cH)end;if IsBoosting then ao[#ao+1]=b([[ROCKET BOOST ENABLED]],cD,cH+20)end;if antigrav and antigrav.getState()==1 and AntigravTargetAltitude~=nil then if math.abs(CoreAltitude-antigrav.getBaseAltitude())<501 then ao[#ao+1]=b([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],cD,cI+20,a(AntigravTargetAltitude),a(antigrav.getBaseAltitude()))else ao[#ao+1]=b([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],cD,cI+20,a(AntigravTargetAltitude),a(antigrav.getBaseAltitude()))end elseif Autopilot and AutopilotTargetName~="None"then ao[#ao+1]=b([[Autopilot %s]],cD,cI,AutopilotStatus)elseif FollowMode then ao[#ao+1]=b([[Follow Mode Engaged]],cD,cI)elseif AltitudeHold then if AutoTakeoff then ao[#ao+1]=b([[Ascent to %s]],cD,cI,getDistanceDisplayString(HoldAltitude))if BrakeIsOn then ao[#ao+1]=b([[Throttle Up and Disengage Brake For Takeoff]],cD,cI+50)end else ao[#ao+1]=b([[Altitude Hold: %s]],cD,cI,getDistanceDisplayString2(HoldAltitude))end elseif Reentry then ao[#ao+1]=b([[Parachute Re-entry in Progress]],cD,cI)end;if BrakeLanding then if StrongBrakes then ao[#ao+1]=b([[Brake-Landing]],cD,cI)else ao[#ao+1]=b([[Coast-Landing]],cD,cI)end end;if ProgradeIsOn then ao[#ao+1]=b([[Prograde Alignment]],cD,cI)end;if RetrogradeIsOn then ao[#ao+1]=b([[Retrograde Alignment]],cD,cI)end;if TurnBurn then ao[#ao+1]=b([[Turn & Burn Braking]],cD,cJ)end;if VectorToTarget then ao[#ao+1]=b([[%s]],cD,cJ,VectorStatus)end;ao[#ao+1]=""end;function DisplayOrbitScreen(ao)if orbit~=nil and unit.getAtmosphereDensity()<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 cL=75;local cM=0;local cN=250;local cO=4;cM=cM+cO;local cP=15;local ab=cL+cN+cL/2+cO;local ac=cM+cN/2+5+cO;local cQ,cR,cS,cT;cQ=cN/4;cT=0;ao[#ao+1]=[[]]ao[#ao+1]=b('',cN+cL*2,cN+cM,cO,cO)if orbit.periapsis~=nil and orbit.apoapsis~=nil then cS=(orbit.apoapsis.altitude+orbit.periapsis.altitude+planet.radius*2)/(cQ*2)cR=(planet.radius+orbit.periapsis.altitude+(orbit.apoapsis.altitude-orbit.periapsis.altitude)/2)/cS*(1-orbit.eccentricity)cT=cQ-orbit.periapsis.altitude/cS-planet.radius/cS;local cU=""if orbit.periapsis.altitude<=0 then cU='redout'end;ao[#ao+1]=b([[]],cU,cL+cN/2+cT+cO,cM+cN/2+cO,cQ,cR)ao[#ao+1]=b('',cL+cN/2+cO,cM+cN/2+cO,planet.radius/cS)end;if orbit.apoapsis~=nil and orbit.apoapsis.speed1 then ao[#ao+1]=b([[]],ab-35,ac-5,cL+cN/2+cQ+cT,ac-5)ao[#ao+1]=b([[Apoapsis]],ab,ac)ac=ac+cP;ao[#ao+1]=b([[%s]],ab,ac,getDistanceDisplayString(orbit.apoapsis.altitude))ac=ac+cP;ao[#ao+1]=b([[%s]],ab,ac,FormatTimeString(orbit.timeToApoapsis))ac=ac+cP;ao[#ao+1]=b([[%s]],ab,ac,getSpeedDisplayString(orbit.apoapsis.speed))end;ac=cM+cN/2+5+cO;ab=cL-cL/2+10+cO;if orbit.periapsis~=nil and orbit.periapsis.speed1 then ao[#ao+1]=b([[]],ab+35,ac-5,cL+cN/2-cQ+cT,ac-5)ao[#ao+1]=b([[Periapsis]],ab,ac)ac=ac+cP;ao[#ao+1]=b([[%s]],ab,ac,getDistanceDisplayString(orbit.periapsis.altitude))ac=ac+cP;ao[#ao+1]=b([[%s]],ab,ac,FormatTimeString(orbit.timeToPeriapsis))ac=ac+cP;ao[#ao+1]=b([[%s]],ab,ac,getSpeedDisplayString(orbit.periapsis.speed))end;ao[#ao+1]=b([[%s]],cL+cN/2+cO,20+cO,planet.name)if orbit.period~=nil and orbit.periapsis~=nil and orbit.apoapsis~=nil and orbit.apoapsis.speed>1 then local cV=orbit.timeToApoapsis/orbit.period*2*math.pi;local cW=cQ*math.cos(cV)local cX=cR*math.sin(cV)ao[#ao+1]=b('',cL+cN/2+cW+cT+cO,cM+cN/2+cX+cO)end;ao[#ao+1]=[[]]end end;function Atlas()return{[0]={[1]={GM=6930729684,bodyId=1,center={x=17465536.000,y=22665536.000,z=-34464.000},name='Madis',planetarySystemId=0,radius=44300,atmos=true,gravity=0.36},[2]={GM=157470826617,bodyId=2,center={x=-8.000,y=-8.000,z=-126303.000},name='Alioth',planetarySystemId=0,radius=126068,atmos=true,gravity=1.01},[3]={GM=11776905000,bodyId=3,center={x=29165536.000,y=10865536.000,z=65536.000},name='Thades',planetarySystemId=0,radius=49000,atmos=true,gravity=0.50},[4]={GM=14893847582,bodyId=4,center={x=-13234464.000,y=55765536.000,z=465536.000},name='Talemai',planetarySystemId=0,radius=57450,atmos=true,gravity=0.46},[5]={GM=16951680000,bodyId=5,center={x=-43534464.000,y=22565536.000,z=-48934464.000},name='Feli',planetarySystemId=0,radius=60000,atmos=true,gravity=0.48},[6]={GM=10502547741,bodyId=6,center={x=52765536.000,y=27165538.000,z=52065535.000},name='Sicari',planetarySystemId=0,radius=51100,atmos=true,gravity=0.41},[7]={GM=13033380591,bodyId=7,center={x=58665538.000,y=29665535.000,z=58165535.000},name='Sinnen',planetarySystemId=0,radius=54950,atmos=true,gravity=0.44},[8]={GM=18477723600,bodyId=8,center={x=80865538.000,y=54665536.000,z=-934463.940},name='Teoma',planetarySystemId=0,radius=62000,atmos=true,gravity=0.49},[9]={GM=18606274330,bodyId=9,center={x=-94134462.000,y=12765534.000,z=-3634464.000},name='Jago',planetarySystemId=0,radius=61590,atmos=true,gravity=0.50},[10]={GM=78480000,bodyId=10,center={x=17448118.224,y=22966846.286,z=143078.820},name='Madis Moon 1',planetarySystemId=0,radius=10000,atmos=false,gravity=0.08},[11]={GM=237402000,bodyId=11,center={x=17194626.000,y=22243633.880,z=-214962.810},name='Madis Moon 2',planetarySystemId=0,radius=11000,atmos=false,gravity=0.10},[12]={GM=265046609,bodyId=12,center={x=17520614.000,y=22184730.000,z=-309989.990},name='Madis Moon 3',planetarySystemId=0,radius=15005,atmos=false,gravity=0.12},[21]={GM=2118960000,bodyId=21,center={x=457933.000,y=-1509011.000,z=115524.000},name='Alioth Moon 1',planetarySystemId=0,radius=30000,atmos=false,gravity=0.24},[22]={GM=2165833514,bodyId=22,center={x=-1692694.000,y=729681.000,z=-411464.000},name='Alioth Moon 4',planetarySystemId=0,radius=30330,atmos=false,gravity=0.24},[26]={GM=68234043600,bodyId=26,center={x=-1404835.000,y=562655.000,z=-285074.000},name='Sanctuary',planetarySystemId=0,radius=83400,atmos=true,gravity=1.00},[30]={GM=211564034,bodyId=30,center={x=29214402.000,y=10907080.695,z=433858.200},name='Thades Moon 1',planetarySystemId=0,radius=14002,atmos=false,gravity=0.11},[31]={GM=264870000,bodyId=31,center={x=29404193.000,y=10432768.000,z=19554.131},name='Thades Moon 2',planetarySystemId=0,radius=15000,atmos=false,gravity=0.12},[40]={GM=141264000,bodyId=40,center={x=-13503090.000,y=55594325.000,z=769838.640},name='Talemai Moon 2',planetarySystemId=0,radius=12000,atmos=false,gravity=0.10},[41]={GM=106830900,bodyId=41,center={x=-12800515.000,y=55700259.000,z=325207.840},name='Talemai Moon 3',planetarySystemId=0,radius=11000,atmos=false,gravity=0.09},[42]={GM=264870000,bodyId=42,center={x=-13058408.000,y=55781856.000,z=740177.760},name='Talemai Moon 1',planetarySystemId=0,radius=15000,atmos=false,gravity=0.12},[50]={GM=499917600,bodyId=50,center={x=-43902841.780,y=22261034.700,z=-48862386.000},name='Feli Moon 1',planetarySystemId=0,radius=14000,atmos=false,gravity=0.11},[70]={GM=396912600,bodyId=70,center={x=58969616.000,y=29797945.000,z=57969449.000},name='Sinnen Moon 1',planetarySystemId=0,radius=17000,atmos=false,gravity=0.14},[100]={GM=13975172474,bodyId=100,center={x=98865536.000,y=-13534464.000,z=-934461.990},name='Lacobus',planetarySystemId=0,radius=55650,atmos=true,gravity=0.46},[101]={GM=264870000,bodyId=101,center={x=98905288.170,y=-13950921.100,z=-647589.530},name='Lacobus Moon 3',planetarySystemId=0,radius=15000,atmos=false,gravity=0.12},[102]={GM=444981600,bodyId=102,center={x=99180968.000,y=-13783862.000,z=-926156.400},name='Lacobus Moon 1',planetarySystemId=0,radius=18000,atmos=false,gravity=0.14},[103]={GM=211503600,bodyId=103,center={x=99250052.000,y=-13629215.000,z=-1059341.400},name='Lacobus Moon 2',planetarySystemId=0,radius=14000,atmos=false,gravity=0.11},[110]={GM=9204742375,bodyId=110,center={x=14165536.000,y=-85634465.000,z=-934464.300},name='Symeon',planetarySystemId=0,radius=49050,atmos=true,gravity=0.39},[120]={GM=7135606629,bodyId=120,center={x=2865536.700,y=-99034464.000,z=-934462.020},name='Ion',planetarySystemId=0,radius=44950,atmos=true,gravity=0.36},[121]={GM=106830900,bodyId=121,center={x=2472916.800,y=-99133747.000,z=-1133582.800},name='Ion Moon 1',planetarySystemId=0,radius=11000,atmos=false,gravity=0.09},[122]={GM=176580000,bodyId=122,center={x=2995424.500,y=-99275010.000,z=-1378480.700},name='Ion Moon 2',planetarySystemId=0,radius=15000,atmos=false,gravity=0.12}}}end;atlas=Atlas()for U,V in pairs(atlas[0])do if w==nil or V.center.xx then x=V.center.x end;if y==nil or V.center.yz then z=V.center.y end end;GalaxyMapHTML=""local cY=1.1*(x-w)/1920;local cZ=1.4*(z-y)/1080;for U,V in pairs(atlas[0])do local ab=960+V.center.x/cY;local ac=540+V.center.y/cZ;GalaxyMapHTML=GalaxyMapHTML..''if not string.match(V.name,"Moon")and not string.match(V.name,"Sanctuary")then GalaxyMapHTML=GalaxyMapHTML..""..V.name..""end end;local bA=vec3(core.getConstructWorldPos())local ab=960+bA.x/cY;local ac=540+bA.y/cZ;GalaxyMapHTML=GalaxyMapHTML..''GalaxyMapHTML=GalaxyMapHTML.."You Are Here"GalaxyMapHTML=GalaxyMapHTML..[[]]MapXRatio=cY;MapYRatio=cZ;if screen_2 then screen_2.setHTML(''..GalaxyMapHTML)local bA=vec3(core.getConstructWorldPos())local ab=960+bA.x/cY;local ac=540+bA.y/cZ;GalaxyMapHTML=''GalaxyMapHTML=GalaxyMapHTML.."You Are Here"YouAreHere=screen_2.addContent((ab-80)/19.20,(ac-80)/10.80,GalaxyMapHTML)end;function PlanetRef()local function c_(d0)return type(d0)=='number'end;local function d1(d0)return type(tonumber(d0))=='number'end;local function d2(d3)return type(d3)=='table'end;local function d4(d5)return type(d5)=='string'end;local function d6(V)return d2(V)and c_(V.x and V.y and V.z)end;local function d7(d8)return d2(d8)and c_(d8.latitude and d8.longitude and d8.altitude and d8.bodyId and d8.systemId)end;local d9=math.pi/180;local da=180/math.pi;local db=1e-10;local c5=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local dc='::pos{'..c5 ..','..c5 ..','..c5 ..','..c5 ..','..c5 ..'}'local utils=require('cpml.utils')local vec3=require('cpml.vec3')local dd=utils.clamp;local function de(df,dg)if df==0 then return math.abs(dg)<1e-09 end;if dg==0 then return math.abs(df)<1e-09 end;return math.abs(df-dg)=0 then local ed=math.sqrt(ec)local ee=eb+ed;local ef=eb-ed;if ef>0 then return e2,ee,ef elseif ee>0 then return e2,ee,nil end end end;return nil,nil,nil end;function dE:closestBody(eg)assert(type(eg)=='table','Invalid coordinates.')local eh,e2;local ei=vec3(eg)for _,ej in pairs(self)do local ek=(ej.center-ei):len2()if not e2 or ek=0 and eo or 2*math.pi+eo;dC=math.pi/2-math.acos(en.z/cA)end;return setmetatable({latitude=dC,longitude=dD,altitude=bl,bodyId=self.bodyId,systemId=self.planetarySystemId},dy)end;function dm:convertToWorldCoordinates(dB)local el=d4(dB)and dA(dB)or dB;if el.bodyId==0 then return vec3(el.latitude,el.longitude,el.altitude)end;assert(d7(el),'Argument 1 (mapPosition) is not an instance of "MapPosition".')assert(el.systemId==self.planetarySystemId,'Argument 1 (mapPosition) has a different planetary system ID.')assert(el.bodyId==self.bodyId,'Argument 1 (mapPosition) has a different planetary body ID.')local ep=math.cos(el.latitude)return self.center+(self.radius+el.altitude)*vec3(ep*math.cos(el.longitude),ep*math.sin(el.longitude),math.sin(el.latitude))end;function dm:getAltitude(dw)return(vec3(dw)-self.center):len()-self.radius end;function dm:getDistance(dw)return(vec3(dw)-self.center):len()end;function dm:getGravity(dw)local eq=self.center-vec3(dw)local er=eq:len2()return self.GM/er*eq/math.sqrt(er)end;return setmetatable(PlanetaryReference,{__call=function(_,...)return dM(...)end})end;function Keplers()local vec3=require('cpml.vec3')local PlanetRef=PlanetRef()local function d4(d5)return type(d5)=='string'end;local function d2(d3)return type(d3)=='table'end;local function de(df,dg)if df==0 then return math.abs(dg)<1e-09 end;if dg==0 then return math.abs(df)<1e-09 end;return math.abs(df-dg)0 then eI=eH;eJ=eI+eC/2 end;if eJ>eC then eJ=eJ-eC end end;return{periapsis={position=ez,speed=eB/ex,circularOrbitSpeed=math.sqrt(eu/ex),altitude=ex-self.body.radius},apoapsis=eA and{position=eA,speed=eB/ey,circularOrbitSpeed=math.sqrt(eu/ey),altitude=ey-self.body.radius},currentVelocity=V,currentPosition=bA,eccentricity=ew,period=eC,eccentricAnomaly=eE,meanAnomaly=eG,timeToPeriapsis=eI,timeToApoapsis=eJ}end;local function eK(eL)local ej=PlanetRef.BodyParameters(eL.planetarySystemId,eL.bodyId,eL.radius,eL.center,eL.GM)return setmetatable({body=ej},Kepler)end;return setmetatable(Kepler,{__call=function(_,...)return eK(...)end})end;function Kinematics()local Kinematic={}local eM=30000000/3600;local eN=eM*eM;local eO=100;local function eP(V)return 1/math.sqrt(1-V*V/eN)end;function Kinematic.computeAccelerationTime(eQ,eR,eS)local eT=eM*math.asin(eQ/eM)return(eM*math.asin(eS/eM)-eT)/eR end;function Kinematic.computeDistanceAndTime(eQ,eS,eU,eV,eW,eX)eW=eW or 0;eX=eX or 0;local eY=eQ<=eS;local eZ=eV*(eY and 1 or-1)/eU;local e_=-eX/eU;local f0=eZ+e_;if eY and f0<=0 or not eY and f0>=0 then return-1,-1 end;local f1,f2=0,0;if eZ~=0 and eW>0 then local eT=math.asin(eQ/eM)local f3=math.pi*(eZ/2+e_)local f4=eZ*eW;local f5=eM*math.pi;local V=function(d3)local aH=(f3*d3-f4*math.sin(math.pi*d3/2/eW)+f5*eT)/f5;local f6=math.tan(aH)return eM*f6/math.sqrt(f6*f6+1)end;local f7=eY and function(d5)return d5>=eS end or function(d5)return d5<=eS end;f2=2*eW;if f7(V(f2))then local f8=0;while math.abs(f2-f8)>0.5 do local d3=(f2+f8)/2;if f7(V(d3))then f2=d3 else f8=d3 end end end;local f9=eQ;local fa=f2/eO;for fb=1,eO do local bm=V(fb*fa)f1=f1+(bm+f9)*fa/2;f9=bm end;if f2<2*eW then return f1,f2 end;eQ=f9 end;local eT=eM*math.asin(eQ/eM)local fc=(eM*math.asin(eS/eM)-eT)/f0;local fd=eN*math.cos(eT/eM)/f0;local cA=fd-eN*math.cos((f0*fc+eT)/eM)/f0;return cA+f1,fc+f2 end;function Kinematic.computeTravelTime(eQ,eR,cA)if cA==0 then return 0 end;if eR>0 then local eT=eM*math.asin(eQ/eM)local fd=eN*math.cos(eT/eM)/eR;return(eM*math.acos(eR*(fd-cA)/eN)-eT)/eR end;assert(eQ>0,'Acceleration and initial speed are both zero.')return cA/eQ end;function Kinematic.lorentz(V)return eP(V)end;return Kinematic end;PlanetaryReference=PlanetRef()galaxyReference=PlanetaryReference(Atlas())Kinematic=Kinematics()Kep=Keplers()function getDistanceDisplayString(cA)local fe=cA>100000;local W=""if fe then W=round(cA/1000/200,1).." SU"elseif cA<1000 then W=round(cA,1).." M"else W=round(cA/1000,1).." KM"end;return W end;function getDistanceDisplayString2(cA)local fe=cA>100000;local W=""if fe then W=round(cA/1000/200,2).." SU"elseif cA<1000 then W=round(cA,2).." M"else W=round(cA/1000,2).." KM"end;return W end;function getSpeedDisplayString(bm)return a(round(bm*3.6,0)+0.5).." km/h"end;function FormatTimeString(ff)local fg=a(ff/86400)local fh=a(ff/3600)local fi=a(ff/60%60)local ff=a(ff%60)if ff<0 or fh<0 or fi<0 then return"0s"end;if fg>0 then return fg.."d "..fh.."h "elseif fh>0 then return fh.."h "..fi.."m "elseif fi>0 then return fi.."m "..ff.."s"else return ff.."s"end end;function getMagnitudeInDirection(bc,d_)bc=vec3(bc)d_=vec3(d_):normalize()local W=bc*d_;return W.x+W.y+W.z end;function UpdateAutopilotTarget()if AutopilotTargetIndex==0 then AutopilotTargetName="None"AutopilotTargetPlanet=nil;return true end;local fj=AtlasOrdered[AutopilotTargetIndex].index;local fk=atlas[0][fj]if fk.center then AutopilotTargetName=fk.name;AutopilotTargetPlanet=galaxyReference[0][fj]if CustomTarget~=nil then if unit.getAtmosphereDensity()==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 end;CustomTarget=nil else CustomTarget=fk;for _,V in pairs(galaxyReference[0])do if V.name==CustomTarget.planetname then AutopilotTargetPlanet=V;AutopilotTargetName=nil;break end end end;AutopilotTargetCoords=vec3(AutopilotTargetPlanet.center)_,AutopilotEndSpeed=Kep(AutopilotTargetPlanet):escapeAndOrbitalSpeed(AutopilotTargetOrbit)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;UpdateAutopilotTarget()end;function DecrementAutopilotTargetIndex()AutopilotTargetIndex=AutopilotTargetIndex-1;if AutopilotTargetIndex<0 then AutopilotTargetIndex=#AtlasOrdered end;UpdateAutopilotTarget()end;function GetAutopilotMaxMass()local fl=LastMaxBrake/AutopilotTargetPlanet:getGravity(AutopilotTargetPlanet.center+vec3(0,0,1)*AutopilotTargetPlanet.radius):len()return fl end;function GetAutopilotTravelTime()if not Autopilot then AutopilotDistance=(AutopilotTargetPlanet.center-vec3(core.getConstructWorldPos())):len()end;local velocity=core.getWorldVelocity()local fm,fn=Kinematic.computeDistanceAndTime(vec3(velocity):len(),MaxGameVelocity,k(),Nav:maxForceForward(),warmup,0)local fo,fp;if not TurnBurn then fo,fp=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else fo,fp=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;local _,fq;if not TurnBurn then _,fq=GetAutopilotBrakeDistanceAndTime(vec3(velocity):len())else _,fq=GetAutopilotTBBrakeDistanceAndTime(vec3(velocity):len())end;local fr=0;local fs=0;if AutopilotCruising then fs=Kinematic.computeTravelTime(vec3(velocity):len(),0,AutopilotDistance)elseif fo+fm0 then return Kinematic.computeDistanceAndTime(bm,AutopilotEndSpeed,k(),0,0,LastMaxBrake-AutopilotPlanetGravity*k())else return 0,0 end end end;function GetAutopilotTBBrakeDistanceAndTime(bm)refreshLastMaxBrake()return Kinematic.computeDistanceAndTime(bm,AutopilotEndSpeed,k(),Nav:maxForceForward(),warmup,LastMaxBrake-AutopilotPlanetGravity*k())end;function GetFlightStyle()local fu=Nav.axisCommandManager:getAxisCommandType(0)local bx="TRAVEL"if fu==1 then bx="CRUISE"end;if Autopilot then bx="AUTOPILOT"end;return bx end;function hoverDetectGround()local fv=-1;if vBooster then fv=vBooster.distance()elseif hover then fv=hover.distance()end;return fv end;function round(c5,fw)local fx=10^(fw or 0)return a(c5*fx+0.5)/fx end;function tablelength(fy)local fz=0;for _ in pairs(fy)do fz=fz+1 end;return fz end;function BeginProfile(fA)ProfileTimeStart=system.getTime()end;function EndProfile(fA)local fB=system.getTime()-ProfileTimeStart;ProfileTimeSum=ProfileTimeSum+fB;ProfileCount=ProfileCount+1;if fB>ProfileTimeMax then ProfileTimeMax=fB end;if fB0 then if HasSpaceRadar and EmergencyWarp then local fJ=fI:gmatch('{"constructId[^}]*}[^}]*}')for V in fJ do local al,cA=V:match([[{"constructId":"([%d%.]*)","distance":([%d%.]*)]])if al~=nil and al~=""then cA=math.floor(cA)if cAIgnoreEmergencyWarpDistance then if NotTriedEmergencyWarp and json.decode(warpdrive.getData()).errorMsg~="PLANET TOO CLOSE"then if radar_1.hasMatchingTransponder(al)~=1 then if RequireLock then if not V:find('targetThreatState":0')then InEmergencyWarp=true;NotTriedEmergencyWarp=false;break end else InEmergencyWarp=true;NotTriedEmergencyWarp=false;break end end end end end end end;local fK=fI:find('identifiedConstructs":%[%]')if fK==nil and perisPanelID==nil then Peris=1;ToggleRadarPanel()end;if fK~=nil and perisPanelID~=nil then ToggleRadarPanel()end;if radarPanelID==nil then ToggleRadarPanel()end;RadarMessage=string.format([[Radar: %i contacts]],#fH)local fL={}for U,V in pairs(fH)do if radar_1.hasMatchingTransponder(V)==1 then fL[#fL+1]=V end end;if#fL>0 then local ac=15;RadarMessage=string.format([[%sFriendlies In Range]],RadarMessage,ac)for U,V in pairs(fL)do ac=ac+20;RadarMessage=string.format([[%s%s]],RadarMessage,ac,radar_1.getConstructName(V))end end else local fJ;fJ=fI:find('worksInEnvironment":false')if fJ then RadarMessage=[[Radar: Jammed]]else RadarMessage=[[Radar: No Contacts]]end;if radarPanelID~=nil then Peris=0;ToggleRadarPanel()end end end end;Animating=false;Animated=false;AddLocationsToAtlas()UpdateAutopilotTarget()collectgarbage("collect")unit.setTimer("apTick",apTickRate)unit.setTimer("oneSecond",1)unit.setTimer("tenthSecond",1/10)end)end;function script.onStop()_autoconf.hideCategoryPanels()if antigrav~=nil then antigrav.hide()end;if warpdrive~=nil then warpdrive.hide()end;core.hide()Nav.control.switchOffHeadlights()local fM=unit.getAtmosphereDensity()if door and(fM>0 or fM==0 and CoreAltitude<10000)then for _,V in pairs(door)do V.activate()end end;if forcefield and(fM>0 or fM==0 and CoreAltitude<10000)then for _,V in pairs(forcefield)do V.activate()end end;if dbHud then if not WipedDatabank then for U,V in pairs(AutoVariables)do dbHud.setStringValue(V,json.encode(_G[V]))end;for U,V in pairs(SaveableVariables)do dbHud.setStringValue(V,json.encode(_G[V]))end;system.print("Saved Variables to Datacore")end end;if button then button.activate()end end;function script.onTick(fN)if fN=="tenthSecond"then if AutopilotTargetName~="None"then if panelInterplanetary==nil then SetupInterplanetaryPanel()end;if AutopilotTargetName~=nil then planetMaxMass=GetAutopilotMaxMass()system.updateData(interplanetaryHeaderText,'{"label": "Target", "value": "'..AutopilotTargetName..'", "unit":""}')travelTime=GetAutopilotTravelTime()Distance=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()if not TurnBurn then BrakeDistance,BrakeTime=GetAutopilotBrakeDistanceAndTime(velMag)MaxBrakeDistance,MaxBrakeTime=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else BrakeDistance,BrakeTime=GetAutopilotTBBrakeDistanceAndTime(velMag)MaxBrakeDistance,MaxBrakeTime=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;system.updateData(widgetDistanceText,'{"label": "Distance", "value": "'..getDistanceDisplayString(Distance)..'", "unit":""}')system.updateData(widgetTravelTimeText,'{"label": "Travel Time", "value": "'..FormatTimeString(travelTime)..'", "unit":""}')system.updateData(widgetCurBrakeDistanceText,'{"label": "Cur Brake Distance", "value": "'..getDistanceDisplayString(BrakeDistance)..'", "unit":""}')system.updateData(widgetCurBrakeTimeText,'{"label": "Cur Brake Time", "value": "'..FormatTimeString(BrakeTime)..'", "unit":""}')system.updateData(widgetMaxBrakeDistanceText,'{"label": "Max Brake Distance", "value": "'..getDistanceDisplayString(MaxBrakeDistance)..'", "unit":""}')system.updateData(widgetMaxBrakeTimeText,'{"label": "Max Brake Time", "value": "'..FormatTimeString(MaxBrakeTime)..'", "unit":""}')system.updateData(widgetMaxMassText,'{"label": "Maximum Mass", "value": "'..string.format("%.2f tons",planetMaxMass/1000)..'", "unit":""}')if unit.getAtmosphereDensity()>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 unit.getAtmosphereDensity()==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 else system.updateData(interplanetaryHeaderText,'{"label": "Target", "value": "'..CustomTarget.name..'", "unit":""}')Distance=(vec3(core.getConstructWorldPos())-CustomTarget.position):len()system.updateData(widgetDistanceText,'{"label": "Distance", "value": "'..getDistanceDisplayString(Distance)..'", "unit":""}')system.removeDataFromWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)system.removeDataFromWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)system.removeDataFromWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)system.removeDataFromWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)system.removeDataFromWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)system.removeDataFromWidget(widgetMaxMassText,widgetMaxMass)system.removeDataFromWidget(widgetTravelTimeText,widgetTravelTime)end else HideInterplanetaryPanel()end;if warpdrive~=nil then if InEmergencyWarp then if json.decode(warpdrive.getData()).buttonMsg~="CANNOT WARP"then MsgText="EMERGENCY WARP ACTIVATED"MsgTimer=5;warpdrive.activateWarp()warpdrive.show()showWarpWidget=true;EmergencyWarp=false;InEmergencyWarp=false else MsgText="Emergency Warp Condition Met - Cannot Warp, will retry in 1 second\n"..json.decode(warpdrive.getData()).errorMsg;msgTick=1;InEmergencyWarp=false;unit.setTimer("reEmergencyWarp",1)end end;if json.decode(warpdrive.getData()).destination~="Unknown"and json.decode(warpdrive.getData()).distance>400000 then warpdrive.show()showWarpWidget=true else warpdrive.hide()showWarpWidget=false end end elseif fN=="oneSecond"then refreshLastMaxBrake(nil,true)updateDistance()updateRadar()updateWeapons()local ao={}local bx=GetFlightStyle()DrawOdometer(ao,TotalDistanceTrip,TotalDistanceTravelled,bx,FlightTime)checkDamage(ao)LastOdometerOutput=table.concat(ao,"")collectgarbage("collect")elseif fN=="reEmergencyWarp"then if EmergencyWarp then NotTriedEmergencyWarp=true;InEmergencyWarp=true end;unit.stopTimer("reEmergencyWarp")elseif fN=="msgTick"then local ao={}DisplayMessage(ao,"empty")MsgText="empty"unit.stopTimer("msgTick")MsgTimer=3 elseif fN=="animateTick"then Animated=true;Animating=false;SimulatedX=0;SimulatedY=0;unit.stopTimer("animateTick")elseif fN=="apTick"then local l=Nav.control.isRemoteControlled;RateOfChange=vec3(core.getConstructWorldOrientationForward()):dot(vec3(core.getWorldVelocity()):normalize())YawInput2=0;RollInput2=0;PitchInput2=0;LastApsDiff=-1;velocity=vec3(core.getWorldVelocity())velMag=vec3(velocity):len()sys=galaxyReference[0]planet=sys:closestBody(core.getConstructWorldPos())kepPlanet=Kep(planet)orbit=kepPlanet:orbitalParameters(core.getConstructWorldPos(),velocity)HovGndDet=hoverDetectGround()local fO=system.getMouseDeltaX()local fP=system.getMouseDeltaY()TargetGroundAltitude=Nav:getTargetGroundAltitude()local fQ=velMag>8334;if not fQ and LastIsWarping then if not BrakeIsOn then BrakeToggle()end;if Autopilot then ToggleAutopilot()end end;LastIsWarping=fQ;if BrakeIsOn then BrakeInput=1 else BrakeInput=0 end;CoreAltitude=core.getAltitude()if CoreAltitude==0 then CoreAltitude=(vec3(core.getConstructWorldPos())-planet.center):len()-planet.radius end;local ao={}HUDPrologue(ao)if showHud then updateHud(ao)else DisplayOrbitScreen(ao)DrawWarnings(ao)end;HUDEpilogue(ao)ao[#ao+1]=[[]]if MsgText~="empty"then DisplayMessage(ao,MsgText)end;if l()==0 and userControlScheme=="virtual joystick"then DrawDeadZone(ao)end;if l()==1 and screen_1 and screen_1.getMouseY()~=-1 then SimulatedX=screen_1.getMouseX()*2560;SimulatedY=screen_1.getMouseY()*1440;SetButtonContains()DrawButtons(ao)if screen_1.getMouseState()==1 then CheckButtons()end;ao[#ao+1]=string.format([[]],SimulatedX,SimulatedY)elseif system.isViewLocked()==0 then if l()==1 and HoldingCtrl then if not Animating then SimulatedX=SimulatedX+fO;SimulatedY=SimulatedY+fP end;SetButtonContains()DrawButtons(ao)if not Animating and not Animated then local fR=table.concat(ao,"")ao={}ao[#ao+1]=""ao[#ao+1]=GalaxyMapHTML;ao[#ao+1]=fR;ao[#ao+1]=""Animating=true;ao[#ao+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(ao,"")system.setScreen(content)elseif Animated then local fR=table.concat(ao,"")ao={}ao[#ao+1]=""ao[#ao+1]=GalaxyMapHTML;ao[#ao+1]=fR;ao[#ao+1]=""end;if not Animating then ao[#ao+1]=string.format([[]],SimulatedX,SimulatedY)end else CheckButtons()SimulatedX=0;SimulatedY=0 end else SimulatedX=SimulatedX+fO;SimulatedY=SimulatedY+fP;Distance=math.sqrt(SimulatedX*SimulatedX+SimulatedY*SimulatedY)if not HoldingCtrl and l()==0 then if userControlScheme=="virtual joystick"then if SimulatedX>0 and SimulatedX>DeadZone then YawInput2=YawInput2-(SimulatedX-DeadZone)*MouseXSensitivity elseif SimulatedX<0 and SimulatedX0 and SimulatedY>DeadZone then PitchInput2=PitchInput2-(SimulatedY-DeadZone)*MouseYSensitivity elseif SimulatedY<0 and SimulatedYDeadZone then DrawCursorLine(ao)end else SetButtonContains()DrawButtons(ao)end;ao[#ao+1]=string.format([[]],SimulatedX,SimulatedY)end;ao[#ao+1]=[[]]content=table.concat(ao,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end;if ProgradeIsOn then if velMag>MinAutopilotSpeed then local fS=AlignToWorldVector(vec3(velocity),0.01)if SpaceLand then autoRoll=true;if fS then ProgradeIsOn=false;ReentryMode=true;BeginReentry()SpaceLand=false;FinalLand=true;autoRoll=autoRollPreference end end end end;if RetrogradeIsOn then if velMag>MinAutopilotSpeed then AlignToWorldVector(-vec3(velocity))end end;if not ProgradeIsOn and SpaceLand then if unit.getAtmosphereDensity()==0 then ReentryMode=true;BeginReentry()SpaceLand=false;FinalLand=true else SpaceLand=false;ToggleAutopilot()end end;if FinalLand and CoreAltitudeReentrySpeed-100 then ToggleAutopilot()FinalLand=false end;if Autopilot and unit.getAtmosphereDensity()==0 then local fo,fp;if not TurnBurn then fo,fp=GetAutopilotBrakeDistanceAndTime(velMag)else fo,fp=GetAutopilotTBBrakeDistanceAndTime(velMag)end;fo=fo;fp=fp;local fT=AutopilotTargetCoords;if orbit.apoapsis==nil and velMag>300 and AutopilotAccelerating then local fU=(vec3(AutopilotTargetCoords)-vec3(core.getConstructWorldPos())):normalize()-vec3(velocity):normalize()local fV=getMagnitudeInDirection(fU,AutopilotShipUp)local fW=getMagnitudeInDirection(fU,AutopilotShipRight)local fX=-fW*AutopilotDistance*velMag*TrajectoryAlignmentStrength;local fY=-fV*AutopilotDistance*velMag*TrajectoryAlignmentStrength;fT=AutopilotTargetCoords+-fX*vec3(AutopilotShipRight)+-fY*vec3(AutopilotShipUp)end;AutopilotDistance=(vec3(fT)-vec3(core.getConstructWorldPos())):len()local fZ=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()system.updateData(widgetDistanceText,'{"label": "Distance", "value": "'..getDistanceDisplayString(fZ)..'", "unit":""}')local f_=true;local g0=(AutopilotTargetPlanet.center-(vec3(core.getConstructWorldPos())+vec3(velocity):normalize()*AutopilotDistance)):len()-AutopilotTargetPlanet.radius;system.updateData(widgetTrajectoryAltitudeText,'{"label": "Projected Altitude", "value": "'..getDistanceDisplayString(g0)..'", "unit":""}')if not AutopilotCruising and not AutopilotBraking then f_=AlignToWorldVector((fT-vec3(core.getConstructWorldPos())):normalize())elseif TurnBurn then f_=AlignToWorldVector(-vec3(velocity):normalize())end;if AutopilotAccelerating then if not f_ or BrakeIsOn then AutopilotStatus="Adjusting Trajectory"else AutopilotStatus="Accelerating"end;if vec3(core.getConstructWorldOrientationForward()):dot(velocity)<0 and velMag>300 then BrakeIsOn=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false elseif not APThrottleSet then BrakeIsOn=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)APThrottleSet=true end;if vec3(core.getVelocity()):len()>=MaxGameVelocity and math.abs(g0-AutopilotTargetOrbit)<1000 or unit.getThrottle()==0 and APThrottleSet then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false end;if AutopilotDistance<=fo then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false end elseif AutopilotBraking then BrakeIsOn=true;BrakeInput=1;if TurnBurn then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,100)end;if orbit.periapsis~=nil and orbit.eccentricity<1 then AutopilotStatus="Circularizing"if orbit.eccentricity>LastEccentricity or orbit.apoapsis.altitude0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if f_ then if not AutopilotRealigned then AutopilotTargetCoords=vec3(AutopilotTargetPlanet.center)+(AutopilotTargetOrbit+AutopilotTargetPlanet.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotRealigned=true;AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()elseif f_ then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not APThrottleSet then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)APThrottleSet=true;BrakeIsOn=false end end end end end;if FollowMode then autoRoll=true;local g1=0;local bA=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local g2=bA-vec3(core.getConstructWorldPos())local g3=vec3(g2):project_on(vec3(core.getConstructWorldOrientationForward())):len()local g4=vec3(g2):project_on(vec3(core.getConstructWorldOrientationRight())):len()local cA=math.sqrt(g3*g3+g4*g4)AlignToWorldVector(g2:normalize())local g5=40;local g6=cAg9 then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(g1-aF)local ga=pitchPID:get()PitchInput2=ga end end;local bT=vec3(core.getWorldVertical())*-1;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget then local bl=CoreAltitude;local gb=HoldAltitude-bl;local gc=500+velMag;local g1=(utils.smoothstep(gb,-gc,gc)-0.5)*2*MaxPitch;if not AltitudeHold then g1=0 end;autoRoll=true;if Reentry then local gd=ReentrySpeed;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=gd then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,gd)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if not ReentryMode then g1=-80;if unit.getAtmosphereDensity()>0.02 then MsgText="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;g1=0;autoRoll=autoRollPreference end elseif Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==ReentrySpeed then ReentryMode=false;Reentry=false;autoRoll=autoRollPreference end end;local ge=PitchInput2;if velMag>MinAutopilotSpeed then AlignToWorldVector(vec3(velocity))end;if VectorToTarget and CustomTarget~=nil and AutopilotTargetIndex>0 then local be=CustomTarget.position-vec3(core.getConstructWorldPos())AlignToWorldVector(be)local gf=be:len()-be:project_on(bT):len()local a6=json.decode(unit.getData()).maxBrake;local bR=velocity.x*bT.x+velocity.y*bT.y+velocity.z*bT.z;local gg=velocity:len()-math.abs(bR)local gh=vec3(core.getWorldAirFrictionAcceleration())if a6~=nil then LastMaxBrake=a6;BrakeDistance,BrakeTime=Kinematic.computeDistanceAndTime(gg,0,core.getConstructMass(),0,0,a6+(gh:len()-gh:project_on(bT):len())*core.getConstructMass())else BrakeDistance,BrakeTime=Kinematic.computeDistanceAndTime(gg,0,core.getConstructMass(),0,0,LastMaxBrake+vec3(core.getWorldAirFrictionAcceleration()):len()*core.getConstructMass())end;StrongBrakes=planet.gravity*9.80665*core.getConstructMass()LastTargetDistance and not AltitudeHold and not AutoTakeoff then BrakeLanding=true;VectorToTarget=false end;LastTargetDistance=gf end;PitchInput2=ge;local bo=vec3(core.getConstructWorldOrientationForward())local bp=vec3(core.getConstructWorldOrientationRight())local bn=vec3(core.getWorldVertical())local fv=-1;local aF=getPitch(bn,bo,bp)local g9=0.1;if BrakeLanding then g1=0;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)local bR=velocity.x*bT.x+velocity.y*bT.y+velocity.z*bT.z;fv=HovGndDet;if fv>-1 then if math.abs(g1-aF)50000 then if Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=5000 then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,5000)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end end end;if math.abs(g1-aF)>g9 then if pitchPID==nil then pitchPID=pid.new(8*0.01,0,8*0.1)end;pitchPID:inject(g1-aF)local ga=pitchPID:get()PitchInput2=PitchInput2+ga end end;LastEccentricity=orbit.eccentricity;if antigrav and CoreAltitude<200000 then if antigrav.getState()==1 then local velocity=vec3(core.getWorldVelocity())local bT=vec3(core.getWorldVertical())*-1;local bR=velocity.x*bT.x+velocity.y*bT.y+velocity.z*bT.z;local gi=antigrav.getBaseAltitude()if AntigravTargetAltitude==nil then AntigravTargetAltitude=1000 end;local gj=unit.getThrottle()if Nav.axisCommandManager:getAxisCommandType(0)==1 then gj=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)end;local gk=math.abs(CoreAltitude-gi)if gj>-1 and gj<1 and gk>10 and gk<501 and unit.getAtmosphereDensity()<0.01 then if CoreAltitude>antigrav.getBaseAltitude()and AntigravTargetAltitude>CoreAltitude and bR<0 or CoreAltitude0 then BrakeIsOn=true else BrakeIsOn=false end end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end else if AntigravTargetAltitude==nil then desiredBaseAltitude=CoreAltitude else desiredBaseAltitude=AntigravTargetAltitude end end end end end;function script.onFlush()if antigrav then if antigrav.getState()==0 and antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(AntigravTargetAltitude)end end;local gl=2;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)gl=math.max(gl,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 gm=utils.clamp(PitchInput+PitchInput2+system.getControlDeviceForwardInput(),-1,1)local gn=utils.clamp(RollInput+RollInput2+system.getControlDeviceYawInput(),-1,1)local go=utils.clamp(YawInput+YawInput2-system.getControlDeviceLeftRightInput(),-1,1)local gp=BrakeInput;local gq=vec3(core.getWorldVertical())local gr=vec3(core.getConstructWorldOrientationUp())local gs=vec3(core.getConstructWorldOrientationForward())local gt=vec3(core.getConstructWorldOrientationRight())local gu=vec3(core.getWorldVelocity())local gv=vec3(core.getWorldVelocity()):normalize()local gw=getRoll(gq,gs,gt)local gx=math.abs(gw)local gy=utils.sign(gw)local f=unit.getAtmosphereDensity()local gz=vec3(core.getWorldAngularVelocity())local gA=gm*pitchSpeedFactor*gt+gn*rollSpeedFactor*gs+go*yawSpeedFactor*gr;if gq:len()>0.01 and f>0.0 or ProgradeIsOn then local gB=1.0;if autoRoll==true and gx>gB and gn==0 then local gC=utils.clamp(0,gx-30,gx+30)if rollPID==nil then rollPID=pid.new(autoRollFactor*0.01,0,autoRollFactor*0.1)end;rollPID:inject(gC-gw)local gD=rollPID:get()gA=gA+gD*gs end end;if gq:len()>0.01 and f>0.0 then local gE=20.0;if turnAssist==true and gx>gE and gm==0 and go==0 then local gF=turnAssistFactor*0.1;local gG=turnAssistFactor*0.025;local gH=(gx-gE)/(180-gE)*180;local gI=0;if gH<90 then gI=gH/90 elseif gH<180 then gI=(180-gH)/90 end;gI=gI*gI;local gJ=-gy*gG*(1.0-gI)local gK=gF*gI;gA=gA+gK*gt+gJ*gr end end;local gL=1;local gM=0;local gN=1;local gO=gl*(gA-gz)local gP=vec3(core.getWorldAirFrictionAngularAcceleration())gO=gO-gP;Nav:setEngineTorqueCommand('torque',gO,gL,'airfoil','','',gN)local gQ=-gp*(brakeSpeedFactor*gu+brakeFlatFactor*gv)Nav:setEngineForceCommand('brake',gQ)local gR=''local gS=vec3()local gT=false;local gU='thrust analog longitudinal'local gV=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if gV==axisCommandType.byThrottle then local gW=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(gU,axisCommandId.longitudinal)Nav:setEngineForceCommand(gU,gW,gL)elseif gV==axisCommandType.byTargetSpeed then local gW=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)gR=gR..' , '..gU;gS=gS+gW;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then gT=true end end;local gX='thrust analog lateral'local gY=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if gY==axisCommandType.byThrottle then local gZ=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(gX,axisCommandId.lateral)Nav:setEngineForceCommand(gX,gZ,gL)elseif gY==axisCommandType.byTargetSpeed then local g_=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)gR=gR..' , '..gX;gS=gS+g_ end;local h0='thrust analog vertical'local h1=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if h1==axisCommandType.byThrottle then local h2=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(h0,axisCommandId.vertical)if UpAmount~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(h0,h2,gL,'airfoil','ground','',gN)else Nav:setEngineForceCommand(h0,vec3(),gL)Nav:setEngineForceCommand('airfoil vertical',h2,gL,'airfoil','','',gN)Nav:setEngineForceCommand('ground vertical',h2,gL,'ground','','',gN)end elseif h1==axisCommandType.byTargetSpeed then if UpAmount==0 then Nav:setEngineForceCommand('hover',vec3(),gL)end;local h3=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)gR=gR..' , '..h0;gS=gS+h3 end;if gS:len()>constants.epsilon then if BrakeInput~=0 or gT or math.abs(gv:dot(gs))<0.95 then gR=gR..', brake'end;Nav:setEngineForceCommand(gR,gS,gM,'','','',gN)end;Nav:setBoosterCommand('rocket_engine')if IsBoosting then local bm=vec3(core.getVelocity()):len()local h4=unit.setEngineThrust;local h5=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local gj=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if bm*3.6>gj*(1-h5)then h4('rocket_engine',0)elseif IsBoosting then h4('rocket_engine',1)end else local h6=unit.getThrottle()local g8=h6/100;if f==0 then g8=g8*MaxGameVelocity;if bm>=g8*(1-h5)then h4('rocket_engine',0)elseif IsBoosting then h4('rocket_engine',1)end else g8=g8*1050/3.6;if bm>=g8*(1-h5)then h4('rocket_engine',0)elseif IsBoosting then h4('rocket_engine',1)end end end end end;function script.onUpdate()if not SetupComplete then local _,W=coroutine.resume(beginSetup)if W then SetupComplete=true end else Nav:update()if not Animating and content~=LastContent then system.setScreen(content)end;LastContent=content end end;function script.onActionStart(h7)if h7=="gear"then GearExtended=not GearExtended;if GearExtended then VectorToTarget=false;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)if(vBooster or hover)and HovGndDet==-1 and(unit.getAtmosphereDensity()>0 or CoreAltitudeMinAutopilotSpeed then MsgText="WARNING: Insufficient Brakes - Attempting landing anyway"end;Reentry=false;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=true;autoRoll=true;GearExtended=false else BrakeIsOn=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end else Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end elseif h7=="light"then if Nav.control.isAnyHeadlightSwitchedOn()==1 then Nav.control.switchOffHeadlights()else Nav.control.switchOnHeadlights()end elseif h7=="forward"then PitchInput=PitchInput-1 elseif h7=="backward"then PitchInput=PitchInput+1 elseif h7=="left"then RollInput=RollInput-1 elseif h7=="right"then RollInput=RollInput+1 elseif h7=="yawright"then YawInput=YawInput-1 elseif h7=="yawleft"then YawInput=YawInput+1 elseif h7=="straferight"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,1.0)elseif h7=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,-1.0)elseif h7=="up"then UpAmount=UpAmount+1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,1.0)elseif h7=="down"then UpAmount=UpAmount-1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,-1.0)elseif h7=="groundaltitudeup"then OldButtonMod=HoldAltitudeButtonModifier;OldAntiMod=AntiGravButtonModifier;if antigrav and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude+AntiGravButtonModifier else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+HoldAltitudeButtonModifier else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif h7=="groundaltitudedown"then OldButtonMod=HoldAltitudeButtonModifier;OldAntiMod=AntiGravButtonModifier;if antigrav and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude-AntiGravButtonModifier;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-HoldAltitudeButtonModifier else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif h7=="option1"then IncrementAutopilotTargetIndex()ToggleView=false elseif h7=="option2"then DecrementAutopilotTargetIndex()ToggleView=false elseif h7=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;ToggleView=false;ToggleWidgets()elseif h7=="option4"then ToggleAutopilot()ToggleView=false elseif h7=="option5"then ToggleTurnBurn()ToggleView=false elseif h7=="option6"then ToggleAltitudeHold()ToggleView=false elseif h7=="option7"then wipeSaveVariables()ToggleView=false elseif h7=="option8"then ToggleFollowMode()ToggleView=false elseif h7=="option9"then if gyro~=nil then gyro.toggle()GyroIsOn=gyro.getState()==1 end;ToggleView=false elseif h7=="lshift"then if system.isViewLocked()==1 then HoldingCtrl=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif Nav.control.isRemoteControlled()==1 and ShiftShowsRemoteButtons then HoldingCtrl=true;Animated=false;Animating=false end elseif h7=="brake"then if brakeToggle then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif h7=="lalt"then if Nav.control.isRemoteControlled()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif h7=="booster"then IsBoosting=not IsBoosting;if IsBoosting then unit.setEngineThrust('rocket_engine',1)else unit.setEngineThrust('rocket_engine',0)end elseif h7=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)elseif h7=="speedup"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)else IncrementAutopilotTargetIndex()end elseif h7=="speeddown"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)else DecrementAutopilotTargetIndex()end elseif h7=="antigravity"then if antigrav~=nil then ToggleAntigrav()end elseif h7=="warp"then if warpdrive~=nil then if not InEmergencyWarp then if showWarpWidget then warpdrive.hide()showWarpWidget=false else warpdrive.show()showWarpWidget=true end;if json.decode(warpdrive.getData()).buttonMsg=="CANNOT WARP"then MsgText=json.decode(warpdrive.getData()).errorMsg else warpdrive.activateWarp()warpdrive.show()showWarpWidget=true end else InEmergencyWarp=false;EmergencyWarp=false;MsgText="Emergency Warp Cancelled"end end end end;function script.onActionStop(h7)if h7=="forward"then PitchInput=0 elseif h7=="backward"then PitchInput=0 elseif h7=="left"then RollInput=0 elseif h7=="right"then RollInput=0 elseif h7=="yawright"then YawInput=0 elseif h7=="yawleft"then YawInput=0 elseif h7=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)elseif h7=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)elseif h7=="up"then UpAmount=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif h7=="down"then UpAmount=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif h7=="groundaltitudeup"then if antigrav and antigrav.getState()==1 then AntiGravButtonModifier=OldAntiMod elseif AltitudeHold then HoldAltitudeButtonModifier=OldButtonMod end;ToggleView=false elseif h7=="groundaltitudedown"then if antigrav and antigrav.getState()==1 then AntiGravButtonModifier=OldAntiMod elseif AltitudeHold then HoldAltitudeButtonModifier=OldButtonMod end;ToggleView=false elseif h7=="lshift"then if system.isViewLocked()==1 then HoldingCtrl=false;SimulatedX=0;SimulatedY=0;system.lockView(PrevViewLock)elseif Nav.control.isRemoteControlled()==1 and ShiftShowsRemoteButtons then HoldingCtrl=false;Animated=false;Animating=false end elseif h7=="brake"then if not brakeToggle then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif h7=="lalt"then if Nav.control.isRemoteControlled()==0 and freeLookToggle then if ToggleView then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else ToggleView=true end elseif Nav.control.isRemoteControlled()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end end end;function script.onActionLoop(h7)if h7=="groundaltitudeup"then if antigrav and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude+AntiGravButtonModifier;AntiGravButtonModifier=AntiGravButtonModifier*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+HoldAltitudeButtonModifier;HoldAltitudeButtonModifier=HoldAltitudeButtonModifier*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif h7=="groundaltitudedown"then if antigrav and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude-AntiGravButtonModifier;AntiGravButtonModifier=AntiGravButtonModifier*1.05;BrakeIsOn=false;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-HoldAltitudeButtonModifier;HoldAltitudeButtonModifier=HoldAltitudeButtonModifier*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif h7=="speedup"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end elseif h7=="speeddown"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end;function DisplayMessage(ao,h8)if h8~="empty"then ao[#ao+1]=[[]]for h9 in string.gmatch(h8,"([^\n]+)")do ao[#ao+1]=string.format([[%s]],h9)end;ao[#ao+1]=[[]]end;if MsgTimer~=0 then unit.setTimer("msgTick",MsgTimer)MsgTimer=0 end end;function updateDistance()local a1=system.getTime()local velocity=vec3(core.getWorldVelocity())local bv=vec3(velocity):len()local ha=a1-LastTravelTime;if bv>1.38889 then bv=bv/1000;local hb=bv*(a1-LastTravelTime)TotalDistanceTravelled=TotalDistanceTravelled+hb;TotalDistanceTrip=TotalDistanceTrip+hb end;FlightTime=FlightTime+ha;TotalFlightTime=TotalFlightTime+ha;LastTravelTime=a1 end;script.onStart() -- error handling code added by wrap.lua diff --git a/ChangeLog.md b/ChangeLog.md index 6044aaf..6166b15 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ ## ChangeLog - Most recent changes at the top +Version 4.836 +- Added user variable ShowOdometer default true. If you toggle it off then the Odometer panel doesnt show up top. +- Added Yaw to center of AH when in atmo and moving fast enough. + Version 4.835 - With NQ concurrence - Modified AGG so that when you turn it OFF, the BaseAltitude will rapidly reach the TargetAltitude, allowing you to resume using your AGG without waiting for the Base Altitude to reach Target Altitude at 3.8m/s. Speed while AGG diff --git a/src/ButtonHUD.lua b/src/ButtonHUD.lua index 820a463..5c13ae8 100644 --- a/src/ButtonHUD.lua +++ b/src/ButtonHUD.lua @@ -10,7 +10,7 @@ function script.onStart() {1000, 5000, 10000, 20000, 30000}) -- Written by Dimencia and Archaegeo. Optimization and Automation of scripting by ChronosWS Linked sources where appropriate, most have been modified. - VERSION_NUMBER = 4.835 + VERSION_NUMBER = 4.836 -- function localizations local mfloor = math.floor local stringf = string.format @@ -48,6 +48,7 @@ function script.onStart() circleRad = 400 -- export: The size of the artifical horizon circle, recommended minimum 100, maximum 400. Looks different > 200. Set to 0 to remove. DeadZone = 50 -- export: Number of pixels of deadzone at the center of the screen showHud = true -- export: Uncheck to hide the HUD and only use autopilot features via ALT+# keys. + ShowOdometer = true -- export: Uncheck to hide the odometer panel up top. hideHudOnToggleWidgets = true -- export: Uncheck to keep showing HUD when you toggle on the widgets via ALT+3. ShiftShowsRemoteButtons = true -- export: Whether or not pressing Shift in remote controller mode shows you the buttons (otherwise no access to them) StallAngle = 35 --export: Determines how much Autopilot is allowed to make you yaw/pitch in atmosphere. Also gives a stall warning when not autopilot. (default 35, higher = more tolerance for yaw/pitch/roll) @@ -1589,7 +1590,7 @@ function script.onStart() if not IsInFreeLook() or brightHud then if nearPlanet then -- use real pitch, roll, and heading DrawRollLines (newContent, centerX, centerY, originalRoll, bottomText, nearPlanet) - DrawArtificialHorizon(newContent, originalPitch, originalRoll, atmos, centerX, centerY, nearPlanet) + DrawArtificialHorizon(newContent, originalPitch, originalRoll, atmos, centerX, centerY, nearPlanet, mfloor(getRelativeYaw(velocity)), speed) DrawAltitudeDisplay(newContent, altitude, atmos) else -- use Relative Pitch and Relative Yaw DrawRollLines (newContent, centerX, centerY, roll, bottomText, nearPlanet) @@ -1703,6 +1704,7 @@ function script.onStart() refreshLastMaxBrake(gravity) maxThrust = Nav:maxForceForward() totalMass = constructMass() + if not ShowOdometer then return end local accel = (vec3(core.getWorldAcceleration()):len() / 9.80665) if gravity > 0.1 then reqThrust = totalMass * gravity @@ -1914,7 +1916,7 @@ function script.onStart() ]], yawx, yawy+25, yawC, yawx, yawy+35, bottomText) end - function DrawArtificialHorizon(newContent, originalPitch, originalRoll, atmos, centerX, centerY, nearPlanet) + function DrawArtificialHorizon(newContent, originalPitch, originalRoll, atmos, centerX, centerY, nearPlanet, atmoYaw, speed) -- ** CIRCLE ALTIMETER - Base Code from Discord @Rainsome = Youtube CaptainKilmar** local horizonRadius = circleRad -- Aliased global local pitchX = math.floor(horizonRadius * 3 / 5) @@ -1965,6 +1967,14 @@ function script.onStart() end if horizonRadius > 200 then if atmos > 0 then + if speed > MinAutopilotSpeed then + newContent[#newContent + 1] = stringf([[" + + %s + %d deg + + ]], centerX, centerY-15, "Yaw", centerX, centerY+20, atmoYaw) + end newContent[#newContent + 1] = stringf([[]], -originalRoll, centerX, centerY) else newContent[#newContent + 1] = stringf([[]], centerX, centerY) @@ -1975,20 +1985,31 @@ function script.onStart() centerX+pitchX-25, centerY-5, centerX+pitchX-20, centerY, centerX+pitchX-25, centerY+5, centerX+pitchX-30, centerY+4, pitchC) newContent[#newContent +1] = "" end - newContent[#newContent + 1] = stringf([[]], - centerX-50, centerY) + newContent[#newContent + 1] = stringf([[]], + centerX-math.floor(horizonRadius/2)+15, centerY, horizonRadius-10) if atmos == 0 and nearPlanet then newContent[#newContent + 1] = stringf([[]], (-1 * originalRoll), centerX, centerY, centerX-pitchX+10, centerY, pitchX*2-20) end newContent[#newContent + 1] = "" if horizonRadius < 200 then - newContent[#newContent + 1] = stringf([[" - - %s - %d deg - - ]], centerX, centerY-horizonRadius, pitchstring, centerX, centerY-horizonRadius+10, pitchC) + if atmos > 0 and speed > MinAutopilotSpeed then + newContent[#newContent + 1] = stringf([[" + + %s + %d deg + %s + %d deg + + ]], centerX, centerY-horizonRadius, pitchstring, centerX, centerY-horizonRadius+10, pitchC, centerX, centerY-15, "Yaw", centerX, centerY+20, atmoYaw) + else + newContent[#newContent + 1] = stringf([[" + + %s + %d deg + + ]], centerX, centerY-horizonRadius, pitchstring, centerX, centerY-horizonRadius+15, pitchC ) + end end end end