Esempio n. 1
0
 def enter(self, startTrack = None, playRate = None):
     StateData.StateData.enter(self)
     self.notify.debug('Walking ' + self.character.getName() + '... from ' + str(self.walkInfo[0]) + ' to ' + str(self.walkInfo[1]))
     posPoints = CCharPaths.getPointsFromTo(self.walkInfo[0], self.walkInfo[1], self.paths)
     lastPos = posPoints[-1]
     newLastPos = Point3(lastPos[0] + self.offsetX, lastPos[1] + self.offsetY, lastPos[2])
     posPoints[-1] = newLastPos
     firstPos = posPoints[0]
     newFirstPos = Point3(firstPos[0] + self.oldOffsetX, firstPos[1] + self.oldOffsetY, firstPos[2])
     posPoints[0] = newFirstPos
     self.walkTrack = Sequence(name=self.character.getName() + '-walk')
     if startTrack:
         self.walkTrack.append(startTrack)
     self.character.setPos(posPoints[0])
     raycast = CCharPaths.getRaycastFlag(self.walkInfo[0], self.walkInfo[1], self.paths)
     moveTrack = self.makePathTrack(self.character, posPoints, self.speed, raycast)
     if playRate:
         self.walkTrack.append(Func(self.character.setPlayRate, playRate, 'walk'))
     self.walkTrack.append(Func(self.character.loop, 'walk'))
     self.walkTrack.append(moveTrack)
     doneEventName = self.character.getName() + 'WalkDone'
     self.walkTrack.append(Func(messenger.send, doneEventName))
     ts = globalClockDelta.localElapsedTime(self.walkInfo[2])
     self.accept(doneEventName, self.doneHandler)
     self.notify.debug('walkTrack.start(%s)' % ts)
     self.walkTrack.start(ts)
Esempio n. 2
0
 def enter(self):
     destNode = self._CharWalkStateAI__lastWalkNode
     choices = CCharPaths.getAdjacentNodes(self._CharWalkStateAI__curWalkNode, self.paths)
     if len(choices) == 1:
         destNode = choices[0]
     else:
         while destNode == self._CharWalkStateAI__lastWalkNode:
             destNode = random.choice(CCharPaths.getAdjacentNodes(self._CharWalkStateAI__curWalkNode, self.paths))
     self.notify.debug(
         "Walking "
         + self.character.getName()
         + "... from "
         + str(self._CharWalkStateAI__curWalkNode)
         + "("
         + str(CCharPaths.getNodePos(self._CharWalkStateAI__curWalkNode, self.paths))
         + ") to "
         + str(destNode)
         + "("
         + str(CCharPaths.getNodePos(destNode, self.paths))
         + ")"
     )
     self.character.sendUpdate(
         "setWalk", [self._CharWalkStateAI__curWalkNode, destNode, globalClockDelta.getRealNetworkTime()]
     )
     duration = CCharPaths.getWalkDuration(self._CharWalkStateAI__curWalkNode, destNode, self.speed, self.paths)
     t = taskMgr.doMethodLater(
         duration, self.doneHandler, self.character.taskName(self.character.getName() + "DoneWalking")
     )
     t.newWalkNode = destNode
     self.destNode = destNode
Esempio n. 3
0
    def enter(self):
        destNode = self.__lastWalkNode
        choices = CCharPaths.getAdjacentNodes(self.__curWalkNode, self.paths)
        if len(choices) == 1:
            destNode = choices[0]
        else:
            while destNode == self.__lastWalkNode:
                destNode = random.choice(
                    CCharPaths.getAdjacentNodes(self.__curWalkNode,
                                                self.paths))

        self.notify.debug(
            'Walking ' + self.character.getName() + '... from ' +
            str(self.__curWalkNode) + '(' +
            str(CCharPaths.getNodePos(self.__curWalkNode, self.paths)) +
            ') to ' + str(destNode) + '(' +
            str(CCharPaths.getNodePos(destNode, self.paths)) + ')')
        self.character.sendUpdate('setWalk', [
            self.__curWalkNode, destNode,
            globalClockDelta.getRealNetworkTime()
        ])
        duration = CCharPaths.getWalkDuration(self.__curWalkNode, destNode,
                                              self.speed, self.paths)
        t = taskMgr.doMethodLater(
            duration, self.doneHandler,
            self.character.taskName(self.character.getName() + 'DoneWalking'))
        t.newWalkNode = destNode
        self.destNode = destNode
