Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description = "A high performance Python interface for communicating with RLBot
dynamic = ["version"]
requires-python = ">= 3.11"
dependencies = [
"rlbot_flatbuffers~=0.17.0",
"rlbot_flatbuffers~=0.18.2",
"psutil==7.*",
]
readme = "README.md"
Expand All @@ -26,7 +26,7 @@ version = {attr = "rlbot.version.__version__"}

[dependency-groups]
dev = [
"ruff>=0.12.5",
"ruff>=0.13.0",
"toml>=0.10.2",
]

Expand Down
9 changes: 4 additions & 5 deletions rlbot/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pathlib import Path
from socket import IPPROTO_TCP, TCP_NODELAY, socket
from threading import Thread
from typing import Optional

from rlbot import flat
from rlbot.utils.logging import get_logger
Expand Down Expand Up @@ -46,13 +45,13 @@ class SocketRelay:
Callable[[flat.ControllableTeamInfo], None]
] = []
rendering_status_handlers: list[Callable[[flat.RenderingStatus], None]] = []
raw_handlers: list[Callable[[flat.CoreMessage], None]] = []
raw_handlers: list[Callable[[flat.CorePacket], None]] = []

def __init__(
self,
agent_id: str,
connection_timeout: float = 120,
logger: Optional[logging.Logger] = None,
logger: logging.Logger | None = None,
):
self.agent_id = agent_id
self.connection_timeout = connection_timeout
Expand Down Expand Up @@ -272,12 +271,12 @@ def handle_incoming_message(self, incoming_message: bytes) -> MsgHandlingResult:
Returns True if the message was NOT a shutdown request
"""

flatbuffer = flat.CorePacket.unpack(incoming_message).message
flatbuffer = flat.CorePacket.unpack(incoming_message)

for raw_handler in self.raw_handlers:
raw_handler(flatbuffer)

match flatbuffer.item:
match flatbuffer.message:
case flat.DisconnectSignal():
return MsgHandlingResult.TERMINATED
case flat.GamePacket() as packet:
Expand Down
30 changes: 8 additions & 22 deletions rlbot/managers/bot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from traceback import print_exc
from typing import Optional

from rlbot import flat
from rlbot.interface import (
Expand All @@ -13,8 +12,6 @@
from rlbot.utils import fill_desired_game_state
from rlbot.utils.logging import DEFAULT_LOGGER, get_logger

WARNED_SPAWN_ID_DEPRECATED = False


class Bot:
"""
Expand All @@ -32,17 +29,6 @@ class Bot:
name: str = ""
player_id: int = 0

@property
def spawn_id(self) -> int:
global WARNED_SPAWN_ID_DEPRECATED
if not WARNED_SPAWN_ID_DEPRECATED:
WARNED_SPAWN_ID_DEPRECATED = True
self.logger.warning(
"'spawn_id' getter accessed, which is deprecated in favor of 'player_id'."
)

return self.player_id

match_config = flat.MatchConfiguration()
"""
Contains info about what map you're on, game mode, mutators, etc.
Expand All @@ -63,10 +49,10 @@ def spawn_id(self) -> int:
_has_field_info = False
_has_player_mapping = False

_latest_packet: Optional[flat.GamePacket] = None
_latest_packet: flat.GamePacket | None = None
_latest_prediction = flat.BallPrediction()

def __init__(self, default_agent_id: Optional[str] = None):
def __init__(self, default_agent_id: str | None = None):
agent_id = os.environ.get("RLBOT_AGENT_ID") or default_agent_id

if agent_id is None:
Expand Down Expand Up @@ -107,7 +93,7 @@ def _try_initialize(self):
return

for player in self.match_config.player_configurations:
match player.variety.item:
match player.variety:
case flat.CustomBot(name):
if player.player_id == self.player_id:
self.name = name
Expand Down Expand Up @@ -253,7 +239,7 @@ def rendering_status_update(self, update: flat.RenderingStatus):
def update_rendering_status(
self,
status: bool,
index: Optional[int] = None,
index: int | None = None,
is_bot: bool = True,
):
"""
Expand All @@ -274,7 +260,7 @@ def handle_match_comm(
index: int,
team: int,
content: bytes,
display: Optional[str],
display: str | None,
team_only: bool,
):
"""
Expand All @@ -284,7 +270,7 @@ def handle_match_comm(
"""

