Skip to content

Condition

Classes

Condition

Bases: AoE2Object, TriggerComponent

Object for handling a condition.

Source code in AoE2ScenarioParser/objects/data_objects/condition.py
 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
class Condition(AoE2Object, TriggerComponent):
    """Object for handling a condition."""
    hidden_attribute = 'condition_type'

    _link_list = [
        RetrieverObjectLinkGroup("Triggers", "trigger_data[__index__].condition_data[__index__]", group=[
            RetrieverObjectLink("condition_type"),
            RetrieverObjectLink("quantity"),
            RetrieverObjectLink("attribute"),
            RetrieverObjectLink("unit_object"),
            RetrieverObjectLink("next_object"),
            RetrieverObjectLink("object_list"),
            RetrieverObjectLink("source_player"),
            RetrieverObjectLink("technology"),
            RetrieverObjectLink("timer"),
            RetrieverObjectLink("area_x1"),
            RetrieverObjectLink("area_y1"),
            RetrieverObjectLink("area_x2"),
            RetrieverObjectLink("area_y2"),
            RetrieverObjectLink("object_group"),
            RetrieverObjectLink("object_type"),
            RetrieverObjectLink("ai_signal"),
            RetrieverObjectLink("inverted"),
            RetrieverObjectLink("variable"),
            RetrieverObjectLink("comparison"),
            RetrieverObjectLink("target_player"),
            RetrieverObjectLink("unit_ai_action", support=Support(since=1.40)),
            RetrieverObjectLink("object_state", support=Support(since=1.42)),
            RetrieverObjectLink("timer_id", support=Support(since=1.46)),
            RetrieverObjectLink("victory_timer_type", support=Support(since=1.46)),
            RetrieverObjectLink("include_changeable_weapon_objects", support=Support(since=1.46)),
            RetrieverObjectLink("xs_function", support=Support(since=1.40)),
        ])
    ]

    def __init__(
            self,
            condition_type: int = None,
            quantity: int = None,
            attribute: int = None,
            unit_object: int = None,
            next_object: int = None,
            object_list: int = None,
            source_player: int | IntEnum = None,
            technology: int | IntEnum = None,
            timer: int = None,
            area_x1: int = None,
            area_y1: int = None,
            area_x2: int = None,
            area_y2: int = None,
            object_group: int = None,
            object_type: int = None,
            ai_signal: int = None,
            inverted: int = None,
            variable: int = None,
            comparison: int = None,
            target_player: int | IntEnum = None,
            unit_ai_action: int = None,
            object_state: int = None,
            timer_id: int = None,
            victory_timer_type: int = None,
            include_changeable_weapon_objects: int = None,
            xs_function: str = None,
            **kwargs
    ):
        raise_if_not_int_subclass([object_list, technology])
        area_x1, area_y1, area_x2, area_y2 = validate_coords(area_x1, area_y1, area_x2, area_y2)

        self.condition_type: int = condition_type
        self.quantity: int = quantity
        self.attribute: int = attribute
        self.unit_object: int = unit_object
        self.next_object: int = next_object
        self.object_list: int = object_list
        self.source_player: int = source_player
        self.technology: int = technology
        self.timer: int = timer
        self.area_x1: int = area_x1
        self.area_y1: int = area_y1
        self.area_x2: int = area_x2
        self.area_y2: int = area_y2
        self.object_group: int = object_group
        self.object_type: int = object_type
        self.ai_signal: int = ai_signal
        self.inverted: int = inverted
        self.variable: int = variable
        self.comparison: int = comparison
        self.target_player: int = target_player
        self.unit_ai_action: int = unit_ai_action
        self.object_state: int = object_state
        self.timer_id: int = timer_id
        self.victory_timer_type: int = victory_timer_type
        self.include_changeable_weapon_objects: int = include_changeable_weapon_objects
        self.xs_function: str = xs_function

        super().__init__(**kwargs)

    def _should_be_displayed(self, attr: str, val: Any) -> bool:
        # Include the only exception to the -1 == invalid rule
        if self.condition_type == ConditionId.DIFFICULTY_LEVEL and attr == 'quantity' and val == -1:
            return True

        return super()._should_be_displayed(attr, val)

    def get_content_as_string(self, include_condition_definition: bool = False) -> str:
        """
        Create a human-readable string showcasing all content of this condition.

        This is also the function that is called when doing: `print(condition)`

        Args:
            include_condition_definition: If the condition meta-data should be added by this function

        Returns:
            The created string
        """
        if self.condition_type not in conditions.attributes:
            attributes_list = conditions.empty_attributes
        else:
            attributes_list = conditions.attributes[self.condition_type]

        return_string = ""
        for attribute in attributes_list:
            val = getattr(self, attribute)
            if not self._should_be_displayed(attribute, val):
                continue

            value_string = transform_condition_attr_value(self.condition_type, attribute, val, self._uuid)
            return_string += f"{attribute}: {value_string}\n"

        if return_string == "":
            return "<< No Attributes >>\n"

        if include_condition_definition:
            return f"{conditions.condition_names[self.condition_type]}:\n{add_tabs(return_string, 1)}"

        return return_string

    def __str__(self):
        return f"[Condition] {self.get_content_as_string(include_condition_definition=True)}"

