|
| 1 | +# Copyright 2025-2025 the openage authors. See copying.md for legal info. |
| 2 | + |
| 3 | +""" |
| 4 | +Creates upgrade patches for building conversion in SWBG. |
| 5 | +""" |
| 6 | +from __future__ import annotations |
| 7 | +import typing |
| 8 | + |
| 9 | +from ......nyan.nyan_structs import MemberOperator |
| 10 | +from .....entity_object.conversion.aoc.genie_tech import GenieTechEffectBundleGroup |
| 11 | +from .....entity_object.conversion.converter_object import RawAPIObject |
| 12 | +from .....service.conversion import internal_name_lookups |
| 13 | +from .....value_object.conversion.forward_ref import ForwardRef |
| 14 | + |
| 15 | +if typing.TYPE_CHECKING: |
| 16 | + from .....entity_object.conversion.converter_object import ConverterObjectGroup |
| 17 | + |
| 18 | + |
| 19 | +def convert_building_upgrade( |
| 20 | + converter_group: ConverterObjectGroup, |
| 21 | + value: typing.Any, |
| 22 | + operator: MemberOperator, |
| 23 | + team: bool = False |
| 24 | +) -> list[ForwardRef]: |
| 25 | + """ |
| 26 | + Creates a patch for the building conversion effect (ID: 28). |
| 27 | +
|
| 28 | + :param converter_group: Tech/Civ that gets the patch. |
| 29 | + :param value: Value used for patching the member. |
| 30 | + :param operator: Operator used for patching the member. |
| 31 | + :returns: The forward references for the generated patches. |
| 32 | + """ |
| 33 | + force_ids = [115, 180] |
| 34 | + dataset = converter_group.data |
| 35 | + |
| 36 | + patches = [] |
| 37 | + |
| 38 | + for force_id in force_ids: |
| 39 | + line = dataset.unit_lines[force_id] |
| 40 | + |
| 41 | + name_lookup_dict = internal_name_lookups.get_entity_lookups(dataset.game_version) |
| 42 | + |
| 43 | + obj_id = converter_group.get_id() |
| 44 | + if isinstance(converter_group, GenieTechEffectBundleGroup): |
| 45 | + tech_lookup_dict = internal_name_lookups.get_tech_lookups(dataset.game_version) |
| 46 | + obj_name = tech_lookup_dict[obj_id][0] |
| 47 | + |
| 48 | + else: |
| 49 | + civ_lookup_dict = internal_name_lookups.get_civ_lookups(dataset.game_version) |
| 50 | + obj_name = civ_lookup_dict[obj_id][0] |
| 51 | + |
| 52 | + game_entity_name = name_lookup_dict[force_id][0] |
| 53 | + |
| 54 | + patch_target_ref = f"{game_entity_name}.Convert" |
| 55 | + patch_target_forward_ref = ForwardRef(line, patch_target_ref) |
| 56 | + |
| 57 | + # Building conversion |
| 58 | + |
| 59 | + # Wrapper |
| 60 | + wrapper_name = "EnableBuildingConversionWrapper" |
| 61 | + wrapper_ref = f"{obj_name}.{wrapper_name}" |
| 62 | + wrapper_location = ForwardRef(converter_group, obj_name) |
| 63 | + wrapper_raw_api_object = RawAPIObject(wrapper_ref, |
| 64 | + wrapper_name, |
| 65 | + dataset.nyan_api_objects, |
| 66 | + wrapper_location) |
| 67 | + wrapper_raw_api_object.add_raw_parent("engine.util.patch.Patch") |
| 68 | + |
| 69 | + # Nyan patch |
| 70 | + nyan_patch_name = "EnableBuildingConversion" |
| 71 | + nyan_patch_ref = f"{obj_name}.{wrapper_name}.{nyan_patch_name}" |
| 72 | + nyan_patch_location = ForwardRef(converter_group, wrapper_ref) |
| 73 | + nyan_patch_raw_api_object = RawAPIObject(nyan_patch_ref, |
| 74 | + nyan_patch_name, |
| 75 | + dataset.nyan_api_objects, |
| 76 | + nyan_patch_location) |
| 77 | + nyan_patch_raw_api_object.add_raw_parent("engine.util.patch.NyanPatch") |
| 78 | + nyan_patch_raw_api_object.set_patch_target(patch_target_forward_ref) |
| 79 | + |
| 80 | + # New allowed types |
| 81 | + allowed_types = [ |
| 82 | + dataset.pregen_nyan_objects["util.game_entity_type.types.Building"].get_nyan_object( |
| 83 | + ) |
| 84 | + ] |
| 85 | + nyan_patch_raw_api_object.add_raw_patch_member("allowed_types", |
| 86 | + allowed_types, |
| 87 | + "engine.ability.type.ApplyDiscreteEffect", |
| 88 | + MemberOperator.ADD) |
| 89 | + |
| 90 | + # Blacklisted buildings |
| 91 | + tc_line = dataset.building_lines[109] |
| 92 | + farm_line = dataset.building_lines[50] |
| 93 | + temple_line = dataset.building_lines[104] |
| 94 | + wonder_line = dataset.building_lines[276] |
| 95 | + |
| 96 | + blacklisted_forward_refs = [ForwardRef(tc_line, "CommandCenter"), |
| 97 | + ForwardRef(farm_line, "Farm"), |
| 98 | + ForwardRef(temple_line, "Temple"), |
| 99 | + ForwardRef(wonder_line, "Monument"), |
| 100 | + ] |
| 101 | + nyan_patch_raw_api_object.add_raw_patch_member("blacklisted_entities", |
| 102 | + blacklisted_forward_refs, |
| 103 | + "engine.ability.type.ApplyDiscreteEffect", |
| 104 | + MemberOperator.ADD) |
| 105 | + |
| 106 | + patch_forward_ref = ForwardRef(converter_group, nyan_patch_ref) |
| 107 | + wrapper_raw_api_object.add_raw_member("patch", |
| 108 | + patch_forward_ref, |
| 109 | + "engine.util.patch.Patch") |
| 110 | + |
| 111 | + converter_group.add_raw_api_object(wrapper_raw_api_object) |
| 112 | + converter_group.add_raw_api_object(nyan_patch_raw_api_object) |
| 113 | + |
| 114 | + wrapper_forward_ref = ForwardRef(converter_group, wrapper_ref) |
| 115 | + patches.append(wrapper_forward_ref) |
| 116 | + |
| 117 | + return patches |
0 commit comments