mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2024-10-31 16:57:54 +00:00
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
|
import ActiveCellAI
|
||
|
from direct.directnotify import DirectNotifyGlobal
|
||
|
|
||
|
class CrusherCellAI(ActiveCellAI.ActiveCellAI):
|
||
|
notify = DirectNotifyGlobal.directNotify.newCategory('CrusherCellAI')
|
||
|
|
||
|
def __init__(self, level, entId):
|
||
|
ActiveCellAI.ActiveCellAI.__init__(self, level, entId)
|
||
|
self.crushers = []
|
||
|
self.crushables = []
|
||
|
|
||
|
def destroy(self):
|
||
|
self.notify.info('destroy entity %s' % self.entId)
|
||
|
for entId in self.crushers:
|
||
|
self.unregisterCrusher(entId)
|
||
|
|
||
|
ActiveCellAI.ActiveCellAI.destroy(self)
|
||
|
|
||
|
def registerCrusher(self, entId):
|
||
|
if entId not in self.crushers:
|
||
|
ent = self.level.entities.get(entId, None)
|
||
|
if ent:
|
||
|
self.crushers.append(entId)
|
||
|
self.accept(ent.crushMsg, self.doCrush)
|
||
|
return
|
||
|
|
||
|
def unregisterCrusher(self, entId):
|
||
|
if entId in self.crushers:
|
||
|
self.crushers.remove(entId)
|
||
|
if not hasattr(self, 'level'):
|
||
|
self.notify.error("unregisterCrusher(%s): CrusherCellAI %s has no attrib 'level'" % (entId, self.entId))
|
||
|
ent = self.level.entities.get(entId, None)
|
||
|
if ent:
|
||
|
self.ignore(ent.crushMsg)
|
||
|
return
|
||
|
|
||
|
def registerCrushable(self, entId):
|
||
|
if entId not in self.crushables:
|
||
|
self.crushables.append(entId)
|
||
|
|
||
|
def unregisterCrushable(self, entId):
|
||
|
if entId in self.crushables:
|
||
|
self.crushables.remove(entId)
|
||
|
|
||
|
def doCrush(self, crusherId, axis):
|
||
|
self.notify.debug('doCrush %s' % crusherId)
|
||
|
for occupantId in self.occupantIds:
|
||
|
if occupantId in self.crushables:
|
||
|
crushObj = self.level.entities.get(occupantId, None)
|
||
|
if crushObj:
|
||
|
crushObj.doCrush(crusherId, axis)
|
||
|
else:
|
||
|
self.notify.warning("couldn't find crushable object %d" % self.occupantId)
|
||
|
|
||
|
return
|
||
|
|
||
|
def updateCrushables(self):
|
||
|
for id in self.crushables:
|
||
|
crushable = self.level.entities.get(id, None)
|
||
|
if crushable:
|
||
|
crushable.updateGrid()
|
||
|
|
||
|
return
|