Skip to content

Commit 5ded36e

Browse files
committed
convert: Refactor AoCCivSubprocessor into separate files.
1 parent 9dbbe24 commit 5ded36e

File tree

11 files changed

+759
-612
lines changed

11 files changed

+759
-612
lines changed

openage/convert/processor/conversion/aoc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ add_py_modules(
1919

2020
add_subdirectory(ability)
2121
add_subdirectory(auxiliary)
22+
add_subdirectory(civ)
2223
add_subdirectory(effect)
2324
add_subdirectory(resistance)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
add_py_modules(
2+
__init__.py
3+
civ_bonus.py
4+
modifiers.py
5+
starting_resources.py
6+
tech_tree.py
7+
unique_techs.py
8+
unique_units.py
9+
util.py
10+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
Creates patches and modifiers for civs.
5+
"""
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
nyan conversion routines for civ bonuses.
5+
"""
6+
from __future__ import annotations
7+
import typing
8+
9+
from ......nyan.nyan_structs import MemberOperator
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+
from ..tech_subprocessor import AoCTechSubprocessor
14+
15+
if typing.TYPE_CHECKING:
16+
from .....entity_object.conversion.aoc.genie_civ import GenieCivilizationGroup
17+
18+
19+
def setup_civ_bonus(civ_group: GenieCivilizationGroup) -> list[ForwardRef]:
20+
"""
21+
Returns global modifiers of a civ.
22+
23+
:param civ_group: Civ group representing an AoC civilization.
24+
"""
25+
patches: list = []
26+
27+
civ_id = civ_group.get_id()
28+
dataset = civ_group.data
29+
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+
civ_name = civ_lookup_dict[civ_id][0]
34+
35+
# key: tech_id; value patched in patches
36+
tech_patches = {}
37+
38+
for civ_bonus in civ_group.civ_boni.values():
39+
if not civ_bonus.replaces_researchable_tech():
40+
bonus_patches = AoCTechSubprocessor.get_patches(civ_bonus)
41+
42+
# civ boni might be unlocked by age ups. if so, patch them into the age up
43+
# patches are queued here
44+
required_tech_count = civ_bonus.tech["required_tech_count"].value
45+
if required_tech_count > 0 and len(bonus_patches) > 0:
46+
if required_tech_count == 1:
47+
tech_id = civ_bonus.tech["required_techs"][0].value
48+
49+
elif required_tech_count == 2:
50+
tech_id = civ_bonus.tech["required_techs"][1].value
51+
52+
if tech_id == 104:
53+
# Skip Dark Age; it is not a tech in openage
54+
patches.extend(bonus_patches)
55+
56+
elif tech_id in tech_patches:
57+
tech_patches[tech_id].extend(bonus_patches)
58+
59+
else:
60+
tech_patches[tech_id] = bonus_patches
61+
62+
else:
63+
patches.extend(bonus_patches)
64+
65+
for tech_id, patches in tech_patches.items():
66+
tech_group = dataset.tech_groups[tech_id]
67+
tech_name = tech_lookup_dict[tech_id][0]
68+
69+
patch_target_ref = f"{tech_name}"
70+
patch_target_forward_ref = ForwardRef(tech_group, patch_target_ref)
71+
72+
# Wrapper
73+
wrapper_name = f"{tech_name}CivBonusWrapper"
74+
wrapper_ref = f"{civ_name}.{wrapper_name}"
75+
wrapper_location = ForwardRef(civ_group, civ_name)
76+
wrapper_raw_api_object = RawAPIObject(wrapper_ref,
77+
wrapper_name,
78+
dataset.nyan_api_objects,
79+
wrapper_location)
80+
wrapper_raw_api_object.add_raw_parent("engine.util.patch.Patch")
81+
82+
# Nyan patch
83+
nyan_patch_name = f"{tech_name}CivBonus"
84+
nyan_patch_ref = f"{civ_name}.{wrapper_name}.{nyan_patch_name}"
85+
nyan_patch_location = ForwardRef(civ_group, wrapper_ref)
86+
nyan_patch_raw_api_object = RawAPIObject(nyan_patch_ref,
87+
nyan_patch_name,
88+
dataset.nyan_api_objects,
89+
nyan_patch_location)
90+
nyan_patch_raw_api_object.add_raw_parent("engine.util.patch.NyanPatch")
91+
nyan_patch_raw_api_object.set_patch_target(patch_target_forward_ref)
92+
93+
nyan_patch_raw_api_object.add_raw_patch_member("updates",
94+
patches,
95+
"engine.util.tech.Tech",
96+
MemberOperator.ADD)
97+
98+
patch_forward_ref = ForwardRef(civ_group, nyan_patch_ref)
99+
wrapper_raw_api_object.add_raw_member("patch",
100+
patch_forward_ref,
101+
"engine.util.patch.Patch")
102+
103+
civ_group.add_raw_api_object(wrapper_raw_api_object)
104+
civ_group.add_raw_api_object(nyan_patch_raw_api_object)
105+
106+
wrapper_forward_ref = ForwardRef(civ_group, wrapper_ref)
107+
patches.append(wrapper_forward_ref)
108+
109+
return patches
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
nyan conversion routines for civ modifiers.
5+
"""
6+
from __future__ import annotations
7+
import typing
8+
9+
from .....value_object.conversion.forward_ref import ForwardRef
10+
11+
if typing.TYPE_CHECKING:
12+
from .....entity_object.conversion.aoc.genie_civ import GenieCivilizationGroup
13+
14+
15+
def get_modifiers(civ_group: GenieCivilizationGroup) -> list[ForwardRef]:
16+
"""
17+
Returns global modifiers of a civ.
18+
19+
:param civ_group: Civ group representing an AoC civilization.
20+
"""
21+
modifiers = []
22+
23+
for civ_bonus in civ_group.civ_boni.values():
24+
if civ_bonus.replaces_researchable_tech():
25+
# TODO: instant tech research modifier
26+
pass
27+
28+
return modifiers
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
nyan conversion routines for civ starting resources.
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+
13+
if typing.TYPE_CHECKING:
14+
from .....entity_object.conversion.aoc.genie_civ import GenieCivilizationGroup
15+
16+
17+
def get_starting_resources(civ_group: GenieCivilizationGroup) -> list[ForwardRef]:
18+
"""
19+
Returns the starting resources of a civ.
20+
21+
:param civ_group: Civ group representing an AoC civilization.
22+
"""
23+
resource_amounts = []
24+
25+
civ_id = civ_group.get_id()
26+
dataset = civ_group.data
27+
28+
civ_lookup_dict = internal_name_lookups.get_civ_lookups(dataset.game_version)
29+
30+
civ_name = civ_lookup_dict[civ_id][0]
31+
32+
# Find starting resource amounts
33+
food_amount = civ_group.civ["resources"][91].value
34+
wood_amount = civ_group.civ["resources"][92].value
35+
gold_amount = civ_group.civ["resources"][93].value
36+
stone_amount = civ_group.civ["resources"][94].value
37+
38+
# Find civ unique starting resources
39+
tech_tree = civ_group.get_tech_tree_effects()
40+
for effect in tech_tree:
41+
type_id = effect.get_type()
42+
43+
if type_id != 1:
44+
continue
45+
46+
resource_id = effect["attr_a"].value
47+
amount = effect["attr_d"].value
48+
if resource_id == 91:
49+
food_amount += amount
50+
51+
elif resource_id == 92:
52+
wood_amount += amount
53+
54+
elif resource_id == 93:
55+
gold_amount += amount
56+
57+
elif resource_id == 94:
58+
stone_amount += amount
59+
60+
food_ref = f"{civ_name}.FoodStartingAmount"
61+
food_raw_api_object = RawAPIObject(food_ref, "FoodStartingAmount",
62+
dataset.nyan_api_objects)
63+
food_raw_api_object.add_raw_parent("engine.util.resource.ResourceAmount")
64+
civ_location = ForwardRef(civ_group, civ_lookup_dict[civ_group.get_id()][0])
65+
food_raw_api_object.set_location(civ_location)
66+
67+
resource = dataset.pregen_nyan_objects["util.resource.types.Food"].get_nyan_object()
68+
food_raw_api_object.add_raw_member("type",
69+
resource,
70+
"engine.util.resource.ResourceAmount")
71+
72+
food_raw_api_object.add_raw_member("amount",
73+
food_amount,
74+
"engine.util.resource.ResourceAmount")
75+
76+
food_forward_ref = ForwardRef(civ_group, food_ref)
77+
resource_amounts.append(food_forward_ref)
78+
79+
wood_ref = f"{civ_name}.WoodStartingAmount"
80+
wood_raw_api_object = RawAPIObject(wood_ref, "WoodStartingAmount",
81+
dataset.nyan_api_objects)
82+
wood_raw_api_object.add_raw_parent("engine.util.resource.ResourceAmount")
83+
civ_location = ForwardRef(civ_group, civ_lookup_dict[civ_group.get_id()][0])
84+
wood_raw_api_object.set_location(civ_location)
85+
86+
resource = dataset.pregen_nyan_objects["util.resource.types.Wood"].get_nyan_object()
87+
wood_raw_api_object.add_raw_member("type",
88+
resource,
89+
"engine.util.resource.ResourceAmount")
90+
91+
wood_raw_api_object.add_raw_member("amount",
92+
wood_amount,
93+
"engine.util.resource.ResourceAmount")
94+
95+
wood_forward_ref = ForwardRef(civ_group, wood_ref)
96+
resource_amounts.append(wood_forward_ref)
97+
98+
gold_ref = f"{civ_name}.GoldStartingAmount"
99+
gold_raw_api_object = RawAPIObject(gold_ref, "GoldStartingAmount",
100+
dataset.nyan_api_objects)
101+
gold_raw_api_object.add_raw_parent("engine.util.resource.ResourceAmount")
102+
civ_location = ForwardRef(civ_group, civ_lookup_dict[civ_group.get_id()][0])
103+
gold_raw_api_object.set_location(civ_location)
104+
105+
resource = dataset.pregen_nyan_objects["util.resource.types.Gold"].get_nyan_object()
106+
gold_raw_api_object.add_raw_member("type",
107+
resource,
108+
"engine.util.resource.ResourceAmount")
109+
110+
gold_raw_api_object.add_raw_member("amount",
111+
gold_amount,
112+
"engine.util.resource.ResourceAmount")
113+
114+
gold_forward_ref = ForwardRef(civ_group, gold_ref)
115+
resource_amounts.append(gold_forward_ref)
116+
117+
stone_ref = f"{civ_name}.StoneStartingAmount"
118+
stone_raw_api_object = RawAPIObject(stone_ref, "StoneStartingAmount",
119+
dataset.nyan_api_objects)
120+
stone_raw_api_object.add_raw_parent("engine.util.resource.ResourceAmount")
121+
civ_location = ForwardRef(civ_group, civ_lookup_dict[civ_group.get_id()][0])
122+
stone_raw_api_object.set_location(civ_location)
123+
124+
resource = dataset.pregen_nyan_objects["util.resource.types.Stone"].get_nyan_object()
125+
stone_raw_api_object.add_raw_member("type",
126+
resource,
127+
"engine.util.resource.ResourceAmount")
128+
129+
stone_raw_api_object.add_raw_member("amount",
130+
stone_amount,
131+
"engine.util.resource.ResourceAmount")
132+
133+
stone_forward_ref = ForwardRef(civ_group, stone_ref)
134+
resource_amounts.append(stone_forward_ref)
135+
136+
civ_group.add_raw_api_object(food_raw_api_object)
137+
civ_group.add_raw_api_object(wood_raw_api_object)
138+
civ_group.add_raw_api_object(gold_raw_api_object)
139+
civ_group.add_raw_api_object(stone_raw_api_object)
140+
141+
return resource_amounts

0 commit comments

Comments
 (0)