2 """<title>a magic tool that prettifies your levels for you</title>
5 usage: levelpretty map.tga in.tga out.tga
9 map.tga contains "base" tiles drawn in the background and pretty tiles drawn in
10 the foreground. it should contain all the knowldge needed to infer how to
13 in.tga contains a level drawn using all "base" tiles (except where the algorithm
14 doesn't work -- you can put in fancy tiles to fill in those spaces, the algorithm
15 will back-wards infer what "base" tile the fancy tile is a substitute for)
17 out.tga will be generated using the map.tga and the in.tga
19 (to edit in leveledit and switch between background and foreground press 't')
35 levelpretty takes a level drawn with "base" tiles and auto-magically (using the knowledge
36 supplied in map.tga) turns a basic level into a fancy level. this tool is useful for
37 rapid development of fancy looking levels that only have a few kinds of base tiles
38 but those base tiles look better when rendered using lots of fancier tiles.
43 from optparse import OptionParser
48 print 'psyco installed'
50 print 'psyco not installed'
52 from pgu.tilevid import Tilevid
56 [ 10, 1000,10000, 1000, 10],
57 [ 100,10000, 0,10000, 100],
58 [ 10, 1000,10000, 1000, 10],
64 width,height = len(l[0]),len(l)
65 if ty >= 0 and ty < height and tx >= 0 and tx < width: return l[ty][tx]
69 width,height = len(l[0]),len(l)
70 if ty >= 0 and ty < height and tx >= 0 and tx < width: return l[ty][tx]
75 width,height = len(l[0]),len(l)
76 if ty >= 0 and ty < height and tx >= 0 and tx < width:
79 if v in rmap: return rmap[v]
88 va,vb = a[y][x],b[y][x]
89 if va == vb: r += scoring[y][x]
90 else: r -= scoring[y][x]
93 usage = "usage: %prog map.tga in.tga out.tga"
94 parser = OptionParser(usage)
95 (opts, args) = parser.parse_args()
97 parser.error("incorrect number of arguments")
99 m_fname,i_fname, o_fname = args
102 m_level.tga_load_level(m_fname,1)
107 i_level.tga_load_level(i_fname,1)
111 o_level.tga_load_level(i_fname,1)
114 width,height = m_level.size
118 for y in xrange(0,height):
119 for x in xrange(0,width):
121 if v not in used: used.append(v)
127 k = (get2(bt,x,y),get2(bt,x,y-1),get2(bt,x+1,y),get2(bt,x,y+1),get2(bt,x-1,y))
128 if k == (0,0,0,0,0): continue
131 k = (get2(at,x,y),get2(at,x,y-1),get2(at,x+1,y),get2(at,x,y+1),get2(at,x-1,y))
132 if k == (0,0,0,0,0): continue
134 k = (get(at,x,y),get(at,x,y-1),get(at,x+1,y),get(at,x,y+1),get(at,x-1,y))
136 if k not in lookup: lookup[k] = []
137 lookup[k].append((x,y))
140 width,height = i_level.size
141 for y in xrange(0,height):
143 for x in xrange(0,width):
146 idata = [[get3(it,tx,ty) for tx in xrange(x-2,x+3)] for ty in xrange(y-2,y+3)]
147 k = (get3(it,x,y),get3(it,x,y-1),get3(it,x+1,y),get3(it,x,y+1),get3(it,x-1,y))
150 for xx,yy in lookup[k]:
151 adata = [[get(at,tx,ty) for tx in xrange(xx-2,xx+3)] for ty in xrange(yy-2,yy+3)]
153 _score = diff(idata,adata)
154 if _score > score: v,score = _v,_score
157 o_level.tga_save_level(o_fname) #save the o_fname