async def debug_set_unit_value(self, unit_tags: Union[Iterable[int], Units, Unit], unit_value: int, value: float): """ Sets a "unit value" (Energy, Life or Shields) of the given units to the given value. Can't set the life of a unit to 0, use "debug_kill_unit" for that. Also can't set the life above the unit's maximum. The following example sets the health of all your workers to 1: await self.debug_set_unit_value(self.workers, 2, value=1) """ if isinstance(unit_tags, Units): unit_tags = unit_tags.tags if isinstance(unit_tags, Unit): unit_tags = [unit_tags.tag] assert hasattr( unit_tags, "__iter__" ), f"unit_tags argument needs to be an iterable (list, dict, set, Units), given argument is {type(unit_tags).__name__}" assert ( 1 <= unit_value <= 3 ), f"unit_value needs to be between 1 and 3 (1 for energy, 2 for life, 3 for shields), given argument is {unit_value}" assert all( tag > 0 for tag in unit_tags), f"Unit tags have invalid value: {unit_tags}" assert isinstance( value, (int, float)), "Value needs to be of type int or float" assert value >= 0, "Value can't be negative" await self._execute(debug=sc_pb.RequestDebug( debug=(debug_pb.DebugCommand(unit_value=debug_pb.DebugSetUnitValue( unit_value=unit_value, value=float(value), unit_tag=unit_tag)) for unit_tag in unit_tags)))
def test_hallucination(self): self.god() # Create some sentries. self.create_unit(unit_type=units.Protoss.Sentry, owner=1, pos=(30, 30)) self.create_unit(unit_type=units.Protoss.Sentry, owner=2, pos=(30, 28)) self.step() obs = self.observe() # Give one enough energy. tag = utils.get_unit(obs[0], unit_type=units.Protoss.Sentry, owner=1).tag self.debug(unit_value=sc_debug.DebugSetUnitValue( unit_value=sc_debug.DebugSetUnitValue.Energy, value=200, unit_tag=tag)) self.step() obs = self.observe() # Create a hallucinated archon. self.raw_unit_command(0, "Hallucination_Archon_quick", tag) self.step() obs = self.observe() # Verify the owner knows it's a hallucination, but the opponent doesn't. p1 = utils.get_unit(obs[0], unit_type=units.Protoss.Archon) p2 = utils.get_unit(obs[1], unit_type=units.Protoss.Archon) self.assertTrue(p1.is_hallucination) self.assertFalse(p2.is_hallucination) # Create an observer so the opponent has detection. self.create_unit(unit_type=units.Protoss.Observer, owner=2, pos=(28, 30)) self.step() obs = self.observe() # Verify the opponent now also knows it's a hallucination. p1 = utils.get_unit(obs[0], unit_type=units.Protoss.Archon) p2 = utils.get_unit(obs[1], unit_type=units.Protoss.Archon) self.assertTrue(p1.is_hallucination) self.assertTrue(p2.is_hallucination)
def set_energy(self, tag, energy): self.debug(unit_value=sc_debug.DebugSetUnitValue( unit_value=sc_debug.DebugSetUnitValue.Energy, value=energy, unit_tag=tag))
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)