Skip to content

Commit 72440be

Browse files
committed
convert: Refactor AoCModifierSubprocessor into separate files.
1 parent 8de72a4 commit 72440be

File tree

9 files changed

+252
-205
lines changed

9 files changed

+252
-205
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ add_subdirectory(auxiliary)
2222
add_subdirectory(civ)
2323
add_subdirectory(effect)
2424
add_subdirectory(media)
25+
add_subdirectory(modifier)
2526
add_subdirectory(resistance)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
22

33
"""
4-
Derives and adds abilities to game entities created from lines. Subroutine of the
5-
nyan subprocessor.
4+
Derives and adds abilities to game entities created from lines.
65
"""
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
add_py_modules(
2+
__init__.py
3+
elevation_attack.py
4+
flyover_effect.py
5+
gather_rate.py
6+
move_speed.py
7+
)
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+
Derives and adds modifiers to lines or civ groups.
5+
"""
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
nyan conversion routines for the ElevationAttack modifier.
5+
"""
6+
from __future__ import annotations
7+
import typing
8+
9+
if typing.TYPE_CHECKING:
10+
from ......nyan.nyan_structs import NyanObject
11+
from .....entity_object.conversion.aoc.genie_unit import GenieGameEntityGroup
12+
13+
14+
def elevation_attack_modifiers(converter_obj_group: GenieGameEntityGroup) -> list[NyanObject]:
15+
"""
16+
Adds the pregenerated elevation damage multipliers to a line or civ group.
17+
18+
:param converter_obj_group: ConverterObjectGroup that gets the modifier.
19+
:returns: The forward references for the modifier.
20+
"""
21+
dataset = converter_obj_group.data
22+
modifiers = [
23+
dataset.pregen_nyan_objects[
24+
"util.modifier.elevation_difference.AttackHigh"
25+
].get_nyan_object(),
26+
dataset.pregen_nyan_objects[
27+
"util.modifier.elevation_difference.AttackLow"
28+
].get_nyan_object()
29+
]
30+
31+
return modifiers
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
nyan conversion routines for the FlyoverEffect modifier.
5+
"""
6+
from __future__ import annotations
7+
import typing
8+
9+
if typing.TYPE_CHECKING:
10+
from ......nyan.nyan_structs import NyanObject
11+
from .....entity_object.conversion.aoc.genie_unit import GenieGameEntityGroup
12+
13+
14+
def flyover_effect_modifier(converter_obj_group: GenieGameEntityGroup) -> NyanObject:
15+
"""
16+
Adds the pregenerated fly-over-cliff damage multiplier to a line or civ group.
17+
18+
:param converter_obj_group: ConverterObjectGroup that gets the modifier.
19+
:returns: The forward reference for the modifier.
20+
"""
21+
dataset = converter_obj_group.data
22+
modifier = dataset.pregen_nyan_objects[
23+
"util.modifier.flyover_cliff.AttackFlyover"
24+
].get_nyan_object()
25+
26+
return modifier
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
nyan conversion routines for the GatherRate modifier.
5+
"""
6+
7+
from .....entity_object.conversion.aoc.genie_unit import GenieGameEntityGroup, \
8+
GenieBuildingLineGroup, GenieVillagerGroup, GenieAmbientGroup, GenieVariantGroup
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+
14+
def gather_rate_modifier(converter_obj_group: GenieGameEntityGroup) -> list[ForwardRef]:
15+
"""
16+
Adds Gather modifiers to a line or civ group.
17+
18+
:param converter_obj_group: ConverterObjectGroup that gets the modifier.
19+
:returns: The forward reference for the modifier.
20+
"""
21+
dataset = converter_obj_group.data
22+
23+
modifiers = []
24+
25+
if isinstance(converter_obj_group, GenieGameEntityGroup):
26+
if isinstance(converter_obj_group, GenieVillagerGroup):
27+
gatherers = converter_obj_group.variants[0].line
28+
29+
else:
30+
gatherers = [converter_obj_group.line[0]]
31+
32+
head_unit_id = converter_obj_group.get_head_unit_id()
33+
34+
name_lookup_dict = internal_name_lookups.get_entity_lookups(dataset.game_version)
35+
36+
target_obj_name = name_lookup_dict[head_unit_id][0]
37+
38+
for gatherer in gatherers:
39+
unit_commands = gatherer["unit_commands"].value
40+
41+
for command in unit_commands:
42+
# Find a gather ability.
43+
type_id = command["type"].value
44+
45+
gather_task_ids = internal_name_lookups.get_gather_lookups(
46+
dataset.game_version).keys()
47+
if type_id not in gather_task_ids:
48+
continue
49+
50+
work_value = command["work_value1"].value
51+
52+
# Check if the work value is 1 (with some rounding error margin)
53+
# if not, we have to create a modifier
54+
if 0.9999 < work_value < 1.0001:
55+
continue
56+
57+
# Search for the lines with the matching class/unit id
58+
class_id = command["class_id"].value
59+
unit_id = command["unit_id"].value
60+
61+
entity_lines = {}
62+
entity_lines.update(dataset.unit_lines)
63+
entity_lines.update(dataset.building_lines)
64+
entity_lines.update(dataset.ambient_groups)
65+
entity_lines.update(dataset.variant_groups)
66+
67+
if unit_id != -1:
68+
lines = [entity_lines[unit_id]]
69+
70+
elif class_id != -1:
71+
lines = []
72+
for line in entity_lines.values():
73+
if line.get_class_id() == class_id:
74+
lines.append(line)
75+
76+
else:
77+
raise ValueError("Gather task has no valid target ID.")
78+
79+
# Create a modifier for each matching resource spot
80+
for resource_line in lines:
81+
head_unit_id = resource_line.get_head_unit_id()
82+
if isinstance(resource_line, GenieBuildingLineGroup):
83+
resource_line_name = name_lookup_dict[head_unit_id][0]
84+
85+
elif isinstance(resource_line, GenieAmbientGroup):
86+
resource_line_name = name_lookup_dict[head_unit_id][0]
87+
88+
elif isinstance(resource_line, GenieVariantGroup):
89+
resource_line_name = name_lookup_dict[head_unit_id][1]
90+
91+
modifier_ref = f"{target_obj_name}.{resource_line_name}GatheringRate"
92+
modifier_raw_api_object = RawAPIObject(modifier_ref,
93+
"%sGatheringRate",
94+
dataset.nyan_api_objects)
95+
modifier_raw_api_object.add_raw_parent(
96+
"engine.modifier.multiplier.type.GatheringRate")
97+
modifier_location = ForwardRef(converter_obj_group, target_obj_name)
98+
modifier_raw_api_object.set_location(modifier_location)
99+
100+
# Multiplier
101+
modifier_raw_api_object.add_raw_member(
102+
"multiplier",
103+
work_value,
104+
"engine.modifier.multiplier.MultiplierModifier"
105+
)
106+
107+
# Resource spot
108+
spot_ref = (f"{resource_line_name}.Harvestable."
109+
f"{resource_line_name}ResourceSpot")
110+
spot_forward_ref = ForwardRef(resource_line, spot_ref)
111+
modifier_raw_api_object.add_raw_member(
112+
"resource_spot",
113+
spot_forward_ref,
114+
"engine.modifier.multiplier.type.GatheringRate"
115+
)
116+
117+
converter_obj_group.add_raw_api_object(modifier_raw_api_object)
118+
modifier_forward_ref = ForwardRef(converter_obj_group,
119+
modifier_raw_api_object.get_id())
120+
modifiers.append(modifier_forward_ref)
121+
122+
return modifiers
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
nyan conversion routines for the MoveSpeed modifier.
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_unit import GenieGameEntityGroup
15+
16+
17+
def move_speed_modifier(converter_obj_group: GenieGameEntityGroup, value: float) -> ForwardRef:
18+
"""
19+
Adds a MoveSpeed modifier to a line or civ group.
20+
21+
:param converter_obj_group: ConverterObjectGroup that gets the modifier.
22+
:returns: The forward reference for the modifier.
23+
"""
24+
dataset = converter_obj_group.data
25+
if isinstance(converter_obj_group, GenieGameEntityGroup):
26+
head_unit_id = converter_obj_group.get_head_unit_id()
27+
name_lookup_dict = internal_name_lookups.get_entity_lookups(dataset.game_version)
28+
target_obj_name = name_lookup_dict[head_unit_id][0]
29+
30+
else:
31+
# Civs
32+
civ_lookup_dict = internal_name_lookups.get_civ_lookups(dataset.game_version)
33+
target_obj_name = civ_lookup_dict[converter_obj_group.get_id()][0]
34+
35+
modifier_ref = f"{target_obj_name}.MoveSpeed"
36+
modifier_raw_api_object = RawAPIObject(modifier_ref, "MoveSpeed", dataset.nyan_api_objects)
37+
modifier_raw_api_object.add_raw_parent("engine.modifier.multiplier.type.MoveSpeed")
38+
modifier_location = ForwardRef(converter_obj_group, target_obj_name)
39+
modifier_raw_api_object.set_location(modifier_location)
40+
41+
modifier_raw_api_object.add_raw_member("multiplier",
42+
value,
43+
"engine.modifier.multiplier.MultiplierModifier")
44+
45+
converter_obj_group.add_raw_api_object(modifier_raw_api_object)
46+
47+
modifier_forward_ref = ForwardRef(converter_obj_group, modifier_raw_api_object.get_id())
48+
49+
return modifier_forward_ref

0 commit comments

Comments
 (0)