Skip to content

Player

Classes

Player

Bases: AoE2Object

A class for handling all player information.

Source code in AoE2ScenarioParser/objects/data_objects/player/player.py
 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
class Player(AoE2Object):
    """A class for handling all player information."""

    _object_attributes = [
        'player_id',
        'starting_age',
        'lock_civ',
        'food',
        'wood',
        'gold',
        'stone',
        'color',
        'active',
        'human',
        'civilization',
        'architecture_set',
    ]
    _object_attributes_non_gaia = [
        'population_cap',
        'diplomacy',
        'initial_camera_x',
        'initial_camera_y',
        'allied_victory',
        'disabled_techs',
        'disabled_buildings',
        'disabled_units',
        'base_priority',
        'tribe_name',
        'string_table_name_id',
    ]

    def __init__(
            self,
            player_id: int,
            starting_age: int,
            lock_civ: int,
            lock_personality: int,
            food: int,
            wood: int,
            gold: int,
            stone: int,
            color: int,
            active: bool,
            human: bool,
            civilization: int,
            architecture_set: int,

            # Optionals due to GAIA not having such value
            population_cap: Optional[int] = None,
            diplomacy: Optional[List[int]] = None,
            initial_camera_x: Optional[int] = None,
            initial_camera_y: Optional[int] = None,
            allied_victory: Optional[int] = None,
            disabled_techs: Optional[List[int]] = None,
            disabled_buildings: Optional[List[int]] = None,
            disabled_units: Optional[List[int]] = None,
            tribe_name: Optional[str] = None,
            base_priority: Optional[int] = None,
            string_table_name_id: Optional[int] = None,
            **kwargs
    ):
        super().__init__(**kwargs)

        self._player_id: int = player_id
        self._active: bool = active
        self.starting_age: int = dataset_or_value(StartingAge, starting_age)
        self.lock_civ: bool = bool(lock_civ)
        self.lock_personality: bool = bool(lock_personality)
        self.food: int = food
        self.wood: int = wood
        self.gold: int = gold
        self.stone: int = stone
        self.color: int = color
        self.human: bool = human
        self.civilization: int | Civilization = dataset_or_value(Civilization, civilization)
        self.architecture_set: int | Civilization = dataset_or_value(Civilization, architecture_set)

        # Optionals due to GAIA not having such value
        self.population_cap: Optional[int] = population_cap
        self.diplomacy: Optional[List[int]] = diplomacy
        self.initial_camera_x: Optional[int] = initial_camera_x
        self.initial_camera_y: Optional[int] = initial_camera_y
        self.allied_victory: Optional[bool] = bool(allied_victory) if allied_victory is not None else None
        self.disabled_techs: Optional[List[int]] = disabled_techs
        self.disabled_buildings: Optional[List[int]] = disabled_buildings
        self.disabled_units: Optional[List[int]] = disabled_units
        self.tribe_name: Optional[str] = tribe_name
        self.base_priority: Optional[int] = base_priority
        self.string_table_name_id: Optional[int] = string_table_name_id

    @property
    def player_id(self):
        """Read-only value of the player ID"""
        return self._player_id

    @property
    def active(self):
        """Read-only value if this player is active or not"""
        return self._active

    def set_player_diplomacy(self, players: PlayerId | int | List[PlayerId | int], diplomacy: DiplomacyState):
        """
        Set the diplomacy of this player to other players.

        Note: This sets the player diplomacy ONE WAY!
            This does NOT set the other player's diplomacy to this player to the same diplomacy

        Args:
            players: The player(s) to change
            diplomacy: The diplomacy setting to set the player to
        """
        players: List[PlayerId | int] = listify(players)

        if self.player_id in players:
            raise ValueError("Cannot set diplomacy from and to the same player")

        for player in players:
            self.diplomacy[player - 1] = diplomacy

    def _get_object_attrs(self):
        attrs = self._object_attributes
        if self.player_id != PlayerId.GAIA:
            attrs.extend(self._object_attributes_non_gaia)
        return super()._get_object_attrs() + attrs

Attributes

Attribute Type
allied_victory instance-attribute
Optional[bool]
architecture_set instance-attribute
int | Civilization
base_priority instance-attribute
Optional[int]
civilization instance-attribute
int | Civilization
color instance-attribute
int
diplomacy instance-attribute
Optional[List[int]]
disabled_buildings instance-attribute
Optional[List[int]]
disabled_techs instance-attribute
Optional[List[int]]
disabled_units instance-attribute
Optional[List[int]]
food instance-attribute
int
gold instance-attribute
int
human instance-attribute
bool
initial_camera_x instance-attribute
Optional[int]
initial_camera_y instance-attribute
Optional[int]
lock_civ instance-attribute
bool
lock_personality instance-attribute
bool
population_cap instance-attribute
Optional[int]
starting_age instance-attribute
int
stone instance-attribute
int
string_table_name_id instance-attribute
Optional[int]
tribe_name instance-attribute
Optional[str]
wood instance-attribute
int
active property

