def __init__(self, air): DistributedKartPadAI.__init__(self, air) FSM.__init__(self, 'DistributedRacePadAI') self.genre = 'urban' self.state = 'Off' self.trackInfo = [0, 0] self.laps = 3 self.avIds = []
def delete(self): # Remove any outstanding tasks for avId in list(self.kickAvDict.keys()): self.stopTimeout(self.kickAvDict.get(avId)) del self.kickAvDict[avId] del self.kickAvDict # Perform the Remaining Delete on the Super Class DistributedKartPadAI.delete(self)
def __init__(self, air): DistributedKartPadAI.__init__(self, air) FSM.__init__(self, 'DistributedRacePadAI') self.air = air self.trackId, self.trackType = [None, None] self.lastTime = globalClockDelta.getRealNetworkTime() self.shouldStart = False self.index = -1 self.nameType = 'urban'
def __init__(self, air, area): """ COMMENT """ # Initialize the KartPadAI Super Classes DistributedKartPadAI.__init__(self, air, area) # Initialize Instance Variables self.id = DistributedViewPadAI.id DistributedViewPadAI.id += 1 self.kickAvDict = {} self.lastEntered = 0
def addAvBlock(self, avId, block, paid): """ Purpose: The addAvBlock Method updates the starting block of the avatar that has requested entry to the block. Params: avId - the id of the avatar entering the block. block - the Starting Block object that the avatar will enter. Return: None """ # Call the Super Class Method success = DistributedKartPadAI.addAvBlock(self, avId, block, paid) if (success != KartGlobals.ERROR_CODE.success): return success # Need to store information here.... timeStamp = globalClockDelta.getRealNetworkTime() #self.d_setAvEnterPad( avId, timeStamp ) self.d_setLastEntered(timeStamp) # Start the countdown to kick the avatar out of the spot... self.kickAvDict[avId] = self.startCountdown(self.uniqueName( 'ExitViewPadTask|%s' % (avId)), self.__handleKickTimeout, KartGlobals.COUNTDOWN_TIME, params=[avId]) return success
def addAvBlock(self, avId, block, paid): """ Purpose: The addAvBlock Method updates the starting block of the avatar that has requested entry to the block. Params: avId - the id of the avatar entering the block. block - the Starting Block object that the avatar will enter. Return: None """ # Grab the avatar and make certain its valid av = self.air.doId2do.get(avId, None) if (not av): self.notify.warning("addAvBlock: Avatar not found with id %s" % (avId)) return KartGlobals.ERROR_CODE.eGeneric # Make sure this track is open #if (self.trackId in (RaceGlobals.RT_Urban_1, RaceGlobals.RT_Urban_1_rev) and # not simbase.config.GetBool('test-urban-track', 0)): # return KartGlobals.ERROR_CODE.eTrackClosed grandPrixWeekendRunning = self.air.holidayManager.isHolidayRunning( ToontownGlobals.CIRCUIT_RACING_EVENT) # trialer restriction - only Speedway Practice races if not paid and not grandPrixWeekendRunning: genre = RaceGlobals.getTrackGenre(self.trackId) if not ((genre == RaceGlobals.Speedway) and (self.trackType == RaceGlobals.Practice)): return KartGlobals.ERROR_CODE.eUnpaid if not (self.state == 'WaitEmpty' or self.state == 'WaitCountdown'): #you can only join a racepad in one of these states return KartGlobals.ERROR_CODE.eTooLate # Only check for non-practice races if (av.hasKart() and (not self.trackType == RaceGlobals.Practice)): # Check if the toon owns enough tickets for the race raceFee = RaceGlobals.getEntryFee(self.trackId, self.trackType) avTickets = av.getTickets() if (avTickets < raceFee): self.notify.debug( "addAvBlock: Avatar %s does not own enough tickets for the race!" ) return KartGlobals.ERROR_CODE.eTickets # Call the Super Class Method success = DistributedKartPadAI.addAvBlock(self, avId, block, paid) if (success != KartGlobals.ERROR_CODE.success): return success # A valid avatar has entered a starting block, now enter wait # countdown state. If already in the WaitCountdown state this # will not cause any harm. if (self.isOccupied()): self.request('WaitCountdown') return success
def removeAvBlock(self, avId, block): """ The removeAvBlock Method updates the starting block of the avatar which has requested removal from the starting block. Params: avId - the id of the avatar to remove from the block. block - the starting block object that the avatar will exit. Return: None """ # Call the SuperClass Method DistributedKartPadAI.removeAvBlock(self, avId, block) # Remove the avatar from the kick dictionary and update the # local client dictionary as well. if (avId in self.kickAvDict): self.stopCountdown(self.kickAvDict[avId]) del self.kickAvDict[avId]
def removeAvBlock(self, avId, block): """ The removeAvBlock Method updates the starting block of the avatar which has requested removal from the starting block. Params: avId - the id of the avatar to remove from the block. block - the starting block object that the avatar will exit. Return: None """ # Call the Super Class Method DistributedKartPadAI.removeAvBlock(self, avId, block) if (not self.isOccupied() and (self.timerTask is not None)): # Remove the TimerTask from the taskMgr and request # a state transition to the WaitEmpty since there are no # longer any toons occupying the kart. taskMgr.remove(self.timerTask) self.timerTask = None self.request('WaitEmpty')
def __init__(self, air, area, tunnelGenre, tunnelId): """ COMMENT """ # Initialize the KartPadAI and FSM Super Classes DistributedKartPadAI.__init__(self, air, area) FSM.__init__(self, "RacePad_%s_FSM" % (DistributedRacePadAI.id)) # Initialize Instance Variables self.id = DistributedRacePadAI.id DistributedRacePadAI.id += 1 self.tunnelId = tunnelId self.tunnelGenre = tunnelGenre self.timerTask = None raceInfo = RaceGlobals.getNextRaceInfo(-1, tunnelGenre, tunnelId) self.trackId = raceInfo[0] self.trackType = raceInfo[1] self.numLaps = raceInfo[2] self.raceMgr = self.air.raceMgr
def __startCountdown(self, name, callback, time, params=[]): """ Purpose: The __startCountdown Method generates a task that acts as a timer. It calls a specified callback method after the time period expires, and it additionally records a timestamp for when the timer began. Params: name - a unique name for the task. callback - method to handle the case when the timer expires. time - amount of time before the timer expires. params - extra arguments for the callback method. Return: None """ self.timerTask = self.stopCountdown(self.timerTask) self.timerTask = DistributedKartPadAI.startCountdown( self, name, callback, time, params)
def __init__(self, air): DistributedKartPadAI.__init__(self, air) self.timestamp = globalClockDelta.getRealNetworkTime()
def __init__(self, air): DistributedKartPadAI.__init__(self, air) self.lastEntered = globalClockDelta.getRealNetworkTime()
def generate(self): DistributedKartPadAI.generate(self) self.b_setState('WaitEmpty', globalClockDelta.getRealNetworkTime())
def __init__(self, air): DistributedKartPadAI.__init__(self, air) self.state = 'Off' self.trackInfo = [0, 0]
def __init__(self, air): DistributedKartPadAI.__init__(self, air) self.lastEntered = 0
def announceGenerate(self): DistributedKartPadAI.announceGenerate(self) self.lastEntered = globalClockDelta.getRealNetworkTime()
def delete(self): taskMgr.remove(self.uniqueName('changeTrack')) taskMgr.remove(self.uniqueName('countdownTask')) taskMgr.remove(self.uniqueName('enterRaceTask')) DistributedKartPadAI.delete(self)
def delete(self): DistributedKartPadAI.delete(self) FSM.cleanup(self)