ID:142546
 
Code:
mob/verb/test_symbol_index(index as num)
var/symbols_length = (index == 1 ? 1 : round(log(52,index-1)) + 1)
. = ""
for(var/i = symbols_length-1, i >= 0, i--)
var/base_symbol = round((index-1) / (52**i))
usr << base_symbol
if(base_symbol < 26)
if(base_symbol == -1) . += "Z" //bugfix hack
else . += ascii2text(base_symbol+97)
else . += ascii2text(base_symbol+39)
index %= 52**i
usr << .


Problem description:
DMM files store map symbols in base-52, "numbered" from [a-zA-Z].

If you'll note the comment above, I had to apply a hack to the system because for the even multiples of 52**n (except 52!), the system produces a -1 result for every symbol after the first.

Could anyone help me fix this so I don't need the hack? I'm not sure I understand why it's coming up in the first place.


The procedure is intended to take an integer greater than zero and convert it into the DMM-format base-52.
I have this in pif_MapLoader's source. Here's the code I use. Unfortunately, it has a nested loop, but it's never shown significant slowdown for me.
#define num2letter(x) ascii2text((x) + 96 - ((x) > 26 && 58))

proc/combinations(x)
var/list/combinations[0]

var/amount = round(log(52, x)) + 1
if(52 ** (amount) == x) amount ++

var/list/num[amount]
for(var/a = 1 to num.len) num[a] = 1

for(var/a = 1 to x)
var/string
for(var/e in num) string = "[num2letter(e)][string]"
combinations += string

count_list(num)

for(var/a = 1 to combinations.len) condition[condition[a]] = combinations[a]