Пример #1
0
    def _reconstruct_object(parsed_data, objects,
                            **kwargs) -> None:  # Expected {}
        player_units_retriever = find_retriever(
            parsed_data['UnitsPiece'].retrievers, "Player Units")

        player_units_retriever.data = []
        for player_units in objects['UnitsObject'].units:

            units_list = []
            for unit in player_units:
                UnitObject._reconstruct_object(parsed_data,
                                               objects,
                                               unit=unit,
                                               units=units_list)

            player_units_retriever.data.append(
                PlayerUnitsStruct(data=[len(units_list), units_list]))
Пример #2
0
    def change_ownership(self, unit: UnitObject, to_player: Player) -> None:
        """
        Changes a unit's ownership to the given player.

        Args:
            unit: The unit object which ownership will be changed
            to_player: The player that'll get ownership over the unit (using Player enum)
        """
        for i, player_unit in enumerate(self.units[unit.player.value]):
            if player_unit == unit:
                del self.units[unit.player.value][i]
                self.units[to_player.value].append(unit)
                unit._player = Player(to_player)
                return
Пример #3
0
    def add_unit(
        self,
        player: Player,
        unit_id: int,
        x: float,
        y: float,
        z: float = 0,
        rotation: float = 0,
        garrisoned_in_id: int = -1,
        animation_frame: int = 0,
        status: int = 2,
        reference_id: int = None,
    ) -> UnitObject:
        """
        Adds a unit to the scenario.

        Args:
            player: The player the unit belongs to.
            unit_id: Defines what unit you're placing. The IDs used in the unit/buildings dataset.
            x: The x location in the scenario.
            y: The y location in the scenario.
            z: The z (height) location in the scenario.
            rotation: The rotation of the unit.
            garrisoned_in_id: The reference_id of another unit this unit is garrisoned in.
            animation_frame: The animation frame of the unit.
            status: Unknown - Always 2. 0-6 no difference (?) | 7-255 makes it disappear. (Except from the mini-map)
            reference_id: The reference ID of this unit. Normally added automatically. Used for garrisoning or reference
                in triggers
        Returns:
            The UnitObject created
        """
        if reference_id is None:
            reference_id = self.get_new_reference_id()

        unit = UnitObject(
            player=player,
            x=x,
            y=y,
            z=z,
            reference_id=reference_id,
            unit_const=unit_id,
            status=status,
            rotation=rotation,
            initial_animation_frame=animation_frame,
            garrisoned_in_id=garrisoned_in_id,
        )

        self.units[player.value].append(unit)
        return unit
Пример #4
0
    def _reconstruct_object(parsed_header, parsed_data, objects,
                            **kwargs) -> None:  # Expected {}
        player_units_retriever = find_retriever(
            parsed_data['UnitsPiece'].retrievers, "Player Units")

        # Todo: Move this to DataHeader
        new_unit_id_retriever = find_retriever(
            parsed_data['DataHeaderPiece'].retrievers, "Next unit ID to place")
        new_unit_id_retriever.data = objects[
            'UnitsObject'].get_new_reference_id()

        player_units_retriever.data = []
        for player_units in objects['UnitsObject'].units:

            units_list = []
            for unit in player_units:
                UnitObject._reconstruct_object(parsed_header,
                                               parsed_data,
                                               objects,
                                               unit=unit,
                                               units=units_list)

            player_units_retriever.data.append(
                PlayerUnitsStruct(data=[len(units_list), units_list]))
Пример #5
0
    def _parse_object(parsed_data, **kwargs) -> UnitsObject:
        object_piece = parsed_data['UnitsPiece']
        units_per_player = find_retriever(object_piece.retrievers,
                                          "Player Units").data

        player_units = []
        for player_id in range(0, 9):  # 0 Gaia & 1-8 Players:
            player_units.append([])
            units = parser.listify(
                find_retriever(units_per_player[player_id].retrievers,
                               "Units").data)

            for unit in units:
                player_units[player_id].append(
                    UnitObject._parse_object(parsed_data,
                                             unit=unit,
                                             player=Player(player_id)))

        return UnitsObject(units=player_units)