Ejemplo n.º 1
0
 def __war3_setup_bytemaps__(self):
     heightmap = Bytemap(self.WC3map_xSize, self.WC3map_ySize)
     rampMap = Bytemap(self.WC3map_xSize, self.WC3map_ySize, init = 0, dataType = "B")
     
     # Not sure if the maximal height of a WC3 map is useful,
     # we will keep it in mind.
     maxHeight = 0
     
     for x in xrange(self.WC3map_xSize):
         for y in xrange(self.WC3map_ySize):
             index = y*self.WC3map_xSize + x
             tile =  self.wc3_mapinfo["info"][index]
             
             height = tile["layerHeight"]
             
             ramp_flag = (tile["flags"] & 0x1)
             rampMap.setVal(x, y, ramp_flag)
             
             
             ## voodoo magic, disabled for now until I understand it
             #The tilepoint "final height" you see on the WE is given by:
             #(ground_height - 0x2000 + (layer - 2)*0x0200)/4
             #height = tile["groundHeight"] - 0x2000 + ((tile["nibble2"] & 0xF) -2) *0x0200 / 4
             #if height < lowestHeight:
             #    lowestHeight = height
             
             if height > maxHeight: maxHeight = height
             heightmap.setVal(x, y, height)
     
     return heightmap, rampMap, maxHeight
Ejemplo n.º 2
0
 def __war3_setup_bytemaps__(self):
     heightmap = Bytemap(self.WC3map_xSize, self.WC3map_ySize)
     rampMap = Bytemap(self.WC3map_xSize, self.WC3map_ySize, init = 0, dataType = "B")
     
     # Not sure if the maximal height of a WC3 map is useful,
     # we will keep it in mind.
     maxHeight = 0
     
     for x in xrange(self.WC3map_xSize):
         for y in xrange(self.WC3map_ySize):
             index = y*self.WC3map_xSize + x
             tile = self.data.mapInfo["info"][index]
             
             height = tile["layerHeight"]
             
             ramp_flag = (tile["flags"] & 0x1)
             rampMap.setVal(x, y, ramp_flag)
             
             
             ## voodoo magic, disabled for now until I understand it
             #The tilepoint "final height" you see on the WE is given by:
             #(ground_height - 0x2000 + (layer - 2)*0x0200)/4
             #height = tile["groundHeight"] - 0x2000 + ((tile["nibble2"] & 0xF) -2) *0x0200 / 4
             #if height < lowestHeight:
             #    lowestHeight = height
             
             if height > maxHeight: maxHeight = height
             heightmap.setVal(x, y, height)
     
     return heightmap, rampMap, maxHeight
