All pastes #836101 Raw Edit

slime73

public text v1 · immutable
#836101 ·published 2007-12-29 06:00 UTC
rendered paste body
declare('LocationID')

local xtable = {a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10, k=11, l=12, m=13, n=14, o=15, p=16}

function LocationID(str)
	str = str:lower():gsub('(%a-)-(%d-)$', '%1%2')
	local system, _, sector = str:match('^(%w+)(.-)(%S+)$')
	local sectorx, sectory = sector:match('^(%a)(%d+)$')
	sectorx = xtable[sectorx]
	sectory = (tonumber(sectory)-1)*16
	if tonumber(system) then system = tonumber(system) - 1
	else system = SystemNames[system] - 1 end
	local sectorid = (256*system) + (sectorx+sectory)
	return sectorid
end