예제 #1
0
 def GetAxialCoordinateFromUIPosition(self, x, y):
     px_hx = hexUtil.pixel_to_hex(x, y, self.hexGridSize, isFlatTop=self.isFlatTop)
     ax_cu = hexUtil.axial_to_cube_coordinate(*px_hx)
     ax_cu_rounded = hexUtil.hex_round(*ax_cu)
     if self.isFlatTop:
         cu_ax = hexUtil.cube_to_odd_q_axial_coordinate(*ax_cu_rounded)
     else:
         cu_ax = hexUtil.cube_to_odd_r_axial_coordinate(*ax_cu_rounded)
     return cu_ax
예제 #2
0
 def GetAxialCoordinateFromUIPosition(self, x, y):
     px_hx = hexUtil.pixel_to_hex(x,
                                  y,
                                  self.hexGridSize,
                                  isFlatTop=self.isFlatTop)
     ax_cu = hexUtil.axial_to_cube_coordinate(*px_hx)
     ax_cu_rounded = hexUtil.hex_round(*ax_cu)
     if self.isFlatTop:
         cu_ax = hexUtil.cube_to_odd_q_axial_coordinate(*ax_cu_rounded)
     else:
         cu_ax = hexUtil.cube_to_odd_r_axial_coordinate(*ax_cu_rounded)
     return cu_ax
예제 #3
0
def PrepareCombinedMap(objectID):
    rootLayout = GetPlotDataForObject(objectID)
    rootLayout, rootsize = AutoFitLayout(rootLayout)
    isFlatTop = True
    maxChildSize = 0
    for childID, childGridPosition in rootLayout.iteritems():
        childLayout = GetPlotDataForObject(childID)
        childLayout, size = AutoFitLayout(childLayout)
        maxChildSize = max(maxChildSize, size)

    maxOffset = 0
    layoutData = {}
    connectionData = []
    exitConnectionData = []
    for childID, childGridPosition in rootLayout.iteritems():
        column, row = childGridPosition
        cX, cY = hexUtil.hex_slot_center_position(column, row, isFlatTop, maxChildSize / 2)
        px_hx = hexUtil.pixel_to_hex(cX, cY, 1, isFlatTop)
        ax_cu = hexUtil.axial_to_cube_coordinate(*px_hx)
        ax_cu_rounded = hexUtil.hex_round(*ax_cu)
        cu_ax = hexUtil.cube_to_odd_q_axial_coordinate(*ax_cu_rounded)
        childLayout = GetPlotDataForObject(childID)
        childLayout, size = AutoFitLayout(childLayout)
        connectionData += uicore.mapConnectionDataByID.get(childID, [])
        for grandChildID, grandChildGridPosition in childLayout.iteritems():
            childColumn = cu_ax[0] + grandChildGridPosition[0]
            childRow = cu_ax[1] + grandChildGridPosition[1]
            layoutData[grandChildID] = (childColumn, childRow)
            maxOffset = max(maxOffset, childColumn, abs(childColumn), childRow, abs(childRow))

    connections = uicore.mapExitConnectionsByID.get(objectID, None)
    if connections:
        for fromID, fromParentID, toID, toParentID in connections:
            exitConnectionData.append((fromID, toID))

    combinedLayout, size = AutoFitLayout(layoutData)
    return (combinedLayout,
     connectionData,
     exitConnectionData,
     size)
예제 #4
0
def PrepareCombinedMap(objectID):
    rootLayout = GetPlotDataForObject(objectID)
    rootLayout, rootsize = AutoFitLayout(rootLayout)
    isFlatTop = True
    maxChildSize = 0
    for childID, childGridPosition in rootLayout.iteritems():
        childLayout = GetPlotDataForObject(childID)
        childLayout, size = AutoFitLayout(childLayout)
        maxChildSize = max(maxChildSize, size)

    maxOffset = 0
    layoutData = {}
    connectionData = []
    exitConnectionData = []
    for childID, childGridPosition in rootLayout.iteritems():
        column, row = childGridPosition
        cX, cY = hexUtil.hex_slot_center_position(column, row, isFlatTop,
                                                  maxChildSize / 2)
        px_hx = hexUtil.pixel_to_hex(cX, cY, 1, isFlatTop)
        ax_cu = hexUtil.axial_to_cube_coordinate(*px_hx)
        ax_cu_rounded = hexUtil.hex_round(*ax_cu)
        cu_ax = hexUtil.cube_to_odd_q_axial_coordinate(*ax_cu_rounded)
        childLayout = GetPlotDataForObject(childID)
        childLayout, size = AutoFitLayout(childLayout)
        connectionData += uicore.mapConnectionDataByID.get(childID, [])
        for grandChildID, grandChildGridPosition in childLayout.iteritems():
            childColumn = cu_ax[0] + grandChildGridPosition[0]
            childRow = cu_ax[1] + grandChildGridPosition[1]
            layoutData[grandChildID] = (childColumn, childRow)
            maxOffset = max(maxOffset, childColumn, abs(childColumn), childRow,
                            abs(childRow))

    connections = uicore.mapExitConnectionsByID.get(objectID, None)
    if connections:
        for fromID, fromParentID, toID, toParentID in connections:
            exitConnectionData.append((fromID, toID))

    combinedLayout, size = AutoFitLayout(layoutData)
    return (combinedLayout, connectionData, exitConnectionData, size)
예제 #5
0
    def PreparePathFinder(self):
        xStep, yStep = hexUtil.hex_slot_size(self.isFlatTop, self.hexGridSize / 2.0)
        xRange = int(self.width / xStep)
        yRange = int(self.height / yStep)
        xRange = xRange - xRange % 3 + 3
        yRange = yRange - yRange % 3 + 3
        pathMap = pyEvePathfinder.EveMap()
        pathMap.CreateRegion(-1)
        pathMap.CreateConstellation(-2, -1)
        self.pathMap = pathMap
        pathfinder = EvePathfinderCore(pathMap)
        pathfinderState = HexMapPathfinderInterface()
        self.avoidPathFinderState = HexMapPathfinderInterface()

        def ConvertPathFinderIDMock(ret):
            return ret

        self.pathfinderHandler = ClientPathfinder(pathfinder, pathfinderState, self.avoidPathFinderState, ConvertPathFinderIDMock, ConvertPathFinderIDMock)
        self.avoidPathFinderState.blockedSpots = []
        self.avoidPathFinderState.usedSpots = []
        if getattr(self, 'pathFindingPairs', None):
            for i in xrange(yRange * xRange):
                pathMap.CreateSolarSystem(i, -2, -1)

            self.AddToPathFinding(self.pathFindingPairs)
            return
        self.column_row_to_pathfinder = column_row_to_pathfinder = {}
        self.pathfinder_to_xy = pathfinder_to_xy = []
        self.pathfinderIndexGrid = indexGrid = []
        self.pathFindingPairs = pathFindingPairs = set()
        self.pathFindingPairSequence = pathFindingPairSequence = {}
        showDebug = not self.isChild and settings.user.ui.Get('mapDebugSubdivision', 0)
        self.pathfinderSize = (xRange, yRange)
        i = 0
        for y in xrange(yRange):
            row = []
            indexGrid.append(row)
            yOdd = y & 1
            for x in xrange(xRange):
                row.append(i)
                posX = x * xStep
                posY = y * yStep
                if y % 2:
                    posX += xStep / 2
                isPrimary = not (x - yOdd + self.mapsize / 2 % 3) % 3
                if isPrimary:
                    px_hx = hexUtil.pixel_to_hex(posX - self.width / 2, posY - self.height / 2, self.hexGridSize, isFlatTop=self.isFlatTop)
                    ax_cu = hexUtil.axial_to_cube_coordinate(*px_hx)
                    ax_cu_rounded = hexUtil.hex_round(*ax_cu)
                    cu_ax = hexUtil.cube_to_odd_q_axial_coordinate(*ax_cu_rounded)
                    column_row_to_pathfinder[cu_ax] = i
                for cMod, rMod in ((-1, 0), (-1 + yOdd, -1), (yOdd, -1)):
                    cIndex = x + cMod
                    rIndex = y + rMod
                    if rIndex >= 0 and cIndex >= 0:
                        try:
                            pathFindingPairs.add((i, indexGrid[rIndex][cIndex]))
                        except IndexError:
                            pass

                if showDebug:
                    if isPrimary:
                        textColor = (1, 0, 0, 1)
                    else:
                        textColor = (0, 1, 0, 1)
                    EveLabelSmall(parent=self, text=str(i), left=posX - self.width / 2, top=posY - self.height / 2, align=uiconst.CENTER, color=textColor)
                pathfinder_to_xy.append((posX, posY))
                pathMap.CreateSolarSystem(i, -2, -1)
                i += 1

        self.AddToPathFinding(self.pathFindingPairs, showDebug)
