Beispiel #1
0
    def loadDnaStoreTutorial(self):
        self.dnaStore = DNAStorage()

        tree = loader.loadDNA('phase_3.5/dna/storage_tutorial.xml').store(
            self.dnaStore)

        tree = loader.loadDNA('phase_3.5/dna/storage_interior.xml').store(
            self.dnaStore)
Beispiel #2
0
 def loadDnaStore(self):
     if not hasattr(self, 'dnaStore'):
         self.dnaStore = DNAStorage()
         files = ('phase_4/dna/storage.jazz',
                  'phase_3.5/dna/storage_interior.jazz')
         dnaBulk = DNABulkLoader(self.dnaStore, files)
         dnaBulk.loadDNAFiles()
         self.dnaStore.storeFont('humanist',
                                 ToontownGlobals.getInterfaceFont())
         self.dnaStore.storeFont('mickey', ToontownGlobals.getSignFont())
         self.dnaStore.storeFont('suit', ToontownGlobals.getSuitFont())
Beispiel #3
0
    def setupDNA(self):
        if self.dnaStore:
            return
        self.dnaStore = DNAStorage()
        dnaFileName = self.genDNAFileName()
        try:
            simbase.air.loadDNAFileAI(self.dnaStore, dnaFileName)
        except:
            loader.loadDNAFileAI(self.dnaStore, dnaFileName)

        self.initDNAInfo()
        return
Beispiel #4
0
    def loadDnaStore(self):
        if not hasattr(self, 'dnaStore'):
            self.dnaStore = DNAStorage()

            loader.loadDNA('phase_4/dna/storage.xml').store(self.dnaStore)

            self.dnaStore.storeFont(ToontownGlobals.getInterfaceFont(),
                                    'humanist')
            self.dnaStore.storeFont(ToontownGlobals.getSignFont(), 'mickey')
            self.dnaStore.storeFont(ToontownGlobals.getSuitFont(), 'suit')

            loader.loadDNA('phase_3.5/dna/storage_interior.xml').store(
                self.dnaStore)
 def dnaStoreMap(self, zone):
     dnaStore = self._dnaStoreMap.get(zone)
     if not dnaStore:
         dnaStore = DNAStorage()
         self.loadDNAFileAI(dnaStore, self.genDNAFileName(zone))
         self._dnaStoreMap[zone] = dnaStore
     return dnaStore
    def loadDnaStoreTutorial(self):
        self.dnaStore = DNAStorage()

        tree = loader.loadDNA(
            'phase_3.5/dna/storage_tutorial.xml').store(self.dnaStore)

        tree = loader.loadDNA(
            'phase_3.5/dna/storage_interior.xml').store(self.dnaStore)
    def announceGenerate(self):
        DistributedEvent.announceGenerate(self)
        dnaStore = DNAStorage()
        dnaFileToLoad = 'phase_4/dna/toontown_central_old_sz.pdna'
        loadDNAFileAI(dnaStore, dnaFileToLoad)
        zoneVisDict = {}
        for i in xrange(dnaStore.getNumDNAVisGroupsAI()):
            groupFullName = dnaStore.getDNAVisGroupName(i)
            visGroup = dnaStore.getDNAVisGroupAI(i)
            visZoneId = int(base.cr.hoodMgr.extractGroupName(groupFullName))
            visibles = []
            for i in xrange(visGroup.getNumVisibles()):
                visibles.append(int(visGroup.visibles[i]))

            visibles.append(ZoneUtil.getBranchZone(visZoneId))
            zoneVisDict[visZoneId] = visibles

        self.cr.sendSetZoneMsg(self.zoneId, zoneVisDict.values()[0])
Beispiel #8
0
    def enter(self, requestStatus):
        CogHQExterior.CogHQExterior.enter(self, requestStatus)
        dnaStore = DNAStorage()
        dnaFileName = self.genDNAFileName(self.zoneId)
        loadDNAFileAI(dnaStore, dnaFileName)
        self.zoneVisDict = {}
        for i in xrange(dnaStore.getNumDNAVisGroupsAI()):
            groupFullName = dnaStore.getDNAVisGroupName(i)
            visGroup = dnaStore.getDNAVisGroupAI(i)
            visZoneId = int(base.cr.hoodMgr.extractGroupName(groupFullName))
            visZoneId = ZoneUtil.getTrueZoneId(visZoneId, self.zoneId)
            visibles = []
            for i in xrange(visGroup.getNumVisibles()):
                visibles.append(int(visGroup.visibles[i]))

            visibles.append(ZoneUtil.getBranchZone(visZoneId))
            self.zoneVisDict[visZoneId] = visibles

        base.cr.sendSetZoneMsg(self.zoneId, self.zoneVisDict.values()[0])
Beispiel #9
0
    def loadDnaStore(self):
        if not hasattr(self, 'dnaStore'):
            self.dnaStore = DNAStorage()

            loader.loadDNA('phase_4/dna/storage.xml').store(self.dnaStore)

            self.dnaStore.storeFont(ToontownGlobals.getInterfaceFont(), 'humanist')
            self.dnaStore.storeFont(ToontownGlobals.getSignFont(), 'mickey')
            self.dnaStore.storeFont(ToontownGlobals.getSuitFont(), 'suit')

            loader.loadDNA('phase_3.5/dna/storage_interior.xml').store(self.dnaStore)
    def loadDnaStore(self):
        if not hasattr(self, "dnaStore"):
            self.dnaStore = DNAStorage()

            loader.loadDNA("phase_4/dna/storage.xml").store(self.dnaStore)

            self.dnaStore.storeFont(ToontownGlobals.getInterfaceFont(), "humanist")
            self.dnaStore.storeFont(ToontownGlobals.getSignFont(), "mickey")
            self.dnaStore.storeFont(ToontownGlobals.getSuitFont(), "suit")

            loader.loadDNA("phase_3.5/dna/storage_interior.xml").store(self.dnaStore)
Beispiel #11
0
    def enter(self, requestStatus):
        self.zoneId = requestStatus['zoneId']
        if self.zoneId != ToontownGlobals.LawbotOfficeExt and self.zoneId != ToontownGlobals.SellbotWestWing and self.zoneId not in ToontownGlobals.ShortWorkZones:
            dnaStore = DNAStorage()
            dnaFileName = self.genDNAFileName(self.zoneId)
            loadDNAFileAI(dnaStore, dnaFileName)
            self.zoneVisDict = {}
            for i in xrange(dnaStore.getNumDNAVisGroupsAI()):
                groupFullName = dnaStore.getDNAVisGroupName(i)
                visGroup = dnaStore.getDNAVisGroupAI(i)
                visZoneId = int(
                    base.cr.hoodMgr.extractGroupName(groupFullName))
                visZoneId = ZoneUtil.getTrueZoneId(visZoneId, self.zoneId)
                visibles = []
                for i in xrange(visGroup.getNumVisibles()):
                    visibles.append(int(visGroup.visibles[i]))

                visibles.append(ZoneUtil.getBranchZone(visZoneId))
                self.zoneVisDict[visZoneId] = visibles

            base.cr.sendSetZoneMsg(self.zoneId, self.zoneVisDict.values()[0])
        BattlePlace.BattlePlace.enter(self)
        self.fsm.enterInitialState()
        base.playMusic(self.loader.music, looping=1, volume=0.8)
        self.loader.geom.reparentTo(render)
        if self.loader.factGeom:
            self.loader.factGeom.reparentTo(render)
        self.nodeList = [self.loader.geom]
        self.loader.hood.startSky()
        self._telemLimiter = TLGatherAllAvs('FactoryExterior',
                                            RotationLimitToH)
        self.accept('doorDoneEvent', self.handleDoorDoneEvent)
        self.accept('DistributedDoor_doorTrigger', self.handleDoorTrigger)
        NametagGlobals.setMasterArrowsOn(1)
        self.tunnelOriginList = base.cr.hoodMgr.addLinkTunnelHooks(
            self, self.nodeList, self.zoneId)
        how = requestStatus['how']
        self.fsm.request(how, [requestStatus])
    def setupDNA(self, suitPlanner):
        if suitPlanner.dnaStore:
            return None

        suitPlanner.dnaStore = DNAStorage()
        loadDNAFileAI(suitPlanner.dnaStore,
                      'phase_4/dna/toontown_central_sz.pdna')

        visGroups = {}
        for visGroup in suitPlanner.dnaStore.DNAVisGroups:
            zone = int(visGroup.name)
            if zone == 2000:
                visGroups[2000] = self.zoneId
            else:
                visGroups[zone] = self.air.allocateZone()
            visGroup.name = str(visGroups[zone])

        for suitEdges in suitPlanner.dnaStore.suitEdges.values():
            for suitEdge in suitEdges:
                suitEdge.setZoneId(visGroups[suitEdge.zoneId])

        self.setVisGroups(visGroups.values())
        suitPlanner.initDNAInfo()
Beispiel #13
0
 def loadDnaStoreTutorial(self):
     self.dnaStore = DNAStorage()
     files = ('phase_3.5/dna/storage_tutorial.jazz',
              'phase_3.5/dna/storage_interior.jazz')
     dnaBulk = DNABulkLoader(self.dnaStore, files)
     dnaBulk.loadDNAFiles()
