From 26838b28144b44c70a9fdfcbb9d21b9467114f26 Mon Sep 17 00:00:00 2001 From: archaegeo Date: Fri, 8 Jan 2021 19:45:37 -0500 Subject: [PATCH 1/2] Fixed addlocation via waypoint --- ButtonHUD.conf | 54 +++++++++++++++++++------------------- ChangeLog.md | 5 ++++ src/ButtonHUD.lua | 66 ++++++++++++++++++++++++++++++----------------- 3 files changed, 74 insertions(+), 51 deletions(-) diff --git a/ButtonHUD.conf b/ButtonHUD.conf index 48796da..1c99a2b 100644 --- a/ButtonHUD.conf +++ b/ButtonHUD.conf @@ -169,10 +169,10 @@ handlers: ExternalAGG = false --export: Toggle On if using an external AGG system. If on will prevent this HUD from doing anything with AGG. UseSatNav = false --export: Toggle on if using Trog SatNav script. This will provide SatNav support. 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. - Nav=Navigator.new(system,core,unit)script={}BrakeToggleStatus=BrakeToggleDefault;BrakeIsOn=false;RetrogradeIsOn=false;ProgradeIsOn=false;Autopilot=false;TurnBurn=false;AltitudeHold=false;BrakeLanding=false;AutoTakeoff=false;DisplayOrbit=true;Reentry=false;HoldAltitude=1000;AutopilotAccelerating=false;AutopilotRealigned=false;AutopilotBraking=false;AutopilotCruising=false;AutopilotEndSpeed=0;AutopilotStatus="Aligning"AutopilotPlanetGravity=0;PrevViewLock=1;AutopilotTargetName="None"AutopilotTargetCoords=nil;AutopilotTargetIndex=0;GearExtended=nil;TargetGroundAltitude=LandingGearGroundHeight;TotalDistanceTravelled=0.0;TotalFlightTime=0;SavedLocations={}VectorToTarget=false;LocationIndex=0;LastMaxBrake=0;LockPitch=nil;LastMaxBrakeInAtmo=0;AntigravTargetAltitude=core.getAltitude()LastStartTime=0;local a={"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","AtmoSpeedLimit","ReentryAltitude","centerX","centerY","vSpdMeterX","vSpdMeterY","altMeterX","altMeterY","fuelX","fuelY","LandingGearGroundHeight","TrajectoryAlignmentStrength","RemoteHud","StallAngle","ResolutionX","ResolutionY","UseSatNav","FuelTankOptimization","ContainerOptimization","ExtraLongitudeTags","ExtraLateralTags","ExtraVerticalTags"}local b={"BrakeToggleStatus","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","LockPitch","LastMaxBrakeInAtmo","AntigravTargetAltitude","LastStartTime"}local c=system.print;local d=math.floor;local e=string.format;local f=json.decode;local g=json.encode;local h=core.getElementMaxHitPointsById;local j=unit.getAtmosphereDensity;local k=core.getElementHitPointsById;local l=core.getElementTypeById;local m=core.getElementMassById;local n=core.getConstructMass;local o=Nav.control.isRemoteControlled;function round(p,q)local r=10^(q or 0)return d(p*r+0.5)/r end;local s=round(ResolutionX/2,0)local t=round(ResolutionY/2,0)local u=false;local v=true;local w=55;local x=false;local y=1;local z=1;local A=false;local B=0;local C=0;local D=0;local E=0;local F=0;local G=0;local H=0;local I=false;local J=false;local K="empty"local L=1;local M=5;local N=5;local O=false;local P,Q=0;local R,S=0;local T=false;local U=false;local V=nil;local W=0;local X=0;local Y=false;local Z=0;local a0=0;local a1=0;local a2=3;local a3=0;local a4=""local a5=""local a6=0;local a7=false;local a8=false;local a9=false;local aa=-1;local ab=false;local ac=""local ad=j()>0;local ae=core.getAltitude()local af=core.getElementIdList()local ag=system.getTime()local ah=nil;local ai=false;local aj=[[rgb(]]..d(PrimaryR+0.5)..","..d(PrimaryG+0.5)..","..d(PrimaryB+0.5)..[[)]]local ak=[[rgb(]]..d(PrimaryR*0.9+0.5)..","..d(PrimaryG*0.9+0.5)..","..d(PrimaryB*0.9+0.5)..[[)]]local al={}local am=0;local an=0;local ao=""local ap=true;local aq={}local ar=1;local as=0.001;local at=ResolutionX;local au=ResolutionY;local av=nil;local aw=nil;local ax=nil;local ay=nil;local az=false;local aA=false;local aB=0;local aC=nil;local aD={}local aE={}local aF={}local aG=0;local aH=false;local aI={}local aJ={}local aK=d(1/apTickRate)*2;local aL={}local aM={}local aN={}local aO={}local aP=false;local aQ=16;local aR=0;local aS=nil;local aT=""local aU=nil;local aV=nil;local aW=nil;local aX=nil;local aY=nil;local aZ=nil;local a_=nil;local b0=false;local b1=false;local b2=autoRollPreference;function LoadVariables()if dbHud_1 then local b3=dbHud_1.hasKey;if not useTheseSettings then for b4,b5 in pairs(a)do if b3(b5)then local b6=f(dbHud_1.getStringValue(b5))if b6~=nil then c(b5 .." "..dbHud_1.getStringValue(b5))_G[b5]=b6;az=true end end end end;coroutine.yield()for b4,b5 in pairs(b)do if b3(b5)then local b6=f(dbHud_1.getStringValue(b5))if b6~=nil then c(b5 .." "..dbHud_1.getStringValue(b5))_G[b5]=b6;az=true end end end;if useTheseSettings then K="Updated user preferences used. Will be saved when you exit seat.\nToggle off useTheseSettings to use saved values"a2=5 elseif az then K="Loaded Saved Variables (see Lua Chat Tab for list)"else K="No Saved Variables Found - Stand up / leave remote to save settings"end else K="No databank found, install one anywhere and rerun the autoconfigure to save variables"end;local b7=system.getTime()if LastStartTime+180b9 then b9=b8 end;if ContainerOptimization>0 then b9=b9-b9*ContainerOptimization*0.05 end;if FuelTankOptimization>0 then b9=b9-b9*FuelTankOptimization*0.05 end;return b9 end;function ProcessElements()for b4 in pairs(af)do local type=l(af[b4])if type=="landing gear"then A=true end;if type=="dynamic core"then local ba=h(af[b4])if ba>10000 then aQ=128 elseif ba>1000 then aQ=64 elseif ba>150 then aQ=32 end end;aG=aG+h(af[b4])if fuelX~=0 and fuelY~=0 then if type=="Atmospheric Fuel Tank"or type=="Space Fuel Tank"or type=="Rocket Fuel Tank"then local ba=h(af[b4])local bb=m(af[b4])local b8=0;local bc=system.getTime()if type=="Atmospheric Fuel Tank"then local b9=400;local bd=35.03;if ba>10000 then b9=51200;bd=5480 elseif ba>1300 then b9=6400;bd=988.67 elseif ba>150 then b9=1600;bd=182.67 end;b8=bb-bd;if fuelTankHandlingAtmo>0 then b9=b9+b9*fuelTankHandlingAtmo*0.2 end;b9=CalculateFuelVolume(b8,b9)aD[#aD+1]={af[b4],core.getElementNameById(af[b4]),b9,bd,b8,bc}end;if type=="Rocket Fuel Tank"then local b9=320;local bd=173.42;if ba>65000 then b9=40000;bd=25740 elseif ba>6000 then b9=5120;bd=4720 elseif ba>700 then b9=640;bd=886.72 end;b8=bb-bd;if fuelTankHandlingRocket>0 then b9=b9+b9*fuelTankHandlingRocket*0.2 end;b9=CalculateFuelVolume(b8,b9)aF[#aF+1]={af[b4],core.getElementNameById(af[b4]),b9,bd,b8,bc}end;if type=="Space Fuel Tank"then local b9=2400;local bd=182.67;if ba>10000 then b9=76800;bd=5480 elseif ba>1300 then b9=9600;bd=988.67 end;b8=bb-bd;if fuelTankHandlingSpace>0 then b9=b9+b9*fuelTankHandlingSpace*0.2 end;b9=CalculateFuelVolume(b8,b9)aE[#aE+1]={af[b4],core.getElementNameById(af[b4]),b9,bd,b8,bc}end end end end end;function SetupChecks()if gyro~=nil then ah=gyro.getState()==1 end;if userControlScheme~="keyboard"then system.lockView(1)else system.lockView(0)end;if ad then BrakeIsOn=true end;if radar_1 then if l(radar_1.getId())=="Space Radar"then T=true else U=true end end;if door then for _,b5 in pairs(door)do b5.toggle()end end;if switch then for _,b5 in pairs(switch)do b5.toggle()end end;if forcefield then for _,b5 in pairs(forcefield)do b5.toggle()end end;if antigrav~=nil and not ExternalAGG then if antigrav.getState()==1 then antigrav.show()end end;if o()==1 and RemoteFreeze then system.freeze(1)else system.freeze(0)end;if A 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 A then GearExtended=true end else if GearExtended or not A then Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)GearExtended=true else Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end end;if ad and not dbHud_1 and(GearExtended or not A)then BrakeIsOn=true end;WasInAtmo=ad end;function ConvertResolutionX(b5)if ResolutionX==1920 then return b5 else return round(ResolutionX*b5/1920,0)end end;function ConvertResolutionY(b5)if ResolutionY==1080 then return b5 else return round(ResolutionY*b5/1080,0)end end;function RefreshLastMaxBrake(be,bf)if be==nil then be=core.g()end;be=round(be,5)local bg=j()if bf~=nil and bf or(aC==nil or aC~=be)then local velocity=core.getVelocity()local bh=vec3(velocity):len()local bi=f(unit.getData()).maxBrake;if bi~=nil and bi>0 and ad then bi=bi/utils.clamp(bh/100,0.1,1)bi=bi/bg;if bi>LastMaxBrakeInAtmo and bg>0.10 then LastMaxBrakeInAtmo=bi end end;if bi~=nil and bi>0 then LastMaxBrake=bi end;aC=be end end;function MakeButton(bj,bk,bl,bm,bn,bo,bp,bq,br)local bs={enableName=bj,disableName=bk,width=bl,height=bm,x=bn,y=bo,toggleVar=bp,toggleFunction=bq,drawCondition=br,hovered=false}table.insert(aq,bs)return bs end;function UpdateAtlasLocationsList()AtlasOrdered={}for b4,b5 in pairs(aS[0])do table.insert(AtlasOrdered,{name=b5.name,index=b4})end;local function bt(bu,bv)return bu.name-1 then aS[0][bE]=bz end;UpdateAtlasLocationsList()K=CustomTarget.name.." position updated"AutopilotTargetIndex=0;UpdateAutopilotTarget()else K="Name Not Found"end end;function ClearCurrentPosition()local bE=-1;for b4,b5 in pairs(aS[0])do if b5.name and b5.name==CustomTarget.name then bE=b4 end end;if bE>-1 then table.remove(aS[0],bE)end;bE=-1;for b4,b5 in pairs(SavedLocations)do if b5.name and b5.name==CustomTarget.name then K=b5.name.." saved location cleared"bE=b4;break end end;if bE~=-1 then table.remove(SavedLocations,bE)end;DecrementAutopilotTargetIndex()UpdateAtlasLocationsList()end;function DrawDeadZone(bG)bG[#bG+1]=e([[]],DeadZone)end;function ToggleRadarPanel()if radarPanelID~=nil and a6==0 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;if perisPanelID~=nil then system.destroyWidgetPanel(perisPanelID)perisPanelID=nil end else if a6==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;a6=0 end end;function ToggleWidgets()if ap 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;ap=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;ap=true end end;function SetupInterplanetaryPanel()panelInterplanetary=system.createWidgetPanel("Interplanetary Helper")interplanetaryHeader=system.createWidget(panelInterplanetary,"value")interplanetaryHeaderText=system.createData('{"label": "Target Planet", "value": "N/A", "unit":""}')system.addDataToWidget(interplanetaryHeaderText,interplanetaryHeader)widgetDistance=system.createWidget(panelInterplanetary,"value")widgetDistanceText=system.createData('{"label": "distance", "value": "N/A", "unit":""}')system.addDataToWidget(widgetDistanceText,widgetDistance)widgetTravelTime=system.createWidget(panelInterplanetary,"value")widgetTravelTimeText=system.createData('{"label": "Travel Time", "value": "N/A", "unit":""}')system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)widgetMaxMass=system.createWidget(panelInterplanetary,"value")widgetMaxMassText=system.createData('{"label": "Maximum Mass", "value": "N/A", "unit":""}')system.addDataToWidget(widgetMaxMassText,widgetMaxMass)widgetCurBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetCurBrakeDistanceText=system.createData('{"label": "Cur Brake distance", "value": "N/A", "unit":""}')if not ad then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;widgetCurBrakeTime=system.createWidget(panelInterplanetary,"value")widgetCurBrakeTimeText=system.createData('{"label": "Cur Brake Time", "value": "N/A", "unit":""}')if not ad then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;widgetMaxBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeDistanceText=system.createData('{"label": "Max Brake distance", "value": "N/A", "unit":""}')if not ad then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;widgetMaxBrakeTime=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeTimeText=system.createData('{"label": "Max Brake Time", "value": "N/A", "unit":""}')if not ad then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;widgetTrajectoryAltitude=system.createWidget(panelInterplanetary,"value")widgetTrajectoryAltitudeText=system.createData('{"label": "Projected Altitude", "value": "N/A", "unit":""}')if not ad then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;function Contains(bH,bI,bn,bo,bl,bm)if bH>bn and bHbo and bIw then K="WARNING: Insufficient Brakes - Attempting coast landing, beware obstacles"end;AltitudeHold=false;AutoTakeoff=false;LockPitch=nil;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=ae+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end end;function ToggleLockPitch()if LockPitch==nil then local bJ=vec3(core.getConstructWorldOrientationForward())local bK=vec3(core.getConstructWorldOrientationRight())local bL=vec3(core.getWorldVertical())local bM=getPitch(bL,bJ,bK)LockPitch=bM;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=false else LockPitch=nil end end;function ToggleAltitudeHold()AltitudeHold=not AltitudeHold;if AltitudeHold then Autopilot=false;ProgradeIsOn=false;RetrogradeIsOn=false;I=false;BrakeLanding=false;Reentry=false;b2=true;LockPitch=nil;if not GearExtended and not BrakeIsOn or not ad then AutoTakeoff=false;HoldAltitude=ae;if not a8 and Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end else AutoTakeoff=true;HoldAltitude=ae+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end;if a8 then HoldAltitude=100000 end else b2=autoRollPreference;AutoTakeoff=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;VectorToTarget=false end end;function ToggleFollowMode()if o()==1 then I=not I;if I 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;b2=autoRollPreference;GearExtended=OldGearExtended;if GearExtended then Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end end else K="Follow Mode only works with Remote controller"I=false end end;function ToggleAutopilot()if AutopilotTargetIndex>0 and not Autopilot and not VectorToTarget then if CustomTarget~=nil then LockPitch=nil;if planet.name==CustomTarget.planetname then StrongBrakes=planet.gravity*9.80665*n()w then K="Insufficient Brake Force\nCoast landing will be inaccurate"end;if j()>0 then if not AltitudeHold then if not VectorToTarget then ToggleVectorToTarget()end else if not VectorToTarget then ToggleVectorToTarget()end end else a7=true end else a8=true;RetrogradeIsOn=false;ProgradeIsOn=false;if j()~=0 then ToggleAltitudeHold()else Autopilot=true end end elseif j()==0 then Autopilot=true;RetrogradeIsOn=false;ProgradeIsOn=false;AutopilotRealigned=false;I=false;AltitudeHold=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;u=false;LockPitch=nil else a8=true;ToggleAltitudeHold()end else Autopilot=false;AutopilotRealigned=false;VectorToTarget=false;u=false;AutoTakeoff=false;AltitudeHold=false;VectorToTarget=false end end;function ProgradeToggle()ProgradeIsOn=not ProgradeIsOn;RetrogradeIsOn=false;Autopilot=false;AltitudeHold=false;I=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function RetrogradeToggle()RetrogradeIsOn=not RetrogradeIsOn;ProgradeIsOn=false;Autopilot=false;AltitudeHold=false;I=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function BrakeToggle()BrakeIsOn=not BrakeIsOn;if BrakeLanding then BrakeLanding=false;b2=autoRollPreference end;if BrakeIsOn then AltitudeHold=false;VectorToTarget=false;AutoTakeoff=false;Reentry=false;ProgradeIsOn=false;BrakeLanding=false;AutoLanding=false;AltitudeHold=false;LockPitch=nil;b2=autoRollPreference end end;function CheckDamage(bG)local bN=0;ao=""local bO=aG;local bP=0;local bQ=0;local bR=0;local bS=0;local bT=""for b4 in pairs(af)do local ba=0;local bU=0;bU=h(af[b4])ba=k(af[b4])bP=bP+ba;if ba0 and al[11]==af[b4]then for bV in pairs(al)do core.deleteSticker(al[bV])end;al={}end end;bN=d(bP/bO*100)if bN<100 then bG[#bG+1]=[[]]bS=d(bN*2.55)bT=e("rgb(%d,%d,%d)",255-bS,bS,0)if bN<100 then bG[#bG+1]=e([[Elemental Integrity: %i %%]],bT,bN)if bR>0 then bG[#bG+1]=e([[Disabled Modules: %i Damaged Modules: %i]],bT,bR,bQ)elseif bQ>0 then bG[#bG+1]=e([[Damaged Modules: %i]],bT,bQ)end end;bG[#bG+1]=[[<\g>]]end end;function DrawCursorLine(bG)local bW=d(utils.clamp(a3/(at/4)*255,0,255))bG[#bG+1]=e("",a0,a1,d(PrimaryR+0.5)+bW,d(PrimaryG+0.5)-bW,d(PrimaryB+0.5)-bW)end;function getPitch(bX,bY,bv)local bZ=bX:cross(bv):normalize_inplace()local bM=math.acos(utils.clamp(bZ:dot(-bY),-1,1))*constants.rad2deg;if bZ:cross(-bY):dot(bv)<0 then bM=-bM end;return bM end;function clearAll()if ab then ab=false;AutopilotAccelerating=false;AutopilotBraking=false;AutopilotCruising=false;Autopilot=false;AutopilotRealigned=false;AutopilotStatus="Aligning"RetrogradeIsOn=false;ProgradeIsOn=false;AltitudeHold=false;Reentry=false;BrakeLanding=false;BrakeIsOn=false;AutoTakeoff=false;I=false;u=false;a7=false;a8=false;x=false;b2=autoRollPreference;VectorToTarget=false;TurnBurn=false;ah=false;LockPitch=nil else ab=true end end;function wipeSaveVariables()if not dbHud_1 then K="No Databank Found, unable to wipe. \nYou must have a Databank attached to ship prior to running the HUD autoconfigure"a2=5 else if aA then for b4,b5 in pairs(a)do dbHud_1.setStringValue(b5,g(nil))end;for b4,b5 in pairs(b)do if b5~="SavedLocations"then dbHud_1.setStringValue(b5,g(nil))end end;K="Databank wiped. New variables will save after re-enter seat and exit"a2=5;aA=false;az=false;Y=true else K="Press ALT-7 again to confirm wipe of ALL data"aA=true end end end;function CheckButtons()for _,b5 in pairs(aq)do if b5.hovered then if not b5.drawCondition or b5.drawCondition()then b5.toggleFunction()end;b5.hovered=false end end end;function SetButtonContains()local bn=a0+at/2;local bo=a1+au/2;for _,b5 in pairs(aq)do b5.hovered=Contains(bn,bo,b5.x,b5.y,b5.width,b5.height)end end;function DrawButton(bG,b_,hover,bn,bo,c0,c1,c2,c3,c4,c5)if type(c4)=="function"then c4=c4()end;if type(c5)=="function"then c5=c5()end;bG[#bG+1]=e(""if b_ then bG[#bG+1]=e("%s",c4)else bG[#bG+1]=e("%s",c5)end end;function DrawButtons(bG)local c6="rgb(50,50,50)'"local c7="rgb(210,200,200)"local c8=DrawButton;for _,b5 in pairs(aq)do local bk=b5.disableName;local bj=b5.enableName;if type(bk)=="function"then bk=bk()end;if type(bj)=="function"then bj=bj()end;if not b5.drawCondition or b5.drawCondition()then c8(bG,b5.toggleVar(),b5.hovered,b5.x,b5.y,b5.width,b5.height,c7,c6,bk,bj)end end end;function DrawTank(bG,aP,bn,c9,ca,cb,cc,cd)local ce=1;local cf=2;local cg=3;local ch=4;local ci=5;local cj=6;local ck=""local cl=0;local cm=fuelY;local cn=fuelY+10;if o()==1 and not RemoteHud then cm=cm-50;cn=cn-50 end;bG[#bG+1]=[[]]if ca=="ATMO"then ck="atmofueltank"elseif ca=="SPACE"then ck="spacefueltank"else ck="rocketfueltank"end;cl=_G[ck.."_size"]if#cb>0 then for i=1,#cb do local bB=string.sub(cb[i][cf],1,12)local co=0;for bV=1,cl do if cb[i][cf]==f(unit[ck.."_"..bV].getData()).name then co=bV;break end end;if aP or cc[i]==nil or cd[i]==nil then local cp=0;local cq=0;local cr=0;local cs=0;local bc=system.getTime()if co~=0 then cd[i]=f(unit[ck.."_"..co].getData()).percentage;cc[i]=f(unit[ck.."_"..co].getData()).timeLeft;if cc[i]=="n/a"then cc[i]=0 end else cr=m(cb[i][ce])-cb[i][ch]cp=cb[i][cg]cd[i]=d(0.5+cr*100/cp)cq=cb[i][ci]cs=cb[i][cj]if cq<=cr then cc[i]=0 else cc[i]=d(0.5+cr/((cq-cr)/(bc-cs)))end;cb[i][ci]=cr;cb[i][cj]=bc end end;if bB==c9 then bB=e("%s %d",ca,i)end;if co==0 then bB=bB.." *"end;local ct;if cc[i]==0 then ct="n/a"else ct=FormatTimeString(cc[i])end;if cd[i]~=nil then local bS=d(cd[i]*2.55)local bT=e("rgb(%d,%d,%d)",255-bS,bS,0)local cu=""if ct~="n/a"and cc[i]<120 or cd[i]<5 then if aP then cu=[[class="red"]]end end;bG[#bG+1]=e([[ + Nav=Navigator.new(system,core,unit)script={}BrakeToggleStatus=BrakeToggleDefault;BrakeIsOn=false;RetrogradeIsOn=false;ProgradeIsOn=false;Autopilot=false;TurnBurn=false;AltitudeHold=false;BrakeLanding=false;AutoTakeoff=false;DisplayOrbit=true;Reentry=false;HoldAltitude=1000;AutopilotAccelerating=false;AutopilotRealigned=false;AutopilotBraking=false;AutopilotCruising=false;AutopilotEndSpeed=0;AutopilotStatus="Aligning"AutopilotPlanetGravity=0;PrevViewLock=1;AutopilotTargetName="None"AutopilotTargetCoords=nil;AutopilotTargetIndex=0;GearExtended=nil;TargetGroundAltitude=LandingGearGroundHeight;TotalDistanceTravelled=0.0;TotalFlightTime=0;SavedLocations={}VectorToTarget=false;LocationIndex=0;LastMaxBrake=0;LockPitch=nil;LastMaxBrakeInAtmo=0;AntigravTargetAltitude=core.getAltitude()LastStartTime=0;local a={"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","AtmoSpeedLimit","ReentryAltitude","centerX","centerY","vSpdMeterX","vSpdMeterY","altMeterX","altMeterY","fuelX","fuelY","LandingGearGroundHeight","TrajectoryAlignmentStrength","RemoteHud","StallAngle","ResolutionX","ResolutionY","UseSatNav","FuelTankOptimization","ContainerOptimization","ExtraLongitudeTags","ExtraLateralTags","ExtraVerticalTags"}local b={"BrakeToggleStatus","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","LockPitch","LastMaxBrakeInAtmo","AntigravTargetAltitude","LastStartTime"}local c=system.print;local d=math.floor;local e=string.format;local f=json.decode;local g=json.encode;local h=core.getElementMaxHitPointsById;local j=unit.getAtmosphereDensity;local k=core.getElementHitPointsById;local l=core.getElementTypeById;local m=core.getElementMassById;local n=core.getConstructMass;local o=Nav.control.isRemoteControlled;function round(p,q)local r=10^(q or 0)return d(p*r+0.5)/r end;local s=round(ResolutionX/2,0)local t=round(ResolutionY/2,0)local u=false;local v=true;local w=55;local x=false;local y=1;local z=1;local A=false;local B=0;local C=0;local D=0;local E=0;local F=0;local G=0;local H=0;local I=false;local J=false;local K="empty"local L=1;local M=5;local N=5;local O=false;local P,Q=0;local R,S=0;local T=false;local U=false;local V=nil;local W=0;local X=0;local Y=false;local Z=0;local a0=0;local a1=0;local a2=3;local a3=0;local a4=""local a5=""local a6=0;local a7=false;local a8=false;local a9=false;local aa=-1;local ab=false;local ac=""local ad=j()>0;local ae=core.getAltitude()local af=core.getElementIdList()local ag=system.getTime()local ah=nil;local ai=false;local aj=[[rgb(]]..d(PrimaryR+0.5)..","..d(PrimaryG+0.5)..","..d(PrimaryB+0.5)..[[)]]local ak=[[rgb(]]..d(PrimaryR*0.9+0.5)..","..d(PrimaryG*0.9+0.5)..","..d(PrimaryB*0.9+0.5)..[[)]]local al={}local am=0;local an=0;local ao=""local ap=true;local aq={}local ar=1;local as=0.001;local at=ResolutionX;local au=ResolutionY;local av=nil;local aw=nil;local ax=nil;local ay=nil;local az=false;local aA=false;local aB=0;local aC=nil;local aD={}local aE={}local aF={}local aG=0;local aH=false;local aI={}local aJ={}local aK=d(1/apTickRate)*2;local aL={}local aM={}local aN={}local aO={}local aP=false;local aQ=16;local aR=0;local aS=nil;local aT=""local aU=nil;local aV=nil;local aW=nil;local aX=nil;local aY=nil;local aZ=nil;local a_=nil;local b0=false;local b1=false;local b2=autoRollPreference;function LoadVariables()if dbHud_1 then local b3=dbHud_1.hasKey;if not useTheseSettings then for b4,b5 in pairs(a)do if b3(b5)then local b6=f(dbHud_1.getStringValue(b5))if b6~=nil then c(b5 .." "..dbHud_1.getStringValue(b5))_G[b5]=b6;az=true end end end end;coroutine.yield()for b4,b5 in pairs(b)do if b3(b5)then local b6=f(dbHud_1.getStringValue(b5))if b6~=nil then c(b5 .." "..dbHud_1.getStringValue(b5))_G[b5]=b6;az=true end end end;if useTheseSettings then K="Updated user preferences used. Will be saved when you exit seat.\nToggle off useTheseSettings to use saved values"a2=5 elseif az then K="Loaded Saved Variables (see Lua Chat Tab for list)"else K="No Saved Variables Found - Stand up / leave remote to save settings"end else K="No databank found, install one anywhere and rerun the autoconfigure to save variables"end;local b7=system.getTime()if LastStartTime+180b9 then b9=b8 end;if ContainerOptimization>0 then b9=b9-b9*ContainerOptimization*0.05 end;if FuelTankOptimization>0 then b9=b9-b9*FuelTankOptimization*0.05 end;return b9 end;function ProcessElements()for b4 in pairs(af)do local type=l(af[b4])if type=="landing gear"then A=true end;if type=="dynamic core"then local ba=h(af[b4])if ba>10000 then aQ=128 elseif ba>1000 then aQ=64 elseif ba>150 then aQ=32 end end;aG=aG+h(af[b4])if fuelX~=0 and fuelY~=0 then if type=="Atmospheric Fuel Tank"or type=="Space Fuel Tank"or type=="Rocket Fuel Tank"then local ba=h(af[b4])local bb=m(af[b4])local b8=0;local bc=system.getTime()if type=="Atmospheric Fuel Tank"then local b9=400;local bd=35.03;if ba>10000 then b9=51200;bd=5480 elseif ba>1300 then b9=6400;bd=988.67 elseif ba>150 then b9=1600;bd=182.67 end;b8=bb-bd;if fuelTankHandlingAtmo>0 then b9=b9+b9*fuelTankHandlingAtmo*0.2 end;b9=CalculateFuelVolume(b8,b9)aD[#aD+1]={af[b4],core.getElementNameById(af[b4]),b9,bd,b8,bc}end;if type=="Rocket Fuel Tank"then local b9=320;local bd=173.42;if ba>65000 then b9=40000;bd=25740 elseif ba>6000 then b9=5120;bd=4720 elseif ba>700 then b9=640;bd=886.72 end;b8=bb-bd;if fuelTankHandlingRocket>0 then b9=b9+b9*fuelTankHandlingRocket*0.2 end;b9=CalculateFuelVolume(b8,b9)aF[#aF+1]={af[b4],core.getElementNameById(af[b4]),b9,bd,b8,bc}end;if type=="Space Fuel Tank"then local b9=2400;local bd=182.67;if ba>10000 then b9=76800;bd=5480 elseif ba>1300 then b9=9600;bd=988.67 end;b8=bb-bd;if fuelTankHandlingSpace>0 then b9=b9+b9*fuelTankHandlingSpace*0.2 end;b9=CalculateFuelVolume(b8,b9)aE[#aE+1]={af[b4],core.getElementNameById(af[b4]),b9,bd,b8,bc}end end end end end;function SetupChecks()if gyro~=nil then ah=gyro.getState()==1 end;if userControlScheme~="keyboard"then system.lockView(1)else system.lockView(0)end;if ad then BrakeIsOn=true end;if radar_1 then if l(radar_1.getId())=="Space Radar"then T=true else U=true end end;if door then for _,b5 in pairs(door)do b5.toggle()end end;if switch then for _,b5 in pairs(switch)do b5.toggle()end end;if forcefield then for _,b5 in pairs(forcefield)do b5.toggle()end end;if antigrav~=nil and not ExternalAGG then if antigrav.getState()==1 then antigrav.show()end end;if o()==1 and RemoteFreeze then system.freeze(1)else system.freeze(0)end;if A 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 A then GearExtended=true end else if GearExtended or not A then Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)GearExtended=true else Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end end;if ad and not dbHud_1 and(GearExtended or not A)then BrakeIsOn=true end;WasInAtmo=ad end;function ConvertResolutionX(b5)if ResolutionX==1920 then return b5 else return round(ResolutionX*b5/1920,0)end end;function ConvertResolutionY(b5)if ResolutionY==1080 then return b5 else return round(ResolutionY*b5/1080,0)end end;function RefreshLastMaxBrake(be,bf)if be==nil then be=core.g()end;be=round(be,5)local bg=j()if bf~=nil and bf or(aC==nil or aC~=be)then local velocity=core.getVelocity()local bh=vec3(velocity):len()local bi=f(unit.getData()).maxBrake;if bi~=nil and bi>0 and ad then bi=bi/utils.clamp(bh/100,0.1,1)bi=bi/bg;if bi>LastMaxBrakeInAtmo and bg>0.10 then LastMaxBrakeInAtmo=bi end end;if bi~=nil and bi>0 then LastMaxBrake=bi end;aC=be end end;function MakeButton(bj,bk,bl,bm,bn,bo,bp,bq,br)local bs={enableName=bj,disableName=bk,width=bl,height=bm,x=bn,y=bo,toggleVar=bp,toggleFunction=bq,drawCondition=br,hovered=false}table.insert(aq,bs)return bs end;function UpdateAtlasLocationsList()AtlasOrdered={}for b4,b5 in pairs(aS[0])do table.insert(AtlasOrdered,{name=b5.name,index=b4})end;local function bt(bu,bv)return bu.name-1 then aS[0][bM]=bH end;UpdateAtlasLocationsList()K=CustomTarget.name.." position updated"AutopilotTargetIndex=0;UpdateAutopilotTarget()else K="Name Not Found"end end;function ClearCurrentPosition()local bM=-1;for b4,b5 in pairs(aS[0])do if b5.name and b5.name==CustomTarget.name then bM=b4 end end;if bM>-1 then table.remove(aS[0],bM)end;bM=-1;for b4,b5 in pairs(SavedLocations)do if b5.name and b5.name==CustomTarget.name then K=b5.name.." saved location cleared"bM=b4;break end end;if bM~=-1 then table.remove(SavedLocations,bM)end;DecrementAutopilotTargetIndex()UpdateAtlasLocationsList()end;function DrawDeadZone(bO)bO[#bO+1]=e([[]],DeadZone)end;function ToggleRadarPanel()if radarPanelID~=nil and a6==0 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;if perisPanelID~=nil then system.destroyWidgetPanel(perisPanelID)perisPanelID=nil end else if a6==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;a6=0 end end;function ToggleWidgets()if ap 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;ap=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;ap=true end end;function SetupInterplanetaryPanel()panelInterplanetary=system.createWidgetPanel("Interplanetary Helper")interplanetaryHeader=system.createWidget(panelInterplanetary,"value")interplanetaryHeaderText=system.createData('{"label": "Target Planet", "value": "N/A", "unit":""}')system.addDataToWidget(interplanetaryHeaderText,interplanetaryHeader)widgetDistance=system.createWidget(panelInterplanetary,"value")widgetDistanceText=system.createData('{"label": "distance", "value": "N/A", "unit":""}')system.addDataToWidget(widgetDistanceText,widgetDistance)widgetTravelTime=system.createWidget(panelInterplanetary,"value")widgetTravelTimeText=system.createData('{"label": "Travel Time", "value": "N/A", "unit":""}')system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)widgetMaxMass=system.createWidget(panelInterplanetary,"value")widgetMaxMassText=system.createData('{"label": "Maximum Mass", "value": "N/A", "unit":""}')system.addDataToWidget(widgetMaxMassText,widgetMaxMass)widgetCurBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetCurBrakeDistanceText=system.createData('{"label": "Cur Brake distance", "value": "N/A", "unit":""}')if not ad then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;widgetCurBrakeTime=system.createWidget(panelInterplanetary,"value")widgetCurBrakeTimeText=system.createData('{"label": "Cur Brake Time", "value": "N/A", "unit":""}')if not ad then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;widgetMaxBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeDistanceText=system.createData('{"label": "Max Brake distance", "value": "N/A", "unit":""}')if not ad then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;widgetMaxBrakeTime=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeTimeText=system.createData('{"label": "Max Brake Time", "value": "N/A", "unit":""}')if not ad then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;widgetTrajectoryAltitude=system.createWidget(panelInterplanetary,"value")widgetTrajectoryAltitudeText=system.createData('{"label": "Projected Altitude", "value": "N/A", "unit":""}')if not ad then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;function Contains(bP,bQ,bn,bo,bl,bm)if bP>bn and bPbo and bQw then K="WARNING: Insufficient Brakes - Attempting coast landing, beware obstacles"end;AltitudeHold=false;AutoTakeoff=false;LockPitch=nil;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=ae+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end end;function ToggleLockPitch()if LockPitch==nil then local bR=vec3(core.getConstructWorldOrientationForward())local bS=vec3(core.getConstructWorldOrientationRight())local bT=vec3(core.getWorldVertical())local bU=getPitch(bT,bR,bS)LockPitch=bU;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=false else LockPitch=nil end end;function ToggleAltitudeHold()AltitudeHold=not AltitudeHold;if AltitudeHold then Autopilot=false;ProgradeIsOn=false;RetrogradeIsOn=false;I=false;BrakeLanding=false;Reentry=false;b2=true;LockPitch=nil;if not GearExtended and not BrakeIsOn or not ad then AutoTakeoff=false;HoldAltitude=ae;if not a8 and Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end else AutoTakeoff=true;HoldAltitude=ae+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end;if a8 then HoldAltitude=100000 end else b2=autoRollPreference;AutoTakeoff=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;VectorToTarget=false end end;function ToggleFollowMode()if o()==1 then I=not I;if I 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;b2=autoRollPreference;GearExtended=OldGearExtended;if GearExtended then Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end end else K="Follow Mode only works with Remote controller"I=false end end;function ToggleAutopilot()if AutopilotTargetIndex>0 and not Autopilot and not VectorToTarget then if CustomTarget~=nil then LockPitch=nil;if planet.name==CustomTarget.planetname then StrongBrakes=planet.gravity*9.80665*n()w then K="Insufficient Brake Force\nCoast landing will be inaccurate"end;if j()>0 then if not AltitudeHold then if not VectorToTarget then ToggleVectorToTarget()end else if not VectorToTarget then ToggleVectorToTarget()end end else a7=true end else a8=true;RetrogradeIsOn=false;ProgradeIsOn=false;if j()~=0 then ToggleAltitudeHold()else Autopilot=true end end elseif j()==0 then Autopilot=true;RetrogradeIsOn=false;ProgradeIsOn=false;AutopilotRealigned=false;I=false;AltitudeHold=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;u=false;LockPitch=nil else a8=true;ToggleAltitudeHold()end else Autopilot=false;AutopilotRealigned=false;VectorToTarget=false;u=false;AutoTakeoff=false;AltitudeHold=false;VectorToTarget=false end end;function ProgradeToggle()ProgradeIsOn=not ProgradeIsOn;RetrogradeIsOn=false;Autopilot=false;AltitudeHold=false;I=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function RetrogradeToggle()RetrogradeIsOn=not RetrogradeIsOn;ProgradeIsOn=false;Autopilot=false;AltitudeHold=false;I=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function BrakeToggle()BrakeIsOn=not BrakeIsOn;if BrakeLanding then BrakeLanding=false;b2=autoRollPreference end;if BrakeIsOn then AltitudeHold=false;VectorToTarget=false;AutoTakeoff=false;Reentry=false;ProgradeIsOn=false;BrakeLanding=false;AutoLanding=false;AltitudeHold=false;LockPitch=nil;b2=autoRollPreference end end;function CheckDamage(bO)local bV=0;ao=""local bW=aG;local bX=0;local bY=0;local bZ=0;local b_=0;local c0=""for b4 in pairs(af)do local ba=0;local c1=0;c1=h(af[b4])ba=k(af[b4])bX=bX+ba;if ba0 and al[11]==af[b4]then for c3 in pairs(al)do core.deleteSticker(al[c3])end;al={}end end;bV=d(bX/bW*100)if bV<100 then bO[#bO+1]=[[]]b_=d(bV*2.55)c0=e("rgb(%d,%d,%d)",255-b_,b_,0)if bV<100 then bO[#bO+1]=e([[Elemental Integrity: %i %%]],c0,bV)if bZ>0 then bO[#bO+1]=e([[Disabled Modules: %i Damaged Modules: %i]],c0,bZ,bY)elseif bY>0 then bO[#bO+1]=e([[Damaged Modules: %i]],c0,bY)end end;bO[#bO+1]=[[<\g>]]end end;function DrawCursorLine(bO)local c4=d(utils.clamp(a3/(at/4)*255,0,255))bO[#bO+1]=e("",a0,a1,d(PrimaryR+0.5)+c4,d(PrimaryG+0.5)-c4,d(PrimaryB+0.5)-c4)end;function getPitch(c5,c6,bv)local c7=c5:cross(bv):normalize_inplace()local bU=math.acos(utils.clamp(c7:dot(-c6),-1,1))*constants.rad2deg;if c7:cross(-c6):dot(bv)<0 then bU=-bU end;return bU end;function clearAll()if ab then ab=false;AutopilotAccelerating=false;AutopilotBraking=false;AutopilotCruising=false;Autopilot=false;AutopilotRealigned=false;AutopilotStatus="Aligning"RetrogradeIsOn=false;ProgradeIsOn=false;AltitudeHold=false;Reentry=false;BrakeLanding=false;BrakeIsOn=false;AutoTakeoff=false;I=false;u=false;a7=false;a8=false;x=false;b2=autoRollPreference;VectorToTarget=false;TurnBurn=false;ah=false;LockPitch=nil else ab=true end end;function wipeSaveVariables()if not dbHud_1 then K="No Databank Found, unable to wipe. \nYou must have a Databank attached to ship prior to running the HUD autoconfigure"a2=5 else if aA then for b4,b5 in pairs(a)do dbHud_1.setStringValue(b5,g(nil))end;for b4,b5 in pairs(b)do if b5~="SavedLocations"then dbHud_1.setStringValue(b5,g(nil))end end;K="Databank wiped. New variables will save after re-enter seat and exit"a2=5;aA=false;az=false;Y=true else K="Press ALT-7 again to confirm wipe of ALL data"aA=true end end end;function CheckButtons()for _,b5 in pairs(aq)do if b5.hovered then if not b5.drawCondition or b5.drawCondition()then b5.toggleFunction()end;b5.hovered=false end end end;function SetButtonContains()local bn=a0+at/2;local bo=a1+au/2;for _,b5 in pairs(aq)do b5.hovered=Contains(bn,bo,b5.x,b5.y,b5.width,b5.height)end end;function DrawButton(bO,c8,hover,bn,bo,c9,ca,cb,cc,cd,ce)if type(cd)=="function"then cd=cd()end;if type(ce)=="function"then ce=ce()end;bO[#bO+1]=e(""if c8 then bO[#bO+1]=e("%s",cd)else bO[#bO+1]=e("%s",ce)end end;function DrawButtons(bO)local cf="rgb(50,50,50)'"local cg="rgb(210,200,200)"local ch=DrawButton;for _,b5 in pairs(aq)do local bk=b5.disableName;local bj=b5.enableName;if type(bk)=="function"then bk=bk()end;if type(bj)=="function"then bj=bj()end;if not b5.drawCondition or b5.drawCondition()then ch(bO,b5.toggleVar(),b5.hovered,b5.x,b5.y,b5.width,b5.height,cg,cf,bk,bj)end end end;function DrawTank(bO,aP,bn,ci,cj,ck,cl,cm)local cn=1;local co=2;local cp=3;local cq=4;local cr=5;local cs=6;local ct=""local cu=0;local cv=fuelY;local cw=fuelY+10;if o()==1 and not RemoteHud then cv=cv-50;cw=cw-50 end;bO[#bO+1]=[[]]if cj=="ATMO"then ct="atmofueltank"elseif cj=="SPACE"then ct="spacefueltank"else ct="rocketfueltank"end;cu=_G[ct.."_size"]if#ck>0 then for i=1,#ck do local bJ=string.sub(ck[i][co],1,12)local cx=0;for c3=1,cu do if ck[i][co]==f(unit[ct.."_"..c3].getData()).name then cx=c3;break end end;if aP or cl[i]==nil or cm[i]==nil then local cy=0;local cz=0;local cA=0;local cB=0;local bc=system.getTime()if cx~=0 then cm[i]=f(unit[ct.."_"..cx].getData()).percentage;cl[i]=f(unit[ct.."_"..cx].getData()).timeLeft;if cl[i]=="n/a"then cl[i]=0 end else cA=m(ck[i][cn])-ck[i][cq]cy=ck[i][cp]cm[i]=d(0.5+cA*100/cy)cz=ck[i][cr]cB=ck[i][cs]if cz<=cA then cl[i]=0 else cl[i]=d(0.5+cA/((cz-cA)/(bc-cB)))end;ck[i][cr]=cA;ck[i][cs]=bc end end;if bJ==ci then bJ=e("%s %d",cj,i)end;if cx==0 then bJ=bJ.." *"end;local cC;if cl[i]==0 then cC="n/a"else cC=FormatTimeString(cl[i])end;if cm[i]~=nil then local b_=d(cm[i]*2.55)local c0=e("rgb(%d,%d,%d)",255-b_,b_,0)local cD=""if cC~="n/a"and cl[i]<120 or cm[i]<5 then if aP then cD=[[class="red"]]end end;bO[#bO+1]=e([[ %s %d%% %s - ]],bn,cm,cu,bB,bn,cn,bT,cd[i],ct)cm=cm+30;cn=cn+30 end end end;bG[#bG+1]=""end;function HideInterplanetaryPanel()system.destroyWidgetPanel(panelInterplanetary)panelInterplanetary=nil end;function getRelativePitch(velocity)velocity=vec3(velocity)local bM=-math.deg(math.atan(velocity.y,velocity.z))+180;bM=bM-90;if bM<0 then bM=360+bM end;if bM>180 then bM=-180+bM-180 end;return-bM end;function getRelativeYaw(velocity)velocity=vec3(velocity)local cv=math.deg(math.atan(velocity.y,velocity.x))-90;if cv<-180 then cv=360+cv end;return cv end;function AlignToWorldVector(cw,cx)if not ad or RateOfChange>MinimumRateOfChange+0.08 or aa~=-1 then if cx==nil then cx=as end;cw=vec3(cw):normalize()local cy=vec3(core.getConstructWorldOrientationForward())-cw;local cz=-getMagnitudeInDirection(cy,core.getConstructWorldOrientationRight())*ar;local cA=-getMagnitudeInDirection(cy,core.getConstructWorldOrientationUp())*ar;if am==0 then am=cz/2 end;if an==0 then an=cA/2 end;D=D-(cz+(cz-am)*DampingMultiplier)C=C+cA+(cA-an)*DampingMultiplier;am=cz;an=cA;if math.abs(cz)0 and CustomTarget~=nil end)MakeButton("Clear Position","Clear Position",200,cE.height,cE.x-200-30,cE.y,function()return true end,ClearCurrentPosition,function()return AutopilotTargetIndex>0 and CustomTarget~=nil end)cB=60;cC=300;local bn=10;local bo=au/2-300;MakeButton("Enable Turn and Burn","Disable Turn and Burn",cC,cB,bn,bo,function()return TurnBurn end,ToggleTurnBurn)MakeButton("Engage Altitude Hold","Disable Altitude Hold",cC,cB,bn+cC+20,bo,function()return AltitudeHold end,ToggleAltitudeHold)bo=bo+cB+20;MakeButton("Engage Autoland","Disable Autoland",cC,cB,bn,bo,function()return AutoLanding end,ToggleAutoLanding)MakeButton("Engage Auto Takeoff","Disable Auto Takeoff",cC,cB,bn+cC+20,bo,function()return AutoTakeoff end,ToggleAutoTakeoff)bo=bo+cB+20;MakeButton("Show Orbit Display","Hide Orbit Display",cC,cB,bn,bo,function()return DisplayOrbit end,function()DisplayOrbit=not DisplayOrbit;if DisplayOrbit then K="Orbit Display Enabled"else K="Orbit Display Disabled"end end)bo=bo+cB+20;MakeButton("Glide Re-Entry","Cancel Glide Re-Entry",cC,cB,bn,bo,function()return Reentry end,function()x=true;BeginReentry()end,function()return ae>ReentryAltitude end)MakeButton("Parachute Re-Entry","Cancel Parachute Re-Entry",cC,cB,bn+cC+20,bo,function()return Reentry end,BeginReentry,function()return ae>ReentryAltitude end)bo=bo+cB+20;MakeButton("Engage Follow Mode","Disable Follow Mode",cC,cB,bn,bo,function()return I end,ToggleFollowMode,function()return o()==1 end)MakeButton("Enable Repair Arrows","Disable Repair Arrows",cC,cB,bn+cC+20,bo,function()return aH end,function()aH=not aH;if aH then K="Repair Arrows Enabled"else K="Repair Arrows Diabled"end end,function()return o()==1 end)bo=bo+cB+20;if not ExternalAGG then MakeButton("Enable AGG","Disable AGG",cC,cB,bn,bo,function()return antigrav.getState()==1 end,ToggleAntigrav,function()return antigrav~=nil end)end;bo=bo+cB+20;MakeButton(function()return e("Toggle Control Scheme - Current: %s",userControlScheme)end,function()return e("Control Scheme: %s",userControlScheme)end,cC*2,cB,bn,bo,function()return false end,function()if userControlScheme=="keyboard"then userControlScheme="mouse"elseif userControlScheme=="mouse"then userControlScheme="virtual joystick"else userControlScheme="keyboard"end end)end;function GetFlightStyle()local cF=Nav.axisCommandManager:getAxisCommandType(0)local cG="TRAVEL"if cF==1 then cG="CRUISE"end;if Autopilot then cG="AUTOPILOT"end;return cG end;function updateHud(bG)local cH=ae;local velocity=core.getVelocity()local bh=vec3(velocity):len()local bL=vec3(core.getWorldVertical())local bJ=vec3(core.getConstructWorldOrientationForward())local bK=vec3(core.getConstructWorldOrientationRight())local cI=vec3(core.getConstructWorldOrientationUp())local cJ=getRoll(bL,bJ,bK)local cK=cJ/180*math.pi;local cL=math.cos(cK)local cM=math.sin(cK)local bM=getPitch(bL,bJ,bK*cL+cI*cM)local cN=cJ;local cO=bM;local cP=j()local cQ=d(unit.getThrottle())local cR=bh*3.6;local cS=unit.getAxisCommandValue(0)local cG=GetFlightStyle()local cT="ROLL"local cU=unit.getClosestPlanetInfluence()>0;if cQ==nil then cQ=0 end;if not cU then if bh>5 then bM=getRelativePitch(velocity)cJ=getRelativeYaw(velocity)else bM=0;cJ=0 end;cT="YAW"end;bG[#bG+1]=a5;bG[#bG+1]=ao;bG[#bG+1]=a4;if aR%aK==0 then aP=true end;if fuelX~=0 and fuelY~=0 then DrawTank(bG,aP,fuelX,"Atmospheric ","ATMO",aD,aN,aO)DrawTank(bG,aP,fuelX+100,"Space fuel t","SPACE",aE,aL,aM)DrawTank(bG,aP,fuelX+200,"Rocket fuel ","ROCKET",aF,aI,aJ)end;if aP then aP=false;aR=0 end;aR=aR+1;DrawVerticalSpeed(bG,cH)if o()==0 or RemoteHud then if not IsInFreeLook()or brightHud then if cU then DrawRollLines(bG,centerX,centerY,cN,cT,cU)DrawArtificialHorizon(bG,cO,cN,centerX,centerY,cU,d(getRelativeYaw(velocity)),bh)else DrawRollLines(bG,centerX,centerY,cJ,cT,cU)DrawArtificialHorizon(bG,bM,cJ,centerX,centerY,cU,d(cJ),bh)end;DrawAltitudeDisplay(bG,cH,cU)DrawPrograde(bG,velocity,bh,centerX,centerY)end end;DrawThrottle(bG,cG,cQ,cS)DrawSpeed(bG,cR)DrawWarnings(bG)DisplayOrbitScreen(bG)if screen_2 then local cV=vec3(core.getConstructWorldPos())local bn=960+cV.x/aU;local bo=450+cV.y/aV;screen_2.moveContent(aW,(bn-80)/19.2,(bo-80)/10.8)end end;function IsInFreeLook()return system.isViewLocked()==0 and userControlScheme~="keyboard"and o()==0 end;function HUDPrologue(bG)local cW=aj;local cX=ak;local cY=aj;local cZ=ak;if IsInFreeLook()and not brightHud then cW=[[rgb(]]..d(PrimaryR*0.4+0.5)..","..d(PrimaryG*0.4+0.5)..","..d(PrimaryB*0.3+0.5)..[[)]]cX=[[rgb(]]..d(PrimaryR*0.3+0.5)..","..d(PrimaryG*0.3+0.5)..","..d(PrimaryB*0.2+0.5)..[[)]]end;bG[#bG+1]=e([[ + ]],bn,cv,cD,bJ,bn,cw,c0,cm[i],cC)cv=cv+30;cw=cw+30 end end end;bO[#bO+1]=""end;function HideInterplanetaryPanel()system.destroyWidgetPanel(panelInterplanetary)panelInterplanetary=nil end;function getRelativePitch(velocity)velocity=vec3(velocity)local bU=-math.deg(math.atan(velocity.y,velocity.z))+180;bU=bU-90;if bU<0 then bU=360+bU end;if bU>180 then bU=-180+bU-180 end;return-bU end;function getRelativeYaw(velocity)velocity=vec3(velocity)local cE=math.deg(math.atan(velocity.y,velocity.x))-90;if cE<-180 then cE=360+cE end;return cE end;function AlignToWorldVector(cF,cG)if not ad or RateOfChange>MinimumRateOfChange+0.08 or aa~=-1 then if cG==nil then cG=as end;cF=vec3(cF):normalize()local cH=vec3(core.getConstructWorldOrientationForward())-cF;local cI=-getMagnitudeInDirection(cH,core.getConstructWorldOrientationRight())*ar;local cJ=-getMagnitudeInDirection(cH,core.getConstructWorldOrientationUp())*ar;if am==0 then am=cI/2 end;if an==0 then an=cJ/2 end;D=D-(cI+(cI-am)*DampingMultiplier)C=C+cJ+(cJ-an)*DampingMultiplier;am=cI;an=cJ;if math.abs(cI)0 and CustomTarget~=nil end)MakeButton("Clear Position","Clear Position",200,cN.height,cN.x-200-30,cN.y,function()return true end,ClearCurrentPosition,function()return AutopilotTargetIndex>0 and CustomTarget~=nil end)cK=60;cL=300;local bn=10;local bo=au/2-300;MakeButton("Enable Turn and Burn","Disable Turn and Burn",cL,cK,bn,bo,function()return TurnBurn end,ToggleTurnBurn)MakeButton("Engage Altitude Hold","Disable Altitude Hold",cL,cK,bn+cL+20,bo,function()return AltitudeHold end,ToggleAltitudeHold)bo=bo+cK+20;MakeButton("Engage Autoland","Disable Autoland",cL,cK,bn,bo,function()return AutoLanding end,ToggleAutoLanding)MakeButton("Engage Auto Takeoff","Disable Auto Takeoff",cL,cK,bn+cL+20,bo,function()return AutoTakeoff end,ToggleAutoTakeoff)bo=bo+cK+20;MakeButton("Show Orbit Display","Hide Orbit Display",cL,cK,bn,bo,function()return DisplayOrbit end,function()DisplayOrbit=not DisplayOrbit;if DisplayOrbit then K="Orbit Display Enabled"else K="Orbit Display Disabled"end end)bo=bo+cK+20;MakeButton("Glide Re-Entry","Cancel Glide Re-Entry",cL,cK,bn,bo,function()return Reentry end,function()x=true;BeginReentry()end,function()return ae>ReentryAltitude end)MakeButton("Parachute Re-Entry","Cancel Parachute Re-Entry",cL,cK,bn+cL+20,bo,function()return Reentry end,BeginReentry,function()return ae>ReentryAltitude end)bo=bo+cK+20;MakeButton("Engage Follow Mode","Disable Follow Mode",cL,cK,bn,bo,function()return I end,ToggleFollowMode,function()return o()==1 end)MakeButton("Enable Repair Arrows","Disable Repair Arrows",cL,cK,bn+cL+20,bo,function()return aH end,function()aH=not aH;if aH then K="Repair Arrows Enabled"else K="Repair Arrows Diabled"end end,function()return o()==1 end)bo=bo+cK+20;if not ExternalAGG then MakeButton("Enable AGG","Disable AGG",cL,cK,bn,bo,function()return antigrav.getState()==1 end,ToggleAntigrav,function()return antigrav~=nil end)end;bo=bo+cK+20;MakeButton(function()return e("Toggle Control Scheme - Current: %s",userControlScheme)end,function()return e("Control Scheme: %s",userControlScheme)end,cL*2,cK,bn,bo,function()return false end,function()if userControlScheme=="keyboard"then userControlScheme="mouse"elseif userControlScheme=="mouse"then userControlScheme="virtual joystick"else userControlScheme="keyboard"end end)end;function GetFlightStyle()local cO=Nav.axisCommandManager:getAxisCommandType(0)local cP="TRAVEL"if cO==1 then cP="CRUISE"end;if Autopilot then cP="AUTOPILOT"end;return cP end;function updateHud(bO)local bC=ae;local velocity=core.getVelocity()local bh=vec3(velocity):len()local bT=vec3(core.getWorldVertical())local bR=vec3(core.getConstructWorldOrientationForward())local bS=vec3(core.getConstructWorldOrientationRight())local cQ=vec3(core.getConstructWorldOrientationUp())local cR=getRoll(bT,bR,bS)local cS=cR/180*math.pi;local cT=math.cos(cS)local cU=math.sin(cS)local bU=getPitch(bT,bR,bS*cT+cQ*cU)local cV=cR;local cW=bU;local cX=j()local cY=d(unit.getThrottle())local cZ=bh*3.6;local c_=unit.getAxisCommandValue(0)local cP=GetFlightStyle()local d0="ROLL"local d1=unit.getClosestPlanetInfluence()>0;if cY==nil then cY=0 end;if not d1 then if bh>5 then bU=getRelativePitch(velocity)cR=getRelativeYaw(velocity)else bU=0;cR=0 end;d0="YAW"end;bO[#bO+1]=a5;bO[#bO+1]=ao;bO[#bO+1]=a4;if aR%aK==0 then aP=true end;if fuelX~=0 and fuelY~=0 then DrawTank(bO,aP,fuelX,"Atmospheric ","ATMO",aD,aN,aO)DrawTank(bO,aP,fuelX+100,"Space fuel t","SPACE",aE,aL,aM)DrawTank(bO,aP,fuelX+200,"Rocket fuel ","ROCKET",aF,aI,aJ)end;if aP then aP=false;aR=0 end;aR=aR+1;DrawVerticalSpeed(bO,bC)if o()==0 or RemoteHud then if not IsInFreeLook()or brightHud then if d1 then DrawRollLines(bO,centerX,centerY,cV,d0,d1)DrawArtificialHorizon(bO,cW,cV,centerX,centerY,d1,d(getRelativeYaw(velocity)),bh)else DrawRollLines(bO,centerX,centerY,cR,d0,d1)DrawArtificialHorizon(bO,bU,cR,centerX,centerY,d1,d(cR),bh)end;DrawAltitudeDisplay(bO,bC,d1)DrawPrograde(bO,velocity,bh,centerX,centerY)end end;DrawThrottle(bO,cP,cY,c_)DrawSpeed(bO,cZ)DrawWarnings(bO)DisplayOrbitScreen(bO)if screen_2 then local bw=vec3(core.getConstructWorldPos())local bn=960+bw.x/aU;local bo=450+bw.y/aV;screen_2.moveContent(aW,(bn-80)/19.2,(bo-80)/10.8)end end;function IsInFreeLook()return system.isViewLocked()==0 and userControlScheme~="keyboard"and o()==0 end;function HUDPrologue(bO)local d2=aj;local d3=ak;local d4=aj;local d5=ak;if IsInFreeLook()and not brightHud then d2=[[rgb(]]..d(PrimaryR*0.4+0.5)..","..d(PrimaryG*0.4+0.5)..","..d(PrimaryB*0.3+0.5)..[[)]]d3=[[rgb(]]..d(PrimaryR*0.3+0.5)..","..d(PrimaryG*0.3+0.5)..","..d(PrimaryB*0.2+0.5)..[[)]]end;bO[#bO+1]=e([[ ",ResolutionX,ResolutionY)bG[#bG+1]=aT;bG[#bG+1]=hf;bG[#bG+1]=""b0=true;bG[#bG+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(bG,"")system.setScreen(content)elseif b1 then local hf=table.concat(bG,"")bG={}bG[#bG+1]=e("",ResolutionX,ResolutionY)bG[#bG+1]=aT;bG[#bG+1]=hf;bG[#bG+1]=""end;if not b0 then bG[#bG+1]=e([[]],s,t,a0,a1)end else CheckButtons()a0=0;a1=0 end else a0=a0+hc;a1=a1+hd;a3=math.sqrt(a0*a0+a1*a1)if not J and o()==0 then if userControlScheme=="virtual joystick"then if a0>0 and a0>DeadZone then D=D-(a0-DeadZone)*MouseXSensitivity elseif a0<0 and a00 and a1>DeadZone then C=C-(a1-DeadZone)*MouseYSensitivity elseif a1<0 and a1DeadZone then DrawCursorLine(bG)end else SetButtonContains()DrawButtons(bG)end;bG[#bG+1]=e([[]],s,t,a0,a1)end;bG[#bG+1]=[[]]content=table.concat(bG,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end;if ProgradeIsOn then if velMag>w then local hg=AlignToWorldVector(vec3(velocity),0.01)if a7 then b2=true;if hg then ProgradeIsOn=false;x=true;BeginReentry()a7=false;a9=true;b2=autoRollPreference end end end end;if RetrogradeIsOn then if ad then RetrogradeIsOn=false elseif velMag>w then AlignToWorldVector(-vec3(velocity))end end;if not ProgradeIsOn and a7 then if j()==0 then x=true;BeginReentry()a7=false;a9=true else a7=false;ToggleAutopilot()end end;if a9 and aeReentrySpeed-100 then ToggleAutopilot()a9=false end;if Autopilot and j()==0 then local P,Q;if not TurnBurn then P,Q=GetAutopilotBrakeDistanceAndTime(velMag)else P,Q=GetAutopilotTBBrakeDistanceAndTime(velMag)end;P=P;Q=Q;local hh=AutopilotTargetCoords;if orbit.apoapsis==nil and velMag>300 and AutopilotAccelerating then local hi=(vec3(AutopilotTargetCoords)-vec3(core.getConstructWorldPos())):normalize()-vec3(velocity):normalize()local hj=getMagnitudeInDirection(hi,AutopilotShipUp)local hk=getMagnitudeInDirection(hi,AutopilotShipRight)local hl=-hk*AutopilotDistance*velMag*TrajectoryAlignmentStrength;local hm=-hj*AutopilotDistance*velMag*TrajectoryAlignmentStrength;hh=AutopilotTargetCoords+-hl*vec3(AutopilotShipRight)+-hm*vec3(AutopilotShipUp)end;AutopilotDistance=(vec3(hh)-vec3(core.getConstructWorldPos())):len()local hn=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()system.updateData(widgetDistanceText,'{"label": "distance", "value": "'..getDistanceDisplayString(hn)..'", "unit":""}')local ho=true;local hp=(V.center-(vec3(core.getConstructWorldPos())+vec3(velocity):normalize()*AutopilotDistance)):len()-V.radius;system.updateData(widgetTrajectoryAltitudeText,'{"label": "Projected Altitude", "value": "'..getDistanceDisplayString(hp)..'", "unit":""}')if not AutopilotCruising and not AutopilotBraking then ho=AlignToWorldVector((hh-vec3(core.getConstructWorldPos())):normalize())elseif TurnBurn then ho=AlignToWorldVector(-vec3(velocity):normalize())end;if AutopilotAccelerating then if not ho 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)u=false elseif not u then BrakeIsOn=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)u=true end;if vec3(core.getVelocity()):len()>=MaxGameVelocity and math.abs(hp-AutopilotTargetOrbit)<1000 or unit.getThrottle()==0 and u then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)u=false end;if AutopilotDistance<=P then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)u=false end elseif AutopilotBraking then BrakeIsOn=true;G=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>L or orbit.apoapsis.altitude0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if ho then if not AutopilotRealigned then AutopilotTargetCoords=vec3(V.center)+(AutopilotTargetOrbit+V.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotRealigned=true;AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()elseif ho then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not u then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)u=true;BrakeIsOn=false end end end end end;if I then b2=true;local hq=0;local cV=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local hr=cV-vec3(core.getConstructWorldPos())local hs=vec3(hr):project_on(vec3(core.getConstructWorldOrientationForward())):len()local ht=vec3(hr):project_on(vec3(core.getConstructWorldOrientationRight())):len()local a3=math.sqrt(hs*hs+ht*ht)AlignToWorldVector(hr:normalize())local hu=40;local hv=a3hy then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(hq-bM)local hz=pitchPID:get()C=hz end end;local de=vec3(core.getWorldVertical())*-1;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget or LockPitch~=nil then local cU=unit.getClosestPlanetInfluence()>0;local cH=ae;local hA=HoldAltitude-cH;local hB=500+velMag;local hq=(utils.smoothstep(hA,-hB,hB)-0.5)*2*MaxPitch;if not AltitudeHold then hq=0 end;if LockPitch~=nil then if cU then hq=LockPitch else LockPitch=nil end end;b2=true;if Reentry then local hC=ReentrySpeed;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=hC then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,hC)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if not x then hq=-80;if j()>0.02 then K="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;hq=0;b2=autoRollPreference end elseif Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==ReentrySpeed then x=false;Reentry=false;b2=autoRollPreference end end;local hD=C;if velMag>w then AlignToWorldVector(vec3(velocity))end;if VectorToTarget and CustomTarget~=nil and AutopilotTargetIndex>0 then local cy=CustomTarget.position-vec3(core.getConstructWorldPos())AlignToWorldVector(cy)local hE=cy:len()-cy:project_on(de):len()local bi=LastMaxBrakeInAtmo;local dc=velocity.x*de.x+velocity.y*de.y+velocity.z*de.z;local hF=velocity:len()-math.abs(dc)local hG=vec3(core.getWorldAirFrictionAcceleration())if bi~=nil then P,Q=aZ.computeDistanceAndTime(hF,0,n(),0,0,bi+(hG:len()-hG:project_on(de):len())*n())else P,Q=aZ.computeDistanceAndTime(hF,0,n(),0,0,LastMaxBrake+vec3(core.getWorldAirFrictionAcceleration()):len()*n())end;StrongBrakes=planet.gravity*9.80665*n()LastTargetDistance and not AltitudeHold and not AutoTakeoff then BrakeLanding=true;VectorToTarget=false end;LastTargetDistance=hE end;C=hD;local bJ=vec3(core.getConstructWorldOrientationForward())local bK=vec3(core.getConstructWorldOrientationRight())local bL=vec3(core.getWorldVertical())local eB=-1;local bM=getPitch(bL,bJ,bK)local hy=0.1;if BrakeLanding then hq=0;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)local dc=velocity.x*de.x+velocity.y*de.y+velocity.z*de.z;eB=aa;if eB>-1 then if math.abs(hq-bM)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(hq-bM)>hy then if pitchPID==nil then pitchPID=pid.new(8*0.01,0,8*0.1)end;pitchPID:inject(hq-bM)local hz=pitchPID:get()C=C+hz end end;L=orbit.eccentricity;if antigrav and not ExternalAGG and ae<200000 then if AntigravTargetAltitude==nil then AntigravTargetAltitude=1000 end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end end end end;function script.onFlush()if antigrav and not ExternalAGG then if antigrav.getState()==0 and antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(AntigravTargetAltitude)end end;local hH=2;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)hH=math.max(hH,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 hI=utils.clamp(B+C+system.getControlDeviceForwardInput(),-1,1)local hJ=utils.clamp(E+H+system.getControlDeviceYawInput(),-1,1)local hK=utils.clamp(F+D-system.getControlDeviceLeftRightInput(),-1,1)local hL=G;local hM=vec3(core.getWorldVertical())local hN=vec3(core.getConstructWorldOrientationUp())local hO=vec3(core.getConstructWorldOrientationForward())local hP=vec3(core.getConstructWorldOrientationRight())local hQ=vec3(core.getWorldVelocity())local hR=vec3(core.getWorldVelocity()):normalize()local hS=getRoll(hM,hO,hP)local hT=math.abs(hS)local hU=utils.sign(hS)local j=j()local hV=vec3(core.getWorldAngularVelocity())local hW=hI*pitchSpeedFactor*hP+hJ*rollSpeedFactor*hO+hK*yawSpeedFactor*hN;if hM:len()>0.01 and j>0.0 or ProgradeIsOn then local hX=1.0;if b2==true and hT>hX and hJ==0 then local hY=utils.clamp(0,hT-30,hT+30)if rollPID==nil then rollPID=pid.new(autoRollFactor*0.01,0,autoRollFactor*0.1)end;rollPID:inject(hY-hS)local hZ=rollPID:get()hW=hW+hZ*hO end end;if hM:len()>0.01 and j>0.0 then local h_=20.0;if turnAssist==true and hT>h_ and hI==0 and hK==0 then local i0=turnAssistFactor*0.1;local i1=turnAssistFactor*0.025;local i2=(hT-h_)/(180-h_)*180;local i3=0;if i2<90 then i3=i2/90 elseif i2<180 then i3=(180-i2)/90 end;i3=i3*i3;local i4=-hU*i1*(1.0-i3)local i5=i0*i3;hW=hW+i5*hP+i4*hN end end;local i6=1;local i7=0;local i8=1;local i9=hH*(hW-hV)local ia=vec3(core.getWorldAirFrictionAngularAcceleration())i9=i9-ia;Nav:setEngineTorqueCommand('torque',i9,i6,'airfoil','','',i8)local ib=-hL*(brakeSpeedFactor*hQ+brakeFlatFactor*hR)Nav:setEngineForceCommand('brake',ib)local ic=''local id=vec3()local ie=false;local ig='thrust analog longitudinal 'if ExtraLongitudeTags~="none"then ig=ig..ExtraLongitudeTags end;local ih=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if ih==axisCommandType.byThrottle then local ii=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ig,axisCommandId.longitudinal)Nav:setEngineForceCommand(ig,ii,i6)elseif ih==axisCommandType.byTargetSpeed then local ii=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)ic=ic..' , '..ig;id=id+ii;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then ie=true end end;local ij='thrust analog lateral 'if ExtraLateralTags~="none"then ij=ij..ExtraLateralTags end;local ik=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if ik==axisCommandType.byThrottle then local il=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ij,axisCommandId.lateral)Nav:setEngineForceCommand(ij,il,i6)elseif ik==axisCommandType.byTargetSpeed then local im=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)ic=ic..' , '..ij;id=id+im end;local io='thrust analog vertical 'if ExtraVerticalTags~="none"then io=io..ExtraVerticalTags end;local ip=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if ip==axisCommandType.byThrottle then local iq=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(io,axisCommandId.vertical)if Z~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(io,iq,i6,'airfoil','ground','',i8)else Nav:setEngineForceCommand(io,vec3(),i6)Nav:setEngineForceCommand('airfoil vertical',iq,i6,'airfoil','','',i8)Nav:setEngineForceCommand('ground vertical',iq,i6,'ground','','',i8)end elseif ip==axisCommandType.byTargetSpeed then if Z==0 then Nav:setEngineForceCommand('hover',vec3(),i6)end;local ir=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)ic=ic..' , '..io;id=id+ir end;if id:len()>constants.epsilon then if G~=0 or ie or math.abs(hR:dot(hO))<0.95 then ic=ic..', brake'end;Nav:setEngineForceCommand(ic,id,i7,'','','',i8)end;Nav:setBoosterCommand('rocket_engine')if O and not VanillaRockets then local bh=vec3(core.getVelocity()):len()local is=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local it=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if bh*3.6>it*(1-is)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh*3.6=hx*(1-is)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh=hx*(1-is)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh0 or aew then K="WARNING: Insufficient Brakes - Attempting landing anyway"end;Reentry=false;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=true;b2=true;GearExtended=false else BrakeIsOn=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end else Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end elseif iv=="light"then if Nav.control.isAnyHeadlightSwitchedOn()==1 then Nav.control.switchOffHeadlights()else Nav.control.switchOnHeadlights()end elseif iv=="forward"then B=B-1 elseif iv=="backward"then B=B+1 elseif iv=="left"then E=E-1 elseif iv=="right"then E=E+1 elseif iv=="yawright"then F=F-1 elseif iv=="yawleft"then F=F+1 elseif iv=="straferight"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,1.0)elseif iv=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,-1.0)elseif iv=="up"then Z=Z+1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,1.0)elseif iv=="down"then Z=Z-1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,-1.0)elseif iv=="groundaltitudeup"then OldButtonMod=M;OldAntiMod=N;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+N;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+N end else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+M else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif iv=="groundaltitudedown"then OldButtonMod=M;OldAntiMod=N;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-M else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif iv=="option1"then IncrementAutopilotTargetIndex()v=false elseif iv=="option2"then DecrementAutopilotTargetIndex()v=false elseif iv=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;v=false;ToggleWidgets()elseif iv=="option4"then ToggleAutopilot()v=false elseif iv=="option5"then ToggleLockPitch()v=false elseif iv=="option6"then ToggleAltitudeHold()v=false elseif iv=="option7"then wipeSaveVariables()v=false elseif iv=="option8"then ToggleFollowMode()v=false elseif iv=="option9"then if gyro~=nil then gyro.toggle()ah=gyro.getState()==1 end;v=false elseif iv=="lshift"then if system.isViewLocked()==1 then J=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif o()==1 and ShiftShowsRemoteButtons then J=true;b1=false;b0=false end elseif iv=="brake"then if BrakeToggleStatus then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif iv=="lalt"then if o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif iv=="booster"then if VanillaRockets then Nav:toggleBoosters()elseif not O then if not IsRocketOn then Nav:toggleBoosters()IsRocketOn=true end;O=true else if IsRocketOn then Nav:toggleBoosters()IsRocketOn=false end;O=false end elseif iv=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)clearAll()elseif iv=="speedup"then if not J then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)else IncrementAutopilotTargetIndex()end elseif iv=="speeddown"then if not J then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)else DecrementAutopilotTargetIndex()end elseif iv=="antigravity"and not ExternalAGG then if antigrav~=nil then ToggleAntigrav()end end end;function script.onActionStop(iv)if iv=="forward"then B=0 elseif iv=="backward"then B=0 elseif iv=="left"then E=0 elseif iv=="right"then E=0 elseif iv=="yawright"then F=0 elseif iv=="yawleft"then F=0 elseif iv=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)elseif iv=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)elseif iv=="up"then Z=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif iv=="down"then Z=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif iv=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then N=OldAntiMod end;if AltitudeHold then M=OldButtonMod end;v=false elseif iv=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then N=OldAntiMod end;if AltitudeHold then M=OldButtonMod end;v=false elseif iv=="lshift"then if system.isViewLocked()==1 then J=false;a0=0;a1=0;system.lockView(PrevViewLock)elseif o()==1 and ShiftShowsRemoteButtons then J=false;b1=false;b0=false end elseif iv=="brake"then if not BrakeToggleStatus then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif iv=="lalt"then if o()==0 and freeLookToggle then if v then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else v=true end elseif o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end end end;function script.onActionLoop(iv)if iv=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+N;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+N end;N=N*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+M;M=M*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif iv=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end;N=N*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-M;M=M*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif iv=="speedup"then if not J then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end elseif iv=="speeddown"then if not J then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end;function script.onInputText(iw)local i;local ix="/commands /setname /G /agg /addlocation"local iy,iz;local iA="Command List:\n/commands \n/setname - Updates current selected saved position name\n/G VariableName newValue - Updates global variable to new value\n"iA=iA.."/agg - Manually set agg target height\n/addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572} - adds a saved location by waypoint, not as accurate as making one at location"i=string.find(iw," ")if i~=nil then iy=string.sub(iw,0,i-1)iz=string.sub(iw,i+1)elseif i==nil or not string.find(ix,iy)then for eU in string.gmatch(iA,"([^\n]+)")do c(eU)end;return end;if iy=="/setname"then if iz==nil or iz==""then K="Usage: /setname Newname"return end;if AutopilotTargetIndex>0 and CustomTarget~=nil then UpdatePosition(iz)else K="Select a saved target to rename first"end elseif iy=="/addlocation"then if iz==nil or iz==""or string.find(iz,"::")==nil then K="Usage: /addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572}"return end;i=string.find(iz,"::")local bw=string.sub(iz,1,i-2)i=string.find(iz,",")iz=string.sub(iz,i+1)local bV=string.find(iz,",")local bx=tonumber(string.sub(iz,1,bV-1))i=string.find(iz,",")iz=string.sub(iz,i+1)bV=string.find(iz,",")local bn=tonumber(string.sub(iz,1,bV-1))i=string.find(iz,",")iz=string.sub(iz,i+1)bV=string.find(iz,",")local bo=tonumber(string.sub(iz,1,bV-1))i=string.find(iz,",")iz=string.sub(iz,i+1)local by=tonumber(string.sub(iz,1,#iz-1))AddNewLocationByWaypoint(bw,bx,bn,bo,by)elseif iy=="/agg"then if iz==nil or iz==""then K="Usage: /agg targetheight"return end;iz=tonumber(iz)if iz<1000 then iz=1000 end;AntigravTargetAltitude=iz;K="AGG Target Height set to "..iz elseif iy=="/G"then if iz==nil or iz==""then K="Usage: /G VariableName variablevalue"return end;i=string.find(iz," ")local iB=string.sub(iz,0,i-1)local iC=string.sub(iz,i+1)for b4,b5 in pairs(a)do if b5==iB then K="Variable "..iB.." changed to "..iC;local iD=type(_G[b5])if iD=="number"then iC=tonumber(iC)elseif iD=="boolean"then if string.lower(iC)=="true"then iC=true else iC=false end end;_G[b5]=iC;return end end;K="No such global variable: "..iB end end;script.onStart() + ]],cD,bn,bo+dW,dT,bn,bo+dX,dS))bM=bM+1;dJ=dJ*10;if dS==dM then dK=dU else dK=0 end end;table.insert(bO,[[]])end end;function DrawPrograde(bO,velocity,bh,centerX,centerY)if bh>5 and not ad or bh>w then local dp=circleRad;local dY=20;local dZ=20;local d_=vec3(velocity)local e0=getRelativePitch(d_)local e1=getRelativeYaw(d_)local e2=-e1/dZ*dp;local e3=e0/dY*dp;local bn=centerX+e2;local bo=centerY+e3;local a3=math.sqrt(e2^2+e3^2)if a3',bn,bo)else local dk=math.atan(e3,e2)local e4=centerX+dp*math.cos(dk)local e5=centerY+dp*math.sin(dk)bO[#bO+1]=e('',e4,e5)end;e0=getRelativePitch(-d_)e1=getRelativeYaw(-d_)e2=-e1/dZ*dp;e3=e0/dY*dp;bn=centerX+e2;bo=centerY+e3;a3=math.sqrt(e2^2+e3^2)if not ad then if a3',bn,bo)else local dk=math.atan(e3,e2)local e4=centerX+dp*math.cos(dk)local e5=centerY+dp*math.sin(dk)bO[#bO+1]=e('',e4,e5)end end end end;function DrawWarnings(bO)bO[#bO+1]=e([[DU Hud Version: %.3f]],ConvertResolutionX(1900),ConvertResolutionY(1070),VERSION_NUMBER)bO[#bO+1]=[[]]if unit.isMouseControlActivated()==1 then bO[#bO+1]=e([[ + Warning: Invalid Control Scheme Detected]],ConvertResolutionX(960),ConvertResolutionY(550))bO[#bO+1]=e([[ + Keyboard Scheme must be selected]],ConvertResolutionX(960),ConvertResolutionY(600))bO[#bO+1]=e([[ + Set your preferred scheme in Lua Parameters instead]],ConvertResolutionX(960),ConvertResolutionY(650))end;local e6=ConvertResolutionX(960)local e7=ConvertResolutionY(860)local e8=ConvertResolutionY(880)local e9=ConvertResolutionY(900)local ea=ConvertResolutionY(960)local eb=ConvertResolutionY(200)local ec=ConvertResolutionY(150)local ed=ConvertResolutionY(960)if o()==1 and not RemoteHud then e7=ConvertResolutionY(135)e8=ConvertResolutionY(155)e9=ConvertResolutionY(175)eb=ConvertResolutionY(115)ec=ConvertResolutionY(95)end;if BrakeIsOn then bO[#bO+1]=e([[Brake Engaged]],e6,e7)end;if ad and RateOfChangebrakeLandingRate+5 then bO[#bO+1]=e([[** STALL WARNING **]],e6,eb+50)end;if ah then bO[#bO+1]=e([[Gyro Enabled]],e6,ed)end;if GearExtended then if A then bO[#bO+1]=e([[Gear Extended]],e6,e8)else bO[#bO+1]=e([[Landed (G: Takeoff)]],e6,e8)end;bO[#bO+1]=e([[Hover Height: %s]],e6,e9,getDistanceDisplayString(Nav:getTargetGroundAltitude()))end;if O then bO[#bO+1]=e([[ROCKET BOOST ENABLED]],e6,ea+20)end;if antigrav and not ExternalAGG and antigrav.getState()==1 and AntigravTargetAltitude~=nil then if math.abs(ae-antigrav.getBaseAltitude())<501 then bO[#bO+1]=e([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],e6,eb+20,d(AntigravTargetAltitude),d(antigrav.getBaseAltitude()))else bO[#bO+1]=e([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],e6,eb+20,d(AntigravTargetAltitude),d(antigrav.getBaseAltitude()))end elseif Autopilot and AutopilotTargetName~="None"then bO[#bO+1]=e([[Autopilot %s]],e6,eb+20,AutopilotStatus)elseif LockPitch~=nil then bO[#bO+1]=e([[LockedPitch: %d]],e6,eb+20,d(LockPitch))elseif I then bO[#bO+1]=e([[Follow Mode Engaged]],e6,eb+20)elseif Reentry then bO[#bO+1]=e([[Parachute Re-entry in Progress]],e6,eb+20)end;if AltitudeHold then if AutoTakeoff then bO[#bO+1]=e([[Ascent to %s]],e6,eb,getDistanceDisplayString(HoldAltitude))if BrakeIsOn then bO[#bO+1]=e([[Throttle Up and Disengage Brake For Takeoff]],e6,eb+50)end else bO[#bO+1]=e([[Altitude Hold: %s]],e6,eb,getDistanceDisplayString2(HoldAltitude))end end;if BrakeLanding then if StrongBrakes then bO[#bO+1]=e([[Brake-Landing]],e6,eb)else bO[#bO+1]=e([[Coast-Landing]],e6,eb)end end;if ProgradeIsOn then bO[#bO+1]=e([[Prograde Alignment]],e6,eb)end;if RetrogradeIsOn then bO[#bO+1]=e([[Retrograde Alignment]],e6,eb)end;if TurnBurn then bO[#bO+1]=e([[Turn & Burn Braking]],e6,ec)end;if VectorToTarget then bO[#bO+1]=e([[%s]],e6,eb+30,VectorStatus)end;bO[#bO+1]=""end;function DisplayOrbitScreen(bO)if orbit~=nil and j()<0.2 and planet~=nil and orbit.apoapsis~=nil and orbit.periapsis~=nil and orbit.period~=nil and orbit.apoapsis.speed>5 and DisplayOrbit then local ee=75;local ef=0;local eg=250;local eh=4;ef=ef+eh;local ei=15;local bn=ee+eg+ee/2+eh;local bo=ef+eg/2+5+eh;local ej,ek,el,em;ej=eg/4;em=0;bO[#bO+1]=[[]]bO[#bO+1]=e('',eg+ee*2,eg+ef,eh,eh)if orbit.periapsis~=nil and orbit.apoapsis~=nil then el=(orbit.apoapsis.altitude+orbit.periapsis.altitude+planet.radius*2)/(ej*2)ek=(planet.radius+orbit.periapsis.altitude+(orbit.apoapsis.altitude-orbit.periapsis.altitude)/2)/el*(1-orbit.eccentricity)em=ej-orbit.periapsis.altitude/el-planet.radius/el;local en=""if orbit.periapsis.altitude<=0 then en='redout'end;bO[#bO+1]=e([[]],en,ee+eg/2+em+eh,ef+eg/2+eh,ej,ek)bO[#bO+1]=e('',ee+eg/2+eh,ef+eg/2+eh,planet.radius/el)end;if orbit.apoapsis~=nil and orbit.apoapsis.speed1 then bO[#bO+1]=e([[]],bn-35,bo-5,ee+eg/2+ej+em,bo-5)bO[#bO+1]=e([[Apoapsis]],bn,bo)bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,getDistanceDisplayString(orbit.apoapsis.altitude))bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,FormatTimeString(orbit.timeToApoapsis))bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,getSpeedDisplayString(orbit.apoapsis.speed))end;bo=ef+eg/2+5+eh;bn=ee-ee/2+10+eh;if orbit.periapsis~=nil and orbit.periapsis.speed1 then bO[#bO+1]=e([[]],bn+35,bo-5,ee+eg/2-ej+em,bo-5)bO[#bO+1]=e([[Periapsis]],bn,bo)bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,getDistanceDisplayString(orbit.periapsis.altitude))bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,FormatTimeString(orbit.timeToPeriapsis))bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,getSpeedDisplayString(orbit.periapsis.speed))end;bO[#bO+1]=e([[%s]],ee+eg/2+eh,20+eh,planet.name)if orbit.period~=nil and orbit.periapsis~=nil and orbit.apoapsis~=nil and orbit.apoapsis.speed>1 then local eo=orbit.timeToApoapsis/orbit.period*2*math.pi;local ep=ej*math.cos(eo)local eq=ek*math.sin(eo)bO[#bO+1]=e('',ee+eg/2+ep+em+eh,ef+eg/2+eq+eh)end;bO[#bO+1]=[[]]end end;function getDistanceDisplayString(a3)local er=a3>100000;local b6=""if er then b6=round(a3/1000/200,1).." SU"elseif a3<1000 then b6=round(a3,1).." M"else b6=round(a3/1000,1).." KM"end;return b6 end;function getDistanceDisplayString2(a3)local er=a3>100000;local b6=""if er then b6=round(a3/1000/200,2).." SU"elseif a3<1000 then b6=round(a3,2).." M"else b6=round(a3/1000,2).." KM"end;return b6 end;function getSpeedDisplayString(bh)return d(round(bh*3.6,0)+0.5).." km/h"end;function FormatTimeString(es)local et=0;local eu=0;local ev=0;if es<60 then es=d(es)elseif es<3600 then et=d(es/60)es=d(es%60)elseif es<86400 then eu=d(es/3600)et=d(es%3600/60)else ev=d(es/86400)eu=d(es%86400/60)end;if ev>0 then return ev.."d "..eu.."h "elseif eu>0 then return eu.."h "..et.."m "elseif et>0 then return et.."m "..es.."s"elseif es>0 then return es.."s"else return"0s"end end;function getMagnitudeInDirection(cF,ew)cF=vec3(cF)ew=vec3(ew):normalize()local b6=cF*ew;return b6.x+b6.y+b6.z end;function UpdateAutopilotTarget()if AutopilotTargetIndex==0 then AutopilotTargetName="None"V=nil;return true end;local ex=AtlasOrdered[AutopilotTargetIndex].index;local ey=aS[0][ex]if ey.center then AutopilotTargetName=ey.name;V=aY[0][ex]if CustomTarget~=nil then if j()==0 then if system.updateData(widgetMaxBrakeTimeText,widgetMaxBrakeTime)~=1 then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;if system.updateData(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)~=1 then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;if system.updateData(widgetCurBrakeTimeText,widgetCurBrakeTime)~=1 then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;if system.updateData(widgetCurBrakeDistanceText,widgetCurBrakeDistance)~=1 then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;if system.updateData(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)~=1 then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;if system.updateData(widgetMaxMassText,widgetMaxMass)~=1 then system.addDataToWidget(widgetMaxMassText,widgetMaxMass)end;if system.updateData(widgetTravelTimeText,widgetTravelTime)~=1 then system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)end end;CustomTarget=nil else CustomTarget=ey;for _,b5 in pairs(aY[0])do if b5.name==CustomTarget.planetname then V=b5;AutopilotTargetName=CustomTarget.name;break end end;if system.updateData(widgetMaxMassText,widgetMaxMass)~=1 then system.addDataToWidget(widgetMaxMassText,widgetMaxMass)end;if system.updateData(widgetTravelTimeText,widgetTravelTime)~=1 then system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)end end;AutopilotTargetCoords=vec3(V.center)_,AutopilotEndSpeed=a_(V):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 ez=LastMaxBrakeInAtmo/V:getGravity(V.center+vec3(0,0,1)*V.radius):len()return ez end;function GetAutopilotTravelTime()if not Autopilot then if CustomTarget==nil or CustomTarget.planetname~=planet.name then AutopilotDistance=(V.center-vec3(core.getConstructWorldPos())):len()else AutopilotDistance=(CustomTarget.position-vec3(core.getConstructWorldPos())):len()end end;local velocity=core.getWorldVelocity()local bh=vec3(velocity):len()local eA,eB=aZ.computeDistanceAndTime(vec3(velocity):len(),MaxGameVelocity,n(),Nav:maxForceForward(),warmup,0)local P,Q;if not TurnBurn then P,Q=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else P,Q=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;local _,eC;if not TurnBurn then _,eC=GetAutopilotBrakeDistanceAndTime(bh)else _,eC=GetAutopilotTBBrakeDistanceAndTime(bh)end;local eD=0;local eE=0;if AutopilotCruising or not Autopilot and bh>5 then eE=aZ.computeTravelTime(bh,0,AutopilotDistance)elseif P+eA0 then return aZ.computeDistanceAndTime(bh,AutopilotEndSpeed,n(),0,0,LastMaxBrakeInAtmo-AutopilotPlanetGravity*n())else return 0,0 end end end;function GetAutopilotTBBrakeDistanceAndTime(bh)RefreshLastMaxBrake()return aZ.computeDistanceAndTime(bh,AutopilotEndSpeed,n(),Nav:maxForceForward(),warmup,LastMaxBrake-AutopilotPlanetGravity*n())end;function hoverDetectGround()local eG=-1;local eH=-1;if vBooster then eG=vBooster.distance()end;if hover then eH=hover.distance()end;if eG~=-1 and eH~=-1 then if eGProfileTimeMax then ProfileTimeMax=eN end;if eN0 then local eX=eU:find('identifiedConstructs":%[%]')if eX==nil and perisPanelID==nil then a6=1;ToggleRadarPanel()end;if eX~=nil and perisPanelID~=nil then ToggleRadarPanel()end;if radarPanelID==nil then ToggleRadarPanel()end;a4=e([[Radar: %i contacts]],eV,eW,#eT)local eY={}for b4,b5 in pairs(eT)do if radar_1.hasMatchingTransponder(b5)==1 then eY[#eY+1]=b5 end end;if#eY>0 then local bo=ConvertResolutionY(15)local bn=ConvertResolutionX(1370)a4=e([[%sFriendlies In Range]],a4,bn,bo)for b4,b5 in pairs(eY)do bo=bo+20;a4=e([[%s%s]],a4,bn,bo,radar_1.getConstructName(b5))end end else local eZ;eZ=eU:find('worksInEnvironment":false')if eZ then a4=e([[ + Radar: Jammed]],eV,eW)else a4=e([[ + Radar: No Contacts]],eV,eW)end;if radarPanelID~=nil then a6=0;ToggleRadarPanel()end end end end;function DisplayMessage(bO,e_)if e_~="empty"then bO[#bO+1]=[[]]for f0 in string.gmatch(e_,"([^\n]+)")do bO[#bO+1]=e([[%s]],f0)end;bO[#bO+1]=[[]]end;if a2~=0 then unit.setTimer("msgTick",a2)a2=0 end end;function updateDistance()local bc=system.getTime()local velocity=vec3(core.getWorldVelocity())local cZ=vec3(velocity):len()local f1=bc-ag;if cZ>1.38889 then cZ=cZ/1000;local f2=cZ*(bc-ag)TotalDistanceTravelled=TotalDistanceTravelled+f2;W=W+f2 end;X=X+f1;TotalFlightTime=TotalFlightTime+f1;ag=bc 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;function SetupAtlas()aS=Atlas()for b4,b5 in pairs(aS[0])do if av==nil or b5.center.xaw then aw=b5.center.x end;if ax==nil or b5.center.yay then ay=b5.center.y end end;aT=""local f3=1.1*(aw-av)/1920;local f4=1.4*(ay-ax)/1080;for b4,b5 in pairs(aS[0])do local bn=960+b5.center.x/f3;local bo=540+b5.center.y/f4;aT=aT..''if not string.match(b5.name,"Moon")and not string.match(b5.name,"Sanctuary")then aT=aT..""..b5.name..""end end;local bw=vec3(core.getConstructWorldPos())local bn=960+bw.x/f3;local bo=540+bw.y/f4;aT=aT..''aT=aT.."You Are Here"aT=aT..[[]]aU=f3;aV=f4;if screen_2 then screen_2.setHTML(''..aT)local bw=vec3(core.getConstructWorldPos())local bn=960+bw.x/f3;local bo=540+bw.y/f4;aT=''aT=aT.."You Are Here"aW=screen_2.addContent((bn-80)/19.20,(bo-80)/10.80,aT)end end;function PlanetRef()local function f5(f6)return type(f6)=='number'end;local function f7(f6)return type(tonumber(f6))=='number'end;local function f8(f9)return type(f9)=='table'end;local function fa(fb)return type(fb)=='string'end;local function fc(b5)return f8(b5)and f5(b5.x and b5.y and b5.z)end;local function fd(fe)return f8(fe)and f5(fe.latitude and fe.longitude and fe.altitude and fe.bodyId and fe.systemId)end;local ff=math.pi/180;local fg=180/math.pi;local fh=1e-10;local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local bx='::pos{'..p..','..p..','..p..','..p..','..p..'}'local utils=require('cpml.utils')local vec3=require('cpml.vec3')local fi=utils.clamp;local function fj(fk,fl)if fk==0 then return math.abs(fl)<1e-09 end;if fl==0 then return math.abs(fk)<1e-09 end;return math.abs(fk-fl)=0 then local gc=math.sqrt(gb)local gd=ga+gc;local ge=ga-gc;if ge>0 then return g1,gd,ge elseif gd>0 then return g1,gd,nil end end end;return nil,nil,nil end;function fE:closestBody(gf)assert(type(gf)=='table','Invalid coordinates.')local gg,g1;local gh=vec3(gf)for _,gi in pairs(self)do local gj=(gi.center-gh):len2()if not g1 or gj=0 and gn or 2*math.pi+gn;bA=math.pi/2-math.acos(gm.z/a3)end;return setmetatable({latitude=bA,longitude=bB,altitude=bC,bodyId=self.bodyId,systemId=self.planetarySystemId},fA)end;function fr:convertToWorldCoordinates(fD)local gk=fa(fD)and fC(fD)or fD;if gk.bodyId==0 then return vec3(gk.latitude,gk.longitude,gk.altitude)end;assert(fd(gk),'Argument 1 (mapPosition) is not an instance of "MapPosition".')assert(gk.systemId==self.planetarySystemId,'Argument 1 (mapPosition) has a different planetary system ID.')assert(gk.bodyId==self.bodyId,'Argument 1 (mapPosition) has a different planetary body ID.')local bD=math.cos(gk.latitude)return self.center+(self.radius+gk.altitude)*vec3(bD*math.cos(gk.longitude),bD*math.sin(gk.longitude),math.sin(gk.latitude))end;function fr:getAltitude(fy)return(vec3(fy)-self.center):len()-self.radius end;function fr:getDistance(fy)return(vec3(fy)-self.center):len()end;function fr:getGravity(fy)local go=self.center-vec3(fy)local gp=go:len2()return self.GM/gp*go/math.sqrt(gp)end;return setmetatable(aX,{__call=function(_,...)return fM(...)end})end;function Keplers()local vec3=require('cpml.vec3')local PlanetRef=PlanetRef()local function fa(fb)return type(fb)=='string'end;local function f8(f9)return type(f9)=='table'end;local function fj(fk,fl)if fk==0 then return math.abs(fl)<1e-09 end;if fl==0 then return math.abs(fk)<1e-09 end;return math.abs(fk-fl)0 then gG=gF;gH=gG+gA/2 end;if gH>gA then gH=gH-gA end end;return{periapsis={position=gx,speed=gz/gv,circularOrbitSpeed=math.sqrt(gs/gv),altitude=gv-self.body.radius},apoapsis=gy and{position=gy,speed=gz/gw,circularOrbitSpeed=math.sqrt(gs/gw),altitude=gw-self.body.radius},currentVelocity=b5,currentPosition=bw,eccentricity=gu,period=gA,eccentricAnomaly=gC,meanAnomaly=gE,timeToPeriapsis=gG,timeToApoapsis=gH}end;local function gI(gJ)local gi=PlanetRef.BodyParameters(gJ.planetarySystemId,gJ.bodyId,gJ.radius,gJ.center,gJ.GM)return setmetatable({body=gi},Kepler)end;return setmetatable(Kepler,{__call=function(_,...)return gI(...)end})end;function Kinematics()local aZ={}local gK=30000000/3600;local gL=gK*gK;local gM=100;local function gN(b5)return 1/math.sqrt(1-b5*b5/gL)end;function aZ.computeAccelerationTime(gO,gP,gQ)local gR=gK*math.asin(gO/gK)return(gK*math.asin(gQ/gK)-gR)/gP end;function aZ.computeDistanceAndTime(gO,gQ,gS,gT,gU,gV)gU=gU or 0;gV=gV or 0;local gW=gO<=gQ;local gX=gT*(gW and 1 or-1)/gS;local gY=-gV/gS;local gZ=gX+gY;if gW and gZ<=0 or not gW and gZ>=0 then return-1,-1 end;local g_,h0=0,0;if gX~=0 and gU>0 then local gR=math.asin(gO/gK)local h1=math.pi*(gX/2+gY)local h2=gX*gU;local h3=gK*math.pi;local b5=function(f9)local c9=(h1*f9-h2*math.sin(math.pi*f9/2/gU)+h3*gR)/h3;local h4=math.tan(c9)return gK*h4/math.sqrt(h4*h4+1)end;local h5=gW and function(fb)return fb>=gQ end or function(fb)return fb<=gQ end;h0=2*gU;if h5(b5(h0))then local h6=0;while math.abs(h0-h6)>0.5 do local f9=(h0+h6)/2;if h5(b5(f9))then h0=f9 else h6=f9 end end end;local h7=gO;local h8=h0/gM;for h9=1,gM do local bh=b5(h9*h8)g_=g_+(bh+h7)*h8/2;h7=bh end;if h0<2*gU then return g_,h0 end;gO=h7 end;local gR=gK*math.asin(gO/gK)local b7=(gK*math.asin(gQ/gK)-gR)/gZ;local ha=gL*math.cos(gR/gK)/gZ;local a3=ha-gL*math.cos((gZ*b7+gR)/gK)/gZ;return a3+g_,b7+h0 end;function aZ.computeTravelTime(gO,gP,a3)if a3==0 then return 0 end;if gP>0 then local gR=gK*math.asin(gO/gK)local ha=gL*math.cos(gR/gK)/gP;return(gK*math.acos(gP*(ha-a3)/gL)-gR)/gP end;assert(gO>0,'Acceleration and initial speed are both zero.')return a3/gO end;function aZ.lorentz(b5)return gN(b5)end;return aZ end;function script.onStart()VERSION_NUMBER=4.920;SetupComplete=false;beginSetup=coroutine.create(function()Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal,{1000,5000,10000,20000,30000})LoadVariables()coroutine.yield()ProcessElements()coroutine.yield()SetupChecks()SetupButtons()coroutine.yield()SetupAtlas()aX=PlanetRef()aY=aX(Atlas())aZ=Kinematics()a_=Keplers()AddLocationsToAtlas()UpdateAutopilotTarget()coroutine.yield()unit.hide()system.showScreen(1)collectgarbage("collect")unit.setTimer("apTick",apTickRate)unit.setTimer("oneSecond",1)unit.setTimer("tenthSecond",1/10)if UseSatNav then unit.setTimer("fiveSecond",5)end end)end;function script.onStop()_autoconf.hideCategoryPanels()if antigrav~=nil and not ExternalAGG then antigrav.hide()end;if warpdrive~=nil then warpdrive.hide()end;core.hide()Nav.control.switchOffHeadlights()local bI=j()if door and(bI>0 or bI==0 and ae<10000)then for _,b5 in pairs(door)do b5.toggle()end end;if switch then for _,b5 in pairs(switch)do b5.toggle()end end;if forcefield and(bI>0 or bI==0 and ae<10000)then for _,b5 in pairs(forcefield)do b5.toggle()end end;if dbHud_1 then if not Y then for b4,b5 in pairs(b)do dbHud_1.setStringValue(b5,g(_G[b5]))end;for b4,b5 in pairs(a)do dbHud_1.setStringValue(b5,g(_G[b5]))end;c("Saved Variables to Datacore")end end;if button then button.activate()end end;function script.onTick(hb)if hb=="tenthSecond"then if AutopilotTargetName~="None"then if panelInterplanetary==nil then SetupInterplanetaryPanel()end;if AutopilotTargetName~=nil then local hc=CustomTarget~=nil;planetMaxMass=GetAutopilotMaxMass()system.updateData(interplanetaryHeaderText,'{"label": "Target", "value": "'..AutopilotTargetName..'", "unit":""}')travelTime=GetAutopilotTravelTime()if hc then a3=(vec3(core.getConstructWorldPos())-CustomTarget.position):len()else a3=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()end;if not TurnBurn then P,Q=GetAutopilotBrakeDistanceAndTime(velMag)R,S=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else P,Q=GetAutopilotTBBrakeDistanceAndTime(velMag)R,S=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;system.updateData(widgetDistanceText,'{"label": "distance", "value": "'..getDistanceDisplayString(a3)..'", "unit":""}')system.updateData(widgetTravelTimeText,'{"label": "Travel Time", "value": "'..FormatTimeString(travelTime)..'", "unit":""}')system.updateData(widgetCurBrakeDistanceText,'{"label": "Cur Brake distance", "value": "'..getDistanceDisplayString(P)..'", "unit":""}')system.updateData(widgetCurBrakeTimeText,'{"label": "Cur Brake Time", "value": "'..FormatTimeString(Q)..'", "unit":""}')system.updateData(widgetMaxBrakeDistanceText,'{"label": "Max Brake distance", "value": "'..getDistanceDisplayString(R)..'", "unit":""}')system.updateData(widgetMaxBrakeTimeText,'{"label": "Max Brake Time", "value": "'..FormatTimeString(S)..'", "unit":""}')system.updateData(widgetMaxMassText,'{"label": "Maximum Mass", "value": "'..e("%.2f tons",planetMaxMass/1000)..'", "unit":""}')if j()>0 and not WasInAtmo then system.removeDataFromWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)system.removeDataFromWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)system.removeDataFromWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)system.removeDataFromWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)system.removeDataFromWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)WasInAtmo=true end;if j()==0 and WasInAtmo then if system.updateData(widgetMaxBrakeTimeText,widgetMaxBrakeTime)==1 then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;if system.updateData(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)==1 then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;if system.updateData(widgetCurBrakeTimeText,widgetCurBrakeTime)==1 then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;if system.updateData(widgetCurBrakeDistanceText,widgetCurBrakeDistance)==1 then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;if system.updateData(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)==1 then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end;WasInAtmo=false end end else HideInterplanetaryPanel()end;if warpdrive~=nil then if f(warpdrive.getData()).destination~="Unknown"and f(warpdrive.getData()).distance>400000 then warpdrive.show()showWarpWidget=true else warpdrive.hide()showWarpWidget=false end end elseif hb=="oneSecond"then ab=false;RefreshLastMaxBrake(nil,true)updateDistance()updateRadar()updateWeapons()local bO={}local cP=GetFlightStyle()DrawOdometer(bO,W,TotalDistanceTravelled,cP,X)CheckDamage(bO)a5=table.concat(bO,"")collectgarbage("collect")elseif hb=="fiveSecond"then ac=dbHud_1.getStringValue("SPBAutopilotTargetName")if ac~=nil and ac~=""and ac~="SatNavNotChanged"then local b6=json.decode(dbHud_1.getStringValue("SavedLocations"))if b6~=nil then _G["SavedLocations"]=b6;local bM=-1;local bH;for b4,b5 in pairs(SavedLocations)do if b5.name and b5.name=="SatNav Location"then bM=b4;break end end;if bM~=-1 then bH=SavedLocations[bM]bM=-1;for b4,b5 in pairs(aS[0])do if b5.name and b5.name=="SatNav Location"then bM=b4;break end end;if bM>-1 then aS[0][bM]=bH end;UpdateAtlasLocationsList()K=bH.name.." position updated"end end;for i=1,#AtlasOrdered do if AtlasOrdered[i].name==ac then AutopilotTargetIndex=i;system.print("Index = "..AutopilotTargetIndex.." "..AtlasOrdered[i].name)UpdateAutopilotTarget()dbHud_1.setStringValue("SPBAutopilotTargetName","SatNavNotChanged")break end end end elseif hb=="msgTick"then local bO={}DisplayMessage(bO,"empty")K="empty"unit.stopTimer("msgTick")a2=3 elseif hb=="animateTick"then b1=true;b0=false;a0=0;a1=0;unit.stopTimer("animateTick")elseif hb=="apTick"then local o=o;RateOfChange=vec3(core.getConstructWorldOrientationForward()):dot(vec3(core.getWorldVelocity()):normalize())ad=j()>0;D=0;H=0;C=0;LastApsDiff=-1;velocity=vec3(core.getWorldVelocity())velMag=vec3(velocity):len()sys=aY[0]planet=sys:closestBody(core.getConstructWorldPos())kepPlanet=a_(planet)orbit=kepPlanet:orbitalParameters(core.getConstructWorldPos(),velocity)aa=hoverDetectGround()local hd=system.getMouseDeltaX()local he=system.getMouseDeltaY()TargetGroundAltitude=Nav:getTargetGroundAltitude()local hf=velMag>8334;if not hf and LastIsWarping then if not BrakeIsOn then BrakeToggle()end;if Autopilot then ToggleAutopilot()end end;LastIsWarping=hf;if ad and j()>0.09 then if not ai then if velMag>AtmoSpeedLimit/3.6 then BrakeIsOn=true;ai=true end else if velMag]],ResolutionX,ResolutionY)if K~="empty"then DisplayMessage(bO,K)end;if o()==0 and userControlScheme=="virtual joystick"then DrawDeadZone(bO)end;if o()==1 and screen_1 and screen_1.getMouseY()~=-1 then a0=screen_1.getMouseX()*ResolutionX;a1=screen_1.getMouseY()*ResolutionY;SetButtonContains()DrawButtons(bO)if screen_1.getMouseState()==1 then CheckButtons()end;bO[#bO+1]=e([[]],s,t,a0,a1)elseif system.isViewLocked()==0 then if o()==1 and J then if not b0 then a0=a0+hd;a1=a1+he end;SetButtonContains()DrawButtons(bO)if not b0 and not b1 then local hg=table.concat(bO,"")bO={}bO[#bO+1]=e("",ResolutionX,ResolutionY)bO[#bO+1]=aT;bO[#bO+1]=hg;bO[#bO+1]=""b0=true;bO[#bO+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(bO,"")system.setScreen(content)elseif b1 then local hg=table.concat(bO,"")bO={}bO[#bO+1]=e("",ResolutionX,ResolutionY)bO[#bO+1]=aT;bO[#bO+1]=hg;bO[#bO+1]=""end;if not b0 then bO[#bO+1]=e([[]],s,t,a0,a1)end else CheckButtons()a0=0;a1=0 end else a0=a0+hd;a1=a1+he;a3=math.sqrt(a0*a0+a1*a1)if not J and o()==0 then if userControlScheme=="virtual joystick"then if a0>0 and a0>DeadZone then D=D-(a0-DeadZone)*MouseXSensitivity elseif a0<0 and a00 and a1>DeadZone then C=C-(a1-DeadZone)*MouseYSensitivity elseif a1<0 and a1DeadZone then DrawCursorLine(bO)end else SetButtonContains()DrawButtons(bO)end;bO[#bO+1]=e([[]],s,t,a0,a1)end;bO[#bO+1]=[[]]content=table.concat(bO,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end;if ProgradeIsOn then if velMag>w then local hh=AlignToWorldVector(vec3(velocity),0.01)if a7 then b2=true;if hh then ProgradeIsOn=false;x=true;BeginReentry()a7=false;a9=true;b2=autoRollPreference end end end end;if RetrogradeIsOn then if ad then RetrogradeIsOn=false elseif velMag>w then AlignToWorldVector(-vec3(velocity))end end;if not ProgradeIsOn and a7 then if j()==0 then x=true;BeginReentry()a7=false;a9=true else a7=false;ToggleAutopilot()end end;if a9 and aeReentrySpeed-100 then ToggleAutopilot()a9=false end;if Autopilot and j()==0 then local P,Q;if not TurnBurn then P,Q=GetAutopilotBrakeDistanceAndTime(velMag)else P,Q=GetAutopilotTBBrakeDistanceAndTime(velMag)end;P=P;Q=Q;local hi=AutopilotTargetCoords;if orbit.apoapsis==nil and velMag>300 and AutopilotAccelerating then local hj=(vec3(AutopilotTargetCoords)-vec3(core.getConstructWorldPos())):normalize()-vec3(velocity):normalize()local hk=getMagnitudeInDirection(hj,AutopilotShipUp)local hl=getMagnitudeInDirection(hj,AutopilotShipRight)local hm=-hl*AutopilotDistance*velMag*TrajectoryAlignmentStrength;local hn=-hk*AutopilotDistance*velMag*TrajectoryAlignmentStrength;hi=AutopilotTargetCoords+-hm*vec3(AutopilotShipRight)+-hn*vec3(AutopilotShipUp)end;AutopilotDistance=(vec3(hi)-vec3(core.getConstructWorldPos())):len()local ho=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()system.updateData(widgetDistanceText,'{"label": "distance", "value": "'..getDistanceDisplayString(ho)..'", "unit":""}')local hp=true;local hq=(V.center-(vec3(core.getConstructWorldPos())+vec3(velocity):normalize()*AutopilotDistance)):len()-V.radius;system.updateData(widgetTrajectoryAltitudeText,'{"label": "Projected Altitude", "value": "'..getDistanceDisplayString(hq)..'", "unit":""}')if not AutopilotCruising and not AutopilotBraking then hp=AlignToWorldVector((hi-vec3(core.getConstructWorldPos())):normalize())elseif TurnBurn then hp=AlignToWorldVector(-vec3(velocity):normalize())end;if AutopilotAccelerating then if not hp 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)u=false elseif not u then BrakeIsOn=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)u=true end;if vec3(core.getVelocity()):len()>=MaxGameVelocity and math.abs(hq-AutopilotTargetOrbit)<1000 or unit.getThrottle()==0 and u then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)u=false end;if AutopilotDistance<=P then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)u=false end elseif AutopilotBraking then BrakeIsOn=true;G=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>L or orbit.apoapsis.altitude0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if hp then if not AutopilotRealigned then AutopilotTargetCoords=vec3(V.center)+(AutopilotTargetOrbit+V.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotRealigned=true;AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()elseif hp then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not u then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)u=true;BrakeIsOn=false end end end end end;if I then b2=true;local hr=0;local bw=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local hs=bw-vec3(core.getConstructWorldPos())local ht=vec3(hs):project_on(vec3(core.getConstructWorldOrientationForward())):len()local hu=vec3(hs):project_on(vec3(core.getConstructWorldOrientationRight())):len()local a3=math.sqrt(ht*ht+hu*hu)AlignToWorldVector(hs:normalize())local hv=40;local hw=a3hz then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(hr-bU)local hA=pitchPID:get()C=hA end end;local dl=vec3(core.getWorldVertical())*-1;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget or LockPitch~=nil then local d1=unit.getClosestPlanetInfluence()>0;local bC=ae;local hB=HoldAltitude-bC;local hC=500+velMag;local hr=(utils.smoothstep(hB,-hC,hC)-0.5)*2*MaxPitch;if not AltitudeHold then hr=0 end;if LockPitch~=nil then if d1 then hr=LockPitch else LockPitch=nil end end;b2=true;if Reentry then local hD=ReentrySpeed;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=hD then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,hD)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if not x then hr=-80;if j()>0.02 then K="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;hr=0;b2=autoRollPreference end elseif Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==ReentrySpeed then x=false;Reentry=false;b2=autoRollPreference end end;local hE=C;if velMag>w then AlignToWorldVector(vec3(velocity))end;if VectorToTarget and CustomTarget~=nil and AutopilotTargetIndex>0 then local cH=CustomTarget.position-vec3(core.getConstructWorldPos())AlignToWorldVector(cH)local hF=cH:len()-cH:project_on(dl):len()local bi=LastMaxBrakeInAtmo;local dj=velocity.x*dl.x+velocity.y*dl.y+velocity.z*dl.z;local hG=velocity:len()-math.abs(dj)local hH=vec3(core.getWorldAirFrictionAcceleration())if bi~=nil then P,Q=aZ.computeDistanceAndTime(hG,0,n(),0,0,bi+(hH:len()-hH:project_on(dl):len())*n())else P,Q=aZ.computeDistanceAndTime(hG,0,n(),0,0,LastMaxBrake+vec3(core.getWorldAirFrictionAcceleration()):len()*n())end;StrongBrakes=planet.gravity*9.80665*n()LastTargetDistance and not AltitudeHold and not AutoTakeoff then BrakeLanding=true;VectorToTarget=false end;LastTargetDistance=hF end;C=hE;local bR=vec3(core.getConstructWorldOrientationForward())local bS=vec3(core.getConstructWorldOrientationRight())local bT=vec3(core.getWorldVertical())local eI=-1;local bU=getPitch(bT,bR,bS)local hz=0.1;if BrakeLanding then hr=0;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)local dj=velocity.x*dl.x+velocity.y*dl.y+velocity.z*dl.z;eI=aa;if eI>-1 then if math.abs(hr-bU)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(hr-bU)>hz then if pitchPID==nil then pitchPID=pid.new(8*0.01,0,8*0.1)end;pitchPID:inject(hr-bU)local hA=pitchPID:get()C=C+hA end end;L=orbit.eccentricity;if antigrav and not ExternalAGG and ae<200000 then if AntigravTargetAltitude==nil then AntigravTargetAltitude=1000 end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end end end end;function script.onFlush()if antigrav and not ExternalAGG then if antigrav.getState()==0 and antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(AntigravTargetAltitude)end end;local hI=2;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)hI=math.max(hI,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 hJ=utils.clamp(B+C+system.getControlDeviceForwardInput(),-1,1)local hK=utils.clamp(E+H+system.getControlDeviceYawInput(),-1,1)local hL=utils.clamp(F+D-system.getControlDeviceLeftRightInput(),-1,1)local hM=G;local hN=vec3(core.getWorldVertical())local hO=vec3(core.getConstructWorldOrientationUp())local hP=vec3(core.getConstructWorldOrientationForward())local hQ=vec3(core.getConstructWorldOrientationRight())local hR=vec3(core.getWorldVelocity())local hS=vec3(core.getWorldVelocity()):normalize()local hT=getRoll(hN,hP,hQ)local hU=math.abs(hT)local hV=utils.sign(hT)local j=j()local hW=vec3(core.getWorldAngularVelocity())local hX=hJ*pitchSpeedFactor*hQ+hK*rollSpeedFactor*hP+hL*yawSpeedFactor*hO;if hN:len()>0.01 and j>0.0 or ProgradeIsOn then local hY=1.0;if b2==true and hU>hY and hK==0 then local hZ=utils.clamp(0,hU-30,hU+30)if rollPID==nil then rollPID=pid.new(autoRollFactor*0.01,0,autoRollFactor*0.1)end;rollPID:inject(hZ-hT)local h_=rollPID:get()hX=hX+h_*hP end end;if hN:len()>0.01 and j>0.0 then local i0=20.0;if turnAssist==true and hU>i0 and hJ==0 and hL==0 then local i1=turnAssistFactor*0.1;local i2=turnAssistFactor*0.025;local i3=(hU-i0)/(180-i0)*180;local i4=0;if i3<90 then i4=i3/90 elseif i3<180 then i4=(180-i3)/90 end;i4=i4*i4;local i5=-hV*i2*(1.0-i4)local i6=i1*i4;hX=hX+i6*hQ+i5*hO end end;local i7=1;local i8=0;local i9=1;local ia=hI*(hX-hW)local ib=vec3(core.getWorldAirFrictionAngularAcceleration())ia=ia-ib;Nav:setEngineTorqueCommand('torque',ia,i7,'airfoil','','',i9)local ic=-hM*(brakeSpeedFactor*hR+brakeFlatFactor*hS)Nav:setEngineForceCommand('brake',ic)local id=''local ie=vec3()local ig=false;local ih='thrust analog longitudinal 'if ExtraLongitudeTags~="none"then ih=ih..ExtraLongitudeTags end;local ii=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if ii==axisCommandType.byThrottle then local ij=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ih,axisCommandId.longitudinal)Nav:setEngineForceCommand(ih,ij,i7)elseif ii==axisCommandType.byTargetSpeed then local ij=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)id=id..' , '..ih;ie=ie+ij;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then ig=true end end;local ik='thrust analog lateral 'if ExtraLateralTags~="none"then ik=ik..ExtraLateralTags end;local il=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if il==axisCommandType.byThrottle then local im=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ik,axisCommandId.lateral)Nav:setEngineForceCommand(ik,im,i7)elseif il==axisCommandType.byTargetSpeed then local io=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)id=id..' , '..ik;ie=ie+io end;local ip='thrust analog vertical 'if ExtraVerticalTags~="none"then ip=ip..ExtraVerticalTags end;local iq=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if iq==axisCommandType.byThrottle then local ir=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ip,axisCommandId.vertical)if Z~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(ip,ir,i7,'airfoil','ground','',i9)else Nav:setEngineForceCommand(ip,vec3(),i7)Nav:setEngineForceCommand('airfoil vertical',ir,i7,'airfoil','','',i9)Nav:setEngineForceCommand('ground vertical',ir,i7,'ground','','',i9)end elseif iq==axisCommandType.byTargetSpeed then if Z==0 then Nav:setEngineForceCommand('hover',vec3(),i7)end;local is=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)id=id..' , '..ip;ie=ie+is end;if ie:len()>constants.epsilon then if G~=0 or ig or math.abs(hS:dot(hP))<0.95 then id=id..', brake'end;Nav:setEngineForceCommand(id,ie,i8,'','','',i9)end;Nav:setBoosterCommand('rocket_engine')if O and not VanillaRockets then local bh=vec3(core.getVelocity()):len()local it=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local iu=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if bh*3.6>iu*(1-it)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh*3.6=hy*(1-it)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh=hy*(1-it)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh0 or aew then K="WARNING: Insufficient Brakes - Attempting landing anyway"end;Reentry=false;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=true;b2=true;GearExtended=false else BrakeIsOn=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end else Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end elseif iw=="light"then if Nav.control.isAnyHeadlightSwitchedOn()==1 then Nav.control.switchOffHeadlights()else Nav.control.switchOnHeadlights()end elseif iw=="forward"then B=B-1 elseif iw=="backward"then B=B+1 elseif iw=="left"then E=E-1 elseif iw=="right"then E=E+1 elseif iw=="yawright"then F=F-1 elseif iw=="yawleft"then F=F+1 elseif iw=="straferight"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,1.0)elseif iw=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,-1.0)elseif iw=="up"then Z=Z+1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,1.0)elseif iw=="down"then Z=Z-1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,-1.0)elseif iw=="groundaltitudeup"then OldButtonMod=M;OldAntiMod=N;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+N;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+N end else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+M else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif iw=="groundaltitudedown"then OldButtonMod=M;OldAntiMod=N;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-M else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif iw=="option1"then IncrementAutopilotTargetIndex()v=false elseif iw=="option2"then DecrementAutopilotTargetIndex()v=false elseif iw=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;v=false;ToggleWidgets()elseif iw=="option4"then ToggleAutopilot()v=false elseif iw=="option5"then ToggleLockPitch()v=false elseif iw=="option6"then ToggleAltitudeHold()v=false elseif iw=="option7"then wipeSaveVariables()v=false elseif iw=="option8"then ToggleFollowMode()v=false elseif iw=="option9"then if gyro~=nil then gyro.toggle()ah=gyro.getState()==1 end;v=false elseif iw=="lshift"then if system.isViewLocked()==1 then J=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif o()==1 and ShiftShowsRemoteButtons then J=true;b1=false;b0=false end elseif iw=="brake"then if BrakeToggleStatus then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif iw=="lalt"then if o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif iw=="booster"then if VanillaRockets then Nav:toggleBoosters()elseif not O then if not IsRocketOn then Nav:toggleBoosters()IsRocketOn=true end;O=true else if IsRocketOn then Nav:toggleBoosters()IsRocketOn=false end;O=false end elseif iw=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)clearAll()elseif iw=="speedup"then if not J then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)else IncrementAutopilotTargetIndex()end elseif iw=="speeddown"then if not J then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)else DecrementAutopilotTargetIndex()end elseif iw=="antigravity"and not ExternalAGG then if antigrav~=nil then ToggleAntigrav()end end end;function script.onActionStop(iw)if iw=="forward"then B=0 elseif iw=="backward"then B=0 elseif iw=="left"then E=0 elseif iw=="right"then E=0 elseif iw=="yawright"then F=0 elseif iw=="yawleft"then F=0 elseif iw=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)elseif iw=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)elseif iw=="up"then Z=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif iw=="down"then Z=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif iw=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then N=OldAntiMod end;if AltitudeHold then M=OldButtonMod end;v=false elseif iw=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then N=OldAntiMod end;if AltitudeHold then M=OldButtonMod end;v=false elseif iw=="lshift"then if system.isViewLocked()==1 then J=false;a0=0;a1=0;system.lockView(PrevViewLock)elseif o()==1 and ShiftShowsRemoteButtons then J=false;b1=false;b0=false end elseif iw=="brake"then if not BrakeToggleStatus then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif iw=="lalt"then if o()==0 and freeLookToggle then if v then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else v=true end elseif o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end end end;function script.onActionLoop(iw)if iw=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+N;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+N end;N=N*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+M;M=M*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif iw=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end;N=N*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-M;M=M*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif iw=="speedup"then if not J then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end elseif iw=="speeddown"then if not J then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end;function script.onInputText(ix)local i;local iy="/commands /setname /G /agg /addlocation"local iz,iA;local iB="Command List:\n/commands \n/setname - Updates current selected saved position name\n/G VariableName newValue - Updates global variable to new value\n"iB=iB.."/agg - Manually set agg target height\n/addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572} - adds a saved location by waypoint, not as accurate as making one at location"i=string.find(ix," ")if i~=nil then iz=string.sub(ix,0,i-1)iA=string.sub(ix,i+1)elseif i==nil or not string.find(iy,iz)then for f0 in string.gmatch(iB,"([^\n]+)")do c(f0)end;return end;if iz=="/setname"then if iA==nil or iA==""then K="Usage: /setname Newname"return end;if AutopilotTargetIndex>0 and CustomTarget~=nil then UpdatePosition(iA)else K="Select a saved target to rename first"end elseif iz=="/addlocation"then if iA==nil or iA==""or string.find(iA,"::")==nil then K="Usage: /addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572}"return end;i=string.find(iA,"::")local bF=string.sub(iA,1,i-2)local bw=string.sub(iA,i)local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local bx='::pos{'..p..','..p..','..p..','..p..','..p..'}'local by,bz,bA,bB,bC=string.match(bw,bx)local planet=aS[tonumber(by)][tonumber(bz)]AddNewLocationByWaypoint(bF,tonumber(bz),bw)K="Added "..bF.." to saved locations,\nplanet "..planet.name.." at "..bw;a2=5 elseif iz=="/agg"then if iA==nil or iA==""then K="Usage: /agg targetheight"return end;iA=tonumber(iA)if iA<1000 then iA=1000 end;AntigravTargetAltitude=iA;K="AGG Target Height set to "..iA elseif iz=="/G"then if iA==nil or iA==""then K="Usage: /G VariableName variablevalue"return end;i=string.find(iA," ")local iC=string.sub(iA,0,i-1)local iD=string.sub(iA,i+1)for b4,b5 in pairs(a)do if b5==iC then K="Variable "..iC.." changed to "..iD;local iE=type(_G[b5])if iE=="number"then iD=tonumber(iD)elseif iE=="boolean"then if string.lower(iD)=="true"then iD=true else iD=false end end;_G[b5]=iD;return end end;K="No such global variable: "..iC end end;script.onStart() -- error handling code added by wrap.lua diff --git a/ChangeLog.md b/ChangeLog.md index 538850d..1229a92 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,10 @@ ## ChangeLog - Most recent changes at the top +Version 4.921 +- Fixed issue of converting ::pos to WorldCoordinates. /addlocation Name ::waypoint works now +- Provided feedback when adding a waypoint save location. +- Fixed comment on ExtraVerticalTags to say vertical (no change to performance) + Version 4.920 - Support for user input - Implemented user text input. To use, hit tab and hit enter to send messages to Lua Chat. (this will not cause tab fps slideshow if the chat tab is open first) Currently supported commands: - /commands - Shows command list and help diff --git a/src/ButtonHUD.lua b/src/ButtonHUD.lua index 2eae37e..e403a0a 100644 --- a/src/ButtonHUD.lua +++ b/src/ButtonHUD.lua @@ -577,26 +577,51 @@ function AddLocationsToAtlas() -- Just called once during init really UpdateAtlasLocationsList() end -function AddNewLocationByWaypoint(savename, planetnumber, x, y, z) +function zeroConvertToWorldCoordinates(pos) -- Many thanks to SilverZero for this. + local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)' + local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' .. num .. ',' .. num .. '}' + local systemId, bodyId, latitude, longitude, altitude = string.match(pos, posPattern) + longitude = math.rad(longitude) + latitude = math.rad(latitude) + if (systemId == 0 and bodyId == 0) then + return vec3(latitude, + longitude, + altitude) + end + local planet = atlas[tonumber(systemId)][tonumber(bodyId)] + local xproj = math.cos(latitude); + local planetxyz = vec3(xproj*math.cos(longitude), + xproj*math.sin(longitude), + math.sin(latitude)); + return planet.center + (planet.radius + altitude) * planetxyz +end + +function AddNewLocationByWaypoint(savename, planetnumber, pos) if dbHud_1 then local newLocation = {} + local position = zeroConvertToWorldCoordinates(pos) + local planet = atlas[0][planetnumber] if planetnumber == 0 then newLocation = { - position = vec3(x, y, z), + position = position, name = savename, atmosphere = 0, planetname = "Space", gravity = 0 } else - local atmo - if atlas[0][planetnumber].atmos then atmo = 100 else atmo = 0 end + local atmo = false + if planet.atmos then + atmo = true + else + atmo = false + end newLocation = { - position = vec3(x, y, z), + position = position, name = savename, atmosphere = atmo, - planetname = atlas[0][planetnumber].name, - gravity = atlas[0][planetnumber].gravity + planetname = planet.name, + gravity = planet.gravity } end SavedLocations[#SavedLocations + 1] = newLocation @@ -611,6 +636,7 @@ function AddNewLocation() -- Don't call this unless they have a databank or it's -- Add a new location to SavedLocations if dbHud_1 then local position = vec3(core.getConstructWorldPos()) + sprint(position.x.." "..position.y.." "..position.z) local name = planet.name .. ". " .. #SavedLocations if radar_1 then -- Just match the first one @@ -622,7 +648,7 @@ function AddNewLocation() -- Don't call this unless they have a databank or it's local newLocation = { position = position, name = name, - atmosphere = atmosphere(), + atmosphere = inAtmo, planetname = planet.name, gravity = unit.getClosestPlanetInfluence() } @@ -5641,22 +5667,14 @@ function script.onInputText(text) end i = string.find(arguement, "::") local savename = string.sub(arguement, 1, i-2) - i = string.find(arguement, ",") - arguement = string.sub(arguement, i+1) - local j = string.find(arguement,",") - local planetnumber = tonumber(string.sub(arguement, 1, j-1)) - i = string.find(arguement, ",") - arguement = string.sub(arguement, i+1) - j = string.find(arguement,",") - local x = tonumber(string.sub(arguement, 1, j-1)) - i = string.find(arguement, ",") - arguement = string.sub(arguement, i+1) - j = string.find(arguement,",") - local y = tonumber(string.sub(arguement, 1, j-1)) - i = string.find(arguement, ",") - arguement = string.sub(arguement, i+1) - local z = tonumber(string.sub(arguement, 1, #arguement-1)) - AddNewLocationByWaypoint(savename, planetnumber, x, y, z) + local pos = string.sub(arguement, i) + local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)' + local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' .. num .. ',' .. num .. '}' + local systemId, bodyId, latitude, longitude, altitude = string.match(pos, posPattern); + local planet = atlas[tonumber(systemId)][tonumber(bodyId)] + AddNewLocationByWaypoint(savename, tonumber(bodyId), pos) + msgText = "Added "..savename.." to saved locations,\nplanet "..planet.name.." at "..pos + msgTimer = 5 elseif command == "/agg" then if arguement == nil or arguement == "" then msgText = "Usage: /agg targetheight" From bb0c298ec3ab855853bfa591659bad7d2e8ebe39 Mon Sep 17 00:00:00 2001 From: archaegeo Date: Fri, 8 Jan 2021 19:46:26 -0500 Subject: [PATCH 2/2] Version number --- ButtonHUD.conf | 4 ++-- src/ButtonHUD.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ButtonHUD.conf b/ButtonHUD.conf index 1c99a2b..75a9d2a 100644 --- a/ButtonHUD.conf +++ b/ButtonHUD.conf @@ -1,4 +1,4 @@ -name: ButtonsHud - Dimencia and Archaegeo v4.920 (Minified) +name: ButtonsHud - Dimencia and Archaegeo v4.921 (Minified) slots: core: class: CoreUnit @@ -311,7 +311,7 @@ handlers: Keyboard Scheme must be selected]],ConvertResolutionX(960),ConvertResolutionY(600))bO[#bO+1]=e([[ Set your preferred scheme in Lua Parameters instead]],ConvertResolutionX(960),ConvertResolutionY(650))end;local e6=ConvertResolutionX(960)local e7=ConvertResolutionY(860)local e8=ConvertResolutionY(880)local e9=ConvertResolutionY(900)local ea=ConvertResolutionY(960)local eb=ConvertResolutionY(200)local ec=ConvertResolutionY(150)local ed=ConvertResolutionY(960)if o()==1 and not RemoteHud then e7=ConvertResolutionY(135)e8=ConvertResolutionY(155)e9=ConvertResolutionY(175)eb=ConvertResolutionY(115)ec=ConvertResolutionY(95)end;if BrakeIsOn then bO[#bO+1]=e([[Brake Engaged]],e6,e7)end;if ad and RateOfChangebrakeLandingRate+5 then bO[#bO+1]=e([[** STALL WARNING **]],e6,eb+50)end;if ah then bO[#bO+1]=e([[Gyro Enabled]],e6,ed)end;if GearExtended then if A then bO[#bO+1]=e([[Gear Extended]],e6,e8)else bO[#bO+1]=e([[Landed (G: Takeoff)]],e6,e8)end;bO[#bO+1]=e([[Hover Height: %s]],e6,e9,getDistanceDisplayString(Nav:getTargetGroundAltitude()))end;if O then bO[#bO+1]=e([[ROCKET BOOST ENABLED]],e6,ea+20)end;if antigrav and not ExternalAGG and antigrav.getState()==1 and AntigravTargetAltitude~=nil then if math.abs(ae-antigrav.getBaseAltitude())<501 then bO[#bO+1]=e([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],e6,eb+20,d(AntigravTargetAltitude),d(antigrav.getBaseAltitude()))else bO[#bO+1]=e([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],e6,eb+20,d(AntigravTargetAltitude),d(antigrav.getBaseAltitude()))end elseif Autopilot and AutopilotTargetName~="None"then bO[#bO+1]=e([[Autopilot %s]],e6,eb+20,AutopilotStatus)elseif LockPitch~=nil then bO[#bO+1]=e([[LockedPitch: %d]],e6,eb+20,d(LockPitch))elseif I then bO[#bO+1]=e([[Follow Mode Engaged]],e6,eb+20)elseif Reentry then bO[#bO+1]=e([[Parachute Re-entry in Progress]],e6,eb+20)end;if AltitudeHold then if AutoTakeoff then bO[#bO+1]=e([[Ascent to %s]],e6,eb,getDistanceDisplayString(HoldAltitude))if BrakeIsOn then bO[#bO+1]=e([[Throttle Up and Disengage Brake For Takeoff]],e6,eb+50)end else bO[#bO+1]=e([[Altitude Hold: %s]],e6,eb,getDistanceDisplayString2(HoldAltitude))end end;if BrakeLanding then if StrongBrakes then bO[#bO+1]=e([[Brake-Landing]],e6,eb)else bO[#bO+1]=e([[Coast-Landing]],e6,eb)end end;if ProgradeIsOn then bO[#bO+1]=e([[Prograde Alignment]],e6,eb)end;if RetrogradeIsOn then bO[#bO+1]=e([[Retrograde Alignment]],e6,eb)end;if TurnBurn then bO[#bO+1]=e([[Turn & Burn Braking]],e6,ec)end;if VectorToTarget then bO[#bO+1]=e([[%s]],e6,eb+30,VectorStatus)end;bO[#bO+1]=""end;function DisplayOrbitScreen(bO)if orbit~=nil and j()<0.2 and planet~=nil and orbit.apoapsis~=nil and orbit.periapsis~=nil and orbit.period~=nil and orbit.apoapsis.speed>5 and DisplayOrbit then local ee=75;local ef=0;local eg=250;local eh=4;ef=ef+eh;local ei=15;local bn=ee+eg+ee/2+eh;local bo=ef+eg/2+5+eh;local ej,ek,el,em;ej=eg/4;em=0;bO[#bO+1]=[[]]bO[#bO+1]=e('',eg+ee*2,eg+ef,eh,eh)if orbit.periapsis~=nil and orbit.apoapsis~=nil then el=(orbit.apoapsis.altitude+orbit.periapsis.altitude+planet.radius*2)/(ej*2)ek=(planet.radius+orbit.periapsis.altitude+(orbit.apoapsis.altitude-orbit.periapsis.altitude)/2)/el*(1-orbit.eccentricity)em=ej-orbit.periapsis.altitude/el-planet.radius/el;local en=""if orbit.periapsis.altitude<=0 then en='redout'end;bO[#bO+1]=e([[]],en,ee+eg/2+em+eh,ef+eg/2+eh,ej,ek)bO[#bO+1]=e('',ee+eg/2+eh,ef+eg/2+eh,planet.radius/el)end;if orbit.apoapsis~=nil and orbit.apoapsis.speed1 then bO[#bO+1]=e([[]],bn-35,bo-5,ee+eg/2+ej+em,bo-5)bO[#bO+1]=e([[Apoapsis]],bn,bo)bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,getDistanceDisplayString(orbit.apoapsis.altitude))bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,FormatTimeString(orbit.timeToApoapsis))bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,getSpeedDisplayString(orbit.apoapsis.speed))end;bo=ef+eg/2+5+eh;bn=ee-ee/2+10+eh;if orbit.periapsis~=nil and orbit.periapsis.speed1 then bO[#bO+1]=e([[]],bn+35,bo-5,ee+eg/2-ej+em,bo-5)bO[#bO+1]=e([[Periapsis]],bn,bo)bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,getDistanceDisplayString(orbit.periapsis.altitude))bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,FormatTimeString(orbit.timeToPeriapsis))bo=bo+ei;bO[#bO+1]=e([[%s]],bn,bo,getSpeedDisplayString(orbit.periapsis.speed))end;bO[#bO+1]=e([[%s]],ee+eg/2+eh,20+eh,planet.name)if orbit.period~=nil and orbit.periapsis~=nil and orbit.apoapsis~=nil and orbit.apoapsis.speed>1 then local eo=orbit.timeToApoapsis/orbit.period*2*math.pi;local ep=ej*math.cos(eo)local eq=ek*math.sin(eo)bO[#bO+1]=e('',ee+eg/2+ep+em+eh,ef+eg/2+eq+eh)end;bO[#bO+1]=[[]]end end;function getDistanceDisplayString(a3)local er=a3>100000;local b6=""if er then b6=round(a3/1000/200,1).." SU"elseif a3<1000 then b6=round(a3,1).." M"else b6=round(a3/1000,1).." KM"end;return b6 end;function getDistanceDisplayString2(a3)local er=a3>100000;local b6=""if er then b6=round(a3/1000/200,2).." SU"elseif a3<1000 then b6=round(a3,2).." M"else b6=round(a3/1000,2).." KM"end;return b6 end;function getSpeedDisplayString(bh)return d(round(bh*3.6,0)+0.5).." km/h"end;function FormatTimeString(es)local et=0;local eu=0;local ev=0;if es<60 then es=d(es)elseif es<3600 then et=d(es/60)es=d(es%60)elseif es<86400 then eu=d(es/3600)et=d(es%3600/60)else ev=d(es/86400)eu=d(es%86400/60)end;if ev>0 then return ev.."d "..eu.."h "elseif eu>0 then return eu.."h "..et.."m "elseif et>0 then return et.."m "..es.."s"elseif es>0 then return es.."s"else return"0s"end end;function getMagnitudeInDirection(cF,ew)cF=vec3(cF)ew=vec3(ew):normalize()local b6=cF*ew;return b6.x+b6.y+b6.z end;function UpdateAutopilotTarget()if AutopilotTargetIndex==0 then AutopilotTargetName="None"V=nil;return true end;local ex=AtlasOrdered[AutopilotTargetIndex].index;local ey=aS[0][ex]if ey.center then AutopilotTargetName=ey.name;V=aY[0][ex]if CustomTarget~=nil then if j()==0 then if system.updateData(widgetMaxBrakeTimeText,widgetMaxBrakeTime)~=1 then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;if system.updateData(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)~=1 then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;if system.updateData(widgetCurBrakeTimeText,widgetCurBrakeTime)~=1 then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;if system.updateData(widgetCurBrakeDistanceText,widgetCurBrakeDistance)~=1 then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;if system.updateData(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)~=1 then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;if system.updateData(widgetMaxMassText,widgetMaxMass)~=1 then system.addDataToWidget(widgetMaxMassText,widgetMaxMass)end;if system.updateData(widgetTravelTimeText,widgetTravelTime)~=1 then system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)end end;CustomTarget=nil else CustomTarget=ey;for _,b5 in pairs(aY[0])do if b5.name==CustomTarget.planetname then V=b5;AutopilotTargetName=CustomTarget.name;break end end;if system.updateData(widgetMaxMassText,widgetMaxMass)~=1 then system.addDataToWidget(widgetMaxMassText,widgetMaxMass)end;if system.updateData(widgetTravelTimeText,widgetTravelTime)~=1 then system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)end end;AutopilotTargetCoords=vec3(V.center)_,AutopilotEndSpeed=a_(V):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 ez=LastMaxBrakeInAtmo/V:getGravity(V.center+vec3(0,0,1)*V.radius):len()return ez end;function GetAutopilotTravelTime()if not Autopilot then if CustomTarget==nil or CustomTarget.planetname~=planet.name then AutopilotDistance=(V.center-vec3(core.getConstructWorldPos())):len()else AutopilotDistance=(CustomTarget.position-vec3(core.getConstructWorldPos())):len()end end;local velocity=core.getWorldVelocity()local bh=vec3(velocity):len()local eA,eB=aZ.computeDistanceAndTime(vec3(velocity):len(),MaxGameVelocity,n(),Nav:maxForceForward(),warmup,0)local P,Q;if not TurnBurn then P,Q=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else P,Q=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;local _,eC;if not TurnBurn then _,eC=GetAutopilotBrakeDistanceAndTime(bh)else _,eC=GetAutopilotTBBrakeDistanceAndTime(bh)end;local eD=0;local eE=0;if AutopilotCruising or not Autopilot and bh>5 then eE=aZ.computeTravelTime(bh,0,AutopilotDistance)elseif P+eA0 then return aZ.computeDistanceAndTime(bh,AutopilotEndSpeed,n(),0,0,LastMaxBrakeInAtmo-AutopilotPlanetGravity*n())else return 0,0 end end end;function GetAutopilotTBBrakeDistanceAndTime(bh)RefreshLastMaxBrake()return aZ.computeDistanceAndTime(bh,AutopilotEndSpeed,n(),Nav:maxForceForward(),warmup,LastMaxBrake-AutopilotPlanetGravity*n())end;function hoverDetectGround()local eG=-1;local eH=-1;if vBooster then eG=vBooster.distance()end;if hover then eH=hover.distance()end;if eG~=-1 and eH~=-1 then if eGProfileTimeMax then ProfileTimeMax=eN end;if eN0 then local eX=eU:find('identifiedConstructs":%[%]')if eX==nil and perisPanelID==nil then a6=1;ToggleRadarPanel()end;if eX~=nil and perisPanelID~=nil then ToggleRadarPanel()end;if radarPanelID==nil then ToggleRadarPanel()end;a4=e([[Radar: %i contacts]],eV,eW,#eT)local eY={}for b4,b5 in pairs(eT)do if radar_1.hasMatchingTransponder(b5)==1 then eY[#eY+1]=b5 end end;if#eY>0 then local bo=ConvertResolutionY(15)local bn=ConvertResolutionX(1370)a4=e([[%sFriendlies In Range]],a4,bn,bo)for b4,b5 in pairs(eY)do bo=bo+20;a4=e([[%s%s]],a4,bn,bo,radar_1.getConstructName(b5))end end else local eZ;eZ=eU:find('worksInEnvironment":false')if eZ then a4=e([[ Radar: Jammed]],eV,eW)else a4=e([[ - Radar: No Contacts]],eV,eW)end;if radarPanelID~=nil then a6=0;ToggleRadarPanel()end end end end;function DisplayMessage(bO,e_)if e_~="empty"then bO[#bO+1]=[[]]for f0 in string.gmatch(e_,"([^\n]+)")do bO[#bO+1]=e([[%s]],f0)end;bO[#bO+1]=[[]]end;if a2~=0 then unit.setTimer("msgTick",a2)a2=0 end end;function updateDistance()local bc=system.getTime()local velocity=vec3(core.getWorldVelocity())local cZ=vec3(velocity):len()local f1=bc-ag;if cZ>1.38889 then cZ=cZ/1000;local f2=cZ*(bc-ag)TotalDistanceTravelled=TotalDistanceTravelled+f2;W=W+f2 end;X=X+f1;TotalFlightTime=TotalFlightTime+f1;ag=bc 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;function SetupAtlas()aS=Atlas()for b4,b5 in pairs(aS[0])do if av==nil or b5.center.xaw then aw=b5.center.x end;if ax==nil or b5.center.yay then ay=b5.center.y end end;aT=""local f3=1.1*(aw-av)/1920;local f4=1.4*(ay-ax)/1080;for b4,b5 in pairs(aS[0])do local bn=960+b5.center.x/f3;local bo=540+b5.center.y/f4;aT=aT..''if not string.match(b5.name,"Moon")and not string.match(b5.name,"Sanctuary")then aT=aT..""..b5.name..""end end;local bw=vec3(core.getConstructWorldPos())local bn=960+bw.x/f3;local bo=540+bw.y/f4;aT=aT..''aT=aT.."You Are Here"aT=aT..[[]]aU=f3;aV=f4;if screen_2 then screen_2.setHTML(''..aT)local bw=vec3(core.getConstructWorldPos())local bn=960+bw.x/f3;local bo=540+bw.y/f4;aT=''aT=aT.."You Are Here"aW=screen_2.addContent((bn-80)/19.20,(bo-80)/10.80,aT)end end;function PlanetRef()local function f5(f6)return type(f6)=='number'end;local function f7(f6)return type(tonumber(f6))=='number'end;local function f8(f9)return type(f9)=='table'end;local function fa(fb)return type(fb)=='string'end;local function fc(b5)return f8(b5)and f5(b5.x and b5.y and b5.z)end;local function fd(fe)return f8(fe)and f5(fe.latitude and fe.longitude and fe.altitude and fe.bodyId and fe.systemId)end;local ff=math.pi/180;local fg=180/math.pi;local fh=1e-10;local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local bx='::pos{'..p..','..p..','..p..','..p..','..p..'}'local utils=require('cpml.utils')local vec3=require('cpml.vec3')local fi=utils.clamp;local function fj(fk,fl)if fk==0 then return math.abs(fl)<1e-09 end;if fl==0 then return math.abs(fk)<1e-09 end;return math.abs(fk-fl)=0 then local gc=math.sqrt(gb)local gd=ga+gc;local ge=ga-gc;if ge>0 then return g1,gd,ge elseif gd>0 then return g1,gd,nil end end end;return nil,nil,nil end;function fE:closestBody(gf)assert(type(gf)=='table','Invalid coordinates.')local gg,g1;local gh=vec3(gf)for _,gi in pairs(self)do local gj=(gi.center-gh):len2()if not g1 or gj=0 and gn or 2*math.pi+gn;bA=math.pi/2-math.acos(gm.z/a3)end;return setmetatable({latitude=bA,longitude=bB,altitude=bC,bodyId=self.bodyId,systemId=self.planetarySystemId},fA)end;function fr:convertToWorldCoordinates(fD)local gk=fa(fD)and fC(fD)or fD;if gk.bodyId==0 then return vec3(gk.latitude,gk.longitude,gk.altitude)end;assert(fd(gk),'Argument 1 (mapPosition) is not an instance of "MapPosition".')assert(gk.systemId==self.planetarySystemId,'Argument 1 (mapPosition) has a different planetary system ID.')assert(gk.bodyId==self.bodyId,'Argument 1 (mapPosition) has a different planetary body ID.')local bD=math.cos(gk.latitude)return self.center+(self.radius+gk.altitude)*vec3(bD*math.cos(gk.longitude),bD*math.sin(gk.longitude),math.sin(gk.latitude))end;function fr:getAltitude(fy)return(vec3(fy)-self.center):len()-self.radius end;function fr:getDistance(fy)return(vec3(fy)-self.center):len()end;function fr:getGravity(fy)local go=self.center-vec3(fy)local gp=go:len2()return self.GM/gp*go/math.sqrt(gp)end;return setmetatable(aX,{__call=function(_,...)return fM(...)end})end;function Keplers()local vec3=require('cpml.vec3')local PlanetRef=PlanetRef()local function fa(fb)return type(fb)=='string'end;local function f8(f9)return type(f9)=='table'end;local function fj(fk,fl)if fk==0 then return math.abs(fl)<1e-09 end;if fl==0 then return math.abs(fk)<1e-09 end;return math.abs(fk-fl)0 then gG=gF;gH=gG+gA/2 end;if gH>gA then gH=gH-gA end end;return{periapsis={position=gx,speed=gz/gv,circularOrbitSpeed=math.sqrt(gs/gv),altitude=gv-self.body.radius},apoapsis=gy and{position=gy,speed=gz/gw,circularOrbitSpeed=math.sqrt(gs/gw),altitude=gw-self.body.radius},currentVelocity=b5,currentPosition=bw,eccentricity=gu,period=gA,eccentricAnomaly=gC,meanAnomaly=gE,timeToPeriapsis=gG,timeToApoapsis=gH}end;local function gI(gJ)local gi=PlanetRef.BodyParameters(gJ.planetarySystemId,gJ.bodyId,gJ.radius,gJ.center,gJ.GM)return setmetatable({body=gi},Kepler)end;return setmetatable(Kepler,{__call=function(_,...)return gI(...)end})end;function Kinematics()local aZ={}local gK=30000000/3600;local gL=gK*gK;local gM=100;local function gN(b5)return 1/math.sqrt(1-b5*b5/gL)end;function aZ.computeAccelerationTime(gO,gP,gQ)local gR=gK*math.asin(gO/gK)return(gK*math.asin(gQ/gK)-gR)/gP end;function aZ.computeDistanceAndTime(gO,gQ,gS,gT,gU,gV)gU=gU or 0;gV=gV or 0;local gW=gO<=gQ;local gX=gT*(gW and 1 or-1)/gS;local gY=-gV/gS;local gZ=gX+gY;if gW and gZ<=0 or not gW and gZ>=0 then return-1,-1 end;local g_,h0=0,0;if gX~=0 and gU>0 then local gR=math.asin(gO/gK)local h1=math.pi*(gX/2+gY)local h2=gX*gU;local h3=gK*math.pi;local b5=function(f9)local c9=(h1*f9-h2*math.sin(math.pi*f9/2/gU)+h3*gR)/h3;local h4=math.tan(c9)return gK*h4/math.sqrt(h4*h4+1)end;local h5=gW and function(fb)return fb>=gQ end or function(fb)return fb<=gQ end;h0=2*gU;if h5(b5(h0))then local h6=0;while math.abs(h0-h6)>0.5 do local f9=(h0+h6)/2;if h5(b5(f9))then h0=f9 else h6=f9 end end end;local h7=gO;local h8=h0/gM;for h9=1,gM do local bh=b5(h9*h8)g_=g_+(bh+h7)*h8/2;h7=bh end;if h0<2*gU then return g_,h0 end;gO=h7 end;local gR=gK*math.asin(gO/gK)local b7=(gK*math.asin(gQ/gK)-gR)/gZ;local ha=gL*math.cos(gR/gK)/gZ;local a3=ha-gL*math.cos((gZ*b7+gR)/gK)/gZ;return a3+g_,b7+h0 end;function aZ.computeTravelTime(gO,gP,a3)if a3==0 then return 0 end;if gP>0 then local gR=gK*math.asin(gO/gK)local ha=gL*math.cos(gR/gK)/gP;return(gK*math.acos(gP*(ha-a3)/gL)-gR)/gP end;assert(gO>0,'Acceleration and initial speed are both zero.')return a3/gO end;function aZ.lorentz(b5)return gN(b5)end;return aZ end;function script.onStart()VERSION_NUMBER=4.920;SetupComplete=false;beginSetup=coroutine.create(function()Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal,{1000,5000,10000,20000,30000})LoadVariables()coroutine.yield()ProcessElements()coroutine.yield()SetupChecks()SetupButtons()coroutine.yield()SetupAtlas()aX=PlanetRef()aY=aX(Atlas())aZ=Kinematics()a_=Keplers()AddLocationsToAtlas()UpdateAutopilotTarget()coroutine.yield()unit.hide()system.showScreen(1)collectgarbage("collect")unit.setTimer("apTick",apTickRate)unit.setTimer("oneSecond",1)unit.setTimer("tenthSecond",1/10)if UseSatNav then unit.setTimer("fiveSecond",5)end end)end;function script.onStop()_autoconf.hideCategoryPanels()if antigrav~=nil and not ExternalAGG then antigrav.hide()end;if warpdrive~=nil then warpdrive.hide()end;core.hide()Nav.control.switchOffHeadlights()local bI=j()if door and(bI>0 or bI==0 and ae<10000)then for _,b5 in pairs(door)do b5.toggle()end end;if switch then for _,b5 in pairs(switch)do b5.toggle()end end;if forcefield and(bI>0 or bI==0 and ae<10000)then for _,b5 in pairs(forcefield)do b5.toggle()end end;if dbHud_1 then if not Y then for b4,b5 in pairs(b)do dbHud_1.setStringValue(b5,g(_G[b5]))end;for b4,b5 in pairs(a)do dbHud_1.setStringValue(b5,g(_G[b5]))end;c("Saved Variables to Datacore")end end;if button then button.activate()end end;function script.onTick(hb)if hb=="tenthSecond"then if AutopilotTargetName~="None"then if panelInterplanetary==nil then SetupInterplanetaryPanel()end;if AutopilotTargetName~=nil then local hc=CustomTarget~=nil;planetMaxMass=GetAutopilotMaxMass()system.updateData(interplanetaryHeaderText,'{"label": "Target", "value": "'..AutopilotTargetName..'", "unit":""}')travelTime=GetAutopilotTravelTime()if hc then a3=(vec3(core.getConstructWorldPos())-CustomTarget.position):len()else a3=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()end;if not TurnBurn then P,Q=GetAutopilotBrakeDistanceAndTime(velMag)R,S=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else P,Q=GetAutopilotTBBrakeDistanceAndTime(velMag)R,S=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;system.updateData(widgetDistanceText,'{"label": "distance", "value": "'..getDistanceDisplayString(a3)..'", "unit":""}')system.updateData(widgetTravelTimeText,'{"label": "Travel Time", "value": "'..FormatTimeString(travelTime)..'", "unit":""}')system.updateData(widgetCurBrakeDistanceText,'{"label": "Cur Brake distance", "value": "'..getDistanceDisplayString(P)..'", "unit":""}')system.updateData(widgetCurBrakeTimeText,'{"label": "Cur Brake Time", "value": "'..FormatTimeString(Q)..'", "unit":""}')system.updateData(widgetMaxBrakeDistanceText,'{"label": "Max Brake distance", "value": "'..getDistanceDisplayString(R)..'", "unit":""}')system.updateData(widgetMaxBrakeTimeText,'{"label": "Max Brake Time", "value": "'..FormatTimeString(S)..'", "unit":""}')system.updateData(widgetMaxMassText,'{"label": "Maximum Mass", "value": "'..e("%.2f tons",planetMaxMass/1000)..'", "unit":""}')if j()>0 and not WasInAtmo then system.removeDataFromWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)system.removeDataFromWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)system.removeDataFromWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)system.removeDataFromWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)system.removeDataFromWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)WasInAtmo=true end;if j()==0 and WasInAtmo then if system.updateData(widgetMaxBrakeTimeText,widgetMaxBrakeTime)==1 then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;if system.updateData(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)==1 then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;if system.updateData(widgetCurBrakeTimeText,widgetCurBrakeTime)==1 then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;if system.updateData(widgetCurBrakeDistanceText,widgetCurBrakeDistance)==1 then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;if system.updateData(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)==1 then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end;WasInAtmo=false end end else HideInterplanetaryPanel()end;if warpdrive~=nil then if f(warpdrive.getData()).destination~="Unknown"and f(warpdrive.getData()).distance>400000 then warpdrive.show()showWarpWidget=true else warpdrive.hide()showWarpWidget=false end end elseif hb=="oneSecond"then ab=false;RefreshLastMaxBrake(nil,true)updateDistance()updateRadar()updateWeapons()local bO={}local cP=GetFlightStyle()DrawOdometer(bO,W,TotalDistanceTravelled,cP,X)CheckDamage(bO)a5=table.concat(bO,"")collectgarbage("collect")elseif hb=="fiveSecond"then ac=dbHud_1.getStringValue("SPBAutopilotTargetName")if ac~=nil and ac~=""and ac~="SatNavNotChanged"then local b6=json.decode(dbHud_1.getStringValue("SavedLocations"))if b6~=nil then _G["SavedLocations"]=b6;local bM=-1;local bH;for b4,b5 in pairs(SavedLocations)do if b5.name and b5.name=="SatNav Location"then bM=b4;break end end;if bM~=-1 then bH=SavedLocations[bM]bM=-1;for b4,b5 in pairs(aS[0])do if b5.name and b5.name=="SatNav Location"then bM=b4;break end end;if bM>-1 then aS[0][bM]=bH end;UpdateAtlasLocationsList()K=bH.name.." position updated"end end;for i=1,#AtlasOrdered do if AtlasOrdered[i].name==ac then AutopilotTargetIndex=i;system.print("Index = "..AutopilotTargetIndex.." "..AtlasOrdered[i].name)UpdateAutopilotTarget()dbHud_1.setStringValue("SPBAutopilotTargetName","SatNavNotChanged")break end end end elseif hb=="msgTick"then local bO={}DisplayMessage(bO,"empty")K="empty"unit.stopTimer("msgTick")a2=3 elseif hb=="animateTick"then b1=true;b0=false;a0=0;a1=0;unit.stopTimer("animateTick")elseif hb=="apTick"then local o=o;RateOfChange=vec3(core.getConstructWorldOrientationForward()):dot(vec3(core.getWorldVelocity()):normalize())ad=j()>0;D=0;H=0;C=0;LastApsDiff=-1;velocity=vec3(core.getWorldVelocity())velMag=vec3(velocity):len()sys=aY[0]planet=sys:closestBody(core.getConstructWorldPos())kepPlanet=a_(planet)orbit=kepPlanet:orbitalParameters(core.getConstructWorldPos(),velocity)aa=hoverDetectGround()local hd=system.getMouseDeltaX()local he=system.getMouseDeltaY()TargetGroundAltitude=Nav:getTargetGroundAltitude()local hf=velMag>8334;if not hf and LastIsWarping then if not BrakeIsOn then BrakeToggle()end;if Autopilot then ToggleAutopilot()end end;LastIsWarping=hf;if ad and j()>0.09 then if not ai then if velMag>AtmoSpeedLimit/3.6 then BrakeIsOn=true;ai=true end else if velMag]],ResolutionX,ResolutionY)if K~="empty"then DisplayMessage(bO,K)end;if o()==0 and userControlScheme=="virtual joystick"then DrawDeadZone(bO)end;if o()==1 and screen_1 and screen_1.getMouseY()~=-1 then a0=screen_1.getMouseX()*ResolutionX;a1=screen_1.getMouseY()*ResolutionY;SetButtonContains()DrawButtons(bO)if screen_1.getMouseState()==1 then CheckButtons()end;bO[#bO+1]=e([[]],s,t,a0,a1)elseif system.isViewLocked()==0 then if o()==1 and J then if not b0 then a0=a0+hd;a1=a1+he end;SetButtonContains()DrawButtons(bO)if not b0 and not b1 then local hg=table.concat(bO,"")bO={}bO[#bO+1]=e("",ResolutionX,ResolutionY)bO[#bO+1]=aT;bO[#bO+1]=hg;bO[#bO+1]=""b0=true;bO[#bO+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(bO,"")system.setScreen(content)elseif b1 then local hg=table.concat(bO,"")bO={}bO[#bO+1]=e("",ResolutionX,ResolutionY)bO[#bO+1]=aT;bO[#bO+1]=hg;bO[#bO+1]=""end;if not b0 then bO[#bO+1]=e([[]],s,t,a0,a1)end else CheckButtons()a0=0;a1=0 end else a0=a0+hd;a1=a1+he;a3=math.sqrt(a0*a0+a1*a1)if not J and o()==0 then if userControlScheme=="virtual joystick"then if a0>0 and a0>DeadZone then D=D-(a0-DeadZone)*MouseXSensitivity elseif a0<0 and a00 and a1>DeadZone then C=C-(a1-DeadZone)*MouseYSensitivity elseif a1<0 and a1DeadZone then DrawCursorLine(bO)end else SetButtonContains()DrawButtons(bO)end;bO[#bO+1]=e([[]],s,t,a0,a1)end;bO[#bO+1]=[[]]content=table.concat(bO,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end;if ProgradeIsOn then if velMag>w then local hh=AlignToWorldVector(vec3(velocity),0.01)if a7 then b2=true;if hh then ProgradeIsOn=false;x=true;BeginReentry()a7=false;a9=true;b2=autoRollPreference end end end end;if RetrogradeIsOn then if ad then RetrogradeIsOn=false elseif velMag>w then AlignToWorldVector(-vec3(velocity))end end;if not ProgradeIsOn and a7 then if j()==0 then x=true;BeginReentry()a7=false;a9=true else a7=false;ToggleAutopilot()end end;if a9 and aeReentrySpeed-100 then ToggleAutopilot()a9=false end;if Autopilot and j()==0 then local P,Q;if not TurnBurn then P,Q=GetAutopilotBrakeDistanceAndTime(velMag)else P,Q=GetAutopilotTBBrakeDistanceAndTime(velMag)end;P=P;Q=Q;local hi=AutopilotTargetCoords;if orbit.apoapsis==nil and velMag>300 and AutopilotAccelerating then local hj=(vec3(AutopilotTargetCoords)-vec3(core.getConstructWorldPos())):normalize()-vec3(velocity):normalize()local hk=getMagnitudeInDirection(hj,AutopilotShipUp)local hl=getMagnitudeInDirection(hj,AutopilotShipRight)local hm=-hl*AutopilotDistance*velMag*TrajectoryAlignmentStrength;local hn=-hk*AutopilotDistance*velMag*TrajectoryAlignmentStrength;hi=AutopilotTargetCoords+-hm*vec3(AutopilotShipRight)+-hn*vec3(AutopilotShipUp)end;AutopilotDistance=(vec3(hi)-vec3(core.getConstructWorldPos())):len()local ho=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()system.updateData(widgetDistanceText,'{"label": "distance", "value": "'..getDistanceDisplayString(ho)..'", "unit":""}')local hp=true;local hq=(V.center-(vec3(core.getConstructWorldPos())+vec3(velocity):normalize()*AutopilotDistance)):len()-V.radius;system.updateData(widgetTrajectoryAltitudeText,'{"label": "Projected Altitude", "value": "'..getDistanceDisplayString(hq)..'", "unit":""}')if not AutopilotCruising and not AutopilotBraking then hp=AlignToWorldVector((hi-vec3(core.getConstructWorldPos())):normalize())elseif TurnBurn then hp=AlignToWorldVector(-vec3(velocity):normalize())end;if AutopilotAccelerating then if not hp 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)u=false elseif not u then BrakeIsOn=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)u=true end;if vec3(core.getVelocity()):len()>=MaxGameVelocity and math.abs(hq-AutopilotTargetOrbit)<1000 or unit.getThrottle()==0 and u then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)u=false end;if AutopilotDistance<=P then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)u=false end elseif AutopilotBraking then BrakeIsOn=true;G=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>L or orbit.apoapsis.altitude0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if hp then if not AutopilotRealigned then AutopilotTargetCoords=vec3(V.center)+(AutopilotTargetOrbit+V.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotRealigned=true;AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()elseif hp then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not u then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)u=true;BrakeIsOn=false end end end end end;if I then b2=true;local hr=0;local bw=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local hs=bw-vec3(core.getConstructWorldPos())local ht=vec3(hs):project_on(vec3(core.getConstructWorldOrientationForward())):len()local hu=vec3(hs):project_on(vec3(core.getConstructWorldOrientationRight())):len()local a3=math.sqrt(ht*ht+hu*hu)AlignToWorldVector(hs:normalize())local hv=40;local hw=a3hz then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(hr-bU)local hA=pitchPID:get()C=hA end end;local dl=vec3(core.getWorldVertical())*-1;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget or LockPitch~=nil then local d1=unit.getClosestPlanetInfluence()>0;local bC=ae;local hB=HoldAltitude-bC;local hC=500+velMag;local hr=(utils.smoothstep(hB,-hC,hC)-0.5)*2*MaxPitch;if not AltitudeHold then hr=0 end;if LockPitch~=nil then if d1 then hr=LockPitch else LockPitch=nil end end;b2=true;if Reentry then local hD=ReentrySpeed;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=hD then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,hD)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if not x then hr=-80;if j()>0.02 then K="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;hr=0;b2=autoRollPreference end elseif Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==ReentrySpeed then x=false;Reentry=false;b2=autoRollPreference end end;local hE=C;if velMag>w then AlignToWorldVector(vec3(velocity))end;if VectorToTarget and CustomTarget~=nil and AutopilotTargetIndex>0 then local cH=CustomTarget.position-vec3(core.getConstructWorldPos())AlignToWorldVector(cH)local hF=cH:len()-cH:project_on(dl):len()local bi=LastMaxBrakeInAtmo;local dj=velocity.x*dl.x+velocity.y*dl.y+velocity.z*dl.z;local hG=velocity:len()-math.abs(dj)local hH=vec3(core.getWorldAirFrictionAcceleration())if bi~=nil then P,Q=aZ.computeDistanceAndTime(hG,0,n(),0,0,bi+(hH:len()-hH:project_on(dl):len())*n())else P,Q=aZ.computeDistanceAndTime(hG,0,n(),0,0,LastMaxBrake+vec3(core.getWorldAirFrictionAcceleration()):len()*n())end;StrongBrakes=planet.gravity*9.80665*n()LastTargetDistance and not AltitudeHold and not AutoTakeoff then BrakeLanding=true;VectorToTarget=false end;LastTargetDistance=hF end;C=hE;local bR=vec3(core.getConstructWorldOrientationForward())local bS=vec3(core.getConstructWorldOrientationRight())local bT=vec3(core.getWorldVertical())local eI=-1;local bU=getPitch(bT,bR,bS)local hz=0.1;if BrakeLanding then hr=0;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)local dj=velocity.x*dl.x+velocity.y*dl.y+velocity.z*dl.z;eI=aa;if eI>-1 then if math.abs(hr-bU)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(hr-bU)>hz then if pitchPID==nil then pitchPID=pid.new(8*0.01,0,8*0.1)end;pitchPID:inject(hr-bU)local hA=pitchPID:get()C=C+hA end end;L=orbit.eccentricity;if antigrav and not ExternalAGG and ae<200000 then if AntigravTargetAltitude==nil then AntigravTargetAltitude=1000 end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end end end end;function script.onFlush()if antigrav and not ExternalAGG then if antigrav.getState()==0 and antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(AntigravTargetAltitude)end end;local hI=2;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)hI=math.max(hI,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 hJ=utils.clamp(B+C+system.getControlDeviceForwardInput(),-1,1)local hK=utils.clamp(E+H+system.getControlDeviceYawInput(),-1,1)local hL=utils.clamp(F+D-system.getControlDeviceLeftRightInput(),-1,1)local hM=G;local hN=vec3(core.getWorldVertical())local hO=vec3(core.getConstructWorldOrientationUp())local hP=vec3(core.getConstructWorldOrientationForward())local hQ=vec3(core.getConstructWorldOrientationRight())local hR=vec3(core.getWorldVelocity())local hS=vec3(core.getWorldVelocity()):normalize()local hT=getRoll(hN,hP,hQ)local hU=math.abs(hT)local hV=utils.sign(hT)local j=j()local hW=vec3(core.getWorldAngularVelocity())local hX=hJ*pitchSpeedFactor*hQ+hK*rollSpeedFactor*hP+hL*yawSpeedFactor*hO;if hN:len()>0.01 and j>0.0 or ProgradeIsOn then local hY=1.0;if b2==true and hU>hY and hK==0 then local hZ=utils.clamp(0,hU-30,hU+30)if rollPID==nil then rollPID=pid.new(autoRollFactor*0.01,0,autoRollFactor*0.1)end;rollPID:inject(hZ-hT)local h_=rollPID:get()hX=hX+h_*hP end end;if hN:len()>0.01 and j>0.0 then local i0=20.0;if turnAssist==true and hU>i0 and hJ==0 and hL==0 then local i1=turnAssistFactor*0.1;local i2=turnAssistFactor*0.025;local i3=(hU-i0)/(180-i0)*180;local i4=0;if i3<90 then i4=i3/90 elseif i3<180 then i4=(180-i3)/90 end;i4=i4*i4;local i5=-hV*i2*(1.0-i4)local i6=i1*i4;hX=hX+i6*hQ+i5*hO end end;local i7=1;local i8=0;local i9=1;local ia=hI*(hX-hW)local ib=vec3(core.getWorldAirFrictionAngularAcceleration())ia=ia-ib;Nav:setEngineTorqueCommand('torque',ia,i7,'airfoil','','',i9)local ic=-hM*(brakeSpeedFactor*hR+brakeFlatFactor*hS)Nav:setEngineForceCommand('brake',ic)local id=''local ie=vec3()local ig=false;local ih='thrust analog longitudinal 'if ExtraLongitudeTags~="none"then ih=ih..ExtraLongitudeTags end;local ii=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if ii==axisCommandType.byThrottle then local ij=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ih,axisCommandId.longitudinal)Nav:setEngineForceCommand(ih,ij,i7)elseif ii==axisCommandType.byTargetSpeed then local ij=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)id=id..' , '..ih;ie=ie+ij;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then ig=true end end;local ik='thrust analog lateral 'if ExtraLateralTags~="none"then ik=ik..ExtraLateralTags end;local il=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if il==axisCommandType.byThrottle then local im=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ik,axisCommandId.lateral)Nav:setEngineForceCommand(ik,im,i7)elseif il==axisCommandType.byTargetSpeed then local io=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)id=id..' , '..ik;ie=ie+io end;local ip='thrust analog vertical 'if ExtraVerticalTags~="none"then ip=ip..ExtraVerticalTags end;local iq=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if iq==axisCommandType.byThrottle then local ir=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ip,axisCommandId.vertical)if Z~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(ip,ir,i7,'airfoil','ground','',i9)else Nav:setEngineForceCommand(ip,vec3(),i7)Nav:setEngineForceCommand('airfoil vertical',ir,i7,'airfoil','','',i9)Nav:setEngineForceCommand('ground vertical',ir,i7,'ground','','',i9)end elseif iq==axisCommandType.byTargetSpeed then if Z==0 then Nav:setEngineForceCommand('hover',vec3(),i7)end;local is=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)id=id..' , '..ip;ie=ie+is end;if ie:len()>constants.epsilon then if G~=0 or ig or math.abs(hS:dot(hP))<0.95 then id=id..', brake'end;Nav:setEngineForceCommand(id,ie,i8,'','','',i9)end;Nav:setBoosterCommand('rocket_engine')if O and not VanillaRockets then local bh=vec3(core.getVelocity()):len()local it=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local iu=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if bh*3.6>iu*(1-it)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh*3.6=hy*(1-it)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh=hy*(1-it)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh0 or aew then K="WARNING: Insufficient Brakes - Attempting landing anyway"end;Reentry=false;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=true;b2=true;GearExtended=false else BrakeIsOn=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end else Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end elseif iw=="light"then if Nav.control.isAnyHeadlightSwitchedOn()==1 then Nav.control.switchOffHeadlights()else Nav.control.switchOnHeadlights()end elseif iw=="forward"then B=B-1 elseif iw=="backward"then B=B+1 elseif iw=="left"then E=E-1 elseif iw=="right"then E=E+1 elseif iw=="yawright"then F=F-1 elseif iw=="yawleft"then F=F+1 elseif iw=="straferight"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,1.0)elseif iw=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,-1.0)elseif iw=="up"then Z=Z+1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,1.0)elseif iw=="down"then Z=Z-1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,-1.0)elseif iw=="groundaltitudeup"then OldButtonMod=M;OldAntiMod=N;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+N;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+N end else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+M else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif iw=="groundaltitudedown"then OldButtonMod=M;OldAntiMod=N;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-M else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif iw=="option1"then IncrementAutopilotTargetIndex()v=false elseif iw=="option2"then DecrementAutopilotTargetIndex()v=false elseif iw=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;v=false;ToggleWidgets()elseif iw=="option4"then ToggleAutopilot()v=false elseif iw=="option5"then ToggleLockPitch()v=false elseif iw=="option6"then ToggleAltitudeHold()v=false elseif iw=="option7"then wipeSaveVariables()v=false elseif iw=="option8"then ToggleFollowMode()v=false elseif iw=="option9"then if gyro~=nil then gyro.toggle()ah=gyro.getState()==1 end;v=false elseif iw=="lshift"then if system.isViewLocked()==1 then J=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif o()==1 and ShiftShowsRemoteButtons then J=true;b1=false;b0=false end elseif iw=="brake"then if BrakeToggleStatus then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif iw=="lalt"then if o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif iw=="booster"then if VanillaRockets then Nav:toggleBoosters()elseif not O then if not IsRocketOn then Nav:toggleBoosters()IsRocketOn=true end;O=true else if IsRocketOn then Nav:toggleBoosters()IsRocketOn=false end;O=false end elseif iw=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)clearAll()elseif iw=="speedup"then if not J then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)else IncrementAutopilotTargetIndex()end elseif iw=="speeddown"then if not J then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)else DecrementAutopilotTargetIndex()end elseif iw=="antigravity"and not ExternalAGG then if antigrav~=nil then ToggleAntigrav()end end end;function script.onActionStop(iw)if iw=="forward"then B=0 elseif iw=="backward"then B=0 elseif iw=="left"then E=0 elseif iw=="right"then E=0 elseif iw=="yawright"then F=0 elseif iw=="yawleft"then F=0 elseif iw=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)elseif iw=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)elseif iw=="up"then Z=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif iw=="down"then Z=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif iw=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then N=OldAntiMod end;if AltitudeHold then M=OldButtonMod end;v=false elseif iw=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then N=OldAntiMod end;if AltitudeHold then M=OldButtonMod end;v=false elseif iw=="lshift"then if system.isViewLocked()==1 then J=false;a0=0;a1=0;system.lockView(PrevViewLock)elseif o()==1 and ShiftShowsRemoteButtons then J=false;b1=false;b0=false end elseif iw=="brake"then if not BrakeToggleStatus then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif iw=="lalt"then if o()==0 and freeLookToggle then if v then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else v=true end elseif o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end end end;function script.onActionLoop(iw)if iw=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+N;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+N end;N=N*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+M;M=M*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif iw=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end;N=N*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-M;M=M*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif iw=="speedup"then if not J then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end elseif iw=="speeddown"then if not J then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end;function script.onInputText(ix)local i;local iy="/commands /setname /G /agg /addlocation"local iz,iA;local iB="Command List:\n/commands \n/setname - Updates current selected saved position name\n/G VariableName newValue - Updates global variable to new value\n"iB=iB.."/agg - Manually set agg target height\n/addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572} - adds a saved location by waypoint, not as accurate as making one at location"i=string.find(ix," ")if i~=nil then iz=string.sub(ix,0,i-1)iA=string.sub(ix,i+1)elseif i==nil or not string.find(iy,iz)then for f0 in string.gmatch(iB,"([^\n]+)")do c(f0)end;return end;if iz=="/setname"then if iA==nil or iA==""then K="Usage: /setname Newname"return end;if AutopilotTargetIndex>0 and CustomTarget~=nil then UpdatePosition(iA)else K="Select a saved target to rename first"end elseif iz=="/addlocation"then if iA==nil or iA==""or string.find(iA,"::")==nil then K="Usage: /addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572}"return end;i=string.find(iA,"::")local bF=string.sub(iA,1,i-2)local bw=string.sub(iA,i)local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local bx='::pos{'..p..','..p..','..p..','..p..','..p..'}'local by,bz,bA,bB,bC=string.match(bw,bx)local planet=aS[tonumber(by)][tonumber(bz)]AddNewLocationByWaypoint(bF,tonumber(bz),bw)K="Added "..bF.." to saved locations,\nplanet "..planet.name.." at "..bw;a2=5 elseif iz=="/agg"then if iA==nil or iA==""then K="Usage: /agg targetheight"return end;iA=tonumber(iA)if iA<1000 then iA=1000 end;AntigravTargetAltitude=iA;K="AGG Target Height set to "..iA elseif iz=="/G"then if iA==nil or iA==""then K="Usage: /G VariableName variablevalue"return end;i=string.find(iA," ")local iC=string.sub(iA,0,i-1)local iD=string.sub(iA,i+1)for b4,b5 in pairs(a)do if b5==iC then K="Variable "..iC.." changed to "..iD;local iE=type(_G[b5])if iE=="number"then iD=tonumber(iD)elseif iE=="boolean"then if string.lower(iD)=="true"then iD=true else iD=false end end;_G[b5]=iD;return end end;K="No such global variable: "..iC end end;script.onStart() + Radar: No Contacts]],eV,eW)end;if radarPanelID~=nil then a6=0;ToggleRadarPanel()end end end end;function DisplayMessage(bO,e_)if e_~="empty"then bO[#bO+1]=[[]]for f0 in string.gmatch(e_,"([^\n]+)")do bO[#bO+1]=e([[%s]],f0)end;bO[#bO+1]=[[]]end;if a2~=0 then unit.setTimer("msgTick",a2)a2=0 end end;function updateDistance()local bc=system.getTime()local velocity=vec3(core.getWorldVelocity())local cZ=vec3(velocity):len()local f1=bc-ag;if cZ>1.38889 then cZ=cZ/1000;local f2=cZ*(bc-ag)TotalDistanceTravelled=TotalDistanceTravelled+f2;W=W+f2 end;X=X+f1;TotalFlightTime=TotalFlightTime+f1;ag=bc 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;function SetupAtlas()aS=Atlas()for b4,b5 in pairs(aS[0])do if av==nil or b5.center.xaw then aw=b5.center.x end;if ax==nil or b5.center.yay then ay=b5.center.y end end;aT=""local f3=1.1*(aw-av)/1920;local f4=1.4*(ay-ax)/1080;for b4,b5 in pairs(aS[0])do local bn=960+b5.center.x/f3;local bo=540+b5.center.y/f4;aT=aT..''if not string.match(b5.name,"Moon")and not string.match(b5.name,"Sanctuary")then aT=aT..""..b5.name..""end end;local bw=vec3(core.getConstructWorldPos())local bn=960+bw.x/f3;local bo=540+bw.y/f4;aT=aT..''aT=aT.."You Are Here"aT=aT..[[]]aU=f3;aV=f4;if screen_2 then screen_2.setHTML(''..aT)local bw=vec3(core.getConstructWorldPos())local bn=960+bw.x/f3;local bo=540+bw.y/f4;aT=''aT=aT.."You Are Here"aW=screen_2.addContent((bn-80)/19.20,(bo-80)/10.80,aT)end end;function PlanetRef()local function f5(f6)return type(f6)=='number'end;local function f7(f6)return type(tonumber(f6))=='number'end;local function f8(f9)return type(f9)=='table'end;local function fa(fb)return type(fb)=='string'end;local function fc(b5)return f8(b5)and f5(b5.x and b5.y and b5.z)end;local function fd(fe)return f8(fe)and f5(fe.latitude and fe.longitude and fe.altitude and fe.bodyId and fe.systemId)end;local ff=math.pi/180;local fg=180/math.pi;local fh=1e-10;local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local bx='::pos{'..p..','..p..','..p..','..p..','..p..'}'local utils=require('cpml.utils')local vec3=require('cpml.vec3')local fi=utils.clamp;local function fj(fk,fl)if fk==0 then return math.abs(fl)<1e-09 end;if fl==0 then return math.abs(fk)<1e-09 end;return math.abs(fk-fl)=0 then local gc=math.sqrt(gb)local gd=ga+gc;local ge=ga-gc;if ge>0 then return g1,gd,ge elseif gd>0 then return g1,gd,nil end end end;return nil,nil,nil end;function fE:closestBody(gf)assert(type(gf)=='table','Invalid coordinates.')local gg,g1;local gh=vec3(gf)for _,gi in pairs(self)do local gj=(gi.center-gh):len2()if not g1 or gj=0 and gn or 2*math.pi+gn;bA=math.pi/2-math.acos(gm.z/a3)end;return setmetatable({latitude=bA,longitude=bB,altitude=bC,bodyId=self.bodyId,systemId=self.planetarySystemId},fA)end;function fr:convertToWorldCoordinates(fD)local gk=fa(fD)and fC(fD)or fD;if gk.bodyId==0 then return vec3(gk.latitude,gk.longitude,gk.altitude)end;assert(fd(gk),'Argument 1 (mapPosition) is not an instance of "MapPosition".')assert(gk.systemId==self.planetarySystemId,'Argument 1 (mapPosition) has a different planetary system ID.')assert(gk.bodyId==self.bodyId,'Argument 1 (mapPosition) has a different planetary body ID.')local bD=math.cos(gk.latitude)return self.center+(self.radius+gk.altitude)*vec3(bD*math.cos(gk.longitude),bD*math.sin(gk.longitude),math.sin(gk.latitude))end;function fr:getAltitude(fy)return(vec3(fy)-self.center):len()-self.radius end;function fr:getDistance(fy)return(vec3(fy)-self.center):len()end;function fr:getGravity(fy)local go=self.center-vec3(fy)local gp=go:len2()return self.GM/gp*go/math.sqrt(gp)end;return setmetatable(aX,{__call=function(_,...)return fM(...)end})end;function Keplers()local vec3=require('cpml.vec3')local PlanetRef=PlanetRef()local function fa(fb)return type(fb)=='string'end;local function f8(f9)return type(f9)=='table'end;local function fj(fk,fl)if fk==0 then return math.abs(fl)<1e-09 end;if fl==0 then return math.abs(fk)<1e-09 end;return math.abs(fk-fl)0 then gG=gF;gH=gG+gA/2 end;if gH>gA then gH=gH-gA end end;return{periapsis={position=gx,speed=gz/gv,circularOrbitSpeed=math.sqrt(gs/gv),altitude=gv-self.body.radius},apoapsis=gy and{position=gy,speed=gz/gw,circularOrbitSpeed=math.sqrt(gs/gw),altitude=gw-self.body.radius},currentVelocity=b5,currentPosition=bw,eccentricity=gu,period=gA,eccentricAnomaly=gC,meanAnomaly=gE,timeToPeriapsis=gG,timeToApoapsis=gH}end;local function gI(gJ)local gi=PlanetRef.BodyParameters(gJ.planetarySystemId,gJ.bodyId,gJ.radius,gJ.center,gJ.GM)return setmetatable({body=gi},Kepler)end;return setmetatable(Kepler,{__call=function(_,...)return gI(...)end})end;function Kinematics()local aZ={}local gK=30000000/3600;local gL=gK*gK;local gM=100;local function gN(b5)return 1/math.sqrt(1-b5*b5/gL)end;function aZ.computeAccelerationTime(gO,gP,gQ)local gR=gK*math.asin(gO/gK)return(gK*math.asin(gQ/gK)-gR)/gP end;function aZ.computeDistanceAndTime(gO,gQ,gS,gT,gU,gV)gU=gU or 0;gV=gV or 0;local gW=gO<=gQ;local gX=gT*(gW and 1 or-1)/gS;local gY=-gV/gS;local gZ=gX+gY;if gW and gZ<=0 or not gW and gZ>=0 then return-1,-1 end;local g_,h0=0,0;if gX~=0 and gU>0 then local gR=math.asin(gO/gK)local h1=math.pi*(gX/2+gY)local h2=gX*gU;local h3=gK*math.pi;local b5=function(f9)local c9=(h1*f9-h2*math.sin(math.pi*f9/2/gU)+h3*gR)/h3;local h4=math.tan(c9)return gK*h4/math.sqrt(h4*h4+1)end;local h5=gW and function(fb)return fb>=gQ end or function(fb)return fb<=gQ end;h0=2*gU;if h5(b5(h0))then local h6=0;while math.abs(h0-h6)>0.5 do local f9=(h0+h6)/2;if h5(b5(f9))then h0=f9 else h6=f9 end end end;local h7=gO;local h8=h0/gM;for h9=1,gM do local bh=b5(h9*h8)g_=g_+(bh+h7)*h8/2;h7=bh end;if h0<2*gU then return g_,h0 end;gO=h7 end;local gR=gK*math.asin(gO/gK)local b7=(gK*math.asin(gQ/gK)-gR)/gZ;local ha=gL*math.cos(gR/gK)/gZ;local a3=ha-gL*math.cos((gZ*b7+gR)/gK)/gZ;return a3+g_,b7+h0 end;function aZ.computeTravelTime(gO,gP,a3)if a3==0 then return 0 end;if gP>0 then local gR=gK*math.asin(gO/gK)local ha=gL*math.cos(gR/gK)/gP;return(gK*math.acos(gP*(ha-a3)/gL)-gR)/gP end;assert(gO>0,'Acceleration and initial speed are both zero.')return a3/gO end;function aZ.lorentz(b5)return gN(b5)end;return aZ end;function script.onStart()VERSION_NUMBER=4.921;SetupComplete=false;beginSetup=coroutine.create(function()Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal,{1000,5000,10000,20000,30000})LoadVariables()coroutine.yield()ProcessElements()coroutine.yield()SetupChecks()SetupButtons()coroutine.yield()SetupAtlas()aX=PlanetRef()aY=aX(Atlas())aZ=Kinematics()a_=Keplers()AddLocationsToAtlas()UpdateAutopilotTarget()coroutine.yield()unit.hide()system.showScreen(1)collectgarbage("collect")unit.setTimer("apTick",apTickRate)unit.setTimer("oneSecond",1)unit.setTimer("tenthSecond",1/10)if UseSatNav then unit.setTimer("fiveSecond",5)end end)end;function script.onStop()_autoconf.hideCategoryPanels()if antigrav~=nil and not ExternalAGG then antigrav.hide()end;if warpdrive~=nil then warpdrive.hide()end;core.hide()Nav.control.switchOffHeadlights()local bI=j()if door and(bI>0 or bI==0 and ae<10000)then for _,b5 in pairs(door)do b5.toggle()end end;if switch then for _,b5 in pairs(switch)do b5.toggle()end end;if forcefield and(bI>0 or bI==0 and ae<10000)then for _,b5 in pairs(forcefield)do b5.toggle()end end;if dbHud_1 then if not Y then for b4,b5 in pairs(b)do dbHud_1.setStringValue(b5,g(_G[b5]))end;for b4,b5 in pairs(a)do dbHud_1.setStringValue(b5,g(_G[b5]))end;c("Saved Variables to Datacore")end end;if button then button.activate()end end;function script.onTick(hb)if hb=="tenthSecond"then if AutopilotTargetName~="None"then if panelInterplanetary==nil then SetupInterplanetaryPanel()end;if AutopilotTargetName~=nil then local hc=CustomTarget~=nil;planetMaxMass=GetAutopilotMaxMass()system.updateData(interplanetaryHeaderText,'{"label": "Target", "value": "'..AutopilotTargetName..'", "unit":""}')travelTime=GetAutopilotTravelTime()if hc then a3=(vec3(core.getConstructWorldPos())-CustomTarget.position):len()else a3=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()end;if not TurnBurn then P,Q=GetAutopilotBrakeDistanceAndTime(velMag)R,S=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else P,Q=GetAutopilotTBBrakeDistanceAndTime(velMag)R,S=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;system.updateData(widgetDistanceText,'{"label": "distance", "value": "'..getDistanceDisplayString(a3)..'", "unit":""}')system.updateData(widgetTravelTimeText,'{"label": "Travel Time", "value": "'..FormatTimeString(travelTime)..'", "unit":""}')system.updateData(widgetCurBrakeDistanceText,'{"label": "Cur Brake distance", "value": "'..getDistanceDisplayString(P)..'", "unit":""}')system.updateData(widgetCurBrakeTimeText,'{"label": "Cur Brake Time", "value": "'..FormatTimeString(Q)..'", "unit":""}')system.updateData(widgetMaxBrakeDistanceText,'{"label": "Max Brake distance", "value": "'..getDistanceDisplayString(R)..'", "unit":""}')system.updateData(widgetMaxBrakeTimeText,'{"label": "Max Brake Time", "value": "'..FormatTimeString(S)..'", "unit":""}')system.updateData(widgetMaxMassText,'{"label": "Maximum Mass", "value": "'..e("%.2f tons",planetMaxMass/1000)..'", "unit":""}')if j()>0 and not WasInAtmo then system.removeDataFromWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)system.removeDataFromWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)system.removeDataFromWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)system.removeDataFromWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)system.removeDataFromWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)WasInAtmo=true end;if j()==0 and WasInAtmo then if system.updateData(widgetMaxBrakeTimeText,widgetMaxBrakeTime)==1 then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;if system.updateData(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)==1 then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;if system.updateData(widgetCurBrakeTimeText,widgetCurBrakeTime)==1 then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;if system.updateData(widgetCurBrakeDistanceText,widgetCurBrakeDistance)==1 then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;if system.updateData(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)==1 then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end;WasInAtmo=false end end else HideInterplanetaryPanel()end;if warpdrive~=nil then if f(warpdrive.getData()).destination~="Unknown"and f(warpdrive.getData()).distance>400000 then warpdrive.show()showWarpWidget=true else warpdrive.hide()showWarpWidget=false end end elseif hb=="oneSecond"then ab=false;RefreshLastMaxBrake(nil,true)updateDistance()updateRadar()updateWeapons()local bO={}local cP=GetFlightStyle()DrawOdometer(bO,W,TotalDistanceTravelled,cP,X)CheckDamage(bO)a5=table.concat(bO,"")collectgarbage("collect")elseif hb=="fiveSecond"then ac=dbHud_1.getStringValue("SPBAutopilotTargetName")if ac~=nil and ac~=""and ac~="SatNavNotChanged"then local b6=json.decode(dbHud_1.getStringValue("SavedLocations"))if b6~=nil then _G["SavedLocations"]=b6;local bM=-1;local bH;for b4,b5 in pairs(SavedLocations)do if b5.name and b5.name=="SatNav Location"then bM=b4;break end end;if bM~=-1 then bH=SavedLocations[bM]bM=-1;for b4,b5 in pairs(aS[0])do if b5.name and b5.name=="SatNav Location"then bM=b4;break end end;if bM>-1 then aS[0][bM]=bH end;UpdateAtlasLocationsList()K=bH.name.." position updated"end end;for i=1,#AtlasOrdered do if AtlasOrdered[i].name==ac then AutopilotTargetIndex=i;system.print("Index = "..AutopilotTargetIndex.." "..AtlasOrdered[i].name)UpdateAutopilotTarget()dbHud_1.setStringValue("SPBAutopilotTargetName","SatNavNotChanged")break end end end elseif hb=="msgTick"then local bO={}DisplayMessage(bO,"empty")K="empty"unit.stopTimer("msgTick")a2=3 elseif hb=="animateTick"then b1=true;b0=false;a0=0;a1=0;unit.stopTimer("animateTick")elseif hb=="apTick"then local o=o;RateOfChange=vec3(core.getConstructWorldOrientationForward()):dot(vec3(core.getWorldVelocity()):normalize())ad=j()>0;D=0;H=0;C=0;LastApsDiff=-1;velocity=vec3(core.getWorldVelocity())velMag=vec3(velocity):len()sys=aY[0]planet=sys:closestBody(core.getConstructWorldPos())kepPlanet=a_(planet)orbit=kepPlanet:orbitalParameters(core.getConstructWorldPos(),velocity)aa=hoverDetectGround()local hd=system.getMouseDeltaX()local he=system.getMouseDeltaY()TargetGroundAltitude=Nav:getTargetGroundAltitude()local hf=velMag>8334;if not hf and LastIsWarping then if not BrakeIsOn then BrakeToggle()end;if Autopilot then ToggleAutopilot()end end;LastIsWarping=hf;if ad and j()>0.09 then if not ai then if velMag>AtmoSpeedLimit/3.6 then BrakeIsOn=true;ai=true end else if velMag]],ResolutionX,ResolutionY)if K~="empty"then DisplayMessage(bO,K)end;if o()==0 and userControlScheme=="virtual joystick"then DrawDeadZone(bO)end;if o()==1 and screen_1 and screen_1.getMouseY()~=-1 then a0=screen_1.getMouseX()*ResolutionX;a1=screen_1.getMouseY()*ResolutionY;SetButtonContains()DrawButtons(bO)if screen_1.getMouseState()==1 then CheckButtons()end;bO[#bO+1]=e([[]],s,t,a0,a1)elseif system.isViewLocked()==0 then if o()==1 and J then if not b0 then a0=a0+hd;a1=a1+he end;SetButtonContains()DrawButtons(bO)if not b0 and not b1 then local hg=table.concat(bO,"")bO={}bO[#bO+1]=e("",ResolutionX,ResolutionY)bO[#bO+1]=aT;bO[#bO+1]=hg;bO[#bO+1]=""b0=true;bO[#bO+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(bO,"")system.setScreen(content)elseif b1 then local hg=table.concat(bO,"")bO={}bO[#bO+1]=e("",ResolutionX,ResolutionY)bO[#bO+1]=aT;bO[#bO+1]=hg;bO[#bO+1]=""end;if not b0 then bO[#bO+1]=e([[]],s,t,a0,a1)end else CheckButtons()a0=0;a1=0 end else a0=a0+hd;a1=a1+he;a3=math.sqrt(a0*a0+a1*a1)if not J and o()==0 then if userControlScheme=="virtual joystick"then if a0>0 and a0>DeadZone then D=D-(a0-DeadZone)*MouseXSensitivity elseif a0<0 and a00 and a1>DeadZone then C=C-(a1-DeadZone)*MouseYSensitivity elseif a1<0 and a1DeadZone then DrawCursorLine(bO)end else SetButtonContains()DrawButtons(bO)end;bO[#bO+1]=e([[]],s,t,a0,a1)end;bO[#bO+1]=[[]]content=table.concat(bO,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end;if ProgradeIsOn then if velMag>w then local hh=AlignToWorldVector(vec3(velocity),0.01)if a7 then b2=true;if hh then ProgradeIsOn=false;x=true;BeginReentry()a7=false;a9=true;b2=autoRollPreference end end end end;if RetrogradeIsOn then if ad then RetrogradeIsOn=false elseif velMag>w then AlignToWorldVector(-vec3(velocity))end end;if not ProgradeIsOn and a7 then if j()==0 then x=true;BeginReentry()a7=false;a9=true else a7=false;ToggleAutopilot()end end;if a9 and aeReentrySpeed-100 then ToggleAutopilot()a9=false end;if Autopilot and j()==0 then local P,Q;if not TurnBurn then P,Q=GetAutopilotBrakeDistanceAndTime(velMag)else P,Q=GetAutopilotTBBrakeDistanceAndTime(velMag)end;P=P;Q=Q;local hi=AutopilotTargetCoords;if orbit.apoapsis==nil and velMag>300 and AutopilotAccelerating then local hj=(vec3(AutopilotTargetCoords)-vec3(core.getConstructWorldPos())):normalize()-vec3(velocity):normalize()local hk=getMagnitudeInDirection(hj,AutopilotShipUp)local hl=getMagnitudeInDirection(hj,AutopilotShipRight)local hm=-hl*AutopilotDistance*velMag*TrajectoryAlignmentStrength;local hn=-hk*AutopilotDistance*velMag*TrajectoryAlignmentStrength;hi=AutopilotTargetCoords+-hm*vec3(AutopilotShipRight)+-hn*vec3(AutopilotShipUp)end;AutopilotDistance=(vec3(hi)-vec3(core.getConstructWorldPos())):len()local ho=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()system.updateData(widgetDistanceText,'{"label": "distance", "value": "'..getDistanceDisplayString(ho)..'", "unit":""}')local hp=true;local hq=(V.center-(vec3(core.getConstructWorldPos())+vec3(velocity):normalize()*AutopilotDistance)):len()-V.radius;system.updateData(widgetTrajectoryAltitudeText,'{"label": "Projected Altitude", "value": "'..getDistanceDisplayString(hq)..'", "unit":""}')if not AutopilotCruising and not AutopilotBraking then hp=AlignToWorldVector((hi-vec3(core.getConstructWorldPos())):normalize())elseif TurnBurn then hp=AlignToWorldVector(-vec3(velocity):normalize())end;if AutopilotAccelerating then if not hp 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)u=false elseif not u then BrakeIsOn=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)u=true end;if vec3(core.getVelocity()):len()>=MaxGameVelocity and math.abs(hq-AutopilotTargetOrbit)<1000 or unit.getThrottle()==0 and u then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)u=false end;if AutopilotDistance<=P then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)u=false end elseif AutopilotBraking then BrakeIsOn=true;G=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>L or orbit.apoapsis.altitude0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if hp then if not AutopilotRealigned then AutopilotTargetCoords=vec3(V.center)+(AutopilotTargetOrbit+V.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotRealigned=true;AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()elseif hp then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not u then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)u=true;BrakeIsOn=false end end end end end;if I then b2=true;local hr=0;local bw=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local hs=bw-vec3(core.getConstructWorldPos())local ht=vec3(hs):project_on(vec3(core.getConstructWorldOrientationForward())):len()local hu=vec3(hs):project_on(vec3(core.getConstructWorldOrientationRight())):len()local a3=math.sqrt(ht*ht+hu*hu)AlignToWorldVector(hs:normalize())local hv=40;local hw=a3hz then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(hr-bU)local hA=pitchPID:get()C=hA end end;local dl=vec3(core.getWorldVertical())*-1;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget or LockPitch~=nil then local d1=unit.getClosestPlanetInfluence()>0;local bC=ae;local hB=HoldAltitude-bC;local hC=500+velMag;local hr=(utils.smoothstep(hB,-hC,hC)-0.5)*2*MaxPitch;if not AltitudeHold then hr=0 end;if LockPitch~=nil then if d1 then hr=LockPitch else LockPitch=nil end end;b2=true;if Reentry then local hD=ReentrySpeed;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=hD then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,hD)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if not x then hr=-80;if j()>0.02 then K="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;hr=0;b2=autoRollPreference end elseif Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==ReentrySpeed then x=false;Reentry=false;b2=autoRollPreference end end;local hE=C;if velMag>w then AlignToWorldVector(vec3(velocity))end;if VectorToTarget and CustomTarget~=nil and AutopilotTargetIndex>0 then local cH=CustomTarget.position-vec3(core.getConstructWorldPos())AlignToWorldVector(cH)local hF=cH:len()-cH:project_on(dl):len()local bi=LastMaxBrakeInAtmo;local dj=velocity.x*dl.x+velocity.y*dl.y+velocity.z*dl.z;local hG=velocity:len()-math.abs(dj)local hH=vec3(core.getWorldAirFrictionAcceleration())if bi~=nil then P,Q=aZ.computeDistanceAndTime(hG,0,n(),0,0,bi+(hH:len()-hH:project_on(dl):len())*n())else P,Q=aZ.computeDistanceAndTime(hG,0,n(),0,0,LastMaxBrake+vec3(core.getWorldAirFrictionAcceleration()):len()*n())end;StrongBrakes=planet.gravity*9.80665*n()LastTargetDistance and not AltitudeHold and not AutoTakeoff then BrakeLanding=true;VectorToTarget=false end;LastTargetDistance=hF end;C=hE;local bR=vec3(core.getConstructWorldOrientationForward())local bS=vec3(core.getConstructWorldOrientationRight())local bT=vec3(core.getWorldVertical())local eI=-1;local bU=getPitch(bT,bR,bS)local hz=0.1;if BrakeLanding then hr=0;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)local dj=velocity.x*dl.x+velocity.y*dl.y+velocity.z*dl.z;eI=aa;if eI>-1 then if math.abs(hr-bU)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(hr-bU)>hz then if pitchPID==nil then pitchPID=pid.new(8*0.01,0,8*0.1)end;pitchPID:inject(hr-bU)local hA=pitchPID:get()C=C+hA end end;L=orbit.eccentricity;if antigrav and not ExternalAGG and ae<200000 then if AntigravTargetAltitude==nil then AntigravTargetAltitude=1000 end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end end end end;function script.onFlush()if antigrav and not ExternalAGG then if antigrav.getState()==0 and antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(AntigravTargetAltitude)end end;local hI=2;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)hI=math.max(hI,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 hJ=utils.clamp(B+C+system.getControlDeviceForwardInput(),-1,1)local hK=utils.clamp(E+H+system.getControlDeviceYawInput(),-1,1)local hL=utils.clamp(F+D-system.getControlDeviceLeftRightInput(),-1,1)local hM=G;local hN=vec3(core.getWorldVertical())local hO=vec3(core.getConstructWorldOrientationUp())local hP=vec3(core.getConstructWorldOrientationForward())local hQ=vec3(core.getConstructWorldOrientationRight())local hR=vec3(core.getWorldVelocity())local hS=vec3(core.getWorldVelocity()):normalize()local hT=getRoll(hN,hP,hQ)local hU=math.abs(hT)local hV=utils.sign(hT)local j=j()local hW=vec3(core.getWorldAngularVelocity())local hX=hJ*pitchSpeedFactor*hQ+hK*rollSpeedFactor*hP+hL*yawSpeedFactor*hO;if hN:len()>0.01 and j>0.0 or ProgradeIsOn then local hY=1.0;if b2==true and hU>hY and hK==0 then local hZ=utils.clamp(0,hU-30,hU+30)if rollPID==nil then rollPID=pid.new(autoRollFactor*0.01,0,autoRollFactor*0.1)end;rollPID:inject(hZ-hT)local h_=rollPID:get()hX=hX+h_*hP end end;if hN:len()>0.01 and j>0.0 then local i0=20.0;if turnAssist==true and hU>i0 and hJ==0 and hL==0 then local i1=turnAssistFactor*0.1;local i2=turnAssistFactor*0.025;local i3=(hU-i0)/(180-i0)*180;local i4=0;if i3<90 then i4=i3/90 elseif i3<180 then i4=(180-i3)/90 end;i4=i4*i4;local i5=-hV*i2*(1.0-i4)local i6=i1*i4;hX=hX+i6*hQ+i5*hO end end;local i7=1;local i8=0;local i9=1;local ia=hI*(hX-hW)local ib=vec3(core.getWorldAirFrictionAngularAcceleration())ia=ia-ib;Nav:setEngineTorqueCommand('torque',ia,i7,'airfoil','','',i9)local ic=-hM*(brakeSpeedFactor*hR+brakeFlatFactor*hS)Nav:setEngineForceCommand('brake',ic)local id=''local ie=vec3()local ig=false;local ih='thrust analog longitudinal 'if ExtraLongitudeTags~="none"then ih=ih..ExtraLongitudeTags end;local ii=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if ii==axisCommandType.byThrottle then local ij=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ih,axisCommandId.longitudinal)Nav:setEngineForceCommand(ih,ij,i7)elseif ii==axisCommandType.byTargetSpeed then local ij=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)id=id..' , '..ih;ie=ie+ij;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then ig=true end end;local ik='thrust analog lateral 'if ExtraLateralTags~="none"then ik=ik..ExtraLateralTags end;local il=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if il==axisCommandType.byThrottle then local im=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ik,axisCommandId.lateral)Nav:setEngineForceCommand(ik,im,i7)elseif il==axisCommandType.byTargetSpeed then local io=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)id=id..' , '..ik;ie=ie+io end;local ip='thrust analog vertical 'if ExtraVerticalTags~="none"then ip=ip..ExtraVerticalTags end;local iq=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if iq==axisCommandType.byThrottle then local ir=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(ip,axisCommandId.vertical)if Z~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(ip,ir,i7,'airfoil','ground','',i9)else Nav:setEngineForceCommand(ip,vec3(),i7)Nav:setEngineForceCommand('airfoil vertical',ir,i7,'airfoil','','',i9)Nav:setEngineForceCommand('ground vertical',ir,i7,'ground','','',i9)end elseif iq==axisCommandType.byTargetSpeed then if Z==0 then Nav:setEngineForceCommand('hover',vec3(),i7)end;local is=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)id=id..' , '..ip;ie=ie+is end;if ie:len()>constants.epsilon then if G~=0 or ig or math.abs(hS:dot(hP))<0.95 then id=id..', brake'end;Nav:setEngineForceCommand(id,ie,i8,'','','',i9)end;Nav:setBoosterCommand('rocket_engine')if O and not VanillaRockets then local bh=vec3(core.getVelocity()):len()local it=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local iu=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if bh*3.6>iu*(1-it)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh*3.6=hy*(1-it)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh=hy*(1-it)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bh0 or aew then K="WARNING: Insufficient Brakes - Attempting landing anyway"end;Reentry=false;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=true;b2=true;GearExtended=false else BrakeIsOn=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end else Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end elseif iw=="light"then if Nav.control.isAnyHeadlightSwitchedOn()==1 then Nav.control.switchOffHeadlights()else Nav.control.switchOnHeadlights()end elseif iw=="forward"then B=B-1 elseif iw=="backward"then B=B+1 elseif iw=="left"then E=E-1 elseif iw=="right"then E=E+1 elseif iw=="yawright"then F=F-1 elseif iw=="yawleft"then F=F+1 elseif iw=="straferight"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,1.0)elseif iw=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,-1.0)elseif iw=="up"then Z=Z+1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,1.0)elseif iw=="down"then Z=Z-1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,-1.0)elseif iw=="groundaltitudeup"then OldButtonMod=M;OldAntiMod=N;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+N;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+N end else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+M else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif iw=="groundaltitudedown"then OldButtonMod=M;OldAntiMod=N;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-M else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif iw=="option1"then IncrementAutopilotTargetIndex()v=false elseif iw=="option2"then DecrementAutopilotTargetIndex()v=false elseif iw=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;v=false;ToggleWidgets()elseif iw=="option4"then ToggleAutopilot()v=false elseif iw=="option5"then ToggleLockPitch()v=false elseif iw=="option6"then ToggleAltitudeHold()v=false elseif iw=="option7"then wipeSaveVariables()v=false elseif iw=="option8"then ToggleFollowMode()v=false elseif iw=="option9"then if gyro~=nil then gyro.toggle()ah=gyro.getState()==1 end;v=false elseif iw=="lshift"then if system.isViewLocked()==1 then J=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif o()==1 and ShiftShowsRemoteButtons then J=true;b1=false;b0=false end elseif iw=="brake"then if BrakeToggleStatus then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif iw=="lalt"then if o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif iw=="booster"then if VanillaRockets then Nav:toggleBoosters()elseif not O then if not IsRocketOn then Nav:toggleBoosters()IsRocketOn=true end;O=true else if IsRocketOn then Nav:toggleBoosters()IsRocketOn=false end;O=false end elseif iw=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)clearAll()elseif iw=="speedup"then if not J then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)else IncrementAutopilotTargetIndex()end elseif iw=="speeddown"then if not J then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)else DecrementAutopilotTargetIndex()end elseif iw=="antigravity"and not ExternalAGG then if antigrav~=nil then ToggleAntigrav()end end end;function script.onActionStop(iw)if iw=="forward"then B=0 elseif iw=="backward"then B=0 elseif iw=="left"then E=0 elseif iw=="right"then E=0 elseif iw=="yawright"then F=0 elseif iw=="yawleft"then F=0 elseif iw=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)elseif iw=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)elseif iw=="up"then Z=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif iw=="down"then Z=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif iw=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then N=OldAntiMod end;if AltitudeHold then M=OldButtonMod end;v=false elseif iw=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then N=OldAntiMod end;if AltitudeHold then M=OldButtonMod end;v=false elseif iw=="lshift"then if system.isViewLocked()==1 then J=false;a0=0;a1=0;system.lockView(PrevViewLock)elseif o()==1 and ShiftShowsRemoteButtons then J=false;b1=false;b0=false end elseif iw=="brake"then if not BrakeToggleStatus then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif iw=="lalt"then if o()==0 and freeLookToggle then if v then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else v=true end elseif o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end end end;function script.onActionLoop(iw)if iw=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+N;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+N end;N=N*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+M;M=M*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif iw=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-N;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end;N=N*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-M;M=M*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif iw=="speedup"then if not J then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end elseif iw=="speeddown"then if not J then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end;function script.onInputText(ix)local i;local iy="/commands /setname /G /agg /addlocation"local iz,iA;local iB="Command List:\n/commands \n/setname - Updates current selected saved position name\n/G VariableName newValue - Updates global variable to new value\n"iB=iB.."/agg - Manually set agg target height\n/addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572} - adds a saved location by waypoint, not as accurate as making one at location"i=string.find(ix," ")if i~=nil then iz=string.sub(ix,0,i-1)iA=string.sub(ix,i+1)elseif i==nil or not string.find(iy,iz)then for f0 in string.gmatch(iB,"([^\n]+)")do c(f0)end;return end;if iz=="/setname"then if iA==nil or iA==""then K="Usage: /setname Newname"return end;if AutopilotTargetIndex>0 and CustomTarget~=nil then UpdatePosition(iA)else K="Select a saved target to rename first"end elseif iz=="/addlocation"then if iA==nil or iA==""or string.find(iA,"::")==nil then K="Usage: /addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572}"return end;i=string.find(iA,"::")local bF=string.sub(iA,1,i-2)local bw=string.sub(iA,i)local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local bx='::pos{'..p..','..p..','..p..','..p..','..p..'}'local by,bz,bA,bB,bC=string.match(bw,bx)local planet=aS[tonumber(by)][tonumber(bz)]AddNewLocationByWaypoint(bF,tonumber(bz),bw)K="Added "..bF.." to saved locations,\nplanet "..planet.name.." at "..bw;a2=5 elseif iz=="/agg"then if iA==nil or iA==""then K="Usage: /agg targetheight"return end;iA=tonumber(iA)if iA<1000 then iA=1000 end;AntigravTargetAltitude=iA;K="AGG Target Height set to "..iA elseif iz=="/G"then if iA==nil or iA==""then K="Usage: /G VariableName variablevalue"return end;i=string.find(iA," ")local iC=string.sub(iA,0,i-1)local iD=string.sub(iA,i+1)for b4,b5 in pairs(a)do if b5==iC then K="Variable "..iC.." changed to "..iD;local iE=type(_G[b5])if iE=="number"then iD=tonumber(iD)elseif iE=="boolean"then if string.lower(iD)=="true"then iD=true else iD=false end end;_G[b5]=iD;return end end;K="No such global variable: "..iC end end;script.onStart() -- error handling code added by wrap.lua diff --git a/src/ButtonHUD.lua b/src/ButtonHUD.lua index e403a0a..55c7244 100644 --- a/src/ButtonHUD.lua +++ b/src/ButtonHUD.lua @@ -4182,7 +4182,7 @@ end -- Start of actual HUD Script. Written by Dimencia and Archaegeo. Optimization and Automation of scripting by ChronosWS Linked sources where appropriate, most have been modified. function script.onStart() - VERSION_NUMBER = 4.920 + VERSION_NUMBER = 4.921 SetupComplete = false beginSetup = coroutine.create(function() Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal,