def enterWalking(self, pointLetter, startPointLetter, ts): if self.walkIval: self.walkIval.finish() self.walkIval = None self.nametag.clearChatText() self.loop('walk') point = WALK_POINTS[self.charId][pointLetter][0] lastPoint = WALK_POINTS[self.charId][startPointLetter][0] seq = Sequence(name=self.uniqueName('DCharWalkIval')) if self.charId == PLUTO: seq.append(ActorInterval(self, 'stand')) elif self.charId == SLEEP_DONALD: seq.append(ActorInterval(self, 'neutral2walk')) seq.append(Func(self.loop, 'walk')) ival = NPCWalkInterval(self, point, startPos=lastPoint, fluid=1) seq.append(ival) seq.append(Func(self.loop, 'neutral')) seq.start(ts) self.currentPointLetter = pointLetter self.walkIval = ival
def createFlyPath(self): self.b_setAnimState('flyNeutral') if self.flyTrack: self.ignore(self.flyTrack.getDoneEvent()) self.flyTrack.pause() self.flyTrack = None point = random.choice(EGG.EAGLE_FLY_POINTS) if self.currentFlyPoint == point: self.createFlyPath() return if self.currentFlyPoint == None: point_list = list(EGG.EAGLE_FLY_POINTS) point_list.remove(point) startIndex = point_list.index(random.choice(point_list)) else: startIndex = -1 self.b_setSuitState(5, startIndex, EGG.EAGLE_FLY_POINTS.index(point)) mgRound = self.getMinigame().getRound() if mgRound: self.flyTrack = NPCWalkInterval(self, point, durationFactor = EGG.ROUND_2_EAGLE_SPEED[mgRound], startPos = self.getPos(render), fluid = 1, name = self.uniqueName('DEagleSuitAI-flyTrack')) self.flyTrack.setDoneEvent(self.flyTrack.getName()) self.acceptOnce(self.flyTrack.getDoneEvent(), self.handleFlyDone) self.flyTrack.start() self.currentFlyPoint = point else: return
def walk(self, speed=0.2): self.currentPathIndex += 1 if len(self.pathQueue) <= self.currentPathIndex: if self.getCurrentOrNextState() == 'Pursue': if self.getClosestPoint() != self.currentKey: if self.numTries >= self.maxTries: self.request('GoBackToGuardSpot') else: self.runToClosestPoint() else: if self.getCurrentOrNextState() == 'GoBackToGuardSpot': self.request('Guard') return print self.pathQueue[self.currentPathIndex] if self.currentPathIndex == 1 and self.pathQueue[0] == 1: startPoint = self.getPos(render) endPoint = CGG.FactoryWalkPoints[self.firstPoint] else: if self.pathQueue[0] == 0: self.pathQueue.remove(self.pathQueue[0]) key = self.pathQueue[self.currentPathIndex] endPoint = CGG.FactoryWalkPoints[key] oldKey = self.pathQueue[self.currentPathIndex - 1] startPoint = CGG.FactoryWalkPoints[oldKey] self.walkTrack = NPCWalkInterval(self, endPoint, speed, startPoint) self.walkTrack.setDoneEvent(self.uniqueName('guardWalkDone')) self.acceptOnce(self.uniqueName('guardWalkDone'), self.walk) self.walkTrack.start()
def walk(self, speed=0.2): self.currentPathIndex += 1 if len(self.pathQueue) <= self.currentPathIndex: if self.getCurrentOrNextState() == 'Pursue': if self.getClosestPoint() != self.currentKey: # Wow, the player ran off somewhere else! Go there! if self.numTries >= self.maxTries: # Dang it, give up, we can't get to them! self.request('GoBackToGuardSpot') else: self.runToClosestPoint() elif self.getCurrentOrNextState() == 'GoBackToGuardSpot': self.request('Guard') return print self.pathQueue[self.currentPathIndex] if self.currentPathIndex == 1 and self.pathQueue[0] == 1: # We need to walk from our guard point to the first waypoint in our path startPoint = self.getPos(render) endPoint = CGG.FactoryWalkPoints[self.firstPoint] else: if self.pathQueue[0] == 0: self.pathQueue.remove(self.pathQueue[0]) key = self.pathQueue[self.currentPathIndex] endPoint = CGG.FactoryWalkPoints[key] oldKey = self.pathQueue[self.currentPathIndex - 1] startPoint = CGG.FactoryWalkPoints[oldKey] self.walkTrack = NPCWalkInterval(self, endPoint, speed, startPoint) self.walkTrack.setDoneEvent(self.uniqueName('guardWalkDone')) self.acceptOnce(self.uniqueName('guardWalkDone'), self.walk) self.walkTrack.start()
def createPath(self, fromCurPos=False): durationFactor = 0.2 if not hasattr(self, 'currentPath'): self.currentPath = None if self.currentPath == None: path = random.choice(TutorialGlobals.SUIT_POINTS) self.currentPath = TutorialGlobals.SUIT_POINTS.index(path) startIndex = -1 else: if fromCurPos == False: startIndex = int(self.currentPath) else: startIndex = -1 self.currentPath += 1 if self.currentPath >= len(TutorialGlobals.SUIT_POINTS): self.currentPath = 0 path = TutorialGlobals.SUIT_POINTS[self.currentPath] endIndex = self.currentPath startPos = self.getPos(render) pathName = self.uniqueName('suitPath') self.walkTrack = NPCWalkInterval(self, path, startPos=startPos, name=pathName, durationFactor=durationFactor, fluid=1) self.walkTrack.setDoneEvent(self.walkTrack.getName()) self.acceptOnce(self.walkTrack.getDoneEvent(), self.createPath) self.walkTrack.start() self.b_setAnimState('walk') self.b_setSuitState(1, startIndex, endIndex)
def createPath(self, path_key=None, durationFactor=0.2, fromCurPos=False): if path_key == None and not len(self.currentPathQueue): path_key_list = CIGlobals.SuitPathData[self.hood][self.currentPath] path_key = random.choice(path_key_list) elif len(self.currentPathQueue): path_key = self.currentPathQueue[0] self.currentPathQueue.remove(path_key) endIndex = CIGlobals.SuitSpawnPoints[self.hood].keys().index(path_key) path = CIGlobals.SuitSpawnPoints[self.hood][path_key] if self.walkTrack: self.ignore(self.walkTrack.getDoneEvent()) self.walkTrack.clearToInitial() self.walkTrack = None if not self.currentPath or fromCurPos: startIndex = -1 else: oldPath = self.currentPath startIndex = CIGlobals.SuitSpawnPoints[self.hood].keys().index( oldPath) self.currentPath = path_key pathName = self.uniqueName('suitPath') self.walkTrack = NPCWalkInterval(self, path, startPos=self.getPos(render), name=pathName, durationFactor=durationFactor, fluid=1) self.walkTrack.setDoneEvent(self.walkTrack.getName()) self.startFollow() self.b_setSuitState(1, startIndex, endIndex)
def startMoveInterval(self, startX, startY, startZ, endX, endY, endZ, duration): self.stopMoving() endPos = Point3(endX, endY, endZ) self.moveIval = NPCWalkInterval(self, endPos, durationFactor=duration, fluid=1) self.moveIval.start()
def enterStationSlot(self, slot): self.cr.playGame.getPlace().fsm.request('station') camera.reparentTo(self) numSlots = len(self.circles) camera.setPos(self.numPlayers2CamPos[numSlots]) camera.setPos(camera.getPos(render)) camera.reparentTo(render) camera.lookAt(self) base.localAvatar.headsUp(slot) base.localAvatar.setAnimState('run') runTrack = NPCWalkInterval(base.localAvatar, slot.getPos(render), 0.1, startPos=base.localAvatar.getPos(render)) runTrack.setDoneEvent('SlotEnterDone') runTrack.start() base.acceptOnce('SlotEnterDone', self.__handleSlotEntrance)
def doPath(): global path if not len(path): suit.loop('neutral') return endX, endY = path[0] endPoint = Point3(endX, endY, 0) startPoint = suit.getPos(render) path.remove(path[0]) ival = NPCWalkInterval(suit, endPoint, 0.2, startPoint) ival.setDoneEvent(suit.uniqueName('guardWalkDone')) base.acceptOnce(suit.uniqueName('guardWalkDone'), doPath) ival.start() suit.loop('walk')
def enterWalking(self, startIndex, endIndex, ts=0.0): durationFactor = 0.2 if startIndex > -1: startPos = TutorialGlobals.SUIT_POINTS[startIndex] else: startPos = self.getPos(render) endPos = TutorialGlobals.SUIT_POINTS[endIndex] self.stopMoving() self.moveIval = NPCWalkInterval(self, endPos, durationFactor, startPos, fluid=1) self.moveIval.start(ts) self.animFSM.request('walk')
def enterEagleFly(self, startIndex, endIndex, ts=0.0): durationFactor = self.getFlySpeed() if startIndex > -1: startPos = EGG.EAGLE_FLY_POINTS[startIndex] else: startPos = self.getPos(render) endPos = EGG.EAGLE_FLY_POINTS[endIndex] if self.moveIval: self.moveIval.pause() self.moveIval = None self.moveIval = NPCWalkInterval(self, endPos, durationFactor=durationFactor, startPos=startPos, fluid=1) self.moveIval.start(ts) return
def walkBackToSpawnPointWithBarrel(self): pos = DGG.SpawnPoints[self.spawnPoint] startPos = self.getPos(render) self.b_setSuitState(1, -1, self.spawnPoint) durationFactor = 0.2 pathName = self.uniqueName('WalkBackToSpawn') self.walkTrack = NPCWalkInterval(self, pos, startPos=startPos, name=pathName, durationFactor=durationFactor, fluid=1) self.walkTrack.setDoneEvent(self.walkTrack.getName()) self.acceptOnce(self.walkTrack.getDoneEvent(), self.__walkedBack2Spawn) self.walkTrack.start() self.b_setAnimState( SuitGlobals.getAnimId(SuitGlobals.getAnimByName('tray-walk')))
def enterWalking(self, startIndex, endIndex, ts = 0.0): durationFactor = 0.2 if startIndex > -1: startPoint = CIGlobals.SuitSpawnPoints[self.getHood()].keys()[startIndex] startPos = CIGlobals.SuitSpawnPoints[self.getHood()][startPoint] else: startPos = self.getPos(render) endPoint = CIGlobals.SuitSpawnPoints[self.getHood()].keys()[endIndex] endPos = CIGlobals.SuitSpawnPoints[self.getHood()][endPoint] if self.moveIval: self.moveIval.pause() self.moveIval = None self.moveIval = NPCWalkInterval(self, endPos, durationFactor, startPos, fluid = 1) self.moveIval.start(ts) self.animFSM.request('walk')
def walkToTruck(self): index = DGG.WalkToTruckIndex pos = DGG.TruckSuitPointsByIndex[self.truckIndex] startPos = self.getPos(render) self.b_setSuitState(1, -1, index) durationFactor = 0.2 pathName = self.uniqueName('WalkToTruck') self.walkTrack = NPCWalkInterval(self, pos, startPos=startPos, name=pathName, durationFactor=durationFactor, fluid=1) self.walkTrack.setDoneEvent(self.walkTrack.getName()) self.acceptOnce(self.walkTrack.getDoneEvent(), self.__walkedToTruck) self.walkTrack.start() self.b_setAnimState( SuitGlobals.getAnimId(SuitGlobals.getAnimByName('walk')))
def throwGear(self, point): self.gearModel.reparentTo(self.getPart("body")) self.gearModel.setX(0.0) self.gearModel.setY(-2) self.gearModel.setZ(5) self.gearModel.setPos(self.gearModel.getPos(render)) self.gearModel.reparentTo(render) self.gearModel.show() self.gearModel.lookAt(point) if self.gearThrowIval: self.gearThrowIval.finish() self.gearThrowIval = None self.gearThrowIval = NPCWalkInterval(self.gearModel, point, durationFactor=0.01, fluid=1, lookAtTarget=False) self.gearThrowIval.start()
def enterWalking(self, startIndex, endIndex, ts=0.0): durationFactor = 0.2 if startIndex > -1: startPos = DGG.SpawnPoints[startIndex] else: startPos = self.getPos(render) if endIndex == DGG.WalkToTruckIndex: endPos = DGG.TruckSuitPointsByIndex[self.truckIndex] else: endPos = DGG.SpawnPoints[endIndex] self.stopMoving() self.moveIval = NPCWalkInterval(self, endPos, durationFactor, startPos, fluid=1) self.moveIval.start(ts)
def getMoveIvalFromPath(suit, path, elapsedT, isClient, seqName): moveIval = Sequence(name=suit.uniqueName(seqName)) if isClient: moveIval.append(Func(suit.animFSM.request, 'walk')) for i in xrange(len(path)): if i == 0: continue waypoint = path[i] lastWP = path[i - 1] moveIval.append(Func(suit.headsUp, Point3(*waypoint))) ival = NPCWalkInterval( suit, Point3(*waypoint), startPos=Point3(*lastWP), fluid=1, name=suit.uniqueName('doWalkIval' + str(i)), duration=(Point2(waypoint[0], waypoint[1]) - Point2(lastWP[0], lastWP[1])).length() * 0.2) moveIval.append(ival) if isClient: moveIval.append(Func(suit.animFSM.request, 'neutral')) return moveIval
def testNextWayPoint(self): self.numberOfTests += 1 if self.movementIval: self.movementIval.pause() self.movementIval = None if self.numberOfTests > len(self.wayPointsToTest.keys()) - 1: self.allTestsCompleted() return print "Test number " + str(self.numberOfTests) + " on waypoint " + str( self.number) self.currentWayPointTestKey = self.wayPointsToTest.keys()[ self.numberOfTests] self.movementIval = NPCWalkInterval( node, Point3(*self.wayPointsToTest[self.currentWayPointTestKey]['pos']), 0.005, startPos=self.point, fluid=1) self.movementIval.setDoneEvent('testWayPointDone') base.acceptOnce(self.movementIval.getDoneEvent(), self.currentTestSucceeded) base.acceptOnce("sensors-into", self.handleBadTest) self.movementIval.start()