Beispiel #14
0
class PlayGame(StateData.StateData):
    notify = DirectNotifyGlobal.directNotify.newCategory('PlayGame')
    Hood2ClassDict = {ToontownGlobals.ToontownCentral: TTHood.TTHood,
     ToontownGlobals.DonaldsDock: DDHood.DDHood,
     ToontownGlobals.TheBrrrgh: BRHood.BRHood,
     ToontownGlobals.MinniesMelodyland: MMHood.MMHood,
     ToontownGlobals.DaisyGardens: DGHood.DGHood,
     ToontownGlobals.DonaldsDreamland: DLHood.DLHood,
     ToontownGlobals.FunnyFarm: TFHood.TFHood,
     ToontownGlobals.GoofySpeedway: GSHood.GSHood,
     ToontownGlobals.OutdoorZone: OZHood.OZHood,
     ToontownGlobals.Tutorial: TutorialHood.TutorialHood,
     ToontownGlobals.MyEstate: EstateHood.EstateHood,
     ToontownGlobals.BossbotHQ: BossbotHQ.BossbotHQ,
     ToontownGlobals.SellbotHQ: SellbotHQ.SellbotHQ,
     ToontownGlobals.CashbotHQ: CashbotHQ.CashbotHQ,
     ToontownGlobals.LawbotHQ: LawbotHQ.LawbotHQ,
     ToontownGlobals.GolfZone: GZHood.GZHood,
     ToontownGlobals.PartyHood: PartyHood.PartyHood}
    Hood2StateDict = {ToontownGlobals.ToontownCentral: 'TTHood',
     ToontownGlobals.DonaldsDock: 'DDHood',
     ToontownGlobals.TheBrrrgh: 'BRHood',
     ToontownGlobals.MinniesMelodyland: 'MMHood',
     ToontownGlobals.DaisyGardens: 'DGHood',
     ToontownGlobals.DonaldsDreamland: 'DLHood',
     ToontownGlobals.FunnyFarm: 'TFHood',                
     ToontownGlobals.GoofySpeedway: 'GSHood',
     ToontownGlobals.OutdoorZone: 'OZHood',
     ToontownGlobals.Tutorial: 'TutorialHood',
     ToontownGlobals.MyEstate: 'EstateHood',
     ToontownGlobals.BossbotHQ: 'BossbotHQ',
     ToontownGlobals.SellbotHQ: 'SellbotHQ',
     ToontownGlobals.CashbotHQ: 'CashbotHQ',
     ToontownGlobals.LawbotHQ: 'LawbotHQ',
     ToontownGlobals.GolfZone: 'GZHood',
     ToontownGlobals.PartyHood: 'PartyHood'}

    def __init__(self, parentFSM, doneEvent):
        StateData.StateData.__init__(self, doneEvent)
        self.place = None
        self.fsm = ClassicFSM.ClassicFSM('PlayGame', [State.State('start', self.enterStart, self.exitStart, ['quietZone']),
         State.State('quietZone', self.enterQuietZone, self.exitQuietZone, ['TTHood',
          'DDHood',
          'BRHood',
          'MMHood',
          'DGHood',
          'DLHood',
          'TFHood',
          'GSHood',
          'OZHood',
          'GZHood',
          'SellbotHQ',
          'CashbotHQ',
          'LawbotHQ',
          'BossbotHQ',
          'TutorialHood',
          'EstateHood',
          'PartyHood']),
         State.State('TTHood', self.enterTTHood, self.exitTTHood, ['quietZone']),
         State.State('DDHood', self.enterDDHood, self.exitDDHood, ['quietZone']),
         State.State('BRHood', self.enterBRHood, self.exitBRHood, ['quietZone']),
         State.State('MMHood', self.enterMMHood, self.exitMMHood, ['quietZone']),
         State.State('DGHood', self.enterDGHood, self.exitDGHood, ['quietZone']),
         State.State('DLHood', self.enterDLHood, self.exitDLHood, ['quietZone']),
         State.State('TFHood', self.enterTFHood, self.exitTFHood, ['quietZone']),                                                      
         State.State('GSHood', self.enterGSHood, self.exitGSHood, ['quietZone']),
         State.State('OZHood', self.enterOZHood, self.exitOZHood, ['quietZone']),
         State.State('GZHood', self.enterGZHood, self.exitGZHood, ['quietZone']),
         State.State('BossbotHQ', self.enterBossbotHQ, self.exitBossbotHQ, ['quietZone']),
         State.State('SellbotHQ', self.enterSellbotHQ, self.exitSellbotHQ, ['quietZone']),
         State.State('CashbotHQ', self.enterCashbotHQ, self.exitCashbotHQ, ['quietZone']),
         State.State('LawbotHQ', self.enterLawbotHQ, self.exitLawbotHQ, ['quietZone']),
         State.State('TutorialHood', self.enterTutorialHood, self.exitTutorialHood, ['quietZone']),
         State.State('EstateHood', self.enterEstateHood, self.exitEstateHood, ['quietZone']),
         State.State('PartyHood', self.enterPartyHood, self.exitPartyHood, ['quietZone'])], 'start', 'start')
        self.fsm.enterInitialState()
        self.parentFSM = parentFSM
        self.parentFSM.getStateNamed('playGame').addChild(self.fsm)
        self.hoodDoneEvent = 'hoodDone'
        self.hood = None
        self.quietZoneDoneEvent = uniqueName('quietZoneDone')
        self.quietZoneStateData = None
        self.dnaData = None
        return

    def enter(self, hoodId, zoneId, avId):
        if hoodId == ToontownGlobals.Tutorial:
            loaderName = 'townLoader'
            whereName = 'toonInterior'
        elif hoodId == ToontownGlobals.MyEstate:
            self.getEstateZoneAndGoHome(avId, zoneId)
            return
        elif hoodId == ToontownGlobals.PartyHood:
            self.getPartyZoneAndGoToParty(avId, zoneId)
            return
        else:
            loaderName = ZoneUtil.getLoaderName(zoneId)
            whereName = ZoneUtil.getToonWhereName(zoneId)
        self.fsm.request('quietZone', [{'loader': loaderName,
          'where': whereName,
          'how': 'teleportIn',
          'hoodId': hoodId,
          'zoneId': zoneId,
          'shardId': None,
          'avId': avId}])
        return

    def exit(self):
        if base.placeBeforeObjects and self.quietZoneStateData:
            self.quietZoneStateData.exit()
            self.quietZoneStateData.unload()
            self.quietZoneStateData = None
        self.ignore(self.quietZoneDoneEvent)
        return

    def load(self):
        pass

    def loadDnaStoreTutorial(self):
        self.dnaStore = DNAStorage()

        tree = loader.loadDNA('phase_3.5/dna/storage_tutorial.xml').store(self.dnaStore)

        tree = loader.loadDNA('phase_3.5/dna/storage_interior.xml').store(self.dnaStore)

    def loadDnaStore(self):
        if not hasattr(self, 'dnaStore'):
            self.dnaStore = DNAStorage()

            loader.loadDNA('phase_4/dna/storage.xml').store(self.dnaStore)

            self.dnaStore.storeFont(ToontownGlobals.getInterfaceFont(), 'humanist')
            self.dnaStore.storeFont(ToontownGlobals.getSignFont(), 'mickey')
            self.dnaStore.storeFont(ToontownGlobals.getSuitFont(), 'suit')

            loader.loadDNA('phase_3.5/dna/storage_interior.xml').store(self.dnaStore)

    def unloadDnaStore(self):
        if hasattr(self, 'dnaStore'):
            #self.dnaStore.resetNodes()
            #self.dnaStore.resetTextures()
            del self.dnaStore
            ModelPool.garbageCollect()
            TexturePool.garbageCollect()

    def unload(self):
        self.unloadDnaStore()
        if self.hood:
            self.notify.info('Aggressively cleaning up hood: %s' % self.hood)
            self.hood.exit()
            self.hood.unload()
            self.hood = None
        return

    def enterStart(self):
        pass

    def exitStart(self):
        pass

    def handleHoodDone(self):
        doneStatus = self.hood.getDoneStatus()
        shardId = doneStatus['shardId']
        if shardId != None:
            self.doneStatus = doneStatus
            messenger.send(self.doneEvent)
            base.transitions.fadeOut(0)
            return
        if doneStatus['where'] == 'party':
            self.getPartyZoneAndGoToParty(doneStatus['avId'], doneStatus['zoneId'])
            return
        how = doneStatus['how']
        if how in ['tunnelIn',
         'teleportIn',
         'doorIn',
         'elevatorIn',
         'walk']:
            self.fsm.request('quietZone', [doneStatus])
        else:
            self.notify.error('Exited hood with unexpected mode %s' % how)
        return

    def _destroyHood(self):
        self.ignore(self.hoodDoneEvent)
        self.hood.exit()
        self.hood.unload()
        self.hood = None
        base.cr.cache.flush()
        return

    def enterQuietZone(self, requestStatus):
        self.acceptOnce(self.quietZoneDoneEvent, self.handleQuietZoneDone)
        self.quietZoneStateData = QuietZoneState.QuietZoneState(self.quietZoneDoneEvent)
        self._quietZoneLeftEvent = self.quietZoneStateData.getQuietZoneLeftEvent()
        if base.placeBeforeObjects:
            self.acceptOnce(self._quietZoneLeftEvent, self.handleLeftQuietZone)
        self._enterWaitForSetZoneResponseMsg = self.quietZoneStateData.getEnterWaitForSetZoneResponseMsg()
        self.acceptOnce(self._enterWaitForSetZoneResponseMsg, self.handleWaitForSetZoneResponse)
        self.quietZoneStateData.load()
        self.quietZoneStateData.enter(requestStatus)

    def exitQuietZone(self):
        self.ignore(self._quietZoneLeftEvent)
        self.ignore(self._enterWaitForSetZoneResponseMsg)
        if not base.placeBeforeObjects:
            self.ignore(self.quietZoneDoneEvent)
            self.quietZoneStateData.exit()
            self.quietZoneStateData.unload()
            self.quietZoneStateData = None
        return

    def handleWaitForSetZoneResponse(self, requestStatus):
        hoodId = requestStatus['hoodId']
        canonicalHoodId = ZoneUtil.getCanonicalZoneId(hoodId)
        toHoodPhrase = ToontownGlobals.hoodNameMap[canonicalHoodId][0]
        hoodName = ToontownGlobals.hoodNameMap[canonicalHoodId][-1]
        zoneId = requestStatus['zoneId']
        requestStatus['loader'] = 'cogHQLoader' if ZoneUtil.isCogHQZone(hoodId) else requestStatus['loader']
        loaderName = requestStatus['loader']
        avId = requestStatus.get('avId', -1)
        ownerId = requestStatus.get('ownerId', avId)
        if config.GetBool('want-qa-regression', 0):
            self.notify.info('QA-REGRESSION: NEIGHBORHOODS: Visit %s' % hoodName)
        count = ToontownGlobals.hoodCountMap[canonicalHoodId]
        if loaderName == 'safeZoneLoader':
            count += ToontownGlobals.safeZoneCountMap[canonicalHoodId]
        elif loaderName == 'townLoader':
            count += ToontownGlobals.townCountMap[canonicalHoodId]
        if not loader.inBulkBlock:
            if hoodId == ToontownGlobals.MyEstate:
                if avId == -1:
                    loader.beginBulkLoad('hood', TTLocalizer.HeadingToYourEstate, count, 1, TTLocalizer.TIP_ESTATE)
                else:
                    owner = base.cr.identifyAvatar(ownerId)
                    if owner == None:
                        friend = base.cr.identifyAvatar(avId)
                        if friend != None:
                            avName = friend.getName()
                            loader.beginBulkLoad('hood', TTLocalizer.HeadingToFriend % avName, count, 1, TTLocalizer.TIP_ESTATE)
                        else:
                            self.notify.warning("we can't perform this teleport")
                            return
                    else:
                        avName = owner.getName()
                        loader.beginBulkLoad('hood', TTLocalizer.HeadingToEstate % avName, count, 1, TTLocalizer.TIP_ESTATE)
            elif ZoneUtil.isCogHQZone(zoneId):
                loader.beginBulkLoad('hood', TTLocalizer.HeadingToHood % {'to': toHoodPhrase,
                 'hood': hoodName}, count, 1, TTLocalizer.TIP_COGHQ)
            elif ZoneUtil.isGoofySpeedwayZone(zoneId):
                loader.beginBulkLoad('hood', TTLocalizer.HeadingToHood % {'to': toHoodPhrase,
                 'hood': hoodName}, count, 1, TTLocalizer.TIP_KARTING)
            else:
                loader.beginBulkLoad('hood', TTLocalizer.HeadingToHood % {'to': toHoodPhrase,
                 'hood': hoodName}, count, 1, TTLocalizer.TIP_GENERAL)
        if hoodId == ToontownGlobals.Tutorial:
            self.loadDnaStoreTutorial()
        else:
            self.loadDnaStore()
        hoodClass = self.getHoodClassByNumber(canonicalHoodId)
        self.hood = hoodClass(self.fsm, self.hoodDoneEvent, self.dnaStore, hoodId)
        self.hood.load()
        self.hood.loadLoader(requestStatus)
        if not base.placeBeforeObjects:
            loader.endBulkLoad('hood')
        return

    def handleLeftQuietZone(self):
        status = self.quietZoneStateData.getRequestStatus()
        hoodId = ZoneUtil.getCanonicalZoneId(status['hoodId'])
        hoodState = self.getHoodStateByNumber(hoodId)
        self.fsm.request(hoodState, [status])

    def handleQuietZoneDone(self):
        if base.placeBeforeObjects:
            self.quietZoneStateData.exit()
            self.quietZoneStateData.unload()
            self.quietZoneStateData = None
            loader.endBulkLoad('hood')
        else:
            self.handleLeftQuietZone()
        return

    def enterTTHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitTTHood(self):
        self._destroyHood()

    def enterDDHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitDDHood(self):
        self._destroyHood()

    def enterMMHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitMMHood(self):
        self._destroyHood()

    def enterBRHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitBRHood(self):
        self._destroyHood()

    def enterDGHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitDGHood(self):
        self._destroyHood()

    def enterDLHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitDLHood(self):
        self._destroyHood()

    def enterTFHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitTFHood(self):
        self._destroyHood()

    def enterGSHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitGSHood(self):
        self._destroyHood()

    def enterOZHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitOZHood(self):
        self._destroyHood()

    def enterGZHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitGZHood(self):
        self._destroyHood()

    def enterSellbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitSellbotHQ(self):
        self._destroyHood()

    def enterCashbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitCashbotHQ(self):
        self._destroyHood()

    def enterLawbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitLawbotHQ(self):
        self._destroyHood()

    def enterBossbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitBossbotHQ(self):
        self._destroyHood()

    def enterTutorialHood(self, requestStatus):
        messenger.send('toonArrivedTutorial')
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        base.localAvatar.book.obscureButton(1)
        base.localAvatar.book.setSafeMode(1)
        base.localAvatar.laffMeter.obscure(1)
        base.localAvatar.chatMgr.obscure(1, 1)
        base.localAvatar.obscureFriendsListButton(1)
        requestStatus['how'] = 'tutorial'
        if config.GetString('language', 'english') == 'japanese':
            musicVolume = config.GetFloat('tutorial-music-volume', 0.5)
            requestStatus['musicVolume'] = musicVolume
        self.hood.enter(requestStatus)

    def exitTutorialHood(self):
        self.unloadDnaStore()
        self._destroyHood()
        base.localAvatar.book.obscureButton(0)
        base.localAvatar.book.setSafeMode(0)
        base.localAvatar.laffMeter.obscure(0)
        base.localAvatar.chatMgr.obscure(0, 0)
        base.localAvatar.obscureFriendsListButton(-1)

    def enterEstateHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitEstateHood(self):
        self._destroyHood()

    def getEstateZoneAndGoHome(self, avId, zoneId):
        self.doneStatus = {'avId': avId,
         'zoneId': zoneId,
         'hoodId': ToontownGlobals.MyEstate,
         'loader': 'safeZoneLoader',
         'how': 'teleportIn',
         'shardId': None}
        self.acceptOnce('setLocalEstateZone', self.goHome)
        if avId > 0:
            base.cr.estateMgr.getLocalEstateZone(avId)
        else:
            base.cr.estateMgr.getLocalEstateZone(base.localAvatar.getDoId())
        return

    def goHome(self, ownerId, zoneId):
        self.notify.debug('goHome ownerId = %s' % ownerId)
        if ownerId > 0 and ownerId != base.localAvatar.doId and not base.cr.isFriend(ownerId):
            self.doneStatus['failed'] = 1
            taskMgr.remove('goHomeFailed')
            taskMgr.add(self.goHomeFailed, 'goHomeFailed')
            return
        if ownerId == 0 and zoneId == 0:
            self.doneStatus['failed'] = 1
            self.goHomeFailed(None)
            return
        if self.doneStatus['zoneId'] != zoneId:
            self.doneStatus['where'] = 'house'
        else:
            self.doneStatus['where'] = 'estate'
        self.doneStatus['ownerId'] = ownerId
        self.fsm.request('quietZone', [self.doneStatus])
        return

    def goHomeFailed(self, task):
        self.notify.debug('goHomeFailed')
        failedToVisitAvId = self.doneStatus.get('avId')
        if failedToVisitAvId > 0:
            message = TTLocalizer.EstateTeleportFailedNotFriends % base.cr.identifyAvatar(failedToVisitAvId).getName()
        else:
            message = TTLocalizer.EstateTeleportFailed
        self.notify.debug('goHomeFailed, why =: %s' % message)
        self.ignore('setLocalEstateZone')
        zoneId = base.localAvatar.lastHood
        loaderName = ZoneUtil.getLoaderName(zoneId)
        whereName = ZoneUtil.getToonWhereName(zoneId)
        base.localAvatar.setSystemMessage(0, message)
        self.fsm.request('quietZone', [{'loader': loaderName,
          'where': whereName,
          'how': 'teleportIn',
          'hoodId': zoneId,
          'zoneId': zoneId,
          'shardId': None}])
        return Task.done

    def enterPartyHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        requestStatus['where'] = 'party'
        self.hood.enter(requestStatus)

    def exitPartyHood(self):
        self._destroyHood()

    def getPartyZoneAndGoToParty(self, avId, zoneId):
        self.doneStatus = {'avId': avId,
         'zoneId': zoneId,
         'hoodId': ToontownGlobals.PartyHood,
         'loader': 'safeZoneLoader',
         'how': 'teleportIn',
         'shardId': None}
        if avId < 0:
            avId = base.localAvatar.getDoId()
        base.cr.partyManager.requestPartyZone(avId, zoneId, callback=self.goToParty)
        return

    def goToParty(self, ownerId, partyId, zoneId):
        if ownerId == 0 or partyId == 0 or zoneId == 0:
            self.doneStatus['where'] = 'playground'
        else:
            self.doneStatus['where'] = 'party'
        self.doneStatus['ownerId'] = ownerId
        self.doneStatus['partyId'] = partyId
        self.doneStatus['zoneId'] = zoneId
        self.fsm.request('quietZone', [self.doneStatus])

    def goToPartyFailed(self, reason):
        self.notify.debug('goToPartyFailed')
        failedToVisitAvId = self.doneStatus.get('avId')
        message = base.cr.partyManager.getGoToPartyFailedMessage(reason)
        self.notify.debug('goToPartyFailed, why =: %s' % message)
        self.ignore('gotLocalPartyZone')
        zoneId = base.localAvatar.lastHood
        loaderName = ZoneUtil.getLoaderName(zoneId)
        whereName = ZoneUtil.getToonWhereName(zoneId)
        base.localAvatar.setSystemMessage(0, message)
        self.fsm.request('quietZone', [{'loader': loaderName,
          'where': whereName,
          'how': 'teleportIn',
          'hoodId': zoneId,
          'zoneId': zoneId,
          'shardId': None}])
        return Task.done

    def getCatalogCodes(self, category):
        numCodes = self.dnaStore.getNumCatalogCodes(category)
        codes = []
        for i in range(numCodes):
            codes.append(self.dnaStore.getCatalogCode(category, i))

        return codes

    def getNodePathList(self, catalogGroup):
        result = []
        codes = self.getCatalogCodes(catalogGroup)
        for code in codes:
            np = self.dnaStore.findNode(code)
            result.append(np)

        return result

    def getNodePathDict(self, catalogGroup):
        result = {}
        codes = self.getCatalogCodes(catalogGroup)
        for code in codes:
            np = self.dnaStore.findNode(code)
            result[code] = np

        return result

    def getHoodClassByNumber(self, hoodNumber):
        return self.Hood2ClassDict[hoodNumber]

    def getHoodStateByNumber(self, hoodNumber):
        return self.Hood2StateDict[hoodNumber]

    def setPlace(self, place):
        self.place = place
        if self.place:
            messenger.send('playGameSetPlace')

    def getPlace(self):
        return self.place

    def getPlaceId(self):
        if self.hood:
            return self.hood.hoodId
        else:
            return None
        return None
