From 4301cb4d472c22a2856e382dc10c598d53756b52 Mon Sep 17 00:00:00 2001 From: archaegeo Date: Wed, 16 Dec 2020 10:53:39 -0500 Subject: [PATCH] Fixed for fuel tank, restore emergency warp --- ButtonHUD.conf | 10 ++-- ChangeLog.md | 4 ++ src/ButtonHUD.lua | 116 +++++++++++++++++++++++++++++++++++++--------- 3 files changed, 103 insertions(+), 27 deletions(-) diff --git a/ButtonHUD.conf b/ButtonHUD.conf index 6f58d0d..1cfc23e 100644 --- a/ButtonHUD.conf +++ b/ButtonHUD.conf @@ -1,4 +1,4 @@ -name: ButtonsHud - Dimencia and Archaegeo v4.851 (Minified) +name: ButtonsHud - Dimencia and Archaegeo v4.852 (Minified) slots: core: class: CoreUnit @@ -132,6 +132,8 @@ handlers: MaxPitch = 30 --export: Maximum allowed pitch during takeoff and altitude changes while in altitude hold. Default is 20 deg. You can set higher or lower depending on your ships capabilities. ReentrySpeed = 1050 --export: Target re-entry speed once in atmosphere in m/s. 291 = 1050 km/hr, higher might cause reentry burn. ReentryAltitude = 2500 --export: Target alititude when using re-entry. + EmergencyWarpDistance = 320000 --export: Set to distance as which an emergency warp will occur if radar target within that distance. 320000 is lock range for large radar on large ship no special skills. + IgnoreEmergencyWarpDistance = 500 --export: Any targets within this distance are ignored for emergency warp. AutoTakeoffAltitude = 1000 --export: How high above your ground starting position AutoTakeoff tries to put you TargetHoverHeight = 50 --export: Hover height when retracting landing gear LandingGearGroundHeight = 0 --export: Set to hover height reported - 1 when you use alt-spacebar to just lift off ground from landed postion. 4 is M size landing gear, @@ -157,10 +159,10 @@ handlers: fuelTankHandlingRocket = 0 --export: For accurate estimates, set this to the fuel tank handling level of the person who placed the element. Ignored for slotted tanks. ExternalAGG = false --export: Toggle On if using an external AGG system. If on will prevent this HUD from doing anything with AGG. apTickRate = 0.0166667 --export: Set the Tick Rate for your HUD. 0.016667 is effectively 60 fps and the default value. 0.03333333 is 30 fps. The bigger the number the less often the autopilot and hud updates but may help peformance on slower machings. - Nav=Navigator.new(system,core,unit)script={}local a=system.print;local b=math.floor;local c=string.format;local d=json.decode;local e=json.encode;local f=core.getElementMaxHitPointsById;local g=unit.getAtmosphereDensity;local h=core.getElementHitPointsById;local j=core.getElementTypeById;local k=core.getElementMassById;local l=core.getConstructMass;local m=Nav.control.isRemoteControlled;function script.onStart()VERSION_NUMBER=4.851;SetupComplete=false;beginSetup=coroutine.create(function()Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal,{1000,5000,10000,20000,30000})InAtmo=g()>0;APThrottleSet=false;ToggleView=true;MinAutopilotSpeed=55;LastMaxBrake=0;LastMaxBrakeInAtmo=0;ReentryMode=false;MousePitchFactor=1;MouseYawFactor=1;HasGear=false;PitchInput=0;PitchInput2=0;YawInput2=0;RollInput=0;YawInput=0;BrakeInput=0;RollInput2=0;RetrogradeIsOn=false;ProgradeIsOn=false;Reentry=false;FollowMode=false;TurnBurn=false;AutopilotAccelerating=false;AutopilotRealigned=false;HoldingCtrl=false;PrevViewLock=1;MsgText="empty"LastEccentricity=1;HoldAltitudeButtonModifier=5;AntiGravButtonModifier=5;IsBoosting=false;BrakeDistance,BrakeTime=0;MaxBrakeDistance,MaxBrakeTime=0;HasSpaceRadar=false;HasAtmoRadar=false;AutopilotTargetIndex=0;AutopilotTargetName="None"AutopilotTargetPlanet=nil;TotalDistanceTravelled=0.0;TotalDistanceTrip=0;FlightTime=0;WipedDatabank=false;LocationIndex=0;UpAmount=0;BrakeIsOn=false;Autopilot=false;AltitudeHold=false;BrakeLanding=false;AutoTakeoff=false;HoldAltitude=1000;AutopilotBraking=false;AutopilotCruising=false;VectorToTarget=false;SimulatedX=0;SimulatedY=0;AutopilotStatus="Aligning"MsgTimer=3;TargetGroundAltitude=nil;GearExtended=nil;Distance=0;RadarMessage=""LastOdometerOutput=""Peris=0;CoreAltitude=core.getAltitude()AntigravTargetAltitude=CoreAltitude;ElementsID=core.getElementIdList()LastTravelTime=system.getTime()TotalFlightTime=0;HasGear=false;AutopilotPlanetGravity=0;DisplayOrbit=true;AutopilotEndSpeed=0;SavedLocations={}LandingGearGroundHeight=0;SpaceLand=false;SpaceLaunch=false;FinalLand=false;HovGndDet=-1;clearAllCheck=false;LockPitch=nil;LastStartTime=0;local n={}local o=0;local p=0;local q=""local r=true;local s={}local t=1;local u=0.001;local v=2560;local w=1440;local x=nil;local y=nil;local z=nil;local A=nil;local B=false;local C=false;local D=0;local E=nil;local F={}local G={}local H={}local I=0;local J=false;local K={}local L={}local M=b(1/apTickRate)*2;local N={}local O={}local P={}local Q={}local R=false;local S=16;local T=0;SaveableVariables={"userControlScheme","AutopilotTargetOrbit","apTickRate","freeLookToggle","turnAssist","PrimaryR","PrimaryG","PrimaryB","warmup","DeadZone","circleRad","MouseXSensitivity","MouseYSensitivity","MaxGameVelocity","showHud","autoRollPreference","pitchSpeedFactor","yawSpeedFactor","rollSpeedFactor","brakeSpeedFactor","brakeFlatFactor","autoRollFactor","turnAssistFactor","torqueFactor","AutoTakeoffAltitude","TargetHoverHeight","AutopilotInterplanetaryThrottle","hideHudOnToggleWidgets","DampingMultiplier","fuelTankHandlingAtmo","fuelTankHandlingSpace","fuelTankHandlingRocket","RemoteFreeze","speedChangeLarge","speedChangeSmall","brightHud","brakeLandingRate","MaxPitch","ReentrySpeed","ReentryAltitude","centerX","centerY","vSpdMeterX","vSpdMeterY","altMeterX","altMeterY","fuelX","fuelY","LandingGearGroundHeight","TrajectoryAlignmentStrength","RemoteHud","StallAngle","ResolutionX","ResolutionY"}AutoVariables={"brakeToggle","BrakeIsOn","RetrogradeIsOn","ProgradeIsOn","Autopilot","TurnBurn","AltitudeHold","DisplayOrbit","BrakeLanding","Reentry","AutoTakeoff","HoldAltitude","AutopilotAccelerating","AutopilotBraking","AutopilotCruising","AutopilotRealigned","AutopilotEndSpeed","AutopilotStatus","AutopilotPlanetGravity","PrevViewLock","AutopilotTargetName","AutopilotTargetCoords","AutopilotTargetIndex","GearExtended","TargetGroundAltitude","TotalDistanceTravelled","TotalFlightTime","SavedLocations","VectorToTarget","LocationIndex","LastMaxBrake","LockPitch","LastMaxBrakeInAtmo","AntigravTargetAltitude","LastStartTime"}if dbHud then local U=dbHud.hasKey;if not useTheseSettings then for V,W in pairs(SaveableVariables)do if U(W)then local X=d(dbHud.getStringValue(W))if X~=nil then a(W.." "..dbHud.getStringValue(W))_G[W]=X;B=true end end end end;for V,W in pairs(AutoVariables)do if U(W)then local X=d(dbHud.getStringValue(W))if X~=nil then a(W.." "..dbHud.getStringValue(W))_G[W]=X;B=true end end end;if useTheseSettings then MsgText="Updated user preferences used. Will be saved when you exit seat. Toggle off useTheseSettings to use saved values"elseif B then MsgText="Loaded Saved Variables (see Lua Chat Tab for list)"else MsgText="No Saved Variables Found - Stand up / leave remote to save settings"end else MsgText="No databank found, install one anywhere and rerun the autoconfigure to save variables"end;coroutine.yield()local Y=system.getTime()if LastStartTime+18010000 then S=128 elseif a0>1000 then S=64 elseif a0>150 then S=32 end end;I=I+f(ElementsID[V])if fuelX~=0 and fuelY~=0 then if type=="Atmospheric fuel tank"or type=="Space fuel tank"or type=="Rocket fuel tank"then local a0=f(ElementsID[V])local a1=k(ElementsID[V])local a2=0;local a3=system.getTime()if type=="Atmospheric fuel tank"then local a4=400;local a5=35.03;if a0>10000 then a4=51200;a5=5480 elseif a0>1300 then a4=6400;a5=988.67 elseif a0>150 then a4=1600;a5=182.67 end;a2=a1-a5;if fuelTankHandlingAtmo>0 then a4=a4+a4*fuelTankHandlingAtmo*0.2 end;if a2>a4 then a4=a2 end;F[#F+1]={ElementsID[V],core.getElementNameById(ElementsID[V]),a4,a5,a2,a3}end;if type=="Rocket fuel tank"then local a4=320;local a5=173.42;if a0>65000 then a4=40000;a5=25740 elseif a0>6000 then a4=5120;a5=4720 elseif a0>700 then a4=640;a5=886.72 end;a2=a1-a5;if fuelTankHandlingRocket>0 then a4=a4+a4*fuelTankHandlingRocket*0.2 end;if a2>a4 then a4=a2 end;H[#H+1]={ElementsID[V],core.getElementNameById(ElementsID[V]),a4,a5,a2,a3}end;if type=="Space fuel tank"then local a4=2400;local a5=182.67;if a0>10000 then a4=76800;a5=5480 elseif a0>1300 then a4=9600;a5=988.67 end;a2=a1-a5;if fuelTankHandlingSpace>0 then a4=a4+a4*fuelTankHandlingSpace*0.2 end;if a2>a4 then a4=a2 end;G[#G+1]={ElementsID[V],core.getElementNameById(ElementsID[V]),a4,a5,a2,a3}end end end end;coroutine.yield()if gyro~=nil then GyroIsOn=gyro.getState()==1 end;if userControlScheme~="keyboard"then system.lockView(1)else system.lockView(0)end;if InAtmo then BrakeIsOn=true end;if radar_1 then if j(radar_1.getId())=="Space Radar"then HasSpaceRadar=true else HasAtmoRadar=true end end;if door then for _,W in pairs(door)do W.toggle()end end;if switch then for _,W in pairs(switch)do W.toggle()end end;if forcefield then for _,W in pairs(forcefield)do W.toggle()end end;if antigrav~=nil and not ExternalAGG then if antigrav.getState()==1 then antigrav.show()end end;if m()==1 and RemoteFreeze then system.freeze(1)else system.freeze(0)end;if HasGear then GearExtended=Nav.control.isAnyLandingGearExtended()==1;if GearExtended then Nav.control.extendLandingGears()else Nav.control.retractLandingGears()end end;if TargetGroundAltitude~=nil then Nav.axisCommandManager:setTargetGroundAltitude(TargetGroundAltitude)if TargetGroundAltitude==0 and not HasGear then GearExtended=true end else if GearExtended or not HasGear then Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)GearExtended=true else Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end end;if InAtmo and not dbHud and(GearExtended or not HasGear)then BrakeIsOn=true end;WasInAtmo=InAtmo;unit.hide()function refreshLastMaxBrake(a6,a7)if a6==nil then a6=core.g()end;a6=round(a6,5)local a8=g()if a7~=nil and a7 or(E==nil or E~=a6)then local velocity=core.getVelocity()local a9=vec3(velocity):len()local aa=d(unit.getData()).maxBrake;if aa~=nil and aa>0 and InAtmo then aa=aa/utils.clamp(a9/100,0.1,1)aa=aa/a8;if aa>LastMaxBrakeInAtmo and a8>0.10 then LastMaxBrakeInAtmo=aa end end;if aa~=nil and aa>0 then LastMaxBrake=aa end;E=a6 end end;function MakeButton(ab,ac,ad,ae,af,ag,ah,ai,aj)local ak={enableName=ab,disableName=ac,width=ad,height=ae,x=af,y=ag,toggleVar=ah,toggleFunction=ai,drawCondition=aj,hovered=false}table.insert(s,ak)return ak end;function UpdateAtlasLocationsList()AtlasOrdered={}for V,W in pairs(atlas[0])do table.insert(AtlasOrdered,{name=W.name,index=V})end;local function al(am,an)return am.name-1 then atlas[0][ar]=aq end;UpdateAtlasLocationsList()MsgText=CustomTarget.name.." position updated"end end;function ClearCurrentPosition()local ar=-1;for V,W in pairs(atlas[0])do if W.name and W.name==CustomTarget.name then ar=V end end;if ar>-1 then table.remove(atlas[0],ar)end;ar=-1;for V,W in pairs(SavedLocations)do if W.name and W.name==CustomTarget.name then MsgText=W.name.." saved location cleared"ar=V;break end end;if ar~=-1 then table.remove(SavedLocations,ar)end;DecrementAutopilotTargetIndex()UpdateAtlasLocationsList()end;function DrawDeadZone(as)as[#as+1]=c([[]],DeadZone)end;function ToggleRadarPanel()if radarPanelID~=nil and Peris==0 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;if perisPanelID~=nil then system.destroyWidgetPanel(perisPanelID)perisPanelID=nil end else if Peris==1 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;_autoconf.displayCategoryPanel(radar,radar_size,L_TEXT("ui_lua_widget_periscope", "Periscope"),"periscope")perisPanelID=_autoconf.panels[_autoconf.panels_size]end;placeRadar=true;if radarPanelID==nil and placeRadar then _autoconf.displayCategoryPanel(radar,radar_size,L_TEXT("ui_lua_widget_radar", "Radar"),"radar")radarPanelID=_autoconf.panels[_autoconf.panels_size]placeRadar=false end;Peris=0 end end;function ToggleWidgets()if r 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;r=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;r=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 InAtmo then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;widgetCurBrakeTime=system.createWidget(panelInterplanetary,"value")widgetCurBrakeTimeText=system.createData('{"label": "Cur Brake Time", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;widgetMaxBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeDistanceText=system.createData('{"label": "Max Brake Distance", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;widgetMaxBrakeTime=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeTimeText=system.createData('{"label": "Max Brake Time", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;widgetTrajectoryAltitude=system.createWidget(panelInterplanetary,"value")widgetTrajectoryAltitudeText=system.createData('{"label": "Projected Altitude", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;function Contains(at,au,af,ag,ad,ae)if at>af and atag and auMinAutopilotSpeed then MsgText="WARNING: Insufficient Brakes - Attempting coast landing, beware obstacles"end;AltitudeHold=false;AutoTakeoff=false;LockPitch=nil;BrakeLanding=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)end end;function ToggleAutoTakeoff()if AutoTakeoff then AutoTakeoff=false;if AltitudeHold then ToggleAltitudeHold()end else if not AltitudeHold then ToggleAltitudeHold()end;AutoTakeoff=true;HoldAltitude=CoreAltitude+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end end;function ToggleLockPitch()if LockPitch==nil then local av=vec3(core.getConstructWorldOrientationForward())local aw=vec3(core.getConstructWorldOrientationRight())local ax=vec3(core.getWorldVertical())local ay=getPitch(ax,av,aw)LockPitch=ay;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=false else LockPitch=nil end end;function ToggleAltitudeHold()AltitudeHold=not AltitudeHold;if AltitudeHold then Autopilot=false;ProgradeIsOn=false;RetrogradeIsOn=false;FollowMode=false;BrakeLanding=false;Reentry=false;autoRoll=true;LockPitch=nil;if not GearExtended and not BrakeIsOn or not InAtmo then AutoTakeoff=false;HoldAltitude=CoreAltitude;if not SpaceLaunch and Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end else AutoTakeoff=true;HoldAltitude=CoreAltitude+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end;if SpaceLaunch then HoldAltitude=100000 end else autoRoll=autoRollPreference;AutoTakeoff=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;VectorToTarget=false end end;function ToggleFollowMode()if m()==1 then FollowMode=not FollowMode;if FollowMode then Autopilot=false;RetrogradeIsOn=false;ProgradeIsOn=false;AltitudeHold=false;Reentry=false;BrakeLanding=false;AutoTakeoff=false;OldGearExtended=GearExtended;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)else BrakeIsOn=true;autoRoll=autoRollPreference;GearExtended=OldGearExtended;if GearExtended then Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end end else MsgText="Follow Mode only works with Remote controller"FollowMode=false end end;function ToggleAutopilot()if AutopilotTargetIndex>0 and not Autopilot and not VectorToTarget then if CustomTarget~=nil then LockPitch=nil;if planet.name==CustomTarget.planetname then StrongBrakes=planet.gravity*9.80665*l()MinAutopilotSpeed then MsgText="Insufficient Brake Force\nCoast landing will be inaccurate"end;if g()>0 then if not AltitudeHold then if not VectorToTarget then ToggleVectorToTarget()end else if not VectorToTarget then ToggleVectorToTarget()end end else SpaceLand=true end else SpaceLaunch=true;RetrogradeIsOn=false;ProgradeIsOn=false;if g()~=0 then ToggleAltitudeHold()else Autopilot=true end end elseif g()==0 then Autopilot=true;RetrogradeIsOn=false;ProgradeIsOn=false;AutopilotRealigned=false;FollowMode=false;AltitudeHold=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;APThrottleSet=false;LockPitch=nil else SpaceLaunch=true;ToggleAltitudeHold()end else Autopilot=false;AutopilotRealigned=false;VectorToTarget=false;APThrottleSet=false;AutoTakeoff=false;AltitudeHold=false;VectorToTarget=false end end;function ProgradeToggle()ProgradeIsOn=not ProgradeIsOn;RetrogradeIsOn=false;Autopilot=false;AltitudeHold=false;FollowMode=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function RetrogradeToggle()RetrogradeIsOn=not RetrogradeIsOn;ProgradeIsOn=false;Autopilot=false;AltitudeHold=false;FollowMode=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function BrakeToggle()BrakeIsOn=not BrakeIsOn;if BrakeLanding then BrakeLanding=false;autoRoll=autoRollPreference end;if BrakeIsOn then AltitudeHold=false;VectorToTarget=false;AutoTakeoff=false;Reentry=false;ProgradeIsOn=false;BrakeLanding=false;AutoLanding=false;AltitudeHold=false;LockPitch=nil;autoRoll=autoRollPreference end end;function checkDamage(as)local az=0;q=""local aA=I;local aB=0;local aC=0;local aD=0;local aE=0;local aF=""for V in pairs(ElementsID)do local a0=0;local aG=0;aG=f(ElementsID[V])a0=h(ElementsID[V])aB=aB+a0;if a00 and n[11]==ElementsID[V]then for aI in pairs(n)do core.deleteSticker(n[aI])end;n={}end end;az=b(aB/aA*100)if az<100 then as[#as+1]=[[]]aE=b(az*2.55)aF=c("rgb(%d,%d,%d)",255-aE,aE,0)if az<100 then as[#as+1]=c([[Elemental Integrity: %i %%]],aF,az)if aD>0 then as[#as+1]=c([[Disabled Modules: %i Damaged Modules: %i]],aF,aD,aC)elseif aC>0 then as[#as+1]=c([[Damaged Modules: %i]],aF,aC)end end;as[#as+1]=[[<\g>]]end end;function DrawCursorLine(as)local aJ=b(utils.clamp(Distance/(v/4)*255,0,255))as[#as+1]=c("",SimulatedX,SimulatedY,b(PrimaryR+0.5)+aJ,b(PrimaryG+0.5)-aJ,b(PrimaryB+0.5)-aJ)end;function getPitch(aK,aL,an)local aM=aK:cross(an):normalize_inplace()local ay=math.acos(utils.clamp(aM:dot(-aL),-1,1))*constants.rad2deg;if aM:cross(-aL):dot(an)<0 then ay=-ay end;return ay end;function clearAll()if clearAllCheck then clearAllCheck=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;FollowMode=false;APThrottleSet=false;SpaceLand=false;SpaceLaunch=false;ReentryMode=false;autoRoll=autoRollPreference;VectorToTarget=false;TurnBurn=false;GyroIsOn=false;LockPitch=nil else clearAllCheck=true end end;function wipeSaveVariables()if not dbHud then MsgText="No Databank Found, unable to wipe. \nYou must have a Databank attached to ship prior to running the HUD autoconfigure"MsgTimer=5 else if C then for V,W in pairs(SaveableVariables)do dbHud.setStringValue(W,e(nil))end;for V,W in pairs(AutoVariables)do if W~="SavedLocations"then dbHud.setStringValue(W,e(nil))end end;MsgText="Databank wiped. New variables will save after re-enter seat and exit"MsgTimer=5;C=false;B=false;WipedDatabank=true else MsgText="Press ALT-7 again to confirm wipe of ALL data"C=true end end end;function CheckButtons()for _,W in pairs(s)do if W.hovered then if not W.drawCondition or W.drawCondition()then W.toggleFunction()end;W.hovered=false end end end;function SetButtonContains()local af=SimulatedX+v/2;local ag=SimulatedY+w/2;for _,W in pairs(s)do W.hovered=Contains(af,ag,W.x,W.y,W.width,W.height)end end;function DrawButton(as,aN,hover,af,ag,aO,aP,aQ,aR,aS,aT)if type(aS)=="function"then aS=aS()end;if type(aT)=="function"then aT=aT()end;as[#as+1]=c(""if aN then as[#as+1]=c("%s",aS)else as[#as+1]=c("%s",aT)end end;function DrawButtons(as)local aU="rgb(50,50,50)'"local aV="rgb(210,200,200)"local aW=DrawButton;for _,W in pairs(s)do local ac=W.disableName;local ab=W.enableName;if type(ac)=="function"then ac=ac()end;if type(ab)=="function"then ab=ab()end;if not W.drawCondition or W.drawCondition()then aW(as,W.toggleVar(),W.hovered,W.x,W.y,W.width,W.height,aV,aU,ac,ab)end end end;function DrawTank(as,R,af,aX,aY,aZ,a_,b0)local b1=1;local b2=2;local b3=3;local b4=4;local b5=5;local b6=6;local b7=""local b8=0;local b9=fuelY;local ba=fuelY+10;if m()==1 and not RemoteHud then b9=b9-50;ba=ba-50 end;as[#as+1]=[[]]if aY=="ATMO"then b7="atmofueltank"elseif aY=="SPACE"then b7="spacefueltank"else b7="rocketfueltank"end;b8=_G[b7 .."_size"]if#aZ>0 then for i=1,#aZ do local ao=string.sub(aZ[i][b2],1,12)local bb=0;for aI=1,b8 do if aZ[i][b2]==d(unit[b7 .."_"..aI].getData()).name then bb=aI;break end end;if R or a_[i]==nil or b0[i]==nil then local bc=0;local bd=0;local be=0;local bf=0;local a3=system.getTime()if bb~=0 then b0[i]=d(unit[b7 .."_"..bb].getData()).percentage;a_[i]=d(unit[b7 .."_"..bb].getData()).timeLeft;if a_[i]=="n/a"then a_[i]=0 end else be=k(aZ[i][b1])-aZ[i][b4]bc=aZ[i][b3]b0[i]=b(0.5+be*100/bc)bd=aZ[i][b5]bf=aZ[i][b6]if bd<=be then a_[i]=0 else a_[i]=b(0.5+be/((bd-be)/(a3-bf)))end;aZ[i][b5]=be;aZ[i][b6]=a3 end end;if ao==aX then ao=c("%s %d",aY,i)end;if bb==0 then ao=ao.." *"end;local bg;if a_[i]==0 then bg="n/a"else bg=FormatTimeString(a_[i])end;if b0[i]~=nil then local aE=b(b0[i]*2.55)local aF=c("rgb(%d,%d,%d)",255-aE,aE,0)local bh=""if bg~="n/a"and a_[i]<120 or b0[i]<5 then if R then bh=[[class="red"]]end end;as[#as+1]=c([[ + Nav=Navigator.new(system,core,unit)script={}local a=system.print;local b=math.floor;local c=string.format;local d=json.decode;local e=json.encode;local f=core.getElementMaxHitPointsById;local g=unit.getAtmosphereDensity;local h=core.getElementHitPointsById;local j=core.getElementTypeById;local k=core.getElementMassById;local l=core.getConstructMass;local m=Nav.control.isRemoteControlled;function script.onStart()VERSION_NUMBER=4.852;SetupComplete=false;beginSetup=coroutine.create(function()Nav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal,{1000,5000,10000,20000,30000})InAtmo=g()>0;APThrottleSet=false;ToggleView=true;MinAutopilotSpeed=55;LastMaxBrake=0;LastMaxBrakeInAtmo=0;EmergencyWarp=false;ReentryMode=false;MousePitchFactor=1;MouseYawFactor=1;HasGear=false;PitchInput=0;PitchInput2=0;YawInput2=0;RollInput=0;YawInput=0;BrakeInput=0;RollInput2=0;RetrogradeIsOn=false;ProgradeIsOn=false;Reentry=false;FollowMode=false;TurnBurn=false;AutopilotAccelerating=false;AutopilotRealigned=false;HoldingCtrl=false;PrevViewLock=1;MsgText="empty"LastEccentricity=1;HoldAltitudeButtonModifier=5;AntiGravButtonModifier=5;IsBoosting=false;BrakeDistance,BrakeTime=0;MaxBrakeDistance,MaxBrakeTime=0;HasSpaceRadar=false;HasAtmoRadar=false;AutopilotTargetIndex=0;AutopilotTargetName="None"AutopilotTargetPlanet=nil;TotalDistanceTravelled=0.0;TotalDistanceTrip=0;InEmergencyWarp=false;NotTriedEmergencyWarp=true;FlightTime=0;WipedDatabank=false;LocationIndex=0;UpAmount=0;BrakeIsOn=false;Autopilot=false;AltitudeHold=false;BrakeLanding=false;AutoTakeoff=false;HoldAltitude=1000;AutopilotBraking=false;AutopilotCruising=false;VectorToTarget=false;SimulatedX=0;SimulatedY=0;AutopilotStatus="Aligning"MsgTimer=3;TargetGroundAltitude=nil;GearExtended=nil;Distance=0;RadarMessage=""LastOdometerOutput=""Peris=0;CoreAltitude=core.getAltitude()AntigravTargetAltitude=CoreAltitude;ElementsID=core.getElementIdList()LastTravelTime=system.getTime()TotalFlightTime=0;HasGear=false;AutopilotPlanetGravity=0;DisplayOrbit=true;AutopilotEndSpeed=0;SavedLocations={}LandingGearGroundHeight=0;SpaceLand=false;SpaceLaunch=false;FinalLand=false;HovGndDet=-1;clearAllCheck=false;LockPitch=nil;LastStartTime=0;local n={}local o=0;local p=0;local q=""local r=true;local s={}local t=1;local u=0.001;local v=2560;local w=1440;local x=nil;local y=nil;local z=nil;local A=nil;local B=false;local C=false;local D=0;local E=nil;local F={}local G={}local H={}local I=0;local J=false;local K={}local L={}local M=b(1/apTickRate)*2;local N={}local O={}local P={}local Q={}local R=false;local S=16;local T=0;SaveableVariables={"userControlScheme","AutopilotTargetOrbit","apTickRate","freeLookToggle","turnAssist","PrimaryR","PrimaryG","PrimaryB","warmup","DeadZone","circleRad","MouseXSensitivity","MouseYSensitivity","MaxGameVelocity","showHud","autoRollPreference","pitchSpeedFactor","yawSpeedFactor","rollSpeedFactor","brakeSpeedFactor","brakeFlatFactor","autoRollFactor","turnAssistFactor","torqueFactor","AutoTakeoffAltitude","TargetHoverHeight","AutopilotInterplanetaryThrottle","hideHudOnToggleWidgets","DampingMultiplier","fuelTankHandlingAtmo","fuelTankHandlingSpace","fuelTankHandlingRocket","RemoteFreeze","speedChangeLarge","speedChangeSmall","brightHud","brakeLandingRate","MaxPitch","ReentrySpeed","ReentryAltitude","EmergencyWarpDistance","centerX","centerY","vSpdMeterX","vSpdMeterY","altMeterX","altMeterY","fuelX","fuelY","LandingGearGroundHeight","TrajectoryAlignmentStrength","RemoteHud","StallAngle","ResolutionX","ResolutionY"}AutoVariables={"EmergencyWarp","brakeToggle","BrakeIsOn","RetrogradeIsOn","ProgradeIsOn","Autopilot","TurnBurn","AltitudeHold","DisplayOrbit","BrakeLanding","Reentry","AutoTakeoff","HoldAltitude","AutopilotAccelerating","AutopilotBraking","AutopilotCruising","AutopilotRealigned","AutopilotEndSpeed","AutopilotStatus","AutopilotPlanetGravity","PrevViewLock","AutopilotTargetName","AutopilotTargetCoords","AutopilotTargetIndex","GearExtended","TargetGroundAltitude","TotalDistanceTravelled","TotalFlightTime","SavedLocations","VectorToTarget","LocationIndex","LastMaxBrake","LockPitch","LastMaxBrakeInAtmo","AntigravTargetAltitude","LastStartTime"}if dbHud then local U=dbHud.hasKey;if not useTheseSettings then for V,W in pairs(SaveableVariables)do if U(W)then local X=d(dbHud.getStringValue(W))if X~=nil then a(W.." "..dbHud.getStringValue(W))_G[W]=X;B=true end end end end;for V,W in pairs(AutoVariables)do if U(W)then local X=d(dbHud.getStringValue(W))if X~=nil then a(W.." "..dbHud.getStringValue(W))_G[W]=X;B=true end end end;if useTheseSettings then MsgText="Updated user preferences used. Will be saved when you exit seat. Toggle off useTheseSettings to use saved values"elseif B then MsgText="Loaded Saved Variables (see Lua Chat Tab for list)"else MsgText="No Saved Variables Found - Stand up / leave remote to save settings"end else MsgText="No databank found, install one anywhere and rerun the autoconfigure to save variables"end;coroutine.yield()local Y=system.getTime()if LastStartTime+18010000 then S=128 elseif a0>1000 then S=64 elseif a0>150 then S=32 end end;I=I+f(ElementsID[V])if fuelX~=0 and fuelY~=0 then if type=="Atmospheric Fuel Tank"or type=="Space Fuel Tank"or type=="Rocket Fuel Tank"then local a0=f(ElementsID[V])local a1=k(ElementsID[V])local a2=0;local a3=system.getTime()if type=="Atmospheric Fuel Tank"then local a4=400;local a5=35.03;if a0>10000 then a4=51200;a5=5480 elseif a0>1300 then a4=6400;a5=988.67 elseif a0>150 then a4=1600;a5=182.67 end;a2=a1-a5;if fuelTankHandlingAtmo>0 then a4=a4+a4*fuelTankHandlingAtmo*0.2 end;if a2>a4 then a4=a2 end;F[#F+1]={ElementsID[V],core.getElementNameById(ElementsID[V]),a4,a5,a2,a3}end;if type=="Rocket Fuel Tank"then local a4=320;local a5=173.42;if a0>65000 then a4=40000;a5=25740 elseif a0>6000 then a4=5120;a5=4720 elseif a0>700 then a4=640;a5=886.72 end;a2=a1-a5;if fuelTankHandlingRocket>0 then a4=a4+a4*fuelTankHandlingRocket*0.2 end;if a2>a4 then a4=a2 end;H[#H+1]={ElementsID[V],core.getElementNameById(ElementsID[V]),a4,a5,a2,a3}end;if type=="Space Fuel Tank"then local a4=2400;local a5=182.67;if a0>10000 then a4=76800;a5=5480 elseif a0>1300 then a4=9600;a5=988.67 end;a2=a1-a5;if fuelTankHandlingSpace>0 then a4=a4+a4*fuelTankHandlingSpace*0.2 end;if a2>a4 then a4=a2 end;G[#G+1]={ElementsID[V],core.getElementNameById(ElementsID[V]),a4,a5,a2,a3}end end end end;coroutine.yield()if gyro~=nil then GyroIsOn=gyro.getState()==1 end;if userControlScheme~="keyboard"then system.lockView(1)else system.lockView(0)end;if InAtmo then BrakeIsOn=true end;if radar_1 then if j(radar_1.getId())=="Space Radar"then HasSpaceRadar=true else HasAtmoRadar=true end end;if door then for _,W in pairs(door)do W.toggle()end end;if switch then for _,W in pairs(switch)do W.toggle()end end;if forcefield then for _,W in pairs(forcefield)do W.toggle()end end;if antigrav~=nil and not ExternalAGG then if antigrav.getState()==1 then antigrav.show()end end;if m()==1 and RemoteFreeze then system.freeze(1)else system.freeze(0)end;if HasGear then GearExtended=Nav.control.isAnyLandingGearExtended()==1;if GearExtended then Nav.control.extendLandingGears()else Nav.control.retractLandingGears()end end;if TargetGroundAltitude~=nil then Nav.axisCommandManager:setTargetGroundAltitude(TargetGroundAltitude)if TargetGroundAltitude==0 and not HasGear then GearExtended=true end else if GearExtended or not HasGear then Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)GearExtended=true else Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end end;if InAtmo and not dbHud and(GearExtended or not HasGear)then BrakeIsOn=true end;WasInAtmo=InAtmo;unit.hide()function refreshLastMaxBrake(a6,a7)if a6==nil then a6=core.g()end;a6=round(a6,5)local a8=g()if a7~=nil and a7 or(E==nil or E~=a6)then local velocity=core.getVelocity()local a9=vec3(velocity):len()local aa=d(unit.getData()).maxBrake;if aa~=nil and aa>0 and InAtmo then aa=aa/utils.clamp(a9/100,0.1,1)aa=aa/a8;if aa>LastMaxBrakeInAtmo and a8>0.10 then LastMaxBrakeInAtmo=aa end end;if aa~=nil and aa>0 then LastMaxBrake=aa end;E=a6 end end;function MakeButton(ab,ac,ad,ae,af,ag,ah,ai,aj)local ak={enableName=ab,disableName=ac,width=ad,height=ae,x=af,y=ag,toggleVar=ah,toggleFunction=ai,drawCondition=aj,hovered=false}table.insert(s,ak)return ak end;function UpdateAtlasLocationsList()AtlasOrdered={}for V,W in pairs(atlas[0])do table.insert(AtlasOrdered,{name=W.name,index=V})end;local function al(am,an)return am.name-1 then atlas[0][ar]=aq end;UpdateAtlasLocationsList()MsgText=CustomTarget.name.." position updated"end end;function ClearCurrentPosition()local ar=-1;for V,W in pairs(atlas[0])do if W.name and W.name==CustomTarget.name then ar=V end end;if ar>-1 then table.remove(atlas[0],ar)end;ar=-1;for V,W in pairs(SavedLocations)do if W.name and W.name==CustomTarget.name then MsgText=W.name.." saved location cleared"ar=V;break end end;if ar~=-1 then table.remove(SavedLocations,ar)end;DecrementAutopilotTargetIndex()UpdateAtlasLocationsList()end;function DrawDeadZone(as)as[#as+1]=c([[]],DeadZone)end;function ToggleRadarPanel()if radarPanelID~=nil and Peris==0 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;if perisPanelID~=nil then system.destroyWidgetPanel(perisPanelID)perisPanelID=nil end else if Peris==1 then system.destroyWidgetPanel(radarPanelID)radarPanelID=nil;_autoconf.displayCategoryPanel(radar,radar_size,L_TEXT("ui_lua_widget_periscope", "Periscope"),"periscope")perisPanelID=_autoconf.panels[_autoconf.panels_size]end;placeRadar=true;if radarPanelID==nil and placeRadar then _autoconf.displayCategoryPanel(radar,radar_size,L_TEXT("ui_lua_widget_radar", "Radar"),"radar")radarPanelID=_autoconf.panels[_autoconf.panels_size]placeRadar=false end;Peris=0 end end;function ToggleWidgets()if r 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;r=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;r=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 InAtmo then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;widgetCurBrakeTime=system.createWidget(panelInterplanetary,"value")widgetCurBrakeTimeText=system.createData('{"label": "Cur Brake Time", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;widgetMaxBrakeDistance=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeDistanceText=system.createData('{"label": "Max Brake Distance", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;widgetMaxBrakeTime=system.createWidget(panelInterplanetary,"value")widgetMaxBrakeTimeText=system.createData('{"label": "Max Brake Time", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;widgetTrajectoryAltitude=system.createWidget(panelInterplanetary,"value")widgetTrajectoryAltitudeText=system.createData('{"label": "Projected Altitude", "value": "N/A", "unit":""}')if not InAtmo then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;function Contains(at,au,af,ag,ad,ae)if at>af and atag and auMinAutopilotSpeed then MsgText="WARNING: Insufficient Brakes - Attempting coast landing, beware obstacles"end;AltitudeHold=false;AutoTakeoff=false;LockPitch=nil;BrakeLanding=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)end end;function ToggleAutoTakeoff()if AutoTakeoff then AutoTakeoff=false;if AltitudeHold then ToggleAltitudeHold()end else if not AltitudeHold then ToggleAltitudeHold()end;AutoTakeoff=true;HoldAltitude=CoreAltitude+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end end;function ToggleLockPitch()if LockPitch==nil then local av=vec3(core.getConstructWorldOrientationForward())local aw=vec3(core.getConstructWorldOrientationRight())local ax=vec3(core.getWorldVertical())local ay=getPitch(ax,av,aw)LockPitch=ay;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=false else LockPitch=nil end end;function ToggleAltitudeHold()AltitudeHold=not AltitudeHold;if AltitudeHold then Autopilot=false;ProgradeIsOn=false;RetrogradeIsOn=false;FollowMode=false;BrakeLanding=false;Reentry=false;autoRoll=true;LockPitch=nil;if not GearExtended and not BrakeIsOn or not InAtmo then AutoTakeoff=false;HoldAltitude=CoreAltitude;if not SpaceLaunch and Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end else AutoTakeoff=true;HoldAltitude=CoreAltitude+AutoTakeoffAltitude;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(500)BrakeIsOn=true end;if SpaceLaunch then HoldAltitude=100000 end else autoRoll=autoRollPreference;AutoTakeoff=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;VectorToTarget=false end end;function ToggleFollowMode()if m()==1 then FollowMode=not FollowMode;if FollowMode then Autopilot=false;RetrogradeIsOn=false;ProgradeIsOn=false;AltitudeHold=false;Reentry=false;BrakeLanding=false;AutoTakeoff=false;OldGearExtended=GearExtended;GearExtended=false;Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)else BrakeIsOn=true;autoRoll=autoRollPreference;GearExtended=OldGearExtended;if GearExtended then Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end end else MsgText="Follow Mode only works with Remote controller"FollowMode=false end end;function ToggleAutopilot()if AutopilotTargetIndex>0 and not Autopilot and not VectorToTarget then if CustomTarget~=nil then LockPitch=nil;if planet.name==CustomTarget.planetname then StrongBrakes=planet.gravity*9.80665*l()MinAutopilotSpeed then MsgText="Insufficient Brake Force\nCoast landing will be inaccurate"end;if g()>0 then if not AltitudeHold then if not VectorToTarget then ToggleVectorToTarget()end else if not VectorToTarget then ToggleVectorToTarget()end end else SpaceLand=true end else SpaceLaunch=true;RetrogradeIsOn=false;ProgradeIsOn=false;if g()~=0 then ToggleAltitudeHold()else Autopilot=true end end elseif g()==0 then Autopilot=true;RetrogradeIsOn=false;ProgradeIsOn=false;AutopilotRealigned=false;FollowMode=false;AltitudeHold=false;BrakeLanding=false;Reentry=false;AutoTakeoff=false;APThrottleSet=false;LockPitch=nil else SpaceLaunch=true;ToggleAltitudeHold()end else Autopilot=false;AutopilotRealigned=false;VectorToTarget=false;APThrottleSet=false;AutoTakeoff=false;AltitudeHold=false;VectorToTarget=false end end;function ProgradeToggle()ProgradeIsOn=not ProgradeIsOn;RetrogradeIsOn=false;Autopilot=false;AltitudeHold=false;FollowMode=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function RetrogradeToggle()RetrogradeIsOn=not RetrogradeIsOn;ProgradeIsOn=false;Autopilot=false;AltitudeHold=false;FollowMode=false;BrakeLanding=false;LockPitch=nil;Reentry=false;AutoTakeoff=false end;function BrakeToggle()BrakeIsOn=not BrakeIsOn;if BrakeLanding then BrakeLanding=false;autoRoll=autoRollPreference end;if BrakeIsOn then AltitudeHold=false;VectorToTarget=false;AutoTakeoff=false;Reentry=false;ProgradeIsOn=false;BrakeLanding=false;AutoLanding=false;AltitudeHold=false;LockPitch=nil;autoRoll=autoRollPreference end end;function checkDamage(as)local az=0;q=""local aA=I;local aB=0;local aC=0;local aD=0;local aE=0;local aF=""for V in pairs(ElementsID)do local a0=0;local aG=0;aG=f(ElementsID[V])a0=h(ElementsID[V])aB=aB+a0;if a00 and n[11]==ElementsID[V]then for aI in pairs(n)do core.deleteSticker(n[aI])end;n={}end end;az=b(aB/aA*100)if az<100 then as[#as+1]=[[]]aE=b(az*2.55)aF=c("rgb(%d,%d,%d)",255-aE,aE,0)if az<100 then as[#as+1]=c([[Elemental Integrity: %i %%]],aF,az)if aD>0 then as[#as+1]=c([[Disabled Modules: %i Damaged Modules: %i]],aF,aD,aC)elseif aC>0 then as[#as+1]=c([[Damaged Modules: %i]],aF,aC)end end;as[#as+1]=[[<\g>]]end end;function DrawCursorLine(as)local aJ=b(utils.clamp(Distance/(v/4)*255,0,255))as[#as+1]=c("",SimulatedX,SimulatedY,b(PrimaryR+0.5)+aJ,b(PrimaryG+0.5)-aJ,b(PrimaryB+0.5)-aJ)end;function getPitch(aK,aL,an)local aM=aK:cross(an):normalize_inplace()local ay=math.acos(utils.clamp(aM:dot(-aL),-1,1))*constants.rad2deg;if aM:cross(-aL):dot(an)<0 then ay=-ay end;return ay end;function clearAll()if clearAllCheck then clearAllCheck=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;FollowMode=false;APThrottleSet=false;SpaceLand=false;SpaceLaunch=false;ReentryMode=false;autoRoll=autoRollPreference;EmergencyWarp=false;VectorToTarget=false;TurnBurn=false;GyroIsOn=false;LockPitch=nil else clearAllCheck=true end end;function wipeSaveVariables()if not dbHud then MsgText="No Databank Found, unable to wipe. \nYou must have a Databank attached to ship prior to running the HUD autoconfigure"MsgTimer=5 else if C then for V,W in pairs(SaveableVariables)do dbHud.setStringValue(W,e(nil))end;for V,W in pairs(AutoVariables)do if W~="SavedLocations"then dbHud.setStringValue(W,e(nil))end end;MsgText="Databank wiped. New variables will save after re-enter seat and exit"MsgTimer=5;C=false;B=false;WipedDatabank=true else MsgText="Press ALT-7 again to confirm wipe of ALL data"C=true end end end;function CheckButtons()for _,W in pairs(s)do if W.hovered then if not W.drawCondition or W.drawCondition()then W.toggleFunction()end;W.hovered=false end end end;function SetButtonContains()local af=SimulatedX+v/2;local ag=SimulatedY+w/2;for _,W in pairs(s)do W.hovered=Contains(af,ag,W.x,W.y,W.width,W.height)end end;function DrawButton(as,aN,hover,af,ag,aO,aP,aQ,aR,aS,aT)if type(aS)=="function"then aS=aS()end;if type(aT)=="function"then aT=aT()end;as[#as+1]=c(""if aN then as[#as+1]=c("%s",aS)else as[#as+1]=c("%s",aT)end end;function DrawButtons(as)local aU="rgb(50,50,50)'"local aV="rgb(210,200,200)"local aW=DrawButton;for _,W in pairs(s)do local ac=W.disableName;local ab=W.enableName;if type(ac)=="function"then ac=ac()end;if type(ab)=="function"then ab=ab()end;if not W.drawCondition or W.drawCondition()then aW(as,W.toggleVar(),W.hovered,W.x,W.y,W.width,W.height,aV,aU,ac,ab)end end end;function DrawTank(as,R,af,aX,aY,aZ,a_,b0)local b1=1;local b2=2;local b3=3;local b4=4;local b5=5;local b6=6;local b7=""local b8=0;local b9=fuelY;local ba=fuelY+10;if m()==1 and not RemoteHud then b9=b9-50;ba=ba-50 end;as[#as+1]=[[]]if aY=="ATMO"then b7="atmofueltank"elseif aY=="SPACE"then b7="spacefueltank"else b7="rocketfueltank"end;b8=_G[b7 .."_size"]if#aZ>0 then for i=1,#aZ do local ao=string.sub(aZ[i][b2],1,12)local bb=0;for aI=1,b8 do if aZ[i][b2]==d(unit[b7 .."_"..aI].getData()).name then bb=aI;break end end;if R or a_[i]==nil or b0[i]==nil then local bc=0;local bd=0;local be=0;local bf=0;local a3=system.getTime()if bb~=0 then b0[i]=d(unit[b7 .."_"..bb].getData()).percentage;a_[i]=d(unit[b7 .."_"..bb].getData()).timeLeft;if a_[i]=="n/a"then a_[i]=0 end else be=k(aZ[i][b1])-aZ[i][b4]bc=aZ[i][b3]b0[i]=b(0.5+be*100/bc)bd=aZ[i][b5]bf=aZ[i][b6]if bd<=be then a_[i]=0 else a_[i]=b(0.5+be/((bd-be)/(a3-bf)))end;aZ[i][b5]=be;aZ[i][b6]=a3 end end;if ao==aX then ao=c("%s %d",aY,i)end;if bb==0 then ao=ao.." *"end;local bg;if a_[i]==0 then bg="n/a"else bg=FormatTimeString(a_[i])end;if b0[i]~=nil then local aE=b(b0[i]*2.55)local aF=c("rgb(%d,%d,%d)",255-aE,aE,0)local bh=""if bg~="n/a"and a_[i]<120 or b0[i]<5 then if R then bh=[[class="red"]]end end;as[#as+1]=c([[ %s %d%% %s - ]],af,b9,bh,ao,af,ba,aF,b0[i],bg)b9=b9+30;ba=ba+30 end end end;as[#as+1]=""end;function HideInterplanetaryPanel()system.destroyWidgetPanel(panelInterplanetary)panelInterplanetary=nil end;system.showScreen(1)function getRelativePitch(velocity)velocity=vec3(velocity)local ay=-math.deg(math.atan(velocity.y,velocity.z))+180;ay=ay-90;if ay<0 then ay=360+ay end;if ay>180 then ay=-180+ay-180 end;return-ay end;function getRelativeYaw(velocity)velocity=vec3(velocity)local bi=math.deg(math.atan(velocity.y,velocity.x))-90;if bi<-180 then bi=360+bi end;return bi end;function AlignToWorldVector(bj,bk)if not InAtmo or RateOfChange>MinimumRateOfChange+0.08 or HovGndDet~=-1 then if bk==nil then bk=u end;bj=vec3(bj):normalize()local bl=vec3(core.getConstructWorldOrientationForward())-bj;local bm=-getMagnitudeInDirection(bl,core.getConstructWorldOrientationRight())*t;local bn=-getMagnitudeInDirection(bl,core.getConstructWorldOrientationUp())*t;if o==0 then o=bm/2 end;if p==0 then p=bn/2 end;YawInput2=YawInput2-(bm+(bm-o)*DampingMultiplier)PitchInput2=PitchInput2+bn+(bn-p)*DampingMultiplier;o=bm;p=bn;if math.abs(bm)0 and CustomTarget~=nil end)MakeButton("Clear Position","Clear Position",200,br.height,br.x-200-30,br.y,function()return true end,ClearCurrentPosition,function()return AutopilotTargetIndex>0 and CustomTarget~=nil end)bo=60;bp=300;local af=10;local ag=w/2-300;MakeButton("Enable Turn and Burn","Disable Turn and Burn",bp,bo,af,ag,function()return TurnBurn end,ToggleTurnBurn)MakeButton("Engage Altitude Hold","Disable Altitude Hold",bp,bo,af+bp+20,ag,function()return AltitudeHold end,ToggleAltitudeHold)ag=ag+bo+20;MakeButton("Engage Autoland","Disable Autoland",bp,bo,af,ag,function()return AutoLanding end,ToggleAutoLanding)MakeButton("Engage Auto Takeoff","Disable Auto Takeoff",bp,bo,af+bp+20,ag,function()return AutoTakeoff end,ToggleAutoTakeoff)ag=ag+bo+20;MakeButton("Show Orbit Display","Hide Orbit Display",bp,bo,af,ag,function()return DisplayOrbit end,function()DisplayOrbit=not DisplayOrbit;if DisplayOrbit then MsgText="Orbit Display Enabled"else MsgText="Orbit Display Disabled"end end)ag=ag+bo+20;MakeButton("Glide Re-Entry","Cancel Glide Re-Entry",bp,bo,af,ag,function()return Reentry end,function()ReentryMode=true;BeginReentry()end,function()return CoreAltitude>ReentryAltitude end)MakeButton("Parachute Re-Entry","Cancel Parachute Re-Entry",bp,bo,af+bp+20,ag,function()return Reentry end,BeginReentry,function()return CoreAltitude>ReentryAltitude end)ag=ag+bo+20;MakeButton("Engage Follow Mode","Disable Follow Mode",bp,bo,af,ag,function()return FollowMode end,ToggleFollowMode,function()return m()==1 end)MakeButton("Enable Repair Arrows","Disable Repair Arrows",bp,bo,af+bp+20,ag,function()return J end,function()J=not J;if J then MsgText="Repair Arrows Enabled"else MsgText="Repair Arrows Diabled"end end,function()return m()==1 end)ag=ag+bo+20;if not ExternalAGG then MakeButton("Enable AGG","Disable AGG",bp,bo,af,ag,function()return antigrav.getState()==1 end,ToggleAntigrav,function()return antigrav~=nil end)end;ag=ag+bo+20;MakeButton(function()return c("Toggle Control Scheme - Current: %s",userControlScheme)end,function()return c("Control Scheme: %s",userControlScheme)end,bp*2,bo,af,ag,function()return false end,function()if userControlScheme=="keyboard"then userControlScheme="mouse"elseif userControlScheme=="mouse"then userControlScheme="virtual joystick"else userControlScheme="keyboard"end end)coroutine.yield()function GetFlightStyle()local bs=Nav.axisCommandManager:getAxisCommandType(0)local bt="TRAVEL"if bs==1 then bt="CRUISE"end;if Autopilot then bt="AUTOPILOT"end;return bt end;function updateHud(as)local bu=CoreAltitude;local velocity=core.getVelocity()local a9=vec3(velocity):len()local ax=vec3(core.getWorldVertical())local av=vec3(core.getConstructWorldOrientationForward())local aw=vec3(core.getConstructWorldOrientationRight())local bv=vec3(core.getConstructWorldOrientationUp())local bw=getRoll(ax,av,aw)local bx=bw/180*math.pi;local by=math.cos(bx)local bz=math.sin(bx)local ay=getPitch(ax,av,aw*by+bv*bz)local bA=bw;local bB=ay;local bC=g()local bD=b(unit.getThrottle())local bE=a9*3.6;local bF=unit.getAxisCommandValue(0)local bt=GetFlightStyle()local bG="ROLL"local bH=unit.getClosestPlanetInfluence()>0;if bD==nil then bD=0 end;if not bH then if a9>5 then ay=getRelativePitch(velocity)bw=getRelativeYaw(velocity)else ay=0;bw=0 end;bG="YAW"end;as[#as+1]=LastOdometerOutput;as[#as+1]=q;as[#as+1]=RadarMessage;if T%M==0 then R=true end;if fuelX~=0 and fuelY~=0 then DrawTank(as,R,fuelX,"Atmospheric ","ATMO",F,P,Q)DrawTank(as,R,fuelX+100,"Space fuel t","SPACE",G,N,O)DrawTank(as,R,fuelX+200,"Rocket fuel ","ROCKET",H,K,L)end;if R then R=false;T=0 end;T=T+1;DrawVerticalSpeed(as,bu)if m()==0 or RemoteHud then if not IsInFreeLook()or brightHud then if bH then DrawRollLines(as,centerX,centerY,bA,bG,bH)DrawArtificialHorizon(as,bB,bA,centerX,centerY,bH,b(getRelativeYaw(velocity)),a9)DrawAltitudeDisplay(as,bu)else DrawRollLines(as,centerX,centerY,bw,bG,bH)DrawArtificialHorizon(as,ay,bw,centerX,centerY,bH,b(bw),a9)end;DrawPrograde(as,velocity,a9,centerX,centerY)end end;DrawThrottle(as,bt,bD,bF)DrawSpeed(as,bE)DrawWarnings(as)DisplayOrbitScreen(as)if screen_2 then local bI=vec3(core.getConstructWorldPos())local af=960+bI.x/MapXRatio;local ag=450+bI.y/MapYRatio;screen_2.moveContent(YouAreHere,(af-80)/19.2,(ag-80)/10.8)end end;function IsInFreeLook()return system.isViewLocked()==0 and userControlScheme~="keyboard"and m()==0 end;function HUDPrologue(as)local bJ=rgb;local bK=Z;local bL=rgb;local bM=Z;if IsInFreeLook()and not brightHud then bJ=[[rgb(]]..b(PrimaryR*0.4+0.5)..","..b(PrimaryG*0.4+0.5)..","..b(PrimaryB*0.3+0.5)..[[)]]bK=[[rgb(]]..b(PrimaryR*0.3+0.5)..","..b(PrimaryG*0.3+0.5)..","..b(PrimaryB*0.2+0.5)..[[)]]end;as[#as+1]=c([[ + ]],af,b9,bh,ao,af,ba,aF,b0[i],bg)b9=b9+30;ba=ba+30 end end end;as[#as+1]=""end;function HideInterplanetaryPanel()system.destroyWidgetPanel(panelInterplanetary)panelInterplanetary=nil end;system.showScreen(1)function getRelativePitch(velocity)velocity=vec3(velocity)local ay=-math.deg(math.atan(velocity.y,velocity.z))+180;ay=ay-90;if ay<0 then ay=360+ay end;if ay>180 then ay=-180+ay-180 end;return-ay end;function getRelativeYaw(velocity)velocity=vec3(velocity)local bi=math.deg(math.atan(velocity.y,velocity.x))-90;if bi<-180 then bi=360+bi end;return bi end;function AlignToWorldVector(bj,bk)if not InAtmo or RateOfChange>MinimumRateOfChange+0.08 or HovGndDet~=-1 then if bk==nil then bk=u end;bj=vec3(bj):normalize()local bl=vec3(core.getConstructWorldOrientationForward())-bj;local bm=-getMagnitudeInDirection(bl,core.getConstructWorldOrientationRight())*t;local bn=-getMagnitudeInDirection(bl,core.getConstructWorldOrientationUp())*t;if o==0 then o=bm/2 end;if p==0 then p=bn/2 end;YawInput2=YawInput2-(bm+(bm-o)*DampingMultiplier)PitchInput2=PitchInput2+bn+(bn-p)*DampingMultiplier;o=bm;p=bn;if math.abs(bm)0 and CustomTarget~=nil end)MakeButton("Clear Position","Clear Position",200,br.height,br.x-200-30,br.y,function()return true end,ClearCurrentPosition,function()return AutopilotTargetIndex>0 and CustomTarget~=nil end)bo=60;bp=300;local af=10;local ag=w/2-300;MakeButton("Enable Turn and Burn","Disable Turn and Burn",bp,bo,af,ag,function()return TurnBurn end,ToggleTurnBurn)MakeButton("Engage Altitude Hold","Disable Altitude Hold",bp,bo,af+bp+20,ag,function()return AltitudeHold end,ToggleAltitudeHold)ag=ag+bo+20;MakeButton("Engage Autoland","Disable Autoland",bp,bo,af,ag,function()return AutoLanding end,ToggleAutoLanding)MakeButton("Engage Auto Takeoff","Disable Auto Takeoff",bp,bo,af+bp+20,ag,function()return AutoTakeoff end,ToggleAutoTakeoff)ag=ag+bo+20;MakeButton("Show Orbit Display","Hide Orbit Display",bp,bo,af,ag,function()return DisplayOrbit end,function()DisplayOrbit=not DisplayOrbit;if DisplayOrbit then MsgText="Orbit Display Enabled"else MsgText="Orbit Display Disabled"end end)MakeButton("Enable Emergency Warp","Disable Emergency Warp",bp,bo,af+bp+20,ag,function()return EmergencyWarp end,function()EmergencyWarp=not EmergencyWarp;if EmergencyWarp then MsgText="Emergency Warp Enabled"else MsgText="Emergency Warp Disabled"end end,function()return warpdrive~=nil end)ag=ag+bo+20;MakeButton("Glide Re-Entry","Cancel Glide Re-Entry",bp,bo,af,ag,function()return Reentry end,function()ReentryMode=true;BeginReentry()end,function()return CoreAltitude>ReentryAltitude end)MakeButton("Parachute Re-Entry","Cancel Parachute Re-Entry",bp,bo,af+bp+20,ag,function()return Reentry end,BeginReentry,function()return CoreAltitude>ReentryAltitude end)ag=ag+bo+20;MakeButton("Engage Follow Mode","Disable Follow Mode",bp,bo,af,ag,function()return FollowMode end,ToggleFollowMode,function()return m()==1 end)MakeButton("Enable Repair Arrows","Disable Repair Arrows",bp,bo,af+bp+20,ag,function()return J end,function()J=not J;if J then MsgText="Repair Arrows Enabled"else MsgText="Repair Arrows Diabled"end end,function()return m()==1 end)ag=ag+bo+20;if not ExternalAGG then MakeButton("Enable AGG","Disable AGG",bp,bo,af,ag,function()return antigrav.getState()==1 end,ToggleAntigrav,function()return antigrav~=nil end)end;ag=ag+bo+20;MakeButton(function()return c("Toggle Control Scheme - Current: %s",userControlScheme)end,function()return c("Control Scheme: %s",userControlScheme)end,bp*2,bo,af,ag,function()return false end,function()if userControlScheme=="keyboard"then userControlScheme="mouse"elseif userControlScheme=="mouse"then userControlScheme="virtual joystick"else userControlScheme="keyboard"end end)coroutine.yield()function GetFlightStyle()local bs=Nav.axisCommandManager:getAxisCommandType(0)local bt="TRAVEL"if bs==1 then bt="CRUISE"end;if Autopilot then bt="AUTOPILOT"end;return bt end;function updateHud(as)local bu=CoreAltitude;local velocity=core.getVelocity()local a9=vec3(velocity):len()local ax=vec3(core.getWorldVertical())local av=vec3(core.getConstructWorldOrientationForward())local aw=vec3(core.getConstructWorldOrientationRight())local bv=vec3(core.getConstructWorldOrientationUp())local bw=getRoll(ax,av,aw)local bx=bw/180*math.pi;local by=math.cos(bx)local bz=math.sin(bx)local ay=getPitch(ax,av,aw*by+bv*bz)local bA=bw;local bB=ay;local bC=g()local bD=b(unit.getThrottle())local bE=a9*3.6;local bF=unit.getAxisCommandValue(0)local bt=GetFlightStyle()local bG="ROLL"local bH=unit.getClosestPlanetInfluence()>0;if bD==nil then bD=0 end;if not bH then if a9>5 then ay=getRelativePitch(velocity)bw=getRelativeYaw(velocity)else ay=0;bw=0 end;bG="YAW"end;as[#as+1]=LastOdometerOutput;as[#as+1]=q;as[#as+1]=RadarMessage;if T%M==0 then R=true end;if fuelX~=0 and fuelY~=0 then DrawTank(as,R,fuelX,"Atmospheric ","ATMO",F,P,Q)DrawTank(as,R,fuelX+100,"Space fuel t","SPACE",G,N,O)DrawTank(as,R,fuelX+200,"Rocket fuel ","ROCKET",H,K,L)end;if R then R=false;T=0 end;T=T+1;DrawVerticalSpeed(as,bu)if m()==0 or RemoteHud then if not IsInFreeLook()or brightHud then if bH then DrawRollLines(as,centerX,centerY,bA,bG,bH)DrawArtificialHorizon(as,bB,bA,centerX,centerY,bH,b(getRelativeYaw(velocity)),a9)DrawAltitudeDisplay(as,bu)else DrawRollLines(as,centerX,centerY,bw,bG,bH)DrawArtificialHorizon(as,ay,bw,centerX,centerY,bH,b(bw),a9)end;DrawPrograde(as,velocity,a9,centerX,centerY)end end;DrawThrottle(as,bt,bD,bF)DrawSpeed(as,bE)DrawWarnings(as)DisplayOrbitScreen(as)if screen_2 then local bI=vec3(core.getConstructWorldPos())local af=960+bI.x/MapXRatio;local ag=450+bI.y/MapYRatio;screen_2.moveContent(YouAreHere,(af-80)/19.2,(ag-80)/10.8)end end;function IsInFreeLook()return system.isViewLocked()==0 and userControlScheme~="keyboard"and m()==0 end;function HUDPrologue(as)local bJ=rgb;local bK=Z;local bL=rgb;local bM=Z;if IsInFreeLook()and not brightHud then bJ=[[rgb(]]..b(PrimaryR*0.4+0.5)..","..b(PrimaryG*0.4+0.5)..","..b(PrimaryB*0.3+0.5)..[[)]]bK=[[rgb(]]..b(PrimaryR*0.3+0.5)..","..b(PrimaryG*0.3+0.5)..","..b(PrimaryB*0.2+0.5)..[[)]]end;as[#as+1]=c([[ "as[#as+1]=GalaxyMapHTML;as[#as+1]=f_;as[#as+1]=""Animating=true;as[#as+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(as,"")system.setScreen(content)elseif Animated then local f_=table.concat(as,"")as={}as[#as+1]=""as[#as+1]=GalaxyMapHTML;as[#as+1]=f_;as[#as+1]=""end;if not Animating then as[#as+1]=c([[]],SimulatedX,SimulatedY)end else CheckButtons()SimulatedX=0;SimulatedY=0 end else SimulatedX=SimulatedX+fX;SimulatedY=SimulatedY+fY;Distance=math.sqrt(SimulatedX*SimulatedX+SimulatedY*SimulatedY)if not HoldingCtrl and m()==0 then if userControlScheme=="virtual joystick"then if SimulatedX>0 and SimulatedX>DeadZone then YawInput2=YawInput2-(SimulatedX-DeadZone)*MouseXSensitivity elseif SimulatedX<0 and SimulatedX0 and SimulatedY>DeadZone then PitchInput2=PitchInput2-(SimulatedY-DeadZone)*MouseYSensitivity elseif SimulatedY<0 and SimulatedYDeadZone then DrawCursorLine(as)end else SetButtonContains()DrawButtons(as)end;as[#as+1]=c([[]],SimulatedX,SimulatedY)end;as[#as+1]=[[]]content=table.concat(as,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end;if ProgradeIsOn then if velMag>MinAutopilotSpeed then local g0=AlignToWorldVector(vec3(velocity),0.01)if SpaceLand then autoRoll=true;if g0 then ProgradeIsOn=false;ReentryMode=true;BeginReentry()SpaceLand=false;FinalLand=true;autoRoll=autoRollPreference end end end end;if RetrogradeIsOn then if InAtmo then RetrogradeIsOn=false elseif velMag>MinAutopilotSpeed then AlignToWorldVector(-vec3(velocity))end end;if not ProgradeIsOn and SpaceLand then if g()==0 then ReentryMode=true;BeginReentry()SpaceLand=false;FinalLand=true else SpaceLand=false;ToggleAutopilot()end end;if FinalLand and CoreAltitudeReentrySpeed-100 then ToggleAutopilot()FinalLand=false end;if Autopilot and g()==0 then local fx,fy;if not TurnBurn then fx,fy=GetAutopilotBrakeDistanceAndTime(velMag)else fx,fy=GetAutopilotTBBrakeDistanceAndTime(velMag)end;fx=fx;fy=fy;local g1=AutopilotTargetCoords;if orbit.apoapsis==nil and velMag>300 and AutopilotAccelerating then local g2=(vec3(AutopilotTargetCoords)-vec3(core.getConstructWorldPos())):normalize()-vec3(velocity):normalize()local g3=getMagnitudeInDirection(g2,AutopilotShipUp)local g4=getMagnitudeInDirection(g2,AutopilotShipRight)local g5=-g4*AutopilotDistance*velMag*TrajectoryAlignmentStrength;local g6=-g3*AutopilotDistance*velMag*TrajectoryAlignmentStrength;g1=AutopilotTargetCoords+-g5*vec3(AutopilotShipRight)+-g6*vec3(AutopilotShipUp)end;AutopilotDistance=(vec3(g1)-vec3(core.getConstructWorldPos())):len()local g7=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()system.updateData(widgetDistanceText,'{"label": "Distance", "value": "'..getDistanceDisplayString(g7)..'", "unit":""}')local g8=true;local g9=(AutopilotTargetPlanet.center-(vec3(core.getConstructWorldPos())+vec3(velocity):normalize()*AutopilotDistance)):len()-AutopilotTargetPlanet.radius;system.updateData(widgetTrajectoryAltitudeText,'{"label": "Projected Altitude", "value": "'..getDistanceDisplayString(g9)..'", "unit":""}')if not AutopilotCruising and not AutopilotBraking then g8=AlignToWorldVector((g1-vec3(core.getConstructWorldPos())):normalize())elseif TurnBurn then g8=AlignToWorldVector(-vec3(velocity):normalize())end;if AutopilotAccelerating then if not g8 or BrakeIsOn then AutopilotStatus="Adjusting Trajectory"else AutopilotStatus="Accelerating"end;if vec3(core.getConstructWorldOrientationForward()):dot(velocity)<0 and velMag>300 then BrakeIsOn=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false elseif not APThrottleSet then BrakeIsOn=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)APThrottleSet=true end;if vec3(core.getVelocity()):len()>=MaxGameVelocity and math.abs(g9-AutopilotTargetOrbit)<1000 or unit.getThrottle()==0 and APThrottleSet then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false end;if AutopilotDistance<=fx then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false end elseif AutopilotBraking then BrakeIsOn=true;BrakeInput=1;if TurnBurn then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,100)end;if orbit.periapsis~=nil and orbit.eccentricity<1 then AutopilotStatus="Circularizing"if orbit.eccentricity>LastEccentricity or orbit.apoapsis.altitude0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if g8 then if not AutopilotRealigned then AutopilotTargetCoords=vec3(AutopilotTargetPlanet.center)+(AutopilotTargetOrbit+AutopilotTargetPlanet.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotRealigned=true;AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()elseif g8 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not APThrottleSet then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)APThrottleSet=true;BrakeIsOn=false end end end end end;if FollowMode then autoRoll=true;local ga=0;local bI=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local gb=bI-vec3(core.getConstructWorldPos())local gc=vec3(gb):project_on(vec3(core.getConstructWorldOrientationForward())):len()local gd=vec3(gb):project_on(vec3(core.getConstructWorldOrientationRight())):len()local cK=math.sqrt(gc*gc+gd*gd)AlignToWorldVector(gb:normalize())local ge=40;local gf=cKgi then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(ga-ay)local gj=pitchPID:get()PitchInput2=gj end end;local c1=vec3(core.getWorldVertical())*-1;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget or LockPitch~=nil then local bH=unit.getClosestPlanetInfluence()>0;local bu=CoreAltitude;local gk=HoldAltitude-bu;local gl=500+velMag;local ga=(utils.smoothstep(gk,-gl,gl)-0.5)*2*MaxPitch;if not AltitudeHold then ga=0 end;if LockPitch~=nil then if bH then ga=LockPitch else LockPitch=nil end end;autoRoll=true;if Reentry then local gm=ReentrySpeed;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=gm then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,gm)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if not ReentryMode then ga=-80;if g()>0.02 then MsgText="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;ga=0;autoRoll=autoRollPreference end elseif Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==ReentrySpeed then ReentryMode=false;Reentry=false;autoRoll=autoRollPreference end end;local gn=PitchInput2;if velMag>MinAutopilotSpeed then AlignToWorldVector(vec3(velocity))end;if VectorToTarget and CustomTarget~=nil and AutopilotTargetIndex>0 then local bl=CustomTarget.position-vec3(core.getConstructWorldPos())AlignToWorldVector(bl)local go=bl:len()-bl:project_on(c1):len()local aa=LastMaxBrakeInAtmo;local b_=velocity.x*c1.x+velocity.y*c1.y+velocity.z*c1.z;local gp=velocity:len()-math.abs(b_)local gq=vec3(core.getWorldAirFrictionAcceleration())if aa~=nil then BrakeDistance,BrakeTime=Kinematic.computeDistanceAndTime(gp,0,l(),0,0,aa+(gq:len()-gq:project_on(c1):len())*l())else BrakeDistance,BrakeTime=Kinematic.computeDistanceAndTime(gp,0,l(),0,0,LastMaxBrake+vec3(core.getWorldAirFrictionAcceleration()):len()*l())end;StrongBrakes=planet.gravity*9.80665*l()LastTargetDistance and not AltitudeHold and not AutoTakeoff then BrakeLanding=true;VectorToTarget=false end;LastTargetDistance=go end;PitchInput2=gn;local av=vec3(core.getConstructWorldOrientationForward())local aw=vec3(core.getConstructWorldOrientationRight())local ax=vec3(core.getWorldVertical())local fD=-1;local ay=getPitch(ax,av,aw)local gi=0.1;if BrakeLanding then ga=0;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)local b_=velocity.x*c1.x+velocity.y*c1.y+velocity.z*c1.z;fD=HovGndDet;if fD>-1 then if math.abs(ga-ay)50000 then if Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=5000 then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,5000)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end end end;if math.abs(ga-ay)>gi then if pitchPID==nil then pitchPID=pid.new(8*0.01,0,8*0.1)end;pitchPID:inject(ga-ay)local gj=pitchPID:get()PitchInput2=PitchInput2+gj end end;LastEccentricity=orbit.eccentricity;if antigrav and not ExternalAGG and CoreAltitude<200000 then if antigrav.getState()==1 then if AntigravTargetAltitude==nil then AntigravTargetAltitude=1000 end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end else if AntigravTargetAltitude==nil then desiredBaseAltitude=CoreAltitude else desiredBaseAltitude=AntigravTargetAltitude end;if antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(desiredBaseAltitude)end end end end end;function script.onFlush()local gr=2;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)gr=math.max(gr,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 gs=utils.clamp(PitchInput+PitchInput2+system.getControlDeviceForwardInput(),-1,1)local gt=utils.clamp(RollInput+RollInput2+system.getControlDeviceYawInput(),-1,1)local gu=utils.clamp(YawInput+YawInput2-system.getControlDeviceLeftRightInput(),-1,1)local gv=BrakeInput;local gw=vec3(core.getWorldVertical())local gx=vec3(core.getConstructWorldOrientationUp())local gy=vec3(core.getConstructWorldOrientationForward())local gz=vec3(core.getConstructWorldOrientationRight())local gA=vec3(core.getWorldVelocity())local gB=vec3(core.getWorldVelocity()):normalize()local gC=getRoll(gw,gy,gz)local gD=math.abs(gC)local gE=utils.sign(gC)local g=g()local gF=vec3(core.getWorldAngularVelocity())local gG=gs*pitchSpeedFactor*gz+gt*rollSpeedFactor*gy+gu*yawSpeedFactor*gx;if gw:len()>0.01 and g>0.0 or ProgradeIsOn then local gH=1.0;if autoRoll==true and gD>gH and gt==0 then local gI=utils.clamp(0,gD-30,gD+30)if rollPID==nil then rollPID=pid.new(autoRollFactor*0.01,0,autoRollFactor*0.1)end;rollPID:inject(gI-gC)local gJ=rollPID:get()gG=gG+gJ*gy end end;if gw:len()>0.01 and g>0.0 then local gK=20.0;if turnAssist==true and gD>gK and gs==0 and gu==0 then local gL=turnAssistFactor*0.1;local gM=turnAssistFactor*0.025;local gN=(gD-gK)/(180-gK)*180;local gO=0;if gN<90 then gO=gN/90 elseif gN<180 then gO=(180-gN)/90 end;gO=gO*gO;local gP=-gE*gM*(1.0-gO)local gQ=gL*gO;gG=gG+gQ*gz+gP*gx end end;local gR=1;local gS=0;local gT=1;local gU=gr*(gG-gF)local gV=vec3(core.getWorldAirFrictionAngularAcceleration())gU=gU-gV;Nav:setEngineTorqueCommand('torque',gU,gR,'airfoil','','',gT)local gW=-gv*(brakeSpeedFactor*gA+brakeFlatFactor*gB)Nav:setEngineForceCommand('brake',gW)local gX=''local gY=vec3()local gZ=false;local g_='thrust analog longitudinal'local h0=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if h0==axisCommandType.byThrottle then local h1=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(g_,axisCommandId.longitudinal)Nav:setEngineForceCommand(g_,h1,gR)elseif h0==axisCommandType.byTargetSpeed then local h1=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)gX=gX..' , '..g_;gY=gY+h1;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then gZ=true end end;local h2='thrust analog lateral'local h3=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if h3==axisCommandType.byThrottle then local h4=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(h2,axisCommandId.lateral)Nav:setEngineForceCommand(h2,h4,gR)elseif h3==axisCommandType.byTargetSpeed then local h5=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)gX=gX..' , '..h2;gY=gY+h5 end;local h6='thrust analog vertical'local h7=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if h7==axisCommandType.byThrottle then local h8=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(h6,axisCommandId.vertical)if UpAmount~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(h6,h8,gR,'airfoil','ground','',gT)else Nav:setEngineForceCommand(h6,vec3(),gR)Nav:setEngineForceCommand('airfoil vertical',h8,gR,'airfoil','','',gT)Nav:setEngineForceCommand('ground vertical',h8,gR,'ground','','',gT)end elseif h7==axisCommandType.byTargetSpeed then if UpAmount==0 then Nav:setEngineForceCommand('hover',vec3(),gR)end;local h9=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)gX=gX..' , '..h6;gY=gY+h9 end;if gY:len()>constants.epsilon then if BrakeInput~=0 or gZ or math.abs(gB:dot(gy))<0.95 then gX=gX..', brake'end;Nav:setEngineForceCommand(gX,gY,gS,'','','',gT)end;Nav:setBoosterCommand('rocket_engine')if IsBoosting then local a9=vec3(core.getVelocity()):len()local ha=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local hb=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if a9*3.6>hb*(1-ha)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif a9*3.6=gh*(1-ha)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif a9=gh*(1-ha)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif a90 or CoreAltitudeMinAutopilotSpeed then MsgText="WARNING: Insufficient Brakes - Attempting landing anyway"end;Reentry=false;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=true;autoRoll=true;GearExtended=false else BrakeIsOn=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end else Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end elseif hd=="light"then if Nav.control.isAnyHeadlightSwitchedOn()==1 then Nav.control.switchOffHeadlights()else Nav.control.switchOnHeadlights()end elseif hd=="forward"then PitchInput=PitchInput-1 elseif hd=="backward"then PitchInput=PitchInput+1 elseif hd=="left"then RollInput=RollInput-1 elseif hd=="right"then RollInput=RollInput+1 elseif hd=="yawright"then YawInput=YawInput-1 elseif hd=="yawleft"then YawInput=YawInput+1 elseif hd=="straferight"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,1.0)elseif hd=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,-1.0)elseif hd=="up"then UpAmount=UpAmount+1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,1.0)elseif hd=="down"then UpAmount=UpAmount-1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,-1.0)elseif hd=="groundaltitudeup"then OldButtonMod=HoldAltitudeButtonModifier;OldAntiMod=AntiGravButtonModifier;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude+AntiGravButtonModifier else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+HoldAltitudeButtonModifier else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif hd=="groundaltitudedown"then OldButtonMod=HoldAltitudeButtonModifier;OldAntiMod=AntiGravButtonModifier;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude-AntiGravButtonModifier;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-HoldAltitudeButtonModifier else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif hd=="option1"then IncrementAutopilotTargetIndex()ToggleView=false elseif hd=="option2"then DecrementAutopilotTargetIndex()ToggleView=false elseif hd=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;ToggleView=false;ToggleWidgets()elseif hd=="option4"then ToggleAutopilot()ToggleView=false elseif hd=="option5"then ToggleLockPitch()ToggleView=false elseif hd=="option6"then ToggleAltitudeHold()ToggleView=false elseif hd=="option7"then wipeSaveVariables()ToggleView=false elseif hd=="option8"then ToggleFollowMode()ToggleView=false elseif hd=="option9"then if gyro~=nil then gyro.toggle()GyroIsOn=gyro.getState()==1 end;ToggleView=false elseif hd=="lshift"then if system.isViewLocked()==1 then HoldingCtrl=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif m()==1 and ShiftShowsRemoteButtons then HoldingCtrl=true;Animated=false;Animating=false end elseif hd=="brake"then if brakeToggle then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif hd=="lalt"then if m()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif hd=="booster"then if not IsBoosting then if not IsRocketOn then Nav:toggleBoosters()IsRocketOn=true end;IsBoosting=true else if IsRocketOn then Nav:toggleBoosters()IsRocketOn=false end;IsBoosting=false end elseif hd=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)clearAll()elseif hd=="speedup"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)else IncrementAutopilotTargetIndex()end elseif hd=="speeddown"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)else DecrementAutopilotTargetIndex()end elseif hd=="antigravity"and not ExternalAGG then if antigrav~=nil then ToggleAntigrav()end elseif hd=="warp"then if warpdrive~=nil then if showWarpWidget then warpdrive.hide()showWarpWidget=false else warpdrive.show()showWarpWidget=true end;if d(warpdrive.getData()).buttonMsg=="CANNOT WARP"then MsgText=d(warpdrive.getData()).errorMsg else warpdrive.activateWarp()warpdrive.show()showWarpWidget=true end end end end;function script.onActionStop(hd)if hd=="forward"then PitchInput=0 elseif hd=="backward"then PitchInput=0 elseif hd=="left"then RollInput=0 elseif hd=="right"then RollInput=0 elseif hd=="yawright"then YawInput=0 elseif hd=="yawleft"then YawInput=0 elseif hd=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)elseif hd=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)elseif hd=="up"then UpAmount=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif hd=="down"then UpAmount=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif hd=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then AntiGravButtonModifier=OldAntiMod elseif AltitudeHold then HoldAltitudeButtonModifier=OldButtonMod end;ToggleView=false elseif hd=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then AntiGravButtonModifier=OldAntiMod elseif AltitudeHold then HoldAltitudeButtonModifier=OldButtonMod end;ToggleView=false elseif hd=="lshift"then if system.isViewLocked()==1 then HoldingCtrl=false;SimulatedX=0;SimulatedY=0;system.lockView(PrevViewLock)elseif m()==1 and ShiftShowsRemoteButtons then HoldingCtrl=false;Animated=false;Animating=false end elseif hd=="brake"then if not brakeToggle then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif hd=="lalt"then if m()==0 and freeLookToggle then if ToggleView then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else ToggleView=true end elseif m()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end end end;function script.onActionLoop(hd)if hd=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude+AntiGravButtonModifier;AntiGravButtonModifier=AntiGravButtonModifier*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+HoldAltitudeButtonModifier;HoldAltitudeButtonModifier=HoldAltitudeButtonModifier*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif hd=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude-AntiGravButtonModifier;AntiGravButtonModifier=AntiGravButtonModifier*1.05;BrakeIsOn=false;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-HoldAltitudeButtonModifier;HoldAltitudeButtonModifier=HoldAltitudeButtonModifier*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif hd=="speedup"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end elseif hd=="speeddown"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end;function DisplayMessage(as,he)if he~="empty"then as[#as+1]=[[]]for hf in string.gmatch(he,"([^\n]+)")do as[#as+1]=c([[%s]],hf)end;as[#as+1]=[[]]end;if MsgTimer~=0 then unit.setTimer("msgTick",MsgTimer)MsgTimer=0 end end;function updateDistance()local a3=system.getTime()local velocity=vec3(core.getWorldVelocity())local bE=vec3(velocity):len()local hg=a3-LastTravelTime;if bE>1.38889 then bE=bE/1000;local hh=bE*(a3-LastTravelTime)TotalDistanceTravelled=TotalDistanceTravelled+hh;TotalDistanceTrip=TotalDistanceTrip+hh end;FlightTime=FlightTime+hg;TotalFlightTime=TotalFlightTime+hg;LastTravelTime=a3 end;script.onStart() + ]],bh,af,ag+cB,cy,af,ag+cC,cx))ar=ar+1;co=co*10;if cx==cr then cp=cz else cp=0 end end;table.insert(as,[[]])end end;function DrawPrograde(as,velocity,a9,centerX,centerY)if a9>5 and not InAtmo or a9>MinAutopilotSpeed then local c4=circleRad;local cD=20;local cE=20;local cF=vec3(velocity)local cG=getRelativePitch(cF)local cH=getRelativeYaw(cF)local cI=-cH/cE*c4;local cJ=cG/cD*c4;local af=centerX+cI;local ag=centerY+cJ;local cK=math.sqrt(cI^2+cJ^2)if cK',af,ag)else local c0=math.atan(cJ,cI)local cL=centerX+c4*math.cos(c0)local cM=centerY+c4*math.sin(c0)as[#as+1]=c('',cL,cM)end;cG=getRelativePitch(-cF)cH=getRelativeYaw(-cF)cI=-cH/cE*c4;cJ=cG/cD*c4;af=centerX+cI;ag=centerY+cJ;cK=math.sqrt(cI^2+cJ^2)if not InAtmo then if cK',af,ag)else local c0=math.atan(cJ,cI)local cL=centerX+c4*math.cos(c0)local cM=centerY+c4*math.sin(c0)as[#as+1]=c('',cL,cM)end end end end;function DrawWarnings(as)as[#as+1]=c([[DU Hud Version: %.3f]],VERSION_NUMBER)as[#as+1]=[[]]if unit.isMouseControlActivated()==1 then as[#as+1]=[[Warning: Invalid Control Scheme Detected]]as[#as+1]=[[Keyboard Scheme must be selected]]as[#as+1]=[[Set your preferred scheme in Lua Parameters instead]]end;local cN=960;local cO=860;local cP=880;local cQ=900;local cR=960;local cS=200;local cT=150;local cU=960;if m()==1 and not RemoteHud then cO=135;cP=155;cQ=175;cS=115;cT=95 end;if BrakeIsOn then as[#as+1]=c([[Brake Engaged]],cN,cO)end;if InAtmo and RateOfChangebrakeLandingRate+5 then as[#as+1]=c([[** STALL WARNING **]],cN,cS+50)end;if GyroIsOn then as[#as+1]=c([[Gyro Enabled]],cN,cU)end;if GearExtended then if HasGear then as[#as+1]=c([[Gear Extended]],cN,cP)else as[#as+1]=c([[Landed (G: Takeoff)]],cN,cP)end;as[#as+1]=c([[Hover Height: %s]],cN,cQ,getDistanceDisplayString(Nav:getTargetGroundAltitude()))end;if EmergencyWarp then as[#as+1]=c([[E-WARP ENGAGED]],cN,cR)end;if IsBoosting then as[#as+1]=c([[ROCKET BOOST ENABLED]],cN,cR+20)end;if antigrav and not ExternalAGG and antigrav.getState()==1 and AntigravTargetAltitude~=nil then if math.abs(CoreAltitude-antigrav.getBaseAltitude())<501 then as[#as+1]=c([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],cN,cS+20,b(AntigravTargetAltitude),b(antigrav.getBaseAltitude()))else as[#as+1]=c([[AGG On - Target Altitude: %d Singluarity Altitude: %d]],cN,cS+20,b(AntigravTargetAltitude),b(antigrav.getBaseAltitude()))end elseif Autopilot and AutopilotTargetName~="None"then as[#as+1]=c([[Autopilot %s]],cN,cS,AutopilotStatus)elseif LockPitch~=nil then as[#as+1]=c([[LockedPitch: %d]],cN,cS,b(LockPitch))elseif FollowMode then as[#as+1]=c([[Follow Mode Engaged]],cN,cS)elseif AltitudeHold then if AutoTakeoff then as[#as+1]=c([[Ascent to %s]],cN,cS,getDistanceDisplayString(HoldAltitude))if BrakeIsOn then as[#as+1]=c([[Throttle Up and Disengage Brake For Takeoff]],cN,cS+50)end else as[#as+1]=c([[Altitude Hold: %s]],cN,cS,getDistanceDisplayString2(HoldAltitude))end elseif Reentry then as[#as+1]=c([[Parachute Re-entry in Progress]],cN,cS)end;if BrakeLanding then if StrongBrakes then as[#as+1]=c([[Brake-Landing]],cN,cS)else as[#as+1]=c([[Coast-Landing]],cN,cS)end end;if ProgradeIsOn then as[#as+1]=c([[Prograde Alignment]],cN,cS)end;if RetrogradeIsOn then as[#as+1]=c([[Retrograde Alignment]],cN,cS)end;if TurnBurn then as[#as+1]=c([[Turn & Burn Braking]],cN,cT)end;if VectorToTarget then as[#as+1]=c([[%s]],cN,cS+30,VectorStatus)end;as[#as+1]=""end;function DisplayOrbitScreen(as)if orbit~=nil and g()<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 cV=75;local cW=0;local cX=250;local cY=4;cW=cW+cY;local cZ=15;local af=cV+cX+cV/2+cY;local ag=cW+cX/2+5+cY;local c_,d0,d1,d2;c_=cX/4;d2=0;as[#as+1]=[[]]as[#as+1]=c('',cX+cV*2,cX+cW,cY,cY)if orbit.periapsis~=nil and orbit.apoapsis~=nil then d1=(orbit.apoapsis.altitude+orbit.periapsis.altitude+planet.radius*2)/(c_*2)d0=(planet.radius+orbit.periapsis.altitude+(orbit.apoapsis.altitude-orbit.periapsis.altitude)/2)/d1*(1-orbit.eccentricity)d2=c_-orbit.periapsis.altitude/d1-planet.radius/d1;local d3=""if orbit.periapsis.altitude<=0 then d3='redout'end;as[#as+1]=c([[]],d3,cV+cX/2+d2+cY,cW+cX/2+cY,c_,d0)as[#as+1]=c('',cV+cX/2+cY,cW+cX/2+cY,planet.radius/d1)end;if orbit.apoapsis~=nil and orbit.apoapsis.speed1 then as[#as+1]=c([[]],af-35,ag-5,cV+cX/2+c_+d2,ag-5)as[#as+1]=c([[Apoapsis]],af,ag)ag=ag+cZ;as[#as+1]=c([[%s]],af,ag,getDistanceDisplayString(orbit.apoapsis.altitude))ag=ag+cZ;as[#as+1]=c([[%s]],af,ag,FormatTimeString(orbit.timeToApoapsis))ag=ag+cZ;as[#as+1]=c([[%s]],af,ag,getSpeedDisplayString(orbit.apoapsis.speed))end;ag=cW+cX/2+5+cY;af=cV-cV/2+10+cY;if orbit.periapsis~=nil and orbit.periapsis.speed1 then as[#as+1]=c([[]],af+35,ag-5,cV+cX/2-c_+d2,ag-5)as[#as+1]=c([[Periapsis]],af,ag)ag=ag+cZ;as[#as+1]=c([[%s]],af,ag,getDistanceDisplayString(orbit.periapsis.altitude))ag=ag+cZ;as[#as+1]=c([[%s]],af,ag,FormatTimeString(orbit.timeToPeriapsis))ag=ag+cZ;as[#as+1]=c([[%s]],af,ag,getSpeedDisplayString(orbit.periapsis.speed))end;as[#as+1]=c([[%s]],cV+cX/2+cY,20+cY,planet.name)if orbit.period~=nil and orbit.periapsis~=nil and orbit.apoapsis~=nil and orbit.apoapsis.speed>1 then local d4=orbit.timeToApoapsis/orbit.period*2*math.pi;local d5=c_*math.cos(d4)local d6=d0*math.sin(d4)as[#as+1]=c('',cV+cX/2+d5+d2+cY,cW+cX/2+d6+cY)end;as[#as+1]=[[]]end end;function Atlas()return{[0]={[1]={GM=6930729684,bodyId=1,center={x=17465536.000,y=22665536.000,z=-34464.000},name='Madis',planetarySystemId=0,radius=44300,atmos=true,gravity=0.36},[2]={GM=157470826617,bodyId=2,center={x=-8.000,y=-8.000,z=-126303.000},name='Alioth',planetarySystemId=0,radius=126068,atmos=true,gravity=1.01},[3]={GM=11776905000,bodyId=3,center={x=29165536.000,y=10865536.000,z=65536.000},name='Thades',planetarySystemId=0,radius=49000,atmos=true,gravity=0.50},[4]={GM=14893847582,bodyId=4,center={x=-13234464.000,y=55765536.000,z=465536.000},name='Talemai',planetarySystemId=0,radius=57450,atmos=true,gravity=0.46},[5]={GM=16951680000,bodyId=5,center={x=-43534464.000,y=22565536.000,z=-48934464.000},name='Feli',planetarySystemId=0,radius=60000,atmos=true,gravity=0.48},[6]={GM=10502547741,bodyId=6,center={x=52765536.000,y=27165538.000,z=52065535.000},name='Sicari',planetarySystemId=0,radius=51100,atmos=true,gravity=0.41},[7]={GM=13033380591,bodyId=7,center={x=58665538.000,y=29665535.000,z=58165535.000},name='Sinnen',planetarySystemId=0,radius=54950,atmos=true,gravity=0.44},[8]={GM=18477723600,bodyId=8,center={x=80865538.000,y=54665536.000,z=-934463.940},name='Teoma',planetarySystemId=0,radius=62000,atmos=true,gravity=0.49},[9]={GM=18606274330,bodyId=9,center={x=-94134462.000,y=12765534.000,z=-3634464.000},name='Jago',planetarySystemId=0,radius=61590,atmos=true,gravity=0.50},[10]={GM=78480000,bodyId=10,center={x=17448118.224,y=22966846.286,z=143078.820},name='Madis Moon 1',planetarySystemId=0,radius=10000,atmos=false,gravity=0.08},[11]={GM=237402000,bodyId=11,center={x=17194626.000,y=22243633.880,z=-214962.810},name='Madis Moon 2',planetarySystemId=0,radius=11000,atmos=false,gravity=0.10},[12]={GM=265046609,bodyId=12,center={x=17520614.000,y=22184730.000,z=-309989.990},name='Madis Moon 3',planetarySystemId=0,radius=15005,atmos=false,gravity=0.12},[21]={GM=2118960000,bodyId=21,center={x=457933.000,y=-1509011.000,z=115524.000},name='Alioth Moon 1',planetarySystemId=0,radius=30000,atmos=false,gravity=0.24},[22]={GM=2165833514,bodyId=22,center={x=-1692694.000,y=729681.000,z=-411464.000},name='Alioth Moon 4',planetarySystemId=0,radius=30330,atmos=false,gravity=0.24},[26]={GM=68234043600,bodyId=26,center={x=-1404835.000,y=562655.000,z=-285074.000},name='Sanctuary',planetarySystemId=0,radius=83400,atmos=true,gravity=1.00},[30]={GM=211564034,bodyId=30,center={x=29214402.000,y=10907080.695,z=433858.200},name='Thades Moon 1',planetarySystemId=0,radius=14002,atmos=false,gravity=0.11},[31]={GM=264870000,bodyId=31,center={x=29404193.000,y=10432768.000,z=19554.131},name='Thades Moon 2',planetarySystemId=0,radius=15000,atmos=false,gravity=0.12},[40]={GM=141264000,bodyId=40,center={x=-13503090.000,y=55594325.000,z=769838.640},name='Talemai Moon 2',planetarySystemId=0,radius=12000,atmos=false,gravity=0.10},[41]={GM=106830900,bodyId=41,center={x=-12800515.000,y=55700259.000,z=325207.840},name='Talemai Moon 3',planetarySystemId=0,radius=11000,atmos=false,gravity=0.09},[42]={GM=264870000,bodyId=42,center={x=-13058408.000,y=55781856.000,z=740177.760},name='Talemai Moon 1',planetarySystemId=0,radius=15000,atmos=false,gravity=0.12},[50]={GM=499917600,bodyId=50,center={x=-43902841.780,y=22261034.700,z=-48862386.000},name='Feli Moon 1',planetarySystemId=0,radius=14000,atmos=false,gravity=0.11},[70]={GM=396912600,bodyId=70,center={x=58969616.000,y=29797945.000,z=57969449.000},name='Sinnen Moon 1',planetarySystemId=0,radius=17000,atmos=false,gravity=0.14},[100]={GM=13975172474,bodyId=100,center={x=98865536.000,y=-13534464.000,z=-934461.990},name='Lacobus',planetarySystemId=0,radius=55650,atmos=true,gravity=0.46},[101]={GM=264870000,bodyId=101,center={x=98905288.170,y=-13950921.100,z=-647589.530},name='Lacobus Moon 3',planetarySystemId=0,radius=15000,atmos=false,gravity=0.12},[102]={GM=444981600,bodyId=102,center={x=99180968.000,y=-13783862.000,z=-926156.400},name='Lacobus Moon 1',planetarySystemId=0,radius=18000,atmos=false,gravity=0.14},[103]={GM=211503600,bodyId=103,center={x=99250052.000,y=-13629215.000,z=-1059341.400},name='Lacobus Moon 2',planetarySystemId=0,radius=14000,atmos=false,gravity=0.11},[110]={GM=9204742375,bodyId=110,center={x=14165536.000,y=-85634465.000,z=-934464.300},name='Symeon',planetarySystemId=0,radius=49050,atmos=true,gravity=0.39},[120]={GM=7135606629,bodyId=120,center={x=2865536.700,y=-99034464.000,z=-934462.020},name='Ion',planetarySystemId=0,radius=44950,atmos=true,gravity=0.36},[121]={GM=106830900,bodyId=121,center={x=2472916.800,y=-99133747.000,z=-1133582.800},name='Ion Moon 1',planetarySystemId=0,radius=11000,atmos=false,gravity=0.09},[122]={GM=176580000,bodyId=122,center={x=2995424.500,y=-99275010.000,z=-1378480.700},name='Ion Moon 2',planetarySystemId=0,radius=15000,atmos=false,gravity=0.12}}}end;atlas=Atlas()for V,W in pairs(atlas[0])do if x==nil or W.center.xy then y=W.center.x end;if z==nil or W.center.yA then A=W.center.y end end;GalaxyMapHTML=""local d7=1.1*(y-x)/1920;local d8=1.4*(A-z)/1080;for V,W in pairs(atlas[0])do local af=960+W.center.x/d7;local ag=540+W.center.y/d8;GalaxyMapHTML=GalaxyMapHTML..''if not string.match(W.name,"Moon")and not string.match(W.name,"Sanctuary")then GalaxyMapHTML=GalaxyMapHTML..""..W.name..""end end;local bI=vec3(core.getConstructWorldPos())local af=960+bI.x/d7;local ag=540+bI.y/d8;GalaxyMapHTML=GalaxyMapHTML..''GalaxyMapHTML=GalaxyMapHTML.."You Are Here"GalaxyMapHTML=GalaxyMapHTML..[[]]MapXRatio=d7;MapYRatio=d8;if screen_2 then screen_2.setHTML(''..GalaxyMapHTML)local bI=vec3(core.getConstructWorldPos())local af=960+bI.x/d7;local ag=540+bI.y/d8;GalaxyMapHTML=''GalaxyMapHTML=GalaxyMapHTML.."You Are Here"YouAreHere=screen_2.addContent((af-80)/19.20,(ag-80)/10.80,GalaxyMapHTML)end;function PlanetRef()local function d9(da)return type(da)=='number'end;local function db(da)return type(tonumber(da))=='number'end;local function dc(dd)return type(dd)=='table'end;local function de(df)return type(df)=='string'end;local function dg(W)return dc(W)and d9(W.x and W.y and W.z)end;local function dh(di)return dc(di)and d9(di.latitude and di.longitude and di.altitude and di.bodyId and di.systemId)end;local dj=math.pi/180;local dk=180/math.pi;local dl=1e-10;local ce=' *([+-]?%d+%.?%d*e?[+-]?%d*)'local dm='::pos{'..ce..','..ce..','..ce..','..ce..','..ce..'}'local utils=require('cpml.utils')local vec3=require('cpml.vec3')local dn=utils.clamp;local function dp(dq,dr)if dq==0 then return math.abs(dr)<1e-09 end;if dr==0 then return math.abs(dq)<1e-09 end;return math.abs(dq-dr)=0 then local en=math.sqrt(em)local eo=el+en;local ep=el-en;if ep>0 then return ec,eo,ep elseif eo>0 then return ec,eo,nil end end end;return nil,nil,nil end;function dO:closestBody(eq)assert(type(eq)=='table','Invalid coordinates.')local er,ec;local es=vec3(eq)for _,et in pairs(self)do local eu=(et.center-es):len2()if not ec or eu=0 and ey or 2*math.pi+ey;dM=math.pi/2-math.acos(ex.z/cK)end;return setmetatable({latitude=dM,longitude=dN,altitude=bu,bodyId=self.bodyId,systemId=self.planetarySystemId},dI)end;function dx:convertToWorldCoordinates(dL)local ev=de(dL)and dK(dL)or dL;if ev.bodyId==0 then return vec3(ev.latitude,ev.longitude,ev.altitude)end;assert(dh(ev),'Argument 1 (mapPosition) is not an instance of "MapPosition".')assert(ev.systemId==self.planetarySystemId,'Argument 1 (mapPosition) has a different planetary system ID.')assert(ev.bodyId==self.bodyId,'Argument 1 (mapPosition) has a different planetary body ID.')local ez=math.cos(ev.latitude)return self.center+(self.radius+ev.altitude)*vec3(ez*math.cos(ev.longitude),ez*math.sin(ev.longitude),math.sin(ev.latitude))end;function dx:getAltitude(dG)return(vec3(dG)-self.center):len()-self.radius end;function dx:getDistance(dG)return(vec3(dG)-self.center):len()end;function dx:getGravity(dG)local eA=self.center-vec3(dG)local eB=eA:len2()return self.GM/eB*eA/math.sqrt(eB)end;return setmetatable(PlanetaryReference,{__call=function(_,...)return dW(...)end})end;function Keplers()local vec3=require('cpml.vec3')local PlanetRef=PlanetRef()local function de(df)return type(df)=='string'end;local function dc(dd)return type(dd)=='table'end;local function dp(dq,dr)if dq==0 then return math.abs(dr)<1e-09 end;if dr==0 then return math.abs(dq)<1e-09 end;return math.abs(dq-dr)0 then eS=eR;eT=eS+eM/2 end;if eT>eM then eT=eT-eM end end;return{periapsis={position=eJ,speed=eL/eH,circularOrbitSpeed=math.sqrt(eE/eH),altitude=eH-self.body.radius},apoapsis=eK and{position=eK,speed=eL/eI,circularOrbitSpeed=math.sqrt(eE/eI),altitude=eI-self.body.radius},currentVelocity=W,currentPosition=bI,eccentricity=eG,period=eM,eccentricAnomaly=eO,meanAnomaly=eQ,timeToPeriapsis=eS,timeToApoapsis=eT}end;local function eU(eV)local et=PlanetRef.BodyParameters(eV.planetarySystemId,eV.bodyId,eV.radius,eV.center,eV.GM)return setmetatable({body=et},Kepler)end;return setmetatable(Kepler,{__call=function(_,...)return eU(...)end})end;function Kinematics()local Kinematic={}local eW=30000000/3600;local eX=eW*eW;local eY=100;local function eZ(W)return 1/math.sqrt(1-W*W/eX)end;function Kinematic.computeAccelerationTime(e_,f0,f1)local f2=eW*math.asin(e_/eW)return(eW*math.asin(f1/eW)-f2)/f0 end;function Kinematic.computeDistanceAndTime(e_,f1,f3,f4,f5,f6)f5=f5 or 0;f6=f6 or 0;local f7=e_<=f1;local f8=f4*(f7 and 1 or-1)/f3;local f9=-f6/f3;local fa=f8+f9;if f7 and fa<=0 or not f7 and fa>=0 then return-1,-1 end;local fb,fc=0,0;if f8~=0 and f5>0 then local f2=math.asin(e_/eW)local fd=math.pi*(f8/2+f9)local fe=f8*f5;local ff=eW*math.pi;local W=function(dd)local aO=(fd*dd-fe*math.sin(math.pi*dd/2/f5)+ff*f2)/ff;local fg=math.tan(aO)return eW*fg/math.sqrt(fg*fg+1)end;local fh=f7 and function(df)return df>=f1 end or function(df)return df<=f1 end;fc=2*f5;if fh(W(fc))then local fi=0;while math.abs(fc-fi)>0.5 do local dd=(fc+fi)/2;if fh(W(dd))then fc=dd else fi=dd end end end;local fj=e_;local fk=fc/eY;for fl=1,eY do local a9=W(fl*fk)fb=fb+(a9+fj)*fk/2;fj=a9 end;if fc<2*f5 then return fb,fc end;e_=fj end;local f2=eW*math.asin(e_/eW)local Y=(eW*math.asin(f1/eW)-f2)/fa;local fm=eX*math.cos(f2/eW)/fa;local cK=fm-eX*math.cos((fa*Y+f2)/eW)/fa;return cK+fb,Y+fc end;function Kinematic.computeTravelTime(e_,f0,cK)if cK==0 then return 0 end;if f0>0 then local f2=eW*math.asin(e_/eW)local fm=eX*math.cos(f2/eW)/f0;return(eW*math.acos(f0*(fm-cK)/eX)-f2)/f0 end;assert(e_>0,'Acceleration and initial speed are both zero.')return cK/e_ end;function Kinematic.lorentz(W)return eZ(W)end;return Kinematic end;PlanetaryReference=PlanetRef()galaxyReference=PlanetaryReference(Atlas())Kinematic=Kinematics()Kep=Keplers()function getDistanceDisplayString(cK)local fn=cK>100000;local X=""if fn then X=round(cK/1000/200,1).." SU"elseif cK<1000 then X=round(cK,1).." M"else X=round(cK/1000,1).." KM"end;return X end;function getDistanceDisplayString2(cK)local fn=cK>100000;local X=""if fn then X=round(cK/1000/200,2).." SU"elseif cK<1000 then X=round(cK,2).." M"else X=round(cK/1000,2).." KM"end;return X end;function getSpeedDisplayString(a9)return b(round(a9*3.6,0)+0.5).." km/h"end;function FormatTimeString(fo)local fp=b(fo/86400)local fq=b(fo/3600)local fr=b(fo/60%60)local fo=b(fo%60)if fo<0 or fq<0 or fr<0 then return"0s"end;if fp>0 then return fp.."d "..fq.."h "elseif fq>0 then return fq.."h "..fr.."m "elseif fr>0 then return fr.."m "..fo.."s"else return fo.."s"end end;function getMagnitudeInDirection(bj,e9)bj=vec3(bj)e9=vec3(e9):normalize()local X=bj*e9;return X.x+X.y+X.z end;function UpdateAutopilotTarget()if AutopilotTargetIndex==0 then AutopilotTargetName="None"AutopilotTargetPlanet=nil;return true end;local fs=AtlasOrdered[AutopilotTargetIndex].index;local ft=atlas[0][fs]if ft.center then AutopilotTargetName=ft.name;AutopilotTargetPlanet=galaxyReference[0][fs]if CustomTarget~=nil then if g()==0 then if system.updateData(widgetMaxBrakeTimeText,widgetMaxBrakeTime)~=1 then system.addDataToWidget(widgetMaxBrakeTimeText,widgetMaxBrakeTime)end;if system.updateData(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)~=1 then system.addDataToWidget(widgetMaxBrakeDistanceText,widgetMaxBrakeDistance)end;if system.updateData(widgetCurBrakeTimeText,widgetCurBrakeTime)~=1 then system.addDataToWidget(widgetCurBrakeTimeText,widgetCurBrakeTime)end;if system.updateData(widgetCurBrakeDistanceText,widgetCurBrakeDistance)~=1 then system.addDataToWidget(widgetCurBrakeDistanceText,widgetCurBrakeDistance)end;if system.updateData(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)~=1 then system.addDataToWidget(widgetTrajectoryAltitudeText,widgetTrajectoryAltitude)end end;if system.updateData(widgetMaxMassText,widgetMaxMass)~=1 then system.addDataToWidget(widgetMaxMassText,widgetMaxMass)end;if system.updateData(widgetTravelTimeText,widgetTravelTime)~=1 then system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)end end;CustomTarget=nil else CustomTarget=ft;for _,W in pairs(galaxyReference[0])do if W.name==CustomTarget.planetname then AutopilotTargetPlanet=W;AutopilotTargetName=CustomTarget.name;break end end;if system.updateData(widgetMaxMassText,widgetMaxMass)~=1 then system.addDataToWidget(widgetMaxMassText,widgetMaxMass)end;if system.updateData(widgetTravelTimeText,widgetTravelTime)~=1 then system.addDataToWidget(widgetTravelTimeText,widgetTravelTime)end end;AutopilotTargetCoords=vec3(AutopilotTargetPlanet.center)_,AutopilotEndSpeed=Kep(AutopilotTargetPlanet):escapeAndOrbitalSpeed(AutopilotTargetOrbit)AutopilotPlanetGravity=0;AutopilotAccelerating=false;AutopilotBraking=false;AutopilotCruising=false;Autopilot=false;AutopilotRealigned=false;AutopilotStatus="Aligning"return true end;function IncrementAutopilotTargetIndex()AutopilotTargetIndex=AutopilotTargetIndex+1;if AutopilotTargetIndex>#AtlasOrdered then AutopilotTargetIndex=0 end;UpdateAutopilotTarget()end;function DecrementAutopilotTargetIndex()AutopilotTargetIndex=AutopilotTargetIndex-1;if AutopilotTargetIndex<0 then AutopilotTargetIndex=#AtlasOrdered end;UpdateAutopilotTarget()end;function GetAutopilotMaxMass()local fu=LastMaxBrakeInAtmo/AutopilotTargetPlanet:getGravity(AutopilotTargetPlanet.center+vec3(0,0,1)*AutopilotTargetPlanet.radius):len()return fu end;function GetAutopilotTravelTime()if not Autopilot then if CustomTarget==nil or CustomTarget.planetname~=planet.name then AutopilotDistance=(AutopilotTargetPlanet.center-vec3(core.getConstructWorldPos())):len()else AutopilotDistance=(CustomTarget.position-vec3(core.getConstructWorldPos())):len()end end;local velocity=core.getWorldVelocity()local a9=vec3(velocity):len()local fv,fw=Kinematic.computeDistanceAndTime(vec3(velocity):len(),MaxGameVelocity,l(),Nav:maxForceForward(),warmup,0)local fx,fy;if not TurnBurn then fx,fy=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else fx,fy=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;local _,fz;if not TurnBurn then _,fz=GetAutopilotBrakeDistanceAndTime(a9)else _,fz=GetAutopilotTBBrakeDistanceAndTime(a9)end;local fA=0;local fB=0;if AutopilotCruising or not Autopilot and a9>5 then fB=Kinematic.computeTravelTime(a9,0,AutopilotDistance)elseif fx+fv0 then return Kinematic.computeDistanceAndTime(a9,AutopilotEndSpeed,l(),0,0,LastMaxBrakeInAtmo-AutopilotPlanetGravity*l())else return 0,0 end end end;function GetAutopilotTBBrakeDistanceAndTime(a9)refreshLastMaxBrake()return Kinematic.computeDistanceAndTime(a9,AutopilotEndSpeed,l(),Nav:maxForceForward(),warmup,LastMaxBrake-AutopilotPlanetGravity*l())end;function hoverDetectGround()local fD=-1;if vBooster then fD=vBooster.distance()elseif hover then fD=hover.distance()end;return fD end;function round(ce,fE)local fF=10^(fE or 0)return b(ce*fF+0.5)/fF end;function tablelength(fG)local fH=0;for _ in pairs(fG)do fH=fH+1 end;return fH end;function BeginProfile(fI)ProfileTimeStart=system.getTime()end;function EndProfile(fI)local fJ=system.getTime()-ProfileTimeStart;ProfileTimeSum=ProfileTimeSum+fJ;ProfileCount=ProfileCount+1;if fJ>ProfileTimeMax then ProfileTimeMax=fJ end;if fJ0 then if HasSpaceRadar and EmergencyWarp then local fR=fQ:gmatch('{"constructId[^}]*}[^}]*}')for W in fR do local ap,cK=W:match([[{"constructId":"([%d%.]*)","distance":([%d%.]*)]])if ap~=nil and ap~=""then cK=b(cK)if cKIgnoreEmergencyWarpDistance then if NotTriedEmergencyWarp and d(warpdrive.getData()).errorMsg~="PLANET TOO CLOSE"then if radar_1.hasMatchingTransponder(ap)~=1 then InEmergencyWarp=true;NotTriedEmergencyWarp=false;break end end end end end end;local fS=fQ:find('identifiedConstructs":%[%]')if fS==nil and perisPanelID==nil then Peris=1;ToggleRadarPanel()end;if fS~=nil and perisPanelID~=nil then ToggleRadarPanel()end;if radarPanelID==nil then ToggleRadarPanel()end;RadarMessage=c([[Radar: %i contacts]],#fP)local fT={}for V,W in pairs(fP)do if radar_1.hasMatchingTransponder(W)==1 then fT[#fT+1]=W end end;if#fT>0 then local ag=15;RadarMessage=c([[%sFriendlies In Range]],RadarMessage,ag)for V,W in pairs(fT)do ag=ag+20;RadarMessage=c([[%s%s]],RadarMessage,ag,radar_1.getConstructName(W))end end else local fR;fR=fQ:find('worksInEnvironment":false')if fR then RadarMessage=[[Radar: Jammed]]else RadarMessage=[[Radar: No Contacts]]end;if radarPanelID~=nil then Peris=0;ToggleRadarPanel()end end end end;Animating=false;Animated=false;AddLocationsToAtlas()UpdateAutopilotTarget()collectgarbage("collect")unit.setTimer("apTick",apTickRate)unit.setTimer("oneSecond",1)unit.setTimer("tenthSecond",1/10)end)end;function script.onStop()_autoconf.hideCategoryPanels()if antigrav~=nil and not ExternalAGG then antigrav.hide()end;if warpdrive~=nil then warpdrive.hide()end;core.hide()Nav.control.switchOffHeadlights()local fU=g()if door and(fU>0 or fU==0 and CoreAltitude<10000)then for _,W in pairs(door)do W.toggle()end end;if switch then for _,W in pairs(switch)do W.toggle()end end;if forcefield and(fU>0 or fU==0 and CoreAltitude<10000)then for _,W in pairs(forcefield)do W.toggle()end end;if dbHud then if not WipedDatabank then for V,W in pairs(AutoVariables)do dbHud.setStringValue(W,e(_G[W]))end;for V,W in pairs(SaveableVariables)do dbHud.setStringValue(W,e(_G[W]))end;a("Saved Variables to Datacore")end end;if button then button.activate()end end;function script.onTick(fV)if fV=="tenthSecond"then if AutopilotTargetName~="None"then if panelInterplanetary==nil then SetupInterplanetaryPanel()end;if AutopilotTargetName~=nil then local fW=CustomTarget~=nil;planetMaxMass=GetAutopilotMaxMass()system.updateData(interplanetaryHeaderText,'{"label": "Target", "value": "'..AutopilotTargetName..'", "unit":""}')travelTime=GetAutopilotTravelTime()if fW then Distance=(vec3(core.getConstructWorldPos())-CustomTarget.position):len()else Distance=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()end;if not TurnBurn then BrakeDistance,BrakeTime=GetAutopilotBrakeDistanceAndTime(velMag)MaxBrakeDistance,MaxBrakeTime=GetAutopilotBrakeDistanceAndTime(MaxGameVelocity)else BrakeDistance,BrakeTime=GetAutopilotTBBrakeDistanceAndTime(velMag)MaxBrakeDistance,MaxBrakeTime=GetAutopilotTBBrakeDistanceAndTime(MaxGameVelocity)end;system.updateData(widgetDistanceText,'{"label": "Distance", "value": "'..getDistanceDisplayString(Distance)..'", "unit":""}')system.updateData(widgetTravelTimeText,'{"label": "Travel Time", "value": "'..FormatTimeString(travelTime)..'", "unit":""}')system.updateData(widgetCurBrakeDistanceText,'{"label": "Cur Brake Distance", "value": "'..getDistanceDisplayString(BrakeDistance)..'", "unit":""}')system.updateData(widgetCurBrakeTimeText,'{"label": "Cur Brake Time", "value": "'..FormatTimeString(BrakeTime)..'", "unit":""}')system.updateData(widgetMaxBrakeDistanceText,'{"label": "Max Brake Distance", "value": "'..getDistanceDisplayString(MaxBrakeDistance)..'", "unit":""}')system.updateData(widgetMaxBrakeTimeText,'{"label": "Max Brake Time", "value": "'..FormatTimeString(MaxBrakeTime)..'", "unit":""}')system.updateData(widgetMaxMassText,'{"label": "Maximum Mass", "value": "'..c("%.2f tons",planetMaxMass/1000)..'", "unit":""}')if g()>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 g()==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 InEmergencyWarp then if d(warpdrive.getData()).buttonMsg~="CANNOT WARP"then MsgText="EMERGENCY WARP ACTIVATED"MsgTimer=5;warpdrive.activateWarp()warpdrive.show()showWarpWidget=true;EmergencyWarp=false;InEmergencyWarp=false else MsgText="Emergency Warp Condition Met - Cannot Warp, will retry in 1 second\n"..d(warpdrive.getData()).errorMsg;msgTick=1;InEmergencyWarp=false;unit.setTimer("reEmergencyWarp",1)end end;if d(warpdrive.getData()).destination~="Unknown"and d(warpdrive.getData()).distance>400000 then warpdrive.show()showWarpWidget=true else warpdrive.hide()showWarpWidget=false end end elseif fV=="oneSecond"then clearAllCheck=false;refreshLastMaxBrake(nil,true)updateDistance()updateRadar()updateWeapons()local as={}local bt=GetFlightStyle()DrawOdometer(as,TotalDistanceTrip,TotalDistanceTravelled,bt,FlightTime)checkDamage(as)LastOdometerOutput=table.concat(as,"")collectgarbage("collect")elseif fV=="reEmergencyWarp"then if EmergencyWarp then NotTriedEmergencyWarp=true;InEmergencyWarp=true end;unit.stopTimer("reEmergencyWarp")elseif fV=="msgTick"then local as={}DisplayMessage(as,"empty")MsgText="empty"unit.stopTimer("msgTick")MsgTimer=3 elseif fV=="animateTick"then Animated=true;Animating=false;SimulatedX=0;SimulatedY=0;unit.stopTimer("animateTick")elseif fV=="apTick"then local m=m;RateOfChange=vec3(core.getConstructWorldOrientationForward()):dot(vec3(core.getWorldVelocity()):normalize())InAtmo=g()>0;YawInput2=0;RollInput2=0;PitchInput2=0;LastApsDiff=-1;velocity=vec3(core.getWorldVelocity())velMag=vec3(velocity):len()sys=galaxyReference[0]planet=sys:closestBody(core.getConstructWorldPos())kepPlanet=Kep(planet)orbit=kepPlanet:orbitalParameters(core.getConstructWorldPos(),velocity)HovGndDet=hoverDetectGround()local fX=system.getMouseDeltaX()local fY=system.getMouseDeltaY()TargetGroundAltitude=Nav:getTargetGroundAltitude()local fZ=velMag>8334;if not fZ and LastIsWarping then if not BrakeIsOn then BrakeToggle()end;if Autopilot then ToggleAutopilot()end end;LastIsWarping=fZ;if BrakeIsOn then BrakeInput=1 else BrakeInput=0 end;CoreAltitude=core.getAltitude()if CoreAltitude==0 then CoreAltitude=(vec3(core.getConstructWorldPos())-planet.center):len()-planet.radius end;local as={}HUDPrologue(as)if showHud then updateHud(as)else DisplayOrbitScreen(as)DrawWarnings(as)end;HUDEpilogue(as)as[#as+1]=[[]]if MsgText~="empty"then DisplayMessage(as,MsgText)end;if m()==0 and userControlScheme=="virtual joystick"then DrawDeadZone(as)end;if m()==1 and screen_1 and screen_1.getMouseY()~=-1 then SimulatedX=screen_1.getMouseX()*2560;SimulatedY=screen_1.getMouseY()*1440;SetButtonContains()DrawButtons(as)if screen_1.getMouseState()==1 then CheckButtons()end;as[#as+1]=c([[]],SimulatedX,SimulatedY)elseif system.isViewLocked()==0 then if m()==1 and HoldingCtrl then if not Animating then SimulatedX=SimulatedX+fX;SimulatedY=SimulatedY+fY end;SetButtonContains()DrawButtons(as)if not Animating and not Animated then local f_=table.concat(as,"")as={}as[#as+1]=""as[#as+1]=GalaxyMapHTML;as[#as+1]=f_;as[#as+1]=""Animating=true;as[#as+1]=[[]]unit.setTimer("animateTick",0.5)local content=table.concat(as,"")system.setScreen(content)elseif Animated then local f_=table.concat(as,"")as={}as[#as+1]=""as[#as+1]=GalaxyMapHTML;as[#as+1]=f_;as[#as+1]=""end;if not Animating then as[#as+1]=c([[]],SimulatedX,SimulatedY)end else CheckButtons()SimulatedX=0;SimulatedY=0 end else SimulatedX=SimulatedX+fX;SimulatedY=SimulatedY+fY;Distance=math.sqrt(SimulatedX*SimulatedX+SimulatedY*SimulatedY)if not HoldingCtrl and m()==0 then if userControlScheme=="virtual joystick"then if SimulatedX>0 and SimulatedX>DeadZone then YawInput2=YawInput2-(SimulatedX-DeadZone)*MouseXSensitivity elseif SimulatedX<0 and SimulatedX0 and SimulatedY>DeadZone then PitchInput2=PitchInput2-(SimulatedY-DeadZone)*MouseYSensitivity elseif SimulatedY<0 and SimulatedYDeadZone then DrawCursorLine(as)end else SetButtonContains()DrawButtons(as)end;as[#as+1]=c([[]],SimulatedX,SimulatedY)end;as[#as+1]=[[]]content=table.concat(as,"")if not DidLogOutput then system.logInfo(LastContent)DidLogOutput=true end;if ProgradeIsOn then if velMag>MinAutopilotSpeed then local g0=AlignToWorldVector(vec3(velocity),0.01)if SpaceLand then autoRoll=true;if g0 then ProgradeIsOn=false;ReentryMode=true;BeginReentry()SpaceLand=false;FinalLand=true;autoRoll=autoRollPreference end end end end;if RetrogradeIsOn then if InAtmo then RetrogradeIsOn=false elseif velMag>MinAutopilotSpeed then AlignToWorldVector(-vec3(velocity))end end;if not ProgradeIsOn and SpaceLand then if g()==0 then ReentryMode=true;BeginReentry()SpaceLand=false;FinalLand=true else SpaceLand=false;ToggleAutopilot()end end;if FinalLand and CoreAltitudeReentrySpeed-100 then ToggleAutopilot()FinalLand=false end;if Autopilot and g()==0 then local fx,fy;if not TurnBurn then fx,fy=GetAutopilotBrakeDistanceAndTime(velMag)else fx,fy=GetAutopilotTBBrakeDistanceAndTime(velMag)end;fx=fx;fy=fy;local g1=AutopilotTargetCoords;if orbit.apoapsis==nil and velMag>300 and AutopilotAccelerating then local g2=(vec3(AutopilotTargetCoords)-vec3(core.getConstructWorldPos())):normalize()-vec3(velocity):normalize()local g3=getMagnitudeInDirection(g2,AutopilotShipUp)local g4=getMagnitudeInDirection(g2,AutopilotShipRight)local g5=-g4*AutopilotDistance*velMag*TrajectoryAlignmentStrength;local g6=-g3*AutopilotDistance*velMag*TrajectoryAlignmentStrength;g1=AutopilotTargetCoords+-g5*vec3(AutopilotShipRight)+-g6*vec3(AutopilotShipUp)end;AutopilotDistance=(vec3(g1)-vec3(core.getConstructWorldPos())):len()local g7=(AutopilotTargetCoords-vec3(core.getConstructWorldPos())):len()system.updateData(widgetDistanceText,'{"label": "Distance", "value": "'..getDistanceDisplayString(g7)..'", "unit":""}')local g8=true;local g9=(AutopilotTargetPlanet.center-(vec3(core.getConstructWorldPos())+vec3(velocity):normalize()*AutopilotDistance)):len()-AutopilotTargetPlanet.radius;system.updateData(widgetTrajectoryAltitudeText,'{"label": "Projected Altitude", "value": "'..getDistanceDisplayString(g9)..'", "unit":""}')if not AutopilotCruising and not AutopilotBraking then g8=AlignToWorldVector((g1-vec3(core.getConstructWorldPos())):normalize())elseif TurnBurn then g8=AlignToWorldVector(-vec3(velocity):normalize())end;if AutopilotAccelerating then if not g8 or BrakeIsOn then AutopilotStatus="Adjusting Trajectory"else AutopilotStatus="Accelerating"end;if vec3(core.getConstructWorldOrientationForward()):dot(velocity)<0 and velMag>300 then BrakeIsOn=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false elseif not APThrottleSet then BrakeIsOn=false;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)APThrottleSet=true end;if vec3(core.getVelocity()):len()>=MaxGameVelocity and math.abs(g9-AutopilotTargetOrbit)<1000 or unit.getThrottle()==0 and APThrottleSet then AutopilotAccelerating=false;AutopilotStatus="Cruising"AutopilotCruising=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false end;if AutopilotDistance<=fx then AutopilotAccelerating=false;AutopilotStatus="Braking"AutopilotBraking=true;Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,0)APThrottleSet=false end elseif AutopilotBraking then BrakeIsOn=true;BrakeInput=1;if TurnBurn then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,100)end;if orbit.periapsis~=nil and orbit.eccentricity<1 then AutopilotStatus="Circularizing"if orbit.eccentricity>LastEccentricity or orbit.apoapsis.altitude0 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"AutopilotCruising=false end else if g8 then if not AutopilotRealigned then AutopilotTargetCoords=vec3(AutopilotTargetPlanet.center)+(AutopilotTargetOrbit+AutopilotTargetPlanet.radius)*vec3(core.getConstructWorldOrientationRight())AutopilotRealigned=true;AutopilotShipUp=core.getConstructWorldOrientationUp()AutopilotShipRight=core.getConstructWorldOrientationRight()elseif g8 then AutopilotAccelerating=true;AutopilotStatus="Accelerating"if not APThrottleSet then Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal,AutopilotInterplanetaryThrottle)APThrottleSet=true;BrakeIsOn=false end end end end end;if FollowMode then autoRoll=true;local ga=0;local bI=vec3(core.getConstructWorldPos())+vec3(unit.getMasterPlayerRelativePosition())local gb=bI-vec3(core.getConstructWorldPos())local gc=vec3(gb):project_on(vec3(core.getConstructWorldOrientationForward())):len()local gd=vec3(gb):project_on(vec3(core.getConstructWorldOrientationRight())):len()local cK=math.sqrt(gc*gc+gd*gd)AlignToWorldVector(gb:normalize())local ge=40;local gf=cKgi then if pitchPID==nil then pitchPID=pid.new(2*0.01,0,2*0.1)end;pitchPID:inject(ga-ay)local gj=pitchPID:get()PitchInput2=gj end end;local c1=vec3(core.getWorldVertical())*-1;if AltitudeHold or BrakeLanding or Reentry or VectorToTarget or LockPitch~=nil then local bH=unit.getClosestPlanetInfluence()>0;local bu=CoreAltitude;local gk=HoldAltitude-bu;local gl=500+velMag;local ga=(utils.smoothstep(gk,-gl,gl)-0.5)*2*MaxPitch;if not AltitudeHold then ga=0 end;if LockPitch~=nil then if bH then ga=LockPitch else LockPitch=nil end end;autoRoll=true;if Reentry then local gm=ReentrySpeed;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=gm then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,gm)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end;if not ReentryMode then ga=-80;if g()>0.02 then MsgText="PARACHUTE DEPLOYED"Reentry=false;BrakeLanding=true;ga=0;autoRoll=autoRollPreference end elseif Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==ReentrySpeed then ReentryMode=false;Reentry=false;autoRoll=autoRollPreference end end;local gn=PitchInput2;if velMag>MinAutopilotSpeed then AlignToWorldVector(vec3(velocity))end;if VectorToTarget and CustomTarget~=nil and AutopilotTargetIndex>0 then local bl=CustomTarget.position-vec3(core.getConstructWorldPos())AlignToWorldVector(bl)local go=bl:len()-bl:project_on(c1):len()local aa=LastMaxBrakeInAtmo;local b_=velocity.x*c1.x+velocity.y*c1.y+velocity.z*c1.z;local gp=velocity:len()-math.abs(b_)local gq=vec3(core.getWorldAirFrictionAcceleration())if aa~=nil then BrakeDistance,BrakeTime=Kinematic.computeDistanceAndTime(gp,0,l(),0,0,aa+(gq:len()-gq:project_on(c1):len())*l())else BrakeDistance,BrakeTime=Kinematic.computeDistanceAndTime(gp,0,l(),0,0,LastMaxBrake+vec3(core.getWorldAirFrictionAcceleration()):len()*l())end;StrongBrakes=planet.gravity*9.80665*l()LastTargetDistance and not AltitudeHold and not AutoTakeoff then BrakeLanding=true;VectorToTarget=false end;LastTargetDistance=go end;PitchInput2=gn;local av=vec3(core.getConstructWorldOrientationForward())local aw=vec3(core.getConstructWorldOrientationRight())local ax=vec3(core.getWorldVertical())local fD=-1;local ay=getPitch(ax,av,aw)local gi=0.1;if BrakeLanding then ga=0;if Nav.axisCommandManager:getAxisCommandType(0)==1 then Nav.control.cancelCurrentControlMasterMode()end;Nav.axisCommandManager:setTargetGroundAltitude(500)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(500)local b_=velocity.x*c1.x+velocity.y*c1.y+velocity.z*c1.z;fD=HovGndDet;if fD>-1 then if math.abs(ga-ay)50000 then if Nav.axisCommandManager:getAxisCommandType(0)==0 then Nav.control.cancelCurrentControlMasterMode()end;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)~=5000 then Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.longitudinal,5000)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.vertical,0)Nav.axisCommandManager:setTargetSpeedCommand(axisCommandId.lateral,0)end end end;if math.abs(ga-ay)>gi then if pitchPID==nil then pitchPID=pid.new(8*0.01,0,8*0.1)end;pitchPID:inject(ga-ay)local gj=pitchPID:get()PitchInput2=PitchInput2+gj end end;LastEccentricity=orbit.eccentricity;if antigrav and not ExternalAGG and CoreAltitude<200000 then if antigrav.getState()==1 then if AntigravTargetAltitude==nil then AntigravTargetAltitude=1000 end;if desiredBaseAltitude~=AntigravTargetAltitude then desiredBaseAltitude=AntigravTargetAltitude;antigrav.setBaseAltitude(desiredBaseAltitude)end else if AntigravTargetAltitude==nil then desiredBaseAltitude=CoreAltitude else desiredBaseAltitude=AntigravTargetAltitude end end end end end;function script.onFlush()if antigrav and not ExternalAGG then if antigrav.getState()==0 and antigrav.getBaseAltitude()~=AntigravTargetAltitude then antigrav.setBaseAltitude(AntigravTargetAltitude)end end;local gr=2;pitchSpeedFactor=math.max(pitchSpeedFactor,0.01)yawSpeedFactor=math.max(yawSpeedFactor,0.01)rollSpeedFactor=math.max(rollSpeedFactor,0.01)gr=math.max(gr,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 gs=utils.clamp(PitchInput+PitchInput2+system.getControlDeviceForwardInput(),-1,1)local gt=utils.clamp(RollInput+RollInput2+system.getControlDeviceYawInput(),-1,1)local gu=utils.clamp(YawInput+YawInput2-system.getControlDeviceLeftRightInput(),-1,1)local gv=BrakeInput;local gw=vec3(core.getWorldVertical())local gx=vec3(core.getConstructWorldOrientationUp())local gy=vec3(core.getConstructWorldOrientationForward())local gz=vec3(core.getConstructWorldOrientationRight())local gA=vec3(core.getWorldVelocity())local gB=vec3(core.getWorldVelocity()):normalize()local gC=getRoll(gw,gy,gz)local gD=math.abs(gC)local gE=utils.sign(gC)local g=g()local gF=vec3(core.getWorldAngularVelocity())local gG=gs*pitchSpeedFactor*gz+gt*rollSpeedFactor*gy+gu*yawSpeedFactor*gx;if gw:len()>0.01 and g>0.0 or ProgradeIsOn then local gH=1.0;if autoRoll==true and gD>gH and gt==0 then local gI=utils.clamp(0,gD-30,gD+30)if rollPID==nil then rollPID=pid.new(autoRollFactor*0.01,0,autoRollFactor*0.1)end;rollPID:inject(gI-gC)local gJ=rollPID:get()gG=gG+gJ*gy end end;if gw:len()>0.01 and g>0.0 then local gK=20.0;if turnAssist==true and gD>gK and gs==0 and gu==0 then local gL=turnAssistFactor*0.1;local gM=turnAssistFactor*0.025;local gN=(gD-gK)/(180-gK)*180;local gO=0;if gN<90 then gO=gN/90 elseif gN<180 then gO=(180-gN)/90 end;gO=gO*gO;local gP=-gE*gM*(1.0-gO)local gQ=gL*gO;gG=gG+gQ*gz+gP*gx end end;local gR=1;local gS=0;local gT=1;local gU=gr*(gG-gF)local gV=vec3(core.getWorldAirFrictionAngularAcceleration())gU=gU-gV;Nav:setEngineTorqueCommand('torque',gU,gR,'airfoil','','',gT)local gW=-gv*(brakeSpeedFactor*gA+brakeFlatFactor*gB)Nav:setEngineForceCommand('brake',gW)local gX=''local gY=vec3()local gZ=false;local g_='thrust analog longitudinal'local h0=Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)if h0==axisCommandType.byThrottle then local h1=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(g_,axisCommandId.longitudinal)Nav:setEngineForceCommand(g_,h1,gR)elseif h0==axisCommandType.byTargetSpeed then local h1=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)gX=gX..' , '..g_;gY=gY+h1;if Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)==0 or Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal)<-Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal)*0.5 then gZ=true end end;local h2='thrust analog lateral'local h3=Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)if h3==axisCommandType.byThrottle then local h4=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(h2,axisCommandId.lateral)Nav:setEngineForceCommand(h2,h4,gR)elseif h3==axisCommandType.byTargetSpeed then local h5=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)gX=gX..' , '..h2;gY=gY+h5 end;local h6='thrust analog vertical'local h7=Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)if h7==axisCommandType.byThrottle then local h8=Nav.axisCommandManager:composeAxisAccelerationFromThrottle(h6,axisCommandId.vertical)if UpAmount~=0 or BrakeLanding and BrakeIsOn then Nav:setEngineForceCommand(h6,h8,gR,'airfoil','ground','',gT)else Nav:setEngineForceCommand(h6,vec3(),gR)Nav:setEngineForceCommand('airfoil vertical',h8,gR,'airfoil','','',gT)Nav:setEngineForceCommand('ground vertical',h8,gR,'ground','','',gT)end elseif h7==axisCommandType.byTargetSpeed then if UpAmount==0 then Nav:setEngineForceCommand('hover',vec3(),gR)end;local h9=Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)gX=gX..' , '..h6;gY=gY+h9 end;if gY:len()>constants.epsilon then if BrakeInput~=0 or gZ or math.abs(gB:dot(gy))<0.95 then gX=gX..', brake'end;Nav:setEngineForceCommand(gX,gY,gS,'','','',gT)end;Nav:setBoosterCommand('rocket_engine')if IsBoosting then local a9=vec3(core.getVelocity()):len()local ha=0.15;if Nav.axisCommandManager:getAxisCommandType(0)==1 then local hb=Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)if a9*3.6>hb*(1-ha)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif a9*3.6=gh*(1-ha)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif a9=gh*(1-ha)and IsRocketOn then IsRocketOn=false;Nav:toggleBoosters()elseif a90 or CoreAltitudeMinAutopilotSpeed then MsgText="WARNING: Insufficient Brakes - Attempting landing anyway"end;Reentry=false;AutoTakeoff=false;AltitudeHold=false;BrakeLanding=true;autoRoll=true;GearExtended=false else BrakeIsOn=true;Nav.control.extendLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(LandingGearGroundHeight)end else Nav.control.retractLandingGears()Nav.axisCommandManager:setTargetGroundAltitude(TargetHoverHeight)end elseif hd=="light"then if Nav.control.isAnyHeadlightSwitchedOn()==1 then Nav.control.switchOffHeadlights()else Nav.control.switchOnHeadlights()end elseif hd=="forward"then PitchInput=PitchInput-1 elseif hd=="backward"then PitchInput=PitchInput+1 elseif hd=="left"then RollInput=RollInput-1 elseif hd=="right"then RollInput=RollInput+1 elseif hd=="yawright"then YawInput=YawInput-1 elseif hd=="yawleft"then YawInput=YawInput+1 elseif hd=="straferight"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,1.0)elseif hd=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral,-1.0)elseif hd=="up"then UpAmount=UpAmount+1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,1.0)elseif hd=="down"then UpAmount=UpAmount-1;Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical,-1.0)elseif hd=="groundaltitudeup"then OldButtonMod=HoldAltitudeButtonModifier;OldAntiMod=AntiGravButtonModifier;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude+AntiGravButtonModifier else AntigravTargetAltitude=desiredBaseAltitude+100 end elseif AltitudeHold then HoldAltitude=HoldAltitude+HoldAltitudeButtonModifier else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)end elseif hd=="groundaltitudedown"then OldButtonMod=HoldAltitudeButtonModifier;OldAntiMod=AntiGravButtonModifier;if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude-AntiGravButtonModifier;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end else AntigravTargetAltitude=desiredBaseAltitude end elseif AltitudeHold then HoldAltitude=HoldAltitude-HoldAltitudeButtonModifier else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)end elseif hd=="option1"then IncrementAutopilotTargetIndex()ToggleView=false elseif hd=="option2"then DecrementAutopilotTargetIndex()ToggleView=false elseif hd=="option3"then if hideHudOnToggleWidgets then if showHud then showHud=false else showHud=true end end;ToggleView=false;ToggleWidgets()elseif hd=="option4"then ToggleAutopilot()ToggleView=false elseif hd=="option5"then ToggleLockPitch()ToggleView=false elseif hd=="option6"then ToggleAltitudeHold()ToggleView=false elseif hd=="option7"then wipeSaveVariables()ToggleView=false elseif hd=="option8"then ToggleFollowMode()ToggleView=false elseif hd=="option9"then if gyro~=nil then gyro.toggle()GyroIsOn=gyro.getState()==1 end;ToggleView=false elseif hd=="lshift"then if system.isViewLocked()==1 then HoldingCtrl=true;PrevViewLock=system.isViewLocked()system.lockView(1)elseif m()==1 and ShiftShowsRemoteButtons then HoldingCtrl=true;Animated=false;Animating=false end elseif hd=="brake"then if brakeToggle then BrakeToggle()elseif not BrakeIsOn then BrakeToggle()else BrakeIsOn=true end elseif hd=="lalt"then if m()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(1)end elseif hd=="booster"then if not IsBoosting then if not IsRocketOn then Nav:toggleBoosters()IsRocketOn=true end;IsBoosting=true else if IsRocketOn then Nav:toggleBoosters()IsRocketOn=false end;IsBoosting=false end elseif hd=="stopengines"then Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)clearAll()elseif hd=="speedup"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,speedChangeLarge)else IncrementAutopilotTargetIndex()end elseif hd=="speeddown"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal,-speedChangeLarge)else DecrementAutopilotTargetIndex()end elseif hd=="antigravity"and not ExternalAGG then if antigrav~=nil then ToggleAntigrav()end elseif hd=="warp"then if warpdrive~=nil then if not InEmergencyWarp then if showWarpWidget then warpdrive.hide()showWarpWidget=false else warpdrive.show()showWarpWidget=true end;if d(warpdrive.getData()).buttonMsg=="CANNOT WARP"then MsgText=d(warpdrive.getData()).errorMsg else warpdrive.activateWarp()warpdrive.show()showWarpWidget=true end else InEmergencyWarp=false;EmergencyWarp=false;MsgText="Emergency Warp Cancelled"end end end end;function script.onActionStop(hd)if hd=="forward"then PitchInput=0 elseif hd=="backward"then PitchInput=0 elseif hd=="left"then RollInput=0 elseif hd=="right"then RollInput=0 elseif hd=="yawright"then YawInput=0 elseif hd=="yawleft"then YawInput=0 elseif hd=="straferight"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,-1.0)elseif hd=="strafeleft"then Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral,1.0)elseif hd=="up"then UpAmount=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,-1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif hd=="down"then UpAmount=0;Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical,1.0)Nav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)Nav:setEngineForceCommand('hover',vec3(),1)elseif hd=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then AntiGravButtonModifier=OldAntiMod elseif AltitudeHold then HoldAltitudeButtonModifier=OldButtonMod end;ToggleView=false elseif hd=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then AntiGravButtonModifier=OldAntiMod elseif AltitudeHold then HoldAltitudeButtonModifier=OldButtonMod end;ToggleView=false elseif hd=="lshift"then if system.isViewLocked()==1 then HoldingCtrl=false;SimulatedX=0;SimulatedY=0;system.lockView(PrevViewLock)elseif m()==1 and ShiftShowsRemoteButtons then HoldingCtrl=false;Animated=false;Animating=false end elseif hd=="brake"then if not brakeToggle then if BrakeIsOn then BrakeToggle()else BrakeIsOn=false end end elseif hd=="lalt"then if m()==0 and freeLookToggle then if ToggleView then if system.isViewLocked()==1 then system.lockView(0)else system.lockView(1)end else ToggleView=true end elseif m()==0 and not freeLookToggle and userControlScheme=="keyboard"then system.lockView(0)end end end;function script.onActionLoop(hd)if hd=="groundaltitudeup"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude+AntiGravButtonModifier;AntiGravButtonModifier=AntiGravButtonModifier*1.05;BrakeIsOn=false else AntigravTargetAltitude=desiredBaseAltitude+100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude+HoldAltitudeButtonModifier;HoldAltitudeButtonModifier=HoldAltitudeButtonModifier*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)end elseif hd=="groundaltitudedown"then if antigrav and not ExternalAGG and antigrav.getState()==1 then if AntigravTargetAltitude~=nil then AntigravTargetAltitude=AntigravTargetAltitude-AntiGravButtonModifier;AntiGravButtonModifier=AntiGravButtonModifier*1.05;BrakeIsOn=false;if AntigravTargetAltitude<1000 then AntigravTargetAltitude=1000 end else AntigravTargetAltitude=desiredBaseAltitude-100;BrakeIsOn=false end elseif AltitudeHold then HoldAltitude=HoldAltitude-HoldAltitudeButtonModifier;HoldAltitudeButtonModifier=HoldAltitudeButtonModifier*1.05 else Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)end elseif hd=="speedup"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,speedChangeSmall)end elseif hd=="speeddown"then if not HoldingCtrl then Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal,-speedChangeSmall)end end end;function DisplayMessage(as,he)if he~="empty"then as[#as+1]=[[]]for hf in string.gmatch(he,"([^\n]+)")do as[#as+1]=c([[%s]],hf)end;as[#as+1]=[[]]end;if MsgTimer~=0 then unit.setTimer("msgTick",MsgTimer)MsgTimer=0 end end;function updateDistance()local a3=system.getTime()local velocity=vec3(core.getWorldVelocity())local bE=vec3(velocity):len()local hg=a3-LastTravelTime;if bE>1.38889 then bE=bE/1000;local hh=bE*(a3-LastTravelTime)TotalDistanceTravelled=TotalDistanceTravelled+hh;TotalDistanceTrip=TotalDistanceTrip+hh end;FlightTime=FlightTime+hg;TotalFlightTime=TotalFlightTime+hg;LastTravelTime=a3 end;script.onStart() -- error handling code added by wrap.lua diff --git a/ChangeLog.md b/ChangeLog.md index e7dc2f4..7dbb755 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ ## ChangeLog - Most recent changes at the top +Version 4.852 +- Fixed fuel tanks, again (stop changing element names!) +- Restored emergency warp. + Version 4.851 - Fixed Rockets. Note that rockets will not work in Cruise mode now, thats vanilla. Normal operation: If speed > 85% of throttleSetting*1100kph in atmo or > 85% of thottleSetting*MaxVelocity user parameter in space, rockets will turn off. diff --git a/src/ButtonHUD.lua b/src/ButtonHUD.lua index 5440e3b..2d1e20e 100644 --- a/src/ButtonHUD.lua +++ b/src/ButtonHUD.lua @@ -20,7 +20,7 @@ local isRemote = Nav.control.isRemoteControlled function script.onStart() -- Written by Dimencia and Archaegeo. Optimization and Automation of scripting by ChronosWS Linked sources where appropriate, most have been modified. - VERSION_NUMBER = 4.851 + VERSION_NUMBER = 4.852 SetupComplete = false beginSetup = coroutine.create(function() @@ -63,6 +63,8 @@ function script.onStart() MaxPitch = 30 -- export: Maximum allowed pitch during takeoff and altitude changes while in altitude hold. Default is 20 deg. You can set higher or lower depending on your ships capabilities. ReentrySpeed = 1050 -- export: Target re-entry speed once in atmosphere in m/s. 291 = 1050 km/hr, higher might cause reentry burn. ReentryAltitude = 2500 -- export: Target alititude when using re-entry. + EmergencyWarpDistance = 320000 -- export: Set to distance as which an emergency warp will occur if radar target within that distance. 320000 is lock range for large radar on large ship no special skills. + IgnoreEmergencyWarpDistance = 500 -- export: Any targets within this distance are ignored for emergency warp. AutoTakeoffAltitude = 1000 -- export: How high above your ground starting position AutoTakeoff tries to put you TargetHoverHeight = 50 -- export: Hover height when retracting landing gear LandingGearGroundHeight = 0 --export: Set to hover height reported - 1 when you use alt-spacebar to just lift off ground from landed postion. 4 is M size landing gear, @@ -96,6 +98,7 @@ function script.onStart() MinAutopilotSpeed = 55 -- Minimum speed for autopilot to maneuver in m/s. Keep above 25m/s to prevent nosedives when boosters kick in LastMaxBrake = 0 LastMaxBrakeInAtmo = 0 + EmergencyWarp = false ReentryMode = false MousePitchFactor = 1 -- Mouse control only MouseYawFactor = 1 -- Mouse control only @@ -130,6 +133,8 @@ function script.onStart() AutopilotTargetPlanet = nil TotalDistanceTravelled = 0.0 TotalDistanceTrip = 0 + InEmergencyWarp = false + NotTriedEmergencyWarp = true FlightTime = 0 WipedDatabank = false LocationIndex = 0 @@ -217,10 +222,10 @@ function script.onStart() "hideHudOnToggleWidgets", "DampingMultiplier", "fuelTankHandlingAtmo", "fuelTankHandlingSpace", "fuelTankHandlingRocket", "RemoteFreeze", "speedChangeLarge", "speedChangeSmall", "brightHud", "brakeLandingRate", "MaxPitch", - "ReentrySpeed", "ReentryAltitude", "centerX", "centerY", + "ReentrySpeed", "ReentryAltitude", "EmergencyWarpDistance", "centerX", "centerY", "vSpdMeterX", "vSpdMeterY", "altMeterX", "altMeterY", "fuelX","fuelY", "LandingGearGroundHeight", "TrajectoryAlignmentStrength", "RemoteHud", "StallAngle", "ResolutionX", "ResolutionY"} - AutoVariables = {"brakeToggle", "BrakeIsOn", "RetrogradeIsOn", "ProgradeIsOn", + AutoVariables = {"EmergencyWarp", "brakeToggle", "BrakeIsOn", "RetrogradeIsOn", "ProgradeIsOn", "Autopilot", "TurnBurn", "AltitudeHold", "DisplayOrbit", "BrakeLanding", "Reentry", "AutoTakeoff", "HoldAltitude", "AutopilotAccelerating", "AutopilotBraking", "AutopilotCruising", "AutopilotRealigned", "AutopilotEndSpeed", "AutopilotStatus", @@ -306,12 +311,12 @@ function script.onStart() end eleTotalMaxHp = eleTotalMaxHp + eleMaxHp(ElementsID[k]) if (fuelX ~= 0 and fuelY ~= 0) then - if (type == "Atmospheric fuel tank" or type == "Space fuel tank" or type == "Rocket fuel tank") then + if (type == "Atmospheric Fuel Tank" or type == "Space Fuel Tank" or type == "Rocket Fuel Tank") then local hp = eleMaxHp(ElementsID[k]) local mass = eleMass(ElementsID[k]) local curMass = 0 local curTime = system.getTime() - if (type == "Atmospheric fuel tank") then + if (type == "Atmospheric Fuel Tank") then local vanillaMaxVolume = 400 local massEmpty = 35.03 if hp > 10000 then @@ -334,7 +339,7 @@ function script.onStart() atmoTanks[#atmoTanks + 1] = {ElementsID[k], core.getElementNameById(ElementsID[k]), vanillaMaxVolume, massEmpty, curMass, curTime} end - if (type == "Rocket fuel tank") then + if (type == "Rocket Fuel Tank") then local vanillaMaxVolume = 320 local massEmpty = 173.42 if hp > 65000 then @@ -357,7 +362,7 @@ function script.onStart() rocketTanks[#rocketTanks + 1] = {ElementsID[k], core.getElementNameById(ElementsID[k]), vanillaMaxVolume, massEmpty, curMass, curTime} end - if (type == "Space fuel tank") then + if (type == "Space Fuel Tank") then local vanillaMaxVolume = 2400 local massEmpty = 182.67 if hp > 10000 then @@ -480,6 +485,7 @@ function script.onStart() lastMaxBrakeAtG = gravity end end + function MakeButton(enableName, disableName, width, height, x, y, toggleVar, toggleFunction, drawCondition) local newButton = { enableName = enableName, @@ -1103,6 +1109,7 @@ function script.onStart() SpaceLaunch = false ReentryMode = false autoRoll = autoRollPreference + EmergencyWarp = false VectorToTarget = false TurnBurn = false GyroIsOn = false @@ -1534,6 +1541,17 @@ function script.onStart() MsgText = "Orbit Display Disabled" end end) + MakeButton("Enable Emergency Warp", "Disable Emergency Warp", buttonWidth, buttonHeight, x + buttonWidth + 20, y, function() + return EmergencyWarp end, function() + EmergencyWarp = not EmergencyWarp + if (EmergencyWarp) then + MsgText = "Emergency Warp Enabled" + else + MsgText = "Emergency Warp Disabled" + end + end, function() + return warpdrive ~= nil + end) y = y + buttonHeight + 20 MakeButton("Glide Re-Entry", "Cancel Glide Re-Entry", buttonWidth, buttonHeight, x, y, function() return Reentry end, function() ReentryMode = true BeginReentry() end, function() return (CoreAltitude > ReentryAltitude) end ) @@ -2287,6 +2305,10 @@ function script.onStart() warningX, hoverY, getDistanceDisplayString(Nav:getTargetGroundAltitude())) end + if EmergencyWarp then + newContent[#newContent + 1] = stringf([[E-WARP ENGAGED]], + warningX, ewarpY) + end if IsBoosting then newContent[#newContent + 1] = stringf([[ROCKET BOOST ENABLED]], warningX, ewarpY+20) @@ -3910,6 +3932,24 @@ function script.onStart() local radarContacts = radar_1.getEntries() local radarData = radar_1.getData() if #radarContacts > 0 then + if HasSpaceRadar and EmergencyWarp then + local data = radarData:gmatch('{"constructId[^}]*}[^}]*}') -- Gets each construct's entry in full + for v in data do + local id, distance = v:match([[{"constructId":"([%d%.]*)","distance":([%d%.]*)]]) + if id ~= nil and id ~= "" then + distance = mfloor(distance) + if (distance < EmergencyWarpDistance) and ( distance > IgnoreEmergencyWarpDistance) then + if NotTriedEmergencyWarp and jdecode(warpdrive.getData()).errorMsg ~= "PLANET TOO CLOSE" then + if radar_1.hasMatchingTransponder(id) ~= 1 then + InEmergencyWarp = true + NotTriedEmergencyWarp = false + break + end + end + end + end + end + end local target = radarData:find('identifiedConstructs":%[%]') if target == nil and perisPanelID == nil then Peris = 1 @@ -4078,6 +4118,23 @@ function script.onTick(timerId) HideInterplanetaryPanel() end if warpdrive ~= nil then + if InEmergencyWarp then + if jdecode(warpdrive.getData()).buttonMsg ~= "CANNOT WARP" then + MsgText = "EMERGENCY WARP ACTIVATED" + MsgTimer = 5 + warpdrive.activateWarp() + warpdrive.show() + showWarpWidget = true + EmergencyWarp = false + InEmergencyWarp = false + else + MsgText = "Emergency Warp Condition Met - Cannot Warp, will retry in 1 second\n" .. + (jdecode(warpdrive.getData()).errorMsg) + msgTick = 1 + InEmergencyWarp = false + unit.setTimer("reEmergencyWarp", 1) + end + end if jdecode(warpdrive.getData()).destination ~= "Unknown" and jdecode(warpdrive.getData()).distance > 400000 then warpdrive.show() showWarpWidget = true @@ -4101,6 +4158,12 @@ function script.onTick(timerId) checkDamage(newContent) LastOdometerOutput = table.concat(newContent, "") collectgarbage("collect") + elseif timerId == "reEmergencyWarp" then + if EmergencyWarp then + NotTriedEmergencyWarp = true + InEmergencyWarp = true + end + unit.stopTimer("reEmergencyWarp") elseif timerId == "msgTick" then -- This is used to clear a message on screen after a short period of time and then stop itself local newContent = {} @@ -4751,15 +4814,17 @@ function script.onTick(timerId) else desiredBaseAltitude = AntigravTargetAltitude end - if antigrav.getBaseAltitude() ~= AntigravTargetAltitude then - antigrav.setBaseAltitude(desiredBaseAltitude) - end end end end end function script.onFlush() + if antigrav and not ExternalAGG then + if antigrav.getState() == 0 and antigrav.getBaseAltitude() ~= AntigravTargetAltitude then + antigrav.setBaseAltitude(AntigravTargetAltitude) + end + end local torqueFactor = 2 -- Force factor applied to reach rotationSpeed
(higher value may be unstable)
Valid values: Superior or equal to 0.01 -- validate params @@ -5174,19 +5239,25 @@ function script.onActionStart(action) end elseif action == "warp" then if warpdrive ~= nil then - if showWarpWidget then - warpdrive.hide() - showWarpWidget = false - else - warpdrive.show() - showWarpWidget = true - end - if jdecode(warpdrive.getData()).buttonMsg == "CANNOT WARP" then - MsgText = jdecode(warpdrive.getData()).errorMsg + if not InEmergencyWarp then + if showWarpWidget then + warpdrive.hide() + showWarpWidget = false + else + warpdrive.show() + showWarpWidget = true + end + if jdecode(warpdrive.getData()).buttonMsg == "CANNOT WARP" then + MsgText = jdecode(warpdrive.getData()).errorMsg + else + warpdrive.activateWarp() + warpdrive.show() + showWarpWidget = true + end else - warpdrive.activateWarp() - warpdrive.show() - showWarpWidget = true + InEmergencyWarp = false -- lower case is IN situation + EmergencyWarp = false -- upper case is if to monitor for situation + MsgText = "Emergency Warp Cancelled" end end end @@ -5345,4 +5416,3 @@ function updateDistance() end script.onStart() -