Skip to content

Commit ce4afe3

Browse files
committed
convert: Refactor AoCPregenSubprocessor into separate files.
1 parent 1a64b57 commit ce4afe3

File tree

19 files changed

+3066
-2472
lines changed

19 files changed

+3066
-2472
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ add_subdirectory(media)
2525
add_subdirectory(modifier)
2626
add_subdirectory(modpack)
2727
add_subdirectory(nyan)
28+
add_subdirectory(pregen)
2829
add_subdirectory(resistance)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
add_py_modules(
2+
__init__.py
3+
activity.py
4+
attribute.py
5+
condition.py
6+
diplomatic.py
7+
effect.py
8+
entity.py
9+
exchange.py
10+
formation.py
11+
language.py
12+
misc.py
13+
modifier.py
14+
path.py
15+
resource.py
16+
team_property.py
17+
terrain.py
18+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
Creates nyan objects for things that are hardcoded into the Genie Engine,
5+
but configurable in openage, e.g. HP.
6+
"""
7+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.

openage/convert/processor/conversion/aoc/pregen/activity.py

Lines changed: 505 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
Create the attributes used in AoC.
5+
6+
TODO: Fill translations
7+
"""
8+
from __future__ import annotations
9+
import typing
10+
11+
from .....entity_object.conversion.converter_object import RawAPIObject, ConverterObjectGroup
12+
from .....value_object.conversion.forward_ref import ForwardRef
13+
14+
if typing.TYPE_CHECKING:
15+
from .....entity_object.conversion.aoc.genie_object_container import GenieObjectContainer
16+
17+
ATTRIBUTE_PARENT = "engine.util.attribute.Attribute"
18+
ATTRIBUTES_LOCATION = "data/util/attribute/"
19+
20+
21+
def generate_attributes(
22+
full_data_set: GenieObjectContainer,
23+
pregen_converter_group: ConverterObjectGroup
24+
) -> None:
25+
"""
26+
Generate Attribute objects.
27+
28+
:param full_data_set: Storage for all converted objects and metadata.
29+
:param pregen_converter_group: Stores all pregenerated nyan objects.
30+
"""
31+
_generate_hp_attribute(full_data_set, pregen_converter_group)
32+
_generate_faith_attribute(full_data_set, pregen_converter_group)
33+
34+
35+
def _generate_hp_attribute(
36+
full_data_set: GenieObjectContainer,
37+
pregen_converter_group: ConverterObjectGroup
38+
) -> None:
39+
"""
40+
Generate the HP attribute.
41+
42+
:param full_data_set: Storage for all converted objects and metadata.
43+
:param pregen_converter_group: Stores all pregenerated nyan objects.
44+
"""
45+
pregen_nyan_objects = full_data_set.pregen_nyan_objects
46+
api_objects = full_data_set.nyan_api_objects
47+
48+
health_ref_in_modpack = "util.attribute.types.Health"
49+
health_raw_api_object = RawAPIObject(health_ref_in_modpack,
50+
"Health", api_objects,
51+
ATTRIBUTES_LOCATION)
52+
health_raw_api_object.set_filename("types")
53+
health_raw_api_object.add_raw_parent(ATTRIBUTE_PARENT)
54+
55+
name_forward_ref = ForwardRef(pregen_converter_group,
56+
"util.attribute.types.Health.HealthName")
57+
health_raw_api_object.add_raw_member("name", name_forward_ref,
58+
ATTRIBUTE_PARENT)
59+
abbrv_forward_ref = ForwardRef(pregen_converter_group,
60+
"util.attribute.types.Health.HealthAbbreviation")
61+
health_raw_api_object.add_raw_member("abbreviation", abbrv_forward_ref,
62+
ATTRIBUTE_PARENT)
63+
64+
pregen_converter_group.add_raw_api_object(health_raw_api_object)
65+
pregen_nyan_objects.update({health_ref_in_modpack: health_raw_api_object})
66+
67+
name_value_parent = "engine.util.language.translated.type.TranslatedString"
68+
health_name_ref_in_modpack = "util.attribute.types.Health.HealthName"
69+
health_name_value = RawAPIObject(health_name_ref_in_modpack, "HealthName",
70+
api_objects, ATTRIBUTES_LOCATION)
71+
health_name_value.set_filename("types")
72+
health_name_value.add_raw_parent(name_value_parent)
73+
health_name_value.add_raw_member("translations", [], name_value_parent)
74+
75+
pregen_converter_group.add_raw_api_object(health_name_value)
76+
pregen_nyan_objects.update({health_name_ref_in_modpack: health_name_value})
77+
78+
abbrv_value_parent = "engine.util.language.translated.type.TranslatedString"
79+
health_abbrv_ref_in_modpack = "util.attribute.types.Health.HealthAbbreviation"
80+
health_abbrv_value = RawAPIObject(health_abbrv_ref_in_modpack, "HealthAbbreviation",
81+
api_objects, ATTRIBUTES_LOCATION)
82+
health_abbrv_value.set_filename("types")
83+
health_abbrv_value.add_raw_parent(abbrv_value_parent)
84+
health_abbrv_value.add_raw_member("translations", [], abbrv_value_parent)
85+
86+
pregen_converter_group.add_raw_api_object(health_abbrv_value)
87+
pregen_nyan_objects.update({health_abbrv_ref_in_modpack: health_abbrv_value})
88+
89+
90+
def _generate_faith_attribute(
91+
full_data_set: GenieObjectContainer,
92+
pregen_converter_group: ConverterObjectGroup
93+
) -> None:
94+
"""
95+
Generate the Faith attribute.
96+
97+
:param full_data_set: Storage for all converted objects and metadata.
98+
:param pregen_converter_group: Stores all pregenerated nyan objects.
99+
"""
100+
pregen_nyan_objects = full_data_set.pregen_nyan_objects
101+
api_objects = full_data_set.nyan_api_objects
102+
103+
faith_ref_in_modpack = "util.attribute.types.Faith"
104+
faith_raw_api_object = RawAPIObject(faith_ref_in_modpack,
105+
"Faith", api_objects,
106+
ATTRIBUTES_LOCATION)
107+
faith_raw_api_object.set_filename("types")
108+
faith_raw_api_object.add_raw_parent(ATTRIBUTE_PARENT)
109+
110+
name_forward_ref = ForwardRef(pregen_converter_group,
111+
"util.attribute.types.Faith.FaithName")
112+
faith_raw_api_object.add_raw_member("name", name_forward_ref,
113+
ATTRIBUTE_PARENT)
114+
abbrv_forward_ref = ForwardRef(pregen_converter_group,
115+
"util.attribute.types.Faith.FaithAbbreviation")
116+
faith_raw_api_object.add_raw_member("abbreviation", abbrv_forward_ref,
117+
ATTRIBUTE_PARENT)
118+
119+
pregen_converter_group.add_raw_api_object(faith_raw_api_object)
120+
pregen_nyan_objects.update({faith_ref_in_modpack: faith_raw_api_object})
121+
122+
name_value_parent = "engine.util.language.translated.type.TranslatedString"
123+
faith_name_ref_in_modpack = "util.attribute.types.Faith.FaithName"
124+
faith_name_value = RawAPIObject(faith_name_ref_in_modpack, "FaithName",
125+
api_objects, ATTRIBUTES_LOCATION)
126+
faith_name_value.set_filename("types")
127+
faith_name_value.add_raw_parent(name_value_parent)
128+
faith_name_value.add_raw_member("translations", [], name_value_parent)
129+
130+
pregen_converter_group.add_raw_api_object(faith_name_value)
131+
pregen_nyan_objects.update({faith_name_ref_in_modpack: faith_name_value})
132+
133+
abbrv_value_parent = "engine.util.language.translated.type.TranslatedString"
134+
faith_abbrv_ref_in_modpack = "util.attribute.types.Faith.FaithAbbreviation"
135+
faith_abbrv_value = RawAPIObject(faith_abbrv_ref_in_modpack, "FaithAbbreviation",
136+
api_objects, ATTRIBUTES_LOCATION)
137+
faith_abbrv_value.set_filename("types")
138+
faith_abbrv_value.add_raw_parent(abbrv_value_parent)
139+
faith_abbrv_value.add_raw_member("translations", [], abbrv_value_parent)
140+
141+
pregen_converter_group.add_raw_api_object(faith_abbrv_value)
142+
pregen_nyan_objects.update({faith_abbrv_ref_in_modpack: faith_abbrv_value})
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Copyright 2025-2025 the openage authors. See copying.md for legal info.
2+
3+
"""
4+
Create conditions for AoC.
5+
"""
6+
from __future__ import annotations
7+
import typing
8+
9+
from .....entity_object.conversion.converter_object import RawAPIObject, ConverterObjectGroup
10+
from .....value_object.conversion.forward_ref import ForwardRef
11+
12+
if typing.TYPE_CHECKING:
13+
from .....entity_object.conversion.aoc.genie_object_container import GenieObjectContainer
14+
15+
LOGIC_PARENT = "engine.util.logic.LogicElement"
16+
LITERAL_PARENT = "engine.util.logic.literal.Literal"
17+
INTERVAL_PARENT = "engine.util.logic.literal.type.AttributeBelowValue"
18+
19+
SCOPE_PARENT = "engine.util.logic.literal_scope.LiteralScope"
20+
SELF_SCOPE_PARENT = "engine.util.logic.literal_scope.type.Self"
21+
22+
23+
def generate_death_condition(
24+
full_data_set: GenieObjectContainer,
25+
pregen_converter_group: ConverterObjectGroup
26+
) -> None:
27+
"""
28+
Generate DeathCondition objects for unit and building deaths in AoC.
29+
30+
:param full_data_set: Storage for all converted objects and metadata.
31+
:param pregen_converter_group: Stores all pregenerated nyan objects.
32+
"""
33+
pregen_nyan_objects = full_data_set.pregen_nyan_objects
34+
api_objects = full_data_set.nyan_api_objects
35+
36+
literal_location = "data/util/logic/death/"
37+
38+
death_ref_in_modpack = "util.logic.literal.death.StandardHealthDeathLiteral"
39+
literal_raw_api_object = RawAPIObject(death_ref_in_modpack,
40+
"StandardHealthDeathLiteral",
41+
api_objects,
42+
literal_location)
43+
literal_raw_api_object.set_filename("death")
44+
literal_raw_api_object.add_raw_parent(INTERVAL_PARENT)
45+
46+
# Literal will not default to 'True' when it was fulfilled once
47+
literal_raw_api_object.add_raw_member("only_once", False, LOGIC_PARENT)
48+
49+
# Scope
50+
scope_forward_ref = ForwardRef(pregen_converter_group,
51+
"util.logic.literal_scope.death.StandardHealthDeathScope")
52+
literal_raw_api_object.add_raw_member("scope",
53+
scope_forward_ref,
54+
LITERAL_PARENT)
55+
56+
# Attribute
57+
health_forward_ref = ForwardRef(pregen_converter_group,
58+
"util.attribute.types.Health")
59+
literal_raw_api_object.add_raw_member("attribute",
60+
health_forward_ref,
61+
INTERVAL_PARENT)
62+
63+
# sidenote: Apparently this is actually HP<1 in Genie
64+
# (https://youtu.be/FdBk8zGbE7U?t=7m16s)
65+
literal_raw_api_object.add_raw_member("threshold",
66+
1,
67+
INTERVAL_PARENT)
68+
69+
pregen_converter_group.add_raw_api_object(literal_raw_api_object)
70+
pregen_nyan_objects.update({death_ref_in_modpack: literal_raw_api_object})
71+
72+
# LiteralScope
73+
death_scope_ref_in_modpack = "util.logic.literal_scope.death.StandardHealthDeathScope"
74+
scope_raw_api_object = RawAPIObject(death_scope_ref_in_modpack,
75+
"StandardHealthDeathScope",
76+
api_objects)
77+
scope_location = ForwardRef(pregen_converter_group, death_ref_in_modpack)
78+
scope_raw_api_object.set_location(scope_location)
79+
scope_raw_api_object.add_raw_parent(SELF_SCOPE_PARENT)
80+
81+
scope_diplomatic_stances = [api_objects["engine.util.diplomatic_stance.type.Self"]]
82+
scope_raw_api_object.add_raw_member("stances",
83+
scope_diplomatic_stances,
84+
SCOPE_PARENT)
85+
86+
pregen_converter_group.add_raw_api_object(scope_raw_api_object)
87+
pregen_nyan_objects.update({death_scope_ref_in_modpack: scope_raw_api_object})
88+
89+
90+
def generate_garrison_empty_condition(
91+
full_data_set: GenieObjectContainer,
92+
pregen_converter_group: ConverterObjectGroup
93+
) -> None:
94+
"""
95+
Generate condition objects for emptying garrisoned buildings when they have
96+
low HP in AoC.
97+
98+
:param full_data_set: Storage for all converted objects and metadata.
99+
:param pregen_converter_group: Stores all pregenerated nyan objects.
100+
"""
101+
pregen_nyan_objects = full_data_set.pregen_nyan_objects
102+
api_objects = full_data_set.nyan_api_objects
103+
104+
literal_location = "data/util/logic/garrison_empty/"
105+
106+
garrison_literal_ref_in_modpack = "util.logic.literal.garrison.BuildingDamageEmpty"
107+
literal_raw_api_object = RawAPIObject(garrison_literal_ref_in_modpack,
108+
"BuildingDamageEmptyLiteral",
109+
api_objects,
110+
literal_location)
111+
literal_raw_api_object.set_filename("garrison_empty")
112+
literal_raw_api_object.add_raw_parent(INTERVAL_PARENT)
113+
114+
# Literal will not default to 'True' when it was fulfilled once
115+
literal_raw_api_object.add_raw_member("only_once", False, LOGIC_PARENT)
116+
117+
# Scope
118+
scope_forward_ref = ForwardRef(pregen_converter_group,
119+
"util.logic.literal_scope.garrison.BuildingDamageEmptyScope")
120+
literal_raw_api_object.add_raw_member("scope",
121+
scope_forward_ref,
122+
LITERAL_PARENT)
123+
124+
# Attribute
125+
health_forward_ref = ForwardRef(pregen_converter_group,
126+
"util.attribute.types.Health")
127+
literal_raw_api_object.add_raw_member("attribute",
128+
health_forward_ref,
129+
INTERVAL_PARENT)
130+
131+
# Threshhold
132+
literal_raw_api_object.add_raw_member("threshold",
133+
0.2,
134+
INTERVAL_PARENT)
135+
136+
pregen_converter_group.add_raw_api_object(literal_raw_api_object)
137+
pregen_nyan_objects.update({garrison_literal_ref_in_modpack: literal_raw_api_object})
138+
139+
# LiteralScope
140+
garrison_scope_ref_in_modpack = "util.logic.literal_scope.garrison.BuildingDamageEmptyScope"
141+
scope_raw_api_object = RawAPIObject(garrison_scope_ref_in_modpack,
142+
"BuildingDamageEmptyScope",
143+
api_objects)
144+
scope_location = ForwardRef(pregen_converter_group, garrison_literal_ref_in_modpack)
145+
scope_raw_api_object.set_location(scope_location)
146+
scope_raw_api_object.add_raw_parent(SELF_SCOPE_PARENT)
147+
148+
scope_diplomatic_stances = [api_objects["engine.util.diplomatic_stance.type.Self"]]
149+
scope_raw_api_object.add_raw_member("stances",
150+
scope_diplomatic_stances,
151+
SCOPE_PARENT)
152+
153+
pregen_converter_group.add_raw_api_object(scope_raw_api_object)
154+
pregen_nyan_objects.update({garrison_scope_ref_in_modpack: scope_raw_api_object})

0 commit comments

Comments
 (0)