All pastes #190763 Raw Edit

Unnamed

public python v1 · immutable
·published 2006-10-04 09:08 UTC
rendered paste body
_encode64 = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_")_decode64 = {"a":0, "b":1, "c":2, "d":3, "e":4, "f":5, "g":6, "h":7, "i":8, "j":9, "k":10, "l":11, "m":12, "n":13, "o":14, "p":15, "q":16, "r":17, "s":18, "t":19, "u":20, "v":21, "w":22, "x":23, "y":24, "z":25, "A":26, "B":27, "C":28, "D":29, "E":30, "F":31, "G":32, "H":33, "I":34, "J":35, "K":36, "L":37, "M":38, "N":39, "O":40, "P":41, "Q":42, "R":43, "S":44, "T":45, "U":46, "V":47, "W":48, "X":49, "Y":50, "Z":51, "0":52, "1":53, "2":54, "3":55, "4":56, "5":57, "6":58, "7":59, "8":60, "9":61, "-":62, "_":63}class Cell(object):	passdef uncompressMap(sData, bForced=False):	cellArray = []	cellNum = 0	for i in xrange(0, len(sData), 10):		cellObj = uncompressCell(sData[i:i+10], bForced, 0)		cellObj.num = cellNum		cellNum += 1		cellArray.append(cellObj)	return cellArraydef uncompressCell(sData, bForced=False, nPermanentLevel=0):	oC = Cell()	dD = [_decode64[i] for i in sData]	oC.active = (dD[0] & 32) >> 5 == 1	if oC.active or bForced:            oC.nPermanentLevel = nPermanentLevel            oC.lineOfSight = dD[0] & 1 == 1            oC.layerGroundRot = (dD[1] & 48) >> 4            oC.groundLevel = dD[1] & 15            oC.movement = (dD[2] & 56) >> 3            oC.layerGroundNum = ((dD[2] & 7) << 6) + dD[3]            oC.groundSlope = (dD[4] & 60) >> 2            oC.layerGroundFlip = (dD[4] & 2) >> 1 == 1            oC.layerObject1Num = ((dD[4] & 1) << 12) + (dD[5] << 6) + dD[6]            oC.layerObject1Rot = (dD[7] & 48) >> 4            oC.layerObject1Flip = (dD[7] & 8) >> 3 == 1            oC.layerObject2Flip = (dD[7] & 4) >> 2 == 1            oC.layerObject2Interactive = (dD[7] & 2) >> 1 == 1            oC.layerObject2Num = ((dD[7] & 1) << 12) + (dD[8] << 6) + dD[9]            oC.layerObjectExternal = ""            oC.layerObjectExternalInteractive = False	return oCclass Step(object):	passdef compressPath(aFullPathData, bWithFirst=False):	sD = ""	lP = makeLightPath(aFullPathData, bWithFirst)	for i in lP:		sD += _encode64[i.dir & 7]		sD += _encode64[(i.num & 4032) >> 6]		sD += _encode64[i.num & 63]	return sDdef makeLightPath(aFullPath, bWithFirst=False):	aD = []	curDir = None	if bWithFirst:		aD.append(aFullPath[0])	for i in reversed(aFullPath):		if i.dir != curDir:			aD.insert(0, i)			curDir = i.dir	return aDdef extractFullPath(mapWidth, compressedData):	aT = []	for i in xrange(0, len(compressedData), 3):		tdir = _decode64[compressedData[i+0]]		tnu = _decode64[compressedData[i+1]]		tnl = _decode64[compressedData[i+2]]		tnum = ((tnu & 15) << 6) + tnl		tS = Step()		tS.dir = tdir		tS.num = tnum		aT.append(tS)	return makeFullPath(mapWidth, aT)def makeFullPath(mapWidth, aLightPath):	dirs = (1, mapWidth, mapWidth*2-1, mapWidth-1, -1, -mapWidth, -mapWidth*2+1, -(mapWidth - 1))	aF = []	curNum = aLightPath[0].num	aF.append(curNum)	for i in aLightPath[1:]:		tNum = i.num		tDir = i.dir		while aF[-1] != tNum:			curNum = curNum + dirs[tDir]			aF.append(curNum)		curNum = tNum	return aF