Last active
June 4, 2017 11:48
-
-
Save Upliner/1ee943594bd9fb43bed9949e60316da9 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
import sys | |
from struct import unpack | |
typs = [False,"Wall","SmashWall","InvisibleTrap","JetPackPickup","RiflePickup","OneWayer",False, False,"Detonation_button","Teleport","AntiAir","VisibleTrap","InactiveTrap","Wall","Railing","Railing","Railing"] | |
zmap = [0,150] + [0] * 20 | |
zmap[14] = 450 | |
zmap[16] = 300 | |
zmap[17] = 300 | |
if len(sys.argv)<2: | |
print("Usage: map2csv file.map") | |
i = 1 | |
fmt = "maz" | |
if sys.argv[1] == '-c': | |
i = 2 | |
fmt="csv" | |
fn = sys.argv[i] | |
mapf = open(fn,"rb") | |
m = bytearray(mapf.read(16000)) | |
expos = unpack("H",mapf.read(2))[0]-1 | |
mapf.close() | |
outf = open(fn[:-3]+fmt,"w") | |
if fmt == "csv": | |
outf.write('---,Type,Location,TargetLocation\n') | |
idx = 1 | |
def wrobj(typ,x,y,z,tx,ty,tz): | |
global idx | |
if fmt == "csv": | |
outf.write('%i,%s,"(X=%i,Y=%i,Z=%i)","(X=%i,Y=%i,Z=%i)"\n' % (idx, typ, x, y, z, tx, ty, tz)) | |
else: | |
outf.write('%i,%s,%i,%i,%i,%i,%i,%i\n' % (idx, typ, x, y, z, tx, ty, tz)) | |
idx += 1 | |
def getxy(i): | |
return (i % 80 * 300 + 150, i // 80 * 300 + 150) | |
def gettxy(i): | |
return (max(m[i*4+1] * 300 - 150, 0), max(m[i*4+2] * 300 - 150, 0)) | |
ex_x, ex_y = getxy(expos) | |
wrobj("Exit",ex_x,ex_y,0,0,0,0) | |
doors = [] | |
keys = [] | |
for i in range(4000): | |
t = m[i*4] | |
if t == 7: | |
doors.append(i) | |
elif t == 8: | |
keys.append(i) | |
elif t == 9: | |
m[(((m[i*4+2])-1)*80+m[i*4+1]-1)*4] = 0 | |
for i in range(4000): | |
t = m[i*4] | |
typ = typs[t] | |
if typ == None: print("Warning: unknown type %i" % t) | |
if not typ: continue | |
x, y = getxy(i) | |
z = zmap[t] | |
tx, ty = gettxy(i) | |
tz = 0 | |
if t == 9: | |
tz = 150 | |
elif t == 10: | |
tt = m[(((m[i*4+2])-1)*80+m[i*4+1]-1)*4] | |
if tt == 1 or tt == 2 or tt == 17: | |
tz = 300 | |
elif tt == 14: | |
tz = 600 | |
if t == 14 or t == 17: | |
wrobj("Wall",x,y,150,0,0,0) | |
wrobj(typ,x,y,z,tx,ty,tz) | |
for i in doors: | |
x,y = getxy(i) | |
wrobj("SKEY_Door",x,y,0,0,0,0) | |
for i in keys: | |
x,y = getxy(i) | |
tx,ty = gettxy(i) | |
wrobj("SKEY",x,y,0,tx,ty,0) | |
outf.close() |
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
#!/usr/bin/python | |
import sys | |
from struct import unpack | |
typs = [False,"Wall","SmashWall","InvisibleTrap","JetPackPickup","RiflePickup","OneWayer",False, False,"Detonation_button","Teleport","AntiAir","VisibleTrap","InactiveTrap","Wall","RailingDown","Railing","Railing"] + [None] * 100 | |
typs[100]="Exit" | |
zmap = [0,150] + [0] * 100 | |
zmap[14] = 450 | |
if len(sys.argv)<2: | |
print("Usage: map2csv file.map") | |
i=1 | |
fmt = "maz" | |
if sys.argv[1] == '-c': | |
i = 2 | |
fmt="csv" | |
fn = sys.argv[i] | |
mapf = open(fn,"rb") | |
maxx, startx, maxy, starty, maxz, startz = tuple(bytearray(mapf.read(6))) | |
m = bytearray(mapf.read(maxx*maxy*maxz*4)) | |
mapf.close() | |
outf = open(fn[:-4]+fmt,"w") | |
if fmt=="csv": | |
outf.write('---,Type,Location,TargetLocation\n') | |
idx = 1 | |
def wrobj(typ,x,y,z,tx,ty,tz): | |
global idx | |
if fmt == "csv": | |
outf.write('%i,%s,"(X=%i,Y=%i,Z=%i)","(X=%i,Y=%i,Z=%i)"\n' % (idx, typ, x, y, z, tx, ty, tz)) | |
else: | |
outf.write('%i,%s,%i,%i,%i,%i,%i,%i\n' % (idx, typ, x, y, z, tx, ty, tz)) | |
idx += 1 | |
def getxyz(i): | |
return (i % maxx * 300 + 150, i // maxx % maxy * 300 + 150, i // maxx // maxy * 300) | |
def gettxyz(i): | |
return (max(m[i*4+1] * 300 - 150, 0), max(m[i*4+2] * 300 - 150, 0), m[i*4+3] * 300) | |
while m[(startz*maxx*maxy+starty*maxx+startx)*4] == 1: | |
startz += 1 | |
wrobj("PlayerStart",startx * 300 + 150,starty * 300 + 150,startz * 300,0,0,0) | |
doors = [] | |
keys = [] | |
for i in range(maxx*maxy*maxz): | |
t = m[i*4] | |
if t == 7: | |
doors.append(i) | |
elif t == 8: | |
keys.append(i) | |
elif t == 9: | |
m[(((m[i*4+2])-1)*80+m[i*4+1]-1)*4] = 0 | |
for i in range(maxx*maxy*maxz): | |
t = m[i*4] | |
typ = typs[t] | |
if typ == None: print("Warning: unknown type %i" % t) | |
if not typ: continue | |
x, y, z = getxyz(i) | |
z += zmap[t] | |
tx, ty, tz = gettxyz(i) | |
if t == 9: | |
tz += 150 | |
elif t == 10: | |
tt = m[(((m[i*4+2])-1)*80+m[i*4+1]-1)*4] | |
if tt == 1 or tt == 2 or tt == 17: | |
tz += 300 | |
elif tt == 14: | |
tz += 600 | |
if t == 14 or t == 17: | |
wrobj("Wall",x,y,z+150,0,0,0) | |
wrobj(typ,x,y,z,tx,ty,tz) | |
for i in doors: | |
x,y,z = getxyz(i) | |
wrobj("SKEY_Door",x,y,z,0,0,0) | |
for i in keys: | |
x,y,z = getxyz(i) | |
tx,ty,tz = gettxyz(i) | |
wrobj("SKEY",x,y,z,tx,ty,tz) | |
outf.close() |
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
from distutils.core import setup | |
import py2exe | |
setup(console=['map2maz.py']) | |
setup(console=['mapa2maz.py']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment