Beispiel #1
0
    def test_suit_points(self):
        store = DNAStorage()

        point1 = DNASuitPoint(5, DNASuitPoint.STREET_POINT,
                              Point3(100, 20, 0.5))
        point2 = DNASuitPoint(10, DNASuitPoint.STREET_POINT,
                              Point3(100, 0, 0.5))
        point3 = DNASuitPoint(15, DNASuitPoint.FRONT_DOOR_POINT,
                              Point3(100, -20, 0.5), 10)

        store.storeSuitPoint(point1)
        store.storeSuitPoint(point2)
        store.storeSuitPoint(point3)

        self.assertEqual(store.getNumSuitPoints(), 3)
        self.assertEqual(store.getSuitPointAtIndex(0), point1)
        self.assertEqual(store.getSuitPointAtIndex(1), point2)
        self.assertEqual(store.getSuitPointAtIndex(2), point3)
        self.assertEqual(store.getSuitPointWithIndex(5), point1)
        self.assertEqual(store.getSuitPointWithIndex(10), point2)
        self.assertEqual(store.getSuitPointWithIndex(15), point3)

        # Test invalid index
        self.assertEqual(store.getSuitPointWithIndex(1000), None)

        # Test suit edges
        edges = ((5, 10, 2301), (10, 15, 2302), (15, 5, 2303))

        for edge in edges:
            store.storeSuitEdge(*edge)

        for edge in edges:
            dna_edge = store.getSuitEdge(edge[0], edge[1])
            self.assertTrue(dna_edge is not None)
            self.assertEqual(dna_edge.getStartPoint(), store.getSuitPointWithIndex(edge[0]))
            self.assertEqual(dna_edge.getEndPoint(), store.getSuitPointWithIndex(edge[1]))
            self.assertEqual(dna_edge.getZoneId(), edge[2])
            self.assertEqual(store.getSuitEdgeZone(edge[0], edge[1]), edge[2])

        adj_points = store.getAdjacentPoints(point1)
        self.assertEqual(adj_points.getNumPoints(), 1)
        self.assertEqual(adj_points.getPoint(0), point2)
        self.assertEqual(store.getSuitEdgeTravelTime(5, 10, 5), 4)
        self.assertEqual(store.getSuitEdgeTravelTime(10, 15, 5), 4)
        self.assertEqual(store.getSuitEdgeTravelTime(15, 5, 5), 8)

        # Test suit path
        path = store.getSuitPath(point1, point3, 1, 10)
        self.assertEqual(path.getNumPoints(), 3)
        self.assertEqual(path.getPoint(0), point1)
        self.assertEqual(path.getPoint(1), point2)
        self.assertEqual(path.getPoint(2), point3)

        # Test invalid values
        store.storeSuitEdge(1, 2, 2800)
        self.assertEqual(store.getSuitEdge(1, 2), None)
        self.assertEqual(store.getSuitEdge(145, 13442), None)
        self.assertEqual(store.getSuitEdgeTravelTime(1, 2, 5), 0)
        self.assertEqual(repr(store.getSuitEdgeTravelTime(10, 15, 0)), 'inf')  # Division by 0

        point4 = DNASuitPoint(400, DNASuitPoint.STREET_POINT, Point3(0, 0, 0))
        self.assertEqual(store.getSuitPath(point4, point2, 1, 10), None)

        # Reset
        store.resetSuitPoints()
        self.assertEqual(store.getSuitPointWithIndex(5), None)
        self.assertEqual(store.getSuitPointWithIndex(10), None)
        self.assertEqual(store.getSuitPointWithIndex(15), None)
        self.assertTrue(store.discoverContinuity())
Beispiel #2
0
    def test_suit_points(self):
        store = DNAStorage()

        point1 = DNASuitPoint(5, DNASuitPoint.STREET_POINT,
                              Point3(100, 20, 0.5))
        point2 = DNASuitPoint(10, DNASuitPoint.STREET_POINT,
                              Point3(100, 0, 0.5))
        point3 = DNASuitPoint(15, DNASuitPoint.FRONT_DOOR_POINT,
                              Point3(100, -20, 0.5), 10)

        store.storeSuitPoint(point1)
        store.storeSuitPoint(point2)
        store.storeSuitPoint(point3)

        self.assertEqual(store.getNumSuitPoints(), 3)
        self.assertEqual(store.getSuitPointAtIndex(0), point1)
        self.assertEqual(store.getSuitPointAtIndex(1), point2)
        self.assertEqual(store.getSuitPointAtIndex(2), point3)
        self.assertEqual(store.getSuitPointWithIndex(5), point1)
        self.assertEqual(store.getSuitPointWithIndex(10), point2)
        self.assertEqual(store.getSuitPointWithIndex(15), point3)

        # Test invalid index
        self.assertEqual(store.getSuitPointWithIndex(1000), None)

        # Test suit edges
        edges = ((5, 10, 2301), (10, 15, 2302), (15, 5, 2303))

        for edge in edges:
            store.storeSuitEdge(*edge)

        for edge in edges:
            dna_edge = store.getSuitEdge(edge[0], edge[1])
            self.assertTrue(dna_edge is not None)
            self.assertEqual(dna_edge.getStartPoint(),
                             store.getSuitPointWithIndex(edge[0]))
            self.assertEqual(dna_edge.getEndPoint(),
                             store.getSuitPointWithIndex(edge[1]))
            self.assertEqual(dna_edge.getZoneId(), edge[2])
            self.assertEqual(store.getSuitEdgeZone(edge[0], edge[1]), edge[2])

        adj_points = store.getAdjacentPoints(point1)
        self.assertEqual(adj_points.getNumPoints(), 1)
        self.assertEqual(adj_points.getPoint(0), point2)
        self.assertEqual(store.getSuitEdgeTravelTime(5, 10, 5), 4)
        self.assertEqual(store.getSuitEdgeTravelTime(10, 15, 5), 4)
        self.assertEqual(store.getSuitEdgeTravelTime(15, 5, 5), 8)

        # Test suit path
        path = store.getSuitPath(point1, point3, 1, 10)
        self.assertEqual(path.getNumPoints(), 3)
        self.assertEqual(path.getPoint(0), point1)
        self.assertEqual(path.getPoint(1), point2)
        self.assertEqual(path.getPoint(2), point3)

        # Test invalid values
        store.storeSuitEdge(1, 2, 2800)
        self.assertEqual(store.getSuitEdge(1, 2), None)
        self.assertEqual(store.getSuitEdge(145, 13442), None)
        self.assertEqual(store.getSuitEdgeTravelTime(1, 2, 5), 0)
        self.assertEqual(repr(store.getSuitEdgeTravelTime(10, 15, 0)),
                         'inf')  # Division by 0

        point4 = DNASuitPoint(400, DNASuitPoint.STREET_POINT, Point3(0, 0, 0))
        self.assertEqual(store.getSuitPath(point4, point2, 1, 10), None)

        # Reset
        store.resetSuitPoints()
        self.assertEqual(store.getSuitPointWithIndex(5), None)
        self.assertEqual(store.getSuitPointWithIndex(10), None)
        self.assertEqual(store.getSuitPointWithIndex(15), None)
        self.assertTrue(store.discoverContinuity())