Attributes

ai_signal: int = ai_signal instance-attribute
Type: int
Value: ai_signal
area_x1: int = area_x1 instance-attribute
Type: int
Value: area_x1
area_x2: int = area_x2 instance-attribute
Type: int
Value: area_x2
area_y1: int = area_y1 instance-attribute
Type: int
Value: area_y1
area_y2: int = area_y2 instance-attribute
Type: int
Value: area_y2
attribute: int = attribute instance-attribute
Type: int
Value: attribute
comparison: int = comparison instance-attribute
Type: int
Value: comparison
condition_type: int = condition_type instance-attribute
Type: int
Value: condition_type
hidden_attribute = 'condition_type' class-attribute instance-attribute
Value: 'condition_type'
include_changeable_weapon_objects: int = include_changeable_weapon_objects instance-attribute
Type: int
Value: include_changeable_weapon_objects
inverted: int = inverted instance-attribute
Type: int
Value: inverted
next_object: int = next_object instance-attribute
Type: int
Value: next_object
object_group: int = object_group instance-attribute
Type: int
Value: object_group
object_list: int = object_list instance-attribute
Type: int
Value: object_list
object_state: int = object_state instance-attribute
Type: int
Value: object_state
object_type: int = object_type instance-attribute
Type: int
Value: object_type
quantity: int = quantity instance-attribute
Type: int
Value: quantity
source_player: int = source_player instance-attribute
Type: int
Value: source_player
target_player: int = target_player instance-attribute
Type: int
Value: target_player
technology: int = technology instance-attribute
Type: int
Value: technology
timer: int = timer instance-attribute
Type: int
Value: timer
timer_id: int = timer_id instance-attribute
Type: int
Value: timer_id
unit_ai_action: int = unit_ai_action instance-attribute
Type: int
Value: unit_ai_action
unit_object: int = unit_object instance-attribute
Type: int
Value: unit_object
variable: int = variable instance-attribute
Type: int
Value: variable
victory_timer_type: int = victory_timer_type instance-attribute
Type: int
Value: victory_timer_type
xs_function: str = xs_function instance-attribute
Type: str
Value: xs_function

Functions


def __init__(...)

Parameters:

