Skip to content

Instantly share code, notes, and snippets.

@Brianetta
Created December 5, 2011 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Brianetta/1433651 to your computer and use it in GitHub Desktop.
Save Brianetta/1433651 to your computer and use it in GitHub Desktop.
Pioneer script for flying to interesting places.
local dest
local range = 5 -- sectors, not light years
local getnexthop = function (dest)
local dX = dest.sectorX - Game.system.path.sectorX
local dY = dest.sectorY - Game.system.path.sectorY
local dZ = dest.sectorZ - Game.system.path.sectorZ
local dH = math.ceil(math.sqrt(dX*dX+dY*dY+dZ*dZ))
if math.ceil(dH) == 1 then
UI.Message('Final jump','Brian')
else
UI.Message(('At most {total} jumps to go'):interp({total = math.ceil(dH)}),'Brian')
end
local longhop
longhop = function (jumpdistance)
print("Jump distance: ",jumpdistance)
local multiplier = jumpdistance / dH
local X,Y,Z
X = math.ceil(dX * multiplier) + Game.system.path.sectorX
Y = math.ceil(dY * multiplier) + Game.system.path.sectorY
Z = math.ceil(dZ * multiplier) + Game.system.path.sectorZ
local OK,newdest = pcall(SystemPath.New,X,Y,Z,0)
if OK then
if Game.system.path:IsSameSystem(newdest) then
return longhop(jumpdistance +1)
else
return newdest
end
elseif jumpdistance > range then
return nil
else
return longhop(jumpdistance +1)
end
end
if dH <= 1 then
return dest
else
return longhop(1)
end
end
local givenewship = function ()
Game.player:SetShipType('Eagle MK-III')
Game.player:SetLabel('Pioneer-3')
Game.player:RemoveEquip("DRIVE_CLASS1")
Game.player:AddEquip("DRIVE_MIL3")
Game.player:AddEquip("MILITARY_FUEL",6)
end
local go_next = function (ship,station)
if ship and not ship:IsPlayer() then return end
local nexthop = getnexthop(dest)
if nexthop then
print('Next hop: ',nexthop:GetStarSystem().name)
Game.player:HyperspaceTo(nexthop)
end
end
local onEnterSystem = function(ship)
EventQueue.onShipUndocked:Disconnect(go_next)
if ship:IsPlayer() and ship.label == 'Pioneer-3' then
if ship:GetEquipCount('ENGINE','DRIVE_MIL3') < 1 then
UI.Message('Engine broke; replacing...','Brian')
ship:RemoveEquip('RUBBISH',ship:GetEquipCount('CARGO','RUBBISH'))
Game.player:AddEquip("DRIVE_MIL3")
end
if Game.system.path:IsSameSystem(dest) then
ship:RemoveEquip('RUBBISH',ship:GetEquipCount('CARGO','RUBBISH'))
ship:RemoveEquip('MILITARY_FUEL',ship:GetEquipCount('CARGO','MILITARY_FUEL'))
ship:RemoveEquip('DRIVE_MIL3',ship:GetEquipCount('ENGINE','DRIVE_MIL3'))
ship:AddEquip('AUTOPILOT')
ship:AddEquip('SCANNER')
ship:AddEquip('ATMOSPHERIC_SHIELDING')
UI.Message("There you go. You're on your own now.",'Brian')
ship:SetLabel('Pioneer 3')
else
local used_fuel = ship:GetEquipCount('CARGO','RADIOACTIVES')
ship:RemoveEquip('RADIOACTIVES',used_fuel)
ship:AddEquip('MILITARY_FUEL',used_fuel)
Timer:CallAt(Game.time+1,go_next)
end
end
end
local onChat = function (form, ref, option)
if option > 0 then
form:Clear()
dest = ({
SystemPath.New( -3125, 0, 0, 0 ),
SystemPath.New( 22, 4, 11, 0 ),
SystemPath.New( 0, 0, 53, 0 ),
SystemPath.New( -9, 1, -5, 0 ),
SystemPath.New( -28, -32, 15, 1 ),
SystemPath.New( 0, 0, 0, 0 ),
})[option]
givenewship()
form:SetMessage("Launch in your own time. Please don't break my ship in the meantime.")
form:RemoveAdvertOnClose()
EventQueue.onShipUndocked:Connect(go_next)
return
end
local brianetta = Character.New({
name = "Brian Ronald",
female = false,
title = "Pioneer Developer",
armour = false,
seed = 2397007322,
})
form:SetTitle('Where would you like to go?')
form:SetFace(brianetta)
form:SetMessage([[I can fly you to cool places. I'll replace your ship with
one of my own design, so if you care about your game, save
it now. The journey will begin the moment you launch. If you need to abort,
lose the fuel.
This does involve a fair amount of cheating, but I can't do anything
about the size of the galaxy. Some of the more remote destinations
will take a long time. A very long time. Also, unless there's a place
to land, you're pretty much going to be stuck there. Heh.]])
form:AddOption('The black hole in the middle',1)
form:AddOption('Werribee (the Australian system)',2)
form:AddOption('Polaris',3)
form:AddOption('Lambda Sagittarii (the nearest supergiant)',4)
form:AddOption('Canbewa (nearby hypergiant)',5)
form:AddOption('Sol',6)
end
local onCreateBB = function (station)
station:AddAdvert('Fly places with Brian!',onChat)
end
EventQueue.onEnterSystem:Connect(onEnterSystem)
EventQueue.onCreateBB:Connect(onCreateBB)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment