Created
February 4, 2012 01:10
-
-
Save Brianetta/1734205 to your computer and use it in GitHub Desktop.
Fly Places with Brian (generic edition)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local dest | |
local coordinate_choice | |
local choices | |
local brianetta = Character.New({ | |
name = "Brian Ronald", | |
female = false, | |
title = "Pioneer Developer", | |
armour = false, | |
seed = 2397007322, | |
}) | |
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 | |
Comms.Message('Final jump','Brian') | |
else | |
Comms.Message(('Something like {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_mk3') | |
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) | |
Event.Deregister("onShipUndocked",go_next) | |
Event.Deregister("onShipUndocked",go_next) | |
if ship:IsPlayer() and ship.label == 'Pioneer-3' then | |
if ship:GetEquipCount('ENGINE','DRIVE_MIL3') < 1 then | |
Comms.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') | |
ship:AddEquip('DRIVE_CLASS1') | |
ship:AddEquip('HYDROGEN',2) | |
Comms.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) | |
local SetFormMessage = function () | |
form:SetMessage(([[Welcome to Brian's really cheating fly-anywhere cheat. | |
Using this cheat will cost you your ship (I'll give you mine). | |
Please enter the sector coordinates of your destination. | |
Setting component {component}: ({X},{Y},{Z})]]):interp({component = coordinate_choice.component,X=coordinate_choice.X,Y=coordinate_choice.Y,Z=coordinate_choice.Z})) | |
end | |
local DoDigit = function (digit) | |
if coordinate_choice[coordinate_choice.component] == '_' then | |
coordinate_choice[coordinate_choice.component] = 0 | |
end | |
coordinate_choice[coordinate_choice.component] = coordinate_choice[coordinate_choice.component] * 10 + digit | |
SetFormMessage() | |
end | |
local SetSystem = function(systemNumber) | |
givenewship() | |
dest = choices[systemNumber] | |
form:Clear() | |
form:SetMessage("Launch in your own time. Please don't break my ship in the meantime.") | |
Event.Register("onShipUndocked",go_next) | |
end | |
local TopDigits = function () | |
form:Clear() | |
SetFormMessage() | |
if coordinate_choice.component == 'Z' | |
then | |
form:AddOption('Done',15) | |
else | |
form:AddOption(', (comma)',12) | |
end | |
form:AddOption('- (negative)',11) | |
form:AddOption('0 (zero)',10) | |
form:AddOption('1 (one)',1) | |
form:AddOption('2 (two)',2) | |
form:AddOption('3 (three)',3) | |
form:AddOption('4 (four)',4) | |
form:AddOption('5 (five)',5) | |
form:AddOption('More digits...',14) | |
end | |
local BottomDigits = function () | |
form:Clear() | |
SetFormMessage() | |
form:AddOption('2 (two)',2) | |
form:AddOption('3 (three)',3) | |
form:AddOption('4 (four)',4) | |
form:AddOption('5 (five)',5) | |
form:AddOption('6 (two)',6) | |
form:AddOption('7 (three)',7) | |
form:AddOption('8 (four)',8) | |
form:AddOption('9 (five)',9) | |
form:AddOption('More digits...',13) | |
end | |
(({ | |
[0] = function () | |
coordinate_choice={component='X',X='_',Y='_',Z='_'} | |
systemNumber = 0 | |
choices = {} | |
form:SetTitle('Where would you like to go?') | |
form:SetFace(brianetta) | |
TopDigits() | |
end, | |
[1] = function () DoDigit(1) end, | |
[2] = function () DoDigit(2) end, | |
[3] = function () DoDigit(3) end, | |
[4] = function () DoDigit(4) end, | |
[5] = function () DoDigit(5) end, | |
[6] = function () DoDigit(6) end, | |
[7] = function () DoDigit(7) end, | |
[8] = function () DoDigit(8) end, | |
[9] = function () DoDigit(9) end, | |
[10] = function () DoDigit(0) end, | |
[11] = function () | |
if coordinate_choice[coordinate_choice.component] == '_' then | |
coordinate_choice[coordinate_choice.component] = 0 | |
end | |
coordinate_choice[coordinate_choice.component] = coordinate_choice[coordinate_choice.component] * (-1) | |
SetFormMessage() | |
end, | |
[12] = function () | |
if coordinate_choice.component == 'X' and type(coordinate_choice.X) == 'number' | |
then | |
coordinate_choice.component = 'Y' | |
elseif coordinate_choice.component == 'Y' and type(coordinate_choice.Y) == 'number' | |
then | |
coordinate_choice.component = 'Z' | |
end | |
TopDigits() | |
end, | |
[13] = TopDigits, | |
[14] = BottomDigits, | |
[15] = function () | |
form:Clear() | |
if coordinate_choice.Z == '_' then | |
coordinate_choice.Z = 0 | |
end | |
form:SetMessage('Please choose your destination system.') | |
local OK,systemDest = true | |
local systemNumber = 0 | |
while OK do | |
OK,systemDest = pcall(SystemPath.New, | |
coordinate_choice.X, | |
coordinate_choice.Y, | |
coordinate_choice.Z, | |
systemNumber | |
) | |
if OK then | |
choices[systemNumber] = systemDest | |
form:AddOption(systemDest:GetStarSystem().name,systemNumber+16) | |
end | |
systemNumber = systemNumber + 1 | |
end | |
end, | |
[16] = function () SetSystem(0) end, | |
[17] = function () SetSystem(1) end, | |
[18] = function () SetSystem(2) end, | |
[19] = function () SetSystem(3) end, | |
[20] = function () SetSystem(4) end, | |
[21] = function () SetSystem(5) end, | |
[22] = function () SetSystem(6) end, | |
[23] = function () SetSystem(7) end, | |
[24] = function () SetSystem(8) end, | |
[25] = function () SetSystem(9) end, | |
})[option])() | |
end | |
local onCreateBB = function (station) | |
station:AddAdvert('Fly places with Brian!',onChat) | |
end | |
Event.Register("onEnterSystem",onEnterSystem) | |
Event.Register("onCreateBB",onCreateBB) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment