Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions rlbot/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def start_match(self, match_config: Path | flat.MatchConfiguration):
flatbuffer = settings
case _:
raise ValueError(
"Expected MatchSettings or path to match settings toml file"
"Expected MatchConfiguration or path to match config toml file"
)

self.send_msg(flatbuffer)
Expand Down Expand Up @@ -243,32 +243,33 @@ def handle_incoming_messages(self, blocking: bool = False) -> MsgHandlingResult:
try:
self.socket.setblocking(blocking)
incoming_message = self.read_message()
try:
return self.handle_incoming_message(incoming_message)
except flat.InvalidFlatbuffer as e:
self.logger.error(
"Error while unpacking message (%s bytes): %s",
len(incoming_message),
e,
)
return MsgHandlingResult.TERMINATED
except Exception as e:
self.logger.error(
"Unexpected error while handling message of type: %s",
e,
)
return MsgHandlingResult.TERMINATED
except BlockingIOError:
# No incoming messages and blocking==False
return MsgHandlingResult.NO_INCOMING_MSGS
except:
self.logger.error("SocketRelay disconnected unexpectedly!")
return MsgHandlingResult.TERMINATED

try:
return self.handle_incoming_message(incoming_message)
except flat.InvalidFlatbuffer as e:
self.logger.error(
"Error while unpacking message (%s bytes): %s",
len(incoming_message),
e,
)
return MsgHandlingResult.TERMINATED
except Exception as e:
self.logger.error(
"Unexpected error while handling message of type: %s",
e,
)
return MsgHandlingResult.TERMINATED

def handle_incoming_message(self, incoming_message: bytes) -> MsgHandlingResult:
"""
Handles a messages by passing it to the relevant handlers.
Returns True if the message was NOT a shutdown request (i.e. NONE).
Returns True if the message was NOT a shutdown request
"""

flatbuffer = flat.CorePacket.unpack(incoming_message).message
Expand Down
33 changes: 16 additions & 17 deletions rlbot/managers/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ def _try_initialize(self):
# Not ready to initialize
return

for player in self.match_config.player_configurations:
match player.variety.item:
case flat.CustomBot(name):
if player.player_id == self.player_id:
self.name = name
self.logger = get_logger(self.name)
break
else: # else block runs if break was not hit
self.logger.warning(
"Bot with agent id '%s' did not find itself in the match configuration",
self._game_interface.agent_id,
)

try:
self.initialize()
except Exception as e:
Expand All @@ -125,20 +138,6 @@ def _handle_match_config(self, match_config: flat.MatchConfiguration):
match_config.enable_rendering == flat.DebugRendering.OnByDefault
)

# Search match settings for our name
for player in self.match_config.player_configurations:
match player.variety.item:
case flat.CustomBot(name):
if player.player_id == self.player_id:
self.name = name
self.logger = get_logger(self.name)
break
else: # else block runs if break was not hit
self.logger.warning(
"Bot with agent id '%s' did not find itself in the match settings",
self._game_interface.agent_id,
)

self._try_initialize()

def _handle_field_info(self, field_info: flat.FieldInfo):
Expand Down Expand Up @@ -259,7 +258,7 @@ def update_rendering_status(
):
"""
Requests the server to update the status of the ability for this bot to render.
Will be ignored if rendering has been set to AlwaysOff in the match settings.
Will be ignored if rendering has been set to AlwaysOff in the match configuration.
If the status is successfully updated, the `self.rendering_status_update` method will be called which will update `self.renderer.can_render`.

- `status`: `True` to enable rendering, `False` to disable.
Expand All @@ -281,7 +280,7 @@ def handle_match_comm(
"""
Called when a match communication message is received.
See `send_match_comm`.
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match settings.
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match configuration.
"""

def send_match_comm(
Expand Down Expand Up @@ -331,7 +330,7 @@ def set_loadout(self, loadout: flat.PlayerLoadout, index: Optional[int] = None):

def initialize(self):
"""
Called when the bot is ready for initialization. Field info, match settings, name, index, and team are
Called when the bot is ready for initialization. Field info, match configuration, name, index, and team are
fully loaded at this point, and will not return garbage data unlike in `__init__`.
"""

Expand Down
32 changes: 19 additions & 13 deletions rlbot/managers/hivemind.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ def _try_initialize(self):
):
return

# Search match configuration for our spawn ids
for player_id in self.player_ids:
for player in self.match_config.player_configurations:
match player.variety.item:
case flat.CustomBot(name):
if player.player_id == player_id:
self.names.append(name)
self.loggers.append(get_logger(name))
break
else: # else block runs if break was not hit
self._logger.warning(
"Hivemind with agent id '%s' did not find itself in the match configuration for player id %s",
self._game_interface.agent_id,
player_id,
)

try:
self.initialize()
except Exception as e:
Expand All @@ -125,16 +141,6 @@ def _handle_match_config(self, match_config: flat.MatchConfiguration):
self.match_config = match_config
self._has_match_settings = True

# Search match settings for our spawn ids
for player_id in self.player_ids:
for player in self.match_config.player_configurations:
match player.variety.item:
case flat.CustomBot(name):
if player.player_id == player_id:
self.names.append(name)
self.loggers.append(get_logger(name))
break

self._try_initialize()

def _handle_field_info(self, field_info: flat.FieldInfo):
Expand Down Expand Up @@ -250,7 +256,7 @@ def update_rendering_status(
):
"""
Requests the server to update the status of the ability for this bot to render.
Will be ignored if rendering has been set to AlwaysOff in the match settings.
Will be ignored if rendering has been set to AlwaysOff in the match configuration.
If the status is successfully updated, the `self.rendering_status_update` method will be called which will update `self.renderer.can_render`.

