def updateVisibility(self, zoneNum=None):
        if zoneNum is None:
            zoneNum = self.curZoneNum
            if zoneNum is None:
                return
        if hasattr(self, 'lockVizZone'):
            zoneNum = self.lockVizZone
        zoneEnt = self.getEntity(zoneNum)
        visibleZoneNums = list2dict([zoneNum])
        visibleZoneNums.update(list2dict(zoneEnt.getVisibleZoneNums()))
        if not __debug__:
            if self.lastToonZone not in visibleZoneNums:
                if self.lastToonZone is not None:
                    self.notify.warning(
                        'adding zoneNum %s to visibility list because toon is standing in that zone!'
                        % self.lastToonZone)
                    visibleZoneNums.update(list2dict([self.lastToonZone]))
        zoneEntIds = list(self.entType2ids['zone'])
        zoneEntIds.remove(LevelConstants.UberZoneEntId)
        if len(zoneEntIds):
            pass
        vizZonesChanged = 1
        addedZoneNums = []
        removedZoneNums = []
        allVZ = dict(visibleZoneNums)
        allVZ.update(self.curVisibleZoneNums)
        for vz, dummy in allVZ.items():
            new = vz in visibleZoneNums
            old = vz in self.curVisibleZoneNums
            if new and old:
                continue
            if new:
                addedZoneNums.append(vz)
            else:
                removedZoneNums.append(vz)

        if not addedZoneNums and not removedZoneNums:
            DistributedLevel.notify.debug('visible zone list has not changed')
            vizZonesChanged = 0
        else:
            DistributedLevel.notify.debug('showing zones %s' % addedZoneNums)
            for az in addedZoneNums:
                self.showZone(az)

            DistributedLevel.notify.debug('hiding zones %s' % removedZoneNums)
            for rz in removedZoneNums:
                self.hideZone(rz)

        if vizZonesChanged or self.fForceSetZoneThisFrame:
            self.setVisibility(visibleZoneNums.keys())
            self.fForceSetZoneThisFrame = 0
        self.curZoneNum = zoneNum
        self.curVisibleZoneNums = visibleZoneNums
        return
    def resetVisibility(self):
        self.curVisibleZoneNums = list2dict(self.zoneNums)
        del self.curVisibleZoneNums[LevelConstants.UberZoneEntId]
        for vz, dummy in self.curVisibleZoneNums.items():
            self.showZone(vz)

        self.updateVisibility()
Example #3
0
        def setRequestNewEntity(self, data):
            spec = self.level.levelSpec
            entIds = spec.getAllEntIds()
            entIdDict = list2dict(entIds)
            allocRange = EditorGlobals.getEntIdAllocRange()
            if not hasattr(self, 'lastAllocatedEntId'):
                self.lastAllocatedEntId = allocRange[0]
            idChosen = 0
            while not idChosen:
                for id in range(self.lastAllocatedEntId, allocRange[1]):
                    print id
                    if id not in entIdDict:
                        idChosen = 1
                        break
                else:
                    if self.lastAllocatedEntId != allocRange[0]:
                        self.lastAllocatedEntId = allocRange[0]
                    else:
                        self.notify.error('out of entIds')

            data.update({'entId': id})
            self.lastAllocatedEntId = id
            self.level.setAttribChange(self.entId, 'insertEntity', data)
            self.level.levelSpec.doSetAttrib(self.entId, 'requestNewEntity', None)
            return
    def initVisibility(self):
        self.curVisibleZoneNums = list2dict(self.zoneNums)
        del self.curVisibleZoneNums[LevelConstants.UberZoneEntId]
        self.curZoneNum = None
        self.visChangedThisFrame = 0
        self.fForceSetZoneThisFrame = 0

        def handleCameraRayFloorCollision(collEntry, self=self):
            name = collEntry.getIntoNode().getName()
            self.notify.debug('camera floor ray collided with: %s' % name)
            prefixLen = len(DistributedLevel.FloorCollPrefix)
            if name[:prefixLen] == DistributedLevel.FloorCollPrefix:
                try:
                    zoneNum = int(name[prefixLen:])
                except:
                    DistributedLevel.notify.warning(
                        'Invalid zone floor collision node: %s' % name)
                else:
                    self.camEnterZone(zoneNum)

        self.accept('on-floor', handleCameraRayFloorCollision)
        if not DistributedLevel.WantVisibility:
            zoneNums = list(self.zoneNums)
            zoneNums.remove(LevelConstants.UberZoneEntId)
            self.forceSetZoneThisFrame()
            self.setVisibility(zoneNums)
        taskMgr.add(self.visChangeTask,
                    self.uniqueName(DistributedLevel.VisChangeTaskName),
                    priority=49)
        return
