Skip to content

Commit bf4d445

Browse files
committed
convert: Refactor SWBGCCUpgradeResourceSubprocessor into separate files.
1 parent 9e3d52f commit bf4d445

15 files changed

+872
-739
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ add_subdirectory(nyan)
2020
add_subdirectory(pregen)
2121
add_subdirectory(tech)
2222
add_subdirectory(upgrade_attribute)
23+
add_subdirectory(upgrade_resource)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
add_py_modules(
2+
__init__.py
3+
assault_mech_anti_air.py
4+
berserk_heal_rate.py
5+
cloak.py
6+
concentration.py
7+
convert_building.py
8+
convert_monk.py
9+
convert_range.py
10+
faith_recharge_rate.py
11+
heal_range.py
12+
__init__.py
13+
shield.py
14+
submarine_detect.py
15+
)
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+
Create upgrade patches for civ resources in SWBG.
5+
"""
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
Creates upgrade patches for the assault mech anti air upgrade in SWBG.
5+
"""
6+
from __future__ import annotations
7+
import typing
8+
9+
if typing.TYPE_CHECKING:
10+
from .....entity_object.conversion.converter_object import ConverterObjectGroup
11+
from .....value_object.conversion.forward_ref import ForwardRef
12+
from ......nyan.nyan_structs import MemberOperator
13+
14+
15+
def assault_mech_anti_air_upgrade(
16+
converter_group: ConverterObjectGroup,
17+
value: typing.Any,
18+
operator: MemberOperator,
19+
team: bool = False
20+
) -> list[ForwardRef]:
21+
"""
22+
Creates a patch for the assault mech anti air effect (ID: 31).
23+
24+
:param converter_group: Tech/Civ that gets the patch.
25+
:param value: Value used for patching the member.
26+
:param operator: Operator used for patching the member.
27+
:returns: The forward references for the generated patches.
28+
"""
29+
patches = []
30+
31+
# TODO: Implement
32+
33+
return patches
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
Creates upgrade patches for the berserk heal rate in SWBG.
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 ......nyan.nyan_structs import MemberOperator
17+
18+
19+
def berserk_heal_rate_upgrade(
20+
converter_group: ConverterObjectGroup,
21+
value: typing.Union[int, float],
22+
operator: MemberOperator,
23+
team: bool = False
24+
) -> list[ForwardRef]:
25+
"""
26+
Creates a patch for the berserk heal rate modify effect (ID: 96).
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+
berserk_id = 8
34+
dataset = converter_group.data
35+
line = dataset.unit_lines[berserk_id]
36+
37+
patches = []
38+
39+
name_lookup_dict = internal_name_lookups.get_entity_lookups(dataset.game_version)
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+
game_entity_name = name_lookup_dict[berserk_id][0]
51+
52+
patch_target_ref = f"{game_entity_name}.RegenerateHealth.HealthRate"
53+
patch_target_forward_ref = ForwardRef(line, patch_target_ref)
54+
55+
# Wrapper
56+
wrapper_name = f"Change{game_entity_name}HealthRegenerationWrapper"
57+
wrapper_ref = f"{obj_name}.{wrapper_name}"
58+
wrapper_location = ForwardRef(converter_group, obj_name)
59+
wrapper_raw_api_object = RawAPIObject(wrapper_ref,
60+
wrapper_name,
61+
dataset.nyan_api_objects,
62+
wrapper_location)
63+
wrapper_raw_api_object.add_raw_parent("engine.util.patch.Patch")
64+
65+
# Nyan patch
66+
nyan_patch_name = f"Change{game_entity_name}HealthRegeneration"
67+
nyan_patch_ref = f"{obj_name}.{wrapper_name}.{nyan_patch_name}"
68+
nyan_patch_location = ForwardRef(converter_group, wrapper_ref)
69+
nyan_patch_raw_api_object = RawAPIObject(nyan_patch_ref,
70+
nyan_patch_name,
71+
dataset.nyan_api_objects,
72+
nyan_patch_location)
73+
nyan_patch_raw_api_object.add_raw_parent("engine.util.patch.NyanPatch")
74+
nyan_patch_raw_api_object.set_patch_target(patch_target_forward_ref)
75+
76+
# Regeneration is on a counter, so we have to invert the value
77+
value = 1 / value
78+
nyan_patch_raw_api_object.add_raw_patch_member("rate",
79+
value,
80+
"engine.util.attribute.AttributeRate",
81+
operator)
82+
83+
patch_forward_ref = ForwardRef(converter_group, nyan_patch_ref)
84+
wrapper_raw_api_object.add_raw_member("patch",
85+
patch_forward_ref,
86+
"engine.util.patch.Patch")
87+
88+
if team:
89+
team_property = dataset.pregen_nyan_objects["util.patch.property.types.Team"].get_nyan_object(
90+
)
91+
properties = {
92+
dataset.nyan_api_objects["engine.util.patch.property.type.Diplomatic"]: team_property
93+
}
94+
wrapper_raw_api_object.add_raw_member("properties",
95+
properties,
96+
"engine.util.patch.Patch")
97+
98+
converter_group.add_raw_api_object(wrapper_raw_api_object)
99+
converter_group.add_raw_api_object(nyan_patch_raw_api_object)
100+
101+
wrapper_forward_ref = ForwardRef(converter_group, wrapper_ref)
102+
patches.append(wrapper_forward_ref)
103+
104+
return patches
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
Creates upgrade patches for cloak upgrades in SWBG.
5+
"""
6+
from __future__ import annotations
7+
import typing
8+
9+
if typing.TYPE_CHECKING:
10+
from .....entity_object.conversion.converter_object import ConverterObjectGroup
11+
from .....value_object.conversion.forward_ref import ForwardRef
12+
from ......nyan.nyan_structs import MemberOperator
13+
14+
15+
def cloak_upgrade(
16+
converter_group: ConverterObjectGroup,
17+
value: typing.Any,
18+
operator: MemberOperator,
19+
team: bool = False
20+
) -> list[ForwardRef]:
21+
"""
22+
Creates a patch for the force cloak effect (ID: 56).
23+
24+
:param converter_group: Tech/Civ that gets the patch.
25+
:param value: Value used for patching the member.
26+
:param operator: Operator used for patching the member.
27+
:returns: The forward references for the generated patches.
28+
"""
29+
patches = []
30+
31+
# TODO: Implement
32+
33+
return patches
34+
35+
36+
def detect_cloak_upgrade(
37+
converter_group: ConverterObjectGroup,
38+
value: typing.Any,
39+
operator: MemberOperator,
40+
team: bool = False
41+
) -> list[ForwardRef]:
42+
"""
43+
Creates a patch for the force detect cloak effect (ID: 58).
44+
45+
:param converter_group: Tech/Civ that gets the patch.
46+
:param value: Value used for patching the member.
47+
:param operator: Operator used for patching the member.
48+
:returns: The forward references for the generated patches.
49+
"""
50+
patches = []
51+
52+
# TODO: Implement
53+
54+
return patches
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
Creates upgrade patches for the concentration upgrade in SWBG.
5+
"""
6+
from __future__ import annotations
7+
import typing
8+
9+
if typing.TYPE_CHECKING:
10+
from .....entity_object.conversion.converter_object import ConverterObjectGroup
11+
from .....value_object.conversion.forward_ref import ForwardRef
12+
from ......nyan.nyan_structs import MemberOperator
13+
14+
15+
def concentration_upgrade(
16+
converter_group: ConverterObjectGroup,
17+
value: typing.Any,
18+
operator: MemberOperator,
19+
team: bool = False
20+
) -> list[ForwardRef]:
21+
"""
22+
Creates a patch for the concentration effect (ID: 87).
23+
24+
:param converter_group: Tech/Civ that gets the patch.
25+
:param value: Value used for patching the member.
26+
:param operator: Operator used for patching the member.
27+
:returns: The forward references for the generated patches.
28+
"""
29+
patches = []
30+
31+
# TODO: Implement
32+
33+
return patches
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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

Comments
 (0)