예제 #6
0
    def PreparePathFinder(self):
        xStep, yStep = hexUtil.hex_slot_size(self.isFlatTop,
                                             self.hexGridSize / 2.0)
        xRange = int(self.width / xStep)
        yRange = int(self.height / yStep)
        xRange = xRange - xRange % 3 + 3
        yRange = yRange - yRange % 3 + 3
        pathMap = pyEvePathfinder.EveMap()
        pathMap.CreateRegion(-1)
        pathMap.CreateConstellation(-2, -1)
        self.pathMap = pathMap
        pathfinder = EvePathfinderCore(pathMap)
        pathfinderState = HexMapPathfinderInterface()
        self.avoidPathFinderState = HexMapPathfinderInterface()

        def ConvertPathFinderIDMock(ret):
            return ret

        self.pathfinderHandler = ClientPathfinder(pathfinder, pathfinderState,
                                                  self.avoidPathFinderState,
                                                  ConvertPathFinderIDMock,
                                                  ConvertPathFinderIDMock)
        self.avoidPathFinderState.blockedSpots = []
        self.avoidPathFinderState.usedSpots = []
        if getattr(self, 'pathFindingPairs', None):
            for i in xrange(yRange * xRange):
                pathMap.CreateSolarSystem(i, -2, -1)

            self.AddToPathFinding(self.pathFindingPairs)
            return
        self.column_row_to_pathfinder = column_row_to_pathfinder = {}
        self.pathfinder_to_xy = pathfinder_to_xy = []
        self.pathfinderIndexGrid = indexGrid = []
        self.pathFindingPairs = pathFindingPairs = set()
        self.pathFindingPairSequence = pathFindingPairSequence = {}
        showDebug = not self.isChild and settings.user.ui.Get(
            'mapDebugSubdivision', 0)
        self.pathfinderSize = (xRange, yRange)
        i = 0
        for y in xrange(yRange):
            row = []
            indexGrid.append(row)
            yOdd = y & 1
            for x in xrange(xRange):
                row.append(i)
                posX = x * xStep
                posY = y * yStep
                if y % 2:
                    posX += xStep / 2
                isPrimary = not (x - yOdd + self.mapsize / 2 % 3) % 3
                if isPrimary:
                    px_hx = hexUtil.pixel_to_hex(posX - self.width / 2,
                                                 posY - self.height / 2,
                                                 self.hexGridSize,
                                                 isFlatTop=self.isFlatTop)
                    ax_cu = hexUtil.axial_to_cube_coordinate(*px_hx)
                    ax_cu_rounded = hexUtil.hex_round(*ax_cu)
                    cu_ax = hexUtil.cube_to_odd_q_axial_coordinate(
                        *ax_cu_rounded)
                    column_row_to_pathfinder[cu_ax] = i
                for cMod, rMod in ((-1, 0), (-1 + yOdd, -1), (yOdd, -1)):
                    cIndex = x + cMod
                    rIndex = y + rMod
                    if rIndex >= 0 and cIndex >= 0:
                        try:
                            pathFindingPairs.add(
                                (i, indexGrid[rIndex][cIndex]))
                        except IndexError:
                            pass

                if showDebug:
                    if isPrimary:
                        textColor = (1, 0, 0, 1)
                    else:
                        textColor = (0, 1, 0, 1)
                    EveLabelSmall(parent=self,
                                  text=str(i),
                                  left=posX - self.width / 2,
                                  top=posY - self.height / 2,
                                  align=uiconst.CENTER,
                                  color=textColor)
                pathfinder_to_xy.append((posX, posY))
                pathMap.CreateSolarSystem(i, -2, -1)
                i += 1

        self.AddToPathFinding(self.pathFindingPairs, showDebug)