Skip to content

Commit

Permalink
convert: Fill converter groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Oct 28, 2019
1 parent 19a000a commit 6035bbe
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 65 deletions.
9 changes: 8 additions & 1 deletion openage/convert/dataformat/aoc/genie_civ.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ def __init__(self, civ_id, full_data_set):
self.civ = self.data.genie_civs[civ_id]

team_bonus_id = self.civ.get_member("team_bonus_id").get_value()
self.team_bonus = self.data.genie_effect_bundles[team_bonus_id]
if civ_id == 0:
# Gaia civ has no team bonus
self.team_bonus = None
else:
self.team_bonus = self.data.genie_effect_bundles[team_bonus_id]

tech_tree_id = self.civ.get_member("tech_tree_id").get_value()
self.disabled_techs = self.data.genie_effect_bundles[tech_tree_id]
18 changes: 18 additions & 0 deletions openage/convert/dataformat/aoc/genie_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,23 @@ def __init__(self, bundle_id, effects, full_data_set, members=None):

self.effects = effects

# Sanitized bundles should not contain 'garbage' effects, e.g.
# - effects that do nothing
# - effects without a type #
# Processors should set this to True, once the bundle is sanitized.
self.sanitized = False

self.data = full_data_set
self.data.genie_effect_bundles.update({self.get_id(): self})

def get_effects(self):
"""
Returns the effects in the bundle.
"""
return self.effects

def is_sanitized(self):
"""
Returns whether the effect bundle has been sanitized.
"""
return self.sanitized
6 changes: 4 additions & 2 deletions openage/convert/dataformat/aoc/genie_object_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def __init__(self):
self.villager_groups = {}
self.monk_groups = {}
self.civ_groups = {}
self.team_boni = {}
self.tech_groups = {}
self.tech_lines = {}
self.age_upgrades = {}
self.unit_upgrades = {}
self.unit_unlocks = {}
self.civ_boni = {}
50 changes: 14 additions & 36 deletions openage/convert/dataformat/aoc/genie_tech.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from ...dataformat.converter_object import ConverterObject,\
ConverterObjectGroup
from openage.convert.dataformat.aoc.genie_effect import GenieEffectBundle


class GenieTechObject(ConverterObject):
Expand Down Expand Up @@ -49,47 +50,18 @@ def __init__(self, tech_id, full_data_set):
super().__init__(tech_id)

self.data = full_data_set
self.data.tech_groups.update({self.get_id(): self})

# The tech that belongs to the tech id
self.tech = self.data.genie_techs[tech_id]

# Effects of the tech
self.effects = []

effect_bundle_id = self.tech.get_member("tech_effect_id").get_value()
tech_effects = self.data.genie_effect_bundles[effect_bundle_id].get_effects()

self.effects.extend(tech_effects)


class GenieTechLineGroup(ConverterObjectGroup):
"""
Collection of GenieTechEffectBundleGroups that form a line (i.e. they unlock each other
consecutively).
Example: Double-bit axe->Bow Saw-> Two-man saw
Each of the techs in line will become individual Tech API objects.
"""

def __init__(self, line_id, full_data_set):
"""
Creates a new Genie tech group object.

:param line_id: The internal line_id from the .dat file (ResearchConnection).
:param full_data_set: GenieObjectContainer instance that
contains all relevant data for the conversion
process.
"""

super().__init__(line_id)
if effect_bundle_id > -1:
self.effects = self.data.genie_effect_bundles[effect_bundle_id]

# The line is stored as an ordered list of GenieTechEffectBundleGroups.
self.line = []

self.data = full_data_set
self.data.tech_lines.update({self.get_id(): self})
# only add it to the set if there's an effect
self.data.tech_groups.update({self.get_id(): self})


class AgeUpgrade(GenieTechEffectBundleGroup):
Expand Down Expand Up @@ -117,6 +89,8 @@ def __init__(self, tech_id, age_id, full_data_set):

self.age_id = age_id

self.data.age_upgrades.update({self.get_id(): self})


class UnitLineUpgrade(GenieTechEffectBundleGroup):
"""
Expand All @@ -142,6 +116,8 @@ def __init__(self, tech_id, unit_line_id, upgrade_target_id, full_data_set):
self.unit_line_id = unit_line_id
self.upgrade_target_id = upgrade_target_id

self.data.unit_upgrades.update({self.get_id(): self})


class UnitUnlock(GenieTechEffectBundleGroup):
"""
Expand All @@ -153,12 +129,11 @@ class UnitUnlock(GenieTechEffectBundleGroup):
will be created.
"""

def __init__(self, tech_id, unit_type, line_id, full_data_set):
def __init__(self, tech_id, line_id, full_data_set):
"""
Creates a new Genie tech group object.
:param tech_id: The internal tech_id from the .dat file.
:param unit_type: Type of the unit (unit=70,building=80).
:param line_id: The unit line that is unlocked.
:param full_data_set: GenieObjectContainer instance that
contains all relevant data for the conversion
Expand All @@ -167,9 +142,10 @@ def __init__(self, tech_id, unit_type, line_id, full_data_set):