Esempio n. 4
0
    def enter(self, chipDestNode):
        destNode = self.__lastWalkNode
        choices = CCharPaths.getAdjacentNodes(self.__curWalkNode, self.paths)
        if len(choices) == 1:
            destNode = choices[0]
        else:
            while destNode == self.__lastWalkNode:
                destNode = random.choice(
                    CCharPaths.getAdjacentNodes(self.__curWalkNode,
                                                self.paths))

        destNode = chipDestNode
        self.notify.debug(
            'Walking ' + self.character.getName() + '... from ' +
            str(self.__curWalkNode) + '(' +
            str(CCharPaths.getNodePos(self.__curWalkNode, self.paths)) +
            ') to ' + str(destNode) + '(' +
            str(CCharPaths.getNodePos(destNode, self.paths)) + ')')
        self.offsetDistance = ToontownGlobals.DaleOrbitDistance
        angle = random.randint(0, 359)
        self.offsetX = math.cos(deg2Rad(angle)) * self.offsetDistance
        self.offsetY = math.sin(deg2Rad(angle)) * self.offsetDistance
        self.character.sendUpdate('setFollowChip', [
            self.__curWalkNode, destNode,
            globalClockDelta.getRealNetworkTime(), self.offsetX, self.offsetY
        ])
        duration = CCharPaths.getWalkDuration(self.__curWalkNode, destNode,
                                              self.speed, self.paths)
        t = taskMgr.doMethodLater(
            duration, self.__doneHandler,
            self.character.taskName(self.character.getName() + 'DoneWalking'))
        t.newWalkNode = destNode
 def generate(self):
     DistributedChar.DistributedChar.generate(self)
     self.setPos(CCharPaths.getNodePos(CCharPaths.startNode, CCharPaths.getPaths(self.getName())))
     self.setHpr(0, 0, 0)
     self.setParent(ToontownGlobals.SPRender)
     self.startBlink()
     self.startEarTask()
     self.chatTrack = Sequence()
     self.acceptOnce('enter' + self.cSphereNode.getName(), self._DistributedCCharBase__handleCollisionSphereEnter)
     self.accept('exitSafeZone', self._DistributedCCharBase__handleExitSafeZone)
Esempio n. 6
0
    def enter(self, chipDestNode):
        """
        ////////////////////////////////////////////////////////////////////
        // Function:   called when the character enters the walk state
        //             create a doLater to wait a specific amount of time
        //             while character gets to the destination on all client
        //             machines.
        // Parameters: none
        // Changes:
        ////////////////////////////////////////////////////////////////////
        """
        # choose a destination
        # choose a new destination node, different from last
        #import pdb; pdb.set_trace()
        destNode = self.__lastWalkNode
        choices = CCharPaths.getAdjacentNodes(self.__curWalkNode, self.paths)
        if len(choices) == 1:
            destNode = choices[0]
        else:
            while destNode == self.__lastWalkNode:
                destNode = random.choice(
                    CCharPaths.getAdjacentNodes(self.__curWalkNode,
                                                self.paths))

        destNode = chipDestNode
        self.notify.debug("Walking " +
                          self.character.getName() +
                          "... from " + \
                          str(self.__curWalkNode) + "(" +
                          str(CCharPaths.getNodePos(self.__curWalkNode,
                                                    self.paths))
                          + ") to " + \
                          str(destNode) + "(" +
                          str(CCharPaths.getNodePos(destNode,self.paths)) +
                          ")")
        # calculate an offset
        self.offsetDistance = ToontownGlobals.DaleOrbitDistance
        angle = random.randint(0, 359)
        self.offsetX = math.cos(deg2Rad(angle)) * self.offsetDistance
        self.offsetY = math.sin(deg2Rad(angle)) * self.offsetDistance

        # broadcast the walk
        self.character.sendUpdate("setFollowChip", [
            self.__curWalkNode, destNode,
            globalClockDelta.getRealNetworkTime(), self.offsetX, self.offsetY
        ])

        # set up a doLater to fire when character is done walking
        duration = CCharPaths.getWalkDuration(self.__curWalkNode, destNode,
                                              self.speed, self.paths)
        t = taskMgr.doMethodLater(
            duration, self.__doneHandler,
            self.character.taskName(self.character.getName() + "DoneWalking"))
        t.newWalkNode = destNode
