Poodletooth-iLand/toontown/hood/OZHoodAI.py

103 lines
4.6 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from toontown.hood import HoodAI
from panda3d.core import *
2015-03-03 16:10:12 -06:00
from toontown.toonbase import ToontownGlobals
from toontown.distributed.DistributedTimerAI import DistributedTimerAI
import string
2015-03-03 16:10:12 -06:00
from toontown.dna.DNAParser import DNAGroup, DNAVisGroup
from toontown.safezone.DistributedPicnicBasketAI import DistributedPicnicBasketAI
from toontown.safezone import DistributedPicnicTableAI
from toontown.safezone import DistributedChineseCheckersAI
from toontown.safezone import DistributedCheckersAI
2015-03-03 16:10:12 -06:00
from toontown.hood import ZoneUtil
import random
2015-03-03 16:10:12 -06:00
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):
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],
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):
2015-05-24 09:21:40 -05:00
zoneId = int(dnaGroup.getName().split(':')[0])
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):
self.picnicTables = []
for zoneId in self.getZoneTable():
dnaData = self.air.dnaDataMap.get(zoneId, None)
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):
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()
nameInfo = childDnaGroup.getName().split('_')
2015-05-02 18:47:45 -05:00
tableIndex = int(childDnaGroup.get_parent().getName().split('_')[-1])
gameTable = DistributedPicnicTableAI.DistributedPicnicTableAI(simbase.air, zoneId, nameInfo[2], pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2])
gameTable.setTableIndex(tableIndex)
2015-05-02 18:47:45 -05:00
gameTable.generateOtpObject(simbase.air.districtId, zoneId, ['setX', 'setY', 'setZ', 'setH', 'setP', 'setR'])
2015-03-03 16:10:12 -06:00
elif isinstance(dnaGroup, DNAVisGroup) and (not overrideDNAZone):
2015-05-24 09:21:40 -05:00
zoneId = int(dnaGroup.getName().split(':')[0])
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):
self.gameTables = []
for zoneId in self.getZoneTable():
dnaData = self.air.dnaDataMap.get(zoneId, None)
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)