Read-only value if this player is active or not

Source code in AoE2ScenarioParser/objects/data_objects/player/player.py
109
110
111
def active(self):
    """Read-only value if this player is active or not"""
    return self._active
player_id property

Read-only value of the player ID

Source code in AoE2ScenarioParser/objects/data_objects/player/player.py
104
105
106
def player_id(self):
    """Read-only value of the player ID"""
    return self._player_id

Functions


def __init__(...)

Parameters:

Name Type Description Default
player_id int - required
starting_age int - required
lock_civ int - required
lock_personality int - required
food int - required
wood int - required
gold int - required
stone int - required
color int - required
active bool - required
human bool - required
civilization int - required
architecture_set int - required
population_cap Optional[int] - None
diplomacy Optional[List[int]] - None
initial_camera_x Optional[int] - None
initial_camera_y Optional[int] - None
allied_victory Optional[int] - None
disabled_techs Optional[List[int]] - None
disabled_buildings Optional[List[int]] - None
disabled_units Optional[List[int]] - None
tribe_name Optional[str] - None
base_priority Optional[int] - None
string_table_name_id Optional[int] - None
kwargs ? - {}
Source code in AoE2ScenarioParser/objects/data_objects/player/player.py
 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
def __init__(
        self,
        player_id: int,
        starting_age: int,
        lock_civ: int,
        lock_personality: int,
        food: int,
        wood: int,
        gold: int,
        stone: int,
        color: int,
        active: bool,
        human: bool,
        civilization: int,
        architecture_set: int,

        # Optionals due to GAIA not having such value
        population_cap: Optional[int] = None,
        diplomacy: Optional[List[int]] = None,
        initial_camera_x: Optional[int] = None,
        initial_camera_y: Optional[int] = None,
        allied_victory: Optional[int] = None,
        disabled_techs: Optional[List[int]] = None,
        disabled_buildings: Optional[List[int]] = None,
        disabled_units: Optional[List[int]] = None,
        tribe_name: Optional[str] = None,
        base_priority: Optional[int] = None,
        string_table_name_id: Optional[int] = None,
        **kwargs
):
    super().__init__(**kwargs)

    self._player_id: int = player_id
    self._active: bool = active
    self.starting_age: int = dataset_or_value(StartingAge, starting_age)
    self.lock_civ: bool = bool(lock_civ)
    self.lock_personality: bool = bool(lock_personality)
    self.food: int = food
    self.wood: int = wood
    self.gold: int = gold
    self.stone: int = stone
    self.color: int = color
    self.human: bool = human
    self.civilization: int | Civilization = dataset_or_value(Civilization, civilization)
    self.architecture_set: int | Civilization = dataset_or_value(Civilization, architecture_set)

    # Optionals due to GAIA not having such value
    self.population_cap: Optional[int] = population_cap
    self.diplomacy: Optional[List[int]] = diplomacy
    self.initial_camera_x: Optional[int] = initial_camera_x
    self.initial_camera_y: Optional[int] = initial_camera_y
    self.allied_victory: Optional[bool] = bool(allied_victory) if allied_victory is not None else None
    self.disabled_techs: Optional[List[int]] = disabled_techs
    self.disabled_buildings: Optional[List[int]] = disabled_buildings
    self.disabled_units: Optional[List[int]] = disabled_units
    self.tribe_name: Optional[str] = tribe_name
    self.base_priority: Optional[int] = base_priority
    self.string_table_name_id: Optional[int] = string_table_name_id

def set_player_diplomacy(...)

Set the diplomacy of this player to other players.

This sets the player diplomacy ONE WAY!

This does NOT set the other player's diplomacy to this player to the same diplomacy

Parameters:

Name Type Description Default
players PlayerId | int | List[PlayerId | int]

The player(s) to change

required
diplomacy DiplomacyState

The diplomacy setting to set the player to

required
Source code in AoE2ScenarioParser/objects/data_objects/player/player.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def set_player_diplomacy(self, players: PlayerId | int | List[PlayerId | int], diplomacy: DiplomacyState):
    """
    Set the diplomacy of this player to other players.

    Note: This sets the player diplomacy ONE WAY!
        This does NOT set the other player's diplomacy to this player to the same diplomacy

    Args:
        players: The player(s) to change
        diplomacy: The diplomacy setting to set the player to
    """
    players: List[PlayerId | int] = listify(players)

    if self.player_id in players:
        raise ValueError("Cannot set diplomacy from and to the same player")

    for player in players:
        self.diplomacy[player - 1] = diplomacy

Functions