-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.lua
186 lines (166 loc) · 5.7 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
--@require SimpleSlotDetector
--@require ExportedVariables
--@require PlanetRef
--@require Kinematics
--@require EventDelegate
--@require TaskManager
--@require DynamicDocument
--@require DUTTY
--@require CSS_SHUD
--@require FuelTankHelper
--@require TagManager
--@require KeybindController
--@require STEC
--@require SHUD
--@require MouseMovement
--@require STEC_Config
--@timer SHUDRender
--@timer FuelStatus
--@timer KeplerSim
--@timer WaypointTest
--@timer Debug
--@class Main
--@outFilename Horizon1.json
_G.BuildUnit = {}
local Unit = _G.BuildUnit
_G.BuildSystem = {}
local System = _G.BuildSystem
function Unit.onStart()
Events.Flush.Add(mouse.apply)
Events.Flush.Add(ship.apply)
Events.Update.Add(SHUD.Update)
if flightModeDb then
if flightModeDb.hasKey("controlMode") == 0 then flightModeDb.setIntValue("controlMode", unit.getControlMode()) end
local controlMode = flightModeDb.getIntValue("controlMode")
if controlMode ~= unit.getControlMode() then
unit.cancelCurrentControlMasterMode()
end
end
if flightModeDb ~= nil then getFuelRenderedHtml() end
unit.setTimer("SHUDRender", 0.02)
unit.setTimer("FuelStatus", 3)
unit.setTimer("KeplerSim", 0.1)
--unit.setTimer("Debug", 2)
-- unit.setTimer("WaypointTest", 1)
system.print([[Horizon 1.1.1.9]])
if showDockingWidget then
parentingPanelId = system.createWidgetPanel("Docking")
parentingWidgetId = system.createWidget(parentingPanelId,"parenting")
system.addDataToWidget(unit.getWidgetDataId(),parentingWidgetId)
end
if system.showHelper then system.showHelper(0) end
--local fMax = construct.getMaxThrustAlongAxis("all", {vec3(0,1,0):unpack()})
--local vMax = construct.getMaxThrustAlongAxis("all", {vec3(0,0,1):unpack()})
--system.print(string.format( "fMax: %f, %f, %f, %f",fMax[1],fMax[2],fMax[3],fMax[4]))
--system.print(string.format( "vMax: %f, %f, %f, %f",vMax[1],vMax[2],vMax[3],vMax[4]))
end
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
function format_int(number)
number = round2(number,0)
local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
-- reverse the int-string and append a comma to all blocks of 3 digits
int = int:reverse():gsub("(%d%d%d)", "%1,")
-- reverse the int-string back remove an optional comma and put the
-- optional minus and fractional part back
return minus .. int:reverse():gsub("^,", "") .. fraction
end
function Unit.onStop()
if flightModeDb then
flightModeDb.setIntValue("controlMode", unit.getControlMode())
end
system.showScreen(false)
end
local switch = false
function Unit.onTimer(timer)
if timer == "SHUDRender" then
if SHUD then SHUD.Render() end
if antigrav ~= nil then
updateAGGBaseAlt()
readAGGState()
updateAGGState()
end
end
-- if timer == "Debug" then
-- --system.print("ship.direction.x: "..ship.direction.x)
-- --system.print("ship.direction.y: "..ship.direction.y)
-- --system.print("ship.direction.z: "..ship.direction.z)
-- --system.print("ship.rotationSpeedz: "..ship.rotationSpeed)
-- --system.print("ship.world.atmosphericDensity: "..ship.world.atmosphericDensity)
-- --system.print("ship.target.prograde(): "..tostring(vec3(ship.world.prograde())))
-- system.print("prograde.x: "..(ship.world.position + (ship.target.prograde() * 2)).x)
-- system.print("prograde.y: "..(ship.world.position + (ship.target.prograde() * 2)).y)
-- local x = ship.nearestPlanet:convertToMapPosition(ship.world.position + (ship.target.prograde() * 2))
-- system.print(x)
-- system.setWaypoint(x)
-- --system.print("ship.forwardThrust: "..format_int(ship.forwardThrust))
-- end
if timer == "FuelStatus" then
getFuelRenderedHtml()
--local msa = construct.getMaxSpeedPerAxis()
--system.print(dump(msa))
end
if timer == "KeplerSim" then
if ship.gotoLock ~= nil then
Task(function()
local t = ship.ETA - ship.accelTime
if ship.ETA == 0 then t = 30 end
local f = simulateAhead(t,t * 0.1)
ship.simulationPos = f.position
end)
end
end
if timer == "WaypointTest" then
-- if ship.gotoLock ~= nil then
-- system.print("[----------------------------------------------]")
-- system.print("Deviation angle: "..ship.deviationAngle.."°")
-- system.print("Target Dist: "..ship.targetDist)
-- system.print("Brake Dist: "..ship.brakeDistance)
-- system.print("Stopping: "..tostring(ship.stopping))
-- system.print("Brake Diff: "..(ship.targetDist - ship.brakeDistance))
-- system.print("Trajectory Diff: "..ship.trajectoryDiff)
-- system.print("Mass (tons): "..ship.mass / 1000)
-- system.print("Max Speed: "..ship.constructMaxSpeed)
-- system.print("ETA: "..disp_time(ship.ETA))
-- system.print("[----------------------------------------------]")
-- end
-- if switch then
-- local waypointString = ship.nearestPlanet:convertToMapPosition(ship.simulationPos)
-- system.setWaypoint(tostring(waypointString))
-- else
-- if ship.gotoLock ~= nil then
-- local waypointString = ship.nearestPlanet:convertToMapPosition(ship.gotoLock)
-- system.setWaypoint(tostring(waypointString))
-- end
-- end
-- switch = not switch
end
end
function System.onActionStart(action)
keybindPresets[keybindPreset].Call(action, "down")
end
function System.onActionStop(action)
keybindPresets[keybindPreset].Call(action, "up")
end
function System.onInputText(action)
if DUTTY then DUTTY.input(action) end
end
function System.onActionLoop(action)
end
function System.onUpdate()
if Events then Events.Update() end
if TaskManager then TaskManager.Update() end
end
function System.onFlush()
if Events then Events.Flush() end
end