-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait_for_overhead.ks
More file actions
60 lines (47 loc) · 1.63 KB
/
wait_for_overhead.ks
File metadata and controls
60 lines (47 loc) · 1.63 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
// Wait until target is some time behind
// Parameters
parameter lead_time is 0.
// Imports
run once koslib.
// Fixed parameters
set forward_search_resolution to 30.
set backtracking_resolution to 1.
// Make sure we're landed
//if status <> "LANDED" {
// print "You need to be on the ground to use this".
//}
clearscreen.
// When will the target be overhead hit the ground?
function posang {
parameter a.
return mod(a + 360, 360).
}
function overhead_time {
local guess_time is time:seconds.
local our_lng is posang(body:geopositionof(positionat(ship, guess_time)):lng).
local targ_lng is posang(body:geopositionof(positionat(target, guess_time)):lng).
// Forward search.
until targ_lng > our_lng {
clearscreen.
set guess_time to guess_time + forward_search_resolution.
print "Checking t+" + (guess_time - time:seconds) at (0, 0).
set targ_lng to posang(body:geopositionof(positionat(target, guess_time)):lng).
}
// Backtrack.
until targ_lng < our_lng {
clearscreen.
set guess_time to guess_time - backtracking_resolution.
print "Checking t+" + (guess_time - time:seconds) at (0, 0).
set targ_lng to posang(body:geopositionof(positionat(target, guess_time)):lng).
}
if guess_time < time:seconds {
set guess_time to guess_time + target:orbit:period.
}
print "Final t+" + (guess_time - time:seconds) at (0,1).
return guess_time.
}
clearscreen.
set overhead_t to overhead_time().
print "Print waiting another " + sec2timestr(overhead_t - time:seconds - lead_time).
// Actually do the waiting
warpto(overhead_t - lead_time).