Name Type Description Default
condition_type int - None
quantity int - None
attribute int - None
unit_object int - None
next_object int - None
object_list int - None
source_player int | IntEnum - None
technology int | IntEnum - None
timer int - None
area_x1 int - None
area_y1 int - None
area_x2 int - None
area_y2 int - None
object_group int - None
object_type int - None
ai_signal int - None
inverted int - None
variable int - None
comparison int - None
target_player int | IntEnum - None
unit_ai_action int - None
object_state int - None
timer_id int - None
victory_timer_type int - None
include_changeable_weapon_objects int - None
xs_function str - None
kwargs ? - {}
Source code in AoE2ScenarioParser/objects/data_objects/condition.py
 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
def __init__(
        self,
        condition_type: int = None,
        quantity: int = None,
        attribute: int = None,
        unit_object: int = None,
        next_object: int = None,
        object_list: int = None,
        source_player: int | IntEnum = None,
        technology: int | IntEnum = None,
        timer: int = None,
        area_x1: int = None,
        area_y1: int = None,
        area_x2: int = None,
        area_y2: int = None,
        object_group: int = None,
        object_type: int = None,
        ai_signal: int = None,
        inverted: int = None,
        variable: int = None,
        comparison: int = None,
        target_player: int | IntEnum = None,
        unit_ai_action: int = None,
        object_state: int = None,
        timer_id: int = None,
        victory_timer_type: int = None,
        include_changeable_weapon_objects: int = None,
        xs_function: str = None,
        **kwargs
):
    raise_if_not_int_subclass([object_list, technology])
    area_x1, area_y1, area_x2, area_y2 = validate_coords(area_x1, area_y1, area_x2, area_y2)

    self.condition_type: int = condition_type
    self.quantity: int = quantity
    self.attribute: int = attribute
    self.unit_object: int = unit_object
    self.next_object: int = next_object
    self.object_list: int = object_list
    self.source_player: int = source_player
    self.technology: int = technology
    self.timer: int = timer
    self.area_x1: int = area_x1
    self.area_y1: int = area_y1
    self.area_x2: int = area_x2
    self.area_y2: int = area_y2
    self.object_group: int = object_group
    self.object_type: int = object_type
    self.ai_signal: int = ai_signal
    self.inverted: int = inverted
    self.variable: int = variable
    self.comparison: int = comparison
    self.target_player: int = target_player
    self.unit_ai_action: int = unit_ai_action
    self.object_state: int = object_state
    self.timer_id: int = timer_id
    self.victory_timer_type: int = victory_timer_type
    self.include_changeable_weapon_objects: int = include_changeable_weapon_objects
    self.xs_function: str = xs_function

    super().__init__(**kwargs)

def __str__(...)
Source code in AoE2ScenarioParser/objects/data_objects/condition.py
156
157
def __str__(self):
    return f"[Condition] {self.get_content_as_string(include_condition_definition=True)}"

def get_content_as_string(...)

Create a human-readable string showcasing all content of this condition.

This is also the function that is called when doing: print(condition)

Parameters:

Name Type Description Default
include_condition_definition bool

If the condition meta-data should be added by this function

False

Returns:

Type Description
str

The created string

Source code in AoE2ScenarioParser/objects/data_objects/condition.py
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
def get_content_as_string(self, include_condition_definition: bool = False) -> str:
    """
    Create a human-readable string showcasing all content of this condition.

    This is also the function that is called when doing: `print(condition)`

    Args:
        include_condition_definition: If the condition meta-data should be added by this function

    Returns:
        The created string
    """
    if self.condition_type not in conditions.attributes:
        attributes_list = conditions.empty_attributes
    else:
        attributes_list = conditions.attributes[self.condition_type]

    return_string = ""
    for attribute in attributes_list:
        val = getattr(self, attribute)
        if not self._should_be_displayed(attribute, val):
            continue

        value_string = transform_condition_attr_value(self.condition_type, attribute, val, self._uuid)
        return_string += f"{attribute}: {value_string}\n"

    if return_string == "":
        return "<< No Attributes >>\n"

    if include_condition_definition:
        return f"{conditions.condition_names[self.condition_type]}:\n{add_tabs(return_string, 1)}"

    return return_string

Functions

Modules