Esempio n. 7
0
 def __init__(self, doneEvent, character, diffPath=None):
     StateData.StateData.__init__(self, doneEvent)
     self._CharWalkStateAI__doneEvent = doneEvent
     self.character = character
     if diffPath == None:
         self.paths = CCharPaths.getPaths(character.getName(), character.getCCLocation())
     else:
         self.paths = CCharPaths.getPaths(diffPath, character.getCCLocation())
     self.speed = character.walkSpeed()
     self._CharWalkStateAI__lastWalkNode = CCharPaths.startNode
     self._CharWalkStateAI__curWalkNode = CCharPaths.startNode
Esempio n. 8
0
 def __init__(self, doneEvent, character, diffPath=None):
     StateData.StateData.__init__(self, doneEvent)
     self.__doneEvent = doneEvent
     self.character = character
     if diffPath == None:
         self.paths = CCharPaths.getPaths(character.getName(), character.getCCLocation())
     else:
         self.paths = CCharPaths.getPaths(diffPath, character.getCCLocation())
     self.speed = character.walkSpeed()
     self.__lastWalkNode = CCharPaths.startNode
     self.__curWalkNode = CCharPaths.startNode
     return
    def makePathTrack(self, nodePath, posPoints, velocity, raycast=0):
        retval = Sequence()
        if raycast:
            retval.append(Func(nodePath.enableRaycast, 1))

        chip = base.cr.doId2do.get(self.chipId)
        self.chipPaths = CCharPaths.getPaths(chip.getName(),
                                             chip.getCCLocation())
        self.posPoints = posPoints
        chipDuration = chip.walk.walkTrack.getDuration()
        self.notify.debug('chipDuration = %f' % chipDuration)
        chipDistance = CCharPaths.getWalkDistance(self.srcNode, self.destNode,
                                                  ToontownGlobals.ChipSpeed,
                                                  self.chipPaths)
        self.revolutions = chipDistance / self.completeRevolutionDistance
        srcOffset = (0, 0)
        if self.srcNode in self.offsetDict:
            srcOffset = self.offsetDict[self.srcNode]

        srcTheta = math.atan2(srcOffset[1], srcOffset[0])
        if srcTheta < 0:
            srcTheta += 2 * math.pi

        if srcTheta > 0:
            srcRev = (2 * math.pi - srcTheta) / 2 * math.pi
        else:
            srcRev = 0
        self.srcTheta = srcTheta
        destOffset = (0, 0)
        if self.destNode in self.offsetDict:
            destOffset = self.offsetDict[self.destNode]

        destTheta = math.atan2(destOffset[1], destOffset[0])
        if destTheta < 0:
            destTheta += 2 * math.pi

        self.destTheta = destTheta
        self.revolutions += srcRev
        endingTheta = srcTheta + (self.revolutions % 1.0) * 2 * math.pi
        diffTheta = destTheta - endingTheta
        destRev = diffTheta / 2 * math.pi
        self.revolutions += destRev
        while self.revolutions < 1:
            self.revolutions += 1

        def positionDale(t):
            self.orbitChip(t)

        retval.append(LerpFunctionInterval(positionDale, chipDuration))
        if raycast:
            retval.append(Func(nodePath.enableRaycast, 0))

        return retval
Esempio n. 10
0
    def enter(self, startTrack=None, playRate=None):
        """
        startTrack, allows us to prepend a track to the walk
                    tracks (such as a stand up).
        playRate, sets the play rate for walk.

        start walking, create intervals to make the character
        move from start to destination
        """
        StateData.StateData.enter(self)
        self.notify.debug("Walking " + self.character.getName() +
                          "... from " +
                          str(self.walkInfo[0]) + " to " +
                          str(self.walkInfo[1]))

        posPoints = CCharPaths.getPointsFromTo(self.walkInfo[0],
                                               self.walkInfo[1],
                                               self.paths)
        lastPos = posPoints[-1]
        newLastPos = Point3( lastPos[0]+self.offsetX, lastPos[1]+self.offsetY, lastPos[2])
        posPoints[-1] = newLastPos
        firstPos = posPoints[0]
        newFirstPos = Point3( firstPos[0]+self.oldOffsetX, firstPos[1]+self.oldOffsetY, firstPos[2])
        posPoints[0] = newFirstPos

        self.walkTrack = Sequence(name = self.character.getName() + '-walk')
        if startTrack:
            self.walkTrack.append(startTrack)

        # Ensure we are placed at the beginning of the path before we
        # start the track.  This will put the character at the right
        # place even if the timestamp is way stale.
        self.character.setPos(posPoints[0])

        raycast = CCharPaths.getRaycastFlag(self.walkInfo[0],
                                            self.walkInfo[1],
                                            self.paths)
        moveTrack = self.makePathTrack(self.character, posPoints,
                                         self.speed, raycast)
        # make the walking animation and lerping happen at the same time
        if playRate:
            self.walkTrack.append(Func(self.character.setPlayRate, playRate, 'walk'))
        self.walkTrack.append(Func(self.character.loop, 'walk'))
        self.walkTrack.append(moveTrack)

        doneEventName = self.character.getName() + 'WalkDone'
        self.walkTrack.append(Func(messenger.send, doneEventName))

        ts = globalClockDelta.localElapsedTime(self.walkInfo[2])
        self.accept(doneEventName, self.doneHandler)
        self.notify.debug("walkTrack.start(%s)" % (ts))
        self.walkTrack.start(ts)
 def generate(self):
     DistributedChar.DistributedChar.generate(self)
     self.setPos(
         CCharPaths.getNodePos(CCharPaths.startNode,
                               CCharPaths.getPaths(self.getName())))
     self.setHpr(0, 0, 0)
     self.setParent(ToontownGlobals.SPRender)
     self.startBlink()
     self.startEarTask()
     self.chatTrack = Sequence()
     self.acceptOnce('enter' + self.cSphereNode.getName(),
                     self.__handleCollisionSphereEnter)
     self.accept('exitSafeZone', self.__handleExitSafeZone)
Esempio n. 12
0
    def enter(self):
        """
        ////////////////////////////////////////////////////////////////////
        // Function:   called when the character enters the walk state
        //             create a doLater to wait a specific amount of time
        //             while character gets to the destination on all client
        //             machines.
        // Parameters: none
        // Changes:
        ////////////////////////////////////////////////////////////////////
        """
        # choose a destination
        # choose a new destination node, different from last
        destNode = self.__lastWalkNode
        choices = CCharPaths.getAdjacentNodes(self.__curWalkNode, self.paths)
        if len(choices) == 1:
            destNode = choices[0]
        else:
            while destNode == self.__lastWalkNode:
                destNode = random.choice(
                    CCharPaths.getAdjacentNodes(self.__curWalkNode,
                                                self.paths))

        self.notify.debug("Walking " +
                          self.character.getName() +
                          "... from " + \
                          str(self.__curWalkNode) + "(" +
                          str(CCharPaths.getNodePos(self.__curWalkNode,
                                                    self.paths))
                          + ") to " + \
                          str(destNode) + "(" +
                          str(CCharPaths.getNodePos(destNode,self.paths)) +
                          ")")

        # broadcast the walk
        self.character.sendUpdate("setWalk", [
            self.__curWalkNode, destNode,
            globalClockDelta.getRealNetworkTime()
        ])

        # set up a doLater to fire when character is done walking
        duration = CCharPaths.getWalkDuration(self.__curWalkNode, destNode,
                                              self.speed, self.paths)
        t = taskMgr.doMethodLater(
            duration, self.doneHandler,
            self.character.taskName(self.character.getName() + "DoneWalking"))
        t.newWalkNode = destNode

        # keep track of the destination since dale needs to know about
        self.destNode = destNode
Esempio n. 13
0
 def __init__(self, doneEvent, character, diffPath = None):
     StateData.StateData.__init__(self, doneEvent)
     self.doneEvent = doneEvent
     self.character = character
     if diffPath == None:
         self.paths = CCharPaths.getPaths(character.getName(), character.getCCLocation())
     else:
         self.paths = CCharPaths.getPaths(diffPath, character.getCCLocation())
     self.speed = character.walkSpeed()
     self.offsetX = 0
     self.offsetY = 0
     self.oldOffsetX = 0
     self.olfOffsetY = 0
     self.walkTrack = None
