Poodletooth-iLand/toontown/hood/OZHoodAI.py

98 lines
4.4 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from toontown.hood import HoodAI
from toontown.toonbase import ToontownGlobals
from toontown.distributed.DistributedTimerAI import DistributedTimerAI
from toontown.dna.DNAParser import DNAGroup, DNAVisGroup
from toontown.safezone.DistributedPicnicBasketAI import DistributedPicnicBasketAI
2015-03-03 16:10:12 -06:00
from toontown.safezone import DistributedGameTableAI
from toontown.hood import ZoneUtil
class OZHoodAI(HoodAI.HoodAI):
def __init__(self, air):
HoodAI.HoodAI.__init__(self, air,
ToontownGlobals.OutdoorZone,
ToontownGlobals.OutdoorZone)
self.timer = None
self.picnicTables = []
self.gameTables = []
self.startup()
def startup(self):
HoodAI.HoodAI.startup(self)
self.createTimer()
self.createPicnicTables()
if simbase.config.GetBool('want-game-tables', True):
self.createGameTables()
def createTimer(self):
self.timer = DistributedTimerAI(self.air)
self.timer.generateWithRequired(self.zoneId)
def findPicnicTables(self, dnaGroup, zoneId, area, overrideDNAZone=False):
2015-03-03 16:10:12 -06:00
picnicTables = []
if isinstance(dnaGroup, DNAGroup) and ('picnic_table' in dnaGroup.getName()):
nameInfo = dnaGroup.getName().split('_')
for i in xrange(dnaGroup.getNumChildren()):
childDnaGroup = dnaGroup.at(i)
if 'picnic_table' in childDnaGroup.getName():
pos = childDnaGroup.getPos()
hpr = childDnaGroup.getHpr()
picnicTable = DistributedPicnicBasketAI(
simbase.air, nameInfo[2],
2015-03-03 16:10:12 -06:00
pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2])
picnicTable.generateWithRequired(zoneId)
picnicTables.append(picnicTable)
elif isinstance(dnaGroup, DNAVisGroup) and (not overrideDNAZone):
zoneId = ZoneUtil.getTrueZoneId(int(dnaGroup.getName().split(':')[0]), zoneId)
2015-03-03 16:10:12 -06:00
for i in xrange(dnaGroup.getNumChildren()):
foundPicnicTables = self.findPicnicTables(
dnaGroup.at(i), zoneId, area, overrideDNAZone=overrideDNAZone)
picnicTables.extend(foundPicnicTables)
return picnicTables
def createPicnicTables(self):
2015-03-03 16:10:12 -06:00
self.picnicTables = []
for zoneId in self.getZoneTable():
dnaData = self.air.dnaDataMap.get(zoneId, None)
zoneId = ZoneUtil.getTrueZoneId(zoneId, self.zoneId)
2015-03-03 16:10:12 -06:00
if dnaData.getName() == 'root':
area = ZoneUtil.getCanonicalZoneId(zoneId)
2015-03-03 16:10:12 -06:00
foundPicnicTables = self.findPicnicTables(
dnaData, zoneId, area, overrideDNAZone=True)
2015-03-03 16:10:12 -06:00
self.picnicTables.extend(foundPicnicTables)
for picnicTable in self.picnicTables:
picnicTable.start()
def findGameTables(self, dnaGroup, zoneId, area, overrideDNAZone=False):
2015-03-03 16:10:12 -06:00
gameTables = []
if isinstance(dnaGroup, DNAGroup) and ('game_table' in dnaGroup.getName()):
for i in xrange(dnaGroup.getNumChildren()):
childDnaGroup = dnaGroup.at(i)
if 'game_table' in childDnaGroup.getName():
pos = childDnaGroup.getPos()
hpr = childDnaGroup.getHpr()
gameTable = DistributedGameTableAI.DistributedGameTableAI(simbase.air)
gameTable.setPosHpr(pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2])
gameTable.generateWithRequired(zoneId)
elif isinstance(dnaGroup, DNAVisGroup) and (not overrideDNAZone):
zoneId = ZoneUtil.getTrueZoneId(int(dnaGroup.getName().split(':')[0]), zoneId)
2015-03-03 16:10:12 -06:00
for i in xrange(dnaGroup.getNumChildren()):
foundGameTables = self.findGameTables(
dnaGroup.at(i), zoneId, area, overrideDNAZone=overrideDNAZone)
gameTables.extend(foundGameTables)
return gameTables
def createGameTables(self):
2015-03-03 16:10:12 -06:00
self.gameTables = []
for zoneId in self.getZoneTable():
dnaData = self.air.dnaDataMap.get(zoneId, None)
zoneId = ZoneUtil.getTrueZoneId(zoneId, self.zoneId)
2015-03-03 16:10:12 -06:00
if dnaData.getName() == 'root':
area = ZoneUtil.getCanonicalZoneId(zoneId)
2015-03-03 16:10:12 -06:00
foundGameTables = self.findGameTables(
dnaData, zoneId, area, overrideDNAZone=True)
2015-03-03 16:10:12 -06:00
self.gameTables.extend(foundGameTables)