Example #5
0
        def checkSpecIntegrity(self):
            entIds = self.getGlobalEntIds()
            entIds = list2dict(entIds)
            for i in range(self.getNumScenarios()):
                for id in self.getScenarioEntIds(i):
                    entIds[id] = None

            if self.entTypeReg is not None:
                allEntIds = entIds
                for entId in allEntIds:
                    spec = self.getEntitySpec(entId)
                    entType = spec['type']
                    typeDesc = self.entTypeReg.getTypeDesc(entType)
                    attribNames = typeDesc.getAttribNames()
                    attribDescs = typeDesc.getAttribDescDict()
                    for attrib in spec.keys():
                        if attrib not in attribNames:
                            LevelSpec.notify.warning(
                                "entId %s (%s): unknown attrib '%s', omitting"
                                % (entId, spec['type'], attrib))
                            del spec[attrib]

                    for attribName in attribNames:
                        if not spec.has_key(attribName):
                            LevelSpec.notify.warning(
                                "entId %s (%s): missing attrib '%s'" %
                                (entId, spec['type'], attribName))

            return
 def __handleLevelMgrCreated(self):
     levelMgr = self.getEntity(LevelConstants.LevelMgrEntId)
     self.geom = levelMgr.geom
     self.zoneNum2node = LevelUtil.getZoneNum2Node(self.geom)
     self.zoneNums = self.zoneNum2node.keys()
     self.zoneNums.sort()
     self.zoneNumDict = list2dict(self.zoneNums)
     DistributedLevel.notify.debug('zones from model: %s' % self.zoneNums)
     self.fixupLevelModel()
Example #7
0
    def __init__(self, spec=None, scenario=0):
        newSpec = 0
        if type(spec) is types.ModuleType:
            if __dev__:
                reload(spec)
            self.specDict = spec.levelSpec
            if __dev__:
                self.setFilename(spec.__file__)
        elif type(spec) is types.DictType:
            self.specDict = spec
        elif spec is None:
            if __dev__:
                newSpec = 1
                self.specDict = {'globalEntities': {}, 'scenarios': [{}]}
        self.entId2specDict = {}
        self.entId2specDict.update(
            list2dict(self.getGlobalEntIds(),
                      value=self.privGetGlobalEntityDict()))
        for i in range(self.getNumScenarios()):
            self.entId2specDict.update(
                list2dict(self.getScenarioEntIds(i),
                          value=self.privGetScenarioEntityDict(i)))

        self.setScenario(scenario)
        if __dev__:
            if newSpec:
                import EntityTypes
                import EntityTypeRegistry
                etr = EntityTypeRegistry.EntityTypeRegistry(EntityTypes)
                self.setEntityTypeReg(etr)
                entId = LevelConstants.UberZoneEntId
                self.insertEntity(entId, 'zone')
                self.doSetAttrib(entId, 'name', 'UberZone')
                entId = LevelConstants.LevelMgrEntId
                self.insertEntity(entId, 'levelMgr')
                self.doSetAttrib(entId, 'name', 'LevelMgr')
                entId = LevelConstants.EditMgrEntId
                self.insertEntity(entId, 'editMgr')
                self.doSetAttrib(entId, 'name', 'EditMgr')
        return
