Rename lib/rendezvous to lib/target, adding target_ship() convenience function.

This commit is contained in:
Casper V. Kristensen 2019-03-01 23:02:19 +01:00
parent 2885d1a183
commit 296a7d0947
Signed by: caspervk
GPG key ID: 289CA03790535054
2 changed files with 40 additions and 28 deletions

View file

@ -1,28 +0,0 @@
@LAZYGLOBAL off.
run once "lib/node".
function relative_velocity {
//
// Return the relative orbital velocity between the ship and our target in the target's inertial frame of reference.
//
if not HASTARGET {
return V(0,0,0). // avoids 'has no target' errors upon docking
}
local t is TARGET.
if TARGET:istype("Part") { // e.g. if selected docking port as target
set t to TARGET:ship.
}
return SHIP:velocity:orbit - t:velocity:orbit.
}
function kill_relative_velocity {
parameter tolerance is 0.1.
if relative_velocity():mag > tolerance {
execute_burn(-relative_velocity()).
}
}

40
lib/target.ks Normal file
View file

@ -0,0 +1,40 @@
@LAZYGLOBAL off.
run once "lib/node".
function target_ship {
//
// Return the target vessel even though a docking port might have been selected as the target.
//
if TARGET:istype("Part") { // e.g. if selected docking port as target
return TARGET:ship.
}
return TARGET.
}
function relative_velocity {
//
// Return the relative orbital velocity between the ship and our target in the target's inertial frame of reference.
//
if not HASTARGET {
return V(0,0,0). // avoids 'has no target' errors upon docking
}
return SHIP:velocity:orbit - target_ship():velocity:orbit.
}
function kill_relative_velocity {
//
// Kill relative velocity to target if it is above tolerance.
//
parameter tolerance is 0.1.
if relative_velocity():mag < tolerance {
print "Relative velocity within tolerance of " + tolerance + " m/s".
return.
}
execute_burn(-relative_velocity()).
}