def createInitialSuitBuildings(self):
        if self.buildingMgr is None:
            return

        # If we aren't at our minimum number of buildings, let's spawn some!
        suitBlockCount = len(self.buildingMgr.getSuitBlocks())
        if suitBlockCount < self.targetNumSuitBuildings:
            for _ in xrange(self.targetNumSuitBuildings - suitBlockCount):
                blockNumber = random.choice(self.buildingMgr.getToonBlocks())
                building = self.buildingMgr.getBuilding(blockNumber)
                if building is None:
                    continue
                if NPCToons.isZoneProtected(
                        building.getExteriorAndInteriorZoneId()[1]):
                    continue
                suitName = self.air.suitInvasionManager.getInvadingCog()[0]
                if suitName is None:
                    suitName = self.defaultSuitName
                suitType = None
                suitTrack = None
                if suitName is not None:
                    suitType = SuitDNA.getSuitType(suitName)
                    suitTrack = SuitDNA.getSuitDept(suitName)
                (suitLevel, suitType, suitTrack) = self.pickLevelTypeAndTrack(
                    None, suitType, suitTrack)
                building.suitTakeOver(suitTrack, suitLevel, None)

        # Save the building manager's state:
        self.buildingMgr.save()
    def createInitialSuitBuildings(self):
        if self.buildingMgr is None:
            return

        # If we aren't at our minimum number of buildings, let's spawn some!
        suitBlockCount = len(self.buildingMgr.getSuitBlocks())
        if suitBlockCount < self.targetNumSuitBuildings:
            for _ in xrange(self.targetNumSuitBuildings - suitBlockCount):
                blockNumber = random.choice(self.buildingMgr.getToonBlocks())
                building = self.buildingMgr.getBuilding(blockNumber)
                if building is None:
                    continue
                if NPCToons.isZoneProtected(building.getExteriorAndInteriorZoneId()[1]):
                    continue
                suitName = self.air.suitInvasionManager.getInvadingCog()[0]
                if suitName is None:
                    suitName = self.defaultSuitName
                suitType = None
                suitTrack = None
                if suitName is not None:
                    suitType = SuitDNA.getSuitType(suitName)
                    suitTrack = SuitDNA.getSuitDept(suitName)
                (suitLevel, suitType, suitTrack) = self.pickLevelTypeAndTrack(None, suitType, suitTrack)
                building.suitTakeOver(suitTrack, suitLevel, None)

        # Save the building manager's state:
        self.buildingMgr.save()
    def chooseDestination(self, suit, startTime, toonBlockTakeover=None,
            cogdoTakeover=None, minPathLen=None, maxPathLen=None):
        possibles = []
        backup = []

        if toonBlockTakeover is not None:
            suit.attemptingTakeover = 1
            blockNumber = toonBlockTakeover
            if blockNumber in self.buildingFrontDoors:
                possibles.append((blockNumber, self.buildingFrontDoors[blockNumber]))
        elif suit.attemptingTakeover:
            for blockNumber in self.buildingMgr.getToonBlocks():
                building = self.buildingMgr.getBuilding(blockNumber)
                (extZoneId, intZoneId) = building.getExteriorAndInteriorZoneId()
                if not NPCToons.isZoneProtected(intZoneId):
                    if blockNumber in self.buildingFrontDoors:
                        possibles.append((blockNumber, self.buildingFrontDoors[blockNumber]))
            if cogdoTakeover is None:
                if suit.dna.dept in ALLOWED_FO_TRACKS:
                    cogdoTakeover = random.random() < self.CogdoRatio
        elif self.buildingMgr:
            for blockNumber in self.buildingMgr.getSuitBlocks():
                track = self.buildingMgr.getBuildingTrack(blockNumber)
                if (track == suit.track) and (blockNumber in self.buildingSideDoors):
                    for doorPoint in self.buildingSideDoors[blockNumber]:
                        possibles.append((blockNumber, doorPoint))
        backup = []
        for p in self.streetPointList:
            backup.append((None, p))
        if self.notify.getDebug():
            self.notify.debug('Choosing destination point from %s+%s possibles.' % (len(possibles), len(backup)))
        if len(possibles) == 0:
            possibles = backup
            backup = []
        if minPathLen is None:
            if suit.attemptingTakeover:
                minPathLen = self.MIN_TAKEOVER_PATH_LEN
            else:
                minPathLen = self.MIN_PATH_LEN
        if maxPathLen is None:
            maxPathLen = self.MAX_PATH_LEN
        retryCount = 0
        while (len(possibles) > 0) and (retryCount < 50):
            p = random.choice(possibles)
            possibles.remove(p)
            if len(possibles) == 0:
                possibles = backup
                backup = []
            path = self.genPath(suit.startPoint, p[1], minPathLen, maxPathLen)
            if path and (not self.pathCollision(path, startTime)):
                suit.endPoint = p[1]
                suit.minPathLen = minPathLen
                suit.maxPathLen = maxPathLen
                suit.buildingDestination = p[0]
                suit.buildingDestinationIsCogdo = cogdoTakeover
                suit.setPath(path)
                return 1
            retryCount += 1
        return 0
    def chooseDestination(self, suit, startTime, toonBlockTakeover=None,
            cogdoTakeover=None, minPathLen=None, maxPathLen=None):
        possibles = []
        backup = []

        if toonBlockTakeover is not None:
            suit.attemptingTakeover = 1
            blockNumber = toonBlockTakeover
            if blockNumber in self.buildingFrontDoors:
                possibles.append((blockNumber, self.buildingFrontDoors[blockNumber]))
        elif suit.attemptingTakeover:
            for blockNumber in self.buildingMgr.getToonBlocks():
                building = self.buildingMgr.getBuilding(blockNumber)
                (extZoneId, intZoneId) = building.getExteriorAndInteriorZoneId()
                if not NPCToons.isZoneProtected(intZoneId):
                    if blockNumber in self.buildingFrontDoors:
                        possibles.append((blockNumber, self.buildingFrontDoors[blockNumber]))
            if cogdoTakeover is None:
                if suit.dna.dept in ALLOWED_FO_TRACKS:
                    cogdoTakeover = random.random() < self.CogdoRatio
        elif self.buildingMgr:
            for blockNumber in self.buildingMgr.getSuitBlocks():
                track = self.buildingMgr.getBuildingTrack(blockNumber)
                if (track == suit.track) and (blockNumber in self.buildingSideDoors):
                    for doorPoint in self.buildingSideDoors[blockNumber]:
                        possibles.append((blockNumber, doorPoint))
        backup = []
        for p in self.streetPointList:
            backup.append((None, p))
        if self.notify.getDebug():
            self.notify.debug('Choosing destination point from %s+%s possibles.' % (len(possibles), len(backup)))
        if len(possibles) == 0:
            possibles = backup
            backup = []
        if minPathLen is None:
            if suit.attemptingTakeover:
                minPathLen = self.MIN_TAKEOVER_PATH_LEN
            else:
                minPathLen = self.MIN_PATH_LEN
        if maxPathLen is None:
            maxPathLen = self.MAX_PATH_LEN
        retryCount = 0
        while (len(possibles) > 0) and (retryCount < 50):
            p = random.choice(possibles)
            possibles.remove(p)
            if len(possibles) == 0:
                possibles = backup
                backup = []
            path = self.genPath(suit.startPoint, p[1], minPathLen, maxPathLen)
            if path and (not self.pathCollision(path, startTime)):
                suit.endPoint = p[1]
                suit.minPathLen = minPathLen
                suit.maxPathLen = maxPathLen
                suit.buildingDestination = p[0]
                suit.buildingDestinationIsCogdo = cogdoTakeover
                suit.setPath(path)
                return 1
            retryCount += 1
        return 0
    def chooseDestination(self, suit, startTime, toonBlockTakeover = None, cogdoTakeover = None, minPathLen = None, maxPathLen = None):
        possibles = []
        backup = []
        
        if toonBlockTakeover != None:
            suit.attemptingTakeover = 1
            blockNumber = toonBlockTakeover
            if self.buildingFrontDoors.has_key(blockNumber):
                possibles.append((blockNumber, self.buildingFrontDoors[blockNumber]))
                            
        elif suit.attemptingTakeover:
            for blockNumber in self.buildingMgr.getToonBlocks():
                building = self.buildingMgr.getBuilding(blockNumber)
                (extZoneId, intZoneId) = building.getExteriorAndInteriorZoneId()
                if not NPCToons.isZoneProtected(intZoneId):
                    if self.buildingFrontDoors.has_key(blockNumber):
                        if not self.isBlockSuitTarget(blockNumber):
                            possibles.append((blockNumber, self.buildingFrontDoors[blockNumber]))
                                
            if cogdoTakeover is None:
                if suit.dna.dept in ALLOWED_FO_TRACKS:
                    cogdoTakeover = random.random() < self.CogdoRatio
            
        elif self.buildingMgr and 0:
            for blockNumber in self.buildingMgr.getSuitBlocks():
                track = self.buildingMgr.getBuildingTrack(blockNumber)
                if track == suit.track and self.buildingSideDoors.has_key(blockNumber):
                    for doorPoint in self.buildingSideDoors[blockNumber]:
                        possibles.append((blockNumber, doorPoint))
 
        backup = []
        for p in self.streetPointList:
            backup.append((None, p))
        
        if self.notify.getDebug():
            self.notify.debug('Choosing destination point from %d+%d possibles.' % (len(possibles), len(backup)))
        
        if len(possibles) == 0:
            possibles = backup
            backup = []
        
        if minPathLen == None:
            if suit.attemptingTakeover:
                minPathLen = self.MIN_TAKEOVER_PATH_LEN
            else:
                minPathLen = self.MIN_PATH_LEN
        
        if maxPathLen == None:
            maxPathLen = self.MAX_PATH_LEN
        
        retryCount = 0
        while len(possibles) > 0 and retryCount < 50:
            p = random.choice(possibles)
            possibles.remove(p)
            if len(possibles) == 0:
                possibles = backup
                backup = []
            
            try:
                path = self.genPath(suit.startPoint, p[1], minPathLen, maxPathLen)
                
            except Exception as e:
                print self.zoneId, e
                exit()
            
            if path and not self.pathCollision(path, startTime):                   
                suit.endPoint = p[1]
                suit.minPathLen = minPathLen
                suit.maxPathLen = maxPathLen
                suit.buildingDestination = p[0]
                
                if suit.buildingDestination is not None and self.zoneId == 7100:
                    print 'DSP assigned %r buildingDestination to %s/%s' % (suit, p[0], p[1].getIndex())
                    
                suit.buildingDestinationIsCogdo = cogdoTakeover
                suit.setPath(path)
                return 1
            
            retryCount += 1
        return 0
    def chooseDestination(
        self, suit, startTime, toonBlockTakeover=None, cogdoTakeover=None, minPathLen=None, maxPathLen=None
    ):
        possibles = []
        backup = []
        if cogdoTakeover is None:
            cogdoTakeover = False
        if toonBlockTakeover != None:
            suit.attemptingTakeover = 1
            blockNumber = toonBlockTakeover
            if self.buildingFrontDoors.has_key(blockNumber):
                possibles.append((blockNumber, self.buildingFrontDoors[blockNumber]))
        elif suit.attemptingTakeover:
            for blockNumber in self.buildingMgr.getToonBlocks():
                building = self.buildingMgr.getBuilding(blockNumber)
                extZoneId, intZoneId = building.getExteriorAndInteriorZoneId()
                if not NPCToons.isZoneProtected(intZoneId):
                    if self.buildingFrontDoors.has_key(blockNumber):
                        possibles.append((blockNumber, self.buildingFrontDoors[blockNumber]))

        else:
            if self.buildingMgr:
                for blockNumber in self.buildingMgr.getSuitBlocks():
                    track = self.buildingMgr.getBuildingTrack(blockNumber)
                    if track == suit.track and self.buildingSideDoors.has_key(blockNumber):
                        for doorPoint in self.buildingSideDoors[blockNumber]:
                            possibles.append((blockNumber, doorPoint))

            backup = []
            for p in self.streetPointList:
                backup.append((None, p))

        if self.notify.getDebug():
            self.notify.debug("Choosing destination point from %d+%d possibles." % (len(possibles), len(backup)))
        if len(possibles) == 0:
            possibles = backup
            backup = []
        if minPathLen == None:
            if suit.attemptingTakeover:
                minPathLen = self.MIN_TAKEOVER_PATH_LEN
            else:
                minPathLen = self.MIN_PATH_LEN
        if maxPathLen == None:
            maxPathLen = self.MAX_PATH_LEN
        retryCount = 0
        while len(possibles) > 0 and retryCount < 50:
            p = random.choice(possibles)
            possibles.remove(p)
            if len(possibles) == 0:
                possibles = backup
                backup = []
            path = self.genPath(suit.startPoint, p[1], minPathLen, maxPathLen)
            if path and not self.pathCollision(path, startTime):
                suit.endPoint = p[1]
                suit.minPathLen = minPathLen
                suit.maxPathLen = maxPathLen
                suit.buildingDestination = p[0]
                suit.buildingDestinationIsCogdo = cogdoTakeover
                suit.setPath(self.dnaData.suitGraph, path)
                return 1
            retryCount += 1

        return 0
    def chooseDestination(self,
                          suit,
                          startTime,
                          toonBlockTakeover=None,
                          cogdoTakeover=None,
                          minPathLen=None,
                          maxPathLen=None):
        possibles = []
        backup = []

        if toonBlockTakeover != None:
            suit.attemptingTakeover = 1
            blockNumber = toonBlockTakeover
            if self.buildingFrontDoors.has_key(blockNumber):
                possibles.append(
                    (blockNumber, self.buildingFrontDoors[blockNumber]))

        elif suit.attemptingTakeover:
            for blockNumber in self.buildingMgr.getToonBlocks():
                building = self.buildingMgr.getBuilding(blockNumber)
                (extZoneId,
                 intZoneId) = building.getExteriorAndInteriorZoneId()
                if not NPCToons.isZoneProtected(intZoneId):
                    if self.buildingFrontDoors.has_key(blockNumber):
                        if not self.isBlockSuitTarget(blockNumber):
                            possibles.append(
                                (blockNumber,
                                 self.buildingFrontDoors[blockNumber]))

            if cogdoTakeover is None:
                if suit.dna.dept in ALLOWED_FO_TRACKS:
                    cogdoTakeover = random.random() < self.CogdoRatio

        elif self.buildingMgr and 0:
            for blockNumber in self.buildingMgr.getSuitBlocks():
                track = self.buildingMgr.getBuildingTrack(blockNumber)
                if track == suit.track and self.buildingSideDoors.has_key(
                        blockNumber):
                    for doorPoint in self.buildingSideDoors[blockNumber]:
                        possibles.append((blockNumber, doorPoint))

        backup = []
        for p in self.streetPointList:
            backup.append((None, p))

        if self.notify.getDebug():
            self.notify.debug(
                'Choosing destination point from %d+%d possibles.' %
                (len(possibles), len(backup)))

        if len(possibles) == 0:
            possibles = backup
            backup = []

        if minPathLen == None:
            if suit.attemptingTakeover:
                minPathLen = self.MIN_TAKEOVER_PATH_LEN
            else:
                minPathLen = self.MIN_PATH_LEN

        if maxPathLen == None:
            maxPathLen = self.MAX_PATH_LEN

        retryCount = 0
        while len(possibles) > 0 and retryCount < 50:
            p = random.choice(possibles)
            possibles.remove(p)
            if len(possibles) == 0:
                possibles = backup
                backup = []

            try:
                path = self.genPath(suit.startPoint, p[1], minPathLen,
                                    maxPathLen)

            except Exception as e:
                print self.zoneId, e
                exit()

            if path and not self.pathCollision(path, startTime):
                suit.endPoint = p[1]
                suit.minPathLen = minPathLen
                suit.maxPathLen = maxPathLen
                suit.buildingDestination = p[0]

                if suit.buildingDestination is not None and self.zoneId == 7100:
                    print 'DSP assigned %r buildingDestination to %s/%s' % (
                        suit, p[0], p[1].getIndex())

                suit.buildingDestinationIsCogdo = cogdoTakeover
                suit.setPath(path)
                return 1

            retryCount += 1
        return 0