Example #8
0
 def announceZoneChange(self, newZoneId, oldZoneId):
     DistributedPetAI.notify.debug('%s.announceZoneChange: %s->%s' %
                                   (self.doId, oldZoneId, newZoneId))
     broadcastZones = list2dict([newZoneId, oldZoneId])
     self.estateOwnerId = simbase.air.estateMgr.getOwnerFromZone(newZoneId)
     if self.estateOwnerId:
         if __dev__:
             pass
         self.inEstate = 1
         self.estateZones = simbase.air.estateMgr.getEstateZones(
             self.estateOwnerId)
     else:
         self.inEstate = 0
         self.estateZones = []
     PetObserve.send(
         broadcastZones.keys(),
         PetObserve.PetActionObserve(PetObserve.Actions.CHANGE_ZONE,
                                     self.doId, (oldZoneId, newZoneId)))
Example #9
0
    def _handlePhraseObserve(self, observe):
        def _handleGettingFriendlyAttention(avId, self=self):
            self.pet.lerpMoods({
                'boredom': -.85,
                'restlessness': -.1,
                'playfulness': 0.2,
                'loneliness': -.4,
                'sadness': -.1,
                'fatigue': -.05,
                'excitement': 0.05,
                'anger': -.05
            })
            self.updateLastInteractTime(avId)

        def _handleComeHere(avId, self=self):
            avatar = simbase.air.doId2do.get(avId)
            if avatar:
                self._chase(avatar)
                avatar.setHatePets(0)

        def _handleFollowMe(avId, self=self):
            avatar = simbase.air.doId2do.get(avId)
            if avatar:
                self._chase(avatar)
                avatar.setHatePets(0)

        def _handleStay(avId, self=self):
            avatar = simbase.air.doId2do.get(avId)
            if avatar:
                self._stay(avatar)

        def _handleCriticism(avId, self=self):
            ownerFactor = 0.5
            if avId == self.pet.ownerId:
                ownerFactor = 1.0
            self.pet.lerpMoods({
                'affection': -.4,
                'anger': 0.4,
                'boredom': -.3,
                'confusion': 0.05,
                'fatigue': 0.2,
                'playfulness': -.1,
                'sadness': 0.5 * ownerFactor
            })

        def _handleGoAway(avId, self=self):
            avatar = simbase.air.doId2do.get(avId)
            if avatar is not None:
                if self.getFocus() == avatar:
                    self._wander()
            return

        def _handleDoTrick(trickId, avId, self=self):
            avatar = simbase.air.doId2do.get(avId)
            if avatar:
                if self.lookedAtBy(avatar.doId):
                    if not self.goalMgr.hasTrickGoal():
                        if not self.pet._willDoTrick(trickId):
                            self.pet.trickFailLogger.addEvent(trickId)
                            trickId = PetTricks.Tricks.BALK
                        trickGoal = PetGoal.DoTrick(avatar, trickId)
                        self.goalMgr.addGoal(trickGoal)

        phrase = observe.getPetPhrase()
        avId = observe.getAvId()
        OP = PetObserve.Phrases
        if phrase in list2dict([
                OP.COME, OP.FOLLOW_ME, OP.STAY, OP.NEED_LAFF, OP.NEED_GAGS,
                OP.NEED_JB, OP.HI, OP.SOOTHE, OP.PRAISE, OP.HAPPY, OP.QUESTION,
                OP.FRIENDLY, OP.LETS_PLAY, OP.DO_TRICK
        ]):
            _handleGettingFriendlyAttention(avId)
        if phrase == OP.COME:
            _handleComeHere(avId)
        if phrase == OP.FOLLOW_ME:
            _handleFollowMe(avId)
        if phrase == OP.STAY:
            _handleStay(avId)
        if phrase == OP.CRITICISM:
            _handleCriticism(avId)
        if phrase == OP.GO_AWAY:
            _handleGoAway(avId)
        if phrase == OP.DO_TRICK:
            _handleDoTrick(observe.getTrickId(), avId)