-
Notifications
You must be signed in to change notification settings - Fork 3
/
maneuvers.ks
158 lines (145 loc) · 3.75 KB
/
maneuvers.ks
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
function hohman_dv {
parameter desiredAltitude.
local u is ship:obt:body:mu.
local r1 is ship:obt:semimajoraxis.
local r2 is desiredAltitude + ship:obt:body:radius.
// v1
local v1 is sqrt(u / r1) * (sqrt((2 * r2) / (r1 + r2)) - 1).
// v2
local v2 is sqrt(u / r2) * (1 - sqrt((2 * r1) / (r1 + r2))).
return list(v1, v2).
}
function mnv_time {
parameter dv.
local f is 0.
list engines in en.
//for engine in en {
// if engine:ignition and not engine:flameout {
// set f to f + engine:maxthrust.
// }
//}
// loop above is used for multiple engines.
set f to en[0]:maxthrust * 1000. // convert kn to n [single engine]
local m is ship:mass * 1000. // convert from t to kg
local e is constant():e. // base of natural log
local p is en[0]:isp. // engine isp (s)
local g is getGravAccConst(). // gravitational acceleration constant (m/s^2)
if f = 0 or p = 0 {
return 0.
}
return g * m * p * (1 - e^(-dv/(g*p))) / f.
}
function execNodeOld {
parameter node.
parameter dispData.
local nodeDV is 0.
local mnvPhase is 0.
set mnvInProgress to true.
sas off.
until mnvPhase = 1 {
set nodeDir to lookdirup(node:deltav, ship:facing:topvector).
until abs(nodeDir:pitch - facing:pitch) < 0.1 and abs(nodeDir:yaw - facing:yaw) < 0.1 {
mainLoop().
wait 0.001.
}
SET WARPMODE TO "RAILS".
warpto(time:seconds + (node:eta - (nodeBurnTime(node) / 2)) - 15).
until abs(nodeDir:pitch - facing:pitch) < 0.1 and abs(nodeDir:yaw - facing:yaw) < 0.1 {
mainLoop().
wait 0.001.
}
mainLoop().
set mnvPhase to 1.
}
until mnvPhase = 2 {
set nodeDir to lookdirup(node:deltav, ship:facing:topvector).
set mnv_complete to false.
set nodeDV to node:deltav.
if node:eta <= (nodeBurnTime(node) / 2) {
until mnv_complete {
set tval to min(node:deltav:mag / shipAcc(), 1).
set nodeDir to lookdirup(node:deltav, ship:facing:topvector).
if vdot(nodeDV, node:deltav) < 0 {
lock throttle to 0.
break.
}
if node:deltav:mag < 0.4 {
until vdot(nodeDV, node:deltav) < 0.5 {
displayGUI().
wait 0.001.
}
lock throttle to 0.
set tval to 0.
set mnv_complete to true.
unlock steering.
unlock throttle.
set mnvPhase to 2.
}
displayGUI().
}
}
displayGUI().
}
set mnvInProgress to false.
set mNodeDisp to false.
set tval to 0.
remove node.
return true.
}
function execNode {
parameter node.
parameter dispData.
local nodeDV is 0.
local mnvPhase is 0.
set mnvInProgress to true.
sas off.
until mnvPhase = 1 {
set nodeDir to lookdirup(node:deltav, ship:facing:topvector).
until abs(nodeDir:pitch - facing:pitch) < 0.1 and abs(nodeDir:yaw - facing:yaw) < 0.1 {
mainLoop().
wait 0.001.
}
SET WARPMODE TO "RAILS".
warpto(time:seconds + (node:eta - (nodeBurnTime(node) / 2)) - 15).
until abs(nodeDir:pitch - facing:pitch) < 0.1 and abs(nodeDir:yaw - facing:yaw) < 0.1 {
mainLoop().
wait 0.001.
}
mainLoop().
set mnvPhase to 1.
}
until mnvPhase = 2 {
set nodeDir to lookdirup(node:deltav, ship:facing:topvector).
set mnv_complete to false.
set nodeDV to node:deltav.
if node:eta <= (nodeBurnTime(node) / 2) {
until mnv_complete {
set tval to min(node:deltav:mag / shipAcc(), 1).
set nodeDir to lookdirup(node:deltav, ship:facing:topvector).
if vdot(nodeDV, node:deltav) < 0 {
lock throttle to 0.
break.
}
if node:deltav:mag < 0.4 {
until vdot(nodeDV, node:deltav) < 0.5 {
displayGUI().
wait 0.001.
}
lock throttle to 0.
set tval to 0.
set mnv_complete to true.
unlock steering.
unlock throttle.
set mnvPhase to 2.
}
displayGUI().
}
}
displayGUI().
}
set mnvInProgress to false.
set mNodeDisp to false.
set tval to 0.
remove node.
return true.
}