Beispiel #15
0
class SuitPlannerBase:
    notify = DirectNotifyGlobal.directNotify.newCategory('SuitPlannerBase')
    SuitHoodInfo = [[
        2100, 5, 15, 0, 5, 20, 3, (1, 5, 10, 40, 60, 80), (25, 25, 25, 25, 0),
        (1, 2, 3), []
    ],
                    [
                        2200, 3, 10, 0, 5, 15, 3, (1, 5, 10, 40, 60, 80),
                        (10, 70, 10, 10, 0), (1, 2, 3), []
                    ],
                    [
                        2300, 3, 10, 0, 5, 15, 3, (1, 5, 10, 40, 60, 80),
                        (10, 10, 40, 40, 0), (1, 2, 3), []
                    ],
                    [
                        1100, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (90, 10, 0, 0, 0), (2, 3, 4), []
                    ],
                    [
                        1200, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (0, 0, 90, 10, 0), (3, 4, 5, 6), []
                    ],
                    [
                        1300, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (40, 40, 10, 10, 0), (3, 4, 5, 6), []
                    ],
                    [
                        3100, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (90, 10, 0, 0, 0), (5, 6, 7), []
                    ],
                    [
                        3200, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (10, 20, 30, 40, 0), (5, 6, 7), []
                    ],
                    [
                        3300, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (5, 85, 5, 5, 0), (7, 8, 9), []
                    ],
                    [
                        4100, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (0, 0, 50, 50, 0), (2, 3, 4), []
                    ],
                    [
                        4200, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (0, 0, 90, 10, 0), (3, 4, 5, 6), []
                    ],
                    [
                        4300, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (50, 50, 0, 0, 0), (3, 4, 5, 6), []
                    ],
                    [
                        5100, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (0, 20, 10, 70, 0), (2, 3, 4), []
                    ],
                    [
                        5200, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (10, 70, 0, 20, 0), (3, 4, 5, 6), []
                    ],
                    [
                        5300, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (5, 5, 5, 85, 0), (3, 4, 5, 6), []
                    ],
                    [
                        9100, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (25, 25, 25, 25, 0), (6, 7, 8, 9), []
                    ],
                    [
                        9200, 1, 5, 0, 99, 100, 4, (1, 5, 10, 40, 60, 80),
                        (5, 5, 85, 5, 0), (6, 7, 8, 9), []
                    ],
                    [
                        11000, 3, 15, 0, 0, 0, 4, (1, 5, 10, 40, 60, 80),
                        (0, 0, 0, 100, 0), (4, 5, 6), []
                    ],
                    [
                        11200, 10, 20, 0, 0, 0, 4, (1, 5, 10, 40, 60, 80),
                        (0, 0, 0, 100, 0), (4, 5, 6), []
                    ],
                    [
                        12000, 10, 20, 0, 0, 0, 4, (1, 5, 10, 40, 60, 80),
                        (0, 0, 100, 0, 0), (7, 8, 9), []
                    ],
                    [
                        13000, 10, 20, 0, 0, 0, 4, (1, 5, 10, 40, 60, 80),
                        (0, 100, 0, 0, 0), (8, 9, 10), []
                    ],
                    [
                        19000, 10, 20, 0, 0, 0, 4, (1, 5, 10, 40, 60, 80),
                        (0, 0, 0, 0, 100),
                        (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), []
                    ]]
    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
        self.dnaStore = DNAStorage()
        dnaFileName = self.genDNAFileName()
        try:
            simbase.air.loadDNAFileAI(self.dnaStore, dnaFileName)
        except:
            loader.loadDNAFileAI(self.dnaStore, dnaFileName)

        self.initDNAInfo()
        return

    def genDNAFileName(self):
        try:
            return simbase.air.genDNAFileName(self.getZoneId())
        except:
            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.jazz' % (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 str(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:
                battleCell = vg.getBattleCell(0)
                self.battlePosDict[zoneId] = vg.getBattleCell(0).getPos()
            else:
                if vg.getNumBattleCells() > 1:
                    self.notify.warning('multiple battle cells for zone: %d' %
                                        zoneId)
                    self.battlePosDict[zoneId] = vg.getBattleCell(0).getPos()
            if True:
                for i in range(vg.getNumChildren()):
                    childDnaGroup = vg.at(i)
                    if isinstance(childDnaGroup, DNAInteractiveProp):
                        self.notify.debug('got interactive prop %s' %
                                          childDnaGroup)
                        battleCellId = childDnaGroup.getCellId()
                        if battleCellId == -1:
                            self.notify.warning(
                                'interactive prop %s  at %s not associated with a a battle'
                                % (childDnaGroup, zoneId))
                        elif battleCellId == 0:
                            if self.cellToGagBonusDict.has_key(zoneId):
                                self.notify.error(
                                    'FIXME battle cell at zone %s has two props %s %s linked to it'
                                    % (zoneId, self.cellToGagBonusDict[zoneId],
                                       childDnaGroup))
                            else:
                                name = childDnaGroup.getName()
                                propType = HoodUtil.calcPropType(name)
                                if propType in ToontownBattleGlobals.PropTypeToTrackBonus:
                                    trackBonus = ToontownBattleGlobals.PropTypeToTrackBonus[
                                        propType]
                                    self.cellToGagBonusDict[
                                        zoneId] = trackBonus

        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)
            else:
                if point.getPointType() == DNASuitPoint.SIDE_DOOR_POINT:
                    self.sidedoorPointList.append(point)
                else:
                    if 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

        return

    def performPathTest(self):
        if not self.notify.getDebug():
            return
        startAndEnd = self.pickPath()
        if not startAndEnd:
            return
        startPoint = startAndEnd[0]
        endPoint = startAndEnd[1]
        path = self.dnaStore.getSuitPath(startPoint, endPoint)
        numPathPoints = path.getNumPoints()
        for i in xrange(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 ' + ` i ` + ' to point ' +
                              ` (i + 1) ` + ' is in zone: ' + ` zone ` +
                              ' and will take ' + ` travelTime ` +
                              ' seconds to walk.')

        return

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

    def getDnaStore(self):
        return self.dnaStore
 def setup(self):
     self.dnaStore = base.cr.playGame.dnaStore
     self.randomGenerator = random.Random()
     self.randomGenerator.seed(self.zoneId)
     self.interior = loader.loadModel(
         'phase_3.5/models/modules/toon_interior_tutorial')
     self.interior.reparentTo(render)
     dnaStore = DNAStorage()
     node = loader.loadDNA('phase_3.5/dna/tutorial_street.xml').generate(
         self.dnaStore)
     self.street = render.attachNewNode(node)
     self.street.flattenMedium()
     self.street.setPosHpr(-17, 42, -0.5, 180, 0, 0)
     self.street.find('**/tb2:toon_landmark_TT_A1_DNARoot').stash()
     self.street.find(
         '**/tb1:toon_landmark_hqTT_DNARoot/**/door_flat_0').stash()
     self.street.findAllMatches('**/+CollisionNode').stash()
     self.skyFile = 'phase_3.5/models/props/TT_sky'
     self.sky = loader.loadModel(self.skyFile)
     self.sky.setScale(0.8)
     self.sky.reparentTo(render)
     self.sky.setDepthTest(0)
     self.sky.setDepthWrite(0)
     self.sky.setBin('background', 100)
     self.sky.find('**/Sky').reparentTo(self.sky, -1)
     hoodId = ZoneUtil.getCanonicalHoodId(self.zoneId)
     self.colors = ToonInteriorColors.colors[hoodId]
     self.replaceRandomInModel(self.interior)
     doorModelName = 'door_double_round_ul'
     if doorModelName[-1:] == 'r':
         doorModelName = doorModelName[:-1] + 'l'
     else:
         doorModelName = doorModelName[:-1] + 'r'
     door = self.dnaStore.findNode(doorModelName)
     door_origin = render.find('**/door_origin;+s')
     doorNP = door.copyTo(door_origin)
     door_origin.setScale(0.8, 0.8, 0.8)
     door_origin.setPos(door_origin, 0, -0.025, 0)
     color = self.randomGenerator.choice(self.colors['TI_door'])
     DNADoor.setupDoor(doorNP, self.interior, door_origin, self.dnaStore,
                       str(self.block), color)
     doorFrame = doorNP.find('door_*_flat')
     doorFrame.wrtReparentTo(self.interior)
     doorFrame.setColor(color)
     del self.colors
     del self.dnaStore
     del self.randomGenerator
     self.interior.flattenMedium()
     npcOrigin = self.interior.find('**/npc_origin_' +
                                    ` (self.npc.posIndex) `)
     if not npcOrigin.isEmpty():
         self.npc.reparentTo(npcOrigin)
         self.npc.clearMat()
     self.createSuit()
     self.mickeyMovie = QuestParser.NPCMoviePlayer('tutorial_mickey',
                                                   base.localAvatar,
                                                   self.npc)
     place = base.cr.playGame.getPlace()
     if place and hasattr(place,
                          'fsm') and place.fsm.getCurrentState().getName():
         self.notify.info('Tutorial movie: Place ready.')
         self.playMovie()
     else:
         self.notify.info(
             'Tutorial movie: Waiting for place=%s, has fsm=%s' %
             (place, hasattr(place, 'fsm')))
         if hasattr(place, 'fsm'):
             self.notify.info('Tutorial movie: place state=%s' %
                              place.fsm.getCurrentState().getName())
         self.acceptOnce('enterTutorialInterior', self.playMovie)
