def wcs_teleport_command(command_info, player:convert_userid_to_player, x:float, y:float, z:float): if player is None: return location = Vector(x, y, z) origin = player.origin angles = QAngle(*player.get_property_vector('m_angAbsRotation')) forward = Vector() right = Vector() up = Vector() angles.get_angle_vectors(forward, right, up) forward.normalize() forward *= 10 playerinfo = player.playerinfo mins, maxs = playerinfo.mins, playerinfo.maxs players = TraceFilterSimple(PlayerIter()) for _ in range(100): ray = Ray(location, location, mins, maxs) trace = GameTrace() engine_trace.trace_ray(ray, ContentMasks.PLAYER_SOLID, players, trace) if not trace.did_hit(): player.teleport(origin=location) break location -= forward if location.get_distance(origin) <= 10.0: break
def get_trace_ray(self, mask=ContentMasks.ALL, trace_filter=None): """Return the player's current trace data. :param ContentMasks mask: Will be passed to the trace filter. :param TraceFilter trace_filter: The trace filter to use. If ``None`` was given :class:`engines.trace.TraceFilterSimple` will be used. :rtype: GameTrace """ # Get the eye location of the player start_vec = self.eye_location # Calculate the greatest possible distance end_vec = start_vec + self.view_vector * MAX_TRACE_LENGTH # Create a new trace object trace = GameTrace() # Start the trace engine_trace.trace_ray( Ray(start_vec, end_vec), mask, TraceFilterSimple( (self, )) if trace_filter is None else trace_filter, trace) # Return the trace data return trace
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 check_space(position, mins, maxs): mask = ContentMasks.ALL generator = BaseEntityGenerator ray = Ray(position, position, mins, maxs) trace = GameTrace() engine_trace.trace_ray(ray, mask, TraceFilterSimple(generator()), trace) return trace
def _find_floor(self, origin): if origin is None: origin = self.origin end_trace_vec = origin + Vector(0, 0, -1) * MAX_TRACE_LENGTH trace = GameTrace() engine_trace.trace_ray(Ray(origin, end_trace_vec), ContentMasks.ALL, TraceFilterSimple(), trace) if not trace.did_hit(): return None return trace.end_position
def is_in_solid( self, mask=ContentMasks.ALL, generator=BaseEntityGenerator): """Return whether or not the entity is in solid.""" # Get a Ray object of the entity physic box ray = Ray(self.origin, self.origin, self.mins, self.maxs) # Get a new GameTrace instance trace = GameTrace() # Do the trace engine_trace.trace_ray(ray, mask, TraceFilterSimple( [entity.index for entity in generator()]), trace) # Return whether or not the trace did hit return trace.did_hit()
def is_player_stuck(player_index, origin): '''Return whether or not the given player is stuck in solid.''' # Get the player's PlayerInfo instance... player_info = playerinfo_from_index(player_index) # Get the player's origin... #origin = player_info.origin # Get a Ray object based on the player physic box... ray = Ray(origin, origin, player_info.mins, player_info.maxs) # Get a new GameTrace instance... trace = GameTrace() # Do the trace... engine_trace.trace_ray(ray, ContentMasks.PLAYER_SOLID, TraceFilterSimple(PlayerIter()), trace) # Return whether or not the trace did hit... return trace.did_hit()
def is_in_solid( self, mask=ContentMasks.ALL, generator=BaseEntityGenerator): """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 a Ray object of the entity physic box ray = Ray(self.origin, self.origin, self.mins, self.maxs) # Get a new GameTrace instance trace = GameTrace() # Do the trace engine_trace.trace_ray(ray, mask, TraceFilterSimple( generator()), trace) # Return whether or not the trace did hit return trace.did_hit()
def _tick(self): now = time() players = { wcsplayer: player.origin for player, wcsplayer in self._filter } for wcsplayer in list(players.keys()): if wcsplayer.player.dead: warn(f'Player "{wcsplayer.name}" should NOT be here') del players[wcsplayer] ignore = TraceFilterSimple(PlayerIter()) for ward in self.copy(): if ward._next_tick <= now: try: ward.on_tick() except: except_hooks.print_exception() try: ward.on_disappear() except: except_hooks.print_exception() self.remove(ward) continue else: ward._next_tick = now + ward.tick_interval ward.duration -= 1 if not ward.duration: try: ward.on_disappear() except: except_hooks.print_exception() self.remove(ward) entities = ward.entities team = ward.team_target for wcsplayer, origin in players.items(): if team is None or wcsplayer.player.team == team: trace = GameTrace() ray = Ray(ward.origin, origin) engine_trace.trace_ray(ray, ContentMasks.ALL, ignore, trace) if ward.has_within(origin) and not trace.did_hit_world(): if wcsplayer in entities: if entities[wcsplayer] <= now: entities[ wcsplayer] = now + ward.update_interval try: ward.on_update(wcsplayer) except: except_hooks.print_exception() else: entities[wcsplayer] = now + ward.update_interval try: ward.on_enter(wcsplayer) except: except_hooks.print_exception() else: if wcsplayer in entities: del entities[wcsplayer] try: ward.on_exit(wcsplayer) except: except_hooks.print_exception()
def _get_trace(self, start, end, mask, player, trace): engine_trace.trace_ray(Ray(start, end), ContentMasks.ALL, TraceFilterSimple((player, )), trace) return trace
class Turret(Prop): "Extensions of Prop, to add turret intelligence." # All intelligence, and damage management. tick_manager = on_tick_listener_manager last_fired = 0 delay = 2 ammunition = 200 damage = 50 def __init__(self, index): super(Prop, self).__init__(index) self.tick_manager.register_listener(self._tick) self.last_fired = time() def _tick(self): "Generic intelligence handling for turrets. Do not override!" # Check the turret firstly has ammunition. If not then stop. if self.ammunition == 0: return # Should the turret be able to fire? If not then just delay. next_fire = self.last_fired + self.delay if next_fire > time(): return # Try and find a local enemy, that we have vision on. If not then just delay again. enemy = self.get_closest_enemy() if not enemy: return # Cause the damage, and all changes to the turret. enemy.take_damage(self.damage, attacker_index=self.owner.index) self.last_fired = time() self.ammunition -= 1 # To be implemented. self.animate() # Storing trace masks and filters for checking obstructions. mask = ContentMasks.ALL trace_filter = TraceFilterSimple() def get_ray(self, vector): "Returns a game engine ray between the turrets aim and the target <Vector>." return Ray(self.origin, vector) def can_see_location(self, vector): "Checks to see if the turret can see the <Vector> provided." trace = GameTrace() engine_trace.trace_ray(self.get_ray(vector), self.mask, self.trace_filter, trace) return not trace.did_hit() def can_see_entity(self, entity): "Checks to see if the turret can see the <Entity> provided." return self.can_see_location(entity.origin) # Setting defaults for targetting enemies. target = "t" radius = 350 def get_surrounding_enemies(self): "Returns a list of all surrounding targets." return [ player for player in PlayerIter(self.target) if self.origin.get_distance(player.origin) <= self.radius and self.can_see_entity(player) ] def get_closest_enemy(self): "Returns the <Player> instance of the closest enemy." enemies = self.get_surrounding_enemies() if len(enemies) == 0: return None return sorted(enemies, key=lambda x: self.origin.get_distance(x.origin))[0] # Animation (TBC) def animate(self): "Not currently implemented."