entities.collisions module

Provides entity collisions functionality.

class entities.collisions.BaseCollisionRules

Bases: core.WeakAutoUnload, Boost.Python.instance

__init__()

Raises an exception This class cannot be instantiated from Python

should_collide((BaseCollisionRules)self, (BaseEntity)entity, (BaseEntity)other) → bool :

Returns whether the given entities should collide with each other.

Return type:bool
mode

Returns the collision mode for these rules.

Return type:CollisionMode
solid_only

Returns whether these rules affect solid contents only.

Return type:bool
class entities.collisions.CollisionHash

Bases: _entities._collisions.BaseCollisionRules

Collision rules where contained pairs never collide with each other.

Example:

from entities.collisions import CollisionHash
from events import Event
from players.entity import Player

h = CollisionHash()

@Event('player_say')
def player_say(game_event):
    player = Player.from_userid(game_event['userid'])
    entity = player.view_entity
    if entity is None:
        return
    # Toggle collisions with aimed entity
    if h.has_pair(player, entity):
        h.remove_pair(player, entity)
    else:
        h.add_pair(player, entity)
__init__((object)arg1[, (CollisionMode)mode=_entities._collisions.CollisionMode.PREVENT[, (bool)solid_only=True]]) → object :

Constructs and initializes the collision hash.

Parameters:
  • mode (CollisionMode) – The collision mode for these rules.
  • solid_only (bool) – Whether these rules should affect solid contents only.
add_pair((CollisionHash)self, (BaseEntity)entity, (BaseEntity)other) → None :

Adds the given entity pair to the hash.

Raises:ValueError – If any of the given entities is not networked.
clear((CollisionHash)self) → None :

Removes all entities from the hash.

get_count((CollisionHash)self, (BaseEntity)entity) → int :

Returns the amount of pairs associated with the given entity.

Return type:int
get_pairs((CollisionHash)self, (BaseEntity)entity) → list :

Returns a list of all entities associated with the given entity.

Return type:list
has_pair((CollisionHash)self, (BaseEntity)entity, (BaseEntity)other) → bool :

Returns whether the given pair is in the hash.

Return type:bool
remove_pair((CollisionHash)self, (BaseEntity)entity, (BaseEntity)other) → None :

Removes the given pair from the hash.

remove_pairs((CollisionHash)self, (BaseEntity)entity) → None :

Removes all pairs associated with the given entity.

class entities.collisions.CollisionHook(callback)[source]

Bases: core.AutoUnload

Decorator used to create collision hooks that auto unload.

Example:

from engines.trace import ContentFlags
from entities.collisions import CollisionHook

@CollisionHook
def collision_hook(entity, other, trace_filter, mask):
    # Prevent hostages from being killed by bullets
    if not mask & ContentFlags.HITBOX:
        return
    return other.classname != 'hostage_entity'
__init__(callback)[source]

Registers the collision hook.

Parameters:callback (function) – Function to register as a collision hook callback.
class entities.collisions.CollisionManager

Bases: Boost.Python.instance

__init__()

Raises an exception This class cannot be instantiated from Python

register_hook((CollisionManager)self, (object)callback) → None :

Registers a collision hook.

Parameters:callback (function) – Function to register as a collision hook callback.
Raises:ValueError – If the given callback is already registered.
unregister_hook((CollisionManager)self, (object)callback) → None :

Unregisters a collision hook.

Parameters:callback (function) – Function to unregister as a collision hook callback.
Raises:ValueError – If the given callback was not registered.
solid_masks

Returns a list containing the masks that are currently considered solid.

Return type:list
class entities.collisions.CollisionMap

Bases: _entities._collisions.BaseCollisionRules

Collision rules that overrides one-way collisions.

Example:

from entities.collisions import CollisionMap
from events import Event
from players.entity import Player

m = CollisionMap()

@Event('player_say')
def player_say(game_event):
    player = Player.from_userid(game_event['userid'])
    entity = player.view_entity
    if entity is None:
        return
    # Toggle one-way collisions with aimed entity
    s = m[player]
    if entity in s:
        s.remove(entity)
    else:
        s.add(entity)
__init__((object)arg1[, (CollisionMode)mode=_entities._collisions.CollisionMode.PREVENT[, (bool)solid_only=True]]) → object :

Constructs and initializes the collision map.

Parameters:
  • mode (CollisionMode) – The collision mode for these rules.
  • solid_only (bool) – Whether these rules should affect solid contents only.
clear((CollisionMap)self) → None :

Removes all entities from the map.

class entities.collisions.CollisionMode

Bases: Boost.Python.enum

ALLOW = _entities._collisions.CollisionMode.ALLOW
PREVENT = _entities._collisions.CollisionMode.PREVENT
names = {'ALLOW': _entities._collisions.CollisionMode.ALLOW, 'PREVENT': _entities._collisions.CollisionMode.PREVENT}
values = {0: _entities._collisions.CollisionMode.ALLOW, 1: _entities._collisions.CollisionMode.PREVENT}
class entities.collisions.CollisionSet

Bases: _entities._collisions.BaseCollisionRules

Collision rules where contained entities never collide with anything.

Example:

from entities.collisions import CollisionSet
from events import Event
from players.entity import Player

s = CollisionSet()

@Event('player_say')
def player_say(game_event):
    player = Player.from_userid(game_event['userid'])
    # Toggle collisions with everything
    if player in s:
        s.remove(player)
    else:
        s.add(player)
__init__((object)arg1[, (CollisionMode)mode=_entities._collisions.CollisionMode.PREVENT[, (bool)solid_only=True]]) → object :

Constructs and initializes the collision set.

Parameters:
  • mode (CollisionMode) – The collision mode for these rules.
  • solid_only (bool) – Whether these rules should affect solid contents only.
add((CollisionSet)self, (BaseEntity)entity) → None :

Adds the given entity to the set.

Raises:ValueError – If the given entity is not networked.
clear((CollisionSet)self) → None :

Removes all entities from the set.

remove((CollisionSet)self, (BaseEntity)entity) → None :

Removes the given entity from the set.