diff --git a/ButtonHUD.conf b/ButtonHUD.conf index 75a9d2a..88dcf30 100644 --- a/ButtonHUD.conf +++ b/ButtonHUD.conf @@ -1,4 +1,4 @@ -name: ButtonsHud - Dimencia and Archaegeo v4.921 (Minified) +name: ButtonsHud - Dimencia and Archaegeo v4.922 (Minified) slots: core: class: CoreUnit @@ -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][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([[ + 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;SpaceTarget=false;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={"SpaceTarget","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][bL]=bG end;UpdateAtlasLocationsList()K=CustomTarget.name.." position updated"AutopilotTargetIndex=0;UpdateAutopilotTarget()else K="Name Not Found"end end;function ClearCurrentPosition()local bL=-1;for b4,b5 in pairs(aS[0])do if b5.name and b5.name==CustomTarget.name then bL=b4 end end;if bL>-1 then table.remove(aS[0],bL)end;bL=-1;for b4,b5 in pairs(SavedLocations)do if b5.name and b5.name==CustomTarget.name then K=b5.name.." saved location cleared"bL=b4;break end end;if bL~=-1 then table.remove(SavedLocations,bL)end;DecrementAutopilotTargetIndex()UpdateAtlasLocationsList()end;function DrawDeadZone(bN)bN[#bN+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(bO,bP,bn,bo,bl,bm)if bO>bn and bObo and bPw 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 bQ=vec3(core.getConstructWorldOrientationForward())local bR=vec3(core.getConstructWorldOrientationRight())local bS=vec3(core.getWorldVertical())local bT=getPitch(bS,bQ,bR)LockPitch=bT;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 and not a8 then if CustomTarget~=nil then LockPitch=nil;SpaceTarget=CustomTarget.planetname=="Space"if SpaceTarget then a8=true;if j()~=0 then ToggleAltitudeHold()else Autopilot=true end elseif 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(SpaceTarget)end else if not VectorToTarget then ToggleVectorToTarget(SpaceTarget)end end else if ae>100000 or ae==0 then a8=true;Autopilot=true else a7=true end 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 a8=false;Autopilot=false;AutopilotRealigned=false;VectorToTarget=false;u=false;AutoTakeoff=false;AltitudeHold=false;VectorToTarget=false;HoldAltitude=ae 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(bN)local bU=0;ao=""local bV=aG;local bW=0;local bX=0;local bY=0;local bZ=0;local b_=""for b4 in pairs(af)do local ba=0;local c0=0;c0=h(af[b4])ba=k(af[b4])bW=bW+ba;if ba0 and al[11]==af[b4]then for c2 in pairs(al)do core.deleteSticker(al[c2])end;al={}end end;bU=d(bW/bV*100)if bU<100 then bN[#bN+1]=[[]]bZ=d(bU*2.55)b_=e("rgb(%d,%d,%d)",255-bZ,bZ,0)if bU<100 then bN[#bN+1]=e([[Elemental Integrity: %i %%]],b_,bU)if bY>0 then bN[#bN+1]=e([[Disabled Modules: %i Damaged Modules: %i]],b_,bY,bX)elseif bX>0 then bN[#bN+1]=e([[Damaged Modules: %i]],b_,bX)end end;bN[#bN+1]=[[<\g>]]end end;function DrawCursorLine(bN)local c3=d(utils.clamp(a3/(at/4)*255,0,255))bN[#bN+1]=e("",a0,a1,d(PrimaryR+0.5)+c3,d(PrimaryG+0.5)-c3,d(PrimaryB+0.5)-c3)end;function getPitch(c4,c5,bv)local c6=c4:cross(bv):normalize_inplace()local bT=math.acos(utils.clamp(c6:dot(-c5),-1,1))*constants.rad2deg;if c6:cross(-c5):dot(bv)<0 then bT=-bT end;return bT 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(bN,c7,hover,bn,bo,c8,c9,ca,cb,cc,cd)if type(cc)=="function"then cc=cc()end;if type(cd)=="function"then cd=cd()end;bN[#bN+1]=e(""if c7 then bN[#bN+1]=e("%s",cc)else bN[#bN+1]=e("%s",cd)end end;function DrawButtons(bN)local ce="rgb(50,50,50)'"local cf="rgb(210,200,200)"local cg=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 cg(bN,b5.toggleVar(),b5.hovered,b5.x,b5.y,b5.width,b5.height,cf,ce,bk,bj)end end end;function DrawTank(bN,aP,bn,ch,ci,cj,ck,cl)local cm=1;local cn=2;local co=3;local cp=4;local cq=5;local cr=6;local cs=""local ct=0;local cu=fuelY;local cv=fuelY+10;if o()==1 and not RemoteHud then cu=cu-50;cv=cv-50 end;bN[#bN+1]=[[]]if ci=="ATMO"then cs="atmofueltank"elseif ci=="SPACE"then cs="spacefueltank"else cs="rocketfueltank"end;ct=_G[cs.."_size"]if#cj>0 then for i=1,#cj do local bI=string.sub(cj[i][cn],1,12)local cw=0;for c2=1,ct do if cj[i][cn]==f(unit[cs.."_"..c2].getData()).name then cw=c2;break end end;if aP or ck[i]==nil or cl[i]==nil then local cx=0;local cy=0;local cz=0;local cA=0;local bc=system.getTime()if cw~=0 then cl[i]=f(unit[cs.."_"..cw].getData()).percentage;ck[i]=f(unit[cs.."_"..cw].getData()).timeLeft;if ck[i]=="n/a"then ck[i]=0 end else cz=m(cj[i][cm])-cj[i][cp]cx=cj[i][co]cl[i]=d(0.5+cz*100/cx)cy=cj[i][cq]cA=cj[i][cr]if cy<=cz then ck[i]=0 else ck[i]=d(0.5+cz/((cy-cz)/(bc-cA)))end;cj[i][cq]=cz;cj[i][cr]=bc end end;if bI==ch then bI=e("%s %d",ci,i)end;if cw==0 then bI=bI.." *"end;local cB;if ck[i]==0 then cB="n/a"else cB=FormatTimeString(ck[i])end;if cl[i]~=nil then local bZ=d(cl[i]*2.55)local b_=e("rgb(%d,%d,%d)",255-bZ,bZ,0)local cC=""if cB~="n/a"and ck[i]<120 or cl[i]<5 then if aP then cC=[[class="red"]]end end;bN[#bN+1]=e([[ %s %d%% %s - ]],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([[ + ]],bn,cu,cC,bI,bn,cv,b_,cl[i],cB)cu=cu+30;cv=cv+30 end end end;bN[#bN+1]=""end;function HideInterplanetaryPanel()system.destroyWidgetPanel(panelInterplanetary)panelInterplanetary=nil end;function getRelativePitch(velocity)velocity=vec3(velocity)local bT=-math.deg(math.atan(velocity.y,velocity.z))+180;bT=bT-90;if bT<0 then bT=360+bT end;if bT>180 then bT=-180+bT-180 end;return-bT end;function getRelativeYaw(velocity)velocity=vec3(velocity)local cD=math.deg(math.atan(velocity.y,velocity.x))-90;if cD<-180 then cD=360+cD end;return cD end;function AlignToWorldVector(cE,cF)if not ad or RateOfChange>MinimumRateOfChange+0.08 or aa~=-1 then if cF==nil then cF=as end;cE=vec3(cE):normalize()local cG=vec3(core.getConstructWorldOrientationForward())-cE;local cH=-getMagnitudeInDirection(cG,core.getConstructWorldOrientationRight())*ar;local cI=-getMagnitudeInDirection(cG,core.getConstructWorldOrientationUp())*ar;if am==0 then am=cH/2 end;if an==0 then an=cI/2 end;D=D-(cH+(cH-am)*DampingMultiplier)C=C+cI+(cI-an)*DampingMultiplier;am=cH;an=cI;if math.abs(cH)0 and CustomTarget~=nil end)MakeButton("Clear Position","Clear Position",200,cM.height,cM.x-200-30,cM.y,function()return true end,ClearCurrentPosition,function()return AutopilotTargetIndex>0 and CustomTarget~=nil end)cJ=60;cK=300;local bn=10;local bo=au/2-300;MakeButton("Enable Turn and Burn","Disable Turn and Burn",cK,cJ,bn,bo,function()return TurnBurn end,ToggleTurnBurn)MakeButton("Engage Altitude Hold","Disable Altitude Hold",cK,cJ,bn+cK+20,bo,function()return AltitudeHold end,ToggleAltitudeHold)bo=bo+cJ+20;MakeButton("Engage Autoland","Disable Autoland",cK,cJ,bn,bo,function()return AutoLanding end,ToggleAutoLanding)MakeButton("Engage Auto Takeoff","Disable Auto Takeoff",cK,cJ,bn+cK+20,bo,function()return AutoTakeoff end,ToggleAutoTakeoff)bo=bo+cJ+20;MakeButton("Show Orbit Display","Hide Orbit Display",cK,cJ,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+cJ+20;MakeButton("Glide Re-Entry","Cancel Glide Re-Entry",cK,cJ,bn,bo,function()return Reentry end,function()x=true;BeginReentry()end,function()return ae>ReentryAltitude end)MakeButton("Parachute Re-Entry","Cancel Parachute Re-Entry",cK,cJ,bn+cK+20,bo,function()return Reentry end,BeginReentry,function()return ae>ReentryAltitude end)bo=bo+cJ+20;MakeButton("Engage Follow Mode","Disable Follow Mode",cK,cJ,bn,bo,function()return I end,ToggleFollowMode,function()return o()==1 end)MakeButton("Enable Repair Arrows","Disable Repair Arrows",cK,cJ,bn+cK+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+cJ+20;if not ExternalAGG then MakeButton("Enable AGG","Disable AGG",cK,cJ,bn,bo,function()return antigrav.getState()==1 end,ToggleAntigrav,function()return antigrav~=nil end)end;bo=bo+cJ+20;MakeButton(function()return e("Toggle Control Scheme - Current: %s",userControlScheme)end,function()return e("Control Scheme: %s",userControlScheme)end,cK*2,cJ,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 cN=Nav.axisCommandManager:getAxisCommandType(0)local cO="TRAVEL"if cN==1 then cO="CRUISE"end;if Autopilot then cO="AUTOPILOT"end;return cO end;function updateHud(bN)local bC=ae;local velocity=core.getVelocity()local bh=vec3(velocity):len()local bS=vec3(core.getWorldVertical())local bQ=vec3(core.getConstructWorldOrientationForward())local bR=vec3(core.getConstructWorldOrientationRight())local cP=vec3(core.getConstructWorldOrientationUp())local cQ=getRoll(bS,bQ,bR)local cR=cQ/180*math.pi;local cS=math.cos(cR)local cT=math.sin(cR)local bT=getPitch(bS,bQ,bR*cS+cP*cT)local cU=cQ;local cV=bT;local cW=j()local cX=d(unit.getThrottle())local cY=bh*3.6;local cZ=unit.getAxisCommandValue(0)local cO=GetFlightStyle()local c_="ROLL"local d0=unit.getClosestPlanetInfluence()>0;if cX==nil then cX=0 end;if not d0 then if bh>5 then bT=getRelativePitch(velocity)cQ=getRelativeYaw(velocity)else bT=0;cQ=0 end;c_="YAW"end;bN[#bN+1]=a5;bN[#bN+1]=ao;bN[#bN+1]=a4;if aR%aK==0 then aP=true end;if fuelX~=0 and fuelY~=0 then DrawTank(bN,aP,fuelX,"Atmospheric ","ATMO",aD,aN,aO)DrawTank(bN,aP,fuelX+100,"Space fuel t","SPACE",aE,aL,aM)DrawTank(bN,aP,fuelX+200,"Rocket fuel ","ROCKET",aF,aI,aJ)end;if aP then aP=false;aR=0 end;aR=aR+1;DrawVerticalSpeed(bN,bC)if o()==0 or RemoteHud then if not IsInFreeLook()or brightHud then if d0 then DrawRollLines(bN,centerX,centerY,cU,c_,d0)DrawArtificialHorizon(bN,cV,cU,centerX,centerY,d0,d(getRelativeYaw(velocity)),bh)else DrawRollLines(bN,centerX,centerY,cQ,c_,d0)DrawArtificialHorizon(bN,bT,cQ,centerX,centerY,d0,d(cQ),bh)end;DrawAltitudeDisplay(bN,bC,d0)DrawPrograde(bN,velocity,bh,centerX,centerY)end end;DrawThrottle(bN,cO,cX,cZ)DrawSpeed(bN,cY)DrawWarnings(bN)DisplayOrbitScreen(bN)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(bN)local d1=aj;local d2=ak;local d3=aj;local d4=ak;if IsInFreeLook()and not brightHud then d1=[[rgb(]]..d(PrimaryR*0.4+0.5)..","..d(PrimaryG*0.4+0.5)..","..d(PrimaryB*0.3+0.5)..[[)]]d2=[[rgb(]]..d(PrimaryR*0.3+0.5)..","..d(PrimaryG*0.3+0.5)..","..d(PrimaryB*0.2+0.5)..[[)]]end;bN[#bN+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() + ]],cC,bn,bo+dV,dS,bn,bo+dW,dR))bL=bL+1;dI=dI*10;if dR==dL then dJ=dT else dJ=0 end end;table.insert(bN,[[]])end end;function DrawPrograde(bN,velocity,bh,centerX,centerY)if bh>5 and not ad or bh>w then local dn=circleRad;local dX=20;local dY=20;local dZ=vec3(velocity)local d_=getRelativePitch(dZ)local e0=getRelativeYaw(dZ)local e1=-e0/dY*dn;local e2=d_/dX*dn;local bn=centerX+e1;local bo=centerY+e2;local a3=math.sqrt(e1^2+e2^2)if a3',bn,bo)else local dj=math.atan(e2,e1)local e3=centerX+dn*math.cos(dj)local e4=centerY+dn*math.sin(dj)bN[#bN+1]=e('',e3,e4)end;d_=getRelativePitch(-dZ)e0=getRelativeYaw(-dZ)e1=-e0/dY*dn;e2=d_/dX*dn;bn=centerX+e1;bo=centerY+e2;a3=math.sqrt(e1^2+e2^2)if not ad then if a3',bn,bo)else local dj=math.atan(e2,e1)local e3=centerX+dn*math.cos(dj)local e4=centerY+dn*math.sin(dj)bN[#bN+1]=e('',e3,e4)end end end end;function DrawWarnings(bN)bN[#bN+1]=e([[DU Hud Version: %.3f]],ConvertResolutionX(1900),ConvertResolutionY(1070),VERSION_NUMBER)bN[#bN+1]=[[]]if unit.isMouseControlActivated()==1 then bN[#bN+1]=e([[ + Warning: Invalid Control Scheme Detected]],ConvertResolutionX(960),ConvertResolutionY(550))bN[#bN+1]=e([[ + Keyboard Scheme must be selected]],ConvertResolutionX(960),ConvertResolutionY(600))bN[#bN+1]=e([[ + Set your preferred scheme in Lua Parameters instead]],ConvertResolutionX(960),ConvertResolutionY(650))end;local e5=ConvertResolutionX(960)local e6=ConvertResolutionY(860)local e7=ConvertResolutionY(880)local e8=ConvertResolutionY(900)local e9=ConvertResolutionY(960)local ea=ConvertResolutionY(200)local eb=ConvertResolutionY(150)local ec=ConvertResolutionY(960)if o()==1 and not RemoteHud then e6=ConvertResolutionY(135)e7=ConvertResolutionY(155)e8=ConvertResolutionY(175)ea=ConvertResolutionY(115)eb=ConvertResolutionY(95)end;if BrakeIsOn then bN[#bN+1]=e([[Brake Engaged]],e5,e6)end;if ad and RateOfChangebrakeLandingRate+5 then bN[#bN+1]=e([[** STALL WARNING **]],e5,ea+50)end;if ah then bN[#bN+1]=e([[Gyro Enabled]],e5,ec)end;if GearExtended then if A then bN[#bN+1]=e([[Gear Extended]],e5,e7)else bN[#bN+1]=e([[Landed (G: Takeoff)]],e5,e7)end;bN[#bN+1]=e([[Hover Height: %s]],e5,e8,getDistanceDisplayString(Nav:getTargetGroundAltitude()))end;if O then bN[#bN+1]=e([[ROCKET BOOST ENABLED]],e5,e9+20)end;if antigrav and not ExternalAGG and antigrav.getState()==1 and AntigravTargetAltitude~=nil then if math.abs(ae-antigrav.getBaseAltitude())<501 then bN[#bN+1]=e([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],e5,ea+20,d(AntigravTargetAltitude),d(antigrav.getBaseAltitude()))else bN[#bN+1]=e([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],e5,ea+20,d(AntigravTargetAltitude),d(antigrav.getBaseAltitude()))end elseif Autopilot and AutopilotTargetName~="None"then bN[#bN+1]=e([[Autopilot %s]],e5,ea+20,AutopilotStatus)elseif LockPitch~=nil then bN[#bN+1]=e([[LockedPitch: %d]],e5,ea+20,d(LockPitch))elseif I then bN[#bN+1]=e([[Follow Mode Engaged]],e5,ea+20)elseif Reentry then bN[#bN+1]=e([[Parachute Re-entry in Progress]],e5,ea+20)end;if AltitudeHold then if AutoTakeoff then bN[#bN+1]=e([[Ascent to %s]],e5,ea,getDistanceDisplayString(HoldAltitude))if BrakeIsOn then bN[#bN+1]=e([[Throttle Up and Disengage Brake For Takeoff]],e5,ea+50)end else bN[#bN+1]=e([[Altitude Hold: %s]],e5,ea,getDistanceDisplayString2(HoldAltitude))end end;if BrakeLanding then if StrongBrakes then bN[#bN+1]=e([[Brake-Landing]],e5,ea)else bN[#bN+1]=e([[Coast-Landing]],e5,ea)end end;if ProgradeIsOn then bN[#bN+1]=e([[Prograde Alignment]],e5,ea)end;if RetrogradeIsOn then bN[#bN+1]=e([[Retrograde Alignment]],e5,ea)end;if TurnBurn then bN[#bN+1]=e([[Turn & Burn Braking]],e5,eb)end;if VectorToTarget then bN[#bN+1]=e([[%s]],e5,ea+30,VectorStatus)end;bN[#bN+1]=""end;function DisplayOrbitScreen(bN)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 ed=75;local ee=0;local ef=250;local eg=4;ee=ee+eg;local eh=15;local bn=ed+ef+ed/2+eg;local bo=ee+ef/2+5+eg;local ei,ej,ek,el;ei=ef/4;el=0;bN[#bN+1]=[[]]bN[#bN+1]=e('',ef+ed*2,ef+ee,eg,eg)if orbit.periapsis~=nil and orbit.apoapsis~=nil then ek=(orbit.apoapsis.altitude+orbit.periapsis.altitude+planet.radius*2)/(ei*2)ej=(planet.radius+orbit.periapsis.altitude+(orbit.apoapsis.altitude-orbit.periapsis.altitude)/2)/ek*(1-orbit.eccentricity)el=ei-orbit.periapsis.altitude/ek-planet.radius/ek;local em=""if orbit.periapsis.altitude<=0 then em='redout'end;bN[#bN+1]=e([[]],em,ed+ef/2+el+eg,ee+ef/2+eg,ei,ej)bN[#bN+1]=e('',ed+ef/2+eg,ee+ef/2+eg,planet.radius/ek)end;if orbit.apoapsis~=nil and orbit.apoapsis.speed1 then bN[#bN+1]=e([[]],bn-35,bo-5,ed+ef/2+ei+el,bo-5)bN[#bN+1]=e([[Apoapsis]],bn,bo)bo=bo+eh;bN[#bN+1]=e([[%s]],bn,bo,getDistanceDisplayString(orbit.apoapsis.altitude))bo=bo+eh;bN[#bN+1]=e([[%s]],bn,bo,FormatTimeString(orbit.timeToApoapsis))bo=bo+eh;bN[#bN+1]=e([[%s]],bn,bo,getSpeedDisplayString(orbit.apoapsis.speed))end;bo=ee+ef/2+5+eg;bn=ed-ed/2+10+eg;if orbit.periapsis~=nil and orbit.periapsis.speed1 then bN[#bN+1]=e([[]],bn+35,bo-5,ed+ef/2-ei+el,bo-5)bN[#bN+1]=e([[Periapsis]],bn,bo)bo=bo+eh;bN[#bN+1]=e([[%s]],bn,bo,getDistanceDisplayString(orbit.periapsis.altitude))bo=bo+eh;bN[#bN+1]=e([[%s]],bn,bo,FormatTimeString(orbit.timeToPeriapsis))bo=bo+eh;bN[#bN+1]=e([[%s]],bn,bo,getSpeedDisplayString(orbit.periapsis.speed))end;bN[#bN+1]=e([[%s]],ed+ef/2+eg,20+eg,planet.name)if orbit.period~=nil and orbit.periapsis~=nil and orbit.apoapsis~=nil and orbit.apoapsis.speed>1 then local en=orbit.timeToApoapsis/orbit.period*2*math.pi;local eo=ei*math.cos(en)local ep=ej*math.sin(en)bN[#bN+1]=e('',ed+ef/2+eo+el+eg,ee+ef/2+ep+eg)end;bN[#bN+1]=[[]]end end;function getDistanceDisplayString(a3)local eq=a3>100000;local b6=""if eq 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 eq=a3>100000;local b6=""if eq 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(er)local es=0;local et=0;local eu=0;if er<60 then er=d(er)elseif er<3600 then es=d(er/60)er=d(er%60)elseif er<86400 then et=d(er/3600)es=d(er%3600/60)else eu=d(er/86400)et=d(er%86400/60)end;if eu>0 then return eu.."d "..et.."h "elseif et>0 then return et.."h "..es.."m "elseif es>0 then return es.."m "..er.."s"elseif er>0 then return er.."s"else return"0s"end end;function getMagnitudeInDirection(cE,ev)cE=vec3(cE)ev=vec3(ev):normalize()local b6=cE*ev;return b6.x+b6.y+b6.z end;function UpdateAutopilotTarget()if AutopilotTargetIndex==0 then AutopilotTargetName="None"V=nil;return true end;local ew=AtlasOrdered[AutopilotTargetIndex].index;local ex=aS[0][ew]if ex.center then AutopilotTargetName=ex.name;V=aY[0][ew]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=ex;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;if CustomTarget==nil then AutopilotTargetCoords=vec3(V.center)else AutopilotTargetCoords=CustomTarget.position end;if CustomTarget~=nil and CustomTarget.planetname=="Space"then AutopilotEndSpeed=0 else _,AutopilotEndSpeed=a_(V):escapeAndOrbitalSpeed(AutopilotTargetOrbit)end;AutopilotPlanetGravity=0;AutopilotAccelerating=false;AutopilotBraking=false;AutopilotCruising=false;Autopilot=false;AutopilotRealigned=false;AutopilotStatus="Aligning"return true end;function IncrementAutopilotTargetIndex()AutopilotTargetIndex=AutopilotTargetIndex+1;if AutopilotTargetIndex>#AtlasOrdered then AutopilotTargetIndex=0 end;UpdateAutopilotTarget()end;function DecrementAutopilotTargetIndex()AutopilotTargetIndex=AutopilotTargetIndex-1;if AutopilotTargetIndex<0 then AutopilotTargetIndex=#AtlasOrdered end;UpdateAutopilotTarget()end;function GetAutopilotMaxMass()local ey=LastMaxBrakeInAtmo/V:getGravity(V.center+vec3(0,0,1)*V.radius):len()return ey 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 ez,eA=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 _,eB;if not TurnBurn then _,eB=GetAutopilotBrakeDistanceAndTime(bh)else _,eB=GetAutopilotTBBrakeDistanceAndTime(bh)end;local eC=0;local eD=0;if AutopilotCruising or not Autopilot and bh>5 then eD=aZ.computeTravelTime(bh,0,AutopilotDistance)elseif P+ez0 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 eF=-1;local eG=-1;if vBooster then eF=vBooster.distance()end;if hover then eG=hover.distance()end;if eF~=-1 and eG~=-1 then if eFProfileTimeMax then ProfileTimeMax=eM end;if eM0 then local eW=eT:find('identifiedConstructs":%[%]')if eW==nil and perisPanelID==nil then a6=1;ToggleRadarPanel()end;if eW~=nil and perisPanelID~=nil then ToggleRadarPanel()end;if radarPanelID==nil then ToggleRadarPanel()end;a4=e([[Radar: %i contacts]],eU,eV,#eS)local eX={}for b4,b5 in pairs(eS)do if radar_1.hasMatchingTransponder(b5)==1 then table.insert(eX,b5)end end;if#eX>0 then local bo=ConvertResolutionY(15)local bn=ConvertResolutionX(1370)a4=e([[%sFriendlies In Range]],a4,bn,bo)for b4,b5 in pairs(eX)do bo=bo+20;a4=e([[%s%s]],a4,bn,bo,radar_1.getConstructName(b5))end end else local eY;eY=eT:find('worksInEnvironment":false')if eY then a4=e([[ + Radar: Jammed]],eU,eV)else a4=e([[ + Radar: No Contacts]],eU,eV)end;if radarPanelID~=nil then a6=0;ToggleRadarPanel()end end end end;function DisplayMessage(bN,eZ)if eZ~="empty"then bN[#bN+1]=[[]]for e_ in string.gmatch(eZ,"([^\n]+)")do bN[#bN+1]=e([[%s]],e_)end;bN[#bN+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 cY=vec3(velocity):len()local f0=bc-ag;if cY>1.38889 then cY=cY/1000;local f1=cY*(bc-ag)TotalDistanceTravelled=TotalDistanceTravelled+f1;W=W+f1 end;X=X+f0;TotalFlightTime=TotalFlightTime+f0;ag=bc end;function Atlas()return{[0]={[0]={GM=0,bodyId=0,center={x=0,y=0,z=0},name='Space',planetarySystemId=0,radius=0,atmos=false,gravity=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 f2=1.1*(aw-av)/1920;local f3=1.4*(ay-ax)/1080;for b4,b5 in pairs(aS[0])do local bn=960+b5.center.x/f2;local bo=540+b5.center.y/f3;aT=aT..''if not string.match(b5.name,"Moon")and not string.match(b5.name,"Sanctuary")and not string.match(b5.name,"Space")then aT=aT..""..b5.name..""end end;local bw=vec3(core.getConstructWorldPos())local bn=960+bw.x/f2;local bo=540+bw.y/f3;aT=aT..''aT=aT.."You Are Here"aT=aT..[[]]aU=f2;aV=f3;if screen_2 then screen_2.setHTML(''..aT)local bw=vec3(core.getConstructWorldPos())local bn=960+bw.x/f2;local bo=540+bw.y/f3;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 f4(f5)return type(f5)=='number'end;local function f6(f5)return type(tonumber(f5))=='number'end;local function f7(f8)return type(f8)=='table'end;local function f9(fa)return type(fa)=='string'end;local function fb(b5)return f7(b5)and f4(b5.x and b5.y and b5.z)end;local function fc(fd)return f7(fd)and f4(fd.latitude and fd.longitude and fd.altitude and fd.bodyId and fd.systemId)end;local fe=math.pi/180;local ff=180/math.pi;local fg=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 fh=utils.clamp;local function fi(fj,fk)if fj==0 then return math.abs(fk)<1e-09 end;if fk==0 then return math.abs(fj)<1e-09 end;return math.abs(fj-fk)=0 then local gb=math.sqrt(ga)local gc=g9+gb;local gd=g9-gb;if gd>0 then return g0,gc,gd elseif gc>0 then return g0,gc,nil end end end;return nil,nil,nil end;function fD:closestBody(ge)assert(type(ge)=='table','Invalid coordinates.')local gf,g0;local gg=vec3(ge)for _,gh in pairs(self)do local gi=(gh.center-gg):len2()if not g0 or gi=0 and gm or 2*math.pi+gm;bA=math.pi/2-math.acos(gl.z/a3)end;return setmetatable({latitude=bA,longitude=bB,altitude=bC,bodyId=self.bodyId,systemId=self.planetarySystemId},fz)end;function fq:convertToWorldCoordinates(fC)local gj=f9(fC)and fB(fC)or fC;if gj.bodyId==0 then return vec3(gj.latitude,gj.longitude,gj.altitude)end;assert(fc(gj),'Argument 1 (mapPosition) is not an instance of "MapPosition".')assert(gj.systemId==self.planetarySystemId,'Argument 1 (mapPosition) has a different planetary system ID.')assert(gj.bodyId==self.bodyId,'Argument 1 (mapPosition) has a different planetary body ID.')local bD=math.cos(gj.latitude)return self.center+(self.radius+gj.altitude)*vec3(bD*math.cos(gj.longitude),bD*math.sin(gj.longitude),math.sin(gj.latitude))end;function fq:getAltitude(fx)return(vec3(fx)-self.center):len()-self.radius end;function fq:getDistance(fx)return(vec3(fx)-self.center):len()end;function fq:getGravity(fx)local gn=self.center-vec3(fx)local go=gn:len2()return self.GM/go*gn/math.sqrt(go)end;return setmetatable(aX,{__call=function(_,...)return fL(...)end})end;function Keplers()local vec3=require('cpml.vec3')local PlanetRef=PlanetRef()local function f9(fa)return type(fa)=='string'end;local function f7(f8)return type(f8)=='table'end;local function fi(fj,fk)if fj==0 then return math.abs(fk)<1e-09 end;if fk==0 then return math.abs(fj)<1e-09 end;return math.abs(fj-fk)0 then gF=gE;gG=gF+gz/2 end;if gG>gz then gG=gG-gz end end;return{periapsis={position=gw,speed=gy/gu,circularOrbitSpeed=math.sqrt(gr/gu),altitude=gu-self.body.radius},apoapsis=gx and{position=gx,speed=gy/gv,circularOrbitSpeed=math.sqrt(gr/gv),altitude=gv-self.body.radius},currentVelocity=b5,currentPosition=bw,eccentricity=gt,period=gz,eccentricAnomaly=gB,meanAnomaly=gD,timeToPeriapsis=gF,timeToApoapsis=gG}end;local function gH(gI)local gh=PlanetRef.BodyParameters(gI.planetarySystemId,gI.bodyId,gI.radius,gI.center,gI.GM)return setmetatable({body=gh},Kepler)end;return setmetatable(Kepler,{__call=function(_,...)return gH(...)end})end;function Kinematics()local aZ={}local gJ=30000000/3600;local gK=gJ*gJ;local gL=100;local function gM(b5)return 1/math.sqrt(1-b5*b5/gK)end;function aZ.computeAccelerationTime(gN,gO,gP)local gQ=gJ*math.asin(gN/gJ)return(gJ*math.asin(gP/gJ)-gQ)/gO end;function aZ.computeDistanceAndTime(gN,gP,gR,gS,gT,gU)gT=gT or 0;gU=gU or 0;local gV=gN<=gP;local gW=gS*(gV and 1 or-1)/gR;local gX=-gU/gR;local gY=gW+gX;if gV and gY<=0 or not gV and gY>=0 then return-1,-1 end;local gZ,g_=0,0;if gW~=0 and gT>0 then local gQ=math.asin(gN/gJ)local h0=math.pi*(gW/2+gX)local h1=gW*gT;local h2=gJ*math.pi;local b5=function(f8)local c8=(h0*f8-h1*math.sin(math.pi*f8/2/gT)+h2*gQ)/h2;local h3=math.tan(c8)return gJ*h3/math.sqrt(h3*h3+1)end;local h4=gV and function(fa)return fa>=gP end or function(fa)return fa<=gP end;g_=2*gT;if h4(b5(g_))then local h5=0;while math.abs(g_-h5)>0.5 do local f8=(g_+h5)/2;if h4(b5(f8))then g_=f8 else h5=f8 end end end;local h6=gN;local h7=g_/gL;for h8=1,gL do local bh=b5(h8*h7)gZ=gZ+(bh+h6)*h7/2;h6=bh end;if g_<2*gT then return gZ,g_ end;gN=h6 end;local gQ=gJ*math.asin(gN/gJ)local b7=(gJ*math.asin(gP/gJ)-gQ)/gY;local h9=gK*math.cos(gQ/gJ)/gY;local a3=h9-gK*math.cos((gY*b7+gQ)/gJ)/gY;return a3+gZ,b7+g_ end;function aZ.computeTravelTime(gN,gO,a3)if a3==0 then return 0 end;if gO>0 then local gQ=gJ*math.asin(gN/gJ)local h9=gK*math.cos(gQ/gJ)/gO;return(gJ*math.acos(gO*(h9-a3)/gK)-gQ)/gO end;assert(gN>0,'Acceleration and initial speed are both zero.')return a3/gN end;function aZ.lorentz(b5)return gM(b5)end;return aZ end;function script.onStart()VERSION_NUMBER=4.922;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()UpdateAtlasLocationsList()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 bH=j()if door and(bH>0 or bH==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(bH>0 or bH==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(ha)if ha=="tenthSecond"then if AutopilotTargetName~="None"then if panelInterplanetary==nil then SetupInterplanetaryPanel()end;if AutopilotTargetName~=nil then local hb=CustomTarget~=nil;planetMaxMass=GetAutopilotMaxMass()system.updateData(interplanetaryHeaderText,'{"label": "Target", "value": "'..AutopilotTargetName..'", "unit":""}')travelTime=GetAutopilotTravelTime()if hb 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 ha=="oneSecond"then ab=false;RefreshLastMaxBrake(nil,true)updateDistance()updateRadar()updateWeapons()local bN={}local cO=GetFlightStyle()DrawOdometer(bN,W,TotalDistanceTravelled,cO,X)CheckDamage(bN)a5=table.concat(bN,"")collectgarbage("collect")elseif ha=="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 bL=-1;local bG;for b4,b5 in pairs(SavedLocations)do if b5.name and b5.name=="SatNav Location"then bL=b4;break end end;if bL~=-1 then bG=SavedLocations[bL]bL=-1;for b4,b5 in pairs(aS[0])do if b5.name and b5.name=="SatNav Location"then bL=b4;break end end;if bL>-1 then aS[0][bL]=bG end;UpdateAtlasLocationsList()K=bG.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 ha=="msgTick"then local bN={}DisplayMessage(bN,"empty")K="empty"unit.stopTimer("msgTick")a2=3 elseif ha=="animateTick"then b1=true;b0=false;a0=0;a1=0;unit.stopTimer("animateTick")elseif ha=="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())if planet.name=="Space"then planet=aS[0][2]end;kepPlanet=a_(planet)orbit=kepPlanet:orbitalParameters(core.getConstructWorldPos(),velocity)aa=hoverDetectGround()local hc=system.getMouseDeltaX()local hd=system.getMouseDeltaY()TargetGroundAltitude=Nav:getTargetGroundAltitude()local he=velMag>8334;if not he and LastIsWarping then if not BrakeIsOn then BrakeToggle()end;if Autopilot then ToggleAutopilot()end end;LastIsWarping=he;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(bN,K)end;if o()==0 and userControlScheme=="virtual joystick"then DrawDeadZone(bN)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(bN)if screen_1.getMouseState()==1 then CheckButtons()end;bN[#bN+1]=e([[]],s,t,a0,a1)elseif system.isViewLocked()==0 then if o()==1 and J then if not b0 then a0=a0+hc;a1=a1+hd end;SetButtonContains()DrawButtons(bN)if not b0 and not b1 then local hf=table.concat(bN,"")bN={}bN[#bN+1]=e("",ResolutionX,ResolutionY)bN[#bN+1]=aT;bN[#bN+1]=hf;bN[#bN+1]=""b0=true;bN[#bN+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(bN,"")system.setScreen(content)elseif b1 then local hf=table.concat(bN,"")bN={}bN[#bN+1]=e("",ResolutionX,ResolutionY)bN[#bN+1]=aT;bN[#bN+1]=hf;bN[#bN+1]=""end;if not b0 then bN[#bN+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(bN)end else SetButtonContains()DrawButtons(bN)end;bN[#bN+1]=e([[]],s,t,a0,a1)end;bN[#bN+1]=[[]]content=table.concat(bN,"")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;a7=false;a9=true;b2=autoRollPreference;BeginReentry()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 and not a7 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 CustomTarget~=nil and CustomTarget.planetname=="Space"and velMag<50 then K="Autopilot complete, arrived at space location"AutopilotBraking=false;Autopilot=false;AutopilotStatus="Aligning"elseif(CustomTarget==nil or CustomTarget~=nil and CustomTarget.planetname~="Space")and 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 and CustomTarget==nil or not AutopilotRealigned and CustomTarget~=nil and CustomTarget.planetname~="Space"then if not a7 then AutopilotTargetCoords=vec3(V.center)+(AutopilotTargetOrbit+V.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()end;AutopilotRealigned=true 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 bw=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local hr=bw-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-bT)local hz=pitchPID:get()C=hz end end;local dk=vec3(core.getWorldVertical())*-1;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget or LockPitch~=nil then local d0=unit.getClosestPlanetInfluence()>0;local bC=ae;local hA=HoldAltitude-bC;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 d0 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 cG=CustomTarget.position-vec3(core.getConstructWorldPos())AlignToWorldVector(cG)local hE=cG:len()-cG:project_on(dk):len()local bi=LastMaxBrakeInAtmo;local di=velocity.x*dk.x+velocity.y*dk.y+velocity.z*dk.z;local hF=velocity:len()-math.abs(di)local hG=vec3(core.getWorldAirFrictionAcceleration())if bi~=nil then P,Q=aZ.computeDistanceAndTime(hF,0,n(),0,0,bi+(hG:len()-hG:project_on(dk):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 bQ=vec3(core.getConstructWorldOrientationForward())local bR=vec3(core.getConstructWorldOrientationRight())local bS=vec3(core.getWorldVertical())local eH=-1;local bT=getPitch(bS,bQ,bR)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 di=velocity.x*dk.x+velocity.y*dk.y+velocity.z*dk.z;eH=aa;if eH>-1 then if math.abs(hq-bT)50000 then if Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=3500 then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,3500)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end end end;if math.abs(hq-bT)>hy then if pitchPID==nil then pitchPID=pid.new(8*0.01,0,8*0.1)end;pitchPID:inject(hq-bT)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 e_ in string.gmatch(iA,"([^\n]+)")do c(e_)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 bF=string.sub(iz,1,i-2)local bw=string.sub(iz,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,planet,bw)K="Added "..bF.." to saved locations,\nplanet "..planet.name.." at "..bw;a2=5 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() -- error handling code added by wrap.lua diff --git a/ChangeLog.md b/ChangeLog.md index 1229a92..bc768db 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,24 @@ ## ChangeLog - Most recent changes at the top +Version 4.930 - Now with space! (Space waypoints and autopiloting to them) +WARNING WARNING WARNING - Autopiloting to a point in space that has a physical object at it might end up +with you smeared all over it. The AP endeavors to stop you in time. Recommend setting a waypoint nearby or +wear a diaper AND brown pants buttercup. +- Autopilot will now go to a saved location in space. If on arrival you are too far off, you can Alt-4 again and +it will close in. +- Added Space as a entry in the Atlas to allow for saving locations in space. +- /addlocation now supports space waypoints. +Save Locations: +To make locations on planets, use either the Save Button or /addlocation Name Waypoint command +To make locations in space, use only the /addlocation Name Waypoint command +To rename a location, select it in the Interplanetary window, then use the /setname Name command +To delete a location, select it in the interplanetary window, then click the Clear button +Do not use Update button for space locations at this time. +KNOWN ISSUES: +- Autopilot from land to space save point may arrive off when first stops, just hit alt-4 again and it will zero in (works best starting in space) +- Autopilot from space to land point SOMETIMES has issues when ready for re-entry, troubleshooting that. If happens alt-4 to cancel, brake, alt-4 to go on in. + + Version 4.921 - Fixed issue of converting ::pos to WorldCoordinates. /addlocation Name ::waypoint works now - Provided feedback when adding a waypoint save location. diff --git a/src/ButtonHUD.lua b/src/ButtonHUD.lua index 55c7244..1a5ad96 100644 --- a/src/ButtonHUD.lua +++ b/src/ButtonHUD.lua @@ -110,6 +110,7 @@ LockPitch = nil LastMaxBrakeInAtmo = 0 AntigravTargetAltitude = core.getAltitude() LastStartTime = 0 +SpaceTarget = false -- VARIABLES TO BE SAVED GO HERE, SAVEABLE are Edit LUA Parameter settable, AUTO are ship status saves that occur over get up and sit down. local saveableVariables = {"userControlScheme", "AutopilotTargetOrbit", "apTickRate", "freeLookToggle", "turnAssist", @@ -126,7 +127,7 @@ local saveableVariables = {"userControlScheme", "AutopilotTargetOrbit", "apTickR "RemoteHud", "StallAngle", "ResolutionX", "ResolutionY", "UseSatNav", "FuelTankOptimization", "ContainerOptimization", "ExtraLongitudeTags", "ExtraLateralTags", "ExtraVerticalTags"} -local autoVariables = {"BrakeToggleStatus", "BrakeIsOn", "RetrogradeIsOn", "ProgradeIsOn", +local autoVariables = {"SpaceTarget","BrakeToggleStatus", "BrakeIsOn", "RetrogradeIsOn", "ProgradeIsOn", "Autopilot", "TurnBurn", "AltitudeHold", "DisplayOrbit", "BrakeLanding", "Reentry", "AutoTakeoff", "HoldAltitude", "AutopilotAccelerating", "AutopilotBraking", "AutopilotCruising", "AutopilotRealigned", "AutopilotEndSpeed", "AutopilotStatus", @@ -581,13 +582,13 @@ function zeroConvertToWorldCoordinates(pos) -- Many thanks to SilverZero for thi local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)' local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' .. num .. ',' .. num .. '}' local systemId, bodyId, latitude, longitude, altitude = string.match(pos, posPattern) + if (systemId == "0" and bodyId == "0") then + return vec3(tonumber(latitude), + tonumber(longitude), + tonumber(altitude)) + end 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), @@ -596,18 +597,17 @@ function zeroConvertToWorldCoordinates(pos) -- Many thanks to SilverZero for thi return planet.center + (planet.radius + altitude) * planetxyz end -function AddNewLocationByWaypoint(savename, planetnumber, pos) +function AddNewLocationByWaypoint(savename, planet, pos) if dbHud_1 then local newLocation = {} local position = zeroConvertToWorldCoordinates(pos) - local planet = atlas[0][planetnumber] - if planetnumber == 0 then + if planet.name == "Space" then newLocation = { position = position, name = savename, - atmosphere = 0, - planetname = "Space", - gravity = 0 + atmosphere = false, + planetname = planet.name, + gravity = planet.gravity } else local atmo = false @@ -636,21 +636,24 @@ 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 local id,_ = radar_1.getData():match('"constructId":"([0-9]*)","distance":([%d%.]*)') if id ~= nil and id ~= "" then name = name .. " " .. radar_1.getConstructName(id) end end - local newLocation = { + local newLocation = {} + local atmo = false + if planet.atmos then + atmo = true + end + newLocation = { position = position, name = name, - atmosphere = inAtmo, + atmosphere = atmo, planetname = planet.name, - gravity = unit.getClosestPlanetInfluence() + gravity = planet.gravity } SavedLocations[#SavedLocations + 1] = newLocation -- Nearest planet, gravity also important - if it's 0, we don't autopilot to the target planet, the target isn't near a planet. @@ -864,13 +867,13 @@ function ToggleTurnBurn() TurnBurn = not TurnBurn end -function ToggleVectorToTarget() +function ToggleVectorToTarget(SpaceTarget) -- This is a feature to vector toward the target destination in atmo or otherwise on-planet -- Uses altitude hold. VectorToTarget = not VectorToTarget if VectorToTarget then TurnBurn = false - if not AltitudeHold then + if not AltitudeHold and not SpaceTarget then ToggleAltitudeHold() end end @@ -997,7 +1000,7 @@ end function ToggleAutopilot() -- Toggle Autopilot, as long as the target isn't None - if AutopilotTargetIndex > 0 and not Autopilot and not VectorToTarget then + if AutopilotTargetIndex > 0 and not Autopilot and not VectorToTarget and not spaceLaunch then -- If it's a custom location... -- Behavior is probably -- a. If not at the same nearest planet and in space and the target has gravity, autopilot to that planet @@ -1011,7 +1014,15 @@ function ToggleAutopilot() -- f2. Should we even try to let this happen on ships with bad brakes. Eventually, try that. For now just don't let them use this if CustomTarget ~= nil then LockPitch = nil - if planet.name == CustomTarget.planetname then + SpaceTarget = (CustomTarget.planetname == "Space") + if SpaceTarget then + spaceLaunch = true + if atmosphere() ~= 0 then + ToggleAltitudeHold() + else + Autopilot = true + end + elseif planet.name == CustomTarget.planetname then StrongBrakes = ((planet.gravity * 9.80665 * constructMass()) < LastMaxBrakeInAtmo) if not StrongBrakes and velMag > minAutopilotSpeed then msgText = "Insufficient Brake Force\nCoast landing will be inaccurate" @@ -1021,16 +1032,21 @@ function ToggleAutopilot() if not AltitudeHold then -- Autotakeoff gets engaged inside the toggle if conditions are met if not VectorToTarget then - ToggleVectorToTarget() + ToggleVectorToTarget(SpaceTarget) end else -- Vector to target if not VectorToTarget then - ToggleVectorToTarget() + ToggleVectorToTarget(SpaceTarget) end end -- TBH... this is the only thing we need to do, make sure Alt Hold is on. else - spaceLand = true + if coreAltitude > 100000 or coreAltitude == 0 then + spaceLaunch = true + Autopilot = true + else + spaceLand = true + end end else spaceLaunch = true @@ -1059,6 +1075,7 @@ function ToggleAutopilot() ToggleAltitudeHold() end else + spaceLaunch = false Autopilot = false AutopilotRealigned = false VectorToTarget = false @@ -1066,6 +1083,7 @@ function ToggleAutopilot() AutoTakeoff = false AltitudeHold = false VectorToTarget = false + HoldAltitude = coreAltitude end end @@ -1551,7 +1569,7 @@ function BeginReentry() autoRoll = autoRollPreference AltitudeHold = false elseif atmosphere() ~= 0 or unit.getClosestPlanetInfluence() <= 0 or Reentry or not planet.atmos then - msgText = "Re-Entry requirements not met: you must start out of atmosphere and within a planets gravity well over a planet with atmosphere" + msgText = "Re-Entry requirements not met: you must start out of atmosphere\n and within a planets gravity well over a planet with atmosphere" msgTimer = 5 elseif not reentryMode then-- Parachute ReEntry StrongBrakes = ((planet.gravity * 9.80665 * constructMass()) < LastMaxBrakeInAtmo) @@ -2722,9 +2740,17 @@ function UpdateAutopilotTarget() if system.updateData(widgetTravelTimeText, widgetTravelTime) ~= 1 then system.addDataToWidget(widgetTravelTimeText, widgetTravelTime) end end - AutopilotTargetCoords = vec3(autopilotTargetPlanet.center) -- Aim center until we align + if CustomTarget == nil then + AutopilotTargetCoords = vec3(autopilotTargetPlanet.center) -- Aim center until we align + else + AutopilotTargetCoords = CustomTarget.position + end -- Determine the end speed - _, AutopilotEndSpeed = Kep(autopilotTargetPlanet):escapeAndOrbitalSpeed(AutopilotTargetOrbit) + if CustomTarget ~= nil and CustomTarget.planetname == "Space" then + AutopilotEndSpeed = 0 + else + _, AutopilotEndSpeed = Kep(autopilotTargetPlanet):escapeAndOrbitalSpeed(AutopilotTargetOrbit) + end -- AutopilotEndSpeed = 0 -- AutopilotPlanetGravity = autopilotTargetPlanet:getGravity(autopilotTargetPlanet.center + vec3({1,0,0}) * AutopilotTargetOrbit):len() -- Any direction, at our orbit height AutopilotPlanetGravity = 0 -- This is inaccurate unless we integrate and we're not doing that. @@ -2964,7 +2990,7 @@ function updateRadar() local friendlies = {} for k, v in pairs(radarContacts) do if radar_1.hasMatchingTransponder(v) == 1 then - friendlies[#friendlies + 1] = v + table.insert(friendlies,v) end end if #friendlies > 0 then @@ -3033,6 +3059,20 @@ end function Atlas() return { [0] = { + [0] = { + GM = 0, + bodyId = 0, + center = { + x = 0, + y = 0, + z = 0 + }, + name = 'Space', + planetarySystemId = 0, + radius = 0, + atmos = false, + gravity = 0 + }, [1] = { GM = 6930729684, bodyId = 1, @@ -3484,7 +3524,7 @@ function SetupAtlas() GalaxyMapHTML = GalaxyMapHTML .. '' - if not string.match(v.name, "Moon") and not string.match(v.name, "Sanctuary") then + if not string.match(v.name, "Moon") and not string.match(v.name, "Sanctuary") and not string.match (v.name, "Space") then GalaxyMapHTML = GalaxyMapHTML .. "" .. v.name .. "" @@ -4182,7 +4222,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.921 + VERSION_NUMBER = 4.922 SetupComplete = false beginSetup = coroutine.create(function() Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal, @@ -4210,13 +4250,11 @@ function script.onStart() Kinematic = Kinematics() Kep = Keplers() AddLocationsToAtlas() + UpdateAtlasLocationsList() UpdateAutopilotTarget() - coroutine.yield() - unit.hide() system.showScreen(1) - -- That was a lot of work with dirty strings and json. Clean up collectgarbage("collect") -- Start timers @@ -4427,6 +4465,7 @@ function script.onTick(timerId) velMag = vec3(velocity):len() sys = galaxyReference[0] planet = sys:closestBody(core.getConstructWorldPos()) + if planet.name == "Space" then planet = atlas[0][2] end kepPlanet = Kep(planet) orbit = kepPlanet:orbitalParameters(core.getConstructWorldPos(), velocity) hovGndDet = hoverDetectGround() @@ -4626,10 +4665,10 @@ function script.onTick(timerId) if align then ProgradeIsOn = false reentryMode = true - BeginReentry() spaceLand = false finalLand = true autoRoll = autoRollPreference + BeginReentry() end end end @@ -4656,7 +4695,7 @@ function script.onTick(timerId) ToggleAutopilot() finalLand = false end - if Autopilot and atmosphere() == 0 then + if Autopilot and atmosphere() == 0 and not spaceLand then -- Planetary autopilot engaged, we are out of atmo, and it has a target -- Do it. -- And tbh we should calc the brakeDistance live too, and of course it's also in meters @@ -4759,7 +4798,12 @@ function script.onTick(timerId) -- We'll try <0.9 instead of <1 so that we don't end up in a barely-orbit where touching the controls will make it an escape orbit -- Though we could probably keep going until it starts getting more eccentric, so we'd maybe have a circular orbit - if orbit.periapsis ~= nil and orbit.eccentricity < 1 then + if (CustomTarget ~=nil and CustomTarget.planetname == "Space" and velMag < 50) then + msgText = "Autopilot complete, arrived at space location" + AutopilotBraking = false + Autopilot = false + AutopilotStatus = "Aligning" -- Disable autopilot and reset + elseif (CustomTarget ==nil or (CustomTarget ~= nil and CustomTarget.planetname ~= "Space")) and orbit.periapsis ~= nil and orbit.eccentricity < 1 then AutopilotStatus = "Circularizing" if orbit.eccentricity > lastEccentricity or (orbit.apoapsis.altitude < AutopilotTargetOrbit and orbit.periapsis.altitude < @@ -4773,7 +4817,7 @@ function script.onTick(timerId) brakeInput = 0 Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 0) apThrottleSet = false - if CustomTarget ~= nil then + if CustomTarget ~= nil and CustomTarget.planetname ~= "Space" then ProgradeIsOn = true spaceLand = true end @@ -4794,13 +4838,15 @@ function script.onTick(timerId) -- It's engaged but hasn't started accelerating yet. if aligned then -- Re-align to 200km from our aligned right - if not AutopilotRealigned then -- Removed radius from this because it makes our readouts look inaccurate? - AutopilotTargetCoords = vec3(autopilotTargetPlanet.center) + - ((AutopilotTargetOrbit + autopilotTargetPlanet.radius) * - vec3(core.getConstructWorldOrientationRight())) + if not AutopilotRealigned and CustomTarget == nil or (not AutopilotRealigned and CustomTarget ~= nil and CustomTarget.planetname ~= "Space") then + if not spaceLand then + AutopilotTargetCoords = vec3(autopilotTargetPlanet.center) + + ((AutopilotTargetOrbit + autopilotTargetPlanet.radius) * + vec3(core.getConstructWorldOrientationRight())) + AutopilotShipUp = core.getConstructWorldOrientationUp() + AutopilotShipRight = core.getConstructWorldOrientationRight() + end AutopilotRealigned = true - AutopilotShipUp = core.getConstructWorldOrientationUp() - AutopilotShipRight = core.getConstructWorldOrientationRight() elseif aligned then AutopilotAccelerating = true AutopilotStatus = "Accelerating" @@ -5033,8 +5079,8 @@ function script.onTick(timerId) if Nav.axisCommandManager:getAxisCommandType(0) == 0 then Nav.control.cancelCurrentControlMasterMode() end - if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal) ~= 5000 then -- This thing is dumb. - Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal, 5000) + if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal) ~= 3500 then -- This thing is dumb. + Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal, 3500) Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical, 0) Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral, 0) end @@ -5672,7 +5718,7 @@ function script.onInputText(text) 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) + AddNewLocationByWaypoint(savename, planet, pos) msgText = "Added "..savename.." to saved locations,\nplanet "..planet.name.." at "..pos msgTimer = 5 elseif command == "/agg" then