|
| 1 | +# Copyright 2025-2025 the openage authors. See copying.md for legal info. |
| 2 | + |
| 3 | +""" |
| 4 | +Convert building lines to openage game entities. |
| 5 | +""" |
| 6 | +from __future__ import annotations |
| 7 | +import typing |
| 8 | + |
| 9 | +from .....entity_object.conversion.aoc.genie_unit import GenieGarrisonMode |
| 10 | +from .....entity_object.conversion.converter_object import RawAPIObject |
| 11 | +from .....service.conversion import internal_name_lookups |
| 12 | +from ..ability_subprocessor import AoCAbilitySubprocessor |
| 13 | +from ..auxiliary_subprocessor import AoCAuxiliarySubprocessor |
| 14 | +from .projectile import projectiles_from_line |
| 15 | + |
| 16 | +if typing.TYPE_CHECKING: |
| 17 | + from .....entity_object.conversion.aoc.genie_unit import GenieBuildingLineGroup |
| 18 | + |
| 19 | + |
| 20 | +def building_line_to_game_entity(building_line: GenieBuildingLineGroup) -> None: |
| 21 | + """ |
| 22 | + Creates raw API objects for a building line. |
| 23 | +
|
| 24 | + :param building_line: Building line that gets converted to a game entity. |
| 25 | + :type building_line: ..dataformat.converter_object.ConverterObjectGroup |
| 26 | + """ |
| 27 | + current_building = building_line.line[0] |
| 28 | + current_building_id = building_line.get_head_unit_id() |
| 29 | + dataset = building_line.data |
| 30 | + |
| 31 | + name_lookup_dict = internal_name_lookups.get_entity_lookups(dataset.game_version) |
| 32 | + class_lookup_dict = internal_name_lookups.get_class_lookups(dataset.game_version) |
| 33 | + |
| 34 | + # Start with the generic GameEntity |
| 35 | + game_entity_name = name_lookup_dict[current_building_id][0] |
| 36 | + obj_location = f"data/game_entity/generic/{name_lookup_dict[current_building_id][1]}/" |
| 37 | + raw_api_object = RawAPIObject(game_entity_name, game_entity_name, |
| 38 | + dataset.nyan_api_objects) |
| 39 | + raw_api_object.add_raw_parent("engine.util.game_entity.GameEntity") |
| 40 | + raw_api_object.set_location(obj_location) |
| 41 | + raw_api_object.set_filename(name_lookup_dict[current_building_id][1]) |
| 42 | + building_line.add_raw_api_object(raw_api_object) |
| 43 | + |
| 44 | + # ======================================================================= |
| 45 | + # Game Entity Types |
| 46 | + # ======================================================================= |
| 47 | + # we give a building two types |
| 48 | + # - util.game_entity_type.types.Building (if unit_type >= 80) |
| 49 | + # - util.game_entity_type.types.<Class> (depending on the class) |
| 50 | + # and additionally |
| 51 | + # - util.game_entity_type.types.DropSite (only if this is used as a drop site) |
| 52 | + # ======================================================================= |
| 53 | + # Create or use existing auxiliary types |
| 54 | + types_set = [] |
| 55 | + unit_type = current_building["unit_type"].value |
| 56 | + |
| 57 | + if unit_type >= 80: |
| 58 | + type_obj = dataset.pregen_nyan_objects[ |
| 59 | + "util.game_entity_type.types.Building" |
| 60 | + ].get_nyan_object() |
| 61 | + types_set.append(type_obj) |
| 62 | + |
| 63 | + unit_class = current_building["unit_class"].value |
| 64 | + class_name = class_lookup_dict[unit_class] |
| 65 | + class_obj_name = f"util.game_entity_type.types.{class_name}" |
| 66 | + type_obj = dataset.pregen_nyan_objects[class_obj_name].get_nyan_object() |
| 67 | + types_set.append(type_obj) |
| 68 | + |
| 69 | + if building_line.is_dropsite(): |
| 70 | + type_obj = dataset.pregen_nyan_objects[ |
| 71 | + "util.game_entity_type.types.DropSite" |
| 72 | + ].get_nyan_object() |
| 73 | + types_set.append(type_obj) |
| 74 | + |
| 75 | + raw_api_object.add_raw_member("types", types_set, "engine.util.game_entity.GameEntity") |
| 76 | + |
| 77 | + # ======================================================================= |
| 78 | + # Abilities |
| 79 | + # ======================================================================= |
| 80 | + abilities_set = [] |
| 81 | + |
| 82 | + abilities_set.append(AoCAbilitySubprocessor.attribute_change_tracker_ability(building_line)) |
| 83 | + abilities_set.append(AoCAbilitySubprocessor.death_ability(building_line)) |
| 84 | + abilities_set.append(AoCAbilitySubprocessor.delete_ability(building_line)) |
| 85 | + abilities_set.append(AoCAbilitySubprocessor.despawn_ability(building_line)) |
| 86 | + abilities_set.append(AoCAbilitySubprocessor.idle_ability(building_line)) |
| 87 | + abilities_set.append(AoCAbilitySubprocessor.collision_ability(building_line)) |
| 88 | + abilities_set.append(AoCAbilitySubprocessor.live_ability(building_line)) |
| 89 | + abilities_set.append(AoCAbilitySubprocessor.los_ability(building_line)) |
| 90 | + abilities_set.append(AoCAbilitySubprocessor.named_ability(building_line)) |
| 91 | + abilities_set.append(AoCAbilitySubprocessor.resistance_ability(building_line)) |
| 92 | + abilities_set.extend(AoCAbilitySubprocessor.selectable_ability(building_line)) |
| 93 | + abilities_set.append(AoCAbilitySubprocessor.stop_ability(building_line)) |
| 94 | + abilities_set.append(AoCAbilitySubprocessor.terrain_requirement_ability(building_line)) |
| 95 | + abilities_set.append(AoCAbilitySubprocessor.visibility_ability(building_line)) |
| 96 | + |
| 97 | + # Config abilities |
| 98 | + if building_line.is_creatable(): |
| 99 | + abilities_set.append(AoCAbilitySubprocessor.constructable_ability(building_line)) |
| 100 | + |
| 101 | + if not building_line.is_passable(): |
| 102 | + abilities_set.append(AoCAbilitySubprocessor.pathable_ability(building_line)) |
| 103 | + |
| 104 | + if building_line.has_foundation(): |
| 105 | + if building_line.get_class_id() == 49: |
| 106 | + # Use OverlayTerrain for the farm terrain |
| 107 | + abilities_set.append(AoCAbilitySubprocessor.overlay_terrain_ability(building_line)) |
| 108 | + abilities_set.append(AoCAbilitySubprocessor.foundation_ability(building_line, |
| 109 | + terrain_id=27)) |
| 110 | + |
| 111 | + else: |
| 112 | + abilities_set.append(AoCAbilitySubprocessor.foundation_ability(building_line)) |
| 113 | + |
| 114 | + # Creation/Research abilities |
| 115 | + if len(building_line.creates) > 0: |
| 116 | + abilities_set.append(AoCAbilitySubprocessor.create_ability(building_line)) |
| 117 | + abilities_set.append(AoCAbilitySubprocessor.production_queue_ability(building_line)) |
| 118 | + |
| 119 | + if len(building_line.researches) > 0: |
| 120 | + abilities_set.append(AoCAbilitySubprocessor.research_ability(building_line)) |
| 121 | + |
| 122 | + # Effect abilities |
| 123 | + if building_line.is_projectile_shooter(): |
| 124 | + abilities_set.append(AoCAbilitySubprocessor.shoot_projectile_ability(building_line, 7)) |
| 125 | + abilities_set.append(AoCAbilitySubprocessor.game_entity_stance_ability(building_line)) |
| 126 | + projectiles_from_line(building_line) |
| 127 | + |
| 128 | + # Storage abilities |
| 129 | + if building_line.is_garrison(): |
| 130 | + abilities_set.append(AoCAbilitySubprocessor.storage_ability(building_line)) |
| 131 | + abilities_set.append(AoCAbilitySubprocessor.remove_storage_ability(building_line)) |
| 132 | + |
| 133 | + garrison_mode = building_line.get_garrison_mode() |
| 134 | + |
| 135 | + if garrison_mode == GenieGarrisonMode.NATURAL: |
| 136 | + abilities_set.append( |
| 137 | + AoCAbilitySubprocessor.send_back_to_task_ability(building_line)) |
| 138 | + |
| 139 | + if garrison_mode in (GenieGarrisonMode.NATURAL, GenieGarrisonMode.SELF_PRODUCED): |
| 140 | + abilities_set.append(AoCAbilitySubprocessor.rally_point_ability(building_line)) |
| 141 | + |
| 142 | + # Resource abilities |
| 143 | + if building_line.is_harvestable(): |
| 144 | + abilities_set.append(AoCAbilitySubprocessor.harvestable_ability(building_line)) |
| 145 | + |
| 146 | + if building_line.is_dropsite(): |
| 147 | + abilities_set.append(AoCAbilitySubprocessor.drop_site_ability(building_line)) |
| 148 | + |
| 149 | + ability = AoCAbilitySubprocessor.provide_contingent_ability(building_line) |
| 150 | + if ability: |
| 151 | + abilities_set.append(ability) |
| 152 | + |
| 153 | + # Trade abilities |
| 154 | + if building_line.is_trade_post(): |
| 155 | + abilities_set.append(AoCAbilitySubprocessor.trade_post_ability(building_line)) |
| 156 | + |
| 157 | + if building_line.get_id() == 84: |
| 158 | + # Market trading |
| 159 | + abilities_set.extend(AoCAbilitySubprocessor.exchange_resources_ability(building_line)) |
| 160 | + |
| 161 | + raw_api_object.add_raw_member("abilities", abilities_set, |
| 162 | + "engine.util.game_entity.GameEntity") |
| 163 | + |
| 164 | + # ======================================================================= |
| 165 | + # Modifiers |
| 166 | + # ======================================================================= |
| 167 | + raw_api_object.add_raw_member("modifiers", [], "engine.util.game_entity.GameEntity") |
| 168 | + |
| 169 | + # ======================================================================= |
| 170 | + # TODO: Variants |
| 171 | + # ======================================================================= |
| 172 | + raw_api_object.add_raw_member("variants", [], "engine.util.game_entity.GameEntity") |
| 173 | + |
| 174 | + # ======================================================================= |
| 175 | + # Misc (Objects that are not used by the unit line itself, but use its values) |
| 176 | + # ======================================================================= |
| 177 | + if building_line.is_creatable(): |
| 178 | + AoCAuxiliarySubprocessor.get_creatable_game_entity(building_line) |
0 commit comments