|
| 1 | +# Copyright 2025-2025 the openage authors. See copying.md for legal info. |
| 2 | + |
| 3 | +""" |
| 4 | +Creates upgrade patches for crabon cost amounts in SWGB. |
| 5 | +""" |
| 6 | +from __future__ import annotations |
| 7 | +import typing |
| 8 | + |
| 9 | +from .....entity_object.conversion.aoc.genie_tech import GenieTechEffectBundleGroup |
| 10 | +from .....entity_object.conversion.converter_object import RawAPIObject |
| 11 | +from .....service.conversion import internal_name_lookups |
| 12 | +from .....value_object.conversion.forward_ref import ForwardRef |
| 13 | + |
| 14 | +if typing.TYPE_CHECKING: |
| 15 | + from .....entity_object.conversion.converter_object import ConverterObjectGroup |
| 16 | + from .....entity_object.conversion.aoc.genie_unit import GenieGameEntityGroup |
| 17 | + from ......nyan.nyan_structs import MemberOperator |
| 18 | + |
| 19 | + |
| 20 | +def cost_carbon_upgrade( |
| 21 | + converter_group: ConverterObjectGroup, |
| 22 | + line: GenieGameEntityGroup, |
| 23 | + value: typing.Union[int, float], |
| 24 | + operator: MemberOperator, |
| 25 | + team: bool = False |
| 26 | +) -> list[ForwardRef]: |
| 27 | + """ |
| 28 | + Creates a patch for the carbon cost modify effect (ID: 104). |
| 29 | +
|
| 30 | + :param converter_group: Tech/Civ that gets the patch. |
| 31 | + :param line: Unit/Building line that has the ability. |
| 32 | + :param value: Value used for patching the member. |
| 33 | + :param operator: Operator used for patching the member. |
| 34 | + :returns: The forward references for the generated patches. |
| 35 | + """ |
| 36 | + head_unit_id = line.get_head_unit_id() |
| 37 | + dataset = line.data |
| 38 | + |
| 39 | + patches = [] |
| 40 | + |
| 41 | + obj_id = converter_group.get_id() |
| 42 | + if isinstance(converter_group, GenieTechEffectBundleGroup): |
| 43 | + tech_lookup_dict = internal_name_lookups.get_tech_lookups(dataset.game_version) |
| 44 | + obj_name = tech_lookup_dict[obj_id][0] |
| 45 | + |
| 46 | + else: |
| 47 | + civ_lookup_dict = internal_name_lookups.get_civ_lookups(dataset.game_version) |
| 48 | + obj_name = civ_lookup_dict[obj_id][0] |
| 49 | + |
| 50 | + name_lookup_dict = internal_name_lookups.get_entity_lookups(dataset.game_version) |
| 51 | + |
| 52 | + game_entity_name = name_lookup_dict[head_unit_id][0] |
| 53 | + |
| 54 | + patch_target_ref = (f"{game_entity_name}.CreatableGameEntity." |
| 55 | + f"{game_entity_name}Cost.CarbonAmount") |
| 56 | + patch_target_forward_ref = ForwardRef(line, patch_target_ref) |
| 57 | + |
| 58 | + # Wrapper |
| 59 | + wrapper_name = f"Change{game_entity_name}CarbonCostWrapper" |
| 60 | + wrapper_ref = f"{obj_name}.{wrapper_name}" |
| 61 | + wrapper_location = ForwardRef(converter_group, obj_name) |
| 62 | + wrapper_raw_api_object = RawAPIObject(wrapper_ref, |
| 63 | + wrapper_name, |
| 64 | + dataset.nyan_api_objects, |
| 65 | + wrapper_location) |
| 66 | + wrapper_raw_api_object.add_raw_parent("engine.util.patch.Patch") |
| 67 | + |
| 68 | + # Nyan patch |
| 69 | + nyan_patch_name = f"Change{game_entity_name}CarbonCost" |
| 70 | + nyan_patch_ref = f"{obj_name}.{wrapper_name}.{nyan_patch_name}" |
| 71 | + nyan_patch_location = ForwardRef(converter_group, wrapper_ref) |
| 72 | + nyan_patch_raw_api_object = RawAPIObject(nyan_patch_ref, |
| 73 | + nyan_patch_name, |
| 74 | + dataset.nyan_api_objects, |
| 75 | + nyan_patch_location) |
| 76 | + nyan_patch_raw_api_object.add_raw_parent("engine.util.patch.NyanPatch") |
| 77 | + nyan_patch_raw_api_object.set_patch_target(patch_target_forward_ref) |
| 78 | + |
| 79 | + nyan_patch_raw_api_object.add_raw_patch_member("amount", |
| 80 | + value, |
| 81 | + "engine.util.resource.ResourceAmount", |
| 82 | + operator) |
| 83 | + |
| 84 | + patch_forward_ref = ForwardRef(converter_group, nyan_patch_ref) |
| 85 | + wrapper_raw_api_object.add_raw_member("patch", |
| 86 | + patch_forward_ref, |
| 87 | + "engine.util.patch.Patch") |
| 88 | + |
| 89 | + if team: |
| 90 | + team_property = dataset.pregen_nyan_objects["util.patch.property.types.Team"].get_nyan_object( |
| 91 | + ) |
| 92 | + properties = { |
| 93 | + dataset.nyan_api_objects["engine.util.patch.property.type.Diplomatic"]: team_property |
| 94 | + } |
| 95 | + wrapper_raw_api_object.add_raw_member("properties", |
| 96 | + properties, |
| 97 | + "engine.util.patch.Patch") |
| 98 | + |
| 99 | + converter_group.add_raw_api_object(wrapper_raw_api_object) |
| 100 | + converter_group.add_raw_api_object(nyan_patch_raw_api_object) |
| 101 | + |
| 102 | + wrapper_forward_ref = ForwardRef(converter_group, wrapper_ref) |
| 103 | + patches.append(wrapper_forward_ref) |
| 104 | + |
| 105 | + return patches |
0 commit comments