Skip to content

Commit 892b715

Browse files
Merge pull request #33 from RLBot/mc-fix
Fix match config bug
2 parents cd87e1c + be40669 commit 892b715

File tree

8 files changed

+71
-66
lines changed

8 files changed

+71
-66
lines changed

rlbot/interface.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def start_match(self, match_config: Path | flat.MatchConfiguration):
134134
flatbuffer = settings
135135
case _:
136136
raise ValueError(
137-
"Expected MatchSettings or path to match settings toml file"
137+
"Expected MatchConfiguration or path to match config toml file"
138138
)
139139

140140
self.send_msg(flatbuffer)
@@ -243,32 +243,33 @@ def handle_incoming_messages(self, blocking: bool = False) -> MsgHandlingResult:
243243
try:
244244
self.socket.setblocking(blocking)
245245
incoming_message = self.read_message()
246-
try:
247-
return self.handle_incoming_message(incoming_message)
248-
except flat.InvalidFlatbuffer as e:
249-
self.logger.error(
250-
"Error while unpacking message (%s bytes): %s",
251-
len(incoming_message),
252-
e,
253-
)
254-
return MsgHandlingResult.TERMINATED
255-
except Exception as e:
256-
self.logger.error(
257-
"Unexpected error while handling message of type: %s",
258-
e,
259-
)
260-
return MsgHandlingResult.TERMINATED
261246
except BlockingIOError:
262247
# No incoming messages and blocking==False
263248
return MsgHandlingResult.NO_INCOMING_MSGS
264249
except:
265250
self.logger.error("SocketRelay disconnected unexpectedly!")
266251
return MsgHandlingResult.TERMINATED
267252

253+
try:
254+
return self.handle_incoming_message(incoming_message)
255+
except flat.InvalidFlatbuffer as e:
256+
self.logger.error(
257+
"Error while unpacking message (%s bytes): %s",
258+
len(incoming_message),
259+
e,
260+
)
261+
return MsgHandlingResult.TERMINATED
262+
except Exception as e:
263+
self.logger.error(
264+
"Unexpected error while handling message of type: %s",
265+
e,
266+
)
267+
return MsgHandlingResult.TERMINATED
268+
268269
def handle_incoming_message(self, incoming_message: bytes) -> MsgHandlingResult:
269270
"""
270271
Handles a messages by passing it to the relevant handlers.
271-
Returns True if the message was NOT a shutdown request (i.e. NONE).
272+
Returns True if the message was NOT a shutdown request
272273
"""
273274

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

rlbot/managers/bot.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ def _try_initialize(self):
106106
# Not ready to initialize
107107
return
108108

109+
for player in self.match_config.player_configurations:
110+
match player.variety.item:
111+
case flat.CustomBot(name):
112+
if player.player_id == self.player_id:
113+
self.name = name
114+
self.logger = get_logger(self.name)
115+
break
116+
else: # else block runs if break was not hit
117+
self.logger.warning(
118+
"Bot with agent id '%s' did not find itself in the match configuration",
119+
self._game_interface.agent_id,
120+
)
121+
109122
try:
110123
self.initialize()
111124
except Exception as e:
@@ -125,20 +138,6 @@ def _handle_match_config(self, match_config: flat.MatchConfiguration):
125138
match_config.enable_rendering == flat.DebugRendering.OnByDefault
126139
)
127140

128-
# Search match settings for our name
129-
for player in self.match_config.player_configurations:
130-
match player.variety.item:
131-
case flat.CustomBot(name):
132-
if player.player_id == self.player_id:
133-
self.name = name
134-
self.logger = get_logger(self.name)
135-
break
136-
else: # else block runs if break was not hit
137-
self.logger.warning(
138-
"Bot with agent id '%s' did not find itself in the match settings",
139-
self._game_interface.agent_id,
140-
)
141-
142141
self._try_initialize()
143142

