Skip to content

InfoDatasetBase

Bases: Enum

This enum class is the base class for the UnitInfo, BuildingInfo, HeroInfo and OtherInfo datasets. It provides the properties and functions common to all the mentioned classes

Methods

Source code in AoE2ScenarioParser/datasets/support/info_dataset_base.py
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
class InfoDatasetBase(Enum):
    """
    This enum class is the base class for the UnitInfo, BuildingInfo, HeroInfo and OtherInfo datasets. It provides the
    properties and functions common to all the mentioned classes

    **Methods**







    """

    @staticmethod
    def _id_map() -> dict:
        """
        Returns:
            A dict that maps the names of the properties to their index in the info tuple
        """
        return {'id': 0, 'icon_id': 1, 'dead_id': 2, 'hotkey_id': 3, 'gaia_only': 4}

    def _get_property(self, name: str) -> int | bool:
        """
        Get the specified property by its name from an object of this (or its derived) class

        Args:
            name: the name of the property to get

        Returns:
        """
        return self.value[self._id_map()[name]]

    @property
    def ID(self) -> int:
        """
        Returns:
            The ID of the specified unit
        """
        return self._get_property('id')

    @property
    def ICON_ID(self) -> int:
        """
        Returns:
            The Icon ID of the specified unit
        """
        return self._get_property('icon_id')

    @property
    def DEAD_ID(self) -> int:
        """
        Returns:
            The Dead Unit ID of the specified unit
        """
        return self._get_property('dead_id')

    @property
    def HOTKEY_ID(self) -> int:
        """
        Returns:
            The HotKey ID of the specified unit
        """
        return self._get_property('hotkey_id')

    @property
    def IS_GAIA_ONLY(self) -> bool:
        """
        Returns:
            A boolean value indicating if the specified unit is a gaia only unit (e.g. Deer)
        """
        return self._get_property('gaia_only')

    @classmethod
    def _from_id(cls, id_type: str, value: int) -> InfoDatasetBase:
        """
        Finds and returns the member object that uses the given value for the specified property (id_type)

        Args:
            id_type: the property of member objects that should match the value specified
            value: the value of the property to search for

        Returns:
            An InfoDatasetBase member object which uses the given value for the specified property (id_type
        """
        index = cls._id_map()[id_type]

        if type(value) is not int:
            raise TypeError(f"from_id expected int, got {type(value)}")
        if value < 0:
            raise ValueError(f"{value} is not a valid id value")

        for member in cls._member_map_.values():
            if member.value[index] == value:
                return member

        raise KeyError(f"A unit with {id_type} = {value} was not found in the dataset")

    @classmethod
    def from_id(cls, unit_id: int) -> InfoDatasetBase:
        """
        Finds and returns the unit with the given unit ID

        Args:
            unit_id: the unit ID to search for

        Returns:
            A unit with the given unit I
        """
        return cls._from_id('id', unit_id)

    @classmethod
    def from_icon_id(cls, icon_id: int) -> InfoDatasetBase:
        """
        Finds and returns the unit with the given icon ID

        Args:
            icon_id: the icon ID to search for

        Returns:
            A unit with the given icon ID
        """
        return cls._from_id('icon_id', icon_id)

    @classmethod
    def from_dead_id(cls, dead_id: int) -> InfoDatasetBase:
        """
        Finds and returns the unit with the given dead unit ID

        Args:
            dead_id: the dead unit ID to search for

        Returns:
            A unit with the given dead unit ID
        """
        return cls._from_id('dead_id', dead_id)

    @classmethod
    def from_hotkey_id(cls, hotkey_id: int) -> InfoDatasetBase:
        """
        Finds and returns the unit with the given hotkey ID. Note that there may be multiple units that
        use the same hotkey ID, currently only one is returned!

        Args:
            hotkey_id: the hotkey ID to search for

        Returns:
            A unit with the given hotkey ID
        """
        return cls._from_id('hotkey_id', hotkey_id)

    @classmethod
    def gaia_only(cls) -> List[InfoDatasetBase]:
        """
        Returns:
            A list of all the gaia only units (e.g. Deer)
        """
        return cls._gaia_filter(gaia_only=True)

    @classmethod
    def non_gaia(cls) -> List[InfoDatasetBase]:
        """
        Returns:
            A list of all the units excluding gaia only units (e.g. militia)
        """
        return cls._gaia_filter(gaia_only=False)

    @classmethod
    def _gaia_filter(cls, gaia_only: bool) -> List[InfoDatasetBase]:
        """
        Args:
            gaia_only: if set to true, lists all gaia only units. If set to `False`, lists all units except gaia only units

        Returns:
            A list of either all gaia only units or a list of all units excluding gaia only units
        """
        result = []
        for x in cls:
            if x.IS_GAIA_ONLY == gaia_only:
                result.append(x)
        return result

