async def debug_create_unit( self, unit_spawn_commands: List[List[Union[UnitTypeId, int, Point2, Point3]]]): """ Usage example (will spawn 5 marines in the center of the map for player ID 1): await self._client.debug_create_unit([[UnitTypeId.MARINE, 5, self._game_info.map_center, 1]]) :param unit_spawn_commands: """ assert isinstance(unit_spawn_commands, list) assert unit_spawn_commands assert isinstance(unit_spawn_commands[0], list) assert len(unit_spawn_commands[0]) == 4 assert isinstance(unit_spawn_commands[0][0], UnitTypeId) assert unit_spawn_commands[0][ 1] > 0 # careful, in realtime=True this function may create more units assert isinstance(unit_spawn_commands[0][2], (Point2, Point3)) assert 1 <= unit_spawn_commands[0][3] <= 2 await self._execute(debug=sc_pb.RequestDebug( debug=(debug_pb.DebugCommand(create_unit=debug_pb.DebugCreateUnit( unit_type=unit_type.value, owner=owner_id, pos=common_pb.Point2D(x=position.x, y=position.y), quantity=amount_of_units, )) for unit_type, amount_of_units, position, owner_id in unit_spawn_commands)))
def create_unit(self, unit_type, owner, pos, quantity=1): if isinstance(pos, tuple): pos = sc_common.Point2D(x=pos[0], y=pos[1]) elif isinstance(pos, sc_common.Point): pos = sc_common.Point2D(x=pos.x, y=pos.y) return self.debug(create_unit=sc_debug.DebugCreateUnit( unit_type=unit_type, owner=owner, pos=pos, quantity=quantity))
def test_multi_player(self): run_config = run_configs.get() map_inst = maps.get("Simple64") with run_config.start(want_rgb=False) as controller: create = sc_pb.RequestCreateGame(local_map=sc_pb.LocalMap( map_path=map_inst.path, map_data=map_inst.data(run_config))) create.player_setup.add(type=sc_pb.Participant) create.player_setup.add(type=sc_pb.Computer, race=sc_common.Terran, difficulty=sc_pb.VeryEasy) join = sc_pb.RequestJoinGame( race=sc_common.Terran, options=sc_pb.InterfaceOptions(raw=True)) controller.create_game(create) controller.join_game(join) info = controller.game_info() map_size = info.start_raw.map_size controller.step(2) obs = controller.observe() def get_marines(obs): return { u.tag: u for u in obs.observation.raw_data.units if u.unit_type == units.Terran.Marine } self.assertEmpty(get_marines(obs)) controller.debug( sc_debug.DebugCommand(create_unit=sc_debug.DebugCreateUnit( unit_type=units.Terran.Marine, owner=1, pos=sc_common.Point2D(x=map_size.x // 2, y=map_size.y // 2), quantity=5))) controller.step(2) obs = controller.observe() marines = get_marines(obs) self.assertEqual(5, len(marines)) tags = sorted(marines.keys()) controller.debug([ sc_debug.DebugCommand(kill_unit=sc_debug.DebugKillUnit( tag=[tags[0]])), sc_debug.DebugCommand(unit_value=sc_debug.DebugSetUnitValue( unit_value=sc_debug.DebugSetUnitValue.Life, value=5, unit_tag=tags[1])), ]) controller.step(2) obs = controller.observe() marines = get_marines(obs) self.assertEqual(4, len(marines)) self.assertNotIn(tags[0], marines) self.assertEqual(marines[tags[1]].health, 5)