144143
def _handle_field_info(self, field_info: flat.FieldInfo):
@@ -259,7 +258,7 @@ def update_rendering_status(
259258
):
260259
"""
261260
Requests the server to update the status of the ability for this bot to render.
262-
Will be ignored if rendering has been set to AlwaysOff in the match settings.
261+
Will be ignored if rendering has been set to AlwaysOff in the match configuration.
263262
If the status is successfully updated, the `self.rendering_status_update` method will be called which will update `self.renderer.can_render`.
264263
265264
- `status`: `True` to enable rendering, `False` to disable.
@@ -281,7 +280,7 @@ def handle_match_comm(
281280
"""
282281
Called when a match communication message is received.
283282
See `send_match_comm`.
284-
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match settings.
283+
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match configuration.
285284
"""
286285

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

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

rlbot/managers/hivemind.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ def _try_initialize(self):
107107
):
108108
return
109109

110+
# Search match configuration for our spawn ids
111+
for player_id in self.player_ids:
112+
for player in self.match_config.player_configurations:
113+
match player.variety.item:
114+
case flat.CustomBot(name):
115+
if player.player_id == player_id:
116+
self.names.append(name)
117+
self.loggers.append(get_logger(name))
118+
break
119+
else: # else block runs if break was not hit
120+
self._logger.warning(
121+
"Hivemind with agent id '%s' did not find itself in the match configuration for player id %s",
122+
self._game_interface.agent_id,
123+
player_id,
124+
)
125+
110126
try:
111127
self.initialize()
112128
except Exception as e:
@@ -125,16 +141,6 @@ def _handle_match_config(self, match_config: flat.MatchConfiguration):
125141
self.match_config = match_config
126142
self._has_match_settings = True
127143

128-
# Search match settings for our spawn ids
129-
for player_id in self.player_ids:
130-
for player in self.match_config.player_configurations:
131-
match player.variety.item:
132-
case flat.CustomBot(name):
133-
if player.player_id == player_id:
134-
self.names.append(name)
135-
self.loggers.append(get_logger(name))
136-
break
137-
138144
self._try_initialize()
139145

140146
def _handle_field_info(self, field_info: flat.FieldInfo):
@@ -250,7 +256,7 @@ def update_rendering_status(
250256
):
251257
"""
252258
Requests the server to update the status of the ability for this bot to render.
253-
Will be ignored if rendering has been set to AlwaysOff in the match settings.
259+
Will be ignored if rendering has been set to AlwaysOff in the match configuration.
254260
If the status is successfully updated, the `self.rendering_status_update` method will be called which will update `self.renderer.can_render`.
255261
256262
- `status`: `True` to enable rendering, `False` to disable.
@@ -283,7 +289,7 @@ def handle_match_comm(
283289
"""
284290
Called when a match communication message is received.
285291
See `send_match_comm`.
286-
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match settings.
292+
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match configuration.
287293
"""
288294

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

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

rlbot/managers/match.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def start_match(
108108
ensure_server_started: bool = True,
109109
):
110110
"""
111-
Starts a match using the given match settings or a path to a match settings toml file.
111+
Starts a match using the given match configuration or a path to a match config toml file.
112112
Connection is automatically established if missing. Call `connect` if you
113113
want this process to receive match communication or ball prediction messages.
114114
"""

rlbot/managers/script.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ def _try_initialize(self):
7575

7676
self.logger = get_logger(self.name)
7777

78+
for i, script in enumerate(self.match_config.script_configurations):
79+
if script.agent_id == self._game_interface.agent_id:
80+
self.index = i
81+
self.name = script.name
82+
break
83+
else: # else block runs if break was not hit
84+
self.logger.warning(
85+
"Script with agent id '%s' did not find itself in the match configuration",
86+
self._game_interface.agent_id,
87+
)
88+
7889
try:
7990
self.initialize()
8091
except Exception as e:
@@ -96,17 +107,6 @@ def _handle_match_config(self, match_config: flat.MatchConfiguration):
96107
match_config.enable_rendering == flat.DebugRendering.OnByDefault
97108
)
98109

99-
for i, script in enumerate(match_config.script_configurations):
100-
if script.agent_id == self._game_interface.agent_id:
101-
self.index = i
102-
self.name = script.name
103-
break
104-
else: # else block runs if break was not hit
105-
self.logger.warning(
106-
"Script with agent id '%s' did not find itself in the match settings",
107-
self._game_interface.agent_id,
108-
)
109-
110110
self._try_initialize()
111111

112112
def _handle_field_info(self, field_info: flat.FieldInfo):
@@ -205,7 +205,7 @@ def update_rendering_status(
205205
):
206206
"""
207207
Requests the server to update the status of the ability for this bot to render.
208-
Will be ignored if rendering has been set to AlwaysOff in the match settings.
208+
Will be ignored if rendering has been set to AlwaysOff in the match configuration.
209209
If the status is successfully updated, the `self.rendering_status_update` method will be called which will update `self.renderer.can_render`.
210210
211211
- `status`: `True` to enable rendering, `False` to disable.
@@ -227,7 +227,7 @@ def handle_match_comm(
227227
"""
228228
Called when a match communication message is received.
229229
See `send_match_comm`.
230-
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match settings.
230+
NOTE: Messages from scripts will have `team == 2` and the index will be its index in the match configuration.
231231
"""
232232

233233
def send_match_comm(
@@ -276,7 +276,7 @@ def set_loadout(self, loadout: flat.PlayerLoadout, index: int):
276276

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

rlbot/utils/maps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"EstadioVida_Dusk": "ff_dusk_p",
7272
"Mannfield_Dusk": "eurostadium_dusk_p",
7373
"Farmstead_Pitched": "farm_grs_p",
74-
"Farmstead_Upsidedown": "farm_hw_p",
7574
"Wasteland_Pitched": "wasteland_grs_p",
7675
"Neotokyo_Hacked": "neotokyo_hax_p",
7776
"AquaDome_Shallows": "Underwater_GRS_P",
@@ -84,6 +83,7 @@
8483
"FuturaGarden": "UF_Day_P",
8584
"DFHStadium_Anniversary": "stadium_10a_p",
8685
"Holyfield": "Labs_Holyfield_Space_P",
86+
"DriftWoods_Night": "woods_night_p"
8787
}
8888

8989
STANDARD_MAPS = [
@@ -138,4 +138,5 @@
138138
"Neotokyo_Arcade",
139139
"FuturaGarden",
140140
"DFHStadium_Anniversary",
141+
"DriftWoods_Night"
141142
]

rlbot/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.0.0-beta.46"
1+
__version__ = "2.0.0-beta.47"

tests/render_test/render.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from email.policy import default
2-
31
from rlbot import flat
42
from rlbot.flat import BallAnchor, CarAnchor, Color, RenderAnchor, Vector3
53
from rlbot.managers import Script

0 commit comments

Comments
 (0)