pioneerspacesim/pioneer — pull request #769 by Ziusudra (2011-11-03 06:55:34+00:00)
Title: Target Relative Set Speed (#462)

Activated by holding CTRL while targeting a body in WorldView by either clicking on the body or pressing Tab while the body is under the cross hair.

If a hyperspace arrival cloud is the set speed target when it's ship arrives, that ship becomes the set speed target. When a ship that is the set speed target hyperspaces, its departure cloud becomes the set speed target.

Attempts to match player's velocity (speed and direction of motion) to that of the body. Does not change orientation of the player's ship. It is left to the player to ensure that their ship is in an orientation where that velocity can be achieved/maintained.

Works across frames. If the target is accelerating, the player will have to adjust the set speed to maintain a relative velocity of zero. This effect is magnified by time acceleration. Ship orientation also can have an effect on actual relative velocity due to differences in thrust.

Test script:

```lua
local my_ship, planets

spawn = function ()
planets = Space.GetBodies(function (body) return body:isa("Planet") end)

my_ship = Space.SpawnShipNear('Hammerhead Heavy Freighter', Game.player, 1, 3)
my_ship:AddEquip('RUBBISH', 1000000)
end

go = function ()
local planet = planets[Engine.rand:Integer(1,#planets)]
my_ship:AIFlyTo(planet)
print('test_ship: '..my_ship.label..' flying to '..planet.label)
end

local onShipDestroyed = function (ship, attacker)
if my_ship == ship then
print('test_ship: '..ship.label..' destroyed by '..attacker.label)
my_ship = nil
end
end
EventQueue.onShipDestroyed:Connect(onShipDestroyed)
```