Beispiel #3
0
class SuitPlannerBase:
    notify = directNotify.newCategory('SuitPlannerBase')
    SuitHoodInfo = [[2100,               ##This is the Street name Sily Street
      5,                                 ##
      15,                                ##
      0,                                 ##
      5,                                 ##
      20,                                ##
      3,                                 ##
      (1,                                ##
       5,                                ##
       10,                               ##
       40,                               ##
       60,                               ##
       80),                              ##
      (20,                               ##This is the chance a Bossbot spawns
       20,                               ## Lawbot Spawn
       20,                               ##Cashbot
       20,                               ## Sellbot
       20),                              ## Secbot
      (1, 2, 3),                         ## These are the cog levels
      []],
     [2200,                              ##Loopy Lane
      3,
      10,
      0,
      5,
      15,
      3,
      (1,
       5,
       10,
       40,
       60,
       80),
      (10,
       60,
       10,
       10,
       10),
      (1, 2, 3),
      []],
     [2300,
      3,
      10,
      0,
      5,
      15,
      3,
      (1,
       5,
       10,
       40,
       60,
       80),
      (12,
       12,
       23,
       23,
       30),
      (1, 2, 3),
      []],
     [1100,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (80,
       10,
       0,
       0,
       10),
      (2, 3, 4),
      []],
     [1200,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (5,
       5,
       75,
       10,
       5),
      (3,
       4,
       5,
       6),
      []],
     [1300,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (30,
       30,
       12,
       12,
       16),
      (3,
       4,
       5,
       6),
      []],
     [3100,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (70,
       10,
       5,
       10,
       5),
      (5, 6, 7),
      []],
     [3200,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (10,
       20,
       20,
       25,
       25),
      (5, 6, 7, 8),
      []],
     [3300,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (5,
       80,
       5,
       5,
       5),
      (7, 8, 9),
      []],
     [4100,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (5,
       5,
       40,
       45,
       5),
      (2, 3, 4, 5),
      []],
     [4200,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (0,
       5,
       80,
       10,
       5),
      (3,
       4,
       5,
       6),
      []],
     [4300,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (35,
       35,
       10,
       10,
       10),
      (3,
       4,
       5,
       6),
      []],
     [5100,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (0,
       15,
       10,
       65,
       10),
      (2, 3, 4),
      []],
     [5200,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (7,
       45,
       0,
       13,
       35),
      (3,
       4,
       5,
       6),
      []],
     [5300,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (5,
       5,
       5,
       80,
       5),
      (3,
       4,
       5,
       6),
      []],
     [9100,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (20,
       20,
       20,
       20,
       20),
      (6,
       7,
       8,
       9),
      []],
     [9200,
      1,
      5,
      0,
      99,
      100,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (5,
       5,
       80,
       5,
       10),
      (6,
       7,
       8,
       9,
       10),
      []],
     [10000,
      3,
      15,
      0,
      5,
      15,
      3,
      (1,
       5,
       10,
       40,
       60,
       80),
      (100,
       0,
       0,
       0),
      (7, 8, 9, 10),
      []],
     [11000,
      3,
      15,
      0,
      0,
      0,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (0,
       0,
       0,
       100),
      (4, 5, 6),
      []],
     [11200,
      10,
      20,
      0,
      0,
      0,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (0,
       0,
       0,
       100),
      (4, 5, 6),
      []],
     [12000,
      10,
      20,
      0,
      0,
      0,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (0,
       0,
       100,
       0),
      (7, 8, 9),
      []],
     [13000,
      10,
      20,
      0,
      0,
      0,
      4,
      (1,
       5,
       10,
       40,
       60,
       80),
      (0,
       100,
       0,
       0),
      (8, 9, 10),
      []]]
    SUIT_HOOD_INFO_ZONE = 0
    SUIT_HOOD_INFO_MIN = 1
    SUIT_HOOD_INFO_MAX = 2
    SUIT_HOOD_INFO_BMIN = 3
    SUIT_HOOD_INFO_BMAX = 4
    SUIT_HOOD_INFO_BWEIGHT = 5
    SUIT_HOOD_INFO_SMAX = 6
    SUIT_HOOD_INFO_JCHANCE = 7
    SUIT_HOOD_INFO_TRACK = 8
    SUIT_HOOD_INFO_LVL = 9
    SUIT_HOOD_INFO_HEIGHTS = 10
    TOTAL_BWEIGHT = 0
    TOTAL_BWEIGHT_PER_TRACK = [0,
     0,
     0,
     0]
    TOTAL_BWEIGHT_PER_HEIGHT = [0,
     0,
     0,
     0,
     0]
    for currHoodInfo in SuitHoodInfo:
        weight = currHoodInfo[SUIT_HOOD_INFO_BWEIGHT]
        tracks = currHoodInfo[SUIT_HOOD_INFO_TRACK]
        levels = currHoodInfo[SUIT_HOOD_INFO_LVL]
        heights = [0,
         0,
         0,
         0,
         0]
        for level in levels:
            minFloors, maxFloors = SuitBuildingGlobals.SuitBuildingInfo[level - 1][0]
            for i in range(minFloors - 1, maxFloors):
                heights[i] += 1

        currHoodInfo[SUIT_HOOD_INFO_HEIGHTS] = heights
        TOTAL_BWEIGHT += weight
        TOTAL_BWEIGHT_PER_TRACK[0] += weight * tracks[0]
        TOTAL_BWEIGHT_PER_TRACK[1] += weight * tracks[1]
        TOTAL_BWEIGHT_PER_TRACK[2] += weight * tracks[2]
        TOTAL_BWEIGHT_PER_TRACK[3] += weight * tracks[3]
        TOTAL_BWEIGHT_PER_HEIGHT[0] += weight * heights[0]
        TOTAL_BWEIGHT_PER_HEIGHT[1] += weight * heights[1]
        TOTAL_BWEIGHT_PER_HEIGHT[2] += weight * heights[2]
        TOTAL_BWEIGHT_PER_HEIGHT[3] += weight * heights[3]
        TOTAL_BWEIGHT_PER_HEIGHT[4] += weight * heights[4]

    def __init__(self):
        self.suitWalkSpeed = ToontownGlobals.SuitWalkSpeed
        self.dnaStore = None
        self.pointIndexes = {}
        return

    def delete(self):
        del self.dnaStore

    def setupDNA(self):
        if self.dnaStore:
            return None
        self.dnaStore = DNAStorage()
        dnaFileName = self.genDNAFileName()
        loadDNAFileAI(self.dnaStore, dnaFileName)
        self.initDNAInfo()

    def genDNAFileName(self):
        zoneId = ZoneUtil.getCanonicalZoneId(self.getZoneId())
        hoodId = ZoneUtil.getCanonicalHoodId(zoneId)
        hood = ToontownGlobals.dnaMap[hoodId]
        phase = ToontownGlobals.streetPhaseMap[hoodId]
        if hoodId == zoneId:
            zoneId = 'sz'
        return 'phase_%s/dna/%s_%s.dna' % (phase, hood, zoneId)

    def getZoneId(self):
        return self.zoneId

    def setZoneId(self, zoneId):
        self.notify.debug('setting zone id for suit planner')
        self.zoneId = zoneId
        self.setupDNA()

    def extractGroupName(self, groupFullName):
        return groupFullName.split(':', 1)[0]

    def initDNAInfo(self):
        numGraphs = self.dnaStore.discoverContinuity()
        if numGraphs != 1:
            self.notify.info('zone %s has %s disconnected suit paths.' % (self.zoneId, numGraphs))
        self.battlePosDict = {}
        self.cellToGagBonusDict = {}
        for i in range(self.dnaStore.getNumDNAVisGroupsAI()):
            vg = self.dnaStore.getDNAVisGroupAI(i)
            zoneId = int(self.extractGroupName(vg.getName()))
            if vg.getNumBattleCells() == 1:
                self.battlePosDict[zoneId] = vg.getBattleCell(0).getPos()
            elif vg.getNumBattleCells() > 1:
                self.notify.warning('multiple battle cells for zone: %d' % zoneId)
                self.battlePosDict[zoneId] = vg.getBattleCell(0).getPos()
        self.dnaStore.resetDNAGroups()
        self.dnaStore.resetDNAVisGroups()
        self.dnaStore.resetDNAVisGroupsAI()
        self.streetPointList = []
        self.frontdoorPointList = []
        self.sidedoorPointList = []
        self.cogHQDoorPointList = []
        numPoints = self.dnaStore.getNumSuitPoints()
        for i in range(numPoints):
            point = self.dnaStore.getSuitPointAtIndex(i)
            if point.getPointType() == DNASuitPoint.FRONT_DOOR_POINT:
                self.frontdoorPointList.append(point)
            elif point.getPointType() == DNASuitPoint.SIDE_DOOR_POINT:
                self.sidedoorPointList.append(point)
            elif (point.getPointType() == DNASuitPoint.COGHQ_IN_POINT) or (point.getPointType() == DNASuitPoint.COGHQ_OUT_POINT):
                self.cogHQDoorPointList.append(point)
            else:
                self.streetPointList.append(point)
            self.pointIndexes[point.getIndex()] = point

    def performPathTest(self):
        if not self.notify.getDebug():
            return None
        startAndEnd = self.pickPath()
        if not startAndEnd:
            return None
        startPoint = startAndEnd[0]
        endPoint = startAndEnd[1]
        path = self.dnaStore.getSuitPath(startPoint, endPoint)
        numPathPoints = path.getNumPoints()
        for i in range(numPathPoints - 1):
            zone = self.dnaStore.getSuitEdgeZone(path.getPointIndex(i), path.getPointIndex(i + 1))
            travelTime = self.dnaStore.getSuitEdgeTravelTime(path.getPointIndex(i), path.getPointIndex(i + 1), self.suitWalkSpeed)
            self.notify.debug('edge from point ' + repr(i) + ' to point ' + repr((i + 1)) + ' is in zone: ' + repr(zone) + ' and will take ' + repr(travelTime) + ' seconds to walk.')

    def genPath(self, startPoint, endPoint, minPathLen, maxPathLen):
        return self.dnaStore.getSuitPath(startPoint, endPoint, minPathLen, maxPathLen)

    def getDnaStore(self):
        return self.dnaStore