super().__init__(tech_id, full_data_set)

self.unit_type = unit_type
self.line_id = line_id

self.data.unit_unlocks.update({self.get_id(): self})


class CivBonus(GenieTechEffectBundleGroup):
"""
Expand All @@ -193,3 +169,5 @@ def __init__(self, tech_id, civ_id, full_data_set):
super().__init__(tech_id, full_data_set)

self.civ_id = civ_id

self.data.civ_boni.update({self.get_id(): self})
53 changes: 33 additions & 20 deletions openage/convert/dataformat/aoc/genie_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,14 @@ def add_unit(self, genie_unit, after=None):
is not present, the unit is appended at the end
of the line.
"""

unit_type = genie_unit.get_member("unit_type").get_value()
unit_id = genie_unit.get_member("id0").get_value()

# Only add unit if it is not already in the list
if not self.contains_unit(unit_id):
# Valid units have type >= 70
if unit_type != 70:
raise Exception("GenieUnitObject must have type == 70"
"to be added to a unit line")

if after:
for unit in self.line:
if after == unit.get_id():
self.line.insert(self.line.index(unit), genie_unit)
self.line.insert(self.line.index(unit) + 1, genie_unit)
break

else:
Expand Down Expand Up @@ -225,21 +218,14 @@ def add_unit(self, genie_unit, after=None):
is not present, the unit is appended at the end
of the line.
"""

unit_type = genie_unit.get_member("unit_type").get_value()
unit_id = genie_unit.get_member("id0").get_value()

# Only add building if it is not already in the list
if not self.contains_building(unit_id):
# Valid units have type >= 70
if unit_type != 80:
raise Exception("GenieUnitObject must have type == 80"
"to be added to a building line")

if after:
for unit in self.line:
if after == unit.get_id():
self.line.insert(self.line.index(unit), genie_unit)
self.line.insert(self.line.index(unit) + 1, genie_unit)
break

else:
Expand Down Expand Up @@ -293,6 +279,31 @@ def contains_researchable(self, line_id):
return tech_line in self.researches


class GenieStackBuildingGroup(GenieBuildingLineGroup):
"""
Buildings that stack with other units and have annexes. These buildings
are replaced by their stack unit once built.
Examples: Gate, Town Center
The 'stack unit' becomes the GameEntity, the 'head unit' will be a state
during construction.
"""

def __init__(self, head_building_id, stack_unit_id, full_data_set):
"""
Creates a new Genie building line.
:param head_building_id: The building that is first in line.
:param full_data_set: GenieObjectContainer instance that
contains all relevant data for the conversion
process.
"""
super().__init__(head_building_id, full_data_set)

# TODO


class GenieUnitTransformGroup(GenieUnitLineGroup):
"""
Collection of genie units that reference each other with their
Expand All @@ -319,7 +330,7 @@ def __init__(self, line_id, head_unit_id, full_data_set):

self.head_unit = self.data.genie_units[head_unit_id]

transform_id = self.head_unit.get_member("transform_id").get_value()
transform_id = self.head_unit.get_member("transform_unit_id").get_value()
self.transform_unit = self.data.genie_units[transform_id]


Expand Down Expand Up @@ -386,11 +397,14 @@ class GenieUnitTaskGroup(GenieUnitLineGroup):
the other are used to create more abilities with AnimationOverride.
"""

# From unit connection
male_line_id = 83 # male villager (with combat task)

# Female villagers have no line id (boo!) so we just assign an arbitrary
# ID to them.
female_line_id = 1337

def __init__(self, line_id, task_group_id, head_task_id, full_data_set):
def __init__(self, line_id, task_group_id, full_data_set):
"""
Creates a new Genie task group.
Expand All @@ -404,10 +418,9 @@ def __init__(self, line_id, task_group_id, head_task_id, full_data_set):
super().__init__(line_id, full_data_set)

self.task_group_id = task_group_id
self.head_task_id = head_task_id

# Add a reference for the unit to the dataset
self.data.task_groups.update({self.get_id(): self})
self.data.task_groups.update({task_group_id: self})


class GenieVillagerGroup(ConverterObjectGroup):
Expand Down
2 changes: 1 addition & 1 deletion openage/convert/gamedata/tech.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class OtherConnection(GenieStructure):
raw_type="int32_t",
type_name="connection_mode",
lookup_dict={
0: "NOTHING",
0: "AGE",
1: "BUILDING",
2: "UNIT",
3: "RESEARCH",
Expand Down
Loading

0 comments on commit 6035bbe

Please sign in to comment.