def send_match_comm(
self, content: bytes, display: Optional[str] = None, team_only: bool = False
self, content: bytes, display: str | None = None, team_only: bool = False
):
"""
Emits a match communication message to other bots and scripts.
Expand All @@ -307,7 +293,7 @@ def set_game_state(
self,
balls: dict[int, flat.DesiredBallState] = {},
cars: dict[int, flat.DesiredCarState] = {},
match_info: Optional[flat.DesiredMatchInfo] = None,
match_info: flat.DesiredMatchInfo | None = None,
commands: list[str] = [],
):
"""
Expand All @@ -319,7 +305,7 @@ def set_game_state(
game_state = fill_desired_game_state(balls, cars, match_info, commands)
self._game_interface.send_msg(game_state)

def set_loadout(self, loadout: flat.PlayerLoadout, index: Optional[int] = None):
def set_loadout(self, loadout: flat.PlayerLoadout, index: int | None = None):
"""
Sets the loadout of a bot.
Can be used to select or generate a loadout for the match when called inside `initialize`.
Expand Down
28 changes: 7 additions & 21 deletions rlbot/managers/hivemind.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from logging import Logger
from traceback import print_exc
from typing import Optional

from rlbot import flat
from rlbot.interface import (
Expand All @@ -14,8 +13,6 @@
from rlbot.utils import fill_desired_game_state
from rlbot.utils.logging import DEFAULT_LOGGER, get_logger

WARNED_SPAWN_ID_DEPRECATED = False


class Hivemind:
"""
Expand All @@ -34,17 +31,6 @@ class Hivemind:
names: list[str] = []
player_ids: list[int] = []

@property
def spawn_ids(self) -> list[int]:
global WARNED_SPAWN_ID_DEPRECATED
if not WARNED_SPAWN_ID_DEPRECATED:
WARNED_SPAWN_ID_DEPRECATED = True
self._logger.warning(
"'spawn_id' getter accessed, which is deprecated in favor of 'player_id'."
)

return self.player_ids

match_config = flat.MatchConfiguration()
"""
Contains info about what map you're on, game mode, mutators, etc.
Expand All @@ -65,10 +51,10 @@ def spawn_ids(self) -> list[int]:
_has_field_info = False
_has_player_mapping = False

_latest_packet: Optional[flat.GamePacket] = None
_latest_packet: flat.GamePacket | None = None
_latest_prediction = flat.BallPrediction()

def __init__(self, default_agent_id: Optional[str] = None):
def __init__(self, default_agent_id: str | None = None):
agent_id = os.environ.get("RLBOT_AGENT_ID") or default_agent_id

if agent_id is None:
Expand Down Expand Up @@ -110,7 +96,7 @@ def _try_initialize(self):
# 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:
match player.variety:
case flat.CustomBot(name):
if player.player_id == player_id:
self.names.append(name)
Expand Down Expand Up @@ -251,7 +237,7 @@ def rendering_status_update(self, update: flat.RenderingStatus):
def update_rendering_status(
self,
status: bool,
index: Optional[int] = None,
index: int | None = None,
is_bot: bool = True,
):
"""
Expand Down Expand Up @@ -283,7 +269,7 @@ def handle_match_comm(
index: int,
team: int,
content: bytes,
display: Optional[str],
display: str | None,
team_only: bool,
):
"""
Expand All @@ -296,7 +282,7 @@ def send_match_comm(
self,
index: int,
content: bytes,
display: Optional[str] = None,
display: str | None = None,
team_only: bool = False,
):
"""
Expand All @@ -320,7 +306,7 @@ def set_game_state(
self,
balls: dict[int, flat.DesiredBallState] = {},
cars: dict[int, flat.DesiredCarState] = {},
match_info: Optional[flat.DesiredMatchInfo] = None,
match_info: flat.DesiredMatchInfo | None = None,
commands: list[str] = [],
):
"""
Expand Down
13 changes: 6 additions & 7 deletions rlbot/managers/match.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pathlib import Path
from time import sleep
from typing import Optional

import psutil

Expand All @@ -17,14 +16,14 @@ class MatchManager:
"""

logger = DEFAULT_LOGGER
packet: Optional[flat.GamePacket] = None
rlbot_server_process: Optional[psutil.Process] = None
packet: flat.GamePacket | None = None
rlbot_server_process: psutil.Process | None = None
rlbot_server_port = RLBOT_SERVER_PORT
initialized = False

def __init__(
self,
main_executable_path: Optional[Path] = None,
main_executable_path: Path | None = None,
main_executable_name: str = MAIN_EXECUTABLE_NAME,
):
self.main_executable_path = main_executable_path
Expand Down Expand Up @@ -76,7 +75,7 @@ def connect(
wants_ball_predictions: bool,
close_between_matches: bool = True,
rlbot_server_ip: str = RLBOT_SERVER_IP,
rlbot_server_port: Optional[int] = None,
rlbot_server_port: int | None = None,
):
"""
Connects to the RLBot server specifying the given settings.
Expand Down Expand Up @@ -109,7 +108,7 @@ def connect_and_run(
wants_ball_predictions: bool,
close_between_matches: bool = True,
rlbot_server_ip: str = RLBOT_SERVER_IP,
rlbot_server_port: Optional[int] = None,
rlbot_server_port: int | None = None,
background_thread: bool = False,
):
"""
Expand Down Expand Up @@ -184,7 +183,7 @@ def set_game_state(
self,
balls: dict[int, flat.DesiredBallState] = {},
cars: dict[int, flat.DesiredCarState] = {},
match_info: Optional[flat.DesiredMatchInfo] = None,
match_info: flat.DesiredMatchInfo | None = None,
commands: list[str] = [],
):
"""
Expand Down
3 changes: 1 addition & 2 deletions rlbot/managers/rendering.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import math
from collections.abc import Callable, Sequence
from contextlib import contextmanager
from typing import Optional

from rlbot import flat
from rlbot.interface import SocketRelay
Expand Down Expand Up @@ -51,7 +50,7 @@ class Renderer:
_logger = get_logger("renderer")

_used_group_ids: set[int] = set()
_group_id: Optional[int] = None
_group_id: int | None = None
_current_renders: list[flat.RenderMessage] = []

_default_color = white
Expand Down
13 changes: 6 additions & 7 deletions rlbot/managers/script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from traceback import print_exc
from typing import Optional

from rlbot import flat
from rlbot.interface import (
Expand Down Expand Up @@ -35,10 +34,10 @@ class Script:
_has_match_settings = False
_has_field_info = False

_latest_packet: Optional[flat.GamePacket] = None
_latest_packet: flat.GamePacket | None = None
_latest_prediction = flat.BallPrediction()

def __init__(self, default_agent_id: Optional[str] = None):
def __init__(self, default_agent_id: str | None = None):
agent_id = os.environ.get("RLBOT_AGENT_ID") or default_agent_id

if agent_id is None:
Expand Down Expand Up @@ -200,7 +199,7 @@ def rendering_status_update(self, update: flat.RenderingStatus):
def update_rendering_status(
self,
status: bool,
index: Optional[int] = None,
index: int | None = None,
is_bot: bool = False,
):
"""
Expand All @@ -221,7 +220,7 @@ def handle_match_comm(
index: int,
team: int,
content: bytes,
display: Optional[str],
display: str | None,
team_only: bool,
):
"""
Expand All @@ -231,7 +230,7 @@ def handle_match_comm(
"""

def send_match_comm(
self, content: bytes, display: Optional[str] = None, team_only: bool = False
self, content: bytes, display: str | None = None, team_only: bool = False
):
"""
Emits a match communication message to other bots and scripts.
Expand All @@ -254,7 +253,7 @@ def set_game_state(
self,
balls: dict[int, flat.DesiredBallState] = {},
cars: dict[int, flat.DesiredCarState] = {},
match_info: Optional[flat.DesiredMatchInfo] = None,
match_info: flat.DesiredMatchInfo | None = None,
commands: list[str] = [],
):
"""
Expand Down
4 changes: 1 addition & 3 deletions rlbot/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from typing import Optional

from rlbot import flat


def fill_desired_game_state(
balls: dict[int, flat.DesiredBallState] = {},
cars: dict[int, flat.DesiredCarState] = {},
match_info: Optional[flat.DesiredMatchInfo] = None,
match_info: flat.DesiredMatchInfo | None = None,
commands: list[str] = [],
) -> flat.DesiredGameState:
"""
Expand Down
Loading