Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function DistanceAtTime {
- Parameter T.
- Parameter TargetDestination.
- return ((positionat(ship, T) - positionat(TargetDestination, T)):mag).
- }
- Function ClosestApproachGetter {
- Parameter PeriodPrecision.
- Parameter T.
- Parameter ScoreToBeat.
- set BestCandidate to T.
- set Candidates to list().
- set StandardStepSize to ScoringNode:orbit:period * PeriodPrecision.
- Set StepSize to StandardStepSize.
- set EndFunction to 0.
- until EndFunction = 10 {
- Candidates:add(list(T + StepSize, TargetDestination)).
- set StepSize to StepSize + StandardStepSize.
- set EndFunction to EndFunction + 1.
- }
- Set StepSize to StandardStepSize.
- set EndFunction to 0.
- until EndFunction = 10 {
- Candidates:add(list(T - StepSize, TargetDestination)).
- set StepSize to StepSize + StandardStepSize.
- set EndFunction to EndFunction + 1.
- }
- for Candidate in Candidates {
- set CandidateScore to DistanceAtTime(Candidate[0], Candidate[1]).
- if CandidateScore < ScoreToBeat {
- set ScoreToBeat to CandidateScore.
- set BestCandidate to Candidate[0].
- set ClosestApproach to DistanceAtTime(Candidate[0], Candidate[1]).
- }
- }
- }
- Function ClosestApproachRefiner {
- Parameter TargetDestination.
- set ScoringNode to nextnode.
- set T to time:seconds + 0.5 * ScoringNode:orbit:period.
- set ScoreToBeat to DistanceAtTime(T, TargetDestination).
- ClosestApproachGetter(0.05, T, ScoreToBeat).
- set multiplier to 0.05.
- until multiplier*ScoringNode:orbit:period < 1 {
- set multiplier to multiplier/10.
- ClosestApproachGetter(multiplier, BestCandidate, ClosestApproach).
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement