Pushed what I have so far for grand prix

This commit is contained in:
John 2015-08-31 00:01:13 +03:00
parent 62d1aed98a
commit cc283ad32b
7 changed files with 84 additions and 20 deletions

Binary file not shown.

View file

@ -119,6 +119,9 @@ class NewsManagerAI(DistributedObjectAI):
return Task.again
def isGrandPrixRunning(self):
return self.isHolidayRunning(ToontownGlobals.SILLY_SATURDAY, ToontownGlobals.GRAND_PRIX) or True
@magicWord(category=CATEGORY_PROGRAMMER)
def newsShutdown():
"""

View file

@ -41,6 +41,8 @@ class DistributedRace(DistributedObject.DistributedObject):
SFX_Applause = SFX_BaseDir + 'KART_Applause_%d.ogg'
def __init__(self, cr):
if hasattr(base, 'race') and base.race:
base.race.delete()
self.qbox = loader.loadModel('phase_6/models/karting/qbox')
self.boostArrowTexture = loader.loadTexture('phase_6/maps/boost_arrow.jpg', 'phase_6/maps/boost_arrow_a.rgb')
self.boostArrowTexture.setMinfilter(Texture.FTLinear)
@ -182,6 +184,8 @@ class DistributedRace(DistributedObject.DistributedObject):
del i
self.piejectileManager.delete()
if not hasattr(base, 'race'):
return
if self.curveTs:
del self.curveTs
if self.curvePoints:
@ -194,13 +198,12 @@ class DistributedRace(DistributedObject.DistributedObject):
del self.anvilFall
del self.bananaSound
del self.localKart
DistributedObject.DistributedObject.delete(self)
taskMgr.remove(self.uniqueName('countdownTimerTask'))
taskMgr.remove('raceWatcher')
bboard.remove('race')
self.ignoreAll()
DistributedObject.DistributedObject.delete(self)
del base.race
return
def d_requestThrow(self, x, y, z):
self.sendUpdate('requestThrow', [x, y, z])
@ -721,6 +724,7 @@ class DistributedRace(DistributedObject.DistributedObject):
if self.trackId in (RaceGlobals.RT_Urban_2, RaceGlobals.RT_Urban_2_rev):
dnaFile = 'phase_6/dna/urban_track_town_B.pdna'
node = loader.loadDNAFile(self.dnaStore, dnaFile)
self.geomNode = node
self.townGeom = self.geom.attachNewNode(node)
self.townGeom.findAllMatches('**/+CollisionNode').stash()
self.buildingGroups = {}
@ -1219,8 +1223,8 @@ class DistributedRace(DistributedObject.DistributedObject):
def setRaceZone(self, zoneId, trackId):
hoodId = self.cr.playGame.hood.hoodId
base.loader.endBulkLoad('atRace')
self.kartCleanup()
#base.loader.endBulkLoad('atRace')
#self.kartCleanup()
self.doneBarrier('waitingForExit')
self.sendUpdate('racerLeft', [localAvatar.doId])
out = {'loader': 'racetrack',

View file

@ -15,7 +15,7 @@ from toontown.toonbase import TTLocalizer, ToontownGlobals
class DistributedRaceAI(DistributedObjectAI, FSM):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedRaceAI")
def __init__(self, air):
def __init__(self, air, circuitPoints=[], circuitWinnings=[]):
DistributedObjectAI.__init__(self, air)
FSM.__init__(self, 'DistributedRaceAI')
self.air = air
@ -33,6 +33,11 @@ class DistributedRaceAI(DistributedObjectAI, FSM):
self.livingGags = []
self.currentlyAffectedByAnvil = {}
self.avatarProgress = {}
print 'circuit points %s' % (circuitPoints,)
print 'circuit winnings %s' % (circuitWinnings,)
self.circuitPoints = circuitPoints
self.circuitWinnings = circuitWinnings
self.quitAvatars = []
self.startTime = globalClockDelta.networkToLocalTime(globalClockDelta.getRealNetworkTime()) + 3
def generate(self):
@ -46,9 +51,11 @@ class DistributedRaceAI(DistributedObjectAI, FSM):
kart.requestDelete()
for gag in self.livingGags:
gag.requestDelete()
self.air.deallocateZone(self.zoneId)
if not self.circuitLoop:
self.air.deallocateZone(self.zoneId)
for i in xrange(len(self.gags)):
taskMgr.remove('regenGag%i-%i' % (i, self.doId))
taskMgr.remove(self.uniqueName('next-race'))
DistributedObjectAI.delete(self)
def enterJoin(self):
@ -131,6 +138,9 @@ class DistributedRaceAI(DistributedObjectAI, FSM):
def setCircuitLoop(self, circuitLoop):
self.circuitLoop = circuitLoop
if self.circuitLoop and not self.circuitPoints:
self.circuitPoints = [0] * len(self.avatars)
self.circuitWinnings = [0] * len(self.avatars)
def getCircuitLoop(self):
return self.circuitLoop
@ -271,9 +281,36 @@ class DistributedRaceAI(DistributedObjectAI, FSM):
if not avId in self.avatars:
self.air.writeServerEvent('suspicious', avId, 'Toon tried to leave race they\'re not in!')
return
self.avatars.remove(avId)
if set(self.finishedAvatars) == set(self.avatars) or len(self.avatars) == 0:
self.requestDelete()
if self.circuitLoop and self.finishedAvatars:
if avId in self.quitAvatars:
return
self.quitAvatars.append(avId)
self.checkForNextRace()
else:
self.avatars.remove(avId)
if avId in self.quitAvatars:
self.quitAvatars.remove(avId)
if set(self.finishedAvatars) == set(self.avatars) or len(self.avatars) == 0:
self.requestDelete()
def checkForNextRace(self):
if len(self.quitAvatars) >= len(self.avatars):
trackId = self.circuitLoop[0]
self.nextRace = DistributedRaceAI(self.air, self.circuitPoints, self.circuitWinnings)
self.nextRace.setZoneId(self.zoneId)
self.nextRace.setTrackId(trackId)
self.nextRace.setRaceType(self.raceType)
self.nextRace.setAvatars(self.avatars)
self.nextRace.setCircuitLoop(self.circuitLoop)
self.nextRace.setStartingPlaces(range(len(self.avatars)))
self.nextRace.setLapCount(3)
taskMgr.doMethodLater(3, self.startNewRace, self.uniqueName('next-race'), extraArgs=[trackId])
def startNewRace(self, trackId, task=None):
self.nextRace.generateWithRequired(self.zoneId)
self.sendUpdate('setRaceZone', [self.zoneId, trackId])
def heresMyT(self, avId, laps, currentLapT, timestamp):
realAvId = self.air.getAvatarIdFromSender()
@ -299,6 +336,7 @@ class DistributedRaceAI(DistributedObjectAI, FSM):
av = self.air.doId2do.get(avId)
place = len(self.finishedAvatars)
listPlace = place + (4 - len(self.avatarProgress)) - 1
entryFee = RaceGlobals.getEntryFee(self.trackId, self.raceType)
bonus = 0
totalTime = globalClockDelta.networkToLocalTime(globalClockDelta.getRealNetworkTime()) - self.startTime
@ -310,8 +348,7 @@ class DistributedRaceAI(DistributedObjectAI, FSM):
winnings = RaceGlobals.PracticeWinnings
trophies = []
elif qualify:
offset = 4 - len(self.avatarProgress) # self.avatarProgress contains the amount of STARTING players.
winnings = entryFee * RaceGlobals.Winnings[(place+offset)-1]
winnings = entryFee * RaceGlobals.Winnings[listPlace]
trophies = self.calculateTrophies(avId, place == 1, qualify, totalTime)
else:
winnings = 0
@ -320,7 +357,18 @@ class DistributedRaceAI(DistributedObjectAI, FSM):
if av.getTickets() > RaceGlobals.MaxTickets:
av.b_setTickets(RaceGlobals.MaxTickets)
av.addStat(ToontownGlobals.STAT_RACING)
self.sendUpdate('setPlace', [avId, totalTime, place, entryFee, qualify, max((winnings-entryFee), 0), bonus, trophies, [], 0])
if self.circuitPoints:
avIndex = self.avatars.index(avId)
self.circuitPoints[avIndex] += RaceGlobals.CircuitPoints[place - 1]
self.sendUpdate('setPlace', [avId, totalTime, place, entryFee, qualify, max((winnings-entryFee), 0), bonus, trophies, self.circuitPoints, 0])
if self.circuitPoints:
self.circuitWinnings[avIndex] += winnings
del self.circuitLoop[0]
self.sendUpdate('setCircuitLoop', [self.circuitLoop])
self.sendUpdate('setCircuitPlace', [avId, place, entryFee, self.circuitWinnings[avIndex], bonus, trophies])
if len(self.finishedAvatars) == len(self.avatars):
self.sendUpdate('endCircuitRace')
def calculateTrophies(self, avId, won, qualify, time):
if won:
@ -436,6 +484,8 @@ class DistributedRaceAI(DistributedObjectAI, FSM):
count += 1
if len(self.avatars) == 0:
self.requestDelete()
else:
self.checkForNextRace()
def requestKart(self):
pass

View file

@ -50,7 +50,7 @@ class DistributedRacePadAI(DistributedKartPadAI, FSM):
taskMgr.remove('changeTrack%i' % self.doId)
def enterWaitCountdown(self):
taskMgr.doMethodLater(30, DistributedRacePadAI.startRace, 'startRace%i' % self.doId, [self])
taskMgr.doMethodLater(11, DistributedRacePadAI.startRace, 'startRace%i' % self.doId, [self])
def exitWaitCountdown(self):
taskMgr.remove('startRace%i' % self.doId)
@ -100,7 +100,7 @@ class DistributedRacePadAI(DistributedKartPadAI, FSM):
if self.runningMovie:
self.request('WaitBoarding')
return
if self.trackType != RaceGlobals.Practice:
if self.trackType != RaceGlobals.Practice and False:
count = 0
for block in self.startingBlocks:
if block.avId != 0:
@ -124,8 +124,13 @@ class DistributedRacePadAI(DistributedKartPadAI, FSM):
race.setZoneId(self.raceZone)
race.setTrackId(self.trackId)
race.setRaceType(self.trackType)
race.setCircuitLoop([])
race.setAvatars(avatars)
if self.trackType == RaceGlobals.Circuit:
print 'Circuit!'
print 'circuit loop: %s' % (RaceGlobals.getCircuitLoop(self.trackId),)
race.setCircuitLoop(RaceGlobals.getCircuitLoop(self.trackId))
else:
race.setCircuitLoop([])
race.setStartingPlaces(range(len(avatars)))
race.setLapCount(3)
race.generateWithRequired(self.raceZone)

View file

@ -129,7 +129,7 @@ class RaceResultsPanel(DirectFrame):
displayPar = Parallel(bonusSeq, ticketSeq)
displayPar.start()
self.entryListSeqs.append(displayPar)
if not circuitPoints == []:
if circuitPoints:
self.pointsLabel.show()
newPoints = circuitPoints[:].pop()
currentPoints = sum(circuitPoints[:-1])
@ -376,8 +376,7 @@ class RaceEndPanel(DirectFrame):
def updateWinningsFromCircuit(self, place, entryFee, winnings, bonus, trophies = ()):
print 'updateWinningsFromCircuit'
self.seq.finish()
totalTickets = winnings + entryFee + bonus
self.results.updateWinnings(place, totalTickets)
self.results.updateWinnings(place, winnings + entryFee + bonus)
self.startWinningsPanel(entryFee, winnings, 0, bonus, trophies, True)
def startWinningsPanel(self, entryFee, winnings, track, bonus = None, trophies = (), endOfCircuitRace = False):

View file

@ -205,7 +205,7 @@ def getTunnelSignName(genreId, padId):
RacePadId2RaceInfo = {0: (0, Practice, 3),
1: (1, Practice, 3),
2: (0, ToonBattle, 3),
3: (1, ToonBattle, 3)}
3: (1, Circuit, 3)}
def getGenreFromString(string):
if string == 'town':
@ -236,6 +236,9 @@ def getNextRaceInfo(prevTrackId, genreString, padId):
genre = getGenreFromString(genreString)
cPadId = getCanonicalPadId(padId)
raceInfo = RacePadId2RaceInfo.get(cPadId)
raceType = raceInfo[1]
if raceType == Circuit and not simbase.air.newsManager.isGrandPrixRunning():
raceType = ToonBattle
trackList = getTrackListByType(genre, raceInfo[0])
if trackList.count(prevTrackId) == 0:
trackId = trackList[1]
@ -244,7 +247,7 @@ def getNextRaceInfo(prevTrackId, genreString, padId):
index += 1
index %= len(trackList)
trackId = trackList[index]
return (trackId, raceInfo[1], raceInfo[2])
return (trackId, raceType, raceInfo[2])
TrackPath = 'phase_6/models/karting/'