Esempio n. 14
0
    def makePathTrack(self, nodePath, posPoints, velocity, raycast = 0):
        retval = Sequence()
        if raycast:
            retval.append(Func(nodePath.enableRaycast, 1))
        
        chip = base.cr.doId2do.get(self.chipId)
        self.chipPaths = CCharPaths.getPaths(chip.getName(), chip.getCCLocation())
        self.posPoints = posPoints
        chipDuration = chip.walk.walkTrack.getDuration()
        self.notify.debug('chipDuration = %f' % chipDuration)
        chipDistance = CCharPaths.getWalkDistance(self.srcNode, self.destNode, ToontownGlobals.ChipSpeed, self.chipPaths)
        self.revolutions = chipDistance / self.completeRevolutionDistance
        srcOffset = (0, 0)
        if self.srcNode in self.offsetDict:
            srcOffset = self.offsetDict[self.srcNode]
        
        srcTheta = math.atan2(srcOffset[1], srcOffset[0])
        if srcTheta < 0:
            srcTheta += 2 * math.pi
        
        if srcTheta > 0:
            srcRev = (2 * math.pi - srcTheta) / 2 * math.pi
        else:
            srcRev = 0
        self.srcTheta = srcTheta
        destOffset = (0, 0)
        if self.destNode in self.offsetDict:
            destOffset = self.offsetDict[self.destNode]
        
        destTheta = math.atan2(destOffset[1], destOffset[0])
        if destTheta < 0:
            destTheta += 2 * math.pi
        
        self.destTheta = destTheta
        self.revolutions += srcRev
        endingTheta = srcTheta + (self.revolutions % 1.0) * 2 * math.pi
        diffTheta = destTheta - endingTheta
        destRev = diffTheta / 2 * math.pi
        self.revolutions += destRev
        while self.revolutions < 1:
            self.revolutions += 1
        
        def positionDale(t):
            self.orbitChip(t)

        retval.append(LerpFunctionInterval(positionDale, chipDuration))
        if raycast:
            retval.append(Func(nodePath.enableRaycast, 0))
        
        return retval
 def generate(self, diffPath = None):
     DistributedChar.DistributedChar.generate(self)
     if diffPath == None:
         self.setPos(CCharPaths.getNodePos(CCharPaths.startNode, CCharPaths.getPaths(self.getName(), self.getCCLocation())))
     else:
         self.setPos(CCharPaths.getNodePos(CCharPaths.startNode, CCharPaths.getPaths(diffPath, self.getCCLocation())))
     self.setHpr(0, 0, 0)
     self.setParent(ToontownGlobals.SPRender)
     self.startBlink()
     self.startEarTask()
     self.chatTrack = Sequence()
     self.chatterDialogue = None
     self.acceptOnce('enter' + self.cSphereNode.getName(), self.__handleCollisionSphereEnter)
     self.accept('exitSafeZone', self.__handleExitSafeZone)
     return
Esempio n. 16
0
 def generate(self, diffPath = None):
     DistributedChar.DistributedChar.generate(self)
     if diffPath == None:
         self.setPos(CCharPaths.getNodePos(CCharPaths.startNode, CCharPaths.getPaths(self.getName(), self.getCCLocation())))
     else:
         self.setPos(CCharPaths.getNodePos(CCharPaths.startNode, CCharPaths.getPaths(diffPath, self.getCCLocation())))
     self.setHpr(0, 0, 0)
     self.setParent(ToontownGlobals.SPRender)
     self.startBlink()
     self.startEarTask()
     self.chatTrack = Sequence()
     self.chatterDialogue = None
     self.acceptOnce('enter' + self.cSphereNode.getName(), self.__handleCollisionSphereEnter)
     self.accept('exitSafeZone', self.__handleExitSafeZone)
     return
Esempio n. 17
0
 def __init__(self, doneEvent, character, diffPath = None):
     StateData.StateData.__init__(self, doneEvent)
     self.doneEvent = doneEvent
     self.character = character
     if diffPath == None:
         self.paths = CCharPaths.getPaths(character.getName(), character.getCCLocation())
     else:
         self.paths = CCharPaths.getPaths(diffPath, character.getCCLocation())
     self.speed = character.walkSpeed()
     self.offsetX = 0
     self.offsetY = 0
     self.oldOffsetX = 0
     self.olfOffsetY = 0
     self.walkTrack = None
     return
