UnitManager
Classes¶
UnitManager
¶
Bases: AoE2Object
Manager of everything unit related.
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
Attributes¶
reference_id_generator: Generator[int] = create_id_generator(next_unit_id)
instance-attribute
¶
Generator[int]
Value:
create_id_generator(next_unit_id)
Functions¶
def __init__(...)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_player_units |
List[PlayerUnits]
|
- | required |
next_unit_id |
int
|
- | required |
kwargs |
? | - |
{}
|
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
22 23 24 25 26 27 28 29 30 31 |
|
def add_unit(...)
¶
Adds a unit to the scenario.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
player |
int | PlayerId
|
The player the unit belongs to. |
required |
unit_const |
int
|
Defines what unit you're placing. The IDs used in the unit/buildings dataset. |
required |
x |
float
|
The x location in the scenario. |
0
|
y |
float
|
The y location in the scenario. |
0
|
z |
float
|
The z (height) location in the scenario. |
0
|
rotation |
float
|
The rotation of the unit. |
0
|
garrisoned_in_id |
int
|
The reference_id of another unit this unit is garrisoned in. |
-1
|
animation_frame |
int
|
The animation frame of the unit. |
0
|
status |
int
|
Unknown - Always 2. 0-6 no difference (?) | 7-255 makes it disappear. (Except from the mini-map) |
2
|
reference_id |
int
|
The reference ID of this unit. Normally added automatically. Used for garrisoning or reference in triggers |
None
|
caption_string_id |
int
|
A string ID for the caption of a unit |
-1
|
tile |
Tile | Tuple[int, int]
|
An object that represents a tile on the map. Replaces parameters x and y. Also, automatically adds .5 to both ints to place the unit centered on the tile. |
None
|
Returns:
Type | Description |
---|---|
Unit
|
The Unit created |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
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 |
|
def change_ownership(...)
staticmethod
¶
Changes a unit's ownership to the given player.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit |
Unit | List[Unit]
|
The unit object which ownership will be changed |
required |
to_player |
int | PlayerId
|
The player that'll get ownership over the unit (using PlayerId enum) |
required |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
def clone_unit(...)
¶
Clones an existing unit with the adjusted variables. Everything except the initial unit is optional. When arguments are provided, they will override the corresponding values in the cloned unit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit |
Unit
|
The unit to clone |
required |
player |
int | PlayerId
|
The player to set the cloned unit to (If not provided, the original player will be used) |
None
|
unit_const |
int
|
The unit you're placing (If not provided, the original unit constant will be used) |
None
|
x |
float
|
The X coordinate of the cloned unit (If not provided, the original x coordinate will be used) |
None
|
y |
float
|
The Y coordinate of the cloned unit (If not provided, the original y coordinate will be used) |
None
|
z |
float
|
The Z coordinate of the cloned unit (If not provided, the original z coordinate will be used) |
None
|
rotation |
float
|
The rotation of the cloned unit (If not provided, the original rotation will be used) |
None
|
garrisoned_in_id |
int
|
The id of the garrisoned unit (If not provided, the original garrisoned id will be used) |
None
|
animation_frame |
int
|
The animation frame of the cloned unit (If not provided, the original animation frame will be used) |
None
|
status |
int
|
The status of the cloned unit (If not provided, the original status will be used) |
None
|
reference_id |
int
|
Reference id of the cloned unit (If not provided, a new reference id will be generated) |
None
|
tile |
Tile | Tuple[int, int]
|
The tile of the cloned unit (If not provided, the original x,y coordinates will be used) |
None
|
Returns:
Type | Description |
---|---|
Unit
|
The cloned unit |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
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 |
|
def filter_units_by(...)
¶
Filter units based on a given attribute of units
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str
|
The attribute to filter by |
required |
unit_attrs |
List[int]
|
The values for the attributes to filter with |
required |
blacklist |
bool
|
Use the given constant list as blacklist instead of whitelist |
False
|
player_list |
List[Union[int, PlayerId]]
|
A list of players to filter from. If not used, all players are used. |
None
|
unit_list |
List[Unit]
|
A set of units to filter from. If not used, all units are used. |
None
|
Returns:
Type | Description |
---|---|
List[Unit]
|
A list of units |
Raises:
Type | Description |
---|---|
AttributeError
|
If the provided attr does not exist on objects of the Unit class |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
def filter_units_by_const(...)
¶
Filter unit on their unit_const value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_consts |
List[int]
|
The constants to filter with |
required |
blacklist |
bool
|
Use the given constant list as blacklist instead of whitelist |
False
|
player_list |
List[Union[int, PlayerId]]
|
A list of players to filter from. If not used, all players are used. |
None
|
unit_list |
List[Unit]
|
A set of units to filter from. If not used, all units are used. |
None
|
Returns:
Type | Description |
---|---|
List[Unit]
|
A list of units |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
def filter_units_by_reference_id(...)
¶
Filter unit on their unit_const value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_reference_ids |
List[int]
|
The reference_ids to filter with |
required |
blacklist |
bool
|
Use the given constant list as blacklist instead of whitelist |
False
|
player_list |
List[int]
|
A list of players to filter from. If not used, all players are used. |
None
|
unit_list |
List[Unit]
|
A set of units to filter from. If not used, all units are used. |
None
|
Returns:
Type | Description |
---|---|
List[Unit]
|
A list of units |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
def find_highest_reference_id(...)
¶
Find the highest ID in the map. Searches through all units for the highest ID.
Returns:
Type | Description |
---|---|
int
|
The highest ID in the map |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
361 362 363 364 365 366 367 368 369 370 371 372 |
|
def get_all_units(...)
¶
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
182 183 184 185 186 |
|
def get_new_reference_id(...)
¶
Get a new ID each time the function is called. Starting from the current highest ID.
Returns:
Type | Description |
---|---|
int
|
The newly generated ID |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
352 353 354 355 356 357 358 359 |
|
def get_player_units(...)
¶
Returns a list of UnitObjects for the given player.
Raises:
Type | Description |
---|---|
ValueError
|
If player is not between 0 (GAIA) and 8 (EIGHT) |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
player |
int | PlayerId
|
- | required |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
171 172 173 174 175 176 177 178 179 180 |
|
def get_units_in_area(...)
¶
Returns all units in the square with left corner (x1, y1) and right corner (x2, y2). Both corners inclusive.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x1 |
float
|
The X location of the left corner |
None
|
y1 |
float
|
The Y location of the left corner |
None
|
x2 |
float
|
The X location of the right corner |
None
|
y2 |
float
|
The Y location of the right corner |
None
|
tile1 |
Tile
|
The x,y location of the 1st corner as Tile Object |
None
|
tile2 |
Tile
|
The x,y location of the 2nd corner as Tile Object |
None
|
unit_list |
List[Unit]
|
(Optional) A list of units (Defaults to all units in the map, including GAIA (Trees etc.) |
None
|
players |
List[Union[int, PlayerId]]
|
(Optional) A list of Players which units need to be selected from the selected area |
None
|
ignore_players |
List[PlayerId]
|
(Optional) A list of Players which units need to be ignored from the selected area |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
if not all 4 (x1, y1, x2 and y2) are used simultaneously. Or if both (tile1 and tile2) are not used simultaneously. Or if any of the 4 (x1, y1, x2, y2) is used together with any of (tile1, tile2). Use one or the other. Or if players and ignore_players are used simultaneously. |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
def remove_eye_candy(...)
¶
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
398 399 400 |
|
def remove_unit(...)
¶
Removes a unit. Please note that unit=...
is a lot faster than reference_id=...
due to reference_id having
to search through all units on the map. And unit has an ownership (player) attribute which is used for knowing
which list to remove the unit from.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference_id |
int
|
The id of the unit. Note that this is NOT a unit constant (So NOT: UnitInfo.ARCHER) |
None
|
unit |
Unit
|
The Unit object to be removed. |
None
|
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
def update_unit_player_values(...)
¶
Function to update all player values in all units. Useful when units are moved manually (in mass).
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
53 54 55 56 57 |
|
Functions¶
def create_id_generator(...)
¶
Create generator for increasing value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_id |
int
|
The id to start returning |
required |
Returns:
Type | Description |
---|---|
Generator[int]
|
A generator which will return a +1 ID value for each time called with next. |
Source code in AoE2ScenarioParser/objects/managers/unit_manager.py
416 417 418 419 420 421 422 423 424 425 426 427 428 |
|