The roles system
The SpaceObject class has methods for assigning and removing 'roles' to objects.
Roles are like sides but can be more dynamic and are not seen by the simulation. You can have multiple roles on an object. Roles can be used in targeting etc.
** This need more documentation** placing examples for now
Adding a role
add_role(some_id, 'spy')
Remove a role
remove_role(some_id, 'spy')
Check for a role
if has_role(some_id, 'spy')
pass
Using with targeting
close = closest(some_id, role("spy"))
# class names are included in roles
close = closest(some_id, role("station"))
# side is included in roles
close = closest(some_id, role("tsn"))
API: Roles
add_role(set_holder, role)
add a role to a set of agents
Parameters:
Name | Type | Description | Default |
---|---|---|---|
set_holder
|
agent set
|
a set of IDs or |
required |
role
|
str
|
The role to add |
required |
all_roles(roles)
returns a set of all the agents with a given role.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
roles
|
str
|
The roles comma separated |
required |
Returns:
Type | Description |
---|---|
agent id set: a set of agent IDs |
any_role(roles)
returns a set of all the agents with a any of the given roles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
role
|
str
|
The role |
required |
Returns:
Type | Description |
---|---|
agent id set: a set of agent IDs |
get_race(id_or_obj)
get the race of the specified agent
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_or_obj
|
agent
|
an agent id or object |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
The race of the object or None |
has_role(so, role)
check if an agent has a role
Parameters:
Name | Type | Description | Default |
---|---|---|---|
so
|
an agent
|
an agent id or object |
required |
role
|
str
|
the role to test for |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
if the agent has that role |
has_roles(so, roles)
check if an agent has all the roles specified
Parameters:
Name | Type | Description | Default |
---|---|---|---|
so
|
an agent
|
an agent id or object |
required |
role
|
str
|
a string comma separated roles |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
if the agent has that role |
remove_role(agents, role)
remove a role from a set of agents
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agents
|
agent set
|
a set of IDs or |
required |
role
|
str
|
The role to add |
required |
role(role)
returns a set of all the agents with a given role.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
role
|
str
|
The role |
required |
Returns:
Type | Description |
---|---|
agent id set: a set of agent IDs |