Advertisement
Guest User

KOS Hillclimb Closest Approach

a guest
Jul 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. Function DistanceAtTime {
  2. Parameter T.
  3. Parameter TargetDestination.
  4.  
  5. return ((positionat(ship, T) - positionat(TargetDestination, T)):mag).
  6. }
  7.  
  8. Function ClosestApproachGetter {
  9.  
  10. Parameter PeriodPrecision.
  11. Parameter T.
  12. Parameter ScoreToBeat.
  13.  
  14. set BestCandidate to T.
  15.  
  16. set Candidates to list().
  17. set StandardStepSize to ScoringNode:orbit:period * PeriodPrecision.
  18. Set StepSize to StandardStepSize.
  19. set EndFunction to 0.
  20.  
  21. until EndFunction = 10 {
  22. Candidates:add(list(T + StepSize, TargetDestination)).
  23. set StepSize to StepSize + StandardStepSize.
  24. set EndFunction to EndFunction + 1.
  25. }
  26.  
  27. Set StepSize to StandardStepSize.
  28. set EndFunction to 0.
  29.  
  30. until EndFunction = 10 {
  31. Candidates:add(list(T - StepSize, TargetDestination)).
  32. set StepSize to StepSize + StandardStepSize.
  33. set EndFunction to EndFunction + 1.
  34. }
  35.  
  36. for Candidate in Candidates {
  37. set CandidateScore to DistanceAtTime(Candidate[0], Candidate[1]).
  38. if CandidateScore < ScoreToBeat {
  39. set ScoreToBeat to CandidateScore.
  40. set BestCandidate to Candidate[0].
  41. set ClosestApproach to DistanceAtTime(Candidate[0], Candidate[1]).
  42. }
  43. }
  44. }
  45.  
  46.  
  47. Function ClosestApproachRefiner {
  48. Parameter TargetDestination.
  49.  
  50. set ScoringNode to nextnode.
  51. set T to time:seconds + 0.5 * ScoringNode:orbit:period.
  52. set ScoreToBeat to DistanceAtTime(T, TargetDestination).
  53. ClosestApproachGetter(0.05, T, ScoreToBeat).
  54.  
  55. set multiplier to 0.05.
  56.  
  57. until multiplier*ScoringNode:orbit:period < 1 {
  58. set multiplier to multiplier/10.
  59. ClosestApproachGetter(multiplier, BestCandidate, ClosestApproach).
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement