def __init__(self, index, caching=True): """Initialize the Entity instance. :param int index: The entity index to wrap. :param bool caching: Whether to lookup the cache for an existing instance or not. """ # Initialize the object BaseEntity.__init__(self, index) Pointer.__init__(self, self.pointer) # Set the entity's base attributes type(self).index.set_cached_value(self, index)
def is_in_solid( self, mask=ContentMasks.ALL, generator=None): """Return whether or not the entity is in solid. :param ContentMasks mask: Contents the ray can possibly collide with. :param generator: A callable that returns an iterable which contains :class:`BaseEntity` instances that are ignored by the ray. :rtype: bool """ # Get the entity's origin origin = self.origin # Get a Ray object of the entity physic box ray = Ray(origin, origin, self.mins, self.maxs) # Get a new GameTrace instance trace = GameTrace() # Do the trace if generator is None: # No need to trace against anything but the world if we are going # to filter out everything regardless. engine_trace.clip_ray_to_entity( ray, mask, BaseEntity(WORLD_ENTITY_INDEX), trace ) else: engine_trace.trace_ray(ray, mask, TraceFilterSimple( generator()), trace) # Return whether or not the trace did hit return trace.did_hit()
def create(cls, classname): """Create a new networked entity with the given classname.""" entity = BaseEntity.create(classname) if entity.is_networked(): return cls(entity.index) entity.remove() raise ValueError('"{}" is not a networked entity.'.format(classname))
def find(cls, classname): """Try to find an entity with the given classname. If not entity has been found, None will be returned. :param str classname: The classname of the entity. :return: Return the found entity. :rtype: Entity """ entity = BaseEntity.find(classname) if entity is not None and entity.is_networked(): return cls(entity.index) return None
def create(cls, classname): """Create a new networked entity with the given classname. :param str classname: Classname of the entity to create. :raise ValueError: Raised if the given classname is not a networked entity. """ entity = BaseEntity.create(classname) if entity.is_networked(): return cls(entity.index) entity.remove() raise ValueError('"{}" is not a networked entity.'.format(classname))
def __new__(cls, index): """Verify the given index is valid and store base attributes.""" # Get the given indexes edict edict = edict_from_index(index, False) # Is the edict valid? if edict is None or edict.get_unknown() is None: # If not raise an error raise ValueError( 'Index "{0}" is not a proper entity index.'.format(index)) # Create the object self = BaseEntity.__new__(cls) # Set the entity's base attributes self._index = index self._edict = edict self._pointer = pointer_from_edict(edict) # Return the instance return self