From 1bd8f057afb5d293433658cbe84a68f50b9ac74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bergstr=C3=B6m?= <davbe125@student.liu.se> Date: Wed, 1 Aug 2018 14:22:11 +0200 Subject: [PATCH] Make morphing abilities a separate entry --- src/TechTree.cpp | 5 +++++ src/TechTree.h | 1 + src/TechTreeImproved.cpp | 4 ++-- src/TechTreeImproved.h | 3 ++- src/Unit.cpp | 14 +------------- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/TechTree.cpp b/src/TechTree.cpp index a358e4d4e..d81fadd12 100644 --- a/src/TechTree.cpp +++ b/src/TechTree.cpp @@ -48,10 +48,15 @@ void TechTree::onStart() data.requiredUnits.clear(); data.requiredUpgrades.clear(); updated.insert(description.result_type); + + data.buildAbility = sc2::ABILITY_ID::INVALID; } data.whatBuilds.push_back(UnitType(description.producer_type, m_bot)); + if (description.build_ability != sc2::ABILITY_ID::INVALID) data.buildAbility = description.build_ability; + if (description.morph_ability != sc2::ABILITY_ID::INVALID) data.morphAbility = description.morph_ability; + for (sc2::UNIT_TYPEID unit_typeid : description.buildings_needed) { data.requiredUnits.push_back(UnitType(unit_typeid, m_bot)); diff --git a/src/TechTree.h b/src/TechTree.h index f790805c1..c20274588 100644 --- a/src/TechTree.h +++ b/src/TechTree.h @@ -26,6 +26,7 @@ struct TypeData std::vector<UnitType> requiredUnits; // owning ONE of these is required to make std::vector<sc2::UPGRADE_ID> requiredUpgrades; // having ALL of these is required to make std::vector<UnitType> requiredAddons; // a unit of this type must be present next to the producer + sc2::AbilityID morphAbility = 0; // the ability which morphes the producer into this type }; class TechTree diff --git a/src/TechTreeImproved.cpp b/src/TechTreeImproved.cpp index 9a20e5535..8b07889ae 100644 --- a/src/TechTreeImproved.cpp +++ b/src/TechTreeImproved.cpp @@ -115,7 +115,7 @@ void add_requirement(BuildDescription & description, json & requirement) void parse_build_description(BuildDescription & description, json & build_item) { description.result_type = static_cast<sc2::UNIT_TYPEID>(build_item["unit"]); - description.ability_used = static_cast<sc2::ABILITY_ID>(build_item["ability"]); + description.build_ability = static_cast<sc2::ABILITY_ID>(build_item["ability"]); if (build_item.find("requires") != build_item.end()) { @@ -197,7 +197,7 @@ void TechTreeImproved::parse_unit(json::iterator it) { BuildDescription description; description.producer_type = producer_id; - description.ability_used = static_cast<sc2::ABILITY_ID>(morph_item["ability"]); + description.morph_ability = static_cast<sc2::ABILITY_ID>(morph_item["ability"]); description.result_type = static_cast<sc2::UNIT_TYPEID>(morph_item["unit"]); if (morph_item.find("requires") != morph_item.end()) diff --git a/src/TechTreeImproved.h b/src/TechTreeImproved.h index 55b022701..0948a328c 100644 --- a/src/TechTreeImproved.h +++ b/src/TechTreeImproved.h @@ -12,7 +12,8 @@ struct BuildDescription { sc2::UNIT_TYPEID producer_type; sc2::UNIT_TYPEID result_type; - sc2::AbilityID ability_used; + sc2::AbilityID build_ability; + sc2::AbilityID morph_ability; std::vector<sc2::UNIT_TYPEID> buildings_needed; std::vector<sc2::UNIT_TYPEID> addons_needed; diff --git a/src/Unit.cpp b/src/Unit.cpp index 934db2c6e..a18995967 100644 --- a/src/Unit.cpp +++ b/src/Unit.cpp @@ -271,31 +271,19 @@ void Unit::build(const UnitType & buildingType, CCTilePosition pos) const void Unit::buildTarget(const UnitType & buildingType, const Unit & target) const { BOT_ASSERT(isValid(), "Unit is not valid"); -#ifdef SC2API m_bot->Actions()->UnitCommand(m_unit, m_bot->Data(buildingType).buildAbility, target.getUnitPtr()); -#else - BOT_ASSERT(false, "buildTarget shouldn't be called for BWAPI bots"); -#endif } void Unit::train(const UnitType & type) const { BOT_ASSERT(isValid(), "Unit is not valid"); -#ifdef SC2API m_bot->Actions()->UnitCommand(m_unit, m_bot->Data(type).buildAbility); -#else - m_unit->train(type.getAPIUnitType()); -#endif } void Unit::morph(const UnitType & type) const { BOT_ASSERT(isValid(), "Unit is not valid"); -#ifdef SC2API - m_bot->Actions()->UnitCommand(m_unit, m_bot->Data(type).buildAbility); -#else - m_unit->morph(type.getAPIUnitType()); -#endif + m_bot->Actions()->UnitCommand(m_unit, m_bot->Data(type).morphAbility); } void Unit::research(sc2::UpgradeID upgrade) const -- GitLab