Exemple #1
0
    def setup_match(self):
        # Set up RLBot.cfg
        framework_config = create_bot_config_layout()
        config_location = os.path.join(os.path.dirname(__file__), 'rlbot.cfg')
        framework_config.parse_file(config_location, max_index=MAX_PLAYERS)
        match_config = parse_match_config(framework_config, config_location, {}, {})
        match_config.game_map = self.choreo_obj.map_name

        # The three blocks of code below are basically identical.
        # TODO Make them into a function?

        # Gets appearance list from choreo.
        appearances = self.choreo_obj.get_appearances(self.min_bots)
        # Checks that it is the correct length.
        if len(appearances) != self.min_bots:
            print('[RLBotChoreography]: Number of appearances does not match number of bots.')
            print('[RLBotChoreography]: Using default appearances.')
            appearances = ['default.cfg'] * self.min_bots

        # Gets teams list from choreo.
        teams = self.choreo_obj.get_teams(self.min_bots)
        # Checks that it is the correct length.
        if len(teams) != self.min_bots:
            print('[RLBotChoreography]: Number of teams does not match number of bots.')
            print('[RLBotChoreography]: Putting all on blue.')
            teams = [0] * self.min_bots

        # Gets names list from choreo.
        names = self.choreo_obj.get_names(self.min_bots)
        # Checks that it is the correct length.
        if len(names) != self.min_bots:
            print('[RLBotChoreography]: Number of names does not match number of bots.')
            print('[RLBotChoreography]: Using bot indices as names.')
            names = range(self.min_bots)

        # Loads appearances.
        looks_configs = {
            idx: create_looks_configurations().parse_file(
                os.path.abspath('./ChoreographyHive/appearances/' + file_name))
            for idx, file_name in enumerate(appearances)
        }

        # rlbot.cfg specifies only one bot, 
        # so we have to copy each and assign correct appearance.
        player_config = match_config.player_configs[0]
        match_config.player_configs.clear()
        for i in range(self.min_bots):
            copied = PlayerConfig()
            copied.name = names[i]
            copied.team = teams[i]
            copied.bot = player_config.bot
            copied.rlbot_controlled = player_config.rlbot_controlled
            copied.config_path = player_config.config_path
            copied.loadout_config = load_bot_appearance(looks_configs[i], copied.team)
            match_config.player_configs.append(copied)

        manager = SetupManager()
        manager.load_match_config(match_config, {})
        manager.connect_to_game()
        manager.start_match()
Exemple #2
0
 def get_looks_config(self) -> ConfigObject:
     """
     Creates a looks config from the config bundle
     :param config_bundle:
     :return:
     """
     return create_looks_configurations().parse_file(self.looks_path)
Exemple #3
0
 def get_looks_config(self) -> ConfigObject:
     """
     Creates a looks config from the config bundle
     :param config_bundle:
     :return:
     """
     if self.looks_path is None:
         raise ValueError("Cannot get looks config because looks_path is None")
     return create_looks_configurations().parse_file(self.looks_path)
Exemple #4
0
def set_random_psyonix_bot_preset(player: PlayerConfig):
    """
    Sets the name and loadout to a randomly selected psyonix bot preset.
    """
    loadout_file = PSYONIX_PRESET_LIST[0]
    PSYONIX_PRESET_LIST.append(PSYONIX_PRESET_LIST.pop(0))  # Move preset to the end of the list.
    loadout_config = create_looks_configurations().parse_file(loadout_file)
    player.loadout_config = load_bot_appearance(loadout_config, player.team)
    player.name = loadout_file.name.split("_")[1].title()
    player.name = ["Rookie ", "Pro ", ""][min(int(abs(player.bot_skill) * 3), 2)] + player.name
Exemple #5
0
def convert_to_looks_config(looks: dict):
    looks_config = create_looks_configurations()

    def deserialize_category(source: dict, header_name: str):
        header = looks_config.get_header(header_name)
        for key in header.values.keys():
            if key in source:
                header.set_value(key, source[key])

    deserialize_category(looks['blue'], BOT_CONFIG_LOADOUT_HEADER)
    deserialize_category(looks['orange'], BOT_CONFIG_LOADOUT_ORANGE_HEADER)
    deserialize_category(looks['blue'], BOT_CONFIG_LOADOUT_PAINT_BLUE_HEADER)
    deserialize_category(looks['orange'], BOT_CONFIG_LOADOUT_PAINT_ORANGE_HEADER)

    return looks_config
Exemple #6
0
def get_looks(path: str) -> dict:
    looks_config = create_looks_configurations().parse_file(path)
    looks = {'blue': {}, 'orange': {}}

    def serialize_category(target: dict, header_name: str):
        header = looks_config.get_header(header_name)
        for key in header.values.keys():
            if header.get(key) is not None:
                target[key] = str(header.get(key))

    serialize_category(looks['blue'], BOT_CONFIG_LOADOUT_HEADER)
    serialize_category(looks['orange'], BOT_CONFIG_LOADOUT_ORANGE_HEADER)
    serialize_category(looks['blue'], BOT_CONFIG_LOADOUT_PAINT_BLUE_HEADER)
    serialize_category(looks['orange'], BOT_CONFIG_LOADOUT_PAINT_ORANGE_HEADER)

    return looks
Exemple #7
0
 def __init__(self, name, file_path=None):
     super().__init__(create_looks_configurations(), file_path, name)
Exemple #8
0
 def load_cfg_file(self, file_path: Path, team: int) -> LoadoutConfig:
     file = self.base_directory / Path(file_path)
     config_object = create_looks_configurations().parse_file(file)
     return load_bot_appearance(config_object, team)