Esempio n. 18
0
 def enter(self, chipDestNode):
     destNode = self._CharFollowChipStateAI__lastWalkNode
     choices = CCharPaths.getAdjacentNodes(self._CharFollowChipStateAI__curWalkNode, self.paths)
     if len(choices) == 1:
         destNode = choices[0]
     else:
         while destNode == self._CharFollowChipStateAI__lastWalkNode:
             destNode = random.choice(
                 CCharPaths.getAdjacentNodes(self._CharFollowChipStateAI__curWalkNode, self.paths)
             )
     destNode = chipDestNode
     self.notify.debug(
         "Walking "
         + self.character.getName()
         + "... from "
         + str(self._CharFollowChipStateAI__curWalkNode)
         + "("
         + str(CCharPaths.getNodePos(self._CharFollowChipStateAI__curWalkNode, self.paths))
         + ") to "
         + str(destNode)
         + "("
         + str(CCharPaths.getNodePos(destNode, self.paths))
         + ")"
     )
     self.offsetDistance = ToontownGlobals.DaleOrbitDistance
     angle = random.randint(0, 359)
     self.offsetX = math.cos(deg2Rad(angle)) * self.offsetDistance
     self.offsetY = math.sin(deg2Rad(angle)) * self.offsetDistance
     self.character.sendUpdate(
         "setFollowChip",
         [
             self._CharFollowChipStateAI__curWalkNode,
             destNode,
             globalClockDelta.getRealNetworkTime(),
             self.offsetX,
             self.offsetY,
         ],
     )
     duration = CCharPaths.getWalkDuration(
         self._CharFollowChipStateAI__curWalkNode, destNode, self.speed, self.paths
     )
     t = taskMgr.doMethodLater(
         duration,
         self._CharFollowChipStateAI__doneHandler,
         self.character.taskName(self.character.getName() + "DoneWalking"),
     )
     t.newWalkNode = destNode
Esempio n. 19
0
 def __init__(self, doneEvent, character, followedChar):
     StateData.StateData.__init__(self, doneEvent)
     self._CharFollowChipStateAI__doneEvent = doneEvent
     self.character = character
     self.followedChar = followedChar
     self.paths = CCharPaths.getPaths(character.getName(), character.getCCLocation())
     self.speed = character.walkSpeed()
     self._CharFollowChipStateAI__lastWalkNode = CCharPaths.startNode
     self._CharFollowChipStateAI__curWalkNode = CCharPaths.startNode
Esempio n. 20
0
 def __init__(self, doneEvent, character, followedChar):
     StateData.StateData.__init__(self, doneEvent)
     self.__doneEvent = doneEvent
     self.character = character
     self.followedChar = followedChar
     self.paths = CCharPaths.getPaths(character.getName(), character.getCCLocation())
     self.speed = character.walkSpeed()
     self.__lastWalkNode = CCharPaths.startNode
     self.__curWalkNode = CCharPaths.startNode
Esempio n. 21
0
    def generate(self, diffPath=None):
        """
        This method is called when the DistributedObject is reintroduced
        to the world, either for the first time or from the cache.
        """
        DistributedChar.DistributedChar.generate(self)

        if diffPath == None:
            self.setPos(
                CCharPaths.getNodePos(
                    CCharPaths.startNode,
                    CCharPaths.getPaths(self.getName(), self.getCCLocation())))
        else:
            self.setPos(
                CCharPaths.getNodePos(
                    CCharPaths.startNode,
                    CCharPaths.getPaths(diffPath, self.getCCLocation())))

        self.setHpr(0, 0, 0)

        # The characters can be immediately parented to render.
        self.setParent(ToontownGlobals.SPRender)

        # hmm. does this character ever blink?
        self.startBlink()
        self.startEarTask()

        # the character's chat track
        self.chatTrack = Sequence()

        # Currently playing dialog
        self.chatterDialogue = None

        # listen for the collision sphere enter event
        self.acceptOnce("enter" + self.cSphereNode.getName(),
                        self.__handleCollisionSphereEnter)

        # listen for safe zone exit event
        self.accept("exitSafeZone", self.__handleExitSafeZone)
