-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormalizeOrbit.ks
More file actions
61 lines (47 loc) · 1.99 KB
/
NormalizeOrbit.ks
File metadata and controls
61 lines (47 loc) · 1.99 KB
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
@LAZYGLOBAL off.
parameter orbitSize.
RUNONCEPATH("ExecNode.ks").
print "Setting orbit size to " + orbitSize.
LOCAL tolerance TO orbitSize * 0.03.
LOCK altOtherSide TO (POSITIONAT(SHIP, TIME:SECONDS + (SHIP:ORBIT:PERIOD / 2)) - SHIP:BODY:POSITION):MAG - SHIP:BODY:RADIUS.
GLOBAL THROTTLE TO 0.
print "OtherSideAlt: " + altOtherSide.
UNTIL False {
GLOBAL THROTTLE to 0.
WAIT 5.
print "Warping...".
SET KUNIVERSE:TIMEWARP:WARP to 3.
WAIT UNTIL altOtherSide + tolerance < orbitSize OR altOtherSide - tolerance > orbitSize OR (SHIP:ORBIT:PERIAPSIS + tolerance > orbitSize AND SHIP:ORBIT:PERIAPSIS - tolerance < orbitSize AND SHIP:ORBIT:APOAPSIS + tolerance > orbitSize AND SHIP:ORBIT:APOAPSIS - tolerance < orbitSize).
LOCAL need_correction TO False.
LOCAL raising TO False.
if (altOtherSide + tolerance < orbitSize){
LOCK STEERING TO SHIP:VELOCITY:ORBIT. // Prograde
SET need_correction TO True.
SET raising TO True.
} else if (altOtherSide - tolerance > orbitSize){
LOCK STEERING TO -SHIP:VELOCITY:ORBIT. // Retrograde
SET need_correction TO True.
SET raising TO False.
}
if (need_correction) {
kuniverse:timewarp:CANCELWARP().
print "Correcting: " + altOtherSide + " -> " + orbitSize.
print "Waiting for vessel to align...".
RCS ON.
WAIT UNTIL VANG(STEERING, SHIP:FACING:VECTOR) < 0.25.
GLOBAL THROTTLE to 1.
if (raising) WAIT UNTIL altOtherSide > orbitSize.
else WAIT UNTIL altOtherSide < orbitSize.
GLOBAL THROTTLE to 0.
RCS OFF.
print "Done correcting: " + altOtherSide + " -> " + orbitSize.
}
if (SHIP:ORBIT:PERIAPSIS + tolerance > orbitSize AND SHIP:ORBIT:PERIAPSIS - tolerance < orbitSize AND SHIP:ORBIT:APOAPSIS + tolerance > orbitSize AND SHIP:ORBIT:APOAPSIS - tolerance < orbitSize){
print "Done normalizing".
break.
}
}
kuniverse:timewarp:CANCELWARP().
UNLOCK THROTTLE.
UNLOCK STEERING.
print "End".