Ejemplo n.º 3
0
    def create_vmf(self):
        wc3map_xSize = self.base.WC3map_xSize
        wc3map_ySize = self.base.WC3map_ySize

        wc3_tileSize = self.base.wc3_tileSize
        wc3_tileHeight = self.base.wc3_tileHeight
        blobAffinity = Bytemap(wc3map_xSize, wc3map_xSize)
        bloblist = []

        # We iterate a second time to group tiles of similar height together.
        # rectangularCheck uses a brute force approach.
        for x in xrange(wc3map_xSize):
            for y in xrange(wc3map_ySize):

                localHeight = self.base.WC3map_heightmap.getVal(x, y)

                # We check if the tile already belongs to a group.
                # -1 means no. If not equal to -1, we skip it.
                if blobAffinity.getVal(x, y) == -1:
                    endX, endY = self.rectangularCheck(x, y, wc3map_xSize,
                                                       wc3map_ySize,
                                                       localHeight,
                                                       blobAffinity)

                    for ix in xrange(x, endX):
                        for iy in xrange(y, endY):
                            # We set the value for the coordinates to 1 to signal that
                            # they belong to a "blob", i.e. a group of planes
                            blobAffinity.setVal(ix, iy, 1)

                    bloblist.append(((x, y), (endX, endY), localHeight))

        print "Preparations are done, now creating the planes..."

        for index, plane in enumerate(bloblist):
            startCoords, endCoords, height = plane

            startX, startY = startCoords
            endX, endY = endCoords

            boxWidth = endX - startX
            boxLength = endY - startY

            height = (
                height
            ) * wc3_tileHeight  # Each layer of the map has a height of 64 units

            # midX and midY: middle of box that spans from startX;startY to endX;endY
            midX = startX + boxWidth / 2.0  # Very important, DO NOT ROUND: causes issues with random overlapping
            midY = startY + boxLength / 2.0

            # A little bit of optimization, only draw the block if it has a non-zero height
            # (Hammer only likes blocks with non-zero dimensions, for good reason)
            if height > 0:
                vert = vmflib.types.Vertex(
                    (midX * wc3_tileSize) - self.base.vmfmap_xMidOffset,
                    (midY * wc3_tileSize) - self.base.vmfmap_yMidOffset,
                    0 + (height // 2))
                block = tools.Block(origin=vert,
                                    dimensions=(boxWidth * wc3_tileSize,
                                                boxLength * wc3_tileSize,
                                                height))

                if self.texture == "dota2":
                    block.set_material("nature/dirt_grass_00")
                else:
                    block.set_material("brick/brick_ext_08")

                self.base.m.world.children.append(block)

        print "Building map finished."
Ejemplo n.º 4
0
 m.world.children.append(skybox_right)
 m.world.children.append(skybox_ceiling)
 
 
 print "Done adding walls, now to do the map itself..." 
 
 try:
     os.makedirs('./output')
     print "created output directory"
 except OSError as error:
     print str(error)
 
 
 bloblist = []
 
 heightmap = Bytemap(data.mapInfo["width"], data.mapInfo["height"])
 rampMap = Bytemap(data.mapInfo["width"], data.mapInfo["height"], init = 0, dataType = "B")
 #blobAffinity = Bytemap(data.mapInfo["width"], data.mapInfo["height"])
     
     
 # Iterate once over the map to store the height of each tile.
 # This way, we avoid having to use the binary AND every time 
 # we try to retrieve the height of a tile
 
 #lowestHeight = 10000000
 
 for x in xrange(data.mapInfo["width"]):
     for y in xrange(data.mapInfo["height"]):
         index = y*data.mapInfo["width"] + x
         tile = data.mapInfo["info"][index]
         
Ejemplo n.º 5
0
    def create_vmf(self):
        wc3map_xSize = self.base.WC3map_xSize
        wc3map_ySize = self.base.WC3map_ySize
        
        wc3_tileSize = self.base.wc3_tileSize
        wc3_tileHeight = self.base.wc3_tileHeight
        blobAffinity = Bytemap(wc3map_xSize, wc3map_xSize)
        bloblist = []
        
        # We iterate a second time to group tiles of similar height together.
        # rectangularCheck uses a brute force approach.
        for x in xrange(wc3map_xSize):
            for y in xrange(wc3map_ySize):
                
                localHeight = self.base.WC3map_heightmap.getVal(x,y)
                
                # We check if the tile already belongs to a group.
                # -1 means no. If not equal to -1, we skip it.
                if blobAffinity.getVal(x, y) == -1:
                    endX, endY = self.rectangularCheck(x, y,
                                                       wc3map_xSize, wc3map_ySize,
                                                       localHeight, blobAffinity)
                    
                    for ix in xrange(x, endX):
                        for iy in xrange(y, endY):
                            # We set the value for the coordinates to 1 to signal that
                            # they belong to a "blob", i.e. a group of planes
                            blobAffinity.setVal(ix, iy, 1) 
                    
                    bloblist.append( ((x,y), (endX, endY), localHeight) )
        
        
        print "Preparations are done, now creating the planes..."

        for index, plane in enumerate(bloblist):
            startCoords, endCoords, height = plane
            
            startX, startY = startCoords
            endX, endY = endCoords
            
            boxWidth = endX-startX
            boxLength = endY-startY
            
            height = (height)*wc3_tileHeight # Each layer of the map has a height of 64 units
            
            # midX and midY: middle of box that spans from startX;startY to endX;endY
            midX = startX + boxWidth/2.0 # Very important, DO NOT ROUND: causes issues with random overlapping
            midY = startY + boxLength/2.0
            
            # A little bit of optimization, only draw the block if it has a non-zero height
            # (Hammer only likes blocks with non-zero dimensions, for good reason)
            if height > 0:
                vert = vmflib.types.Vertex((midX*wc3_tileSize)-self.base.vmfmap_xMidOffset, 
                                           (midY*wc3_tileSize)-self.base.vmfmap_yMidOffset, 
                                           0+(height//2))
                block = tools.Block(origin = vert, dimensions=(boxWidth*wc3_tileSize, boxLength*wc3_tileSize, height))
                
                if self.texture == "dota2":
                    block.set_material("nature/dirt_grass_00")
                else:
                    block.set_material("brick/brick_ext_08")
                
                self.base.m.world.children.append(block)
    

        print "Building map finished."