@@ -42,7 +42,7 @@ def __init__(self):
4242 self ._game_interface .match_settings_handlers .append (self ._handle_match_settings )
4343 self ._game_interface .field_info_handlers .append (self ._handle_field_info )
4444 self ._game_interface .match_communication_handlers .append (
45- self ._handle_match_communication
45+ self .handle_match_communication
4646 )
4747 self ._game_interface .ball_prediction_handlers .append (
4848 self ._handle_ball_prediction
@@ -51,6 +51,21 @@ def __init__(self):
5151
5252 self .renderer = Renderer (self ._game_interface )
5353
54+ def _initialize_agent (self ):
55+ try :
56+ self .initialize_agent ()
57+ except Exception as e :
58+ self ._logger .critical (
59+ "Hivemind %s failed to initialize due the following error: %s" ,
60+ "Unknown" if len (self .names ) == 0 else self .names [0 ],
61+ e ,
62+ )
63+ print_exc ()
64+ exit ()
65+
66+ self ._initialized_bot = True
67+ self ._game_interface .send_init_complete (flat .InitComplete (self .spawn_ids [0 ]))
68+
5469 def _handle_match_settings (self , match_settings : flat .MatchSettings ):
5570 self .match_settings = match_settings
5671 self ._has_match_settings = True
@@ -64,30 +79,19 @@ def _handle_match_settings(self, match_settings: flat.MatchSettings):
6479 break
6580
6681 if not self ._initialized_bot and self ._has_field_info :
67- self .initialize_agent ()
68- self ._initialized_bot = True
82+ self ._initialize_agent ()
6983
7084 def _handle_field_info (self , field_info : flat .FieldInfo ):
7185 self .field_info = field_info
7286 self ._has_field_info = True
7387
7488 if not self ._initialized_bot and self ._has_match_settings :
75- self .initialize_agent ()
76- self ._initialized_bot = True
77-
78- def _handle_match_communication (self , match_comm : flat .MatchComm ):
79- if match_comm .team_only and self .team != match_comm .team :
80- return
81-
82- self .handle_match_communication (match_comm )
89+ self ._initialize_agent ()
8390
8491 def _handle_ball_prediction (self , ball_prediction : flat .BallPrediction ):
8592 self .ball_prediction = ball_prediction
8693
8794 def _handle_packet (self , packet : flat .GameTickPacket ):
88- if not self ._initialized_bot :
89- return
90-
9195 if len (self .indicies ) != len (self .spawn_ids ) or any (
9296 packet .players [i ].spawn_id not in self .spawn_ids for i in self .indicies
9397 ):
@@ -178,6 +182,15 @@ def set_game_state(self, game_state: flat.DesiredGameState):
178182 """
179183 self ._game_interface .send_game_state (game_state )
180184
185+ def set_loadout (self , loadout : flat .PlayerLoadout , spawn_id : int ):
186+ """
187+ Sets the loadout of a bot.
188+
189+ For use as a loadout generator, call inside of `initialize_agent`.
190+ Will be ignored if called outside of `initialize_agent` when state setting is disabled.
191+ """
192+ self ._game_interface .send_set_loadout (flat .SetLoadout (spawn_id , loadout ))
193+
181194 def initialize_agent (self ):
182195 """
183196 Called for all heaver initialization that needs to happen.
0 commit comments