Esempio n. 22
0
    def showPathPoints(self, paths, waypoints):
        self.hideDebugPointText()
        lines = LineSegs()
        lines.setColor(1, 0, 0, 1)
        import CCharPaths
        for name, pointDef in paths.items():
            self.showDebugPointText(name, pointDef[0])
            for connectTo in pointDef[1]:
                toDef = paths[connectTo]
                fromP = pointDef[0]
                toP = toDef[0]
                lines.moveTo(fromP[0], fromP[1], fromP[2] + 2.0)
                wpList = CCharPaths.getWayPoints(name, connectTo, paths, waypoints)
                for wp in wpList:
                    lines.drawTo(wp[0], wp[1], wp[2] + 2.0)
                    self.showDebugPointText('*', wp)

                lines.drawTo(toP[0], toP[1], toP[2] + 2.0)

        self.debugText.attachNewNode(lines.create())
Esempio n. 23
0
 def showPathPoints(self, paths, waypoints):
     self.hideDebugPointText()
     lines = LineSegs()
     lines.setColor(1, 0, 0, 1)
     import CCharPaths
     for (name, pointDef) in paths.items():
         self.showDebugPointText(name, pointDef[0])
         for connectTo in pointDef[1]:
             toDef = paths[connectTo]
             fromP = pointDef[0]
             toP = toDef[0]
             lines.moveTo(fromP[0], fromP[1], fromP[2] + 2.0)
             wpList = CCharPaths.getWayPoints(name, connectTo, paths, waypoints)
             for wp in wpList:
                 lines.drawTo(wp[0], wp[1], wp[2] + 2.0)
                 self.showDebugPointText('*', wp)
             
             lines.drawTo(toP[0], toP[1], toP[2] + 2.0)
         
     
     self.debugText.attachNewNode(lines.create())
Esempio n. 24
0
 def __init__(self, doneEvent, character):
     StateData.StateData.__init__(self, doneEvent)
     self.__doneEvent = doneEvent
     self.character = character
     self.paths = CCharPaths.getPaths(character.getName())
     self.speed = character.walkSpeed()
Esempio n. 25
0
    def makePathTrack(self, nodePath, posPoints, velocity, raycast=0):
        """Create the interval of dale orbiting chip."""
        retval = Sequence()
        if raycast:
            retval.append(
                Func(nodePath.enableRaycast, 1))
        chip = base.cr.doId2do.get(self.chipId)
        self.chipPaths = CCharPaths.getPaths( chip.getName(),
                                          chip.getCCLocation() )
        self.posPoints = posPoints

        #chipDuration = CCharPaths.getWalkDuration(self.srcNode,
        #                                      self.destNode,
        #                                      ToontownGlobals.ChipSpeed,
        #                                      self.chipPaths)
        # using getWalkDuration returns a bigger duration than chip uses
        chipDuration = chip.walk.walkTrack.getDuration()
        self.notify.debug('chipDuration = %f' % chipDuration)
        chipDistance = CCharPaths.getWalkDistance(self.srcNode,
                                              self.destNode,
                                              ToontownGlobals.ChipSpeed,
                                              self.chipPaths)
        #import pdb; pdb.set_trace()
        self.revolutions = chipDistance / self.completeRevolutionDistance
        # now lets add in the extra revs from the randomization offset
        srcOffset = (0,0)
        if self.srcNode in self.offsetDict:
            srcOffset = self.offsetDict[self.srcNode]
        srcTheta = math.atan2(srcOffset[1], srcOffset[0])
        # srcTheta returns a value in range -pi to pi
        if srcTheta < 0:
            srcTheta += 2 * math.pi
        if srcTheta > 0:
            srcRev =  ( (2 * math.pi) - srcTheta) / ( 2 * math.pi)
        else:
            srcRev = 0
        self.srcTheta = srcTheta

        destOffset = (0,0)
        if self.destNode in self.offsetDict:
            destOffset = self.offsetDict[self.destNode]
        destTheta = math.atan2(destOffset[1], destOffset[0])
        # destTheta returns a value in range -pi to pi
        if destTheta < 0:
            destTheta += 2 * math.pi
        self.destTheta = destTheta

        self.revolutions += srcRev
        endingTheta = srcTheta+ ((self.revolutions % 1.0) * 2 * math.pi)
        diffTheta = destTheta - endingTheta
        destRev =  diffTheta / ( 2 * math.pi)
        self.revolutions += destRev

        # really short segments might produce negative revolutions
        while self.revolutions < 1:
            self.revolutions += 1

        def positionDale(t):
            self.orbitChip(t)

        retval.append(LerpFunctionInterval(positionDale, chipDuration))

        if raycast:
            retval.append(
                Func(nodePath.enableRaycast, 0))

        return retval