2
0

EntityCreatorAI.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """EntityCreatorAI module: contains the EntityCreatorAI class"""
  2. import EntityCreatorBase
  3. import LogicGateAI
  4. import LevelMgrAI
  5. import ZoneEntityAI
  6. from PythonUtil import Functor
  7. # some useful constructor functions
  8. # ctor functions for entities must take
  9. # (level, entId, zoneId)
  10. # this func creates distributed entities whose constructors take
  11. # (air, level doId, entId)
  12. # and do not generate themselves
  13. def createDistributedEntity(AIclass, level, entId, zoneId):
  14. """create a distributed entity and call generate"""
  15. ent = AIclass(level, entId)
  16. ent.generateWithRequired(zoneId)
  17. return ent
  18. # this func creates local entities whose constructors take
  19. # (level, entId)
  20. def createLocalEntity(AIclass, level, entId, zoneId):
  21. """create a local entity"""
  22. ent = AIclass(level, entId)
  23. # take any number of args to support local and distributed entities
  24. def nothing(*args):
  25. """Create entity that doesn't have a server side representation."""
  26. return None
  27. class EntityCreatorAI(EntityCreatorBase.EntityCreatorBase):
  28. """This class is responsible for creating instances of Entities on the AI.
  29. It can be subclassed to handle more Entity types."""
  30. def __init__(self, level):
  31. EntityCreatorBase.EntityCreatorBase.__init__(self, level)
  32. # create short aliases for ctor funcs
  33. cLE = createLocalEntity
  34. self.privRegisterTypes({
  35. 'levelMgr': Functor(cLE, LevelMgrAI.LevelMgrAI),
  36. 'logicGate': Functor(cLE, LogicGateAI.LogicGateAI),
  37. 'nodepath': nothing,
  38. 'zone': Functor(cLE, ZoneEntityAI.ZoneEntityAI),
  39. })
  40. def doCreateEntity(self, ctor, entId):
  41. zoneId = self.level.getEntityZoneId(entId)
  42. self.notify.debug('creating entity %s in zone %s' % (entId, zoneId))
  43. return ctor(self.level, entId, zoneId)