diff --git a/ButtonHUD.conf b/ButtonHUD.conf index 8300d38..73ef71f 100644 --- a/ButtonHUD.conf +++ b/ButtonHUD.conf @@ -1,4 +1,4 @@ -name: ButtonsHud - Dimencia and Archaegeo v5.300 (Minified) +name: ButtonsHud - Dimencia and Archaegeo v5.320 (Minified) slots: core: class: CoreUnit @@ -182,7 +182,8 @@ handlers: CalculateBrakeLandingSpeed = false --export: (Default: false) Whether BrakeLanding speed at non-waypoints should be calculated or use the brakeLandingRate user setting. Only set to true for ships with low mass to lift capability. autoRollRollThreshold = 0 --export: (Default: 0) The minimum amount of roll before autoRoll kicks in and stabilizes (if active) AtmoSpeedAssist = true --export: (Default: true) Whether or not atmospheric speeds should be limited to a maximum of AtmoSpeedLimit - Nav=Navigator.new(system,core,unit)script={}BrakeToggleStatus=BrakeToggleDefault;BrakeIsOn=false;RetrogradeIsOn=false;ProgradeIsOn=false;Autopilot=false;TurnBurn=false;AltitudeHold=false;BrakeLanding=false;AutoTakeoff=false;Reentry=false;HoldAltitude=1000;AutopilotAccelerating=false;AutopilotRealigned=false;AutopilotBraking=false;AutopilotCruising=false;AutopilotEndSpeed=0;AutopilotStatus="Aligning"AutopilotPlanetGravity=0;PrevViewLock=1;AutopilotTargetName="None"AutopilotTargetCoords=nil;AutopilotTargetIndex=0;GearExtended=nil;TotalDistanceTravelled=0.0;TotalFlightTime=0;SavedLocations={}VectorToTarget=false;LocationIndex=0;LastMaxBrake=0;LockPitch=nil;LastMaxBrakeInAtmo=0;AntigravTargetAltitude=core.getAltitude()LastStartTime=0;SpaceTarget=false;local a={"userControlScheme","TargetOrbitRadius","apTickRate","freeLookToggle","turnAssist","PrimaryR","PrimaryG","PrimaryB","warmup","DeadZone","circleRad","MouseXSensitivity","MouseYSensitivity","MaxGameVelocity","showHud","autoRollPreference","InvertMouse","pitchSpeedFactor","yawSpeedFactor","rollSpeedFactor","brakeSpeedFactor","brakeFlatFactor","autoRollFactor","turnAssistFactor","torqueFactor","AutoTakeoffAltitude","TargetHoverHeight","AutopilotInterplanetaryThrottle","hideHudOnToggleWidgets","DampingMultiplier","fuelTankHandlingAtmo","ExternalAGG","ShouldCheckDamage","fuelTankHandlingSpace","fuelTankHandlingRocket","RemoteFreeze","hudTickRate","speedChangeLarge","speedChangeSmall","brightHud","brakeLandingRate","MaxPitch","ReentrySpeed","AtmoSpeedLimit","ReentryAltitude","centerX","centerY","SpaceSpeedLimit","AtmoSpeedAssist","vSpdMeterX","vSpdMeterY","altMeterX","altMeterY","fuelX","fuelY","LandingGearGroundHeight","TrajectoryAlignmentStrength","RemoteHud","YawStallAngle","PitchStallAngle","ResolutionX","ResolutionY","UseSatNav","FuelTankOptimization","ContainerOptimization","ExtraLongitudeTags","ExtraLateralTags","ExtraVerticalTags","OrbitMapSize","OrbitMapX","OrbitMapY","DisplayOrbit","CalculateBrakeLandingSpeed"}local b={"SpaceTarget","BrakeToggleStatus","BrakeIsOn","RetrogradeIsOn","ProgradeIsOn","Autopilot","TurnBurn","AltitudeHold","BrakeLanding","Reentry","AutoTakeoff","HoldAltitude","AutopilotAccelerating","AutopilotBraking","AutopilotCruising","AutopilotRealigned","AutopilotEndSpeed","AutopilotStatus","AutopilotPlanetGravity","PrevViewLock","AutopilotTargetName","AutopilotTargetCoords","AutopilotTargetIndex","TotalDistanceTravelled","TotalFlightTime","SavedLocations","VectorToTarget","LocationIndex","LastMaxBrake","LockPitch","LastMaxBrakeInAtmo","AntigravTargetAltitude","LastStartTime"}local c=system.print;local d=math.floor;local e=string.format;local f=json.decode;local g=json.encode;local h=core.getElementMaxHitPointsById;local j=unit.getAtmosphereDensity;local k=core.getElementHitPointsById;local l=core.getElementTypeById;local m=core.getElementMassById;local n=core.getConstructMass;local o=Nav.control.isRemoteControlled;function round(p,q)local r=10^(q or 0)return d(p*r+0.5)/r end;local s=0;local t=0;local u=false;local v=0;local w=false;local x=round(ResolutionX/2,0)local y=round(ResolutionY/2,0)local z=false;local A=true;local B=55;local C=false;local D=1;local E=1;local F=false;local G=0;local H=0;local I=0;local J=0;local K=0;local L=0;local M=0;local N=false;local O=false;local P="empty"local Q=1;local R=5;local S=5;local T=false;local U,V=0;local W,X=0;local Y=false;local Z=false;local a0=nil;local a1=0;local a2=0;local a3=false;local a4=0;local a5=0;local a6=0;local a7=3;local a8=0;local a9=""local aa=""local ab=0;local ac=false;local ad=false;local ae=false;local af=-1;local ag=false;local ah=""local ai=j()>0;local aj=core.getAltitude()local ak=core.getElementIdList()local al=system.getTime()local am=nil;local an=false;local ao=[[rgb(]]..d(PrimaryR+0.5)..","..d(PrimaryG+0.5)..","..d(PrimaryB+0.5)..[[)]]local ap=[[rgb(]]..d(PrimaryR*0.9+0.5)..","..d(PrimaryG*0.9+0.5)..","..d(PrimaryB*0.9+0.5)..[[)]]local aq={}local ar=0;local as=0;local at=""local au=true;local av={}local aw=1;local ax=0.001;local ay=ResolutionX;local az=ResolutionY;local aA=nil;local aB=nil;local aC=nil;local aD=nil;local aE=false;local aF=false;local aG=0;local aH=nil;local aI={}local aJ={}local aK={}local aL=0;local aM=false;local aN={}local aO={}local aP=d(1/apTickRate)*2;local aQ={}local aR={}local aS={}local aT={}local aU=false;local aV=16;local aW=0;local aX=nil;local aY=""local aZ=nil;local a_=nil;local b0=nil;local b1=nil;local b2=nil;local b3=nil;local b4=nil;local b5=nil;local b6=false;local b7=false;local b8=autoRollPreference;local b9=vec3(core.getConstructWorldOrientationForward()):dot(vec3(core.getWorldVelocity()):normalize())local ba=vec3(core.getWorldVelocity())local bb=vec3(ba):len()local bc=math.cos(YawStallAngle*constants.deg2rad)local bd=LandingGearGroundHeight;local be=system.getMouseDeltaX()local bf=system.getMouseDeltaY()local bg=false;local bh=system.getTime()local bi=0;local bj=0;local bk=AtmoSpeedLimit;function round(p,q)local r=10^(q or 0)return math.floor(p*r+0.5)/r end;function LoadVariables()if dbHud_1 then local bl=dbHud_1.hasKey;if not useTheseSettings then for bm,bn in pairs(a)do if bl(bn)then local bo=f(dbHud_1.getStringValue(bn))if bo~=nil then c(bn.." "..dbHud_1.getStringValue(bn))_G[bn]=bo;aE=true end end end end;coroutine.yield()for bm,bn in pairs(b)do if bl(bn)then local bo=f(dbHud_1.getStringValue(bn))if bo~=nil then c(bn.." "..dbHud_1.getStringValue(bn))_G[bn]=bo;aE=true end end end;if useTheseSettings then P="Updated user preferences used. Will be saved when you exit seat.\nToggle off useTheseSettings to use saved values"a7=5 elseif aE then P="Loaded Saved Variables (see Lua Chat Tab for list)"else P="No Saved Variables Found - Stand up / leave remote to save settings"end else P="No databank found, install one anywhere and rerun the autoconfigure to save variables"end;local bp=system.getTime()if LastStartTime+180br then br=bq end;if ContainerOptimization>0 then br=br-br*ContainerOptimization*0.05 end;if FuelTankOptimization>0 then br=br-br*FuelTankOptimization*0.05 end;return br end;function ProcessElements()local bs=fuelX~=0 and fuelY~=0;for bm in pairs(ak)do local type=l(ak[bm])if type=="Landing Gear"then F=true end;if type=="Dynamic Core Unit"then local bt=h(ak[bm])if bt>10000 then aV=128 elseif bt>1000 then aV=64 elseif bt>150 then aV=32 end end;aL=aL+h(ak[bm])if bs and(type=="Atmospheric Fuel Tank"or type=="Space Fuel Tank"or type=="Rocket Fuel Tank")then local bt=h(ak[bm])local bu=m(ak[bm])local bq=0;local bv=system.getTime()if type=="Atmospheric Fuel Tank"then local br=400;local bw=35.03;if bt>10000 then br=51200;bw=5480 elseif bt>1300 then br=6400;bw=988.67 elseif bt>150 then br=1600;bw=182.67 end;bq=bu-bw;if fuelTankHandlingAtmo>0 then br=br+br*fuelTankHandlingAtmo*0.2 end;br=CalculateFuelVolume(bq,br)aI[#aI+1]={ak[bm],core.getElementNameById(ak[bm]),br,bw,bq,bv}end;if type=="Rocket Fuel Tank"then local br=320;local bw=173.42;if bt>65000 then br=40000;bw=25740 elseif bt>6000 then br=5120;bw=4720 elseif bt>700 then br=640;bw=886.72 end;bq=bu-bw;if fuelTankHandlingRocket>0 then br=br+br*fuelTankHandlingRocket*0.1 end;br=CalculateFuelVolume(bq,br)aK[#aK+1]={ak[bm],core.getElementNameById(ak[bm]),br,bw,bq,bv}end;if type=="Space Fuel Tank"then local br=2400;local bw=182.67;if bt>10000 then br=76800;bw=5480 elseif bt>1300 then br=9600;bw=988.67 end;bq=bu-bw;if fuelTankHandlingSpace>0 then br=br+br*fuelTankHandlingSpace*0.2 end;br=CalculateFuelVolume(bq,br)aJ[#aJ+1]={ak[bm],core.getElementNameById(ak[bm]),br,bw,bq,bv}end end end end;function SetupChecks()if gyro~=nil then am=gyro.getState()==1 end;if userControlScheme~="keyboard"then system.lockView(1)else system.lockView(0)end;if radar_1 then if l(radar_1.getId())=="Space Radar"then Y=true else Z=true end end;local bx=j()if door and(bx>0 or bx==0 and aj<10000)then for _,bn in pairs(door)do bn.toggle()end end;if switch then for _,bn in pairs(switch)do bn.toggle()end end;if forcefield and(bx>0 or bx==0 and aj<10000)then for _,bn in pairs(forcefield)do bn.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 F then GearExtended=Nav.control.isAnyLandingGearExtended()==1;if GearExtended then Nav.control.extendLandingGears()else Nav.control.retractLandingGears()end end;local by=AboveGroundLevel()if by~=-1 or not ai and vec3(core.getVelocity()):len()<50 then BrakeIsOn=true;if not F then GearExtended=true end else BrakeIsOn=false end;if bd~=nil then Nav.axisCommandManager:setTargetGroundAltitude(bd)if bd==0 and not F then GearExtended=true;BrakeIsOn=true end else bd=Nav:getTargetGroundAltitude()if GearExtended then Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)else Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end end;if ai and by~=-1 then b4=core.getMaxKinematicsParametersAlongAxis("ground",core.getConstructOrientationUp())[1]end;userControlScheme=string.lower(userControlScheme)WasInAtmo=ai end;function ConvertResolutionX(bn)if ResolutionX==1920 then return bn else return round(ResolutionX*bn/1920,0)end end;function ConvertResolutionY(bn)if ResolutionY==1080 then return bn else return round(ResolutionY*bn/1080,0)end end;function RefreshLastMaxBrake(bz,bA)if bz==nil then bz=core.g()end;bz=round(bz,5)local bB=j()if bA~=nil and bA or(aH==nil or aH~=bz)then local ba=core.getVelocity()local bC=vec3(ba):len()local bD=f(unit.getData()).maxBrake;if bD~=nil and bD>0 and ai then bD=bD/utils.clamp(bC/100,0.1,1)bD=bD/bB;if bB>0.10 then if LastMaxBrakeInAtmo then LastMaxBrakeInAtmo=(LastMaxBrakeInAtmo+bD)/2 else LastMaxBrakeInAtmo=bD end end end;if bD~=nil and bD>0 then LastMaxBrake=bD end;aH=bz end end;function MakeButton(bE,bF,bG,bH,bI,bJ,bK,bL,bM)local bN={enableName=bE,disableName=bF,width=bG,height=bH,x=bI,y=bJ,toggleVar=bK,toggleFunction=bL,drawCondition=bM,hovered=false}table.insert(av,bN)return bN end;function UpdateAtlasLocationsList()AtlasOrdered={}for bm,bn in pairs(aX[0])do table.insert(AtlasOrdered,{name=bn.name,index=bm})end;local function bO(bP,bQ)return bP.name=0 and b_ or 2*math.pi+b_;bY=math.pi/2-math.acos(bW.z/a8)end;return setmetatable({latitude=math.deg(bY),longitude=math.deg(bZ),altitude=bX,bodyId=bT.bodyId,systemId=bT.planetarySystemId},MapPosition)end;function zeroConvertToWorldCoordinates(c0)local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local c1='::pos{'..p..','..p..','..p..','..p..','..p..'}'local c2,c3,bY,bZ,bX=string.match(c0,c1)if c2=="0"and c3=="0"then return vec3(tonumber(bY),tonumber(bZ),tonumber(bX))end;bZ=math.rad(bZ)bY=math.rad(bY)local planet=aX[tonumber(c2)][tonumber(c3)]local c4=math.cos(bY)local c5=vec3(c4*math.cos(bZ),c4*math.sin(bZ),math.sin(bY))return planet.center+(planet.radius+bX)*c5 end;function AddNewLocationByWaypoint(c6,planet,c0)if dbHud_1 then local c7={}local position=zeroConvertToWorldCoordinates(c0)if planet.name=="Space"then c7={position=position,name=c6,atmosphere=false,planetname=planet.name,gravity=planet.gravity}else local bx=false;if planet.hasAtmosphere then bx=true else bx=false end;c7={position=position,name=c6,atmosphere=bx,planetname=planet.name,gravity=planet.gravity}end;SavedLocations[#SavedLocations+1]=c7;table.insert(aX[0],c7)UpdateAtlasLocationsList()else P="Databank must be installed to save locations"end end;function AddNewLocation()if dbHud_1 then local position=vec3(core.getConstructWorldPos())local c8=planet.name..". "..#SavedLocations;if radar_1 then local c9,_=radar_1.getData():match('"constructId":"([0-9]*)","distance":([%d%.]*)')if c9~=nil and c9~=""then c8=c8 .." "..radar_1.getConstructName(c9)end end;local c7={}local bx=false;if planet.hasAtmosphere then bx=true end;c7={position=position,name=c8,atmosphere=bx,planetname=planet.name,gravity=planet.gravity,safe=true}SavedLocations[#SavedLocations+1]=c7;table.insert(aX[0],c7)UpdateAtlasLocationsList()P="Location saved as "..c8 else P="Databank must be installed to save locations"end end;function UpdatePosition(ca)local cb=-1;local c7;for bm,bn in pairs(SavedLocations)do if bn.name and bn.name==CustomTarget.name then cb=bm;break end end;if cb~=-1 then local cc;if ca~=nil then c7={position=SavedLocations[cb].position,name=ca,atmosphere=SavedLocations[cb].atmosphere,planetname=SavedLocations[cb].planetname,gravity=SavedLocations[cb].gravity}else c7={position=vec3(core.getConstructWorldPos()),name=SavedLocations[cb].name,atmosphere=j(),planetname=planet.name,gravity=unit.getClosestPlanetInfluence(),safe=true}end;SavedLocations[cb]=c7;cb=-1;for bm,bn in pairs(aX[0])do if bn.name and bn.name==CustomTarget.name then cb=bm end end;if cb>-1 then aX[0][cb]=c7 end;UpdateAtlasLocationsList()P=CustomTarget.name.." position updated"AutopilotTargetIndex=0;UpdateAutopilotTarget()else P="Name Not Found"end end;function ClearCurrentPosition()local cb=-1;for bm,bn in pairs(aX[0])do if bn.name and bn.name==CustomTarget.name then cb=bm end end;if cb>-1 then table.remove(aX[0],cb)end;cb=-1;for bm,bn in pairs(SavedLocations)do if bn.name and bn.name==CustomTarget.name then P=bn.name.." saved location cleared"cb=bm;break end end;if cb~=-1 then table.remove(SavedLocations,cb)end;DecrementAutopilotTargetIndex()UpdateAtlasLocationsList()end;function DrawDeadZone(cd)cd[#cd+1]=e([[]],DeadZone)end;function ToggleRadarPanel()if radarPanelID~=nil and ab==0 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;if perisPanelID~=nil then system.destroyWidgetPanel(perisPanelID)perisPanelID=nil end else if ab==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;ab=0 end end;function ToggleWidgets()if au 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;au=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;au=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 ai then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;widgetCurBrakeTime=system.createWidget(panelInterplanetary,"value")widgetCurBrakeTimeText=system.createData('{"label": "Cur Brake Time", "value": "N/A", "unit":""}')if not ai then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;widgetMaxBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeDistanceText=system.createData('{"label": "Max Brake distance", "value": "N/A", "unit":""}')if not ai then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;widgetMaxBrakeTime=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeTimeText=system.createData('{"label": "Max Brake Time", "value": "N/A", "unit":""}')if not ai then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;widgetTrajectoryAltitude=system.createWidget(panelInterplanetary,"value")widgetTrajectoryAltitudeText=system.createData('{"label": "Projected Altitude", "value": "N/A", "unit":""}')if not ai then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end;widgetTargetOrbit=system.createWidget(panelInterplanetary,"value")widgetTargetOrbitText=system.createData('{"label": "Target Altitude", "value": "N/A", "unit":""}')system.addDataToWidget(widgetTargetOrbitText,widgetTargetOrbit)end;function Contains(ce,cf,bI,bJ,bG,bH)if ce>bI and cebJ and cf-1 then HoldAltitude=aj end;if not ad and Nav.axisCommandManager:getAxisCommandType(0)==0 and not AtmoSpeedAssist then Nav.control.cancelCurrentControlMasterMode()end else AutoTakeoff=true;if bj>-1 then HoldAltitude=aj+AutoTakeoffAltitude end;GearExtended=false;Nav.control.retractLandingGears()BrakeIsOn=true;Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end;if ad then HoldAltitude=100000 end else b8=autoRollPreference;AutoTakeoff=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;VectorToTarget=false end end;function ToggleFollowMode()if o()==1 then N=not N;if N 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;b8=autoRollPreference;GearExtended=OldGearExtended;if GearExtended then Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end end else P="Follow Mode only works with Remote controller"N=false end end;function ToggleAutopilot()TargetSet=false;if AutopilotTargetIndex>0 and not Autopilot and not VectorToTarget and not ad then UpdateAutopilotTarget()local ck=zeroConvertToMapPosition(a0,AutopilotTargetCoords)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)if CustomTarget~=nil then LockPitch=nil;SpaceTarget=CustomTarget.planetname=="Space"if SpaceTarget then if j()~=0 then ad=true;ToggleAltitudeHold()else Autopilot=true end elseif planet.name==CustomTarget.planetname then StrongBrakes=true;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 aj>100000 or aj==0 then Autopilot=true else ac=true;ProgradeIsOn=true;if AltitudeHold then ToggleAltitudeHold()end end end else RetrogradeIsOn=false;ProgradeIsOn=false;if j()~=0 then ad=true;ToggleAltitudeHold()else Autopilot=true end end elseif j()==0 then Autopilot=true;RetrogradeIsOn=false;ProgradeIsOn=false;AutopilotRealigned=false;N=false;AltitudeHold=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;z=false;LockPitch=nil;WaypointSet=false else ad=true;ToggleAltitudeHold()end else ad=false;Autopilot=false;AutopilotRealigned=false;VectorToTarget=false;z=false;AutoTakeoff=false;AltitudeHold=false;VectorToTarget=false;HoldAltitude=aj;TargetSet=false end end;function ProgradeToggle()ProgradeIsOn=not ProgradeIsOn;RetrogradeIsOn=false;Autopilot=false;AltitudeHold=false;N=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function RetrogradeToggle()RetrogradeIsOn=not RetrogradeIsOn;ProgradeIsOn=false;Autopilot=false;AltitudeHold=false;N=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function BrakeToggle()BrakeIsOn=not BrakeIsOn;if BrakeLanding then BrakeLanding=false;b8=autoRollPreference end;if BrakeIsOn then AltitudeHold=false;VectorToTarget=false;AutoTakeoff=false;Reentry=false;ProgradeIsOn=false;BrakeLanding=false;AutoLanding=false;AltitudeHold=false;LockPitch=nil;b8=autoRollPreference;ac=false;ae=false end end;function CheckDamage(cd)local cl=0;at=""local cm=aL;local cn=0;local co=0;local cp=0;local cq=0;local cr=""for bm in pairs(ak)do local bt=0;local cs=0;cs=h(ak[bm])bt=k(ak[bm])cn=cn+bt;if bt0 and aq[11]==ak[bm]then for cu in pairs(aq)do core.deleteSticker(aq[cu])end;aq={}end end;cl=d(cn/cm*100)if cl<100 then cd[#cd+1]=[[]]cq=d(cl*2.55)cr=e("rgb(%d,%d,%d)",255-cq,cq,0)if cl<100 then cd[#cd+1]=e([[Elemental Integrity: %i %%]],cr,cl)if cp>0 then cd[#cd+1]=e([[Disabled Modules: %i Damaged Modules: %i]],cr,cp,co)elseif co>0 then cd[#cd+1]=e([[Damaged Modules: %i]],cr,co)end end;cd[#cd+1]=[[<\g>]]end end;function DrawCursorLine(cd)local cv=d(utils.clamp(a8/(ay/4)*255,0,255))cd[#cd+1]=e("",a5,a6,d(PrimaryR+0.5)+cv,d(PrimaryG+0.5)-cv,d(PrimaryB+0.5)-cv)end;function getPitch(cw,cx,bQ)local cy=cw:cross(bQ):normalize_inplace()local cj=math.acos(utils.clamp(cy:dot(-cx),-1,1))*constants.rad2deg;if cy:cross(-cx):dot(bQ)<0 then cj=-cj end;return cj end;local cz=math.atan;local function cA(cB,cC,cD)return cz(cC:cross(cD):dot(cB),cC:dot(cD))end;function clearAll()if ag then ag=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;N=false;z=false;ac=false;ad=false;C=false;b8=autoRollPreference;VectorToTarget=false;TurnBurn=false;am=false;LockPitch=nil else ag=true end end;function wipeSaveVariables()if not dbHud_1 then P="No Databank Found, unable to wipe. \nYou must have a Databank attached to ship prior to running the HUD autoconfigure"a7=5 else if aF then for bm,bn in pairs(a)do dbHud_1.setStringValue(bn,g(nil))end;for bm,bn in pairs(b)do if bn~="SavedLocations"then dbHud_1.setStringValue(bn,g(nil))end end;P="Databank wiped. New variables will save after re-enter seat and exit"a7=5;aF=false;aE=false;a3=true else P="Press ALT-7 again to confirm wipe of ALL data"aF=true end end end;function CheckButtons()for _,bn in pairs(av)do if bn.hovered then if not bn.drawCondition or bn.drawCondition()then bn.toggleFunction()end;bn.hovered=false end end end;function SetButtonContains()local bI=a5+ay/2;local bJ=a6+az/2;for _,bn in pairs(av)do bn.hovered=Contains(bI,bJ,bn.x,bn.y,bn.width,bn.height)end end;function DrawButton(cd,cE,hover,bI,bJ,cF,cG,cH,cI,cJ,cK)if type(cJ)=="function"then cJ=cJ()end;if type(cK)=="function"then cK=cK()end;cd[#cd+1]=e(""if cE then cd[#cd+1]=e("%s",cJ)else cd[#cd+1]=e("%s",cK)end end;function DrawButtons(cd)local cL="rgb(50,50,50)'"local cM="rgb(210,200,200)"local cN=DrawButton;for _,bn in pairs(av)do local bF=bn.disableName;local bE=bn.enableName;if type(bF)=="function"then bF=bF()end;if type(bE)=="function"then bE=bE()end;if not bn.drawCondition or bn.drawCondition()then cN(cd,bn.toggleVar(),bn.hovered,bn.x,bn.y,bn.width,bn.height,cM,cL,bF,bE)end end end;function DrawTank(cd,aU,bI,cO,cP,cQ,cR,cS)local cT=1;local cU=2;local cV=3;local cW=4;local cX=5;local cY=6;local cZ=""local c_=0;local d0=fuelY;local d1=fuelY+10;if o()==1 and not RemoteHud then d0=d0-50;d1=d1-50 end;cd[#cd+1]=[[]]if cP=="ATMO"then cZ="atmofueltank"elseif cP=="SPACE"then cZ="spacefueltank"else cZ="rocketfueltank"end;c_=_G[cZ.."_size"]if#cQ>0 then for i=1,#cQ do local c8=string.sub(cQ[i][cU],1,12)local d2=0;for cu=1,c_ do if cQ[i][cU]==f(unit[cZ.."_"..cu].getData()).name then d2=cu;break end end;if aU or cR[i]==nil or cS[i]==nil then local d3=0;local d4=0;local d5=0;local d6=0;local bv=system.getTime()if d2~=0 then cS[i]=f(unit[cZ.."_"..d2].getData()).percentage;cR[i]=f(unit[cZ.."_"..d2].getData()).timeLeft;if cR[i]=="n/a"then cR[i]=0 end else d5=m(cQ[i][cT])-cQ[i][cW]d3=cQ[i][cV]cS[i]=d(0.5+d5*100/d3)d4=cQ[i][cX]d6=cQ[i][cY]if d4<=d5 then cR[i]=0 else cR[i]=d(0.5+d5/((d4-d5)/(bv-d6)))end;cQ[i][cX]=d5;cQ[i][cY]=bv end end;if c8==cO then c8=e("%s %d",cP,i)end;if d2==0 then c8=c8 .." *"end;local d7;if cR[i]==0 then d7="n/a"else d7=FormatTimeString(cR[i])end;if cS[i]~=nil then local cq=d(cS[i]*2.55)local cr=e("rgb(%d,%d,%d)",255-cq,cq,0)local d8=""if d7~="n/a"and cR[i]<120 or cS[i]<5 then if aU then d8=[[class="red"]]end end;cd[#cd+1]=e([[ + ForceAlignment = false --export: (Default: false) Whether velocity vector alignment should be forced when in Altitude Hold + Nav=Navigator.new(system,core,unit)script={}BrakeToggleStatus=BrakeToggleDefault;BrakeIsOn=false;RetrogradeIsOn=false;ProgradeIsOn=false;Autopilot=false;TurnBurn=false;AltitudeHold=false;BrakeLanding=false;AutoTakeoff=false;Reentry=false;HoldAltitude=1000;AutopilotAccelerating=false;AutopilotRealigned=false;AutopilotBraking=false;AutopilotCruising=false;AutopilotEndSpeed=0;AutopilotStatus="Aligning"AutopilotPlanetGravity=0;PrevViewLock=1;AutopilotTargetName="None"AutopilotTargetCoords=nil;AutopilotTargetIndex=0;GearExtended=nil;TotalDistanceTravelled=0.0;TotalFlightTime=0;SavedLocations={}VectorToTarget=false;LocationIndex=0;LastMaxBrake=0;LockPitch=nil;LastMaxBrakeInAtmo=0;AntigravTargetAltitude=core.getAltitude()LastStartTime=0;SpaceTarget=false;local a={"userControlScheme","TargetOrbitRadius","apTickRate","freeLookToggle","turnAssist","PrimaryR","PrimaryG","PrimaryB","warmup","DeadZone","circleRad","MouseXSensitivity","MouseYSensitivity","MaxGameVelocity","showHud","autoRollPreference","InvertMouse","pitchSpeedFactor","yawSpeedFactor","rollSpeedFactor","brakeSpeedFactor","brakeFlatFactor","autoRollFactor","turnAssistFactor","torqueFactor","AutoTakeoffAltitude","TargetHoverHeight","AutopilotInterplanetaryThrottle","hideHudOnToggleWidgets","DampingMultiplier","fuelTankHandlingAtmo","ExternalAGG","ShouldCheckDamage","fuelTankHandlingSpace","fuelTankHandlingRocket","RemoteFreeze","hudTickRate","speedChangeLarge","speedChangeSmall","brightHud","brakeLandingRate","MaxPitch","ReentrySpeed","AtmoSpeedLimit","ReentryAltitude","centerX","centerY","SpaceSpeedLimit","AtmoSpeedAssist","vSpdMeterX","vSpdMeterY","altMeterX","altMeterY","fuelX","fuelY","LandingGearGroundHeight","TrajectoryAlignmentStrength","RemoteHud","YawStallAngle","PitchStallAngle","ResolutionX","ResolutionY","UseSatNav","FuelTankOptimization","ContainerOptimization","ExtraLongitudeTags","ExtraLateralTags","ExtraVerticalTags","OrbitMapSize","OrbitMapX","OrbitMapY","DisplayOrbit","CalculateBrakeLandingSpeed","ForceAlignment"}local b={"SpaceTarget","BrakeToggleStatus","BrakeIsOn","RetrogradeIsOn","ProgradeIsOn","Autopilot","TurnBurn","AltitudeHold","BrakeLanding","Reentry","AutoTakeoff","HoldAltitude","AutopilotAccelerating","AutopilotBraking","AutopilotCruising","AutopilotRealigned","AutopilotEndSpeed","AutopilotStatus","AutopilotPlanetGravity","PrevViewLock","AutopilotTargetName","AutopilotTargetCoords","AutopilotTargetIndex","TotalDistanceTravelled","TotalFlightTime","SavedLocations","VectorToTarget","LocationIndex","LastMaxBrake","LockPitch","LastMaxBrakeInAtmo","AntigravTargetAltitude","LastStartTime"}local c=system.print;local d=math.floor;local e=string.format;local f=json.decode;local g=json.encode;local h=core.getElementMaxHitPointsById;local j=unit.getAtmosphereDensity;local k=core.getElementHitPointsById;local l=core.getElementTypeById;local m=core.getElementMassById;local n=core.getConstructMass;local o=Nav.control.isRemoteControlled;function round(p,q)local r=10^(q or 0)return d(p*r+0.5)/r end;local s=0;local t=0;local u=false;local v=0;local w=false;local x=round(ResolutionX/2,0)local y=round(ResolutionY/2,0)local z=false;local A=true;local B=55;local C=false;local D=1;local E=1;local F=false;local G=0;local H=0;local I=0;local J=0;local K=0;local L=0;local M=0;local N=false;local O=false;local P="empty"local Q=1;local R=5;local S=5;local T=false;local U,V=0;local W,X=0;local Y=false;local Z=false;local a0=nil;local a1=0;local a2=0;local a3=false;local a4=0;local a5=0;local a6=0;local a7=3;local a8=0;local a9=""local aa=""local ab=0;local ac=false;local ad=false;local ae=false;local af=-1;local ag=false;local ah=""local ai=j()>0;local aj=core.getAltitude()local ak=core.getElementIdList()local al=system.getTime()local am=nil;local an=false;local ao=[[rgb(]]..d(PrimaryR+0.5)..","..d(PrimaryG+0.5)..","..d(PrimaryB+0.5)..[[)]]local ap=[[rgb(]]..d(PrimaryR*0.9+0.5)..","..d(PrimaryG*0.9+0.5)..","..d(PrimaryB*0.9+0.5)..[[)]]local aq={}local ar=0;local as=0;local at=""local au=true;local av={}local aw=1;local ax=0.001;local ay=ResolutionX;local az=ResolutionY;local aA=nil;local aB=nil;local aC=nil;local aD=nil;local aE=false;local aF=false;local aG=0;local aH=nil;local aI={}local aJ={}local aK={}local aL=0;local aM=false;local aN={}local aO={}local aP=d(1/apTickRate)*2;local aQ={}local aR={}local aS={}local aT={}local aU=false;local aV=16;local aW=0;local aX=nil;local aY=""local aZ=nil;local a_=nil;local b0=nil;local b1=nil;local b2=nil;local b3=nil;local b4=nil;local b5=nil;local b6=false;local b7=false;local b8=autoRollPreference;local b9=vec3(core.getConstructWorldOrientationForward()):dot(vec3(core.getWorldVelocity()):normalize())local ba=vec3(core.getWorldVelocity())local bb=vec3(ba):len()local bc=math.cos(YawStallAngle*constants.deg2rad)local bd=LandingGearGroundHeight;local be=system.getMouseDeltaX()local bf=system.getMouseDeltaY()local bg=false;local bh=system.getTime()local bi=0;local bj=0;local bk=AtmoSpeedLimit;function round(p,q)local r=10^(q or 0)return math.floor(p*r+0.5)/r end;function LoadVariables()if dbHud_1 then local bl=dbHud_1.hasKey;if not useTheseSettings then for bm,bn in pairs(a)do if bl(bn)then local bo=f(dbHud_1.getStringValue(bn))if bo~=nil then c(bn.." "..dbHud_1.getStringValue(bn))_G[bn]=bo;aE=true end end end end;coroutine.yield()for bm,bn in pairs(b)do if bl(bn)then local bo=f(dbHud_1.getStringValue(bn))if bo~=nil then c(bn.." "..dbHud_1.getStringValue(bn))_G[bn]=bo;aE=true end end end;if useTheseSettings then P="Updated user preferences used. Will be saved when you exit seat.\nToggle off useTheseSettings to use saved values"a7=5 elseif aE then P="Loaded Saved Variables (see Lua Chat Tab for list)"else P="No Saved Variables Found - Stand up / leave remote to save settings"end else P="No databank found, install one anywhere and rerun the autoconfigure to save variables"end;local bp=system.getTime()if LastStartTime+180br then br=bq end;if ContainerOptimization>0 then br=br-br*ContainerOptimization*0.05 end;if FuelTankOptimization>0 then br=br-br*FuelTankOptimization*0.05 end;return br end;function ProcessElements()local bs=fuelX~=0 and fuelY~=0;for bm in pairs(ak)do local type=l(ak[bm])if type=="Landing Gear"then F=true end;if type=="Dynamic Core Unit"then local bt=h(ak[bm])if bt>10000 then aV=128 elseif bt>1000 then aV=64 elseif bt>150 then aV=32 end end;aL=aL+h(ak[bm])if bs and(type=="Atmospheric Fuel Tank"or type=="Space Fuel Tank"or type=="Rocket Fuel Tank")then local bt=h(ak[bm])local bu=m(ak[bm])local bq=0;local bv=system.getTime()if type=="Atmospheric Fuel Tank"then local br=400;local bw=35.03;if bt>10000 then br=51200;bw=5480 elseif bt>1300 then br=6400;bw=988.67 elseif bt>150 then br=1600;bw=182.67 end;bq=bu-bw;if fuelTankHandlingAtmo>0 then br=br+br*fuelTankHandlingAtmo*0.2 end;br=CalculateFuelVolume(bq,br)aI[#aI+1]={ak[bm],core.getElementNameById(ak[bm]),br,bw,bq,bv}end;if type=="Rocket Fuel Tank"then local br=320;local bw=173.42;if bt>65000 then br=40000;bw=25740 elseif bt>6000 then br=5120;bw=4720 elseif bt>700 then br=640;bw=886.72 end;bq=bu-bw;if fuelTankHandlingRocket>0 then br=br+br*fuelTankHandlingRocket*0.1 end;br=CalculateFuelVolume(bq,br)aK[#aK+1]={ak[bm],core.getElementNameById(ak[bm]),br,bw,bq,bv}end;if type=="Space Fuel Tank"then local br=2400;local bw=182.67;if bt>10000 then br=76800;bw=5480 elseif bt>1300 then br=9600;bw=988.67 end;bq=bu-bw;if fuelTankHandlingSpace>0 then br=br+br*fuelTankHandlingSpace*0.2 end;br=CalculateFuelVolume(bq,br)aJ[#aJ+1]={ak[bm],core.getElementNameById(ak[bm]),br,bw,bq,bv}end end end end;function SetupChecks()if gyro~=nil then am=gyro.getState()==1 end;if userControlScheme~="keyboard"then system.lockView(1)else system.lockView(0)end;if radar_1 then if l(radar_1.getId())=="Space Radar"then Y=true else Z=true end end;local bx=j()if door and(bx>0 or bx==0 and aj<10000)then for _,bn in pairs(door)do bn.toggle()end end;if switch then for _,bn in pairs(switch)do bn.toggle()end end;if forcefield and(bx>0 or bx==0 and aj<10000)then for _,bn in pairs(forcefield)do bn.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 F then GearExtended=Nav.control.isAnyLandingGearExtended()==1;if GearExtended then Nav.control.extendLandingGears()else Nav.control.retractLandingGears()end end;local by=AboveGroundLevel()if by~=-1 or not ai and vec3(core.getVelocity()):len()<50 then BrakeIsOn=true;if not F then GearExtended=true end else BrakeIsOn=false end;if bd~=nil then Nav.axisCommandManager:setTargetGroundAltitude(bd)if bd==0 and not F then GearExtended=true;BrakeIsOn=true end else bd=Nav:getTargetGroundAltitude()if GearExtended then Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)else Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end end;if ai and by~=-1 then b4=core.getMaxKinematicsParametersAlongAxis("ground",core.getConstructOrientationUp())[1]end;userControlScheme=string.lower(userControlScheme)WasInAtmo=ai end;function ConvertResolutionX(bn)if ResolutionX==1920 then return bn else return round(ResolutionX*bn/1920,0)end end;function ConvertResolutionY(bn)if ResolutionY==1080 then return bn else return round(ResolutionY*bn/1080,0)end end;function RefreshLastMaxBrake(bz,bA)if bz==nil then bz=core.g()end;bz=round(bz,5)local bB=j()if bA~=nil and bA or(aH==nil or aH~=bz)then local ba=core.getVelocity()local bC=vec3(ba):len()local bD=f(unit.getData()).maxBrake;if bD~=nil and bD>0 and ai then bD=bD/utils.clamp(bC/100,0.1,1)bD=bD/bB;if bB>0.10 then if LastMaxBrakeInAtmo then LastMaxBrakeInAtmo=(LastMaxBrakeInAtmo+bD)/2 else LastMaxBrakeInAtmo=bD end end end;if bD~=nil and bD>0 then LastMaxBrake=bD end;aH=bz end end;function MakeButton(bE,bF,bG,bH,bI,bJ,bK,bL,bM)local bN={enableName=bE,disableName=bF,width=bG,height=bH,x=bI,y=bJ,toggleVar=bK,toggleFunction=bL,drawCondition=bM,hovered=false}table.insert(av,bN)return bN end;function UpdateAtlasLocationsList()AtlasOrdered={}for bm,bn in pairs(aX[0])do table.insert(AtlasOrdered,{name=bn.name,index=bm})end;local function bO(bP,bQ)return bP.name=0 and b_ or 2*math.pi+b_;bY=math.pi/2-math.acos(bW.z/a8)end;return setmetatable({latitude=math.deg(bY),longitude=math.deg(bZ),altitude=bX,bodyId=bT.bodyId,systemId=bT.planetarySystemId},MapPosition)end;function zeroConvertToWorldCoordinates(c0)local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local c1='::pos{'..p..','..p..','..p..','..p..','..p..'}'local c2,c3,bY,bZ,bX=string.match(c0,c1)if c2=="0"and c3=="0"then return vec3(tonumber(bY),tonumber(bZ),tonumber(bX))end;bZ=math.rad(bZ)bY=math.rad(bY)local planet=aX[tonumber(c2)][tonumber(c3)]local c4=math.cos(bY)local c5=vec3(c4*math.cos(bZ),c4*math.sin(bZ),math.sin(bY))return planet.center+(planet.radius+bX)*c5 end;function AddNewLocationByWaypoint(c6,planet,c0)if dbHud_1 then local c7={}local position=zeroConvertToWorldCoordinates(c0)if planet.name=="Space"then c7={position=position,name=c6,atmosphere=false,planetname=planet.name,gravity=planet.gravity}else local bx=false;if planet.hasAtmosphere then bx=true else bx=false end;c7={position=position,name=c6,atmosphere=bx,planetname=planet.name,gravity=planet.gravity}end;SavedLocations[#SavedLocations+1]=c7;table.insert(aX[0],c7)UpdateAtlasLocationsList()else P="Databank must be installed to save locations"end end;function AddNewLocation()if dbHud_1 then local position=vec3(core.getConstructWorldPos())local c8=planet.name..". "..#SavedLocations;if radar_1 then local c9,_=radar_1.getData():match('"constructId":"([0-9]*)","distance":([%d%.]*)')if c9~=nil and c9~=""then c8=c8 .." "..radar_1.getConstructName(c9)end end;local c7={}local bx=false;if planet.hasAtmosphere then bx=true end;c7={position=position,name=c8,atmosphere=bx,planetname=planet.name,gravity=planet.gravity,safe=true}SavedLocations[#SavedLocations+1]=c7;table.insert(aX[0],c7)UpdateAtlasLocationsList()P="Location saved as "..c8 else P="Databank must be installed to save locations"end end;function UpdatePosition(ca)local cb=-1;local c7;for bm,bn in pairs(SavedLocations)do if bn.name and bn.name==CustomTarget.name then cb=bm;break end end;if cb~=-1 then local cc;if ca~=nil then c7={position=SavedLocations[cb].position,name=ca,atmosphere=SavedLocations[cb].atmosphere,planetname=SavedLocations[cb].planetname,gravity=SavedLocations[cb].gravity}else c7={position=vec3(core.getConstructWorldPos()),name=SavedLocations[cb].name,atmosphere=j(),planetname=planet.name,gravity=unit.getClosestPlanetInfluence(),safe=true}end;SavedLocations[cb]=c7;cb=-1;for bm,bn in pairs(aX[0])do if bn.name and bn.name==CustomTarget.name then cb=bm end end;if cb>-1 then aX[0][cb]=c7 end;UpdateAtlasLocationsList()P=CustomTarget.name.." position updated"AutopilotTargetIndex=0;UpdateAutopilotTarget()else P="Name Not Found"end end;function ClearCurrentPosition()local cb=-1;for bm,bn in pairs(aX[0])do if bn.name and bn.name==CustomTarget.name then cb=bm end end;if cb>-1 then table.remove(aX[0],cb)end;cb=-1;for bm,bn in pairs(SavedLocations)do if bn.name and bn.name==CustomTarget.name then P=bn.name.." saved location cleared"cb=bm;break end end;if cb~=-1 then table.remove(SavedLocations,cb)end;DecrementAutopilotTargetIndex()UpdateAtlasLocationsList()end;function DrawDeadZone(cd)cd[#cd+1]=e([[]],DeadZone)end;function ToggleRadarPanel()if radarPanelID~=nil and ab==0 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;if perisPanelID~=nil then system.destroyWidgetPanel(perisPanelID)perisPanelID=nil end else if ab==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;ab=0 end end;function ToggleWidgets()if au 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;au=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;au=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 ai then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;widgetCurBrakeTime=system.createWidget(panelInterplanetary,"value")widgetCurBrakeTimeText=system.createData('{"label": "Cur Brake Time", "value": "N/A", "unit":""}')if not ai then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;widgetMaxBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeDistanceText=system.createData('{"label": "Max Brake distance", "value": "N/A", "unit":""}')if not ai then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;widgetMaxBrakeTime=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeTimeText=system.createData('{"label": "Max Brake Time", "value": "N/A", "unit":""}')if not ai then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;widgetTrajectoryAltitude=system.createWidget(panelInterplanetary,"value")widgetTrajectoryAltitudeText=system.createData('{"label": "Projected Altitude", "value": "N/A", "unit":""}')if not ai then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end;widgetTargetOrbit=system.createWidget(panelInterplanetary,"value")widgetTargetOrbitText=system.createData('{"label": "Target Altitude", "value": "N/A", "unit":""}')system.addDataToWidget(widgetTargetOrbitText,widgetTargetOrbit)end;function Contains(ce,cf,bI,bJ,bG,bH)if ce>bI and cebJ and cf-1 then HoldAltitude=aj end;if not ad and Nav.axisCommandManager:getAxisCommandType(0)==0 and not AtmoSpeedAssist then Nav.control.cancelCurrentControlMasterMode()end else AutoTakeoff=true;if bj>-1 then HoldAltitude=aj+AutoTakeoffAltitude end;GearExtended=false;Nav.control.retractLandingGears()BrakeIsOn=true;Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end;if ad then HoldAltitude=100000 end else b8=autoRollPreference;AutoTakeoff=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;VectorToTarget=false end end;function ToggleFollowMode()if o()==1 then N=not N;if N 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;b8=autoRollPreference;GearExtended=OldGearExtended;if GearExtended then Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end end else P="Follow Mode only works with Remote controller"N=false end end;function ToggleAutopilot()TargetSet=false;if AutopilotTargetIndex>0 and not Autopilot and not VectorToTarget and not ad then UpdateAutopilotTarget()local ck=zeroConvertToMapPosition(a0,AutopilotTargetCoords)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)if CustomTarget~=nil then LockPitch=nil;SpaceTarget=CustomTarget.planetname=="Space"if SpaceTarget then if j()~=0 then ad=true;ToggleAltitudeHold()else Autopilot=true end elseif planet.name==CustomTarget.planetname then StrongBrakes=true;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 aj>100000 or aj==0 then Autopilot=true else ac=true;ProgradeIsOn=true;if AltitudeHold then ToggleAltitudeHold()end end end else RetrogradeIsOn=false;ProgradeIsOn=false;if j()~=0 then ad=true;ToggleAltitudeHold()else Autopilot=true end end elseif j()==0 then Autopilot=true;RetrogradeIsOn=false;ProgradeIsOn=false;AutopilotRealigned=false;N=false;AltitudeHold=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;z=false;LockPitch=nil;WaypointSet=false else ad=true;ToggleAltitudeHold()end else ad=false;Autopilot=false;AutopilotRealigned=false;VectorToTarget=false;z=false;AutoTakeoff=false;AltitudeHold=false;VectorToTarget=false;HoldAltitude=aj;TargetSet=false end end;function ProgradeToggle()ProgradeIsOn=not ProgradeIsOn;RetrogradeIsOn=false;Autopilot=false;AltitudeHold=false;N=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function RetrogradeToggle()RetrogradeIsOn=not RetrogradeIsOn;ProgradeIsOn=false;Autopilot=false;AltitudeHold=false;N=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function BrakeToggle()BrakeIsOn=not BrakeIsOn;if BrakeLanding then BrakeLanding=false;b8=autoRollPreference end;if BrakeIsOn then AltitudeHold=false;VectorToTarget=false;AutoTakeoff=false;Reentry=false;ProgradeIsOn=false;BrakeLanding=false;AutoLanding=false;AltitudeHold=false;LockPitch=nil;b8=autoRollPreference;ac=false;ae=false end end;function CheckDamage(cd)local cl=0;at=""local cm=aL;local cn=0;local co=0;local cp=0;local cq=0;local cr=""for bm in pairs(ak)do local bt=0;local cs=0;cs=h(ak[bm])bt=k(ak[bm])cn=cn+bt;if bt0 and aq[11]==ak[bm]then for cu in pairs(aq)do core.deleteSticker(aq[cu])end;aq={}end end;cl=d(cn/cm*100)if cl<100 then cd[#cd+1]=[[]]cq=d(cl*2.55)cr=e("rgb(%d,%d,%d)",255-cq,cq,0)if cl<100 then cd[#cd+1]=e([[Elemental Integrity: %i %%]],cr,cl)if cp>0 then cd[#cd+1]=e([[Disabled Modules: %i Damaged Modules: %i]],cr,cp,co)elseif co>0 then cd[#cd+1]=e([[Damaged Modules: %i]],cr,co)end end;cd[#cd+1]=[[<\g>]]end end;function DrawCursorLine(cd)local cv=d(utils.clamp(a8/(ay/4)*255,0,255))cd[#cd+1]=e("",a5,a6,d(PrimaryR+0.5)+cv,d(PrimaryG+0.5)-cv,d(PrimaryB+0.5)-cv)end;function getPitch(cw,cx,bQ)local cy=cw:cross(bQ):normalize_inplace()local cj=math.acos(utils.clamp(cy:dot(-cx),-1,1))*constants.rad2deg;if cy:cross(-cx):dot(bQ)<0 then cj=-cj end;return cj end;local cz=math.atan;local function cA(cB,cC,cD)cC=cC:project_on_plane(cB)cD=cD:project_on_plane(cB)return cz(cC:cross(cD):dot(cB),cC:dot(cD))end;function clearAll()if ag then ag=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;N=false;z=false;ac=false;ad=false;C=false;b8=autoRollPreference;VectorToTarget=false;TurnBurn=false;am=false;LockPitch=nil else ag=true end end;function wipeSaveVariables()if not dbHud_1 then P="No Databank Found, unable to wipe. \nYou must have a Databank attached to ship prior to running the HUD autoconfigure"a7=5 else if aF then for bm,bn in pairs(a)do dbHud_1.setStringValue(bn,g(nil))end;for bm,bn in pairs(b)do if bn~="SavedLocations"then dbHud_1.setStringValue(bn,g(nil))end end;P="Databank wiped. New variables will save after re-enter seat and exit"a7=5;aF=false;aE=false;a3=true else P="Press ALT-7 again to confirm wipe of ALL data"aF=true end end end;function CheckButtons()for _,bn in pairs(av)do if bn.hovered then if not bn.drawCondition or bn.drawCondition()then bn.toggleFunction()end;bn.hovered=false end end end;function SetButtonContains()local bI=a5+ay/2;local bJ=a6+az/2;for _,bn in pairs(av)do bn.hovered=Contains(bI,bJ,bn.x,bn.y,bn.width,bn.height)end end;function DrawButton(cd,cE,hover,bI,bJ,cF,cG,cH,cI,cJ,cK)if type(cJ)=="function"then cJ=cJ()end;if type(cK)=="function"then cK=cK()end;cd[#cd+1]=e(""if cE then cd[#cd+1]=e("%s",cJ)else cd[#cd+1]=e("%s",cK)end end;function DrawButtons(cd)local cL="rgb(50,50,50)'"local cM="rgb(210,200,200)"local cN=DrawButton;for _,bn in pairs(av)do local bF=bn.disableName;local bE=bn.enableName;if type(bF)=="function"then bF=bF()end;if type(bE)=="function"then bE=bE()end;if not bn.drawCondition or bn.drawCondition()then cN(cd,bn.toggleVar(),bn.hovered,bn.x,bn.y,bn.width,bn.height,cM,cL,bF,bE)end end end;function DrawTank(cd,aU,bI,cO,cP,cQ,cR,cS)local cT=1;local cU=2;local cV=3;local cW=4;local cX=5;local cY=6;local cZ=""local c_=0;local d0=fuelY;local d1=fuelY+10;if o()==1 and not RemoteHud then d0=d0-50;d1=d1-50 end;cd[#cd+1]=[[]]if cP=="ATMO"then cZ="atmofueltank"elseif cP=="SPACE"then cZ="spacefueltank"else cZ="rocketfueltank"end;c_=_G[cZ.."_size"]if#cQ>0 then for i=1,#cQ do local c8=string.sub(cQ[i][cU],1,12)local d2=0;for cu=1,c_ do if cQ[i][cU]==f(unit[cZ.."_"..cu].getData()).name then d2=cu;break end end;if aU or cR[i]==nil or cS[i]==nil then local d3=0;local d4=0;local d5=0;local d6=0;local bv=system.getTime()if d2~=0 then cS[i]=f(unit[cZ.."_"..d2].getData()).percentage;cR[i]=f(unit[cZ.."_"..d2].getData()).timeLeft;if cR[i]=="n/a"then cR[i]=0 end else d5=m(cQ[i][cT])-cQ[i][cW]d3=cQ[i][cV]cS[i]=d(0.5+d5*100/d3)d4=cQ[i][cX]d6=cQ[i][cY]if d4<=d5 then cR[i]=0 else cR[i]=d(0.5+d5/((d4-d5)/(bv-d6)))end;cQ[i][cX]=d5;cQ[i][cY]=bv end end;if c8==cO then c8=e("%s %d",cP,i)end;if d2==0 then c8=c8 .." *"end;local d7;if cR[i]==0 then d7="n/a"else d7=FormatTimeString(cR[i])end;if cS[i]~=nil then local cq=d(cS[i]*2.55)local cr=e("rgb(%d,%d,%d)",255-cq,cq,0)local d8=""if d7~="n/a"and cR[i]<120 or cS[i]<5 then if aU then d8=[[class="red"]]end end;cd[#cd+1]=e([[ %s %d%% %s ]],bI,d0,d8,c8,bI,d1,cr,cS[i],d7)d0=d0+30;d1=d1+30 end end end;cd[#cd+1]=""end;function HideInterplanetaryPanel()system.destroyWidgetPanel(panelInterplanetary)panelInterplanetary=nil end;function getRelativePitch(ba)ba=vec3(ba)local cj=-math.deg(math.atan(ba.y,ba.z))+180;cj=cj-90;if cj<0 then cj=360+cj end;if cj>180 then cj=-180+cj-180 end;return-cj end;function getRelativeYaw(ba)ba=vec3(ba)local d9=math.deg(math.atan(ba.y,ba.x))-90;if d9<-180 then d9=360+d9 end;return d9 end;function AlignToWorldVector(da,db,dc)if not ai or not bg or af~=-1 or bb0 and CustomTarget~=nil end)MakeButton("Clear Position","Clear Position",200,dp.height,dp.x-200-30,dp.y,function()return true end,ClearCurrentPosition,function()return AutopilotTargetIndex>0 and CustomTarget~=nil end)dl=60;dm=300;local bI=10;local bJ=az/2-300;MakeButton("Enable Turn and Burn","Disable Turn and Burn",dm,dl,bI,bJ,function()return TurnBurn end,ToggleTurnBurn)MakeButton("Engage Altitude Hold","Disable Altitude Hold",dm,dl,bI+dm+20,bJ,function()return AltitudeHold end,ToggleAltitudeHold)bJ=bJ+dl+20;MakeButton("Engage Autoland","Disable Autoland",dm,dl,bI,bJ,function()return AutoLanding end,ToggleAutoLanding)MakeButton("Engage Auto Takeoff","Disable Auto Takeoff",dm,dl,bI+dm+20,bJ,function()return AutoTakeoff end,ToggleAutoTakeoff)bJ=bJ+dl+20;MakeButton("Show Orbit Display","Hide Orbit Display",dm,dl,bI,bJ,function()return DisplayOrbit end,function()DisplayOrbit=not DisplayOrbit;if DisplayOrbit then P="Orbit Display Enabled"else P="Orbit Display Disabled"end end)bJ=bJ+dl+20;MakeButton("Glide Re-Entry","Cancel Glide Re-Entry",dm,dl,bI,bJ,function()return Reentry end,function()ac=true;ProgradeToggle()end,function()return aj>ReentryAltitude end)MakeButton("Parachute Re-Entry","Cancel Parachute Re-Entry",dm,dl,bI+dm+20,bJ,function()return Reentry end,BeginReentry,function()return aj>ReentryAltitude end)bJ=bJ+dl+20;MakeButton("Engage Follow Mode","Disable Follow Mode",dm,dl,bI,bJ,function()return N end,ToggleFollowMode,function()return o()==1 end)MakeButton("Enable Repair Arrows","Disable Repair Arrows",dm,dl,bI+dm+20,bJ,function()return aM end,function()aM=not aM;if aM then P="Repair Arrows Enabled"else P="Repair Arrows Diabled"end end,function()return o()==1 end)bJ=bJ+dl+20;if not ExternalAGG then MakeButton("Enable AGG","Disable AGG",dm,dl,bI,bJ,function()return antigrav.getState()==1 end,ToggleAntigrav,function()return antigrav~=nil end)end;bJ=bJ+dl+20;MakeButton(function()return e("Toggle Control Scheme - Current: %s",userControlScheme)end,function()return e("Control Scheme: %s",userControlScheme)end,dm*2,dl,bI,bJ,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 dq=Nav.axisCommandManager:getAxisCommandType(0)local dr="TRAVEL"if dq==1 then dr="CRUISE"end;if Autopilot then dr="AUTOPILOT"end;return dr end;function UpdateHud(cd)local bX=aj;local ba=core.getVelocity()local bC=vec3(ba):len()local ci=vec3(core.getWorldVertical())local cg=vec3(core.getConstructWorldOrientationForward())local ch=vec3(core.getConstructWorldOrientationRight())local ds=vec3(core.getConstructWorldOrientationUp())local dt=getRoll(ci,cg,ch)local du=dt/180*math.pi;local dv=math.cos(du)local dw=math.sin(du)local cj=getPitch(ci,cg,ch*dv+ds*dw)local dx=dt;local dy=cj;local dz=j()local dA=d(unit.getThrottle())local dB=bC*3.6;local dC=unit.getAxisCommandValue(0)if AtmoSpeedAssist and Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle then dC=s;dA=s*100 end;local dr=GetFlightStyle()local dD="ROLL"local dE=unit.getClosestPlanetInfluence()>0;if dA==nil then dA=0 end;if not dE then if bC>5 then cj=getRelativePitch(ba)dt=getRelativeYaw(ba)else cj=0;dt=0 end;dD="YAW"end;cd[#cd+1]=aa;cd[#cd+1]=at;cd[#cd+1]=a9;if aW%aP==0 then aU=true end;if fuelX~=0 and fuelY~=0 then DrawTank(cd,aU,fuelX,"Atmospheric ","ATMO",aI,aS,aT)DrawTank(cd,aU,fuelX+100,"Space fuel t","SPACE",aJ,aQ,aR)DrawTank(cd,aU,fuelX+200,"Rocket fuel ","ROCKET",aK,aN,aO)end;if aU then aU=false;aW=0 end;aW=aW+1;DrawVerticalSpeed(cd,bX)if o()==0 or RemoteHud then if not IsInFreeLook()or brightHud then if dE then DrawRollLines(cd,centerX,centerY,dx,dD,dE)DrawArtificialHorizon(cd,dy,dx,centerX,centerY,dE,d(getRelativeYaw(ba)),bC)else DrawRollLines(cd,centerX,centerY,dt,dD,dE)DrawArtificialHorizon(cd,cj,dt,centerX,centerY,dE,d(dt),bC)end;DrawAltitudeDisplay(cd,bX,dE)DrawPrograde(cd,ba,bC,centerX,centerY)end end;DrawThrottle(cd,dr,dA,dC)DrawSpeed(cd,dB)DrawWarnings(cd)DisplayOrbitScreen(cd)if screen_2 then local c0=vec3(core.getConstructWorldPos())local bI=960+c0.x/aZ;local bJ=450+c0.y/a_;screen_2.moveContent(b0,(bI-80)/19.2,(bJ-80)/10.8)end end;function IsInFreeLook()return system.isViewLocked()==0 and userControlScheme~="keyboard"and o()==0 end;function HUDPrologue(cd)local dF=ao;local dG=ap;local dH=ao;local dI=ap;if IsInFreeLook()and not brightHud then dF=[[rgb(]]..d(PrimaryR*0.4+0.5)..","..d(PrimaryG*0.4+0.5)..","..d(PrimaryB*0.3+0.5)..[[)]]dG=[[rgb(]]..d(PrimaryR*0.3+0.5)..","..d(PrimaryG*0.3+0.5)..","..d(PrimaryB*0.2+0.5)..[[)]]end;cd[#cd+1]=e([[ @@ -378,7 +379,7 @@ handlers: Keyboard Scheme must be selected]],ConvertResolutionX(960),ConvertResolutionY(600))cd[#cd+1]=e([[ Set your preferred scheme in Lua Parameters instead]],ConvertResolutionX(960),ConvertResolutionY(650))end;local eN=ConvertResolutionX(960)local eO=ConvertResolutionY(860)local eP=ConvertResolutionY(880)local eQ=ConvertResolutionY(900)local eR=ConvertResolutionY(960)local eS=ConvertResolutionY(200)local eT=ConvertResolutionY(150)local eU=ConvertResolutionY(960)if o()==1 and not RemoteHud then eO=ConvertResolutionY(135)eP=ConvertResolutionY(155)eQ=ConvertResolutionY(175)eS=ConvertResolutionY(115)eT=ConvertResolutionY(95)end;if BrakeIsOn then cd[#cd+1]=e([[Brake Engaged]],eN,eO)elseif t>0 then cd[#cd+1]=e([[Auto-Brake Engaged]],eN,eO,t)end;if ai and bg and hoverDetectGround()==-1 then cd[#cd+1]=e([[** STALL WARNING **]],eN,eS+50)end;if am then cd[#cd+1]=e([[Gyro Enabled]],eN,eU)end;if GearExtended then if F then cd[#cd+1]=e([[Gear Extended]],eN,eP)else cd[#cd+1]=e([[Landed (G: Takeoff)]],eN,eP)end;local dh,di=getDistanceDisplayString(Nav:getTargetGroundAltitude())cd[#cd+1]=e([[Hover Height: %s]],eN,eQ,dh..di)end;if T then cd[#cd+1]=e([[ROCKET BOOST ENABLED]],eN,eR+20)end;if antigrav and not ExternalAGG and antigrav.getState()==1 and AntigravTargetAltitude~=nil then if math.abs(aj-antigrav.getBaseAltitude())<501 then cd[#cd+1]=e([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],eN,eS+20,d(AntigravTargetAltitude),d(antigrav.getBaseAltitude()))else cd[#cd+1]=e([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],eN,eS+20,d(AntigravTargetAltitude),d(antigrav.getBaseAltitude()))end elseif Autopilot and AutopilotTargetName~="None"then cd[#cd+1]=e([[Autopilot %s]],eN,eS+20,AutopilotStatus)elseif LockPitch~=nil then cd[#cd+1]=e([[LockedPitch: %d]],eN,eS+20,d(LockPitch))elseif N then cd[#cd+1]=e([[Follow Mode Engaged]],eN,eS+20)elseif Reentry then cd[#cd+1]=e([[Re-entry in Progress]],eN,eS+20)end;local eV,eW,eX=b2:getPlanetarySystem(0):castIntersections(vec3(core.getConstructWorldPos()),ba:normalize(),function(eY)if eY.noAtmosphericDensityAltitude>0 then return eY.radius+eY.noAtmosphericDensityAltitude else return eY.radius+eY.surfaceMaxAltitude*1.5 end end)local eZ=eW;if eX~=nil and eW~=nil then eZ=math.min(eX,eW)end;if AltitudeHold then if AutoTakeoff then local dh,di=getDistanceDisplayString(HoldAltitude)cd[#cd+1]=e([[Ascent to %s]],eN,eS,dh..di)if BrakeIsOn then cd[#cd+1]=e([[Throttle Up and Disengage Brake For Takeoff]],eN,eS+50)end else local dh,di=getDistanceDisplayString2(HoldAltitude)cd[#cd+1]=e([[Altitude Hold: %s]],eN,eS,dh..di)end end;if BrakeLanding then if StrongBrakes then cd[#cd+1]=e([[Brake-Landing]],eN,eS)else cd[#cd+1]=e([[Coast-Landing]],eN,eS)end end;if ProgradeIsOn then cd[#cd+1]=e([[Prograde Alignment]],eN,eS)end;if RetrogradeIsOn then cd[#cd+1]=e([[Retrograde Alignment]],eN,eS)end;if TurnBurn then cd[#cd+1]=e([[Turn & Burn Braking]],eN,eT)elseif eZ~=nil and j()==0 then local dh,di=getDistanceDisplayString(eZ)local travelTime=b3.computeTravelTime(bb,0,eZ)local e_="Collision"if eV.noAtmosphericDensityAltitude>0 then e_="Atmosphere"end;cd[#cd+1]=e([[%s %s In %s (%s)]],eN,eT,eV.name,e_,FormatTimeString(travelTime),dh..di)end;if VectorToTarget then cd[#cd+1]=e([[%s]],eN,eS+30,VectorStatus)end;cd[#cd+1]=""end;function DisplayOrbitScreen(cd)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 f0=OrbitMapX;local f1=OrbitMapY;local f2=OrbitMapSize;local f3=4;f1=f1+f3;local f4=15;local bI=f0+f2+f0/2+f3;local bJ=f1+f2/2+5+f3;local f5,f6,f7,f8;f5=f2/4;f8=0;cd[#cd+1]=[[]]cd[#cd+1]=e('',f2+f0*2,f2+f1,f3,f3)if orbit.periapsis~=nil and orbit.apoapsis~=nil then f7=(orbit.apoapsis.altitude+orbit.periapsis.altitude+planet.radius*2)/(f5*2)f6=(planet.radius+orbit.periapsis.altitude+(orbit.apoapsis.altitude-orbit.periapsis.altitude)/2)/f7*(1-orbit.eccentricity)f8=f5-orbit.periapsis.altitude/f7-planet.radius/f7;local f9=""if orbit.periapsis.altitude<=0 then f9='redout'end;cd[#cd+1]=e([[]],f9,f0+f2/2+f8+f3,f1+f2/2+f3,f5,f6)cd[#cd+1]=e('',f0+f2/2+f3,f1+f2/2+f3,planet.radius/f7)end;if orbit.apoapsis~=nil and orbit.apoapsis.speed1 then cd[#cd+1]=e([[]],bI-35,bJ-5,f0+f2/2+f5+f8,bJ-5)cd[#cd+1]=e([[Apoapsis]],bI,bJ)bJ=bJ+f4;local dh,di=getDistanceDisplayString(orbit.apoapsis.altitude)cd[#cd+1]=e([[%s]],bI,bJ,dh..di)bJ=bJ+f4;cd[#cd+1]=e([[%s]],bI,bJ,FormatTimeString(orbit.timeToApoapsis))bJ=bJ+f4;cd[#cd+1]=e([[%s]],bI,bJ,getSpeedDisplayString(orbit.apoapsis.speed))end;bJ=f1+f2/2+5+f3;bI=f0-f0/2+10+f3;if orbit.periapsis~=nil and orbit.periapsis.speed1 then cd[#cd+1]=e([[]],bI+35,bJ-5,f0+f2/2-f5+f8,bJ-5)cd[#cd+1]=e([[Periapsis]],bI,bJ)bJ=bJ+f4;local dh,di=getDistanceDisplayString(orbit.periapsis.altitude)cd[#cd+1]=e([[%s]],bI,bJ,dh..di)bJ=bJ+f4;cd[#cd+1]=e([[%s]],bI,bJ,FormatTimeString(orbit.timeToPeriapsis))bJ=bJ+f4;cd[#cd+1]=e([[%s]],bI,bJ,getSpeedDisplayString(orbit.periapsis.speed))end;cd[#cd+1]=e([[%s]],f0+f2/2+f3,20+f3,planet.name)if orbit.period~=nil and orbit.periapsis~=nil and orbit.apoapsis~=nil and orbit.apoapsis.speed>1 then local fa=orbit.timeToApoapsis/orbit.period*2*math.pi;local fb=f5*math.cos(fa)local fc=f6*math.sin(fa)cd[#cd+1]=e('',f0+f2/2+fb+f8+f3,f1+f2/2+fc+f3)end;cd[#cd+1]=[[]]end end;function getDistanceDisplayString(a8)local fd=a8>100000;local bo,di=""if fd then bo,di=round(a8/1000/200,1),"SU"elseif a8<1000 then bo,di=round(a8,1),"m"else bo,di=round(a8/1000,1),"Km"end;return bo,di end;function getDistanceDisplayString2(a8)local fd=a8>100000;local bo,di=""if fd then bo,di=round(a8/1000/200,2)," SU"elseif a8<1000 then bo,di=round(a8,2)," M"else bo,di=round(a8/1000,2)," KM"end;return bo,di end;function getSpeedDisplayString(bC)return d(round(bC*3.6,0)+0.5).." km/h"end;function FormatTimeString(fe)local ff=0;local fg=0;local fh=0;if fe<60 then fe=d(fe)elseif fe<3600 then ff=d(fe/60)fe=d(fe%60)elseif fe<86400 then fg=d(fe/3600)ff=d(fe%3600/60)else fh=d(fe/86400)fg=d(fe%86400/3600)end;if fh>0 then return fh.."d "..fg.."h "elseif fg>0 then return fg.."h "..ff.."m "elseif ff>0 then return ff.."m "..fe.."s"elseif fe>0 then return fe.."s"else return"0s"end end;function getMagnitudeInDirection(da,fi)da=vec3(da)fi=vec3(fi):normalize()local bo=da*fi;return bo.x+bo.y+bo.z end;function UpdateAutopilotTarget()if AutopilotTargetIndex==0 then AutopilotTargetName="None"a0=nil;CustomTarget=nil;return true end;local fj=AtlasOrdered[AutopilotTargetIndex].index;local fk=aX[0][fj]if fk.center then AutopilotTargetName=fk.name;a0=b2[0][fj]if CustomTarget~=nil then if j()==0 then if system.updateData(widgetMaxBrakeTimeText,widgetMaxBrakeTime)~=1 then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;if system.updateData(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)~=1 then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;if system.updateData(widgetCurBrakeTimeText,widgetCurBrakeTime)~=1 then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;if system.updateData(widgetCurBrakeDistanceText,widgetCurBrakeDistance)~=1 then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;if system.updateData(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)~=1 then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;if system.updateData(widgetMaxMassText,widgetMaxMass)~=1 then system.addDataToWidget(widgetMaxMassText,widgetMaxMass)end;if system.updateData(widgetTravelTimeText,widgetTravelTime)~=1 then system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)end;if system.updateData(widgetTargetOrbitText,widgetTargetOrbit)~=1 then system.addDataToWidget(widgetTargetOrbitText,widgetTargetOrbit)end end;CustomTarget=nil else CustomTarget=fk;for _,bn in pairs(b2[0])do if bn.name==CustomTarget.planetname then a0=bn;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(a0.center)else AutopilotTargetCoords=CustomTarget.position end;if a0.planetname~="Space"then if a0.hasAtmosphere then AutopilotTargetOrbit=math.floor(a0.radius*(TargetOrbitRadius-1)+a0.noAtmosphericDensityAltitude)else AutopilotTargetOrbit=math.floor(a0.radius*(TargetOrbitRadius-1)+a0.surfaceMaxAltitude)end else AutopilotTargetOrbit=1000 end;if CustomTarget~=nil and CustomTarget.planetname=="Space"then AutopilotEndSpeed=0 else _,AutopilotEndSpeed=b5(a0):escapeAndOrbitalSpeed(AutopilotTargetOrbit)end;AutopilotPlanetGravity=0;AutopilotAccelerating=false;AutopilotBraking=false;AutopilotCruising=false;Autopilot=false;AutopilotRealigned=false;AutopilotStatus="Aligning"return true end;function IncrementAutopilotTargetIndex()AutopilotTargetIndex=AutopilotTargetIndex+1;if AutopilotTargetIndex>#AtlasOrdered then AutopilotTargetIndex=0 end;if AutopilotTargetIndex==0 then UpdateAutopilotTarget()else local fj=AtlasOrdered[AutopilotTargetIndex].index;local fk=aX[0][fj]if fk.name=="Space"then IncrementAutopilotTargetIndex()else UpdateAutopilotTarget()end end end;function DecrementAutopilotTargetIndex()AutopilotTargetIndex=AutopilotTargetIndex-1;if AutopilotTargetIndex<0 then AutopilotTargetIndex=#AtlasOrdered end;if AutopilotTargetIndex==0 then UpdateAutopilotTarget()else local fj=AtlasOrdered[AutopilotTargetIndex].index;local fk=aX[0][fj]if fk.name=="Space"then DecrementAutopilotTargetIndex()else UpdateAutopilotTarget()end end end;function GetAutopilotMaxMass()local fl=LastMaxBrakeInAtmo/a0:getGravity(a0.center+vec3(0,0,1)*a0.radius):len()return fl end;function GetAutopilotTravelTime()if not Autopilot then if CustomTarget==nil or CustomTarget.planetname~=planet.name then AutopilotDistance=(a0.center-vec3(core.getConstructWorldPos())):len()else AutopilotDistance=(CustomTarget.position-vec3(core.getConstructWorldPos())):len()end end;local ba=core.getWorldVelocity()local bC=vec3(ba):len()local fm=unit.getThrottle()/100;if AtmoSpeedAssist then fm=s end;local fn,fo=b3.computeDistanceAndTime(vec3(ba):len(),MaxGameVelocity,n(),Nav:maxForceForward()*fm,warmup,0)local U,V;if not TurnBurn then U,V=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else U,V=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;local _,fp;if not TurnBurn and bC>0 then _,fp=GetAutopilotBrakeDistanceAndTime(bC)else _,fp=GetAutopilotTBBrakeDistanceAndTime(bC)end;local fq=0;local fr=0;if AutopilotCruising or not Autopilot and bC>5 then fr=b3.computeTravelTime(bC,0,AutopilotDistance)elseif U+fn0 then return b3.computeDistanceAndTime(bC,AutopilotEndSpeed,n(),0,0,LastMaxBrakeInAtmo-AutopilotPlanetGravity*n())else return 0,0 end end end;function GetAutopilotTBBrakeDistanceAndTime(bC)RefreshLastMaxBrake()return b3.computeDistanceAndTime(bC,AutopilotEndSpeed,n(),Nav:maxForceForward(),warmup,LastMaxBrake-AutopilotPlanetGravity*n())end;function hoverDetectGround()local ft=-1;local fu=-1;if vBooster then ft=vBooster.distance()end;if hover then fu=hover.distance()end;if ft~=-1 and fu~=-1 then if ftProfileTimeMax then ProfileTimeMax=fA end;if fA0 then local fK=fH:find('identifiedConstructs":%[%]')if fK==nil and perisPanelID==nil then ab=1;ToggleRadarPanel()end;if fK~=nil and perisPanelID~=nil then ToggleRadarPanel()end;if radarPanelID==nil then ToggleRadarPanel()end;a9=e([[Radar: %i contacts]],fI,fJ,#fG)local fL={}for bm,bn in pairs(fG)do if radar_1.hasMatchingTransponder(bn)==1 then table.insert(fL,bn)end end;if#fL>0 then local bJ=ConvertResolutionY(15)local bI=ConvertResolutionX(1370)a9=e([[%sFriendlies In Range]],a9,bI,bJ)for bm,bn in pairs(fL)do bJ=bJ+20;a9=e([[%s%s]],a9,bI,bJ,radar_1.getConstructName(bn))end end else local fM;fM=fH:find('worksInEnvironment":false')if fM then a9=e([[ Radar: Jammed]],fI,fJ)else a9=e([[ - Radar: No Contacts]],fI,fJ)end;if radarPanelID~=nil then ab=0;ToggleRadarPanel()end end end end;function DisplayMessage(cd,dh)if dh~="empty"then cd[#cd+1]=[[]]for fN in string.gmatch(dh,"([^\n]+)")do cd[#cd+1]=e([[%s]],fN)end;cd[#cd+1]=[[]]end;if a7~=0 then unit.setTimer("msgTick",a7)a7=0 end end;function updateDistance()local bv=system.getTime()local ba=vec3(core.getWorldVelocity())local dB=vec3(ba):len()local fO=bv-al;if dB>1.38889 then dB=dB/1000;local fP=dB*(bv-al)TotalDistanceTravelled=TotalDistanceTravelled+fP;a1=a1+fP end;a2=a2+fO;TotalFlightTime=TotalFlightTime+fO;al=bv end;function composeAxisAccelerationFromTargetSpeed(fQ,fR)local fS=vec3()local fT=vec3()if fQ==axisCommandId.longitudinal then fS=vec3(core.getConstructOrientationForward())fT=vec3(core.getConstructWorldOrientationForward())elseif fQ==axisCommandId.vertical then fS=vec3(core.getConstructOrientationUp())fT=vec3(core.getConstructWorldOrientationUp())elseif fQ==axisCommandId.lateral then fS=vec3(core.getConstructOrientationRight())fT=vec3(core.getConstructWorldOrientationRight())else return vec3()end;local fU=vec3(core.getWorldGravity())local fV=fU:dot(fT)local fW=vec3(core.getWorldAirFrictionAcceleration())local fX=fW:dot(fT)local fY=vec3(core.getVelocity())local fZ=fY:dot(fS)local f_=fR*constants.kph2m;if targetSpeedPID==nil then targetSpeedPID=pid.new(1,0,10.0)end;targetSpeedPID:inject(f_-fZ)local g0=targetSpeedPID:get()local g1=(g0-fX-fV)*fT;return g1 end;function Atlas()return{[0]={[0]={GM=0,bodyId=0,center={x=0,y=0,z=0},name='Space',planetarySystemId=0,radius=0,hasAtmosphere=false,gravity=0,noAtmosphericDensityAltitude=0,surfaceMaxAltitude=0},[2]={name="Alioth",description="Alioth is the planet selected by the arkship for landfall; it is a typical goldilocks planet where humanity may rebuild in the coming decades. The arkship geological survey reports mountainous regions alongside deep seas and lush forests. This is where it all starts.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9401,atmosphericEngineMaxAltitude=5580,biosphere="Forest",classification="Mesoplanet",bodyId=2,GM=157470826617,gravity=1.0082568597356114,fullAtmosphericDensityMaxAltitude=-10,habitability="High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=6272,numSatellites=2,positionFromSun=2,center={x=-8,y=-8,z=-126303},radius=126067.8984375,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=3410,surfaceArea=199718780928,surfaceAverageAltitude=200,surfaceMaxAltitude=1100,surfaceMinAltitude=-330,systemZone="High",territories=259472,type="Planet",waterLevel=0,planetarySystemId=0},[21]={name="Alioth Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=21,GM=2118960000,gravity=0.24006116402380084,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=457933,y=-1509011,z=115524},radius=30000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=11309733888,surfaceAverageAltitude=140,surfaceMaxAltitude=200,surfaceMinAltitude=10,systemZone=nil,territories=14522,type="",waterLevel=nil,planetarySystemId=0},[22]={name="Alioth Moon 4",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=22,GM=2165833514,gravity=0.2427018259886451,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-1692694,y=729681,z=-411464},radius=30330,safeAreaEdgeAltitude=500000,size="L",spaceEngineMinAltitude=0,surfaceArea=11559916544,surfaceAverageAltitude=-15,surfaceMaxAltitude=-5,surfaceMinAltitude=-50,systemZone=nil,territories=14522,type="",waterLevel=nil,planetarySystemId=0},[5]={name="Feli",description="Feli is easily identified by its massive and deep crater. Outside of the crater, the arkship geological survey reports a fairly bland and uniform planet, it also cannot explain the existence of the crater. Feli is particular for having an extremely small atmosphere, allowing life to develop in the deeper areas of its crater but limiting it drastically on the actual surface.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.5488,atmosphericEngineMaxAltitude=66725,biosphere="Barren",classification="Mesoplanet",bodyId=5,GM=16951680000,gravity=0.4801223280476017,fullAtmosphericDensityMaxAltitude=30,habitability="Low",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=78500,numSatellites=1,positionFromSun=5,center={x=-43534464,y=22565536,z=-48934464},radius=41800,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=42800,surfaceArea=21956466688,surfaceAverageAltitude=18300,surfaceMaxAltitude=18500,surfaceMinAltitude=46,systemZone="Low",territories=27002,type="Planet",waterLevel=nil,planetarySystemId=0},[50]={name="Feli Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=50,GM=499917600,gravity=0.11202853997062348,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-43902841.78,y=22261034.7,z=-48862386},radius=14000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=2463008768,surfaceAverageAltitude=800,surfaceMaxAltitude=900,surfaceMinAltitude=0,systemZone=nil,territories=3002,type="",waterLevel=nil,planetarySystemId=0},[120]={name="Ion",description="Ion is nothing more than an oversized ice cube frozen through and through. It is a largely inhospitable planet due to its extremely low temperatures. The arkship geological survey reports extremely rough mountainous terrain with little habitable land.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9522,atmosphericEngineMaxAltitude=10480,biosphere="Ice",classification="Hypopsychroplanet",bodyId=120,GM=7135606629,gravity=0.36009174603570127,fullAtmosphericDensityMaxAltitude=-30,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=17700,numSatellites=2,positionFromSun=12,center={x=2865536.7,y=-99034464,z=-934462.02},radius=44950,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=6410,surfaceArea=25390383104,surfaceAverageAltitude=500,surfaceMaxAltitude=1300,surfaceMinAltitude=250,systemZone="Average",territories=32672,type="Planet",waterLevel=nil,planetarySystemId=0},[121]={name="Ion Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=121,GM=106830900,gravity=0.08802242599860607,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=2472916.8,y=-99133747,z=-1133582.8},radius=11000,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=0,surfaceArea=1520530944,surfaceAverageAltitude=100,surfaceMaxAltitude=200,surfaceMinAltitude=3,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[122]={name="Ion Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=122,GM=176580000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=2995424.5,y=-99275010,z=-1378480.7},radius=15000,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=-1900,surfaceMaxAltitude=-1400,surfaceMinAltitude=-2100,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[9]={name="Jago",description="Jago is a water planet. The large majority of the planet's surface is covered by large oceans dotted by small areas of landmass across the planet. The arkship geological survey reports deep seas across the majority of the planet with sub 15 percent coverage of solid ground.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9835,atmosphericEngineMaxAltitude=9695,biosphere="Water",classification="Mesoplanet",bodyId=9,GM=18606274330,gravity=0.5041284298678057,fullAtmosphericDensityMaxAltitude=-90,habitability="Very High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=10900,numSatellites=0,positionFromSun=9,center={x=-94134462,y=12765534,z=-3634464},radius=61590,safeAreaEdgeAltitude=500000,size="XL",spaceEngineMinAltitude=5900,surfaceArea=47668367360,surfaceAverageAltitude=0,surfaceMaxAltitude=1200,surfaceMinAltitude=-500,systemZone="Very High",territories=60752,type="Planet",waterLevel=0,planetarySystemId=0},[100]={name="Lacobus",description="Lacobus is an ice planet that also features large bodies of water. The arkship geological survey reports deep oceans alongside a frozen and rough mountainous environment. Lacobus seems to feature regional geothermal activity allowing for the presence of water on the surface.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.7571,atmosphericEngineMaxAltitude=11120,biosphere="Ice",classification="Psychroplanet",bodyId=100,GM=13975172474,gravity=0.45611622622739767,fullAtmosphericDensityMaxAltitude=-20,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=12510,numSatellites=3,positionFromSun=10,center={x=98865536,y=-13534464,z=-934461.99},radius=55650,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=6790,surfaceArea=38917074944,surfaceAverageAltitude=800,surfaceMaxAltitude=1660,surfaceMinAltitude=250,systemZone="Average",territories=50432,type="Planet",waterLevel=0,planetarySystemId=0},[102]={name="Lacobus Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=102,GM=444981600,gravity=0.14403669598391783,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=99180968,y=-13783862,z=-926156.4},radius=18000,safeAreaEdgeAltitude=500000,size="XL",spaceEngineMinAltitude=0,surfaceArea=4071504128,surfaceAverageAltitude=150,surfaceMaxAltitude=300,surfaceMinAltitude=10,systemZone=nil,territories=5072,type="",waterLevel=nil,planetarySystemId=0},[103]={name="Lacobus Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=103,GM=211503600,gravity=0.11202853997062348,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=99250052,y=-13629215,z=-1059341.4},radius=14000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2463008768,surfaceAverageAltitude=-1380,surfaceMaxAltitude=-1280,surfaceMinAltitude=-1880,systemZone=nil,territories=3002,type="",waterLevel=nil,planetarySystemId=0},[101]={name="Lacobus Moon 3",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=101,GM=264870000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=98905288.17,y=-13950921.1,z=-647589.53},radius=15000,safeAreaEdgeAltitude=500000,size="L",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=500,surfaceMaxAltitude=820,surfaceMinAltitude=3,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[1]={name="Madis",description="Madis is a barren wasteland of a rock; it sits closest to the sun and temperatures reach extreme highs during the day. The arkship geological survey reports long rocky valleys intermittently separated by small ravines.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.8629,atmosphericEngineMaxAltitude=7165,biosphere="Barren",classification="hyperthermoplanet",bodyId=1,GM=6930729684,gravity=0.36009174603570127,fullAtmosphericDensityMaxAltitude=220,habitability="Low",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=8050,numSatellites=3,positionFromSun=1,center={x=17465536,y=22665536,z=-34464},radius=44300,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=4480,surfaceArea=24661377024,surfaceAverageAltitude=750,surfaceMaxAltitude=850,surfaceMinAltitude=670,systemZone="Low",territories=30722,type="Planet",waterLevel=nil,planetarySystemId=0},[10]={name="Madis Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=10,GM=78480000,gravity=0.08002039003323584,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=17448118.224,y=22966846.286,z=143078.82},radius=10000,safeAreaEdgeAltitude=500000,size="XL",spaceEngineMinAltitude=0,surfaceArea=1256637056,surfaceAverageAltitude=210,surfaceMaxAltitude=420,surfaceMinAltitude=0,systemZone=nil,territories=1472,type="",waterLevel=nil,planetarySystemId=0},[11]={name="Madis Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=11,GM=237402000,gravity=0.09602446196397631,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=17194626,y=22243633.88,z=-214962.81},radius=12000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=1809557376,surfaceAverageAltitude=-700,surfaceMaxAltitude=300,surfaceMinAltitude=-2900,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[12]={name="Madis Moon 3",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=12,GM=265046609,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=17520614,y=22184730,z=-309989.99},radius=15000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=700,surfaceMaxAltitude=1100,surfaceMinAltitude=0,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[26]={name="Sanctuary",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9666,atmosphericEngineMaxAltitude=6935,biosphere="",classification="",bodyId=26,GM=68234043600,gravity=1.0000000427743831,fullAtmosphericDensityMaxAltitude=-30,habitability="",hasAtmosphere=true,isSanctuary=true,noAtmosphericDensityAltitude=7800,numSatellites=0,positionFromSun=0,center={x=-1404835,y=562655,z=-285074},radius=83400,safeAreaEdgeAltitude=0,size="L",spaceEngineMinAltitude=4230,surfaceArea=87406149632,surfaceAverageAltitude=80,surfaceMaxAltitude=500,surfaceMinAltitude=-60,systemZone=nil,territories=111632,type="",waterLevel=0,planetarySystemId=0},[6]={name="Sicari",description="Sicari is a typical desert planet; it has survived for millenniums and will continue to endure. While not the most habitable of environments it remains a relatively untouched and livable planet of the Alioth sector. The arkship geological survey reports large flatlands alongside steep plateaus.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.897,atmosphericEngineMaxAltitude=7725,biosphere="Desert",classification="Mesoplanet",bodyId=6,GM=10502547741,gravity=0.4081039739797361,fullAtmosphericDensityMaxAltitude=-625,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=8770,numSatellites=0,positionFromSun=6,center={x=52765536,y=27165538,z=52065535},radius=51100,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=4480,surfaceArea=32813432832,surfaceAverageAltitude=130,surfaceMaxAltitude=220,surfaceMinAltitude=50,systemZone="Average",territories=41072,type="Planet",waterLevel=nil,planetarySystemId=0},[7]={name="Sinnen",description="Sinnen is a an empty and rocky hell. With no atmosphere to speak of it is one of the least hospitable planets in the sector. The arkship geological survey reports mostly flatlands alongside deep ravines which look to have once been riverbeds. This planet simply looks to have dried up and died, likely from solar winds.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9226,atmosphericEngineMaxAltitude=10335,biosphere="Desert",classification="Mesoplanet",bodyId=7,GM=13033380591,gravity=0.4401121421448438,fullAtmosphericDensityMaxAltitude=-120,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=11620,numSatellites=1,positionFromSun=7,center={x=58665538,y=29665535,z=58165535},radius=54950,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=6270,surfaceArea=37944188928,surfaceAverageAltitude=317,surfaceMaxAltitude=360,surfaceMinAltitude=23,systemZone="Average",territories=48002,type="Planet",waterLevel=nil,planetarySystemId=0},[70]={name="Sinnen Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=70,GM=396912600,gravity=0.1360346539426409,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=58969616,y=29797945,z=57969449},radius=17000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=3631681280,surfaceAverageAltitude=-2050,surfaceMaxAltitude=-1950,surfaceMinAltitude=-2150,systemZone=nil,territories=4322,type="",waterLevel=nil,planetarySystemId=0},[110]={name="Symeon",description="Symeon is an ice planet mysteriously split at the equator by a band of solid desert. Exactly how this phenomenon is possible is unclear but some sort of weather anomaly may be responsible. The arkship geological survey reports a fairly diverse mix of flat-lands alongside mountainous formations.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9559,atmosphericEngineMaxAltitude=6920,biosphere="Ice, Desert",classification="Hybrid",bodyId=110,GM=9204742375,gravity=0.3920998898971822,fullAtmosphericDensityMaxAltitude=-30,habitability="High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=7800,numSatellites=0,positionFromSun=11,center={x=14165536,y=-85634465,z=-934464.3},radius=49050,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=4230,surfaceArea=30233462784,surfaceAverageAltitude=39,surfaceMaxAltitude=450,surfaceMinAltitude=126,systemZone="High",territories=38882,type="Planet",waterLevel=nil,planetarySystemId=0},[4]={name="Talemai",description="Talemai is a planet in the final stages of an Ice Age. It seems likely that the planet was thrown into tumult by a cataclysmic volcanic event which resulted in its current state. The arkship geological survey reports large mountainous regions across the entire planet.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.8776,atmosphericEngineMaxAltitude=9685,biosphere="Barren",classification="Psychroplanet",bodyId=4,GM=14893847582,gravity=0.4641182439650478,fullAtmosphericDensityMaxAltitude=-78,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=10890,numSatellites=3,positionFromSun=4,center={x=-13234464,y=55765536,z=465536},radius=57500,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=5890,surfaceArea=41547563008,surfaceAverageAltitude=580,surfaceMaxAltitude=610,surfaceMinAltitude=520,systemZone="Average",territories=52922,type="Planet",waterLevel=nil,planetarySystemId=0},[42]={name="Talemai Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=42,GM=264870000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-13058408,y=55781856,z=740177.76},radius=15000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=720,surfaceMaxAltitude=850,surfaceMinAltitude=0,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[40]={name="Talemai Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=40,GM=141264000,gravity=0.09602446196397631,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-13503090,y=55594325,z=769838.64},radius=12000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=1809557376,surfaceAverageAltitude=250,surfaceMaxAltitude=450,surfaceMinAltitude=0,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[41]={name="Talemai Moon 3",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=41,GM=106830900,gravity=0.08802242599860607,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-12800515,y=55700259,z=325207.84},radius=11000,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=0,surfaceArea=1520530944,surfaceAverageAltitude=190,surfaceMaxAltitude=400,surfaceMinAltitude=0,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[8]={name="Teoma",description="[REDACTED] The arkship geological survey [REDACTED]. This planet should not be here.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.7834,atmosphericEngineMaxAltitude=5580,biosphere="Forest",classification="Mesoplanet",bodyId=8,GM=18477723600,gravity=0.48812434578525177,fullAtmosphericDensityMaxAltitude=15,habitability="High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=6280,numSatellites=0,positionFromSun=8,center={x=80865538,y=54665536,z=-934463.94},radius=62000,safeAreaEdgeAltitude=500000,size="L",spaceEngineMinAltitude=3420,surfaceArea=48305131520,surfaceAverageAltitude=700,surfaceMaxAltitude=1100,surfaceMinAltitude=-200,systemZone="High",territories=60752,type="Planet",waterLevel=0,planetarySystemId=0},[3]={name="Thades",description="Thades is a scorched desert planet. Perhaps it was once teaming with life but now all that remains is ash and dust. The arkship geological survey reports a rocky mountainous planet bisected by a massive unnatural ravine; something happened to this planet.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.03552,atmosphericEngineMaxAltitude=32180,biosphere="Desert",classification="Thermoplanet",bodyId=3,GM=11776905000,gravity=0.49612641213015557,fullAtmosphericDensityMaxAltitude=150,habitability="Low",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=32800,numSatellites=2,positionFromSun=3,center={x=29165536,y=10865536,z=65536},radius=49000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=21400,surfaceArea=30171856896,surfaceAverageAltitude=13640,surfaceMaxAltitude=13690,surfaceMinAltitude=370,systemZone="Low",territories=38882,type="Planet",waterLevel=nil,planetarySystemId=0},[30]={name="Thades Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=30,GM=211564034,gravity=0.11202853997062348,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=29214402,y=10907080.695,z=433858.2},radius=14000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2463008768,surfaceAverageAltitude=60,surfaceMaxAltitude=300,surfaceMinAltitude=0,systemZone=nil,territories=3002,type="",waterLevel=nil,planetarySystemId=0},[31]={name="Thades Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=31,GM=264870000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=29404193,y=10432768,z=19554.131},radius=15000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=70,surfaceMaxAltitude=350,surfaceMinAltitude=0,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0}}}end;function SetupAtlas()aX=Atlas()for bm,bn in pairs(aX[0])do if aA==nil or bn.center.xaB then aB=bn.center.x end;if aC==nil or bn.center.yaD then aD=bn.center.y end end;aY=""local g2=1.1*(aB-aA)/1920;local g3=1.4*(aD-aC)/1080;for bm,bn in pairs(aX[0])do local bI=960+bn.center.x/g2;local bJ=540+bn.center.y/g3;aY=aY..''if not string.match(bn.name,"Moon")and not string.match(bn.name,"Sanctuary")and not string.match(bn.name,"Space")then aY=aY..""..bn.name..""end end;local c0=vec3(core.getConstructWorldPos())local bI=960+c0.x/g2;local bJ=540+c0.y/g3;aY=aY..''aY=aY.."You Are Here"aY=aY..[[]]aZ=g2;a_=g3;if screen_2 then screen_2.setHTML(''..aY)local c0=vec3(core.getConstructWorldPos())local bI=960+c0.x/g2;local bJ=540+c0.y/g3;aY=''aY=aY.."You Are Here"b0=screen_2.addContent((bI-80)/19.20,(bJ-80)/10.80,aY)end end;function PlanetRef()local function g4(g5)return type(g5)=='number'end;local function g6(g5)return type(tonumber(g5))=='number'end;local function g7(g8)return type(g8)=='table'end;local function g9(ga)return type(ga)=='string'end;local function gb(bn)return g7(bn)and g4(bn.x and bn.y and bn.z)end;local function gc(gd)return g7(gd)and g4(gd.latitude and gd.longitude and gd.altitude and gd.bodyId and gd.systemId)end;local ge=math.pi/180;local gf=180/math.pi;local epsilon=1e-10;local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local c1='::pos{'..p..','..p..','..p..','..p..','..p..'}'local utils=require('cpml.utils')local vec3=require('cpml.vec3')local gg=utils.clamp;local function float_eq(bR,bS)if bR==0 then return math.abs(bS)<1e-09 end;if bS==0 then return math.abs(bR)<1e-09 end;return math.abs(bR-bS)=0 then local h4=math.sqrt(h3)local eW=h2+h4;local eX=h2-h4;if eX>0 then return eY,eW,eX elseif eW>0 then return eY,eW,nil end end end;return nil,nil,nil end;function gx:closestBody(h5)assert(type(h5)=='table','Invalid coordinates.')local h6,eY;local h7=vec3(h5)for _,h8 in pairs(self)do local h9=(h8.center-h7):len2()if(not eY or h9=0 and b_ or 2*math.pi+b_;bY=math.pi/2-math.acos(bW.z/a8)end;return setmetatable({latitude=bY,longitude=bZ,altitude=bX,bodyId=self.bodyId,systemId=self.planetarySystemId},MapPosition)end;function gm:convertToWorldCoordinates(gw)local ha=g9(gw)and gv(gw)or gw;if ha.bodyId==0 then return vec3(ha.latitude,ha.longitude,ha.altitude)end;assert(gc(ha),'Argument 1 (mapPosition) is not an instance of "MapPosition".')assert(ha.systemId==self.planetarySystemId,'Argument 1 (mapPosition) has a different planetary system ID.')assert(ha.bodyId==self.bodyId,'Argument 1 (mapPosition) has a different planetary body ID.')local c4=math.cos(ha.latitude)return self.center+(self.radius+ha.altitude)*vec3(c4*math.cos(ha.longitude),c4*math.sin(ha.longitude),math.sin(ha.latitude))end;function gm:getAltitude(bU)return(vec3(bU)-self.center):len()-self.radius end;function gm:getDistance(bU)return(vec3(bU)-self.center):len()end;function gm:getGravity(bU)local hb=self.center-vec3(bU)local hc=hb:len2()return self.GM/hc*hb/math.sqrt(hc)end;return setmetatable(b1,{__call=function(_,...)return gF(...)end})end;function Keplers()local vec3=require('cpml.vec3')local PlanetRef=PlanetRef()local function g9(ga)return type(ga)=='string'end;local function g7(g8)return type(g8)=='table'end;local function float_eq(bR,bS)if bR==0 then return math.abs(bS)<1e-09 end;if bS==0 then return math.abs(bR)<1e-09 end;return math.abs(bR-bS)0 then ht=hs;hu=ht+hn/2 end;if hu>hn then hu=hu-hn end end;return{periapsis={position=hk,speed=hm/hi,circularOrbitSpeed=math.sqrt(hf/hi),altitude=hi-self.body.radius},apoapsis=hl and{position=hl,speed=hm/hj,circularOrbitSpeed=math.sqrt(hf/hj),altitude=hj-self.body.radius},currentVelocity=bn,currentPosition=c0,eccentricity=hh,period=hn,eccentricAnomaly=hp,meanAnomaly=hr,timeToPeriapsis=ht,timeToApoapsis=hu}end;local function hv(hw)local h8=PlanetRef.BodyParameters(hw.planetarySystemId,hw.bodyId,hw.radius,hw.center,hw.GM)return setmetatable({body=h8},Kepler)end;return setmetatable(Kepler,{__call=function(_,...)return hv(...)end})end;function Kinematics()local b3={}local hx=30000000/3600;local hy=hx*hx;local hz=100;local function hA(bn)return 1/math.sqrt(1-bn*bn/hy)end;function b3.computeAccelerationTime(hB,hC,hD)local hE=hx*math.asin(hB/hx)return(hx*math.asin(hD/hx)-hE)/hC end;function b3.computeDistanceAndTime(hB,hD,hF,hG,hH,hI)hH=hH or 0;hI=hI or 0;local hJ=hB<=hD;local hK=hG*(hJ and 1 or-1)/hF;local hL=-hI/hF;local hM=hK+hL;if hJ and hM<=0 or not hJ and hM>=0 then return-1,-1 end;local hN,hO=0,0;if hK~=0 and hH>0 then local hE=math.asin(hB/hx)local hP=math.pi*(hK/2+hL)local hQ=hK*hH;local hR=hx*math.pi;local bn=function(g8)local cF=(hP*g8-hQ*math.sin(math.pi*g8/2/hH)+hR*hE)/hR;local hS=math.tan(cF)return hx*hS/math.sqrt(hS*hS+1)end;local hT=hJ and function(ga)return ga>=hD end or function(ga)return ga<=hD end;hO=2*hH;if hT(bn(hO))then local hU=0;while math.abs(hO-hU)>0.5 do local g8=(hO+hU)/2;if hT(bn(g8))then hO=g8 else hU=g8 end end end;local hV=hB;local hW=hO/hz;for hX=1,hz do local bC=bn(hX*hW)hN=hN+(bC+hV)*hW/2;hV=bC end;if hO<2*hH then return hN,hO end;hB=hV end;local hE=hx*math.asin(hB/hx)local bp=(hx*math.asin(hD/hx)-hE)/hM;local hY=hy*math.cos(hE/hx)/hM;local a8=hY-hy*math.cos((hM*bp+hE)/hx)/hM;return a8+hN,bp+hO end;function b3.computeTravelTime(hB,hC,a8)if a8==0 then return 0 end;if hC>0 then local hE=hx*math.asin(hB/hx)local hY=hy*math.cos(hE/hx)/hC;return(hx*math.acos(hC*(hY-a8)/hy)-hE)/hC end;if hB==0 then return-1 end;assert(hB>0,'Acceleration and initial speed are both zero.')return a8/hB end;function b3.lorentz(bn)return hA(bn)end;return b3 end;function script.onStart()VERSION_NUMBER=5.300;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()b1=PlanetRef()b2=b1(Atlas())b3=Kinematics()b5=Keplers()AddLocationsToAtlas()UpdateAtlasLocationsList()UpdateAutopilotTarget()coroutine.yield()unit.hide()system.showScreen(1)collectgarbage("collect")coroutine.yield()unit.setTimer("apTick",apTickRate)unit.setTimer("hudTick",hudTickRate)unit.setTimer("oneSecond",1)unit.setTimer("tenthSecond",1/10)if UseSatNav then unit.setTimer("fiveSecond",5)end end)end;function SaveDataBank(hZ)if dbHud_1 then if not a3 then for bm,bn in pairs(b)do dbHud_1.setStringValue(bn,g(_G[bn]))if hZ and dbHud_2 then dbHud_2.setStringValue(bn,g(_G[bn]))end end;for bm,bn in pairs(a)do dbHud_1.setStringValue(bn,g(_G[bn]))if hZ and dbHud_2 then dbHud_2.setStringValue(bn,g(_G[bn]))end end;c("Saved Variables to Datacore")if hZ and dbHud_2 then P="Databank copied. Remove copy when ready."end 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 bx=j()if door and(bx>0 or bx==0 and aj<10000)then for _,bn in pairs(door)do bn.toggle()end end;if switch then for _,bn in pairs(switch)do bn.toggle()end end;if forcefield and(bx>0 or bx==0 and aj<10000)then for _,bn in pairs(forcefield)do bn.toggle()end end;SaveDataBank()if button then button.activate()end end;function script.onTick(h_)if h_=="tenthSecond"then if AutopilotTargetName~="None"then if panelInterplanetary==nil then SetupInterplanetaryPanel()end;if AutopilotTargetName~=nil then local i0=CustomTarget~=nil;planetMaxMass=GetAutopilotMaxMass()system.updateData(interplanetaryHeaderText,'{"label": "Target", "value": "'..AutopilotTargetName..'", "unit":""}')travelTime=GetAutopilotTravelTime()if i0 and not Autopilot then a8=(vec3(core.getConstructWorldPos())-CustomTarget.position):len()else a8=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()end;if not TurnBurn then U,V=GetAutopilotBrakeDistanceAndTime(bb)W,X=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else U,V=GetAutopilotTBBrakeDistanceAndTime(bb)W,X=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;local dh,di=getDistanceDisplayString(a8)system.updateData(widgetDistanceText,'{"label": "distance", "value": "'..dh..'", "unit":"'..di..'"}')system.updateData(widgetTravelTimeText,'{"label": "Travel Time", "value": "'..FormatTimeString(travelTime)..'", "unit":""}')dh,di=getDistanceDisplayString(U)system.updateData(widgetCurBrakeDistanceText,'{"label": "Cur Brake distance", "value": "'..dh..'", "unit":"'..di..'"}')system.updateData(widgetCurBrakeTimeText,'{"label": "Cur Brake Time", "value": "'..FormatTimeString(V)..'", "unit":""}')dh,di=getDistanceDisplayString(W)system.updateData(widgetMaxBrakeDistanceText,'{"label": "Max Brake distance", "value": "'..dh..'", "unit":"'..di..'"}')system.updateData(widgetMaxBrakeTimeText,'{"label": "Max Brake Time", "value": "'..FormatTimeString(X)..'", "unit":""}')system.updateData(widgetMaxMassText,'{"label": "Maximum Mass", "value": "'..e("%.2f",planetMaxMass/1000)..'", "unit":" Tons"}')dh,di=getDistanceDisplayString(AutopilotTargetOrbit)system.updateData(widgetTargetOrbitText,'{"label": "Target Orbit", "value": "'..e("%.2f",dh)..'", "unit":"'..di..'"}')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;if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle then elseif AtmoSpeedAssist then s=1;Nav.control.cancelCurrentControlMasterMode()w=false end 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 h_=="oneSecond"then ag=false;RefreshLastMaxBrake(nil,true)updateDistance()updateRadar()updateWeapons()local cd={}local dr=GetFlightStyle()DrawOdometer(cd,a1,TotalDistanceTravelled,dr,a2)if ShouldCheckDamage then CheckDamage(cd)end;aa=table.concat(cd,"")collectgarbage("collect")elseif h_=="fiveSecond"then ah=dbHud_1.getStringValue("SPBAutopilotTargetName")if ah~=nil and ah~=""and ah~="SatNavNotChanged"then local bo=json.decode(dbHud_1.getStringValue("SavedLocations"))if bo~=nil then _G["SavedLocations"]=bo;local cb=-1;local c7;for bm,bn in pairs(SavedLocations)do if bn.name and bn.name=="SatNav Location"then cb=bm;break end end;if cb~=-1 then c7=SavedLocations[cb]cb=-1;for bm,bn in pairs(aX[0])do if bn.name and bn.name=="SatNav Location"then cb=bm;break end end;if cb>-1 then aX[0][cb]=c7 end;UpdateAtlasLocationsList()P=c7.name.." position updated"end end;for i=1,#AtlasOrdered do if AtlasOrdered[i].name==ah then AutopilotTargetIndex=i;system.print("Index = "..AutopilotTargetIndex.." "..AtlasOrdered[i].name)UpdateAutopilotTarget()dbHud_1.setStringValue("SPBAutopilotTargetName","SatNavNotChanged")break end end end elseif h_=="msgTick"then local cd={}DisplayMessage(cd,"empty")P="empty"unit.stopTimer("msgTick")a7=3 elseif h_=="animateTick"then b7=true;b6=false;a5=0;a6=0;unit.stopTimer("animateTick")elseif h_=="hudTick"then local cd={}HUDPrologue(cd)if showHud then UpdateHud(cd)else DisplayOrbitScreen(cd)DrawWarnings(cd)end;HUDEpilogue(cd)cd[#cd+1]=e([[]],ResolutionX,ResolutionY)if P~="empty"then DisplayMessage(cd,P)end;if o()==0 and userControlScheme=="virtual joystick"then DrawDeadZone(cd)end;if o()==1 and screen_1 and screen_1.getMouseY()~=-1 then SetButtonContains()DrawButtons(cd)if screen_1.getMouseState()==1 then CheckButtons()end;cd[#cd+1]=e([[]],x,y,a5,a6)elseif system.isViewLocked()==0 then if o()==1 and O then SetButtonContains()DrawButtons(cd)if not b6 and not b7 then local i1=table.concat(cd,"")cd={}cd[#cd+1]=e("",ResolutionX,ResolutionY)cd[#cd+1]=aY;cd[#cd+1]=i1;cd[#cd+1]=""b6=true;cd[#cd+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(cd,"")system.setScreen(content)elseif b7 then local i1=table.concat(cd,"")cd={}cd[#cd+1]=e("",ResolutionX,ResolutionY)cd[#cd+1]=aY;cd[#cd+1]=i1;cd[#cd+1]=""end;if not b6 then cd[#cd+1]=e([[]],x,y,a5,a6)end else CheckButtons()end else if not O and o()==0 then CheckButtons()if a8>DeadZone then DrawCursorLine(cd)end else SetButtonContains()DrawButtons(cd)end;cd[#cd+1]=e([[]],x,y,a5,a6)end;cd[#cd+1]=[[]]content=table.concat(cd,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end elseif h_=="apTick"then b9=vec3(core.getConstructWorldOrientationForward()):dot(vec3(core.getWorldVelocity()):normalize())ai=j()>0;local bp=system.getTime()local i2=bp-bh;bh=bp;local cg=vec3(core.getConstructWorldOrientationForward())local ch=vec3(core.getConstructWorldOrientationRight())local i3=vec3(core.getConstructWorldOrientationUp())local ci=vec3(core.getWorldVertical())local i4=vec3(core.getConstructWorldPos())local i5=core.getVelocity()local dt=getRoll(ci,cg,ch)local du=dt/180*math.pi;local dv=math.cos(du)local dw=math.sin(du)local cj=getPitch(ci,cg,ch)local i6=getPitch(ci,cg,ch*dv+i3*dw)local i7=-math.deg(cA(i3,ba,cg))local i8=math.deg(cA(ch,ba,cg))bg=ai and i7<-YawStallAngle or i7>YawStallAngle or i8<-PitchStallAngle or i8>PitchStallAngle;local i9=150;be=system.getMouseDeltaX()bf=system.getMouseDeltaY()if InvertMouse and not O then bf=-bf end;I=0;M=0;H=0;ba=vec3(core.getWorldVelocity())bb=vec3(ba):len()sys=b2[0]planet=sys:closestBody(core.getConstructWorldPos())kepPlanet=b5(planet)orbit=kepPlanet:orbitalParameters(core.getConstructWorldPos(),ba)af=hoverDetectGround()local bz=planet:getGravity(core.getConstructWorldPos()):len()*n()bi=0;b4=core.getMaxKinematicsParametersAlongAxis("ground",core.getConstructOrientationUp())[1]if o()==1 and screen_1 and screen_1.getMouseY()~=-1 then a5=screen_1.getMouseX()*ResolutionX;a6=screen_1.getMouseY()*ResolutionY elseif system.isViewLocked()==0 then if o()==1 and O then if not b6 then a5=a5+be;a6=a6+bf end else a5=0;a6=0 end else a5=a5+be;a6=a6+bf;a8=math.sqrt(a5*a5+a6*a6)if not O and o()==0 then if userControlScheme=="virtual joystick"then if a5>0 and a5>DeadZone then I=I-(a5-DeadZone)*MouseXSensitivity elseif a5<0 and a50 and a6>DeadZone then H=H-(a6-DeadZone)*MouseYSensitivity elseif a6<0 and a68334;if bb>SpaceSpeedLimit/3.6 and not ai and not Autopilot and not ia then P="Space Speed Engine Shutoff reached"if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0 end;if not ia and LastIsWarping then if not BrakeIsOn then BrakeToggle()end;if Autopilot then ToggleAutopilot()end end;LastIsWarping=ia;if ai and j()>0.09 then if bb>bk/3.6 and not AtmoSpeedAssist and not an then BrakeIsOn=true;an=true elseif not AtmoSpeedAssist and an then if bb85)and bb>=bk/3.6-1 then BrakeIsOn=false;ProgradeIsOn=false;C=true;ac=false;ae=true;Autopilot=false;BeginReentry()else if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,math.floor(bk))s=0 end elseif bb>B then AlignToWorldVector(vec3(ba),0.01)end end;if RetrogradeIsOn then if ai then RetrogradeIsOn=false elseif bb>B then AlignToWorldVector(-vec3(ba))end end;if not ProgradeIsOn and ac then if j()==0 then C=true;BeginReentry()ac=false;ae=true else ac=false;ToggleAutopilot()end end;local dY=vec3(core.getWorldVertical())*-1;local dW=ba.x*dY.x+ba.y*dY.y+ba.z*dY.z;if ae and(ajHoldAltitude-200)and bb*3.6>bk-100 and math.abs(dW)<20 and j()>=0.1 then ToggleAutopilot()ae=false end;if Autopilot and j()==0 and not ac then local ic=AutopilotTargetCoords;local id=false;if CustomTarget~=nil and CustomTarget.planetname~="Space"then AutopilotRealigned=true;local ie=(CustomTarget.position-a0.center):normalize()local ig=ie:project_on_plane((a0.center-i4):normalize()):normalize()local ih=a0.center+ig*(a0.radius+AutopilotTargetOrbit)local ii=CustomTarget.position+(CustomTarget.position-a0.center):normalize()*(AutopilotTargetOrbit-a0:getAltitude(CustomTarget.position))if not TargetSet then if(i4-ih):len()<(i4-ii):len()then ic=ih;AutopilotTargetCoords=ic else ic=CustomTarget.position+(CustomTarget.position-a0.center):normalize()*(AutopilotTargetOrbit-a0:getAltitude(CustomTarget.position))AutopilotTargetCoords=ic end;local ck=zeroConvertToMapPosition(a0,AutopilotTargetCoords)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)id=true;TargetSet=true end;AutopilotPlanetGravity=0 elseif CustomTarget~=nil and CustomTarget.planetname=="Space"then AutopilotPlanetGravity=0;id=true;TargetSet=true;AutopilotRealigned=true;ic=CustomTarget.position+(i4-CustomTarget.position)*AutopilotTargetOrbit elseif CustomTarget==nil then AutopilotPlanetGravity=0;if not TargetSet then local ie=(i4+ba*100000-a0.center):normalize()local ig=ie:project_on_plane((a0.center-i4):normalize()):normalize()if ig:len()<1 then ie=(i4+vec3(core.getConstructWorldOrientationForward())*100000-a0.center):normalize()ig=ie:project_on_plane((a0.center-i4):normalize()):normalize()end;ic=a0.center+ig*(a0.radius+AutopilotTargetOrbit)AutopilotTargetCoords=ic;TargetSet=true;id=true;AutopilotRealigned=true;local ck=zeroConvertToMapPosition(a0,AutopilotTargetCoords)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)end end;AutopilotDistance=(vec3(ic)-vec3(core.getConstructWorldPos())):len()local eV,eW,eX=b2:getPlanetarySystem(0):castIntersections(i4,ba:normalize(),function(eY)if eY.noAtmosphericDensityAltitude>0 then return eY.radius+eY.noAtmosphericDensityAltitude else return eY.radius+eY.surfaceMaxAltitude*1.5 end end)local eZ=eW;if eX~=nil and eW~=nil then eZ=math.min(eX,eW)end;if eZ~=nil and eZ300 and AutopilotAccelerating then local de=vec3(ic)-vec3(core.getConstructWorldPos())local ik=utils.clamp(math.deg(cA(i3,ba:normalize(),de:normalize()))*bb/500,-90,90)local il=utils.clamp(math.deg(cA(ch,ba:normalize(),de:normalize()))*bb/500,-90,90)if math.abs(ik)<20 and math.abs(il)<20 then ik=ik*2;il=il*2 end;if math.abs(ik)<2 and math.abs(il)<2 then ik=ik*2;il=il*2 end;local i7=-math.deg(cA(i3,cg,ba:normalize()))local i8=-math.deg(cA(ch,cg,ba:normalize()))if apPitchPID==nil then apPitchPID=pid.new(2*0.01,0,2*0.1)end;apPitchPID:inject(il-i8)local im=utils.clamp(apPitchPID:get(),-1,1)H=H+im;if apYawPID==nil then apYawPID=pid.new(2*0.01,0,2*0.1)end;apYawPID:inject(ik-i7)local io=utils.clamp(apYawPID:get(),-1,1)I=I+io;id=true;if math.abs(ik)>2 or math.abs(il)>2 then AutopilotStatus="Adjusting Trajectory"else AutopilotStatus="Accelerating"end end;if ij=MaxGameVelocity or fm==0 and z then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0 end;if AutopilotDistance<=U then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;z=false end elseif AutopilotBraking then if AutopilotStatus~="Orbiting to Target"then BrakeIsOn=true;L=1 end;if TurnBurn then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,100)s=1 end;local _,ip=b5(a0):escapeAndOrbitalSpeed((vec3(core.getConstructWorldPos())-planet.center):len()-planet.radius)local de,iq,ir;if CustomTarget~=nil then de=CustomTarget.position-i4;iq=planet:getAltitude(CustomTarget.position)ir=math.sqrt(de:len()^2-(aj-iq)^2)end;if CustomTarget~=nil and CustomTarget.planetname=="Space"and bb<50 then P="Autopilot complete, arrived at space location"AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"elseif CustomTarget~=nil and CustomTarget.planetname~="Space"and bb<=ip and(orbit.apoapsis==nil or orbit.periapsis==nil or orbit.apoapsis.altitude<=0 or orbit.periapsis.altitude<=0)then P="Autopilot complete, proceeding with reentry"AutopilotTargetCoords=CustomTarget.position;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;z=false;ProgradeIsOn=true;ac=true;local ck=zeroConvertToMapPosition(a0,AutopilotTargetCoords)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)elseif orbit.periapsis~=nil and orbit.periapsis.altitude>0 and orbit.eccentricity<1 then AutopilotStatus="Circularizing"local _,ip=b5(a0):escapeAndOrbitalSpeed((vec3(core.getConstructWorldPos())-planet.center):len()-planet.radius)if bb<=ip then if CustomTarget~=nil then if ba:normalize():dot(de:normalize())>0.4 then AutopilotStatus="Orbiting to Target"if not WaypointSet then BrakeIsOn=false;local ck=zeroConvertToMapPosition(a0,CustomTarget.position)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)WaypointSet=true end else P="Autopilot complete, proceeding with reentry"AutopilotTargetCoords=CustomTarget.position;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;z=false;ProgradeIsOn=true;ac=true;BrakeIsOn=false;local ck=zeroConvertToMapPosition(a0,CustomTarget.position)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)WaypointSet=false end else BrakeIsOn=false;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"P="Autopilot completed, orbit established"L=0;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;z=false;if CustomTarget~=nil and CustomTarget.planetname~="Space"then ProgradeIsOn=true;ac=true end end end end elseif AutopilotCruising then if AutopilotDistance<=U then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true end;local fm=unit.getThrottle()if AtmoSpeedAssist then fm=s end;if fm>0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if ib then if not AutopilotRealigned and CustomTarget==nil or not AutopilotRealigned and CustomTarget~=nil and CustomTarget.planetname~="Space"then if not ac then AutopilotTargetCoords=vec3(a0.center)+(AutopilotTargetOrbit+a0.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()end;AutopilotRealigned=true elseif ib then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not z then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)s=round(AutopilotInterplanetaryThrottle,2)z=true;BrakeIsOn=false end end end end elseif Autopilot and(CustomTarget~=nil and CustomTarget.planetname~="Space"and j()>0)then P="Autopilot complete, proceeding with reentry"AutopilotTargetCoords=CustomTarget.position;BrakeIsOn=false;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"L=0;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;z=false;ProgradeIsOn=true;ac=true;local ck=zeroConvertToMapPosition(a0,CustomTarget.position)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)end;if N then b8=true;local il=0;local c0=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local is=c0-vec3(core.getConstructWorldPos())local it=vec3(is):project_on(vec3(core.getConstructWorldOrientationForward())):len()local iu=vec3(is):project_on(vec3(core.getConstructWorldOrientationRight())):len()local a8=math.sqrt(it*it+iu*iu)AlignToWorldVector(is:normalize())local iv=40;local iw=a8iy then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(il-cj)local im=pitchPID:get()H=im end end;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget or LockPitch~=nil then local dE=unit.getClosestPlanetInfluence()>0;local iz=HoldAltitude-aj;local iA=500+bb;local iB=1;if AutoTakeoff then iB=utils.clamp(bb/100,0.1,1)end;local il=(utils.smoothstep(iz,-iA,iA)-0.5)*2*MaxPitch*iB;if not Reentry and not ac and not VectorToTarget and cg:dot(ba:normalize())<0.99 then il=(utils.smoothstep(iz,-iA*utils.clamp(20-19*j()*10,1,20),iA*utils.clamp(20-19*j()*10,1,20))-0.5)*2*MaxPitch*utils.clamp(2-j()*10,1,2)*iB end;if not AltitudeHold then il=0 end;if LockPitch~=nil then if dE then il=LockPitch else LockPitch=nil end end;b8=true;local iC=H;if Reentry then local ReentrySpeed=math.floor(bk)local iD,iE=b3.computeDistanceAndTime(bb,ReentrySpeed/3.6,n(),0,0,LastMaxBrake-planet.gravity*9.8*n())local iF=aj-(planet.noAtmosphericDensityAltitude+5000)if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and aj>planet.noAtmosphericDensityAltitude+5000 and bb<=ReentrySpeed/3.6 and bb>ReentrySpeed/3.6-10 and math.abs(ba:normalize():dot(cg))>0.9 then Nav.control.cancelCurrentControlMasterMode()s=0 elseif Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle and(iD>-1 and iF<=iD or aj<=planet.noAtmosphericDensityAltitude+5000)then BrakeIsOn=true else BrakeIsOn=false end;if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=ReentrySpeed then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,ReentrySpeed)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if not C then il=-80;if j()>0.02 then P="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;il=0;b8=autoRollPreference end elseif planet.noAtmosphericDensityAltitude>0 and aj>planet.noAtmosphericDensityAltitude+5000 then if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed then il=-70 else il=-MaxPitch end;b8=true elseif aj<=planet.noAtmosphericDensityAltitude+5000 then if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle then Nav.control.cancelCurrentControlMasterMode()Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,ReentrySpeed)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==bk then il=-MaxPitch;C=false;Reentry=false;b8=true end end end;if(VectorToTarget or ad)and AutopilotTargetIndex>0 and j()>0.01 then local de;if CustomTarget~=nil then de=CustomTarget.position-vec3(core.getConstructWorldPos())else de=a0.center-i4 end;local i3=vec3(core.getConstructWorldOrientationUp())local ik=math.deg(cA(ci:normalize(),ba:project_on_plane(ci),de:project_on_plane(ci)))*2;local iG=math.rad(math.abs(dt))if bb>i9 and j()>0.01 then local iH=utils.clamp(90-il,60,90)bi=utils.clamp(ik,-iH,iH)local iI=ik;ik=utils.clamp(utils.clamp((i7-ik)*math.cos(iG),i7-YawStallAngle*0.85,i7+YawStallAngle*0.85)+utils.clamp((il-i6)*math.sin(math.rad(dt)),-YawStallAngle*0.85,YawStallAngle*0.85),i7-YawStallAngle*0.85,i7+YawStallAngle*0.85)il=utils.clamp(utils.clamp(il*math.cos(iG),-PitchStallAngle*0.85,PitchStallAngle*0.85)+math.abs(utils.clamp(math.abs(iI)*math.sin(iG),-PitchStallAngle*0.85,PitchStallAngle*0.85)),-PitchStallAngle*0.85,PitchStallAngle*0.85)else bi=0;ik=utils.clamp(i7-ik,-90,90)end;local iJ=ik;if not bg and bb>i9 and j()>0.01 then if yawPID==nil then yawPID=pid.new(5*0.01,0,5*0.1)end;yawPID:inject(iJ)local io=utils.clamp(yawPID:get(),-1,1)I=I+io elseif ai and af>-1 or bb0.01 then if(i7<-YawStallAngle or i7>YawStallAngle)and j()>0.01 then AlignToWorldVector(ba)end;if(i8<-PitchStallAngle or i8>PitchStallAngle)and j()>0.01 then il=utils.clamp(i6-i8,i6-PitchStallAngle*0.85,i6+PitchStallAngle*0.85)end end;if CustomTarget~=nil and not ad then local iq=planet:getAltitude(CustomTarget.position)local iF=math.sqrt(de:len()^2-(aj-iq)^2)local iK=LastMaxBrakeInAtmo;if iK then iK=iK*utils.clamp(bb/100,0.1,1)*j()else iK=LastMaxBrake end;if j()<0.01 then iK=LastMaxBrake else end;local dW=ba.x*dY.x+ba.y*dY.y+ba.z*dY.z;local iL=ba:len()-math.abs(dW)local iM=vec3(core.getWorldAirFrictionAcceleration())local iN=math.sqrt(iM:len()-iM:project_on(dY):len())*n()if bb>100 then U,V=b3.computeDistanceAndTime(bb,100,n(),0,0,iK+iN)local iO,iP=b3.computeDistanceAndTime(100,0,n(),0,0,iK/2)U=U+iO else U,V=b3.computeDistanceAndTime(bb,0,n(),0,0,iK/2)end;StrongBrakes=true;if not ad and iF<=U+bb*i2/2 and ba:project_on_plane(ci):dot(de:project_on_plane(ci))>0.99 then VectorStatus="Finalizing Approach"if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;if AltitudeHold then ToggleAltitudeHold()VectorToTarget=true end;BrakeIsOn=true elseif not AutoTakeoff then BrakeIsOn=false end;if VectorStatus=="Finalizing Approach"and(iL<0.1 or iF<0.1 or LastDistanceToTarget~=nil and LastDistanceToTarget0.01 and af==-1 and bb>i9 and VectorStatus~="Finalizing Approach"then AlignToWorldVector(ba)il=utils.clamp(i6-i8,i6-PitchStallAngle*0.85,i6+PitchStallAngle*0.85)end;H=iC;local fv=-1;local iy=0.1;if BrakeLanding then il=0;local dW=ba.x*dY.x+ba.y*dY.y+ba.z*dY.z;local iQ=false;local iR=30;if b4~=nil and b4>0 then local iN=0;local dz=utils.clamp(j(),0.4,2)local iK=LastMaxBrakeInAtmo*utils.clamp(bb/100,0.1,1)*dz;local iS=b4*dz+iK+iN-bz;local iT=iK+iN-bz;local iU=iK/2+iN-bz;local iV=bb-math.sqrt(math.abs(iU/2)*20/(0.5*n()))*utils.sign(iU)if iV<0 then iV=0 end;local iW;if bb>100 then local iX,_=b3.computeDistanceAndTime(bb,100,n(),0,0,iK)local iY,_=b3.computeDistanceAndTime(100,0,n(),0,0,math.sqrt(iK))iW=iX+iY else iW=b3.computeDistanceAndTime(bb,0,n(),0,0,math.sqrt(iK))end;if iW<20 then BrakeIsOn=false else local iZ=0;if iV>100 then local i_,_=b3.computeDistanceAndTime(iV,100,n(),0,0,iS)local j0,_=b3.computeDistanceAndTime(100,0,n(),0,0,b4*dz+math.sqrt(iK)+iN-bz)iZ=i_+j0 else iZ,_=b3.computeDistanceAndTime(iV,0,n(),0,0,b4*dz+math.sqrt(iK)+iN-bz)end;iZ=(iZ+15+bb*i2)*1.1;local j1=CustomTarget~=nil and planet:getAltitude(CustomTarget.position)>0 and CustomTarget.safe;if j1 then local iq=planet:getAltitude(CustomTarget.position)local j2=aj-iq-100;local de=CustomTarget.position-vec3(core.getConstructWorldPos())local ir=math.sqrt(de:len()^2-(aj-iq)^2)if ir>100 then j1=false elseif j2<=iZ or iZ==-1 then BrakeIsOn=true;iQ=true else BrakeIsOn=false;iQ=true end end;if not j1 and CalculateBrakeLandingSpeed then if iZ>=iR then BrakeIsOn=true else BrakeIsOn=false end;iQ=true end end end;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)fv=af;if fv>-1 then b8=autoRollPreference;if bb<1 or ba:normalize():dot(ci)<0 then BrakeLanding=false;AltitudeHold=false;GearExtended=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)a4=0;BrakeIsOn=true else BrakeIsOn=true end elseif StrongBrakes and ba:normalize():dot(-dY)<0.999 then BrakeIsOn=true elseif dW<-brakeLandingRate and not iQ then BrakeIsOn=true elseif not iQ then BrakeIsOn=false end end;if AutoTakeoff or ad then local eV,eX,eW=b2:getPlanetarySystem(0):castIntersections(i4,(AutopilotTargetCoords-i4):normalize(),function(eY)return eY.radius+eY.noAtmosphericDensityAltitude end)if math.abs(il)<15 and aj/HoldAltitude>0.75 then AutoTakeoff=false;if not ad then if Nav.axisCommandManager:getAxisCommandType(0)==0 and not AtmoSpeedAssist then Nav.control.cancelCurrentControlMasterMode()end elseif ad and bb-1;local j4=cj;if VectorToTarget and not j3 and bb>i9 and j()>0.01 then local iG=math.rad(math.abs(dt))j4=cj*math.abs(math.cos(iG))+i8*math.sin(iG)end;local j5=utils.clamp(il-j4,-PitchStallAngle*0.85,PitchStallAngle*0.85)if j()<0.01 and VectorToTarget then j5=utils.clamp(il-j4,-85,MaxPitch)elseif j()<0.01 then j5=utils.clamp(il-j4,-MaxPitch,MaxPitch)end;if math.abs(dt)<5 or VectorToTarget or BrakeLanding or j3 or AltitudeHold then if pitchPID==nil then pitchPID=pid.new(5*0.01,0,5*0.1)end;pitchPID:inject(j5)local im=pitchPID:get()H=H+im end end;Q=orbit.eccentricity;if antigrav and not ExternalAGG and aj<200000 then if AntigravTargetAltitude==nil or AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end end end end;function script.onFlush()if antigrav and not ExternalAGG then if antigrav.getState()==0 and antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(AntigravTargetAltitude)end end;if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle and w then s=0;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,s)w=false elseif Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and not w then s=0;w=true end;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)torqueFactor=math.max(torqueFactor,0.01)brakeSpeedFactor=math.max(brakeSpeedFactor,0.01)brakeFlatFactor=math.max(brakeFlatFactor,0.01)autoRollFactor=math.max(autoRollFactor,0.01)turnAssistFactor=math.max(turnAssistFactor,0.01)local j6=utils.clamp(G+H+system.getControlDeviceForwardInput(),-1,1)local j7=utils.clamp(J+M+system.getControlDeviceYawInput(),-1,1)local j8=utils.clamp(K+I-system.getControlDeviceLeftRightInput(),-1,1)local j9=L;local ja=vec3(core.getWorldVertical())if ja==nil or ja:len()==0 then ja=(planet.center-vec3(core.getConstructWorldPos())):normalize()end;local jb=vec3(core.getConstructWorldOrientationUp())local jc=vec3(core.getConstructWorldOrientationForward())local jd=vec3(core.getConstructWorldOrientationRight())local je=vec3(core.getWorldVelocity())local jf=vec3(core.getWorldVelocity()):normalize()local jg=getRoll(ja,jc,jd)local jh=math.abs(jg)local ji=utils.sign(jg)local j=j()local jj=vec3(core.getWorldAngularVelocity())local jk=j6*pitchSpeedFactor*jd+j7*rollSpeedFactor*jc+j8*yawSpeedFactor*jb;if ja:len()>0.01 and(j>0.0 or ProgradeIsOn or Reentry or ac or AltitudeHold)then local dt=getRoll(ja,jc,jd)local du=dt/180*math.pi;local dv=math.cos(du)local dw=math.sin(du)local i6=getPitch(ja,jc,jd*dv+jb*dw)if b8==true and math.abs(bi-jg)>autoRollRollThreshold and j7==0 and math.abs(i6)<85 then local jl=bi;local jm=autoRollFactor;if j==0 then jm=jm/4;bi=0;jl=0 end;if rollPID==nil then rollPID=pid.new(jm*0.01,0,jm*0.1)end;rollPID:inject(jl-jg)local jn=rollPID:get()jk=jk+jn*jc end end;if ja:len()>0.01 and j>0.0 then local jo=20.0;if turnAssist==true and jh>jo and j6==0 and j8==0 then local jp=turnAssistFactor*0.1;local jq=turnAssistFactor*0.025;local jr=(jh-jo)/(180-jo)*180;local js=0;if jr<90 then js=jr/90 elseif jr<180 then js=(180-jr)/90 end;js=js*js;local jt=-ji*jq*(1.0-js)local ju=jp*js;jk=jk+ju*jd+jt*jb end end;local jv=1;local jw=0;local jx=1;if system.getMouseWheel()>0 then if AltIsOn then if j>0 or Reentry then bk=utils.clamp(bk+speedChangeLarge,0,AtmoSpeedLimit)elseif Autopilot then MaxGameVelocity=utils.clamp(MaxGameVelocity+speedChangeLarge/3.6*100,0,8333.00)end;A=false else s=round(utils.clamp(s+speedChangeLarge/100,-1,1),2)end elseif system.getMouseWheel()<0 then if AltIsOn then if j>0 or Reentry then bk=utils.clamp(bk-speedChangeLarge,0,AtmoSpeedLimit)elseif Autopilot then MaxGameVelocity=utils.clamp(MaxGameVelocity-speedChangeLarge/3.6*100,0,8333.00)end;A=false else s=round(utils.clamp(s-speedChangeLarge/100,-1,1),2)end end;t=0;local dW=-ja:dot(je)if ai and AtmoSpeedAssist and Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle then if throttlePID==nil then throttlePID=pid.new(0.5,0,1)end;throttlePID:inject(bk/3.6-je:dot(jc))local jy=throttlePID:get()v=utils.clamp(jy,-1,1)if v0.05 or j>0.01 and dW<0)then u=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,utils.clamp(v,0.01,1))else u=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,s)end;if brakePID==nil then brakePID=pid.new(1*0.01,0,1*0.1)end;brakePID:inject(je:len()-bk/3.6)local jz=utils.clamp(brakePID:get(),0,1)if j>0 and dW<-80 or j>0.05 then t=jz end;if t>0 then if u and v==0.01 then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)end else v=utils.clamp(v,0.01,1)end;local jA=''local jB=vec3()local jC='thrust analog vertical 'local jD='thrust analog lateral 'if ExtraLateralTags~="none"then jD=jD..ExtraLateralTags end;if ExtraVerticalTags~="none"then jC=jC..ExtraVerticalTags end;local jE=composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical,a4*1000)jA=jA..' , '..jC;jB=jB+jE;local jF='thrust analog longitudinal 'if ExtraLongitudeTags~="none"then jF=jF..ExtraLongitudeTags end;local jG=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)local jH=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(jF,axisCommandId.longitudinal)local jI=composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral,0)jA=jA..' , '..jD;jB=jB+jI;if jB:len()>constants.epsilon then Nav:setEngineForceCommand(jA,jB,jw,'','','',jx)end;Nav:setEngineForceCommand(jF,jH,jv)if j9==0 then j9=t end;local jJ=-j9*(brakeSpeedFactor*je+brakeFlatFactor*jf)Nav:setEngineForceCommand('brake',jJ)else if AtmoSpeedAssist then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,s)end;local jJ=-j9*(brakeSpeedFactor*je+brakeFlatFactor*jf)Nav:setEngineForceCommand('brake',jJ)local jA=''local jB=vec3()local jK=false;local jF='thrust analog longitudinal 'if ExtraLongitudeTags~="none"then jF=jF..ExtraLongitudeTags end;local jG=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if jG==axisCommandType.byThrottle then local jH=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(jF,axisCommandId.longitudinal)Nav:setEngineForceCommand(jF,jH,jv)elseif jG==axisCommandType.byTargetSpeed then local jH=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)jA=jA..' , '..jF;jB=jB+jH;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then jK=true end end;local jD='thrust analog lateral 'if ExtraLateralTags~="none"then jD=jD..ExtraLateralTags end;local jL=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if jL==axisCommandType.byThrottle then local jM=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(jD,axisCommandId.lateral)Nav:setEngineForceCommand(jD,jM,jv)elseif jL==axisCommandType.byTargetSpeed then local jI=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)jA=jA..' , '..jD;jB=jB+jI end;local jC='thrust analog vertical 'if ExtraVerticalTags~="none"then jC=jC..ExtraVerticalTags end;local jN=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if jN==axisCommandType.byThrottle then local jE=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(jC,axisCommandId.vertical)if a4~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(jC,jE,jv,'airfoil','ground','',jx)else Nav:setEngineForceCommand(jC,vec3(),jv)Nav:setEngineForceCommand('airfoil vertical',jE,jv,'airfoil','','',jx)Nav:setEngineForceCommand('ground vertical',jE,jv,'ground','','',jx)end elseif jN==axisCommandType.byTargetSpeed then if a4<0 then Nav:setEngineForceCommand('hover',vec3(),jv)end;local jO=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)jA=jA..' , '..jC;jB=jB+jO end;local fR=unit.getAxisCommandValue(0)if jB:len()>constants.epsilon then if L~=0 or jK or math.abs(jf:dot(jc))<0.8 or ba:len()>fR/3.6 then jA=jA..', brake'end;Nav:setEngineForceCommand(jA,jB,jw,'','','',jx)end end;local jP=torqueFactor*(jk-jj)local jQ=vec3(core.getWorldAirFrictionAngularAcceleration())jP=jP-jQ;Nav:setEngineTorqueCommand('torque',jP,jv,'airfoil','','',jx)Nav:setBoosterCommand('rocket_engine')if T and not VanillaRockets then local bC=vec3(core.getVelocity()):len()local jR=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local jS=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if bC*3.6>jS*(1-jR)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bC*3.6=fR*(1-jR)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bC=fR*(1-jR)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bC0 or ajHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+S;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+S end else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+R else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif jT=="groundaltitudedown"then OldButtonMod=R;OldAntiMod=S;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-S;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-S;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-R else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif jT=="option1"then IncrementAutopilotTargetIndex()A=false elseif jT=="option2"then DecrementAutopilotTargetIndex()A=false elseif jT=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;A=false;ToggleWidgets()elseif jT=="option4"then ToggleAutopilot()A=false elseif jT=="option5"then ToggleLockPitch()A=false elseif jT=="option6"then ToggleAltitudeHold()A=false elseif jT=="option7"then wipeSaveVariables()A=false elseif jT=="option8"then ToggleFollowMode()A=false elseif jT=="option9"then if gyro~=nil then gyro.toggle()am=gyro.getState()==1 end;A=false elseif jT=="lshift"then if system.isViewLocked()==1 then O=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif o()==1 and ShiftShowsRemoteButtons then O=true;b7=false;b6=false end elseif jT=="brake"then if BrakeToggleStatus then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif jT=="lalt"then AltIsOn=true;if o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif jT=="booster"then if VanillaRockets then Nav:toggleBoosters()elseif not T then if not IsRocketOn then Nav:toggleBoosters()IsRocketOn=true end;T=true else if IsRocketOn then Nav:toggleBoosters()IsRocketOn=false end;T=false end elseif jT=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)clearAll()s=0 elseif jT=="speedup"then if not O then if AtmoSpeedAssist and not AltIsOn then s=utils.clamp(s+speedChangeLarge/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)end else IncrementAutopilotTargetIndex()end elseif jT=="speeddown"then if not O then if AtmoSpeedAssist and not AltIsOn then s=utils.clamp(s-speedChangeLarge/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)end else DecrementAutopilotTargetIndex()end elseif jT=="antigravity"and not ExternalAGG then if antigrav~=nil then ToggleAntigrav()end end end;function script.onActionStop(jT)if jT=="forward"then G=0 elseif jT=="backward"then G=0 elseif jT=="left"then J=0 elseif jT=="right"then J=0 elseif jT=="yawright"then K=0 elseif jT=="yawleft"then K=0 elseif jT=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)elseif jT=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)elseif jT=="up"then a4=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif jT=="down"then a4=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif jT=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then S=OldAntiMod end;if AltitudeHold then R=OldButtonMod end;A=false elseif jT=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then S=OldAntiMod end;if AltitudeHold then R=OldButtonMod end;A=false elseif jT=="lshift"then if system.isViewLocked()==1 then O=false;a5=0;a6=0;system.lockView(PrevViewLock)elseif o()==1 and ShiftShowsRemoteButtons then O=false;b7=false;b6=false end elseif jT=="brake"then if not BrakeToggleStatus then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif jT=="lalt"then if o()==0 and freeLookToggle then if A then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else A=true end elseif o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end;AltIsOn=false end end;function script.onActionLoop(jT)if jT=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+S;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+S end;S=S*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+R;R=R*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif jT=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-S;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-S;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end;S=S*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-R;R=R*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif jT=="speedup"then if not O then if AtmoSpeedAssist and not AltIsOn then s=utils.clamp(s+speedChangeSmall/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end end elseif jT=="speeddown"then if not O then if AtmoSpeedAssist and not AltIsOn then s=utils.clamp(s-speedChangeSmall/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end end;function script.onInputText(dj)local i;local jU="/commands /setname /G /agg /addlocation /copydatabank"local jV,jW=nil,nil;local jX="Command List:\n/commands \n/setname - Updates current selected saved position name\n/G VariableName newValue - Updates global variable to new value\n".."/G dump - shows all updatable variables with /G\n/agg - Manually set agg target height\n".."/addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572} - adds a saved location by waypoint, not as accurate as making one at location\n".."/copydatabank - copies dbHud databank to a blank databank"i=string.find(dj," ")jV=dj;if i~=nil then jV=string.sub(dj,0,i-1)jW=string.sub(dj,i+1)elseif not string.find(jU,jV)then for fN in string.gmatch(jX,"([^\n]+)")do c(fN)end;return end;if jV=="/setname"then if jW==nil or jW==""then P="Usage: /setname Newname"return end;if AutopilotTargetIndex>0 and CustomTarget~=nil then UpdatePosition(jW)else P="Select a saved target to rename first"end elseif jV=="/addlocation"then if jW==nil or jW==""or string.find(jW,"::")==nil then P="Usage: /addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572}"return end;i=string.find(jW,"::")local c6=string.sub(jW,1,i-2)local c0=string.sub(jW,i)local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local c1='::pos{'..p..','..p..','..p..','..p..','..p..'}'local c2,c3,bY,bZ,bX=string.match(c0,c1)local planet=aX[tonumber(c2)][tonumber(c3)]AddNewLocationByWaypoint(c6,planet,c0)P="Added "..c6 .." to saved locations,\nplanet "..planet.name.." at "..c0;a7=5 elseif jV=="/agg"then if jW==nil or jW==""then P="Usage: /agg targetheight"return end;jW=tonumber(jW)if jW<1000 then jW=1000 end;AntigravTargetAltitude=jW;P="AGG Target Height set to "..jW elseif jV=="/G"then if jW==nil or jW==""then P="Usage: /G VariableName variablevalue\n/G dump - shows all variables"return end;if jW=="dump"then for bm,bn in pairs(a)do if type(_G[bn])=="boolean"then if _G[bn]==true then c(bn.." true")else c(bn.." false")end elseif _G[bn]==nil then c(bn.." nil")else c(bn.." ".._G[bn])end end;return end;i=string.find(jW," ")local jY=string.sub(jW,0,i-1)local jZ=string.sub(jW,i+1)for bm,bn in pairs(a)do if bn==jY then P="Variable "..jY.." changed to "..jZ;local j_=type(_G[bn])if j_=="number"then jZ=tonumber(jZ)elseif j_=="boolean"then if string.lower(jZ)=="true"then jZ=true else jZ=false end end;_G[bn]=jZ;return end end;P="No such global variable: "..jY elseif jV=="/copydatabank"then if dbHud_2 then SaveDataBank(true)else P="Databank required to copy databank"end end end;script.onStart() + Radar: No Contacts]],fI,fJ)end;if radarPanelID~=nil then ab=0;ToggleRadarPanel()end end end end;function DisplayMessage(cd,dh)if dh~="empty"then cd[#cd+1]=[[]]for fN in string.gmatch(dh,"([^\n]+)")do cd[#cd+1]=e([[%s]],fN)end;cd[#cd+1]=[[]]end;if a7~=0 then unit.setTimer("msgTick",a7)a7=0 end end;function updateDistance()local bv=system.getTime()local ba=vec3(core.getWorldVelocity())local dB=vec3(ba):len()local fO=bv-al;if dB>1.38889 then dB=dB/1000;local fP=dB*(bv-al)TotalDistanceTravelled=TotalDistanceTravelled+fP;a1=a1+fP end;a2=a2+fO;TotalFlightTime=TotalFlightTime+fO;al=bv end;function composeAxisAccelerationFromTargetSpeed(fQ,fR)local fS=vec3()local fT=vec3()if fQ==axisCommandId.longitudinal then fS=vec3(core.getConstructOrientationForward())fT=vec3(core.getConstructWorldOrientationForward())elseif fQ==axisCommandId.vertical then fS=vec3(core.getConstructOrientationUp())fT=vec3(core.getConstructWorldOrientationUp())elseif fQ==axisCommandId.lateral then fS=vec3(core.getConstructOrientationRight())fT=vec3(core.getConstructWorldOrientationRight())else return vec3()end;local fU=vec3(core.getWorldGravity())local fV=fU:dot(fT)local fW=vec3(core.getWorldAirFrictionAcceleration())local fX=fW:dot(fT)local fY=vec3(core.getVelocity())local fZ=fY:dot(fS)local f_=fR*constants.kph2m;if targetSpeedPID==nil then targetSpeedPID=pid.new(10,0,10.0)end;targetSpeedPID:inject(f_-fZ)local g0=targetSpeedPID:get()local g1=(g0-fX-fV)*fT;system.addMeasure("dynamic","acceleration","command",g0)system.addMeasure("dynamic","acceleration","intensity",g1:len())return g1 end;function Atlas()return{[0]={[0]={GM=0,bodyId=0,center={x=0,y=0,z=0},name='Space',planetarySystemId=0,radius=0,hasAtmosphere=false,gravity=0,noAtmosphericDensityAltitude=0,surfaceMaxAltitude=0},[2]={name="Alioth",description="Alioth is the planet selected by the arkship for landfall; it is a typical goldilocks planet where humanity may rebuild in the coming decades. The arkship geological survey reports mountainous regions alongside deep seas and lush forests. This is where it all starts.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9401,atmosphericEngineMaxAltitude=5580,biosphere="Forest",classification="Mesoplanet",bodyId=2,GM=157470826617,gravity=1.0082568597356114,fullAtmosphericDensityMaxAltitude=-10,habitability="High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=6272,numSatellites=2,positionFromSun=2,center={x=-8,y=-8,z=-126303},radius=126067.8984375,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=3410,surfaceArea=199718780928,surfaceAverageAltitude=200,surfaceMaxAltitude=1100,surfaceMinAltitude=-330,systemZone="High",territories=259472,type="Planet",waterLevel=0,planetarySystemId=0},[21]={name="Alioth Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=21,GM=2118960000,gravity=0.24006116402380084,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=457933,y=-1509011,z=115524},radius=30000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=11309733888,surfaceAverageAltitude=140,surfaceMaxAltitude=200,surfaceMinAltitude=10,systemZone=nil,territories=14522,type="",waterLevel=nil,planetarySystemId=0},[22]={name="Alioth Moon 4",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=22,GM=2165833514,gravity=0.2427018259886451,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-1692694,y=729681,z=-411464},radius=30330,safeAreaEdgeAltitude=500000,size="L",spaceEngineMinAltitude=0,surfaceArea=11559916544,surfaceAverageAltitude=-15,surfaceMaxAltitude=-5,surfaceMinAltitude=-50,systemZone=nil,territories=14522,type="",waterLevel=nil,planetarySystemId=0},[5]={name="Feli",description="Feli is easily identified by its massive and deep crater. Outside of the crater, the arkship geological survey reports a fairly bland and uniform planet, it also cannot explain the existence of the crater. Feli is particular for having an extremely small atmosphere, allowing life to develop in the deeper areas of its crater but limiting it drastically on the actual surface.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.5488,atmosphericEngineMaxAltitude=66725,biosphere="Barren",classification="Mesoplanet",bodyId=5,GM=16951680000,gravity=0.4801223280476017,fullAtmosphericDensityMaxAltitude=30,habitability="Low",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=78500,numSatellites=1,positionFromSun=5,center={x=-43534464,y=22565536,z=-48934464},radius=41800,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=42800,surfaceArea=21956466688,surfaceAverageAltitude=18300,surfaceMaxAltitude=18500,surfaceMinAltitude=46,systemZone="Low",territories=27002,type="Planet",waterLevel=nil,planetarySystemId=0},[50]={name="Feli Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=50,GM=499917600,gravity=0.11202853997062348,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-43902841.78,y=22261034.7,z=-48862386},radius=14000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=2463008768,surfaceAverageAltitude=800,surfaceMaxAltitude=900,surfaceMinAltitude=0,systemZone=nil,territories=3002,type="",waterLevel=nil,planetarySystemId=0},[120]={name="Ion",description="Ion is nothing more than an oversized ice cube frozen through and through. It is a largely inhospitable planet due to its extremely low temperatures. The arkship geological survey reports extremely rough mountainous terrain with little habitable land.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9522,atmosphericEngineMaxAltitude=10480,biosphere="Ice",classification="Hypopsychroplanet",bodyId=120,GM=7135606629,gravity=0.36009174603570127,fullAtmosphericDensityMaxAltitude=-30,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=17700,numSatellites=2,positionFromSun=12,center={x=2865536.7,y=-99034464,z=-934462.02},radius=44950,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=6410,surfaceArea=25390383104,surfaceAverageAltitude=500,surfaceMaxAltitude=1300,surfaceMinAltitude=250,systemZone="Average",territories=32672,type="Planet",waterLevel=nil,planetarySystemId=0},[121]={name="Ion Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=121,GM=106830900,gravity=0.08802242599860607,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=2472916.8,y=-99133747,z=-1133582.8},radius=11000,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=0,surfaceArea=1520530944,surfaceAverageAltitude=100,surfaceMaxAltitude=200,surfaceMinAltitude=3,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[122]={name="Ion Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=122,GM=176580000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=2995424.5,y=-99275010,z=-1378480.7},radius=15000,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=-1900,surfaceMaxAltitude=-1400,surfaceMinAltitude=-2100,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[9]={name="Jago",description="Jago is a water planet. The large majority of the planet's surface is covered by large oceans dotted by small areas of landmass across the planet. The arkship geological survey reports deep seas across the majority of the planet with sub 15 percent coverage of solid ground.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9835,atmosphericEngineMaxAltitude=9695,biosphere="Water",classification="Mesoplanet",bodyId=9,GM=18606274330,gravity=0.5041284298678057,fullAtmosphericDensityMaxAltitude=-90,habitability="Very High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=10900,numSatellites=0,positionFromSun=9,center={x=-94134462,y=12765534,z=-3634464},radius=61590,safeAreaEdgeAltitude=500000,size="XL",spaceEngineMinAltitude=5900,surfaceArea=47668367360,surfaceAverageAltitude=0,surfaceMaxAltitude=1200,surfaceMinAltitude=-500,systemZone="Very High",territories=60752,type="Planet",waterLevel=0,planetarySystemId=0},[100]={name="Lacobus",description="Lacobus is an ice planet that also features large bodies of water. The arkship geological survey reports deep oceans alongside a frozen and rough mountainous environment. Lacobus seems to feature regional geothermal activity allowing for the presence of water on the surface.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.7571,atmosphericEngineMaxAltitude=11120,biosphere="Ice",classification="Psychroplanet",bodyId=100,GM=13975172474,gravity=0.45611622622739767,fullAtmosphericDensityMaxAltitude=-20,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=12510,numSatellites=3,positionFromSun=10,center={x=98865536,y=-13534464,z=-934461.99},radius=55650,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=6790,surfaceArea=38917074944,surfaceAverageAltitude=800,surfaceMaxAltitude=1660,surfaceMinAltitude=250,systemZone="Average",territories=50432,type="Planet",waterLevel=0,planetarySystemId=0},[102]={name="Lacobus Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=102,GM=444981600,gravity=0.14403669598391783,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=99180968,y=-13783862,z=-926156.4},radius=18000,safeAreaEdgeAltitude=500000,size="XL",spaceEngineMinAltitude=0,surfaceArea=4071504128,surfaceAverageAltitude=150,surfaceMaxAltitude=300,surfaceMinAltitude=10,systemZone=nil,territories=5072,type="",waterLevel=nil,planetarySystemId=0},[103]={name="Lacobus Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=103,GM=211503600,gravity=0.11202853997062348,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=99250052,y=-13629215,z=-1059341.4},radius=14000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2463008768,surfaceAverageAltitude=-1380,surfaceMaxAltitude=-1280,surfaceMinAltitude=-1880,systemZone=nil,territories=3002,type="",waterLevel=nil,planetarySystemId=0},[101]={name="Lacobus Moon 3",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=101,GM=264870000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=98905288.17,y=-13950921.1,z=-647589.53},radius=15000,safeAreaEdgeAltitude=500000,size="L",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=500,surfaceMaxAltitude=820,surfaceMinAltitude=3,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[1]={name="Madis",description="Madis is a barren wasteland of a rock; it sits closest to the sun and temperatures reach extreme highs during the day. The arkship geological survey reports long rocky valleys intermittently separated by small ravines.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.8629,atmosphericEngineMaxAltitude=7165,biosphere="Barren",classification="hyperthermoplanet",bodyId=1,GM=6930729684,gravity=0.36009174603570127,fullAtmosphericDensityMaxAltitude=220,habitability="Low",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=8050,numSatellites=3,positionFromSun=1,center={x=17465536,y=22665536,z=-34464},radius=44300,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=4480,surfaceArea=24661377024,surfaceAverageAltitude=750,surfaceMaxAltitude=850,surfaceMinAltitude=670,systemZone="Low",territories=30722,type="Planet",waterLevel=nil,planetarySystemId=0},[10]={name="Madis Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=10,GM=78480000,gravity=0.08002039003323584,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=17448118.224,y=22966846.286,z=143078.82},radius=10000,safeAreaEdgeAltitude=500000,size="XL",spaceEngineMinAltitude=0,surfaceArea=1256637056,surfaceAverageAltitude=210,surfaceMaxAltitude=420,surfaceMinAltitude=0,systemZone=nil,territories=1472,type="",waterLevel=nil,planetarySystemId=0},[11]={name="Madis Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=11,GM=237402000,gravity=0.09602446196397631,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=17194626,y=22243633.88,z=-214962.81},radius=12000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=1809557376,surfaceAverageAltitude=-700,surfaceMaxAltitude=300,surfaceMinAltitude=-2900,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[12]={name="Madis Moon 3",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=12,GM=265046609,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=17520614,y=22184730,z=-309989.99},radius=15000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=700,surfaceMaxAltitude=1100,surfaceMinAltitude=0,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[26]={name="Sanctuary",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9666,atmosphericEngineMaxAltitude=6935,biosphere="",classification="",bodyId=26,GM=68234043600,gravity=1.0000000427743831,fullAtmosphericDensityMaxAltitude=-30,habitability="",hasAtmosphere=true,isSanctuary=true,noAtmosphericDensityAltitude=7800,numSatellites=0,positionFromSun=0,center={x=-1404835,y=562655,z=-285074},radius=83400,safeAreaEdgeAltitude=0,size="L",spaceEngineMinAltitude=4230,surfaceArea=87406149632,surfaceAverageAltitude=80,surfaceMaxAltitude=500,surfaceMinAltitude=-60,systemZone=nil,territories=111632,type="",waterLevel=0,planetarySystemId=0},[6]={name="Sicari",description="Sicari is a typical desert planet; it has survived for millenniums and will continue to endure. While not the most habitable of environments it remains a relatively untouched and livable planet of the Alioth sector. The arkship geological survey reports large flatlands alongside steep plateaus.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.897,atmosphericEngineMaxAltitude=7725,biosphere="Desert",classification="Mesoplanet",bodyId=6,GM=10502547741,gravity=0.4081039739797361,fullAtmosphericDensityMaxAltitude=-625,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=8770,numSatellites=0,positionFromSun=6,center={x=52765536,y=27165538,z=52065535},radius=51100,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=4480,surfaceArea=32813432832,surfaceAverageAltitude=130,surfaceMaxAltitude=220,surfaceMinAltitude=50,systemZone="Average",territories=41072,type="Planet",waterLevel=nil,planetarySystemId=0},[7]={name="Sinnen",description="Sinnen is a an empty and rocky hell. With no atmosphere to speak of it is one of the least hospitable planets in the sector. The arkship geological survey reports mostly flatlands alongside deep ravines which look to have once been riverbeds. This planet simply looks to have dried up and died, likely from solar winds.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9226,atmosphericEngineMaxAltitude=10335,biosphere="Desert",classification="Mesoplanet",bodyId=7,GM=13033380591,gravity=0.4401121421448438,fullAtmosphericDensityMaxAltitude=-120,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=11620,numSatellites=1,positionFromSun=7,center={x=58665538,y=29665535,z=58165535},radius=54950,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=6270,surfaceArea=37944188928,surfaceAverageAltitude=317,surfaceMaxAltitude=360,surfaceMinAltitude=23,systemZone="Average",territories=48002,type="Planet",waterLevel=nil,planetarySystemId=0},[70]={name="Sinnen Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=70,GM=396912600,gravity=0.1360346539426409,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=58969616,y=29797945,z=57969449},radius=17000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=3631681280,surfaceAverageAltitude=-2050,surfaceMaxAltitude=-1950,surfaceMinAltitude=-2150,systemZone=nil,territories=4322,type="",waterLevel=nil,planetarySystemId=0},[110]={name="Symeon",description="Symeon is an ice planet mysteriously split at the equator by a band of solid desert. Exactly how this phenomenon is possible is unclear but some sort of weather anomaly may be responsible. The arkship geological survey reports a fairly diverse mix of flat-lands alongside mountainous formations.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.9559,atmosphericEngineMaxAltitude=6920,biosphere="Ice, Desert",classification="Hybrid",bodyId=110,GM=9204742375,gravity=0.3920998898971822,fullAtmosphericDensityMaxAltitude=-30,habitability="High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=7800,numSatellites=0,positionFromSun=11,center={x=14165536,y=-85634465,z=-934464.3},radius=49050,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=4230,surfaceArea=30233462784,surfaceAverageAltitude=39,surfaceMaxAltitude=450,surfaceMinAltitude=126,systemZone="High",territories=38882,type="Planet",waterLevel=nil,planetarySystemId=0},[4]={name="Talemai",description="Talemai is a planet in the final stages of an Ice Age. It seems likely that the planet was thrown into tumult by a cataclysmic volcanic event which resulted in its current state. The arkship geological survey reports large mountainous regions across the entire planet.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.8776,atmosphericEngineMaxAltitude=9685,biosphere="Barren",classification="Psychroplanet",bodyId=4,GM=14893847582,gravity=0.4641182439650478,fullAtmosphericDensityMaxAltitude=-78,habitability="Average",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=10890,numSatellites=3,positionFromSun=4,center={x=-13234464,y=55765536,z=465536},radius=57500,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=5890,surfaceArea=41547563008,surfaceAverageAltitude=580,surfaceMaxAltitude=610,surfaceMinAltitude=520,systemZone="Average",territories=52922,type="Planet",waterLevel=nil,planetarySystemId=0},[42]={name="Talemai Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=42,GM=264870000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-13058408,y=55781856,z=740177.76},radius=15000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=720,surfaceMaxAltitude=850,surfaceMinAltitude=0,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0},[40]={name="Talemai Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=40,GM=141264000,gravity=0.09602446196397631,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-13503090,y=55594325,z=769838.64},radius=12000,safeAreaEdgeAltitude=500000,size="S",spaceEngineMinAltitude=0,surfaceArea=1809557376,surfaceAverageAltitude=250,surfaceMaxAltitude=450,surfaceMinAltitude=0,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[41]={name="Talemai Moon 3",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=41,GM=106830900,gravity=0.08802242599860607,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=-12800515,y=55700259,z=325207.84},radius=11000,safeAreaEdgeAltitude=500000,size="XS",spaceEngineMinAltitude=0,surfaceArea=1520530944,surfaceAverageAltitude=190,surfaceMaxAltitude=400,surfaceMinAltitude=0,systemZone=nil,territories=1922,type="",waterLevel=nil,planetarySystemId=0},[8]={name="Teoma",description="[REDACTED] The arkship geological survey [REDACTED]. This planet should not be here.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.7834,atmosphericEngineMaxAltitude=5580,biosphere="Forest",classification="Mesoplanet",bodyId=8,GM=18477723600,gravity=0.48812434578525177,fullAtmosphericDensityMaxAltitude=15,habitability="High",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=6280,numSatellites=0,positionFromSun=8,center={x=80865538,y=54665536,z=-934463.94},radius=62000,safeAreaEdgeAltitude=500000,size="L",spaceEngineMinAltitude=3420,surfaceArea=48305131520,surfaceAverageAltitude=700,surfaceMaxAltitude=1100,surfaceMinAltitude=-200,systemZone="High",territories=60752,type="Planet",waterLevel=0,planetarySystemId=0},[3]={name="Thades",description="Thades is a scorched desert planet. Perhaps it was once teaming with life but now all that remains is ash and dust. The arkship geological survey reports a rocky mountainous planet bisected by a massive unnatural ravine; something happened to this planet.",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0.03552,atmosphericEngineMaxAltitude=32180,biosphere="Desert",classification="Thermoplanet",bodyId=3,GM=11776905000,gravity=0.49612641213015557,fullAtmosphericDensityMaxAltitude=150,habitability="Low",hasAtmosphere=true,isSanctuary=false,noAtmosphericDensityAltitude=32800,numSatellites=2,positionFromSun=3,center={x=29165536,y=10865536,z=65536},radius=49000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=21400,surfaceArea=30171856896,surfaceAverageAltitude=13640,surfaceMaxAltitude=13690,surfaceMinAltitude=370,systemZone="Low",territories=38882,type="Planet",waterLevel=nil,planetarySystemId=0},[30]={name="Thades Moon 1",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=30,GM=211564034,gravity=0.11202853997062348,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=29214402,y=10907080.695,z=433858.2},radius=14000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2463008768,surfaceAverageAltitude=60,surfaceMaxAltitude=300,surfaceMinAltitude=0,systemZone=nil,territories=3002,type="",waterLevel=nil,planetarySystemId=0},[31]={name="Thades Moon 2",description="",antiGravMinAltitude=1000,atmosphericDensityAboveSurface=0,atmosphericEngineMaxAltitude=0,biosphere="",classification="",bodyId=31,GM=264870000,gravity=0.12003058201190042,fullAtmosphericDensityMaxAltitude=0,habitability="",hasAtmosphere=false,isSanctuary=false,noAtmosphericDensityAltitude=0,numSatellites=0,positionFromSun=0,center={x=29404193,y=10432768,z=19554.131},radius=15000,safeAreaEdgeAltitude=500000,size="M",spaceEngineMinAltitude=0,surfaceArea=2827433472,surfaceAverageAltitude=70,surfaceMaxAltitude=350,surfaceMinAltitude=0,systemZone=nil,territories=3632,type="",waterLevel=nil,planetarySystemId=0}}}end;function SetupAtlas()aX=Atlas()for bm,bn in pairs(aX[0])do if aA==nil or bn.center.xaB then aB=bn.center.x end;if aC==nil or bn.center.yaD then aD=bn.center.y end end;aY=""local g2=1.1*(aB-aA)/1920;local g3=1.4*(aD-aC)/1080;for bm,bn in pairs(aX[0])do local bI=960+bn.center.x/g2;local bJ=540+bn.center.y/g3;aY=aY..''if not string.match(bn.name,"Moon")and not string.match(bn.name,"Sanctuary")and not string.match(bn.name,"Space")then aY=aY..""..bn.name..""end end;local c0=vec3(core.getConstructWorldPos())local bI=960+c0.x/g2;local bJ=540+c0.y/g3;aY=aY..''aY=aY.."You Are Here"aY=aY..[[]]aZ=g2;a_=g3;if screen_2 then screen_2.setHTML(''..aY)local c0=vec3(core.getConstructWorldPos())local bI=960+c0.x/g2;local bJ=540+c0.y/g3;aY=''aY=aY.."You Are Here"b0=screen_2.addContent((bI-80)/19.20,(bJ-80)/10.80,aY)end end;function PlanetRef()local function g4(g5)return type(g5)=='number'end;local function g6(g5)return type(tonumber(g5))=='number'end;local function g7(g8)return type(g8)=='table'end;local function g9(ga)return type(ga)=='string'end;local function gb(bn)return g7(bn)and g4(bn.x and bn.y and bn.z)end;local function gc(gd)return g7(gd)and g4(gd.latitude and gd.longitude and gd.altitude and gd.bodyId and gd.systemId)end;local ge=math.pi/180;local gf=180/math.pi;local epsilon=1e-10;local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local c1='::pos{'..p..','..p..','..p..','..p..','..p..'}'local utils=require('cpml.utils')local vec3=require('cpml.vec3')local gg=utils.clamp;local function float_eq(bR,bS)if bR==0 then return math.abs(bS)<1e-09 end;if bS==0 then return math.abs(bR)<1e-09 end;return math.abs(bR-bS)=0 then local h4=math.sqrt(h3)local eW=h2+h4;local eX=h2-h4;if eX>0 then return eY,eW,eX elseif eW>0 then return eY,eW,nil end end end;return nil,nil,nil end;function gx:closestBody(h5)assert(type(h5)=='table','Invalid coordinates.')local h6,eY;local h7=vec3(h5)for _,h8 in pairs(self)do local h9=(h8.center-h7):len2()if(not eY or h9=0 and b_ or 2*math.pi+b_;bY=math.pi/2-math.acos(bW.z/a8)end;return setmetatable({latitude=bY,longitude=bZ,altitude=bX,bodyId=self.bodyId,systemId=self.planetarySystemId},MapPosition)end;function gm:convertToWorldCoordinates(gw)local ha=g9(gw)and gv(gw)or gw;if ha.bodyId==0 then return vec3(ha.latitude,ha.longitude,ha.altitude)end;assert(gc(ha),'Argument 1 (mapPosition) is not an instance of "MapPosition".')assert(ha.systemId==self.planetarySystemId,'Argument 1 (mapPosition) has a different planetary system ID.')assert(ha.bodyId==self.bodyId,'Argument 1 (mapPosition) has a different planetary body ID.')local c4=math.cos(ha.latitude)return self.center+(self.radius+ha.altitude)*vec3(c4*math.cos(ha.longitude),c4*math.sin(ha.longitude),math.sin(ha.latitude))end;function gm:getAltitude(bU)return(vec3(bU)-self.center):len()-self.radius end;function gm:getDistance(bU)return(vec3(bU)-self.center):len()end;function gm:getGravity(bU)local hb=self.center-vec3(bU)local hc=hb:len2()return self.GM/hc*hb/math.sqrt(hc)end;return setmetatable(b1,{__call=function(_,...)return gF(...)end})end;function Keplers()local vec3=require('cpml.vec3')local PlanetRef=PlanetRef()local function g9(ga)return type(ga)=='string'end;local function g7(g8)return type(g8)=='table'end;local function float_eq(bR,bS)if bR==0 then return math.abs(bS)<1e-09 end;if bS==0 then return math.abs(bR)<1e-09 end;return math.abs(bR-bS)0 then ht=hs;hu=ht+hn/2 end;if hu>hn then hu=hu-hn end end;return{periapsis={position=hk,speed=hm/hi,circularOrbitSpeed=math.sqrt(hf/hi),altitude=hi-self.body.radius},apoapsis=hl and{position=hl,speed=hm/hj,circularOrbitSpeed=math.sqrt(hf/hj),altitude=hj-self.body.radius},currentVelocity=bn,currentPosition=c0,eccentricity=hh,period=hn,eccentricAnomaly=hp,meanAnomaly=hr,timeToPeriapsis=ht,timeToApoapsis=hu}end;local function hv(hw)local h8=PlanetRef.BodyParameters(hw.planetarySystemId,hw.bodyId,hw.radius,hw.center,hw.GM)return setmetatable({body=h8},Kepler)end;return setmetatable(Kepler,{__call=function(_,...)return hv(...)end})end;function Kinematics()local b3={}local hx=30000000/3600;local hy=hx*hx;local hz=100;local function hA(bn)return 1/math.sqrt(1-bn*bn/hy)end;function b3.computeAccelerationTime(hB,hC,hD)local hE=hx*math.asin(hB/hx)return(hx*math.asin(hD/hx)-hE)/hC end;function b3.computeDistanceAndTime(hB,hD,hF,hG,hH,hI)hH=hH or 0;hI=hI or 0;local hJ=hB<=hD;local hK=hG*(hJ and 1 or-1)/hF;local hL=-hI/hF;local hM=hK+hL;if hJ and hM<=0 or not hJ and hM>=0 then return-1,-1 end;local hN,hO=0,0;if hK~=0 and hH>0 then local hE=math.asin(hB/hx)local hP=math.pi*(hK/2+hL)local hQ=hK*hH;local hR=hx*math.pi;local bn=function(g8)local cF=(hP*g8-hQ*math.sin(math.pi*g8/2/hH)+hR*hE)/hR;local hS=math.tan(cF)return hx*hS/math.sqrt(hS*hS+1)end;local hT=hJ and function(ga)return ga>=hD end or function(ga)return ga<=hD end;hO=2*hH;if hT(bn(hO))then local hU=0;while math.abs(hO-hU)>0.5 do local g8=(hO+hU)/2;if hT(bn(g8))then hO=g8 else hU=g8 end end end;local hV=hB;local hW=hO/hz;for hX=1,hz do local bC=bn(hX*hW)hN=hN+(bC+hV)*hW/2;hV=bC end;if hO<2*hH then return hN,hO end;hB=hV end;local hE=hx*math.asin(hB/hx)local bp=(hx*math.asin(hD/hx)-hE)/hM;local hY=hy*math.cos(hE/hx)/hM;local a8=hY-hy*math.cos((hM*bp+hE)/hx)/hM;return a8+hN,bp+hO end;function b3.computeTravelTime(hB,hC,a8)if a8==0 then return 0 end;if hC>0 then local hE=hx*math.asin(hB/hx)local hY=hy*math.cos(hE/hx)/hC;return(hx*math.acos(hC*(hY-a8)/hy)-hE)/hC end;if hB==0 then return-1 end;assert(hB>0,'Acceleration and initial speed are both zero.')return a8/hB end;function b3.lorentz(bn)return hA(bn)end;return b3 end;function script.onStart()VERSION_NUMBER=5.320;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()b1=PlanetRef()b2=b1(Atlas())b3=Kinematics()b5=Keplers()AddLocationsToAtlas()UpdateAtlasLocationsList()UpdateAutopilotTarget()coroutine.yield()unit.hide()system.showScreen(1)collectgarbage("collect")coroutine.yield()unit.setTimer("apTick",apTickRate)unit.setTimer("hudTick",hudTickRate)unit.setTimer("oneSecond",1)unit.setTimer("tenthSecond",1/10)if UseSatNav then unit.setTimer("fiveSecond",5)end end)end;function SaveDataBank(hZ)if dbHud_1 then if not a3 then for bm,bn in pairs(b)do dbHud_1.setStringValue(bn,g(_G[bn]))if hZ and dbHud_2 then dbHud_2.setStringValue(bn,g(_G[bn]))end end;for bm,bn in pairs(a)do dbHud_1.setStringValue(bn,g(_G[bn]))if hZ and dbHud_2 then dbHud_2.setStringValue(bn,g(_G[bn]))end end;c("Saved Variables to Datacore")if hZ and dbHud_2 then P="Databank copied. Remove copy when ready."end 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 bx=j()if door and(bx>0 or bx==0 and aj<10000)then for _,bn in pairs(door)do bn.toggle()end end;if switch then for _,bn in pairs(switch)do bn.toggle()end end;if forcefield and(bx>0 or bx==0 and aj<10000)then for _,bn in pairs(forcefield)do bn.toggle()end end;SaveDataBank()if button then button.activate()end end;function script.onTick(h_)if h_=="tenthSecond"then if j()>0 and not WasInAtmo then if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and AtmoSpeedAssist and(AltitudeHold or Reentry)then s=1;Nav.control.cancelCurrentControlMasterMode()w=false end end;if AutopilotTargetName~="None"then if panelInterplanetary==nil then SetupInterplanetaryPanel()end;if AutopilotTargetName~=nil then local i0=CustomTarget~=nil;planetMaxMass=GetAutopilotMaxMass()system.updateData(interplanetaryHeaderText,'{"label": "Target", "value": "'..AutopilotTargetName..'", "unit":""}')travelTime=GetAutopilotTravelTime()if i0 and not Autopilot then a8=(vec3(core.getConstructWorldPos())-CustomTarget.position):len()else a8=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()end;if not TurnBurn then U,V=GetAutopilotBrakeDistanceAndTime(bb)W,X=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else U,V=GetAutopilotTBBrakeDistanceAndTime(bb)W,X=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;local dh,di=getDistanceDisplayString(a8)system.updateData(widgetDistanceText,'{"label": "distance", "value": "'..dh..'", "unit":"'..di..'"}')system.updateData(widgetTravelTimeText,'{"label": "Travel Time", "value": "'..FormatTimeString(travelTime)..'", "unit":""}')dh,di=getDistanceDisplayString(U)system.updateData(widgetCurBrakeDistanceText,'{"label": "Cur Brake distance", "value": "'..dh..'", "unit":"'..di..'"}')system.updateData(widgetCurBrakeTimeText,'{"label": "Cur Brake Time", "value": "'..FormatTimeString(V)..'", "unit":""}')dh,di=getDistanceDisplayString(W)system.updateData(widgetMaxBrakeDistanceText,'{"label": "Max Brake distance", "value": "'..dh..'", "unit":"'..di..'"}')system.updateData(widgetMaxBrakeTimeText,'{"label": "Max Brake Time", "value": "'..FormatTimeString(X)..'", "unit":""}')system.updateData(widgetMaxMassText,'{"label": "Maximum Mass", "value": "'..e("%.2f",planetMaxMass/1000)..'", "unit":" Tons"}')dh,di=getDistanceDisplayString(AutopilotTargetOrbit)system.updateData(widgetTargetOrbitText,'{"label": "Target Orbit", "value": "'..e("%.2f",dh)..'", "unit":"'..di..'"}')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 h_=="oneSecond"then ag=false;RefreshLastMaxBrake(nil,true)updateDistance()updateRadar()updateWeapons()local cd={}local dr=GetFlightStyle()DrawOdometer(cd,a1,TotalDistanceTravelled,dr,a2)if ShouldCheckDamage then CheckDamage(cd)end;aa=table.concat(cd,"")collectgarbage("collect")elseif h_=="fiveSecond"then ah=dbHud_1.getStringValue("SPBAutopilotTargetName")if ah~=nil and ah~=""and ah~="SatNavNotChanged"then local bo=json.decode(dbHud_1.getStringValue("SavedLocations"))if bo~=nil then _G["SavedLocations"]=bo;local cb=-1;local c7;for bm,bn in pairs(SavedLocations)do if bn.name and bn.name=="SatNav Location"then cb=bm;break end end;if cb~=-1 then c7=SavedLocations[cb]cb=-1;for bm,bn in pairs(aX[0])do if bn.name and bn.name=="SatNav Location"then cb=bm;break end end;if cb>-1 then aX[0][cb]=c7 end;UpdateAtlasLocationsList()P=c7.name.." position updated"end end;for i=1,#AtlasOrdered do if AtlasOrdered[i].name==ah then AutopilotTargetIndex=i;system.print("Index = "..AutopilotTargetIndex.." "..AtlasOrdered[i].name)UpdateAutopilotTarget()dbHud_1.setStringValue("SPBAutopilotTargetName","SatNavNotChanged")break end end end elseif h_=="msgTick"then local cd={}DisplayMessage(cd,"empty")P="empty"unit.stopTimer("msgTick")a7=3 elseif h_=="animateTick"then b7=true;b6=false;a5=0;a6=0;unit.stopTimer("animateTick")elseif h_=="hudTick"then local cd={}HUDPrologue(cd)if showHud then UpdateHud(cd)else DisplayOrbitScreen(cd)DrawWarnings(cd)end;HUDEpilogue(cd)cd[#cd+1]=e([[]],ResolutionX,ResolutionY)if P~="empty"then DisplayMessage(cd,P)end;if o()==0 and userControlScheme=="virtual joystick"then DrawDeadZone(cd)end;if o()==1 and screen_1 and screen_1.getMouseY()~=-1 then SetButtonContains()DrawButtons(cd)if screen_1.getMouseState()==1 then CheckButtons()end;cd[#cd+1]=e([[]],x,y,a5,a6)elseif system.isViewLocked()==0 then if o()==1 and O then SetButtonContains()DrawButtons(cd)if not b6 and not b7 then local i1=table.concat(cd,"")cd={}cd[#cd+1]=e("",ResolutionX,ResolutionY)cd[#cd+1]=aY;cd[#cd+1]=i1;cd[#cd+1]=""b6=true;cd[#cd+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(cd,"")system.setScreen(content)elseif b7 then local i1=table.concat(cd,"")cd={}cd[#cd+1]=e("",ResolutionX,ResolutionY)cd[#cd+1]=aY;cd[#cd+1]=i1;cd[#cd+1]=""end;if not b6 then cd[#cd+1]=e([[]],x,y,a5,a6)end else CheckButtons()end else if not O and o()==0 then CheckButtons()if a8>DeadZone then DrawCursorLine(cd)end else SetButtonContains()DrawButtons(cd)end;cd[#cd+1]=e([[]],x,y,a5,a6)end;cd[#cd+1]=[[]]content=table.concat(cd,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end elseif h_=="apTick"then b9=vec3(core.getConstructWorldOrientationForward()):dot(vec3(core.getWorldVelocity()):normalize())ai=j()>0;local bp=system.getTime()local i2=bp-bh;bh=bp;local cg=vec3(core.getConstructWorldOrientationForward())local ch=vec3(core.getConstructWorldOrientationRight())local i3=vec3(core.getConstructWorldOrientationUp())local ci=vec3(core.getWorldVertical())local i4=vec3(core.getConstructWorldPos())local i5=core.getVelocity()local dt=getRoll(ci,cg,ch)local du=dt/180*math.pi;local dv=math.cos(du)local dw=math.sin(du)local cj=getPitch(ci,cg,ch)local i6=getPitch(ci,cg,ch*dv+i3*dw)local i7=-math.deg(cA(i3,ba,cg))local i8=math.deg(cA(ch,ba,cg))bg=ai and i7<-YawStallAngle or i7>YawStallAngle or i8<-PitchStallAngle or i8>PitchStallAngle;local i9=150;be=system.getMouseDeltaX()bf=system.getMouseDeltaY()if InvertMouse and not O then bf=-bf end;I=0;M=0;H=0;ba=vec3(core.getWorldVelocity())bb=vec3(ba):len()sys=b2[0]planet=sys:closestBody(core.getConstructWorldPos())kepPlanet=b5(planet)orbit=kepPlanet:orbitalParameters(core.getConstructWorldPos(),ba)af=hoverDetectGround()local bz=planet:getGravity(core.getConstructWorldPos()):len()*n()bi=0;b4=core.getMaxKinematicsParametersAlongAxis("ground",core.getConstructOrientationUp())[1]if o()==1 and screen_1 and screen_1.getMouseY()~=-1 then a5=screen_1.getMouseX()*ResolutionX;a6=screen_1.getMouseY()*ResolutionY elseif system.isViewLocked()==0 then if o()==1 and O then if not b6 then a5=a5+be;a6=a6+bf end else a5=0;a6=0 end else a5=a5+be;a6=a6+bf;a8=math.sqrt(a5*a5+a6*a6)if not O and o()==0 then if userControlScheme=="virtual joystick"then if a5>0 and a5>DeadZone then I=I-(a5-DeadZone)*MouseXSensitivity elseif a5<0 and a50 and a6>DeadZone then H=H-(a6-DeadZone)*MouseYSensitivity elseif a6<0 and a68334;if bb>SpaceSpeedLimit/3.6 and not ai and not Autopilot and not ia then P="Space Speed Engine Shutoff reached"if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0 end;if not ia and LastIsWarping then if not BrakeIsOn then BrakeToggle()end;if Autopilot then ToggleAutopilot()end end;LastIsWarping=ia;if ai and j()>0.09 then if bb>bk/3.6 and not AtmoSpeedAssist and not an then BrakeIsOn=true;an=true elseif not AtmoSpeedAssist and an then if bb85)and bb>=bk/3.6-1 then BrakeIsOn=false;ProgradeIsOn=false;C=true;ac=false;ae=true;Autopilot=false;BeginReentry()else if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,math.floor(bk))s=0 end elseif bb>B then AlignToWorldVector(vec3(ba),0.01)end end;if RetrogradeIsOn then if ai then RetrogradeIsOn=false elseif bb>B then AlignToWorldVector(-vec3(ba))end end;if not ProgradeIsOn and ac then if j()==0 then C=true;BeginReentry()ac=false;ae=true else ac=false;ToggleAutopilot()end end;local dY=vec3(core.getWorldVertical())*-1;local dW=ba.x*dY.x+ba.y*dY.y+ba.z*dY.z;if ae and(ajHoldAltitude-200)and bb*3.6>bk-100 and math.abs(dW)<20 and j()>=0.1 and(CustomTarget.position-i4):len()>2000+aj then ToggleAutopilot()ae=false end;if Autopilot and j()==0 and not ac then local ic=AutopilotTargetCoords;local id=false;if CustomTarget~=nil and CustomTarget.planetname~="Space"then AutopilotRealigned=true;local ie=(CustomTarget.position-a0.center):normalize()local ig=ie:project_on_plane((a0.center-i4):normalize()):normalize()local ih=a0.center+ig*(a0.radius+AutopilotTargetOrbit)local ii=CustomTarget.position+(CustomTarget.position-a0.center):normalize()*(AutopilotTargetOrbit-a0:getAltitude(CustomTarget.position))if not TargetSet then if(i4-ih):len()<(i4-ii):len()then ic=ih;AutopilotTargetCoords=ic else ic=CustomTarget.position+(CustomTarget.position-a0.center):normalize()*(AutopilotTargetOrbit-a0:getAltitude(CustomTarget.position))AutopilotTargetCoords=ic end;local ck=zeroConvertToMapPosition(a0,AutopilotTargetCoords)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)id=true;TargetSet=true end;AutopilotPlanetGravity=0 elseif CustomTarget~=nil and CustomTarget.planetname=="Space"then AutopilotPlanetGravity=0;id=true;TargetSet=true;AutopilotRealigned=true;ic=CustomTarget.position+(i4-CustomTarget.position)*AutopilotTargetOrbit elseif CustomTarget==nil then AutopilotPlanetGravity=0;if not TargetSet then local ie=(i4+ba*100000-a0.center):normalize()local ig=ie:project_on_plane((a0.center-i4):normalize()):normalize()if ig:len()<1 then ie=(i4+vec3(core.getConstructWorldOrientationForward())*100000-a0.center):normalize()ig=ie:project_on_plane((a0.center-i4):normalize()):normalize()end;ic=a0.center+ig*(a0.radius+AutopilotTargetOrbit)AutopilotTargetCoords=ic;TargetSet=true;id=true;AutopilotRealigned=true;local ck=zeroConvertToMapPosition(a0,AutopilotTargetCoords)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)end end;AutopilotDistance=(vec3(ic)-vec3(core.getConstructWorldPos())):len()local eV,eW,eX=b2:getPlanetarySystem(0):castIntersections(i4,ba:normalize(),function(eY)if eY.noAtmosphericDensityAltitude>0 then return eY.radius+eY.noAtmosphericDensityAltitude else return eY.radius+eY.surfaceMaxAltitude*1.5 end end)local eZ=eW;if eX~=nil and eW~=nil then eZ=math.min(eX,eW)end;if eZ~=nil and eZ300 and AutopilotAccelerating then local de=vec3(ic)-vec3(core.getConstructWorldPos())local ik=utils.clamp(math.deg(cA(i3,ba:normalize(),de:normalize()))*bb/500,-90,90)local il=utils.clamp(math.deg(cA(ch,ba:normalize(),de:normalize()))*bb/500,-90,90)if math.abs(ik)<20 and math.abs(il)<20 then ik=ik*2;il=il*2 end;if math.abs(ik)<2 and math.abs(il)<2 then ik=ik*2;il=il*2 end;local i7=-math.deg(cA(i3,cg,ba:normalize()))local i8=-math.deg(cA(ch,cg,ba:normalize()))if apPitchPID==nil then apPitchPID=pid.new(2*0.01,0,2*0.1)end;apPitchPID:inject(il-i8)local im=utils.clamp(apPitchPID:get(),-1,1)H=H+im;if apYawPID==nil then apYawPID=pid.new(2*0.01,0,2*0.1)end;apYawPID:inject(ik-i7)local io=utils.clamp(apYawPID:get(),-1,1)I=I+io;id=true;if math.abs(ik)>2 or math.abs(il)>2 then AutopilotStatus="Adjusting Trajectory"else AutopilotStatus="Accelerating"end end;if ij=MaxGameVelocity or fm==0 and z then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0 end;if AutopilotDistance<=U then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;z=false end elseif AutopilotBraking then if AutopilotStatus~="Orbiting to Target"then BrakeIsOn=true;L=1 end;if TurnBurn then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,100)s=1 end;local _,ip=b5(a0):escapeAndOrbitalSpeed((vec3(core.getConstructWorldPos())-planet.center):len()-planet.radius)local de,iq,ir;if CustomTarget~=nil then de=CustomTarget.position-i4;iq=planet:getAltitude(CustomTarget.position)ir=math.sqrt(de:len()^2-(aj-iq)^2)end;if CustomTarget~=nil and CustomTarget.planetname=="Space"and bb<50 then P="Autopilot complete, arrived at space location"AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"elseif CustomTarget~=nil and CustomTarget.planetname~="Space"and bb<=ip and(orbit.apoapsis==nil or orbit.periapsis==nil or orbit.apoapsis.altitude<=0 or orbit.periapsis.altitude<=0)then P="Autopilot complete, proceeding with reentry"AutopilotTargetCoords=CustomTarget.position;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;z=false;ProgradeIsOn=true;ac=true;local ck=zeroConvertToMapPosition(a0,AutopilotTargetCoords)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)elseif orbit.periapsis~=nil and orbit.periapsis.altitude>0 and orbit.eccentricity<1 then AutopilotStatus="Circularizing"local _,ip=b5(a0):escapeAndOrbitalSpeed((vec3(core.getConstructWorldPos())-planet.center):len()-planet.radius)if bb<=ip then if CustomTarget~=nil then if ba:normalize():dot(de:normalize())>0.4 then AutopilotStatus="Orbiting to Target"if not WaypointSet then BrakeIsOn=false;local ck=zeroConvertToMapPosition(a0,CustomTarget.position)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)WaypointSet=true end else P="Autopilot complete, proceeding with reentry"AutopilotTargetCoords=CustomTarget.position;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;z=false;ProgradeIsOn=true;ac=true;BrakeIsOn=false;local ck=zeroConvertToMapPosition(a0,CustomTarget.position)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)WaypointSet=false end else BrakeIsOn=false;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"P="Autopilot completed, orbit established"L=0;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;z=false;if CustomTarget~=nil and CustomTarget.planetname~="Space"then ProgradeIsOn=true;ac=true end end end end elseif AutopilotCruising then if AutopilotDistance<=U then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true end;local fm=unit.getThrottle()if AtmoSpeedAssist then fm=s end;if fm>0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if ib then if not AutopilotRealigned and CustomTarget==nil or not AutopilotRealigned and CustomTarget~=nil and CustomTarget.planetname~="Space"then if not ac then AutopilotTargetCoords=vec3(a0.center)+(AutopilotTargetOrbit+a0.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()end;AutopilotRealigned=true elseif ib then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not z then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)s=round(AutopilotInterplanetaryThrottle,2)z=true;BrakeIsOn=false end end end end elseif Autopilot and(CustomTarget~=nil and CustomTarget.planetname~="Space"and j()>0)then P="Autopilot complete, proceeding with reentry"AutopilotTargetCoords=CustomTarget.position;BrakeIsOn=false;AutopilotBraking=false;Autopilot=false;TargetSet=false;AutopilotStatus="Aligning"L=0;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;z=false;ProgradeIsOn=true;ac=true;local ck=zeroConvertToMapPosition(a0,CustomTarget.position)ck="::pos{"..ck.systemId..","..ck.bodyId..","..ck.latitude..","..ck.longitude..","..ck.altitude.."}"system.setWaypoint(ck)end;if N then b8=true;local il=0;local c0=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local is=c0-vec3(core.getConstructWorldPos())local it=vec3(is):project_on(vec3(core.getConstructWorldOrientationForward())):len()local iu=vec3(is):project_on(vec3(core.getConstructWorldOrientationRight())):len()local a8=math.sqrt(it*it+iu*iu)AlignToWorldVector(is:normalize())local iv=40;local iw=a8iy then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(il-cj)local im=pitchPID:get()H=im end end;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget or LockPitch~=nil then local dE=unit.getClosestPlanetInfluence()>0;local iz=HoldAltitude-aj;local iA=500+bb;local iB=1;if AutoTakeoff then iB=utils.clamp(bb/100,0.1,1)end;local il=(utils.smoothstep(iz,-iA,iA)-0.5)*2*MaxPitch*iB;if not Reentry and not ac and not VectorToTarget and cg:dot(ba:normalize())<0.99 then il=(utils.smoothstep(iz,-iA*utils.clamp(20-19*j()*10,1,20),iA*utils.clamp(20-19*j()*10,1,20))-0.5)*2*MaxPitch*utils.clamp(2-j()*10,1,2)*iB end;if not AltitudeHold then il=0 end;if LockPitch~=nil then if dE then il=LockPitch else LockPitch=nil end end;b8=true;local iC=H;if Reentry then local ReentrySpeed=math.floor(bk)local iD,iE=b3.computeDistanceAndTime(bb,ReentrySpeed/3.6,n(),0,0,LastMaxBrake-planet.gravity*9.8*n())local iF=aj-(planet.noAtmosphericDensityAltitude+5000)if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and aj>planet.noAtmosphericDensityAltitude+5000 and bb<=ReentrySpeed/3.6 and bb>ReentrySpeed/3.6-10 and math.abs(ba:normalize():dot(cg))>0.9 then Nav.control.cancelCurrentControlMasterMode()s=0 elseif Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle and(iD>-1 and iF<=iD or aj<=planet.noAtmosphericDensityAltitude+5000)then BrakeIsOn=true else BrakeIsOn=false end;if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=ReentrySpeed then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,ReentrySpeed)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if not C then il=-80;if j()>0.02 then P="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;il=0;b8=autoRollPreference end elseif planet.noAtmosphericDensityAltitude>0 and aj>planet.noAtmosphericDensityAltitude+5000 then b8=true elseif aj<=planet.noAtmosphericDensityAltitude+5000 then if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle then Nav.control.cancelCurrentControlMasterMode()Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,ReentrySpeed)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==bk then C=false;Reentry=false;b8=true end end end;if bb>B and not ad and not VectorToTarget and not BrakeLanding and ForceAlignment then AlignToWorldVector(vec3(ba))end;if(VectorToTarget or ad)and AutopilotTargetIndex>0 and j()>0.01 then local de;if CustomTarget~=nil then de=CustomTarget.position-vec3(core.getConstructWorldPos())else de=a0.center-i4 end;local i3=vec3(core.getConstructWorldOrientationUp())local ik=math.deg(cA(ci:normalize(),ba,de))*2;local iG=math.rad(math.abs(dt))if bb>i9 and j()>0.01 then local iH=utils.clamp(90-il*2,-90,90)bi=utils.clamp(ik*2,-iH,iH)local iI=ik;ik=utils.clamp(utils.clamp(ik,-YawStallAngle*0.85,YawStallAngle*0.85)*math.cos(iG)+4*(i6-il)*math.sin(math.rad(dt)),-YawStallAngle*0.85,YawStallAngle*0.85)il=utils.clamp(utils.clamp(il*math.cos(iG),-PitchStallAngle*0.85,PitchStallAngle*0.85)+math.abs(utils.clamp(math.abs(iI)*math.sin(iG),-PitchStallAngle*0.85,PitchStallAngle*0.85)),-PitchStallAngle*0.85,PitchStallAngle*0.85)else bi=0;ik=utils.clamp(ik,-90,90)end;local iJ=i7-ik;if not bg and bb>i9 and j()>0.01 then if yawPID==nil then yawPID=pid.new(5*0.01,0,5*0.1)end;yawPID:inject(iJ)local io=utils.clamp(yawPID:get(),-1,1)I=I+io elseif ai and af>-1 or bb0.01 then if(i7<-YawStallAngle or i7>YawStallAngle)and j()>0.01 then AlignToWorldVector(ba)end;if(i8<-PitchStallAngle or i8>PitchStallAngle)and j()>0.01 then il=utils.clamp(i6-i8,i6-PitchStallAngle*0.85,i6+PitchStallAngle*0.85)end end;if CustomTarget~=nil and not ad then local iq=planet:getAltitude(CustomTarget.position)local iF=math.sqrt(de:len()^2-(aj-iq)^2)local iK=LastMaxBrakeInAtmo;if iK then iK=iK*utils.clamp(bb/100,0.1,1)*j()else iK=LastMaxBrake end;if j()<0.01 then iK=LastMaxBrake else end;local dW=ba.x*dY.x+ba.y*dY.y+ba.z*dY.z;local iL=ba:len()-math.abs(dW)local iM=vec3(core.getWorldAirFrictionAcceleration())local iN=math.sqrt(iM:len()-iM:project_on(dY):len())*n()if bb>100 then U,V=b3.computeDistanceAndTime(bb,100,n(),0,0,iK+iN)local iO,iP=b3.computeDistanceAndTime(100,0,n(),0,0,iK/2)U=U+iO else U,V=b3.computeDistanceAndTime(bb,0,n(),0,0,iK/2)end;StrongBrakes=true;if not ad and iF<=U+bb*i2/2 and(ba:project_on_plane(ci):normalize():dot(de:project_on_plane(ci):normalize())>0.99 or VectorStatus=="Finalizing Approach")then VectorStatus="Finalizing Approach"if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)s=0;if AltitudeHold then ToggleAltitudeHold()VectorToTarget=true end;BrakeIsOn=true elseif not AutoTakeoff then BrakeIsOn=false end;if VectorStatus=="Finalizing Approach"and(iL<0.1 or iF<0.1 or LastDistanceToTarget~=nil and LastDistanceToTarget0.01 and af==-1 and bb>i9 and VectorStatus~="Finalizing Approach"then AlignToWorldVector(ba)il=utils.clamp(i6-i8,i6-PitchStallAngle*0.85,i6+PitchStallAngle*0.85)end;H=iC;local fv=-1;local iy=0.1;if BrakeLanding then il=0;local dW=ba.x*dY.x+ba.y*dY.y+ba.z*dY.z;local iQ=false;local iR=30;if b4~=nil and b4>0 then local iN=0;local dz=utils.clamp(j(),0.4,2)local iK=LastMaxBrakeInAtmo*utils.clamp(bb/100,0.1,1)*dz;local iS=b4*dz+iK+iN-bz;local iT=iK+iN-bz;local iU=iK/2+iN-bz;local iV=bb-math.sqrt(math.abs(iU/2)*20/(0.5*n()))*utils.sign(iU)if iV<0 then iV=0 end;local iW;if bb>100 then local iX,_=b3.computeDistanceAndTime(bb,100,n(),0,0,iK)local iY,_=b3.computeDistanceAndTime(100,0,n(),0,0,math.sqrt(iK))iW=iX+iY else iW=b3.computeDistanceAndTime(bb,0,n(),0,0,math.sqrt(iK))end;if iW<20 then BrakeIsOn=false else local iZ=0;if iV>100 then local i_,_=b3.computeDistanceAndTime(iV,100,n(),0,0,iS)local j0,_=b3.computeDistanceAndTime(100,0,n(),0,0,b4*dz+math.sqrt(iK)+iN-bz)iZ=i_+j0 else iZ,_=b3.computeDistanceAndTime(iV,0,n(),0,0,b4*dz+math.sqrt(iK)+iN-bz)end;iZ=(iZ+15+bb*i2)*1.1;local j1=CustomTarget~=nil and planet:getAltitude(CustomTarget.position)>0 and CustomTarget.safe;if j1 then local iq=planet:getAltitude(CustomTarget.position)local j2=aj-iq-100;local de=CustomTarget.position-vec3(core.getConstructWorldPos())local ir=math.sqrt(de:len()^2-(aj-iq)^2)if ir>100 then j1=false elseif j2<=iZ or iZ==-1 then BrakeIsOn=true;iQ=true else BrakeIsOn=false;iQ=true end end;if not j1 and CalculateBrakeLandingSpeed then if iZ>=iR then BrakeIsOn=true else BrakeIsOn=false end;iQ=true end end end;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)fv=af;if fv>-1 then b8=autoRollPreference;if bb<1 or ba:normalize():dot(ci)<0 then BrakeLanding=false;AltitudeHold=false;GearExtended=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)a4=0;BrakeIsOn=true else BrakeIsOn=true end elseif StrongBrakes and ba:normalize():dot(-dY)<0.999 then BrakeIsOn=true elseif dW<-brakeLandingRate and not iQ then BrakeIsOn=true elseif not iQ then BrakeIsOn=false end end;if AutoTakeoff or ad then local eV,eX,eW=b2:getPlanetarySystem(0):castIntersections(i4,(AutopilotTargetCoords-i4):normalize(),function(eY)return eY.radius+eY.noAtmosphericDensityAltitude end)if math.abs(il)<15 and aj/HoldAltitude>0.75 then AutoTakeoff=false;if not ad then if Nav.axisCommandManager:getAxisCommandType(0)==0 and not AtmoSpeedAssist then Nav.control.cancelCurrentControlMasterMode()end elseif ad and bb-1;local j4=cj;if(VectorToTarget or ad)and not j3 and bb>i9 and j()>0.01 then local iG=math.rad(math.abs(dt))j4=cj*math.abs(math.cos(iG))+i8*math.sin(iG)end;local j5=utils.clamp(il-j4,-PitchStallAngle*0.85,PitchStallAngle*0.85)if j()<0.01 and VectorToTarget then j5=utils.clamp(il-j4,-85,MaxPitch)elseif j()<0.01 then j5=utils.clamp(il-j4,-MaxPitch,MaxPitch)end;if math.abs(dt)<5 or VectorToTarget or BrakeLanding or j3 or AltitudeHold then if pitchPID==nil then pitchPID=pid.new(5*0.01,0,5*0.1)end;pitchPID:inject(j5)local im=pitchPID:get()H=H+im end end;Q=orbit.eccentricity;if antigrav and not ExternalAGG and aj<200000 then if AntigravTargetAltitude==nil or AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end end end end;function script.onFlush()if antigrav and not ExternalAGG then if antigrav.getState()==0 and antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(AntigravTargetAltitude)end end;if Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle and w then s=0;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,s)w=false elseif Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byTargetSpeed and not w then s=0;w=true end;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)torqueFactor=math.max(torqueFactor,0.01)brakeSpeedFactor=math.max(brakeSpeedFactor,0.01)brakeFlatFactor=math.max(brakeFlatFactor,0.01)autoRollFactor=math.max(autoRollFactor,0.01)turnAssistFactor=math.max(turnAssistFactor,0.01)local j6=utils.clamp(G+H+system.getControlDeviceForwardInput(),-1,1)local j7=utils.clamp(J+M+system.getControlDeviceYawInput(),-1,1)local j8=utils.clamp(K+I-system.getControlDeviceLeftRightInput(),-1,1)local j9=L;local ja=vec3(core.getWorldVertical())if ja==nil or ja:len()==0 then ja=(planet.center-vec3(core.getConstructWorldPos())):normalize()end;local jb=vec3(core.getConstructWorldOrientationUp())local jc=vec3(core.getConstructWorldOrientationForward())local jd=vec3(core.getConstructWorldOrientationRight())local je=vec3(core.getWorldVelocity())local jf=vec3(core.getWorldVelocity()):normalize()local jg=getRoll(ja,jc,jd)local jh=math.abs(jg)local ji=utils.sign(jg)local j=j()local jj=vec3(core.getWorldAngularVelocity())local jk=j6*pitchSpeedFactor*jd+j7*rollSpeedFactor*jc+j8*yawSpeedFactor*jb;if ja:len()>0.01 and(j>0.0 or ProgradeIsOn or Reentry or ac or AltitudeHold)then local dt=getRoll(ja,jc,jd)local du=dt/180*math.pi;local dv=math.cos(du)local dw=math.sin(du)local i6=getPitch(ja,jc,jd*dv+jb*dw)if b8==true and math.abs(bi-jg)>autoRollRollThreshold and j7==0 and math.abs(i6)<85 then local jl=bi;local jm=autoRollFactor;if j==0 then jm=jm/4;bi=0;jl=0 end;if rollPID==nil then rollPID=pid.new(jm*0.01,0,jm*0.1)end;rollPID:inject(jl-jg)local jn=rollPID:get()jk=jk+jn*jc end end;if ja:len()>0.01 and j>0.0 then local jo=20.0;if turnAssist==true and jh>jo and j6==0 and j8==0 then local jp=turnAssistFactor*0.1;local jq=turnAssistFactor*0.025;local jr=(jh-jo)/(180-jo)*180;local js=0;if jr<90 then js=jr/90 elseif jr<180 then js=(180-jr)/90 end;js=js*js;local jt=-ji*jq*(1.0-js)local ju=jp*js;jk=jk+ju*jd+jt*jb end end;local jv=1;local jw=0;local jx=1;if system.getMouseWheel()>0 then if AltIsOn then if j>0 or Reentry then bk=utils.clamp(bk+speedChangeLarge,0,AtmoSpeedLimit)elseif Autopilot then MaxGameVelocity=utils.clamp(MaxGameVelocity+speedChangeLarge/3.6*100,0,8333.00)end;A=false else s=round(utils.clamp(s+speedChangeLarge/100,-1,1),2)end elseif system.getMouseWheel()<0 then if AltIsOn then if j>0 or Reentry then bk=utils.clamp(bk-speedChangeLarge,0,AtmoSpeedLimit)elseif Autopilot then MaxGameVelocity=utils.clamp(MaxGameVelocity-speedChangeLarge/3.6*100,0,8333.00)end;A=false else s=round(utils.clamp(s-speedChangeLarge/100,-1,1),2)end end;t=0;local dW=-ja:dot(je)if ai and AtmoSpeedAssist and Nav.axisCommandManager:getAxisCommandType(0)==axisCommandType.byThrottle then if throttlePID==nil then throttlePID=pid.new(0.5,0,1)end;throttlePID:inject(bk/3.6-je:dot(jc))local jy=throttlePID:get()v=utils.clamp(jy,-1,1)if v0.05 or j>0.01 and dW<0)then u=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,utils.clamp(v,0.01,1))else u=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,s)end;if brakePID==nil then brakePID=pid.new(1*0.01,0,1*0.1)end;brakePID:inject(je:len()-bk/3.6)local jz=utils.clamp(brakePID:get(),0,1)if j>0 and dW<-80 or j>0.05 then t=jz end;if t>0 then if u and v==0.01 then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)end else v=utils.clamp(v,0.01,1)end;local jA=''local jB=vec3()local jC=composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical,a4*1000)jA=jA..' , '.."vertical airfoil , vertical ground "jB=jB+jC;local jD='thrust analog longitudinal 'if ExtraLongitudeTags~="none"then jD=jD..ExtraLongitudeTags end;local jE=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)local jF=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(jD,axisCommandId.longitudinal)local jG=composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral,0)jA=jA..' , '.."lateral airfoil , lateral ground "jB=jB+jG;if jB:len()>constants.epsilon then Nav:setEngineForceCommand(jA,jB,jw,'','','',jx)end;Nav:setEngineForceCommand(jD,jF,jv)local jH='thrust analog vertical fueled 'local jI='thrust analog lateral fueled 'if ExtraLateralTags~="none"then jI=jI..ExtraLateralTags end;if ExtraVerticalTags~="none"then jH=jH..ExtraVerticalTags end;if a4~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(jH,jC,jv)else Nav:setEngineForceCommand(jH,vec3(),jv)end;if LeftAmount~=0 then Nav:setEngineForceCommand(jI,jG,jv)else Nav:setEngineForceCommand(jI,vec3(),jv)end;if j9==0 then j9=t end;local jJ=-j9*(brakeSpeedFactor*je+brakeFlatFactor*jf)Nav:setEngineForceCommand('brake',jJ)else if AtmoSpeedAssist then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,s)end;local jJ=-j9*(brakeSpeedFactor*je+brakeFlatFactor*jf)Nav:setEngineForceCommand('brake',jJ)local jA=''local jB=vec3()local jK=false;local jD='thrust analog longitudinal 'if ExtraLongitudeTags~="none"then jD=jD..ExtraLongitudeTags end;local jE=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if jE==axisCommandType.byThrottle then local jF=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(jD,axisCommandId.longitudinal)Nav:setEngineForceCommand(jD,jF,jv)elseif jE==axisCommandType.byTargetSpeed then local jF=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)jA=jA..' , '..jD;jB=jB+jF;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then jK=true end end;local jI='thrust analog lateral 'if ExtraLateralTags~="none"then jI=jI..ExtraLateralTags end;local jL=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if jL==axisCommandType.byThrottle then local jM=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(jI,axisCommandId.lateral)Nav:setEngineForceCommand(jI,jM,jv)elseif jL==axisCommandType.byTargetSpeed then local jG=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)jA=jA..' , '..jI;jB=jB+jG end;local jH='thrust analog vertical 'if ExtraVerticalTags~="none"then jH=jH..ExtraVerticalTags end;local jN=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if jN==axisCommandType.byThrottle then local jC=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(jH,axisCommandId.vertical)if a4~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(jH,jC,jv,'airfoil','ground','',jx)else Nav:setEngineForceCommand(jH,vec3(),jv)Nav:setEngineForceCommand('airfoil vertical',jC,jv,'airfoil','','',jx)Nav:setEngineForceCommand('ground vertical',jC,jv,'ground','','',jx)end elseif jN==axisCommandType.byTargetSpeed then if a4<0 then Nav:setEngineForceCommand('hover',vec3(),jv)end;local jO=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)jA=jA..' , '..jH;jB=jB+jO end;local fR=unit.getAxisCommandValue(0)if jB:len()>constants.epsilon then if L~=0 or jK or math.abs(jf:dot(jc))<0.8 or ba:len()>fR/3.6 then jA=jA..', brake'end;Nav:setEngineForceCommand(jA,jB,jw,'','','',jx)end end;local jP=torqueFactor*(jk-jj)local jQ=vec3(core.getWorldAirFrictionAngularAcceleration())jP=jP-jQ;Nav:setEngineTorqueCommand('torque',jP,jv,'airfoil','','',jx)Nav:setBoosterCommand('rocket_engine')if T and not VanillaRockets then local bC=vec3(core.getVelocity()):len()local jR=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local jS=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if bC*3.6>jS*(1-jR)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bC*3.6=fR*(1-jR)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bC=fR*(1-jR)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif bC0 or ajHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+S;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+S end else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+R else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif jT=="groundaltitudedown"then OldButtonMod=R;OldAntiMod=S;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-S;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-S;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-R else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif jT=="option1"then IncrementAutopilotTargetIndex()A=false elseif jT=="option2"then DecrementAutopilotTargetIndex()A=false elseif jT=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;A=false;ToggleWidgets()elseif jT=="option4"then ToggleAutopilot()A=false elseif jT=="option5"then ToggleLockPitch()A=false elseif jT=="option6"then ToggleAltitudeHold()A=false elseif jT=="option7"then wipeSaveVariables()A=false elseif jT=="option8"then ToggleFollowMode()A=false elseif jT=="option9"then if gyro~=nil then gyro.toggle()am=gyro.getState()==1 end;A=false elseif jT=="lshift"then if system.isViewLocked()==1 then O=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif o()==1 and ShiftShowsRemoteButtons then O=true;b7=false;b6=false end elseif jT=="brake"then if BrakeToggleStatus then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif jT=="lalt"then AltIsOn=true;if o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif jT=="booster"then if VanillaRockets then Nav:toggleBoosters()elseif not T then if not IsRocketOn then Nav:toggleBoosters()IsRocketOn=true end;T=true else if IsRocketOn then Nav:toggleBoosters()IsRocketOn=false end;T=false end elseif jT=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)clearAll()s=0 elseif jT=="speedup"then if not O then if AtmoSpeedAssist and not AltIsOn then s=utils.clamp(s+speedChangeLarge/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)end else IncrementAutopilotTargetIndex()end elseif jT=="speeddown"then if not O then if AtmoSpeedAssist and not AltIsOn then s=utils.clamp(s-speedChangeLarge/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)end else DecrementAutopilotTargetIndex()end elseif jT=="antigravity"and not ExternalAGG then if antigrav~=nil then ToggleAntigrav()end end end;function script.onActionStop(jT)if jT=="forward"then G=0 elseif jT=="backward"then G=0 elseif jT=="left"then J=0 elseif jT=="right"then J=0 elseif jT=="yawright"then K=0 elseif jT=="yawleft"then K=0 elseif jT=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)LeftAmount=0 elseif jT=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)LeftAmount=0 elseif jT=="up"then a4=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif jT=="down"then a4=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif jT=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then S=OldAntiMod end;if AltitudeHold then R=OldButtonMod end;A=false elseif jT=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then S=OldAntiMod end;if AltitudeHold then R=OldButtonMod end;A=false elseif jT=="lshift"then if system.isViewLocked()==1 then O=false;a5=0;a6=0;system.lockView(PrevViewLock)elseif o()==1 and ShiftShowsRemoteButtons then O=false;b7=false;b6=false end elseif jT=="brake"then if not BrakeToggleStatus then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif jT=="lalt"then if o()==0 and freeLookToggle then if A then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else A=true end elseif o()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end;AltIsOn=false end end;function script.onActionLoop(jT)if jT=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude+S;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude+S end;S=S*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+R;R=R*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif jT=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then if AltitudeHold and AntigravTargetAltitudeHoldAltitude-10 then AntigravTargetAltitude=AntigravTargetAltitude-S;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end;HoldAltitude=AntigravTargetAltitude else AntigravTargetAltitude=AntigravTargetAltitude-S;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end end;S=S*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-R;R=R*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif jT=="speedup"then if not O then if AtmoSpeedAssist and not AltIsOn then s=utils.clamp(s+speedChangeSmall/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end end elseif jT=="speeddown"then if not O then if AtmoSpeedAssist and not AltIsOn then s=utils.clamp(s-speedChangeSmall/100,-1,1)else Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end end;function script.onInputText(dj)local i;local jU="/commands /setname /G /agg /addlocation /copydatabank"local jV,jW=nil,nil;local jX="Command List:\n/commands \n/setname - Updates current selected saved position name\n/G VariableName newValue - Updates global variable to new value\n".."/G dump - shows all updatable variables with /G\n/agg - Manually set agg target height\n".."/addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572} - adds a saved location by waypoint, not as accurate as making one at location\n".."/copydatabank - copies dbHud databank to a blank databank"i=string.find(dj," ")jV=dj;if i~=nil then jV=string.sub(dj,0,i-1)jW=string.sub(dj,i+1)elseif not string.find(jU,jV)then for fN in string.gmatch(jX,"([^\n]+)")do c(fN)end;return end;if jV=="/setname"then if jW==nil or jW==""then P="Usage: /setname Newname"return end;if AutopilotTargetIndex>0 and CustomTarget~=nil then UpdatePosition(jW)else P="Select a saved target to rename first"end elseif jV=="/addlocation"then if jW==nil or jW==""or string.find(jW,"::")==nil then P="Usage: /addlocation savename ::pos{0,2,46.4596,-155.1799,22.6572}"return end;i=string.find(jW,"::")local c6=string.sub(jW,1,i-2)local c0=string.sub(jW,i)local p=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local c1='::pos{'..p..','..p..','..p..','..p..','..p..'}'local c2,c3,bY,bZ,bX=string.match(c0,c1)local planet=aX[tonumber(c2)][tonumber(c3)]AddNewLocationByWaypoint(c6,planet,c0)P="Added "..c6 .." to saved locations,\nplanet "..planet.name.." at "..c0;a7=5 elseif jV=="/agg"then if jW==nil or jW==""then P="Usage: /agg targetheight"return end;jW=tonumber(jW)if jW<1000 then jW=1000 end;AntigravTargetAltitude=jW;P="AGG Target Height set to "..jW elseif jV=="/G"then if jW==nil or jW==""then P="Usage: /G VariableName variablevalue\n/G dump - shows all variables"return end;if jW=="dump"then for bm,bn in pairs(a)do if type(_G[bn])=="boolean"then if _G[bn]==true then c(bn.." true")else c(bn.." false")end elseif _G[bn]==nil then c(bn.." nil")else c(bn.." ".._G[bn])end end;return end;i=string.find(jW," ")local jY=string.sub(jW,0,i-1)local jZ=string.sub(jW,i+1)for bm,bn in pairs(a)do if bn==jY then P="Variable "..jY.." changed to "..jZ;local j_=type(_G[bn])if j_=="number"then jZ=tonumber(jZ)elseif j_=="boolean"then if string.lower(jZ)=="true"then jZ=true else jZ=false end end;_G[bn]=jZ;return end end;P="No such global variable: "..jY elseif jV=="/copydatabank"then if dbHud_2 then SaveDataBank(true)else P="Databank required to copy databank"end end end;script.onStart() -- error handling code added by wrap.lua diff --git a/ChangeLog.md b/ChangeLog.md index 0f06765..a4353e2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,19 @@ ## ChangeLog - Most recent changes at the top +Version 5.32 - Fix VTOL performance. +- Strengthened convergence of velocity vector to ship forward in atmosphere +- Fixed issue allowing 'Finalizing Approach' to occur when the ship was not on target yet +- Fixed erratic yaw behavior while rolling in atmosphere +- User Parameter: ForceAlignment = false --export: (Default: false) Whether velocity vector alignment should be forced when in Altitude Hold + +Version 5.31 +- Improved autopilot trajectory alignment weirdness that happened sometimes +- Added ForceAlignment parameter to return to old AltitudeHold behavior of forcing the ship to face the velocity vector +- Fixed cruise not swapping to throttled mode during reentry without a target +- Fixed vertical/lateral engines firing against gravity at all times +- 'Proceeding to Waypoint' only engages after reentry if you are at least 2km horizontally from the target, to give space to turn +- Fixed atmospheric exit waypoints from being unable to use pitch properly when rolling in atmosphere + Version 5.300 - Surface-To-Surface Overhaul - Throttle Cruise system complete - Alt+Mousewheel changes max speed in atmosphere, with a maximum of AtmoSpeedLimit (user parameter) diff --git a/src/ButtonHUD.lua b/src/ButtonHUD.lua index 4119280..d185a82 100644 --- a/src/ButtonHUD.lua +++ b/src/ButtonHUD.lua @@ -86,6 +86,7 @@ ShouldCheckDamage = true --export: (Default: true) Whether or not damage checks CalculateBrakeLandingSpeed = false --export: (Default: false) Whether BrakeLanding speed at non-waypoints should be calculated or use the brakeLandingRate user setting. Only set to true for ships with low mass to lift capability. autoRollRollThreshold = 0 --export: (Default: 0) The minimum amount of roll before autoRoll kicks in and stabilizes (if active) AtmoSpeedAssist = true --export: (Default: true) Whether or not atmospheric speeds should be limited to a maximum of AtmoSpeedLimit +ForceAlignment = false --export: (Default: false) Whether velocity vector alignment should be forced when in Altitude Hold -- Auto Variable declarations that store status of ship. Must be global because they get saved/read to Databank due to using _G assignment BrakeToggleStatus = BrakeToggleDefault @@ -136,7 +137,8 @@ local saveableVariables = {"userControlScheme", "TargetOrbitRadius", "apTickRate "ReentrySpeed", "AtmoSpeedLimit", "ReentryAltitude", "centerX", "centerY", "SpaceSpeedLimit", "AtmoSpeedAssist", "vSpdMeterX", "vSpdMeterY", "altMeterX", "altMeterY", "fuelX","fuelY", "LandingGearGroundHeight", "TrajectoryAlignmentStrength", "RemoteHud", "YawStallAngle", "PitchStallAngle", "ResolutionX", "ResolutionY", "UseSatNav", "FuelTankOptimization", "ContainerOptimization", - "ExtraLongitudeTags", "ExtraLateralTags", "ExtraVerticalTags", "OrbitMapSize", "OrbitMapX", "OrbitMapY", "DisplayOrbit", "CalculateBrakeLandingSpeed"} + "ExtraLongitudeTags", "ExtraLateralTags", "ExtraVerticalTags", "OrbitMapSize", "OrbitMapX", "OrbitMapY", "DisplayOrbit", "CalculateBrakeLandingSpeed", + "ForceAlignment"} local autoVariables = {"SpaceTarget","BrakeToggleStatus", "BrakeIsOn", "RetrogradeIsOn", "ProgradeIsOn", "Autopilot", "TurnBurn", "AltitudeHold", "BrakeLanding", @@ -1363,6 +1365,8 @@ end local atan = math.atan local function signedRotationAngle(normal, vecA, vecB) + vecA = vecA:project_on_plane(normal) + vecB = vecB:project_on_plane(normal) return atan(vecA:cross(vecB):dot(normal), vecA:dot(vecB)) end @@ -3417,8 +3421,8 @@ function composeAxisAccelerationFromTargetSpeed(commandAxis, targetSpeed) local targetAxisSpeedMS = targetSpeed * constants.kph2m - if targetSpeedPID == nil then - targetSpeedPID = pid.new(1, 0, 10.0) -- The PID used to compute acceleration to reach target speed + if targetSpeedPID == nil then -- CHanged first param from 1 to 10... + targetSpeedPID = pid.new(10, 0, 10.0) -- The PID used to compute acceleration to reach target speed end targetSpeedPID:inject(targetAxisSpeedMS - currentAxisSpeedMS) -- update PID @@ -3427,9 +3431,9 @@ function composeAxisAccelerationFromTargetSpeed(commandAxis, targetSpeed) local finalAcceleration = (accelerationCommand - airResistanceAccelerationCommand - gravityAccelerationCommand) * axisWorldDirection -- Try to compensate air friction - -- The hell are these? - --self.system.addMeasure("dynamic", "acceleration", "command", accelerationCommand) - --self.system.addMeasure("dynamic", "acceleration", "intensity", finalAcceleration:len()) + -- The hell are these? Uncommented recently just in case they were important + system.addMeasure("dynamic", "acceleration", "command", accelerationCommand) + system.addMeasure("dynamic", "acceleration", "intensity", finalAcceleration:len()) return finalAcceleration end @@ -5297,7 +5301,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 = 5.300 + VERSION_NUMBER = 5.320 SetupComplete = false beginSetup = coroutine.create(function() Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal, @@ -5404,6 +5408,15 @@ end function script.onTick(timerId) if timerId == "tenthSecond" then + if atmosphere() > 0 and not WasInAtmo then + if Nav.axisCommandManager:getAxisCommandType(0) == axisCommandType.byTargetSpeed and AtmoSpeedAssist and (AltitudeHold or Reentry) then + -- If they're reentering atmo from cruise, and have atmo speed Assist + -- Put them in throttle mode at 100% + PlayerThrottle = 1 + Nav.control.cancelCurrentControlMasterMode() + WasInCruise = false -- And override the thing that would reset it, in this case + end + end if AutopilotTargetName ~= "None" then if panelInterplanetary == nil then SetupInterplanetaryPanel() @@ -5453,16 +5466,6 @@ function script.onTick(timerId) system.removeDataFromWidget(widgetCurBrakeDistanceText, widgetCurBrakeDistance) system.removeDataFromWidget(widgetTrajectoryAltitudeText, widgetTrajectoryAltitude) WasInAtmo = true - if Nav.axisCommandManager:getAxisCommandType(0) == axisCommandType.byThrottle then - -- Put real throttle into PlayerThrottle as we enter - --PlayerThrottle = unit.getAxisCommandValue(0) - elseif AtmoSpeedAssist then - -- If they're reentering atmo from cruise, and have atmo speed Assist - -- Put them in throttle mode at 100% - PlayerThrottle = 1 - Nav.control.cancelCurrentControlMasterMode() - WasInCruise = false -- And override the thing that would reset it, in this case - end end if atmosphere() == 0 and WasInAtmo then if system.updateData(widgetMaxBrakeTimeText, widgetMaxBrakeTime) == 1 then @@ -5861,7 +5864,8 @@ function script.onTick(timerId) end local up = vec3(core.getWorldVertical()) * -1 local vSpd = (velocity.x * up.x) + (velocity.y * up.y) + (velocity.z * up.z) - if finalLand and (coreAltitude < (HoldAltitude + 200) and coreAltitude > (HoldAltitude - 200)) and ((velMag*3.6) > (adjustedAtmoSpeedLimit-100)) and math.abs(vSpd) < 20 and atmosphere() >= 0.1 then + if finalLand and (coreAltitude < (HoldAltitude + 200) and coreAltitude > (HoldAltitude - 200)) and ((velMag*3.6) > (adjustedAtmoSpeedLimit-100)) and math.abs(vSpd) < 20 and atmosphere() >= 0.1 + and (CustomTarget.position-worldPos):len() > 2000 + coreAltitude then -- Only engage if far enough away to be able to turn back for it ToggleAutopilot() finalLand = false end @@ -6373,11 +6377,11 @@ function script.onTick(timerId) autoRoll = autoRollPreference end elseif planet.noAtmosphericDensityAltitude > 0 and coreAltitude > planet.noAtmosphericDensityAltitude + 5000 then -- 5km is good - if Nav.axisCommandManager:getAxisCommandType(0) == axisCommandType.byTargetSpeed then - targetPitch = -70 -- Maybe -70 will do better, something is keeping it from pitching up at the right time... - else - targetPitch = -MaxPitch - end + --if Nav.axisCommandManager:getAxisCommandType(0) == axisCommandType.byTargetSpeed then + -- targetPitch = -70 -- Maybe -70 will do better, something is keeping it from pitching up at the right time... + --else + -- targetPitch = -MaxPitch + --end autoRoll = true -- It shouldn't actually do it, except while aligning elseif coreAltitude <= planet.noAtmosphericDensityAltitude + 5000 then if Nav.axisCommandManager:getAxisCommandType(0) == axisCommandType.byThrottle then -- Cancel throttle @@ -6387,7 +6391,7 @@ function script.onTick(timerId) Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral, 0) end -- Then we have to wait a tick for it to take our new speed. if Nav.axisCommandManager:getAxisCommandType(0) == axisCommandType.byTargetSpeed and Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal) == adjustedAtmoSpeedLimit then - targetPitch = -MaxPitch + --targetPitch = -MaxPitch -- It will handle pitching for us after this. reentryMode = false Reentry = false autoRoll = true -- wtf? On some ships this makes it flail around because of the -80 and never recover @@ -6401,9 +6405,9 @@ function script.onTick(timerId) -- Align it prograde but keep whatever pitch inputs they gave us before, and ignore pitch input from alignment. -- So, you know, just yaw. - --if velMag > minAutopilotSpeed and not spaceLaunch and not VectorToTarget and not BrakeLanding then -- When do we even need this, just alt hold? lol - -- AlignToWorldVector(vec3(velocity)) - --end + if velMag > minAutopilotSpeed and not spaceLaunch and not VectorToTarget and not BrakeLanding and ForceAlignment then -- When do we even need this, just alt hold? lol + AlignToWorldVector(vec3(velocity)) + end if (VectorToTarget or spaceLaunch) and AutopilotTargetIndex > 0 and atmosphere() > 0.01 then local targetVec if CustomTarget ~= nil then @@ -6427,7 +6431,7 @@ function script.onTick(timerId) -- And is wrong? --local targetYaw = math.deg(math.atan(flatForward.y-vectorInYawDirection.y, flatForward.x-vectorInYawDirection.x)) -- These projections save it from bugging out at weird angles. - local targetYaw = math.deg(signedRotationAngle(worldV:normalize(),velocity:project_on_plane(worldV),targetVec:project_on_plane(worldV)))*2 + local targetYaw = math.deg(signedRotationAngle(worldV:normalize(),velocity,targetVec))*2 --local targetYaw = math.deg(math.acos((vectorInYawDirection:dot(flatForward)))) * -utils.sign(targetVec:dot(velocity:cross(worldV)))*2 --system.print(math.abs(worldV:dot(targetVec:normalize()))) -- or math.abs(targetYaw) > 350 @@ -6439,16 +6443,15 @@ function script.onTick(timerId) -- We can try it with roll... local rollRad = math.rad(math.abs(roll)) if velMag > minRollVelocity and atmosphere() > 0.01 then - local maxRoll = utils.clamp(90-targetPitch,60,90) -- No downwards roll allowed :( - targetRoll = utils.clamp(targetYaw, -maxRoll, maxRoll) + local maxRoll = utils.clamp(90-targetPitch*2,-90,90) -- No downwards roll allowed? :( + targetRoll = utils.clamp(targetYaw*2, -maxRoll, maxRoll) local origTargetYaw = targetYaw - -- I have no fucking clue why we add currentYaw to StallAngle when currentYaw is already potentially a large value outside of the velocity vector - -- But it doesn't work otherwise and stalls if we don't do it like that. I don't fucking know. - targetYaw = utils.clamp(utils.clamp((currentYaw-targetYaw)*math.cos(rollRad),currentYaw-YawStallAngle*0.85,currentYaw+YawStallAngle*0.85) + utils.clamp((targetPitch-adjustedPitch)*math.sin(math.rad(roll)),-YawStallAngle*0.85,YawStallAngle*0.85),currentYaw-YawStallAngle*0.85,currentYaw+YawStallAngle*0.85) -- Try signing the pitch component of this + -- 4x weight to pitch consideration because yaw is often very weak compared and the pid needs help? + targetYaw = utils.clamp(utils.clamp(targetYaw,-YawStallAngle*0.85,YawStallAngle*0.85)*math.cos(rollRad) + 4*(adjustedPitch-targetPitch)*math.sin(math.rad(roll)),-YawStallAngle*0.85,YawStallAngle*0.85) -- We don't want any yaw if we're rolled targetPitch = utils.clamp(utils.clamp(targetPitch*math.cos(rollRad),-PitchStallAngle*0.85,PitchStallAngle*0.85) + math.abs(utils.clamp(math.abs(origTargetYaw)*math.sin(rollRad),-PitchStallAngle*0.85,PitchStallAngle*0.85)),-PitchStallAngle*0.85,PitchStallAngle*0.85) -- Always yaw positive else targetRoll = 0 - targetYaw = utils.clamp((currentYaw-targetYaw),-90,90) + targetYaw = utils.clamp(targetYaw,-90,90) end-- We're just taking abs of the yaw for pitch, because we just want to pull up, and it rolled the right way already. -- And the pitch now gets info about yaw too? -- cos(roll) should give 0 at 90 and 1/-1 at 0 and 180 @@ -6458,7 +6461,7 @@ function script.onTick(timerId) -- and pitch would be targetPitch*cos(roll) - targetYaw*sin(roll) cuz yaw and pitch are reversed from eachother - local yawDiff = targetYaw + local yawDiff = currentYaw-targetYaw if not stalling and velMag > minRollVelocity and atmosphere() > 0.01 then if (yawPID == nil) then @@ -6523,7 +6526,7 @@ function script.onTick(timerId) StrongBrakes = true -- We don't care about this or glide landing anymore and idk where all it gets used -- Fudge it with the distance we'll travel in a tick - or half that and the next tick accounts for the other? idk - if not spaceLaunch and distanceToTarget <= brakeDistance + (velMag*deltaTick)/2 and velocity:project_on_plane(worldV):dot(targetVec:project_on_plane(worldV)) > 0.99 then + if not spaceLaunch and distanceToTarget <= brakeDistance + (velMag*deltaTick)/2 and (velocity:project_on_plane(worldV):normalize():dot(targetVec:project_on_plane(worldV):normalize()) > 0.99 or VectorStatus == "Finalizing Approach") then VectorStatus = "Finalizing Approach" if Nav.axisCommandManager:getAxisCommandType(0) == axisCommandType.byTargetSpeed then Nav.control.cancelCurrentControlMasterMode() @@ -6729,7 +6732,7 @@ function script.onTick(timerId) local onGround = hoverDetectGround() > -1 local pitchToUse = pitch - if VectorToTarget and not onGround and velMag > minRollVelocity and atmosphere() > 0.01 then + if (VectorToTarget or spaceLaunch) and not onGround and velMag > minRollVelocity and atmosphere() > 0.01 then local rollRad = math.rad(math.abs(roll)) pitchToUse = pitch*math.abs(math.cos(rollRad))+currentPitch*math.sin(rollRad) --pitchToUse = adjustedPitch -- Use velocity vector pitch instead, we're potentially sideways @@ -6986,14 +6989,10 @@ function script.onFlush() local autoNavigationEngineTags = '' local autoNavigationAcceleration = vec3() - local verticalStrafeEngineTags = 'thrust analog vertical ' - local lateralStrafeEngineTags = 'thrust analog lateral ' - - if ExtraLateralTags ~= "none" then lateralStrafeEngineTags = lateralStrafeEngineTags..ExtraLateralTags end - if ExtraVerticalTags ~= "none" then verticalStrafeEngineTags = verticalStrafeEngineTags..ExtraVerticalTags end + local verticalStrafeAcceleration = composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical,upAmount*1000) - autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. verticalStrafeEngineTags + autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. "vertical airfoil , vertical ground " autoNavigationAcceleration = autoNavigationAcceleration + verticalStrafeAcceleration local longitudinalEngineTags = 'thrust analog longitudinal ' @@ -7003,7 +7002,7 @@ function script.onFlush() longitudinalEngineTags, axisCommandId.longitudinal) local lateralAcceleration = composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral, 0) - autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. lateralStrafeEngineTags + autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. "lateral airfoil , lateral ground " -- We handle the rest later autoNavigationAcceleration = autoNavigationAcceleration + lateralAcceleration -- Auto Navigation (Cruise Control) @@ -7014,6 +7013,25 @@ function script.onFlush() -- And let throttle do its thing separately Nav:setEngineForceCommand(longitudinalEngineTags, longitudinalAcceleration, keepCollinearity) + local verticalStrafeEngineTags = 'thrust analog vertical fueled ' + local lateralStrafeEngineTags = 'thrust analog lateral fueled ' + + if ExtraLateralTags ~= "none" then lateralStrafeEngineTags = lateralStrafeEngineTags..ExtraLateralTags end + if ExtraVerticalTags ~= "none" then verticalStrafeEngineTags = verticalStrafeEngineTags..ExtraVerticalTags end + + -- Vertical also handles the non-airfoils separately + if upAmount ~= 0 or (BrakeLanding and BrakeIsOn) then + Nav:setEngineForceCommand(verticalStrafeEngineTags, verticalStrafeAcceleration, keepCollinearity) + else + Nav:setEngineForceCommand(verticalStrafeEngineTags, vec3(), keepCollinearity) -- Reset vertical engines but not airfoils or ground + end + + if LeftAmount ~= 0 then + Nav:setEngineForceCommand(lateralStrafeEngineTags, lateralAcceleration, keepCollinearity) + else + Nav:setEngineForceCommand(lateralStrafeEngineTags, vec3(), keepCollinearity) -- Reset vertical engines but not airfoils or ground + end + if finalBrakeInput == 0 then -- If player isn't braking, use cruise assist braking finalBrakeInput = brakeInput2 end @@ -7237,8 +7255,10 @@ function script.onActionStart(action) yawInput = yawInput + 1 elseif action == "straferight" then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral, 1.0) + LeftAmount = 1 elseif action == "strafeleft" then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral, -1.0) + LeftAmount = -1 elseif action == "up" then upAmount = upAmount + 1 Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization() @@ -7411,8 +7431,10 @@ function script.onActionStop(action) yawInput = 0 elseif action == "straferight" then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral, -1.0) + LeftAmount = 0 elseif action == "strafeleft" then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral, 1.0) + LeftAmount = 0 elseif action == "up" then upAmount = 0 Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical, -1.0)