[Python] AOE2 parser, tree square question, Python

Discussão em 'Python' iniciado por Stack, Agosto 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently on the python library AOE2 parser and I'm working on a map with the Terrain manager and unit manager https://ksneijders.github.io/AoE2ScenarioParser/api_docs/units/unit_manager_de/?h=unitmana https://ksneijders.github.io/AoE2ScenarioParser/api_docs/map/map_manager/?h=map

    I've managed to a lot of stuff with it : for context current map state and I reach the final part of my project, placing the trees and the limit to separate the green

    in the end I'm looking to have a form like this:result waited
    stone on the side between the water and the land, and trees generated in an empty square

    I know the map tile is calculated from left to right, up map is max_x and min Y and down map is max y and min x which lead that the left is max x and max y:Image from cheatsheet in AOE2 parser guide:https://ksneijders.github.io/AoE2ScenarioParser/cheatsheets/map/

    I use this code to create the trees

    border_X_max= map_manager.map_width
    border_Y_max= map_manager.map_height
    border_X_min = 0 + largeur_eau
    border_Y_min = 0 + largeur_eau
    excluded_terrain = [TerrainId.SNOW,TerrainId.SNOW_LIGHT,TerrainId.ICE,TerrainId.ROCK_1,water_arround_arena,TerrainId.BEACH_ICE]
    for tree_x_coord in range(border_X_min, border_X_max):
    for tree_y_coord in range(border_Y_min, border_Y_max):
    tile = map_manager.get_tile(tree_x_coord, tree_y_coord)
    if tile.terrain_id not in excluded_terrain:
    print(f"Tile ID est {tile_id}")
    print(f"Tree placed in {start_x}")
    placement_x: float = tree_x_coord + 0.5
    placement_y: float = tree_y_coord + 0.5
    stone_head = unit_manager.add_unit(
    player=P0,
    unit_const=OtherInfo.TREE_SNOW_PINE.ID,
    x=placement_x,
    y=placement_y,
    z=0,
    rotation=0,
    animation_frame=0,
    )
    else:
    print(f"Tree isn't placed because terrain is in exception list")


    My idea would be to make some sort a grid like generating all the trees in a singular lane for example from x_something to max Y and does the same for the other side thus making the square but I just cannot figure it out how I am suppose to calculate this as the map generation is extra weird

    Can you help me figure it out, how I'm suppose to handle the whole math aspect of the tree generation ?

    Continue reading...

Compartilhe esta Página