Attributes

DEAD_ID: int property

Type: int

Returns:

Type Description
int

The Dead Unit ID of the specified unit

HOTKEY_ID: int property

Type: int

Returns:

Type Description
int

The HotKey ID of the specified unit

ICON_ID: int property

Type: int

Returns:

Type Description
int

The Icon ID of the specified unit

ID: int property

Type: int

Returns:

Type Description
int

The ID of the specified unit

IS_GAIA_ONLY: bool property

Type: bool

Returns:

Type Description
bool

A boolean value indicating if the specified unit is a gaia only unit (e.g. Deer)

Functions


def from_dead_id(...) classmethod

Finds and returns the unit with the given dead unit ID

Parameters:

Name Type Description Default
dead_id int

the dead unit ID to search for

required

Returns:

Type Description
InfoDatasetBase

A unit with the given dead unit ID

Source code in AoE2ScenarioParser/datasets/support/info_dataset_base.py
132
133
134
135
136
137
138
139
140
141
142
143
@classmethod
def from_dead_id(cls, dead_id: int) -> InfoDatasetBase:
    """
    Finds and returns the unit with the given dead unit ID

    Args:
        dead_id: the dead unit ID to search for

    Returns:
        A unit with the given dead unit ID
    """
    return cls._from_id('dead_id', dead_id)

def from_hotkey_id(...) classmethod

Finds and returns the unit with the given hotkey ID. Note that there may be multiple units that use the same hotkey ID, currently only one is returned!

Parameters:

Name Type Description Default
hotkey_id int

the hotkey ID to search for

required

Returns:

Type Description
InfoDatasetBase

A unit with the given hotkey ID

Source code in AoE2ScenarioParser/datasets/support/info_dataset_base.py
145
146
147
148
149
150
151
152
153
154
155
156
157
@classmethod
def from_hotkey_id(cls, hotkey_id: int) -> InfoDatasetBase:
    """
    Finds and returns the unit with the given hotkey ID. Note that there may be multiple units that
    use the same hotkey ID, currently only one is returned!

    Args:
        hotkey_id: the hotkey ID to search for

    Returns:
        A unit with the given hotkey ID
    """
    return cls._from_id('hotkey_id', hotkey_id)

def from_icon_id(...) classmethod

Finds and returns the unit with the given icon ID

Parameters:

Name Type Description Default
icon_id int

the icon ID to search for

required

Returns:

Type Description
InfoDatasetBase

A unit with the given icon ID

Source code in AoE2ScenarioParser/datasets/support/info_dataset_base.py
119
120
121
122
123
124
125
126
127
128
129
130
@classmethod
def from_icon_id(cls, icon_id: int) -> InfoDatasetBase:
    """
    Finds and returns the unit with the given icon ID

    Args:
        icon_id: the icon ID to search for

    Returns:
        A unit with the given icon ID
    """
    return cls._from_id('icon_id', icon_id)

def from_id(...) classmethod

Finds and returns the unit with the given unit ID

Parameters:

Name Type Description Default
unit_id int

the unit ID to search for

required

Returns:

Type Description
InfoDatasetBase

A unit with the given unit I

Source code in AoE2ScenarioParser/datasets/support/info_dataset_base.py
106
107
108
109
110
111
112
113
114
115
116
117
@classmethod
def from_id(cls, unit_id: int) -> InfoDatasetBase:
    """
    Finds and returns the unit with the given unit ID

    Args:
        unit_id: the unit ID to search for

    Returns:
        A unit with the given unit I
    """
    return cls._from_id('id', unit_id)

def gaia_only(...) classmethod

Returns:

Type Description
List[InfoDatasetBase]

A list of all the gaia only units (e.g. Deer)

Source code in AoE2ScenarioParser/datasets/support/info_dataset_base.py
159
160
161
162
163
164
165
@classmethod
def gaia_only(cls) -> List[InfoDatasetBase]:
    """
    Returns:
        A list of all the gaia only units (e.g. Deer)
    """
    return cls._gaia_filter(gaia_only=True)

def non_gaia(...) classmethod

Returns:

Type Description
List[InfoDatasetBase]

A list of all the units excluding gaia only units (e.g. militia)

Source code in AoE2ScenarioParser/datasets/support/info_dataset_base.py
167
168
169
170
171
172
173
@classmethod
def non_gaia(cls) -> List[InfoDatasetBase]:
    """
    Returns:
        A list of all the units excluding gaia only units (e.g. militia)
    """
    return cls._gaia_filter(gaia_only=False)