class PlayGame(StateData.StateData):
    notify = DirectNotifyGlobal.directNotify.newCategory("PlayGame")
    Hood2ClassDict = {
        ToontownGlobals.ToontownCentral: TTHood.TTHood,
        ToontownGlobals.DonaldsDock: DDHood.DDHood,
        ToontownGlobals.TheBrrrgh: BRHood.BRHood,
        ToontownGlobals.MinniesMelodyland: MMHood.MMHood,
        ToontownGlobals.DaisyGardens: DGHood.DGHood,
        ToontownGlobals.DonaldsDreamland: DLHood.DLHood,
        ToontownGlobals.FunnyFarm: TFHood.TFHood,
        ToontownGlobals.GoofySpeedway: GSHood.GSHood,
        ToontownGlobals.OutdoorZone: OZHood.OZHood,
        ToontownGlobals.Tutorial: TutorialHood.TutorialHood,
        ToontownGlobals.MyEstate: EstateHood.EstateHood,
        ToontownGlobals.BossbotHQ: BossbotHQ.BossbotHQ,
        ToontownGlobals.SellbotHQ: SellbotHQ.SellbotHQ,
        ToontownGlobals.CashbotHQ: CashbotHQ.CashbotHQ,
        ToontownGlobals.LawbotHQ: LawbotHQ.LawbotHQ,
        ToontownGlobals.GolfZone: GZHood.GZHood,
        ToontownGlobals.PartyHood: PartyHood.PartyHood,
    }
    Hood2StateDict = {
        ToontownGlobals.ToontownCentral: "TTHood",
        ToontownGlobals.DonaldsDock: "DDHood",
        ToontownGlobals.TheBrrrgh: "BRHood",
        ToontownGlobals.MinniesMelodyland: "MMHood",
        ToontownGlobals.DaisyGardens: "DGHood",
        ToontownGlobals.DonaldsDreamland: "DLHood",
        ToontownGlobals.FunnyFarm: "TFHood",
        ToontownGlobals.GoofySpeedway: "GSHood",
        ToontownGlobals.OutdoorZone: "OZHood",
        ToontownGlobals.Tutorial: "TutorialHood",
        ToontownGlobals.MyEstate: "EstateHood",
        ToontownGlobals.BossbotHQ: "BossbotHQ",
        ToontownGlobals.SellbotHQ: "SellbotHQ",
        ToontownGlobals.CashbotHQ: "CashbotHQ",
        ToontownGlobals.LawbotHQ: "LawbotHQ",
        ToontownGlobals.GolfZone: "GZHood",
        ToontownGlobals.PartyHood: "PartyHood",
    }

    def __init__(self, parentFSM, doneEvent):
        StateData.StateData.__init__(self, doneEvent)
        self.place = None
        self.fsm = ClassicFSM.ClassicFSM(
            "PlayGame",
            [
                State.State("start", self.enterStart, self.exitStart, ["quietZone"]),
                State.State(
                    "quietZone",
                    self.enterQuietZone,
                    self.exitQuietZone,
                    [
                        "TTHood",
                        "DDHood",
                        "BRHood",
                        "MMHood",
                        "DGHood",
                        "DLHood",
                        "TFHood",
                        "GSHood",
                        "OZHood",
                        "GZHood",
                        "SellbotHQ",
                        "CashbotHQ",
                        "LawbotHQ",
                        "BossbotHQ",
                        "TutorialHood",
                        "EstateHood",
                        "PartyHood",
                    ],
                ),
                State.State("TTHood", self.enterTTHood, self.exitTTHood, ["quietZone"]),
                State.State("DDHood", self.enterDDHood, self.exitDDHood, ["quietZone"]),
                State.State("BRHood", self.enterBRHood, self.exitBRHood, ["quietZone"]),
                State.State("MMHood", self.enterMMHood, self.exitMMHood, ["quietZone"]),
                State.State("DGHood", self.enterDGHood, self.exitDGHood, ["quietZone"]),
                State.State("DLHood", self.enterDLHood, self.exitDLHood, ["quietZone"]),
                State.State("TFHood", self.enterTFHood, self.exitTFHood, ["quietZone"]),
                State.State("GSHood", self.enterGSHood, self.exitGSHood, ["quietZone"]),
                State.State("OZHood", self.enterOZHood, self.exitOZHood, ["quietZone"]),
                State.State("GZHood", self.enterGZHood, self.exitGZHood, ["quietZone"]),
                State.State("BossbotHQ", self.enterBossbotHQ, self.exitBossbotHQ, ["quietZone"]),
                State.State("SellbotHQ", self.enterSellbotHQ, self.exitSellbotHQ, ["quietZone"]),
                State.State("CashbotHQ", self.enterCashbotHQ, self.exitCashbotHQ, ["quietZone"]),
                State.State("LawbotHQ", self.enterLawbotHQ, self.exitLawbotHQ, ["quietZone"]),
                State.State("TutorialHood", self.enterTutorialHood, self.exitTutorialHood, ["quietZone"]),
                State.State("EstateHood", self.enterEstateHood, self.exitEstateHood, ["quietZone"]),
                State.State("PartyHood", self.enterPartyHood, self.exitPartyHood, ["quietZone"]),
            ],
            "start",
            "start",
        )
        self.fsm.enterInitialState()
        self.parentFSM = parentFSM
        self.parentFSM.getStateNamed("playGame").addChild(self.fsm)
        self.hoodDoneEvent = "hoodDone"
        self.hood = None
        self.quietZoneDoneEvent = uniqueName("quietZoneDone")
        self.quietZoneStateData = None
        self.dnaData = None
        return

    def enter(self, hoodId, zoneId, avId):
        if hoodId == ToontownGlobals.Tutorial:
            loaderName = "townLoader"
            whereName = "toonInterior"
        elif hoodId == ToontownGlobals.MyEstate:
            self.getEstateZoneAndGoHome(avId, zoneId)
            return
        elif hoodId == ToontownGlobals.PartyHood:
            self.getPartyZoneAndGoToParty(avId, zoneId)
            return
        else:
            loaderName = ZoneUtil.getLoaderName(zoneId)
            whereName = ZoneUtil.getToonWhereName(zoneId)
        self.fsm.request(
            "quietZone",
            [
                {
                    "loader": loaderName,
                    "where": whereName,
                    "how": "teleportIn",
                    "hoodId": hoodId,
                    "zoneId": zoneId,
                    "shardId": None,
                    "avId": avId,
                }
            ],
        )
        return

    def exit(self):
        if base.placeBeforeObjects and self.quietZoneStateData:
            self.quietZoneStateData.exit()
            self.quietZoneStateData.unload()
            self.quietZoneStateData = None
        self.ignore(self.quietZoneDoneEvent)
        return

    def load(self):
        pass

    def loadDnaStoreTutorial(self):
        self.dnaStore = DNAStorage()

        tree = loader.loadDNA("phase_3.5/dna/storage_tutorial.xml").store(self.dnaStore)

        tree = loader.loadDNA("phase_3.5/dna/storage_interior.xml").store(self.dnaStore)

    def loadDnaStore(self):
        if not hasattr(self, "dnaStore"):
            self.dnaStore = DNAStorage()

            loader.loadDNA("phase_4/dna/storage.xml").store(self.dnaStore)

            self.dnaStore.storeFont(ToontownGlobals.getInterfaceFont(), "humanist")
            self.dnaStore.storeFont(ToontownGlobals.getSignFont(), "mickey")
            self.dnaStore.storeFont(ToontownGlobals.getSuitFont(), "suit")

            loader.loadDNA("phase_3.5/dna/storage_interior.xml").store(self.dnaStore)

    def unloadDnaStore(self):
        if hasattr(self, "dnaStore"):
            # self.dnaStore.resetNodes()
            # self.dnaStore.resetTextures()
            del self.dnaStore
            ModelPool.garbageCollect()
            TexturePool.garbageCollect()

    def unload(self):
        self.unloadDnaStore()
        if self.hood:
            self.notify.info("Aggressively cleaning up hood: %s" % self.hood)
            self.hood.exit()
            self.hood.unload()
            self.hood = None
        return

    def enterStart(self):
        pass

    def exitStart(self):
        pass

    def handleHoodDone(self):
        doneStatus = self.hood.getDoneStatus()
        shardId = doneStatus["shardId"]
        if shardId != None:
            self.doneStatus = doneStatus
            messenger.send(self.doneEvent)
            base.transitions.fadeOut(0)
            return
        if doneStatus["where"] == "party":
            self.getPartyZoneAndGoToParty(doneStatus["avId"], doneStatus["zoneId"])
            return
        how = doneStatus["how"]
        if how in ["tunnelIn", "teleportIn", "doorIn", "elevatorIn", "walk"]:
            self.fsm.request("quietZone", [doneStatus])
        else:
            self.notify.error("Exited hood with unexpected mode %s" % how)
        return

    def _destroyHood(self):
        self.ignore(self.hoodDoneEvent)
        self.hood.exit()
        self.hood.unload()
        self.hood = None
        base.cr.cache.flush()
        return

    def enterQuietZone(self, requestStatus):
        self.acceptOnce(self.quietZoneDoneEvent, self.handleQuietZoneDone)
        self.quietZoneStateData = QuietZoneState.QuietZoneState(self.quietZoneDoneEvent)
        self._quietZoneLeftEvent = self.quietZoneStateData.getQuietZoneLeftEvent()
        if base.placeBeforeObjects:
            self.acceptOnce(self._quietZoneLeftEvent, self.handleLeftQuietZone)
        self._enterWaitForSetZoneResponseMsg = self.quietZoneStateData.getEnterWaitForSetZoneResponseMsg()
        self.acceptOnce(self._enterWaitForSetZoneResponseMsg, self.handleWaitForSetZoneResponse)
        self.quietZoneStateData.load()
        self.quietZoneStateData.enter(requestStatus)

    def exitQuietZone(self):
        self.ignore(self._quietZoneLeftEvent)
        self.ignore(self._enterWaitForSetZoneResponseMsg)
        if not base.placeBeforeObjects:
            self.ignore(self.quietZoneDoneEvent)
            self.quietZoneStateData.exit()
            self.quietZoneStateData.unload()
            self.quietZoneStateData = None
        return

    def handleWaitForSetZoneResponse(self, requestStatus):
        hoodId = requestStatus["hoodId"]
        canonicalHoodId = ZoneUtil.getCanonicalZoneId(hoodId)
        toHoodPhrase = ToontownGlobals.hoodNameMap[canonicalHoodId][0]
        hoodName = ToontownGlobals.hoodNameMap[canonicalHoodId][-1]
        zoneId = requestStatus["zoneId"]
        requestStatus["loader"] = "cogHQLoader" if ZoneUtil.isCogHQZone(hoodId) else requestStatus["loader"]
        loaderName = requestStatus["loader"]
        avId = requestStatus.get("avId", -1)
        ownerId = requestStatus.get("ownerId", avId)
        if config.GetBool("want-qa-regression", 0):
            self.notify.info("QA-REGRESSION: NEIGHBORHOODS: Visit %s" % hoodName)
        count = ToontownGlobals.hoodCountMap[canonicalHoodId]
        if loaderName == "safeZoneLoader":
            count += ToontownGlobals.safeZoneCountMap[canonicalHoodId]
        elif loaderName == "townLoader":
            count += ToontownGlobals.townCountMap[canonicalHoodId]
        if not loader.inBulkBlock:
            if hoodId == ToontownGlobals.MyEstate:
                if avId == -1:
                    loader.beginBulkLoad("hood", TTLocalizer.HeadingToYourEstate, count, 1, TTLocalizer.TIP_ESTATE)
                else:
                    owner = base.cr.identifyAvatar(ownerId)
                    if owner == None:
                        friend = base.cr.identifyAvatar(avId)
                        if friend != None:
                            avName = friend.getName()
                            loader.beginBulkLoad(
                                "hood", TTLocalizer.HeadingToFriend % avName, count, 1, TTLocalizer.TIP_ESTATE
                            )
                        else:
                            self.notify.warning("we can't perform this teleport")
                            return
                    else:
                        avName = owner.getName()
                        loader.beginBulkLoad(
                            "hood", TTLocalizer.HeadingToEstate % avName, count, 1, TTLocalizer.TIP_ESTATE
                        )
            elif ZoneUtil.isCogHQZone(zoneId):
                loader.beginBulkLoad(
                    "hood",
                    TTLocalizer.HeadingToHood % {"to": toHoodPhrase, "hood": hoodName},
                    count,
                    1,
                    TTLocalizer.TIP_COGHQ,
                )
            elif ZoneUtil.isGoofySpeedwayZone(zoneId):
                loader.beginBulkLoad(
                    "hood",
                    TTLocalizer.HeadingToHood % {"to": toHoodPhrase, "hood": hoodName},
                    count,
                    1,
                    TTLocalizer.TIP_KARTING,
                )
            else:
                loader.beginBulkLoad(
                    "hood",
                    TTLocalizer.HeadingToHood % {"to": toHoodPhrase, "hood": hoodName},
                    count,
                    1,
                    TTLocalizer.TIP_GENERAL,
                )
        if hoodId == ToontownGlobals.Tutorial:
            self.loadDnaStoreTutorial()
        else:
            self.loadDnaStore()
        hoodClass = self.getHoodClassByNumber(canonicalHoodId)
        self.hood = hoodClass(self.fsm, self.hoodDoneEvent, self.dnaStore, hoodId)
        self.hood.load()
        self.hood.loadLoader(requestStatus)
        if not base.placeBeforeObjects:
            loader.endBulkLoad("hood")
        return

    def handleLeftQuietZone(self):
        status = self.quietZoneStateData.getRequestStatus()
        hoodId = ZoneUtil.getCanonicalZoneId(status["hoodId"])
        hoodState = self.getHoodStateByNumber(hoodId)
        self.fsm.request(hoodState, [status])

    def handleQuietZoneDone(self):
        if base.placeBeforeObjects:
            self.quietZoneStateData.exit()
            self.quietZoneStateData.unload()
            self.quietZoneStateData = None
            loader.endBulkLoad("hood")
        else:
            self.handleLeftQuietZone()
        return

    def enterTTHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitTTHood(self):
        self._destroyHood()

    def enterDDHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitDDHood(self):
        self._destroyHood()

    def enterMMHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitMMHood(self):
        self._destroyHood()

    def enterBRHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitBRHood(self):
        self._destroyHood()

    def enterDGHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitDGHood(self):
        self._destroyHood()

    def enterDLHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitDLHood(self):
        self._destroyHood()

    def enterTFHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitTFHood(self):
        self._destroyHood()

    def enterGSHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitGSHood(self):
        self._destroyHood()

    def enterOZHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitOZHood(self):
        self._destroyHood()

    def enterGZHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitGZHood(self):
        self._destroyHood()

    def enterSellbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitSellbotHQ(self):
        self._destroyHood()

    def enterCashbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitCashbotHQ(self):
        self._destroyHood()

    def enterLawbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitLawbotHQ(self):
        self._destroyHood()

    def enterBossbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitBossbotHQ(self):
        self._destroyHood()

    def enterTutorialHood(self, requestStatus):
        messenger.send("toonArrivedTutorial")
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        base.localAvatar.book.obscureButton(1)
        base.localAvatar.book.setSafeMode(1)
        base.localAvatar.laffMeter.obscure(1)
        base.localAvatar.chatMgr.obscure(1, 1)
        base.localAvatar.obscureFriendsListButton(1)
        requestStatus["how"] = "tutorial"
        if config.GetString("language", "english") == "japanese":
            musicVolume = config.GetFloat("tutorial-music-volume", 0.5)
            requestStatus["musicVolume"] = musicVolume
        self.hood.enter(requestStatus)

    def exitTutorialHood(self):
        self.unloadDnaStore()
        self._destroyHood()
        base.localAvatar.book.obscureButton(0)
        base.localAvatar.book.setSafeMode(0)
        base.localAvatar.laffMeter.obscure(0)
        base.localAvatar.chatMgr.obscure(0, 0)
        base.localAvatar.obscureFriendsListButton(-1)

    def enterEstateHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitEstateHood(self):
        self._destroyHood()

    def getEstateZoneAndGoHome(self, avId, zoneId):
        self.doneStatus = {
            "avId": avId,
            "zoneId": zoneId,
            "hoodId": ToontownGlobals.MyEstate,
            "loader": "safeZoneLoader",
            "how": "teleportIn",
            "shardId": None,
        }
        self.acceptOnce("setLocalEstateZone", self.goHome)
        if avId > 0:
            base.cr.estateMgr.getLocalEstateZone(avId)
        else:
            base.cr.estateMgr.getLocalEstateZone(base.localAvatar.getDoId())
        return

    def goHome(self, ownerId, zoneId):
        self.notify.debug("goHome ownerId = %s" % ownerId)
        if ownerId > 0 and ownerId != base.localAvatar.doId and not base.cr.isFriend(ownerId):
            self.doneStatus["failed"] = 1
            taskMgr.remove("goHomeFailed")
            taskMgr.add(self.goHomeFailed, "goHomeFailed")
            return
        if ownerId == 0 and zoneId == 0:
            self.doneStatus["failed"] = 1
            self.goHomeFailed(None)
            return
        if self.doneStatus["zoneId"] != zoneId:
            self.doneStatus["where"] = "house"
        else:
            self.doneStatus["where"] = "estate"
        self.doneStatus["ownerId"] = ownerId
        self.fsm.request("quietZone", [self.doneStatus])
        return

    def goHomeFailed(self, task):
        self.notify.debug("goHomeFailed")
        failedToVisitAvId = self.doneStatus.get("avId")
        if failedToVisitAvId > 0:
            message = TTLocalizer.EstateTeleportFailedNotFriends % base.cr.identifyAvatar(failedToVisitAvId).getName()
        else:
            message = TTLocalizer.EstateTeleportFailed
        self.notify.debug("goHomeFailed, why =: %s" % message)
        self.ignore("setLocalEstateZone")
        zoneId = base.localAvatar.lastHood
        loaderName = ZoneUtil.getLoaderName(zoneId)
        whereName = ZoneUtil.getToonWhereName(zoneId)
        base.localAvatar.setSystemMessage(0, message)
        self.fsm.request(
            "quietZone",
            [
                {
                    "loader": loaderName,
                    "where": whereName,
                    "how": "teleportIn",
                    "hoodId": zoneId,
                    "zoneId": zoneId,
                    "shardId": None,
                }
            ],
        )
        return Task.done

    def enterPartyHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        requestStatus["where"] = "party"
        self.hood.enter(requestStatus)

    def exitPartyHood(self):
        self._destroyHood()

    def getPartyZoneAndGoToParty(self, avId, zoneId):
        self.doneStatus = {
            "avId": avId,
            "zoneId": zoneId,
            "hoodId": ToontownGlobals.PartyHood,
            "loader": "safeZoneLoader",
            "how": "teleportIn",
            "shardId": None,
        }
        if avId < 0:
            avId = base.localAvatar.getDoId()
        base.cr.partyManager.requestPartyZone(avId, zoneId, callback=self.goToParty)
        return

    def goToParty(self, ownerId, partyId, zoneId):
        if ownerId == 0 or partyId == 0 or zoneId == 0:
            self.doneStatus["where"] = "playground"
        else:
            self.doneStatus["where"] = "party"
        self.doneStatus["ownerId"] = ownerId
        self.doneStatus["partyId"] = partyId
        self.doneStatus["zoneId"] = zoneId
        self.fsm.request("quietZone", [self.doneStatus])

    def goToPartyFailed(self, reason):
        self.notify.debug("goToPartyFailed")
        failedToVisitAvId = self.doneStatus.get("avId")
        message = base.cr.partyManager.getGoToPartyFailedMessage(reason)
        self.notify.debug("goToPartyFailed, why =: %s" % message)
        self.ignore("gotLocalPartyZone")
        zoneId = base.localAvatar.lastHood
        loaderName = ZoneUtil.getLoaderName(zoneId)
        whereName = ZoneUtil.getToonWhereName(zoneId)
        base.localAvatar.setSystemMessage(0, message)
        self.fsm.request(
            "quietZone",
            [
                {
                    "loader": loaderName,
                    "where": whereName,
                    "how": "teleportIn",
                    "hoodId": zoneId,
                    "zoneId": zoneId,
                    "shardId": None,
                }
            ],
        )
        return Task.done

    def getCatalogCodes(self, category):
        numCodes = self.dnaStore.getNumCatalogCodes(category)
        codes = []
        for i in range(numCodes):
            codes.append(self.dnaStore.getCatalogCode(category, i))

        return codes

    def getNodePathList(self, catalogGroup):
        result = []
        codes = self.getCatalogCodes(catalogGroup)
        for code in codes:
            np = self.dnaStore.findNode(code)
            result.append(np)

        return result

    def getNodePathDict(self, catalogGroup):
        result = {}
        codes = self.getCatalogCodes(catalogGroup)
        for code in codes:
            np = self.dnaStore.findNode(code)
            result[code] = np

        return result

    def getHoodClassByNumber(self, hoodNumber):
        return self.Hood2ClassDict[hoodNumber]

    def getHoodStateByNumber(self, hoodNumber):
        return self.Hood2StateDict[hoodNumber]

    def setPlace(self, place):
        self.place = place
        if self.place:
            messenger.send("playGameSetPlace")

    def getPlace(self):
        return self.place

    def getPlaceId(self):
        if self.hood:
            return self.hood.hoodId
        else:
            return None
        return None
