|
| 1 | +# Copyright 2025-2025 the openage authors. See copying.md for legal info. |
| 2 | + |
| 3 | +""" |
| 4 | +nyan conversion routines for researchables (techs). |
| 5 | +""" |
| 6 | +from __future__ import annotations |
| 7 | +import typing |
| 8 | + |
| 9 | +from .....entity_object.conversion.converter_object import RawAPIObject |
| 10 | +from .....service.conversion import internal_name_lookups |
| 11 | +from .....value_object.conversion.forward_ref import ForwardRef |
| 12 | +from .util import get_condition |
| 13 | + |
| 14 | +if typing.TYPE_CHECKING: |
| 15 | + from .....entity_object.conversion.aoc.genie_tech import GenieTechEffectBundleGroup |
| 16 | + |
| 17 | + |
| 18 | +@staticmethod |
| 19 | +def get_researchable_tech(tech_group: GenieTechEffectBundleGroup) -> None: |
| 20 | + """ |
| 21 | + Creates the ResearchableTech object for a Tech. |
| 22 | +
|
| 23 | + :param tech_group: Tech group that is a technology. |
| 24 | + """ |
| 25 | + dataset = tech_group.data |
| 26 | + research_location_id = tech_group.get_research_location_id() |
| 27 | + research_location = dataset.building_lines[research_location_id] |
| 28 | + |
| 29 | + name_lookup_dict = internal_name_lookups.get_entity_lookups(dataset.game_version) |
| 30 | + tech_lookup_dict = internal_name_lookups.get_tech_lookups(dataset.game_version) |
| 31 | + civ_lookup_dict = internal_name_lookups.get_civ_lookups(dataset.game_version) |
| 32 | + |
| 33 | + research_location_name = name_lookup_dict[research_location_id][0] |
| 34 | + tech_name = tech_lookup_dict[tech_group.get_id()][0] |
| 35 | + |
| 36 | + obj_ref = f"{tech_name}.ResearchableTech" |
| 37 | + obj_name = f"{tech_name}Researchable" |
| 38 | + researchable_raw_api_object = RawAPIObject(obj_ref, obj_name, dataset.nyan_api_objects) |
| 39 | + researchable_raw_api_object.add_raw_parent("engine.util.research.ResearchableTech") |
| 40 | + |
| 41 | + # Location of the object depends on whether it'a a unique tech or a normal tech |
| 42 | + if tech_group.is_unique(): |
| 43 | + # Add object to the Civ object |
| 44 | + civ_id = tech_group.get_civilization() |
| 45 | + civ = dataset.civ_groups[civ_id] |
| 46 | + civ_name = civ_lookup_dict[civ_id][0] |
| 47 | + |
| 48 | + researchable_location = ForwardRef(civ, civ_name) |
| 49 | + |
| 50 | + else: |
| 51 | + # Add object to the research location's Research ability |
| 52 | + researchable_location = ForwardRef(research_location, |
| 53 | + f"{research_location_name}.Research") |
| 54 | + |
| 55 | + researchable_raw_api_object.set_location(researchable_location) |
| 56 | + |
| 57 | + # Tech |
| 58 | + tech_forward_ref = ForwardRef(tech_group, tech_name) |
| 59 | + researchable_raw_api_object.add_raw_member("tech", |
| 60 | + tech_forward_ref, |
| 61 | + "engine.util.research.ResearchableTech") |
| 62 | + |
| 63 | + # Cost |
| 64 | + cost_ref = f"{tech_name}.ResearchableTech.{tech_name}Cost" |
| 65 | + cost_raw_api_object = RawAPIObject(cost_ref, |
| 66 | + f"{tech_name}Cost", |
| 67 | + dataset.nyan_api_objects) |
| 68 | + cost_raw_api_object.add_raw_parent("engine.util.cost.type.ResourceCost") |
| 69 | + tech_forward_ref = ForwardRef(tech_group, obj_ref) |
| 70 | + cost_raw_api_object.set_location(tech_forward_ref) |
| 71 | + |
| 72 | + payment_mode = dataset.nyan_api_objects["engine.util.payment_mode.type.Advance"] |
| 73 | + cost_raw_api_object.add_raw_member("payment_mode", |
| 74 | + payment_mode, |
| 75 | + "engine.util.cost.Cost") |
| 76 | + |
| 77 | + cost_amounts = [] |
| 78 | + for resource_amount in tech_group.tech["research_resource_costs"].value: |
| 79 | + resource_id = resource_amount["type_id"].value |
| 80 | + resource = None |
| 81 | + resource_name = "" |
| 82 | + if resource_id == -1: |
| 83 | + # Not a valid resource |
| 84 | + continue |
| 85 | + |
| 86 | + if resource_id == 0: |
| 87 | + resource = dataset.pregen_nyan_objects["util.resource.types.Food"].get_nyan_object() |
| 88 | + resource_name = "Food" |
| 89 | + |
| 90 | + elif resource_id == 1: |
| 91 | + resource = dataset.pregen_nyan_objects["util.resource.types.Wood"].get_nyan_object() |
| 92 | + resource_name = "Wood" |
| 93 | + |
| 94 | + elif resource_id == 2: |
| 95 | + resource = dataset.pregen_nyan_objects["util.resource.types.Stone"].get_nyan_object( |
| 96 | + ) |
| 97 | + resource_name = "Stone" |
| 98 | + |
| 99 | + elif resource_id == 3: |
| 100 | + resource = dataset.pregen_nyan_objects["util.resource.types.Gold"].get_nyan_object() |
| 101 | + resource_name = "Gold" |
| 102 | + |
| 103 | + else: |
| 104 | + # Other resource ids are handled differently |
| 105 | + continue |
| 106 | + |
| 107 | + # Skip resources that are only expected to be there |
| 108 | + if not resource_amount["enabled"].value: |
| 109 | + continue |
| 110 | + |
| 111 | + amount = resource_amount["amount"].value |
| 112 | + |
| 113 | + cost_amount_ref = f"{cost_ref}.{resource_name}Amount" |
| 114 | + cost_amount = RawAPIObject(cost_amount_ref, |
| 115 | + f"{resource_name}Amount", |
| 116 | + dataset.nyan_api_objects) |
| 117 | + cost_amount.add_raw_parent("engine.util.resource.ResourceAmount") |
| 118 | + cost_forward_ref = ForwardRef(tech_group, cost_ref) |
| 119 | + cost_amount.set_location(cost_forward_ref) |
| 120 | + |
| 121 | + cost_amount.add_raw_member("type", |
| 122 | + resource, |
| 123 | + "engine.util.resource.ResourceAmount") |
| 124 | + cost_amount.add_raw_member("amount", |
| 125 | + amount, |
| 126 | + "engine.util.resource.ResourceAmount") |
| 127 | + |
| 128 | + cost_amount_forward_ref = ForwardRef(tech_group, cost_amount_ref) |
| 129 | + cost_amounts.append(cost_amount_forward_ref) |
| 130 | + tech_group.add_raw_api_object(cost_amount) |
| 131 | + |
| 132 | + cost_raw_api_object.add_raw_member("amount", |
| 133 | + cost_amounts, |
| 134 | + "engine.util.cost.type.ResourceCost") |
| 135 | + |
| 136 | + cost_forward_ref = ForwardRef(tech_group, cost_ref) |
| 137 | + researchable_raw_api_object.add_raw_member("cost", |
| 138 | + cost_forward_ref, |
| 139 | + "engine.util.research.ResearchableTech") |
| 140 | + |
| 141 | + research_time = tech_group.tech["research_time"].value |
| 142 | + researchable_raw_api_object.add_raw_member("research_time", |
| 143 | + research_time, |
| 144 | + "engine.util.research.ResearchableTech") |
| 145 | + |
| 146 | + # Create sound object |
| 147 | + sound_ref = f"{tech_name}.ResearchableTech.Sound" |
| 148 | + sound_raw_api_object = RawAPIObject(sound_ref, "ResearchSound", |
| 149 | + dataset.nyan_api_objects) |
| 150 | + sound_raw_api_object.add_raw_parent("engine.util.sound.Sound") |
| 151 | + sound_location = ForwardRef(tech_group, |
| 152 | + f"{tech_name}.ResearchableTech") |
| 153 | + sound_raw_api_object.set_location(sound_location) |
| 154 | + |
| 155 | + # AoE doesn't support sounds here, so this is empty |
| 156 | + sound_raw_api_object.add_raw_member("play_delay", |
| 157 | + 0, |
| 158 | + "engine.util.sound.Sound") |
| 159 | + sound_raw_api_object.add_raw_member("sounds", |
| 160 | + [], |
| 161 | + "engine.util.sound.Sound") |
| 162 | + |
| 163 | + sound_forward_ref = ForwardRef(tech_group, sound_ref) |
| 164 | + researchable_raw_api_object.add_raw_member("research_sounds", |
| 165 | + [sound_forward_ref], |
| 166 | + "engine.util.research.ResearchableTech") |
| 167 | + |
| 168 | + tech_group.add_raw_api_object(sound_raw_api_object) |
| 169 | + |
| 170 | + # Condition |
| 171 | + unlock_conditions = [] |
| 172 | + if tech_group.get_id() > -1: |
| 173 | + unlock_conditions.extend(get_condition(tech_group, |
| 174 | + obj_ref, |
| 175 | + tech_group.get_id(), |
| 176 | + top_level=True)) |
| 177 | + |
| 178 | + researchable_raw_api_object.add_raw_member("condition", |
| 179 | + unlock_conditions, |
| 180 | + "engine.util.research.ResearchableTech") |
| 181 | + |
| 182 | + tech_group.add_raw_api_object(researchable_raw_api_object) |
| 183 | + tech_group.add_raw_api_object(cost_raw_api_object) |
0 commit comments