- `status`: `True` to enable rendering, `False` to disable.
Expand Down Expand Up @@ -283,7 +289,7 @@ def handle_match_comm(
"""
Called when a match communication message is received.
See `send_match_comm`.
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match settings.
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match configuration.
"""

def send_match_comm(
Expand Down Expand Up @@ -337,7 +343,7 @@ def set_loadout(self, loadout: flat.PlayerLoadout, index: int):

def initialize(self):
"""
Called when the bot is ready for initialization. Field info, match settings, name, index, and team are
Called when the bot is ready for initialization. Field info, match configuration, name, index, and team are
fully loaded at this point, and will not return garbage data unlike in `__init__`.
"""

Expand Down
2 changes: 1 addition & 1 deletion rlbot/managers/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def start_match(
ensure_server_started: bool = True,
):
"""
Starts a match using the given match settings or a path to a match settings toml file.
Starts a match using the given match configuration or a path to a match config toml file.
Connection is automatically established if missing. Call `connect` if you
want this process to receive match communication or ball prediction messages.
"""
Expand Down
28 changes: 14 additions & 14 deletions rlbot/managers/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ def _try_initialize(self):

self.logger = get_logger(self.name)

for i, script in enumerate(self.match_config.script_configurations):
if script.agent_id == self._game_interface.agent_id:
self.index = i
self.name = script.name
break
else: # else block runs if break was not hit
self.logger.warning(
"Script with agent id '%s' did not find itself in the match configuration",
self._game_interface.agent_id,
)

try:
self.initialize()
except Exception as e:
Expand All @@ -96,17 +107,6 @@ def _handle_match_config(self, match_config: flat.MatchConfiguration):
match_config.enable_rendering == flat.DebugRendering.OnByDefault
)

for i, script in enumerate(match_config.script_configurations):
if script.agent_id == self._game_interface.agent_id:
self.index = i
self.name = script.name
break
else: # else block runs if break was not hit
self.logger.warning(
"Script with agent id '%s' did not find itself in the match settings",
self._game_interface.agent_id,
)

self._try_initialize()

def _handle_field_info(self, field_info: flat.FieldInfo):
Expand Down Expand Up @@ -205,7 +205,7 @@ def update_rendering_status(
):
"""
Requests the server to update the status of the ability for this bot to render.
Will be ignored if rendering has been set to AlwaysOff in the match settings.
Will be ignored if rendering has been set to AlwaysOff in the match configuration.
If the status is successfully updated, the `self.rendering_status_update` method will be called which will update `self.renderer.can_render`.

- `status`: `True` to enable rendering, `False` to disable.
Expand All @@ -227,7 +227,7 @@ def handle_match_comm(
"""
Called when a match communication message is received.
See `send_match_comm`.
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match settings.
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match configuration.
"""

def send_match_comm(
Expand Down Expand Up @@ -276,7 +276,7 @@ def set_loadout(self, loadout: flat.PlayerLoadout, index: int):

def initialize(self):
"""
Called when the script is ready for initialization. Field info, match settings, name, and index are
Called when the script is ready for initialization. Field info, match configuration, name, and index are
fully loaded at this point, and will not return garbage data unlike in `__init__`.
"""

Expand Down
3 changes: 2 additions & 1 deletion rlbot/utils/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"EstadioVida_Dusk": "ff_dusk_p",
"Mannfield_Dusk": "eurostadium_dusk_p",
"Farmstead_Pitched": "farm_grs_p",
"Farmstead_Upsidedown": "farm_hw_p",
"Wasteland_Pitched": "wasteland_grs_p",
"Neotokyo_Hacked": "neotokyo_hax_p",
"AquaDome_Shallows": "Underwater_GRS_P",
Expand All @@ -84,6 +83,7 @@
"FuturaGarden": "UF_Day_P",
"DFHStadium_Anniversary": "stadium_10a_p",
"Holyfield": "Labs_Holyfield_Space_P",
"DriftWoods_Night": "woods_night_p"
}

STANDARD_MAPS = [
Expand Down Expand Up @@ -138,4 +138,5 @@
"Neotokyo_Arcade",
"FuturaGarden",
"DFHStadium_Anniversary",
"DriftWoods_Night"
]
2 changes: 1 addition & 1 deletion rlbot/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.0-beta.46"
__version__ = "2.0.0-beta.47"
2 changes: 0 additions & 2 deletions tests/render_test/render.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from email.policy import default

from rlbot import flat
from rlbot.flat import BallAnchor, CarAnchor, Color, RenderAnchor, Vector3
from rlbot.managers import Script
Expand Down