Beispiel #18
0
class PlayGame(StateData.StateData):
    notify = DirectNotifyGlobal.directNotify.newCategory('PlayGame')
    Hood2ClassDict = {
        ToontownGlobals.ToontownCentral: TTHood.TTHood,
        ToontownGlobals.DonaldsDock: DDHood.DDHood,
        ToontownGlobals.TheBrrrgh: BRHood.BRHood,
        ToontownGlobals.MinniesMelodyland: MMHood.MMHood,
        ToontownGlobals.DaisyGardens: DGHood.DGHood,
        ToontownGlobals.DonaldsDreamland: DLHood.DLHood,
        ToontownGlobals.GoofySpeedway: GSHood.GSHood,
        ToontownGlobals.OutdoorZone: OZHood.OZHood,
        ToontownGlobals.ToonFest: TFHood.TFHood,
        ToontownGlobals.Tutorial: TutorialHood.TutorialHood,
        ToontownGlobals.MyEstate: EstateHood.EstateHood,
        ToontownGlobals.BossbotHQ: BossbotHQ.BossbotHQ,
        ToontownGlobals.SellbotHQ: SellbotHQ.SellbotHQ,
        ToontownGlobals.CashbotHQ: CashbotHQ.CashbotHQ,
        ToontownGlobals.LawbotHQ: LawbotHQ.LawbotHQ,
        ToontownGlobals.GolfZone: GZHood.GZHood,
        ToontownGlobals.PartyHood: PartyHood.PartyHood,
        ToontownGlobals.OldDaisyGardens: ODGHood.ODGHood,
        ToontownGlobals.ScroogeBank: SBHood.SBHood
    }
    Hood2StateDict = {
        ToontownGlobals.ToontownCentral: 'TTHood',
        ToontownGlobals.DonaldsDock: 'DDHood',
        ToontownGlobals.TheBrrrgh: 'BRHood',
        ToontownGlobals.MinniesMelodyland: 'MMHood',
        ToontownGlobals.DaisyGardens: 'DGHood',
        ToontownGlobals.DonaldsDreamland: 'DLHood',
        ToontownGlobals.GoofySpeedway: 'GSHood',
        ToontownGlobals.OutdoorZone: 'OZHood',
        ToontownGlobals.ToonFest: 'TFHood',
        ToontownGlobals.Tutorial: 'TutorialHood',
        ToontownGlobals.MyEstate: 'EstateHood',
        ToontownGlobals.BossbotHQ: 'BossbotHQ',
        ToontownGlobals.SellbotHQ: 'SellbotHQ',
        ToontownGlobals.CashbotHQ: 'CashbotHQ',
        ToontownGlobals.LawbotHQ: 'LawbotHQ',
        ToontownGlobals.GolfZone: 'GZHood',
        ToontownGlobals.PartyHood: 'PartyHood',
        ToontownGlobals.OldDaisyGardens: 'ODGHood',
        ToontownGlobals.ScroogeBank: 'SBHood'
    }

    def __init__(self, parentFSM, doneEvent):
        StateData.StateData.__init__(self, doneEvent)
        self.place = None
        self.fsm = ClassicFSM.ClassicFSM('PlayGame', [
            State.State('start', self.enterStart, self.exitStart,
                        ['quietZone']),
            State.State('quietZone', self.enterQuietZone, self.exitQuietZone, [
                'TTHood', 'DDHood', 'BRHood', 'MMHood', 'DGHood', 'DLHood',
                'GSHood', 'OZHood', 'TFHood', 'GZHood', 'SellbotHQ',
                'CashbotHQ', 'LawbotHQ', 'BossbotHQ', 'TutorialHood',
                'EstateHood', 'PartyHood', 'ODGHood', 'SBHood'
            ]),
            State.State('TTHood', self.enterTTHood, self.exitTTHood,
                        ['quietZone']),
            State.State('DDHood', self.enterDDHood, self.exitDDHood,
                        ['quietZone']),
            State.State('BRHood', self.enterBRHood, self.exitBRHood,
                        ['quietZone']),
            State.State('MMHood', self.enterMMHood, self.exitMMHood,
                        ['quietZone']),
            State.State('DGHood', self.enterDGHood, self.exitDGHood,
                        ['quietZone']),
            State.State('ODGHood', self.enterODGHood, self.exitODGHood,
                        ['quietZone']),
            State.State('SBHood', self.enterSBHood, self.exitSBHood,
                        ['quietZone']),
            State.State('DLHood', self.enterDLHood, self.exitDLHood,
                        ['quietZone']),
            State.State('GSHood', self.enterGSHood, self.exitGSHood,
                        ['quietZone']),
            State.State('OZHood', self.enterOZHood, self.exitOZHood,
                        ['quietZone']),
            State.State('TFHood', self.enterTFHood, self.exitTFHood,
                        ['quietZone']),
            State.State('GZHood', self.enterGZHood, self.exitGZHood,
                        ['quietZone']),
            State.State('BossbotHQ', self.enterBossbotHQ, self.exitBossbotHQ,
                        ['quietZone']),
            State.State('SellbotHQ', self.enterSellbotHQ, self.exitSellbotHQ,
                        ['quietZone']),
            State.State('CashbotHQ', self.enterCashbotHQ, self.exitCashbotHQ,
                        ['quietZone']),
            State.State('LawbotHQ', self.enterLawbotHQ, self.exitLawbotHQ,
                        ['quietZone']),
            State.State('TutorialHood', self.enterTutorialHood,
                        self.exitTutorialHood, ['quietZone']),
            State.State('EstateHood', self.enterEstateHood,
                        self.exitEstateHood, ['quietZone']),
            State.State('PartyHood', self.enterPartyHood, self.exitPartyHood,
                        ['quietZone'])
        ], 'start', 'start')
        self.fsm.enterInitialState()
        self.parentFSM = parentFSM
        self.parentFSM.getStateNamed('playGame').addChild(self.fsm)
        self.hoodDoneEvent = 'hoodDone'
        self.hood = None
        self.quietZoneDoneEvent = uniqueName('quietZoneDone')
        self.quietZoneStateData = None
        return

    def enter(self, hoodId, zoneId, avId):
        if hoodId == ToontownGlobals.Tutorial:
            loaderName = 'townLoader'
            whereName = 'toonInterior'
        else:
            if hoodId == ToontownGlobals.MyEstate:
                self.getEstateZoneAndGoHome(avId, zoneId)
                return
            if hoodId == ToontownGlobals.PartyHood:
                self.getPartyZoneAndGoToParty(avId, zoneId)
                return
            loaderName = ZoneUtil.getLoaderName(zoneId)
            whereName = ZoneUtil.getToonWhereName(zoneId)
        self.fsm.request('quietZone', [{
            'loader': loaderName,
            'where': whereName,
            'how': 'teleportIn',
            'hoodId': hoodId,
            'zoneId': zoneId,
            'shardId': None,
            'avId': avId
        }])
        return

    def exit(self):
        if base.placeBeforeObjects and self.quietZoneStateData:
            self.quietZoneStateData.exit()
            self.quietZoneStateData.unload()
            self.quietZoneStateData = None
        self.ignore(self.quietZoneDoneEvent)
        return

    def load(self):
        pass

    def loadDnaStoreTutorial(self):
        self.dnaStore = DNAStorage()
        files = ('phase_3.5/dna/storage_tutorial.jazz',
                 'phase_3.5/dna/storage_interior.jazz')
        dnaBulk = DNABulkLoader(self.dnaStore, files)
        dnaBulk.loadDNAFiles()

    def loadDnaStore(self):
        if not hasattr(self, 'dnaStore'):
            self.dnaStore = DNAStorage()
            files = ('phase_4/dna/storage.jazz',
                     'phase_3.5/dna/storage_interior.jazz')
            dnaBulk = DNABulkLoader(self.dnaStore, files)
            dnaBulk.loadDNAFiles()
            self.dnaStore.storeFont('humanist',
                                    ToontownGlobals.getInterfaceFont())
            self.dnaStore.storeFont('mickey', ToontownGlobals.getSignFont())
            self.dnaStore.storeFont('suit', ToontownGlobals.getSuitFont())

    def unloadDnaStore(self):
        if hasattr(self, 'dnaStore'):
            self.dnaStore.resetNodes()
            self.dnaStore.resetTextures()
            del self.dnaStore
            ModelPool.garbageCollect()
            TexturePool.garbageCollect()

    def unload(self):
        self.unloadDnaStore()
        if self.hood:
            self.notify.info('Aggressively cleaning up hood: %s' % self.hood)
            self.hood.exit()
            self.hood.unload()
            self.hood = None
        return

    def enterStart(self):
        pass

    def exitStart(self):
        pass

    def handleHoodDone(self):
        doneStatus = self.hood.getDoneStatus()
        shardId = doneStatus['shardId']
        if shardId != None:
            self.doneStatus = doneStatus
            messenger.send(self.doneEvent)
            base.transitions.fadeOut(0)
            return
        if doneStatus['where'] == 'party':
            self.getPartyZoneAndGoToParty(doneStatus['avId'],
                                          doneStatus['zoneId'])
            return
        how = doneStatus['how']
        if how in ('tunnelIn', 'teleportIn', 'doorIn', 'elevatorIn', 'trainIn',
                   'walk'):
            self.fsm.request('quietZone', [doneStatus])
        else:
            self.notify.error('Exited hood with unexpected mode %s' % how)
        return

    def _destroyHood(self):
        self.ignore(self.hoodDoneEvent)
        self.hood.exit()
        self.hood.unload()
        self.hood = None
        base.cr.cache.flush()
        return

    def enterQuietZone(self, requestStatus):
        self.acceptOnce(self.quietZoneDoneEvent, self.handleQuietZoneDone)
        self.quietZoneStateData = QuietZoneState.QuietZoneState(
            self.quietZoneDoneEvent)
        self._quietZoneLeftEvent = self.quietZoneStateData.getQuietZoneLeftEvent(
        )
        if base.placeBeforeObjects:
            self.acceptOnce(self._quietZoneLeftEvent, self.handleLeftQuietZone)
        self._enterWaitForSetZoneResponseMsg = self.quietZoneStateData.getEnterWaitForSetZoneResponseMsg(
        )
        self.acceptOnce(self._enterWaitForSetZoneResponseMsg,
                        self.handleWaitForSetZoneResponse)
        self.quietZoneStateData.load()
        self.quietZoneStateData.enter(requestStatus)

    def exitQuietZone(self):
        self.ignore(self._quietZoneLeftEvent)
        self.ignore(self._enterWaitForSetZoneResponseMsg)
        if not base.placeBeforeObjects:
            self.ignore(self.quietZoneDoneEvent)
            self.quietZoneStateData.exit()
            self.quietZoneStateData.unload()
            self.quietZoneStateData = None
        return

    def handleWaitForSetZoneResponse(self, requestStatus):
        hoodId = requestStatus['hoodId']
        canonicalHoodId = ZoneUtil.getCanonicalZoneId(hoodId)
        toHoodPhrase = ToontownGlobals.hoodNameMap[canonicalHoodId][0]
        hoodName = ToontownGlobals.hoodNameMap[canonicalHoodId][(-1)]
        zoneId = requestStatus['zoneId']
        requestStatus['loader'] = 'cogHQLoader' if ZoneUtil.isCogHQZone(
            hoodId) else requestStatus['loader']
        loaderName = requestStatus['loader']
        avId = requestStatus.get('avId', -1)
        ownerId = requestStatus.get('ownerId', avId)
        if config.GetBool('want-qa-regression', 0):
            self.notify.info('QA-REGRESSION: NEIGHBORHOODS: Visit %s' %
                             hoodName)
        count = ToontownGlobals.hoodCountMap[canonicalHoodId]
        if loaderName == 'safeZoneLoader':
            count += ToontownGlobals.safeZoneCountMap[canonicalHoodId]
        else:
            if loaderName == 'townLoader':
                count += ToontownGlobals.townCountMap[canonicalHoodId]
        if not loader.inBulkBlock:
            if hoodId == ToontownGlobals.MyEstate:
                if avId == -1:
                    loader.beginBulkLoad('hood',
                                         TTLocalizer.HeadingToYourEstate,
                                         count, 1, TTLocalizer.TIP_ESTATE)
                else:
                    owner = base.cr.identifyAvatar(ownerId)
                    if owner == None:
                        friend = base.cr.identifyAvatar(avId)
                        if friend != None:
                            avName = friend.getName()
                            loader.beginBulkLoad(
                                'hood', TTLocalizer.HeadingToFriend % avName,
                                count, 1, TTLocalizer.TIP_ESTATE)
                        else:
                            self.notify.warning(
                                "we can't perform this teleport")
                            return
                    else:
                        avName = owner.getName()
                        loader.beginBulkLoad(
                            'hood', TTLocalizer.HeadingToEstate % avName,
                            count, 1, TTLocalizer.TIP_ESTATE)
            elif ZoneUtil.isCogHQZone(zoneId):
                loader.beginBulkLoad(
                    'hood', TTLocalizer.HeadingToHood % {
                        'to': toHoodPhrase,
                        'hood': hoodName
                    }, count, 1, TTLocalizer.TIP_COGHQ)
            elif zoneId == ToontownGlobals.ScroogeBank:
                loader.beginBulkLoad(
                    'hood', TTLocalizer.HeadingToHood % {
                        'to': TTLocalizer.Prologue[0],
                        'hood': TTLocalizer.Prologue[2]
                    }, count, 1, TTLocalizer.TIP_GENERAL)
            elif ZoneUtil.isGoofySpeedwayZone(zoneId):
                loader.beginBulkLoad(
                    'hood', TTLocalizer.HeadingToHood % {
                        'to': toHoodPhrase,
                        'hood': hoodName
                    }, count, 1, TTLocalizer.TIP_KARTING)
            else:
                loader.beginBulkLoad(
                    'hood', TTLocalizer.HeadingToHood % {
                        'to': toHoodPhrase,
                        'hood': hoodName
                    }, count, 1, TTLocalizer.TIP_GENERAL)
        if hoodId == ToontownGlobals.Tutorial:
            self.loadDnaStoreTutorial()
        else:
            self.loadDnaStore()
        hoodClass = self.getHoodClassByNumber(canonicalHoodId)
        self.hood = hoodClass(self.fsm, self.hoodDoneEvent, self.dnaStore,
                              hoodId)
        self.hood.load()
        self.hood.loadLoader(requestStatus)
        if not base.placeBeforeObjects:
            loader.endBulkLoad('hood')
        return

    def handleLeftQuietZone(self):
        status = self.quietZoneStateData.getRequestStatus()
        hoodId = ZoneUtil.getCanonicalZoneId(status['hoodId'])
        hoodState = self.getHoodStateByNumber(hoodId)
        self.fsm.request(hoodState, [status])

    def handleQuietZoneDone(self):
        if base.placeBeforeObjects:
            self.quietZoneStateData.exit()
            self.quietZoneStateData.unload()
            self.quietZoneStateData = None
            loader.endBulkLoad('hood')
        else:
            self.handleLeftQuietZone()
        return

    def enterTTHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitTTHood(self):
        self._destroyHood()

    def enterDDHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitDDHood(self):
        self._destroyHood()

    def enterMMHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitMMHood(self):
        self._destroyHood()

    def enterBRHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitBRHood(self):
        self._destroyHood()

    def enterDGHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitDGHood(self):
        self._destroyHood()

    def enterODGHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitODGHood(self):
        self._destroyHood()

    def enterSBHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitSBHood(self):
        self._destroyHood()

    def enterDLHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitDLHood(self):
        self._destroyHood()

    def enterGSHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitGSHood(self):
        self._destroyHood()

    def enterOZHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitOZHood(self):
        self._destroyHood()

    def enterTFHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitTFHood(self):
        self._destroyHood()

    def enterGZHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitGZHood(self):
        self._destroyHood()

    def enterSellbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitSellbotHQ(self):
        self._destroyHood()

    def enterCashbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitCashbotHQ(self):
        self._destroyHood()

    def enterLawbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitLawbotHQ(self):
        self._destroyHood()

    def enterBossbotHQ(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitBossbotHQ(self):
        self._destroyHood()

    def enterTutorialHood(self, requestStatus):
        messenger.send('toonArrivedTutorial')
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        base.localAvatar.book.obscureButton(1)
        base.localAvatar.book.setSafeMode(1)
        base.localAvatar.laffMeter.obscure(1)
        base.localAvatar.chatMgr.obscure(1, 1)
        base.localAvatar.obscureFriendsListButton(1)
        requestStatus['how'] = 'tutorial'
        if config.GetString('language', 'english') == 'japanese':
            musicVolume = config.GetFloat('tutorial-music-volume', 0.5)
            requestStatus['musicVolume'] = musicVolume
        self.hood.enter(requestStatus)

    def exitTutorialHood(self):
        self.unloadDnaStore()
        self._destroyHood()
        base.localAvatar.book.obscureButton(0)
        base.localAvatar.book.setSafeMode(0)
        base.localAvatar.laffMeter.obscure(0)
        base.localAvatar.chatMgr.obscure(0, 0)
        base.localAvatar.obscureFriendsListButton(-1)

    def enterEstateHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        self.hood.enter(requestStatus)

    def exitEstateHood(self):
        self._destroyHood()

    def getEstateZoneAndGoHome(self, avId, zoneId):
        self.doneStatus = {
            'avId': avId,
            'zoneId': zoneId,
            'hoodId': ToontownGlobals.MyEstate,
            'loader': 'safeZoneLoader',
            'how': 'teleportIn',
            'shardId': None
        }
        self.acceptOnce('setLocalEstateZone', self.goHome)
        if avId > 0:
            base.cr.estateMgr.getLocalEstateZone(avId)
        else:
            base.cr.estateMgr.getLocalEstateZone(base.localAvatar.getDoId())
        return

    def goHome(self, ownerId, zoneId):
        self.notify.debug('goHome ownerId = %s' % ownerId)
        if ownerId > 0 and ownerId != base.localAvatar.doId and not base.cr.isFriend(
                ownerId):
            self.doneStatus['failed'] = 1
            taskMgr.remove('goHomeFailed')
            taskMgr.add(self.goHomeFailed, 'goHomeFailed')
            return
        if ownerId == 0 and zoneId == 0:
            self.doneStatus['failed'] = 1
            self.goHomeFailed(None)
            return
        if self.doneStatus['zoneId'] != zoneId:
            self.doneStatus['where'] = 'house'
        else:
            self.doneStatus['where'] = 'estate'
        self.doneStatus['ownerId'] = ownerId
        self.fsm.request('quietZone', [self.doneStatus])
        return

    def goHomeFailed(self, task):
        self.notify.debug('goHomeFailed')
        failedToVisitAvId = self.doneStatus.get('avId')
        if failedToVisitAvId > 0:
            message = TTLocalizer.EstateTeleportFailedNotFriends % base.cr.identifyAvatar(
                failedToVisitAvId).getName()
        else:
            message = TTLocalizer.EstateTeleportFailed
        self.notify.debug('goHomeFailed, why =: %s' % message)
        self.ignore('setLocalEstateZone')
        zoneId = base.localAvatar.lastHood
        loaderName = ZoneUtil.getLoaderName(zoneId)
        whereName = ZoneUtil.getToonWhereName(zoneId)
        base.localAvatar.setSystemMessage(0, message)
        self.fsm.request('quietZone', [{
            'loader': loaderName,
            'where': whereName,
            'how': 'teleportIn',
            'hoodId': zoneId,
            'zoneId': zoneId,
            'shardId': None
        }])
        return Task.done

    def enterPartyHood(self, requestStatus):
        self.accept(self.hoodDoneEvent, self.handleHoodDone)
        requestStatus['where'] = 'party'
        self.hood.enter(requestStatus)

    def exitPartyHood(self):
        self._destroyHood()

    def getPartyZoneAndGoToParty(self, avId, zoneId):
        self.doneStatus = {
            'avId': avId,
            'zoneId': zoneId,
            'hoodId': ToontownGlobals.PartyHood,
            'loader': 'safeZoneLoader',
            'how': 'teleportIn',
            'shardId': None
        }
        if avId < 0:
            avId = base.localAvatar.getDoId()
        base.cr.partyManager.requestPartyZone(avId,
                                              zoneId,
                                              callback=self.goToParty)
        return

    def goToParty(self, ownerId, partyId, zoneId):
        if ownerId == 0 or partyId == 0 or zoneId == 0:
            self.doneStatus['where'] = 'playground'
        else:
            self.doneStatus['where'] = 'party'
        self.doneStatus['ownerId'] = ownerId
        self.doneStatus['partyId'] = partyId
        self.doneStatus['zoneId'] = zoneId
        self.fsm.request('quietZone', [self.doneStatus])

    def goToPartyFailed(self, reason):
        self.notify.debug('goToPartyFailed')
        failedToVisitAvId = self.doneStatus.get('avId')
        message = base.cr.partyManager.getGoToPartyFailedMessage(reason)
        self.notify.debug('goToPartyFailed, why =: %s' % message)
        self.ignore('gotLocalPartyZone')
        zoneId = base.localAvatar.lastHood
        loaderName = ZoneUtil.getLoaderName(zoneId)
        whereName = ZoneUtil.getToonWhereName(zoneId)
        base.localAvatar.setSystemMessage(0, message)
        self.fsm.request('quietZone', [{
            'loader': loaderName,
            'where': whereName,
            'how': 'teleportIn',
            'hoodId': zoneId,
            'zoneId': zoneId,
            'shardId': None
        }])
        return Task.done

    def getCatalogCodes(self, category):
        numCodes = self.dnaStore.getNumCatalogCodes(category)
        codes = []
        for i in range(numCodes):
            codes.append(self.dnaStore.getCatalogCode(category, i))

        return codes

    def getNodePathList(self, catalogGroup):
        result = []
        codes = self.getCatalogCodes(catalogGroup)
        for code in codes:
            np = self.dnaStore.findNode(code)
            result.append(np)

        return result

    def getNodePathDict(self, catalogGroup):
        result = {}
        codes = self.getCatalogCodes(catalogGroup)
        for code in codes:
            np = self.dnaStore.findNode(code)
            result[code] = np

        return result

    def getHoodClassByNumber(self, hoodNumber):
        return self.Hood2ClassDict[hoodNumber]

    def getHoodStateByNumber(self, hoodNumber):
        return self.Hood2StateDict[hoodNumber]

    def setPlace(self, place):
        self.place = place
        if self.place:
            messenger.send('playGameSetPlace')

    def getPlace(self):
        return self.place

    def getPlaceId(self):
        if self.hood:
            return self.hood.hoodId
        return
        return
Beispiel #19
0
    def loadUrbanTrack(self):
        self.dnaStore = DNAStorage()
        files = ('phase_4/dna/storage.jazz', 'phase_5/dna/storage_town.jazz', 'phase_4/dna/storage_TT.jazz',
                 'phase_5/dna/storage_TT_town.jazz', 'phase_8/dna/storage_BR.jazz',
                 'phase_8/dna/storage_BR_town.jazz', 'phase_8/dna/storage_DL.jazz',
                 'phase_8/dna/storage_DL_town.jazz')
        dnaBulk = DNABulkLoader(self.dnaStore, files)
        dnaBulk.loadDNAFiles()
        dnaFile = 'phase_6/dna/urban_track_town.jazz'
        if self.trackId in (RaceGlobals.RT_Urban_2, RaceGlobals.RT_Urban_2_rev):
            dnaFile = 'phase_6/dna/urban_track_town_B.jazz'
        node = loader.loadDNAFile(self.dnaStore, dnaFile)
        self.geomNode = node
        self.townGeom = self.geom.attachNewNode(node)
        self.townGeom.findAllMatches('**/+CollisionNode').stash()
        self.buildingGroups = {}
        self.currBldgInd = {}
        self.currBldgGroups = {}
        bgGeom = self.geom.find('**/polySurface8')
        if self.dummyNode:
            bgGeom.reparentTo(self.dummyNode)
        else:
            bgGeom.reparentTo(localAvatar)
        bgGeom.setScale(0.1)
        ce = CompassEffect.make(NodePath(), CompassEffect.PRot)
        bgGeom.node().setEffect(ce)
        bgGeom.setDepthTest(0)
        bgGeom.setDepthWrite(0)
        bgGeom.setBin('background', 102)
        bgGeom.setZ(-1)
        self.bgGeom = bgGeom
        l = self.geom.findAllMatches('**/+ModelNode')
        for n in l:
            n.node().setPreserveTransform(0)

        self.geom.flattenLight()
        maxNum = 0
        for side in ['inner', 'outer']:
            self.buildingGroups[side] = []
            self.currBldgInd[side] = None
            self.currBldgGroups[side] = None
            i = 0
            while 1:
                bldgGroup = self.townGeom.find('**/Buildings_' + side + '-' + str(i))
                if bldgGroup.isEmpty():
                    break
                l = bldgGroup.findAllMatches('**/+ModelNode')
                for n in l:
                    n2 = n.getParent().attachNewNode(n.getName())
                    n.getChildren().reparentTo(n2)
                    n.removeNode()

                bldgGroup.flattenStrong()
                if not bldgGroup.getNode(0).getBounds().isEmpty():
                    self.buildingGroups[side].append(bldgGroup)
                i += 1

            if i > maxNum:
                maxNum = i

        for side in ['innersidest', 'outersidest']:
            self.buildingGroups[side] = []
            self.currBldgInd[side] = None
            self.currBldgGroups[side] = None
            for i in xrange(maxNum):
                for barricade in ('innerbarricade', 'outerbarricade'):
                    bldgGroup = self.townGeom.find('**/Buildings_' + side + '-' + barricade + '_' + str(i))
                    if bldgGroup.isEmpty():
                        continue
                    l = bldgGroup.findAllMatches('**/+ModelNode')
                    for n in l:
                        n2 = n.getParent().attachNewNode(n.getName())
                        n.getChildren().reparentTo(n2)
                        n.removeNode()

                    self.buildingGroups[side].append(bldgGroup)

        treeNodes = self.townGeom.findAllMatches('**/prop_tree_*')
        for tree in treeNodes:
            tree.flattenStrong()

        snowTreeNodes = self.townGeom.findAllMatches('**/prop_snow_tree_*')
        for snowTree in snowTreeNodes:
            snowTree.flattenStrong()

        for side in ['inner', 'outer', 'innersidest', 'outersidest']:
            for grp in self.buildingGroups[side]:
                grp.stash()

        self.showBuildings(0)
        return