Skip to content

Commit

Permalink
convert: Link creatables.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Nov 3, 2019
1 parent 6dea8bd commit 7308d54
Show file tree
Hide file tree
Showing 7 changed files with 472 additions and 53 deletions.
8 changes: 4 additions & 4 deletions libopenage/unit/producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void ObjectProducer::initialise(Unit *unit, Player &player) {
else if (this->unit_data.unit_class == gamedata::unit_classes::PREY_ANIMAL) {
unit->add_attribute(std::make_shared<Attribute<attr_type::resource>>(game_resource::food, 140));
}
else if (this->unit_data.unit_class == gamedata::unit_classes::SHEEP) {
else if (this->unit_data.unit_class == gamedata::unit_classes::HERDABLE) {
unit->add_attribute(std::make_shared<Attribute<attr_type::resource>>(game_resource::food, 100, 0.1));
}
else if (this->unit_data.unit_class == gamedata::unit_classes::GOLD_MINE) {
Expand Down Expand Up @@ -455,7 +455,7 @@ void LivingProducer::initialise(Unit *unit, Player &player) {
MovableProducer::initialise(unit, player);

// population of 1 for all movable units
if (this->unit_data.unit_class != gamedata::unit_classes::SHEEP) {
if (this->unit_data.unit_class != gamedata::unit_classes::HERDABLE) {
unit->add_attribute(std::make_shared<Attribute<attr_type::population>>(1, 0));
}

Expand All @@ -482,7 +482,7 @@ void LivingProducer::initialise(Unit *unit, Player &player) {
multitype_attr.types[gamedata::unit_classes::CIVILIAN] = this->parent_type(); // get default villager
multitype_attr.types[gamedata::unit_classes::BUILDING] = this->owner.get_type(156); // builder 118
multitype_attr.types[gamedata::unit_classes::BERRY_BUSH] = this->owner.get_type(120); // forager
multitype_attr.types[gamedata::unit_classes::SHEEP] = this->owner.get_type(592); // sheperd
multitype_attr.types[gamedata::unit_classes::HERDABLE] = this->owner.get_type(592); // sheperd
multitype_attr.types[gamedata::unit_classes::TREES] = this->owner.get_type(123); // woodcutter
multitype_attr.types[gamedata::unit_classes::GOLD_MINE] = this->owner.get_type(579); // gold miner
multitype_attr.types[gamedata::unit_classes::STONE_MINE] = this->owner.get_type(124); // stone miner
Expand All @@ -494,7 +494,7 @@ void LivingProducer::initialise(Unit *unit, Player &player) {
multitype_attr.types[gamedata::unit_classes::CIVILIAN] = this->parent_type(); // get default villager
multitype_attr.types[gamedata::unit_classes::BUILDING] = this->owner.get_type(222); // builder 212
multitype_attr.types[gamedata::unit_classes::BERRY_BUSH] = this->owner.get_type(354); // forager
multitype_attr.types[gamedata::unit_classes::SHEEP] = this->owner.get_type(590); // sheperd
multitype_attr.types[gamedata::unit_classes::HERDABLE] = this->owner.get_type(590); // sheperd
multitype_attr.types[gamedata::unit_classes::TREES] = this->owner.get_type(218); // woodcutter
multitype_attr.types[gamedata::unit_classes::GOLD_MINE] = this->owner.get_type(581); // gold miner
multitype_attr.types[gamedata::unit_classes::STONE_MINE] = this->owner.get_type(220); // stone miner
Expand Down
27 changes: 24 additions & 3 deletions openage/convert/dataformat/aoc/genie_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def __init__(self, effect_id, bundle_id, full_data_set, members=None):
self.bundle_id = bundle_id
self.data = full_data_set

def get_type(self):
"""
Returns the effect's type.
"""
return self.get_member("type_id").get_value()


class GenieEffectBundle(ConverterObject):
"""
Expand Down Expand Up @@ -58,11 +64,26 @@ def __init__(self, bundle_id, effects, full_data_set, members=None):
self.data = full_data_set
self.data.genie_effect_bundles.update({self.get_id(): self})

def get_effects(self):
def get_effects(self, effect_type=None):
"""
Returns the effects in the bundle.
Returns the effects in the bundle, optionally only effects with a specific
type.
:param effect_type: Type that the effects should have.
:type effect_type: int, optional
:returns: List of matching effects.
:rtype: list
"""
return self.effects
if effect_type:
matching_effects = []
for _, effect in self.effects.items():
if effect.get_type() == effect_type:
matching_effects.append(effect)

return matching_effects

else:
return self.effects

def is_sanitized(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions openage/convert/dataformat/aoc/genie_object_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ def __init__(self):
self.transform_groups = {}
self.villager_groups = {}
self.monk_groups = {}
self.variant_groups = {}
self.civ_groups = {}
self.tech_groups = {}
self.age_upgrades = {}
self.unit_upgrades = {}
self.building_upgrades = {}
self.unit_unlocks = {}
self.civ_boni = {}
68 changes: 64 additions & 4 deletions openage/convert/dataformat/aoc/genie_tech.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

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


class GenieTechObject(ConverterObject):
Expand Down Expand Up @@ -50,6 +49,7 @@ 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]
Expand All @@ -60,8 +60,41 @@ def __init__(self, tech_id, full_data_set):
if effect_bundle_id > -1:
self.effects = self.data.genie_effect_bundles[effect_bundle_id]

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

def is_researchable(self):
"""
Techs are researchable if they have a valid research location.
:returns: True if the research location id is greater than zero.
"""
research_location_id = self.tech.get_member("research_location_id").get_value()

# -1 = no train location
if research_location_id == -1:
return False

return True

def get_research_location(self):
"""
Returns the group_id for a building line if the tech is
researchable, otherwise return None.
"""
if self.is_researchable():
return self.tech.get_member("research_location_id").get_value()

return None

def has_effect(self):
"""
Returns True if the techology's effects do anything.
"""
if self.effects:
return len(self.effects.get_effects()) > 0
else:
return False


class AgeUpgrade(GenieTechEffectBundleGroup):
Expand Down Expand Up @@ -101,7 +134,7 @@ class UnitLineUpgrade(GenieTechEffectBundleGroup):

def __init__(self, tech_id, unit_line_id, upgrade_target_id, full_data_set):
"""
Creates a new Genie tech group object.
Creates a new Genie line upgrade object.
:param tech_id: The internal tech_id from the .dat file.
:param unit_line_id: The unit line that is upgraded.
Expand All @@ -119,6 +152,33 @@ def __init__(self, tech_id, unit_line_id, upgrade_target_id, full_data_set):
self.data.unit_upgrades.update({self.get_id(): self})


class BuildingLineUpgrade(GenieTechEffectBundleGroup):
"""
Upgrades a building in a line.
This will become a Tech API object targeted at the line's game entity.
"""

def __init__(self, tech_id, building_line_id, upgrade_target_id, full_data_set):
"""
Creates a new Genie line upgrade object.
:param tech_id: The internal tech_id from the .dat file.
:param building_line_id: The building line that is upgraded.
:param upgrade_target_id: The unit that is the result of the upgrade.
:param full_data_set: GenieObjectContainer instance that
contains all relevant data for the conversion
process.
"""

super().__init__(tech_id, full_data_set)

self.building_line_id = building_line_id
self.upgrade_target_id = upgrade_target_id

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


class UnitUnlock(GenieTechEffectBundleGroup):
"""
Unlocks units and buildings for an Age, sometimes with additional
Expand Down
Loading

0 comments on commit 7308d54

Please sign in to comment.